package com.playlet.web.controller.app;

import com.github.pagehelper.PageInfo;
import com.playlet.common.annotation.Log;
import com.playlet.common.core.controller.BaseController;
import com.playlet.common.core.domain.AjaxResult;
import com.playlet.common.core.domain.Result;
import com.playlet.common.enums.BusinessType;
import com.playlet.system.domain.PlayletTask;
import com.playlet.web.service.app.PlayletTaskAppService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @Date: 2024-03-21 23:54
 * @Author: 但星霖
 * @Version: v1.0
 * @Description: 短剧任务app控制层
 */
@Slf4j
@Api(tags = "短剧任务app控制层")
@RestController
@RequestMapping(value = "/app/task")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class PlayletTaskAppController extends BaseController {

    private final PlayletTaskAppService playletTaskAppService;

    /**
     * 分页查询任务列表
     */
    @ResponseBody
    @PostMapping("/getTaskList")
    @ApiOperation(value = "分页查询任务列表")
    public Result<PageInfo<PlayletTask>> getTaskList(@RequestBody PlayletTask playletTask,
                                                     @RequestParam(value = "pageNum") Integer pageNum,
                                                     @RequestParam(value = "pageSize") Integer pageSize) {
        return Result.success(playletTaskAppService.getTaskPage(playletTask, pageNum, pageSize));
    }

    /**
     * 分页查询任务列表
     */
    @ResponseBody
    @PostMapping("/getTaskListByUser")
    @ApiOperation(value = "分页查询用户任务列表")
    public Result<PageInfo<PlayletTask>> getTaskListByUser(@RequestBody PlayletTask playletTask,
                                                           @RequestParam(value = "pageNum") Integer pageNum,
                                                           @RequestParam(value = "pageSize") Integer pageSize) {
        return Result.success(playletTaskAppService.getTaskPageByUser(playletTask, pageNum, pageSize));
    }

    /**
     * 任务详情
     */
    @ResponseBody
    @GetMapping("/load")
    @ApiOperation(value = "查询任务详情")
    public Result<PlayletTask> loadByTaskId(@RequestParam(value = "taskId") Long taskId) {
        return Result.success(playletTaskAppService.selectPlayletTaskById(taskId));
    }

    /**
     * 新增保存任务
     */
    @PostMapping("/addDesignate")
    @ResponseBody
    public AjaxResult addSave(@RequestBody PlayletTask playletTask) {
        return toAjax(playletTaskAppService.userDesignateTask(playletTask));
    }


}
