package com.kingdee.eas.custom.emp;

import java.util.List;

import org.apache.log4j.Logger;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.custom.emp.MultiDataToPersonBaseSqlLoader.SqlTask;
import com.kingdee.eas.util.app.DbUtil;

public class MultiDataToPersonBaseFacadeControllerBean extends AbstractMultiDataToPersonBaseFacadeControllerBean {
	private static final Logger logger = Logger
			.getLogger("com.kingdee.eas.custom.emp.MultiDataToPersonBaseFacadeControllerBean");

	private static final String DIALECT_PREFIX = "/*dialect*/ ";

	protected void _syncMultiDataToBase(Context ctx) throws BOSException, EASBizException {
		logger.info("syncMultiDataToBase start");

		List<SqlTask> tasks = MultiDataToPersonBaseSqlLoader.loadTasks();
		for (int i = 0; i < tasks.size(); i++) {
			SqlTask task = tasks.get(i);
			logger.info("execute sync sql [" + (i + 1) + "/" + tasks.size() + "] id=" + task.getId() + ", desc="
					+ task.getDesc() + ", dialect=" + task.isDialect());
			executeSql(ctx, task);
		}

		logger.info("syncMultiDataToBase finish");
	}

	private void executeSql(Context ctx, SqlTask task) throws BOSException {
		String sql = task.getSql();
		if (task.isDialect()) {
			DbUtil.execute(ctx, DIALECT_PREFIX + sql);
		} else {
			DbUtil.execute(ctx, sql);
		}
	}
}
