You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ds8-solution-pro/ds-wms-service/DS.WMS.Core/Op/Method/ShippingBillPartCtnService.cs

128 lines
4.8 KiB
C#

using DS.Module.Core;
using DS.Module.Core.Data;
using DS.Module.Core.Extensions;
using DS.Module.SqlSugar;
using DS.Module.UserModule;
using DS.WMS.Core.Fee.Entity;
using DS.WMS.Core.Op.Dtos;
using DS.WMS.Core.Op.Entity;
using DS.WMS.Core.Op.Interface;
using Mapster;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
namespace DS.WMS.Core.Op.Method
{
public class ShippingBillPartCtnService : IShippingBillPartCtnService
{
private readonly IServiceProvider _serviceProvider;
private readonly ISqlSugarClient db;
private readonly IUser user;
private readonly ISaasDbService saasService;
/// <summary>
///
/// </summary>
/// <param name="serviceProvider"></param>
public ShippingBillPartCtnService(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
user = _serviceProvider.GetRequiredService<IUser>();
saasService = _serviceProvider.GetRequiredService<ISaasDbService>();
}
/// <summary>
/// 列表
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public DataResult<List<ShippingBillPartCtnRes>> GetListByPage(PageRequest request)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
//序列化查询条件
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
var data = tenantDb.Queryable<SeaExportShippingBillPartCtn>()
.Where(whereList)
.Select<ShippingBillPartCtnRes>().ToQueryPage(request.PageCondition);
return data;
}
/// <summary>
/// 批量删除
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
public DataResult BatchDelShippingBillPartCtn(IdModel req)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
var list = tenantDb.Queryable<SeaExportShippingBillPartCtn>().Where(x => req.Ids.Contains(x.Id)).ToList();
if (list.Count > 0)
{
tenantDb.Deleteable(list).ExecuteCommand();
}
return DataResult.Successed("删除成功!", MultiLanguageConst.DataDelSuccess);
}
/// <summary>
/// 舱单分票编辑
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public DataResult EditShippingBillPartCtn(ShippingBillPartCtnMainReq req)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
var info = tenantDb.Queryable<SeaExport>().Where(x => x.Id == req.BusinessId).First();
if (info.IsNull())
{
return DataResult.Failed("不存在的海运出口信息!", MultiLanguageConst.SeaExportExist);
}
if (req.PartList.Count > 0)
{
var ctnList = tenantDb.Queryable<SeaExportShippingBillPartCtn>().Where(x => x.Pid == req.BusinessId).ToList();
var ctns = tenantDb.Queryable<OpCtn>().Where(x => x.BSNO == req.BusinessId.ToString()).ToList();
if (req.PartList.Sum(x => x.PKGS) > ctns.Sum(x => x.PKGS))
{
return DataResult.Failed("舱单分票件数合计超出限制!", MultiLanguageConst.SeaExportPartCtnPKGSLimit);
}
if (req.PartList.Sum(x => x.KGS) > ctns.Sum(x => x.KGS))
{
return DataResult.Failed("舱单分票重量合计超出限制!", MultiLanguageConst.SeaExportPartCtnKGSLimit);
}
if (req.PartList.Sum(x => x.CBM) > ctns.Sum(x => x.CBM))
{
return DataResult.Failed("舱单分票尺码合计超出限制!", MultiLanguageConst.SeaExportPartCtnCBMLimit);
}
foreach (var item in req.PartList)
{
if (item.Id == 0)
{
var ctn = item.Adapt<SeaExportShippingBillPartCtn>();
ctn.Pid = info.Id;
tenantDb.Insertable(ctn).ExecuteCommand();
}
else
{
var ctn = ctnList.First(x => x.Id == item.Id);
ctn = item.Adapt(ctn);
tenantDb.Updateable(ctn).ExecuteCommand();
}
}
}
else
{
}
return DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess);
}
}
}