|
@@ -1,14 +1,21 @@
|
|
|
package shop.alien.storeplatform.service.impl;
|
|
package shop.alien.storeplatform.service.impl;
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
+import shop.alien.entity.store.StorePlatformMenu;
|
|
|
|
|
+import shop.alien.entity.store.StorePlatformRole;
|
|
|
import shop.alien.entity.store.StorePlatformUserRole;
|
|
import shop.alien.entity.store.StorePlatformUserRole;
|
|
|
import shop.alien.entity.store.StoreUser;
|
|
import shop.alien.entity.store.StoreUser;
|
|
|
|
|
+import shop.alien.entity.store.vo.PermissionItemVo;
|
|
|
|
|
+import shop.alien.entity.store.vo.SubAccountDetailVo;
|
|
|
import shop.alien.entity.store.vo.SubAccountVo;
|
|
import shop.alien.entity.store.vo.SubAccountVo;
|
|
|
|
|
+import shop.alien.mapper.StorePlatformMenuMapper;
|
|
|
|
|
+import shop.alien.mapper.StorePlatformRoleMapper;
|
|
|
import shop.alien.mapper.StorePlatformUserRoleMapper;
|
|
import shop.alien.mapper.StorePlatformUserRoleMapper;
|
|
|
import shop.alien.mapper.StoreUserMapper;
|
|
import shop.alien.mapper.StoreUserMapper;
|
|
|
import shop.alien.storeplatform.service.StorePlatformRoleMenuService;
|
|
import shop.alien.storeplatform.service.StorePlatformRoleMenuService;
|
|
@@ -34,6 +41,8 @@ public class StorePlatformUserRoleServiceImpl extends ServiceImpl<StorePlatformU
|
|
|
private final StorePlatformUserRoleMapper storePlatformUserRoleMapper;
|
|
private final StorePlatformUserRoleMapper storePlatformUserRoleMapper;
|
|
|
private final StoreUserMapper storeUserMapper;
|
|
private final StoreUserMapper storeUserMapper;
|
|
|
private final StorePlatformRoleMenuService storePlatformRoleMenuService;
|
|
private final StorePlatformRoleMenuService storePlatformRoleMenuService;
|
|
|
|
|
+ private final StorePlatformRoleMapper storePlatformRoleMapper;
|
|
|
|
|
+ private final StorePlatformMenuMapper storePlatformMenuMapper;
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public List<Long> getRoleIdsByUserId(Integer userId, Integer storeId) {
|
|
public List<Long> getRoleIdsByUserId(Integer userId, Integer storeId) {
|
|
@@ -84,11 +93,13 @@ public class StorePlatformUserRoleServiceImpl extends ServiceImpl<StorePlatformU
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public boolean removeRole(Integer userId, Long roleId, Integer storeId) {
|
|
public boolean removeRole(Integer userId, Long roleId, Integer storeId) {
|
|
|
- LambdaQueryWrapper<StorePlatformUserRole> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
- queryWrapper.eq(StorePlatformUserRole::getUserId, userId)
|
|
|
|
|
|
|
+ // 逻辑删除
|
|
|
|
|
+ LambdaUpdateWrapper<StorePlatformUserRole> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
|
+ updateWrapper.eq(StorePlatformUserRole::getUserId, userId)
|
|
|
.eq(StorePlatformUserRole::getRoleId, roleId)
|
|
.eq(StorePlatformUserRole::getRoleId, roleId)
|
|
|
- .eq(StorePlatformUserRole::getStoreId, storeId);
|
|
|
|
|
- return storePlatformUserRoleMapper.delete(queryWrapper) > 0;
|
|
|
|
|
|
|
+ .eq(StorePlatformUserRole::getStoreId, storeId)
|
|
|
|
|
+ .set(StorePlatformUserRole::getDeleteFlag, 1); // 1代表删除
|
|
|
|
|
+ return storePlatformUserRoleMapper.update(null, updateWrapper) > 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -195,5 +206,111 @@ public class StorePlatformUserRoleServiceImpl extends ServiceImpl<StorePlatformU
|
|
|
return new ArrayList<>();
|
|
return new ArrayList<>();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public SubAccountDetailVo getSubAccountDetail(Integer userId, Integer storeId) {
|
|
|
|
|
+ if (userId == null || storeId == null) {
|
|
|
|
|
+ log.error("用户ID或店铺ID不能为空: userId={}, storeId={}", userId, storeId);
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ SubAccountDetailVo detailVo = new SubAccountDetailVo();
|
|
|
|
|
+ detailVo.setUserId(userId);
|
|
|
|
|
+
|
|
|
|
|
+ // 1. 查询用户基本信息
|
|
|
|
|
+ StoreUser storeUser = storeUserMapper.selectById(userId);
|
|
|
|
|
+ if (storeUser == null) {
|
|
|
|
|
+ log.error("用户不存在: userId={}", userId);
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 设置账号名称(优先使用 name,否则使用 nick_name)
|
|
|
|
|
+ String accountName = storeUser.getName();
|
|
|
|
|
+ if (accountName == null || accountName.isEmpty()) {
|
|
|
|
|
+ accountName = storeUser.getNickName();
|
|
|
|
|
+ }
|
|
|
|
|
+ detailVo.setAccountName(accountName);
|
|
|
|
|
+ detailVo.setPhone(storeUser.getPhone());
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 查询用户角色关联(根据userId和storeId查询)
|
|
|
|
|
+ LambdaQueryWrapper<StorePlatformUserRole> userRoleQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ userRoleQueryWrapper.eq(StorePlatformUserRole::getUserId, userId)
|
|
|
|
|
+ .eq(StorePlatformUserRole::getStoreId, storeId);
|
|
|
|
|
+ StorePlatformUserRole userRole = storePlatformUserRoleMapper.selectOne(userRoleQueryWrapper);
|
|
|
|
|
+
|
|
|
|
|
+ if (userRole != null && userRole.getRoleId() != null) {
|
|
|
|
|
+ Long roleId = userRole.getRoleId();
|
|
|
|
|
+ detailVo.setRoleId(roleId);
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 查询角色信息
|
|
|
|
|
+ StorePlatformRole role = storePlatformRoleMapper.selectById(roleId);
|
|
|
|
|
+ if (role != null) {
|
|
|
|
|
+ detailVo.setRoleName(role.getRoleName());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 查询权限列表(菜单列表)
|
|
|
|
|
+ List<Long> menuIds = storePlatformRoleMenuService.getMenuIdsByRoleId(roleId);
|
|
|
|
|
+ if (menuIds != null && !menuIds.isEmpty()) {
|
|
|
|
|
+ LambdaQueryWrapper<StorePlatformMenu> menuQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ menuQueryWrapper.in(StorePlatformMenu::getMenuId, menuIds);
|
|
|
|
|
+ menuQueryWrapper.eq(StorePlatformMenu::getDelFlag, "0");
|
|
|
|
|
+ menuQueryWrapper.eq(StorePlatformMenu::getStatus, "0");
|
|
|
|
|
+ menuQueryWrapper.orderByAsc(StorePlatformMenu::getMenuSort);
|
|
|
|
|
+ List<StorePlatformMenu> menus = storePlatformMenuMapper.selectList(menuQueryWrapper);
|
|
|
|
|
+
|
|
|
|
|
+ // 转换为权限项VO列表
|
|
|
|
|
+ List<PermissionItemVo> permissionList = menus.stream()
|
|
|
|
|
+ .map(menu -> {
|
|
|
|
|
+ PermissionItemVo permissionItem = new PermissionItemVo();
|
|
|
|
|
+ permissionItem.setPermissionId(menu.getMenuId());
|
|
|
|
|
+ permissionItem.setPermissionName(menu.getMenuName());
|
|
|
|
|
+ return permissionItem;
|
|
|
|
|
+ })
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ detailVo.setPermissions(permissionList);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ detailVo.setPermissions(new ArrayList<>());
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 如果没有角色,设置为空
|
|
|
|
|
+ detailVo.setRoleId(null);
|
|
|
|
|
+ detailVo.setRoleName(null);
|
|
|
|
|
+ detailVo.setPermissions(new ArrayList<>());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return detailVo;
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("查询子账号详情失败: userId={}, storeId={}", userId, storeId, e);
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public boolean batchDeleteSubAccounts(List<Integer> userIds, Integer storeId) {
|
|
|
|
|
+ if (userIds == null || userIds.isEmpty()) {
|
|
|
|
|
+ log.error("用户ID列表不能为空");
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (storeId == null) {
|
|
|
|
|
+ log.error("店铺ID不能为空");
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 批量逻辑删除用户角色关联关系
|
|
|
|
|
+ LambdaUpdateWrapper<StorePlatformUserRole> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
|
+ updateWrapper.eq(StorePlatformUserRole::getStoreId, storeId)
|
|
|
|
|
+ .in(StorePlatformUserRole::getUserId, userIds)
|
|
|
|
|
+ .set(StorePlatformUserRole::getDeleteFlag, 1); // 1代表删除
|
|
|
|
|
+
|
|
|
|
|
+ int result = storePlatformUserRoleMapper.update(null, updateWrapper);
|
|
|
|
|
+ log.info("批量删除子账号成功: storeId={}, userIds={}, 删除数量={}", storeId, userIds, result);
|
|
|
|
|
+ return result > 0;
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("批量删除子账号失败: storeId={}, userIds={}", storeId, userIds, e);
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|