Exemple #1
0
        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]);
        }
Exemple #2
0
        public static SimpleJson SaveOrg(ISession session, Org org, OrgType type, string action, User oper)
        {
            Org original = null;

            switch (action)
            {
            case "create":
                Org parent = Org.Get(session, type, org.ParentId);
                if (parent == null)
                {
                    return(new SimpleJson().HandleError(string.Format("父节点{0}不存在", org.ParentId)));
                }

                org.CreateBy   = oper.UserId;
                org.CreateDate = DateTime.Now;
                org.IsVirtual  = false;
                org.IsRoot     = false;
                org.OrgType    = type;
                org.Deleted    = false;
                org.OrgSeq     = org.OrgSeq <= 0 ? (short)(Org.MaxSeq(session, org.ParentId) + 1) : org.OrgSeq;
                org.Create(session);

                if (OrgTypeRegistry.HasExtAttr(type) && org.ExtAttr != null)
                {
                    IOrgExtend oext = org.ExtAttr as IOrgExtend;
                    oext.OrgId = org.OrgId;
                    oext.Create(session);
                }

                parent.AddChild(org);
                Org.SortOrg(parent, org);
                return(Org.GetOrgJSON(session, org));

            case "update":
                original = Org.Get(session, type, org.OrgId);
                if (original == null)
                {
                    return(new SimpleJson().HandleError(string.Format("{0}不存在", org.OrgId)));
                }
                original.OrgCode     = org.OrgCode;
                original.OrgName     = org.OrgName;
                original.Description = org.Description;
                original.ModifyBy    = oper.UserId;
                original.ModifyDate  = DateTime.Now;
                original.OrgSeq      = org.OrgSeq;
                original.Manager     = org.Manager;
                original.Update(session, "OrgCode", "OrgName", "Description", "ModifyBy", "ModifyDate", "OrgSeq", "Manager");

                if (OrgTypeRegistry.HasExtAttr(type) && org.ExtAttr != null)
                {
                    IOrgExtend oext = org.ExtAttr as IOrgExtend;
                    oext.OrgId = org.OrgId;
                    oext.Update(session);
                    original.ExtAttr = oext;
                }

                Org.SortOrg(Org.Get(session, type, original.ParentId), original);
                return(Org.GetOrgJSON(session, original));

            default:
                return(new SimpleJson().HandleError(string.Format("无效的操作{0}", action)));
            }
        }
Exemple #3
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);
        }