CommonServiceImpl.java 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package com.fdkankan.scene.service.impl;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.fdkankan.common.util.FileUtils;
  5. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  6. import com.fdkankan.model.constants.ConstantFilePath;
  7. import com.fdkankan.model.constants.UploadFilePath;
  8. import com.fdkankan.model.utils.CreateObjUtil;
  9. import com.fdkankan.redis.constant.RedisKey;
  10. import com.fdkankan.redis.util.RedisUtil;
  11. import com.fdkankan.scene.bean.SceneJsonBean;
  12. import com.fdkankan.scene.service.ICommonService;
  13. import org.springframework.stereotype.Service;
  14. import javax.annotation.Resource;
  15. import java.io.File;
  16. import java.nio.charset.StandardCharsets;
  17. import java.util.Map;
  18. @Service
  19. public class CommonServiceImpl implements ICommonService {
  20. @Resource
  21. private FYunFileServiceInterface fYunFileService;
  22. @Resource
  23. private RedisUtil redisUtil;
  24. @Override
  25. public void transferToFlv(String num, String fileName, String bucket) throws Exception {
  26. String userEditPath = String.format(UploadFilePath.USER_EDIT_PATH, num);
  27. String localImagesPath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num);
  28. String localFilePath = localImagesPath + fileName;
  29. File targetFile = new File(localImagesPath);
  30. if (!targetFile.exists()){
  31. targetFile.mkdirs();
  32. }
  33. targetFile = new File(localFilePath);
  34. if (targetFile.exists()){
  35. FileUtils.deleteFile(localFilePath);
  36. }
  37. //从用户编辑目录中下载视频到本地
  38. String filePath = userEditPath + fileName;
  39. fYunFileService.downloadFile(bucket, filePath, localImagesPath + fileName);
  40. //视频格式转换
  41. CreateObjUtil.mp4ToFlv(localFilePath, localFilePath.replace("mp4", "flv"));
  42. //上传
  43. String flvFileName = fileName.replace("mp4", "flv");
  44. fYunFileService.uploadFile(bucket, localFilePath.replace("mp4", "flv"), userEditPath+flvFileName);
  45. }
  46. @Override
  47. public void updateViewGetInfo(String num, Map<String, Object> param) {
  48. JSONObject infoJson = this.getInfoJson(num);
  49. param.keySet().stream().forEach(k->{
  50. infoJson.replace(k, param.get(k));
  51. });
  52. String sceneJsonKey = String.format(UploadFilePath.DATA_VIEW_PATH, num) + "scene.json";
  53. fYunFileService.uploadFile(infoJson.toJSONString().getBytes(StandardCharsets.UTF_8), sceneJsonKey);
  54. String redisKey = String.format(RedisKey.SCENE_JSON, num);
  55. redisUtil.del(redisKey);
  56. }
  57. @Override
  58. public JSONObject getInfoJson(String num) {
  59. String sceneJsonKey = String.format(UploadFilePath.DATA_VIEW_PATH, num) + "scene.json";
  60. String fileContent = fYunFileService.getFileContent(sceneJsonKey);
  61. return JSON.parseObject(fileContent);
  62. }
  63. }