package com.sqx.modules.taskCenter.controller;


import com.sqx.modules.taskCenter.entity.TaskCenterReward;
import com.sqx.modules.taskCenter.service.TaskCenterRewardService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sqx.common.utils.DateUtils;
import com.sqx.common.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@Slf4j
@RestController
@Api(value = "任务中心", tags = {"任务中心"})
@RequestMapping(value = "/app/taskCenterReward")
public class TaskCenterRewardController {
    /**
     * 服务对象
     */
    @Autowired
    private TaskCenterRewardService taskCenterRewardService;

    @PostMapping("/insertTaskCenterReward")
    @ApiOperation("添加任务奖励")
    public Result insertTaskCenterReward(@RequestBody TaskCenterReward taskCenterReward) {
        taskCenterReward.setCreateTime(DateUtils.format(new Date()));
        taskCenterRewardService.save(taskCenterReward);
        return Result.success();
    }

    @GetMapping("/{id}")
    @ApiOperation("通过Id查询详情")
    public Result selectOne(@PathVariable Integer id) {
        return Result.success().put("data", taskCenterRewardService.getById(id));
    }

    @PostMapping("/updateTaskCenterReward")
    @ApiOperation("修改任务奖励")
    public Result updateTaskCenterReward(@RequestBody TaskCenterReward taskCenterReward) {
        taskCenterReward.setUpdateTime(DateUtils.format(new Date()));
        taskCenterRewardService.updateById(taskCenterReward);
        return Result.success();
    }

    @PostMapping("/deleteTaskCenterReward")
    @ApiOperation("删除任务奖励")
    public Result deleteTaskCenterReward(Long id) {
        taskCenterRewardService.removeById(id);
        return Result.success();
    }

    @GetMapping("/selectTaskCenterReward")
    @ApiOperation("查询任务奖励")
    public Result selectTaskCenterReward(Integer page, Integer limit,TaskCenterReward taskCenterReward) {
        return Result.success().put("data", taskCenterRewardService.page(new Page<>(page, limit), new QueryWrapper<>(taskCenterReward).orderByDesc("id")));
    }
}

