|
@@ -1,5 +1,6 @@
|
|
|
package com.qmth.themis.backend.api;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.qmth.themis.backend.config.DictionaryConfig;
|
|
|
import com.qmth.themis.backend.constant.BackendConstant;
|
|
@@ -7,10 +8,13 @@ import com.qmth.themis.backend.util.ServletUtil;
|
|
|
import com.qmth.themis.business.constant.SystemConstant;
|
|
|
import com.qmth.themis.business.entity.TBAttachment;
|
|
|
import com.qmth.themis.business.entity.TBPrivilege;
|
|
|
+import com.qmth.themis.business.entity.TBTaskHistory;
|
|
|
import com.qmth.themis.business.entity.TBUser;
|
|
|
+import com.qmth.themis.business.enums.DownloadFileEnum;
|
|
|
import com.qmth.themis.business.enums.RoleEnum;
|
|
|
import com.qmth.themis.business.service.TBAttachmentService;
|
|
|
import com.qmth.themis.business.service.TBPrivilegeService;
|
|
|
+import com.qmth.themis.business.service.TBTaskHistoryService;
|
|
|
import com.qmth.themis.common.enums.ExceptionResultEnum;
|
|
|
import com.qmth.themis.common.exception.BusinessException;
|
|
|
import com.qmth.themis.common.util.Result;
|
|
@@ -24,6 +28,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
@@ -48,6 +53,9 @@ public class SysController {
|
|
|
@Resource
|
|
|
TBAttachmentService tbAttachmentService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ TBTaskHistoryService tbTaskHistoryService;
|
|
|
+
|
|
|
@Resource
|
|
|
DictionaryConfig dictionaryConfig;
|
|
|
|
|
@@ -106,4 +114,49 @@ public class SysController {
|
|
|
map.put(SystemConstant.TYPE, tbAttachment.getType());
|
|
|
return ResultUtil.ok(map);
|
|
|
}
|
|
|
+
|
|
|
+ @ApiOperation(value = "文件下载接口")
|
|
|
+ @RequestMapping(value = "/file/download", method = RequestMethod.GET)
|
|
|
+ @ApiResponses({@ApiResponse(code = 200, message = "{\"url\":string}", response = Result.class)})
|
|
|
+ public Result fileDownload(@ApiParam(value = "任务id", required = true) @RequestParam Long id, @ApiParam(value = "下载文件类型", required = true) @RequestParam Integer type) {
|
|
|
+ if (Objects.isNull(id) || Objects.equals(id, "")) {
|
|
|
+ throw new BusinessException(ExceptionResultEnum.TASK_ID_IS_NULL);
|
|
|
+ }
|
|
|
+ if (Objects.isNull(type) || Objects.equals(type, "")) {
|
|
|
+ throw new BusinessException(ExceptionResultEnum.DOWNLOAD_FILE_TYPE_IS_NULL);
|
|
|
+ }
|
|
|
+ if (Objects.isNull(DownloadFileEnum.convertToName(type))) {
|
|
|
+ throw new BusinessException(ExceptionResultEnum.DOWNLOAD_FILE_TYPE_ERROR);
|
|
|
+ }
|
|
|
+ TBTaskHistory tbTaskHistory = tbTaskHistoryService.getById(id);
|
|
|
+ if (Objects.isNull(tbTaskHistory)) {
|
|
|
+ throw new BusinessException(ExceptionResultEnum.TASK_NO);
|
|
|
+ }
|
|
|
+ boolean oss = dictionaryConfig.sysDomain().isOss();
|
|
|
+ JSONObject jsonObject = null;
|
|
|
+ switch (type) {
|
|
|
+ case 0:
|
|
|
+ jsonObject = JSONObject.parseObject(tbTaskHistory.getImportFilePath());
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ jsonObject = JSONObject.parseObject(tbTaskHistory.getErrorFilePath());
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ jsonObject = JSONObject.parseObject(tbTaskHistory.getResultFilePath());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (Objects.isNull(jsonObject) || Objects.isNull(jsonObject.get("path"))) {
|
|
|
+ throw new BusinessException("下载文件地址不存在");
|
|
|
+ }
|
|
|
+ String filePath = String.valueOf(jsonObject.get("path"));
|
|
|
+ String url = null;
|
|
|
+ if (oss) {
|
|
|
+ url = dictionaryConfig.aliYunOssDomain().getUrl() + File.separator + filePath;
|
|
|
+ } else {
|
|
|
+ url = "http://" + dictionaryConfig.sysDomain().getFileHost() + File.separator + filePath;
|
|
|
+ }
|
|
|
+ Map map = new HashMap();
|
|
|
+ map.put("url", url);
|
|
|
+ return ResultUtil.ok(map);
|
|
|
+ }
|
|
|
}
|