package com.xhkjedu.sapi.controller.assess;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xhkjedu.annotation.Action;
import com.xhkjedu.sapi.model.assess.TAssess;
import com.xhkjedu.sapi.service.assess.AssessService;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.utils.PageUtil;
import com.xhkjedu.vo.PageResult;
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 TAssessController
* @description
* @date 2021/11/10 10:31
**/
@RestController
@RequestMapping("/assess")
public class AssessController {
    @Resource
    private AssessService assessService;

    @PostMapping("/add")
    @Action("评价录入-增加")
    public ResultVo add(@RequestBody TAssess assess) {
        TAssess tAssess = assessService.save(assess);
        return new ResultVo(0,"保存成功",tAssess);
    }

    @PostMapping("/delete")
    @Action("评价录入-删除")
    public ResultVo delete(@RequestBody TAssess assess) {
        assessService.deleteById(assess.getAssessid());
        return new ResultVo(0,"删除成功");
    }

    @PostMapping("/update")
    @Action("评价录入-修改")
    public ResultVo update(@RequestBody TAssess assess) {
        assessService.update(assess);
        return new ResultVo(0,"修改成功");
    }

    @PostMapping("/detail")
    public ResultVo detail(@RequestBody TAssess assess) {
        Integer assessid = assess.getAssessid();
        Integer templateid = assess.getTemplateid();
        N_Utils.validation(new Object[]{assessid,"评价用户id",1,templateid,"评价模板id",1});
        List<Map> list = assessService.listDetail(assess);
        return new ResultVo(0,"获取详情成功",list);
    }

    @PostMapping("/list")
    public ResultVo list(@RequestBody TAssess assess) {
        N_Utils.validation(new Object[]{assess.getSchoolid(),"学校id",1,assess.getTemplateid(),"评价模板id",1
                ,assess.getPage(),"页码",1,assess.getPageSize(),"显示条数",1});
        assess.setUsertype(assessService.getUsertypeById(assess.getCreateid()));
        PageHelper.startPage(assess.getPage(), assess.getPageSize());
        List<Map> list = assessService.listAll(assess);
        PageResult pageResult = PageUtil.getPageResult(new PageInfo(list));
        return new ResultVo(0,"获取列表成功",pageResult);
    }

    @PostMapping("/analyze")
    public ResultVo analyze(@RequestBody TAssess assess) {
        Integer templateid = assess.getTemplateid();
        N_Utils.validation(new Object[]{templateid,"评价模板id",1});
        List<Map> list = assessService.listAnalyze(assess);
        return new ResultVo(0,"获取评价统计成功",list);
    }
}
