当前位置:网站首页>[microservice openfeign] use openfeign to remotely call the file upload interface
[microservice openfeign] use openfeign to remotely call the file upload interface
2022-07-04 04:18:00 【Bulst】
List of articles
Service providers - File upload interface
@PostMapping("/saveFile")
@Transactional
@ApiOperation(value = " file save ", response = ResponseEntity.class)
@ApiImplicitParams(
{
@ApiImplicitParam(name = "fileUploadModel", value = " File upload information ",
required = true, dataType = "String", paramType = "query"),
@ApiImplicitParam(name = "uploadFiles", value = " File stream ",
required = true, allowMultiple = true, dataType = "__file", paramType = "query")
})
public ResponseEntity<Object> saveFile(@RequestParam(value = "fileUploadModel", required = false) String fileUploadModel,
@RequestParam(value = "uploadFiles", required = false) List<MultipartFile> uploadFiles) {
FileUploadModel model = JSON.parseObject(fileUploadModel, FileUploadModel.class);
// JSON.toJSONString()
// The attachment
List<OfficeAttach> uploadFileList = new ArrayList<>();
if (uploadFiles != null && uploadFiles.size() > 0) {
uploadFileList = addFileInfoDto(uploadFiles, model);
// this.fileService.saveOfficeAttachList(uploadFileList);
fileService.saveBatch(uploadFileList);
}
return ResponseEntity.ok(" File upload succeeded ");
}
FeignClient
@FeignClient(name = "${custom.feign.file.name}", url = "${custom.feign.file.url}", fallback = FileFeignClientFallBack.class, configuration = FileFeignClient.MultipartSupportConfig.class)
public interface FileFeignClient {
@RequestMapping(value = "/upload/saveFile", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<Object> fileUpload(@RequestParam(value = "fileUploadModel", required = false) String fileUploadModel,
@RequestPart(value = "uploadFiles", required = false) List<MultipartFile> uploadFiles);
consumer - adopt FeignClient Call file upload interface
/** * @Description: 1、 Call the asset service to insert the application asset information * 2、 Insert the request information to itsm_request_info surface , The status is directly written as IT Waiting list * 3、 Call the file service to upload files * @Param: * @return: * @Author: Brest * @Date: 2022/7/3 */
@PostMapping("/commitRequest")
@Idempotent
@GlobalTransactional
@ApiOperation(value = " Request Submission ", response = ResultModel.class)
@ApiImplicitParams(
{
@ApiImplicitParam(name = "requestInfo", value = " Demand application information ",
required = true, dataType = "String", paramType = "query"),
@ApiImplicitParam(name = "assetModelList", value = " Asset application information ",
required = true, dataType = "String", paramType = "query"),
@ApiImplicitParam(name = "uploadFiles", value = " Upload file information ",
required = true, allowMultiple = true, dataType = "__file", paramType = "query")
})
public ResultModel commitRequest(@RequestParam(value = "requestInfo", required = false) String requestInfoModel,
@RequestParam(value = "assetModelList", required = false) String assetRequestModel,
@RequestParam(value = "uploadFiles", required = false) List<MultipartFile> uploadFiles,
HttpServletRequest request) {
RequestInfo requestInfo = JSON.parseObject(requestInfoModel, RequestInfo.class);
List<AssetRequestModel> applyModelList = JSON.parseArray(assetRequestModel, AssetRequestModel.class);
String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
String userId = request.getHeader("userId");
//issuId
String issueId = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
//path
// Call the asset service to insert the application asset information
FileUploadModel uploadModel = new FileUploadModel();
uploadModel.setUploadPath("/request/");
uploadModel.setAttachType(" Demand application ");
uploadModel.setCreateId(request.getHeader("userId"));
uploadModel.setIssueId(issueId);
uploadModel.setRemark(requestInfo.getIssueContent());
uploadModel.setObjectType("office End ");
uploadModel.setRoleId("role-office");
uploadModel.setRoleType("role-type");
for (AssetRequestModel requestModel : applyModelList) {
requestModel.setIssueId(issueId).setOperateType("2").setCreateId(request.getHeader("userId"));
}
assetFeignClient.saveApply(applyModelList);
// Save the request information
requestInfo.setIssueId(issueId);
requestInfo.setGuid(UUID.randomUUID().toString());
requestInfo.setDelFlag("N");
requestInfo.setStatus("IT Waiting list ");
requestInfo.setCreateTime(time);
requestInfo.setUpdateTime(time);
requestInfo.setCreateId(userId);
requestInfo.setUpdateId(userId);
requestService.save(requestInfo);
// Call the file service to upload files
String fileUploadModel = JSON.toJSONString(uploadModel);
feignClient.fileUpload(fileUploadModel, uploadFiles);
return ResultModel.ok(" Submit successfully ");
}
边栏推荐
- 量子力学习题
- leetcode刷题:二叉树07(二叉树的最大深度)
- 【罗技】m720
- Idea modify body color
- 2022-07-03: there are 0 and 1 in the array. Be sure to flip an interval. Flip: 0 becomes 1, 1 becomes 0. What is the maximum number of 1 after turning? From little red book. 3.13 written examination.
- ctf-pikachu-XSS
- Rhcsa-- day one
- The maximum expiration time of client secret in azure ad application registration is modified to 2 years
- pytest多进程/多线程执行测试用例
- 【读书会第十三期】多媒体处理工具 FFmpeg 工具集
猜你喜欢

AAAI2022 | Word Embeddings via Causal Inference: Gender Bias Reducing and Semantic Information Preserving

干货!基于GAN的稀有样本生成

Getting started with the go language is simple: go implements the Caesar password

pytest多进程/多线程执行测试用例

如何远程办公更有效率 | 社区征文

02 specific implementation of LS command

leetcode刷题:二叉树07(二叉树的最大深度)

深度优先搜索简要讲解(附带基础题)

Illustrated network: what is the hot backup router protocol HSRP?

图解网络:什么是热备份路由器协议HSRP?
随机推荐
2020 Bioinformatics | TransformerCPI
华为云鲲鹏工程师培训(广西大学)
毕业设计:设计秒杀电商系统
图解网络:什么是热备份路由器协议HSRP?
CesiumJS 2022^ 源码解读[0] - 文章目录与源码工程结构
Objective C attribute keyword
Objective-C description method and type method
用于TCP协议交互的TCPClientDemo
Introduction to asynchronous task capability of function calculation - task trigger de duplication
支持首次触发的 Go Ticker
Getting started with the go language is simple: go implements the Caesar password
[Huawei cloud IOT] reading notes, "Internet of things: core technology and security of the Internet of things", Chapter 3 (I)
Small record of thinking
Programmers' telecommuting is mixed | community essay solicitation
[paddleseg source code reading] normalize operation of paddleseg transform
线程常用的方法
Pointer array and array pointer
【罗技】m720
智慧地铁| 云计算为城市地铁交通注入智慧
Balance between picture performance of unity mobile game performance optimization spectrum and GPU pressure