package com.sw.mes.yb.pc.dao;

import com.sw.mes.core.base.BaseDao;
import com.sw.mes.yb.pc.entity.SideSkinCodingRule;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @Author
 * @Description：
 * @Date:
 * @Modified By:
 */
public interface SideSkinCodingRuleDao extends BaseDao<SideSkinCodingRule, Integer> {
    /**
     * 查询是否存在
     *
     * @param skinName 规则名称
     * @return 条数
     */
    @Query(value = "SELECT 1 FROM side_skin_coding_rule WHERE skin_name=?1 LIMIT 1", nativeQuery = true)
    Integer findCountBySkinName(String skinName);

    @Query(value = "SELECT * FROM side_skin_coding_rule \n" +
                    "WHERE \n" +
                    "IF(?1 is null ,1=1,area=?1) \n" +
                    "AND IF(?2 is null ,1=1,series=?2) \n" +
                    "AND IF(?3 is null ,1=1,thermal=?3) \n" +
                    "AND IF(?4 is null ,1=1,lot_no=?4) \n" +
                    "AND IF(?5 is NULL,1=1,specs=?5) \n" +
                    "AND IF(?6 is null ,1=1,again_num=?6) \n" +
                    "AND IF(?7 is null ,1=1,again_count=?7)\n" +
                    "AND IF(?8 is null ,1=1,lot_count=?8)\n" +
                    "AND IF(?9 is null ,1=1,piecewise_num=?9)", nativeQuery = true)
    List<SideSkinCodingRule> findBySegmentInfo(String area, String series, String thermal, String lotNo, String specs, Integer againNum, Integer againCount, Integer lotCount, String piecewiseNum);

}
