package com.erp.skumatch.repository;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.erp.skumatch.entity.ErpSku;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface ErpSkuRepository extends BaseMapper<ErpSku> {
    
    @Select("<script>" +
            "SELECT * FROM erp_sku WHERE status = 'active' " +
            "<if test='keyword != null and keyword != \"\"'> AND (sku_name LIKE CONCAT('%', #{keyword}, '%') OR sku_code LIKE CONCAT('%', #{keyword}, '%') OR barcode LIKE CONCAT('%', #{keyword}, '%')) </if>" +
            "ORDER BY updated_at DESC" +
            "</script>")
    IPage<ErpSku> selectPageByKeyword(Page<ErpSku> page, @Param("keyword") String keyword);
}
