package com.sqx.modules.complet.controller;


import cn.hutool.core.date.DateUtil;
import com.sqx.modules.complet.entity.CompletAward;
import com.sqx.modules.complet.service.CompletAwardService;
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 = "/completAward")
public class CompletAwardController {
    /**
     * 服务对象
     */
    @Autowired
    private CompletAwardService completAwardService;

    @PostMapping("/insertCompletAward")
    @ApiOperation("添加达标奖励")
    public Result insertCompletAward(@RequestBody CompletAward completAward) {
        completAward.setCreateTime(DateUtil.now());
        completAwardService.save(completAward);
        return Result.success();
    }

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

    @PostMapping("/updateCompletAward")
    @ApiOperation("修改达标奖励")
    public Result updateCompletAward(@RequestBody CompletAward completAward) {
        completAward.setUpdateTime(DateUtil.now());
        completAwardService.updateById(completAward);
        return Result.success();
    }

    @PostMapping("/deleteCompletAward")
    @ApiOperation("删除达标奖励")
    public Result deleteCompletAward(Long id) {
        completAwardService.removeById(id);
        return Result.success();
    }

    @GetMapping("/selectCompletAward")
    @ApiOperation("查询达标奖励")
    public Result selectCompletAward(Integer page, Integer limit) {
        return Result.success().put("data", completAwardService.page(new Page<>(page, limit), new QueryWrapper<CompletAward>().orderByAsc("id")));
    }
}

