TFFlowController.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. package com.qmth.distributed.print.api;
  2. import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
  3. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  4. import com.google.common.reflect.TypeToken;
  5. import com.google.gson.Gson;
  6. import com.qmth.boot.api.constant.ApiConstant;
  7. import com.qmth.boot.api.exception.ApiException;
  8. import com.qmth.distributed.print.business.bean.params.FlowApproveParam;
  9. import com.qmth.distributed.print.business.bean.params.FlowParam;
  10. import com.qmth.distributed.print.business.bean.params.FlowTaskApproveParam;
  11. import com.qmth.distributed.print.business.bean.result.EditResult;
  12. import com.qmth.distributed.print.business.bean.result.FlowApproveResult;
  13. import com.qmth.distributed.print.business.bean.result.FlowTaskApprovePeopleAllResult;
  14. import com.qmth.distributed.print.business.bean.result.FlowTaskResult;
  15. import com.qmth.distributed.print.business.entity.ExamTask;
  16. import com.qmth.distributed.print.business.entity.TFFlow;
  17. import com.qmth.distributed.print.business.entity.TFFlowApprove;
  18. import com.qmth.distributed.print.business.entity.TFFlowApproveLog;
  19. import com.qmth.distributed.print.business.enums.MessageEnum;
  20. import com.qmth.distributed.print.business.service.*;
  21. import com.qmth.teachcloud.common.bean.params.ApproveUserResult;
  22. import com.qmth.teachcloud.common.contant.SystemConstant;
  23. import com.qmth.teachcloud.common.entity.BasicAttachment;
  24. import com.qmth.teachcloud.common.entity.SysUser;
  25. import com.qmth.teachcloud.common.enums.*;
  26. import com.qmth.teachcloud.common.service.BasicAttachmentService;
  27. import com.qmth.teachcloud.common.service.SysUserService;
  28. import com.qmth.teachcloud.common.util.JacksonUtil;
  29. import com.qmth.teachcloud.common.util.Result;
  30. import com.qmth.teachcloud.common.util.ResultUtil;
  31. import com.qmth.teachcloud.common.util.ServletUtil;
  32. import io.swagger.annotations.*;
  33. import org.slf4j.Logger;
  34. import org.slf4j.LoggerFactory;
  35. import org.springframework.beans.factory.annotation.Autowired;
  36. import org.springframework.dao.DuplicateKeyException;
  37. import org.springframework.transaction.annotation.Transactional;
  38. import org.springframework.validation.BindingResult;
  39. import org.springframework.validation.annotation.Validated;
  40. import org.springframework.web.bind.annotation.*;
  41. import org.springframework.web.multipart.MultipartFile;
  42. import javax.annotation.Resource;
  43. import javax.validation.Valid;
  44. import javax.validation.constraints.Max;
  45. import javax.validation.constraints.Min;
  46. import java.io.IOException;
  47. import java.util.*;
  48. /**
  49. * <p>
  50. * 流程表 前端控制器
  51. * </p>
  52. *
  53. * @author wangliang
  54. * @since 2021-08-02
  55. */
  56. @Api(tags = "流程Controller")
  57. @RestController
  58. @RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + "/${prefix.url.flow}")
  59. //@Aac(auth = BOOL.FALSE, strict = BOOL.FALSE)
  60. @Validated
  61. public class TFFlowController {
  62. private final static Logger log = LoggerFactory.getLogger(TFFlowController.class);
  63. @Resource
  64. PrintCommonService printCommonService;
  65. @Resource
  66. BasicAttachmentService basicAttachmentService;
  67. @Resource
  68. ActivitiService activitiService;
  69. @Resource
  70. TFFlowService tfFlowService;
  71. @Resource
  72. TFFlowApproveLogService tfFlowApproveLogService;
  73. @Autowired
  74. SysUserService sysUserService;
  75. @Autowired
  76. BasicMessageService basicMessageService;
  77. @ApiOperation(value = "注册流程")
  78. @Transactional
  79. @ApiResponses({@ApiResponse(code = 200, message = "常规信息", response = ResultUtil.class)})
  80. @RequestMapping(value = "/register", method = RequestMethod.POST)
  81. public Result register(@ApiParam(value = "上传文件", required = true) @RequestParam MultipartFile file,
  82. @ApiParam(value = "流程文件名称", required = true) @RequestParam String name) {
  83. BasicAttachment basicAttachment = null;
  84. try {
  85. int temp = file.getOriginalFilename().lastIndexOf(".");
  86. String fileName = file.getOriginalFilename().substring(0, temp);
  87. String format = file.getOriginalFilename().substring(temp, file.getOriginalFilename().length());
  88. if (!format.equalsIgnoreCase(".bpmn")) {
  89. throw ExceptionResultEnum.ERROR.exception("上传的流程文件格式只能为.bmpn");
  90. }
  91. basicAttachment = printCommonService.saveAttachment(file, ServletUtil.getRequestMd5(), UploadFileEnum.FILE);
  92. if (Objects.isNull(basicAttachment)) {
  93. throw ExceptionResultEnum.ATTACHMENT_ERROR.exception();
  94. }
  95. activitiService.uploadDeployment(file);
  96. String actFlowId = tfFlowService.findActIdByFlowKey(SystemConstant.GDYKDX_FLOW_KEY);
  97. SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
  98. TFFlow tfFlow = new TFFlow(SystemConstant.getHeadOrUserSchoolId(), sysUser.getOrgId(), name, sysUser.getId(), fileName, actFlowId);
  99. tfFlowService.save(tfFlow);
  100. } catch (Exception e) {
  101. log.error("请求出错", e);
  102. if (Objects.nonNull(basicAttachment)) {
  103. basicAttachmentService.deleteAttachment(basicAttachment);
  104. }
  105. if (e instanceof DuplicateKeyException) {
  106. String errorColumn = e.getCause().toString();
  107. String columnStr = errorColumn.substring(errorColumn.lastIndexOf("key") + 3, errorColumn.length()).replaceAll("'", "");
  108. throw ExceptionResultEnum.SQL_ERROR.exception("[" + FieldUniqueEnum.convertToTitle(columnStr) + "]数据不允许重复插入");
  109. } else if (e instanceof ApiException) {
  110. ResultUtil.error((ApiException) e, e.getMessage());
  111. } else {
  112. ResultUtil.error(e.getMessage());
  113. }
  114. }
  115. return ResultUtil.ok(new EditResult(basicAttachment.getId()));
  116. }
  117. // @ApiOperation(value = "发布流程")
  118. // @ApiResponses({@ApiResponse(code = 200, message = "常规信息", response = ResultUtil.class)})
  119. // @RequestMapping(value = "/publish", method = RequestMethod.POST)
  120. // public Result publish(@ApiParam(value = "流程文件id", required = true) @RequestParam String id) {
  121. // SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
  122. // UpdateWrapper tfFlowUpdateWrapper = new UpdateWrapper<>();
  123. // tfFlowUpdateWrapper.lambda().eq(TFFlow::getId, Long.parseLong(id))
  124. // .set(TFFlow::getPublish, true)
  125. // .set(TFFlow::getUpdateId, sysUser.getId())
  126. // .set(TFFlow::getUpdateTime, System.currentTimeMillis());
  127. // return ResultUtil.ok(tfFlowService.update(tfFlowUpdateWrapper));
  128. // }
  129. @ApiOperation(value = "流程逻辑删除")
  130. @ApiResponses({@ApiResponse(code = 200, message = "常规信息", response = ResultUtil.class)})
  131. @RequestMapping(value = "/enable", method = RequestMethod.POST)
  132. public Result enable(@Valid @RequestBody FlowParam flowParam, BindingResult bindingResult) {
  133. if (bindingResult.hasErrors()) {
  134. return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
  135. }
  136. return ResultUtil.ok(activitiService.flowDelete(flowParam.getId()));
  137. }
  138. @ApiOperation(value = "流程列表")
  139. @ApiResponses({@ApiResponse(code = 200, message = "流程信息", response = TFFlow.class)})
  140. @RequestMapping(value = "/list", method = RequestMethod.POST)
  141. public Result list(@ApiParam(value = "流程名称", required = false) @RequestParam(required = false) String name,
  142. @ApiParam(value = "页码", required = true) @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
  143. @ApiParam(value = "数量", required = true) @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {
  144. SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
  145. return ResultUtil.ok(tfFlowService.list(new Page<>(pageNumber, pageSize), name, SystemConstant.getHeadOrUserSchoolId(), sysUser.getOrgId()));
  146. }
  147. @ApiOperation(value = "审批流程")
  148. @ApiResponses({@ApiResponse(code = 200, message = "常规信息", response = ResultUtil.class)})
  149. @RequestMapping(value = "/task/approve", method = RequestMethod.POST)
  150. public Result taskApprove(@Valid @RequestBody FlowTaskApproveParam flowTaskApproveParam, BindingResult bindingResult) {
  151. if (bindingResult.hasErrors()) {
  152. return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
  153. }
  154. Map<String, Object> map = new HashMap<>();
  155. map.computeIfAbsent(SystemConstant.FLOW_TASK_ID, v -> flowTaskApproveParam.getTaskId());
  156. map.computeIfAbsent(SystemConstant.APPROVE_OPERATION, v -> flowTaskApproveParam.getApprovePass());
  157. map.computeIfAbsent(SystemConstant.APPROVE_REMARK, v -> flowTaskApproveParam.getRemark());
  158. map.computeIfAbsent(SystemConstant.APPROVE_SETUP, v -> flowTaskApproveParam.getSetup());
  159. map.computeIfAbsent(SystemConstant.APPROVE_USER_IDS, v -> flowTaskApproveParam.getApproveUserIds());
  160. Map<String, Object> objectMap = activitiService.taskApprove(map);
  161. if (Objects.nonNull(objectMap)) {
  162. TFFlowApprove tfFlowApprove = (TFFlowApprove) objectMap.get("tfFlowApprove");
  163. ExamTask examTask = (ExamTask) objectMap.get("examTask");
  164. //审核通过,生成pdf
  165. if (Objects.nonNull(tfFlowApprove) && FlowApproveSetupEnum.FINISH.getSetup() == tfFlowApprove.getSetup()) {
  166. // 取命题老师ID
  167. SysUser sysUser = sysUserService.getById(examTask.getUserId());
  168. try {
  169. printCommonService.checkData(examTask.getSchoolId(), examTask.getCourseCode(), examTask.getPaperNumber(), sysUser);
  170. } catch (IOException e) {
  171. throw ExceptionResultEnum.ERROR.exception("生成pdf失败");
  172. }
  173. }
  174. // 驳回短信(驳回给提交老师)
  175. if (tfFlowApprove.getStatus() == FlowStatusEnum.REJECT
  176. && (tfFlowApprove.getSetup().intValue() == FlowApproveSetupEnum.SUBMIT.getSetup())
  177. || tfFlowApprove.getSetup().intValue() == FlowApproveSetupEnum.THREE_APPROVE.getSetup()) {
  178. List<SysUser> sysUsers = sysUserService.listByIds(Arrays.asList(examTask.getUserId()));
  179. List<ApproveUserResult> sysUserList = new Gson().fromJson(JacksonUtil.parseJson(sysUsers), new TypeToken<List<ApproveUserResult>>() {
  180. }.getType());
  181. basicMessageService.sendNoticeTaskAuditFlow(examTask, sysUserList, MessageEnum.NOTICE_OF_AUDIT_REJECT);
  182. }
  183. }
  184. return ResultUtil.ok();
  185. }
  186. @ApiOperation(value = "流程审批记录列表")
  187. @ApiResponses({@ApiResponse(code = 200, message = "流程审批记录信息", response = FlowApproveResult.class)})
  188. @RequestMapping(value = "/approve/list", method = RequestMethod.POST)
  189. public Result taskApproveList(@ApiParam(value = "发起人名称", required = false) @RequestParam(required = false) String startName,
  190. @ApiParam(value = "页码", required = true) @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
  191. @ApiParam(value = "数量", required = true) @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {
  192. SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
  193. return ResultUtil.ok(tfFlowService.flowApproveList(new Page<>(pageNumber, pageSize), startName, SystemConstant.getHeadOrUserSchoolId(), sysUser.getOrgId(), null));
  194. }
  195. @ApiOperation(value = "流程审批记录逻辑删除")
  196. @ApiResponses({@ApiResponse(code = 200, message = "常规信息", response = ResultUtil.class)})
  197. @RequestMapping(value = "/approve/enable", method = RequestMethod.POST)
  198. public Result enable(@Valid @RequestBody FlowApproveParam flowApproveParam, BindingResult bindingResult) {
  199. if (bindingResult.hasErrors()) {
  200. return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
  201. }
  202. UpdateWrapper<TFFlowApproveLog> tfFlowApproveLogUpdateWrapper = new UpdateWrapper<>();
  203. tfFlowApproveLogUpdateWrapper.lambda().eq(TFFlowApproveLog::getFlowId, flowApproveParam.getFlowId())
  204. .set(TFFlowApproveLog::getEnable, flowApproveParam.getEnable());
  205. return ResultUtil.ok(tfFlowApproveLogService.update(tfFlowApproveLogUpdateWrapper));
  206. }
  207. @ApiOperation(value = "流程终止")
  208. @ApiResponses({@ApiResponse(code = 200, message = "常规信息", response = ResultUtil.class)})
  209. @RequestMapping(value = "/end", method = RequestMethod.POST)
  210. public Result end(@ApiParam(value = "流程id", required = true) @RequestParam String flowId) {
  211. activitiService.flowEnd(flowId);
  212. return ResultUtil.ok();
  213. }
  214. @ApiOperation(value = "获取所有流程节点")
  215. @ApiResponses({@ApiResponse(code = 200, message = "流程节点", response = FlowTaskResult.class)})
  216. @RequestMapping(value = "/task/all", method = RequestMethod.POST)
  217. public Result taskAll(@ApiParam(value = "流程id", required = true) @RequestParam String flowId) {
  218. return ResultUtil.ok(activitiService.getTaskAll(flowId));
  219. }
  220. @ApiOperation(value = "获取所有流程节点待审批人")
  221. @ApiResponses({@ApiResponse(code = 200, message = "流程节点待审批人", response = FlowTaskApprovePeopleAllResult.class)})
  222. @RequestMapping(value = "/task/approver/people_all", method = RequestMethod.POST)
  223. public Result taskApproverPeopleAll(@ApiParam(value = "课程编码", required = false) @RequestParam(required = false) String courseCode,
  224. @ApiParam(value = "流程节点id", required = false) @RequestParam(required = false) String taskId) {
  225. return ResultUtil.ok(activitiService.taskApproverPeopleAll(courseCode, taskId));
  226. }
  227. @ApiOperation(value = "流程节点转他人审批")
  228. @ApiResponses({@ApiResponse(code = 200, message = "常规信息", response = ResultUtil.class)})
  229. @RequestMapping(value = "/task/approver/exchange", method = RequestMethod.POST)
  230. public Result taskApproverExchange(@ApiParam(value = "审批人id", required = true) @RequestParam String userId,
  231. @ApiParam(value = "流程节点id", required = true) @RequestParam String taskId) {
  232. return ResultUtil.ok(activitiService.taskApproverExchange(userId, taskId));
  233. }
  234. @ApiOperation(value = "获取转他人审批人")
  235. @ApiResponses({@ApiResponse(code = 200, message = "流程节点审批人", response = FlowTaskApprovePeopleAllResult.class)})
  236. @RequestMapping(value = "/task/approver/exchange/people", method = RequestMethod.POST)
  237. public Result taskApproverExchangePeople(@ApiParam(value = "流程节点id", required = true) @RequestParam String taskId,
  238. @ApiParam(value = "用户姓名", required = false) @RequestParam(required = false) String realName) {
  239. return ResultUtil.ok(activitiService.taskApproverExchangePeople(taskId, realName));
  240. }
  241. @ApiOperation(value = "获取下级节点审批人")
  242. @ApiResponses({@ApiResponse(code = 200, message = "流程节点审批人", response = FlowTaskApprovePeopleAllResult.class)})
  243. @RequestMapping(value = "/task/approver/next/people", method = RequestMethod.POST)
  244. public Result taskApproverNextPeople(@ApiParam(value = "课程编码", required = false) @RequestParam(required = false) String courseCode,
  245. @ApiParam(value = "流程节点id", required = false) @RequestParam(required = false) String taskId) {
  246. return ResultUtil.ok(activitiService.taskApproverNextPeople(courseCode, taskId));
  247. }
  248. }