流程撤回优化管理员admin可以撤回任何流程

master
Harry Yang 2023-01-03 11:10:47 +08:00
parent 8512b630c3
commit 23c87187de
2 changed files with 37 additions and 10 deletions

View File

@ -36,6 +36,7 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import javax.persistence.EntityManager;
@ -325,10 +326,7 @@ public class ProcessController {
@ResponseBody
@GetMapping("/{id}")
public ProjectProcessDetail get(@PathVariable int id) {
ProjectProcess process = processService.getById(id);
if (process == null) {
throw ErrorMessageException.failed("流程不存在");
}
ProjectProcess process = obtainProjectProcess(id);
ProjectProcessDetail detail = new ProjectProcessDetail();
detail.setProcessId(id);
@ -476,10 +474,7 @@ public class ProcessController {
@PutMapping("/{id}")
@Transactional(rollbackFor = Exception.class)
public void update(@PathVariable int id, @RequestBody @Valid ProcessUpdateForm form) throws Exception {
ProjectProcess entity = processService.getById(id);
if (entity == null) {
throw ErrorMessageException.failed("流程不存在");
}
ProjectProcess entity = obtainProjectProcess(id);
Integer processId = entity.getId();
ProcessType processType = entity.getProcessType();
@ -647,7 +642,29 @@ public class ProcessController {
@PostMapping("/revoke/{id}")
public void revoke(@PathVariable("id") int id) {
// TODO 发起申请的人,在第一个人还没审批的情况下可以撤回
processService.updateProcessStatus(id, ProcessStatus.draft);
Admin admin = InterfaceUtil.getAdmin();
if (admin == null) {
throw ErrorMessageException.failed("权限不足");
}
if (Objects.equals("admin", admin.getUserName())) {
processService.revoke(id);
}
else {
ProjectProcess process = obtainProjectProcess(id);
Integer applyPersonId = process.getApplyPersonId();
if (!Objects.equals(admin.getId(), applyPersonId)) {
throw ErrorMessageException.failed("流程不属于自己");
}
processService.revoke(id);
}
}
private ProjectProcess obtainProjectProcess(int id) {
ProjectProcess projectProcess = processService.getById(id);
if (projectProcess == null) {
throw ErrorMessageException.failed("流程不存在");
}
return projectProcess;
}
@ResponseBody
@ -657,7 +674,7 @@ public class ProcessController {
Integer applyUserId = admin.getId();
int update = jdbcTemplate.update("delete from project_process where id =? and apply_person_id=?", id, applyUserId);
if (update != 1) {
throw new RuntimeException("删除的流程不存在或者不属于自己");
throw ErrorMessageException.failed("删除的流程不存在或者不属于自己");
}
}

View File

@ -165,6 +165,16 @@ public class ProjectProcessService {
jdbcTemplate.update("update project_process set `status`=? where id=?", status.getValue(), processId);
}
/**
*
*
* @param processId ID
*/
public void revoke(int processId) {
jdbcTemplate.update("update project_process set current_audit=?, current_audit_id=?, `status`=? where id=?",
null, null, ProcessStatus.draft.getValue(), processId);
}
/**
* ID
*