123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- using System.Collections.Generic;
- using System.Linq;
- using GxPress.EnumConst;
- using GxPress.Result;
- using GxPress.Service.Interface.ContentJson;
- using Newtonsoft.Json;
- namespace GxPress.Service.Implement.ContentJson
- {
- public class ContentJsonService : IContentJsonService
- {
- public string GetTitile(string title, string content)
- {
- if (string.IsNullOrWhiteSpace(title))
- {
- if (string.IsNullOrEmpty(content))
- content = "[]";
- var data = JsonConvert.DeserializeObject<List<ContentJsonData>>(content);
- if (data.Count > 0)
- {
- var first = data.First();
- if (first.TypeValue == AllTypeConst.Text.GetHashCode() && !string.IsNullOrWhiteSpace(first.Text))
- title = first.Text;
- else
- {
- foreach (var contentJsonData in data)
- {
- //是否是文本
- if (contentJsonData.TypeValue == AllTypeConst.Text.GetHashCode())
- continue;
- else if (contentJsonData.TypeValue == AllTypeConst.Image.GetHashCode())
- {
- title = "[图片]";
- break;
- }
- else if (contentJsonData.TypeValue == AllTypeConst.File.GetHashCode())
- {
- title = "[附件]";
- break;
- }
- else
- {
- title = "[附件]";
- break;
- }
- }
- }
- }
- }
- if (string.IsNullOrEmpty(title))
- title = string.Empty;
- if (title.Length > 50)
- title = title.Remove(50, title.Length - 50);
- return title;
- }
- }
- }
|