当前位置:网站首页>[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 ");
}
边栏推荐
- VIM mapping command
- Katalon中控件的参数化
- leetcode刷题:二叉树09(二叉树的最小深度)
- 【愚公系列】2022年7月 Go教学课程 002-Go语言环境安装
- The new data center helps speed up the construction of a digital economy with data as a key element
- 拼夕夕二面:说说布隆过滤器与布谷鸟过滤器?应用场景?我懵了。。
- Objective-C description method and type method
- Pointer array and array pointer
- Two commonly used graphics can easily realize data display
- 深度优先搜索简要讲解(附带基础题)
猜你喜欢
2020 Bioinformatics | TransformerCPI
AAAI2022 | Word Embeddings via Causal Inference: Gender Bias Reducing and Semantic Information Preserving
Idea modify body color
指针数组和数组指针
Msgraphmailbag - search only driveitems of file types
CesiumJS 2022^ 源码解读[0] - 文章目录与源码工程结构
Infiltration practice guest account mimikatz sunflower SQL rights lifting offline decryption
SQL語句加强練習(MySQL8.0為例)
软件测试是干什么的 发现缺陷错误,提高软件的质量
There is a problem that the package cannot be parsed in the like project
随机推荐
'2'&gt;' 10'==true? How does JS perform implicit type conversion?
[csrf-01] basic principle and attack and defense of Cross Site Request Forgery vulnerability
SQL語句加强練習(MySQL8.0為例)
laravel admin里百度编辑器自定义路径和文件名
01 QEMU starts the compiled image vfs: unable to mount root FS on unknown block (0,0)
Redis cluster uses Lua script. Lua script can also be used for different slots
[paddleseg source code reading] paddleseg custom data class
STM32 external DHT11 display temperature and humidity
Getting started with the go language is simple: go implements the Caesar password
Exercices de renforcement des déclarations SQL (MySQL 8.0 par exemple)
Parameterization of controls in katalon
02 specific implementation of LS command
How was my life in 2021
Reduce function under functools
Spa in SDP
Katalon中控件的参数化
Simple dialogue system -- text classification using transformer
Select sorting and bubble sorting template
华为云鲲鹏工程师培训(广西大学)
Objective-C member variable permissions