1、在生产订单审核操作上配置自动下推服务,如下图:
2、二开服务端插件,挂在生产订单的审核操作上,代码如下
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using Kingdee.BOS.Util;
using Kingdee.K3.Core.MFG.EntityHelper;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS;
using Kingdee.K3.MFG.App;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Orm;
namespace EK.Kingdee.K3.MFG.PRD.App.ServicePlugIn
{
[Description("生产订单审核自动下推汇报单之后,汇报单自动提交,审核")]
public class MoAudit : AbstractOperationServicePlugIn
{
/// <summary>
/// 【生产订单.明细】实体名
/// </summary>
public static string KEY_Entity = "TreeEntity";
public override void AfterExecuteOperationTransaction(global::Kingdee.BOS.Core.DynamicForm.PlugIn.Args.AfterExecuteOperationTransaction e)
{
base.AfterExecuteOperationTransaction(e);
if (e.DataEntitys.IsEmpty()) return;
var entryDatas = from data in e.DataEntitys
from row in data.GetDynamicValue<DynamicObjectCollection>(KEY_Entity)
select row;
if (entryDatas.IsEmpty()) return;
List<long> moEntryIds = entryDatas.Select(s => s.GetDynamicValue<long>("ID")).Distinct().ToList();
string sql = string.Format(@"SELECT T.FID FROM T_PRD_MORPT TR
INNER JOIN T_PRD_MORPTENTRY T ON TR.FID=T.FID AND TR.FDOCUMENTSTATUS='A'
INNER JOIN {0} TT ON T.FMOENTRYID=TT.FID", StringUtils.GetSqlWithCardinality(moEntryIds.Distinct().Count(), "@MOENTRYIDS", 1));
List<SqlParam> sqlParams = new List<SqlParam>();
sqlParams.Add(new SqlParam("@MOENTRYIDS", KDDbType.udt_inttable, moEntryIds.Distinct().ToArray()));
DynamicObjectCollection objs = AppServiceContext.DbUtils.ExecuteDynamicObject(this.Context, sql, sqlParams.ToArray());
if (objs.IsEmpty()) return;
//提交
List<object> pkIds = new List<object>();
List<KeyValuePair<object, object>> pkEntryIds = new List<KeyValuePair<object, object>>();
foreach (DynamicObject targetBill in objs)
{
pkIds.Add(targetBill["FID"]);
pkEntryIds.Add(new KeyValuePair<object, object>(targetBill["FID"], ""));
}
FormMetadata targetForm = (FormMetadata)AppServiceContext.MetadataService.Load(this.Context, "PRD_MORPT");
OperateOption option = OperateOption.Create();
IOperationResult submitOperateTarget = AppServiceContext.SubmitService.Submit(this.Context, targetForm.BusinessInfo, pkIds.ToArray(), "Submit", option);
if (submitOperateTarget.IsSuccess)
{
//审核
List<object> paraAudit = new List<object>();
//1审核通过
paraAudit.Add("1");
//审核意见
paraAudit.Add("");
IOperationResult auditOperateTarget = AppServiceContext.SetStatusService.SetBillStatus(this.Context, targetForm.BusinessInfo, pkEntryIds, paraAudit, "Audit", option);
}
}
}
}
推荐阅读
您的鼓励与嘉奖将成为创作者们前进的动力,如果觉得本文还不错,可以给予作者创作打赏哦!
请选择打赏金币数 *