package com.xhkjedu.sstudy.service.resource;

import com.xhkjedu.sstudy.mapper.resource.GuideGroupMapper;
import com.xhkjedu.sstudy.model.resource.TGuideGroup;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.sstudy.vo.resource.GuideGroupStudentVo;
import com.xhkjedu.sstudy.vo.resource.GuideGroupVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ywx
 * @classname TGuideGroupService
 * @description 
 * @date 2020/6/2 17:04
 **/
@Service
public class GuideGroupService {
    @Resource
    private GuideGroupMapper guideGroupMapper;

    //添加
    public Integer batchSave(List<TGuideGroup> list) {
        return guideGroupMapper.insertList(list);
    }

    //导学分析
    public List <GuideGroupVo> findAll(TGuideGroup group) {
        List<GuideGroupVo> list = guideGroupMapper.findAll(group);
        for (GuideGroupVo guideGroupVo : list) {
            Integer groupnum = guideGroupVo.getGroupnum();//分组人数
            List<GuideGroupStudentVo> students = guideGroupVo.getStudents();
            Integer yyxnum = 0;//已预习人数
            for (GuideGroupStudentVo student : students) {
                if (student.getCosttime() > 0){
                    yyxnum ++;
                }
            }
            guideGroupVo.setYyxnum(yyxnum);
            guideGroupVo.setWyxnum(groupnum-yyxnum);//未预习人数
            guideGroupVo.setScale(N_Utils.getIntegerDivideAndMulitiply(yyxnum,groupnum));//预习比例向下取整
        }
        return list;
    }
}
