package com.platform.modules.live.controller;

import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpStatus;
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.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
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.annotation.SysLog;
import com.platform.common.utils.PageUtils;
import com.platform.common.utils.R;
import com.platform.modules.live.entity.LiveChannelEntity;
import com.platform.modules.live.entity.LiveReportEntity;
import com.platform.modules.live.service.LiveChannelService;
import com.platform.modules.sys.controller.AbstractController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import springfox.documentation.annotations.ApiIgnore;


/**
 * 现场栏目信息
 * 
 * @author weiyan
 * @email 
 * @date 2019-03-28 10:06:27
 */
@RestController
@RequestMapping("/live/channel")
@Api(value = "现场栏目管理", tags = "现场栏目管理")
public class LiveChannelController extends AbstractController{
	@Autowired
	private LiveChannelService liveChannelService;
	
	/**
	 * 列表
	 */
	@GetMapping("/list")
	@RequiresPermissions("live:channel:list")
	@ApiOperation("现场栏目列表")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "page", value = "页数", defaultValue = "1", paramType = "query", dataType = "Integer"),
		@ApiImplicitParam(name = "limit", value = "显示行数", defaultValue = "10", paramType = "query", dataType = "Integer"),
		@ApiImplicitParam(name = "name", value = "现场名称", paramType = "query", dataType = "String")})
	@ApiResponses({@ApiResponse(code = HttpStatus.SC_OK, message = "success", response = LiveReportEntity.class, responseContainer = "List")})
	public R list(@ApiIgnore @RequestParam(required = false) Map<String, Object> params){
		params.put("isDelete", 0);
		PageUtils page =  liveChannelService.page(params);
		return R.ok().put("page", page);
	}
	
	
	/**
	 * 信息
	 */
	@GetMapping("/info")
	@RequiresPermissions("live:channel:info")
	@ApiOperation("现场栏目信息")
	public R info(@RequestParam("id") Integer id){
		return R.ok().put("info", liveChannelService.selectById(id));
	}
	/**
	 * 保存
	 */
	@SysLog("保存栏目信息")
	@PostMapping("/save")
	@RequiresPermissions("live:channel:save")
	@ApiOperation("保存栏目信息")
	public R save(@ModelAttribute LiveChannelEntity liveChannel){
		if(StringUtils.isBlank(liveChannel.getName())) {
			return R.error("栏目名称不能为空");
		}
		if(StringUtils.isBlank(liveChannel.getIdentify())) {
			return R.error("栏目标识不能为空");
		}
		liveChannelService.save(liveChannel, getUserId());
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@SysLog("修改栏目信息")
	@PostMapping("/update")
	@RequiresPermissions("live:channel:update")
	@ApiOperation("修改栏目信息")
	public R update(@ModelAttribute LiveChannelEntity liveChannel){
		if(liveChannel == null || liveChannel.getId()==null) {
			return R.error("栏目ID不能为空");
		}
		if(StringUtils.isBlank(liveChannel.getName())) {
			return R.error("栏目名称不能为空");
		}
		if(StringUtils.isBlank(liveChannel.getIdentify())) {
			return R.error("栏目标识不能为空");
		}
		liveChannelService.update(liveChannel, getUserId());
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@SysLog("删除栏目信息")
	@PostMapping("/delete")
	@RequiresPermissions("live:channel:delete")
	@ApiOperation("删除栏目信息")
	public R delete(Integer[] ids){
		liveChannelService.deleteBatch(ids, getUserId());
		return R.ok();
	}
	
	/**
	 * 显示
	 */
	@SysLog("批量显示栏目信息")
	@PostMapping("/display")
	@RequiresPermissions("live:channel:display")
	@ApiOperation("批量显示栏目信息")
	public R display(Integer[] ids){
		if(ids==null || ids.length==0){
			return R.error("栏目ID不能为空");
		}
		liveChannelService.displayBatch(ids,getUserId());
		return R.ok();
	}
	/**
	 * 取消不显示
	 */
	@SysLog("批量取消显示栏目信息")
	@PostMapping("/cancelDisplay")
	@RequiresPermissions("live:channel:cancelDisplay")
	@ApiOperation("批量取消显示栏目信息")
	public R cancelTop(Integer[] ids){
		if(ids==null || ids.length==0){
			return R.error("栏目ID不能为空");
		}
		liveChannelService.cancelDisplayBatch(ids, getUserId());
		return R.ok();
	}
	/**
	 * 排序
	 */
	@SysLog("栏目信息排序")
	@PostMapping("/priority")
	@RequiresPermissions("live:channel:priority")
	@ApiOperation("栏目信息排序")
	public R priority(Integer[] ids,Integer[] prioritys){
		if(ids==null || ids.length==0){
			return R.error("栏目ID不能为空");
		}
		if(prioritys==null || prioritys.length==0){
			return R.error("栏目排序不能为空");
		}
		liveChannelService.priority(ids, prioritys, getUserId());
		return R.ok();
	}
	
}
