|
|
@@ -1,10 +1,16 @@
|
|
|
package com.zd.chemical.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.date.LocalDateTimeUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.zd.algorithm.api.alarm.entity.AlarmEntrty;
|
|
|
import com.zd.algorithm.api.alarm.entity.Routes;
|
|
|
+import com.zd.algorithm.api.alarm.entity.SendTypes;
|
|
|
import com.zd.algorithm.api.alarm.feign.RemoteAlarmService;
|
|
|
+import com.zd.algorithm.api.camera.feign.RemoteCameraService;
|
|
|
import com.zd.algorithm.api.forward.feign.RemoteForwardService;
|
|
|
import com.zd.algorithm.api.rfid.feign.RemoteRfidService;
|
|
|
import com.zd.chemical.controller.HxpAIOController;
|
|
|
@@ -12,10 +18,7 @@ import com.zd.chemical.domain.*;
|
|
|
import com.zd.chemical.domain.vo.*;
|
|
|
import com.zd.chemical.mapper.*;
|
|
|
import com.zd.chemical.properties.AlarmProperties;
|
|
|
-import com.zd.chemical.service.IHxpChemicalJoinCabinetService;
|
|
|
-import com.zd.chemical.service.IHxpClassifyConfigService;
|
|
|
-import com.zd.chemical.service.IHxpStockService;
|
|
|
-import com.zd.chemical.service.IHxpUserecordService;
|
|
|
+import com.zd.chemical.service.*;
|
|
|
import com.zd.chemical.util.ChemicalUtils;
|
|
|
import com.zd.chemical.util.SmsSydUtil;
|
|
|
import com.zd.common.core.annotation.DataScope;
|
|
|
@@ -24,14 +27,20 @@ import com.zd.common.core.utils.DateUtils;
|
|
|
import com.zd.common.core.utils.DictUtils;
|
|
|
import com.zd.common.core.utils.SaveUtil;
|
|
|
import com.zd.common.core.utils.SecurityUtils;
|
|
|
+import com.zd.laboratory.api.dto.CheckSubjectDto;
|
|
|
+import com.zd.laboratory.api.dto.WarningConfigDto;
|
|
|
+import com.zd.laboratory.api.dto.WarningNoticeLogDto;
|
|
|
+import com.zd.laboratory.api.entity.LabMessageContent;
|
|
|
+import com.zd.laboratory.api.feign.RemoteLabHardwareService;
|
|
|
import com.zd.laboratory.api.feign.RemoteLaboratoryService;
|
|
|
import com.zd.laboratory.api.feign.RemoteMessageContentService;
|
|
|
+import com.zd.model.constant.HttpStatus;
|
|
|
import com.zd.model.domain.AjaxResult;
|
|
|
import com.zd.model.domain.R;
|
|
|
+import com.zd.model.domain.ResultData;
|
|
|
import com.zd.model.domain.per.PerPrefix;
|
|
|
import com.zd.model.entity.HardwareRfidDto;
|
|
|
import com.zd.model.entity.InventoryTag;
|
|
|
-import com.zd.model.entity.SysFile;
|
|
|
import com.zd.system.api.entity.SysDictData;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
@@ -39,16 +48,20 @@ import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.concurrent.Executors;
|
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
/**
|
|
|
* 库存管理Service业务层处理
|
|
|
@@ -60,6 +73,7 @@ import java.util.concurrent.TimeUnit;
|
|
|
public class HxpStockServiceImpl implements IHxpStockService {
|
|
|
private static Logger logger = LoggerFactory.getLogger(HxpStockServiceImpl.class);
|
|
|
|
|
|
+// private static final ScheduledExecutorService scheduledExecutorService = SpringUtils.getBean("scheduledExecutorService");
|
|
|
private static Map<String, Date> cacheMap = new ConcurrentHashMap<>();
|
|
|
|
|
|
private static int interval = 60 * 3;
|
|
|
@@ -113,6 +127,15 @@ public class HxpStockServiceImpl implements IHxpStockService {
|
|
|
private AlarmProperties alarmProperties;
|
|
|
@Resource
|
|
|
private RemoteForwardService remoteForwardService;
|
|
|
+ @Resource
|
|
|
+ private RemoteLabHardwareService remoteLabHardwareService;
|
|
|
+ @Resource
|
|
|
+ private RemoteCameraService remoteCameraService;
|
|
|
+ @Resource
|
|
|
+ private ScheduledExecutorService scheduledExecutorService;
|
|
|
+ @Autowired
|
|
|
+ private IHxpChemicalService hxpChemicalService;
|
|
|
+
|
|
|
/**
|
|
|
* 查询库存管理
|
|
|
*
|
|
|
@@ -344,6 +367,7 @@ public class HxpStockServiceImpl implements IHxpStockService {
|
|
|
logger.info("RFID 实时检测 (标签未绑定化学品): " + rfidCode);
|
|
|
return false;
|
|
|
}
|
|
|
+ HxpChemicalJoinCabinet hxpChemicalJoinCabinet = hxpCabinetJoinCabinetService.selectHxpChemicalJoinCabinetById(hxpStock.getJoinId());
|
|
|
|
|
|
// 查询该库存数据是否处于领用状态
|
|
|
HxpUserecord hxpUserecord = hxpUserecordMapper.selectByStockId(hxpStock.getId());
|
|
|
@@ -352,24 +376,95 @@ public class HxpStockServiceImpl implements IHxpStockService {
|
|
|
return false;
|
|
|
}else {
|
|
|
logger.info("RFID 检测到违规触发报警: " + JSONUtil.toJsonStr(hxpStock));
|
|
|
- String streamUrl = alarmProperties.getStreamUrl();
|
|
|
- R<SysFile> fileR = null;
|
|
|
- if (org.springframework.util.StringUtils.hasLength(streamUrl)){
|
|
|
- fileR= remoteForwardService.photograph(alarmProperties.getStreamUrl());
|
|
|
- }
|
|
|
- if (fileR!=null){
|
|
|
- logger.info("文件上传状态:{},接口返回消息:{},文件上传路径:{}",fileR.getCode(),fileR.getMsg(),fileR.getData());
|
|
|
- }
|
|
|
//触发RFID警报
|
|
|
HardwareRfidDto hardwareRfidDto = tag.getHardwareRfidDto();
|
|
|
boolean isAlarm = false;
|
|
|
- if (hardwareRfidDto!=null){
|
|
|
- R<Boolean> alarm = remoteRfidService.alarm(hardwareRfidDto);//RFID设备报警
|
|
|
- logger.info("==================>{},{}",alarm.getCode(),alarm.getMsg());
|
|
|
- //isAlarm = true;
|
|
|
- }else {
|
|
|
- logger.info("==================> rfid 参数有误!"+ tag.toString());
|
|
|
- }
|
|
|
+ // 查询配置
|
|
|
+ ResultData<WarningConfigDto> byType = remoteLaboratoryService.getByType(2);
|
|
|
+ if (HttpStatus.SUCCESS != byType.getCode()) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ //违规带离(1系统通知 2短信通知 3声光报警)
|
|
|
+ WarningConfigDto warningConfigDto = byType.getData();
|
|
|
+ String illegalRemoval = warningConfigDto.getIllegalRemoval();
|
|
|
+
|
|
|
+ WarningNoticeLogDto warningNoticeLogDto = new WarningNoticeLogDto();
|
|
|
+ warningNoticeLogDto.setKeyId(hxpStock.getId());
|
|
|
+ warningNoticeLogDto.setName(hxpStock.getChemicalName());
|
|
|
+ warningNoticeLogDto.setWarningType(2);
|
|
|
+ warningNoticeLogDto.setWarningSubType(1);
|
|
|
+ warningNoticeLogDto.setWarningContent("化学品违规带离");
|
|
|
+ warningNoticeLogDto.setWarningTime(LocalDateTime.now());
|
|
|
+ warningNoticeLogDto.setWarningWay(illegalRemoval);
|
|
|
+ warningNoticeLogDto.setMargin(hxpStock.getOutUsages());
|
|
|
+ warningNoticeLogDto.setDeposit(hxpStock.getCabinetName());
|
|
|
+ warningNoticeLogDto.setSpecification(hxpChemicalJoinCabinet.getChemicalAmount() + hxpChemicalJoinCabinet.getChemicalAmountUnit());
|
|
|
+
|
|
|
+ //查询到实验室负责人id 安全责任人id
|
|
|
+ ResultData<List<CheckSubjectDto>> subjectInfoList = remoteLaboratoryService.findSubjectInfoList(String.valueOf(hxpStock.getSubId()));
|
|
|
+ StringBuffer userIdStr = new StringBuffer();
|
|
|
+ StringBuffer phones = new StringBuffer();
|
|
|
+ if (HttpStatus.SUCCESS == subjectInfoList.getCode()) {
|
|
|
+ List<CheckSubjectDto> data = subjectInfoList.getData();
|
|
|
+ CheckSubjectDto i = data.get(0);
|
|
|
+ warningNoticeLogDto.setSubId(i.getSubId());
|
|
|
+ warningNoticeLogDto.setSubName(i.getSubjectName());
|
|
|
+ warningNoticeLogDto.setBuildName(i.getBuildName());
|
|
|
+ warningNoticeLogDto.setFloorName(i.getFloorName());
|
|
|
+ warningNoticeLogDto.setRoomNum(i.getRoomNumber());
|
|
|
+ userIdStr.append(i.getSafeUserId()).append(",").append(i.getAdminId());
|
|
|
+ phones.append(i.getAdminPhone()).append(",").append(i.getSafeUserPhone());
|
|
|
+ }
|
|
|
+ ResultData resultData = remoteLaboratoryService.addWarningNoticeLog(warningNoticeLogDto);
|
|
|
+ if (HttpStatus.SUCCESS != resultData.getCode()) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ Long logId = (Long)resultData.getData();
|
|
|
+ if(illegalRemoval != null){
|
|
|
+ String text = "【实验室安全系统】实验室名称-实验人员违规携带化学品名称离开房间,发生时间:"+LocalDateTimeUtil.format(LocalDateTime.now(),"yyyy-MM-dd HH:mm:ss")+",请尽快确认。点击查看:http://";
|
|
|
+ if (illegalRemoval.contains("1")) {
|
|
|
+ //系统通知
|
|
|
+ LabMessageContent labMessageContent = new LabMessageContent();
|
|
|
+ labMessageContent.setSendMode(2);
|
|
|
+ labMessageContent.setSendRange(3);
|
|
|
+ labMessageContent.setMessClass(1);
|
|
|
+ labMessageContent.setMessType(13);
|
|
|
+ labMessageContent.setSubIds(String.valueOf(hxpStock.getSubId()));
|
|
|
+ labMessageContent.setUserIds(userIdStr.toString());
|
|
|
+ labMessageContent.setContent(text);
|
|
|
+ remoteMessageContentService.sendMessage(labMessageContent);
|
|
|
+
|
|
|
+ }
|
|
|
+ if (illegalRemoval.contains("2")) {
|
|
|
+ //短信通知
|
|
|
+ String[] strings = Stream.of(phones.toString().split(","))
|
|
|
+ .filter(a -> StrUtil.isNotBlank(a))
|
|
|
+ .collect(Collectors.joining(","))
|
|
|
+ .split(",");
|
|
|
+
|
|
|
+ if (strings != null) {
|
|
|
+ AlarmEntrty alarmEntrty = new AlarmEntrty(Routes.NoticePush, strings, SendTypes.SMS.toString(),text);
|
|
|
+ remoteAlarmService.send(alarmEntrty);
|
|
|
+ logger.info("气瓶发送短信打电话消息推送完成!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (hardwareRfidDto!=null && illegalRemoval.contains("3")) {
|
|
|
+ //声光报警
|
|
|
+ R<Boolean> alarm = remoteRfidService.alarm(hardwareRfidDto);
|
|
|
+ logger.info("==================>{},{}",alarm.getCode(),alarm.getMsg());
|
|
|
+ }
|
|
|
+ ResultData result = remoteLabHardwareService.findCameraByType(hxpStock.getSubId(), 4, 2);
|
|
|
+ if (HttpStatus.SUCCESS == result.getCode()) {
|
|
|
+ String ip = String.valueOf(result.getData());
|
|
|
+ startVideo(ip);
|
|
|
+ scheduledExecutorService.schedule(new TimerTask() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ stopVideo(ip,logId);
|
|
|
+ }
|
|
|
+ }, 30, TimeUnit.SECONDS);
|
|
|
+ }
|
|
|
+ }
|
|
|
// 如果非领用状态,做报警台账
|
|
|
// 0.检测实验室声光报警器是否使用- 使用则直接调用触发- 否则跳过
|
|
|
Map<String,Object> subInfo = hxpUserecordMapper.selectSubInfoById(hxpStock.getSubId());
|
|
|
@@ -497,6 +592,35 @@ public class HxpStockServiceImpl implements IHxpStockService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void startVideo(String cameraIpAddress) {
|
|
|
+ if(org.apache.commons.lang3.StringUtils.isNotBlank(cameraIpAddress)){
|
|
|
+ R r = remoteCameraService.startRecord(cameraIpAddress);
|
|
|
+ logger.info("报警模块-开始录制视频返回结果打印={}", JSON.toJSONString(r));
|
|
|
+ if (r.getCode() == HttpStatus.SUCCESS) {
|
|
|
+ logger.info("报警模块-开始录制视频成功!");
|
|
|
+ } else {
|
|
|
+ logger.info("报警模块-开始录制视频失败!");
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ logger.info("报警模块-摄像头ip为空!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private void stopVideo(String cameraIpAddress,Long logId) {
|
|
|
+ if(org.apache.commons.lang3.StringUtils.isNotBlank(cameraIpAddress)){
|
|
|
+ R r = remoteCameraService.stopRecord(cameraIpAddress);
|
|
|
+ logger.info("报警模块-录制视频结束返回结果打印={}", JSON.toJSONString(r));
|
|
|
+ if (r.getCode() == HttpStatus.SUCCESS) {
|
|
|
+ String recordVideo = String.valueOf(r.getData());
|
|
|
+ WarningNoticeLogDto warningNoticeLogDto = new WarningNoticeLogDto();
|
|
|
+ warningNoticeLogDto.setId(logId);
|
|
|
+ warningNoticeLogDto.setRecordVideo(recordVideo);
|
|
|
+ remoteLaboratoryService.updateWarningNoticeLog(warningNoticeLogDto);
|
|
|
+ } else {
|
|
|
+ logger.info("报警模块-结束录制视频失败!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private Long sendPhoneAlarm(Long stockId, Long subId, String subName, String chemicalName, String phones) {
|
|
|
|
|
|
try {
|
|
|
@@ -763,4 +887,230 @@ public class HxpStockServiceImpl implements IHxpStockService {
|
|
|
hxpCabinetlockLogMapper.updateHxpCabinetlockLog(hxpCabinetlockLog);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 化学品已过期 化学品即将过期
|
|
|
+ *
|
|
|
+ * @Param []
|
|
|
+ * @Return void
|
|
|
+ **/
|
|
|
+
|
|
|
+ @Scheduled(cron = "0 0 0 * * ?")
|
|
|
+// @Scheduled(cron = "0 0/1 * * * ? ")
|
|
|
+ public void hxpExpired() {
|
|
|
+ //之前代码
|
|
|
+ //expireCheck();
|
|
|
+
|
|
|
+ // 查询配置
|
|
|
+ ResultData<WarningConfigDto> byType = remoteLaboratoryService.getByType(2);
|
|
|
+ if (HttpStatus.SUCCESS != byType.getCode()) {
|
|
|
+ logger.info("未查询到相关配置!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //违规带离(1系统通知 2短信通知 3声光报警)
|
|
|
+ WarningConfigDto warningConfigDto = byType.getData();
|
|
|
+ //化学品已过期 化学品即将过期
|
|
|
+ List<HxpStock> hxpStocks = hxpStockMapper.selectHxpStockList(new HxpStock());
|
|
|
+ Optional.ofNullable(hxpStocks).orElseGet(Collections::emptyList).forEach(hxpStock -> {
|
|
|
+ //过期时间
|
|
|
+ Date expirationTime = hxpStock.getExpirationTime();
|
|
|
+ //即将过期提醒天数
|
|
|
+ Integer unexpiredWarnDays = warningConfigDto.getUnexpiredWarnDays();
|
|
|
+ DateTime startDateTime = DateUtil.offsetDay(DateTime.now(), unexpiredWarnDays);
|
|
|
+ DateTime endDateTime = DateUtil.offsetDay(DateTime.now(), unexpiredWarnDays + 1);
|
|
|
+
|
|
|
+ ResultData resultData = remoteLaboratoryService.getRemindData(hxpStock.getId());
|
|
|
+ if (HttpStatus.SUCCESS != resultData.getCode()) {
|
|
|
+ logger.error("获取提醒日志数据失败!");
|
|
|
+ }
|
|
|
+ List<WarningNoticeLogDto> warningNoticeLogDtos = JSON.parseArray(JSON.toJSONString(resultData.getData()), WarningNoticeLogDto.class);
|
|
|
+ //过期提醒数据
|
|
|
+ List<WarningNoticeLogDto> logDtoList = Optional.ofNullable(warningNoticeLogDtos).orElseGet(Collections::emptyList).stream().filter(i -> i.getWarningType() == 2 && i.getWarningSubType() == 4).collect(Collectors.toList());
|
|
|
+
|
|
|
+ //过期时间在提醒天数内 并且在一天之内
|
|
|
+ WarningNoticeLogDto warningNoticeLogDto = new WarningNoticeLogDto();
|
|
|
+ warningNoticeLogDto.setKeyId(hxpStock.getId());
|
|
|
+ warningNoticeLogDto.setName(hxpStock.getChemicalName());
|
|
|
+ warningNoticeLogDto.setWarningType(2);
|
|
|
+ warningNoticeLogDto.setWarningTime(LocalDateTime.now());
|
|
|
+ //TODO 余量
|
|
|
+ warningNoticeLogDto.setMargin(BigDecimal.ZERO);
|
|
|
+ warningNoticeLogDto.setSpecification(String.valueOf(hxpStock.getChemicalAmount()));
|
|
|
+
|
|
|
+ //查询到实验室负责人id 安全责任人id
|
|
|
+ ResultData<List<CheckSubjectDto>> subjectInfoList = remoteLaboratoryService.findSubjectInfoList(String.valueOf(hxpStock.getSubId()));
|
|
|
+ StringBuffer userIdStr = new StringBuffer();
|
|
|
+ StringBuffer phones = new StringBuffer();
|
|
|
+ if (HttpStatus.SUCCESS == subjectInfoList.getCode()) {
|
|
|
+ List<CheckSubjectDto> data = subjectInfoList.getData();
|
|
|
+ CheckSubjectDto i = data.get(0);
|
|
|
+ warningNoticeLogDto.setSubId(i.getSubId());
|
|
|
+ warningNoticeLogDto.setSubName(i.getSubjectName());
|
|
|
+ warningNoticeLogDto.setBuildName(i.getBuildName());
|
|
|
+ warningNoticeLogDto.setFloorName(i.getFloorName());
|
|
|
+ warningNoticeLogDto.setFloorName(i.getRoomNumber());
|
|
|
+ userIdStr.append(i.getSafeUserId()).append(",").append(i.getAdminId());
|
|
|
+ phones.append(i.getAdminPhone()).append(",").append(i.getSafeUserPhone());
|
|
|
+ }
|
|
|
+ //即将过期
|
|
|
+ if (startDateTime.getTime() < expirationTime.getTime() && endDateTime.getTime() > expirationTime.getTime()) {
|
|
|
+ String text = "【实验室安全系统】实验室名称-化学品名称即将过期,发生时间:" + LocalDateTime.now() + ",请尽快确认。点击查看:http://";
|
|
|
+ warningNoticeLogDto.setWarningContent("化学品即将过期");
|
|
|
+ warningNoticeLogDto.setWarningSubType(3);
|
|
|
+ String unexpired = warningConfigDto.getUnexpired();
|
|
|
+ warningNoticeLogDto.setWarningWay(unexpired);
|
|
|
+ if (unexpired.contains("1")) {
|
|
|
+ //系统通知
|
|
|
+ LabMessageContent labMessageContent = new LabMessageContent();
|
|
|
+ labMessageContent.setSendMode(2);
|
|
|
+ labMessageContent.setSendRange(3);
|
|
|
+ labMessageContent.setMessClass(1);
|
|
|
+ labMessageContent.setMessType(13);
|
|
|
+ labMessageContent.setSubIds(String.valueOf(hxpStock.getSubId()));
|
|
|
+ labMessageContent.setUserIds(userIdStr.toString());
|
|
|
+ labMessageContent.setContent(text);
|
|
|
+ remoteMessageContentService.sendMessage(labMessageContent);
|
|
|
+
|
|
|
+ }
|
|
|
+ if (unexpired.contains("2")) {
|
|
|
+ //短信通知
|
|
|
+ String[] strings = Stream.of(phones.toString().split(",")).filter(a -> StrUtil.isNotBlank(a)).collect(Collectors.joining(",")).split(",");
|
|
|
+ if (strings != null) {
|
|
|
+ AlarmEntrty alarmEntrty = new AlarmEntrty(Routes.NoticePush, strings, SendTypes.SMS.toString(), text);
|
|
|
+ remoteAlarmService.send(alarmEntrty);
|
|
|
+ logger.info("化学品发送短信打电话消息推送完成!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ResultData result = remoteLaboratoryService.addWarningNoticeLog(warningNoticeLogDto);
|
|
|
+ if (HttpStatus.SUCCESS == result.getCode()) {
|
|
|
+ logger.info("即将过期保存日志成功!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //已过期
|
|
|
+ if (DateUtils.getNowDate().getTime() >= expirationTime.getTime() && logDtoList.size() <= warningConfigDto.getExpiredWarnCount()) {
|
|
|
+ String text2 = "【实验室安全系统】实验室名称-化学品名称已过期,请尽快确认。点击查看:http://";
|
|
|
+ warningNoticeLogDto.setWarningContent("化学品已过期");
|
|
|
+ warningNoticeLogDto.setWarningSubType(4);
|
|
|
+ String expired = warningConfigDto.getExpired();
|
|
|
+ warningNoticeLogDto.setWarningWay(expired);
|
|
|
+ if (expired.contains("1")) {
|
|
|
+ //系统通知
|
|
|
+ LabMessageContent labMessageContent = new LabMessageContent();
|
|
|
+ labMessageContent.setSendMode(2);
|
|
|
+ labMessageContent.setSendRange(3);
|
|
|
+ labMessageContent.setMessClass(1);
|
|
|
+ labMessageContent.setMessType(13);
|
|
|
+ labMessageContent.setSubIds(String.valueOf(hxpStock.getSubId()));
|
|
|
+ labMessageContent.setUserIds(userIdStr.toString());
|
|
|
+ labMessageContent.setContent(text2);
|
|
|
+ remoteMessageContentService.sendMessage(labMessageContent);
|
|
|
+ }
|
|
|
+ if (expired.contains("2")) {
|
|
|
+ //短信通知
|
|
|
+ String[] strings = Stream.of(phones.toString().split(",")).filter(a -> StrUtil.isNotBlank(a)).collect(Collectors.joining(",")).split(",");
|
|
|
+ if (strings != null) {
|
|
|
+ AlarmEntrty alarmEntrty = new AlarmEntrty(Routes.NoticePush, strings, SendTypes.SMS.toString(), text2);
|
|
|
+ remoteAlarmService.send(alarmEntrty);
|
|
|
+ logger.info("化学品发送短信打电话消息推送完成!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ResultData result = remoteLaboratoryService.addWarningNoticeLog(warningNoticeLogDto);
|
|
|
+ if (HttpStatus.SUCCESS == result.getCode()) {
|
|
|
+ logger.info("已过期保存日志成功!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 化学品超时未归还
|
|
|
+ * @Param []
|
|
|
+ * @Return void
|
|
|
+ **/
|
|
|
+// @Scheduled(cron = "0 0/1 * * * ? ")
|
|
|
+ @Scheduled(cron = "0 0 0 * * ?")
|
|
|
+ public void hxpTimeOut() {
|
|
|
+ // 查询配置
|
|
|
+ ResultData<WarningConfigDto> byType = remoteLaboratoryService.getByType(2);
|
|
|
+ if (HttpStatus.SUCCESS != byType.getCode()) {
|
|
|
+ logger.info("未查询到相关配置!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ WarningConfigDto warningConfigDto = byType.getData();
|
|
|
+ //化学品超时未归还
|
|
|
+ List hxpIds = new ArrayList<>();
|
|
|
+ List<HxpUserecord> hxpUserecordList = hxpUserecordMapper.selectByOvertime();
|
|
|
+
|
|
|
+ Optional.ofNullable(hxpUserecordList).orElseGet(Collections::emptyList).forEach(hxpUserecord -> {
|
|
|
+ HxpStock hxpStock = hxpStockMapper.selectHxpStockById(hxpUserecord.getStockId());
|
|
|
+ AioChemicalVo aioChemicalVo = new AioChemicalVo();
|
|
|
+ aioChemicalVo.setCabinetId(hxpStock.getCabinetId());
|
|
|
+ HxpChemicalJoinCabinet hxpChemicalJoinCabinet = hxpChemicalJoinCabinetMapper.selectHxpChemicalJoinCabinetById(hxpStock.getJoinId());
|
|
|
+ HxpChemical hxpChemical = hxpChemicalService.selectHxpChemicalById(hxpChemicalJoinCabinet.getId());
|
|
|
+ Integer collectHour = hxpChemical.getCollectHour();
|
|
|
+ Integer collectMinute = hxpChemical.getCollectMinute();
|
|
|
+ Integer minute = collectHour * 60 + collectMinute;
|
|
|
+ DateTime dateTime = DateUtil.offsetMinute(hxpUserecord.getCollectTime(), minute);
|
|
|
+
|
|
|
+ //过期时间在提醒天数内 并且在一天之内
|
|
|
+ WarningNoticeLogDto warningNoticeLogDto = new WarningNoticeLogDto();
|
|
|
+ warningNoticeLogDto.setKeyId(hxpStock.getId());
|
|
|
+ warningNoticeLogDto.setName(hxpStock.getChemicalShapeName());
|
|
|
+ warningNoticeLogDto.setWarningType(2);
|
|
|
+ warningNoticeLogDto.setWarningTime(LocalDateTime.now());
|
|
|
+ //TODO 余量
|
|
|
+ warningNoticeLogDto.setMargin(BigDecimal.ZERO);
|
|
|
+ warningNoticeLogDto.setSpecification(String.valueOf(hxpStock.getChemicalAmount()));
|
|
|
+
|
|
|
+ //查询到实验室负责人id 安全责任人id
|
|
|
+ ResultData<List<CheckSubjectDto>> subjectInfoList = remoteLaboratoryService.findSubjectInfoList(String.valueOf(hxpStock.getSubId()));
|
|
|
+ StringBuffer userIdStr = new StringBuffer();
|
|
|
+ StringBuffer phones = new StringBuffer();
|
|
|
+ if (HttpStatus.SUCCESS == subjectInfoList.getCode()) {
|
|
|
+ List<CheckSubjectDto> data = subjectInfoList.getData();
|
|
|
+ CheckSubjectDto i = data.get(0);
|
|
|
+ warningNoticeLogDto.setSubId(i.getSubId());
|
|
|
+ warningNoticeLogDto.setSubName(i.getSubjectName());
|
|
|
+ warningNoticeLogDto.setBuildName(i.getBuildName());
|
|
|
+ warningNoticeLogDto.setFloorName(i.getFloorName());
|
|
|
+ warningNoticeLogDto.setFloorName(i.getRoomNumber());
|
|
|
+ userIdStr.append(i.getSafeUserId()).append(",").append(i.getAdminId());
|
|
|
+ phones.append(i.getAdminPhone()).append(",").append(i.getSafeUserPhone());
|
|
|
+ }
|
|
|
+ if(DateUtils.getNowDate().getTime() > dateTime.getTime()){
|
|
|
+ hxpIds.add(hxpUserecord.getId());
|
|
|
+ //过了最大领用时间
|
|
|
+ String text = "【实验室安全系统】实验室名称-人名领用化学品名称超时未归还,领用时间:"+LocalDateTime.now().toString() +",请尽快确认。点击查看:http://";
|
|
|
+ warningNoticeLogDto.setWarningContent("化学品超时未归还");
|
|
|
+ warningNoticeLogDto.setWarningSubType(2);
|
|
|
+ String timeout = warningConfigDto.getTimeout();
|
|
|
+ warningNoticeLogDto.setWarningWay(timeout);
|
|
|
+ if (timeout.contains("1")) {
|
|
|
+ //系统通知
|
|
|
+ LabMessageContent labMessageContent = new LabMessageContent();
|
|
|
+ labMessageContent.setSendMode(2);
|
|
|
+ labMessageContent.setSendRange(3);
|
|
|
+ labMessageContent.setMessClass(1);
|
|
|
+ labMessageContent.setMessType(13);
|
|
|
+ labMessageContent.setSubIds(String.valueOf(hxpStock.getSubId()));
|
|
|
+ labMessageContent.setUserIds(userIdStr.toString());
|
|
|
+ labMessageContent.setContent(text);
|
|
|
+ remoteMessageContentService.sendMessage(labMessageContent);
|
|
|
+ }
|
|
|
+ if (timeout.contains("2")) {
|
|
|
+ //短信通知
|
|
|
+ String[] strings = Stream.of(phones.toString().split(",")).filter(a -> StrUtil.isNotBlank(a)).collect(Collectors.joining(",")).split(",");
|
|
|
+ if (strings != null) {
|
|
|
+ AlarmEntrty alarmEntrty = new AlarmEntrty(Routes.NoticePush, strings, SendTypes.SMS.toString(), text);
|
|
|
+ remoteAlarmService.send(alarmEntrty);
|
|
|
+ logger.info("化学品发送短信打电话消息推送完成!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ResultData result = remoteLaboratoryService.addWarningNoticeLog(warningNoticeLogDto);
|
|
|
+ if (HttpStatus.SUCCESS == result.getCode()) {
|
|
|
+ logger.info("化学品超时未归还保存日志成功!");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ hxpUserecordMapper.updateUserecordOvertimeByIds(hxpIds);
|
|
|
+ }
|
|
|
}
|