Browse Source

add: 车辆管理添加消息推送

zhongwei
liwen 10 months ago
parent
commit
ecd6b36435
  1. 4
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/CarEntity.java
  2. 87
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/jobs/CarJob.java
  3. 1
      hzims-service/safeproduct/src/main/resources/db/1.0.2.sql

4
hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/CarEntity.java

@ -89,6 +89,10 @@ public class CarEntity extends BaseEntity {
private String maintenanceStatus;
@NotNull
@ApiModelProperty("车辆管理人id")
private Long managerId;
@NotNull
@Size(max = 50, message = "车辆管理人长度不能超过50")
@ApiModelProperty("车辆管理人")
private String manager;

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

@ -1,6 +1,9 @@
package com.hnac.hzims.safeproduct.jobs;
import com.alibaba.excel.util.CollectionUtils;
import com.hnac.hzims.common.constant.CommonConstant;
import com.hnac.hzims.common.logs.utils.StringUtils;
import com.hnac.hzims.message.dto.BusinessMessageDTO;
import com.hnac.hzims.message.fegin.IMessageClient;
import com.hnac.hzims.safeproduct.entity.CarEntity;
import com.hnac.hzims.safeproduct.entity.CarMaintenanceEntity;
import com.hnac.hzims.safeproduct.enums.CarInsuranceStatusEnum;
@ -9,10 +12,13 @@ import com.hnac.hzims.safeproduct.service.ICarMaintenanceService;
import com.hnac.hzims.safeproduct.service.ICarService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.system.feign.ISysClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.util.Date;
import java.util.List;
@ -32,6 +38,12 @@ public class CarJob {
@Autowired
ICarMaintenanceService carMaintenanceService;
@Autowired
IMessageClient messageClient;
@Autowired
ISysClient sysClient;
/**
* 车辆台账自动变更
*/
@ -41,28 +53,83 @@ public class CarJob {
// 获取时间范围
Date current = DateUtil.now();
Date before = DateUtil.minusDays(current, 1);
String today = DateUtil.format(current, "yyyy-mm-dd");
String yesterday = DateUtil.format(before, "yyyy-mm-dd");
// 车状态变更
String today = DateUtil.format(current, DateUtil.PATTERN_DATE);
String yesterday = DateUtil.format(before, DateUtil.PATTERN_DATE);
// 车状态变更
List<CarEntity> uninsuredCarList = carService.getCarListByInsuranceTime(today, yesterday);
uninsuredCarList.forEach(car -> car.setInsuranceStatus(CarInsuranceStatusEnum.UNINSURED.getValue()));
boolean insuranceUpdate = carService.updateBatchById(uninsuredCarList);
if (!insuranceUpdate) {
return ReturnT.FAIL;
if (!CollectionUtils.isEmpty(uninsuredCarList)) {
uninsuredCarList.forEach(car -> {
car.setInsuranceStatus(CarInsuranceStatusEnum.UNINSURED.getValue());
sendUninsuredMessage(car);
});
boolean insuranceUpdate = carService.updateBatchById(uninsuredCarList);
if (!insuranceUpdate) {
return ReturnT.FAIL;
}
}
// 维保状态变更
List<CarEntity> unMaintainedCarList = carService.getCarListByMaintenanceTime(today, yesterday);
if (CollectionUtils.isEmpty(unMaintainedCarList)) {
return ReturnT.SUCCESS;
}
unMaintainedCarList.forEach(car -> {
// 查询车辆在两次维保时间内是否有确认过的维保记录
String lastMaintenanceTime = DateUtil.format(car.getMaintenanceLastTime(), "yyyy-mm-dd");
String nextMaintenanceTime = DateUtil.format(car.getMaintenanceNextTime(), "yyyy-mm-dd");
String lastMaintenanceTime = DateUtil.format(car.getMaintenanceLastTime(), DateUtil.PATTERN_DATE);
String nextMaintenanceTime = DateUtil.format(car.getMaintenanceNextTime(), DateUtil.PATTERN_DATE);
List<CarMaintenanceEntity> carMaintenanceList = carMaintenanceService.getCarMaintenanceByCarIdAndTime(car.getId(),
lastMaintenanceTime, nextMaintenanceTime);
// 若无维保记录,说明在规定范围内未进行有效维保
if (CollectionUtils.isEmpty(carMaintenanceList)) {
car.setMaintenanceStatus(CarMaintenanceStatusEnum.UNMAINTAINED.getValue());
sendUnMaintainedMessage(car);
}
});
return carService.updateBatchById(unMaintainedCarList) ? ReturnT.SUCCESS : ReturnT.FAIL;
}
/**
* 推送车保过期消息
* @param carEntity 车辆实体类
*/
private void sendUninsuredMessage(CarEntity carEntity) {
BusinessMessageDTO businessMessageDTO = new BusinessMessageDTO();
String deptId = AuthUtil.getDeptId();
if (StringUtils.isNotEmpty(deptId)) {
Long id = Long.valueOf(deptId);
businessMessageDTO.setDeptId(id);
businessMessageDTO.setDeptName(sysClient.getDeptName(id).getData());
businessMessageDTO.setBusinessKey("车保到期");
businessMessageDTO.setBusinessClassify("system");
businessMessageDTO.setTaskId(carEntity.getId());
businessMessageDTO.setSubject("车保到期通知");
businessMessageDTO.setContent("您所管理的车辆" + carEntity.getPlateNumber() + "车保已过期,请及时续保。");
businessMessageDTO.setUserIds(String.valueOf(carEntity.getManagerId()));
businessMessageDTO.setCreateUser(carEntity.getCreateUser());
businessMessageDTO.setTenantId(CommonConstant.TENANT_ID);
}
messageClient.sendAppAndWsMsgByUsers(businessMessageDTO);
}
/**
* 推送维保过期消息
* @param carEntity 车辆实体类
*/
private void sendUnMaintainedMessage(CarEntity carEntity) {
BusinessMessageDTO businessMessageDTO = new BusinessMessageDTO();
String deptId = AuthUtil.getDeptId();
if (StringUtils.isNotEmpty(deptId)) {
Long id = Long.valueOf(deptId);
businessMessageDTO.setDeptId(id);
businessMessageDTO.setDeptName(sysClient.getDeptName(id).getData());
businessMessageDTO.setBusinessKey("维保到期");
businessMessageDTO.setBusinessClassify("system");
businessMessageDTO.setTaskId(carEntity.getId());
businessMessageDTO.setSubject("维保到期通知");
businessMessageDTO.setContent("您所管理的车辆" + carEntity.getPlateNumber() + "维保已过期,请及时进行维保。");
businessMessageDTO.setUserIds(String.valueOf(carEntity.getManagerId()));
businessMessageDTO.setCreateUser(carEntity.getCreateUser());
businessMessageDTO.setTenantId(CommonConstant.TENANT_ID);
}
messageClient.sendAppAndWsMsgByUsers(businessMessageDTO);
}
}

1
hzims-service/safeproduct/src/main/resources/db/1.0.2.sql

@ -240,6 +240,7 @@ CREATE TABLE `hzims_car` (
`maintenance_next_time` date DEFAULT NULL COMMENT '下期保养时间',
`maintenance_mileage` decimal(10, 2) DEFAULT NULL COMMENT '保养里程',
`maintenance_status` varchar(50) DEFAULT NULL COMMENT '保养状态',
`manager_id` bigint(20) NOT NULL COMMENT '车辆管理人id',
`manager` varchar(50) NOT NULL COMMENT '车辆管理人',
`img_path` varchar(1000) NOT NULL DEFAULT '' COMMENT '车辆图片',
`file_path` varchar(1000) NOT NULL DEFAULT '' COMMENT '车辆附件',

Loading…
Cancel
Save