12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- 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.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.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.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();
- }
- }
|