新增save

optimize
wet 2 years ago
parent db5a21e2b1
commit fcd716392e

@ -329,6 +329,266 @@ namespace Myshipping.Application
return list;
}
/// <summary>
/// 立即返回保存信息
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/BookingOrder/Save")]
public async Task<BookingOrderOutput> Save(BookingOrderDto input){
if (input == null)
{
throw Oops.Bah("请传入正常数据!");
}
JsonUtil.PropToUpper(input, "ORDNO", "BSSTATUS", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME");
JsonUtil.TrimFields(input);
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)}");
input.CNTRTOTAL = string.Join(" / ", groupList);
}
if (!string.IsNullOrWhiteSpace(input.MBLNO))
{
var et = await _rep.Where(x => x.MBLNO == input.MBLNO && x.TenantId == UserManager.TENANT_ID && x.HBLNO == input.HBLNO && x.ParentId == input.ParentId && x.Id != input.Id).FirstAsync();
if (et != null)
{
throw Oops.Bah("当前提单号已存在,请勿重复录入!");
}
}
var entity = input.Adapt<BookingOrder>();
if (input.Id == 0)
{
entity.BOOKINGNO = Yitter.IdGenerator.YitIdHelper.NextId().ToString();
await _rep.InsertAsync(entity);
if (input.ctnInputs != null)
{
foreach (var item in input.ctnInputs)
{
var ctnentity = item.Adapt<BookingCtn>();
ctnentity.BILLID = entity.Id;
await _repCtn.InsertAsync(ctnentity);
//这里保存有可能没有添加多品名,所有箱下没有货物信息
if (item.ctnDetailInputs != null)
{
foreach (var it in item.ctnDetailInputs)
{
var ctndetail = it.Adapt<BookingCtnDetail>();
ctndetail.CTNID = ctnentity.Id;
await _ctndetailrep.InsertAsync(ctndetail);
}
}
}
}
if (input.BookingEDIExt != null)
{
//写入EDI扩展
var ediExt = input.BookingEDIExt.Adapt<BookingEDIExt>();
ediExt.BookingId = entity.Id;
await _bookingEDIExt.InsertAsync(ediExt);
}
////添加booking日志
await _bookinglog.InsertAsync(new BookingLog
{
Type = "Add",
BookingId = entity.Id,
TenantId = Convert.ToInt64(UserManager.TENANT_ID),
CreatedTime = DateTime.Now,
CreatedUserId = UserManager.UserId,
CreatedUserName = UserManager.Name
});
}
else
{
var mlist = await _rep.AsQueryable().Filter(null, true).Where(x => x.Id == input.Id).FirstAsync();
await _rep.AsUpdateable(entity).IgnoreColumns(it => new
{
it.ParentId,
it.TenantId,
it.CreatedTime,
it.CreatedUserId,
it.CreatedUserName,
it.TenantName,
it.IsDeleted,
it.BOOKINGNO
}).ExecuteCommandAsync();
var ctnlist = await _repCtn.AsQueryable().Where(x => x.BILLID == input.Id).Select(x => x.Id).ToListAsync();
await _repCtn.DeleteAsync(x => x.BILLID == input.Id);
await _ctndetailrep.DeleteAsync(x => ctnlist.Contains((long)x.CTNID));
if (input.ctnInputs != null)
{
foreach (var item in input.ctnInputs)
{
var ctnentity = item.Adapt<BookingCtn>();
ctnentity.BILLID = entity.Id;
await _repCtn.InsertAsync(ctnentity);
if (item.ctnDetailInputs != null)
{
foreach (var it in item.ctnDetailInputs)
{
var ctndetail = it.Adapt<BookingCtnDetail>();
ctndetail.CTNID = ctnentity.Id;
await _ctndetailrep.InsertAsync(ctndetail);
}
}
}
}
if (input.BookingEDIExt != null)
{
//检索EDI扩展
var ediExt = _bookingEDIExt.FirstOrDefault(u => u.BookingId == input.Id);
if (ediExt == null)
{
//写入EDI扩展
ediExt = input.BookingEDIExt.Adapt<BookingEDIExt>();
ediExt.BookingId = entity.Id;
await _bookingEDIExt.InsertAsync(ediExt);
}
else
{
//更新EDI扩展
var currEdiExtEntity = input.BookingEDIExt.Adapt<BookingEDIExt>();
currEdiExtEntity.Id = ediExt.Id;
currEdiExtEntity.BookingId = ediExt.BookingId;
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 = mlist.GetType().GetProperty(name).GetValue(mlist, 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 = UserManager.UserId,
CreatedUserName = UserManager.Name
});
flag = false;
}
await _bookinglogdetail.InsertReturnSnowflakeIdAsync(new BookingLogDetail
{
PId = bid,
Field = descriptor.Description,
OldValue = _oldvalue,
NewValue = _value,
});
}
}
}
var Id = entity.Id;
BookingOrderOutput ordOut = new BookingOrderOutput();
var main = await _rep.FirstOrDefaultAsync(u => u.Id == Id);
if (main != null)
{
ordOut = main.Adapt<BookingOrderOutput>();
var ctnlist = await _repCtn.AsQueryable().Where(x => x.BILLID == Id).ToListAsync();
var ctninput = ctnlist.Adapt<List<BookingCtnDto>>();
foreach (var item in ctninput)
{
var ctndetaillist = await _ctndetailrep.AsQueryable().Where(x => x.CTNID == item.Id).ToListAsync();
item.ctnDetailInputs = ctndetaillist.Adapt<List<BookingCtnDetailDto>>();
}
ordOut.ctnInputs = ctninput;
var ordUrl = _repOrderUrl.FirstOrDefault(x => x.BookingId == Id);
if (ordUrl != null)
{
ordOut.Link = new BookingOrderUrlOutput()
{
LinkUrlTxxp = ordUrl.UrlTxxp,
LinkUrlVgm = ordUrl.UrlVgm,
LinkUrlVmgSi = ordUrl.UrlVgmSi,
};
}
}
List<BookingOrderDto> HbList = new List<BookingOrderDto>();
var _hblist = await _rep.AsQueryable().Where(x => x.ParentId == Id).ToListAsync();
if (_hblist != null)
{
HbList = _hblist.Adapt<List<BookingOrderDto>>();
foreach (var item in HbList)
{
var ctnlist = await _repCtn.AsQueryable().Where(x => x.BILLID == item.Id).ToListAsync();
var ctninput = ctnlist.Adapt<List<BookingCtnDto>>();
foreach (var it in ctninput)
{
var ctndetaillist = await _ctndetailrep.AsQueryable().Where(x => x.CTNID == it.Id).ToListAsync();
it.ctnDetailInputs = ctndetaillist.Adapt<List<BookingCtnDetailDto>>();
}
item.ctnInputs = ctninput;
//检索EDI扩展
var ediExt = _bookingEDIExt.FirstOrDefault(u => u.BookingId == item.Id);
if (ediExt != null)
{
item.BookingEDIExt = ediExt.Adapt<BookingEDIExtDto>();
}
}
ordOut.HbList = HbList;
}
//检索EDI扩展
var ediExtEntity = _bookingEDIExt.FirstOrDefault(u => u.BookingId == Id);
if (ediExtEntity != null)
{
ordOut.BookingEDIExt = ediExtEntity.Adapt<BookingEDIExtDto>();
}
return ordOut;
}
[HttpPost("/BookingOrder/AddOrUpdate")]
public async Task<long> AddOrUpdate(BookingOrderDto Dto)
@ -337,6 +597,7 @@ namespace Myshipping.Application
{
throw Oops.Bah("请传入正常数据!");
}
if (Dto.Id == 0)
{
return await Add(Dto);
@ -357,31 +618,6 @@ namespace Myshipping.Application
[HttpPost("/BookingOrder/Add")]
public async Task<long> Add(BookingOrderDto input)
{
//if (input.ParentId == 0)
//{
// //if (!string.IsNullOrWhiteSpace(input.HBLNO))
// //{
// // throw Oops.Bah("主单不需要填写分单号");
// //}
// if (string.IsNullOrWhiteSpace(input.MBLNO))
// {
// throw Oops.Bah("请填写提单号!");
// }
//}
//else
//{
// if (string.IsNullOrWhiteSpace(input.MBLNO))
// {
// throw Oops.Bah("请填写主提单号");
// }
// if (string.IsNullOrWhiteSpace(input.HBLNO))
// {
// throw Oops.Bah("请填写分提单号");
// }
//}
JsonUtil.PropToUpper(input, "ORDNO", "BSSTATUS", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME");
JsonUtil.TrimFields(input);
if (input.ctnInputs != null)
@ -478,28 +714,7 @@ namespace Myshipping.Application
[HttpPost("/BookingOrder/Update")]
public async Task Update(BookingOrderDto input)
{
//if (input.ParentId == 0)
//{
// //if (!string.IsNullOrWhiteSpace(input.HBLNO))
// //{
// // throw Oops.Bah("主单不需要填写分单号");
// //}
// if (string.IsNullOrWhiteSpace(input.MBLNO))
// {
// throw Oops.Bah("请填写提单号!");
// }
//}
//else
//{
// if (string.IsNullOrWhiteSpace(input.MBLNO))
// {
// throw Oops.Bah("请填写主提单号");
// }
// if (string.IsNullOrWhiteSpace(input.HBLNO))
// {
// throw Oops.Bah("请填写分提单号");
// }
//}
JsonUtil.PropToUpper(input, "ORDNO", "BSSTATUS", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME");
JsonUtil.TrimFields(input);
if (input.ctnInputs != null)

Loading…
Cancel
Save