|  |  | @ -1,35 +1,35 @@ | 
			
		
	
		
		
			
				
					
					|  |  |  | package com.glxp.sale.admin.controller.thrsys; |  |  |  | package com.glxp.sale.admin.controller.thrsys; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import cn.hutool.core.io.IoUtil; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import cn.hutool.json.JSONUtil; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.github.pagehelper.PageInfo; |  |  |  | import com.github.pagehelper.PageInfo; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import com.glxp.sale.admin.constant.BasicProcessStatus; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import com.glxp.sale.admin.entity.thrsys.ThrProductsEntity; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.glxp.sale.admin.entity.thrsys.ThrProductsImportDetailEntity; |  |  |  | import com.glxp.sale.admin.entity.thrsys.ThrProductsImportDetailEntity; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.glxp.sale.admin.entity.thrsys.ThrProductsImportLogEntity; |  |  |  | import com.glxp.sale.admin.entity.thrsys.ThrProductsImportLogEntity; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.glxp.sale.admin.req.basic.FilterUdiIpLogRequest; |  |  |  | import com.glxp.sale.admin.req.basic.FilterUdiIpLogRequest; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.glxp.sale.admin.req.inout.DeleteRequest; |  |  |  | import com.glxp.sale.admin.req.inout.DeleteRequest; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.glxp.sale.admin.req.thrsys.PostThrProductsRequest; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.glxp.sale.admin.res.PageSimpleResponse; |  |  |  | import com.glxp.sale.admin.res.PageSimpleResponse; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.glxp.sale.admin.res.basic.ErpProductsResponse; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.glxp.sale.admin.service.param.SystemParamConfigService; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.glxp.sale.admin.service.thrsys.ThrProductsImportDetailService; |  |  |  | import com.glxp.sale.admin.service.thrsys.ThrProductsImportDetailService; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.glxp.sale.admin.service.thrsys.ThrProductsImportLogService; |  |  |  | import com.glxp.sale.admin.service.thrsys.ThrProductsImportLogService; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.glxp.sale.admin.thread.ThrProductsImportService; |  |  |  | import com.glxp.sale.admin.thread.ThrProductsImportService; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import com.glxp.sale.admin.util.CustomUtil; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.glxp.sale.common.enums.ResultEnum; |  |  |  | import com.glxp.sale.common.enums.ResultEnum; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.glxp.sale.common.res.BaseResponse; |  |  |  | import com.glxp.sale.common.res.BaseResponse; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.glxp.sale.common.util.ResultVOUtils; |  |  |  | import com.glxp.sale.common.util.ResultVOUtils; | 
			
		
	
		
		
			
				
					
					|  |  |  | import org.apache.commons.lang3.StringUtils; |  |  |  | import lombok.extern.slf4j.Slf4j; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | import org.apache.poi.hssf.usermodel.HSSFWorkbook; |  |  |  | import org.apache.poi.ss.usermodel.CellType; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | import org.apache.poi.ss.usermodel.*; |  |  |  | import org.apache.poi.ss.usermodel.Row; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | import org.apache.poi.xssf.usermodel.XSSFWorkbook; |  |  |  |  | 
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | import org.springframework.validation.BindingResult; |  |  |  | import org.springframework.validation.BindingResult; | 
			
		
	
		
		
			
				
					
					|  |  |  | import org.springframework.web.bind.annotation.*; |  |  |  | import org.springframework.web.bind.annotation.*; | 
			
		
	
		
		
			
				
					
					|  |  |  | import org.springframework.web.multipart.MultipartFile; |  |  |  | import org.springframework.web.multipart.MultipartFile; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | import javax.annotation.Resource; |  |  |  | import javax.annotation.Resource; | 
			
		
	
		
		
			
				
					
					|  |  |  | import java.io.File; |  |  |  | import java.io.File; | 
			
		
	
		
		
			
				
					
					|  |  |  | import java.io.IOException; |  |  |  | import java.util.Date; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | import java.io.InputStream; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | import java.util.ArrayList; |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | import java.util.List; |  |  |  | import java.util.List; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | @Slf4j | 
			
		
	
		
		
			
				
					
					|  |  |  | @RestController |  |  |  | @RestController | 
			
		
	
		
		
			
				
					
					|  |  |  | public class ThrProductsImportLogController { |  |  |  | public class ThrProductsImportLogController { | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -97,7 +97,7 @@ public class ThrProductsImportLogController { | 
			
		
	
		
		
			
				
					
					|  |  |  |     //产品信息导入
 |  |  |  |     //产品信息导入
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     @PostMapping("/udiwms/thrProducts/importLog/upload") |  |  |  |     @PostMapping("/udiwms/thrProducts/importLog/upload") | 
			
		
	
		
		
			
				
					
					|  |  |  |     public BaseResponse uploadPi(@RequestParam("file") List<MultipartFile> files, @RequestParam("thirdSys") String thirdSys) { |  |  |  |     public BaseResponse uploadPi(@RequestParam("file") List<MultipartFile> files, @RequestParam("thirdSys") String thirdSys) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         String filePath = "D:\\1s\\udiwms\\filePath\\"; |  |  |  |         String filePath = "D:\\udiwms\\filePath\\"; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         File createFile = new File(filePath); |  |  |  |         File createFile = new File(filePath); | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (!createFile.exists()) { |  |  |  |         if (!createFile.exists()) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             createFile.mkdirs(); |  |  |  |             createFile.mkdirs(); | 
			
		
	
	
		
		
			
				
					|  |  | @ -109,92 +109,28 @@ public class ThrProductsImportLogController { | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |             String fileName = file.getOriginalFilename(); |  |  |  |             String fileName = file.getOriginalFilename(); | 
			
		
	
		
		
			
				
					
					|  |  |  |             try { |  |  |  |             try { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 InputStream inputStream = file.getInputStream(); |  |  |  |                 String fileType = fileName.substring(fileName.lastIndexOf(".")); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 Workbook workbook = null; |  |  |  |                 if (!".json".equals(fileType.toLowerCase())) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 String filetype = fileName.substring(fileName.lastIndexOf(".")); |  |  |  |                     return ResultVOUtils.error(500, "请上传json文件"); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |                 } | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 if (".xls".equals(filetype)) { |  |  |  |                 //导入数据
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                     workbook = new HSSFWorkbook(inputStream); |  |  |  |                 String jsonData = IoUtil.read(file.getInputStream()).toString(); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 } else if (".xlsx".equals(filetype)) { |  |  |  |                 List<ThrProductsEntity> thrProductsEntities = JSONUtil.toList(jsonData, ThrProductsEntity.class); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                     workbook = new XSSFWorkbook(inputStream); |  |  |  | 
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 } else { |  |  |  |                 //导入日志
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                     return ResultVOUtils.error(500, "请上传excel文件"); |  |  |  |                 ThrProductsImportLogEntity importLog = new ThrProductsImportLogEntity(); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 String genKey = CustomUtil.getId(); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 Sheet sheet = null; |  |  |  |                 importLog.setGenKey(genKey); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 Row row = null; |  |  |  |                 importLog.setFromType("文件导入"); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 List<ErpProductsResponse> erpProductsResponses = new ArrayList<>(); |  |  |  |                 importLog.setStatus(BasicProcessStatus.UDIINFO_IMPORT_UNPROCESS); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 for (int j = 0; j < workbook.getNumberOfSheets(); j++) { |  |  |  | 
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                     sheet = workbook.getSheetAt(j); |  |  |  |                 importLog.setUpdateTime(new Date(System.currentTimeMillis())); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                     if (sheet == null) { |  |  |  |                 thrProductsImportLogService.insertImportLog(importLog); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                         continue; |  |  |  |                 thrProductsImportService.importJsonData(thrProductsEntities); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                     } |  |  |  |                 importLog.setStatus(BasicProcessStatus.UDIINFO_IMPORT_SUCCESS); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                     // 滤过第一行标题
 |  |  |  |                 thrProductsImportLogService.updateImportLog(importLog); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                     row = sheet.getRow(0); |  |  |  |             } catch (Exception e) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                     if ((row.getCell(0) == null || row.getCell(1) == null || row.getCell(2) == null |  |  |  |                 log.error("产品信息导入失败", e); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                             || row.getCell(3) == null || row.getCell(4) == null || row.getCell(5) == null) || |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                             (!"产品ID".equals(row.getCell(0).getStringCellValue()) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                                     || !"产品名称".equals(row.getCell(1).getStringCellValue()) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                                     || !"计量单位".equals(row.getCell(2).getStringCellValue()) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                                     || !"规格型号".equals(row.getCell(3).getStringCellValue()) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                                     || !"注册证号".equals(row.getCell(4).getStringCellValue()) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                                     || !"生产厂家".equals(row.getCell(5).getStringCellValue()))) { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         return ResultVOUtils.error(500, "文件格式错误!"); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                     } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                     for (int k = sheet.getFirstRowNum(); k <= sheet.getLastRowNum(); k++) { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         row = sheet.getRow(k); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         if (row == null || row.getRowNum() <= 0) { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                             continue; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         if (filterEmpty(row)) { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                             continue; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         ErpProductsResponse erpProductsResponse = new ErpProductsResponse(); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         Cell cell = row.getCell(0); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         if (cell != null) { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                             cell.setCellType(CellType.STRING); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                             erpProductsResponse.setCode(cell.getStringCellValue()); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         Cell cell2 = row.getCell(1); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         if (cell2 != null) { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                             cell2.setCellType(CellType.STRING); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                             erpProductsResponse.setName(cell2.getStringCellValue()); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         Cell cell3 = row.getCell(2); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         if (cell3 != null) { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                             cell3.setCellType(CellType.STRING); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                             erpProductsResponse.setMeasname(cell3.getStringCellValue()); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         Cell cell4 = row.getCell(3); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         if (cell4 != null) { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                             cell4.setCellType(CellType.STRING); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                             erpProductsResponse.setSpec(cell4.getStringCellValue()); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         Cell cell5 = row.getCell(4); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         if (cell5 != null) { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                             cell5.setCellType(CellType.STRING); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                             erpProductsResponse.setRegisterNo(cell5.getStringCellValue()); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         Cell cell6 = row.getCell(5); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         if (cell6 != null) { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                             cell6.setCellType(CellType.STRING); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                             erpProductsResponse.setManufactory(cell6.getStringCellValue()); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         Cell cell7 = row.getCell(6); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         if (cell7 != null) { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                             cell7.setCellType(CellType.STRING); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                             erpProductsResponse.setSupName(cell7.getStringCellValue()); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         erpProductsResponses.add(erpProductsResponse); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                     } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 PostThrProductsRequest postThrProductsRequest = new PostThrProductsRequest(); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 postThrProductsRequest.setDatas(erpProductsResponses); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 postThrProductsRequest.setUploadType("文件导入"); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 postThrProductsRequest.setThirdSys(thirdSys); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 thrProductsImportService.importThrProduct(postThrProductsRequest); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 workbook.close(); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             } catch (IOException e) { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 e.printStackTrace(); |  |  |  |  | 
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |         return ResultVOUtils.success("上传成功"); |  |  |  |         return ResultVOUtils.success("上传成功"); | 
			
		
	
	
		
		
			
				
					|  |  | 
 |