Bladeren bron

权限接口

chenxiaofei 1 maand geleden
bovenliggende
commit
642829082e

+ 12 - 0
sckw-auth/src/main/java/com/sckw/auth/model/vo/res/LoginResVo1.java

@@ -165,6 +165,18 @@ public class LoginResVo1 implements Serializable {
      */
     private List<TabBarItem> tabBar;
 
+    @Schema(description = "是否展示订单统计模块")
+    private Boolean showOrderStatisticsModule;
+
+    @Schema(description = "是否展示销售统计模块")
+    private Boolean showSalesStatisticsModule;
+
+    @Schema(description = "是否展示钱包模块")
+    private Boolean showWalletModule;
+
+    @Schema(description = "钱包模块展示项")
+    private List<String> walletModuleItems;
+
     @Data
     public static class TabBarItem implements Serializable {
         @Serial

+ 52 - 0
sckw-auth/src/main/java/com/sckw/auth/service/impl/AuthServiceImpl.java

@@ -172,6 +172,7 @@ public class AuthServiceImpl implements IAuthService {
         if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(tabBar)) {
             loginRes.setTabBar(tabBar);
         }
+        applyAppModulePermissions(loginRes, loginBase, null);
         loginRes.setRefreshToken(refreshToken);
         return HttpResult.ok(loginRes);
     }
@@ -265,6 +266,7 @@ public class AuthServiceImpl implements IAuthService {
         if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(tabBar)) {
             loginRes.setTabBar(tabBar);
         }
+        applyAppModulePermissions(loginRes, loginBase, user.getRoleName());
         if (user.getSystemType().equals(SystemTypeEnum.MANAGE.getCode())) {
             loginRes.setValid(true);
         } else {
@@ -354,6 +356,7 @@ public class AuthServiceImpl implements IAuthService {
         if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(tabBar)) {
             loginRes.setTabBar(tabBar);
         }
+        applyAppModulePermissions(loginRes, loginBase, user.getRoleName());
         if (user.getSystemType().equals(SystemTypeEnum.MANAGE.getCode())) {
             loginRes.setValid(true);
         } else {
@@ -517,6 +520,9 @@ public class AuthServiceImpl implements IAuthService {
         loginRes.setToken(token);
         loginRes.setDeptId(user.getDeptId());
         loginRes.setRoleId(user.getRoleId());
+        LoginBase loginBase = new LoginBase();
+        loginBase.setClientType(clientType);
+        applyAppModulePermissions(loginRes, loginBase, user.getRoleName());
         if (user.getSystemType().equals(SystemTypeEnum.MANAGE.getCode())) {
             loginRes.setValid(true);
         } else {
@@ -855,6 +861,7 @@ public class AuthServiceImpl implements IAuthService {
         if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(tabBar)) {
             loginRes.setTabBar(tabBar);
         }
+        applyAppModulePermissions(loginRes, loginBase, null);
         return loginRes;
     }
     
@@ -891,6 +898,7 @@ public class AuthServiceImpl implements IAuthService {
         if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(tabBar)) {
             loginRes.setTabBar(tabBar);
         }
+        applyAppModulePermissions(loginRes, loginBase, user.getRoleName());
         if (user.getSystemType().equals(SystemTypeEnum.MANAGE.getCode())) {
             loginRes.setValid(true);
         } else {
@@ -907,10 +915,54 @@ public class AuthServiceImpl implements IAuthService {
                 || Objects.equals(clientType, ClientTypeEnum.mobile.getValue());
     }
 
+    private void applyAppModulePermissions(LoginResVo1 loginRes, LoginBase loginBase, String roleName) {
+        loginRes.setShowOrderStatisticsModule(Boolean.FALSE);
+        loginRes.setShowSalesStatisticsModule(Boolean.FALSE);
+        loginRes.setShowWalletModule(Boolean.FALSE);
+        loginRes.setWalletModuleItems(Collections.emptyList());
+        if (!isAppLogin(loginBase) || StringUtils.isBlank(roleName)) {
+            return;
+        }
+        boolean isSeller = containsAnyRole(roleName, "销售");
+        boolean isFinance = containsAnyRole(roleName, "财务");
+        boolean isPurchase = containsAnyRole(roleName, "采购", "买家");
+        if (isSeller) {
+            loginRes.setShowOrderStatisticsModule(Boolean.TRUE);
+            loginRes.setShowSalesStatisticsModule(Boolean.TRUE);
+            return;
+        }
+        if (isFinance) {
+            loginRes.setShowOrderStatisticsModule(Boolean.TRUE);
+            loginRes.setShowWalletModule(Boolean.TRUE);
+            loginRes.setWalletModuleItems(Arrays.asList("PENDING_PERFORMANCE_BALANCE", "PENDING_FREIGHT"));
+            return;
+        }
+        if (isPurchase) {
+            loginRes.setShowOrderStatisticsModule(Boolean.TRUE);
+            loginRes.setShowWalletModule(Boolean.TRUE);
+            loginRes.setWalletModuleItems(Arrays.asList("PREPAY_BALANCE", "PENDING_FREIGHT"));
+        }
+    }
+
+    private boolean containsAnyRole(String roleName, String... roleKeywords) {
+        if (StringUtils.isBlank(roleName) || roleKeywords == null) {
+            return false;
+        }
+        for (String roleKeyword : roleKeywords) {
+            if (StringUtils.isNotBlank(roleKeyword) && roleName.contains(roleKeyword)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
     private List<LoginResVo1.TabBarItem> buildAppTabBar(LoginBase loginBase, String roleName,int flag) {
         if (!isAppLogin(loginBase)) {
             return List.of();
         }
+        if (containsAnyRole(roleName, "采购")) {
+            return buildBuyerTabBar();
+        }
         boolean isDoorKeeper = StringUtils.isNotBlank(roleName) && roleName.contains("门卫");
         boolean isForkliftDriver = StringUtils.isNotBlank(roleName) && roleName.contains("铲车司机");
         boolean isBuyer = StringUtils.isNotBlank(roleName) && roleName.contains("买家");