Commit e7263365 authored by zhangsen's avatar zhangsen

巡检发送消息改为单独的定时任务

parent 3480f6ec
...@@ -220,6 +220,32 @@ public class PlanTaskController extends AbstractBaseController { ...@@ -220,6 +220,32 @@ public class PlanTaskController extends AbstractBaseController {
} }
/** /**
* 定时任务推送巡检待办任务消息
*/
@Scheduled(cron = "${jobs.cron}")
public void taskMessage() {
planTaskService.taskMessage(null);
}
/**
* 模拟发送巡检待办任务消息定时任务
*
* @return
*/
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(value = "模拟发送巡检待办任务消息定时任务", notes = "模拟发送巡检待办任务消息定时任务")
@RequestMapping(value = "/taskMessage", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
public CommonResponse taskMessage(@ApiParam(value = "跑批日期格式yyyyMMdd", required = false) @RequestParam(required = false) String runDate) {
try {
planTaskService.taskMessage(runDate);
return CommonResponseUtil.success();
} catch (Exception e) {
log.error(e.getMessage(), e);
return CommonResponseUtil.failure();
}
}
/**
* 模拟定时任务调起服务 * 模拟定时任务调起服务
* *
* @return * @return
......
package com.yeejoin.amos.patrol.business.dao.mapper; package com.yeejoin.amos.patrol.business.dao.mapper;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.yeejoin.amos.patrol.dao.entity.Plan;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import com.yeejoin.amos.patrol.business.entity.mybatis.CheckChkExListBo; import com.yeejoin.amos.patrol.business.entity.mybatis.CheckChkExListBo;
...@@ -185,5 +187,7 @@ public interface PlanTaskMapper extends BaseMapper { ...@@ -185,5 +187,7 @@ public interface PlanTaskMapper extends BaseMapper {
List<Map<String, Object>> queryTimeAxis(HashMap<String, Object> params); List<Map<String, Object>> queryTimeAxis(HashMap<String, Object> params);
List<Plan> getPlanIdsByDate(@Param("date") Date date);
List<PlanTask> getPlanTaskList(@Param("date") Date date);
} }
...@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONArray; ...@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.yeejoin.amos.boot.biz.common.constants.RuleConstant; import com.yeejoin.amos.boot.biz.common.constants.RuleConstant;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.amos.component.rule.RuleTrigger; import com.yeejoin.amos.component.rule.RuleTrigger;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel; import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import com.yeejoin.amos.feign.privilege.model.DepartmentModel; import com.yeejoin.amos.feign.privilege.model.DepartmentModel;
...@@ -116,6 +117,11 @@ public class PlanTaskServiceImpl implements IPlanTaskService { ...@@ -116,6 +117,11 @@ public class PlanTaskServiceImpl implements IPlanTaskService {
@Autowired @Autowired
private RuleTrigger ruleTrigger; private RuleTrigger ruleTrigger;
@Autowired
RedisUtils redisUtils;
private final String PATROL_PLAN_TASK_KEY = "PATROL_PLAN_ID:";
private final String packageId = "消息/addCheckRule"; private final String packageId = "消息/addCheckRule";
private final String msgType = "patrolSystem"; private final String msgType = "patrolSystem";
private final String APP = "APP"; private final String APP = "APP";
...@@ -713,8 +719,8 @@ public class PlanTaskServiceImpl implements IPlanTaskService { ...@@ -713,8 +719,8 @@ public class PlanTaskServiceImpl implements IPlanTaskService {
planTask.setEndTime(endTime); planTask.setEndTime(endTime);
// 1.保存执行数据主表 // 1.保存执行数据主表
iplanTaskDao.saveAndFlush(planTask); iplanTaskDao.saveAndFlush(planTask);
// 发送APP待办消息 // 发送APP待办消息 (20220617 改为定时任务发送消息)
sendMessage(plan, planTask); // sendMessage(plan, planTask);
String executorId = planTask.getUserId(); String executorId = planTask.getUserId();
long planId = planTask.getId(); long planId = planTask.getId();
for (int i1 = 0; i1 < pointIdList.size(); i1++) { for (int i1 = 0; i1 < pointIdList.size(); i1++) {
...@@ -765,6 +771,35 @@ public class PlanTaskServiceImpl implements IPlanTaskService { ...@@ -765,6 +771,35 @@ public class PlanTaskServiceImpl implements IPlanTaskService {
} }
//bug 5980 待办任务消息应只触发执行中的任务,漏检的任务和未开始的任务不需要触发待办任务消息.
@Override
@Transactional
public void taskMessage(String runDate) {
SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");
//1.扫描plan表查询,需要生成执行数据的任务信息,无则return
Date now = new Date();//今天
String format = df.format(now);
if (runDate != null) {//上送则已上送的为准
runDate = runDate + " " + format;
now = DateUtil.str2Date(runDate, "yyyyMMdd HH:mm:ss");
}
List<Plan> planIdsByDate = planTaskMapper.getPlanIdsByDate(now);
List<PlanTask> planTaskList = planTaskMapper.getPlanTaskList(now);
Map<Long, Plan> collect = planIdsByDate.stream().collect(Collectors.toMap(Plan::getId, t -> t));
for (PlanTask planTask : planTaskList) {
if (!redisUtils.hasKey(PATROL_PLAN_TASK_KEY + planTask.getId())) {
try {
sendMessage(collect.get(planTask.getPlanId()), planTask);
} catch (Exception e) {
e.printStackTrace();
}
redisUtils.set(PATROL_PLAN_TASK_KEY + planTask.getId(), 1, (long) collect.get(planTask.getPlanId()).getDuration() * 60);
}
}
}
public void sendMessage(Plan plan, PlanTask planTask) throws Exception { public void sendMessage(Plan plan, PlanTask planTask) throws Exception {
MsgRo msgRo = new MsgRo(); MsgRo msgRo = new MsgRo();
// 标题 // 标题
......
...@@ -46,6 +46,13 @@ public interface IPlanTaskService { ...@@ -46,6 +46,13 @@ public interface IPlanTaskService {
void taskExecution(String runDate); void taskExecution(String runDate);
/** /**
* 定时任务发送消息执行中的消息
*
* @param runDate
*/
void taskMessage(String runDate);
/**
* 根据路线id获取关联的所有计划任务 * 根据路线id获取关联的所有计划任务
* *
* @param routeId * @param routeId
......
...@@ -974,4 +974,29 @@ ...@@ -974,4 +974,29 @@
ORDER BY ORDER BY
ppk.begin_time DESC LIMIT 60 ppk.begin_time DESC LIMIT 60
</select> </select>
<select id="getPlanIdsByDate" resultType="com.yeejoin.amos.patrol.dao.entity.Plan">
select *
from p_plan
where id in (
select plan_id
from p_plan_task
where
begin_time &lt;= #{date,jdbcType=TIMESTAMP}
and end_time &gt; #{date,jdbcType=TIMESTAMP}
and finish_status in (0, 1)
and status = 0
group by plan_id
)
</select>
<select id="getPlanTaskList" resultType="com.yeejoin.amos.patrol.dao.entity.PlanTask">
select *
from p_plan_task
where
begin_time &lt;= #{date,jdbcType=TIMESTAMP}
and end_time &gt; #{date,jdbcType=TIMESTAMP}
and finish_status in (0, 1)
and status = 0
</select>
</mapper> </mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment