package com.xhkjedu.sapi.controller.itemtool;

import com.xhkjedu.annotation.Action;
import com.xhkjedu.sapi.model.itemtool.TTodo;
import com.xhkjedu.sapi.service.itemtool.TodoService;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.vo.ResultVo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
* @author ywx
* @classname TTodoController
* @description
* @date 2020/06/12 16:01
**/
@RestController
@RequestMapping("/todo")
public class TodoController {
    @Resource
    private TodoService todoService;

    @PostMapping("/add")
    @Action("待办事项-增加")
    public ResultVo add(@RequestBody TTodo tTodo) {
        Integer id = todoService.save(tTodo);
        return new ResultVo(0, "保存成功",id);
    }

    @PostMapping("/delete")
    @Action("待办事项-删除")
    public ResultVo delete(@RequestBody TTodo tTodo) {
        N_Utils.validation(new Object[]{tTodo.getTodoid(),"待办事项id",1});
        todoService.deleteById(tTodo.getTodoid());
        return new ResultVo(0,"删除成功");
    }

    @PostMapping("/update")
    @Action("待办事项-修改")
    public ResultVo update(@RequestBody TTodo tTodo) {
        N_Utils.validation(new Object[]{tTodo.getTodoid(),"待办事项id",1});
        todoService.update(tTodo);
        return new ResultVo(0,"修改成功");
    }

    @PostMapping("/list")
    public ResultVo listAll(@RequestBody TTodo tTodo) {
        N_Utils.validation(new Object[]{tTodo.getTododate(),"年月",2,tTodo.getUserid(),"用户id",1});
        List<TTodo> list = todoService.listAll(tTodo);
        return new ResultVo(0,"获取列表成功",list);
    }

    @PostMapping("/finished")
    public ResultVo finished(@RequestBody TTodo tTodo) {
        N_Utils.validation(new Object[]{tTodo.getTodoid(),"待办事项id",1});
        todoService.finished(tTodo.getTodoid(),tTodo.getTodostate());
        return new ResultVo(0,"代办事项完成成功");
    }
}
