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/BookingOrderContact/BookingOrderContactService.cs

162 lines
6.2 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.Extensions.Logging;
using System.Collections.Generic;
2 years ago
using Furion.FriendlyException;
using Myshipping.Core.Entity;
2 years ago
namespace Myshipping.Application
{
/// <summary>
/// 订舱关系人服务
/// </summary>
[ApiDescriptionSettings("Application", Name = "BookingOrderContact", Order = 1)]
public class BookingOrderContactService : IBookingOrderContactService, IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<BookingOrderContact> _rep;
private readonly SqlSugarRepository<BookingOrder> _repOrder;
private readonly SqlSugarRepository<DjyCustomerContact> _repContact;
2 years ago
private readonly ILogger<BookingOrderContact> _logger;
public BookingOrderContactService(SqlSugarRepository<BookingOrderContact> rep,
SqlSugarRepository<BookingOrder> repOrder,
SqlSugarRepository<DjyCustomerContact> repContact,
ILogger<BookingOrderContact> logger)
2 years ago
{
_rep = rep;
_repOrder = repOrder;
_repContact = repContact;
2 years ago
_logger = logger;
}
/// <summary>
/// 分页查询订舱关系人
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("/BookingOrderContact/page")]
public async Task<dynamic> Page([FromQuery] QueryBookingOrderContactInput input)
{
var entities = await _rep.AsQueryable()
.WhereIF(!string.IsNullOrWhiteSpace(input.RoleCode), u => u.RoleCode.Contains(input.RoleCode.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.Name), u => u.Name.Contains(input.Name.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.Tel), u => u.Tel.Contains(input.Tel.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.Email), u => u.Email.Contains(input.Email.Trim()))
.WhereIF(input.BookingId != 0, u => u.BookingId == input.BookingId)
2 years ago
.ToPagedListAsync(input.PageNo, input.PageSize);
return entities.XnPagedResult();
}
/// <summary>
/// 增加订舱关系人
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/BookingOrderContact/add")]
public async Task Add(AddBookingOrderContactInput input)
{
var entity = input.Adapt<BookingOrderContact>();
await _rep.InsertAsync(entity);
}
/// <summary>
/// 更新订舱关系人
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/BookingOrderContact/edit")]
public async Task Update(UpdateBookingOrderContactInput input)
{
var entity = input.Adapt<BookingOrderContact>();
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
}
/// <summary>
/// 删除订舱关系人
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/BookingOrderContact/delete")]
public async Task Delete(GetBookingOrderContactInput input)
{
var entity = await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
await _rep.DeleteAsync(entity);
}
/// <summary>
/// 获取订舱关系人
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("/BookingOrderContact/detail")]
public async Task<BookingOrderContact> Get([FromQuery] GetBookingOrderContactInput input)
{
return await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
}
/// <summary>
/// 根据订舱ID获取关系人
/// </summary>
/// <param name="bookingId"></param>
/// <returns></returns>
[HttpGet("/BookingOrderContact/listbyorder")]
public async Task<List<BookingOrderContactOutput>> ListByOrder(long bookingId)
{
var list = await _rep.Where(x => x.BookingId == bookingId).ToListAsync();
return list.Adapt<List<BookingOrderContactOutput>>();
}
/// <summary>
/// 批量保存关系人(同时新增、删除、修改)
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/BookingOrderContact/savebatch"), SqlSugarUnitOfWork]
public async Task SaveBatch(List<UpdateBookingOrderContactInput> input, long bookingId)
2 years ago
{
_rep.Delete(x => x.BookingId == bookingId);
if (input != null && input.Count > 0)
{
2 years ago
foreach (var item in input)
{
await _rep.InsertAsync(item.Adapt<BookingOrderContact>());
}
2 years ago
}
//自动增加到该客户的联系人
var bookObj = _repOrder.FirstOrDefault(x => x.Id == bookingId);
if (bookObj.CUSTOMERID.HasValue && bookObj.CUSTOMERID.Value > 0)
{
var dbContacts = _repContact.Where(x => x.CustomerId == bookObj.CUSTOMERID.Value).ToList();
//不存在的,增加
foreach (var item in input.Where(x => dbContacts.Count(cc => cc.Name == x.Name) == 0))
{
var ct = item.Adapt<DjyCustomerContact>();
ct.CustomerId = bookObj.CUSTOMERID.Value;
await _repContact.InsertAsync(ct);
}
}
2 years ago
}
///// <summary>
///// 获取订舱关系人列表
///// </summary>
///// <param name="input"></param>
///// <returns></returns>
//[HttpGet("/BookingOrderContact/list")]
//public async Task<dynamic> List([FromQuery] QueryBookingOrderContactInput input)
//{
// return await _rep.ToListAsync();
//}
}
}