using Attribute; using Dto; using Vo; using Model; using Model.Base; using Repository; using Service; using Microsoft.AspNetCore.Mvc; using Aliyun.OSS; using Infrastructure.Model; using Base; namespace Services { /// /// 资源文件更新信息Service业务层处理 /// [AppService(ServiceType = typeof(IFileUpdateInfoService), ServiceLifetime = LifeTime.Transient)] public class FileUpdateInfoService : BaseService, IFileUpdateInfoService { /// /// 资源文件更新信息-列表 /// /// 请求参数 /// 资源文件更新信息列表 public PagedInfo List([FromQuery] FileUpdateInfoListDto parm) { //开始拼装查询条件 var predicate = Expressionable.Create(); predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.kind), m => m.kind.Contains(parm.kind)); var response = Queryable() .Where(predicate.ToExpression()) .OrderByDescending(m => m.id) .ToPage(new PagerInfo()); return response; } /// /// 资源文件更新信息-更新文件 /// /// 请求参数 /// 资源文件更新信息更新文件 public void UpdateFile([FromQuery] FileUpdateInfoUpdateFileDto parm) { OssConfigs ossConfigs = new(); AppSettings.Bind("OssConfigs", ossConfigs); GetSystemFiles(ossConfigs, parm.kind); foreach (string filename in SystemFiles) { string Path = filename.Substring(0, filename.LastIndexOf("/") + 1); string template = filename.Substring(filename.LastIndexOf("/") + 1); if (!template.EndsWith(".html") && !template.EndsWith(".DS_Store") && !template.EndsWith("LICENSE") && !template.EndsWith("Thumbs.db")) { FileUpdateInfo check = GetFirst(m => m.path == Path && m.fileName == template && m.kind == parm.kind); if (check == null) { Add(new FileUpdateInfo() { createDate = DateTime.Now, updateDate = DateTime.Now, fileName = template, path = Path, versionNum = 0, kind = parm.kind, }); } } } } List SystemFiles; private void GetSystemFiles(OssConfigs ossConfigs, string Kind = "default") { SystemFiles = new List(); var client = new OssClient(ossConfigs.Endpoint, ossConfigs.Key, ossConfigs.Secret); var listObjectsRequest = new ListObjectsRequest(ossConfigs.BucketName); listObjectsRequest.MaxKeys = 1000; listObjectsRequest.Prefix = "skin/app/" + Kind + "/"; var result = client.ListObjects(listObjectsRequest); foreach (var summary in result.ObjectSummaries.Where(m => m.Size > 0).ToList()) { string path = summary.Key.Substring(summary.Key.IndexOf(listObjectsRequest.Prefix) + listObjectsRequest.Prefix.Length).Replace("\\", "/"); SystemFiles.Add(path); } } } }