package tqq9.lc123.cloud.app.plugin.operate.ap; import kd.bos.algo.DataSet; import kd.bos.dataentity.entity.DynamicObject; import kd.bos.dataentity.entity.DynamicObjectCollection; import kd.bos.db.DB; import kd.bos.db.DBRoute; import kd.bos.entity.ExtendedDataEntity; import kd.bos.entity.ExtendedDataEntitySet; import kd.bos.entity.botp.plugin.AbstractConvertPlugIn; import kd.bos.entity.botp.plugin.args.AfterConvertEventArgs; import kd.bos.logging.Log; import kd.bos.logging.LogFactory; import kd.bos.orm.ORM; import kd.sdk.plugin.Plugin; import tqq9.lc123.cloud.app.plugin.operate.im.PurOrderPushReceiptNoticePlugin; import java.math.BigDecimal; import java.util.Map; /** * 单据转换插件 */ public class PurApplySyncSupplierDeductPlugin extends AbstractConvertPlugIn implements Plugin { private final static Log logger = LogFactory.getLog(PurApplySyncSupplierDeductPlugin.class); private static String RECEIPTNOTICE = "ap_payapply"; @Override public void afterConvert(AfterConvertEventArgs e) { super.afterConvert(e); ExtendedDataEntitySet targetExtDataEntitySet = e.getTargetExtDataEntitySet(); ExtendedDataEntity[] extendedDataEntities = targetExtDataEntitySet.FindByEntityKey(RECEIPTNOTICE); // Map variables = this.getOption().getVariables(); for (ExtendedDataEntity extendedDataEntity : extendedDataEntities) { //付款申请单 DynamicObject dataEntity = extendedDataEntity.getDataEntity(); DynamicObjectCollection dynamicObjectCollection = dataEntity.getDynamicObjectCollection("entry"); DynamicObject e_asstact = dynamicObjectCollection.get(0).getDynamicObject("e_asstact"); if (e_asstact != null) { long id = e_asstact.getLong("id"); String sql = "/*dialect*/select fasstactid,sum(funsettleamount) qty from t_ap_finapbill WHERE fsettlestatus in ('unsettle','partsettle') " + "and fiswrittenoff='0' and fbillstatus ='C' and funsettleamount<0 AND fasstactid=" + id + " group by fasstactid"; DataSet dataSet = DB.queryDataSet(this.getClass().getName(), DBRoute.of("cas"), sql); DataSet copy = dataSet.copy(); DynamicObjectCollection dynamicObjects = ORM.create().toPlainDynamicObjectCollection(copy); BigDecimal qty = dynamicObjects.get(0).getBigDecimal("qty"); dataEntity.set("tqq9_gyskdkzje",qty); } } } }