package com.jsowell.pile.service;

import com.jsowell.common.core.domain.ykc.RealTimeMonitorData;
import com.jsowell.common.core.domain.ykc.TransactionRecordsData;
import com.jsowell.pile.domain.OrderBasicInfo;
import com.jsowell.pile.domain.OrderDetail;
import com.jsowell.pile.dto.*;
import com.jsowell.pile.vo.base.OrderAmountDetailVO;
import com.jsowell.pile.vo.base.OrderPeriodAmountVO;
import com.jsowell.pile.vo.lianlian.AccumulativeInfoVO;
import com.jsowell.pile.vo.uniapp.OrderVO;
import com.jsowell.pile.vo.uniapp.PersonPileConnectorSumInfoVO;
import com.jsowell.pile.vo.uniapp.SendMessageVO;
import com.jsowell.pile.vo.web.IndexOrderInfoVO;
import com.jsowell.pile.vo.web.OrderListVO;
import com.jsowell.pile.vo.web.OrderTotalDataVO;
import com.jsowell.wxpay.dto.WeChatRefundDTO;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * 订单Service接口
 *
 * @author jsowell
 * @date 2022-09-30
 */
public interface IOrderBasicInfoService {

	/**
	 * 条件查询订单基础信息
	 * @param info
	 * @return
	 */
	OrderBasicInfo getOrderBasicInfo(OrderBasicInfo info);

	/**
	 * 查询订单列表
	 *
	 * @param dto 订单
	 * @return 订单集合
	 */
	List<OrderListVO> selectOrderBasicInfoList(QueryOrderDTO dto);

	/**
	 * 查询充电中的订单，没有数据权限校验，后管不要用
	 * @param pileSn
	 * @return
	 */
	List<OrderListVO> selectChargingOrder(String pileSn);

	/**
	 * 修改订单
	 *
	 * @param orderBasicInfo 订单
	 * @return 结果
	 */
	int updateOrderBasicInfo(OrderBasicInfo orderBasicInfo);

	/**
	 * 修改订单详情
	 * @param orderDetail
	 * @return
	 */
	int updateOrderDetail(OrderDetail orderDetail);

	// 清订单缓存
	void cleanCacheByOrderCode(String orderCode, String transactionCode);

	/**
	 * 批量删除订单
	 *
	 * @param ids 需要删除的订单主键集合
	 * @return 结果
	 */
	int deleteOrderBasicInfoByIds(Long[] ids);

	/**
	 * 通过订单号查询订单信息
	 *
	 * @param orderCode 订单号
	 * @return
	 */
	OrderBasicInfo getOrderInfoByOrderCode(String orderCode);

	OrderBasicInfo getOrderInfoByTransactionCode(String transactionCode);

	/**
	 * 通过桩号和枪口号查询充电中的状态
	 * @param pileSn 桩编号
	 * @param connectorCode 枪口号
	 * @return
	 */
	OrderBasicInfo queryChargingByPileSnAndConnectorCode(String pileSn, String connectorCode);

	OrderBasicInfo queryChargingByPileConnectorCode(String pileConnectorCode);

	/**
	 * 根据交易记录结算订单
	 * @param data 交易记录数据
	 * @param orderBasicInfo
	 */
	void settleOrder(TransactionRecordsData data, OrderBasicInfo orderBasicInfo);

	/**
	 * 关闭15分钟未支付订单
	 * @return
	 */
	int close15MinutesOfUnpaidOrders();

	/**
	 * 通过订单号查询订单详情
	 *
	 * @param orderCode 订单号
	 * @return 订单详情
	 */
	OrderDetail getOrderDetailByOrderCode(String orderCode);

	List<OrderDetail> getOrderDetailList(List<String> orderCodes);

	/**
	 * 通过会员Id和订单状态查询订单信息
	 *
	 * @param memberId 会员id
	 * @param orderStatusList 订单状态集合
	 * @return
	 */
	List<OrderVO> getListByMemberIdAndOrderStatus(String memberId, List<String> orderStatusList);

	List<OrderVO> getListByMemberIdAndOrderStatus(String memberId, List<String> orderStatusList, LocalDateTime dateTime);

	List<OrderVO> getListByMemberIdAndOrderStatus(String memberId, List<String> orderStatusList, LocalDateTime dateTime, String stationId);

    void tempOrderRefund();

    void realTimeMonitorDataRedis2DB(String transactionCode, String orderCode);

	void updateElecAmount();

	/**
	 * 结算订单退款和用户余额退款调这个方法
	 */
	void weChatRefund(WeChatRefundDTO dto);

	/**
	 * 保存非法订单记录
	 */
	void saveAbnormalOrder(TransactionRecordsData data);

	/**
	 * 获取充电实时数据
	 * @param transactionCode 交易流水号
	 * @return
	 */
	List<RealTimeMonitorData> getChargingRealTimeData(String transactionCode);

	/**
	 * 首页订单数据展示
	 * @param dto 首页信息查询dto
	 * @return
	 */
	List<IndexOrderInfoVO> getIndexOrderInfo(IndexQueryDTO dto);

	/**
	 * 获取超过15分钟的待支付状态订单
	 * @return
	 */
	List<OrderBasicInfo> getUnpaidOrderListOver15Min();

	/**
	 * 根据orderId批量修改订单状态
	 * @param orderIds
	 * @param orderStatus
	 */
	void updateOrderStatusById(List<String> orderIds, String orderStatus);

	/**
	 * 通过订单状态和支付状态 转换订单状态描述
	 * @param orderStatus 订单状态
	 * @param payStatus 支付状态
	 * @return 订单状态描述
	 */
	String transformOrderStatusDescribe(String orderStatus, String payStatus);

	/**
	 * 查询时间段内订单总金额和总用电量
	 */
	OrderTotalDataVO getOrderTotalData(QueryOrderDTO orderBasicInfo);

	/**
	 * 通过订单号查询订单信息（小程序发送消息用）
	 * @param orderCode
	 * @return
	 */
	SendMessageVO selectOrderInfoByOrderCode(String orderCode);

	/**
	 * 充电桩启动失败
	 * @param orderCode
	 * @param failedReasonMsg
	 */
	void chargingPileFailedToStart(String orderCode, String failedReasonMsg);

	/**
	 * 充电桩启动成功
	 * @param orderCode
	 */
	void chargingPileStartedSuccessfully(String orderCode);

	/**
	 * 关闭启动失败的订单
	 */
	void closeStartFailedOrder(String startTime, String endTime);

	List<OrderVO> getListByOrderCodes(List<String> orderCodes);

	/**
	 * 个人桩查询充电数据
	 * @param dto
	 * @return
	 */
	List<PersonPileConnectorSumInfoVO> getAccumulativeInfo(QueryPersonPileDTO dto);

	/**
	 * 修改订单状态为异常（桩离线时调用）
	 *
	 * @param pileSn
	 */
	void updateOrderStatusAsAbnormal(String pileSn);

	List<OrderBasicInfo> getAppointmentOrder(LocalDateTime dateTime);

	Map<String, Object> generateOrderByCard(GenerateOrderDTO dto);

	/**
	 * 联联平台 获取累计数据用
	 * @param dto
	 * @return
	 */
	List<AccumulativeInfoVO> getAccumulativeInfoForLianLian(QueryStationInfoDTO dto);

	/**
	 * 联联平台生成订单
	 * @param dto
	 * @return
	 */
	Map<String, Object> generateOrderForLianLian(QueryStartChargeDTO dto);

	List<OrderAmountDetailVO> queryOrderAmountDetail(List<String> orderCodes);

	List<OrderPeriodAmountVO> transformPeriodAmountByOrderDetail(OrderDetail orderDetail);


	String tempUpdateVirtualAmount(QueryOrderDTO dto);

	/**
	 * 汇付支付 订单退款
	 * @param dto
	 */
	void refundForOrderWithAdapay(WeChatRefundDTO dto);

	/**
	 * 汇付支付 余额退款
	 * @param dto
	 */
	void refundForBalanceWithAdapay(WeChatRefundDTO dto);

	/**
	 * 生成订单日报
	 */
	void generateDailyOrderReports(String stationId);
}
