123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- using GxPress.Service.Interface.Press;
- using GxPress.Repository.Interface.Press;
- using System.Threading.Tasks;
- using GxPress.Result.Press;
- using GxPress.EnumConst;
- using GxPress.Service.Interface.Analyze;
- using GxPress.Service.Interface.VisitHistory;
- using GxPress.Request.Press;
- using System.Linq;
- using GxPress.Common.Tools;
- using GxPress.Repository.Interface.Teacher;
- using GxPress.Request.TeacherRequest;
- using GxPress.Repository.Interface.Media;
- using System.Collections.Generic;
- namespace GxPress.Service.Implement.Press
- {
- public class PressService : IPressService
- {
- private readonly IPressRepository pressRepository;
- private readonly IAnalyzeService _analyzeService;
- private readonly IVisitHistoryService visitHistoryService;
- private readonly ITeacherRepository teacherRepository;
- private readonly IMediaRepository mediaRepository;
- public PressService(IPressRepository pressRepository, IAnalyzeService _analyzeService,
- IVisitHistoryService visitHistoryService, ITeacherRepository teacherRepository,
- IMediaRepository mediaRepository)
- {
- this.pressRepository = pressRepository;
- this._analyzeService = _analyzeService;
- this.visitHistoryService = visitHistoryService;
- this.teacherRepository = teacherRepository;
- this.mediaRepository = mediaRepository;
- }
- /// <summary>
- /// 根据ID获取组织
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public async Task<PressResult> GetPressAsync(int id, int userId)
- {
- var result = await pressRepository.GetPressAsync(id);
- //获取老师
- result.TeacherResult = await teacherRepository.GetPressTeacherResult(new TeacherRequest { PressId = id, UserId = userId });
- var sourceLibrary = new List<int> { AllTypeConst.Book.GetHashCode(), AllTypeConst.Video.GetHashCode(), AllTypeConst.Audio.GetHashCode() };
- //获取共享资源
- result.Resource = new List<Result.AppPageSearch.AppPageSearchResult<Result.Media.MediaSearchResult>>();
- foreach (var item in sourceLibrary)
- {
- var items = (await mediaRepository.GetMediaByLableIdAysnc(new Request.Media.MediaLableIdRequest { Page = 1, PerPage = 3, PressId = id, MediaType = item })).Items;
- if (items.Count() == 0)
- continue;
- result.Resource.Add(new Result.AppPageSearch.AppPageSearchResult<Result.Media.MediaSearchResult>
- {
- LableName = ((AllTypeConst)item).GetDescriptionOriginal(),
- LableId = item,
- Items = items
- });
- }
- var analyzeRequest = new Request.App.Analyze.AnalyzeRequest();
- analyzeRequest.TypeValue = AllTypeConst.Press.GetHashCode();
- analyzeRequest.AnalyzeType = 1;
- analyzeRequest.SourceId = id;
- analyzeRequest.UserId = userId;
- //获取话题的转发数量
- analyzeRequest.AnalyzeType = 4;
- var retransmissionCount = await _analyzeService.CountAsync(analyzeRequest);
- result.RetransmissionCount = retransmissionCount;
- result.IsRetransmission = await _analyzeService.ExistsAsync(analyzeRequest);
- //获取话题的收藏数量
- analyzeRequest.AnalyzeType = 3;
- var collectCount = await _analyzeService.CountAsync(analyzeRequest);
- result.CollectCount = collectCount;
- //是否收藏
- result.IsCollect = await _analyzeService.ExistsAsync(analyzeRequest);
- //获取点赞数量
- analyzeRequest.AnalyzeType = 1;
- var praiseCount = await _analyzeService.CountAsync(analyzeRequest);
- result.PraiseCount = praiseCount;
- //是否点赞
- result.IsPraise = await _analyzeService.ExistsAsync(analyzeRequest);
- if (userId > 0)
- //获取用户历史记录
- await visitHistoryService.InsertAsync(userId, id, AllTypeConst.Press.GetHashCode());
- return result;
- }
- /// <summary>
- /// 添加修改
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- public async Task<bool> AddOrModifyAsync(PressAddOrModifyRequest request)
- {
- if (request.LableName.Count() == 0 || string.IsNullOrEmpty(request.ExtendLableName))
- throw new Common.Exceptions.BusinessException("必要参数为空");
- var press = new Entity.Press.Press()
- {
- FileUrl = StringUtils.RemoveDomain(request.FileUrl),
- IsDisable = request.IsDisable,
- IsTop = request.IsTop,
- IsHot = request.IsHot,
- IsRecommend = request.IsRecommend,
- ImageUrl = StringUtils.RemoveDomain(request.ImageUrl),
- Name = request.Name,
- Summary = request.Summary,
- Sort = request.Sort,
- VideoCoverImage = StringUtils.RemoveDomain(request.VideoCoverImage),
- ExtendLableName = request.ExtendLableName
- };
- if (request.Id > 0)
- press = await pressRepository.GetAsync(request.Id);
- press.LableName = StringUtils.ObjectCollectionToString(request.LableName, ",");
- press.Duration = StringUtils.MediaDuration(press.FileUrl);
- press.VideoImage = StringUtils.MediaImage(press.FileUrl);
- if (request.Id > 0)
- return await pressRepository.UpdateAsync(press);
- return await pressRepository.InsertAsync(press) > 0;
- }
- }
- }
|