1.第三方产品信息导入,第三方往来单位导入修改为json数据导入

master
MrZhai 3 years ago
parent 4182796740
commit d5d7d0eadc

@ -1,6 +1,10 @@
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.ThrCorpEntity;
import com.glxp.sale.admin.entity.thrsys.ThrCorpImportDetailEntity;
import com.glxp.sale.admin.entity.thrsys.ThrCorpImportLogEntity;
import com.glxp.sale.admin.req.basic.FilterUdiIpLogRequest;
@ -8,21 +12,25 @@ import com.glxp.sale.admin.req.info.DeleteRequest;
import com.glxp.sale.admin.res.PageSimpleResponse;
import com.glxp.sale.admin.service.thrsys.ThrCorpImportDetailService;
import com.glxp.sale.admin.service.thrsys.ThrCorpImportLogService;
import com.glxp.sale.admin.service.thrsys.ThrCorpService;
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.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.File;
import java.util.Date;
import java.util.List;
/**
*
*/
@Slf4j
@RestController
public class ThrCorpImportLogController {
@ -30,6 +38,8 @@ public class ThrCorpImportLogController {
ThrCorpImportLogService thrCorpImportLogService;
@Resource
ThrCorpImportDetailService thrCorpImportDetailService;
@Resource
ThrCorpService thrCorpService;
@GetMapping("/udiwms/thrCorp/importLog/filter")
public BaseResponse filter(FilterUdiIpLogRequest filterUdiIpLogRequest,
@ -83,5 +93,45 @@ public class ThrCorpImportLogController {
return ResultVOUtils.success("删除成功");
}
@PostMapping("/udiwms/thrCorp/importLog/uploadCorps")
public BaseResponse uploadCorps(@RequestParam("file") List<MultipartFile> files) {
String filePath = "D:\\udiwms\\filePath\\";
File createFile = new File(filePath);
if (!createFile.exists()) {
createFile.mkdirs();
}
for (int i = 0; i < files.size(); i++) {
MultipartFile file = files.get(i);
if (file.isEmpty()) {
return ResultVOUtils.error(500, "上传第" + (i++) + "个文件失败");
}
String fileName = file.getOriginalFilename();
try {
String fileType = fileName.substring(fileName.lastIndexOf("."));
if (!".json".equals(fileType.toLowerCase())) {
return ResultVOUtils.error(500, "请上传json文件");
}
//导入数据
String jsonData = IoUtil.read(file.getInputStream()).toString();
List<ThrCorpEntity> thrCorpEntities = JSONUtil.toList(jsonData, ThrCorpEntity.class);
//导入日志
ThrCorpImportLogEntity importLog = new ThrCorpImportLogEntity();
String genKey = CustomUtil.getId();
importLog.setGenKey(genKey);
importLog.setFromType("文件导入");
importLog.setStatus(BasicProcessStatus.UDIINFO_IMPORT_UNPROCESS);
importLog.setUpdateTime(new Date(System.currentTimeMillis()));
thrCorpImportLogService.insertImportLog(importLog);
thrCorpService.importJsonData(thrCorpEntities);
importLog.setStatus(BasicProcessStatus.UDIINFO_IMPORT_SUCCESS);
thrCorpImportLogService.updateImportLog(importLog);
} catch (Exception e) {
log.error("产品信息导入失败", e);
}
}
return ResultVOUtils.success("上传成功");
}
}

@ -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("上传成功");

@ -23,4 +23,11 @@ public interface ThrCorpDao {
boolean deleteByUnitId(@Param("unitId") String unitId);
boolean deleteAll();
/**
*
*
* @param thrCorpEntities
*/
void importThrCorps(@Param("thrCorpEntities") List<ThrCorpEntity> thrCorpEntities);
}

@ -24,4 +24,11 @@ public interface ThrProductsDao {
boolean deleteById(@Param("id") String id);
boolean deleteAll();
/**
*
*
* @param thrProductsEntities
*/
void importThrProducts(@Param("thrProductsEntities") List<ThrProductsEntity> thrProductsEntities);
}

@ -21,4 +21,11 @@ public interface ThrCorpService {
boolean deleteByUnitId(String id);
boolean deleteAll();
/**
*
*
* @param thrCorpEntities
*/
void importJsonData(List<ThrCorpEntity> thrCorpEntities);
}

@ -5,12 +5,15 @@ import com.glxp.sale.admin.dao.thrsys.ThrCorpDao;
import com.glxp.sale.admin.entity.thrsys.ThrCorpEntity;
import com.glxp.sale.admin.req.thrsys.FilterThrCorpRequest;
import com.glxp.sale.admin.service.thrsys.ThrCorpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
@Slf4j
@Service
public class ThrCorpServiceImpl implements ThrCorpService {
@ -59,4 +62,14 @@ public class ThrCorpServiceImpl implements ThrCorpService {
public boolean deleteAll() {
return thrCorpDao.deleteAll();
}
@Override
@Async
public void importJsonData(List<ThrCorpEntity> thrCorpEntities) {
try {
thrCorpDao.importThrCorps(thrCorpEntities);
} catch (Exception e) {
log.error("导入第三方往来单位数据异常", e);
}
}
}

@ -1,24 +1,22 @@
package com.glxp.sale.admin.thread;
import com.glxp.sale.admin.constant.BasicProcessStatus;
import com.glxp.sale.admin.entity.thrsys.*;
import com.glxp.sale.admin.req.basic.FilterUdiIpLogRequest;
import com.glxp.sale.admin.dao.thrsys.ThrProductsDao;
import com.glxp.sale.admin.entity.thrsys.ThrProductsEntity;
import com.glxp.sale.admin.entity.thrsys.ThrProductsImportLogEntity;
import com.glxp.sale.admin.req.thrsys.PostThrProductsRequest;
import com.glxp.sale.admin.res.basic.ErpProductsResponse;
import com.glxp.sale.admin.service.thrsys.*;
import com.glxp.sale.admin.service.thrsys.ThrProductsImportLogService;
import com.glxp.sale.admin.util.CustomUtil;
import com.glxp.sale.common.enums.ResultEnum;
import com.glxp.sale.common.util.ResultVOUtils;
import org.springframework.beans.BeanUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Slf4j
@Service
public class ThrProductsImportService {
@ -26,6 +24,8 @@ public class ThrProductsImportService {
private ThrProductsDlService thrProductsDlService;
@Resource
ThrProductsImportLogService thrProductsImportLogService;
@Resource
ThrProductsDao thrProductsDao;
@Async
public void importThrProduct(PostThrProductsRequest postThrProductsRequest) {
@ -59,4 +59,18 @@ public class ThrProductsImportService {
thrProductsImportLogService.updateImportLog(thrProductsImportLogEntity);
}
}
/**
*
*
* @param thrCorpEntities
*/
@Async
public void importJsonData(List<ThrProductsEntity> thrProductsEntities) {
try {
thrProductsDao.importThrProducts(thrProductsEntities);
} catch (Exception e) {
log.error("导入产品信息异常", e);
}
}
}

@ -98,5 +98,23 @@
WHERE id = #{id}
</update>
<insert id="importThrCorps" parameterType="java.util.List">
replace INTO thr_corp
(id, unitId, name, spell, addr, creditNo,
contact, mobile, thirdSysFk, updateTime)
values
<foreach collection="thrCorpEntities" item="item" index="index"
separator=",">
(#{item.id},
#{item.unitId},
#{item.name},
#{item.spell},
#{item.addr},
#{item.creditNo},
#{item.contact},
#{item.mobile},
#{item.thirdSysFk}, #{item.updateTime})
</foreach>
</insert>
</mapper>

@ -117,4 +117,25 @@
<delete id="deleteAll">
DELETE FROM thr_products
</delete>
<insert id="importThrProducts" parameterType="java.util.List">
replace INTO thr_products
(id, code, name, measname, spec, registerNo, manufactory,
cplb, flbm, qxlb, ybbm, sptm, tyshxydm, zczbhhzbapzbh, ylqxzcrbarmc, ylqxzcrbarywmc, cpms,
thirdSysFk, updateTime, supName)
values
<foreach collection="thrProductsEntities" item="item" index="index"
separator=",">
(#{item.id},
#{item.code},
#{item.name},
#{item.measname},
#{item.spec},
#{item.registerNo},
#{item.manufactory},
#{item.cplb}, #{item.flbm}, #{item.qxlb}, #{item.ybbm}, #{item.sptm},
#{item.tyshxydm}, #{item.zczbhhzbapzbh}, #{item.ylqxzcrbarmc}, #{item.ylqxzcrbarywmc}, #{item.cpms},
#{item.thirdSysFk}, #{item.updateTime}, #{item.supName})
</foreach>
</insert>
</mapper>
Loading…
Cancel
Save