|
|
|
@ -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())); |
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|