Barcode 리더 사용시 바코드 정보 parsing -> 제품코드, 제조번호, 유효기간, 제품일련번호

dev
Jonguk. Lim 6 months ago
parent c7f827b305
commit 4d39716bcb

@ -1,9 +1,13 @@
package cokr.xit.adds.biz.nims.model;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import cokr.xit.adds.core.Constants;
import cokr.xit.adds.inf.nims.model.NimsApiDto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
@ -148,4 +152,169 @@ public class BizNimsResponse {
// */
// private String prtmSeNm;
}
/**
* <pre>
* Barcode(GS1-128) response
* 30
* AI(2) + (14) + AI(2) + (6) + AI(2) + (1) + AI(2) + (1)
* -> ((1) + (13)), (1), (1)
* </pre>
*/
@Schema(name = "Barcode", description = "Barcode response DTO")
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public static class Barcode {
/**
* <pre>
* GS1-128 barcode - 01 : AI
* 2 : 01
* </pre>
*/
@Builder.Default
private String gsId = "01";
/**
* <pre>
* GS1-128
* 14 - (0) + (13)
* </pre>
*/
private String gsPrductCd;
/**
* <pre>
* GS1-128
* 1 - (0)
* </pre>
*/
@Builder.Default
private String gsPrductExtCd = "0";
/**
* <pre>
* AI
* 2 : 17
* </pre>
*/
@Builder.Default
private String gsDistributionDel = "17";
/**
* <pre>
* : YYMMDD
* 6
* </pre>
*/
private String gsDistributionDate;
/**
* <pre>
* AI
* 2 - 10
* </pre>
*/
@Builder.Default
private String gsAiLotNo = "10";
/**
* <pre>
* ( )
* 20
* AI(10) ~ AI(21)
* </pre>
*/
private String gsMnfNo;
/**
* <pre>
* AI
* 2 - 21
* </pre>
*/
@Builder.Default
private String gsAiSerialNo = "21";
/**
* <pre>
*
* AI 20
* </pre>
*/
private String gsMnfSeqNo;
/**
* <pre>
* reader - Barcode(GS1-128)
* , , ,
*
* @param barcodeStr
* @return NimsApiDto.MnfSeqInfo
* </pre>
*/
public NimsApiDto.MnfSeqInfo parseBarcode(final String barcodeStr){
NimsApiDto.MnfSeqInfo mnfSeqInfo = new NimsApiDto.MnfSeqInfo();
if(barcodeStr.length() < 30){
throw new IllegalArgumentException("Barcode는 최소 30자리 이상이어야 합니다.");
}
// AI상품식별코드(01)로 시작
if(barcodeStr.startsWith(this.gsId) == false){
throw new IllegalArgumentException("Barcode(GS1-128)는 AI상품식별코드(01)로 시작 되어야 합니다.");
}
String barcode = barcodeStr.substring(barcodeStr.indexOf(this.gsId)+this.gsId.length());
// 상품코드(확장코드(0) + 상품코드(13))
String temp = barcode.substring(0, 14);
String regx = "^0(\\d{13})";
Pattern pattern = Pattern.compile(regx);
Matcher matcher = pattern.matcher(temp);
if(matcher.find()) {
//this.gsPrductCd = matcher.group(1);
mnfSeqInfo.setPrductCd(matcher.group(1));
}else{
throw new IllegalArgumentException("Barcode(GS1-128) 상품코드는 확장코드(0) + 상품코드(13)로 구성되어야 합니다.");
}
barcode = barcode.substring(14);
// 유통일자 : AI최대유통일자(17) + 6자리 유통일자
temp = barcode.substring(0, 8);
regx = "^17(\\d{6})";
pattern = Pattern.compile(regx);
matcher = pattern.matcher(temp);
if(matcher.find()) {
//this.gsDistributionDate = matcher.group(1);
mnfSeqInfo.setPrdValidDe(matcher.group(1));
}else{
throw new IllegalArgumentException("Barcode(GS1-128) 유통일자는 AI최대유통일자(17) + 유통일자(6)로 구성되어야 합니다.");
}
barcode = barcode.substring(8);
// 제조번호 : AI로트번호(10)로 시작 ~ 20자 이하 제조번호 ~ AI일련번호(21) 이전
regx = "^10(.{1,20})21";
pattern = Pattern.compile(regx);
matcher = pattern.matcher(barcode);
if(matcher.find()) {
//this.gsMnfNo = matcher.group(1);
mnfSeqInfo.setMnfNo(matcher.group(1));
}else {
throw new IllegalArgumentException("Barcode(GS1-128) 제조번호는 AI로트번호(10)로 시작 되어 AI일련번호(21)로 끝나야 합니다.");
}
barcode = barcode.substring(mnfSeqInfo.getMnfNo().length()+2);
// 제품일련번호 : AI일련번호(21)로 시작 ~ 20자 이하 제조일련번호
regx = "^21(.{1,20}$)";
pattern = Pattern.compile(regx);
matcher = pattern.matcher(barcode);
if(matcher.find()) {
//this.gsMnfSeqNo = matcher.group(1);
mnfSeqInfo.setMnfSeq(matcher.group(1));
}else {
throw new IllegalArgumentException("Barcode(GS1-128) 제조일련번호는 AI일련번호(21)로 시작 되어야 합니다.");
}
return mnfSeqInfo;
}
}
}

@ -1,6 +1,7 @@
package cokr.xit.adds.biz.nims.web;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -14,7 +15,10 @@ import org.springframework.web.servlet.ModelAndView;
import com.google.zxing.NotFoundException;
import cokr.xit.adds.biz.nims.model.BizNimsResponse;
import cokr.xit.adds.core.util.XingUtils;
import cokr.xit.adds.inf.nims.model.NimsApiDto;
import io.swagger.v3.oas.annotations.tags.Tag;
/**
* <pre>
@ -31,23 +35,26 @@ import cokr.xit.adds.core.util.XingUtils;
*
* </pre>
*/
@Tag(name = "QrController", description = "qrcode API")
@RestController
public class QrController {
@GetMapping("/biz/nims/v1/qrcodeForm")
@GetMapping("/api/biz/nims/v1/qrcodeForm")
public ModelAndView qrcodeForm() {
return new ModelAndView("/zxing/index.html");
}
@PostMapping("/biz/nims/v1/getQrcode")
public List<Map<String, Object>> uploadQrCode(
@PostMapping(value = "/api/biz/nims/v1/getQrcode", consumes = { "multipart/form-data" })
public List<NimsApiDto.MnfSeqInfo> uploadQrCode(
@RequestParam("uploadFiles")
final List<MultipartFile> multipartFiles
) {
return multipartFiles.stream().map(mf -> {
List<NimsApiDto.MnfSeqInfo> mnfSeqInfos = new ArrayList<>();
List<Map<String, String>> list = multipartFiles.stream().map(mf -> {
System.out.println(mf.getOriginalFilename());
System.out.println(mf.getSize());
Map<String, Object> map = new HashMap<>();
Map<String, String> map = new HashMap<>();
try {
map.put("qrcode", XingUtils.readQrcodeFromFile(XingUtils.convert(mf)));
map.put("name", mf.getOriginalFilename());
@ -56,5 +63,13 @@ public class QrController {
}
return map;
}).toList();
for(Map<String,String> map: list){
System.out.println(map.get("qrcode"));
BizNimsResponse.Barcode barcode = new BizNimsResponse.Barcode();
mnfSeqInfos.add(barcode.parseBarcode(map.get("qrcode")));
}
return mnfSeqInfos;
}
}

Loading…
Cancel
Save