package com.sifang.modules.supply.warehouse.dao;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.sifang.modules.sunshine.fittingManager.entity.CrmSiteFitting;
import com.sifang.modules.supply.warehouse.entity.CrmSupplyPurchaseOrderDetail;
import com.sifang.modules.sys.common.persistence.BaseDao;
import com.sifang.modules.sys.util.SqlBuilder;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class CrmSupplyPurchaseOrderDetailDao extends BaseDao<CrmSupplyPurchaseOrderDetail> {

   public List<CrmSupplyPurchaseOrderDetail> getDetailList(String purchaseId){
       String sql = "from CrmSupplyPurchaseOrderDetail where purchaseId = :purchaseId and status ='1'";
       Query query = getSession().createQuery(sql);
       query.setParameter("purchaseId", purchaseId);
       List<CrmSupplyPurchaseOrderDetail> list = query.list();
       return list;
   }


    public List<Record> getDetailsByOrderIds(List<String> orderIds) {
        SqlBuilder builder = new SqlBuilder();
        builder.line("select d.*")
                .line("from crm_supply_purchase_order_detail d")
                .inst("where d.status='1' and  d.purchase_id in ", orderIds);
        return Db.find(builder.build(), builder.params());
    }
}
