Browse Source

update: 特种设备添加消息推送

zhongwei
liwen 1 year ago
parent
commit
8ff603a6de
  1. 53
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/jobs/DeviceJob.java

53
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/jobs/DeviceJob.java

@ -1,11 +1,20 @@
package com.hnac.hzims.safeproduct.jobs;
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.DeviceEntity;
import com.hnac.hzims.safeproduct.enums.DeviceStatusEnum;
import com.hnac.hzims.safeproduct.service.IDeviceService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.system.feign.ISysClient;
import org.springblade.system.user.entity.User;
import org.springblade.system.user.feign.IUserClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
@ -19,12 +28,22 @@ import java.util.List;
* @author liwen
* @date 2024-01-16
*/
@Slf4j
@Component
public class DeviceJob {
@Autowired
IDeviceService deviceService;
@Autowired
IUserClient userClient;
@Autowired
ISysClient sysClient;
@Autowired
IMessageClient messageClient;
@XxlJob("autoChangeDeviceStatus")
public ReturnT<String> autoChangeDeviceStatus(String param) {
// 获取时间范围
@ -37,9 +56,41 @@ public class DeviceJob {
if (CollectionUtils.isEmpty(list)) {
return ReturnT.SUCCESS;
}
list.forEach(e -> e.setDeviceStatus(DeviceStatusEnum.EXPIRED.getValue()));
list.forEach(device -> {
device.setDeviceStatus(DeviceStatusEnum.EXPIRED.getValue());
sendExpiredMessage(device);
});
// 更新状态
boolean update = deviceService.updateBatchById(list);
return update ? ReturnT.SUCCESS : ReturnT.FAIL;
}
/**
* 推送设备过期消息
* @param deviceEntity 特种设备实体类
*/
private void sendExpiredMessage(DeviceEntity deviceEntity) {
if (deviceEntity.getManagerId() == null) {
log.error("系统无该用户信息,推送设备过期消息失败");
return;
}
// 查询用户
R<User> userRes = userClient.userInfoById(deviceEntity.getManagerId());
User user = userRes.getData();
BusinessMessageDTO businessMessageDTO = new BusinessMessageDTO();
if (StringUtils.isNotEmpty(user.getDeptId())) {
Long id = Long.valueOf(user.getDeptId());
businessMessageDTO.setDeptId(id);
businessMessageDTO.setDeptName(sysClient.getDeptName(id).getData());
businessMessageDTO.setBusinessKey("设备到期");
businessMessageDTO.setBusinessClassify("system");
businessMessageDTO.setTaskId(deviceEntity.getId());
businessMessageDTO.setSubject("设备到期通知");
businessMessageDTO.setContent("您所管理的特种设备" + deviceEntity.getName() + "已到期,请尽快进行检验。");
businessMessageDTO.setUserIds(String.valueOf(deviceEntity.getManagerId()));
businessMessageDTO.setCreateUser(deviceEntity.getCreateUser());
businessMessageDTO.setTenantId(CommonConstant.TENANT_ID);
}
messageClient.sendAppAndWsMsgByUsers(businessMessageDTO);
}
}

Loading…
Cancel
Save