package com.steering.pss.qcm;

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.pss.qcm.model.BaseStdRSpecEntity;

public class BaseStdRSpec extends DBCommon{

    /**
     * 查询标准与适用规格关系数据
     * @param strJSON 参数
     * @return obj
     */
	public CoreReturnObject query(String strJSON){
		JSONObject obj = JSONObject.fromObject(strJSON);
		BaseStdRSpecEntity baseStdRSpec = (BaseStdRSpecEntity)JSONObject.toBean(obj, BaseStdRSpecEntity.class);
		String sql = CoreXmlSqlParsersFactory.getSql("BaseStdRSpec.query");
		//sql = fillSql(sql, baseStdRSpec);
		sql = EntityTool.fillSqlByEntity(sql, baseStdRSpec);
		
		return this.getData(sql);
	}
	
	/**
	 * 操作标准与适用规格关系数据
	 * @param list 参数
	 * @return obj
	 */
	public CoreReturnObject noQuery(ArrayList<String> list, String strAction){
		ArrayList<String> sqllist = new ArrayList<String>();
		String sqlSaveTmp = CoreXmlSqlParsersFactory.getSql("BaseStdRSpec.save");
		String sqlupdateStateTmp = CoreXmlSqlParsersFactory.getSql("BaseStdRSpec.updateState");
		for(int i = 0; i < list.size(); i++){
			String sql = "";
			if(strAction.equals("Save"))
			{
				sql = sqlSaveTmp;
			}
			else if(strAction.equals("Delete") || strAction.equals("Resume"))
			{
				sql = sqlupdateStateTmp;
			}
			String strJSON = list.get(i);
			JSONObject obj = JSONObject.fromObject(strJSON);
			BaseStdRSpecEntity baseStdRSpec = (BaseStdRSpecEntity)JSONObject.toBean(obj, BaseStdRSpecEntity.class);
			//sql = fillSql(sql, baseStdRSpec);
			sql = EntityTool.fillSqlByEntity(sql, baseStdRSpec);
			
			sqllist.add(sql);
		}
		
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
	}
	
	/**
	 * 获取最终操作标准与规格关系的数据。
	 * @param list
	 * @param strAction
	 * @return
	 */
	public  ArrayList<String> getNoQuerySqlList(ArrayList<String> list, String strAction){
		ArrayList<String> sqllist = new ArrayList<String>();
		String sqlSaveTmp = CoreXmlSqlParsersFactory.getSql("BaseStdRSpec.save");
		String sqlupdateStateTmp = CoreXmlSqlParsersFactory.getSql("BaseStdRSpec.updateState");
		for(int i = 0; i < list.size(); i++){
			String sql = "";
			if(strAction.equals("Save"))
			{
				sql = sqlSaveTmp;
			}
			else if(strAction.equals("Delete") || strAction.equals("Resume"))
			{
				sql = sqlupdateStateTmp;
			}
			String strJSON = list.get(i);
			JSONObject obj = JSONObject.fromObject(strJSON);
			BaseStdRSpecEntity baseStdRSpec = (BaseStdRSpecEntity)JSONObject.toBean(obj, BaseStdRSpecEntity.class);
			//sql = fillSql(sql, baseStdRSpec);
			sql = EntityTool.fillSqlByEntity(sql, baseStdRSpec);
			sqllist.add(sql);
		}
		
		return sqllist;
	}
	
	/**
	 * 是否存在规格范围
	 * @return obj
	 */
	public CoreReturnObject isExistSpec(String strJSON){
		JSONObject obj = JSONObject.fromObject(strJSON);
		BaseStdRSpecEntity baseStdRSpec = (BaseStdRSpecEntity)JSONObject.toBean(obj, BaseStdRSpecEntity.class);
		String sql = CoreXmlSqlParsersFactory.getSql("BaseStdRSpec.isExistSpec");
		//sql = fillSql(sql, baseStdRSpec);
		sql = EntityTool.fillSqlByEntity(sql, baseStdRSpec);
		
		return this.getData(sql);
	}
}
