FileUpdateInfoService.cs 3.6 KB

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