package com.xhpc.order.mapper;

import com.xhpc.common.domain.XhpcRate;
import com.xhpc.common.domain.XhpcTerminal;
import com.xhpc.order.domain.XhpcChargeOrder;
import com.xhpc.order.domain.XhpcOrderRedisRecord;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

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

/**
 * @author yuyang
 * @date 2021/8/4 9:55
 */
@Mapper
public interface XhpcChargeOrderMapper {


    /**
     * 判断实时订单
     *
     * @param userId
     * @return
     */
    Map<String,Object> getHistotyChargeOrderMessageMap(@Param("userId") Long userId,@Param("tenantId") String tenantId,@Param("userType") Integer userType,@Param("thirdCode")String thirdCode);

    int getHistotyChargeOrderMessage(@Param("userId") Long userId,@Param("tenantId") String tenantIde,@Param("userType") Integer userTyp,@Param("sunchaStatus") Integer sunchaStatus);

    int getUserTypeSunchaSwitch(@Param("userId") Long userId,@Param("tenantId") String tenantId,@Param("userType") Integer userType);



    Map<String,Object> getMessage(@Param("userId") Long userId);
    /**
     * 异常订单
     * @param userId
     * @return
     */
    List<Map<String,Object>> getHistotyChargeOrderStatusList(@Param("userId")Long userId,@Param("tenantId") String tenantId,@Param("userType") Integer userType);


    /**
     * 获取用户信息
     */
    Map<String,Object> getUserMessage(@Param("userId")Long userId);

    /**
     * C端用户修改余额
     * @param userId
     * @param balance
     * @return
     */
    int updateUserBalance(@Param("userId")Long userId, @Param("balance")BigDecimal balance);

    /**
     * 双枪修改金额
     * @param userId
     * @param balance
     * @param sunchaStatus
     * @return
     */
    int updateUserSunchaBalance(@Param("userId")Long userId, @Param("balance")BigDecimal balance, @Param("sunchaStatus")Integer sunchaStatus);

    /**
     * 社区用户修改余额
     * @param userId
     * @param balance
     * @return
     */
    int updateCommunityBalance(@Param("userId")Long userId, @Param("balance")BigDecimal balance);

    /**
     * 双枪修改金额
     * @param userId
     * @param balance
     * @param sunchaStatus
     * @return
     */
    int updateCommunitySunchaBalance(@Param("userId")Long userId, @Param("balance")BigDecimal balance, @Param("sunchaStatus")Integer sunchaStatus);
    /**
     * B端用户修改余额
     * @param userId
     * @param balance
     * @return
     */
    int updateCustomersBalance(@Param("userId")Long userId, @Param("balance")BigDecimal balance);
    /**
     * 双枪修改金额
     * @param userId
     * @param balance
     * @param sunchaStatus
     * @return
     */
    int updateCustomersSunchaBalance(@Param("userId")Long userId, @Param("balance")BigDecimal balance, @Param("sunchaStatus")Integer sunchaStatus);


    /**
     * 更新川逸充用户余额
     */
    public int updateAppInternetUserBalance(@Param("userId")Long userId, @Param("balance")BigDecimal balance);


    /**
     * 更新车队总金额
     */
    public int updateMotorcadeRemainingAmont(@Param("userId")Long userId, @Param("remainingAmount")BigDecimal remainingAmount, @Param("consumptionAmount")BigDecimal consumptionAmount);

    public int updateMotorcadeUserSurplusMoney(@Param("userId")Long userId, @Param("surplusMoney")BigDecimal surplusMoney, @Param("consumeMoney")BigDecimal consumeMoney);


    /**
     * 判断用户是否在充电中
     */
    String countXhpcRealTimeOrder(@Param("userId")Long userId,@Param("source")Integer source,@Param("tenantId")String tenantId);

    /**
     * 判断用户是否有异常订单未处理
     */
    int countXhpcChargeOrder(@Param("userId")Long userId,@Param("source")Integer source,@Param("tenantId")String tenantId);

    /**
     * 获取终端信息
     */
    XhpcTerminal getXhpcTerminalSerialNumber(@Param("serialNumber")String serialNumber,@Param("tenantId")String tenantId);

    /**
     * 添加充电订单
     *
     * @param xhpcChargeOrder
     * @return
     */
    int addXhpcChargeOrder(XhpcChargeOrder xhpcChargeOrder);

    /**
     * 修改充电订单
     *
     * @param xhpcChargeOrder
     * @return
     */
    void updateXhpcChargeOrder(XhpcChargeOrder xhpcChargeOrder);

    /**
     * 获取充电订单数据
     *
     * @param serialNumber 订单编号
     * @return
     */
    XhpcChargeOrder getSerialNumberMessage(@Param("serialNumber") String serialNumber);

    /**
     * 判断用户是第几次充电
     * @param userId
     * @return
     */
    int getCount(@Param("userId") Long userId,@Param("chargeOrderId")Long chargeOrderId,@Param("source")Integer source,@Param("tenantId")String tenantId);

    /**
     * 判断是否内部场站
     */
    int getInternalChargingStation(@Param("chargingStationId") Long chargingStationId);

    int getInternalUserType(@Param("chargingStationId") Long chargingStationId,@Param("source")Integer source,@Param("id") Long id);


    /**
     * 活动
     * @return
     */
    Map<String,Object> getPromotion();

    /**
     * 获取充电订单数据
     *
     * @param chargingOrderId 订单id
     * @return
     */
    XhpcChargeOrder getChargingOrderId(@Param("chargingOrderId") Long chargingOrderId);

    /**
     * 获取运营商信息
     * @param chargingStationId
     * @return
     */
    Map<String,Object> getOperatorMessage(@Param("chargingStationId") Long chargingStationId);

    Map<String,Object> getXhpcUserVehicleMessage(@Param("userId")Long userId,@Param("source")Integer source);

    //获取桩信息
    Map<String,Object> getXhpcChargingPileById(@Param("chargingPileid") Long chargingPileid,@Param("tenantId")String tenantId);

    /**
     * 添加redis数据到数据库
     */
    void addXhpcOrderRedisRecord(XhpcOrderRedisRecord xhpcOrderRedisRecord);

    /**
     * 添加流水
     * @param userId              用户id
     * @param amount              流水金额
     * @param remainingSum        余额
     * @param chargeOrderId       充电订单id
     * @param type                类型（1充值 2退款 3充电）
     * @param date                时间
     * @return
     */
    int insertUserAccountStatement(@Param("userId") Long userId,@Param("amount") BigDecimal amount,@Param("remainingSum") BigDecimal remainingSum,@Param("chargeOrderId") Long chargeOrderId,@Param("type") Integer type,@Param("date") Date date,@Param("source")Integer source);


    int insertUserAccountStatementPlaceholder(@Param("userId") Long userId,@Param("amount") BigDecimal amount,@Param("remainingSum") BigDecimal remainingSum,@Param("placeholderOrderId") Long placeholderOrderId,@Param("type") Integer type,@Param("date") Date date,@Param("source")Integer source);

    /**
     * 获取费率
     */
    List<XhpcRate> getRateModelId(@Param("rateModelId")Long rateModelId);

    /**
     * 获取电桩信息
     * @param terminalId
     * @return
     */
    Map<String, Object> getXhpcChargingPile(@Param("terminalId") Long terminalId);


    /**
     * 获取一次订单
     *
     * @param status -1准备充电 0开始充电 1自动结算，2异常，3平台结算
     * @return
     */
    List<Map<String,Object>> getXhpcChargeOrderStatus(@Param("status") Integer status,@Param("number") Integer number);

    /**
     * insert a row by 3rd.
     *
     * @param internetSerialNumber
     * @param driverId
     * @param chargingAmt
     * @param plateNum
     * @param status
     * @return
     */
    int addBy3rd(@Param(value = "internetSerialNumber") String internetSerialNumber,
                 @Param(value = "serialNum") String serialNum,
                 @Param(value = "driverId") String driverId,
                 @Param(value = "chargingAmt") Integer chargingAmt,
                 @Param(value = "plateNum") String plateNum,
                 @Param(value = "status") Integer status,
                 @Param(value = "createTime") Date createTime,
                 @Param(value = "rateModelId") Long rateModelId,
                 @Param(value = "terminalId") Long terminalId,
                 @Param(value = "power") Double power,
                 @Param(value = "chargingStationId") Long chargingStationId,
                 @Param(value = "chargingMode") String chargingMode,
                 @Param(value = "source") Integer source,
                 @Param(value = "userId") Long userId);

    /**
     * 标记异常大于创建4小时，标记为异常
     */
    void updateStatus(@Param("status")Integer status,@Param("chargeOrderId")Long chargeOrderId,@Param("erroRemark")String erroRemark);

    /**
     * 4小时订单未结算的订单
     * @return
     */
    List<XhpcChargeOrder> getFourTimsStatus();

    List<Map<String, Object>> getChargeOrderStatus();

    void updateStatusNull();

    void updateStatusNegativeOne();
    /**
     * 查询相同桩之后是否有订单结算
     * @param serialNumber   订单号
     * @return
     */
    int getSerialNumberLike(@Param("serialNumber")String serialNumber,@Param("chargeOrderId")Long chargeOrderId);


    List<Map<String, Object>> selectDate3rdNeedBy(@Param(value = "serialNumber") String serialNumber);

    List<Map<String, Object>> select3rdNameBy(@Param(value = "operatorIdEvcs") String operatorIdEvcs);

    Map<String,Object> getSerialNumberOrder(@Param("serialNumber")String serialNumber);


    //查询场站是否有道闸
    Map<String,Object> getXhpcBarrierGate(@Param("chargingStationId")Long chargingStationId);

    //根据VIN码获取用户
    Map<String,Object> getvVinNumber(@Param("vinNumber")String vinNumber,@Param("reverseVinNumber")String reverseVinNumber);

    //获取充电站信息
    Map<String,Object> getChargingStationById(@Param("chargingStationId")Long chargingStationId);

    //修改账户金额C端
    int updateXhpcAppUser(@Param("userId")Long userId,@Param("aBalance")BigDecimal aBalance,@Param("bBalance")BigDecimal bBalance);

    //修改账户金额社区用户
    int updateXhpcCommunityPersonnel(@Param("userId")Long userId,@Param("aBalance")BigDecimal aBalance,@Param("bBalance")BigDecimal bBalance);

    //修改账户金额B端用户
    int updateXhpcCustomersPersonnel(@Param("userId")Long userId,@Param("aBalance")BigDecimal aBalance,@Param("bBalance")BigDecimal bBalance);

    //查询是否可以充电
    int getBlacklistUser(@Param("phone")String phone,@Param("vin")String vin,@Param("plateNnum")String plateNnum,@Param("chargingStationId")Long chargingStationId,@Param("time")String time);

    List<Map<String,Object>> getXhpcTerminalList(@Param("chargingStationId")Long chargingStationId,@Param("chargingPileId")Long chargingPileId,@Param("type")Integer type,@Param("userId")Long userId);


    int getXhpcPlaceholderOrderNumber(@Param("userId")Long userId, @Param("source")Integer source, @Param("terminalId")String terminalId);

    Map<String,Object> getUserOrderMessage(@Param("userId")Long userId,@Param("source") Integer source);

    List<Map<String,Object>> getAutomaticSettlement(@Param("chargingStationIds") List<String> chargingStationIds);


    Map<String,Object> getUserOderMassage(@Param("userId")Long userId,@Param("source") Integer source);

}
