han\hanst 2 months ago
parent
commit
40da28acec
  1. 24
      src/main/java/com/xujie/sys/modules/ecss/mapper/CoDelMapper.java
  2. 106
      src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelServiceImpl.java
  3. 18
      src/main/resources/mapper/ecss/CoDelMapper.xml

24
src/main/java/com/xujie/sys/modules/ecss/mapper/CoDelMapper.java

@ -307,8 +307,24 @@ public interface CoDelMapper {
List<Map<String, Object>> getCustomerTemplateList(Map<String, Object> params);
// 根据模板名称获取客户模板信息
@Select("SELECT * FROM ecss_Customer_template WHERE template_name = #{templateName}")
Map<String, Object> getCustomerTemplateByName(@Param("templateName") String templateName);
@Select({
"<script>",
"SELECT TOP 1 *",
"FROM ecss_Customer_template",
"WHERE template_name = #{templateName}",
"<if test='templateBuNo != null and templateBuNo != \"\"'>",
" AND EXISTS (",
" SELECT 1",
" FROM string_split(REPLACE(#{templateBuNo}, ' ', ''), ',') queryBu",
" WHERE queryBu.value != ''",
" AND CHARINDEX(',' + queryBu.value + ',', ',' + REPLACE(ISNULL(bu_no, ''), ' ', '') + ',') > 0",
" )",
"</if>",
"ORDER BY template_no DESC",
"</script>"
})
Map<String, Object> getCustomerTemplateByName(@Param("templateName") String templateName,
@Param("templateBuNo") String templateBuNo);
// 获取最大的template_no用于生成新的template_no
@Select("SELECT TOP 1 template_no FROM ecss_Customer_template ORDER BY template_no DESC")
@ -319,9 +335,9 @@ public interface CoDelMapper {
String getCustomerCodeByName(@Param("customerName") String customerName);
// 插入新的客户模板模板名称变化时使用
@Insert("INSERT INTO ecss_Customer_template (template_no, template_name,ccuscode, ccusname, localShipAddress, " +
@Insert("INSERT INTO ecss_Customer_template (template_no, template_name, bu_no, ccuscode, ccusname, localShipAddress, " +
"overseasShipper, overseasAddress, cnative, salesArea) " +
"VALUES (#{template_no}, #{templateName},#{ccuscode}, #{ccusname}, #{localShipAddress}, " +
"VALUES (#{template_no}, #{templateName}, #{templateBuNo}, #{ccuscode}, #{ccusname}, #{localShipAddress}, " +
"#{overseasShipper}, #{overseasAddress}, #{cnative}, #{salesArea})")
void insertCustomerTemplate(Map<String, Object> params);

106
src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelServiceImpl.java

@ -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);

18
src/main/resources/mapper/ecss/CoDelMapper.xml

@ -1513,6 +1513,7 @@ create_by,create_date,update_by,update_date
SELECT
template_no,
template_name,
bu_no AS buNo,
ccuscode,
ccusname,
caddcode1,
@ -1530,18 +1531,31 @@ create_by,create_date,update_by,update_date
<if test="customerName != null and customerName != ''">
AND customer_name like '%'+#{customerName}+'%'
</if>
<if test="templateBuNo != null and templateBuNo != ''">
AND EXISTS (
SELECT 1
FROM string_split(REPLACE(#{templateBuNo}, ' ', ''), ',') queryBu
WHERE queryBu.value != ''
AND CHARINDEX(',' + queryBu.value + ',', ',' + REPLACE(ISNULL(bu_no, ''), ' ', '') + ',') > 0
)
</if>
</where>
ORDER BY template_name
</select>
<update id="updateCustomerTemplate">
update ecss_Customer_template
set ccusname = #{ccusname},
<set>
ccusname = #{ccusname},
localShipAddress = #{localShipAddress},
overseasShipper = #{overseasShipper},
overseasAddress = #{overseasAddress},
cnative = #{cnative},
salesArea = #{salesArea}
salesArea = #{salesArea},
<if test="templateBuNo != null and templateBuNo != ''">
bu_no = #{templateBuNo},
</if>
</set>
where template_no = #{templateNo}
</update>

Loading…
Cancel
Save