1.基础数据往来单位信息导入导出关联第三方数据

master
MrZhai 3 years ago
parent 971b8e2b51
commit 392a296754

@ -9,6 +9,7 @@ import com.glxp.api.admin.req.basic.FilterUdiIpLogRequest;
import com.glxp.api.admin.req.basic.PostCorpsRequest; import com.glxp.api.admin.req.basic.PostCorpsRequest;
import com.glxp.api.admin.req.inout.DeleteRequest; import com.glxp.api.admin.req.inout.DeleteRequest;
import com.glxp.api.admin.res.PageSimpleResponse; import com.glxp.api.admin.res.PageSimpleResponse;
import com.glxp.api.admin.res.basic.BasicUnitMaintainExportResponse;
import com.glxp.api.admin.service.basic.BasicThirdSysService; import com.glxp.api.admin.service.basic.BasicThirdSysService;
import com.glxp.api.admin.service.basic.CorpImportDetailService; import com.glxp.api.admin.service.basic.CorpImportDetailService;
import com.glxp.api.admin.service.basic.CorpImportLogService; import com.glxp.api.admin.service.basic.CorpImportLogService;
@ -110,7 +111,7 @@ public class CorpImportLogController {
//往来单位信息文件导入 //往来单位信息文件导入
@PostMapping("/udiwms/corps/importLog/upload") @PostMapping("/udiwms/corps/importLog/upload")
public BaseResponse uploadProducts(@RequestParam("file") List<MultipartFile> files, @RequestParam("thirdSys") String thirdSys) { public BaseResponse uploadCorp(@RequestParam("file") List<MultipartFile> files, @RequestParam("thirdSys") String thirdSys) {
String filePath = "D:\\udiwms\\filePath\\"; String filePath = "D:\\udiwms\\filePath\\";
File createFile = new File(filePath); File createFile = new File(filePath);
if (!createFile.exists()) { if (!createFile.exists()) {
@ -125,9 +126,9 @@ public class CorpImportLogController {
//解析数据 //解析数据
try { try {
String fileType = fileName.substring(fileName.lastIndexOf(".")); String fileType = fileName.substring(fileName.lastIndexOf("."));
if (".udi".equals(fileType.toLowerCase())) { if (".udi".equalsIgnoreCase(fileType)) {
String jsonData = IoUtil.read(file.getInputStream()).toString(); String jsonData = IoUtil.read(file.getInputStream()).toString();
List<BasicUnitMaintainEntity> basicUnitMaintainEntities = JSONUtil.toList(jsonData, BasicUnitMaintainEntity.class); BasicUnitMaintainExportResponse data = JSONUtil.toBean(jsonData, BasicUnitMaintainExportResponse.class);
//导入日志 //导入日志
CorpImportLogEntity corpImportLogEntity = new CorpImportLogEntity(); CorpImportLogEntity corpImportLogEntity = new CorpImportLogEntity();
@ -137,7 +138,7 @@ public class CorpImportLogController {
corpImportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_UNPROCESS); corpImportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_UNPROCESS);
corpImportLogEntity.setUpdateTime(new Date(System.currentTimeMillis())); corpImportLogEntity.setUpdateTime(new Date(System.currentTimeMillis()));
corpImportLogService.insertImportLog(corpImportLogEntity); corpImportLogService.insertImportLog(corpImportLogEntity);
basicCorpImportService.importJsonData(basicUnitMaintainEntities); basicCorpImportService.importJsonData(data);
corpImportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_SUCCESS); corpImportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_SUCCESS);
corpImportLogService.updateImportLog(corpImportLogEntity); corpImportLogService.updateImportLog(corpImportLogEntity);
} else { } else {

@ -23,4 +23,6 @@ public interface ThrCorpDao {
boolean deleteByUnitId(@Param("unitId") String unitId); boolean deleteByUnitId(@Param("unitId") String unitId);
boolean deleteAll(); boolean deleteAll();
void importThrCorp(ThrCorpEntity thrCorpEntity);
} }

@ -3,11 +3,14 @@ package com.glxp.api.admin.thread;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import com.glxp.api.admin.constant.BasicProcessStatus; import com.glxp.api.admin.constant.BasicProcessStatus;
import com.glxp.api.admin.dao.basic.BasicUnitMaintainDao; import com.glxp.api.admin.dao.basic.BasicUnitMaintainDao;
import com.glxp.api.admin.dao.thrsys.ThrCorpDao;
import com.glxp.api.admin.entity.basic.BasicUnitMaintainEntity; import com.glxp.api.admin.entity.basic.BasicUnitMaintainEntity;
import com.glxp.api.admin.entity.basic.CorpImportDetailEntity; import com.glxp.api.admin.entity.basic.CorpImportDetailEntity;
import com.glxp.api.admin.entity.basic.CorpImportLogEntity; import com.glxp.api.admin.entity.basic.CorpImportLogEntity;
import com.glxp.api.admin.entity.thrsys.ThrCorpEntity;
import com.glxp.api.admin.req.basic.BasicUnitMaintainFilterRequest; import com.glxp.api.admin.req.basic.BasicUnitMaintainFilterRequest;
import com.glxp.api.admin.req.basic.FilterUdiIpLogRequest; import com.glxp.api.admin.req.basic.FilterUdiIpLogRequest;
import com.glxp.api.admin.res.basic.BasicUnitMaintainExportResponse;
import com.glxp.api.admin.service.basic.BasicUnitMaintainService; import com.glxp.api.admin.service.basic.BasicUnitMaintainService;
import com.glxp.api.admin.service.basic.CorpImportDetailService; import com.glxp.api.admin.service.basic.CorpImportDetailService;
import com.glxp.api.admin.service.basic.CorpImportLogService; import com.glxp.api.admin.service.basic.CorpImportLogService;
@ -76,18 +79,35 @@ public class BasicCorpImportService {
* @param basicUnitMaintainEntities * @param basicUnitMaintainEntities
*/ */
@Async @Async
public void importJsonData(List<BasicUnitMaintainEntity> basicUnitMaintainEntities) { public void importJsonData(BasicUnitMaintainExportResponse importData) {
if (CollUtil.isNotEmpty(basicUnitMaintainEntities)) { if (null != importData) {
try { SqlSession batchSession = sqlSessionFactory.openSession(ExecutorType.BATCH, TransactionIsolationLevel.READ_COMMITTED);
SqlSession batchSession = sqlSessionFactory.openSession(ExecutorType.BATCH, TransactionIsolationLevel.READ_COMMITTED); if (CollUtil.isNotEmpty(importData.getCorpList())) {
BasicUnitMaintainDao mapper = batchSession.getMapper(BasicUnitMaintainDao.class); try {
for (BasicUnitMaintainEntity basicUnitMaintainEntity : basicUnitMaintainEntities) { List<BasicUnitMaintainEntity> corpList = importData.getCorpList();
mapper.importBasicUnitMaintain(basicUnitMaintainEntity); BasicUnitMaintainDao mapper = batchSession.getMapper(BasicUnitMaintainDao.class);
for (BasicUnitMaintainEntity basicUnitMaintainEntity : corpList) {
mapper.importBasicUnitMaintain(basicUnitMaintainEntity);
}
batchSession.commit();
log.info("导入往来单位数据成功,导入数量为:{} 条", corpList.size());
} catch (Exception e) {
log.error("导入往来单位信息异常", e);
}
}
if (CollUtil.isNotEmpty(importData.getThrCorpEntities())) {
try {
List<ThrCorpEntity> thrCorpEntities = importData.getThrCorpEntities();
ThrCorpDao mapper = batchSession.getMapper(ThrCorpDao.class);
thrCorpEntities.forEach(thrCorpEntity -> {
mapper.importThrCorp(thrCorpEntity);
});
batchSession.commit();
log.info("导入第三方往来单位数据成功,导入数量为:{}", thrCorpEntities.size());
} catch (Exception e) {
log.error("导入第三方往来单位数据失败", e);
} }
batchSession.commit();
log.info("导入数据成功,导入数量为:{} 条", basicUnitMaintainEntities.size());
} catch (Exception e) {
log.error("导入往来单位信息异常", e);
} }
} }
} }

@ -4,18 +4,23 @@ import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.file.FileWriter; import cn.hutool.core.io.file.FileWriter;
import cn.hutool.core.util.ReflectUtil; import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.glxp.api.admin.constant.BasicProcessStatus; import com.glxp.api.admin.constant.BasicProcessStatus;
import com.glxp.api.admin.dao.basic.UdiInfoDao; import com.glxp.api.admin.dao.basic.UdiInfoDao;
import com.glxp.api.admin.dao.basic.UdiRelevanceDao; import com.glxp.api.admin.dao.basic.UdiRelevanceDao;
import com.glxp.api.admin.dao.thrsys.ThrCorpDao;
import com.glxp.api.admin.dao.thrsys.ThrProductsDao; import com.glxp.api.admin.dao.thrsys.ThrProductsDao;
import com.glxp.api.admin.entity.basic.*; import com.glxp.api.admin.entity.basic.*;
import com.glxp.api.admin.entity.thrsys.ThrCorpEntity;
import com.glxp.api.admin.entity.thrsys.ThrProductsEntity; import com.glxp.api.admin.entity.thrsys.ThrProductsEntity;
import com.glxp.api.admin.req.basic.BasicUnitMaintainFilterRequest; import com.glxp.api.admin.req.basic.BasicUnitMaintainFilterRequest;
import com.glxp.api.admin.req.basic.CorpsExportRequest; import com.glxp.api.admin.req.basic.CorpsExportRequest;
import com.glxp.api.admin.req.basic.FilterUdiInfoRequest; import com.glxp.api.admin.req.basic.FilterUdiInfoRequest;
import com.glxp.api.admin.req.basic.UdiInfoExportRequest; import com.glxp.api.admin.req.basic.UdiInfoExportRequest;
import com.glxp.api.admin.req.thrsys.FilterThrCorpRequest;
import com.glxp.api.admin.req.thrsys.FilterThrProductsRequest; import com.glxp.api.admin.req.thrsys.FilterThrProductsRequest;
import com.glxp.api.admin.res.basic.BasicUnitMaintainExportResponse;
import com.glxp.api.admin.res.basic.UdiRelevanceExportJsonResponse; import com.glxp.api.admin.res.basic.UdiRelevanceExportJsonResponse;
import com.glxp.api.admin.res.basic.UdiRelevanceResponse; import com.glxp.api.admin.res.basic.UdiRelevanceResponse;
import com.glxp.api.admin.service.basic.BasicUnitMaintainService; import com.glxp.api.admin.service.basic.BasicUnitMaintainService;
@ -51,33 +56,72 @@ public class BasicGenJsonService {
UdiInfoDao udiInfoDao; UdiInfoDao udiInfoDao;
@Resource @Resource
ThrProductsDao thrProductsDao; ThrProductsDao thrProductsDao;
@Resource
ThrCorpDao thrCorpDao;
public void exportCorp(String genKey, CorpsExportRequest corpsExportRequest) { public void exportCorp(String genKey, CorpsExportRequest corpsExportRequest) {
CorpExportLogEntity corpExportLogEntity = corpExportLogService.selectByGenKey(genKey); CorpExportLogEntity corpExportLogEntity = corpExportLogService.selectByGenKey(genKey);
List<BasicUnitMaintainEntity> exportData = new ArrayList<>(); BasicUnitMaintainExportResponse exportData = new BasicUnitMaintainExportResponse();
List<BasicUnitMaintainEntity> unitMaintainEntities = new ArrayList<>();
if (corpsExportRequest.getIds() != null && corpsExportRequest.getIds().size() > 0) { if (corpsExportRequest.getIds() != null && corpsExportRequest.getIds().size() > 0) {
List<Integer> ids = corpsExportRequest.getIds(); List<Integer> ids = corpsExportRequest.getIds();
ids.forEach(id -> { ids.forEach(id -> {
BasicUnitMaintainFilterRequest request = new BasicUnitMaintainFilterRequest(); BasicUnitMaintainFilterRequest request = new BasicUnitMaintainFilterRequest();
request.setId(id); request.setId(id);
List<BasicUnitMaintainEntity> basicUnitMaintainEntities = basicUnitMaintainService.filterList(request); List<BasicUnitMaintainEntity> basicUnitMaintainEntities = basicUnitMaintainService.filterList(request);
exportData.addAll(basicUnitMaintainEntities); unitMaintainEntities.addAll(basicUnitMaintainEntities);
getThrCorpList(exportData, basicUnitMaintainEntities);
}); });
} else { //一键导出 } else { //一键导出
BasicUnitMaintainFilterRequest filterRequest = new BasicUnitMaintainFilterRequest(); BasicUnitMaintainFilterRequest filterRequest = new BasicUnitMaintainFilterRequest();
BeanUtils.copyProperties(corpsExportRequest, filterRequest); BeanUtils.copyProperties(corpsExportRequest, filterRequest);
filterRequest.setPage(null); filterRequest.setPage(null);
List<BasicUnitMaintainEntity> basicUnitMaintainEntities = basicUnitMaintainService.filterList(filterRequest); List<BasicUnitMaintainEntity> basicUnitMaintainEntities = basicUnitMaintainService.filterList(filterRequest);
exportData.addAll(basicUnitMaintainEntities); unitMaintainEntities.addAll(basicUnitMaintainEntities);
getThrCorpList(exportData, basicUnitMaintainEntities);
} }
exportData.setCorpList(unitMaintainEntities);
FileWriter writer = new FileWriter(corpExportLogEntity.getFilePath()); FileWriter writer = new FileWriter(corpExportLogEntity.getFilePath());
writer.write(JSONUtil.toJsonStr(exportData)); writer.write(JSONUtil.toJsonStr(exportData));
corpExportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_SUCCESS); corpExportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_SUCCESS);
corpExportLogService.updateCorpExportLog(corpExportLogEntity); corpExportLogService.updateCorpExportLog(corpExportLogEntity);
} }
/**
*
*
* @param exportData
* @param basicUnitMaintainEntities
*/
private void getThrCorpList(BasicUnitMaintainExportResponse exportData, List<BasicUnitMaintainEntity> basicUnitMaintainEntities) {
if (CollUtil.isNotEmpty(basicUnitMaintainEntities)) {
List<ThrCorpEntity> thrCorpEntities = new ArrayList<>();
Field[] fields = ReflectUtil.getFields(BasicUnitMaintainEntity.class);
basicUnitMaintainEntities.forEach(basicUnitMaintainEntity -> {
for (Field field : fields) {
if (field.getName().contains("thirdId")) {
String value = String.valueOf(ReflectUtil.getFieldValue(basicUnitMaintainEntity, field));
if (StrUtil.isNotBlank(value)) {
FilterThrCorpRequest thrCorpRequest = new FilterThrCorpRequest();
thrCorpRequest.setThirdSysFk("thirdId");
thrCorpRequest.setUnitId(value);
List<ThrCorpEntity> result = thrCorpDao.filterThrCorps(thrCorpRequest);
if (CollUtil.isNotEmpty(result)) {
thrCorpEntities.addAll(result);
}
}
}
}
});
if (CollUtil.isNotEmpty(thrCorpEntities)) {
exportData.setThrCorpEntities(thrCorpEntities);
}
}
}
/** /**
* json * json
* *

@ -356,7 +356,6 @@ public class ThrCorpsDlService {
@Async @Async
public void genJsonFile(String genKey, ThrCorpExportRequest thrCorpExportRequest) { public void genJsonFile(String genKey, ThrCorpExportRequest thrCorpExportRequest) {
ThrCorpExportLogEntity thrCorpExportLogEntity = thrCorpExportLogService.selectByGenKey(genKey); ThrCorpExportLogEntity thrCorpExportLogEntity = thrCorpExportLogService.selectByGenKey(genKey);
List<List<String>> excelData = new ArrayList<>();
List<ThrCorpEntity> exportData = new ArrayList<>(); List<ThrCorpEntity> exportData = new ArrayList<>();
//选中导出 //选中导出
if (thrCorpExportRequest.getThrCorpEntities() != null && thrCorpExportRequest.getThrCorpEntities().size() > 0) { if (thrCorpExportRequest.getThrCorpEntities() != null && thrCorpExportRequest.getThrCorpEntities().size() > 0) {

@ -98,5 +98,17 @@
WHERE id = #{id} WHERE id = #{id}
</update> </update>
<insert id="importThrCorp" parameterType="com.glxp.api.admin.entity.thrsys.ThrCorpEntity">
replace into thr_corp (id, unitId, spell, addr, creditNo, contact, mobile, thirdSysFk, name, updateTime)
values (#{id},
#{unitId},
#{spell},
#{addr},
#{creditNo},
#{contact},
#{mobile},
#{thirdSysFk},
#{name},
#{updateTime})
</insert>
</mapper> </mapper>
Loading…
Cancel
Save