From 9bcbf4398202139b31de1df6599e362915f15682 Mon Sep 17 00:00:00 2001
From: 刘帅 <rr.iii@qq.com>
Date: 星期二, 22 九月 2026 10:05:21 +0800
Subject: [PATCH] bug:数据返回问题
---
cloud-server-management/src/main/webapp/WEB-INF/view/system/user/user_edit.html | 2
cloud-server-management/src/main/webapp/WEB-INF/view/system/user/user_view.html | 2
cloud-server-management/src/main/webapp/static/modular/system/user/user_info.js | 9 ++++
cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/system/UserMgrController.java | 33 ++++++++++++++--
cloud-server-management/src/main/webapp/WEB-INF/view/system/user/user_edit1.html | 2
cloud-server-management/src/main/resources/mapper/TStoreMapper.xml | 19 +++++++--
cloud-server-management/src/main/webapp/WEB-INF/view/system/user/user_add.html | 2
7 files changed, 56 insertions(+), 13 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 64a2b86..90bbaa7 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
@@ -153,6 +153,11 @@
User user = this.userService.getById(userId);
Role role = roleService.getById(user.getRoleid());
Dept dept = deptService.getById(user.getDeptid());
+ // 兼容历史账号:部分账号的登录手机号仅保存在 account 字段。
+ // 个人资料页必须能回显该绑定手机号,避免前端提交空值。
+ if (StringUtils.isEmpty(user.getPhone()) && !StringUtils.isEmpty(user.getAccount())) {
+ user.setPhone(user.getAccount());
+ }
user.setPhone(maskPhone(user.getPhone()));
user.setIdCard(maskIdCard(user.getIdCard()));
model.addAttribute(user);
@@ -214,6 +219,11 @@
User user = this.userService.getById(userId);
Role role = roleService.getById(user.getRoleid());
Dept dept = deptService.getById(user.getDeptid());
+ // 兼容历史账号:部分账号的登录手机号仅保存在 account 字段。
+ // 个人资料页必须能回显该绑定手机号,避免前端提交空值。
+ if (StringUtils.isEmpty(user.getPhone()) && !StringUtils.isEmpty(user.getAccount())) {
+ user.setPhone(user.getAccount());
+ }
user.setPhone(maskPhone(user.getPhone()));
user.setIdCard(maskIdCard(user.getIdCard()));
model.addAttribute(user);
@@ -434,9 +444,12 @@
}
User oldUser = userService.getById(user.getId());
// 判断是否更改电话
- if (user.getPhone() != null && user.getPhone().contains("*")) {
+ if (StringUtils.isEmpty(user.getPhone()) || user.getPhone().contains("*")) {
// The edit view displays a masked phone. Treat an unchanged masked
- // value as "keep original", never as a value to persist.
+ // value, or an omitted field, as "keep original", never as a
+ // value to persist. Some edit forms do not submit disabled or
+ // hidden fields; allowing an empty value through would erase the
+ // stored phone after deployment.
} else if (!Objects.equals(oldUser.getPhone(), user.getPhone())) {
User phone = userService.getOne(new QueryWrapper<User>().eq("phone", user.getPhone()));
if (phone == null){
@@ -448,7 +461,11 @@
oldUser.setName(user.getName());
oldUser.setBirthday(user.getBirthday());
oldUser.setDeptid(user.getDeptid());
- if (user.getIdCard() == null || !user.getIdCard().contains("*")) oldUser.setIdCard(user.getIdCard());
+ // 身份证号为空说明本次表单没有提交该字段,不能覆盖数据库中的历史值;
+ // 脱敏值同样只用于回显,不能写回数据库。
+ if (!StringUtils.isEmpty(user.getIdCard()) && !user.getIdCard().contains("*")) {
+ oldUser.setIdCard(user.getIdCard());
+ }
oldUser.setSex(user.getSex());
oldUser.setEmail(user.getEmail());
if (user.getAvatar()!=null && (!user.getAvatar().equals("")))
@@ -468,13 +485,21 @@
}
// 门店关联会维护员工归属信息,但不能覆盖编辑页明确选择的角色。
// 必须在关联处理后写入,否则有门店的员工会被上面的兼容逻辑强制改回角色 3。
- if (!StringUtils.isEmpty(user.getRoleid())) {
+ // 个人资料页不提供 roleid_ 回显控件时,旧版前端可能提交字符串
+ // "undefined";该值绝不能覆盖 sys_user.roleid。
+ if (isValidRoleId(user.getRoleid())) {
oldUser.setRoleid(user.getRoleid());
}
this.userService.updateById(oldUser);
return SUCCESS_TIP;
}
+ private boolean isValidRoleId(String roleId) {
+ return !StringUtils.isEmpty(roleId)
+ && !"undefined".equalsIgnoreCase(roleId)
+ && !"null".equalsIgnoreCase(roleId);
+ }
+
private String maskPhone(String value) {
if (value == null) return null;
return value.length() <= 7 ? stars(value.length()) : value.substring(0, 3) + "****" + value.substring(7);
diff --git a/cloud-server-management/src/main/resources/mapper/TStoreMapper.xml b/cloud-server-management/src/main/resources/mapper/TStoreMapper.xml
index 423ef7d..7ebf93d 100644
--- a/cloud-server-management/src/main/resources/mapper/TStoreMapper.xml
+++ b/cloud-server-management/src/main/resources/mapper/TStoreMapper.xml
@@ -35,7 +35,11 @@
</delete>
<select id="listAll" resultType="com.dsh.guns.modular.system.model.TStoreListVo">
- select t1.*,t2.name userName,t2.phone userPhone,t3.name yysName
+ select t1.*,
+ t2.name as userName,
+ coalesce(nullif(t1.phone, ''), nullif(t2.phone, '')) as phone,
+ coalesce(nullif(t2.phone, ''), nullif(t1.phone, '')) as userPhone,
+ t3.name as yysName
from t_store t1
left join sys_user t2 on t1.storeStaffId = t2.id
left join t_operator t3 on t1.operatorId = t3.id
@@ -50,7 +54,7 @@
and t2.name like concat("%",#{name},"%")
</if>
<if test="phone !=null and phone !=''">
- and t2.phone like concat("%",#{phone},"%")
+ and coalesce(nullif(t2.phone, ''), nullif(t1.phone, '')) like concat("%",#{phone},"%")
</if>
<if test="shopName !=null and shopName !=''">
and t1.name like concat("%",#{shopName},"%")
@@ -177,7 +181,14 @@
</select>
<select id="listAllStore" resultType="com.dsh.guns.modular.system.model.TStoreListVo">
- select t1.*,t2.name userName,t2.phone userPhone,t3.name yysName from t_store t1 left join sys_user t2 on t1.storeStaffId = t2.id left join t_operator t3 on t1.operatorId = t3.id
+ select t1.*,
+ t2.name as userName,
+ coalesce(nullif(t1.phone, ''), nullif(t2.phone, '')) as phone,
+ coalesce(nullif(t2.phone, ''), nullif(t1.phone, '')) as userPhone,
+ t3.name as yysName
+ from t_store t1
+ left join sys_user t2 on t1.storeStaffId = t2.id
+ left join t_operator t3 on t1.operatorId = t3.id
where t1.id =#{id}
<if test="provinceCode !=null and provinceCode !=''">
and t1.provinceCode = #{provinceCode}
@@ -189,7 +200,7 @@
and t2.name like concat("%",#{name},"%")
</if>
<if test="phone !=null and phone !=''">
- and t2.phone like concat("%",#{phone},"%")
+ and coalesce(nullif(t2.phone, ''), nullif(t1.phone, '')) like concat("%",#{phone},"%")
</if>
<if test="shopName !=null and shopName !=''">
and t1.name like concat("%",#{shopName},"%")
diff --git a/cloud-server-management/src/main/webapp/WEB-INF/view/system/user/user_add.html b/cloud-server-management/src/main/webapp/WEB-INF/view/system/user/user_add.html
index e23cf95..787119c 100644
--- a/cloud-server-management/src/main/webapp/WEB-INF/view/system/user/user_add.html
+++ b/cloud-server-management/src/main/webapp/WEB-INF/view/system/user/user_add.html
@@ -60,7 +60,7 @@
</div>
-<script src="${ctxPath}/modular/system/user/user_info.js?v=20260916-2"></script>
+<script src="${ctxPath}/modular/system/user/user_info.js?v=20260922-1"></script>
<script>
laydate.render({
elem: '#birthday'
diff --git a/cloud-server-management/src/main/webapp/WEB-INF/view/system/user/user_edit.html b/cloud-server-management/src/main/webapp/WEB-INF/view/system/user/user_edit.html
index 921b2a3..feee7d1 100644
--- a/cloud-server-management/src/main/webapp/WEB-INF/view/system/user/user_edit.html
+++ b/cloud-server-management/src/main/webapp/WEB-INF/view/system/user/user_edit.html
@@ -67,7 +67,7 @@
-<script src="${ctxPath}/modular/system/user/user_info.js?v=20260916-2"></script>
+<script src="${ctxPath}/modular/system/user/user_info.js?v=20260922-1"></script>
<script>
laydate.render({
elem: '#birthday'
diff --git a/cloud-server-management/src/main/webapp/WEB-INF/view/system/user/user_edit1.html b/cloud-server-management/src/main/webapp/WEB-INF/view/system/user/user_edit1.html
index 7b4c658..bcea32f 100644
--- a/cloud-server-management/src/main/webapp/WEB-INF/view/system/user/user_edit1.html
+++ b/cloud-server-management/src/main/webapp/WEB-INF/view/system/user/user_edit1.html
@@ -51,7 +51,7 @@
-<script src="${ctxPath}/modular/system/user/user_info.js?v=20260916-2"></script>
+<script src="${ctxPath}/modular/system/user/user_info.js?v=20260922-1"></script>
<script>
laydate.render({
elem: '#birthday'
diff --git a/cloud-server-management/src/main/webapp/WEB-INF/view/system/user/user_view.html b/cloud-server-management/src/main/webapp/WEB-INF/view/system/user/user_view.html
index 3742e77..c034294 100644
--- a/cloud-server-management/src/main/webapp/WEB-INF/view/system/user/user_view.html
+++ b/cloud-server-management/src/main/webapp/WEB-INF/view/system/user/user_view.html
@@ -67,7 +67,7 @@
</div>
</div>
</div>
-<script src="${ctxPath}/modular/system/user/user_info.js?v=20260916-2"></script>
+<script src="${ctxPath}/modular/system/user/user_info.js?v=20260922-1"></script>
<script>
laydate.render({
elem: '#birthday'
diff --git a/cloud-server-management/src/main/webapp/static/modular/system/user/user_info.js b/cloud-server-management/src/main/webapp/static/modular/system/user/user_info.js
index 367c5dd..c5f1e55 100644
--- a/cloud-server-management/src/main/webapp/static/modular/system/user/user_info.js
+++ b/cloud-server-management/src/main/webapp/static/modular/system/user/user_info.js
@@ -409,5 +409,12 @@
avatarUp.setUploadBarId("progressBar");
avatarUp.init();
- document.getElementById('roleid').value = $("#roleid_").val();
+ // 员工编辑页有 roleid_ 用于回显;个人资料页只有隐藏的 roleid。
+ // 不能把不存在控件的 undefined 写回 roleid,否则提交 /mgr/edit
+ // 会将 sys_user.roleid 更新为字符串 "undefined"。
+ var roleIdSource = $("#roleid_");
+ var roleIdTarget = $("#roleid");
+ if (roleIdSource.length && roleIdTarget.length && roleIdSource.val()) {
+ roleIdTarget.val(roleIdSource.val());
+ }
});
--
Gitblit v1.7.1