瀏覽代碼

合同续约-流向条件

jzh 1 年之前
父節點
當前提交
581e57de2b

+ 56 - 25
zjugis-business/src/main/java/com/zjugis/business/flow/contractRenew/event/ContractRenewEvent.java

@@ -4,7 +4,6 @@ import cn.hutool.core.collection.CollectionUtil;
 import com.zjugis.business.converter.contractRenew.ContractRenewConvert;
 import com.zjugis.business.flow.contractRenew.entity.ContractRenewDO;
 import com.zjugis.business.flow.contractRenew.service.ContractRenewService;
-import com.zjugis.framework.common.pojo.CommonResult;
 import com.zjugis.framework.common.util.date.LocalDateTimeUtils;
 import com.zjugis.framework.workflow.exception.BusinessException;
 import com.zjugis.framework.workflow.model.BaseController;
@@ -14,15 +13,15 @@ import com.zjugis.module.adm.api.staff.StaffApi;
 import com.zjugis.module.adm.api.staff.dto.StaffRecordsDTO;
 import com.zjugis.module.system.api.dept.DeptApi;
 import com.zjugis.module.system.api.dept.DeptLeaderApi;
-import com.zjugis.module.system.api.dept.dto.DeptLeaderRespDTO;
-import com.zjugis.module.system.api.dept.dto.DeptRespDTO;
+import com.zjugis.module.system.api.dept.PostApi;
+import com.zjugis.module.system.api.dept.dto.PostRespDTO;
 import com.zjugis.module.system.api.user.AdminUserApi;
 import com.zjugis.module.system.api.user.dto.AdminUserRespDTO;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
@@ -31,6 +30,7 @@ import javax.annotation.Resource;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
+import java.util.stream.Collectors;
 
 import static com.zjugis.business.constants.FlowStatusConstants.*;
 import static com.zjugis.framework.common.util.collection.CollectionUtils.convertSet;
@@ -59,15 +59,18 @@ public class ContractRenewEvent extends BaseController {
 
     @Resource
     private ContractRenewService contractRenewService;
-    @Autowired
+    @Resource
     WorkflowClient workflowClient;
 
-    @Autowired
+
+    @Resource
+    private PostApi postApi;
+    @Resource
     DeptApi deptApi;
     @Resource
     private DeptLeaderApi deptLeaderApi;
 
-    @Autowired
+    @Resource
     AdminUserApi adminUserApi;
     @Resource
     private StaffApi staffApi;
@@ -271,29 +274,57 @@ public class ContractRenewEvent extends BaseController {
 
 
     /**
-     * 转到分管领导
+     * 判断是经理还是普通员工
+     * 1经理  2员工
      */
-    @PostMapping("/to-dept-manager-leader")
-    public String toDeptManagerLeader(String flowInstanceId) {
+    @PostMapping("/post/{type}")
+    public String department(@ParamModel Map flowInstance, @PathVariable String type) {
         try {
-            if (StringUtils.isNotBlank(flowInstanceId)) {
-                ContractRenewDO entity = contractRenewService.findByInstanceId(flowInstanceId);
-                List<Map<String, String>> userMaps = new ArrayList<>();
-                if (StringUtils.isNotBlank(entity.getDeptId())) {
-                    DeptLeaderRespDTO deptLeaderRespDTO = deptLeaderApi.getDeptLeaderByDeptId(entity.getDeptId()).getCheckedData();
-                    if (deptLeaderRespDTO != null && StringUtils.isNotBlank(deptLeaderRespDTO.getUserId())) {
-                        HashMap<String, String> map = new HashMap<>();
-                        map.put("id", deptLeaderRespDTO.getUserId());
-                        userMaps.add(map);
+            String flowInstanceId = flowInstance.get("id").toString();
+
+
+            ContractRenewDO entity = contractRenewService.findByInstanceId(flowInstanceId);
+            List<PostRespDTO> posts = postApi.getPostByUser(entity.getUserId()).getCheckedData();
+            List<Long> postIds = posts.stream().map(PostRespDTO::getId).collect(Collectors.toList());
+            String flag = "false";
+            switch (type) {
+                case "1":
+                    if (checkExist(postIds)) {
+                        flag = "true";
                     }
+                    break;
+
+
+                case "2":
+                    if (!checkExist(postIds)) {
+                        flag = "true";
+                    }
+                    break;
+
+                default:
+                    return flag;
+            }
+
+            return flag;
+
+
+        } catch (Exception ex) {
+            return error(ex.getMessage(), ErrorCode.DEFAULT);
+        }
+    }
+
+    private boolean checkExist(List<Long> postIds) {
+
+        boolean flag = false;
+        if (CollectionUtil.isNotEmpty(postIds)) {
+            for (Long id : postIds) {
+                String s = String.valueOf(id);
+                if (s.equals(deptLeader) || s.equals(saleLeader)) {
+                    flag = true;
+                    break;
                 }
-                return ok(userMaps);
-            } else {
-                throw new BusinessException("找不到流程id");
             }
-        } catch (Exception e) {
-            log.error(e.getMessage(), e);
-            throw new BusinessException("执行事件出错,请联系管理员!");
         }
+        return flag;
     }
 }