package com.xjrsoft.module.student.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xjrsoft.common.model.result.RT;
import com.xjrsoft.common.page.ConventPage;
import com.xjrsoft.common.page.PageOutput;
import com.xjrsoft.module.student.dto.AddQuotaFormulaRuleAttributeDto;
import com.xjrsoft.module.student.dto.QuotaFormulaRuleAttributePageDto;
import com.xjrsoft.module.student.dto.UpdateQuotaFormulaRuleAttributeDto;
import com.xjrsoft.module.student.entity.QuotaFormulaRuleAttribute;
import com.xjrsoft.module.student.service.IQuotaFormulaRuleAttributeService;
import com.xjrsoft.module.student.vo.QuotaFormulaRuleAttributePageVo;
import com.xjrsoft.module.student.vo.QuotaFormulaRuleAttributeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
* @title: 考核表单属性
* @Author szs
* @Date: 2024-01-29
* @Version 1.0
*/
@RestController
@RequestMapping("/student" + "/quotaFormulaRuleAttribute")
@Api(value = "/student"  + "/quotaFormulaRuleAttribute",tags = "考核表单属性代码")
@AllArgsConstructor
public class QuotaFormulaRuleAttributeController {


    private final IQuotaFormulaRuleAttributeService quotaFormulaRuleAttributeService;

    @GetMapping(value = "/page")
    @ApiOperation(value="考核表单属性列表(分页)")
    @SaCheckPermission("quotaformularuleattribute:detail")
    public RT<PageOutput<QuotaFormulaRuleAttributePageVo>> page(@Valid QuotaFormulaRuleAttributePageDto dto){

        Page<QuotaFormulaRuleAttributePageVo> page = quotaFormulaRuleAttributeService.getPage(new Page<>(dto.getLimit(), dto.getSize()), dto);
        PageOutput<QuotaFormulaRuleAttributePageVo> pageOutput = ConventPage.getPageOutput(page, QuotaFormulaRuleAttributePageVo.class);
        return RT.ok(pageOutput);
    }

    @GetMapping(value = "/info")
    @ApiOperation(value="根据id查询考核表单属性信息")
    @SaCheckPermission("quotaformularuleattribute:detail")
    public RT<QuotaFormulaRuleAttributeVo> info(@RequestParam Long id){
        QuotaFormulaRuleAttribute quotaFormulaRuleAttribute = quotaFormulaRuleAttributeService.getById(id);
        if (quotaFormulaRuleAttribute == null) {
           return RT.error("找不到此数据！");
        }
        return RT.ok(BeanUtil.toBean(quotaFormulaRuleAttribute, QuotaFormulaRuleAttributeVo.class));
    }


    @PostMapping
    @ApiOperation(value = "新增考核表单属性")
    @SaCheckPermission("quotaformularuleattribute:add")
    public RT<Boolean> add(@Valid @RequestBody AddQuotaFormulaRuleAttributeDto dto){
        QuotaFormulaRuleAttribute quotaFormulaRuleAttribute = BeanUtil.toBean(dto, QuotaFormulaRuleAttribute.class);
        boolean isSuccess = quotaFormulaRuleAttributeService.save(quotaFormulaRuleAttribute);
    return RT.ok(isSuccess);
    }

    @PutMapping
    @ApiOperation(value = "修改考核表单属性")
    @SaCheckPermission("quotaformularuleattribute:edit")
    public RT<Boolean> update(@Valid @RequestBody UpdateQuotaFormulaRuleAttributeDto dto){

        QuotaFormulaRuleAttribute quotaFormulaRuleAttribute = BeanUtil.toBean(dto, QuotaFormulaRuleAttribute.class);
        return RT.ok(quotaFormulaRuleAttributeService.updateById(quotaFormulaRuleAttribute));

    }

    @DeleteMapping
    @ApiOperation(value = "删除考核表单属性")
    @SaCheckPermission("quotaformularuleattribute:delete")
    public RT<Boolean> delete(@Valid @RequestBody List<Long> ids){
        return RT.ok(quotaFormulaRuleAttributeService.removeBatchByIds(ids));

    }

}