package com.steering.pss.qcm;
import java.util.ArrayList;

import net.sf.json.JSONObject;
import com.steering.pss.qcm.model.*;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.EntityTool;
import com.steering.comm.tools.StringTool;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;
/**
 * 钢种与规格关系维护
 * @author Administrator
 *
 */
public class GrandeRSpec extends DBCommon {
	/**
	 * 查询钢种
	 * @param strJSON 钢种实体类JSON字符串
	 * @return Obj
	 */
	public CoreReturnObject queryGrade(String strJSON) {
		JSONObject obj = JSONObject.fromObject(strJSON);
		ComMscGradeEntity gradeEntity = (ComMscGradeEntity)JSONObject.toBean(obj, ComMscGradeEntity.class);
		String sql = CoreXmlSqlParsersFactory.getSql("GrandeRSpec.queryGrade");
		sql = EntityTool.fillSqlByEntity(sql, gradeEntity);
		
		return this.getData(sql);
	}
	
	/**
	 * 查询规格范围
	 * @param strJSON 钢种实体类JSON字符串。
	 * @return obj
	 */
	public CoreReturnObject querySpec(String strJSON, String strIsDelete){
		JSONObject obj = JSONObject.fromObject(strJSON);
		ComMscGradeEntity gradeEntity = (ComMscGradeEntity)JSONObject.toBean(obj, ComMscGradeEntity.class);
		String sql = CoreXmlSqlParsersFactory.getSql("GrandeRSpec.querySpec");
		sql = EntityTool.fillSqlByEntity(sql, gradeEntity);
		sql = StringTool.ReplaceAll(sql, "#IS_DELETE#", strIsDelete);
		return this.getData(sql);
	}
	
	/**
	 * 保存规格范围
	 * @param strJSONs 规格实体类JSON字符串
	 * @return obj
	 */
	public CoreReturnObject saveSpec(String gradeJson, ArrayList<String> strJSONs){
		ArrayList<String> sqllist = new ArrayList<String>();
		
		ComMscGradeEntity gradeEntity = (ComMscGradeEntity)EntityTool.getEntityByJSONStr(gradeJson, ComMscGradeEntity.class);
		String sqlUpdateGrade = CoreXmlSqlParsersFactory.getSql("GrandeRSpec.UpdateGrade");
		sqlUpdateGrade = EntityTool.fillSqlByEntity(sqlUpdateGrade, gradeEntity);
		sqllist.add(sqlUpdateGrade);
		
		for(int i = 0; i < strJSONs.size(); i++){
			JSONObject obj = JSONObject.fromObject(strJSONs.get(i));
			ComMscGradeRSpecEntity specEntity = (ComMscGradeRSpecEntity)JSONObject.toBean(obj, ComMscGradeRSpecEntity.class);
			String sql = CoreXmlSqlParsersFactory.getSql("GrandeRSpec.SaveSpec");
			sql = EntityTool.fillSqlByEntity(sql, specEntity);
			sqllist.add(sql);
		}
		
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
	}
	
	/**
	 * 作废或者恢复规格范围
	 * @return obj
	 */
	public CoreReturnObject deleteOrResumeSpec(ArrayList<String> strJSONs){
		ArrayList<String> sqllist = new ArrayList<String>();
		for(int i = 0; i < strJSONs.size(); i++){
			JSONObject obj = JSONObject.fromObject(strJSONs.get(i));
			ComMscGradeRSpecEntity specEntity = (ComMscGradeRSpecEntity)JSONObject.toBean(obj, ComMscGradeRSpecEntity.class);
			String sql = CoreXmlSqlParsersFactory.getSql("GrandeRSpec.deleteOrResumeSpec");
			sql = EntityTool.fillSqlByEntity(sql, specEntity);
			sqllist.add(sql);
		}
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
	}
	
	public CoreReturnObject isExitSpec(String strJSON){
		JSONObject obj = JSONObject.fromObject(strJSON);
		ComMscGradeRSpecEntity specEntity = (ComMscGradeRSpecEntity)JSONObject.toBean(obj, ComMscGradeRSpecEntity.class);
		String sql = CoreXmlSqlParsersFactory.getSql("GrandeRSpec.isExistSpec");
		sql = EntityTool.fillSqlByEntity(sql, specEntity);
		return this.getData(sql);
	}
}
