CommonServiceImpl.java 2.9 KB

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