Browse Source

unitId规则变更

master
han\hanst 4 months ago
parent
commit
1ffce1f78f
  1. 57
      src/main/java/com/gaotao/modules/base/service/Impl/ReportLabelListServiceImpl.java
  2. 16
      src/main/java/com/gaotao/modules/handlingunit/service/HandlingUnitIdGeneratorService.java
  3. 89
      src/main/java/com/gaotao/modules/handlingunit/service/impl/HandlingUnitIdGeneratorServiceImpl.java
  4. 4
      src/main/java/com/gaotao/modules/inspection/task/IfsInspectionHistoryTask.java
  5. 20
      src/main/java/com/gaotao/modules/po/service/impl/PoServiceImpl.java
  6. 3
      src/main/resources/mapper/base/BaseMapper.xml

57
src/main/java/com/gaotao/modules/base/service/Impl/ReportLabelListServiceImpl.java

@ -229,13 +229,12 @@ public class ReportLabelListServiceImpl extends ServiceImpl<ReportLabelListMappe
// 为每个ZPL代码设置到printRequest中用于日志记录
printRequest.setZplCode(zplCode);
Map<String, Object> labelData = i < labelDataList.size() ? labelDataList.get(i) : new HashMap<>();
// 发送ZPL到打印机
RfidProcessResult printResult = sendZplToPrinterAndGetResult(printerIP, zplCode, requestedCopies, rfidFlag);
RfidProcessResult printResult = sendZplToPrinterAndGetResult(printerIP, zplCode, requestedCopies, rfidFlag,labelData);
// 打印成功后保存标签记录
if (printResult.isSuccess()) {
java.util.Map<String, Object> labelData = i < labelDataList.size() ? labelDataList.get(i) : new HashMap<>();
saveWmsLabelRecord(printRequest, labelSettingDataList.getFirst().getLabelType(), printResult, defaultLabelSettingData.getLabelNo(), i + 1, labelData);
}
}
@ -251,21 +250,22 @@ public class ReportLabelListServiceImpl extends ServiceImpl<ReportLabelListMappe
/**
* 发送ZPL代码到打印机并返回结果支持RFID标签处理和多份打印
*/
private RfidProcessResult sendZplToPrinterAndGetResult(String printerIP, String zplCode, Integer copies, String rfidFlag) {
private RfidProcessResult sendZplToPrinterAndGetResult(String printerIP, String zplCode,
Integer copies, String rfidFlag,Map<String, Object> labelData) {
try {
log.info("开始处理标签打印: {}, 请求份数: {}, RFID标志: {}", printerIP, copies, rfidFlag);
RfidProcessResult result;
if ("Y".equals(rfidFlag)) {
// RFID模式单张处理返回第一个结果
result = processRfidLabel(printerIP, zplCode, 1, rfidFlag);
result = processRfidLabel(printerIP, zplCode, 1, rfidFlag,labelData);
if (!result.isSuccess()) {
throw new RuntimeException("RFID标签打印失败: " + result.getErrorMessage());
}
log.info("RFID标签打印完成,TID: {}", result.getTid());
} else {
// 普通模式直接处理
result = processRfidLabel(printerIP, zplCode, copies, rfidFlag);
result = processRfidLabel(printerIP, zplCode, copies, rfidFlag,labelData);
if (!result.isSuccess()) {
throw new RuntimeException("普通标签打印失败: " + result.getErrorMessage());
}
@ -417,43 +417,11 @@ public class ReportLabelListServiceImpl extends ServiceImpl<ReportLabelListMappe
}
}
/**
* 处理RFID标签的多份打印
* 由于RFID标签的特殊性需要逐张处理并在每张之间留有足够的间隔
*/
private void handleRfidMultiplePrint(String printerIP, String zplCode, Integer copies) {
log.info("开始处理RFID多份打印,份数: {}", copies);
for (int i = 1; i <= copies; i++) {
try {
log.info("开始处理第{}张RFID标签", i);
// 每张标签之间留有间隔避免RFID模块冲突
if (i > 1) {
Thread.sleep(2000); // 2秒间隔
log.info("等待间隔完成,开始处理第{}张标签", i);
}
RfidProcessResult result = processRfidLabel(printerIP, zplCode, i, "Y");
if (!result.isSuccess()) {
throw new RuntimeException("第" + i + "张RFID标签处理失败: " + result.getErrorMessage());
}
log.info("第{}张RFID标签处理成功", i);
} catch (Exception e) {
log.error("第{}张RFID标签处理失败: {}", i, e.getMessage());
throw new RuntimeException("第" + i + "张RFID标签处理失败: " + e.getMessage());
}
}
log.info("RFID多份打印完成,总计{}张", copies);
}
/**
* 处理标签打印支持RFID和普通标签
*/
private RfidProcessResult processRfidLabel(String printerIP, String originalZplCode, int copiesOrIndex, String rfidFlag) {
private RfidProcessResult processRfidLabel(String printerIP, String originalZplCode, int copiesOrIndex,
String rfidFlag,Map<String, Object> labelData) {
RfidProcessResult result = new RfidProcessResult(copiesOrIndex);
java.net.Socket socket = null;
try {
@ -479,7 +447,7 @@ public class ReportLabelListServiceImpl extends ServiceImpl<ReportLabelListMappe
InputStream inputStream = socket.getInputStream();
// 步骤1: 读取RFID标签的TID
String tid = readRfidTid(outputStream, inputStream, originalZplCode);
String tid = readRfidTid(outputStream, inputStream, originalZplCode,labelData);
result.setTid(tid);
log.info("第{}张RFID标签 - 读取到TID: {}", copiesOrIndex, tid);
result.markCompleted(true, null);
@ -508,12 +476,15 @@ public class ReportLabelListServiceImpl extends ServiceImpl<ReportLabelListMappe
/**
* 读取RFID标签的TID
*/
private String readRfidTid(OutputStream outputStream, InputStream inputStream, String originalZplCode) throws Exception {
private String readRfidTid(OutputStream outputStream, InputStream inputStream,
String originalZplCode,Map<String, Object> labelData) throws Exception {
log.info("开始读取RFID标签TID...");
// 清空输入流缓冲区避免之前的数据干扰
clearInputStreamBuffer(inputStream);
// 生成有效的EPC数据 - 确保格式正确避免写入失败
String epc = "1234567890AB1234567890AB"; // 示例EPC数据实际应用中应生成或获取有效的EPC
String epc = getStringValue(labelData, "unit_id", "");
// 补齐到24位不足的在前面加0
epc = String.format("%024s", epc);
// 处理原始ZPL代码移除可能的打印份数指令确保只打印1张
String cleanedZplCode = cleanZplForSinglePrint(originalZplCode.substring(3));
// 组装 ZPL - 优化RFID指令确保EPC写入成功

16
src/main/java/com/gaotao/modules/handlingunit/service/HandlingUnitIdGeneratorService.java

@ -0,0 +1,16 @@
package com.gaotao.modules.handlingunit.service;
/**
* 处理单元ID生成服务接口
* 生成格式P+site+YYYYMMDD+8位自增流水码
* 流水码每天根据前缀从1开始计数
*/
public interface HandlingUnitIdGeneratorService {
/**
* 生成新的处理单元ID
* @param site 工厂代码
* @return 生成的处理单元ID格式P+site+YYYYMMDD+8位自增流水码
*/
String generateUnitId(String site);
}

89
src/main/java/com/gaotao/modules/handlingunit/service/impl/HandlingUnitIdGeneratorServiceImpl.java

@ -0,0 +1,89 @@
package com.gaotao.modules.handlingunit.service.impl;
import com.gaotao.modules.handlingunit.service.HandlingUnitIdGeneratorService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
/**
* 处理单元ID生成服务实现类
* 生成格式P+site+YYYYMMDD+8位自增流水码
* 流水码每天根据前缀从1开始计数
*/
@Slf4j
@Service
public class HandlingUnitIdGeneratorServiceImpl implements HandlingUnitIdGeneratorService {
@Autowired
private JdbcTemplate jdbcTemplate;
/**
* 生成新的处理单元ID
* @param site 工厂代码
* @return 生成的处理单元ID格式A+site+YYYYMMDD+8位自增流水码
*/
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public String generateUnitId(String site) {
// 生成当前日期字符串 YYYYMMDD
String dateStr = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
// 生成前缀A+site+YYYYMMDD
String prefix = "A" + site + dateStr;
// 获取下一个流水号8位从1开始每天重置
int sequenceNo = getNextSequenceNumber(prefix);
// 格式化为8位流水号补齐前导零
String formattedSequence = String.format("%08d", sequenceNo);
// 组合完整的处理单元ID
String unitId = prefix + formattedSequence;
log.debug("生成处理单元ID: site={}, prefix={}, sequence={}, unitId={}",
site, prefix, sequenceNo, unitId);
return unitId;
}
/**
* 获取下一个流水号
* 使用数据库保证并发安全每天重置计数
* @param prefix 日期前缀 (P+site+YYYYMMDD)
* @return 下一个流水号
*/
private int getNextSequenceNumber(String prefix) {
try {
// 检查是否已存在当天的记录
String checkSql = "SELECT COUNT(*) FROM handling_unit_sequence WHERE prefix = ?";
Integer count = jdbcTemplate.queryForObject(checkSql, Integer.class, prefix);
if (count == null || count == 0) {
// 不存在记录插入新记录流水号从1开始
String insertSql = "INSERT INTO handling_unit_sequence (prefix, next_sequence, created_date) VALUES (?, 1, GETDATE())";
jdbcTemplate.update(insertSql, prefix);
return 1;
} else {
// 存在记录更新并返回下一个流水号
String updateSql = "UPDATE handling_unit_sequence SET next_sequence = next_sequence + 1, modified_date = GETDATE() " +
"WHERE prefix = ?";
jdbcTemplate.update(updateSql, prefix);
// 获取更新后的流水号
String selectSql = "SELECT next_sequence FROM handling_unit_sequence WHERE prefix = ?";
Integer nextSequence = jdbcTemplate.queryForObject(selectSql, Integer.class, prefix);
return nextSequence != null ? nextSequence : 1;
}
} catch (Exception e) {
log.error("获取流水号失败,prefix={}, error={}", prefix, e.getMessage(), e);
// 发生错误时尝试使用系统时间作为备用方案
return (int) (System.currentTimeMillis() % 100000000); // 取后8位作为备用
}
}
}

4
src/main/java/com/gaotao/modules/inspection/task/IfsInspectionHistoryTask.java

@ -26,11 +26,11 @@ public class IfsInspectionHistoryTask {
*/
private final ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
@Scheduled(cron = "0 02 16 * * ?")
/* @Scheduled(cron = "0 02 16 * * ?")
public void syncIfsInspectionHistory() {
log.info("=== 开始执行IFS检验历史同步定时任务 ===");
doSync(1);
}
}*/
private void doSync(int attempt) {
try {

20
src/main/java/com/gaotao/modules/po/service/impl/PoServiceImpl.java

@ -17,6 +17,7 @@ import com.gaotao.modules.handlingunit.entity.HandlingUnit;
import com.gaotao.modules.handlingunit.entity.HandlingUnitDetail;
import com.gaotao.modules.handlingunit.service.HandlingUnitDetailService;
import com.gaotao.modules.handlingunit.service.HandlingUnitService;
import com.gaotao.modules.handlingunit.service.HandlingUnitIdGeneratorService;
import com.gaotao.modules.po.dao.PoMapper;
import com.gaotao.modules.po.entity.PoReceipt;
import com.gaotao.modules.po.entity.PoReceiptDetail;
@ -66,6 +67,8 @@ public class PoServiceImpl extends ServiceImpl<PoMapper, PurchaseOrder> implemen
private AgvClientUtil agvClientUtil;
@Autowired
private AccessSiteMapper accessSiteMapper;
@Autowired
private HandlingUnitIdGeneratorService handlingUnitIdGeneratorService;
@Value("${custom.ifs-url}")
private String ifsUrl;
@ -200,10 +203,10 @@ public class PoServiceImpl extends ServiceImpl<PoMapper, PurchaseOrder> implemen
private void handlingUnitPart(TransDetailDto inData, int i, TransHeader transHeader, SysUserEntity currentUser, Integer shelfLife) {
TransDetailSubDto huInfo = inData.getHandlingUnitList().get(i);
String subType = "HU";
for (int j = 0; j < huInfo.getPerQty(); j++) {
// 获取流水号
TransNoControl huTrans = transNoService.getTransNo(inData.getSite(), subType, 10);
// 生成处理单元ID - 使用新的格式A+site+YYYYMMDD+8位自增流水码
String unitId = handlingUnitIdGeneratorService.generateUnitId(inData.getSite());
// 创建TransDetailSub记录保持原有逻辑
TransDetailSub transDetailSub = new TransDetailSub();
transDetailSub.setSite(inData.getSite());
@ -212,17 +215,16 @@ public class PoServiceImpl extends ServiceImpl<PoMapper, PurchaseOrder> implemen
transDetailSub.setSeqNo(inData.getItemNo());
transDetailSub.setSubQty(huInfo.getPackageQty());
transDetailSub.setOrderRef1(inData.getPoNo());
transDetailSub.setOrderRef2(huTrans.getNewTransNo());
transDetailSub.setOrderRef2(unitId);
transDetailSub.setLocationId(inData.getLocationNo());
transDetailSub.setBatchNo(inData.getBatchNo());
transDetailSub.setPartNo(inData.getPartNo());
transDetailSub.setSubNo(huTrans.getNewTransNo());
transDetailSub.setSubNo(unitId);
transDetailSub.setOrderRef3(inData.getWdr());
transDetailSub.setDirection("+");
subService.save(transDetailSub);
// 创建HandlingUnit主记录
HandlingUnit handlingUnit = new HandlingUnit();
// 生成处理单元ID
String unitId = huTrans.getNewTransNo();
handlingUnit.setUnitId(unitId);
handlingUnit.setSite(inData.getSite());
handlingUnit.setUnitType("ROLL");
@ -303,6 +305,7 @@ public class PoServiceImpl extends ServiceImpl<PoMapper, PurchaseOrder> implemen
String pmResponse = HttpUtils.doGetWithBody(ifsUrl+"POLineSupplierMaterial",pmJsonBody,null);
List<Map<String, Object>> poLineData = objectMapper.readValue(pmResponse, new TypeReference<>() {});
if (poLineData.isEmpty()) {
log.info("普通ordinary PO,PO号: {}", inData.getOrderNo());
return null;
} else {
// 获取对应行号和releaseNo的数据
@ -310,6 +313,7 @@ public class PoServiceImpl extends ServiceImpl<PoMapper, PurchaseOrder> implemen
String lineNo = line.get("lineNo") != null ? line.get("lineNo").toString() : "";
String releaseNo = line.get("releaseNo") != null ? line.get("releaseNo").toString() : "";
if (inData.getLineNo().equals(lineNo) && (inData.getReleaseNo() != null && inData.getReleaseNo().equals(releaseNo))) {
log.info("委外ordinary PO,PO号: {}", inData.getOrderNo());
return line;
}
}
@ -615,7 +619,7 @@ public class PoServiceImpl extends ServiceImpl<PoMapper, PurchaseOrder> implemen
if (inData.getPurchaseUOM() != null && !"KG".equalsIgnoreCase(inData.getPurchaseUOM())) {
poReceiptDetail.setWidth(BigDecimal.valueOf(1000));
} else {
poReceiptDetail.setWidth(BigDecimal.valueOf(0));
poReceiptDetail.setWidth(null);
}
}
// length就是数量除以width再乘以1000
@ -625,7 +629,7 @@ public class PoServiceImpl extends ServiceImpl<PoMapper, PurchaseOrder> implemen
.multiply(BigDecimal.valueOf(1000));
poReceiptDetail.setLength(length);
} else {
poReceiptDetail.setLength(BigDecimal.valueOf(0));
poReceiptDetail.setLength(null);
}
// 备注信息
String remarkText = "PO接收自动创建";

3
src/main/resources/mapper/base/BaseMapper.xml

@ -503,6 +503,9 @@
<if test="params.locationId != null and params.locationId != ''">
AND location_id = #{params.locationId}
</if>
<if test="params.wdr != null and params.wdr != ''">
AND wdr = #{params.wdr}
</if>
<!-- 可以根据需要添加更多参数 -->
</if>
</where>

Loading…
Cancel
Save