package com.ym.mec.biz.dal.dao;

import com.ym.mec.biz.dal.dto.*;
import com.ym.mec.biz.dal.entity.CourseSchedule;
import com.ym.mec.biz.dal.entity.CourseScheduleTeacherSalary;
import com.ym.mec.biz.dal.entity.TeacherSalaryModifyLog;
import com.ym.mec.biz.dal.enums.GroupType;
import com.ym.mec.biz.dal.enums.TeacherSalaryConfirmStatus;
import com.ym.mec.common.dal.BaseDAO;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

public interface CourseScheduleTeacherSalaryDao extends BaseDAO<Long, CourseScheduleTeacherSalary> {

	/**
	 * @return int
	 * @Author: Joburgess
	 * @Date: 2019/10/10
	 * @params [courseScheduleTeacherSalaries]
	 * @describe 批量插入
	 */
	int batchInsert(List<CourseScheduleTeacherSalary> courseScheduleTeacherSalaries);

	/**
	 * @param courseScheduleIds: 课程编号列表
	 * @return int
	 * @describe 根据课程编号批量删除教师课酬记录
	 * @author Joburgess
	 * @date 2019/10/31
	 */
	int batchDeleteByCourseScheduleIds(@Param("courseScheduleIds") List<Long> courseScheduleIds);

	/**
	 * @return java.util.List<com.ym.mec.biz.dal.dto.VipGroupSalaryDto>
	 * @Author: Joburgess
	 * @Date: 2019/10/11
	 * @params [params]
	 * @describe 获取vip课财务记录
	 */
	List<VipGroupSalaryDto> findVipGroupSalarys(Map<String, Object> params);

	int countVipGroupSalarys(Map<String, Object> params);

	/**
	 * @describe 统计课程对应学生实际缴费金额
	 * @author Joburgess
	 * @date 2019/12/2
	 * @param courseScheduleIds:
	 * @return java.util.List<java.util.Map<java.lang.Integer,java.math.BigDecimal>>
	 */
	List<Map<Integer,BigDecimal>> countActualAmount(@Param("courseScheduleIds") List<Long> courseScheduleIds);

	/**
	 * @return java.util.List<com.ym.mec.biz.dal.entity.TeacherDefaultVipGroupSalary>
	 * @Author: Joburgess
	 * @Date: 2019/10/15
	 * @params [days:天数]
	 * @describe 获取多少天之前的未结算教师课酬记录（vip课）
	 */
	List<CourseScheduleTeacherSalary> findSomeDayAgoTeacherCourseSalaryNoSettlement(@Param("startDate") String startDate,@Param("endDate") String endDate);

	List<CourseScheduleTeacherSalary> findTemp();

	/**
	 * @return java.util.List<com.ym.mec.biz.dal.entity.TeacherDefaultVipGroupSalary>
	 * @Author: Joburgess
	 * @Date: 2019/10/15
	 * @params [days:天数]
	 * @describe 获取多少天之前的未结算教师课酬记录（陪练课课）
	 */
	List<CourseScheduleTeacherSalary> findTeacherCourseSalaryNoSettlement(@Param("startDate") String startDate,@Param("endDate") String endDate);

	/**
	 * 查询老师指定课程的课酬
	 *
	 * @param courseScheduleId
	 * @param teacherId
	 * @return
	 */
	CourseScheduleTeacherSalary queryByCourseScheduleIdAndUserId(@Param("courseScheduleId") Long courseScheduleId, @Param("teacherId") Integer teacherId);

	/**
	 * 批量更新指定老师所教学班级的报酬（课酬、补贴）
	 *
	 * @param classGroupId 班级编号
	 * @param userId       老师编号
	 * @param salary       课酬
	 * @param subsidy      补贴
	 * @param startDateTime      开始时间
	 * @return
	 */
	int batchUpdateWages(@Param("classGroupId") Integer classGroupId, @Param("userId") Integer userId, @Param("salary") BigDecimal salary,
			@Param("subsidy") BigDecimal subsidy, @Param("startDateTime") String startDateTime);

	/**
	 * @param courseScheduleId: 课程编号
	 * @param userIds:          课程关联教师编号
	 * @return int
	 * @describe 批量更新指定班级关联教师预计薪水
	 * @author Joburgess
	 * @date 2019/10/23
	 */
	int batchUpdateTeacherExpectSalary(@Param("courseScheduleId") Integer courseScheduleId,
									   @Param("userIds") List<Integer> userIds);

	/**
	 * @param courseScheduleTeacherSalaries:
	 * @return int
	 * @describe 批量更新教师预计薪水
	 * @author Joburgess
	 * @date 2019/10/23
	 */
	int batchUpdateTeacherExpectSalarys(@Param("courseScheduleTeacherSalaries") List<CourseScheduleTeacherSalary> courseScheduleTeacherSalaries);

	int batchUpdate(@Param("courseScheduleTeacherSalaries") List<CourseScheduleTeacherSalary> courseScheduleTeacherSalaries);

	/**
	 * @describe 更新指定课程的课酬
	 * @author Joburgess
	 * @date 2020.06.10
	 * @param courseIds:
	 * @param salary:
	 * @return int
	 */
	int batchUpdateCourseSalarys(@Param("courseIds") List<Long> courseIds,
								 @Param("salary") BigDecimal salary);

	/**
	 * @describe 根据课程编号与老师编号删除对应教师课酬记录
	 * @author Joburgess
	 * @date 2019/12/2
	 * @param courseScheduleId: 课程编号
	 * @param userIds: 教师编号列表
	 * @return int
	 */
	int batchDeleteByCourseAndTeacher(@Param("courseScheduleId") Long courseScheduleId,
									  @Param("userIds") List<Integer> userIds);

	/**
	 * @param courseScheduleIds:
	 * @param teacherRole:
	 * @return java.util.List<com.ym.mec.biz.dal.dto.BasicUserDto>
	 * @describe 根据班级编号和教师类型获取老师列表
	 * @author Joburgess
	 * @date 2019/10/23
	 */
	List<CourseScheduleTeacherSalary> findByCourseScheduleIdsAndTeacherRole(@Param("courseScheduleIds") List<Integer> courseScheduleIds,
																			@Param("teacherRole") String teacherRole);

	/**
	 * @param courseScheduleIds: 课程编号列表
	 * @return java.util.List<java.util.Map < java.lang.String, java.lang.String>>
	 * @describe 根据课程获取对应乐团结算方式
	 * @author Joburgess
	 * @date 2019/10/24
	 */
	List<Map<String, String>> findMusicGroupSettlementTypeByCourse(@Param("courseScheduleIds") List<Long> courseScheduleIds);

	/**
	 * @param courseScheduleIds: 课程编号列表
	 * @return java.util.List<java.util.Map < java.lang.String, java.lang.Integer>>
	 * @describe 根据课程获取对应乐团的收费类型
	 * @author Joburgess
	 * @date 2019/11/3
	 */
	List<Map<String, Integer>> findMusicGroupChargeTypeByCourse(@Param("courseScheduleIds") List<Long> courseScheduleIds);

	/**
	 * @param courseScheduleIds: 课程编号列表
	 * @return java.util.List<java.util.Map < java.lang.Integer, java.math.BigDecimal>>
	 * @describe 根据课程获取对应的教学点补贴
	 * @author Joburgess
	 * @date 2019/10/24
	 */
	List<Map<Long, BigDecimal>> findCourseSubsidyByCourses(@Param("courseScheduleIds") List<Long> courseScheduleIds);

	/**
	 * 乐团详情--课酬调整--课程教师列表
	 *
	 * @param courseScheduleId
	 * @return
	 */
	List<CourseScheduleTeachersDto> queryTeacherSalary(@Param("courseScheduleId") Long courseScheduleId,
													   @Param("teacherId") Integer teacherId);

	/**
	 * @param courseScheduleIds: 课程编号列表
	 * @return java.util.List<com.ym.mec.biz.dal.entity.CourseScheduleTeacherSalary>
	 * @describe 根据课程获取课程相关的老师课酬记录
	 * @author Joburgess
	 * @date 2019/11/3
	 */
	List<CourseScheduleTeacherSalary> findByCourseSchedules(@Param("courseScheduleIds") List<Long> courseScheduleIds);

	List<CourseScheduleTeacherSalary> findByCourseSchedule(@Param("courseScheduleId") Long courseScheduleId);

	/**
	 * @param courseScheduleIds: 课程编号列表
	 * @return java.util.List<com.ym.mec.biz.dal.entity.CourseScheduleTeacherSalary>
	 * @describe 根据课程获取课程相关的老师未结算课酬记录
	 * @author Joburgess
	 * @date 2019/11/3
	 */
	List<CourseScheduleTeacherSalary> findByCourseSchedulesWithNoSettlement(@Param("courseScheduleIds") List<Long> courseScheduleIds);

	/**
	 * @param classGroupId: 班级编号
	 * @return java.util.List<java.util.Map < java.lang.String, java.math.BigDecimal>>
	 * @describe 统计班级上老师的先上课，线下课课酬
	 * @author Joburgess
	 * @date 2019/11/5
	 */
	List<Map<String, BigDecimal>> countTeacherOnlineOfflineSalaryByClass(@Param("classGroupId") Integer classGroupId);

	/**
	 * count教师薪酬
	 *
	 * @param params
	 * @return
	 */
	int countSalaries(Map<String, Object> params);

	/**
	 * query教师薪酬
	 *
	 * @param params
	 * @return
	 */
	List<TeacherSalaryDto> querySalaries(Map<String, Object> params);

	List<CourseScheduleTeacherSalary> findCourseScheduleTeacherSalaryByMusicGroupId(@Param("musicGroupId") String musicGroupId,
																					@Param("groupType") GroupType groupType);

	/**
	 * @describe 判断指定课程是否已经结算
	 * @author Joburgess
	 * @date 2019/12/5
	 * @param courseScheduleId: 课程编号
	 * @return boolean
	 */
	int checkCourseIsSettlement(@Param("courseScheduleId") Integer courseScheduleId);

	/**
	 * @describe 检测给定的课程是否都已经结算
	 * @author Joburgess
	 * @date 2019/12/5
	 * @param courseScheduleIds: 课程编号列表
	 * @return java.util.List<java.util.Map<java.lang.Integer,java.lang.Integer>>
	 */
	List<Map<Long,Integer>> checkCoursesIsSettlement(@Param("courseScheduleIds") List<Long> courseScheduleIds);
	
	/**
	 * 批量删除
	 * @param musicGroupId
	 * @param groupType
	 * @return
	 */
	int deleteByMusicGroupId(@Param("musicGroupId")String musicGroupId, @Param("groupType")GroupType groupType);


	/**
	 * @describe 获取乐团获取小课的课酬记录
	 * @author Joburgess
	 * @date 2019/12/14
	 * @param groupId:
	 * @param groupType:
	 * @return java.util.List<com.ym.mec.biz.dal.entity.CourseScheduleTeacherSalary>
	 */
	List<CourseScheduleTeacherSalary> findByGroup(@Param("groupId")String groupId, @Param("groupType")String groupType);

	/**
	 * @describe 获取乐团获取小课的课酬记录
	 * @author Joburgess
	 * @date 2019/12/14
	 * @param groupId:
	 * @param groupType:
	 * @return java.util.List<com.ym.mec.biz.dal.entity.CourseScheduleTeacherSalary>
	 */
	List<CourseScheduleTeacherSalary> findByGroupWithNotStart(@Param("groupId")String groupId, @Param("groupType")String groupType);

	List<CourseScheduleTeacherSalary> queryUserNoSettlementListByTypeAndStartClassDate(@Param("userId") Integer userId, @Param("typeList") String typeList,
			@Param("startClassDate") Date startClassDate);

	/**
	 * @describe 根据教师编号获取课酬
	 * @author Joburgess
	 * @date 2020/1/27
	 * @param groupId:
	 * @param groupType:
	 * @param courseType:
	 * @param teacherId:
	 * @return com.ym.mec.biz.dal.entity.CourseScheduleTeacherSalary
	 */
	List<CourseScheduleTeacherSalary> findByTeacher(@Param("groupId") String groupId,
											  @Param("groupType") GroupType groupType,
											  @Param("courseType")CourseSchedule.CourseScheduleType courseType,
											  @Param("teacherIds")List<Integer> teacherIds);

	/**
	 * @describe 获取与指定学生有关联的教师
	 * @author Joburgess
	 * @date 2020/2/3
	 * @param studentId: 学生编号
	 * @param teacherIds: 教师编号列表
	 * @return java.util.List<com.ym.mec.biz.dal.entity.CourseScheduleTeacherSalary>
	 */
	List<CourseScheduleTeacherSalary> findStudentRelateTeachers(@Param("studentId") Integer studentId,
																@Param("teacherIds") List<Integer> teacherIds);

	/**
	 * @describe 统计教师指定团体类型的课程数量
	 * @author Joburgess
	 * @date 2020/2/3
	 * @param teacherIds: 教师编号列表
	 * @param groupType: 课程类型
	 * @return java.util.List<java.util.Map<java.lang.Integer,java.lang.Integer>>
	 */
	List<Map<Integer,Integer>> countTeacherCourses(@Param("teacherIds") List<Integer> teacherIds,
												   @Param("groupType") GroupType groupType);

    void batchUpdateTeacher(@Param("courseScheduleIds") Set<Long> courseScheduleIds, @Param("teacherId") Integer teacherId);

	/**
	 * @describe 根据团体删除班级
	 * @author Joburgess
	 * @date 2020/2/17
	 * @param groupId:
	 * @param groupType:
	 * @return int
	 */
	int deleteByGroup(@Param("groupId") String groupId,
					  @Param("groupType")GroupType groupType);

	/**
	 * 教师乐团课酬列表
	 * @param params
	 * @return
	 */
    List<ExportTeacherSalaryDto> exportMusicTeacherSalary(Map<String, Object> params);

	/**
	 * 教师vip课课酬
	 * @param params
	 * @return
	 */
	List<ExportTeacherSalaryDto> exportVipTeacherSalary(Map<String, Object> params);

	/**
	 * 教师陪练课课酬
	 * @param params
	 * @return
	 */
	List<ExportTeacherSalaryDto> exportPracticeTeacherSalary(Map<String, Object> params);

	/**
	 * 获取未结算的课程
	 * @param courseScheduleIds
	 * @return
	 */
	List<Long> querySettlementScheduleId(String courseScheduleIds);
	
	/**
	 * 获取所有线上课
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	List<TeacherVipSalaryDto> queryOnlineCourseByGroupType(@Param("startDate") String startDate, @Param("endDate") String endDate);
	/**
	 * 该用户是不是这个群组的老师
	 * @param groupId
	 * @param userId
	 * @return
	 */
    Boolean isTeacher(@Param("groupId") Integer groupId, @Param("userId") Integer userId);

	/**
	 * 统计老师授课次数
	 * @param userId
	 * @return
	 */
	Integer countTeacherGiveLesson(Integer userId);

	/**
	 * @describe 获取课酬记录
	 * @author Joburgess
	 * @date 2020/4/15
	 * @param params:
	 * @return java.util.List<com.ym.mec.biz.dal.dto.TeacherCourseSalaryDetail4WebDto>
	 */
	List<TeacherCourseSalaryDetail4WebDto> findIsSettlementCourseSalarys(Map<String, Object> params);

	int countIsSettlementCourseSalarys(Map<String, Object> params);

	/**
	 * @describe 获取老师指定月份的已结算课酬编号
	 * @author Joburgess
	 * @date 2020/4/15
	 * @param teacherId:
	 * @param month:
	 * @return java.util.List<java.lang.Long>
	 */
	List<Long> findTeacherSalaryIdsWithMonth(@Param("teacherId") Integer teacherId,
											 @Param("month") String month);

	/**
	 * @describe 获取指定月份已结算的老师编号
	 * @author Joburgess
	 * @date 2020/4/16
	 * @param month:
	 * @return java.util.List<java.lang.Integer>
	 */
	List<Integer> findIsSettlementTeacherIdsWithMonth(@Param("month") String month);

	/**
	 * @describe 更新指定课酬的确认状态
	 * @author Joburgess
	 * @date 2020/4/15
	 * @param ids:
	 * @param confirmStatus:
	 * @return int
	 */
	int updateTeacherSalaryConfirmStatus(@Param("ids") List<Long> ids,
                                         @Param("confirmStatus") TeacherSalaryConfirmStatus confirmStatus);

	/**
	 * @describe 更新指定课酬的确认状态至已完成
	 * @author Joburgess
	 * @date 2020/4/16
	 * @param ids:
	 * @return int
	 */
	int updateTeacherSalaryConfirmStatusToComplied(@Param("ids") List<Long> ids);

	/**
	 * @describe 统计教师指定月份不同团体类型的课酬
	 * @author Joburgess
	 * @date 2020/4/15
	 * @param month:
	 * @param teacherId:
	 * @return java.util.List<com.ym.mec.biz.dal.dto.CourseTeacherSalaryStatisticsDto>
	 */
	List<CourseTeacherSalaryStatisticsDto> getTeacherGroupTypeSalary(@Param("month") String month,
																 @Param("teacherId") Integer teacherId);

	/**
	 * @describe 统计教师每月的工资
	 * @author Joburgess
	 * @date 2020/4/15
	 * @param teacherId:
	 * @return java.util.List<com.ym.mec.biz.dal.dto.CourseTeacherSalaryStatisticsDto>
	 */
	List<CourseTeacherSalaryStatisticsDto> getTeacherMonthSalarys(@Param("teacherId") Integer teacherId,
																  @Param("year") String year);

    /**
     * @describe 统计指定月份已开启课酬确认的数量
     * @author Joburgess
     * @date 2020/4/16
     * @param month:
     * @return int
     */
    int countOpenConfirmSalarysWithMonth(@Param("month") String month,
										 @Param("confirmStatus") TeacherSalaryConfirmStatus confirmStatus);

    /**
     * @describe 获取课程结算时间
     * @author Joburgess
     * @date 2020.05.07
     * @param courseScheduleIds:
     * @return java.util.List<java.util.Map<java.lang.Long,java.util.Date>>
     */
    List<Map<Long, String>> getCoursesSettlementTime(@Param("courseScheduleIds") List<Long> courseScheduleIds);

	/**
	 * 获取课程是否有课酬
	 * @param courseScheduleIds
	 * @return
	 */
	int getHasTeacherSalaryCount(@Param("courseScheduleIds") List<Long> courseScheduleIds);

	/**
	 * 根据助教主教获取教师列表
	 * @param classGroupId
	 * @return
	 */
    List<Integer> queryTeacherByTeaching(@Param("classGroupId") Integer classGroupId,@Param("teacherRole") String teacherRole);

	/**
	 * 根据助教主教获取教师列表
	 * @param classGroupId
	 * @return
	 */
    Integer queryTeacherByBishop(@Param("classGroupId") Integer classGroupId);

	/**
	 * 获取课程关联的教师列表
	 * @zouxuan
	 * @param courseScheduleIds
	 * @param teacherRole
	 * @return
	 */
	List<Map<Long, String>> queryTeacherIdMap(@Param("courseScheduleIds") List<Long> courseScheduleIds, @Param("teacherRole") String teacherRole);

	/**
	 * @describe 获取指定时间段内已结算的教师课酬记录
	 * @author Joburgess
	 * @date 2020/12/29 0029
	 * @param startDate:
	 * @param endDate:
	 * @return java.util.List<com.ym.mec.biz.dal.entity.CourseScheduleTeacherSalary>
	 */
	List<CourseScheduleTeacherSalary> getIsSalaryWithDate(@Param("startDate") String startDate, @Param("endDate") String endDate);

}
