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

import com.ym.mec.biz.dal.dto.*;
import com.ym.mec.biz.dal.entity.Goods;
import com.ym.mec.biz.dal.entity.Organization;
import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
import com.ym.mec.biz.dal.entity.StudentPaymentRouteOrder;
import com.ym.mec.biz.dal.enums.DealStatusEnum;
import com.ym.mec.biz.dal.enums.GroupType;
import com.ym.mec.biz.dal.enums.OrderDetailTypeEnum;
import com.ym.mec.biz.dal.enums.OrderTypeEnum;
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;

public interface StudentPaymentOrderDao extends BaseDAO<Long, StudentPaymentOrder> {

    StudentPaymentOrder lockOrder(@Param("id") Long id);

    /**
     * 查询商品列表
     *
     * @param musicGroupId
     * @param type
     * @return
     */
    List<Goods> queryApplyGoodsList(@Param("musicGroupId") String musicGroupId, @Param("type") OrderDetailTypeEnum type);

    List<StudentPaymentOrder> queryByCondition(@Param("groupType") GroupType groupType, @Param("musicGroupId") String musicGroupId,
                                               @Param("userId") Integer userId, @Param("status") DealStatusEnum status, @Param("type") OrderTypeEnum type);

    /**
     * @Author: Joburgess
     * @Date: 2019/10/3
     * 根据学生vip课获取缴费订单
     */
    StudentPaymentOrder findByStudentVipGroup(@Param("vipGroupId") Long vipGroupId,
                                              @Param("userId") Integer userId,
                                              @Param("status") String status);

    /**
     * @param vipGroupId:
     * @param userId:
     * @return java.math.BigDecimal
     * @describe 统计学员剩余课时的课程费用
     * @author Joburgess
     * @date 2019/12/3
     */
    BigDecimal sumSurplusCourseFee(@Param("vipGroupId") String vipGroupId,
                                   @Param("userId") Integer userId);

    /**
     * @Author: Joburgess
     * @Date: 2019/10/3
     * 根据学生vip课获取非失败缴费订单
     */
    List<StudentPaymentOrder> findNotFailedOrderByStudentVipGroup(@Param("vipGroupId") Long vipGroupId,
                                                                  @Param("userId") Integer userId);

    /**
     * @param musicGroupId: 乐团编号/vip课编号
     * @return java.lang.Integer
     * @describe 统计报名人数
     * @author Joburgess
     * @date 2019/11/13
     */
    Integer countStudentPaymentNum(@Param("musicGroupId") String musicGroupId);

    /**
     * 查询乐团报名的订单
     *
     * @param userId
     * @param musicGroupId
     * @param status
     * @return
     */
    StudentPaymentOrder findMusicGroupApplyOrderByStatus(@Param("userId") Integer userId, @Param("musicGroupId") String musicGroupId,
                                                         @Param("status") DealStatusEnum status);

    /**
     * 根据订单号查询订单
     *
     * @param orderNo
     * @return
     */
    StudentPaymentOrder findOrderByOrderNo(@Param("orderNo") String orderNo);

    /**
     * 查询指定交易状态的乐团报名的订单信息
     *
     * @param musicGroupId 乐团编号
     * @param type         订单类型
     * @param status       订单状态
     * @return
     */
    List<StudentPaymentOrder> queryByDealStatus(@Param("musicGroupId") String musicGroupId,
                                                @Param("type") OrderTypeEnum type,
                                                @Param("status") DealStatusEnum status);

    /**
     * 查找支付成功和支付中订单
     *
     * @return
     */
    int findPayOrderNum();

    /**
     * 获取学员报名时所购买的商品
     *
     * @param musicGroupId
     * @param userId
     * @return
     */
    List<UserGoodsDto> findGoodsIds(@Param("musicGroupId") String musicGroupId, @Param("userId") Integer userId);

    /**
     * 查询支付中订单
     *
     * @param status
     * @return
     */
    List<StudentPaymentOrder> findOrdersByStatus(@Param("status") DealStatusEnum status, @Param("paymentChannel") String paymentChannel);

    /**
     * 查询支付中超时的订单
     *
     * @param orderNoList
     * @param status
     * @param beforeTime
     * @return
     */
    List<StudentPaymentOrder> findOrdersOverTime(@Param("orderNoList") List<String> orderNoList, @Param("status") DealStatusEnum status, @Param("beforeTime") Date beforeTime);

    /**
     * @param musicGroupId: 乐团编号
     * @param userId:       用户编号
     * @return int
     * @describe 根据乐团和用户编号统计剩余课时
     * @author Joburgess
     * @date 2019/12/4
     */
    int countSurplusCourseByMusicGroupAndUser(@Param("musicGroupId") String musicGroupId, @Param("userId") Integer userId);

    /**
     * @param musicGroupId: 乐团或小课金额
     * @param groupType:
     * @return java.math.BigDecimal
     * @describe 统计乐团或vip课的收入金额
     * @author Joburgess
     * @date 2019/12/4
     */
    BigDecimal sumGroupIncomeFee(@Param("musicGroupId") String musicGroupId,
                                 @Param("groupType") String groupType);

    List<StudentPaymentOrder> findStudentPaymentOrder(@Param("groupType") String groupType, @Param("musicGroupId") String musicGroupId);

    /**
     * 获取零星订单
     *
     * @param userId
     * @param sporadicId
     * @param groupType
     * @param status
     * @return
     */
    Integer findOrderByGroupType(@Param("userId") Integer userId, @Param("sporadicId") Integer sporadicId, @Param("groupType") String groupType, @Param("status") DealStatusEnum status);

    /**
     * @param userId:
     * @param sporadicId:
     * @param groupType:
     * @param status:
     * @return java.util.List<com.ym.mec.biz.dal.entity.StudentPaymentOrder>
     * @describe 获取零星订单
     * @author qnc99
     * @date 2020/12/5 0005
     */
    List<StudentPaymentOrder> findPaymentOrderByGroupType(@Param("userId") Integer userId, @Param("sporadicId") Integer sporadicId, @Param("groupType") String groupType, @Param("status") DealStatusEnum status);

    List<StudentPaymentOrder> findOrderByGroup(@Param("groupId") String groupId,
                                               @Param("groupType") GroupType groupType,
                                               @Param("status") DealStatusEnum status);

    /**
     * 获取订单金额map
     *
     * @param paymentOrderNo
     * @return
     */
    List<Map<Long, BigDecimal>> queryExpectAmount(@Param("paymentOrderNo") List<Long> paymentOrderNo);


    List<StudentPaymentOrder> findFixOrder();

    /**
     * 订单导出
     *
     * @param params
     * @return
     */
    List<StudentPaymentOrderExportDto> ExportQueryPage(Map<String, Object> params);

    /**
     * 获取零星收费订单列表
     *
     * @param queryInfo
     * @return
     */
    List<SporadicChargeInfoDto> sporadicQueryPage(Map<String, Object> queryInfo);

    /**
     * COUNT零星收费订单列表
     *
     * @param params
     * @return
     */
    int countSporadicPage(Map<String, Object> params);

    List<OrderStatisDto> getLuckStatis();

    /**
     * 统计收入信息
     *
     * @param organId
     * @return
     */
    Map<String, Object> queryIncomeStatisticsWithCurrentMonth(@Param("organId") String organId);

    /**
     * @param userId:     用户编号
     * @param vipGroupId: 小课编号
     * @return int
     * @describe 统计学员购买小课成功的订单数量
     * @author Joburgess
     * @date 2020/2/3
     */
    int countUserBuyVipGroupSuccessOrder(@Param("userId") Integer userId,
                                         @Param("vipGroupId") Integer vipGroupId);

    /**
     * @param userId:     用户编号
     * @param vipGroupId: 小课编号
     * @return java.util.List<com.ym.mec.biz.dal.entity.StudentPaymentOrder>
     * @describe 获取学员购买小课的订单
     * @author Joburgess
     * @date 2020/2/5
     */
    List<StudentPaymentOrder> findUserBuyVipGroupOrder(@Param("userId") Integer userId,
                                                       @Param("vipGroupId") Integer vipGroupId);

    /**
     * @param userId:
     * @param groupId:
     * @param groupType:
     * @return java.util.List<com.ym.mec.biz.dal.entity.StudentPaymentOrder>
     * @describe 获取用户的团体订单
     * @author Joburgess
     * @date 2020/2/21
     */
    List<StudentPaymentOrder> findUserGroupOrders(@Param("userId") Integer userId,
                                                  @Param("groupId") String groupId,
                                                  @Param("groupType") GroupType groupType,
                                                  @Param("status") DealStatusEnum orderStatus);

    StudentPaymentOrder getOrderMoneyAmount(Map<String, Object> params);

    List<StudentPaymentOrder> queryPageOrder(Map<String, Object> params);

    /**
     * 统计收款金额
     *
     * @param merNo
     * @return
     */
    BigDecimal sumPerAccountAmount(@Param("merNo") String merNo, @Param("firstDate") Date firstDate);

    /**
     * 统计充值金额
     *
     * @param params
     * @return
     */
    BigDecimal getChargeAmount(Map<String, Object> params);

    /**
     * 统计商户当月收款金额
     *
     * @param merNo
     * @param firstDate
     * @return
     */
    BigDecimal sumAccountAmount(@Param("merNo") String merNo, @Param("firstDate") Date firstDate);

    /**
     * @param groupId:
     * @param groupType:
     * @return int
     * @describe 统计课程组非失败订单数量
     * @author Joburgess
     * @date 2020.06.22
     */
    int countGroupOrderWithoutFailed(@Param("groupId") String groupId,
                                     @Param("groupType") GroupType groupType);

    /**
     * 统计
     *
     * @param sporadicId
     * @return
     */
    Integer countSporadicOrder(Integer sporadicId);

    /*

     */
    Integer findOrganPayOrderNum(@Param("organId") Integer organId);

    List<OrderByTypeExportDto> getOrderByMonthAndType(@Param("organIds") String organIds,
                                                      @Param("orderTypeList") List<OrderTypeEnum> orderTypeList,
                                                      @Param("startTime") Date startTime, @Param("endTime") Date endTime);

    /**
     * 搜索用户
     *
     * @param search
     * @return
     */
    List<BasicUserDto> getUsers(@Param("search") String search);

    /**
     * 获取2020双十一活动统计
     *
     * @return
     */
    List<OrderStatisDto> doubleEleven2020Statis(@Param("organs") List<Organization> organs);

    /**
     * 获取用户某种类型订单成功的数量
     *
     * @param userId
     * @param type
     * @return
     */
    int getUserOrderNumByType(@Param("userId") Integer userId, @Param("orderType") OrderTypeEnum orderType);


    /**
     * 根据ids获取商品
     *
     * @param ids
     * @return
     */
    List<UserGoodsDto> getUserGoods(@Param("ids") String ids);


    /**
     * 获取用户某种类型的订单
     *
     * @param userId
     * @param type
     * @param status
     * @return
     */
    List<StudentPaymentOrder> getUserOrderByType(@Param("userId") Integer userId, @Param("type") OrderTypeEnum type, @Param("status") DealStatusEnum status);

    /**
     * @param params:
     * @return java.util.List<com.ym.mec.biz.dal.dto.StudentVipDouble11Dto>
     * @describe 获取参与双十一的学员
     * @author qnc99
     * @date 2020/11/25 0025
     */
    List<StudentVipDouble11Dto> queryDouble11Students(Map<String, Object> params);

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

    List<StudentVipDouble11Dto> findStudentsDouble11Infos(@Param("studentIds") List<Integer> studentIds);


    /**
     * 获取学生的报名订单
     *
     * @param userId
     * @param musicGroupId
     * @return
     */
    List<StudentPaymentOrderExportDto> getUserApplyOrders(@Param("userId") Integer userId, @Param("musicGroupId") String musicGroupId);

    /**
     * 获取成功的汇付支付的订单
     *
     * @param startTime
     * @param endTime
     * @return
     */
    List<StudentPaymentOrder> getAdaPayOrdersByTime(@Param("startTime") Date startTime, @Param("endTime") Date endTime);
}
