二开案例.列表插件.信息中心流程消息查看单据时取消验权
【应用场景】
信息中心流程消息查看单据时,默认会验证当前登录用户的查看权限,可通过插件取消验权。
【案例演示】
信息中心流程消息查看单据时取消验权。
【实现步骤】
<1>编写列表插件,代码如下。
using Kingdee.BOS; using Kingdee.BOS.Core.Bill; using Kingdee.BOS.Core.DynamicForm; using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; using Kingdee.BOS.Core.Metadata; using Kingdee.BOS.Core.Metadata.FieldElement; using Kingdee.BOS.Core.Metadata.FormElement; using Kingdee.BOS.Core.Permission; using Kingdee.BOS.Core.SqlBuilder; using Kingdee.BOS.Msg; using Kingdee.BOS.Orm.DataEntity; using Kingdee.BOS.ServiceHelper; using Kingdee.BOS.Util; using Kingdee.BOS.Workflow.PlugIns; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; namespace Jac.XkDemo.BOS.Business.PlugIn { /// <summary> /// 【列表插件】信息中心流程消息查看单据时取消验权 /// 使用说明: /// 1.扩展信息中心_收件箱[WF_MessageBill] /// 2.注册二开的列表插件:Jac.XkDemo.BOS.Business.PlugIn.WorkCenterOpenBillCancelCheckRightListPlugIn, Jac.XkDemo.BOS.Business.PlugIn /// 3.禁用标准产品的列表插件:Kingdee.BOS.Workflow.PlugIns.MessageList, Kingdee.BOS.Workflow.PlugIns /// </summary> [Description("【列表插件】信息中心流程消息查看单据时取消验权"), HotUpdate] public class WorkCenterOpenBillCancelCheckRightListPlugIn : MessageList { public override void BarItemClick(BarItemClickEventArgs e) { if (e.BarItemKey.EqualsIgnoreCase("TBVIEWBILL")) { var selectedRow = this.ListView.CurrentSelectedRowInfo; if (selectedRow == null) { return; } DynamicObject obj = BusinessDataServiceHelper.LoadSingle(this.Context, selectedRow.PrimaryKeyValue, this.View.BillBusinessInfo.GetDynamicObjectType()); string objectTypeId = (string) obj["ObjectTypeId_Id"]; string keyValue = (string) obj["KeyValue"]; MsgType msgType = (MsgType) Convert.ToInt32(obj["TYPE"]); WorkflowPlugInHelper.OpenBillWindow(this.View, objectTypeId, keyValue, msgType); return; } base.BarItemClick(e); } #region WorkflowPlugInHelper public class WorkflowPlugInHelper { public static void OpenBillWindow(IDynamicFormView view, string formId, string keyValue, MsgType msgType = MsgType.CommonMessage, ShowType showType = ShowType.MainNewTabPage) { try { if (string.IsNullOrWhiteSpace(formId) || string.IsNullOrWhiteSpace(keyValue)) { view.ShowNotificationMessage(Kingdee.BOS.Resource.ResManager.LoadKDString("未关联单据,或者关联的单据已经被删除!", "002406030017566", Kingdee.BOS.Resource.SubSystemType.BOS)); return; } // 验查看权 //if (!CheckReadRight(view.Context, formId, keyValue)) //{ // view.ShowNotificationMessage(Kingdee.BOS.Resource.ResManager.LoadKDString("对不起,您没有所选单据查看权限!", "002406030017569", Kingdee.BOS.Resource.SubSystemType.BOS)); // return; //} BillShowParameter showParam = new BillShowParameter(); showParam.AllowNavigation = false; showParam.PageId = Guid.NewGuid().ToString(); showParam.FormId = formId; showParam.PKey = keyValue; showParam.Status = OperationStatus.VIEW; //工作流消息查看 if (msgType == MsgType.WorkflowMessage) { // 加载单据类型视图 FormMetadata meta = Kingdee.BOS.ServiceHelper.MetaDataServiceHelper.Load( view.Context, formId) as FormMetadata; string layoutId = GetLayoutByBillType(view.Context, meta, keyValue); if (!string.IsNullOrEmpty(layoutId)) { showParam.LayoutId = layoutId; } } //showParam.OpenStyle.TagetKey = "FMainTab"; if (view.ParentFormView == null || view.ParentFormView.ParentFormView == null) { showParam.OpenStyle.ShowType = ShowType.Modal; } else { showParam.OpenStyle.ShowType = showType; } //if (msgType != MsgType.BusinessFlowMessage) //{ // showParam.CustomParams.Add("workflowHandled", "1"); //} // 工作流消息,查看单据,无需关闭菜单,放开 // 前面代码已经检验过查看权、数据权,用户完全能够正常打开单据 // 放开单据的菜单后,用户可以从消息入口,进行下推、查看附件等与流程密切相关的操作 // Johnny Ding 2014.4.17 //if (msgType == MsgType.WorkflowMessage) //{ // showParam.CustomParams.Add("workflowHandled", "1"); //} if (view.ParentFormView == null || view.ParentFormView.ParentFormView == null) { view.ShowForm(showParam); } else { IDynamicFormView showView = view.GetView(view.ParentFormView.ParentFormView.PageId); showView.ShowForm(showParam); view.SendDynamicFormAction(showView); } } catch (Kingdee.BOS.KDExceptionLicense ex) { view.ShowErrMessage(ex.Message); } catch { view.ShowErrMessage(Kingdee.BOS.Resource.ResManager.LoadKDString("单据与单据编码配置错误,请联系管理员!", "002406030017572", Kingdee.BOS.Resource.SubSystemType.BOS), Kingdee.BOS.Resource.ResManager.LoadKDString("单据查看失败", "002406030017575", Kingdee.BOS.Resource.SubSystemType.BOS)); } } /// <summary> /// 校验查看权限:登陆组织查看权 + 数据权 /// </summary> private static bool CheckReadRight(Context ctx, string formId, object pkValue) { // 验证功能权限 BusinessObject businessObject = new BusinessObject(); businessObject.Id = formId; FormMetadata meta = Kingdee.BOS.ServiceHelper.MetaDataServiceHelper.Load(ctx, formId) as FormMetadata; BusinessInfo info = meta.BusinessInfo; Form form = info.GetForm(); //不需要验权直接返回 if (form.SupportPermissionControl == 0) { return true; } PermissionAuthResult authResult = PermissionServiceHelper.FuncPermissionAuth(ctx, businessObject, PermissionConst.View); if (!authResult.Passed) { // 功能权限验证未通过 return false; } // 验证其数据权限 QueryBuilderParemeter queryParam = new QueryBuilderParemeter(); queryParam.FormId = formId; queryParam.BusinessInfo = info; queryParam.RequiresDataPermission = true; string pkField = form.PkFieldName; string filter = string.Empty; if (form.PkFieldType == EnumPkFieldType.STRING) { filter = string.Format("{0} = '{1}'", pkField, pkValue); } else { filter = string.Format("{0} = {1}", pkField, pkValue); } queryParam.SelectItems.Add(new SelectorItemInfo(pkField)); if (info.MainOrgField != null) { queryParam.SelectItems.Add(new SelectorItemInfo(info.MainOrgField.Key)); } queryParam.FilterClauseWihtKey = filter; var data = QueryServiceHelper.GetDynamicObjectCollection(ctx, queryParam); if (data.Count == 0) { // 没有数据权限 return false; } // 判断用户是否具有主业务组织的查看权 if (info.MainOrgField != null) { long orgId = Convert.ToInt64(data[0][1]); // 功能权限验证通过,进一步验证其组织查看权 Organization org = authResult.OrgActions.FirstOrDefault((item) => item.Id == orgId); if (org == null) { // 无登陆组织授权信息:无权 return false; } } return true; } /// <summary> /// 获取单据类型关联的布局 /// </summary> public static string GetLayoutByBillType(Context ctx, FormMetadata formMetadata, string keyValue) { string result = null; if (formMetadata != null) { BillTypeField billTypeField = formMetadata.BusinessInfo.GetBillTypeField(); if (billTypeField != null) { // 取单据类型绑定的单据视图 Form form = formMetadata.BusinessInfo.GetForm(); string filter = (form.PkFieldType == EnumPkFieldType.STRING) ? string.Format("{0}='{1}'", form.PkFieldName, keyValue) : string.Format("{0}={1}", form.PkFieldName, keyValue); OQLFilter oqlFilter = OQLFilter.CreateHeadEntityFilter(filter); List<SelectorItemInfo> selector = new List<SelectorItemInfo>(); selector.Add(new SelectorItemInfo(billTypeField.Key)); DynamicObject dyn = BusinessDataServiceHelper.LoadFromCache(ctx, form.Id, selector, oqlFilter).FirstOrDefault(); if (null != dyn) { string billType = Convert.ToString(billTypeField.RefIDDynamicProperty.GetValue(dyn)); DynamicObject billTypeObj = billTypeField.BillTypeInfo.FirstOrDefault(t => t["Id"].ToString().EqualsIgnoreCase(billType)); if (billTypeObj != null) { DynamicObject layoutSolutionObj = billTypeObj["LayoutSolution"] as DynamicObject; if (layoutSolutionObj != null) { result = layoutSolutionObj["Id"].ToString(); } } } } } return result; } } #endregion } }
<2>拷贝插件组件到应用站点的WebSite\Bin目录下,重启IIS。
<3>BOSIDE扩展信息中心_收件箱[WF_MessageBill],注册列表插件,禁用标准产品的列表插件,保存元数据,开发完毕。
【功能验证】
<1>登录业务站点,打开信息中心的流程消息,此时去查看单据时,不会再验证用户的查看权限了。
---------------------------------------------------------------------------------------------------------
【金蝶云星空BOS二次开发案例演示】https://vip.kingdee.com/article/94751030918525696
二开案例.列表插件.信息中心流程消息查看单据时取消验权
【应用场景】信息中心流程消息查看单据时,默认会验证当前登录用户的查看权限,可通过插件取消验权。【案例演示】信息中心流程消息查看单据...
点击下载文档
本文2024-09-23 03:58:42发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-162315.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章