|
|
@ -0,0 +1,301 @@
|
|
|
|
|
|
|
|
using Furion;
|
|
|
|
|
|
|
|
using Furion.DependencyInjection;
|
|
|
|
|
|
|
|
using Furion.DynamicApiController;
|
|
|
|
|
|
|
|
using Furion.FriendlyException;
|
|
|
|
|
|
|
|
using Mapster;
|
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
|
|
using Myshipping.Application.ConfigOption;
|
|
|
|
|
|
|
|
using Myshipping.Application.Entity;
|
|
|
|
|
|
|
|
using Myshipping.Core;
|
|
|
|
|
|
|
|
using Myshipping.Core.Service;
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
using System.Web;
|
|
|
|
|
|
|
|
using Yitter.IdGenerator;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Myshipping.Application
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 客户订舱
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
[ApiDescriptionSettings("Application", Name = "BookingCustomerOrder", Order = 1)]
|
|
|
|
|
|
|
|
public class BookingCustomerOrderService : IDynamicApiController, ITransient
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
private readonly SqlSugarRepository<BookingCustomerOrder> _rep;
|
|
|
|
|
|
|
|
private readonly SqlSugarRepository<BookingCtn> _repCtn;
|
|
|
|
|
|
|
|
private readonly ILogger<BookingOrderService> _logger;
|
|
|
|
|
|
|
|
private readonly ISysCacheService _cache;
|
|
|
|
|
|
|
|
private readonly SqlSugarRepository<BookingFile> _repFile;
|
|
|
|
|
|
|
|
private readonly SqlSugarRepository<BookingStatusLog> _repStatuslog;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public BookingCustomerOrderService(SqlSugarRepository<BookingCustomerOrder> rep, SqlSugarRepository<BookingCtn> repCtn,
|
|
|
|
|
|
|
|
ILogger<BookingOrderService> logger, ISysCacheService cache, SqlSugarRepository<BookingFile> repFile, SqlSugarRepository<BookingStatusLog> statuslog)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
this._logger = logger;
|
|
|
|
|
|
|
|
this._rep = rep;
|
|
|
|
|
|
|
|
this._repCtn = repCtn;
|
|
|
|
|
|
|
|
this._cache = cache;
|
|
|
|
|
|
|
|
this._repFile = repFile;
|
|
|
|
|
|
|
|
this._repStatuslog = statuslog;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//查询台账
|
|
|
|
|
|
|
|
[HttpPost("/BookingCustomerOrder/PageData")]
|
|
|
|
|
|
|
|
public async Task<SqlSugarPagedList<BookingCustomerOrderListOutput>> PageData(BookingCustomerOrderQueryInput input)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var query = _rep.AsQueryable();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var entities = await query.ToPagedListAsync(input.PageNo, input.PageSize);
|
|
|
|
|
|
|
|
var list = entities.Adapt<SqlSugarPagedList<BookingCustomerOrderListOutput>>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 保存数据
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
|
|
[HttpPost("/BookingCustomerOrder/Save")]
|
|
|
|
|
|
|
|
public async Task<BookingCustomerOrderSaveOutput> Save(BookingCustomerOrderSaveInput input)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (input == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw Oops.Bah("请传入正常数据!");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var ms = JsonUtil.TrimFields(input);
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(ms))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw Oops.Bah(ms);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BookingCustomerOrder entity = null;
|
|
|
|
|
|
|
|
List<BookingCtn> ctnList = new List<BookingCtn>();
|
|
|
|
|
|
|
|
if (input.Id == 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
entity = input.Adapt<BookingCustomerOrder>();
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(entity.VOYNO))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
entity.VOYNO = entity.VOYNOINNER;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
entity.BSSTATUS = "已录入";
|
|
|
|
|
|
|
|
entity.BOOKINGNO = $"BK{YitIdHelper.NextId()}";
|
|
|
|
|
|
|
|
await _rep.InsertAsync(entity);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
entity = await _rep.AsQueryable().Filter(null, true).FirstAsync(x => x.Id == input.Id);
|
|
|
|
|
|
|
|
if (entity.BSSTATUS != "已录入" || entity.BSSTATUS != "已驳回")
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw Oops.Bah("当前状态不允许修改");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(entity.VOYNO))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
entity.VOYNO = entity.VOYNOINNER;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
entity = input.Adapt(entity);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await _rep.UpdateAsync(entity);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await _repCtn.DeleteAsync(x => x.BILLID == input.Id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//箱信息保存
|
|
|
|
|
|
|
|
if (input.CtnList != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
foreach (var item in input.CtnList)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var ctnentity = item.Adapt<BookingCtn>();
|
|
|
|
|
|
|
|
ctnentity.BILLID = entity.Id;
|
|
|
|
|
|
|
|
await _repCtn.InsertAsync(ctnentity);
|
|
|
|
|
|
|
|
ctnList.Add(ctnentity);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//文件
|
|
|
|
|
|
|
|
var dbFiles = _repFile.AsQueryable().Where(x => x.BookingId == entity.Id).ToList();
|
|
|
|
|
|
|
|
var opt = App.GetOptions<BookingAttachOptions>();
|
|
|
|
|
|
|
|
var dirAbs = string.Empty;
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(opt.basePath))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
dirAbs = Path.Combine(App.WebHostEnvironment.WebRootPath, opt.relativePath);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
dirAbs = Path.Combine(opt.basePath, opt.relativePath);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!Directory.Exists(dirAbs))
|
|
|
|
|
|
|
|
Directory.CreateDirectory(dirAbs);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//临时文件转为正式文件
|
|
|
|
|
|
|
|
if (input.TempFileNames != null && input.TempFileNames.Count() > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var optTempFile = App.GetOptions<TempFileOptions>().Path;
|
|
|
|
|
|
|
|
foreach (var tmpFile in input.TempFileNames)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var tempPath = Path.Combine(optTempFile, tmpFile);
|
|
|
|
|
|
|
|
if (File.Exists(tempPath))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var saveFileName = $"{DateTime.Now.Ticks}{Path.GetExtension(tmpFile)}";
|
|
|
|
|
|
|
|
var fileRelaPath = Path.Combine(opt.relativePath, saveFileName).ToLower();
|
|
|
|
|
|
|
|
var fileAbsPath = Path.Combine(dirAbs, saveFileName).ToLower();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
File.Copy(tempPath, fileAbsPath, true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var newFile = new BookingFile
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Id = YitIdHelper.NextId(),
|
|
|
|
|
|
|
|
FileName = Path.GetFileName(tmpFile),
|
|
|
|
|
|
|
|
FilePath = fileRelaPath,
|
|
|
|
|
|
|
|
TypeCode = "tuodan",
|
|
|
|
|
|
|
|
TypeName = "托单文件",
|
|
|
|
|
|
|
|
BookingId = entity.Id,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
await _repFile.InsertAsync(newFile);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//清除前端已删除的文件
|
|
|
|
|
|
|
|
if (input.Files != null && input.Files.Count() > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var delIds = dbFiles.Where(x => !input.Files.Contains(x.Id)).Select(x => x.Id);
|
|
|
|
|
|
|
|
await _repFile.DeleteAsync(x => delIds.Contains(x.Id));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
await _repFile.DeleteAsync(x => x.BookingId == entity.Id);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//日志动态
|
|
|
|
|
|
|
|
var staLog = new BookingStatusLog();
|
|
|
|
|
|
|
|
staLog.Status = input.Id == 0 ? "已录入" : "已修改";
|
|
|
|
|
|
|
|
staLog.CreatedUserId = UserManager.UserId;
|
|
|
|
|
|
|
|
staLog.CreatedUserName = UserManager.Name;
|
|
|
|
|
|
|
|
staLog.CreatedTime = DateTime.Now;
|
|
|
|
|
|
|
|
staLog.OpTime = DateTime.Now;
|
|
|
|
|
|
|
|
staLog.BookingId = entity.Id;
|
|
|
|
|
|
|
|
_repStatuslog.Insert(staLog);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var outModel = entity.Adapt<BookingCustomerOrderSaveOutput>();
|
|
|
|
|
|
|
|
outModel.CtnList = ctnList.Adapt<List<BookingCustomerCtnDto>>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var dicFile = new Dictionary<long, string>();
|
|
|
|
|
|
|
|
_repFile.AsQueryable().Where(x => x.BookingId == entity.Id).ForEach(x => dicFile.Add(x.Id, x.FileName));
|
|
|
|
|
|
|
|
outModel.Files = dicFile;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
outModel.LogList = _repStatuslog.AsQueryable().Where(x => x.BookingId == entity.Id).ToList().Adapt<List<BookingCustomerLogDto>>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return outModel;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 获取详情
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
|
|
[HttpPost("/BookingCustomerOrder/Get")]
|
|
|
|
|
|
|
|
public async Task<BookingCustomerOrderSaveOutput> Get(long id)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var entity = await _rep.AsQueryable().Filter(null, true).FirstAsync(x => x.Id == id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var outModel = entity.Adapt<BookingCustomerOrderSaveOutput>();
|
|
|
|
|
|
|
|
outModel.CtnList = _repCtn.Where(x => x.BILLID == id).Adapt<List<BookingCustomerCtnDto>>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var dicFile = new Dictionary<long, string>();
|
|
|
|
|
|
|
|
_repFile.AsQueryable().Where(x => x.BookingId == entity.Id).ForEach(x => dicFile.Add(x.Id, x.FileName));
|
|
|
|
|
|
|
|
outModel.Files = dicFile;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
outModel.LogList = _repStatuslog.AsQueryable().Where(x => x.BookingId == entity.Id).ToList().Adapt<List<BookingCustomerLogDto>>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return outModel;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 上传临时文件
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="file"></param>
|
|
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
|
|
[HttpPost("/BookingCustomerOrder/UploadTempFile")]
|
|
|
|
|
|
|
|
public async Task<string> UploadTempFile(IFormFile file)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//未上传文件
|
|
|
|
|
|
|
|
if (file == null || file.Length == 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw Oops.Bah("未上传任何文件");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var optTempFile = App.GetOptions<TempFileOptions>().Path;
|
|
|
|
|
|
|
|
var tempFilePath = $"{DateTime.Now.Ticks}"; //临时存放目录
|
|
|
|
|
|
|
|
var tempSavePath = Path.Combine(optTempFile, tempFilePath);
|
|
|
|
|
|
|
|
Directory.CreateDirectory(tempSavePath);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var fileFullPath = Path.Combine(tempSavePath, file.FileName);//服务器路径
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using (var stream = File.Create(fileFullPath))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
await file.CopyToAsync(stream);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Path.Combine(tempFilePath, file.FileName);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 下载查看上传的文件
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
|
|
[HttpGet("/BookingCustomerOrder/GetFile"), AllowAnonymous]
|
|
|
|
|
|
|
|
public async Task<IActionResult> GetFile(long id)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var savedFile = await _repFile.AsQueryable().Filter(null, true).FirstAsync(u => u.Id == id);
|
|
|
|
|
|
|
|
if (savedFile == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw Oops.Oh("文件不存在");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var opt = App.GetOptions<BookingAttachOptions>();
|
|
|
|
|
|
|
|
var dirAbs = opt.basePath;
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(dirAbs))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
dirAbs = App.WebHostEnvironment.WebRootPath;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var fileFullPath = Path.Combine(dirAbs, savedFile.FilePath);
|
|
|
|
|
|
|
|
if (!File.Exists(fileFullPath))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw Oops.Oh("文件不存在");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var fileName = HttpUtility.UrlEncode(savedFile.FileName, Encoding.GetEncoding("UTF-8"));
|
|
|
|
|
|
|
|
var result = new FileStreamResult(new FileStream(fileFullPath, FileMode.Open), "application/octet-stream") { FileDownloadName = fileName };
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 提交订舱
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
|
|
[HttpPost("/BookingCustomerOrder/Submit")]
|
|
|
|
|
|
|
|
public async Task Submit()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|