From 568508a66ed4d52ece846c72c36d48b938bf1123 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期一, 20 十一月 2023 14:33:23 +0800
Subject: [PATCH] #小车电量预警检测 => 强制预警
---
src/main/java/com/zy/asrs/task/ShuttlePowerEarlyWarning.java | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 103 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/zy/asrs/task/ShuttlePowerEarlyWarning.java b/src/main/java/com/zy/asrs/task/ShuttlePowerEarlyWarning.java
new file mode 100644
index 0000000..259b56e
--- /dev/null
+++ b/src/main/java/com/zy/asrs/task/ShuttlePowerEarlyWarning.java
@@ -0,0 +1,103 @@
+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();
+ }
+ }
+
+ }
+
+}
--
Gitblit v1.9.1