package com.ruoyi.frequency.customer.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.controller.req.CustomerPageReq;
import com.ruoyi.controller.resp.UserResultInfo;
import com.ruoyi.frequency.customer.entity.Customer;
import com.ruoyi.frequency.customer.model.result.CustomerCount;
import com.ruoyi.frequency.illegaldeductionrecord.model.result.OrderInfoResp;
import com.ruoyi.vo.UserVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

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

/**
 * 用户Mapper接口
 *
 * @author liwenlong
 * @date 2023-09-22
 */
public interface CustomerMapper  extends BaseMapper<Customer>
{
    /**
     * 查询用户
     *
     * @param id 用户主键
     * @return 用户
     */
    public Customer selectCustomerById(Long id);

    /**
     * 查询用户列表
     *
     * @param customer 用户
     * @return 用户集合
     */
    public List<Customer> selectCustomerList(Customer customer);

    /**
     * 新增用户
     *
     * @param customer 用户
     * @return 结果
     */
    public int insertCustomer(Customer customer);

    /**
     * 修改用户
     *
     * @param customer 用户
     * @return 结果
     */
    public int updateCustomer(Customer customer);

    /**
     * 删除用户
     *
     * @param id 用户主键
     * @return 结果
     */
    public int deleteCustomerById(Long id);

    /**
     * 批量删除用户
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteCustomerByIds(Long[] ids);

    UserResultInfo info(@Param("userId") Long userId);

    @Update("update  t_customer  set balance=balance + #{price} where id = #{customerId}")
    boolean addBalance(@Param("customerId") Long customerId, @Param("price") BigDecimal price);

    @Update("update  t_customer  set balance=balance - #{price} where id = #{customerId} and balance >=#{price}")
    boolean subBalance(@Param("customerId") Long customerId, @Param("price") BigDecimal price);

    @Update("update  t_customer  set give_balance=give_balance + #{price} where id = #{customerId}")
    boolean addGiveBalance(@Param("customerId") Long customerId, @Param("price") BigDecimal price);

    @Update("update  t_customer  set give_balance=give_balance - #{price} where id = #{customerId} and give_balance >=#{price}")
    boolean subGiveBalance(@Param("customerId") Long customerId, @Param("price") BigDecimal price);


    @Update("update  t_customer  set integral=integral + #{price} where id = #{customerId}")
    boolean addIntegral(@Param("customerId") Long customerId, @Param("price") BigDecimal price);

    @Update("update  t_customer  set integral=integral - #{price} where id = #{customerId} and integral >=#{price}")
    boolean subIntegral(@Param("customerId") Long customerId, @Param("price") BigDecimal price);

    @Update("update  t_customer  set consumption_amount=consumption_amount + #{price} where id = #{customerId}")
    boolean addConsumptionAmount(@Param("customerId") Long customerId, @Param("price") BigDecimal price);

    String longestIdNo();

    void saveIdNo(@Param("id") Long id);

    Page<Customer> customerPage(@Param("page") Page<Object> objectPage,@Param("req") CustomerPageReq req, @Param("userVo")UserVo userVo);

    CustomerCount statistics(@Param("list") List<Long> customerIdList);

    Integer onlineNumber(Customer customer);

    Integer canCancellation(@Param("userId")Long userId);

    OrderInfoResp getOrderInfo(@Param("orderId")Long orderId);

    void insertOnlineLog(@Param("userVo") UserVo userVo);
}
