package com.fdkankan.scene.service.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.fdkankan.common.util.FileUtils; import com.fdkankan.fyun.face.FYunFileServiceInterface; import com.fdkankan.model.constants.ConstantFilePath; import com.fdkankan.model.constants.UploadFilePath; import com.fdkankan.model.utils.CreateObjUtil; import com.fdkankan.redis.constant.RedisKey; import com.fdkankan.redis.util.RedisUtil; import com.fdkankan.scene.bean.SceneJsonBean; import com.fdkankan.scene.service.ICommonService; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.io.File; import java.util.Map; @Service public class CommonServiceImpl implements ICommonService { @Resource private FYunFileServiceInterface fYunFileService; @Resource private RedisUtil redisUtil; @Override public void transferToFlv(String num, String fileName, String bucket) throws Exception { String userEditPath = String.format(UploadFilePath.USER_EDIT_PATH, num); String localImagesPath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, 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); } //从用户编辑目录中下载视频到本地 String filePath = userEditPath + fileName; fYunFileService.downloadFile(bucket, filePath, localImagesPath + fileName); //视频格式转换 CreateObjUtil.mp4ToFlv(localFilePath, localFilePath.replace("mp4", "flv")); //上传 String flvFileName = fileName.replace("mp4", "flv"); fYunFileService.uploadFile(bucket, localFilePath.replace("mp4", "flv"), userEditPath+flvFileName); } @Override public void updateViewGetInfo(String num, Map param) { JSONObject infoJson = this.getInfoJson(num); param.keySet().stream().forEach(k->{ infoJson.replace(k, param.get(k)); }); String redisKey = String.format(RedisKey.SCENE_JSON, num); redisUtil.del(redisKey); } @Override public JSONObject getInfoJson(String num) { String sceneJsonKey = String.format(UploadFilePath.DATA_VIEW_PATH, num) + "scene.json"; String fileContent = fYunFileService.getFileContent(sceneJsonKey); return JSON.parseObject(fileContent); } }