package com.xhkjedu.sstudy.service.resource;

import com.xhkjedu.sstudy.mapper.resource.GuideGroupStudentHistoryMapper;
import com.xhkjedu.sstudy.mapper.resource.GuideGroupStudentMapper;
import com.xhkjedu.sstudy.model.resource.TGuideGroupStudent;
import com.xhkjedu.utils.N_Utils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author ywx
 * @classname TGuideGroupStudentService
 * @description 
 * @date 2020/6/2 17:04
 **/
@Service
public class GuideGroupStudentService {
    @Resource
    private GuideGroupStudentMapper guideGroupStudentMapper;
    @Resource
    private GuideGroupStudentHistoryMapper guideGroupStudentHistoryMapper;

    //更新查看记录
    public Integer updateRead(TGuideGroupStudent student) {
        //修改学生观看记录
        Integer timestamp = N_Utils.getSecondTimestamp();
        student.setReadtime(timestamp);
        int rtn = guideGroupStudentMapper.updateRead(student);

        //保存学生预习记录历史    2021/8/11 10:35改为学生端定时修改学生预习时长，不保存预习历史
        //先获取学生管理记录数据
        /*List<TGuideGroupStudent> ggslist = guideGroupStudentMapper.listGuideGroupStudent(student.getResourceid(),student.getStudentid());
        if(ggslist!=null && ggslist.size()>0){

            List<TGuideGroupStudentHistory> hlist = new ArrayList<>();

            for(TGuideGroupStudent ggs : ggslist){
                TGuideGroupStudentHistory ggsh = new TGuideGroupStudentHistory();
                ggsh.setRgsid(ggs.getRgsid());
                ggsh.setResourceid(ggs.getResourceid());
                ggsh.setClassid(ggs.getClassid());
                ggsh.setStudentid(ggs.getStudentid());
                ggsh.setCosttime(student.getCosttime());
                ggsh.setReadtime(timestamp);
                ggsh.setCreatetime(timestamp);

                hlist.add(ggsh);
            }

            //批量保存学生预习记录历史
            guideGroupStudentHistoryMapper.insertList(hlist);
        }*/
        return rtn;
    }
}
