Procházet zdrojové kódy

审批-我发起的列表 我发起的审批详情 取消审批 抄送我的全部 未读列表

肖玮 před 5 roky
rodič
revize
068fdf339a

+ 1 - 1
mec-education/src/main/java/com/ym/mec/education/mapper/SysRoleMapper.java

@@ -1,7 +1,7 @@
 package com.ym.mec.education.mapper;
 
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.ym.mec.education.entity.SysRole;
-import com.baomidou.mybatisplus.mapper.BaseMapper;
 
 /**
  * <p>

+ 5 - 2
mec-education/src/main/java/com/ym/mec/education/req/ApprovalReq.java

@@ -18,6 +18,9 @@ public class ApprovalReq extends BaseQuery {
     @ApiModelProperty(value = "处理人")
     private Integer userId;
 
-    @ApiModelProperty(value = "审批任务id")
-    private String taskId;
+    @ApiModelProperty(value = "流程id")
+    private String orderId;
+
+    @ApiModelProperty(value = "未读状态 0 未读 1 已读")
+    private Integer status;
 }

+ 7 - 1
mec-education/src/main/java/com/ym/mec/education/resp/ApprovalResp.java

@@ -26,6 +26,8 @@ public class ApprovalResp implements Serializable {
     private String status;
     @ApiModelProperty(value = "审批任务id")
     private String taskId;
+    @ApiModelProperty(value = "流程实例id")
+    private String orderId;
     @ApiModelProperty(value = "审批事项")
     private String approvalType;
     @ApiModelProperty(value = "申请日期")
@@ -41,7 +43,7 @@ public class ApprovalResp implements Serializable {
 
     @Data
     @ApiModel(description = "审批历史详情")
-    class ApprovalHistoryInfo implements Serializable{
+    public static class ApprovalHistoryInfo implements Serializable{
         @ApiModelProperty(value = "审批处理人")
         private String operator;
         @ApiModelProperty(value = "审批状态")
@@ -49,4 +51,8 @@ public class ApprovalResp implements Serializable {
         @ApiModelProperty(value = "拒绝原因")
         private String reason;
     }
+
+    public static ApprovalHistoryInfo getApprovalHistoryInfo(){
+        return new ApprovalHistoryInfo();
+    }
 }

+ 1 - 1
mec-education/src/main/java/com/ym/mec/education/service/ISysRoleService.java

@@ -1,7 +1,7 @@
 package com.ym.mec.education.service;
 
+import com.baomidou.mybatisplus.extension.service.IService;
 import com.ym.mec.education.entity.SysRole;
-import com.baomidou.mybatisplus.service.IService;
 
 /**
  * <p>

+ 134 - 17
mec-education/src/main/java/com/ym/mec/education/service/impl/ApprovalServiceImpl.java

@@ -2,19 +2,24 @@ package com.ym.mec.education.service.impl;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.google.common.collect.Lists;
 import com.ym.mec.education.base.BaseResponse;
 import com.ym.mec.education.base.PageResponse;
+import com.ym.mec.education.entity.SysRole;
 import com.ym.mec.education.entity.SysUser;
 import com.ym.mec.education.enums.ApprovalStatusEnum;
 import com.ym.mec.education.req.ApprovalReq;
 import com.ym.mec.education.resp.ApprovalResp;
 import com.ym.mec.education.service.ApprovalService;
+import com.ym.mec.education.service.ISysRoleService;
 import com.ym.mec.education.service.ISysUserService;
 import org.apache.commons.lang3.StringUtils;
 import org.snaker.engine.IQueryService;
 import org.snaker.engine.access.Page;
 import org.snaker.engine.access.QueryFilter;
-import org.snaker.engine.entity.WorkItem;
+import org.snaker.engine.core.AccessService;
+import org.snaker.engine.core.TaskService;
+import org.snaker.engine.entity.*;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -38,6 +43,10 @@ public class ApprovalServiceImpl implements ApprovalService {
     private IQueryService queryService;
     @Autowired
     private ISysUserService userService;
+    @Autowired
+    private TaskService taskService;
+    @Autowired
+    private ISysRoleService roleService;
 
     @Override
     public PageResponse<ApprovalResp> getProcessingList(ApprovalReq approvalReq) {
@@ -69,22 +78,110 @@ public class ApprovalServiceImpl implements ApprovalService {
 
     @Override
     public PageResponse<ApprovalResp> getLaunchList(ApprovalReq approvalReq) {
-        return null;
+        if (Objects.isNull(approvalReq.getUserId())) {
+            return PageResponse.errorParam();
+        }
+        Page<HistoryOrder> page = new Page();
+        page.setPageNo(approvalReq.getPageNo());
+        page.setPageSize(approvalReq.getPageSize());
+        QueryFilter queryFilter = new QueryFilter();
+        queryFilter.setOperator(approvalReq.getUserId().toString());
+        queryService.getHistoryOrders(page, queryFilter);
+        Page<ApprovalResp> pageResult = new Page();
+        BeanUtils.copyProperties(page, pageResult);
+        List<ApprovalResp> list = new ArrayList<>(page.getResult().size());
+        if (!CollectionUtils.isEmpty(page.getResult())) {
+            page.getResult().forEach(item -> {
+                ApprovalResp approvalResp = initApprovalResp(item.getVariable(), userService.getById(item.getCreator()));
+                approvalResp.setOrderId(item.getId()).setApprovalType(item.getProcessName())
+                    .setApprovalDate(item.getCreateTime().substring(0, 10));
+                list.add(approvalResp);
+            });
+        }
+        pageResult.setResult(list);
+        return PageResponse.success(pageResult);
     }
 
     @Override
     public BaseResponse<ApprovalResp> getLaunchInfo(ApprovalReq approvalReq) {
-        return null;
+        if (Objects.isNull(approvalReq.getOrderId())) {
+            return BaseResponse.errorParam();
+        }
+        Order order = queryService.getOrder(approvalReq.getOrderId());
+        ApprovalResp approvalResp = initApprovalResp(order.getVariable(), userService.getById(order.getCreator()));
+        QueryFilter queryFilter = new QueryFilter();
+        queryFilter.setOperator(order.getCreator()).orderBy("create_Time desc");
+        List<HistoryTask> historyTaskList = queryService.getHistoryTasks(queryFilter);
+        List<Task> activeTaskList = queryService.getActiveTasks(queryFilter);
+        List<ApprovalResp.ApprovalHistoryInfo> historyInfoList = Lists.newArrayList();
+        ApprovalResp.ApprovalHistoryInfo approvalHistoryInfo = ApprovalResp.getApprovalHistoryInfo();
+        approvalHistoryInfo.setOperator("我").setStatus("发起申请");
+        historyInfoList.add(approvalHistoryInfo);
+        if (!CollectionUtils.isEmpty(historyTaskList)) {
+            historyTaskList.forEach(task -> {
+                ApprovalResp.ApprovalHistoryInfo historyInfo = initApprovalHisotoryVariable(task.getVariable());
+                SysRole role = roleService.getById(task.getOperator());
+                if (Objects.nonNull(role)) {
+                    Optional.ofNullable(role.getRoleName()).ifPresent(roleName -> historyInfo.setOperator(roleName));
+                }
+                historyInfoList.add(historyInfo);
+            });
+        }
+        if (!CollectionUtils.isEmpty(activeTaskList)) {
+            historyTaskList.forEach(task -> {
+                ApprovalResp.ApprovalHistoryInfo historyInfo = initApprovalHisotoryVariable(task.getVariable());
+                SysRole role = roleService.getById(task.getOperator());
+                if (Objects.nonNull(role)) {
+                    Optional.ofNullable(role.getRoleName()).ifPresent(roleName -> historyInfo.setOperator(roleName));
+                }
+                historyInfoList.add(historyInfo);
+            });
+        }
+        approvalResp.setApprovalHistory(historyInfoList);
+        return BaseResponse.success(approvalResp);
     }
 
     @Override
     public BaseResponse<ApprovalResp> cancel(ApprovalReq approvalReq) {
-        return null;
+        if (Objects.isNull(approvalReq.getOrderId()) || Objects.isNull(approvalReq.getUserId())) {
+            return BaseResponse.errorParam();
+        }
+        //查询该实例最新的任务
+        QueryFilter queryFilter = new QueryFilter();
+        queryFilter.setOrderId(approvalReq.getOrderId()).orderBy("create_Time desc");
+        List<Task> taskList = queryService.getActiveTasks(queryFilter);
+        taskList.stream().findFirst().ifPresent(task -> taskService.withdrawTask(task.getId(),
+            approvalReq.getUserId().toString()));
+        return BaseResponse.success("取消成功");
     }
 
     @Override
     public PageResponse<ApprovalResp> getCcList(ApprovalReq approvalReq) {
-        return null;
+        if (Objects.isNull(approvalReq.getUserId())) {
+            return PageResponse.errorParam();
+        }
+        Page<HistoryOrder> page = new Page();
+        page.setPageNo(approvalReq.getPageNo());
+        page.setPageSize(approvalReq.getPageSize());
+        QueryFilter queryFilter = new QueryFilter();
+        queryFilter.setOperator(approvalReq.getUserId().toString());
+        if (Objects.nonNull(approvalReq.getStatus()) && approvalReq.getStatus() == 0) {
+            //未读
+            queryFilter.setState(AccessService.STATE_ACTIVE);
+        }
+        queryService.getCCWorks(page, queryFilter);
+        Page<ApprovalResp> pageResult = new Page();
+        List<ApprovalResp> list = new ArrayList<>(page.getResult().size());
+        if (!CollectionUtils.isEmpty(page.getResult())) {
+            page.getResult().forEach(item -> {
+                ApprovalResp approvalResp = initApprovalResp(item.getVariable(), userService.getById(item.getCreator()));
+                approvalResp.setOrderId(item.getId()).setApprovalType(item.getProcessName())
+                    .setApprovalDate(item.getCreateTime().substring(0, 10));
+                list.add(approvalResp);
+            });
+        }
+        pageResult.setResult(list);
+        return PageResponse.success(pageResult);
     }
 
     private Page<ApprovalResp> workItem2Approval(Page<WorkItem> page) {
@@ -93,19 +190,8 @@ public class ApprovalServiceImpl implements ApprovalService {
         List<ApprovalResp> list = new ArrayList<>(page.getResult().size());
         if (!CollectionUtils.isEmpty(page.getResult())) {
             page.getResult().forEach(item -> {
-                ApprovalResp approvalResp = new ApprovalResp();
                 SysUser user = userService.getById(item.getCreator());
-                if (Objects.nonNull(user)) {
-                    Optional.ofNullable(user.getRealName()).ifPresent(name -> approvalResp.setApplicant(name));
-                }
-                String orderVariable = item.getOrderVariable();
-                if (StringUtils.isNotBlank(orderVariable)) {
-                    JSONObject jsonObject = JSON.parseObject(orderVariable);
-                    approvalResp.setStatus(ApprovalStatusEnum.getMsgByCode(jsonObject.getString("status")));
-                    Optional.ofNullable(jsonObject.getString("startTime")).ifPresent(time -> approvalResp.setStartTime(time));
-                    Optional.ofNullable(jsonObject.getString("endTime")).ifPresent(time -> approvalResp.setEndTime(time));
-                    Optional.ofNullable(jsonObject.getString("remark")).ifPresent(remark -> approvalResp.setRemark(remark));
-                }
+                ApprovalResp approvalResp = initApprovalResp(item.getOrderVariable(), user);
                 approvalResp.setTaskId(item.getTaskId()).setApprovalType(item.getProcessName())
                     .setApprovalDate(item.getOrderCreateTime().substring(0, 10));
                 list.add(approvalResp);
@@ -114,4 +200,35 @@ public class ApprovalServiceImpl implements ApprovalService {
         pageResult.setResult(list);
         return pageResult;
     }
+
+    private ApprovalResp initApprovalResp(String variable, SysUser user) {
+        ApprovalResp approvalResp = initApprovalVariable(variable);
+        if (Objects.nonNull(user)) {
+            Optional.ofNullable(user.getRealName()).ifPresent(name -> approvalResp.setApplicant(name));
+            Optional.ofNullable(user.getAvatar()).ifPresent(img -> approvalResp.setApplicantImg(img));
+        }
+        return approvalResp;
+    }
+
+    private ApprovalResp initApprovalVariable(String variable) {
+        ApprovalResp approvalResp = new ApprovalResp();
+        if (StringUtils.isNotBlank(variable)) {
+            JSONObject jsonObject = JSON.parseObject(variable);
+            approvalResp.setStatus(ApprovalStatusEnum.getMsgByCode(jsonObject.getString("status")));
+            Optional.ofNullable(jsonObject.getString("startTime")).ifPresent(time -> approvalResp.setStartTime(time));
+            Optional.ofNullable(jsonObject.getString("endTime")).ifPresent(time -> approvalResp.setEndTime(time));
+            Optional.ofNullable(jsonObject.getString("remark")).ifPresent(remark -> approvalResp.setRemark(remark));
+        }
+        return approvalResp;
+    }
+
+    private ApprovalResp.ApprovalHistoryInfo initApprovalHisotoryVariable(String variable) {
+        ApprovalResp.ApprovalHistoryInfo historyInfo = ApprovalResp.getApprovalHistoryInfo();
+        if (StringUtils.isNotBlank(variable)) {
+            JSONObject jsonObject = JSON.parseObject(variable);
+            historyInfo.setStatus(ApprovalStatusEnum.getMsgByCode(jsonObject.getString("status")));
+            Optional.ofNullable(jsonObject.getString("reason")).ifPresent(reason -> historyInfo.setReason(reason));
+        }
+        return historyInfo;
+    }
 }

+ 1 - 1
mec-education/src/main/java/com/ym/mec/education/service/impl/SysRoleServiceImpl.java

@@ -1,9 +1,9 @@
 package com.ym.mec.education.service.impl;
 
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ym.mec.education.entity.SysRole;
 import com.ym.mec.education.mapper.SysRoleMapper;
 import com.ym.mec.education.service.ISysRoleService;
-import com.baomidou.mybatisplus.service.impl.ServiceImpl;
 import org.springframework.stereotype.Service;
 
 /**