From d0243cfc13545b2ee6145b4858c18701f4561508 Mon Sep 17 00:00:00 2001 From: yanjinhui <3306209981@qq.com> Date: 星期二, 08 四月 2025 13:34:55 +0800 Subject: [PATCH] 原先基础上添加排序功能 --- 项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/Telescopic/LoginhsyController.cs | 4 项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_ITelescopicService/ILoginhsyService.cs | 2 项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/System/Sys_UserController.cs | 3 项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/Telescopic/MaintenanceTeamController.cs | 6 项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/LoginhsyService.cs | 63 ++++++++++++--- 项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/MaintenanceService.cs | 35 ++++++++ 项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Model/Models/Telescopic/Dt_Loginhsy.cs | 4 项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/MaintenanceTeamService.cs | 31 +++++++ 项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_DTO/Telescopic/PaginationDTO.cs | 10 ++ 项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_SystemServices/Sys_UserService.cs | 24 ++++- 10 files changed, 147 insertions(+), 35 deletions(-) diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_DTO/Telescopic/PaginationDTO.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_DTO/Telescopic/PaginationDTO.cs" index a017ed0..7c60b02 100644 --- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_DTO/Telescopic/PaginationDTO.cs" +++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_DTO/Telescopic/PaginationDTO.cs" @@ -39,6 +39,16 @@ /// </summary> public int ? status { get; set; } + /// <summary> + /// 鎺掑簭瀛楁鍚� + /// </summary> + public string ?sortField { get; set; } + + /// <summary> + /// 鎺掑簭鏂瑰紡锛�"asc" 鎴� "desc" + /// </summary> + public string ?sortOrder { get; set; } + } } diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_ITelescopicService/ILoginhsyService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_ITelescopicService/ILoginhsyService.cs" index 44c2c74..bf4b5ed 100644 --- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_ITelescopicService/ILoginhsyService.cs" +++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_ITelescopicService/ILoginhsyService.cs" @@ -25,7 +25,7 @@ /// 閫�鍑烘椂闂� /// </summary> /// <returns></returns> - WebResponseContent OutLoginTime(int id); + WebResponseContent OutLoginTime(string account); } diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Model/Models/Telescopic/Dt_Loginhsy.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Model/Models/Telescopic/Dt_Loginhsy.cs" index 67243b3..8f0efea 100644 --- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Model/Models/Telescopic/Dt_Loginhsy.cs" +++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Model/Models/Telescopic/Dt_Loginhsy.cs" @@ -34,12 +34,12 @@ /// 閫�鍑烘椂闂� /// </summary> [SugarColumn(IsNullable = true, ColumnDescription = "閫�鍑烘椂闂�")] - public DateTime OutTiem { get; set; } + public DateTime?OutTiem { get; set; } /// <summary> /// 鎿嶄綔鍐呭 /// </summary> [SugarColumn(IsNullable = true, Length = 50, ColumnDescription = "鎿嶄綔鍐呭")] - public string OpCenten { get; set; } + public string? OpCenten { get; set; } } } diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/System/Sys_UserController.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/System/Sys_UserController.cs" index 66a2e06..8cef055 100644 --- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/System/Sys_UserController.cs" +++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/System/Sys_UserController.cs" @@ -70,7 +70,8 @@ [HttpPost, Route("login"), AllowAnonymous] public IActionResult Login([FromBody] LoginInfo loginInfo) { - return Json(Service.Login(loginInfo)); + var result = Json(Service.Login(loginInfo)); + return result; } [HttpPost, Route("getCurrentUserInfo")] public WebResponseContent GetCurrentUser() diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/Telescopic/LoginhsyController.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/Telescopic/LoginhsyController.cs" index 1879f10..93cf682 100644 --- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/Telescopic/LoginhsyController.cs" +++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/Telescopic/LoginhsyController.cs" @@ -35,9 +35,9 @@ /// <param name="id"></param> /// <returns></returns> [HttpPost, Route("OutLoginTime"), AllowAnonymous] - public WebResponseContent OutLoginTime(int id) + public WebResponseContent OutLoginTime(string account) { - return Service.OutLoginTime(id); + return Service.OutLoginTime(account); } } diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/Telescopic/MaintenanceTeamController.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/Telescopic/MaintenanceTeamController.cs" index f6d9777..0d467ac 100644 --- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/Telescopic/MaintenanceTeamController.cs" +++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/Telescopic/MaintenanceTeamController.cs" @@ -12,9 +12,9 @@ { [Route("api/[controller]")] [ApiController] - public class MaintenanceTeamController : ApiBaseController<IMaintenanceService, Dt_MaintenanceTeam> + public class MaintenanceTeamController : ApiBaseController<IMaintenanceTeamService, Dt_MaintenanceTeam> { - public MaintenanceTeamController(IMaintenanceService service) : base(service) + public MaintenanceTeamController(IMaintenanceTeamService service) : base(service) { @@ -28,7 +28,7 @@ [HttpPost, Route("MaintenanceSettingRecord"), AllowAnonymous] public WebResponseContent MaintenanceSettingRecord([FromBody] PaginationDTO pagination ) { - return Service.MaintenanceOperationRecord(pagination); + return Service.MaintenanceSettingRecord(pagination); } } diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_SystemServices/Sys_UserService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_SystemServices/Sys_UserService.cs" index c20cabf..2e1b8a6 100644 --- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_SystemServices/Sys_UserService.cs" +++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_SystemServices/Sys_UserService.cs" @@ -198,10 +198,13 @@ LoginTiem =DateTime.Now, CreateDate = DateTime.Now }; + // 淇濆瓨鐢ㄦ埛鐧诲綍淇℃伅 _cacheService.AddOrUpdate(user.UserId.ToString(), token); - _LoginhsyServer.AddData(loghis); + _LoginhsyServer.AddData(loghis); + // var id= _LoginhsyServer.Db.Insertable(loghis).ExecuteReturnIdentity(); + // 杩斿洖鍝嶅簲 content = WebResponseContent.Instance.OK(data: new @@ -210,7 +213,8 @@ userName = user.UserTrueName, img = user.HeadImageUrl, ID = user.UserId, - RoleId = user.RoleId + RoleId = user.RoleId, + }); } else @@ -220,7 +224,7 @@ } catch (Exception ex) { - content = WebResponseContent.Instance.Error(ex.Message); + content = WebResponseContent.Instance.Error("鐧诲綍寮傚父: " + ex.ToString()); } return content; @@ -511,7 +515,7 @@ /// <summary> - /// 鏇存柊鐢ㄦ埛 + ///鐧惧害浜� 鏇存柊鐢ㄦ埛 /// </summary> /// <param name="addUserDTO"></param> /// <returns></returns> @@ -519,8 +523,10 @@ { try { + // 1. 鏌ヨ鐢ㄦ埛 - var sys = BaseDal.QueryData(x => x.User_Id == addUserDTO.id).FirstOrDefault(); + var user = BaseDal.QueryData(); + var sys = user.Where(x => x.User_Id == addUserDTO.id).FirstOrDefault(); if (sys == null) { return new WebResponseContent { Status = false, Message = "娌℃壘鍒拌鐢ㄦ埛" }; @@ -560,7 +566,11 @@ sys.Role_Id = addUserDTO.roleid; sys.RoleName = addUserDTO.rolename; sys.Enable = addUserDTO.enable; - + var list = user.Where(a => a.UserName == addUserDTO.username).FirstOrDefault(); + if (list != null) + { + return new WebResponseContent { Status = false, Message = "璐﹀彿閲嶅锛岃閲嶆柊褰曞叆" }; + } // 7. 鏇存柊鏁版嵁搴� BaseDal.UpdateData(sys); @@ -624,7 +634,7 @@ return new WebResponseContent { Status = false, Message = "璇蜂笂浼犳枃浠�" }; // 1. 纭繚瀛樺偍鐩綍瀛樺湪 - string baseDirectory = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "UploadfaceImage"); + string baseDirectory = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "image"); if (!Directory.Exists(baseDirectory)) Directory.CreateDirectory(baseDirectory); diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/LoginhsyService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/LoginhsyService.cs" index 799b2f0..e2edc32 100644 --- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/LoginhsyService.cs" +++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/LoginhsyService.cs" @@ -4,6 +4,7 @@ using System.Text; using System.Threading.Tasks; using AutoMapper; +using SqlSugar; using WIDESEAWCS_Core; using WIDESEAWCS_Core.BaseRepository; using WIDESEAWCS_Core.BaseServices; @@ -18,9 +19,9 @@ public IRepository<Dt_Loginhsy> Repository => BaseDal; private readonly IRepository<Sys_User> _user; - public LoginhsyService(IRepository<Dt_Loginhsy> BaseDal) : base(BaseDal) + public LoginhsyService(IRepository<Sys_User> user, IRepository<Dt_Loginhsy> BaseDal) : base(BaseDal) { - + _user = user; } public WebResponseContent LoginRecord(PaginationDTO pagination) @@ -32,21 +33,52 @@ var sys = _user.Db.Queryable<Sys_User>(); var main = Db.Queryable<Dt_Loginhsy>(); + //妯$硦鏌ヨ var query = sys.InnerJoin<Dt_Loginhsy>((a, b) => a.UserName == b.UserName); if (!string.IsNullOrEmpty(pagination.searchKeyword)) { query = query.Where((a, b) => a.UserTrueName.Contains(pagination.searchKeyword) || a.Userteam.Contains(pagination.searchKeyword) || - b.OpCenten.Contains(pagination.searchKeyword) - ); + b.OpCenten.Contains(pagination.searchKeyword)); } + + //鏃堕棿鏌ヨ if (pagination.startDate.HasValue && pagination.endDate.HasValue) { - query = query.Where((a, b) => b.LoginTiem >= pagination.startDate.Value && b.LoginTiem <= pagination.endDate.Value);//鐧诲叆鏃堕棿 + query = query.Where((a, b) => b.LoginTiem >= pagination.startDate.Value && b.LoginTiem <= pagination.endDate.Value); } - var result=query - .Select((a, b) => new + + // 鎺掑簭澶勭悊 + if (!string.IsNullOrEmpty(pagination.sortField)) + { + //isAsc锛氳繖鏄竴涓竷灏斿�硷紝鍒ゆ柇鎺掑簭鏄崌搴� (true)"asc" ,杩樻槸闄嶅簭 (false) "desc" + var isAsc = pagination.sortOrder?.ToLower() == "asc";//pagination.sortOrder 涓嶄负绌猴紝鍒欒皟鐢� ToLower() 鏂规硶灏嗗叾杞负灏忓啓瀛楁瘝 + + query = pagination.sortField.ToLower() switch + { + //濡傛灉isAsc 涓簍ure灏辨墽琛宷uery.OrderBy((a, b) => b.LoginTiem, OrderByType.Asc)鍗囧簭鎺掑簭锛� + //濡傛灉涓篺ales灏辨墽琛宷uery.OrderBy((a, b) => b.LoginTiem, OrderByType.Desc)闄嶅簭鎺掑簭 + "logintiem" => isAsc ? query.OrderBy((a, b) => b.LoginTiem, OrderByType.Asc) + : query.OrderBy((a, b) => b.LoginTiem, OrderByType.Desc), + + "outtiem" => isAsc ? query.OrderBy((a, b) => b.OutTiem, OrderByType.Asc) + : query.OrderBy((a, b) => b.OutTiem, OrderByType.Desc), + + //"usertruename" => isAsc ? query.OrderBy((a, b) => a.UserTrueName, OrderByType.Asc) + //: query.OrderBy((a, b) => a.UserTrueName, OrderByType.Desc), + _ => query.OrderBy((a, b) => b.LoginTiem, OrderByType.Desc) // 榛樿鎸夌櫥鍏ユ椂闂撮檷搴� + }; + } + else + { + // 榛樿鎸� LoginTiem 闄嶅簭 + query = query.OrderBy((a, b) => b.LoginTiem, OrderByType.Desc); + } + + + //杩斿洖缁撴灉 + var result = query.Select((a, b) => new { a.User_Id, a.UserTrueName, @@ -56,32 +88,33 @@ b.OutTiem, b.OpCenten, }).ToPageList(pagination.pageIndex, pagination.pageSize, ref totalCount); + return new WebResponseContent { Status = true, Data = new { - TotalCount = totalCount,//鎬绘暟 - PageIndex = pagination.pageIndex,//椤垫暟 - PageSize = pagination.pageSize,//涓�椤靛灏戜釜鏁版嵁 + TotalCount = totalCount, // 鎬绘暟 + PageIndex = pagination.pageIndex, // 椤垫暟 + PageSize = pagination.pageSize, // 涓�椤靛灏戜釜鏁版嵁 Items = result } }; } catch (Exception ex) { - - return new WebResponseContent { Status = true, Message = "閿欒" + ex }; + return new WebResponseContent { Status = false, Message = "閿欒: " + ex.Message }; } } - - public WebResponseContent OutLoginTime(int id) + + + public WebResponseContent OutLoginTime(string account) { try { - var log = BaseDal.QueryFirst(x => x.ID == id); + var log = BaseDal.QueryData(x=>x.UserName== account).OrderByDescending(x=>x.UserName).FirstOrDefault(); if (log==null) { return new WebResponseContent { Status = false, Message = "澶辫触" }; diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/MaintenanceService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/MaintenanceService.cs" index aad8de4..f821fef 100644 --- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/MaintenanceService.cs" +++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/MaintenanceService.cs" @@ -25,6 +25,8 @@ { _user = user; } + + public WebResponseContent ShowMaintence(PaginationDTO pagination) { try @@ -75,7 +77,7 @@ /// <summary> - /// 妯$硦鏌ヨ + /// 浜哄憳鐩戞帶 /// </summary> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> @@ -166,6 +168,12 @@ } } + + /// <summary> + /// 鏇存敼鐘舵�� + /// </summary> + /// <param name="id"></param> + /// <returns></returns> public WebResponseContent ChangeTasState(int id) { try @@ -219,8 +227,8 @@ var sys = _user.Db.Queryable<Sys_User>(); var main = Db.Queryable<Dt_Maintenance>(); + //妯$硦鏌ヨ var query = sys.InnerJoin<Dt_Maintenance>((a, b) => a.UserName == b.UserAccount); - if (!string.IsNullOrEmpty(pagination.searchKeyword)) { query = query.Where((a, b) => @@ -229,12 +237,33 @@ a.HeadImageUrl.Contains(pagination.searchKeyword) ); } - + //鏃堕棿鏌ヨ if (pagination.startDate.HasValue && pagination.endDate.HasValue) { query = query.Where((a, b) => b.MaintenancStartTime >= pagination.startDate.Value && b.MaintenancStartTime <= pagination.endDate.Value); } + //鎺掑簭 + if (!string.IsNullOrEmpty(pagination.sortField)) + { + var isAcs = pagination.sortOrder?.ToLower() == "asc"; + query = pagination.sortField.ToLower() switch + { + + "maintenancstarttime" => isAcs ? query.OrderBy((a, b) => b.MaintenancStartTime) : query.OrderByDescending((a, b) => b.MaintenancStartTime), + + "maintenancenendtime" => isAcs ? query.OrderBy((a, b) => b.MaintenancEendTime) : query.OrderByDescending((a, b) => b.MaintenancEendTime), + + _ => query.OrderByDescending((a, b) => b.Creater) // 榛樿鎸夊垱寤烘椂闂撮檷搴� + }; + + } + else + { + query=query.OrderByDescending((a, b) => b.Creater); + } + + //杩斿洖缁撴灉 var result = query.Select((a, b) => new { a.UserTrueName, diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/MaintenanceTeamService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/MaintenanceTeamService.cs" index 41dc177..44f9d69 100644 --- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/MaintenanceTeamService.cs" +++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/MaintenanceTeamService.cs" @@ -1,4 +1,5 @@ -锘縰sing System; +锘縰sing SqlSugar; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -36,6 +37,8 @@ var sys = _user.Db.Queryable<Sys_User>(); var main = Db.Queryable<Dt_MaintenanceTeam>(); + + //妯$硦鏌ヨ var query = sys.InnerJoin<Dt_MaintenanceTeam>((a, b) => a.UserTrueName == b.OperatorName); if (!string .IsNullOrEmpty(pagination.searchKeyword)) { @@ -46,10 +49,36 @@ b.Modifier.Contains(pagination.searchKeyword) ); } + //鏃堕棿鏌ヨ if (pagination.startDate.HasValue&&pagination.endDate.HasValue) { query = query.Where((a, b) => b.DistributionTime >= pagination.startDate && b.DistributionTime <= pagination.endDate); } + //鎺掑簭 + if (!string.IsNullOrEmpty(pagination.sortField)) + { + var isAsc = pagination.sortOrder?.ToLower() == "asc"; + query = pagination.sortField.ToLower() switch + { + //"OperatorName" => isAsc ? query.OrderBy((a, b) => b.OperatorName) : query.OrderByDescending((a, b) => b.OperatorName), + + //"TeamName" => isAsc ? query.OrderBy((a, b) => b.TeamName) : query.OrderByDescending((a, b) => b.TeamName), + + "distributiontime" => isAsc ? query.OrderBy((a, b) => b.DistributionTime) : query.OrderByDescending((a, b) => b.DistributionTime), + + //"Modifier" => isAsc ? query.OrderBy((a, b) => b.Modifier) : query.OrderByDescending((a, b) => b.Modifier), + + _ => query.OrderByDescending((a, b) => b.Creater), // 榛樿鎸夊垱寤烘椂闂撮檷搴� + }; + + } + else + { + //榛樿鎸夊垱寤烘椂闂撮檷搴忔帓搴� + query = query.OrderByDescending((a, b) => b.Creater); + } + + //杩斿洖缁撴灉 var result=query .Select((a, b) => new { -- Gitblit v1.9.3