|  | @@ -1,6 +1,7 @@
 | 
	
		
			
				|  |  |  package org.jeecg.modules.splfi.controller;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import java.io.File;
 | 
	
		
			
				|  |  | +import java.io.InputStream;
 | 
	
		
			
				|  |  |  import java.io.UnsupportedEncodingException;
 | 
	
		
			
				|  |  |  import java.io.IOException;
 | 
	
		
			
				|  |  |  import java.lang.reflect.Array;
 | 
	
	
		
			
				|  | @@ -19,7 +20,9 @@ import com.alibaba.fastjson.JSONArray;
 | 
	
		
			
				|  |  |  import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  |  import com.google.gson.Gson;
 | 
	
		
			
				|  |  |  import com.google.gson.GsonBuilder;
 | 
	
		
			
				|  |  | -import org.apache.poi.ss.usermodel.Workbook;
 | 
	
		
			
				|  |  | +import org.apache.poi.ss.usermodel.*;
 | 
	
		
			
				|  |  | +import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 | 
	
		
			
				|  |  | +import org.jeecg.common.exception.JeecgBootException;
 | 
	
		
			
				|  |  |  import org.jeecg.common.system.api.ISysBaseAPI;
 | 
	
		
			
				|  |  |  import org.jeecg.common.system.util.JwtUtil;
 | 
	
		
			
				|  |  |  import org.jeecg.common.system.vo.LoginUser;
 | 
	
	
		
			
				|  | @@ -461,39 +464,19 @@ public class SyPackingListFabricController {
 | 
	
		
			
				|  |  |  	public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
 | 
	
		
			
				|  |  |  	  MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
 | 
	
		
			
				|  |  |  	  Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
 | 
	
		
			
				|  |  | -	  for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
 | 
	
		
			
				|  |  | -		  MultipartFile file = entity.getValue();// 获取上传文件对象
 | 
	
		
			
				|  |  | -		  ImportParams params = new ImportParams();
 | 
	
		
			
				|  |  | -		  //params.setTitleRows(1);//注释后就能读取数据了
 | 
	
		
			
				|  |  | -		  //params.setHeadRows(1);
 | 
	
		
			
				|  |  | -		  params.setNeedSave(true);
 | 
	
		
			
				|  |  | +	  for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()){
 | 
	
		
			
				|  |  |  		  try {
 | 
	
		
			
				|  |  | -			  List<SyPackingListFabricVo> list = ExcelImportUtil.importExcel(file.getInputStream(), SyPackingListFabricVo.class, params);
 | 
	
		
			
				|  |  | -			  Map<String,SyPackingListFabric> maps=new HashMap<>();
 | 
	
		
			
				|  |  | -			  for (SyPackingListFabricVo vo : list) {
 | 
	
		
			
				|  |  | -				  SyPackingListFabricItem po =new SyPackingListFabricItem();
 | 
	
		
			
				|  |  | -				  BeanUtils.copyProperties(vo,po);
 | 
	
		
			
				|  |  | -			  	 if(!maps.containsKey(vo.getSyShippingDetailsId())){
 | 
	
		
			
				|  |  | -					 SyPackingListFabric main =new SyPackingListFabric();
 | 
	
		
			
				|  |  | -					 main.setGarmentFactory(vo.getTheGarmentFactory());//成衣工厂
 | 
	
		
			
				|  |  | -					 main.setSyPackingListFabricItem(new ArrayList<>());
 | 
	
		
			
				|  |  | -					 main.getSyPackingListFabricItem().add(po);
 | 
	
		
			
				|  |  | -					 maps.put(vo.getSyShippingDetailsId(),main);
 | 
	
		
			
				|  |  | -				 }else{
 | 
	
		
			
				|  |  | -			  	 	maps.get(vo.getSyShippingDetailsId()).getSyPackingListFabricItem().add(po);
 | 
	
		
			
				|  |  | -				 }
 | 
	
		
			
				|  |  | -			  }
 | 
	
		
			
				|  |  | -			  syPackingListFabricService.excelAdd(maps);
 | 
	
		
			
				|  |  | -			  return Result.OK("文件导入成功!数据行数:" + list.size());
 | 
	
		
			
				|  |  | +			  MultipartFile file = entity.getValue();// 获取上传文件对象
 | 
	
		
			
				|  |  | +			  InputStream inputStream=file.getInputStream();
 | 
	
		
			
				|  |  | +			  Workbook workbook=new XSSFWorkbook(inputStream);
 | 
	
		
			
				|  |  | +			  Map<String,SyPackingListFabric> maps=refreshSheet(workbook);
 | 
	
		
			
				|  |  | +			  syPackingListFabricService.excelAdd(maps);//循环
 | 
	
		
			
				|  |  | +			  return Result.OK("文件导入成功!数据行数:" + maps.size());
 | 
	
		
			
				|  |  |  		  } catch (Exception e) {
 | 
	
		
			
				|  |  |  			  log.error(e.getMessage(),e);
 | 
	
		
			
				|  |  |  			  return Result.error("文件导入失败:"+e.getMessage());
 | 
	
		
			
				|  |  |  		  } finally {
 | 
	
		
			
				|  |  | -			  try {
 | 
	
		
			
				|  |  | -				  file.getInputStream().close();
 | 
	
		
			
				|  |  | -			  } catch (IOException e) {
 | 
	
		
			
				|  |  | -				  e.printStackTrace();
 | 
	
		
			
				|  |  | -			  }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  		  }
 | 
	
		
			
				|  |  |  	  }
 | 
	
		
			
				|  |  |  	  return Result.OK("文件导入失败!");
 | 
	
	
		
			
				|  | @@ -507,56 +490,54 @@ public class SyPackingListFabricController {
 | 
	
		
			
				|  |  |  	  * @return
 | 
	
		
			
				|  |  |  	  */
 | 
	
		
			
				|  |  |  	 @RequestMapping(value = "/importExcel2", method = RequestMethod.POST)
 | 
	
		
			
				|  |  | -	 public Result<?> importExcel2(HttpServletRequest request, HttpServletResponse response) {
 | 
	
		
			
				|  |  | +	 public Result<?> importExcel2(HttpServletRequest request, HttpServletResponse response) throws IOException {
 | 
	
		
			
				|  |  |  		 MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
 | 
	
		
			
				|  |  |  		 Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
 | 
	
		
			
				|  |  | -		 for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
 | 
	
		
			
				|  |  | -			 MultipartFile file = entity.getValue();// 获取上传文件对象
 | 
	
		
			
				|  |  | -			 ImportParams params = new ImportParams();
 | 
	
		
			
				|  |  | -			 //params.setTitleRows(1);//注释后就能读取数据了
 | 
	
		
			
				|  |  | -			 //params.setHeadRows(1);
 | 
	
		
			
				|  |  | -			 params.setNeedSave(true);
 | 
	
		
			
				|  |  | +		 for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()){
 | 
	
		
			
				|  |  |  			 try {
 | 
	
		
			
				|  |  | -				 List<SyPackingListFabricVo> list = ExcelImportUtil.importExcel(file.getInputStream(), SyPackingListFabricVo.class, params);
 | 
	
		
			
				|  |  | -				 Map<String,SyPackingListFabric> maps=new HashMap<>();
 | 
	
		
			
				|  |  | -				 for (SyPackingListFabricVo vo : list) {
 | 
	
		
			
				|  |  | -					 SyPackingListFabricItem po =new SyPackingListFabricItem();
 | 
	
		
			
				|  |  | -					 BeanUtils.copyProperties(vo,po);
 | 
	
		
			
				|  |  | -					 if(po==null){
 | 
	
		
			
				|  |  | -					 	continue;
 | 
	
		
			
				|  |  | -					 }
 | 
	
		
			
				|  |  | -					 if(vo.getManualYarnFlag1()!=null&&vo.getManualYarnFlag1().equals("是")){
 | 
	
		
			
				|  |  | -						 po.setManualYarnFlag(1);
 | 
	
		
			
				|  |  | -					 }else{
 | 
	
		
			
				|  |  | -						 po.setManualYarnFlag(0);
 | 
	
		
			
				|  |  | +				 MultipartFile file = entity.getValue();// 获取上传文件对象
 | 
	
		
			
				|  |  | +				 InputStream inputStream=file.getInputStream();
 | 
	
		
			
				|  |  | +				 Workbook workbook=new XSSFWorkbook(inputStream);
 | 
	
		
			
				|  |  | +				 Map<String,SyPackingListFabric> maps=refreshSheet(workbook);
 | 
	
		
			
				|  |  | +				 String str=syPackingListFabricService.excelTest(maps);//循环
 | 
	
		
			
				|  |  | +				 return Result.OK(str);
 | 
	
		
			
				|  |  | +			 } catch (Exception e) {
 | 
	
		
			
				|  |  | +				 log.error(e.getMessage(),e);
 | 
	
		
			
				|  |  | +				 return Result.error("文件导入失败:"+e.getMessage());
 | 
	
		
			
				|  |  | +			 } finally {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +			 }
 | 
	
		
			
				|  |  | +		 }
 | 
	
		
			
				|  |  | +		 return Result.OK("文件导入失败!");
 | 
	
		
			
				|  |  | +	 }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	 public Map<String,SyPackingListFabric>  refreshSheet(Workbook workbook1) {
 | 
	
		
			
				|  |  | +		 Map<String,SyPackingListFabric> maps=new HashMap<>();
 | 
	
		
			
				|  |  | +		 Iterator sheets=workbook1.sheetIterator();
 | 
	
		
			
				|  |  | +		 while (sheets.hasNext()){
 | 
	
		
			
				|  |  | +			 Sheet sheet=(Sheet) sheets.next();
 | 
	
		
			
				|  |  | +			 for (int x=0;x<=sheet.getLastRowNum();x++){
 | 
	
		
			
				|  |  | +				 Row row=sheet.getRow(x);
 | 
	
		
			
				|  |  | +				 if(x>3){
 | 
	
		
			
				|  |  | +					 List<String> itemStrs=new ArrayList<>();
 | 
	
		
			
				|  |  | +					 for (int i=0;i<row.getLastCellNum();i++){
 | 
	
		
			
				|  |  | +						 Cell cell=row.getCell(i);
 | 
	
		
			
				|  |  | +						 itemStrs.add(cell.toString());
 | 
	
		
			
				|  |  |  					 }
 | 
	
		
			
				|  |  | -					 if(!maps.containsKey(vo.getSyShippingDetailsId())){
 | 
	
		
			
				|  |  | +					 SyPackingListFabricItem syPackingListFabricItem=new SyPackingListFabricItem(itemStrs.toArray(new String[itemStrs.size()]));
 | 
	
		
			
				|  |  | +					 if(!maps.containsKey(syPackingListFabricItem.getGarmentFactory())){
 | 
	
		
			
				|  |  |  						 SyPackingListFabric main =new SyPackingListFabric();
 | 
	
		
			
				|  |  | -						 main.setGarmentFactory(vo.getTheGarmentFactory());//成衣工厂
 | 
	
		
			
				|  |  | +						 main.setGarmentFactory(syPackingListFabricItem.getGarmentFactory());//成衣工厂
 | 
	
		
			
				|  |  |  						 main.setSyPackingListFabricItem(new ArrayList<>());
 | 
	
		
			
				|  |  | -						 main.getSyPackingListFabricItem().add(po);
 | 
	
		
			
				|  |  | -						 maps.put(vo.getSyShippingDetailsId(),main);
 | 
	
		
			
				|  |  | +						 main.getSyPackingListFabricItem().add(syPackingListFabricItem);
 | 
	
		
			
				|  |  | +						 maps.put(syPackingListFabricItem.getGarmentFactory(),main);
 | 
	
		
			
				|  |  |  					 }else{
 | 
	
		
			
				|  |  | -						 maps.get(vo.getSyShippingDetailsId()).getSyPackingListFabricItem().add(po);
 | 
	
		
			
				|  |  | +						 maps.get(syPackingListFabricItem.getGarmentFactory()).getSyPackingListFabricItem().add(syPackingListFabricItem);
 | 
	
		
			
				|  |  |  					 }
 | 
	
		
			
				|  |  |  				 }
 | 
	
		
			
				|  |  | -				 String strs=syPackingListFabricService.excelTest(maps);
 | 
	
		
			
				|  |  | -				 if(strs!=null){
 | 
	
		
			
				|  |  | -					 return Result.OK(strs);
 | 
	
		
			
				|  |  | -				 }
 | 
	
		
			
				|  |  | -				 return Result.OK("文件导入成功!数据行数:" + list.size());
 | 
	
		
			
				|  |  | -			 } catch (Exception e) {
 | 
	
		
			
				|  |  | -				 log.error(e.getMessage(),e);
 | 
	
		
			
				|  |  | -				 return Result.error("文件导入失败:"+e.getMessage());
 | 
	
		
			
				|  |  | -			 } finally {
 | 
	
		
			
				|  |  | -				 try {
 | 
	
		
			
				|  |  | -					 file.getInputStream().close();
 | 
	
		
			
				|  |  | -				 } catch (IOException e) {
 | 
	
		
			
				|  |  | -					 e.printStackTrace();
 | 
	
		
			
				|  |  | -				 }
 | 
	
		
			
				|  |  |  			 }
 | 
	
		
			
				|  |  |  		 }
 | 
	
		
			
				|  |  | -		 return Result.OK("文件导入失败!");
 | 
	
		
			
				|  |  | +		 return maps;
 | 
	
		
			
				|  |  |  	 }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	@AutoLog(value = "手动同步辅料数据")
 | 
	
	
		
			
				|  | @@ -758,4 +739,6 @@ public class SyPackingListFabricController {
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  |  		return result;
 | 
	
		
			
				|  |  |  	 }
 | 
	
		
			
				|  |  | -}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | + }
 |