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.
254 lines
8.7 KiB
C#
254 lines
8.7 KiB
C#
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 Furion.FriendlyException;
|
|
using Myshipping.Application.Enum;
|
|
using System.ComponentModel;
|
|
using System.Collections.Generic;
|
|
using Myshipping.Application.Service.BookingTemplate.Dto;
|
|
using System.IO;
|
|
using MiniExcelLibs;
|
|
using NPOI.HSSF.UserModel;
|
|
using Myshipping.Core.Helper;
|
|
using NPOI.SS.UserModel;
|
|
using Furion;
|
|
using System;
|
|
using System.Web;
|
|
using System.Text;
|
|
using Myshipping.Application.ConfigOption;
|
|
|
|
namespace Myshipping.Application
|
|
{
|
|
/// <summary>
|
|
/// 订舱模板服务
|
|
/// </summary>
|
|
[ApiDescriptionSettings("Application", Name = "BookingTemplate", Order = 1)]
|
|
public class BookingTemplateService : IBookingTemplateService, IDynamicApiController, ITransient
|
|
{
|
|
private readonly SqlSugarRepository<BookingTemplate> _rep;
|
|
private readonly SqlSugarRepository<BookingOrder> _repOrder;
|
|
|
|
private readonly SqlSugarRepository<BookingPrintTemplate> _repPrintTemplate;
|
|
private readonly SqlSugarRepository<BookingTemplateShare> _repPrintTemplateShare;
|
|
private readonly ILogger<BookingTemplate> _logger;
|
|
|
|
public BookingTemplateService(SqlSugarRepository<BookingTemplate> rep, SqlSugarRepository<BookingOrder> repOrder, SqlSugarRepository<BookingPrintTemplate> repPrintTemplate, SqlSugarRepository<BookingTemplateShare> repPrintTemplateShare, ILogger<BookingTemplate> logger)
|
|
{
|
|
|
|
|
|
_repOrder = repOrder;
|
|
_rep = rep;
|
|
_logger = logger;
|
|
_repPrintTemplate = repPrintTemplate;
|
|
_repPrintTemplateShare = repPrintTemplateShare;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 分页查询订舱模板
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("/BookingTemplate/page")]
|
|
public async Task<dynamic> Page([FromQuery] QueryBookingTemplateInput input)
|
|
{
|
|
var entities = await _rep.AsQueryable()
|
|
.Where(x => x.CreatedUserId == UserManager.UserId)
|
|
.WhereIF(!string.IsNullOrEmpty(input.Title), x => x.Title.Contains(input.Title))
|
|
.WhereIF(!string.IsNullOrEmpty(input.Type), x => x.Type.Contains(input.Type))
|
|
.Select(x => new QueryBookingTemplateOutput()
|
|
{
|
|
Id = x.Id,
|
|
Title = x.Title,
|
|
Type = x.Type,
|
|
Content = x.Content,
|
|
Remark = x.Remark,
|
|
ADDR = x.ADDR,
|
|
COUNTRY = x.COUNTRY,
|
|
COUNTRYName = x.COUNTRYName,
|
|
TEL = x.TEL
|
|
})
|
|
.ToPagedListAsync(input.PageNo, input.PageSize);
|
|
|
|
//分享标志
|
|
var tempIdList = entities.Items.Select(x => x.Id).ToList();
|
|
var shareList = _repPrintTemplateShare.AsQueryable().Where(x => tempIdList.Contains(x.TemplateId)).ToList();
|
|
foreach (var item in entities.Items)
|
|
{
|
|
item.IsShared = shareList.Count(x => x.TemplateId == item.Id) > 0;
|
|
}
|
|
|
|
return entities.XnPagedResult();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 增加订舱模板
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("/BookingTemplate/add")]
|
|
public async Task Add(AddBookingTemplateInput input)
|
|
{
|
|
//var c = _rep.Count(x => x.Type.Contains(input.Type) && x.Title == input.Title);
|
|
//if (c > 0)
|
|
//{
|
|
// throw Oops.Oh(BookingErrorCode.BOOK101);
|
|
//}
|
|
|
|
var entity = input.Adapt<BookingTemplate>();
|
|
await _rep.InsertAsync(entity);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新订舱模板
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("/BookingTemplate/edit")]
|
|
public async Task Update(UpdateBookingTemplateInput input)
|
|
{
|
|
var bt = _rep.FirstOrDefault(x => x.Id == input.Id);
|
|
if (bt == null)
|
|
{
|
|
throw Oops.Oh(BookingErrorCode.BOOK111);
|
|
}
|
|
|
|
input.Adapt(bt);
|
|
|
|
await _rep.AsUpdateable(bt).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除订舱模板
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("/BookingTemplate/delete")]
|
|
public async Task Delete(GetBookingTemplateInput input)
|
|
{
|
|
var entity = await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
|
|
await _rep.DeleteAsync(entity);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取订舱模板
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("/BookingTemplate/detail")]
|
|
public async Task<BookingTemplate> Get([FromQuery] GetBookingTemplateInput input)
|
|
{
|
|
return await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 新增编辑分享
|
|
/// </summary>
|
|
/// <param name="dto"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("/BookingTemplate/SaveTemplateShare")]
|
|
public async Task SaveTemplateShare(List<BookingTemplateShareDto> dto)
|
|
{
|
|
if (dto == null || dto.Count == 0)
|
|
{
|
|
|
|
throw Oops.Oh("请上传正确数据");
|
|
}
|
|
_repPrintTemplateShare.Delete(x => x.TemplateId == dto[0].TemplateId);
|
|
foreach (var item in dto)
|
|
{
|
|
var entity = item.Adapt<BookingTemplateShare>();
|
|
await _repPrintTemplateShare.InsertAsync(entity);
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 分享模板给所有人
|
|
/// </summary>
|
|
/// <param name="tempId"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("/BookingTemplate/ShareToAll")]
|
|
public async Task ShareTemplate(long tempId)
|
|
{
|
|
var bts = new BookingTemplateShare();
|
|
bts.TemplateId = tempId;
|
|
bts.ShareToId = -1;
|
|
bts.ShareToName = "所有人";
|
|
await _repPrintTemplateShare.InsertAsync(bts);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 取消分享模板
|
|
/// </summary>
|
|
/// <param name="tempId"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("/BookingTemplate/CancelShare")]
|
|
public async Task CancelShareTemplate(long tempId)
|
|
{
|
|
_repPrintTemplateShare.Delete(x => x.TemplateId == tempId);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取分享列表
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet("/BookingTemplate/GetTemplateShareList")]
|
|
public async Task<dynamic> GetTemplateShareList(long Id)
|
|
{
|
|
var list = _repPrintTemplateShare.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false && x.TemplateId == Id).ToList();
|
|
return list;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 删除分享
|
|
/// </summary>
|
|
/// <param name="Ids"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("/BookingTemplate/DeleteTemplateShare")]
|
|
public async Task DeleteTemplateShare(string Ids)
|
|
{
|
|
var arr = Ids.Split(",");
|
|
if (arr.Count() > 0)
|
|
{
|
|
foreach (var ar in arr)
|
|
{
|
|
long Id = Convert.ToInt64(ar);
|
|
var entity = await _repPrintTemplateShare.FirstOrDefaultAsync(u => u.Id == Id);
|
|
await _repPrintTemplateShare.DeleteAsync(entity);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取分享列表
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet("/BookingTemplate/GetTemplateShare")]
|
|
public async Task<dynamic> GetTemplateShare(string TemplateName, string Type)
|
|
{
|
|
var TemplateIds = _repPrintTemplateShare.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false && (x.ShareToId == UserManager.UserId || x.ShareToId == -1)).Select(x => x.TemplateId).ToList();
|
|
|
|
var list = await _rep.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false && (TemplateIds.Contains(x.Id) || x.CreatedUserId == UserManager.UserId)).
|
|
WhereIF(!string.IsNullOrEmpty(TemplateName), x => x.Title.Contains(TemplateName)).
|
|
WhereIF(!string.IsNullOrEmpty(Type), x => x.Type.Contains(Type)).Distinct().ToListAsync();
|
|
|
|
return list;
|
|
}
|
|
|
|
}
|
|
}
|