diff --git a/src/main/java/com/glxp/api/controller/inout/IoOrderDetailBizController.java b/src/main/java/com/glxp/api/controller/inout/IoOrderDetailBizController.java index 7bf8cd24..209661f4 100644 --- a/src/main/java/com/glxp/api/controller/inout/IoOrderDetailBizController.java +++ b/src/main/java/com/glxp/api/controller/inout/IoOrderDetailBizController.java @@ -795,14 +795,14 @@ public class IoOrderDetailBizController extends BaseController { addBizProductReqeust.setOrderEntity(ioOrderEntity); } addBizProductReqeust.setProductType(udiRelevanceResponse.getProductType()); - BaseResponse response = orderDetailBizService.addBizProduct(addBizProductReqeust); - if (response.getCode() != 20000) { - return response; - } - if (i == 0) { - ioOrderEntity = JSONObject.parseObject(JSONObject.toJSONString(response.getData()), IoOrderEntity.class); - addBizProductReqeust.setOrderEntity(ioOrderEntity); - } +// BaseResponse response = orderDetailBizService.addBizProduct(addBizProductReqeust); +// if (response.getCode() != 20000) { +// return response; +// } +// if (i == 0) { +// ioOrderEntity = JSONObject.parseObject(JSONObject.toJSONString(response.getData()), IoOrderEntity.class); +// addBizProductReqeust.setOrderEntity(ioOrderEntity); +// } AddOrderRequest addOrderRequest = new AddOrderRequest(); BeanUtils.copyProperties(ioOrderEntity, addOrderRequest); diff --git a/src/main/java/com/glxp/api/service/inout/IoCheckInoutService.java b/src/main/java/com/glxp/api/service/inout/IoCheckInoutService.java index c5573ae7..69799149 100644 --- a/src/main/java/com/glxp/api/service/inout/IoCheckInoutService.java +++ b/src/main/java/com/glxp/api/service/inout/IoCheckInoutService.java @@ -347,14 +347,18 @@ public class IoCheckInoutService { curCount = codeEntity.getMyReCount(); } // TODO 药品单据临时数量超出不做校验(为了湖里妇幼) - if(!codeEntity.getProductType().equals(2)){ + if (!codeEntity.getProductType().equals(2)) { if (curCount > bizEntity.getCount()) { - return "当前产品" + bizEntity.getCoName() + "数量超出!"; + return "当前产品" + bizEntity.getCoName() + "数量超出!"; } } - if (bizEntity.getPrice() != null) codeEntity.setPrice(bizEntity.getPrice()); + if (StrUtil.isNotEmpty(codeEntity.getProduceDate()) && StrUtil.isEmpty(bizEntity.getProductDate())) { + bizEntity.setProductDate(codeEntity.getProduceDate()); + bizEntity.setExpireDate(codeEntity.getExpireDate()); + orderDetailBizService.update(bizEntity); + } return null; } diff --git a/src/main/java/com/glxp/api/service/inout/impl/IoOrderDetailBizServiceImpl.java b/src/main/java/com/glxp/api/service/inout/impl/IoOrderDetailBizServiceImpl.java index 13fd0422..39b3b08c 100644 --- a/src/main/java/com/glxp/api/service/inout/impl/IoOrderDetailBizServiceImpl.java +++ b/src/main/java/com/glxp/api/service/inout/impl/IoOrderDetailBizServiceImpl.java @@ -69,6 +69,7 @@ public class IoOrderDetailBizServiceImpl implements IoOrderDetailBizService { IoOrderInvoiceMapper ioOrderInvoiceMapper; @Resource IoOrderDetailCodeDao orderDetailCodeDao; + @Override public IoOrderDetailBizEntity selectById(Long id) { return ioOrderDetailBizDao.selectById(id); @@ -443,7 +444,9 @@ public class IoOrderDetailBizServiceImpl implements IoOrderDetailBizService { ioOrderDetailBizEntity.setUuidFk(udiRelevanceResponse.getUuid()); ioOrderDetailBizEntity.setNameCode(udiRelevanceResponse.getNameCode()); ioOrderDetailBizEntity.setCoName(udiRelevanceResponse.getCpmctymc()); - ioOrderDetailBizEntity.setCertCode(addBizProductReqeust.getZczbhhzbapzbh()); + if (StrUtil.isNotEmpty(addBizProductReqeust.getZczbhhzbapzbh())) + ioOrderDetailBizEntity.setCertCode(addBizProductReqeust.getZczbhhzbapzbh()); + else ioOrderDetailBizEntity.setCertCode(udiRelevanceResponse.getZczbhhzbapzbh()); ioOrderDetailBizEntity.setYlqxzcrbarmc(udiRelevanceResponse.getYlqxzcrbarmc()); ioOrderDetailBizEntity.setManufacturer(udiRelevanceResponse.getManufactory()); ioOrderDetailBizEntity.setMeasname(udiRelevanceResponse.getMeasname()); @@ -456,14 +459,14 @@ public class IoOrderDetailBizServiceImpl implements IoOrderDetailBizService { ioOrderDetailBizEntity.setYcBizNo(item.getYcBizNo()); if (item.getCount() != null) ioOrderDetailBizEntity.setCount(item.getCount()); String salesInvoiceNumberSecondTicket = item.getSalesInvoiceNumberSecondTicket(); - if (StrUtil.isNotEmpty(salesInvoiceNumberSecondTicket)){ + if (StrUtil.isNotEmpty(salesInvoiceNumberSecondTicket)) { ioOrderDetailBizEntity.setRegStatus(true); } this.insert(ioOrderDetailBizEntity); //补充发票号 - if (StrUtil.isNotEmpty(salesInvoiceNumberSecondTicket)){ + if (StrUtil.isNotEmpty(salesInvoiceNumberSecondTicket)) { IoOrderInvoiceEntity ioOrderInvoiceEntity = new IoOrderInvoiceEntity(); ioOrderInvoiceEntity.setOrderIdFk(ioOrderDetailBizEntity.getOrderIdFk()); diff --git a/src/main/java/com/glxp/api/util/udi/FilterUdiUtils2.java b/src/main/java/com/glxp/api/util/udi/FilterUdiUtils2.java new file mode 100644 index 00000000..69accc84 --- /dev/null +++ b/src/main/java/com/glxp/api/util/udi/FilterUdiUtils2.java @@ -0,0 +1,276 @@ +package com.glxp.api.util.udi; + + +import cn.hutool.core.util.StrUtil; +import com.glxp.api.entity.basic.UdiEntity; +import com.glxp.api.util.gs1.AI; +import com.glxp.api.util.gs1.AIs; +import com.glxp.api.util.gs1.Gs1128Decoder; +import com.glxp.api.util.gs1.Gs1128Engine; + +import java.util.Map; + +public class FilterUdiUtils2 { + private static final String TAG = "FilterUdiUtils"; + private static final char GS = '\u001D'; // GS1分组分隔符 + + public static UdiEntity getUdi(String data) { + if (data == null || data.length() <= 2) { + return null; + } + + // 1. 处理原有的带标识的情况 + if (data.startsWith("MA")) { + return getZGCUdi(data); + } else if (data.startsWith("#")) { + return getGLXPUdi(data); + } else if (data.length() >= 18 && data.startsWith("8")) { + return getDrugInfo(data); + } + + // 2. 处理GS1编码情况(包括有无标识的情况) + if (data.startsWith("]C1")) { + // 已经带有GS1标识,直接去除]C1后处理 + return getGS1Udi(data.substring(3)); + } else if (data.contains(String.valueOf(GS))) { + // 包含GS分隔符的GS1编码 + return getGS1Udi(data); + } else if (data.startsWith("01")) { + // 没有GS1标识但是以01开头,说明是GS1编码,补充标识后处理 + return getGS1Udi(addGSSeparators(data)); + } else if (isGS1Format(data)) { + // 尝试判断是否符合GS1格式 + return getGS1Udi(addGSSeparators(data)); + } + + return null; + } + + /** + * 判断是否符合GS1格式的编码 + * GS1编码通常以应用标识符(AI)开头,如01、10、17、21等 + * + * @param data 待检查的编码 + * @return 是否符合GS1格式 + */ + private static boolean isGS1Format(String data) { + if (data == null || data.length() < 14) { // GS1编码至少14位 + return false; + } + + // 检查是否以常见的GS1应用标识符开头 + String[] commonAIs = {"01", "10", "17", "21", "11", "13", "30"}; + for (String ai : commonAIs) { + if (data.startsWith(ai)) { + return true; + } + } + + // 检查数据结构是否符合GS1格式(数字组成,长度合理等) + return data.matches("^\\d{14,}$") && // 至少14位数字 + (data.length() % 2 == 0); // GS1编码通常是偶数位 + } + + /** + * 为GS1编码添加分组分隔符 + * 根据GS1编码规则,只需在序列号(21)前添加分隔符 + * + * @param data 原始编码 + * @return 添加分隔符后的编码 + */ + private static String addGSSeparators(String data) { + if (data == null || data.length() < 14) { + return data; + } + + // 查找序列号标识符(21)的位置 + int position = data.indexOf("21", 14); // 从GTIN后开始查找 + if (position > 0) { + return data.substring(0, position) + GS + data.substring(position); + } + + return data; + } + + /** + * 获取不同应用标识符(AI)的数据长度 + * + * @param ai 应用标识符 + * @return 对应的数据长度,-1表示未知长度 + */ + private static int getAILength(String ai) { + switch (ai) { + case "01": + return 16; // GTIN (AI(01) + 14位数字) + case "10": + return 4 + 6; // BATCH/LOT (AI(10) + 最多6位) + case "17": + return 4 + 6; // EXPIRY (AI(17) + 6位日期) + case "11": + return 4 + 6; // PROD DATE (AI(11) + 6位日期) + case "21": + return 4 + 6; // SERIAL (AI(21) + 最多6位) + default: + return -1; + } + } + + public static void main(String[] args) { + test(); + } + + public static void test() { + String udiCode1 = "010693845081130011250101172801012100110001"; + UdiEntity result1 = FilterUdiUtils.getUdi(udiCode1); + result1.toString(); + } + + public static UdiEntity getGS1Udi(String data) { + // 如果没有GS1标识,添加]C1前缀 + String fullData = data.startsWith("]C1") ? data : "]C1" + data; + + // 确保编码中包含GS分隔符,且不是以]C1开头的原始数据 + if (!fullData.contains(String.valueOf(GS)) && !data.startsWith("]C1")) { + fullData = "]C1" + addGSSeparators(data); + } + + Gs1128Engine engine = new Gs1128Engine(); + Gs1128Decoder decoder = engine.decoder(); + Map result = decoder.decode(fullData); + UdiEntity udiEntity = new UdiEntity(); + int length = 0; + for (Map.Entry entry : result.entrySet()) { + length = length + entry.getValue().length(); + if (entry.getKey() == AIs.GTIN) { + udiEntity.setUdi(entry.getValue()); + } else if (entry.getKey() == AIs.BATCH_LOT) { + udiEntity.setBatchNo(entry.getValue()); + } else if (entry.getKey() == AIs.EXPIRY) { + udiEntity.setExpireDate(entry.getValue()); + } else if (entry.getKey() == AIs.PROD_DATE) { + udiEntity.setProduceDate(entry.getValue()); + } else if (entry.getKey() == AIs.SERIAL) { + udiEntity.setSerialNo(entry.getValue()); + } + } + if (data.length() - length > 22) { + return null; + } + if (StrUtil.isEmpty(udiEntity.getUdi())) { + return null; + } + if (udiEntity.getUdi().length() < 14 + ) { + return null; + } else + return udiEntity; + } + + public static UdiEntity getZGCUdi(String data) { + String batchNo = ""; + String produceDate = ""; + String expireDate = ""; + String serialNo = null; + String nameCode = ""; + String[] spilts = data.split("[.]"); + if (spilts != null && spilts.length >= 5) { + for (int i = 0; i < 5; i++) { + nameCode = nameCode + "." + spilts[i]; + } + nameCode = nameCode.substring(1); + for (int i = 0; i < spilts.length; i++) { + String tempStr = spilts[i]; + if (tempStr != null && tempStr.length() > 1 && tempStr.substring(0, 1).equals("M")) { + produceDate = tempStr.substring(1); + } else if (tempStr != null && tempStr.length() > 1 && tempStr.substring(0, 1).equals("L")) { + batchNo = tempStr.substring(1); + } else if (tempStr != null && tempStr.length() > 1 && tempStr.substring(0, 1).equals("E")) { + expireDate = tempStr.substring(1); + } else if (tempStr != null && tempStr.length() > 1 && tempStr.substring(0, 1).equals("S")) { + serialNo = tempStr.substring(1); + } + } + } + + UdiEntity udiEntity = new UdiEntity(); + udiEntity.setBatchNo(batchNo); + udiEntity.setExpireDate(expireDate); + udiEntity.setProduceDate(produceDate); + udiEntity.setUdi(nameCode); + udiEntity.setSerialNo(serialNo); + return udiEntity; + + } + + public static UdiEntity getGLXPUdi(String data) { + String batchNo = ""; + String produceDate = ""; + String expireDate = ""; + String serialNo = null; + String udi = ""; + String[] spilts = data.split("#", data.length()); + if (spilts != null && spilts.length >= 5) { + udi = spilts[1]; + produceDate = spilts[2]; + expireDate = spilts[3]; + batchNo = spilts[4]; + if (spilts.length > 6) { + serialNo = spilts[5]; + } + + if (StrUtil.isEmpty(batchNo)) { + batchNo = null; + } + if (StrUtil.isEmpty(serialNo)) { + serialNo = null; + } + + } + UdiEntity udiEntity = new UdiEntity(); + udiEntity.setBatchNo(batchNo); + udiEntity.setExpireDate(expireDate); + udiEntity.setProduceDate(produceDate); + udiEntity.setUdi(udi); + udiEntity.setSerialNo(serialNo); + return udiEntity; + } + + public static String getDiStr(String data) { + String prefix = ""; + if (data != null && data.length() > 2) { + if (data.substring(0, 2).equals("MA")) { + String[] spilts = data.split("[.]"); + if (spilts != null && spilts.length >= 5) { + for (int i = 0; i < 5; i++) { + prefix = prefix + "." + spilts[i]; + } + prefix = prefix.substring(1); + } + } else if (data.substring(0, 2).equals("01") && data.length() >= 16) { + prefix = data.substring(2, 16); + } else if (data.substring(0, 1).equals("#")) { + String[] spilts = data.split("#"); + if (spilts != null && spilts.length >= 1) + prefix = spilts[1]; + } + } + if (prefix.equals("")) + return data; + return prefix; + } + + + public static UdiEntity getDrugInfo(String data) { + UdiEntity udiEntity = new UdiEntity(); + String prefix = data.substring(0, 7); + String serialNo = data.substring(7, 16); + udiEntity.setBatchNo(null); + udiEntity.setExpireDate(null); + udiEntity.setProduceDate(null); + udiEntity.setUdi(prefix); + udiEntity.setSerialNo(serialNo); + return udiEntity; + } + + +}