package com.ym.mec.biz.service;

import com.ym.mec.biz.dal.dto.*;
import com.ym.mec.biz.dal.entity.*;
import com.ym.mec.biz.dal.enums.ClassGroupTypeEnum;
import com.ym.mec.biz.dal.page.StudentRegistrationQueryInfo;
import com.ym.mec.common.page.PageInfo;
import com.ym.mec.common.service.BaseService;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

public interface StudentRegistrationService extends BaseService<Long, StudentRegistration> {

    /**
     * 获取乐团学员报名详情
     *
     * @param queryInfo
     * @return
     */
    PageInfo<StudentApplyDetailDto> queryStudentDetailPage(StudentRegistrationQueryInfo queryInfo);

    /**
     * 批量调剂
     *
     * @param userId
     * @param subId
     * @return
     */
    Integer batchUpdateSubject(Integer userId, Integer subId, String musicGroupId) throws Exception;

    /**
     * 学生报名缴费金额详情
     *
     * @param studentId
     * @param musicGroupId
     * @return
     */
    StudentFeeDetailDto queryFeeDetail(Integer studentId, String musicGroupId);

    /**
     * 获取未分配的班级的学生
     *
     * @param musicGroupId    乐团id
     * @param actualSubjectId 科目id
     * @return
     */
    List<Map<String, Object>> getNoClassStuBySubjectId(String musicGroupId, String actualSubjectId);

    /**
     * 获取乐团声部未分配学生统计
     *
     * @param musicGroupId
     * @return
     */
    List<MusicGroupSubjectPlan> getNoClassStuCountByMusicGroupId(String musicGroupId);

    /**
     * 根据user_id 和 乐团id更新
     *
     * @param studentRegistration
     * @return
     */
    Integer updateByUserIdAndMusicGroupId(StudentRegistration studentRegistration);

    /**
     * 添加学生报名信息
     *
     * @param studentRegistration
     * @return
     */
    StudentRegistration addStudent(StudentRegistration studentRegistration) throws Exception;

    /**
     * 查询学生信息
     *
     * @param userId
     * @return
     */
    StudentInfo queryStudentInfo(Integer userId);

    /**
     * 学生注册缴费订单
     *
     * @param studentRegistration
     * @param amount
     * @param courseFee
     * @param goodsGroups
     * @param goodsList
     * @return
     */
    StudentPaymentOrder addOrder(StudentRegistration studentRegistration, BigDecimal amount, String orderNo, String paymentChannel, BigDecimal courseFee,
                                 List<MusicGroupSubjectGoodsGroup> goodsGroups, List<Goods> goodsList, List<Goods> otherGoodsList, List<CourseFormDto> courseForms,
                                 BigDecimal remitFee, BigDecimal courseRemitFee, List<MusicGroupPaymentCalenderCourseSettings> newCourses) throws Exception;

    /**
     * 学生注册缴费重新下订单
     *
     * @param userId
     * @param amount
     * @param courseFee
     * @param goodsGroups
     * @param goodsList
     * @return
     */
    StudentPaymentOrder reAddOrder(
            Integer userId, BigDecimal amount, String orderNo, String paymentChannel, BigDecimal courseFee,
            List<MusicGroupSubjectGoodsGroup> goodsGroups, List<Goods> goodsList, List<Goods> otherGoodsList,
            String musicGroupId, StudentPaymentOrder oldOrder, List<CourseFormDto> courseForms, BigDecimal remitFee, BigDecimal courseRemitFee, List<MusicGroupPaymentCalenderCourseSettings> newCourses) throws Exception;

    /**
     * 查询用户指定乐团的报名信息
     *
     * @param userId       用户编号
     * @param musicGroupId 乐团编号
     * @return
     */
    StudentRegistration queryByUserIdAndMusicGroupId(Integer userId, String musicGroupId);

    /**
     * 根据乐团id，手机查询乐团注册信息
     *
     * @param musicGroupId
     * @param parentsPhone
     * @return
     */
    StudentRegistration getByPhoneAndMusicGroupId(String musicGroupId, String parentsPhone);

    /**
     * 乐团插入新学员
     *
     * @param studentAddDto
     * @return
     */
    Integer insertStudent(StudentAddDto studentAddDto) throws Exception;

    /**
     * 跨团合班进行中加学员
     * @param studentIds 学员列表
     * @param oldMusicGroupId 原乐团
     * @param newMusicGroupId 主乐团
     * @return
     */
    void insertStudent(String studentIds,String oldMusicGroupId,String newMusicGroupId,Map<Integer, List<MusicGroupPaymentCalenderStudentDetail>> collect);

    /**
     * 获取班级学生
     *
     * @param musicGroupId
     * @param classGroupId
     * @return
     */
    List<StudentRegistration> findClassGroupStu(String musicGroupId, Integer classGroupId);


    /**
     * 更新报名订单
     *
     * @param studentPaymentOrder
     * @return
     */
    StudentPaymentOrder updateApplyOrder(StudentPaymentOrder studentPaymentOrder) throws Exception;

    /**
     * 获取乐团科目的学生
     *
     * @param musicGroupId    乐团id
     * @param actualSubjectId 科目id
     * @return
     */
    List<StudentRegistration> findMusicGroupNoClassGroupStudent(String musicGroupId, Integer actualSubjectId);

    /**
     * 根据id list 查询报名学生
     *
     * @param idList
     * @return
     */
    List<StudentRegistration> findStudentListByIdList(List<Long> idList);

    /**
     * 批量插入
     *
     * @param studentRegistrationList
     * @return
     */
    int batchInsert(List<StudentRegistration> studentRegistrationList);


    /**
     * 根据userId 和班级id查询学生
     *
     * @param userId
     * @param classGroupId
     * @return
     */
    StudentRegistration findStudentByClassGroupIdAndUserId(Integer userId, Integer classGroupId);


    /**
     * 查询乐团声部下的学生
     *
     * @return
     */
    List<StudentRegistration> findMusicGroupStudent(String musicGroupId, String actualSubjectId);

    /**
     * 查询乐团userIdList的学生
     *
     * @param musicGroupId
     * @param userIdList
     * @return
     */
    List<StudentRegistration> findStudentListByUserIdList(String musicGroupId, List<Integer> userIdList);

    /**
     * 开启缴费
     *
     * @param ids
     * @return
     */
    int openPayment(String ids) throws IOException;

    /**
     * 根据乐团编号获取已缴费学员列表
     *
     * @param musicGroupId
     * @return
     */
    List<StudentRegistration> queryStudentByMusicGroupId(String musicGroupId);

    /**
     * 根据家长的手机号列表，获取用户编号
     *
     * @param parentPhones
     * @return
     */
    List<Map<Integer, String>> findParentId(String parentPhones);

    /**
     * 更新用户注册信息
     *
     * @param studentRegistration
     * @return
     */
    StudentRegistration updateStudent(StudentRegistration studentRegistration);

    /**
     * 获取学员基本信息
     *
     * @param mobile
     * @return
     */
    StudentRegistration queryUserByPhone(String mobile);

    /**
     * 获取没有某种班级类型的学生
     *
     * @param musicGroupId
     * @param type
     * @param subjectId
     * @return
     */
    List<StudentRegistration> findMusicGroupStuNoClassType(String musicGroupId, Long classGroupId, ClassGroupTypeEnum type, String subjectIds);

    /**
     * 获取乐团下所有学员身上的声部列表
     *
     * @param musicGroupId
     * @return
     */
    List<Subject> findMusicGroupAllStudentSubjects(String musicGroupId);

    /**
     * 获取学员详情页，包含所在乐团信息
     *
     * @param studentId
     * @return
     */
    StudentMusicDetailDto getStudentDetail(Integer studentId);

    /**
     * 获取学生
     *
     * @param studentId
     * @param musicGroupId
     * @return
     */
    List<StudentPaymentOrderDetail> getStudentApplyDetail(Integer studentId, String musicGroupId);

    /**
     * 更换学生声部
     *
     * @param musicGroup
     * @param originalSubjectId
     * @param changeSubjectId
     * @return
     */
    StudentRegistration changeStudentSubject(Integer studentId, String musicGroupId, Integer originalSubjectId, Integer changeSubjectId);


    /**
     * 获取班级未上课程的价值
     * @param classGroupIds
     * @return
     */
    BigDecimal getClassGroupCourseExpectPrice(List<Integer> classGroupIds);

    /**
     * @describe 更新学生乐团可用课程余额
     * @author qnc99
     * @date 2020/12/2 0002
     * @param userId:
     * @param amount:
     * @param memo:
     * @param operatorId:
     * @return boolean
     */
    BigDecimal updateUserSurplusCourseFee(Integer userId, String musicGroupId, BigDecimal amount, String memo, Integer operatorId);
    
    /**
     * 查询指定学生的乐团信息
     * @param userId
     * @return
     */
    List<StudentMusicGroupDto> queryStudentMusicGroupInfo(Integer userId);


    /**
     * 删除学生报名
     * @param id
     * @return
     */
    Boolean delReg(Long id);


    /**
     * 批量删除报名的学生
     * @param userIds
     * @return
     */
    Boolean batchDelRegs(String musicGroupId,List<Integer> userIds);


    /**
     * 获取乐团学员剩余课程金额
     * @param musicGroupId
     * @return
     */
    List<StudentRegistration> getMusicGroupStuReBack(String musicGroupId);

}
