package com.yida.data.user.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yida.data.common.core.entity.user.EduParentStudent;
import com.yida.data.user.mapper.EduParentStudentMapper;
import com.yida.data.user.mapper.EduStudentMapper;
import com.yida.data.user.service.EduParentStudentService;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.List;

import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
@Transactional(rollbackFor = Exception.class)
public class EduParentStudentServiceImpl extends ServiceImpl<EduParentStudentMapper, EduParentStudent> implements EduParentStudentService {

    private final EduStudentMapper eduStudentMapper;

    /**
     * 查询数据库中已存在的家长和学生关系数据
     *
     * @param parentId 家长id
     * @return com.yida.data.common.core.common.ResultBean<java.util.List < com.yida.data.common.core.entity.user.EduParentStudent>>
     * @author ZYJ
     * @date 2021/8/21 16:24
     */
    @Override
    public List<EduParentStudent> listParentStudent(Long parentId) {
        // 查询数据库中已存在的家长和学生关系数据
        List<EduParentStudent> eduParentStudentList = this.baseMapper.listParentStudent(parentId);
        // 查询学生企业微信id
        if (!CollectionUtils.isEmpty(eduParentStudentList)) {
            eduParentStudentList.forEach(eduParentStudent -> eduParentStudent.setStudentWxId(this.eduStudentMapper.selectById(eduParentStudent.getStudentId()).getWxId()));
        }
        return eduParentStudentList;
    }
}
