using Myshipping.Core; using Furion.DependencyInjection; using Furion.DynamicApiController; using Mapster; using Microsoft.AspNetCore.Mvc; using SqlSugar; using System.Linq; using System.Threading.Tasks; using Myshipping.Application.Entity; using Microsoft.AspNetCore.Authorization; using Furion; using Microsoft.AspNetCore.Http; using Furion.DataEncryption; using System.Collections.Generic; using System.Security.Claims; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Identity; using Furion.FriendlyException; using Furion.Logging; using System; using Microsoft.Extensions.Logging; using System.Reflection; using System.ComponentModel; using Myshipping.Application.Service.BookingOrder.Dto; using Myshipping.Application.ConfigOption; using System.IO; using Yitter.IdGenerator; using Myshipping.Core.Entity; using Furion.RemoteRequest.Extensions; using System.Net.Http; namespace Myshipping.Application { /// /// 订舱服务 /// [ApiDescriptionSettings("Application", Name = "BookingOrder", Order = 1)] public class BookingOrderService : IBookingOrderService, IDynamicApiController, ITransient { private readonly SqlSugarRepository _rep; private readonly SqlSugarRepository _repCtn; private readonly SqlSugarRepository _ctndetailrep; private readonly SqlSugarRepository _bookinglog; private readonly SqlSugarRepository _bookinglogdetail; private readonly SqlSugarRepository _bookingremark; private readonly SqlSugarRepository _bookingfile; private readonly SqlSugarRepository _webconfig; private readonly SqlSugarRepository _dicdata; private readonly ILogger _logger; public BookingOrderService(SqlSugarRepository rep, SqlSugarRepository repCtn, SqlSugarRepository ctndetailrep, SqlSugarRepository bookinglog, SqlSugarRepository bookinglogdetail, SqlSugarRepository bookingremark, SqlSugarRepository bookingfile, SqlSugarRepository webconfig, SqlSugarRepository dicdata, ILogger logger) { this._logger = logger; this._rep = rep; this._repCtn = repCtn; this._ctndetailrep = ctndetailrep; this._bookinglog = bookinglog; this._bookinglogdetail = bookinglogdetail; this._bookingremark = bookingremark; this._bookingfile = bookingfile; this._webconfig = webconfig; this._dicdata = dicdata; } /// /// 分页查询订舱主表 /// /// /// [HttpGet("/BookingOrder/page")] public async Task Page([FromQuery] BookingOrderInput input) { List userlist = await DataFilterExtensions.GetDataScopeIdList(); var entities = await _rep.AsQueryable() .WhereIF(!string.IsNullOrWhiteSpace(input.BSSTATUS), u => u.BSSTATUS == input.BSSTATUS) .WhereIF(!string.IsNullOrWhiteSpace(input.MBLNO), u => input.MBLNO.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Contains(u.MBLNO)) .WhereIF(!string.IsNullOrWhiteSpace(input.HBLNO), u => input.HBLNO.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Contains(u.HBLNO)) .WhereIF(!string.IsNullOrWhiteSpace(input.BOOKINGNO), u => u.BOOKINGNO.IndexOf(input.BOOKINGNO) > -1) .WhereIF(!string.IsNullOrWhiteSpace(input.CONTRACTNO), u => u.CONTRACTNO.IndexOf(input.CONTRACTNO) > -1) .WhereIF(!string.IsNullOrWhiteSpace(input.SERVICECONTRACTNO), u => u.SERVICECONTRACTNO.IndexOf(input.SERVICECONTRACTNO) > -1) .WhereIF(!string.IsNullOrWhiteSpace(input.SHIPPER), u => u.SHIPPER.Contains(input.SHIPPER)) .WhereIF(!string.IsNullOrWhiteSpace(input.CONSIGNEE), u => u.CONSIGNEE.Contains(input.CONSIGNEE)) .WhereIF(!string.IsNullOrWhiteSpace(input.NOTIFYPARTY), u => u.NOTIFYPARTY.Contains(input.NOTIFYPARTY)) .WhereIF(!string.IsNullOrWhiteSpace(input.NOTIFYPARTY2), u => u.NOTIFYPARTY2.Contains(input.NOTIFYPARTY2)) .WhereIF(!string.IsNullOrWhiteSpace(input.YARDID), u => u.YARDID == input.YARDID) .WhereIF(!string.IsNullOrWhiteSpace(input.YARD), u => u.YARD == input.YARD) .WhereIF(!string.IsNullOrWhiteSpace(input.VESSELID), u => u.VESSELID.IndexOf(input.VESSELID) > -1) .WhereIF(!string.IsNullOrWhiteSpace(input.VESSEL), u => u.VESSEL.ToLower().IndexOf(u.VESSEL.ToLower()) > -1) .WhereIF(!string.IsNullOrWhiteSpace(input.VOYNO), u => u.VOYNO.IndexOf(input.VOYNO) > -1) .WhereIF(!string.IsNullOrWhiteSpace(input.VOYNOINNER), u => u.VOYNOINNER.IndexOf(input.VOYNOINNER) > -1) .WhereIF(!string.IsNullOrWhiteSpace(input.PLACERECEIPT), u => u.PLACERECEIPT.Contains(input.PLACERECEIPT)) .WhereIF(!string.IsNullOrWhiteSpace(input.PLACERECEIPTID), u => u.PLACERECEIPTID == input.PLACERECEIPTID) .WhereIF(!string.IsNullOrWhiteSpace(input.PORTLOAD), u => u.PORTLOAD.IndexOf(input.PORTLOAD) > -1) .WhereIF(!string.IsNullOrWhiteSpace(input.PORTDISCHARGE), u => u.PORTDISCHARGE.IndexOf(input.PORTDISCHARGE) > -1) .WhereIF(!string.IsNullOrWhiteSpace(input.PLACEDELIVERY), u => u.PLACEDELIVERY.Contains(input.PLACEDELIVERY)) .WhereIF(!string.IsNullOrWhiteSpace(input.PLACEDELIVERYID), u => u.PLACEDELIVERYID == input.PLACEDELIVERYID) .WhereIF(!string.IsNullOrWhiteSpace(input.DESTINATION), u => u.DESTINATION.Contains(input.DESTINATION)) .WhereIF(!string.IsNullOrWhiteSpace(input.DESTINATIONID), u => u.DESTINATIONID == input.DESTINATIONID) .WhereIF(!string.IsNullOrWhiteSpace(input.NOBILL), u => u.NOBILL == input.NOBILL) .WhereIF(!string.IsNullOrWhiteSpace(input.COPYNOBILLL), u => u.COPYNOBILLL == input.COPYNOBILLL) .WhereIF(!string.IsNullOrWhiteSpace(input.ISSUETYPE), u => u.ISSUETYPE == input.ISSUETYPE) .WhereIF(!string.IsNullOrWhiteSpace(input.ISSUEPLACE), u => u.ISSUEPLACE.Contains(input.ISSUEPLACE)) .WhereIF(!string.IsNullOrWhiteSpace(input.ISSUEPLACEID), u => u.ISSUEPLACEID == input.ISSUEPLACEID) .WhereIF(!string.IsNullOrWhiteSpace(input.BLFRT), u => u.BLFRT == input.BLFRT) .WhereIF(!string.IsNullOrWhiteSpace(input.PREPARDATID), u => u.PREPARDATID == input.PREPARDATID) .WhereIF(!string.IsNullOrWhiteSpace(input.PREPARDAT), u => u.PREPARDAT == input.PREPARDAT) .WhereIF(!string.IsNullOrWhiteSpace(input.PAYABLEAT), u => u.PAYABLEAT.Contains(input.PAYABLEAT)) .WhereIF(!string.IsNullOrWhiteSpace(input.PAYABLEATID), u => u.PAYABLEATID == input.PAYABLEATID) .WhereIF(!string.IsNullOrWhiteSpace(input.SERVICE), u => u.SERVICE.Contains(input.SERVICE)) .WhereIF(!string.IsNullOrWhiteSpace(input.MARKS), u => u.MARKS.Contains(input.MARKS)) .WhereIF(!string.IsNullOrWhiteSpace(input.HSCODE), u => u.HSCODE.IndexOf(input.HSCODE) > -1) .WhereIF(!string.IsNullOrWhiteSpace(input.DESCRIPTION), u => u.DESCRIPTION.Contains(input.DESCRIPTION)) .WhereIF(!string.IsNullOrWhiteSpace(input.KINDPKGS), u => u.KINDPKGS == input.KINDPKGS) .WhereIF(!string.IsNullOrWhiteSpace(input.CNTRTOTAL), u => u.CNTRTOTAL == input.CNTRTOTAL) .WhereIF(!string.IsNullOrWhiteSpace(input.CARRIERID), u => u.CARRIERID == input.CARRIERID) .WhereIF(!string.IsNullOrWhiteSpace(input.CARRIER), u => u.CARRIER.Contains(input.CARRIER)) .WhereIF(!string.IsNullOrWhiteSpace(input.CARGOID), u => u.CARGOID == input.CARGOID) .WhereIF(!string.IsNullOrWhiteSpace(input.DCLASS), u => u.DCLASS == input.DCLASS) .WhereIF(!string.IsNullOrWhiteSpace(input.DUNNO), u => u.DUNNO == input.DUNNO) .WhereIF(!string.IsNullOrWhiteSpace(input.DPAGE), u => u.DPAGE == input.DPAGE) .WhereIF(!string.IsNullOrWhiteSpace(input.DLABEL), u => u.DLABEL == input.DLABEL) .WhereIF(!string.IsNullOrWhiteSpace(input.LINKMAN), u => u.LINKMAN == input.LINKMAN) .WhereIF(!string.IsNullOrWhiteSpace(input.TEMPID), u => u.TEMPID == input.TEMPID) .WhereIF(!string.IsNullOrWhiteSpace(input.TEMPSET), u => u.TEMPSET == input.TEMPSET) .WhereIF(!string.IsNullOrWhiteSpace(input.REEFERF), u => u.REEFERF == input.REEFERF) .WhereIF(!string.IsNullOrWhiteSpace(input.HUMIDITY), u => u.HUMIDITY == input.HUMIDITY) .WhereIF(!string.IsNullOrWhiteSpace(input.TEMPMIN), u => u.TEMPMIN == input.TEMPMIN) .WhereIF(!string.IsNullOrWhiteSpace(input.TEMPMAX), u => u.TEMPMAX == input.TEMPMAX) .WhereIF(!input.ISCONTAINERSOC, u => u.ISCONTAINERSOC == input.ISCONTAINERSOC) .WhereIF(!string.IsNullOrWhiteSpace(input.SOREMARK), u => u.SOREMARK.Contains(input.SOREMARK)) .WhereIF(!string.IsNullOrWhiteSpace(input.SIREMARK), u => u.SIREMARK.Contains(input.SIREMARK)) .WhereIF(!string.IsNullOrWhiteSpace(input.YARDREMARK), u => u.YARDREMARK.Contains(input.YARDREMARK)) .WhereIF(!string.IsNullOrWhiteSpace(input.COMPID), u => u.COMPID == input.COMPID) .WhereIF(!string.IsNullOrWhiteSpace(input.COMPNAME), u => u.COMPNAME.IndexOf(input.COMPNAME) > -1) .WhereIF(!string.IsNullOrWhiteSpace(input.SHIPPERNAME), u => u.SHIPPERNAME.Contains(input.SHIPPERNAME)) .WhereIF(!string.IsNullOrWhiteSpace(input.SHIPPERCITY), u => u.SHIPPERCITY.Contains(input.SHIPPERCITY)) .WhereIF(!string.IsNullOrWhiteSpace(input.SHIPPERPROVINCE), u => u.SHIPPERPROVINCE == input.SHIPPERPROVINCE) .WhereIF(!string.IsNullOrWhiteSpace(input.SHIPPERPOSTCODE), u => u.SHIPPERPOSTCODE == input.SHIPPERPOSTCODE) .WhereIF(!string.IsNullOrWhiteSpace(input.SHIPPERCOUNTRY), u => u.SHIPPERCOUNTRY == input.SHIPPERCOUNTRY) .WhereIF(!string.IsNullOrWhiteSpace(input.SHIPPERATTN), u => u.SHIPPERATTN.Contains(input.SHIPPERATTN)) .WhereIF(!string.IsNullOrWhiteSpace(input.SHIPPERTEL), u => u.SHIPPERTEL == input.SHIPPERTEL) .WhereIF(!string.IsNullOrWhiteSpace(input.CONSIGNEENAME), u => u.CONSIGNEENAME.Contains(input.CONSIGNEENAME)) .WhereIF(!string.IsNullOrWhiteSpace(input.CONSIGNEECITY), u => u.CONSIGNEECITY.Contains(input.CONSIGNEECITY)) .WhereIF(!string.IsNullOrWhiteSpace(input.CONSIGNEEPROVINCE), u => u.CONSIGNEEPROVINCE == input.CONSIGNEEPROVINCE) .WhereIF(!string.IsNullOrWhiteSpace(input.CONSIGNEEPOSTCODE), u => u.CONSIGNEEPOSTCODE == input.CONSIGNEEPOSTCODE) .WhereIF(!string.IsNullOrWhiteSpace(input.CONSIGNEERCOUNTRY), u => u.CONSIGNEERCOUNTRY == input.CONSIGNEERCOUNTRY) .WhereIF(!string.IsNullOrWhiteSpace(input.CONSIGNEEATTN), u => u.CONSIGNEEATTN.Contains(input.CONSIGNEEATTN)) .WhereIF(!string.IsNullOrWhiteSpace(input.CONSIGNEETEL), u => u.CONSIGNEETEL == input.CONSIGNEETEL) .WhereIF(!string.IsNullOrWhiteSpace(input.NOTIFYPARTYNAME), u => u.NOTIFYPARTYNAME.Contains(input.NOTIFYPARTYNAME)) .WhereIF(!string.IsNullOrWhiteSpace(input.NOTIFYPARTYCITY), u => u.NOTIFYPARTYCITY.Contains(input.NOTIFYPARTYCITY)) .WhereIF(!string.IsNullOrWhiteSpace(input.NOTIFYPARTYPROVINCE), u => u.NOTIFYPARTYPROVINCE == input.NOTIFYPARTYPROVINCE) .WhereIF(!string.IsNullOrWhiteSpace(input.NOTIFYPARTYPOSTCODE), u => u.NOTIFYPARTYPOSTCODE == input.NOTIFYPARTYPOSTCODE) .WhereIF(!string.IsNullOrWhiteSpace(input.NOTIFYPARTYCOUNTRY), u => u.NOTIFYPARTYCOUNTRY == input.NOTIFYPARTYCOUNTRY) .WhereIF(!string.IsNullOrWhiteSpace(input.NOTIFYPARTYATTN), u => u.NOTIFYPARTYATTN.Contains(input.NOTIFYPARTYATTN)) .WhereIF(!string.IsNullOrWhiteSpace(input.NOTIFYPARTYTEL), u => u.NOTIFYPARTYTEL == input.NOTIFYPARTYTEL) .WhereIF(!string.IsNullOrWhiteSpace(input.PONO), u => u.PONO == input.PONO) .WhereIF(!string.IsNullOrWhiteSpace(input.OPID), u => u.OPID == input.OPID) .WhereIF(!string.IsNullOrWhiteSpace(input.DOCID), u => u.DOCID == input.DOCID) .WhereIF(!string.IsNullOrWhiteSpace(input.OP), u => u.OP == input.OP) .WhereIF(!string.IsNullOrWhiteSpace(input.DOC), u => u.DOC == input.DOC) .WhereIF(!string.IsNullOrWhiteSpace(input.SALEID), u => u.SALEID == input.SALEID) .WhereIF(!string.IsNullOrWhiteSpace(input.SALE), u => u.SALE.Contains(input.SALE)) .WhereIF(!string.IsNullOrWhiteSpace(input.CUSTSERVICEID), u => u.CUSTSERVICEID == input.CUSTSERVICEID) .WhereIF(!string.IsNullOrWhiteSpace(input.CUSTSERVICE), u => u.CUSTSERVICE.Contains(input.CUSTSERVICE)) .WhereIF(!string.IsNullOrWhiteSpace(input.CUSTOMERNAME), u => u.CUSTOMERNAME.Contains(input.CUSTOMERNAME)) .WhereIF(input.CUSTOMERID != 0, u => u.CUSTOMERID == input.CUSTOMERID) .WhereIF(!string.IsNullOrWhiteSpace(input.FORWARDER), u => u.FORWARDER.Contains(input.FORWARDER)) .WhereIF(!string.IsNullOrWhiteSpace(input.CUSTSERVICE), u => u.CUSTSERVICE == input.CUSTSERVICE) .WhereIF(!string.IsNullOrWhiteSpace(input.CUSTOMERNAME), u => u.CUSTOMERNAME == input.CUSTOMERNAME) .WhereIF(!string.IsNullOrWhiteSpace(input.FORWARDER), u => u.FORWARDER == input.FORWARDER) .WhereIF(!string.IsNullOrWhiteSpace(input.SHIPAGENCY), u => u.SHIPAGENCY == input.SHIPAGENCY) .WhereIF(!string.IsNullOrWhiteSpace(input.CUSTOMSER), u => u.CUSTOMSER == input.CUSTOMSER) .WhereIF(!string.IsNullOrWhiteSpace(input.TRUCKER), u => u.TRUCKER == input.TRUCKER) .WhereIF(!string.IsNullOrWhiteSpace(input.AGENTID), u => u.AGENTID == input.AGENTID) .WhereIF(!string.IsNullOrWhiteSpace(input.FORWARDERID), u => u.FORWARDERID == input.FORWARDERID) .WhereIF(!string.IsNullOrWhiteSpace(input.SHIPAGENCY), u => u.SHIPAGENCY.Contains(input.SHIPAGENCY)) .WhereIF(!string.IsNullOrWhiteSpace(input.SHIPAGENCYID), u => u.SHIPAGENCYID == input.SHIPAGENCYID) .WhereIF(!string.IsNullOrWhiteSpace(input.CUSTOMSER), u => u.CUSTOMSER.Contains(input.CUSTOMSER)) .WhereIF(!string.IsNullOrWhiteSpace(input.CUSTOMSERID), u => u.CUSTOMSERID == input.CUSTOMSERID) .WhereIF(!string.IsNullOrWhiteSpace(input.TRUCKER), u => u.TRUCKER.Contains(input.TRUCKER)) .WhereIF(!string.IsNullOrWhiteSpace(input.TRUCKERID), u => u.TRUCKERID == input.TRUCKERID) .WhereIF(!string.IsNullOrWhiteSpace(input.AGENTNAME), u => u.AGENTNAME.Contains(input.AGENTNAME)) .WhereIF(!string.IsNullOrWhiteSpace(input.AGENTID), u => u.AGENTID == input.AGENTID) .WhereIF(!string.IsNullOrWhiteSpace(input.WEITUO), u => u.WEITUO.Contains(input.WEITUO)) .WhereIF(!string.IsNullOrWhiteSpace(input.SCACCODE), u => u.SCACCODE == input.SCACCODE) .WhereIF(!string.IsNullOrWhiteSpace(input.ITNCODE), u => u.ITNCODE == input.ITNCODE) .WhereIF(!string.IsNullOrWhiteSpace(input.CUSTNO), u => u.CUSTNO.Contains(input.CUSTNO)) .WhereIF(!string.IsNullOrWhiteSpace(input.TRANSPORTID), u => u.TRANSPORTID == input.TRANSPORTID) .WhereIF(!string.IsNullOrWhiteSpace(input.TRANSPORT), u => u.TRANSPORT.Contains(input.TRANSPORT)) .WhereIF(!string.IsNullOrWhiteSpace(input.YARDCONTRACTTEL), u => u.YARDCONTRACTTEL == input.YARDCONTRACTTEL) .WhereIF(!string.IsNullOrWhiteSpace(input.YARDCONTRACTEMAIL), u => u.YARDCONTRACTEMAIL == input.YARDCONTRACTEMAIL) .WhereIF(!string.IsNullOrWhiteSpace(input.LANECODE), u => u.LANECODE == input.LANECODE) .WhereIF(!string.IsNullOrWhiteSpace(input.LANENAME), u => u.LANENAME.Contains(input.LANENAME)) .WhereIF(!string.IsNullOrWhiteSpace(input.FREIGHTPAYER), u => u.FREIGHTPAYER.Contains(input.FREIGHTPAYER)) .Where(u => userlist.Contains((long)u.CreatedUserId)) .ToPagedListAsync(input.PageNo, input.PageSize); return entities.XnPagedResult(); } /// /// 增加订舱 /// /// /// [SqlSugarUnitOfWork] [HttpPost("/BookingOrder/add")] public async Task Add(AddBookingOrderInput input) { JsonUtil.PropToUpper(input, "ORDNO", "BSSTATUS", "YardContract", "YardContractTel", "YardContractEmail"); 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); } var entity = input.Adapt(); await _rep.InsertAsync(entity); if (input.ctnInputs != null) { foreach (var item in input.ctnInputs) { var ctnentity = item.Adapt(); ctnentity.BILLID = entity.Id; await _repCtn.InsertAsync(ctnentity); foreach (var it in item.ctnDetailInputs) { var ctndetail = it.Adapt(); ctndetail.CTNID = ctnentity.Id; await _ctndetailrep.InsertAsync(ctndetail); } } } ////添加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 }); if (!string.IsNullOrWhiteSpace(input.YARDID) && !string.IsNullOrWhiteSpace(input.YARD) && !string.IsNullOrWhiteSpace(input.MBLNO)) { _logger.LogInformation("提单号:" + input.MBLNO + " 调用运踪接口"); var key = _webconfig.FirstOrDefault(x => x.TenantId == Convert.ToInt64(UserManager.TENANT_ID) && x.TypeCode == "seae_billtraceurl"); var url = _dicdata.FirstOrDefault(x => x.Code == "seae_billtraceurl"); BillTraceDto billdto = new BillTraceDto(); List billTraceList = new List(); billTraceList.Add(new BillTraceList { MBLNO = input.MBLNO, YARD = input.YARD, YardCode = input.YARDID, CARRIER=null, CARRIERID=null, isBook=false }); billdto.Children = billTraceList; billdto.Key = key.Account; billdto.PWD = key.Password; var json=billdto.ToJsonString(); var html= await url.Value.SetHttpMethod(HttpMethod.Post).SetQueries(new { msg = json }).SetRetryPolicy(3, 5000).SendAsAsync(); _logger.LogInformation("提单号:" + input.MBLNO + " 调用运踪接口返回"+ html.ToJsonString()); } } /// /// 删除订舱 /// /// /// [SqlSugarUnitOfWork] [HttpPost("/BookingOrder/delete")] public async Task Delete(long Id) { var ctnlist = await _repCtn.AsQueryable().Where(x => x.BILLID == Id).Select(x => x.Id).ToListAsync(); await _repCtn.UpdateAsync(x => x.BILLID == Id, x => new BookingCtn { IsDeleted = true }); await _ctndetailrep.UpdateAsync(x => ctnlist.Contains((long)x.CTNID), x => new BookingCtnDetail { IsDeleted = true }); _logger.LogInformation(Id + "删除成功!"); } /// /// 更新订舱 /// /// /// [SqlSugarUnitOfWork] [HttpPost("/BookingOrder/update")] public async Task Update(UpdateBookingOrderInput input) { JsonUtil.PropToUpper(input, "ORDNO", "BSSTATUS", "YardContract", "YardContractTel", "YardContractEmail"); 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); } var main = await _rep.FirstOrDefaultAsync(u => u.Id == input.Id); var entity = input.Adapt(); await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).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(); ctnentity.BILLID = entity.Id; await _repCtn.InsertAsync(ctnentity); foreach (var it in item.ctnDetailInputs) { var ctndetail = it.Adapt(); ctndetail.CTNID = ctnentity.Id; await _ctndetailrep.InsertAsync(ctndetail); } } } 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) { 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, }); if (descriptor.Name== "YARDID"|| descriptor.Name == "YARD"|| descriptor.Name == "MBLNO") { if (!string.IsNullOrWhiteSpace(input.YARDID) && !string.IsNullOrWhiteSpace(input.YARD) && !string.IsNullOrWhiteSpace(input.MBLNO)) { _logger.LogInformation("提单号:" + input.MBLNO + " 调用运踪接口"); var key = _webconfig.FirstOrDefault(x => x.TenantId == Convert.ToInt64(UserManager.TENANT_ID) && x.TypeCode == "seae_billtraceurl"); var url = _dicdata.FirstOrDefault(x => x.Code == "seae_billtraceurl"); BillTraceDto billdto = new BillTraceDto(); List billTraceList = new List(); billTraceList.Add(new BillTraceList { MBLNO = input.MBLNO, YARD = input.YARD, YardCode = input.YARDID, CARRIER = null, CARRIERID = null, isBook = false }); billdto.Children = billTraceList; billdto.Key = key.Account; billdto.PWD = key.Password; var json = billdto.ToJsonString(); var html = await url.Value.SetHttpMethod(HttpMethod.Post).SetQueries(new { msg = json }).SetRetryPolicy(3, 5000).SendAsAsync(); _logger.LogInformation("提单号:" + input.MBLNO + " 调用运踪接口返回" + html.ToJsonString()); } } } } } /// /// 获取订舱明细 /// /// /// [HttpGet("/BookingOrder/get")] public async Task Get(long Id) { BookingOrderOutput list = new BookingOrderOutput(); var main = await _rep.FirstOrDefaultAsync(u => u.Id == Id); if (main != null) { list = main.Adapt(); var ctnlist = await _repCtn.AsQueryable().Where(x => x.BILLID == Id).ToListAsync(); var ctninput = ctnlist.Adapt>(); foreach (var item in ctninput) { var ctndetaillist = await _ctndetailrep.AsQueryable().Where(x => x.CTNID == item.Id).ToListAsync(); item.ctnDetailInputs = ctndetaillist.Adapt>(); } list.ctnInputs = ctninput; } return list; } /// /// 获取日志明细 /// /// /// [HttpGet("/BookingOrder/getLog")] public async Task GetLog(long Id) { BookingLogDto list = new BookingLogDto(); var main = await _bookinglog.FirstOrDefaultAsync(u => u.BookingId == Id); if (main != null) { list = main.Adapt(); var details = await _bookinglogdetail.AsQueryable().Where(x => x.PId == main.Id).ToListAsync(); list.details = details; } return list; } /// /// 获取备注 /// /// /// [HttpGet("/BookingOrder/getRemark")] public async Task GetRemark(long Id) { var list = await _bookingremark.FirstOrDefaultAsync(u => u.PId == Id); return list; } /// /// 增加备注 /// /// /// [SqlSugarUnitOfWork] [HttpPost("/BookingOrder/addRemark")] public async Task AddRemark(BookingRemarkDto dto) { var entity = dto.Adapt(); await _bookingremark.InsertAsync(entity); } /// /// 增加订舱附件 /// /// /// /// [HttpPost("/BookingOrder/addFile")] public async Task AddFile(IFormFile file, [FromForm] BookingFileDto dto) { //未上传打印模板文件 if (file == null || file.Length == 0) { throw Oops.Oh(ErrorCode.BOOK113); } var opt = App.GetOptions(); var originalFilename = file.FileName; // 文件原始名称 var fileSuffix = Path.GetExtension(file.FileName).ToLower(); // 文件后缀 if (!opt.fileType.Contains(fileSuffix)) { throw Oops.Oh(ErrorCode.BOOK114); } var dirAbs = string.Empty; if (string.IsNullOrEmpty(opt.basePath)) { dirAbs = Path.Combine(App.WebHostEnvironment.WebRootPath, opt.relativePath); } else { dirAbs = Path.Combine(opt.basePath, opt.relativePath); } if (!Directory.Exists(dirAbs)) Directory.CreateDirectory(dirAbs); // 先存库获取Id var id = YitIdHelper.NextId(); var fileSaveName = $"{id}{fileSuffix}".ToLower(); var fileRelaPath = Path.Combine(opt.relativePath, fileSaveName).ToLower(); var fileAbsPath = Path.Combine(dirAbs, fileSaveName).ToLower(); var newFile = new BookingFile { Id = id, FileName = originalFilename, FilePath = fileRelaPath, TypeCode = dto.TypeCode, TypeName = dto.TypeName, TenantId = Convert.ToInt16(UserManager.TENANT_ID), TenantName = UserManager.CLAINM_TENANT_NAME, }; await _bookingfile.InsertAsync(newFile); using (var stream = File.Create(fileAbsPath)) { await file.CopyToAsync(stream); } } /// /// 获取附件 /// /// /// [HttpGet("/BookingOrder/getFile")] public async Task GetFile(long Id) { var list = await _bookingfile.FirstOrDefaultAsync(u => u.BookingId == Id); return list; } } }