修改客户管理权限控制,按user_id控制
This commit is contained in:
+6
@@ -1,6 +1,7 @@
|
||||
package com.bms.customer.customerinfo.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.bms.common.core.domain.entity.SysUser;
|
||||
import com.bms.customer.customerinfo.domain.BmsCustomer;
|
||||
|
||||
/**
|
||||
@@ -15,6 +16,11 @@ public interface CustomerSyncMapper
|
||||
*/
|
||||
List<String> selectExistingCodes();
|
||||
|
||||
/**
|
||||
* 未删除用户的 工号(user_name)->用户ID(user_id) 映射,用于 TMS BELONG_SALER 工号转换
|
||||
*/
|
||||
List<SysUser> selectUserLoginMap();
|
||||
|
||||
/**
|
||||
* 新增客户(同步专用,字段集与老系统导入脚本一致)
|
||||
*/
|
||||
|
||||
+45
-3
@@ -4,6 +4,7 @@ import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
@@ -14,6 +15,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.bms.common.utils.StringUtils;
|
||||
import com.bms.common.core.domain.entity.SysUser;
|
||||
import com.bms.customer.customerinfo.domain.BmsCustomer;
|
||||
import com.bms.customer.customerinfo.mapper.CustomerSyncMapper;
|
||||
|
||||
@@ -84,6 +86,9 @@ public class CustomerSyncService
|
||||
|
||||
Set<String> existingCodes = new HashSet<>(customerSyncMapper.selectExistingCodes());
|
||||
|
||||
// 业务员归属转本系统用户ID:数据权限按 user_id 控制,工号后续修改不影响归属
|
||||
Map<String, String> userIdByLogin = loadUserIdByLogin();
|
||||
|
||||
List<BmsCustomer> inserts = new ArrayList<>();
|
||||
List<BmsCustomer> updates = new ArrayList<>();
|
||||
Set<String> seenCodes = new HashSet<>();
|
||||
@@ -118,7 +123,7 @@ public class CustomerSyncService
|
||||
continue;
|
||||
}
|
||||
|
||||
BmsCustomer c = mapRow(row, code, name, warnings);
|
||||
BmsCustomer c = mapRow(row, code, name, userIdByLogin, warnings);
|
||||
if (existingCodes.contains(code))
|
||||
{
|
||||
c.setUpdateBy(SYNC_MARKER);
|
||||
@@ -155,7 +160,8 @@ public class CustomerSyncService
|
||||
/**
|
||||
* 单行映射(逻辑对齐 import_customers.py 的 build_row)
|
||||
*/
|
||||
private BmsCustomer mapRow(Map<String, Object> row, String code, String name, List<String> warnings)
|
||||
private BmsCustomer mapRow(Map<String, Object> row, String code, String name,
|
||||
Map<String, String> userIdByLogin, List<String> warnings)
|
||||
{
|
||||
BmsCustomer c = new BmsCustomer();
|
||||
c.setCustomerCode(truncate(code, LEN_CODE, code, "customer_code", warnings));
|
||||
@@ -163,7 +169,7 @@ public class CustomerSyncService
|
||||
c.setDelFlag("0");
|
||||
|
||||
c.setCustomerCodeDw(truncate(getStr(row, "CUSTOMER_OUTER_CODE"), LEN_CODE_DW, code, "customer_code_dw", warnings));
|
||||
c.setSalesUserId(truncate(getStr(row, "BELONG_SALER"), LEN_USER_ID, code, "sales_user_id", warnings));
|
||||
c.setSalesUserId(resolveSalesUserId(clean(getStr(row, "BELONG_SALER")), userIdByLogin, code, warnings));
|
||||
c.setSalesUser(truncate(getStr(row, "BELONG_SALER_NAME"), LEN_USER, code, "sales_user", warnings));
|
||||
c.setSettlementUser(truncate(getStr(row, "SETTLEMENT_MAN"), LEN_USER, code, "settlement_user", warnings));
|
||||
c.setServiceUser(truncate(getStr(row, "SERVICE_MAN"), LEN_USER, code, "service_user", warnings));
|
||||
@@ -225,6 +231,42 @@ public class CustomerSyncService
|
||||
return ("1".equals(s) || "1.0".equals(s)) ? "0" : "1";
|
||||
}
|
||||
|
||||
/** 加载未删除用户的 工号(user_name)->用户ID(user_id) 映射 */
|
||||
private Map<String, String> loadUserIdByLogin()
|
||||
{
|
||||
Map<String, String> map = new HashMap<>();
|
||||
for (SysUser u : customerSyncMapper.selectUserLoginMap())
|
||||
{
|
||||
if (u != null && u.getUserName() != null && u.getUserId() != null
|
||||
&& !map.containsKey(u.getUserName()))
|
||||
{
|
||||
map.put(u.getUserName(), String.valueOf(u.getUserId()));
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 业务员工号 -> 本系统 sys_user.user_id 转换(数据权限按 user_id 控制,工号修改不影响归属)。
|
||||
* 工号在系统用户中不存在时保留原工号并告警(常见于该用户尚未同步),避免归属信息丢失。
|
||||
*/
|
||||
private String resolveSalesUserId(String salerCode, Map<String, String> userIdByLogin,
|
||||
String code, List<String> warnings)
|
||||
{
|
||||
String s = truncate(salerCode, LEN_USER_ID, code, "sales_user_id", warnings);
|
||||
if (s == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
String userId = userIdByLogin.get(s);
|
||||
if (userId != null)
|
||||
{
|
||||
return userId;
|
||||
}
|
||||
warnings.add(code + ": 业务员工号 " + s + " 在系统用户中不存在,sales_user_id 保留原工号");
|
||||
return s;
|
||||
}
|
||||
|
||||
private static String clean(String v)
|
||||
{
|
||||
if (v == null)
|
||||
|
||||
@@ -59,12 +59,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
su.nick_name as sales_user_nick_name,
|
||||
cps.price_set_id, ps.price_set_name
|
||||
from ctr_customer c
|
||||
<!-- 老系统同步数据 sales_user_id 存员工工号(=sys_user.user_name);
|
||||
BMS 手工新建数据可能存数字 user_id,两种都要能关联上。
|
||||
'WS0052'+0 在 MySQL 中结果为 0,不会误关联到任何用户 -->
|
||||
<!-- sales_user_id 统一存本系统 user_id(同步时由工号转换、手工录入选人即存ID),
|
||||
数据权限按 su.user_id / su.dept_id 控制;保留 user_name 匹配仅作历史未转换工号兜底 -->
|
||||
left join sys_user su
|
||||
on su.del_flag = '0'
|
||||
and (su.user_name = c.sales_user_id or su.user_id = c.sales_user_id + 0)
|
||||
and (su.user_id = c.sales_user_id + 0 or su.user_name = c.sales_user_id)
|
||||
<!-- 客户套餐绑定:uk_customer_one_set 保证一客户至多一条,不会放大行数 -->
|
||||
left join prc_customer_price_set cps on cps.customer_id = c.customer_id
|
||||
left join prc_price_set ps on ps.price_set_id = cps.price_set_id
|
||||
|
||||
@@ -8,6 +8,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
SELECT customer_code FROM ctr_customer WHERE del_flag = '0'
|
||||
</select>
|
||||
|
||||
<!-- 工号->用户ID 映射(列别名显式映射,项目未开下划线转驼峰) -->
|
||||
<select id="selectUserLoginMap" resultType="com.bms.common.core.domain.entity.SysUser">
|
||||
SELECT user_id AS userId, user_name AS userName
|
||||
FROM sys_user
|
||||
WHERE del_flag = '0'
|
||||
</select>
|
||||
|
||||
<!-- 字段集与 scripts/import_customers.py 的 MAP_COLUMNS 保持一致;
|
||||
源行为空的字段不写,走数据库默认值 -->
|
||||
<insert id="insertSyncCustomer" parameterType="com.bms.customer.customerinfo.domain.BmsCustomer">
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
-- 客户归属销售员由"工号"改存本系统用户ID(数据权限按 user_id 控制,工号后续修改不影响归属)
|
||||
-- 同步链路已在 CustomerSyncService.resolveSalesUserId 做同样转换,本脚本只处理存量数据。
|
||||
-- 仅转换"含非数字字符"的工号值(工号形如 WS0052/WSC0184/wsadmin);
|
||||
-- 已是数字(user_id)的行不触碰,脚本可重复执行。
|
||||
UPDATE ctr_customer c
|
||||
JOIN sys_user u ON u.del_flag = '0' AND u.user_name = c.sales_user_id
|
||||
SET c.sales_user_id = CONVERT(u.user_id, CHAR)
|
||||
WHERE c.del_flag = '0'
|
||||
AND c.sales_user_id IS NOT NULL
|
||||
AND c.sales_user_id REGEXP '[^0-9]';
|
||||
@@ -75,7 +75,6 @@
|
||||
<el-form-item label="业务员" prop="salesUserId">
|
||||
<user-select
|
||||
v-model="form.salesUserId"
|
||||
value-field="userName"
|
||||
placeholder="请选择业务员"
|
||||
@change="(uid, user) => handleUserChange(uid, user, 'salesUser')"
|
||||
/>
|
||||
|
||||
@@ -34,8 +34,7 @@
|
||||
<el-form-item label="业务员" prop="salesUserId">
|
||||
<user-select
|
||||
v-model="queryParams.salesUserId"
|
||||
value-field="userName"
|
||||
placeholder="工号/姓名搜索"
|
||||
placeholder="姓名/工号搜索"
|
||||
@change="handleQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
Reference in New Issue
Block a user