package com.steering.pss.qcm.DAL;

import java.util.ArrayList;
import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.EntityTool;
import com.steering.comm.tools.SqlBuilder;
import com.steering.comm.tools.TransctionTool;
import com.steering.pss.qcm.model.ComBaseImpactCEntity;

public class ComBaseImpactTempCDAL extends DBCommon {

	/**
	 * 通用查询
	 */
	public CoreReturnObject Query(String id, String validflag) {
		SqlBuilder b = new SqlBuilder("ComBaseImpactTempCDAL.Query");
		b.Fill(new String[] { id, validflag });
		return this.getData(b.toString());
	}

	/**
	 * 修改有效标志
	 */
	public CoreReturnObject UpdateValidflag(ArrayList<String> jsons,
			String validflag) {
		TransctionTool transction = new TransctionTool();
		try {
			for (String json : jsons) {
				ComBaseImpactCEntity comBaseImpactCEntity = EntityTool
						.getEntityByGson(json, ComBaseImpactCEntity.class);
				String sqlUpdateValidflag = "";
				if (validflag.equals("0")) {
					sqlUpdateValidflag = CoreXmlSqlParsersFactory
							.getSql("ComBaseImpactTempCDAL.Delete");
				} else {
					sqlUpdateValidflag = CoreXmlSqlParsersFactory
							.getSql("ComBaseImpactTempCDAL.Resume");
				}
				sqlUpdateValidflag = EntityTool.fillSqlByEntity(
						sqlUpdateValidflag, comBaseImpactCEntity);
				if (!transction.ExcuteTransction(sqlUpdateValidflag)) {
					return transction.rollBack();
				}
			}
		} catch (Exception ex) {
			CoreReturnObject cro = transction.rollBack();
			cro.setV_errMsg(ex.getMessage());
			return cro;
		}
		return transction.commit();
	}
}
