李昊 4 年之前
父节点
当前提交
37a8c3ddc8

+ 13 - 0
gx_api/GxPress/Api/GxPress.Api/AppControllers/AppPageController.cs

@@ -17,6 +17,7 @@ using GxPress.Result.Category;
 using GxPress.Repository.Interface.Category;
 using GxPress.Service.Interface.Media;
 using GxPress.Result.Navigation;
+using GxPress.Request.Navigation;
 
 namespace GxPress.Api.AppControllers
 {
@@ -287,5 +288,17 @@ namespace GxPress.Api.AppControllers
         {
             return await appHomePageService.GetNavigationPressAsync(categoryId);
         }
+
+        /// <summary>
+        /// 获取年份数据
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [HttpPost("year")]
+        [AllowAnonymous]
+        public async Task<IEnumerable<NavigationYearResult>> GetNavigationYearResult(NavigationYearRequest request)
+        {
+            return await appHomePageService.GetNavigationYearResult(request);
+        }
     }
 }

+ 20 - 0
gx_api/GxPress/Model/GxPress.Request/Media/MediaRequest.cs

@@ -306,6 +306,26 @@ namespace GxPress.Request.Media
         /// </summary>
         /// <value></value>
         public List<int> MediaIds { get; set; }
+        /// <summary>
+        /// 作者ID
+        /// </summary>
+        /// <value></value>
+        public int AuthorId { get; set; }
+        /// <summary>
+        /// 开始时间
+        /// </summary>
+        /// <value></value>
+        public string BeginTime { get; set; }
+        /// <summary>
+        /// 结束时间
+        /// </summary>
+        /// <value></value>
+        public string EndTime { get; set; }
+        /// <summary>
+        /// 出版社
+        /// </summary>
+        /// <value></value>
+        public string Press { get; set; }
     }
 
     /// <summary>

+ 21 - 0
gx_api/GxPress/Model/GxPress.Request/Navigation/NavigationRequest.cs

@@ -97,4 +97,25 @@ namespace GxPress.Request.Navigation
 
         public string ActionUrl { get; set; }
     }
+    /// <summary>
+    /// 年份搜索
+    /// </summary>
+    public class NavigationYearRequest
+    {
+        /// <summary>
+        /// 开始时间
+        /// </summary>
+        /// <value></value>
+        public string BeginTime { get; set; }
+        /// <summary>
+        /// 结束时间
+        /// </summary>
+        /// <value></value>
+        public string EndTime { get; set; }
+        /// <summary>
+        /// 分类ID
+        /// </summary>
+        /// <value></value>
+        public int CategoryId{get;set;}
+    }
 }

+ 7 - 0
gx_api/GxPress/Model/GxPress.Result/Navigation/NavigationResult.cs

@@ -302,4 +302,11 @@ namespace GxPress.Result.Navigation
         /// <value></value>
         public int Count { get; set; }
     }
+
+    public class NavigationYearResult
+    {
+        public string Year { get; set; }
+
+        public int Count { get; set; }
+    }
 }

+ 33 - 2
gx_api/GxPress/Repository/GxPress.Repository.Implement/Media/MediaRepository.cs

@@ -791,11 +791,42 @@ namespace GxPress.Repository.Implement.Media
             query.Where(nameof(Entity.tede2.Media.Media.MediaType), GxPress.EnumConst.AllTypeConst.Book.GetHashCode());
             if (request.MediaIds.Count() > 0)
                 query.WhereIn(nameof(Entity.tede2.Media.Media.Id), request.MediaIds);
+            if (request.AuthorId > 0)
+                query.Where(nameof(Entity.tede2.Media.Media.TeacherId), request.AuthorId);
             resut.Total = await _repository.CountAsync(query);
+            if (!string.IsNullOrEmpty(request.BeginTime) && !string.IsNullOrEmpty(request.EndTime))
+            {
+                query.Where(nameof(Entity.tede2.Media.Media.AddDate), ">=", request.BeginTime);
+                query.Where(nameof(Entity.tede2.Media.Media.AddDate), "<=", request.EndTime);
+            }
+            if (!string.IsNullOrEmpty(request.Press))
+            {
+                query.Where(nameof(Entity.tede2.Media.Media.Press), request.Press);
+            }
             if (!string.IsNullOrEmpty(request.Sort))
             {
-                query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsTop));
-                query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsRecommend));
+                if (request.Sort.Equals("0"))
+                {
+                    query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsTop));
+                    query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsRecommend));
+                }
+                if (request.Sort.Equals("1"))
+                {
+                    query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsTop));
+                    query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsRecommend));
+                }
+                if (request.Sort.Equals("2"))
+                {
+                    query.OrderByDesc(nameof(Entity.tede2.Media.Media.ReadCount));
+                }
+                if (request.Sort.Equals("3"))
+                {
+                    query.OrderByDesc(nameof(Entity.tede2.Media.Media.AddDate));
+                }
+                if (request.Sort.Equals("4"))
+                {
+                    query.OrderBy(nameof(Entity.tede2.Media.Media.AddDate));
+                }
             }
             else
                 query.OrderByDesc(nameof(Entity.tede2.Media.Media.CreatedDate));

+ 42 - 0
gx_api/GxPress/Service/GxPress.Service.Implement/AppHomePage/AppHomePageService.Search.cs

@@ -1,7 +1,9 @@
+using System;
 using System.Collections.Generic;
 using System.Threading.Tasks;
 using Dapper;
 using Datory;
+using GxPress.Request.Navigation;
 using GxPress.Result.Navigation;
 
 namespace GxPress.Service.Implement.AppHomePage
@@ -37,5 +39,45 @@ namespace GxPress.Service.Implement.AppHomePage
             var connection = database.GetConnection();
             return await connection.QueryAsync<string>(sql);
         }
+        /// <summary>
+        /// 获取年份数据
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        public async Task<IEnumerable<NavigationYearResult>> GetNavigationYearResult(NavigationYearRequest request)
+        {
+            var result = new List<NavigationYearResult>();
+            var database = new Database(DatabaseType.MySql, Common.Tools.ConfigHelper.GetValue("Database:ConnectionString"));
+            var connection = database.GetConnection();
+            var str = "";
+            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})";
+            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 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)
+                {
+
+                    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 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 number = await connection.ExecuteScalarAsync<int>(sql);
+                    result.Add(new NavigationYearResult() { Year = (minYearDate.Year) + "年", Count = number });
+                }
+            }
+            return result;
+        }
     }
 }

+ 7 - 0
gx_api/GxPress/Service/GxPress.Service.Interface/AppHomePage/IAppHomePageService.cs

@@ -3,6 +3,7 @@ using System.Threading.Tasks;
 using GxPress.Common.Page;
 using GxPress.Request.ArticleGroup;
 using GxPress.Request.Media;
+using GxPress.Request.Navigation;
 using GxPress.Request.TeacherRequest;
 using GxPress.Result.Media;
 using GxPress.Result.Navigation;
@@ -73,5 +74,11 @@ namespace GxPress.Service.Interface.AppHomePage
         /// <param name="categoryId"></param>
         /// <returns></returns>
         Task<IEnumerable<string>> GetNavigationPressAsync(int categoryId);
+         /// <summary>
+        /// 获取年份数据
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+       Task<IEnumerable<NavigationYearResult>> GetNavigationYearResult(NavigationYearRequest request);
     }
 }