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/BookingTruck/BookingTruckService.cs

506 lines
15 KiB
C#

using Furion;
using Furion.DependencyInjection;
using Furion.DistributedIDGenerator;
using Furion.DynamicApiController;
using Furion.FriendlyException;
using Furion.JsonSerialization;
using Furion.RemoteRequest.Extensions;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Myshipping.Application.Entity;
using Myshipping.Core;
using Myshipping.Core.Entity;
using Myshipping.Core.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace Myshipping.Application
{
/// <summary>
/// 派车服务
/// </summary>
[ApiDescriptionSettings("Application", Name = "BookingTruck", Order = 9)]
public class BookingTruckService : IBookingTruckService, IDynamicApiController, ITransient
{
private readonly ISysCacheService _cache;
private readonly ILogger<BookingTruckService> _logger;
private readonly SqlSugarRepository<BookingTruck> _bookingTruckRepository;
private readonly SqlSugarRepository<BookingTruckCtn> _bookingTruckContaRepository;
2 years ago
private readonly SqlSugarRepository<BookingOrder> _bookingOrderRepository;
private readonly SqlSugarRepository<BookingCtn> _bookingCtnRepository;
public BookingTruckService(ISysCacheService cache, ILogger<BookingTruckService> logger,
SqlSugarRepository<BookingTruck> bookingTruckRepository,
2 years ago
SqlSugarRepository<BookingTruckCtn> bookingTruckContaRepository,
SqlSugarRepository<BookingOrder> bookingOrderRepository,
SqlSugarRepository<BookingCtn> bookingCtnRepository)
{
_cache = cache;
_logger = logger;
_bookingTruckRepository = bookingTruckRepository;
_bookingTruckContaRepository = bookingTruckContaRepository;
2 years ago
_bookingOrderRepository = bookingOrderRepository;
_bookingCtnRepository = bookingCtnRepository;
}
/// <summary>
/// 保存派车
/// </summary>
/// <param name="info">派车信息</param>
/// <returns>返回回执</returns>
2 years ago
[HttpPost("/BookingTruck/Save")]
public async Task<TaskManageOrderResultDto> Save(BookingTruckDto info)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
2 years ago
BookingTruck entity = info.Adapt<BookingTruck>();
if(entity == null)
throw Oops.Oh($"派车信息不能为空");
List<BookingTruckCtn> entityCtnList = info.ContaList.Adapt<List<BookingTruckCtn>>();
if (entity.Id == 0)
{
_bookingTruckRepository.Insert(entity);
if (entityCtnList.Count > 0)
{
entityCtnList.ForEach(async ctn =>
{
ctn.TruckId = entity.Id;
await _bookingTruckContaRepository.InsertAsync(ctn);
});
}
}
else
{
await _bookingTruckRepository.AsUpdateable(entity).IgnoreColumns(it => new
{
it.TenantId,
it.CreatedTime,
it.CreatedUserId,
it.CreatedUserName,
it.IsDeleted,
it.BookingId,
it.TruckId,
it.TruckName,
it.TruckCode,
}).ExecuteCommandAsync();
if (entityCtnList.Count > 0)
{
entityCtnList.ForEach(async ctn =>
{
ctn.TruckId = entity.Id;
await _bookingTruckContaRepository.AsUpdateable(ctn).IgnoreColumns(it => new
{
it.TenantId,
it.CreatedTime,
it.CreatedUserId,
it.CreatedUserName,
it.IsDeleted,
}).ExecuteCommandAsync();
});
}
}
result.succ = true;
result.msg = "保存成功";
result.ext = entity.Id;
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"保存派车异常,原因:{ex.Message}";
}
return result;
}
/// <summary>
/// 获取派车详情
/// </summary>
/// <param name="id">派车主键</param>
/// <returns>返回回执</returns>
[HttpGet("/BookingTruck/GetInfo")]
public async Task<TaskManageOrderResultDto> GetInfo(long id)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
var truckOrder = _bookingTruckRepository.AsQueryable().First(a => a.Id == id);
if (truckOrder == null)
throw Oops.Oh($"派车主键{id}无法获取业务信息");
2 years ago
var truckCtnList = _bookingTruckContaRepository.AsQueryable().Where(a => a.TruckId == id).ToList();
BookingTruckShowDto model = truckOrder.Adapt<BookingTruckShowDto>();
if (truckCtnList.Count > 0)
model.ContaList = truckCtnList.Adapt<List<BookingTruckCtnDto>>();
result.succ = true;
result.ext = model;
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"获取派车详情异常,原因:{ex.Message}";
}
2 years ago
return result;
}
/// <summary>
/// 订舱生成派车初始信息
/// </summary>
/// <param name="bookingId">订舱主键</param>
/// <returns>返回派车初始信息</returns>
[HttpGet("/BookingTruck/InitFromBookingOrder")]
public async Task<TaskManageOrderResultDto> InitFromBookingOrder(long bookingId)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
var model = InnerCreateTruckFromBookingOrder(bookingId);
result.succ = true;
result.ext = model;
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"订舱生成派车初始信息异常,原因:{ex.Message}";
}
return result;
}
private BookingTruckDto InnerCreateTruckFromBookingOrder(long bookingId)
{
BookingTruckDto model = null;
//取订舱主信息
var orderInfo = _bookingOrderRepository.AsQueryable()
.First(a => a.Id == bookingId);
if (orderInfo == null)
throw Oops.Oh($"订舱主键{bookingId}无法获取业务信息");
model = new BookingTruckDto();
model.YARDID = orderInfo.YARDID;
model.YARD = orderInfo.YARD;
model.ClosingTime = orderInfo.CLOSINGDATE;
model.InYardID = orderInfo.YARDID;
model.InYard = orderInfo.YARD;
model.FromName = UserManager.Name;
model.FromTel = UserManager.TEl;
model.FromMail = UserManager.Email;
if (orderInfo.KGS.HasValue)
{
//计算总吨数
model.KGS = Math.Round(orderInfo.KGS.Value / 1000m, 3);
}
//取订舱箱列表
var ctnList = _bookingCtnRepository.AsQueryable()
.Where(a => a.BILLID == bookingId).ToList();
if (ctnList.Count > 0)
{
model.ContaList = new List<BookingTruckCtnDto>();
ctnList.ForEach(b =>
{
if (b.CTNNUM == 1)
{
model.ContaList.Add(new BookingTruckCtnDto
{
CTNCODE = b.CTNCODE,
CTNALL = b.CTNALL,
KGS = b.KGS,
PKGS = b.PKGS,
CBM = b.CBM,
TAREWEIGHT = b.TAREWEIGHT,
CNTRNO = b.CNTRNO,
KINDPKGS = b.KINDPKGS,
SEALNO = b.SEALNO,
TEU = b.TEU,
CTNNUM = b.CTNNUM,
});
}
else
{
for (int i = 0; i < b.CTNNUM; i++)
{
model.ContaList.Add(new BookingTruckCtnDto
{
CTNCODE = b.CTNCODE,
CTNALL = b.CTNALL,
KGS = b.KGS,
PKGS = b.PKGS,
CBM = b.CBM,
TAREWEIGHT = b.TAREWEIGHT,
CNTRNO = b.CNTRNO,
KINDPKGS = b.KINDPKGS,
SEALNO = b.SEALNO,
TEU = b.TEU,
CTNNUM = b.CTNNUM,
});
}
}
});
}
return model;
}
/// <summary>
/// 引入订舱详情生成派车信息
/// </summary>
/// <param name="bookingId">订舱主键</param>
/// <returns>返回派车初始信息</returns>
[HttpGet("/BookingTruck/PullInBookingOrder")]
public async Task<TaskManageOrderResultDto> PullInBookingOrder(long bookingId)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
var model = InnerCreateTruckFromBookingOrder(bookingId);
result.succ = true;
result.ext = model;
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"引入订舱详情生成派车信息异常,原因:{ex.Message}";
}
return result;
}
/// <summary>
/// 引入订舱集装箱详情生成派车信息
/// </summary>
/// <param name="bookingId">订舱主键</param>
/// <returns>返回派车集装箱初始信息</returns>
[HttpGet("/BookingTruck/PullInBookingOrderConta")]
public async Task<TaskManageOrderResultDto> PullInBookingOrderConta(long bookingId)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
}
catch (Exception ex)
{
}
return result;
}
/// <summary>
/// 提交派车
/// </summary>
/// <param name="info">派车信息</param>
/// <returns>返回回执</returns>
2 years ago
[HttpPost("/BookingTruck/Submit")]
public async Task<TaskManageOrderResultDto> Submit(BookingTruckDto info)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
}
catch (Exception ex)
{
}
return result;
}
/// <summary>
/// 批量提交派车
/// </summary>
/// <param name="ids">派车主键组</param>
/// <returns>返回回执</returns>
2 years ago
[HttpPost("/BookingTruck/SubmitBatch")]
public async Task<TaskManageOrderResultDto> SubmitBatch([FromBody] long[] ids)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
}
catch (Exception ex)
{
}
return result;
}
/// <summary>
/// 撤销派车
/// </summary>
/// <param name="id">派车主键</param>
/// <returns>返回回执</returns>
2 years ago
[HttpGet("/BookingTruck/Cancel")]
public async Task<TaskManageOrderResultDto> Cancel(long id)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
}
catch (Exception ex)
{
}
return result;
}
/// <summary>
/// 批量撤销派车
/// </summary>
/// <param name="ids">派车主键组</param>
/// <returns>返回回执</returns>
2 years ago
public async Task<TaskManageOrderResultDto> CancelBatch([FromBody] long[] ids)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
}
catch (Exception ex)
{
}
return result;
}
/// <summary>
/// 打印派车
/// </summary>
/// <param name="id">派车主键</param>
/// <returns>返回回执</returns>
2 years ago
[HttpGet("/BookingTruck/Print")]
public async Task<TaskManageOrderResultDto> Print(long id)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
}
catch (Exception ex)
{
}
return result;
}
/// <summary>
/// 批量派车
/// </summary>
/// <param name="ids">派车主键组</param>
/// <returns>返回回执</returns>
2 years ago
[HttpPost("/BookingTruck/SendDispatchBatch")]
public async Task<TaskManageOrderResultDto> SendDispatchBatch([FromBody] long[] ids)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
}
catch (Exception ex)
{
}
return result;
}
/// <summary>
/// 取消派车
/// </summary>
/// <param name="id">派车主键</param>
/// <returns>返回回执</returns>
2 years ago
[HttpGet("/BookingTruck/CancelDispatch")]
public async Task<TaskManageOrderResultDto> CancelDispatch(long id)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
}
catch (Exception ex)
{
}
return result;
}
/// <summary>
/// 批量取消派车
/// </summary>
/// <param name="ids">派车主键组</param>
/// <returns>返回回执</returns>
2 years ago
[HttpPost("/BookingTruck/CancelDispatchBatch")]
public async Task<TaskManageOrderResultDto> CancelDispatchBatch([FromBody] long[] ids)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
}
catch (Exception ex)
{
}
return result;
}
2 years ago
2 years ago
}
}