package com.xhkjedu.sapi.controller.research;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xhkjedu.annotation.Action;
import com.xhkjedu.sapi.model.research.TResearch;
import com.xhkjedu.sapi.model.research.TResearchUser;
import com.xhkjedu.sapi.service.research.ResearchUserService;
import com.xhkjedu.sapi.vo.research.ResearchUserVo;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.utils.PageUtil;
import com.xhkjedu.vo.PageResult;
import com.xhkjedu.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
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 java.util.List;
import java.util.Map;

/**
 * @ClassName ResearchUserController
 * Description TODO
 * Author WN
 * Date 2020/6/11 19:36
 **/
@RestController
@RequestMapping("/researchu")
public class ResearchUserController {
    @Autowired
    private ResearchUserService researchUserService;

    /**
     *功能描述 列表--已评论用户列表
     * @author WN
     * @date 2020/6/11
     * @param  * @param research
     * @return com.xhkjedu.vo.ResultVo
     */
    @PostMapping("ulist")
    public ResultVo ulist(@RequestBody TResearch research){
        N_Utils.validation(new Object[]{
                research.getPage(),"显示页码",1,research.getPageSize(),"显示条数",1,
                research.getResearchid(),"教研id",1});

        if(!N_Utils.isNotEmpty(research.getRorder())){
            research.setRorder("stoptime");
        }
        PageHelper.startPage(research.getPage(), research.getPageSize());
        List<Map> list = researchUserService.listRusersByReaearchid(research.getResearchid(),research.getSchoolid());
        PageResult pageResult = PageUtil.getPageResult(new PageInfo(list));
        return new ResultVo(0,"获取教研用户列表成功",pageResult);
    }

    /**
     *功能描述 列表--教师参与教研列表
     * @author WN
     * @date 2020/6/12
     * @param  * @param researchUser
     * @return com.xhkjedu.vo.ResultVo
     */
    @PostMapping("list")
    public ResultVo list(@RequestBody TResearchUser researchUser){
        N_Utils.validation(new Object[]{
                researchUser.getPage(),"显示页码",1,researchUser.getPageSize(),"显示条数",1,
                researchUser.getUserid(),"教师id",1,researchUser.getRorder(),"排序",2});
        PageHelper.startPage(researchUser.getPage(), researchUser.getPageSize());
        List<Map> list = researchUserService.listUserResearchs(researchUser.getUserid(), researchUser.getRorder(), researchUser.getRustate());
        PageResult pageResult = PageUtil.getPageResult(new PageInfo(list));
        return new ResultVo(0,"获取教师教研列表成功",pageResult);
    }


    @PostMapping("other_list")
    public ResultVo otherList(@RequestBody TResearchUser research){
        N_Utils.validation(new Object[]{research.getPage(),"显示页码",1,research.getPageSize(),"显示条数",1,
                research.getUserid(),"用户id",1,research.getResearchid(),"教研id",1});
        PageHelper.startPage(research.getPage(), research.getPageSize());
        List<Map> list = researchUserService.otherList(research);
        PageResult pageResult = PageUtil.getPageResult(new PageInfo(list));
        return new ResultVo(0,"获取其他教研活动列表成功",pageResult);
    }


    /**
     *功能描述  教师--教研详情
     * @author WN
     * @date 2020/6/11
     * @param  * @param research
     * @return com.xhkjedu.vo.ResultVo
     */
    @PostMapping("/detail")
    public ResultVo detail(@RequestBody TResearchUser research){
        N_Utils.validation(new Object[]{
                research.getResearchid(),"教研id",1,
                research.getUserid(),"教师id",1
        });
        ResearchUserVo ruser = researchUserService.getResearchUserDetail(research.getResearchid(),research.getUserid());
        return new ResultVo(0,"获取教师教研详情成功",ruser);
    }

    /**
     *功能描述 教师--保存教研评价
     * @author WN
     * @date 2020/6/12
     * @param  * @param research
     * @return com.xhkjedu.vo.ResultVo
     */
    @PostMapping("/up")
    @Action("教研管理-保存教师教研")
    public ResultVo up(@RequestBody TResearchUser research){
        N_Utils.validation(new Object[]{
                research.getResearchid(),"教研id",1,
                research.getUserid(),"教师id",1,
                research.getContent(),"教研评价内容",2
        });
        Integer result = researchUserService.updateUserResearch(research);
        if(result>0){
            return new ResultVo(0,"保存成功");
        }else{
            return new ResultVo(1,"保存失败");
        }

    }

    @PostMapping("no_evaluated_num")
    public ResultVo noEvaluatedNum(@RequestBody TResearchUser researchUser){
        N_Utils.validation(new Object[]{researchUser.getUserid(),"教师id",1});
        Integer num = researchUserService.noEvaluatedNum(researchUser.getUserid());
        return new ResultVo(0,"获取教师未评价教研数量成功",num);
    }

    /*
     * @Description 删除用户教研
     * @Author WN
     * @Date 2023/8/8 15:39:05
     */
    @PostMapping("deltr")
    @Action("教研管理-删除教师教研")
    public ResultVo delTeacherResearch(@RequestBody TResearchUser ruser){
        N_Utils.validation(new Object[]{ruser.getRuid(),"教师教研id",1,ruser.getUserid(),"当前登录教师id",1});
        return researchUserService.delTeacherResearch(ruser);
    }

    /*
    * @Description 修改自己教研
    * @Author WN
    * @Date 2023/8/8 16:03:54
    */
    @PostMapping("uptr")
    @Action("教研管理-修改教研内容")
    public ResultVo updateTeacherResearch(@RequestBody TResearchUser ruser){
        N_Utils.validation(new Object[]{ruser.getRuid(),"教师教研id",1,ruser.getUserid(),"当前登录教师id",1});
        return researchUserService.updateTeacherResearch(ruser);
    }
}
