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;
///
///
///
///
public ShippingBillPartCtnService(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
db = _serviceProvider.GetRequiredService();
user = _serviceProvider.GetRequiredService();
saasService = _serviceProvider.GetRequiredService();
}
///
/// 列表
///
///
///
public DataResult> GetListByPage(PageRequest request)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
//序列化查询条件
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
var data = tenantDb.Queryable()
.Where(whereList)
.Select().ToQueryPage(request.PageCondition);
return data;
}
///
/// 批量删除
///
///
///
public DataResult BatchDelShippingBillPartCtn(IdModel req)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
var list = tenantDb.Queryable().Where(x => req.Ids.Contains(x.Id)).ToList();
if (list.Count > 0)
{
tenantDb.Deleteable(list).ExecuteCommand();
}
return DataResult.Successed("删除成功!", MultiLanguageConst.DataDelSuccess);
}
///
/// 舱单分票编辑
///
///
///
///
public DataResult EditShippingBillPartCtn(ShippingBillPartCtnMainReq req)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
var info = tenantDb.Queryable().Where(x => x.Id == req.BusinessId).First();
if (info.IsNull())
{
return DataResult.Failed("不存在的海运出口信息!", MultiLanguageConst.SeaExportExist);
}
if (req.PartList.Count > 0)
{
var ctnList = tenantDb.Queryable().Where(x => x.Pid == req.BusinessId).ToList();
var ctns = tenantDb.Queryable().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();
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);
}
}
}