瀏覽代碼

维多利亚

home 2 年之前
父節點
當前提交
1aeb9b35e1

+ 10 - 0
hx-common/service-file/src/main/java/com/fjhx/feign/FileClient.java

@@ -4,8 +4,12 @@ import com.fjhx.entity.FileInfo;
 import com.fjhx.service.FileInfoService;
 import org.springblade.core.tool.api.R;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.MediaType;
 import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RequestPart;
 import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.util.List;
 
@@ -43,4 +47,10 @@ public class FileClient implements IFileClient {
         return R.success(list);
     }
 
+    @PostMapping(value = UPLOAD_FILE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
+    public R<FileInfo> uploadFile(@RequestPart("file") MultipartFile file) {
+        FileInfo result = fileInfoService.uploadFile(file);
+        return R.success(result);
+    }
+
 }

+ 8 - 1
hx-service-api/service-file-api/src/main/java/com/fjhx/feign/IFileClient.java

@@ -2,12 +2,14 @@ package com.fjhx.feign;
 
 import com.fjhx.constants.ClientConstant;
 import com.fjhx.entity.FileInfo;
-import com.fjhx.params.FileInfoParam;
 import org.springblade.core.tool.api.R;
 import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.http.MediaType;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RequestPart;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.util.List;
 
@@ -25,6 +27,8 @@ public interface IFileClient {
 
     String GET_FILE_INFO = ClientConstant.API_PREFIX + "/getFileInfo";
 
+    String UPLOAD_FILE = ClientConstant.API_PREFIX + "/uploadFile";
+
     /**
      * 文件绑定业务id
      *
@@ -67,4 +71,7 @@ public interface IFileClient {
     @PostMapping(GET_FILE_INFO)
     R<List<FileInfo>> getFileInfo(@RequestBody List<Long> businessIdList);
 
+    @PostMapping(value = UPLOAD_FILE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
+    R<FileInfo> uploadFile(@RequestPart("file") MultipartFile file);
+
 }

+ 9 - 4
hx-service-api/victoriatourist-api/src/main/java/com/fjhx/entity/excel/ExcelImportLog.java

@@ -32,17 +32,22 @@ public class ExcelImportLog extends BaseEntity {
     /**
      * 文件名
      */
+    private Long fileId;
+
+    /**
+     * 文件名
+     */
     private String fileName;
 
     /**
-     * 执行时间(秒)
+     * 文件路径
      */
-    private Long executeTime;
+    private String filePath;
 
     /**
-     * 源文件
+     * 执行时间(秒)
      */
-    private byte[] sourceFile;
+    private Long executeTime;
 
     /**
      * 逻辑删除 0未删除 1已删除

+ 9 - 0
hx-service/victoriatourist/src/main/java/com/fjhx/controller/excel/ExcelImportLogController.java

@@ -1,6 +1,9 @@
 package com.fjhx.controller.excel;
 
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fjhx.base.Condition;
+import com.fjhx.entity.excel.ExcelImportLog;
 import com.fjhx.params.excel.ExcelProcessingProgress;
 import com.fjhx.service.excel.ExcelImportLogService;
 import org.springblade.core.tool.api.R;
@@ -25,6 +28,12 @@ public class ExcelImportLogController {
     @Autowired
     private ExcelImportLogService excelImportLogService;
 
+    @PostMapping("page")
+    public R page(@RequestBody Condition condition) {
+        Page<ExcelImportLog> result = excelImportLogService.getPage(condition);
+        return R.data(result);
+    }
+
     @PostMapping("readRate")
     public R readRate(@RequestBody JSONObject json) {
         ExcelProcessingProgress readRate = excelImportLogService.getReadRate(json.getLong("flag"));

+ 4 - 0
hx-service/victoriatourist/src/main/java/com/fjhx/service/excel/ExcelImportLogService.java

@@ -1,6 +1,8 @@
 package com.fjhx.service.excel;
 
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.fjhx.base.BaseService;
+import com.fjhx.base.Condition;
 import com.fjhx.entity.excel.ExcelImportLog;
 import com.fjhx.params.excel.BaseExcelVo;
 import com.fjhx.params.excel.ExcelProcessingProgress;
@@ -66,4 +68,6 @@ public interface ExcelImportLogService extends BaseService<ExcelImportLog> {
      */
     void editLog(Long start, Long flag, Integer status);
 
+    Page<ExcelImportLog> getPage(Condition condition);
+
 }

+ 27 - 1
hx-service/victoriatourist/src/main/java/com/fjhx/service/excel/impl/ExcelImportLogServiceImpl.java

@@ -3,19 +3,26 @@ package com.fjhx.service.excel.impl;
 import cn.hutool.core.io.IoUtil;
 import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.excel.EasyExcel;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fjhx.base.BaseEntity;
+import com.fjhx.base.Condition;
 import com.fjhx.config.TaskPoolConfig;
 import com.fjhx.constants.VRedisKeyConstant;
+import com.fjhx.entity.FileInfo;
 import com.fjhx.entity.excel.ExcelImportLog;
+import com.fjhx.feign.IFileClient;
 import com.fjhx.listener.EasyExcelListener;
 import com.fjhx.mapper.excel.ExcelImportLogMapper;
 import com.fjhx.params.excel.BaseExcelVo;
 import com.fjhx.params.excel.ExcelProcessingProgress;
 import com.fjhx.service.excel.ExcelImportLogService;
+import com.fjhx.utils.Assert;
+import com.fjhx.utils.wrapperUtil.IWrapper;
 import org.springblade.core.excel.support.ExcelException;
 import org.springblade.core.redis.cache.BladeRedis;
 import org.springblade.core.secure.utils.AuthUtil;
+import org.springblade.core.tool.api.R;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
@@ -50,6 +57,9 @@ public class ExcelImportLogServiceImpl extends ServiceImpl<ExcelImportLogMapper,
     @Resource
     private BladeRedis bladeRedis;
 
+    @Autowired
+    private IFileClient fileClient;
+
     @Override
     public <T extends BaseExcelVo> void asyncRead(int pageSize, Long flag, MultipartFile file, Class<T> cls, Integer businessType,
                                                   Consumer<List<T>> handleFun, Runnable errorFun) {
@@ -158,12 +168,18 @@ public class ExcelImportLogServiceImpl extends ServiceImpl<ExcelImportLogMapper,
 
     @Override
     public void saveLog(Long flag, Integer businessType, MultipartFile file) {
+
+        R<FileInfo> fileInfoR = fileClient.uploadFile(file);
+        FileInfo result = Assert.result(fileInfoR);
+
         // 上传记录记录数据库
         ExcelImportLog excelImportLog = new ExcelImportLog();
         excelImportLog.setId(flag);
         excelImportLog.setBusinessType(businessType);
         excelImportLog.setStatus(1);
-        excelImportLog.setFileName(file.getOriginalFilename());
+        excelImportLog.setFileId(result.getId());
+        excelImportLog.setFileName(result.getFileName());
+        excelImportLog.setFilePath(result.getFilePath());
         excelImportLog.setCreateTime(new Date());
         excelImportLog.setCreateUser(AuthUtil.getUserId());
         save(excelImportLog);
@@ -187,6 +203,16 @@ public class ExcelImportLogServiceImpl extends ServiceImpl<ExcelImportLogMapper,
         );
     }
 
+    @Override
+    public Page<ExcelImportLog> getPage(Condition condition) {
+        IWrapper<ExcelImportLog> wrapper = IWrapper.getWrapper(condition);
+        wrapper.eq(ExcelImportLog::getBusinessType);
+        wrapper.periodTime(ExcelImportLog::getCreateTime);
+        wrapper.orderByDesc(ExcelImportLog::getId);
+
+        return page(condition.getPage(), wrapper);
+    }
+
     /**
      * 插入缓存信息
      *

+ 1 - 1
hx-service/victoriatourist/src/main/java/com/fjhx/service/order/impl/OrderJdServiceImpl.java

@@ -124,6 +124,7 @@ public class OrderJdServiceImpl extends ServiceImpl<OrderJdMapper, OrderJd> impl
         removeById(orderJdVo.getId());
     }
 
+    @Transactional(rollbackFor = Exception.class)
     @Override
     public Long excelImport(MultipartFile file) {
 
@@ -216,7 +217,6 @@ public class OrderJdServiceImpl extends ServiceImpl<OrderJdMapper, OrderJd> impl
             existCodeList.forEach(joiner::add);
 
             // 保存导入记录
-//            excelImportLogService.editLog(start, flag, 2);
             throw new ServiceException("存在相同的采购单号:" + joiner);
         }
     }