ContentJsonService.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using GxPress.EnumConst;
  4. using GxPress.Result;
  5. using GxPress.Service.Interface.ContentJson;
  6. using Newtonsoft.Json;
  7. namespace GxPress.Service.Implement.ContentJson
  8. {
  9. public class ContentJsonService : IContentJsonService
  10. {
  11. public string GetTitile(string title, string content)
  12. {
  13. if (string.IsNullOrWhiteSpace(title))
  14. {
  15. if (string.IsNullOrEmpty(content))
  16. content = "[]";
  17. var data = JsonConvert.DeserializeObject<List<ContentJsonData>>(content);
  18. if (data.Count > 0)
  19. {
  20. var first = data.First();
  21. if (first.TypeValue == AllTypeConst.Text.GetHashCode() && !string.IsNullOrWhiteSpace(first.Text))
  22. title = first.Text;
  23. else
  24. {
  25. foreach (var contentJsonData in data)
  26. {
  27. //是否是文本
  28. if (contentJsonData.TypeValue == AllTypeConst.Text.GetHashCode())
  29. continue;
  30. else if (contentJsonData.TypeValue == AllTypeConst.Image.GetHashCode())
  31. {
  32. title = "[图片]";
  33. break;
  34. }
  35. else if (contentJsonData.TypeValue == AllTypeConst.File.GetHashCode())
  36. {
  37. title = "[附件]";
  38. break;
  39. }
  40. else
  41. {
  42. title = "[附件]";
  43. break;
  44. }
  45. }
  46. }
  47. }
  48. }
  49. if (string.IsNullOrEmpty(title))
  50. title = string.Empty;
  51. if (title.Length > 50)
  52. title = title.Remove(50, title.Length - 50);
  53. return title;
  54. }
  55. }
  56. }