|
|
|
@ -2569,9 +2569,99 @@ public class CoDelServiceImpl implements CoDelService { |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<Map<String, Object>> getCustomerTemplateList(Map<String, Object> params) { |
|
|
|
ensureTemplateBuNo(params); |
|
|
|
return coDelMapper.getCustomerTemplateList(params); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 统一补齐客户模板BU分组参数(templateBuNo) |
|
|
|
* 规则: |
|
|
|
* 01/03 -> 03-RFID,01-Label |
|
|
|
* 02/05 -> 02-Hardtag,05-Alpha |
|
|
|
* 04 -> 04-MHM |
|
|
|
* |
|
|
|
* @param params 请求参数 |
|
|
|
* @return 规范化后的templateBuNo |
|
|
|
*/ |
|
|
|
private String ensureTemplateBuNo(Map<String, Object> params) { |
|
|
|
if (params == null) { |
|
|
|
return ""; |
|
|
|
} |
|
|
|
|
|
|
|
String templateBuNo = getTrimmedString(params.get("templateBuNo")); |
|
|
|
if (StringUtils.isBlank(templateBuNo)) { |
|
|
|
templateBuNo = mapTemplateBuNoByBu(getTrimmedString(params.get("buNo"))); |
|
|
|
} |
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(templateBuNo)) { |
|
|
|
params.put("templateBuNo", templateBuNo); |
|
|
|
} |
|
|
|
return templateBuNo; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 将页面选择的BU转换为模板bu_no分组 |
|
|
|
* |
|
|
|
* @param buNo 页面传入的BU |
|
|
|
* @return 模板分组bu_no |
|
|
|
*/ |
|
|
|
private String mapTemplateBuNoByBu(String buNo) { |
|
|
|
if (StringUtils.isBlank(buNo)) { |
|
|
|
return ""; |
|
|
|
} |
|
|
|
|
|
|
|
String sourceBu = buNo.trim(); |
|
|
|
String upperBu = sourceBu.toUpperCase(); |
|
|
|
String buCode = extractBuCode(upperBu); |
|
|
|
|
|
|
|
if ("01".equals(buCode) || "03".equals(buCode) || upperBu.contains("RFID") || upperBu.contains("LABEL") || upperBu.contains("软标")) { |
|
|
|
return "03-RFID,01-Label"; |
|
|
|
} |
|
|
|
if ("02".equals(buCode) || "05".equals(buCode) || upperBu.contains("HARDTAG") || upperBu.contains("HARD") || upperBu.contains("ALPHA") || upperBu.contains("硬标")) { |
|
|
|
return "02-Hardtag,05-Alpha"; |
|
|
|
} |
|
|
|
if ("04".equals(buCode) || upperBu.contains("MHM") || upperBu.contains("天线")) { |
|
|
|
return "04-MHM"; |
|
|
|
} |
|
|
|
return sourceBu; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 从BU字符串中提取前2位数字编码 |
|
|
|
* |
|
|
|
* @param buValue BU值 |
|
|
|
* @return BU编码 |
|
|
|
*/ |
|
|
|
private String extractBuCode(String buValue) { |
|
|
|
if (StringUtils.isBlank(buValue)) { |
|
|
|
return ""; |
|
|
|
} |
|
|
|
|
|
|
|
StringBuilder codeBuilder = new StringBuilder(); |
|
|
|
for (int i = 0; i < buValue.length(); i++) { |
|
|
|
char ch = buValue.charAt(i); |
|
|
|
if (Character.isDigit(ch)) { |
|
|
|
codeBuilder.append(ch); |
|
|
|
if (codeBuilder.length() == 2) { |
|
|
|
break; |
|
|
|
} |
|
|
|
} else if (codeBuilder.length() > 0) { |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
return codeBuilder.length() == 2 ? codeBuilder.toString() : ""; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取去空格后的字符串 |
|
|
|
* |
|
|
|
* @param value 入参对象 |
|
|
|
* @return 字符串 |
|
|
|
*/ |
|
|
|
private String getTrimmedString(Object value) { |
|
|
|
return value == null ? "" : String.valueOf(value).trim(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 更新或创建客户模板 |
|
|
|
* |
|
|
|
@ -2598,6 +2688,7 @@ public class CoDelServiceImpl implements CoDelService { |
|
|
|
String templateName = (String) params.get("templateName"); |
|
|
|
String originalTemplateName = (String) params.get("originalTemplateName"); |
|
|
|
String customerName = (String) params.get("ccusname"); |
|
|
|
String templateBuNo = ensureTemplateBuNo(params); |
|
|
|
|
|
|
|
// 判断是否传入了原始模板名称 |
|
|
|
boolean hasOriginalTemplate = originalTemplateName != null && !originalTemplateName.trim().isEmpty(); |
|
|
|
@ -2609,7 +2700,7 @@ public class CoDelServiceImpl implements CoDelService { |
|
|
|
if (hasOriginalTemplate) { |
|
|
|
// 场景1:基于原模板修改(来自双击选择模板后的操作) |
|
|
|
// 获取原始模板信息 |
|
|
|
originalTemplate = coDelMapper.getCustomerTemplateByName(originalTemplateName); |
|
|
|
originalTemplate = coDelMapper.getCustomerTemplateByName(originalTemplateName, templateBuNo); |
|
|
|
|
|
|
|
// 判断模板名称是否发生变化 |
|
|
|
boolean nameChanged = !templateName.equals(originalTemplateName); |
|
|
|
@ -2617,7 +2708,7 @@ public class CoDelServiceImpl implements CoDelService { |
|
|
|
if (nameChanged) { |
|
|
|
// 模板名称变化,另存为新模板 |
|
|
|
// 检查新模板名是否已存在 |
|
|
|
targetTemplate = coDelMapper.getCustomerTemplateByName(templateName); |
|
|
|
targetTemplate = coDelMapper.getCustomerTemplateByName(templateName, templateBuNo); |
|
|
|
if (targetTemplate == null) { |
|
|
|
// 新模板名不存在,创建新模板 |
|
|
|
createNewTemplate(params, customerName); |
|
|
|
@ -2638,7 +2729,7 @@ public class CoDelServiceImpl implements CoDelService { |
|
|
|
} else { |
|
|
|
// 场景2:直接输入模板名(来自手动输入模板名的操作) |
|
|
|
// 查询该模板名是否已存在 |
|
|
|
targetTemplate = coDelMapper.getCustomerTemplateByName(templateName); |
|
|
|
targetTemplate = coDelMapper.getCustomerTemplateByName(templateName, templateBuNo); |
|
|
|
|
|
|
|
if (targetTemplate == null) { |
|
|
|
// 模板不存在,创建新模板 |
|
|
|
@ -2672,6 +2763,7 @@ public class CoDelServiceImpl implements CoDelService { |
|
|
|
String templateName = params.get("templateName") != null ? String.valueOf(params.get("templateName")).trim() : null; |
|
|
|
String originalTemplateName = params.get("originalTemplateName") != null ? String.valueOf(params.get("originalTemplateName")).trim() : null; |
|
|
|
String customerName = params.get("ccusname") != null ? String.valueOf(params.get("ccusname")).trim() : null; |
|
|
|
String templateBuNo = ensureTemplateBuNo(params); |
|
|
|
|
|
|
|
if (templateName == null || templateName.isEmpty()) { |
|
|
|
throw new RuntimeException("模板名称不能为空"); |
|
|
|
@ -2684,11 +2776,11 @@ public class CoDelServiceImpl implements CoDelService { |
|
|
|
|
|
|
|
try { |
|
|
|
if (hasOriginalTemplate) { |
|
|
|
Map<String, Object> originalTemplate = coDelMapper.getCustomerTemplateByName(originalTemplateName); |
|
|
|
Map<String, Object> originalTemplate = coDelMapper.getCustomerTemplateByName(originalTemplateName, templateBuNo); |
|
|
|
boolean nameChanged = !templateName.equals(originalTemplateName); |
|
|
|
|
|
|
|
if (nameChanged) { |
|
|
|
Map<String, Object> targetTemplate = coDelMapper.getCustomerTemplateByName(templateName); |
|
|
|
Map<String, Object> targetTemplate = coDelMapper.getCustomerTemplateByName(templateName, templateBuNo); |
|
|
|
if (targetTemplate == null) { |
|
|
|
createNewTemplate(params, customerName); |
|
|
|
} else { |
|
|
|
@ -2703,7 +2795,7 @@ public class CoDelServiceImpl implements CoDelService { |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
Map<String, Object> targetTemplate = coDelMapper.getCustomerTemplateByName(templateName); |
|
|
|
Map<String, Object> targetTemplate = coDelMapper.getCustomerTemplateByName(templateName, templateBuNo); |
|
|
|
if (targetTemplate == null) { |
|
|
|
createNewTemplate(params, customerName); |
|
|
|
} else { |
|
|
|
@ -2732,6 +2824,7 @@ public class CoDelServiceImpl implements CoDelService { |
|
|
|
customerCode = coDelMapper.getCustomerCodeByName(customerName); |
|
|
|
} |
|
|
|
params.put("ccuscode", customerCode != null ? customerCode : ""); |
|
|
|
ensureTemplateBuNo(params); |
|
|
|
|
|
|
|
// 2. 生成新的template_no |
|
|
|
String maxTemplateNo = coDelMapper.getMaxTemplateNo(); |
|
|
|
@ -2759,6 +2852,7 @@ public class CoDelServiceImpl implements CoDelService { |
|
|
|
// XML 中 WHERE 条件是 #{templateNo}(camelCase),必须用 templateNo 作为 key |
|
|
|
params.put("templateNo", existingTemplateNo); |
|
|
|
params.put("ccuscode", existingCcuscode != null ? existingCcuscode : ""); |
|
|
|
ensureTemplateBuNo(params); |
|
|
|
|
|
|
|
// 更新模板 |
|
|
|
coDelMapper.updateCustomerTemplate(params); |
|
|
|
|