diff --git a/src/main/java/cn/lihongjie/coal/common/GroovyScriptUtils.java b/src/main/java/cn/lihongjie/coal/common/GroovyScriptUtils.java index c776b8a1..80bc4748 100644 --- a/src/main/java/cn/lihongjie/coal/common/GroovyScriptUtils.java +++ b/src/main/java/cn/lihongjie/coal/common/GroovyScriptUtils.java @@ -6,6 +6,7 @@ import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import groovy.lang.Binding; +import groovy.lang.Closure; import groovy.lang.GroovyClassLoader; import groovy.lang.Script; @@ -25,10 +26,6 @@ import org.codehaus.groovy.control.customizers.SecureASTCustomizer; import org.springframework.util.StopWatch; import java.math.BigDecimal; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.time.YearMonth; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -47,34 +44,7 @@ public class GroovyScriptUtils { private static final Cache, Script> scriptInstanceCache = CacheBuilder.newBuilder().maximumSize(10000).build(); - public static SecureASTCustomizer SecurityCustomizer = - new SecureASTCustomizer() { - { - setAllowedImports(List.of("java.lang.Math")); - setAllowedConstantTypesClasses( - Arrays.asList( - Integer.class, - Long.class, - Double.class, - Float.class, - String.class, - Boolean.class, - LocalDateTime.class, - LocalDate.class, - LocalTime.class, - YearMonth.class, - Math.class)); - - setAllowedReceiversClasses( - Arrays.asList( - Math.class, - Integer.class, - Float.class, - Double.class, - Long.class, - BigDecimal.class)); - } - }; + public static SecureASTCustomizer SecurityCustomizer; public String replaceVariable( String patternstr, String script, Function mapper) { @@ -114,10 +84,55 @@ public class GroovyScriptUtils { private static final GroovyClassLoader groovyClassLoader; static { + initSecurityCustomizer(); CompilerConfiguration config = new CompilerConfiguration(); groovyClassLoader = new GroovyClassLoader(GroovyScriptUtils.class.getClassLoader(), config); } + public static void initSecurityCustomizer() { + + SecurityCustomizer = + new SecureASTCustomizer() { + { + setAllowedImports(List.of("java.lang.Math")); +// setAllowedConstantTypesClasses( +// Arrays.asList( +// int.class, +// long.class, +// double.class, +// float.class, +// Object.class, +// Map.class, +// Integer.class, +// Long.class, +// Double.class, +// Float.class, +// String.class, +// Boolean.class, +// LocalDateTime.class, +// LocalDate.class, +// LocalTime.class, +// YearMonth.class, +// Math.class)); + + setAllowedReceiversClasses( + Arrays.asList( + Object[].class, + Arrays.class, + java.math.RoundingMode.class, + Closure.class, + Map.class, + Object.class, + Math.class, + Integer.class, + Float.class, + Double.class, + Long.class, + BigDecimal.class)); + } + }; + } + public static List variables(String formula) { if (StringUtils.isEmpty(formula)) { return new ArrayList<>(); diff --git a/src/main/java/cn/lihongjie/coal/common/ReflectUtils.java b/src/main/java/cn/lihongjie/coal/common/ReflectUtils.java index 877317ec..d94cf8c9 100644 --- a/src/main/java/cn/lihongjie/coal/common/ReflectUtils.java +++ b/src/main/java/cn/lihongjie/coal/common/ReflectUtils.java @@ -4,6 +4,7 @@ import cn.lihongjie.coal.base.dto.BaseDto; import cn.lihongjie.coal.base.entity.BaseEntity; import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; @@ -22,6 +23,7 @@ import org.jetbrains.annotations.NotNull; import org.springframework.util.ReflectionUtils; import java.lang.reflect.Field; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; @@ -44,7 +46,13 @@ public class ReflectUtils { CacheBuilder.newBuilder().maximumSize(10000).build(); - private static final ObjectMapper objectMapper = new ObjectMapper(); + private static final ObjectMapper objectMapper; + + static { + objectMapper = new ObjectMapper(); + objectMapper.registerModule(new com.fasterxml.jackson.datatype.jsr310.JavaTimeModule()); + objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + } public static String getId(Object o) { @@ -198,7 +206,7 @@ public class ReflectUtils { public static Map toMap(Object entity) { if (entity == null) { - return Map.of(); + return new HashMap<>(); } 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 e0c033e8..b6d7ac21 100644 --- a/src/main/java/cn/lihongjie/coal/empSalary/dto/EmpSalaryDto.java +++ b/src/main/java/cn/lihongjie/coal/empSalary/dto/EmpSalaryDto.java @@ -13,6 +13,7 @@ import lombok.Data; import org.hibernate.annotations.Comment; import java.math.BigDecimal; +import java.time.LocalDate; @Data public class EmpSalaryDto extends OrgCommonDto { @@ -82,4 +83,203 @@ public class EmpSalaryDto extends OrgCommonDto { private BigDecimal item48; private BigDecimal item49; private BigDecimal item50; + + private BigDecimal yfheji; + private BigDecimal kfheji; + private BigDecimal sfheji; + + + + /** 出勤记录冗余字段 */ + @Comment("是否全勤") + private Boolean fullAttendance; + + @Comment("是否满勤") + private Boolean fullWork; + + @Comment("应出勤天数") + private Double shouldAttendanceDays; + + @Comment("实际出勤天数") + private Double actualAttendanceDays; + + @Comment("加班天数") + private Double overtimeDays; + + @Comment("请假天数") + private Double leaveDays; + + @Comment("事假天数") + private Double personalLeaveDays; + + @Comment("病假天数") + private Double sickLeaveDays; + + @Comment("婚假天数") + private Double marriageLeaveDays; + + @Comment("产假天数") + private Double maternityLeaveDays; + + @Comment("陪产假天数") + private Double paternityLeaveDays; + + @Comment("丧假天数") + private Double funeralLeaveDays; + + @Comment("年假天数") + private Double annualLeaveDays; + + @Comment("迟到次数") + private Integer lateTimes; + + @Comment("迟到分钟数") + private Integer lateMinutes; + + @Comment("早退次数") + private Integer earlyTimes; + + @Comment("早退分钟数") + private Integer earlyMinutes; + + @Comment("旷工次数") + private Integer absenteeismTimes; + + /** 员工信息冗余字段 */ + private String empName; + + private String empCode; + + @Comment("性别") + private String sex; + + @Comment("性别-名称") + @DictTranslate(dictKey = DictCode.SEX) + private String sexName; + + @Comment("民族") + private String nation; + + @Comment("民族-名称") + @DictTranslate(dictKey = DictCode.NATION) + private String nationName; + + @Comment("婚姻状况") + private String marriage; + + @Comment("婚姻状况-名称") + @DictTranslate(dictKey = DictCode.MARRIAGE) + private String marriageName; + + @Comment("入职时间") + private LocalDate entryDate; + + @Comment("身份证号") + private String idCard; + + @Comment("学历") + private String education; + + @Comment("学历-名称") + @DictTranslate(dictKey = DictCode.EDUCATION) + private String educationName; + + @Comment("毕业学校") + private String school; + + @Comment("籍贯") + private String nativePlace; + + @Comment("住址") + private String address; + + @Comment("手机号") + private String phone; + + @Comment("部门") + private String departmentId; + + @Comment("部门") + private String departmentCode; + + @Comment("部门") + private String departmentName; + + @Comment("岗位") + private String jobPostId; + + @Comment("岗位") + private String jobPostCode; + + @Comment("岗位") + private String jobPostName; + + @Comment("银行编码") + private String bank; + + @DictTranslate(dictKey = DictCode.BANK) + private String bankName; + + @Comment("银行卡号") + private String bankCardNumber; + + @Comment("收款人姓名") + private String bankCardName; + + @Comment("离职时间") + private LocalDate resignDate; + + @Comment("离职原因") + private String resignReason; + + @Comment("员工状态") + private String empStatus; + + @DictTranslate(dictKey = DictCode.EMP_STATUS) + private String empStatusName; + + @Comment("养老保险基数") + private Double insurance1Base; + + @Comment("养老保险比例") + private Double insurance1Percent; + + @Comment("医疗保险基数") + private Double insurance2Base; + + @Comment("医疗保险比例") + private Double insurance2Percent; + + @Comment("失业保险基数") + private Double insurance3Base; + + @Comment("失业保险比例") + private Double insurance3Percent; + + @Comment("工伤保险基数") + private Double insurance4Base; + + @Comment("工伤保险比例") + private Double insurance4Percent; + + @Comment("生育保险基数") + private Double insurance5Base; + + @Comment("生育保险比例") + private Double insurance5Percent; + + @Comment("住房公积金基数") + private Double insurance6Base; + + @Comment("住房公积金比例") + private Double insurance6Percent; + + @Comment("工龄") + private Double workAge; + + @Comment("年龄") + private Double age; + + @Comment("出生日期") + private LocalDate birthday; } 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 366ea438..79c56b53 100644 --- a/src/main/java/cn/lihongjie/coal/empSalary/service/EmpSalaryService.java +++ b/src/main/java/cn/lihongjie/coal/empSalary/service/EmpSalaryService.java @@ -6,7 +6,9 @@ import cn.lihongjie.coal.base.entity.OrgCommonEntity; import cn.lihongjie.coal.base.service.BaseService; import cn.lihongjie.coal.common.GroovyScriptUtils; import cn.lihongjie.coal.common.ReflectUtils; +import cn.lihongjie.coal.empMonthAttendance.dto.EmpMonthAttendanceDto; import cn.lihongjie.coal.empMonthAttendance.entity.EmpMonthAttendanceEntity; +import cn.lihongjie.coal.empMonthAttendance.mapper.EmpMonthAttendanceMapper; import cn.lihongjie.coal.empSalary.dto.CreateEmpSalaryDto; import cn.lihongjie.coal.empSalary.dto.EmpSalaryDto; import cn.lihongjie.coal.empSalary.dto.InitSalaryDto; @@ -14,7 +16,9 @@ import cn.lihongjie.coal.empSalary.dto.UpdateEmpSalaryDto; import cn.lihongjie.coal.empSalary.entity.EmpSalaryEntity; import cn.lihongjie.coal.empSalary.mapper.EmpSalaryMapper; import cn.lihongjie.coal.empSalary.repository.EmpSalaryRepository; +import cn.lihongjie.coal.empSalaryBatch.dto.EmpSalaryBatchDto; import cn.lihongjie.coal.empSalaryBatch.entity.EmpSalaryBatchEntity; +import cn.lihongjie.coal.empSalaryBatch.mapper.EmpSalaryBatchMapper; import cn.lihongjie.coal.empSalaryBatch.service.EmpSalaryBatchService; import cn.lihongjie.coal.empSalaryItem.entity.EmpSalaryItemEntity; import cn.lihongjie.coal.empSalaryItem.service.EmpSalaryItemService; @@ -27,6 +31,8 @@ import groovy.lang.Binding; import groovy.lang.GroovyClassLoader; import groovy.lang.Script; +import io.vavr.control.Try; + import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; @@ -144,12 +150,7 @@ public class EmpSalaryService extends BaseService queryHisSalary(List employeesIds) { - - return this.em - .createQuery( - "select s from EmpSalaryEntity s where s.employee.id in :empIds and rank() over (partition by s.employee.id order by s.createTime desc ) = 1", - EmpSalaryEntity.class) - .setParameter("empIds", employeesIds) - .getResultList(); - } + @Autowired EmpMonthAttendanceMapper empMonthAttendanceMapper; private String genScript(EmpSalaryBatchEntity batch) { String script = ""; @@ -534,6 +523,28 @@ public class EmpSalaryService extends BaseService queryHisSalary(List employeesIds) { + + return new ArrayList<>(); + // return this.em + // .createQuery( + // "select s from EmpSalaryEntity s where s.employee.id in :empIds + // and rank() over (partition by s.employee.id order by s.createTime desc ) = 1", + // EmpSalaryEntity.class) + // .setParameter("empIds", employeesIds) + // .getResultList(); + } /** * 构建计算上下文 @@ -545,10 +556,21 @@ public class EmpSalaryService extends BaseService buildCtx( - EmpSalaryBatchEntity batch, + EmpSalaryBatchEntity batchEntity, EmployeeDto employee, - EmpMonthAttendanceEntity attendance, - EmpSalaryEntity salary) { + EmpMonthAttendanceEntity attendanceEntity, + EmpSalaryEntity salaryEntity) { + + EmpSalaryBatchDto batch = empSalaryBatchMapper.toDto(batchEntity); + + EmpMonthAttendanceDto attendance = empMonthAttendanceMapper.toDto(attendanceEntity); + + EmpSalaryDto salary = empSalaryMapper.toDto(salaryEntity); + + // if (batch!=null )em.detach(batch); + // em.detach(employee); + // if (attendance!=null )em.detach(attendance); + // if (salary!=null )em.detach(salary); Map empMap = employee == null ? new HashMap<>() : ReflectUtils.toMap(employee); @@ -557,6 +579,13 @@ public class EmpSalaryService extends BaseService empMap.put("departmentId", employee.getDepartment().getId())); + Try.run(() -> empMap.put("departmentCode", employee.getDepartment().getCode())); + Try.run(() -> empMap.put("departmentName", employee.getDepartment().getName())); + Try.run(() -> empMap.put("jobPostId", employee.getJobPost().getId())); + Try.run(() -> empMap.put("jobPostCode", employee.getJobPost().getCode())); + Try.run(() -> empMap.put("jobPostName", employee.getJobPost().getName())); } Map batchMap = batch == null ? new HashMap<>() : ReflectUtils.toMap(batch); @@ -588,4 +617,20 @@ public class EmpSalaryService extends BaseService { sysItemScript + .append("def ") .append(sysItem.getCode()) .append(" = ") .append(sysItem.getItemExpression().trim())