Răsfoiți Sursa

Merge remote-tracking branch 'origin/V0.1.0' into V0.1.0

jingyuanchao 1 an în urmă
părinte
comite
88453efd9a

+ 5 - 0
project_data/sql/0.1.0/soc/soc.sql

@@ -242,3 +242,8 @@ create table sms_send_record
 create index idx_orgId
     on sms_send_record (org_id);
 
+update core_safety_task set start_time = submit_time,end_time = submit_time where submit_by is not null;
+
+-- 新增没有办事处的地区系统配置
+DELETE FROM `sys_config` WHERE `config_key` ='NO_BSC_AREA';
+INSERT INTO `sys_config` (`config_name`, `config_key`, `config_value`, `config_type`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES ('演练地区评优推优由省联社直接管理的地区', 'NO_BSC_AREA', '4358025846521957,1739556950966714370', 'Y', '超级管理员', '2024-05-31 10:25:25', '', NULL, NULL);

+ 487 - 50
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/resumption/service/impl/AppPlanServiceImpl.java

@@ -82,6 +82,8 @@ import java.util.*;
 import java.util.concurrent.CompletableFuture;
 import java.util.stream.Collectors;
 
+import static java.util.stream.Collectors.toList;
+
 /**
  * @author : 高雄
  * @date :2022/4/27 17:44
@@ -207,8 +209,20 @@ public class AppPlanServiceImpl extends ServiceImpl<AppPlanMapper, AppPlan> impl
         }
         //如果计划所属机构类型为省联社,生成下发子计划
         if (ObjectUtil.equal(oldPlan.getPlanOfOrgType(), 1)) {
-            for (DistributeStatusDto d :
-                    dto.getOrgAndStatus()) {
+
+            List<AppPlanToExecOrg> execOrgs = appPlanToExecOrgMapper.selectList(new LambdaQueryWrapper<AppPlanToExecOrg>().eq(AppPlanToExecOrg::getPlanId, dto.getId()));
+            List<Long> parentPlanExceOrgIds=new ArrayList<>();
+            List<SysOrg> parentPlanExecOrgs =null;
+            List<SysOrg> hsOrgs =null;
+            if(ObjectUtil.isNotEmpty(execOrgs))
+            {
+                parentPlanExceOrgIds= execOrgs.stream().map(x->x.getOrgId()).collect(toList());
+                parentPlanExecOrgs = remoteOrgService.selectByOrgIdList(parentPlanExceOrgIds, SecurityConstants.INNER);
+                hsOrgs =   remoteOrgService.selectParentHs(parentPlanExceOrgIds, SecurityConstants.INNER);
+            }
+
+
+            for (DistributeStatusDto d :dto.getOrgAndStatus()) {
 
                 AppPlan tempplan = baseMapper.selectOne(new LambdaQueryWrapper<AppPlan>()
                         .eq(AppPlan::getPlanOfOrgId, d.getOrgId())
@@ -228,20 +242,20 @@ public class AppPlanServiceImpl extends ServiceImpl<AppPlanMapper, AppPlan> impl
 
                     tempplan.setDistributePlanStatus(d.getStatus().toString());
 //                    tempplan.setDistributeStatus("1");
-                    if (!immediateEffect) {
-                        //停用状态下发,逻辑删除旧的计划,并生成一份副本
-                        baseMapper.updateById(tempplan);
-                        baseMapper.deleteById(tempplan);
-
-                        Long hsPlanId = IDHelper.id();
-                        baseMapper.copyChildren(tempplan.getId(), hsPlanId, parentId);
-                        baseMapper.copyPlanOrgs(tempplan.getId(), hsPlanId);
-                        baseMapper.copyPlanRoles(tempplan.getId(), hsPlanId);
-                        baseMapper.copyPlanPoints(tempplan.getId(), hsPlanId);
-//                        AppPlan newPlan = baseMapper.selectById(hsPlanId);
-                    } else {
+//                    if (!immediateEffect) {
+//                        //停用状态下发,逻辑删除旧的计划,并生成一份副本
+//                        baseMapper.updateById(tempplan);
+//                        baseMapper.deleteById(tempplan);
+//
+//                        Long hsPlanId = IDHelper.id();
+//                        baseMapper.copyChildren(tempplan.getId(), hsPlanId, parentId);
+//                        baseMapper.copyPlanOrgs(tempplan.getId(), hsPlanId);
+//                        baseMapper.copyPlanRoles(tempplan.getId(), hsPlanId);
+//                        baseMapper.copyPlanPoints(tempplan.getId(), hsPlanId);
+////                        AppPlan newPlan = baseMapper.selectById(hsPlanId);
+//                    } else {
                         baseMapper.updateById(tempplan);
-                    }
+//                    }
                 } else {
                     AppPlan plan = new AppPlan();
                     BeanUtils.copyProperties(oldPlan, plan);
@@ -270,20 +284,22 @@ public class AppPlanServiceImpl extends ServiceImpl<AppPlanMapper, AppPlan> impl
                     Long id = plan.getId();
 
                     List<Long> roleList = appPlanToRoleMapper.selectList(new LambdaQueryWrapper<AppPlanToRole>().eq(AppPlanToRole::getPlanId, dto.getId())).stream().map(AppPlanToRole::getRoleId).collect(Collectors.toList());
-                    AppPlanToRole atr = null;
-                    List<AppPlanToRole> planToRoles = new ArrayList<>();
-                    for (Long roleId : roleList) {
-                        atr = new AppPlanToRole();
-                        atr.setRoleId(roleId);
-                        atr.setPlanId(id);
-                        planToRoles.add(atr);
-//                        appPlanToRoleMapper.insert(atr);
-                    }
-                    if (planToRoles.size() != 0) {
-                        appPlanToRoleMapper.batchInsertData(planToRoles);
-                    }
+                    addPlanRole(id,roleList);
+//                    AppPlanToRole atr = null;
+//                    List<AppPlanToRole> planToRoles = new ArrayList<>();
+//                    for (Long roleId : roleList) {
+//                        atr = new AppPlanToRole();
+//                        atr.setRoleId(roleId);
+//                        atr.setPlanId(id);
+//                        planToRoles.add(atr);
+////                        appPlanToRoleMapper.insert(atr);
+//                    }
+//                    if (planToRoles.size() != 0) {
+//                        appPlanToRoleMapper.batchInsertData(planToRoles);
+//                    }
 
                     List<AppPlanToPoint> itemList = appPlanToItemMapper.selectList(new LambdaQueryWrapper<AppPlanToPoint>().eq(AppPlanToPoint::getPlanId, dto.getId()));
+
                     AppPlanToPoint item = null;
                     List<AppPlanToPoint> planToPoints = new ArrayList<>();
                     for (AppPlanToPoint ruleItemVo : itemList) {
@@ -301,19 +317,20 @@ public class AppPlanServiceImpl extends ServiceImpl<AppPlanMapper, AppPlan> impl
                         appPlanToItemMapper.batchInsertData(planToPoints);
                     }
 
+                    List<Long> childPlanExceOrgIds = getChildPlanExceOrgIds(plan, hsOrgs, parentPlanExecOrgs);
+                    addPlanExecOrg(id,childPlanExceOrgIds);
 
-                    List<AppPlanToExecOrg> execOrgs = appPlanToExecOrgMapper.selectList(new LambdaQueryWrapper<AppPlanToExecOrg>().eq(AppPlanToExecOrg::getPlanId, dto.getId()));
-                    List<AppPlanToExecOrg> planToExecOrgs = new ArrayList<>();
-                    for (AppPlanToExecOrg execOrg : execOrgs) {
-                        AppPlanToExecOrg n = new AppPlanToExecOrg();
-                        n.setPlanId(id);
-                        n.setOrgId(execOrg.getOrgId());
-                        planToExecOrgs.add(n);
-//                        appPlanToExecOrgMapper.insert(n);
-                    }
-                    if (planToExecOrgs.size() != 0) {
-                        appPlanToExecOrgMapper.batchInsertData(planToExecOrgs);
-                    }
+//                    List<AppPlanToExecOrg> planToExecOrgs = new ArrayList<>();
+//                    for (Long orgId  : childPlanExceOrgIds) {
+//                        AppPlanToExecOrg n = new AppPlanToExecOrg();
+//                        n.setPlanId(id);
+//                        n.setOrgId(orgId);
+//                        planToExecOrgs.add(n);
+////                        appPlanToExecOrgMapper.insert(n);
+//                    }
+//                    if (planToExecOrgs.size() != 0) {
+//                        appPlanToExecOrgMapper.batchInsertData(planToExecOrgs);
+//                    }
                 }
             }
         }
@@ -329,15 +346,15 @@ public class AppPlanServiceImpl extends ServiceImpl<AppPlanMapper, AppPlan> impl
 //        plan.setBuildTaskNow(null);
 
         baseMapper.updateById(plan);
-        if (ObjectUtil.equal(oldPlan.getPlanStatus(), PlanStatus.DELETED.getCode())) {
-            //停用时下发且立即生效,逻辑删除旧计划并生成新计划
-            baseMapper.copySelf(plan.getId(), parentId);
-            baseMapper.copyPlanPoints(plan.getId(), parentId);
-            baseMapper.copyPlanRoles(plan.getId(), parentId);
-            baseMapper.copyPlanOrgs(plan.getId(), parentId);
-
-            baseMapper.deleteById(plan);
-        }
+//        if (ObjectUtil.equal(oldPlan.getPlanStatus(), PlanStatus.DELETED.getCode())) {
+//            //停用时下发且立即生效,逻辑删除旧计划并生成新计划
+//            baseMapper.copySelf(plan.getId(), parentId);
+//            baseMapper.copyPlanPoints(plan.getId(), parentId);
+//            baseMapper.copyPlanRoles(plan.getId(), parentId);
+//            baseMapper.copyPlanOrgs(plan.getId(), parentId);
+//
+//            baseMapper.deleteById(plan);
+//        }
 
         if (immediateEffect) {
             TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
@@ -543,9 +560,9 @@ public class AppPlanServiceImpl extends ServiceImpl<AppPlanMapper, AppPlan> impl
      * @param immediateEffect
      * @throws Exception
      */
-    @Override
+//    @Override
     @Transactional(rollbackFor = Exception.class)
-    public void saveOrUpdatePlan(AppPlanVo app, Boolean immediateEffect) throws Exception {
+    public void saveOrUpdatePla_old(AppPlanVo app, Boolean immediateEffect) throws Exception {
         AppPlan plan = convertToAppPlan(app);
         Calendar calendar = Calendar.getInstance();
         calendar.set(2000, 0, 1);
@@ -832,6 +849,426 @@ public class AppPlanServiceImpl extends ServiceImpl<AppPlanMapper, AppPlan> impl
     }
 
     /**
+     * immediateEffect:参数无效
+     *
+     * @param app
+     *
+     * @throws Exception
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void saveOrUpdatePlan(AppPlanVo app, Boolean immediateEffect) throws Exception {
+        AppPlan plan = convertToAppPlan(app);
+//        Calendar calendar = Calendar.getInstance();
+//        calendar.set(2000, 0, 1);
+
+        // 新增计划
+        if (app.getId() == null) {
+            addPlan(plan,app);
+        }
+        // 修改计划
+        else
+        {
+            AppPlan existPlan = baseMapper.selectById(app.getId());
+
+            plan.setModifiedBy(SecurityUtils.getActualSubmitUserId());
+
+            List<Object> needRebuildPlans = new ArrayList<>();
+
+            //计划处于草稿状态,没有子计划,没有任务(可修改所有数据)
+            if(ObjectUtil.equal(existPlan.getPlanStatus(), PlanStatus.DRAFT.getCode()))
+            {
+                //更新主计划下的履职内容
+                updatePlanPoint(existPlan,app.getItemList());
+                //更新主计划下的履职角色
+                updatePlanRole(existPlan,app.getRoleList());
+                //更新主计划下的履职机构
+                updatePlanExecOrg(existPlan,app.getOrgList());
+
+                //最后处理本计划
+                plan.setUpdateTime(new Date());
+                //前端总是会传递计划创建id,修改时需要排除
+                plan.setPlanStatus(null);
+                plan.setPlanCreateOrgId(null);
+                plan.setPlanCreateOrgName(null);
+                baseMapper.updateById(plan);
+            }
+            //计划处于使用中状态:存在子计划、任务数据(也可能不存在任务); 只能修改:计划名称、履职内容
+            else if(ObjectUtil.equal(existPlan.getPlanStatus(), PlanStatus.USING.getCode()))
+            {
+                Long newPlanID = IDHelper.id();
+                //任务为使用中且有已完成或当前周期内停用,则下个周期生效,需要副本;任务为使用中且无已完成,则删除所有任务,并重新生成任务
+                Boolean needCopy = needCopyOnEdit(existPlan);
+
+                //修改所有子计划
+                List<AppPlan> appPlans = baseMapper.selectList(new LambdaQueryWrapper<AppPlan>().eq(AppPlan::getParentId, plan.getId()));
+                //修改后 履职机构对应的行社机构
+                List<SysOrg> hsOrgs =null;
+                //修改后 履职机构对象
+                List<SysOrg> parentPlanExceOrgs =null;
+                if(ObjectUtil.isNotEmpty(app.getOrgList()))
+                {
+                    hsOrgs=   remoteOrgService.selectParentHs(app.getOrgList(), SecurityConstants.INNER);
+                    parentPlanExceOrgs = remoteOrgService.selectByOrgIdList(app.getOrgList(), SecurityConstants.INNER);
+                }
+                for (AppPlan ap : appPlans) {
+                    AppPlan newChildPlan = reBuildChildPlan(needCopy,ap,plan,newPlanID);
+                    updateChildPlan(false, newChildPlan,app,hsOrgs,parentPlanExceOrgs);
+                    if (needRebuildOnEdit(newChildPlan, existPlan.getTaskHasCompleted())) {
+                        needRebuildPlans.add(newChildPlan);
+                    }
+                }
+                // 复制主计划
+                if (needCopy) {
+                    copyPlan(true,existPlan.getId(),newPlanID,null);
+                    baseMapper.deleteById(app.getId());
+                    plan.setId(newPlanID);
+                }
+                //更新主计划下的履职内容
+                updatePlanPoint(plan,app.getItemList());
+
+                //最后处理本计划
+                plan.setUpdateTime(new Date());
+                //前端总是会传递计划创建id,修改时需要排除
+                plan.setPlanStatus(null);
+                plan.setPlanCreateOrgId(null);
+                plan.setPlanCreateOrgName(null);
+                baseMapper.updateById(plan);
+            }
+            // 计划处于停用状态:存在子计划、有已完成的任务; 能编辑:计划名称、履职内容、履职机构
+            else if (ObjectUtil.equal(existPlan.getPlanStatus(), PlanStatus.DELETED.getCode())) {
+                Long newPlanID = IDHelper.id();
+                //任务为使用中且有已完成或当前周期内停用,则下个周期生效,需要副本;任务为使用中且无已完成,则删除所有任务,并重新生成任务
+                Boolean needCopy = needCopyOnEdit(existPlan);
+                //修改所有子计划
+                List<AppPlan> oldChildPlans = baseMapper.selectList(new LambdaQueryWrapper<AppPlan>().eq(AppPlan::getParentId, plan.getId()));
+
+                //修改后应该有的子计划
+                List<SysOrg> needCreatePlanhsOrgs=null;
+
+                //修改后 履职机构对象
+                List<SysOrg> parentPlanExceOrgs =null;
+
+                if(ObjectUtil.isNotEmpty(app.getOrgList()))
+                {
+                    needCreatePlanhsOrgs=  remoteOrgService.selectParentHs(app.getOrgList(), SecurityConstants.INNER);
+                    parentPlanExceOrgs = remoteOrgService.selectByOrgIdList(app.getOrgList(), SecurityConstants.INNER);
+                }
+                // 下发时没有子计划的行社会新增子计划,此处只处理应删除的子计划
+                for (AppPlan ap : oldChildPlans) {
+
+                    // 找出历史子计划在修改后应创建子计划列表中不存在的删除掉
+                    if(ObjectUtil.isNotEmpty(needCreatePlanhsOrgs) && !needCreatePlanhsOrgs.stream().anyMatch(y -> ObjectUtil.equal(y.getId(), ap.getPlanOfOrgId())))
+                    {
+                        baseMapper.deleteById(ap.getId());
+                        continue;
+                    }
+                    AppPlan newChildPlan = reBuildChildPlan(needCopy,ap,plan,newPlanID);
+                    updateChildPlan(false, newChildPlan,app,needCreatePlanhsOrgs,parentPlanExceOrgs);
+                    if (needRebuildOnEdit(newChildPlan, existPlan.getTaskHasCompleted())) {
+                        needRebuildPlans.add(newChildPlan);
+                    }
+                }
+                // 复制主计划
+                if (needCopy) {
+                    copyPlan(true,existPlan.getId(),newPlanID,null);
+                    baseMapper.deleteById(app.getId());
+                    plan.setId(newPlanID);
+                }
+                //更新主计划下的履职内容
+                updatePlanPoint(plan,app.getItemList());
+                //更新主计划下的履职角色
+//                updatePlanRole(plan,app);
+                //更新主计划下的履职机构
+                updatePlanExecOrg(plan,app.getOrgList());
+
+                //最后处理本计划
+                plan.setUpdateTime(new Date());
+                //前端总是会传递计划创建id,修改时需要排除
+                plan.setPlanStatus(null);
+                plan.setPlanCreateOrgId(null);
+                plan.setPlanCreateOrgName(null);
+                baseMapper.updateById(plan);
+            }
+            if (needRebuildOnEdit(existPlan, existPlan.getTaskHasCompleted())) {
+                needRebuildPlans.add(baseMapper.selectById(plan.getId()));
+            }
+            resumptionTaskBusiness.rebuildCurrentCycleTask(needRebuildPlans);
+        }
+    }
+
+    private void copyPlan(boolean copySelf,Long existPlanId,Long newPlanId,Long newParentPlanId)
+    {
+        if(copySelf)
+        {
+            baseMapper.copySelf(existPlanId, newPlanId);
+        }
+        else{
+            baseMapper.copyChildren(existPlanId, newPlanId, newParentPlanId);
+        }
+
+        baseMapper.copyPlanOrgs(existPlanId, newPlanId);
+        baseMapper.copyPlanRoles(existPlanId, newPlanId);
+        baseMapper.copyPlanPoints(existPlanId, newPlanId);
+    }
+
+    private AppPlan reBuildChildPlan(boolean needCopy, AppPlan existChild,AppPlan curentPlan,Long newParentPlanId)
+    {
+        AppPlan child = existChild;
+        if (needCopy) {
+            //使用中状态且立即生效,复制子计划副本
+            Long newChildPlanId = IDHelper.id();
+            copyPlan(false,existChild.getId(),newChildPlanId,newParentPlanId);
+            baseMapper.deleteById(existChild.getId());
+            child = baseMapper.selectById(newChildPlanId);
+        }
+
+        child.setPlanType(curentPlan.getPlanType());
+        child.setPlanCycle(curentPlan.getPlanCycle());
+        child.setExecOrgType(curentPlan.getExecOrgType());
+        child.setPlanExec(curentPlan.getPlanExec());
+        child.setModifiedBy(SecurityUtils.getActualSubmitUserId());
+        child.setUpdateTime(new Date());
+        child.setPlanName(curentPlan.getPlanName());
+        child.setCount(curentPlan.getCount());
+        child.setStartDate(curentPlan.getStartDate());
+        child.setEndDate(curentPlan.getEndDate());
+        return child;
+    }
+
+    /**
+     *
+     * @param needUpdateExecOrg
+     * @param child
+     * @param curentPlanVo
+     */
+    private void updateChildPlan(boolean needUpdateExecOrg, AppPlan child,AppPlanVo curentPlanVo,List<SysOrg> hsOrgs,List<SysOrg> parentPlanExceOrgs)
+    {
+        baseMapper.updateById(child);
+        //更新子计划下的履职内容
+        updatePlanPoint(child,curentPlanVo.getItemList());
+
+        //更新子计划下的履职机构
+        if(needUpdateExecOrg)
+        {
+            List<Long> childPlanExceOrgIds = getChildPlanExceOrgIds(child, hsOrgs, parentPlanExceOrgs);
+            updatePlanExecOrg(child,childPlanExceOrgIds);
+        }
+
+    }
+
+    private void  addPlan( AppPlan plan ,AppPlanVo app)
+    {
+        plan.setParentId(-1L);
+        plan.setDeleted(0);
+        plan.setSolidId(IDHelper.id());
+        plan.setParentSolidId(-1L);
+        plan.setCreateTime(new Date());
+        plan.setUpdateTime(new Date());
+        //新增
+        plan.setPlanOfOrgId(app.getPlanCreateOrgId());
+        plan.setPlanOfOrgName(app.getPlanCreateOrgName());
+        //验证名称是否重复
+        QueryWrapper<AppPlan> qw = new QueryWrapper<>();
+        qw.lambda().eq(AppPlan::getPlanName, app.getPlanName()).eq(AppPlan::getDeleted, 0);
+
+        Long size = baseMapper.selectCount(qw);
+
+        if (size > 0) {
+            throw new RuntimeException("计划名称重复,请确认!");
+        }
+
+//            plan.setBuildTaskNow(app.getBuildTaskNow());
+        plan.setDistribute("0");
+        plan.setPlanStatus(0);
+        //设置计划所属机构类型
+        plan.setPlanOfOrgType(orgService.selectSysOrgById(app.getPlanCreateOrgId(), SecurityConstants.INNER).getType());
+
+        baseMapper.insert(plan);
+        Long id = plan.getId();
+
+
+        addPlanPoint(id,app.getItemList());
+        addPlanRole(id,app.getRoleList());
+        addPlanExecOrg(id,app.getOrgList());
+
+//        List<Long> roleList = app.getRoleList();
+//        AppPlanToRole atr = null;
+//        for (Long roleId : roleList) {
+//            atr = new AppPlanToRole();
+//            atr.setRoleId(roleId);
+//            atr.setPlanId(id);
+//            appPlanToRoleMapper.insert(atr);
+//        }
+//
+//        List<RuleItemVo> itemList = app.getItemList();
+//        if (CollectionUtil.isEmpty(itemList)) {
+//            throw new RuntimeException("请选择履职要点");
+//        }
+//
+//        AppPlanToPoint item = null;
+//        for (RuleItemVo ruleItemVo : itemList) {
+//            item = new AppPlanToPoint();
+//            item.setPointId(ruleItemVo.getId());
+//            item.setPlanId(id);
+//            item.setPointScan(ruleItemVo.isPointScan());
+//            item.setRequired(ruleItemVo.isRequired());
+//            item.setOfOrgId(ruleItemVo.getOfOrgId());
+//            appPlanToItemMapper.insert(item);
+//        }
+//
+//        if (ObjectUtil.isNotEmpty(app.getOrgList())) {
+//            for (Long orgId : app.getOrgList()) {
+//                AppPlanToExecOrg execOrg = new AppPlanToExecOrg();
+//                execOrg.setOrgId(orgId);
+//                execOrg.setPlanId(id);
+//
+//                appPlanToExecOrgMapper.insert(execOrg);
+//            }
+//        }
+    }
+
+    /**
+     * 修改计划下的履职内容
+     * @param existPlan 当前已存在的计划
+     * @param itemList 新增的计划/编辑后新计划 后的履职内容
+     */
+    private void  updatePlanPoint(AppPlan existPlan,List<RuleItemVo> itemList)
+    {
+        deletePlanPoint(existPlan.getId(),existPlan.getPlanCreateOrgId());
+        addPlanPoint(existPlan.getId(),itemList);
+    }
+
+    private void deletePlanPoint(Long planId,Long createOrgId){
+        QueryWrapper<AppPlanToPoint> api = new QueryWrapper<>();
+        api.lambda().eq(AppPlanToPoint::getPlanId, planId).eq(AppPlanToPoint::getOfOrgId, createOrgId);
+        appPlanToItemMapper.delete(api);
+    }
+
+    private void addPlanPoint(Long planId,List<RuleItemVo> itemList)
+    {
+        if (CollectionUtil.isEmpty(itemList)) {
+            throw new RuntimeException("请选择履职要点");
+        }
+
+        List<AppPlanToPoint> planToPoints = new ArrayList<>();
+        for (RuleItemVo ruleItemVo : itemList) {
+            AppPlanToPoint  item = new AppPlanToPoint();
+            item.setPointId(ruleItemVo.getId());
+            item.setPlanId(planId);
+            item.setPointScan(ruleItemVo.isPointScan());
+            item.setRequired(ruleItemVo.isRequired());
+            item.setOfOrgId(ruleItemVo.getOfOrgId());
+            planToPoints.add(item);
+//            appPlanToItemMapper.insert(item);
+        }
+        if(ObjectUtil.isNotEmpty(planToPoints))
+        {
+            appPlanToItemMapper.batchInsertData(planToPoints);
+        }
+    }
+
+    /**
+     * 修改计划下的履职角色
+     * @param plan 计划
+     * @param roleList 新增的计划/编辑后新计划 的角色
+     */
+    private void  updatePlanRole(AppPlan plan,List<Long> roleList)
+    {
+        deletePlanRole(plan.getId());
+        addPlanRole(plan.getId(),roleList);
+    }
+
+    private void deletePlanRole(Long planId){
+        QueryWrapper<AppPlanToRole> apr = new QueryWrapper<>();
+        apr.lambda().eq(AppPlanToRole::getPlanId, planId);
+        appPlanToRoleMapper.delete(apr);
+    }
+
+    private void addPlanRole(Long planId,List<Long> roleList)
+    {
+        if(ObjectUtil.isEmpty(roleList)){
+            return;
+        }
+        List<AppPlanToRole> planToRoles = new ArrayList<>();
+        for (Long roleId : roleList) {
+            AppPlanToRole temp = new AppPlanToRole();
+            temp.setRoleId(roleId);
+            temp.setPlanId(planId);
+            planToRoles.add(temp);
+//            appPlanToRoleMapper.insert(temp);
+        }
+        if(ObjectUtil.isNotEmpty(planToRoles))
+        {
+            appPlanToRoleMapper.batchInsertData(planToRoles);
+        }
+    }
+
+    /**
+     * 获取子计划 对应的履职机构
+     * @param childPlan
+     * @param hsOrgs
+     * @param parentPlanExceOrgs
+     * @return
+     */
+    private List<Long> getChildPlanExceOrgIds(AppPlan childPlan,List<SysOrg> hsOrgs,List<SysOrg> parentPlanExceOrgs)
+    {
+        if(ObjectUtil.isEmpty(parentPlanExceOrgs) || ObjectUtil.isEmpty(hsOrgs))
+        {
+            return new ArrayList<>();
+        }
+
+        SysOrg planOrg =null;
+        final Optional<SysOrg> planOrgOpt = hsOrgs.stream().filter(x -> ObjectUtil.equal(x.getId(), childPlan.getPlanOfOrgId())).findFirst();
+        if(planOrgOpt.isPresent())
+        {
+            planOrg = planOrgOpt.get();
+        }
+        else{
+            planOrg = remoteOrgService.selectSysOrgById(childPlan.getPlanOfOrgId(), SecurityConstants.INNER);
+        }
+        String path =planOrg.getPath();
+        return  parentPlanExceOrgs.stream().filter(x -> x.getPath().contains(path)).map(x -> x.getId()).collect(toList());
+    }
+
+    /**
+     * 修改计划下的履职机构
+     * @param plan 计划
+     * @param orgList 新增的计划/编辑后新计划 的履职机构
+     */
+    private void  updatePlanExecOrg(AppPlan plan,List<Long> orgList)
+    {
+        deletePlanExecOrg(plan.getId());
+
+        addPlanExecOrg(plan.getId(),orgList);
+    }
+
+    private void deletePlanExecOrg(Long planId){
+        QueryWrapper<AppPlanToExecOrg> apr = new QueryWrapper<>();
+        apr.lambda().eq(AppPlanToExecOrg::getPlanId, planId);
+        appPlanToExecOrgMapper.delete(apr);
+    }
+
+    private void addPlanExecOrg(Long planId,List<Long> orgList)
+    {
+        if(ObjectUtil.isEmpty(orgList)){
+            return;
+        }
+        List<AppPlanToExecOrg> planToExecOrgs = new ArrayList<>();
+        for (Long orgId : orgList) {
+            AppPlanToExecOrg execOrg = new AppPlanToExecOrg();
+            execOrg.setOrgId(orgId);
+            execOrg.setPlanId(planId);
+            planToExecOrgs.add(execOrg);
+//            appPlanToExecOrgMapper.insert(execOrg);
+        }
+        if(ObjectUtil.isNotEmpty(planToExecOrgs))
+        {
+            appPlanToExecOrgMapper.batchInsertData(planToExecOrgs);
+        }
+    }
+
+    /**
      * 编辑时,该计划是否需要副本。
      * 1.使用中且还没有到生效时间,不需要;
      * 2.使用中且有已完成时,需要

+ 1 - 1
soc-modules/soc-modules-core/src/main/resources/mapper/resumption/AppPlanMapper.xml

@@ -113,7 +113,7 @@
                 where path like concat((select path from sys_org where id=#{info.orgId}),'%'))
             </if>
         </where>
-        order by a.plan_status asc, a.update_time DESC
+        order by a.update_time DESC
     </select>
     <!--    <select id="selectChildren" parameterType="com.xunmei.core.resumption.dto.plan.CoreResumptionPlanPageDto"-->
     <!--            resultMap="appPlans">-->

+ 1 - 1
soc-modules/soc-modules-core/src/main/resources/mapper/safetycheck/CoreSafecheckPlanMapper.xml

@@ -292,7 +292,7 @@
 
         ) tem
         GROUP BY tem.id,tem.create_time
-        order by tem.plan_status asc, tem.update_time DESC
+        order by tem.update_time DESC
     </select>
     <select id="selectItemIdsByPlanId" resultType="java.lang.String">
         select distinct point_id as item_id