Răsfoiți Sursa

监控调阅任务 执行选择具体调阅机构

zhulu 1 an în urmă
părinte
comite
206fc867ef
13 a modificat fișierele cu 738 adăugiri și 264 ștergeri
  1. 2 0
      project_data/sql/0.0.7/quartz/quartz.sql
  2. 7 0
      project_data/sql/0.0.7/soc/soc.sql
  3. 4 3
      soc-modules/soc-modules-core/src/main/java/com/xunmei/core/access/controller/TMonitoringRetrievalPlanController.java
  4. 30 0
      soc-modules/soc-modules-core/src/main/java/com/xunmei/core/access/domain/TMonitoringRetrievalPlanToExecOrg.java
  5. 111 0
      soc-modules/soc-modules-core/src/main/java/com/xunmei/core/access/dto/TMonitoringRetrievalPlanDto.java
  6. 21 0
      soc-modules/soc-modules-core/src/main/java/com/xunmei/core/access/mapper/TMonitoringRetrievalPlanToExecOrgMapper.java
  7. 5 0
      soc-modules/soc-modules-core/src/main/java/com/xunmei/core/access/service/ITMonitoringRetrievalPlanService.java
  8. 11 0
      soc-modules/soc-modules-core/src/main/java/com/xunmei/core/access/service/ITMonitoringRetrievalPlanToExecOrgService.java
  9. 503 260
      soc-modules/soc-modules-core/src/main/java/com/xunmei/core/access/service/impl/TMonitoringRetrievalPlanServiceImpl.java
  10. 15 0
      soc-modules/soc-modules-core/src/main/java/com/xunmei/core/access/service/impl/TMonitoringRetrievalPlanToExecOrgServiceImpl.java
  11. 5 0
      soc-modules/soc-modules-core/src/main/java/com/xunmei/core/access/vo/TMonitoringRetrievalPlanVO.java
  12. 1 1
      soc-modules/soc-modules-core/src/main/java/com/xunmei/core/retrieval/service/impl/CoreMonitoringRetrievalTaskBuilderServiceImpl.java
  13. 23 0
      soc-modules/soc-modules-core/src/main/resources/mapper/access/TMonitoringRetrievalPlanToExecOrgMapper.xml

+ 2 - 0
project_data/sql/0.0.7/quartz/quartz.sql

@@ -0,0 +1,2 @@
+-- 每天更新履职任务状态 调整为没小时执行一次,解决营业前、中、后的任务 到时间后任务状态变为已逾期的问题
+UPDATE `sys_job` SET `cron_expression` = '0 0 * * * ?' WHERE `job_name` = '每天更新履职任务状态';

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

@@ -0,0 +1,7 @@
+
+-- 新增 监控调阅计划与执行机构关系表
+DROP TABLE IF EXISTS `core_monitoring_retrieval_plan_to_exec_org`;
+CREATE TABLE `core_monitoring_retrieval_plan_to_exec_org`  (
+                                                               `plan_id` bigint NOT NULL COMMENT '计划id',
+                                                               `org_id` bigint NOT NULL COMMENT '机构id'
+) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '监控调阅计划与执行机构关系表' ROW_FORMAT = Dynamic;

+ 4 - 3
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/access/controller/TMonitoringRetrievalPlanController.java

@@ -9,6 +9,7 @@ import com.xunmei.common.log.enums.BusinessType;
 import com.xunmei.common.security.annotation.RequiresPermissions;
 import com.xunmei.common.security.utils.SecurityUtils;
 import com.xunmei.core.access.domain.TMonitoringRetrievalPlan;
+import com.xunmei.core.access.dto.TMonitoringRetrievalPlanDto;
 import com.xunmei.core.access.service.ITMonitoringRetrievalPlanService;
 import com.xunmei.core.access.vo.TMonitoringRetrievalPlanVO;
 import com.xunmei.core.reportForms.monitor.service.MonitorAccessReportService;
@@ -93,8 +94,8 @@ public class TMonitoringRetrievalPlanController extends BaseController {
     @RequiresPermissions("core:accessPlan:add")
     @Log(title = "监控调阅计划", businessType = BusinessType.INSERT)
     @PostMapping
-    public AjaxResult add(@RequestBody TMonitoringRetrievalPlan tMonitoringRetrievalPlan) {
-        return toAjax(tMonitoringRetrievalPlanService.insertTMonitoringRetrievalPlan(tMonitoringRetrievalPlan));
+    public AjaxResult add(@RequestBody TMonitoringRetrievalPlanDto tMonitoringRetrievalPlanDto) {
+        return toAjax(tMonitoringRetrievalPlanService.insertTMonitoringRetrievalPlan(tMonitoringRetrievalPlanDto));
     }
 
     /**
@@ -104,7 +105,7 @@ public class TMonitoringRetrievalPlanController extends BaseController {
     @RequiresPermissions("core:accessPlan:edit")
     @Log(title = "监控调阅计划", businessType = BusinessType.UPDATE)
     @PutMapping
-    public AjaxResult edit(@RequestBody TMonitoringRetrievalPlan tMonitoringRetrievalPlan) {
+    public AjaxResult edit(@RequestBody TMonitoringRetrievalPlanDto tMonitoringRetrievalPlan) throws ParseException  {
         return toAjax(tMonitoringRetrievalPlanService.updateTMonitoringRetrievalPlan(tMonitoringRetrievalPlan));
     }
 

+ 30 - 0
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/access/domain/TMonitoringRetrievalPlanToExecOrg.java

@@ -0,0 +1,30 @@
+package com.xunmei.core.access.domain;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import io.swagger.annotations.ApiModel;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+
+
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@TableName("core_monitoring_retrieval_plan_to_exec_org")
+@ApiModel(value = "TMonitoringRetrievalPlanToExecOrg对象", description = "监控调阅计划与执行机构关系表")
+public class TMonitoringRetrievalPlanToExecOrg {
+    @TableField("plan_id")
+    private Long planId;
+
+    @TableField("org_id")
+    private Long orgId;
+
+    @TableField(exist = false)
+    private String orgName;
+
+    @TableField(exist = false)
+    private String orgPath;
+
+}

+ 111 - 0
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/access/dto/TMonitoringRetrievalPlanDto.java

@@ -0,0 +1,111 @@
+package com.xunmei.core.access.dto;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.Date;
+import java.util.List;
+
+@Data
+public class TMonitoringRetrievalPlanDto {
+
+    /**
+     * 主键
+     */
+    @JsonSerialize(using = ToStringSerializer.class)
+    private Long id;
+
+    /**
+     * 上级id
+     */
+    @JsonSerialize(using = ToStringSerializer.class)
+    @ApiModelProperty(value = "上级id")
+    private Long parentId;
+    /**
+     * 计划名称
+     */
+    @ApiModelProperty(value = "计划名称")
+    private String planName;
+    @ApiModelProperty(value = "是否显示下发")
+    private String isDistribute;
+    @ApiModelProperty(value = "是否立即生效", notes = "0:否,1:是")
+    private Boolean immediately = Boolean.FALSE;
+
+    /**
+     * 计划归属机构
+     */
+    @ApiModelProperty(value = "计划归属机构")
+    @JsonSerialize(using = ToStringSerializer.class)
+    private Long orgId;
+    @ApiModelProperty(value = "开始时间")
+    // @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date startTime;
+    @ApiModelProperty(value = "结束时间")
+    // @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date endTime;
+    @ApiModelProperty(value = "下发类型0不能做任务1可以直接做任务")
+    private Integer createType;
+    /**
+     * 计划归属机构
+     */
+    @ApiModelProperty(value = "计划归属机构")
+    private String orgPath;
+
+    /**
+     * 计划归属机构
+     */
+    @ApiModelProperty(value = "创建机构")
+    private String orgName;
+    @ApiModelProperty(value = "所属机构")
+    private String organization;
+    /**
+     * 调阅机构类型
+     */
+    @ApiModelProperty(value = "调阅机构类型")
+    private String orgType;
+
+    /**
+     * 调阅角色
+     */
+    @ApiModelProperty(value = "调阅角色")
+    private Long roleId;
+    @ApiModelProperty(value = "调阅角色")
+    private String roleName;
+    /**
+     * 调阅周期无周期、每日、每周、每月、每季度、每半年、每年(0-6)
+     */
+    @ApiModelProperty(value = "调阅周期无周期、每日、每周、每月、每季度、每半年、每年", notes = "0=-6")
+    private String planCycle;
+
+    /**
+     * 调阅频次
+     */
+    @ApiModelProperty(value = "调阅频次")
+    private Long planFrequency;
+
+    /**
+     * 计划状态
+     */
+    @ApiModelProperty(value = "计划状态")
+
+    private Integer planStatus;
+
+    /**
+     * 备注
+     */
+    @ApiModelProperty(value = "备注")
+    private String description;
+
+    /**
+     * 是否删除(0正常,1删除)
+     */
+    @ApiModelProperty(value = "是否删除", notes = "0=正常,1删除")
+    private Long isDeleted;
+
+    @ApiModelProperty(value = "计划执行具体机构")
+    private List<Long> planExecOrgIdList;
+}

+ 21 - 0
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/access/mapper/TMonitoringRetrievalPlanToExecOrgMapper.java

@@ -0,0 +1,21 @@
+package com.xunmei.core.access.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.xunmei.core.access.domain.TMonitoringRetrievalPlanToExecOrg;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * @author jingyuanchao
+ * @date 2023/8/25 14:27
+ */
+public interface TMonitoringRetrievalPlanToExecOrgMapper extends BaseMapper<TMonitoringRetrievalPlanToExecOrg> {
+
+    List<TMonitoringRetrievalPlanToExecOrg> selectLisByPlanId(@Param("planId") Long planId);
+
+    Integer deleteLisByPlanId(@Param("planId") Long planId);
+
+
+    List<Long> selectOrgIdByPlanId(@Param("planId") Long planId);
+}

+ 5 - 0
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/access/service/ITMonitoringRetrievalPlanService.java

@@ -3,6 +3,7 @@ package com.xunmei.core.access.service;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.xunmei.common.core.web.page.TableDataInfo;
 import com.xunmei.core.access.domain.TMonitoringRetrievalPlan;
+import com.xunmei.core.access.dto.TMonitoringRetrievalPlanDto;
 import com.xunmei.core.access.vo.AccessPdfVO;
 import com.xunmei.core.access.vo.TMonitoringRetrievalPlanVO;
 import com.xunmei.core.safetyCheck.domain.CoreSafetyTask;
@@ -54,6 +55,8 @@ public interface ITMonitoringRetrievalPlanService extends IService<TMonitoringRe
      */
     int insertTMonitoringRetrievalPlan(TMonitoringRetrievalPlan tMonitoringRetrievalPlan);
 
+    int insertTMonitoringRetrievalPlan(TMonitoringRetrievalPlanDto tMonitoringRetrievalPlanDto);
+
     /**
      * 修改监控调阅计划
      *
@@ -62,6 +65,8 @@ public interface ITMonitoringRetrievalPlanService extends IService<TMonitoringRe
      */
     int updateTMonitoringRetrievalPlan(TMonitoringRetrievalPlan tMonitoringRetrievalPlan);
 
+    int updateTMonitoringRetrievalPlan(TMonitoringRetrievalPlanDto tMonitoringRetrievalPlanDto) throws ParseException;
+
     void updateComplete(boolean isComplete, TMonitoringRetrievalPlan tMonitoringRetrievalPlan, TMonitoringRetrievalPlan plan);
 
     /**

+ 11 - 0
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/access/service/ITMonitoringRetrievalPlanToExecOrgService.java

@@ -0,0 +1,11 @@
+package com.xunmei.core.access.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.xunmei.core.access.domain.TMonitoringRetrievalPlanToExecOrg;
+
+/**
+ * @author jingyuanchao
+ * @date 2023/8/25 14:30
+ */
+public interface ITMonitoringRetrievalPlanToExecOrgService extends IService<TMonitoringRetrievalPlanToExecOrg> {
+}

+ 503 - 260
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/access/service/impl/TMonitoringRetrievalPlanServiceImpl.java

@@ -1,17 +1,15 @@
 package com.xunmei.core.access.service.impl;
 
 
-import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.map.MapUtil;
 import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.nacos.common.utils.CollectionUtils;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-
 import com.xunmei.common.core.constant.ErrorMsgConstants;
 import com.xunmei.common.core.constant.SecurityConstants;
-import com.xunmei.common.core.domain.DateRange;
 import com.xunmei.common.core.domain.registerbook.domain.CoreRegisterBookPdf;
 import com.xunmei.common.core.domain.retrieval.domain.CoreMonitoringRetrievalTask;
 import com.xunmei.common.core.enums.RegisterBookType;
@@ -19,35 +17,35 @@ import com.xunmei.common.core.exception.ServiceException;
 import com.xunmei.common.core.exception.SystemException;
 import com.xunmei.common.core.utils.DateUtils;
 import com.xunmei.common.core.utils.StringUtils;
-
-import com.xunmei.common.core.web.domain.AjaxResult;
 import com.xunmei.common.core.web.page.TableDataInfo;
 import com.xunmei.common.redis.utils.RedisUtils;
 import com.xunmei.common.security.utils.SecurityUtils;
-import com.xunmei.core.access.domain.CoreMonitoringTaskRegistration;
 import com.xunmei.core.access.domain.TMonitoringRetrievalPlan;
+import com.xunmei.core.access.domain.TMonitoringRetrievalPlanToExecOrg;
+import com.xunmei.core.access.dto.TMonitoringRetrievalPlanDto;
 import com.xunmei.core.access.mapper.TMonitoringRetrievalPlanMapper;
+import com.xunmei.core.access.mapper.TMonitoringRetrievalPlanToExecOrgMapper;
 import com.xunmei.core.access.service.ITMonitoringRetrievalPlanService;
-
+import com.xunmei.core.access.service.ITMonitoringRetrievalPlanToExecOrgService;
 import com.xunmei.core.access.vo.AccessPdfVO;
 import com.xunmei.core.access.vo.TMonitoringRetrievalPlanVO;
 import com.xunmei.core.registerbook.service.ICoreRegisterBookPdfService;
 import com.xunmei.core.retrieval.mapper.CoreMonitoringRetrievalTaskMapper;
 import com.xunmei.core.retrieval.service.ICoreMonitoringRetrievalTaskBuilderService;
 import com.xunmei.core.retrieval.service.ICoreMonitoringRetrievalTaskService;
-
-import com.xunmei.core.safetyCheck.domain.CoreSafetyTask;
-import com.xunmei.core.safetyCheck.vo.regsiter.AppTaskRegisterPointVo;
+import com.xunmei.core.thread.ThreadPoolConfig;
 import com.xunmei.system.api.RemoteFileService;
 import com.xunmei.system.api.RemoteOrgService;
 import com.xunmei.system.api.RemoteRoleService;
 import com.xunmei.system.api.RemoteUserService;
 import com.xunmei.system.api.domain.*;
-
+import com.xunmei.system.api.function.RemoteCallHandlerExecutor;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.scheduling.annotation.Async;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
@@ -56,10 +54,12 @@ import javax.annotation.Resource;
 import java.io.File;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
-import java.time.Duration;
 import java.time.LocalDate;
-import java.util.*;
-
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
 import java.util.stream.Collectors;
 
 
@@ -97,6 +97,16 @@ public class TMonitoringRetrievalPlanServiceImpl extends ServiceImpl<TMonitoring
     @Autowired
     private ICoreRegisterBookPdfService iCoreRegisterBookPdfService;
 
+    @Autowired
+    private ITMonitoringRetrievalPlanToExecOrgService itMonitoringRetrievalPlanToExecOrgService;
+
+    @Autowired
+    TMonitoringRetrievalPlanToExecOrgMapper tMonitoringRetrievalPlanToExecOrgMapper;
+
+    @Autowired
+    @Qualifier(ThreadPoolConfig.SOC_EXECUTOR)
+    private ThreadPoolTaskExecutor threadPoolTaskExecutor;
+
     @Override
     public TableDataInfo selectPage(TMonitoringRetrievalPlan tMonitoringRetrievalPlan) {
         //未删除
@@ -190,6 +200,9 @@ public class TMonitoringRetrievalPlanServiceImpl extends ServiceImpl<TMonitoring
         }
         tMonitoringRetrievalPlanVO.setIsHaveTask(haveTask);
         tMonitoringRetrievalPlanVO.setIsComplete(isComplete);
+        final List<TMonitoringRetrievalPlanToExecOrg> execOrgList = tMonitoringRetrievalPlanToExecOrgMapper.selectByMap(MapUtil.of("plan_id", id));
+        final List<Long> execOrgIdList = execOrgList.stream().map(TMonitoringRetrievalPlanToExecOrg::getOrgId).collect(Collectors.toList());
+        tMonitoringRetrievalPlanVO.setPlanExecOrgIdList(ObjectUtil.isEmpty(execOrgIdList) ? null : execOrgIdList);
         return tMonitoringRetrievalPlanVO;
     }
 
@@ -204,6 +217,9 @@ public class TMonitoringRetrievalPlanServiceImpl extends ServiceImpl<TMonitoring
         tMonitoringRetrievalPlan.setUpdateTime(DateUtils.getNowDate());
         tMonitoringRetrievalPlan.setUpdateBy(SecurityUtils.getUsername());
         tMonitoringRetrievalPlanMapper.updateById(tMonitoringRetrievalPlan);
+
+        final List<TMonitoringRetrievalPlanToExecOrg> planExecOrgList = tMonitoringRetrievalPlanToExecOrgMapper.selectByMap(MapUtil.of("plan_id", id));
+
         Integer i = 1;
         QueryWrapper queryWrapper = new QueryWrapper();
         queryWrapper.eq(PARENT_ID, id);
@@ -215,117 +231,122 @@ public class TMonitoringRetrievalPlanServiceImpl extends ServiceImpl<TMonitoring
         //如果当前是省联社
         if (nowUserOrg.getType() == 1) {
             //如果顶级
-            SysOrg org = new SysOrg();
-            org.setType(3);
-            org.setPath(topOrg.getPath());
             if (CollectionUtils.isNotEmpty(list1)) {
                 for (TMonitoringRetrievalPlan tm : list1) {
                     tm.setPlanStatus(1);
                     tm.setIsDistribute("1");
                     baseMapper.updateById(tm);
                     if (tMonitoringRetrievalPlan.getOrgType().equals("3")) {
-                        if (!tMonitoringRetrievalPlan.getPlanCycle().equals(ZERO.toString()) &&
-                                tMonitoringRetrievalPlan.getImmediately().equals(Boolean.TRUE)) {
-                            tm.setStartTime(new Date());
-                            int amount = 0;
-                            LocalDate lastDayOfMonth;
-                            switch (tMonitoringRetrievalPlan.getPlanCycle()) {
-                                case "2":
-                                    amount = 7;
-                                    break;
-                                case "3":
-                                    LocalDate currentDate = LocalDate.now();
-                                    lastDayOfMonth = currentDate.withDayOfMonth(currentDate.lengthOfMonth());
-                                    amount = lastDayOfMonth.getDayOfMonth() - currentDate.getDayOfMonth();
-                                    break;
-                                case "4":
-                                    amount = getDayNum(3);
-                                    break;
-                                case "5":
-                                    amount = getDayNum(6);
-                                    break;
-                                case "6":
-                                    amount = getDayNum(12);
-                                    break;
-                                default:
-                                    amount = 1;
-                                    break;
-                            }
-                            Calendar cal = Calendar.getInstance();
-                            cal.setTime(new Date());
-                            cal.add(Calendar.DATE, amount);
-                            Date time = cal.getTime();
-                            tm.setEndTime(time);
-                            tMonitoringRetrievalPlans.add(tm);
-                        }
+//                        if (!tMonitoringRetrievalPlan.getPlanCycle().equals(ZERO.toString()) &&
+//                                tMonitoringRetrievalPlan.getImmediately().equals(Boolean.TRUE)) {
+//                            tm.setStartTime(new Date());
+//                            int amount = 0;
+//                            LocalDate lastDayOfMonth;
+//                            switch (tMonitoringRetrievalPlan.getPlanCycle()) {
+//
+//                                case "2":
+//                                    amount = 7;
+//                                    break;
+//                                case "3":
+//                                    LocalDate currentDate = LocalDate.now();
+//                                    lastDayOfMonth = currentDate.withDayOfMonth(currentDate.lengthOfMonth());
+//                                    amount = lastDayOfMonth.getDayOfMonth() - currentDate.getDayOfMonth();
+//                                    break;
+//                                case "4":
+//                                    amount = getDayNum(3);
+//                                    break;
+//                                case "5":
+//                                    amount = getDayNum(6);
+//                                    break;
+//                                case "6":
+//                                    amount = getDayNum(12);
+//                                    break;
+//                                default:
+//                                    amount = 1;
+//                                    break;
+//                            }
+//                            Calendar cal = Calendar.getInstance();
+//                            cal.setTime(new Date());
+//                            cal.add(Calendar.DATE, amount);
+//                            Date time = cal.getTime();
+//                            tm.setEndTime(time);
+//                        }
+                        setPlanStartEndTime(tMonitoringRetrievalPlan,tm);
+                        tMonitoringRetrievalPlans.add(tm);
                     } else {
-                        SysOrg sysOrg = new SysOrg();
-                        sysOrg.setPath(tm.getOrgPath());
-                        sysOrg.setType(Integer.valueOf(tMonitoringRetrievalPlan.getOrgType()));
-                        List<SysOrg> sysOrgs = remoteOrgService.listByParentIdAndType(sysOrg, SecurityConstants.INNER);
+//                        SysOrg sysOrg = new SysOrg();
+//                        sysOrg.setPath(tm.getOrgPath());
+//                        sysOrg.setType(Integer.valueOf(tMonitoringRetrievalPlan.getOrgType()));
+//                        List<SysOrg> sysOrgs = remoteOrgService.listByParentIdAndType(sysOrg, SecurityConstants.INNER);
+                        List<SysOrg> sysOrgs=getExecOrgList(planExecOrgList,Integer.valueOf(tMonitoringRetrievalPlan.getOrgType()),tm.getOrgPath());
                         for (SysOrg s : sysOrgs) {
-                            TMonitoringRetrievalPlan plan = new TMonitoringRetrievalPlan();
-                            BeanUtils.copyProperties(tMonitoringRetrievalPlan, plan);
-                            plan.setPlanName(tMonitoringRetrievalPlan.getPlanName());
-                            plan.setOrgId(s.getId());
-                            plan.setOrganization(s.getShortName());
-                            plan.setOrgName(s.getShortName());
-                            plan.setOrganization(s.getShortName());
-                            plan.setRoleId(tMonitoringRetrievalPlan.getRoleId());
-                            plan.setRoleName(tMonitoringRetrievalPlan.getRoleName());
-                            plan.setOrgPath(s.getPath());
-                            plan.setOrgType(tMonitoringRetrievalPlan.getOrgType());
-                            plan.setPlanCycle(tMonitoringRetrievalPlan.getPlanCycle());
-                            plan.setPlanFrequency(tMonitoringRetrievalPlan.getPlanFrequency());
-                            plan.setPlanStatus(ZERO);
-                            plan.setCreateBy(SecurityUtils.getUsername());
-                            plan.setUpdateTime(DateUtils.getNowDate());
-                            plan.setUpdateBy(SecurityUtils.getUsername());
-                            plan.setCreateTime(DateUtils.getNowDate());
-                            plan.setDescription(tMonitoringRetrievalPlan.getDescription());
-                            plan.setCreateType(1);
-                            plan.setParentId(tMonitoringRetrievalPlan.getId());
-                            plan.setIsDistribute("1");
-                            if (!tMonitoringRetrievalPlan.getPlanCycle().equals(ZERO.toString()) &&
-                                    tMonitoringRetrievalPlan.getImmediately().equals(Boolean.TRUE)) {
-                                plan.setStartTime(new Date());
-                                int amount = 0;
-                                LocalDate lastDayOfMonth;
-                                switch (tMonitoringRetrievalPlan.getPlanCycle()) {
-                                    case "2":
-                                        amount = 7;
-                                        break;
-                                    case "3":
-                                        LocalDate currentDate = LocalDate.now();
-                                        lastDayOfMonth = currentDate.withDayOfMonth(currentDate.lengthOfMonth());
-                                        amount = lastDayOfMonth.getDayOfMonth() - currentDate.getDayOfMonth();
-                                        break;
-                                    case "4":
-                                        amount = getDayNum(3);
-                                        break;
-                                    case "5":
-                                        amount = getDayNum(6);
-                                        break;
-                                    case "6":
-                                        amount = getDayNum(12);
-                                        break;
-                                    default:
-                                        amount = 1;
-                                        break;
-                                }
-                                Calendar cal = Calendar.getInstance();
-                                cal.setTime(new Date());
-                                cal.add(Calendar.DATE, amount);
-                                Date time = cal.getTime();
-                                plan.setEndTime(time);
-                            }
+//                            TMonitoringRetrievalPlan plan = new TMonitoringRetrievalPlan();
+//                            BeanUtils.copyProperties(tMonitoringRetrievalPlan, plan);
+//                            plan.setPlanName(tMonitoringRetrievalPlan.getPlanName());
+//                            plan.setOrgId(s.getId());
+//                            plan.setOrganization(s.getShortName());
+//                            plan.setOrgName(s.getShortName());
+//                            plan.setOrganization(s.getShortName());
+//                            plan.setRoleId(tMonitoringRetrievalPlan.getRoleId());
+//                            plan.setRoleName(tMonitoringRetrievalPlan.getRoleName());
+//                            plan.setOrgPath(s.getPath());
+//                            plan.setOrgType(tMonitoringRetrievalPlan.getOrgType());
+//                            plan.setPlanCycle(tMonitoringRetrievalPlan.getPlanCycle());
+//                            plan.setPlanFrequency(tMonitoringRetrievalPlan.getPlanFrequency());
+//                            plan.setPlanStatus(ZERO);
+//                            plan.setCreateBy(SecurityUtils.getUsername());
+//                            plan.setUpdateTime(DateUtils.getNowDate());
+//                            plan.setUpdateBy(SecurityUtils.getUsername());
+//                            plan.setCreateTime(DateUtils.getNowDate());
+//                            plan.setDescription(tMonitoringRetrievalPlan.getDescription());
+//                            plan.setCreateType(1);
+//                            plan.setParentId(tMonitoringRetrievalPlan.getId());
+//                            plan.setIsDistribute("1");
+//                            if (!tMonitoringRetrievalPlan.getPlanCycle().equals(ZERO.toString()) &&
+//                                    tMonitoringRetrievalPlan.getImmediately().equals(Boolean.TRUE)) {
+//                                plan.setStartTime(new Date());
+//                                int amount = 0;
+//                                LocalDate lastDayOfMonth;
+//                                switch (tMonitoringRetrievalPlan.getPlanCycle()) {
+//                                    case "2":
+//                                        amount = 7;
+//                                        break;
+//                                    case "3":
+//                                        LocalDate currentDate = LocalDate.now();
+//                                        lastDayOfMonth = currentDate.withDayOfMonth(currentDate.lengthOfMonth());
+//                                        amount = lastDayOfMonth.getDayOfMonth() - currentDate.getDayOfMonth();
+//                                        break;
+//                                    case "4":
+//                                        amount = getDayNum(3);
+//                                        break;
+//                                    case "5":
+//                                        amount = getDayNum(6);
+//                                        break;
+//                                    case "6":
+//                                        amount = getDayNum(12);
+//                                        break;
+//                                    default:
+//                                        amount = 1;
+//                                        break;
+//                                }
+//                                Calendar cal = Calendar.getInstance();
+//                                cal.setTime(new Date());
+//                                cal.add(Calendar.DATE, amount);
+//                                Date time = cal.getTime();
+//                                plan.setEndTime(time);
+//                            }
+                            TMonitoringRetrievalPlan plan = createTempPlan(tMonitoringRetrievalPlan,tMonitoringRetrievalPlan.getId(),s);
                             tMonitoringRetrievalPlans.add(plan);
                         }
                     }
                 }
             } else {
+//                SysOrg org = new SysOrg();
+//                org.setType(3);
+//                org.setPath(topOrg.getPath());
                 //查询符合的机构,需求是先把行社加入
-                List<SysOrg> list = remoteOrgService.listByParentIdAndType(org, SecurityConstants.INNER);
+//                List<SysOrg> list = remoteOrgService.listByParentIdAndType(org, SecurityConstants.INNER);
+                List<SysOrg> list=getExecOrgList(planExecOrgList,3,topOrg.getPath());
                 for (SysOrg l : list) {
                     TMonitoringRetrievalPlan tMonitoringRetrievalPlan1 = new TMonitoringRetrievalPlan();
                     BeanUtils.copyProperties(tMonitoringRetrievalPlan, tMonitoringRetrievalPlan1);
@@ -340,109 +361,115 @@ public class TMonitoringRetrievalPlanServiceImpl extends ServiceImpl<TMonitoring
                         SysOrg sysOrg = remoteOrgService.selectSysOrgById(tMonitoringRetrievalPlan.getOrgId(), SecurityConstants.INNER);
                         tMonitoringRetrievalPlan1.setOrgName(sysOrg.getShortName());
                         i = insertTMonitoringRetrievalPlan(tMonitoringRetrievalPlan1);
+                        if(ObjectUtil.isNotEmpty(planExecOrgList)){
+                            batchSavePlanToExecOrg(planExecOrgList.stream().map(x->x.getOrgId()).collect(Collectors.toList()), tMonitoringRetrievalPlan1.getId());
+                        }
                     }
                     if (tMonitoringRetrievalPlan.getOrgType().equals("3")) {
                         tMonitoringRetrievalPlan.setCreateType(1);
                         tMonitoringRetrievalPlan.setUpdateBy(SecurityUtils.getUsername());
                         tMonitoringRetrievalPlan.setUpdateTime(DateUtils.getNowDate());
                         baseMapper.updateById(tMonitoringRetrievalPlan);
-                        if (!tMonitoringRetrievalPlan.getPlanCycle().equals(ZERO.toString()) &&
-                                tMonitoringRetrievalPlan.getImmediately().equals(Boolean.TRUE)) {
-                            tMonitoringRetrievalPlan1.setStartTime(new Date());
-                            int amount = 0;
-                            LocalDate lastDayOfMonth;
-                            switch (tMonitoringRetrievalPlan.getPlanCycle()) {
-
-                                case "2":
-                                    amount = 7;
-                                    break;
-                                case "3":
-                                    LocalDate currentDate = LocalDate.now();
-                                    lastDayOfMonth = currentDate.withDayOfMonth(currentDate.lengthOfMonth());
-                                    amount = lastDayOfMonth.getDayOfMonth() - currentDate.getDayOfMonth();
-                                    break;
-                                case "4":
-                                    amount = getDayNum(3);
-                                    break;
-                                case "5":
-                                    amount = getDayNum(6);
-                                    break;
-                                case "6":
-                                    amount = getDayNum(12);
-                                    break;
-                                default:
-                                    amount = 1;
-                                    break;
-                            }
-                            Calendar cal = Calendar.getInstance();
-                            cal.setTime(new Date());
-                            cal.add(Calendar.DATE, amount);
-                            Date time = cal.getTime();
-                            tMonitoringRetrievalPlan1.setEndTime(time);
-                        }
+//                        if (!tMonitoringRetrievalPlan.getPlanCycle().equals(ZERO.toString()) &&
+//                                tMonitoringRetrievalPlan.getImmediately().equals(Boolean.TRUE)) {
+//                            tMonitoringRetrievalPlan1.setStartTime(new Date());
+//                            int amount = 0;
+//                            LocalDate lastDayOfMonth;
+//                            switch (tMonitoringRetrievalPlan.getPlanCycle()) {
+//
+//                                case "2":
+//                                    amount = 7;
+//                                    break;
+//                                case "3":
+//                                    LocalDate currentDate = LocalDate.now();
+//                                    lastDayOfMonth = currentDate.withDayOfMonth(currentDate.lengthOfMonth());
+//                                    amount = lastDayOfMonth.getDayOfMonth() - currentDate.getDayOfMonth();
+//                                    break;
+//                                case "4":
+//                                    amount = getDayNum(3);
+//                                    break;
+//                                case "5":
+//                                    amount = getDayNum(6);
+//                                    break;
+//                                case "6":
+//                                    amount = getDayNum(12);
+//                                    break;
+//                                default:
+//                                    amount = 1;
+//                                    break;
+//                            }
+//                            Calendar cal = Calendar.getInstance();
+//                            cal.setTime(new Date());
+//                            cal.add(Calendar.DATE, amount);
+//                            Date time = cal.getTime();
+//                            tMonitoringRetrievalPlan1.setEndTime(time);
+//                        }
+                        setPlanStartEndTime(tMonitoringRetrievalPlan,tMonitoringRetrievalPlan1);
                         tMonitoringRetrievalPlans.add(tMonitoringRetrievalPlan1);
                     } else {
-                        SysOrg sysOrg = new SysOrg();
-                        sysOrg.setPath(l.getPath());
-                        sysOrg.setType(Integer.valueOf(tMonitoringRetrievalPlan.getOrgType()));
-                        List<SysOrg> sysOrgs = remoteOrgService.listByParentIdAndType(sysOrg, SecurityConstants.INNER);
+//                        SysOrg sysOrg = new SysOrg();
+//                        sysOrg.setPath(l.getPath());
+//                        sysOrg.setType(Integer.valueOf(tMonitoringRetrievalPlan.getOrgType()));
+//                        List<SysOrg> sysOrgs = remoteOrgService.listByParentIdAndType(sysOrg, SecurityConstants.INNER);
+                        List<SysOrg> sysOrgs=getExecOrgList(planExecOrgList,Integer.valueOf(tMonitoringRetrievalPlan.getOrgType()),l.getPath());
                         for (SysOrg s : sysOrgs) {
-                            TMonitoringRetrievalPlan plan = new TMonitoringRetrievalPlan();
-                            BeanUtils.copyProperties(tMonitoringRetrievalPlan, plan);
-                            plan.setPlanName(tMonitoringRetrievalPlan.getPlanName());
-                            plan.setOrgId(s.getId());
-                            plan.setOrganization(s.getShortName());
-                            plan.setId(tMonitoringRetrievalPlan1.getId());
-                            plan.setOrgName(s.getShortName());
-                            plan.setRoleId(tMonitoringRetrievalPlan.getRoleId());
-                            plan.setRoleName(tMonitoringRetrievalPlan.getRoleName());
-                            plan.setOrgPath(s.getPath());
-                            plan.setOrgType(tMonitoringRetrievalPlan.getOrgType());
-                            plan.setPlanCycle(tMonitoringRetrievalPlan.getPlanCycle());
-                            plan.setPlanFrequency(tMonitoringRetrievalPlan.getPlanFrequency());
-                            plan.setPlanStatus(ZERO);
-                            plan.setCreateBy(SecurityUtils.getUsername());
-                            plan.setUpdateTime(DateUtils.getNowDate());
-                            plan.setUpdateBy(SecurityUtils.getUsername());
-                            plan.setCreateTime(DateUtils.getNowDate());
-                            plan.setDescription(tMonitoringRetrievalPlan.getDescription());
-                            plan.setCreateType(1);
-                            plan.setParentId(tMonitoringRetrievalPlan.getId());
-                            plan.setIsDistribute("1");
-                            if (!tMonitoringRetrievalPlan.getPlanCycle().equals(ZERO.toString()) &&
-                                    tMonitoringRetrievalPlan.getImmediately().equals(Boolean.TRUE)) {
-                                plan.setStartTime(new Date());
-                                int amount = 0;
-                                LocalDate lastDayOfMonth;
-                                switch (tMonitoringRetrievalPlan.getPlanCycle()) {
-
-                                    case "2":
-                                        amount = 7;
-                                        break;
-                                    case "3":
-                                        LocalDate currentDate = LocalDate.now();
-                                        lastDayOfMonth = currentDate.withDayOfMonth(currentDate.lengthOfMonth());
-                                        amount = lastDayOfMonth.getDayOfMonth() - currentDate.getDayOfMonth();
-                                        break;
-                                    case "4":
-                                        amount = getDayNum(3);
-                                        break;
-                                    case "5":
-                                        amount = getDayNum(6);
-                                        break;
-                                    case "6":
-                                        amount = getDayNum(12);
-                                        break;
-                                    default:
-                                        amount = 1;
-                                        break;
-                                }
-                                Calendar cal = Calendar.getInstance();
-                                cal.setTime(new Date());
-                                cal.add(Calendar.DATE, amount);
-                                Date time = cal.getTime();
-                                plan.setEndTime(time);
-                            }
+//                            TMonitoringRetrievalPlan plan = new TMonitoringRetrievalPlan();
+//                            BeanUtils.copyProperties(tMonitoringRetrievalPlan, plan);
+//                            plan.setPlanName(tMonitoringRetrievalPlan.getPlanName());
+//                            plan.setOrgId(s.getId());
+//                            plan.setOrganization(s.getShortName());
+//                            plan.setId(tMonitoringRetrievalPlan1.getId());
+//                            plan.setOrgName(s.getShortName());
+//                            plan.setRoleId(tMonitoringRetrievalPlan.getRoleId());
+//                            plan.setRoleName(tMonitoringRetrievalPlan.getRoleName());
+//                            plan.setOrgPath(s.getPath());
+//                            plan.setOrgType(tMonitoringRetrievalPlan.getOrgType());
+//                            plan.setPlanCycle(tMonitoringRetrievalPlan.getPlanCycle());
+//                            plan.setPlanFrequency(tMonitoringRetrievalPlan.getPlanFrequency());
+//                            plan.setPlanStatus(ZERO);
+//                            plan.setCreateBy(SecurityUtils.getUsername());
+//                            plan.setUpdateTime(DateUtils.getNowDate());
+//                            plan.setUpdateBy(SecurityUtils.getUsername());
+//                            plan.setCreateTime(DateUtils.getNowDate());
+//                            plan.setDescription(tMonitoringRetrievalPlan.getDescription());
+//                            plan.setCreateType(1);
+//                            plan.setParentId(tMonitoringRetrievalPlan.getId());
+//                            plan.setIsDistribute("1");
+//                            if (!tMonitoringRetrievalPlan.getPlanCycle().equals(ZERO.toString()) &&
+//                                    tMonitoringRetrievalPlan.getImmediately().equals(Boolean.TRUE)) {
+//                                plan.setStartTime(new Date());
+//                                int amount = 0;
+//                                LocalDate lastDayOfMonth;
+//                                switch (tMonitoringRetrievalPlan.getPlanCycle()) {
+//
+//                                    case "2":
+//                                        amount = 7;
+//                                        break;
+//                                    case "3":
+//                                        LocalDate currentDate = LocalDate.now();
+//                                        lastDayOfMonth = currentDate.withDayOfMonth(currentDate.lengthOfMonth());
+//                                        amount = lastDayOfMonth.getDayOfMonth() - currentDate.getDayOfMonth();
+//                                        break;
+//                                    case "4":
+//                                        amount = getDayNum(3);
+//                                        break;
+//                                    case "5":
+//                                        amount = getDayNum(6);
+//                                        break;
+//                                    case "6":
+//                                        amount = getDayNum(12);
+//                                        break;
+//                                    default:
+//                                        amount = 1;
+//                                        break;
+//                                }
+//                                Calendar cal = Calendar.getInstance();
+//                                cal.setTime(new Date());
+//                                cal.add(Calendar.DATE, amount);
+//                                Date time = cal.getTime();
+//                                plan.setEndTime(time);
+//                            }
+                            TMonitoringRetrievalPlan plan = createTempPlan(tMonitoringRetrievalPlan,tMonitoringRetrievalPlan1.getId(),s);
                             tMonitoringRetrievalPlans.add(plan);
                         }
                     }
@@ -457,61 +484,62 @@ public class TMonitoringRetrievalPlanServiceImpl extends ServiceImpl<TMonitoring
             sysOrg.setType(Integer.valueOf(tMonitoringRetrievalPlan.getOrgType()));
             List<SysOrg> sysOrgs = remoteOrgService.listByParentIdAndType(sysOrg, SecurityConstants.INNER);
             for (SysOrg s : sysOrgs) {
-                TMonitoringRetrievalPlan plan = new TMonitoringRetrievalPlan();
-                BeanUtils.copyProperties(tMonitoringRetrievalPlan, plan);
-                plan.setPlanName(tMonitoringRetrievalPlan.getPlanName());
-                plan.setOrgId(s.getId());
-                plan.setOrganization(s.getShortName());
-                plan.setOrgName(s.getShortName());
-                plan.setRoleId(tMonitoringRetrievalPlan.getRoleId());
-                plan.setRoleName(tMonitoringRetrievalPlan.getRoleName());
-                plan.setOrgPath(s.getPath());
-                plan.setOrgType(tMonitoringRetrievalPlan.getOrgType());
-                plan.setPlanCycle(tMonitoringRetrievalPlan.getPlanCycle());
-                plan.setPlanFrequency(tMonitoringRetrievalPlan.getPlanFrequency());
-                plan.setPlanStatus(ZERO);
-                plan.setCreateBy(SecurityUtils.getUsername());
-                plan.setUpdateTime(DateUtils.getNowDate());
-                plan.setUpdateBy(SecurityUtils.getUsername());
-                plan.setCreateTime(DateUtils.getNowDate());
-                plan.setDescription(tMonitoringRetrievalPlan.getDescription());
-                plan.setCreateType(1);
-                plan.setParentId(tMonitoringRetrievalPlan.getId());
-                plan.setIsDistribute("1");
-                if (!tMonitoringRetrievalPlan.getPlanCycle().equals(ZERO.toString()) &&
-                        tMonitoringRetrievalPlan.getImmediately().equals(Boolean.TRUE)) {
-                    plan.setStartTime(new Date());
-                    int amount = 0;
-                    LocalDate lastDayOfMonth;
-                    switch (tMonitoringRetrievalPlan.getPlanCycle()) {
-
-                        case "2":
-                            amount = 7;
-                            break;
-                        case "3":
-                            LocalDate currentDate = LocalDate.now();
-                            lastDayOfMonth = currentDate.withDayOfMonth(currentDate.lengthOfMonth());
-                            amount = lastDayOfMonth.getDayOfMonth() - currentDate.getDayOfMonth();
-                            break;
-                        case "4":
-                            amount = getDayNum(3);
-                            break;
-                        case "5":
-                            amount = getDayNum(6);
-                            break;
-                        case "6":
-                            amount = getDayNum(12);
-                            break;
-                        default:
-                            amount = 1;
-                            break;
-                    }
-                    Calendar cal = Calendar.getInstance();
-                    cal.setTime(new Date());
-                    cal.add(Calendar.DATE, amount);
-                    Date time = cal.getTime();
-                    plan.setEndTime(time);
-                }
+//                TMonitoringRetrievalPlan plan = new TMonitoringRetrievalPlan();
+//                BeanUtils.copyProperties(tMonitoringRetrievalPlan, plan);
+//                plan.setPlanName(tMonitoringRetrievalPlan.getPlanName());
+//                plan.setOrgId(s.getId());
+//                plan.setOrganization(s.getShortName());
+//                plan.setOrgName(s.getShortName());
+//                plan.setRoleId(tMonitoringRetrievalPlan.getRoleId());
+//                plan.setRoleName(tMonitoringRetrievalPlan.getRoleName());
+//                plan.setOrgPath(s.getPath());
+//                plan.setOrgType(tMonitoringRetrievalPlan.getOrgType());
+//                plan.setPlanCycle(tMonitoringRetrievalPlan.getPlanCycle());
+//                plan.setPlanFrequency(tMonitoringRetrievalPlan.getPlanFrequency());
+//                plan.setPlanStatus(ZERO);
+//                plan.setCreateBy(SecurityUtils.getUsername());
+//                plan.setUpdateTime(DateUtils.getNowDate());
+//                plan.setUpdateBy(SecurityUtils.getUsername());
+//                plan.setCreateTime(DateUtils.getNowDate());
+//                plan.setDescription(tMonitoringRetrievalPlan.getDescription());
+//                plan.setCreateType(1);
+//                plan.setParentId(tMonitoringRetrievalPlan.getId());
+//                plan.setIsDistribute("1");
+//                if (!tMonitoringRetrievalPlan.getPlanCycle().equals(ZERO.toString()) &&
+//                        tMonitoringRetrievalPlan.getImmediately().equals(Boolean.TRUE)) {
+//                    plan.setStartTime(new Date());
+//                    int amount = 0;
+//                    LocalDate lastDayOfMonth;
+//                    switch (tMonitoringRetrievalPlan.getPlanCycle()) {
+//
+//                        case "2":
+//                            amount = 7;
+//                            break;
+//                        case "3":
+//                            LocalDate currentDate = LocalDate.now();
+//                            lastDayOfMonth = currentDate.withDayOfMonth(currentDate.lengthOfMonth());
+//                            amount = lastDayOfMonth.getDayOfMonth() - currentDate.getDayOfMonth();
+//                            break;
+//                        case "4":
+//                            amount = getDayNum(3);
+//                            break;
+//                        case "5":
+//                            amount = getDayNum(6);
+//                            break;
+//                        case "6":
+//                            amount = getDayNum(12);
+//                            break;
+//                        default:
+//                            amount = 1;
+//                            break;
+//                    }
+//                    Calendar cal = Calendar.getInstance();
+//                    cal.setTime(new Date());
+//                    cal.add(Calendar.DATE, amount);
+//                    Date time = cal.getTime();
+//                    plan.setEndTime(time);
+//                }
+                TMonitoringRetrievalPlan plan = createTempPlan(tMonitoringRetrievalPlan,tMonitoringRetrievalPlan.getId(),s);
                 tMonitoringRetrievalPlans.add(plan);
             }
         }
@@ -525,6 +553,120 @@ public class TMonitoringRetrievalPlanServiceImpl extends ServiceImpl<TMonitoring
         return i;
     }
 
+    private List<SysOrg> getExecOrgList(List<TMonitoringRetrievalPlanToExecOrg> planExecOrgList, Integer execOrgType, String belongOrgPath) {
+        if (ObjectUtil.isEmpty(planExecOrgList)) {
+            return RemoteCallHandlerExecutor.executeRemoteCall(() ->
+                            remoteOrgService.selectByOrgPathAndOrgType(belongOrgPath, execOrgType, SecurityConstants.INNER),
+                    ErrorMsgConstants.QUERY_ORG_DATA_ERROR);
+        } else {
+            List<Long> list = planExecOrgList.stream().map(TMonitoringRetrievalPlanToExecOrg::getOrgId).collect(Collectors.toList());
+            return RemoteCallHandlerExecutor.executeRemoteCall(() ->
+                            remoteOrgService.selectOrgByIdList(list, SecurityConstants.INNER),
+                    ErrorMsgConstants.QUERY_ORG_DATA_ERROR);
+        }
+    }
+
+    // 准备生成任务需要的临时计划
+    private TMonitoringRetrievalPlan createTempPlan(TMonitoringRetrievalPlan tMonitoringRetrievalPlan,Long planId,SysOrg org)
+    {
+        TMonitoringRetrievalPlan plan = new TMonitoringRetrievalPlan();
+        BeanUtils.copyProperties(tMonitoringRetrievalPlan, plan);
+        plan.setPlanName(tMonitoringRetrievalPlan.getPlanName());
+        plan.setOrgId(org.getId());
+        plan.setOrganization(org.getShortName());
+        plan.setId(planId);
+        plan.setOrgName(org.getShortName());
+        plan.setRoleId(tMonitoringRetrievalPlan.getRoleId());
+        plan.setRoleName(tMonitoringRetrievalPlan.getRoleName());
+        plan.setOrgPath(org.getPath());
+        plan.setOrgType(tMonitoringRetrievalPlan.getOrgType());
+        plan.setPlanCycle(tMonitoringRetrievalPlan.getPlanCycle());
+        plan.setPlanFrequency(tMonitoringRetrievalPlan.getPlanFrequency());
+        plan.setPlanStatus(ZERO);
+        plan.setCreateBy(SecurityUtils.getUsername());
+        plan.setUpdateTime(DateUtils.getNowDate());
+        plan.setUpdateBy(SecurityUtils.getUsername());
+        plan.setCreateTime(DateUtils.getNowDate());
+        plan.setDescription(tMonitoringRetrievalPlan.getDescription());
+        plan.setCreateType(1);
+        plan.setParentId(tMonitoringRetrievalPlan.getId());
+        plan.setIsDistribute("1");
+//        if (!tMonitoringRetrievalPlan.getPlanCycle().equals(ZERO.toString()) &&
+//                tMonitoringRetrievalPlan.getImmediately().equals(Boolean.TRUE)) {
+//            plan.setStartTime(new Date());
+//            int amount = 0;
+//            LocalDate lastDayOfMonth;
+//            switch (tMonitoringRetrievalPlan.getPlanCycle()) {
+//
+//                case "2":
+//                    amount = 7;
+//                    break;
+//                case "3":
+//                    LocalDate currentDate = LocalDate.now();
+//                    lastDayOfMonth = currentDate.withDayOfMonth(currentDate.lengthOfMonth());
+//                    amount = lastDayOfMonth.getDayOfMonth() - currentDate.getDayOfMonth();
+//                    break;
+//                case "4":
+//                    amount = getDayNum(3);
+//                    break;
+//                case "5":
+//                    amount = getDayNum(6);
+//                    break;
+//                case "6":
+//                    amount = getDayNum(12);
+//                    break;
+//                default:
+//                    amount = 1;
+//                    break;
+//            }
+//            Calendar cal = Calendar.getInstance();
+//            cal.setTime(new Date());
+//            cal.add(Calendar.DATE, amount);
+//            Date time = cal.getTime();
+//            plan.setEndTime(time);
+//        }
+        setPlanStartEndTime(tMonitoringRetrievalPlan,plan);
+        return plan;
+    }
+
+    private void setPlanStartEndTime(TMonitoringRetrievalPlan tMonitoringRetrievalPlan,TMonitoringRetrievalPlan tempPlan)
+    {
+        if (!tMonitoringRetrievalPlan.getPlanCycle().equals(ZERO.toString()) &&
+                tMonitoringRetrievalPlan.getImmediately().equals(Boolean.TRUE)) {
+            tempPlan.setStartTime(new Date());
+            int amount = 0;
+            LocalDate lastDayOfMonth;
+            switch (tMonitoringRetrievalPlan.getPlanCycle()) {
+
+                case "2":
+                    amount = 7;
+                    break;
+                case "3":
+                    LocalDate currentDate = LocalDate.now();
+                    lastDayOfMonth = currentDate.withDayOfMonth(currentDate.lengthOfMonth());
+                    amount = lastDayOfMonth.getDayOfMonth() - currentDate.getDayOfMonth();
+                    break;
+                case "4":
+                    amount = getDayNum(3);
+                    break;
+                case "5":
+                    amount = getDayNum(6);
+                    break;
+                case "6":
+                    amount = getDayNum(12);
+                    break;
+                default:
+                    amount = 1;
+                    break;
+            }
+            Calendar cal = Calendar.getInstance();
+            cal.setTime(new Date());
+            cal.add(Calendar.DATE, amount);
+            Date time = cal.getTime();
+            tempPlan.setEndTime(time);
+        }
+    }
+
     private void checkPlanIsCreatingTask(Long planId,String msg)
     {
         String redisKey="Monitoring_Creating_Task" + planId;
@@ -743,6 +885,31 @@ public class TMonitoringRetrievalPlanServiceImpl extends ServiceImpl<TMonitoring
         return tMonitoringRetrievalPlanMapper.insert(tMonitoringRetrievalPlan);
     }
 
+    @Override
+    public int insertTMonitoringRetrievalPlan(TMonitoringRetrievalPlanDto tMonitoringRetrievalPlanDto) {
+        if (ObjectUtil.equal(tMonitoringRetrievalPlanDto.getPlanCycle(), 0) && ObjectUtil.hasEmpty(tMonitoringRetrievalPlanDto.getStartTime(), tMonitoringRetrievalPlanDto.getEndTime())) {
+            throw new RuntimeException("当计划为无周期的时候,请填入开始时间和结束时间!");
+        }
+        TMonitoringRetrievalPlan tMonitoringRetrievalPlan =new TMonitoringRetrievalPlan();
+        BeanUtils.copyProperties(tMonitoringRetrievalPlanDto, tMonitoringRetrievalPlan);
+        int result= insertTMonitoringRetrievalPlan(tMonitoringRetrievalPlan);
+        batchSavePlanToExecOrg(tMonitoringRetrievalPlanDto.getPlanExecOrgIdList(), tMonitoringRetrievalPlan.getId());
+        return result;
+    }
+
+    public void batchSavePlanToExecOrg(List<Long> orgIdList, Long planId) {
+        List<TMonitoringRetrievalPlanToExecOrg> planOrgList = new ArrayList();
+        for (Long orgId : orgIdList) {
+            TMonitoringRetrievalPlanToExecOrg org = new TMonitoringRetrievalPlanToExecOrg();
+            org.setOrgId(orgId);
+            org.setPlanId(planId);
+            planOrgList.add(org);
+        }
+        if (ObjectUtil.isNotEmpty(planOrgList)) {
+            itMonitoringRetrievalPlanToExecOrgService.saveBatch(planOrgList);
+        }
+    }
+
     @Async
     @Override
     public void updateComplete(boolean isComplete, TMonitoringRetrievalPlan tMonitoringRetrievalPlan, TMonitoringRetrievalPlan plan) {
@@ -849,10 +1016,86 @@ public class TMonitoringRetrievalPlanServiceImpl extends ServiceImpl<TMonitoring
         // SysRole sysRole = remoteRoleService.getRoleById(tMonitoringRetrievalPlan.getRoleId(), SecurityConstants.INNER);
         // plan.setRoleName(sysRole.getRoleName());
         int i = tMonitoringRetrievalPlanMapper.updateById(plan);
+
+
         iCoreMonitoringRetrievalTaskService.updateComplete(isComplete, tMonitoringRetrievalPlan, plan);
         return i;
     }
 
+    @Transactional
+    @Override
+    public int updateTMonitoringRetrievalPlan(TMonitoringRetrievalPlanDto tMonitoringRetrievalPlanDto) throws ParseException {
+        try {
+            TMonitoringRetrievalPlan tMonitoringRetrievalPlan =new TMonitoringRetrievalPlan();
+            BeanUtils.copyProperties(tMonitoringRetrievalPlanDto, tMonitoringRetrievalPlan);
+
+            boolean isComplete = getIsComplete(tMonitoringRetrievalPlanDto.getId());
+            TMonitoringRetrievalPlan plan = baseMapper.selectById(tMonitoringRetrievalPlanDto.getId());
+            BeanUtils.copyProperties(tMonitoringRetrievalPlanDto, plan);
+            int result =0;
+            // 存在已完成的任务,不能修改具体执行机构
+            if(isComplete){
+                result = tMonitoringRetrievalPlanMapper.updateById(plan);
+                iCoreMonitoringRetrievalTaskService.updateComplete(isComplete, tMonitoringRetrievalPlan, plan);
+                return result;
+            }
+            else {
+                // 草稿状态
+                if(plan.getPlanStatus()==0)
+                {
+                    tMonitoringRetrievalPlanToExecOrgMapper.deleteByMap(MapUtil.of("plan_id", plan.getId()));
+                    batchSavePlanToExecOrg(tMonitoringRetrievalPlanDto.getPlanExecOrgIdList(), plan.getId());
+                    result = tMonitoringRetrievalPlanMapper.updateById(plan);
+                }
+                // 使用中, 但是任务都未完成, 删除现有任务,并重新生成任务
+                else if(plan.getPlanStatus()==1)
+                {
+                    tMonitoringRetrievalPlanToExecOrgMapper.deleteByMap(MapUtil.of("plan_id", plan.getId()));
+                    batchSavePlanToExecOrg(tMonitoringRetrievalPlanDto.getPlanExecOrgIdList(), plan.getId());
+                    result =tMonitoringRetrievalPlanMapper.updateById(plan);
+                    CompletableFuture.runAsync(() -> {
+
+                        try{
+                            clearTaskByPlanId(plan.getId());
+                            distribute(plan.getId(),true);
+                        }
+                        catch (Exception e) {
+                            e.getMessage();
+                        }
+                    }, threadPoolTaskExecutor);
+                }
+            }
+            return 0;
+        }
+        catch (Exception e) {
+            e.getMessage();
+            return 0;
+        }
+    }
+
+    // 根据计划Id清除计划下的所有任务
+    private void clearTaskByPlanId(Long id){
+        TMonitoringRetrievalPlan plan = baseMapper.selectById(id);
+        QueryWrapper queryWrapper = new QueryWrapper();
+        queryWrapper.eq(PARENT_ID, id);
+        List<TMonitoringRetrievalPlan> list1 = tMonitoringRetrievalPlanMapper.selectList(queryWrapper);
+        List<Long> planIds = new ArrayList<>();
+        // 不为空说明是一个有 子计划的省联社计划
+        if (CollectionUtils.isNotEmpty(list1)) {
+            planIds = list1.stream().map(TMonitoringRetrievalPlan::getId).collect(Collectors.toList());
+            coreMonitoringRetrievalTaskBuilderService.deleteAllTaskByPlanIds(planIds);
+        }
+        else if (plan.getPlanCycle().equals("0")) {
+            planIds.add(id);
+            coreMonitoringRetrievalTaskBuilderService.deleteAllTaskByPlanIds(planIds);
+        }
+        // 是一个行社计划
+        else if (CollectionUtils.isEmpty(list1)) {
+            planIds.add(id);
+            coreMonitoringRetrievalTaskBuilderService.deleteAllTaskByPlanIds(planIds);
+        }
+    }
+
     /**
      * 批量删除监控调阅计划(逻辑删除
      *

+ 15 - 0
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/access/service/impl/TMonitoringRetrievalPlanToExecOrgServiceImpl.java

@@ -0,0 +1,15 @@
+package com.xunmei.core.access.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.xunmei.core.access.domain.TMonitoringRetrievalPlanToExecOrg;
+import com.xunmei.core.access.mapper.TMonitoringRetrievalPlanToExecOrgMapper;
+import com.xunmei.core.access.service.ITMonitoringRetrievalPlanToExecOrgService;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author jingyuanchao
+ * @date 2023/8/25 14:31
+ */
+@Service
+public class TMonitoringRetrievalPlanToExecOrgServiceImpl extends ServiceImpl<TMonitoringRetrievalPlanToExecOrgMapper, TMonitoringRetrievalPlanToExecOrg> implements ITMonitoringRetrievalPlanToExecOrgService {
+}

+ 5 - 0
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/access/vo/TMonitoringRetrievalPlanVO.java

@@ -4,6 +4,8 @@ import com.xunmei.core.access.domain.TMonitoringRetrievalPlan;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
+import java.util.List;
+
 /**
  * @author :LuoWei
  * @date : 2023/9/5
@@ -19,4 +21,7 @@ public class TMonitoringRetrievalPlanVO extends TMonitoringRetrievalPlan {
     private Long parentFrequency;
     @ApiModelProperty(value = "是否有任务")
     private Boolean isHaveTask;
+
+    @ApiModelProperty(value = "计划执行具体机构")
+    private List<Long> planExecOrgIdList;
 }

+ 1 - 1
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/retrieval/service/impl/CoreMonitoringRetrievalTaskBuilderServiceImpl.java

@@ -492,7 +492,7 @@ public class CoreMonitoringRetrievalTaskBuilderServiceImpl extends ServiceImpl<C
         CoreMonitoringRetrievalTask task = new CoreMonitoringRetrievalTask();
         task.setId(IdWorker.getId());
         if (totalNumber == 1 && plan.getPlanFrequency() == 1) {
-            task.setTaskName(plan.getPlanName() + "调阅任务");
+            task.setTaskName(plan.getPlanName()); // + "调阅任务"
         } else {
             task.setTaskName(plan.getPlanName() + "第" + frequency + "次调阅");
         }

+ 23 - 0
soc-modules/soc-modules-core/src/main/resources/mapper/access/TMonitoringRetrievalPlanToExecOrgMapper.xml

@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.xunmei.core.access.mapper.TMonitoringRetrievalPlanToExecOrgMapper">
+    <select id="selectLisByPlanId" resultType="com.xunmei.core.access.domain.TMonitoringRetrievalPlanToExecOrg">
+        select g.plan_id as planId, g.org_id as orgId, o.name as orgName
+        from core_monitoring_retrieval_plan_to_exec_org g
+                 inner join sys_org o on g.org_id = o.id
+        where g.plan_id = #{planId}
+    </select>
+
+    <select id="selectOrgIdByPlanId" resultType="java.lang.Long">
+        select distinct org_id
+        from core_monitoring_retrieval_plan_to_exec_org
+        where plan_id = #{planId}
+    </select>
+    <delete id="deleteLisByPlanId">
+        delete
+        from core_monitoring_task_monitor_info
+        where plan_id = #{planId}
+    </delete>
+</mapper>