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