|
|
|
|
using Furion.DependencyInjection;
|
|
|
|
|
using Furion.DynamicApiController;
|
|
|
|
|
using Furion.FriendlyException;
|
|
|
|
|
using Mapster;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Myshipping.Application.Entity;
|
|
|
|
|
using Myshipping.Application.Service.BookingLabel.Dto;
|
|
|
|
|
using Myshipping.Core;
|
|
|
|
|
using Myshipping.Core.Service;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Myshipping.Application
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 订舱标签服务
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ApiDescriptionSettings("Application", Name = "BookingLabel", Order = 1)]
|
|
|
|
|
public class BookingLabelService : IBookingLabelService, IDynamicApiController, ITransient
|
|
|
|
|
{
|
|
|
|
|
private readonly SqlSugarRepository<BookingLabel> _rep;
|
|
|
|
|
private readonly SqlSugarRepository<BookingLabelAllocation> _repAllocation;
|
|
|
|
|
|
|
|
|
|
private readonly ISysCacheService _cache;
|
|
|
|
|
public BookingLabelService(SqlSugarRepository<BookingLabel> rep,
|
|
|
|
|
ISysCacheService cache,
|
|
|
|
|
SqlSugarRepository<BookingLabelAllocation> repAllocation)
|
|
|
|
|
{
|
|
|
|
|
_rep = rep;
|
|
|
|
|
_cache = cache;
|
|
|
|
|
_repAllocation = repAllocation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 为舱位分配标签
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("/BookingLabel/Bind")]
|
|
|
|
|
public async Task SetLabel(BindLabelDto input)
|
|
|
|
|
{
|
|
|
|
|
if (input.BusinessIdArray?.Any() != true)
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Oh("请检查参数");
|
|
|
|
|
}
|
|
|
|
|
_rep.CurrentBeginTran();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await _repAllocation.DeleteAsync(x => input.BusinessIdArray.Contains(x.BusinessId));
|
|
|
|
|
|
|
|
|
|
if (input.LabelIdArray != null && input.LabelIdArray.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
List<BookingLabelAllocation> list = new();
|
|
|
|
|
foreach (var item in input.LabelIdArray)
|
|
|
|
|
{
|
|
|
|
|
foreach (var businessId in input.BusinessIdArray)
|
|
|
|
|
{
|
|
|
|
|
list.Add(new BookingLabelAllocation
|
|
|
|
|
{
|
|
|
|
|
LabelId = item,
|
|
|
|
|
BusinessId = businessId,
|
|
|
|
|
//TenantId = UserManager.TENANT_ID
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
await _repAllocation.InsertAsync(list);
|
|
|
|
|
}
|
|
|
|
|
_rep.CurrentCommitTran();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
_rep.CurrentRollbackTran();
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取全部或指定范围类型的标签列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="scope">标签使用范围 空-全部 1-舱位管理台账</param>
|
|
|
|
|
[HttpGet("/BookingLabel/List")]
|
|
|
|
|
public async Task<List<BookingLabelBaseDto>> List(int? scope)
|
|
|
|
|
{
|
|
|
|
|
List<BookingLabelBaseDto> cacheList = await _cache.GetAsync<List<BookingLabelBaseDto>>(CommonConst.CACHE_KEY_BOOKING_LABEL + ":" + UserManager.TENANT_ID);
|
|
|
|
|
if (cacheList?.Any() != true)
|
|
|
|
|
{
|
|
|
|
|
cacheList = await Cache();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var result = scope == null
|
|
|
|
|
? cacheList
|
|
|
|
|
: cacheList.Where(x => x.Scope == scope).ToList();
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 分页获取全部或指定范围类型的标签列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpPost("/BookingLabel/PageList")]
|
|
|
|
|
public async Task<SqlSugarPagedList<BookingLabelBaseDto>> PageList(BookingLabelPageListInput input)
|
|
|
|
|
{
|
|
|
|
|
var list = await _rep.AsQueryable()
|
|
|
|
|
.WhereIF(!string.IsNullOrEmpty(input.Name), x => x.Name.Contains(input.Name))
|
|
|
|
|
.WhereIF(input.Scope != null, x => x.Scope == input.Scope)
|
|
|
|
|
.ToPagedListAsync(input.PageNo, input.PageSize);
|
|
|
|
|
|
|
|
|
|
var result = list.Adapt<SqlSugarPagedList<BookingLabelBaseDto>>();
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 新增或修改标签信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpPost("/BookingLabel/Save")]
|
|
|
|
|
public async Task<long> Save(BookingLabelBaseDto input)
|
|
|
|
|
{
|
|
|
|
|
var model = input.Adapt<BookingLabel>();
|
|
|
|
|
if (input.Id is null or 0)
|
|
|
|
|
{
|
|
|
|
|
await _rep.InsertAsync(model);
|
|
|
|
|
await Cache();
|
|
|
|
|
return model.Id;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var oldModel = await _rep.FirstOrDefaultAsync(x => x.Id == input.Id);
|
|
|
|
|
if (oldModel != null)
|
|
|
|
|
{
|
|
|
|
|
input.Adapt(oldModel);
|
|
|
|
|
await _rep.UpdateAsync(oldModel);
|
|
|
|
|
await Cache();
|
|
|
|
|
}
|
|
|
|
|
return (long)input.Id;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除标签信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpPost("/BookingLabel/Delete")]
|
|
|
|
|
public async Task Delete([FromBody] long[] ids)
|
|
|
|
|
{
|
|
|
|
|
if (ids != null && ids.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
await _rep.DeleteAsync(x => ids.Contains(x.Id));
|
|
|
|
|
await Cache();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[NonAction]
|
|
|
|
|
private async Task<List<BookingLabelBaseDto>> Cache()
|
|
|
|
|
{
|
|
|
|
|
var list = await _rep.AsQueryable().Filter(null,true).Where(a=>a.TenantId == UserManager.TENANT_ID).ToListAsync();
|
|
|
|
|
var cacheList = list.Adapt<List<BookingLabelBaseDto>>();
|
|
|
|
|
|
|
|
|
|
await _cache.SetTimeoutAsync(CommonConst.CACHE_KEY_BOOKING_LABEL + ":" + UserManager.TENANT_ID, cacheList, TimeSpan.FromDays(3));
|
|
|
|
|
return cacheList;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|