当前位置:网站首页>[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 ");
}
边栏推荐
- 线程常用的方法
- Flink学习8:数据的一致性
- 【罗技】m720
- Idea configuration 360zip open by default -- external tools
- 用于TCP协议交互的TCPClientDemo
- 深度优先搜索简要讲解(附带基础题)
- 【读书会第十三期】多媒体处理工具 FFmpeg 工具集
- MySQL maxscale realizes read-write separation
- 【微服务|openfeign】@FeignClient详解
- Cesiumjs 2022^ source code interpretation [0] - article directory and source code engineering structure
猜你喜欢

Rhcsa-- day one

Confession code collection, who says program apes don't understand romance

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

函数计算异步任务能力介绍 - 任务触发去重

MySQL maxscale realizes read-write separation

Pointer array and array pointer

LNK2038 检测到“RuntimeLibrary”的不匹配项: 值“MD_DynamicRelease”不匹配值“MDd_DynamicDebug”(main.obj 中)

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

Objective-C description method and type method

Two commonly used graphics can easily realize data display
随机推荐
Why is the probability of pod increasing after IPtable
2021 RSC | Drug–target affinity prediction using graph neural network and contact maps
【webrtc】m98 ninja 构建和编译指令
Unity移动端游戏性能优化简谱之 画面表现与GPU压力的权衡
I was tortured by my colleague's null pointer for a long time, and finally learned how to deal with null pointer
用于TCP协议交互的TCPClientDemo
【微服务|openfeign】使用openfeign远程调用文件上传接口
拼夕夕二面:说说布隆过滤器与布谷鸟过滤器?应用场景?我懵了。。
三菱M70宏变量读取三菱M80公共变量采集三菱CNC变量读取采集三菱CNC远程刀补三菱机床在线刀补三菱数控在线测量
Support the first triggered go ticker
Myslq delete followed by limit
CesiumJS 2022^ 源码解读[0] - 文章目录与源码工程结构
Huawei cloud Kunpeng engineer training (Guangxi University)
Distributed system: what, why, how
1289_FreeRTOS中vTaskSuspend()接口实现分析
10 reasons for not choosing to use free virtual hosts
JS实现文字滚动 跑马灯效果
Idea configuration 360zip open by default -- external tools
JDBC 进阶
Go 语言入门很简单:Go 实现凯撒密码