package cn.iocoder.yudao.module.base.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.iocoder.yudao.module.base.service.DlDriveSchoolCoachService;
import cn.iocoder.yudao.module.base.service.DlDriveSchoolStaffService;
import cn.iocoder.yudao.module.base.service.DlDriveSchoolStudentService;
import cn.iocoder.yudao.module.base.vo.DlDriveSchoolStaffVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

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

/**
 * 驾校人员管理通用接口实现类
 *
 * @author pqz
 */
@Service
@Validated
public class DlDriveSchoolStaffServiceImpl implements DlDriveSchoolStaffService {

    @Resource
    private DlDriveSchoolCoachService coachService;
    @Resource
    private DlDriveSchoolStudentService studentService;


    /**
     * 分页获取人员信息
     *
     * @param staffVO {@link DlDriveSchoolStaffVO}
     * @param page    分页参数
     * @return com.baomidou.mybatisplus.core.metadata.IPage<cn.iocoder.yudao.module.base.vo.DlDriveSchoolStaffVO>
     * @author PQZ
     * @date 13:50 2025/2/6
     **/
    @Override
    public IPage<DlDriveSchoolStaffVO> pageStaff(DlDriveSchoolStaffVO staffVO, Page<DlDriveSchoolStaffVO> page) {
        IPage<DlDriveSchoolStaffVO> staffVOIPage = null;
        if ("student".equals(staffVO.getType())){
            //学生
            staffVOIPage = studentService.pageStaffStudent(staffVO,page);
        } else {
            //教练和员工
            staffVOIPage = coachService.pageStaffCoach(staffVO,page);
            staffVOIPage.getRecords().forEach(item->{
                if(null!=item.getCarRegisterDate()){
                    //计算车龄
                    Long carOld = DateUtil.betweenYear(item.getCarRegisterDate(),new Date(),true);
                    item.setCarOld(carOld);
                }
            });
        }
        return staffVOIPage;
    }
}