package cn.ysk.cashier.cons.repository;

import cn.ysk.cashier.cons.domain.TbConsInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

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

/**
* @website https://eladmin.vip
* @author admin
* @date 2024-06-22
**/
public interface TbConsInfoRepository extends JpaRepository<TbConsInfo, Integer>, JpaSpecificationExecutor<TbConsInfo> {


    int countByConCode(String conCode);

    List<TbConsInfo> findByConTypeId(Integer typeId);

    TbConsInfo findByConCode(String conCode);


    @Query(value =
            "SELECT pro.id, pro.name" +
            "    FROM" +
            "        tb_prosku_con conPro" +
            "        LEFT JOIN tb_product pro ON conPro.product_id = pro.id AND pro.shop_id = :shopId AND conPro.shop_id = :shopId" +
            "  where conPro.con_info_id = :conInfoId " +
            "  group by conPro.product_id ",nativeQuery = true)
    List<Map<Integer, Object>> queryAllAndPro(@Param("shopId") Integer shopId, @Param("conInfoId")Integer conInfoId);
}