From ace1830bbbe632132a5262c9d98952660f37dc18 Mon Sep 17 00:00:00 2001 From: yewj Date: Wed, 23 Oct 2024 14:02:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=A4=87=E4=BB=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../inout/IoCodeTempController.java | 28 ++++-- .../inout/IoSplitFifoInvController.java | 2 +- .../com/glxp/api/util/VailBatchCodeUtils.java | 97 +++++++++++++++++++ src/main/resources/application-dev.yml | 4 +- 4 files changed, 122 insertions(+), 9 deletions(-) create mode 100644 src/main/java/com/glxp/api/util/VailBatchCodeUtils.java diff --git a/src/main/java/com/glxp/api/controller/inout/IoCodeTempController.java b/src/main/java/com/glxp/api/controller/inout/IoCodeTempController.java index dc2d155f0..fd35781f4 100644 --- a/src/main/java/com/glxp/api/controller/inout/IoCodeTempController.java +++ b/src/main/java/com/glxp/api/controller/inout/IoCodeTempController.java @@ -404,12 +404,14 @@ public class IoCodeTempController extends BaseController { codeList = codeList.stream().distinct().collect(Collectors.toList()); List vailCodeResultResponses = new ArrayList<>(); List prefixes = Arrays.asList("01", "11", "17", "10", "21"); - //判断是否多段扫码 - String mutiCode = filterAndConcatenate(codeList, prefixes); - UdiEntity temp = FilterUdiUtils.getUdi(mutiCode); - if (temp != null) { - codeList.clear(); - codeList.add(mutiCode); + if (hasMoreThanTwoPrefixes(codeList, prefixes.toArray(new String[0]))) { + //判断是否多段扫码 + String mutiCode = filterAndConcatenate(codeList, prefixes); + UdiEntity temp = FilterUdiUtils.getUdi(mutiCode); + if (temp != null) { + codeList.clear(); + codeList.add(mutiCode); + } } for (String code : codeList) { VailCodeResultResponse vailCodeResultResponse = new VailCodeResultResponse(); @@ -433,6 +435,20 @@ public class IoCodeTempController extends BaseController { return ResultVOUtils.success(vailCodeResultResponses); } + public static boolean hasMoreThanTwoPrefixes(List codes, String[] prefixes) { + int uniquePrefixCount = 0; + boolean[] prefixFound = new boolean[prefixes.length]; + for (String code : codes) { + for (int i = 0; i < prefixes.length; i++) { + if (code.startsWith(prefixes[i]) && !prefixFound[i]) { + prefixFound[i] = true; + uniquePrefixCount++; + break; + } + } + } + return uniquePrefixCount > 1; + } public static String filterAndConcatenate(List codeList, List prefixes) { Set matchedPrefixes = new HashSet<>(); diff --git a/src/main/java/com/glxp/api/controller/inout/IoSplitFifoInvController.java b/src/main/java/com/glxp/api/controller/inout/IoSplitFifoInvController.java index 5993c3641..ce5865271 100644 --- a/src/main/java/com/glxp/api/controller/inout/IoSplitFifoInvController.java +++ b/src/main/java/com/glxp/api/controller/inout/IoSplitFifoInvController.java @@ -55,7 +55,7 @@ public class IoSplitFifoInvController extends BaseController { Long workPlaceCode = ioSplitFifoInvRequest.getWorkPlaceCode(); SysWorkplace workplace = sysWorkplaceService.getWorkplace(workPlaceCode); Integer workPlaceClass = workplace.getWorkPlaceClass(); - if (workPlaceClass == 1){ + if (workPlaceClass == 1) { SysWorkplacePutRel putWorkPlace = sysWorkplacePutRelService.findPutWorkPlace(workPlaceCode, null); ioSplitFifoInvRequest.setWorkPlaceCode(putWorkPlace.getWorkPlaceCode()); } diff --git a/src/main/java/com/glxp/api/util/VailBatchCodeUtils.java b/src/main/java/com/glxp/api/util/VailBatchCodeUtils.java new file mode 100644 index 000000000..555be292f --- /dev/null +++ b/src/main/java/com/glxp/api/util/VailBatchCodeUtils.java @@ -0,0 +1,97 @@ +package com.glxp.api.util; + + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.StrUtil; +import com.glxp.api.entity.basic.UdiEntity; +import com.glxp.api.res.inout.VailCodeResultResponse; +import com.glxp.api.util.udi.FilterUdiUtils; + +import java.util.*; +import java.util.stream.Collectors; + +public class VailBatchCodeUtils { + + public static List batchVailCode(String codes) { + List codeList = List.of(codes.split(";")); + if (CollUtil.isEmpty(codeList)) return null; + codeList = codeList.stream().distinct().collect(Collectors.toList()); + List vailCodeResultResponses = new ArrayList<>(); + List prefixes = Arrays.asList("01", "11", "17", "10", "21"); + if (hasMoreThanTwoPrefixes(codeList, prefixes.toArray(new String[0]))) { + //判断是否多段扫码 + String mutiCode = filterAndConcatenate(codeList, prefixes); + UdiEntity temp = FilterUdiUtils.getUdi(mutiCode); + if (temp != null) { + codeList.clear(); + codeList.add(mutiCode); + } + } + + for (String code : codeList) { + VailCodeResultResponse vailCodeResultResponse = new VailCodeResultResponse(); + UdiEntity udiEntity = FilterUdiUtils.getUdi(code); + vailCodeResultResponse.setCode(code); + if (udiEntity != null) { + vailCodeResultResponse.setStatus(1); + vailCodeResultResponse.setErrMsg("解析正确"); + } else { + vailCodeResultResponse.setStatus(2); + vailCodeResultResponse.setErrMsg("追溯码格式错误"); + } + vailCodeResultResponses.add(vailCodeResultResponse); + } + return vailCodeResultResponses; + } + + public static boolean hasMoreThanTwoPrefixes(List codes, String[] prefixes) { + int uniquePrefixCount = 0; + boolean[] prefixFound = new boolean[prefixes.length]; + for (String code : codes) { + for (int i = 0; i < prefixes.length; i++) { + if (code.startsWith(prefixes[i]) && !prefixFound[i]) { + prefixFound[i] = true; + uniquePrefixCount++; + break; + } + } + } + return uniquePrefixCount > 1; + } + + public static void main(String[] args) { + String code = "MA.156.M0.100442.0WET6505.S1394.M230624.L230601.DS22306241.E250624.V250623.C5"; +// String code = "0116922943800657112406011724063010JY999\u001D210003;0118822943800657112406011724063010JY999\u001D210003"; +// String code = "0116922943800657;1124060117240630;10JY999\u001D210003;www.baidu.com;32329382;0118822943800657112406011724063010JY999\u001D210003"; + + List vailCodeResultResponses = batchVailCode(code); + for (VailCodeResultResponse vailCodeResultResponse : vailCodeResultResponses) { + System.out.println(vailCodeResultResponse.getCode() + ":" + vailCodeResultResponse.getStatus() + ":" + vailCodeResultResponse.getErrMsg()); + } + + } + + public static String filterAndConcatenate(List codeList, List prefixes) { + Set matchedPrefixes = new HashSet<>(); + StringBuilder concatenatedResult = new StringBuilder(); + for (String prefix : prefixes) { + for (String code : codeList) { + if (code.length() >= 2 && code.startsWith(prefix)) { + if (!matchedPrefixes.contains(prefix)) { + matchedPrefixes.add(prefix); + concatenatedResult.append(code); + break; + } + } + } + UdiEntity udiEntity = FilterUdiUtils.getUdi(concatenatedResult.toString()); + if (udiEntity != null && StrUtil.isNotEmpty(udiEntity.getBatchNo())) { + if (concatenatedResult.toString().endsWith("10" + udiEntity.getBatchNo())) { + concatenatedResult.append("\u001D"); + } + } + } + return concatenatedResult.toString(); + } + +} diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 794856e96..550f24925 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -4,9 +4,9 @@ server: spring: datasource: driver-class-name: com.p6spy.engine.spy.P6SpyDriver - jdbc-url: jdbc:p6spy:mysql://192.168.0.206:3306/udiwms81?allowMultiQueries=true&serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true + jdbc-url: jdbc:p6spy:mysql://127.0.0.1:3306/udi_wms?allowMultiQueries=true&serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true username: root - password: Glxp@6066 + password: 123456 hikari: connection-timeout: 60000 maximum-pool-size: 20