package cn.com.ctop.material.controller;

import cn.com.ctop.material.entity.MaterialUploadTask;
import cn.com.ctop.material.service.IMaterialUploadTaskService;
import cn.com.ctop.material.utils.Check;
import cn.com.ctop.material.utils.LoadFileUtil;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.entity.mime.content.FileBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.FileSystemResource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;

/**
 * 同步素材任务
 *
 * @author jeecg-boot
 * @version V1.0
 * @date 2021-10-21
 */
@Slf4j
@RestController
@RequestMapping("/material/materialUploadTask")
public class MaterialUploadTaskController {
  @Autowired private IMaterialUploadTaskService materialUploadTaskService;

  @ResponseBody
  @GetMapping("/uploadMaterial")
  public JSONObject uploadVideo(String signature) {
    JSONObject returnJson = new JSONObject();
    materialUploadTaskService.upload(signature);
    returnJson.put("code", 0);
    returnJson.put("message", "任务提交成功");
    return returnJson;
  }

  @ResponseBody
  @GetMapping("/test")
  public void test() {
    File file = new File("/Users/yumeng/video/1.mp4");
    FileBody fileBody = new FileBody(file);
    MaterialUploadTask task = new MaterialUploadTask();
    task.setAccountId(1759777704649735L);
    task.setMediaId(1);
    task.setSignature("14f24444fdab5242761bec1213650734");
    task.setUserId("e9ca23d68d884d4ebb19d07889727dae");
    task.setUserName("管理员");
    task.setMaterialName("1.mp4");
    task.setMaterialUrl("https://media-1301855440.cos.ap-chongqing.myqcloud.com/video/2023-03-13/%E5%8F%AC%E5%9B%9E%2B%E6%B1%87%E5%88%9B%2B%E5%A4%B4%E6%9D%A1%2B20230313%2B%E8%9C%9C%E8%96%AF5%2B%E5%BE%85%E5%AE%A1%E6%A0%B8%2BZZH-1678691834344.mp4");
    task.setSyncAccounts("[1759777704649735,1759777704059917,1759777701723144,1759777701112845,1759777700004935,1759777682207880,1759777681621000,1759777679400973,1759777678261271,1758502285557767,1759777703494669,1759777702891592,1759777702301710,1759777700549646,1759777699317768,1759777681113230,1759777680537613,1759777677705223,1759777677127694,1759777656271885,1759777679938567,1757319984358413,1756429324240909,1756429323677709,1756429323158542,1756429322571790,1756429321976840,1756429321414669,1756429320814599,1756429320190989,1756429319592973,1756429319105544,1758502308354061,1758502307810312,1758502307224584,1758502306708493,1758502306035719,1758502305470478,1758502304949319,1758502304398344,1758502303870990,1758502303312910,1758502285011976,1758502284244062,1758502282601544,1758502282007559,1758502280980487,1758502232711181,1758502232163341,1758502227493902]");
    materialUploadTaskService.uploadBytedance(fileBody,task);
  }

}
