From 8f60343ef26b4e06dde4aa7c14b157d5c81b6423 Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期四, 16 十一月 2023 15:54:02 +0800
Subject: [PATCH] 行政区添加canAdd和canDelete属性,并实现判断行政区是否可以添加下级行政区,及是否可以删除本级行政区
---
pipIrr-platform/pipIrr-web/pipIrr-web-sso/src/main/java/com/dy/sso/busi/SsoCtrl.java | 183 +++++++++++++++++++++++++++++++++------------
1 files changed, 135 insertions(+), 48 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 957ef19..699d5bc 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
@@ -2,10 +2,14 @@
import com.dy.common.aop.SsoVo;
import com.dy.common.multiDataSource.DataSourceContext;
+import com.dy.common.util.MD5;
import com.dy.common.webUtil.BaseResponse;
import com.dy.common.webUtil.BaseResponseUtils;
import com.dy.common.webUtil.ResultCodeMsg;
import com.dy.pipIrrGlobal.pojoBa.BaUser;
+import com.dy.pipIrrGlobal.util.DistrictLevel;
+import com.dy.pipIrrGlobal.util.Org;
+import com.mysql.cj.util.StringUtils;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
@@ -23,6 +27,8 @@
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
+import java.util.Arrays;
+import java.util.List;
import java.util.Objects;
import java.util.UUID;
@@ -52,6 +58,24 @@
/**
+ * 瀹㈡埛绔姹傚緱鍒版墍鏈夌粍缁囨満鏋�
+ * @return 鎵�鏈夌粍缁囨満鏋勬暟鎹�
+ */
+ @Operation(summary = "鎵�鏈夌粍缁囨満鏋�", description = "杩斿洖鎵�鏈夋墍鏈夌粍缁囨満鏋勬暟鎹�")
+ @ApiResponses(value = {
+ @ApiResponse(
+ responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
+ description = "杩斿洖鎵�鏈夌粍缁囨満鏋勬暟鎹紙BaseResponse.content:[ { \"tag\":\"ym\", \"name\":\"鍏冭皨\" }, { \"tag\":\"鐗囪\", \"name\":\"鐗囪闀嘰" }]锛�",
+ content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
+ schema = @Schema(implementation = Org.class))}
+ )
+ })
+ @GetMapping(path = "allOrg")
+ public BaseResponse<List<Org>> allOrg(){
+ List<Org> list = Arrays.asList(Org.Ym, Org.Pj) ;
+ return BaseResponseUtils.buildSuccess(list);
+ }
+ /**
* 瀹㈡埛绔姹傜敤鎴风櫥褰曪紝瀹㈡埛绔彁浜son鏁版嵁
* @param vo 鐢ㄦ埛鐧诲綍鍊煎璞�
* @param bindingResult 杈撳叆楠岃瘉
@@ -80,13 +104,25 @@
if(bindingResult != null && bindingResult.hasErrors()){
return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
}
+ if(vo.orgTag == null || vo.orgTag.trim().length() == 0){
+ return BaseResponseUtils.buildFail("鏈�夋嫨缁勭粐鍗曚綅");
+ }
+ //鎶婄粍缁囧崟浣嶆爣绛句綔涓烘暟鎹簮鍚嶇О
+ DataSourceContext.set(vo.orgTag);
String uuid ;
BaUser userPo ;
try {
//Boolean flag = cacheManager.getCacheNames().isEmpty() ;
uuid = UUID.randomUUID().toString();
- userPo = this.sv.login(uuid, vo.phone, vo.password);
+ if(!StringUtils.isNullOrEmpty(vo.password)){
+ /*
+ 濡傛灉鍓嶇杩涜浜哹ase64鍔犲瘑
+ po.password = new String(Base64.getDecoder().decode(po.password)) ;
+ */
+ vo.password = MD5.encrypt(vo.password) ;
+ }
+ userPo = this.sv.loginWithMapperXml(uuid, vo.phone, vo.password);
} catch (Exception e) {
log.error("鐢ㄦ埛鐧诲綍寮傚父", e);
return BaseResponseUtils.buildException(e.getMessage()) ;
@@ -131,7 +167,14 @@
try {
//Boolean flag = cacheManager.getCacheNames().isEmpty() ;
uuid = UUID.randomUUID().toString();
- userPo = this.sv.login(uuid, vo.phone, vo.password);
+ if(!StringUtils.isNullOrEmpty(vo.password)){
+ /*
+ 濡傛灉鍓嶇杩涜浜哹ase64鍔犲瘑
+ po.password = new String(Base64.getDecoder().decode(po.password)) ;
+ */
+ vo.password = MD5.encrypt(vo.password) ;
+ }
+ userPo = this.sv.loginWithMapperXml(uuid, vo.phone, vo.password);
} catch (Exception e) {
log.error("鐢ㄦ埛鐧诲綍寮傚父", e);
return BaseResponseUtils.buildException(e.getMessage()) ;
@@ -199,62 +242,27 @@
BaUser userPo = this.sv.getByUuid(token) ;
SsoVo vo = new SsoVo();
if(userPo != null){
+ vo.dataSourceName = userPo.orgTag ;
vo.logined = true ;
vo.hasPower = false ;//榛樿鏄棤鏉冮檺
if(userPo.supperAdmin != null && userPo.supperAdmin == 1){
vo.hasPower = true ;
}else{
- if(userPo.privileges != null && userPo.privileges.size() > 0){
- if(privilege != null && !privilege.trim().equals("")){
- int intPri = Integer.parseInt(privilege) ;
- for(Integer pri : userPo.privileges){
- if(pri == intPri){
- vo.hasPower = true ;
- break ;
- }
- }
- }else{
- if(allPrivilege != null && allPrivilege.length > 0){
- int intPri ;
- boolean ok = false ;
- boolean allOk = true ;
- for(String strPri : allPrivilege){
- intPri = Integer.parseInt(strPri) ;
- for(Integer pri : userPo.privileges){
- if(pri == intPri){
- ok = true ;
- break ;
- }
- }
- if(!ok){
- allOk = false ;
- break ;
- }
- }
- if(allOk){
- vo.hasPower = true ;
- }
- }else{
- int intPri ;
- if(anyPrivilege != null && anyPrivilege.length > 0){
- for(String strPri : anyPrivilege){
- intPri = Integer.parseInt(strPri) ;
- for(Integer pri : userPo.privileges){
- if(pri == intPri){
- vo.hasPower = true ;
- break ;
- }
- }
- if(vo.hasPower){
- break ;
- }
- }
+ if(privilege.equals("-1")){
+ //鏃犻渶鏉冮檺楠岃瘉
+ vo.hasPower = true ;
+ }else{
+ if(userPo.privileges != null && userPo.privileges.size() > 0){
+ vo.hasPower = this.hasOnePrivilege(privilege, userPo) ;
+ if(!vo.hasPower){
+ vo.hasPower = this.hasAllPrivilege(allPrivilege, userPo) ;
+ if(!vo.hasPower){
+ vo.hasPower = this.hasAnyPrivilege(anyPrivilege, userPo) ;
}
}
}
}
}
- vo.dataSourceName = userPo.getOrgTag() ;
}else{
vo.logined = false ;
vo.hasPower = false ;
@@ -262,5 +270,84 @@
return vo ;
}
+ /////////////////////////////////////////////////////////////////
+ //
+ // 浠ヤ笅绉佹湁鏂规硶
+ //
+ /////////////////////////////////////////////////////////////////
+ /**
+ * 鍒ゆ柇鐧诲綍鐢ㄦ埛鏄惁鎷ユ湁鎸囧畾鐨勪竴涓潈闄�
+ * @param privilege 鎸囧畾鐨勪竴涓潈闄�
+ * @param userPo 褰撳墠鐧诲綍鐢ㄦ埛
+ * @return 鏄惁鏈夋潈闄�
+ */
+ private boolean hasOnePrivilege(String privilege, BaUser userPo){
+ boolean hasPrivilege = false ;
+ if (privilege != null && !privilege.trim().equals("")) {
+ int intPri = Integer.parseInt(privilege);
+ for (Integer pri : userPo.privileges) {
+ if (pri == intPri) {
+ hasPrivilege = true;
+ break;
+ }
+ }
+ }
+ return hasPrivilege ;
+ }
+
+ /**
+ * 鍒ゆ柇鐧诲綍鐢ㄦ埛鏄惁鎷ユ湁鎸囧畾鐨勫涓潈闄�
+ * @param allPrivilege 鎸囧畾鐨勫涓潈闄�
+ * @param userPo 褰撳墠鐧诲綍鐢ㄦ埛
+ * @return 鏄惁鏈夋潈闄�
+ */
+ private boolean hasAllPrivilege(String[] allPrivilege, BaUser userPo){
+ boolean hasPrivilege = false ;
+ if(allPrivilege != null && allPrivilege.length > 0){
+ int intPri ;
+ int count = 0 ;
+ for(String strPri : allPrivilege){
+ intPri = Integer.parseInt(strPri) ;
+ for(Integer pri : userPo.privileges){
+ if(pri == intPri){
+ count++ ;
+ break ;
+ }
+ }
+ }
+ if(count == allPrivilege.length){
+ hasPrivilege = true ;
+ }
+ }
+ return hasPrivilege ;
+ }
+
+
+ /**
+ * 鍒ゆ柇鐧诲綍鐢ㄦ埛鏄惁鎷ユ湁鎸囧畾鐨勬煇涓潈闄�
+ * @param anyPrivilege 鎸囧畾鐨勫涓潈闄�
+ * @param userPo 褰撳墠鐧诲綍鐢ㄦ埛
+ * @return 鏄惁鏈夋潈闄�
+ */
+ private boolean hasAnyPrivilege(String[] anyPrivilege, BaUser userPo){
+ boolean hasPrivilege = false ;
+ int intPri ;
+ if(anyPrivilege != null && anyPrivilege.length > 0){
+ for(String strPri : anyPrivilege){
+ intPri = Integer.parseInt(strPri) ;
+ for(Integer pri : userPo.privileges){
+ if(pri == intPri){
+ hasPrivilege = true ;
+ break ;
+ }
+ }
+ if(hasPrivilege){
+ break ;
+ }
+ }
+ }
+ return hasPrivilege ;
+ }
+
}
--
Gitblit v1.8.0