mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
处理继承项问题
This commit is contained in:
@@ -74,6 +74,9 @@ public class EmpSalaryController {
|
||||
return this.service.batchSelectedEmpIds(request);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@PostMapping("/archive")
|
||||
public Object archive(@RequestBody IdRequest request) {
|
||||
this.service.archive(request);
|
||||
|
||||
@@ -14,5 +14,5 @@ import java.util.List;
|
||||
public interface EmpSalaryRepository extends BaseRepository<EmpSalaryEntity> {
|
||||
@Query("delete from EmpSalaryEntity where batch.id in :ids")
|
||||
@Modifying
|
||||
long deleteByBatchId(@Param("ids") List<String> ids);
|
||||
Integer deleteByBatchId(@Param("ids") List<String> ids);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import cn.lihongjie.coal.empSalary.mapper.EmpSalaryMapper;
|
||||
import cn.lihongjie.coal.empSalary.repository.EmpSalaryRepository;
|
||||
import cn.lihongjie.coal.empSalaryBatch.entity.EmpSalaryBatchEntity;
|
||||
import cn.lihongjie.coal.empSalaryBatch.service.EmpSalaryBatchService;
|
||||
import cn.lihongjie.coal.empSalaryItem.entity.EmpSalaryItemEntity;
|
||||
import cn.lihongjie.coal.empSalaryItem.service.EmpSalaryItemService;
|
||||
import cn.lihongjie.coal.employee.dto.EmployeeDto;
|
||||
import cn.lihongjie.coal.employee.entity.EmployeeEntity;
|
||||
@@ -31,6 +32,10 @@ import jakarta.persistence.PersistenceContext;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.codehaus.groovy.control.CompilerConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.redisson.api.RLock;
|
||||
@@ -358,6 +363,22 @@ public class EmpSalaryService extends BaseService<EmpSalaryEntity, EmpSalaryRepo
|
||||
|
||||
stopWatch.stop();
|
||||
|
||||
stopWatch.start("getItems");
|
||||
// 获取工资项
|
||||
List<EmpSalaryItemEntity> items =
|
||||
empSalaryItemService.getItems(batch.getOrganizationId());
|
||||
|
||||
List<EmpSalaryItemEntity> inheritItems =
|
||||
items.stream()
|
||||
.filter(
|
||||
x ->
|
||||
BooleanUtils.isTrue(x.getInherit())
|
||||
&& StringUtils.equalsAny(x.getInputType(), "0"))
|
||||
.filter(x -> ObjectUtils.notEqual(x.getStatus(), 0))
|
||||
.toList();
|
||||
|
||||
stopWatch.stop();
|
||||
|
||||
stopWatch.start("parseScript");
|
||||
groovyClassLoader = initClassLoader(groovyClassLoader);
|
||||
|
||||
@@ -365,6 +386,18 @@ public class EmpSalaryService extends BaseService<EmpSalaryEntity, EmpSalaryRepo
|
||||
|
||||
stopWatch.stop();
|
||||
|
||||
// 搜索历史工资数据
|
||||
|
||||
stopWatch.start("queryHistorySalary");
|
||||
|
||||
List<EmpSalaryEntity> salaryHis = this.queryHisSalary(employeesIds);
|
||||
|
||||
Map<String, EmpSalaryEntity> salaryHisMap =
|
||||
salaryHis.stream()
|
||||
.collect(Collectors.toMap(e -> e.getEmployee().getId(), e -> e));
|
||||
|
||||
stopWatch.stop();
|
||||
|
||||
// 执行计算脚本
|
||||
|
||||
List<EmpSalaryEntity> salaries = new ArrayList<>();
|
||||
@@ -383,6 +416,18 @@ public class EmpSalaryService extends BaseService<EmpSalaryEntity, EmpSalaryRepo
|
||||
|
||||
// todo 处理继承项
|
||||
|
||||
if (salaryHisMap.containsKey(employee.getId())
|
||||
&& CollectionUtils.isNotEmpty(inheritItems)) {
|
||||
|
||||
for (EmpSalaryItemEntity inheritItem : inheritItems) {
|
||||
|
||||
ctx.put(
|
||||
inheritItem.getCode(),
|
||||
ReflectUtils.getFieldValue(
|
||||
salaryHisMap.get(employee.getId()), inheritItem.getCode()));
|
||||
}
|
||||
}
|
||||
|
||||
// 计算
|
||||
|
||||
stopWatch.start("execScript: " + employee.getName());
|
||||
@@ -423,6 +468,16 @@ public class EmpSalaryService extends BaseService<EmpSalaryEntity, EmpSalaryRepo
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
private String genScript(EmpSalaryBatchEntity batch) {
|
||||
String script = "";
|
||||
|
||||
@@ -525,7 +580,7 @@ public class EmpSalaryService extends BaseService<EmpSalaryEntity, EmpSalaryRepo
|
||||
|
||||
public void deleteByBatchId(IdRequest request) {
|
||||
|
||||
long cnt = this.repository.deleteByBatchId(request.getIds());
|
||||
Integer cnt = this.repository.deleteByBatchId(request.getIds());
|
||||
|
||||
log.info("删除工资数据 {} 条", cnt);
|
||||
}
|
||||
|
||||
@@ -875,4 +875,20 @@ public class EmpSalaryItemService
|
||||
.parseClass(script.toString());
|
||||
return scriptClass;
|
||||
}
|
||||
|
||||
public List<EmpSalaryItemEntity> getItems(String organizationId) {
|
||||
|
||||
return this.findAll(
|
||||
new Specification<EmpSalaryItemEntity>() {
|
||||
@Override
|
||||
public Predicate toPredicate(
|
||||
Root<EmpSalaryItemEntity> root,
|
||||
CriteriaQuery<?> query,
|
||||
CriteriaBuilder criteriaBuilder) {
|
||||
return criteriaBuilder.and(
|
||||
criteriaBuilder.equal(root.get("organizationId"), organizationId),
|
||||
criteriaBuilder.equal(root.get("status"), 1));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user