FileUpdateInfoService.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 Infrastructure.Model;
  11. using Base;
  12. using Common;
  13. namespace Services
  14. {
  15. /// <summary>
  16. /// 资源文件更新信息Service业务层处理
  17. /// </summary>
  18. [AppService(ServiceType = typeof(IFileUpdateInfoService), ServiceLifetime = LifeTime.Transient)]
  19. public class FileUpdateInfoService : BaseService<FileUpdateInfo>, IFileUpdateInfoService
  20. {
  21. /// <summary>
  22. /// 资源文件更新信息-列表
  23. /// </summary>
  24. /// <param name="parm">请求参数</param>
  25. /// <returns>资源文件更新信息列表</returns>
  26. public PagedInfo<FileUpdateInfoListVo> List([FromQuery] FileUpdateInfoListDto parm, [FromQuery] PagerInfo page)
  27. {
  28. //开始拼装查询条件
  29. var predicate = Expressionable.Create<FileUpdateInfo>();
  30. predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.kind), m => m.kind.Contains(parm.kind));
  31. var response = Queryable()
  32. .Where(predicate.ToExpression())
  33. .OrderByDescending(m => m.id)
  34. .ToPage<FileUpdateInfo, FileUpdateInfoListVo>(page);
  35. return response;
  36. }
  37. /// <summary>
  38. /// 资源文件更新信息-更新文件
  39. /// </summary>
  40. /// <param name="parm">请求参数</param>
  41. /// <returns>资源文件更新信息更新文件</returns>
  42. public void UpdateFile([FromQuery] FileUpdateInfoUpdateFileDto parm)
  43. {
  44. OssConfigs ossConfigs = new();
  45. AppSettings.Bind("OssConfigs", ossConfigs);
  46. GetSystemFiles(ossConfigs, parm.kind);
  47. foreach (string filename in SystemFiles)
  48. {
  49. string Path = filename.Substring(0, filename.LastIndexOf("/") + 1);
  50. string template = filename.Substring(filename.LastIndexOf("/") + 1);
  51. if (!template.EndsWith(".html") && !template.EndsWith(".DS_Store") && !template.EndsWith("LICENSE") && !template.EndsWith("Thumbs.db"))
  52. {
  53. FileUpdateInfo check = GetFirst(m => m.path == Path && m.fileName == template && m.kind == parm.kind);
  54. if (check == null)
  55. {
  56. Add(new FileUpdateInfo()
  57. {
  58. createDate = DateTime.Now,
  59. updateDate = DateTime.Now,
  60. fileName = template,
  61. path = Path,
  62. versionNum = 0,
  63. kind = parm.kind,
  64. });
  65. }
  66. }
  67. }
  68. }
  69. List<string> SystemFiles;
  70. private void GetSystemFiles(OssConfigs ossConfigs, string Kind = "default")
  71. {
  72. SystemFiles = new List<string>();
  73. var client = new OssClient(ossConfigs.Endpoint, ossConfigs.Key, ossConfigs.Secret);
  74. var listObjectsRequest = new ListObjectsRequest(ossConfigs.BucketName);
  75. listObjectsRequest.MaxKeys = 1000;
  76. listObjectsRequest.Prefix = "skin/app/" + Kind + "/";
  77. var result = client.ListObjects(listObjectsRequest);
  78. foreach (var summary in result.ObjectSummaries.Where(m => m.Size > 0).ToList())
  79. {
  80. string path = summary.Key.Substring(summary.Key.IndexOf(listObjectsRequest.Prefix) + listObjectsRequest.Prefix.Length).Replace("\\", "/");
  81. SystemFiles.Add(path);
  82. }
  83. }
  84. /// <summary>
  85. /// 生成APP配置文件
  86. /// </summary>
  87. /// <param name="parm">请求参数</param>
  88. /// <returns>生成APP配置文件</returns>
  89. public string makeAppInitData(string kind)
  90. {
  91. FileUpdateInfoListDto parm = new FileUpdateInfoListDto();
  92. parm.kind = kind;
  93. PagerInfo page = new PagerInfo();
  94. page.pageSize = 100000;
  95. var obj = List(parm, page);
  96. string str = Newtonsoft.Json.JsonConvert.SerializeObject(obj.Records);
  97. return Dbconn.Encrypt3DES(str, "*ga34|^7");
  98. }
  99. }
  100. }