package org.dromara.zhishu.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
import org.dromara.zhishu.domain.TFreight;
import org.dromara.zhishu.domain.TShelves;
import org.dromara.zhishu.domain.ZhishuShopGoods;
import org.dromara.zhishu.domain.ZhishuShopImages;
import org.dromara.zhishu.domain.bo.ZhishuShopGoodsBo;
import org.dromara.zhishu.domain.vo.*;
import org.springframework.data.repository.query.Param;

import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 商品信息Mapper接口
 *
 * @author Lion Li
 * @date 2025-03-07
 */
@Mapper
public interface ZhishuShopGoodsMapper extends BaseMapperPlus<ZhishuShopGoods, ZhishuShopGoodsVo> {

    /**
     * 批量查询商品根据id
     * @param ids
     * @return
     */
    List<ZhishuShopGoodsVo> selectByIds(List<String> ids);

    List<ProductVo> selectShopGoodsByIsbn(String isbn);

    ZhishuShopGoodsVo selectShopGoodsByItemNumbers(String itemNumber);

    ZhishuShopGoodsVo selectShopGoodsByArtNo(String artNo);


    ZhishuShopGoodsVo selectShopGoodsByItemNumber1(ZhishuShopGoods zhishuShopGoods);


    ZhishuShopGoods selectInventory(String barcode, String letterCode);

    void updateArtNo(String firstChar, String secondChar, String thirdChar, String artNo);

    Integer selectDepot(Long userId);

    List<ZhishuShopGoodsBo> selectAll(Long userId);

    Integer updateByProduct(ZhishuShopGoods zhishuShopGoods);

    List<TShelves> selectSheCount(Long depotId);

    List<Long> selectFreCount(Long sheId);

    void insertTask(Long depotId, String filename, int count, Long userId);

    ZhishuShopGoods selectPriceByIsbnAndConditionCode(String barcode, String letterCode, Long price);

    ZhishuShopGoods selectartNoByIsbnAndConditionCodeAndArtNo(String barcode, String letterCode, String artNo, Long price, Long userId);

    long selectArtNo(String artNo, Long userId);

    long selectCodeByCodeAndIsbn(String barcode, String letterCode, Long userId);

    long selectUserId(Long userId);

    long selectIsbnCount(Long userId, String barcode);

    /**
     * 查询是否存在
     *
     * @param isbn       ISBN
     * @param artNo      货号
     * @param userId     用户id
     * @param letterCode 品相
     * @param price      价格
     * @return
     */
    long selectCountByIsbnAndArtNoAndUserIdAndBarcode(String isbn, String artNo, String userId, String letterCode, String price);

    void updateShop(ZhishuShopGoods existingGoods);

    void updateInventory(long newInventory, Long userId, String letterCode, String artNo, long price, String barcode);

    Long findBookMsgByISBN(ZhishuShopGoods zhishuShopGoods);

    Integer setExamineBook(ZhishuShopGoods zhishuShopGoods);

    Integer selectGoods(ZhishuShopGoods add);

    List<TFreight> selectFreCount1(@Param("sheCount") List<TShelves> sheCount);

//    void updateBook(ZhishuShopGoods add);

    String selectShopId(String userId, String barcode, String name);

    List<TFreight> selectBySId(Long id);

    List<ZhishuShopGoodsVo> selectShopGoodsByUser(Long userId);

    List<FreightGoodsCountVo> selectFreightGoodsNumber(@Param("userId") Long userId, @Param("freightIdList") List<Long> freightIdList);

    TDepotVo selectDepotName(Long userId, String depotCode);

    Integer deleteByIds1(Collection<String> ids);

    ZhishuShopGoodsVo selectByIdVo(String id);

    Integer deleteIds(Collection<String> ids);

    String selectArtNoCount(String artNo, Long price);

    String queryByShopId(String shopId);

//    Long selectArtNoCount1(String artNo,Long price);

    Map<String, String> batchQueryPathByShopIds(List<String> shopIds);

    String selectByBookPic(String id);

    Long selectArtNoCount1(String artNo, Long price, String letterCode);

    void delPubGood(String id);

    Integer selectPubCount(String id);

    Integer insertInventory(@Param("update") ZhishuShopGoods update,@Param("inventory") Long inventory);

    List<StockChangeLogVo> selectStockLog(String id);

    Page<ZhishuShopGoodsVo> selectShopGoodsByUserPage(Page<ZhishuShopGoodsVo> page, Long userId);

    Page<ZhishuShopGoodsVo> selectShopGoodsByUserPageWithDate(
        @Param("page") Page<ZhishuShopGoodsVo> page,
        @Param("userId") Long userId,
        @Param("startDate") Date startDate,
        @Param("endDate") Date endDate
    );

    Long selectDepotIds(String artNo);

    Long selectSheId(Long depotId, String letterCode);

    Long selectFreId(Long sheId, String thirdChar);

    Map selectArt(@Param("userId") String userId,@Param("dcode") String dcode,@Param("scode") String scode,@Param("fcode") String fcode);

    Boolean updateChunkInventory(ZhishuShopGoods update);

    List<ZhishuShopImages> selectImages();

    String getSelectArtNo(Long deId, Long shId, Long frId, Long userId);

    Integer batchUpdateartNo(@Param("deId") Long deId,@Param("beartNo") String beartNo,@Param("ids") List<String> ids);

    Page<ZhishuShopGoodsVo> selectShopGoodsByUserPageWithDateArtNo(
            @Param("page") Page<ZhishuShopGoodsVo> page,
            @Param("userId") Long userId,
            @Param("startDate") Date startDate,
            @Param("endDate") Date endDate,
            @Param("code") String code
    );

    Page<ZhishuShopGoodsVo> selectShopGoodsByUserPageArtNo(Page<ZhishuShopGoodsVo> page, Long userId, String code);

    List<String> selectAllArtNo(Long userId);

    List<TShelves> selectSheCounts(@Param("depotCount")List<TDepotVo> depotVos);

    Long getTaskDataNum(Long taskId);

    boolean updateByArtNo(ZhishuShopGoodsBo updateBo);

    int updateByArtNoPrefix(@Param("isJoinDistribution") String isJoinDistribution,@Param("artNoPrefix") String artNoPrefix,@Param("userId") Long userId,@Param("limitNum") Long limitNum);

//    @Select("select * from zhishu_shop_goods where isbn = #{barcode} AND condition_code = #{conditionCode}")
//    ZhishuShopGoods selectInventory(String barcode, letterCode);

    int selectArtNobyartNo(String artNo, Long userId);

    ZhishuShopGoodsVo selectShopGoodsByShopIdAndPlatformId(@Param("shopId") String shopId,@Param("platformId") String platformId);

    ZhishuShopGoodsVo selectShopGoodsByArtNoAndUserId(@Param("artNo") String artNo,@Param("userId") Long userId);

    ZhishuShopGoodsVo selectShopGoodsByProductId(@Param("productId") String productId,@Param("userId") Long userId);
}