Quellcode durchsuchen

按履职计划重新生成任务

jiawuxian vor 2 Jahren
Ursprung
Commit
85d107f0fa

+ 7 - 0
project_data/sql/0.0.2/soc/soc.sql

@@ -1108,6 +1108,13 @@ END IF;
 
     END IF;
 
+	-- 履职任务表存储父计划id及创建任务计划id
+    IF
+        NOT EXISTS ( SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = DATABASE () and TABLE_NAME = 'core_resumption' AND COLUMN_NAME = 'parent_plan_id' ) THEN
+        ALTER TABLE `core_resumption` 
+			CHANGE COLUMN `plan_id` `parent_plan_id` bigint NULL DEFAULT NULL COMMENT '父计划id,没有就与plan_id一致' AFTER `ymd_minute`,
+			ADD COLUMN `plan_id` bigint NULL COMMENT '生成任务的计划id' AFTER `parent_plan_id`;
+    END IF;
 
 
 	ALTER TABLE `core_protection` MODIFY COLUMN `device_id` BIGINT NULL DEFAULT NULL COMMENT '设备ID' AFTER `id`;

+ 106 - 20
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/TaskCreatingServiceImplBase.java

@@ -4,16 +4,23 @@ import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.date.DateField;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.ObjectUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.xunmei.common.core.constant.Constants;
 import com.xunmei.common.core.constant.SecurityConstants;
 import com.xunmei.common.core.domain.DateRange;
+import com.xunmei.common.core.domain.R;
 import com.xunmei.common.core.domain.worktime.dto.WorkTimeDto;
+import com.xunmei.common.core.enums.OrgTypeEnum;
 import com.xunmei.common.core.event.WorkTimeChangeEvent;
 import com.xunmei.common.core.utils.DateUtils;
 import com.xunmei.common.core.enums.CycleCommonEnum;
+import com.xunmei.core.resumption.domain.AppPlan;
+import com.xunmei.system.api.Eto.OrgListByTypesConditionEto;
+import com.xunmei.system.api.RemoteOrgService;
 import com.xunmei.system.api.RemoteWorkTimeService;
 import com.xunmei.common.core.domain.worktime.domain.SysWorkTime;
+import com.xunmei.system.api.domain.SysOrg;
 import org.springframework.beans.factory.annotation.Autowired;
 
 import java.util.*;
@@ -23,6 +30,9 @@ public abstract class TaskCreatingServiceImplBase<M extends BaseMapper<T>, T> ex
     @Autowired
     private RemoteWorkTimeService workTimeService;
 
+    @Autowired
+    private RemoteOrgService orgService;
+
     public List<SysWorkTime> selectWorkTimeList(Date now, CycleCommonEnum cycle, WorkTimeChangeEvent event) {
         return selectWorkTimeList(now, cycle, event.getOrgIds());
     }
@@ -39,14 +49,15 @@ public abstract class TaskCreatingServiceImplBase<M extends BaseMapper<T>, T> ex
         workTimeDto.setOrgIdList(orgIds);
         workTimeDto.setStartTime(startTime);
         workTimeDto.setEndTime(endTime);
+
 //
         return workTimeService.findWorkTimeByRange(workTimeDto, SecurityConstants.FROM_SOURCE).getData();
     }
 
     public Map<Long, Boolean> orgWorkTimeStatusMap(Date now, CycleCommonEnum cycle, List<Long> orgIds) {
         List<SysWorkTime> times = selectWorkTimeList(now, cycle, orgIds);
-        if(CollectionUtil.isEmpty(times)){
-            return  new HashMap<>();
+        if (CollectionUtil.isEmpty(times)) {
+            return new HashMap<>();
         }
         Map<Long, List<SysWorkTime>> map = times.stream()
                 .filter(t -> ObjectUtil.equal(t.getIsEnable(), 1L))
@@ -58,38 +69,59 @@ public abstract class TaskCreatingServiceImplBase<M extends BaseMapper<T>, T> ex
         return r;
     }
 
+    public Map<Long, SysWorkTime> orgSingleWorkTimeMap(Date now, CycleCommonEnum cycle, List<Long> orgIds) {
+        List<SysWorkTime> times = selectWorkTimeList(now, cycle, orgIds);
+        if (CollectionUtil.isEmpty(times)) {
+            return new HashMap<>();
+        }
+        Map<Long, List<SysWorkTime>> map = times.stream()
+                .filter(t -> ObjectUtil.equal(t.getIsEnable(), 1L))
+                .collect(Collectors.groupingBy(t -> t.getOrgId()));
+        Map<Long, SysWorkTime> r = new HashMap<>();
+        map.forEach((k, v) -> {
+            r.put(k, CollectionUtil.isNotEmpty(v) ? v.get(0) : null);
+        });
+        return r;
+    }
+
     public void rebuildTask(WorkTimeChangeEvent timeChangeEvent) {
-        if(containCurrentCycle(timeChangeEvent.getDataList(),CycleCommonEnum.DAILY)){
-            SysWorkTime today= timeChangeEvent.getDataList().stream().filter(d->d.getYmdDate().equals (DateUtil.beginOfDay(new Date()) )).findFirst().get();
+        if (containCurrentCycle(timeChangeEvent.getDataList(), CycleCommonEnum.DAILY)) {
+            SysWorkTime today = timeChangeEvent.getDataList().stream().filter(d -> d.getYmdDate().equals(DateUtil.beginOfDay(new Date()))).findFirst().get();
             rebuildDayTask(timeChangeEvent.getOrgIds(), today);
         }
 
-        if(containCurrentCycle(timeChangeEvent.getDataList(),CycleCommonEnum.WEEKLY)){
+        if (containCurrentCycle(timeChangeEvent.getDataList(), CycleCommonEnum.WEEKLY)) {
             DateRange range = DateUtils.getStartAndEnd(new Date(), CycleCommonEnum.WEEKLY);
-            rebuildWeeklyTask(timeChangeEvent.getOrgIds(),range.getStartTime(),range.getEndTime());
+            rebuildWeeklyTask(timeChangeEvent.getOrgIds(), range.getStartTime(), range.getEndTime());
         }
 
-        if(containCurrentCycle(timeChangeEvent.getDataList(),CycleCommonEnum.MONTHLY)){
+        if (containCurrentCycle(timeChangeEvent.getDataList(), CycleCommonEnum.MONTHLY)) {
             DateRange range = DateUtils.getStartAndEnd(new Date(), CycleCommonEnum.MONTHLY);
-            rebuildMonthTask(timeChangeEvent.getOrgIds(),range.getStartTime(),range.getEndTime());
+            rebuildMonthTask(timeChangeEvent.getOrgIds(), range.getStartTime(), range.getEndTime());
         }
 
-        if(containCurrentCycle(timeChangeEvent.getDataList(),CycleCommonEnum.QUARTERLY)){
+        if (containCurrentCycle(timeChangeEvent.getDataList(), CycleCommonEnum.QUARTERLY)) {
             DateRange range = DateUtils.getStartAndEnd(new Date(), CycleCommonEnum.QUARTERLY);
-            rebuildQuarterTask(timeChangeEvent.getOrgIds(),range.getStartTime(),range.getEndTime());
+            rebuildQuarterTask(timeChangeEvent.getOrgIds(), range.getStartTime(), range.getEndTime());
         }
 
-        if(containCurrentCycle(timeChangeEvent.getDataList(),CycleCommonEnum.HALF_YEARLY)){
+        if (containCurrentCycle(timeChangeEvent.getDataList(), CycleCommonEnum.HALF_YEARLY)) {
             DateRange range = DateUtils.getStartAndEnd(new Date(), CycleCommonEnum.HALF_YEARLY);
-            rebuildHalfYearTask(timeChangeEvent.getOrgIds(),range.getStartTime(),range.getEndTime());
+            rebuildHalfYearTask(timeChangeEvent.getOrgIds(), range.getStartTime(), range.getEndTime());
         }
 
-        if(containCurrentCycle(timeChangeEvent.getDataList(),CycleCommonEnum.YEARLY)){
+        if (containCurrentCycle(timeChangeEvent.getDataList(), CycleCommonEnum.YEARLY)) {
             DateRange range = DateUtils.getStartAndEnd(new Date(), CycleCommonEnum.YEARLY);
-            rebuildYearTask(timeChangeEvent.getOrgIds(),range.getStartTime(),range.getEndTime());
+            rebuildYearTask(timeChangeEvent.getOrgIds(), range.getStartTime(), range.getEndTime());
         }
     }
 
+    /*
+     * 按计划重新生成。为保持通用,参数使用object
+     * */
+    public void rebuildCurrentCycleTask(List<Object> plans) {
+    }
+
     private Boolean containCurrentCycle(List<SysWorkTime> workTimes, CycleCommonEnum cycle) {
         DateRange range = DateUtils.getStartAndEnd(new Date(), cycle);
         Date start = range.getStartTime();
@@ -110,15 +142,69 @@ public abstract class TaskCreatingServiceImplBase<M extends BaseMapper<T>, T> ex
         }
     }
 
-    public  void rebuildDayTask(List<Long> orgIds, SysWorkTime workTime){}
+    public void rebuildDayTask(List<Long> orgIds, SysWorkTime workTime) {
+    }
 
-    public  void rebuildWeeklyTask(List<Long> orgIds, Date startDate, Date endDate){}
+    public void rebuildWeeklyTask(List<Long> orgIds, Date startDate, Date endDate) {
+    }
 
-    public  void rebuildMonthTask(List<Long> orgIds, Date startDate, Date endDate){}
+    public void rebuildMonthTask(List<Long> orgIds, Date startDate, Date endDate) {
+    }
+
+    public void rebuildQuarterTask(List<Long> orgIds, Date startDate, Date endDate) {
+    }
+
+    public void rebuildHalfYearTask(List<Long> orgIds, Date startDate, Date endDate) {
+    }
+
+    public void rebuildYearTask(List<Long> orgIds, Date startDate, Date endDate) {
+    }
+
+    /**
+     * 获取计划的执行机构id
+     *
+     * @param appPlan
+     * @return
+     */
+    protected List<Long> getPlanOrgIds(AppPlan appPlan) {
+        List<Long> orgIds = null;
+//        if (appPlan.getExecType()!=null&&appPlan.getExecType() == 0) {//0机构类型需要安类型去机构里查询所以的机构
+        OrgListByTypesConditionEto cond = new OrgListByTypesConditionEto();
+        cond.setOrgId(appPlan.getPlanOfOrgId());
+        cond.setOrgTypes(Arrays.asList(appPlan.getExecOrgType().toString()));
+        R<List<SysOrg>> r = orgService.listByTypes(cond);
+        if (ObjectUtil.isNull(r) || ObjectUtil.isEmpty(r.getData())) {
+            return new ArrayList<>();
+        }
+        orgIds = r.getData().stream().map(i -> i.getId()).collect(Collectors.toList());
+//        }
+//        else {
+//            List<SysOrg> sysOrgs = orgService.selectByOrgType(appPlan.getExecOrgType(), SecurityConstants.INNER);
+//             orgIds = sysOrgs.stream().map(SysOrg::getId).collect(Collectors.toList());
+////            orgIds = appPlanService.findExecOrgByPlan(appPlan.getId());
+//        }
+
+        return orgIds;
+    }
+
+//    protected List<SysOrg> getPlanOrgs(AppPlan appPlan) {
+//        List<Long> orgIds = null;
+//        if (appPlan.getExecType() == 0) {//0机构类型需要安类型去机构里查询所以的机构
+//            orgIds = orgService.findListByOrgType(appPlan.getExecOrgType(), SecurityConstants.INNER).getData();
+//        } else {
+//            orgIds = appPlanService.findExecOrgByPlan(appPlan.getId());
+//        }
+//
+//        return orgService.listByIds(orgIds, SecurityConstants.INNER).getData();
+//    }
 
-    public  void rebuildQuarterTask(List<Long> orgIds, Date startDate, Date endDate){}
+    protected List<Long> getHangsheOrgIds() {
+        R<List<Long>> allHangshe = orgService.findListByOrgType(OrgTypeEnum.HANG_SHE.getCode(), SecurityConstants.INNER);
+        if (ObjectUtil.isNull(allHangshe) || ObjectUtil.isEmpty(allHangshe.getData())) {
+            return new ArrayList<>();
+        }
 
-    public  void rebuildHalfYearTask(List<Long> orgIds, Date startDate, Date endDate){}
+        return allHangshe.getData();
+    }
 
-    public  void rebuildYearTask(List<Long> orgIds, Date startDate, Date endDate){}
 }

+ 1 - 0
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/resumption/domain/Resumption.java

@@ -93,6 +93,7 @@ public class Resumption extends BaseEntity {
     private AppPlan plan;
 
 
+    private Long parentPlanId;
     private Long planId;
     private Date startTime;
     private Date endTime;

+ 19 - 5
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/resumption/service/impl/ResumptionRecordServiceImpl.java

@@ -13,11 +13,13 @@ import com.xunmei.common.core.exception.ServiceException;
 import com.xunmei.common.core.utils.DateHelper;
 import com.xunmei.common.core.vo.IdNameVo;
 import com.xunmei.common.core.web.page.TableDataInfo;
+import com.xunmei.core.resumption.domain.AppPlanToRole;
 import com.xunmei.core.resumption.domain.Resumption;
 import com.xunmei.core.resumption.dto.resumptionRecord.ResumptionNFCDto;
 import com.xunmei.core.resumption.dto.resumptionRecord.ResumptionRecordPageDto;
 import com.xunmei.core.resumption.dto.resumptionRecord.ResumptionRoleDto;
 import com.xunmei.core.resumption.mapper.AppPlanMapper;
+import com.xunmei.core.resumption.mapper.AppPlanToRoleMapper;
 import com.xunmei.core.resumption.mapper.AppResumptionDataRemarkimgMapper;
 import com.xunmei.core.resumption.mapper.ResumptionRecordMapper;
 import com.xunmei.core.resumption.service.AppPlanService;
@@ -69,6 +71,9 @@ public class ResumptionRecordServiceImpl extends ServiceImpl<ResumptionRecordMap
     @Resource
     private RemoteDictDataService remoteDictDataService;
 
+    @Resource
+    private AppPlanToRoleMapper appPlanToRoleMapper;
+
     @Override
     public TableDataInfo selectList(ResumptionRecordPageDto pageDto) {
         Page<ResumptionRecordPageVo> page = pageDto.getPageDto();
@@ -225,9 +230,15 @@ public class ResumptionRecordServiceImpl extends ServiceImpl<ResumptionRecordMap
         List<IdNameVo> orgNames = orgService.getParentName(list.stream()
                         .map(i -> i.getOrgId()).distinct().collect(Collectors.toList()), SecurityConstants.INNER)
                 .getData();
+
+
+        LambdaQueryWrapper<AppPlanToRole> prWrapper = new LambdaQueryWrapper<>();
+        prWrapper.in(AppPlanToRole::getPlanId, list.stream().map(ResumptionRecordPageVo::getPlanId).distinct().collect(Collectors.toList()));
+        List<AppPlanToRole> prMapper = appPlanToRoleMapper.selectList(prWrapper);
+
         List<IdNameVo> roleNames = roleService.getNames(RoleConditionEto
                 .builder()
-                .ids(list.stream().map(i -> i.getRoleId()).distinct().collect(Collectors.toList())).build());
+                .ids(prMapper.stream().map(i -> i.getRoleId()).distinct().collect(Collectors.toList())).build());
         list.stream().filter(pageVo -> ObjectUtil.equal(pageVo.getStatus(), "1")).forEach(pageVo -> pageVo.setSubmitter(null));
 
         //List<Org> orgList = orgService.all();
@@ -244,10 +255,13 @@ public class ResumptionRecordServiceImpl extends ServiceImpl<ResumptionRecordMap
 //            if (plan.isPresent()) {
 //                vo.setPlanName(plan.get().getName());
 //            }
+            List<Long> roleIds = prMapper.stream().filter(pr -> ObjectUtil.equal(pr.getPlanId(), vo.getPlanId()))
+                    .map(AppPlanToRole::getRoleId)
+                    .collect(Collectors.toList());
 
-            Optional<IdNameVo> role = roleNames.stream().filter(r -> r.getId().equals(vo.getRoleId())).findFirst();
-            if (role.isPresent()) {
-                vo.setRoleName(role.get().getName());
+            List<IdNameVo> roles = roleNames.stream().filter(r -> roleIds.contains(r.getId())).collect(Collectors.toList());
+            if (CollectionUtil.isNotEmpty(roles)) {
+                vo.setRoleName(StringUtils.join(roles.stream().map(IdNameVo::getName).collect(Collectors.toList()), ","));
             }
         }
     }
@@ -346,7 +360,7 @@ public class ResumptionRecordServiceImpl extends ServiceImpl<ResumptionRecordMap
         Map<String, SysDictData> dicts = remoteDictDataService.selectDictByeType("resumption_status", SecurityConstants.INNER)
                 .stream().collect(Collectors.toMap(SysDictData::getDictValue, v -> v));
         List<ResumptionRecordPageVo> limit = data.stream().limit(10000).collect(Collectors.toList());
-        int index=1;
+        int index = 1;
         for (ResumptionRecordPageVo r : limit) {
             r.setIndex(index++);
             if (dicts.containsKey(r.getStatus())) {

+ 2 - 1
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/resumption/service/impl/ResumptionServiceImpl.java

@@ -139,7 +139,8 @@ public class ResumptionServiceImpl extends ServiceImpl<ResumptionMapper, Resumpt
             resumption.setYmdHour(Long.valueOf(ymd.getHour()));
             resumption.setYmdQuarter(Long.valueOf(ymd.getQuarter()));
             resumption.setYmdHalfyear(Long.valueOf(ymd.getHalfyear()));
-            resumption.setPlanId((ObjectUtil.equal(appPlan.getParentId(), -1L) || ObjectUtil.isNull(appPlan.getParentId())) ? appPlan.getId() : appPlan.getParentId());
+            resumption.setParentPlanId((ObjectUtil.equal(appPlan.getParentId(), -1L) || ObjectUtil.isNull(appPlan.getParentId())) ? appPlan.getId() : appPlan.getParentId());
+            resumption.setPlanId(appPlan.getId());
             resumption.setOrgId(orgId);
             resumption.setType(type.getValue());
             resumption.setRoleId(roleId);

+ 133 - 64
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/resumption/task/RebuildResumptionTaskBusiness.java

@@ -4,14 +4,18 @@ import cn.hutool.core.collection.ListUtil;
 import cn.hutool.core.date.DateField;
 import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.io.unit.DataUnit;
 import cn.hutool.core.util.NumberUtil;
 import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.google.common.collect.Lists;
 import com.xunmei.common.core.constant.SecurityConstants;
+import com.xunmei.common.core.domain.DateRange;
 import com.xunmei.common.core.domain.worktime.domain.SysWorkTime;
 import com.xunmei.common.core.enums.CycleCommonEnum;
+import com.xunmei.common.core.utils.DateUtils;
+import com.xunmei.common.core.utils.ResumptionType;
 import com.xunmei.common.core.utils.Ymd;
 import com.xunmei.core.TaskCreatingServiceImplBase;
 import com.xunmei.core.resumption.domain.AppPlan;
@@ -20,101 +24,157 @@ import com.xunmei.core.resumption.domain.Resumption;
 import com.xunmei.core.resumption.mapper.AppPlanMapper;
 import com.xunmei.core.resumption.mapper.AppPlanToRoleMapper;
 import com.xunmei.core.resumption.mapper.ResumptionMapper;
+import com.xunmei.core.resumption.service.AppPlanService;
+import com.xunmei.core.resumption.service.IAppRulePointService;
+import com.xunmei.core.resumption.vo.AppRulePointTaskVo;
 import com.xunmei.system.api.RemoteOrgService;
 import com.xunmei.system.api.domain.SysOrg;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.*;
 import java.util.stream.Collectors;
 
 @Component
+@Slf4j
 public class RebuildResumptionTaskBusiness extends TaskCreatingServiceImplBase<ResumptionMapper, Resumption> {
     @Autowired
     private AppPlanMapper appPlanMapper;
 
     @Autowired
-    private AppPlanToRoleMapper appPlanToRoleMapper;
+    private RemoteOrgService remoteOrgService;
 
     @Autowired
-    private RemoteOrgService remoteOrgService;
+    private IAppRulePointService appRulePointService;
+
+    @Autowired
+    private AppPlanService appPlanService;
 
+    /*
+     * 按计划重新生成。为保持通用,参数使用object.只支持同属一个父计划的子计划
+     * */
     @Override
-    public void rebuildDayTask(List<Long> orgIds, SysWorkTime workTime) {
-        try {
-            List<Resumption> resumptionList = queryTask(workTime.getYmdDate(), CycleCommonEnum.DAILY, orgIds);
-            List<Resumption> resumptionListYlz = resumptionList.stream().filter(item -> item.getStatus() == 3).collect(Collectors.toList());
-            if (CollectionUtils.isNotEmpty(resumptionList)) {
-                //取出未履职的数据(待履职,进行中)
-                List<Resumption> resumptionListWlz = resumptionList.stream().filter(item -> item.getStatus() == 1 || item.getStatus() == 2).collect(Collectors.toList());
-                //删除这些数据
-                if (CollectionUtils.isNotEmpty(resumptionListWlz)) {
-                    baseMapper.deleteBatchIds(resumptionListWlz.stream().map(Resumption::getId).collect(Collectors.toList()));
-                }
+    @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;
+        }
+
+        AppPlan plan = appPlans.get(0);
+        CycleCommonEnum cycle = CycleCommonEnum.getEnum(plan.getPlanCycle());
+        DateRange range = DateUtils.getStartAndEnd(new Date(), cycle);
 
-            //营业重新生成任务
-            if (workTime.getIsEnable() == 1) {
-                List<Long> hsOrgIds = remoteOrgService.selectParentHs(orgIds, SecurityConstants.INNER)
-                        .stream().map(SysOrg::getId)
-                        .collect(Collectors.toList());
-                List<AppPlan> listPlans = queryPlans(hsOrgIds, CycleCommonEnum.DAILY,new ArrayList<>());
-                //通过计划id获取计划关系的角色
-                if (CollectionUtils.isNotEmpty(listPlans)) {
-                    List<Long> planIds = listPlans.stream().map(AppPlan::getId).collect(Collectors.toList());
-                    List<AppPlanToRole> appPlanToRoles = appPlanToRoleMapper.selectList(new QueryWrapper<AppPlanToRole>().lambda().in(AppPlanToRole::getPlanId, planIds));
-                    List<Resumption> newResumptionList = new ArrayList<>();
-                    for (AppPlan plan : listPlans) {
-                        //根据计划获取角色
-//                        List<AppPlanToRole> planToRoles = appPlanToRoles.stream().filter(item -> item.getPlanId().equals(plan.getId())).collect(Collectors.toList());
-                        List<Resumption> resumptionLista = this.buildResumptions(plan,  workTime);
-                        if (CollectionUtils.isNotEmpty(resumptionLista)) {
-                            //根据planId和roleId是否判断resumptionLista中的数据是否在resumptionListYlz中
-                            List<Resumption> resumptionListb = resumptionLista.stream().filter(item -> !resumptionListYlz.stream().filter(item1 -> item1.getPlanId().equals(item.getPlanId())
-                                    && item1.getRoleId().equals(item.getRoleId())).findFirst().isPresent()).collect(Collectors.toList());
-                            if (CollectionUtils.isNotEmpty(resumptionListb)) {
-                                newResumptionList.addAll(resumptionListb);
-                            }
-                        }
-                    }
-                    this.saveBatch(newResumptionList);
+        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);
+        }
+
+        createTask(appPlans);
+    }
+
+    private void createTask(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);
+            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(), 1)) {
+                    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);
+                }
             }
-        } catch (Exception e) {
-            e.printStackTrace();
         }
+
+        this.saveBatch(resumptions);
+    }
+
+    @Override
+    public void rebuildDayTask(List<Long> orgIds, SysWorkTime workTime) {
+        rebuildTask(orgIds, workTime.getYmdDate(), workTime.getYmdDate(), CycleCommonEnum.DAILY, workTime);
     }
 
     @Override
     public void rebuildWeeklyTask(List<Long> orgIds, Date startDate, Date endDate) {
-        rebuildTask(orgIds, startDate, endDate, CycleCommonEnum.WEEKLY);
+        rebuildTask(orgIds, startDate, endDate, CycleCommonEnum.WEEKLY, null);
     }
 
 
     @Override
     public void rebuildMonthTask(List<Long> orgIds, Date startDate, Date endDate) {
-        rebuildTask(orgIds, startDate, endDate, CycleCommonEnum.MONTHLY);
+        rebuildTask(orgIds, startDate, endDate, CycleCommonEnum.MONTHLY, null);
     }
 
     @Override
     public void rebuildQuarterTask(List<Long> orgIds, Date startDate, Date endDate) {
-        rebuildTask(orgIds, startDate, endDate, CycleCommonEnum.QUARTERLY);
+        rebuildTask(orgIds, startDate, endDate, CycleCommonEnum.QUARTERLY, null);
     }
 
     @Override
     public void rebuildHalfYearTask(List<Long> orgIds, Date startDate, Date endDate) {
-        rebuildTask(orgIds, startDate, endDate, CycleCommonEnum.HALF_YEARLY);
+        rebuildTask(orgIds, startDate, endDate, CycleCommonEnum.HALF_YEARLY, null);
     }
 
     @Override
     public void rebuildYearTask(List<Long> orgIds, Date startDate, Date endDate) {
-        rebuildTask(orgIds, startDate, endDate, CycleCommonEnum.YEARLY);
+        rebuildTask(orgIds, startDate, endDate, CycleCommonEnum.YEARLY, null);
     }
 
-    private void rebuildTask(List<Long> orgIds, Date startDate, Date endDate, CycleCommonEnum cycle) {
-        List<Resumption> resumptionList = queryTask(startDate, cycle, orgIds);
+    /**
+     * @param orgIds
+     * @param startDate
+     * @param endDate
+     * @param cycle
+     * @param workTime  周期为每日时,使用该值
+     */
+    @Transactional
+    public void rebuildTask(List<Long> orgIds, Date startDate, Date endDate, CycleCommonEnum cycle, SysWorkTime workTime) {
+        List<Resumption> resumptionList = queryTask(startDate, cycle, orgIds, null);
         List<Long> deleteIds = resumptionList.stream()
                 .filter(r -> (ObjectUtil.equal(r.getStatus(), 1) || ObjectUtil.equal(r.getStatus(), 2)))
                 .map(Resumption::getId).collect(Collectors.toList());
@@ -130,7 +190,7 @@ public class RebuildResumptionTaskBusiness extends TaskCreatingServiceImplBase<R
 
         List<SysOrg> orgs = remoteOrgService.selectByOrgIdList(orgIds, SecurityConstants.INNER);
         for (SysOrg org : orgs) {
-            if(ObjectUtil.isNull(org.getType())){
+            if (ObjectUtil.isNull(org.getType())) {
                 continue;
             }
 
@@ -154,24 +214,27 @@ public class RebuildResumptionTaskBusiness extends TaskCreatingServiceImplBase<R
             for (AppPlan plan : listPlans) {
                 //根据计划获取角色
 //                List<AppPlanToRole> planToRoles = appPlanToRoles.stream().filter(item -> item.getPlanId().equals(plan.getId())).collect(Collectors.toList());
+
                 Long executedCount = executedResumptionList.stream()
                         .filter(r -> ObjectUtil.equal(r.getOrgId(), orgId) && ObjectUtil.equal(r.getPlanId(), plan.getParentId()))
                         .count();
-                List<Resumption> planResumptionList = this.buildResumptions(plan, startDate, endDate, executedCount);
+
+                List<Resumption> planResumptionList;
+                if (ObjectUtil.equal(cycle, CycleCommonEnum.DAILY)) {
+                    planResumptionList = this.buildResumptions(plan, orgId, workTime);
+                } else {
+                    planResumptionList = this.buildResumptions(plan, orgId, startDate, endDate, executedCount);
+                }
+
                 if (CollectionUtils.isNotEmpty(planResumptionList)) {
-                    //根据planId和roleId是否判断resumptionLista中的数据是否在resumptionListYlz中
-//                    List<Resumption> resumptionListb = resumptionLista.stream().filter(item -> !resumptionListYlz.stream().filter(item1 -> item1.getPlanId().equals(item.getPlanId())
-//                            && item1.getRoleId().equals(item.getRoleId())).findFirst().isPresent()).collect(Collectors.toList());
-//                    if (CollectionUtils.isNotEmpty(resumptionListb)) {
                     newResumptionList.addAll(planResumptionList);
-//                    }
                 }
             }
             this.saveBatch(newResumptionList);
         }
     }
 
-    private List<Resumption> buildResumptions(AppPlan appPlan, SysWorkTime workTime) {
+    private List<Resumption> buildResumptions(AppPlan appPlan, Long execOrgId, SysWorkTime workTime) {
         DateTime dateTime = new DateTime(workTime.getYmdDate());
         String opentime = workTime.getOpenTime();//营业时间
         String closetime = workTime.getCloseTime();//营业终了
@@ -197,10 +260,10 @@ public class RebuildResumptionTaskBusiness extends TaskCreatingServiceImplBase<R
             planendTime = DateUtil.endOfDay(time2).setField(DateField.MILLISECOND, 0);
         }
 
-        return buildResumptions(appPlan, planstartTime, planendTime, 0L);
+        return buildResumptions(appPlan, execOrgId, planstartTime, planendTime, 0L);
     }
 
-    private List<Resumption> buildResumptions(AppPlan appPlan, Date planStartTime, Date planEndTime, Long executedCount) {
+    private List<Resumption> buildResumptions(AppPlan appPlan, Long execOrgId, Date planStartTime, Date planEndTime, Long executedCount) {
         List<Resumption> resumptionList = new ArrayList<>();
         Long count = 1L;
         if (NumberUtil.isNumber(appPlan.getCount())) {
@@ -221,8 +284,9 @@ public class RebuildResumptionTaskBusiness extends TaskCreatingServiceImplBase<R
             resumption.setYmdHour(Long.valueOf(ymd.getHour()));
             resumption.setYmdQuarter(Long.valueOf(ymd.getQuarter()));
             resumption.setYmdHalfyear(Long.valueOf(ymd.getHalfyear()));
-            resumption.setPlanId((ObjectUtil.equal(appPlan.getParentId(), -1L) || ObjectUtil.isNull(appPlan.getParentId())) ? appPlan.getId() : appPlan.getParentId());
-            resumption.setOrgId(appPlan.getPlanOfOrgId());
+            resumption.setParentPlanId((ObjectUtil.equal(appPlan.getParentId(), -1L) || ObjectUtil.isNull(appPlan.getParentId())) ? appPlan.getId() : appPlan.getParentId());
+            resumption.setPlanId(appPlan.getId());
+            resumption.setOrgId(execOrgId);
             resumption.setType(appPlan.getPlanCycle());
             resumption.setPlanStartTime(planStartTime);
             resumption.setPlanEndTime(planEndTime);
@@ -233,10 +297,15 @@ public class RebuildResumptionTaskBusiness extends TaskCreatingServiceImplBase<R
         return resumptionList;
     }
 
-    private List<Resumption> queryTask(Date ymdDate, CycleCommonEnum cycle, List<Long> orgIds) {
+    private List<Resumption> queryTask(Date ymdDate, CycleCommonEnum cycle, List<Long> orgIds, List<Long> planIds) {
         QueryWrapper<Resumption> queryWrapper = new QueryWrapper<>();
         queryWrapper.lambda().eq(Resumption::getYmdDate, ymdDate);
-        queryWrapper.lambda().in(Resumption::getOrgId, orgIds);
+        if (CollectionUtils.isNotEmpty(orgIds)) {
+            queryWrapper.lambda().in(Resumption::getOrgId, orgIds);
+        }
+        if (CollectionUtils.isNotEmpty(planIds)) {
+            queryWrapper.lambda().in(Resumption::getPlanId, planIds);
+        }
         queryWrapper.lambda().eq(Resumption::getType, cycle.getCode());
 
         List<Resumption> resumptionList = baseMapper.selectList(queryWrapper);
@@ -250,7 +319,7 @@ public class RebuildResumptionTaskBusiness extends TaskCreatingServiceImplBase<R
      * @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) {
         if (CollectionUtils.isEmpty(planOfOrgId)) {
             return new ArrayList<>();
         }
@@ -259,8 +328,8 @@ public class RebuildResumptionTaskBusiness extends TaskCreatingServiceImplBase<R
         qw.lambda().eq(AppPlan::getPlanCycle, cycle.getCode());
         qw.lambda().in(AppPlan::getPlanOfOrgId, planOfOrgId);
 
-        if(CollectionUtils.isNotEmpty(execOrgTypes)){
-            qw.lambda().in(AppPlan::getExecOrgType,execOrgTypes);
+        if (CollectionUtils.isNotEmpty(execOrgTypes)) {
+            qw.lambda().in(AppPlan::getExecOrgType, execOrgTypes);
         }
         List<AppPlan> listPlans = appPlanMapper.selectList(qw);
 

+ 7 - 51
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/resumption/task/ResumptionTaskBusiness.java

@@ -49,8 +49,7 @@ public class ResumptionTaskBusiness extends TaskCreatingServiceImplBase<AppPlanM
     private ResumptionService resumptionService;
     @Autowired
     private RemoteWorkTimeService workTimeService;
-    @Autowired
-    private RemoteOrgService orgService;
+
     @Autowired
     private AppPlanService appPlanService;
     @Autowired
@@ -225,12 +224,12 @@ public class ResumptionTaskBusiness extends TaskCreatingServiceImplBase<AppPlanM
                 continue;
             }
             //获取所有要点中的区域id
-            Set<Long> nfcBindIdList = new HashSet<>();
-            for (AppRulePointTaskVo p : pointList) {
-                if (p.getNfcBindId() != null && p.getPointScan() == 1) {
-                    nfcBindIdList.add(p.getNfcBindId());
-                }
-            }
+//            Set<Long> nfcBindIdList = new HashSet<>();
+//            for (AppRulePointTaskVo p : pointList) {
+//                if (p.getNfcBindId() != null && p.getPointScan() == 1) {
+//                    nfcBindIdList.add(p.getNfcBindId());
+//                }
+//            }
             //根据区域获取区域内绑定的nfc
             /*NFCBindJobDto jobDto = new NFCBindJobDto();
             jobDto.setAreaIds(new ArrayList(areaList));
@@ -751,52 +750,9 @@ public class ResumptionTaskBusiness extends TaskCreatingServiceImplBase<AppPlanM
 //        this.resumptionService.updateTaskStatus();
 //    }
 
-    /**
-     * 获取计划的执行机构id
-     *
-     * @param appPlan
-     * @return
-     */
-    private List<Long> getPlanOrgIds(AppPlan appPlan) {
-        List<Long> orgIds = null;
-//        if (appPlan.getExecType()!=null&&appPlan.getExecType() == 0) {//0机构类型需要安类型去机构里查询所以的机构
-        OrgListByTypesConditionEto cond = new OrgListByTypesConditionEto();
-        cond.setOrgId(appPlan.getPlanOfOrgId());
-        cond.setOrgTypes(Arrays.asList(appPlan.getExecOrgType().toString()));
-        R<List<SysOrg>> r = orgService.listByTypes(cond);
-        if (ObjectUtil.isNull(r) || ObjectUtil.isEmpty(r.getData())) {
-            return new ArrayList<>();
-        }
-        orgIds = r.getData().stream().map(i -> i.getId()).collect(Collectors.toList());
-//        }
-//        else {
-//            List<SysOrg> sysOrgs = orgService.selectByOrgType(appPlan.getExecOrgType(), SecurityConstants.INNER);
-//             orgIds = sysOrgs.stream().map(SysOrg::getId).collect(Collectors.toList());
-////            orgIds = appPlanService.findExecOrgByPlan(appPlan.getId());
-//        }
-
-        return orgIds;
-    }
 
-    private List<SysOrg> getPlanOrgs(AppPlan appPlan) {
-        List<Long> orgIds = null;
-        if (appPlan.getExecType() == 0) {//0机构类型需要安类型去机构里查询所以的机构
-            orgIds = orgService.findListByOrgType(appPlan.getExecOrgType(), SecurityConstants.INNER).getData();
-        } else {
-            orgIds = appPlanService.findExecOrgByPlan(appPlan.getId());
-        }
 
-        return orgService.listByIds(orgIds, SecurityConstants.INNER).getData();
-    }
 
-    private List<Long> getHangsheOrgIds() {
-        R<List<Long>> allHangshe = orgService.findListByOrgType(OrgTypeEnum.HANG_SHE.getCode(), SecurityConstants.INNER);
-        if (ObjectUtil.isNull(allHangshe) || ObjectUtil.isEmpty(allHangshe.getData())) {
-            return new ArrayList<>();
-        }
-
-        return allHangshe.getData();
-    }
 
     /**
      * 根据作息变更生成新的每日每小时履职任务

+ 2 - 2
soc-modules/soc-modules-core/src/main/resources/mapper/resumption/ResumptionRecordMapper.xml

@@ -207,10 +207,10 @@
                 </foreach>
             </if>
             <if test="pageDto.executeRole !=null ">
-                and r.role_id = #{pageDto.executeRole}
+                and r.plan_id in (select plan_id from core_resumption_plan_to_role where role_id=#{pageDto.executeRole})
             </if>
             <if test="pageDto.planId !=null ">
-                and r.plan_id = #{pageDto.planId}
+                and r.parent_plan_id = #{pageDto.planId}
             </if>
             <!--            <if test="pageDto.checkSub == true">-->
             <!--                and o.path like concat(#{pageDto.orgPath},'%')-->

+ 0 - 1
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/listener/WorkTimeChangeEventListener.java

@@ -25,7 +25,6 @@ public class WorkTimeChangeEventListener implements ApplicationListener<WorkTime
     @EventListener(WorkTimeChangeEvent.class)
     @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT, fallbackExecution = false)
     public void onApplicationEvent(WorkTimeChangeEvent event) {
-
         remoteResumptionTaskService.rebuild(JSON.toJSONString(event), SecurityConstants.INNER);
     }
 }