From 16900a8d681aed70bca5b3fea8dc28715dde9712 Mon Sep 17 00:00:00 2001
From: Administrator <zhubaomin>
Date: 星期三, 17 七月 2024 09:53:13 +0800
Subject: [PATCH] 2024-07-17 朱宝民 重构了获取取水口两个接口

---
 pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/intake/IntakeCtrl.java |  157 +++++++++++++++++++++++++++++++++++----------------
 1 files changed, 107 insertions(+), 50 deletions(-)

diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/intake/IntakeCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/intake/IntakeCtrl.java
index cdb44cb..455015f 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/intake/IntakeCtrl.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/intake/IntakeCtrl.java
@@ -9,7 +9,10 @@
 import com.dy.common.webUtil.ResultCodeMsg;
 import com.dy.pipIrrGlobal.pojoPr.PrIntake;
 import com.dy.pipIrrGlobal.voPr.VoIntake;
+import com.dy.pipIrrGlobal.voPr.VoOnLineIntake;
 import com.dy.pipIrrGlobal.voSe.VoActiveCard;
+import com.dy.pipIrrProject.intake.qo.OnLineIntakesQO;
+import com.dy.pipIrrProject.result.ProjectResultCode;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
 import io.swagger.v3.oas.annotations.media.Content;
@@ -32,10 +35,7 @@
 import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
 import java.time.format.DateTimeFormatter;
-import java.util.Date;
-import java.util.List;
-import java.util.Objects;
-import java.util.Optional;
+import java.util.*;
 
 /**
  * @author WuZeYu
@@ -47,14 +47,15 @@
 @Slf4j
 @Tag(name = "鍙栨按鍙g鐞�", description = "鍙栨按鍙f搷浣�")
 @RestController
-@RequestMapping(path="intake")
+@RequestMapping(path = "intake")
 @RequiredArgsConstructor
 public class IntakeCtrl {
     private final IntakeSv intakeSv;
 
     /**
-     * 瀹㈡埛绔姹傚緱鍒版墍鏈夊垎姘村彛鍚嶅瓧
-     * @return 鎵�鏈夊垎姘村彛鍚嶅瓧
+     * 瀹㈡埛绔姹傚緱鍒版墍鏈夊彇姘村彛鍚嶅瓧
+     *
+     * @return 鎵�鏈夊彇姘村彛鍚嶅瓧
      */
     @Operation(summary = "鑾峰緱鍏ㄩ儴鍙栨按鍙�", description = "杩斿洖鍏ㄩ儴鍙栨按鍙f暟鎹�")
     @ApiResponses(value = {
@@ -67,18 +68,23 @@
     })
     @GetMapping(path = "all")
     @SsoAop()
-    public BaseResponse<QueryResultVo<List<PrIntake>>> all(){
+    public BaseResponse<QueryResultVo<List<PrIntake>>> all() {
         try {
             QueryResultVo<List<PrIntake>> res = this.intakeSv.selectAll();
-            return BaseResponseUtils.buildSuccess(res);
+            if (res == null) {
+                return BaseResponseUtils.buildFail(ProjectResultCode.NO_INTAKES.getMessage());
+            } else {
+                return BaseResponseUtils.buildSuccess(res);
+            }
         } catch (Exception e) {
             log.error("鏌ヨ鍙栨按鍙e紓甯�", e);
-            return BaseResponseUtils.buildException(e.getMessage()) ;
+            return BaseResponseUtils.buildException(e.getMessage());
         }
     }
 
     /**
      * 寰楀埌涓�涓彇姘村彛鏁版嵁
+     *
      * @return 涓�涓彇姘村彛鏁版嵁
      */
     @Operation(summary = "涓�涓彇姘村彛", description = "寰楀埌涓�涓彇姘村彛鏁版嵁")
@@ -92,8 +98,12 @@
     })
     @GetMapping(path = "one/{id}")
     @SsoAop()
-    public BaseResponse<PrIntake> one(@PathVariable("id") Long id){
-        return BaseResponseUtils.buildSuccess(this.intakeSv.selectById(id));
+    public BaseResponse<PrIntake> one(@PathVariable("id") Long id) {
+        if (this.intakeSv.selectById(id) == null) {
+            return BaseResponseUtils.buildFail(ProjectResultCode.NO_INTAKES.getMessage());
+        } else {
+            return BaseResponseUtils.buildSuccess(this.intakeSv.selectById(id));
+        }
     }
 
     @Operation(summary = "鑾峰緱涓�椤靛彇姘村彛璁板綍", description = "杩斿洖涓�椤靛彇姘村彛鏁版嵁")
@@ -105,18 +115,18 @@
                             schema = @Schema(implementation = VoActiveCard.class))}
             )
     })
-    @GetMapping(path = "getIntakes", consumes = MediaType.APPLICATION_JSON_VALUE)
+    @GetMapping(path = "getIntakes")
     @SsoAop()
-    public BaseResponse<QueryResultVo<List<VoIntake>>> getIntakes(@RequestBody @Parameter(description = "鏌ヨform琛ㄥ崟json鏁版嵁", required = true) QueryVo vo){
+    public BaseResponse<QueryResultVo<List<VoIntake>>> getIntakes(QueryVo vo) {
         try {
             QueryResultVo<List<VoIntake>> res = intakeSv.getIntakes(vo);
-            if(res == null) {
-                return BaseResponseUtils.buildFail("鏌ヨ澶辫触");
+            if (res == null) {
+                return BaseResponseUtils.buildFail(ProjectResultCode.NO_INTAKES.getMessage());
             }
             return BaseResponseUtils.buildSuccess(res);
         } catch (Exception e) {
             log.error("鑾峰彇鍙栨按鍙h褰曞紓甯�", e);
-            return BaseResponseUtils.buildException(e.getMessage()) ;
+            return BaseResponseUtils.buildException(e.getMessage());
         }
     }
 
@@ -132,23 +142,27 @@
     @PostMapping(path = "add", consumes = MediaType.APPLICATION_JSON_VALUE)
     @Transactional(rollbackFor = Exception.class)
     @SsoAop()
-    public BaseResponse<Boolean> add(@RequestBody @Parameter(description = "form琛ㄥ崟json鏁版嵁", required = true) @Valid PrIntake po, @Parameter(hidden = true) BindingResult bindingResult){
+    public BaseResponse<Boolean> add(@RequestBody  @Valid PrIntake po, @Parameter(hidden = true) BindingResult bindingResult) {
         DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
-        if(bindingResult != null && bindingResult.hasErrors()){
+        if (bindingResult != null && bindingResult.hasErrors()) {
             return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
         }
-
-        Date operateTime = new Date();
-        po.setOperateDt(operateTime);
-        Integer rec = Optional.ofNullable(intakeSv.addIntake(po)).orElse(0);
-        if(rec == 0) {
-            return BaseResponseUtils.buildFail("鏁版嵁搴撳瓨鍌ㄥけ璐�");
+        List<Long> ids = intakeSv.getIntakeIdsByName(po.getName());
+        if (ids.size() > 0) {
+            return BaseResponseUtils.buildFail(ProjectResultCode.INTAKE_NAME_EXIST.getMessage());
         }
-        return BaseResponseUtils.buildSuccess(true) ;
+        po.setOperateDt(new Date());
+        po.setDeleted((byte)0);
+        Integer rec = Optional.ofNullable(intakeSv.addIntake(po)).orElse(0);
+        if (rec == 0) {
+            return BaseResponseUtils.buildFail(ProjectResultCode.ADD_INTAKE_FAIL.getMessage());
+        }
+        return BaseResponseUtils.buildSuccess(true);
     }
 
     /**
      * 缂栬緫淇敼鍙栨按鍙�
+     *
      * @param po 淇濆瓨鍙栨按鍙orm琛ㄥ崟瀵硅薄
      * @return 鏄惁鎴愬姛
      */
@@ -163,29 +177,33 @@
     })
     @PostMapping(path = "update", consumes = MediaType.APPLICATION_JSON_VALUE)
     @SsoAop()
-    public BaseResponse<Boolean> update(@RequestBody @Parameter(description = "form琛ㄥ崟json鏁版嵁", required = true) @Valid PrIntake po, @Parameter(hidden = true) BindingResult bindingResult){
-        if(bindingResult != null && bindingResult.hasErrors()){
+    public BaseResponse<Boolean> update(@RequestBody @Parameter(description = "form琛ㄥ崟json鏁版嵁", required = true) @Valid PrIntake po, @Parameter(hidden = true) BindingResult bindingResult) {
+        if (bindingResult != null && bindingResult.hasErrors()) {
             return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
         }
+        List<Long> ids = intakeSv.getIntakeIdByNameExcludeId(po.getId(), po.getName());
+        if (ids.size() > 0){
+            return BaseResponseUtils.buildFail(ProjectResultCode.INTAKE_NAME_EXIST.getMessage());
+        }
         int count;
-        Date operateTime = new Date();
-        po.setOperateDt(operateTime);
+        po.setOperateDt( new Date());
         try {
             count = this.intakeSv.update(po);
         } catch (Exception e) {
-            log.error("淇濆瓨鍒嗘按鍙e紓甯�", e);
-            return BaseResponseUtils.buildException(e.getMessage()) ;
+            log.error("淇濆瓨鍙栨按鍙e紓甯�", e);
+            return BaseResponseUtils.buildException(e.getMessage());
         }
-        if(count <= 0){
-            return BaseResponseUtils.buildFail("鏁版嵁搴撳瓨鍌ㄥけ璐�") ;
-        }else{
-            return BaseResponseUtils.buildSuccess(true) ;
+        if (count <= 0) {
+            return BaseResponseUtils.buildFail(ProjectResultCode.UPDATE_INTAKE.getMessage());
+        } else {
+            return BaseResponseUtils.buildSuccess(true);
         }
     }
 
     /**
      * 鍒犻櫎鍙栨按鍙�
-     * @param id 鍙栨按鍙D
+     *
+     * @param map 鍙栨按鍙D
      * @return 鏄惁鎴愬姛
      */
     @Operation(summary = "鍒犻櫎鍒嗘按鍙�", description = "鎻愪氦鍙栨按鍙D锛岃繘琛岄�昏緫鍒犻櫎")
@@ -197,28 +215,32 @@
                             schema = @Schema(implementation = Boolean.class))}
             )
     })
-    @GetMapping(path = "delete/{id}")
+    @PostMapping(path = "delete")
     @SsoAop()
-    public BaseResponse<Boolean> delete(@PathVariable("id") Long id){
-        if(id == null){
-            return BaseResponseUtils.buildFail("id涓嶈兘涓虹┖") ;
+    public BaseResponse<Boolean> delete(@RequestBody Map map) {
+        if (map == null || map.size() <= 0) {
+            return BaseResponseUtils.buildFail(ProjectResultCode.PLEASE_INPUT_INTAKE_ID.getMessage());
         }
-        int count;
+        Long id = Long.parseLong(map.get("id").toString());
         try {
-            count = this.intakeSv.delete(id);
+            //鍙栨按鍙D
+            Integer recordCount = Optional.ofNullable(intakeSv.delete(id)).orElse(0);
+            if (recordCount == 0) {
+                return BaseResponseUtils.buildFail(ProjectResultCode.DELETE_INTAKE_FAIL.getMessage());
+            } else {
+                return BaseResponseUtils.buildSuccess(true);
+            }
         } catch (Exception e) {
             log.error("淇濆瓨鍒嗘按鍙e紓甯�", e);
-            return BaseResponseUtils.buildException(e.getMessage()) ;
+            return BaseResponseUtils.buildException(e.getMessage());
         }
-        if(count <= 0){
-            return BaseResponseUtils.buildFail("鏁版嵁搴撳瓨鍌ㄥけ璐�") ;
-        }else{
-            return BaseResponseUtils.buildSuccess(true) ;
-        }
+
+
     }
 
     /**
      * 瀵煎嚭鍙栨按鍙e垪琛�
+     *
      * @param response
      * @param vo
      */
@@ -238,6 +260,7 @@
 
     /**
      * 瀵煎叆鍙栨按鍙e垪琛�
+     *
      * @param file
      */
     @SneakyThrows
@@ -248,7 +271,7 @@
                 .head(VoIntake.class)
                 .sheet()
                 .doReadSync();
-        return BaseResponseUtils.buildSuccess(memberList) ;
+        return BaseResponseUtils.buildSuccess(memberList);
     }
 
     /**
@@ -260,4 +283,38 @@
         String fileName = URLEncoder.encode(rawFileName, "UTF-8").replaceAll("\\+", "%20");
         response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
     }
+
+    /**
+     * 鑾峰彇鍙栨按鍙e垪琛紙鍦ㄧ嚎鍜屼笉鍦ㄧ嚎锛�
+     * @param qo
+     * @return
+     */
+    @GetMapping(path = "all_intakes")
+    @SsoAop()
+    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")
+    @SsoAop()
+    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());
+        }
+    }
 }

--
Gitblit v1.8.0