任务下派功能新增循环任务类型的下派

完善超时任务逻辑
This commit is contained in:
Renpc-kilig 2021-10-30 15:15:07 +08:00
parent e9e8395519
commit 5a3a8a2bf3
12 changed files with 527 additions and 54 deletions

View File

@ -264,7 +264,8 @@ public class DistributeController extends DefaultBaseController{
* 例如设置的1015下派但是定时任务在1012执行过一次下次执行时间为1017
* 所以在定时任务时间会前后误差五分钟
*/
@Scheduled(cron = "0 0/5 * * * ?")
// @Scheduled(cron = "0 0/5 * * * ?")
@Scheduled(cron = "0/5 * * * * ?")
@Async
public void regularDispatch() {
try {

View File

@ -123,4 +123,11 @@ public interface IDistributeSubDao {
* @throws UpdateException
*/
void deleteAll(Map<String, Object> params) throws UpdateException;
/**
* 通过distributeId获取最后一条录入的数据
* @param params
* @return
*/
DistributeSubDTO descGmtCreat(Map<String, Object> params) throws SearchException;
}

View File

@ -130,4 +130,12 @@ public interface IReceiverUserDao {
* @throws UpdateException
*/
void cancel(Map<String, Object> params) throws UpdateException;
/**
* 查询当前任务的任务接收人列表
* 专用于自动下派方法
* @param params
* @return
*/
List<ReceiverUserDTO> listForAuto(Map<String, Object> params) throws SearchException;
}

View File

@ -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{" +

View File

@ -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<ReceiverUserVO> 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<ReceiverUserVO> 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<String> ids) {
remove(null, ids);
@ -240,10 +312,26 @@ public class DistributeServiceImpl extends DefaultBaseService implements IDistri
receiverUserService.removeAll(params);
if(distributeVO.getDeadlineList().size() <= 1) {
List<ReceiverUserVO> 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<ReceiverUserVO> 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<DistributeDTO> listForAuto(Map<String, Object> params) {
params.put("taskType", "正常");
List<DistributeDTO> distributeDTOList = distributeDao.list(params);
if(null != distributeDTOList && distributeDTOList.size() > 0) {
for(DistributeDTO distributeDTO: distributeDTOList) {
params.put("distributeId", distributeDTO.getDistributeId());
List<ReceiverUserDTO> receiverUserDTOList = receiverUserDao.listForAuto(params);
distributeDTO.setReceiveUserList(receiverUserDTOList);
}
}
return distributeDTOList;
}
@Override
public List<DistributeBO> listBO(Map<String, Object> 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<TemplateDTO> templateDTOList = templateService.list(params);
if(null != templateDTOList && templateDTOList.size() > 0) {
Iterator<TemplateDTO> 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<String, Object> params, List<DistributeDTO> 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<ReceiverUserVO> receiverUserVOList = new ArrayList<>();
RateDTO rateDTO = getRateData(distributeDTO.getTaskTemplate());
String rateType = null;
if(null != rateDTO) {
rateType = rateDTO.getRateType();
}
// 获取任务接收人列表并拼接接收人ID用于app端发送通知
List<ReceiverUserDTO> 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);
}
}
}

View File

@ -208,4 +208,11 @@ public interface IDistributeSubService {
* @param distributeId
*/
void deleteAll(String distributeId);
/**
* 通过distributeId获取最后一条录入的数据
* @param distributeId
* @return
*/
DistributeSubDTO descGmtCreat(String distributeId);
}

View File

@ -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<String, Object> 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<String, Object> params = new HashMap<>(2);
params.put("distributeId", distributeId);
return distributeSubDao.descGmtCreat(params);
}
}

View File

@ -77,10 +77,23 @@ public class ReceiverUserServiceImpl extends DefaultBaseService implements IRece
String receiverUserId = UUIDUtil.getUUID();
Map<String, Object> 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<ReceiverUserDTO> 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<ReceiverUserDTO> 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<String, Object> 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());

View File

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

View File

@ -534,6 +534,12 @@
<if test="userId != null and userId != ''">
AND t2.task_type = '正常'
</if>
<if test="templateIds != null and templateIds.size > 0">
AND t1.task_template IN
<foreach collection="templateIds" index="index" open="(" separator="," close=")">
#{templateIds[${index}]}
</foreach>
</if>
<if test="keywords != null and keywords != ''">
AND (
t1.distribute_title LIKE CONCAT('%', #{keywords}, '%')

View File

@ -322,4 +322,35 @@
t1.is_delete = 0
</select>
<!-- 任务表副表列表 -->
<select id="descGmtCreat" parameterType="map" resultMap="distributeSubDTO">
SELECT
t1.distribute_sub_id,
t1.distribute_id,
t1.frequency,
t1.dead_time,
t1.creator,
t1.gmt_create,
t1.modifier,
t1.gmt_modified,
t1.is_delete
FROM
task_distribute_sub t1
WHERE
t1.is_delete = 0
AND gmt_create = (
SELECT
MAX(gmt_create)
FROM
task_distribute_sub t2
WHERE
t2.is_delete = 0
<if test="distributeId != null and distributeId != ''">
AND t2.distribute_id = #{distributeId}
</if>
LIMIT 0, 1
)
LIMIT 0, 1
</select>
</mapper>

View File

@ -19,6 +19,7 @@
<result column="distribute_status" property="distributeStatus"/>
<result column="distribute_time" property="distributeTime"/>
<result column="distribute_deadline" property="distributeDeadline"/>
<result column="task_template" property="taskTemplate"/>
<result column="days" property="days"/>
<result column="hours" property="hours"/>
<result column="reason" property="reason"/>
@ -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 @@
</if>
</select>
<!-- 任务接收人列表(专用于自动下派) -->
<select id="listForAuto" parameterType="map" resultMap="receiverUserDTO">
SELECT
DISTINCT
t1.user_id,
t1.user_name,
t1.distribute_id
FROM
task_receiver_user t1
WHERE
t1.is_delete = 0
<if test="distributeId != null and distributeId != ''">
AND
t1.distribute_id = #{distributeId}
</if>
<if test="taskType != null and taskType != ''">
AND
t1.task_type = #{taskType}
</if>
</select>
<!-- 任务接收人列表 -->
<select id="listBO" parameterType="map" resultMap="receiverUserBO">
SELECT