浏览代码

SRM销售订单导入测试

fenghaifu 8 月之前
父节点
当前提交
349cfddb10

+ 120 - 10
jeecg-boot-module-system/src/main/java/org/jeecg/modules/report/controller/FabricLossController.java

@@ -10,9 +10,13 @@ import com.lowagie.text.pdf.parser.PdfTextExtractor;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.csv.CSVFormat;
+import org.apache.commons.csv.CSVPrinter;
+import org.apache.shiro.SecurityUtils;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.aspect.annotation.AutoLog;
 import org.jeecg.common.system.api.ISysBaseAPI;
+import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.common.util.DateUtils;
 import org.jeecg.common.util.oConvertUtils;
 import org.jeecg.modules.base.service.BaseCommonService;
@@ -22,6 +26,7 @@ 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.entity.SysUser;
 import org.jeecg.modules.system.util.DoubleOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.MediaType;
@@ -371,6 +376,7 @@ public class FabricLossController {
 		MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
 		MultipartFile file = multipartRequest.getFile("file");// 获取上传文件对象
 		StringBuilder content = new StringBuilder();
+		String orderResult = "";
 		try{
 			PdfReader pdfReader = new PdfReader(file.getBytes());
 			PdfTextExtractor pdfTextExtractor = new PdfTextExtractor(pdfReader);
@@ -378,15 +384,20 @@ public class FabricLossController {
 				content.append(pdfTextExtractor.getTextFromPage(i));
 				content.append("\n");
 			}
+			List<String[]> parseData = parseOrder(content.toString());
+			LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+			String userId = user.getId();
+			cacheOrder.put(userId, parseData);
+			result.success("解析成功");
 		}catch (Exception ex){
 			result.error500(ex.getMessage());
 		}
-		result.success(parseOrder(content.toString()));
-
 
 		return result;
 	}
 
+	static HashMap<String,List<String[]>> cacheOrder = new HashMap<>();
+
 	/**
 	 * PMK销售订单上传测试
 	 * SUPPLIER COPY 统计页
@@ -397,7 +408,7 @@ public class FabricLossController {
 	 * @param content
 	 * @return
 	 */
-	private String parseOrder(String content){
+	private List<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");
@@ -423,6 +434,7 @@ public class FabricLossController {
 
 
 		StringBuilder sb = new StringBuilder();
+		List<String[]> ret = new ArrayList<>();
 
 		int startIndex = pContent1.indexOf("Kimball: ")+"Kimball: ".length();
 		int endIndex = pContent1.indexOf("\n", startIndex);
@@ -483,6 +495,33 @@ public class FabricLossController {
 		sb.append("总金额: \t"+totalMoney+"  \t");
 		sb.append("\n");
 
+		List<String> row = new ArrayList<>();
+		row.add("订单编号");
+		row.add(orderNo);
+		row.add("订单日期");
+		row.add(orderDate);
+		ret.add(row.toArray(new String[row.size()]));
+		row = new ArrayList<>();
+		row.add("客户订单号");
+		row.add(purchaseOrder);
+		row.add("成衣加工厂");
+		row.add(closeFactory);
+		ret.add(row.toArray(new String[row.size()]));
+		row = new ArrayList<>();
+		row.add("币种");
+		row.add(currency);
+		row.add("包装方式");
+		row.add(packageType);
+		ret.add(row.toArray(new String[row.size()]));
+		row = new ArrayList<>();
+		row.add("总数量");
+		row.add(totalNumer);
+		row.add("总金额");
+		row.add(totalMoney);
+		ret.add(row.toArray(new String[row.size()]));
+		ret.add(new String[]{"款号","预发货日期","预完工日期","PackId","小PO","分销点","存货名称","规格型号","数量","含税单价","价税合计","箱数","颜色","是否TC","尺码"});
+
+
 		sb.append("款号 \t预发货日期 \t预完工日期 \tPackId \t小PO \t分销点 \t存货名称 \t规格型号 \t数量 \t含税单价 \t");
 		sb.append("价税合计 \t箱数 \t颜色 \t是否TC \t尺码 \t");
 		sb.append("\n");
@@ -539,12 +578,44 @@ public class FabricLossController {
 					String packId = "";// 配比编码
 					Integer packs = 0;// 箱数
 					String color = "";//颜色
+					List<String> lstSize = new ArrayList<>();
 
 					String packRow = arrPacks[k].trim();
+					// 去掉 pack type
+					packRow = packRow.replace("Solid Colour", "").replace("Solid Colour/Solid Size", "");
+					boolean mutilSize = packRow.indexOf(",")>-1;// 是否有多个尺寸
+					String[] arrPackCol = packRow.split(" ");
+					if (arrPackCol.length<5){
+						continue;
+					}
+					packId = arrPackCol[0];
+
+					packs = oConvertUtils.getInt(arrPackCol[arrPackCol.length-2]);
+
+					if (!mutilSize){
+						color = arrPackCol[2];
+						lstSize.add(arrPackCol[1]);
+					}else{
+						for (int x=1;x<arrPackCol.length;x++){
+							String size = arrPackCol[x];
+							if (size.endsWith(",")){
+								lstSize.add(size.replace(",", ""));
+							}else{
+								lstSize.add(size);
+								color = arrPackCol[x+1];
+								break;
+							}
+						}
+					}
+
+
+
+					/*
 					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++){
@@ -560,10 +631,8 @@ public class FabricLossController {
 					}
 					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++){
@@ -582,15 +651,21 @@ public class FabricLossController {
 								String sumRow = arrRows[startIndex].trim();
 								String[] arrSum = sumRow.split(" ");
 
+								int diff = 0;
+								while (!arrSum[diff].matches("[+-]?\\d+") && diff<arrSum.length){
+									diff++;
+								}
 								for (int m=0;m<lstSize.size();m++) {
 									String strSize = lstSize.get(m);
-									Integer sumPerBox = oConvertUtils.getInt(arrSum[m+1]);
+									Integer sumPerBox = oConvertUtils.getInt(arrSum[m+diff]);
 									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");
 
+									ret.add(new String[]{styleNo,handoverDDate,finishDate,packId,poNo,station,invName,fibre,sum.toString(),price.toString(),money.toString(),packs.toString(),color,isTc,strSize});
+
 								};
 
 							}else{// 独码
@@ -603,7 +678,7 @@ public class FabricLossController {
 								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");
-
+								ret.add(new String[]{styleNo,handoverDDate,finishDate,packId,poNo,station,invName,fibre,sum.toString(),price.toString(),money.toString(),packs.toString(),color,isTc,strSize});
 
 							}
 							break;
@@ -612,7 +687,42 @@ public class FabricLossController {
 				}
 			}
 		}
-		return sb.toString();
+		//return sb.toString();
+		return ret;
+	}
+
+
+	/**
+	 * 获取附件内容
+	 * @return
+	 */
+	@RequestMapping(value="/downOrder", method = RequestMethod.GET)
+	public void downOrder(HttpServletRequest request, HttpServletResponse response) throws IOException {
+		// 设置HTTP头信息
+		response.setContentType("text/csv");
+		response.addHeader("Content-Disposition", "attachment; filename=data.csv");
+		response.setCharacterEncoding("UTF-8");
+
+		try (CSVPrinter printer = new CSVPrinter(response.getWriter(), CSVFormat.DEFAULT)) {
+
+			LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+			String userId = user.getId();
+			List<String[]> content = cacheOrder.get(userId);
+			if (content != null){
+				for (String[] row : content){
+					printer.printRecord(row);
+				};
+			}
+
+
+
+
+			// 清空输出流
+			response.flushBuffer();
+		} catch (Exception e) {
+			throw new RuntimeException("Failed to generate CSV file.", e);
+		}
+
 	}
 
 }