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.StringTool;
import com.steering.pss.sale.order.model.CraftFileApplyEntity;
import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;

public class CraftFileApplyDAL extends DBCommon{
	
	public CoreReturnObject query(String strJSON){
		CraftFileApplyEntity craftFileApply = EntityTool.getEntityByJSONStr(strJSON, CraftFileApplyEntity.class);
		String sql = CoreXmlSqlParsersFactory.getSql("CraftFileApplyDAL.query");
		sql = EntityTool.fillSqlByEntity(sql, craftFileApply);
		return this.getData(sql);
	}
	
	public CoreReturnObject save(ArrayList<String> listJSON){
		ArrayList<String> sqllist = new ArrayList<String>();
		for(String strJSON : listJSON){
			CraftFileApplyEntity craftFileApply = EntityTool.getEntityByJSONStr(strJSON, CraftFileApplyEntity.class);
			String sqlDelete = CoreXmlSqlParsersFactory.getSql("CraftFileApplyDAL.delete");
			sqlDelete = EntityTool.fillSqlByEntity(sqlDelete, craftFileApply);
			sqllist.add(sqlDelete);
			sqlDelete = EntityTool.fillSqlByEntity(sqlDelete, craftFileApply);
			String sql = CoreXmlSqlParsersFactory.getSql("CraftFileApplyDAL.insert");
			sql = EntityTool.fillSqlByEntity(sql, craftFileApply);
			sqllist.add(sql);
		}
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
	}
	
	/**
	 * 获取相同项目的数目
	 * @param strJSON
	 * @return
	 */
	public CoreReturnObject getSampeCnt(String strJSON){
		CraftFileApplyEntity craftFileApply = EntityTool.getEntityByJSONStr(strJSON, CraftFileApplyEntity.class);
		String sql = CoreXmlSqlParsersFactory.getSql("CraftFileApplyDAL.getSampeCnt");
		sql = EntityTool.fillSqlByEntity(sql, craftFileApply);
		return this.getData(sql);
	}
	
	/**
	 * 获取匹配的工艺文件
	 * @param ordLnPk
	 * @return
	 */
	public CoreReturnObject getMatchCraftFile(String ordLnPk){
		String sql = CoreXmlSqlParsersFactory.getSql("CraftFileApplyDAL.getMatchCraftFile");
		sql = StringTool.ReplaceAll(sql, "#ORD_LN_PK#", ordLnPk);
		return this.getData(sql);
	}
}
