public override void Startup(IService service) { service .AddSiteMenu(siteId => { var request = Context.GetCurrentRequest(); if (!request.AdminPermissions.IsSiteAdmin(siteId)) { var userDepartmentIdList = DepartmentManager.GetDepartmentIdList(siteId, request.AdminName); if (userDepartmentIdList.Count == 0) { return(null); } var acceptCount = DataDao.GetUserCount(siteId, new List <DataState> { DataState.New }, string.Empty, 0, userDepartmentIdList); var replyCount = DataDao.GetUserCount(siteId, new List <DataState> { DataState.Accepted, DataState.Redo }, string.Empty, 0, userDepartmentIdList); return(new Menu { Text = "依申请公开", IconClass = "ion-ios-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 = "ion-ios-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(DataDao.TableName, DataDao.Columns) .AddDatabaseTable(DepartmentDao.TableName, DepartmentDao.Columns) .AddDatabaseTable(LogDao.TableName, LogDao.Columns) .AddDatabaseTable(FileDao.TableName, FileDao.Columns) .AddStlElementParser(StlApplication.ElementName, StlApplication.Parse) ; }
public IHttpActionResult List() { try { var request = Context.GetCurrentRequest(); 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 = DataDao.GetCount(siteId, stateList, keyword, departmentId); } else { keyword = string.Empty; departmentId = 0; totalCount = DataCountManager.GetCount(siteId, stateList); } } else { userDepartmentIdList = DepartmentManager.GetDepartmentIdList(siteId, request.AdminName); totalCount = DataDao.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; } List <DataInfo> dataInfoList; if (totalCount == 0) { dataInfoList = new List <DataInfo>(); } else { if (isSiteAdmin) { if (totalCount <= ApplicationUtils.PageSize) { dataInfoList = DataDao.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 = DataDao.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 = DataDao.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)); } }