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.Core/Service/DjyVesselInfo/DjyVesselInfoService.cs

200 lines
8.0 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.Core.Entity;
using Myshipping.Application.Entity;
using Furion.FriendlyException;
using System.Collections.Generic;
2 years ago
using System;
2 years ago
namespace Myshipping.Core.Service
{
/// <summary>
/// 船期手工维护模块
2 years ago
/// </summary>
[ApiDescriptionSettings(Name = "DjyVesselInfo", Order = 1)]
public class DjyVesselInfoService : IDjyVesselInfoService, IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<DjyVesselInfo> _rep;
private readonly ISysCacheService _sysCacheService;
1 year ago
1 year ago
public DjyVesselInfoService(SqlSugarRepository<DjyVesselInfo> rep, ISysCacheService sysCacheService)
2 years ago
{
_sysCacheService = sysCacheService;
_rep = rep;
1 year ago
2 years ago
}
2 years ago
/// <summary>
/// 获取列表
/// </summary>
/// <returns></returns>
[HttpGet("/DjyVesselInfoService/GetListPage")]
1 year ago
public async Task<dynamic> GetListPage([FromQuery] string CARRIER, string Vessel, string VoynoInside, string Voyno, DateTime? StartETD, DateTime? EndETD)
2 years ago
{
2 years ago
1 year ago
return await _rep.AsQueryable().Filter(null, true).Where(x => x.TenantId == UserManager.TENANT_ID && x.IsDeleted == false)
2 years ago
.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))
1 year ago
.WhereIF(StartETD != null, x => x.ETD >= StartETD)
2 years ago
.WhereIF(EndETD != null, x => x.ETD <= EndETD)
.ToListAsync();
2 years ago
}
1 year ago
/// <summary>
/// 获取列表分页
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("/DjyVesselInfoService/page")]
public async Task<dynamic> GetListPage([FromQuery] QueryDjyVesselInfoInput input)
{
1 year ago
return await _rep.AsQueryable().Filter(null, true).Where(x => x.TenantId == UserManager.TENANT_ID && x.IsDeleted == false)
2 years ago
.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);
}
2 years ago
/// <summary>
/// 删除
/// </summary>
2 years ago
/// <param name="Ids"></param>
2 years ago
/// <returns></returns>
[HttpGet("/DjyVesselInfoService/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);
1 year ago
var entity = await _rep.FirstOrDefaultAsync(u => u.Id == Id);
2 years ago
await _rep.DeleteAsync(entity);
}
}
2 years ago
1 year ago
2 years ago
}
2 years ago
2 years ago
/// <summary>
/// 新增编辑
/// </summary>
/// <param name="dto"></param>
/// <returns></returns>
2 years ago
[HttpPost("/DjyVesselInfoService/AddOrUpdate")]
2 years ago
public async Task<long> AddOrUpdate(DjyVesselInfoDto dto)
2 years ago
{
if (dto == null)
{
throw Oops.Bah("请传入数据!");
}
if (dto.Id == 0)
{
2 years ago
var entity = dto.Adapt<DjyVesselInfo>();
1 year ago
var e = _rep.AsQueryable().Filter(null, true).Where(x => x.TenantId == UserManager.TENANT_ID && x.IsDeleted == false && x.CARRIERID == entity.CARRIERID && x.Vessel == entity.Vessel && x.Voyno == entity.Voyno && x.VoynoInside == entity.VoynoInside).First();
1 year ago
if (e == null)
{
await _rep.InsertAsync(entity);
}
1 year ago
else
{
1 year ago
entity.Id = e.Id;
if (e.ETA != null)
{
entity.ETA = e.ETA;
}
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
}
2 years ago
}
else
{
2 years ago
var entity = dto.Adapt<DjyVesselInfo>();
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
2 years ago
}
return dto.Id;
}
2 years ago
2 years ago
/// <summary>
/// 下拉列表
/// </summary>
/// <returns></returns>
2 years ago
[HttpGet("/DjyVesselInfoService/GetList")]
1 year ago
public async Task<dynamic> GetList([FromQuery] string CarrierID, DateTime? ETD = null, string PortDischargeId = null, string KeyWord = "")
2 years ago
{
2 years ago
//获取船名
List<CodeVessel> list = await _sysCacheService.GetAllCodeVessel();
2 years ago
1 year ago
var tlist = await _rep.AsQueryable().Filter(null, true).
Where(x => x.TenantId == UserManager.TENANT_ID && x.IsDeleted == false && x.CARRIERID != null && x.CARRIERID != "").
WhereIF(!string.IsNullOrWhiteSpace(KeyWord), x => x.Vessel.StartsWith(KeyWord.ToUpper())).
1 year ago
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天之前
1 year ago
WhereIF(!string.IsNullOrEmpty(CarrierID), x => x.CARRIERID == CarrierID || x.CARRIERID == null || x.CARRIERID == "").
2 years ago
Select(x => new
{
Voyno = x.Voyno,
VoynoInside = x.VoynoInside,
2 years ago
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 HH:mm:ss"),
1 year ago
PortDischargeId = x.PortDischargeId,
PortDischarge = x.PortDischarge,
ClosingDate = x.ClosingDate == null ? "" : Convert.ToDateTime(x.ClosingDate).ToString("yyyy-MM-dd HH:mm:ss"),
CloseDocTime = x.CloseDocTime == null ? "" : Convert.ToDateTime(x.CloseDocTime).ToString("yyyy-MM-dd HH:mm:ss"),
2 years ago
}).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
2 years ago
{
Voyno = "",
VoynoInside = "",
Vessel = x.Name,
ETD = "",
ATD = "",
2 years ago
PortDischargeId = "",
PortDischarge = ""
}).Take(20).ToList();
foreach (var item in ves)
2 years ago
{
all.RemoveAll(x => x.Vessel.StartsWith(item));
2 years ago
}
return tlist.Union<dynamic>(all);
2 years ago
}
}
}