|
|
@@ -1,6 +1,7 @@
|
|
|
package com.loan.system.controller.wechat;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.loan.system.context.BaseContext;
|
|
|
import com.loan.system.domain.dto.ApprovalDTO;
|
|
|
import com.loan.system.domain.dto.PreApprovalDTO;
|
|
|
@@ -10,10 +11,12 @@ import com.loan.system.domain.enums.StepEnum;
|
|
|
import com.loan.system.domain.enums.StepPropertyEnum;
|
|
|
import com.loan.system.domain.pojo.Result;
|
|
|
import com.loan.system.domain.vo.*;
|
|
|
+import com.loan.system.exception.DescribeException;
|
|
|
import com.loan.system.properties.JwtProperties;
|
|
|
import com.loan.system.service.*;
|
|
|
import com.loan.system.service.Impl.UserServiceImpl;
|
|
|
import com.loan.system.utils.JwtUtil;
|
|
|
+import com.loan.system.utils.RedisData;
|
|
|
import com.loan.system.utils.ResultUtil;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
@@ -21,9 +24,12 @@ import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
+import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
+import org.springframework.util.ObjectUtils;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
@@ -40,87 +46,54 @@ import static com.loan.system.domain.enums.ExceptionEnum.*;
|
|
|
public class ApprovalController {
|
|
|
private static final Logger log = LoggerFactory.getLogger(UserServiceImpl.class);
|
|
|
@Autowired
|
|
|
- private UserService userService;
|
|
|
- @Autowired
|
|
|
- private CustomerService customerService;
|
|
|
- @Autowired
|
|
|
private LoanService loanCaseService;
|
|
|
@Autowired
|
|
|
private ApprovalService approvalService;
|
|
|
@Autowired
|
|
|
- private DocumentService documentService;
|
|
|
- @Autowired
|
|
|
private StepService stepService;
|
|
|
@Autowired
|
|
|
- private JwtProperties jwtProperties;
|
|
|
- @Autowired
|
|
|
- private MessageService messageService;
|
|
|
-// @Autowired
|
|
|
-// private WxService wxService;
|
|
|
+ private StringRedisTemplate stringRedisTemplate;
|
|
|
|
|
|
@GetMapping("preApproval/detail")
|
|
|
@ApiOperation("获取预审审详情")
|
|
|
@PreAuthorize("@pms.hasAnyRoles('SYSTEM_ADMIN','APPROVER','LEAD_SALES', 'ASSIST_SALES', 'FINANCE', 'BACK_OFFICE')")
|
|
|
public Result getPreApprovalDetail(@RequestParam Long caseId) {
|
|
|
- ApprovalVO approvalVO = new ApprovalVO();
|
|
|
- StepVO stepVO = stepService.findByStepNameAndCaseId(StepPropertyEnum.PRE_TRIAL.getLabel(), caseId);
|
|
|
- Map<UserVO,String> decision=new HashMap<>();
|
|
|
- Map<UserVO,String> comment=new HashMap<>();
|
|
|
-
|
|
|
- if (stepVO.getUserId2()!=null){
|
|
|
- User user=userService.findByIdAndIsDelete(stepVO.getUserId2());
|
|
|
- ApprovalRecordVO approvalRecordVO = approvalService.findByCaseIdAndIsDeleteAndStepName(caseId, StepPropertyEnum.APPROVAL.getLabel(), user.getId());
|
|
|
- decision.put(BeanUtil.copyProperties(user,UserVO.class),approvalRecordVO.getDecision());
|
|
|
- comment.put(BeanUtil.copyProperties(user,UserVO.class),approvalRecordVO.getComments());
|
|
|
- }
|
|
|
+ if (ObjectUtils.isEmpty(caseId) || !loanCaseService.existsByIdAndIsDelete(caseId))
|
|
|
+ throw new DescribeException(PROJECT_NOT_EXIST);
|
|
|
|
|
|
- return ResultUtil.success("success",approvalVO);
|
|
|
+ return ResultUtil.success("success",approvalService.findByCaseIdAndStepNameAndIsDelete(caseId,StepPropertyEnum.PRE_TRIAL.getLabel()));
|
|
|
}
|
|
|
|
|
|
@PostMapping("/preapproval-assist/pass")
|
|
|
@PreAuthorize("@pms.hasRole('ASSIST_SALES')")
|
|
|
@ApiOperation("副业务员审核")
|
|
|
public Result pre_approval_save_primary(@RequestBody PreApprovalDTO preApprovalDTO) {
|
|
|
+ if(ObjectUtils.isEmpty(preApprovalDTO)||ObjectUtils.isEmpty(preApprovalDTO.getCaseId()))
|
|
|
+ throw new DescribeException(INPUT_ERROR);
|
|
|
+
|
|
|
Long userId= BaseContext.getCurrentId();
|
|
|
- log.info("用户id: {}", userId);
|
|
|
- User user = userService.findByIdAndIsDelete(userId);
|
|
|
- log.info("用户: {}", user.getMobile());
|
|
|
- LoanCase loanCase = loanCaseService.findLoanCaseByIdAndIsDelete(preApprovalDTO.getCaseId(),false);
|
|
|
+ Long caseId=preApprovalDTO.getCaseId();
|
|
|
+ LoanCase loanCase = loanCaseService.findLoanCaseByIdAndIsDelete(caseId,false);
|
|
|
if(loanCase == null||loanCase.getIsDelete()){
|
|
|
return ResultUtil.error(PROJECT_NOT_EXIST.getCode(), PROJECT_NOT_EXIST.getMsg());
|
|
|
}
|
|
|
- StepVO step = stepService.findByStepNameAndCaseId(StepPropertyEnum.PRE_TRIAL.getLabel(), preApprovalDTO.getCaseId());
|
|
|
- if(step.getUserId2()!=null&&userId!=step.getUserId2()){
|
|
|
- return ResultUtil.error(STEP_USER_NOT_EXPECTED.getCode(), "环节处理人不是预期用户");
|
|
|
- }
|
|
|
- if(step.getStatus()==StepEnum.COMPLETED.getMsg()){
|
|
|
- return ResultUtil.error(STEP_HAS_COMPLETEED.getCode(), "环节已完成,无法重复审批");
|
|
|
- }
|
|
|
- ApprovalRecordVO approvalRecord_origin = approvalService.findByCaseIdAndIsDeleteAndStepName(preApprovalDTO.getCaseId(),StepPropertyEnum.PRE_TRIAL.getLabel(),userId);
|
|
|
- if (approvalRecord_origin == null) {
|
|
|
- // 创建审批记录
|
|
|
- ApprovalRecord approvalRecord = new ApprovalRecord();
|
|
|
- approvalRecord.setCaseId(preApprovalDTO.getCaseId());
|
|
|
- approvalRecord.setStepName(StepPropertyEnum.PRE_TRIAL.getLabel());
|
|
|
- approvalRecord.setApproverId(user.getId());
|
|
|
- approvalRecord.setDecision(DecisionEnum.PASS.getMsg());
|
|
|
- approvalRecord.setComments(preApprovalDTO.getComments());
|
|
|
- approvalRecord.setCreateTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
- approvalRecord.setUpdateTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
- approvalRecord.setIsDelete(false);
|
|
|
- // 保存到数据库
|
|
|
- approvalService.save(approvalRecord);
|
|
|
- stepService.updateUserId2ByCaseIdAndStepName(StepPropertyEnum.PRE_TRIAL.getLabel(), user.getId(), preApprovalDTO.getCaseId());
|
|
|
- }else {
|
|
|
- approvalService.updateDecisionByCaseIdAndStepNameAndIsDelete(DecisionEnum.PASS.getMsg(), preApprovalDTO.getCaseId(), StepPropertyEnum.PRE_TRIAL.getLabel(), preApprovalDTO.getComments(), userId);
|
|
|
- }
|
|
|
- stepService.updateUserId2ByCaseIdAndStepName(StepPropertyEnum.PRE_TRIAL.getLabel(),userId,preApprovalDTO.getCaseId());
|
|
|
+ StepVO step = stepService.findByStepNameAndCaseId(StepPropertyEnum.PRE_TRIAL.getLabel(), caseId);
|
|
|
+ if(ObjectUtils.isEmpty(step)||!step.getStatus().equals(StepEnum.PROCESS.getMsg()))
|
|
|
+ throw new DescribeException(STEP_HAS_NOT_PROCESS);
|
|
|
+
|
|
|
+ //如果当前业务员与第一个业务员相同 或 当前业务员与第二个业务员不同 则报错
|
|
|
+ if((step.getUserId1()!=null && step.getUserId1().equals(userId)) || (step.getUserId2()!=null&&userId!=step.getUserId2()))
|
|
|
+ throw new DescribeException(STEP_USER_NOT_EXPECTED);
|
|
|
+
|
|
|
+ //添加记录
|
|
|
+ approvalService.addApprovalRecord(caseId,StepPropertyEnum.PRE_TRIAL.getLabel(),DecisionEnum.PASS.getMsg(),preApprovalDTO.getComments());
|
|
|
+
|
|
|
+ stepService.updateUserId1ByCaseIdAndStepName(StepPropertyEnum.PRE_TRIAL.getLabel(),userId,caseId);
|
|
|
//更新步骤状态
|
|
|
- stepService.updateStatusByCaseId(StepEnum.COMPLETED.getMsg(), StepPropertyEnum.PRE_TRIAL_PARENT.getLabel(), preApprovalDTO.getCaseId());
|
|
|
- stepService.updateStatusByCaseId(StepEnum.COMPLETED.getMsg(), StepPropertyEnum.PRE_TRIAL.getLabel(), preApprovalDTO.getCaseId());
|
|
|
- stepService.updateStatusByCaseId(StepEnum.PROCESS.getMsg(), StepPropertyEnum.APPROVAL_PARENT.getLabel(), preApprovalDTO.getCaseId());
|
|
|
- stepService.updateStatusByCaseId(StepEnum.PROCESS.getMsg(), StepPropertyEnum.APPROVAL.getLabel(), preApprovalDTO.getCaseId());
|
|
|
- loanCaseService.updateUpdatetimeByIdAndIsDeleted(preApprovalDTO.getCaseId(),false);
|
|
|
+ stepService.updateStatusByCaseId(StepEnum.COMPLETED.getMsg(), StepPropertyEnum.PRE_TRIAL_PARENT.getLabel(),caseId);
|
|
|
+ stepService.updateStatusByCaseId(StepEnum.COMPLETED.getMsg(), StepPropertyEnum.PRE_TRIAL.getLabel(), caseId);
|
|
|
+ stepService.tryStartStep(StepPropertyEnum.PRE_TRIAL.getLabel(),caseId);
|
|
|
+ loanCaseService.updateUpdatetimeByIdAndIsDeleted(caseId,false);
|
|
|
//TODO:微信推送预审通过消息和通知下一环节
|
|
|
// SysMessage message = new SysMessage();
|
|
|
// message.setMobile(null);
|
|
|
@@ -182,47 +155,35 @@ public class ApprovalController {
|
|
|
@PreAuthorize("@pms.hasAnyRoles('LEAD_SALES','ASSIST_SALES')")
|
|
|
@ApiOperation("业务预审拒绝")
|
|
|
public Result pre_approval_reject(@RequestBody PreApprovalDTO preApprovalDTO) {
|
|
|
+ if(ObjectUtils.isEmpty(preApprovalDTO)||ObjectUtils.isEmpty(preApprovalDTO.getCaseId()))
|
|
|
+ throw new DescribeException(INPUT_ERROR);
|
|
|
+
|
|
|
Long userId= BaseContext.getCurrentId();
|
|
|
- log.info("用户id: {}", userId);
|
|
|
- User user = userService.findByIdAndIsDelete(userId);
|
|
|
- log.info("用户: {}", user.getMobile());
|
|
|
- LoanCase loanCase = loanCaseService.findLoanCaseByIdAndIsDelete(preApprovalDTO.getCaseId(),false);
|
|
|
- StepVO step = stepService.findByStepNameAndCaseId(StepPropertyEnum.PRE_TRIAL.getLabel(), preApprovalDTO.getCaseId());
|
|
|
+ Long caseId = preApprovalDTO.getCaseId();
|
|
|
+
|
|
|
+ LoanCase loanCase = loanCaseService.findLoanCaseByIdAndIsDelete(caseId,false);
|
|
|
+ StepVO step = stepService.findByStepNameAndCaseId(StepPropertyEnum.PRE_TRIAL.getLabel(),caseId);
|
|
|
+ if(ObjectUtils.isEmpty(step)||!step.getStatus().equals(StepEnum.PROCESS.getMsg()))
|
|
|
+ throw new DescribeException(STEP_HAS_NOT_PROCESS);
|
|
|
+
|
|
|
//判断过去处理人与目前处理人是否一致
|
|
|
- if(step.getUserId2()!=null&&userId!=step.getUserId2()){
|
|
|
- return ResultUtil.error(STEP_USER_NOT_EXPECTED.getCode(), "环节处理人不是预期用户");
|
|
|
- }
|
|
|
- if(step.getStatus()==StepEnum.COMPLETED.getMsg()){
|
|
|
- return ResultUtil.error(STEP_HAS_COMPLETEED.getCode(), "环节已完成,无法重复审批");
|
|
|
- }
|
|
|
+ if(step.getUserId2()!=null&&userId!=step.getUserId2())
|
|
|
+ throw new DescribeException(STEP_USER_NOT_EXPECTED);
|
|
|
+
|
|
|
if(loanCase == null||loanCase.getIsDelete()){
|
|
|
return ResultUtil.error(PROJECT_NOT_EXIST.getCode(), PROJECT_NOT_EXIST.getMsg());
|
|
|
}
|
|
|
- ApprovalRecordVO approvalRecord_origin = approvalService.findByCaseIdAndIsDeleteAndStepName(preApprovalDTO.getCaseId(),StepPropertyEnum.PRE_TRIAL.getLabel(),userId);
|
|
|
- if(approvalRecord_origin == null) {
|
|
|
- log.info("没找到对应以前审批记录");
|
|
|
- // 创建审批记录
|
|
|
- ApprovalRecord approvalRecord = new ApprovalRecord();
|
|
|
- approvalRecord.setCaseId(preApprovalDTO.getCaseId());
|
|
|
- approvalRecord.setStepName(StepPropertyEnum.PRE_TRIAL.getLabel());
|
|
|
- approvalRecord.setApproverId(userId);
|
|
|
- approvalRecord.setDecision(DecisionEnum.REJECT.getMsg());
|
|
|
- approvalRecord.setComments(preApprovalDTO.getComments());
|
|
|
- approvalRecord.setCreateTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
- approvalRecord.setUpdateTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
- approvalRecord.setIsDelete(false);
|
|
|
- // 保存到数据库
|
|
|
- approvalService.save(approvalRecord);
|
|
|
- }else{
|
|
|
- log.info("找到对应以前审批记录");
|
|
|
- approvalService.updateDecisionByCaseIdAndStepNameAndIsDelete(DecisionEnum.REJECT.getMsg(),preApprovalDTO.getCaseId(),StepPropertyEnum.PRE_TRIAL.getLabel(),preApprovalDTO.getComments(),userId);
|
|
|
- }
|
|
|
- stepService.updateUserId2ByCaseIdAndStepName(StepPropertyEnum.PRE_TRIAL.getLabel(),userId,preApprovalDTO.getCaseId());
|
|
|
- stepService.updateStatusByCaseId(StepEnum.PROCESS.getMsg(),StepPropertyEnum.BUSINESS_ACCEPT.getLabel(),preApprovalDTO.getCaseId());
|
|
|
- stepService.updateStatusByCaseId(StepEnum.PROCESS.getMsg(),StepPropertyEnum.BUSINESS_ACCEPT_PARENT.getLabel(),preApprovalDTO.getCaseId());
|
|
|
- stepService.updateStatusByCaseId(StepEnum.UNSTART.getMsg(),StepPropertyEnum.PRE_TRIAL_PARENT.getLabel(),preApprovalDTO.getCaseId());
|
|
|
- stepService.updateStatusByCaseId(StepEnum.UNSTART.getMsg(),StepPropertyEnum.PRE_TRIAL.getLabel(),preApprovalDTO.getCaseId());
|
|
|
- loanCaseService.updateUpdatetimeByIdAndIsDeleted(preApprovalDTO.getCaseId(),false);
|
|
|
+ //添加记录
|
|
|
+ approvalService.addApprovalRecord(caseId,StepPropertyEnum.PRE_TRIAL.getLabel(),DecisionEnum.REJECT.getMsg(),preApprovalDTO.getComments());
|
|
|
+ RedisData redisData = new RedisData(stringRedisTemplate);
|
|
|
+ redisData.setRejectApprovalRecord(caseId,StepPropertyEnum.BUSINESS_ACCEPT.getLabel(),preApprovalDTO.getComments());
|
|
|
+
|
|
|
+ stepService.updateUserId2ByCaseIdAndStepName(StepPropertyEnum.PRE_TRIAL.getLabel(),userId,caseId);
|
|
|
+ stepService.updateStatusByCaseId(StepEnum.PROCESS.getMsg(),StepPropertyEnum.BUSINESS_ACCEPT.getLabel(),caseId);
|
|
|
+ stepService.updateStatusByCaseId(StepEnum.PROCESS.getMsg(),StepPropertyEnum.BUSINESS_ACCEPT_PARENT.getLabel(),caseId);
|
|
|
+ stepService.updateStatusByCaseId(StepEnum.UNSTART.getMsg(),StepPropertyEnum.PRE_TRIAL_PARENT.getLabel(),caseId);
|
|
|
+ stepService.updateStatusByCaseId(StepEnum.UNSTART.getMsg(),StepPropertyEnum.PRE_TRIAL.getLabel(),caseId);
|
|
|
+ loanCaseService.updateUpdatetimeByIdAndIsDeleted(caseId,false);
|
|
|
//TODO:微信推送预审拒绝消息和通知下一环节
|
|
|
// SysMessage message = new SysMessage();
|
|
|
// message.setMobile(null);
|
|
|
@@ -242,79 +203,74 @@ public class ApprovalController {
|
|
|
@ApiOperation("获取审批详情")
|
|
|
@PreAuthorize("@pms.hasAnyRoles('SYSTEM_ADMIN','APPROVER','LEAD_SALES', 'ASSIST_SALES', 'FINANCE', 'BACK_OFFICE')")
|
|
|
public Result getApprovalDetail(@RequestParam Long caseId) {
|
|
|
- ApprovalVO approvalVO = new ApprovalVO();
|
|
|
- StepVO stepVO = stepService.findByStepNameAndCaseId(StepPropertyEnum.APPROVAL.getLabel(), caseId);
|
|
|
- Map<UserVO,String> decision=new HashMap<>();
|
|
|
- Map<UserVO,String> comment=new HashMap<>();
|
|
|
-
|
|
|
- if (stepVO.getUserId1()!=null){
|
|
|
- User user=userService.findByIdAndIsDelete(stepVO.getUserId1());
|
|
|
- ApprovalRecordVO approvalRecordVO = approvalService.findByCaseIdAndIsDeleteAndStepName(caseId, StepPropertyEnum.APPROVAL.getLabel(), user.getId());
|
|
|
- decision.put(BeanUtil.copyProperties(user,UserVO.class),approvalRecordVO.getDecision());
|
|
|
- comment.put(BeanUtil.copyProperties(user,UserVO.class),approvalRecordVO.getComments());
|
|
|
- }
|
|
|
-
|
|
|
- if (stepVO.getUserId2()!=null){
|
|
|
- User user=userService.findByIdAndIsDelete(stepVO.getUserId2());
|
|
|
- ApprovalRecordVO approvalRecordVO = approvalService.findByCaseIdAndIsDeleteAndStepName(caseId, StepPropertyEnum.APPROVAL.getLabel(), user.getId());
|
|
|
- decision.put(BeanUtil.copyProperties(user,UserVO.class),approvalRecordVO.getDecision());
|
|
|
- comment.put(BeanUtil.copyProperties(user,UserVO.class),approvalRecordVO.getComments());
|
|
|
- }
|
|
|
+ if (ObjectUtils.isEmpty(caseId) || !loanCaseService.existsByIdAndIsDelete(caseId))
|
|
|
+ throw new DescribeException(PROJECT_NOT_EXIST);
|
|
|
|
|
|
- return ResultUtil.success("success",approvalVO);
|
|
|
+ return ResultUtil.success("success",approvalService.findByCaseIdAndStepNameAndIsDelete(caseId,StepPropertyEnum.APPROVAL.getLabel()));
|
|
|
}
|
|
|
|
|
|
@PostMapping("/approval/pass")
|
|
|
@PreAuthorize("@pms.hasRole('APPROVER')")
|
|
|
@ApiOperation("业务审批通过")
|
|
|
public Result approval_pass(@RequestBody ApprovalDTO approvalDTO) {
|
|
|
+ if(ObjectUtils.isEmpty(approvalDTO)||approvalDTO.getCaseId() == null)
|
|
|
+ throw new DescribeException(INPUT_ERROR);
|
|
|
+
|
|
|
Long userId= BaseContext.getCurrentId();
|
|
|
- log.info("用户id: {}", userId);
|
|
|
+ Long caseId = approvalDTO.getCaseId();
|
|
|
//审批业务逻辑
|
|
|
- LoanCase loanCase = loanCaseService.findLoanCaseByIdAndIsDelete(approvalDTO.getCaseId(), false);
|
|
|
- StepVO step = stepService.findByStepNameAndCaseId(StepPropertyEnum.APPROVAL.getLabel(), approvalDTO.getCaseId());
|
|
|
+ LoanCase loanCase = loanCaseService.findLoanCaseByIdAndIsDelete(caseId, false);
|
|
|
+ StepVO step = stepService.findByStepNameAndCaseId(StepPropertyEnum.APPROVAL.getLabel(),caseId);
|
|
|
//判断过去处理人与目前处理人是否一致
|
|
|
- if(step.getUserId1()!=null&&step.getUserId2()!=null&&userId != step.getUserId2()&&userId!=step.getUserId1()){
|
|
|
- return ResultUtil.error(STEP_USER_NOT_EXPECTED.getCode(), "环节处理人不是预期用户");
|
|
|
- }
|
|
|
- if(step.getStatus()==StepEnum.COMPLETED.getMsg()){
|
|
|
- return ResultUtil.error(STEP_HAS_COMPLETEED.getCode(), "环节已完成,无法重复审批");
|
|
|
- }
|
|
|
+ if(ObjectUtils.isEmpty(step)||!step.getStatus().equals(StepEnum.PROCESS.getMsg()))
|
|
|
+ throw new DescribeException(STEP_HAS_NOT_PROCESS);
|
|
|
+
|
|
|
+ if(step.getUserId1()!=null&&step.getUserId2()!=null&&userId != step.getUserId2()&&userId!=step.getUserId1())
|
|
|
+ throw new DescribeException(STEP_USER_NOT_EXPECTED);
|
|
|
+
|
|
|
if(loanCase == null || loanCase.getIsDelete()){
|
|
|
- return ResultUtil.error(PROJECT_NOT_EXIST.getCode(), PROJECT_NOT_EXIST.getMsg());
|
|
|
- }
|
|
|
- ApprovalRecordVO approvalRecord_origin = approvalService.findByCaseIdAndIsDeleteAndStepName(approvalDTO.getCaseId(),StepPropertyEnum.APPROVAL.getLabel(),userId);
|
|
|
- if(approvalRecord_origin == null) {
|
|
|
- log.info("没找到对应以前审批记录");
|
|
|
- // 创建审批记录
|
|
|
- ApprovalRecord approvalRecord = new ApprovalRecord();
|
|
|
- approvalRecord.setCaseId(approvalDTO.getCaseId());
|
|
|
- approvalRecord.setStepName(StepPropertyEnum.APPROVAL.getLabel());
|
|
|
- approvalRecord.setApproverId(userId);
|
|
|
- approvalRecord.setDecision(DecisionEnum.PASS.getMsg());
|
|
|
- approvalRecord.setComments(approvalDTO.getComments());
|
|
|
- approvalRecord.setCreateTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
- approvalRecord.setUpdateTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
- approvalRecord.setIsDelete(false);
|
|
|
- // 保存到数据库
|
|
|
- approvalService.save(approvalRecord);
|
|
|
- }else{
|
|
|
- log.info("找到对应以前审批记录");
|
|
|
- approvalService.updateDecisionByCaseIdAndStepNameAndIsDelete(DecisionEnum.PASS.getMsg(),approvalDTO.getCaseId(),StepPropertyEnum.APPROVAL.getLabel(),approvalDTO.getComments(),userId);
|
|
|
+ throw new DescribeException(PROJECT_NOT_EXIST);
|
|
|
}
|
|
|
+
|
|
|
+ List<ApprovalRecordVO> records = approvalService.findByCaseIdAndStepNameAndApproverIdAndIsDelete(caseId, StepPropertyEnum.APPROVAL.getLabel(), userId);
|
|
|
+ ApprovalRecordVO record = ObjectUtils.isEmpty(records)?null:records.get(records.size()-1);//获取当前审批人上次的记录
|
|
|
if(step.getUserId1()== null){
|
|
|
- stepService.updateUserId1ByCaseIdAndStepName(StepPropertyEnum.APPROVAL.getLabel(),userId,approvalDTO.getCaseId());
|
|
|
- }else if(step.getUserId2()== null){
|
|
|
- stepService.updateUserId2ByCaseIdAndStepName(StepPropertyEnum.APPROVAL.getLabel(),userId,approvalDTO.getCaseId());
|
|
|
+ stepService.updateUserId1ByCaseIdAndStepName(StepPropertyEnum.APPROVAL.getLabel(),userId,caseId);
|
|
|
+ }else if(step.getUserId2()== null ){
|
|
|
+ //如果用户1审批过且通过,无法重复审批
|
|
|
+ if(step.getUserId1() == userId && record!=null && record.getDecision().equals(DecisionEnum.PASS.getMsg()))
|
|
|
+ throw new DescribeException(APPROVAL_USER_IS_COMPLETED);
|
|
|
+ else if(step.getUserId1()!= userId)
|
|
|
+ stepService.updateUserId2ByCaseIdAndStepName(StepPropertyEnum.APPROVAL.getLabel(),userId,caseId);
|
|
|
+ }else {
|
|
|
+ List<ApprovalRecordVO> approvalRecords1 = approvalService.findByCaseIdAndStepNameAndApproverIdAndIsDelete(caseId, StepPropertyEnum.APPROVAL.getLabel(), step.getUserId1());
|
|
|
+ ApprovalRecordVO approvalRecord1 = approvalRecords1.get(approvalRecords1.size()-1);
|
|
|
+ List<ApprovalRecordVO> approvalRecords2 = approvalService.findByCaseIdAndStepNameAndApproverIdAndIsDelete(caseId, StepPropertyEnum.APPROVAL.getLabel(), step.getUserId2());
|
|
|
+ ApprovalRecordVO approvalRecord2 = approvalRecords2.get(approvalRecords2.size()-1);
|
|
|
+ if(step.getUserId1()== userId){//仅版本一样或版本小于可新增
|
|
|
+ if(approvalRecord1.getVersion()> approvalRecord2.getVersion() && approvalRecord1.getDecision().equals(DecisionEnum.PASS.getMsg()))
|
|
|
+ throw new DescribeException(APPROVAL_USER_IS_COMPLETED);
|
|
|
+ }else{
|
|
|
+ if(approvalRecord1.getVersion()< approvalRecord2.getVersion() && approvalRecord2.getDecision().equals(DecisionEnum.PASS.getMsg()))
|
|
|
+ throw new DescribeException(APPROVAL_USER_IS_COMPLETED);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ approvalService.addApprovalRecord(caseId,StepPropertyEnum.APPROVAL.getLabel(),DecisionEnum.PASS.getMsg(),approvalDTO.getComments());
|
|
|
+
|
|
|
+ step=stepService.findByStepNameAndCaseId(StepPropertyEnum.APPROVAL.getLabel(), caseId);
|
|
|
if(step.getUserId1()!=null&&step.getUserId2()!=null){
|
|
|
- ApprovalRecordVO approvalRecord_user1 = approvalService.findByCaseIdAndIsDeleteAndStepName(approvalDTO.getCaseId(),StepPropertyEnum.APPROVAL.getLabel(),step.getUserId1());
|
|
|
- ApprovalRecordVO approvalRecord_user2 = approvalService.findByCaseIdAndIsDeleteAndStepName(approvalDTO.getCaseId(),StepPropertyEnum.APPROVAL.getLabel(),step.getUserId2());
|
|
|
- if(approvalRecord_user1.getDecision() == DecisionEnum.PASS.getMsg()&&approvalRecord_user2.getDecision() == DecisionEnum.PASS.getMsg()){
|
|
|
- stepService.updateStatusByCaseId(StepEnum.COMPLETED.getMsg(),StepPropertyEnum.APPROVAL_PARENT.getLabel(),approvalDTO.getCaseId());
|
|
|
- stepService.updateStatusByCaseId(StepEnum.COMPLETED.getMsg(),StepPropertyEnum.APPROVAL.getLabel(),approvalDTO.getCaseId());
|
|
|
- stepService.updateStatusByCaseId(StepEnum.PROCESS.getMsg(),StepPropertyEnum.CONTRACT_SIGN_PARENT.getLabel(),approvalDTO.getCaseId());
|
|
|
- stepService.updateStatusByCaseId(StepEnum.PROCESS.getMsg(),StepPropertyEnum.CONTRACT_SIGN.getLabel(),approvalDTO.getCaseId());
|
|
|
+ List<ApprovalRecordVO> records1 = approvalService.findByCaseIdAndStepNameAndApproverIdAndIsDelete(caseId, StepPropertyEnum.APPROVAL.getLabel(), step.getUserId1());
|
|
|
+ ApprovalRecordVO record1 = records1.get(records1.size()-1);//获取当前审批人上次的记录
|
|
|
+ List<ApprovalRecordVO> records2 = approvalService.findByCaseIdAndStepNameAndApproverIdAndIsDelete(caseId, StepPropertyEnum.APPROVAL.getLabel(), step.getUserId2());
|
|
|
+ ApprovalRecordVO record2 = records2.get(records2.size()-1);//获取当前审批人上次的记录
|
|
|
+
|
|
|
+ //TODO:同一阶段双人审批通过,才结束
|
|
|
+ if(record1.getVersion()==record2.getVersion() && record1.getDecision().equals(DecisionEnum.PASS.getMsg()) && record2.getDecision().equals(DecisionEnum.PASS.getMsg())){
|
|
|
+ stepService.updateStatusByCaseId(StepEnum.COMPLETED.getMsg(),StepPropertyEnum.APPROVAL_PARENT.getLabel(),caseId);
|
|
|
+ stepService.updateStatusByCaseId(StepEnum.COMPLETED.getMsg(),StepPropertyEnum.APPROVAL.getLabel(),caseId);
|
|
|
+
|
|
|
+ stepService.tryStartStep(StepPropertyEnum.APPROVAL.getLabel(), caseId);
|
|
|
//TODO微信推送审批通过消息和通知下一环节
|
|
|
}
|
|
|
}else{
|
|
|
@@ -329,53 +285,45 @@ public class ApprovalController {
|
|
|
@PreAuthorize("@pms.hasRole('APPROVER')")
|
|
|
@ApiOperation("业务审批拒绝")
|
|
|
public Result approval_reject(@RequestBody ApprovalDTO approvalDTO) {
|
|
|
+ if(ObjectUtils.isEmpty(approvalDTO)||approvalDTO.getCaseId() == null)
|
|
|
+ throw new DescribeException(INPUT_ERROR);
|
|
|
Long userId= BaseContext.getCurrentId();
|
|
|
- log.info("用户id: {}", userId);
|
|
|
+ Long caseId = approvalDTO.getCaseId();
|
|
|
//审批业务逻辑
|
|
|
LoanCase loanCase = loanCaseService.findLoanCaseByIdAndIsDelete(approvalDTO.getCaseId(),false);
|
|
|
if(loanCase == null||loanCase.getIsDelete()){
|
|
|
return ResultUtil.error(PROJECT_NOT_EXIST.getCode(), PROJECT_NOT_EXIST.getMsg());
|
|
|
}
|
|
|
StepVO step = stepService.findByStepNameAndCaseId(StepPropertyEnum.APPROVAL.getLabel(), approvalDTO.getCaseId());
|
|
|
+ if(ObjectUtils.isEmpty(step)||!step.getStatus().equals(StepEnum.PROCESS.getMsg()))
|
|
|
+ throw new DescribeException(STEP_HAS_NOT_PROCESS);
|
|
|
+
|
|
|
//判断过去处理人与目前处理人是否一致
|
|
|
- if(step.getUserId1()!=null&&step.getUserId2()!=null&&userId!=step.getUserId2()&&userId!=step.getUserId1()){
|
|
|
- return ResultUtil.error(STEP_USER_NOT_EXPECTED.getCode(), "环节处理人不是预期用户");
|
|
|
- }
|
|
|
- if(step.getStatus()==StepEnum.COMPLETED.getMsg()){
|
|
|
- return ResultUtil.error(STEP_HAS_COMPLETEED.getCode(), "环节已完成,无法重复审批");
|
|
|
- }
|
|
|
- //审批记录处理
|
|
|
- ApprovalRecordVO approvalRecord_origin = approvalService.findByCaseIdAndIsDeleteAndStepName(approvalDTO.getCaseId(),StepPropertyEnum.APPROVAL.getLabel(),userId);
|
|
|
- if(approvalRecord_origin == null) {
|
|
|
- log.info("没找到对应以前审批记录");
|
|
|
- // 创建审批记录
|
|
|
- ApprovalRecord approvalRecord = new ApprovalRecord();
|
|
|
- approvalRecord.setCaseId(approvalDTO.getCaseId());
|
|
|
- approvalRecord.setStepName(StepPropertyEnum.APPROVAL.getLabel());
|
|
|
- approvalRecord.setApproverId(userId);
|
|
|
- approvalRecord.setDecision(DecisionEnum.REJECT.getMsg());
|
|
|
- approvalRecord.setComments(approvalDTO.getComments());
|
|
|
- approvalRecord.setCreateTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
- approvalRecord.setUpdateTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
- approvalRecord.setIsDelete(false);
|
|
|
- // 保存到数据库
|
|
|
- approvalService.save(approvalRecord);
|
|
|
- }else{
|
|
|
- log.info("找到对应以前审批记录");
|
|
|
- approvalService.updateDecisionByCaseIdAndStepNameAndIsDelete(DecisionEnum.REJECT.getMsg(),approvalDTO.getCaseId(),StepPropertyEnum.APPROVAL.getLabel(),approvalDTO.getComments(),userId);
|
|
|
- }
|
|
|
+ if(step.getUserId1()!=null&&step.getUserId2()!=null&&userId!=step.getUserId2()&&userId!=step.getUserId1())
|
|
|
+ throw new DescribeException(STEP_USER_NOT_EXPECTED);
|
|
|
+
|
|
|
+ List<ApprovalRecordVO> records = approvalService.findByCaseIdAndStepNameAndApproverIdAndIsDelete(caseId, StepPropertyEnum.APPROVAL.getLabel(), userId);
|
|
|
+ ApprovalRecordVO record = ObjectUtils.isEmpty(records)?null:records.get(records.size()-1);//获取当前审批人上次的记录
|
|
|
if(step.getUserId1()== null){
|
|
|
- stepService.updateUserId1ByCaseIdAndStepName(StepPropertyEnum.APPROVAL.getLabel(),userId,approvalDTO.getCaseId());
|
|
|
- }else if(step.getUserId2()== null){
|
|
|
- stepService.updateUserId2ByCaseIdAndStepName(StepPropertyEnum.APPROVAL.getLabel(),userId,approvalDTO.getCaseId());
|
|
|
+ stepService.updateUserId1ByCaseIdAndStepName(StepPropertyEnum.APPROVAL.getLabel(),userId,caseId);
|
|
|
+ }else if(step.getUserId2()== null ){
|
|
|
+ //如果用户1审批过且通过,无法重复审批
|
|
|
+ if(step.getUserId1() == userId && record!=null && record.getDecision().equals(DecisionEnum.PASS.getMsg()))
|
|
|
+ throw new DescribeException(APPROVAL_USER_IS_COMPLETED);
|
|
|
+ else if(step.getUserId1()!= userId)
|
|
|
+ stepService.updateUserId2ByCaseIdAndStepName(StepPropertyEnum.APPROVAL.getLabel(),userId,caseId);
|
|
|
}
|
|
|
+ approvalService.addApprovalRecord(caseId,StepPropertyEnum.APPROVAL.getLabel(),DecisionEnum.REJECT.getMsg(),approvalDTO.getComments());
|
|
|
+ RedisData redisData = new RedisData(stringRedisTemplate);
|
|
|
+ redisData.setRejectApprovalRecord(caseId,StepPropertyEnum.BUSINESS_ACCEPT.getLabel(),approvalDTO.getComments());
|
|
|
+
|
|
|
//更新环节状态
|
|
|
- stepService.updateStatusByCaseId(StepEnum.PROCESS.getMsg(),StepPropertyEnum.BUSINESS_ACCEPT_PARENT.getLabel(),approvalDTO.getCaseId());
|
|
|
- stepService.updateStatusByCaseId(StepEnum.PROCESS.getMsg(),StepPropertyEnum.BUSINESS_ACCEPT.getLabel(),approvalDTO.getCaseId());
|
|
|
- stepService.updateStatusByCaseId(StepEnum.UNSTART.getMsg(),StepPropertyEnum.PRE_TRIAL_PARENT.getLabel(),approvalDTO.getCaseId());
|
|
|
- stepService.updateStatusByCaseId(StepEnum.UNSTART.getMsg(),StepPropertyEnum.PRE_TRIAL.getLabel(),approvalDTO.getCaseId());
|
|
|
- stepService.updateStatusByCaseId(StepEnum.UNSTART.getMsg(),StepPropertyEnum.APPROVAL_PARENT.getLabel(),approvalDTO.getCaseId());
|
|
|
- stepService.updateStatusByCaseId(StepEnum.UNSTART.getMsg(),StepPropertyEnum.APPROVAL.getLabel(),approvalDTO.getCaseId());
|
|
|
+ stepService.updateStatusByCaseId(StepEnum.PROCESS.getMsg(),StepPropertyEnum.BUSINESS_ACCEPT_PARENT.getLabel(),caseId);
|
|
|
+ stepService.updateStatusByCaseId(StepEnum.PROCESS.getMsg(),StepPropertyEnum.BUSINESS_ACCEPT.getLabel(),caseId);
|
|
|
+ stepService.updateStatusByCaseId(StepEnum.UNSTART.getMsg(),StepPropertyEnum.PRE_TRIAL_PARENT.getLabel(),caseId);
|
|
|
+ stepService.updateStatusByCaseId(StepEnum.UNSTART.getMsg(),StepPropertyEnum.PRE_TRIAL.getLabel(),caseId);
|
|
|
+ stepService.updateStatusByCaseId(StepEnum.UNSTART.getMsg(),StepPropertyEnum.APPROVAL_PARENT.getLabel(),caseId);
|
|
|
+ stepService.updateStatusByCaseId(StepEnum.UNSTART.getMsg(),StepPropertyEnum.APPROVAL.getLabel(),caseId);
|
|
|
//TODO微信推送审批驳回消息和通知重新受理(到业务受理)
|
|
|
|
|
|
return ResultUtil.success("success","审批驳回");
|
|
|
@@ -384,55 +332,42 @@ public class ApprovalController {
|
|
|
@PreAuthorize("@pms.hasRole('APPROVER')")
|
|
|
@ApiOperation("业务审批终结")
|
|
|
public Result approval_end(@RequestBody ApprovalDTO approvalDTO) {
|
|
|
+ if (ObjectUtils.isEmpty(approvalDTO)||approvalDTO.getCaseId() == null)
|
|
|
+ throw new DescribeException(INPUT_ERROR);
|
|
|
Long userId= BaseContext.getCurrentId();
|
|
|
- log.info("用户id: {}", userId);
|
|
|
+ Long caseId = approvalDTO.getCaseId();
|
|
|
//审批业务逻辑
|
|
|
LoanCase loanCase = loanCaseService.findLoanCaseByIdAndIsDelete(approvalDTO.getCaseId(),false);
|
|
|
if(loanCase == null||loanCase.getIsDelete()){
|
|
|
return ResultUtil.error(PROJECT_NOT_EXIST.getCode(), PROJECT_NOT_EXIST.getMsg());
|
|
|
}
|
|
|
StepVO step = stepService.findByStepNameAndCaseId(StepPropertyEnum.APPROVAL.getLabel(), approvalDTO.getCaseId());
|
|
|
+ if(ObjectUtils.isEmpty(step)||!step.getStatus().equals(StepEnum.PROCESS.getMsg()))
|
|
|
+ throw new DescribeException(STEP_HAS_NOT_PROCESS);
|
|
|
//判断过去处理人与目前处理人是否一致
|
|
|
- if(step.getUserId1()!=null&&step.getUserId2()!=null&&userId!=step.getUserId2()&&userId!=step.getUserId1()){
|
|
|
- return ResultUtil.error(STEP_USER_NOT_EXPECTED.getCode(), "环节处理人不是预期用户");
|
|
|
- }
|
|
|
- if(step.getStatus()==StepEnum.COMPLETED.getMsg()){
|
|
|
- return ResultUtil.error(STEP_HAS_COMPLETEED.getCode(), "环节已完成,无法重复审批");
|
|
|
- }
|
|
|
+ if(step.getUserId1()!=null&&step.getUserId2()!=null&&userId!=step.getUserId2()&&userId!=step.getUserId1())
|
|
|
+ throw new DescribeException(STEP_USER_NOT_EXPECTED);
|
|
|
+
|
|
|
//审批记录处理
|
|
|
- ApprovalRecordVO approvalRecord_origin = approvalService.findByCaseIdAndIsDeleteAndStepName(approvalDTO.getCaseId(),StepPropertyEnum.APPROVAL.getLabel(),userId);
|
|
|
- if(approvalRecord_origin == null) {
|
|
|
- log.info("没找到对应以前审批记录");
|
|
|
- // 创建审批记录
|
|
|
- ApprovalRecord approvalRecord = new ApprovalRecord();
|
|
|
- approvalRecord.setCaseId(approvalDTO.getCaseId());
|
|
|
- approvalRecord.setStepName(StepPropertyEnum.APPROVAL.getLabel());
|
|
|
- approvalRecord.setApproverId(userId);
|
|
|
- approvalRecord.setDecision(DecisionEnum.TERMINATE.getMsg());
|
|
|
- approvalRecord.setComments(approvalDTO.getComments());
|
|
|
- approvalRecord.setCreateTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
- approvalRecord.setUpdateTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
- approvalRecord.setIsDelete(false);
|
|
|
- // 保存到数据库
|
|
|
- approvalService.save(approvalRecord);
|
|
|
- }else{
|
|
|
- log.info("找到对应以前审批记录");
|
|
|
- approvalService.updateDecisionByCaseIdAndStepNameAndIsDelete(DecisionEnum.TERMINATE.getMsg(),approvalDTO.getCaseId(),StepPropertyEnum.APPROVAL.getLabel(),approvalDTO.getComments(),userId);
|
|
|
- }
|
|
|
+ List<ApprovalRecordVO> records = approvalService.findByCaseIdAndStepNameAndApproverIdAndIsDelete(caseId, StepPropertyEnum.APPROVAL.getLabel(), userId);
|
|
|
+ ApprovalRecordVO record = ObjectUtils.isEmpty(records)?null:records.get(records.size()-1);//获取当前审批人上次的记录
|
|
|
if(step.getUserId1()== null){
|
|
|
- stepService.updateUserId1ByCaseIdAndStepName(StepPropertyEnum.APPROVAL.getLabel(),userId,approvalDTO.getCaseId());
|
|
|
- }else if(step.getUserId2()== null){
|
|
|
- stepService.updateUserId2ByCaseIdAndStepName(StepPropertyEnum.APPROVAL.getLabel(),userId,approvalDTO.getCaseId());
|
|
|
- }
|
|
|
- //更新项目和环节状态 作逻辑删除
|
|
|
- loanCaseService.logic_delete(approvalDTO.getCaseId());
|
|
|
- List<StepVO> steps = stepService.getStepByCaseId(approvalDTO.getCaseId());
|
|
|
- for (StepVO step_each : steps){
|
|
|
- stepService.logic_delete(step_each.getId());
|
|
|
+ stepService.updateUserId1ByCaseIdAndStepName(StepPropertyEnum.APPROVAL.getLabel(),userId,caseId);
|
|
|
+ }else if(step.getUserId2()== null ){
|
|
|
+ //如果用户1审批过且通过,无法重复审批
|
|
|
+ if(step.getUserId1() == userId && record!=null && record.getDecision().equals(DecisionEnum.PASS.getMsg()))
|
|
|
+ throw new DescribeException(APPROVAL_USER_IS_COMPLETED);
|
|
|
+ else if(step.getUserId1()!= userId)
|
|
|
+ stepService.updateUserId2ByCaseIdAndStepName(StepPropertyEnum.APPROVAL.getLabel(),userId,caseId);
|
|
|
}
|
|
|
+ approvalService.addApprovalRecord(caseId,StepPropertyEnum.APPROVAL.getLabel(),DecisionEnum.TERMINATE.getMsg(),approvalDTO.getComments());
|
|
|
+
|
|
|
+ //项目终结
|
|
|
+ loanCaseService.updateIsCompleteByCaseId(DecisionEnum.TERMINATE.getMsg(),caseId);
|
|
|
+
|
|
|
//TODO微信推送审批驳回消息和通知重新受理(到业务受理)
|
|
|
|
|
|
- return ResultUtil.success("success","审批驳回");
|
|
|
+ return ResultUtil.success("success","审批终结");
|
|
|
}
|
|
|
}
|
|
|
|