From 6a6fdb7655f658550efa1d4916d36f216fe34a23 Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期日, 27 四月 2025 09:58:37 +0800
Subject: [PATCH] 1、增加一个MyBatis拦截器,这个拦截器可配置启用,拦截器实现设置虚拟卡占用状态时,统一设置为非占用状态; 2、完善代码。
---
pipIrr-platform/pipIrr-web/pipIrr-web-sso/src/main/java/com/dy/sso/busi/SsoCtrl.java | 72 +++++++++++++++++++++++------------
1 files changed, 47 insertions(+), 25 deletions(-)
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-sso/src/main/java/com/dy/sso/busi/SsoCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-sso/src/main/java/com/dy/sso/busi/SsoCtrl.java
index 725177d..2dd7dee 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-sso/src/main/java/com/dy/sso/busi/SsoCtrl.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-sso/src/main/java/com/dy/sso/busi/SsoCtrl.java
@@ -25,11 +25,7 @@
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
-import java.util.List;
-import java.util.Objects;
-import java.util.UUID;
-
-//import org.springframework.cache.CacheManager;
+import java.util.*;
/**
* 娉ㄨВTag 鍦ˋPI涓樉绀猴細 Tag 娉ㄨВ, 缁欐暣涓帴鍙h捣浜嗕釜鍚嶅瓧涓庢弿杩�"
@@ -47,6 +43,7 @@
//鍦ㄥ睘鎬т笂娉ㄨВ@Autowired鏃讹紝浼氳鍛� Field injection is not recommended锛堜笉鍐嶆帹鑽愪娇鐢ㄥ瓧娈垫敞鍏ワ級
private SsoSv sv ;
+ //private KaptchaConfig kaptchaConfig;
//@Autowired
//private CacheManager cacheManager ;
@@ -55,6 +52,10 @@
this.sv = sv ;
}
+ //@Autowired
+ //public void setKaptchaConfig(KaptchaConfig kaptchaConfig) {
+ // this.kaptchaConfig = kaptchaConfig;
+ //}
/**
* 瀹㈡埛绔姹傚緱鍒版墍鏈夌粍缁囨満鏋�
@@ -70,7 +71,7 @@
)
})
@GetMapping(path = "allOrg")
- public BaseResponse<List<Org>> allOrg(){
+ public BaseResponse<List<Org.OrgVo>> allOrg(){
//List<Org> list = Arrays.asList(Org.Ym, Org.Pj) ;
return BaseResponseUtils.buildSuccess(Org.OrgList);
}
@@ -100,26 +101,47 @@
)
})
@PostMapping(path = "loginJson", consumes = MediaType.APPLICATION_JSON_VALUE)
- public BaseResponse<UserVo> loginJson(@RequestBody @Parameter(description = "鐧诲綍json鏁版嵁", required = true) @Valid LoginVo vo, @Parameter(hidden = true) BindingResult bindingResult) {
+ public BaseResponse<UserVo> loginJson(HttpServletRequest request, @RequestBody @Parameter(description = "鐧诲綍json鏁版嵁", required = true) @Valid LoginVo vo, @Parameter(hidden = true) BindingResult bindingResult) {
if(bindingResult != null && bindingResult.hasErrors()){
- return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
+ return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
}
if(!vo.phone.equals("admin")){
if(vo.phone.length() != 11){
- return BaseResponseUtils.buildFail("鎵嬫満鍙凤紙闀垮害涓嶆槸11浣嶏級涓嶆纭�");
+ return BaseResponseUtils.buildErrorMsg("鎵嬫満鍙凤紙闀垮害涓嶆槸11浣嶏級涓嶆纭�");
}
}
if(vo.orgTag == null || vo.orgTag.trim().length() == 0){
- return BaseResponseUtils.buildFail("鏈�夋嫨缁勭粐鍗曚綅");
+ return BaseResponseUtils.buildErrorMsg("鏈�夋嫨缁勭粐鍗曚綅");
+ }
+ if(vo.token == null || vo.token.trim().length() == 0){
+ return BaseResponseUtils.buildErrorMsg("鏃爐oken");
+ }
+ if(vo.code == null || vo.code.trim().length() == 0){
+ return BaseResponseUtils.buildErrorMsg("璇疯緭鍏ラ獙璇佺爜");
}
//鎶婄粍缁囧崟浣嶆爣绛句綔涓烘暟鎹簮鍚嶇О
DataSourceContext.set(vo.orgTag);
- String uuid ;
- BaUser userPo ;
+ // 浠庢暟鎹簱鑾峰彇楠岃瘉鐮�
+ Map map = sv.getCodeByToken(vo.token);
+ Long expiration = Long.parseLong(map.get("expiration").toString());
+ Long currentTimestamp = System.currentTimeMillis();
+ if(currentTimestamp > expiration) {
+ return BaseResponseUtils.buildErrorMsg("楠岃瘉鐮佸凡瓒呮椂");
+ }
+ String localCode = map.get("code").toString();
+ if(!vo.code.equals(localCode)) {
+ return BaseResponseUtils.buildErrorMsg("楠岃瘉鐮侀敊璇�");
+ }
+
+ if(!sv.existPhone(vo.phone)){
+ return BaseResponseUtils.buildErrorMsg("璐﹀彿涓嶅瓨鍦�");
+ }
+
+ String uuid4Token = null;
+ BaUser userPo = null ;
try {
- //Boolean flag = cacheManager.getCacheNames().isEmpty() ;
- uuid = UUID.randomUUID().toString();
+ uuid4Token = UUID.randomUUID().toString();
if(!StringUtils.isNullOrEmpty(vo.password)){
/*
濡傛灉鍓嶇杩涜浜哹ase64鍔犲瘑
@@ -127,7 +149,7 @@
*/
vo.password = MD5.encrypt(vo.password) ;
}
- userPo = this.sv.loginWithMapperXml(uuid, vo.phone, vo.password);
+ userPo = this.sv.loginWithMapperXml(uuid4Token, vo.phone, vo.password);
} catch (Exception e) {
log.error("鐢ㄦ埛鐧诲綍寮傚父", e);
return BaseResponseUtils.buildException(e.getMessage()) ;
@@ -135,10 +157,10 @@
if(userPo != null){
UserVo uVo = UserVoMapper.INSTANCT.po2vo(userPo);
- uVo.token = uuid ;
+ uVo.token = uuid4Token ;
return BaseResponseUtils.buildSuccess(uVo);
}else{
- return BaseResponseUtils.buildFail("鐧诲綍澶辫触");
+ return BaseResponseUtils.buildErrorMsg("鐧诲綍澶辫触");
}
}
@@ -159,10 +181,10 @@
@PostMapping(path = "loginForm", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public BaseResponse<UserVo> loginForm(@Parameter(description = "form琛ㄥ崟鏁版嵁", required = true) @Valid LoginVo vo, @Parameter(hidden = true) BindingResult bindingResult){
if(bindingResult != null && bindingResult.hasErrors()){
- return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
+ return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
}
if(vo.orgTag == null || vo.orgTag.trim().length() == 0){
- return BaseResponseUtils.buildFail("鏈�夋嫨缁勭粐鍗曚綅");
+ return BaseResponseUtils.buildErrorMsg("鏈�夋嫨缁勭粐鍗曚綅");
}
//鎶婄粍缁囧崟浣嶆爣绛句綔涓烘暟鎹簮鍚嶇О
DataSourceContext.set(vo.orgTag);
@@ -190,7 +212,7 @@
uVo.token = uuid ;
return BaseResponseUtils.buildSuccess(uVo);
}else{
- return BaseResponseUtils.buildFail("鐧诲綍澶辫触");
+ return BaseResponseUtils.buildErrorMsg("鐧诲綍澶辫触");
}
}
@@ -215,7 +237,7 @@
this.sv.logout(token) ;
return BaseResponseUtils.buildSuccess(true);
}else{
- return BaseResponseUtils.buildFail("鏈粠header涓緱鍒皌oken");
+ return BaseResponseUtils.buildErrorMsg("鏈粠header涓緱鍒皌oken");
}
}
@@ -229,7 +251,7 @@
@GetMapping(path = "loginUserId")
public Long loginUserId(String token){
BaUser userPo = this.sv.getByUuid(token) ;
- return userPo == null ? null : userPo.userId ;
+ return userPo == null ? null : userPo.id ;
}
/**
* 姝ゆ柟娉曚緵瀛愭ā鍧楃郴缁熻皟鐢紝鎵�浠ヤ笉鍏紑鍦ˋPI鎺ュ彛涓�
@@ -245,10 +267,10 @@
if(userPo != null){
vo.dataSourceName = userPo.orgTag ;
vo.logined = true ;
- vo.hasPower = true ;//榛樿鏈夋潈闄�
+ vo.hasPower = true ;//榛樿鏈夋潈闄愩��2023-12-21 缁忓晢璁紝鐢卞墠绔壌鏉�
}else{
vo.logined = false ;
- vo.hasPower = true ;//榛樿鏈夋潈闄�
+ vo.hasPower = true ;//榛樿鏈夋潈闄愩��2023-12-21 缁忓晢璁紝鐢卞墠绔壌鏉�
}
return vo ;
}
@@ -306,7 +328,7 @@
BaUser userPo = this.sv.getByUuid(token) ;
CurUserVo vo = new CurUserVo();
if(userPo != null){
- vo.id = userPo.userId ;
+ vo.id = userPo.id ;
vo.name = userPo.userName;
}
return vo ;
--
Gitblit v1.8.0