|
|
|
@ -1,8 +1,11 @@
|
|
|
|
|
package com.glxp.sale.admin.controller.basic;
|
|
|
|
|
|
|
|
|
|
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.basic.BasicThirdSysEntity;
|
|
|
|
|
import com.glxp.sale.admin.entity.basic.BasicUnitMaintainEntity;
|
|
|
|
|
import com.glxp.sale.admin.entity.basic.CorpImportDetailEntity;
|
|
|
|
|
import com.glxp.sale.admin.entity.basic.CorpImportLogEntity;
|
|
|
|
|
import com.glxp.sale.admin.req.basic.FilterUdiIpLogRequest;
|
|
|
|
@ -17,6 +20,7 @@ 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 lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
@ -32,6 +36,7 @@ import java.util.ArrayList;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
@RestController
|
|
|
|
|
public class CorpImportLogController {
|
|
|
|
|
@Resource
|
|
|
|
@ -114,7 +119,6 @@ public class CorpImportLogController {
|
|
|
|
|
@PostMapping("/udiwms/corps/importLog/upload")
|
|
|
|
|
public BaseResponse uploadProducts(@RequestParam("file") List<MultipartFile> files, @RequestParam("thirdSys") String thirdSys) {
|
|
|
|
|
|
|
|
|
|
BasicThirdSysEntity basicThirdSysEntity = basicThirdSysService.selectMainThrSys();
|
|
|
|
|
String filePath = "D:\\udiwms\\filePath\\";
|
|
|
|
|
File createFile = new File(filePath);
|
|
|
|
|
if (!createFile.exists()) {
|
|
|
|
@ -126,20 +130,14 @@ public class CorpImportLogController {
|
|
|
|
|
return ResultVOUtils.error(500, "上传第" + (i++) + "个文件失败");
|
|
|
|
|
}
|
|
|
|
|
String fileName = file.getOriginalFilename();
|
|
|
|
|
//解析数据
|
|
|
|
|
try {
|
|
|
|
|
InputStream inputStream = file.getInputStream();
|
|
|
|
|
Workbook workbook = null;
|
|
|
|
|
String filetype = fileName.substring(fileName.lastIndexOf("."));
|
|
|
|
|
String fileType = fileName.substring(fileName.lastIndexOf("."));
|
|
|
|
|
if (".json".equals(fileType.toLowerCase())) {
|
|
|
|
|
String jsonData = IoUtil.read(file.getInputStream()).toString();
|
|
|
|
|
List<BasicUnitMaintainEntity> basicUnitMaintainEntities = JSONUtil.toList(jsonData, BasicUnitMaintainEntity.class);
|
|
|
|
|
|
|
|
|
|
if (".xls".equals(filetype)) {
|
|
|
|
|
workbook = new HSSFWorkbook(inputStream);
|
|
|
|
|
} else if (".xlsx".equals(filetype)) {
|
|
|
|
|
workbook = new XSSFWorkbook(inputStream);
|
|
|
|
|
} else {
|
|
|
|
|
return ResultVOUtils.error(500, "请上传excel文件");
|
|
|
|
|
}
|
|
|
|
|
Sheet sheet = null;
|
|
|
|
|
Row row = null;
|
|
|
|
|
//导入日志
|
|
|
|
|
CorpImportLogEntity corpImportLogEntity = new CorpImportLogEntity();
|
|
|
|
|
String genKey = CustomUtil.getId();
|
|
|
|
|
corpImportLogEntity.setGenKey(genKey);
|
|
|
|
@ -147,191 +145,14 @@ public class CorpImportLogController {
|
|
|
|
|
corpImportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_UNPROCESS);
|
|
|
|
|
corpImportLogEntity.setUpdateTime(new Date(System.currentTimeMillis()));
|
|
|
|
|
corpImportLogService.insertImportLog(corpImportLogEntity);
|
|
|
|
|
List<CorpImportDetailEntity> corpImportDetailEntities = new ArrayList<>();
|
|
|
|
|
for (int j = 0; j < 1; j++) {//workbook.getNumberOfSheets();
|
|
|
|
|
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 || row.getCell(6) == 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())
|
|
|
|
|
|| !"社会信用号".equals(row.getCell(6).getStringCellValue())
|
|
|
|
|
|| !"往来单位状态".equals(row.getCell(7).getStringCellValue())
|
|
|
|
|
|| !"往来单位类型".equals(row.getCell(8).getStringCellValue())
|
|
|
|
|
|| !"thirdId".equals(row.getCell(9).getStringCellValue()))) {
|
|
|
|
|
corpImportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_FAIL);
|
|
|
|
|
corpImportLogEntity.setUpdateTime(new Date(System.currentTimeMillis()));
|
|
|
|
|
corpImportLogEntity.setRemark("文件格式错误!");
|
|
|
|
|
basicCorpImportService.importJsonData(basicUnitMaintainEntities);
|
|
|
|
|
corpImportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_SUCCESS);
|
|
|
|
|
corpImportLogService.updateImportLog(corpImportLogEntity);
|
|
|
|
|
return ResultVOUtils.error(500, "文件格式错误!");
|
|
|
|
|
}
|
|
|
|
|
for (int k = sheet.getFirstRowNum() + 1; k <= sheet.getLastRowNum(); k++) {
|
|
|
|
|
|
|
|
|
|
row = sheet.getRow(k);
|
|
|
|
|
if (row == null || row.getRowNum() <= 0) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (filterEmpty(row)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
CorpImportDetailEntity corpImportDetailEntity = new CorpImportDetailEntity();
|
|
|
|
|
Cell cell1 = row.getCell(0);
|
|
|
|
|
if (cell1 != null) {
|
|
|
|
|
cell1.setCellType(CellType.STRING);
|
|
|
|
|
corpImportDetailEntity.setErpId(cell1.getStringCellValue());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Cell cell2 = row.getCell(1);
|
|
|
|
|
if (cell2 != null) {
|
|
|
|
|
cell2.setCellType(CellType.STRING);
|
|
|
|
|
corpImportDetailEntity.setName(cell2.getStringCellValue());
|
|
|
|
|
}
|
|
|
|
|
Cell cell3 = row.getCell(2);
|
|
|
|
|
if (cell3 != null) {
|
|
|
|
|
cell3.setCellType(CellType.STRING);
|
|
|
|
|
corpImportDetailEntity.setSpell(cell3.getStringCellValue());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
Cell cell4 = row.getCell(3);
|
|
|
|
|
if (cell4 != null) {
|
|
|
|
|
cell4.setCellType(CellType.STRING);
|
|
|
|
|
corpImportDetailEntity.setAddr(cell4.getStringCellValue());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
Cell cell5 = row.getCell(4);
|
|
|
|
|
if (cell5 != null) {
|
|
|
|
|
cell5.setCellType(CellType.STRING);
|
|
|
|
|
corpImportDetailEntity.setContact(cell5.getStringCellValue());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
Cell cell6 = row.getCell(5);
|
|
|
|
|
if (cell6 != null) {
|
|
|
|
|
cell6.setCellType(CellType.STRING);
|
|
|
|
|
corpImportDetailEntity.setMobile(cell6.getStringCellValue());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Cell cell7 = row.getCell(6);
|
|
|
|
|
if (cell7 != null) {
|
|
|
|
|
cell7.setCellType(CellType.STRING);
|
|
|
|
|
corpImportDetailEntity.setCreditNo(cell7.getStringCellValue());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Cell cell8 = row.getCell(7);
|
|
|
|
|
if (cell8 != null) {
|
|
|
|
|
cell8.setCellType(CellType.STRING);
|
|
|
|
|
corpImportDetailEntity.setStatus(cell8.getStringCellValue());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Cell cell9 = row.getCell(8);
|
|
|
|
|
if (cell9 != null) {
|
|
|
|
|
cell9.setCellType(CellType.STRING);
|
|
|
|
|
corpImportDetailEntity.setType(cell9.getStringCellValue());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Cell cell10 = row.getCell(9);
|
|
|
|
|
if (cell10 != null) {
|
|
|
|
|
cell10.setCellType(CellType.STRING);
|
|
|
|
|
corpImportDetailEntity.setThirdId(cell10.getStringCellValue());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Cell cell11 = row.getCell(10);
|
|
|
|
|
if (cell11 != null) {
|
|
|
|
|
cell11.setCellType(CellType.STRING);
|
|
|
|
|
corpImportDetailEntity.setThirdName(cell11.getStringCellValue());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Cell cell12 = row.getCell(11);
|
|
|
|
|
if (cell12 != null) {
|
|
|
|
|
cell12.setCellType(CellType.STRING);
|
|
|
|
|
corpImportDetailEntity.setThirdId1(cell12.getStringCellValue());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Cell cell13 = row.getCell(12);
|
|
|
|
|
if (cell13 != null) {
|
|
|
|
|
cell13.setCellType(CellType.STRING);
|
|
|
|
|
corpImportDetailEntity.setThirdName1(cell13.getStringCellValue());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Cell cell14 = row.getCell(13);
|
|
|
|
|
if (cell14 != null) {
|
|
|
|
|
cell14.setCellType(CellType.STRING);
|
|
|
|
|
corpImportDetailEntity.setThirdId2(cell14.getStringCellValue());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Cell cell15 = row.getCell(14);
|
|
|
|
|
if (cell15 != null) {
|
|
|
|
|
cell15.setCellType(CellType.STRING);
|
|
|
|
|
corpImportDetailEntity.setThirdName2(cell15.getStringCellValue());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Cell cell16 = row.getCell(15);
|
|
|
|
|
if (cell16 != null) {
|
|
|
|
|
cell16.setCellType(CellType.STRING);
|
|
|
|
|
corpImportDetailEntity.setThirdId3(cell16.getStringCellValue());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Cell cell17 = row.getCell(16);
|
|
|
|
|
if (cell17 != null) {
|
|
|
|
|
cell17.setCellType(CellType.STRING);
|
|
|
|
|
corpImportDetailEntity.setThirdName3(cell17.getStringCellValue());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Cell cell18 = row.getCell(17);
|
|
|
|
|
if (cell18 != null) {
|
|
|
|
|
cell18.setCellType(CellType.STRING);
|
|
|
|
|
corpImportDetailEntity.setThirdId4(cell18.getStringCellValue());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Cell cell19 = row.getCell(18);
|
|
|
|
|
if (cell19 != null) {
|
|
|
|
|
cell19.setCellType(CellType.STRING);
|
|
|
|
|
corpImportDetailEntity.setThirdName4(cell19.getStringCellValue());
|
|
|
|
|
}
|
|
|
|
|
if (basicThirdSysEntity != null) {
|
|
|
|
|
if ("thirdId".equals(basicThirdSysEntity.getThirdId())) {
|
|
|
|
|
corpImportDetailEntity.setThirdId(corpImportDetailEntity.getThirdId());
|
|
|
|
|
corpImportDetailEntity.setThirdName(corpImportDetailEntity.getThirdName());
|
|
|
|
|
} else if ("thirdId1".equals(basicThirdSysEntity.getThirdId())) {
|
|
|
|
|
corpImportDetailEntity.setThirdId1(corpImportDetailEntity.getThirdId1());
|
|
|
|
|
corpImportDetailEntity.setThirdName1(corpImportDetailEntity.getThirdName1());
|
|
|
|
|
} else if ("thirdId2".equals(basicThirdSysEntity.getThirdId())) {
|
|
|
|
|
corpImportDetailEntity.setThirdId2(corpImportDetailEntity.getThirdId2());
|
|
|
|
|
corpImportDetailEntity.setThirdName2(corpImportDetailEntity.getThirdName2());
|
|
|
|
|
} else if ("thirdId3".equals(basicThirdSysEntity.getThirdId())) {
|
|
|
|
|
corpImportDetailEntity.setThirdId3(corpImportDetailEntity.getThirdId3());
|
|
|
|
|
corpImportDetailEntity.setThirdName3(corpImportDetailEntity.getThirdName3());
|
|
|
|
|
} else if ("thirdId4".equals(basicThirdSysEntity.getThirdId())) {
|
|
|
|
|
corpImportDetailEntity.setThirdId4(corpImportDetailEntity.getThirdId4());
|
|
|
|
|
corpImportDetailEntity.setThirdName4(corpImportDetailEntity.getThirdName4());
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
corpImportDetailEntity.setThirdId(corpImportDetailEntity.getErpId());
|
|
|
|
|
corpImportDetailEntity.setThirdName(corpImportDetailEntity.getName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
corpImportDetailEntity.setGenKeyFk(genKey);
|
|
|
|
|
corpImportDetailEntity.setImportStatus(BasicProcessStatus.UDIINFO_IMPORT_CODE_UNPROCESS);
|
|
|
|
|
corpImportDetailEntity.setUpdateTime(new Date(System.currentTimeMillis()));
|
|
|
|
|
corpImportDetailEntities.add(corpImportDetailEntity);
|
|
|
|
|
return ResultVOUtils.error(500, "请上传json文件");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
corpImportDetailService.insertCorpImports(corpImportDetailEntities);
|
|
|
|
|
corpImportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_UNPROCESS);
|
|
|
|
|
corpImportLogService.updateImportLog(corpImportLogEntity);
|
|
|
|
|
workbook.close();
|
|
|
|
|
basicCorpImportService.importCorps(genKey);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("导入往来单位信息错误,文件名为:{}", fileName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ResultVOUtils.success("上传成功");
|
|
|
|
@ -374,6 +195,7 @@ public class CorpImportLogController {
|
|
|
|
|
basicCorpImportService.importCorps(genKey);
|
|
|
|
|
return ResultVOUtils.success("上传成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean filterEmpty(Row row) {
|
|
|
|
|
|
|
|
|
|
if (row.getCell(0) != null) {
|
|
|
|
|