package com.xhkjedu.sapi.service.research;

import com.xhkjedu.sapi.listener.MessageSender;
import com.xhkjedu.sapi.mapper.research.ResearchMapper;
import com.xhkjedu.sapi.mapper.research.ResearchUserMapper;
import com.xhkjedu.sapi.model.research.TResearchUser;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.sapi.vo.research.ResearchUserVo;
import com.xhkjedu.sapi.vo.research.ResearchVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName ResearchUserService
 * Description TODO
 * Author WN
 * Date 2020/6/11 19:34
 **/
@Service
public class ResearchUserService {
    @Autowired
    private ResearchUserMapper researchUserMapper;
    @Autowired
    private ResearchMapper researchMapper;
    @Autowired
    private MessageSender messageSender;

    /**
     *功能描述  参与评论集合
     * @author WN
     * @date 2020/6/11
     * @param  * @param researchid
     * @return java.util.List<com.xhkjedu.model.research.TResearchUser>
     */
    public List<TResearchUser> listRusersByReaearchid(Integer researchid){
        return researchUserMapper.listRusersByReaearchid(researchid);
    }

    /**
     *功能描述 教师--参与教研集合
     * @author WN
     * @date 2020/6/12
     * @param  * @param userid
     * @param rorder
     * @return java.util.List<com.xhkjedu.vo.research.ResearchVo>
     */
    public List<ResearchVo> listUserResearchs(Integer userid,String rorder,Integer rustate){
        return researchUserMapper.listUserResearchs(userid,rorder,rustate);
    }

    /**
     *功能描述 教师--获取教研详情
     * @author WN
     * @date 2020/6/12
     * @param  * @param researchid
     * @return com.xhkjedu.model.research.TResearch
     */
    public ResearchUserVo getResearchUserDetail(Integer researchid,Integer userid){
        ResearchUserVo researchUserVo = researchUserMapper.getResearchUserDetail(researchid,userid);
        //更改阅读次数
        researchMapper.updateReadnum(researchid);

        //视频转换mq
        if (!researchUserVo.getMp4code().equals("h264")) {
            messageSender.convertVideo(researchUserVo.getResearchid(), researchUserVo.getResearchpath());
        }
        return researchUserVo;
    }

    /**
     *功能描述 教师--保存教研评价
     * @author WN
     * @date 2020/6/12
     * @param  * @param ru
     * @return java.lang.Integer
     */
    public Integer updateUserResearch(TResearchUser ru){
        ru.setRustate(1);//状态0未评1已评
        ru.setReviewtime(N_Utils.getSecondTimestamp());
        return researchUserMapper.updateUserResearch(ru);
    }

    /**
     * 其他教研活动列表
     * @Param [research]
     * @Author ywx
     * @Date 2020/6/23 14:24
     * @return java.util.List<com.xhkjedu.vo.research.ResearchVo>
     **/
    public List<ResearchVo> otherList(TResearchUser research) {
        return researchUserMapper.otherList(research);
    }

    /**
     * 教师未评价教研数量
     * @Param [userid]
     * @Author ywx
     * @Date 2020/7/24 10:45
     * @return java.lang.Integer
     **/
    public Integer noEvaluatedNum(Integer userid) {
        return researchUserMapper.noEvaluatedNum(userid);
    }
}
