Kaynağa Gözat

fix 代办查询

ys321973351 1 yıl önce
ebeveyn
işleme
49992e52d8

+ 94 - 73
itdmServer/module-ACTIVITI/src/main/java/org/jeecg/modules/activiti/controller/ServiceController.java

@@ -15,7 +15,6 @@ import org.activiti.engine.impl.identity.Authentication;
 import org.activiti.engine.impl.persistence.entity.VariableInstance;
 import org.activiti.engine.repository.Model;
 import org.activiti.engine.repository.ProcessDefinition;
-import org.activiti.engine.runtime.Execution;
 import org.activiti.engine.runtime.ProcessInstance;
 import org.activiti.engine.task.Task;
 import org.activiti.engine.task.TaskQuery;
@@ -84,17 +83,18 @@ public class ServiceController {
     private ICustomFormService customFormService;
     @Resource
     private ActivitiTracingChart activitiTracingChart;
+
     /**
      * stencilset
      *
      * @return stencilset.json
      */
-    @RequestMapping(value="/act/userSyn", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
+    @RequestMapping(value = "/act/userSyn", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
     public Result<LoginUser> actUserSyn(HttpServletRequest request) {
-        LoginUser sysUser         = (LoginUser) request.getAttribute("user");
-        String    selectedRoles   =  request.getAttribute("selectedRoles").toString();
-        String    selectedDeparts =  request.getAttribute("selectedDeparts").toString();
-        Result<LoginUser> result  = (Result<LoginUser>) request.getAttribute("result");
+        LoginUser sysUser = (LoginUser) request.getAttribute("user");
+        String selectedRoles = request.getAttribute("selectedRoles").toString();
+        String selectedDeparts = request.getAttribute("selectedDeparts").toString();
+        Result<LoginUser> result = (Result<LoginUser>) request.getAttribute("result");
 
         ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
         IdentityService identityService = engine.getIdentityService();
@@ -111,10 +111,11 @@ public class ServiceController {
 
     /**
      * 获取角色信息
+     *
      * @param request
      * @return
      */
-    @RequestMapping(value="/act/role/getRoleList", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
+    @RequestMapping(value = "/act/role/getRoleList", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
     public List<Group> getRoleList(HttpServletRequest request) {
         List<Group> result = new ArrayList<>();
         result = identityService.createGroupQuery().list();
@@ -123,40 +124,42 @@ public class ServiceController {
 
     /**
      * 获取用户信息
+     *
      * @param request
      * @param page
      * @param limit
      * @param keyword
      * @return
      */
-    @RequestMapping(value="/act/user/actUserList/{page}/{limit}", method = RequestMethod.GET,
+    @RequestMapping(value = "/act/user/actUserList/{page}/{limit}", method = RequestMethod.GET,
             produces = "application/json;charset=utf-8")
-    public Result actUserList(HttpServletRequest request,@PathVariable("page")  int page,
-                              @PathVariable("limit")  int limit,
+    public Result actUserList(HttpServletRequest request, @PathVariable("page") int page,
+                              @PathVariable("limit") int limit,
                               @RequestParam String keyword) {
         List<User> list = new ArrayList<>();
         Integer total = 0;
-        if(null!=keyword&&!keyword.equals("")){
-           list = identityService.createNativeUserQuery().sql("select id_,rev_ ,first_,last_,email_,pwd_ FROM act_id_user where first_ like #{first_}")
-                    .parameter("first_","%"+keyword+"%").listPage((page-1)*limit, limit);
-            total= identityService.createNativeUserQuery().sql("select id_,rev_ ,first_,last_,email_,pwd_ FROM act_id_user where first_ like #{first_}")
-                    .parameter("first_","%"+keyword+"%").list().size();
+        if (null != keyword && !keyword.equals("")) {
+            list = identityService.createNativeUserQuery().sql("select id_,rev_ ,first_,last_,email_,pwd_ FROM act_id_user where first_ like #{first_}")
+                    .parameter("first_", "%" + keyword + "%").listPage((page - 1) * limit, limit);
+            total = identityService.createNativeUserQuery().sql("select id_,rev_ ,first_,last_,email_,pwd_ FROM act_id_user where first_ like #{first_}")
+                    .parameter("first_", "%" + keyword + "%").list().size();
 
-        }else{
+        } else {
             //查询所有角色
-           list = identityService.createNativeUserQuery().sql("select id_,rev_ ,first_,last_,email_,pwd_ FROM act_id_user ").listPage((page-1)*limit,limit);
-           total= identityService.createNativeUserQuery().sql("select id_,rev_ ,first_,last_,email_,pwd_ FROM act_id_user ").list().size();
+            list = identityService.createNativeUserQuery().sql("select id_,rev_ ,first_,last_,email_,pwd_ FROM act_id_user ").listPage((page - 1) * limit, limit);
+            total = identityService.createNativeUserQuery().sql("select id_,rev_ ,first_,last_,email_,pwd_ FROM act_id_user ").list().size();
 
 
         }
-        return Result.OKK(list,total);
+        return Result.OKK(list, total);
     }
 
     /**
      * 获取流程信息
+     *
      * @return
      */
-    @RequestMapping(value="/act/rep/actRepList", method = RequestMethod.GET,
+    @RequestMapping(value = "/act/rep/actRepList", method = RequestMethod.GET,
             produces = "application/json;charset=utf-8")
     public Object actRepList() {
         List<ProcessDefinition> processDefinitions = repositoryService.createNativeProcessDefinitionQuery()
@@ -167,6 +170,7 @@ public class ServiceController {
 
     /**
      * 通过模型id 查询流程图片
+     *
      * @param pdid
      * @param response
      * @throws Exception
@@ -175,12 +179,12 @@ public class ServiceController {
     @RequestMapping(value = "/act/showResource", method = RequestMethod.GET)
     public void showResource(@RequestParam("pdid") String pdid,
                              HttpServletResponse response) throws Exception {
-        System.out.println("查看工作流图片"+pdid);
+        System.out.println("查看工作流图片" + pdid);
         Model model = repositoryService.createModelQuery().modelId(pdid).singleResult();
         ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(model.getDeploymentId()).singleResult();
         BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinition.getId());
         ProcessDiagramGenerator diagramGenerator = configuration.getProcessDiagramGenerator();
-        InputStream is = diagramGenerator.generateDiagram(bpmnModel, "png",  "宋体", "宋体", "宋体",
+        InputStream is = diagramGenerator.generateDiagram(bpmnModel, "png", "宋体", "宋体", "宋体",
                 configuration.getClassLoader(), 1.0);
         ServletOutputStream output = response.getOutputStream();
         IOUtils.copy(is, output);
@@ -188,6 +192,7 @@ public class ServiceController {
 
     /**
      * 直接通过 流程定义id 查询流程图片
+     *
      * @param pdid
      * @param response
      * @throws Exception
@@ -195,16 +200,18 @@ public class ServiceController {
     @ApiOperation("查看工作流图片")
     @RequestMapping(value = "/act/showResourceForProc", method = RequestMethod.GET)
     public void showResourceForProc(@RequestParam("pdid") String pdid,
-                             HttpServletResponse response) throws Exception {
+                                    HttpServletResponse response) throws Exception {
         BpmnModel bpmnModel = repositoryService.getBpmnModel(pdid);
         ProcessDiagramGenerator diagramGenerator = configuration.getProcessDiagramGenerator();
-        InputStream is = diagramGenerator.generateDiagram(bpmnModel, "png",  "宋体", "宋体", "宋体",
+        InputStream is = diagramGenerator.generateDiagram(bpmnModel, "png", "宋体", "宋体", "宋体",
                 configuration.getClassLoader(), 1.0);
         ServletOutputStream output = response.getOutputStream();
         IOUtils.copy(is, output);
     }
+
     /**
      * 直接通过 流程定义id 查询流程图片
+     *
      * @param pdid
      * @param response
      * @throws Exception
@@ -212,61 +219,69 @@ public class ServiceController {
     @ApiOperation("发起流程前返回自定义表单")
     @RequestMapping(value = "/act/beforeStartProc", method = RequestMethod.GET)
     public Result beforeStartProc(@RequestParam("pdid") String pdid,
-                                    HttpServletResponse response) throws Exception {
+                                  HttpServletResponse response) throws Exception {
         // 根据流程定义id获取启动节点的formKey,也就是获取自定义表单值,启动节点就是那个流程图的第一个圈
         String formKey = formService.getStartFormKey(pdid);
         // 根据任务id获取任务id的formKey,也就是获取任务节点的自定义表单值
         //formService.getTaskFormData(taskId).getFormKey();
-         CustomForm customForm = customFormService.getById(formKey);
-        return  Result.OK("",customForm.getFormcontent());
+        CustomForm customForm = customFormService.getById(formKey);
+        return Result.OK("", customForm.getFormcontent());
     }
+
     @ApiOperation("发起流程")
     @RequestMapping(value = "/act/startProc", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
     public Result startProc(@RequestParam("procKey") String procKey,
-                            @RequestParam("businessKey") String businessKey ,
-                            @RequestParam("formData") String formData ,HttpServletResponse response) throws Exception {
+                            @RequestParam("businessKey") String businessKey,
+                            @RequestParam("formData") String formData, HttpServletResponse response) throws Exception {
         // 设置申请人,将之保存在流程变量中
         LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
-        Map<String ,Object > variables = new HashMap<>();
+        Map<String, Object> variables = new HashMap<>();
         //variables.put("applyuserid", user.getId());
         variables.put("userid", user.getId());
         variables.put("applyUser", user.getId());
-        variables.put("formData",formData);
-      //  String[] person ={user.getId()};
-      //  variables.put("people",Arrays.asList(person));
+        variables.put("formData", formData);
+        //  String[] person ={user.getId()};
+        //  variables.put("people",Arrays.asList(person));
         Authentication.setAuthenticatedUserId(String.valueOf(user.getId()));
         ProcessInstance processInstance = null;
         try {
-            processInstance = runtimeService.startProcessInstanceByKeyAndTenantId(procKey,businessKey,variables,"0");
-        }catch (Exception e){
-            processInstance = runtimeService.startProcessInstanceByKey(procKey,businessKey,variables);
+            processInstance = runtimeService.startProcessInstanceByKeyAndTenantId(procKey, businessKey, variables, "0");
+        } catch (Exception e) {
+            processInstance = runtimeService.startProcessInstanceByKey(procKey, businessKey, variables);
         }
 
         //
-       Task autoTask = taskService.createTaskQuery()
+        Task autoTask = taskService.createTaskQuery()
                 .processDefinitionKey(procKey).processInstanceId(processInstance.getId()).singleResult();
         autoTask.setOwner(user.getId());
         taskService.saveTask(autoTask);
 
 
 //        taskService.complete(autoTask.getId());
-        return  Result.OK("请求成功");
+        return Result.OK("请求成功");
     }
+
     @ApiOperation("查询我的待办任务列表")
     @GetMapping("/act/mylist")
     @ResponseBody
-    public Result mylist(@RequestParam("pageNo") int pageNo,@RequestParam("pageSize") int pageSize,@RequestParam("key") String key)
-    {
+    public Result mylist(@RequestParam("pageNo") int pageNo, @RequestParam("pageSize") int pageSize, @RequestParam(value = "key", required = false) String key) {
         LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
         String userId = user.getId();
         TaskQuery condition = taskService.createTaskQuery().taskAssignee(userId);
 
         // 过滤掉流程挂起的待办任务
         int total = condition.active().orderByTaskCreateTime().desc().list().size();
-        List<Task> taskList = condition.active().orderByTaskCreateTime().processInstanceId(key).desc().listPage((pageNo-1) * pageSize, pageSize);
+        List<Task> taskList ;
+        if (StringUtils.isNotEmpty(key)) {
+            taskList = condition.active().orderByTaskCreateTime().processInstanceId(key).desc().listPage((pageNo - 1) * pageSize, pageSize);
+
+        } else {
+            taskList = condition.active().orderByTaskCreateTime().desc().listPage((pageNo - 1) * pageSize, pageSize);
+
+        }
         List<TaskInfo> tasks = new ArrayList<>();
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-        taskList.stream().forEach(a->{
+        taskList.stream().forEach(a -> {
             ProcessInstance process = runtimeService.createProcessInstanceQuery().processInstanceId(a.getProcessInstanceId()).singleResult();
             TaskInfo info = new TaskInfo();
             info.setAssignee(identityService.createUserQuery().userId(a.getAssignee()).singleResult().getFirstName());
@@ -276,32 +291,34 @@ public class ServiceController {
             info.setExecutionId(a.getExecutionId());
             info.setProcessInstanceId(a.getProcessInstanceId());
             info.setProcessName(process.getProcessDefinitionName());
-            info.setStarter(process.getStartUserId()==null?"0":identityService.createUserQuery().userId(process.getStartUserId()).singleResult().getFirstName());
+            info.setStarter(process.getStartUserId() == null ? "0" : identityService.createUserQuery().userId(process.getStartUserId()).singleResult().getFirstName());
             info.setStartTime(sdf.format(process.getStartTime()));
             info.setTaskId(a.getId());
             String formKey = formService.getTaskFormData(a.getId()).getFormKey();
             info.setFormKey(formKey);
             tasks.add(info);
         });
-        Result.OKK(tasks,total);
-        return Result.OKK(tasks,total);
+        Result.OKK(tasks, total);
+        return Result.OKK(tasks, total);
     }
+
     @ApiOperation("流程图进度追踪")
     @RequestMapping(value = {"/traceProcess/{processInstanceId}"}, method = RequestMethod.GET)
     public void traceprocess(@PathVariable String processInstanceId, HttpServletResponse response) throws IOException {
         activitiTracingChart.generateFlowChart(processInstanceId, response.getOutputStream());
     }
+
     @ApiOperation("办理一个用户任务")
     @RequestMapping(value = "/getTaskInfo/{executionId}/{taskId}", method = RequestMethod.POST)
     @ResponseBody
-    public Result completeTask(@PathVariable("executionId") String executionId,@PathVariable("taskId") String taskId) {
-        VariableInstance variableInstance = runtimeService.getVariableInstance(executionId,"formData");
+    public Result completeTask(@PathVariable("executionId") String executionId, @PathVariable("taskId") String taskId) {
+        VariableInstance variableInstance = runtimeService.getVariableInstance(executionId, "formData");
 
         List<HistoricVariableInstance> variableInstances = historyService.createHistoricVariableInstanceQuery()
                 .processInstanceId(executionId)
                 .variableName("formData").list();
         List<VariableInfo> infos = new ArrayList<>();
-        variableInstances.forEach(v->{
+        variableInstances.forEach(v -> {
             VariableInfo info = new VariableInfo();
             BeanUtils.copyBeanProp(info, v);
             info.setValue(v.getValue().toString());
@@ -311,41 +328,43 @@ public class ServiceController {
         // 根据任务id获取任务id的formKey,也就是获取任务节点的自定义表单值
         //formService.getTaskFormData(taskId).getFormKey();
         CustomForm customForm = customFormService.getById(task.getFormKey());
-        Map<String ,Object> map = new HashMap<>();
-        map.put("fromData1",infos);
-        map.put("fromData2",customForm.getFormcontent());
-        return Result.OK("查询成功",map);
+        Map<String, Object> map = new HashMap<>();
+        map.put("fromData1", infos);
+        map.put("fromData2", customForm.getFormcontent());
+        return Result.OK("查询成功", map);
     }
+
     @ApiOperation("提交一个用户任务")
     @RequestMapping(value = "/completeTask/{taskId}", method = RequestMethod.POST)
     @ResponseBody
     public AjaxResult completeTask(@PathVariable("taskId") String taskId,
-                                   @RequestBody(required=false) String  comment,
-                                   @RequestBody(required=false) String  formData) {
+                                   @RequestBody(required = false) String comment,
+                                   @RequestBody(required = false) String formData) {
         LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
         String username = user.getId();
         taskService.setAssignee(taskId, username);
-        Map<String ,Object > variables = new HashMap<>();
-        variables.put("formData",formData);
+        Map<String, Object> variables = new HashMap<>();
+        variables.put("formData", formData);
         // 查出流程实例id
         String processInstanceId = taskService.createTaskQuery().taskId(taskId).singleResult().getProcessInstanceId();
-        if (comment == null||comment.equals("")) {
-            taskService.complete(taskId,variables);
+        if (comment == null || comment.equals("")) {
+            taskService.complete(taskId, variables);
         } else {
             // 添加审批意见
             if (comment != null && !comment.equals("")) {
-                taskService.addComment(taskId, processInstanceId,comment);
+                taskService.addComment(taskId, processInstanceId, comment);
             }
             taskService.complete(taskId, variables);
         }
         return AjaxResult.success();
     }
+
     /**
      * stencilset
      *
      * @return stencilset.json
      */
-    @RequestMapping(value="/editor/stencilset", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
+    @RequestMapping(value = "/editor/stencilset", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
     public String getStencilset() {
         InputStream stencilsetStream = this.getClass().getResourceAsStream("/static/stencilset.json");
         try {
@@ -362,7 +381,7 @@ public class ServiceController {
      * @param modelId
      * @return
      */
-    @RequestMapping(value="/model/{modelId}/json", method = RequestMethod.GET)
+    @RequestMapping(value = "/model/{modelId}/json", method = RequestMethod.GET)
     public ObjectNode getEditorJson(@PathVariable String modelId) {
         ObjectNode modelNode = null;
 
@@ -371,13 +390,13 @@ public class ServiceController {
         if (model != null) {
             try {
                 if (StringUtils.isNotEmpty(model.getMetaInfo())) {
-                    modelNode = (ObjectNode)objectMapper.readTree(model.getMetaInfo());
+                    modelNode = (ObjectNode) objectMapper.readTree(model.getMetaInfo());
                 } else {
                     modelNode = objectMapper.createObjectNode();
                     modelNode.put("name", model.getName());
                 }
                 modelNode.put("modelId", model.getId());
-                ObjectNode editorJsonNode = (ObjectNode)objectMapper
+                ObjectNode editorJsonNode = (ObjectNode) objectMapper
                         .readTree(new String(repositoryService.getModelEditorSource(model.getId()), "utf-8"));
                 modelNode.set("model", editorJsonNode);
 
@@ -397,19 +416,19 @@ public class ServiceController {
      * @param svgXml
      * @param description
      */
-    @RequestMapping(value = "/model/{modelId}/save", method=RequestMethod.PUT)
+    @RequestMapping(value = "/model/{modelId}/save", method = RequestMethod.PUT)
     public void saveModel(@PathVariable String modelId, @RequestParam("name") String name,
                           @RequestParam("json_xml") String jsonXml, @RequestParam("svg_xml") String svgXml,
-                          @RequestParam("description") String description,HttpServletRequest req) {
+                          @RequestParam("description") String description, HttpServletRequest req) {
         try {
             String tenantId = req.getHeader("tenant-id");
             Model model = repositoryService.getModel(modelId);
-            ObjectNode modelJson = (ObjectNode)objectMapper.readTree(model.getMetaInfo());
+            ObjectNode modelJson = (ObjectNode) objectMapper.readTree(model.getMetaInfo());
             modelJson.put("name", name);
             modelJson.put("description", description);
             model.setMetaInfo(modelJson.toString());
             model.setName(name);
-            model.setVersion(model.getVersion()+1);
+            model.setVersion(model.getVersion() + 1);
             model.setTenantId(tenantId);
             repositoryService.saveModel(model);
             repositoryService.addModelEditorSource(model.getId(), jsonXml.getBytes(StandardCharsets.UTF_8));
@@ -427,6 +446,7 @@ public class ServiceController {
             throw new ActivitiException("Error saving model", e);
         }
     }
+
     @ApiOperation("查询所有流程实例列表-包含在运行和已结束")
     @RequestMapping(value = "/listHistoryProcess", method = RequestMethod.GET)
     @ResponseBody
@@ -458,14 +478,14 @@ public class ServiceController {
             info.setStartTime(p.getStartTime());
             info.setEndTime(p.getEndTime());
             info.setStartUserId(p.getStartUserId());
-            if(StringUtils.isNotEmpty(p.getStartUserId()) && (!p.getStartUserId().equals("")) && (!p.getStartUserId().equals("null"))){
+            if (StringUtils.isNotEmpty(p.getStartUserId()) && (!p.getStartUserId().equals("")) && (!p.getStartUserId().equals("null"))) {
                 User user1 = identityService.createUserQuery().userId(p.getStartUserId()).singleResult();
                 info.setStartUserId(user1.getFirstName());
             }
             if (p.getEndTime() == null) {
                 info.setEnded(false);
                 // 查看当前活动任务
-                List<Task> tasks =  taskService.createTaskQuery().processInstanceId(p.getId()).list();
+                List<Task> tasks = taskService.createTaskQuery().processInstanceId(p.getId()).list();
                 if (tasks.size() > 0) {
                     String taskName = "";
                     String assignee = "";
@@ -473,11 +493,11 @@ public class ServiceController {
                         taskName += t.getName() + ",";
                         assignee += t.getAssignee() + ",";
                     }
-                    taskName = taskName.substring(0, taskName.length() -1);
-                    assignee = assignee.substring(0, assignee.length() -1);
+                    taskName = taskName.substring(0, taskName.length() - 1);
+                    assignee = assignee.substring(0, assignee.length() - 1);
                     info.setCurrentTask(taskName);
                     info.setAssignee(assignee);
-                    if(StringUtils.isNotEmpty(assignee) && !assignee.equals("") && !assignee.equals("null")){
+                    if (StringUtils.isNotEmpty(assignee) && !assignee.equals("") && !assignee.equals("null")) {
                         User user = identityService.createUserQuery().userId(assignee).singleResult();
                         info.setAssignee(user.getFirstName());
                     }
@@ -498,4 +518,5 @@ public class ServiceController {
         p.setSearchCount(true);
         return Result.OK(p);
 
-    }}
+    }
+}