批次归档同步进行工资归档

This commit is contained in:
2024-09-02 11:03:00 +08:00
parent fdfb617a1f
commit c2e38b18ce
2 changed files with 28 additions and 8 deletions

View File

@@ -298,7 +298,8 @@ public class EmpSalaryService extends BaseService<EmpSalaryEntity, EmpSalaryRepo
@Autowired EmpSalaryItemService empSalaryItemService;
private static void assertBatchEditable(EmpSalaryBatchEntity salaryBatch) {
if (salaryBatch.getStatus() != 1 || ObjectUtils.notEqual(salaryBatch.getArchiveStatus(), "0")) {
if (salaryBatch.getStatus() != 1
|| ObjectUtils.notEqual(salaryBatch.getArchiveStatus(), "0")) {
throw new BizException("批次不属于编辑状态, 无法编辑或删除");
}
}
@@ -311,6 +312,22 @@ public class EmpSalaryService extends BaseService<EmpSalaryEntity, EmpSalaryRepo
return getById(entity.getId());
}
public void archiveByBatchId(IdRequest request) {
em.createQuery(
"update EmpSalaryEntity s set s.archiveStatus = '1' where s.batch.id in :batchId")
.setParameter("batchId", request.getIds())
.executeUpdate();
}
public void unarchiveByBatchId(IdRequest request) {
em.createQuery(
"update EmpSalaryEntity s set s.archiveStatus = '0' where s.batch.id in :batchId")
.setParameter("batchId", request.getIds())
.executeUpdate();
}
public EmpSalaryDto update(UpdateEmpSalaryDto request) {
assertBatchEditable(request.getBatch());
@@ -858,8 +875,9 @@ public class EmpSalaryService extends BaseService<EmpSalaryEntity, EmpSalaryRepo
private List<EmpSalaryEntity> queryHisSalary(List<String> employeesIds) {
List<String> ids = em.createNativeQuery(
"""
List<String> ids =
em.createNativeQuery(
"""
with tmp1 as (
select s.id, rank() over (partition by employee_id order by batch_year_month desc ) rk from t_emp_salary s where s.employee_id in :ids
@@ -868,13 +886,12 @@ public class EmpSalaryService extends BaseService<EmpSalaryEntity, EmpSalaryRepo
select id from tmp1 where rk = 1
""",
String.class)
.setParameter("ids", employeesIds)
.getResultList();
String.class)
.setParameter("ids", employeesIds)
.getResultList();
return em.createQuery(
"select s from EmpSalaryEntity s where s.id in :ids",
EmpSalaryEntity.class)
"select s from EmpSalaryEntity s where s.id in :ids", EmpSalaryEntity.class)
.setParameter("ids", ids)
.getResultList();
}

View File

@@ -182,12 +182,15 @@ public class EmpSalaryBatchService
return pageDto;
}
public void archive(IdRequest dto) {
this.repository.archive(dto);
empSalaryService.archiveByBatchId(dto);
}
public void unarchive(IdRequest dto) {
this.repository.unArchive(dto);
empSalaryService.unarchiveByBatchId(dto);
}
@Autowired EmpSalaryBatchAuditLogService batchAuditLogService;