|
@@ -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,90 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
return ResultData.ok();
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public ResultData uploadTagImg(String num, MultipartFile file, String sid, Integer size, Integer tileSize) 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 + "/" + sid + "." + extName;
|
|
|
+ file.transferTo(new File(origFilePath));
|
|
|
+
|
|
|
+ String ossPath = String.format(UploadFilePath.USER_EDIT_PATH, num) + "hotspot/" + sid + "/";
|
|
|
+ Map<String, String> uploadMap = new HashMap<>();
|
|
|
+
|
|
|
+ //切图
|
|
|
+ String fragmentCmd = "vips dzsave --tile-size " + tileSize + " " + 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ //上传
|
|
|
+ uploadMap.entrySet().stream().forEach(entry->{
|
|
|
+ fYunFileService.uploadFile(entry.getKey(), entry.getValue());
|
|
|
+ });
|
|
|
+
|
|
|
+ //上传原图
|
|
|
+ fYunFileService.uploadFile(origFilePath, ossPath + sid + "." + extName);
|
|
|
+
|
|
|
+ }finally {
|
|
|
+ FileUtil.del(workPath);
|
|
|
+ FileUtil.del(dziPath);
|
|
|
+ FileUtil.del(outFilesPath);
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> hw = new HashMap<>();
|
|
|
+ hw.put("height",height);
|
|
|
+ hw.put("width",width);
|
|
|
+ hw.put("sid",sid);
|
|
|
+ hw.put("tileSize",tileSize);
|
|
|
+ return ResultData.ok(hw);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultData deleteTagImg(DeleteSidListParamVO param) {
|
|
|
+ param.getSidList().stream().forEach(sid->{
|
|
|
+ String ossPath = String.format(UploadFilePath.USER_EDIT_PATH, param.getNum()) + "hotspot/" + sid + "/";
|
|
|
+ if(CollUtil.isNotEmpty(fYunFileService.listRemoteFiles(ossPath))){
|
|
|
+ fYunFileService.deleteFolder(ossPath);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ return ResultData.ok();
|
|
|
+ }
|
|
|
+
|
|
|
private void addOrUpdateHotData(String num, List<HotParamVO> hotDataList) throws Exception{
|
|
|
Map<String, String> addOrUpdateMap = new HashMap<>();
|
|
|
int i = 0;
|
|
@@ -531,6 +619,7 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
}
|
|
|
//删除图片音频视频等资源文件
|
|
|
List<String> deleteFileList = new ArrayList<>();
|
|
|
+ List<String> deleteKeys = new ArrayList<>();
|
|
|
for (String data : hotdataList) {
|
|
|
if(StrUtil.isBlank(data)){
|
|
|
continue;
|
|
@@ -554,23 +643,20 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
JSONArray media = jsonObject.getJSONArray("media");
|
|
|
media.stream().forEach(v->{
|
|
|
JSONObject o = (JSONObject) v;
|
|
|
- String src = o.getString("src");
|
|
|
- if(StrUtil.isNotEmpty(src)){
|
|
|
- deleteFileList.add(src);
|
|
|
+ String fileSid = o.getString("sid");
|
|
|
+ if(o.containsKey("tileSize")){//4.14.0版本,图片类型热点不调用通用上传接口上传,改为切图接口上传,所以这里直接删除整个文件目录
|
|
|
+ String ossPath = String.format(UploadFilePath.USER_EDIT_PATH, num) + "hotspot/" + fileSid + "/";
|
|
|
+ deleteKeys.add(ossPath);
|
|
|
+ }else{
|
|
|
+ String src = o.getString("src");
|
|
|
+ if(StrUtil.isNotEmpty(src)){
|
|
|
+ deleteFileList.add(src);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- /* v4.12版本之前是这种方式
|
|
|
- "media": {
|
|
|
- "image": [
|
|
|
- {
|
|
|
- "src": "FfRdi413774.jpg"
|
|
|
- }
|
|
|
- ]
|
|
|
- },
|
|
|
- "type": "image"
|
|
|
- */
|
|
|
if("image".equals(type) || "audio".equals(type) || "video".equals(type)){
|
|
|
//删除图片、视频
|
|
|
JSONObject media = jsonObject.getJSONObject("media");
|
|
@@ -585,14 +671,19 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if(CollUtil.isEmpty(deleteFileList)){
|
|
|
- return;
|
|
|
+ if(CollUtil.isNotEmpty(deleteFileList)){
|
|
|
+ sceneUploadService.delete(
|
|
|
+ DeleteFileParamVO.builder()
|
|
|
+ .num(num)
|
|
|
+ .fileNames(deleteFileList)
|
|
|
+ .bizType("tag-media").build());
|
|
|
}
|
|
|
- sceneUploadService.delete(
|
|
|
- DeleteFileParamVO.builder()
|
|
|
- .num(num)
|
|
|
- .fileNames(deleteFileList)
|
|
|
- .bizType("tag-media").build());
|
|
|
+ if(CollUtil.isNotEmpty(deleteKeys)){
|
|
|
+ deleteKeys.stream().forEach(key->{
|
|
|
+ fYunFileService.deleteFolder(key);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -1214,8 +1305,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);
|
|
|
}
|
|
|
|
|
|
|