From 5a3a8a2bf3b1a96d1db86c306203515a0eae40a3 Mon Sep 17 00:00:00 2001 From: Renpc-kilig <308442850@qq.com> Date: Sat, 30 Oct 2021 15:15:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E4=B8=8B=E6=B4=BE=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E6=96=B0=E5=A2=9E=E5=BE=AA=E7=8E=AF=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E7=9A=84=E4=B8=8B=E6=B4=BE=20=E5=AE=8C?= =?UTF-8?q?=E5=96=84=E8=B6=85=E6=97=B6=E4=BB=BB=E5=8A=A1=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/distribute/DistributeController.java | 3 +- .../dao/distributesub/IDistributeSubDao.java | 7 + .../dao/receiveruser/IReceiverUserDao.java | 8 + .../dtos/receiveruser/ReceiverUserDTO.java | 10 + .../impl/DistributeServiceImpl.java | 242 ++++++++++++++++-- .../distributesub/IDistributeSubService.java | 7 + .../impl/DistributeSubServiceImpl.java | 29 ++- .../impl/ReceiverUserServiceImpl.java | 38 ++- .../tenlion/systemtask/utils/DateUtils.java | 177 +++++++++++-- .../mapper/distribute/distribute-mapper.xml | 6 + .../distributesub/distribute-sub-mapper.xml | 31 +++ .../receiveruser/receiver-user-mapper.xml | 23 ++ 12 files changed, 527 insertions(+), 54 deletions(-) diff --git a/src/main/java/cn/com/tenlion/systemtask/controller/api/distribute/DistributeController.java b/src/main/java/cn/com/tenlion/systemtask/controller/api/distribute/DistributeController.java index 377c75b..b56711b 100644 --- a/src/main/java/cn/com/tenlion/systemtask/controller/api/distribute/DistributeController.java +++ b/src/main/java/cn/com/tenlion/systemtask/controller/api/distribute/DistributeController.java @@ -264,7 +264,8 @@ public class DistributeController extends DefaultBaseController{ * 例如:设置的10:15下派,但是定时任务在10:12执行过一次,下次执行时间为10:17 * 所以在定时任务时间会前后误差五分钟 */ - @Scheduled(cron = "0 0/5 * * * ?") + // @Scheduled(cron = "0 0/5 * * * ?") + @Scheduled(cron = "0/5 * * * * ?") @Async public void regularDispatch() { try { diff --git a/src/main/java/cn/com/tenlion/systemtask/dao/distributesub/IDistributeSubDao.java b/src/main/java/cn/com/tenlion/systemtask/dao/distributesub/IDistributeSubDao.java index 1fe46c9..fb58974 100644 --- a/src/main/java/cn/com/tenlion/systemtask/dao/distributesub/IDistributeSubDao.java +++ b/src/main/java/cn/com/tenlion/systemtask/dao/distributesub/IDistributeSubDao.java @@ -123,4 +123,11 @@ public interface IDistributeSubDao { * @throws UpdateException */ void deleteAll(Map params) throws UpdateException; + + /** + * 通过distributeId获取最后一条录入的数据 + * @param params + * @return + */ + DistributeSubDTO descGmtCreat(Map params) throws SearchException; } \ No newline at end of file diff --git a/src/main/java/cn/com/tenlion/systemtask/dao/receiveruser/IReceiverUserDao.java b/src/main/java/cn/com/tenlion/systemtask/dao/receiveruser/IReceiverUserDao.java index 641acd9..6e0583d 100644 --- a/src/main/java/cn/com/tenlion/systemtask/dao/receiveruser/IReceiverUserDao.java +++ b/src/main/java/cn/com/tenlion/systemtask/dao/receiveruser/IReceiverUserDao.java @@ -130,4 +130,12 @@ public interface IReceiverUserDao { * @throws UpdateException */ void cancel(Map params) throws UpdateException; + + /** + * 查询当前任务的任务接收人列表 + * 专用于自动下派方法 + * @param params + * @return + */ + List listForAuto(Map params) throws SearchException; } \ No newline at end of file diff --git a/src/main/java/cn/com/tenlion/systemtask/pojo/dtos/receiveruser/ReceiverUserDTO.java b/src/main/java/cn/com/tenlion/systemtask/pojo/dtos/receiveruser/ReceiverUserDTO.java index 168acf6..5f5a72a 100644 --- a/src/main/java/cn/com/tenlion/systemtask/pojo/dtos/receiveruser/ReceiverUserDTO.java +++ b/src/main/java/cn/com/tenlion/systemtask/pojo/dtos/receiveruser/ReceiverUserDTO.java @@ -60,6 +60,8 @@ public class ReceiverUserDTO { private Integer hours; @ApiModelProperty(name = "frequency", value = "任务次数") private String frequency; + @ApiModelProperty(name = "taskTemplate", value = "任务模板") + private String taskTemplate; public String getReceiverUserId() { return receiverUserId == null ? "" : receiverUserId.trim(); @@ -237,6 +239,14 @@ public class ReceiverUserDTO { this.frequency = frequency; } + public String getTaskTemplate() { + return taskTemplate; + } + + public void setTaskTemplate(String taskTemplate) { + this.taskTemplate = taskTemplate; + } + @Override public String toString() { return "ReceiverUserDTO{" + diff --git a/src/main/java/cn/com/tenlion/systemtask/service/distribute/impl/DistributeServiceImpl.java b/src/main/java/cn/com/tenlion/systemtask/service/distribute/impl/DistributeServiceImpl.java index a6571fd..5c765df 100644 --- a/src/main/java/cn/com/tenlion/systemtask/service/distribute/impl/DistributeServiceImpl.java +++ b/src/main/java/cn/com/tenlion/systemtask/service/distribute/impl/DistributeServiceImpl.java @@ -1,11 +1,13 @@ package cn.com.tenlion.systemtask.service.distribute.impl; import cn.com.tenlion.systemtask.dao.distribute.IDistributeDao; +import cn.com.tenlion.systemtask.dao.receiveruser.IReceiverUserDao; import cn.com.tenlion.systemtask.pojo.bos.distribute.DistributeBO; import cn.com.tenlion.systemtask.pojo.dtos.despicableconfigure.DespicableConfigureDTO; import cn.com.tenlion.systemtask.pojo.dtos.distribute.ChartsDTO; import cn.com.tenlion.systemtask.pojo.dtos.distribute.DistributeDTO; import cn.com.tenlion.systemtask.pojo.dtos.distribute.DistributeListDTO; +import cn.com.tenlion.systemtask.pojo.dtos.distributesub.DistributeSubDTO; import cn.com.tenlion.systemtask.pojo.dtos.rate.RateDTO; import cn.com.tenlion.systemtask.pojo.dtos.receiveruser.ReceiverUserDTO; import cn.com.tenlion.systemtask.pojo.dtos.template.TemplateDTO; @@ -71,6 +73,8 @@ public class DistributeServiceImpl extends DefaultBaseService implements IDistri @Autowired private IReceiverUserService receiverUserService; @Autowired + private IReceiverUserDao receiverUserDao; + @Autowired private IDespicableConfigureService despicableConfigureService; @Autowired private IDistributeSubService distributeSubService; @@ -120,15 +124,72 @@ public class DistributeServiceImpl extends DefaultBaseService implements IDistri setAppSaveInfo(token, params); } distributeDao.save(params); - if(distributeVO.getDeadlineList().size() <= 1) { - List receiverUserVOList = distributeVO.getReceiverUserList(); - if(null != receiverUserVOList && receiverUserVOList.size() > 0) { - saveReceiveUser(distributeId, receiverUserVOList, null); + + RateDTO rateDTO = getRateData(distributeVO.getTaskTemplate()); + + String rateType = null; + if(null != rateDTO) { + rateType = rateDTO.getRateType(); + } + + if("循环任务".equals(rateType)) { + try { + Date date = df.parse(distributeVO.getDistributeTime()); + setDistributeSubByRateType(rateDTO.getCycleType(), date, distributeId, distributeVO); + }catch (Exception e) { + e.printStackTrace(); + } + }else { + if (distributeVO.getDeadlineList().size() <= 1) { + List receiverUserVOList = distributeVO.getReceiverUserList(); + if (null != receiverUserVOList && receiverUserVOList.size() > 0) { + saveReceiveUser(distributeId, receiverUserVOList, null); + } } } return distributeId; } + /** + * 通过任务类型(循环)来设置子任务 + * @param rateType + * @param distributeId + * @param distributeVO + */ + private void setDistributeSubByRateType(String rateType, Date date, String distributeId, DistributeVO distributeVO) throws ParseException { + DateRange dateRange; + if("每天".equals(rateType)) { + dateRange = DateUtils.getTodayRange(); + getDateToSub(distributeId, distributeVO, dateRange); + } + if("每周".equals(rateType)) { + dateRange = DateUtils.getTimeInterval(date); + getDateToSub(distributeId, distributeVO, dateRange); + } + if("每月".equals(rateType)) { + dateRange = DateUtils.getThisMonth(); + getDateToSub(distributeId, distributeVO, dateRange); + } + if("每季度".equals(rateType)) { + dateRange = DateUtils.getThisQuarter(); + getDateToSub(distributeId, distributeVO, dateRange); + } + if("每半年".equals(rateType)) { + dateRange = DateUtils.getHalfYearInterval(date); + getDateToSub(distributeId, distributeVO, dateRange); + } + if("每年".equals(rateType)) { + dateRange = DateUtils.getYearInterval(date); + getDateToSub(distributeId, distributeVO, dateRange); + } + } + + private void getDateToSub(String distributeId, DistributeVO distributeVO, DateRange dateRange) { + Date endDate = dateRange.getEnd(); + String deadline = df.format(endDate).substring(0, 10); + saveDistributeSub(distributeId, deadline + " 23:59:59", deadline +"号任务", distributeVO); + } + /** * 将任务清单配置信息转存到DistributeListVO * @param templateListDTOS @@ -174,18 +235,29 @@ public class DistributeServiceImpl extends DefaultBaseService implements IDistri } if(deadlineList.size() > 1) { - DistributeSubVO distributeSubVO = new DistributeSubVO(); - distributeSubVO.setDistributeId(distributeId); - distributeSubVO.setDeadTime(deadline); - distributeSubVO.setFrequency("第" + (i+1) + "次任务"); - String subId = distributeSubService.saveReturnId(null, distributeSubVO); - saveReceiveUser(distributeId, distributeVO.getReceiverUserList(), subId); + saveDistributeSub(distributeId, deadline, "第" + (i+1) + "次任务", distributeVO); } } distributeVO.setDistributeDeadline(stringBuffer.toString()); } } + /** + * 保存任务子表 + * @param distributeId + * @param deadline + * @param frequency + * @param distributeVO + */ + private void saveDistributeSub(String distributeId, String deadline, String frequency, DistributeVO distributeVO) { + DistributeSubVO distributeSubVO = new DistributeSubVO(); + distributeSubVO.setDistributeId(distributeId); + distributeSubVO.setDeadTime(deadline); + distributeSubVO.setFrequency(frequency); + String subId = distributeSubService.saveReturnId(null, distributeSubVO); + saveReceiveUser(distributeId, distributeVO.getReceiverUserList(), subId); + } + @Override public void remove(List ids) { remove(null, ids); @@ -240,10 +312,26 @@ public class DistributeServiceImpl extends DefaultBaseService implements IDistri receiverUserService.removeAll(params); - if(distributeVO.getDeadlineList().size() <= 1) { - List receiverUserVOList = distributeVO.getReceiverUserList(); - if(null != receiverUserVOList && receiverUserVOList.size() > 0) { - saveReceiveUser(distributeId, receiverUserVOList, null); + RateDTO rateDTO = getRateData(distributeVO.getTaskTemplate()); + + String rateType = null; + if(null != rateDTO) { + rateType = rateDTO.getRateType(); + } + + if("循环任务".equals(rateType)) { + try { + Date date = df.parse(distributeVO.getDistributeTime()); + setDistributeSubByRateType(rateDTO.getCycleType(), date, distributeId, distributeVO); + }catch (Exception e) { + e.printStackTrace(); + } + }else { + if (distributeVO.getDeadlineList().size() <= 1) { + List receiverUserVOList = distributeVO.getReceiverUserList(); + if (null != receiverUserVOList && receiverUserVOList.size() > 0) { + saveReceiveUser(distributeId, receiverUserVOList, null); + } } } } @@ -387,6 +475,24 @@ public class DistributeServiceImpl extends DefaultBaseService implements IDistri return distributeDao.list(params); } + /** + * 专用于自动下派方法 + * @param params + * @return + */ + private List listForAuto(Map params) { + params.put("taskType", "正常"); + List distributeDTOList = distributeDao.list(params); + if(null != distributeDTOList && distributeDTOList.size() > 0) { + for(DistributeDTO distributeDTO: distributeDTOList) { + params.put("distributeId", distributeDTO.getDistributeId()); + List receiverUserDTOList = receiverUserDao.listForAuto(params); + distributeDTO.setReceiveUserList(receiverUserDTOList); + } + } + return distributeDTOList; + } + @Override public List listBO(Map params) { return distributeDao.listBO(params); @@ -514,36 +620,120 @@ public class DistributeServiceImpl extends DefaultBaseService implements IDistri params.remove("reportCount"); params.remove("areaCode"); } - distributeDTOList = distributeDao.list(params); + distributeDTOList = listForAuto(params); + sendTask(params, distributeDTOList); + + // 获取所有任务模板中频率为循环任务的数据 + String templateIds = ""; + if(null == distributeDTOList || distributeDTOList.size() < 1) { + List templateDTOList = templateService.list(params); + if(null != templateDTOList && templateDTOList.size() > 0) { + Iterator iterator = templateDTOList.iterator(); + while(iterator.hasNext()) { + TemplateDTO templateDTO = iterator.next(); + RateDTO rateDTO = rateService.get(templateDTO.getTaskRateId()); + if(null != rateDTO) { + if(!"循环任务".equals(rateDTO.getRateType())) { + iterator.remove(); + }else { + templateIds += templateDTO.getTemplateId() + ","; + } + } + } + } + } + if(templateIds.length() > 0) { + templateIds = templateIds.substring(0, templateIds.length() - 1); + } + params.put("templateIds", Arrays.asList(templateIds.split("\\,"))); + params.remove("distributeStatus"); + distributeDTOList = listForAuto(params); sendTask(params, distributeDTOList); } + /** + * 获取任务模板数据 + * @param templateId + * @return + */ + private RateDTO getRateData(String templateId) { + String taskTemplate = null; + RateDTO rateDTO = null; + if(!StringUtils.isEmpty(templateId)) { + taskTemplate = templateId; + TemplateDTO templateDTO = templateService.get(taskTemplate); + if(null != templateDTO) { + rateDTO = rateService.get(templateDTO.getTaskRateId()); + } + } + return rateDTO; + } + + /** + * 遍历任务集合并下派 + * @param params + * @param distributeDTOList + * @throws ParseException + */ private void sendTask(Map params, List distributeDTOList) throws ParseException { if(null != distributeDTOList && distributeDTOList.size() > 0) { String userIds = null; // 系统当前时间 String nowDateStr = df.format(new Date()); for(DistributeDTO distributeDTO: distributeDTOList) { + DistributeVO distributeVO = new DistributeVO(); + List receiverUserVOList = new ArrayList<>(); + RateDTO rateDTO = getRateData(distributeDTO.getTaskTemplate()); + String rateType = null; + if(null != rateDTO) { + rateType = rateDTO.getRateType(); + } + // 获取任务接收人列表,并拼接接收人ID,用于app端发送通知 List receiverUserDTOList = distributeDTO.getReceiveUserList(); if(null != receiverUserDTOList && receiverUserDTOList.size() > 0) { for(ReceiverUserDTO receiverUserDTO: receiverUserDTOList) { + ReceiverUserVO receiverUserVO = new ReceiverUserVO(); + receiverUserVO.setDistributeId(receiverUserDTO.getDistributeId()); + receiverUserVO.setUserId(receiverUserDTO.getUserId()); + receiverUserVO.setUserName(receiverUserDTO.getUserName()); + receiverUserVOList.add(receiverUserVO); userIds += receiverUserDTO.getUserId() + "_"; } userIds = userIds.substring(0, userIds.length()-1); } - // 任务下派时间字符串 - String distributeTimeStr = distributeDTO.getDistributeTime(); - boolean flag = dateBig(nowDateStr, distributeTimeStr); - if(flag) { - params.put("distributeStatus", "下派超时"); - receiverUserService.sendAppMsg("任务下派超时", "您的任务:" + distributeDTO.getDistributeTitle() + "下派超期,请联系管理员处理。", userIds); - }else { - params.put("distributeStatus", "已下派"); - receiverUserService.sendAppMsg("任务已下派", "您的任务:" + distributeDTO.getDistributeTitle() + "已下派,请及时接收并处理。", userIds); + distributeVO.setReceiverUserList(receiverUserVOList); + if("循环任务".equals(rateType)) { + try { + DistributeSubDTO distributeSubDTO = distributeSubService.descGmtCreat(distributeDTO.getDistributeId()); + if(null != distributeSubDTO) { + boolean flag = DateUtils.isOverRateType(rateDTO.getCycleType(), df.format(new Date()), distributeSubDTO.getGmtCreate()); + if(!flag) { + flag = DateUtils.isOverRateType(rateDTO.getCycleType(), distributeSubDTO.getGmtCreate(), df.format(new Date())); + } + if(flag) { + setDistributeSubByRateType(rateDTO.getCycleType(), new Date(), distributeDTO.getDistributeId(), distributeVO); + } + } + }catch (Exception e) { + e.printStackTrace(); + } + } + if("未下派".equals(distributeDTO.getDistributeStatus())) { + // 任务下派时间字符串 + String distributeTimeStr = distributeDTO.getDistributeTime(); + boolean flag = dateBig(nowDateStr, distributeTimeStr); + if(flag) { + params.put("distributeStatus", "下派超时"); + receiverUserService.sendAppMsg("任务下派超时", "您的任务:" + distributeDTO.getDistributeTitle() + "下派超期,请联系管理员处理。", userIds); + }else { + params.put("distributeStatus", "已下派"); + receiverUserService.sendAppMsg("任务已下派", "您的任务:" + distributeDTO.getDistributeTitle() + "已下派,请及时接收并处理。", userIds); + } + params.put("taskTemplate", distributeDTO.getTaskTemplate()); + params.put("distributeId", distributeDTO.getDistributeId()); + distributeDao.update(params); } - params.put("distributeId", distributeDTO.getDistributeId()); - distributeDao.update(params); } } } diff --git a/src/main/java/cn/com/tenlion/systemtask/service/distributesub/IDistributeSubService.java b/src/main/java/cn/com/tenlion/systemtask/service/distributesub/IDistributeSubService.java index ef1c24f..b23aad4 100644 --- a/src/main/java/cn/com/tenlion/systemtask/service/distributesub/IDistributeSubService.java +++ b/src/main/java/cn/com/tenlion/systemtask/service/distributesub/IDistributeSubService.java @@ -208,4 +208,11 @@ public interface IDistributeSubService { * @param distributeId */ void deleteAll(String distributeId); + + /** + * 通过distributeId获取最后一条录入的数据 + * @param distributeId + * @return + */ + DistributeSubDTO descGmtCreat(String distributeId); } \ No newline at end of file diff --git a/src/main/java/cn/com/tenlion/systemtask/service/distributesub/impl/DistributeSubServiceImpl.java b/src/main/java/cn/com/tenlion/systemtask/service/distributesub/impl/DistributeSubServiceImpl.java index d338e80..a3b58b3 100644 --- a/src/main/java/cn/com/tenlion/systemtask/service/distributesub/impl/DistributeSubServiceImpl.java +++ b/src/main/java/cn/com/tenlion/systemtask/service/distributesub/impl/DistributeSubServiceImpl.java @@ -9,6 +9,7 @@ import cn.com.tenlion.systemtask.service.distributesub.IDistributeSubService; import ink.wgink.common.base.DefaultBaseService; import ink.wgink.pojo.ListPage; import ink.wgink.pojo.result.SuccessResultList; +import ink.wgink.util.date.DateUtil; import ink.wgink.util.map.HashMapUtil; import ink.wgink.util.UUIDUtil; import com.github.pagehelper.PageHelper; @@ -52,10 +53,23 @@ public class DistributeSubServiceImpl extends DefaultBaseService implements IDis String distributeSubId = UUIDUtil.getUUID(); Map params = HashMapUtil.beanToMap(distributeSubVO); params.put("distributeSubId", distributeSubId); - if (StringUtils.isBlank(token)) { - setSaveInfo(params); - } else { - setAppSaveInfo(token, params); + try { + if (null == securityComponent) { + if (StringUtils.isBlank(token)) { + setSaveInfo(params); + } else { + setAppSaveInfo(token, params); + } + } else { + String currentDate = DateUtil.getTime(); + params.put("creator", 1); + params.put("gmtCreate", currentDate); + params.put("modifier", 1); + params.put("gmtModified", currentDate); + params.put("isDelete", 0); + } + }catch (Exception e) { + } distributeSubDao.save(params); return distributeSubId; @@ -191,4 +205,11 @@ public class DistributeSubServiceImpl extends DefaultBaseService implements IDis distributeSubDao.deleteAll(params); } + @Override + public DistributeSubDTO descGmtCreat(String distributeId) { + Map params = new HashMap<>(2); + params.put("distributeId", distributeId); + return distributeSubDao.descGmtCreat(params); + } + } \ No newline at end of file diff --git a/src/main/java/cn/com/tenlion/systemtask/service/receiveruser/impl/ReceiverUserServiceImpl.java b/src/main/java/cn/com/tenlion/systemtask/service/receiveruser/impl/ReceiverUserServiceImpl.java index b072c1d..0eba7fc 100644 --- a/src/main/java/cn/com/tenlion/systemtask/service/receiveruser/impl/ReceiverUserServiceImpl.java +++ b/src/main/java/cn/com/tenlion/systemtask/service/receiveruser/impl/ReceiverUserServiceImpl.java @@ -77,10 +77,23 @@ public class ReceiverUserServiceImpl extends DefaultBaseService implements IRece String receiverUserId = UUIDUtil.getUUID(); Map params = HashMapUtil.beanToMap(receiverUserVO); params.put("receiverUserId", receiverUserId); - if (StringUtils.isBlank(token)) { - setSaveInfo(params); - } else { - setAppSaveInfo(token, params); + try { + if (null == securityComponent) { + if (StringUtils.isBlank(token)) { + setSaveInfo(params); + } else { + setAppSaveInfo(token, params); + } + } else { + String currentDate = DateUtil.getTime(); + params.put("creator", 1); + params.put("gmtCreate", currentDate); + params.put("modifier", 1); + params.put("gmtModified", currentDate); + params.put("isDelete", 0); + } + }catch (Exception e) { + } receiverUserDao.save(params); return receiverUserId; @@ -186,8 +199,8 @@ public class ReceiverUserServiceImpl extends DefaultBaseService implements IRece List receiverUserDTOList = receiverUserDao.list(params); if(null != receiverUserDTOList && receiverUserDTOList.size() > 0) { for(ReceiverUserDTO receiverUserDTO: receiverUserDTOList) { - String[] deadLineArr = receiverUserDTO.getDistributeDeadline().split(","); - if(deadLineArr.length > 1) { + String distributeSubId = receiverUserDTO.getDistributeSubId(); + if(!StringHandler.isNull(distributeSubId)) { DistributeSubDTO distributeSubDTO = distributeSubService.get(receiverUserDTO.getDistributeSubId()); if(null != distributeSubDTO) { receiverUserDTO.setFrequency(distributeSubDTO.getFrequency()); @@ -280,11 +293,19 @@ public class ReceiverUserServiceImpl extends DefaultBaseService implements IRece params.put("executeStatusNoOver", "完成"); List receiverUserDTOList = list(params); if(null != receiverUserDTOList && receiverUserDTOList.size() > 0) { - String receiveUserId; // 获取当前系统时间 // 系统当前时间 String nowDateStr = df.format(new Date()); for(ReceiverUserDTO receiverUserDTO: receiverUserDTOList) { + // 判断当前任务是否选择了任务模板 + // 如果选择了模板:则判断任务类型 + // 单次任务和多次任务根据给定的截止日期 + // 循环任务根据默认时限为最后时限 + // 例如:每天,则为当天24点前 + // 例如:每周,则为本周周日24点前 + if(StringUtils.isEmpty(receiverUserDTO.getTaskTemplate())) { + + } String[] deadLineTime = receiverUserDTO.getDistributeDeadline().split(","); if(1 == deadLineTime.length) { setTaskType(nowDateStr, deadLineTime[0], receiverUserDTO); @@ -311,6 +332,9 @@ public class ReceiverUserServiceImpl extends DefaultBaseService implements IRece Map params = new HashMap<>(2); int days = receiverUserDTO.getDays(); int hours = receiverUserDTO.getHours(); + // 根据当前日期与任务截止日期做对比 + // 超过则直接超时 + // 否则与设置的小时数天数做对比,超过则即将超期 boolean flag = distributeService.dateBig(nowDateStr, deadTime); UrgeVO urgeVO = new UrgeVO(); urgeVO.setTaskId(receiverUserDTO.getDistributeId()); diff --git a/src/main/java/cn/com/tenlion/systemtask/utils/DateUtils.java b/src/main/java/cn/com/tenlion/systemtask/utils/DateUtils.java index f4e28a4..5dc3c40 100644 --- a/src/main/java/cn/com/tenlion/systemtask/utils/DateUtils.java +++ b/src/main/java/cn/com/tenlion/systemtask/utils/DateUtils.java @@ -6,7 +6,10 @@ package cn.com.tenlion.systemtask.utils; * @author renpc */ +import cn.com.tenlion.systemtask.pojo.vos.distribute.DistributeVO; + import java.text.DateFormat; +import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; @@ -16,7 +19,7 @@ public class DateUtils { /**设置初始值*/ private static Calendar cal; - private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); /** * 根据当前系统时区定义Calendar @@ -25,6 +28,120 @@ public class DateUtils { cal = Calendar.getInstance(); } + /** + * 通过系统当前时间和上次下派任务时间做对比 + * @param rateType + * @param nowTime + * @param sendTime + * @return + * @throws ParseException + */ + public static boolean isOverRateType(String rateType, String nowTime, String sendTime) throws ParseException { + DateRange dateRange; + boolean flag = false; + if("每天".equals(rateType)) { + int day = compareDate(nowTime, sendTime, 0); + if(day == 1) { + flag = true; + } + } + if("每周".equals(rateType)) { + int day = compareDate(nowTime, sendTime, 0); + if(day == 7) { + flag = true; + } + } + if("每月".equals(rateType)) { + int month = compareDate(nowTime, sendTime, 1); + if(month == 1) { + flag = true; + } + } + if("每季度".equals(rateType)) { + int month = compareDate(nowTime, sendTime, 1); + if(month == 3) { + flag = true; + } + } + if("每半年".equals(rateType)) { + int month = compareDate(nowTime, sendTime, 1); + if(month == 6) { + flag = true; + } + } + if("每年".equals(rateType)) { + int month = compareDate(nowTime, sendTime, 1); + if(month == 12) { + flag = true; + } + } + return flag; + } + + /** + * 根据日期获取半年的时间范围 + * @param date + * @return + */ + public static DateRange getHalfYearInterval(Date date) throws ParseException { + DateRange dateRange = new DateRange(null, null); + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + int year = cal.get(Calendar.YEAR); + int month = cal.get(Calendar.MONTH) + 1; + if(month > 6) { + cal.setTime(sdf.parse(year + "-07-01")); + dateRange.setStart(cal.getTime()); + cal.setTime(sdf.parse(year + "-12-31")); + dateRange.setEnd(cal.getTime()); + }else { + cal.setTime(sdf.parse(year + "-01-01")); + dateRange.setStart(cal.getTime()); + cal.setTime(sdf.parse(year + "-06-30")); + dateRange.setEnd(cal.getTime()); + } + return dateRange; + } + + /** + * 根据日期获取年的时间范围 + * @param date + * @return + */ + public static DateRange getYearInterval(Date date) throws ParseException { + DateRange dateRange = new DateRange(null, null); + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + int year = cal.get(Calendar.YEAR); + cal.setTime(sdf.parse(year + "-01-01")); + dateRange.setStart(cal.getTime()); + cal.setTime(sdf.parse(year + "-12-31")); + dateRange.setEnd(cal.getTime()); + return dateRange; + } + + /** + * 根据当前日期获得所在周的日期区间(周一和周日日期) + * + * @return + * @author renpc + */ + public static DateRange getTimeInterval(Date date) { + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + int dayWeek = cal.get(Calendar.DAY_OF_WEEK);// 得到当前日期是一个星期的第几天 + if (1 == dayWeek) { + cal.add(Calendar.DAY_OF_MONTH, -1); + } + cal.setFirstDayOfWeek(Calendar.MONDAY); + int day = cal.get(Calendar.DAY_OF_WEEK); + cal.add(Calendar.DATE, cal.getFirstDayOfWeek() - day); + DateRange dateRange = new DateRange(cal.getTime(), null); + cal.add(Calendar.DATE, 6); + dateRange.setEnd(cal.getTime()); + return dateRange; + } + /** * 比较两个日期是否相等 * @param startDate @@ -108,7 +225,7 @@ public class DateUtils { * 获取当前季度的时间范围 * @return current quarter */ - public static DateRange getThisQuarter(int quarter) { + public static DateRange getThisQuarter() { Calendar startCalendar = Calendar.getInstance(); startCalendar.set(Calendar.MONTH, ((int) startCalendar.get(Calendar.MONTH) / 3) * 3); startCalendar.set(Calendar.DAY_OF_MONTH, 1); @@ -138,6 +255,22 @@ public class DateUtils { return new DateRange(startCalendar.getTime(), endCalendar.getTime()); } + /** + * 获取今天的时间范围 + * @return + */ + public static DateRange getTodayRange() { + Calendar startCalendar = Calendar.getInstance(); + startCalendar.add(Calendar.DAY_OF_MONTH, 0); + setMinTime(startCalendar); + + Calendar endCalendar = Calendar.getInstance(); + endCalendar.add(Calendar.DAY_OF_MONTH, 0); + setMaxTime(endCalendar); + + return new DateRange(startCalendar.getTime(), endCalendar.getTime()); + } + /** * 获取当前月份的时间范围 * @return @@ -279,6 +412,17 @@ public class DateUtils { calendar.set(Calendar.MILLISECOND, calendar.getActualMaximum(Calendar.MILLISECOND)); } + /** + * 设置日期时间为23时59分59秒 + * @param calendar + */ + private static void setEndTime(Calendar calendar) { + calendar.set(Calendar.HOUR_OF_DAY, 23); + calendar.set(Calendar.MINUTE, 59); + calendar.set(Calendar.SECOND, 59); + calendar.set(Calendar.MILLISECOND, 999); + } + public final static String DEFAULT_PATTERN = "MM/dd/yyyy HH:mm:ss"; @@ -287,20 +431,21 @@ public class DateUtils { return sdf.format(date); } - public static void main(String[] args) { - int dateNum = 10; - int monthTime = 10; - int yearTime = 2020; - String xAxisValue = ""; - int j = 0; - for(int i=1;i<=dateNum;i++) { - if (monthTime > 12) { - yearTime += 1; - monthTime = 1; - } - xAxisValue += yearTime + "年-" + monthTime + "月" + ","; - monthTime++; + public static boolean dateBig(String startTime, String endTime) throws ParseException { + // 设置允许误差时间为五分钟 + long errorTime = 5 * 60 * 1000; + SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date startDate = df1.parse(startTime); + Date endDate = df1.parse(endTime); + boolean flag = startDate.getTime() > endDate.getTime(); + if(flag) { + startDate = new Date(startDate.getTime() - errorTime); + flag = startDate.getTime() > endDate.getTime(); } - System.out.println(xAxisValue); + return flag; + } + + public static void main(String[] args) throws ParseException { + System.out.println(isOverRateType("每天", "2021-11-01 12:25:33", "2021-10-28 20:22:12")); } } \ No newline at end of file diff --git a/src/main/resources/mybatis/mapper/distribute/distribute-mapper.xml b/src/main/resources/mybatis/mapper/distribute/distribute-mapper.xml index c3bbb89..48b4165 100644 --- a/src/main/resources/mybatis/mapper/distribute/distribute-mapper.xml +++ b/src/main/resources/mybatis/mapper/distribute/distribute-mapper.xml @@ -534,6 +534,12 @@ AND t2.task_type = '正常' + + AND t1.task_template IN + + #{templateIds[${index}]} + + AND ( t1.distribute_title LIKE CONCAT('%', #{keywords}, '%') diff --git a/src/main/resources/mybatis/mapper/distributesub/distribute-sub-mapper.xml b/src/main/resources/mybatis/mapper/distributesub/distribute-sub-mapper.xml index 62bcd2b..f8621ad 100644 --- a/src/main/resources/mybatis/mapper/distributesub/distribute-sub-mapper.xml +++ b/src/main/resources/mybatis/mapper/distributesub/distribute-sub-mapper.xml @@ -322,4 +322,35 @@ t1.is_delete = 0 + + + \ No newline at end of file diff --git a/src/main/resources/mybatis/mapper/receiveruser/receiver-user-mapper.xml b/src/main/resources/mybatis/mapper/receiveruser/receiver-user-mapper.xml index b30567f..abacc44 100644 --- a/src/main/resources/mybatis/mapper/receiveruser/receiver-user-mapper.xml +++ b/src/main/resources/mybatis/mapper/receiveruser/receiver-user-mapper.xml @@ -19,6 +19,7 @@ + @@ -343,6 +344,7 @@ t2.distribute_summary, t2.distribute_time, t2.distribute_deadline, + t2.task_template, t2.days, t2.hours, t1.is_warning, @@ -453,6 +455,27 @@ + + +