PageUpdateInfoService.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using Attribute;
  2. using Dto;
  3. using Vo;
  4. using Model;
  5. using Model.Base;
  6. using Repository;
  7. using Service;
  8. using Microsoft.AspNetCore.Mvc;
  9. using Aliyun.OSS;
  10. using Common;
  11. using System.Text.RegularExpressions;
  12. using Infrastructure.Model;
  13. using Base;
  14. namespace Services
  15. {
  16. /// <summary>
  17. /// 页面模板更新信息Service业务层处理
  18. /// </summary>
  19. [AppService(ServiceType = typeof(IPageUpdateInfoService), ServiceLifetime = LifeTime.Transient)]
  20. public class PageUpdateInfoService : BaseService<PageUpdateInfo>, IPageUpdateInfoService
  21. {
  22. /// <summary>
  23. /// 页面模板更新信息-列表
  24. /// </summary>
  25. /// <param name="parm">请求参数</param>
  26. /// <returns>页面模板更新信息列表</returns>
  27. public PagedInfo<PageUpdateInfoListVo> List([FromQuery] PageUpdateInfoListDto parm)
  28. {
  29. //开始拼装查询条件
  30. var predicate = Expressionable.Create<PageUpdateInfo>();
  31. predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.kind), m => m.kind.Contains(parm.kind));
  32. var response = Queryable()
  33. .Where(predicate.ToExpression())
  34. .OrderByDescending(m => m.id)
  35. .ToPage<PageUpdateInfo, PageUpdateInfoListVo>(new PagerInfo());
  36. return response;
  37. }
  38. /// <summary>
  39. /// 页面模板更新信息-刷新文件
  40. /// </summary>
  41. /// <param name="parm">请求参数</param>
  42. /// <returns>页面模板更新信息刷新文件</returns>
  43. public void UpdateTemplate([FromQuery] PageUpdateInfoListDto parm)
  44. {
  45. OssConfigs ossConfigs = new();
  46. AppSettings.Bind("OssConfigs", ossConfigs);
  47. GetSystemFiles(ossConfigs, parm.kind);
  48. foreach (string filename in SystemFiles)
  49. {
  50. string template = filename.Substring(filename.LastIndexOf("/") + 1);
  51. if (template.EndsWith(".html"))
  52. {
  53. PageUpdateInfo check = GetFirst(m => m.modulePath == template && m.kind == parm.kind);
  54. if (check == null)
  55. {
  56. string ModuleContent = Function.GetNetFileContent(ossConfigs.Host + "template/app/" + parm.kind + "/" + template);
  57. if (!string.IsNullOrEmpty(ModuleContent))
  58. {
  59. string admintitle = "";
  60. string title = "";
  61. Match match = Regex.Match(ModuleContent, "<title>.*?</title>", RegexOptions.IgnoreCase);
  62. if (match.Success)
  63. {
  64. admintitle = match.Value.Replace("<title>", "").Replace("</title>", "");
  65. if (admintitle.Contains("-"))
  66. {
  67. title = admintitle.Substring(admintitle.LastIndexOf("-") + 1);
  68. }
  69. else
  70. {
  71. title = admintitle;
  72. }
  73. }
  74. Add(new PageUpdateInfo()
  75. {
  76. createDate = DateTime.Now,
  77. updateDate = DateTime.Now,
  78. kind = parm.kind,
  79. leftAction1 = "{\"Url\":\"GoBack#{\\\"Level\\\":\\\"1\\\"}\",\"Jump\":\"1\",\"Kind\":\"2\"}",
  80. leftBtn1 = "static/images/left.png",
  81. skidFlag = true,
  82. showScrollBar = false,
  83. title = title,
  84. showTitle = true,
  85. statusBarStyle = "default",
  86. textColor = "FFFFFF",
  87. backgroudColor = "FD7538",
  88. modulePath = template,
  89. moduleVersion = 1,
  90. });
  91. }
  92. }
  93. }
  94. }
  95. }
  96. List<string> SystemFiles;
  97. private void GetSystemFiles(OssConfigs ossConfigs, string Kind = "default")
  98. {
  99. SystemFiles = new List<string>();
  100. var client = new OssClient(ossConfigs.Endpoint, ossConfigs.Key, ossConfigs.Secret);
  101. var listObjectsRequest = new ListObjectsRequest(ossConfigs.BucketName);
  102. listObjectsRequest.MaxKeys = 1000;
  103. listObjectsRequest.Prefix = "template/app/" + Kind + "/";
  104. var result = client.ListObjects(listObjectsRequest);
  105. foreach (var summary in result.ObjectSummaries)
  106. {
  107. SystemFiles.Add(summary.Key);
  108. }
  109. }
  110. }
  111. }