ContractController.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. package com.loan.system.controller.wechat;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import cn.hutool.http.server.HttpServerResponse;
  4. import com.loan.system.context.BaseContext;
  5. import com.loan.system.domain.dto.DocumentDTO;
  6. import com.loan.system.domain.entity.Contract;
  7. import com.loan.system.domain.entity.Document;
  8. import com.loan.system.domain.enums.ExceptionEnum;
  9. import com.loan.system.domain.pojo.ContractInformation;
  10. import com.loan.system.domain.vo.CustomerVO;
  11. import com.loan.system.domain.vo.LoanCaseSimpleVO;
  12. import com.loan.system.exception.DescribeException;
  13. import com.loan.system.service.*;
  14. import com.loan.system.utils.PoiWordUtil;
  15. import com.loan.system.domain.enums.StepEnum;
  16. import com.loan.system.domain.enums.StepPropertyEnum;
  17. import com.loan.system.domain.pojo.Result;
  18. import com.loan.system.domain.vo.ContractVO;
  19. import com.loan.system.domain.vo.StepVO;
  20. import com.loan.system.utils.ResultUtil;
  21. import io.swagger.annotations.Api;
  22. import io.swagger.annotations.ApiOperation;
  23. import org.springframework.beans.factory.annotation.Autowired;
  24. import org.springframework.beans.factory.annotation.Value;
  25. import org.springframework.security.access.prepost.PreAuthorize;
  26. import org.springframework.util.ObjectUtils;
  27. import org.springframework.web.bind.annotation.*;
  28. import javax.servlet.http.HttpServletResponse;
  29. import java.util.List;
  30. import java.util.UUID;
  31. import static com.loan.system.domain.enums.ExceptionEnum.STEP_HAS_NOT_PROCESS;
  32. import static com.loan.system.domain.enums.ExceptionEnum.STEP_USER_NOT_EXPECTED;
  33. @RestController
  34. @RequestMapping("/wechat/contract")
  35. @Api(tags = "合同签订接口")
  36. public class ContractController {
  37. @Value("${upload.templatePath}")
  38. private String contractPath;
  39. @Autowired
  40. private ContractService contractService;
  41. @Autowired
  42. private StepService stepService;
  43. @Autowired
  44. private DocumentService documentService;
  45. @Autowired
  46. private CustomerService customerService;
  47. @Autowired
  48. private LoanService loanService;
  49. @GetMapping
  50. @ApiOperation("显示所有合同(内部人员)")
  51. @PreAuthorize("@pms.hasAnyRoles('SYSTEM_ADMIN','APPROVER','LEAD_SALES', 'ASSIST_SALES', 'FINANCE', 'BACK_OFFICE')")
  52. public Result findContracts(@RequestParam Long caseId){
  53. return ResultUtil.success("success",contractService.findContractByCaseId(caseId));
  54. }
  55. @GetMapping("/{id}")
  56. @ApiOperation("显示合同文件详情(内部人员)")
  57. @PreAuthorize("@pms.hasAnyRoles('SYSTEM_ADMIN','APPROVER','LEAD_SALES', 'ASSIST_SALES', 'FINANCE', 'BACK_OFFICE')")
  58. public void findContractsDetails(@PathVariable("id") Long contractId , @RequestParam Long caseId , HttpServletResponse response){
  59. //获取合同信息
  60. Contract contractById = contractService.findContractById(contractId);
  61. if(ObjectUtils.isEmpty(contractById))
  62. throw new DescribeException(ExceptionEnum.CONTRACT_NOT_EXIST);
  63. getContractInformation(response,caseId,BeanUtil.copyProperties(contractById,ContractVO.class));
  64. }
  65. // @GetMapping("/{contractSeq}")
  66. // @ApiOperation("显示合同表详情(内部人员)")
  67. // @PreAuthorize("@pms.hasAnyRoles('SYSTEM_ADMIN','APPROVER','LEAD_SALES', 'ASSIST_SALES', 'FINANCE', 'BACK_OFFICE')")
  68. // public Result findContractsDetails(@PathVariable("contractSeq") Integer contractSeq , @RequestParam Long caseId , HttpServletResponse response){
  69. // //获取合同信息
  70. // List<ContractVO> contractVOS = contractService.findContractByCaseId(caseId);
  71. // if(contractVOS.size()<contractSeq)
  72. // throw new DescribeException(ExceptionEnum.CONTRACT_NOT_EXIST);
  73. // ContractVO contractVO = contractVOS.get(contractSeq-1);
  74. //
  75. // return ResultUtil.success("success",getContractInformation(response,caseId,contractVO));
  76. // }
  77. @PostMapping("/{id}")
  78. @ApiOperation("推送合同")
  79. @PreAuthorize("@pms.hasAnyRoles('SYSTEM_ADMIN','APPROVER','LEAD_SALES', 'ASSIST_SALES', 'FINANCE', 'BACK_OFFICE')")
  80. public Result pushContract(@PathVariable("id") Long contractId,@RequestParam Long caseId){
  81. if(caseId == null||!loanService.existsByIdAndIsDelete(caseId))
  82. throw new DescribeException(ExceptionEnum.PROJECT_NOT_EXIST);
  83. StepVO step = stepService.findByStepNameAndCaseId(StepPropertyEnum.CONTRACT_SIGN.getLabel(),caseId);
  84. if(ObjectUtils.isEmpty(step)||!step.getStatus().equals(StepEnum.PROCESS.getMsg()))
  85. throw new DescribeException(STEP_HAS_NOT_PROCESS);
  86. Long currentId = step.getUserId1();
  87. if(currentId!=null && !BaseContext.getCurrentId().equals(currentId)){
  88. throw new DescribeException(STEP_USER_NOT_EXPECTED);
  89. }
  90. Contract contract = contractService.findContractById(contractId);
  91. if(contract.getIsPush())
  92. throw new DescribeException(ExceptionEnum.CONTRACT_HAS_PUSH);
  93. contractService.updateIsPushById(contractId);
  94. //TODO:微信推送预审通过消息和通知下一环节
  95. // SysMessage message = new SysMessage();
  96. // message.setMobile(null);
  97. // message.setUserRole("");
  98. // message.setMessageTitle("");
  99. // message.setMessageContent("");
  100. // message.setStepName("");
  101. // message.setRelatedId(loanCase.getId());
  102. // message.setRelatedType("");
  103. // messageService.addMessage(message);
  104. // wxService.sendTemplateMessage(loanCase.getCustomer().getMobile(),new TemplateMessage());
  105. return ResultUtil.success("success");
  106. }
  107. @GetMapping("/customer")
  108. @ApiOperation("显示所有合同详情(客户)")
  109. @PreAuthorize("@pms.hasAnyRoles('EXTERNAL')")
  110. public Result findContractsByCustomer(@RequestParam Long caseId) {
  111. return ResultUtil.success("success",contractService.findContractByCaseIdAndIsPush(caseId,true));
  112. }
  113. @GetMapping("/customer/{id}")
  114. @ApiOperation("显示合同文件详情(客户)")
  115. @PreAuthorize("@pms.hasAnyRoles('EXTERNAL')")
  116. public void findContractsDetailByCustomer(@PathVariable("id") Long contractId ,@RequestParam Long caseId,HttpServletResponse response){
  117. if(caseId == null||!loanService.existsByIdAndIsDelete(caseId))
  118. throw new DescribeException(ExceptionEnum.PROJECT_NOT_EXIST);
  119. //显示已经推送过的合同
  120. Contract contractById = contractService.findContractById(contractId);
  121. if(ObjectUtils.isEmpty(contractById))
  122. throw new DescribeException(ExceptionEnum.CONTRACT_NOT_EXIST);
  123. if (!contractById.getIsPush())
  124. throw new DescribeException(ExceptionEnum.CONTRACT_NOT_PUSH);
  125. getContractInformation(response,caseId,BeanUtil.copyProperties(contractById,ContractVO.class));
  126. }
  127. // @GetMapping("/customer/{contractSeq}")
  128. // @ApiOperation("显示合同详情(客户)")
  129. // @PreAuthorize("@pms.hasAnyRoles('EXTERNAL')")
  130. // public Result findContractsByCustomer(@PathVariable("contractSeq") Integer contractSeq ,@RequestParam Long caseId,HttpServletResponse response){
  131. // //显示已经推送过的合同
  132. // List<ContractVO> contracts = contractService.findContractByCaseIdAndIsPush(caseId,true);
  133. // if(contracts.size()<contractSeq)
  134. // throw new DescribeException(ExceptionEnum.CONTRACT_NOT_EXIST);
  135. // ContractVO contractVO = contracts.get(contractSeq-1);
  136. //
  137. // return ResultUtil.success("success",getContractInformation(response,caseId,contractVO));
  138. // }
  139. //签署的电子信息先以附件上传
  140. //再修改合同状态
  141. @PostMapping("/{id}/sign")
  142. @ApiOperation("签署合同(客户)")
  143. @PreAuthorize("@pms.hasAnyRoles('EXTERNAL')")
  144. public Result updateContract(@PathVariable("id")Long contractId,@RequestParam Long signId,@RequestParam Long commitedId){
  145. Contract contract = contractService.findContractById(contractId);
  146. if(ObjectUtils.isEmpty(contract))
  147. throw new DescribeException(ExceptionEnum.CONTRACT_NOT_EXIST);
  148. if(!contract.getIsPush())
  149. throw new DescribeException(ExceptionEnum.CONTRACT_NOT_PUSH);
  150. if(contract.getSignedByCustomer())
  151. throw new DescribeException(ExceptionEnum.CONTRACT_HAS_SIGNED);
  152. if(!contract.getCustomerId().equals(BaseContext.getCurrentId()))
  153. throw new DescribeException(ExceptionEnum.CONTRACT_SIGNED_PERMISSION_NOT_ALLOW);
  154. contractService.updateContractById1(contractId,commitedId,signId);
  155. return ResultUtil.success("success");
  156. }
  157. @PutMapping("/case/{caseId}")
  158. @ApiOperation("合同签订完成")
  159. @PreAuthorize("@pms.hasAnyRoles('SYSTEM_ADMIN','APPROVER','LEAD_SALES', 'ASSIST_SALES', 'FINANCE', 'BACK_OFFICE')")
  160. public Result completeContract(@PathVariable("caseId")Long caseId){
  161. if(!loanService.existsByIdAndIsDelete(caseId))
  162. throw new DescribeException(ExceptionEnum.PROJECT_NOT_EXIST);
  163. StepVO step = stepService.findByStepNameAndCaseId(StepPropertyEnum.CONTRACT_SIGN.getLabel(),caseId);
  164. if(ObjectUtils.isEmpty( step)||!step.getStatus().equals(StepEnum.PROCESS.getMsg()))
  165. throw new DescribeException(STEP_HAS_NOT_PROCESS);
  166. Long currentId = step.getUserId1();
  167. if(currentId!=null && !BaseContext.getCurrentId().equals(currentId)){
  168. throw new DescribeException(STEP_USER_NOT_EXPECTED);
  169. }
  170. //合同签约完成
  171. stepService.updateStatusByCaseId(StepEnum.COMPLETED.getMsg(), StepPropertyEnum.CONTRACT_SIGN_PARENT.getLabel(),caseId);
  172. stepService.updateStatusByCaseId(StepEnum.COMPLETED.getMsg(),StepPropertyEnum.CONTRACT_SIGN.getLabel(),caseId);
  173. // //出款开始环节
  174. // stepService.updateStatusByCaseId(StepEnum.PROCESS.getMsg(),StepPropertyEnum.DISBURSE_PARENT.getLabel(),caseId);
  175. // stepService.updateStatusByCaseId(StepEnum.PROCESS.getMsg(),StepPropertyEnum.PLAN_REPORT.getLabel(),caseId);
  176. //
  177. // //取证开始环节
  178. // stepService.updateStatusByCaseId(StepEnum.PROCESS.getMsg(),StepPropertyEnum.COLLATERAL_RECEIVE.getLabel(),caseId);
  179. // stepService.updateStatusByCaseId(StepEnum.PROCESS.getMsg(),StepPropertyEnum.PLAN_SUBMISSION.getLabel(),caseId);
  180. //
  181. // //送证开始环节
  182. // stepService.updateStatusByCaseId(StepEnum.PROCESS.getMsg(),StepPropertyEnum.COLLATERAL_DELIVERY.getLabel(),caseId);
  183. // stepService.updateStatusByCaseId(StepEnum.PROCESS.getMsg(),StepPropertyEnum.PLAN_SUBMISSION_2.getLabel(),caseId);
  184. return ResultUtil.success("success");
  185. }
  186. private void getContractInformation(HttpServletResponse response, Long caseId,ContractVO contractVO){
  187. LoanCaseSimpleVO loancase = loanService.findLoanCaseSimpleByIdAndIsDelete(caseId, false);
  188. CustomerVO customer = customerService.findByCustomerIdAndIsDelete(loancase.getCustomerId(),false);
  189. ContractInformation contractInformation = BeanUtil.copyProperties(customer, ContractInformation.class);
  190. contractInformation.setContractNo(contractVO.getContractNo());
  191. contractInformation.setInterestRate(contractVO.getInterestRate());
  192. String downloadName = contractVO.getContractName()+"-"+contractVO.getId();
  193. new PoiWordUtil().writeApprove(response,contractPath,contractInformation,downloadName);
  194. }
  195. }