From 346b480ab7848c742065e9bf989abaf43b515613 Mon Sep 17 00:00:00 2001
From: zhubaomin <zhubaomin>
Date: 星期一, 21 四月 2025 15:05:26 +0800
Subject: [PATCH] 获取轮灌组详情
---
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voIr/VoGroupIntakes.java | 34 ++++++
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/irrigation/IrrigationSv.java | 150 +++++++++++++++++++++++++++++
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoIr/IrIrrigateGroupMapper.java | 14 ++
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voIr/VoIntake.java | 32 ++++++
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/irrigation/IrrigationCtrl.java | 21 ++++
pipIrr-platform/pipIrr-global/src/main/resources/mapper/IrIrrigateGroupMapper.xml | 24 ++++
6 files changed, 274 insertions(+), 1 deletions(-)
diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoIr/IrIrrigateGroupMapper.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoIr/IrIrrigateGroupMapper.java
index d4b1a79..e49bf93 100644
--- a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoIr/IrIrrigateGroupMapper.java
+++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoIr/IrIrrigateGroupMapper.java
@@ -87,4 +87,18 @@
* @return
*/
List<VoGroupResult> getGroupResult_terminate(@Param("planId") Long planId, @Param("terminateTime") Date terminateTime);
+
+ /**
+ * 鏍规嵁杞亴缁処D鑾峰彇杞亴缁勮鎯�
+ * @param groupId
+ * @return
+ */
+ List<VoGroupIntakes> getGroupIntakes(Long groupId);
+
+ /**
+ * 鏍规嵁杞亴缁処D鑾峰彇杞亴缁勮鎯呭垪琛�
+ * @param groupId
+ * @return
+ */
+ List<VoIntake> getGroupIntakesList(Long groupId);
}
\ No newline at end of file
diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voIr/VoGroupIntakes.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voIr/VoGroupIntakes.java
new file mode 100644
index 0000000..abd65aa
--- /dev/null
+++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voIr/VoGroupIntakes.java
@@ -0,0 +1,34 @@
+package com.dy.pipIrrGlobal.voIr;
+
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * @author ZhuBaoMin
+ * @date 2025-04-18 17:07
+ * @LastEditTime 2025-04-18 17:07
+ * @Description 杞亴缁勮鎯呰鍥惧璞�
+ */
+
+@Data
+@JsonPropertyOrder({"projectName", "groupName", "intakes"})
+public class VoGroupIntakes {
+ private static final long serialVersionUID = 202504181713001L;
+
+ /**
+ * 椤圭洰鍚嶇О
+ */
+ private String projectName;
+
+ /**
+ * 杞亴缁勫悕绉�
+ */
+ private String groupName;
+
+ /**
+ * 杞亴缁勫寘鍚殑鍙栨按鍙�
+ */
+ private List<VoIntake> intakes;
+}
diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voIr/VoIntake.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voIr/VoIntake.java
new file mode 100644
index 0000000..2f1b987
--- /dev/null
+++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voIr/VoIntake.java
@@ -0,0 +1,32 @@
+package com.dy.pipIrrGlobal.voIr;
+
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+import lombok.Data;
+
+/**
+ * @author ZhuBaoMin
+ * @date 2025-04-18 17:08
+ * @LastEditTime 2025-04-18 17:08
+ * @Description 鍙栨按鍙h鍥惧璞★紝鐢ㄤ簬杞亴缁勮鎯呭睍绀哄彇姘村彛淇℃伅锛屽寘鎷悕绉板拰鍦ㄧ嚎鎯呭喌
+ */
+
+@Data
+@JsonPropertyOrder({"intakeName", "rtuAddr", "isOnLine"})
+public class VoIntake {
+ private static final long serialVersionUID = 202504181410001L;
+
+ /**
+ * 鍙栨按鍙e悕绉�
+ */
+ private String intakeName;
+
+ /**
+ * rtu鍦板潃
+ */
+ private String rtuAddr;
+
+ /**
+ * 鏄惁鍦ㄧ嚎
+ */
+ private Boolean isOnLine;
+}
diff --git a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/IrIrrigateGroupMapper.xml b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/IrIrrigateGroupMapper.xml
index a2636b2..115fe2b 100644
--- a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/IrIrrigateGroupMapper.xml
+++ b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/IrIrrigateGroupMapper.xml
@@ -338,4 +338,28 @@
INNER JOIN ir_plan_schedule ps ON ps.schedule_id = sche.id
WHERE ps.plan_id = #{planId}
</select>
+
+ <!--鏍规嵁杞亴缁処D鑾峰彇杞亴缁勮鎯�-->
+ <select id="getGroupIntakes" resultType="com.dy.pipIrrGlobal.voIr.VoGroupIntakes">
+ SELECT
+ pro.project_name AS projectName,
+ gro.group_code AS groupName,
+ NULL AS intakes
+ FROM ir_irrigate_group gro
+ INNER JOIN ir_project_group pg ON pg.group_id = gro.id
+ INNER JOIN ir_project pro ON pro.id = pg.project_id
+ WHERE gro.deleted = 0 AND gro.id = #{groupId}
+ </select>
+
+ <!--鏍规嵁杞亴缁処D鑾峰彇杞亴缁勮鎯呭垪琛�-->
+ <select id="getGroupIntakesList" resultType="com.dy.pipIrrGlobal.voIr.VoIntake">
+ SELECT
+ con.rtuAddr,
+ inta.name AS intakeName,
+ NULL AS isOnLine
+ FROM ir_group_intake gi
+ INNER JOIN pr_intake inta ON inta.id = gi.intake_id
+ INNER JOIN pr_controller con ON con.intakeId = gi.intake_id
+ WHERE gi.group_id = #{groupId}
+ </select>
</mapper>
\ No newline at end of file
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/irrigation/IrrigationCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/irrigation/IrrigationCtrl.java
index 6962e05..6ebf27c 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/irrigation/IrrigationCtrl.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/irrigation/IrrigationCtrl.java
@@ -3,6 +3,7 @@
import com.dy.common.webUtil.BaseResponse;
import com.dy.common.webUtil.BaseResponseUtils;
import com.dy.common.webUtil.QueryResultVo;
+import com.dy.pipIrrGlobal.voIr.VoGroupIntakes;
import com.dy.pipIrrGlobal.voIr.VoGroupSimple;
import com.dy.pipIrrGlobal.voIr.VoProjectSimple;
import com.dy.pipIrrWechat.irrigation.qo.QoGroup;
@@ -11,6 +12,7 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@@ -59,4 +61,23 @@
return BaseResponseUtils.buildException(e.getMessage());
}
}
+
+ /**
+ * 鏍规嵁杞亴缁処D鑾峰彇杞亴缁勮鎯�
+ * @param groupId
+ * @return
+ */
+ @GetMapping(path = "/getGroupDetails")
+ public BaseResponse<VoGroupIntakes> getGroupDetails(@RequestParam Long groupId) {
+ if(groupId == null) {
+ return BaseResponseUtils.buildErrorMsg("杞亴缁処D涓嶈兘涓虹┖");
+ }
+
+ try {
+ return BaseResponseUtils.buildSuccess(irrigationSv.getGroupDetails(groupId).get("content"));
+ } catch (Exception e) {
+ log.error("鑾峰彇杞亴缁勮鎯呭紓甯�", e);
+ return BaseResponseUtils.buildException(e.getMessage());
+ }
+ }
}
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 53d5b19..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,17 +1,38 @@
package com.dy.pipIrrWechat.irrigation;
-import com.dy.common.webUtil.QueryResultVo;
+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.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;
@@ -30,6 +51,27 @@
@Autowired
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";
+
/**
* 鏍规嵁鎸囧畾鏉′欢鑾峰彇椤圭洰璁板綍(绮剧畝)
@@ -58,4 +100,110 @@
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