package com.zhongzheng.modules.user.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.microsoft.schemas.office.visio.x2012.main.SectionType;
import com.zhongzheng.common.utils.DateUtils;
import com.zhongzheng.modules.bank.domain.Exam;
import com.zhongzheng.modules.course.bo.CourseQueryBo;
import com.zhongzheng.modules.face.service.IFaceService;
import com.zhongzheng.modules.goods.service.IGoodsService;
import com.zhongzheng.modules.goods.vo.GoodsUserVo;
import com.zhongzheng.modules.goods.vo.GoodsVo;
import com.zhongzheng.modules.grade.bo.UserPeriodAddBo;
import com.zhongzheng.modules.grade.bo.UserPeriodStatusAddBo;
import com.zhongzheng.modules.grade.domain.UserPeriod;
import com.zhongzheng.modules.grade.domain.UserPeriodStatus;
import com.zhongzheng.modules.grade.service.IUserPeriodService;
import com.zhongzheng.modules.grade.service.IUserPeriodStatusService;
import com.zhongzheng.modules.grade.vo.UserPeriodStatusVo;
import com.zhongzheng.modules.inform.bo.InformRemindQueryBo;
import com.zhongzheng.modules.inform.bo.InformUserAddBo;
import com.zhongzheng.modules.inform.service.IInformRemindService;
import com.zhongzheng.modules.inform.service.IInformUserService;
import com.zhongzheng.modules.inform.vo.InformRemindBusinessVo;
import com.zhongzheng.modules.inform.vo.InformRemindVo;
import com.zhongzheng.modules.user.bo.*;
import com.zhongzheng.modules.user.domain.UserPlan;
import com.zhongzheng.modules.user.domain.UserStudyRecord;
import com.zhongzheng.modules.user.mapper.UserStudyRecordMapper;
import com.zhongzheng.modules.user.service.*;
import com.zhongzheng.modules.user.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.Page;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 用户学习记录Service业务层处理
 *
 * @author ruoyi
 * @date 2021-06-25
 */
@Service
public class UserStudyRecordServiceImpl extends ServiceImpl<UserStudyRecordMapper, UserStudyRecord> implements IUserStudyRecordService {

    @Autowired
    private UserStudyRecordMapper userStudyRecordMapper;


    @Autowired
    private IUserStudyRecordService iUserStudyRecordService;

    @Autowired
    private IUserStudyRecordPhotoService userStudyRecordPhotoService;

    @Autowired
    private IUserPeriodService iUserPeriodService;

    @Autowired
    private IUserPeriodStatusService iUserPeriodStatusService;

    @Autowired
    private IUserPlanService userPlanService;

    @Autowired
    private IInformRemindService iInformRemindService;

    @Autowired
    private IGoodsService iGoodsService;

    @Autowired
    private com.zhongzheng.modules.alisms.service.IAliSmsService IAliSmsService;

    @Autowired
    private IUserService iUserService;

    @Autowired
    private IInformUserService iInformUserService;

    @Value("${aliyun.sms.completionReminderCode}")
    private String completionReminderCode;



    @Override
    public UserStudyRecordVo queryById(Long recordId) {
        UserStudyRecord db = this.baseMapper.selectById(recordId);
        return BeanUtil.toBean(db, UserStudyRecordVo.class);
    }

    @Override
    public UserStudyRecordVo queryLast(UserStudyRecordQueryBo bo) {
        LambdaQueryWrapper<UserStudyRecord> lqw = Wrappers.lambdaQuery();
        lqw.eq(bo.getUserId() != null, UserStudyRecord::getUserId, bo.getUserId());
        lqw.eq(bo.getCourseId() != null, UserStudyRecord::getCourseId, bo.getCourseId());
        lqw.eq(bo.getSectionId() != null, UserStudyRecord::getSectionId, bo.getSectionId());
        lqw.eq(bo.getGoodsId() != null, UserStudyRecord::getGoodsId, bo.getGoodsId());
        lqw.eq(bo.getModuleId() != null, UserStudyRecord::getModuleId, bo.getModuleId());
        lqw.orderByDesc(UserStudyRecord::getRecordId);
        return BeanUtil.toBean(this.getOne(lqw.last("limit 1")), UserStudyRecordVo.class);
    }

    @Override
    public List<UserStudyRecordVo> queryList(UserStudyRecordQueryBo bo) {
        LambdaQueryWrapper<UserStudyRecord> lqw = Wrappers.lambdaQuery();
        lqw.eq(bo.getUserId() != null, UserStudyRecord::getUserId, bo.getUserId());
        lqw.eq(bo.getCourseId() != null, UserStudyRecord::getCourseId, bo.getCourseId());
        lqw.eq(bo.getSectionId() != null, UserStudyRecord::getSectionId, bo.getSectionId());
        lqw.eq(bo.getStudyDuration() != null, UserStudyRecord::getStudyDuration, bo.getStudyDuration());
        lqw.eq(bo.getStartTime() != null, UserStudyRecord::getStartTime, bo.getStartTime());
        lqw.eq(bo.getEndTime() != null, UserStudyRecord::getEndTime, bo.getEndTime());
        return entity2Vo(this.list(lqw));
    }

    @Override
    public List<UserStudyRecordVo> selectList(UserStudyRecordQueryBo bo) {
        return userStudyRecordMapper.selectList(bo);
    }

    /**
     * 实体类转化成视图对象
     *
     * @param collection 实体类集合
     * @return
     */
    private List<UserStudyRecordVo> entity2Vo(Collection<UserStudyRecord> collection) {
        List<UserStudyRecordVo> voList = collection.stream()
                .map(any -> BeanUtil.toBean(any, UserStudyRecordVo.class))
                .collect(Collectors.toList());
        if (collection instanceof Page) {
            Page<UserStudyRecord> page = (Page<UserStudyRecord>) collection;
            Page<UserStudyRecordVo> pageVo = new Page<>();
            BeanUtil.copyProperties(page, pageVo);
            pageVo.addAll(voList);
            voList = pageVo;
        }
        return voList;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Integer insertByAddBo(UserStudyRecordAddBo bo) {
        UserStudyRecord add = BeanUtil.toBean(bo, UserStudyRecord.class);
        validEntityBeforeSave(add);
        add.setCreateTime(DateUtils.getNowTime());
        add.setUpdateTime(DateUtils.getNowTime());
        add.setStartTime(DateUtils.getNowTime() - add.getStudyDuration());
        add.setEndTime(DateUtils.getNowTime());
        this.save(add);
        //新增学时记录,照片
        userPeriodSave(add, bo);
        //完成当天学习计划
        userPlanSave(add);
        //判断有无学习结束
        studyFinish(add);
        return 0;
    }

    private void studyFinish(UserStudyRecord bo) {
        //获得当前所在班级
        if (bo.getStatus() != null && bo.getStatus().equals(1)){
            Long secLong = 0L;
            Long studyLong = 0L;
            SubjectStudyRecordQueryBo subjectStudyRecordQueryBo = new SubjectStudyRecordQueryBo();
            subjectStudyRecordQueryBo.setGoodsId(bo.getGoodsId());
            subjectStudyRecordQueryBo.setUserId(bo.getUserId());
            subjectStudyRecordQueryBo.setGradeId(bo.getGradeId());
            List<SubjectStudyRecordVo> subjectStudyRecordVos = iUserStudyRecordService.listSubject(subjectStudyRecordQueryBo);
            for (SubjectStudyRecordVo subjectStudyRecordVo : subjectStudyRecordVos) {
                secLong = new BigDecimal(secLong.toString()).add(new BigDecimal(subjectStudyRecordVo.getSectionNum().toString())).longValue();
                studyLong = new BigDecimal(studyLong.toString()).add(new BigDecimal(subjectStudyRecordVo.getRecordNum().toString())).longValue();
            }
            //发送课时完成
            if (secLong.equals(studyLong)) {
                InformRemindQueryBo informRemindQueryBo = new InformRemindQueryBo();
                informRemindQueryBo.setSort(8L);
                List<InformRemindVo> list = iInformRemindService.queryList(informRemindQueryBo);
                CourseQueryBo courseQueryBo = new CourseQueryBo();
                courseQueryBo.setGoodsId(bo.getGoodsId());
                GoodsVo goodsVo = iGoodsService.selectUserDetail(courseQueryBo);
                if (!CollectionUtils.isEmpty(list)){
                    InformRemindVo informRemindVo = list.get(0);
                    if (!CollectionUtils.isEmpty(informRemindVo.getInformRemindBusiness())) {
                        for (InformRemindBusinessVo informRemindBusiness : informRemindVo.getInformRemindBusiness()) {
                            if (goodsVo.getBusinessId().equals(informRemindBusiness.getBusinessId())) {
                                if (informRemindVo.getWayStatus().equals(1)) {
                                    InformUserAddBo informUserAddBo = new InformUserAddBo();
                                    informUserAddBo.setUserId(bo.getUserId());
                                    informUserAddBo.setSendStatus(1);
                                    informUserAddBo.setSendTime(DateUtils.getNowTime());
                                    informUserAddBo.setCreateTime(DateUtils.getNowTime());
                                    informUserAddBo.setUpdateTime(DateUtils.getNowTime());
                                    informUserAddBo.setRemindId(8L);
                                    informUserAddBo.setSystemStatus(1);
                                    informUserAddBo.setRemind("学时学习完成提醒");
                                    informUserAddBo.setGoodsId(bo.getGoodsId());
                                    GoodsVo goodsVo1 = iGoodsService.queryById(bo.getGoodsId());
                                    informUserAddBo.setText("尊敬的用户：您购买的"+goodsVo1.getGoodsName()+"课程学时已全部学完，请耐心等待审核学时。");
                                    iInformUserService.insertByAddBo(informUserAddBo);
                                }
                                if (informRemindVo.getNoteStatus().equals(1)){
                                    InformUserAddBo informUserAddBo = new InformUserAddBo();
                                    informUserAddBo.setUserId(bo.getUserId());
                                    informUserAddBo.setSendTime(DateUtils.getNowTime());
                                    informUserAddBo.setSendStatus(1);
                                    informUserAddBo.setCreateTime(DateUtils.getNowTime());
                                    informUserAddBo.setUpdateTime(DateUtils.getNowTime());
                                    informUserAddBo.setRemindId(8L);
                                    informUserAddBo.setSystemStatus(3);
                                    informUserAddBo.setRemind("学时学习完成提醒");
                                    informUserAddBo.setGoodsId(bo.getGoodsId());
                                    GoodsVo goodsVo1 = iGoodsService.queryById(bo.getGoodsId());
                                    informUserAddBo.setText("尊敬的用户：您购买的"+goodsVo1.getGoodsName()+"课程学时已全部学完，请耐心等待审核学时。");
                                    iInformUserService.insertByAddBo(informUserAddBo);
                                    UserVo userVo = iUserService.queryById(bo.getUserId());
                                    Map<String, Object> param = new HashMap<>();
                                    param.put("goods", goodsVo1.getGoodsName());
                                    IAliSmsService.sendInformSms(userVo.getTelphone(), JSON.toJSONString(param), completionReminderCode);
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    @Override
    public Boolean updateByEditBo(UserStudyRecordEditBo bo) {
        UserStudyRecord update = BeanUtil.toBean(bo, UserStudyRecord.class);
        validEntityBeforeSave(update);
        update.setUpdateTime(DateUtils.getNowTime());
        return this.updateById(update);
    }

    /**
     * 保存前的数据校验
     *
     * @param entity 实体类数据
     */
    private void validEntityBeforeSave(UserStudyRecord entity) {
        //TODO 做一些数据校验,如唯一约束
    }


    private void userPeriodSave(UserStudyRecord entity, UserStudyRecordAddBo bo) {
        //记录学时审核
        Long periodId = null;
        // 学习无记录加一条学时审核记录
        if (baseMapper.selectStudyRecord(entity) < 1) {
            UserPeriod userPeriod = new UserPeriod();
            userPeriod.setUserId(entity.getUserId());
            userPeriod.setCourseId(entity.getCourseId());
            userPeriod.setSectionId(entity.getSectionId());
            userPeriod.setGoodsId(entity.getGoodsId());
            userPeriod.setType(1);
            userPeriod.setCreateTime(DateUtils.getNowTime());
            userPeriod.setUpdateTime(DateUtils.getNowTime());
            userPeriod.setModuleId(entity.getModuleId());
            userPeriod.setChapterId(entity.getChapterId());
            userPeriod.setGradeId(entity.getGradeId());
            iUserPeriodService.save(userPeriod);
            periodId = userPeriod.getId();
            UserPeriodStatus userPeriodStatusAddBo = new UserPeriodStatus();
            userPeriodStatusAddBo.setPeriodStatus(1);
            userPeriodStatusAddBo.setStatus(2);
            userPeriodStatusAddBo.setRecordStartTime(entity.getStartTime());
            if (entity.getStatus() != null && entity.getStatus() == 1) {
                userPeriodStatusAddBo.setRecordEndTime(entity.getEndTime());
            }
            userPeriodStatusAddBo.setPeriodId(userPeriod.getId());
            userPeriodStatusAddBo.setCreateTime(DateUtils.getNowTime());
            userPeriodStatusAddBo.setUpdateTime(DateUtils.getNowTime());
            iUserPeriodStatusService.save(userPeriodStatusAddBo);
        } else {
            //待审有结束时间跳过下面两步
            if (baseMapper.selectPeriod(entity) < 1) {
                //有学习记录时审核记录0作弊或3待重修更改为待审核，完整播放也添加结束时间
                UserPeriodStatus userPeriodStatus = baseMapper.selectPeriodCount(entity);
                if (userPeriodStatus.getStatus() == 0) {
                    userPeriodStatus.setPeriodStatus(0);
                    iUserPeriodStatusService.updateById(userPeriodStatus);
                    UserPeriodStatus userPeriodStatusAddBo = new UserPeriodStatus();
                    userPeriodStatusAddBo.setPeriodStatus(1);
                    userPeriodStatusAddBo.setStatus(2);
                    userPeriodStatusAddBo.setPeriodId(userPeriodStatus.getPeriodId());
                    userPeriodStatusAddBo.setRecordStartTime(entity.getStartTime());
                    userPeriodStatusAddBo.setCreateTime(DateUtils.getNowTime());
                    userPeriodStatusAddBo.setUpdateTime(DateUtils.getNowTime());
                    if (entity.getStatus() != null && entity.getStatus() == 1) {
                        userPeriodStatusAddBo.setRecordEndTime(entity.getEndTime());
                    }
                    iUserPeriodStatusService.save(userPeriodStatusAddBo);
                    periodId = userPeriodStatusAddBo.getId();
                } else if (userPeriodStatus.getStatus() == 3) {
                    userPeriodStatus.setPeriodStatus(1);
                    userPeriodStatus.setStatus(2);
                    userPeriodStatus.setRecordStartTime(entity.getStartTime());
                    userPeriodStatus.setCreateTime(DateUtils.getNowTime());
                    userPeriodStatus.setUpdateTime(DateUtils.getNowTime());
                    if (entity.getStatus() != null && entity.getStatus() == 1) {
                        userPeriodStatus.setRecordEndTime(entity.getEndTime());
                    }
                    iUserPeriodStatusService.updateById(userPeriodStatus);
                    periodId = userPeriodStatus.getId();
                }
                if (userPeriodStatus.getStatus() == 2) {
                    //有学习记录完整播放且为待审添加结束时间
                    userPeriodStatus.setPeriodStatus(1);
                    userPeriodStatus.setStatus(2);
                    userPeriodStatus.setRecordStartTime(entity.getStartTime());
                    userPeriodStatus.setCreateTime(DateUtils.getNowTime());
                    userPeriodStatus.setUpdateTime(DateUtils.getNowTime());
                    if (entity.getStatus() != null && entity.getStatus() == 1) {
                        userPeriodStatus.setRecordEndTime(entity.getEndTime());
                    }
                    iUserPeriodStatusService.updateById(userPeriodStatus);
                    periodId = userPeriodStatus.getId();
                }
            }
        }
        //记录照片
        if (bo.getPhoto() != null) {
            UserStudyRecordPhotoAddBo userStudyRecordPhotoAddBo = new UserStudyRecordPhotoAddBo();
            userStudyRecordPhotoAddBo.setPhoto(bo.getPhoto());
            userStudyRecordPhotoAddBo.setRecordId(entity.getRecordId());
            userStudyRecordPhotoAddBo.setPeriodId(periodId);
            userStudyRecordPhotoService.insertByAddBo(userStudyRecordPhotoAddBo);
        }
    }

    private void userPlanSave(UserStudyRecord entity) {
        //搜索该用户得商品有没有计划没有跳过，完整播放且计划里没有该学习记录更新学习计划状态
        if (baseMapper.userPlanSave(entity.getGoodsId()) > 0 && entity.getStatus().equals(1)) {
            Long planId = baseMapper.userPlanSaveId(entity.getGoodsId());
            entity.setPlanId(planId);
            if (baseMapper.selectPland(entity) < 1) {
                this.updateById(entity);
                List<Long> goodsIds = baseMapper.getPlanGoods(planId);
                //更新计划
                UserPlanQueryBo userPlanQueryBo = new UserPlanQueryBo();
                userPlanQueryBo.setPlanId(planId);
                userPlanQueryBo.setUserId(entity.getUserId());
                UserPlanVo userPlanVo = userPlanService.queryById(userPlanQueryBo);
                Calendar rightNow = Calendar.getInstance();
                boolean status = true;
                //得到日历日期
                List<CalendarStudyVo> calendarStudyVo = userPlanVo.getCalendarStudyVo();
                calendarStudyVo = calendarStudyVo.stream().filter(CalendarStudyVo -> CalendarStudyVo.getMonth().equals(rightNow.get(Calendar.MONTH) + 1)).collect(Collectors.toList());
                //对比今天学习的数量是否更新完成
                if (CollectionUtils.isNotEmpty(calendarStudyVo)) {
                    for (CalendarStudyVo studyVo : calendarStudyVo) {
                        List<DayStudyVo> collect = studyVo.getDayStudyList();
                        collect = studyVo.getDayStudyList().stream().filter(dayStudyVo -> dayStudyVo.getDate().equals(rightNow.get(Calendar.DAY_OF_MONTH))).collect(Collectors.toList());
                        for (DayStudyVo dayStudyVo : collect) {
                            for (DaySectionVo daySectionVo : dayStudyVo.getDaySectionList()) {
                                Long count = baseMapper.selectPlandCount(daySectionVo.getGoodsId(), entity.getPlanId());
                                if (count < daySectionVo.getStudyGoodsKnob()) {
                                    status = false;
                                }
                            }
                        }
                    }
                    if (status) {
                        List<CalendarStudyVo> calendarStudyUp = userPlanVo.getCalendarStudyVo();
                        for (CalendarStudyVo studyVo : calendarStudyUp) {
                            if (studyVo.getMonth().equals((rightNow.get(Calendar.MONTH) + 1)) && studyVo.getYear().equals(rightNow.get(Calendar.YEAR))) {
                                for (DayStudyVo dayStudyVo : studyVo.getDayStudyList()) {
                                    if (dayStudyVo.getDate().equals(Calendar.DAY_OF_MONTH)) {
                                        dayStudyVo.setPerform(1);
                                        for (DaySectionVo daySectionVo : dayStudyVo.getDaySectionList()) {
                                            daySectionVo.setGoodsPerform(1);
                                        }
                                    }
                                }
                            }
                        }
                        UserPlan userPlan = new UserPlan();
                        userPlan.setSchedule(JSON.toJSONString(calendarStudyUp));
                        userPlan.setPlanId(userPlanVo.getPlanId());
                        userPlanService.updateById(userPlan);
                    }
                }
            }
        }
    }

    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if (isValid) {
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return this.removeByIds(ids);
    }

    @Override
    public List<UserStudyRecord> selectUserStudy(Long userId, Integer courseId) {
        return baseMapper.selectUserStudy(userId, courseId);
    }

    @Override
    public List<GoodsStudyRecordVo> queryGoods(UserQueryBo bo) {
        List<GoodsStudyRecordVo> list = baseMapper.queryGoods(bo);

        for (GoodsStudyRecordVo goodsStudyRecordVo : list) {
            Long secLong = 0L;
            Long studyLong = 0L;

            SubjectStudyRecordQueryBo subjectStudyRecordQueryBo = new SubjectStudyRecordQueryBo();
            subjectStudyRecordQueryBo.setGoodsId(goodsStudyRecordVo.getGoodsId());
            subjectStudyRecordQueryBo.setUserId(goodsStudyRecordVo.getUserId());
            List<SubjectStudyRecordVo> subjectStudyRecordVos = iUserStudyRecordService.listSubject(subjectStudyRecordQueryBo);
            for (SubjectStudyRecordVo subjectStudyRecordVo : subjectStudyRecordVos) {
                String sectionType = "";
                secLong = new BigDecimal(secLong.toString()).add(new BigDecimal(subjectStudyRecordVo.getSectionNum().toString())).longValue();
                studyLong = new BigDecimal(studyLong.toString()).add(new BigDecimal(subjectStudyRecordVo.getRecordNum().toString())).longValue();

                if (CollectionUtils.isNotEmpty(baseMapper.sectionType(subjectStudyRecordVo.getCourseId(), 1L))) {
                    sectionType = sectionType.concat("1,");
                }
                if (CollectionUtils.isNotEmpty(baseMapper.sectionType(subjectStudyRecordVo.getCourseId(), 2L))) {
                    sectionType = sectionType.concat("2,");
                }
                if (CollectionUtils.isNotEmpty(baseMapper.sectionType(subjectStudyRecordVo.getCourseId(), 3L))) {
                    sectionType = sectionType.concat("3,");
                }
                if (StringUtils.isNotBlank(sectionType)) {
                    subjectStudyRecordVo.setSectionType(sectionType.substring(0, sectionType.length() - 1));
                }
            }
            BigDecimal divide = new BigDecimal("0");
            if (secLong != 0) {
                divide = new BigDecimal(studyLong.toString()).divide(new BigDecimal(secLong.toString()), 2, BigDecimal.ROUND_HALF_UP);
            }
            goodsStudyRecordVo.setStudyNum(divide.multiply(new BigDecimal("100")).longValue());
            goodsStudyRecordVo.setSubjectStudyRecordVos(subjectStudyRecordVos);
            goodsStudyRecordVo.setSecAllNum(secLong);
            goodsStudyRecordVo.setStuAllNum(studyLong);
        }

        return list;
    }

    @Override
    public List<SubjectStudyRecordVo> listSubject(SubjectStudyRecordQueryBo bo) {
        List<SubjectStudyRecordVo> subjectStudyRecordVos = baseMapper.listSubject(bo);
        return subjectStudyRecordVos;
    }

    @Override
    public List<SectionStudyRecordVo> listSection(SubjectStudyRecordQueryBo bo) {
        List<SectionStudyRecordVo> sectionStudyRecordVos = baseMapper.listSection(bo);
        for (SectionStudyRecordVo sectionStudyRecordVo : sectionStudyRecordVos) {
            if (sectionStudyRecordVo.getStartTime() == null) {
                sectionStudyRecordVo.setStatus(2L);
            }
        }
        return sectionStudyRecordVos;
    }

    @Override
    public List<ExamStudyRecordVo> querExamStudy(UserQueryBo bo) {
        List<ExamStudyRecordVo> examStudyRecordVos = baseMapper.querExamStudy(bo);
        for (ExamStudyRecordVo examStudyRecordVo : examStudyRecordVos) {
            SubjectStudyRecordQueryBo subjectStudyRecordQueryBo = new SubjectStudyRecordQueryBo();
            subjectStudyRecordQueryBo.setUserId(examStudyRecordVo.getUserId());
            subjectStudyRecordQueryBo.setGoodsId(examStudyRecordVo.getGoodsId());
            List<ExamSonStudyRecordVo> examSonStudyRecordVos = baseMapper.listExamSon(subjectStudyRecordQueryBo);
            for (ExamSonStudyRecordVo examSonStudyRecordVo : examSonStudyRecordVos) {
                List<String> examTypes = baseMapper.examTypes(examSonStudyRecordVo.getQuestionId());
                String s = "";
                for (String examType : examTypes) {
                    if (StringUtils.isNotBlank(examType)) {
                        s = s.concat(examType + ",");
                    }
                }
                if (StringUtils.isNotBlank(s)) {
                    examSonStudyRecordVo.setExamType(s.substring(0, s.length() - 1));
                }
            }
            examStudyRecordVo.setExamSonStudyRecordVos(examSonStudyRecordVos);
        }
        return examStudyRecordVos;
    }

    @Override
    public List<ExamSonStudyRecordVo> listExamSon(SubjectStudyRecordQueryBo bo) {
        List<ExamSonStudyRecordVo> examSonStudyRecordVos = baseMapper.listExamSon(bo);

        return examSonStudyRecordVos;
    }
}
