package cn.pluss.platform.controller.task;

import cn.pluss.platform.api.Result;
import cn.pluss.platform.api.ResultGenerator;
import cn.pluss.platform.base.BaseModelController;
import cn.pluss.platform.entity.UserTask;
import cn.pluss.platform.schedule.UserTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

/**
 * @author DJH
 */
@Controller
@RequestMapping("/userTask")
public class UserTaskController extends BaseModelController<UserTaskService, UserTask> {

    @Autowired
    private UserTaskService userTaskService;

    @GetMapping("/index")
    public String index() {
        return "task/userTaskIndex";
    }

    @PostMapping("/cancel")
    @ResponseBody
    public Result<?> cancel(Integer id) {
        final UserTask entity = userTaskService.getById(id);
        entity.setStatus(UserTask.STATUS_CANCELED);
        entity.setUpdateTime(new Date());
        userTaskService.updateById(entity);

        return ResultGenerator.genSuccessResult("操作成功", null);
    }
}
