|
|
|
using DS.Module.Core;
|
|
|
|
using DS.Module.Core.Constants;
|
|
|
|
using DS.Module.Core.Data;
|
|
|
|
using DS.Module.Core.Extensions;
|
|
|
|
using DS.WMS.Core.Check.Entity;
|
|
|
|
using DS.WMS.Core.Fee.Entity;
|
|
|
|
using DS.WMS.Core.Info.Dtos;
|
|
|
|
using DS.WMS.Core.Info.Entity;
|
|
|
|
using DS.WMS.Core.Info.Interface;
|
|
|
|
using DS.WMS.Core.Op.Entity;
|
|
|
|
using DS.WMS.Core.Sys.Entity;
|
|
|
|
using Mapster;
|
|
|
|
|
|
|
|
namespace DS.WMS.Core.Info.Method;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 往来单位服务
|
|
|
|
/// </summary>
|
|
|
|
public class ClientInfoService : ServiceBase, IClientInfoService
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
///
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="serviceProvider"></param>
|
|
|
|
public ClientInfoService(IServiceProvider serviceProvider) : base(serviceProvider)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 列表
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="request"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public DataResult<List<ClientInfoRes>> GetListByPage(PageRequest request)
|
|
|
|
{
|
|
|
|
long orgId = User.OrgId;
|
|
|
|
//序列化查询条件
|
|
|
|
var whereList = request.GetConditionalModels(Db);
|
|
|
|
var result = TenantDb.Queryable<InfoClient>()
|
|
|
|
.Where(x => x.OrgId == orgId || x.IsShared)
|
|
|
|
.Where(whereList)
|
|
|
|
.Select<ClientInfoRes>().ToQueryPage(request.PageCondition);
|
|
|
|
|
|
|
|
if (result.Data?.Count > 0)
|
|
|
|
{
|
|
|
|
var ids = result.Data.SelectMany(x => x.SaleOrgIdList).Distinct();
|
|
|
|
var orgs = Db.Queryable<SysOrg>().Where(x => ids.Contains(x.Id)).Select(x => new { x.Id, x.OrgName }).ToList();
|
|
|
|
|
|
|
|
foreach (var item in result.Data)
|
|
|
|
{
|
|
|
|
var list = orgs.FindAll(x => item.SaleOrgIdList.Contains(x.Id));
|
|
|
|
item.SaleOrgNames = string.Join(",", list.Select(x => x.OrgName));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 编辑
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="req"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public DataResult EditClientInfo(ClientInfoReq req)
|
|
|
|
{
|
|
|
|
if (req.Id == 0)
|
|
|
|
{
|
|
|
|
if (TenantDb.Queryable<InfoClient>().Where(x =>( x.ShortName == req.ShortName.Trim() || x.Description == req.Description.Trim() || x.TaxNo == req.TaxNo.Trim())).Any())
|
|
|
|
{
|
|
|
|
return DataResult.Failed("客户信息已存在,请检查客户全称、简称或社会信用代码是否重复!", MultiLanguageConst.ClientInfoExist);
|
|
|
|
}
|
|
|
|
|
|
|
|
var data = req.Adapt<InfoClient>();
|
|
|
|
var tag = req.ClientTag.Adapt<InfoClientTag>();
|
|
|
|
//助记码
|
|
|
|
data.CodeName = PinYinUtil.GetFristLetter(req.ShortName);
|
|
|
|
|
|
|
|
var entity = TenantDb.InsertNav(data).Include(x => x.InvoiceHeaders).ExecuteReturnEntity();
|
|
|
|
tag.ClientId = entity.Id;
|
|
|
|
TenantDb.Insertable(tag).RemoveDataCache($"{SqlSugarCacheConst.InfoClient}{User.TenantId}").ExecuteCommand();
|
|
|
|
return DataResult.Successed("添加成功!", entity.Id, MultiLanguageConst.DataCreateSuccess);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var info = TenantDb.Queryable<InfoClient>().Where(x => x.Id == req.Id).First();
|
|
|
|
var tag = TenantDb.Queryable<InfoClientTag>().Where(x => x.ClientId == req.Id).First();
|
|
|
|
|
|
|
|
info = req.Adapt(info);
|
|
|
|
|
|
|
|
if (TenantDb.Queryable<InfoClient>().Where(x => x.Id!= info.Id && (x.ShortName == req.ShortName.Trim() || x.Description == req.Description.Trim() || x.TaxNo == req.TaxNo.Trim())).Any())
|
|
|
|
{
|
|
|
|
return DataResult.Failed("请检查客户全称、简称或社会信用代码是否重复!", MultiLanguageConst.ClientInfoExist);
|
|
|
|
}
|
|
|
|
//助记码
|
|
|
|
info.CodeName = PinYinUtil.GetFristLetter(info.ShortName);
|
|
|
|
tag = req.ClientTag.Adapt(tag);
|
|
|
|
|
|
|
|
TenantDb.Updateable(info).RemoveDataCache($"{SqlSugarCacheConst.InfoClient}{User.TenantId}").IgnoreColumns(ignoreAllNullColumns: true).EnableDiffLogEvent().ExecuteCommand();
|
|
|
|
TenantDb.Updateable(tag).IgnoreColumns(ignoreAllNullColumns: true).EnableDiffLogEvent().ExecuteCommand();
|
|
|
|
|
|
|
|
//创建或更新发票抬头
|
|
|
|
if (req.InvoiceHeaders?.Count > 0)
|
|
|
|
TenantDb.Storageable(req.InvoiceHeaders).DefaultAddElseUpdate().ExecuteCommand();
|
|
|
|
|
|
|
|
return DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 详情
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="id"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public DataResult<ClientInfoRes> GetClientInfo(string id)
|
|
|
|
{
|
|
|
|
var data = TenantDb.Queryable<InfoClient>()
|
|
|
|
.Where(a => a.Id == long.Parse(id))
|
|
|
|
.Select<ClientInfoRes>()
|
|
|
|
.First();
|
|
|
|
if (data == null)
|
|
|
|
return DataResult<ClientInfoRes>.Success(data);
|
|
|
|
|
|
|
|
var tag = TenantDb.Queryable<InfoClientTag>().Select<ClientTagRes>()
|
|
|
|
.First(a => a.ClientId == long.Parse(id));
|
|
|
|
data.ClientTag = tag;
|
|
|
|
|
|
|
|
data.InvoiceHeaders ??= TenantDb.Queryable<InvoiceHeader>().Where(x => x.RelativeId == data.Id).ToList();
|
|
|
|
|
|
|
|
return DataResult<ClientInfoRes>.Success(data, MultiLanguageConst.DataQuerySuccess);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 批量删除发票抬头
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="idModel"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public async Task<DataResult> DeleteInvoiceHeaderAsync(IdModel idModel)
|
|
|
|
{
|
|
|
|
int rows = await TenantDb.Deleteable<InvoiceHeader>().Where(x => idModel.Ids.Contains(x.Id)).ExecuteCommandAsync();
|
|
|
|
return rows > 0 ? DataResult.Success : DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 批量删除
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="req"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public async Task<DataResult> DeleteAsync(IdModel req)
|
|
|
|
{
|
|
|
|
await TenantDb.Ado.BeginTranAsync();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (TenantDb.Queryable<SeaExport>().Where(x => req.Ids.Contains((long)x.ShipperId)).Any())
|
|
|
|
return DataResult.Failed("存在海运出口使用的发货人信息!");
|
|
|
|
if (TenantDb.Queryable<SeaExport>().Where(x => req.Ids.Contains((long)x.ConsigneeId)).Any())
|
|
|
|
return DataResult.Failed("存在海运出口使用的收货人信息!");
|
|
|
|
if (TenantDb.Queryable<SeaExport>().Where(x => req.Ids.Contains((long)x.NotifyPartyId)).Any())
|
|
|
|
return DataResult.Failed("存在海运出口使用的通知人信息!");
|
|
|
|
|
|
|
|
if (TenantDb.Queryable<SeaExport>().Where(x => req.Ids.Contains(x.AgentId)).Any())
|
|
|
|
return DataResult.Failed("存在海运出口使用的国外代理人信息!");
|
|
|
|
if (TenantDb.Queryable<SeaExport>().Where(x => req.Ids.Contains(x.ShipAgencyId)).Any())
|
|
|
|
return DataResult.Failed("存在海运出口使用的船代I信息!");
|
|
|
|
if (TenantDb.Queryable<SeaExport>().Where(x => req.Ids.Contains(x.CustomerId)).Any())
|
|
|
|
return DataResult.Failed("存在海运出口使用的委托单位信息!");
|
|
|
|
if (TenantDb.Queryable<SeaExport>().Where(x => req.Ids.Contains(x.YardId)).Any())
|
|
|
|
return DataResult.Failed("存在海运出口使用的场站信息!");
|
|
|
|
if (TenantDb.Queryable<SeaExport>().Where(x => req.Ids.Contains(x.CarrierId)).Any())
|
|
|
|
return DataResult.Failed("存在海运出口使用的船公司信息!");
|
|
|
|
if (TenantDb.Queryable<SeaExport>().Where(x => req.Ids.Contains(x.ForwarderId)).Any())
|
|
|
|
return DataResult.Failed("存在海运出口使用的货代公司信息!");
|
|
|
|
if (TenantDb.Queryable<SeaExport>().Where(x => req.Ids.Contains(x.CustomserId)).Any())
|
|
|
|
return DataResult.Failed("存在海运出口使用的报关行信息!");
|
|
|
|
if (TenantDb.Queryable<SeaExport>().Where(x => req.Ids.Contains(x.TruckerId)).Any())
|
|
|
|
return DataResult.Failed("存在海运出口使用的承运车队信息!");
|
|
|
|
if (TenantDb.Queryable<SeaExport>().Where(x => req.Ids.Contains(x.WareHouseId)).Any())
|
|
|
|
return DataResult.Failed("存在海运出口使用的仓库信息!");
|
|
|
|
|
|
|
|
if (TenantDb.Queryable<FeeRecord>().Where(x => req.Ids.Contains(x.CustomerId)).Any())
|
|
|
|
return DataResult.Failed("存在费用记录使用的费用对象信息!");
|
|
|
|
if (TenantDb.Queryable<CheckBill>().Where(x => req.Ids.Contains(x.CustomerId)).Any())
|
|
|
|
return DataResult.Failed("存在客户对账使用的对账客户信息!");
|
|
|
|
|
|
|
|
if (TenantDb.Queryable<CheckBillAuto>().Where(x => req.Ids.Contains(x.CustomerId)).Any())
|
|
|
|
return DataResult.Failed("存在自动对账使用的对账客户信息!");
|
|
|
|
|
|
|
|
//银行信息
|
|
|
|
await TenantDb.Deleteable<InfoClientBank>().Where(x => req.Ids.Contains(x.ClientId)).ExecuteCommandAsync();
|
|
|
|
//联系人
|
|
|
|
await TenantDb.Deleteable<InfoClientContact>().Where(x => req.Ids.Contains(x.ClientId)).ExecuteCommandAsync();
|
|
|
|
//合同信息
|
|
|
|
await TenantDb.Deleteable<InfoClientContract>().Where(x => req.Ids.Contains(x.ClientId)).ExecuteCommandAsync();
|
|
|
|
//账期
|
|
|
|
await TenantDb.Deleteable<InfoClientAccountDate>().Where(x => req.Ids.Contains(x.ClientId)).ExecuteCommandAsync();
|
|
|
|
//收发货人
|
|
|
|
await TenantDb.Deleteable<InfoClientShipper>().Where(x => req.Ids.Contains(x.ClientId)).ExecuteCommandAsync();
|
|
|
|
//删除客户信息
|
|
|
|
await TenantDb.Deleteable<InfoClient>().RemoveDataCache($"{SqlSugarCacheConst.InfoClient}{User.TenantId}").Where(x => req.Ids.Contains(x.Id)).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
await TenantDb.Ado.CommitTranAsync();
|
|
|
|
return DataResult.Success;
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
await TenantDb.Ado.RollbackTranAsync();
|
|
|
|
await ex.LogAsync(Db);
|
|
|
|
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///// <summary>
|
|
|
|
///// 客户合并
|
|
|
|
///// </summary>
|
|
|
|
///// <param name="request"></param>
|
|
|
|
///// <returns></returns>
|
|
|
|
//public async Task<DataResult> MergeAsync(ClientMergeRequest request)
|
|
|
|
//{
|
|
|
|
// await TenantDb.Ado.BeginTranAsync();
|
|
|
|
// try
|
|
|
|
// {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// await TenantDb.Ado.CommitTranAsync();
|
|
|
|
// return DataResult.Success;
|
|
|
|
// }
|
|
|
|
// catch (Exception ex)
|
|
|
|
// {
|
|
|
|
// await TenantDb.Ado.RollbackTranAsync();
|
|
|
|
// await ex.LogAsync(Db);
|
|
|
|
// return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
#region 获取往来单位详情(含有联系人列表)
|
|
|
|
/// <summary>
|
|
|
|
/// 获取往来单位详情(含有联系人列表)
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="query">查询往来单位</param>
|
|
|
|
/// <returns>返回往来单位详情</returns>
|
|
|
|
public async Task<DataResult<ClientInfoRes>> GetClientInfoWithContact(QueryClientInfo query)
|
|
|
|
{
|
|
|
|
var data = await TenantDb.Queryable<InfoClient>().InnerJoin<InfoClientTag>((c, t) => c.Id == t.ClientId)
|
|
|
|
.Where((c, t) => c.Id == query.ClientId)
|
|
|
|
.WhereIF(query.IsController, (c, t) => t.IsController.HasValue && t.IsController.HasValue)
|
|
|
|
.WhereIF(query.IsCarrier, (c, t) => t.IsCarrier.HasValue && t.IsCarrier.HasValue)
|
|
|
|
.WhereIF(query.IsBooking, (c, t) => t.IsBooking.HasValue && t.IsBooking.HasValue)
|
|
|
|
.WhereIF(query.IsYard, (c, t) => t.IsYard.HasValue && t.IsYard.HasValue)
|
|
|
|
.WhereIF(query.IsTruck, (c, t) => t.IsTruck.HasValue && t.IsTruck.HasValue)
|
|
|
|
.WhereIF(query.IsController, (c, t) => t.IsController.HasValue && t.IsController.HasValue)
|
|
|
|
.WhereIF(query.IsCustom, (c, t) => t.IsCustom.HasValue && t.IsCustom.HasValue)
|
|
|
|
.WhereIF(query.IsAgent, (c, t) => t.IsAgent.HasValue && t.IsAgent.HasValue)
|
|
|
|
.WhereIF(query.IsAgentCn, (c, t) => t.IsAgentCn.HasValue && t.IsAgentCn.HasValue)
|
|
|
|
.WhereIF(query.IsExpress, (c, t) => t.IsExpress.HasValue && t.IsExpress.HasValue)
|
|
|
|
.WhereIF(query.IsAirLines, (c, t) => t.IsAirLines.HasValue && t.IsAirLines.HasValue)
|
|
|
|
.WhereIF(query.IsShipper, (c, t) => t.IsShipper.HasValue && t.IsShipper.HasValue)
|
|
|
|
.WhereIF(query.IsConsignee, (c, t) => t.IsConsignee.HasValue && t.IsConsignee.HasValue)
|
|
|
|
.WhereIF(query.IsNotifyParty, (c, t) => t.IsNotifyParty.HasValue && t.IsNotifyParty.HasValue)
|
|
|
|
.WhereIF(query.IsWareHouse, (c, t) => t.IsWareHouse.HasValue && t.IsWareHouse.HasValue)
|
|
|
|
.WhereIF(query.IsWharf, (c, t) => t.IsWharf.HasValue && t.IsWharf.HasValue)
|
|
|
|
.WhereIF(query.IsInsurer, (c, t) => t.IsInsurer.HasValue && t.IsInsurer.HasValue)
|
|
|
|
.WhereIF(query.IsLeasing, (c, t) => t.IsLeasing.HasValue && t.IsLeasing.HasValue)
|
|
|
|
.WhereIF(query.IsTradingAgency, (c, t) => t.IsTradingAgency.HasValue && t.IsTradingAgency.HasValue)
|
|
|
|
.WhereIF(query.IsOther, (c, t) => t.IsOther.HasValue && t.IsOther.HasValue)
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(query.Others), (c, t) => t.Others == query.Others)
|
|
|
|
.WhereIF(query.IsShipAgency, (c, t) => t.IsShipAgency.HasValue && t.IsShipAgency.HasValue)
|
|
|
|
.WhereIF(query.IsEnterprise, (c, t) => t.IsEnterprise.HasValue && t.IsEnterprise.HasValue)
|
|
|
|
|
|
|
|
.Select((c, t) => new { Client = c, tag = t })
|
|
|
|
.FirstAsync();
|
|
|
|
|
|
|
|
var clientInfo = data.Client.Adapt<ClientInfoRes>();
|
|
|
|
|
|
|
|
clientInfo.ClientTag = data.tag.Adapt<ClientTagRes>();
|
|
|
|
|
|
|
|
var contactList = TenantDb.Queryable<InfoClientContact>()
|
|
|
|
.Where(a => a.ClientId == clientInfo.Id && a.Status == StatusEnum.Enable).ToList();
|
|
|
|
|
|
|
|
if (contactList.Count > 0)
|
|
|
|
clientInfo.ClientContactList = contactList.Adapt<List<ClientContactRes>>();
|
|
|
|
|
|
|
|
if (clientInfo == null)
|
|
|
|
return DataResult<ClientInfoRes>.FailedData(clientInfo);
|
|
|
|
|
|
|
|
return DataResult<ClientInfoRes>.Success(clientInfo);
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|