package nc.impl.tbb;

import java.util.List;
import java.util.Map;

import nc.bs.framework.common.NCLocator;
import nc.itf.tbb.IBudgetService;
import nc.itf.uap.IUAPQueryBS;
import nc.jdbc.framework.processor.BeanProcessor;
import nc.ms.tb.control.CtlSchemeCTL;
import nc.ms.tb.rule.CtlSchemeServiceGetter;
import nc.vo.tb.task.MdTask;

public class BudgetServiceImpl implements IBudgetService{
	IUAPQueryBS iuap= (IUAPQueryBS) NCLocator.getInstance().lookup(IUAPQueryBS.class.getName());
	@Override
	public void reset_RequiresNew(String entityPk, String pk_year) throws Exception {
		String sWhere_cube = "pk_plan in (SELECT pk_obj FROM tb_md_task WHERE planstatus <> '000' and versionstatus in ( '00', '08', '06' ) and pk_planent = '"+entityPk+"' and pk_year = '"+pk_year+"' and ( BUSISYSTEM = 'TB' ) ) and isstarted = 'Y' and pk_parent is not null";
		Map<String, List<String>> ctlmap_Cube = CtlSchemeServiceGetter.getICtlScheme().queryCtrlSchemeSimply(sWhere_cube);
		//ctlmap_Cube不等于0表示该控制方案已经停用不需要重新启用停用
		if(ctlmap_Cube.size() != 0) {
			//停用控制方案
			CtlSchemeServiceGetter.getICtlScheme().deleteCtrlScheme(ctlmap_Cube);
			//启用控制方案
			String sql =  "SELECT * FROM tb_md_task WHERE planstatus <> '000' and versionstatus in ( '00', '08', '06' ) and pk_planent = '"+entityPk+"' and pk_year = '"+pk_year+"' and ( BUSISYSTEM = 'TB' )";
			MdTask mdTask = (MdTask) iuap.executeQuery(sql, new BeanProcessor(MdTask.class));
			CtlSchemeCTL.onUseAllCrelSchemeInClient(new MdTask[] {mdTask});
		}
		
	}

}
