Commit c5f4e25d by Ren Ping

feat:增加服务类消息预警自动任务

1 parent b3b193bd
......@@ -102,4 +102,10 @@ public interface OrderInfoDao extends JpaRepository<OrderInfoEntity, Long>, JpaS
@Query(value = "SELECT count(*) from order_info WHERE dt =:dt and service_status ='STARTED' and actual_end_time is null " +
"and DATE_ADD(NOW(), INTERVAL 10 MINUTE) > plan_end_time and org_branch_id = :orgBranchId", nativeQuery = true)
long countOvertimeByDtAndOrgBranchId(LocalDate dt, String orgBranchId);
@Query(value = "from OrderInfoEntity where orderStatus <> 'CANCELED' and engineerCode is not null"
+ " and planStartTime is not null and planEndTime is not null and planStartTime>?1"
+ " and ((actualStartTime is null and planStartTime<= ?2) "
+ " or (actualStartTime is not null and actualEndTime is null and planEndTime<= ?2))")
List<OrderInfoEntity> getDelayOrTimeoutOrder(LocalDateTime today, LocalDateTime now);
}
package com.dituhui.pea.order.scheduler;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.StrUtil;
import com.dituhui.pea.order.dao.*;
import com.dituhui.pea.order.dto.MsgDTO;
import com.dituhui.pea.order.entity.*;
import com.dituhui.pea.order.enums.MsgTagEnum;
import com.dituhui.pea.order.enums.MsgTypeEnum;
import com.dituhui.pea.order.service.MsgService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
@Slf4j
@Component
public class ServiceMsgScheduler {
@Resource
private OrderInfoDao orderInfoDao;
@Resource
private MsgService msgService;
@Resource
private OrgGroupDao orgGroupDao;
@Resource
private OrgBranchDao orgBranchDao;
@Resource
private OrgClusterDao orgClusterDao;
@Resource
private EngineerInfoDao engineerInfoDao;
@Scheduled(cron = "${scheduler.service-msg}")
public void run() {
log.info(">>> 服务类消息预警开始");
LocalDateTime today = LocalDateTimeUtil.beginOfDay(LocalDateTime.now());
LocalDateTime now = LocalDateTime.now().plusMinutes(10);
List<OrderInfoEntity> orderList = orderInfoDao.getDelayOrTimeoutOrder(today, now);
String delayContent = "%s机构%s员工(工号%s)的%s工单未按预约开始时间%s上门";
String timeoutContent = "%s机构%s员工(工号%s)的%s工单未按预约结束时间%s结束服务";
for (OrderInfoEntity orderInfoEntity : orderList) {
try {
MsgDTO dto = new MsgDTO();
dto.setClusterId(orderInfoEntity.getOrgClusterId());
dto.setBranchId(orderInfoEntity.getOrgBranchId());
dto.setGroupId(orderInfoEntity.getOrgGroupId());
dto.setType(MsgTypeEnum.SERVICE.getCode());
dto.setTag(MsgTagEnum.URGENT.getCode());
dto.setOrderIds(orderInfoEntity.getOrderId());
String orgName = null;
try {
if (StrUtil.isNotEmpty(dto.getGroupId())) {
orgName = orgGroupDao.getByGroupId(dto.getGroupId()).getGroupName();
} else if (StrUtil.isNotEmpty(dto.getBranchId())) {
orgName = orgBranchDao.getByBranchId(dto.getBranchId()).getBranchName();
} else if (StrUtil.isNotEmpty(dto.getClusterId())) {
orgName = orgClusterDao.getByClusterId(dto.getClusterId()).getName();
}
} catch (Exception e) {
log.error("工单({}) 组织机构未找到", orderInfoEntity.getOrderId());
}
String engineerName = null;
try {
engineerName = engineerInfoDao.getByEngineerCode(orderInfoEntity.getEngineerCode()).getName();
} catch (Exception e) {
log.error("工程师({}) 未找到", orderInfoEntity.getEngineerCode());
}
if (Objects.isNull(orderInfoEntity.getActualStartTime())) {//delay
dto.setContent(String.format(delayContent,
orgName,
engineerName,
orderInfoEntity.getEngineerCode(),
orderInfoEntity.getOrderId(),
DateUtil.format(orderInfoEntity.getPlanStartTime(), "yyyy-MM-dd HH:mm")
));
} else {//超时
dto.setContent(String.format(timeoutContent,
orgName,
engineerName,
orderInfoEntity.getEngineerCode(),
orderInfoEntity.getOrderId(),
DateUtil.format(orderInfoEntity.getPlanEndTime(), "yyyy-MM-dd HH:mm")
));
}
msgService.add(dto);
} catch (Exception e) {
log.error("工单(" + orderInfoEntity.getOrderId() + ") 预警消息保存失败:" + e.getMessage(), e);
}
}
log.info(">>> 服务类消息预警结束");
}
}
......@@ -90,4 +90,6 @@ scheduler:
# 8-20点,每小时1次
cron-expr: 0 0 1-23 * * ?
day-offset-begin: 0
day-offset-end: 14
\ No newline at end of file
day-offset-end: 14
service-msg: 0 40 11,17 * * ?
\ No newline at end of file
......@@ -90,6 +90,9 @@ scheduler:
cron-expr: 0 0 1-23 * * ?
day-offset-begin: 0
day-offset-end: 20
service-msg: 0 0 11,17 * * ?
logging:
level:
root: info
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!