From bffb2468c7ca87ad5ce78208be319b276d27fa1b Mon Sep 17 00:00:00 2001 From: wj <1285151836@qq.com> Date: Thu, 27 Apr 2023 10:11:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=95=B0=E6=8D=AE=E5=86=99?= =?UTF-8?q?=E5=85=A5=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sync/SpsSyncDownloadController.java | 32 +++++++++++++++++-- .../sync/BasicDownloadStatusEntity.java | 5 +++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/glxp/api/controller/sync/SpsSyncDownloadController.java b/src/main/java/com/glxp/api/controller/sync/SpsSyncDownloadController.java index dc5cde69..b90b85b0 100644 --- a/src/main/java/com/glxp/api/controller/sync/SpsSyncDownloadController.java +++ b/src/main/java/com/glxp/api/controller/sync/SpsSyncDownloadController.java @@ -3,6 +3,7 @@ package com.glxp.api.controller.sync; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.lang.Dict; +import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; @@ -43,6 +44,7 @@ import com.glxp.api.service.sync.BasicDownloadService; import com.glxp.api.service.sync.BasicExportService; import com.glxp.api.service.sync.SpsSyncDownloadService; import com.glxp.api.util.CustomUtil; +import com.glxp.api.util.DateUtil; import com.glxp.api.util.JsonUtils; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -52,6 +54,7 @@ import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.TransactionIsolationLevel; import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Value; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -60,9 +63,7 @@ import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import javax.validation.Valid; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; +import java.io.*; import java.util.Date; import java.util.List; @@ -323,6 +324,8 @@ public class SpsSyncDownloadController { return baseResponse; } + @Value("${file_path}") + private String filePrefix; @ApiOperation("上传同步数据") @PostMapping("sps/sync/upload/data") @@ -363,6 +366,8 @@ public class SpsSyncDownloadController { .idDatas(upLoadRequest.getExportType().getKey()) .scheduleType(1) .build(); + String fileFullPath = writeFile(filePrefix, upLoadRequest.getExportType().getRemark(), JSONUtil.toJsonStr(upLoadRequest.getData())); + downloadStatus.setCacheFilePath(fileFullPath); basicDownloadService.insertDownloadStatus(downloadStatus); return ResultVOUtils.success(); } catch (Exception e) { @@ -372,6 +377,27 @@ public class SpsSyncDownloadController { } + + private String writeFile(String filePath, String fileDesc, String content) throws IOException { + filePath = String.format("%s/%s", filePath, DateUtil.getDate()); + String fileFullPath = String.format("%s/%s-%s.udi", filePath, fileDesc, IdUtil.fastSimpleUUID()); + File file = new File(filePath); + if (!file.exists()) { + file.mkdirs(); + } + file = new File(fileFullPath); + while (!file.createNewFile()) { + fileFullPath = String.format("%s/%s/%s-%s.udi", filePath, DateUtil.getDate(), fileDesc, IdUtil.fastSimpleUUID()); + file = new File(fileFullPath); + } + + FileWriter fileWriter = new FileWriter(file); + fileWriter.write(content); + fileWriter.flush(); + fileWriter.close(); + return fileFullPath; + } + private final SystemParamConfigDao systemParamConfigDao; private final EntrustReceDao entrustReceDao; private final SystemPDFModuleDao systemPDFModuleDao; diff --git a/src/main/java/com/glxp/api/entity/sync/BasicDownloadStatusEntity.java b/src/main/java/com/glxp/api/entity/sync/BasicDownloadStatusEntity.java index d0f4a6f1..688a7830 100644 --- a/src/main/java/com/glxp/api/entity/sync/BasicDownloadStatusEntity.java +++ b/src/main/java/com/glxp/api/entity/sync/BasicDownloadStatusEntity.java @@ -1,5 +1,7 @@ package com.glxp.api.entity.sync; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -11,6 +13,7 @@ import java.util.Date; @AllArgsConstructor @NoArgsConstructor @Builder +@TableName("basic_download_status") public class BasicDownloadStatusEntity { /** @@ -30,4 +33,6 @@ public class BasicDownloadStatusEntity { private Date startTime; private Date endTime; private String remark; + @TableField(value = "cacheFilePath") + private String cacheFilePath; }