package yem.wm.cm.ht.op;



import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.args.AfterOperationArgs;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import yem.base.common.module.version.helper.NewVersionHelper;

/**
 * 合同条款库审核变更赋值
 * @author zhangh
 *
 */
public class ClauseSetValueAuditOp extends AbstractOperationServicePlugIn{

	@Override
	public void afterExecuteOperationTransaction(AfterOperationArgs e) {
		for (DynamicObject dataEntity : e.getDataEntities()) {
			String name = dataEntity.getDataEntityType().getName();
			dataEntity = BusinessDataServiceHelper.loadSingleFromCache(dataEntity.getLong("id"), name);
			NewVersionHelper newVersionHelper = new NewVersionHelper(name);
			if (newVersionHelper.isChanged()) {
				DynamicObject sourceBill = BusinessDataServiceHelper.loadSingleFromCache(dataEntity.getLong("yem_masterid"), newVersionHelper.getRequireKey());
				sourceBill.set("yem_changeclause", dataEntity.getDynamicObject("yem_clausetype"));
				sourceBill.set("yem_changenamechina", dataEntity.getString("yem_clausechina"));
				sourceBill.set("yem_changeclauseeng", dataEntity.getString("yem_clauseenglish"));
				sourceBill.set("yem_changechina", dataEntity.getString("yem_clausecontentchina"));
				sourceBill.set("yem_changechina_tag", dataEntity.getString("yem_clausecontentchina_tag"));
				sourceBill.set("yem_changeenglish", dataEntity.getString("yem_clausecontentenglish"));
				sourceBill.set("yem_changeenglish_tag", dataEntity.getString("yem_clausecontentenglish_tag"));
				SaveServiceHelper.save(new DynamicObject[] {sourceBill});
			}
		}
	}
}
