修改客户管理权限控制,按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)
|
||||
|
||||
Reference in New Issue
Block a user