From 28166074197530c517f1fb4eaec5b3658fa38482 Mon Sep 17 00:00:00 2001 From: lihongjie0209 Date: Sun, 18 Aug 2024 15:59:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/lihongjie/coal/common/DictCode.java | 2 + .../controller/EmpSalaryController.java | 7 + .../coal/empSalary/dto/EmpSalaryDto.java | 7 + .../empSalary/dto/EmpSalaryReportRequest.java | 65 +++++++++ .../empSalary/entity/EmpSalaryEntity.java | 18 +++ .../empSalary/service/EmpSalaryService.java | 131 +++++++++++++++++- .../service/EmpSalaryReportService.java | 7 + .../coal/employee/dto/CreateEmployeeDto.java | 3 + .../employee/dto/EmployeeCalculateDto.java | 3 +- .../coal/employee/dto/EmployeeDto.java | 7 + .../coal/employee/dto/UpdateEmployeeDto.java | 3 + .../coal/employee/entity/EmployeeEntity.java | 4 + src/main/resources/config/dictionary.json | 59 ++++++++ 13 files changed, 312 insertions(+), 4 deletions(-) create mode 100644 src/main/java/cn/lihongjie/coal/empSalary/dto/EmpSalaryReportRequest.java diff --git a/src/main/java/cn/lihongjie/coal/common/DictCode.java b/src/main/java/cn/lihongjie/coal/common/DictCode.java index 36557d2b..4598d468 100644 --- a/src/main/java/cn/lihongjie/coal/common/DictCode.java +++ b/src/main/java/cn/lihongjie/coal/common/DictCode.java @@ -8,6 +8,8 @@ public class DictCode { public static final String METER_TYPE = "meter.type"; + public static final String EMP_POLITICALSTATUS = "emp.politicalStatus"; + public static final String EMP_SALARY_BATCH_STATUS = "emp.salary.batch.status"; public static final String COMMON_STEP_STATUS = "common.step.status"; diff --git a/src/main/java/cn/lihongjie/coal/empSalary/controller/EmpSalaryController.java b/src/main/java/cn/lihongjie/coal/empSalary/controller/EmpSalaryController.java index 2a299bf1..009c9151 100644 --- a/src/main/java/cn/lihongjie/coal/empSalary/controller/EmpSalaryController.java +++ b/src/main/java/cn/lihongjie/coal/empSalary/controller/EmpSalaryController.java @@ -113,4 +113,11 @@ public class EmpSalaryController { this.service.unarchive(request); return true; } + + @PostMapping("/report") + public Object report(@RequestBody EmpSalaryReportRequest request) { + return this.service.report(request); + } + + } diff --git a/src/main/java/cn/lihongjie/coal/empSalary/dto/EmpSalaryDto.java b/src/main/java/cn/lihongjie/coal/empSalary/dto/EmpSalaryDto.java index 4c0f3c4d..4ce2159c 100644 --- a/src/main/java/cn/lihongjie/coal/empSalary/dto/EmpSalaryDto.java +++ b/src/main/java/cn/lihongjie/coal/empSalary/dto/EmpSalaryDto.java @@ -157,6 +157,13 @@ public class EmpSalaryDto extends OrgCommonDto { @DictTranslate(dictKey = DictCode.SEX) private String sexName; + @Comment("政治面貌") + private String politicalStatus; + + @DictTranslate(dictKey = DictCode.EMP_POLITICALSTATUS) + + private String politicalStatusName; + @Comment("民族") private String nation; diff --git a/src/main/java/cn/lihongjie/coal/empSalary/dto/EmpSalaryReportRequest.java b/src/main/java/cn/lihongjie/coal/empSalary/dto/EmpSalaryReportRequest.java new file mode 100644 index 00000000..627c9054 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/empSalary/dto/EmpSalaryReportRequest.java @@ -0,0 +1,65 @@ +package cn.lihongjie.coal.empSalary.dto; + +import cn.lihongjie.coal.base.dto.CommonQuery; + +import lombok.Data; + +import org.hibernate.annotations.Comment; + +import java.time.LocalDate; +import java.util.*; + +@Data +public class EmpSalaryReportRequest extends CommonQuery { + + @Comment( + """ +时间维度 +year +month + +""") + private String timeDimension; + + @Comment( + """ +统计字段 + + +""") + private List reportFields; + + private List fieldInfos; + + private LocalDate startTime; + private LocalDate endTime; + + /** 过滤条件 */ + private List employeeIds; + + private List departmentIds; + private List jobPostIds; + + private String empName; + + private String departmentName; + + private String jobPostName; + + private String idCard; + + private String phone; + + private List nations; + private List marriages; + private List educations; + private List politicalStatuses; + + @Data + public static class FieldInfo { + private String fieldName; + + @Comment("sum avg count max min") + private String function; + } +} diff --git a/src/main/java/cn/lihongjie/coal/empSalary/entity/EmpSalaryEntity.java b/src/main/java/cn/lihongjie/coal/empSalary/entity/EmpSalaryEntity.java index 2cff1611..9537accc 100644 --- a/src/main/java/cn/lihongjie/coal/empSalary/entity/EmpSalaryEntity.java +++ b/src/main/java/cn/lihongjie/coal/empSalary/entity/EmpSalaryEntity.java @@ -169,6 +169,13 @@ public class EmpSalaryEntity extends OrgCommonEntity implements SalaryItemData { @DictTranslate(dictKey = DictCode.SEX) private String sexName; + @Comment("政治面貌") + private String politicalStatus; + + @DictTranslate(dictKey = DictCode.EMP_POLITICALSTATUS) + private String politicalStatusName; + + @Comment("民族") private String nation; @@ -345,6 +352,9 @@ public class EmpSalaryEntity extends OrgCommonEntity implements SalaryItemData { this.empCode = salaryEntity.empCode; this.sex = salaryEntity.sex; this.sexName = salaryEntity.sexName; + this.politicalStatus = salaryEntity.politicalStatus; + this.politicalStatusName = salaryEntity.politicalStatusName; + this.nation = salaryEntity.nation; this.nationName = salaryEntity.nationName; this.marriage = salaryEntity.marriage; @@ -602,6 +612,11 @@ public class EmpSalaryEntity extends OrgCommonEntity implements SalaryItemData { map.put("sexName", this.sexName); + map.put("politicalStatus", this.politicalStatus); + + map.put("politicalStatusName", this.politicalStatusName); + + map.put("nation", this.nation); map.put("nationName", this.nationName); @@ -717,6 +732,9 @@ public class EmpSalaryEntity extends OrgCommonEntity implements SalaryItemData { this.empCode = (String) ctx.get("empCode"); this.sex = (String) ctx.get("sex"); this.sexName = (String) ctx.get("sexName"); + this.politicalStatus = (String) ctx.get("politicalStatus"); + this.politicalStatusName = (String) ctx.get("politicalStatusName"); + this.nation = (String) ctx.get("nation"); this.nationName = (String) ctx.get("nationName"); this.marriage = (String) ctx.get("marriage"); diff --git a/src/main/java/cn/lihongjie/coal/empSalary/service/EmpSalaryService.java b/src/main/java/cn/lihongjie/coal/empSalary/service/EmpSalaryService.java index 5bb13705..32dcd0c2 100644 --- a/src/main/java/cn/lihongjie/coal/empSalary/service/EmpSalaryService.java +++ b/src/main/java/cn/lihongjie/coal/empSalary/service/EmpSalaryService.java @@ -6,12 +6,11 @@ import cn.lihongjie.coal.base.dto.IdRequest; import cn.lihongjie.coal.base.entity.OrgCommonEntity; import cn.lihongjie.coal.base.mapper.CommonMapper; import cn.lihongjie.coal.base.service.BaseService; -import cn.lihongjie.coal.common.ExcelUtils; -import cn.lihongjie.coal.common.MapUtils; -import cn.lihongjie.coal.common.ReflectUtils; +import cn.lihongjie.coal.common.*; import cn.lihongjie.coal.empMonthAttendance.entity.EmpMonthAttendanceEntity; import cn.lihongjie.coal.empMonthAttendance.mapper.EmpMonthAttendanceMapper; import cn.lihongjie.coal.empSalary.dto.*; +import cn.lihongjie.coal.empSalary.dto.EmpSalaryReportRequest; import cn.lihongjie.coal.empSalary.entity.EmpSalaryEntity; import cn.lihongjie.coal.empSalary.mapper.EmpSalaryMapper; import cn.lihongjie.coal.empSalary.repository.EmpSalaryRepository; @@ -27,12 +26,15 @@ import cn.lihongjie.coal.employee.service.EmployeeService; import cn.lihongjie.coal.exception.BizException; import cn.lihongjie.coal.file.service.FileService; +import com.google.common.base.CaseFormat; + import groovy.lang.Binding; import groovy.lang.GroovyClassLoader; import groovy.lang.Script; import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; +import jakarta.persistence.Tuple; import lombok.Cleanup; import lombok.SneakyThrows; @@ -48,6 +50,7 @@ import org.redisson.api.RedissonClient; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.convert.ConversionService; import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; @@ -81,6 +84,128 @@ public class EmpSalaryService extends BaseService + + <#if field?is_first> , + + ${field} + + <#if field?has_next>, + + <#list fieldInfos as field> + + <#if field?is_first> , + + ${field.function}(${field.fieldName}) as ${field.fieldName} + + <#if field?has_next>, + + + + from t_emp_salary + + + where 1=1 + + <#if startTime??> and batchYearMonth >= :startTime + + <#if endTime??> and batchYearMonth <= :endTime + + <#if employeeIds??> and employee_id in :employeeIds + + <#if departmentIds??> and department_id in :departmentIds + + <#if jobPostIds??> and job_post_id in :jobPostIds + + <#if nations??> and nation in :nations + <#if marriages??> and marriage in :marriages + <#if educations??> and education in :educations + + + <#if empName??> and emp_name like :empName + + <#if departmentName??> and department_name like :departmentName + + <#if jobPostName??> and job_post_name like :jobPostName + + <#if idCard??> and id_card like :idCard + + <#if phone??> and phone like :phone + + + + group by 1, date_trunc(${timeDimension}, batchYearMonth) + <#list reportField as field> + + <#if field?is_first> , + + ${field} + + <#if field?has_next>, + + + + + + + + + + """, + request); + + var countSql = "select count(1) from (" + sql + ") as t"; + + var selectSql = + "select * from (" + + sql + + ") as t limit " + + request.getPageSize() + + " offset " + + request.getPageNo() * request.getPageSize(); + + Integer count = JpaUtils.execNativeQuery(em, countSql, request, Integer.class).get(0); + + List data = JpaUtils.execNativeQuery(em, selectSql, request, Tuple.class); + + var resultList = JpaUtils.convertTuplesToMap(data); + + var ans = + resultList.stream() + .map( + x -> + ((Map) x) + .entrySet().stream() + .collect( + Collectors.toMap( + (Map.Entry e) -> + CaseFormat + .LOWER_UNDERSCORE + .to( + CaseFormat + .LOWER_CAMEL, + e.getKey() + .toString()), + e -> + ObjectUtils + .defaultIfNull( + e + .getValue(), + "")))) + .toList(); + + return new PageImpl<>(ans, PageRequest.of(0, request.getPageSize()), count); + } + public Page list(CommonQuery query) { Page page = repository.findAll( diff --git a/src/main/java/cn/lihongjie/coal/empSalaryReport/service/EmpSalaryReportService.java b/src/main/java/cn/lihongjie/coal/empSalaryReport/service/EmpSalaryReportService.java index 4189b146..56122acd 100644 --- a/src/main/java/cn/lihongjie/coal/empSalaryReport/service/EmpSalaryReportService.java +++ b/src/main/java/cn/lihongjie/coal/empSalaryReport/service/EmpSalaryReportService.java @@ -12,6 +12,9 @@ import cn.lihongjie.coal.empSalaryReport.mapper.EmpSalaryReportMapper; import cn.lihongjie.coal.empSalaryReport.repository.EmpSalaryReportRepository; import cn.lihongjie.coal.exception.BizException; +import jakarta.persistence.EntityManager; +import jakarta.persistence.PersistenceContext; + import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -78,4 +81,8 @@ public class EmpSalaryReportService return page.map(this.mapper::toDto); } + + @PersistenceContext EntityManager em; + + } diff --git a/src/main/java/cn/lihongjie/coal/employee/dto/CreateEmployeeDto.java b/src/main/java/cn/lihongjie/coal/employee/dto/CreateEmployeeDto.java index b957b9b6..a2b9aa5e 100644 --- a/src/main/java/cn/lihongjie/coal/employee/dto/CreateEmployeeDto.java +++ b/src/main/java/cn/lihongjie/coal/employee/dto/CreateEmployeeDto.java @@ -19,6 +19,9 @@ public class CreateEmployeeDto extends OrgCommonDto { @Comment("性别") private String sex; + @Comment("政治面貌") + private String politicalStatus; + @Comment("民族") private String nation; diff --git a/src/main/java/cn/lihongjie/coal/employee/dto/EmployeeCalculateDto.java b/src/main/java/cn/lihongjie/coal/employee/dto/EmployeeCalculateDto.java index eecae5c8..1c8d47f5 100644 --- a/src/main/java/cn/lihongjie/coal/employee/dto/EmployeeCalculateDto.java +++ b/src/main/java/cn/lihongjie/coal/employee/dto/EmployeeCalculateDto.java @@ -22,7 +22,8 @@ import java.util.Map; public class EmployeeCalculateDto extends OrgCommonDto { @Comment("性别") private String sex; - + @Comment("政治面貌") + private String politicalStatus; @Comment("性别-名称") @DictTranslate(dictKey = DictCode.SEX) private String sexName; diff --git a/src/main/java/cn/lihongjie/coal/employee/dto/EmployeeDto.java b/src/main/java/cn/lihongjie/coal/employee/dto/EmployeeDto.java index 421fca2a..c10a4c45 100644 --- a/src/main/java/cn/lihongjie/coal/employee/dto/EmployeeDto.java +++ b/src/main/java/cn/lihongjie/coal/employee/dto/EmployeeDto.java @@ -30,6 +30,13 @@ public class EmployeeDto extends OrgCommonDto { @DictTranslate(dictKey = DictCode.SEX) private String sexName; + @Comment("政治面貌") + private String politicalStatus; + + @DictTranslate(dictKey = DictCode.EMP_POLITICALSTATUS) + private String politicalStatusName; + + @Comment("民族") private String nation; diff --git a/src/main/java/cn/lihongjie/coal/employee/dto/UpdateEmployeeDto.java b/src/main/java/cn/lihongjie/coal/employee/dto/UpdateEmployeeDto.java index 3cca7bd9..fb64b545 100644 --- a/src/main/java/cn/lihongjie/coal/employee/dto/UpdateEmployeeDto.java +++ b/src/main/java/cn/lihongjie/coal/employee/dto/UpdateEmployeeDto.java @@ -20,6 +20,9 @@ public class UpdateEmployeeDto extends OrgCommonDto { @Comment("性别") private String sex; + @Comment("政治面貌") + private String politicalStatus; + @Comment("民族") private String nation; diff --git a/src/main/java/cn/lihongjie/coal/employee/entity/EmployeeEntity.java b/src/main/java/cn/lihongjie/coal/employee/entity/EmployeeEntity.java index 976b572e..2dae6073 100644 --- a/src/main/java/cn/lihongjie/coal/employee/entity/EmployeeEntity.java +++ b/src/main/java/cn/lihongjie/coal/employee/entity/EmployeeEntity.java @@ -30,6 +30,10 @@ public class EmployeeEntity extends OrgCommonEntity { @Comment("性别") private String sex; + @Comment("政治面貌") + private String politicalStatus; + + @Comment("民族") private String nation; diff --git a/src/main/resources/config/dictionary.json b/src/main/resources/config/dictionary.json index 909a7fce..121160a1 100644 --- a/src/main/resources/config/dictionary.json +++ b/src/main/resources/config/dictionary.json @@ -1675,7 +1675,66 @@ } ] }, + { + "code": "emp.politicalStatus", + "name": "政治面貌", + "item": [ + { + "code": "0", + "name": "中共党员" + }, + { + "code": "1", + "name": "中共预备党员" + }, + { + "code": "2", + "name": "共青团员" + }, + { + "code": "3", + "name": "民革党员" + }, + { + "code": "4", + "name": "民盟盟员" + }, + { + "code": "5", + "name": "民建会员" + }, + { + "code": "6", + "name": "民进会员" + }, + { + "code": "7", + "name": "农工党党员" + }, + { + "code": "8", + "name": "致公党党员" + }, + { + "code": "9", + "name": "九三学社社员" + }, + { + "code": "10", + "name": "台盟盟员" + }, + { + "code": "11", + "name": "无党派人士" + }, + { + "code": "12", + "name": "群众" + } + + ] + }, { "code": "emp.salary.batch.status", "name": "工资批次状态",