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; using Common; namespace Services { /// /// 资源文件更新信息Service业务层处理 /// [AppService(ServiceType = typeof(IFileUpdateInfoService), ServiceLifetime = LifeTime.Transient)] public class FileUpdateInfoService : BaseService, IFileUpdateInfoService { /// /// 资源文件更新信息-列表 /// /// 请求参数 /// 资源文件更新信息列表 public PagedInfo List([FromQuery] FileUpdateInfoListDto parm, [FromQuery] PagerInfo page) { //开始拼装查询条件 var predicate = Expressionable.Create(); predicate = predicate.And(m => m.appVersion == parm.appVersion); predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.kind), m => m.kind.Contains(parm.kind)); var response = Queryable() .Where(predicate.ToExpression()) .OrderByDescending(m => m.id) .ToPage(page); return response; } /// /// 资源文件更新信息-更新文件 /// /// 请求参数 /// 资源文件更新信息更新文件 public void UpdateFile([FromQuery] FileUpdateInfoUpdateFileDto parm) { OssConfigs ossConfigs = new(); AppSettings.Bind("OssConfigs", ossConfigs); string kind = parm.kind; if(!string.IsNullOrEmpty(parm.appVersion)) { kind += "/" + parm.appVersion; } GetSystemFiles(ossConfigs, 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 && m.appVersion == parm.appVersion); if (check == null) { Add(new FileUpdateInfo() { createDate = DateTime.Now, updateDate = DateTime.Now, fileName = template, path = Path, versionNum = 0, kind = parm.kind, appVersion = Function.CheckNull(parm.appVersion), }); } } } } 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); } } /// /// 生成APP配置文件 /// /// 请求参数 /// 生成APP配置文件 public string makeAppInitData(string kind, string appVersion = "") { FileUpdateInfoListDto parm = new FileUpdateInfoListDto(); parm.kind = kind; parm.appVersion = appVersion; PagerInfo page = new PagerInfo(); page.pageSize = 100000; var obj = List(parm, page); string str = Newtonsoft.Json.JsonConvert.SerializeObject(obj.Records); return Dbconn.Encrypt3DES(str, "*ga34|^7"); } } }