Sfoglia il codice sorgente

商家pc端 分权限 第三笔提交

liudongzhi 3 mesi fa
parent
commit
ee6d7d5da8

+ 37 - 0
alien-entity/src/main/java/shop/alien/entity/store/vo/SubAccountVo.java

@@ -0,0 +1,37 @@
+package shop.alien.entity.store.vo;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * 子账号信息VO
+ *
+ * @author system
+ * @since 2025-01-XX
+ */
+@Data
+@JsonInclude
+@ApiModel(value = "SubAccountVo对象", description = "子账号信息VO")
+public class SubAccountVo {
+
+    @ApiModelProperty(value = "用户ID")
+    private Integer userId;
+
+    @ApiModelProperty(value = "账号名称")
+    private String accountName;
+
+    @ApiModelProperty(value = "手机号")
+    private String phone;
+
+    @ApiModelProperty(value = "角色ID")
+    private Long roleId;
+
+    @ApiModelProperty(value = "角色名称")
+    private String roleName;
+
+    @ApiModelProperty(value = "权限数量")
+    private Integer permissionCount;
+}
+

+ 17 - 0
alien-entity/src/main/java/shop/alien/mapper/StorePlatformUserRoleMapper.java

@@ -2,7 +2,11 @@ package shop.alien.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 import shop.alien.entity.store.StorePlatformUserRole;
+import shop.alien.entity.store.vo.SubAccountVo;
+
+import java.util.List;
 
 /**
  * 用户角色关联表 Mapper 接口
@@ -13,5 +17,18 @@ import shop.alien.entity.store.StorePlatformUserRole;
 @Mapper
 public interface StorePlatformUserRoleMapper extends BaseMapper<StorePlatformUserRole> {
 
+    /**
+     * 根据店铺ID查询子账号列表(连表查询)
+     *
+     * @param storeId    店铺ID
+     * @param accountName 账号名称(模糊查询)
+     * @param phone       手机号(模糊查询)
+     * @param roleName    角色名称(模糊查询)
+     * @return 子账号列表
+     */
+    List<SubAccountVo> querySubAccounts(@Param("storeId") Integer storeId,
+                                        @Param("accountName") String accountName,
+                                        @Param("phone") String phone,
+                                        @Param("roleName") String roleName);
 }
 

+ 35 - 0
alien-entity/src/main/resources/mapper/StorePlatformUserRoleMapper.xml

@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="shop.alien.mapper.StorePlatformUserRoleMapper">
+
+    <!-- 根据店铺ID查询子账号列表(连表查询) -->
+    <select id="querySubAccounts" resultType="shop.alien.entity.store.vo.SubAccountVo">
+        SELECT
+            sur.id AS userId,
+            COALESCE(sur.name, sur.nick_name) AS accountName,
+            sur.phone AS phone,
+            spr.role_id AS roleId,
+            spr.role_name AS roleName,
+            0 AS permissionCount
+        FROM store_platform_user_role spur
+        INNER JOIN store_user sur ON spur.user_id = sur.id
+        LEFT JOIN store_platform_role spr ON spur.role_id = spr.role_id
+        WHERE spur.store_id = #{storeId}
+          AND sur.account_type = 2
+          AND sur.delete_flag = 0
+        <if test="accountName != null and accountName != ''">
+            AND (sur.name LIKE CONCAT('%', #{accountName}, '%') OR sur.nick_name LIKE CONCAT('%', #{accountName}, '%'))
+        </if>
+        <if test="phone != null and phone != ''">
+            AND sur.phone LIKE CONCAT('%', #{phone}, '%')
+        </if>
+        <if test="roleName != null and roleName != ''">
+            AND spr.role_name LIKE CONCAT('%', #{roleName}, '%')
+        </if>
+        ORDER BY spur.created_time DESC
+    </select>
+
+</mapper>
+

+ 22 - 34
alien-store-platform/src/main/java/shop/alien/storeplatform/controller/StorePlatformUserRoleController.java

@@ -1,11 +1,13 @@
 package shop.alien.storeplatform.controller;
 
 import io.swagger.annotations.*;
-import lombok.Data;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.web.bind.annotation.*;
 import shop.alien.entity.result.R;
+import shop.alien.entity.store.vo.SubAccountVo;
+import shop.alien.storeplatform.dto.AssignRolesDto;
+import shop.alien.storeplatform.dto.CreateAccountDto;
 import shop.alien.storeplatform.service.StorePlatformUserRoleService;
 
 import java.util.List;
@@ -116,39 +118,25 @@ public class StorePlatformUserRoleController {
         return R.fail("创建账号并分配角色失败");
     }
 
-    /**
-     * 分配角色请求DTO
-     */
-    @Data
-    @ApiModel(value = "AssignRolesDto", description = "分配角色请求参数")
-    static class AssignRolesDto {
-        @ApiModelProperty(value = "用户ID", required = true)
-        private Integer userId;
-
-        @ApiModelProperty(value = "角色ID列表", required = true)
-        private List<Long> roleIds;
-
-        @ApiModelProperty(value = "店铺ID", required = true)
-        private Integer storeId;
-    }
-
-    /**
-     * 创建账号请求DTO
-     */
-    @Data
-    @ApiModel(value = "CreateAccountDto", description = "创建账号请求参数")
-    static class CreateAccountDto {
-        @ApiModelProperty(value = "手机号", required = true)
-        private String phone;
-
-        @ApiModelProperty(value = "账号名称")
-        private String accountName;
-
-        @ApiModelProperty(value = "店铺ID", required = true)
-        private Integer storeId;
-
-        @ApiModelProperty(value = "角色ID", required = true)
-        private Long roleId;
+    @ApiOperation("查询当前店铺下的子账号列表")
+    @ApiOperationSupport(order = 7)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "storeId", value = "店铺ID", dataType = "int", paramType = "query", required = true),
+            @ApiImplicitParam(name = "accountName", value = "账号名称(模糊查询)", dataType = "String", paramType = "query", required = false),
+            @ApiImplicitParam(name = "phone", value = "手机号(模糊查询)", dataType = "String", paramType = "query", required = false),
+            @ApiImplicitParam(name = "roleName", value = "角色名称(模糊查询)", dataType = "String", paramType = "query", required = false)
+    })
+    @GetMapping("/querySubAccounts")
+    public R<List<SubAccountVo>> querySubAccounts(
+            @RequestParam("storeId") Integer storeId,
+            @RequestParam(value = "accountName", required = false) String accountName,
+            @RequestParam(value = "phone", required = false) String phone,
+            @RequestParam(value = "roleName", required = false) String roleName) {
+        log.info("StorePlatformUserRoleController.querySubAccounts?storeId={}, accountName={}, phone={}, roleName={}", 
+                storeId, accountName, phone, roleName);
+        List<SubAccountVo> subAccountList = storePlatformUserRoleService.querySubAccounts(
+                storeId, accountName, phone, roleName);
+        return R.data(subAccountList);
     }
 }
 

+ 28 - 0
alien-store-platform/src/main/java/shop/alien/storeplatform/dto/AssignRolesDto.java

@@ -0,0 +1,28 @@
+package shop.alien.storeplatform.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * 分配角色请求DTO
+ *
+ * @author system
+ * @since 2025-01-XX
+ */
+@Data
+@ApiModel(value = "AssignRolesDto", description = "分配角色请求参数")
+public class AssignRolesDto {
+
+    @ApiModelProperty(value = "用户ID", required = true)
+    private Integer userId;
+
+    @ApiModelProperty(value = "角色ID列表", required = true)
+    private List<Long> roleIds;
+
+    @ApiModelProperty(value = "店铺ID", required = true)
+    private Integer storeId;
+}
+

+ 29 - 0
alien-store-platform/src/main/java/shop/alien/storeplatform/dto/CreateAccountDto.java

@@ -0,0 +1,29 @@
+package shop.alien.storeplatform.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * 创建账号请求DTO
+ *
+ * @author system
+ * @since 2025-01-XX
+ */
+@Data
+@ApiModel(value = "CreateAccountDto", description = "创建账号请求参数")
+public class CreateAccountDto {
+
+    @ApiModelProperty(value = "手机号", required = true)
+    private String phone;
+
+    @ApiModelProperty(value = "账号名称")
+    private String accountName;
+
+    @ApiModelProperty(value = "店铺ID", required = true)
+    private Integer storeId;
+
+    @ApiModelProperty(value = "角色ID", required = true)
+    private Long roleId;
+}
+

+ 29 - 0
alien-store-platform/src/main/java/shop/alien/storeplatform/dto/QuerySubAccountDto.java

@@ -0,0 +1,29 @@
+package shop.alien.storeplatform.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * 查询子账号请求DTO
+ *
+ * @author system
+ * @since 2025-01-XX
+ */
+@Data
+@ApiModel(value = "QuerySubAccountDto", description = "查询子账号请求参数")
+public class QuerySubAccountDto {
+
+    @ApiModelProperty(value = "店铺ID", required = true)
+    private Integer storeId;
+
+    @ApiModelProperty(value = "账号名称(模糊查询)")
+    private String accountName;
+
+    @ApiModelProperty(value = "手机号(模糊查询)")
+    private String phone;
+
+    @ApiModelProperty(value = "角色名称(模糊查询)")
+    private String roleName;
+}
+

+ 15 - 0
alien-store-platform/src/main/java/shop/alien/storeplatform/service/StorePlatformUserRoleService.java

@@ -2,6 +2,7 @@ package shop.alien.storeplatform.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import shop.alien.entity.store.StorePlatformUserRole;
+import shop.alien.entity.store.vo.SubAccountVo;
 
 import java.util.List;
 
@@ -72,5 +73,19 @@ public interface StorePlatformUserRoleService extends IService<StorePlatformUser
      * @return 是否成功
      */
     boolean createAccountAndAssignRole(String phone, String accountName, Integer storeId, Long roleId);
+
+    /**
+     * 查询当前店铺下的子账号列表
+     * 根据店铺ID查询 store_platform_user_role 表连表 store_user 和 store_platform_role
+     * 支持根据账号名称、手机号、角色名称进行模糊查询
+     * 并计算每个子账号的权限数量
+     *
+     * @param storeId    店铺ID
+     * @param accountName 账号名称(模糊查询)
+     * @param phone       手机号(模糊查询)
+     * @param roleName    角色名称(模糊查询)
+     * @return 子账号列表
+     */
+    List<SubAccountVo> querySubAccounts(Integer storeId, String accountName, String phone, String roleName);
 }
 

+ 38 - 2
alien-store-platform/src/main/java/shop/alien/storeplatform/service/impl/StorePlatformUserRoleServiceImpl.java

@@ -8,10 +8,13 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import shop.alien.entity.store.StorePlatformUserRole;
 import shop.alien.entity.store.StoreUser;
+import shop.alien.entity.store.vo.SubAccountVo;
 import shop.alien.mapper.StorePlatformUserRoleMapper;
 import shop.alien.mapper.StoreUserMapper;
+import shop.alien.storeplatform.service.StorePlatformRoleMenuService;
 import shop.alien.storeplatform.service.StorePlatformUserRoleService;
 
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.stream.Collectors;
@@ -30,6 +33,7 @@ public class StorePlatformUserRoleServiceImpl extends ServiceImpl<StorePlatformU
 
     private final StorePlatformUserRoleMapper storePlatformUserRoleMapper;
     private final StoreUserMapper storeUserMapper;
+    private final StorePlatformRoleMenuService storePlatformRoleMenuService;
 
     @Override
     public List<Long> getRoleIdsByUserId(Integer userId, Integer storeId) {
@@ -106,13 +110,15 @@ public class StorePlatformUserRoleServiceImpl extends ServiceImpl<StorePlatformU
                 StoreUser newUser = new StoreUser();
                 newUser.setPhone(phone);
                 newUser.setName(accountName != null ? accountName : phone);
-                newUser.setStoreId(storeId);
+//                newUser.setStoreId(storeId);
                 newUser.setStatus(0); // 0:启用
                 newUser.setDeleteFlag(0); // 0:未删除
                 newUser.setMoney(0);
 //                newUser.setPassType(0); // 0:初始密码
                 newUser.setLogoutFlag(0); // 0:未注销
-                newUser.setAlipayAccount("2");
+                newUser.setAccountType(2);
+                newUser.setPassType(0);
+                newUser.setPassword("");
                 newUser.setNickName(accountName != null ? accountName : phone);
                 newUser.setCreatedTime(new Date());
                 
@@ -159,5 +165,35 @@ public class StorePlatformUserRoleServiceImpl extends ServiceImpl<StorePlatformU
             return false;
         }
     }
+
+    @Override
+    public List<SubAccountVo> querySubAccounts(Integer storeId, String accountName, String phone, String roleName) {
+        if (storeId == null) {
+            log.error("店铺ID不能为空");
+            return new ArrayList<>();
+        }
+
+        try {
+            // 查询子账号列表
+            List<SubAccountVo> subAccountList = storePlatformUserRoleMapper.querySubAccounts(
+                    storeId, accountName, phone, roleName);
+
+            // 计算每个子账号的权限数量
+            subAccountList.forEach(subAccount -> {
+                if (subAccount.getRoleId() != null) {
+                    List<Long> menuIds = storePlatformRoleMenuService.getMenuIdsByRoleId(subAccount.getRoleId());
+                    subAccount.setPermissionCount(menuIds != null ? menuIds.size() : 0);
+                } else {
+                    subAccount.setPermissionCount(0);
+                }
+            });
+
+            return subAccountList;
+        } catch (Exception e) {
+            log.error("查询子账号列表失败: storeId={}, accountName={}, phone={}, roleName={}", 
+                    storeId, accountName, phone, roleName, e);
+            return new ArrayList<>();
+        }
+    }
 }