From f5a10d5ae1290d8ceefee143815555d59be6ff9a Mon Sep 17 00:00:00 2001
From: Administrator <zhubaomin>
Date: 星期四, 23 五月 2024 08:50:58 +0800
Subject: [PATCH] Merge branch 'master' of http://8.140.179.55:20000/r/pipIrr-SV

---
 pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigateUnit/IrrigateUnitCtrl.java |  213 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 210 insertions(+), 3 deletions(-)

diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigateUnit/IrrigateUnitCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigateUnit/IrrigateUnitCtrl.java
index f2b0bf9..2688634 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigateUnit/IrrigateUnitCtrl.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigateUnit/IrrigateUnitCtrl.java
@@ -1,12 +1,39 @@
 package com.dy.pipIrrIrrigate.irrigateUnit;
 
 
+import com.dy.common.aop.SsoAop;
+import com.dy.common.webUtil.BaseResponse;
+import com.dy.common.webUtil.BaseResponseUtils;
+import com.dy.common.webUtil.QueryResultVo;
+import com.dy.common.webUtil.ResultCodeMsg;
+import com.dy.pipIrrGlobal.pojoIr.IrIrrigateUnit;
+import com.dy.pipIrrGlobal.pojoIr.IrProject;
+import com.dy.pipIrrGlobal.voIr.VoProject;
+import com.dy.pipIrrGlobal.voIr.VoProjectOne;
+import com.dy.pipIrrGlobal.voIr.VoUnit;
+import com.dy.pipIrrGlobal.voIr.VoUnitOne;
+import com.dy.pipIrrGlobal.voSe.VoActiveCard;
+import com.dy.pipIrrIrrigate.irrigateUnit.QueryVo;
+import com.dy.pipIrrIrrigate.result.IrrigateResultCode;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
 import io.swagger.v3.oas.annotations.tags.Tag;
+import jakarta.validation.Valid;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.http.MediaType;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.validation.BindingResult;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
 
 /**
  * @author :WuZeYu
@@ -17,9 +44,189 @@
 @Slf4j
 @Tag(name = "鐏屾簤鍗曞厓", description = "鐏屾簤鍗曞厓")
 @RestController
-@RequestMapping(path = "irrigate/unit")
+@RequestMapping(path = "unit")
 @RequiredArgsConstructor
 public class IrrigateUnitCtrl {
     @Autowired
     private  IrrigateUnitSv irrigateUnitSv;
+
+    /**
+     * 鍒涘缓鐏屾簤鍗曞厓
+     *
+     * @param po            鐏屾簤鍗曞厓瀹炰綋瀵硅薄
+     * @param bindingResult
+     * @return 娣诲姞鏄惁鎴愬姛
+     */
+    @Operation(summary = "鍒涘缓鐏屾簤鍗曞厓璁板綍", description = "鍒涘缓鐏屾簤鍗曞厓璁板綍")
+    @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 = "add", consumes = MediaType.APPLICATION_JSON_VALUE)
+    @Transactional(rollbackFor = Exception.class)
+    @SsoAop()
+    public BaseResponse<Boolean> add(@RequestBody @Valid IrIrrigateUnit po, BindingResult bindingResult) {
+        if (bindingResult != null && bindingResult.hasErrors()) {
+            return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
+        }
+        try {
+            Integer rec = Optional.ofNullable(irrigateUnitSv.addIrrigateUnit(po)).orElse(0);
+            if (rec == 0) {
+                return BaseResponseUtils.buildFail(IrrigateResultCode.ADD_PROJECT_FAIL.getMessage());
+            }
+        } catch (Exception e) {
+            log.error("鍒涘缓鐏屾簤鍗曞厓寮傚父", e);
+            return BaseResponseUtils.buildException(e.getMessage());
+        }
+        return BaseResponseUtils.buildSuccess(true);
+    }
+
+    /**
+     * 閫昏緫鍒犻櫎鐏屾簤鍗曞厓
+     * @param map
+     * @return
+     */
+    @Operation(summary = "閫昏緫鍒犻櫎鐏屾簤鍗曞厓", description = "閫昏緫鍒犻櫎鐏屾簤鍗曞厓")
+    @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 = "delete", consumes = MediaType.APPLICATION_JSON_VALUE)
+    @Transactional(rollbackFor = Exception.class)
+    @SsoAop()
+    public BaseResponse<Boolean> delete(@RequestBody Map map) {
+        if (map == null || map.size() <= 0) {
+            BaseResponseUtils.buildFail(IrrigateResultCode.PLEASE_INPUT_PROJECT_ID.getMessage());
+        }
+        Long unitId = Long.parseLong(map.get("id").toString());
+        try {
+            Integer rows = irrigateUnitSv.deleteUnit(unitId);
+            if (rows == 0) {
+                return BaseResponseUtils.buildFail(IrrigateResultCode.DELETE_PROJECT_FAIL.getMessage());
+            }
+        } catch (Exception e) {
+            log.error("鍒犻櫎鐏屾簤鍗曞厓寮傚父", e);
+            return BaseResponseUtils.buildException(e.getMessage());
+        }
+        return BaseResponseUtils.buildSuccess(true);
+    }
+
+    /**
+     * 鎵归噺鍒犻櫎
+     * @param unitIds
+     * @return
+     */
+    @PostMapping(path = "delete_batch", consumes = MediaType.APPLICATION_JSON_VALUE)
+    @Transactional(rollbackFor = Exception.class)
+    @SsoAop()
+    public BaseResponse<Boolean> delete_batch(@RequestBody Map<String, List> unitIds) {
+        if (unitIds == null || unitIds.size() <= 0) {
+            BaseResponseUtils.buildFail(IrrigateResultCode.PLEASE_INPUT_PROJECT_ID.getMessage());
+        }
+        List ids = unitIds.get("unitIds");
+        for (int i = 0; i < ids.size(); i++) {
+            long unitId = Long.parseLong(ids.get(i).toString());
+            try {
+                Integer rows = irrigateUnitSv.deleteUnit(unitId);
+                if (rows == 0) {
+                    return BaseResponseUtils.buildFail(IrrigateResultCode.DELETE_PROJECT_FAIL.getMessage());
+                }
+            } catch (Exception e) {
+                log.error("鍒犻櫎鐏屾簤鍗曞厓寮傚父", e);
+                return BaseResponseUtils.buildException(e.getMessage());
+            }
+        }
+        return BaseResponseUtils.buildSuccess(true);
+    }
+
+    /**
+     * 淇敼鐏屾簤鍗曞厓
+     * @param po
+     * @param bindingResult
+     * @return
+     */
+    @Operation(summary = "淇敼鐏屾簤鍗曞厓", description = "淇敼鐏屾簤鍗曞厓")
+    @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)
+    @Transactional(rollbackFor = Exception.class)
+    @SsoAop()
+    public BaseResponse<Boolean> update(@RequestBody @Valid IrIrrigateUnit po, BindingResult bindingResult){
+        if (bindingResult != null && bindingResult.hasErrors()) {
+            return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
+        }
+        try {
+            Integer rec = Optional.ofNullable(irrigateUnitSv.updateUnit(po)).orElse(0);
+            if (rec == 0) {
+                return BaseResponseUtils.buildFail(IrrigateResultCode.UPDATE_PROJECT_FAIL.getMessage());
+            }
+        } catch (Exception e) {
+            log.error("淇敼鐏屾簤鍗曞厓寮傚父", e);
+            return BaseResponseUtils.buildException(e.getMessage());
+        }
+        return BaseResponseUtils.buildSuccess(true);
+    }
+
+    /**
+     * 鑾峰彇涓�涓亴婧夊崟鍏�
+     *
+     * @return 鑾峰彇涓�涓亴婧夊崟鍏�
+     */
+    @Operation(summary = "鑾峰彇涓�涓亴婧夊崟鍏�", description = "鑾峰彇涓�涓亴婧夊崟鍏�")
+    @ApiResponses(value = {
+            @ApiResponse(
+                    responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
+                    description = "鑾峰彇涓�涓亴婧夊崟鍏冿紙BaseResponse.content:{}锛�",
+                    content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
+                            schema = @Schema(implementation = IrIrrigateUnit.class))}
+            )
+    })
+    @GetMapping(path = "one")
+    @SsoAop()
+    public BaseResponse<VoUnitOne> one(@RequestParam Long id) {
+        VoUnitOne irIrrigateUnit = this.irrigateUnitSv.selectById(id);
+
+            return BaseResponseUtils.buildSuccess(irIrrigateUnit);
+
+    }
+
+    /**
+     * 鍒嗛〉鏌ヨ
+     * @param vo
+     * @return
+     */
+    @Operation(summary = "鑾峰緱涓�椤电亴婧夊崟鍏冭褰�", description = "鑾峰緱涓�椤电亴婧夊崟鍏冭褰�")
+    @ApiResponses(value = {
+            @ApiResponse(
+                    responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
+                    description = "鑾峰緱涓�椤电亴婧夊崟鍏冭褰曪紙BaseResponse.content:QueryResultVo[{}]锛�",
+                    content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
+                            schema = @Schema(implementation = VoActiveCard.class))}
+            )
+    })
+    @GetMapping(path = "some")
+    @SsoAop()
+    public BaseResponse<QueryResultVo<List<VoUnit>>> getUnits(QueryVo vo) {
+        try {
+            QueryResultVo<List<VoUnit>> res = irrigateUnitSv.getUnits(vo);
+            return BaseResponseUtils.buildSuccess(res);
+        } catch (Exception e) {
+            log.error("鑾峰彇鐏屾簤鍗曞厓璁板綍寮傚父", e);
+            return BaseResponseUtils.buildException(e.getMessage());
+        }
+    }
 }

--
Gitblit v1.8.0