123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using System.Transactions;
- using AutoMapper;
- using GxPress.Common.Tools;
- using GxPress.Entity.Topic;
- using GxPress.Repository.Interface;
- using GxPress.Request.App.Topic;
- using GxPress.Service.Interface.Topic;
- using Datory;
- using GxPress.Common.Exceptions;
- using GxPress.Common.Page;
- using GxPress.Repository.Interface.Topic;
- using GxPress.Result;
- using GxPress.Result.App.Topic;
- using GxPress.Service.Interface.Note;
- using Newtonsoft.Json;
- using GxPress.Repository.Interface.Visit;
- using GxPress.Service.Interface.Visit;
- using GxPress.Service.Interface.Analyze;
- using GxPress.EnumConst;
- namespace GxPress.Service.Implement.Topic
- {
- public partial class TopicService : ITopicService
- {
- private readonly ITopicRepository _topicRepository;
- private readonly IUserRepository _userRepository;
- private readonly ITopicAddresseeRepository _topicAddresseeRepository;
- private readonly IDepartmentRepository _departmentRepository;
- private readonly ITopicGroupRepository _topicGroupRepository;
- private readonly ITopicGroupUserRepository _topicGroupUserRepository;
- private readonly IAnalyzeService _analyzeService;
- private readonly ICommentRepository _commentRepository;
- private readonly IMapper _mapper;
- private readonly IGroupUserRepository _groupUserRepository;
- private readonly IFolderUserRepository _folderUserRepository;
- private readonly INoteService _noteService;
- private readonly IMiddleRepository _middleRepository;
- private readonly IVisitRepository _visitRepository;
- private readonly IVisitService _visitService;
- public TopicService(ITopicRepository topicRepository, IUserRepository userRepository,
- ITopicAddresseeRepository topicAddresseeRepository,
- ITopicGroupRepository topicGroupRepository,
- ITopicGroupUserRepository topicGroupUserRepository, IAnalyzeService analyzeService,
- ICommentRepository commentRepository, IMapper mapper, IDepartmentRepository departmentRepository,
- IGroupUserRepository groupUserRepository, IFolderUserRepository folderUserRepository,
- INoteService noteService, IMiddleRepository middleRepository, IVisitRepository visitRepository, IVisitService visitService)
- {
- _topicRepository = topicRepository;
- _userRepository = userRepository;
- _topicAddresseeRepository = topicAddresseeRepository;
- _topicGroupRepository = topicGroupRepository;
- _topicGroupUserRepository = topicGroupUserRepository;
- _analyzeService = analyzeService;
- _commentRepository = commentRepository;
- _departmentRepository = departmentRepository;
- _mapper = mapper;
- _groupUserRepository = groupUserRepository;
- _folderUserRepository = folderUserRepository;
- _noteService = noteService;
- _middleRepository = middleRepository;
- _visitRepository = visitRepository;
- _visitService = visitService;
- }
-
-
-
-
-
- public async Task<bool> DeleteTopicGroupAsync(List<int> ids)
- {
- try
- {
- using (TransactionScope transactionScope = new TransactionScope())
- {
- await _topicGroupRepository.DeleteAsync(ids);
- await _topicGroupUserRepository.DeleteGroupIdAsync(ids);
- transactionScope.Complete();
- }
- }
- catch (Exception e)
- {
- Console.WriteLine(e);
- throw;
- }
- return false;
- }
-
-
-
-
-
- public async Task<PagedList<TopicListPageResult>> GetTopicPageAsync(TopicPageSearchRequest request)
- {
- var result = await _topicRepository.GetTopicPage(request);
-
-
- foreach (var item in result.Items)
- {
- if (string.IsNullOrWhiteSpace(item.UserName))
- {
- item.Content = "[]";
- item.Data = JsonConvert.DeserializeObject<List<ContentJsonData>>(item.Content);
- item.Content = "";
- continue;
- }
- if (string.IsNullOrWhiteSpace(item.Content))
- item.Content = "[]";
- var contentJsonData = JsonConvert.DeserializeObject<List<ContentJsonData>>(item.Content);
- foreach (var contentJsonDataItem in contentJsonData)
- contentJsonDataItem.File = StringUtils.AddDomain(contentJsonDataItem.File);
- if (contentJsonData.Count == 0)
- item.DataType = 1;
- item.Content = "";
- if (contentJsonData.Count > 0)
- {
- var imgData = new List<ContentJsonData>();
- var FileData = new List<ContentJsonData>();
- var forCount = 1;
- var firstContent = string.Empty;
- foreach (var jsonData in contentJsonData)
- {
- if (jsonData.TypeValue == OldTextEditorTypeConst.Text.GetHashCode() && forCount == 1)
-
- firstContent = jsonData.Text;
- else if (jsonData.TypeValue == OldTextEditorTypeConst.Text.GetHashCode() && forCount > 1)
-
- continue;
-
- else if (jsonData.TypeValue == OldTextEditorTypeConst.Image.GetHashCode() && FileData.Count == 0)
- {
- if (imgData.Count > 9)
- break;
- imgData.Add(jsonData);
- }
-
- else
- {
- FileData.Add(jsonData);
- break;
- }
- forCount++;
- }
- item.Content = string.IsNullOrWhiteSpace(firstContent) ? "" : firstContent;
- if (imgData.Count > 0) { item.DataType = 2; item.Data = imgData; }
- else if (FileData.Count > 0) { item.DataType = 3; item.Data = FileData; }
- else item.DataType = 1;
- var contType = new List<int> { OldTextEditorTypeConst.Text.GetHashCode(), OldTextEditorTypeConst.Image.GetHashCode() };
- item.FileCount = contentJsonData.Count(n => !contType.Contains(n.Type));
- }
- if (item.Data == null || item.Data.Count == 0)
- item.Data = new List<ContentJsonData>();
- }
- return result;
- }
-
-
-
-
-
- public List<ContentJsonData> GetListAsync(List<ContentJsonData> contentJsonDataList)
- {
- var result = new List<ContentJsonData>();
- if (contentJsonDataList.Count > 0)
- {
-
- var txtType = contentJsonDataList.FirstOrDefault(n => n.Type == 1);
- if (txtType != null)
- result.Add(txtType);
-
- var imgType = contentJsonDataList.FindAll(n => n.Type == 2);
- if (imgType.Any())
- {
- foreach (var item in imgType)
- {
-
- if (result.Count(n => n.Type == 2) > 8)
- break;
- result.Add(item);
- }
- }
- else
- {
- var values = new List<int> { 1, 2 };
- var list = contentJsonDataList.FindAll(n => !values.Contains(n.Type));
- if (list.Any())
- result.Add(list.FirstOrDefault());
- }
- }
- return result;
- }
-
-
-
-
-
-
- public async Task<bool> InsertTopicGroupUserAsync(List<int> userIds, int topicGroupId)
- {
- try
- {
- using (TransactionScope transactionScope = new TransactionScope())
- {
-
- var topicGroupUsers =
- await _topicGroupUserRepository.GetAllAsync(Q.Where(nameof(TopicGroupUser.TopicGroupId),
- topicGroupId));
- var groupUsers = topicGroupUsers as TopicGroupUser[] ?? topicGroupUsers.ToArray();
- foreach (var userId in userIds)
- {
- if (groupUsers.Any(n => n.UserId == userId))
- continue;
- var topicGroupUser = new TopicGroupUser { TopicGroupId = topicGroupId, UserId = userId };
- await _topicGroupUserRepository.InsertAsync(topicGroupUser);
- }
-
- var includeCount =
- await _topicGroupUserRepository.CountAsync(Q.Where(nameof(TopicGroupUser.TopicGroupId),
- topicGroupId));
-
- await _topicGroupRepository.UpdateAsync(Q.Where(nameof(TopicGroup.Id), topicGroupId)
- .Set(nameof(TopicGroup.IncludeCount), includeCount));
- transactionScope.Complete();
- return true;
- }
- }
- catch (Exception e)
- {
- Console.WriteLine(e);
- throw;
- }
- }
-
-
-
-
-
- public async Task<bool> DeleteTopicGroupUserAsync(List<int> ids)
- {
- if (ids.Count == 0)
- throw new BusinessException("删除的话题分组成员不存在");
- try
- {
- using (TransactionScope transactionScope = new TransactionScope())
- {
-
- var topicGroupUser = await _topicGroupUserRepository.GetAsync(ids[0]);
- await _topicGroupUserRepository.DeleteAsync(Q.WhereIn(nameof(TopicGroupUser.Id), ids));
- var count = await _topicGroupUserRepository.CountAsync(Q.Where(nameof(TopicGroupUser.TopicGroupId),
- topicGroupUser.TopicGroupId));
-
- await _topicGroupRepository.UpdateAsync(Q.Set(nameof(TopicGroup.IncludeCount), count)
- .Where(nameof(TopicGroup.Id), topicGroupUser.TopicGroupId));
- transactionScope.Complete();
- }
- }
- catch (Exception e)
- {
- Console.WriteLine(e);
- throw;
- }
- return true;
- }
-
-
-
-
-
- public async Task<bool> MoveToGroupAsync(MoveToGroupRequest request)
- {
- using (TransactionScope transactionScope = new TransactionScope())
- {
-
- var topicGroupUser = await _topicGroupUserRepository.GetAsync(request.Ids[0]);
-
- await _topicGroupUserRepository.UpdateAsync(Q
- .Set(nameof(TopicGroupUser.TopicGroupId), request.TopicGroupId)
- .WhereIn(nameof(TopicGroupUser.Id), request.Ids));
-
- var originalCount = await _topicGroupUserRepository.CountAsync(Q.Where(nameof(TopicGroupUser.TopicGroupId),
- topicGroupUser.TopicGroupId));
- await _topicGroupRepository.UpdateAsync(Q.Set(nameof(TopicGroup.IncludeCount), originalCount)
- .Where(nameof(TopicGroup.Id), topicGroupUser.TopicGroupId));
-
- var count = await _topicGroupUserRepository.CountAsync(Q.Where(nameof(TopicGroupUser.TopicGroupId),
- request.TopicGroupId));
- await _topicGroupRepository.UpdateAsync(Q.Set(nameof(TopicGroup.IncludeCount), count)
- .Where(nameof(TopicGroup.Id), request.TopicGroupId));
- transactionScope.Complete();
- }
- return true;
- }
-
-
-
-
-
- public async Task<PagedList<TopicListPageResult>> FindTopicByGroupIdAsync(TopicDetailListRequest request)
- {
-
- var topics = await _topicRepository.GetAllAsync(Q.Where(nameof(Entity.Topic.Topic.GroupId), request.GroupId));
-
- await _topicAddresseeRepository.UpdateAsync(Q.WhereIn(nameof(Entity.Topic.TopicAddressee.TopicId), topics.Select(n => n.Id).ToList()).Where(nameof(Entity.Topic.TopicAddressee.UserId), request.UserId).Set(nameof(Entity.Topic.TopicAddressee.IsRead), true));
- var topicListPageResults = await _topicRepository.FindTopicByGroupIdAsync(request);
- foreach (var item in topicListPageResults.Items)
- {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if (string.IsNullOrWhiteSpace(item.Content))
- item.Content = "[]";
- var contentJsonData = JsonConvert.DeserializeObject<List<ContentJsonData>>(item.Content);
- foreach (var contentJsonDataItem in contentJsonData)
- contentJsonDataItem.File = StringUtils.AddDomain(contentJsonDataItem.File);
- if (contentJsonData.Count == 0)
- item.DataType = 1;
- item.Content = "";
- if (contentJsonData.Count > 0)
- {
- var imgData = new List<ContentJsonData>();
- var FileData = new List<ContentJsonData>();
- var forCount = 1;
- var firstContent = string.Empty;
- foreach (var jsonData in contentJsonData)
- {
- if (jsonData.TypeValue == OldTextEditorTypeConst.Text.GetHashCode() && forCount == 1)
-
- firstContent = jsonData.Text;
- else if (jsonData.TypeValue == OldTextEditorTypeConst.Text.GetHashCode() && forCount > 1)
-
- continue;
-
- else if (jsonData.TypeValue == OldTextEditorTypeConst.Image.GetHashCode() && FileData.Count == 0)
- {
- if (imgData.Count > 9)
- break;
- imgData.Add(jsonData);
- }
-
- else
- {
- FileData.Add(jsonData);
- break;
- }
- forCount++;
- }
- item.Content = string.IsNullOrWhiteSpace(firstContent) ? "" : firstContent;
- if (imgData.Count > 0) { item.DataType = 2; item.Data = imgData; }
- else if (FileData.Count > 0) { item.DataType = 3; item.Data = FileData; }
- else item.DataType = 1;
- var contType = new List<int> { OldTextEditorTypeConst.Text.GetHashCode(), OldTextEditorTypeConst.Image.GetHashCode() };
- item.FileCount = contentJsonData.Count(n => !contType.Contains(n.Type));
- }
- if (item.Data == null || item.Data.Count == 0)
- item.Data = new List<ContentJsonData>();
-
- }
- return topicListPageResults;
- }
- }
- }
|