From 4a46a9d54623f9010ac4e2f4606766aaf5bbb543 Mon Sep 17 00:00:00 2001 From: lihongjie0209 Date: Mon, 12 Aug 2024 21:49:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E7=BB=A7=E6=89=BF=E9=A1=B9?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/EmpSalaryController.java | 3 + .../repository/EmpSalaryRepository.java | 2 +- .../empSalary/service/EmpSalaryService.java | 57 ++++++++++++++++++- .../service/EmpSalaryItemService.java | 16 ++++++ 4 files changed, 76 insertions(+), 2 deletions(-) diff --git a/src/main/java/cn/lihongjie/coal/empSalary/controller/EmpSalaryController.java b/src/main/java/cn/lihongjie/coal/empSalary/controller/EmpSalaryController.java index ff91e5da..e7d6b279 100644 --- a/src/main/java/cn/lihongjie/coal/empSalary/controller/EmpSalaryController.java +++ b/src/main/java/cn/lihongjie/coal/empSalary/controller/EmpSalaryController.java @@ -74,6 +74,9 @@ public class EmpSalaryController { return this.service.batchSelectedEmpIds(request); } + + + @PostMapping("/archive") public Object archive(@RequestBody IdRequest request) { this.service.archive(request); diff --git a/src/main/java/cn/lihongjie/coal/empSalary/repository/EmpSalaryRepository.java b/src/main/java/cn/lihongjie/coal/empSalary/repository/EmpSalaryRepository.java index c3f0145d..4dcbec73 100644 --- a/src/main/java/cn/lihongjie/coal/empSalary/repository/EmpSalaryRepository.java +++ b/src/main/java/cn/lihongjie/coal/empSalary/repository/EmpSalaryRepository.java @@ -14,5 +14,5 @@ import java.util.List; public interface EmpSalaryRepository extends BaseRepository { @Query("delete from EmpSalaryEntity where batch.id in :ids") @Modifying - long deleteByBatchId(@Param("ids") List ids); + Integer deleteByBatchId(@Param("ids") List ids); } 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 0b5d8953..52eb1a40 100644 --- a/src/main/java/cn/lihongjie/coal/empSalary/service/EmpSalaryService.java +++ b/src/main/java/cn/lihongjie/coal/empSalary/service/EmpSalaryService.java @@ -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 items = + empSalaryItemService.getItems(batch.getOrganizationId()); + + List 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 salaryHis = this.queryHisSalary(employeesIds); + + Map salaryHisMap = + salaryHis.stream() + .collect(Collectors.toMap(e -> e.getEmployee().getId(), e -> e)); + + stopWatch.stop(); + // 执行计算脚本 List salaries = new ArrayList<>(); @@ -383,6 +416,18 @@ 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(); + } + private String genScript(EmpSalaryBatchEntity batch) { String script = ""; @@ -525,7 +580,7 @@ public class EmpSalaryService extends BaseService getItems(String organizationId) { + + return this.findAll( + new Specification() { + @Override + public Predicate toPredicate( + Root root, + CriteriaQuery query, + CriteriaBuilder criteriaBuilder) { + return criteriaBuilder.and( + criteriaBuilder.equal(root.get("organizationId"), organizationId), + criteriaBuilder.equal(root.get("status"), 1)); + } + }); + } }