|
|
@@ -2,14 +2,10 @@ package org.springblade.los.business.sea.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
-import com.sun.org.apache.xpath.internal.operations.Bool;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.springblade.core.secure.utils.AuthUtil;
|
|
|
import org.springblade.core.tool.api.R;
|
|
|
-import org.springblade.los.Util.RegularUtils;
|
|
|
import org.springblade.los.basic.packages.entity.BPackages;
|
|
|
import org.springblade.los.basic.packages.service.IBPackagesService;
|
|
|
import org.springblade.los.basic.ports.entity.BPorts;
|
|
|
@@ -23,7 +19,6 @@ import org.springblade.los.business.sea.service.IBillsService;
|
|
|
import org.springblade.los.business.sea.service.ITemplateImportService;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
-import org.stringtemplate.v4.ST;
|
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
import java.lang.reflect.Field;
|
|
|
@@ -33,7 +28,12 @@ import java.math.RoundingMode;
|
|
|
import java.nio.file.Files;
|
|
|
import java.nio.file.Path;
|
|
|
import java.nio.file.StandardCopyOption;
|
|
|
-import java.util.*;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
|
/**
|
|
|
* @author :jixinyuan
|
|
|
@@ -50,68 +50,68 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
|
|
|
private final IBillsService billsService;
|
|
|
|
|
|
- public static double splitNumericPrefixFromString(String str){
|
|
|
- str=str.replace(" ","").trim();
|
|
|
- String str2="", str3="";
|
|
|
+ public static double splitNumericPrefixFromString(String str) {
|
|
|
+ str = str.replace(" ", "").trim();
|
|
|
+ String str2 = "", str3 = "";
|
|
|
Boolean bf = false;
|
|
|
- if(str != null && !"".equals(str)){
|
|
|
- for(int i=0; i<str.length(); i++){
|
|
|
- if(!bf && (str.charAt(i)==46||(str.charAt(i)>=48 && str.charAt(i)<=57))){
|
|
|
+ if (str != null && !"".equals(str)) {
|
|
|
+ for (int i = 0; i < str.length(); i++) {
|
|
|
+ if (!bf && (str.charAt(i) == 46 || (str.charAt(i) >= 48 && str.charAt(i) <= 57))) {
|
|
|
str2 += str.charAt(i);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
bf = true;
|
|
|
str3 += str.charAt(i);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- double d=0;
|
|
|
+ double d = 0;
|
|
|
|
|
|
- try{
|
|
|
+ try {
|
|
|
d = Double.parseDouble(str2);
|
|
|
- }catch (Exception e){
|
|
|
+ } catch (Exception e) {
|
|
|
d = 0;
|
|
|
- }finally{
|
|
|
+ } finally {
|
|
|
return d;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static Map<String, Object> splitNumericPrefixMapFromString(String str){
|
|
|
+ public static Map<String, Object> splitNumericPrefixMapFromString(String str) {
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
- str=str.replace(" ","").trim();
|
|
|
- String str2="", str3="";
|
|
|
+ str = str.replace(" ", "").trim();
|
|
|
+ String str2 = "", str3 = "";
|
|
|
Boolean bf = false;
|
|
|
- if(str != null && !"".equals(str)){
|
|
|
- for(int i=0; i<str.length(); i++){
|
|
|
- if(!bf && (str.charAt(i)==46||(str.charAt(i)>=48 && str.charAt(i)<=57))){
|
|
|
+ if (str != null && !"".equals(str)) {
|
|
|
+ for (int i = 0; i < str.length(); i++) {
|
|
|
+ if (!bf && (str.charAt(i) == 46 || (str.charAt(i) >= 48 && str.charAt(i) <= 57))) {
|
|
|
str2 += str.charAt(i);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
bf = true;
|
|
|
str3 += str.charAt(i);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- double d=0;
|
|
|
+ double d = 0;
|
|
|
|
|
|
- try{
|
|
|
+ try {
|
|
|
d = Double.parseDouble(str2);
|
|
|
- }catch (Exception e){
|
|
|
+ } catch (Exception e) {
|
|
|
d = 0;
|
|
|
- }finally{
|
|
|
+ } finally {
|
|
|
map.put("value", d);
|
|
|
map.put("str", str3);
|
|
|
return map;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static String getSheetCellValueAsString(Sheet sheet, int row, int col){
|
|
|
+ public static String getSheetCellValueAsString(Sheet sheet, int row, int col) {
|
|
|
Row r = sheet.getRow(row);
|
|
|
Cell c = ObjectUtils.isNotNull(r) ? r.getCell(col) : null;
|
|
|
String res = "";
|
|
|
- if(ObjectUtils.isNotNull(c)){
|
|
|
+ if (ObjectUtils.isNotNull(c)) {
|
|
|
CellType ct = c.getCellTypeEnum();
|
|
|
- switch (ct){
|
|
|
+ switch (ct) {
|
|
|
case STRING:
|
|
|
res = c.getStringCellValue().trim();
|
|
|
break;
|
|
|
@@ -130,17 +130,17 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
- public static double getSheetCellValueAsDouble(Sheet sheet, int row, int col){
|
|
|
+ public static double getSheetCellValueAsDouble(Sheet sheet, int row, int col) {
|
|
|
Row r = sheet.getRow(row);
|
|
|
Cell c = ObjectUtils.isNotNull(r) ? r.getCell(col) : null;
|
|
|
double res = 0.0;
|
|
|
- if(ObjectUtils.isNotNull(c)){
|
|
|
+ if (ObjectUtils.isNotNull(c)) {
|
|
|
CellType ct = c.getCellTypeEnum();
|
|
|
- switch (ct){
|
|
|
+ switch (ct) {
|
|
|
case STRING:
|
|
|
try {
|
|
|
res = Double.parseDouble(c.getStringCellValue().trim());
|
|
|
- }catch (Exception e) {
|
|
|
+ } catch (Exception e) {
|
|
|
res = 0;
|
|
|
}
|
|
|
break;
|
|
|
@@ -171,17 +171,17 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
return splitNumericPrefixMapFromString(str);
|
|
|
}
|
|
|
|
|
|
- public static Boolean stringBuilderIsNotEmpty(StringBuilder sb){
|
|
|
+ public static Boolean stringBuilderIsNotEmpty(StringBuilder sb) {
|
|
|
return ObjectUtils.isNotNull(sb) && !sb.toString().trim().isEmpty();
|
|
|
}
|
|
|
|
|
|
- public static String getFirstStars(String text){
|
|
|
+ public static String getFirstStars(String text) {
|
|
|
String ret = "";
|
|
|
- if(ObjectUtils.isNotNull(text)) {
|
|
|
- for (int i = 0; i<text.length(); i++){
|
|
|
- if(text.charAt(i)=='*'){
|
|
|
+ if (ObjectUtils.isNotNull(text)) {
|
|
|
+ for (int i = 0; i < text.length(); i++) {
|
|
|
+ if (text.charAt(i) == '*') {
|
|
|
ret += '*';
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
@@ -189,13 +189,13 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
- public static String getLastStars(String text){
|
|
|
+ public static String getLastStars(String text) {
|
|
|
String ret = "";
|
|
|
- if(ObjectUtils.isNotNull(text)) {
|
|
|
- for (int i = text.length() - 1; i>=0; i--){
|
|
|
- if(text.charAt(i)=='*'){
|
|
|
+ if (ObjectUtils.isNotNull(text)) {
|
|
|
+ for (int i = text.length() - 1; i >= 0; i--) {
|
|
|
+ if (text.charAt(i) == '*') {
|
|
|
ret += '*';
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
@@ -203,33 +203,33 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
- public static String getStarLines(StringBuilder sb, String starts){
|
|
|
+ public static String getStarLines(StringBuilder sb, String starts) {
|
|
|
StringBuilder ret = new StringBuilder();
|
|
|
|
|
|
- if(ObjectUtils.isNotNull(sb) && ObjectUtils.isNotNull(starts)){
|
|
|
+ if (ObjectUtils.isNotNull(sb) && ObjectUtils.isNotNull(starts)) {
|
|
|
String[] lines = sb.toString().split("\n");
|
|
|
ArrayList<String> newLines = new ArrayList<String>();
|
|
|
Boolean bInStar = false;
|
|
|
for (String line : lines) {
|
|
|
- if(getFirstStars(line).equals(starts)){
|
|
|
+ if (getFirstStars(line).equals(starts)) {
|
|
|
bInStar = true;
|
|
|
- if(line.length()>starts.length()){
|
|
|
+ if (line.length() > starts.length()) {
|
|
|
ret.append(line.substring(starts.length() - 1).concat("\r\n"));
|
|
|
}
|
|
|
- }else{
|
|
|
- if(bInStar && (line.isEmpty() || line.charAt(0)!='*')){
|
|
|
+ } else {
|
|
|
+ if (bInStar && (line.isEmpty() || line.charAt(0) != '*')) {
|
|
|
ret.append(line.concat("\r\n"));
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
bInStar = false;
|
|
|
}
|
|
|
- if(!bInStar) {
|
|
|
+ if (!bInStar) {
|
|
|
newLines.add(line);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
sb.setLength(0);
|
|
|
- newLines.forEach(line->{
|
|
|
+ newLines.forEach(line -> {
|
|
|
sb.append(line.concat("\r\n"));
|
|
|
});
|
|
|
}
|
|
|
@@ -237,7 +237,7 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
return ret.toString().trim();
|
|
|
}
|
|
|
|
|
|
- public static void resetBillsNullValuesAsEmptyString(Bills bills){
|
|
|
+ public static void resetBillsNullValuesAsEmptyString(Bills bills) {
|
|
|
//将字符串为null的赋默认值为""
|
|
|
Field[] fields = bills.getClass().getDeclaredFields();
|
|
|
for (Field field : fields) {
|
|
|
@@ -254,8 +254,9 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
@Override
|
|
|
- public R<Bills> importOne(MultipartFile file,Long billId) throws Exception {
|
|
|
+ public R<Bills> importOne(MultipartFile file, Long billId) throws Exception {
|
|
|
Bills bills = billsService.getById(billId);
|
|
|
SeaBillsDetail seaBillsDetail = new SeaBillsDetail();
|
|
|
// 创建临时文件
|
|
|
@@ -268,16 +269,16 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
Sheet sheet = null;
|
|
|
String errMsg = "";
|
|
|
|
|
|
- try{
|
|
|
+ try {
|
|
|
workbook = WorkbookFactory.create(fis);
|
|
|
sheet = workbook.getSheetAt(0); // 获取第一个工作表
|
|
|
- }catch (Exception e){
|
|
|
+ } catch (Exception e) {
|
|
|
workbook = null;
|
|
|
sheet = null;
|
|
|
errMsg = e.getMessage();
|
|
|
}
|
|
|
|
|
|
- if(ObjectUtils.isNull(workbook) || ObjectUtils.isNull(sheet)) {
|
|
|
+ if (ObjectUtils.isNull(workbook) || ObjectUtils.isNull(sheet)) {
|
|
|
throw new RuntimeException("文件读取失败,该文件可能不是 Excel 文件!" + errMsg);
|
|
|
}
|
|
|
|
|
|
@@ -285,14 +286,14 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
|
|
|
int firstRow = sheet.getFirstRowNum();
|
|
|
int lastRow = sheet.getLastRowNum();
|
|
|
- if(firstRow<=0 && lastRow<0){
|
|
|
+ if (firstRow <= 0 && lastRow < 0) {
|
|
|
throw new RuntimeException("文件内容为空!");
|
|
|
}
|
|
|
|
|
|
StringBuilder sbLines = new StringBuilder();
|
|
|
- for(int r=firstRow; r<=lastRow; r++) {
|
|
|
+ for (int r = firstRow; r <= lastRow; r++) {
|
|
|
String val0 = getSheetCellValueAsString(sheet, r, 0).toUpperCase().replace(" ", "");
|
|
|
- if(val0.isEmpty()){
|
|
|
+ if (val0.isEmpty()) {
|
|
|
sbLines.append(getSheetCellValueAsString(sheet, r, 1).concat("\r\n"));
|
|
|
} else if (val0.equals("TO:")) {
|
|
|
System.out.println("TO:" + getSheetCellValueAsString(sheet, r, 1).toUpperCase());
|
|
|
@@ -330,7 +331,7 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
sbLines.setLength(0);
|
|
|
|
|
|
String blno = getSheetCellValueAsString(sheet, r, 1);
|
|
|
- if(ObjectUtils.isNotNull(blno)){
|
|
|
+ if (ObjectUtils.isNotNull(blno)) {
|
|
|
System.out.println("blno:" + blno);
|
|
|
bills.setMblno(blno);
|
|
|
} else {
|
|
|
@@ -365,7 +366,7 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
} else {
|
|
|
// throw new RuntimeException("船名航次不能为空");
|
|
|
}
|
|
|
- }else if (val0.equals("KINDOFB/L")) {
|
|
|
+ } else if (val0.equals("KINDOFB/L")) {
|
|
|
String s1 = getSheetCellValueAsString(sheet, r, 1);
|
|
|
System.out.println("kindOfBl:" + s1);
|
|
|
if (ObjectUtils.isNotNull(s1)) {
|
|
|
@@ -379,10 +380,10 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
|
|
|
s1 = getSheetCellValueAsString(sheet, r, 4);
|
|
|
System.out.println("PAYMODE:" + s1);
|
|
|
- if(s1.indexOf("PREPAID")>=0){
|
|
|
+ if (s1.indexOf("PREPAID") >= 0) {
|
|
|
bills.setHpaymode("PP");
|
|
|
}
|
|
|
- if(s1.indexOf("COLLECT")>=0){
|
|
|
+ if (s1.indexOf("COLLECT") >= 0) {
|
|
|
bills.setHpaymode("CC");
|
|
|
}
|
|
|
} else if (val0.equals("PLACEOFISSUE")) {
|
|
|
@@ -397,7 +398,7 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
if (ports != null) {
|
|
|
bills.setIssueAtId(ports.getId());
|
|
|
bills.setIssueAt(ports.getEnName());
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
throw new RuntimeException("签单地点 " + port + " 无法识别!");
|
|
|
}
|
|
|
}
|
|
|
@@ -418,9 +419,9 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
// MARKS
|
|
|
int remarkLn = 0;
|
|
|
sbLines.setLength(0);
|
|
|
- for (int l = r + 1; l<=lastRow; l++) {
|
|
|
+ for (int l = r + 1; l <= lastRow; l++) {
|
|
|
String s1 = getSheetCellValueAsString(sheet, l, 0);
|
|
|
- if("REMARK".equals(s1.trim())){
|
|
|
+ if ("REMARK".equals(s1.trim())) {
|
|
|
if (stringBuilderIsNotEmpty(sbLines)) {
|
|
|
System.out.println("marks:" + sbLines);
|
|
|
bills.setMarks(sbLines.toString().trim());
|
|
|
@@ -428,7 +429,7 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
|
|
|
remarkLn = l;
|
|
|
break;
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
sbLines.append(s1.concat("\r\n"));
|
|
|
}
|
|
|
}
|
|
|
@@ -439,10 +440,10 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
|
|
|
Map<String, Object> pkgs = getSheetCellValueAsNumericPrefixMap(sheet, r + 1, 1);
|
|
|
String kindPkgs = pkgs.get("str").toString();
|
|
|
- if(ObjectUtils.isNull(kindPkgs)) {
|
|
|
+ if (ObjectUtils.isNull(kindPkgs)) {
|
|
|
kindPkgs = getSheetCellValueAsString(sheet, r, 1);
|
|
|
}
|
|
|
- if(ObjectUtils.isNotNull(kindPkgs)) {
|
|
|
+ if (ObjectUtils.isNotNull(kindPkgs)) {
|
|
|
BPackages bPackages = bPackagesService.getOne(new LambdaQueryWrapper<BPackages>()
|
|
|
.eq(BPackages::getEnName, kindPkgs));
|
|
|
if (bPackages != null) {
|
|
|
@@ -463,10 +464,10 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
System.out.println("meas:" + meas);
|
|
|
bills.setMeasurement(new BigDecimal(meas).setScale(3, RoundingMode.HALF_UP));
|
|
|
|
|
|
- if(remarkLn>0) {
|
|
|
+ if (remarkLn > 0) {
|
|
|
// DESCRIPTION
|
|
|
sbLines.setLength(0);
|
|
|
- for (int l = r + 1; l<remarkLn; l++) {
|
|
|
+ for (int l = r + 1; l < remarkLn; l++) {
|
|
|
String s1 = getSheetCellValueAsString(sheet, l, 2);
|
|
|
sbLines.append(s1.concat("\r\n"));
|
|
|
}
|
|
|
@@ -474,11 +475,11 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
bills.setCommodityDescr(sbLines.toString().trim());
|
|
|
|
|
|
sbLines.setLength(0);
|
|
|
- for (int l = remarkLn; l<=lastRow; l++) {
|
|
|
+ for (int l = remarkLn; l <= lastRow; l++) {
|
|
|
String s1 = getSheetCellValueAsString(sheet, l, 0);
|
|
|
- if(s1.isEmpty() || "REMARK".equals(s1)){
|
|
|
+ if (s1.isEmpty() || "REMARK".equals(s1)) {
|
|
|
sbLines.append(getSheetCellValueAsString(sheet, l, 1).concat("\r\n"));
|
|
|
- }else if("FINAL DESTINATION FOR THE MERCHANT’S REFERENCE".equals(s1)){
|
|
|
+ } else if ("FINAL DESTINATION FOR THE MERCHANT’S REFERENCE".equals(s1)) {
|
|
|
String port = getSheetCellValueAsString(sheet, l, 4);
|
|
|
System.out.println("finalDestination:" + port);
|
|
|
if (ObjectUtils.isNotNull(port)) {
|
|
|
@@ -492,7 +493,7 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
bills.setFinalDestinationCode(ports.getCode());
|
|
|
bills.setFinalDestinationName(ports.getEnName());
|
|
|
bills.setFinalDestinationNamePrint(ports.getEnName());
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
throw new RuntimeException("最终目的地 " + port + " 无法识别!");
|
|
|
}
|
|
|
}
|
|
|
@@ -521,7 +522,7 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public R<Bills> importPilBooking(MultipartFile file,Long billId) throws Exception {
|
|
|
+ public R<Bills> importPilBooking(MultipartFile file, Long billId) throws Exception {
|
|
|
Bills bills = billsService.getById(billId);
|
|
|
SeaBillsDetail seaBillsDetail = new SeaBillsDetail();
|
|
|
// 创建临时文件
|
|
|
@@ -536,7 +537,7 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
|
|
|
//SHIPPER
|
|
|
StringBuilder shipper = new StringBuilder();
|
|
|
- for(int r=2; r<=6; r++) {
|
|
|
+ for (int r = 2; r <= 6; r++) {
|
|
|
String line = "";
|
|
|
for (int i = 0; i <= 3; i++) {
|
|
|
if (ObjectUtils.isNotNull(sheet.getRow(r).getCell(i))) {
|
|
|
@@ -548,13 +549,13 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
if (stringBuilderIsNotEmpty(shipper)) {
|
|
|
System.out.println("shipper:" + shipper);
|
|
|
seaBillsDetail.setHshipperDetails(shipper.toString().trim());
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
throw new RuntimeException("发货人不能为空");
|
|
|
}
|
|
|
|
|
|
//CONSIGNEE
|
|
|
StringBuilder consignee = new StringBuilder();
|
|
|
- for(int r=9; r<=13; r++) {
|
|
|
+ for (int r = 9; r <= 13; r++) {
|
|
|
String line = "";
|
|
|
for (int i = 0; i <= 3; i++) {
|
|
|
if (ObjectUtils.isNotNull(sheet.getRow(r).getCell(i))) {
|
|
|
@@ -566,12 +567,12 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
if (stringBuilderIsNotEmpty(consignee)) {
|
|
|
System.out.println("consignee:" + consignee);
|
|
|
seaBillsDetail.setHconsigneeDetails(consignee.toString().trim());
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
throw new RuntimeException("收货人不能为空");
|
|
|
}
|
|
|
//NOTIFY PARTY
|
|
|
StringBuilder notifyParty = new StringBuilder();
|
|
|
- for(int r=16; r<=20; r++) {
|
|
|
+ for (int r = 16; r <= 20; r++) {
|
|
|
String line = "";
|
|
|
for (int i = 0; i <= 3; i++) {
|
|
|
if (ObjectUtils.isNotNull(sheet.getRow(r).getCell(i))) {
|
|
|
@@ -583,7 +584,7 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
if (stringBuilderIsNotEmpty(notifyParty)) {
|
|
|
System.out.println("notifyParty:" + notifyParty);
|
|
|
seaBillsDetail.setHnotifyDetails(notifyParty.toString().trim());
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
throw new RuntimeException("通知人不能为空");
|
|
|
}
|
|
|
//VSL/VOY
|
|
|
@@ -710,7 +711,7 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
}
|
|
|
//MARKS
|
|
|
StringBuilder marks = new StringBuilder();
|
|
|
- for(int r=28; r<=44; r++) {
|
|
|
+ for (int r = 28; r <= 44; r++) {
|
|
|
String line = "";
|
|
|
for (int i = 0; i <= 0; i++) {
|
|
|
if (ObjectUtils.isNotNull(sheet.getRow(r).getCell(i))) {
|
|
|
@@ -725,7 +726,7 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
}
|
|
|
//BAGS
|
|
|
if (ObjectUtils.isNotNull(sheet.getRow(28).getCell(2))) {
|
|
|
- double bags = getSheetCellValueAsNumericPrefix(sheet,28, 2);
|
|
|
+ double bags = getSheetCellValueAsNumericPrefix(sheet, 28, 2);
|
|
|
System.out.println("bags:" + bags);
|
|
|
bills.setQuantity(new BigDecimal(bags).setScale(0, RoundingMode.HALF_UP));
|
|
|
} else {
|
|
|
@@ -735,31 +736,31 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
StringBuilder description = new StringBuilder();
|
|
|
String hscode = "";
|
|
|
Boolean findHsCode = false;
|
|
|
- for(int r=28; r<=44; r++) {
|
|
|
+ for (int r = 28; r <= 44; r++) {
|
|
|
String line = "";
|
|
|
if (ObjectUtils.isNotNull(sheet.getRow(r).getCell(3))) {
|
|
|
line = getSheetCellValueAsString(sheet, r, 3);
|
|
|
}
|
|
|
- if(!findHsCode){
|
|
|
+ if (!findHsCode) {
|
|
|
findHsCode = line.toUpperCase().startsWith("HS CODE:");
|
|
|
- if(findHsCode){
|
|
|
+ if (findHsCode) {
|
|
|
hscode = line.substring(8).trim();
|
|
|
bills.setHscode(hscode);
|
|
|
}
|
|
|
}
|
|
|
- if(!findHsCode) {
|
|
|
+ if (!findHsCode) {
|
|
|
description.append(line + "\r\n");
|
|
|
}
|
|
|
}
|
|
|
if (stringBuilderIsNotEmpty(description)) {
|
|
|
System.out.println("description:" + description.toString().trim());
|
|
|
bills.setCommodityDescr(description.toString().trim());
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
throw new RuntimeException("货物描述不能为空");
|
|
|
}
|
|
|
//G.W.
|
|
|
if (ObjectUtils.isNotNull(sheet.getRow(28).getCell(6))) {
|
|
|
- double gw = getSheetCellValueAsNumericPrefix(sheet,28,6);
|
|
|
+ double gw = getSheetCellValueAsNumericPrefix(sheet, 28, 6);
|
|
|
System.out.println("gw:" + gw);
|
|
|
bills.setGrossWeight(new BigDecimal(gw).setScale(3, RoundingMode.HALF_UP));
|
|
|
} else {
|
|
|
@@ -767,7 +768,7 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
}
|
|
|
//MEAS
|
|
|
if (ObjectUtils.isNotNull(sheet.getRow(28).getCell(7))) {
|
|
|
- double meas = getSheetCellValueAsNumericPrefix(sheet,28,7);
|
|
|
+ double meas = getSheetCellValueAsNumericPrefix(sheet, 28, 7);
|
|
|
System.out.println("meas:" + meas);
|
|
|
bills.setMeasurement(new BigDecimal(meas).setScale(3, RoundingMode.HALF_UP));
|
|
|
} else {
|
|
|
@@ -788,7 +789,7 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public R<Bills> importPilCutOffOrders(MultipartFile file,Long billId) throws Exception {
|
|
|
+ public R<Bills> importPilCutOffOrders(MultipartFile file, Long billId) throws Exception {
|
|
|
Bills bills = billsService.getById(billId);
|
|
|
SeaBillsDetail seaBillsDetail = new SeaBillsDetail();
|
|
|
// 创建临时文件
|
|
|
@@ -803,7 +804,7 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
|
|
|
//SHIPPER
|
|
|
StringBuilder shipper = new StringBuilder();
|
|
|
- for(int r=2; r<=6; r++) {
|
|
|
+ for (int r = 2; r <= 6; r++) {
|
|
|
String line = "";
|
|
|
for (int i = 0; i <= 3; i++) {
|
|
|
if (ObjectUtils.isNotNull(sheet.getRow(r).getCell(i))) {
|
|
|
@@ -815,13 +816,13 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
if (stringBuilderIsNotEmpty(shipper)) {
|
|
|
System.out.println("shipper:" + shipper);
|
|
|
seaBillsDetail.setHshipperDetails(shipper.toString().trim());
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
throw new RuntimeException("发货人不能为空");
|
|
|
}
|
|
|
|
|
|
//CONSIGNEE
|
|
|
StringBuilder consignee = new StringBuilder();
|
|
|
- for(int r=9; r<=13; r++) {
|
|
|
+ for (int r = 9; r <= 13; r++) {
|
|
|
String line = "";
|
|
|
for (int i = 0; i <= 3; i++) {
|
|
|
if (ObjectUtils.isNotNull(sheet.getRow(r).getCell(i))) {
|
|
|
@@ -833,12 +834,12 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
if (stringBuilderIsNotEmpty(consignee)) {
|
|
|
System.out.println("consignee:" + consignee);
|
|
|
seaBillsDetail.setHconsigneeDetails(consignee.toString().trim());
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
throw new RuntimeException("收货人不能为空");
|
|
|
}
|
|
|
//NOTIFY PARTY
|
|
|
StringBuilder notifyParty = new StringBuilder();
|
|
|
- for(int r=16; r<=20; r++) {
|
|
|
+ for (int r = 16; r <= 20; r++) {
|
|
|
String line = "";
|
|
|
for (int i = 0; i <= 3; i++) {
|
|
|
if (ObjectUtils.isNotNull(sheet.getRow(r).getCell(i))) {
|
|
|
@@ -850,7 +851,7 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
if (stringBuilderIsNotEmpty(notifyParty)) {
|
|
|
System.out.println("notifyParty:" + notifyParty);
|
|
|
seaBillsDetail.setHnotifyDetails(notifyParty.toString().trim());
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
throw new RuntimeException("通知人不能为空");
|
|
|
}
|
|
|
//VSL/VOY
|
|
|
@@ -977,7 +978,7 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
}
|
|
|
//MARKS
|
|
|
StringBuilder marks = new StringBuilder();
|
|
|
- for(int r=28; r<=44; r++) {
|
|
|
+ for (int r = 28; r <= 44; r++) {
|
|
|
String line = "";
|
|
|
for (int i = 0; i <= 0; i++) {
|
|
|
if (ObjectUtils.isNotNull(sheet.getRow(r).getCell(i))) {
|
|
|
@@ -992,7 +993,7 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
}
|
|
|
//BAGS
|
|
|
if (ObjectUtils.isNotNull(sheet.getRow(28).getCell(2))) {
|
|
|
- double bags = getSheetCellValueAsNumericPrefix(sheet,28, 2);
|
|
|
+ double bags = getSheetCellValueAsNumericPrefix(sheet, 28, 2);
|
|
|
System.out.println("bags:" + bags);
|
|
|
bills.setQuantity(new BigDecimal(bags).setScale(0, RoundingMode.HALF_UP));
|
|
|
} else {
|
|
|
@@ -1002,31 +1003,31 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
StringBuilder description = new StringBuilder();
|
|
|
String hscode = "";
|
|
|
Boolean findHsCode = false;
|
|
|
- for(int r=28; r<=44; r++) {
|
|
|
+ for (int r = 28; r <= 44; r++) {
|
|
|
String line = "";
|
|
|
if (ObjectUtils.isNotNull(sheet.getRow(r).getCell(3))) {
|
|
|
line = getSheetCellValueAsString(sheet, r, 3);
|
|
|
}
|
|
|
- if(!findHsCode){
|
|
|
+ if (!findHsCode) {
|
|
|
findHsCode = line.toUpperCase().startsWith("HS CODE:");
|
|
|
- if(findHsCode){
|
|
|
+ if (findHsCode) {
|
|
|
hscode = line.substring(8).trim();
|
|
|
bills.setHscode(hscode);
|
|
|
}
|
|
|
}
|
|
|
- if(!findHsCode) {
|
|
|
+ if (!findHsCode) {
|
|
|
description.append(line + "\r\n");
|
|
|
}
|
|
|
}
|
|
|
if (stringBuilderIsNotEmpty(description)) {
|
|
|
System.out.println("description:" + description.toString().trim());
|
|
|
bills.setCommodityDescr(description.toString().trim());
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
throw new RuntimeException("货物描述不能为空");
|
|
|
}
|
|
|
//G.W.
|
|
|
if (ObjectUtils.isNotNull(sheet.getRow(28).getCell(6))) {
|
|
|
- double gw = getSheetCellValueAsNumericPrefix(sheet,28,6);
|
|
|
+ double gw = getSheetCellValueAsNumericPrefix(sheet, 28, 6);
|
|
|
System.out.println("gw:" + gw);
|
|
|
bills.setGrossWeight(new BigDecimal(gw).setScale(3, RoundingMode.HALF_UP));
|
|
|
} else {
|
|
|
@@ -1034,7 +1035,7 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
}
|
|
|
//MEAS
|
|
|
if (ObjectUtils.isNotNull(sheet.getRow(28).getCell(7))) {
|
|
|
- double meas = getSheetCellValueAsNumericPrefix(sheet,28,7);
|
|
|
+ double meas = getSheetCellValueAsNumericPrefix(sheet, 28, 7);
|
|
|
System.out.println("meas:" + meas);
|
|
|
bills.setMeasurement(new BigDecimal(meas).setScale(3, RoundingMode.HALF_UP));
|
|
|
} else {
|
|
|
@@ -1054,7 +1055,7 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public R<Bills> importHisenseBill(MultipartFile file,Long billId) throws Exception {
|
|
|
+ public R<Bills> importHisenseBill(MultipartFile file, Long billId) throws Exception {
|
|
|
Bills bills = billsService.getById(billId);
|
|
|
SeaBillsDetail seaBillsDetail = new SeaBillsDetail();
|
|
|
List<Containers> containersList = new ArrayList<>();
|
|
|
@@ -1070,20 +1071,20 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
Sheet sheet = workbook.getSheetAt(0); // 获取第一个工作表
|
|
|
|
|
|
String header = getSheetCellValueAsString(sheet, 0, 0);
|
|
|
- if(!header.toUpperCase().equals("HISENSE B/L INFORMATION")){
|
|
|
+ if (!header.toUpperCase().equals("HISENSE B/L INFORMATION")) {
|
|
|
throw new RuntimeException("这可能不是海信提单文件!");
|
|
|
}
|
|
|
|
|
|
int firstRow = sheet.getFirstRowNum();
|
|
|
int lastRow = sheet.getLastRowNum();
|
|
|
- if(firstRow<=0 && lastRow<0){
|
|
|
+ if (firstRow <= 0 && lastRow < 0) {
|
|
|
throw new RuntimeException("文件内容为空!");
|
|
|
}
|
|
|
|
|
|
StringBuilder sbLines = new StringBuilder();
|
|
|
- for(int r=firstRow; r<=lastRow; r++){
|
|
|
+ for (int r = firstRow; r <= lastRow; r++) {
|
|
|
String val0 = getSheetCellValueAsString(sheet, r, 0).toUpperCase().replace(" ", "");
|
|
|
- if(val0.isEmpty()){
|
|
|
+ if (val0.isEmpty()) {
|
|
|
sbLines.append(getSheetCellValueAsString(sheet, r, 1).concat("\r\n"));
|
|
|
} else if (val0.equals("SHIPPER")) {
|
|
|
sbLines.setLength(0);
|
|
|
@@ -1109,7 +1110,7 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
}
|
|
|
sbLines.setLength(0);
|
|
|
sbLines.append(getSheetCellValueAsString(sheet, r, 1).concat("\r\n"));
|
|
|
- } else if (val0.equals("PORTOFLOADING")||val0.equals("PLACEOFRECEIPT")||val0.equals("PORTOFDISCHARGE")||val0.equals("PLACEOFDELIVERY")) {
|
|
|
+ } else if (val0.equals("PORTOFLOADING") || val0.equals("PLACEOFRECEIPT") || val0.equals("PORTOFDISCHARGE") || val0.equals("PLACEOFDELIVERY")) {
|
|
|
if (val0.equals("PORTOFLOADING") && stringBuilderIsNotEmpty(sbLines)) {
|
|
|
System.out.println("notify2:" + sbLines);
|
|
|
seaBillsDetail.setHnotify2Details(sbLines.toString().trim());
|
|
|
@@ -1170,7 +1171,7 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
.eq(BPackages::getIsDeleted, 0)
|
|
|
.eq(BPackages::getCode, getSheetCellValueAsString(sheet, r, 3))
|
|
|
.last("limit 1"));
|
|
|
- if(ObjectUtils.isNotNull(packages)){
|
|
|
+ if (ObjectUtils.isNotNull(packages)) {
|
|
|
bills.setPackingUnitId(packages.getId());
|
|
|
bills.setPackingUnit(packages.getCode());
|
|
|
}
|
|
|
@@ -1178,10 +1179,10 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
BigDecimal sumGw = new BigDecimal(0L);
|
|
|
BigDecimal sumVol = new BigDecimal(BigInteger.ZERO);
|
|
|
|
|
|
- for(int cr=r+1; cr<=lastRow; cr++) {
|
|
|
+ for (int cr = r + 1; cr <= lastRow; cr++) {
|
|
|
String cntrType = getSheetCellValueAsString(sheet, cr, 0);
|
|
|
String cntrNo = getSheetCellValueAsString(sheet, cr, 1);
|
|
|
- if(cntrType.length()==4 && cntrNo.length()==11) {
|
|
|
+ if (cntrType.length() == 4 && cntrNo.length() == 11) {
|
|
|
Containers containers = new Containers();
|
|
|
containers.setCntrTypeCode(cntrType);
|
|
|
containers.setCntrNo(cntrNo);
|
|
|
@@ -1195,7 +1196,7 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
double v1 = getSheetCellValueAsDouble(sheet, cr, 5);
|
|
|
containers.setMeasurement(BigDecimal.valueOf(v1));
|
|
|
sumVol = sumVol.add(new BigDecimal(v1));
|
|
|
- if(ObjectUtils.isNotNull(packages)){
|
|
|
+ if (ObjectUtils.isNotNull(packages)) {
|
|
|
containers.setPackingUnitId(packages.getId());
|
|
|
containers.setPackingUnit(packages.getCode());
|
|
|
}
|
|
|
@@ -1218,25 +1219,25 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
|
|
|
String lines = ObjectUtils.isNotNull(seaBillsDetail.getHshipperDetails()) ? seaBillsDetail.getHshipperDetails().trim() : "";
|
|
|
String stars = getLastStars(lines);
|
|
|
- if(!stars.isEmpty()){
|
|
|
+ if (!stars.isEmpty()) {
|
|
|
seaBillsDetail.setHshipperDetails(lines.substring(0, lines.length() - stars.length()).concat("\r\n").concat(getStarLines(sbLines, stars)));
|
|
|
}
|
|
|
|
|
|
lines = ObjectUtils.isNotNull(seaBillsDetail.getHconsigneeDetails()) ? seaBillsDetail.getHconsigneeDetails().trim() : "";
|
|
|
stars = getLastStars(lines);
|
|
|
- if(!stars.isEmpty()){
|
|
|
+ if (!stars.isEmpty()) {
|
|
|
seaBillsDetail.setHconsigneeDetails(lines.substring(0, lines.length() - stars.length()).concat("\r\n").concat(getStarLines(sbLines, stars)));
|
|
|
}
|
|
|
|
|
|
lines = ObjectUtils.isNotNull(seaBillsDetail.getHnotifyDetails()) ? seaBillsDetail.getHnotifyDetails().trim() : "";
|
|
|
stars = getLastStars(lines);
|
|
|
- if(!stars.isEmpty()){
|
|
|
+ if (!stars.isEmpty()) {
|
|
|
seaBillsDetail.setHnotifyDetails(lines.substring(0, lines.length() - stars.length()).concat("\r\n").concat(getStarLines(sbLines, stars)));
|
|
|
}
|
|
|
|
|
|
lines = ObjectUtils.isNotNull(seaBillsDetail.getHnotify2Details()) ? seaBillsDetail.getHnotify2Details().trim() : "";
|
|
|
stars = getLastStars(lines);
|
|
|
- if(!stars.isEmpty()){
|
|
|
+ if (!stars.isEmpty()) {
|
|
|
seaBillsDetail.setHnotify2Details(lines.substring(0, lines.length() - stars.length()).concat("\r\n").concat(getStarLines(sbLines, stars)));
|
|
|
}
|
|
|
|
|
|
@@ -1255,7 +1256,7 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public R<List<Containers>> importHisense(MultipartFile file,Long billId) throws Exception {
|
|
|
+ public R<List<Containers>> importHisense(MultipartFile file, Long billId) throws Exception {
|
|
|
List<Containers> containersList = new ArrayList<>();
|
|
|
|
|
|
// 创建临时文件
|
|
|
@@ -1291,4 +1292,208 @@ public class TemplateImportServiceImpl implements ITemplateImportService {
|
|
|
}
|
|
|
return R.data(containersList);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R<Bills> importBills(MultipartFile file, Long billId) throws Exception {
|
|
|
+ Bills bills = billsService.getById(billId);
|
|
|
+ SeaBillsDetail seaBillsDetail = new SeaBillsDetail();
|
|
|
+ // 创建临时文件
|
|
|
+ Path tempFile = Files.createTempFile("prefix", "suffix");
|
|
|
+ // 将MultipartFile的内容复制到临时文件
|
|
|
+ Files.copy(file.getInputStream(), tempFile, StandardCopyOption.REPLACE_EXISTING);
|
|
|
+ // 创建FileInputStream来读取临时文件
|
|
|
+ FileInputStream fis = new FileInputStream(tempFile.toFile());
|
|
|
+ Workbook workbook = null;
|
|
|
+ Sheet sheet = null;
|
|
|
+ String errMsg = "";
|
|
|
+
|
|
|
+ try {
|
|
|
+ workbook = WorkbookFactory.create(fis);
|
|
|
+ sheet = workbook.getSheetAt(0); // 获取第一个工作表
|
|
|
+ } catch (Exception e) {
|
|
|
+ workbook = null;
|
|
|
+ sheet = null;
|
|
|
+ errMsg = e.getMessage();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ObjectUtils.isNull(workbook) || ObjectUtils.isNull(sheet)) {
|
|
|
+ throw new RuntimeException("文件读取失败,该文件可能不是 Excel 文件!" + errMsg);
|
|
|
+ }
|
|
|
+
|
|
|
+ String stringCellValue = "";
|
|
|
+
|
|
|
+ int firstRow = sheet.getFirstRowNum();
|
|
|
+ int lastRow = sheet.getLastRowNum();
|
|
|
+ if (firstRow <= 0 && lastRow < 0) {
|
|
|
+ throw new RuntimeException("文件内容为空!");
|
|
|
+ }
|
|
|
+
|
|
|
+ StringBuilder sbLines = new StringBuilder();
|
|
|
+ //发货人提单描述
|
|
|
+ String hshipper = getSheetCellValueAsString(sheet, 1, 0);
|
|
|
+ if (ObjectUtils.isNotNull(hshipper)) {
|
|
|
+ seaBillsDetail.setHshipperDetails(hshipper);
|
|
|
+ }
|
|
|
+ //收货人提单描述
|
|
|
+ String hconsignee = getSheetCellValueAsString(sheet, 7, 0);
|
|
|
+ if (ObjectUtils.isNotNull(hconsignee)) {
|
|
|
+ seaBillsDetail.setHconsigneeDetails(hconsignee);
|
|
|
+ }
|
|
|
+ //通知人提单描述
|
|
|
+ String hnotify = getSheetCellValueAsString(sheet, 13, 0);
|
|
|
+ if (ObjectUtils.isNotNull(hnotify)) {
|
|
|
+ seaBillsDetail.setHnotifyDetails(hnotify);
|
|
|
+ }
|
|
|
+ //提单号
|
|
|
+ String mblno = getSheetCellValueAsString(sheet, 6, 10);
|
|
|
+ if (ObjectUtils.isNotNull(mblno)) {
|
|
|
+ bills.setMblno(mblno);
|
|
|
+ }
|
|
|
+ //VSL/VOY
|
|
|
+ String vslVoy = getSheetCellValueAsString(sheet, 17, 11);
|
|
|
+ if (ObjectUtils.isNotNull(vslVoy)) {
|
|
|
+ if (vslVoy.contains("/")) {
|
|
|
+ String vsl = vslVoy.substring(0, vslVoy.indexOf("/"));
|
|
|
+ String voy = vslVoy.substring(vslVoy.indexOf("/") + 1);
|
|
|
+ if (ObjectUtils.isNotNull(vsl)) {
|
|
|
+ BVessels vessels = bVesselsService.getOne(new LambdaQueryWrapper<BVessels>()
|
|
|
+ .eq(BVessels::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(BVessels::getIsDeleted, 0)
|
|
|
+ .like(BVessels::getEnName, vsl)
|
|
|
+ .last("limit 1"));
|
|
|
+ if (vessels != null) {
|
|
|
+ bills.setVesselEnName(vessels.getEnName());
|
|
|
+ bills.setVesselCnName(vessels.getCnName());
|
|
|
+ bills.setVesselId(vessels.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ bills.setVoyageNo(voy);
|
|
|
+ System.out.println("vsl:" + vsl);
|
|
|
+ System.out.println("voy:" + voy);
|
|
|
+ System.out.println("vslVoy:" + vslVoy);
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("船名航次不能为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //pol
|
|
|
+ String pol = getSheetCellValueAsString(sheet, 19, 0);
|
|
|
+ System.out.println("Port of Loading:" + pol);
|
|
|
+ if (ObjectUtils.isNotNull(pol)) {
|
|
|
+ BPorts ports = bPortsService.getOne(new LambdaQueryWrapper<BPorts>()
|
|
|
+ .eq(BPorts::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(BPorts::getIsDeleted, 0)
|
|
|
+ .like(BPorts::getEnName, pol)
|
|
|
+ .last("limit 1"));
|
|
|
+ if (ports != null) {
|
|
|
+ bills.setPolId(ports.getId());
|
|
|
+ bills.setPolCnName(ports.getCnName());
|
|
|
+ bills.setPolCode(ports.getCode());
|
|
|
+ bills.setPolEnName(ports.getEnName());
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("Port of Loading:" + pol + " 无法识别!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //pod
|
|
|
+ String pod = getSheetCellValueAsString(sheet, 19, 2);
|
|
|
+ System.out.println("Port of Discharge:" + pod);
|
|
|
+ if (ObjectUtils.isNotNull(pod)) {
|
|
|
+ BPorts ports = bPortsService.getOne(new LambdaQueryWrapper<BPorts>()
|
|
|
+ .eq(BPorts::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(BPorts::getIsDeleted, 0)
|
|
|
+ .like(BPorts::getEnName, pod)
|
|
|
+ .last("limit 1"));
|
|
|
+ if (ports != null) {
|
|
|
+ bills.setPodId(ports.getId());
|
|
|
+ bills.setPodCnName(ports.getCnName());
|
|
|
+ bills.setPodCode(ports.getCode());
|
|
|
+ bills.setPodEnName(ports.getEnName());
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("Port of Discharge:" + pod + " 无法识别!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //交货地
|
|
|
+ String placeDelivery = getSheetCellValueAsString(sheet, 19, 10);
|
|
|
+ System.out.println("Place of delivery:" + placeDelivery);
|
|
|
+ if (ObjectUtils.isNotNull(placeDelivery)) {
|
|
|
+ BPorts ports = bPortsService.getOne(new LambdaQueryWrapper<BPorts>()
|
|
|
+ .eq(BPorts::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(BPorts::getIsDeleted, 0)
|
|
|
+ .like(BPorts::getEnName, placeDelivery)
|
|
|
+ .last("limit 1"));
|
|
|
+ if (ports != null) {
|
|
|
+ bills.setPlaceDeliveryId(ports.getId());
|
|
|
+ bills.setPlaceDeliveryName(ports.getEnName());
|
|
|
+ bills.setPlaceDeliveryCode(ports.getCode());
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("Place of delivery:" + placeDelivery + " 无法识别!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //G.W.
|
|
|
+ String gw = getSheetCellValueAsString(sheet, 21, 11);
|
|
|
+ if (ObjectUtils.isNotNull(gw)) {
|
|
|
+ int lastDigitIndex = this.getIndex(gw);
|
|
|
+ if (lastDigitIndex > 0) {
|
|
|
+ String number = gw.substring(0, lastDigitIndex + 1);
|
|
|
+ bills.setGrossWeight(new BigDecimal(number));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ System.out.println("gw:" + gw);
|
|
|
+ //件数
|
|
|
+ String quantity = getSheetCellValueAsString(sheet, 21, 1);
|
|
|
+ if (ObjectUtils.isNotNull(quantity)) {
|
|
|
+ int lastDigitIndex = this.getIndex(quantity);
|
|
|
+ if (lastDigitIndex > 0) {
|
|
|
+ String number = quantity.substring(0, lastDigitIndex + 1);
|
|
|
+ bills.setQuantity(new BigDecimal(number));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ System.out.println("quantity:" + quantity);
|
|
|
+ //体积
|
|
|
+ String measurement = getSheetCellValueAsString(sheet, 21, 13);
|
|
|
+ if (ObjectUtils.isNotNull(measurement)) {
|
|
|
+ int lastDigitIndex = this.getIndex(measurement);
|
|
|
+ if (lastDigitIndex > 0) {
|
|
|
+ String number = measurement.substring(0, lastDigitIndex + 1);
|
|
|
+ bills.setMeasurement(new BigDecimal(number));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ System.out.println("measurement:" + measurement);
|
|
|
+ //货物描述
|
|
|
+ String commodityDescr = getSheetCellValueAsString(sheet, 21, 3);
|
|
|
+ if (ObjectUtils.isNotNull(commodityDescr)) {
|
|
|
+ bills.setCommodityDescr(commodityDescr);
|
|
|
+ }
|
|
|
+ //货物描述
|
|
|
+ String hpaymode = getSheetCellValueAsString(sheet, 31, 0);
|
|
|
+ if (ObjectUtils.isNotNull(hpaymode)) {
|
|
|
+ if ("FREIGHT PREPAID".equals(hpaymode)) {
|
|
|
+ bills.setHpaymode("PP");
|
|
|
+ } else if ("FREIGHT COLLECT".equals(hpaymode)) {
|
|
|
+ bills.setHpaymode("CC");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ bills.setContainersList(new ArrayList<>());
|
|
|
+ bills.setPreContainersList(new ArrayList<>());
|
|
|
+ bills.setContainersReportsList(new ArrayList<>());
|
|
|
+ bills.setFeeCenterListC(new ArrayList<>());
|
|
|
+ bills.setFeeCenterListD(new ArrayList<>());
|
|
|
+ bills.setFilesList(new ArrayList<>());
|
|
|
+ bills.setWaitingBoxList(new ArrayList<>());
|
|
|
+ bills.setDetail(seaBillsDetail);
|
|
|
+ //将字符串为null的赋默认值为""
|
|
|
+ resetBillsNullValuesAsEmptyString(bills);
|
|
|
+
|
|
|
+ return R.data(bills);
|
|
|
+ }
|
|
|
+
|
|
|
+ private int getIndex(String gw) {
|
|
|
+ int lastIndex = -1; // 用于存储最后一个数字的索引
|
|
|
+ for (int i = gw.length() - 1; i >= 0; i--) {
|
|
|
+ if (Character.isDigit(gw.charAt(i))) {
|
|
|
+ lastIndex = i; // 找到最后一个数字,记录其位置
|
|
|
+ break; // 找到后退出循环
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return lastIndex;
|
|
|
+ }
|
|
|
}
|