PageUpdateInfoService.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. using Mapster;
  15. namespace Services
  16. {
  17. /// <summary>
  18. /// 页面模板更新信息Service业务层处理
  19. /// </summary>
  20. [AppService(ServiceType = typeof(IPageUpdateInfoService), ServiceLifetime = LifeTime.Transient)]
  21. public class PageUpdateInfoService : BaseService<PageUpdateInfo>, IPageUpdateInfoService
  22. {
  23. /// <summary>
  24. /// 页面模板更新信息-列表
  25. /// </summary>
  26. /// <param name="parm">请求参数</param>
  27. /// <returns>页面模板更新信息列表</returns>
  28. public PagedInfo<PageUpdateInfoListVo> List([FromQuery] PageUpdateInfoListDto parm)
  29. {
  30. PagerInfo pager = new PagerInfo();
  31. pager.pageSize = 100000;
  32. //开始拼装查询条件
  33. var predicate = Expressionable.Create<PageUpdateInfo>();
  34. predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.kind), m => m.kind.Contains(parm.kind));
  35. var response = Queryable()
  36. .Where(predicate.ToExpression())
  37. .OrderByDescending(m => m.id)
  38. .ToPage<PageUpdateInfo, PageUpdateInfoListVo>(pager);
  39. return response;
  40. }
  41. /// <summary>
  42. /// 页面模板更新信息-刷新文件
  43. /// </summary>
  44. /// <param name="parm">请求参数</param>
  45. /// <returns>页面模板更新信息刷新文件</returns>
  46. public void UpdateTemplate([FromQuery] PageUpdateInfoUpdateTemplateDto parm)
  47. {
  48. OssConfigs ossConfigs = new();
  49. AppSettings.Bind("OssConfigs", ossConfigs);
  50. GetSystemFiles(ossConfigs, parm.kind);
  51. foreach (string filename in SystemFiles)
  52. {
  53. string template = filename.Substring(filename.LastIndexOf("/") + 1);
  54. if (template.EndsWith(".html"))
  55. {
  56. PageUpdateInfo check = GetFirst(m => m.modulePath == template && m.kind == parm.kind);
  57. if (check == null)
  58. {
  59. string ModuleContent = Function.GetNetFileContent(ossConfigs.Host + "template/app/" + parm.kind + "/" + template);
  60. if (!string.IsNullOrEmpty(ModuleContent))
  61. {
  62. string admintitle = "";
  63. string title = "";
  64. Match match = Regex.Match(ModuleContent, "<title>.*?</title>", RegexOptions.IgnoreCase);
  65. if (match.Success)
  66. {
  67. admintitle = match.Value.Replace("<title>", "").Replace("</title>", "");
  68. if (admintitle.Contains("-"))
  69. {
  70. title = admintitle.Substring(admintitle.LastIndexOf("-") + 1);
  71. }
  72. else
  73. {
  74. title = admintitle;
  75. }
  76. }
  77. Add(new PageUpdateInfo()
  78. {
  79. createDate = DateTime.Now,
  80. updateDate = DateTime.Now,
  81. kind = parm.kind,
  82. leftAction1 = "{\"Url\":\"GoBack#{\\\"Level\\\":\\\"1\\\"}\",\"Jump\":\"1\",\"Kind\":\"2\"}",
  83. leftBtn1 = "static/images/left.png",
  84. skidFlag = true,
  85. showScrollBar = false,
  86. title = title,
  87. showTitle = true,
  88. statusBarStyle = "default",
  89. textColor = "FFFFFF",
  90. backgroudColor = "FD7538",
  91. modulePath = template,
  92. moduleVersion = 1,
  93. });
  94. }
  95. }
  96. }
  97. }
  98. }
  99. List<string> SystemFiles;
  100. private void GetSystemFiles(OssConfigs ossConfigs, string Kind = "default")
  101. {
  102. SystemFiles = new List<string>();
  103. var client = new OssClient(ossConfigs.Endpoint, ossConfigs.Key, ossConfigs.Secret);
  104. var listObjectsRequest = new ListObjectsRequest(ossConfigs.BucketName);
  105. listObjectsRequest.MaxKeys = 1000;
  106. listObjectsRequest.Prefix = "template/app/" + Kind + "/";
  107. var result = client.ListObjects(listObjectsRequest);
  108. foreach (var summary in result.ObjectSummaries)
  109. {
  110. SystemFiles.Add(summary.Key);
  111. }
  112. }
  113. /// <summary>
  114. /// 生成APP配置文件
  115. /// </summary>
  116. /// <param name="parm">请求参数</param>
  117. /// <returns>生成APP配置文件</returns>
  118. public string makeAppInitData(string kind)
  119. {
  120. OssConfigs ossConfigs = new();
  121. AppSettings.Bind("OssConfigs", ossConfigs);
  122. string GotoPages = "{";
  123. string PageInfoList = "{";
  124. string LibFile = "{";
  125. List<PageUpdateInfo> newpages = GetList(m => m.kind == kind).OrderBy(m => m.id).ToList();
  126. foreach (PageUpdateInfo page in newpages)
  127. {
  128. string FileName = page.modulePath.Split('.')[0];
  129. var pageinfo = page.Adapt<AppPageInfoVo>();
  130. pageinfo.dataId = Function.MD5_16(pageinfo.id.ToString() + "123890");
  131. PageInfoList += "\"page" + FileName + "\":" + Newtonsoft.Json.JsonConvert.SerializeObject(pageinfo) + ",";
  132. string PagePath = "template/app/" + kind + "/" + page.modulePath;
  133. string pageContent = Function.GetNetFileContent(ossConfigs.Host + PagePath);
  134. pageContent = Dbconn.Encrypt3DES(pageContent, "*ga34|^7");
  135. LibFile += "\"page" + FileName + "\":\"" + pageContent + "\",";
  136. }
  137. PageInfoList = PageInfoList.TrimEnd(',');
  138. PageInfoList += "}";
  139. GotoPages = GotoPages.TrimEnd(',');
  140. GotoPages += "}";
  141. LibFile = LibFile.TrimEnd(',');
  142. LibFile += "}";
  143. return Dbconn.Encrypt3DES(PageInfoList, "*ga34|^7") + "#cut#" + GotoPages + "#cut#" + Dbconn.Encrypt3DES(LibFile, "*ga34|^7");
  144. }
  145. }
  146. }