From 11e68fab1491fc2f764688eae85011943b4ff3fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=A8=E9=B1=BC=28iFish=29?= Date: Thu, 16 Jul 2015 21:00:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=90=84=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E6=9F=A5=E7=9C=8B=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ChatRoomServer.Db/ChatDb.cs | 76 +++++++ ChatRoomServer.Db/Entities/UserConnectLog.cs | 3 + ChatRoomServer.Main/ChatSession.cs | 3 +- .../Areas/Api/Controllers/MsgsController.cs | 22 +- .../Areas/Api/Controllers/UsersController.cs | 55 +++++ ChatRoomServer.Www/ChatRoomServer.Www.csproj | 3 + .../Controllers/UsersController.cs | 15 ++ ChatRoomServer.Www/Scripts/controller.js | 215 ++++++++++++++++-- ChatRoomServer.Www/Views/Msgs/LogList.cshtml | 27 ++- .../Views/Shared/_Layout.cshtml | 4 +- .../Views/Users/BlockList.cshtml | 70 ++++++ .../Views/Users/ConnectionLog.cshtml | 76 +++++++ .../Views/Users/UserList.cshtml | 78 +++++++ .../StationInfo/SameStationManager.cs | 4 +- .../StationInfo/StationManager.cs | 6 +- .../TrainInfo/TrainInfoManager.cs | 4 +- .../TrainInfo/WebDataProvider.cs | 5 +- .../TrainInfomationProviderService.csproj | 1 + .../Web/WebClient.cs | 53 +++++ Web12306/Web.config | 5 + 20 files changed, 688 insertions(+), 37 deletions(-) create mode 100644 ChatRoomServer.Www/Views/Users/BlockList.cshtml create mode 100644 ChatRoomServer.Www/Views/Users/ConnectionLog.cshtml create mode 100644 ChatRoomServer.Www/Views/Users/UserList.cshtml create mode 100644 TrainInfomationProviderService/Web/WebClient.cs diff --git a/ChatRoomServer.Db/ChatDb.cs b/ChatRoomServer.Db/ChatDb.cs index 3cec84d..a1fcb3c 100644 --- a/ChatRoomServer.Db/ChatDb.cs +++ b/ChatRoomServer.Db/ChatDb.cs @@ -115,5 +115,81 @@ namespace ChatRoomServer.Db TotalCount = (long)totalCountParameter.Value }; } + + public async Task> GetMsgLogList(string username, int pagesize, int pageindex) + { + var sp = "exec usp_MsgLog_GetList @pageindex, @pagesize, @user, @count output"; + var totalCountParameter = new SqlParameter("count", SqlDbType.BigInt) { Direction = ParameterDirection.Output, Value = 0 }; + var list = await Database.SqlQuery( + sp, + new SqlParameter("pageindex", SqlDbType.Int) { Value = pageindex }, + new SqlParameter("pagesize", SqlDbType.Int) { Value = pagesize }, + new SqlParameter("user", SqlDbType.VarChar, 100) { Value = username }, + totalCountParameter + ).ToListAsync(); + + return new PagedData() + { + Data = list, + TotalCount = (long)totalCountParameter.Value + }; + } + + public async Task> GetBlockUserList(string username, int pagesize, int pageindex) + { + var sp = "exec usp_Block_GetList @pageindex, @pagesize, @user, @count output"; + var totalCountParameter = new SqlParameter("count", SqlDbType.BigInt) { Direction = ParameterDirection.Output, Value = 0 }; + var list = await Database.SqlQuery( + sp, + new SqlParameter("pageindex", SqlDbType.Int) { Value = pageindex }, + new SqlParameter("pagesize", SqlDbType.Int) { Value = pagesize }, + new SqlParameter("user", SqlDbType.VarChar, 100) { Value = username }, + totalCountParameter + ).ToListAsync(); + + return new PagedData() + { + Data = list, + TotalCount = (long)totalCountParameter.Value + }; + } + + public async Task> GetUserList(string username, int pagesize, int pageindex) + { + var sp = "exec usp_User_GetList @pageindex, @pagesize, @user, @count output"; + var totalCountParameter = new SqlParameter("count", SqlDbType.BigInt) { Direction = ParameterDirection.Output, Value = 0 }; + var list = await Database.SqlQuery( + sp, + new SqlParameter("pageindex", SqlDbType.Int) { Value = pageindex }, + new SqlParameter("pagesize", SqlDbType.Int) { Value = pagesize }, + new SqlParameter("user", SqlDbType.VarChar, 100) { Value = username ?? "" }, + totalCountParameter + ).ToListAsync(); + + return new PagedData() + { + Data = list, + TotalCount = (long)totalCountParameter.Value + }; + } + + public async Task> GetConnectionLogList(string username, int pagesize, int pageindex) + { + var sp = "exec usp_ConnectionLog_GetList @pageindex, @pagesize, @user, @count output"; + var totalCountParameter = new SqlParameter("count", SqlDbType.BigInt) { Direction = ParameterDirection.Output, Value = 0 }; + var list = await Database.SqlQuery( + sp, + new SqlParameter("pageindex", SqlDbType.Int) { Value = pageindex }, + new SqlParameter("pagesize", SqlDbType.Int) { Value = pagesize }, + new SqlParameter("user", SqlDbType.VarChar, 100) { Value = username }, + totalCountParameter + ).ToListAsync(); + + return new PagedData() + { + Data = list, + TotalCount = (long)totalCountParameter.Value + }; + } } } diff --git a/ChatRoomServer.Db/Entities/UserConnectLog.cs b/ChatRoomServer.Db/Entities/UserConnectLog.cs index 45cd9be..d38563d 100644 --- a/ChatRoomServer.Db/Entities/UserConnectLog.cs +++ b/ChatRoomServer.Db/Entities/UserConnectLog.cs @@ -43,6 +43,8 @@ namespace ChatRoomServer.Db.Entities /// public int? ElapsedTime { get; set; } + public string Ip { get; set; } + } /// @@ -57,6 +59,7 @@ namespace ChatRoomServer.Db.Entities Property(s => s.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity); Property(s => s.UserName).HasMaxLength(100).IsRequired(); Property(s => s.RoomID).HasMaxLength(100).IsRequired(); + Property(s => s.Ip).IsRequired(); } } } diff --git a/ChatRoomServer.Main/ChatSession.cs b/ChatRoomServer.Main/ChatSession.cs index db5fbf7..ecedca1 100644 --- a/ChatRoomServer.Main/ChatSession.cs +++ b/ChatRoomServer.Main/ChatSession.cs @@ -94,7 +94,8 @@ namespace ChatRoomServer.Main { UserName = UserName, ConnectTime = DateTime.Now, - RoomID = Id + RoomID = Id, + Ip = RemoteEndPoint.ToString() }; db.UserConnectLogs.Add(ucl); db.SaveChanges(); diff --git a/ChatRoomServer.Www/Areas/Api/Controllers/MsgsController.cs b/ChatRoomServer.Www/Areas/Api/Controllers/MsgsController.cs index acab26b..7506eea 100644 --- a/ChatRoomServer.Www/Areas/Api/Controllers/MsgsController.cs +++ b/ChatRoomServer.Www/Areas/Api/Controllers/MsgsController.cs @@ -7,12 +7,15 @@ using System.Web.Http; namespace ChatRoomServer.Www.Areas.Api.Controllers { + using System.Data.Entity; using System.Threading.Tasks; using ChatRoomServer.Db; [Authorize] - public class MsgsController : ApiController - { + [RoutePrefix("api/msgs")] + public class MsgsController : ApiController + { + [Route("list")] public async Task List([FromBody] Dictionary query) { var searchUser = query.GetValue("searchUser") ?? ""; @@ -20,7 +23,20 @@ namespace ChatRoomServer.Www.Areas.Api.Controllers var pagesize = query.GetValue("pagesize").ToInt32(20); var db = new ChatDb(); + var data = await db.GetMsgLogList(searchUser, pagesize, pageIndex); + var rooms = data.Data.Select(s => s.RoomId).Distinct().ToArray(); + var roomdata = await db.Rooms.Where(s => rooms.Contains(s.ID)).ToDictionaryAsync(s => s.ID); + + return new + { + count = data.TotalCount, + list = data.Data.Select(s => new + { + msg = s, + room = roomdata.GetValue(s.RoomId) + }) + }; } - } + } } diff --git a/ChatRoomServer.Www/Areas/Api/Controllers/UsersController.cs b/ChatRoomServer.Www/Areas/Api/Controllers/UsersController.cs index dde0333..f45f110 100644 --- a/ChatRoomServer.Www/Areas/Api/Controllers/UsersController.cs +++ b/ChatRoomServer.Www/Areas/Api/Controllers/UsersController.cs @@ -18,6 +18,61 @@ namespace ChatRoomServer.Www.Areas.Api.Controllers [RoutePrefix("api/users"), Authorize] public class UsersController : ApiController { + [Route("blockList")] + public async Task BlockUsersList([FromBody] Dictionary query) + { + var searchUser = query.GetValue("searchUser") ?? ""; + var pageIndex = query.GetValue("pageIndex").ToInt32(1); + var pagesize = query.GetValue("pagesize").ToInt32(20); + var db = new ChatDb(); + + var data = await db.GetBlockUserList(searchUser, pagesize, pageIndex); + + return new + { + count = data.TotalCount, + list = data.Data + }; + } + + [Route("connectionLog")] + public async Task ConnectionLog([FromBody] Dictionary query) + { + var searchUser = query.GetValue("searchUser") ?? ""; + var pageIndex = query.GetValue("pageIndex").ToInt32(1); + var pagesize = query.GetValue("pagesize").ToInt32(20); + var db = new ChatDb(); + + var data = await db.GetConnectionLogList(searchUser, pagesize, pageIndex); + var rooms = data.Data.Select(s => s.RoomID).Distinct().ToArray(); + var roomdata = await db.Rooms.Where(s => rooms.Contains(s.ID)).ToDictionaryAsync(s => s.ID); + + + return new + { + count = data.TotalCount, + list = data.Data.Select(s => new + { + msg = s, + room = roomdata.GetValue(s.RoomID) + }) + }; + } + + [Route("list"), HttpGet] + public async Task UserList(int pageindex, int pagesize, string user) + { + var db = new ChatDb(); + + var data = await db.GetUserList(user, pagesize, pageindex); + + return new + { + count = data.TotalCount, + list = data.Data + }; + } + [Route("abuseList")] public async Task AbuseList([FromBody]Dictionary query) diff --git a/ChatRoomServer.Www/ChatRoomServer.Www.csproj b/ChatRoomServer.Www/ChatRoomServer.Www.csproj index c1ebb96..8626e8c 100644 --- a/ChatRoomServer.Www/ChatRoomServer.Www.csproj +++ b/ChatRoomServer.Www/ChatRoomServer.Www.csproj @@ -194,6 +194,9 @@ + + + diff --git a/ChatRoomServer.Www/Controllers/UsersController.cs b/ChatRoomServer.Www/Controllers/UsersController.cs index a435642..8e262eb 100644 --- a/ChatRoomServer.Www/Controllers/UsersController.cs +++ b/ChatRoomServer.Www/Controllers/UsersController.cs @@ -13,5 +13,20 @@ namespace ChatRoomServer.Www.Controllers { return View(); } + + public ActionResult ConnectionLog() + { + return View(); + } + + public ActionResult UserList() + { + return View(); + } + + public ActionResult BlockList() + { + return View(); + } } } \ No newline at end of file diff --git a/ChatRoomServer.Www/Scripts/controller.js b/ChatRoomServer.Www/Scripts/controller.js index e60d77a..1195e7f 100644 --- a/ChatRoomServer.Www/Scripts/controller.js +++ b/ChatRoomServer.Www/Scripts/controller.js @@ -252,7 +252,7 @@ var app = angular.module('chat12306', ['ngCookies']); $scope.filter = { searchUser: "", pageIndex: 1, - pagesize : "20" + pagesize: "20" }; $scope.pages = 0; $scope.itemsCount = 0; @@ -276,21 +276,16 @@ var app = angular.module('chat12306', ['ngCookies']); }); $http.post(listApi, $scope.filter) .success(function (data) { - if (data.success) { - notify.update({ - "title": "操作成功...", - type: "success", - icon: "fa fa-check", - showProgressbar: false - }); - $scope.items = data.items; - $scope.itemsCount = data.count; - } else { - notify.changeStatus("danger", "fa fa-ban", "加载失败:" + data.message, null, -2); - } + notify.update({ + "title": "加载成功...", + type: "success", + icon: "fa fa-check", + showProgressbar: false + }); + $scope.items = data.list; + $scope.itemsCount = data.count; + $scope.pages = Math.ceil($scope.itemsCount / parseInt($scope.filter.pagesize, 10)); setTimeout(notify.close, 2000); - - $("tr[data-id=" + item.id + "] button.btn").remove(); }).error(function () { notify.setTitle("加载失败,请重试。服务器错误啦....").setType("danger").setIcon("fa fa-ban").hideProgress().delayClose(); }); @@ -311,4 +306,194 @@ var app = angular.module('chat12306', ['ngCookies']); } app.controller("ChatMessageListController", ['$scope', '$http', chatMessageListController]); +})(); +(function ConnectionLogControllerContainer() { + function connectionLogController($scope, $http) { + var listApi = "/api/users/connectionlog"; + + $scope.filter = { + searchUser: "", + pageIndex: 1, + pagesize: "20" + }; + $scope.pages = 0; + $scope.itemsCount = 0; + $scope.items = []; + + //加载 + $scope.reload = function () { + var notify = $.notify({ + title: "数据加载中...", + "icon": "fa-spin fa fa-spinner", + type: "info" + }, { + delay: 0, + progress: -1, + showProgressbar: true, + allow_dismiss: false, + placement: { + from: "top", + align: "center" + } + }); + $http.post(listApi, $scope.filter) + .success(function (data) { + notify.update({ + "title": "加载成功...", + type: "success", + icon: "fa fa-check", + showProgressbar: false + }); + $scope.items = data.list; + $scope.itemsCount = data.count; + $scope.pages = Math.ceil($scope.itemsCount / parseInt($scope.filter.pagesize, 10)); + setTimeout(notify.close, 2000); + }).error(function () { + notify.setTitle("加载失败,请重试。服务器错误啦....").setType("danger").setIcon("fa fa-ban").hideProgress().delayClose(); + }); + }; + $scope.goPage = function (page) { + if (page <= 0) + return; + $scope.filter.pageIndex = page; + }; + $scope.go = function (pageOffset) { + $scope.filter.pageIndex = Math.max(1, Math.min($scope.filter.pageIndex + pageOffset, $scope.pages)); + }; + + + $scope.$watch("filter", function (newvalue, oldvalue) { + $scope.reload(); + }, true); + } + + app.controller("ConnectionLogController", ['$scope', '$http', connectionLogController]); +})(); +//------------------------------------------------------------- +(function blockUserListControllerContainer() { + function blockUserListController($scope, $http) { + var listApi = "/api/users/blockList"; + + $scope.filter = { + searchUser: "", + pageIndex: 1, + pagesize: "20" + }; + $scope.pages = 0; + $scope.itemsCount = 0; + $scope.items = []; + + //加载 + $scope.reload = function () { + var notify = $.notify({ + title: "数据加载中...", + "icon": "fa-spin fa fa-spinner", + type: "info" + }, { + delay: 0, + progress: -1, + showProgressbar: true, + allow_dismiss: false, + placement: { + from: "top", + align: "center" + } + }); + $http.post(listApi, $scope.filter) + .success(function (data) { + notify.update({ + "title": "加载成功...", + type: "success", + icon: "fa fa-check", + showProgressbar: false + }); + $scope.items = data.list; + $scope.itemsCount = data.count; + $scope.pages = Math.ceil($scope.itemsCount / parseInt($scope.filter.pagesize, 10)); + setTimeout(notify.close, 2000); + }).error(function () { + notify.setTitle("加载失败,请重试。服务器错误啦....").setType("danger").setIcon("fa fa-ban").hideProgress().delayClose(); + }); + }; + $scope.goPage = function (page) { + if (page <= 0) + return; + $scope.filter.pageIndex = page; + }; + $scope.go = function (pageOffset) { + $scope.filter.pageIndex = Math.max(1, Math.min($scope.filter.pageIndex + pageOffset, $scope.pages)); + }; + + + $scope.$watch("filter", function (newvalue, oldvalue) { + $scope.reload(); + }, true); + } + + app.controller("BlockUserListController", ['$scope', '$http', blockUserListController]); +})(); +//------------------------------------------------------------- +(function userListControllerContainer() { + function userListController($scope, $http) { + var listApi = "/api/users/list"; + + $scope.filter = { + user: "", + pageIndex: 1, + pagesize: "20" + }; + $scope.pages = 0; + $scope.itemsCount = 0; + $scope.items = []; + + //加载 + $scope.reload = function () { + var notify = $.notify({ + title: "数据加载中...", + "icon": "fa-spin fa fa-spinner", + type: "info" + }, { + delay: 0, + progress: -1, + showProgressbar: true, + allow_dismiss: false, + placement: { + from: "top", + align: "center" + } + }); + $http.get(listApi, { + params: $scope.filter + }) + .success(function (data) { + notify.update({ + "title": "加载成功...", + type: "success", + icon: "fa fa-check", + showProgressbar: false + }); + $scope.items = data.list; + $scope.itemsCount = data.count; + $scope.pages = Math.ceil($scope.itemsCount / parseInt($scope.filter.pagesize, 10)); + setTimeout(notify.close, 2000); + }).error(function () { + notify.setTitle("加载失败,请重试。服务器错误啦....").setType("danger").setIcon("fa fa-ban").hideProgress().delayClose(); + }); + }; + $scope.goPage = function (page) { + if (page <= 0) + return; + $scope.filter.pageIndex = page; + }; + $scope.go = function (pageOffset) { + $scope.filter.pageIndex = Math.max(1, Math.min($scope.filter.pageIndex + pageOffset, $scope.pages)); + }; + + + $scope.$watch("filter", function (newvalue, oldvalue) { + $scope.reload(); + }, true); + } + + app.controller("UserListController", ['$scope', '$http', userListController]); })(); \ No newline at end of file diff --git a/ChatRoomServer.Www/Views/Msgs/LogList.cshtml b/ChatRoomServer.Www/Views/Msgs/LogList.cshtml index 6440cf3..63a0655 100644 --- a/ChatRoomServer.Www/Views/Msgs/LogList.cshtml +++ b/ChatRoomServer.Www/Views/Msgs/LogList.cshtml @@ -10,6 +10,11 @@
搜索
+ + +
@@ -25,12 +30,12 @@ 发送给 - {{item.msg.id}} - {{item.room.name}} - {{item.msg.userName}} - {{item.msg.sendTime|jsonDate}} - {{item.msg.ip}} - {{item.msg.atUser}} + {{item.msg.id}} + {{item.room.name}} + {{item.msg.userName}} + {{item.msg.sendTime|jsonDate}} + {{item.msg.ip}} + {{item.msg.atUser}} @@ -47,11 +52,6 @@
  • 共 {{itemsCount}} 条记录,每页 {{filter.pagesize}} 条,共 {{ pages }} 页
  • -
  • - - - -
  • 每页记录数 @@ -60,6 +60,11 @@
  • +
  • + + + +
  • diff --git a/ChatRoomServer.Www/Views/Shared/_Layout.cshtml b/ChatRoomServer.Www/Views/Shared/_Layout.cshtml index 46d269f..3949303 100644 --- a/ChatRoomServer.Www/Views/Shared/_Layout.cshtml +++ b/ChatRoomServer.Www/Views/Shared/_Layout.cshtml @@ -27,7 +27,9 @@ 用户管理