package com.ruoyi.frequency.store.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.frequency.store.entity.Store;
import com.ruoyi.frequency.store.model.result.OrderResult;
import com.ruoyi.frequency.store.model.result.StoreCount;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

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

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

    /**
     * 查询商户列表
     *
     * @param store 商户
     * @return 商户集合
     */
    public List<Store> selectStoreList(Store store);

    /**
     * 新增商户
     *
     * @param store 商户
     * @return 结果
     */
    public int insertStore(Store store);

    /**
     * 修改商户
     *
     * @param store 商户
     * @return 结果
     */
    public int updateStore(Store store);

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

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

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

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

    @Update("update  t_store  set violation_deduction=violation_deduction + #{price} where id = #{storeId}")
    boolean addViolationDeduction(@Param("storeId") Long storeId, @Param("price") BigDecimal price);

    @Update("update  t_store set violation_deduction=violation_deduction - #{price} where id = #{storeId} and violation_deduction >=#{price}")
    boolean subViolationDeduction(@Param("storeId") Long storeId, @Param("price") BigDecimal price);


    @Update("update  t_store  set bond_amount=bond_amount + #{price} where id = #{storeId}")
    boolean addBondAmount(@Param("storeId") Long storeId, @Param("price") BigDecimal price);

    @Update("update  t_store  set bond_amount=bond_amount - #{price} where id = #{storeId} and bond_amount >=#{price}")
    boolean subBondAmount(@Param("storeId") Long storeId, @Param("price") BigDecimal price);

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

    @Update("update  t_store  set income=income + #{price} where id = #{storeId}")
    boolean addIncome(@Param("storeId") Long storeId, @Param("price") BigDecimal price);


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

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

    int getAuthStore(@Param("list") List<Long> userIds);

    int getCommonAuthStore(@Param("list") List<Long> userIds);

    int getHighAuthStore(@Param("list") List<Long> userIds);

    int getKujialeAuthStore(@Param("list") List<Long> userIds);
    StoreCount statistics(@Param("list") List<Long> storeIdList,@Param("beginOfMonth") Date beginOfMonth);

    Integer onlineNumber(Store store);

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

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