|
@@ -5,6 +5,8 @@ import cn.hutool.core.date.DateTime;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.lowagie.text.pdf.PdfReader;
|
|
|
+import com.lowagie.text.pdf.parser.PdfTextExtractor;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -20,20 +22,20 @@ import org.jeecg.modules.report.service.IFabricOmOrderService;
|
|
|
import org.jeecg.modules.report.service.IFabricPoOrderService;
|
|
|
import org.jeecg.modules.report.service.ISyFabricLossReportService;
|
|
|
import org.jeecg.modules.system.controller.CommonController;
|
|
|
+import org.jeecg.modules.system.util.DoubleOperation;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+import org.springframework.web.multipart.MultipartHttpServletRequest;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
|
import java.net.URLEncoder;
|
|
|
-import java.util.Collection;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
|
|
|
import static sun.net.www.protocol.http.HttpURLConnection.userAgent;
|
|
|
|
|
@@ -359,4 +361,258 @@ public class FabricLossController {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ @AutoLog(value = "销售订单上传测试")
|
|
|
+ @ApiOperation(value="销售订单上传测试", notes="销售订单上传测试")
|
|
|
+ @PostMapping(value = "/uploadOrder")
|
|
|
+ public Result<String> uploadOrder(HttpServletRequest request, HttpServletResponse response){
|
|
|
+
|
|
|
+ Result<String> result = new Result<String>();
|
|
|
+
|
|
|
+ MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
|
|
+ MultipartFile file = multipartRequest.getFile("file");// 获取上传文件对象
|
|
|
+ StringBuilder content = new StringBuilder();
|
|
|
+ try{
|
|
|
+ PdfReader pdfReader = new PdfReader(file.getBytes());
|
|
|
+ PdfTextExtractor pdfTextExtractor = new PdfTextExtractor(pdfReader);
|
|
|
+ for (int i=1; i<= pdfReader.getNumberOfPages(); i++){
|
|
|
+ content.append(pdfTextExtractor.getTextFromPage(i));
|
|
|
+ content.append("\n");
|
|
|
+ }
|
|
|
+ }catch (Exception ex){
|
|
|
+ result.error500(ex.getMessage());
|
|
|
+ }
|
|
|
+ result.success(parseOrder(content.toString()));
|
|
|
+
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * PMK销售订单上传测试
|
|
|
+ * SUPPLIER COPY 统计页
|
|
|
+ * SUPPLIER COPY STYLE 成分页
|
|
|
+ * SUPPLIER COPY PACKS 成分配比页
|
|
|
+ * SUPPLIER COPY DELIVERIES 交付页
|
|
|
+ * SUPPLIER COPY ITEMS 尾页
|
|
|
+ * @param content
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String parseOrder(String content){
|
|
|
+ int index2 = content.indexOf("SUPPLIER COPY STYLE");
|
|
|
+ int index3 = content.indexOf("SUPPLIER COPY PACKS");
|
|
|
+ int index4 = content.indexOf("SUPPLIER COPY DELIVERIES");
|
|
|
+ int index5 = content.indexOf("SUPPLIER COPY ITEMS");
|
|
|
+ String pContent1 = content.substring(0, index2);
|
|
|
+ String pContent2 = content.substring(index2, index3);
|
|
|
+ String pContent3 = content.substring(index3, index4);
|
|
|
+ String pContent4 = content.substring(index4, index5);
|
|
|
+
|
|
|
+ String styleNo = "";//款号
|
|
|
+ String orderNo = "";//订单编号
|
|
|
+ String closeFactory = "";//成衣加工厂
|
|
|
+ String currency = "";//币种
|
|
|
+ String packageType = "";// 包装方式
|
|
|
+ String orderDate = "";// 订单日期
|
|
|
+ String purchaseOrder = "";//客户订单号
|
|
|
+ String totalNumer = "";//总数量
|
|
|
+ String totalMoney = "";//总金额
|
|
|
+ String invName = "";//存货名称
|
|
|
+ String fibre = "";// 成分
|
|
|
+ String isTc = ""; // 是否tc
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+
|
|
|
+ int startIndex = pContent1.indexOf("Kimball: ")+"Kimball: ".length();
|
|
|
+ int endIndex = pContent1.indexOf("\n", startIndex);
|
|
|
+ styleNo = pContent1.substring(startIndex, endIndex);
|
|
|
+
|
|
|
+ startIndex = pContent1.indexOf("Season/Year: ")+"Season/Year: ".length();
|
|
|
+ endIndex = pContent1.indexOf(" ", startIndex);
|
|
|
+ orderNo = pContent1.substring(startIndex, endIndex);
|
|
|
+ orderNo = orderNo.replace("20", "") +"-PMK-"+styleNo;
|
|
|
+
|
|
|
+ startIndex = pContent1.indexOf("Factory")+"Factory\n".length();
|
|
|
+ endIndex = pContent1.indexOf("\n", startIndex);
|
|
|
+ closeFactory = pContent1.substring(startIndex, endIndex);
|
|
|
+
|
|
|
+ startIndex = pContent1.indexOf("Currency: ")+"Currency: ".length();
|
|
|
+ endIndex = pContent1.indexOf(" ", startIndex);
|
|
|
+ currency = pContent1.substring(startIndex, endIndex);
|
|
|
+
|
|
|
+ startIndex = content.indexOf("H/F: ")+"H/F: ".length();
|
|
|
+ endIndex = content.indexOf("\n", startIndex);
|
|
|
+ packageType = content.substring(startIndex, endIndex);
|
|
|
+
|
|
|
+ startIndex = pContent1.indexOf("Order Date: ")+"Order Date: ".length();
|
|
|
+ endIndex = pContent1.indexOf(" ", startIndex);
|
|
|
+ orderDate = pContent1.substring(startIndex, endIndex);
|
|
|
+
|
|
|
+ startIndex = pContent1.indexOf("Purchase Order: ")+"Purchase Order: ".length();
|
|
|
+ endIndex = pContent1.indexOf("\n", startIndex);
|
|
|
+ purchaseOrder = pContent1.substring(startIndex, endIndex);
|
|
|
+
|
|
|
+ startIndex = pContent1.indexOf("Total Units (Inc. TBC): ")+"Total Units (Inc. TBC): ".length();
|
|
|
+ endIndex = pContent1.indexOf("\n", startIndex);
|
|
|
+ totalNumer = pContent1.substring(startIndex, endIndex);
|
|
|
+
|
|
|
+ startIndex = pContent1.indexOf("Supplier Cost Value: $ ")+"Supplier Cost Value: $ ".length();
|
|
|
+ endIndex = pContent1.indexOf(" ", startIndex);
|
|
|
+ totalMoney = pContent1.substring(startIndex, endIndex);
|
|
|
+
|
|
|
+ startIndex = pContent1.indexOf("Description: ")+"Description: ".length();
|
|
|
+ endIndex = pContent1.indexOf(" Kimball:", startIndex);
|
|
|
+ invName = pContent1.substring(startIndex, endIndex)+styleNo;
|
|
|
+
|
|
|
+ startIndex = pContent2.indexOf("Fibre: ")+"Fibre: ".length();
|
|
|
+ endIndex = pContent2.indexOf("\n", startIndex);
|
|
|
+ fibre = pContent2.substring(startIndex, endIndex);
|
|
|
+ isTc = fibre.indexOf("Recycled")>-1?"是":"否";
|
|
|
+
|
|
|
+ sb.append("订单编号: \t"+orderNo+" \t");
|
|
|
+ sb.append("订单日期: \t"+orderDate+" \t");
|
|
|
+ sb.append("\n");
|
|
|
+ sb.append("客户订单号: \t"+purchaseOrder+" \t");
|
|
|
+ sb.append("成衣加工厂: \t"+closeFactory+" \t");
|
|
|
+ sb.append("\n");
|
|
|
+ sb.append("币种: \t"+currency+" \t");
|
|
|
+ sb.append("包装方式: \t"+packageType+" \t");
|
|
|
+ sb.append("\n");
|
|
|
+ sb.append("总数量: \t"+totalNumer+" \t");
|
|
|
+ sb.append("总金额: \t"+totalMoney+" \t");
|
|
|
+ sb.append("\n");
|
|
|
+
|
|
|
+ sb.append("款号 \t预发货日期 \t预完工日期 \tPackId \t小PO \t分销点 \t存货名称 \t规格型号 \t数量 \t含税单价 \t");
|
|
|
+ sb.append("价税合计 \t箱数 \t颜色 \t是否TC \t尺码 \t");
|
|
|
+ sb.append("\n");
|
|
|
+
|
|
|
+ String[] arrPackDetails = pContent3.split("Pack Id: ");
|
|
|
+
|
|
|
+ // 每个小定单循环,Delivery Number:分割,去掉第一段
|
|
|
+ String[] orderList = pContent4.split("Delivery Number:");
|
|
|
+ for (int i=1; i<orderList.length; i++){
|
|
|
+ String searchStr = orderList[i];
|
|
|
+ startIndex = searchStr.indexOf("Exit Port: ")+"Exit Port: ".length();
|
|
|
+ endIndex = searchStr.indexOf(" Confirmed: ", startIndex);
|
|
|
+ String exitPort = searchStr.substring(startIndex,endIndex);//出口港
|
|
|
+
|
|
|
+ startIndex = searchStr.indexOf("Handover Date: ")+"Handover Date: ".length();
|
|
|
+ endIndex = searchStr.indexOf(" COM:", startIndex);
|
|
|
+ String handoverDDate=searchStr.substring(startIndex,endIndex);// 交期
|
|
|
+ String finishDate = "";//预计完工日期
|
|
|
+ try{
|
|
|
+ finishDate = DateUtils.formatAddDate(handoverDDate, "yyyyMMdd", -15);
|
|
|
+ handoverDDate =DateUtils.date2Str(DateUtils.str2Date(handoverDDate, DateUtils.yyyyMMdd.get()), DateUtils.date_sdf.get());
|
|
|
+ }catch (Exception ex){
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 每个分销点循环
|
|
|
+ String[] stationList = searchStr.split("Destination Number");
|
|
|
+ for (int j=1; j<stationList.length-1;j++){
|
|
|
+ String stationStr = stationList[j];
|
|
|
+
|
|
|
+ String station = "";//分销点
|
|
|
+ String poNo = "";// 小定单号
|
|
|
+ Double price = 0.0;// 单价
|
|
|
+
|
|
|
+ startIndex = stationStr.indexOf("\n")+1;
|
|
|
+ endIndex = stationStr.indexOf("\n", startIndex);
|
|
|
+ String strTmp = stationStr.substring(startIndex,endIndex);
|
|
|
+ String[] arrTmp = strTmp.split(" ");
|
|
|
+ station = arrTmp[1];
|
|
|
+ poNo = arrTmp[0];
|
|
|
+
|
|
|
+ startIndex = endIndex+1;
|
|
|
+ endIndex = stationStr.indexOf("\n", startIndex);
|
|
|
+ strTmp = stationStr.substring(startIndex,endIndex).replace("$","").trim();
|
|
|
+ arrTmp = strTmp.split(" ");
|
|
|
+ price = oConvertUtils.getDouble(arrTmp[0], 0.0);
|
|
|
+
|
|
|
+ startIndex = stationStr.indexOf("Pack Id ");
|
|
|
+ endIndex = stationStr.indexOf("\n", startIndex);
|
|
|
+ startIndex = endIndex+1;
|
|
|
+ strTmp = stationStr.substring(startIndex);
|
|
|
+ String[] arrPacks =strTmp.split("\n");
|
|
|
+ for (int k=0; k<arrPacks.length;k++){
|
|
|
+ String packId = "";// 配比编码
|
|
|
+ Integer packs = 0;// 箱数
|
|
|
+ String color = "";//颜色
|
|
|
+
|
|
|
+ String packRow = arrPacks[k].trim();
|
|
|
+ String[] arrPackCol = packRow.replace(",","").split(" ");
|
|
|
+ if (arrPackCol.length<6) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ List<String> lstSize = new ArrayList<>();
|
|
|
+ int lastSizeIndex = -1;
|
|
|
+ for (int x=0; x<arrPackCol.length;x++){
|
|
|
+ strTmp = arrPackCol[x].trim();
|
|
|
+ startIndex=strTmp.indexOf("/");
|
|
|
+ if (startIndex>-1 && startIndex<strTmp.length()-1 && startIndex>0){
|
|
|
+ if (strTmp.charAt(startIndex-1)>='0' && strTmp.charAt(startIndex-1)<='9' &&
|
|
|
+ strTmp.charAt(startIndex+1)>='0' && strTmp.charAt(startIndex+1)<='9'){
|
|
|
+ lstSize.add(strTmp);
|
|
|
+ lastSizeIndex = x;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (lstSize.size() == 0){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ packId = arrPackCol[0];
|
|
|
+ color = arrPackCol[lastSizeIndex+1];
|
|
|
+ packs = oConvertUtils.getInt(arrPackCol[arrPackCol.length-2]);
|
|
|
+
|
|
|
+ // 查找配码明细
|
|
|
+ for (int l=1; l<arrPackDetails.length;l++){
|
|
|
+ String strPackDetails = arrPackDetails[l];
|
|
|
+ if (strPackDetails.indexOf(packId)>-1){
|
|
|
+ endIndex = strPackDetails.indexOf("Total Pack Units: ");
|
|
|
+ if (endIndex>-1){ // 配码
|
|
|
+ String[] arrRows = strPackDetails.split("\n");
|
|
|
+ for (int x=0;x<arrRows.length;x++){
|
|
|
+ if (arrRows[x].indexOf("Total Pack Units: ")>-1){
|
|
|
+ startIndex = x-1;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String sumRow = arrRows[startIndex].trim();
|
|
|
+ String[] arrSum = sumRow.split(" ");
|
|
|
+
|
|
|
+ for (int m=0;m<lstSize.size();m++) {
|
|
|
+ String strSize = lstSize.get(m);
|
|
|
+ Integer sumPerBox = oConvertUtils.getInt(arrSum[m+1]);
|
|
|
+ Integer sum = sumPerBox*packs;
|
|
|
+ Double money = DoubleOperation.mul(price, sum*1.0, 2);
|
|
|
+ sb.append(styleNo + " \t" + handoverDDate + " \t" + finishDate + " \t"+
|
|
|
+ packId+" \t"+poNo+" \t"+station+" \t"+invName+" \t"+fibre+" \t"+
|
|
|
+ sum+" \t"+price+" \t"+money+" \t"+packs+" \t"+color+" \t"+isTc+" \t"+strSize+" \t\n");
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+ }else{// 独码
|
|
|
+ String strSize = lstSize.get(0);
|
|
|
+ startIndex = strPackDetails.indexOf(strSize)+strSize.length();
|
|
|
+ endIndex = strPackDetails.indexOf("\n", startIndex);
|
|
|
+ Integer sumPerBox = oConvertUtils.getInt(strPackDetails.substring(startIndex, endIndex).trim());
|
|
|
+ Integer sum = sumPerBox*packs;
|
|
|
+ Double money = DoubleOperation.mul(price, sum*1.0, 2);
|
|
|
+ sb.append(styleNo + " \t" + handoverDDate + " \t" + finishDate + " \t"+
|
|
|
+ packId+" \t"+poNo+" \t"+station+" \t"+invName+" \t"+fibre+" \t"+
|
|
|
+ sum+" \t"+price+" \t"+money+" \t"+packs+" \t"+color+" \t"+isTc+" \t"+strSize+" \t\n");
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
}
|