package com.platform.modules.ks.controller;

import io.swagger.annotations.ApiOperation;

import java.util.HashMap;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.platform.common.utils.PageUtils;
import com.platform.common.utils.R;
import com.platform.modules.ks.service.PlmVideoDownloadLogService;
import com.platform.modules.ks.service.PlmVideoService;
import com.platform.modules.sys.controller.AbstractController;

@RestController
@RequestMapping(value = "/api/material")
public class MaterialController extends AbstractController{
	
	@Autowired
	private PlmVideoService PlmVideoService;
	@Autowired
	private PlmVideoDownloadLogService PlmVideoDownloadLogService;
	
	@GetMapping("/list")
	@RequiresPermissions("kuaishou:video:list")
	@ApiOperation(value = "列表")
	public R list(@RequestParam Map<String, Object> params) {
		params.put("operatorId", getUserId());
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			map = PlmVideoService.query(params);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return R.ok(map);
	}
	@GetMapping("/download")
	@RequiresPermissions("kuaishou:video:download")
	@ApiOperation(value = "下载")
	public R download(@RequestParam Map<String, Object> params) {
		params.put("operatorId", getUserId()==null?1:getUserId());
		try {
			PlmVideoService.download(params);
		} catch (JSONException e) {
			e.printStackTrace();
			return R.error("下载失败");
		}
		return R.ok();
	}
	
	@GetMapping("/download/list")
	@RequiresPermissions("kuaishou:video:download:list")
	@ApiOperation(value = "下载列表")
	public R downloadList(@RequestParam Map<String, Object> params) {
		PageUtils page = PlmVideoDownloadLogService.queryPage(params);
		return R.ok().put("page", page);
	}
}
