From 074bcb8394fab66ce531c219e1e7de7c142ff2d5 Mon Sep 17 00:00:00 2001
From: doum <doum>
Date: 星期五, 29 五月 2026 11:07:10 +0800
Subject: [PATCH] 新增智能电表、空调管理

---
 server/visits/dmvisit_service/src/main/java/com/doumee/core/conditoner/ConditionerUtil.java |   85 ++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 81 insertions(+), 4 deletions(-)

diff --git a/server/visits/dmvisit_service/src/main/java/com/doumee/core/conditoner/ConditionerUtil.java b/server/visits/dmvisit_service/src/main/java/com/doumee/core/conditoner/ConditionerUtil.java
index 95dd398..45f4b3f 100644
--- a/server/visits/dmvisit_service/src/main/java/com/doumee/core/conditoner/ConditionerUtil.java
+++ b/server/visits/dmvisit_service/src/main/java/com/doumee/core/conditoner/ConditionerUtil.java
@@ -18,6 +18,8 @@
 
 import java.net.URLEncoder;
 import java.nio.charset.StandardCharsets;
+import java.math.BigDecimal;
+import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -283,11 +285,54 @@
     }
 
     public static ConditionerBaseResponse<Object> addGs(CompanyGsManageRequest req) {
-        return postJson("/addGs", req, Object.class);
+        if (req == null) {
+            return null;
+        }
+        req.fillSessionDefaults();
+        JSONObject body = new JSONObject(true);
+        putSessionFields(body, req);
+        body.put("is_pwr", req.getIs_pwr() != null ? req.getIs_pwr() : 1);
+        body.put("li_dev", req.getLi_dev() != null ? req.getLi_dev() : Collections.emptyList());
+        body.put("d_dev", req.getD_dev() != null ? req.getD_dev() : Collections.emptyMap());
+        body.put("gs_name", req.getGs_name());
+        body.put("is_rest_stop", req.getIs_rest_stop() != null ? req.getIs_rest_stop() : 0);
+        body.put("gs_bz", StringUtils.defaultString(req.getGs_bz()));
+        putStopMoney(body, req.getStop_money());
+        return postJsonBody("/addGs", body, Object.class);
     }
 
     public static ConditionerBaseResponse<Object> changeGs(CompanyGsManageRequest req) {
-        return postJson("/changeGs", req, Object.class);
+        if (req == null || req.getId() == null) {
+            return null;
+        }
+        req.fillSessionDefaults();
+        JSONObject body = new JSONObject(true);
+        putSessionFields(body, req);
+        body.put("id", req.getId());
+        body.put("is_pwr", req.getIs_pwr() != null ? req.getIs_pwr() : 1);
+        body.put("is_rest_stop", req.getIs_rest_stop() != null ? req.getIs_rest_stop() : 0);
+        body.put("gs_name", req.getGs_name());
+        if (req.getLeft_money() != null) {
+            body.put("left_money", req.getLeft_money());
+        }
+        body.put("is_stop", req.getIs_stop() != null ? req.getIs_stop() : 0);
+        body.put("li_dev", req.getLi_dev() != null ? req.getLi_dev() : Collections.emptyList());
+        body.put("d_dev", req.getD_dev() != null ? req.getD_dev() : Collections.emptyMap());
+        body.put("gs_bz", StringUtils.defaultString(req.getGs_bz()));
+        putStopMoney(body, req.getStop_money());
+        return postJsonBody("/changeGs", body, Object.class);
+    }
+
+    private static void putStopMoney(JSONObject body, Object stopMoney) {
+        if (stopMoney == null) {
+            body.put("stop_money", "0");
+            return;
+        }
+        if (stopMoney instanceof BigDecimal) {
+            body.put("stop_money", ((BigDecimal) stopMoney).toPlainString());
+        } else {
+            body.put("stop_money", String.valueOf(stopMoney));
+        }
     }
 
     public static ConditionerBaseResponse<Object> delGs(CompanyGsManageRequest req) {
@@ -299,11 +344,26 @@
     }
 
     public static ConditionerBaseResponse<Object> addMoney(AddMoneyRequest req) {
-        return postJson("/addMoney", req, Object.class);
+        if (req == null) {
+            return null;
+        }
+        req.fillSessionDefaults();
+        JSONObject body = new JSONObject(true);
+        putSessionFields(body, req);
+        body.put("id", req.getId());
+        body.put("cz_money", req.getCz_money());
+        return postJsonBody("/addMoney", body, Object.class);
     }
 
     public static ConditionerBaseResponse<Object> cleanMoney(CompanyGsManageRequest req) {
-        return postJson("/cleanMoney", req, Object.class);
+        if (req == null || req.getId() == null) {
+            return null;
+        }
+        req.fillSessionDefaults();
+        JSONObject body = new JSONObject(true);
+        putSessionFields(body, req);
+        body.put("id", req.getId());
+        return postJsonBody("/cleanMoney", body, Object.class);
     }
 
     public static ConditionerBaseResponse<List<Object>> getCzLog(LogQueryRequest req) {
@@ -381,6 +441,23 @@
         }
     }
 
+    private static <T> ConditionerBaseResponse<T> postJsonBody(String path, JSONObject body, Class<T> dataClass) {
+        try {
+            String raw = doPostRaw(path, body.toJSONString());
+            return parseObjectResponse(raw, dataClass);
+        } catch (Exception e) {
+            log.error("conditioner POST {} failed", path, e);
+            return null;
+        }
+    }
+
+    private static void putSessionFields(JSONObject body, ConditionerSessionRequest req) {
+        body.put("kt_token", req.getKt_token());
+        body.put("kt_dwid", req.getKt_dwid());
+        body.put("kt_unit", StringUtils.defaultIfBlank(req.getKt_unit(), ConditionerConstant.DEFAULT_KT_UNIT));
+        body.put("kt_sonid", req.getKt_sonid());
+    }
+
     private static String resolveUrl(String path) {
         String base = StringUtils.defaultIfBlank(ConditionerConstant.base_url, ConditionerConstant.DEFAULT_BASE_URL);
         if (base.endsWith("/")) {

--
Gitblit v1.9.3