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/BookingVesselInfo/BookingVesselInfoService.cs

325 lines
13 KiB
C#

1 year 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 Furion.FriendlyException;
using System.Collections.Generic;
using System;
using Myshipping.Core.Service;
using Myshipping.Core.Entity;
1 year ago
using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.SignalR;
using Furion;
1 year ago
namespace Myshipping.Application
{
/// <summary>
/// 船期手工维护模块
/// </summary>
[ApiDescriptionSettings("Application", Name = "BookingVesselInfo", Order = 1)]
public class BookingVesselInfoService : IBookingVesselInfoService, IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<DjyVesselInfo> _rep;
private readonly ISysCacheService _sysCacheService;
private readonly IBookingOrderService _bookingorderservice;
private readonly SqlSugarRepository<BookingOrder> _order;
1 year ago
private readonly ILogger<BookingVesselInfoService> _logger;
private readonly IHubContext<ChatHub, IChatClient> _chatHubContext;
public BookingVesselInfoService(SqlSugarRepository<DjyVesselInfo> rep, ILogger<BookingVesselInfoService> logger, SqlSugarRepository<BookingOrder> order,
ISysCacheService sysCacheService,
IBookingOrderService bookingorderservice,
IHubContext<ChatHub, IChatClient> chatHubContext)
1 year ago
{
_sysCacheService = sysCacheService;
_rep = rep;
_order = order;
_bookingorderservice = bookingorderservice;
1 year ago
this._logger = logger;
this._chatHubContext = chatHubContext;
1 year ago
}
///// <summary>
///// 获取列表
///// </summary>
///// <returns></returns>
//[HttpGet("/DjyVesselInfoService/GetListPage")]
//public async Task<dynamic> GetListPage([FromQuery] string CARRIER, string Vessel, string VoynoInside, string Voyno, DateTime? StartETD, DateTime? EndETD)
//{
// return await _rep.AsQueryable().Filter(null, true).Where(x => x.TenantId == UserManager.TENANT_ID)
// .WhereIF(!string.IsNullOrWhiteSpace(CARRIER), x => x.CARRIER.Contains(CARRIER))
// .WhereIF(!string.IsNullOrWhiteSpace(Vessel), x => x.Vessel.Contains(Vessel))
// .WhereIF(!string.IsNullOrWhiteSpace(VoynoInside), x => x.VoynoInside.Contains(VoynoInside))
// .WhereIF(!string.IsNullOrWhiteSpace(Voyno), x => x.Voyno.Contains(Voyno))
// .WhereIF(StartETD != null, x => x.ETD >= StartETD)
// .WhereIF(EndETD != null, x => x.ETD <= EndETD)
// .ToListAsync();
//}
///// <summary>
///// 获取列表分页
///// </summary>
///// <param name="input"></param>
///// <returns></returns>
//[HttpGet("/DjyVesselInfoService/page")]
//public async Task<dynamic> GetListPage([FromQuery] QueryDjyVesselInfoInput input)
//{
// return await _rep.AsQueryable().Filter(null, true).Where(x => x.TenantId == UserManager.TENANT_ID)
// .WhereIF(!string.IsNullOrWhiteSpace(input.CARRIER), x => x.CARRIER.Contains(input.CARRIER))
// .WhereIF(!string.IsNullOrWhiteSpace(input.Vessel), x => x.Vessel.Contains(input.Vessel))
// .WhereIF(!string.IsNullOrWhiteSpace(input.VoynoInside), x => x.VoynoInside.Contains(input.VoynoInside))
// .WhereIF(!string.IsNullOrWhiteSpace(input.Voyno), x => x.Voyno.Contains(input.Voyno))
// .WhereIF(input.StartETD != null, x => x.ETD >= input.StartETD)
// .WhereIF(input.EndETD != null, x => x.ETD <= input.EndETD)
// .ToPagedListAsync(input.PageNo, input.PageSize);
//}
///// <summary>
///// 删除
///// </summary>
///// <param name="Ids"></param>
///// <returns></returns>
//[HttpGet("/DjyVesselInfoService/Delete")]
//public async Task Delete(string Ids)
//{
// var arr = Ids.Split(",");
// if (arr.Count() > 0)
// {
// foreach (var ar in arr)
// {
// long Id = Convert.ToInt64(ar);
// var entity = await _rep.FirstOrDefaultAsync(u => u.Id == Id);
// await _rep.DeleteAsync(entity);
// }
// }
//}
/// <summary>
/// 新增编辑
/// </summary>
/// <param name="dto"></param>
/// <returns></returns>
[HttpPost("/BookingVesselInfo/AddOrUpdate")]
public async Task<long> AddOrUpdate(DjyVesselInfoDto dto)
{
1 year ago
DjyVesselInfo old = new DjyVesselInfo();
1 year ago
if (dto == null)
{
throw Oops.Bah("请传入数据!");
}
if (dto.Id == 0)
{
var entity = dto.Adapt<DjyVesselInfo>();
await _rep.InsertAsync(entity);
1 year ago
old = entity;
1 year ago
}
else
{
1 year ago
old = _rep.FirstOrDefault(x => x.Id == dto.Id);
1 year ago
var entity = dto.Adapt<DjyVesselInfo>();
await _rep.AsUpdateable(entity)
.UpdateColumns(x => new
{
x.Vessel,
x.Voyno,
x.PortLoading,
x.PortTransit,
x.PortDischarge,
x.PortLoadingId,
x.PortTransitId,
x.PortDischargeId,
x.ETD,
x.YgtETD,
x.ClosingDate,
x.ETA,
x.Yard,
x.YardCode,
x.ATD,
x.CARRIER,
x.CARRIERID,
x.VoynoInside,
x.CloseDocTime
})
.ExecuteCommandAsync();
1 year ago
}
1 year ago
if ((dto.ETA != null || dto.ETD != null || dto.ATD != null)
&& !string.IsNullOrEmpty(old.Vessel)
&& !string.IsNullOrEmpty(old.Voyno)
&& !string.IsNullOrEmpty(old.CARRIERID))
1 year ago
{
var query = _order.AsQueryable()
.Filter(null, true)
.Where(x => x.TenantId == UserManager.TENANT_ID
&& x.IsDeleted == false
&& x.VESSEL == old.Vessel
&& x.VOYNO == old.Voyno
&& x.CARRIERID == old.CARRIERID);
if (App.Configuration["RunType"] != CommonConst.RUN_TYPE_HECHUAN)
{
query.WhereIF(!string.IsNullOrEmpty(old.PortLoadingId), x => x.PORTLOADID == old.PortLoadingId);
}
var order = await query.ToListAsync();
1 year ago
bool issend = false;
if (order != null)
{
1 year ago
_logger.LogInformation("手动更新船期:" + order.ToJsonString());
1 year ago
foreach (var it in order)
{
var oldOrder = it.Adapt<BookingOrder>();
1 year ago
bool flag = false;
if (it.StartETA != dto.ETA)
{
flag = true;
it.StartETA = dto.ETA;
}
1 year ago
if (it.VESSEL != dto.Vessel)
{
flag = true;
it.VESSEL = dto.Vessel;
}
if (it.VOYNO != dto.Voyno)
{
flag = true;
it.VOYNO = dto.Voyno;
}
if (it.VOYNOINNER != dto.VoynoInside)
{
flag = true;
it.VOYNOINNER = dto.VoynoInside;
}
if (it.CARRIERID != dto.CARRIERID)
{
flag = true;
it.CARRIERID = dto.CARRIERID;
}
if (it.CARRIER != dto.CARRIER)
{
flag = true;
it.CARRIER = dto.CARRIER;
}
1 year ago
if (it.YgtETD != dto.YgtETD)
{
flag = true;
1 year ago
1 year ago
it.YgtETD = dto.YgtETD;
}
1 year ago
if (it.ETD != dto.ETD)
1 year ago
{
flag = true;
1 year ago
it.ETD = dto.ETD;
}
if (it.ATD != dto.ATD && dto.ATD != null)
{
flag = true;
1 year ago
it.ATD = dto.ATD;
}
if (dto.ClosingDate != null && dto.ClosingDate != it.CLOSINGDATE)
{
flag = true;
it.CLOSINGDATE = dto.ClosingDate;
}
if (dto.CloseDocTime != null && dto.CloseDocTime != it.CLOSEDOCDATE)
{
flag = true;
it.CLOSEDOCDATE = dto.CloseDocTime;
}
1 year ago
if (flag)
{
issend = true;
await _order.AsUpdateable(it).IgnoreColumns().ExecuteCommandAsync();
await _bookingorderservice.SaveLog(it, oldOrder, "手动更新船期");
1 year ago
}
}
if (issend)
{
1 year ago
var ids = order.Where(x => x.ParentId == 0).Select(x => x.Id).ToArray();
if (ids.Count() > 0)
{
await _bookingorderservice.SendBookingOrder(ids);
}
1 year ago
}
}
}
//通知前端更新缓存
await _chatHubContext.Clients.All.NotifyVesselChange();
1 year ago
return dto.Id;
}
///// <summary>
///// 下拉列表
///// </summary>
///// <returns></returns>
//[HttpGet("/DjyVesselInfoService/GetList")]
//public async Task<dynamic> GetList([FromQuery] string CarrierID, DateTime? ETD = null, string PortDischargeId = null, string KeyWord = "")
//{
// //获取船名
// List<CodeVessel> list = await _sysCacheService.GetAllCodeVessel();
// var tlist = await _rep.AsQueryable().Filter(null, true).WhereIF(!string.IsNullOrWhiteSpace(KeyWord), x => x.Vessel.StartsWith(KeyWord.ToUpper())).
// WhereIF(!string.IsNullOrEmpty(PortDischargeId), x => x.PortDischargeId == PortDischargeId).
// WhereIF(ETD != null, x => Convert.ToDateTime(x.ETD).ToString("yyyy-MM-dd") == Convert.ToDateTime(ETD).ToString("yyyy-MM-dd")).//船期关联船名
// WhereIF(ETD == null, x => x.ETD > DateTime.Now.AddDays(-7)).//领导需求当前日期7天之前
// WhereIF(!string.IsNullOrEmpty(CarrierID), x => x.CARRIERID == CarrierID || x.CARRIERID == null || x.CARRIERID == "").
// Where(x => x.TenantId == UserManager.TENANT_ID && x.CARRIERID != null && x.CARRIERID != "").
// Select(x => new
// {
// Voyno = x.Voyno,
// VoynoInside = x.VoynoInside,
// Vessel = x.Vessel,
// ETD = x.ETD == null ? "" : Convert.ToDateTime(x.ETD).ToString("yyyy-MM-dd"),
// ATD = x.ATD == null ? "" : Convert.ToDateTime(x.ATD).ToString("yyyy-MM-dd"),
// PortDischargeId = x.PortDischargeId,
// PortDischarge = x.PortDischarge
// }).Take(20).
// ToListAsync();
// if (_sysCacheService.GetAllTenantParam().Result.Where(x => x.TenantId == UserManager.TENANT_ID && x.ParaCode == "VESSEL_FROM_CONFIG_ONLY").Select(x => x.ItemCode).FirstOrDefault() == "YES"
// )
// {
// return tlist;
// }
// var ves = tlist.Select(x => x.Vessel).ToList();
// var all = list.WhereIF(!string.IsNullOrWhiteSpace(KeyWord), x => x.Name.StartsWith(KeyWord.ToUpper())).
// Select(x => new
// {
// Voyno = "",
// VoynoInside = "",
// Vessel = x.Name,
// ETD = "",
// ATD = "",
// PortDischargeId = "",
// PortDischarge = ""
// }).Take(20).ToList();
// foreach (var item in ves)
// {
// all.RemoveAll(x => x.Vessel.StartsWith(item));
// }
// return tlist.Union<dynamic>(all);
//}
}
}