From 78937bdb9336ff2ddc89fa959aa7b814ded84b43 Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期三, 15 十一月 2023 15:46:38 +0800
Subject: [PATCH] 前端请求参数去除@RequestBody

---
 pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserCtrl.java |  133 +++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 123 insertions(+), 10 deletions(-)

diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserCtrl.java
index e38a597..6eb252b 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserCtrl.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserCtrl.java
@@ -1,11 +1,16 @@
 package com.dy.pipIrrBase.user;
 
 import com.dy.common.aop.SsoAop;
+import com.dy.common.multiDataSource.DataSourceContext;
+import com.dy.common.mybatis.envm.Deleted;
+import com.dy.common.mybatis.envm.Disabled;
+import com.dy.common.util.MD5;
 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.pojoBa.BaUser;
+import com.mysql.cj.util.StringUtils;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
 import io.swagger.v3.oas.annotations.media.Content;
@@ -18,10 +23,7 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.MediaType;
 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;
@@ -53,9 +55,11 @@
                             schema = @Schema(implementation = BaUser.class))}
             )
     })
-    @PostMapping(path = "some")
+    @PostMapping(path = "some", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
     @SsoAop("-1")
-    public BaseResponse<QueryResultVo<List<BaUser>>> some(QueryVo vo){
+    //濡傛灉鍓嶇璇锋眰鏁版嵁鏄痡son锛屽垯瑕佸姞涓婃敞瑙RequestBody
+    //public BaseResponse<QueryResultVo<List<BaUser>>> some(@RequestBody @Parameter(description = "鏌ヨform琛ㄥ崟鏁版嵁", required = true) @Valid QueryVo vo){
+    public BaseResponse<QueryResultVo<List<BaUser>>> some(@Parameter(description = "鏌ヨform琛ㄥ崟鏁版嵁", required = true) @Valid QueryVo vo){
         try {
             QueryResultVo<List<BaUser>> res = this.sv.selectSome(vo) ;
             return BaseResponseUtils.buildSuccess(res);
@@ -80,8 +84,8 @@
     })
     @GetMapping(path = "one")
     @SsoAop("-1")
-    public BaseResponse<BaUser> one(@Parameter(description = "瀹炰綋id", required = true) Long id){
-        return BaseResponseUtils.buildSuccess(this.sv.selectById(id));
+    public BaseResponse<BaUser> one(@Parameter(description = "瀹炰綋id", required = true) String id){
+        return BaseResponseUtils.buildSuccess(this.sv.selectById(Long.parseLong(id)));
     }
 
     /**
@@ -107,6 +111,16 @@
         po.id = null ;
         int count;
         try {
+            po.disabled = Disabled.NO ;//榛樿涓嶇鐢�
+            po.deleted = Deleted.NO ;//榛樿涓嶅垹闄�
+            po.orgTag = DataSourceContext.get() ;//鏈烘瀯鏍囩
+            if(!StringUtils.isNullOrEmpty(po.password)){
+                /*
+                濡傛灉鍓嶇杩涜浜哹ase64鍔犲瘑
+                po.password = new String(Base64.getDecoder().decode(po.password)) ;
+                */
+                po.password = MD5.encrypt(po.password) ;//杩涜鍔犲瘑鐮�
+            }
             count = this.sv.save(po);
         } catch (Exception e) {
             log.error("淇濆瓨鐢ㄦ埛寮傚父", e);
@@ -144,6 +158,8 @@
         }
         int count;
         try {
+            po.deleted = null ;//璁剧疆涓簄ull锛屼笉鍋氭洿鏂�
+            po.orgTag = null ;//璁剧疆涓簄ull锛屼笉鍋氭洿鏂�
             count = this.sv.update(po);
         } catch (Exception e) {
             log.error("淇濆瓨鐢ㄦ埛寮傚父", e);
@@ -154,6 +170,103 @@
         }else{
             return BaseResponseUtils.buildSuccess(true) ;
         }
+    }
+
+
+    /**
+     * 淇敼瀵嗙爜
+     * @param id 鐢ㄦ埛ID
+     * @return 鏄惁鎴愬姛
+     */
+    @Operation(summary = "淇敼瀵嗙爜", description = "鎻愪氦鐢ㄦ埛ID銆佹棫瀵嗙爜銆佹柊瀵嗙爜锛岃繘琛屾敼瀵嗙爜")
+    @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 = "changePassword", consumes = MediaType.TEXT_PLAIN_VALUE)
+    @SsoAop("-1")//@SsoAop(power = "-1")
+    public BaseResponse<Boolean> changePassword(@Parameter(description = "瀹炰綋id", required = true) String id,
+                                                @Parameter(description = "鏃у瘑鐮�", required = true) String oldPassword,
+                                                @Parameter(description = "鏂板瘑鐮�", required = true) String newPassword) throws Exception{
+        if(id == null){
+            return BaseResponseUtils.buildFail("id涓嶈兘涓虹┖") ;
+        }
+        if(StringUtils.isNullOrEmpty(oldPassword)){
+            return BaseResponseUtils.buildFail("鏃у瘑鐮佷笉鑳戒负绌�") ;
+        }
+        if(StringUtils.isNullOrEmpty(newPassword)){
+            return BaseResponseUtils.buildFail("鏂板瘑鐮佷笉鑳戒负绌�") ;
+        }
+        /*
+        濡傛灉鍓嶇杩涜浜哹ase64鍔犲瘑
+        oldPassword = new String(Base64.getDecoder().decode(oldPassword)) ;
+        newPassword = new String(Base64.getDecoder().decode(newPassword)) ;
+        */
+        oldPassword = MD5.encrypt(oldPassword) ;//杩涜鍔犲瘑鐮�
+        newPassword = MD5.encrypt(newPassword) ;//杩涜鍔犲瘑鐮�
+
+        Long idLg = Long.parseLong(id) ;
+        int count ;
+        try {
+            BaUser po = this.sv.selectById(idLg);
+            if(Objects.isNull(po)){
+                return BaseResponseUtils.buildFail("鏈緱鍒扮敤鎴凤紝璇锋眰澶辫触") ;
+            }else{
+                if(!po.password.equalsIgnoreCase(oldPassword)){
+                    return BaseResponseUtils.buildFail("鏃у瘑鐮佷笉姝g‘锛岃姹傚け璐�") ;
+                }else{
+                    count = this.sv.changePassword(idLg, newPassword) ;
+                }
+            }
+        } catch (Exception e) {
+            log.error("淇濆瓨鐢ㄦ埛寮傚父", e);
+            return BaseResponseUtils.buildException(e.getMessage()) ;
+        }
+        if(count <= 0){
+            return BaseResponseUtils.buildFail("鏁版嵁搴撳瓨鍌ㄥけ璐�") ;
+        }else{
+            return BaseResponseUtils.buildSuccess(true) ;
+        }
+    }
+
+
+    /**
+     * 璁剧疆鐢ㄦ埛瑙掕壊
+     * @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 = "setRoles", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
+    @SsoAop("-1")//@SsoAop(power = "-1")
+    public BaseResponse<Boolean> setRoles(@Parameter(description = "瀹炰綋id", required = true) String id,
+                                          @Parameter(description = "瑙掕壊id鏁扮粍") String[] roleIds){
+        Long[] roleId_lg = null ;
+        if(roleIds != null && roleIds.length > 0){
+            roleId_lg = new Long[roleIds.length] ;
+            int index = 0 ;
+            for(String roleId : roleIds){
+                roleId_lg[index++] = Long.parseLong(roleId) ;
+            }
+        }
+        try {
+            this.sv.setRoles(Long.parseLong(id), roleId_lg);
+        } catch (Exception e) {
+            log.error("淇濆瓨鐢ㄦ埛寮傚父", e);
+            return BaseResponseUtils.buildException(e.getMessage()) ;
+        }
+        return BaseResponseUtils.buildSuccess(true) ;
     }
 
 
@@ -173,13 +286,13 @@
     })
     @GetMapping(path = "delete", consumes = MediaType.TEXT_PLAIN_VALUE)
     @SsoAop("-1")//@SsoAop(power = "-1")
-    public BaseResponse<Boolean> delete(@Parameter(description = "瀹炰綋id", required = true) Long id){
+    public BaseResponse<Boolean> delete(@Parameter(description = "瀹炰綋id", required = true) String id){
         if(id == null){
             return BaseResponseUtils.buildFail("id涓嶈兘涓虹┖") ;
         }
         int count;
         try {
-            count = this.sv.delete(id);
+            count = this.sv.delete(Long.parseLong(id));
         } catch (Exception e) {
             log.error("淇濆瓨鐢ㄦ埛寮傚父", e);
             return BaseResponseUtils.buildException(e.getMessage()) ;

--
Gitblit v1.8.0