当前位置:网站首页>[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 ");
}
边栏推荐
- STM32 external DHT11 display temperature and humidity
- The three-year revenue is 3.531 billion, and this Jiangxi old watch is going to IPO
- 01 qemu 启动编译好的镜像 VFS: Unable to mount root fs on unknown-block(0,0)
- [paddleseg source code reading] paddleseg custom data class
- SQL语句加强练习(MySQL8.0为例)
- There is a problem that the package cannot be parsed in the like project
- 【读书会第十三期】视频文件的封装格式
- Calculate the odd sum of 1~n (1~100 as an example)
- MySQL maxscale realizes read-write separation
- [paddleseg source code reading] paddleseg calculates Miou
猜你喜欢

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

laravel admin里百度编辑器自定义路径和文件名

mysql数据库的存储
![[Logitech] m720](/img/bb/44144a1c3907808398c05b3b36962c.png)
[Logitech] m720

Penetration practice - sqlserver empowerment

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

Exercices de renforcement des déclarations SQL (MySQL 8.0 par exemple)

Evolution of MySQL database architecture

Unity 绘制弹球和台球的运动轨迹

还原窗口位置的微妙之处
随机推荐
【华为云IoT】读书笔记之《万物互联:物联网核心技术与安全》第3章(上)
Introduction to asynchronous task capability of function calculation - task trigger de duplication
AAAI2022 | Word Embeddings via Causal Inference: Gender Bias Reducing and Semantic Information Preserving
pytest多进程/多线程执行测试用例
[Logitech] m720
思考的小记录
Pointer array and array pointer
CesiumJS 2022^ 源码解读[0] - 文章目录与源码工程结构
A review of reverse reinforcement learning at Virginia Tech (VT)
[Huawei cloud IOT] reading notes, "Internet of things: core technology and security of the Internet of things", Chapter 3 (I)
疫情来袭--远程办公之思考|社区征文
Database SQL statement summary, continuous update
Redis cluster uses Lua script. Lua script can also be used for different slots
Smart subway | cloud computing injects wisdom into urban subway transportation
STM32 external DHT11 display temperature and humidity
【微服务|openfeign】@FeignClient详解
[paddleseg source code reading] paddleseg calculation dice
【CSRF-01】跨站请求伪造漏洞基础原理及攻防
vim映射命令
PostgreSQL users cannot create table configurations by themselves