批次增加审核功能

This commit is contained in:
2024-08-13 09:26:46 +08:00
parent 0fa0d2b035
commit 980342d4e1
7 changed files with 458 additions and 56 deletions

View File

@@ -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<Class<?>, 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<String, String> 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<String> variables(String formula) {
if (StringUtils.isEmpty(formula)) {
return new ArrayList<>();

View File

@@ -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<String, Object> toMap(Object entity) {
if (entity == null) {
return Map.of();
return new HashMap<>();
}

View File

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

View File

@@ -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<EmpSalaryEntity, EmpSalaryRepo
return scriptObj;
}
private static @NotNull GroovyClassLoader initClassLoader(GroovyClassLoader groovyClassLoader) {
CompilerConfiguration config = new CompilerConfiguration();
config.addCompilationCustomizers(GroovyScriptUtils.SecurityCustomizer);
groovyClassLoader = new GroovyClassLoader(GroovyScriptUtils.class.getClassLoader(), config);
return groovyClassLoader;
}
@Autowired EmpSalaryBatchMapper empSalaryBatchMapper;
/**
* 查询批次可选的员工
@@ -315,9 +316,6 @@ public class EmpSalaryService extends BaseService<EmpSalaryEntity, EmpSalaryRepo
}
}
/** 初始化工资 */
@SneakyThrows
public void initSalary(InitSalaryDto initSalaryDto) {
@@ -471,16 +469,7 @@ public class EmpSalaryService extends BaseService<EmpSalaryEntity, EmpSalaryRepo
log.info(stopWatch.prettyPrint());
}
}
private List<EmpSalaryEntity> queryHisSalary(List<String> 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<EmpSalaryEntity, EmpSalaryRepo
.collect(Collectors.joining(",")));
}
}
@Autowired EmpSalaryMapper empSalaryMapper;
private static @NotNull GroovyClassLoader initClassLoader(GroovyClassLoader groovyClassLoader) {
GroovyScriptUtils.initSecurityCustomizer();
CompilerConfiguration config = new CompilerConfiguration();
config.addCompilationCustomizers(GroovyScriptUtils.SecurityCustomizer);
groovyClassLoader = new GroovyClassLoader(GroovyScriptUtils.class.getClassLoader(), config);
return groovyClassLoader;
}
private List<EmpSalaryEntity> queryHisSalary(List<String> 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<EmpSalaryEntity, EmpSalaryRepo
* @return
*/
public Map<String, Object> 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<String, Object> empMap =
employee == null ? new HashMap<>() : ReflectUtils.toMap(employee);
@@ -557,6 +579,13 @@ public class EmpSalaryService extends BaseService<EmpSalaryEntity, EmpSalaryRepo
empMap.put("empName", employee.getName());
empMap.put("empCode", employee.getCode());
Try.run(() -> 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<String, Object> batchMap = batch == null ? new HashMap<>() : ReflectUtils.toMap(batch);
@@ -588,4 +617,20 @@ public class EmpSalaryService extends BaseService<EmpSalaryEntity, EmpSalaryRepo
log.info("删除工资数据 {} 条", cnt);
}
public void sendToAudit(IdRequest request){
EmpSalaryBatchEntity batch = this.batchService.get(request.getId());
if (!StringUtils.equalsAny(batch.getBatchStatus(), "1")){
throw new BizException("批次状态不正确");
}
batch.setBatchStatus("2");
}
}

View File

@@ -70,4 +70,40 @@ public class EmpSalaryBatchController {
this.service.unarchive(request);
return true;
}
@PostMapping("/sendToAudit")
public Object sendToAudit(@RequestBody IdRequest request) {
this.service.sendToAudit(request);
return true;
}
@PostMapping("/unDoSendToAudit")
public Object unDoSendToAudit(@RequestBody IdRequest request) {
this.service.unDoSendToAudit(request);
return true;
}
@PostMapping("/audit")
public Object audit(@RequestBody IdRequest request) {
this.service.audit(request);
return true;
}
@PostMapping("/undoAudit")
public Object undoAudit(@RequestBody IdRequest request) {
this.service.undoAudit(request);
return true;
}
@PostMapping("/batchArchive")
public Object batchArchive(@RequestBody IdRequest request) {
this.service.batchArchive(request);
return true;
}
@PostMapping("/undoBatchArchive")
public Object undoBatchArchive(@RequestBody IdRequest request) {
this.service.undoBatchArchive(request);
return true;
}
}

View File

@@ -160,4 +160,101 @@ public class EmpSalaryBatchService
public void unarchive(IdRequest dto) {
this.repository.unArchive(dto);
}
public void sendToAudit(IdRequest request){
EmpSalaryBatchEntity batch = this.get(request.getId());
if (!StringUtils.equalsAny(batch.getBatchStatus(), "1")){
throw new BizException("批次状态不正确");
}
batch.setBatchStatus("2");
this.save(batch);
}
public void unDoSendToAudit(IdRequest request){
EmpSalaryBatchEntity batch = this.get(request.getId());
if (!StringUtils.equalsAny(batch.getBatchStatus(), "2")){
throw new BizException("批次状态不正确");
}
batch.setBatchStatus("1");
this.save(batch);
}
public void audit(IdRequest request){
EmpSalaryBatchEntity batch = this.get(request.getId());
if (!StringUtils.equalsAny(batch.getBatchStatus(), "2")){
throw new BizException("批次状态不正确");
}
batch.setBatchStatus("3");
this.save(batch);
}
public void undoAudit(IdRequest request){
EmpSalaryBatchEntity batch = this.get(request.getId());
if (!StringUtils.equalsAny(batch.getBatchStatus(), "3")){
throw new BizException("批次状态不正确");
}
batch.setBatchStatus("2");
this.save(batch);
}
public void batchArchive(IdRequest request){
EmpSalaryBatchEntity batch = this.get(request.getId());
if (!StringUtils.equalsAny(batch.getBatchStatus(), "3")){
throw new BizException("批次状态不正确");
}
batch.setBatchStatus("4");
batch.setArchiveStatus("1");
this.save(batch);
}
public void undoBatchArchive(IdRequest request){
EmpSalaryBatchEntity batch = this.get(request.getId());
if (!StringUtils.equalsAny(batch.getBatchStatus(), "4")){
throw new BizException("批次状态不正确");
}
batch.setBatchStatus("3");
batch.setArchiveStatus("0");
this.save(batch);
}
}

View File

@@ -743,6 +743,7 @@ public class EmpSalaryItemService
switch (sysItem.getItemType()) {
case "0", "1" -> {
sysItemScript
.append("def ")
.append(sysItem.getCode())
.append(" = ")
.append(sysItem.getItemExpression().trim())