package com.sqx.modules.errand.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sqx.modules.address.entity.Address;
import com.sqx.modules.app.entity.UserEntity;
import com.sqx.modules.errand.entity.ErrandAddress;
import com.sqx.modules.errand.entity.ErrandRedPacket;
import com.sqx.modules.errand.entity.TbIndent;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

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

@Mapper
public interface TbIndentDao extends BaseMapper<TbIndent> {

    IPage<TbIndent> findNewIndent(Page<TbIndent> pages, double riderLng, double riderLat, double distances, String indentType);

    IPage<TbIndent> findNewIndentcity(Page<TbIndent> pages, double riderLng, double riderLat, String address, String indentType);

    TbIndent findIndentByNumber(String indentNumber);

    int selectIndentByRiderUserCount(Long riderUserId);

    void indentReceiving(Long userId, String indentNumber, String format);

    void indentReceiv(Long userId, String indentNumber, String format,String state);

    IPage<TbIndent> findRiderIndent(Page<TbIndent> pages, Long userId, String indentState);

    TbIndent indentRiderMessage(String indentNumber, double riderLng, double riderLat);

    void riderCancleIndent(@Param("riderUserId") Long userId, @Param("indentNumber") String indentNumber);

    void updateRiderCashDeposit(BigDecimal cashDeposit, Long userId);

    void riderDelivery(Long indentId,  String date);

    TbIndent selectIndentByIndentNumber(String indentNumber);

    void updateRiderBalance(BigDecimal balance, Long userId);

    void userDelivery(Long userId, String indentNumber, String date);

    IPage<TbIndent> findallIndent(Page<TbIndent> pages, Long userId, Long riderUserId, Long shopId,Integer indentType,String ordersNo,Integer status,String riderPhone);

    void updateDefault(Long userId);

    void addUserAddress(ErrandAddress errandAddress);

    void updateAddress(@Param("userId")Long userId, @Param("userName") String userName, @Param("userPhone")String userPhone, @Param("address") String address,
                      @Param("addressDetail")String addressDetail, @Param("lng")double lng, @Param("lat")double lat,
                      @Param("updatetime")String datetime, @Param("addressDefault") String addressDefault, @Param("addressId") Long addressId);

    List<ErrandAddress> findUserAddress(Long userId);

    ErrandAddress findAddressById(Long userId, Integer addressId);

    void addDefaultAddress(Long userId, Integer addressId);

    void delUserAddress(Long userId, Integer addressId);

    ErrandRedPacket findRed(Long redPacketId);

    void delRedPacket(Long redPacketId);

    IPage<TbIndent> findAllIndent(Page<TbIndent> pages, String indentType, String phone, String indentState, String date, String dateType,String riderPhone);

    IPage<TbIndent> findAllIndents(Page<TbIndent> pages, String indentType, String phone, String indentState, String date, String dateType,String riderPhone);

    IPage<TbIndent> IndentCenter(Page<TbIndent> pages, String indentType, String indentNumber, String indentState, String phone, String date, String dateType);

    void updateIndentState(String indentNumber, String indentState);

    void adminSoldOutIndent(String indentNumber);

    BigDecimal billMoney(@Param("dateType")String dateType, @Param("date") String date);

    BigDecimal receivingMoney(@Param("dateType")String dateType, @Param("date") String date);

    int billCount(@Param("dateType")String dateType, @Param("date") String date);

    int reveivingCount(@Param("dateType")String dateType, @Param("date") String date);

    IPage<TbIndent> taskAnalysisMoney(Page<TbIndent> pages, @Param("dateType") String dateType, @Param("date") String date,@Param("indentState") String status);

    int findAllCount();

    int findDayAddUser(String format);

    int findMonthAddUser(String format);

    int findYearAddUser(String format);

    BigDecimal findDayIncome(String format);

    BigDecimal findMonthIncome(String format);

    BigDecimal findYearIncome(String format);

    int findIndentCount(String format);

    int selectOrderByStatus(String date, String dateType, Integer status);

    BigDecimal findAdminIncomeday(Long userId, String date, String dateType);

    BigDecimal findPrepayMoney(Long userId, String date, String dateType);

    int findAdminIndentCount(Long userId, String date, String dateType);

    IPage<TbIndent> selectIndentById(Page<TbIndent> pages, Long userId, String date, String dateType);

    IPage<TbIndent> findUserIndent(Page<TbIndent> pages, Long userId, String indentState);

    TbIndent indentMessage(String indentNumber);

    List<UserEntity> find5KmRider(@Param("lng") double lng, @Param("lat") double lat);

    void updateCoordinate(Long userId, double lng, double lat);

    UserEntity findUserInfoById(Long userId);

    List<ErrandRedPacket> findAllRedPacket(Long userId, String expirationTime);

    List<ErrandRedPacket> findRedPacket(Long userId, String indentType, BigDecimal indentBasicsMoney, Date expirationTime);

    int userCancleIndent(@Param("userId") Long userId, @Param("indentNumber") String indentNumber, @Param("cancelIndentTime") String cancelIndentTime);

    int updateRedPaclet(@Param("redPacketId") Long redPacketId);

    List<TbIndent> selectIndentList(Long userId);

    List<TbIndent> selectSendOrder(String date);

    Long selectRiderByDictance(Double userLng, Double userLat, Double distance, Double cashDeposit,Integer maxNum);

    TbIndent indentMessageByOrderId(Long orderId, double riderLng, double riderLat);

}
