using Infrastructure; using Infrastructure.Helpers; using OpenAuth.App.BaseApp.Base; using OpenAuth.App.Interface; using OpenAuth.App.ServiceApp.Achievement.Request; using OpenAuth.Repository; using OpenAuth.Repository.Domain; using SqlSugar; namespace OpenAuth.App.ServiceApp.Achievement; public class InsTifApp : SqlSugarBaseApp { public InsTifApp(ISugarUnitOfWork unitWork, ISimpleClient repository, IAuth auth) : base(unitWork, repository, auth) { } public async Task>> Load(InsTifQuery req) { RefAsync total = 0; var result = await Repository.AsQueryable() .ToPageListAsync(req.page, req.limit, total); return new PageInfo> { Items = result, Total = total }; } public async Task GetTif(string id) { return await Repository.GetByIdAsync(id); } public async Task> Update() { var tifDir = ConfigHelper.GetConfigRoot().GetSection("Insight:TifDir").Value; var files = Directory.GetFiles(tifDir, "*.tif", SearchOption.AllDirectories); foreach (var tifFile in files) { var tifName = Path.GetFileName(tifFile); var tifDate = new DirectoryInfo(tifFile).Parent?.Name; if (string.IsNullOrEmpty(tifDate)) { throw new Exception("获取不到日期目录"); } var areaName = new DirectoryInfo(tifFile).Parent?.Parent?.Name; var currentTime = DateTime.Now; var tifRecord = new InsTif { Id = Guid.NewGuid().ToString(), TifName = tifName, TifPath = tifFile, Remark = "备注", TifDate = DateTime.ParseExact(tifDate, "yyyy年MM月", null), CreateTime = currentTime, UpdateTime = currentTime, AreaName = areaName, PlotName = "地块", AreaId = "areaid", AreaNum = Convert.ToDecimal(0) }; await Repository.InsertAsync(tifRecord); } return new Response { Result = true }; } public async Task> Insert(IEnumerable req) { var tifList = req.MapToList(); var removeList = new List(); foreach (var tif in tifList) { if (await Repository.CountAsync(a => a.TifPath == tif.TifPath) > 0) { removeList.Add(tif); } tif.Id = Guid.NewGuid().ToString(); tif.CreateTime = DateTime.Now; tif.UpdateTime = DateTime.Now; } tifList.RemoveAll(a => removeList.Contains(a)); await Repository.InsertRangeAsync(tifList); return new Response { Result = true }; } }