package org.dromara.zhishu.mapper;

import cn.dev33.satoken.annotation.SaIgnore;
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import org.apache.ibatis.annotations.Param;
import org.dromara.zhishu.domain.RunningTask;
import org.dromara.zhishu.domain.dto.ErpGoodsDto;
import org.dromara.zhishu.domain.dto.RunningTaskShopGoodsDto;
import org.dromara.zhishu.domain.dto.SuccessDataItemDto;
import org.dromara.zhishu.domain.dto.SuccessDataKfz;
import org.dromara.zhishu.domain.vo.RunningTaskNumVo;

import java.util.List;
import java.util.Map;

/**
 * 执行的任务Mapper接口
 *
 * @author yxy
 * @date 2025-08-05
 */
public interface RunningTaskByShopMapper {

    /**
     * 分页查询列表
     * @param tableName
     * @param pageNum
     * @param pageSize
     * @return
     */
    @InterceptorIgnore(tenantLine = "true")
    List<Map> selectGetShopGoodsList(@Param("tableName") String tableName,@Param("isOnsale") String isOnsale,
                                     @Param("isbn") String isbn,@Param("priceDown") Long priceDown,@Param("priceUp") Long priceUp,
                                     @Param("startDate") String startDate,@Param("endDate") String endDate,
                                     @Param("pageNum") Long pageNum, @Param("pageSize") Long pageSize,
                                     @Param("goodsName") String goodsName,@Param("stockDown") String stockDown,
                                     @Param("stockUp") String stockUp,@Param("trilateralId") String trilateralId,
                                     @Param("goodsCode") String goodsCode,@Param("skuCode") String skuCode);

    /**
     * 查询列表总数
     * @param tableName
     * @return
     */
    @InterceptorIgnore(tenantLine = "true")
    int selectGetShopGoodsListCount(@Param("tableName") String tableName,@Param("isOnsale") String isOnsale,
                                    @Param("isbn") String isbn,@Param("priceDown") Long priceDown,@Param("priceUp") Long priceUp,
                                    @Param("startDate") String startDate,@Param("endDate") String endDate,
                                    @Param("goodsName") String goodsName,@Param("stockDown") String stockDown,
                                    @Param("stockUp") String stockUp,@Param("trilateralId") String trilateralId,
                                    @Param("goodsCode") String goodsCode,@Param("skuCode") String skuCode);

    /**
     * 根据DTO查询列表
     * @param runningTaskShopGoodsDto
     * @return
     */
    @InterceptorIgnore(tenantLine = "true")
    List<Map> selectGetShopGoodsListByDto(RunningTaskShopGoodsDto runningTaskShopGoodsDto);

    @InterceptorIgnore(tenantLine = "true")
    int selectNumByIsbn(@Param("tableName") String tableName,@Param("isbn") String isbn);
    /**
     * 查询数据表中数据的总数
     * @param tableName
     * @return
     */
    @InterceptorIgnore(tenantLine = "true")
    int selectGetShopGoodsNum(@Param("tableName") String tableName,@Param("isOnSale") String isOnSale,
                              @Param("isbn") String isbn,@Param("priceDown") Long priceDown,@Param("priceUp") Long priceUp,
                              @Param("startDate") String startDate,@Param("endDate") String endDate,
                              @Param("goodsName") String goodsName,@Param("stockDown") String stockDown,
                              @Param("stockUp") String stockUp,@Param("trilateralId") String trilateralId,
                              @Param("goodsCode") String goodsCode,@Param("skuCode") String skuCode);

    /**
     * 删除店铺商品
     */
    @InterceptorIgnore(tenantLine = "true")
    int delShopGoods(@Param("tableName") String tableName,@Param("isOnSale") String isOnSale,
                      @Param("isbn") String isbn,@Param("priceDown") Long priceDown,@Param("priceUp") Long priceUp,
                      @Param("startDate") String startDate,@Param("endDate") String endDate);

    /**
     * 根据三方平台id查询数据是否存在
     * @param tableName
     * @param trilateralId
     * @return
     */
    @InterceptorIgnore(tenantLine = "true")
    int selectByTrilateralId(@Param("tableName") String tableName,@Param("trilateralId") String trilateralId);

    @InterceptorIgnore(tenantLine = "true")
    RunningTask selectVoByTrilateralId(@Param("tableName") String tableName,@Param("trilateralId") String trilateralId);

    /**
     * 查询店铺最后一次
     * @param tableName
     * @return
     */
    @InterceptorIgnore(tenantLine = "true")
    String selectLastFinishTime(String tableName);

    /**
     * 根据isbn查询商品信息
     * @param tableName
     * @param isbn
     * @return
     */
    @InterceptorIgnore(tenantLine = "true")
    List<RunningTask> selectByIsbn(@Param("tableName") String tableName,@Param("isbn") String isbn);

    /**
     * 查询电偶的日志
     * @param tableName
     * @return
     */
    @InterceptorIgnore(tenantLine = "true")
    List<RunningTaskNumVo> selectTaskShopNum(@Param("tableName") String tableName, @Param("taskId") Long taskId);

    /**
     * 查询是否是最新任务拉取的数据
     * @param tableName
     * @param taskId
     * @return
     */
    @InterceptorIgnore(tenantLine = "true")
    int selectGetShopGoodsNumByTasKId(@Param("tableName") String tableName, @Param("taskId") String taskId);

    /**
     * 查询任务是在执行中还是已完成
     * @param tableName
     * @return
     */
    @InterceptorIgnore(tenantLine = "true")
    String selectStatus(String tableName);

    @InterceptorIgnore(tenantLine = "true")
    List<SuccessDataItemDto> selectShopGoodsList(ErpGoodsDto erpGoodsDto);

    /**
     * kfz专用导出店铺商品数据
     * @param erpGoodsDto
     * @return
     */
    @InterceptorIgnore(tenantLine = "true")
    List<SuccessDataKfz> selectKfzShopGoodsList(ErpGoodsDto erpGoodsDto);


    /**
     * 根据isbn查询重复数据
     * @param tableName
     * @return
     */
    @InterceptorIgnore(tenantLine = "true")
    List<SuccessDataItemDto> selectRepeat(@Param("tableName") String tableName);

    // 检查表是否存在
    @InterceptorIgnore(tenantLine = "true")
    int checkTableExists(@Param("tableName") String tableName);

    // 创建表
    @InterceptorIgnore(tenantLine = "true")
    void createTable(@Param("tableName") String tableName);

    // 插入数据
    @InterceptorIgnore(tenantLine = "true")
    void insert(@Param("tableName") String tableName, @Param("task") RunningTask task);

    //修改数据
    @InterceptorIgnore(tenantLine = "true")
    void update(@Param("tableName") String tableName, @Param("task") RunningTask task);

    // 批量插入数据
    @InterceptorIgnore(tenantLine = "true")
    void batchInsert(@Param("tableName") String tableName, @Param("list") List<RunningTask> list);

    @InterceptorIgnore(tenantLine = "true")
    void updateStatus(String tableName);

    @InterceptorIgnore(tenantLine = "true")
    void deleteAll(String tableName);

    @InterceptorIgnore(tenantLine = "true")
    void deleteByStatus(@Param("tableName") String tableName,@Param("status") String status);

    @InterceptorIgnore(tenantLine = "true")
    void deleteByTaskId(@Param("tableName") String tableName,@Param("taskId") String taskId);


    @InterceptorIgnore(tenantLine = "true")
    List<SuccessDataItemDto> selectOnSaleGoodsId(String tableName);

    @InterceptorIgnore(tenantLine = "true")
    List<SuccessDataItemDto> selectByGoodsId(String tableName, String trilateralId);

    @InterceptorIgnore(tenantLine = "true")
    void updateSuccessDataById(@Param("tableName") String tableName,@Param("id") String id,@Param("successDataJsonStr") String successDataJsonStr);


    @InterceptorIgnore(tenantLine = "true")
    void deleteByGoodsId(@Param("tableName") String tableName,@Param("goodsId") String goodsId);

    @InterceptorIgnore(tenantLine = "true")
    List<Map> getShopGoodsList(@Param("tableName") String tableName);

    @InterceptorIgnore(tenantLine = "true")
    Integer getShopGoodsTotalNum(@Param("tableName")String tableName);

    @InterceptorIgnore(tenantLine = "true")
    Integer getShopGoodsTotalNumByTaskId(@Param("tableName") String tableName,@Param("taskId") Long taskId);


    @InterceptorIgnore(tenantLine = "true")
    List<Map<String, Object>> batchCheckExists(String tableName, List<String> batch);

    @InterceptorIgnore(tenantLine = "true")
    Map<String, Object> selectTodayGoods(@Param("tableName") String tableName, @Param("todayStart") String todayStart, @Param("todayEnd") String todayEnd);

    List<Map> selectGetShopGoodsListAll(String tableName, String isOnsale, Long pageNum, Long pageSize);

    @InterceptorIgnore(tenantLine = "true")
    Integer countAll(@Param("tableName")String tableName);

    /**
     * 批量查询goods_id是否存在，返回存在的goods_id列表
     * @param tableName
     * @param goodsIds
     * @return
     */
    @InterceptorIgnore(tenantLine = "true")
    List<Long> batchSelectExistsByGoodsIds(@Param("tableName") String tableName, @Param("goodsIds") List<Long> goodsIds);

}
