PageUpdateInfoService.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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, [FromQuery] PagerInfo page)
  29. {
  30. //开始拼装查询条件
  31. var predicate = Expressionable.Create<PageUpdateInfo>();
  32. predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.kind), m => m.kind.Contains(parm.kind));
  33. predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.title), m => m.title.Contains(parm.title));
  34. predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.modulePath), m => m.modulePath.Contains(parm.modulePath));
  35. var response = Queryable()
  36. .Where(predicate.ToExpression())
  37. .OrderBy(m => m.id)
  38. .ToPage<PageUpdateInfo, PageUpdateInfoListVo>(page);
  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. var item = GetFirst(m => m.modulePath == template);
  78. if(item == null)
  79. {
  80. Add(new PageUpdateInfo()
  81. {
  82. createDate = DateTime.Now,
  83. updateDate = DateTime.Now,
  84. kind = parm.kind,
  85. leftAction1 = "{\"Url\":\"GoBack#{\\\"Level\\\":\\\"1\\\"}\",\"Jump\":\"1\",\"Kind\":\"2\"}",
  86. leftBtn1 = "static/images/left.png",
  87. skidFlag = true,
  88. showScrollBar = false,
  89. title = title,
  90. showTitle = true,
  91. statusBarStyle = "default",
  92. textColor = "333333",
  93. backgroudColor = "FFFFFF",
  94. modulePath = template,
  95. moduleVersion = 1,
  96. mustUpdate = true,
  97. });
  98. }
  99. else
  100. {
  101. item.updateDate = DateTime.Now;
  102. item.title = title;
  103. Update(item, true);
  104. }
  105. }
  106. }
  107. }
  108. }
  109. }
  110. List<string> SystemFiles;
  111. private void GetSystemFiles(OssConfigs ossConfigs, string Kind = "default")
  112. {
  113. SystemFiles = new List<string>();
  114. var client = new OssClient(ossConfigs.Endpoint, ossConfigs.Key, ossConfigs.Secret);
  115. var listObjectsRequest = new ListObjectsRequest(ossConfigs.BucketName);
  116. listObjectsRequest.MaxKeys = 1000;
  117. listObjectsRequest.Prefix = "template/app/" + Kind + "/";
  118. var result = client.ListObjects(listObjectsRequest);
  119. foreach (var summary in result.ObjectSummaries)
  120. {
  121. SystemFiles.Add(summary.Key);
  122. }
  123. }
  124. /// <summary>
  125. /// 生成APP配置文件
  126. /// </summary>
  127. /// <param name="parm">请求参数</param>
  128. /// <returns>生成APP配置文件</returns>
  129. public string makeAppInitData(string kind)
  130. {
  131. OssConfigs ossConfigs = new();
  132. AppSettings.Bind("OssConfigs", ossConfigs);
  133. string GotoPages = "{";
  134. string PageInfoList = "{";
  135. string LibFile = "{";
  136. List<PageUpdateInfo> newpages = GetList(m => m.kind == kind);
  137. foreach (PageUpdateInfo page in newpages)
  138. {
  139. string FileName = page.modulePath.Split('.')[0];
  140. var pageinfo = page.Adapt<AppPageInfoVo>();
  141. pageinfo.dataId = Function.MD5_16(pageinfo.id.ToString() + "123890");
  142. PageInfoList += "\"page" + FileName + "\":" + Newtonsoft.Json.JsonConvert.SerializeObject(pageinfo) + ",";
  143. string PagePath = "template/app/" + kind + "/" + page.modulePath;
  144. string pageContent = Function.GetNetFileContent(ossConfigs.Host + PagePath);
  145. pageContent = Dbconn.Encrypt3DES(pageContent, "*ga34|^7");
  146. LibFile += "\"page" + FileName + "\":\"" + pageContent + "\",";
  147. }
  148. PageInfoList = PageInfoList.TrimEnd(',');
  149. PageInfoList += "}";
  150. GotoPages = GotoPages.TrimEnd(',');
  151. GotoPages += "}";
  152. LibFile = LibFile.TrimEnd(',');
  153. LibFile += "}";
  154. return Dbconn.Encrypt3DES(PageInfoList, "*ga34|^7") + "#cut#" + GotoPages + "#cut#" + Dbconn.Encrypt3DES(LibFile, "*ga34|^7");
  155. }
  156. }
  157. }