package com.tofly.base.controller.message;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.base.service.messge.UsertaskService;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.common.log.annotation.ToFlyAppLog;
import com.tofly.pojo.message.Usertask;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.web.bind.annotation.ModelAttribute;

import java.util.Arrays;
import java.util.List;

@RestController
@AllArgsConstructor
@RequestMapping("/usertask")
@Api(tags="待办任务信息表接口")
public class UsertaskController {

    private final UsertaskService usertaskService;

//    private final UserTaskStateHandler taskStateHandler;
    /**
    * 分页查询
    * @param page 分页对象
    * @param usertask 待办任务信息表
    * @return
    */
    @GetMapping("/page" )
    @ApiOperation(value = "分页查询")
    public ResultRespone<Page<Usertask>> getUsertaskPage(Page page, @ModelAttribute Usertask usertask) {
      return ResultRespone.success(usertaskService.getUserTaskPage(page, usertask));
    }


    /**
     * 通过id查询待办任务信息表
     * @param id id
     * @return ResultRespone
     */
    @GetMapping("/{id}" )
    @ApiOperation(value = "通过ID查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    public ResultRespone<Usertask> getById(@PathVariable("id" ) Long id) {
      return ResultRespone.success(usertaskService.getById(id));
    }

    /**
     * 新增待办任务信息表
     * @param usertask 待办任务信息表
     * @return ResultRespone
     */
    @ToFlyAppLog(title="新增待办任务信息表" )
    @ApiOperation(value = "新增待办任务信息表")
    @PostMapping("/save")
    public ResultRespone<Boolean> save(@RequestBody Usertask usertask) {
      return ResultRespone.success(usertaskService.save(usertask));
    }

    /**
     * 修改待办任务信息表
     * @param usertask 待办任务信息表
     * @return ResultRespone
     */
    @ToFlyAppLog(title="修改待办任务信息表" )
    @ApiOperation(value = "修改待办任务信息表")
    @PutMapping("/updata")
    public ResultRespone<Boolean> updateById(@RequestBody Usertask usertask) {
      return ResultRespone.success(usertaskService.updateById(usertask));
    }

    /**
     * 通过id删除待办任务信息表
     * @param id id
     * @return ResultRespone
     */
    @ToFlyAppLog(title="通过id删除待办任务信息表" )
    @ApiOperation(value = "通过ID删除待办任务信息表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    @DeleteMapping("/{id}" )
    public ResultRespone removeById(@PathVariable Long id) {
      return ResultRespone.success(usertaskService.removeById(id));
    }

    /**
     * 通过id批量删除待办任务信息表
     * @param ids id
     * @return ResultRespone
     */
    @ToFlyAppLog(title="通过id批量删除待办任务信息表" )
    @ApiOperation(value = "通过ID批量删除待办任务信息表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "批量删除，多个id以逗号隔开", required = true, dataType = "String")
    })
    @DeleteMapping("/deleteByIds" )
    public ResultRespone removeById(String ids) {
        return ResultRespone.success(usertaskService.removeByIds(Arrays.asList(ids.split(","))));
    }

    /**
     * 根据传入对象查询待办事项信息
     * @param usertask 待办任务信息
     * @return
     */
    @PostMapping("/getUserTaskInfo" )
    @ApiOperation(value = "根据传入对象查询待办事项信息")
    public ResultRespone<List<Usertask>> getUserTaskInfo(@RequestBody Usertask usertask) {
        return ResultRespone.success(usertaskService.list(new QueryWrapper<>(usertask)));
    }

}
