操作插件反写上游子单据体原创
84人赞赏了该文章
692次浏览
编辑于2023年10月28日 11:58:48
当上游单据是子单据体下推 时,反写规则无法配置生效。
知识中的“反写上游子单据体”方法需要创建一个 虚拟反写规则,同时所有反写、校验都是需要插件实现。还需要在上游子单据体对应的单据体加隐藏字段。
我尝试了一种操作插件来实现反写与校验,欢迎大伙来参考或拍砖。
一、保存操作插件:实现反写、超额检查
特殊点:反写时 查一次数据库,取上游子单据体对应 的所有下游单据(除本单)的数量和 + 本单数量, 更新上游子单据体分录。 排除本单取汇总的目的是不用判断与记录是否保存后再修改保存。
public override void BeginOperationTransaction(BeginOperationTransactionArgs e) { foreach (DynamicObject o in e.DataEntitys) { } } /// <summary> /// 操作结束后功能处理 /// </summary> /// <param name="e"></param> public override void EndOperationTransaction(EndOperationTransactionArgs e) { foreach (DynamicObject o in e.DataEntitys) { UpdateSrcQty(o); } } private void UpdateSrcQty(DynamicObject dataEntity) { if (dataEntity["F_PBVD_SubEntryId"] == null || dataEntity["F_PBVD_SubEntryId"].ToString().IsNullOrEmptyOrWhiteSpace()) { return; } long srcSubEntryID = Convert.ToInt64(dataEntity["F_PBVD_SubEntryId"]); if (Math.Abs(srcSubEntryID) <= 10) { return; } decimal billQty = Convert.ToDecimal(dataEntity["F_PBVD_SumQty"]); string billID = dataEntity["Id"].ToString(); string strSql = $@"/*dialect*/update a set F_PBVD_GLYLQty = {billQty} + isnull(b.FQTY,0) from T_SAL_DELIVERYEntrySubDYYL a left join ( select t1.FDetailID,isnull(sum(t2.F_PBVD_SumQty),0) as FQTY from T_SAL_DELIVERYEntrySubDYYL t1 left join T_PLN_RESERVEBILL t2 on t1.FDetailID = t2.F_PBVD_SUBENTRYID and t2.FID <> '{billID}' where t1.FDetailID = '{srcSubEntryID}' group by t1.FDetailID ) b on a.FDetailID = b.FDetailID where a.FDetailID = '{srcSubEntryID}' "; DBUtils.Execute(this.Context, strSql); } /// <summary> /// 当前操作的校验器 /// </summary> private class OperValidator : AbstractValidator { public override void Validate(Kingdee.BOS.Core.ExtendedDataEntity[] dataEntities, ValidateContext validateContext, Kingdee.BOS.Context ctx) { foreach (var dataEntity in dataEntities) { bool isError = false; if (dataEntity["F_PBVD_SubEntryId"] == null || dataEntity["F_PBVD_SubEntryId"].ToString().IsNullOrEmptyOrWhiteSpace()) { return; } long srcSubEntryID = Convert.ToInt64(dataEntity["F_PBVD_SubEntryId"]); if (Math.Abs(srcSubEntryID) <= 10) { continue; } string billID = dataEntity["Id"].ToString(); string strSql = $@"/*dialect*/select t1.FDetailID,t1.F_PAEZ_YLSLDY,isnull(sum(t2.F_PBVD_SumQty),0) as FQTY from T_SAL_DELIVERYEntrySubDYYL t1 left join T_PLN_RESERVEBILL t2 on t1.FDetailID = t2.F_PBVD_SUBENTRYID and t2.FID <> '{billID}' where t1.FDetailID = '{srcSubEntryID}' group by t1.FDetailID,t1.F_PAEZ_YLSLDY "; DynamicObjectCollection docDatas = DBUtils.ExecuteDynamicObject(this.Context, strSql); string errMessage = string.Empty; if (docDatas == null || docDatas.Count() <= 0) { isError = true; errMessage = "销售订单评审单数据查询异常!"; } else { decimal srcQty = Convert.ToDecimal(docDatas[0]["F_PAEZ_YLSLDY"]); decimal allQty = Convert.ToDecimal(docDatas[0]["FQTY"]); decimal billQty = Convert.ToDecimal(dataEntity["F_PBVD_SumQty"]); if (srcQty < allQty + billQty) { isError = true; errMessage = $@"超过销售订单评审单【预留数量】【{srcQty}】!已生成计划订单数量【{allQty}】,本次下推数量【{billQty}】"; } } if (isError) { ValidationErrorInfo ValidationErrorInfo = new ValidationErrorInfo( string.Empty, dataEntity["Id"].ToString(), dataEntity.DataEntityIndex, dataEntity.RowIndex, dataEntity["Id"].ToString(), errMessage, string.Empty); validateContext.AddError(null, ValidationErrorInfo); continue; } } } }
二、删除操作插件,更新反写一次。 取上游子单据体对应 的所有下游单据(除本单)的数量和 , 更新上游子单据体分录。 排除本单取汇总的目的是本单会删除。
特殊点:EndOperationTransaction,写在这个方法中,不知道如果删除不成功,是否会回滚。
public override void EndOperationTransaction(EndOperationTransactionArgs e) { base.EndOperationTransaction(e); foreach (DynamicObject o in e.DataEntitys) { UpdateSrcQty(o); } } private void UpdateSrcQty(DynamicObject dataEntity) { if (dataEntity["F_PBVD_SubEntryId"] == null || dataEntity["F_PBVD_SubEntryId"].ToString().IsNullOrEmptyOrWhiteSpace()) { return; } long srcSubEntryID = Convert.ToInt64(dataEntity["F_PBVD_SubEntryId"]); if (Math.Abs(srcSubEntryID) <= 10) { return; } //decimal billQty = Convert.ToDecimal(dataEntity["SugQty"]); string billID = dataEntity["Id"].ToString(); string strSql = $@"/*dialect*/update a set F_PBVD_GLYLQty = isnull(b.FQTY,0) from T_SAL_DELIVERYEntrySubDYYL a left join ( select t1.FDetailID,isnull(sum(t2.F_PBVD_SumQty),0) as FQTY from T_SAL_DELIVERYEntrySubDYYL t1 left join T_PLN_RESERVEBILL t2 on t1.FDetailID = t2.F_PBVD_SUBENTRYID and t2.FID <> '{billID}' where t1.FDetailID = '{srcSubEntryID}' group by t1.FDetailID ) b on a.FDetailID = b.FDetailID where a.FDetailID = '{srcSubEntryID}' "; DBUtils.Execute(this.Context, strSql); }
赞 84
84人点赞
还没有人点赞,快来当第一个点赞的人吧!
打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!
推荐阅读