批量操作

optimize
wet 2 years ago
parent cf45a93cbb
commit a83e717b53

@ -364,8 +364,9 @@ namespace Myshipping.Application
{
throw Oops.Bah("请传入正常数据!");
}
if (!JsonUtil.TrimFields(input)) {
throw Oops.Bah("录入字符存在中文");
var ms = JsonUtil.TrimFields(input);
if (!string.IsNullOrEmpty(ms)) {
throw Oops.Bah(ms);
}
JsonUtil.PropToUpper(input, "ORDNO", "BSSTATUS", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME");
@ -645,7 +646,11 @@ namespace Myshipping.Application
public async Task<long> Add(BookingOrderDto input)
{
JsonUtil.PropToUpper(input, "ORDNO", "BSSTATUS", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME");
JsonUtil.TrimFields(input);
var ms = JsonUtil.TrimFields(input);
if (!string.IsNullOrEmpty(ms))
{
throw Oops.Bah(ms);
}
if (input.ctnInputs != null)
{
var groupList = input.ctnInputs.Where(x => x.CTNNUM > 0).GroupBy(c => c.CTNALL).Select(g => $"{g.Key}*{g.Sum(gg => gg.CTNNUM)}");

@ -164,7 +164,7 @@ namespace Myshipping.Application
}
var userlist = _repUser.AsQueryable().Filter(null, true).ToListAsync();
var user = _repUser.AsQueryable().Filter(null, true).Where(x => x.Name == model.CreatedUserName.Trim()).FirstAsync();
if (user.Result== null)
if (user.Result == null)
{
throw Oops.Bah($"未匹配到创建人 {model.CreatedUserName.Trim()} 请联系管理员添加相关用户");
}
@ -179,7 +179,11 @@ namespace Myshipping.Application
}
JsonUtil.PropToUpper(model, "ORDNO", "BSSTATUS", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME");
JsonUtil.TrimFields(model);
var ms = JsonUtil.TrimFields(model);
if (!string.IsNullOrEmpty(ms))
{
throw Oops.Bah(ms);
}
if (model.ctnInputs != null)
{
var groupList = model.ctnInputs.Where(x => x.CTNNUM > 0).GroupBy(c => c.CTNALL).Select(g => $"{g.Key}*{g.Sum(gg => gg.CTNNUM)}");
@ -192,7 +196,8 @@ namespace Myshipping.Application
throw Oops.Bah("当前提单号已存在,请勿重复录入!");
}
var entity = model.Adapt<BookingOrder>();
if (!string.IsNullOrEmpty(entity.ROUTE)) {
if (!string.IsNullOrEmpty(entity.ROUTE))
{
entity.ROUTEID = userlist.Result.Where(x => x.Name == entity.ROUTE).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == entity.ROUTE).Select(x => x.Id).FirstOrDefault().ToString();
}
if (!string.IsNullOrEmpty(entity.SALE))
@ -214,7 +219,7 @@ namespace Myshipping.Application
entity.CreatedUserId = user.Result.Id;
entity.CreatedUserName = user.Result.Name.ToString();
entity.CreatedTime = DateTime.Now;
entity.ParentId =0;
entity.ParentId = 0;
await _rep.InsertAsync(entity);
if (model.ctnInputs != null)
{
@ -281,7 +286,12 @@ namespace Myshipping.Application
throw Oops.Bah("请填写分提单号!");
}
JsonUtil.PropToUpper(item, "ORDNO", "BSSTATUS", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME");
JsonUtil.TrimFields(item);
var fms = JsonUtil.TrimFields(item);
if (!string.IsNullOrEmpty(fms))
{
throw Oops.Bah(fms);
}
if (item.ctnInputs != null)
{
var groupList = item.ctnInputs.Where(x => x.CTNNUM > 0).GroupBy(c => c.CTNALL).Select(g => $"{g.Key}*{g.Sum(gg => gg.CTNNUM)}");
@ -340,7 +350,7 @@ namespace Myshipping.Application
ctndetail.CTNID = ctnentity.Id;
ctndetail.CreatedUserId = user.Result.Id;
ctndetail.CreatedUserName = user.Result.Name;
await _ctndetailrep.InsertAsync(ctndetail);
}
}
@ -387,7 +397,11 @@ namespace Myshipping.Application
}
JsonUtil.PropToUpper(model, "ORDNO", "BSSTATUS", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME");
JsonUtil.TrimFields(model);
var ms = JsonUtil.TrimFields(model);
if (!string.IsNullOrEmpty(ms))
{
throw Oops.Bah(ms);
}
if (model.ctnInputs != null)
{
@ -554,8 +568,12 @@ namespace Myshipping.Application
throw Oops.Bah("请填写提单号!");
}
JsonUtil.PropToUpper(item, "ORDNO", "BSSTATUS", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME");
JsonUtil.TrimFields(item);
var fms = JsonUtil.TrimFields(item);
if (!string.IsNullOrEmpty(fms))
{
throw Oops.Bah(fms);
}
if (item.ctnInputs != null)
{
var groupList = item.ctnInputs.Where(x => x.CTNNUM > 0).GroupBy(c => c.CTNALL).Select(g => $"{g.Key}*{g.Sum(gg => gg.CTNNUM)}");
@ -571,7 +589,7 @@ namespace Myshipping.Application
{
throw Oops.Bah($"当前提单号{fdet.MBLNO}_{fdet.HBLNO}已存在,请勿重复录入!");
}
fdentity.Id = fdmain.Id;
fdentity.UpdatedUserName = user.Result.Name;
fdentity.UpdatedUserId = user.Result.Id;
@ -632,9 +650,10 @@ namespace Myshipping.Application
}
else {
else
{
fdentity.CreatedUserId = user.Result.Id;
fdentity.CreatedUserName = user.Result.Name;
fdentity.CreatedTime = DateTime.Now;
@ -670,7 +689,7 @@ namespace Myshipping.Application
}
if (item.BookingEDIExt != null)
{
@ -762,12 +781,653 @@ namespace Myshipping.Application
return main.Id;
#endregion
}
}
/// <summary>
/// 同步订舱批量 没有返回值
/// </summary>
/// <param name="list"></param>
/// <returns></returns>
[SqlSugarUnitOfWork]
[HttpPost("/DataSync/SyncBookingList"), ApiUser(ApiCode = "SyncBookingList")]
public async void SyncBookingList(List<SyncBookingOrderDto> list)
{
foreach (var model in list)
{
if (string.IsNullOrWhiteSpace(model.BSNO))
{
throw Oops.Bah("主单BSNO未录入");
}
if (string.IsNullOrWhiteSpace(model.CreatedUserName))
{
throw Oops.Bah("未录入创建人");
}
var userlist = _repUser.AsQueryable().Filter(null, true).ToListAsync();
var user = _repUser.AsQueryable().Filter(null, true).Where(x => x.Name == model.CreatedUserName.Trim()).FirstAsync();
if (user.Result == null)
{
throw Oops.Bah($"未匹配到创建人 {model.CreatedUserName.Trim()} 请联系管理员添加相关用户");
}
var order = await _rep.AsQueryable().Filter(null, true).Where(x => x.BSNO == model.BSNO).FirstAsync();
if (order == null)
{
#region 新增
if (string.IsNullOrWhiteSpace(model.MBLNO))
{
throw Oops.Bah("请填写提单号!");
}
JsonUtil.PropToUpper(model, "ORDNO", "BSSTATUS", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME");
var ms = JsonUtil.TrimFields(model);
if (!string.IsNullOrEmpty(ms))
{
throw Oops.Bah(ms);
}
if (model.ctnInputs != null)
{
var groupList = model.ctnInputs.Where(x => x.CTNNUM > 0).GroupBy(c => c.CTNALL).Select(g => $"{g.Key}*{g.Sum(gg => gg.CTNNUM)}");
model.CNTRTOTAL = string.Join(" / ", groupList);
}
var et = await _rep.Where(x => x.MBLNO == model.MBLNO && x.TenantId == UserManager.TENANT_ID && x.HBLNO == model.HBLNO && x.ParentId == 0).FirstAsync();
if (et != null)
{
throw Oops.Bah("当前提单号已存在,请勿重复录入!");
}
var entity = model.Adapt<BookingOrder>();
if (!string.IsNullOrEmpty(entity.ROUTE))
{
entity.ROUTEID = userlist.Result.Where(x => x.Name == entity.ROUTE).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == entity.ROUTE).Select(x => x.Id).FirstOrDefault().ToString();
}
if (!string.IsNullOrEmpty(entity.SALE))
{
entity.SALEID = userlist.Result.Where(x => x.Name == entity.SALE).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == entity.SALE).Select(x => x.Id).FirstOrDefault().ToString();
}
if (!string.IsNullOrEmpty(entity.OP))
{
entity.OPID = userlist.Result.Where(x => x.Name == entity.OP).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == entity.OP).Select(x => x.Id).FirstOrDefault().ToString();
}
if (!string.IsNullOrEmpty(entity.DOC))
{
entity.DOCID = userlist.Result.Where(x => x.Name == entity.DOC).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == entity.DOC).Select(x => x.Id).FirstOrDefault().ToString();
}
if (!string.IsNullOrEmpty(entity.CUSTSERVICE))
{
entity.CUSTSERVICEID = userlist.Result.Where(x => x.Name == entity.CUSTSERVICE).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == entity.CUSTSERVICE).Select(x => x.Id).FirstOrDefault().ToString();
}
entity.CreatedUserId = user.Result.Id;
entity.CreatedUserName = user.Result.Name.ToString();
entity.CreatedTime = DateTime.Now;
entity.ParentId = 0;
await _rep.InsertAsync(entity);
if (model.ctnInputs != null)
{
foreach (var item in model.ctnInputs)
{
var ctnentity = item.Adapt<BookingCtn>();
ctnentity.BILLID = entity.Id;
ctnentity.CreatedUserId = user.Result.Id;
ctnentity.CreatedUserName = user.Result.Name;
await _repCtn.InsertAsync(ctnentity);
//这里保存有可能没有添加多品名,所有箱下没有货物信息
if (item.ctnDetailInputs != null)
{
foreach (var it in item.ctnDetailInputs)
{
var ctndetail = it.Adapt<BookingCtnDetail>();
ctndetail.CTNID = ctnentity.Id;
ctndetail.CreatedUserId = user.Result.Id;
ctndetail.CreatedUserName = user.Result.Name;
await _ctndetailrep.InsertAsync(ctndetail);
}
}
}
}
if (model.BookingEDIExt != null)
{
//写入EDI扩展
var ediExtEntity = model.BookingEDIExt.Adapt<BookingEDIExt>();
ediExtEntity.BookingId = entity.Id;
ediExtEntity.CreatedUserId = user.Result.Id;
ediExtEntity.CreatedUserName = user.Result.Name;
ediExtEntity.CreatedTime = DateTime.Now;
ediExtEntity.CreatedUserId = user.Result.Id;
ediExtEntity.CreatedUserName = user.Result.Name;
await _bookingEDIExt.InsertAsync(ediExtEntity);
}
////添加booking日志
await _bookinglog.InsertAsync(new BookingLog
{
Type = "Add",
BookingId = entity.Id,
TenantId = Convert.ToInt64(UserManager.TENANT_ID),
CreatedTime = DateTime.Now,
CreatedUserId = user.Result.Id,
CreatedUserName = "系统"
});
//分单
if (model.childrens != null)
{
foreach (var item in model.childrens)
{
if (string.IsNullOrWhiteSpace(item.MBLNO))
{
throw Oops.Bah("请填写提单号!");
}
if (string.IsNullOrWhiteSpace(item.HBLNO))
{
throw Oops.Bah("请填写分提单号!");
}
JsonUtil.PropToUpper(item, "ORDNO", "BSSTATUS", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME");
var fms = JsonUtil.TrimFields(item);
if (!string.IsNullOrEmpty(fms))
{
throw Oops.Bah(fms);
}
if (item.ctnInputs != null)
{
var groupList = item.ctnInputs.Where(x => x.CTNNUM > 0).GroupBy(c => c.CTNALL).Select(g => $"{g.Key}*{g.Sum(gg => gg.CTNNUM)}");
item.CNTRTOTAL = string.Join(" / ", groupList);
}
var fdet = await _rep.Where(x => x.MBLNO == model.MBLNO && x.TenantId == UserManager.TENANT_ID && x.HBLNO == model.HBLNO && x.ParentId == entity.Id).FirstAsync();
if (fdet != null)
{
throw Oops.Bah($"当前分单中提单号({item.MBLNO}_{item.HBLNO})已存在,请勿重复录入!");
}
var fdentity = item.Adapt<BookingOrder>();
if (!string.IsNullOrEmpty(fdentity.ROUTE))
{
fdentity.ROUTEID = userlist.Result.Where(x => x.Name == entity.ROUTE).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == entity.ROUTE).Select(x => x.Id).FirstOrDefault().ToString();
}
if (!string.IsNullOrEmpty(fdentity.SALE))
{
fdentity.SALEID = userlist.Result.Where(x => x.Name == entity.SALE).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == entity.SALE).Select(x => x.Id).FirstOrDefault().ToString();
}
if (!string.IsNullOrEmpty(fdentity.OP))
{
fdentity.OPID = userlist.Result.Where(x => x.Name == entity.OP).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == entity.OP).Select(x => x.Id).FirstOrDefault().ToString();
}
if (!string.IsNullOrEmpty(fdentity.DOC))
{
fdentity.DOCID = userlist.Result.Where(x => x.Name == entity.DOC).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == entity.DOC).Select(x => x.Id).FirstOrDefault().ToString();
}
if (!string.IsNullOrEmpty(fdentity.CUSTSERVICE))
{
fdentity.CUSTSERVICEID = userlist.Result.Where(x => x.Name == entity.CUSTSERVICE).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == entity.CUSTSERVICE).Select(x => x.Id).FirstOrDefault().ToString();
}
fdentity.CreatedUserId = user.Result.Id;
fdentity.CreatedUserName = user.Result.Name;
fdentity.CreatedTime = DateTime.Now;
fdentity.ParentId = entity.Id;
await _rep.InsertAsync(fdentity);
if (item.ctnInputs != null)
{
foreach (var it in item.ctnInputs)
{
var ctnentity = item.Adapt<BookingCtn>();
ctnentity.BILLID = fdentity.Id;
ctnentity.CreatedUserId = user.Result.Id;
ctnentity.CreatedUserName = user.Result.Name;
await _repCtn.InsertAsync(ctnentity);
//这里保存有可能没有添加多品名,所有箱下没有货物信息
if (it.ctnDetailInputs != null)
{
foreach (var dit in it.ctnDetailInputs)
{
var ctndetail = dit.Adapt<BookingCtnDetail>();
ctndetail.CTNID = ctnentity.Id;
ctndetail.CreatedUserId = user.Result.Id;
ctndetail.CreatedUserName = user.Result.Name;
await _ctndetailrep.InsertAsync(ctndetail);
}
}
}
}
if (item.BookingEDIExt != null)
{
//写入EDI扩展
var ediExtEntity = model.BookingEDIExt.Adapt<BookingEDIExt>();
ediExtEntity.BookingId = fdentity.Id;
ediExtEntity.CreatedUserId = user.Result.Id;
ediExtEntity.CreatedUserName = user.Result.Name;
ediExtEntity.CreatedTime = DateTime.Now;
await _bookingEDIExt.InsertAsync(ediExtEntity);
}
////添加booking日志
await _bookinglog.InsertAsync(new BookingLog
{
Type = "Add",
BookingId = fdentity.Id,
TenantId = Convert.ToInt64(UserManager.TENANT_ID),
CreatedTime = DateTime.Now,
CreatedUserId = user.Result.Id,
CreatedUserName = "系统"
});
}
}
#endregion
}
else
{
#region 编辑
if (string.IsNullOrWhiteSpace(model.MBLNO))
{
throw Oops.Bah("请填写提单号!");
}
JsonUtil.PropToUpper(model, "ORDNO", "BSSTATUS", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME");
var ms = JsonUtil.TrimFields(model);
if (!string.IsNullOrEmpty(ms))
{
throw Oops.Bah(ms);
}
if (model.ctnInputs != null)
{
var groupList = model.ctnInputs.Where(x => x.CTNNUM > 0).GroupBy(c => c.CTNALL).Select(g => $"{g.Key}*{g.Sum(gg => gg.CTNNUM)}");
model.CNTRTOTAL = string.Join(" / ", groupList);
}
var main = await _rep.AsQueryable().Filter(null, true).Where(x => x.BSNO == model.BSNO).FirstAsync();
var et = await _rep.AsQueryable().Filter(null, true).Where(x => x.MBLNO == model.MBLNO && x.TenantId == UserManager.TENANT_ID && x.HBLNO == model.HBLNO && x.BSNO != model.BSNO).FirstAsync();
if (et != null)
{
throw Oops.Bah("当前提单号已存在,请勿重复录入!");
}
var entity = model.Adapt<BookingOrder>();
entity.Id = main.Id;
entity.UpdatedUserName = user.Result.Name;
entity.UpdatedUserId = user.Result.Id;
entity.UpdatedTime = DateTime.Now;
if (!string.IsNullOrEmpty(entity.ROUTE))
{
entity.ROUTEID = userlist.Result.Where(x => x.Name == entity.ROUTE).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == entity.ROUTE).Select(x => x.Id).FirstOrDefault().ToString();
}
if (!string.IsNullOrEmpty(entity.SALE))
{
entity.SALEID = userlist.Result.Where(x => x.Name == entity.SALE).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == entity.SALE).Select(x => x.Id).FirstOrDefault().ToString();
}
if (!string.IsNullOrEmpty(entity.OP))
{
entity.OPID = userlist.Result.Where(x => x.Name == entity.OP).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == entity.OP).Select(x => x.Id).FirstOrDefault().ToString();
}
if (!string.IsNullOrEmpty(entity.DOC))
{
entity.DOCID = userlist.Result.Where(x => x.Name == entity.DOC).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == entity.DOC).Select(x => x.Id).FirstOrDefault().ToString();
}
if (!string.IsNullOrEmpty(entity.CUSTSERVICE))
{
entity.CUSTSERVICEID = userlist.Result.Where(x => x.Name == entity.CUSTSERVICE).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == entity.CUSTSERVICE).Select(x => x.Id).FirstOrDefault().ToString();
}
await _rep.AsUpdateable(entity).IgnoreColumns(it => new
{
it.ParentId,
it.TenantId,
it.CreatedTime,
it.CreatedUserId,
it.CreatedUserName
}).ExecuteCommandAsync();
var ctnlist = await _repCtn.AsQueryable().Where(x => x.BILLID == main.Id).Select(x => x.Id).ToListAsync();
await _repCtn.DeleteAsync(x => x.BILLID == main.Id);
await _ctndetailrep.DeleteAsync(x => ctnlist.Contains((long)x.CTNID));
if (model.ctnInputs != null)
{
foreach (var item in model.ctnInputs)
{
var ctnentity = item.Adapt<BookingCtn>();
ctnentity.BILLID = main.Id;
ctnentity.CreatedUserId = user.Result.Id;
ctnentity.CreatedUserName = user.Result.Name;
await _repCtn.InsertAsync(ctnentity);
if (item.ctnDetailInputs != null)
{
foreach (var it in item.ctnDetailInputs)
{
var ctndetail = it.Adapt<BookingCtnDetail>();
ctndetail.CTNID = ctnentity.Id;
ctndetail.CreatedUserId = user.Result.Id;
ctndetail.CreatedUserName = user.Result.Name;
await _ctndetailrep.InsertAsync(ctndetail);
}
}
}
}
if (model.BookingEDIExt != null)
{
//检索EDI扩展
var ediExtEntity = _bookingEDIExt.FirstOrDefault(u => u.BookingId == main.Id);
if (ediExtEntity == null)
{
//写入EDI扩展
ediExtEntity = model.BookingEDIExt.Adapt<BookingEDIExt>();
ediExtEntity.BookingId = main.Id;
ediExtEntity.CreatedUserId = user.Result.Id;
ediExtEntity.CreatedUserName = user.Result.Name;
ediExtEntity.CreatedTime = DateTime.Now;
await _bookingEDIExt.InsertAsync(ediExtEntity);
}
else
{
//更新EDI扩展
var currEdiExtEntity = model.BookingEDIExt.Adapt<BookingEDIExt>();
currEdiExtEntity.Id = ediExtEntity.Id;
currEdiExtEntity.UpdatedUserId = user.Result.Id;
currEdiExtEntity.UpdatedTime = DateTime.Now;
await _bookingEDIExt.AsUpdateable(currEdiExtEntity).IgnoreColumns(it => new
{
it.BookingId,
it.TenantId,
it.CreatedTime,
it.CreatedUserId,
it.CreatedUserName
}).ExecuteCommandAsync();
}
}
bool flag = true;
long bid = 0;
foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(entity))
{
string name = descriptor.Name;
if (name == "TenantId" || name == "CreatedTime" || name == "UpdatedTime" || name == "CreatedUserId" || name == "CreatedUserName")
{
continue;
}
object value = descriptor.GetValue(entity);
var oldvalue = main.GetType().GetProperty(name).GetValue(main, 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))
{
if (flag)
{
////添加booking日志
bid = await _bookinglog.InsertReturnSnowflakeIdAsync(new BookingLog
{
Type = "Edit",
BookingId = entity.Id,
TenantId = Convert.ToInt64(UserManager.TENANT_ID),
CreatedTime = DateTime.Now,
CreatedUserId = user.Result.Id,
CreatedUserName = user.Result.Name
});
flag = false;
}
await _bookinglogdetail.InsertReturnSnowflakeIdAsync(new BookingLogDetail
{
PId = bid,
Field = descriptor.Description,
OldValue = _oldvalue,
NewValue = _value,
});
}
}
//分单
if (model.childrens != null)
{
foreach (var item in model.childrens)
{
if (string.IsNullOrWhiteSpace(item.MBLNO))
{
throw Oops.Bah("请填写提单号!");
}
JsonUtil.PropToUpper(item, "ORDNO", "BSSTATUS", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME");
var fms = JsonUtil.TrimFields(item);
if (!string.IsNullOrEmpty(fms))
{
throw Oops.Bah(fms);
}
if (item.ctnInputs != null)
{
var groupList = item.ctnInputs.Where(x => x.CTNNUM > 0).GroupBy(c => c.CTNALL).Select(g => $"{g.Key}*{g.Sum(gg => gg.CTNNUM)}");
item.CNTRTOTAL = string.Join(" / ", groupList);
}
var fdmain = await _rep.AsQueryable().Filter(null, true).Where(x => x.BSNO == item.BSNO).FirstAsync();
var fdentity = item.Adapt<BookingOrder>();
if (fdmain != null)
{
var fdet = await _rep.Where(x => x.MBLNO == item.MBLNO && x.TenantId == UserManager.TENANT_ID && x.HBLNO == item.HBLNO && x.BSNO != fdmain.BSNO).FirstAsync();
if (fdet != null)
{
throw Oops.Bah($"当前提单号{fdet.MBLNO}_{fdet.HBLNO}已存在,请勿重复录入!");
}
fdentity.Id = fdmain.Id;
fdentity.UpdatedUserName = user.Result.Name;
fdentity.UpdatedUserId = user.Result.Id;
fdentity.UpdatedTime = DateTime.Now;
if (!string.IsNullOrEmpty(fdentity.ROUTE))
{
fdentity.ROUTEID = userlist.Result.Where(x => x.Name == entity.ROUTE).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == entity.ROUTE).Select(x => x.Id).FirstOrDefault().ToString();
}
if (!string.IsNullOrEmpty(fdentity.SALE))
{
fdentity.SALEID = userlist.Result.Where(x => x.Name == entity.SALE).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == entity.SALE).Select(x => x.Id).FirstOrDefault().ToString();
}
if (!string.IsNullOrEmpty(fdentity.OP))
{
fdentity.OPID = userlist.Result.Where(x => x.Name == entity.OP).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == entity.OP).Select(x => x.Id).FirstOrDefault().ToString();
}
if (!string.IsNullOrEmpty(fdentity.DOC))
{
fdentity.DOCID = userlist.Result.Where(x => x.Name == entity.DOC).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == entity.DOC).Select(x => x.Id).FirstOrDefault().ToString();
}
if (!string.IsNullOrEmpty(fdentity.CUSTSERVICE))
{
fdentity.CUSTSERVICEID = userlist.Result.Where(x => x.Name == entity.CUSTSERVICE).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == entity.CUSTSERVICE).Select(x => x.Id).FirstOrDefault().ToString();
}
await _rep.AsUpdateable(fdentity).IgnoreColumns(it => new
{
it.ParentId,
it.TenantId,
it.CreatedTime,
it.CreatedUserId,
it.CreatedUserName
}).ExecuteCommandAsync();
var fdctnlist = await _repCtn.AsQueryable().Where(x => x.BILLID == fdmain.Id).Select(x => x.Id).ToListAsync();
await _repCtn.DeleteAsync(x => x.BILLID == fdmain.Id);
await _ctndetailrep.DeleteAsync(x => fdctnlist.Contains((long)x.CTNID));
if (item.ctnInputs != null)
{
foreach (var it in model.ctnInputs)
{
var ctnentity = item.Adapt<BookingCtn>();
ctnentity.BILLID = fdmain.Id;
ctnentity.CreatedUserId = user.Result.Id;
ctnentity.CreatedUserName = user.Result.Name;
await _repCtn.InsertAsync(ctnentity);
if (it.ctnDetailInputs != null)
{
foreach (var it_ in it.ctnDetailInputs)
{
var ctndetail = it_.Adapt<BookingCtnDetail>();
ctndetail.CTNID = ctnentity.Id;
ctndetail.CreatedUserId = user.Result.Id;
ctndetail.CreatedUserName = user.Result.Name;
await _ctndetailrep.InsertAsync(ctndetail);
}
}
}
}
}
else
{
fdentity.CreatedUserId = user.Result.Id;
fdentity.CreatedUserName = user.Result.Name;
fdentity.CreatedTime = DateTime.Now;
fdentity.ParentId = entity.Id;
await _rep.InsertAsync(fdentity);
if (item.ctnInputs != null)
{
foreach (var it in item.ctnInputs)
{
var ctnentity = item.Adapt<BookingCtn>();
ctnentity.BILLID = fdentity.Id;
ctnentity.CreatedUserId = user.Result.Id;
ctnentity.CreatedUserName = user.Result.Name;
await _repCtn.InsertAsync(ctnentity);
//这里保存有可能没有添加多品名,所有箱下没有货物信息
if (it.ctnDetailInputs != null)
{
foreach (var dit in it.ctnDetailInputs)
{
var ctndetail = dit.Adapt<BookingCtnDetail>();
ctndetail.CTNID = ctnentity.Id;
ctndetail.CreatedUserId = user.Result.Id;
ctndetail.CreatedUserName = user.Result.Name;
await _ctndetailrep.InsertAsync(ctndetail);
}
}
}
}
}
if (item.BookingEDIExt != null)
{
//检索EDI扩展
var ediExtEntity = _bookingEDIExt.FirstOrDefault(u => u.BookingId == fdmain.Id);
if (ediExtEntity == null)
{
//写入EDI扩展
ediExtEntity = item.BookingEDIExt.Adapt<BookingEDIExt>();
ediExtEntity.BookingId = fdmain.Id;
ediExtEntity.CreatedUserId = user.Result.Id;
ediExtEntity.CreatedUserName = user.Result.Name;
ediExtEntity.CreatedTime = DateTime.Now;
await _bookingEDIExt.InsertAsync(ediExtEntity);
}
else
{
//更新EDI扩展
var currEdiExtEntity = model.BookingEDIExt.Adapt<BookingEDIExt>();
currEdiExtEntity.Id = ediExtEntity.Id;
await _bookingEDIExt.AsUpdateable(currEdiExtEntity).IgnoreColumns(it => new
{
it.BookingId,
it.TenantId,
it.CreatedTime,
it.CreatedUserId,
it.CreatedUserName
}).ExecuteCommandAsync();
}
}
bool fdflag = true;
long fdbid = 0;
foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(fdentity))
{
string name = descriptor.Name;
if (name == "TenantId" || name == "CreatedTime" || name == "UpdatedTime" || name == "CreatedUserId" || name == "CreatedUserName")
{
continue;
}
object value = descriptor.GetValue(fdentity);
var oldvalue = fdmain.GetType().GetProperty(name).GetValue(main, 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))
{
if (fdflag)
{
////添加booking日志
fdbid = await _bookinglog.InsertReturnSnowflakeIdAsync(new BookingLog
{
Type = "Edit",
BookingId = fdentity.Id,
TenantId = Convert.ToInt64(UserManager.TENANT_ID),
CreatedTime = DateTime.Now,
CreatedUserId = user.Result.Id,
CreatedUserName = user.Result.Name,
});
fdflag = false;
}
await _bookinglogdetail.InsertReturnSnowflakeIdAsync(new BookingLogDetail
{
PId = fdbid,
Field = descriptor.Description,
OldValue = _oldvalue,
NewValue = _value,
});
}
}
}
}
#endregion
}
}
}
#endregion

@ -1340,7 +1340,7 @@ namespace Myshipping.Application.Service.DataSync.Dto
/// </summary>
public string LineName { get; set; }
/// <summary>
/// <summary>
/// ep号
/// </summary>
public string EPCode { get; set; }

@ -170,7 +170,7 @@ public static class JsonUtil
/// <summary>
/// 长TAB键的识别替换空格
/// </summary>
public static bool TrimFields(object model)
public static string TrimFields(object model)
{
var props = model.GetType().GetProperties();
foreach (PropertyInfo prop in props)
@ -195,21 +195,94 @@ public static class JsonUtil
prop.SetValue(model, sourceVal.ToString().Replace("", "'"));
prop.SetValue(model, sourceVal.ToString().Replace("", "'"));
prop.SetValue(model, sourceVal.ToString().Replace("、", ","));
if (Regex.IsMatch(sourceVal.ToString(), @"[\u4e00-\u9fa5]") && (propName.ToUpper() == "MBLNO" || propName.ToUpper() == "HBLNO" || propName.ToUpper() == "VESSEL" || propName.ToUpper() == "VOYNO"
|| propName.ToUpper() == "VOYNOINNER" || propName.ToUpper() == "PLACERECEIPT" || propName.ToUpper() == "PORTLOAD" || propName.ToUpper() == "PORTDISCHARGE"
|| propName.ToUpper() == "PLACEDELIVERY" || propName.ToUpper() == "DESTINATION" || propName.ToUpper() == "MARKS" || propName.ToUpper() == "HSCODE"
|| propName.ToUpper() == "DESCRIPTION" || propName.ToUpper() == "SHIPPERID" || propName.ToUpper() == "CONSIGNEEID" || propName.ToUpper() == "NOTIFYPARTYID"
|| propName.ToUpper() == "YARDID" || propName.ToUpper() == "VESSELID"))
if(Regex.IsMatch(sourceVal.ToString(), @"[\u4e00-\u9fa5]")&& propName.ToUpper() == "MBLNO")
{
return false;
return "提单号存在中文字符";
}
if (Regex.IsMatch(sourceVal.ToString(), @"[\u4e00-\u9fa5]") && propName.ToUpper() == "HBLNO")
{
return "分提单号存在中文字符";
}
if (Regex.IsMatch(sourceVal.ToString(), @"[\u4e00-\u9fa5]") && propName.ToUpper() == "VESSEL")
{
return "船名存在中文字符";
}
if (Regex.IsMatch(sourceVal.ToString(), @"[\u4e00-\u9fa5]") && propName.ToUpper() == "VOYNO")
{
return "海关航次存在中文字符";
}
if (Regex.IsMatch(sourceVal.ToString(), @"[\u4e00-\u9fa5]") && propName.ToUpper() == "VOYNOINNER")
{
return "内部航次存在中文字符";
}
if (Regex.IsMatch(sourceVal.ToString(), @"[\u4e00-\u9fa5]") && propName.ToUpper() == "PLACERECEIPT")
{
return "收货地存在中文字符";
}
if (Regex.IsMatch(sourceVal.ToString(), @"[\u4e00-\u9fa5]") && propName.ToUpper() == "PORTLOAD")
{
return "起运港存在中文字符";
}
if (Regex.IsMatch(sourceVal.ToString(), @"[\u4e00-\u9fa5]") && propName.ToUpper() == "PORTDISCHARGE")
{
return "卸货港存在中文字符";
}
if (Regex.IsMatch(sourceVal.ToString(), @"[\u4e00-\u9fa5]") && propName.ToUpper() == "PLACEDELIVERY")
{
return "交货地存在中文字符";
}
if (Regex.IsMatch(sourceVal.ToString(), @"[\u4e00-\u9fa5]") && propName.ToUpper() == "DESTINATION")
{
return "目的地存在中文字符";
}
if (Regex.IsMatch(sourceVal.ToString(), @"[\u4e00-\u9fa5]") && propName.ToUpper() == "MARKS")
{
return "唛头存在中文字符";
}
if (Regex.IsMatch(sourceVal.ToString(), @"[\u4e00-\u9fa5]") && propName.ToUpper() == "HSCODE")
{
return "HS代码存在中文字符";
}
if (Regex.IsMatch(sourceVal.ToString(), @"[\u4e00-\u9fa5]") && propName.ToUpper() == "DESCRIPTION")
{
return "货描存在中文字符";
}
if (Regex.IsMatch(sourceVal.ToString(), @"[\u4e00-\u9fa5]") && propName.ToUpper() == "BOOKINGNO")
{
return "订舱编号存在中文字符";
}
if (Regex.IsMatch(sourceVal.ToString(), @"[\u4e00-\u9fa5]") && propName.ToUpper() == "BOOKINGNO")
{
return "订舱编号存在中文字符";
}
if (Regex.IsMatch(sourceVal.ToString(), @"[\u4e00-\u9fa5]") && propName.ToUpper() == "PONO")
{
return "PONO存在中文字符";
}
}
}
}
return true;
return "";
}
}

Loading…
Cancel
Save