This commit is contained in:
2024-08-18 15:59:24 +08:00
parent cf4a0d9db1
commit 2816607419
13 changed files with 312 additions and 4 deletions

View File

@@ -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";

View File

@@ -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);
}
}

View File

@@ -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;

View File

@@ -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<String> reportFields;
private List<FieldInfo> fieldInfos;
private LocalDate startTime;
private LocalDate endTime;
/** 过滤条件 */
private List<String> employeeIds;
private List<String> departmentIds;
private List<String> jobPostIds;
private String empName;
private String departmentName;
private String jobPostName;
private String idCard;
private String phone;
private List<String> nations;
private List<String> marriages;
private List<String> educations;
private List<String> politicalStatuses;
@Data
public static class FieldInfo {
private String fieldName;
@Comment("sum avg count max min")
private String function;
}
}

View File

@@ -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");

View File

@@ -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<EmpSalaryEntity, EmpSalaryRepo
return mapper.toDto(entity);
}
public Object report(EmpSalaryReportRequest request) {
String sql =
FreeMakerUtils.render(
"""
select date_trunc(${timeDimension}, batchYearMonth) as time,
array_agg(id) as ids
<#list reportField as field>
<#if field?is_first> ,</#if>
${field}
<#if field?has_next>,</#if>
</#list>
<#list fieldInfos as field>
<#if field?is_first> ,</#if>
${field.function}(${field.fieldName}) as ${field.fieldName}
<#if field?has_next>,</#if>
</#list>
from t_emp_salary
where 1=1
<#if startTime??> and batchYearMonth >= :startTime </#if>
<#if endTime??> and batchYearMonth <= :endTime </#if>
<#if employeeIds??> and employee_id in :employeeIds </#if>
<#if departmentIds??> and department_id in :departmentIds </#if>
<#if jobPostIds??> and job_post_id in :jobPostIds </#if>
<#if nations??> and nation in :nations </#if>
<#if marriages??> and marriage in :marriages </#if>
<#if educations??> and education in :educations </#if>
<#if empName??> and emp_name like :empName </#if>
<#if departmentName??> and department_name like :departmentName </#if>
<#if jobPostName??> and job_post_name like :jobPostName </#if>
<#if idCard??> and id_card like :idCard </#if>
<#if phone??> and phone like :phone </#if>
group by 1, date_trunc(${timeDimension}, batchYearMonth)
<#list reportField as field>
<#if field?is_first> ,</#if>
${field}
<#if field?has_next>,</#if>
</#list>
""",
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<Tuple> 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<EmpSalaryDto> list(CommonQuery query) {
Page<EmpSalaryEntity> page =
repository.findAll(

View File

@@ -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;
}

View File

@@ -19,6 +19,9 @@ public class CreateEmployeeDto extends OrgCommonDto {
@Comment("性别")
private String sex;
@Comment("政治面貌")
private String politicalStatus;
@Comment("民族")
private String nation;

View File

@@ -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;

View File

@@ -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;

View File

@@ -20,6 +20,9 @@ public class UpdateEmployeeDto extends OrgCommonDto {
@Comment("性别")
private String sex;
@Comment("政治面貌")
private String politicalStatus;
@Comment("民族")
private String nation;

View File

@@ -30,6 +30,10 @@ public class EmployeeEntity extends OrgCommonEntity {
@Comment("性别")
private String sex;
@Comment("政治面貌")
private String politicalStatus;
@Comment("民族")
private String nation;

View File

@@ -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": "工资批次状态",