using Infrastructure; using Microsoft.Extensions.Options; using OpenAuth.App.BaseApp.Base; using OpenAuth.App.Interface; using OpenAuth.App.ServiceApp.ShpGeo.Request; using OpenAuth.App.ServiceApp.ShpGeo.Utils; using OpenAuth.Repository; using OpenAuth.Repository.Domain; using SqlSugar; namespace OpenAuth.App.ServiceApp.ShpGeo; public class GeoStyleApp : SqlSugarBaseApp { private readonly string _filePath; public GeoStyleApp(ISugarUnitOfWork unitWork, ISimpleClient repository, IAuth auth, IOptions setOptions) : base(unitWork, repository, auth) { _filePath = setOptions.Value.UploadPath; if (string.IsNullOrEmpty(_filePath)) { _filePath = AppContext.BaseDirectory; } } public Response Add(GeoStyleReq geoStyle) { // 校验sytleName是否已经存在 var isExists = Repository.AsQueryable().Any(c => c.StyleName.Equals(geoStyle.StyleName)); if (isExists) { return new Response { Result = false, Message = "样式名已存在" }; } var record = geoStyle.MapTo(); record.CreateDate = DateTime.Now; var sldPath = Path.Combine(_filePath, geoStyle.SldPath); var response = GeoUtil.PublishSldStyle(sldPath, geoStyle.StyleName).Result; if (!response) { return new Response { Result = false, Message = "样式发布失败" }; } record.Id = Guid.NewGuid().ToString(); var result = Repository.InsertAsync(record).Result; return new Response { Result = result }; } public async Task>>> Page(GeoStylePageReq req) { // 分页查询 RefAsync totalCount = 0; var result = Repository.AsQueryable() .WhereIF(!string.IsNullOrEmpty(req.Title), a => a.Title.Contains(req.Title)) .WhereIF(!string.IsNullOrEmpty(req.StyleName), a => a.StyleName.Contains(req.StyleName)) .ToPageListAsync(req.page, req.limit, totalCount); return new Response>> { Result = new PageInfo> { Items = await result, Total = totalCount } }; } public Response BindLayer(string layerName, string styleId) { var geoStyle = Repository.AsQueryable().Where(a => a.Id == styleId).First(); if (geoStyle == null) { return new Response { Result = false, Message = "样式不存在" }; } var sldPath = Path.Combine(_filePath, geoStyle.SldPath); var result = GeoUtil.UpdateSldStyle(sldPath, layerName).Result; return new Response { Result = result }; } }