刘帅
2026-09-21 7a8af8c19b40b8028e25ee0b669463d06f723a30
cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/system/UserMgrController.java
@@ -3,7 +3,6 @@
import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dsh.course.mapper.UserMapper;
@@ -411,7 +410,6 @@
        this.userService.save(objectUser);
        if (!assignedStores.isEmpty()) {
            replaceStoreRelations(objectUser.getId(), assignedStores);
            syncStoreManagers(objectUser, Collections.<Integer>emptyList(), assignedStores);
        }
        return SUCCESS_TIP;
    }
@@ -451,7 +449,6 @@
        if (user.getAvatar()!=null && (!user.getAvatar().equals("")))
        oldUser.setAvatar(user.getAvatar());
        if (user.getStoreIds() != null) {
            List<Integer> previousStoreIds = userMapper.getStoreIdsByUserId(oldUser.getId());
            List<TStore> assignedStores = validateStores(user.getStoreIds());
            if (assignedStores == null) return ResultUtil.error("所选门店不存在、已停用或不在当前账号管理范围内");
            replaceStoreRelations(oldUser.getId(), assignedStores);
@@ -463,16 +460,8 @@
                // 清除旧字段关联,避免已移除的首个门店仍被当作该员工所属门店。
                oldUser.setObjectId(null);
            }
            syncStoreManagers(oldUser, previousStoreIds, assignedStores);
        }
        this.userService.updateById(oldUser);
        // 门店表仅保存店长 ID 和联系电话;店长名称由 storeStaffId 关联 sys_user.name 展示。
        // 员工资料修改但门店未修改时,也要将其手机号同步给当前负责的门店。
        if (user.getStoreIds() == null) {
            storeService.update(new LambdaUpdateWrapper<TStore>()
                    .eq(TStore::getStoreStaffId, oldUser.getId())
                    .set(TStore::getPhone, oldUser.getPhone()));
        }
        return SUCCESS_TIP;
    }
@@ -511,32 +500,6 @@
        userMapper.deleteStoreRelations(userId);
        for (TStore store : stores) {
            userMapper.insertStoreRelation(IdWorker.getId(), userId, store.getId());
        }
    }
    /**
     * 同步员工与门店的负责人信息。门店移除时,只清理仍由该员工负责的门店,
     * 防止并发或后续操作已为门店设置新店长时被错误覆盖。
     */
    private void syncStoreManagers(User user, List<Integer> previousStoreIds, List<TStore> assignedStores) {
        Set<Integer> assignedStoreIds = assignedStores.stream()
                .map(TStore::getId)
                .collect(Collectors.toSet());
        for (Integer previousStoreId : previousStoreIds) {
            if (!assignedStoreIds.contains(previousStoreId)) {
                storeService.update(new LambdaUpdateWrapper<TStore>()
                        .eq(TStore::getId, previousStoreId)
                        .eq(TStore::getStoreStaffId, user.getId())
                        .set(TStore::getStoreStaffId, null)
                        .set(TStore::getPhone, null));
            }
        }
        for (TStore store : assignedStores) {
            store.setStoreStaffId(user.getId());
            store.setPhone(user.getPhone());
            storeService.updateById(store);
        }
    }