海运出口日志

usertest
cjy 4 months ago
parent 8fda46315e
commit b554bde49b

@ -0,0 +1,63 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DS.WMS.Core.Op.Dtos
{
public class OpBusinessLogRes
{
/// <summary>
/// 主键Id
/// </summary>
public long Id { get; set; }
/// <summary>
/// 业务id
/// </summary>
public long? BusinessId { get; set; }
/// <summary>
/// 操作方式:新增(Create)、更新(Update)、删除(Delete)
/// </summary>
public string OperateType { get; set; }
/// <summary>
/// 旧值
/// </summary>
public string OldValue { get; set; }
/// <summary>
/// 新值
/// </summary>
public string NewValue { get; set; }
/// <summary>
/// 差异数据
/// </summary>
public string DiffData { get; set; }
/// <summary>
/// 业务来源代码
/// </summary>
public string SourceCode { get; set; }
/// <summary>
/// 业务来源
/// </summary>
public string SourceName { get; set; }
/// <summary>
/// 创建时间
/// </summary>
[Description("创建时间")]
public DateTime CreateTime { get; set; }
/// <summary>
/// 创建人名称
/// </summary>
[Description("创建人名称")]
public string CreateUserName { get; set; }
}
}

@ -19,7 +19,7 @@ namespace DS.WMS.Core.Op.Interface
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
public Task SaveSeaExportLog(SeaExportSaveLog req);
public Task SaveSeaExportLogAsync(SeaExportSaveLog req, SqlSugarScopeProvider tenantDb);
/// <summary>
/// 获取第三方账户
/// </summary>

@ -43,7 +43,7 @@ public interface ISeaExportService
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
DataResult SeaExportBatchEdit(SeaExportBatchEditReq req);
Task<DataResult> SeaExportBatchEdit(SeaExportBatchEditReq req);
/// <summary>
/// 业务单据删除
@ -219,4 +219,11 @@ public interface ISeaExportService
/// <param name="id"></param>
/// <returns></returns>
public Task<DataResult> PrintShippingOrderLetterPDF(string id);
/// <summary>
/// 获取海运出口日志
/// </summary>
/// <param name="id">业务Id</param>
/// <returns></returns>
public Task<DataResult<List<OpBusinessLogRes>>> GetSeaExportLogList(string id);
}

@ -366,6 +366,7 @@ namespace DS.WMS.Core.Op.Method
if (config.IsNotNull() && config.Value == "YES")
{
var order = await tenantDb.Queryable<SeaExport>().Where(x => x.Id == businessId && x.MBLNO == item.MBLNO).FirstAsync();
var oldOrder = order.Adapt<SeaExport>();
if (item.Status == "ATD")
{
//2023-8-31排查单号为177GZHZHQ5711V的数据原来录入的船已开船运踪港前不再查询而因订阅港后数据会继续回推数据所以导致ATD被改
@ -377,12 +378,20 @@ namespace DS.WMS.Core.Op.Method
if (order != null && item.OpTime != null && order.ATD != item.OpTime)
{
order.ATD = item.OpTime;
order.Note = "运踪回调更新ATD";
//order.Note = "运踪回调更新ATD";
await tenantDb.Updateable(order).UpdateColumns(x => new
{
x.ATD,
x.Note
x.ATD
}).EnableDiffLogEvent().ExecuteCommandAsync();
// 记录日志
await seaComService.SaveSeaExportLogAsync(new SeaExportSaveLog()
{
OperateType = "Update",
OldOrder = oldOrder,
NewOrder = order,
SourceCode = "TraceUpdteATD",
SourceName = "运踪回调更新ATD",
}, tenantDb);
//sendDsList.Add(item.BookingId);
//await _bookingorderservice.SaveLog(newOrder, oldOrder, "运踪更新船期");
}
@ -416,11 +425,20 @@ namespace DS.WMS.Core.Op.Method
if (order != null && item.OpTime != null && order.YgtETD != item.OpTime)
{
order.YgtETD = item.OpTime;
order.Note = "运踪回调更新YgtETD";
//order.Note = "运踪回调更新YgtETD";
await tenantDb.Updateable(order).UpdateColumns(x => new
{
x.YgtETD,x.Note
}).EnableDiffLogEvent().ExecuteCommandAsync();
// 记录日志
await seaComService.SaveSeaExportLogAsync(new SeaExportSaveLog()
{
OperateType = "Update",
OldOrder = oldOrder,
NewOrder = order,
SourceCode = "TraceUpdteYgtETD",
SourceName = "运踪回调更新YgtETD",
}, tenantDb);
//await _bookingorderservice.SaveLog(newOrder, oldOrder, "运踪更新船期");
}
}
@ -429,11 +447,20 @@ namespace DS.WMS.Core.Op.Method
if (order != null && item.OpTime != null && order.StartATA != item.OpTime)
{
order.StartATA = item.OpTime;
order.Note = "运踪回调更新StartATA";
//order.Note = "运踪回调更新StartATA";
await tenantDb.Updateable(order).UpdateColumns(x => new
{
x.StartATA, x.Note
x.StartATA
}).EnableDiffLogEvent().ExecuteCommandAsync();
// 记录日志
await seaComService.SaveSeaExportLogAsync(new SeaExportSaveLog()
{
OperateType = "Update",
OldOrder = oldOrder,
NewOrder = order,
SourceCode = "TraceUpdteStartATA",
SourceName = "运踪回调更新StartATA",
}, tenantDb);
//await _bookingorderservice.SaveLog(newOrder, oldOrder, "运踪更新船期");
}
}
@ -442,11 +469,20 @@ namespace DS.WMS.Core.Op.Method
if (order != null && item.OpTime != null && order.StartETA != item.OpTime)
{
order.StartETA = item.OpTime;
order.Note = "运踪回调更新StartETA";
//order.Note = "运踪回调更新StartETA";
await tenantDb.Updateable(order).UpdateColumns(x => new
{
x.StartETA,x.Note
x.StartETA
}).EnableDiffLogEvent().ExecuteCommandAsync();
// 记录日志
await seaComService.SaveSeaExportLogAsync(new SeaExportSaveLog()
{
OperateType = "Update",
OldOrder = oldOrder,
NewOrder = order,
SourceCode = "TraceUpdteStartETA",
SourceName = "运踪回调更新StartETA",
}, tenantDb);
//await _bookingorderservice.SaveLog(newOrder, oldOrder, "运踪更新船期");
}
}
@ -455,11 +491,20 @@ namespace DS.WMS.Core.Op.Method
if (order != null && item.OpTime != null && order.ETA != item.OpTime)
{
order.ETA = item.OpTime;
order.Note = "运踪回调更新ETA";
//order.Note = "运踪回调更新ETA";
await tenantDb.Updateable(order).UpdateColumns(x => new
{
x.ETA,x.Note
x.ETA
}).EnableDiffLogEvent().ExecuteCommandAsync();
// 记录日志
await seaComService.SaveSeaExportLogAsync(new SeaExportSaveLog()
{
OperateType = "Update",
OldOrder = oldOrder,
NewOrder = order,
SourceCode = "TraceUpdteMDGETA",
SourceName = "运踪回调更新ETA",
}, tenantDb);
//await _bookingorderservice.SaveLog(newOrder, oldOrder, "运踪更新船期");
}
@ -467,13 +512,22 @@ namespace DS.WMS.Core.Op.Method
else if (item.Status == "MDGATA")
{
if (order != null && item.OpTime != null && order.ATA != item.OpTime)
{
{
order.ATA = item.OpTime;
order.Note = "运踪回调更新ATA";
//order.Note = "运踪回调更新ATA";
await tenantDb.Updateable(order).UpdateColumns(x => new
{
x.ATA,x.Note
x.ATA
}).EnableDiffLogEvent().ExecuteCommandAsync();
// 记录日志
await seaComService.SaveSeaExportLogAsync(new SeaExportSaveLog()
{
OperateType = "Update",
OldOrder = oldOrder,
NewOrder = order,
SourceCode = "TraceUpdteMDGATA",
SourceName = "运踪更新船期ATA",
}, tenantDb);
//await _bookingorderservice.SaveLog(newOrder, oldOrder, "运踪更新船期");
}

@ -26,6 +26,9 @@ using System.Text;
using System.Text.RegularExpressions;
using Logger = NLog.Logger;
using AnyDiff.Extensions;
using static AnyDiff.DifferenceLines;
using Newtonsoft.Json;
using Masuit.Tools.Hardware;
namespace DS.WMS.Core.Op.Method
{
@ -53,6 +56,7 @@ namespace DS.WMS.Core.Op.Method
_environment = _serviceProvider.GetRequiredService<IWebHostEnvironment>();
}
#region 海运出口差异日志
/// <summary>
/// 忽略的字段
/// </summary>
@ -70,63 +74,42 @@ namespace DS.WMS.Core.Op.Method
"TenantId",
"TenantName",
};
public async Task SaveSeaExportLog(SeaExportSaveLog req) {
bool flag = true;
long bid = 0;
public async Task SaveSeaExportLogAsync(SeaExportSaveLog req, SqlSugarScopeProvider tenantDb)
{
var diff = req.NewOrder.Diff(req.OldOrder);
//var obj1 = new { Name = "Tom", Age = 20 };
//var obj2 = new { Name = "Jerry", Age = 21 };
//var diff = obj1.Diff(obj2).ToList();
foreach (var change in diff)
{
Console.WriteLine($"{change.PropertyType} - {change.Property}: {change.LeftValue} => {change.RightValue}");
}
//foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(req.NewOrder))
//{
// //基础字段不记录
// string name = descriptor.Name;
// if (IgnoreColumns.Contains(name))
// {
// continue;
// }
// // 如果已经明确了被修改的字段,且当前字段不在其中,则跳过
// if (req.UpdateFields.IsNotNull() && !req.UpdateFields.Contains(name))
// {
// continue;
// }
// object value = descriptor.GetValue(req.NewOrder);
// var oldvalue = req.OldOrder.GetType().GetProperty(name).GetValue(req.OldOrder, null);
// //数值类型转换比较
// if (name == "KGS" || name == "CBM")
// {
// if (Convert.ToDecimal(value) == Convert.ToDecimal(oldvalue))
// {
// continue;
// }
// }
// string _oldvalue = oldvalue != null ? oldvalue.ToString() : "";
// string _value = value != null ? value.ToString() : "";
// if (_oldvalue != _value && !string.IsNullOrWhiteSpace(descriptor.Description))
// {
// var data = new OpBusinessLog()
// {
// BusinessId = req.OldOrder.Id,
// OldValue = JsonConvert.SerializeObject(req.OldOrder),
// NewValue= JsonConvert.SerializeObject(req.NewOrder),
// };
// }
//}
StringBuilder sb = new StringBuilder();
foreach (var item in diff)
{
Console.WriteLine($"{item.PropertyType} - {item.Property}: {item.LeftValue} => {item.RightValue}");
if (item.LeftValue.IsNotNull() && item.RightValue.IsNotNull())
{
if (IgnoreColumns.Contains(item.Property))
continue;
if (!item.LeftValue.Equals(item.RightValue))
{
sb.Append($"[字段:{item.Property},修改前:{item.LeftValue},修改后:{item.RightValue}]");
}
}
}
}
var log = new OpBusinessLog()
{
BusinessId = req.NewOrder.Id,
OperateType = "Update",
OldValue = JsonConvert.SerializeObject(req.OldOrder),
NewValue = JsonConvert.SerializeObject(req.NewOrder),
DiffData = sb.ToString(),
SourceCode = req.SourceCode,
SourceName = req.SourceName,
};
await tenantDb.Insertable(log).ExecuteCommandAsync();
}
#endregion
#region 获取客户结算方式及结算日期
public DataResult<CustomerStlRes> GetCustomerStlInfo(CustomerStlReq req)
@ -928,10 +911,19 @@ namespace DS.WMS.Core.Op.Method
{
StatusName = "";
}
var oldOrder = order.Adapt<SeaExport>();
order.BusinessStatusName = StatusName;
order.Note = "更新主单货物状态";
//order.Note = "更新主单货物状态";
await tenantDb.Updateable(order).EnableDiffLogEvent().ExecuteCommandAsync();
// 记录日志
await SaveSeaExportLogAsync(new SeaExportSaveLog()
{
OperateType = "Update",
OldOrder = oldOrder,
NewOrder = order,
SourceCode = "UpdteBusinessStatusName",
SourceName = "自动更新货物状态",
}, tenantDb);
//var newOrder = order.Adapt<SeaExport>();
//newOrder.BSSTATUSNAME = StatusName;
//await SaveLog(newOrder, order, "自动更新货物状态");
@ -2066,7 +2058,7 @@ namespace DS.WMS.Core.Op.Method
{
return await Task.FromResult(DataResult.Failed("海运出口信息业务已锁定!", MultiLanguageConst.SeaExportBusinessLock));
}
var oldOrder = order.Adapt<SeaExport>();
var dic = req.GetPropertiesArray();
var info = req.Adapt(order);
info.Note = "对外开放更新接口";
@ -2097,7 +2089,14 @@ namespace DS.WMS.Core.Op.Method
}
#endregion
await tenantDb.Updateable(info).UpdateColumns(dic).EnableDiffLogEvent().ExecuteCommandAsync();
await SaveSeaExportLogAsync(new SeaExportSaveLog()
{
OperateType = "Update",
OldOrder = oldOrder,
NewOrder = info,
SourceCode = "OpenEdit",
SourceName = "开放对接更新",
}, tenantDb);
return await Task.FromResult(DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess));
}

@ -415,6 +415,21 @@ public partial class SeaExportService : ISeaExportService
return result;
}
/// <summary>
/// 获取海运出口日志
/// </summary>
/// <param name="id">业务Id</param>
/// <returns></returns>
public async Task<DataResult<List<OpBusinessLogRes>>> GetSeaExportLogList(string id) {
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
var data = await tenantDb.Queryable<OpBusinessLog>()
.Where(a => a.BusinessId == long.Parse(id))
.Select<OpBusinessLogRes>()
.ToListAsync();
return await Task.FromResult(DataResult<List<OpBusinessLogRes>>.Success(data, MultiLanguageConst.DataQuerySuccess));
}
/// <summary>
/// 编辑
/// </summary>
@ -514,14 +529,14 @@ public partial class SeaExportService : ISeaExportService
//添加操作权限
var operationRule = commonService.GetOperationRuleConditional<SeaExport>();
var info = await tenantDb.Queryable<SeaExport>().Where(x => x.Id == req.Id).WhereFilterOperationRule(operationRule).FirstAsync();
var oldOrder = info.Adapt<SeaExport>();
var feeStatus = await tenantDb.Queryable<BusinessFeeStatus>().Where(x => x.BusinessId == req.Id).FirstAsync();
if (feeStatus.IsNotNull() && (bool)feeStatus.IsBusinessLocking)
{
return await Task.FromResult(DataResult.Failed("海运出口信息业务已锁定!", MultiLanguageConst.SeaExportBusinessLock));
}
var oldOrder = info;
info = req.Adapt(info);
info= req.Adapt(info);
//TODO 会计期间不允许小于已结转期间
if (info.CloseDocDate.IsNotNull() && info.CloseDocDate > info.ETD)
{
@ -556,14 +571,14 @@ public partial class SeaExportService : ISeaExportService
info.Note = "正常编辑";
await tenantDb.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).EnableDiffLogEvent().ExecuteCommandAsync();
await seaComService.SaveSeaExportLog(new SeaExportSaveLog()
await seaComService.SaveSeaExportLogAsync(new SeaExportSaveLog()
{
OperateType = "Update",
OldOrder = oldOrder,
NewOrder = info,
SourceCode = "NormalEdit",
SourceName = "正常编辑",
});
},tenantDb);
//处理订单联系人信息
DealBusinessOrderContact(info, tenantDb);
@ -752,7 +767,7 @@ public partial class SeaExportService : ISeaExportService
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
public DataResult SeaExportBatchEdit(SeaExportBatchEditReq req)
public async Task<DataResult> SeaExportBatchEdit(SeaExportBatchEditReq req)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (req.Ids.Count == 0)
@ -775,15 +790,25 @@ public partial class SeaExportService : ISeaExportService
return DataResult.Failed("海运出口信息费用已锁定!", MultiLanguageConst.SeaExportFeeLock);
}
}
var orderList = tenantDb.Queryable<SeaExport>().Where(x => req.Ids.Contains(x.Id)).ToList();
var orderList = await tenantDb.Queryable<SeaExport>().Where(x => req.Ids.Contains(x.Id)).ToListAsync();
var dic = req.GetPropertiesArray();
foreach (var item in orderList)
{
var oldOrder = item.Adapt<SeaExport>();
var info = req.Adapt(item);
info.Note = "批量更新";
tenantDb.Updateable(info).UpdateColumns(dic).EnableDiffLogEvent().ExecuteCommand();
await tenantDb.Updateable(info).UpdateColumns(dic).EnableDiffLogEvent().ExecuteCommandAsync();
await seaComService.SaveSeaExportLogAsync(new SeaExportSaveLog()
{
OperateType = "Update",
OldOrder = oldOrder,
NewOrder = info,
SourceCode = "BatchEdit",
SourceName = "批量更新",
}, tenantDb);
}
return DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess);

@ -59,6 +59,20 @@ public class SeaExportController : ApiController
var res = await _invokeService.GetSeaExportPartList(request);
return res;
}
/// <summary>
/// 海运出口日志列表
/// </summary>
/// <param name="id">主单id</param>
/// <returns></returns>
[HttpGet]
[Route("GetSeaExportLogList")]
public async Task<DataResult<List<OpBusinessLogRes>>> GetSeaExportLogList([FromQuery] string id)
{
var res = await _invokeService.GetSeaExportLogList(id);
return res;
}
/// <summary>
/// 编辑
/// </summary>
@ -92,9 +106,9 @@ public class SeaExportController : ApiController
/// <returns></returns>
[HttpPost]
[Route("SeaExportBatchEdit")]
public DataResult SeaExportBatchEdit([FromBody] SeaExportBatchEditReq req)
public async Task<DataResult> SeaExportBatchEdit([FromBody] SeaExportBatchEditReq req)
{
var res = _invokeService.SeaExportBatchEdit(req);
var res = await _invokeService.SeaExportBatchEdit(req);
return res;
}

@ -60,7 +60,7 @@ public class SaasDBUpdateTest
var tenantDb = saasService.GetBizDbScopeById(item.TenantId).CopyNew();
StaticConfig.CodeFirst_MySqlCollate = "utf8mb4_0900_ai_ci"; //较高版本支持
//tenantDb.CodeFirst.InitTables(types); //指定表空间下的实体
tenantDb.CodeFirst.InitTables(typeof(OpLetterYard));//指定更新特定实体
tenantDb.CodeFirst.InitTables(typeof(OpBusinessLog));//指定更新特定实体
}
Assert.True(true);

Loading…
Cancel
Save