Browse Source

update: 车辆/特种设备模块推送消息逻辑修改

zhongwei
liwen 8 months ago
parent
commit
00719f8797
  1. 135
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/jobs/CarJob.java
  2. 50
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/jobs/SpecialDeviceJob.java
  3. 18
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICarService.java
  4. 18
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarServiceImpl.java

135
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/jobs/CarJob.java

@ -67,53 +67,56 @@ public class CarJob {
String today = DateUtil.format(current, DateUtil.PATTERN_DATE); String today = DateUtil.format(current, DateUtil.PATTERN_DATE);
String yesterday = DateUtil.format(before, DateUtil.PATTERN_DATE); String yesterday = DateUtil.format(before, DateUtil.PATTERN_DATE);
// 车保状态变更 // 车保状态变更
List<CarEntity> uninsuredCarList = carService.getCarListByInsuranceTime(today, yesterday); List<CarEntity> uninsuredCarList = carService.getCarListByInsuranceTime(yesterday, today);
if (!CollectionUtils.isEmpty(uninsuredCarList)) { if (!CollectionUtils.isEmpty(uninsuredCarList)) {
uninsuredCarList.forEach(car -> car.setInsuranceStatus(CarInsuranceStatusEnum.UNINSURED.getValue())); uninsuredCarList.forEach(car -> car.setInsuranceStatus(CarInsuranceStatusEnum.UNINSURED.getValue()));
boolean insuranceUpdate = carService.updateBatchById(uninsuredCarList); boolean insuranceUpdate = carService.updateBatchById(uninsuredCarList);
if (!insuranceUpdate) { if (!insuranceUpdate) {
return ReturnT.FAIL; return ReturnT.FAIL;
} }
// 变更成功则推送消息
uninsuredCarList.forEach(this::sendUninsuredMessage);
} }
// 维保状态变更 // 维保状态变更
List<CarEntity> unmaintainedCarList = carService.getCarListByMaintenanceTime(today, yesterday); List<CarEntity> unmaintainedCarList = carService.getCarListByMaintenanceTime(yesterday, today);
if (!CollectionUtils.isEmpty(unmaintainedCarList)) { if (!CollectionUtils.isEmpty(unmaintainedCarList)) {
unmaintainedCarList.forEach(car -> car.setMaintenanceStatus(CarMaintenanceStatusEnum.UNMAINTAINED.getValue())); unmaintainedCarList.forEach(car -> car.setMaintenanceStatus(CarMaintenanceStatusEnum.UNMAINTAINED.getValue()));
boolean maintenanceUpdate = carService.updateBatchById(unmaintainedCarList); boolean maintenanceUpdate = carService.updateBatchById(unmaintainedCarList);
if (!maintenanceUpdate) { if (!maintenanceUpdate) {
return ReturnT.FAIL; return ReturnT.FAIL;
} }
// 变更成功则推送消息
unmaintainedCarList.forEach(this::sendUnmaintainedMessage);
} }
// 年检状态变更 // 年检状态变更
List<CarEntity> uninspectedCarList = carService.getCarListByAnnualInspectionTime(today, yesterday); List<CarEntity> uninspectedCarList = carService.getCarListByAnnualInspectionTime(yesterday, today);
if (!CollectionUtils.isEmpty(uninspectedCarList)) { if (!CollectionUtils.isEmpty(uninspectedCarList)) {
uninspectedCarList.forEach(car -> car.setAnnualInspectionStatus(CarAnnualInspectionStatusEnum.UNFINISHED.getValue())); uninspectedCarList.forEach(car -> car.setAnnualInspectionStatus(CarAnnualInspectionStatusEnum.UNFINISHED.getValue()));
boolean inspectionUpdate = carService.updateBatchById(uninspectedCarList); boolean inspectionUpdate = carService.updateBatchById(uninspectedCarList);
if (!inspectionUpdate) { if (!inspectionUpdate) {
return ReturnT.FAIL; return ReturnT.FAIL;
} }
// 变更成功则推送消息
uninspectedCarList.forEach(this::sendUninspectedMessage);
} }
return ReturnT.SUCCESS; return ReturnT.SUCCESS;
} }
/** /**
* 推送车保过期消息 * 推送车保即将过期消息
* @param carEntity 车辆实体类
*/ */
private void sendUninsuredMessage(CarEntity carEntity) { @XxlJob("sendExpiredInsuranceMessage")
if (carEntity.getManagerId() == null) { public ReturnT<String> sendExpiredInsuranceMessage(String param) {
log.error("系统无该用户信息,推送车保过期消息失败"); // 获取时间范围
return; Date current = DateUtil.now();
Date next = DateUtil.plusDays(current, 2);
String today = DateUtil.format(current, DateUtil.PATTERN_DATE);
String tomorrow = DateUtil.format(next, DateUtil.PATTERN_DATE);
// 获取车保状态即将过期的车辆
List<CarEntity> uninsuredCarList = carService.getCarListByInsuranceTime(today, tomorrow);
if (!CollectionUtils.isEmpty(uninsuredCarList)) {
for (CarEntity car : uninsuredCarList) {
if (car.getManagerId() == null) {
return new ReturnT<>("系统无该用户信息,无法推送车保过期提醒消息");
} }
// 查询用户 // 查询用户
R<User> userRes = userClient.userInfoById(carEntity.getManagerId()); R<User> userRes = userClient.userInfoById(car.getManagerId());
User user = userRes.getData(); User user = userRes.getData();
// 推送消息
BusinessMessageDTO businessMessageDTO = new BusinessMessageDTO(); BusinessMessageDTO businessMessageDTO = new BusinessMessageDTO();
if (StringUtils.isNotEmpty(user.getDeptId())) { if (StringUtils.isNotEmpty(user.getDeptId())) {
Long id = Long.valueOf(user.getDeptId()); Long id = Long.valueOf(user.getDeptId());
@ -121,28 +124,43 @@ public class CarJob {
businessMessageDTO.setDeptName(sysClient.getDeptName(id).getData()); businessMessageDTO.setDeptName(sysClient.getDeptName(id).getData());
businessMessageDTO.setBusinessKey("车保到期"); businessMessageDTO.setBusinessKey("车保到期");
businessMessageDTO.setBusinessClassify("system"); businessMessageDTO.setBusinessClassify("system");
businessMessageDTO.setTaskId(carEntity.getId()); businessMessageDTO.setTaskId(car.getId());
businessMessageDTO.setSubject("车保到期通知"); businessMessageDTO.setSubject("车保即将到期提醒");
businessMessageDTO.setContent("您所管理的车辆" + carEntity.getPlateNumber() + "车保已过期,请及时续保。"); businessMessageDTO.setContent("您所管理的车辆" + car.getPlateNumber() + "的车保即将过期,请及时续保。");
businessMessageDTO.setUserIds(String.valueOf(carEntity.getManagerId())); businessMessageDTO.setUserIds(String.valueOf(car.getManagerId()));
businessMessageDTO.setCreateUser(carEntity.getCreateUser()); businessMessageDTO.setCreateUser(car.getCreateUser());
businessMessageDTO.setTenantId(CommonConstant.TENANT_ID); businessMessageDTO.setTenantId(CommonConstant.TENANT_ID);
} }
messageClient.sendAppAndWsMsgByUsers(businessMessageDTO); R<Boolean> res = messageClient.sendAppAndWsMsgByUsers(businessMessageDTO);
if (!res.isSuccess()) {
return ReturnT.FAIL;
}
}
}
return ReturnT.SUCCESS;
} }
/** /**
* 推送维保过期消息 * 推送维保即将过期消息
* @param carEntity 车辆实体类
*/ */
private void sendUnmaintainedMessage(CarEntity carEntity) { @XxlJob("sendExpiredMaintainedMessage")
if (carEntity.getManagerId() == null) { public ReturnT<String> sendExpiredMaintainedMessage(String param) {
log.error("系统无该用户信息,推送维保过期消息失败"); // 获取时间范围
return; Date current = DateUtil.now();
Date next = DateUtil.plusDays(current, 2);
String today = DateUtil.format(current, DateUtil.PATTERN_DATE);
String tomorrow = DateUtil.format(next, DateUtil.PATTERN_DATE);
// 获取维保状态即将过期的车辆
List<CarEntity> unmaintainedCarList = carService.getCarListByMaintenanceTime(today, tomorrow);
if (!CollectionUtils.isEmpty(unmaintainedCarList)) {
for (CarEntity car : unmaintainedCarList) {
if (car.getManagerId() == null) {
return new ReturnT<>("系统无该用户信息,无法推送维保过期提醒消息");
} }
// 查询用户 // 查询用户
R<User> userRes = userClient.userInfoById(carEntity.getManagerId()); R<User> userRes = userClient.userInfoById(car.getManagerId());
User user = userRes.getData(); User user = userRes.getData();
// 推送消息
BusinessMessageDTO businessMessageDTO = new BusinessMessageDTO(); BusinessMessageDTO businessMessageDTO = new BusinessMessageDTO();
if (StringUtils.isNotEmpty(user.getDeptId())) { if (StringUtils.isNotEmpty(user.getDeptId())) {
Long id = Long.valueOf(user.getDeptId()); Long id = Long.valueOf(user.getDeptId());
@ -150,28 +168,43 @@ public class CarJob {
businessMessageDTO.setDeptName(sysClient.getDeptName(id).getData()); businessMessageDTO.setDeptName(sysClient.getDeptName(id).getData());
businessMessageDTO.setBusinessKey("维保到期"); businessMessageDTO.setBusinessKey("维保到期");
businessMessageDTO.setBusinessClassify("system"); businessMessageDTO.setBusinessClassify("system");
businessMessageDTO.setTaskId(carEntity.getId()); businessMessageDTO.setTaskId(car.getId());
businessMessageDTO.setSubject("维保到期通知"); businessMessageDTO.setSubject("维保即将到期提醒");
businessMessageDTO.setContent("您所管理的车辆" + carEntity.getPlateNumber() + "维保已过期,请及时进行维保。"); businessMessageDTO.setContent("您所管理的车辆" + car.getPlateNumber() + "的维保即将过期,请及时进行维保。");
businessMessageDTO.setUserIds(String.valueOf(carEntity.getManagerId())); businessMessageDTO.setUserIds(String.valueOf(car.getManagerId()));
businessMessageDTO.setCreateUser(carEntity.getCreateUser()); businessMessageDTO.setCreateUser(car.getCreateUser());
businessMessageDTO.setTenantId(CommonConstant.TENANT_ID); businessMessageDTO.setTenantId(CommonConstant.TENANT_ID);
} }
messageClient.sendAppAndWsMsgByUsers(businessMessageDTO); R<Boolean> res = messageClient.sendAppAndWsMsgByUsers(businessMessageDTO);
if (!res.isSuccess()) {
return ReturnT.FAIL;
}
}
}
return ReturnT.SUCCESS;
} }
/** /**
* 推送年检过期消息 * 推送年检即将过期消息
* @param carEntity 车辆实体类
*/ */
private void sendUninspectedMessage(CarEntity carEntity) { @XxlJob("sendExpiredInspectedMessage")
if (carEntity.getManagerId() == null) { public ReturnT<String> sendExpiredInspectedMessage(String param) {
log.error("系统无该用户信息,推送年检过期消息失败"); // 获取时间范围
return; Date current = DateUtil.now();
Date next = DateUtil.plusDays(current, 2);
String today = DateUtil.format(current, DateUtil.PATTERN_DATE);
String tomorrow = DateUtil.format(next, DateUtil.PATTERN_DATE);
// 获取维保状态即将过期的车辆
List<CarEntity> uninspectedCarList = carService.getCarListByAnnualInspectionTime(today, tomorrow);
if (!CollectionUtils.isEmpty(uninspectedCarList)) {
for (CarEntity car : uninspectedCarList) {
if (car.getManagerId() == null) {
return new ReturnT<>("系统无该用户信息,无法推送年检过期提醒消息");
} }
// 查询用户 // 查询用户
R<User> userRes = userClient.userInfoById(carEntity.getManagerId()); R<User> userRes = userClient.userInfoById(car.getManagerId());
User user = userRes.getData(); User user = userRes.getData();
// 推送消息
BusinessMessageDTO businessMessageDTO = new BusinessMessageDTO(); BusinessMessageDTO businessMessageDTO = new BusinessMessageDTO();
if (StringUtils.isNotEmpty(user.getDeptId())) { if (StringUtils.isNotEmpty(user.getDeptId())) {
Long id = Long.valueOf(user.getDeptId()); Long id = Long.valueOf(user.getDeptId());
@ -179,13 +212,19 @@ public class CarJob {
businessMessageDTO.setDeptName(sysClient.getDeptName(id).getData()); businessMessageDTO.setDeptName(sysClient.getDeptName(id).getData());
businessMessageDTO.setBusinessKey("年检到期"); businessMessageDTO.setBusinessKey("年检到期");
businessMessageDTO.setBusinessClassify("system"); businessMessageDTO.setBusinessClassify("system");
businessMessageDTO.setTaskId(carEntity.getId()); businessMessageDTO.setTaskId(car.getId());
businessMessageDTO.setSubject("年检到期通知"); businessMessageDTO.setSubject("年检即将到期提醒");
businessMessageDTO.setContent("您所管理的车辆" + carEntity.getPlateNumber() + "年检已过期,请及时进行年检。"); businessMessageDTO.setContent("您所管理的车辆" + car.getPlateNumber() + "的年检即将过期,请及时进行年检。");
businessMessageDTO.setUserIds(String.valueOf(carEntity.getManagerId())); businessMessageDTO.setUserIds(String.valueOf(car.getManagerId()));
businessMessageDTO.setCreateUser(carEntity.getCreateUser()); businessMessageDTO.setCreateUser(car.getCreateUser());
businessMessageDTO.setTenantId(CommonConstant.TENANT_ID); businessMessageDTO.setTenantId(CommonConstant.TENANT_ID);
} }
messageClient.sendAppAndWsMsgByUsers(businessMessageDTO); R<Boolean> res = messageClient.sendAppAndWsMsgByUsers(businessMessageDTO);
if (!res.isSuccess()) {
return ReturnT.FAIL;
}
}
}
return ReturnT.SUCCESS;
} }
} }

50
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/jobs/SpecialDeviceJob.java

@ -11,6 +11,7 @@ import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob; import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.api.R; import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.DateUtil;
import org.springblade.system.feign.ISysClient; import org.springblade.system.feign.ISysClient;
import org.springblade.system.user.entity.User; import org.springblade.system.user.entity.User;
@ -44,6 +45,9 @@ public class SpecialDeviceJob {
@Autowired @Autowired
IMessageClient messageClient; IMessageClient messageClient;
/**
* 特种设备状态自动变更
*/
@XxlJob("autoChangeDeviceStatus") @XxlJob("autoChangeDeviceStatus")
public ReturnT<String> autoChangeDeviceStatus(String param) { public ReturnT<String> autoChangeDeviceStatus(String param) {
// 获取时间范围 // 获取时间范围
@ -54,11 +58,10 @@ public class SpecialDeviceJob {
// 查询昨天的过期设备 // 查询昨天的过期设备
List<SpecialDeviceEntity> list = deviceService.getExpiredDeviceByTime(yesterday, today); List<SpecialDeviceEntity> list = deviceService.getExpiredDeviceByTime(yesterday, today);
if (CollectionUtils.isEmpty(list)) { if (CollectionUtils.isEmpty(list)) {
return ReturnT.SUCCESS; return new ReturnT<>("无即将过期的特种设备");
} }
list.forEach(device -> { list.forEach(device -> {
device.setDeviceStatus(DeviceStatusEnum.EXPIRED.getValue()); device.setDeviceStatus(DeviceStatusEnum.EXPIRED.getValue());
sendExpiredMessage(device);
}); });
// 更新状态 // 更新状态
boolean update = deviceService.updateBatchById(list); boolean update = deviceService.updateBatchById(list);
@ -66,31 +69,46 @@ public class SpecialDeviceJob {
} }
/** /**
* 推送设备过期消息 * 推送设备即将过期消息
* @param specialDeviceEntity 特种设备实体类
*/ */
private void sendExpiredMessage(SpecialDeviceEntity specialDeviceEntity) { @XxlJob("sendExpiredDeviceMessage")
if (specialDeviceEntity.getManagerId() == null) { public ReturnT<String> sendExpiredDeviceMessage(String param) {
log.error("系统无该用户信息,推送设备过期消息失败"); // 获取时间范围
return; Date current = DateUtil.now();
Date next = DateUtil.plusDays(current, 2);
String today = DateUtil.format(current, DateUtil.PATTERN_DATE);
String tomorrow = DateUtil.format(next, DateUtil.PATTERN_DATE);
// 查询即将的过期设备
List<SpecialDeviceEntity> list = deviceService.getExpiredDeviceByTime(today, tomorrow);
if (CollectionUtil.isNotEmpty(list)) {
for (SpecialDeviceEntity device : list) {
if (device.getManagerId() == null) {
return new ReturnT<>("系统无该用户信息,无法推送特种设备过期提醒消息");
} }
// 查询用户 // 查询用户
R<User> userRes = userClient.userInfoById(specialDeviceEntity.getManagerId()); R<User> userRes = userClient.userInfoById(device.getManagerId());
User user = userRes.getData(); User user = userRes.getData();
BusinessMessageDTO businessMessageDTO = new BusinessMessageDTO(); BusinessMessageDTO businessMessageDTO = new BusinessMessageDTO();
if (StringUtils.isNotEmpty(user.getDeptId())) { if (StringUtils.isNotEmpty(user.getDeptId())) {
Long id = Long.valueOf(user.getDeptId()); Long id = Long.valueOf(user.getDeptId());
businessMessageDTO.setDeptId(id); businessMessageDTO.setDeptId(id);
businessMessageDTO.setDeptName(sysClient.getDeptName(id).getData()); businessMessageDTO.setDeptName(sysClient.getDeptName(id).getData());
businessMessageDTO.setBusinessKey("设备到期"); businessMessageDTO.setBusinessKey("特种设备到期");
businessMessageDTO.setBusinessClassify("system"); businessMessageDTO.setBusinessClassify("system");
businessMessageDTO.setTaskId(specialDeviceEntity.getId()); businessMessageDTO.setTaskId(device.getId());
businessMessageDTO.setSubject("设备到期通知"); businessMessageDTO.setSubject("特种设备到期通知");
businessMessageDTO.setContent("您所管理的特种设备" + specialDeviceEntity.getName() + "已到期,请尽快进行检验。"); businessMessageDTO.setContent("您所管理的特种设备" + device.getName() + "即将过期,请尽快进行检验。");
businessMessageDTO.setUserIds(String.valueOf(specialDeviceEntity.getManagerId())); businessMessageDTO.setUserIds(String.valueOf(device.getManagerId()));
businessMessageDTO.setCreateUser(specialDeviceEntity.getCreateUser()); businessMessageDTO.setCreateUser(device.getCreateUser());
businessMessageDTO.setTenantId(CommonConstant.TENANT_ID); businessMessageDTO.setTenantId(CommonConstant.TENANT_ID);
} }
messageClient.sendAppAndWsMsgByUsers(businessMessageDTO); R<Boolean> res = messageClient.sendAppAndWsMsgByUsers(businessMessageDTO);
if (!res.isSuccess()) {
return ReturnT.FAIL;
} }
}
}
return ReturnT.SUCCESS;
}
} }

18
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICarService.java

@ -30,19 +30,19 @@ public interface ICarService extends IService<CarEntity> {
/** /**
* 根据参保时间查询车辆列表 * 根据参保时间查询车辆列表
* @param today 当天 * @param startTime 开始时间
* @param yesterday 昨天 * @param endTime 结束时间
* @return 车辆列表数据 * @return 车辆列表数据
*/ */
List<CarEntity> getCarListByInsuranceTime(String today, String yesterday); List<CarEntity> getCarListByInsuranceTime(String startTime, String endTime);
/** /**
* 根据维保时间查询车辆列表 * 根据维保时间查询车辆列表
* @param today 当天 * @param startTime 开始时间
* @param yesterday 昨天 * @param endTime 结束时间
* @return 车辆列表数据 * @return 车辆列表数据
*/ */
List<CarEntity> getCarListByMaintenanceTime(String today, String yesterday); List<CarEntity> getCarListByMaintenanceTime(String startTime, String endTime);
/** /**
* 新增车辆 * 新增车辆
@ -75,11 +75,11 @@ public interface ICarService extends IService<CarEntity> {
/** /**
* 根据年检时间查询车辆列表 * 根据年检时间查询车辆列表
* @param today 当天 * @param startTime 开始时间
* @param yesterday 昨天 * @param endTime 结束时间
* @return 车辆列表数据 * @return 车辆列表数据
*/ */
List<CarEntity> getCarListByAnnualInspectionTime(String today, String yesterday); List<CarEntity> getCarListByAnnualInspectionTime(String startTime, String endTime);
/** /**
* 根据车牌查询车辆 * 根据车牌查询车辆

18
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarServiceImpl.java

@ -139,10 +139,10 @@ public class CarServiceImpl extends ServiceImpl<CarMapper, CarEntity> implements
* 根据参保时间查询车辆列表 * 根据参保时间查询车辆列表
*/ */
@Override @Override
public List<CarEntity> getCarListByInsuranceTime(String today, String yesterday) { public List<CarEntity> getCarListByInsuranceTime(String startTime, String endTime) {
QueryWrapper<CarEntity> queryWrapper = new QueryWrapper<>(); QueryWrapper<CarEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().lt(CarEntity::getInsurancePayNextTime, today) queryWrapper.lambda().lt(CarEntity::getInsurancePayNextTime, endTime)
.ge(CarEntity::getInsurancePayNextTime, yesterday); .ge(CarEntity::getInsurancePayNextTime, startTime);
return this.list(queryWrapper); return this.list(queryWrapper);
} }
@ -150,10 +150,10 @@ public class CarServiceImpl extends ServiceImpl<CarMapper, CarEntity> implements
* 根据维保时间查询车辆列表 * 根据维保时间查询车辆列表
*/ */
@Override @Override
public List<CarEntity> getCarListByMaintenanceTime(String today, String yesterday) { public List<CarEntity> getCarListByMaintenanceTime(String startTime, String endTime) {
QueryWrapper<CarEntity> queryWrapper = new QueryWrapper<>(); QueryWrapper<CarEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().lt(CarEntity::getMaintenanceNextTime, today) queryWrapper.lambda().lt(CarEntity::getMaintenanceNextTime, endTime)
.ge(CarEntity::getMaintenanceNextTime, yesterday); .ge(CarEntity::getMaintenanceNextTime, startTime);
return this.list(queryWrapper); return this.list(queryWrapper);
} }
@ -274,10 +274,10 @@ public class CarServiceImpl extends ServiceImpl<CarMapper, CarEntity> implements
* 根据年检时间查询车辆列表 * 根据年检时间查询车辆列表
*/ */
@Override @Override
public List<CarEntity> getCarListByAnnualInspectionTime(String today, String yesterday) { public List<CarEntity> getCarListByAnnualInspectionTime(String startTime, String endTime) {
QueryWrapper<CarEntity> queryWrapper = new QueryWrapper<>(); QueryWrapper<CarEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().lt(CarEntity::getNextAnnualInspectionTime, today) queryWrapper.lambda().lt(CarEntity::getNextAnnualInspectionTime, endTime)
.ge(CarEntity::getNextAnnualInspectionTime, yesterday); .ge(CarEntity::getNextAnnualInspectionTime, startTime);
return this.list(queryWrapper); return this.list(queryWrapper);
} }

Loading…
Cancel
Save