package com.platform.modules.live.controller;

import com.platform.common.utils.PageUtils;
import com.platform.common.utils.R;
import com.platform.modules.live.entity.LiveTaskAllocationEntity;
import com.platform.modules.live.service.LiveTaskAllocationService;
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 org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;



/**
 * 现场评论
 * 
 * @author weiyan
 * @email 
 * @date 2020-04-08 17:42:35
 */
@RestController
@RequestMapping("/live/taskallocation")
@Api(value = "任务分配", tags = "任务分配")
public class LiveTaskAllocationController extends AbstractController {
	
	@Autowired
	private LiveTaskAllocationService liveTaskAllocationService;
	
	/**
	 * 列表
	 * */
	@GetMapping("/list")
	@RequiresPermissions("live:taskallocation:list")
	@ApiOperation("任务分配后台列表")
	@ApiImplicitParams({
			@ApiImplicitParam(value = "页码", name = "pageNo", defaultValue = "1", paramType = "query", dataType = "int"),
			@ApiImplicitParam(value = "页面大小", name = "pageSize", defaultValue = "15",paramType = "query", dataType = "int"),
	})
	public R list(Integer pageNo, Integer pageSize){

		if (null == pageNo || null == pageSize)
			return R.error("必填参数不能为空");

		PageUtils page = liveTaskAllocationService.backgroundList(pageNo, pageSize);
		return R.ok().put("page", page);
	}

	/**
	 * 信息
	 */
	@GetMapping("/info")
	@RequiresPermissions("live:taskallocation:info")
	public R info(Integer id){
		if (null == id)
			return R.error("ID不能为空");
		return R.ok().put("info", liveTaskAllocationService.selectById(id));
	}
	
	/**
	 * 保存
	 */
	@PostMapping("/save")
	@RequiresPermissions("live:taskallocation:save")
	public R save(LiveTaskAllocationEntity liveSceneTaskAllocation,BindingResult bindingResult){

		if (null == liveSceneTaskAllocation.getId())
			return R.error("ID不能为空");

		liveSceneTaskAllocation.setCreateDate(new Date());
		liveSceneTaskAllocation.setCreateId(getUserId().intValue());

		liveTaskAllocationService.save(liveSceneTaskAllocation);
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@PostMapping("/update")
	@RequiresPermissions("live:taskallocation:update")
	public R update(LiveTaskAllocationEntity liveSceneTaskAllocation,BindingResult bindingResult){
		if (null == liveSceneTaskAllocation.getId())
			return R.error("ID不能为空");
		liveTaskAllocationService.update(liveSceneTaskAllocation);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping("/delete")
	@RequiresPermissions("live:taskallocation:delete")
	public R delete(Integer[] ids){
		if (null == ids || ids.length == 0)
			return R.error("参数不能为空");
		liveTaskAllocationService.deleteBatch(ids);
		return R.ok();
	}
	
}
