From ba05613dbb06ceea195067b2c7696b6bde5ab08d Mon Sep 17 00:00:00 2001 From: anthonyywj2 <353682448@qq.com> Date: Thu, 29 Sep 2022 09:14:34 +0800 Subject: [PATCH] =?UTF-8?q?UDI=E9=AA=8C=E8=AF=81=EF=BC=8CGS1=E6=9D=A1?= =?UTF-8?q?=E7=A0=81=E8=A7=A3=E6=9E=90bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../device/ProductInfoController.java | 64 ++++++++++++++ .../udidl/admin/res/udid/VailUdiReponse.java | 10 +++ .../udidl/admin/util/gs1/Gs1128Utils.java | 88 ++++++++++--------- 3 files changed, 119 insertions(+), 43 deletions(-) create mode 100644 src/main/java/com/glxp/udidl/admin/res/udid/VailUdiReponse.java diff --git a/src/main/java/com/glxp/udidl/admin/controller/device/ProductInfoController.java b/src/main/java/com/glxp/udidl/admin/controller/device/ProductInfoController.java index 12c400b..a00389f 100644 --- a/src/main/java/com/glxp/udidl/admin/controller/device/ProductInfoController.java +++ b/src/main/java/com/glxp/udidl/admin/controller/device/ProductInfoController.java @@ -1,5 +1,6 @@ package com.glxp.udidl.admin.controller.device; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; import com.github.pagehelper.PageInfo; import com.glxp.udidl.admin.annotation.AuthRuleAnnotation; @@ -13,6 +14,7 @@ import com.glxp.udidl.admin.req.UdiCompanyRequest; import com.glxp.udidl.admin.res.BaseResponse; import com.glxp.udidl.admin.res.PageSimpleResponse; import com.glxp.udidl.admin.res.udid.ProductInfoResponse; +import com.glxp.udidl.admin.res.udid.VailUdiReponse; import com.glxp.udidl.admin.service.inout.ProductInfoService; import com.glxp.udidl.admin.service.udi.UdiCompanyService; import com.glxp.udidl.admin.util.BeanUtils; @@ -356,4 +358,66 @@ public class ProductInfoController { return ResultVOUtils.success(productInfoService.findLastVersion(productInfoFilterRequest)); } + + @ApiOperation(value = "校验UDI完整性", response = ProductInfoEntity.class) + @ApiImplicitParams({@ApiImplicitParam(name = "code", value = "UDI码", required = true)}) + @GetMapping("udidl/device/vailUdiCode") + public BaseResponse vailUdiCode(String code) { + + if (StrUtil.isEmpty(code)) { + return ResultVOUtils.error(500, "查询条件不能为空!"); + } + UdiEntity udiEntity = FilterUdiUtils.getUdi(code); + if (udiEntity == null) { + return ResultVOUtils.error(500, "UDI码格式错误!"); + } else { + if (StrUtil.isNotEmpty(udiEntity.getUdi())) { + ProductInfoFilterRequest productInfoFilterRequest = new ProductInfoFilterRequest(); + productInfoFilterRequest.setNameCode(udiEntity.getUdi()); + List productInfoEntityList = productInfoService.filterProductInfo(productInfoFilterRequest); + if (CollUtil.isEmpty(productInfoEntityList)) { + return ResultVOUtils.error(500, "未查询到该UDI码国家库产品信息!"); + } else { + ProductInfoEntity productInfoEntity = productInfoEntityList.get(0); + String lostMsg = ""; + boolean checkSuccess = true; + if ("是".equals(productInfoEntity.getScbssfbhph()) && StrUtil.isEmpty(udiEntity.getBatchNo())) { + checkSuccess = false; + lostMsg = lostMsg + ",批次号"; + } + if ("是".equals(productInfoEntity.getScbssfbhscrq()) && StrUtil.isEmpty(udiEntity.getProduceDate())) { + checkSuccess = false; + lostMsg = lostMsg + ",生产日期"; + } + + if ("是".equals(productInfoEntity.getScbssfbhsxrq()) && StrUtil.isEmpty(udiEntity.getExpireDate())) { + checkSuccess = false; + lostMsg = lostMsg + ",失效日期"; + } + if (("是".equals(productInfoEntity.getScbssfbhxlh()) && StrUtil.isEmpty(udiEntity.getSerialNo())) + ) { + checkSuccess = false; + lostMsg = lostMsg + ",序列号"; + } + if (StrUtil.isNotEmpty(udiEntity.getSerialNo()) && udiEntity.getSerialNo().length() > 20) { + return ResultVOUtils.error(504, "序列号超出20位!"); + } + if (StrUtil.isNotEmpty(udiEntity.getBatchNo()) && udiEntity.getBatchNo().length() > 20) { + return ResultVOUtils.error(504, "批次号超出20位!"); + } + if (StrUtil.isEmpty(udiEntity.getSerialNo()) && StrUtil.isEmpty(udiEntity.getBatchNo())) { + checkSuccess = false; + } + if (checkSuccess) { + return ResultVOUtils.success(productInfoEntity); + } else { + return ResultVOUtils.error(500, "UDI码格式错误,缺少"+lostMsg.substring(1)); + } + } + } else { + return ResultVOUtils.error(500, "UDI码格式错误!"); + } + } + + } } diff --git a/src/main/java/com/glxp/udidl/admin/res/udid/VailUdiReponse.java b/src/main/java/com/glxp/udidl/admin/res/udid/VailUdiReponse.java new file mode 100644 index 0000000..fcac0f6 --- /dev/null +++ b/src/main/java/com/glxp/udidl/admin/res/udid/VailUdiReponse.java @@ -0,0 +1,10 @@ +package com.glxp.udidl.admin.res.udid; + +import com.glxp.udidl.admin.entity.udi.ProductInfoEntity; +import lombok.Data; + +@Data +public class VailUdiReponse { + private String errMsg; + private ProductInfoEntity productInfoEntity; +} diff --git a/src/main/java/com/glxp/udidl/admin/util/gs1/Gs1128Utils.java b/src/main/java/com/glxp/udidl/admin/util/gs1/Gs1128Utils.java index 91566e0..264a5a7 100644 --- a/src/main/java/com/glxp/udidl/admin/util/gs1/Gs1128Utils.java +++ b/src/main/java/com/glxp/udidl/admin/util/gs1/Gs1128Utils.java @@ -7,53 +7,55 @@ import java.util.Iterator; */ final class Gs1128Utils { - public static final String PREFIX = "]C1"; - public static final char END_AI_VARIED = (char) 29; - - private Gs1128Utils() { - super(); - } - - public static Iterator iterator(String value) { - return value.chars().mapToObj(c -> (char) c).iterator(); - } - - public static String value(AI ai, Iterator iterator) { - Format format = Format.valueOf(ai.getFormat()); - if (format.isVaried()) { - return variedValue(iterator); - } else { - return fixedValue(format.getLength(), iterator); + public static final String PREFIX = "]C1"; + public static final char END_AI_VARIED = (char) 29; + + private Gs1128Utils() { + super(); + } + + public static Iterator iterator(String value) { + return value.chars().mapToObj(c -> (char) c).iterator(); } - } - - public static String value(Session session, String value) { - Iterator iterator = iterator(value); - if (session.isVaried()) { - return variedValue(iterator); - } else { - return fixedValue(session.getLength(), iterator); + + public static String value(AI ai, Iterator iterator) { + Format format = Format.valueOf(ai.getFormat()); + if (format.isVaried()) { + return variedValue(iterator); + } else { + return fixedValue(format.getLength(), iterator); + } } - } - private static String fixedValue(int size, Iterator iterator) { - StringBuilder builder = new StringBuilder(); - for (int i = 0; i < size; i++) { - builder.append(iterator.next()); + public static String value(Session session, String value) { + Iterator iterator = iterator(value); + if (session.isVaried()) { + return variedValue(iterator); + } else { + return fixedValue(session.getLength(), iterator); + } } - return builder.toString(); - } - - private static String variedValue(Iterator iterator) { - StringBuilder builder = new StringBuilder(); - while (iterator.hasNext()) { - char value = iterator.next(); - if (value == END_AI_VARIED) { - break; - } - builder.append(value); + + private static String fixedValue(int size, Iterator iterator) { + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < size; i++) { + if (iterator.hasNext()) { + builder.append(iterator.next()); + } + } + return builder.toString(); + } + + private static String variedValue(Iterator iterator) { + StringBuilder builder = new StringBuilder(); + while (iterator.hasNext()) { + char value = iterator.next(); + if (value == END_AI_VARIED) { + break; + } + builder.append(value); + } + return builder.toString(); } - return builder.toString(); - } }