自动下派功能优化。
This commit is contained in:
parent
0f79297002
commit
586af83c84
@ -110,6 +110,7 @@ public class DistributeServiceImpl extends DefaultBaseService implements IDistri
|
||||
distributeVO.setDistributeStatus("已下派");
|
||||
}
|
||||
|
||||
// 设置任务清单数据
|
||||
setData(distributeVO, distributeId);
|
||||
|
||||
// 选择下派模板,判断模板中任务频率,若为单次,截止日期为一条,若为多次,截止日期为多条
|
||||
@ -125,6 +126,7 @@ public class DistributeServiceImpl extends DefaultBaseService implements IDistri
|
||||
}
|
||||
distributeDao.save(params);
|
||||
|
||||
// 获取任务频率相关信息
|
||||
RateDTO rateDTO = getRateData(distributeVO.getTaskTemplate());
|
||||
|
||||
String rateType = null;
|
||||
@ -132,6 +134,8 @@ public class DistributeServiceImpl extends DefaultBaseService implements IDistri
|
||||
rateType = rateDTO.getRateType();
|
||||
}
|
||||
|
||||
// 如果任务频率为循环任务,则定时下派任务
|
||||
// 否则正常下派
|
||||
if("循环任务".equals(rateType)) {
|
||||
try {
|
||||
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) {
|
||||
Date endDate = dateRange.getEnd();
|
||||
String deadline = df.format(endDate).substring(0, 10);
|
||||
@ -215,6 +225,8 @@ public class DistributeServiceImpl extends DefaultBaseService implements IDistri
|
||||
|
||||
/**
|
||||
* 设置截止时间
|
||||
* 若截止日期为多条时,保存子表数据
|
||||
* 此方法不考虑循环任务,只考虑单次和多次任务
|
||||
* @param distributeId
|
||||
* @param distributeVO
|
||||
*/
|
||||
@ -233,7 +245,7 @@ public class DistributeServiceImpl extends DefaultBaseService implements IDistri
|
||||
}else {
|
||||
stringBuffer.append("," + deadline);
|
||||
}
|
||||
|
||||
// 截止时间为多条时,设置子表数据
|
||||
if(deadlineList.size() > 1) {
|
||||
saveDistributeSub(distributeId, deadline, "第" + (i+1) + "次任务", distributeVO);
|
||||
}
|
||||
@ -289,6 +301,7 @@ public class DistributeServiceImpl extends DefaultBaseService implements IDistri
|
||||
|
||||
@Override
|
||||
public void update(String token, String distributeId, DistributeVO distributeVO) {
|
||||
// 如果任务下派类型为立即下派,则设置任务状态为已下派
|
||||
if(!"立即下派".equals(distributeVO.getDistributeType())) {
|
||||
distributeVO.setDistributeStatus("未下派");
|
||||
}else {
|
||||
@ -338,6 +351,7 @@ public class DistributeServiceImpl extends DefaultBaseService implements IDistri
|
||||
|
||||
/**
|
||||
* 新增任务接收人
|
||||
* 产生任务接收人数据
|
||||
* @param distributeId
|
||||
* @param receiverUserVOList
|
||||
* @param distributeSubId
|
||||
@ -355,6 +369,11 @@ public class DistributeServiceImpl extends DefaultBaseService implements IDistri
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过任务来保存关联表(任务清单)数据
|
||||
* @param distributeVO
|
||||
* @param distributeId
|
||||
*/
|
||||
private void setData(DistributeVO distributeVO, String distributeId) {
|
||||
// 保存任务清单配置
|
||||
// 选择下派模板:任务清单以模板为主
|
||||
@ -477,13 +496,15 @@ public class DistributeServiceImpl extends DefaultBaseService implements IDistri
|
||||
|
||||
/**
|
||||
* 专用于自动下派方法
|
||||
* 任务列表
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
private List<DistributeDTO> listForAuto(Map<String, Object> params) {
|
||||
params.put("taskType", "正常");
|
||||
params.put("receiveType", "下派");
|
||||
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);
|
||||
@ -621,11 +642,14 @@ public class DistributeServiceImpl extends DefaultBaseService implements IDistri
|
||||
params.remove("areaCode");
|
||||
}
|
||||
distributeDTOList = listForAuto(params);
|
||||
sendTask(params, distributeDTOList);
|
||||
sendTask(params, distributeDTOList, 0);
|
||||
|
||||
// 获取所有任务模板中频率为循环任务的数据
|
||||
// 包括已下派任务
|
||||
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();
|
||||
@ -645,10 +669,11 @@ public class DistributeServiceImpl extends DefaultBaseService implements IDistri
|
||||
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);
|
||||
sendTask(params, distributeDTOList, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -673,51 +698,22 @@ public class DistributeServiceImpl extends DefaultBaseService implements IDistri
|
||||
* 遍历任务集合并下派
|
||||
* @param params
|
||||
* @param distributeDTOList
|
||||
* @param taskRateType
|
||||
* taskRateType(0:单次任务/多次任务;1:循环任务)
|
||||
* @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) {
|
||||
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);
|
||||
}
|
||||
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(1 == taskRateType) {
|
||||
saveUserByLoopTask(distributeDTO);
|
||||
}else {
|
||||
userIds = saveUserData(distributeDTO.getReceiveUserList(), null);
|
||||
}
|
||||
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
|
||||
public void sendTask(String distributeId, DistributeVO distributeVO) {
|
||||
sendTask(null, distributeId, distributeVO);
|
||||
|
@ -474,6 +474,10 @@
|
||||
AND
|
||||
t1.task_type = #{taskType}
|
||||
</if>
|
||||
<if test="receiveType != null and receiveType != ''">
|
||||
AND
|
||||
t1.receive_type = #{receiveType}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<!-- 任务接收人列表 -->
|
||||
|
@ -176,7 +176,7 @@
|
||||
<div class="layui-card-body">
|
||||
<form class="layui-form" action="" lay-filter="info">
|
||||
<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">
|
||||
<input type="number" id="taskScore" name="taskScore" class="layui-input" value="" placeholder="请输入分数(0或正数)" lay-verify="integer">
|
||||
</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="taskStatus">执行状态</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="isSupervision">督办</a>\n' +
|
||||
'</div>';
|
||||
|
Loading…
Reference in New Issue
Block a user