|
|
|
@ -32,6 +32,7 @@ import java.util.concurrent.atomic.AtomicInteger; |
|
|
|
@Slf4j |
|
|
|
@Service |
|
|
|
public class ReportLabelListServiceImpl extends ServiceImpl<ReportLabelListMapper, ReportLabelList> implements ReportLabelListService { |
|
|
|
private static final String RESOLVED_LABEL_DATA_LIST_KEY = "__RESOLVED_LABEL_DATA_LIST__"; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private BaseService baseService; |
|
|
|
@ -331,6 +332,33 @@ public class ReportLabelListServiceImpl extends ServiceImpl<ReportLabelListMappe |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取打印所需标签数据:优先复用已解析数据,避免重复调用IFS |
|
|
|
*/ |
|
|
|
private List<java.util.Map<String, Object>> getLabelDataForPrint(String labelNo, Map<String, Object> queryParams) { |
|
|
|
if (queryParams != null) { |
|
|
|
Object resolvedDataObj = queryParams.get(RESOLVED_LABEL_DATA_LIST_KEY); |
|
|
|
if (resolvedDataObj instanceof List<?> resolvedList && !resolvedList.isEmpty()) { |
|
|
|
List<java.util.Map<String, Object>> resolvedLabelDataList = new ArrayList<>(); |
|
|
|
for (Object item : resolvedList) { |
|
|
|
if (item instanceof Map<?, ?> dataMap) { |
|
|
|
java.util.Map<String, Object> row = new HashMap<>(); |
|
|
|
for (Map.Entry<?, ?> entry : dataMap.entrySet()) { |
|
|
|
if (entry.getKey() != null) { |
|
|
|
row.put(entry.getKey().toString(), entry.getValue()); |
|
|
|
} |
|
|
|
} |
|
|
|
resolvedLabelDataList.add(row); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!resolvedLabelDataList.isEmpty()) { |
|
|
|
return resolvedLabelDataList; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return getLabelDataForSaving(labelNo, queryParams); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 从Map中安全地获取字符串值 |
|
|
|
*/ |
|
|
|
@ -659,8 +687,10 @@ public class ReportLabelListServiceImpl extends ServiceImpl<ReportLabelListMappe |
|
|
|
@Override |
|
|
|
public void printLabelCommon(PrintLabelRequest printRequest) { |
|
|
|
String rfidFlag; |
|
|
|
// 当前端传了customerId时,根据客户编码解析标签编号 |
|
|
|
String resolvedReportId = resolveReportIdByCustomer(printRequest); |
|
|
|
LabelSettingData labelSettingData = new LabelSettingData(); |
|
|
|
labelSettingData.setLabelNo(printRequest.getReportId()); |
|
|
|
labelSettingData.setLabelNo(resolvedReportId); |
|
|
|
labelSettingData.setLabelType(printRequest.getLabelType()); |
|
|
|
List<LabelSettingData> labelSettingDataList = baseService.getLabelSettingList(labelSettingData); |
|
|
|
LabelSettingData labelSetting; |
|
|
|
@ -708,7 +738,7 @@ public class ReportLabelListServiceImpl extends ServiceImpl<ReportLabelListMappe |
|
|
|
// 生成带真实数据的ZPL代码和对应的数据 |
|
|
|
List<String> zplCodeList = previewLabelWithRealData(labelSetting.getLabelNo(), true, queryParams); |
|
|
|
// 同时获取原始数据用于保存WMS标签记录 |
|
|
|
List<java.util.Map<String, Object>> labelDataList = getLabelDataForSaving(labelSetting.getLabelNo(), queryParams); |
|
|
|
List<Map<String, Object>> labelDataList = getLabelDataForPrint(labelSetting.getLabelNo(), queryParams); |
|
|
|
// 2. 验证ZPL代码 |
|
|
|
if (zplCodeList == null || zplCodeList.isEmpty()) { |
|
|
|
throw new RuntimeException("ZPL代码获取失败"); |
|
|
|
@ -766,4 +796,58 @@ public class ReportLabelListServiceImpl extends ServiceImpl<ReportLabelListMappe |
|
|
|
throw new RuntimeException("RFID标签打印失败: " + e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据客户编码解析标签编号(仅当前端传了customerId时生效) |
|
|
|
*/ |
|
|
|
private String resolveReportIdByCustomer(PrintLabelRequest printRequest) { |
|
|
|
String fallbackReportId = printRequest.getReportId(); |
|
|
|
String customerId = printRequest.getCustomerId(); |
|
|
|
if (StringUtils.isBlank(customerId)) { |
|
|
|
return fallbackReportId; |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
CustomerLabelSettingData query = new CustomerLabelSettingData(); |
|
|
|
query.setSearchFlag("Y"); |
|
|
|
query.setCustomerId(customerId.trim()); |
|
|
|
query.setLabelType(printRequest.getLabelType()); |
|
|
|
List<CustomerLabelSettingData> customerLabelList = baseService.getCustomerLabelSettingList(query); |
|
|
|
if (customerLabelList == null || customerLabelList.isEmpty()) { |
|
|
|
log.warn("客户标签映射未找到,回退前端reportId。customerId={}, labelType={}, reportId={}", |
|
|
|
customerId, printRequest.getLabelType(), fallbackReportId); |
|
|
|
return fallbackReportId; |
|
|
|
} |
|
|
|
|
|
|
|
CustomerLabelSettingData matchedLabel = null; |
|
|
|
for (CustomerLabelSettingData item : customerLabelList) { |
|
|
|
if (item == null || StringUtils.isBlank(item.getLabelNo())) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(printRequest.getSite()) |
|
|
|
&& !StringUtils.equalsIgnoreCase(printRequest.getSite(), item.getSite())) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
// 优先主标签(SubReportFlag=N) |
|
|
|
if ("N".equalsIgnoreCase(item.getSubLabelFlag())) { |
|
|
|
matchedLabel = item; |
|
|
|
break; |
|
|
|
} |
|
|
|
if (matchedLabel == null) { |
|
|
|
matchedLabel = item; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (matchedLabel != null && StringUtils.isNotBlank(matchedLabel.getLabelNo())) { |
|
|
|
log.info("按客户标签映射解析reportId成功。customerId={}, labelType={}, resolvedReportId={}", |
|
|
|
customerId, printRequest.getLabelType(), matchedLabel.getLabelNo()); |
|
|
|
return matchedLabel.getLabelNo(); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
log.warn("按客户编码解析标签编号失败,回退前端reportId。customerId={}, labelType={}, error={}", |
|
|
|
customerId, printRequest.getLabelType(), e.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
return fallbackReportId; |
|
|
|
} |
|
|
|
} |