|
|
|
@ -1,35 +1,35 @@
|
|
|
|
|
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.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.ThrProductsImportLogEntity;
|
|
|
|
|
import com.glxp.sale.admin.req.basic.FilterUdiIpLogRequest;
|
|
|
|
|
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.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.ThrProductsImportLogService;
|
|
|
|
|
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.res.BaseResponse;
|
|
|
|
|
import com.glxp.sale.common.util.ResultVOUtils;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.poi.ss.usermodel.CellType;
|
|
|
|
|
import org.apache.poi.ss.usermodel.Row;
|
|
|
|
|
import org.springframework.validation.BindingResult;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
@RestController
|
|
|
|
|
public class ThrProductsImportLogController {
|
|
|
|
|
|
|
|
|
@ -97,7 +97,7 @@ public class ThrProductsImportLogController {
|
|
|
|
|
//产品信息导入
|
|
|
|
|
@PostMapping("/udiwms/thrProducts/importLog/upload")
|
|
|
|
|
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);
|
|
|
|
|
if (!createFile.exists()) {
|
|
|
|
|
createFile.mkdirs();
|
|
|
|
@ -109,92 +109,28 @@ public class ThrProductsImportLogController {
|
|
|
|
|
}
|
|
|
|
|
String fileName = file.getOriginalFilename();
|
|
|
|
|
try {
|
|
|
|
|
InputStream inputStream = file.getInputStream();
|
|
|
|
|
Workbook workbook = null;
|
|
|
|
|
String filetype = fileName.substring(fileName.lastIndexOf("."));
|
|
|
|
|
|
|
|
|
|
if (".xls".equals(filetype)) {
|
|
|
|
|
workbook = new HSSFWorkbook(inputStream);
|
|
|
|
|
} else if (".xlsx".equals(filetype)) {
|
|
|
|
|
workbook = new XSSFWorkbook(inputStream);
|
|
|
|
|
} else {
|
|
|
|
|
return ResultVOUtils.error(500, "请上传excel文件");
|
|
|
|
|
String fileType = fileName.substring(fileName.lastIndexOf("."));
|
|
|
|
|
if (!".json".equals(fileType.toLowerCase())) {
|
|
|
|
|
return ResultVOUtils.error(500, "请上传json文件");
|
|
|
|
|
}
|
|
|
|
|
Sheet sheet = null;
|
|
|
|
|
Row row = null;
|
|
|
|
|
List<ErpProductsResponse> erpProductsResponses = new ArrayList<>();
|
|
|
|
|
for (int j = 0; j < workbook.getNumberOfSheets(); j++) {
|
|
|
|
|
sheet = workbook.getSheetAt(j);
|
|
|
|
|
if (sheet == null) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
// 滤过第一行标题
|
|
|
|
|
row = sheet.getRow(0);
|
|
|
|
|
if ((row.getCell(0) == null || row.getCell(1) == null || row.getCell(2) == null
|
|
|
|
|
|| 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();
|
|
|
|
|
//导入数据
|
|
|
|
|
String jsonData = IoUtil.read(file.getInputStream()).toString();
|
|
|
|
|
List<ThrProductsEntity> thrProductsEntities = JSONUtil.toList(jsonData, ThrProductsEntity.class);
|
|
|
|
|
|
|
|
|
|
//导入日志
|
|
|
|
|
ThrProductsImportLogEntity importLog = new ThrProductsImportLogEntity();
|
|
|
|
|
String genKey = CustomUtil.getId();
|
|
|
|
|
importLog.setGenKey(genKey);
|
|
|
|
|
importLog.setFromType("文件导入");
|
|
|
|
|
importLog.setStatus(BasicProcessStatus.UDIINFO_IMPORT_UNPROCESS);
|
|
|
|
|
|
|
|
|
|
importLog.setUpdateTime(new Date(System.currentTimeMillis()));
|
|
|
|
|
thrProductsImportLogService.insertImportLog(importLog);
|
|
|
|
|
thrProductsImportService.importJsonData(thrProductsEntities);
|
|
|
|
|
importLog.setStatus(BasicProcessStatus.UDIINFO_IMPORT_SUCCESS);
|
|
|
|
|
thrProductsImportLogService.updateImportLog(importLog);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("产品信息导入失败", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ResultVOUtils.success("上传成功");
|
|
|
|
|