New file |
| | |
| | | package com.zy.asrs.task; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.zy.common.utils.HttpHandler; |
| | | import com.zy.core.cache.SlaveConnection; |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.model.ShuttleSlave; |
| | | import com.zy.core.model.protocol.NyShuttleProtocol; |
| | | import com.zy.core.properties.SlaveProperties; |
| | | import com.zy.core.thread.NyShuttleThread; |
| | | import com.zy.system.entity.Config; |
| | | import com.zy.system.service.ConfigService; |
| | | 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; |
| | | |
| | | /** |
| | | * 小车电量预警检测 => 强制预警 |
| | | */ |
| | | @Component |
| | | @Slf4j |
| | | public class ShuttlePowerEarlyWarning { |
| | | |
| | | @Autowired |
| | | private ConfigService configService; |
| | | @Autowired |
| | | private SlaveProperties slaveProperties; |
| | | |
| | | /** |
| | | * 小车电量预警检测 => 强制预警 |
| | | */ |
| | | @Scheduled(cron = "1 * * * * ? ") |
| | | public synchronized void shuttlePowerEarlyWarning() { |
| | | Config config = configService.selectOne(new EntityWrapper<Config>().eq("code","dingdingReportUrl")); |
| | | if (config == null) { |
| | | return; |
| | | } |
| | | |
| | | if (config.getStatus() == 0) { |
| | | return;//通知禁用 |
| | | } |
| | | |
| | | //小车电量预警阈值 |
| | | int shuttlePowerEarlyValue = 20;//默认20 |
| | | Config shuttlePowerEarlyConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "shuttlePowerEarlyValue")); |
| | | if (shuttlePowerEarlyConfig != null) { |
| | | shuttlePowerEarlyValue = Integer.parseInt(shuttlePowerEarlyConfig.getValue()); |
| | | } |
| | | |
| | | StringBuffer buffer = new StringBuffer(); |
| | | buffer.append("【通知】三凯四向库\n");//消息标题 |
| | | |
| | | boolean hasReport = false;//是否有需要报告的数据 |
| | | for (ShuttleSlave slave : slaveProperties.getShuttle()) { |
| | | NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, slave.getId()); |
| | | if (shuttleThread == null) { |
| | | continue; |
| | | } |
| | | |
| | | NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); |
| | | if (shuttleProtocol == null) { |
| | | continue; |
| | | } |
| | | |
| | | if (shuttleProtocol.getChargState() == 1) { |
| | | continue;//充电中,无需通知 |
| | | } |
| | | |
| | | if (shuttleProtocol.getPowerPercent() < shuttlePowerEarlyValue) { |
| | | buffer.append(shuttleProtocol.getShuttleNo()).append("号小车,电量").append(shuttleProtocol.getPowerPercent$()).append(",请注意。\n"); |
| | | } |
| | | } |
| | | |
| | | 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(config.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(); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | } |