mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
重新计算预览
This commit is contained in:
@@ -86,6 +86,12 @@ public class EmpSalaryController {
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/recalculatePreview")
|
||||
public Object recalculatePreview(@RequestBody UpdateEmpSalaryDto request) {
|
||||
this.service.recalculatePreview(request);
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/archive")
|
||||
public Object archive(@RequestBody IdRequest request) {
|
||||
this.service.archive(request);
|
||||
|
||||
@@ -282,4 +282,15 @@ public class EmpSalaryDto extends OrgCommonDto {
|
||||
|
||||
@Comment("出生日期")
|
||||
private LocalDate birthday;
|
||||
|
||||
|
||||
/**
|
||||
* 批次数据冗余
|
||||
*/
|
||||
|
||||
@Comment("批次年月")
|
||||
private LocalDate batchYearMonth;
|
||||
|
||||
@Comment("批次号")
|
||||
private String batchNo;
|
||||
}
|
||||
|
||||
@@ -277,6 +277,17 @@ public class EmpSalaryEntity extends OrgCommonEntity {
|
||||
@Comment("出生日期")
|
||||
private LocalDate birthday;
|
||||
|
||||
|
||||
/**
|
||||
* 批次数据冗余
|
||||
*/
|
||||
|
||||
@Comment("批次年月")
|
||||
private LocalDate batchYearMonth;
|
||||
|
||||
@Comment("批次号")
|
||||
private String batchNo;
|
||||
|
||||
@Comment("归档状态")
|
||||
@ColumnDefault("'0'")
|
||||
private String archiveStatus = "0";
|
||||
@@ -288,6 +299,9 @@ public class EmpSalaryEntity extends OrgCommonEntity {
|
||||
updateEmpInfo(salaryEntity);
|
||||
|
||||
updateAttendance(salaryEntity);
|
||||
|
||||
this.batchNo = salaryEntity.batchNo;
|
||||
this.batchYearMonth = salaryEntity.batchYearMonth;
|
||||
}
|
||||
|
||||
private void updateAttendance(EmpSalaryEntity salaryEntity) {
|
||||
|
||||
@@ -200,9 +200,54 @@ public class EmpSalaryService extends BaseService<EmpSalaryEntity, EmpSalaryRepo
|
||||
}
|
||||
|
||||
/** 针对某个员工重新计算, 用于编辑表单的预览 */
|
||||
public EmpSalaryDto recalculatePreview(UpdateEmpSalaryDto dto) {
|
||||
@SneakyThrows
|
||||
public UpdateEmpSalaryDto recalculatePreview(UpdateEmpSalaryDto dto) {
|
||||
|
||||
return null;
|
||||
EmpSalaryBatchEntity batch = this.batchService.get(dto.getBatch());
|
||||
|
||||
EmpSalaryEntity salary = this.get(dto.getId());
|
||||
|
||||
GroovyClassLoader groovyClassLoader = null;
|
||||
groovyClassLoader = initClassLoader(groovyClassLoader);
|
||||
|
||||
Script scriptObj = initScriptClass(groovyClassLoader, genScript(batch));
|
||||
|
||||
Map<String, Object> ctx = buildCtx(null, null, null, salary);
|
||||
|
||||
// 覆盖工资项目
|
||||
|
||||
overWriteSalaryItem(ctx, ReflectUtils.toMap(dto));
|
||||
|
||||
scriptObj.setBinding(new Binding(Map.of("salary", ctx)));
|
||||
|
||||
scriptObj.run();
|
||||
|
||||
updateItems(ctx, dto);
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
private void updateItems(Map<String, Object> ctx, UpdateEmpSalaryDto dto) {
|
||||
|
||||
for (String string : ctx.keySet()) {
|
||||
|
||||
if (string.startsWith("item")) {
|
||||
|
||||
Object value = ctx.get(string);
|
||||
|
||||
ReflectUtils.writeField(dto, string, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void overWriteSalaryItem(Map<String, Object> ctx, Map<String, Object> map) {
|
||||
|
||||
for (String string : map.keySet()) {
|
||||
|
||||
if (string.startsWith("item")) {
|
||||
ctx.put(string, map.get(string));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 重新计算 */
|
||||
@@ -469,6 +514,7 @@ public class EmpSalaryService extends BaseService<EmpSalaryEntity, EmpSalaryRepo
|
||||
log.info(stopWatch.prettyPrint());
|
||||
}
|
||||
}
|
||||
|
||||
@Autowired EmpMonthAttendanceMapper empMonthAttendanceMapper;
|
||||
|
||||
private String genScript(EmpSalaryBatchEntity batch) {
|
||||
@@ -523,6 +569,7 @@ public class EmpSalaryService extends BaseService<EmpSalaryEntity, EmpSalaryRepo
|
||||
.collect(Collectors.joining(",")));
|
||||
}
|
||||
}
|
||||
|
||||
@Autowired EmpSalaryMapper empSalaryMapper;
|
||||
|
||||
private static @NotNull GroovyClassLoader initClassLoader(GroovyClassLoader groovyClassLoader) {
|
||||
@@ -549,10 +596,6 @@ public class EmpSalaryService extends BaseService<EmpSalaryEntity, EmpSalaryRepo
|
||||
/**
|
||||
* 构建计算上下文
|
||||
*
|
||||
* @param batch
|
||||
* @param employee
|
||||
* @param attendance
|
||||
* @param salary
|
||||
* @return
|
||||
*/
|
||||
public Map<String, Object> buildCtx(
|
||||
@@ -618,19 +661,14 @@ public class EmpSalaryService extends BaseService<EmpSalaryEntity, EmpSalaryRepo
|
||||
log.info("删除工资数据 {} 条", cnt);
|
||||
}
|
||||
|
||||
|
||||
public void sendToAudit(IdRequest request){
|
||||
|
||||
public void sendToAudit(IdRequest request) {
|
||||
|
||||
EmpSalaryBatchEntity batch = this.batchService.get(request.getId());
|
||||
|
||||
if (!StringUtils.equalsAny(batch.getBatchStatus(), "1")){
|
||||
if (!StringUtils.equalsAny(batch.getBatchStatus(), "1")) {
|
||||
throw new BizException("批次状态不正确");
|
||||
}
|
||||
|
||||
batch.setBatchStatus("2");
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user