feat: 测试接入wps
parent
d0b198130c
commit
7fc856529c
|
|
@ -1,14 +1,21 @@
|
|||
package org.qinan.safetyeval.adapter.web;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.x.file.storage.core.FileInfo;
|
||||
import org.dromara.x.file.storage.core.FileStorageService;
|
||||
import org.qinan.safetyeval.infrastructure.mapper.AccountMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 对外开放接口(免鉴权)。
|
||||
|
|
@ -19,26 +26,74 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
@Api(tags = "对外开放接口")
|
||||
@RestController
|
||||
@RequestMapping("/safetyEval-h5/wsp")
|
||||
@Slf4j
|
||||
public class H5OpenController {
|
||||
|
||||
@Autowired
|
||||
private AccountMapper accountMapper;
|
||||
@Autowired
|
||||
private FileStorageService fileStorageService;
|
||||
|
||||
@ApiOperation("wps回调预览")
|
||||
@GetMapping(value = "/v3/3rd/files/{file_id}", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public String getWpsInfoByFileId(@PathVariable("file_id") String fileId) {
|
||||
public String getWpsInfoByFileId(@PathVariable("file_id") String file_id) {
|
||||
log.info("wps回调预览:{}", file_id);
|
||||
return accountMapper.getWps(1);
|
||||
}
|
||||
|
||||
@ApiOperation("wps回调下载")
|
||||
@GetMapping(value = "/v3/3rd/files/{file_id}/download", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public String getWpsDownloadByFileId(@PathVariable("file_id") String fileId) {
|
||||
public String getWpsDownloadByFileId(@PathVariable("file_id") String file_id) {
|
||||
log.info("wps回调下载:{}", file_id);
|
||||
return accountMapper.getWps(2);
|
||||
}
|
||||
|
||||
@ApiOperation("wps回调用户信息")
|
||||
@ApiOperation("wps回调权限信息")
|
||||
@GetMapping(value = "/v3/3rd/files/{file_id}/permission", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public String getWpsPermissionByFileId(@PathVariable("file_id") String fileId) {
|
||||
public String getWpsPermissionByFileId(@PathVariable("file_id") String file_id) {
|
||||
log.info("wps回调权限信息:{}", file_id);
|
||||
return accountMapper.getWps(3);
|
||||
}
|
||||
|
||||
@ApiOperation("wps回调用户信息")
|
||||
@GetMapping(value = "/v3/3rd/users", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public String getWpsUsers(@RequestParam List<Long> user_ids) {
|
||||
log.info("wps回调用户信息:{}", user_ids);
|
||||
return accountMapper.getWps(4);
|
||||
}
|
||||
|
||||
@ApiOperation("wps回调上传第一步")
|
||||
@GetMapping(value = "/v3/3rd/files/{file_id}/upload/prepare", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public String getWpsUpLoadOne(@PathVariable("file_id") String file_id) {
|
||||
log.info("wps回调上传第一步:{}", file_id);
|
||||
return accountMapper.getWps(5);
|
||||
}
|
||||
|
||||
@ApiOperation("wps回调上传第二步")
|
||||
@PostMapping(value = "/v3/3rd/files/{file_id}/upload/address")
|
||||
public String getWpsUpLoadTwo(@PathVariable("file_id") String file_id, @RequestBody Map<String, Object> map) {
|
||||
log.info("wps回调上传第二步:{}, map: {}", file_id, JSON.toJSONString(map));
|
||||
return accountMapper.getWps(6);
|
||||
}
|
||||
|
||||
@ApiOperation("wps回调上传第三步")
|
||||
@PostMapping(value = "/v3/3rd/files/{file_id}/upload/complete")
|
||||
public String getWpsUpLoadThree(@PathVariable("file_id") String file_id, @RequestBody Map<String, Object> map) {
|
||||
String jsonString = JSON.toJSONString(map);
|
||||
log.info("wps回调上传第二步:{}, map: {}", file_id, jsonString);
|
||||
return jsonString;
|
||||
}
|
||||
|
||||
@PostMapping(value = "/upload/{file_id}", consumes = "application/octet-stream")
|
||||
public String uploadFile(@PathVariable("file_id") String file_id, HttpServletRequest request) throws IOException {
|
||||
// 获取文件的二进制流
|
||||
try (InputStream inputStream = request.getInputStream()) {
|
||||
FileInfo upload = fileStorageService.of(inputStream, file_id).upload();
|
||||
log.info("上传文件成功:{}", JSON.toJSONString(upload));
|
||||
return "ok";
|
||||
} catch (Exception e) {
|
||||
log.error("上传文件失败:{}", e.getMessage());
|
||||
return "上传文件失败";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue