批次增加审核和日志

This commit is contained in:
2024-08-14 20:49:15 +08:00
parent 980342d4e1
commit be4b983bfe
13 changed files with 388 additions and 120 deletions

View File

@@ -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;
}

View File

@@ -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;
}
}

View File

@@ -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);
}
}

View File

@@ -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<EmpSalaryBatchAuditLogDto> list(@RequestBody CommonQuery request) {
return this.service.list(request);
}
}

View File

@@ -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 {}

View File

@@ -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 {}

View File

@@ -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 {}

View File

@@ -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;
}

View File

@@ -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> {}

View File

@@ -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<EmpSalaryBatchAuditLogEntity> {
@Query("select false")
boolean isLinked(List<String> ids);
}

View File

@@ -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<EmpSalaryBatchAuditLogEntity, EmpSalaryBatchAuditLogRepository> {
@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<EmpSalaryBatchAuditLogDto> list(CommonQuery query) {
Page<EmpSalaryBatchAuditLogEntity> page =
repository.findAll(
query.specification(conversionService),
PageRequest.of(
query.getPageNo(),
query.getPageSize(),
Sort.by(query.getOrders())));
return page.map(this.mapper::toDto);
}
}

View File

@@ -1682,20 +1682,20 @@
"item": [
{
"code": "1",
"name": "编辑"
"name": "编辑"
},
{
"code": "2",
"name": "已送审"
"name": "审"
},
{
"code": "3",
"name": "已审核"
"name": "归档"
},
{
"code": "4",
"name": "已归档"
"name": "完成"
}
]
},

View File

@@ -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())