package com.ankaibei.workFlow.webadmin.ankaibei.controller;

import com.ankaibei.workFlow.common.core.object.TokenData;
import com.ankaibei.workFlow.webadmin.ankaibei.api.TaskInfoApi;
import com.ankaibei.workFlow.webadmin.ankaibei.enums.CodeEnum;
import com.ankaibei.workFlow.webadmin.ankaibei.utils.JwtUtil;
import com.ankaibei.workFlow.webadmin.ankaibei.vo.ResMsg;
import com.ankaibei.workFlow.webadmin.ankaibei.vo.TaskInfoVo;
import org.springframework.util.StringUtils;
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 javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author lwq
 * @version 1.0
 * @description: 任务列表
 * @date 2022/9/14 17:14
 */
@RestController
@RequestMapping("/task")
public class TaskInfoController {

    @Resource
    private TaskInfoApi taskInfoApi;

    /**
     * 查询任务
     *
     * @param  taskInfoVo
     * @return ResMsg
     */
    @RequestMapping("/findTaskInfo")
    public ResMsg findTaskInfo(@RequestBody TaskInfoVo taskInfoVo){

        return taskInfoApi.findTaskInfo(taskInfoVo);
    }
    /**
     * 查询任务详情
     *
     * @param  taskInfoVo
     * @return ResMsg
     */
    @RequestMapping("/findTaskById")
    public ResMsg findTaskById(@RequestBody TaskInfoVo taskInfoVo){

        return taskInfoApi.findTaskById(taskInfoVo);
    }

    /**
     * 完成任务
     *
     * @param  taskInfoVo
     * @return ResMsg
     */
    @RequestMapping("/performTask")
    public ResMsg performTask(@RequestBody TaskInfoVo taskInfoVo){

        return taskInfoApi.performTask(taskInfoVo);
    }

    /**
     * 新增任务
     *
     * @param  taskInfoVo
     * @return ResMsg
     */
    @RequestMapping("/addTaskInfo")
    public ResMsg addTaskInfo(@RequestBody TaskInfoVo taskInfoVo){
        Long userId = TokenData.takeFromRequest().getUserId();
        taskInfoVo.setTaskCreator(String.valueOf(userId));
        return taskInfoApi.addTaskInfo(taskInfoVo);
    }

    /**
     * 删除任务
     *
     * @param  taskInfoVos
     * @return ResMsg
     */
    @RequestMapping("/deleteTask")
    public ResMsg deleteTask(@RequestBody List<TaskInfoVo> taskInfoVos){
        return taskInfoApi.deleteTask(taskInfoVos);
    }




}
