Explorar el Código

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

jingyuanchao hace 1 año
padre
commit
14a0387418

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

@@ -76,7 +76,7 @@ public class TMonitoringRetrievalPlanController extends BaseController {
         } else if (SecurityUtils.getUserId() == 1) {
             admin = true;
         }
-     //   ajax.put("check", admin);
+        //   ajax.put("check", admin);
         ajax.put("isEdit", sysOrg.getId());
         return ajax;
     }
@@ -88,7 +88,7 @@ public class TMonitoringRetrievalPlanController extends BaseController {
     @RequiresPermissions("core:accessPlan:release")
     @GetMapping(value = "/distribute/{id}/{immediateEffect}")
     public AjaxResult distribute(@PathVariable(value = "id", required = false) Long id, @PathVariable Boolean immediateEffect) throws ParseException {
-        return success(tMonitoringRetrievalPlanService.distribute(id,immediateEffect));
+        return success(tMonitoringRetrievalPlanService.distribute(id, immediateEffect));
     }
 
     /**

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

@@ -62,6 +62,8 @@ public interface ITMonitoringRetrievalPlanService extends IService<TMonitoringRe
      */
     int updateTMonitoringRetrievalPlan(TMonitoringRetrievalPlan tMonitoringRetrievalPlan);
 
+    void updateComplete(boolean isComplete, TMonitoringRetrievalPlan tMonitoringRetrievalPlan, TMonitoringRetrievalPlan plan);
+
     /**
      * 批量删除监控调阅计划
      *
@@ -85,6 +87,8 @@ public interface ITMonitoringRetrievalPlanService extends IService<TMonitoringRe
      * @return Page
      */
     TableDataInfo<TMonitoringRetrievalPlanVO> selectPage(TMonitoringRetrievalPlan tMonitoringRetrievalPlan);
+
     String createSafetyCheckRegisterBookPdf(AccessPdfVO accessPdfVO);
+
     void buildPdf(Long taskId);
 }

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

@@ -723,6 +723,7 @@ public class TMonitoringRetrievalPlanServiceImpl extends ServiceImpl<TMonitoring
     }
 
     @Async
+    @Override
     public void updateComplete(boolean isComplete, TMonitoringRetrievalPlan tMonitoringRetrievalPlan, TMonitoringRetrievalPlan plan) {
         if (isComplete) {
             coreMonitoringRetrievalTaskBuilderService.deleteWaitTaskByPlanId(tMonitoringRetrievalPlan.getId());
@@ -733,7 +734,7 @@ public class TMonitoringRetrievalPlanServiceImpl extends ServiceImpl<TMonitoring
                 SysOrg sysOrg1 = remoteOrgService.selectSysOrgById(SecurityUtils.getLoginUser().getOrgId(), SecurityConstants.INNER);
                 List<TMonitoringRetrievalPlan> tMonitoringRetrievalPlans = new ArrayList<>();
                 if (sysOrg1.getType() == 1 && plan.getIsDistribute().equals("1")) {
-                    distribute(plan.getId(), true);
+                    distribute(plan.getId(), plan.getImmediately());
                 } else {
                     SysOrg sysOrg = new SysOrg();
                     sysOrg.setPath(plan.getOrgPath());
@@ -820,17 +821,14 @@ public class TMonitoringRetrievalPlanServiceImpl extends ServiceImpl<TMonitoring
     @Transactional
     @Override
     public int updateTMonitoringRetrievalPlan(TMonitoringRetrievalPlan tMonitoringRetrievalPlan) {
-        long l = System.currentTimeMillis();
         boolean isComplete = getIsComplete(tMonitoringRetrievalPlan.getId());
         //如果计划下面的任务都是没完成就删除所有任务,有完成就只修改
         TMonitoringRetrievalPlan plan = baseMapper.selectById(tMonitoringRetrievalPlan.getId());
         BeanUtils.copyProperties(tMonitoringRetrievalPlan, plan);
-        SysRole sysRole = remoteRoleService.getRoleById(tMonitoringRetrievalPlan.getRoleId(), SecurityConstants.INNER);
-        plan.setRoleName(sysRole.getRoleName());
+        // SysRole sysRole = remoteRoleService.getRoleById(tMonitoringRetrievalPlan.getRoleId(), SecurityConstants.INNER);
+        // plan.setRoleName(sysRole.getRoleName());
         int i = tMonitoringRetrievalPlanMapper.updateById(plan);
-        this.updateComplete(isComplete, tMonitoringRetrievalPlan, plan);
-        long l1 = System.currentTimeMillis();
-        System.out.print(l1 - l);
+        iCoreMonitoringRetrievalTaskService.updateComplete(isComplete, tMonitoringRetrievalPlan, plan);
         return i;
     }
 

+ 4 - 2
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/retrieval/service/ICoreMonitoringRetrievalTaskService.java

@@ -114,7 +114,7 @@ public interface ICoreMonitoringRetrievalTaskService extends IService<CoreMonito
 
 //    void deleteAllTaskByPlanIds(List<Long> planId);
 
-    List<CoreMonitoringRetrievalTask> selectAllTaskByPlanId(List<Long> planId,List<String>status);
+    List<CoreMonitoringRetrievalTask> selectAllTaskByPlanId(List<Long> planId, List<String> status);
 //
 //    /**
 //     * 删除日任务
@@ -135,9 +135,11 @@ public interface ICoreMonitoringRetrievalTaskService extends IService<CoreMonito
 
     List<PanelListVo> selectCurUserTaskList(PanelListDto panelListDto);
 
-    void selectMonitorExceptionData(List<Long> orgIds,DateTime time);
+    void selectMonitorExceptionData(List<Long> orgIds, DateTime time);
 //
 //    void taskChangeForTimeWorkChange(WorkTimeChangeEvent event);
 
     Object findSource(SafeScoreSourceDto request);
+
+    void updateComplete(boolean isComplete, TMonitoringRetrievalPlan tMonitoringRetrievalPlan, TMonitoringRetrievalPlan plan);
 }

+ 126 - 3
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/retrieval/service/impl/CoreMonitoringRetrievalTaskServiceImpl.java

@@ -6,6 +6,7 @@ import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.excel.EasyExcel;
+import com.alibaba.nacos.common.utils.CollectionUtils;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
@@ -30,6 +31,7 @@ import com.xunmei.common.core.enums.CycleCommonEnum;
 import com.xunmei.common.core.enums.RetrievalTaskCycle;
 import com.xunmei.common.core.enums.edu.EduTrainingPlanCycleEnum;
 import com.xunmei.common.core.event.WorkTimeChangeEvent;
+import com.xunmei.common.core.exception.ServiceException;
 import com.xunmei.common.core.utils.DateHelper;
 import com.xunmei.common.core.utils.DateUtils;
 import com.xunmei.common.core.utils.Ymd;
@@ -39,8 +41,10 @@ import com.xunmei.common.security.utils.SecurityUtils;
 import com.xunmei.core.access.domain.TMonitoringRetrievalPlan;
 import com.xunmei.core.access.dto.CoreMonitoringTaskRegistrationDTO;
 import com.xunmei.core.access.mapper.CoreMonitoringTaskRegistrationMapper;
+import com.xunmei.core.access.mapper.TMonitoringRetrievalPlanMapper;
 import com.xunmei.core.access.service.ITMonitoringRetrievalPlanService;
 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.safetyindex.mapper.CoreSafetyExceptionDataMapper;
 import com.xunmei.system.api.Eto.RoleConditionEto;
@@ -91,9 +95,16 @@ public class CoreMonitoringRetrievalTaskServiceImpl extends ServiceImpl<CoreMoni
     private RemoteRoleService roleService;
     @Autowired
     RemoteWorkTimeService workTimeService;
-
+    @Autowired
+    private ITMonitoringRetrievalPlanService itMonitoringRetrievalPlanService;
     @Autowired
     CoreSafetyExceptionDataMapper exceptionDataMapper;
+    @Autowired
+    ICoreMonitoringRetrievalTaskBuilderService coreMonitoringRetrievalTskBuilderService;
+    @Autowired
+    TMonitoringRetrievalPlanMapper tMonitoringRetrievalPlanMapper;
+    private static final Integer ZERO = 0;
+    private static final String PARENT_ID = "parent_id";
 
     @Override
     public TableDataInfo selectPage(RetrievalTaskPageDto request) {
@@ -147,7 +158,8 @@ public class CoreMonitoringRetrievalTaskServiceImpl extends ServiceImpl<CoreMoni
         EasyExcel.write(response.getOutputStream(), CoreMonitoringRetrievalTaskExcelVo.class).sheet("Sheet1").doWrite(list);
 
     }
-    public static String getLastDay(int year,int month,String format) {
+
+    public static String getLastDay(int year, int month, String format) {
         Calendar calendar = Calendar.getInstance();
         calendar.set(Calendar.YEAR, year);
         calendar.set(Calendar.MONTH, month);
@@ -162,6 +174,7 @@ public class CoreMonitoringRetrievalTaskServiceImpl extends ServiceImpl<CoreMoni
 
         return formattedEndDate;
     }
+
     @Override
     public TableDataInfo selectListApp(CoreMonitoringTaskRegistrationDTO coreMonitoringTaskRegistrationDTO) {
         LoginUser loginUser = SecurityUtils.getLoginUser();
@@ -169,7 +182,7 @@ public class CoreMonitoringRetrievalTaskServiceImpl extends ServiceImpl<CoreMoni
         if (null == coreMonitoringTaskRegistrationDTO.getOrgId()) {
             coreMonitoringTaskRegistrationDTO.setOrgId(loginUser.getOrgId());
         }
-        coreMonitoringTaskRegistrationDTO.setPlanStartTime( DateUtils.parseDate(coreMonitoringTaskRegistrationDTO.getMoth()+"-01"));
+        coreMonitoringTaskRegistrationDTO.setPlanStartTime(DateUtils.parseDate(coreMonitoringTaskRegistrationDTO.getMoth() + "-01"));
         String[] split = coreMonitoringTaskRegistrationDTO.getMoth().split("-");
         String lastDay = getLastDay(Integer.parseInt(split[0]), Integer.parseInt(split[1]), "yyyy-MM-dd");
         coreMonitoringTaskRegistrationDTO.setPlanEndTime(DateUtils.parseDate(lastDay));
@@ -319,6 +332,116 @@ public class CoreMonitoringRetrievalTaskServiceImpl extends ServiceImpl<CoreMoni
 
     }
 
+    @Async
+    @Override
+    public void updateComplete(boolean isComplete, TMonitoringRetrievalPlan tMonitoringRetrievalPlan, TMonitoringRetrievalPlan plan) {
+        if (isComplete) {
+            coreMonitoringRetrievalTskBuilderService.deleteWaitTaskByPlanId(tMonitoringRetrievalPlan.getId());
+            try {
+                QueryWrapper queryWrapper = new QueryWrapper();
+                queryWrapper.eq(PARENT_ID, plan.getId());
+                tMonitoringRetrievalPlanMapper.delete(queryWrapper);
+                SysOrg sysOrg1 = orgService.selectSysOrgById(SecurityUtils.getLoginUser().getOrgId(), SecurityConstants.INNER);
+                List<TMonitoringRetrievalPlan> tMonitoringRetrievalPlans = new ArrayList<>();
+                if (sysOrg1.getType() == 1 && plan.getIsDistribute().equals("1")) {
+                    itMonitoringRetrievalPlanService.distribute(plan.getId(), plan.getImmediately());
+                } else {
+                    SysOrg sysOrg = new SysOrg();
+                    sysOrg.setPath(plan.getOrgPath());
+                    sysOrg.setType(Integer.valueOf(tMonitoringRetrievalPlan.getOrgType()));
+                    List<SysOrg> sysOrgs = orgService.listByParentIdAndType(sysOrg, SecurityConstants.INNER);
+                    for (SysOrg s : sysOrgs) {
+                        TMonitoringRetrievalPlan plan1 = new TMonitoringRetrievalPlan();
+                        BeanUtils.copyProperties(tMonitoringRetrievalPlan, plan1);
+                        plan1.setPlanName(tMonitoringRetrievalPlan.getPlanName());
+                        plan1.setOrgId(s.getId());
+                        plan1.setOrganization(s.getShortName());
+                        plan1.setOrgName(s.getShortName());
+                        plan1.setRoleId(tMonitoringRetrievalPlan.getRoleId());
+                        plan1.setRoleName(tMonitoringRetrievalPlan.getRoleName());
+                        plan1.setOrgPath(s.getPath());
+                        plan1.setOrgType(tMonitoringRetrievalPlan.getOrgType());
+                        plan1.setPlanCycle(tMonitoringRetrievalPlan.getPlanCycle());
+                        plan1.setPlanFrequency(tMonitoringRetrievalPlan.getPlanFrequency());
+                        plan1.setPlanStatus(ZERO);
+                        plan1.setCreateBy(SecurityUtils.getUsername());
+                        plan1.setUpdateTime(DateUtils.getNowDate());
+                        plan1.setUpdateBy(SecurityUtils.getUsername());
+                        plan1.setCreateTime(DateUtils.getNowDate());
+                        plan1.setDescription(tMonitoringRetrievalPlan.getDescription());
+                        plan1.setCreateType(1);
+                        plan1.setParentId(tMonitoringRetrievalPlan.getId());
+                        plan1.setIsDistribute("1");
+                        if (!tMonitoringRetrievalPlan.getPlanCycle().equals(ZERO.toString()) &&
+                                tMonitoringRetrievalPlan.getImmediately().equals(Boolean.TRUE)) {
+                            plan1.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();
+                            plan1.setEndTime(time);
+                        }
+                        tMonitoringRetrievalPlans.add(plan1);
+                    }
+                    if ((tMonitoringRetrievalPlan.getImmediately().equals(Boolean.TRUE) || tMonitoringRetrievalPlan.getPlanCycle().equals(ZERO.toString())) && CollectionUtils.isNotEmpty(tMonitoringRetrievalPlans) && tMonitoringRetrievalPlan.getIsDistribute().equals("1")) {
+                        try {
+                            coreMonitoringRetrievalTskBuilderService.noCycleTask(tMonitoringRetrievalPlans);
+                        } catch (Exception e) {
+                            throw new ServiceException("下发任务异常,请联系管理员");
+                        }
+                    }
+                }
+            } catch (Exception e) {
+                e.getMessage();
+            }
+        }
+    }
+
+    private int getDayNum(int monthsToAdd) {
+        LocalDate lastDayOfMonth;
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        LocalDate localDate = LocalDate.now();
+        LocalDate nextMonthFirstDay = null;
+        nextMonthFirstDay = localDate.plusMonths(monthsToAdd).withDayOfMonth(1);
+        lastDayOfMonth = nextMonthFirstDay.minusDays(1);
+        int dayNum = 0;
+        try {
+            Date d1 = sdf.parse(lastDayOfMonth.toString());
+            Date d2 = sdf.parse(localDate.toString());
+            long date_interval = Math.abs(d1.getTime() - d2.getTime());//绝对值
+            long day = 1000 * 24 * 60 * 60;//1000*24*60*60毫秒是一天
+            dayNum = new Long(date_interval / day).intValue();
+        } catch (Exception e) {
+            e.getMessage();
+        }
+        return dayNum;
+    }
+
     private Map<Long, String> getRoleNames(List<Long> roleIdList) {
         RoleConditionEto conditionEto = new RoleConditionEto();
         conditionEto.setIds(roleIdList);