MediaRepository.cs 49 KB

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