UDI验证,GS1条码解析bug

master
anthonyywj2 3 years ago
parent ed65e148c1
commit ba05613dbb

@ -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<ProductInfoEntity> 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码格式错误");
}
}
}
}

@ -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;
}

@ -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<Character> iterator(String value) {
return value.chars().mapToObj(c -> (char) c).iterator();
}
public static String value(AI ai, Iterator<Character> 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<Character> iterator(String value) {
return value.chars().mapToObj(c -> (char) c).iterator();
}
}
public static String value(Session session, String value) {
Iterator<Character> iterator = iterator(value);
if (session.isVaried()) {
return variedValue(iterator);
} else {
return fixedValue(session.getLength(), iterator);
public static String value(AI ai, Iterator<Character> 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<Character> 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<Character> iterator = iterator(value);
if (session.isVaried()) {
return variedValue(iterator);
} else {
return fixedValue(session.getLength(), iterator);
}
}
return builder.toString();
}
private static String variedValue(Iterator<Character> 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<Character> 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<Character> 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();
}
}

Loading…
Cancel
Save