当前位置:网站首页>[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 ");
}
边栏推荐
- [paddleseg source code reading] paddleseg calculates Miou
- 还原窗口位置的微妙之处
- [paddleseg source code reading] paddleseg custom data class
- 用于TCP协议交互的TCPClientDemo
- MySQL maxscale realizes read-write separation
- 支持首次触发的 Go Ticker
- [Yugong series] go teaching course 002 go language environment installation in July 2022
- Mitsubishi M70 macro variable reading Mitsubishi M80 public variable acquisition Mitsubishi CNC variable reading acquisition Mitsubishi CNC remote tool compensation Mitsubishi machine tool online tool
- How to dynamically cache components in Vue multi-level route nesting
- 【读书会第十三期】多媒体处理工具 FFmpeg 工具集
猜你喜欢
Storage of MySQL database
指针数组和数组指针
'2'&gt;' 10'==true? How does JS perform implicit type conversion?
Brief explanation of depth first search (with basic questions)
毕业设计:设计秒杀电商系统
拼夕夕二面:说说布隆过滤器与布谷鸟过滤器?应用场景?我懵了。。
三年进账35.31亿,这个江西老表要IPO了
如何远程办公更有效率 | 社区征文
2020 Bioinformatics | TransformerCPI
Balance between picture performance of unity mobile game performance optimization spectrum and GPU pressure
随机推荐
ctf-pikachu-CSRF
VIM add interval annotation correctly
图解网络:什么是热备份路由器协议HSRP?
*. No main manifest attribute in jar
Reduce function under functools
ctf-pikachu-XSS
How was my life in 2021
Idea modify body color
软件测试是干什么的 发现缺陷错误,提高软件的质量
Confession code collection, who says program apes don't understand romance
Pytest multi process / multi thread execution test case
【webrtc】m98 ninja 构建和编译指令
智慧地铁| 云计算为城市地铁交通注入智慧
I was tortured by my colleague's null pointer for a long time, and finally learned how to deal with null pointer
2021 RSC | Drug–target affinity prediction using graph neural network and contact maps
[book club issue 13] multimedia processing tool ffmpeg tool set
VIM mapping command
Cesiumjs 2022^ source code interpretation [0] - article directory and source code engineering structure
Perf simple process for multithreaded profile
Activiti7 task service - process variables (setvariable and setvariablelocal)