|
|
@@ -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);
|