package com.ym.mec.biz.service;

import com.ym.mec.biz.dal.dto.PageInfoOrder;
import com.ym.mec.biz.dal.dto.SporadicChargeInfoDto;
import com.ym.mec.biz.dal.dto.StudentPaymentOrderDto;
import com.ym.mec.biz.dal.dto.StudentPaymentOrderExportDto;
import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
import com.ym.mec.biz.dal.entity.StudentPaymentOrderDetail;
import com.ym.mec.biz.dal.enums.DealStatusEnum;
import com.ym.mec.biz.dal.enums.GroupType;
import com.ym.mec.biz.dal.enums.OrderTypeEnum;
import com.ym.mec.biz.dal.enums.PayStatus;
import com.ym.mec.biz.dal.page.SporadicOrderQueryInfo;
import com.ym.mec.biz.dal.page.StudentPaymentOrderQueryInfo;
import com.ym.mec.biz.dal.vo.StudentPaymentOrderVo;
import com.ym.mec.common.entity.HttpResponseResult;
import com.ym.mec.common.entity.MallCreateOrderModel;
import com.ym.mec.common.entity.OrderCancelModel;
import com.ym.mec.common.page.PageInfo;
import com.ym.mec.common.service.BaseService;
import com.ym.mec.thirdparty.adapay.entity.HfMerchantConfig;
import org.apache.ibatis.annotations.Param;

import java.util.Date;
import java.util.List;
import java.util.Map;

public interface StudentPaymentOrderService extends BaseService<Long, StudentPaymentOrder> {

    Map createOrder(StudentPaymentOrder studentPaymentOrder, List<StudentPaymentOrderDetail> details, String payReceiver) throws Exception;

    /**
     * 查询订单列表
     *
     * @param groupType
     * @param musicGroupId
     * @param userId
     * @param status
     * @param type
     * @return
     */
    List<StudentPaymentOrder> queryByCondition(GroupType groupType, String musicGroupId, Integer userId, DealStatusEnum status, OrderTypeEnum type);

    /**
     * 查询报名缴费订单
     *
     * @param musicGroupId
     * @param status
     * @return
     */
    List<StudentPaymentOrder> findMusicGroupApplyOrderByStatus(Integer userId, String musicGroupId, DealStatusEnum status);

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

    /**
     * 根据批次号查询
     *
     * @param userId  用户编号
     * @param batchNo 批次号
     * @param status  状态
     * @return
     */
    List<StudentPaymentOrder> queryByBatchNo(Integer userId, String batchNo, DealStatusEnum status);

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

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

    void queryOrderStatus() throws Exception;


    /**
     *  检查并修改订单状态
     *
     * @param date
     * @param payConfigMap
     * @param payingOrder
     * @param checkTime
     * @return
     */
    OrderCancelModel updateOrderStatus(Date date, Map<Integer, HfMerchantConfig> payConfigMap, StudentPaymentOrder payingOrder, Boolean checkTime) throws Exception;

    //退优惠券和余额
    void quitCouponAndBalance(StudentPaymentOrder order);

    void updateOrder(Map<String, String> rpMap) throws Exception;

    List<StudentPaymentOrderExportDto> ExportQueryPage(Map<String, Object> params);

    /**
     * 获取零星收费订单列表
     *
     * @param queryInfo
     * @return
     */
    PageInfo<SporadicChargeInfoDto> sporadicQueryPage(SporadicOrderQueryInfo queryInfo);


    PageInfoOrder<StudentPaymentOrderDto> OrderQueryPage(StudentPaymentOrderQueryInfo queryInfo);


    /**
     * 获取订单第三方状态
     *
     * @param id
     * @return
     */
    Boolean getOrderStatus(Long id) throws Exception;

    /**
     * 获取分部支付成功支付中订单数量
     *
     * @param organId
     * @return
     */
    Integer findOrganPayOrderNum(Integer organId);

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


    /**
     * 从新提交分账信息
     *
     * @param startTime
     * @param endTime
     * @return
     */
    List<StudentPaymentOrder> reConfirmOrder(Date startTime, Date endTime);

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

    /**
     * 获取用户支付中的乐器置换订单
     *
     * @param userId
     * @param replacementId
     * @return
     */
    StudentPaymentOrder getUserReplacementIngOrder(Integer userId, Integer replacementId);

    void callOrderCallBack(StudentPaymentOrder order) throws Exception;

    int batchUpdate(List<StudentPaymentOrder> studentPaymentOrderList);

    PayStatus queryPayStatus(StudentPaymentOrder studentPaymentOrder) throws Exception;

    /**
     * 获取购买了乐器的报名订单
     *
     * @param musicGroupId
     * @param studentId
     * @return
     */
    Integer getOrderIdByMusical(@Param("musicGroupId") String musicGroupId, @Param("studentId") Integer studentId);

    /**
     * @param vipGroupActivityId
     * @return void
     * @description: 活动赠送课程，或者会员
     * @author zx
     * @date 2021/10/11 10:36
     */
    Integer activityGive(Integer vipGroupActivityId,
                         StudentPaymentOrder studentPaymentOrder,
                         String vipGroupId,
                         String practiceGroupId,
                         Integer teacherId);

    /**
     * @param order
     * @param repeatPay
     * @return com.ym.mec.common.entity.HttpResponseResult
     * @description: 校验重复支付
     * @author zx
     * @date 2021/12/29 14:50
     */
    HttpResponseResult checkRepeatPay(StudentPaymentOrder order, Boolean repeatPay) throws Exception;

    /**
    * @description: 订单关闭时需要更改已缴费学员数
     * @param order
    * @return void
    * @author zx
    * @date 2022/1/18 13:39
    */
    void cutSubjectPlan(StudentPaymentOrder order);

    PageInfo<StudentPaymentOrderVo> queryOrder(Map<String, Object> param) throws Exception;

    StudentPaymentOrderVo queryOrderDetail(String orderNo);

    List<StudentPaymentOrder> queryByDealStatus(String musicGroupId, OrderTypeEnum orderType, DealStatusEnum status);

    StudentPaymentOrder lockOrder(Long paymentOrderId);

    /**
    * @description: 退还账户余额和优惠券
     * @param studentPaymentOrder
     * @param memo
    * @return void
    * @author zx
    * @date 2022/1/20 16:23
    */
    void returnBalanceAndCoupon(StudentPaymentOrder studentPaymentOrder,String memo);

    //获取云教练订单
    StudentPaymentOrder getMemberIngOrder(OrderTypeEnum member, DealStatusEnum status);

    Map createOrder(MallCreateOrderModel model) throws Exception;

    void mallBuyOrderCallback(StudentPaymentOrder order);

    void mallSaveOrderInfo(MallCreateOrderModel model);

    OrderCancelModel cancelOrder(StudentPaymentOrder orderByOrderNo);
}