package com.steering.pss.plnsaleord.processOrder;

import java.util.ArrayList;
import java.util.List;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;

import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.EntityTool;
import com.steering.pss.plnsaleord.base.PlnHelper;
import com.steering.pss.plnsaleord.processOrder.entity.SlmBaseMaterialFPlEntity;

/**
 * 窗体 热处理产线能力
 * 
 * @author Administrator
 * 
 */
public class FrmBaseMaterialFPl extends DBCommon {
	/**
	 * 查询
	 * 
	 * @param inMaterialNo
	 *            投入物料
	 * @param outMaterialNo
	 *            产出物料
	 * @return
	 */
	public CoreReturnObject queryRclPl(String inMaterialNo,
			String outMaterialNo, String groupPlan) {
		Object[] params = new Object[] { inMaterialNo, outMaterialNo,
				groupPlan, groupPlan, groupPlan };
		return this.getDataBySqlID("FrmBaseMaterialFPl.queryRclPl", params);
	}

	/**
	 * 验证是否存在
	 * 
	 * @param plineCode
	 *            产线
	 * @param inMaterialNo
	 *            投入物料
	 * @param outMaterialNo
	 *            产出物料
	 * @return
	 */
	public CoreReturnObject checkIsExist(String plineCode, String inMaterialNo,
			String outMaterialNo) {
		Object[] params = new Object[] { plineCode, inMaterialNo, outMaterialNo };
		return this.getDataBySqlID("FrmBaseMaterialFPl.checkIsExist", params);
	}

	/**
	 * 查询基础热处理产线
	 * 
	 * @return
	 */
	public CoreReturnObject getBasePlineF(String groupPlan) {
		Object[] params = new Object[] { groupPlan, groupPlan, groupPlan };
		return this.getDataBySqlID("FrmBaseMaterialFPl.getBasePlineF", params);
	}

	/**
	 * 查询热处理基础物料描述
	 * 
	 * @param inMaterialNo
	 *            投入物料
	 * @param outMaterialNo
	 *            产出物料
	 * @return
	 */
	public CoreReturnObject getBaseMaterialDescF(String inMaterialNo,
			String outMaterialNo) {
		Object[] params = new Object[] { inMaterialNo, outMaterialNo };
		return this.getDataBySqlID("FrmBaseMaterialFPl.getBaseMaterialDescF",
				params);
	}

	/**
	 * 热处理产线能力操作
	 * 
	 * @param fPlEntitys
	 *            集合
	 * @param flag
	 *            标识
	 * @return
	 */
	public CoreReturnObject saveRclPl(ArrayList<String> jsonList, String flag) {
		List<SlmBaseMaterialFPlEntity> fPlEntitys = PlnHelper
				.jsonsToEntityList(SlmBaseMaterialFPlEntity.class, jsonList);
		ArrayList<String> sqllist = new ArrayList<String>();
		if (flag.equals("0")) {
			// 新增
			for (SlmBaseMaterialFPlEntity fPlEntity : fPlEntitys) {
				String sql = CoreXmlSqlParsersFactory
						.getSql("FrmBaseMaterialFPl.addRclPl");
				sql = EntityTool.fillSqlByEntity(sql, fPlEntity);
				sqllist.add(sql);
			}
		} else if (flag.equals("1")) {
			// 修改
			for (SlmBaseMaterialFPlEntity fPlEntity : fPlEntitys) {
				String sql = CoreXmlSqlParsersFactory
						.getSql("FrmBaseMaterialFPl.updateRclPl");
				sql = EntityTool.fillSqlByEntity(sql, fPlEntity);
				sqllist.add(sql);
			}
		} else {
			// 删除
			for (SlmBaseMaterialFPlEntity fPlEntity : fPlEntitys) {
				String sql = CoreXmlSqlParsersFactory
						.getSql("FrmBaseMaterialFPl.deleteRclPl");
				sql = EntityTool.fillSqlByEntity(sql, fPlEntity);
				sqllist.add(sql);
			}
		}
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
				sqllist);
	}

}
