diff --git a/pom.xml b/pom.xml
index edbd472..9b11842 100644
--- a/pom.xml
+++ b/pom.xml
@@ -191,8 +191,8 @@
maven-compiler-plugin
3.1
- 1.8
- 1.8
+ 9
+ 9
UTF-8
diff --git a/src/main/java/com/glxp/udidl/admin/controller/device/DeviceController.java b/src/main/java/com/glxp/udidl/admin/controller/device/DeviceController.java
index 85f6cbf..9ba2060 100644
--- a/src/main/java/com/glxp/udidl/admin/controller/device/DeviceController.java
+++ b/src/main/java/com/glxp/udidl/admin/controller/device/DeviceController.java
@@ -40,10 +40,6 @@ public class DeviceController {
private DeviceService deviceService;
@Resource
private DevicedownloadMapper devicedownloadMapper;
- @Resource
- ProductInfoService productInfoService;
- @Resource
- DownloadDeviceHelper downloadDeviceHelper;
@ApiOperation(value = "查询医疗器械信息", response = DeviceEntity.class)
@AuthRuleAnnotation("warehouse/device/list")
@@ -89,13 +85,9 @@ public class DeviceController {
}
String key = deviceListRequest.getKey();
- boolean isScan = false;
if (key != null) {
key = FilterUdiUtils.getDiStr(key);
deviceListRequest.setKey(key);
- isScan = true;
- } else {
-
}
DeviceSearchRequest deviceSearchRequest = new DeviceSearchRequest();
deviceSearchRequest.setZxxsdycpbs(key);
@@ -137,186 +129,4 @@ public class DeviceController {
pageSimpleResponse.setList(deviceEntityList);
return ResultVOUtils.success(pageSimpleResponse);
}
-
- @Deprecated
- @ApiOperation(value = "", hidden = true)
- @GetMapping("warehouse/device/unionSearch")
- public BaseResponse search(@Valid DeviceSearchRequest deviceSearchRequest, BindingResult bindingResult) {
- if (bindingResult.hasErrors()) {
- return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
- }
-
- List medicalResonseList = deviceService.search(deviceSearchRequest);
- long total = deviceService.seatchTotal(deviceSearchRequest);
- PageSimpleResponse pageSimpleResponse = new PageSimpleResponse<>();
- pageSimpleResponse.setTotal(total);
- pageSimpleResponse.setList(medicalResonseList);
- return ResultVOUtils.success(pageSimpleResponse);
- }
-
- @Deprecated
- @ApiOperation(value = "", hidden = true)
- @GetMapping("warehouse/device/combineSearch")
- public BaseResponse combineSearch(@Valid DeviceSearchRequest deviceSearchRequest, BindingResult bindingResult) {
-
- if (bindingResult.hasErrors()) {
- return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
- }
-
- List medicalResonseList = deviceService.search(deviceSearchRequest);
-
- long total = 0;
- PageSimpleResponse pageSimpleResponse = new PageSimpleResponse<>();
- List devicedownloads = devicedownloadMapper.selectByExample(new DevicedownloadExample());
- Devicedownload devicedownload;
- if (devicedownloads != null && devicedownloads.size() > 0) {
- devicedownload = devicedownloads.get(0);
- total = devicedownload.getAlltotal() - devicedownload.getAllindex();
- }
-
-
- pageSimpleResponse.setTotal(total * 10);
- pageSimpleResponse.setList(medicalResonseList);
- return ResultVOUtils.success(pageSimpleResponse);
- }
-
- @Deprecated
- @ApiOperation(value = "", hidden = true)
- @PostMapping("warehouse/device/loadsingle")
- public BaseResponse downLoadDiii(@RequestBody DeviceDiRequest deviceRequest) {
-
- if (deviceRequest.getPrimaryDeviceId() == null) {
- return ResultVOUtils.error(999, "最小销售单元标识不能为空");
- }
- new Thread(() -> {
-
- TokenEntity token = downloadDeviceHelper.getToken();
- DownloadDiRequest downloadDiRequest1 = new DownloadDiRequest();
- downloadDiRequest1.setAccessToken(token.getAccessToken());
- downloadDiRequest1.setPrimaryDeviceId(deviceRequest.getPrimaryDeviceId());
- int result = downloadDeviceHelper.downloadBydi(downloadDiRequest1, deviceService, productInfoService);
- if (result == -1) {
- return;// ResultVOUtils.error(505, "下载出错");
- }
-
- }).start();
- return ResultVOUtils.success("开始下载");
- }
-
- @Deprecated
- @ApiOperation(value = "", hidden = true)
- @PostMapping("warehouse/device/downLoadHisory")
- public BaseResponse downLoadHisory(@RequestBody DeviceDiRequest deviceRequest) {
-
- if (deviceRequest.getPrimaryDeviceId() == null) {
- return ResultVOUtils.error(999, "最小销售单元标识不能为空");
- }
- new Thread(() -> {
- String deviceRecordKey = deviceService.selectKey(deviceRequest.getPrimaryDeviceId());
- TokenEntity token = downloadDeviceHelper.getToken();
- DownloadHistoryRequest deviceHistoryRequest = new DownloadHistoryRequest();
- deviceHistoryRequest.setAccessToken(token.getAccessToken());
- deviceHistoryRequest.setCurrentPageNumber("1");
- List dataSetBeans = new ArrayList<>();
- DownloadHistoryRequest.DataSetBean keys = new DownloadHistoryRequest.DataSetBean();
- keys.setDeviceRecordKey(deviceRecordKey);
- dataSetBeans.add(keys);
- deviceHistoryRequest.setDataSet(dataSetBeans);
- int result = downloadDeviceHelper.downloadHistory(deviceHistoryRequest);
- if (result == -1) {
- return;// ResultVOUtils.error(505, "下载出错");
- }
-
- }).start();
- return ResultVOUtils.success("开始下载");
- }
-
- @Deprecated
- @ApiOperation(value = "", hidden = true)
- @PostMapping("warehouse/device/loadudid")
- public BaseResponse downLoadAll(DownloadDeviceRequest downloadDeviceRequest, BindingResult bindingResult) {
-
- if (bindingResult.hasErrors()) {
- return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
- }
- new Thread(() -> {
-
- TokenEntity token = downloadDeviceHelper.getToken();
- int total = downloadDeviceHelper.getTotal(token.getAccessToken());
- int curpage = total;
- Devicedownload devicedownload = devicedownloadMapper.selectByPrimaryKey("udid");
- if (devicedownload != null) {
- int offset = devicedownload.getAlltotal() - devicedownload.getAllindex();
- curpage = total - offset;
- } else {
- devicedownload = new Devicedownload();
- devicedownload.setId("udid");
- devicedownload.setAlltotal(100);
- devicedownload.setAllindex(99);
- devicedownloadMapper.insert(devicedownload);
- }
- devicedownload.setIsdownload(1);
- long startTime = System.currentTimeMillis();
- devicedownload.setStarttime(startTime + "");
- devicedownloadMapper.updateByPrimaryKey(devicedownload);
- Devicedownload stop = devicedownloadMapper.selectByPrimaryKey("udid");
-
- while (curpage > 0 && stop.getIsdownload() == 1 && stop.getStarttime().equals(startTime + "")) {
-
- DeviceRequest deviceRequest = new DeviceRequest();
- deviceRequest.setAccessToken(token.getAccessToken());
- deviceRequest.setRequestType(3 + "");
- deviceRequest.setCurrentPageNumber(curpage + "");
- int result = downloadDeviceHelper.downloadDevices(productInfoService, deviceService, deviceRequest);
- if (result == -1) {
- return;// ResultVOUtils.error(505, "下载出错");
- }
- curpage--;
- Devicedownload devicedownload1 = new Devicedownload();
- devicedownload1.setAlltotal(total);
- devicedownload1.setAllindex(curpage);
- devicedownload1.setId("udid");
- devicedownloadMapper.updateProgress(devicedownload1);
- stop = devicedownloadMapper.selectByPrimaryKey("udid");
- }
- }).start();
- return ResultVOUtils.success("开始下载");
- }
-
- @Deprecated
- @ApiOperation(value = "", hidden = true)
- @GetMapping("warehouse/device/stop")
- public BaseResponse stopDown() {
- Devicedownload devicedownload = devicedownloadMapper.selectByPrimaryKey("udid");
- devicedownload.setIsdownload(2);
- devicedownloadMapper.updateByPrimaryKey(devicedownload);
- return ResultVOUtils.success("停止成功");
- }
-
- @Deprecated
- @ApiOperation(value = "", hidden = true)
- @GetMapping("warehouse/device/progress")
- public BaseResponse getProgress() {
- Devicedownload devicedownload = devicedownloadMapper.selectByPrimaryKey("udid");
- ProgressResponse response = new ProgressResponse();
- if (devicedownload != null) {
- double index = devicedownload.getAlltotal() - devicedownload.getAllindex();
- double total = devicedownload.getAlltotal();
- double progress = 0;
- if (total > 0) {
- progress = index / total;
- }
- response.setTotal(total * 10);
- response.setIndex(index * 10);
- response.setProgress(progress * 100);
- } else {
- response.setTotal(100);
- response.setIndex(1);
- response.setProgress(1);
- }
-
- return ResultVOUtils.success(response);
- }
-
-
}
diff --git a/src/main/java/com/glxp/udidl/admin/controller/device/DownloadDeviceHelper.java b/src/main/java/com/glxp/udidl/admin/controller/device/DownloadDeviceHelper.java
index 629780a..980e420 100644
--- a/src/main/java/com/glxp/udidl/admin/controller/device/DownloadDeviceHelper.java
+++ b/src/main/java/com/glxp/udidl/admin/controller/device/DownloadDeviceHelper.java
@@ -14,12 +14,10 @@ import com.glxp.udidl.admin.res.udid.MedicalSingleResponse;
import com.glxp.udidl.admin.service.info.CompanyService;
import com.glxp.udidl.admin.service.inout.DeviceService;
import com.glxp.udidl.admin.service.inout.ProductInfoService;
-import com.glxp.udidl.admin.service.udi.UdiCompanyService;
import com.glxp.udidl.admin.thread.UdiTransferUtils;
import com.glxp.udidl.admin.util.DateUtil;
import com.glxp.udidl.admin.util.HttpClient;
import com.glxp.udidl.admin.util.WarehousBeanUtils;
-import jdk.nashorn.internal.ir.annotations.Reference;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@@ -37,8 +35,6 @@ public class DownloadDeviceHelper {
String appId;
String appSecret;
@Resource
- UdiCompanyService udiCompanyService;
- @Resource
CompanyService companyService;
@Resource
UdiTransferUtils udiTransferUtils;
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 4261dfd..a2beed2 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
@@ -13,7 +13,6 @@ import com.glxp.udidl.admin.res.PageSimpleResponse;
import com.glxp.udidl.admin.res.udid.ProductInfoResponse;
import com.glxp.udidl.admin.service.inout.ProductInfoService;
import com.glxp.udidl.admin.service.udi.UdiCompanyService;
-import com.glxp.udidl.admin.thread.AsyncDownloadTask;
import com.glxp.udidl.admin.util.FilterUdiUtils;
import com.glxp.udidl.admin.util.ResultVOUtils;
import io.swagger.annotations.Api;
@@ -24,8 +23,6 @@ import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
//udi出入库管理系统API
@Api(tags = "产品信息接口")
@@ -36,8 +33,6 @@ public class ProductInfoController {
ProductInfoService productInfoService;
@Resource
UdiCompanyService udiCompanyService;
- @Resource
- AsyncDownloadTask asyncDownloadTask;
//手持枪扫码查询
@ApiOperation(value = "手持枪扫码查询", response = ProductInfoEntity.class)
@@ -71,8 +66,6 @@ public class ProductInfoController {
}
return ResultVOUtils.success(productInfoResponse);
} else {
- if (key != null && key.length() >= 13)
- asyncDownloadTask.downloadByDi(key); //后台自动下载
return ResultVOUtils.error(500, "未找到产品信息");
}
}
@@ -116,8 +109,6 @@ public class ProductInfoController {
}
return ResultVOUtils.success(productInfoResponse);
} else {
- if (key != null && key.length() >= 13)
- asyncDownloadTask.downloadByDi(key); //后台自动下载
return ResultVOUtils.error(500, "未找到产品信息");
}
}
@@ -261,8 +252,6 @@ public class ProductInfoController {
}
-
-
if (productInfoFilterRequest.getNameCode() != null && !productInfoFilterRequest.getNameCode().equals("") && productInfoFilterRequest.getNameCode().length() < 10) {
return ResultVOUtils.error(500, "请输入完整的最小销售单元标识!");
}
diff --git a/src/main/java/com/glxp/udidl/admin/controller/device/TestController.java b/src/main/java/com/glxp/udidl/admin/controller/device/TestController.java
index 1229eaa..4ed7472 100644
--- a/src/main/java/com/glxp/udidl/admin/controller/device/TestController.java
+++ b/src/main/java/com/glxp/udidl/admin/controller/device/TestController.java
@@ -17,7 +17,6 @@ import com.glxp.udidl.admin.service.dataSync.UdplatSyncService;
import com.glxp.udidl.admin.service.inout.DeviceService;
import com.glxp.udidl.admin.service.inout.ProductInfoService;
import com.glxp.udidl.admin.service.udi.UdiCompanyService;
-import com.glxp.udidl.admin.thread.AsyncDownloadTask;
import com.glxp.udidl.admin.thread.UdiTransferUtils;
import com.glxp.udidl.admin.util.ResultVOUtils;
import org.slf4j.Logger;
@@ -44,8 +43,6 @@ public class TestController {
@Resource
private ProductInfoService productInfoService;
@Resource
- AsyncDownloadTask asyncDownloadTask;
- @Resource
ProductInfoMapper productInfoDao;
@Resource
UdiCompanyService udiCompanyService;
@@ -98,20 +95,6 @@ public class TestController {
}
}
- //https://www.udims.com/UDI_DL_Server/udidl/device/dlBymonth?month=2021-10&page=1
- @GetMapping("udidl/device/dlBymonth")
- public void dlBymonth(String month, int page) {
- logger.info(month + "---按月开启下载");
- asyncDownloadTask.downloadByMonth(month, page);
- }
-
- @GetMapping("udidl/device/dlBymonthTest")
- public void dlBymonthTest(String month, int page) {
-
- logger.info(month + "---按月开启下载");
- asyncDownloadTask.downloadByMonthTest(month, page);
- }
-
@GetMapping("/test/getDistributor")
public String udplatTest() {
return udplatDownloadService.getDistributor();
diff --git a/src/main/java/com/glxp/udidl/admin/controller/device/UdiCooperController.java b/src/main/java/com/glxp/udidl/admin/controller/device/UdiCooperController.java
index 9010325..f3d0d87 100644
--- a/src/main/java/com/glxp/udidl/admin/controller/device/UdiCooperController.java
+++ b/src/main/java/com/glxp/udidl/admin/controller/device/UdiCooperController.java
@@ -5,7 +5,6 @@ import com.glxp.udidl.admin.entity.udi.ProductInfoEntity;
import com.glxp.udidl.admin.req.ProductInfoFilterRequest;
import com.glxp.udidl.admin.res.BaseResponse;
import com.glxp.udidl.admin.service.inout.ProductInfoService;
-import com.glxp.udidl.admin.thread.AsyncDownloadTask;
import com.glxp.udidl.admin.util.FilterUdiUtils;
import com.glxp.udidl.admin.util.ResultVOUtils;
import io.swagger.annotations.Api;
@@ -24,9 +23,6 @@ public class UdiCooperController {
@Resource
ProductInfoService productInfoService;
- @Resource
- AsyncDownloadTask asyncDownloadTask;
-
@ApiOperation(value = "根据DI查询产品信息", response = ProductInfoEntity.class)
@AuthRuleAnnotation("udidl/cooper/findBydi")
@GetMapping("udidl/cooper/findBydi")
@@ -44,7 +40,6 @@ public class UdiCooperController {
ProductInfoEntity productInfoEntity = productInfoEntityList.get(productInfoEntityList.size() - 1);
return ResultVOUtils.success(productInfoEntity);
} else {
- asyncDownloadTask.downloadByDi(key); //后台自动下载
return ResultVOUtils.error(500, "未找到产品信息,请稍后重试");
}
}
diff --git a/src/main/java/com/glxp/udidl/admin/service/dataSync/UdplatDownloadService.java b/src/main/java/com/glxp/udidl/admin/service/dataSync/UdplatDownloadService.java
index e8bce43..e891fb5 100644
--- a/src/main/java/com/glxp/udidl/admin/service/dataSync/UdplatDownloadService.java
+++ b/src/main/java/com/glxp/udidl/admin/service/dataSync/UdplatDownloadService.java
@@ -2,6 +2,7 @@ package com.glxp.udidl.admin.service.dataSync;
import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.util.ParameterizedTypeImpl;
import com.glxp.udidl.admin.config.GlobalConfig;
import com.glxp.udidl.admin.dto.udplat.UdplatDistributorModel;
import com.glxp.udidl.admin.dto.udplat.UdplatGoodsModel;
@@ -11,6 +12,7 @@ import com.glxp.udidl.admin.res.BaseResponse;
import com.glxp.udidl.admin.res.udplat.UdplatResponse;
import com.glxp.udidl.admin.util.Md5Utils;
import com.glxp.udidl.admin.util.ResultVOUtils;
+import com.google.gson.reflect.TypeToken;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
@@ -20,7 +22,6 @@ import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
-import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl;
import java.lang.reflect.Type;
import java.net.URLEncoder;
@@ -259,9 +260,9 @@ public class UdplatDownloadService {
}
private ParameterizedTypeReference> getReference2(Class clazz) {
- ParameterizedTypeImpl type = ParameterizedTypeImpl.make(UdplatResponse.class, new Type[]{clazz},
- UdplatResponse.class.getDeclaringClass());
- return ParameterizedTypeReference.forType(type);
+
+ Type wrapperType = TypeToken.getParameterized(UdplatResponse.class).getType();
+ return ParameterizedTypeReference.forType(wrapperType);
}
private UdplatResponse post(Class clazz, String url, Map headerMap, Object jsonObject, Map map) {
diff --git a/src/main/java/com/glxp/udidl/admin/thread/AsyncDownloadTask.java b/src/main/java/com/glxp/udidl/admin/thread/AsyncDownloadTask.java
deleted file mode 100644
index d6ca433..0000000
--- a/src/main/java/com/glxp/udidl/admin/thread/AsyncDownloadTask.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package com.glxp.udidl.admin.thread;
-
-import com.glxp.udidl.admin.controller.device.DownloadDeviceHelper;
-import com.glxp.udidl.admin.dao.udid.DevicedownloadMapper;
-import com.glxp.udidl.admin.entity.udid.Devicedownload;
-import com.glxp.udidl.admin.entity.udid.TokenEntity;
-import com.glxp.udidl.admin.req.udid.DeviceRequest;
-import com.glxp.udidl.admin.req.udid.DownloadDiRequest;
-import com.glxp.udidl.admin.service.dataSync.DeviceDownloadService;
-import com.glxp.udidl.admin.service.dataSync.DeviceSyncService;
-import com.glxp.udidl.admin.service.info.CompanyService;
-import com.glxp.udidl.admin.service.inout.DeviceService;
-import com.glxp.udidl.admin.service.inout.ProductInfoService;
-import com.glxp.udidl.admin.service.udi.UdiCompanyService;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.scheduling.annotation.Async;
-import org.springframework.stereotype.Service;
-
-import javax.annotation.Resource;
-
-@Service
-public class AsyncDownloadTask {
-
- @Resource
- DeviceService deviceService;
- @Resource
- CompanyService companyService;
- @Resource
- UdiCompanyService udiCompanyService;
- @Resource
- ProductInfoService productInfoService;
- @Resource
- DeviceDownloadService deviceDownloadService;
- @Resource
- DeviceSyncService deviceSyncService;
- @Resource
- DownloadDeviceHelper downloadDeviceHelper;
-
- @Async
- public void downloadByDi(String primaryDeviceId) {
- String token = deviceDownloadService.getToken();
- DownloadDiRequest downloadDiRequest = new DownloadDiRequest();
- downloadDiRequest.setAccessToken(token);
- downloadDiRequest.setPrimaryDeviceId(primaryDeviceId);
- downloadDeviceHelper.downloadBydi(downloadDiRequest, deviceService, productInfoService);
- }
-
- //https://www.udims.com/UDI_DL_Server/udidl/device/dlBymonth?month=2021-10&page=1
- //按月下载UDI
- @Async
- public void downloadByMonth(String month, int page) {
- deviceDownloadService.downloadByMonth(month, page);
- }
-
-
- @Async
- public void downloadByMonthTest(String month, int page) {
- deviceDownloadService.downloadByMonthTest(month, page);
-
-
- }
-
-
-}
diff --git a/src/main/java/com/glxp/udidl/admin/util/FilterUdiUtils.java b/src/main/java/com/glxp/udidl/admin/util/FilterUdiUtils.java
index 3cffc5c..4a6cf21 100644
--- a/src/main/java/com/glxp/udidl/admin/util/FilterUdiUtils.java
+++ b/src/main/java/com/glxp/udidl/admin/util/FilterUdiUtils.java
@@ -1,14 +1,20 @@
package com.glxp.udidl.admin.util;
+import cn.hutool.core.util.StrUtil;
import com.glxp.udidl.admin.entity.udid.UdiEntity;
+import com.glxp.udidl.admin.util.gs1.AI;
+import com.glxp.udidl.admin.util.gs1.AIs;
+import com.glxp.udidl.admin.util.gs1.Gs1128Decoder;
+import com.glxp.udidl.admin.util.gs1.Gs1128Engine;
+
+import java.util.Map;
/**
* @author 彭于晏
* @date 2020/9/22.
*/
public class FilterUdiUtils {
-
private static final String TAG = "FilterUdiUtils";
public static UdiEntity getUdi(String data) {
@@ -25,144 +31,46 @@ public class FilterUdiUtils {
}
public static UdiEntity getGS1Udi(String data) {
- String batchNo = "";
- String produceDate = "";
- String expireDate = "";
- String serialNo = null;
- String udi = "";
- UdiEntity udiEntity = null;
- if (data.length() >= 16) {
- udi = data.substring(2, 16);
- if (data.length() >= 18 && data.substring(16, 18).equals("10")) {
- if (data.contains("\u001D")) {
- String[] splits = data.split("\u001D");
- String front = splits[0];
- batchNo = front.substring(18, front.length());
- String last = splits[1];
- boolean b = last.length() >= 18 && last.substring(16, 18).equals("21");
- if ((last != null && last.length() >= 2) && last.substring(0, 2).equals("11")) {
- produceDate = last.substring(2, 8);
- if (last.length() >= 10 && last.substring(8, 10).equals("17")) {
- expireDate = last.substring(10, 16);
- if (b) {
- serialNo = last.substring(18, last.length());
- } else {
- serialNo = null;
- }
- }
- } else if ((last != null && last.length() >= 2) && last.substring(0, 2).equals("17")) {
- expireDate = last.substring(2, 8);
- if (last.length() >= 10 && last.substring(8, 10).equals("11")) {
- produceDate = last.substring(10, 16);
- if (b) {
- serialNo = last.substring(18, last.length());
- } else {
- serialNo = null;
- }
- }
- } else if ((last != null && last.length() >= 2) && last.substring(0, 2).equals("21")) {
- serialNo = last.substring(2, last.length());
- }
- } else {
- batchNo = data.substring(18);
- }
-
-
- } else if (data.length() >= 18 && data.substring(16, 18).equals("11")) {
- produceDate = data.substring(18, 24);
- if (data.length() >= 26 && data.substring(24, 26).equals("17")) {
- expireDate = data.substring(26, 32);
- if (data.length() >= 34 && data.substring(32, 34).equals("10")) {
- if (data.contains("\u001D")) {
- String[] splits = data.split("\u001D");
- batchNo = splits[0].substring(34, splits[0].length());
- serialNo = splits[1].substring(2);
- } else {
- batchNo = data.substring(34, data.length());
- }
-
- }
- } else if (data.length() >= 26 && data.substring(24, 26).equals("10")) {
- if (data.contains("\u001D")) {
- String[] splits = data.split("\u001D");
- batchNo = splits[0].substring(26, splits[0].length());
- String last = splits[1];
- if (last.substring(0, 2).equals("17")) {
- expireDate = last.substring(2, 8);
- if (last.length() >= 10) {
- serialNo = last.substring(10, last.length());
- }
- } else if (last.substring(0, 2).equals("21")) {
- serialNo = last.substring(2, last.length());
- }
- } else {
- batchNo = data.substring(26, data.length());
- }
-
- } else if (data.length() >= 26 && data.substring(24, 26).equals("21")) {
-
- serialNo = data.substring(26);
- }
- } else if (data.length() >= 18 && data.substring(16, 18).equals("17")) {
- expireDate = data.substring(18, 24);
- if (data.length() >= 26 && data.substring(24, 26).equals("11")) {
- produceDate = data.substring(26, 32);
- if (data.length() >= 34 && data.substring(32, 34).equals("10")) {
- if (data.contains("\u001D")) {
- String[] splits = data.split("\u001D");
- batchNo = splits[0].substring(34, splits[0].length());
- serialNo = splits[1].substring(2);
- } else {
- batchNo = data.substring(34, data.length());
- }
-
- }
- } else if (data.length() >= 26 && data.substring(24, 26).equals("10")) {
- if (data.contains("\u001D")) {
- String[] splits = data.split("\u001D");
- batchNo = splits[0].substring(26, splits[0].length());
- String last = splits[1];
- if (last.substring(0, 2).equals("11")) {
- produceDate = last.substring(2, 8);
- } else if (last.substring(0, 2).equals("21")) {
- serialNo = last.substring(2);
- }
- } else {
- batchNo = data.substring(26, data.length());
- }
- } else if (data.length() >= 26 && data.substring(24, 26).equals("21")) {
-
- serialNo = data.substring(26);
- }
-
- } else if (data.length() >= 18 && data.substring(16, 18).equals("21")) {
- serialNo = data.substring(18);
+ Gs1128Engine engine = new Gs1128Engine();
+ Gs1128Decoder decoder = engine.decoder();
+ Map result = decoder.decode("]C1" + data);
+ UdiEntity udiEntity = new UdiEntity();
+ for (Map.Entry entry : result.entrySet()) {
+ 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());
}
- udiEntity = new UdiEntity();
- udiEntity.setUdi(udi);
- udiEntity.setBatchNo(batchNo);
- udiEntity.setExpireDate(expireDate);
- udiEntity.setProduceDate(produceDate);
- udiEntity.setSerialNo(serialNo);
}
- return udiEntity;
+ if (StrUtil.isEmpty(udiEntity.getUdi())) {
+ return null;
+ } else
+ return udiEntity;
}
+
public static UdiEntity getZGCUdi(String data) {
String batchNo = "";
String produceDate = "";
String expireDate = "";
String serialNo = null;
- String udi = "";
+ String udi = data;
+ String nameCode = "";
String[] spilts = data.split("[.]");
if (spilts != null && spilts.length >= 5) {
for (int i = 0; i < 5; i++) {
- udi = udi + "." + spilts[i];
+ nameCode = nameCode + "." + spilts[i];
}
- udi = udi.substring(1);
+ 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("P")) {
+ 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);
@@ -178,9 +86,10 @@ public class FilterUdiUtils {
udiEntity.setBatchNo(batchNo);
udiEntity.setExpireDate(expireDate);
udiEntity.setProduceDate(produceDate);
- udiEntity.setUdi(udi);
+ udiEntity.setUdi(nameCode);
udiEntity.setSerialNo(serialNo);
return udiEntity;
+
}
public static UdiEntity getGLXPUdi(String data) {
@@ -191,11 +100,17 @@ public class FilterUdiUtils {
String udi = "";
String[] spilts = data.split("#");
if (spilts != null && spilts.length >= 5) {
- udi = spilts[0];
- produceDate = spilts[1];
- expireDate = spilts[2];
- batchNo = spilts[3];
- serialNo = spilts[4];
+ udi = spilts[1];
+ produceDate = spilts[2];
+ expireDate = spilts[3];
+ batchNo = spilts[4];
+ if (spilts.length > 6) {
+ serialNo = spilts[5];
+ if (serialNo != null && serialNo.equals("")) {
+ serialNo = null;
+ }
+ }
+
}
UdiEntity udiEntity = new UdiEntity();
udiEntity.setBatchNo(batchNo);
@@ -222,7 +137,7 @@ public class FilterUdiUtils {
} else if (data.substring(0, 1).equals("#")) {
String[] spilts = data.split("#");
if (spilts != null && spilts.length >= 1)
- prefix = spilts[0];
+ prefix = spilts[1];
}
}
if (prefix.equals(""))
@@ -230,4 +145,5 @@ public class FilterUdiUtils {
return prefix;
}
+
}
diff --git a/src/main/java/com/glxp/udidl/admin/util/gs1/AI.java b/src/main/java/com/glxp/udidl/admin/util/gs1/AI.java
new file mode 100644
index 0000000..a1aae78
--- /dev/null
+++ b/src/main/java/com/glxp/udidl/admin/util/gs1/AI.java
@@ -0,0 +1,14 @@
+package com.glxp.udidl.admin.util.gs1;
+
+/**
+ * @author guilherme.pacheco
+ */
+public interface AI {
+
+ String getCode();
+
+ String getDescription();
+
+ String getFormat();
+
+}
diff --git a/src/main/java/com/glxp/udidl/admin/util/gs1/AIs.java b/src/main/java/com/glxp/udidl/admin/util/gs1/AIs.java
new file mode 100644
index 0000000..d04a8a0
--- /dev/null
+++ b/src/main/java/com/glxp/udidl/admin/util/gs1/AIs.java
@@ -0,0 +1,112 @@
+package com.glxp.udidl.admin.util.gs1;
+
+/**
+ * @author guilherme.pacheco
+ */
+public enum AIs implements AI {
+
+ SSCC("00", "Serial Shipping Container Code", "n2+n18"),
+ GTIN("01", "GTIN-14", "n2+n14"),
+ CONTENT("02", "Number of containers", "n2+n14"),
+ BATCH_LOT("10", "Batch Number", "n2+an..20"),
+ PROD_DATE("11", "Production Date", "n2+n6"),
+ DUE_DATE("12", "Production Date", "n2+n6"),
+ PACK_DATE("13", "Packaging Date", "n2+n6"),
+ BEST_BEFORE("15", "Sell by Date (Quality Control) ", "n2+n6"),
+ EXPIRY("17", "Expiration Date", "n2+n6"),
+ VARIANT("20", "Product Variant", "n2+n2"),
+ SERIAL("21", "Serial Number", "n2+an..20"),
+ INTERNAL("91", "Company Internal Information", "n2+an..30"),
+ ADDITIONAL_ID("240", "Additional Product Identification", "n3+an..30"),
+ CUSTOMER_PART("241", "Customer Part Number", "n3+an..30"),
+ VARIATION_NUMBER("242", "242 Made-to-Order variation no", "n2+n..30"),
+ SECONDARY_SERIAL("250", "Secondary Serial Number", "n3+an..30"),
+ REF_TO_SOURCE("251", "Reference to source entity", "n3+an..30"),
+ DOC_ID("253", "Global Document Type Identifier", "n3+n13+n..17"),
+ GLN_EXTENSION("254", "GLN extension component ", "n3+an..20"),
+ VAR_COUNT("30", "Quantity Each", "n2+n..8"),
+ NET_WEIGHT("310n", "Product Net Weight in kg", "n4+n6"),
+ LENGTH("311n", "Product Length/1st Dimension, in meters", "n4+n6"),
+ WIDTH("312n", "Product Width/Diameter/2nd Dimension, in meters", "n4+n6"),
+ HEIGHT("313n", "Product Depth/Thickness/3rd Dimension, in meters", "n4+n6"),
+ AREA("314n", "Product Area, in square meters", "n4+n6"),
+ NET_VOLUME_LITERS("315n", " Product Volume, in liters", "n4+n6"),
+ NET_VOLUME_CUBICS("316n", " product Volume, in cubic meters", "n4+n6"),
+ NET_WEIGHT_POUNDS("320n", "Product Net Weight, in pounds", "n4+n6"),
+ LENGTH_INCHES("321n", "Product Length/1st Dimension, in inches", "n4+n6"),
+ LENGTH_PES("322n", "Product Length/1st Dimension, in feet", "n4+n6"),
+ LENGTH_YARDS("323n", "Product Length/1st Dimension, in yards", "n4+n6"),
+ WIDTH_INCHES("324n", "Product Width/Diameter/2nd Dimension, in inches", "n4+n6"),
+ WIDTH_FEET("325n", "Product Width/Diameter/2nd Dimension, in feet", "n4+n6"),
+ WIDTH_YARDS("326n", "Product Width/Diameter/2nd Dimension, in yards", "n4+n6"),
+ HEIGHT_INCHES("327n", "Product Depth/Thickness/3rd Dimension, in inches", "n4+n6"),
+ HEIGHT_FEET("328n", "Product Depth/Thickness/3rd Dimension, in feet", "n4+n6"),
+ HEIGHT_YARDS("329n", "Product Depth/Thickness/3rd Dimension, in yards", "n4+n6"),
+ PRODUCT_AREA_INCHES("350n", "Product Area (Square Inches)", "n4+n6"),
+ PRODUCT_AREA_FEET("351n", "Product Area (Square Feet)", "n4+n6"),
+ PRODUCT_AREA_YARDS("352n", "Product Area (Square Yards)", "n4+n6"),
+ CONTAINER_AREA_INCHES("353n", "Container Area (Square Inches) ", "n4+n6"),
+ CONTAINER_AREA_FEET("354n", "Container Area (Square Feet) ", "n4+n6"),
+ CONTAINER_AREA_YARDS("355n", "Container Area (Square Yards) ", "n4+n6"),
+ NET_WEIGHT_OUNCES("356n", "Net Weight (Troy Ounces)", "n4+n6"),
+ PRODUCT_VOLUME_QUARTS("360n", " Product Volume (Quarts)", "n4+n6"),
+ PRODUCT_VOLUME_GALLONS("361n", " Product Volume (Gallons)", "n4+n6"),
+ CONTAINER_VOLUME_QUARTS("362n", " Container Gross Volume (Quarts)", "n4+n6"),
+ CONTAINER_VOLUME_GALLONS("363n", " Container Gross Volume (Gallons)", "n4+n6"),
+ PRODUCT_VOLUME_INCHES("364n", " Product Volume (Cubic Inches)", "n4+n6"),
+ PRODUCT_VOLUME_FEET("365n", " Product Volume (Cubic Feet)", "n4+n6"),
+ PRODUCT_VOLUME_YARDS("366n", " Product Volume (Cubic Yards)", "n4+n6"),
+ CONTAINER_VOLUME_INCHES("367n", " Container Gross Volume (Cubic Inches)", "n4+n6"),
+ CONTAINER_VOLUME_FEET("368n", " Container Gross Volume (Cubic Feet)", "n4+n6"),
+ CONTAINER_VOLUME_YARDS("369n", " Container Gross Volume (Cubic Yards)", "n4+n6"),
+ COUNT("37", " Number of Units Contained", "n2+n..8"),
+ ORDER_NUMBER("400", "Customer Purchase Order Number", "n3+an..30"),
+ SHIP_TO_DELIVER_TO_LOCATION_CODE("410", "Ship To/Deliver To Location Code (EAN13 or DUNS code)", "n3+n13"),
+ BILL_TO_INVOICEE_TO_LOCATION_CODE("411", "Bill To/Invoice Location Code (EAN13 or DUNS code)", "n3+n13"),
+ PURCHASE_FROM_LOCATION_CODE("412", "Purchase From Location Code (EAN13 or DUNS code)", "n3+n13"),
+ SHIP_TO_DELIVER_TO_POSTALCODE("420", "Ship To/Deliver To Postal Code (Single Postal Authority)", "n3+an..9"),
+ SHIP_TO_DELIVER_TO_MULTI_POSTALCODE("421", "Ship To/Deliver To Postal Code (Multiple Postal Authority)",
+ "n3+n3+an..9"),
+ ORIGIN("422", "Country orign", "n3+n3"),
+ COUNTRY_INITIAL_PROCESS("423", "County initial processing", "n3+n3+n..12"),
+ COUNTRY_PROCESS("424", "County processing", "n3+n3"),
+ COUNTRY_DISASSEMBLY("425", "Country disassembly", "n3+n3"),
+ COUNTRY_FULL_PROCESS("426", "Country pull processing", "n3+n3"),
+ ROLL_PRODUCTS("8001", "Roll Products – Width/Length/Core Diameter", "n4+n14"),
+ ESN("8002", "Electronic Serial Number (ESN) for Cellular Phone", "n4+an..20"),
+ UPC_EAN_RETURNABLE_ASSET("8003", "UPC/EAN Number and Serial Number of Returnable Asset", "n4+an..30"),
+ UPC_EAN_SERIAL_IDENTIFICATION("8004", "UPC/EAN Serial Identification", "n4+an..30"),
+ PRICE_UNIT_MEASURE("8005", "Price per Unit of Measure", "n4+n6"),
+ ;
+
+ private final String code;
+ private final String description;
+ private final String format;
+
+ private AIs(String code, String description, String format) {
+ this.code = code;
+ this.description = description;
+ this.format = format;
+ }
+
+ @Override
+ public String getCode() {
+ return code;
+ }
+
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ @Override
+ public String getFormat() {
+ return format;
+ }
+
+ @Override
+ public String toString() {
+ return description;
+ }
+
+}
diff --git a/src/main/java/com/glxp/udidl/admin/util/gs1/AiFactory.java b/src/main/java/com/glxp/udidl/admin/util/gs1/AiFactory.java
new file mode 100644
index 0000000..12b3cbe
--- /dev/null
+++ b/src/main/java/com/glxp/udidl/admin/util/gs1/AiFactory.java
@@ -0,0 +1,32 @@
+package com.glxp.udidl.admin.util.gs1;
+
+/**
+ * @author guilherme.pacheco
+ */
+public final class AiFactory {
+
+ private AiFactory() {
+ super();
+ }
+
+ public static AI create(String code, String description, String format) {
+ return new AI() {
+
+ @Override
+ public String getFormat() {
+ return format;
+ }
+
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ @Override
+ public String getCode() {
+ return code;
+ }
+ };
+ }
+
+}
diff --git a/src/main/java/com/glxp/udidl/admin/util/gs1/Format.java b/src/main/java/com/glxp/udidl/admin/util/gs1/Format.java
new file mode 100644
index 0000000..02375a2
--- /dev/null
+++ b/src/main/java/com/glxp/udidl/admin/util/gs1/Format.java
@@ -0,0 +1,71 @@
+package com.glxp.udidl.admin.util.gs1;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.Validate;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * @author guilherme.pacheco
+ */
+final class Format {
+
+ private static final String JOIN_SYMBOL = "+";
+ private final List sessions;
+
+ public Format(List sessions) {
+ this.sessions = Validate.notEmpty(sessions);
+ }
+
+ public Format(Session... sessions) {
+ this(Arrays.asList(sessions));
+ }
+
+ public Session getIdentifier() {
+ return sessions.get(0);
+ }
+
+ public List getDataSessions() {
+ return sessions.subList(1, sessions.size());
+ }
+
+ @Override
+ public String toString() {
+ return sessions.stream().map(String::valueOf).collect(Collectors.joining(JOIN_SYMBOL));
+ }
+
+ public boolean isValid(String value) {
+ if (StringUtils.isBlank(value)) {
+ return false;
+ }
+ if (!validLength(value)) {
+ return false;
+ }
+ return validate(value);
+ }
+
+ private boolean validate(String value) {
+ return getDataSessions().stream().allMatch(s -> s.getType().isValid(Gs1128Utils.value(s, value)));
+ }
+
+ private boolean validLength(String value) {
+ return isVaried() ? value.length() <= getLength() : value.length() == getLength();
+ }
+
+ public int getLength() {
+ return getDataSessions().stream().mapToInt(Session::getLength).sum();
+ }
+
+ public boolean isVaried() {
+ return getDataSessions().stream().anyMatch(Session::isVaried);
+ }
+
+ public static Format valueOf(String value) {
+ String[] split = StringUtils.split(value, JOIN_SYMBOL);
+ List list = Arrays.stream(split).map(Session::valueOf).collect(Collectors.toList());
+ return new Format(list);
+ }
+
+}
diff --git a/src/main/java/com/glxp/udidl/admin/util/gs1/Gs1128Decoder.java b/src/main/java/com/glxp/udidl/admin/util/gs1/Gs1128Decoder.java
new file mode 100644
index 0000000..a2873e2
--- /dev/null
+++ b/src/main/java/com/glxp/udidl/admin/util/gs1/Gs1128Decoder.java
@@ -0,0 +1,57 @@
+package com.glxp.udidl.admin.util.gs1;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.Validate;
+
+import java.util.*;
+import java.util.function.Function;
+
+/**
+ * @author guilherme.pacheco
+ */
+public final class Gs1128Decoder {
+
+ private final Collection ais;
+
+ Gs1128Decoder(Collection ais) {
+ this.ais = ais;
+ }
+
+ public Map decode(final String barcode) {
+ validateBarcode(barcode);
+ String barcodeValue = StringUtils.remove(barcode, Gs1128Utils.PREFIX);
+ return extract(barcodeValue);
+ }
+
+ private Map extract(String barcode) {
+ final Iterator iterator = Gs1128Utils.iterator(barcode);
+ final Map result = new WeakHashMap<>(4);
+ StringBuilder builder = new StringBuilder();
+ while (iterator.hasNext()) {
+ builder.append(iterator.next());
+ Optional