public static Org Root(ISession session, OrgType type) { IList <Org> list = session.CreateEntityQuery <Org>() .Where(Exp.Eq("IsRoot", true) & Exp.Eq("OrgType", type) & Exp.NEq("Deleted", true)) .List <Org>(); if (OrgTypeRegistry.HasExtAttr(type) && list.Count > 0) { foreach (Org o in list) { //有问题,因为不会加载ExtAttr与Org的对应关系,但合作企业的根节点为虚拟节点,所以不会遇到 o.ExtAttr = EntityManager.Retrieve(session, OrgTypeRegistry.ExtAttrType(type), o.OrgId) as IOrgExtend; } } return(list.Count <= 0 ? null : list[0]); }
public static SimpleJson GetOrgJSON(ISession session, Org org) { SimpleJson json = new SimpleJson(); if (org == null) { json.HandleError("Org is null"); return(json); } json.Add("id", org.OrgId) .Add("parent", org.ParentId) .Add("root", org.IsRoot) .Add("virtual", org.IsVirtual) .Add("seq", org.OrgSeq) .Add("code", org.OrgCode) .Add("name", org.OrgName) .Add("remark", org.Description) .Add("desc", org); if (org.CreateBy > 0) { User createBy = User.Retrieve(session, org.CreateBy); if (createBy != null) { json.Add("createBy", string.IsNullOrEmpty(createBy.FullName) ? createBy.UserName : createBy.FullName); } else { Log.Warn <Org>("User {0} (CreateBy) not found when loading org {1}:{2}", org.CreateBy, org.OrgId, org.OrgCode); } } else { json.Add("createBy", ""); } json.Add("createTime", org.CreateDate); if (org.ModifyBy > 0) { User modefyBy = User.Retrieve(session, org.ModifyBy); if (modefyBy != null) { json.Add("modifyBy", string.IsNullOrEmpty(modefyBy.FullName) ? modefyBy.UserName : modefyBy.FullName); } else { Log.Warn <Org>("User {0} (ModifyBy) not found when loading org {1}:{2}", org.ModifyBy, org.OrgId, org.OrgCode); } } else { json.Add("modifyBy", ""); } json.Add("modifyTime", org.ModifyDate); User manager = null; if (org.Manager > 0) { manager = User.Retrieve(session, org.Manager); if (manager == null) { Log.Warn <Org>("User {0} (Manager) not found when loading org {1}:{2}", org.Manager, org.OrgId, org.OrgCode); } } if (manager != null) { json.Add("managerId", manager.UserId) .Add("manager", string.IsNullOrEmpty(manager.FullName) ? manager.UserName : manager.FullName); } else { json.Add("managerId", -1) .Add("manager", ""); } if (OrgTypeRegistry.HasExtAttr(org.OrgType) && org.ExtAttr != null) { Type type = OrgTypeRegistry.ExtAttrType(org.OrgType); org.ExtAttr.Json(session, json); } return(json); }