From b3221701c387ab536adf66cf315c75d3b429fe04 Mon Sep 17 00:00:00 2001
From: 刘帅 <rr.iii@qq.com>
Date: 星期四, 17 九月 2026 09:38:06 +0800
Subject: [PATCH] feat&bug:文档问题修改及优化
---
cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/system/UserMgrController.java | 23 +++++++++++++++++------
1 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/system/UserMgrController.java b/cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/system/UserMgrController.java
index 373d8b5..098a65a 100644
--- a/cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/system/UserMgrController.java
+++ b/cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/system/UserMgrController.java
@@ -1,6 +1,7 @@
package com.dsh.guns.modular.system.controller.system;
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.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -331,6 +332,7 @@
@BussinessLog(value = "添加管理员", key = "account", dict = UserDict.class)
@Permission(Const.ADMIN_NAME)
@ResponseBody
+ @Transactional(rollbackFor = Exception.class)
public Object add(@Valid UserDto user, BindingResult result) {
if (result.hasErrors()) {
throw new GunsException(BizExceptionEnum.REQUEST_NULL);
@@ -340,7 +342,10 @@
if (StringUtils.isEmpty(user.getPhone())) {
return 5002;
}
- User theUser = userService.getOne(new QueryWrapper<User>().eq("phone", user.getPhone()));
+ // 已逻辑删除的员工(status=3)不占用手机号,可用同一手机号重新创建员工。
+ User theUser = userService.getOne(new QueryWrapper<User>()
+ .eq("phone", user.getPhone())
+ .ne("status", ManagerStatus.DELETED.getCode()));
if (theUser != null || userService.getByAccount(user.getPhone()) != null){
return 5001;
}
@@ -404,8 +409,7 @@
objectUser.setVersion(UserExt.getUser().getId());
this.userService.save(objectUser);
if (!assignedStores.isEmpty()) {
- userMapper.deleteStoreRelations(objectUser.getId());
- userMapper.insertStoreRelations(objectUser.getId(), assignedStores.stream().map(TStore::getId).collect(Collectors.toList()));
+ replaceStoreRelations(objectUser.getId(), assignedStores);
// 各所选门店同步负责人账号;旧系统仍可通过 storeStaffId 查询主负责人。
for (TStore store : assignedStores) {
store.setStoreStaffId(objectUser.getId());
@@ -433,7 +437,7 @@
if (user.getPhone() != null && user.getPhone().contains("*")) {
// The edit view displays a masked phone. Treat an unchanged masked
// value as "keep original", never as a value to persist.
- } else if (!oldUser.getPhone().equals(user.getPhone())){
+ } else if (!Objects.equals(oldUser.getPhone(), user.getPhone())) {
User phone = userService.getOne(new QueryWrapper<User>().eq("phone", user.getPhone()));
if (phone == null){
oldUser.setPhone(user.getPhone());
@@ -452,12 +456,11 @@
if (user.getStoreIds() != null) {
List<TStore> assignedStores = validateStores(user.getStoreIds());
if (assignedStores == null) return ResultUtil.error("所选门店不存在、已停用或不在当前账号管理范围内");
- userMapper.deleteStoreRelations(oldUser.getId());
+ replaceStoreRelations(oldUser.getId(), assignedStores);
if (!assignedStores.isEmpty()) {
oldUser.setObjectType(3);
oldUser.setObjectId(assignedStores.get(0).getId());
oldUser.setRoleid("3");
- userMapper.insertStoreRelations(oldUser.getId(), assignedStores.stream().map(TStore::getId).collect(Collectors.toList()));
for (TStore store : assignedStores) {
store.setStoreStaffId(oldUser.getId());
storeService.updateById(store);
@@ -498,6 +501,14 @@
return stores;
}
+ /** 每条关联记录单独生成雪花主键,避免 MyBatis foreach 复用同一个绑定变量。 */
+ private void replaceStoreRelations(Integer userId, List<TStore> stores) {
+ userMapper.deleteStoreRelations(userId);
+ for (TStore store : stores) {
+ userMapper.insertStoreRelation(IdWorker.getId(), userId, store.getId());
+ }
+ }
+
/**
* 删除管理员(逻辑删除)
* Delete administrator (logical deletion)
--
Gitblit v1.7.1