package com.steering.pss.sale.price.server;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;

import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.EntityTool;
import com.steering.pss.sale.price.entity.SlmPriceBaseframeClassifyEntity;
import com.steering.pss.sale.price.entity.SlmPriceBaseframeSetEntity;
import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;
public class CorePriceBaseFrame extends DBCommon  {

	 /**
     * @param valid
     * @return
     */
    public CoreReturnObject query( String valid) {
      //  String sql = CoreXmlSqlParsersFactory.getSql("CorePriceFactorRange.query");
   
       // sql = sql.replaceAll("#VALIDFLAG#", valid);
        return this.getDataBySqlID("CorePriceBaseFrame.query",new Object[] { valid });
    }
    
	 /**
     * @param valid
     * @return
     */
    public CoreReturnObject queryRange(String frame_Id, String isValid) {
      //  String sql = CoreXmlSqlParsersFactory.getSql("CorePriceFactorRange.query");
   
       // sql = sql.replaceAll("#VALIDFLAG#", valid);
        return this.getDataBySqlID("CorePriceBaseFrame.queryRange",new Object[] {frame_Id, isValid });
    }
	
    /**
     * 查询价格因素
     * @return
     */
    public CoreReturnObject queryFacName() {

        Object[] obj = new Object[] {  };
        return this.getDataBySqlID("CorePriceBaseFrame.queryFacName", obj);

    }
    /**
     * 查询价格因素范围
     * @return
     */
    public CoreReturnObject queryRangeName() {

        Object[] obj = new Object[] {  };
        return this.getDataBySqlID("CorePriceBaseFrame.queryRangeName", obj);

    }
    public CoreReturnObject save(ArrayList<String> listJSON){
		ArrayList<String> sqllist = new ArrayList<String>();
		
		for(String strJSON : listJSON){
			SlmPriceBaseframeSetEntity PBFS = EntityTool.getEntityByJSONStr(strJSON, SlmPriceBaseframeSetEntity.class);
			if (PBFS.getValidflag().equals("")) {
				String sql_insert = CoreXmlSqlParsersFactory.getSql("CorePriceBaseFrame.insert");
				sql_insert = EntityTool.fillSqlByEntity(sql_insert, PBFS);
				sqllist.add(sql_insert);
			}
			else {
				String sql_update = CoreXmlSqlParsersFactory.getSql("CorePriceBaseFrame.update");
				sql_update = EntityTool.fillSqlByEntity(sql_update, PBFS);
				sqllist.add(sql_update);
			}				
		}
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
}
    
    public CoreReturnObject saveRange(ArrayList<String> listJSON){
		ArrayList<String> sqllist = new ArrayList<String>();
		
		for(String strJSON : listJSON){
			SlmPriceBaseframeClassifyEntity  PBFS = EntityTool.getEntityByJSONStr(strJSON, SlmPriceBaseframeClassifyEntity .class);
			if (PBFS.getValidflag().equals("")) {
				String sql_insert = CoreXmlSqlParsersFactory.getSql("CorePriceBaseFrame.insertRange");
				sql_insert = EntityTool.fillSqlByEntity(sql_insert, PBFS);
				sqllist.add(sql_insert);
			}
			else {
				String sql_update = CoreXmlSqlParsersFactory.getSql("CorePriceBaseFrame.updateRange");
				sql_update = EntityTool.fillSqlByEntity(sql_update, PBFS);
				sqllist.add(sql_update);
			}				
		}
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
}
    
    
    public CoreReturnObject deleteOrResume(ArrayList<String> listJSON,Boolean flag){
		ArrayList<String> sqllist = new ArrayList<String>();
		
		for(String strJSON : listJSON){
			SlmPriceBaseframeSetEntity PBFS = EntityTool.getEntityByJSONStr(strJSON, SlmPriceBaseframeSetEntity.class);
			if (flag) {
				String sql_delete = CoreXmlSqlParsersFactory.getSql("CorePriceBaseFrame.Delete");
				sql_delete = EntityTool.fillSqlByEntity(sql_delete, PBFS);
				sqllist.add(sql_delete);
			}
			else {
				String sql_resume = CoreXmlSqlParsersFactory.getSql("CorePriceBaseFrame.Resume");
				sql_resume = EntityTool.fillSqlByEntity(sql_resume, PBFS);
				sqllist.add(sql_resume);
			}				
		}
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
}
    /**
     * 查询数据是否能够恢复
     * @param CLASS_D_ID
   
     * @return
     * @throws SQLException 
     */
    public CoreReturnObject canResume(ArrayList<String> listJSON) throws SQLException {

		String strJSON = listJSON.get(0);
		SlmPriceBaseframeSetEntity PBFS = EntityTool.getEntityByJSONStr(
				strJSON, SlmPriceBaseframeSetEntity.class);

		String sql_canResume = CoreXmlSqlParsersFactory
				.getSql("CorePriceBaseFrame.canResume");
		sql_canResume = EntityTool.fillSqlByEntity(sql_canResume, PBFS);
			
		return this.getData(sql_canResume);
    }
    
    
}
