using Myshipping.Core; using Furion.DependencyInjection; using Furion.DynamicApiController; using Mapster; using Microsoft.AspNetCore.Mvc; using SqlSugar; using System.Linq; using System.Threading.Tasks; using Myshipping.Core.Entity; using Microsoft.Extensions.Logging; using Furion.FriendlyException; using System; namespace Myshipping.Core.Service { /// /// 租户航线维护 /// [ApiDescriptionSettings(Name = "DjyTenantLine", Order = 1)] public class DjyTenantLineService : IDjyTenantLineService, IDynamicApiController, ITransient { private readonly SqlSugarRepository _rep; private readonly ISysCacheService _cache; private readonly ILogger _logger; public DjyTenantLineService(SqlSugarRepository rep, ISysCacheService cache, ILogger logger) { _rep = rep; _cache = cache; _logger = logger; } /// /// 分页查询网站账号维护 /// /// /// [HttpGet("/DjyTenantLine/page")] public async Task Page([FromQuery] QueryDjyTenantLineInput input) { var entities = await _rep.AsQueryable() .Where(m => m.TenantId == UserManager.TENANT_ID) .WhereIF(!string.IsNullOrWhiteSpace(input.LineCode), u => u.LineCode.Contains(input.LineCode.Trim())) .WhereIF(!string.IsNullOrWhiteSpace(input.LineName), u => u.LineName.Contains(input.LineName.Trim())) .ToPagedListAsync(input.PageNo, input.PageSize); return entities.XnPagedResult(); } /// /// 保存租户航线 /// /// /// [HttpPost("/DjyTenantLine/save")] public async Task Save(SaveDjyTenantLineInput input) { var lineLine = await _cache.GetAllCodeLane(); var cc = _rep.Count(x => x.LineName == input.LineName); if (lineLine.Count(x => x.CnName == input.LineName) > 0 || cc > 0) { throw Oops.Bah($"已存在同名航线:{input.LineName}"); } DjyTenantLine model = null; if (input.Id > 0) { model = _rep.FirstOrDefault(x => x.Id == input.Id); input.Adapt(model); await _rep.UpdateAsync(model); } else { model = input.Adapt(); await _rep.InsertAsync(model); } return model.Id; } /// /// 删除租户航线 /// /// /// [HttpPost("/DjyTenantLine/delete")] public async Task Delete(long id) { var entity = await _rep.FirstOrDefaultAsync(u => u.Id == id); await _rep.DeleteAsync(entity); } /// /// 查询当前租户航线列表 /// /// /// [HttpGet("/DjyTenantLine/list")] public async Task List([FromQuery] ListDjyTenantLineInput input) { var sysLines = await _cache.GetAllCodeLane(); var entities = await _rep.AsQueryable() .Where(m => m.TenantId == UserManager.TENANT_ID) .WhereIF(!string.IsNullOrWhiteSpace(input.LineName), u => u.LineName.Contains(input.LineName.Trim())) .Select(x => x.LineName) .ToListAsync(); var result = sysLines.Select(x => x.CnName).ToList(); result.AddRange(entities); return result; } } }