MediaRepository.cs 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975
  1. using System.Linq;
  2. using System.Collections.Generic;
  3. using System.Threading.Tasks;
  4. using AutoMapper;
  5. using Datory;
  6. using GxPress.Common.AppOptions;
  7. using GxPress.Common.Tools;
  8. using GxPress.Repository.Interface.Media;
  9. using GxPress.Result.Media;
  10. using Microsoft.Extensions.Options;
  11. using System.Transactions;
  12. using GxPress.Common.Exceptions;
  13. using GxPress.Common.Page;
  14. using GxPress.Request.Media;
  15. using System;
  16. using GxPress.EnumConst;
  17. using GxPress.Request.ArticleGroup;
  18. using Dapper;
  19. using GxPress.Request.AppChannel;
  20. using GxPress.Result.AppChannel;
  21. namespace GxPress.Repository.Implement.Media
  22. {
  23. public class MediaRepository : IMediaRepository
  24. {
  25. private readonly Repository<Entity.tede2.Media.Media> _repository;
  26. private readonly Repository<Entity.tede2.Media.MediaLibrary> mediaLibraryRepository;
  27. private readonly Repository<Entity.tede2.Media.MediaLable> mediaLableRepository;
  28. private readonly IMapper _mapper;
  29. private readonly string _connectionString;
  30. private readonly string _databaseTypestr;
  31. public MediaRepository(IOptionsMonitor<DatabaseOptions> dbOptionsAccessor, IMapper mapper)
  32. {
  33. _databaseTypestr = dbOptionsAccessor.CurrentValue.DatabaseType;
  34. _connectionString = dbOptionsAccessor.CurrentValue.ConnectionString;
  35. var databaseType =
  36. StringUtils.ToEnum<DatabaseType>(dbOptionsAccessor.CurrentValue.DatabaseType, DatabaseType.MySql);
  37. var database = new Database(databaseType, dbOptionsAccessor.CurrentValue.ConnectionString);
  38. _repository = new Repository<Entity.tede2.Media.Media>(database);
  39. mediaLibraryRepository = new Repository<Entity.tede2.Media.MediaLibrary>(database);
  40. mediaLableRepository = new Repository<Entity.tede2.Media.MediaLable>(database);
  41. _mapper = mapper;
  42. }
  43. public IDatabase Database => _repository.Database;
  44. public string TableName => _repository.TableName;
  45. public List<TableColumn> TableColumns => _repository.TableColumns;
  46. public async Task<MediaResult> GetAsync(int id)
  47. {
  48. var result = new MediaResult();
  49. //获取媒体
  50. var media = await _repository.GetAsync(id);
  51. result = _mapper.Map<MediaResult>(media);
  52. result.ImageUrls = StringUtils.AddDomain(result.ImageUrls);
  53. result.CategoryId = StringUtils.StringCollectionToStringList(media.CategoryId).ToList();
  54. result.CategoryName = StringUtils.StringCollectionToStringList(media.CategoryName).ToList();
  55. result.FullCategoryId = StringUtils.StringCollectionToStringList(media.FullCategoryId).ToList();
  56. //获取媒体库资源
  57. var mediaLibrarys = await mediaLibraryRepository.GetAllAsync(Q.Where(nameof(Entity.tede2.Media.MediaLibrary.MediaId), id));
  58. result.MediaLibraryResults = mediaLibrarys.ToList().Select(n => _mapper.Map<MediaLibraryResult>(n)).ToList();
  59. foreach (var item in result.MediaLibraryResults)
  60. {
  61. item.FileUrl = StringUtils.AddDomain(item.FileUrl);
  62. }
  63. //获取媒体标签
  64. var mediaLables = await mediaLableRepository.GetAllAsync(Q.Where(nameof(Entity.tede2.Media.MediaLable.MediaId), id));
  65. result.MediaLableResults = mediaLables.Select(n => _mapper.Map<MediaLableResult>(n)).ToList();
  66. return result;
  67. }
  68. /// <summary>
  69. /// 删除媒体
  70. /// </summary>
  71. /// <param name="id"></param>
  72. /// <returns></returns>
  73. public async Task<bool> DeleteAsync(int id)
  74. {
  75. try
  76. {
  77. using (var transactionScope = new TransactionScope())
  78. {
  79. // //删除媒体库
  80. // await mediaLibraryRepository.DeleteAsync(Q.Where(nameof(Entity.tede2.Media.MediaLibrary.MediaId), id));
  81. // //删除媒体标签
  82. // await mediaLableRepository.DeleteAsync(Q.Where(nameof(Entity.tede2.Media.MediaLable.MediaId), id));
  83. await _repository.UpdateAsync(Q.Where(nameof(Entity.tede2.Media.Media.Id), id).Set(nameof(Entity.tede2.Media.Media.IsDelete), true));
  84. transactionScope.Complete();
  85. }
  86. }
  87. catch (System.Exception ex)
  88. {
  89. throw new BusinessException(ex.Message);
  90. }
  91. return true;
  92. }
  93. /// <summary>
  94. /// 添加媒体
  95. /// </summary>
  96. /// <param name="result"></param>
  97. /// <returns></returns>
  98. public async Task<bool> InsertAsync(MediaResult result)
  99. {
  100. var model = _mapper.Map<Entity.tede2.Media.Media>(result);
  101. model.ImageUrls = StringUtils.RemoveDomain(result.ImageUrls);
  102. try
  103. {
  104. using (var transactionScope = new TransactionScope())
  105. {
  106. model.AutoNumber = SnowflakeHelper.MakeSnowflake();
  107. var categoryId = "";
  108. foreach (var item in result.CategoryId)
  109. {
  110. categoryId += item.Split(",")[item.Split(",").Length - 1] + ",";
  111. }
  112. categoryId = categoryId.Remove(categoryId.Length - 1, 1);
  113. model.CategoryId = categoryId;
  114. model.FullCategoryId = StringUtils.ObjectCollectionToString(result.CategoryId);
  115. var categoryName = "";
  116. foreach (var item in result.CategoryName)
  117. {
  118. categoryName += item.Split(",")[item.Split(",").Length - 1] + ",";
  119. }
  120. categoryName = categoryName.Remove(categoryName.Length - 1, 1);
  121. model.CategoryName = categoryName;
  122. model.IsLibrary = result.MediaLibraryResults.Count > 0;
  123. var id = await _repository.InsertAsync(model);
  124. if (id > 0)
  125. {
  126. foreach (var item in result.MediaLibraryResults)
  127. {
  128. var mediaLibrary = _mapper.Map<Entity.tede2.Media.MediaLibrary>(item);
  129. mediaLibrary.MediaId = id;
  130. mediaLibrary.FileUrl = StringUtils.RemoveDomain(item.FileUrl);
  131. await mediaLibraryRepository.InsertAsync(mediaLibrary);
  132. }
  133. }
  134. //添加标签
  135. foreach (var item in result.MediaLableResults)
  136. {
  137. var mediaLable = _mapper.Map<Entity.tede2.Media.MediaLable>(item);
  138. mediaLable.MediaId = id;
  139. await mediaLableRepository.InsertAsync(mediaLable);
  140. }
  141. if (result.Id == 0 && result.TeacherId == 0 && !string.IsNullOrEmpty(result.Author))
  142. {
  143. //新增名师
  144. }
  145. //提交事务
  146. transactionScope.Complete();
  147. }
  148. }
  149. catch (System.Exception ex)
  150. {
  151. throw new Common.Exceptions.BusinessException(ex.Message);
  152. }
  153. return true;
  154. }
  155. /// <summary>
  156. /// 获取媒体
  157. /// </summary>
  158. /// <param name="query"></param>
  159. /// <returns></returns>
  160. public async Task<MediaNoteResult> GetAsync(SqlKata.Query query)
  161. {
  162. query.Select(nameof(Entity.tede2.Media.Media.Id));
  163. query.Select(nameof(Entity.tede2.Media.Media.Title));
  164. query.Select(nameof(Entity.tede2.Media.Media.Author));
  165. query.Select(nameof(Entity.tede2.Media.Media.ImageUrls));
  166. return await _repository.GetAsync<MediaNoteResult>(query);
  167. }
  168. public async Task<bool> UpdateAsync(Entity.tede2.Media.Media note)
  169. {
  170. return await _repository.UpdateAsync(note);
  171. }
  172. public async Task<bool> UpdateAsync(SqlKata.Query query)
  173. {
  174. return await _repository.UpdateAsync(query) > 0;
  175. }
  176. /// <summary>
  177. /// 查询
  178. /// </summary>
  179. /// <param name="request"></param>
  180. /// <returns></returns>
  181. public async Task<PagedList<Entity.tede2.Media.Media>> GetAllAsync(MediaSearchRequest request)
  182. {
  183. var result = new PagedList<Entity.tede2.Media.Media>();
  184. var query = Q.NewQuery();
  185. if (!string.IsNullOrEmpty(request.KeyWord))
  186. {
  187. query.OrWhereLike(nameof(Entity.tede2.Media.Media.Title), $"%{request.KeyWord}%");
  188. query.OrWhereLike(nameof(Entity.tede2.Media.Media.Creator), $"%{request.KeyWord}%");
  189. }
  190. if (request.IsDelete > 0)
  191. query.Where(nameof(Entity.tede2.Media.Media.IsDelete), request.IsDelete == 1);
  192. if (request.MediaType > 0)
  193. query.Where(nameof(Entity.tede2.Media.Media.MediaType), request.MediaType);
  194. if (request.LibraryType > 0)
  195. query.Where(nameof(Entity.tede2.Media.Media.IsLibrary), request.LibraryType == 1);
  196. if (!string.IsNullOrEmpty(request.BeginTime) && !string.IsNullOrEmpty(request.EndTime))
  197. {
  198. if (DateTime.TryParse(request.BeginTime, out var beginTime) && DateTime.TryParse(request.EndTime, out var endTime))
  199. {
  200. query.WhereDate(nameof(Entity.tede2.Media.Media.CreatedDate), ">=", beginTime);
  201. query.WhereDate(nameof(Entity.tede2.Media.Media.CreatedDate), "<=", endTime);
  202. }
  203. }
  204. if (request.IsChecked > 0)
  205. query.Where(nameof(Entity.tede2.Media.Media.IsChecked), request.IsChecked == 1);
  206. result.Total = await _repository.CountAsync(query);
  207. //排序
  208. if (string.IsNullOrEmpty(request.Sort))
  209. query.OrderByDesc(nameof(Entity.tede2.Media.Media.CreatedDate));
  210. else if (request.Sort.Equals("SellAmount"))
  211. query.OrderByDesc(nameof(Entity.tede2.Media.Media.SellAmount));
  212. else if (request.Sort.Equals("ReadCount"))
  213. query.OrderByDesc(nameof(Entity.tede2.Media.Media.ReadCount));
  214. var item = await _repository.GetAllAsync(query.ForPage(request.Page, request.PerPage));
  215. result.Items = item;
  216. return result;
  217. }
  218. /// <summary>
  219. /// 根据IDs
  220. /// </summary>
  221. /// <returns></returns>
  222. public async Task<IEnumerable<MediaCathedraResult>> GetMediaByLableIdsAsync(MediaIdsRequest request)
  223. {
  224. if (request.Ids.Count > 0)
  225. {
  226. var str = "";
  227. foreach (var item in request.Ids)
  228. str += item + ",";
  229. str = str.Remove(str.Length - 1, 1);
  230. var sql = $@"SELECT
  231. Id,ImageUrls,Title,Author,MediaType,ReadCount,CreatedDate
  232. FROM
  233. tede_media
  234. WHERE
  235. id IN ({str})
  236. ORDER BY RAND() LIMIT {request.Limit}";
  237. var databaseType = _databaseTypestr.ToEnum<DatabaseType>(DatabaseType.MySql);
  238. var database = new Database(databaseType, _connectionString);
  239. var connection = database.GetConnection();
  240. var result = await connection.QueryAsync<MediaCathedraResult>(sql);
  241. foreach (var item in result)
  242. {
  243. item.ImageUrls = StringUtils.AddDomain(item.ImageUrls);
  244. }
  245. return result;
  246. }
  247. return null;
  248. }
  249. /// <summary>
  250. /// 根据IDs
  251. /// </summary>
  252. /// <returns></returns>
  253. public async Task<PagedList<MediaCathedraResult>> GetMediaByLableIdAsync(MediaLableIdRequest request)
  254. {
  255. var result = new PagedList<MediaCathedraResult>();
  256. if (request.Ids.Count > 0)
  257. {
  258. var str = "";
  259. foreach (var item in request.Ids)
  260. str += item + ",";
  261. str = str.Remove(str.Length - 1, 1);
  262. var sql = $@"SELECT
  263. Id,ImageUrls,Title,Author,MediaType,ReadCount,CreatedDate
  264. FROM
  265. tede_media
  266. WHERE
  267. id IN ({str})
  268. ORDER BY CreatedDate desc LIMIT {(request.Page - 1) * request.PerPage},{request.PerPage}";
  269. var databaseType = _databaseTypestr.ToEnum<DatabaseType>(DatabaseType.MySql);
  270. var database = new Database(databaseType, _connectionString);
  271. var connection = database.GetConnection();
  272. result.Items = await connection.QueryAsync<MediaCathedraResult>(sql);
  273. sql = $@"SELECT count(1) FROM tede_media WHERE id IN ({str})";
  274. result.Total = await connection.ExecuteScalarAsync<int>(sql);
  275. }
  276. foreach (var item in result.Items)
  277. {
  278. item.ImageUrls = StringUtils.AddDomain(item.ImageUrls);
  279. }
  280. return result;
  281. }
  282. public async Task<bool> UpdateAsync(MediaResult result)
  283. {
  284. //var model = _mapper.Map<Entity.tede2.Media.Media>(result);
  285. try
  286. {
  287. using (var transactionScope = new TransactionScope())
  288. {
  289. var model = await _repository.GetAsync(result.Id);
  290. if (result.CategoryId != null && result.CategoryId.Count > 0)
  291. {
  292. var categoryId = "";
  293. foreach (var item in result.CategoryId)
  294. categoryId += item.Split(",")[item.Split(",").Length - 1] + ",";
  295. categoryId = categoryId.Remove(categoryId.Length - 1, 1);
  296. model.CategoryId = categoryId;
  297. model.FullCategoryId = StringUtils.ObjectCollectionToString(result.CategoryId);
  298. }
  299. if (result.CategoryName != null && result.CategoryName.Count > 0)
  300. {
  301. var categoryName = "";
  302. foreach (var item in result.CategoryName)
  303. categoryName += item.Split(",")[item.Split(",").Length - 1] + ",";
  304. categoryName = categoryName.Remove(categoryName.Length - 1, 1);
  305. model.CategoryName = categoryName;
  306. }
  307. if (result.AdminId > 0)
  308. model.AdminId = result.AdminId;
  309. if (!string.IsNullOrEmpty(result.Creator))
  310. model.Creator = result.Creator;
  311. if (result.MediaType > 0)
  312. model.MediaType = result.MediaType;
  313. if (!string.IsNullOrEmpty(result.Title))
  314. model.Title = result.Title;
  315. if (!string.IsNullOrEmpty(result.ImageUrls))
  316. model.ImageUrls = result.ImageUrls;
  317. if (!string.IsNullOrEmpty(result.Summary))
  318. model.Summary = result.Summary;
  319. if (!string.IsNullOrEmpty(result.Author))
  320. model.Author = result.Author;
  321. if (result.TeacherId > 0)
  322. model.TeacherId = result.TeacherId;
  323. if (!string.IsNullOrEmpty(result.Source))
  324. model.Source = result.Source;
  325. if (!string.IsNullOrEmpty(result.Blocks))
  326. model.Blocks = result.Blocks;
  327. if (result.IsChecked > 0)
  328. model.IsChecked = result.IsChecked == 1;
  329. if (!string.IsNullOrEmpty(result.AddDate))
  330. model.AddDate = Convert.ToDateTime(result.AddDate);
  331. if (model.Sort > 0)
  332. model.Sort = result.Sort;
  333. if (model.ReadCount > 0)
  334. model.ReadCount = result.ReadCount;
  335. if (result.IsTop > 0)
  336. model.IsTop = result.IsTop == 1;
  337. if (result.LableId > 0)
  338. model.LableId = result.LableId;
  339. if (result.IsRecommend > 0)
  340. model.IsRecommend = result.IsRecommend == 1;
  341. if (!string.IsNullOrEmpty(result.Press))
  342. model.Press = result.Press;
  343. if (!string.IsNullOrEmpty(result.PublishTime))
  344. model.PublishTime = result.PublishTime;
  345. if (result.IosDiscountPrice > 0)
  346. model.IosDiscountPrice = result.IosDiscountPrice;
  347. if (result.IosPrice > 0)
  348. model.IosPrice = result.IosPrice;
  349. if (result.OtherDiscountPrice > 0)
  350. model.OtherDiscountPrice = result.OtherDiscountPrice;
  351. if (result.OtherPrice > 0)
  352. model.OtherPrice = result.OtherPrice;
  353. if (result.FreeProportion > 0)
  354. model.FreeProportion = result.FreeProportion;
  355. if (result.AttachType > 0)
  356. model.AttachType = result.AttachType;
  357. if (result.AttachId > 0)
  358. model.AttachId = result.AttachId;
  359. if (result.MediaId > 0)
  360. model.MediaId = result.MediaId;
  361. if (!string.IsNullOrEmpty(result.MediaTitle))
  362. model.MediaTitle = result.MediaTitle;
  363. if (!string.IsNullOrEmpty(result.JournalsYear))
  364. model.JournalsYear = result.JournalsYear;
  365. if (result.JournalsCategory > 0)
  366. model.JournalsCategory = result.JournalsCategory;
  367. if (result.IsExercises > 0)
  368. model.IsExercises = result.IsExercises == 1;
  369. if (result.AppCategoryId > 0)
  370. model.AppCategoryId = result.AppCategoryId;
  371. await _repository.UpdateAsync(model);
  372. if (result.MediaLibraryResults != null && result.MediaLibraryResults.Count > 0)
  373. {
  374. model.IsLibrary = result.MediaLibraryResults.Count > 0;
  375. //删除媒体库
  376. await mediaLibraryRepository.DeleteAsync(Q.Where(nameof(Entity.tede2.Media.MediaLibrary.MediaId), result.Id));
  377. foreach (var item in result.MediaLibraryResults)
  378. {
  379. var mediaLibrary = _mapper.Map<Entity.tede2.Media.MediaLibrary>(item);
  380. mediaLibrary.MediaId = result.Id;
  381. mediaLibrary.FileUrl = StringUtils.RemoveDomain(mediaLibrary.FileUrl);
  382. await mediaLibraryRepository.InsertAsync(mediaLibrary);
  383. }
  384. }
  385. if (result.MediaLableResults != null && result.MediaLableResults.Count > 0)
  386. {
  387. //删除媒体标签
  388. await mediaLableRepository.DeleteAsync(Q.Where(nameof(Entity.tede2.Media.MediaLable.MediaId), result.Id));
  389. //添加标签
  390. foreach (var item in result.MediaLableResults)
  391. {
  392. var mediaLable = _mapper.Map<Entity.tede2.Media.MediaLable>(item);
  393. mediaLable.MediaId = result.Id;
  394. await mediaLableRepository.InsertAsync(mediaLable);
  395. }
  396. }
  397. //提交事务
  398. transactionScope.Complete();
  399. }
  400. }
  401. catch (System.Exception ex)
  402. {
  403. throw new Common.Exceptions.BusinessException(ex.Message);
  404. }
  405. return true;
  406. }
  407. public async Task<int> CountAsync(string beginTime, string endTime)
  408. {
  409. return await _repository.CountAsync(Q.WhereDate(nameof(Entity.tede2.Media.Media.CreatedDate), ">=", beginTime).WhereDate(nameof(Entity.tede2.Media.Media.CreatedDate), "<=", endTime));
  410. }
  411. public async Task<int> CountAsync(SqlKata.Query query)
  412. {
  413. return await _repository.CountAsync(query);
  414. }
  415. public async Task<Entity.tede2.Media.Media> GetAsync(string autoNumber)
  416. {
  417. return await _repository.GetAsync(Q.Where(nameof(Entity.tede2.Media.Media.AutoNumber), autoNumber));
  418. }
  419. /// <summary>
  420. /// 获取书籍
  421. /// </summary>
  422. /// <param name="mediaId"></param>
  423. /// <returns></returns>
  424. public async Task<BookMediaResult> GetBookMediaResultAsync(int mediaId)
  425. {
  426. var result = await _repository.GetAsync(Q.Where(nameof(Entity.tede2.Media.Media.Id), mediaId).Where(nameof(Entity.tede2.Media.Media.IsChecked), true).Where(nameof(Entity.tede2.Media.Media.IsDelete), false));
  427. return _mapper.Map<BookMediaResult>(result);
  428. }
  429. /// <summary>
  430. /// 获取视频
  431. /// </summary>
  432. /// <param name="mediaId"></param>
  433. /// <returns></returns>
  434. public async Task<VideoMediaResult> GetVideoMediaResultAsync(int mediaId)
  435. {
  436. var result = await _repository.GetAsync(Q.Where(nameof(Entity.tede2.Media.Media.Id), mediaId).Where(nameof(Entity.tede2.Media.Media.IsChecked), true).Where(nameof(Entity.tede2.Media.Media.IsDelete), false));
  437. return _mapper.Map<VideoMediaResult>(result);
  438. }
  439. /// <summary>
  440. /// 根据
  441. /// </summary>
  442. /// <param name="mediaIds"></param>
  443. /// <returns></returns>
  444. public async Task<IEnumerable<NavigationMediaResult>> GetNavigationMediaResults(IEnumerable<int> mediaIds, int page = 1, int pageSize = 10)
  445. {
  446. //获取媒体
  447. var query = Q.NewQuery();
  448. query.Select(nameof(Entity.tede2.Media.Media.Id));
  449. query.Select(nameof(Entity.tede2.Media.Media.ImageUrls));
  450. query.Select(nameof(Entity.tede2.Media.Media.Title));
  451. query.Select(nameof(Entity.tede2.Media.Media.Summary));
  452. query.Select(nameof(Entity.tede2.Media.Media.TeacherId));
  453. query.Select(nameof(Entity.tede2.Media.Media.AutoNumber));
  454. query.Select(nameof(Entity.tede2.Media.Media.Author));
  455. query.Select(nameof(Entity.tede2.Media.Media.MediaType));
  456. query.Select(nameof(Entity.tede2.Media.Media.ReadCount));
  457. query.Select(nameof(Entity.tede2.Media.Media.CreatedDate));
  458. query.Select(nameof(Entity.tede2.Media.Media.CollectCount));
  459. query.WhereIn(nameof(Entity.tede2.Media.Media.Id), mediaIds);
  460. query.Where(nameof(Entity.tede2.Media.Media.IsChecked), true);
  461. query.Where(nameof(Entity.tede2.Media.Media.IsDelete), false);
  462. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsTop));
  463. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsRecommend));
  464. query.OrderByDesc(nameof(Entity.tede2.Media.Media.LastModifiedDate));
  465. query.ForPage(page, pageSize);
  466. return await _repository.GetAllAsync<NavigationMediaResult>(query);
  467. }
  468. /// <summary>
  469. /// 猜你喜欢
  470. /// </summary>
  471. /// <param name="mediaIds"></param>
  472. /// <returns></returns>
  473. public async Task<IEnumerable<NavigationMediaResult>> GetlikeMediaResults()
  474. {
  475. //获取媒体
  476. var query = Q.NewQuery();
  477. query.Select(nameof(Entity.tede2.Media.Media.Id));
  478. query.Select(nameof(Entity.tede2.Media.Media.ImageUrls));
  479. query.Select(nameof(Entity.tede2.Media.Media.Title));
  480. query.Select(nameof(Entity.tede2.Media.Media.Summary));
  481. query.Select(nameof(Entity.tede2.Media.Media.TeacherId));
  482. query.Select(nameof(Entity.tede2.Media.Media.AutoNumber));
  483. query.Select(nameof(Entity.tede2.Media.Media.Author));
  484. query.Select(nameof(Entity.tede2.Media.Media.MediaType));
  485. query.Where(nameof(Entity.tede2.Media.Media.IsTop), true);
  486. query.Where(nameof(Entity.tede2.Media.Media.IsChecked), true);
  487. query.Where(nameof(Entity.tede2.Media.Media.IsDelete), false);
  488. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsTop));
  489. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsRecommend));
  490. query.ForPage(1, 10);
  491. return await _repository.GetAllAsync<NavigationMediaResult>(query);
  492. }
  493. /// <summary>
  494. /// 推荐
  495. /// </summary>
  496. /// <param name="mediaIds"></param>
  497. /// <returns></returns>
  498. public async Task<IEnumerable<NavigationMediaResult>> GetRecommendMediaResults()
  499. {
  500. //获取媒体
  501. var query = Q.NewQuery();
  502. query.Select(nameof(Entity.tede2.Media.Media.Id));
  503. query.Select(nameof(Entity.tede2.Media.Media.ImageUrls));
  504. query.Select(nameof(Entity.tede2.Media.Media.Title));
  505. query.Select(nameof(Entity.tede2.Media.Media.Summary));
  506. query.Select(nameof(Entity.tede2.Media.Media.TeacherId));
  507. query.Select(nameof(Entity.tede2.Media.Media.AutoNumber));
  508. query.Select(nameof(Entity.tede2.Media.Media.Author));
  509. query.Select(nameof(Entity.tede2.Media.Media.MediaType));
  510. query.Where(nameof(Entity.tede2.Media.Media.IsRecommend), true);
  511. query.Where(nameof(Entity.tede2.Media.Media.IsChecked), true);
  512. query.Where(nameof(Entity.tede2.Media.Media.IsDelete), false);
  513. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsTop));
  514. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsRecommend));
  515. query.ForPage(1, 10);
  516. return await _repository.GetAllAsync<NavigationMediaResult>(query);
  517. }
  518. /// <summary>
  519. /// 排行榜
  520. /// </summary>
  521. /// <param name="request"></param>
  522. /// <returns></returns>
  523. public async Task<IEnumerable<RankingListResult>> GetRankingListResults(RankingListRequest request)
  524. {
  525. //获取媒体
  526. var query = Q.NewQuery();
  527. query.Select(nameof(Entity.tede2.Media.Media.Id));
  528. query.Select(nameof(Entity.tede2.Media.Media.ImageUrls));
  529. query.Select(nameof(Entity.tede2.Media.Media.Title));
  530. query.Select(nameof(Entity.tede2.Media.Media.Summary));
  531. query.Select(nameof(Entity.tede2.Media.Media.TeacherId));
  532. query.Select(nameof(Entity.tede2.Media.Media.AutoNumber));
  533. query.Select(nameof(Entity.tede2.Media.Media.Author));
  534. query.Select(nameof(Entity.tede2.Media.Media.MediaType));
  535. query.Select(nameof(Entity.tede2.Media.Media.CommentScore));
  536. query.Select(nameof(Entity.tede2.Media.Media.CreatedDate));
  537. query.Select(nameof(Entity.tede2.Media.Media.ReadCount));
  538. //1 热搜 2热书榜 3 课程榜 4Top 100 新书 5文献头条 6试听榜 7大众热评 8Top 100 专著
  539. if (request.DataTypeValue > 0)
  540. {
  541. //1 热搜
  542. if (request.DataTypeValue == RankingListConst.HotSearch.GetHashCode())
  543. query.OrderByDesc(nameof(Entity.tede2.Media.Media.ReadCount));
  544. //2热书榜
  545. if (request.DataTypeValue == RankingListConst.ReadBook.GetHashCode())
  546. {
  547. query.Where(nameof(Entity.tede2.Media.Media.MediaType), ResourceTypeConst.Book.GetHashCode());
  548. query.OrderByDesc(nameof(Entity.tede2.Media.Media.ReadCount));
  549. }
  550. //3 课程榜
  551. if (request.DataTypeValue == RankingListConst.Article.GetHashCode())
  552. {
  553. query.Where(nameof(Entity.tede2.Media.Media.MediaType), ResourceTypeConst.Article.GetHashCode());
  554. query.OrderByDesc(nameof(Entity.tede2.Media.Media.ReadCount));
  555. }
  556. //Top 100 新书
  557. if (request.DataTypeValue == RankingListConst.NewBook.GetHashCode())
  558. {
  559. query.Where(nameof(Entity.tede2.Media.Media.MediaType), ResourceTypeConst.Book.GetHashCode());
  560. query.OrderByDesc(nameof(Entity.tede2.Media.Media.CreatedDate));
  561. }
  562. //文献头条
  563. if (request.DataTypeValue == RankingListConst.ArticleTop.GetHashCode())
  564. {
  565. query.Where(nameof(Entity.tede2.Media.Media.MediaType), ResourceTypeConst.Article.GetHashCode());
  566. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsTop));
  567. }
  568. if (request.DataTypeValue == RankingListConst.Audio.GetHashCode())
  569. {
  570. query.Where(nameof(Entity.tede2.Media.Media.MediaType), ResourceTypeConst.Audio.GetHashCode());
  571. query.OrderByDesc(nameof(Entity.tede2.Media.Media.ReadCount));
  572. }
  573. if (request.DataTypeValue == RankingListConst.HotComment.GetHashCode())
  574. query.OrderByDesc(nameof(Entity.tede2.Media.Media.CommentScore));
  575. if (request.DataTypeValue == RankingListConst.CollectionBook.GetHashCode())
  576. query.OrderByDesc(nameof(Entity.tede2.Media.Media.CollectCount));
  577. }
  578. query.Where(nameof(Entity.tede2.Media.Media.IsChecked), true);
  579. query.Where(nameof(Entity.tede2.Media.Media.IsDelete), false);
  580. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsTop));
  581. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsRecommend));
  582. query.ForPage(request.Page, request.PerPage);
  583. var result = await _repository.GetAllAsync<RankingListResult>(query);
  584. foreach (var item in result)
  585. item.ImageUrls = StringUtils.AddDomain(item.ImageUrls);
  586. return result;
  587. }
  588. /// <summary>
  589. /// 排行榜分页
  590. /// </summary>
  591. /// <param name="request"></param>
  592. /// <returns></returns>
  593. public async Task<PagedList<RankingListResult>> GetRankingPageListResults(RankingListRequest request)
  594. {
  595. var result = new PagedList<RankingListResult>();
  596. //获取媒体
  597. var query = Q.NewQuery();
  598. query.Select(nameof(Entity.tede2.Media.Media.Id));
  599. query.Select(nameof(Entity.tede2.Media.Media.ImageUrls));
  600. query.Select(nameof(Entity.tede2.Media.Media.Title));
  601. query.Select(nameof(Entity.tede2.Media.Media.Summary));
  602. query.Select(nameof(Entity.tede2.Media.Media.TeacherId));
  603. query.Select(nameof(Entity.tede2.Media.Media.AutoNumber));
  604. query.Select(nameof(Entity.tede2.Media.Media.Author));
  605. query.Select(nameof(Entity.tede2.Media.Media.MediaType));
  606. query.Select(nameof(Entity.tede2.Media.Media.CommentScore));
  607. query.Select(nameof(Entity.tede2.Media.Media.CreatedDate));
  608. query.Select(nameof(Entity.tede2.Media.Media.ReadCount));
  609. if (!string.IsNullOrEmpty(request.KeyWord))
  610. query.WhereLike(nameof(Entity.tede2.Media.Media.Title), $"%{request.KeyWord}%");
  611. //1 热搜 2热书榜 3 课程榜 4Top 100 新书 5文献头条 6试听榜 7大众热评 8Top 100 专著
  612. if (request.DataTypeValue > 0)
  613. {
  614. //1 热搜
  615. if (request.DataTypeValue == RankingListConst.HotSearch.GetHashCode())
  616. query.OrderByDesc(nameof(Entity.tede2.Media.Media.ReadCount));
  617. //2热书榜
  618. if (request.DataTypeValue == RankingListConst.ReadBook.GetHashCode())
  619. {
  620. query.Where(nameof(Entity.tede2.Media.Media.MediaType), ResourceTypeConst.Book.GetHashCode());
  621. query.OrderByDesc(nameof(Entity.tede2.Media.Media.ReadCount));
  622. }
  623. //3 课程榜
  624. if (request.DataTypeValue == RankingListConst.Article.GetHashCode())
  625. {
  626. query.Where(nameof(Entity.tede2.Media.Media.MediaType), ResourceTypeConst.Article.GetHashCode());
  627. query.OrderByDesc(nameof(Entity.tede2.Media.Media.ReadCount));
  628. }
  629. //Top 100 新书
  630. if (request.DataTypeValue == RankingListConst.NewBook.GetHashCode())
  631. {
  632. query.Where(nameof(Entity.tede2.Media.Media.MediaType), ResourceTypeConst.Book.GetHashCode());
  633. query.OrderByDesc(nameof(Entity.tede2.Media.Media.CreatedDate));
  634. }
  635. //文献头条
  636. if (request.DataTypeValue == RankingListConst.ArticleTop.GetHashCode())
  637. {
  638. query.Where(nameof(Entity.tede2.Media.Media.MediaType), ResourceTypeConst.Article.GetHashCode());
  639. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsTop));
  640. }
  641. if (request.DataTypeValue == RankingListConst.Audio.GetHashCode())
  642. {
  643. query.Where(nameof(Entity.tede2.Media.Media.MediaType), ResourceTypeConst.Audio.GetHashCode());
  644. query.OrderByDesc(nameof(Entity.tede2.Media.Media.ReadCount));
  645. }
  646. if (request.DataTypeValue == RankingListConst.HotComment.GetHashCode())
  647. query.OrderByDesc(nameof(Entity.tede2.Media.Media.CommentScore));
  648. if (request.DataTypeValue == RankingListConst.CollectionBook.GetHashCode())
  649. query.OrderByDesc(nameof(Entity.tede2.Media.Media.CollectCount));
  650. }
  651. query.Where(nameof(Entity.tede2.Media.Media.IsChecked), true);
  652. query.Where(nameof(Entity.tede2.Media.Media.IsDelete), false);
  653. result.Total = await _repository.CountAsync(query);
  654. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsTop));
  655. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsRecommend));
  656. query.ForPage(request.Page, request.PerPage);
  657. result.Items = await _repository.GetAllAsync<RankingListResult>(query);
  658. foreach (var item in result.Items)
  659. item.ImageUrls = StringUtils.AddDomain(item.ImageUrls);
  660. return result;
  661. }
  662. /// <summary>
  663. /// 大咖讲座
  664. /// </summary>
  665. /// <returns></returns>
  666. public async Task<IEnumerable<MediaCathedraResult>> GetMediasByTeacherAsync(ArticleGroupRequest request)
  667. {
  668. var query = Q.NewQuery();
  669. query.Select(nameof(Entity.tede2.Media.Media.Id));
  670. query.Select(nameof(Entity.tede2.Media.Media.Summary));
  671. query.Select(nameof(Entity.tede2.Media.Media.ImageUrls));
  672. query.Select(nameof(Entity.tede2.Media.Media.Title));
  673. query.Select(nameof(Entity.tede2.Media.Media.Author));
  674. query.Select(nameof(Entity.tede2.Media.Media.MediaType));
  675. query.Select(nameof(Entity.tede2.Media.Media.ReadCount));
  676. query.Select(nameof(Entity.tede2.Media.Media.CreatedDate));
  677. query.Where(nameof(Entity.tede2.Media.Media.TeacherId), ">", 0);
  678. query.Where(nameof(Entity.tede2.Media.Media.MediaType), GxPress.EnumConst.AllTypeConst.Video.GetHashCode());
  679. if (!string.IsNullOrEmpty(request.Sort))
  680. {
  681. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsTop));
  682. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsRecommend));
  683. }
  684. else
  685. query.OrderByDesc(nameof(Entity.tede2.Media.Media.CreatedDate));
  686. query.ForPage(request.Page, request.PerPage);
  687. return await _repository.GetAllAsync<MediaCathedraResult>(query);
  688. }
  689. /// <summary>
  690. /// 大咖讲座
  691. /// </summary>
  692. /// <returns></returns>
  693. public async Task<int> GetMediasByTeacherCountAsync(ArticleGroupRequest request)
  694. {
  695. var query = Q.NewQuery();
  696. query.Where(nameof(Entity.tede2.Media.Media.TeacherId), ">", 0);
  697. query.Where(nameof(Entity.tede2.Media.Media.MediaType), GxPress.EnumConst.AllTypeConst.Video.GetHashCode());
  698. return await _repository.CountAsync(query);
  699. }
  700. /// <summary>
  701. /// 每日技能分页
  702. /// </summary>
  703. /// <returns></returns>
  704. public async Task<PagedList<MediaCathedraResult>> GetDaySkillsAsync(MediaDayWeBookRequest request)
  705. {
  706. var resut = new PagedList<MediaCathedraResult>();
  707. var query = Q.NewQuery();
  708. query.Select(nameof(Entity.tede2.Media.Media.Id));
  709. query.Select(nameof(Entity.tede2.Media.Media.ImageUrls));
  710. query.Select(nameof(Entity.tede2.Media.Media.Title));
  711. query.Select(nameof(Entity.tede2.Media.Media.Author));
  712. query.Select(nameof(Entity.tede2.Media.Media.MediaType));
  713. query.Select(nameof(Entity.tede2.Media.Media.ReadCount));
  714. query.Select(nameof(Entity.tede2.Media.Media.CreatedDate));
  715. query.Select(nameof(Entity.tede2.Media.Media.Summary));
  716. query.Where(nameof(Entity.tede2.Media.Media.IsExercises), true);
  717. query.Where(nameof(Entity.tede2.Media.Media.MediaType), request.TypeValue);
  718. resut.Total = await _repository.CountAsync(query);
  719. if (!string.IsNullOrEmpty(request.Sort))
  720. {
  721. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsTop));
  722. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsRecommend));
  723. }
  724. else
  725. query.OrderByDesc(nameof(Entity.tede2.Media.Media.CreatedDate));
  726. query.ForPage(request.Page, request.PerPage);
  727. resut.Items = await _repository.GetAllAsync<MediaCathedraResult>(query);
  728. foreach (var item in resut.Items)
  729. item.ImageUrls = StringUtils.AddDomain(item.ImageUrls);
  730. return resut;
  731. }
  732. /// <summary>
  733. /// 每日技能
  734. /// </summary>
  735. /// <returns></returns>
  736. public async Task<SkillInfo> GetRandomDaySkillAsync()
  737. {
  738. var sql = $@"SELECT
  739. Id,Blocks,MediaType
  740. FROM
  741. tede_media where IsExercises=1 and MediaType={AllTypeConst.Article.GetHashCode()}
  742. ORDER BY RAND() LIMIT 1";
  743. var databaseType = _databaseTypestr.ToEnum<DatabaseType>(DatabaseType.MySql);
  744. var database = new Database(databaseType, _connectionString);
  745. var connection = database.GetConnection();
  746. return await connection.QueryFirstOrDefaultAsync<SkillInfo>(sql);
  747. }
  748. /// <summary>
  749. /// 猜你喜欢
  750. /// </summary>
  751. /// <returns></returns>
  752. public async Task<IEnumerable<MediaCathedraResult>> GetUserLikeAsync()
  753. {
  754. var sql = $@"SELECT
  755. Id,ImageUrls,Title,Author,MediaType,ReadCount,CreatedDate,Summary
  756. FROM
  757. tede_media where IsChecked=1 and MediaType={AllTypeConst.Book.GetHashCode()}
  758. ORDER BY RAND() LIMIT 3";
  759. var databaseType = _databaseTypestr.ToEnum<DatabaseType>(DatabaseType.MySql);
  760. var database = new Database(databaseType, _connectionString);
  761. var connection = database.GetConnection();
  762. return await connection.QueryAsync<MediaCathedraResult>(sql);
  763. }
  764. /// <summary>
  765. /// 导航内容
  766. /// </summary>
  767. /// <returns></returns>
  768. public async Task<PagedList<MediaCathedraResult>> GetContentNavigationAsync(MediaContentNavigationRequest request)
  769. {
  770. var resut = new PagedList<MediaCathedraResult>();
  771. var query = Q.NewQuery();
  772. query.Select(nameof(Entity.tede2.Media.Media.Id));
  773. query.Select(nameof(Entity.tede2.Media.Media.ImageUrls));
  774. query.Select(nameof(Entity.tede2.Media.Media.Title));
  775. query.Select(nameof(Entity.tede2.Media.Media.Author));
  776. query.Select(nameof(Entity.tede2.Media.Media.MediaType));
  777. query.Select(nameof(Entity.tede2.Media.Media.ReadCount));
  778. query.Select(nameof(Entity.tede2.Media.Media.CreatedDate));
  779. query.Select(nameof(Entity.tede2.Media.Media.Summary));
  780. if (request.MediaIds.Count() > 0)
  781. query.WhereIn(nameof(Entity.tede2.Media.Media.Id), request.MediaIds);
  782. if (request.TeacherId != null && request.TeacherId.Count > 0)
  783. query.WhereIn(nameof(Entity.tede2.Media.Media.TeacherId), request.TeacherId);
  784. if (!string.IsNullOrEmpty(request.BeginTime) && !string.IsNullOrEmpty(request.EndTime))
  785. {
  786. query.Where(nameof(Entity.tede2.Media.Media.AddDate), ">=", request.BeginTime);
  787. query.Where(nameof(Entity.tede2.Media.Media.AddDate), "<=", request.EndTime);
  788. }
  789. if (request.Press != null && request.Press.Count > 0)
  790. {
  791. query.OrWhereIn(nameof(Entity.tede2.Media.Media.Press), request.Press);
  792. }
  793. resut.Total = await _repository.CountAsync(query);
  794. if (!string.IsNullOrEmpty(request.Sort))
  795. {
  796. if (request.Sort.Equals("0"))
  797. {
  798. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsTop));
  799. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsRecommend));
  800. }
  801. if (request.Sort.Equals("1"))
  802. {
  803. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsTop));
  804. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsRecommend));
  805. }
  806. if (request.Sort.Equals("2"))
  807. {
  808. query.OrderByDesc(nameof(Entity.tede2.Media.Media.ReadCount));
  809. }
  810. if (request.Sort.Equals("3"))
  811. {
  812. query.OrderByDesc(nameof(Entity.tede2.Media.Media.AddDate));
  813. }
  814. if (request.Sort.Equals("4"))
  815. {
  816. query.OrderBy(nameof(Entity.tede2.Media.Media.AddDate));
  817. }
  818. }
  819. else
  820. query.OrderByDesc(nameof(Entity.tede2.Media.Media.CreatedDate));
  821. query.ForPage(request.Page, request.PerPage);
  822. resut.Items = await _repository.GetAllAsync<MediaCathedraResult>(query);
  823. foreach (var item in resut.Items)
  824. {
  825. item.ImageUrls = StringUtils.AddDomain(item.ImageUrls);
  826. }
  827. return resut;
  828. }
  829. /// <summary>
  830. /// 明栏分页
  831. /// </summary>
  832. /// <returns></returns>
  833. public async Task<PagedList<MediaCathedraResult>> GetStarLablePageAsync(MediaStarLableRequest request)
  834. {
  835. var resut = new PagedList<MediaCathedraResult>();
  836. var query = Q.NewQuery();
  837. query.Select(nameof(Entity.tede2.Media.Media.Id));
  838. query.Select(nameof(Entity.tede2.Media.Media.ImageUrls));
  839. query.Select(nameof(Entity.tede2.Media.Media.Title));
  840. query.Select(nameof(Entity.tede2.Media.Media.Author));
  841. query.Select(nameof(Entity.tede2.Media.Media.MediaType));
  842. query.Select(nameof(Entity.tede2.Media.Media.ReadCount));
  843. query.Select(nameof(Entity.tede2.Media.Media.Summary));
  844. query.Select(nameof(Entity.tede2.Media.Media.CreatedDate));
  845. if (!string.IsNullOrEmpty(request.KeyWord))
  846. query.WhereLike(nameof(Entity.tede2.Media.Media.Title), $"%{request.KeyWord}%");
  847. query.WhereIn(nameof(Entity.tede2.Media.Media.Id), request.MediaIds);
  848. resut.Total = await _repository.CountAsync(query);
  849. if (!string.IsNullOrEmpty(request.Sort))
  850. {
  851. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsTop));
  852. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsRecommend));
  853. }
  854. else
  855. query.OrderByDesc(nameof(Entity.tede2.Media.Media.CreatedDate));
  856. query.ForPage(request.Page, request.PerPage);
  857. resut.Items = await _repository.GetAllAsync<MediaCathedraResult>(query);
  858. foreach (var item in resut.Items)
  859. {
  860. item.ImageUrls = StringUtils.AddDomain(item.ImageUrls);
  861. }
  862. return resut;
  863. }
  864. /// <summary>
  865. /// 明栏
  866. /// </summary>
  867. /// <returns></returns>
  868. public async Task<IEnumerable<MediaCathedraResult>> GetStarLablesAsync(MediaStarLableRequest request)
  869. {
  870. var query = Q.NewQuery();
  871. query.Select(nameof(Entity.tede2.Media.Media.Id));
  872. query.Select(nameof(Entity.tede2.Media.Media.ImageUrls));
  873. query.Select(nameof(Entity.tede2.Media.Media.Title));
  874. query.Select(nameof(Entity.tede2.Media.Media.Author));
  875. query.Select(nameof(Entity.tede2.Media.Media.MediaType));
  876. query.Select(nameof(Entity.tede2.Media.Media.ReadCount));
  877. query.Select(nameof(Entity.tede2.Media.Media.CreatedDate));
  878. query.Select(nameof(Entity.tede2.Media.Media.Summary));
  879. if (!string.IsNullOrEmpty(request.KeyWord))
  880. query.WhereLike(nameof(Entity.tede2.Media.Media.Title), $"%{request.KeyWord}%");
  881. query.WhereIn(nameof(Entity.tede2.Media.Media.Id), request.MediaIds);
  882. if (!string.IsNullOrEmpty(request.Sort))
  883. {
  884. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsTop));
  885. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsRecommend));
  886. }
  887. else
  888. query.OrderByDesc(nameof(Entity.tede2.Media.Media.CreatedDate));
  889. query.ForPage(request.Page, request.PerPage);
  890. var reuslt = await _repository.GetAllAsync<MediaCathedraResult>(query);
  891. foreach (var item in reuslt)
  892. {
  893. item.ImageUrls = StringUtils.AddDomain(item.ImageUrls);
  894. }
  895. return reuslt;
  896. }
  897. /// <summary>
  898. /// app频道
  899. /// </summary>
  900. /// <returns></returns>
  901. public async Task<PagedList<MediaChannelCategoryResult>> GetAppChannelsAsync(AppChannelSearchRequest request)
  902. {
  903. var resut = new PagedList<MediaChannelCategoryResult>();
  904. var query = Q.NewQuery();
  905. query.Select(nameof(Entity.tede2.Media.Media.Id));
  906. query.Select(nameof(Entity.tede2.Media.Media.ImageUrls));
  907. query.Select(nameof(Entity.tede2.Media.Media.Title));
  908. query.Select(nameof(Entity.tede2.Media.Media.Author));
  909. query.Select(nameof(Entity.tede2.Media.Media.MediaType));
  910. query.Select(nameof(Entity.tede2.Media.Media.ReadCount));
  911. query.Select(nameof(Entity.tede2.Media.Media.CreatedDate));
  912. query.Select(nameof(Entity.tede2.Media.Media.Summary));
  913. query.Select(nameof(Entity.tede2.Media.Media.CommentScore));
  914. query.WhereIn(nameof(Entity.tede2.Media.Media.Id), request.Ids);
  915. //最热
  916. if (request.SortSift == 1)
  917. query.OrderByDesc(nameof(Entity.tede2.Media.Media.ReadCount));
  918. //最新
  919. if (request.SortSift == 2)
  920. query.OrderByDesc(nameof(Entity.tede2.Media.Media.CreatedDate));
  921. //好评
  922. if (request.SortSift == 3)
  923. query.OrderByDesc(nameof(Entity.tede2.Media.Media.CommentScore));
  924. if (request.PressSift != null && request.PressSift.Count() > 0)
  925. query.WhereIn(nameof(Entity.tede2.Media.Media.Press), request.PressSift);
  926. if (!string.IsNullOrEmpty(request.KeyWord))
  927. query.WhereLike(nameof(Entity.tede2.Media.Media.Title), $"%{request.KeyWord}%");
  928. resut.Total = await _repository.CountAsync(query);
  929. if (!string.IsNullOrEmpty(request.Sort))
  930. {
  931. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsTop));
  932. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsRecommend));
  933. }
  934. else
  935. query.OrderByDesc(nameof(Entity.tede2.Media.Media.CreatedDate));
  936. query.ForPage(request.Page, request.PerPage);
  937. resut.Items = await _repository.GetAllAsync<MediaChannelCategoryResult>(query);
  938. foreach (var item in resut.Items)
  939. item.ImageUrls = StringUtils.AddDomain(item.ImageUrls);
  940. return resut;
  941. }
  942. /// <summary>
  943. /// 获取出版社
  944. /// </summary>
  945. /// <returns></returns>
  946. public async Task<IEnumerable<string>> GetPresssAsync()
  947. {
  948. var query = Q.NewQuery();
  949. query.Where(nameof(Entity.tede2.Media.Media.Id), ">", 0);
  950. query.GroupBy(nameof(Entity.tede2.Media.Media.Press));
  951. query.Select(nameof(Entity.tede2.Media.Media.Press));
  952. query.Where(nameof(Entity.tede2.Media.Media.Press), "<>", "");
  953. return await _repository.GetAllAsync<string>(query);
  954. }
  955. }
  956. }