package com.schoolinout.api.service.impl;

import com.schoolinout.api.domain.vo.Api_StudentInfoVo;
import com.schoolinout.api.domain.vo.Api_StudentListVo;
import com.schoolinout.api.mapper.ApiStudentMapper;
import com.schoolinout.api.service.IApiStudentService;
import com.schoolinout.common.exception.ServiceException;
import com.schoolinout.common.utils.bean.BeanUtils;
import com.schoolinout.system.domain.AccessLog;
import com.schoolinout.system.domain.Student;
import com.schoolinout.system.mapper.AccessLogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author sakura
 * @date 2024/1/10 10:10:06 Wed
 */
@Service
public class ApiStudentServiceImpl implements IApiStudentService {

    @Autowired
    private ApiStudentMapper studentMapper;
    @Autowired
    private AccessLogMapper accessLogMapper;


    @Override
    public Api_StudentInfoVo listStudentEditInfo(Long parentId, Long studentId) {
        Student student = studentMapper.selectEditInfo(studentId);
        if (student == null) {
            throw new ServiceException("没有对应的学生");
        }

        Api_StudentInfoVo infoVo = new Api_StudentInfoVo();
        BeanUtils.copyBeanProp(infoVo, student);
        infoVo.setStudentId(student.getId());

        // 读取进出记录
        AccessLog accessLog = new AccessLog();
        accessLog.setStudentId(studentId);
        List<AccessLog> accessLogs = accessLogMapper.selectAccessLogList(accessLog);
        infoVo.setInoutRecordList(accessLogs);
        return infoVo;
    }

    @Override
    public Student listStudentSimple(Student selectConditionStu) {
        return studentMapper.selectOnlyOne(selectConditionStu);
    }

    @Override
    public List<Api_StudentListVo> listStudent(Long parentId) {
        return studentMapper.selectListByParentId(parentId);
    }


}
