PlanManageController.java 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. package com.huaxu.task.controller;
  2. import com.baomidou.mybatisplus.core.metadata.IPage;
  3. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  4. import com.huaxu.client.UserCenterClient;
  5. import com.huaxu.model.AjaxMessage;
  6. import com.huaxu.model.LoginUser;
  7. import com.huaxu.model.Pagination;
  8. import com.huaxu.model.ResultStatus;
  9. import com.huaxu.order.entity.WorkFlowDetail;
  10. import com.huaxu.order.entity.WorkFlowLog;
  11. import com.huaxu.order.service.WorkFlowLogService;
  12. import com.huaxu.process.entity.ProcessDefinition;
  13. import com.huaxu.process.service.WorkFlowService;
  14. import com.huaxu.task.dto.PlanManageDto;
  15. import com.huaxu.task.entity.PlanManage;
  16. import com.huaxu.task.entity.TaskManage;
  17. import com.huaxu.task.entity.UserEntity;
  18. import com.huaxu.task.service.PlanManageService;
  19. import com.huaxu.util.DatesUtil;
  20. import com.huaxu.util.UserUtil;
  21. import io.swagger.annotations.Api;
  22. import io.swagger.annotations.ApiOperation;
  23. import io.swagger.annotations.ApiParam;
  24. import org.activiti.engine.task.Task;
  25. import org.springframework.beans.factory.annotation.Autowired;
  26. import org.springframework.util.StringUtils;
  27. import org.springframework.web.bind.annotation.*;
  28. import java.util.*;
  29. import java.util.stream.Collectors;
  30. @RestController
  31. @RequestMapping("/workflow/task/")
  32. @Api(tags = "任务管理")
  33. public class PlanManageController {
  34. @Autowired
  35. PlanManageService planManageService;
  36. @Autowired
  37. WorkFlowService workFlowService;
  38. @Autowired
  39. WorkFlowLogService workFlowLogService;
  40. @Autowired
  41. private UserCenterClient userCenterClient;
  42. /**
  43. * 新增巡检计划
  44. * @param planName 任务名称
  45. * @param taskType 任务类型
  46. * @param planStartDate 计划开始时间
  47. * @param planEndDate 计划结束时间
  48. * @param userId 计划巡检人ID
  49. * @param taskContent 任务内容
  50. * @param taskAreaShape 任务区域坐标
  51. * @param taskAreaName 任务区域名称
  52. * @return
  53. */
  54. @GetMapping("/plan/add")
  55. @ApiOperation(value = "新增巡检计划")
  56. public AjaxMessage addPlan(@ApiParam(value = "任务名称", required = true) @RequestParam(required = true) String planName,
  57. @ApiParam(value = "任务类型", required = true) @RequestParam(required = true) Integer taskType,
  58. @ApiParam(value = "计划开始时间", required = true) @RequestParam(required = true) String planStartDate,
  59. @ApiParam(value = "计划结束时间", required = true) @RequestParam(required = true) String planEndDate,
  60. @ApiParam(value = "计划巡检人ID", required = true) @RequestParam(required = true) String userId,
  61. @ApiParam(value = "任务内容", required = true) @RequestParam(required = true) String taskContent,
  62. @ApiParam(value = "任务区域坐标", required = true) @RequestParam(required = true) String taskAreaShape,
  63. @ApiParam(value = "任务区域名称", required = true) @RequestParam(required = true) String taskAreaName,
  64. @ApiParam(value = "任务签到点", required = false) @RequestParam(required = false) String taskChecked) {
  65. LoginUser loginUser = UserUtil.getCurrentUser();
  66. String planId=DatesUtil.formatDate(new Date(),"yyyyMMddHHmmss")+String.valueOf((int) (Math.random()*(9999-1000)+1000));
  67. PlanManage record = new PlanManage();
  68. record.setUserId(userId);
  69. record.setPlanId(planId);
  70. record.setPlanName(planName);
  71. record.setTaskType(taskType);
  72. record.setTaskChecked(taskChecked);
  73. //record.setPlanDate(new Date());
  74. record.setPlanStartDate(DatesUtil.parseDate(planStartDate,"yyyy-MM-dd"));
  75. record.setPlanEndDate(DatesUtil.parseDate(planEndDate,"yyyy-MM-dd"));
  76. record.setPlanStatus(0);
  77. record.setTaskContent(taskContent);
  78. record.setTaskAreaShape(taskAreaShape);
  79. record.setTaskAreaName(taskAreaName);
  80. record.setDateCreate(new Date());
  81. if(loginUser.getId() != null) {
  82. record.setPlanUserId(String.valueOf(loginUser.getId()));
  83. record.setCreateBy(String.valueOf(loginUser.getId()));
  84. }
  85. if(loginUser.getTenantId() != null) {
  86. record.setTenantId(loginUser.getTenantId());
  87. }
  88. int rows = planManageService.insertSelective(record);
  89. if(rows > 0) {
  90. return new AjaxMessage(ResultStatus.OK);
  91. }
  92. return new AjaxMessage(ResultStatus.ERROR);
  93. }
  94. @GetMapping("/plan/select")
  95. @ApiOperation(value = "查询巡检计划")
  96. public AjaxMessage<Pagination<PlanManageDto>> selectPlan(
  97. @ApiParam(value = "页数", required = true)@RequestParam Integer pageNum,
  98. @ApiParam(value = "条数", required = true)@RequestParam Integer pageSize,
  99. @ApiParam(value = "任务类型(巡检:7,侧漏:8,养护:9)", required = false) @RequestParam(required = false) Integer taskType,
  100. @ApiParam(value = "状态(0:巡检计划;null:所有任务;1:执行中;2:完成)", required = false) @RequestParam(required = false) Integer planStatus,
  101. @ApiParam(value = "计划单号或计划名称", required = false) @RequestParam(required = false) String key,
  102. @ApiParam(value = "计划起始日期(yyyy-MM-dd)", required = false) @RequestParam(required = false) String startDate,
  103. @ApiParam(value = "计划截至日期(yyyy-MM-dd)", required = false) @RequestParam(required = false) String endDate){
  104. PlanManageDto planManageDto = new PlanManageDto();
  105. //根据用户编号,获取用户的权限
  106. LoginUser loginUser = UserUtil.getCurrentUser();
  107. planManageDto.setKey(key);
  108. if(!StringUtils.isEmpty(startDate)&& !StringUtils.isEmpty(endDate)) {
  109. planManageDto.setStartDate(startDate);
  110. planManageDto.setEndDate(endDate);
  111. }
  112. planManageDto.setPlanStatus(planStatus);
  113. planManageDto.setTaskType(taskType);
  114. planManageDto.setTenantId(loginUser.getTenantId());
  115. planManageDto.setProgramItems(loginUser.getProgramItemList());
  116. planManageDto.setUserType(loginUser.getType());
  117. //1是公司,2是公司及以下,3部门,4部门及以下,5自定义
  118. planManageDto.setPermissonType(loginUser.getPermissonType());
  119. IPage<PlanManageDto> iPage = new Page<>(pageNum, pageSize);
  120. iPage = planManageService.selectPage(iPage, planManageDto);
  121. Pagination<PlanManageDto> pages = new Pagination<>(iPage);
  122. setName(pages.getList());
  123. return new AjaxMessage<>(ResultStatus.OK, pages);
  124. }
  125. @GetMapping("/plan/pending")
  126. @ApiOperation(value = "查询待处理任务")
  127. public AjaxMessage<Pagination<PlanManageDto>> selectPendingTask(
  128. @ApiParam(value = "页数", required = true)@RequestParam Integer pageNum,
  129. @ApiParam(value = "条数", required = true)@RequestParam Integer pageSize,
  130. @ApiParam(value = "任务类型(巡检:7,侧漏:8,养护:9)", required = false) @RequestParam(required = false) Integer taskType,
  131. @ApiParam(value = "计划单号或计划名称", required = false) @RequestParam(required = false) String key,
  132. @ApiParam(value = "计划起始日期(yyyy-MM-dd)", required = false) @RequestParam(required = false) String startDate,
  133. @ApiParam(value = "计划截至日期(yyyy-MM-dd)", required = false) @RequestParam(required = false) String endDate){
  134. PlanManageDto planManageDto = new PlanManageDto();
  135. //根据用户编号,获取用户的权限
  136. LoginUser loginUser = UserUtil.getCurrentUser();
  137. planManageDto.setKey(key);
  138. if(!StringUtils.isEmpty(startDate)&& !StringUtils.isEmpty(endDate)) {
  139. planManageDto.setStartDate(startDate);
  140. planManageDto.setEndDate(endDate);
  141. }
  142. planManageDto.setTaskType(taskType);
  143. if(loginUser.getId() != null) {
  144. planManageDto.setCurrentUsers(String.format("%s,", loginUser.getId()));
  145. }
  146. IPage<PlanManageDto> iPage = new Page<>(pageNum, pageSize);
  147. iPage = planManageService.selectPage(iPage, planManageDto);
  148. Pagination<PlanManageDto> pages = new Pagination<>(iPage);
  149. setName(pages.getList());
  150. return new AjaxMessage<>(ResultStatus.OK, pages);
  151. }
  152. @GetMapping("/plan/pending/power")
  153. @ApiOperation(value = "待处理权限")
  154. public AjaxMessage<Boolean> selectPendingPower(
  155. @ApiParam(value = "任务ID", required = true) @RequestParam(required = true) Integer id){
  156. String currentUsers = null;
  157. LoginUser loginUser = UserUtil.getCurrentUser();
  158. if(loginUser.getId() != null) {
  159. currentUsers = String.format("%s,", loginUser.getId());
  160. }
  161. Map<String,Object> map = new HashMap<String,Object>();
  162. map.put("id",id);
  163. map.put("currentUsers",currentUsers);
  164. int rows = planManageService.selectPendingPower(map);
  165. if(rows>0){
  166. return new AjaxMessage<Boolean>(ResultStatus.OK, true);
  167. }
  168. return new AjaxMessage<Boolean>(ResultStatus.OK, false);
  169. }
  170. /**
  171. * APP查询任务详情
  172. * @return Response对象
  173. */
  174. @RequestMapping(value = "selectPlanDetail", method = RequestMethod.GET)
  175. @ApiOperation(value = "APP查询任务详情")
  176. public AjaxMessage<PlanManageDto> selectPlanDetail(
  177. @ApiParam(value = "任务id", required = true) @RequestParam Integer flowId) {
  178. PlanManageDto result=planManageService.selectPlanDetail(flowId);
  179. setName(new ArrayList<PlanManageDto>(){{
  180. this.add(result);
  181. }});
  182. return new AjaxMessage<>(ResultStatus.OK, result );
  183. }
  184. @GetMapping("/plan/submit")
  185. @ApiOperation(value = "提交巡检计划")
  186. public AjaxMessage submitPlan(
  187. @ApiParam(value = "任务ID", required = true) @RequestParam(required = false) Integer id,
  188. @ApiParam(value = "任务类型", required = true) @RequestParam(required = true) String taskType){
  189. LoginUser loginUser = UserUtil.getCurrentUser();
  190. PlanManage planManage = planManageService.selectByPrimaryKey(id);
  191. // ProcessDefinition processDefinition = workFlowService.findProcessDefinition(
  192. // loginUser.getTenantId(),
  193. // loginUser.getCompanyId(),
  194. // planManage.getTaskType());
  195. //流程查询, 测试参数:(test1 1 1)
  196. ProcessDefinition processDefinition = workFlowService.findProcessDefinition(
  197. "test1",
  198. 1,
  199. 1);
  200. if(processDefinition == null){
  201. new AjaxMessage(ResultStatus.ERROR,"没有创建流程,不能提交!");
  202. }
  203. Map<String,Object> vars = new HashMap<>();
  204. vars.put("assineeFormUserId",planManage.getUserId());
  205. //巡检发送系统消息所需参数
  206. vars.put("任务类型",taskType);
  207. vars.put("任务编号",planManage.getId());
  208. vars.put("templateId",4);
  209. vars.put("msgType",4);
  210. String startProcess = workFlowService.startProcess(processDefinition,vars);
  211. Task task = workFlowService.getProcessRuntimeTask(startProcess).get(0);
  212. Set<String> taskParticipator = workFlowService.getTaskParticipator(task.getId(),false,null);
  213. String currentUsers = "";
  214. for (String str : taskParticipator) {
  215. currentUsers += String.format("%s,",str);
  216. }
  217. currentUsers+="235,";
  218. //更新计划表的流程相关字段值。
  219. planManage.setPlanStatus(1);//已执行
  220. if(loginUser.getId() != null) {
  221. planManage.setUpdateBy(String.valueOf(loginUser.getId()));
  222. }
  223. planManage.setPlanDate(new Date());// 提交时间
  224. planManage.setDateUpdate(new Date());// 更新时间
  225. planManage.setProcessInstanceId(task.getProcessInstanceId());
  226. planManage.setProcessDefId(task.getProcessDefinitionId());
  227. planManage.setCurrentTaskId(task.getId());
  228. planManage.setCurrentUsers(currentUsers);
  229. planManage.setCurrentTaskName(task.getName());
  230. int rows = planManageService.updateByPrimaryKeySelective(planManage);
  231. if(rows > 0) {
  232. return new AjaxMessage<>(ResultStatus.OK);
  233. }
  234. return new AjaxMessage<>(ResultStatus.ERROR);
  235. }
  236. @PostMapping("/plan/update")
  237. @ApiOperation(value = "修改巡检计划")
  238. public AjaxMessage updatePlan(@ApiParam(value = "修改巡检计划", required = true) @RequestBody PlanManage planManage) {
  239. PlanManage record = new PlanManage();
  240. record.setId(planManage.getId());
  241. record.setUserId(planManage.getUserId());
  242. record.setPlanName(planManage.getPlanName());
  243. record.setTaskType(planManage.getTaskType());
  244. record.setTaskChecked(planManage.getTaskChecked());
  245. record.setPlanStartDate(planManage.getPlanStartDate());
  246. record.setPlanEndDate(planManage.getPlanEndDate());
  247. record.setTaskContent(planManage.getTaskContent());
  248. record.setTaskAreaShape(planManage.getTaskAreaShape());
  249. record.setTaskAreaName(planManage.getTaskAreaName());
  250. LoginUser loginUser = UserUtil.getCurrentUser();
  251. if(loginUser.getId() != null) {
  252. record.setUpdateBy(String.valueOf(loginUser.getId()));
  253. }
  254. record.setDateUpdate(new Date());
  255. int rows = planManageService.updateByPrimaryKeySelective(record);
  256. if(rows > 0) {
  257. return new AjaxMessage(ResultStatus.OK);
  258. }
  259. return new AjaxMessage(ResultStatus.ERROR);
  260. }
  261. @RequestMapping(value="batchDelete" , method = RequestMethod.DELETE)
  262. @ApiOperation(value = "批量删除")
  263. public AjaxMessage<Integer> batchDelete( @ApiParam(value = "巡检计划ids") @RequestParam List<Integer> ids){
  264. return new AjaxMessage<>(ResultStatus.OK, planManageService.batchDelete(ids));
  265. }
  266. @GetMapping("/plan/delProcInst")
  267. @ApiOperation(value = "终止流程")
  268. public AjaxMessage deleteProcessInstance(
  269. @ApiParam(value = "任务ID", required = true) @RequestParam(required = true) Integer id,
  270. @ApiParam(value = "流程ID", required = true) @RequestParam(required = true) String processInstanceId,
  271. @ApiParam(value = "流程备注", required = false) @RequestParam(required = false) String remark) {
  272. Boolean delFlow = workFlowService.deleteProcessInstance(processInstanceId,remark);
  273. if(delFlow ==true) {
  274. PlanManage planManage = new PlanManage();
  275. planManage.setId(id);
  276. planManage.setPlanStatus(3);//任务终止状态
  277. planManage.setCurrentUsers("");
  278. planManageService.updateByPrimaryKeySelective(planManage);
  279. LoginUser currentUser = UserUtil.getCurrentUser();
  280. WorkFlowLog workFlowLog=new WorkFlowLog();
  281. workFlowLog.setFlowId(id);
  282. workFlowLog.setFlowType(1);
  283. workFlowLog.setFlowResult(remark);
  284. workFlowLog.setCreateBy(currentUser.getId()!=null?currentUser.getId().toString():null);
  285. workFlowLog.setDateCreate(new Date());
  286. workFlowLog.setHandleUserId(currentUser.getId()!=null?currentUser.getId().toString():null);
  287. workFlowLog.setHandleUserName(currentUser.getUsername());
  288. //记录日志
  289. workFlowLogService.insert(workFlowLog);
  290. return new AjaxMessage<>(ResultStatus.OK);
  291. }
  292. return new AjaxMessage<>(ResultStatus.ERROR);
  293. }
  294. /**
  295. * 获取并设置用户、任务工单类型名称
  296. * @param
  297. */
  298. private void setName(List<PlanManageDto> planManageDtoList){
  299. try {
  300. if(planManageDtoList.size()>0) {
  301. List<Long> idList = new ArrayList<Long>();
  302. for (PlanManageDto plan : planManageDtoList) {
  303. if(plan.getUserId() != null) {
  304. idList.add(Long.parseLong(plan.getUserId()));
  305. }
  306. if(plan.getPlanUserId() != null){
  307. idList.add(Long.parseLong(plan.getPlanUserId()));
  308. }
  309. if(plan.getCreateBy() != null){
  310. idList.add(Long.parseLong(plan.getCreateBy()));
  311. }
  312. if(plan.getUpdateBy() != null){
  313. idList.add(Long.parseLong(plan.getUpdateBy()));
  314. }
  315. }
  316. Long[] ids = idList.toArray(new Long[0]);
  317. Map<Long,String> userMap = userCenterClient.findUserIdsByUserIds(ids).stream().collect(Collectors.toMap(UserEntity::getId, UserEntity::getUsername));
  318. Map<String,String> dictMap=userCenterClient.selectListByPCodes("SC_WORK_ORDER_TYPE,SC_TASK_TYPE");
  319. for (PlanManageDto plan : planManageDtoList) {
  320. try {
  321. if (plan.getTaskType() != null) {
  322. plan.setTypeName(dictMap.get(plan.getTaskType().toString()));
  323. }
  324. if (plan.getUserId() != null) {
  325. plan.setUserName(userMap.get(Long.valueOf(plan.getUserId())));
  326. }
  327. if (plan.getPlanUserId() != null) {
  328. plan.setPlanUserName(userMap.get(Long.valueOf(plan.getPlanUserId())));
  329. }
  330. if (plan.getCreateBy() != null) {
  331. plan.setCreateByName(userMap.get(Long.valueOf(plan.getCreateBy())));
  332. }
  333. if (plan.getUpdateBy() != null) {
  334. plan.setUpdateByName(userMap.get(Long.valueOf(plan.getUpdateBy())));
  335. }
  336. if (plan.getWorkFlowDetail() != null) {
  337. WorkFlowDetail workFlowDetail = plan.getWorkFlowDetail();
  338. if (workFlowDetail.getCreateBy() != null) {
  339. workFlowDetail.setCreateByName(userMap.get(Long.valueOf(workFlowDetail.getCreateBy())));
  340. }
  341. if (workFlowDetail.getUpdateBy() != null) {
  342. workFlowDetail.setUpdateByName(userMap.get(Long.valueOf(workFlowDetail.getUpdateBy())));
  343. }
  344. }
  345. if (plan.getWorkFlowLogList() != null) {
  346. for (WorkFlowLog workFlowLog : plan.getWorkFlowLogList()) {
  347. try {
  348. if (workFlowLog.getCreateBy() != null) {
  349. workFlowLog.setCreateByName(userMap.get(Long.valueOf(workFlowLog.getCreateBy())));
  350. }
  351. if (workFlowLog.getUpdateBy() != null) {
  352. workFlowLog.setUpdateByName(userMap.get(Long.valueOf(workFlowLog.getUpdateBy())));
  353. }
  354. }catch (Exception e){
  355. }
  356. }
  357. }
  358. }catch(Exception e){
  359. }
  360. }
  361. }
  362. }catch (Exception e){
  363. e.printStackTrace();
  364. }
  365. }
  366. }