李昊 4 years ago
parent
commit
6ce63434f6

+ 36 - 5
gx_api/GxPress/Api/GxPress.Api/AdminControllers/AdminCategoryController.cs

@@ -1,7 +1,10 @@
 using System.Collections.Generic;
 using System.Threading.Tasks;
+using GxPress.Auth;
 using GxPress.Repository.Interface.Category;
+using GxPress.Repository.Interface.TrackLog;
 using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
 
 // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
@@ -14,9 +17,15 @@ namespace GxPress.Api.AdminControllers
     public class AdminCategoryController : Controller
     {
         private readonly ICategoryRepository categoryRepository;
-        public AdminCategoryController(ICategoryRepository categoryRepository)
+        private readonly ILoginContext _loginContext;
+        private readonly IHttpContextAccessor httpContextAccessor;
+        private readonly ITrackLogRepository trackLogRepository;
+        public AdminCategoryController(ICategoryRepository categoryRepository, ILoginContext _loginContext, IHttpContextAccessor httpContextAccessor, ITrackLogRepository trackLogRepository)
         {
             this.categoryRepository = categoryRepository;
+            this.httpContextAccessor = httpContextAccessor;
+            this._loginContext = _loginContext;
+            this.trackLogRepository = trackLogRepository;
         }
         /// <summary>
         /// 详情
@@ -36,7 +45,15 @@ namespace GxPress.Api.AdminControllers
         [HttpDelete("{id}")]
         public async Task<bool> DeleteAsync(int id)
         {
-            return await categoryRepository.DeleteAsync(id);
+            var success = await categoryRepository.DeleteAsync(id);
+            if (success)
+            {
+                var category = await categoryRepository.GetAsync(id);
+                var ip = httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString();
+                var remark = $"删除类目:{category.Name}";
+                await trackLogRepository.InsertAsync(_loginContext.Name, _loginContext.AccountId, ip, remark);
+            }
+            return success;
         }
         /// <summary>
         /// 添加
@@ -45,9 +62,16 @@ namespace GxPress.Api.AdminControllers
         /// <returns></returns>
         [HttpPost]
 
-        public async Task<int> InsertAsync(Entity.tede2.Category.Category note)
+        public async Task<bool> InsertAsync(Entity.tede2.Category.Category note)
         {
-            return await categoryRepository.InsertAsync(note);
+            var success = await categoryRepository.InsertAsync(note) > 0;
+            if (success)
+            {
+                var ip = httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString();
+                var remark = $"添加类目:{note.Name}";
+                await trackLogRepository.InsertAsync(_loginContext.Name, _loginContext.AccountId, ip, remark);
+            }
+            return success;
         }
         /// <summary>
         /// 修改
@@ -57,7 +81,14 @@ namespace GxPress.Api.AdminControllers
         [HttpPut]
         public async Task<bool> UpdateAsync(Entity.tede2.Category.Category note)
         {
-            return await categoryRepository.UpdateAsync(note);
+            var success = await categoryRepository.UpdateAsync(note);
+            if (success)
+            {
+                var ip = httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString();
+                var remark = $"修改类目:{note.Name}";
+                await trackLogRepository.InsertAsync(_loginContext.Name, _loginContext.AccountId, ip, remark);
+            }
+            return success;
         }
         /// <summary>
         /// 获取所有

+ 37 - 4
gx_api/GxPress/Api/GxPress.Api/AdminControllers/AdminMediaController.cs

@@ -1,12 +1,16 @@
 using System.Threading.Tasks;
 using GxPress.Auth;
 using GxPress.Common.Page;
+using GxPress.EnumConst;
 using GxPress.Repository.Interface.Media;
+using GxPress.Repository.Interface.TrackLog;
 using GxPress.Request.Media;
 using GxPress.Result.Media;
 using GxPress.Service.Interface.Media;
 using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
+using GxPress.Common.Tools;
 
 // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
 
@@ -20,11 +24,15 @@ namespace GxPress.Api.AdminControllers
         private readonly IMediaRepository mediaRepository;
         private readonly ILoginContext _loginContext;
         private readonly IMediaService mediaService;
-        public AdminMediaController(IMediaRepository mediaRepository, ILoginContext _loginContext, IMediaService mediaService)
+        private readonly ITrackLogRepository trackLogRepository;
+        private readonly IHttpContextAccessor httpContextAccessor;
+        public AdminMediaController(IMediaRepository mediaRepository, ILoginContext _loginContext, IMediaService mediaService, ITrackLogRepository trackLogRepository, IHttpContextAccessor httpContextAccessor)
         {
             this.mediaRepository = mediaRepository;
             this._loginContext = _loginContext;
             this.mediaService = mediaService;
+            this.trackLogRepository = trackLogRepository;
+            this.httpContextAccessor = httpContextAccessor;
         }
         /// <summary>
         /// 详情
@@ -44,7 +52,16 @@ namespace GxPress.Api.AdminControllers
         [HttpDelete("{id}")]
         public async Task<bool> DeleteAsync(int id)
         {
-            return await mediaRepository.DeleteAsync(id);
+            var result = await mediaRepository.GetAsync(id);
+            var success = await mediaRepository.DeleteAsync(id);
+            if (success)
+            {
+                var ip = httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString();
+                var mediaTypeValue = ((ResourceTypeConst)result.MediaType).GetDescriptionOriginal();
+                var remark = $"删除{mediaTypeValue}{result.Title}";
+                await trackLogRepository.InsertAsync(_loginContext.Name, _loginContext.AccountId, ip, remark);
+            }
+            return success;
         }
         /// <summary>
         /// 添加媒体
@@ -56,7 +73,15 @@ namespace GxPress.Api.AdminControllers
         {
             result.AdminId = _loginContext.AccountId;
             result.Creator = _loginContext.Name;
-            return await mediaService.InsertAsync(result);
+            var success = await mediaService.InsertAsync(result);
+            if (success)
+            {
+                var ip = httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString();
+                var mediaTypeValue = ((ResourceTypeConst)result.MediaType).GetDescriptionOriginal();
+                var remark = $"添加{mediaTypeValue}{result.Title}";
+                await trackLogRepository.InsertAsync(_loginContext.Name, _loginContext.AccountId, ip, remark);
+            }
+            return success;
         }
         /// <summary>
         /// 修改
@@ -66,7 +91,15 @@ namespace GxPress.Api.AdminControllers
         [HttpPut]
         public async Task<bool> UpdateAsync(MediaResult result)
         {
-            return await mediaRepository.UpdateAsync(result);
+            var success = await mediaRepository.UpdateAsync(result);
+            if (success)
+            {
+                var ip = httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString();
+                var mediaTypeValue = ((ResourceTypeConst)result.MediaType).GetDescriptionOriginal();
+                var remark = $"修改{mediaTypeValue}{result.Title}";
+                await trackLogRepository.InsertAsync(_loginContext.Name, _loginContext.AccountId, ip, remark);
+            }
+            return success;
         }
         /// <summary>
         /// 查询

+ 40 - 5
gx_api/GxPress/Api/GxPress.Api/AdminControllers/AdminVipEquityController.cs

@@ -1,11 +1,15 @@
 using System.Collections.Generic;
 using System.Threading.Tasks;
+using GxPress.Auth;
+using GxPress.EnumConst;
+using GxPress.Repository.Interface.TrackLog;
 using GxPress.Repository.Interface.VipEquity;
 using GxPress.Request.VipEquity;
 using GxPress.Result.VipEquity;
 using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
-
+using GxPress.Common.Tools;
 namespace GxPress.Api.AdminControllers
 {
     /// <summary>
@@ -17,9 +21,15 @@ namespace GxPress.Api.AdminControllers
     public class AdminVipEquityController : Controller
     {
         private readonly IVipEquityRepository vipEquityRepository;
-        public AdminVipEquityController(IVipEquityRepository vipEquityRepository)
+        private readonly ILoginContext _loginContext;
+        private readonly IHttpContextAccessor httpContextAccessor;
+        private readonly ITrackLogRepository trackLogRepository;
+        public AdminVipEquityController(IVipEquityRepository vipEquityRepository, ILoginContext _loginContext, IHttpContextAccessor httpContextAccessor, ITrackLogRepository trackLogRepository)
         {
             this.vipEquityRepository = vipEquityRepository;
+            this._loginContext = _loginContext;
+            this.httpContextAccessor = httpContextAccessor;
+            this.trackLogRepository = trackLogRepository;
         }
         /// <summary>
         /// 获取列表
@@ -30,6 +40,8 @@ namespace GxPress.Api.AdminControllers
         {
             return await vipEquityRepository.GetAllAsync();
         }
+
+
         /// <summary>
         /// 修改
         /// </summary>
@@ -38,7 +50,15 @@ namespace GxPress.Api.AdminControllers
         [HttpPut]
         public async Task<bool> UpdateAsync(VipEquityUpdateRequest request)
         {
-            return await vipEquityRepository.UpdateAsync(request);
+            var success = await vipEquityRepository.UpdateAsync(request);
+            if (success)
+            {
+                var vipEquity = await vipEquityRepository.GetAsync(request.Id);
+                var ip = httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString();
+                var remark = $"修改Vip权益:{((VipCardTypeConst)vipEquity.VipType).GetDescriptionOriginal()}";
+                await trackLogRepository.InsertAsync(_loginContext.Name, _loginContext.AccountId, ip, remark);
+            }
+            return success;
         }
         /// <summary>
         /// 添加
@@ -48,7 +68,14 @@ namespace GxPress.Api.AdminControllers
         [HttpPost]
         public async Task<bool> InsertAsync(Entity.tede2.VipEquity.VipEquity model)
         {
-            return await vipEquityRepository.InsertAsync(model);
+            var success = await vipEquityRepository.InsertAsync(model);
+            if (success)
+            {
+                var ip = httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString();
+                var remark = $"添加Vip权益:{((VipCardTypeConst)model.VipType).GetDescriptionOriginal()}";
+                await trackLogRepository.InsertAsync(_loginContext.Name, _loginContext.AccountId, ip, remark);
+            }
+            return success;
         }
         /// <summary>
         /// 根据ID删除
@@ -58,7 +85,15 @@ namespace GxPress.Api.AdminControllers
         [HttpDelete("{id}")]
         public async Task<bool> DeleteAsync(int id)
         {
-            return await vipEquityRepository.DeleteAsync(id);
+            var success = await vipEquityRepository.DeleteAsync(id);
+            if (success)
+            {
+                var vipEquity = await vipEquityRepository.GetAsync(id);
+                var ip = httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString();
+                var remark = $"删除Vip权益:{((VipCardTypeConst)vipEquity.VipType).GetDescriptionOriginal()}";
+                await trackLogRepository.InsertAsync(_loginContext.Name, _loginContext.AccountId, ip, remark);
+            }
+            return success;
         }
     }
 }

+ 1 - 1
gx_api/GxPress/Model/GxPress.Request/TrackLog/TrackLogRequest.cs

@@ -3,7 +3,7 @@ namespace GxPress.Request.TrackLog
     /// <summary>
     /// 系统日志查询
     /// </summary>
-    public class TrackLogSearchRequest
+    public class TrackLogSearchRequest:Common.Page.PageParameter
     {
         /// <summary>
         /// 搜索字段

+ 5 - 2
gx_api/GxPress/Model/GxPress.Result/Media/MediaResult.cs

@@ -1,16 +1,19 @@
-using System;
-using System.Collections.Generic;
+using System.Collections.Generic;
 using GxPress.EnumConst;
 using GxPress.Result.Category;
 
 namespace GxPress.Result.Media
 {
+    /// <summary>
+    /// 媒体
+    /// </summary>
     public class MediaResult
     {
         /// <summary>
         /// 
         /// </summary>
         public int Id { get; set; }
+        
         /// <summary>
         /// 媒体类型
         /// Article=1,

+ 1 - 1
gx_api/GxPress/Repository/GxPress.Repository.Implement/Attach/AttachRepository.cs

@@ -50,7 +50,7 @@ namespace GxPress.Repository.Implement.Attach
                 query.Where(nameof(Entity.tede2.Attach.Attach.CategoryId), request.AdminId);
             if (request.WithdrawType > 0)
                 query.Where(nameof(Entity.tede2.Attach.Attach.IsWithdraw), request.WithdrawType == 2);
-            result.Items = await _repository.GetAllAsync(query.ForPage(request.Page, request.PerPage));
+            result.Items = await _repository.GetAllAsync(query.OrderByDesc(nameof(Entity.tede2.Attach.Attach.CreatedDate)).ForPage(request.Page, request.PerPage));
             result.Total = await _repository.CountAsync(query);
             return result;
         }

+ 1 - 1
gx_api/GxPress/Repository/GxPress.Repository.Implement/Media/MediaRepository.cs

@@ -176,7 +176,7 @@ namespace GxPress.Repository.Implement.Media
             if (request.LibraryType > 0)
                 query.Where(nameof(Entity.tede2.Media.Media.IsLibrary), request.LibraryType == 1);
             result.Total = await _repository.CountAsync(query);
-            var item = await _repository.GetAllAsync(query.ForPage(request.Page, request.PerPage).OrderByDesc(nameof(Entity.tede2.Media.Media.Sort)));
+            var item = await _repository.GetAllAsync(query.OrderByDesc(nameof(Entity.tede2.Media.Media.CreatedDate)).ForPage(request.Page, request.PerPage));
             result.Items = item;
             return result;
         }

+ 1 - 1
gx_api/GxPress/Repository/GxPress.Repository.Implement/Organization/OrganizationRepository.cs

@@ -41,7 +41,7 @@ namespace GxPress.Repository.Implement.Organization
             if (!string.IsNullOrEmpty(request.KeyWord))
                 query.WhereLike(nameof(Entity.tede2.Organization.Organization.Name), $"%{request.KeyWord}%");
             result.Total = await _repository.CountAsync(query);
-            result.Items = await _repository.GetAllAsync(query.ForPage(request.Page, request.PerPage));
+            result.Items = await _repository.GetAllAsync(query.OrderByDesc(nameof(Entity.tede2.Organization.Organization.CreatedDate)).ForPage(request.Page, request.PerPage));
             return result;
         }
         /// <summary>

+ 1 - 1
gx_api/GxPress/Repository/GxPress.Repository.Implement/SensitiveWord/SensitiveWordRepository.cs

@@ -88,7 +88,7 @@ namespace GxPress.Repository.Implement.SensitiveWord
                 }
             }
             result.Total = await _repository.CountAsync(query);
-            result.Items = await _repository.GetAllAsync(query.ForPage(request.Page, request.PerPage));
+            result.Items = await _repository.GetAllAsync(query.OrderByDesc(nameof(Entity.tede2.SensitiveWord.SensitiveWord.CreatedDate)).ForPage(request.Page, request.PerPage));
             return result;
         }
     }

+ 1 - 1
gx_api/GxPress/Repository/GxPress.Repository.Implement/Teacher/TeacherRepository.cs

@@ -44,7 +44,7 @@ namespace GxPress.Repository.Implement.Teacher
             var query = Q.NewQuery();
             if (!string.IsNullOrEmpty(request.KeyWord))
                 query.WhereLike(nameof(Entity.tede2.Teacher.Teacher.Name), $"%{request.KeyWord}%");
-            result.Items = await _repository.GetAllAsync(query.ForPage(request.Page, request.PerPage));
+            result.Items = await _repository.GetAllAsync(query.OrderByDesc(nameof(Entity.tede2.Teacher.Teacher.CreatedDate)).ForPage(request.Page, request.PerPage));
             result.Total = await _repository.CountAsync(query);
             return result;
         }

+ 1 - 1
gx_api/GxPress/Repository/GxPress.Repository.Implement/ThesaurusRepository.cs

@@ -100,7 +100,7 @@ namespace GxPress.Repository.Implement
                 query.WhereLike(nameof(Thesaurus.ThesaurusName), request.ThesaurusName);
             if (request.ThesaurusType > 0)
                 query.Where(nameof(Thesaurus.ThesaurusType), request.ThesaurusType);
-            query.ForPage(request.Page, request.PerPage);
+            query.OrderByDesc(nameof(Entity.Thesaurus.CreatedDate)).ForPage(request.Page, request.PerPage);
             return await _repository.GetAllAsync(query);
         }
         /// <summary>

+ 13 - 1
gx_api/GxPress/Repository/GxPress.Repository.Implement/TrackLog/TrackLogRepository.cs

@@ -47,7 +47,7 @@ namespace GxPress.Repository.Implement.TrackLog
                 }
             }
             result.Total = await _repository.CountAsync(query);
-            result.Items = await _repository.GetAllAsync(query);
+            result.Items = await _repository.GetAllAsync(query.OrderByDesc(nameof(Entity.tede2.TrackLog.TrackLog.CreatedDate)).ForPage(request.Page, request.PerPage));
             return result;
         }
 
@@ -55,5 +55,17 @@ namespace GxPress.Repository.Implement.TrackLog
         {
             return await _repository.InsertAsync(model) > 0;
         }
+
+        public async Task<bool> InsertAsync(string creator, int adminId, string ip, string remark)
+        {
+            var model = new Entity.tede2.TrackLog.TrackLog()
+            {
+                Creator = creator,
+                AdminId = adminId,
+                Ip = ip,
+                Remark = remark
+            };
+            return await _repository.InsertAsync(model) > 0;
+        }
     }
 }

+ 9 - 0
gx_api/GxPress/Repository/GxPress.Repository.Implement/VipEquity/VipEquityRepository.cs

@@ -66,5 +66,14 @@ namespace GxPress.Repository.Implement.VipEquity
         {
             return await _repository.DeleteAsync(id);
         }
+        /// <summary>
+        /// /// 查询
+        /// </summary>
+        /// <param name="id"></param>
+        /// <returns></returns>
+        public async Task<Entity.tede2.VipEquity.VipEquity> GetAsync(int id)
+        {
+            return await _repository.GetAsync(id);
+        }
     }
 }

+ 1 - 0
gx_api/GxPress/Repository/GxPress.Repository.Interface/TrackLog/ITrackLogRepository.cs

@@ -9,5 +9,6 @@ namespace GxPress.Repository.Interface.TrackLog
     {
         Task<PagedList<Entity.tede2.TrackLog.TrackLog>> GetAllAsync(TrackLogSearchRequest request);
         Task<bool> InsertAsync(Entity.tede2.TrackLog.TrackLog model);
+        Task<bool> InsertAsync(string creator, int adminId, string ip, string remark);
     }
 }

+ 6 - 0
gx_api/GxPress/Repository/GxPress.Repository.Interface/VipEquity/IVipEquityRepository.cs

@@ -13,5 +13,11 @@ namespace GxPress.Repository.Interface.VipEquity
         Task<bool> UpdateAsync(VipEquityUpdateRequest request);
         Task<bool> InsertAsync(Entity.tede2.VipEquity.VipEquity model);
         Task<bool> DeleteAsync(int id);
+        /// <summary>
+        /// /// 查询
+        /// </summary>
+        /// <param name="id"></param>
+        /// <returns></returns>
+         Task<Entity.tede2.VipEquity.VipEquity> GetAsync(int id);
     }
 }