package com.xhkjedu.sapi.controller.assess;

import com.xhkjedu.annotation.Action;
import com.xhkjedu.sapi.model.assess.TAssessQuota;
import com.xhkjedu.sapi.service.assess.AssessQuotaService;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.vo.ResultVo;
import com.xhkjedu.sapi.vo.assess.AssessQuotaVo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
* @author ywx
* @classname 评价指标
* @description
* @date 2021/11/10 10:31
**/
@RestController
@RequestMapping("/aquota")
public class AssessQuotaController {
    @Resource
    private AssessQuotaService assessQuotaService;

    //保存
    @PostMapping("/add")
    @Action("评价指标-增加")
    public ResultVo add(@RequestBody TAssessQuota quota) {
        String quotaname = quota.getQuotaname();
        Integer createid = quota.getCreateid();
        Integer schoolid = quota.getSchoolid();
        N_Utils.validation(new Object[]{quotaname,"指标名称",2,createid,"操作人",1,schoolid,"学校id",1});
        assessQuotaService.save(quota);
        return new ResultVo(0,"保存成功");
    }

    //删除
    @PostMapping("/delete")
    @Action("评价指标-删除")
    public ResultVo delete(@RequestBody TAssessQuota quota) {
        Integer quotaid = quota.getQuotaid();
        N_Utils.validation(new Object[]{quotaid,"指标id",1});
        try {
            assessQuotaService.deleteById(quota.getQuotaid());
        } catch (Exception e) {
            return new ResultVo(1,e.getMessage());
        }
        return new ResultVo(0,"删除成功");
    }

    //修改
    @PostMapping("/update")
    @Action("评价指标-修改")
    public ResultVo update(@RequestBody TAssessQuota quota) {
        String quotaname = quota.getQuotaname();
        Integer createid = quota.getCreateid();
        Integer quotaid = quota.getQuotaid();
        N_Utils.validation(new Object[]{quotaid,"指标id",1,quotaname,"指标名称",2,createid,"操作人",1});
        assessQuotaService.update(quota);
        return new ResultVo(0,"修改成功");
    }

    //列表
    @PostMapping("/list")
    public ResultVo list(@RequestBody TAssessQuota quota) {
        Integer schoolid = quota.getSchoolid();
        N_Utils.validation(new Object[]{schoolid,"学校id",1});
        List<AssessQuotaVo> list = assessQuotaService.listAll(schoolid);
        return new ResultVo(0,"获取列表成功",list);
    }
}
