package com.zy.asrs.wcs.core.task;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONObject;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.zy.asrs.common.utils.HttpHandler;
|
import com.zy.asrs.wcs.core.model.enums.DeviceCtgType;
|
import com.zy.asrs.wcs.rcs.cache.SlaveConnection;
|
import com.zy.asrs.wcs.rcs.entity.Device;
|
import com.zy.asrs.wcs.rcs.model.enums.SlaveType;
|
import com.zy.asrs.wcs.rcs.model.protocol.ShuttleProtocol;
|
import com.zy.asrs.wcs.rcs.service.DeviceService;
|
import com.zy.asrs.wcs.rcs.thread.ShuttleThread;
|
import com.zy.asrs.wcs.system.entity.Dict;
|
import com.zy.asrs.wcs.system.service.DictService;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.stereotype.Component;
|
|
import java.util.HashMap;
|
import java.util.List;
|
|
/**
|
* 小车电量预警检测 => 强制预警
|
*/
|
@Component
|
@Slf4j
|
public class ShuttlePowerEarlyWarning {
|
|
@Autowired
|
private DictService dictService;
|
@Autowired
|
private DeviceService deviceService;
|
|
/**
|
* 小车电量预警检测 => 强制预警
|
* 每30分钟扫描一次
|
*/
|
@Scheduled(cron = "0 30 * * * ? ")
|
public synchronized void shuttlePowerEarlyWarning() {
|
Dict dict = dictService.getOne(new LambdaQueryWrapper<Dict>().eq(Dict::getFlag, "dingdingReportUrl"));
|
if (dict == null) {
|
return;
|
}
|
|
if (dict.getStatus() == 0) {
|
return;//通知禁用
|
}
|
|
//小车电量预警阈值
|
int shuttlePowerEarlyValue = 20;//默认20
|
Dict shuttlePowerEarlyConfig = dictService.getOne(new LambdaQueryWrapper<Dict>().eq(Dict::getFlag, "shuttlePowerEarlyValue"));
|
if (shuttlePowerEarlyConfig != null) {
|
shuttlePowerEarlyValue = Integer.parseInt(shuttlePowerEarlyConfig.getValue());
|
}
|
|
String title = "【通知】四向库";
|
Dict shuttlePowerEarlyTitle = dictService.getOne(new LambdaQueryWrapper<Dict>().eq(Dict::getFlag, "shuttlePowerEarlyTitle"));
|
if (shuttlePowerEarlyTitle != null) {
|
title = shuttlePowerEarlyTitle.getValue();
|
}
|
StringBuffer buffer = new StringBuffer();
|
buffer.append(title);
|
buffer.append("\n");//消息标题
|
|
boolean hasReport = false;//是否有需要报告的数据
|
List<Device> list = deviceService.list(new LambdaQueryWrapper<Device>()
|
.eq(Device::getDeviceType, DeviceCtgType.SHUTTLE.val())
|
.eq(Device::getStatus, 1));
|
for (Device device : list) {
|
//获取四向穿梭车线程
|
ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue());
|
if (shuttleThread == null) {
|
continue;
|
}
|
|
ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
|
if (shuttleProtocol == null) {
|
continue;
|
}
|
|
if (shuttleProtocol.getHasCharge() == null) {
|
continue;
|
}
|
|
if (shuttleProtocol.getHasCharge()) {
|
continue;//充电中,无需通知
|
}
|
|
if (Double.parseDouble(shuttleProtocol.getBatteryPower()) < shuttlePowerEarlyValue) {
|
buffer.append(shuttleProtocol.getShuttleNo()).append("号小车,电量").append(shuttleProtocol.getBatteryPower()).append(",请注意。\n");
|
hasReport = true;
|
}
|
}
|
|
if (hasReport) {
|
try {
|
HashMap<String, Object> param = new HashMap<>();
|
HashMap<String, Object> data = new HashMap<>();
|
data.put("content", buffer.toString());
|
param.put("msgtype", "text");
|
param.put("text", data);
|
String response = new HttpHandler.Builder()
|
.setUri(dict.getValue())
|
.setJson(JSON.toJSONString(param))
|
.setHttps(true)
|
.build()
|
.doPost();
|
JSONObject jsonObject = JSON.parseObject(response);
|
if (jsonObject.get("errmsg").equals("ok")) {
|
return;//发送成功
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
}
|
|
}
|