Infrastructure/OpenAuth.App/ServiceApp/Achievement/InsTifApp.cs

89 lines
2.7 KiB
C#
Raw Normal View History

using Infrastructure;
using Infrastructure.Helpers;
using OpenAuth.App.BaseApp.Base;
using OpenAuth.App.Interface;
2024-11-14 14:41:13 +08:00
using OpenAuth.App.ServiceApp.Achievement.Request;
using OpenAuth.Repository;
using OpenAuth.Repository.Domain;
using SqlSugar;
namespace OpenAuth.App.ServiceApp.Achievement;
public class InsTifApp : SqlSugarBaseApp<InsTif, SugarDbContext>
{
public InsTifApp(ISugarUnitOfWork<SugarDbContext> unitWork, ISimpleClient<InsTif> repository,
IAuth auth) : base(unitWork, repository, auth)
{
}
2024-11-14 14:41:13 +08:00
public async Task<PageInfo<List<InsTif>>> Load(InsTifQuery req)
{
RefAsync<int> total = 0;
var result = await Repository.AsQueryable()
.ToPageListAsync(req.page, req.limit, total);
return new PageInfo<List<InsTif>>
{
Items = result,
Total = total
};
}
public async Task<InsTif> GetTif(string id)
{
return await Repository.GetByIdAsync(id);
}
public async Task<Response<bool>> 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<bool>
{
Result = true
};
}
public async Task<Response<bool>> Insert(IEnumerable<InsTifInsert> req)
{
var tifList = req.MapToList<InsTif>();
foreach (var tif in tifList)
{
tif.Id = Guid.NewGuid().ToString();
tif.CreateTime = DateTime.Now;
tif.UpdateTime = DateTime.Now;
}
await Repository.InsertRangeAsync(tifList);
return new Response<bool>
{
Result = true
};
}
}