李昊 4 years ago
parent
commit
daac3c6879

+ 1 - 2
gx_api/GxPress/Api/GxPress.Api/AdminControllers/AdminMediaController.cs

@@ -1,5 +1,4 @@
-using System.Collections.Generic;
-using System.Threading.Tasks;
+using System.Threading.Tasks;
 using GxPress.Auth;
 using GxPress.Common.Page;
 using GxPress.Repository.Interface.Media;

+ 35 - 0
gx_api/GxPress/Api/GxPress.Api/AdminControllers/AdminTrackLogController.cs

@@ -0,0 +1,35 @@
+using System.Threading.Tasks;
+using GxPress.Common.Page;
+using GxPress.Repository.Interface.TrackLog;
+using GxPress.Request.TrackLog;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc;
+
+namespace GxPress.Api.AdminControllers
+{
+    /// <summary>
+    /// 系统日志
+    /// </summary>
+    [Route("api/admin/log")]
+    [ApiController]
+    [Authorize]
+
+    public class AdminTrackLogController : Controller
+    {
+        private readonly ITrackLogRepository repository;
+        public AdminTrackLogController(ITrackLogRepository repository)
+        {
+            this.repository = repository;
+        }
+        /// <summary>
+        /// 列表
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [HttpPost("list")]
+        public async Task<PagedList<Entity.tede2.TrackLog.TrackLog>> GetAllAsync(TrackLogSearchRequest request)
+        {
+            return await repository.GetAllAsync(request);
+        }
+    }
+}

File diff suppressed because it is too large
+ 6 - 2
gx_api/GxPress/Api/GxPress.Api/AdminControllers/AdminUtilsController.cs


+ 38 - 0
gx_api/GxPress/Model/GxPress.Entity/tede2/TrackLog/TrackLog.cs

@@ -0,0 +1,38 @@
+using Datory.Annotations;
+
+namespace GxPress.Entity.tede2.TrackLog
+{
+    /// <summary>
+    /// 系统日志
+    /// </summary>
+    [DataTable("tede_track_log")]
+
+    public class TrackLog : Datory.Entity
+    {
+        /// <summary>
+        /// 操作人
+        /// </summary>
+        /// <value></value>
+        [DataColumn]
+        public string Creator { get; set; }
+
+        /// <summary>
+        /// 操作人姓名
+        /// </summary>
+        /// <value></value>
+        [DataColumn]
+        public int AdminId { get; set; }
+        /// <summary>
+        /// ip
+        /// </summary>
+        /// <value></value>
+        [DataColumn]
+        public string Ip { get; set; }
+        /// <summary>
+        /// 备注
+        /// </summary>
+        /// <value></value>
+        [DataColumn]
+        public string Remark { get; set; }
+    }
+}

+ 24 - 0
gx_api/GxPress/Model/GxPress.Request/TrackLog/TrackLogRequest.cs

@@ -0,0 +1,24 @@
+namespace GxPress.Request.TrackLog
+{
+    /// <summary>
+    /// 系统日志查询
+    /// </summary>
+    public class TrackLogSearchRequest
+    {
+        /// <summary>
+        /// 搜索字段
+        /// </summary>
+        /// <value></value>
+        public string KeyWord { get; set; }
+        /// <summary>
+        /// 开始时间
+        /// </summary>
+        /// <value></value>
+        public string BeginTime { get; set; }
+        /// <summary>
+        ///结束时间
+        /// </summary>
+        /// <value></value>
+        public string EndTime { get; set; }
+    }
+}

+ 59 - 0
gx_api/GxPress/Repository/GxPress.Repository.Implement/TrackLog/TrackLogRepository.cs

@@ -0,0 +1,59 @@
+using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using AutoMapper;
+using Datory;
+using GxPress.Common.AppOptions;
+using GxPress.Common.Page;
+using GxPress.Common.Tools;
+using GxPress.Repository.Interface.TrackLog;
+using GxPress.Request.TrackLog;
+using Microsoft.Extensions.Options;
+
+namespace GxPress.Repository.Implement.TrackLog
+{
+    public class TrackLogRepository : ITrackLogRepository
+    {
+        private readonly Repository<Entity.tede2.TrackLog.TrackLog> _repository;
+        private readonly IMapper _mapper;
+        private readonly string _connectionString;
+        private readonly string _databaseTypestr;
+        public TrackLogRepository(IOptionsMonitor<DatabaseOptions> dbOptionsAccessor, IMapper mapper)
+        {
+            _databaseTypestr = dbOptionsAccessor.CurrentValue.DatabaseType;
+            _connectionString = dbOptionsAccessor.CurrentValue.ConnectionString;
+            var databaseType =
+                StringUtils.ToEnum<DatabaseType>(dbOptionsAccessor.CurrentValue.DatabaseType, DatabaseType.MySql);
+            var database = new Database(databaseType, dbOptionsAccessor.CurrentValue.ConnectionString);
+            _repository = new Repository<Entity.tede2.TrackLog.TrackLog>(database);
+            _mapper = mapper;
+        }
+        public IDatabase Database => _repository.Database;
+        public string TableName => _repository.TableName;
+        public List<TableColumn> TableColumns => _repository.TableColumns;
+
+        public async Task<PagedList<Entity.tede2.TrackLog.TrackLog>> GetAllAsync(TrackLogSearchRequest request)
+        {
+            var result = new PagedList<Entity.tede2.TrackLog.TrackLog>();
+            var query = Q.NewQuery();
+            if (!string.IsNullOrEmpty(request.KeyWord))
+                query.WhereLike(nameof(Entity.tede2.TrackLog.TrackLog.Remark), $"%request.KeyWord%");
+            if (!string.IsNullOrEmpty(request.BeginTime) && !string.IsNullOrEmpty(request.EndTime))
+            {
+                if (DateTime.TryParse(request.BeginTime, out var beginTime) && DateTime.TryParse(request.BeginTime, out var endTime))
+                {
+                    query.WhereDate(nameof(Entity.tede2.TrackLog.TrackLog.CreatedDate), ">=", beginTime);
+                    query.WhereDate(nameof(Entity.tede2.TrackLog.TrackLog.CreatedDate), "<=", endTime);
+                }
+            }
+            result.Total = await _repository.CountAsync(query);
+            result.Items = await _repository.GetAllAsync(query);
+            return result;
+        }
+
+        public async Task<bool> InsertAsync(Entity.tede2.TrackLog.TrackLog model)
+        {
+            return await _repository.InsertAsync(model) > 0;
+        }
+    }
+}

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

@@ -0,0 +1,13 @@
+using System.Threading.Tasks;
+using Datory;
+using GxPress.Common.Page;
+using GxPress.Request.TrackLog;
+
+namespace GxPress.Repository.Interface.TrackLog
+{
+    public interface ITrackLogRepository : IRepository
+    {
+        Task<PagedList<Entity.tede2.TrackLog.TrackLog>> GetAllAsync(TrackLogSearchRequest request);
+        Task<bool> InsertAsync(Entity.tede2.TrackLog.TrackLog model);
+    }
+}