Browse Source

增加文件管理

tags/24080901
WendyYang 1 year ago
parent
commit
1923e50a73
3 changed files with 127 additions and 5 deletions
  1. +36
    -5
      hz-pm-api/src/main/java/com/hz/pm/api/external/MhFileClient.java
  2. +43
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/external/controller/MhFileController.java
  3. +48
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/external/model/dto/MhFileInfoDTO.java

+ 36
- 5
hz-pm-api/src/main/java/com/hz/pm/api/external/MhFileClient.java View File

@@ -1,10 +1,21 @@
package com.hz.pm.api.external;

import cn.hutool.core.lang.TypeReference;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.hz.pm.api.external.model.dto.MhFileInfoDTO;
import com.hz.pm.api.external.model.dto.MhRetDTO;
import com.ningdatech.basic.exception.BizException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Collection;
import java.util.List;

/**
* <p>
@@ -14,20 +25,40 @@ import java.util.Collection;
* @author WendyYang
* @since 20:24 2023/12/28
*/
@Slf4j
@Component
@RequiredArgsConstructor
public class MhFileClient {

private static final int TIMEOUT_MILLS = 5000;

@Value("${mh.file-down-url:}")
@Value("${mh.file.down-url:}")
private String fileDownUrl;
@Value("${mh.file-detail-url:}")
private String fileDetailUrl;


public void getFileDetail(Collection<String> fileIds) {
@Value("${mh.file.detail-url:}")
private String fileDetailUrl;

public void download(String fileId, HttpServletResponse response) {
String fileUrl = fileDownUrl + fileId;
try (ServletOutputStream stream = response.getOutputStream()) {
long size = HttpUtil.download(fileUrl, stream, true);
log.info("下载文件:{},大小为:{}", fileId, size);
} catch (IOException e) {
log.error("信创平台文件下载异常:{}", fileId, e);
throw BizException.wrap("下载文件失败");
}
}

public List<MhFileInfoDTO> listFileInfo(String fileIds) {
String url = fileDetailUrl + "?ids=" + fileIds;
String body = HttpUtil.get(url, TIMEOUT_MILLS);
MhRetDTO<List<MhFileInfoDTO>> ret = JSONUtil.toBean(body,
new TypeReference<MhRetDTO<List<MhFileInfoDTO>>>() {
}, false);
if (ret.isOk()) {
return ret.getData();
}
throw BizException.wrap("获取文件详情");
}

}

+ 43
- 0
hz-pm-api/src/main/java/com/hz/pm/api/external/controller/MhFileController.java View File

@@ -0,0 +1,43 @@
package com.hz.pm.api.external.controller;

import com.hz.pm.api.external.MhFileClient;
import com.hz.pm.api.external.model.dto.MhFileInfoDTO;
import com.ningdatech.log.annotation.WebLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
* <p>
* MhFileController
* </p>
*
* @author WendyYang
* @since 09:47 2023/12/29
*/
@Api("信创平台文件管理")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/mh/file")
public class MhFileController {

private final MhFileClient mhFileClient;

@GetMapping("/download/{fileId}")
@WebLog("下载信创平台文件")
@ApiOperation("下载信创平台文件")
public void download(@PathVariable String fileId, HttpServletResponse response) {
mhFileClient.download(fileId, response);
}

@GetMapping("/listFileInfo")
@ApiOperation("获取文件详情")
public List<MhFileInfoDTO> listFileInfo(@RequestParam String fileIds) {
return mhFileClient.listFileInfo(fileIds);
}

}

+ 48
- 0
hz-pm-api/src/main/java/com/hz/pm/api/external/model/dto/MhFileInfoDTO.java View File

@@ -0,0 +1,48 @@
package com.hz.pm.api.external.model.dto;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.time.LocalDateTime;

/**
* <p>
* MhFileInfoDTO
* </p>
*
* @author WendyYang
* @since 09:32 2023/12/29
*/
@Data
public class MhFileInfoDTO {

@ApiModelProperty("文件ID")
private String fileId;

@ApiModelProperty("文件bucket")
private String fileBucket;

@ApiModelProperty("文件路径")
private String filePath;

@ApiModelProperty("文件名")
private String fileName;

@ApiModelProperty("文件后缀")
private String fileSuffix;

@ApiModelProperty("文件大小")
private Integer byteSize;

private String createBy;

private LocalDateTime createTime;

@ApiModelProperty("文件完整路径")
private String wholeFilePath;

@ApiModelProperty("文件类型")
private String fileTypeEnum;


}

Loading…
Cancel
Save