From ee43cfdab98fb5e9f1b62938195f61503133de99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B5=87=E6=96=87=E9=BE=99?= Date: Thu, 17 Oct 2024 16:54:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E5=85=A5=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Info/Method/ClientContactService.cs | 14 +++--- .../Info/Method/ClientInfoService.cs | 48 +++++++++++++++---- .../Invoice/Method/GeneralInvoiceService.cs | 3 -- .../Invoice/Method/InvoiceService`1.cs | 3 ++ ds-wms-service/DS.WMS.FeeApi/appsettings.json | 2 +- .../Controllers/ClientInfoController.cs | 15 +++--- 6 files changed, 58 insertions(+), 27 deletions(-) diff --git a/ds-wms-service/DS.WMS.Core/Info/Method/ClientContactService.cs b/ds-wms-service/DS.WMS.Core/Info/Method/ClientContactService.cs index 407fd1d7..0e83e5c7 100644 --- a/ds-wms-service/DS.WMS.Core/Info/Method/ClientContactService.cs +++ b/ds-wms-service/DS.WMS.Core/Info/Method/ClientContactService.cs @@ -2,12 +2,10 @@ using System.Text; using DS.Module.Core; using DS.Module.Core.Data; using DS.Module.Core.Extensions; -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 Mapster; -using Masuit.Tools.Models; namespace DS.WMS.Core.Info.Method; @@ -113,7 +111,7 @@ public class ClientContactService : ServiceBase, IClientContactService }).ToListAsync(); StringBuilder sb = new(); - List contacts = new(list.Count * 2); + List contacts = new(list.Count); foreach (var model in list) { var clientList = clients.FindAll(x => x.ShortName == model.CompanyName || x.Description == model.CompanyName); @@ -146,11 +144,11 @@ public class ClientContactService : ServiceBase, IClientContactService } } - if (sb.Length > 0) - { - sb.Remove(0, 1); - return DataResult.Failed("下列【所属公司】匹配不到客户/供应商:" + sb.ToString()); - } + //if (sb.Length > 0) + //{ + // sb.Remove(0, 1); + // return DataResult.Failed("下列【所属公司】匹配不到客户/供应商:" + sb.ToString()); + //} await TenantDb.Ado.BeginTranAsync(); try diff --git a/ds-wms-service/DS.WMS.Core/Info/Method/ClientInfoService.cs b/ds-wms-service/DS.WMS.Core/Info/Method/ClientInfoService.cs index dcdc7646..996cfd8b 100644 --- a/ds-wms-service/DS.WMS.Core/Info/Method/ClientInfoService.cs +++ b/ds-wms-service/DS.WMS.Core/Info/Method/ClientInfoService.cs @@ -260,6 +260,20 @@ public class ClientInfoService : ServiceBase, IClientInfoService { long userId = long.Parse(User.UserId); DateTime dtNow = DateTime.Now; + TenantDb.QueryFilter.Clear(); + TenantDb.QueryFilter.Clear(); + + var clientNames1 = list.Select(x => x.ShortName).Distinct(); + var clientNames2 = list.Select(x => x.CNName).Distinct(); + var clients = await TenantDb.Queryable().Where(x => clientNames1.Contains(x.ShortName) || clientNames2.Contains(x.Description)) + .Select(x => new InfoClient + { + Id = x.Id, + ShortName = x.ShortName, + Description = x.Description, + IsCustomer = x.IsCustomer, + IsSupplier = x.IsSupplier + }).ToListAsync(); var attrbutes = list.SelectMany(x => x.AttributeNames).Where(x => !string.IsNullOrEmpty(x)).Distinct(); var dicList = await Db.Queryable().InnerJoin((d, t) => d.TypeId == t.Id) @@ -284,10 +298,21 @@ public class ClientInfoService : ServiceBase, IClientInfoService x.DefaultOrgId }).ToListAsync(); - List clients = new List(list.Count); + List newClients = new(list.Count); + List existClients = []; foreach (var model in list) { - InfoClient client = new() + InfoClient? client = clients.Find(x => x.ShortName == model.ShortName && x.Description == model.CNName); + if (client != null) + { + client.IsCustomer = model.IsCustomer; + client.IsSupplier = model.IsSupplier; + //client.Note = "系统导入"; + existClients.Add(client); + continue; + } + + client = new() { Address = model.Address, AuditStatus = model.StatusText == "认证" ? AuditStatusEnum.Approve : AuditStatusEnum.NoAudit, @@ -324,7 +349,7 @@ public class ClientInfoService : ServiceBase, IClientInfoService var dicValue = item.Value.ToUpperCamelCase(); PropertyExtensions.SetPropertyValue(client.ClientTag, dicValue, true); } - + client.AccountDates.Add(new InfoClientAccountDate { AccountType = model.StlType, @@ -336,15 +361,18 @@ public class ClientInfoService : ServiceBase, IClientInfoService CreateTime = dtNow, }); - clients.Add(client); + newClients.Add(client); } await TenantDb.Ado.BeginTranAsync(); try { - await TenantDb.Fastest().RemoveDataCache($"{SqlSugarCacheConst.InfoClient}{User.TenantId}").BulkMergeAsync(clients); - foreach (var client in clients) + if (existClients.Count > 0) + await TenantDb.Updateable(existClients).UpdateColumns(x => new { x.IsCustomer, x.IsSupplier }).ExecuteCommandAsync(); + + await TenantDb.Fastest().RemoveDataCache($"{SqlSugarCacheConst.InfoClient}{User.TenantId}").BulkMergeAsync(newClients); + foreach (var client in newClients) { client.ClientTag.ClientId = client.Id; @@ -352,14 +380,16 @@ public class ClientInfoService : ServiceBase, IClientInfoService item.ClientId = client.Id; } - var tags = clients.Select(x => x.ClientTag).ToList(); + var tags = newClients.Select(x => x.ClientTag).ToList(); await TenantDb.Fastest().BulkMergeAsync(tags); - var accountDates = clients.SelectMany(x => x.AccountDates).ToList(); + var accountDates = newClients.SelectMany(x => x.AccountDates).ToList(); await TenantDb.Fastest().BulkMergeAsync(accountDates); await TenantDb.Ado.CommitTranAsync(); - return DataResult.Success; + var result = DataResult.Success; + result.Message = $"新增往来单位:{newClients.Count}项,更新往来单位:{existClients}项"; + return result; } catch (Exception ex) { diff --git a/ds-wms-service/DS.WMS.Core/Invoice/Method/GeneralInvoiceService.cs b/ds-wms-service/DS.WMS.Core/Invoice/Method/GeneralInvoiceService.cs index 680a549b..7b7231ea 100644 --- a/ds-wms-service/DS.WMS.Core/Invoice/Method/GeneralInvoiceService.cs +++ b/ds-wms-service/DS.WMS.Core/Invoice/Method/GeneralInvoiceService.cs @@ -35,9 +35,6 @@ namespace DS.WMS.Core.Invoice.Method SqlFunc.Subqueryable().Where(d => d.ApplicationId == a.Id && d.Category == DetailCategory.InvoiceApplication && (d.OriginalAmount - d.OriginalProcessedAmount) != 0).Any()) .Select(a => new InvoiceApplicationDto { - //Currency = SqlFunc.IsNullOrEmpty(a.Currency) ? SqlFunc.Subqueryable().Where( - // d => d.ApplicationId == a.Id && d.Category == DetailCategory.InvoiceApplication).SelectStringJoin(d => d.Currency, ",") - // : a.Currency, AmountRMB = SqlFunc.Subqueryable().Where(y => a.Id == y.ApplicationId && y.Currency == FeeCurrency.RMB_CODE).Sum(y => y.ApplyAmount), AmountUSD = SqlFunc.Subqueryable().Where(y => a.Id == y.ApplicationId && y.Currency == FeeCurrency.USD_CODE).Sum(y => y.ApplyAmount), AmountOther = SqlFunc.Subqueryable().Where(y => a.Id == y.ApplicationId && y.Currency != FeeCurrency.RMB_CODE && y.Currency != FeeCurrency.USD_CODE).Sum(y => y.ApplyAmount), diff --git a/ds-wms-service/DS.WMS.Core/Invoice/Method/InvoiceService`1.cs b/ds-wms-service/DS.WMS.Core/Invoice/Method/InvoiceService`1.cs index 934eaeb2..bcd7fcde 100644 --- a/ds-wms-service/DS.WMS.Core/Invoice/Method/InvoiceService`1.cs +++ b/ds-wms-service/DS.WMS.Core/Invoice/Method/InvoiceService`1.cs @@ -576,6 +576,9 @@ namespace DS.WMS.Core.Invoice.Method if (details.Count == 0) return DataResult.Success; + if (invoiceAmount == 0) + return DataResult.Failed("开票金额不能为零"); + var totalRMB = details.Sum(x => x.ApplyAmount); if (Math.Abs(invoiceAmount) > totalRMB) return DataResult.Failed("申请开票金额不能大于剩余开票金额"); diff --git a/ds-wms-service/DS.WMS.FeeApi/appsettings.json b/ds-wms-service/DS.WMS.FeeApi/appsettings.json index 28cf42f4..c9c87f78 100644 --- a/ds-wms-service/DS.WMS.FeeApi/appsettings.json +++ b/ds-wms-service/DS.WMS.FeeApi/appsettings.json @@ -68,7 +68,7 @@ "GenerateFeesUrl": "/feeApi/FeeCustTemplate/GenerateFees" }, "HangfireSettings": { - "DbString": "server=rm-m5e06xxqpa68a68ry5o.mysql.rds.aliyuncs.com;port=3306;uid=rulesengine_admin;pwd=Rule1qaz2wsx!QAZ;database=shippingweb8_hangfire;Allow User Variables=true", + "DbString": "server=rm-m5e06xxqpa68a68ry5o.mysql.rds.aliyuncs.com;port=3306;uid=rulesengine_admin;pwd=Rule1qaz2wsx!QAZ;database=shippingweb8_hangfire2;Allow User Variables=true", "WorkerCount": 10, "ServerName": "FeeApi", "Queues": "fee" diff --git a/ds-wms-service/DS.WMS.MainApi/Controllers/ClientInfoController.cs b/ds-wms-service/DS.WMS.MainApi/Controllers/ClientInfoController.cs index 2ce271aa..401f614c 100644 --- a/ds-wms-service/DS.WMS.MainApi/Controllers/ClientInfoController.cs +++ b/ds-wms-service/DS.WMS.MainApi/Controllers/ClientInfoController.cs @@ -223,9 +223,9 @@ public class ClientInfoController : ApiController AgreementTerm = item["E"] == null ? null : DateTime.Parse(item["E"].ToString()), StatusText = item["F"]?.ToString(), Address = item["G"]?.ToString(), - CNName = item["H"]?.ToString(), - ENName = item["I"]?.ToString(), - ShortName = item["J"]?.ToString(), + CNName = item["H"]?.ToString()?.Trim(), + ENName = item["I"]?.ToString()?.Trim(), + ShortName = item["J"]?.ToString()?.Trim(), TaxID = item["K"]?.ToString(), Code = item["L"]?.ToString(), StlType = item["M"]?.ToString(), @@ -295,9 +295,9 @@ public class ClientInfoController : ApiController AgreementTerm = item["C"] == null ? null : DateTime.Parse(item["C"].ToString()), StatusText = item["D"]?.ToString(), Address = item["E"]?.ToString(), - CNName = item["F"]?.ToString(), - ENName = item["G"]?.ToString(), - ShortName = item["H"]?.ToString(), + CNName = item["F"]?.ToString()?.Trim(), + ENName = item["G"]?.ToString()?.Trim(), + ShortName = item["H"]?.ToString()?.Trim(), TaxID = item["I"]?.ToString(), Code = item["J"]?.ToString(), StlType = item["K"]?.ToString(), @@ -374,6 +374,9 @@ public class ClientInfoController : ApiController IsDefault = int.TryParse(item["P"]?.ToString(), out int value3) && value3 == 1, }; + if (string.IsNullOrEmpty(model.CompanyName)) + model.CompanyName = model.InvoiceHeader; + if (string.IsNullOrEmpty(model.CompanyName)) sb.Append($"行号:{rows.IndexOf(item) + 2} 未填写【公司名称】");