package com.platform.modules.scene.controller;

import io.swagger.annotations.ApiOperation;

import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
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.R;
import com.platform.modules.scene.service.SceneService;
import com.platform.modules.sys.controller.AbstractController;

@RestController
@RequestMapping(value = "scene")
public class SceneController extends AbstractController{
	
	@Autowired
	private SceneService sceneService;
	
	@GetMapping("/list")
	@RequiresPermissions("scene:list")
	@ApiOperation(value = "现场列表")
	public R list(@RequestParam Map<String, Object> params) {
		Map<String, Object> map = sceneService.queryPage(params);
		return R.ok(map);
	}
	
	@GetMapping("/download")
	@RequiresPermissions("scene:download")
	@ApiOperation(value = "现场下载")
	public R download(@RequestParam("sceneId") Integer sceneId) {
		Long userId = getUserId();
		sceneService.download(sceneId, userId);
		return R.ok();
	}
	
	@GetMapping("/info")
	@RequiresPermissions("scene:info")
	@ApiOperation(value = "现场详情")
	public R findById(@RequestParam("sceneId") Integer sceneId) {
		Map<String, Object> map = sceneService.findById(sceneId);
		return R.ok(map);
	}
	
	@GetMapping("/report/list")
	@RequiresPermissions("scenet:report:list")
	@ApiOperation(value = "报道列表")
	public R reportList(@RequestParam Map<String, Object> params) {
		Map<String, Object> map = sceneService.queryReportPage(params);
		return R.ok(map);
	}
	
	@GetMapping("/report/download")
	@RequiresPermissions("scene:report:download")
	@ApiOperation(value = "报道下载")
	public R reportDownload(@RequestParam("title") String title, @RequestParam("sceneId") Integer sceneId,@RequestParam("sceneReportId") Integer sceneReportId) {
		if(sceneId==null || sceneReportId==null){
			return R.error("请选择需要下载的现场报道！");
		}
		Long userId = getUserId();
		sceneService.downloadReport(title, sceneId, sceneReportId, userId);
		return R.ok();
	}
	
	@GetMapping("/report/download/image")
	@RequiresPermissions("scene:report:download")
	@ApiOperation(value = "报道下载")
	public R reportDownloadImage(@RequestParam("title") String title, @RequestParam("sceneId") Integer sceneId,@RequestParam("sceneReportId") Integer sceneReportId,@RequestParam("images[]") String[] images) {
		if(sceneId==null || sceneReportId==null || images==null || images.length==0){
			return R.error("请选择需要下载的现场报道图片！");
		}
		Long userId = getUserId();
		sceneService.downloadReportImages(title, sceneId, sceneReportId, userId,images);
		return R.ok();
	}
	
	@GetMapping("/report/info")
	@RequiresPermissions("scene:report:info")
	@ApiOperation(value = "报道详情")
	public R getReportById(@RequestParam("sceneId") Integer sceneId,@RequestParam("sceneReportId") Integer sceneReportId) {
		Map<String, Object> map = sceneService.findReportById(sceneId, sceneReportId);
		return R.ok(map);
	}

}
