Beispiel #1
0
        public override void Startup(IService service)
        {
            DataRepository       = new DataRepository();
            CategoryRepository   = new CategoryRepository();
            DepartmentRepository = new DepartmentRepository();
            FileRepository       = new FileRepository();
            LogRepository        = new LogRepository();

            service
            .AddSiteMenu(siteId =>
            {
                //var request = Context.AuthenticatedRequest;
                //if (!request.AdminPermissions.IsSiteAdmin(siteId))
                //{
                //    var userDepartmentIdList = DepartmentManager.GetDepartmentIdList(siteId, request.AdminName);
                //    if (userDepartmentIdList.Count == 0) return null;

                //    var acceptCount = DataRepository.GetUserCount(siteId, new List<DataState>
                //    {
                //        DataState.New
                //    }, string.Empty, 0, userDepartmentIdList);
                //    var replyCount = DataRepository.GetUserCount(siteId, new List<DataState>
                //    {
                //        DataState.Accepted,
                //        DataState.Redo
                //    }, string.Empty, 0, userDepartmentIdList);

                //    return new Menu
                //    {
                //        Text = "互动交流",
                //        IconClass = "fa fa-envelope",
                //        Menus = new List<Menu>
                //        {
                //            new Menu
                //            {
                //                Text = $"待受理信件 ({acceptCount})",
                //                Href = $"pages/contents.html?pageType={ApplicationUtils.PageTypeAccept}"
                //            },
                //            new Menu
                //            {
                //                Text = $"待办理信件 ({replyCount})",
                //                Href = $"pages/contents.html?pageType={ApplicationUtils.PageTypeReply}"
                //            },
                //            new Menu
                //            {
                //                Text = "新增信件",
                //                Href = "pages/add.html"
                //            }
                //        }
                //    };
                //}
                //else
                //{
                var acceptCount = DataCountManager.GetCount(siteId, new List <DataState>
                {
                    DataState.New
                });
                var replyCount = DataCountManager.GetCount(siteId, new List <DataState>
                {
                    DataState.Accepted,
                    DataState.Redo
                });
                var checkCount = DataCountManager.GetCount(siteId, new List <DataState>
                {
                    DataState.Replied
                });
                var totalCount = DataCountManager.GetTotalCount(siteId);

                return(new Menu
                {
                    Text = "互动交流",
                    IconClass = "fa fa-envelope",
                    Menus = new List <Menu>
                    {
                        new Menu
                        {
                            Id = ApplicationUtils.PageTypeAccept,
                            Text = $"待受理信件 ({acceptCount})",
                            Href = $"pages/contents.html?pageType={ApplicationUtils.PageTypeAccept}"
                        },
                        new Menu
                        {
                            Id = ApplicationUtils.PageTypeReply,
                            Text = $"待办理信件 ({replyCount})",
                            Href = $"pages/contents.html?pageType={ApplicationUtils.PageTypeReply}"
                        },
                        new Menu
                        {
                            Id = ApplicationUtils.PageTypeCheck,
                            Text = $"待审核信件 ({checkCount})",
                            Href = $"pages/contents.html?pageType={ApplicationUtils.PageTypeCheck}"
                        },
                        new Menu
                        {
                            Id = "all",
                            Text = $"所有信件 ({totalCount})",
                            Href = "pages/contents.html"
                        },
                        new Menu
                        {
                            Id = "add",
                            Text = "新增信件",
                            Href = "pages/add.html"
                        },
                        new Menu
                        {
                            Id = "categories",
                            Text = "分类设置",
                            Href = "pages/categories.html"
                        },
                        new Menu
                        {
                            Id = "departments",
                            Text = "部门设置",
                            Href = "pages/departments.html"
                        },
                        new Menu
                        {
                            Id = "settings",
                            Text = "互动交流设置",
                            Href = "pages/settings.html"
                        },
                        new Menu
                        {
                            Id = "templates",
                            Text = "互动交流模板",
                            Href = "pages/templates.html"
                        }
                    }
                });
                //}
            })
            .AddDatabaseTable(DataRepository.TableName, DataRepository.TableColumns)
            .AddDatabaseTable(CategoryRepository.TableName, CategoryRepository.TableColumns)
            .AddDatabaseTable(DepartmentRepository.TableName, DepartmentRepository.TableColumns)
            .AddDatabaseTable(LogRepository.TableName, LogRepository.TableColumns)
            .AddDatabaseTable(FileRepository.TableName, FileRepository.TableColumns)
            .AddStlElementParser(StlGovInteract.ElementName, StlGovInteract.Parse)
            ;
        }
Beispiel #2
0
        public override void Startup(IService service)
        {
            DataRepository       = new DataRepository();
            DepartmentRepository = new DepartmentRepository();
            FileRepository       = new FileRepository();
            LogRepository        = new LogRepository();

            service
            .AddSiteMenu(siteId =>
            {
                var request = Context.AuthenticatedRequest;
                if (!request.AdminPermissions.IsSiteAdmin(siteId))
                {
                    var userDepartmentIdList = DepartmentManager.GetDepartmentIdList(siteId, request.AdminName);
                    if (userDepartmentIdList.Count == 0)
                    {
                        return(null);
                    }

                    var acceptCount = DataRepository.GetUserCount(siteId, new List <DataState>
                    {
                        DataState.New
                    }, string.Empty, 0, userDepartmentIdList);
                    var replyCount = DataRepository.GetUserCount(siteId, new List <DataState>
                    {
                        DataState.Accepted,
                        DataState.Redo
                    }, string.Empty, 0, userDepartmentIdList);

                    return(new Menu
                    {
                        Text = "依申请公开",
                        IconClass = "fa fa-book",
                        Menus = new List <Menu>
                        {
                            new Menu
                            {
                                Text = $"待受理申请 ({acceptCount})",
                                Href = $"pages/contents.html?pageType={ApplicationUtils.PageTypeAccept}"
                            },
                            new Menu
                            {
                                Text = $"待办理申请 ({replyCount})",
                                Href = $"pages/contents.html?pageType={ApplicationUtils.PageTypeReply}"
                            },
                            new Menu
                            {
                                Text = "新增申请",
                                Href = "pages/add.html"
                            }
                        }
                    });
                }
                else
                {
                    var acceptCount = DataCountManager.GetCount(siteId, new List <DataState>
                    {
                        DataState.New
                    });
                    var replyCount = DataCountManager.GetCount(siteId, new List <DataState>
                    {
                        DataState.Accepted,
                        DataState.Redo
                    });
                    var checkCount = DataCountManager.GetCount(siteId, new List <DataState>
                    {
                        DataState.Replied
                    });
                    var totalCount = DataCountManager.GetTotalCount(siteId);

                    return(new Menu
                    {
                        Text = "依申请公开",
                        IconClass = "fa fa-book",
                        Menus = new List <Menu>
                        {
                            new Menu
                            {
                                Text = $"待受理申请 ({acceptCount})",
                                Href = $"pages/contents.html?pageType={ApplicationUtils.PageTypeAccept}"
                            },
                            new Menu
                            {
                                Text = $"待办理申请 ({replyCount})",
                                Href = $"pages/contents.html?pageType={ApplicationUtils.PageTypeReply}"
                            },
                            new Menu
                            {
                                Text = $"待审核申请 ({checkCount})",
                                Href = $"pages/contents.html?pageType={ApplicationUtils.PageTypeCheck}"
                            },
                            new Menu
                            {
                                Text = $"所有申请 ({totalCount})",
                                Href = "pages/contents.html"
                            },
                            new Menu
                            {
                                Text = "新增申请",
                                Href = "pages/add.html"
                            },
                            new Menu
                            {
                                Text = "部门及权限设置",
                                Href = "pages/departments.html"
                            },
                            new Menu
                            {
                                Text = "依申请公开设置",
                                Href = "pages/settings.html"
                            },
                            new Menu
                            {
                                Text = "依申请公开模板",
                                Href = "pages/templates.html"
                            }
                        }
                    });
                }
            })
            .AddDatabaseTable(DataRepository.TableName, DataRepository.TableColumns)
            .AddDatabaseTable(DepartmentRepository.TableName, DepartmentRepository.TableColumns)
            .AddDatabaseTable(LogRepository.TableName, LogRepository.TableColumns)
            .AddDatabaseTable(FileRepository.TableName, FileRepository.TableColumns)
            .AddStlElementParser(StlGovApplication.ElementName, StlGovApplication.Parse)
            ;
        }
        public IHttpActionResult List()
        {
            try
            {
                var request = Context.AuthenticatedRequest;
                var siteId  = request.GetQueryInt("siteId");
                if (!request.IsAdminLoggin || !request.AdminPermissions.HasSitePermissions(siteId, ApplicationUtils.PluginId))
                {
                    return(Unauthorized());
                }

                var pageType  = request.GetQueryString("pageType");
                var stateList = new List <DataState>();
                if (StringUtils.EqualsIgnoreCase(pageType, ApplicationUtils.PageTypeAccept))
                {
                    stateList.Add(DataState.New);
                }
                else if (StringUtils.EqualsIgnoreCase(pageType, ApplicationUtils.PageTypeReply))
                {
                    stateList.Add(DataState.Accepted);
                    stateList.Add(DataState.Redo);
                }
                else if (StringUtils.EqualsIgnoreCase(pageType, ApplicationUtils.PageTypeCheck))
                {
                    stateList.Add(DataState.Replied);
                }
                else
                {
                    var state = request.GetQueryString("state");
                    if (!string.IsNullOrEmpty(state))
                    {
                        stateList.Add(DataState.ToDataState(state));
                    }
                }

                var page         = request.GetQueryInt("page", 1);
                var isSearch     = request.GetQueryBool("isSearch");
                var keyword      = request.GetQueryString("keyword");
                var departmentId = request.GetQueryInt("departmentId");

                int totalCount;
                var isSiteAdmin          = request.AdminPermissions.IsSiteAdmin(siteId);
                var userDepartmentIdList = new List <int>();

                if (isSiteAdmin)
                {
                    if (isSearch)
                    {
                        totalCount = Main.DataRepository.GetCount(siteId, stateList, keyword, departmentId);
                    }
                    else
                    {
                        keyword      = string.Empty;
                        departmentId = 0;
                        totalCount   = DataCountManager.GetCount(siteId, stateList);
                    }
                }
                else
                {
                    userDepartmentIdList = DepartmentManager.GetDepartmentIdList(siteId, request.AdminName);
                    totalCount           = Main.DataRepository.GetUserCount(siteId, stateList, keyword, departmentId, userDepartmentIdList);
                }

                var pages = Convert.ToInt32(Math.Ceiling((double)totalCount / ApplicationUtils.PageSize));
                if (pages == 0)
                {
                    pages = 1;
                }
                if (page > pages)
                {
                    page = pages;
                }

                IList <DataInfo> dataInfoList;
                if (totalCount == 0)
                {
                    dataInfoList = new List <DataInfo>();
                }
                else
                {
                    if (isSiteAdmin)
                    {
                        if (totalCount <= ApplicationUtils.PageSize)
                        {
                            dataInfoList = Main.DataRepository.GetDataInfoList(siteId, stateList, keyword, departmentId, 0, totalCount);
                        }
                        else
                        {
                            if (page == 0)
                            {
                                page = 1;
                            }
                            var offset = (page - 1) * ApplicationUtils.PageSize;
                            var limit  = totalCount - offset > ApplicationUtils.PageSize
                                ? ApplicationUtils.PageSize
                                : totalCount - offset;
                            dataInfoList = Main.DataRepository.GetDataInfoList(siteId, stateList, keyword, departmentId, offset, limit);
                        }
                    }
                    else
                    {
                        if (page == 0)
                        {
                            page = 1;
                        }
                        var offset = (page - 1) * ApplicationUtils.PageSize;
                        var limit  = totalCount - offset > ApplicationUtils.PageSize
                            ? ApplicationUtils.PageSize
                            : totalCount - offset;
                        dataInfoList = Main.DataRepository.GetUserDataInfoList(siteId, stateList, keyword, departmentId, userDepartmentIdList, offset, limit);
                    }
                }

                List <DepartmentInfo>    departmentInfoList = null;
                Dictionary <string, int> countDict          = null;
                Settings settings = null;

                if (page == 1)
                {
                    if (isSiteAdmin)
                    {
                        departmentInfoList = DepartmentManager.GetDepartmentInfoList(siteId);
                    }
                    else
                    {
                        departmentInfoList = new List <DepartmentInfo>();
                        foreach (var userDepartmentId in userDepartmentIdList)
                        {
                            departmentInfoList.Add(DepartmentManager.GetDepartmentInfo(siteId, userDepartmentId));
                        }
                    }

                    countDict = new Dictionary <string, int>
                    {
                        { "All", DataCountManager.GetTotalCount(siteId) }
                    };
                    foreach (var state in DataState.AllStates)
                    {
                        countDict.Add(state.Value, DataCountManager.GetCount(siteId, state));
                    }

                    settings = ApplicationUtils.GetSettings(siteId);
                }

                return(Ok(new
                {
                    Value = dataInfoList,
                    Count = totalCount,
                    Pages = pages,
                    Page = page,
                    DepartmentInfoList = departmentInfoList,
                    CountDict = countDict,
                    Settings = settings
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }