diff --git a/api-admin/src/main/java/com/glxp/api/admin/constant/BasicProcessStatus.java b/api-admin/src/main/java/com/glxp/api/admin/constant/BasicProcessStatus.java index 444c9455..e2213fba 100644 --- a/api-admin/src/main/java/com/glxp/api/admin/constant/BasicProcessStatus.java +++ b/api-admin/src/main/java/com/glxp/api/admin/constant/BasicProcessStatus.java @@ -17,6 +17,7 @@ public class BasicProcessStatus { public static final int EXPORT_EXCEL = 1; public static final int EXPORT_SMP = 2; + public static final int EXPORT_JSON = 3; } diff --git a/api-admin/src/main/java/com/glxp/api/admin/controller/thrsys/ThrProductsExportLogController.java b/api-admin/src/main/java/com/glxp/api/admin/controller/thrsys/ThrProductsExportLogController.java index 21c6ba13..cde68f54 100644 --- a/api-admin/src/main/java/com/glxp/api/admin/controller/thrsys/ThrProductsExportLogController.java +++ b/api-admin/src/main/java/com/glxp/api/admin/controller/thrsys/ThrProductsExportLogController.java @@ -116,12 +116,10 @@ public class ThrProductsExportLogController { //产品信息导出生成Excel,并创建生成记录 @PostMapping("/udiwms/thrProducts/importLog/export") public BaseResponse excelDownload(@RequestBody ThrProductsExportRequest thrProductsExportRequest) { - - ThrProductsExportLogEntity thrProductsExportLogEntity = new ThrProductsExportLogEntity(); thrProductsExportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_PROCESS); String genKey = CustomUtil.getId(); - String fileName = "D:\\udiwms\\exportFile\\" + "第三方产品信息" + genKey + ".xls"; + String fileName = "D:\\udiwms\\exportFile\\" + "第三方产品信息" + genKey + ".json"; File file = new File(fileName); if (!file.exists()) { try { @@ -134,11 +132,13 @@ public class ThrProductsExportLogController { thrProductsExportLogEntity.setFilePath(fileName); thrProductsExportLogEntity.setUpdateTime(new Date()); thrProductsExportLogEntity.setDlCount(0); - thrProductsExportLogEntity.setType(BasicProcessStatus.EXPORT_EXCEL); + thrProductsExportLogEntity.setType(BasicProcessStatus.EXPORT_JSON); thrProductsExportLogService.insertThrProductsExportLog(thrProductsExportLogEntity); - thrProductsDlService.genExcel(genKey, thrProductsExportRequest); - return ResultVOUtils.success("后台正在导出生成excel文件,请稍后刷新查看!"); + //thrProductsDlService.genExcel(genKey, thrProductsExportRequest); + //修改为导出json文件 + thrProductsDlService.genJsonFile(genKey, thrProductsExportRequest); + return ResultVOUtils.success("后台正在导出生成excel文件,请稍后刷新查看!"); } diff --git a/api-admin/src/main/java/com/glxp/api/admin/dao/thrsys/ThrProductsExportLogDao.java b/api-admin/src/main/java/com/glxp/api/admin/dao/thrsys/ThrProductsExportLogDao.java index 81bf5418..90e5d508 100644 --- a/api-admin/src/main/java/com/glxp/api/admin/dao/thrsys/ThrProductsExportLogDao.java +++ b/api-admin/src/main/java/com/glxp/api/admin/dao/thrsys/ThrProductsExportLogDao.java @@ -17,4 +17,12 @@ public interface ThrProductsExportLogDao { boolean updateThrProductsExportLog(ThrProductsExportLogEntity thrProductsExportLogEntity); boolean deleteById(@Param("id") String id); + + /** + * 查询文件路径 + * + * @param id + * @return + */ + String selectFilePathById(@Param("id") String id); } diff --git a/api-admin/src/main/java/com/glxp/api/admin/service/thrsys/impl/ThrProductsExportLogServiceImpl.java b/api-admin/src/main/java/com/glxp/api/admin/service/thrsys/impl/ThrProductsExportLogServiceImpl.java index e955b446..b10c8e77 100644 --- a/api-admin/src/main/java/com/glxp/api/admin/service/thrsys/impl/ThrProductsExportLogServiceImpl.java +++ b/api-admin/src/main/java/com/glxp/api/admin/service/thrsys/impl/ThrProductsExportLogServiceImpl.java @@ -1,5 +1,7 @@ package com.glxp.api.admin.service.thrsys.impl; +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.util.StrUtil; import com.github.pagehelper.PageHelper; import com.glxp.api.admin.dao.thrsys.ThrProductsExportLogDao; import com.glxp.api.admin.entity.thrsys.ThrProductsExportLogEntity; @@ -52,6 +54,11 @@ public class ThrProductsExportLogServiceImpl implements ThrProductsExportLogServ @Override public boolean deleteById(String id) { + //删除日志同步删除文件 + String filePath = thrProductsExportLogDao.selectFilePathById(id); + if (StrUtil.isNotBlank(filePath)) { + FileUtil.del(filePath); + } return thrProductsExportLogDao.deleteById(id); } } diff --git a/api-admin/src/main/java/com/glxp/api/admin/thread/ThrProductsDlService.java b/api-admin/src/main/java/com/glxp/api/admin/thread/ThrProductsDlService.java index 70d5e7e6..4b0969e3 100644 --- a/api-admin/src/main/java/com/glxp/api/admin/thread/ThrProductsDlService.java +++ b/api-admin/src/main/java/com/glxp/api/admin/thread/ThrProductsDlService.java @@ -1,12 +1,16 @@ package com.glxp.api.admin.thread; +import cn.hutool.core.io.file.FileWriter; +import cn.hutool.json.JSONUtil; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; import com.glxp.api.admin.config.WebSocketServer; import com.glxp.api.admin.constant.BasicProcessStatus; import com.glxp.api.admin.entity.basic.BasicThirdSysDetailEntity; -import com.glxp.api.admin.entity.info.SystemParamConfigEntity; -import com.glxp.api.admin.entity.thrsys.*; +import com.glxp.api.admin.entity.thrsys.ThrProductsEntity; +import com.glxp.api.admin.entity.thrsys.ThrProductsExportLogEntity; +import com.glxp.api.admin.entity.thrsys.ThrProductsImportDetailEntity; +import com.glxp.api.admin.entity.thrsys.ThrProductsImportLogEntity; import com.glxp.api.admin.httpclient.ErpBasicClient; import com.glxp.api.admin.req.basic.FilterErpGoodsRequest; import com.glxp.api.admin.req.basic.FilterUdiIpLogRequest; @@ -422,6 +426,17 @@ public class ThrProductsDlService { return excelData; } + public List genJsonData(String id, FilterThrProductsRequest filterThrProductsRequest) { + List jsonData = new ArrayList<>(); + if (id != null) { + ThrProductsEntity thrProductsEntity = thrProductsService.selectById(id); + jsonData.add(thrProductsEntity); + } else { + jsonData = thrProductsService.filterThrProductsRequest(filterThrProductsRequest); + } + return jsonData; + } + public List> getRows(List thrProductsEntities) { List> excelData = new ArrayList<>(); for (ThrProductsEntity thrProductsEntity : thrProductsEntities) { @@ -437,4 +452,52 @@ public class ThrProductsDlService { } return excelData; } + + + //导出json文件 + @Async + public void genJsonFile(String genKey, ThrProductsExportRequest thrProductsExportRequest) { + + ThrProductsExportLogEntity thrProductsExportLogEntity = thrProductsExportLogService.selectByGenKey(genKey); + + List exportData = new ArrayList<>(); + //选中导出 + if (thrProductsExportRequest.getThrProductsEntities() != null && thrProductsExportRequest.getThrProductsEntities().size() > 0) { + List thrProductsEntities = thrProductsExportRequest.getThrProductsEntities(); + exportData.addAll(thrProductsEntities); + } else {//一键导出 + + BasicThirdSysDetailEntity basicThirdSysDetailEntity = basicThirdSysDetailService.selectByKey("piQueryUrl", thrProductsExportRequest.getThirdSys()); + if (basicThirdSysDetailEntity == null || basicThirdSysDetailEntity.getValue() == null) { + thrProductsExportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_FAIL); + thrProductsExportLogEntity.setRemark("产品信息接口未定义!"); + thrProductsExportLogService.updateThrProductsExportLog(thrProductsExportLogEntity); + return; + } + + if (!basicThirdSysDetailEntity.getEnabled()) { + thrProductsExportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_FAIL); + thrProductsExportLogEntity.setRemark("第三方产品信息服务未启用!"); + thrProductsExportLogService.updateThrProductsExportLog(thrProductsExportLogEntity); + return; + } + + if (basicThirdSysDetailEntity.getFromType() == 0) { + FilterThrProductsRequest filterThrProductsRequest = new FilterThrProductsRequest(); + BeanUtils.copyProperties(thrProductsExportRequest, filterThrProductsRequest); + List thrProductsEntities = exportThrProducts(filterThrProductsRequest); + exportData.addAll(thrProductsEntities); + + } else { + FilterThrProductsRequest filterThrInvProductsRequest = new FilterThrProductsRequest(); + BeanUtils.copyProperties(thrProductsExportRequest, filterThrInvProductsRequest); + List jsonData = genJsonData(null, filterThrInvProductsRequest); + exportData.addAll(jsonData); + } + } + FileWriter writer = new FileWriter(thrProductsExportLogEntity.getFilePath()); + writer.write(JSONUtil.toJsonStr(exportData)); + thrProductsExportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_SUCCESS); + thrProductsExportLogService.updateThrProductsExportLog(thrProductsExportLogEntity); + } } diff --git a/api-admin/src/main/resources/mybatis/mapper/thrsys/ThrProductsExportLogDao.xml b/api-admin/src/main/resources/mybatis/mapper/thrsys/ThrProductsExportLogDao.xml index c9a8fa7f..2213c2e0 100644 --- a/api-admin/src/main/resources/mybatis/mapper/thrsys/ThrProductsExportLogDao.xml +++ b/api-admin/src/main/resources/mybatis/mapper/thrsys/ThrProductsExportLogDao.xml @@ -19,6 +19,9 @@ ORDER BY updateTime DESC +