增加批次接口

This commit is contained in:
2024-08-08 22:41:22 +08:00
parent 136135cf89
commit a07be6d295
9 changed files with 182 additions and 25 deletions

View File

@@ -8,6 +8,8 @@ public class DictCode {
public static final String METER_TYPE = "meter.type";
public static final String EMP_SALARY_BATCH_STATUS = "emp.salary.batch.status";
public static final String COMMON_STEP_STATUS = "common.step.status";
public static final String APPOINTMENT_STATUS = "appointment.status";

View File

@@ -4,6 +4,7 @@ import cn.lihongjie.coal.annotation.OrgScope;
import cn.lihongjie.coal.annotation.SysLog;
import cn.lihongjie.coal.base.dto.CommonQuery;
import cn.lihongjie.coal.base.dto.IdRequest;
import cn.lihongjie.coal.empSalaryBatch.dto.BatchInitRequest;
import cn.lihongjie.coal.empSalaryBatch.dto.CreateEmpSalaryBatchDto;
import cn.lihongjie.coal.empSalaryBatch.dto.EmpSalaryBatchDto;
import cn.lihongjie.coal.empSalaryBatch.dto.UpdateEmpSalaryBatchDto;
@@ -58,6 +59,12 @@ public class EmpSalaryBatchController {
return true;
}
@PostMapping("/init")
public Object init(@RequestBody BatchInitRequest request) {
this.service.init(request);
return true;
}
@PostMapping("/unarchive")
public Object unarchive(@RequestBody IdRequest request) {
this.service.unarchive(request);

View File

@@ -0,0 +1,15 @@
package cn.lihongjie.coal.empSalaryBatch.dto;
import lombok.Data;
import java.time.LocalDate;
import java.util.*;
@Data
public class BatchInitRequest {
private LocalDate start;
private LocalDate end;
private String batchNo;
}

View File

@@ -4,5 +4,19 @@ import cn.lihongjie.coal.base.dto.OrgCommonDto;
import lombok.Data;
import org.hibernate.annotations.Comment;
import java.time.LocalDate;
@Data
public class CreateEmpSalaryBatchDto extends OrgCommonDto {}
public class CreateEmpSalaryBatchDto extends OrgCommonDto {
@Comment("批次年月")
private LocalDate batchYearMonth;
@Comment("批次号")
private String batchNo;
}

View File

@@ -1,12 +1,36 @@
package cn.lihongjie.coal.empSalaryBatch.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import cn.lihongjie.coal.common.DictCode;
import cn.lihongjie.coal.pojoProcessor.DictTranslate;
import lombok.Data;
import org.hibernate.annotations.Comment;
import java.time.LocalDate;
@Data
public class EmpSalaryBatchDto extends OrgCommonDto {
@Comment("批次年月")
private LocalDate batchYearMonth;
@Comment("批次号")
private String batchNo;
@Comment("批次状态 0-初始化 1-编辑中 2-已送审 3-已审核 4-已归档")
private String batchStatus;
@DictTranslate(dictKey = DictCode.EMP_SALARY_BATCH_STATUS)
private String batchStatusName;
private String archiveStatus;
@DictTranslate(dictKey = DictCode.ARCHIVESTATUS)
private String archiveStatusName;
}

View File

@@ -4,5 +4,19 @@ import cn.lihongjie.coal.base.dto.OrgCommonDto;
import lombok.Data;
import org.hibernate.annotations.Comment;
import java.time.LocalDate;
@Data
public class UpdateEmpSalaryBatchDto extends OrgCommonDto {}
public class UpdateEmpSalaryBatchDto extends OrgCommonDto {
@Comment("批次年月")
private LocalDate batchYearMonth;
@Comment("批次号")
private String batchNo;
}

View File

@@ -14,15 +14,13 @@ import java.time.LocalDate;
@Data
@Entity
public class EmpSalaryBatchEntity extends OrgCommonEntity {
@Comment("批次年月")
private LocalDate batchYearMonth;
@Comment("批次号")
private String batchNo;
@Comment("批次状态 0-未编辑 1-编辑中 2-已送审 3-已审核 4-已归档")
private String batchStatus;
@@ -30,5 +28,32 @@ public class EmpSalaryBatchEntity extends OrgCommonEntity {
@ColumnDefault("'0'")
private String archiveStatus = "0";
@Override
public void prePersist() {
super.prePersist();
this.initName();
}
private void initName() {
this.setName(
String.format(
"%s年%s月第%s批",
this.getBatchYearMonth().getYear(),
this.getBatchYearMonth().getMonthValue(),
this.getBatchNo()));
this.setCode(
String.format(
"%s%s%s",
this.getBatchYearMonth().getYear(),
this.getBatchYearMonth().getMonthValue(),
this.getBatchNo()));
}
@Override
public void preUpdate() {
super.preUpdate();
this.initName();
}
}

View File

@@ -4,6 +4,7 @@ import cn.lihongjie.coal.base.dto.CommonQuery;
import cn.lihongjie.coal.base.dto.IdRequest;
import cn.lihongjie.coal.base.service.BaseService;
import cn.lihongjie.coal.common.Ctx;
import cn.lihongjie.coal.empSalaryBatch.dto.BatchInitRequest;
import cn.lihongjie.coal.empSalaryBatch.dto.CreateEmpSalaryBatchDto;
import cn.lihongjie.coal.empSalaryBatch.dto.EmpSalaryBatchDto;
import cn.lihongjie.coal.empSalaryBatch.dto.UpdateEmpSalaryBatchDto;
@@ -29,6 +30,7 @@ import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDate;
import java.util.Objects;
@Service
@@ -42,21 +44,46 @@ public class EmpSalaryBatchService
@Autowired private ConversionService conversionService;
public void init(BatchInitRequest request) {
LocalDate start = request.getStart();
while (!start.isAfter(request.getEnd())) {
CreateEmpSalaryBatchDto dto = new CreateEmpSalaryBatchDto();
dto.setBatchYearMonth(start);
dto.setBatchNo(String.valueOf(request.getBatchNo()));
create(dto);
start = start.plusMonths(1);
}
}
public EmpSalaryBatchDto create(CreateEmpSalaryBatchDto request) {
EmpSalaryBatchEntity entity = mapper.toEntity(request);
// 批次年月和批次号唯一
if (this.repository.count(new Specification<EmpSalaryBatchEntity>() {
@Override
public Predicate toPredicate(Root<EmpSalaryBatchEntity> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
if (this.repository.count(
new Specification<EmpSalaryBatchEntity>() {
@Override
public Predicate toPredicate(
Root<EmpSalaryBatchEntity> root,
CriteriaQuery<?> query,
CriteriaBuilder criteriaBuilder) {
return criteriaBuilder.and(
criteriaBuilder.equal(root.get("batchYearMonth"), entity.getBatchYearMonth()),
criteriaBuilder.equal(root.get("batchNo"), entity.getBatchNo()),
criteriaBuilder.equal(root.get("organizationId"), Ctx.currentUser().getOrganizationId())
);
}
}) > 0){
return criteriaBuilder.and(
criteriaBuilder.equal(
root.get("batchYearMonth"),
entity.getBatchYearMonth()),
criteriaBuilder.equal(
root.get("batchNo"), entity.getBatchNo()),
criteriaBuilder.equal(
root.get("organizationId"),
Ctx.currentUser().getOrganizationId()));
}
})
> 0) {
throw new BizException("相同批次已经存在");
}
@@ -68,11 +95,11 @@ public class EmpSalaryBatchService
public EmpSalaryBatchDto update(UpdateEmpSalaryBatchDto request) {
EmpSalaryBatchEntity entity = this.repository.get(request.getId());
if (this.repository.containArchived(request.getId())){
if (this.repository.containArchived(request.getId())) {
throw new BizException("部分数据已归档,无法编辑或删除");
}
if (!StringUtils.equalsAny(entity.getBatchStatus(), "0")){
if (!StringUtils.equalsAny(entity.getBatchStatus(), "0")) {
throw new BizException("批次状态不是未编辑状态,无法编辑");
}
@@ -84,17 +111,18 @@ public class EmpSalaryBatchService
}
public void delete(IdRequest request) {
if (this.repository.containArchived(request)){
if (this.repository.containArchived(request)) {
throw new BizException("部分数据已归档,无法编辑或删除");
}
this.repository.findAllById(request.getIds()).forEach(entity -> {
if (!Objects.equals(entity.getBatchStatus(), "0")){
throw new BizException("批次状态不是未编辑状态,无法删除");
}
});
this.repository
.findAllById(request.getIds())
.forEach(
entity -> {
if (!Objects.equals(entity.getBatchStatus(), "0")) {
throw new BizException("批次状态不是未编辑状态,无法删除");
}
});
this.repository.deleteAllById(request.getIds());
}

View File

@@ -1675,6 +1675,34 @@
}
]
},
{
"code": "emp.salary.batch.status",
"name": "工资批次状态",
"item": [
{
"code": "0",
"name": "初始化"
},
{
"code": "1",
"name": "编辑中"
},
{
"code": "2",
"name": "已送审"
},
{
"code": "3",
"name": "已审核"
},
{
"code": "4",
"name": "已归档"
}
]
},
{
"code": "common.step.status",
"name": "通用状态步骤",