123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- package com.fdkankan.manage_jp.controller;
- import cn.hutool.core.io.FileUtil;
- import com.alibaba.fastjson.JSONObject;
- import com.fdkankan.fyun.face.FYunFileServiceInterface;
- import com.fdkankan.manage_jp.common.Constant;
- import com.fdkankan.manage_jp.common.Result;
- import com.fdkankan.manage_jp.common.ResultCode;
- import com.fdkankan.manage_jp.config.FyunConfig;
- import com.fdkankan.manage_jp.exception.BusinessException;
- import com.fdkankan.manage_jp.httpClient.client.FdKKClient;
- import com.fdkankan.manage_jp.httpClient.param.UploadEditSceneParam;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.PostMapping;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.bind.annotation.RestController;
- import org.springframework.web.multipart.MultipartFile;
- import java.io.File;
- import java.io.IOException;
- import java.net.URL;
- import java.util.HashMap;
- import java.util.UUID;
- @RestController
- @RequestMapping("/manage_jp/file")
- @Slf4j
- public class UploadController extends BaseController{
- @Autowired
- FYunFileServiceInterface fYunFileServiceInterface;
- @PostMapping("/uploadImg")
- public Result uploadImg(@RequestParam("file") MultipartFile file) throws IOException {
- Long date = System.currentTimeMillis();
- String fileName = date + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
- String filePath = Constant.AGENT_PATH + "company" + File.separator + fileName;
- File targetFile = new File(filePath);
- if(!targetFile.getParentFile().exists()){
- targetFile.getParentFile().mkdirs();
- }
- file.transferTo(targetFile);
- String url = fYunFileServiceInterface.uploadFile(filePath,"img/".concat(fileName));
- return Result.success("",url);
- }
- @Autowired
- FdKKClient fdKKClient;
- @PostMapping("/uploadE57")
- public Result uploadE57(@RequestParam("file") MultipartFile file,Integer isObj) {
- String originalFilename = file.getOriginalFilename();
- String suffix = originalFilename.substring(originalFilename.lastIndexOf("."));
- if(!suffix.equals(".e57")){
- throw new BusinessException(ResultCode.UPLOAD_ERROR2);
- }
- try {
- String newFileName = UUID.randomUUID().toString().replace("-","");
- String filePath = Constant.MANAGE_PATH + "e57" + File.separator + newFileName +suffix;
- File targetFile = new File(filePath);
- if(!targetFile.getParentFile().exists()){
- targetFile.getParentFile().mkdirs();
- }
- file.transferTo(targetFile);
- fYunFileServiceInterface.uploadFile(filePath,filePath.replace(Constant.MANAGE_PATH,"manage/"));
- FileUtil.del(targetFile);
- UploadEditSceneParam editSceneParam = new UploadEditSceneParam();
- editSceneParam.setTitle(originalFilename.replace(suffix,""));
- editSceneParam.setUserId(getUser().getId());
- editSceneParam.setPath(filePath.replace(Constant.MANAGE_PATH,"manage/"));
- editSceneParam.setIsObj(isObj);
- editSceneParam.setOtherType("E57_V4");
- JSONObject jsonObject = fdKKClient.reverseScene(editSceneParam);
- Integer code = jsonObject.getInteger("code");
- if(code != 0){
- log.info("调用失败-toFdCreateScene:{}",jsonObject);
- throw new BusinessException(ResultCode.UPLOAD_ERROR);
- }
- }catch (Exception e){
- log.info("调用失败-toFdCreateScene:",e);
- throw new BusinessException(ResultCode.UPLOAD_ERROR);
- }
- return Result.success();
- }
- @Autowired
- FyunConfig fyunConfig;
- @PostMapping("/getUploadUrl")
- public Result getUploadUrl( @RequestParam(value = "fileName",required = false)String fileName) {
- String newFileName = UUID.randomUUID().toString().replace("-","");
- String suffix = fileName.substring(fileName.lastIndexOf("."));
- URL presignedUrl = fyunConfig.getPresignedUrl("manage/e57/" + newFileName + suffix);
- HashMap<String, Object> map = new HashMap<>();
- map.put("newFileName",newFileName + suffix);
- map.put("url",presignedUrl.toString());
- return Result.success(map);
- }
- @PostMapping("/relevanceE57")
- public Result relevanceE57( @RequestParam(value = "isObj",required = false)Integer isObj,
- @RequestParam(value = "title",required = false)String title,
- @RequestParam(value = "newFileName",required = false)String newFileName ){
- if(StringUtils.isBlank(newFileName)){
- throw new BusinessException(ResultCode.PARAM_ERROR);
- }
- String ossPath = "manage/e57/"+newFileName;
- if(!fYunFileServiceInterface.fileExist(ossPath)){
- throw new BusinessException(ResultCode.UPLOAD_ERROR3);
- }
- UploadEditSceneParam editSceneParam = new UploadEditSceneParam();
- editSceneParam.setTitle(title);
- editSceneParam.setUserId(getUser().getId());
- editSceneParam.setPath("manage/e57/"+newFileName);
- editSceneParam.setIsObj(isObj);
- editSceneParam.setOtherType("E57_V4");
- JSONObject jsonObject = fdKKClient.reverseScene(editSceneParam);
- Integer code = jsonObject.getInteger("code");
- if(code != 0){
- log.info("调用失败-toFdCreateScene:{}",jsonObject);
- throw new BusinessException(ResultCode.UPLOAD_ERROR);
- }
- return Result.success();
- }
- }
|