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

import com.sw.mes.core.base.BaseDao;
import com.sw.mes.yb.plan.entity.PlanWaterLineManageRecord;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
* @Author
* @Description：
* @Date:
* @Modified By:
*/
public interface PlanWaterLineManageRecordDao extends BaseDao<PlanWaterLineManageRecord, Long>{

    @Query(value = "SELECT * FROM plan_water_line_manage_record WHERE pid = ?1", nativeQuery = true)
    List<PlanWaterLineManageRecord> findPlanWaterLineById(Long id);

    @Modifying
    @Transactional
    @Query(value = "DELETE FROM plan_water_line_manage_record WHERE pid=?1",nativeQuery = true)
    void deleteByFid(Long id);


    @Query(value = "select * from plan_water_line_manage_record where  dopant=?1  and  conduction_type=?2 and specs=?3  and  product_type = ?4 LIMIT 1", nativeQuery = true)
    PlanWaterLineManageRecord selectOneOrder(String dopant,  String conductiveType,  String specs, String productType);

    @Query(value = "select * from plan_water_line_manage_record where  dopant=?1  and  conduction_type=?2 and specs=?3 and yb_product_grade like ?4 and (resistance_level like ?5 or resistance_level is null or resistance_level = '' or 1=1) and side_length_range=?6", nativeQuery = true)
    List<PlanWaterLineManageRecord> selectAllOrder(String dopant,  String conductiveType,  String specs, String ybProductGrade, String resLevel, String SideLengthRange);


    @Query(value = "select * from plan_water_line_manage_record where  dopant=?1  and  conduction_type=?2 and specs=?3 and (side_length_range=?4 or 1=1) and yb_product_grade like ?5 and (resistance_level like ?6 or resistance_level is null or resistance_level = '' or 1=1)", nativeQuery = true)
    List<PlanWaterLineManageRecord> selectOrders(String dopant,  String conductiveType,  String specs,String sideLengthRange, String ybLevel, String resLevel);
}
