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


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

import java.util.Date;
import java.util.List;

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

    List<YbProductionOrder> findByAufnr(String code);

    @Query(value = "select a.* from plan_yb_production_order a left join factory_product_model b on a.product_model_id=b.id where a.product_type=?1 and b.dopant=?2 and b.conduction_type=?3 and b.specs=?4  and a.gstrp <=?5 and a.gltrp >= ?5 and a.production_status=1 ",nativeQuery = true)
    List<YbProductionOrder> getYbProductionOrder(String productType, String dopant, String conductiveType, String specs, Date gmtCreate);


    /**
     *
     * @param productType 产品类别
     * @param conductiveType 导电型号
     * @param specs 产品模型规格
     * @param dopant 掺杂剂
     * @param matnr 物料编码
     * @return
     */
    @Query(value = "select a.* from plan_production_order a left join factory_product_model b on a.product_model_id=b.id where a.product_type=?1 and b.dopant=?2 and b.conduction_type=?3 and b.specs=?4 and a.matnr=?5 and a.production_status=1 and a.work_shop=?6",nativeQuery = true)
    List<YbProductionOrder> getYbProductionOrderByMk(String productType, String dopant, String conductiveType, String specs, String matnr, String area);

    @Query(value = "select * from plan_yb_production_order ppo where ppo.production_status = ?1 and ppo.matnr = ?2 and (\t (ppo.gstrp > ?3 and ppo.gstrp < ?4)\n" +
            "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tor (ppo.gltrp > ?3 and ppo.gltrp < ?4)\n" +
            "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tor (ppo.gstrp <= ?3 and ppo.gltrp >= ?4)\t)", nativeQuery = true)
    List<YbProductionOrder> findByStatusAndProductCodeAndTime(boolean b, String matnr, Date gstrp, Date gltrp);
}
