From 0eb28fecafb15512c82aeae00b40fb1bca65f08c Mon Sep 17 00:00:00 2001
From: luofl <1442745593@qq.com>
Date: 星期五, 21 三月 2025 18:41:57 +0800
Subject: [PATCH] 修改按钮权限

---
 springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/service/impl/IdentityInformationServiceImpl.java |   94 +++++++++++++++++++++++++++++++---------------
 1 files changed, 63 insertions(+), 31 deletions(-)

diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/service/impl/IdentityInformationServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/service/impl/IdentityInformationServiceImpl.java
index 60e8b34..b3678da 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/service/impl/IdentityInformationServiceImpl.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/service/impl/IdentityInformationServiceImpl.java
@@ -1,6 +1,8 @@
 package com.panzhihua.sangeshenbian.service.impl;
 
+import cn.hutool.core.collection.CollectionUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.panzhihua.common.exceptions.ServiceException;
 import com.panzhihua.common.model.vos.LoginUserInfoVO;
 import com.panzhihua.common.redis.RedisUtils;
 import com.panzhihua.sangeshenbian.model.entity.PartyMember;
@@ -31,10 +33,16 @@
                 .eq(PartyMember::getDelFlag, 0));
 
         // 获取管理员信息
-        SystemUser systemUser = systemUserService.getSystemUserAdminByPhone(loginUserInfo.getPhone()).orElse(null);
+        SystemUser systemUser = systemUserService.lambdaQuery()
+                .eq(SystemUser::getPhone, loginUserInfo.getPhone())
+                .eq(SystemUser::getIsAdmin, 1).last("LIMIT 1")
+                .ne(SystemUser::getStatus, 3)
+                .one();
         // 获取身份
         Integer identity = (Integer) redisUtils.get("identity:" + loginUserInfo.getPhone());
+        // 权限列表
         List<PermissionsVO> permissions = new ArrayList<>();
+
         IdentityInformation identityInformationVO = new IdentityInformation();
         identityInformationVO.setPartyMember(partyMember);
         identityInformationVO.setSystemUser(systemUser);
@@ -43,23 +51,32 @@
         Integer isConfirm = (Integer) redisUtils.get("confirmContent:" + loginUserInfo.getPhone());
         identityInformationVO.setIsConfirmContent(isConfirm != null && isConfirm == 1);
 
-        if (partyMember != null) {
-            identityInformationVO.setIsFrozen(partyMember.getFreezeStatus() == 1);
-        }
-        if (systemUser != null) {
-            identityInformationVO.setIsFrozen(systemUser.getStatus() == 2);
+        // 获取当前身份
+        if (identity == null){
+            if (systemUser != null){
+                identityInformationVO.setIdentity(2);
+                redisUtils.set("identity:" + loginUserInfo.getPhone(), 2);
+            }else if (partyMember != null && partyMember.getAuditStatus() == 1){
+                identityInformationVO.setIdentity(1);
+                redisUtils.set("identity:" + loginUserInfo.getPhone(), 1);
+            }else {
+                identityInformationVO.setIdentity(null);
+            }
+        }else {
+            if (identity == 1 && (partyMember == null || partyMember.getAuditStatus() != 1)){
+                identityInformationVO.setIdentity(null);
+                redisUtils.remove("identity:" + loginUserInfo.getPhone());
+            }else if (identity == 2 && systemUser == null){
+                identityInformationVO.setIdentity(null);
+                redisUtils.remove("identity:" + loginUserInfo.getPhone());
+            }else {
+                identityInformationVO.setIdentity(identity);
+            }
         }
 
-        if (identity == null && systemUser != null) {
-            identityInformationVO.setIdentity(2);
-            redisUtils.set("identity:" + loginUserInfo.getPhone(), 2);
-        } else if (identity == null && partyMember != null) {
-            identityInformationVO.setIdentity(1);
-            redisUtils.set("identity:" + loginUserInfo.getPhone(), 1);
-        } else {
-            identityInformationVO.setIdentity(identity);
-        }
 
+
+        // 获取是否冻结
         if (identityInformationVO.getIdentity() != null) {
             if (identityInformationVO.getIdentity() == 1) {
                 identityInformationVO.setIsFrozen(partyMember != null && partyMember.getFreezeStatus() == 1);
@@ -70,11 +87,14 @@
             identityInformationVO.setIsFrozen(false);
         }
 
-
+        // 是否认证党员
         identityInformationVO.setIsPartymember(partyMember != null && partyMember.getAuditStatus().equals(1));
+        // 是否确认党员信息
         identityInformationVO.setIsConfirm(partyMember != null && partyMember.getIsConfirm() == 1);
+        // 党员审核状态
         identityInformationVO.setAuditStatus(partyMember == null ? null : partyMember.getAuditStatus());
 
+        // 封装管理员信息
         if (systemUser != null) {
             Integer accountLevel = systemUser.getAccountLevel();
             String districts = systemUser.getDistricts();
@@ -97,7 +117,8 @@
             permissions.add(adminPermissions);
         }
 
-        if (partyMember != null) {
+        // 封装党员信息
+        if (partyMember != null && partyMember.getAuditStatus().equals(1)) {
             PermissionsVO partyMemberPermissions = new PermissionsVO();
             partyMemberPermissions.setIdentity(1);
             partyMemberPermissions.setName(String.format("%s%s", partyMember.getCommunity(), "党员"));
@@ -108,18 +129,29 @@
         return identityInformationVO;
     }
 
-//    @Override
-//    public IdentityInformation getCurrentIdentityInformation(LoginUserInfoVO loginUserInfo) {
-//        if (identity == null && systemUser != null) {
-//            identityInformationVO.setIdentity(2);
-//            redisUtils.set("identity:" + loginUserInfo.getPhone(), 2);
-//        }else if (identity == null && partyMember != null){
-//            identityInformationVO.setIdentity(1);
-//            redisUtils.set("identity:" + loginUserInfo.getPhone(), 1);
-//        }
-//        else {
-//            identityInformationVO.setIdentity(identity);
-//        }
-//        return null;
-//    }
+
+
+    @Override
+    public IdentityInformation getCurrentIdentityInformation(LoginUserInfoVO loginUserInfo) {
+        IdentityInformation identityInformation = getIdentityInformation(loginUserInfo);
+        Boolean isFrozen = identityInformation.getIsFrozen();
+        if (isFrozen) {
+            throw new ServiceException("您的账号已被冻结,请联系管理员");
+        }
+        List<PermissionsVO> permissions = identityInformation.getPermissions();
+        if (CollectionUtil.isEmpty(permissions)){
+            throw new ServiceException("请先完成认证");
+        }
+
+        SystemUser systemUser = identityInformation.getSystemUser();
+        if (systemUser == null && identityInformation.getIdentity() == 2) {
+            throw new ServiceException("管理员信息不存在");
+        }
+
+        PartyMember partyMember = identityInformation.getPartyMember();
+        if (partyMember == null && identityInformation.getIdentity() == 1) {
+            throw new ServiceException("党员信息不存在");
+        }
+        return identityInformation;
+    }
 }

--
Gitblit v1.7.1