|
|
@@ -93,13 +93,56 @@ public class StorePlatformUserRoleServiceImpl extends ServiceImpl<StorePlatformU
|
|
|
|
|
|
@Override
|
|
|
public boolean removeRole(Integer userId, Long roleId, Integer storeId) {
|
|
|
- // 逻辑删除
|
|
|
- LambdaUpdateWrapper<StorePlatformUserRole> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
- updateWrapper.eq(StorePlatformUserRole::getUserId, userId)
|
|
|
- .eq(StorePlatformUserRole::getRoleId, roleId)
|
|
|
- .eq(StorePlatformUserRole::getStoreId, storeId)
|
|
|
- .set(StorePlatformUserRole::getDeleteFlag, 1); // 1代表删除
|
|
|
- return storePlatformUserRoleMapper.update(null, updateWrapper) > 0;
|
|
|
+ if (userId == null || roleId == null || storeId == null) {
|
|
|
+ log.error("参数不能为空: userId={}, roleId={}, storeId={}", userId, roleId, storeId);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 1. 先查询该用户在所有店铺下的子账号数量(未删除的)
|
|
|
+ LambdaQueryWrapper<StorePlatformUserRole> countWrapper = new LambdaQueryWrapper<>();
|
|
|
+ countWrapper.eq(StorePlatformUserRole::getUserId, userId)
|
|
|
+ .eq(StorePlatformUserRole::getDeleteFlag, 0);
|
|
|
+ long subAccountCount = storePlatformUserRoleMapper.selectCount(countWrapper);
|
|
|
+
|
|
|
+ log.info("用户在所有店铺下的子账号数量: userId={}, count={}", userId, subAccountCount);
|
|
|
+
|
|
|
+ // 2. 逻辑删除 store_platform_user_role 表的记录
|
|
|
+ LambdaUpdateWrapper<StorePlatformUserRole> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ updateWrapper.eq(StorePlatformUserRole::getUserId, userId)
|
|
|
+ .eq(StorePlatformUserRole::getRoleId, roleId)
|
|
|
+ .eq(StorePlatformUserRole::getStoreId, storeId)
|
|
|
+ .eq(StorePlatformUserRole::getDeleteFlag, 0)
|
|
|
+ .set(StorePlatformUserRole::getDeleteFlag, 1); // 1代表删除
|
|
|
+ int updateResult = storePlatformUserRoleMapper.update(null, updateWrapper);
|
|
|
+
|
|
|
+ if (updateResult <= 0) {
|
|
|
+ log.error("逻辑删除 store_platform_user_role 记录失败: userId={}, roleId={}, storeId={}", userId, roleId, storeId);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 如果只是一个账号的子账号(删除前只有1个),则同时逻辑删除 store_user 表
|
|
|
+ if (subAccountCount == 1) {
|
|
|
+ LambdaUpdateWrapper<StoreUser> userUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ userUpdateWrapper.eq(StoreUser::getId, userId)
|
|
|
+ .eq(StoreUser::getDeleteFlag, 0)
|
|
|
+ .set(StoreUser::getDeleteFlag, 1); // 1代表删除
|
|
|
+ int userUpdateResult = storeUserMapper.update(null, userUpdateWrapper);
|
|
|
+
|
|
|
+ if (userUpdateResult > 0) {
|
|
|
+ log.info("用户只有一个子账号,已同时逻辑删除 store_user 记录: userId={}", userId);
|
|
|
+ } else {
|
|
|
+ log.warn("逻辑删除 store_user 记录失败或记录不存在: userId={}", userId);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.info("用户有多个子账号(count={}),仅删除 store_platform_user_role 记录,不删除 store_user 记录: userId={}", subAccountCount, userId);
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("移除用户角色失败: userId={}, roleId={}, storeId={}", userId, roleId, storeId, e);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -150,6 +193,15 @@ public class StorePlatformUserRoleServiceImpl extends ServiceImpl<StorePlatformU
|
|
|
userQueryWrapper.eq(StoreUser::getPhone, phone);
|
|
|
StoreUser storeUser = storeUserMapper.selectOne(userQueryWrapper);
|
|
|
|
|
|
+ //校验添加子账号的时候如果是当前主账号的手机号,阻断
|
|
|
+ if (storeUser != null && storeUser.getStoreId() != null) {
|
|
|
+ int storeIdNew = storeUser.getStoreId();
|
|
|
+ if (storeIdNew == storeId) {
|
|
|
+ log.error("该手机号为当前当前店铺手机号,请勿重复创建: phone={}, storeId={}", phone, storeId);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
Integer userId;
|
|
|
if (storeUser == null) {
|
|
|
// 2. 如果没有数据,则插入一条数据
|