PolicyTodoServiceImpl.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. package com.qdport.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.baomidou.mybatisplus.core.metadata.IPage;
  4. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  5. import com.qdport.entity.PolicyStrive;
  6. import com.qdport.enums.QDPortEnum;
  7. import com.qdport.mapper.PolicyCaseMapper;
  8. import com.qdport.mapper.PolicyShareMapper;
  9. import com.qdport.mapper.PolicyStriveMapper;
  10. import com.qdport.modules.system.entity.SysUser;
  11. import com.qdport.modules.system.service.TSysUserService;
  12. import com.qdport.query.QueryWrapperBuilder;
  13. import com.qdport.service.PolicyShareService;
  14. import com.qdport.util.StringUtil;
  15. import com.qdport.vo.*;
  16. import com.qdport.workflow.core.utils.WfTaskUtil;
  17. import com.qdport.workflow.process.model.WfProcess;
  18. import com.qdport.workflow.process.service.IWfProcessService;
  19. import lombok.AllArgsConstructor;
  20. import com.qdport.entity.PolicyTodo;
  21. import com.qdport.query.PolicyTodoQuery;
  22. import com.qdport.mapper.PolicyTodoMapper;
  23. import com.qdport.service.PolicyTodoService;
  24. import com.qdport.wrapper.PolicyTodoWrapper;
  25. import com.qdport.core.tool.utils.BeanUtil;
  26. import org.flowable.engine.HistoryService;
  27. import org.flowable.task.api.history.HistoricTaskInstance;
  28. import org.flowable.task.api.history.HistoricTaskInstanceQuery;
  29. import org.springframework.stereotype.Service;
  30. import org.springframework.transaction.annotation.Transactional;
  31. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  32. import javax.annotation.Resource;
  33. import java.util.Date;
  34. import java.util.List;
  35. import java.util.concurrent.ExecutionException;
  36. import java.util.concurrent.Future;
  37. import java.util.stream.Collectors;
  38. /**
  39. * 政策待办
  40. *
  41. * @author yuheng
  42. * @since 1.0.0 2024-10-11
  43. */
  44. @Service
  45. public class PolicyTodoServiceImpl extends ServiceImpl<PolicyTodoMapper, PolicyTodo> implements PolicyTodoService {
  46. @Resource
  47. private IWfProcessService processService;
  48. @Resource
  49. private TSysUserService sysUserService;
  50. @Resource
  51. private PolicyShareMapper policyShareMapper;
  52. @Resource
  53. private PolicyStriveMapper policyStriveMapper;
  54. @Resource
  55. private PolicyCaseMapper policyCaseMapper;
  56. @Override
  57. public IPage<PolicyTodoVO> page(PolicyTodoQuery query) {
  58. IPage<PolicyTodo> page = new Page<>(query.getPage(), query.getSize());
  59. page = baseMapper.selectPage(page, getWrapper(query));
  60. return PolicyTodoWrapper.build().pageVO(page);
  61. }
  62. private QueryWrapper<PolicyTodo> getWrapper(PolicyTodoQuery query) {
  63. QueryWrapper<PolicyTodo> wrapper = QueryWrapperBuilder.buildQueryWrapper(query, PolicyTodo.class);
  64. wrapper.orderByDesc("CREATE_TIME");
  65. return wrapper;
  66. }
  67. @Override
  68. public void save(PolicyTodoVO vo) {
  69. PolicyTodo entity = BeanUtil.copy(vo, PolicyTodo.class);
  70. baseMapper.insert(entity);
  71. }
  72. @Override
  73. @Transactional(rollbackFor = Exception.class)
  74. public void save(PolicyShareVO vo) throws ExecutionException, InterruptedException {
  75. QueryWrapper<PolicyTodo> todoQueryWrapper = new QueryWrapper<>();
  76. todoQueryWrapper.eq("REF_ID", vo.getId());
  77. todoQueryWrapper.eq("REF_TYPE", QDPortEnum.POLICY_TODO_REFTYPE_POLICY_SHARE.getValue());
  78. todoQueryWrapper.eq("TODO_TYPE", QDPortEnum.POLICY_TODO_TYPE_APPROVE.getValue());
  79. todoQueryWrapper.eq("STATUS", QDPortEnum.POLICY_TODO_STATUS_ACTIVE.getValue());
  80. PolicyTodo todo = new PolicyTodo();
  81. todo.setStatus(QDPortEnum.POLICY_TODO_STATUS_DONE.getValue());
  82. update(todo, todoQueryWrapper);
  83. Future<List<WfProcess>> flowFuture = processService.historyFlowList(vo.getProcessInstanceId(), null, null);
  84. List<WfProcess> ll = flowFuture.get();
  85. List<WfProcess> filter = ll.stream().filter(wfProcess ->
  86. QDPortEnum.POLICY_PROCESS_TYPE_USER_TASK.getValue().equals(wfProcess.getHistoryActivityType())
  87. && StringUtil.isEmpty(wfProcess.getEndTime())
  88. ).collect(Collectors.toList());
  89. if (!filter.isEmpty()) {
  90. WfProcess process = filter.get(0);
  91. String[] assignNames = process.getAssigneeName().split("/");
  92. for (String username : assignNames) {
  93. QueryWrapper<SysUser> sysUserWrapper = new QueryWrapper<>();
  94. sysUserWrapper.eq("username", username);
  95. SysUser user = sysUserService.getOne(sysUserWrapper);
  96. todo = new PolicyTodo();
  97. todo.setRefId(vo.getId());
  98. todo.setRefType(QDPortEnum.POLICY_TODO_REFTYPE_POLICY_SHARE.getValue());
  99. todo.setCreateTime(new Date());
  100. todo.setStatus(QDPortEnum.POLICY_TODO_STATUS_ACTIVE.getValue());
  101. todo.setTodoType(QDPortEnum.POLICY_TODO_TYPE_APPROVE.getValue());
  102. todo.setTodoUserId(user.getId());
  103. todo.setZcAbstractContent(vo.getAbstractContent());
  104. todo.setZcContactPhone(vo.getContactPhone());
  105. todo.setZcCreateId(vo.getCreateId());
  106. todo.setZcCreateName(vo.getCreateName());
  107. todo.setZcCreateTime(vo.getCreateTime());
  108. todo.setZcName(vo.getName());
  109. todo.setZcType(vo.getZcType());
  110. baseMapper.insert(todo);
  111. }
  112. } else {
  113. vo.setStatus(QDPortEnum.POLICY_SHARE_STATUS_DONE.getValue());
  114. vo.setUpdateTime(new Date());
  115. policyShareMapper.updateById(vo);
  116. }
  117. }
  118. @Override
  119. @Transactional(rollbackFor = Exception.class)
  120. public void save(PolicyStriveVO vo) throws ExecutionException, InterruptedException {
  121. QueryWrapper<PolicyTodo> todoQueryWrapper = new QueryWrapper<>();
  122. todoQueryWrapper.eq("REF_ID", vo.getId());
  123. todoQueryWrapper.eq("REF_TYPE", QDPortEnum.POLICY_TODO_REFTYPE_POLICY_STRIVE.getValue());
  124. todoQueryWrapper.eq("TODO_TYPE", QDPortEnum.POLICY_TODO_TYPE_APPROVE.getValue());
  125. todoQueryWrapper.eq("STATUS", QDPortEnum.POLICY_TODO_STATUS_ACTIVE.getValue());
  126. PolicyTodo todo = new PolicyTodo();
  127. todo.setStatus(QDPortEnum.POLICY_TODO_STATUS_DONE.getValue());
  128. update(todo, todoQueryWrapper);
  129. Future<List<WfProcess>> flowFuture = processService.historyFlowList(vo.getProcessInstanceId(), null, null);
  130. List<WfProcess> ll = flowFuture.get();
  131. List<WfProcess> filter = ll.stream().filter(wfProcess ->
  132. QDPortEnum.POLICY_PROCESS_TYPE_USER_TASK.getValue().equals(wfProcess.getHistoryActivityType())
  133. && StringUtil.isEmpty(wfProcess.getEndTime())
  134. ).collect(Collectors.toList());
  135. if (!filter.isEmpty()) {
  136. WfProcess process = filter.get(0);
  137. String[] assignNames = process.getAssigneeName().split("/");
  138. for (String username : assignNames) {
  139. QueryWrapper<SysUser> sysUserWrapper = new QueryWrapper<>();
  140. sysUserWrapper.eq("username", username);
  141. SysUser user = sysUserService.getOne(sysUserWrapper);
  142. todo = new PolicyTodo();
  143. todo.setRefId(vo.getId());
  144. todo.setRefType(QDPortEnum.POLICY_TODO_REFTYPE_POLICY_STRIVE.getValue());
  145. todo.setCreateTime(new Date());
  146. todo.setStatus(QDPortEnum.POLICY_TODO_STATUS_ACTIVE.getValue());
  147. todo.setTodoType(QDPortEnum.POLICY_TODO_TYPE_APPROVE.getValue());
  148. todo.setTodoUserId(user.getId());
  149. todo.setZcAbstractContent(vo.getAbstractContent());
  150. todo.setZcContactPhone(vo.getContactPhone());
  151. todo.setZcCreateId(vo.getCreateId());
  152. todo.setZcCreateName(vo.getCreateName());
  153. todo.setZcCreateTime(vo.getCreateTime());
  154. todo.setZcName(vo.getName());
  155. todo.setZcType(vo.getZcType());
  156. baseMapper.insert(todo);
  157. }
  158. } else {
  159. vo.setStatus(QDPortEnum.POLICY_SHARE_STATUS_DONE.getValue());
  160. vo.setUpdateTime(new Date());
  161. policyStriveMapper.updateById(vo);
  162. }
  163. }
  164. @Override
  165. public void save(PolicyCaseVO vo) throws ExecutionException, InterruptedException {
  166. QueryWrapper<PolicyTodo> todoQueryWrapper = new QueryWrapper<>();
  167. todoQueryWrapper.eq("REF_ID", vo.getId());
  168. todoQueryWrapper.eq("REF_TYPE", QDPortEnum.POLICY_TODO_REFTYPE_POLICY_CASE.getValue());
  169. todoQueryWrapper.eq("TODO_TYPE", QDPortEnum.POLICY_TODO_TYPE_APPROVE.getValue());
  170. todoQueryWrapper.eq("STATUS", QDPortEnum.POLICY_TODO_STATUS_ACTIVE.getValue());
  171. PolicyTodo todo = new PolicyTodo();
  172. todo.setStatus(QDPortEnum.POLICY_TODO_STATUS_DONE.getValue());
  173. update(todo, todoQueryWrapper);
  174. Future<List<WfProcess>> flowFuture = processService.historyFlowList(vo.getProcessInstanceId(), null, null);
  175. List<WfProcess> ll = flowFuture.get();
  176. List<WfProcess> filter = ll.stream().filter(wfProcess ->
  177. QDPortEnum.POLICY_PROCESS_TYPE_USER_TASK.getValue().equals(wfProcess.getHistoryActivityType())
  178. && StringUtil.isEmpty(wfProcess.getEndTime())
  179. ).collect(Collectors.toList());
  180. PolicyStrive policyStrive = vo.getPolicyStrive();
  181. if (!filter.isEmpty()) {
  182. WfProcess process = filter.get(0);
  183. String[] assignNames = process.getAssigneeName().split("/");
  184. for (String username : assignNames) {
  185. QueryWrapper<SysUser> sysUserWrapper = new QueryWrapper<>();
  186. sysUserWrapper.eq("username", username);
  187. SysUser user = sysUserService.getOne(sysUserWrapper);
  188. todo = new PolicyTodo();
  189. todo.setRefId(vo.getId());
  190. todo.setRefType(QDPortEnum.POLICY_TODO_REFTYPE_POLICY_CASE.getValue());
  191. todo.setCreateTime(new Date());
  192. todo.setStatus(QDPortEnum.POLICY_TODO_STATUS_ACTIVE.getValue());
  193. todo.setTodoType(QDPortEnum.POLICY_TODO_TYPE_APPROVE.getValue());
  194. todo.setTodoUserId(user.getId());
  195. todo.setZcAbstractContent(policyStrive.getAbstractContent());
  196. todo.setZcContactPhone(policyStrive.getContactPhone());
  197. todo.setZcCreateId(policyStrive.getCreateId());
  198. todo.setZcCreateName(policyStrive.getCreateName());
  199. todo.setZcCreateTime(vo.getCreateTime());
  200. todo.setZcName(policyStrive.getName());
  201. todo.setZcType(policyStrive.getZcType());
  202. baseMapper.insert(todo);
  203. }
  204. } else {
  205. vo.setStatus(QDPortEnum.POLICY_SHARE_STATUS_DONE.getValue());
  206. vo.setUpdateTime(new Date());
  207. policyCaseMapper.updateById(vo);
  208. }
  209. }
  210. @Override
  211. public void update(PolicyTodoVO vo) {
  212. PolicyTodo entity = BeanUtil.copy(vo, PolicyTodo.class);
  213. updateById(entity);
  214. }
  215. @Override
  216. @Transactional(rollbackFor = Exception.class)
  217. public void delete(List<String> idList) {
  218. removeByIds(idList);
  219. }
  220. }