You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
BookingHeChuan/Myshipping.Application/Service/BookingOrderSeaeEdi/BookingOrderSeaeEdiService.cs

303 lines
11 KiB
C#

2 years ago
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.ConfigOption;
using System.IO;
using Yitter.IdGenerator;
using Myshipping.Core.Entity;
using Furion.RemoteRequest.Extensions;
using System.Net.Http;
using Myshipping.Core.Service;
using System.Reflection.Emit;
using Myshipping.Application.Service.BookingOrderSeaeEdi.Dto;
namespace Myshipping.Application
{
/// <summary>
/// 舱单服务
/// </summary>
[ApiDescriptionSettings("Application", Name = "BookingOrderSeaeEdi", Order = 1)]
public class BookingOrderSeaeEdiService : IBookingOrderSeaeEdiService, IDynamicApiController, ITransient
{
private readonly ILogger<BookingOrderSeaeEdiService> _logger;
private readonly SqlSugarRepository<BookingOrderSeaeEdi> _seaeedi;
private readonly SqlSugarRepository<BookingOrderSeaeEdiCtn> _seaeedictn;
public BookingOrderSeaeEdiService(ILogger<BookingOrderSeaeEdiService> logger, SqlSugarRepository<BookingOrderSeaeEdi> seaeedi, SqlSugarRepository<BookingOrderSeaeEdiCtn> seaeedictn)
{
this._logger = logger;
this._seaeedi = seaeedi;
this._seaeedictn = seaeedictn;
}
/// <summary>
/// 获取数据
/// </summary>
/// <param name="bookingId"></param>
/// <returns></returns>
[HttpGet("/BookingOrderSeaeEdi/PageESeaeEdi")]
public async Task<List<BookingOrderSeaeEdiServiceDto>> PageESeaeEdi(long bookingId)
{
var entities = await _seaeedi.AsQueryable().Filter(null, true).Where(x => x.BookingId == bookingId).ToListAsync();
var list = entities.Adapt<List<BookingOrderSeaeEdiServiceDto>>();
foreach (var item in list)
{
var ctn = await _seaeedictn.AsQueryable().Filter(null, true).Where(x => x.PId == item.Id).ToListAsync();
item.EdiCtn = ctn.Adapt<List<BookingOrderSeaeEdiCtnDto>>();
}
return list;
}
/// <summary>
/// 立即返回保存信息
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/BookingOrderSeaeEdi/Save")]
public async Task<dynamic> Save(BookingOrderSeaeEdiServiceDto input)
{
if (input == null)
{
throw Oops.Bah("请传入正常数据!");
}
if (!string.IsNullOrWhiteSpace(input.MBLNO))
{
var et = await _seaeedi.Where(x => x.MBLNO == input.MBLNO && x.TenantId == UserManager.TENANT_ID && x.HBLNO == input.HBLNO && x.Id != input.Id).FirstAsync();
if (et != null)
{
throw Oops.Bah("当前提单号已存在,请勿重复录入!");
}
}
var entity = input.Adapt<BookingOrderSeaeEdi>();
if (input.Id == 0)
{
await _seaeedi.InsertAsync(entity);
if (input.EdiCtn != null)
{
foreach (var item in input.EdiCtn)
{
var ctn = item.Adapt<BookingOrderSeaeEdiCtn>();
ctn.PId = entity.Id;
await _seaeedictn.InsertAsync(ctn);
}
}
}
else
{
await _seaeedi.AsUpdateable(entity).IgnoreColumns(it => new
{
it.MBLNO,
it.HBLNO,
it.BookingId,
it.TenantId,
it.CreatedTime,
it.CreatedUserId,
it.CreatedUserName,
it.IsDeleted
}).ExecuteCommandAsync();
await _seaeedictn.DeleteAsync(x => x.PId == input.Id);
if (input.EdiCtn != null)
{
foreach (var item in input.EdiCtn)
{
var ctn = item.Adapt<BookingOrderSeaeEdiCtn>();
ctn.PId = entity.Id;
await _seaeedictn.InsertAsync(ctn);
}
}
}
var entities = await _seaeedi.AsQueryable().Filter(null, true).Where(x => x.BookingId == entity.Id).ToListAsync();
var list = entities.Adapt<List<BookingOrderSeaeEdiServiceDto>>();
foreach (var item in list)
{
var ctn = await _seaeedictn.AsQueryable().Filter(null, true).Where(x => x.PId == item.Id).ToListAsync();
item.EdiCtn = ctn.Adapt<List<BookingOrderSeaeEdiCtnDto>>();
}
return list;
}
/// <summary>
/// 删除舱单
/// </summary>
/// <param name="Id"></param>
/// <returns></returns>
[SqlSugarUnitOfWork]
[HttpPost("/BookingOrderSeaeEdi/Delete")]
public async Task Delete(long Id)
{
await _seaeedi.UpdateAsync(x => x.Id == Id, x => new BookingOrderSeaeEdi { IsDeleted = true });
await _seaeedictn.UpdateAsync(x => x.PId == Id, x => new BookingOrderSeaeEdiCtn { IsDeleted = true });
_logger.LogInformation(Id + "删除成功!");
}
#region 舱单
///// <summary>
///// 舱单
///// </summary>
///// <param name="bookingId"></param>
///// <returns></returns>
//[HttpPost("/BookingOrderSeaeEdi/CustEDI")]
//public async Task CustEDI(long bookingId)
//{
// var order = _seaeedi.FirstOrDefault(x => x.BookingId == bookingId);
// var ctns = _seaeedictn.Where(x => x.BILLID == bookingId).ToList();
// //船公司
// if (string.IsNullOrEmpty(order.CARRIERID))
// {
// throw Oops.Bah(BookingErrorCode.BOOK118);
// }
// //提单号不能为空
// if (string.IsNullOrEmpty(order.MBLNO))
// {
// throw Oops.Bah(BookingErrorCode.BOOK127);
// }
// if (string.IsNullOrEmpty(order.YARDID))
// {
// throw Oops.Bah("场站未正确选择");
// }
// List<CustEDIDto> custEDIDtos = new List<CustEDIDto>();
// MDATA mDATA = new MDATA();
// mDATA.MBLNO = order.MBLNO;
// mDATA.HBLNO = order.HBLNO;
// mDATA.ETD = order.ETD == null ? "" : Convert.ToDateTime(order.ETD).ToString("yyyy-MM-dd");
// mDATA.FORWARDER = order.SHIPAGENCY;
// mDATA.VESSEL = order.VESSEL;
// mDATA.VOYNO = order.VOYNO;
// mDATA.CARRIER = order.CARRIERID;
// mDATA.SHIPPERNAME = order.SHIPPER;
// mDATA.SHIPPERADDR1 = order.SHIPPERADDR1;
// mDATA.SHIPPERCOUNTRY = order.SHIPPERCOUNTRY;
// mDATA.SHIPPERTEL = order.SHIPPERTEL;
// mDATA.CONSIGNEENAME = order.CONSIGNEE;
// mDATA.CONSIGNEEADDR1 = order.CONSIGNEEADDR1;
// mDATA.CONSIGNEECOUNTRY = order.CONSIGNEERCOUNTRY;
// mDATA.CONSIGNEETEL = order.CONSIGNEETEL;
// mDATA.NOTIFYPARTYNAME = order.NOTIFYPARTY;
// mDATA.NOTIFYPARTYADDR1 = order.NOTIFYPARTYADDR1;
// mDATA.NOTIFYPARTYCOUNTRY = order.NOTIFYPARTYCOUNTRY;
// mDATA.NOTIFYPARTYTEL = order.NOTIFYPARTYTEL;
// //var user = await _repUser.FirstOrDefaultAsync(x => x.Id == UserManager.UserId);
// // int idx = 1;
// // //调用接口
// // var dicUrl = _cache.GetAllDictData().Result.First(x => x.TypeCode == "url_set" && x.Code == "request_emf");
// // var sendObj = new
// // {
// // SystemCode = "djy_hechuan",
// // billOrderId = order.Id.ToString(),
// // sendOrderCode = order.MBLNO,
// // customerName = $"{UserManager.TENANT_NAME}+{UserManager.Name}", //公司名称+用户姓名
// // customerId = order.CUSTOMERID.ToString(),
// // agentName = string.IsNullOrEmpty(order.FORWARDER) ? UserManager.TENANT_NAME : order.FORWARDER,
// // carrierCode = order.CARRIERID,
// // userName = webacc.Account,
// // userPassword = webacc.Password,
// // depotCode = order.YARDID,
// // depotName = order.YARD,
// // linkName = UserManager.Name,
// // linkMobile = user.Phone,
// // linkEmail = user.Email,
// // userId = user.DjyUserId,
// // returnUrl = "",
// // shipName = order.VESSEL,
// // voyNo = order.VOYNO,
// // etdstr = order.ETD.HasValue ? order.ETD.Value.ToString("yyyy-MM-dd") : string.Empty,
// // potrSend = order.PORTLOAD,
// // potrGoal = order.PORTDISCHARGE,
// // boxinfoStr = order.CNTRTOTAL,
// // vgmEndTimeStr = order.CLOSEVGMDATE.HasValue ? order.CLOSEVGMDATE.Value.ToString("yyyy-MM-dd") : string.Empty,
// // BoxInfo = ctns.Select(c => new
// // {
// // index = idx++,
// // boxType = c.CTNALL,
// // boxcount = c.CTNNUM.HasValue ? c.CTNNUM.Value : 0,
// // code = c.CNTRNO,
// // sealCode = c.SEALNO,
// // weigth = c.KGS,
// // weigthTare = c.TAREWEIGHT,
// // weigthTotal = c.WEIGHKGS,
// // weigthType = c.WEIGHTYPE == "累加" ? "SM2" : "SM1"
// // }).ToList(),
// // returnOkUrl = ""
// // };
// // string strPostObj = sendObj.ToJsonString();
// // _logger.LogInformation($"调用VGM直发接口 {dicUrl.Value} 传递数据:{strPostObj}");
// // var strResp = await dicUrl.Value.SetBody(sendObj).PostAsStringAsync();
// // _logger.LogInformation($"调用VGM直发接口返回{strResp}");
// // var jobjResp = JObject.Parse(strResp);
// // int respCode = jobjResp.GetIntValue("code");
// // if (respCode != 200)
// // {
// // throw Oops.Bah(BookingErrorCode.BOOK128, jobjResp.GetStringValue("message"));
// // }
// // //货运动态
// // var bsl = new BookingStatusLog();
// // bsl.BookingId = bookingId;
// // bsl.Status = $"直发VGM";
// // bsl.OpTime = DateTime.Now;
// // bsl.Category = "ship";
// // bsl.MBLNO = order.MBLNO;
// // await _repStatuslog.InsertAsync(bsl);
//}
#endregion
}
}