package com.steering.pss.sale.order;

import java.util.ArrayList;
import net.sf.json.JSONObject;
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.comm.tools.StringTool;
import com.steering.pss.sale.order.model.DesignMscPlStiEntity;
import com.steering.pss.sale.order.model.DesignMscPlStiTcEntity;

/**
 * 工艺参数维护
 * @author Chenxi
 *
 */
public class CoreOrderCraft extends DBCommon{
	
	/**
	 * 获取全制程工序点信息
	 * @param strJSON 实体类
	 * @return obj
	 */
	public CoreReturnObject getMscPlSti(String strJSON){
		String sql = CoreXmlSqlParsersFactory.getSql("CoreOrderCraft.getMscPlSti");
		JSONObject obj = JSONObject.fromObject(strJSON);
		DesignMscPlStiEntity designMspPlsSti = (DesignMscPlStiEntity)JSONObject.toBean(obj, DesignMscPlStiEntity.class);
		sql = EntityTool.fillSqlByEntity(sql, designMspPlsSti);
		return this.getData(sql);
	}
	
	/**
	 * 获取全制程工序点-工艺参数信息(MPS)
	 * @param strJSON 实体类
	 * @return obj
	 */
	public CoreReturnObject getMscPlStiTc(String strJSON){
		String sql = CoreXmlSqlParsersFactory.getSql("CoreOrderCraft.getMscPlStiTc");
		JSONObject obj = JSONObject.fromObject(strJSON);
		DesignMscPlStiTcEntity designMspPlsSti = (DesignMscPlStiTcEntity)JSONObject.toBean(obj, DesignMscPlStiTcEntity.class);
		sql = EntityTool.fillSqlByEntity(sql, designMspPlsSti);
		
		return this.getData(sql);
	}
	
	/**
	 * 设置全制程工序点-工艺参数信息(MPS)
	 * @param strJSON 实体类
	 * @return obj
	 */
	public CoreReturnObject setMscPlStiTc(ArrayList<String> listJSON, ArrayList<String> listMpsNO){
		ArrayList<String> sqllist = new ArrayList<String>();
		for(int i = 0; i <listJSON.size(); i++){
			String strJSON = listJSON.get(i);
			JSONObject obj = JSONObject.fromObject(strJSON);
			DesignMscPlStiTcEntity designMspPlsSti = (DesignMscPlStiTcEntity)JSONObject.toBean(obj, DesignMscPlStiTcEntity.class);
			if(i == 0){
				String sqlDelete = CoreXmlSqlParsersFactory.getSql("CoreOrderCraft.delMscPlStiTc");
				sqlDelete = EntityTool.fillSqlByEntity(sqlDelete, designMspPlsSti);
				sqllist.add(sqlDelete);
			}
			String sql = CoreXmlSqlParsersFactory.getSql("CoreOrderCraft.setMscPlStiTc");
			sql = EntityTool.fillSqlByEntity(sql, designMspPlsSti);
			sqllist.add(sql);
		}
		
		String sql = CoreXmlSqlParsersFactory.getSql("CoreOrderCraft.setMpsNo");
		sql = StringTool.ReplaceAll(sql, "#ORD_LN_PK#", listMpsNO.get(0));
		sql = StringTool.ReplaceAll(sql, "#MPS_NO#", listMpsNO.get(1));
		sqllist.add(sql);
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
	}
	
	/**
	 * 获取产线
	 * @param strJSON 实体类
	 * @return obj
	 */
	public CoreReturnObject getMscPline(String strJSON){
		String sql = CoreXmlSqlParsersFactory.getSql("CoreOrderCraft.getMscPline");
		JSONObject obj = JSONObject.fromObject(strJSON);
		DesignMscPlStiEntity designMspPlsSti = (DesignMscPlStiEntity)JSONObject.toBean(obj, DesignMscPlStiEntity.class);
		sql = EntityTool.fillSqlByEntity(sql, designMspPlsSti);
		
		return this.getData(sql);
	}
	
	/**
	 * 获取工艺参数个数
	 * @param strJSON 实体类
	 * @return obj
	 */
	public CoreReturnObject getCraftCount(String strJSON){
		String sql = CoreXmlSqlParsersFactory.getSql("CoreOrderCraft.getCraftCount");
		JSONObject obj = JSONObject.fromObject(strJSON);
		DesignMscPlStiEntity designMspPlsSti = (DesignMscPlStiEntity)JSONObject.toBean(obj, DesignMscPlStiEntity.class);
		sql = EntityTool.fillSqlByEntity(sql, designMspPlsSti);
		
		return this.getData(sql);
	}
	
	/**
	 * 获取MPS编号
	 * @param ordLenPk
	 * @return
	 */
	public CoreReturnObject getMpsNo(String ordLnPk){
		String sql = CoreXmlSqlParsersFactory.getSql("CoreOrderCraft.getMpsNo");
		sql = StringTool.ReplaceAll(sql, "#ORD_LN_PK#", ordLnPk);
		
		return this.getData(sql);
	}
	
	/**
	 * 设置MPS编号
	 * @param ordLnPk
	 * @param mpsNo
	 * @return
	 */
	public CoreReturnObject setMpsNo(String ordLnPk, String mpsNo){
		String sql = CoreXmlSqlParsersFactory.getSql("CoreOrderCraft.setMpsNo");
		sql = StringTool.ReplaceAll(sql, "#ORD_LN_PK#", ordLnPk);
		sql = StringTool.ReplaceAll(sql, "#MPS_NO#", mpsNo);
		return this.setData(sql);
	}
}
