From c8aee7b9bfd79cfd741d7e5692520f4f51a31a86 Mon Sep 17 00:00:00 2001
From: kimi <kimi42345@gmail.com>
Date: 星期一, 18 五月 2020 18:30:01 +0800
Subject: [PATCH] bak  修改 获取版本数据前

---
 src/main/java/com/highdatas/mdm/controller/FlowsController.java |   93 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 93 insertions(+), 0 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..4c63758 100644
--- a/src/main/java/com/highdatas/mdm/controller/FlowsController.java
+++ b/src/main/java/com/highdatas/mdm/controller/FlowsController.java
@@ -1,8 +1,29 @@
 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>
@@ -15,5 +36,77 @@
 @RestController
 @RequestMapping("/flows")
 public class FlowsController {
+    @Autowired
+    IFlowsService flowsService;
 
+    @Autowired
+    RuntimeService runtimeService;
+    @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);
+    }
+
+    @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);
+        List<Flows> flows = flowsService.selectList(user_id);
+        for (Flows flow : flows) {
+            closeById(flow.getId());
+        }
+        return Result.success(null);
+    }
+
+    @RequestMapping(value = "close/{id}", method = RequestMethod.GET)
+    public Result close(@PathVariable String id, HttpServletRequest request) {
+        return closeById(id);
+    }
+
+    private Result closeById(@PathVariable String id) {
+        Flows flows = flowsService.selectById(id);
+        if (flows == null) {
+            return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED);
+        }
+        String workflowId = flows.getWorkflowId();
+        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