package com.xhkjedu.sapi.controller.system;

import com.xhkjedu.annotation.Action;
import com.xhkjedu.sapi.model.system.TSchoolStype;
import com.xhkjedu.sapi.service.system.SchoolStypeService;
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 TSchoolStypeController
* @description
* @date 2021/02/23 09:50
**/
@RestController
@RequestMapping("/stype")
public class SchoolStypeController {
    @Resource
    private SchoolStypeService schoolStypeService;

    @PostMapping("/add")
    @Action("学校主题-增加")
    public ResultVo add(@RequestBody List<TSchoolStype> list) {
        return schoolStypeService.batchSave(list);
    }

    @PostMapping("/list")
    public ResultVo list(@RequestBody TSchoolStype stype) {
        N_Utils.validation(new Object[]{stype.getSchooldomain(),"域名",2});
        List<TSchoolStype> list = schoolStypeService.listAll(stype);
        return new ResultVo(0,"获取学校样式列表成功",list);
    }

    @PostMapping("/add2")
    @Action("学校主题-增加")
    public ResultVo add2(@RequestBody List<TSchoolStype> list) {
        if (N_Utils.isListEmpty(list)) return new ResultVo(1,"学校样式不能为空");
        return schoolStypeService.batchSave2(list);
    }

    //获取学校设置的样式
    @PostMapping("/list2")
    public ResultVo list2(@RequestBody TSchoolStype stype) {
        N_Utils.validation(new Object[]{stype.getSchoolid(),"学校id",1});
        List<TSchoolStype> list = schoolStypeService.listAll2(stype);
        return new ResultVo(0,"获取学校样式列表成功",list);
    }

    /*
     * @Description 获取学校样式（设置登录页面获取数据）
     * @Date 2023/11/21 10:19:12
     * @Author WN
     * @Param [stype]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/sstyles")
    public ResultVo allList(@RequestBody TSchoolStype stype) {
        N_Utils.validation(new Object[]{stype.getSchoolid(),"学校id",1});
        Map<String,List<TSchoolStype>> rtnMap = schoolStypeService.listSchoolStypeAndDefault(stype);
        return new ResultVo(0,"获取学校样式列表成功",rtnMap);
    }
}
