zuoxiang 4 years ago
parent
commit
dd23579c17

+ 74 - 0
gx_api/GxPress/Api/GxPress.Api/AdminControllers/AdminSensitiveWordController.cs

@@ -0,0 +1,74 @@
+using System.Threading.Tasks;
+using GxPress.Common.Page;
+using GxPress.Repository.Interface.SensitiveWord;
+using GxPress.Request.SensitiveWord;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc;
+
+namespace GxPress.Api.AdminControllers
+{
+    /// <summary>
+    /// 敏感词
+    /// </summary>
+    [Route("api/admin/sensitive-word")]
+    [ApiController]
+    [Authorize]
+    public class AdminSensitiveWordController : Controller
+    {
+        private readonly ISensitiveWordRepository _repository;
+        public AdminSensitiveWordController(ISensitiveWordRepository _repository)
+        {
+            this._repository = _repository;
+        }
+        /// <summary>
+        /// 查询详情
+        /// </summary>
+        /// <param name="id"></param>
+        /// <returns></returns>
+        [HttpGet("{id}")]
+        public async Task<Entity.tede2.SensitiveWord.SensitiveWord> GetAsync(int id)
+        {
+            return await _repository.GetAsync(id);
+        }
+        /// <summary>
+        /// 删除
+        /// </summary>
+        /// <param name="id"></param>
+        /// <returns></returns>
+        [HttpDelete("{id}")]
+        public async Task<bool> DeleteAsync(int id)
+        {
+            return await _repository.DeleteAsync(id);
+        }
+        /// <summary>
+        /// 添加
+        /// </summary>
+        /// <param name="note"></param>
+        /// <returns></returns>
+        [HttpPost]
+        public async Task<int> InsertAsync(Entity.tede2.SensitiveWord.SensitiveWord note)
+        {
+            return await _repository.InsertAsync(note);
+        }
+        /// <summary>
+        /// 修改
+        /// </summary>
+        /// <param name="note"></param>
+        /// <returns></returns>
+        [HttpPut]
+        public async Task<bool> UpdateAsync(Entity.tede2.SensitiveWord.SensitiveWord note)
+        {
+            return await _repository.UpdateAsync(note);
+        }
+        /// <summary>
+        /// 查询
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [HttpPost("list")]
+        public async Task<PagedList<Entity.tede2.SensitiveWord.SensitiveWord>> GetAllAsync(SensitiveWordRequest request)
+        {
+             return await _repository.GetAllAsync(request);
+        }
+    }
+}

+ 14 - 3
gx_api/GxPress/Api/GxPress.Api/AdminControllers/AdminTeacherController.cs

@@ -7,6 +7,8 @@ using System.Threading.Tasks;
 using System.Collections.Generic;
 using GxPress.Common.Page;
 using GxPress.Request.TeacherRequest;
+using GxPress.Auth;
+using GxPress.Service.Interface.Teacher;
 
 namespace GxPress.Api.AdminControllers
 {
@@ -19,9 +21,14 @@ namespace GxPress.Api.AdminControllers
     public class AdminTeacherController : Controller
     {
         private readonly ITeacherRepository teacherRepository;
-        public AdminTeacherController(ITeacherRepository teacherRepository)
+
+        private readonly ITeacherService service;
+        private readonly ILoginContext _loginContext;
+        public AdminTeacherController(ITeacherRepository teacherRepository, ILoginContext _loginContext, ITeacherService service)
         {
             this.teacherRepository = teacherRepository;
+            this._loginContext = _loginContext;
+            this.service = service;
         }
         /// <summary>
         /// 删除
@@ -70,7 +77,9 @@ namespace GxPress.Api.AdminControllers
         [HttpPost]
         public async Task<int> InsertAsync(Entity.tede2.Teacher.Teacher note)
         {
-            return await teacherRepository.InsertAsync(note);
+            note.AdminId = _loginContext.AccountId;
+            note.Creator = _loginContext.Name;
+            return await service.InsertAsync(note);
         }
         /// <summary>
         /// 修改
@@ -80,7 +89,9 @@ namespace GxPress.Api.AdminControllers
         [HttpPut]
         public async Task<bool> UpdateAsync(Entity.tede2.Teacher.Teacher note)
         {
-            return await teacherRepository.UpdateAsync(note);
+            note.AdminId = _loginContext.AccountId;
+            note.Creator = _loginContext.Name;
+            return await service.UpdateAsync(note);
         }
     }
 }

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


+ 30 - 0
gx_api/GxPress/Model/GxPress.Entity/tede2/SensitiveWord/SensitiveWord.cs

@@ -0,0 +1,30 @@
+using Datory.Annotations;
+
+namespace GxPress.Entity.tede2.SensitiveWord
+{
+    /// <summary>
+    /// 敏感词库
+    /// </summary>
+    [DataTable("tede_sensitive_word")]
+    public class SensitiveWord : Datory.Entity
+    {
+        /// <summary>
+        /// 敏感名称
+        /// </summary>
+        /// <value></value>
+        [DataColumn]
+        public string Name { get; set; }
+        /// <summary>
+        /// 操作人员
+        /// </summary>
+        /// <value></value>
+        [DataColumn]
+        public int AdminId { get; set; }
+        /// <summary>
+        /// 操作人员名称
+        /// </summary>
+        /// <value></value>
+        [DataColumn]
+        public string Creator { get; set; }
+    }
+}

+ 3 - 1
gx_api/GxPress/Model/GxPress.Entity/tede2/Teacher/Teacher.cs

@@ -19,6 +19,7 @@ namespace GxPress.Entity.tede2.Teacher
         /// 操作人
         /// </summary>
         /// <value></value>
+        [DataColumn]
         public string Creator { get; set; }
 
         /// <summary>
@@ -40,7 +41,7 @@ namespace GxPress.Entity.tede2.Teacher
         /// </summary>
         /// <value></value>
         [DataColumn]
-        public string CategoryId { get; set; }
+        public int CategoryId { get; set; }
 
         /// <summary>
         /// 分类名称
@@ -90,5 +91,6 @@ namespace GxPress.Entity.tede2.Teacher
         /// </summary>
         [DataColumn]
         public string ImageUrl { get; set; }
+       
     }
 }

+ 26 - 0
gx_api/GxPress/Model/GxPress.Request/SensitiveWord/SensitiveWordRequest.cs

@@ -0,0 +1,26 @@
+using GxPress.Common.Page;
+
+namespace GxPress.Request.SensitiveWord
+{
+    /// <summary>
+    /// 敏感词查询
+    /// </summary>
+    public class SensitiveWordRequest : PageParameter
+    {
+        /// <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; }
+    }
+}

+ 10 - 0
gx_api/GxPress/Repository/GxPress.Repository.Implement/Category/CategoryRepository.cs

@@ -80,5 +80,15 @@ namespace GxPress.Repository.Implement.Category
             query.Where(nameof(Entity.tede2.Category.Category.ParentId), parentId);
             return await _repository.CountAsync(query) > 0;
         }
+
+        public async Task<string> GetCategoryParentAsync(int id, string categoryName)
+        {
+            var result = await _repository.GetAsync(id);
+            if (result == null)
+                return categoryName;
+            categoryName = string.IsNullOrEmpty(categoryName) ? $"{result.Name}" : $"{result.Name}/{categoryName}";
+            return await GetCategoryParentAsync(result.ParentId, categoryName);
+        }
+
     }
 }

+ 95 - 0
gx_api/GxPress/Repository/GxPress.Repository.Implement/SensitiveWord/SensitiveWordRepository.cs

@@ -0,0 +1,95 @@
+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.SensitiveWord;
+using GxPress.Request.SensitiveWord;
+using Microsoft.Extensions.Options;
+
+namespace GxPress.Repository.Implement.SensitiveWord
+{
+    public class SensitiveWordRepository : ISensitiveWordRepository
+    {
+        private readonly Repository<Entity.tede2.SensitiveWord.SensitiveWord> _repository;
+        private readonly IMapper _mapper;
+        private readonly string _connectionString;
+        private readonly string _databaseTypestr;
+        public SensitiveWordRepository(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.SensitiveWord.SensitiveWord>(database);
+            _mapper = mapper;
+        }
+
+        public IDatabase Database => _repository.Database;
+        public string TableName => _repository.TableName;
+        public List<TableColumn> TableColumns => _repository.TableColumns;
+        /// <summary>
+        /// 查询详情
+        /// </summary>
+        /// <param name="id"></param>
+        /// <returns></returns>
+        public async Task<Entity.tede2.SensitiveWord.SensitiveWord> GetAsync(int id)
+        {
+            return await _repository.GetAsync(id);
+        }
+        /// <summary>
+        /// 删除
+        /// </summary>
+        /// <param name="id"></param>
+        /// <returns></returns>
+        public async Task<bool> DeleteAsync(int id)
+        {
+            return await _repository.DeleteAsync(id);
+        }
+        /// <summary>
+        /// 添加
+        /// </summary>
+        /// <param name="note"></param>
+        /// <returns></returns>
+        public async Task<int> InsertAsync(Entity.tede2.SensitiveWord.SensitiveWord note)
+        {
+            return await _repository.InsertAsync(note);
+        }
+        /// <summary>
+        /// 修改
+        /// </summary>
+        /// <param name="note"></param>
+        /// <returns></returns>
+        public async Task<bool> UpdateAsync(Entity.tede2.SensitiveWord.SensitiveWord note)
+        {
+            return await _repository.UpdateAsync(note);
+        }
+        /// <summary>
+        /// 查询
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        public async Task<PagedList<Entity.tede2.SensitiveWord.SensitiveWord>> GetAllAsync(SensitiveWordRequest request)
+        {
+            var result = new PagedList<Entity.tede2.SensitiveWord.SensitiveWord>();
+            var query = Q.NewQuery();
+            if (!string.IsNullOrEmpty(request.KeyWord))
+                query.Where(Q.WhereLike(nameof(Entity.tede2.SensitiveWord.SensitiveWord.Name), $"%{request.KeyWord}%"));
+            if (!string.IsNullOrEmpty(request.BeginTime) && !string.IsNullOrEmpty(request.EndTime))
+            {
+                if (DateTime.TryParse(request.BeginTime, out var beginTime) && DateTime.TryParse(request.EndTime, out var endTime))
+                {
+                    query.WhereDate(nameof(Entity.tede2.SensitiveWord.SensitiveWord.CreatedDate), ">", beginTime);
+                    query.WhereDate(nameof(Entity.tede2.SensitiveWord.SensitiveWord.CreatedDate), ">", endTime);
+                }
+            }
+            result.Total = await _repository.CountAsync(query);
+            result.Items = await _repository.GetAllAsync(query.ForPage(request.Page, request.PerPage));
+            return result;
+        }
+    }
+}

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

@@ -60,7 +60,7 @@ namespace GxPress.Repository.Implement.Teacher
 
         public async Task<int> InsertAsync(Entity.tede2.Teacher.Teacher note)
         {
-
+             
             return await _repository.InsertAsync(note);
         }
 

+ 2 - 0
gx_api/GxPress/Repository/GxPress.Repository.Interface/Category/CategoryRepository.cs

@@ -31,5 +31,7 @@ namespace GxPress.Repository.Interface.Category
         /// <param name="parentId"></param>
         /// <returns></returns>
         Task<IEnumerable<Entity.tede2.Category.Category>> GetCategoryChildrenAsync(int parentId);
+
+        Task<string> GetCategoryParentAsync(int id, string categoryName);
     }
 }

+ 41 - 0
gx_api/GxPress/Repository/GxPress.Repository.Interface/SensitiveWord/ISensitiveWordRepository.cs

@@ -0,0 +1,41 @@
+using System.Threading.Tasks;
+using Datory;
+using GxPress.Common.Page;
+using GxPress.Request.SensitiveWord;
+
+namespace GxPress.Repository.Interface.SensitiveWord
+{
+    public interface ISensitiveWordRepository : IRepository
+    {
+        /// <summary>
+        /// 查询详情
+        /// </summary>
+        /// <param name="id"></param>
+        /// <returns></returns>
+        Task<Entity.tede2.SensitiveWord.SensitiveWord> GetAsync(int id);
+        /// <summary>
+        /// 删除
+        /// </summary>
+        /// <param name="id"></param>
+        /// <returns></returns>
+        Task<bool> DeleteAsync(int id);
+        /// <summary>
+        /// 添加
+        /// </summary>
+        /// <param name="note"></param>
+        /// <returns></returns>
+        Task<int> InsertAsync(Entity.tede2.SensitiveWord.SensitiveWord note);
+        /// <summary>
+        /// 修改
+        /// </summary>
+        /// <param name="note"></param>
+        /// <returns></returns>
+        Task<bool> UpdateAsync(Entity.tede2.SensitiveWord.SensitiveWord note);
+        /// <summary>
+        /// 查询
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        Task<PagedList<Entity.tede2.SensitiveWord.SensitiveWord>> GetAllAsync(SensitiveWordRequest request);
+    }
+}

+ 31 - 0
gx_api/GxPress/Service/GxPress.Service.Implement/Teacher/TeacherService.cs

@@ -0,0 +1,31 @@
+using System.Threading.Tasks;
+using GxPress.Repository.Interface.Category;
+using GxPress.Repository.Interface.Teacher;
+using GxPress.Service.Interface.Teacher;
+
+namespace GxPress.Service.Implement.Teacher
+{
+    public class TeacherService : ITeacherService
+    {
+        private readonly ICategoryRepository categoryRepository;
+        private readonly ITeacherRepository teacherRepository;
+
+        public TeacherService(ICategoryRepository categoryRepository, ITeacherRepository teacherRepository)
+        {
+            this.categoryRepository = categoryRepository;
+            this.teacherRepository = teacherRepository;
+        }
+
+        public async Task<int> InsertAsync(Entity.tede2.Teacher.Teacher note)
+        {
+            note.CategoryName = await categoryRepository.GetCategoryParentAsync(note.CategoryId, note.CategoryName);
+            return await teacherRepository.InsertAsync(note);
+        }
+
+        public async Task<bool> UpdateAsync(Entity.tede2.Teacher.Teacher note)
+        {
+            note.CategoryName = await categoryRepository.GetCategoryParentAsync(note.CategoryId, note.CategoryName);
+            return await teacherRepository.UpdateAsync(note);
+        }
+    }
+}

+ 10 - 0
gx_api/GxPress/Service/GxPress.Service.Interface/Teacher/ITeacherService.cs

@@ -0,0 +1,10 @@
+using System.Threading.Tasks;
+
+namespace GxPress.Service.Interface.Teacher
+{
+    public interface ITeacherService:IService
+    {
+         Task<int> InsertAsync(Entity.tede2.Teacher.Teacher note);
+         Task<bool> UpdateAsync(Entity.tede2.Teacher.Teacher note);
+    }
+}