From 9c722935e021ffc52ff2622c3b65dbc6913cb54f Mon Sep 17 00:00:00 2001 From: zhangxiaofeng Date: Fri, 5 Jan 2024 18:12:27 +0800 Subject: [PATCH] =?UTF-8?q?AFR=E5=AF=B9=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/djy.IService/Afr/IAfrService.cs | 2 +- web/djy.Model/AFR/AFRCntrno.cs | 1 - web/djy.Model/AFR/AFRHouse.cs | 2 - web/djy.Model/AFR/AFRMaster.cs | 1 - web/djy.Service/Afr/AfrService.cs | 86 +++++++++++++------ web/djy_AfrApi/Controllers/AfrController.cs | 6 +- .../Filter/GlobalExceptionsFilter.cs | 11 ++- .../ExceptionHandlerMiddleware.cs | 1 - .../Milldlewares/RequRespLogMiddleware.cs | 1 - .../FolderProfile-Windows.pubxml.user | 2 +- web/djy_AfrApi/djy_AfrApi.csproj | 2 - 11 files changed, 72 insertions(+), 43 deletions(-) diff --git a/web/djy.IService/Afr/IAfrService.cs b/web/djy.IService/Afr/IAfrService.cs index 150e4ed..a07fb43 100644 --- a/web/djy.IService/Afr/IAfrService.cs +++ b/web/djy.IService/Afr/IAfrService.cs @@ -25,6 +25,6 @@ namespace djy.IService.Afr Task Delete(string ids); Task<(bool isSuccess, string message)> Send(string ids, string hids, int sendType); Task SaveReceipt(AFRReceiptDto input); - Task> GetHistory(string mid, string hid); + Task> GetHistory(string pid, string hid); } } diff --git a/web/djy.Model/AFR/AFRCntrno.cs b/web/djy.Model/AFR/AFRCntrno.cs index 872588f..289bd3e 100644 --- a/web/djy.Model/AFR/AFRCntrno.cs +++ b/web/djy.Model/AFR/AFRCntrno.cs @@ -1,6 +1,5 @@ using djy.Model.AFR; using FreeSql.DataAnnotations; -using System; namespace djy.Model.Afr { diff --git a/web/djy.Model/AFR/AFRHouse.cs b/web/djy.Model/AFR/AFRHouse.cs index eece4e3..406161b 100644 --- a/web/djy.Model/AFR/AFRHouse.cs +++ b/web/djy.Model/AFR/AFRHouse.cs @@ -1,7 +1,5 @@ using djy.Model.AFR; using FreeSql.DataAnnotations; -using NetTopologySuite.Geometries.Prepared; -using System; using System.Collections.Generic; namespace djy.Model.Afr diff --git a/web/djy.Model/AFR/AFRMaster.cs b/web/djy.Model/AFR/AFRMaster.cs index 4445bab..ddd573f 100644 --- a/web/djy.Model/AFR/AFRMaster.cs +++ b/web/djy.Model/AFR/AFRMaster.cs @@ -1,5 +1,4 @@ using djy.Model.AFR; -using djy.Model.Ams; using FreeSql.DataAnnotations; using System; using System.Collections.Generic; diff --git a/web/djy.Service/Afr/AfrService.cs b/web/djy.Service/Afr/AfrService.cs index 45a981c..73adc07 100644 --- a/web/djy.Service/Afr/AfrService.cs +++ b/web/djy.Service/Afr/AfrService.cs @@ -1,5 +1,4 @@ -using AutoMapper; -using Common; +using Common; using Common.Const; using Common.DJYModel; using Common.Extensions; @@ -14,24 +13,14 @@ using djy.Model.Ams; using djy.Model.AmsDto; using djy.Service.DjyService; using FreeSql; -using Google.Protobuf.WellKnownTypes; using Microsoft.Extensions.Logging; -using NETCore.Encrypt.Internal; -using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using NPOI.SS.Formula.Functions; -using Org.BouncyCastle.Ocsp; using System; -using System.Collections; using System.Collections.Generic; using System.Data.Common; using System.Linq; -using System.Security.Cryptography; -using System.Security.Policy; -using System.Security.Principal; using System.Text; using System.Threading.Tasks; -using static NPOI.HSSF.Util.HSSFColor; namespace djy.Service.AFR { @@ -224,7 +213,7 @@ namespace djy.Service.AFR .WhereIf(!string.IsNullOrEmpty(input.UserId), (m) => m.UserID == input.UserId) // 下面是前端传来的条件 .WhereIf(!string.IsNullOrEmpty(input.MBLNO), (m) => m.MBLNO.Contains(input.MBLNO)) - .WhereIf(!string.IsNullOrEmpty(input.UserName), (m) => m.UserName.Contains(input.UserName)) + .WhereIf(!string.IsNullOrEmpty(input.UserName), (m) => m.LastUpdateUserName.Contains(input.UserName)) .WhereIf(!string.IsNullOrEmpty(input.DischargeHarbour), (m) => m.DischargeHarbour.Contains(input.DischargeHarbour)) .WhereIf(!string.IsNullOrEmpty(input.ShipCompanyName), (m) => m.ShipCompanyName.Contains(input.ShipCompanyName)) .WhereIf(input.CreateTimeStart != null, (m) => m.CreateTime >= input.CreateTimeStart) @@ -255,7 +244,7 @@ namespace djy.Service.AFR .WhereIf(!string.IsNullOrEmpty(input.UserId), (m, h) => m.UserID == input.UserId) // 下面是前端传来的条件 .WhereIf(!string.IsNullOrEmpty(input.MBLNO), (m, h) => m.MBLNO.Contains(input.MBLNO)) - .WhereIf(!string.IsNullOrEmpty(input.UserName), (m, h) => m.UserName.Contains(input.UserName)) + .WhereIf(!string.IsNullOrEmpty(input.UserName), (m, h) => h.LastUpdateUserName.Contains(input.UserName)) .WhereIf(!string.IsNullOrEmpty(input.DischargeHarbour), (m, h) => m.DischargeHarbour.Contains(input.DischargeHarbour)) .WhereIf(!string.IsNullOrEmpty(input.ShipCompanyName), (m, h) => m.ShipCompanyName.Contains(input.ShipCompanyName)) .WhereIf(input.CreateTimeStart != null, (m, h) => m.CreateTime >= input.CreateTimeStart) @@ -363,6 +352,19 @@ namespace djy.Service.AFR input.CompID = User.CompId; input.CompName = User.CompName; input.CreateTime = nowTime; + input.StateIsSend = false; + + if (await DbAMS.Select().AnyAsync(m => m.MBLNO == input.MBLNO)) + { + throw new Exception("已存在相同的船东提单号"); + } + + var hblNoList = input.HouseList.Select(h => h.HouseBillNo).ToList(); + if (await DbAMS.Select().AnyAsync(h => hblNoList.Contains(h.HouseBillNo))) + { + throw new Exception("已存在相同的货代提单号"); + } + input.HouseList.ForEach(house => { house.GID = Guid.NewGuid().ToString(); @@ -372,6 +374,8 @@ namespace djy.Service.AFR house.CreateTime = nowTime; house.LastUpdate = nowTime; house.MBLNO = input.MBLNO; + house.StateIsAccept = house.StateIsMatched = house.StateIsSend = house.StateIsDelete = false; + house.NewNotice = ""; // 将null换为空对象,避免后续处理null值麻烦 house.CntrList ??= new List(); @@ -387,9 +391,16 @@ namespace djy.Service.AFR await using DbTransaction tran = await GetDbAmsTransaction(); - await DbAMS.Insert(input).ExecuteAffrowsAsync(); - await DbAMS.Insert(input.HouseList).WithTransaction(tran).ExecuteAffrowsAsync(); - await DbAMS.Insert(input.HouseList.SelectMany(h => h.CntrList)).WithTransaction(tran).ExecuteAffrowsAsync(); + await DbAMS.Insert(input) + .ExecuteAffrowsAsync(); + + await DbAMS.Insert(input.HouseList) + .WithTransaction(tran) + .ExecuteAffrowsAsync(); + + await DbAMS.Insert(input.HouseList.SelectMany(h => h.CntrList)) + .WithTransaction(tran) + .ExecuteAffrowsAsync(); await SaveHistoryAsync(input.GID, input.HouseList, "新增", 0, "创建了单据", tran); @@ -398,6 +409,11 @@ namespace djy.Service.AFR // 修改 else { + if (await DbAMS.Select().AnyAsync(m => m.MBLNO == input.MBLNO && m.GID != input.GID)) + { + throw new Exception("已存在相同的船东提单号"); + } + // 下面这段的3个作用: // 1. 将null换为空对象,避免后续处理null值麻烦 // 2. 如果主键为null,说明是新加的数据,这时候需要手动给GID、PID、CreateTime赋值 @@ -408,7 +424,7 @@ namespace djy.Service.AFR } else { - input.HouseList.ForEach(house => + foreach (var house in input.HouseList) { house.LastUpdate = nowTime; house.LastUpdateUserID = User.GID; @@ -419,6 +435,15 @@ namespace djy.Service.AFR house.PID = input.GID; house.CreateTime = nowTime; house.MBLNO = input.MBLNO; + house.StateIsAccept = house.StateIsMatched = house.StateIsSend = house.StateIsDelete = false; + house.NewNotice = ""; + } + else + { + if (await DbAMS.Select().AnyAsync(h => h.HouseBillNo == house.HouseBillNo && h.GID != house.GID)) + { + throw new Exception("已存在相同的货代提单号"); + } } if (house.CntrList == null) @@ -439,7 +464,7 @@ namespace djy.Service.AFR } }); } - }); + } } #region 对分单数据统计出要执行的操作,判断哪些数据是 新增/修改/删除 @@ -683,7 +708,7 @@ namespace djy.Service.AFR if (houseList.Any(h => h.StateIsDelete == false)) { string tip = string.Join("、", houseList.Where(h => h.StateIsDelete == false).Select(h => h.HouseBillNo).ToList()); - throw new Exception($"所选分单中存在未“删除发送”的记录,分单号:【{tip}】,请重新选择(只有“删除发送”成功的,才能进行“重发”操作)"); + throw new Exception($"只有“删除发送”成功的,才能进行“重发”操作,所选分单中存在未“删除发送”的记录,分单号:【{tip}】"); } } // 如果操作类型为“修改”,则待发送记录不能有“已删除”的 @@ -692,7 +717,7 @@ namespace djy.Service.AFR if (houseList.Any(h => h.StateIsDelete)) { string tip = string.Join("、", houseList.Where(h => h.StateIsDelete).Select(h => h.HouseBillNo).ToList()); - throw new Exception($"所选分单中存在已经“删除发送”的记录,分单号:【{tip}】,请重新选择(已“删除发送”的记录需要先进行“重发”,才能进行 “修改发送”或“删除发送” 操作)"); + throw new Exception($"已“删除发送”的记录需要先进行“重发”,才能进行 “修改发送”或“删除发送” 操作,所选分单中存在已经“删除发送”的记录,分单号:【{tip}】"); } } // 记录状态是回执成功的,才可以修改(暂不校验) @@ -836,7 +861,7 @@ namespace djy.Service.AFR if (code2 == "1") { - string tip = $"发送成功!船东提单号:【{masterItem.MBLNO}】货代提单号:【{string.Join("、", houseList.Select(h => h.HouseBillNo))}】{Environment.NewLine}"; + string tip = $"● 发送成功!船东提单号:【{masterItem.MBLNO}】货代提单号:【{string.Join("、", houseList.Select(h => h.HouseBillNo))}】{Environment.NewLine}"; messageBuilder.Append(tip); #region 扣费、保存状态 @@ -921,11 +946,11 @@ namespace djy.Service.AFR string tip; if (houseList == null) { - tip = $"发送失败!船东提单号:【{masterItem.MBLNO}】,原因:{ex.Message}{Environment.NewLine}"; + tip = $"● 发送失败!船东提单号:【{masterItem.MBLNO}】,原因:{ex.Message}{Environment.NewLine}"; } else { - tip = $"发送失败!船东提单号:【{masterItem.MBLNO}】货代提单号:【{string.Join("、", houseList.Select(h => h.HouseBillNo))}】,原因:{ex.Message}{Environment.NewLine}"; + tip = $"● 发送失败!船东提单号:【{masterItem.MBLNO}】货代提单号:【{string.Join("、", houseList.Select(h => h.HouseBillNo))}】,原因:{ex.Message}{Environment.NewLine}"; } messageBuilder.Append(tip); @@ -993,7 +1018,7 @@ namespace djy.Service.AFR if (code2 == "1") { - string tip = $"发送成功!货代提单号:【{string.Join("、", houseAll.Select(h => h.HouseBillNo))}】{Environment.NewLine}"; + string tip = $"● 发送成功!货代提单号:【{string.Join("、", houseAll.Select(h => h.HouseBillNo))}】{Environment.NewLine}"; messageBuilder.Append(tip); #region 扣费、记录历史、保存状态 @@ -1058,7 +1083,7 @@ namespace djy.Service.AFR catch (Exception ex) { // 构建响应 - string tip = $"发送失败!货代提单号:【{string.Join("、", houseAll.Select(h => h.HouseBillNo))}】,原因:{ex.Message}"; + string tip = $"● 发送失败!货代提单号:【{string.Join("、", houseAll.Select(h => h.HouseBillNo))}】,原因:{ex.Message}"; messageBuilder.Append(tip); // 记录历史 @@ -1131,10 +1156,15 @@ namespace djy.Service.AFR return; } - public async Task> GetHistory(string id, string hid) + public async Task> GetHistory(string pid, string hid) { + if (string.IsNullOrWhiteSpace(pid) && string.IsNullOrWhiteSpace(hid)) + { + throw new ArgumentException(nameof(pid) + "或" + nameof(hid)); + } + var data = await DbAMS.Select() - .WhereIf(!string.IsNullOrEmpty(id), h => h.PID == id) + .WhereIf(!string.IsNullOrEmpty(pid), h => h.PID == pid) .WhereIf(!string.IsNullOrEmpty(hid), h => h.HID == hid) .OrderByDescending(h => h.CreateTime) .ToListAsync(); diff --git a/web/djy_AfrApi/Controllers/AfrController.cs b/web/djy_AfrApi/Controllers/AfrController.cs index 48c2e18..d9cdd28 100644 --- a/web/djy_AfrApi/Controllers/AfrController.cs +++ b/web/djy_AfrApi/Controllers/AfrController.cs @@ -133,13 +133,13 @@ namespace djy_AfrApi.Controllers /// /// 获取历史记录 /// - /// 主单主键 + /// 主单主键 /// 分单主键 /// 历史记录列表 [HttpGet("GetHistory")] - public async Task>> GetHistory(string id, string hid) + public async Task>> GetHistory(string pid, string hid) { - var data = await _afrService.GetHistory(id, hid); + var data = await _afrService.GetHistory(pid, hid); return SuccessResp(data); } diff --git a/web/djy_AfrApi/Filter/GlobalExceptionsFilter.cs b/web/djy_AfrApi/Filter/GlobalExceptionsFilter.cs index 5e3a1b0..46bd15c 100644 --- a/web/djy_AfrApi/Filter/GlobalExceptionsFilter.cs +++ b/web/djy_AfrApi/Filter/GlobalExceptionsFilter.cs @@ -24,8 +24,15 @@ namespace djy_AfrApi.Filter var json = new Response { Message = context.Exception.Message,//错误信息 - Code = 500 //500异常 }; + if (context.Exception is ArgumentException) + { + json.Code = 400; + } + else + { + json.Code = 500; + } //if (env.IsDevelopment()) //{ // json.MessageDev = context.Exception.StackTrace;//堆栈信息 @@ -34,7 +41,7 @@ namespace djy_AfrApi.Filter res.Content = JsonConvert.SerializeObject(json); context.Result = res; - + //进行错误日志记录 _logger.LogError(WriteLog($"GlobalExceptionsFilter中捕获的全局异常(TraceIdentifier:{context.HttpContext?.TraceIdentifier})", context.Exception)); } diff --git a/web/djy_AfrApi/Milldlewares/ExceptionHandlerMiddleware.cs b/web/djy_AfrApi/Milldlewares/ExceptionHandlerMiddleware.cs index 3cc3708..bbfbae7 100644 --- a/web/djy_AfrApi/Milldlewares/ExceptionHandlerMiddleware.cs +++ b/web/djy_AfrApi/Milldlewares/ExceptionHandlerMiddleware.cs @@ -1,5 +1,4 @@ using Common.Utilities; -using djy.Model; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using Newtonsoft.Json; diff --git a/web/djy_AfrApi/Milldlewares/RequRespLogMiddleware.cs b/web/djy_AfrApi/Milldlewares/RequRespLogMiddleware.cs index 8cf20a6..b19c0a6 100644 --- a/web/djy_AfrApi/Milldlewares/RequRespLogMiddleware.cs +++ b/web/djy_AfrApi/Milldlewares/RequRespLogMiddleware.cs @@ -1,6 +1,5 @@ using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; -using Newtonsoft.Json; using System; using System.Diagnostics; using System.IO; diff --git a/web/djy_AfrApi/Properties/PublishProfiles/FolderProfile-Windows.pubxml.user b/web/djy_AfrApi/Properties/PublishProfiles/FolderProfile-Windows.pubxml.user index a1bbbcb..f1f60eb 100644 --- a/web/djy_AfrApi/Properties/PublishProfiles/FolderProfile-Windows.pubxml.user +++ b/web/djy_AfrApi/Properties/PublishProfiles/FolderProfile-Windows.pubxml.user @@ -6,7 +6,7 @@ <_PublishTargetUrl>D:\DJY\Code\djyweb_ams\web\djy_AfrApi\bin\Release\net5.0\publish-windows\ - True|2024-01-05T03:59:09.7697688Z;True|2024-01-05T11:33:19.2093394+08:00;True|2024-01-05T11:27:31.2454199+08:00;True|2024-01-05T11:20:20.5464568+08:00;True|2024-01-04T18:36:38.8259124+08:00;True|2024-01-04T15:54:57.9348895+08:00;True|2024-01-04T15:44:34.6535493+08:00;False|2024-01-04T15:44:20.9673752+08:00;True|2024-01-04T11:14:33.4379160+08:00;True|2024-01-03T21:54:40.3579096+08:00;True|2024-01-03T21:52:09.6604718+08:00;True|2024-01-03T16:04:13.6208067+08:00;True|2024-01-03T15:07:08.9376581+08:00;True|2024-01-02T10:57:59.7067270+08:00;True|2024-01-02T10:28:44.8223638+08:00;True|2023-12-29T17:26:12.9612280+08:00; + True|2024-01-05T09:51:52.2695558Z;True|2024-01-05T17:04:21.5306695+08:00;True|2024-01-05T16:48:05.1050469+08:00;True|2024-01-05T15:13:30.4657789+08:00;True|2024-01-05T15:00:49.5985418+08:00;True|2024-01-05T13:48:06.1634940+08:00;True|2024-01-05T11:59:09.7697688+08:00;True|2024-01-05T11:33:19.2093394+08:00;True|2024-01-05T11:27:31.2454199+08:00;True|2024-01-05T11:20:20.5464568+08:00;True|2024-01-04T18:36:38.8259124+08:00;True|2024-01-04T15:54:57.9348895+08:00;True|2024-01-04T15:44:34.6535493+08:00;False|2024-01-04T15:44:20.9673752+08:00;True|2024-01-04T11:14:33.4379160+08:00;True|2024-01-03T21:54:40.3579096+08:00;True|2024-01-03T21:52:09.6604718+08:00;True|2024-01-03T16:04:13.6208067+08:00;True|2024-01-03T15:07:08.9376581+08:00;True|2024-01-02T10:57:59.7067270+08:00;True|2024-01-02T10:28:44.8223638+08:00;True|2023-12-29T17:26:12.9612280+08:00; \ No newline at end of file diff --git a/web/djy_AfrApi/djy_AfrApi.csproj b/web/djy_AfrApi/djy_AfrApi.csproj index 1492708..34cd2cf 100644 --- a/web/djy_AfrApi/djy_AfrApi.csproj +++ b/web/djy_AfrApi/djy_AfrApi.csproj @@ -13,11 +13,9 @@ - -