|
@@ -13,6 +13,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fdkankan.common.constant.*;
|
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
|
import com.fdkankan.common.response.ResultData;
|
|
|
+import com.fdkankan.common.util.CreateObjUtil;
|
|
|
import com.fdkankan.common.util.FileUtil;
|
|
|
import com.fdkankan.common.util.FileUtils;
|
|
|
import com.fdkankan.fyun.constant.StorageType;
|
|
@@ -23,9 +24,7 @@ import com.fdkankan.scene.bean.SceneJsonBean;
|
|
|
import com.fdkankan.scene.entity.SceneEditControls;
|
|
|
import com.fdkankan.scene.entity.SceneEditInfo;
|
|
|
import com.fdkankan.scene.entity.ScenePro;
|
|
|
-import com.fdkankan.scene.entity.SceneProExt;
|
|
|
import com.fdkankan.scene.factory.FloorLogoHandlerFactory;
|
|
|
-import com.fdkankan.scene.factory.FloorPlanHandlerFactory;
|
|
|
import com.fdkankan.scene.factory.MusicHandlerFactory;
|
|
|
import com.fdkankan.scene.factory.ScreenshotHandlerFactory;
|
|
|
import com.fdkankan.scene.mapper.ISceneEditInfoMapper;
|
|
@@ -45,12 +44,8 @@ import java.util.stream.Collectors;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.io.BufferedReader;
|
|
|
import java.io.IOException;
|
|
|
-import java.io.InputStream;
|
|
|
-import java.io.InputStreamReader;
|
|
|
import java.util.Calendar;
|
|
|
import java.util.Objects;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
@@ -600,4 +595,141 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public ResultData saveVideoBox(SaveVidoeBoxParamVO param) throws Exception {
|
|
|
+
|
|
|
+ JSONObject boxVideo = JSONObject.parseObject(param.getData());
|
|
|
+ String sid = boxVideo.getString("sid");
|
|
|
+ if(StrUtil.isEmpty(sid)){
|
|
|
+ throw new BusinessException(ErrorCode.PARAM_REQUIRED);
|
|
|
+ }
|
|
|
+ ScenePro scenePro = sceneProService.findBySceneNum(param.getNum());
|
|
|
+ if(Objects.isNull(scenePro))
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
|
|
|
+
|
|
|
+ SceneEditInfo sceneEditInfo = this.getBySceneProId(scenePro.getId());
|
|
|
+
|
|
|
+ //转换视频格式
|
|
|
+ this.transferToFlv(param.getNum(), param.getFileName());
|
|
|
+
|
|
|
+ //生成boxVideos数据
|
|
|
+ String boxVideos = this.createBoxVideos(sid, boxVideo, sceneEditInfo, OperationType.ADDORUPDATE.code());
|
|
|
+
|
|
|
+ //更新数据库
|
|
|
+ this.updateBoxVideos(sceneEditInfo, scenePro.getId(), boxVideos);
|
|
|
+
|
|
|
+ return ResultData.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultData deleteVideoBox(DeleteVidoeBoxParamVO param) throws Exception {
|
|
|
+
|
|
|
+ ScenePro scenePro = sceneProService.findBySceneNum(param.getNum());
|
|
|
+ if(Objects.isNull(scenePro))
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
|
|
|
+
|
|
|
+ SceneEditInfo sceneEditInfo = this.getBySceneProId(scenePro.getId());
|
|
|
+
|
|
|
+ //根据sid移除json
|
|
|
+ String boxVideos = this.createBoxVideos(param.getSid(), null, sceneEditInfo, OperationType.DELETE.code());
|
|
|
+
|
|
|
+ //写数据库
|
|
|
+ this.updateBoxVideos(sceneEditInfo,scenePro.getId(),boxVideos);
|
|
|
+
|
|
|
+ return ResultData.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateBoxVideos(SceneEditInfo sceneEditInfo, Long sceneProId, String boxVideos){
|
|
|
+ if(StrUtil.isEmpty(boxVideos)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(Objects.isNull(sceneEditInfo)){
|
|
|
+ sceneEditInfo = new SceneEditInfo();
|
|
|
+ sceneEditInfo.setSceneProId(sceneProId);
|
|
|
+ sceneEditInfo.setBoxVideos(boxVideos);
|
|
|
+ this.save(sceneEditInfo);
|
|
|
+ }else{
|
|
|
+ this.update(new LambdaUpdateWrapper<SceneEditInfo>()
|
|
|
+ .setSql("version = version + 1")
|
|
|
+ .set(SceneEditInfo::getBoxVideos, boxVideos)
|
|
|
+ .eq(SceneEditInfo::getId, sceneEditInfo.getId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String createBoxVideos(String sid, JSONObject boxVideo, SceneEditInfo sceneEditInfo, int type){
|
|
|
+
|
|
|
+ String boxVideos = null;
|
|
|
+ if(sceneEditInfo != null){
|
|
|
+ boxVideos = sceneEditInfo.getBoxVideos();
|
|
|
+ }
|
|
|
+ JSONArray boxVideosJson = null;
|
|
|
+ if (StrUtil.isNotEmpty(boxVideos)) {
|
|
|
+ boxVideosJson = JSONArray.parseArray(boxVideos);
|
|
|
+ }else {
|
|
|
+ boxVideosJson = new JSONArray();
|
|
|
+ }
|
|
|
+
|
|
|
+ //删除
|
|
|
+ if(type == OperationType.DELETE.code()){
|
|
|
+ if(boxVideosJson.size() == 0)
|
|
|
+ return null;
|
|
|
+ for(int i=0;i<boxVideosJson.size();++i){
|
|
|
+ JSONObject ele = boxVideosJson.getJSONObject(i);
|
|
|
+ if(ele.getString("sid").equals(sid)){
|
|
|
+ boxVideosJson.remove(i);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return boxVideosJson.toJSONString();
|
|
|
+ }
|
|
|
+
|
|
|
+ //更新
|
|
|
+ boolean exist = false;
|
|
|
+ for(int i=0;i<boxVideosJson.size();++i){
|
|
|
+ JSONObject ele = boxVideosJson.getJSONObject(i);
|
|
|
+ if(ele.getString("sid").equals(sid)){
|
|
|
+ boxVideosJson.set(i, boxVideo);
|
|
|
+ exist = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //新增
|
|
|
+ if(!exist){
|
|
|
+ boxVideosJson.add(boxVideo);
|
|
|
+ }
|
|
|
+
|
|
|
+ return boxVideosJson.toJSONString();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void transferToFlv(String num, String fileName) throws Exception {
|
|
|
+
|
|
|
+ String userEditPath = String.format(UploadFilePath.USER_EDIT_PATH, num);
|
|
|
+ String localImagesPath = String.format(ConstantFilePath.IMAGESBUFFER_FORMAT, num);
|
|
|
+ String localFilePath = localImagesPath + fileName;
|
|
|
+
|
|
|
+ File targetFile = new File(localImagesPath);
|
|
|
+ if (!targetFile.exists()){
|
|
|
+ targetFile.mkdirs();
|
|
|
+ }
|
|
|
+
|
|
|
+ targetFile = new File(localFilePath);
|
|
|
+ if (targetFile.exists()){
|
|
|
+ FileUtils.deleteFile(localFilePath);
|
|
|
+ }
|
|
|
+
|
|
|
+ //从用户编辑目录中下载视频到本地
|
|
|
+ if (!StorageType.LOCAL.code().equals(this.type)) {
|
|
|
+ String filePath = userEditPath + fileName;
|
|
|
+ String imageUrl = ossUrlPrefix + filePath + "?t=" + System.currentTimeMillis();
|
|
|
+ FileUtils.downLoadFromUrl(imageUrl, fileName, localImagesPath);
|
|
|
+ }
|
|
|
+
|
|
|
+ //视频格式转换
|
|
|
+ CreateObjUtil.mp4ToFlv(localFilePath, localFilePath.replace("mp4", "flv"));
|
|
|
+
|
|
|
+ //上传
|
|
|
+ String flvFileName = fileName.replace("mp4", "flv");
|
|
|
+ uploadToOssUtil.upload(localFilePath, userEditPath + fileName);
|
|
|
+ uploadToOssUtil.upload(localFilePath.replace("mp4", "flv"), userEditPath+flvFileName);
|
|
|
+ }
|
|
|
+
|
|
|
}
|