From 15bf8d8550804f1e853d52a898ebcca7674a5e39 Mon Sep 17 00:00:00 2001
From: wuzeyu <1223318623@qq.com>
Date: 星期一, 15 一月 2024 17:01:34 +0800
Subject: [PATCH] 流量监测站查询、修改 根据流量监测站编号获取绑定记录

---
 pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/flowMonitoring/MoniFlowCtrl.java |   93 ++++++++++++++++++++++++++++++----------------
 1 files changed, 60 insertions(+), 33 deletions(-)

diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/flowMonitoring/MoniFlowCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/flowMonitoring/MoniFlowCtrl.java
index 1748b64..a2c12df 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/flowMonitoring/MoniFlowCtrl.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/flowMonitoring/MoniFlowCtrl.java
@@ -4,6 +4,7 @@
 import com.dy.common.webUtil.BaseResponse;
 import com.dy.common.webUtil.BaseResponseUtils;
 import com.dy.common.webUtil.ResultCodeMsg;
+import com.dy.pipIrrGlobal.pojoPr.PrFlowMonitoring;
 import com.dy.pipIrrGlobal.pojoPr.PrMonitoringFlowmeter;
 import com.dy.pipIrrProject.result.ProjectResultCode;
 import io.swagger.v3.oas.annotations.Operation;
@@ -18,14 +19,9 @@
 import org.springframework.http.MediaType;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.validation.BindingResult;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
-import java.util.Date;
-import java.util.Objects;
-import java.util.Optional;
+import java.util.*;
 
 /**
  * @author ZhuBaoMin
@@ -37,7 +33,7 @@
 @Slf4j
 @Tag(name = "娴侀噺鐩戞祴绔欍�佹祦閲忚鍏宠仈绠$悊", description = "娴侀噺鐩戞祴绔欍�佹祦閲忚鍏宠仈鎿嶄綔")
 @RestController
-@RequestMapping(path="moni_flow")
+@RequestMapping(path = "moni_flow")
 @RequiredArgsConstructor
 public class MoniFlowCtrl {
     private final MoniFlowSv moniFlowSv;
@@ -47,9 +43,10 @@
 
     /**
      * 娴侀噺鐩戞祴绔欑粦瀹氭祦閲忚
-     *      鑻ユ祦閲忕洃娴嬬珯鎴栨祦閲忚涓嶅瓨鍦ㄩ渶鎻愮ず鐢ㄦ埛
-     *      鑻ユ祦閲忕洃娴嬬珯宸茬粡涓庢祦閲忚缁戝畾闇�鎻愮ず鐢ㄦ埛
-     * @param po 缁戝畾鍏崇郴瀵硅薄
+     * 鑻ユ祦閲忕洃娴嬬珯鎴栨祦閲忚涓嶅瓨鍦ㄩ渶鎻愮ず鐢ㄦ埛
+     * 鑻ユ祦閲忕洃娴嬬珯宸茬粡涓庢祦閲忚缁戝畾闇�鎻愮ず鐢ㄦ埛
+     *
+     * @param po            缁戝畾鍏崇郴瀵硅薄
      * @param bindingResult
      * @return
      */
@@ -65,34 +62,34 @@
     @PostMapping(path = "bind", consumes = MediaType.APPLICATION_JSON_VALUE)
     @Transactional(rollbackFor = Exception.class)
     @SsoAop()
-    public BaseResponse<Boolean> bind(@RequestBody @Valid DtoMoniFlow po, BindingResult bindingResult){
-        if(bindingResult != null && bindingResult.hasErrors()){
+    public BaseResponse<Boolean> bind(@RequestBody @Valid DtoMoniFlow po, BindingResult bindingResult) {
+        if (bindingResult != null && bindingResult.hasErrors()) {
             return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
         }
 
         // 鏍规嵁缂栧彿鍒嗗埆鑾峰彇娴侀噺鐩戞祴绔欍�佹祦閲忚鏈垹闄よ褰曟暟
-        Integer recFlowMonitoring = Optional.ofNullable(flowMonitoringSv.getRecordCountOfFlowMonitoring(po.getMonitoringId())).orElse(0);
-        Integer recFlowmeter = Optional.ofNullable(flowmeterSv.getRecordCountOfFlowmeter(po.getFlowmeterId())).orElse(0);
-        if(recFlowMonitoring == 0 || recFlowmeter == 0) {
+        Integer recFlowMonitoring = Optional.ofNullable(flowMonitoringSv.getRecordCountOfFlowMonitoringByFlowMonitoringId(po.getMonitoringId())).orElse(0);
+        Integer recFlowmeter = Optional.ofNullable(flowmeterSv.getRecordCountOfFlowmeterByCode(po.getFlowmeterId())).orElse(0);
+        if (recFlowMonitoring == 0 || recFlowmeter == 0) {
             return BaseResponseUtils.buildFail(ProjectResultCode.STATION_OR_FLOWMETER_NO_EXIST.getMessage());
         }
 
         // 鏍规嵁缂栧彿鑾峰彇宸茬粦瀹氭暟閲�
-        Integer recordCount = Optional.ofNullable(moniFlowSv.getBindRecordCount(po.getMonitoringId(), po.getFlowmeterId(), (byte)1)).orElse(0);
-        if(recordCount > 0) {
+        Integer recordCount = Optional.ofNullable(moniFlowSv.getBindRecordCount(po.getMonitoringId(), po.getFlowmeterId(), (byte) 1)).orElse(0);
+        if (recordCount > 0) {
             return BaseResponseUtils.buildFail(ProjectResultCode.MONITORING_HAS_BINDED_FLOWMETER.getMessage());
         }
 
         PrMonitoringFlowmeter prMonitoringFlowmeter = DtoToMoniFlowPojo.INSTANCT.po2vo(po);
         Date operateTime = new Date();
-        prMonitoringFlowmeter .setOperatedt(operateTime);
-        prMonitoringFlowmeter.setOperatetype((byte)1);
+        prMonitoringFlowmeter.setOperatedt(operateTime);
+        prMonitoringFlowmeter.setOperatetype((byte) 1);
 
         Integer rec = Optional.ofNullable(moniFlowSv.addRecord(prMonitoringFlowmeter)).orElse(0);
-        if(rec == 0) {
+        if (rec == 0) {
             return BaseResponseUtils.buildFail(ProjectResultCode.MONITORING_FLOWMETER_BIND_FAIL.getMessage());
         }
-        return BaseResponseUtils.buildSuccess(true) ;
+        return BaseResponseUtils.buildSuccess(true);
     }
 
     @Operation(summary = "娣诲姞瑙g粦璁板綍", description = "娣诲姞瑙g粦璁板綍")
@@ -107,33 +104,63 @@
     @PostMapping(path = "unbind", consumes = MediaType.APPLICATION_JSON_VALUE)
     @Transactional(rollbackFor = Exception.class)
     @SsoAop()
-    public BaseResponse<Boolean> unbind(@RequestBody @Valid DtoMoniFlow po, BindingResult bindingResult){
-        if(bindingResult != null && bindingResult.hasErrors()){
+    public BaseResponse<Boolean> unbind(@RequestBody @Valid DtoMoniFlow po, BindingResult bindingResult) {
+        if (bindingResult != null && bindingResult.hasErrors()) {
             return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
         }
 
         // 鏍规嵁缂栧彿鍒嗗埆鑾峰彇娴侀噺鐩戞祴绔欍�佹祦閲忚鏈垹闄よ褰曟暟
-        Integer recFlowMonitoring = Optional.ofNullable(flowMonitoringSv.getRecordCountOfFlowMonitoring(po.getMonitoringId())).orElse(0);
-        Integer recFlowmeter = Optional.ofNullable(flowmeterSv.getRecordCountOfFlowmeter(po.getFlowmeterId())).orElse(0);
-        if(recFlowMonitoring == 0 || recFlowmeter == 0) {
+        Integer recFlowMonitoring = Optional.ofNullable(flowMonitoringSv.getRecordCountOfFlowMonitoringByFlowMonitoringId(po.getMonitoringId())).orElse(0);
+        Integer recFlowmeter = Optional.ofNullable(flowmeterSv.getRecordCountOfFlowmeterByCode(po.getFlowmeterId())).orElse(0);
+        if (recFlowMonitoring == 0 || recFlowmeter == 0) {
             return BaseResponseUtils.buildFail(ProjectResultCode.STATION_OR_FLOWMETER_NO_EXIST.getMessage());
         }
 
         // 鏍规嵁缂栧彿鑾峰彇宸茬粦瀹氭暟閲�
-        Integer recordCount = Optional.ofNullable(moniFlowSv.getBindRecordCount(po.getMonitoringId(), po.getFlowmeterId(), (byte)2)).orElse(0);
-        if(recordCount > 0) {
+        Integer recordCount = Optional.ofNullable(moniFlowSv.getBindRecordCount(po.getMonitoringId(), po.getFlowmeterId(), (byte) 2)).orElse(0);
+        if (recordCount > 0) {
             return BaseResponseUtils.buildFail(ProjectResultCode.STATION_FLOWMETER_HAS_UNBOUND.getMessage());
         }
 
         PrMonitoringFlowmeter prMonitoringFlowmeter = DtoToMoniFlowPojo.INSTANCT.po2vo(po);
         Date operateTime = new Date();
-        prMonitoringFlowmeter .setOperatedt(operateTime);
-        prMonitoringFlowmeter.setOperatetype((byte)1);
+        prMonitoringFlowmeter.setOperatedt(operateTime);
+        prMonitoringFlowmeter.setOperatetype((byte) 1);
 
         Integer rec = Optional.ofNullable(moniFlowSv.addRecord(prMonitoringFlowmeter)).orElse(0);
-        if(rec == 0) {
+        if (rec == 0) {
             return BaseResponseUtils.buildFail(ProjectResultCode.MONITORING_FLOWMETER_BIND_FAIL.getMessage());
         }
-        return BaseResponseUtils.buildSuccess(true) ;
+        return BaseResponseUtils.buildSuccess(true);
+    }
+
+    /**
+     * 鏍规嵁鐩戞祴绔欑紪鍙疯幏鍙栫粦瀹氳褰� 鎸夋搷浣滄椂闂撮檷搴�
+     *
+     * @param monitoringId 鐩戞祴绔欑紪鍙�
+     * @return 缁戝畾璁板綍
+     */
+    @Operation(summary = "鑾峰彇缁戝畾璁板綍", description = "杩斿洖鑾峰彇缁戝畾璁板綍")
+    @ApiResponses(value = {
+            @ApiResponse(
+                    responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
+                    description = "杩斿洖缁戝畾璁板綍锛圔aseResponse.content:QueryResultVo[{}]锛�",
+                    content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
+                            schema = @Schema(implementation = PrMonitoringFlowmeter.class))}
+            )
+    })
+    @GetMapping(path = "bingRecords/{monitoringId}")
+    @SsoAop()
+    public BaseResponse<List<Map<String, Object>>> getBingRecordsByMonitoringId(@PathVariable("monitoringId") Long monitoringId) {
+        try {
+            List<Map<String, Object>> list = Optional.ofNullable(moniFlowSv.getBingRecordsByMonitoringId(monitoringId)).orElse(new ArrayList<>());
+            if (list.size() <= 0) {
+                return BaseResponseUtils.buildFail(ProjectResultCode.NO_MONITORING_FLOWMETERS.getMessage());
+            }
+            return BaseResponseUtils.buildSuccess(list);
+        } catch (Exception e) {
+            log.error("鏌ヨ缁戝畾璁板綍寮傚父", e);
+            return BaseResponseUtils.buildException(e.getMessage());
+        }
     }
 }

--
Gitblit v1.8.0