From 656aa4f953eb52502a6414965e46642c31b6e8ee Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期二, 29 四月 2025 15:33:09 +0800
Subject: [PATCH] 设备会在多种功能码上报数据中携带报警与状态数据,这样数据库保存设备报警与状态数据可能很多,为此修改逻辑,当前实现为一设备一个小时内只保存一条报警与状态数据。
---
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/irrigation/IrrigationSv.java | 197 ++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 168 insertions(+), 29 deletions(-)
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/irrigation/IrrigationSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/irrigation/IrrigationSv.java
index 55c979c..205ec52 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/irrigation/IrrigationSv.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/irrigation/IrrigationSv.java
@@ -1,16 +1,38 @@
package com.dy.pipIrrWechat.irrigation;
-import com.dy.common.webUtil.QueryResultVo;
-import com.dy.pipIrrGlobal.daoIr.IrGroupClientMapper;
-import com.dy.pipIrrGlobal.daoIr.IrUnitClientMapper;
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONArray;
+import com.alibaba.fastjson2.JSONObject;
+import com.dy.common.multiDataSource.DataSourceContext;
+import com.dy.common.mw.protocol.Command;
+import com.dy.common.mw.protocol.CommandType;
+
+import com.dy.common.webUtil.BaseResponseUtils;
+import com.dy.pipIrrGlobal.rtuMw.Web2RtuMw;
+
+import com.dy.common.webUtil.BaseResponse;
+import com.dy.pipIrrGlobal.daoIr.IrIrrigateGroupMapper;
+import com.dy.pipIrrGlobal.daoIr.IrProjectMapper;
+import com.dy.pipIrrGlobal.rtuMw.CodeLocal;
+import com.dy.pipIrrGlobal.voIr.VoGroupIntakes;
import com.dy.pipIrrGlobal.voIr.VoGroupSimple;
-import com.dy.pipIrrGlobal.voIr.VoUnitSimple;
-import com.dy.pipIrrWechat.irrigation.qo.QoClient;
+import com.dy.pipIrrGlobal.voIr.VoIntake;
+import com.dy.pipIrrGlobal.voIr.VoProjectSimple;
+import com.dy.pipIrrWechat.irrigation.qo.QoGroup;
+import com.dy.pipIrrWechat.irrigation.qo.QoProject;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.common.utils.PojoUtils;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
+import org.springframework.web.client.RestTemplate;
+import org.springframework.web.util.UriComponentsBuilder;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -25,46 +47,163 @@
@Service
public class IrrigationSv {
@Autowired
- private IrGroupClientMapper irGroupClientMapper;
+ private IrProjectMapper irProjectMapper;
@Autowired
- private IrUnitClientMapper irUnitClientMapper;
+ private IrIrrigateGroupMapper irIrrigateGroupMapper;
+
+ @Autowired
+ private Environment env;
+
+ @Autowired
+ private RestTemplate restTemplate;
+
+ private static final String pro_mw = "mw";
+ private static final String pro_url = "url";
+ protected static final String ContextComSend = "/rtuMw/com/send";
+
+ protected String comSendUrl;
+ /**
+ * pro_mw锛氬睘鎬�
+ * tag浠庢帶鍒跺櫒涓幏鍙�
+ * key_mw锛歶rl鐨刱ey
+ */
+ //private Environment env = null;
+ //private String pro_mw = "mw";
+ private String key_mw = "comSendUrl";
+
/**
- * 鏍规嵁鍐滄埛缂栧彿鑾峰彇杞亴缁勫垪琛�
+ * 鏍规嵁鎸囧畾鏉′欢鑾峰彇椤圭洰璁板綍(绮剧畝)
* @param queryVo
* @return
*/
- public QueryResultVo<List<VoGroupSimple>> getGroupsByClientId(QoClient queryVo) {
+ public List<VoProjectSimple> getSimpleProjects(QoProject queryVo) {
Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo);
-
- Long itemTotal = irGroupClientMapper.getGroupCountByClientId(params);
-
- QueryResultVo<List<VoGroupSimple>> rsVo = new QueryResultVo<>();
- rsVo.pageSize = queryVo.pageSize;
- rsVo.pageCurr = queryVo.pageCurr;
-
- rsVo.calculateAndSet(itemTotal, params);
- rsVo.obj = irGroupClientMapper.getGroupsByClientId(params);
- return rsVo;
+ return irProjectMapper.getSimpleProjects(params);
}
/**
- * 鏍规嵁鍐滄埛缂栧彿鑾峰彇鐏屾簤鍗曞厓鍒楄〃
+ * 鏍规嵁鎸囧畾鏉′欢鑾峰彇杞亴缁勫垪琛�
* @param queryVo
* @return
*/
- public QueryResultVo<List<VoUnitSimple>> getUnitsByClientId(QoClient queryVo) {
+ public List<VoGroupSimple> getSimpleGroups(QoGroup queryVo) {
Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo);
+ //Long itemTotal = irIrrigateGroupMapper.getSimpleGroupCount(params);
- Long itemTotal = irUnitClientMapper.getUnitCountByClientId(params);
+ //QueryResultVo<List<VoGroupSimple>> rsVo = new QueryResultVo<>();
- QueryResultVo<List<VoUnitSimple>> rsVo = new QueryResultVo<>();
- rsVo.pageSize = queryVo.pageSize;
- rsVo.pageCurr = queryVo.pageCurr;
-
- rsVo.calculateAndSet(itemTotal, params);
- rsVo.obj = irUnitClientMapper.getUnitsByClientId(params);
- return rsVo;
+ //rsVo.calculateAndSet(itemTotal, params);
+ //rsVo.obj = irIrrigateGroupMapper.getSimpleGroups(params);
+ //return rsVo;
+ return irIrrigateGroupMapper.getSimpleGroups(params);
}
+
+ /**
+ * 鏍规嵁杞亴缁処D鑾峰彇杞亴缁勮鎯�
+ * @param groupId
+ * @return
+ */
+ public Map getGroupDetails(Long groupId) {
+ try {
+ // 鐢熸垚椤圭洰淇℃伅鍙婅疆鐏岀粍淇℃伅
+ VoGroupIntakes voGroupIntakes = new VoGroupIntakes();
+ String projectName = "";
+ String groupName = "";
+ List<VoGroupIntakes> groupIntakes = irIrrigateGroupMapper.getGroupIntakes(groupId);
+ if (groupIntakes == null) {
+ Map map = new HashMap<>();
+ map.put("success", false);
+ map.put("msg", "杞亴缁勪笉瀛樺湪");
+ map.put("content", null);
+ return map;
+ }
+ for(VoGroupIntakes groupIntake : groupIntakes) {
+ projectName = projectName + groupIntake.getProjectName() + "銆�";
+ groupName = groupIntake.getGroupName();
+ }
+ voGroupIntakes.setProjectName(projectName.substring(0, projectName.length() - 1));
+ voGroupIntakes.setGroupName(groupName);
+
+ // 琛ュ叏鍙栨按鍙d俊鎭紙鍦ㄧ嚎鎯呭喌锛�
+ List<VoIntake> intakes = irIrrigateGroupMapper.getGroupIntakesList(groupId);
+ if(intakes == null) {
+ Map map = new HashMap<>();
+ map.put("success", false);
+ map.put("msg", "璇ヨ疆鐏岀粍鏈粦瀹氬彇姘村彛");
+ map.put("content", null);
+ return map;
+ }
+ for (VoIntake intake : intakes) {
+ intake.setIsOnLine(getRtuStatus(intake.getRtuAddr()));
+ }
+ voGroupIntakes.setIntakes(intakes);
+
+ Map map = new HashMap<>();
+ map.put("success", true);
+ map.put("msg", "鑾峰彇杞亴缁勮鎯呮垚鍔�");
+ map.put("content", voGroupIntakes);
+ return map;
+ } catch (Exception e) {
+ Map map = new HashMap<>();
+ map.put("success", false);
+ map.put("msg", "鑾峰彇杞亴缁勮鎯呭け璐�");
+ map.put("content", null);
+ return map;
+ }
+ }
+
+ /**
+ * 鑾峰彇rtu鍦ㄧ嚎鎯呭喌
+ * @param rtuAdd
+ * @return
+ */
+ public Boolean getRtuStatus(String rtuAdd) {
+ Command com = new Command();
+ com.id = Command.defaultId;
+ com.code = CodeLocal.onLinePart;
+ com.type = CommandType.innerCommand;
+ com.setRtuAddr(rtuAdd);
+ com.setParam(rtuAdd);
+ JSONObject response = (JSONObject) JSON.toJSON(sendCom2Mw(com));
+
+ if (response == null || !response.getString("code").equals("0001") || response.getJSONObject("content").getJSONObject("attachment").size() == 0) {
+ return false;
+ }
+
+ if(response.getJSONObject("content").getJSONObject("attachment").getBoolean(rtuAdd)) {
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+
+ /**
+ * 鍙戦�佸懡浠�
+ *
+ * @return
+ */
+ protected BaseResponse sendCom2Mw(Command com) {
+ String url = UriComponentsBuilder.fromUriString(env.getProperty(pro_mw + "." + DataSourceContext.get() + "." + key_mw))
+ .build()
+ .toUriString();
+ HttpHeaders headers = new HttpHeaders();
+ HttpEntity<Command> httpEntity = new HttpEntity<>(com, headers);
+ ResponseEntity<BaseResponse> response = null;
+ try {
+ // 閫氳繃Post鏂瑰紡璋冪敤鎺ュ彛
+ response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, BaseResponse.class);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ if(response == null) {
+ return BaseResponseUtils.buildErrorMsg("涓棿浠惰皟鐢ㄥけ璐�");
+ }
+
+ return response.getBody();
+ }
+
}
--
Gitblit v1.8.0