李昊 il y a 4 ans
Parent
commit
66eb6fdfd4

+ 4 - 26
gx_api/GxPress/Api/GxPress.Api/AppControllers/AppPageController.cs

@@ -268,37 +268,15 @@ namespace GxPress.Api.AppControllers
             return await mediaService.GetStarLablePageAsync(request);
         }
         /// <summary>
-        /// 获取搜索作者
-        /// </summary>
-        /// <returns></returns>
-        [HttpGet("teacher/{categoryId}")]
-        [AllowAnonymous]
-        public async Task<IEnumerable<NavigationSearchTeacherResult>> GetNavigationSearchResultAysnc(int categoryId)
-        {
-            return await appHomePageService.GetNavigationSearchResultAysnc(categoryId);
-        }
-        /// <summary>
-        /// 获取出版社
-        /// </summary>
-        /// <param name="categoryId"></param>
-        /// <returns></returns>
-        [HttpGet("press/{categoryId}")]
-        [AllowAnonymous]
-        public async Task<IEnumerable<string>> GetNavigationPressAsync(int categoryId)
-        {
-            return await appHomePageService.GetNavigationPressAsync(categoryId);
-        }
-
-        /// <summary>
-        /// 获取年份数据
+        /// 获取搜索内容
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>
-        [HttpPost("year")]
+        [HttpPost("navigation-search")]
         [AllowAnonymous]
-        public async Task<IEnumerable<NavigationYearResult>> GetNavigationYearResult(NavigationYearRequest request)
+        public async Task<NavigationSearchResult> GetNavigationSearchResultAsync(NavigationSearchRequest request)
         {
-            return await appHomePageService.GetNavigationYearResult(request);
+            return await appHomePageService.GetNavigationSearchResultAsync(request);
         }
     }
 }

+ 16 - 1
gx_api/GxPress/Model/GxPress.Request/Navigation/NavigationRequest.cs

@@ -29,6 +29,21 @@ namespace GxPress.Request.Navigation
         /// </summary>
         /// <value></value>
         public string Sort { get; set; }
+        /// <summary>
+        /// 作者ID
+        /// </summary>
+        /// <value></value>
+        public int TeacherId { get; set; }
+        /// <summary>
+        /// 单位
+        /// </summary>
+        /// <value></value>
+        public string Unit { get; set; }
+        /// <summary>
+        /// 出版社
+        /// </summary>
+        /// <value></value>
+        public string Press { get; set; }
 
     }
     /// <summary>
@@ -116,6 +131,6 @@ namespace GxPress.Request.Navigation
         /// 分类ID
         /// </summary>
         /// <value></value>
-        public int CategoryId{get;set;}
+        public int CategoryId { get; set; }
     }
 }

+ 43 - 3
gx_api/GxPress/Model/GxPress.Result/Navigation/NavigationResult.cs

@@ -279,7 +279,17 @@ namespace GxPress.Result.Navigation
         /// 作者
         /// </summary>
         /// <value></value>
-        public IEnumerable<NavigationSearchTeacherResult> TeacherItem { get; set; }
+        public IEnumerable<NavigationSearchTeacherResult> TeacherItems { get; set; }
+        /// <summary>
+        /// 年份
+        /// </summary>
+        /// <value></value>
+        public IEnumerable<NavigationYearResult> YearItems { get; set; }
+        /// <summary>
+        /// 出版社
+        /// </summary>
+        /// <value></value>
+        public IEnumerable<PressResult> PressItems { get; set; }
     }
     /// <summary>
     /// 老师搜索
@@ -301,12 +311,42 @@ namespace GxPress.Result.Navigation
         /// </summary>
         /// <value></value>
         public int Count { get; set; }
+        /// <summary>
+        /// 是否选中
+        /// </summary>
+        /// <value></value>
+        public bool IsChecked { get; set; }
     }
-
+    /// <summary>
+    /// 年份
+    /// </summary>
     public class NavigationYearResult
     {
+        /// <summary>
+        /// 年
+        /// </summary>
+        /// <value></value>
         public string Year { get; set; }
-
+        /// <summary>
+        /// 数量
+        /// </summary>
+        /// <value></value>
         public int Count { get; set; }
     }
+    /// <summary>
+    /// 出版社
+    /// </summary>
+    public class PressResult
+    {
+        /// <summary>
+        /// 名称
+        /// </summary>
+        /// <value></value>
+        public string PressName { get; set; }
+        /// <summary>
+        /// 是否选中
+        /// </summary>
+        /// <value></value>
+        public bool IsChecked { get; set; }
+    }
 }

+ 83 - 21
gx_api/GxPress/Service/GxPress.Service.Implement/AppHomePage/AppHomePageService.Search.cs

@@ -11,70 +11,132 @@ namespace GxPress.Service.Implement.AppHomePage
     public partial class AppHomePageService
     {
         /// <summary>
+        /// 获取搜索内容
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+
+        public async Task<NavigationSearchResult> GetNavigationSearchResultAsync(NavigationSearchRequest request)
+        {
+            var result = new NavigationSearchResult()
+            {
+                PressItems = await GetNavigationPressAsync(request),
+                TeacherItems = await GetNavigationSearchResultAysnc(request),
+                YearItems = await GetNavigationYearResult(request)
+            };
+            return result;
+        }
+
+        /// <summary>
         /// 获取搜索作者
         /// </summary>
         /// <returns></returns>
-        public async Task<IEnumerable<NavigationSearchTeacherResult>> GetNavigationSearchResultAysnc(int categoryId)
+        public async Task<IEnumerable<NavigationSearchTeacherResult>> GetNavigationSearchResultAysnc(NavigationSearchRequest request)
         {
-            var result = new List<NavigationSearchTeacherResult>();
             var database = new Database(DatabaseType.MySql, Common.Tools.ConfigHelper.GetValue("Database:ConnectionString"));
             var connection = database.GetConnection();
-            var sql = $"SELECT TeacherId,Author,count(1) as Count FROM tede_media where id in(select MediaId from tede_system_lable_media where TypeValue=1) and  Author is not null group by Author,TeacherId";
-            if (categoryId > 0)
-                sql = $"SELECT TeacherId,Author,count(1) as Count FROM tede_media where id in(select MediaId from tede_system_lable_media where TypeValue=1 and lableId={categoryId}) and  Author is not null group by Author,TeacherId";
-            return await connection.QueryAsync<NavigationSearchTeacherResult>(sql);
+            var categorySql = "";
+            if (request.CategoryId > 0)
+                categorySql += $" and lableId={request.CategoryId}";
+            var teacherSql = "";
+            if (request.TeacherId > 0)
+                teacherSql += $" and TeacherId={request.TeacherId}";
+            if (!string.IsNullOrEmpty(request.Press))
+                teacherSql += $" and Press='{request.Press}'";
+            if (!string.IsNullOrEmpty(request.BeginTime) && !string.IsNullOrEmpty(request.EndTime))
+            {
+                if (DateTime.TryParse(request.BeginTime, out var beginTime) && DateTime.TryParse(request.EndTime, out var endTime))
+                    teacherSql += $" and AddDate>='{request.BeginTime}' and AddDate<='{request.EndTime}'";
+            }
+            var sql = $"SELECT TeacherId,Author,count(1) as Count FROM tede_media where id in(select MediaId from tede_system_lable_media where TypeValue=1 {categorySql}) {teacherSql} and  Author is not null group by Author,TeacherId";
+            var reuslt = await connection.QueryAsync<NavigationSearchTeacherResult>(sql);
+            if (request.TeacherId > 0)
+                foreach (var item in reuslt)
+                {
+                    item.IsChecked = item.TeacherId.Equals(request.TeacherId);
+                }
+            return reuslt;
         }
         /// <summary>
         /// 获取出版社
         /// </summary>
         /// <param name="categoryId"></param>
         /// <returns></returns>
-        public async Task<IEnumerable<string>> GetNavigationPressAsync(int categoryId)
+        public async Task<IEnumerable<PressResult>> GetNavigationPressAsync(NavigationSearchRequest request)
         {
-            var sql = "SELECT Press FROM tede_media where id in(select MediaId from tede_system_lable_media where TypeValue=1) and  Press is not null group by Press";
-            if (categoryId > 0)
-                sql = "SELECT Press FROM tede_media where id in(select MediaId from tede_system_lable_media where TypeValue=1 and lableId={categoryId}) and  Press is not null group by Press";
-            var result = new List<NavigationSearchTeacherResult>();
+            var result = new List<PressResult>();
+            var categorySql = "";
+            if (request.CategoryId > 0)
+                categorySql += $" and lableId={request.CategoryId}";
+            var teacherSql = "";
+            if (request.TeacherId > 0)
+                teacherSql += $" and TeacherId={request.TeacherId}";
+            if (!string.IsNullOrEmpty(request.Press))
+                teacherSql += $" and Press='{request.Press}'";
+            if (!string.IsNullOrEmpty(request.BeginTime) && !string.IsNullOrEmpty(request.EndTime))
+            {
+                if (DateTime.TryParse(request.BeginTime, out var beginTime) && DateTime.TryParse(request.EndTime, out var endTime))
+                    teacherSql += $" and AddDate>='{request.BeginTime}' and AddDate<='{request.EndTime}'";
+            }
+            var sql = $"SELECT Press FROM tede_media where id in(select MediaId from tede_system_lable_media where TypeValue=1 {categorySql}) {teacherSql} and  Press is not null group by Press";
+            // if (request.CategoryId > 0)
+            //     sql = "SELECT Press FROM tede_media where id in(select MediaId from tede_system_lable_media where TypeValue=1 and lableId={categoryId}) and  Press is not null group by Press";
             var database = new Database(DatabaseType.MySql, Common.Tools.ConfigHelper.GetValue("Database:ConnectionString"));
             var connection = database.GetConnection();
-            return await connection.QueryAsync<string>(sql);
+            var pressList = await connection.QueryAsync<string>(sql);
+            if (request.Press != null)
+                foreach (var item in pressList)
+                {
+                    result.Add(new PressResult { PressName = item, IsChecked = request.Press.Equals(item) });
+                }
+            return result;
         }
         /// <summary>
         /// 获取年份数据
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>
-        public async Task<IEnumerable<NavigationYearResult>> GetNavigationYearResult(NavigationYearRequest request)
+        public async Task<IEnumerable<NavigationYearResult>> GetNavigationYearResult(NavigationSearchRequest request)
         {
             var result = new List<NavigationYearResult>();
             var database = new Database(DatabaseType.MySql, Common.Tools.ConfigHelper.GetValue("Database:ConnectionString"));
             var connection = database.GetConnection();
-            var str = "";
+            var categorySql = "";
             if (request.CategoryId > 0)
-                str = $" and LableId={request.CategoryId} ";
-            var maxYearSql = $"select max(AddDate) from tede_media where id in( SELECT MediaId FROM ccpph_tede.tede_system_lable_media where typevalue=1 {str})";
+                categorySql += $" and lableId={request.CategoryId}";
+            var teacherSql = "";
+            if (request.TeacherId > 0)
+                teacherSql += $" and TeacherId={request.TeacherId}";
+            if (!string.IsNullOrEmpty(request.Press))
+                teacherSql += $" and Press='{request.Press}'";
+            if (!string.IsNullOrEmpty(request.BeginTime) && !string.IsNullOrEmpty(request.EndTime))
+            {
+                if (DateTime.TryParse(request.BeginTime, out var beginTime) && DateTime.TryParse(request.EndTime, out var endTime))
+                    teacherSql += $" and AddDate>='{request.BeginTime}' and AddDate<='{request.EndTime}'";
+            }
+            var maxYearSql = $"select max(AddDate) from tede_media where id in( SELECT MediaId FROM tede_system_lable_media where typevalue=1 {categorySql}) {teacherSql} ";
             var maxYear = await connection.ExecuteScalarAsync<string>(maxYearSql);
-            var minYearSql = $"select min(AddDate) from tede_media where id in( SELECT MediaId FROM ccpph_tede.tede_system_lable_media where typevalue=1 {str})";
+            var minYearSql = $"select min(AddDate) from tede_media where id in( SELECT MediaId FROM tede_system_lable_media where typevalue=1 {categorySql}) {teacherSql}";
             var minYear = await connection.ExecuteScalarAsync<string>(minYearSql);
             //
             if (DateTime.TryParse(maxYear, out var maxYearDate) && DateTime.TryParse(minYear, out var minYearDate))
             {
                 var count = (maxYearDate.Year - minYearDate.Year);
-                if (count > 0)
+                if (count > 0 && minYearDate.Year > 1)
                 {
 
                     for (int i = 0; i < count; i++)
                     {
-                        var sql = $"select count(1) from tede_media where AddDate>'{minYearDate.Year + i}' and AddDate<'{minYearDate.Year + (i + 1)}' and  id in( SELECT MediaId FROM ccpph_tede.tede_system_lable_media where typevalue=1)";
+                        var sql = $"select count(1) from tede_media where AddDate>'{minYearDate.Year + i}' and AddDate<'{minYearDate.Year + (i + 1)}' and  id in( SELECT MediaId FROM tede_system_lable_media where typevalue=1 {categorySql}) {teacherSql}";
                         var number = await connection.ExecuteScalarAsync<int>(sql);
                         result.Add(new NavigationYearResult() { Year = (minYearDate.Year + i) + "年", Count = number });
                     }
                 }
                 else
                 {
-                    var sql = $"select count(1) from tede_media where AddDate>'{minYearDate.Year}' and AddDate<'{minYearDate.Year + 1}' and  id in( SELECT MediaId FROM ccpph_tede.tede_system_lable_media where typevalue=1)";
+                    var sql = $"select count(1) from tede_media where AddDate>'{maxYearDate.Year}' and AddDate<'{maxYearDate.Year + 1}' and  id in( SELECT MediaId FROM tede_system_lable_media where typevalue=1 {categorySql}) {teacherSql}";
                     var number = await connection.ExecuteScalarAsync<int>(sql);
-                    result.Add(new NavigationYearResult() { Year = (minYearDate.Year) + "年", Count = number });
+                    result.Add(new NavigationYearResult() { Year = (maxYearDate.Year) + "年", Count = number });
                 }
             }
             return result;

+ 12 - 6
gx_api/GxPress/Service/GxPress.Service.Interface/AppHomePage/IAppHomePageService.cs

@@ -58,27 +58,33 @@ namespace GxPress.Service.Interface.AppHomePage
         /// <param name="request"></param>
         /// <returns></returns>
         Task<PagedList<MediaCathedraResult>> GetDayWeBookAsync(MediaDayWeBookRequest request);
-         /// <summary>
+        /// <summary>
         /// 导航内容分页
         /// </summary>
         /// <returns></returns>
         Task<PagedList<MediaCathedraResult>> GetContentNavigationAsync(MediaContentNavigationRequest request);
-         /// <summary>
+        /// <summary>
         /// 获取搜索作者
         /// </summary>
         /// <returns></returns>
-       Task<IEnumerable<NavigationSearchTeacherResult>> GetNavigationSearchResultAysnc(int categoryId);
+        Task<IEnumerable<NavigationSearchTeacherResult>> GetNavigationSearchResultAysnc(NavigationSearchRequest request);
         /// <summary>
         /// 获取出版社
         /// </summary>
         /// <param name="categoryId"></param>
         /// <returns></returns>
-        Task<IEnumerable<string>> GetNavigationPressAsync(int categoryId);
-         /// <summary>
+        Task<IEnumerable<PressResult>> GetNavigationPressAsync(NavigationSearchRequest request);
+        /// <summary>
         /// 获取年份数据
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>
-       Task<IEnumerable<NavigationYearResult>> GetNavigationYearResult(NavigationYearRequest request);
+        Task<IEnumerable<NavigationYearResult>> GetNavigationYearResult(NavigationSearchRequest request);
+        /// <summary>
+        /// 获取搜索内容
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        Task<NavigationSearchResult> GetNavigationSearchResultAsync(NavigationSearchRequest request);
     }
 }