diff --git a/api-admin/src/main/java/com/glxp/api/admin/controller/basic/CorpImportLogController.java b/api-admin/src/main/java/com/glxp/api/admin/controller/basic/CorpImportLogController.java index bc4b9995..ab3f1699 100644 --- a/api-admin/src/main/java/com/glxp/api/admin/controller/basic/CorpImportLogController.java +++ b/api-admin/src/main/java/com/glxp/api/admin/controller/basic/CorpImportLogController.java @@ -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.inout.DeleteRequest; 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.CorpImportDetailService; import com.glxp.api.admin.service.basic.CorpImportLogService; @@ -110,7 +111,7 @@ public class CorpImportLogController { //往来单位信息文件导入 @PostMapping("/udiwms/corps/importLog/upload") - public BaseResponse uploadProducts(@RequestParam("file") List files, @RequestParam("thirdSys") String thirdSys) { + public BaseResponse uploadCorp(@RequestParam("file") List files, @RequestParam("thirdSys") String thirdSys) { String filePath = "D:\\udiwms\\filePath\\"; File createFile = new File(filePath); if (!createFile.exists()) { @@ -125,9 +126,9 @@ public class CorpImportLogController { //解析数据 try { String fileType = fileName.substring(fileName.lastIndexOf(".")); - if (".udi".equals(fileType.toLowerCase())) { + if (".udi".equalsIgnoreCase(fileType)) { String jsonData = IoUtil.read(file.getInputStream()).toString(); - List basicUnitMaintainEntities = JSONUtil.toList(jsonData, BasicUnitMaintainEntity.class); + BasicUnitMaintainExportResponse data = JSONUtil.toBean(jsonData, BasicUnitMaintainExportResponse.class); //导入日志 CorpImportLogEntity corpImportLogEntity = new CorpImportLogEntity(); @@ -137,7 +138,7 @@ public class CorpImportLogController { corpImportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_UNPROCESS); corpImportLogEntity.setUpdateTime(new Date(System.currentTimeMillis())); corpImportLogService.insertImportLog(corpImportLogEntity); - basicCorpImportService.importJsonData(basicUnitMaintainEntities); + basicCorpImportService.importJsonData(data); corpImportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_SUCCESS); corpImportLogService.updateImportLog(corpImportLogEntity); } else { diff --git a/api-admin/src/main/java/com/glxp/api/admin/dao/thrsys/ThrCorpDao.java b/api-admin/src/main/java/com/glxp/api/admin/dao/thrsys/ThrCorpDao.java index b3a354cd..d6a1f306 100644 --- a/api-admin/src/main/java/com/glxp/api/admin/dao/thrsys/ThrCorpDao.java +++ b/api-admin/src/main/java/com/glxp/api/admin/dao/thrsys/ThrCorpDao.java @@ -23,4 +23,6 @@ public interface ThrCorpDao { boolean deleteByUnitId(@Param("unitId") String unitId); boolean deleteAll(); + + void importThrCorp(ThrCorpEntity thrCorpEntity); } diff --git a/api-admin/src/main/java/com/glxp/api/admin/thread/BasicCorpImportService.java b/api-admin/src/main/java/com/glxp/api/admin/thread/BasicCorpImportService.java index 64ff55d6..2e38d624 100644 --- a/api-admin/src/main/java/com/glxp/api/admin/thread/BasicCorpImportService.java +++ b/api-admin/src/main/java/com/glxp/api/admin/thread/BasicCorpImportService.java @@ -3,11 +3,14 @@ package com.glxp.api.admin.thread; import cn.hutool.core.collection.CollUtil; import com.glxp.api.admin.constant.BasicProcessStatus; 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.CorpImportDetailEntity; 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.FilterUdiIpLogRequest; +import com.glxp.api.admin.res.basic.BasicUnitMaintainExportResponse; import com.glxp.api.admin.service.basic.BasicUnitMaintainService; import com.glxp.api.admin.service.basic.CorpImportDetailService; import com.glxp.api.admin.service.basic.CorpImportLogService; @@ -76,18 +79,35 @@ public class BasicCorpImportService { * @param basicUnitMaintainEntities */ @Async - public void importJsonData(List basicUnitMaintainEntities) { - if (CollUtil.isNotEmpty(basicUnitMaintainEntities)) { - try { - SqlSession batchSession = sqlSessionFactory.openSession(ExecutorType.BATCH, TransactionIsolationLevel.READ_COMMITTED); - BasicUnitMaintainDao mapper = batchSession.getMapper(BasicUnitMaintainDao.class); - for (BasicUnitMaintainEntity basicUnitMaintainEntity : basicUnitMaintainEntities) { - mapper.importBasicUnitMaintain(basicUnitMaintainEntity); + public void importJsonData(BasicUnitMaintainExportResponse importData) { + if (null != importData) { + SqlSession batchSession = sqlSessionFactory.openSession(ExecutorType.BATCH, TransactionIsolationLevel.READ_COMMITTED); + if (CollUtil.isNotEmpty(importData.getCorpList())) { + try { + List corpList = importData.getCorpList(); + 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 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); } } } diff --git a/api-admin/src/main/java/com/glxp/api/admin/thread/BasicGenJsonService.java b/api-admin/src/main/java/com/glxp/api/admin/thread/BasicGenJsonService.java index 48d35f17..70dca1f7 100644 --- a/api-admin/src/main/java/com/glxp/api/admin/thread/BasicGenJsonService.java +++ b/api-admin/src/main/java/com/glxp/api/admin/thread/BasicGenJsonService.java @@ -4,18 +4,23 @@ import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.io.file.FileWriter; import cn.hutool.core.util.ReflectUtil; +import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONUtil; import com.glxp.api.admin.constant.BasicProcessStatus; import com.glxp.api.admin.dao.basic.UdiInfoDao; 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.entity.basic.*; +import com.glxp.api.admin.entity.thrsys.ThrCorpEntity; import com.glxp.api.admin.entity.thrsys.ThrProductsEntity; import com.glxp.api.admin.req.basic.BasicUnitMaintainFilterRequest; import com.glxp.api.admin.req.basic.CorpsExportRequest; import com.glxp.api.admin.req.basic.FilterUdiInfoRequest; 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.res.basic.BasicUnitMaintainExportResponse; import com.glxp.api.admin.res.basic.UdiRelevanceExportJsonResponse; import com.glxp.api.admin.res.basic.UdiRelevanceResponse; import com.glxp.api.admin.service.basic.BasicUnitMaintainService; @@ -51,33 +56,72 @@ public class BasicGenJsonService { UdiInfoDao udiInfoDao; @Resource ThrProductsDao thrProductsDao; + @Resource + ThrCorpDao thrCorpDao; public void exportCorp(String genKey, CorpsExportRequest corpsExportRequest) { CorpExportLogEntity corpExportLogEntity = corpExportLogService.selectByGenKey(genKey); - List exportData = new ArrayList<>(); + BasicUnitMaintainExportResponse exportData = new BasicUnitMaintainExportResponse(); + + List unitMaintainEntities = new ArrayList<>(); if (corpsExportRequest.getIds() != null && corpsExportRequest.getIds().size() > 0) { List ids = corpsExportRequest.getIds(); ids.forEach(id -> { BasicUnitMaintainFilterRequest request = new BasicUnitMaintainFilterRequest(); request.setId(id); List basicUnitMaintainEntities = basicUnitMaintainService.filterList(request); - exportData.addAll(basicUnitMaintainEntities); + unitMaintainEntities.addAll(basicUnitMaintainEntities); + getThrCorpList(exportData, basicUnitMaintainEntities); }); } else { //一键导出 BasicUnitMaintainFilterRequest filterRequest = new BasicUnitMaintainFilterRequest(); BeanUtils.copyProperties(corpsExportRequest, filterRequest); filterRequest.setPage(null); List basicUnitMaintainEntities = basicUnitMaintainService.filterList(filterRequest); - exportData.addAll(basicUnitMaintainEntities); + unitMaintainEntities.addAll(basicUnitMaintainEntities); + getThrCorpList(exportData, basicUnitMaintainEntities); } + exportData.setCorpList(unitMaintainEntities); FileWriter writer = new FileWriter(corpExportLogEntity.getFilePath()); writer.write(JSONUtil.toJsonStr(exportData)); corpExportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_SUCCESS); corpExportLogService.updateCorpExportLog(corpExportLogEntity); } + /** + * 查询第三方往来单位信息 + * + * @param exportData + * @param basicUnitMaintainEntities + */ + private void getThrCorpList(BasicUnitMaintainExportResponse exportData, List basicUnitMaintainEntities) { + if (CollUtil.isNotEmpty(basicUnitMaintainEntities)) { + List 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 result = thrCorpDao.filterThrCorps(thrCorpRequest); + if (CollUtil.isNotEmpty(result)) { + thrCorpEntities.addAll(result); + } + } + } + } + }); + if (CollUtil.isNotEmpty(thrCorpEntities)) { + exportData.setThrCorpEntities(thrCorpEntities); + } + } + } + /** * 导出json格式医疗器械信息 * diff --git a/api-admin/src/main/java/com/glxp/api/admin/thread/ThrCorpsDlService.java b/api-admin/src/main/java/com/glxp/api/admin/thread/ThrCorpsDlService.java index cecd0ba9..4cf0ff33 100644 --- a/api-admin/src/main/java/com/glxp/api/admin/thread/ThrCorpsDlService.java +++ b/api-admin/src/main/java/com/glxp/api/admin/thread/ThrCorpsDlService.java @@ -356,7 +356,6 @@ public class ThrCorpsDlService { @Async public void genJsonFile(String genKey, ThrCorpExportRequest thrCorpExportRequest) { ThrCorpExportLogEntity thrCorpExportLogEntity = thrCorpExportLogService.selectByGenKey(genKey); - List> excelData = new ArrayList<>(); List exportData = new ArrayList<>(); //选中导出 if (thrCorpExportRequest.getThrCorpEntities() != null && thrCorpExportRequest.getThrCorpEntities().size() > 0) { diff --git a/api-admin/src/main/resources/mybatis/mapper/thrsys/ThrCorpDao.xml b/api-admin/src/main/resources/mybatis/mapper/thrsys/ThrCorpDao.xml index d420aff0..a0c1d4b6 100644 --- a/api-admin/src/main/resources/mybatis/mapper/thrsys/ThrCorpDao.xml +++ b/api-admin/src/main/resources/mybatis/mapper/thrsys/ThrCorpDao.xml @@ -98,5 +98,17 @@ WHERE id = #{id} - + + 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}) + \ No newline at end of file