package com.hzs.system.config.controller.manage;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hzs.common.core.web.controller.BaseController;
import com.hzs.common.core.web.domain.AjaxResult;
import com.hzs.common.core.web.page.TableDataInfo;
import com.hzs.common.domain.vertex.BdVertexBonus;
import com.hzs.common.domain.vertex.ext.BdVertexBonusExt;
import com.hzs.system.config.service.IBdVertexBonusService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 体系奖项配置
 */
@Slf4j
@RestController
@RequestMapping("/manage/vertex-bonus")
public class BdVertexBonusController extends BaseController {

    @Autowired
    private IBdVertexBonusService iBdVertexBonusService;

    /**
     * 查询列表
     *
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo list() {
        startPage();
        List<BdVertexBonusExt> list = iBdVertexBonusService.listVertexBonus();
        return getDataTable(list);
    }

    /**
     * 新增体系配置
     *
     * @param bdVertexBonus
     * @return
     */
    @PostMapping("/save")
    public AjaxResult save(@RequestBody BdVertexBonus bdVertexBonus) {
        LambdaQueryWrapper<BdVertexBonus> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(BdVertexBonus::getPkVertex, bdVertexBonus.getPkVertex());
        wrapper.eq(BdVertexBonus::getBonusItems, bdVertexBonus.getBonusItems());
        if (iBdVertexBonusService.count(wrapper) > 0) {
            return AjaxResult.error("数据已存在");
        }
        iBdVertexBonusService.save(bdVertexBonus);
        return AjaxResult.success();
    }

    /**
     * 删除
     *
     * @param pkId
     * @return
     */
    @DeleteMapping("/{pkId}")
    public AjaxResult delete(@PathVariable Integer pkId) {
        return AjaxResult.success(iBdVertexBonusService.removeById(pkId));
    }

}
