From 7d885c1d4c86f40927af50e6e7bfa13aac0c2180 Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期四, 21 十二月 2023 21:47:15 +0800
Subject: [PATCH] 1、common模块优化代码,Command命令中增加RTU命令结果返回webRul; 2、通信中间件增加了接收http下发RTU命令和内部命令的Controler; 3、RTU模拟器和控制器增加了上报完数据是否关闭TCP连接的控制。

---
 pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/RoleCtrl.java |  136 +++++++++++++++++++++++++++++++++++++--------
 1 files changed, 112 insertions(+), 24 deletions(-)

diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/RoleCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/RoleCtrl.java
index 9cc6bd7..67f1606 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/RoleCtrl.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/RoleCtrl.java
@@ -6,8 +6,10 @@
 import com.dy.common.webUtil.BaseResponseUtils;
 import com.dy.common.webUtil.QueryResultVo;
 import com.dy.common.webUtil.ResultCodeMsg;
+import com.dy.pipIrrBase.result.SystemResultCode;
 import com.dy.pipIrrBase.user.QueryVo;
 import com.dy.pipIrrGlobal.pojoBa.BaRole;
+import com.dy.pipIrrGlobal.pojoBa.BaRolePermissions;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
 import io.swagger.v3.oas.annotations.media.Content;
@@ -16,26 +18,26 @@
 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.http.MediaType;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.validation.BindingResult;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
-import java.util.List;
-import java.util.Objects;
+import java.util.*;
 
 @Slf4j
 @Tag(name = "瑙掕壊绠$悊", description = "瑙掕壊澧炲垹鏀规煡绛夋搷浣�")
 @RestController
 @RequestMapping(path="role")
+@RequiredArgsConstructor
 @SuppressWarnings("unchecked")//java鐗堟湰瓒婇珮锛屽娉涘瀷绾︽潫瓒婁弗锛屾墍浠ラ厤缃甋uppressWarnings("unchecked")
 public class RoleCtrl {
 
     private RoleSv sv ;
+    private final RoleSv roleSv;
 
     @Autowired
     private void setSv(RoleSv sv){
@@ -55,11 +57,11 @@
                             schema = @Schema(implementation = BaRole.class))}
             )
     })
-    @PostMapping(path = "all")
-    @SsoAop("-1")
-    public BaseResponse<QueryResultVo<List<BaRole>>> all(QueryVo vo){
+    @GetMapping(path = "all")
+    @SsoAop()
+    public BaseResponse<QueryResultVo<List<BaRole>>> all(){
         try {
-            QueryResultVo<List<BaRole>> res = this.sv.selectAll(vo) ;
+            QueryResultVo<List<BaRole>> res = this.sv.selectAll() ;
             return BaseResponseUtils.buildSuccess(res);
         } catch (Exception e) {
             log.error("鏌ヨ瑙掕壊寮傚父", e);
@@ -68,7 +70,7 @@
     }
 
     /**
-     * 瀹㈡埛绔姹傚緱鍒版墍鏈夎鑹叉暟鎹�
+     * 瀹㈡埛绔姹傚緱鍒颁竴椤佃鑹叉暟鎹�
      * @return 鎵�鏈夎鑹叉暟鎹�
      */
     @Operation(summary = "鑾峰緱涓�椤佃鑹�", description = "杩斿洖涓�椤佃鑹叉暟鎹�")
@@ -80,9 +82,9 @@
                             schema = @Schema(implementation = BaRole.class))}
             )
     })
-    @PostMapping(path = "some")
-    @SsoAop("-1")
-    public BaseResponse<QueryResultVo<List<BaRole>>> some(QueryVo vo){
+    @PostMapping(path = "some", consumes = MediaType.APPLICATION_JSON_VALUE)
+    @SsoAop()
+    public BaseResponse<QueryResultVo<List<BaRole>>> some(@RequestBody @Parameter(description = "鏌ヨform琛ㄥ崟json鏁版嵁", required = true) @Valid QueryVo vo){
         try {
             QueryResultVo<List<BaRole>> res = this.sv.selectSome(vo) ;
             return BaseResponseUtils.buildSuccess(res);
@@ -105,8 +107,8 @@
                             schema = @Schema(implementation = BaRole.class))}
             )
     })
-    @GetMapping(path = "one")
-    @SsoAop("-1")
+    @GetMapping(path = "one", consumes = MediaType.TEXT_PLAIN_VALUE)
+    @SsoAop()
     public BaseResponse<BaRole> one(@Parameter(description = "瀹炰綋id", required = true) Long id){
         return BaseResponseUtils.buildSuccess(this.sv.selectById(id));
     }
@@ -125,14 +127,14 @@
                             schema = @Schema(implementation = Boolean.class))}
             )
     })
-    @PostMapping(path = "save", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
-    @SsoAop("-1")//@SsoAop(power = "-1")
-    public BaseResponse<Boolean> save(@Parameter(description = "form琛ㄥ崟鏁版嵁", required = true) @Valid BaRole po, @Parameter(hidden = true) BindingResult bindingResult){
+    @PostMapping(path = "save", consumes = MediaType.APPLICATION_JSON_VALUE)
+    @SsoAop()
+    public BaseResponse<Boolean> save(@RequestBody @Parameter(description = "form琛ㄥ崟json鏁版嵁", required = true) @Valid BaRole po, @Parameter(hidden = true) BindingResult bindingResult){
         if(bindingResult != null && bindingResult.hasErrors()){
             return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
         }
         po.id = null ;
-        int count;
+        Long count;
         try {
             po.deleted = Deleted.NO ;//榛樿涓嶅垹闄�
             count = this.sv.save(po);
@@ -161,9 +163,9 @@
                             schema = @Schema(implementation = Boolean.class))}
             )
     })
-    @PostMapping(path = "update", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
-    @SsoAop("-1")//@SsoAop(power = "-1")
-    public BaseResponse<Boolean> update(@Parameter(description = "form琛ㄥ崟鏁版嵁", required = true) @Valid BaRole po, @Parameter(hidden = true) BindingResult bindingResult){
+    @PostMapping(path = "update", consumes = MediaType.APPLICATION_JSON_VALUE)
+    @SsoAop()
+    public BaseResponse<Boolean> update(@RequestBody @Parameter(description = "form琛ㄥ崟json鏁版嵁", required = true) @Valid BaRole po, @Parameter(hidden = true) BindingResult bindingResult){
         if(bindingResult != null && bindingResult.hasErrors()){
             return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
         }
@@ -186,6 +188,41 @@
     }
 
 
+
+    /**
+     * 璁剧疆瑙掕壊鏉冮檺
+     * @param id 瑙掕壊ID
+     * @return 鏄惁鎴愬姛
+     */
+    @Operation(summary = "璁剧疆瑙掕壊鏉冮檺", description = "鎻愪氦瑙掕壊ID锛屽強鎵�閫夋嫨鐨勬潈闄怚D闆嗗悎锛堟暟缁勶級")
+    @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))}
+            )
+    })
+    @GetMapping(path = "setPrivs", consumes = MediaType.APPLICATION_JSON_VALUE)
+    @SsoAop()
+    public BaseResponse<Boolean> setPrivileges(@Parameter(description = "瀹炰綋id", required = true) Long id,
+                                          @Parameter(description = "鏉冮檺id鏁扮粍") Long[] privIds){
+        Long[] privIds_lg = null ;
+        if(privIds != null && privIds.length > 0){
+            privIds_lg = new Long[privIds.length] ;
+            int index = 0 ;
+            for(Long privId : privIds){
+                privIds_lg[index++] = privId ;
+            }
+        }
+        try {
+            this.sv.setRoles(id, privIds_lg);
+        } catch (Exception e) {
+            log.error("淇濆瓨鐢ㄦ埛寮傚父", e);
+            return BaseResponseUtils.buildException(e.getMessage()) ;
+        }
+        return BaseResponseUtils.buildSuccess(true) ;
+    }
     /**
      * 鍒犻櫎瑙掕壊
      * @param id 瑙掕壊ID
@@ -201,7 +238,7 @@
             )
     })
     @GetMapping(path = "delete", consumes = MediaType.TEXT_PLAIN_VALUE)
-    @SsoAop("-1")//@SsoAop(power = "-1")
+    @SsoAop()
     public BaseResponse<Boolean> delete(@Parameter(description = "瀹炰綋id", required = true) Long id){
         if(id == null){
             return BaseResponseUtils.buildFail("id涓嶈兘涓虹┖") ;
@@ -220,4 +257,55 @@
         }
     }
 
+    @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 = "addPermissions", consumes = MediaType.APPLICATION_JSON_VALUE)
+    @Transactional(rollbackFor = Exception.class)
+    @SsoAop()
+    public BaseResponse<Boolean> permission(@RequestBody @Parameter(description = "form琛ㄥ崟json鏁版嵁", required = true) @Valid BaRolePermissions po, @Parameter(hidden = true) BindingResult bindingResult){
+        if(bindingResult != null && bindingResult.hasErrors()){
+            return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
+        }
+
+        /**
+         * 濡傛灉roleid鍜宺oleName閮界┖锛氭彁绀洪敊璇俊鎭�
+         * 濡傛灉roleid涓虹┖锛氭柊寤鸿鑹蹭笖鎺堟潈
+         *      1. 娣诲姞瑙掕壊璁板綍
+         *      2. 娣诲姞瑙掕壊銆佹潈闄愬叧鑱旇褰�
+         * 濡傛灉roleid涓嶄负绌猴細淇敼瑙掕壊鎺堟潈
+         *      1. 鍒犻櫎瑙掕壊銆佹潈闄愯褰�
+         *      2. 娣诲姞瑙掕壊銆佹潈闄愯褰�
+         */
+
+        Long roleid = Optional.ofNullable(po.getRoleid()).orElse(0L);
+        String roleName = Optional.ofNullable(po.getRoleName()).orElse("");
+        String permissions = Optional.ofNullable(po.getPermissions()).orElse("");
+
+        if(roleid == 0 && roleName.length() == 0) {
+            return BaseResponseUtils.buildFail(SystemResultCode.PERMISSION_ERROR.getMessage());
+        }
+
+        // 鏂板缓瑙掕壊涓旀巿鏉�
+        if(roleid == 0) {
+            BaRole baRole = new BaRole();
+            baRole.setName(roleName);
+            roleid = Optional.ofNullable(roleSv.save(baRole)).orElse(0L);
+            po.setRoleid(roleid);
+            roleSv.addPermissions(po);
+            return BaseResponseUtils.buildSuccess(true) ;
+        }
+
+        // 淇敼瑙掕壊鎺堟潈
+        roleSv.delPermissionsByRoleId(roleid);
+        roleSv.addPermissions(po);
+        return BaseResponseUtils.buildSuccess(true) ;
+    }
+
 }

--
Gitblit v1.8.0