dengsixing 5 tháng trước cách đây
mục cha
commit
55a6c3a151

+ 18 - 0
src/main/java/com/fdkankan/scene/controller/SceneEditController.java

@@ -100,6 +100,24 @@ public class SceneEditController extends BaseController {
 
     /**
      * <p>
+     新增或修改场景热点
+     * </p>
+     * @author dengsixing
+     * @date 2022/1/12
+     * @param param
+     * @return com.fdkankan.web.response.ResultData
+     **/
+    @CheckPermit
+    @PostMapping(value = "/tag/img/upload")
+    public ResultData uploadTagImg(@RequestParam(value = "num") String num,
+                                   MultipartFile file,
+                                   @RequestParam(value = "sid") String sid,
+                                   @RequestParam(value = "size", defaultValue = "320") Integer size) throws Exception {
+        return sceneProService.uploadTagImg(num, file, sid, size);
+    }
+
+    /**
+     * <p>
         新增或修改场景热点
      * </p>
      * @author dengsixing

+ 2 - 0
src/main/java/com/fdkankan/scene/service/ISceneProService.java

@@ -34,6 +34,8 @@ public interface ISceneProService extends IService<ScenePro> {
 
     ResultData addOrUpdateTag(SaveTagsParamVO param) throws Exception;
 
+    ResultData uploadTagImg(String num, MultipartFile file, String sid, Integer size) throws Exception;
+
     ResultData deleteTag(DeleteHotParamVO param) throws Exception;
 
     ResultData deleteIcons(DeleteHotIconParamVO param) throws Exception;

+ 82 - 1
src/main/java/com/fdkankan/scene/service/impl/SceneProServiceImpl.java

@@ -5,6 +5,7 @@ import cn.hutool.core.date.DateField;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.util.StrUtil;
+import cn.hutool.core.util.XmlUtil;
 import cn.hutool.core.util.ZipUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
@@ -14,6 +15,7 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fdkankan.common.constant.*;
 import com.fdkankan.common.exception.BusinessException;
+import com.fdkankan.common.util.CmdUtils;
 import com.fdkankan.common.util.FileUtils;
 import com.fdkankan.fyun.face.FYunFileServiceInterface;
 import com.fdkankan.model.constants.ConstantFileName;
@@ -42,6 +44,8 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
 
 import javax.annotation.Resource;
 import java.io.File;
@@ -159,6 +163,73 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
         return ResultData.ok();
     }
 
+    @Override
+    public ResultData uploadTagImg(String num, MultipartFile file, String sid, Integer size) throws Exception {
+        String extName = FileUtil.extName(file.getOriginalFilename());
+        String fragmentPath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num) + "hot_img_fragment/";
+        String workPath = fragmentPath + sid;
+        String dziPath = workPath + ".dzi";
+        String outFilesPath = workPath + "_files/";
+        Integer height = null;
+        Integer width = null;
+        try {
+            FileUtil.mkdir(workPath);
+
+            //保存到本地
+            String origFilePath = workPath + "/" +file.getOriginalFilename();
+            file.transferTo(new File(origFilePath));
+
+            String ossPath = String.format(UploadFilePath.USER_EDIT_PATH, num) + "hotspot/" + sid + "/";
+            Map<String, String> uploadMap = new HashMap<>();
+            //上传原图
+            uploadMap.put(origFilePath, ossPath + sid + "." + extName);
+
+            //切图
+            String fragmentCmd = "vips dzsave " + origFilePath + " " +  workPath;
+            CmdUtils.callLine(fragmentCmd);
+            if(!ComputerUtil.checkComputeCompleted(dziPath, 5, 200)){
+                throw new BusinessException(ErrorCode.FAILURE_CODE_5052);
+            }
+            List<File> files = FileUtil.loopFiles(outFilesPath);
+            files.stream().forEach(v->{
+                uploadMap.put(v.getAbsolutePath(), v.getAbsolutePath().replace(outFilesPath, ossPath));
+            });
+
+            //是否缩放缩略图,判断:读取dzi中的w h,只要有一个超过320,则进行缩放,如果前端传参,则以传参值为准, 缩放默认值320,否则拿原图作为缩略图,
+            String thumbnailName = "thumbnail." + extName;
+            Document document = XmlUtil.readXML(new File(dziPath));
+            Element rootElement = XmlUtil.getRootElement(document);
+            Element sizeElement = XmlUtil.getElement(rootElement, "Size");
+            height = Integer.valueOf(sizeElement.getAttribute("Height"));
+            width = Integer.valueOf(sizeElement.getAttribute("Width"));
+            Integer maxSize = height > width ? height : width;
+            if(maxSize > size){
+                String thumbnailPath =  workPath + "/" + thumbnailName;
+                String scaleCmd = "vipsthumbnail " + origFilePath  + " -s " + size + " -o " + thumbnailPath;
+                CmdUtils.callLine(scaleCmd);
+                if(!ComputerUtil.checkComputeCompleted(thumbnailPath, 5, 200)){
+                    throw new BusinessException(ErrorCode.FAILURE_CODE_5052);
+                }
+                uploadMap.put(thumbnailPath, ossPath + thumbnailName);
+            }else{
+                uploadMap.put(origFilePath, ossPath + thumbnailName);
+            }
+
+            //上传
+            fYunFileService.uploadMulFiles(uploadMap);
+        }finally {
+            FileUtil.del(workPath);
+            FileUtil.del(dziPath);
+            FileUtil.del(outFilesPath);
+        }
+
+        Map<String, Integer> hw = new HashMap<>();
+        hw.put("height",height);
+        hw.put("width",width);
+        return ResultData.ok(hw);
+    }
+
+
     private void addOrUpdateHotData(String num, List<HotParamVO> hotDataList) throws Exception{
         Map<String, String> addOrUpdateMap = new HashMap<>();
         int i = 0;
@@ -1214,8 +1285,18 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
 
     public static void main(String[] args) throws Exception {
 
-        ConvertUtils.convertVisionModelDataToTxt( "D:\\test\\vision.modeldata", "D:\\test\\vision.json");
+//        ConvertUtils.convertVisionModelDataToTxt( "D:\\test\\vision.modeldata", "D:\\test\\vision.json");
+        Document document = XmlUtil.readXML(new File("D:\\Downloads\\aaa.dzi"));
+//        XmlUtil.readObjectFromXml()
+//        Element image = document.getElementById("Image");
+//        getAttribute("size");
+
+        Element rootElement = XmlUtil.getRootElement(document);
+        Element size = XmlUtil.getElement(rootElement, "Size");
+        String Height = size.getAttribute("Height");
+        String Width = size.getAttribute("Width");
 
+        System.out.println(123);
     }