1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- 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
- {
- /// <summary>
- /// 资源文件更新信息Service业务层处理
- /// </summary>
- [AppService(ServiceType = typeof(IFileUpdateInfoService), ServiceLifetime = LifeTime.Transient)]
- public class FileUpdateInfoService : BaseService<FileUpdateInfo>, IFileUpdateInfoService
- {
- /// <summary>
- /// 资源文件更新信息-列表
- /// </summary>
- /// <param name="parm">请求参数</param>
- /// <returns>资源文件更新信息列表</returns>
- public PagedInfo<FileUpdateInfoListVo> List([FromQuery] FileUpdateInfoListDto parm)
- {
- //开始拼装查询条件
- var predicate = Expressionable.Create<FileUpdateInfo>();
- predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.kind), m => m.kind.Contains(parm.kind));
- var response = Queryable()
- .Where(predicate.ToExpression())
- .OrderByDescending(m => m.id)
- .ToPage<FileUpdateInfo, FileUpdateInfoListVo>(new PagerInfo());
- return response;
- }
- /// <summary>
- /// 资源文件更新信息-更新文件
- /// </summary>
- /// <param name="parm">请求参数</param>
- /// <returns>资源文件更新信息更新文件</returns>
- 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<string> SystemFiles;
- private void GetSystemFiles(OssConfigs ossConfigs, string Kind = "default")
- {
- SystemFiles = new List<string>();
- 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);
- }
- }
- }
- }
|