|
@@ -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;
|