|
|
@ -1,5 +1,6 @@ |
|
|
|
package com.ccsens.mt.api; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.ccsens.cloudutil.feign.TallFeignClient; |
|
|
@ -19,6 +20,7 @@ import javax.annotation.Resource; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import javax.servlet.http.Part; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
/** |
|
|
@ -81,4 +83,35 @@ public class FileController { |
|
|
|
log.info("文件下载结束"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "上传图片证明文件(不大于2M)") |
|
|
|
@ApiImplicitParams({ |
|
|
|
}) |
|
|
|
@RequestMapping(value = "/upload/photo", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) |
|
|
|
public JsonResponse<FileVo.Upload> upload(HttpServletRequest request, @RequestParam() Part file) throws Exception { |
|
|
|
log.info("文件上传:{}", file); |
|
|
|
//限制文件大小 2M
|
|
|
|
if(file.getSize() > 2097152){ |
|
|
|
throw new BaseException(CodeEnum.PHOTO_FILE_EXCEED_2M); |
|
|
|
} |
|
|
|
String authHeader = request.getHeader(WebConstant.HEADER_KEY_TOKEN); |
|
|
|
JsonResponse tokenRes = tallFeignClient.getUserIdByToken(authHeader); |
|
|
|
log.info("{}查询userId返回:{}", authHeader, tokenRes); |
|
|
|
if (tokenRes.getCode().intValue() != CodeEnum.SUCCESS.getCode().intValue()) { |
|
|
|
return tokenRes; |
|
|
|
} |
|
|
|
JSONObject json = JSON.parseObject(JSON.toJSONString(tokenRes.getData())); |
|
|
|
Long userId = json.getLong("id"); |
|
|
|
String dir = PropUtil.path + Constant.File.UPLOAD_URL; |
|
|
|
List<Part> files = new ArrayList<>(); |
|
|
|
files.add(file); |
|
|
|
List<CommonFile> fileVos = fileService.saveFile(dir, files, userId); |
|
|
|
List<FileVo.Upload> vos = FileVo.Upload.transFilePo(fileVos); |
|
|
|
log.info("文件上传返回:{}", vos); |
|
|
|
FileVo.Upload vo = new FileVo.Upload(); |
|
|
|
if(CollectionUtil.isNotEmpty(vos)){ |
|
|
|
vo = vos.get(0); |
|
|
|
} |
|
|
|
return JsonResponse.newInstance().ok(vo); |
|
|
|
} |
|
|
|
} |
|
|
|