package com.xhkjedu.sapi.controller.assess;

import com.xhkjedu.annotation.Action;
import com.xhkjedu.sapi.model.assess.TAssessTemplate;
import com.xhkjedu.sapi.service.assess.AssessTemplateService;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.vo.ResultVo;
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;
import java.util.Map;

/**
* @author ywx
* @classname TAssessTemplateController
* @description 评价模版
* @date 2021/11/10 10:31
**/
@RestController
@RequestMapping("/atemplate")
public class AssessTemplateController {
    @Resource
    private AssessTemplateService assessTemplateService;

    //添加
    @PostMapping("/add")
    @Action("评价模版-增加")
    public ResultVo add(@RequestBody TAssessTemplate template) {
        List<Integer> quotaids = template.getQutoaids();
        if(quotaids==null || quotaids.size()==0){
            return new ResultVo(1,"模版指标不能为空");
        }else{
            String templatename = template.getTemplatename();
            Integer schoolid = template.getSchoolid();
            Integer createid = template.getCreateid();
            N_Utils.validation(new Object[]{templatename,"模版名称",2,createid,"操作人",1,schoolid,"学校id",1});
            assessTemplateService.save(template);
            return new ResultVo(0,"保存成功");
        }

    }

    //删除
    @PostMapping("/delete")
    @Action("评价模版-删除")
    public ResultVo delete(@RequestBody TAssessTemplate template) {
        Integer templateid = template.getTemplateid();
        N_Utils.validation(new Object[]{templateid,"模版id",1});
        assessTemplateService.deleteById(templateid);
        return new ResultVo(0,"删除成功");
    }

    //修改
    @PostMapping("/update")
    @Action("评价模版-修改")
    public ResultVo update(@RequestBody TAssessTemplate template) {
        List<Integer> quotaids = template.getQutoaids();
        if(quotaids==null || quotaids.size()==0){
            return new ResultVo(1,"模版指标不能为空");
        }else{
            String templatename = template.getTemplatename();
            Integer templateid = template.getTemplateid();
            Integer createid = template.getCreateid();
            N_Utils.validation(new Object[]{templateid,"模版id",1,templatename,"模版名称",2,createid,"操作人",1});
            assessTemplateService.update(template);
            return new ResultVo(0,"修改成功");
        }
    }

    //模版关联指标
    @PostMapping("/qutoas")
    public ResultVo qutoas(@RequestBody TAssessTemplate template) {
        Integer templateid = template.getTemplateid();
        N_Utils.validation(new Object[]{templateid,"模版id",1});
        List<Integer> lst = assessTemplateService.listQutosByTemplateid(templateid);
        return new ResultVo(0,"获取模版关联指标成功",lst);
    }

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

    //模版下树形指标
    @PostMapping("/tquota")
    public ResultVo listTreeQuotas(@RequestBody TAssessTemplate template) {
        Integer templateid = template.getTemplateid();
        N_Utils.validation(new Object[]{templateid,"模版id",1});
        List<Map> list = assessTemplateService.listQuotaByTemplateid(template.getTemplateid());
        return new ResultVo(0,"获取模版下指标成功",list);
    }
}
