package com.steering.pss.qcm.DAL;

import java.util.ArrayList;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.EntityTool;
import com.steering.comm.tools.SqlBuilder;
import com.steering.comm.tools.StringTool;
import com.steering.pss.qcm.model.ComBaseSplineCEntity;
import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;

public class ComBaseSplineCDAL extends DBCommon{

	public CoreReturnObject Query(String eic, String validflag){
		String sql = CoreXmlSqlParsersFactory.getSql("ComBaseSplineC.Query");
		sql = StringTool.ReplaceAll(sql, "#EIC#", eic);
		sql = StringTool.ReplaceAll(sql, "#VALIDFLAG#", validflag);
		return this.getData(sql);
	}
	
	public CoreReturnObject Query2(String eic){
		String sql = CoreXmlSqlParsersFactory.getSql("ComBaseSplineC.Query2");
		sql = StringTool.ReplaceAll(sql, "#EIC#", eic);
		return this.getData(sql);
	}
	
	public CoreReturnObject Save(ArrayList<String> jsons){
		ArrayList<String> sqllist = new ArrayList<String>();
		for(String json : jsons){
			ComBaseSplineCEntity splineCEntity = EntityTool.getEntityByJSONStr(json, ComBaseSplineCEntity.class);
			String sql = "";
			if(splineCEntity.getValidflag().equals("")){
				sql = CoreXmlSqlParsersFactory.getSql("ComBaseSplineC.Insert");
			}else{
				sql = CoreXmlSqlParsersFactory.getSql("ComBaseSplineC.Update");
			}
			sql = EntityTool.fillSqlByEntity(sql, splineCEntity);
			sqllist.add(sql);
		}
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
	}
	
	public CoreReturnObject UpdateValidflag(ArrayList<String> jsons, String validflag){
		ArrayList<String> sqllist = new ArrayList<String>();
		for(String json : jsons){
			ComBaseSplineCEntity splineCEntity = EntityTool.getEntityByJSONStr(json, ComBaseSplineCEntity.class);
			String sql = "";
			if(validflag.equals("0")){
				sql = CoreXmlSqlParsersFactory.getSql("ComBaseSplineC.Delete");
			}else{
				sql = CoreXmlSqlParsersFactory.getSql("ComBaseSplineC.Resume");
			}
			sql = EntityTool.fillSqlByEntity(sql, splineCEntity);
			sqllist.add(sql);
		}
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
	}
	
	public CoreReturnObject GetComBaseStd(){
		String sql = CoreXmlSqlParsersFactory.getSql("ComBaseSplineC.GetComBaseStd");
		return this.getData(sql);
	}

	/**
	 * 复制标准
	 * @param oldStdCode
	 * @param newStdCode
	 * @param newStdName
	 * @return
	 */
	public CoreReturnObject CopyStd(String oldStdCode, String newStdCode, String newStdName){
		SqlBuilder b = new SqlBuilder("ComBaseSplineC.CopyStd");
		b.Fill(new String[]{ oldStdCode, newStdCode, newStdName });
		return this.setData(b.toString());
	}
}
