pull/1121/head
parent
b2b60f6e38
commit
be232d5d37
|
|
@ -19,10 +19,7 @@ import com.ruoyi.framework.web.service.TokenService;
|
|||
import com.ruoyi.system.service.ISysMenuService;
|
||||
import com.ruoyi.system.service.ISysRoleService;
|
||||
import com.ruoyi.system.service.ISysUserService;
|
||||
import com.ruoyi.web.controller.system.vo.BatchOptStatusVO;
|
||||
import com.ruoyi.web.controller.system.vo.RoleInfoEditByStoreVO;
|
||||
import com.ruoyi.web.controller.system.vo.RoleListItemVO;
|
||||
import com.ruoyi.web.controller.system.vo.RoleQueryVO;
|
||||
import com.ruoyi.web.controller.system.vo.*;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
|
@ -145,4 +142,30 @@ public class StoreRoleController extends XktBaseController {
|
|||
return R.ok(scope.getCount());
|
||||
}
|
||||
|
||||
// @PreAuthorize("@ss.hasAnyRoles('store')")
|
||||
// @Log(title = "角色管理", businessType = BusinessType.UPDATE)
|
||||
// @ApiOperation("授权角色 - 档口")
|
||||
// @PostMapping("/bindUser")
|
||||
public R<Integer> bindUser(@Validated @RequestBody UserRoleBindReqVO vo) {
|
||||
RoleInfo info = roleService.getRoleById(vo.getRoleId());
|
||||
Assert.isTrue(Objects.equals(info.getStoreId(), SecurityUtils.getStoreId()), "档口ID不匹配");
|
||||
int count = roleService.bindUser(vo.getRoleId(), vo.getUserIds());
|
||||
// 清除用户缓存(退出登录)
|
||||
tokenService.deleteCacheUser(vo.getUserIds());
|
||||
return R.ok(count);
|
||||
}
|
||||
|
||||
// @PreAuthorize("@ss.hasAnyRoles('store')")
|
||||
// @Log(title = "角色管理", businessType = BusinessType.UPDATE)
|
||||
// @ApiOperation("取消授权角色 - 档口")
|
||||
// @PostMapping("/unbindUser")
|
||||
public R<Integer> unbindUser(@Validated @RequestBody UserRoleBindReqVO vo) {
|
||||
RoleInfo info = roleService.getRoleById(vo.getRoleId());
|
||||
Assert.isTrue(Objects.equals(info.getStoreId(), SecurityUtils.getStoreId()), "档口ID不匹配");
|
||||
int count = roleService.unbindUser(vo.getRoleId(), vo.getUserIds());
|
||||
// 清除用户缓存(退出登录)
|
||||
tokenService.deleteCacheUser(vo.getUserIds());
|
||||
return R.ok(count);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -135,4 +135,26 @@ public class SysRoleController extends XktBaseController {
|
|||
return R.ok(scope.getCount());
|
||||
}
|
||||
|
||||
// @PreAuthorize("@ss.hasAnyRoles('admin,general_admin')")
|
||||
// @Log(title = "角色管理", businessType = BusinessType.UPDATE)
|
||||
// @ApiOperation("授权角色 - 管理员")
|
||||
// @PostMapping("/bindUser")
|
||||
public R<Integer> bindUser(@Validated @RequestBody UserRoleBindReqVO vo) {
|
||||
int count = roleService.bindUser(vo.getRoleId(), vo.getUserIds());
|
||||
// 清除用户缓存(退出登录)
|
||||
tokenService.deleteCacheUser(vo.getUserIds());
|
||||
return R.ok(count);
|
||||
}
|
||||
|
||||
// @PreAuthorize("@ss.hasAnyRoles('admin,general_admin')")
|
||||
// @Log(title = "角色管理", businessType = BusinessType.UPDATE)
|
||||
// @ApiOperation("取消授权角色 - 管理员")
|
||||
// @PostMapping("/unbindUser")
|
||||
public R<Integer> unbindUser(@Validated @RequestBody UserRoleBindReqVO vo) {
|
||||
int count = roleService.unbindUser(vo.getRoleId(), vo.getUserIds());
|
||||
// 清除用户缓存(退出登录)
|
||||
tokenService.deleteCacheUser(vo.getUserIds());
|
||||
return R.ok(count);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
package com.ruoyi.web.controller.system.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author liangyq
|
||||
* @date 2025-06-25
|
||||
*/
|
||||
@ApiModel
|
||||
@Data
|
||||
public class UserRoleBindReqVO {
|
||||
|
||||
@NotNull
|
||||
@ApiModelProperty("角色ID")
|
||||
private Long roleId;
|
||||
|
||||
@NotEmpty
|
||||
@ApiModelProperty("用户ID")
|
||||
private List<Long> userIds;
|
||||
}
|
||||
|
|
@ -5,9 +5,14 @@ import cn.hutool.core.util.IdUtil;
|
|||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.core.controller.XktBaseController;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.core.domain.model.LoginUser;
|
||||
import com.ruoyi.common.core.domain.model.UserInfo;
|
||||
import com.ruoyi.common.core.page.Page;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.framework.oss.OSSClientWrapper;
|
||||
import com.ruoyi.framework.web.service.TokenService;
|
||||
import com.ruoyi.system.service.ISysUserService;
|
||||
import com.ruoyi.web.controller.xkt.vo.store.*;
|
||||
import com.ruoyi.xkt.dto.store.*;
|
||||
import com.ruoyi.xkt.service.IStoreService;
|
||||
|
|
@ -20,6 +25,7 @@ import org.springframework.web.bind.annotation.*;
|
|||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 档口Controller
|
||||
|
|
@ -34,11 +40,24 @@ import java.util.List;
|
|||
public class StoreController extends XktBaseController {
|
||||
|
||||
final IStoreService storeService;
|
||||
final ISysUserService userService;
|
||||
final TokenService tokenService;
|
||||
|
||||
@Log(title = "新增档口", businessType = BusinessType.UPDATE)
|
||||
@PostMapping
|
||||
public R<Integer> create(@Validated @RequestBody StoreCreateVO createVO) {
|
||||
return R.ok(storeService.create(BeanUtil.toBean(createVO, StoreCreateDTO.class)));
|
||||
int count = storeService.create(BeanUtil.toBean(createVO, StoreCreateDTO.class));
|
||||
if (Objects.equals(SecurityUtils.getUserId(), createVO.getUserId())) {
|
||||
// 当前登录用户关联档口:更新关联用户缓存
|
||||
LoginUser currentUser = SecurityUtils.getLoginUser();
|
||||
UserInfo currentUserInfo = userService.getUserById(createVO.getUserId());
|
||||
currentUser.updateByUser(currentUserInfo);
|
||||
tokenService.refreshToken(currentUser);
|
||||
} else {
|
||||
// 非当前登录用户关联档口:删除关联用户缓存
|
||||
tokenService.deleteCacheUser(createVO.getUserId());
|
||||
}
|
||||
return R.ok(count);
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasAnyRoles('admin,general_admin,store')||@ss.hasSupplierSubRole()")
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
package com.ruoyi.common.core.domain.model;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
|
|
@ -286,6 +288,18 @@ public class LoginUser implements UserDetails
|
|||
this.user = user;
|
||||
}
|
||||
|
||||
public void updateByUser(UserInfo user) {
|
||||
Assert.notNull(user);
|
||||
Assert.isTrue(Objects.equals(this.userId, user.getUserId()));
|
||||
for (RoleInfo roleInfo : CollUtil.emptyIfNull(user.getRoles())) {
|
||||
if (roleInfo.getRoleId().equals(this.currentRoleId)) {
|
||||
this.currentStoreId = roleInfo.getRelStoreId();
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.user = UserExt.create(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<? extends GrantedAuthority> getAuthorities()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -69,6 +69,14 @@ public interface SysUserRoleMapper {
|
|||
*/
|
||||
List<Long> listRelUserId(@Param("roleId") Long roleId);
|
||||
|
||||
/**
|
||||
* 获取用户关联角色ID
|
||||
*
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
List<Long> listRelRoleId(@Param("userId") Long userId);
|
||||
|
||||
/**
|
||||
* 获取角色选择列表
|
||||
*
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.ruoyi.system.service;
|
|||
|
||||
import com.ruoyi.common.core.domain.model.*;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
|
@ -90,4 +91,23 @@ public interface ISysRoleService {
|
|||
* @return
|
||||
*/
|
||||
Set<Long> getSubRoleIdsByStore(Long storeId);
|
||||
|
||||
/**
|
||||
* 角色用户绑定
|
||||
*
|
||||
* @param roleId
|
||||
* @param userIds
|
||||
* @return
|
||||
*/
|
||||
int bindUser(Long roleId, Collection<Long> userIds);
|
||||
|
||||
/**
|
||||
* 角色用户解绑
|
||||
*
|
||||
* @param roleId
|
||||
* @param userIds
|
||||
* @return
|
||||
*/
|
||||
int unbindUser(Long roleId, Collection<Long> userIds);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -162,4 +162,12 @@ public interface ISysUserService {
|
|||
* @return 结果
|
||||
*/
|
||||
public String importUser(List<SysUser> userList, Boolean isUpdateSupport, String operName);
|
||||
|
||||
/**
|
||||
* 更新关联档口ID
|
||||
*
|
||||
* @param userId
|
||||
* @param roleId
|
||||
*/
|
||||
void refreshRelStore(Long userId, Long roleId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
|
|||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.ruoyi.common.constant.Constants;
|
||||
|
|
@ -11,10 +12,13 @@ import com.ruoyi.common.core.domain.entity.SysRole;
|
|||
import com.ruoyi.common.core.domain.model.*;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.common.utils.bean.BeanValidators;
|
||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||
import com.ruoyi.system.domain.SysRoleMenu;
|
||||
import com.ruoyi.system.domain.SysUserRole;
|
||||
import com.ruoyi.system.mapper.SysRoleMapper;
|
||||
import com.ruoyi.system.mapper.SysRoleMenuMapper;
|
||||
import com.ruoyi.system.mapper.SysUserMapper;
|
||||
import com.ruoyi.system.mapper.SysUserRoleMapper;
|
||||
import com.ruoyi.system.service.ISysRoleService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
|
@ -36,6 +40,7 @@ public class SysRoleServiceImpl implements ISysRoleService {
|
|||
final SysRoleMapper roleMapper;
|
||||
final SysRoleMenuMapper roleMenuMapper;
|
||||
final SysUserRoleMapper userRoleMapper;
|
||||
final SysUserMapper userMapper;
|
||||
|
||||
@Override
|
||||
public RoleInfo getRoleById(Long roleId) {
|
||||
|
|
@ -166,6 +171,45 @@ public class SysRoleServiceImpl implements ISysRoleService {
|
|||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public int bindUser(Long roleId, Collection<Long> userIds) {
|
||||
SysRole role = roleMapper.selectById(roleId);
|
||||
Assert.isTrue(BeanValidators.exists(role));
|
||||
Assert.notEmpty(userIds);
|
||||
List<SysUserRole> urs;
|
||||
if (ESystemRole.SUPPLIER.getId().equals(roleId)) {
|
||||
//档口供应商
|
||||
urs = userIds.stream().map(userId -> {
|
||||
Long storeId = userMapper.getManageStoreId(userId);
|
||||
SysUserRole ur = new SysUserRole();
|
||||
ur.setUserId(userId);
|
||||
ur.setRoleId(roleId);
|
||||
ur.setStoreId(storeId);
|
||||
return ur;
|
||||
}).collect(Collectors.toList());
|
||||
} else {
|
||||
Long storeId = role.getStoreId();
|
||||
urs = userIds.stream().map(userId -> {
|
||||
SysUserRole ur = new SysUserRole();
|
||||
ur.setUserId(userId);
|
||||
ur.setRoleId(roleId);
|
||||
ur.setStoreId(storeId);
|
||||
return ur;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
//TODO 用户只能关联一个系统角色,只有电商卖家才能关联档口子角色
|
||||
return userRoleMapper.batchUserRole(urs);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public int unbindUser(Long roleId, Collection<Long> userIds) {
|
||||
Assert.notNull(roleId);
|
||||
Assert.notEmpty(userIds);
|
||||
return userRoleMapper.deleteUserRoleInfos(roleId, ArrayUtil.toArray(userIds, Long.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增角色菜单信息
|
||||
*
|
||||
|
|
|
|||
|
|
@ -405,6 +405,29 @@ public class SysUserServiceImpl implements ISysUserService {
|
|||
return successMsg.toString();
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void refreshRelStore(Long userId, Long roleId) {
|
||||
Assert.notNull(userId);
|
||||
Assert.notNull(roleId);
|
||||
Long storeId;
|
||||
if (ESystemRole.SUPPLIER.getId().equals(roleId)) {
|
||||
storeId = userMapper.getManageStoreId(userId);
|
||||
} else {
|
||||
SysRole role = roleMapper.selectById(roleId);
|
||||
storeId = Optional.ofNullable(role).map(SysRole::getStoreId).orElse(null);
|
||||
}
|
||||
userRoleMapper.deleteUserRoleInfos(roleId, new Long[]{userId});
|
||||
SysUserRole ur = new SysUserRole();
|
||||
ur.setUserId(userId);
|
||||
ur.setRoleId(roleId);
|
||||
ur.setStoreId(storeId);
|
||||
userRoleMapper.batchUserRole(Collections.singletonList(ur));
|
||||
// 检查用户的角色是否合规
|
||||
List<Long> roleIds = userRoleMapper.listRelRoleId(userId);
|
||||
checkRoles(roleIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增用户
|
||||
*
|
||||
|
|
|
|||
|
|
@ -25,6 +25,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
WHERE
|
||||
sur.role_id = #{roleId}
|
||||
</select>
|
||||
<select id="listRelRoleId" resultType="java.lang.Long">
|
||||
SELECT DISTINCT
|
||||
sur.role_id
|
||||
FROM
|
||||
sys_user_role sur
|
||||
WHERE
|
||||
sur.user_id = #{userId}
|
||||
</select>
|
||||
<select id="listRoleSelectItem" resultType="com.ruoyi.common.core.domain.model.RoleSelectItem">
|
||||
SELECT
|
||||
sur.role_id,
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import com.github.pagehelper.PageInfo;
|
|||
import com.ruoyi.common.constant.CacheConstants;
|
||||
import com.ruoyi.common.constant.Constants;
|
||||
import com.ruoyi.common.constant.HttpStatus;
|
||||
import com.ruoyi.common.core.domain.model.ESystemRole;
|
||||
import com.ruoyi.common.core.page.Page;
|
||||
import com.ruoyi.common.core.redis.RedisCache;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
|
|
@ -16,6 +17,7 @@ import com.ruoyi.common.utils.SecurityUtils;
|
|||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.bigDecimal.CollectorsUtil;
|
||||
import com.ruoyi.system.mapper.SysUserMapper;
|
||||
import com.ruoyi.system.service.ISysUserService;
|
||||
import com.ruoyi.xkt.domain.*;
|
||||
import com.ruoyi.xkt.dto.store.*;
|
||||
import com.ruoyi.xkt.enums.StoreStatus;
|
||||
|
|
@ -57,6 +59,7 @@ public class StoreServiceImpl implements IStoreService {
|
|||
final StoreSaleDetailMapper saleDetailMapper;
|
||||
final StoreProductMapper storeProdMapper;
|
||||
final DailySaleProductMapper dailySaleProdMapper;
|
||||
final ISysUserService userService;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -81,6 +84,8 @@ public class StoreServiceImpl implements IStoreService {
|
|||
int count = this.storeMapper.insert(store);
|
||||
// 创建档口账户
|
||||
assetService.createInternalAccountIfNotExists(store.getId());
|
||||
// 档口用户绑定
|
||||
userService.refreshRelStore(store.getUserId(), ESystemRole.SUPPLIER.getId());
|
||||
// 放到redis中
|
||||
redisCache.setCacheObject(CacheConstants.STORE_KEY + store.getId(), store.getId());
|
||||
return count;
|
||||
|
|
|
|||
Loading…
Reference in New Issue