From c007f0ca1785db093d48f4846cda82fe8e955765 Mon Sep 17 00:00:00 2001 From: kimi <kimi42345@gmail.com> Date: 星期三, 27 五月 2020 09:59:29 +0800 Subject: [PATCH] merage --- src/main/java/com/highdatas/mdm/controller/FlowsController.java | 136 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 135 insertions(+), 1 deletions(-) diff --git a/src/main/java/com/highdatas/mdm/controller/FlowsController.java b/src/main/java/com/highdatas/mdm/controller/FlowsController.java index 6a6c88a..f03d148 100644 --- a/src/main/java/com/highdatas/mdm/controller/FlowsController.java +++ b/src/main/java/com/highdatas/mdm/controller/FlowsController.java @@ -1,19 +1,153 @@ package com.highdatas.mdm.controller; +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.baomidou.mybatisplus.mapper.Wrapper; +import com.baomidou.mybatisplus.plugins.Page; +import com.highdatas.mdm.entity.Flows; +import com.highdatas.mdm.entity.TUser; +import com.highdatas.mdm.pojo.ActivitiBusinessType; +import com.highdatas.mdm.pojo.ActivitiStatus; +import com.highdatas.mdm.pojo.CodeMsg; +import com.highdatas.mdm.pojo.Result; +import com.highdatas.mdm.service.IFlowsService; +import com.highdatas.mdm.util.DbUtils; +import org.activiti.engine.RuntimeService; +import org.activiti.engine.runtime.ProcessInstance; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; +import java.util.ArrayList; +import java.util.List; /** * <p> * 鍓嶇鎺у埗鍣� * </p> - * + * @description 娴佺▼瀹炰緥涓氬姟鎺ュ彛 * @author kimi * @since 2019-12-16 */ @RestController @RequestMapping("/flows") public class FlowsController { + @Autowired + IFlowsService flowsService; + @Autowired + RuntimeService runtimeService; + + /** + * + * @description: 鍒嗛〉鑾峰彇娴佺▼瀹炰緥 + * @param pageno 椤垫暟 + * @return: 娴佺▼瀹炰緥 + * + */ + @RequestMapping(value = "/{pageno}", method = RequestMethod.GET) + public Result<Page<Flows>> getAll(@PathVariable int pageno, HttpServletRequest request) { + //鑾峰彇姣忛〉鏁版嵁閲� + String pageSize = request.getParameter("pageSize"); + if (StringUtils.isEmpty(pageSize)) { + pageSize = "15"; + } + EntityWrapper<Flows> flowsEntityWrapper = new EntityWrapper<>(); + //绛涢��-- 寮�鍚敤鎴� + String userId = request.getParameter("userId"); + if (!StringUtils.isEmpty(userId)) { + flowsEntityWrapper.eq("user_id", userId); + } + //绛涢��--鐘舵�� + String status = request.getParameter("status"); + if (!StringUtils.isEmpty(status)) { + flowsEntityWrapper.eq("status", status); + } + Integer size = Integer.valueOf(pageSize); + Page page = new Page(pageno, size); + Page<Flows> menuPage = flowsService.selectPage(page, flowsEntityWrapper); + //鑾峰彇鍒嗛〉鍚庣殑娴佺▼瀹炰緥 + List<Flows> records = menuPage.getRecords(); + List<Flows> recordsStr = new ArrayList<>(); + for (Flows flows : records) { + //鏇存柊鐘舵�佷腑鏂囧悕缁欏墠绔� + flows.setBusinessTypeStr(flows.getBusinessType().toString()); + TUser userById = DbUtils.getUserById(flows.getUserId()); + //鏌ヨ鐢ㄦ埛鐨勫悕绉扮粰鍓嶇 + flows.setUserName(userById.getUserName()); + recordsStr.add(flows); + } + menuPage.setRecords(recordsStr); + return Result.success(menuPage); + } + /** + * + * @description: By 鐢ㄦ埛鍒犻櫎娴佺▼ + * @param userId 鐢ㄦ埛id + * @return: 鏄惁鎴愬姛 + * + */ + + @RequestMapping(value = "closeByUser/{userId}", method = RequestMethod.GET) + public Result closeByUser(@PathVariable String userId, HttpServletRequest request) { + Wrapper<Flows> user_id = new EntityWrapper<Flows>().eq("user_id", userId); + //By user鏌ヨ娴佺▼ + List<Flows> flows = flowsService.selectList(user_id); + for (Flows flow : flows) { + //寰幆鍒犻櫎娴佺▼浠ュ強瀵瑰簲鐨勬祦绋嬩俊鎭� + closeById(flow.getId()); + } + return Result.success(null); + } + /** + * + * @description: 閫氳繃id鍒犻櫎娴佺▼ + * @param id flows鐨刬d + * @return: 鏄惁鍒犻櫎 + * + */ + @RequestMapping(value = "close/{id}", method = RequestMethod.GET) + public Result close(@PathVariable String id, HttpServletRequest request) { + return closeById(id); + } + + /** + * + * @description: 閫氳繃id鍒犻櫎娴佺▼ + * @param id flows鐨刬d + * @return: 鏄惁鍒犻櫎 + * + */ + private Result closeById(@PathVariable String id) { + //閫氳繃id鑾峰彇flow淇℃伅 + Flows flows = flowsService.selectById(id); + if (flows == null) { + return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); + } + //鑾峰彇娴佺▼id + String workflowId = flows.getWorkflowId(); + //鑾峰彇activiti娴佺▼瀹炰緥 + ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(workflowId).singleResult(); + if (processInstance != null) { + //鍒犻櫎娴佺▼ + runtimeService.deleteProcessInstance(workflowId,"缁堟娴佺▼"); + } + //璁剧疆鐘舵�� + flows.setStatus(ActivitiStatus.close); + if (!flows.getBusinessType().equals(ActivitiBusinessType.exists)) { + /*璋冭捣娴佺▼缁撴潫鍚庣殑鍔ㄤ綔*/ + flowsService.aduitFinish(flows); + } + //鏇存柊鏁版嵁搴撲俊鎭� + boolean update = flows.updateById(); + if (update) { + return Result.success(flows); + }else { + return Result.error(CodeMsg.UPDATE_ERROR); + } + } } -- Gitblit v1.8.0