AFR对接

master
zhangxiaofeng 11 months ago
parent a2f65a89d2
commit 9c722935e0

@ -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<List<AFRMasterHistory>> GetHistory(string mid, string hid);
Task<List<AFRMasterHistory>> GetHistory(string pid, string hid);
}
}

@ -1,6 +1,5 @@
using djy.Model.AFR;
using FreeSql.DataAnnotations;
using System;
namespace djy.Model.Afr
{

@ -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

@ -1,5 +1,4 @@
using djy.Model.AFR;
using djy.Model.Ams;
using FreeSql.DataAnnotations;
using System;
using System.Collections.Generic;

@ -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<AFRMaster>().AnyAsync(m => m.MBLNO == input.MBLNO))
{
throw new Exception("已存在相同的船东提单号");
}
var hblNoList = input.HouseList.Select(h => h.HouseBillNo).ToList();
if (await DbAMS.Select<AFRHouse>().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<AFRCntrno>();
@ -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<AFRMaster>().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<AFRHouse>().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<List<AFRMasterHistory>> GetHistory(string id, string hid)
public async Task<List<AFRMasterHistory>> GetHistory(string pid, string hid)
{
if (string.IsNullOrWhiteSpace(pid) && string.IsNullOrWhiteSpace(hid))
{
throw new ArgumentException(nameof(pid) + "或" + nameof(hid));
}
var data = await DbAMS.Select<AFRMasterHistory>()
.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();

@ -133,13 +133,13 @@ namespace djy_AfrApi.Controllers
/// <summary>
/// 获取历史记录
/// </summary>
/// <param name="id">主单主键</param>
/// <param name="pid">主单主键</param>
/// <param name="hid">分单主键</param>
/// <returns>历史记录列表</returns>
[HttpGet("GetHistory")]
public async Task<Response<List<AFRMasterHistory>>> GetHistory(string id, string hid)
public async Task<Response<List<AFRMasterHistory>>> GetHistory(string pid, string hid)
{
var data = await _afrService.GetHistory(id, hid);
var data = await _afrService.GetHistory(pid, hid);
return SuccessResp(data);
}

@ -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;//堆栈信息

@ -1,5 +1,4 @@
using Common.Utilities;
using djy.Model;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;

@ -1,6 +1,5 @@
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System;
using System.Diagnostics;
using System.IO;

@ -6,7 +6,7 @@
<Project>
<PropertyGroup>
<_PublishTargetUrl>D:\DJY\Code\djyweb_ams\web\djy_AfrApi\bin\Release\net5.0\publish-windows\</_PublishTargetUrl>
<History>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;</History>
<History>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;</History>
<LastFailureDetails />
</PropertyGroup>
</Project>

@ -13,11 +13,9 @@
<ItemGroup>
<PackageReference Include="FreeRedis" Version="1.2.11" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.17" />
<PackageReference Include="NLog.Database" Version="5.2.7" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
<PackageReference Include="NLog.Web.AspNetCore" Version="5.3.7" />
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
</ItemGroup>
<ItemGroup>

Loading…
Cancel
Save