Bläddra i källkod

重构及调试履职生成

jiawuxian 2 år sedan
förälder
incheckning
50ca18cc5e

+ 24 - 10
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/TaskCreatingServiceImplBase.java

@@ -5,6 +5,7 @@ import cn.hutool.core.date.DateField;
 import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.ObjectUtil;
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.xunmei.common.core.constant.Constants;
@@ -73,16 +74,26 @@ public abstract class TaskCreatingServiceImplBase<M extends BaseMapper<T>, T> ex
     }
 
     /**
-     * 生成周期内所有任务
+     * 一个入口,生成多种组合
      *
-     * @param dateTime
+     * @param execOrgIds 执行机构类型
+     * @param planIds    计划类型
+     * @param date       要生成的周期中的某个日期
      * @param cycle
-     * @return
      */
-    public int buildTaskByCycle(DateTime dateTime, CycleCommonEnum cycle) {
+    public int buildTask(List<Long> execOrgIds, List<Long> planIds, Date date, CycleCommonEnum cycle) {
         return 0;
     }
 
+//    /**
+//     * 生成周期内所有任务
+//     *
+//     * @param dateTime
+//     * @param cycle
+//     * @return
+//     */
+//    public abstract int buildTaskByCycle(DateTime dateTime, CycleCommonEnum cycle);
+
     private Boolean containCurrentCycle(List<SysWorkTime> workTimes, CycleCommonEnum cycle) {
         DateRange range = DateUtils.getStartAndEnd(new Date(), cycle);
         Date start = range.getStartTime();
@@ -103,17 +114,17 @@ public abstract class TaskCreatingServiceImplBase<M extends BaseMapper<T>, T> ex
         }
     }
 
-    public abstract void rebuildDayTask(List<Long> orgIds, SysWorkTime workTime) ;
+    public abstract void rebuildDayTask(List<Long> orgIds, SysWorkTime workTime);
 
-    public abstract void rebuildWeeklyTask(List<Long> orgIds, Date startDate, Date endDate) ;
+    public abstract void rebuildWeeklyTask(List<Long> orgIds, Date startDate, Date endDate);
 
-    public abstract void rebuildMonthTask(List<Long> orgIds, Date startDate, Date endDate) ;
+    public abstract void rebuildMonthTask(List<Long> orgIds, Date startDate, Date endDate);
 
     public abstract void rebuildQuarterTask(List<Long> orgIds, Date startDate, Date endDate);
 
-    public abstract void rebuildHalfYearTask(List<Long> orgIds, Date startDate, Date endDate) ;
+    public abstract void rebuildHalfYearTask(List<Long> orgIds, Date startDate, Date endDate);
 
-    public abstract void rebuildYearTask(List<Long> orgIds, Date startDate, Date endDate) ;
+    public abstract void rebuildYearTask(List<Long> orgIds, Date startDate, Date endDate);
 
     public abstract Boolean updateTaskStatus();
 
@@ -123,7 +134,7 @@ public abstract class TaskCreatingServiceImplBase<M extends BaseMapper<T>, T> ex
      * @param appPlan
      * @return
      */
-    protected List<Long> getPlanOrgIds(AppPlan appPlan) {
+    protected List<Long> getPlanOrgIds(AppPlan appPlan, List<Long> restrictOrgIds) {
         List<Long> orgIds = null;
 //        if (appPlan.getExecType()!=null&&appPlan.getExecType() == 0) {//0机构类型需要安类型去机构里查询所以的机构
         OrgListByTypesConditionEto cond = new OrgListByTypesConditionEto();
@@ -140,6 +151,9 @@ public abstract class TaskCreatingServiceImplBase<M extends BaseMapper<T>, T> ex
 //             orgIds = sysOrgs.stream().map(SysOrg::getId).collect(Collectors.toList());
 ////            orgIds = appPlanService.findExecOrgByPlan(appPlan.getId());
 //        }
+        if (CollectionUtil.isNotEmpty(restrictOrgIds)) {
+            return orgIds.stream().filter(id -> restrictOrgIds.contains(id)).collect(Collectors.toList());
+        }
 
         return orgIds;
     }

+ 13 - 13
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/resumption/controller/TaskController.java

@@ -59,7 +59,7 @@ public class TaskController {
 
         DateTime datetime = new DateTime();
         datetime.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
-        createResumptionTaskBusiness.buildTaskByCycle(datetime, CycleCommonEnum.DAILY);
+        createResumptionTaskBusiness.buildTask(null,null,datetime, CycleCommonEnum.DAILY);
         return AjaxResult.success();
     }
 
@@ -67,7 +67,7 @@ public class TaskController {
     public AjaxResult weekTask() {
         DateTime datetime = new DateTime();
         datetime.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
-        createResumptionTaskBusiness.buildTaskByCycle(datetime, CycleCommonEnum.WEEKLY);
+        createResumptionTaskBusiness.buildTask(null,null,datetime, CycleCommonEnum.WEEKLY);
         return AjaxResult.success();
     }
 
@@ -80,23 +80,23 @@ public class TaskController {
         int day = dateHelper.getDay();
         if (month == 1 && day == 1) {
             //1.1日获取执行周期为每月,每季,每半年,每年的履职计划Plan_cycle=2,3,4,5
-            createResumptionTaskBusiness.buildTaskByCycle(datetime, CycleCommonEnum.MONTHLY);
-            createResumptionTaskBusiness.buildTaskByCycle(datetime, CycleCommonEnum.QUARTERLY);
-            createResumptionTaskBusiness.buildTaskByCycle(datetime, CycleCommonEnum.HALF_YEARLY);
-            createResumptionTaskBusiness.buildTaskByCycle(datetime, CycleCommonEnum.YEARLY);
+            createResumptionTaskBusiness.buildTask(null,null,datetime, CycleCommonEnum.MONTHLY);
+            createResumptionTaskBusiness.buildTask(null,null,datetime, CycleCommonEnum.QUARTERLY);
+            createResumptionTaskBusiness.buildTask(null,null,datetime, CycleCommonEnum.HALF_YEARLY);
+            createResumptionTaskBusiness.buildTask(null,null,datetime, CycleCommonEnum.YEARLY);
         } else if ((month == 4 && day == 1) || (month == 10 && day == 1)) {
             //4.1||10.1日获取执行周期为每月,每季的履职计划Plan_cycle=2,3
-            createResumptionTaskBusiness.buildTaskByCycle(datetime, CycleCommonEnum.MONTHLY);
-            createResumptionTaskBusiness.buildTaskByCycle(datetime, CycleCommonEnum.QUARTERLY);
+            createResumptionTaskBusiness.buildTask(null,null,datetime, CycleCommonEnum.MONTHLY);
+            createResumptionTaskBusiness.buildTask(null,null,datetime, CycleCommonEnum.QUARTERLY);
         } else if (month == 7 && day == 1) {
             //7.1日获取执行周期为每月,每季,每半年的履职计划Plan_cycle=2,3,4
-            createResumptionTaskBusiness.buildTaskByCycle(datetime, CycleCommonEnum.MONTHLY);
-            createResumptionTaskBusiness.buildTaskByCycle(datetime, CycleCommonEnum.QUARTERLY);
-            createResumptionTaskBusiness.buildTaskByCycle(datetime, CycleCommonEnum.HALF_YEARLY);
+            createResumptionTaskBusiness.buildTask(null,null,datetime, CycleCommonEnum.MONTHLY);
+            createResumptionTaskBusiness.buildTask(null,null,datetime, CycleCommonEnum.QUARTERLY);
+            createResumptionTaskBusiness.buildTask(null,null,datetime, CycleCommonEnum.HALF_YEARLY);
 
         } else {
             //其他获取每月履职计划Plan_cycle=2
-            createResumptionTaskBusiness.buildTaskByCycle(datetime, CycleCommonEnum.MONTHLY);
+            createResumptionTaskBusiness.buildTask(null,null,datetime, CycleCommonEnum.MONTHLY);
         }
         return AjaxResult.success();
     }
@@ -115,7 +115,7 @@ public class TaskController {
         //当有周期存在时保持原有接口不变(doTask),否则按照新的接口创建
         CycleCommonEnum cycle=    CycleCommonEnum.getEnum(request.getPlancycle()) ;
         if (cycle != null) {
-            createResumptionTaskBusiness.buildTaskByCycle(datetime, cycle);
+            createResumptionTaskBusiness.buildTask(null,null,datetime, cycle);
         } else {
             //按照新的接口创建
             List<Long> orgIds = request.getOrgIds();

+ 139 - 48
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/resumption/task/ResumptionTaskBusiness.java

@@ -32,6 +32,8 @@ import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Component;
 import org.springframework.transaction.annotation.Transactional;
 
+import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.NotNull;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -61,52 +63,34 @@ public class ResumptionTaskBusiness extends TaskCreatingServiceImplBase<Resumpti
      * @return
      */
 
+    /**
+     * 一个入口,生成多种组合
+     *
+     * @param execOrgIds 执行机构类型
+     * @param planIds    计划类型
+     * @param date       要生成的周期中的某个日期
+     * @param cycle
+     */
     @Override
     @Transactional
-    public int buildTaskByCycle(DateTime dateTime, CycleCommonEnum cycle) {
-        List<AppPlan> AppPlanList = queryPlans(getHangsheOrgIds(), cycle, null);
-        return createTaskByPlan(AppPlanList);
-    }
-
-    /*
-     * 按计划重新生成。为保持通用,参数使用object.只支持同属一个父计划的子计划
-     * */
-    @Override
-    @Transactional
-    public void rebuildCurrentCycleTask(List<Object> plans) {
-        if (CollectionUtils.isEmpty(plans)) {
-            return;
-        }
-
-        List<AppPlan> appPlans = new ArrayList<>();
-        for (Object plan : plans) {
-            if (plan.getClass() == AppPlan.class) {
-                appPlans.add((AppPlan) plan);
-            }
-        }
-        if (CollectionUtils.isEmpty(appPlans)) {
-            return;
+    public int buildTask(List<Long> execOrgIds, List<Long> planIds, @NotNull Date date, @NotNull CycleCommonEnum cycle) {
+        List<Long> hsOrgIds = null;
+        if (CollectionUtils.isEmpty(execOrgIds)) {
+            hsOrgIds = getHangsheOrgIds();
+        } else {
+            hsOrgIds = remoteOrgService.selectParentHs(execOrgIds, SecurityConstants.INNER).stream()
+                    .map(SysOrg::getId)
+                    .collect(Collectors.toList());
         }
 
-        AppPlan plan = appPlans.get(0);
-        CycleCommonEnum cycle = CycleCommonEnum.getEnum(plan.getPlanCycle());
-        DateRange range = DateUtils.getStartAndEnd(new Date(), cycle);
+        List<AppPlan> appPlanList = queryPlans(hsOrgIds, cycle, null, planIds);
 
-        List<Resumption> resumptionList = queryTask(range.getStartTime(), cycle, null, appPlans.stream().map(AppPlan::getId).collect(Collectors.toList()));
-        List<Long> deleteIds = resumptionList.stream()
-                .filter(r -> (ObjectUtil.equal(r.getStatus(), 1) || ObjectUtil.equal(r.getStatus(), 2)))
-                .map(Resumption::getId).collect(Collectors.toList());
-        if (CollectionUtils.isNotEmpty(deleteIds)) {
-            baseMapper.deleteBatchIds(deleteIds);
-        }
-
-        createTaskByPlan(appPlans);
+        return buildTask(execOrgIds, appPlanList, date);
     }
 
-
-    private int createTaskByPlan(List<AppPlan> appPlanList) {
+    public int buildTask(List<Long> execOrgIds, @NotEmpty List<AppPlan> plans, @NotNull Date date) {
         List<Resumption> resumptions = new ArrayList<>();
-        for (AppPlan appPlan : appPlanList) {
+        for (AppPlan appPlan : plans) {
             //获取履职计划中对应的检查要点
             List<AppRulePointTaskVo> pointList = appRulePointService.findPointByPlan(appPlan.getId());
             if (pointList.size() <= 0) {//没有检查项不生成履职任务
@@ -114,21 +98,23 @@ public class ResumptionTaskBusiness extends TaskCreatingServiceImplBase<Resumpti
                 continue;
             }
 
-            List<Long> orgIdList = getPlanOrgIds(appPlan);
-            if (CollectionUtils.isEmpty(orgIdList)) {//没有检查项不生成履职任务
-                log.info("error:该计划ID:{}没有执行机构", appPlan.getId());
-                continue;
-            }
             //获取履职角色
             List<Long> roleIds = appPlanService.findRoleByPlan(appPlan.getId());
             if (CollectionUtils.isEmpty(roleIds)) {//没有检查项不生成履职任务
                 log.info("error:该计划ID:{}没有履职角色", appPlan.getId());
                 continue;
             }
+
+            List<Long> orgIds = getPlanOrgIds(appPlan, execOrgIds);
+            if (CollectionUtils.isEmpty(orgIds)) {
+                log.info("error:该计划ID:{}没有执行机构", appPlan.getId());
+                continue;
+            }
+
             CycleCommonEnum cycleCommonEnum = CycleCommonEnum.getEnum(appPlan.getPlanCycle());
-            DateRange range = DateUtils.getStartAndEnd(new Date(), cycleCommonEnum);
-            Map<Long, SysWorkTime> workTimes = orgSingleWorkTimeMap(new Date(), cycleCommonEnum, orgIdList);
-            for (Long orgId : orgIdList) {
+            DateRange range = DateUtils.getStartAndEnd(date, cycleCommonEnum);
+            Map<Long, SysWorkTime> workTimes = orgSingleWorkTimeMap(new Date(), cycleCommonEnum, orgIds);
+            for (Long orgId : orgIds) {
                 if (!workTimes.containsKey(orgId) || ObjectUtil.isNull(workTimes.get(orgId)) || ObjectUtil.notEqual(workTimes.get(orgId).getIsEnable(), 1L)) {
                     continue;
                 }
@@ -154,6 +140,108 @@ public class ResumptionTaskBusiness extends TaskCreatingServiceImplBase<Resumpti
         }
     }
 
+//    @Override
+//    @Transactional
+//    public int buildTaskByCycle(DateTime dateTime, CycleCommonEnum cycle) {
+//        List<AppPlan> AppPlanList = queryPlans(getHangsheOrgIds(), cycle, null, null);
+//        return createTaskByPlan(AppPlanList);
+//    }
+
+    /*
+     * 按计划重新生成。为保持通用,参数使用object.只支持同属一个父计划的子计划
+     * */
+    @Override
+    @Transactional
+    public void rebuildCurrentCycleTask(List<Object> plans) {
+        if (CollectionUtils.isEmpty(plans)) {
+            return;
+        }
+        List<Long> hsOrgIds = getHangsheOrgIds();
+        List<AppPlan> appPlans = new ArrayList<>();
+        for (Object plan : plans) {
+            if (plan.getClass() != AppPlan.class) {
+                continue;
+            }
+
+            AppPlan p = (AppPlan) plan;
+            if (!hsOrgIds.contains(p.getPlanOfOrgId())) {
+                continue;
+            }
+            appPlans.add(p);
+        }
+
+        if (CollectionUtils.isEmpty(appPlans)) {
+            return;
+        }
+
+        AppPlan plan = appPlans.get(0);
+        Date workDate = new Date();
+        CycleCommonEnum cycle = CycleCommonEnum.getEnum(plan.getPlanCycle());
+        DateRange range = DateUtils.getStartAndEnd(workDate, cycle);
+
+        List<Resumption> resumptionList = queryTask(range.getStartTime(), cycle, null, appPlans.stream().map(AppPlan::getId).collect(Collectors.toList()));
+        List<Long> deleteIds = resumptionList.stream()
+                .filter(r -> (ObjectUtil.equal(r.getStatus(), 1) || ObjectUtil.equal(r.getStatus(), 2)))
+                .map(Resumption::getId).collect(Collectors.toList());
+        if (CollectionUtils.isNotEmpty(deleteIds)) {
+            baseMapper.deleteBatchIds(deleteIds);
+        }
+
+        buildTask(null, appPlans, workDate);
+
+    }
+
+
+//    private int createTaskByPlan(List<AppPlan> appPlanList) {
+//        List<Resumption> resumptions = new ArrayList<>();
+//        for (AppPlan appPlan : appPlanList) {
+//            //获取履职计划中对应的检查要点
+//            List<AppRulePointTaskVo> pointList = appRulePointService.findPointByPlan(appPlan.getId());
+//            if (pointList.size() <= 0) {//没有检查项不生成履职任务
+//                log.info("error:该计划ID:" + appPlan.getId() + "没有检查项");
+//                continue;
+//            }
+//
+//            List<Long> orgIdList = getPlanOrgIds(appPlan, null);
+//            if (CollectionUtils.isEmpty(orgIdList)) {//没有检查项不生成履职任务
+//                log.info("error:该计划ID:{}没有执行机构", appPlan.getId());
+//                continue;
+//            }
+//            //获取履职角色
+//            List<Long> roleIds = appPlanService.findRoleByPlan(appPlan.getId());
+//            if (CollectionUtils.isEmpty(roleIds)) {//没有检查项不生成履职任务
+//                log.info("error:该计划ID:{}没有履职角色", appPlan.getId());
+//                continue;
+//            }
+//            CycleCommonEnum cycleCommonEnum = CycleCommonEnum.getEnum(appPlan.getPlanCycle());
+//            DateRange range = DateUtils.getStartAndEnd(new Date(), cycleCommonEnum);
+//            Map<Long, SysWorkTime> workTimes = orgSingleWorkTimeMap(new Date(), cycleCommonEnum, orgIdList);
+//            for (Long orgId : orgIdList) {
+//                if (!workTimes.containsKey(orgId) || ObjectUtil.isNull(workTimes.get(orgId)) || ObjectUtil.notEqual(workTimes.get(orgId).getIsEnable(), 1L)) {
+//                    continue;
+//                }
+//                SysWorkTime workTime = workTimes.get(orgId);
+//
+//                List<Resumption> tasks;
+//                if (ObjectUtil.equal(CycleCommonEnum.DAILY.getCode(), appPlan.getPlanCycle())) {
+//                    tasks = buildResumptions(appPlan, orgId, workTime);
+//                } else {
+//                    tasks = buildResumptions(appPlan, orgId, range.getStartTime(), range.getEndTime(), 0L);
+//                }
+//
+//                if (CollectionUtils.isNotEmpty(tasks)) {
+//                    resumptions.addAll(tasks);
+//                }
+//            }
+//        }
+//
+//        if (this.saveBatch(resumptions)) {
+//            return resumptions.size();
+//        } else {
+//            return 0;
+//        }
+//    }
+
     @Override
     public void rebuildDayTask(List<Long> orgIds, SysWorkTime workTime) {
         rebuildTask(orgIds, workTime.getYmdDate(), workTime.getYmdDate(), CycleCommonEnum.DAILY, workTime);
@@ -224,7 +312,7 @@ public class ResumptionTaskBusiness extends TaskCreatingServiceImplBase<Resumpti
             List<Long> hsOrgIds = remoteOrgService.selectParentHs(ListUtil.toList(orgId), SecurityConstants.INNER)
                     .stream().map(SysOrg::getId)
                     .collect(Collectors.toList());
-            List<AppPlan> listPlans = queryPlans(hsOrgIds, cycle, ListUtil.toList(org.getType()));
+            List<AppPlan> listPlans = queryPlans(hsOrgIds, cycle, ListUtil.toList(org.getType()), null);
             if (CollectionUtils.isEmpty(listPlans)) {
                 continue;
             }
@@ -355,7 +443,7 @@ public class ResumptionTaskBusiness extends TaskCreatingServiceImplBase<Resumpti
      * @param cycle
      * @return
      */
-    private List<AppPlan> queryPlans(List<Long> planOfOrgId, CycleCommonEnum cycle, List<Integer> execOrgTypes) {
+    private List<AppPlan> queryPlans(List<Long> planOfOrgId, CycleCommonEnum cycle, List<Integer> execOrgTypes, List<Long> planIds) {
         if (CollectionUtils.isEmpty(planOfOrgId)) {
             return new ArrayList<>();
         }
@@ -367,6 +455,9 @@ public class ResumptionTaskBusiness extends TaskCreatingServiceImplBase<Resumpti
         if (CollectionUtils.isNotEmpty(execOrgTypes)) {
             qw.lambda().in(AppPlan::getExecOrgType, execOrgTypes);
         }
+        if (CollectionUtils.isNotEmpty(planIds)) {
+            qw.lambda().in(AppPlan::getId, planIds);
+        }
         List<AppPlan> listPlans = appPlanMapper.selectList(qw);
 
         return listPlans;