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

129 lines
4.1 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;
public DjyVesselInfoService(SqlSugarRepository<DjyVesselInfo> rep, ISysCacheService sysCacheService)
{
_sysCacheService = sysCacheService;
_rep = rep;
}
2 years ago
/// <summary>
/// 获取列表
/// </summary>
/// <param name="KeyWord"></param>
/// <returns></returns>
[HttpGet("/DjyVesselInfoService/GetListPage")]
2 years ago
public async Task<dynamic> GetListPage([FromQuery] string KeyWord)
{
2 years ago
2 years ago
return await _rep.AsQueryable().WhereIF(!string.IsNullOrWhiteSpace(KeyWord), x => x.Vessel.Contains(KeyWord)
|| x.CARRIER.Contains(KeyWord) || x.Voyno.Contains(KeyWord) || x.PortLoading.Contains(KeyWord) || x.PortTransit.Contains(KeyWord) ||
x.PortDischarge.Contains(KeyWord) || x.VoynoInside.Contains(KeyWord)
).ToListAsync();
2 years ago
}
/// <summary>
/// 删除
/// </summary>
/// <param name="Id"></param>
/// <returns></returns>
[HttpGet("/DjyVesselInfoService/Delete")]
public async Task Delete([FromQuery] long[] Ids)
{
var entity = await _rep.FirstOrDefaultAsync(u => Ids.Contains(u.Id));
await _rep.DeleteAsync(entity);
}
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>();
await _rep.InsertAsync(entity);
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")]
2 years ago
public async Task<dynamic> GetList([FromQuery] string CarrierID, string KeyWord = "")
2 years ago
{
2 years ago
//获取船名
List<CodeVessel> list = await _sysCacheService.GetAllCodeVessel();
2 years ago
2 years ago
var tlist = await _rep.AsQueryable().WhereIF(!string.IsNullOrWhiteSpace(KeyWord), x => x.Vessel.Contains(KeyWord)).
Where(x=> x.CARRIERID == CarrierID && x.ETD > DateTime.Now.AddDays(-7)).
Select(x => new
{
Voyno = x.Voyno,
VoynoInside = x.VoynoInside,
2 years ago
Vessel = x.Vessel,
2 years ago
ETD = x.ETD,
2 years ago
ATD = x.ATD,
}).Take(20).
ToListAsync();
if (tlist.Count() == 0)
{
2 years ago
return list.WhereIF(!string.IsNullOrWhiteSpace(KeyWord), x => x.Name.Contains(KeyWord)).Select(x => new
2 years ago
{
Voyno = "",
2 years ago
VoynoInside = "",
2 years ago
Vessel = x.Name,
ETD = "",
2 years ago
ATD = "",
2 years ago
}).Take(20).ToList();
}
else
{
return tlist;
}
2 years ago
}
}
}