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.SlmPriceBaseframeSetEntity;
import com.steering.pss.sale.price.entity.SlmPriceDocEntity;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;
public class CorePriceBaseDoc extends DBCommon {
	
    /**
     * 查询数据
     * @param PRICE_VER_ID
     * @param PRICE_VER_DESC
     * @param valid
     * @return
     */
    public CoreReturnObject query(String PRICE_VER_ID, String PRICE_VER_DESC, String valid) {
        String sql = CoreXmlSqlParsersFactory.getSql("CorePriceDoc.query");
        sql = sql.replaceAll("#PRICE_VER_ID#", PRICE_VER_ID);
        sql = sql.replaceAll("#PRICE_VER_DESC#", PRICE_VER_DESC);
        sql = sql.replaceAll("#VALIDFLAG#", valid);
        return this.getData(sql);
    }
    
    public CoreReturnObject save(ArrayList<String> listJSON){
		ArrayList<String> sqllist = new ArrayList<String>();
		
		for(String strJSON : listJSON){
			SlmPriceDocEntity PBFS = EntityTool.getEntityByJSONStr(strJSON, SlmPriceDocEntity.class);
			if (PBFS.getValidflag().equals("")) {
				String sql_insert = CoreXmlSqlParsersFactory.getSql("CorePriceDoc.insert");
				sql_insert = EntityTool.fillSqlByEntity(sql_insert, PBFS);
				sqllist.add(sql_insert);
			}
			else {
				String sql_update = CoreXmlSqlParsersFactory.getSql("CorePriceDoc.update");
				sql_update = EntityTool.fillSqlByEntity(sql_update, PBFS);
				sqllist.add(sql_update);
			}				
		}
		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);
		SlmPriceDocEntity PBFS = EntityTool.getEntityByJSONStr(
				strJSON, SlmPriceDocEntity.class);

		String sql_canResume = CoreXmlSqlParsersFactory
				.getSql("CorePriceDoc.canResume");
		sql_canResume = EntityTool.fillSqlByEntity(sql_canResume, PBFS);
			
		return this.getData(sql_canResume);
    }
    public CoreReturnObject deleteOrResume(ArrayList<String> listJSON,Boolean flag){
		ArrayList<String> sqllist = new ArrayList<String>();
		
		for(String strJSON : listJSON){
			SlmPriceDocEntity PBFS = EntityTool.getEntityByJSONStr(strJSON, SlmPriceDocEntity.class);
			if (flag) {
				String sql_delete = CoreXmlSqlParsersFactory.getSql("CorePriceDoc.Delete");
				sql_delete = EntityTool.fillSqlByEntity(sql_delete, PBFS);
				sqllist.add(sql_delete);
			}
			else {
				String sql_resume = CoreXmlSqlParsersFactory.getSql("CorePriceDoc.Resume");
				sql_resume = EntityTool.fillSqlByEntity(sql_resume, PBFS);
				sqllist.add(sql_resume);
			}				
		}
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
}

}
