package com.steering.pss.sale.order.DAL;

import java.util.ArrayList;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.EntityTool;
import com.steering.comm.tools.SqlBuilder;
import com.steering.comm.tools.StringTool;
import com.steering.pss.sale.order.model.PlnSaleordProcEntity;
import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;

public class PlaSaleOrdProcDAL extends DBCommon{
	
	public CoreReturnObject query(String craftNo, String craftNoV){
		String sql = CoreXmlSqlParsersFactory.getSql("PlaSaleOrdProcDAL.query");
		sql = StringTool.ReplaceAll(sql, "#CRAFT_NO#", craftNo);
		sql = StringTool.ReplaceAll(sql, "#CRAFT_NO_V#", craftNoV);
		return this.getData(sql);
	}
	
	public CoreReturnObject queryCount(String craftNo, String craftNoV){
		String sql = CoreXmlSqlParsersFactory.getSql("PlaSaleOrdProcDAL.queryCount");
		sql = StringTool.ReplaceAll(sql, "#CRAFT_NO#", craftNo);
		sql = StringTool.ReplaceAll(sql, "#CRAFT_NO_V#", craftNoV);
		return this.getData(sql);
	}
	
	
	public CoreReturnObject upgradeCraft(ArrayList<String> listJSON){
		ArrayList<String> sqllist = new ArrayList<String>();
		for(String strJSON : listJSON){
			PlnSaleordProcEntity plasaleOrdProc = EntityTool.getEntityByJSONStr(strJSON, PlnSaleordProcEntity.class);
			String sql = CoreXmlSqlParsersFactory.getSql("PlaSaleOrdProcDAL.upgradeCraft");
			sql = EntityTool.fillSqlByEntity(sql, plasaleOrdProc);
			sqllist.add(sql);
		}
		
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
	}
	
	/**
	 * 通过主键查询排产队列表
	 * @param ordLnDlyPk
	 * @param plaDivideId
	 * @return
	 */
	public CoreReturnObject queryPlaProcByPk(String ordLnDlyPk, String plaDivideId){
		String sql = CoreXmlSqlParsersFactory.getSql("PlaSaleOrdProcDAL.queryPlaProcByPk");
		sql = StringTool.ReplaceAll(sql, "#ORD_LN_DLY_PK#", ordLnDlyPk);
		sql = StringTool.ReplaceAll(sql, "#PLN_DIVIDE_ID#", plaDivideId);
		return this.getData(sql);
	}
	
	public CoreReturnObject IsIssued(String craftNo, String craftNoV){
		SqlBuilder b = new SqlBuilder("PlaSaleOrdProcDAL.IsIssued");
		b.Fill("CRAFT_NO", craftNo);
		b.Fill("CRAFT_NO_V", craftNoV);
		return this.getData(b.toString());
	}
}
