From 346b480ab7848c742065e9bf989abaf43b515613 Mon Sep 17 00:00:00 2001
From: zhubaomin <zhubaomin>
Date: 星期一, 21 四月 2025 15:05:26 +0800
Subject: [PATCH] 获取轮灌组详情

---
 pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/block/BlockCtrl.java |  272 ++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 191 insertions(+), 81 deletions(-)

diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/block/BlockCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/block/BlockCtrl.java
index 7f0ef55..2f545ab 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/block/BlockCtrl.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/block/BlockCtrl.java
@@ -36,19 +36,20 @@
 @Slf4j
 @Tag(name = "鐗囧尯绠$悊", description = "鐗囧尯澧炲垹鏀规煡绛夋搷浣�")
 @RestController
-@RequestMapping(path="block")
+@RequestMapping(path = "block")
 @SuppressWarnings("unchecked")//java鐗堟湰瓒婇珮锛屽娉涘瀷绾︽潫瓒婁弗锛屾墍浠ラ厤缃甋uppressWarnings("unchecked")
 public class BlockCtrl {
 
-    private BlockSv sv ;
+    private BlockSv sv;
 
     @Autowired
-    private void setSv(BlockSv sv){
-        this.sv = sv ;
+    private void setSv(BlockSv sv) {
+        this.sv = sv;
     }
 
     /**
      * 瀹㈡埛绔姹傚緱鍒版墍鏈夌墖鍖烘暟鎹�
+     *
      * @return 鎵�鏈夌墖鍖烘暟鎹�
      */
     @Operation(summary = "鑾峰緱鍏ㄩ儴鐗囧尯", description = "杩斿洖鍏ㄩ儴鐗囧尯鏁版嵁")
@@ -62,54 +63,54 @@
     })
     @GetMapping(path = "all")
     @SsoAop()
-    public BaseResponse<QueryResultVo<List<BaBlock>>> all(){
+    public BaseResponse<QueryResultVo<List<BaBlock>>> all() {
         try {
-            QueryResultVo<List<BaBlock>> res = this.sv.selectAll() ;
+            QueryResultVo<List<BaBlock>> res = this.sv.selectAll();
             return BaseResponseUtils.buildSuccess(res);
         } catch (Exception e) {
             log.error("鏌ヨ鐗囧尯寮傚父", e);
-            return BaseResponseUtils.buildException(e.getMessage()) ;
+            return BaseResponseUtils.buildException(e.getMessage());
         }
     }
 
     /**
      * 瀹㈡埛绔姹傚緱鍒版墍鏈夌墖鍖烘暟鎹� 2024-08-14搴熷純
+     *
      * @return 鎵�鏈夌墖鍖烘暟鎹�
      */
     @PostMapping(path = "some2", consumes = MediaType.APPLICATION_JSON_VALUE)
     @SsoAop()
-    public BaseResponse<QueryResultVo<List<BaBlock>>> some(@RequestBody QueryVo vo){
+    public BaseResponse<QueryResultVo<List<BaBlock>>> some(@RequestBody QueryVo vo) {
         try {
-            QueryResultVo<List<BaBlock>> res = this.sv.selectSome(vo) ;
+            QueryResultVo<List<BaBlock>> res = this.sv.selectSome(vo);
             return BaseResponseUtils.buildSuccess(res);
         } catch (Exception e) {
             log.error("鏌ヨ鐗囧尯寮傚父", e);
-            return BaseResponseUtils.buildException(e.getMessage()) ;
+            return BaseResponseUtils.buildException(e.getMessage());
         }
     }
 
     /**
      * 鏍规嵁鎸囧畾鏉′欢鑾峰彇鐗囧尯锛�2024-08-14鏂板锛屾浛鎹㈠師鏉ョ殑鐗囧尯鍒嗛〉鏌ヨ
+     *
      * @param qo
-     * @param bindingResult
+     * @param
      * @return
      */
     @GetMapping(path = "/some")
     @SsoAop()
-    public BaseResponse<QueryResultVo<List<VoBlock>>> getBlocks(@Valid QueryVo qo, BindingResult bindingResult) {
-        if(bindingResult != null && bindingResult.hasErrors()){
-            return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
-        }
+    public BaseResponse<QueryResultVo<List<VoBlock>>> getBlocks(QueryVo qo) {
         try {
             return BaseResponseUtils.buildSuccess(this.sv.getBlocks(qo));
         } catch (Exception e) {
             log.error("鑾峰彇寮�鍗¤褰曞紓甯�", e);
-            return BaseResponseUtils.buildException(e.getMessage()) ;
+            return BaseResponseUtils.buildException(e.getMessage());
         }
     }
 
     /**
      * 寰楀埌涓�涓墖鍖烘暟鎹�
+     *
      * @return 涓�涓墖鍖烘暟鎹�
      */
     @Operation(summary = "涓�涓墖鍖�", description = "寰楀埌涓�涓墖鍖烘暟鎹�")
@@ -124,12 +125,13 @@
     //@GetMapping(path = "one", consumes = MediaType.TEXT_PLAIN_VALUE)
     @GetMapping(path = "one")
     @SsoAop()
-    public BaseResponse<BaBlock> one(Long id){
+    public BaseResponse<BaBlock> one(Long id) {
         return BaseResponseUtils.buildSuccess(this.sv.selectById(id));
     }
 
     /**
      * 淇濆瓨鐗囧尯
+     *
      * @param po 淇濆瓨鐗囧尯form琛ㄥ崟瀵硅薄
      * @return 鏄惁鎴愬姛
      */
@@ -146,8 +148,8 @@
     @Transactional(rollbackFor = Exception.class)
     @SsoAop()
     //public BaseResponse<Boolean> save(@RequestBody @Valid BaBlock po, BindingResult bindingResult){
-    public BaseResponse<Boolean> save(@RequestBody @Valid Block po, BindingResult bindingResult){
-        if(bindingResult != null && bindingResult.hasErrors()){
+    public BaseResponse<Boolean> save(@RequestBody @Valid Block po, BindingResult bindingResult) {
+        if (bindingResult != null && bindingResult.hasErrors()) {
             return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
         }
 
@@ -161,47 +163,49 @@
         baBlock.setRemark(po.getRemark());
         baBlock.deleted = Deleted.NO;
         Long blockId = Optional.ofNullable(this.sv.save(baBlock)).orElse(0L);
-        if(blockId.equals(0)) {
+        if (blockId.equals(0)) {
             return BaseResponseUtils.buildErrorMsg(SystemResultCode.SAVA_BLOCK_ERROR.getMessage());
         }
 
         JSONArray graphs = po.getGraphs();
-        for (int i = 0; i < graphs.size(); i++) {
-            JSONObject graph = graphs.getJSONObject(i);
+        if(graphs != null && graphs.size() > 0){
+            for (int i = 0; i < graphs.size(); i++) {
+                JSONObject graph = graphs.getJSONObject(i);
 
-            // 娣诲姞鍦板浘鍥惧舰璁板綍
-            BaMapGraph baMapGraph = new BaMapGraph();
-            baMapGraph.setBlockId(blockId);
-            switch (graph.getString("type")) {
-                case "CircleMarker":
-                    baMapGraph.setGraphType(graphTypeENUM.CIRCLE_MARKER.getCode());
-                    break;
-                case "Polygon":
-                    baMapGraph.setGraphType(graphTypeENUM.POLYGON.getCode());
-                    break;
-                case "Polyline":
-                    baMapGraph.setGraphType(graphTypeENUM.POLYLINE.getCode());
-                    break;
-            }
-            Long graphId = Optional.ofNullable(this.sv.addMapGraph(baMapGraph)).orElse(0L);
-            if(graphId.equals(0)) {
-                return BaseResponseUtils.buildErrorMsg(SystemResultCode.SAVA_BLOCK_ERROR.getMessage());
-            }
+                // 娣诲姞鍦板浘鍥惧舰璁板綍
+                BaMapGraph baMapGraph = new BaMapGraph();
+                baMapGraph.setBlockId(blockId);
+                switch (graph.getString("type")) {
+                    case "CircleMarker":
+                        baMapGraph.setGraphType(graphTypeENUM.CIRCLE_MARKER.getCode());
+                        break;
+                    case "Polygon":
+                        baMapGraph.setGraphType(graphTypeENUM.POLYGON.getCode());
+                        break;
+                    case "Polyline":
+                        baMapGraph.setGraphType(graphTypeENUM.POLYLINE.getCode());
+                        break;
+                }
+                Long graphId = Optional.ofNullable(this.sv.addMapGraph(baMapGraph)).orElse(0L);
+                if (graphId.equals(0)) {
+                    return BaseResponseUtils.buildErrorMsg(SystemResultCode.SAVA_BLOCK_ERROR.getMessage());
+                }
 
-            // 娣诲姞鍦板浘鍥惧舰鍧愭爣璁板綍
-            JSONArray coordinates = graph.getJSONArray("coordinates");
-            for (int j = 0; j < coordinates.size(); j++) {
-                JSONArray coordinate = coordinates.getJSONArray(j);
-                for (int k = 0; k < coordinate.size(); k++) {
-                    JSONObject point = coordinate.getJSONObject(k);
+                // 娣诲姞鍦板浘鍥惧舰鍧愭爣璁板綍
+                JSONArray coordinates = graph.getJSONArray("coordinates");
+                for (int j = 0; j < coordinates.size(); j++) {
+                    JSONArray coordinate = coordinates.getJSONArray(j);
+                    for (int k = 0; k < coordinate.size(); k++) {
+                        JSONObject point = coordinate.getJSONObject(k);
 
-                    BaMapCoordinates mapCoordinates = new BaMapCoordinates();
-                    mapCoordinates.setGraphId(graphId);
-                    mapCoordinates.setLat(point.getBigDecimal("lat"));
-                    mapCoordinates.setLng(point.getBigDecimal("lng"));
-                    Long coordinateId = Optional.ofNullable(this.sv.addMapCoordinate(mapCoordinates)).orElse(0L);
-                    if(coordinateId.equals(0)) {
-                        return BaseResponseUtils.buildErrorMsg(SystemResultCode.SAVA_BLOCK_ERROR.getMessage());
+                        BaMapCoordinates mapCoordinates = new BaMapCoordinates();
+                        mapCoordinates.setGraphId(graphId);
+                        mapCoordinates.setLat(point.getBigDecimal("lat"));
+                        mapCoordinates.setLng(point.getBigDecimal("lng"));
+                        Long coordinateId = Optional.ofNullable(this.sv.addMapCoordinate(mapCoordinates)).orElse(0L);
+                        if (coordinateId.equals(0)) {
+                            return BaseResponseUtils.buildErrorMsg(SystemResultCode.SAVA_BLOCK_ERROR.getMessage());
+                        }
                     }
                 }
             }
@@ -225,45 +229,129 @@
     }
 
     /**
-     * 缂栬緫淇敼鐗囧尯
+     * 缂栬緫淇敼鐗囧尯 2024-08-15 浣滃簾
+     *
      * @param po 淇濆瓨鐗囧尯form琛ㄥ崟瀵硅薄
      * @return 鏄惁鎴愬姛
      */
-    @Operation(summary = "缂栬緫淇敼鐗囧尯", description = "鎻愪氦鐗囧尯鏁版嵁锛坒orm琛ㄥ崟锛夛紝杩涜淇敼")
-    @ApiResponses(value = {
-            @ApiResponse(
-                    responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
-                    description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�",
-                    content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
-                            schema = @Schema(implementation = Boolean.class))}
-            )
-    })
-    @PostMapping(path = "update", consumes = MediaType.APPLICATION_JSON_VALUE)
+    @PostMapping(path = "update2", consumes = MediaType.APPLICATION_JSON_VALUE)
     @SsoAop()
-    public BaseResponse<Boolean> update(@RequestBody @Valid BaBlock po, BindingResult bindingResult){
-        if(bindingResult != null && bindingResult.hasErrors()){
+    public BaseResponse<Boolean> update2(@RequestBody @Valid BaBlock po, BindingResult bindingResult) {
+        if (bindingResult != null && bindingResult.hasErrors()) {
             return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
         }
-        if(po.id == null){
-            return BaseResponseUtils.buildFail("鏃犳暟鎹疄浣揑D") ;
+        if (po.id == null) {
+            return BaseResponseUtils.buildFail("鏃犳暟鎹疄浣揑D");
         }
         int count;
         try {
             count = this.sv.update(po);
         } catch (Exception e) {
             log.error("淇濆瓨鐗囧尯寮傚父", e);
-            return BaseResponseUtils.buildException(e.getMessage()) ;
+            return BaseResponseUtils.buildException(e.getMessage());
         }
-        if(count <= 0){
-            return BaseResponseUtils.buildFail("鏁版嵁搴撳瓨鍌ㄥけ璐�") ;
-        }else{
-            return BaseResponseUtils.buildSuccess(true) ;
+        if (count <= 0) {
+            return BaseResponseUtils.buildFail("鏁版嵁搴撳瓨鍌ㄥけ璐�");
+        } else {
+            return BaseResponseUtils.buildSuccess(true);
         }
     }
 
+    /**
+     * 淇敼鐗囧尯淇℃伅锛�2024-08-15鏂板锛屾浛鎹㈠師鏉ョ殑鐗囧尯淇敼鎺ュ彛
+     *
+     * @param po
+     * @param bindingResult
+     * @return
+     */
+    @PostMapping(path = "update", consumes = MediaType.APPLICATION_JSON_VALUE)
+    @Transactional(rollbackFor = Exception.class)
+    @SsoAop()
+    public BaseResponse<Boolean> update(@RequestBody @Valid Block po, BindingResult bindingResult) {
+        if (bindingResult != null && bindingResult.hasErrors()) {
+            return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
+        }
+
+        Long blockId = po.getId();
+        if (blockId == null) {
+            return BaseResponseUtils.buildErrorMsg(SystemResultCode.THE_BLOCK_NOT_EXIST.getMessage());
+        }
+
+        // 淇敼鐗囧尯淇℃伅
+        BaBlock baBlock = new BaBlock();
+        baBlock.setId(po.getId());
+        baBlock.setName(po.getName());
+        baBlock.setHeader(po.getHeader());
+        baBlock.setPhone(po.getPhone());
+        baBlock.setArea(po.getArea());
+        baBlock.setColor(po.getColor());
+        baBlock.setRemark(po.getRemark());
+        baBlock.setDeleted(po.getDeleted());
+        int count;
+        try {
+            count = this.sv.update(baBlock);
+        } catch (Exception e) {
+            log.error("淇濆瓨鐗囧尯寮傚父", e);
+            return BaseResponseUtils.buildException(e.getMessage());
+        }
+        if (count <= 0) {
+            return BaseResponseUtils.buildFail("鏁版嵁搴撳瓨鍌ㄥけ璐�");
+        }
+
+        // 鍒犻櫎鍦板浘鍥惧舰鍧愭爣
+        this.sv.deleteMapCoordinates(blockId);
+        // 鍒犻櫎鐗囧尯鍏宠仈鐨勫湴鍥惧浘褰�
+        this.sv.deleteMapGraph(blockId);
+
+        JSONArray graphs = po.getGraphs();
+        if(graphs != null && graphs.size() > 0){
+            for (int i = 0; i < graphs.size(); i++) {
+                JSONObject graph = graphs.getJSONObject(i);
+
+                // 娣诲姞鍦板浘鍥惧舰璁板綍
+                BaMapGraph baMapGraph = new BaMapGraph();
+                baMapGraph.setBlockId(blockId);
+                switch (graph.getString("type")) {
+                    case "CircleMarker":
+                        baMapGraph.setGraphType(graphTypeENUM.CIRCLE_MARKER.getCode());
+                        break;
+                    case "Polygon":
+                        baMapGraph.setGraphType(graphTypeENUM.POLYGON.getCode());
+                        break;
+                    case "Polyline":
+                        baMapGraph.setGraphType(graphTypeENUM.POLYLINE.getCode());
+                        break;
+                }
+                Long graphId = Optional.ofNullable(this.sv.addMapGraph(baMapGraph)).orElse(0L);
+                if (graphId.equals(0)) {
+                    return BaseResponseUtils.buildErrorMsg(SystemResultCode.SAVA_BLOCK_ERROR.getMessage());
+                }
+
+                // 娣诲姞鍦板浘鍥惧舰鍧愭爣璁板綍
+                JSONArray coordinates = graph.getJSONArray("coordinates");
+                for (int j = 0; j < coordinates.size(); j++) {
+                    JSONArray coordinate = coordinates.getJSONArray(j);
+                    for (int k = 0; k < coordinate.size(); k++) {
+                        JSONObject point = coordinate.getJSONObject(k);
+
+                        BaMapCoordinates mapCoordinates = new BaMapCoordinates();
+                        mapCoordinates.setGraphId(graphId);
+                        mapCoordinates.setLat(point.getBigDecimal("lat"));
+                        mapCoordinates.setLng(point.getBigDecimal("lng"));
+                        Long coordinateId = Optional.ofNullable(this.sv.addMapCoordinate(mapCoordinates)).orElse(0L);
+                        if (coordinateId.equals(0)) {
+                            return BaseResponseUtils.buildErrorMsg(SystemResultCode.SAVA_BLOCK_ERROR.getMessage());
+                        }
+                    }
+                }
+            }
+        }
+        return BaseResponseUtils.buildSuccess(true);
+    }
 
     /**
      * 鍒犻櫎鐗囧尯
+     *
      * @param id 鐗囧尯ID
      * @return 鏄惁鎴愬姛
      */
@@ -276,24 +364,46 @@
                             schema = @Schema(implementation = Boolean.class))}
             )
     })
+
     //@GetMapping(path = "delete", consumes = MediaType.TEXT_PLAIN_VALUE)
     @GetMapping(path = "delete")
+    @Transactional(rollbackFor = Exception.class)
     @SsoAop()
-    public BaseResponse<Boolean> delete(Long id){
-        if(id == null){
-            return BaseResponseUtils.buildFail("id涓嶈兘涓虹┖") ;
+    public BaseResponse<Boolean> delete(Long id) {
+        if (id == null) {
+            return BaseResponseUtils.buildFail("id涓嶈兘涓虹┖");
         }
         int count;
         try {
             count = this.sv.delete(id);
         } catch (Exception e) {
             log.error("淇濆瓨鐗囧尯寮傚父", e);
-            return BaseResponseUtils.buildException(e.getMessage()) ;
+            return BaseResponseUtils.buildException(e.getMessage());
         }
-        if(count <= 0){
-            return BaseResponseUtils.buildFail("鏁版嵁搴撳瓨鍌ㄥけ璐�") ;
-        }else{
-            return BaseResponseUtils.buildSuccess(true) ;
+        if (count <= 0) {
+            return BaseResponseUtils.buildFail("鏁版嵁搴撳瓨鍌ㄥけ璐�");
+        }
+
+        // 鍒犻櫎鍦板浘鍥惧舰鍧愭爣
+        this.sv.deleteMapCoordinates(id);
+        // 鍒犻櫎鐗囧尯鍏宠仈鐨勫湴鍥惧浘褰�
+        this.sv.deleteMapGraph(id);
+
+        return BaseResponseUtils.buildSuccess(true);
+    }
+
+    /**
+     * 鑾峰彇鐗囧尯銆佸垎姘存埧鑱斿姩瑙嗗浘锛屾坊鍔犲啘鎴锋椂浣跨敤
+     * @return
+     */
+    @GetMapping(path = "/block_divides")
+    @SsoAop()
+    public BaseResponse<JSONArray> getBlockDivides() {
+        try {
+            return BaseResponseUtils.buildSuccess(this.sv.getBlockDivides());
+        } catch (Exception e) {
+            log.error("鑾峰彇寮�鍗¤褰曞紓甯�", e);
+            return BaseResponseUtils.buildException(e.getMessage());
         }
     }
 }

--
Gitblit v1.8.0