From 2b34d59bb1e9b37cdecefdb9c39a27fd839a446b Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期一, 15 四月 2024 19:32:00 +0800
Subject: [PATCH] 1、完善框架代码
---
pms-parent/pms-web-sso/src/main/java/com/dy/sso/config/CaffeineCacheConfiguration.java | 15 ++++-
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/global/SysSetCtrl.java | 6 +-
pms-parent/pms-global/src/main/resources/application-global.yml | 5 +
pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/user/UserCtrl.java | 65 +++++++++++----------
pms-parent/pms-web-sso/src/main/java/com/dy/sso/busi/SsoCtrl.java | 39 +++++++++----
5 files changed, 79 insertions(+), 51 deletions(-)
diff --git a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/global/SysSetCtrl.java b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/global/SysSetCtrl.java
index 64c3f1d..f2dd9da 100644
--- a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/global/SysSetCtrl.java
+++ b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/global/SysSetCtrl.java
@@ -1,9 +1,9 @@
package com.dy.pmsGlobal.global;
-
import com.dy.common.aop.SsoPowerAop;
import com.dy.common.webUtil.BaseResponse;
import com.dy.common.webUtil.BaseResponseUtils;
+import com.dy.pmsGlobal.pojoBa.BaSysSet;
import com.dy.pmsGlobal.pojoBa.BaUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -28,10 +28,10 @@
* @return 鍞竴绯荤粺璁剧疆
*/
//@GetMapping(path = "one", consumes = MediaType.TEXT_PLAIN_VALUE)//鎸囧墠绔悜鍚庝紶鐨勫弬鏁扮被鍨�
- @GetMapping(path = "one")
+ @GetMapping(path = "single")
//@SsoAop() //鍙湁鐧诲綍楠岃瘉锛屾病鏈夋潈闄愰獙璇�
@SsoPowerAop(power = "-1") //鐧诲綍涓庢潈闄愬悓鏃堕獙璇�
- public BaseResponse<BaUser> single() {
+ public BaseResponse<BaSysSet> single() {
try {
return BaseResponseUtils.buildSuccess(this.sv.selectSingle());
} catch (Exception e) {
diff --git a/pms-parent/pms-global/src/main/resources/application-global.yml b/pms-parent/pms-global/src/main/resources/application-global.yml
index baa8748..df1d7c8 100644
--- a/pms-parent/pms-global/src/main/resources/application-global.yml
+++ b/pms-parent/pms-global/src/main/resources/application-global.yml
@@ -35,10 +35,13 @@
aggressiveLazyLoading: false # 灏嗙Н鏋佸姞杞芥敼涓烘秷鏋佸姞杞斤紙鍗虫寜闇�鍔犺浇锛夛紝榛樿鍊兼槸false
lazy-load-trigger-methods: "" # 闃绘尅涓嶇浉骞茬殑鎿嶄綔瑙﹀彂锛屽疄鐜版噿鍔犺浇
cache-enabled: true #鎵撳紑鍏ㄥ眬缂撳瓨寮�鍏筹紙浜岀骇鐜锛夛紝榛樿鍊兼槸true
- default-enum-type-handler: com.dy.common.mybatis.envm.EnumCodeTypeHandler
+ #default-enum-type-handler: com.dy.common.mybatis.envm.EnumCodeTypeHandler
pms:
global:
dev: true #鏄惁寮�鍙戦樁娈碉紝true鎴杅alse锛屽紑鍙戦樁娈典笉杩涜鐧诲綍楠岃瘉鍙婃潈闄愰獙璇�
+ ssoUserExpireAfterAccess: 60 #sso鐧诲綍鍚庯紝鐢ㄦ埛鍦ㄤ竴瀹氭椂闂达紙ssoUserExpireAfterAccess锛夛紙鍒嗛挓锛夊唴鏈闂郴缁燂紝绯荤粺娓呴櫎缂撳瓨淇℃伅锛屼娇鐢ㄩ噸鏂扮櫥褰曠郴缁�
+ ssoCacheSizeInit: 10 #sso缂撳瓨鍒濆瀹归噺
+ ssoCacheSizeMax: 10000 #sso缂撳瓨鏈�澶у閲忥紝鍗虫敮鎸乻soCacheSizeMax涓敤鎴峰悓鏃剁櫥褰�
sso:
checkUrl: http://127.0.0.1:12344/sso/sso/ssoCheck
webPort: 12344
diff --git a/pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/user/UserCtrl.java b/pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/user/UserCtrl.java
index 2c16460..29e4c59 100644
--- a/pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/user/UserCtrl.java
+++ b/pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/user/UserCtrl.java
@@ -137,14 +137,14 @@
//@SsoAop() //鍙湁鐧诲綍楠岃瘉锛屾病鏈夋潈闄愰獙璇�
@SsoPowerAop(power = "10100011") //鐧诲綍涓庢潈闄愬悓鏃堕獙璇�
public BaseResponse<Boolean> update(@RequestBody @Validated BaUser po, BindingResult bindingResult) {
- if (bindingResult != null && bindingResult.hasErrors()) {
- return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
- }
- if (po.id == null) {
- return BaseResponseUtils.buildFail("鏃犳暟鎹疄浣揑D");
- }
int count;
try {
+ if (bindingResult != null && bindingResult.hasErrors()) {
+ return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
+ }
+ if (po.id == null) {
+ return BaseResponseUtils.buildFail("鏃犳暟鎹疄浣揑D");
+ }
po.password = null;//璁剧疆涓簄ull锛屼笉鍋氭洿鏂�
po.supperAdmin = null;//璁剧疆涓簄ull锛屼笉鍋氭洿鏂�
po.deleted = null;//璁剧疆涓簄ull锛屼笉鍋氭洿鏂�
@@ -168,27 +168,28 @@
//@GetMapping(path = "changePassword", consumes = MediaType.TEXT_PLAIN_VALUE)
@GetMapping(path = "changePassword")
@SsoAop()
- public BaseResponse<Boolean> changePassword(String id, String oldPassword, 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);
+ public BaseResponse<Boolean> changePassword(String id, String oldPassword, String newPassword) {
int count;
try {
+ 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) ;
+
BaUser po = this.sv.selectById(idLg);
if (Objects.isNull(po)) {
return BaseResponseUtils.buildFail("鏈緱鍒扮敤鎴凤紝璇锋眰澶辫触");
@@ -219,15 +220,15 @@
@PostMapping(path = "resetPassword", consumes = MediaType.APPLICATION_JSON_VALUE)
//@SsoAop() //鍙湁鐧诲綍楠岃瘉锛屾病鏈夋潈闄愰獙璇�
@SsoPowerAop(power = "10100011") //鐧诲綍涓庢潈闄愬悓鏃堕獙璇�
- public BaseResponse<Boolean> resetPassword(@RequestBody @Validated ResetPasswordVo vo, BindingResult bindingResult) throws Exception {
- if (bindingResult != null && bindingResult.hasErrors()) {
- return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
- }
- String password = MD5.encrypt(vo.password);//杩涜鍔犲瘑鐮�
- Long idLg = Long.parseLong(vo.id);
+ public BaseResponse<Boolean> resetPassword(@RequestBody @Validated ResetPasswordVo vo, BindingResult bindingResult) {
int count;
try {
- BaUser po = this.sv.selectById(idLg);
+ if (bindingResult != null && bindingResult.hasErrors()) {
+ return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
+ }
+ String password = MD5.encrypt(vo.password);//杩涜鍔犲瘑鐮�
+ Long idLg = Long.parseLong(vo.id);
+ BaUser po = this.sv.selectById(idLg);
if (Objects.isNull(po)) {
return BaseResponseUtils.buildFail("鏈緱鍒扮敤鎴凤紝璇锋眰澶辫触");
} else {
diff --git a/pms-parent/pms-web-sso/src/main/java/com/dy/sso/busi/SsoCtrl.java b/pms-parent/pms-web-sso/src/main/java/com/dy/sso/busi/SsoCtrl.java
index 79eb195..3bc9662 100644
--- a/pms-parent/pms-web-sso/src/main/java/com/dy/sso/busi/SsoCtrl.java
+++ b/pms-parent/pms-web-sso/src/main/java/com/dy/sso/busi/SsoCtrl.java
@@ -46,10 +46,15 @@
*/
@PostMapping(path = "login", consumes = MediaType.APPLICATION_JSON_VALUE)//鍓嶇鎻愪氦json鏁版嵁
public BaseResponse<UserVo> login(@RequestBody @Valid LoginVo vo, BindingResult bindingResult) {
- if(bindingResult != null && bindingResult.hasErrors()){
- return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
+ try {
+ if(bindingResult != null && bindingResult.hasErrors()){
+ return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
+ }
+ return this.doLogin(vo) ;
+ } catch (Exception e) {
+ log.error("鏌ヨ涓�涓敤鎴锋暟鎹紓甯�", e);
+ return BaseResponseUtils.buildException(e.getMessage());
}
- return this.doLogin(vo) ;
}
/**
@@ -59,10 +64,15 @@
*/
@PostMapping(path = "loginForm", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)//鍓嶇鎻愪氦form琛ㄥ崟鏁版嵁
public BaseResponse<UserVo> loginForm(@RequestBody @Valid LoginVo vo, BindingResult bindingResult){
- if(bindingResult != null && bindingResult.hasErrors()){
- return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
+ try{
+ if(bindingResult != null && bindingResult.hasErrors()){
+ return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
+ }
+ return this.doLogin(vo) ;
+ } catch (Exception e) {
+ log.error("鏌ヨ涓�涓敤鎴锋暟鎹紓甯�", e);
+ return BaseResponseUtils.buildException(e.getMessage());
}
- return this.doLogin(vo) ;
}
@@ -73,12 +83,17 @@
*/
@GetMapping(path = "logout")
public BaseResponse<Boolean> logout(HttpServletRequest hr){
- String token = hr.getHeader("token") ;
- if(token != null){
- this.sv.logout(token) ;
- return BaseResponseUtils.buildSuccess(true);
- }else{
- return BaseResponseUtils.buildFail("鏈粠header涓緱鍒皌oken");
+ try{
+ String token = hr.getHeader("token") ;
+ if(token != null){
+ this.sv.logout(token) ;
+ return BaseResponseUtils.buildSuccess(true);
+ }else{
+ return BaseResponseUtils.buildFail("鏈粠header涓緱鍒皌oken");
+ }
+ } catch (Exception e) {
+ log.error("鏌ヨ涓�涓敤鎴锋暟鎹紓甯�", e);
+ return BaseResponseUtils.buildException(e.getMessage());
}
}
diff --git a/pms-parent/pms-web-sso/src/main/java/com/dy/sso/config/CaffeineCacheConfiguration.java b/pms-parent/pms-web-sso/src/main/java/com/dy/sso/config/CaffeineCacheConfiguration.java
index 167e9a1..a8e567f 100644
--- a/pms-parent/pms-web-sso/src/main/java/com/dy/sso/config/CaffeineCacheConfiguration.java
+++ b/pms-parent/pms-web-sso/src/main/java/com/dy/sso/config/CaffeineCacheConfiguration.java
@@ -2,6 +2,7 @@
import com.github.benmanes.caffeine.cache.Caffeine;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.CacheManager;
import org.springframework.cache.caffeine.CaffeineCacheManager;
import org.springframework.context.annotation.Bean;
@@ -27,13 +28,21 @@
maximumSize鍜宮aximumWeight涓嶅彲浠ュ悓鏃朵娇鐢�
weakValues鍜宻oftValues涓嶅彲浠ュ悓鏃朵娇鐢偡weakValues鍜宻oftValues涓嶅彲浠ュ悓鏃朵娇鐢�
*/
+
+ @Value("${pms.global.ssoUserExpireAfterAccess:60}")
+ private Integer defaultTrueRandomFalsePassword;
+ @Value("${pms.global.ssoCacheSizeInit:10}")
+ private Integer ssoCacheSizeInit;
+ @Value("${pms.global.ssoCacheSizeMax:10000}")
+ private Integer ssoCacheSizeMax;
+
@Bean
public CacheManager cacheManager() {
CaffeineCacheManager cacheManager = new CaffeineCacheManager();
cacheManager.setCaffeine(Caffeine.newBuilder()
- .initialCapacity(10)
- .maximumSize(10000)
- .expireAfterAccess(30, TimeUnit.MINUTES));
+ .initialCapacity(ssoCacheSizeInit)
+ .maximumSize(ssoCacheSizeMax)
+ .expireAfterAccess(defaultTrueRandomFalsePassword, TimeUnit.MINUTES));
return cacheManager;
}
--
Gitblit v1.8.0