diff --git a/src/main/java/cn/lihongjie/coal/base/dto/AuditDto.java b/src/main/java/cn/lihongjie/coal/base/dto/AuditDto.java new file mode 100644 index 00000000..101436bd --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/base/dto/AuditDto.java @@ -0,0 +1,55 @@ +package cn.lihongjie.coal.base.dto; + +import lombok.Data; + +import java.util.*; + +@Data +public class AuditDto { + + /** + * 送审 + */ + public static final String ACTION_SEND_TO_AUDIT = "1"; + + /** + * 撤销送审 + */ + public static final String ACTION_UNDO_SEND_TO_AUDIT = "2"; + + /** + * 审核通过 + */ + public static final String ACTION_AUDIT_PASS = "3"; + + /** + * 审核不通过 + */ + public static final String ACTION_AUDIT_DENIAL = "4"; + + /** + * 取消审核 + */ + public static final String ACTION_UNDO_AUDIT = "5"; + + + /** + * 归档 + */ + public static final String ACTION_ARCHIVE = "6"; + + /** + * 取消归档 + */ + public static final String ACTION_UNDO_ARCHIVE = "7"; + + + + private String id; + + private String action; + + + private String remarks; + +} diff --git a/src/main/java/cn/lihongjie/coal/empSalaryBatch/controller/EmpSalaryBatchController.java b/src/main/java/cn/lihongjie/coal/empSalaryBatch/controller/EmpSalaryBatchController.java index b2d90e46..e99cf52e 100644 --- a/src/main/java/cn/lihongjie/coal/empSalaryBatch/controller/EmpSalaryBatchController.java +++ b/src/main/java/cn/lihongjie/coal/empSalaryBatch/controller/EmpSalaryBatchController.java @@ -2,6 +2,7 @@ package cn.lihongjie.coal.empSalaryBatch.controller; import cn.lihongjie.coal.annotation.OrgScope; import cn.lihongjie.coal.annotation.SysLog; +import cn.lihongjie.coal.base.dto.AuditDto; import cn.lihongjie.coal.base.dto.CommonQuery; import cn.lihongjie.coal.base.dto.IdRequest; import cn.lihongjie.coal.empSalaryBatch.dto.BatchInitRequest; @@ -71,39 +72,10 @@ public class EmpSalaryBatchController { return true; } - @PostMapping("/sendToAudit") - public Object sendToAudit(@RequestBody IdRequest request) { - this.service.sendToAudit(request); - return true; - } - - @PostMapping("/unDoSendToAudit") - public Object unDoSendToAudit(@RequestBody IdRequest request) { - this.service.unDoSendToAudit(request); - return true; - } - @PostMapping("/audit") - public Object audit(@RequestBody IdRequest request) { + public Object audit(@RequestBody AuditDto request) { this.service.audit(request); return true; } - @PostMapping("/undoAudit") - public Object undoAudit(@RequestBody IdRequest request) { - this.service.undoAudit(request); - return true; - } - - @PostMapping("/batchArchive") - public Object batchArchive(@RequestBody IdRequest request) { - this.service.batchArchive(request); - return true; - } - - @PostMapping("/undoBatchArchive") - public Object undoBatchArchive(@RequestBody IdRequest request) { - this.service.undoBatchArchive(request); - return true; - } } diff --git a/src/main/java/cn/lihongjie/coal/empSalaryBatch/service/EmpSalaryBatchService.java b/src/main/java/cn/lihongjie/coal/empSalaryBatch/service/EmpSalaryBatchService.java index 112889cf..5550817f 100644 --- a/src/main/java/cn/lihongjie/coal/empSalaryBatch/service/EmpSalaryBatchService.java +++ b/src/main/java/cn/lihongjie/coal/empSalaryBatch/service/EmpSalaryBatchService.java @@ -1,5 +1,6 @@ package cn.lihongjie.coal.empSalaryBatch.service; +import cn.lihongjie.coal.base.dto.AuditDto; import cn.lihongjie.coal.base.dto.CommonQuery; import cn.lihongjie.coal.base.dto.IdRequest; import cn.lihongjie.coal.base.service.BaseService; @@ -12,8 +13,12 @@ import cn.lihongjie.coal.empSalaryBatch.dto.UpdateEmpSalaryBatchDto; import cn.lihongjie.coal.empSalaryBatch.entity.EmpSalaryBatchEntity; import cn.lihongjie.coal.empSalaryBatch.mapper.EmpSalaryBatchMapper; import cn.lihongjie.coal.empSalaryBatch.repository.EmpSalaryBatchRepository; +import cn.lihongjie.coal.empSalaryBatchAuditLog.entity.EmpSalaryBatchAuditLogEntity; +import cn.lihongjie.coal.empSalaryBatchAuditLog.service.EmpSalaryBatchAuditLogService; import cn.lihongjie.coal.exception.BizException; +import jakarta.persistence.EntityManager; +import jakarta.persistence.PersistenceContext; import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.CriteriaQuery; import jakarta.persistence.criteria.Predicate; @@ -61,8 +66,7 @@ public class EmpSalaryBatchService } } - @Autowired - EmpSalaryService empSalaryService; + @Autowired EmpSalaryService empSalaryService; public EmpSalaryBatchDto update(UpdateEmpSalaryBatchDto request) { EmpSalaryBatchEntity entity = this.repository.get(request.getId()); @@ -119,8 +123,6 @@ public class EmpSalaryBatchService throw new BizException("部分数据已归档,无法编辑或删除"); } - - this.repository .findAllById(request.getIds()) .forEach( @@ -161,100 +163,101 @@ public class EmpSalaryBatchService this.repository.unArchive(dto); } + @Autowired EmpSalaryBatchAuditLogService batchAuditLogService; - public void sendToAudit(IdRequest request){ + @PersistenceContext EntityManager em; + public void saveBatchAuditLog(AuditDto dto) { - EmpSalaryBatchEntity batch = this.get(request.getId()); - - if (!StringUtils.equalsAny(batch.getBatchStatus(), "1")){ - throw new BizException("批次状态不正确"); - } - - batch.setBatchStatus("2"); - - this.save(batch); - + EmpSalaryBatchAuditLogEntity entity = new EmpSalaryBatchAuditLogEntity(); + entity.setBatch(em.getReference(EmpSalaryBatchEntity.class, dto.getId())); + entity.setAction(dto.getAction()); + entity.setRemarks(dto.getRemarks()); + batchAuditLogService.save(entity); } + public void audit(AuditDto dto) { + + EmpSalaryBatchEntity entity = get(dto.getId()); + + switch (entity.getBatchStatus()) { + + case "1"->{ + + switch (dto.getAction()){ + + case AuditDto.ACTION_SEND_TO_AUDIT -> { + + entity.setBatchStatus("2"); + saveBatchAuditLog(dto); + save(entity); + return; + } + + } + } + case "2" -> { + switch (dto.getAction()){ + + case AuditDto.ACTION_AUDIT_PASS -> { + entity.setBatchStatus("3"); + saveBatchAuditLog(dto); + save(entity); + return; + + } + + case AuditDto.ACTION_AUDIT_DENIAL -> { + entity.setBatchStatus("1"); + saveBatchAuditLog(dto); + save(entity); + return; + } + + } + } + case "3" -> { + switch (dto.getAction()){ + + case AuditDto.ACTION_ARCHIVE -> { + entity.setBatchStatus("4"); + entity.setArchiveStatus("1"); + saveBatchAuditLog(dto); + save(entity); + return; + + } + + case AuditDto.ACTION_UNDO_AUDIT -> { + entity.setBatchStatus("2"); + saveBatchAuditLog(dto); + save(entity); + return; + + } + + } + } + case "4" -> { + switch (dto.getAction()){ + case AuditDto.ACTION_UNDO_ARCHIVE -> { + entity.setBatchStatus("3"); + entity.setArchiveStatus("0"); + saveBatchAuditLog(dto); + save(entity); + return; + + } + } + } - public void unDoSendToAudit(IdRequest request){ - EmpSalaryBatchEntity batch = this.get(request.getId()); - if (!StringUtils.equalsAny(batch.getBatchStatus(), "2")){ - throw new BizException("批次状态不正确"); } - batch.setBatchStatus("1"); - this.save(batch); + throw new BizException("数据状态异常"); } - - public void audit(IdRequest request){ - - - EmpSalaryBatchEntity batch = this.get(request.getId()); - - if (!StringUtils.equalsAny(batch.getBatchStatus(), "2")){ - throw new BizException("批次状态不正确"); - } - - batch.setBatchStatus("3"); - - this.save(batch); - - } - - public void undoAudit(IdRequest request){ - - - EmpSalaryBatchEntity batch = this.get(request.getId()); - - if (!StringUtils.equalsAny(batch.getBatchStatus(), "3")){ - throw new BizException("批次状态不正确"); - } - - batch.setBatchStatus("2"); - - this.save(batch); - - } - - - public void batchArchive(IdRequest request){ - - - EmpSalaryBatchEntity batch = this.get(request.getId()); - - if (!StringUtils.equalsAny(batch.getBatchStatus(), "3")){ - throw new BizException("批次状态不正确"); - } - - batch.setBatchStatus("4"); - batch.setArchiveStatus("1"); - - this.save(batch); - - } - - - public void undoBatchArchive(IdRequest request){ - - - EmpSalaryBatchEntity batch = this.get(request.getId()); - - if (!StringUtils.equalsAny(batch.getBatchStatus(), "4")){ - throw new BizException("批次状态不正确"); - } - - batch.setBatchStatus("3"); - batch.setArchiveStatus("0"); - - this.save(batch); - - } - } diff --git a/src/main/java/cn/lihongjie/coal/empSalaryBatchAuditLog/controller/EmpSalaryBatchAuditLogController.java b/src/main/java/cn/lihongjie/coal/empSalaryBatchAuditLog/controller/EmpSalaryBatchAuditLogController.java new file mode 100644 index 00000000..4788c452 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/empSalaryBatchAuditLog/controller/EmpSalaryBatchAuditLogController.java @@ -0,0 +1,54 @@ +package cn.lihongjie.coal.empSalaryBatchAuditLog.controller; + +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.empSalaryBatchAuditLog.dto.CreateEmpSalaryBatchAuditLogDto; +import cn.lihongjie.coal.empSalaryBatchAuditLog.dto.EmpSalaryBatchAuditLogDto; +import cn.lihongjie.coal.empSalaryBatchAuditLog.dto.UpdateEmpSalaryBatchAuditLogDto; +import cn.lihongjie.coal.empSalaryBatchAuditLog.service.EmpSalaryBatchAuditLogService; + +import lombok.extern.slf4j.Slf4j; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/empSalaryBatchAuditLog") +@SysLog(module = "") +@Slf4j +@OrgScope +public class EmpSalaryBatchAuditLogController { + @Autowired private EmpSalaryBatchAuditLogService service; + + @PostMapping("/create") + public EmpSalaryBatchAuditLogDto create(@RequestBody CreateEmpSalaryBatchAuditLogDto request) { + return this.service.create(request); + } + + @PostMapping("/update") + public EmpSalaryBatchAuditLogDto update(@RequestBody UpdateEmpSalaryBatchAuditLogDto request) { + return this.service.update(request); + } + + @PostMapping("/delete") + public Object delete(@RequestBody IdRequest request) { + this.service.delete(request); + return true; + } + + @PostMapping("/getById") + public EmpSalaryBatchAuditLogDto getById(@RequestBody IdRequest request) { + return this.service.getById(request.getId()); + } + + @PostMapping("/list") + public Page list(@RequestBody CommonQuery request) { + return this.service.list(request); + } +} diff --git a/src/main/java/cn/lihongjie/coal/empSalaryBatchAuditLog/dto/CreateEmpSalaryBatchAuditLogDto.java b/src/main/java/cn/lihongjie/coal/empSalaryBatchAuditLog/dto/CreateEmpSalaryBatchAuditLogDto.java new file mode 100644 index 00000000..ab7a2cb0 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/empSalaryBatchAuditLog/dto/CreateEmpSalaryBatchAuditLogDto.java @@ -0,0 +1,8 @@ +package cn.lihongjie.coal.empSalaryBatchAuditLog.dto; + +import cn.lihongjie.coal.base.dto.OrgCommonDto; + +import lombok.Data; + +@Data +public class CreateEmpSalaryBatchAuditLogDto extends OrgCommonDto {} diff --git a/src/main/java/cn/lihongjie/coal/empSalaryBatchAuditLog/dto/EmpSalaryBatchAuditLogDto.java b/src/main/java/cn/lihongjie/coal/empSalaryBatchAuditLog/dto/EmpSalaryBatchAuditLogDto.java new file mode 100644 index 00000000..a543ecd9 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/empSalaryBatchAuditLog/dto/EmpSalaryBatchAuditLogDto.java @@ -0,0 +1,8 @@ +package cn.lihongjie.coal.empSalaryBatchAuditLog.dto; + +import cn.lihongjie.coal.base.dto.OrgCommonDto; + +import lombok.Data; + +@Data +public class EmpSalaryBatchAuditLogDto extends OrgCommonDto {} diff --git a/src/main/java/cn/lihongjie/coal/empSalaryBatchAuditLog/dto/UpdateEmpSalaryBatchAuditLogDto.java b/src/main/java/cn/lihongjie/coal/empSalaryBatchAuditLog/dto/UpdateEmpSalaryBatchAuditLogDto.java new file mode 100644 index 00000000..c79351d4 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/empSalaryBatchAuditLog/dto/UpdateEmpSalaryBatchAuditLogDto.java @@ -0,0 +1,8 @@ +package cn.lihongjie.coal.empSalaryBatchAuditLog.dto; + +import cn.lihongjie.coal.base.dto.OrgCommonDto; + +import lombok.Data; + +@Data +public class UpdateEmpSalaryBatchAuditLogDto extends OrgCommonDto {} diff --git a/src/main/java/cn/lihongjie/coal/empSalaryBatchAuditLog/entity/EmpSalaryBatchAuditLogEntity.java b/src/main/java/cn/lihongjie/coal/empSalaryBatchAuditLog/entity/EmpSalaryBatchAuditLogEntity.java new file mode 100644 index 00000000..5d87f9e3 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/empSalaryBatchAuditLog/entity/EmpSalaryBatchAuditLogEntity.java @@ -0,0 +1,23 @@ +package cn.lihongjie.coal.empSalaryBatchAuditLog.entity; + +import cn.lihongjie.coal.base.entity.OrgCommonEntity; +import cn.lihongjie.coal.empSalaryBatch.entity.EmpSalaryBatchEntity; + +import jakarta.persistence.Entity; +import jakarta.persistence.ManyToOne; + +import lombok.Data; + +@Data +@Entity +public class EmpSalaryBatchAuditLogEntity extends OrgCommonEntity { + + @ManyToOne + private EmpSalaryBatchEntity batch; + + + private String action; + + + +} diff --git a/src/main/java/cn/lihongjie/coal/empSalaryBatchAuditLog/mapper/EmpSalaryBatchAuditLogMapper.java b/src/main/java/cn/lihongjie/coal/empSalaryBatchAuditLog/mapper/EmpSalaryBatchAuditLogMapper.java new file mode 100644 index 00000000..8fc84b8f --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/empSalaryBatchAuditLog/mapper/EmpSalaryBatchAuditLogMapper.java @@ -0,0 +1,23 @@ +package cn.lihongjie.coal.empSalaryBatchAuditLog.mapper; + +import cn.lihongjie.coal.base.mapper.BaseMapper; +import cn.lihongjie.coal.base.mapper.CommonEntityMapper; +import cn.lihongjie.coal.base.mapper.CommonMapper; +import cn.lihongjie.coal.empSalaryBatchAuditLog.dto.CreateEmpSalaryBatchAuditLogDto; +import cn.lihongjie.coal.empSalaryBatchAuditLog.dto.EmpSalaryBatchAuditLogDto; +import cn.lihongjie.coal.empSalaryBatchAuditLog.dto.UpdateEmpSalaryBatchAuditLogDto; +import cn.lihongjie.coal.empSalaryBatchAuditLog.entity.EmpSalaryBatchAuditLogEntity; + +import org.mapstruct.Mapper; +import org.mapstruct.control.DeepClone; + +@Mapper( + componentModel = org.mapstruct.MappingConstants.ComponentModel.SPRING, + uses = {CommonMapper.class, CommonEntityMapper.class}, + mappingControl = DeepClone.class) +public interface EmpSalaryBatchAuditLogMapper + extends BaseMapper< + EmpSalaryBatchAuditLogEntity, + EmpSalaryBatchAuditLogDto, + CreateEmpSalaryBatchAuditLogDto, + UpdateEmpSalaryBatchAuditLogDto> {} diff --git a/src/main/java/cn/lihongjie/coal/empSalaryBatchAuditLog/repository/EmpSalaryBatchAuditLogRepository.java b/src/main/java/cn/lihongjie/coal/empSalaryBatchAuditLog/repository/EmpSalaryBatchAuditLogRepository.java new file mode 100644 index 00000000..f7a3fd2d --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/empSalaryBatchAuditLog/repository/EmpSalaryBatchAuditLogRepository.java @@ -0,0 +1,16 @@ +package cn.lihongjie.coal.empSalaryBatchAuditLog.repository; + +import cn.lihongjie.coal.base.dao.BaseRepository; +import cn.lihongjie.coal.empSalaryBatchAuditLog.entity.EmpSalaryBatchAuditLogEntity; + +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface EmpSalaryBatchAuditLogRepository + extends BaseRepository { + @Query("select false") + boolean isLinked(List ids); +} diff --git a/src/main/java/cn/lihongjie/coal/empSalaryBatchAuditLog/service/EmpSalaryBatchAuditLogService.java b/src/main/java/cn/lihongjie/coal/empSalaryBatchAuditLog/service/EmpSalaryBatchAuditLogService.java new file mode 100644 index 00000000..4ecc3bbd --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/empSalaryBatchAuditLog/service/EmpSalaryBatchAuditLogService.java @@ -0,0 +1,81 @@ +package cn.lihongjie.coal.empSalaryBatchAuditLog.service; + +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.dbFunctions.DbFunctionService; +import cn.lihongjie.coal.empSalaryBatchAuditLog.dto.CreateEmpSalaryBatchAuditLogDto; +import cn.lihongjie.coal.empSalaryBatchAuditLog.dto.EmpSalaryBatchAuditLogDto; +import cn.lihongjie.coal.empSalaryBatchAuditLog.dto.UpdateEmpSalaryBatchAuditLogDto; +import cn.lihongjie.coal.empSalaryBatchAuditLog.entity.EmpSalaryBatchAuditLogEntity; +import cn.lihongjie.coal.empSalaryBatchAuditLog.mapper.EmpSalaryBatchAuditLogMapper; +import cn.lihongjie.coal.empSalaryBatchAuditLog.repository.EmpSalaryBatchAuditLogRepository; +import cn.lihongjie.coal.exception.BizException; + +import lombok.extern.slf4j.Slf4j; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.convert.ConversionService; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Sort; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Slf4j +@Transactional +public class EmpSalaryBatchAuditLogService + extends BaseService { + @Autowired private EmpSalaryBatchAuditLogRepository repository; + + @Autowired private EmpSalaryBatchAuditLogMapper mapper; + + @Autowired private ConversionService conversionService; + + @Autowired private DbFunctionService dbFunctionService; + + public EmpSalaryBatchAuditLogDto create(CreateEmpSalaryBatchAuditLogDto request) { + EmpSalaryBatchAuditLogEntity entity = mapper.toEntity(request); + + this.repository.save(entity); + return getById(entity.getId()); + } + + public EmpSalaryBatchAuditLogDto update(UpdateEmpSalaryBatchAuditLogDto request) { + EmpSalaryBatchAuditLogEntity entity = this.repository.get(request.getId()); + this.mapper.updateEntity(entity, request); + + this.repository.save(entity); + + return getById(entity.getId()); + } + + public void delete(IdRequest request) { + boolean linked = this.repository.isLinked(request.getIds()); + + if (linked) { + throw new BizException("数据已被关联,无法删除"); + } + + this.repository.deleteAllById(request.getIds()); + } + + public EmpSalaryBatchAuditLogDto getById(String id) { + EmpSalaryBatchAuditLogEntity entity = repository.get(id); + + return mapper.toDto(entity); + } + + public Page list(CommonQuery query) { + Page page = + repository.findAll( + query.specification(conversionService), + PageRequest.of( + query.getPageNo(), + query.getPageSize(), + Sort.by(query.getOrders()))); + + return page.map(this.mapper::toDto); + } +} diff --git a/src/main/resources/config/dictionary.json b/src/main/resources/config/dictionary.json index 90a4a088..909a7fce 100644 --- a/src/main/resources/config/dictionary.json +++ b/src/main/resources/config/dictionary.json @@ -1682,20 +1682,20 @@ "item": [ { "code": "1", - "name": "编辑中" + "name": "编辑" }, { "code": "2", - "name": "已送审" + "name": "审批" }, { "code": "3", - "name": "已审核" + "name": "归档" }, { "code": "4", - "name": "已归档" + "name": "完成" } ] }, diff --git a/src/main/resources/scripts/dict/enum/empSalaryBatchAuditLogDict.groovy b/src/main/resources/scripts/dict/enum/empSalaryBatchAuditLogDict.groovy new file mode 100644 index 00000000..757779a3 --- /dev/null +++ b/src/main/resources/scripts/dict/enum/empSalaryBatchAuditLogDict.groovy @@ -0,0 +1,17 @@ + +package scripts.dict + +import cn.lihongjie.coal.base.dto.CommonQuery +import cn.lihongjie.coal.empSalaryBatchAuditLog.controller.EmpSalaryBatchAuditLogController +import org.springframework.context.ApplicationContext + +ApplicationContext ioc = ioc + +def controller = ioc.getBean(EmpSalaryBatchAuditLogController.class) + + + + +return controller.list(new CommonQuery()) + +