From 57f9815260b6d23c5a626efa9f75fb2ead989da6 Mon Sep 17 00:00:00 2001
From: Administrator <zhubaomin>
Date: 星期四, 20 六月 2024 09:33:42 +0800
Subject: [PATCH] 2024-06-20 朱宝民 迁移2个微信小程序接口

---
 pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/intake/qo/OnLineIntakesQO.java |   33 ++++++
 pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/ClientCtrl.java             |   14 --
 pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/intake/IntakeCtrl.java         |   63 ++++++++++++
 pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/intake/IntakeSv.java           |  134 ++++++++++++++++++++++++++
 4 files changed, 230 insertions(+), 14 deletions(-)

diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/ClientCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/ClientCtrl.java
index 35b198e..f0abe8f 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/ClientCtrl.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/ClientCtrl.java
@@ -8,8 +8,6 @@
 import com.dy.pipIrrGlobal.pojoBa.BaClient;
 import com.dy.pipIrrGlobal.pojoSe.SeClient;
 import com.dy.pipIrrGlobal.voSe.VoClient;
-import com.dy.pipIrrSell.util.RestTemplateUtil;
-import com.dy.pipIrrSell.wechatpay.PayInfo;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.media.Content;
 import io.swagger.v3.oas.annotations.media.Schema;
@@ -42,18 +40,6 @@
 public class ClientCtrl {
     private final ClientSv clientSv;
     //private final RedisUtils redisUtils;
-    private final RestTemplateUtil restTemplateUtil;
-
-    private final String privateCertFileName = PayInfo.privateCertFileName;
-    private final String appid = PayInfo.appid;
-    private final String secret = PayInfo.secret;
-    private final String mchid = PayInfo.mchid;
-    private final String schema = PayInfo.schema;
-    private final String signType = PayInfo.signType;
-    private final String description = PayInfo.description;
-    private final String loginUrl = PayInfo.loginUrl;
-    private final String notifyUrl = PayInfo.notifyUrl;
-    private final String grantType = PayInfo.grantType;
 
     /**
      * 鑾峰彇鍐滄埛鍒楄〃
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/intake/IntakeCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/intake/IntakeCtrl.java
new file mode 100644
index 0000000..45ee4ed
--- /dev/null
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/intake/IntakeCtrl.java
@@ -0,0 +1,63 @@
+package com.dy.pipIrrWechat.intake;
+
+import com.dy.common.webUtil.BaseResponse;
+import com.dy.common.webUtil.BaseResponseUtils;
+import com.dy.common.webUtil.QueryResultVo;
+import com.dy.pipIrrGlobal.voPr.VoOnLineIntake;
+import com.dy.pipIrrWechat.intake.qo.OnLineIntakesQO;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import lombok.RequiredArgsConstructor;
+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.RestController;
+
+import java.util.List;
+
+/**
+ * @author ZhuBaoMin
+ * @date 2024-06-20 8:37
+ * @LastEditTime 2024-06-20 8:37
+ * @Description
+ */
+
+@Slf4j
+@Tag(name = "鍙栨按鍙f暟鎹搷浣�", description = "鍙栨按鍙f暟鎹搷浣�")
+@RestController
+@RequestMapping(path="intake")
+@RequiredArgsConstructor
+public class IntakeCtrl {
+    private final IntakeSv intakeSv;
+
+    /**
+     * 鑾峰彇鍙栨按鍙e垪琛紙鍦ㄧ嚎鍜屼笉鍦ㄧ嚎锛�
+     * @param qo
+     * @return
+     */
+    @GetMapping(path = "all_intakes")
+    public BaseResponse<QueryResultVo<List<VoOnLineIntake>>> getAllIntakes(OnLineIntakesQO qo) {
+        try {
+            QueryResultVo<List<VoOnLineIntake>> res = intakeSv.selectOnLineIntakes(qo);
+            return BaseResponseUtils.buildSuccess(res);
+        } catch (Exception e) {
+            log.error("鏌ヨ鍙栨按鍙e紓甯�", e);
+            return BaseResponseUtils.buildException(e.getMessage());
+        }
+    }
+
+    /**
+     * 鏍规嵁鎿嶄綔鍛樿幏鍙栧父鐢ㄥ彇姘村彛锛堝湪绾垮拰涓嶅湪绾匡級
+     * @param operator
+     * @return
+     */
+    @GetMapping(path = "used_intakes")
+    public BaseResponse<List<VoOnLineIntake>> getUsedIntakes(Long operator) {
+        try {
+            List<VoOnLineIntake> res = intakeSv.getUsedIntakes(operator);
+            return BaseResponseUtils.buildSuccess(res);
+        } catch (Exception e) {
+            log.error("鏌ヨ鍙栨按鍙e紓甯�", e);
+            return BaseResponseUtils.buildException(e.getMessage());
+        }
+    }
+}
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/intake/IntakeSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/intake/IntakeSv.java
new file mode 100644
index 0000000..0e6fd7f
--- /dev/null
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/intake/IntakeSv.java
@@ -0,0 +1,134 @@
+package com.dy.pipIrrWechat.intake;
+
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONArray;
+import com.alibaba.fastjson2.JSONObject;
+import com.dy.common.mw.protocol.Command;
+import com.dy.common.webUtil.BaseResponse;
+import com.dy.common.webUtil.QueryResultVo;
+import com.dy.pipIrrGlobal.daoPr.PrIntakeMapper;
+import com.dy.pipIrrGlobal.voPr.VoOnLineIntake;
+import com.dy.pipIrrWechat.intake.qo.OnLineIntakesQO;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.dubbo.common.utils.PojoUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+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.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author ZhuBaoMin
+ * @date 2024-06-20 8:37
+ * @LastEditTime 2024-06-20 8:37
+ * @Description
+ */
+
+@Slf4j
+@Service
+public class IntakeSv {
+    @Autowired
+    private PrIntakeMapper prIntakeMapper;
+
+    @Autowired
+    private RestTemplate restTemplate;
+
+    protected static String mwUrlSendCom = "http://127.0.0.1:8070/rtuMw/com/send" ;
+
+    /**
+     * 鑾峰彇鍙栨按鍙e垪琛�
+     * @return
+     */
+    public QueryResultVo<List<VoOnLineIntake>> selectOnLineIntakes(OnLineIntakesQO qo) {
+        Command com = new Command() ;
+        com.id = Command.defaultId;
+        com.code = "LCD0001";
+        com.type = "innerCommand";
+
+        JSONObject response = (JSONObject) JSON.toJSON(sendCom2Mw(com));
+
+        if(response != null && response.getString("code").equals("0001")) {
+            JSONObject attachment = response.getJSONObject("content").getJSONObject("attachment").getJSONObject("onLineMap");
+            HashMap<String, Boolean> onLineMap = JSON.parseObject(attachment.toJSONString(), HashMap.class);
+
+            JSONArray jsonArray = new JSONArray();
+            for (Map.Entry<String, Boolean> entry : onLineMap.entrySet()) {
+                JSONObject jsonObject = new JSONObject();
+                jsonObject.put("rtuAddr", entry.getKey());
+                jsonObject.put("isOnLine", entry.getValue());
+                jsonArray.add(jsonObject);
+            }
+
+            qo.setOnLineMap(jsonArray.toJSONString());
+            Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(qo) ;
+            Long itemTotal = prIntakeMapper.getOnLineIntakesCount(params);
+
+            QueryResultVo<List<VoOnLineIntake>> rsVo = new QueryResultVo<>() ;
+            rsVo.pageSize = qo.pageSize ;
+            rsVo.pageCurr = qo.pageCurr ;
+            rsVo.calculateAndSet(itemTotal, params);
+            rsVo.obj = prIntakeMapper.getOnLineIntakes(params);
+            return rsVo;
+        } else {
+            QueryResultVo<List<VoOnLineIntake>> rsVo = new QueryResultVo<>();
+            return rsVo;
+        }
+    }
+
+    /**
+     * 鏍规嵁鎿嶄綔鍛樿幏鍙栧父鐢ㄥ彇姘村彛
+     * @param operator
+     * @return
+     */
+    public List<VoOnLineIntake> getUsedIntakes(Long operator) {
+        Command com = new Command() ;
+        com.id = Command.defaultId;
+        com.code = "LCD0001";
+        com.type = "innerCommand";
+        JSONObject response = (JSONObject) JSON.toJSON(sendCom2Mw(com));
+
+        if(response != null && response.getString("code").equals("0001")) {
+            JSONObject attachment = response.getJSONObject("content").getJSONObject("attachment").getJSONObject("onLineMap");
+            HashMap<String, Boolean> onLineMap = JSON.parseObject(attachment.toJSONString(), HashMap.class);
+
+            JSONArray jsonArray = new JSONArray();
+            for (Map.Entry<String, Boolean> entry : onLineMap.entrySet()) {
+                JSONObject jsonObject = new JSONObject();
+                jsonObject.put("rtuAddr", entry.getKey());
+                jsonObject.put("isOnLine", entry.getValue());
+                jsonArray.add(jsonObject);
+            }
+            return prIntakeMapper.getUsedIntakes(jsonArray.toJSONString(), operator);
+        } else {
+            return new ArrayList<>();
+        }
+    }
+
+    /**
+     * 鍙戦�佸懡浠�
+     * @return
+     */
+    protected BaseResponse sendCom2Mw(Command com){
+        String url = UriComponentsBuilder.fromUriString(mwUrlSendCom)
+                .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();
+        }
+        return response.getBody();
+    }
+}
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/intake/qo/OnLineIntakesQO.java b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/intake/qo/OnLineIntakesQO.java
new file mode 100644
index 0000000..e305015
--- /dev/null
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/intake/qo/OnLineIntakesQO.java
@@ -0,0 +1,33 @@
+package com.dy.pipIrrWechat.intake.qo;
+
+import com.dy.common.webUtil.QueryConditionVo;
+import jakarta.validation.constraints.Max;
+import jakarta.validation.constraints.Min;
+import lombok.Data;
+
+/**
+ * @author ZhuBaoMin
+ * @date 2024-06-20 8:53
+ * @LastEditTime 2024-06-20 8:53
+ * @Description
+ */
+
+@Data
+public class OnLineIntakesQO extends QueryConditionVo {
+    /**
+     * 涓棿浠惰繑鍥炵殑RTU鍦ㄧ嚎鎯呭喌瀵硅薄鏁扮粍
+     */
+    private String onLineMap;
+
+    /**
+     * 鍙栨按鍙g紪鍙�
+     */
+    private String intakeNum;
+
+    /**
+     * 鏄惁鍦ㄧ嚎
+     */
+    @Max(value = 1,message = "鏄惁鍦ㄧ嚎浠呭厑璁镐负鐪熸垨鍋�")
+    @Min(value = 0,message = "鏄惁鍦ㄧ嚎浠呭厑璁镐负鐪熸垨鍋�")
+    private Boolean isOnLine;
+}

--
Gitblit v1.8.0