package com.platform.modules.app.controller;

import java.util.Map;

import com.platform.modules.live.constants.SceneConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.platform.common.utils.PageUtils;
import com.platform.common.utils.R;
import com.platform.modules.app.annotation.Login;
import com.platform.modules.live.service.LiveTaskAllocationService;

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

@RestController
@RequestMapping("/app/live/task/allocation")
@Api(value = "APP任务分配", tags = "APP任务分配")
public class APPLiveTaskAllocationController extends AppAbstractController{
	
	@Autowired
	private LiveTaskAllocationService liveTaskAllocationService;
	
	/**
	 * 列表
	 */
	@Login
	@GetMapping("/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(@ApiIgnore @RequestParam(required = false) Map<String, Object> params){
		params.put("userId", getUserId());
		params.put("isDelete", SceneConstants.NOT_DELETE);
		PageUtils page = liveTaskAllocationService.queryPage(params);
        return R.ok().put("page", page);
	}
	
	/**
	 * 删除
	 */
	@Login
	@PostMapping("/delete")
	@ApiOperation("任务分配-删除")
//	@ApiImplicitParams({@ApiImplicitParam(value = "任务分配Id", name = "ids", paramType = "query", dataType = "Integer[]")})
	public R delete(Integer[] ids){
		if (null == ids || ids.length == 0)
			return R.error("参数不能为空");
		liveTaskAllocationService.deleteBatch(ids);
		return R.ok();
	}
	
	@Login
	@PostMapping("/read")
	@ApiOperation("任务分配-已读")
//	@ApiImplicitParams({@ApiImplicitParam(value = "任务分配Id", name = "ids", paramType = "query", dataType = "Integer[]")})
	public R read(Integer[] ids){
		liveTaskAllocationService.readBatch(ids);
		return R.ok();
	}

	@Login
	@PostMapping("/handlerAll")
	@ApiOperation("全部已读或删除")
	@ApiImplicitParam(value = "操作标识，true：全部已读；false：全部删除", name = "flag", paramType = "query", dataType = "Boolean")
	public R readAll(boolean flag){
		liveTaskAllocationService.handlerAll(flag, getUserId().intValue());
		return R.ok();
	}
}
