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

664 lines
29 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;
2 years ago
using Myshipping.Application.Enum;
using Myshipping.Application.Service.BookingOrder.Dto;
using Newtonsoft.Json.Linq;
using System.Text;
using System.Web;
using Furion.UnifyResult;
2 years ago
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;
2 years ago
private readonly ISysCacheService _cache;
2 years ago
private readonly IBookingOrderService _rep;
2 years ago
private readonly SqlSugarRepository<BookingStatusLog> _repStatuslog;
2 years ago
private readonly SqlSugarRepository<BookingOrderSeaeEdiTemplate> _repTemplate;
2 years ago
private readonly IDjyWebsiteAccountConfigService _webAccountConfig;
private readonly SqlSugarRepository<BookingOrder> _repBookingOrder;
private readonly SqlSugarRepository<BookingCtn> _repBookingCtn;
2 years ago
public BookingOrderSeaeEdiService(ILogger<BookingOrderSeaeEdiService> logger, SqlSugarRepository<BookingOrderSeaeEdi> seaeedi,
SqlSugarRepository<BookingOrderSeaeEdiCtn> seaeedictn, ISysCacheService cache, SqlSugarRepository<BookingStatusLog> repStatuslog,
SqlSugarRepository<BookingOrderSeaeEdiTemplate> repTemplate, IBookingOrderService rep,
IDjyWebsiteAccountConfigService webAccountConfig, SqlSugarRepository<BookingOrder> repBookingORder, SqlSugarRepository<BookingCtn> repBookingCtn)
2 years ago
{
this._logger = logger;
this._seaeedi = seaeedi;
this._seaeedictn = seaeedictn;
2 years ago
this._cache = cache;
this._repStatuslog = repStatuslog;
this._webAccountConfig = webAccountConfig;
2 years ago
this._repTemplate = repTemplate;
2 years ago
this._rep = rep;
this._repBookingOrder = repBookingORder;
this._repBookingCtn = repBookingCtn;
2 years ago
}
/// <summary>
/// 获取数据
/// </summary>
/// <param name="bookingId"></param>
/// <returns></returns>
[HttpGet("/BookingOrderSeaeEdi/PageESeaeEdi")]
public async Task<List<BookingOrderSeaeEdiServiceDto>> PageESeaeEdi(long bookingId)
{
2 years ago
var entities = await _seaeedi.AsQueryable().Filter(null, true).Where(x => x.BookingId == bookingId && x.IsDeleted == false).ToListAsync();
2 years ago
var list = entities.Adapt<List<BookingOrderSeaeEdiServiceDto>>();
foreach (var item in list)
{
2 years ago
var ctn = await _seaeedictn.AsQueryable().Filter(null, true).Where(x => x.PId == item.Id && x.IsDeleted == false).ToListAsync();
2 years ago
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("当前提单号已存在,请勿重复录入!");
}
}
BookingOrderSeaeEdi entity = null;
2 years ago
if (input.Id == 0)
{
entity = input.Adapt<BookingOrderSeaeEdi>();
entity.State = "已录入";
2 years ago
if (!string.IsNullOrEmpty(entity.CARRIERID))
{
2 years ago
entity.CARRIER = _cache.GetAllCodeCarrier().Result.Where(x => x.Code == entity.CARRIERID).Select(x => x.EdiCode).FirstOrDefault();
}
1 year ago
if (entity.CARGOID != "D")
{
2 years ago
entity.DCLASS = string.Empty;
entity.DUNNO = string.Empty;
}
2 years ago
2 years ago
await _seaeedi.InsertAsync(entity);
if (input.EdiCtn != null)
{
foreach (var item in input.EdiCtn)
{
var ctn = item.Adapt<BookingOrderSeaeEdiCtn>();
ctn.PId = entity.Id;
2 years ago
if (ctn.CTNALL.Length == 4)
{
2 years ago
ctn.SIZE = ctn.CTNALL != null ? ctn.CTNALL.Substring(0, 2) : "";
2 years ago
ctn.CTN = ctn.CTNALL != null ? ctn.CTNALL.Substring(2, 2) : "";
2 years ago
}
2 years ago
if (ctn.CTNALL.Contains("'"))
{
2 years ago
ctn.SIZE = ctn.CTNALL.Split("'")[0].ToString();
ctn.CTN = ctn.CTNALL.Split("'")[1].ToString();
2 years ago
}
2 years ago
2 years ago
await _seaeedictn.InsertAsync(ctn);
}
}
}
else
{
entity = _seaeedi.AsQueryable().First(x => x.Id == input.Id);
if (entity == null)
{
throw Oops.Bah("未找到业务数据");
}
if (entity.State != "已录入")
{
if (input.State != entity.State)
{
input.State = entity.State; //防止前端数据覆盖状态
}
if (input.HBLNO != entity.HBLNO)
{
throw Oops.Bah("已直发状态不能修改分单号");
}
}
//校验数据可修改后,赋值前端数据
input.Adapt(entity);
2 years ago
if (!string.IsNullOrEmpty(entity.CARRIERID))
{
entity.CARRIER = _cache.GetAllCodeCarrier().Result.Where(x => x.Code == entity.CARRIERID).Select(x => x.EdiCode).FirstOrDefault();
}
1 year ago
2 years ago
if (entity.CARGOID != "D")
{
entity.DCLASS = string.Empty;
entity.DUNNO = string.Empty;
}
2 years ago
await _seaeedi.AsUpdateable(entity).IgnoreColumns(it => new
{
it.MBLNO,
//it.HBLNO, //2023年9月4日原有直接忽略的逻辑有问题应该是直发之后不能改而不是录入状态就不能改分单号
2 years ago
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;
2 years ago
if (ctn.CTNALL.Length == 4)
{
ctn.SIZE = ctn.CTNALL != null ? ctn.CTNALL.Substring(0, 2) : "";
2 years ago
ctn.CTN = ctn.CTNALL != null ? ctn.CTNALL.Substring(2, 2) : "";
2 years ago
2 years ago
}
if (ctn.CTNALL.Contains("'"))
{
ctn.SIZE = ctn.CTNALL.Split("'")[0].ToString();
ctn.CTN = ctn.CTNALL.Split("'")[1].ToString();
2 years ago
}
2 years ago
await _seaeedictn.InsertAsync(ctn);
}
}
}
2 years ago
var entities = await _seaeedi.AsQueryable().Filter(null, true).Where(x => x.Id == entity.Id).ToListAsync();
2 years ago
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>
2 years ago
/// <param name="Ids"></param>
2 years ago
/// <returns></returns>
[SqlSugarUnitOfWork]
2 years ago
2 years ago
[HttpPost("/BookingOrderSeaeEdi/Delete")]
2 years ago
public async Task Delete(string Ids)
2 years ago
{
2 years ago
var arr = Ids.Split(",");
if (arr.Count() > 0)
{
foreach (var ar in arr)
{
long Id = Convert.ToInt64(ar);
await _seaeedi.UpdateAsync(x => x.Id == Id, x => new BookingOrderSeaeEdi { IsDeleted = true });
2 years ago
2 years ago
await _seaeedictn.UpdateAsync(x => x.PId == Id, x => new BookingOrderSeaeEdiCtn { IsDeleted = true });
_logger.LogInformation(Id + "删除成功!");
}
}
2 years ago
}
#region 舱单
2 years ago
/// <summary>
/// 舱单
/// </summary>
/// <returns></returns>
[HttpPost("/BookingOrderSeaeEdi/CustEDI")]
public async Task CustEDI(string Ids, string type, string SENDREMARK, bool? isCheck)
2 years ago
{
2 years ago
var arr = Ids.Split(",");
if (arr.Count() > 0)
{
1 year ago
List<CustEDIDto> custEDIDtos = new List<CustEDIDto>();
var key = _webAccountConfig.GetAccountConfig("DjyCangDan", UserManager.UserId).Result;
if (key == null)
{
throw Oops.Bah("当前用户未配置key,请联系管理员");
}
var dicUrl = _cache.GetAllDictData().Result.First(x => x.TypeCode == "url_set" && x.Code == "request_emf");
var waitCheckSeaList = new List<BookingOrderSeaeEdi>();
var waitCheckSeaCtnList = new List<BookingOrderSeaeEdiCtn>();
1 year ago
2 years ago
foreach (var ar in arr)
2 years ago
{
2 years ago
long Id = Convert.ToInt64(ar);
var order = await _seaeedi.AsQueryable().Filter(null, true).Where(x => x.Id == Id).FirstAsync();
2 years ago
var ctns = await _seaeedictn.AsQueryable().Filter(null, true).Where(x => x.PId == order.Id).ToListAsync();
//船公司
2 years ago
if (string.IsNullOrEmpty(order.CARRIER))
2 years ago
{
throw Oops.Bah(BookingErrorCode.BOOK118);
}
//提单号不能为空
if (string.IsNullOrEmpty(order.MBLNO))
{
throw Oops.Bah(BookingErrorCode.BOOK127);
}
2 years ago
2 years ago
MDATA mDATA = new MDATA();
List<CTNDATAItem> CTNDATA = new List<CTNDATAItem>();
mDATA = order.Adapt<MDATA>();
2 years ago
if (string.IsNullOrEmpty(mDATA.FORWARDER))
{
2 years ago
throw Oops.Bah("船代不能为空");
}
if (string.IsNullOrEmpty(mDATA.YARDID))
{
throw Oops.Bah("场站不能为空");
}
2 years ago
mDATA.SENDREMARK = SENDREMARK;
2 years ago
var FORWARDER = mDATA.FORWARDER;
2 years ago
var YardCode = mDATA.YARDID;
2 years ago
if (_cache.GetAllMappingForwarder().Result.Where(x => x.Code == FORWARDER && x.Module == "cangdan").Select(x => x.MapCode).FirstOrDefault() == null)
2 years ago
{
throw Oops.Bah("暂不支持此船代");
}
2 years ago
mDATA.FORWARDER =
2 years ago
_cache.GetAllMappingForwarder().Result.Where(x => x.Code == FORWARDER && x.Module == "cangdan").Select(x => x.MapCode).FirstOrDefault();
2 years ago
1 year ago
mDATA.YARDID = _cache.GetAllMappingYard().Result.Where(x => x.Code == YardCode && x.Module == "cangdan").Select(x => x.MapCode).FirstOrDefault();
2 years ago
CTNDATA = ctns.Adapt<List<CTNDATAItem>>();
2 years ago
foreach (var item in CTNDATA)
{
item.KINDPKGS = _cache.GetAllCodePackage().Result.Where(x => x.Name == item.KINDPKGS).Select(x => x.EdiCode).FirstOrDefault();
}
custEDIDtos.Add(new CustEDIDto
{
MDATA = mDATA,
CTNDATA = CTNDATA
});
waitCheckSeaList.Add(order);
waitCheckSeaCtnList.AddRange(ctns);
}
#region 舱单发送前,校验
if (isCheck == true && (type is "1" or "0"))
{
var checkResult = new List<string>();
// 需要在舱单发送前增加以下字段的比对,由舱单字段与订舱数据字段做比对,比对存在异常提醒客户是否确认发送,对比字段如下:
// 主单提单号:主单主单提单号与订舱主提单号不一致时提醒
// 船名航次,唛头,货描 ,起运港,卸货港:主单与订舱 或 分单与主单不一致时提醒
// 件数,重量,尺码(按箱子判断):分单之和>主单 或 主单 != 订舱 时提醒
// 箱封号、箱型:主单的箱封号+箱型与订舱不一致时提醒、分单中出现主单中不存在的箱封号+箱型时提醒
// 订舱主键
var bkOrderId = waitCheckSeaList[0].BookingId;
// 订舱记录
var bkOrder = await _repBookingOrder.AsQueryable()
.Filter(null, true)
.Where(x => x.Id == bkOrderId && x.IsDeleted == false)
.FirstAsync();
if (bkOrder == null)
{
throw Oops.Bah("未找到订舱数据");
}
var = await _repBookingCtn.AsQueryable()
.Filter(null, true)
.Where(x => x.BILLID == bkOrderId && x.IsDeleted == false)
.ToListAsync();
// 舱单主单
var mainSeaOrder = waitCheckSeaList.FirstOrDefault(x => string.IsNullOrWhiteSpace(x.HBLNO));
// 是否检验舱单主单
var isCheckMainSea = true;
if (mainSeaOrder == null)
{
isCheckMainSea = false;
mainSeaOrder = await _seaeedi.AsQueryable().Filter(null, true).Where(x => x.BookingId == bkOrderId && string.IsNullOrWhiteSpace(x.HBLNO)).FirstAsync();
}
// 舱单分单
var subSeaOrderList = waitCheckSeaList.Where(x => !string.IsNullOrWhiteSpace(x.HBLNO)).ToList();
// 校验1船名航次唛头货描 ,起运港,卸货港,主单提单号
if (isCheckMainSea)
{
if (bkOrder.MBLNO != mainSeaOrder.MBLNO) checkResult.Add("舱单主单与订舱【提单号】不一致");
if (bkOrder.VESSEL != mainSeaOrder.VESSEL) checkResult.Add("舱单主单与订舱【船名】不一致");
if (bkOrder.VOYNO != mainSeaOrder.VOYNO) checkResult.Add("舱单主单与订舱【航次】不一致");
if (bkOrder.MARKS != mainSeaOrder.MARKS) checkResult.Add("舱单主单与订舱【唛头】不一致");
if (bkOrder.DESCRIPTION != mainSeaOrder.DESCRIPTION) checkResult.Add("舱单主单与订舱【货描】不一致");
if (bkOrder.PORTLOADID != mainSeaOrder.PORTLOADID || bkOrder.PORTLOAD != mainSeaOrder.PORTLOAD) checkResult.Add("舱单主单与订舱【起运港】不一致");
if (bkOrder.PORTDISCHARGEID != mainSeaOrder.PORTDISCHARGEID || bkOrder.PORTDISCHARGE != mainSeaOrder.PORTDISCHARGE) checkResult.Add("舱单主单与订舱【卸货港】不一致");
}
subSeaOrderList.ForEach(x =>
{
if (bkOrder.VESSEL != x.VESSEL) checkResult.Add($"舱单分单【{x.HBLNO}】与订舱【船名】不一致");
if (bkOrder.VOYNO != x.VOYNO) checkResult.Add($"舱单分单【{x.HBLNO}】与订舱【航次】不一致");
if (bkOrder.MARKS != x.MARKS) checkResult.Add($"舱单分单【{x.HBLNO}】与订舱【唛头】不一致");
if (bkOrder.DESCRIPTION != x.DESCRIPTION) checkResult.Add($"舱单分单【{x.HBLNO}】与订舱【货描】不一致");
if (bkOrder.PORTLOADID != x.PORTLOADID || bkOrder.PORTLOAD != x.PORTLOAD) checkResult.Add($"舱单分单【{x.HBLNO}】与订舱【起运港】不一致");
if (bkOrder.PORTDISCHARGEID != x.PORTDISCHARGEID || bkOrder.PORTDISCHARGE != x.PORTDISCHARGE) checkResult.Add($"舱单分单【{x.HBLNO}】与订舱【卸货港】不一致");
});
// 校验2件重尺
var = waitCheckSeaCtnList.Where(x => x.PId == mainSeaOrder.Id).ToList();
var = waitCheckSeaCtnList.Where(x => x.PId != mainSeaOrder.Id).ToList();
if (isCheckMainSea)
{
foreach (var item in .GroupBy(x => x.CNTRNO))
{
if (item.Sum(x => x.PKGS) != .Where(x => x.CNTRNO == item.Key).Sum(x => x.PKGS))
{
checkResult.Add($"箱号为【{item.Key}】的箱子,在舱单主单中的【件数】与订舱中同箱号箱子的【件数】不一致");
}
if (item.Sum(x => x.KGS) != .Where(x => x.CNTRNO == item.Key).Sum(x => x.KGS))
{
checkResult.Add($"箱号为【{item.Key}】的箱子,在舱单主单中的【重量】与订舱中同箱号箱子的【重量】不一致");
}
if (item.Sum(x => x.CBM) != .Where(x => x.CNTRNO == item.Key).Sum(x => x.CBM))
{
checkResult.Add($"箱号为【{item.Key}】的箱子,在舱单主单中的【尺码】与订舱中同箱号箱子的【尺码】不一致");
}
}
}
foreach (var item in .GroupBy(x => x.CNTRNO))
{
if (item.Sum(x => x.PKGS) > .Where(x => x.CNTRNO == item.Key).Sum(x => x.PKGS))
{
checkResult.Add($"箱号为【{item.Key}】的箱子,在舱单各分单中的【总件数】大于订舱中同箱号箱子的件数");
}
if (item.Sum(x => x.KGS) > .Where(x => x.CNTRNO == item.Key).Sum(x => x.KGS))
{
checkResult.Add($"箱号为【{item.Key}】的箱子,在舱单各分单中的【总重量】大于订舱中同箱号箱子的重量");
}
if (item.Sum(x => x.CBM) > .Where(x => x.CNTRNO == item.Key).Sum(x => x.CBM))
{
checkResult.Add($"箱号为【{item.Key}】的箱子,在舱单各分单中的【总尺码】大于订舱中同箱号箱子的尺码");
}
}
// 校验3箱号+封号+箱型
var = .Select(x => $"箱号[{x.CNTRNO}] 封号[{x.SEALNO}] 箱型[{x.CTNALL.Replace("'", "")}]").ToList();
var = .Select(x => $"箱号[{x.CNTRNO}] 封号[{x.SEALNO}] 箱型[{x.CTNALL.Replace("'", "")}]").ToList();
var = .Select(x => $"箱号[{x.CNTRNO}] 封号[{x.SEALNO}] 箱型[{x.CTNALL.Replace("'", "")}]").Distinct().ToList();
if (isCheckMainSea)
{
var list1 = .Except();
if (list1.Any())
{
checkResult.Add($"订舱中的下列箱信息在舱单主单中不存在:{string.Join("", list1)}");
}
else
{
var list2 = .Except();
if (list2.Any())
{
checkResult.Add($"舱单主单中的下列箱信息在订舱中不存在:{string.Join("", list2)}");
}
}
}
var list3 = .Except();
if (list3.Any())
{
checkResult.Add($"舱单分单中存在未知的箱信息:{string.Join("", list3)}");
}
if (checkResult.Count > 0)
{
UnifyContext.Fill(new { checkResult });
throw new Exception("校验不通过");
}
1 year ago
}
#endregion
2 years ago
1 year ago
string strPostObj = custEDIDtos.ToJsonString();
var sendObj = new
{
ac = "emf",
uid = UserManager.DjyUserId,
skey = key.Password,
optype = type,
data = strPostObj
};
_logger.LogInformation($"调用舱单接口 {dicUrl.Value} 传递数据:{strPostObj}");
var strResp = await dicUrl.Value.SetContentType("multipart/form-data").SetBody(sendObj).PostAsStringAsync();
_logger.LogInformation($"调用舱单接口返回:{strResp}");
var jobjResp = JObject.Parse(strResp);
bool respCode = jobjResp.GetBooleanValue("Success");
if (respCode == false)
{
throw Oops.Bah(jobjResp.GetStringValue("Message").Replace("<br />", "\r\n").Replace("<br/>", ""));
}
foreach (var ar in arr)
{
long Id = Convert.ToInt64(ar);
var order = await _seaeedi.AsQueryable().Filter(null, true).Where(x => x.Id == Id).FirstAsync();
2 years ago
//货运动态
var bsl = new BookingStatusLog();
2 years ago
bsl.BookingId = order.BookingId;
2 years ago
if (type == "3")
{
2 years ago
bsl.Status = $"保存舱单";
}
if (type == "0")
{
bsl.Status = $"直发舱单";
}
if (type == "1")
{
bsl.Status = $"修改舱单";
}
2 years ago
if (type == "2")
{
bsl.Status = $"删除舱单";
}
2 years ago
if (type == "4")
{
bsl.Status = $"作废舱单";
}
2 years ago
bsl.OpTime = DateTime.Now;
bsl.Category = "ship";
bsl.MBLNO = order.MBLNO;
await _repStatuslog.InsertAsync(bsl);
2 years ago
if (type == "3")
{
2 years ago
await _seaeedi.UpdateAsync(x => x.Id == Id, x => new BookingOrderSeaeEdi { State = "已发送", SENDREMARK = SENDREMARK });
2 years ago
}
1 year ago
if (type == "0" || type == "1")
2 years ago
{
await _seaeedi.UpdateAsync(x => x.Id == Id, x => new BookingOrderSeaeEdi { State = "已直发", SENDREMARK = SENDREMARK });
if (string.IsNullOrEmpty(order.HBLNO))
{
1 year ago
await _rep.SetGoodsStatus("YFCD", order.BookingId);
await _rep.SendBookingOrder(new long[] { order.BookingId });
}
2 years ago
}
2 years ago
if (type == "2")
{
2 years ago
await _seaeedi.UpdateAsync(x => x.Id == Id, x => new BookingOrderSeaeEdi { State = "已删除", SENDREMARK = SENDREMARK });
2 years ago
}
if (type == "4")
{
2 years ago
await _seaeedi.UpdateAsync(x => x.Id == Id, x => new BookingOrderSeaeEdi { State = "已作废", SENDREMARK = SENDREMARK });
2 years ago
}
1 year ago
}
2 years ago
}
2 years ago
}
#endregion
2 years ago
2 years ago
#region 模板
/// <summary>
/// 获取模板数据
/// </summary>
/// <returns></returns>
[HttpGet("/BookingOrderSeaeEdi/GetBookingOrderSeaeEdiTemplateList")]
public async Task<List<BookingOrderSeaeEdiTemplateDto>> GetBookingOrderSeaeEdiTemplateList(string type, string templatename = null)
{
var entities = await _repTemplate.AsQueryable().Where(x => x.Type == type).
WhereIF(!string.IsNullOrEmpty(templatename), x => x.TemplateName.Contains(templatename)).
ToListAsync();
var list = entities.Adapt<List<BookingOrderSeaeEdiTemplateDto>>();
return list;
}
/// <summary>
/// 保存信息
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/BookingOrderSeaeEdi/SaveBookingOrderSeaeEdiTemplate")]
public async Task SaveBookingOrderSeaeEdiTemplate(BookingOrderSeaeEdiTemplateDto input)
{
if (input == null)
{
throw Oops.Bah("请传入正常数据!");
}
if (!string.IsNullOrWhiteSpace(input.TemplateNAME))
{
var et = await _repTemplate.Where(x => x.TemplateName == input.TemplateNAME && x.Id != input.Id).FirstAsync();
if (et != null)
{
throw Oops.Bah("当前模板名称已存在,请勿重复录入!");
}
}
var entity = input.Adapt<BookingOrderSeaeEdiTemplate>();
if (input.Id == 0)
{
await _repTemplate.InsertAsync(entity);
}
else
{
await _repTemplate.AsUpdateable(entity).IgnoreColumns(it => new
{
it.TenantId,
it.CreatedTime,
it.CreatedUserId,
it.CreatedUserName,
it.IsDeleted
}).ExecuteCommandAsync();
}
}
/// <summary>
/// 删除舱单
/// </summary>
/// <param name="Ids"></param>
/// <returns></returns>
[SqlSugarUnitOfWork]
[HttpPost("/BookingOrderSeaeEdi/DeleteBookingOrderSeaeEdiTemplate")]
public async Task DeleteBookingOrderSeaeEdiTemplate(string Ids)
{
var arr = Ids.Split(",");
if (arr.Count() > 0)
{
foreach (var ar in arr)
{
long Id = Convert.ToInt64(ar);
await _repTemplate.UpdateAsync(x => x.Id == Id, x => new BookingOrderSeaeEdiTemplate { IsDeleted = true });
}
}
}
#endregion
2 years ago
}
}