如何实现检验单审核后发送消息提醒仓库进行入库处理时可以通过消息直接联查到收料单通知单
需求描述:以采购管理为例,收料通知单审核后下推检验单进行检验,检验单单据类型中设置了审核自动质检完成,采购管理参数中不勾选相关收料检验后自动入库的参数,想要在检验单审核质检完成后发送消息给仓库人员提醒通过收料通知单进行入库处理,但是通过消息平台配置发送的消息联查单据打开的是检验单而不是收料通知单,想要通过消息联查单据时可以直接打开对应收料通知单进行入库处理而不是打开检验单再上查对应收料通知单进行处理。
解决方案:以来料检验为例,给所有拥有仓管员角色的用户发送消息,详细二开方案如下:
1、系统内新增一个消息来源(注意生成的编码,后续代码中会使用):
2、检验单审核操作上挂二开插件,在插件中从检验单的link表体获取收料通知单的分录内码信息,通过分录内码查询数据库获取收料通知单编号、行号和单据内码信息用于发送消息和设置联查单据使用:
(说明:之所以从link表体获取收料通知单分录内码信息,是因为合并检验时检验单明细分录的源单信息只记录一个收料通知单分录的数据,而多次检验时检验单明细分录的源单信息是检验单而不是收料通知单,而link表体会记录完整的上游收料通知单分录内码信息,无论是合并检验还是多次检验)
3、示例代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using Kingdee.BOS.MessageCenter.Model;
using Kingdee.BOS.Core.MessageCenter;
using Kingdee.BOS.BusinessEntity.MessageCenter;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.K3.Core.MFG.EnumConst;
using Kingdee.BOS.Util;
using Kingdee.K3.Core.MFG.EntityHelper;
using Kingdee.BOS.Contracts.MessageCenter;
using Kingdee.K3.MFG.App;
using Kingdee.BOS.MessageCenter.Contracts;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS;
namespace TEST.K3.MFG.QM.App.ServicePlugIn.InspectBill
{
public class test : AbstractOperationServicePlugIn
{
public override void OnPreparePropertys(PreparePropertysEventArgs e)
{
base.OnPreparePropertys(e);
e.FieldKeys.Add(CONST_QM_InspectBill.CONST_FBillHead.KEY_FBusinessType);
e.FieldKeys.Add(CONST_QM_InspectBill.CONST_FReferDetail.KEY_FSrcBillNo);
e.FieldKeys.Add(CONST_QM_InspectBill.CONST_FReferDetail.KEY_FSrcEntryId);
e.FieldKeys.Add(CONST_QM_InspectBill.CONST_FReferDetail.KEY_FSrcEntrySeq);
e.FieldKeys.Add(CONST_QM_InspectBill.CONST_FReferDetail.KEY_FSrcInterId);
e.FieldKeys.Add(CONST_QM_InspectBill.CONST_FEntity.KEY_FInspectTimes);
}
public override void AfterExecuteOperationTransaction(BOS.Core.DynamicForm.PlugIn.Args.AfterExecuteOperationTransaction e)
{
base.AfterExecuteOperationTransaction(e);
Dictionary<long, string> srcBillDic = new Dictionary<long, string>();
IEnumerable<IGrouping<string, DynamicObject>> inspectBills =
e.DataEntitys.GroupBy(g => g.GetDynamicObjectItemValue<string>(CONST_QM_InspectBill.CONST_FBillHead.ORM_BusinessType)).ToList();
List<long> purEntryIds = new List<long>();
foreach (IGrouping<string, DynamicObject> inspectBill in inspectBills)
{
string businessType = inspectBill.Key;
if (businessType == "1" || businessType == "2")//来料检验
{
foreach (DynamicObject ibBill in inspectBill)
{
DynamicObjectCollection entrys = ibBill.GetDynamicValue<DynamicObjectCollection>(CONST_QM_InspectBill.CONST_FEntity.ENTITY_ORM_Entity);
foreach (DynamicObject entry in entrys)
{
DynamicObjectCollection linkEntrys = entry.GetDynamicValue<DynamicObjectCollection>(CONST_QM_InspectBill.CONST_FEntity_Link.ENTITY_ORM_FEntity_Link);
if (linkEntrys.IsEmpty()) continue;
//收料通知单相关link信息
List<DynamicObject> purLinkEntrys = linkEntrys.Where(o => o.GetDynamicValue<string>(CONST_QM_InspectBill.CONST_FEntity_Link.ORM_STableName) == "T_PUR_ReceiveEntry").ToList();
if (purLinkEntrys.IsEmpty()) continue;
List<long> curPurEntryIds = purLinkEntrys.Select(o => o.GetDynamicValue<long>(CONST_QM_InspectBill.CONST_FEntity_Link.ORM_SId)).ToList();//收料通知单分录内码集合
purEntryIds.AddRange(curPurEntryIds);
}
}
}
}
if (purEntryIds.IsEmpty()) return;
DynamicObjectCollection srcPurInfo = this.GetSrcPurInfo(this.Context, purEntryIds.Distinct().ToList());
if (srcPurInfo.IsEmpty()) return;
Dictionary<long, IGrouping<long, DynamicObject>> purDics = srcPurInfo.GroupBy(o => o.GetDynamicValue<long>("FTEID")).ToDictionary(d => d.Key);
//获取接收消息用户ID(这里是按角色查找的,查找所有有仓管员角色的用户ID,SCM06_SYS为角色编码)
List<long> allReceiverIds = new List<long>();
DynamicObjectCollection receiverInfos = this.GetMessageReceiverIds(this.Context, "SCM06_SYS");
if (!receiverInfos.IsEmpty())
{
allReceiverIds = receiverInfos.Select(o => o.GetDynamicValue<long>("FUSERID")).Distinct().ToList();
}
if (allReceiverIds.IsEmpty()) return;
foreach (IGrouping<string, DynamicObject> inspectBill in inspectBills)
{
string businessType = inspectBill.Key;
if (businessType == "1" || businessType == "2")//来料检验
{
foreach (DynamicObject ibBill in inspectBill)
{
DynamicObjectCollection entrys = ibBill.GetDynamicValue<DynamicObjectCollection>(CONST_QM_InspectBill.CONST_FEntity.ENTITY_ORM_Entity);
foreach (DynamicObject entry in entrys)
{
DynamicObjectCollection linkEntrys = entry.GetDynamicValue<DynamicObjectCollection>(CONST_QM_InspectBill.CONST_FEntity_Link.ENTITY_ORM_FEntity_Link);
if(linkEntrys.IsEmpty())continue;
//获取收料通知单相关link信息
List<DynamicObject> purLinkEntrys = linkEntrys.Where(o => o.GetDynamicValue<string>(CONST_QM_InspectBill.CONST_FEntity_Link.ORM_STableName) == "T_PUR_ReceiveEntry").ToList();
if(purLinkEntrys.IsEmpty())continue;
//获取源单分录内码即收料通知单分录内码
IEnumerable<IGrouping<long, DynamicObject>> purLinkGroups = linkEntrys.GroupBy(o => o.GetDynamicValue<long>(CONST_QM_InspectBill.CONST_FEntity_Link.ORM_SId));
foreach (IGrouping<long, DynamicObject> purLinkGroup in purLinkGroups)
{
long srcEntryId = purLinkGroup.FirstOrDefault().GetDynamicValue<long>(CONST_QM_InspectBill.CONST_FEntity_Link.ORM_SId);//收料单分录内码
IGrouping<long, DynamicObject> matchPurInfo = null;
if (!purDics.TryGetValue(srcEntryId, out matchPurInfo)) continue;
string srcBillNo = matchPurInfo.FirstOrDefault().GetDynamicValue<string>("FSRCBILLNO");
int srcBillSeq = matchPurInfo.FirstOrDefault().GetDynamicValue<int>("FSRCENTRYSEQ");
long srcInterId = matchPurInfo.FirstOrDefault().GetDynamicValue<long>("FID");
SimpleTextMessageSendInfo simpleTextMsgSendInfo = new SimpleTextMessageSendInfo();
simpleTextMsgSendInfo.Content = string.Format("收料通知单{0}第{1}行分录对应检验单已经审核可以下推入库", srcBillNo, srcBillSeq);
simpleTextMsgSendInfo.Title = string.Format("收料通知单{0}第{1}行分录对应检验单已经审核可以下推入库", srcBillNo, srcBillSeq); ;
simpleTextMsgSendInfo.Level = (int)MessageLevel.Normal;
simpleTextMsgSendInfo.MsgType = (int)MessageCenterMessageType.Bussines; //消息类别//消息等级
simpleTextMsgSendInfo.SenderId = this.Context.UserId; //消息发送人UserID
List<int> channelList = new List<int>();
channelList.Add((int)MessageChannelType.MessageCenter); //消息通道
simpleTextMsgSendInfo.ReceiverIds = allReceiverIds.ToArray(); //消息接收人UserID
simpleTextMsgSendInfo.Channels = channelList.ToArray(); //消息通道
simpleTextMsgSendInfo.SourceNumber = "XXLY000001"; //消息来源编码,单独新建一个
simpleTextMsgSendInfo.LinkPKId = Convert.ToString(srcInterId);//收料单内码
simpleTextMsgSendInfo.ObjectTypeId = "PUR_ReceiveBill";
//消息业务对象内码//消息业务对象FormID指定打开的业务对象、业务对象内码
AppServiceContext.GetService<IMessageSendService>().AsyncSendSimpleTextMessage(this.Context, simpleTextMsgSendInfo);
}
}
}
}
}
}
public DynamicObjectCollection GetSrcPurInfo(Context ctx, List<long> purEntryIds)
{
if (purEntryIds.IsEmpty()) return null;
StringBuilder sbSql = new StringBuilder();
sbSql.AppendLine(" SELECT DISTINCT ");
sbSql.AppendLine(" T0.FBILLNO AS FSRCBILLNO, TE.FSEQ AS FSRCENTRYSEQ, ");
sbSql.AppendLine(" TE.FENTRYID AS FTEID,T0.FID ");
sbSql.AppendLine(" FROM T_PUR_RECEIVEENTRY TE ");
sbSql.AppendLine(" INNER JOIN T_PUR_RECEIVE T0 ON TE.FID=T0.FID ");
sbSql.AppendLine(" INNER JOIN" + StringUtils.GetSqlWithCardinality(purEntryIds.Distinct().Count(), "@FID", 1, true) + @"T ON T.FID=TE.FENTRYID ");
sbSql.AppendLine(" ORDER BY T0.FBILLNO, TE.FSEQ ");
List<SqlParam> sqlParam = new List<SqlParam>();
sqlParam.Add(new SqlParam("@FID", KDDbType.udt_inttable, purEntryIds.Distinct().ToArray()));
return AppServiceContext.DbUtils.ExecuteDynamicObject(ctx, sbSql.ToString(), sqlParam.ToArray());
}
public DynamicObjectCollection GetMessageReceiverIds(Context ctx, string roleNumber)
{
if (roleNumber.IsNullOrEmptyOrWhiteSpace()) return null;
StringBuilder sbSql = new StringBuilder();
sbSql.AppendLine(" SELECT t1.FUSERID,t2.FORGID,t4.FNUMBER FROM T_SEC_USER t1 ");
sbSql.AppendLine(" INNER JOIN T_SEC_USERORG t2 ON t1.FUSERID=t2.FUSERID ");
sbSql.AppendLine(" INNER JOIN T_SEC_USERROLEMAP t3 ON t3.FENTITYID=t2.FENTITYID ");
sbSql.AppendLine(" INNER JOIN T_SEC_ROLE t4 on t4.FROLEID=t3.FROLEID AND t4.FNUMBER=@FROLENUMBER");
List<SqlParam> sqlParam = new List<SqlParam>();
sqlParam.Add(new SqlParam("@FROLENUMBER", KDDbType.String, roleNumber));
return AppServiceContext.DbUtils.ExecuteDynamicObject(ctx, sbSql.ToString(), sqlParam.ToArray());
}
}
}
4、实现效果:(说明:选中消息点击查看单据即可打开对应收料通知单)
5、补充说明:工程文件的references中按下图增加相关引用即可;
如何实现检验单审核后发送消息提醒仓库进行入库处理时可以通过消息直接联查到收料单通知单
本文2024-09-23 03:27:37发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-158997.html