package com.jeequan.jeepay.service.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeequan.jeepay.core.entity.PayOrderCount;
import com.jeequan.jeepay.db.entity.Route;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author [mybatis plus generator]
 * @since 2024-04-19
 */
public interface RouteMapper extends BaseMapper<Route> {

    /**
     * 分页查询
     * @param page
     * @param entity
     * @return
     */
    IPage<Route> pageList(@Param("page") Page<Route> page, @Param("entity") Route entity,@Param("date") Date[] dateRange);

    /**
     * 数据统计
     * @param entity
     * @return
     */
    PayOrderCount totalCount(@Param("entity") Route entity,@Param("date") Date[] dateRange);

    /**
     * 更新成功数据
     * @param amount
     * @param routeId
     */
    @Update("UPDATE t_route set succ_num  = succ_num + 1,succ_amount = succ_amount + #{amount} where  route_id = #{routeId}")
    void updateSuccData(@Param("amount") Long amount, @Param("routeId") String routeId);

    /**
     * 更新总数
     * @param amount
     * @param routeId
     */
    @Update("UPDATE t_route set num = num + 1 ,total_num  = total_num + 1,total_amount = total_amount + #{amount} where route_id = #{routeId}")
    void updateTotalData(@Param("amount") Long amount, @Param("routeId") String routeId);

    /**
     * 获取是否默认的路由策略
     * @param mchNo
     * @return
     */
    @Select("SELECT * fROM t_route WHERE is_default = 1 and mch_no = #{mchNo}")
    Route getDefault(String mchNo);
}
