自动下派功能优化。

This commit is contained in:
Renpc-kilig 2021-11-03 18:52:33 +08:00
parent 0f79297002
commit 586af83c84
3 changed files with 113 additions and 43 deletions

View File

@ -110,6 +110,7 @@ public class DistributeServiceImpl extends DefaultBaseService implements IDistri
distributeVO.setDistributeStatus("已下派"); distributeVO.setDistributeStatus("已下派");
} }
// 设置任务清单数据
setData(distributeVO, distributeId); setData(distributeVO, distributeId);
// 选择下派模板判断模板中任务频率若为单次截止日期为一条若为多次截止日期为多条 // 选择下派模板判断模板中任务频率若为单次截止日期为一条若为多次截止日期为多条
@ -125,6 +126,7 @@ public class DistributeServiceImpl extends DefaultBaseService implements IDistri
} }
distributeDao.save(params); distributeDao.save(params);
// 获取任务频率相关信息
RateDTO rateDTO = getRateData(distributeVO.getTaskTemplate()); RateDTO rateDTO = getRateData(distributeVO.getTaskTemplate());
String rateType = null; String rateType = null;
@ -132,6 +134,8 @@ public class DistributeServiceImpl extends DefaultBaseService implements IDistri
rateType = rateDTO.getRateType(); rateType = rateDTO.getRateType();
} }
// 如果任务频率为循环任务则定时下派任务
// 否则正常下派
if("循环任务".equals(rateType)) { if("循环任务".equals(rateType)) {
try { try {
Date date = df.parse(distributeVO.getDistributeTime()); Date date = df.parse(distributeVO.getDistributeTime());
@ -184,6 +188,12 @@ public class DistributeServiceImpl extends DefaultBaseService implements IDistri
} }
} }
/**
* 循环任务专用方法用来获取截止日期并保存子表数据
* @param distributeId
* @param distributeVO
* @param dateRange
*/
private void getDateToSub(String distributeId, DistributeVO distributeVO, DateRange dateRange) { private void getDateToSub(String distributeId, DistributeVO distributeVO, DateRange dateRange) {
Date endDate = dateRange.getEnd(); Date endDate = dateRange.getEnd();
String deadline = df.format(endDate).substring(0, 10); String deadline = df.format(endDate).substring(0, 10);
@ -215,6 +225,8 @@ public class DistributeServiceImpl extends DefaultBaseService implements IDistri
/** /**
* 设置截止时间 * 设置截止时间
* 若截止日期为多条时保存子表数据
* 此方法不考虑循环任务只考虑单次和多次任务
* @param distributeId * @param distributeId
* @param distributeVO * @param distributeVO
*/ */
@ -233,7 +245,7 @@ public class DistributeServiceImpl extends DefaultBaseService implements IDistri
}else { }else {
stringBuffer.append("," + deadline); stringBuffer.append("," + deadline);
} }
// 截止时间为多条时设置子表数据
if(deadlineList.size() > 1) { if(deadlineList.size() > 1) {
saveDistributeSub(distributeId, deadline, "" + (i+1) + "次任务", distributeVO); saveDistributeSub(distributeId, deadline, "" + (i+1) + "次任务", distributeVO);
} }
@ -289,6 +301,7 @@ public class DistributeServiceImpl extends DefaultBaseService implements IDistri
@Override @Override
public void update(String token, String distributeId, DistributeVO distributeVO) { public void update(String token, String distributeId, DistributeVO distributeVO) {
// 如果任务下派类型为立即下派则设置任务状态为已下派
if(!"立即下派".equals(distributeVO.getDistributeType())) { if(!"立即下派".equals(distributeVO.getDistributeType())) {
distributeVO.setDistributeStatus("未下派"); distributeVO.setDistributeStatus("未下派");
}else { }else {
@ -338,6 +351,7 @@ public class DistributeServiceImpl extends DefaultBaseService implements IDistri
/** /**
* 新增任务接收人 * 新增任务接收人
* 产生任务接收人数据
* @param distributeId * @param distributeId
* @param receiverUserVOList * @param receiverUserVOList
* @param distributeSubId * @param distributeSubId
@ -355,6 +369,11 @@ public class DistributeServiceImpl extends DefaultBaseService implements IDistri
} }
} }
/**
* 通过任务来保存关联表(任务清单)数据
* @param distributeVO
* @param distributeId
*/
private void setData(DistributeVO distributeVO, String distributeId) { private void setData(DistributeVO distributeVO, String distributeId) {
// 保存任务清单配置 // 保存任务清单配置
// 选择下派模板任务清单以模板为主 // 选择下派模板任务清单以模板为主
@ -477,13 +496,15 @@ public class DistributeServiceImpl extends DefaultBaseService implements IDistri
/** /**
* 专用于自动下派方法 * 专用于自动下派方法
* 任务列表
* @param params * @param params
* @return * @return
*/ */
private List<DistributeDTO> listForAuto(Map<String, Object> params) { private List<DistributeDTO> listForAuto(Map<String, Object> params) {
params.put("taskType", "正常"); params.put("receiveType", "下派");
List<DistributeDTO> distributeDTOList = distributeDao.list(params); List<DistributeDTO> distributeDTOList = distributeDao.list(params);
if(null != distributeDTOList && distributeDTOList.size() > 0) { if(null != distributeDTOList && distributeDTOList.size() > 0) {
// 获取任务接收人列表
for(DistributeDTO distributeDTO: distributeDTOList) { for(DistributeDTO distributeDTO: distributeDTOList) {
params.put("distributeId", distributeDTO.getDistributeId()); params.put("distributeId", distributeDTO.getDistributeId());
List<ReceiverUserDTO> receiverUserDTOList = receiverUserDao.listForAuto(params); List<ReceiverUserDTO> receiverUserDTOList = receiverUserDao.listForAuto(params);
@ -621,11 +642,14 @@ public class DistributeServiceImpl extends DefaultBaseService implements IDistri
params.remove("areaCode"); params.remove("areaCode");
} }
distributeDTOList = listForAuto(params); distributeDTOList = listForAuto(params);
sendTask(params, distributeDTOList); sendTask(params, distributeDTOList, 0);
// 获取所有任务模板中频率为循环任务的数据 // 获取所有任务模板中频率为循环任务的数据
// 包括已下派任务
String templateIds = ""; String templateIds = "";
if(null == distributeDTOList || distributeDTOList.size() < 1) { if(null == distributeDTOList || distributeDTOList.size() < 1) {
// 获取任务模板列表
// 筛选出任务类型为循环任务的数据
List<TemplateDTO> templateDTOList = templateService.list(params); List<TemplateDTO> templateDTOList = templateService.list(params);
if(null != templateDTOList && templateDTOList.size() > 0) { if(null != templateDTOList && templateDTOList.size() > 0) {
Iterator<TemplateDTO> iterator = templateDTOList.iterator(); Iterator<TemplateDTO> iterator = templateDTOList.iterator();
@ -645,10 +669,11 @@ public class DistributeServiceImpl extends DefaultBaseService implements IDistri
if(templateIds.length() > 0) { if(templateIds.length() > 0) {
templateIds = templateIds.substring(0, templateIds.length() - 1); templateIds = templateIds.substring(0, templateIds.length() - 1);
} }
// 获取任务为循环任务的数据
params.put("templateIds", Arrays.asList(templateIds.split("\\,"))); params.put("templateIds", Arrays.asList(templateIds.split("\\,")));
params.remove("distributeStatus"); params.remove("distributeStatus");
distributeDTOList = listForAuto(params); distributeDTOList = listForAuto(params);
sendTask(params, distributeDTOList); sendTask(params, distributeDTOList, 1);
} }
/** /**
@ -673,51 +698,22 @@ public class DistributeServiceImpl extends DefaultBaseService implements IDistri
* 遍历任务集合并下派 * 遍历任务集合并下派
* @param params * @param params
* @param distributeDTOList * @param distributeDTOList
* @param taskRateType
* taskRateType(0:单次任务/多次任务;1:循环任务)
* @throws ParseException * @throws ParseException
*/ */
private void sendTask(Map<String, Object> params, List<DistributeDTO> distributeDTOList) throws ParseException { private void sendTask(Map<String, Object> params, List<DistributeDTO> distributeDTOList, int taskRateType) throws ParseException {
if(null != distributeDTOList && distributeDTOList.size() > 0) { if(null != distributeDTOList && distributeDTOList.size() > 0) {
String userIds = null; String userIds = null;
// 系统当前时间 // 系统当前时间
String nowDateStr = df.format(new Date()); String nowDateStr = df.format(new Date());
// 遍历任务列表
for(DistributeDTO distributeDTO: distributeDTOList) { for(DistributeDTO distributeDTO: distributeDTOList) {
DistributeVO distributeVO = new DistributeVO(); // 任务频率类型为循环任务时保存任务接收人信息
List<ReceiverUserVO> receiverUserVOList = new ArrayList<>(); if(1 == taskRateType) {
RateDTO rateDTO = getRateData(distributeDTO.getTaskTemplate()); saveUserByLoopTask(distributeDTO);
String rateType = null; }else {
if(null != rateDTO) { userIds = saveUserData(distributeDTO.getReceiveUserList(), null);
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);
}
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())) { if("未下派".equals(distributeDTO.getDistributeStatus())) {
// 任务下派时间字符串 // 任务下派时间字符串
@ -738,6 +734,75 @@ public class DistributeServiceImpl extends DefaultBaseService implements IDistri
} }
} }
/**
* 此方法主要用于自动下派时任务频率类型为循环类型时什用
* @param distributeDTO
*/
private void saveUserByLoopTask(DistributeDTO distributeDTO) {
// 系统当前时间
String nowDateStr = df.format(new Date());
// distributeVO用于任务为循环任务时专用保存数据
DistributeVO distributeVO = new DistributeVO();
// receiverUserVOList用于任务为循环任务时专用保存数据
List<ReceiverUserVO> receiverUserVOList = new ArrayList<>();
// 获取当前任务为
RateDTO rateDTO = getRateData(distributeDTO.getTaskTemplate());
String rateType = null;
if(null != rateDTO) {
rateType = rateDTO.getRateType();
}
// 获取任务接收人列表并拼接接收人ID用于app端发送通知
String userIds = saveUserData(distributeDTO.getReceiveUserList(), receiverUserVOList);
distributeVO.setReceiverUserList(receiverUserVOList);
if("循环任务".equals(rateType)) {
try {
// 获取任务子表数据
DistributeSubDTO distributeSubDTO = distributeSubService.descGmtCreat(distributeDTO.getDistributeId());
if(null != distributeSubDTO) {
// 判断当前任务和上次子表任务下派时间是否符合下一次的下派时间符合的话则下派新的子表数据
boolean flag = DateUtils.isOverRateType(rateDTO.getCycleType(), nowDateStr, distributeSubDTO.getGmtCreate());
// 这里的!flag是因为当时间大小顺序颠倒时会出现数据计算错误问题则将两个时间反过来再计算一次
if(!flag) {
flag = DateUtils.isOverRateType(rateDTO.getCycleType(), distributeSubDTO.getGmtCreate(), nowDateStr);
}
// 如果满足条件则下派子表数据并产生新的任务接收人数据(新的数据还为任务下派选择的人员)
if(flag) {
setDistributeSubByRateType(rateDTO.getCycleType(), new Date(), distributeDTO.getDistributeId(), distributeVO);
receiverUserService.sendAppMsg("任务已下派", "您的任务:" + distributeDTO.getDistributeTitle() + "已下派,请及时接收并处理。", userIds);
}
}
}catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* 遍历任务接收人列表并返回userIds
* 用于自动下派
* @param receiverUserDTOList
* @param receiverUserVOList
* @return
*/
private String saveUserData(List<ReceiverUserDTO> receiverUserDTOList, List<ReceiverUserVO> receiverUserVOList) {
String userIds = "";
if(null != receiverUserDTOList && receiverUserDTOList.size() > 0) {
for(ReceiverUserDTO receiverUserDTO: receiverUserDTOList) {
if(null != receiverUserVOList) {
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);
}
return userIds;
}
@Override @Override
public void sendTask(String distributeId, DistributeVO distributeVO) { public void sendTask(String distributeId, DistributeVO distributeVO) {
sendTask(null, distributeId, distributeVO); sendTask(null, distributeId, distributeVO);

View File

@ -474,6 +474,10 @@
AND AND
t1.task_type = #{taskType} t1.task_type = #{taskType}
</if> </if>
<if test="receiveType != null and receiveType != ''">
AND
t1.receive_type = #{receiveType}
</if>
</select> </select>
<!-- 任务接收人列表 --> <!-- 任务接收人列表 -->

View File

@ -176,7 +176,7 @@
<div class="layui-card-body"> <div class="layui-card-body">
<form class="layui-form" action="" lay-filter="info"> <form class="layui-form" action="" lay-filter="info">
<div class="layui-form-item layui-form-text"> <div class="layui-form-item layui-form-text">
<label class="layui-form-label">回退原因</label> <label class="layui-form-label">任务评分</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input type="number" id="taskScore" name="taskScore" class="layui-input" value="" placeholder="请输入分数(0或正数)" lay-verify="integer"> <input type="number" id="taskScore" name="taskScore" class="layui-input" value="" placeholder="请输入分数(0或正数)" lay-verify="integer">
</div> </div>
@ -486,6 +486,7 @@
' <a class="layui-btn layui-btn-xs" lay-event="check">审核</a>\n' + ' <a class="layui-btn layui-btn-xs" lay-event="check">审核</a>\n' +
' <a class="layui-btn layui-btn-xs" lay-event="taskStatus">执行状态</a>\n' + ' <a class="layui-btn layui-btn-xs" lay-event="taskStatus">执行状态</a>\n' +
' <a class="layui-btn layui-btn-xs" lay-event="taskPatrol">任务记录</a>\n' + ' <a class="layui-btn layui-btn-xs" lay-event="taskPatrol">任务记录</a>\n' +
' <a class="layui-btn layui-btn-xs" lay-event="addScore">评分</a>\n' +
' <a class="layui-btn layui-btn-xs" lay-event="isWarning">预警</a>\n' + ' <a class="layui-btn layui-btn-xs" lay-event="isWarning">预警</a>\n' +
' <a class="layui-btn layui-btn-xs" lay-event="isSupervision">督办</a>\n' + ' <a class="layui-btn layui-btn-xs" lay-event="isSupervision">督办</a>\n' +
'</div>'; '</div>';