package yem.wm.cm.ht.op;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.args.AfterOperationArgs;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;

/**
 * 四大合同源单反审核将合同条款中的是否调整改为否
 * @author zhangh
 *
 */
public class ContractClauseUnAuditOp extends AbstractOperationServicePlugIn{

	@Override
	public void afterExecuteOperationTransaction(AfterOperationArgs e) {
		if (this.getOperationResult().isSuccess()) {
			DynamicObject[] dataEntity = e.getDataEntities();
			for (DynamicObject data : dataEntity) {
				data = BusinessDataServiceHelper.loadSingleFromCache(data.getPkValue(), data.getDataEntityType().getName());
				updateChangenum(data);
			}
		}
	}

	/**
	 * 反审核修改是否
	 * @param data
	 */
	private void updateChangenum(DynamicObject data) {
		DynamicObjectCollection yem_clauseimport = data.getDynamicObjectCollection("yem_clauseimport");
		for (int i = 0; i < yem_clauseimport.size(); i++) {
			DynamicObject clauseimport = yem_clauseimport.get(i);
			clauseimport.set("yem_change", false);
			clauseimport.set("yem_changenum", 0);
		}
		SaveServiceHelper.save(new DynamicObject[] {data});
	}
}
