From f05685fec2d7cb9092fc3411a9eac14a813b4d45 Mon Sep 17 00:00:00 2001 From: jianghaiqing Date: Tue, 3 Jan 2023 16:10:24 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=93=81=E5=90=8D?= =?UTF-8?q?=E5=88=86=E7=B1=BB=E3=80=81=E5=90=88=E7=BA=A6=E5=8F=B7=E5=A2=9E?= =?UTF-8?q?=E3=80=81=E5=88=A0=E3=80=81=E6=94=B9=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Myshipping.Application.xml | 306 +++++++++ .../Service/Para/Dto/ParaContractNoDto.cs | 6 +- .../Para/Dto/QueryParaContractNoDto.cs | 89 +++ .../Para/Dto/QueryParaGoodsCategoryDto.cs | 86 +++ .../Service/Para/Interface/IParaService.cs | 115 ++-- .../Service/Para/ParaService.cs | 604 +++++++++++++++--- 6 files changed, 1089 insertions(+), 117 deletions(-) create mode 100644 Myshipping.Application/Service/Para/Dto/QueryParaContractNoDto.cs create mode 100644 Myshipping.Application/Service/Para/Dto/QueryParaGoodsCategoryDto.cs diff --git a/Myshipping.Application/Myshipping.Application.xml b/Myshipping.Application/Myshipping.Application.xml index e8a8ca98..39f8c47c 100644 --- a/Myshipping.Application/Myshipping.Application.xml +++ b/Myshipping.Application/Myshipping.Application.xml @@ -9760,21 +9760,25 @@ 主键 + 358942162968645 合约号编号 + TAO21A00759 合约号名称 + 测试1 合约号备注 + 测试1 @@ -9923,6 +9927,163 @@ 修改者名称 + + + 约号台账查询 + + + + + 合约号编号 + + + + + 合约号名称 + + + + + 合约号备注 + + + + + 创建者名称 + + + + + + 修改者名称 + + + + + + 创建时间开始 + + 2022-01-01 + + + + 创建时间结束 + + 2023-07-01 + + + + 更新时间开始 + + + + + + 更新时间结束 + + + + + + 当前页码 + + 1 + + + + 页码容量 + + 20 + + + + 排序字段 + + ContractNo + + + + 排序方法,默认降序 + + true + + + + 品名分类参数台账查询 + + + + + 品名分类 + + 02 + + + + 品名分类名称 + + + + + + 创建者名称 + + + + + + 修改者名称 + + + + + + 创建时间开始 + + 2022-01-01 + + + + 创建时间结束 + + 2023-07-01 + + + + 更新时间开始 + + + + + + 更新时间结束 + + + + + + 当前页码 + + 1 + + + + 页码容量 + + 20 + + + + 排序字段 + + GoodsCategory + + + + 排序方法,默认降序 + + true + 品名参数台账查询 @@ -10044,6 +10205,7 @@ 检索品名参数 检索值 + 默认最大行数 返回回执 @@ -10053,6 +10215,78 @@ 品名参数台账查询请求 返回结果 + + + 保存品名分类参数 + + 品名分类参数 + 返回回执 + + + + 主键获取品名分类参数 + + 品名分类主键 + 返回回执 + + + + 检索品名分类参数 + + 检索值 + 默认最大行数 + 返回回执 + + + + 作废品名分类参数 + + 品名分类参数主键数组 + 返回回执 + + + + 品名分类参数台账查询 + + 品名分类参数台账查询请求 + 返回结果 + + + + 保存约号参数 + + 约号参数 + 返回回执 + + + + 主键获取约号参数 + + 约号主键 + 返回回执 + + + + 检索约号参数 + + 检索值 + 默认最大行数 + 返回回执 + + + + 作废约号参数 + + 约号参数主键数组 + 返回回执 + + + + 约号参数台账查询 + + 约号参数台账查询请求 + 返回结果 + 订舱业务参数 @@ -10094,6 +10328,78 @@ 品名参数台账查询请求 返回结果 + + + 保存品名分类参数 + + 品名分类参数 + 返回回执 + + + + 主键获取品名分类参数 + + 品名分类主键 + 返回回执 + + + + 检索品名分类参数 + + 检索值 + 默认最大行数 + 返回回执 + + + + 作废品名分类参数 + + 品名分类参数主键数组 + 返回回执 + + + + 品名分类参数台账查询 + + 品名分类参数台账查询请求 + 返回结果 + + + + 保存约号参数 + + 约号参数 + 返回回执 + + + + 主键获取约号参数 + + 约号主键 + 返回回执 + + + + 检索约号参数 + + 检索值 + 默认最大行数 + 返回回执 + + + + 作废约号参数 + + 约号参数主键数组 + 返回回执 + + + + 约号参数台账查询 + + 约号参数台账查询请求 + 返回结果 + 件数 diff --git a/Myshipping.Application/Service/Para/Dto/ParaContractNoDto.cs b/Myshipping.Application/Service/Para/Dto/ParaContractNoDto.cs index 802bf475..6ba7a685 100644 --- a/Myshipping.Application/Service/Para/Dto/ParaContractNoDto.cs +++ b/Myshipping.Application/Service/Para/Dto/ParaContractNoDto.cs @@ -11,21 +11,25 @@ namespace Myshipping.Application /// /// 主键 /// + /// 358942162968645 public string Id{ get; set; } /// /// 合约号编号 /// - public string ContractNo { get; set; } + /// TAO21A00759 + public string ContractNo { get; set; } /// /// 合约号名称 /// + /// 测试1 public string ContractName { get; set; } /// /// 合约号备注 /// + /// 测试1 public string ContractNote { get; set; } /// diff --git a/Myshipping.Application/Service/Para/Dto/QueryParaContractNoDto.cs b/Myshipping.Application/Service/Para/Dto/QueryParaContractNoDto.cs new file mode 100644 index 00000000..a24be897 --- /dev/null +++ b/Myshipping.Application/Service/Para/Dto/QueryParaContractNoDto.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Myshipping.Application +{ + /// + /// 约号台账查询 + /// + public class QueryParaContractNoDto + { + /// + /// 合约号编号 + /// + public string ContractNo { get; set; } + + /// + /// 合约号名称 + /// + public string ContractName { get; set; } + + /// + /// 合约号备注 + /// + public string ContractNote { get; set; } + + /// + /// 创建者名称 + /// + /// + public string CreateUserName { get; set; } + + /// + /// 修改者名称 + /// + /// + public string UpdateUserName { get; set; } + + /// + /// 创建时间开始 + /// + /// 2022-01-01 + public string CreateTimeBegin { get; set; } + + /// + /// 创建时间结束 + /// + /// 2023-07-01 + public string CreateTimeEnd { get; set; } + + /// + /// 更新时间开始 + /// + /// + public string UpdateTimeBegin { get; set; } + + /// + /// 更新时间结束 + /// + /// + public string UpdateTimeEnd { get; set; } + + /// + /// 当前页码 + /// + /// 1 + public int PageNo { get; set; } = 1; + + /// + /// 页码容量 + /// + /// 20 + public int PageSize { get; set; } = 20; + + /// + /// 排序字段 + /// + /// ContractNo + public string SortField { get; set; } + + /// + /// 排序方法,默认降序 + /// + /// true + public bool descSort { get; set; } = true; + } +} diff --git a/Myshipping.Application/Service/Para/Dto/QueryParaGoodsCategoryDto.cs b/Myshipping.Application/Service/Para/Dto/QueryParaGoodsCategoryDto.cs new file mode 100644 index 00000000..f6546803 --- /dev/null +++ b/Myshipping.Application/Service/Para/Dto/QueryParaGoodsCategoryDto.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Myshipping.Application +{ + /// + /// 品名分类参数台账查询 + /// + public class QueryParaGoodsCategoryDto + { + /// + /// 品名分类 + /// + /// 02 + public string GoodsCategory { get; set; } + + /// + /// 品名分类名称 + /// + /// + public string GoodsCategoryName { get; set; } + + /// + /// 创建者名称 + /// + /// + public string CreateUserName { get; set; } + + /// + /// 修改者名称 + /// + /// + public string UpdateUserName { get; set; } + + /// + /// 创建时间开始 + /// + /// 2022-01-01 + public string CreateTimeBegin { get; set; } + + /// + /// 创建时间结束 + /// + /// 2023-07-01 + public string CreateTimeEnd { get; set; } + + /// + /// 更新时间开始 + /// + /// + public string UpdateTimeBegin { get; set; } + + /// + /// 更新时间结束 + /// + /// + public string UpdateTimeEnd { get; set; } + + /// + /// 当前页码 + /// + /// 1 + public int PageNo { get; set; } = 1; + + /// + /// 页码容量 + /// + /// 20 + public int PageSize { get; set; } = 20; + + /// + /// 排序字段 + /// + /// GoodsCategory + public string SortField { get; set; } + + /// + /// 排序方法,默认降序 + /// + /// true + public bool descSort { get; set; } = true; + } +} diff --git a/Myshipping.Application/Service/Para/Interface/IParaService.cs b/Myshipping.Application/Service/Para/Interface/IParaService.cs index 7b4b9076..98357c8f 100644 --- a/Myshipping.Application/Service/Para/Interface/IParaService.cs +++ b/Myshipping.Application/Service/Para/Interface/IParaService.cs @@ -33,6 +33,7 @@ namespace Myshipping.Application /// 检索品名参数 /// /// 检索值 + /// 默认最大行数 /// 返回回执 Task> QueryParaGoodsInfo(string queryItem, int top = 10); @@ -43,47 +44,77 @@ namespace Myshipping.Application /// 返回结果 Task GetParaGoodsPageAsync(QueryParaGoodsDto QuerySearch); - ///// - ///// 保存品名分类参数 - ///// - ///// 品名分类参数 - ///// 返回回执 - //Task SaveParaGoodsCategoryInfo(ParaGoodsCategoryDto model); - - ///// - ///// 主键获取品名分类参数 - ///// - ///// 品名分类主键 - ///// 返回回执 - //Task GetParaGoodsCategoryInfo(long Id); - - ///// - ///// 检索品名分类参数 - ///// - ///// 检索值 - ///// 返回回执 - //Task QueryParaGoodsCategoryInfo(string queryItem); - - - ///// - ///// 保存约号参数 - ///// - ///// 约号参数 - ///// 返回回执 - //Task SaveParaContractNoInfo(ParaGoodsCategoryDto model); - - ///// - ///// 主键获取约号参数 - ///// - ///// 约号主键 - ///// 返回回执 - //Task GetParaContractNoInfo(long Id); - - ///// - ///// 检索约号参数 - ///// - ///// 检索值 - ///// 返回回执 - //Task QuerytParaContractNoInfo(string queryItem); + /// + /// 保存品名分类参数 + /// + /// 品名分类参数 + /// 返回回执 + Task SaveParaGoodsCategoryInfo(ParaGoodsCategoryDto model); + + /// + /// 主键获取品名分类参数 + /// + /// 品名分类主键 + /// 返回回执 + Task GetParaGoodsCategoryInfo(long Id); + + /// + /// 检索品名分类参数 + /// + /// 检索值 + /// 默认最大行数 + /// 返回回执 + Task> QueryParaGoodsCategoryInfo(string queryItem, int top = 10); + + /// + /// 作废品名分类参数 + /// + /// 品名分类参数主键数组 + /// 返回回执 + Task DeleteParaGoodsCategoryInfo(long[] Ids); + + /// + /// 品名分类参数台账查询 + /// + /// 品名分类参数台账查询请求 + /// 返回结果 + Task GetParaGoodsCategoryPageAsync(QueryParaGoodsCategoryDto QuerySearch); + + + /// + /// 保存约号参数 + /// + /// 约号参数 + /// 返回回执 + Task SaveParaContractNoInfo(ParaContractNoDto model); + + /// + /// 主键获取约号参数 + /// + /// 约号主键 + /// 返回回执 + Task GetParaContractNoInfo(long Id); + + /// + /// 检索约号参数 + /// + /// 检索值 + /// 默认最大行数 + /// 返回回执 + Task> QuerytParaContractNoInfo(string queryItem, int top = 10); + + /// + /// 作废约号参数 + /// + /// 约号参数主键数组 + /// 返回回执 + Task DeleteParaContractNoInfo(long[] Ids); + + /// + /// 约号参数台账查询 + /// + /// 约号参数台账查询请求 + /// 返回结果 + Task GetParaContractNoPageAsync(QueryParaContractNoDto QuerySearch); } } diff --git a/Myshipping.Application/Service/Para/ParaService.cs b/Myshipping.Application/Service/Para/ParaService.cs index c0b47131..5f6523ab 100644 --- a/Myshipping.Application/Service/Para/ParaService.cs +++ b/Myshipping.Application/Service/Para/ParaService.cs @@ -7,8 +7,11 @@ using Microsoft.Extensions.Logging; using Myshipping.Application.Entity; using Myshipping.Application.Helper; using Myshipping.Core; +using Myshipping.Core.Entity; using NPOI.OpenXmlFormats.Wordprocessing; using NPOI.SS.Formula.Functions; +using NPOI.XWPF.UserModel; +using Org.BouncyCastle.Crypto; using System; using System.Collections.Generic; using System.Linq; @@ -60,6 +63,17 @@ namespace Myshipping.Application if(sameList.Count > 0 && !string.IsNullOrWhiteSpace(model.Id) && sameList.Any(t=>t.Id != long.Parse(model.Id))) throw Oops.Oh($"商品编码【{model.GoodsCode}】已存在不能重复保存"); + //如果填写了品名分配需要确认根据库中数据一致 + if (!string.IsNullOrWhiteSpace(model.GoodsCategory)) + { + var categoryInfo = _paraGoodsCategoryInfoRepository.AsQueryable().First(t => t.GOODS_CATEGORY.Equals(model.GoodsCategory.Trim())); + + if (categoryInfo == null) + throw Oops.Oh($"品名分类代码【{model.GoodsCategory}】不存在,请确认品名分类"); + + if (!string.IsNullOrWhiteSpace(model.GoodsCategoryName) && !categoryInfo.GOODS_CATEGORY_NAME.Equals(model.GoodsCategoryName.Trim())) + throw Oops.Oh($"品名分类名称【{model.GoodsCategoryName}】错误,code={model.GoodsCategory}请确认品名分类"); + } if (!string.IsNullOrWhiteSpace(model.Id)) { @@ -281,8 +295,8 @@ namespace Myshipping.Application .WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.GoodsDesp), t => t.GOODS_DESP.Contains(QuerySearch.GoodsDesp.Trim(), StringComparison.OrdinalIgnoreCase)) .WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.GoodsNameEN), t => t.GOODS_NAME_EN.Contains(QuerySearch.GoodsNameEN.Trim(), StringComparison.OrdinalIgnoreCase)) .WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.GoodsCategory), t => t.GOODS_CATEGORY.Equals(QuerySearch.GoodsCategory.Trim(), StringComparison.OrdinalIgnoreCase)) - .WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.CreateUserName), t => t.GOODS_NAME_EN.Contains(QuerySearch.CreateUserName.Trim(), StringComparison.OrdinalIgnoreCase)) - .WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.UpdateUserName), t => t.GOODS_NAME_EN.Contains(QuerySearch.UpdateUserName.Trim(), StringComparison.OrdinalIgnoreCase)) + .WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.CreateUserName), t => t.CreatedUserName.Contains(QuerySearch.CreateUserName.Trim(), StringComparison.OrdinalIgnoreCase)) + .WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.UpdateUserName), t => t.UpdatedUserName.Contains(QuerySearch.UpdateUserName.Trim(), StringComparison.OrdinalIgnoreCase)) .OrderBy(entityOrderCol + (QuerySearch.descSort ? " asc " : " desc ")) .ToPagedListAsync(QuerySearch.PageNo, QuerySearch.PageSize); return new @@ -295,77 +309,519 @@ namespace Myshipping.Application }; } - ///// - ///// 保存品名分类参数 - ///// - ///// 品名分类参数 - ///// 返回回执 - //public async Task SaveParaGoodsCategoryInfo(ParaGoodsCategoryDto model) - //{ - // CommonWebApiResult result = new CommonWebApiResult(); - - // return result; - //} - - ///// - ///// 主键获取品名分类参数 - ///// - ///// 品名分类主键 - ///// 返回回执 - //public async Task GetParaGoodsCategoryInfo(long Id) - //{ - // CommonWebApiResult result = new CommonWebApiResult(); - - // return result; - //} - - ///// - ///// 检索品名分类参数 - ///// - ///// 检索值 - ///// 返回回执 - //public async Task QueryParaGoodsCategoryInfo(string queryItem) - //{ - // CommonWebApiResult result = new CommonWebApiResult(); - - // return result; - //} - - - ///// - ///// 保存约号参数 - ///// - ///// 约号参数 - ///// 返回回执 - //public async Task SaveParaContractNoInfo(ParaGoodsCategoryDto model) - //{ - // CommonWebApiResult result = new CommonWebApiResult(); - - // return result; - //} - - ///// - ///// 主键获取约号参数 - ///// - ///// 约号主键 - ///// 返回回执 - //public async Task GetParaContractNoInfo(long Id) - //{ - // CommonWebApiResult result = new CommonWebApiResult(); - - // return result; - //} - - ///// - ///// 检索约号参数 - ///// - ///// 检索值 - ///// 返回回执 - //public async Task QuerytParaContractNoInfo(string queryItem) - //{ - // CommonWebApiResult result = new CommonWebApiResult(); - - // return result; - //} + /// + /// 保存品名分类参数 + /// + /// 品名分类参数 + /// 返回回执 + public async Task SaveParaGoodsCategoryInfo(ParaGoodsCategoryDto model) + { + ParaGoodsCategoryInfo info = null; + + try + { + //判断代码不能重复 + var sameList = _paraGoodsCategoryInfoRepository.AsQueryable() + .Where(t => t.GOODS_CATEGORY.Equals(model.GoodsCategory, StringComparison.OrdinalIgnoreCase)).ToList(); + + if (sameList.Count > 0 && !string.IsNullOrWhiteSpace(model.Id) && sameList.Any(t => t.Id != long.Parse(model.Id))) + throw Oops.Oh($"商品分类代码【{model.GoodsCategory}】已存在不能重复保存"); + + if (!string.IsNullOrWhiteSpace(model.Id)) + { + info = await _paraGoodsCategoryInfoRepository.AsQueryable().FirstAsync(t => t.Id == long.Parse(model.Id)); + + //如果填写了品名分配需要确认根据库中数据一致 + if (!info.GOODS_CATEGORY.Equals(model.GoodsCategory, StringComparison.OrdinalIgnoreCase)) + { + var existsList = _paraGoodsCategoryInfoRepository.AsQueryable() + .LeftJoin(_paraGoodsInfoRepository.AsQueryable(), (cate, goods) => cate.GOODS_CATEGORY == goods.GOODS_CATEGORY) + .Where(cate => cate.Id == info.Id) + .Select((cate, goods) => new { Cate = cate, Goods = goods }).ToList(); + + if (existsList.Any(t => t.Goods != null)) + throw Oops.Oh($"原分类代码{info.GOODS_CATEGORY}已有对应品名参数,不能修改"); + + } + + info.GOODS_CATEGORY = model.GoodsCategory; + info.GOODS_CATEGORY_NAME = model.GoodsCategoryName; + + await _paraGoodsCategoryInfoRepository.AsUpdateable(info).IgnoreColumns(it => new + { + it.Id, + it.TenantId, + it.CreatedTime, + it.CreatedUserId, + it.CreatedUserName + }).ExecuteCommandAsync(); + } + else + { + info = model.Adapt(); + + await _paraGoodsCategoryInfoRepository.InsertAsync(info); + } + } + catch (Exception ex) + { + throw Oops.Bah($"保存品名分类参数异常,{ex.Message}"); + } + + return info.Id; + } + + /// + /// 主键获取品名分类参数 + /// + /// 品名分类主键 + /// 返回回执 + public async Task GetParaGoodsCategoryInfo(long Id) + { + ParaGoodsCategoryDto model = null; + + try + { + ParaGoodsCategoryInfo info = _paraGoodsCategoryInfoRepository.AsQueryable().First(t => t.Id == Id); + + if (info == null) + throw Oops.Oh($"获取品名分类参数失败"); + + + model = info.Adapt(); + + } + catch (Exception ex) + { + throw Oops.Bah($"获取品名分类参数异常,{ex.Message}"); + } + + return model; + } + + /// + /// 检索品名分类参数 + /// + /// 检索值 + /// 默认最大行数 + /// 返回回执 + [HttpGet("/Para/QueryParaGoodsCategoryInfo")] + public async Task> QueryParaGoodsCategoryInfo([FromQuery] string queryItem, [FromQuery] int top = 10) + { + List list = new List(); + + try + { + var query = _paraGoodsCategoryInfoRepository.AsQueryable(); + + if (!string.IsNullOrWhiteSpace(queryItem)) + { + query = query.Where(t => + t.GOODS_CATEGORY.Contains(queryItem.Trim(), StringComparison.OrdinalIgnoreCase) || + t.GOODS_CATEGORY_NAME.Contains(queryItem.Trim(), StringComparison.OrdinalIgnoreCase) + ); + } + + query = query.OrderBy("GOODS_CATEGORY asc"); + + var currList = await query.Take(top).ToListAsync(); + + if (currList.Count > 0) + list = currList.Select(t => t.Adapt()).ToList(); + + } + catch (Exception ex) + { + throw Oops.Bah($"保存品名参数异常,{ex.Message}"); + } + + return list; + } + + /// + /// 作废品名分类参数 + /// + /// 品名分类参数主键数组 + /// 返回回执 + [HttpPost("/Para/DeleteParaGoodsCategoryInfo")] + public async Task DeleteParaGoodsCategoryInfo(long[] Ids) + { + try + { + //如果没有给主键直接抛异常 + if (Ids.Length == 0) + throw Oops.Oh("没有提供需要作废的主键信息"); + + var list = _paraGoodsCategoryInfoRepository.AsQueryable().Where(t => Ids.Contains(t.Id)).ToList(); + + if (list.Count != Ids.Length) + { + var noRecord = string.Join(",", Ids.GroupJoin(list, l => l, r => r.Id, (l, r) => { + var currList = r.ToList(); + + if (r.Count() > 0) + return string.Empty; + + return l.ToString(); + }).Where(t => !string.IsNullOrWhiteSpace(t)).ToArray()); + + throw Oops.Oh($"以下主键信息 {noRecord} 检索失败或者已作废过"); + } + + //这里需要判断当前的品名分类是否已经对应到品名上,如果已有对应则不能直接作废 + var existsList = _paraGoodsCategoryInfoRepository.AsQueryable() + .LeftJoin(_paraGoodsInfoRepository.AsQueryable(),(cate, goods) => cate.GOODS_CATEGORY == goods.GOODS_CATEGORY) + .Where(cate => Ids.Contains(cate.Id)) + .Select((cate, goods) => new { Cate = cate, Goods = goods }).ToList(); + + if(existsList.Any(t=>t.Goods != null)) + throw Oops.Oh($"以下分类代码已指定品名参数不能直接删除,{string.Join(",",existsList.Select(t=>t.Cate.GOODS_CATEGORY).Distinct().ToArray())}"); + + list.ForEach(async entity => + { + entity.IsDeleted = true; + entity.UpdatedTime = DateTime.Now; + entity.UpdatedUserId = UserManager.UserId; + entity.UpdatedUserName = UserManager.Name; + + await _paraGoodsCategoryInfoRepository.AsUpdateable(entity).IgnoreColumns(it => new + { + it.Id, + it.TenantId, + it.CreatedTime, + it.CreatedUserId, + it.CreatedUserName + }).ExecuteCommandAsync(); + }); + + } + catch (Exception ex) + { + throw Oops.Bah($"作废品名参数异常,{ex.Message}"); + } + + return "作废成功"; + } + + #region 品名分类参数台账查询 + /// + /// 品名分类参数台账查询 + /// + /// 品名分类参数台账查询请求 + /// 返回结果 + public async Task GetParaGoodsCategoryPageAsync(QueryParaGoodsCategoryDto QuerySearch) + { + DateTime createBegin = DateTime.MinValue; + DateTime createEnd = DateTime.MinValue; + + DateTime updateBegin = DateTime.MinValue; + DateTime updateEnd = DateTime.MinValue; + + if (!string.IsNullOrWhiteSpace(QuerySearch.CreateTimeBegin)) + { + if (!DateTime.TryParse(QuerySearch.CreateTimeBegin, out createBegin)) + throw Oops.Oh($"创建开始日期格式错误,{QuerySearch.CreateTimeBegin}"); + } + + if (!string.IsNullOrWhiteSpace(QuerySearch.CreateTimeEnd)) + { + if (!DateTime.TryParse(QuerySearch.CreateTimeEnd, out createEnd)) + throw Oops.Oh($"创建结束日期格式错误,{QuerySearch.CreateTimeEnd}"); + + createEnd = createEnd.AddDays(1); + } + + if (!string.IsNullOrWhiteSpace(QuerySearch.UpdateTimeBegin)) + { + if (!DateTime.TryParse(QuerySearch.UpdateTimeBegin, out updateBegin)) + throw Oops.Oh($"更新起始日期格式错误,{QuerySearch.UpdateTimeBegin}"); + } + + if (!string.IsNullOrWhiteSpace(QuerySearch.UpdateTimeEnd)) + { + if (!DateTime.TryParse(QuerySearch.UpdateTimeEnd, out updateEnd)) + throw Oops.Oh($"更新结束日期格式错误,{QuerySearch.UpdateTimeEnd}"); + + updateEnd = updateEnd.AddDays(1); + } + + string entityOrderCol = "CreatedTime"; + + //这里因为返回给前端的台账数据是DTO,所以这里排序时候需要转换成Entity对应的字段 + if (!string.IsNullOrWhiteSpace(QuerySearch.SortField)) + entityOrderCol = MapsterExtHelper.GetAdaptProperty(QuerySearch.SortField); + + var entities = await _paraGoodsCategoryInfoRepository.AsQueryable().Filter(null, true) + .WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.GoodsCategory), t => t.GOODS_CATEGORY.Contains(QuerySearch.GoodsCategory.Trim(), StringComparison.OrdinalIgnoreCase)) + .WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.GoodsCategoryName), t => t.GOODS_CATEGORY_NAME.Contains(QuerySearch.GoodsCategoryName.Trim(), StringComparison.OrdinalIgnoreCase)) + .WhereIF(createBegin != DateTime.MinValue, t => t.CreatedTime.HasValue && t.CreatedTime.Value >= createBegin) + .WhereIF(createEnd != DateTime.MinValue, t => t.CreatedTime.HasValue && t.CreatedTime.Value < createEnd) + .WhereIF(updateBegin != DateTime.MinValue, t => t.UpdatedTime.HasValue && t.UpdatedTime.Value >= updateBegin) + .WhereIF(updateEnd != DateTime.MinValue, t => t.UpdatedTime.HasValue && t.UpdatedTime.Value < updateEnd) + .WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.CreateUserName), t => t.CreatedUserName.Contains(QuerySearch.CreateUserName.Trim(), StringComparison.OrdinalIgnoreCase)) + .WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.UpdateUserName), t => t.UpdatedUserName.Contains(QuerySearch.UpdateUserName.Trim(), StringComparison.OrdinalIgnoreCase)) + .OrderBy(entityOrderCol + (QuerySearch.descSort ? " asc " : " desc ")) + .ToPagedListAsync(QuerySearch.PageNo, QuerySearch.PageSize); + return new + { + PageNo = entities.PageIndex, + PageSize = entities.PageSize, + TotalPage = entities.TotalPages, + TotalRows = entities.TotalCount, + Rows = entities.Items.Select(t => t.Adapt()).ToList() + }; + } + #endregion + + #region 保存约号参数 + /// + /// 保存约号参数 + /// + /// 约号参数 + /// 返回回执 + public async Task SaveParaContractNoInfo(ParaContractNoDto model) + { + ParaContractNoInfo info = null; + + try + { + //判断代码不能重复 + var sameList = _paraContractNoInfoRepository.AsQueryable() + .Where(t => t.CONTRACT_NO.Equals(model.ContractNo, StringComparison.OrdinalIgnoreCase)).ToList(); + + if (sameList.Count > 0 && !string.IsNullOrWhiteSpace(model.Id) && sameList.Any(t => t.Id != long.Parse(model.Id))) + throw Oops.Oh($"合约号编号【{model.ContractNo}】已存在不能重复保存"); + + if (!string.IsNullOrWhiteSpace(model.Id)) + { + info = await _paraContractNoInfoRepository.AsQueryable().FirstAsync(t => t.Id == long.Parse(model.Id)); + + info.CONTRACT_NO = model.ContractNo; + info.CONTRACT_NAME = model.ContractName; + info.CONTRACT_NAME = model.ContractName; + + await _paraContractNoInfoRepository.AsUpdateable(info).IgnoreColumns(it => new + { + it.Id, + it.TenantId, + it.CreatedTime, + it.CreatedUserId, + it.CreatedUserName + }).ExecuteCommandAsync(); + } + else + { + info = model.Adapt(); + + await _paraContractNoInfoRepository.InsertAsync(info); + } + } + catch (Exception ex) + { + throw Oops.Bah($"保存约号参数异常,{ex.Message}"); + } + + return info.Id; + } + #endregion + + #region 主键获取约号参数 + /// + /// 主键获取约号参数 + /// + /// 约号主键 + /// 返回回执 + public async Task GetParaContractNoInfo(long Id) + { + ParaContractNoDto model = null; + + try + { + ParaContractNoInfo info = _paraContractNoInfoRepository.AsQueryable().First(t => t.Id == Id); + + if (info == null) + throw Oops.Oh($"获取约号参数失败"); + + + model = info.Adapt(); + + } + catch (Exception ex) + { + throw Oops.Bah($"获取约号参数异常,{ex.Message}"); + } + + return model; + } + #endregion + + #region 检索约号参数 + /// + /// 检索约号参数 + /// + /// 检索值 + /// 默认最大行数 + /// 返回回执 + public async Task> QuerytParaContractNoInfo([FromQuery] string queryItem, [FromQuery] int top = 10) + { + List list = new List(); + + try + { + var query = _paraContractNoInfoRepository.AsQueryable(); + + if (!string.IsNullOrWhiteSpace(queryItem)) + { + query = query.Where(t => + t.CONTRACT_NO.Contains(queryItem.Trim(), StringComparison.OrdinalIgnoreCase) || + t.CONTRACT_NAME.Contains(queryItem.Trim(), StringComparison.OrdinalIgnoreCase) || + t.CONTRACT_NOTE.Contains(queryItem.Trim(), StringComparison.OrdinalIgnoreCase) + ); + } + + query = query.OrderBy("CONTRACT_NO asc"); + + var currList = await query.Take(top).ToListAsync(); + + if (currList.Count > 0) + list = currList.Select(t => t.Adapt()).ToList(); + + } + catch (Exception ex) + { + throw Oops.Bah($"检索约号参数异常,{ex.Message}"); + } + + return list; + } + #endregion + + #region 作废约号参数 + /// + /// 作废约号参数 + /// + /// 约号参数主键数组 + /// 返回回执 + public async Task DeleteParaContractNoInfo(long[] Ids) + { + try + { + //如果没有给主键直接抛异常 + if (Ids.Length == 0) + throw Oops.Oh("没有提供需要作废的主键信息"); + + var list = _paraContractNoInfoRepository.AsQueryable().Where(t => Ids.Contains(t.Id)).ToList(); + + if (list.Count != Ids.Length) + { + var noRecord = string.Join(",", Ids.GroupJoin(list, l => l, r => r.Id, (l, r) => { + var currList = r.ToList(); + + if (r.Count() > 0) + return string.Empty; + + return l.ToString(); + }).Where(t => !string.IsNullOrWhiteSpace(t)).ToArray()); + + throw Oops.Oh($"以下主键信息 {noRecord} 检索失败或者已作废过"); + } + + list.ForEach(async entity => + { + entity.IsDeleted = true; + entity.UpdatedTime = DateTime.Now; + entity.UpdatedUserId = UserManager.UserId; + entity.UpdatedUserName = UserManager.Name; + + await _paraContractNoInfoRepository.AsUpdateable(entity).IgnoreColumns(it => new + { + it.Id, + it.TenantId, + it.CreatedTime, + it.CreatedUserId, + it.CreatedUserName + }).ExecuteCommandAsync(); + }); + + } + catch (Exception ex) + { + throw Oops.Bah($"作废约号参数异常,{ex.Message}"); + } + + return "作废成功"; + } + #endregion + + #region 约号参数台账查询 + /// + /// 约号参数台账查询 + /// + /// 约号参数台账查询请求 + /// 返回结果 + public async Task GetParaContractNoPageAsync(QueryParaContractNoDto QuerySearch) + { + DateTime createBegin = DateTime.MinValue; + DateTime createEnd = DateTime.MinValue; + + DateTime updateBegin = DateTime.MinValue; + DateTime updateEnd = DateTime.MinValue; + + if (!string.IsNullOrWhiteSpace(QuerySearch.CreateTimeBegin)) + { + if (!DateTime.TryParse(QuerySearch.CreateTimeBegin, out createBegin)) + throw Oops.Oh($"创建开始日期格式错误,{QuerySearch.CreateTimeBegin}"); + } + + if (!string.IsNullOrWhiteSpace(QuerySearch.CreateTimeEnd)) + { + if (!DateTime.TryParse(QuerySearch.CreateTimeEnd, out createEnd)) + throw Oops.Oh($"创建结束日期格式错误,{QuerySearch.CreateTimeEnd}"); + + createEnd = createEnd.AddDays(1); + } + + if (!string.IsNullOrWhiteSpace(QuerySearch.UpdateTimeBegin)) + { + if (!DateTime.TryParse(QuerySearch.UpdateTimeBegin, out updateBegin)) + throw Oops.Oh($"更新起始日期格式错误,{QuerySearch.UpdateTimeBegin}"); + } + + if (!string.IsNullOrWhiteSpace(QuerySearch.UpdateTimeEnd)) + { + if (!DateTime.TryParse(QuerySearch.UpdateTimeEnd, out updateEnd)) + throw Oops.Oh($"更新结束日期格式错误,{QuerySearch.UpdateTimeEnd}"); + + updateEnd = updateEnd.AddDays(1); + } + + string entityOrderCol = "CreatedTime"; + + //这里因为返回给前端的台账数据是DTO,所以这里排序时候需要转换成Entity对应的字段 + if (!string.IsNullOrWhiteSpace(QuerySearch.SortField)) + entityOrderCol = MapsterExtHelper.GetAdaptProperty(QuerySearch.SortField); + + var entities = await _paraContractNoInfoRepository.AsQueryable().Filter(null, true) + .WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.ContractNo), t => t.CONTRACT_NO.Contains(QuerySearch.ContractNo.Trim(), StringComparison.OrdinalIgnoreCase)) + .WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.ContractName), t => t.CONTRACT_NAME.Contains(QuerySearch.ContractName.Trim(), StringComparison.OrdinalIgnoreCase)) + .WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.ContractNote), t => t.CONTRACT_NOTE.Contains(QuerySearch.ContractNote.Trim(), StringComparison.OrdinalIgnoreCase)) + .WhereIF(createBegin != DateTime.MinValue, t => t.CreatedTime.HasValue && t.CreatedTime.Value >= createBegin) + .WhereIF(createEnd != DateTime.MinValue, t => t.CreatedTime.HasValue && t.CreatedTime.Value < createEnd) + .WhereIF(updateBegin != DateTime.MinValue, t => t.UpdatedTime.HasValue && t.UpdatedTime.Value >= updateBegin) + .WhereIF(updateEnd != DateTime.MinValue, t => t.UpdatedTime.HasValue && t.UpdatedTime.Value < updateEnd) + .WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.CreateUserName), t => t.CreatedUserName.Contains(QuerySearch.CreateUserName.Trim(), StringComparison.OrdinalIgnoreCase)) + .WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.UpdateUserName), t => t.UpdatedUserName.Contains(QuerySearch.UpdateUserName.Trim(), StringComparison.OrdinalIgnoreCase)) + .OrderBy(entityOrderCol + (QuerySearch.descSort ? " asc " : " desc ")) + .ToPagedListAsync(QuerySearch.PageNo, QuerySearch.PageSize); + return new + { + PageNo = entities.PageIndex, + PageSize = entities.PageSize, + TotalPage = entities.TotalPages, + TotalRows = entities.TotalCount, + Rows = entities.Items.Select(t => t.Adapt()).ToList() + }; + } + #endregion } } From e66b5ab894dc6ab66ffba261e8c50e76688a405a Mon Sep 17 00:00:00 2001 From: jianghaiqing Date: Tue, 3 Jan 2023 16:24:38 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E7=9A=84=E5=88=A0=E9=99=A4=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/Para/ParaService.cs | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Myshipping.Application/Service/Para/ParaService.cs b/Myshipping.Application/Service/Para/ParaService.cs index 5f6523ab..7bf66c5c 100644 --- a/Myshipping.Application/Service/Para/ParaService.cs +++ b/Myshipping.Application/Service/Para/ParaService.cs @@ -149,7 +149,6 @@ namespace Myshipping.Application await _paraGoodsInfoRepository.AsUpdateable(entity).IgnoreColumns(it => new { - it.Id, it.TenantId, it.CreatedTime, it.CreatedUserId, @@ -314,18 +313,19 @@ namespace Myshipping.Application /// /// 品名分类参数 /// 返回回执 + [HttpPost("/Para/SaveParaGoodsCategoryInfo")] public async Task SaveParaGoodsCategoryInfo(ParaGoodsCategoryDto model) { ParaGoodsCategoryInfo info = null; try { - //判断代码不能重复 - var sameList = _paraGoodsCategoryInfoRepository.AsQueryable() - .Where(t => t.GOODS_CATEGORY.Equals(model.GoodsCategory, StringComparison.OrdinalIgnoreCase)).ToList(); + ////判断代码不能重复 + //var sameList = _paraGoodsCategoryInfoRepository.AsQueryable() + // .Where(t => t.GOODS_CATEGORY.Equals(model.GoodsCategory, StringComparison.OrdinalIgnoreCase)).ToList(); - if (sameList.Count > 0 && !string.IsNullOrWhiteSpace(model.Id) && sameList.Any(t => t.Id != long.Parse(model.Id))) - throw Oops.Oh($"商品分类代码【{model.GoodsCategory}】已存在不能重复保存"); + //if (sameList.Count > 0 && !string.IsNullOrWhiteSpace(model.Id) && sameList.Any(t => t.Id != long.Parse(model.Id))) + // throw Oops.Oh($"商品分类代码【{model.GoodsCategory}】已存在不能重复保存"); if (!string.IsNullOrWhiteSpace(model.Id)) { @@ -376,6 +376,7 @@ namespace Myshipping.Application /// /// 品名分类主键 /// 返回回执 + [HttpGet("/Para/GetParaGoodsCategoryInfo")] public async Task GetParaGoodsCategoryInfo(long Id) { ParaGoodsCategoryDto model = null; @@ -486,7 +487,6 @@ namespace Myshipping.Application await _paraGoodsCategoryInfoRepository.AsUpdateable(entity).IgnoreColumns(it => new { - it.Id, it.TenantId, it.CreatedTime, it.CreatedUserId, @@ -509,6 +509,7 @@ namespace Myshipping.Application /// /// 品名分类参数台账查询请求 /// 返回结果 + [HttpPost("/Para/GetParaGoodsCategoryPage")] public async Task GetParaGoodsCategoryPageAsync(QueryParaGoodsCategoryDto QuerySearch) { DateTime createBegin = DateTime.MinValue; @@ -579,6 +580,7 @@ namespace Myshipping.Application /// /// 约号参数 /// 返回回执 + [HttpPost("/Para/SaveParaContractNoInfo")] public async Task SaveParaContractNoInfo(ParaContractNoDto model) { ParaContractNoInfo info = null; @@ -631,6 +633,7 @@ namespace Myshipping.Application /// /// 约号主键 /// 返回回执 + [HttpGet("/Para/GetParaContractNoInfo")] public async Task GetParaContractNoInfo(long Id) { ParaContractNoDto model = null; @@ -662,6 +665,7 @@ namespace Myshipping.Application /// 检索值 /// 默认最大行数 /// 返回回执 + [HttpGet("/Para/QuerytParaContractNoInfo")] public async Task> QuerytParaContractNoInfo([FromQuery] string queryItem, [FromQuery] int top = 10) { List list = new List(); @@ -702,6 +706,7 @@ namespace Myshipping.Application /// /// 约号参数主键数组 /// 返回回执 + [HttpPost("/Para/DeleteParaContractNoInfo")] public async Task DeleteParaContractNoInfo(long[] Ids) { try @@ -735,7 +740,6 @@ namespace Myshipping.Application await _paraContractNoInfoRepository.AsUpdateable(entity).IgnoreColumns(it => new { - it.Id, it.TenantId, it.CreatedTime, it.CreatedUserId, @@ -759,6 +763,7 @@ namespace Myshipping.Application /// /// 约号参数台账查询请求 /// 返回结果 + [HttpPost("/Para/GetParaContractNoPage")] public async Task GetParaContractNoPageAsync(QueryParaContractNoDto QuerySearch) { DateTime createBegin = DateTime.MinValue; From 37d3ade77d44020155a0660fe21401ca924245f3 Mon Sep 17 00:00:00 2001 From: wanghaomei Date: Tue, 3 Jan 2023 16:26:49 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E8=AE=A2=E8=88=B1=E6=89=93=E5=8D=B0?= =?UTF-8?q?=E6=96=B0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Myshipping.Application.xml | 45 +++- .../BookingOrder/BookingOrderService.cs | 230 ++++++++++++++++-- 2 files changed, 246 insertions(+), 29 deletions(-) diff --git a/Myshipping.Application/Myshipping.Application.xml b/Myshipping.Application/Myshipping.Application.xml index e8a8ca98..ca158d70 100644 --- a/Myshipping.Application/Myshipping.Application.xml +++ b/Myshipping.Application/Myshipping.Application.xml @@ -3456,6 +3456,16 @@ 显示名称 + + + 分类代码 + + + + + 分类名称 + + 订舱打印模板权限表 @@ -6017,16 +6027,25 @@ - 生成报表文件 + 生成报表文件(准备作废) 类型,1:pdf、2:xlsx、3:docx 报表类型代码,例如fangcang、samplebill等 + + + 生成打印报表文件 + + 订舱ID + 打印模板 + 类型,1:pdf、2:xlsx、3:docx + + - 打印 + 打印(准备作废,使用PrintOrder代替) 订舱Id 打印类型代码,对应字典booking_template_type @@ -6040,12 +6059,13 @@ 文件名 - + - 打印(可浏览器预览) + 打印(返回文件名) 订舱Id - 打印类型代码,对应字典booking_template_type + 打印模板ID + 类型,1:pdf、2:xlsx、3:docx @@ -9531,6 +9551,21 @@ 分单 + + + 显示名称 + + + + + 分类代码 + + + + + 分类名称 + + 订舱打印模板输出参数 diff --git a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs index 8720bd62..c82f3f07 100644 --- a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs +++ b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs @@ -368,7 +368,7 @@ namespace Myshipping.Application var groupList = input.ctnInputs.Where(x => x.CTNNUM > 0).GroupBy(c => c.CTNALL).Select(g => $"{g.Key}*{g.Sum(gg => gg.CTNNUM)}"); input.CNTRTOTAL = string.Join(" / ", groupList); } - var et = await _rep.Where(x => x.MBLNO == input.MBLNO && x.TenantId == UserManager.TENANT_ID&&x.ParentId==0).FirstAsync(); + var et = await _rep.Where(x => x.MBLNO == input.MBLNO && x.TenantId == UserManager.TENANT_ID && x.ParentId == 0).FirstAsync(); if (et != null) { @@ -483,7 +483,7 @@ namespace Myshipping.Application } var main = await _rep.AsQueryable().Where(x => x.Id == input.Id).FirstAsync(); - var et = await _rep.Where(x => x.MBLNO == input.MBLNO && x.TenantId == UserManager.TENANT_ID && x.Id != input.Id&& x.ParentId == 0).FirstAsync(); + var et = await _rep.Where(x => x.MBLNO == input.MBLNO && x.TenantId == UserManager.TENANT_ID && x.Id != input.Id && x.ParentId == 0).FirstAsync(); if (et != null) { @@ -933,7 +933,8 @@ namespace Myshipping.Application } _logger.LogInformation("调用运踪接口提单号:" + item.MBLNO + " 调用运踪接口"); - if (item.isBook&&(string.IsNullOrWhiteSpace(item.CARRIERID)|| string.IsNullOrWhiteSpace(item.CARRIER) || string.IsNullOrWhiteSpace(item.MBLNO))) { + if (item.isBook && (string.IsNullOrWhiteSpace(item.CARRIERID) || string.IsNullOrWhiteSpace(item.CARRIER) || string.IsNullOrWhiteSpace(item.MBLNO))) + { throw Oops.Bah("订阅目的港船公司或提单号不能为空!"); } billTraceList.Add(new BillTraceList @@ -1372,7 +1373,7 @@ namespace Myshipping.Application } /// - /// 获取放舱pdf + /// 获取放舱pdf(准备作废,后期使用打印相关接口) /// /// /// 类型,1:pdf、2:xlsx、3:docx @@ -1412,7 +1413,7 @@ namespace Myshipping.Application } /// - /// 获取放舱excel + /// 获取放舱excel(准备作废,后期使用打印相关接口) /// /// /// @@ -1431,7 +1432,7 @@ namespace Myshipping.Application } /// - /// 生成报表文件 + /// 生成报表文件(准备作废) /// /// /// 类型,1:pdf、2:xlsx、3:docx @@ -1501,11 +1502,75 @@ namespace Myshipping.Application } } + /// + /// 生成打印报表文件 + /// + /// 订舱ID + /// 打印模板 + /// 类型,1:pdf、2:xlsx、3:docx + /// + [NonAction] + private async Task GenPrintFile(long bookingId, BookingPrintTemplate printTemplate, int type = 1) + { + //打印报表服务地址 + var reportUrl = _cache.GetAllDictData().Result.FirstOrDefault(x => x.TypeCode == "url_set" && x.Code == "url_report_generate").Value; + if (!reportUrl.EndsWith("/")) + { + reportUrl += "/"; + } + + //订舱数据 + var order = _rep.FirstOrDefault(x => x.Id == bookingId); + if (order == null) + { + throw Oops.Bah(BookingErrorCode.BOOK001); + } + + var opt = App.GetOptions(); + var dirAbs = opt.basePath; + if (string.IsNullOrEmpty(dirAbs)) + { + dirAbs = App.WebHostEnvironment.WebRootPath; + } + + var fileAbsPath = Path.Combine(dirAbs, printTemplate.FilePath); + _logger.LogInformation($"查找模板文件:{fileAbsPath}"); + if (!File.Exists(fileAbsPath)) + { + throw Oops.Bah(BookingErrorCode.BOOK115); + } + + _logger.LogInformation($"准备调用报表生成:id:{bookingId},文件:{printTemplate.FileName}"); + var genUrl = $"{reportUrl}Report/BookingReport?bookingId={bookingId}&type={type}"; + var rtn = await genUrl + .SetContentType("multipart/form-data") + .SetBodyBytes(("file", File.ReadAllBytes(fileAbsPath), HttpUtility.UrlEncode(printTemplate.FileName, Encoding.GetEncoding("UTF-8")))) + .PostAsStringAsync(); + var jobjRtn = JObject.Parse(rtn); + _logger.LogInformation($"调用报表生成返回:{rtn}"); + if (jobjRtn.GetBooleanValue("Success")) + { + //调用读取文件 + var fn = jobjRtn.GetStringValue("Data"); + _logger.LogInformation($"准备调用读取报表文件:id:{bookingId},文件名:{fn}"); + var readFileUrl = $"{reportUrl}Report/GetFile?fileName={fn}"; + var bs = await readFileUrl.GetAsByteArrayAsync(); + + _logger.LogInformation($"调用读取报表文件返回:{bs.Length}"); + + return bs; + } + else + { + throw Oops.Bah($"生成报表文件失败:{jobjRtn.GetStringValue("Message")}"); + } + } + #endregion #region 打印 /// - /// 打印 + /// 打印(准备作废,使用PrintOrder代替) /// /// 订舱Id /// 打印类型代码,对应字典booking_template_type @@ -1589,16 +1654,40 @@ namespace Myshipping.Application } /// - /// 打印(可浏览器预览) + /// 打印(返回文件名) /// /// 订舱Id - /// 打印类型代码,对应字典booking_template_type + /// 打印模板ID + /// 类型,1:pdf、2:xlsx、3:docx /// - [HttpGet("/BookingOrder/PrintWithView")] - public async Task PrintWithView(long bookingId, string typeCode) + [HttpGet("/BookingOrder/PrintOrder")] + public async Task PrintOrder(long bookingId, long templateId, int type = 1) { - var bs = await GetReportFile(bookingId, typeCode); - var fileName = HttpUtility.UrlEncode($"{bookingId}_{DateTime.Now.Ticks}.pdf", Encoding.GetEncoding("UTF-8"));//名称 + var printTemplate = await _repPrintTemplate.AsQueryable().Filter(null, true).FirstAsync(x => x.Id == templateId); + if (printTemplate == null) + { + throw Oops.Bah(BookingErrorCode.BOOK115); + } + + var bs = await GenPrintFile(bookingId, printTemplate, type); + var fileType = ""; + if (type == 1) + { + fileType = ".pdf"; + } + else if (type == 2) + { + fileType = ".xlsx"; + } + else if (type == 3) + { + fileType = ".docx"; + } + else + { + throw Oops.Bah("类型参数不正确"); + } + var fileName = HttpUtility.UrlEncode($"{bookingId}_{DateTime.Now.Ticks}{fileType}", Encoding.GetEncoding("UTF-8"));//名称 var opt = App.GetOptions().Path; var serverpath = Path.Combine(App.WebHostEnvironment.WebRootPath, opt);//服务器路径 if (!Directory.Exists(serverpath)) @@ -1607,33 +1696,73 @@ namespace Myshipping.Application } var fullPath = Path.Combine(serverpath, fileName); await File.WriteAllBytesAsync(fullPath, bs); - var vid = Guid.NewGuid().ToString().Replace("-", ""); - await _cache.SetTimeoutAsync(vid, fullPath, TimeSpan.FromSeconds(300)); - return vid; + + //记录打印次数和时间,用于前端动态展示常用的打印类型 + var printRecentListKey = $"{PrintRecentListTypeKey}_{printTemplate.CateCode}"; + var usrCfg = _repUserConfig.AsQueryable().First(x => x.CreatedUserId == UserManager.UserId && x.Type == printRecentListKey); + if (usrCfg == null) + { + usrCfg = new DjyUserConfig(); + usrCfg.Type = printRecentListKey; + usrCfg.ConfigJson = (new long[] { templateId }).ToJson(); + await _repUserConfig.InsertAsync(usrCfg); + } + else + { + var arr = JArray.Parse(usrCfg.ConfigJson).Select(x => Convert.ToInt64(x)).Where(x => x != templateId).ToList(); + arr.Insert(0, templateId); + usrCfg.ConfigJson = arr.ToArray().ToJson(); + await _repUserConfig.UpdateAsync(usrCfg); + } + + + return fileName; } + ///// + ///// 下载打印文件(PDF直接预览) + ///// + ///// 查看ID + ///// + //[HttpGet("/BookingOrder/ViewPrintPdf/{vid}"), AllowAnonymous] + //public void ViewPrintPdf(string vid) + //{ + // if (_cache.Exists(vid)) + // { + // var fileFullName = _cache.Get(vid); + // var readMem = new ReadOnlyMemory(File.ReadAllBytes(fileFullName)); + // _httpContextAccessor.HttpContext.Response.BodyWriter.WriteAsync(readMem); + // } + // else + // { + // throw Oops.Bah("下载链接失效,请重新打印"); + // } + //} + /// - /// 下载打印文件(PDF直接预览) + /// 预览模板生成的pdf文件 /// - /// 查看ID + /// 文件名称 /// - [HttpGet("/BookingOrder/ViewPrintPdf/{vid}"), AllowAnonymous] - public void ViewPrintPdf(string vid) + [HttpGet("/BookingOrder/ViewPrintPdf/{fn}"), AllowAnonymous] + public void ViewPrintPdf(string fn) { - if (_cache.Exists(vid)) + var opt = App.GetOptions().Path; + var fileFullPath = Path.Combine(App.WebHostEnvironment.WebRootPath, opt); + var fileFullName = Path.Combine(fileFullPath, fn); + if (File.Exists(fileFullName)) { - var fileFullName = _cache.Get(vid); var readMem = new ReadOnlyMemory(File.ReadAllBytes(fileFullName)); _httpContextAccessor.HttpContext.Response.BodyWriter.WriteAsync(readMem); } else { - throw Oops.Bah("下载链接失效,请重新打印"); + _httpContextAccessor.HttpContext.Response.StatusCode = 404; } } /// - /// 获取订舱打印模板列表(带有当前用户打印历史排序) + /// 获取订舱打印模板列表(带有当前用户打印历史排序)(准备作废,使用PrintTemplateWithHistoryList代替) /// /// [HttpGet("/BookingOrder/PrintTemplateList")] @@ -1682,6 +1811,59 @@ namespace Myshipping.Application } } + + + /// + /// 获取订舱打印模板列表(带有当前用户打印历史排序) + /// + /// 分类代码(使用字典【booking_template_category】中的代码) + /// + [HttpGet("/BookingOrder/PrintTemplateWithHistoryList")] + public async Task PrintTemplateWithHistoryList(string cateCode) + { + //当前公司所有已配置的模板 + var allList = await _repPrintTemplate.AsQueryable() + .Filter(null, true).InnerJoin((d, t) => d.Id == t.PrintTemplateId && t.SysUserId == UserManager.UserId) + .Where(d => d.TenantId == UserManager.TENANT_ID && d.CateCode == cateCode) + .Select(d => new + { + d.Id, + d.CateCode, + d.CateName, + d.DisplayName + + }) + .ToListAsync(); + + var listReult = new List(); + //当前用户打印历史数据 + var printRecentListKey = $"{PrintRecentListTypeKey}_{cateCode}"; + var usrCfg = await _repUserConfig.AsQueryable().FirstAsync(x => x.CreatedUserId == UserManager.UserId && x.Type == printRecentListKey); + if (usrCfg != null) + { + var arr = JArray.Parse(usrCfg.ConfigJson).Select(x => Convert.ToInt64(x)).ToList(); + + //按顺序加入到结果 + arr.ForEach(x => + { + var find = allList.FirstOrDefault(y => y.Id == x); + if (find != null) + { + listReult.Add(find); + } + }); + + var listOut = allList.Where(x => !arr.Contains(x.Id)).ToList(); + listReult.AddRange(listOut); + + return listReult; + } + else + { + return allList; + } + + } #endregion #region 下货纸 From 6289721fc5d63a707b29c793309a596006ec982a Mon Sep 17 00:00:00 2001 From: jianghaiqing Date: Tue, 3 Jan 2023 16:40:30 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=88=91=E7=9A=84?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E5=A2=9E=E5=8A=A0=E6=AD=A3=E6=9C=AC=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TaskOriginalDownloadHisInfo.cs | 87 ++++++++++++++ .../Myshipping.Application.xml | 84 +++++++++++++ .../Interface/ITaskManageService.cs | 8 ++ .../TaskManagePlat/TaskManageService.cs | 113 +++++++++++++++++- 4 files changed, 291 insertions(+), 1 deletion(-) create mode 100644 Myshipping.Application/Entity/TaskManagePlat/TaskOriginalDownloadHisInfo.cs diff --git a/Myshipping.Application/Entity/TaskManagePlat/TaskOriginalDownloadHisInfo.cs b/Myshipping.Application/Entity/TaskManagePlat/TaskOriginalDownloadHisInfo.cs new file mode 100644 index 00000000..b1b35e25 --- /dev/null +++ b/Myshipping.Application/Entity/TaskManagePlat/TaskOriginalDownloadHisInfo.cs @@ -0,0 +1,87 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Myshipping.Application +{ + [Tenant("taskmanage")] + [SugarTable("task_original_download_his")] + [Description("任务正本下载运行表")] + public class TaskOriginalDownloadHisInfo + { + /// + /// 惟一主键 + /// + [SugarColumn(ColumnDescription = "惟一主键", IsPrimaryKey = true)] + public string PK_ID { get; set; } + + /// + /// 任务主键 + /// + public string TASK_ID { get; set; } + + /// + /// 状态 succ-成功 failure-失败 timeout-超时 + /// + public string STATUS { get; set; } + + /// + /// 起始时间 + /// + public Nullable START_DATE { get; set; } + + /// + /// 结束时间 + /// + public Nullable END_DATE { get; set; } + + /// + /// 请求文件URL + /// + public string REQUEST_URL { get; set; } + + /// + /// 下载完文件URL + /// + public string RESULT_URL { get; set; } + + /// + /// 处理结果 + /// + public string RESULT_NOTE { get; set; } + + /// + /// 是否超时 1-超时 0-未超时 + /// + public int IS_TIMEOUT { get; set; } + + /// + /// 创建人ID + /// + public long CreatedUserId { get; set; } + + /// + /// 创建人名称 + /// + public string CreatedUserName { get; set; } + + /// + /// 租户id + /// + public long? TenantId { get; set; } + + /// + /// 租户名称 + /// + public string TenantName { get; set; } + + /// + /// 软删除 + /// + public bool IsDeleted { get; set; } = false; + } +} diff --git a/Myshipping.Application/Myshipping.Application.xml b/Myshipping.Application/Myshipping.Application.xml index 09746b89..b6ed6151 100644 --- a/Myshipping.Application/Myshipping.Application.xml +++ b/Myshipping.Application/Myshipping.Application.xml @@ -4421,6 +4421,76 @@ 品名分类名称 + + + 惟一主键 + + + + + 任务主键 + + + + + 状态 succ-成功 failure-失败 timeout-超时 + + + + + 起始时间 + + + + + 结束时间 + + + + + 请求文件URL + + + + + 下载完文件URL + + + + + 处理结果 + + + + + 是否超时 1-超时 0-未超时 + + + + + 创建人ID + + + + + 创建人名称 + + + + + 租户id + + + + + 租户名称 + + + + + 软删除 + + 收发通模板类型 @@ -12528,6 +12598,13 @@ 任务台账查询请求 返回结果 + + + 下载正本提单 + + 任务主键数组 + 返回结果 + 任务管理 @@ -12569,5 +12646,12 @@ 任务台账查询请求 返回结果 + + + 下载正本提单(可批量) + + 任务主键数组 + 返回结果 + diff --git a/Myshipping.Application/Service/TaskManagePlat/Interface/ITaskManageService.cs b/Myshipping.Application/Service/TaskManagePlat/Interface/ITaskManageService.cs index 868d3b7a..0059d33e 100644 --- a/Myshipping.Application/Service/TaskManagePlat/Interface/ITaskManageService.cs +++ b/Myshipping.Application/Service/TaskManagePlat/Interface/ITaskManageService.cs @@ -40,5 +40,13 @@ namespace Myshipping.Application /// 任务台账查询请求 /// 返回结果 Task GetPageAsync(QueryTaskManageDto QuerySearch); + + + /// + /// 下载正本提单 + /// + /// 任务主键数组 + /// 返回结果 + Task DownloadOriginalTask(string[] PKIds); } } diff --git a/Myshipping.Application/Service/TaskManagePlat/TaskManageService.cs b/Myshipping.Application/Service/TaskManagePlat/TaskManageService.cs index 7d925ed7..580a3712 100644 --- a/Myshipping.Application/Service/TaskManagePlat/TaskManageService.cs +++ b/Myshipping.Application/Service/TaskManagePlat/TaskManageService.cs @@ -2,6 +2,7 @@ using Furion.DistributedIDGenerator; using Furion.DynamicApiController; using Furion.FriendlyException; +using Furion.JsonSerialization; using Furion.RemoteRequest; using Mapster; using Microsoft.AspNetCore.Authorization; @@ -13,6 +14,7 @@ using Myshipping.Application.Entity; using Myshipping.Application.Helper; using Myshipping.Core; using Myshipping.Core.Entity; +using Myshipping.Core.Service; using MySqlX.XDevAPI.Common; using NPOI.SS.Formula.Functions; using SqlSugar; @@ -43,10 +45,13 @@ namespace Myshipping.Application private readonly SqlSugarRepository _taskVGMFeedBackInfoRepository; private readonly SqlSugarRepository _sysUserRepository; private readonly SqlSugarRepository _taskStatManageInfoRepository; - + private readonly SqlSugarRepository _taskOriginalDownloadHisInfoRepository; + private readonly IDjyWebsiteAccountConfigService _webAccountConfig; private readonly ILogger _logger; + const string CONST_WEB_ACCOUNT_TYPE = "CmaWeb"; + public TaskManageService(SqlSugarRepository taskBaseInfoRepository, SqlSugarRepository taskSIFeedBackInfoRepository, SqlSugarRepository taskSIFeedBackContaInfoRepository, @@ -56,6 +61,8 @@ namespace Myshipping.Application SqlSugarRepository taskVGMFeedBackInfoRepository, SqlSugarRepository sysUserRepository, SqlSugarRepository taskStatManageInfoRepository, + SqlSugarRepository taskOriginalDownloadHisInfoRepository, + IDjyWebsiteAccountConfigService webAccountConfig, ILogger logger) { _taskBaseInfoRepository = taskBaseInfoRepository; @@ -67,6 +74,8 @@ namespace Myshipping.Application _taskVGMFeedBackInfoRepository = taskVGMFeedBackInfoRepository; _sysUserRepository = sysUserRepository; _taskStatManageInfoRepository = taskStatManageInfoRepository; + _taskOriginalDownloadHisInfoRepository = taskOriginalDownloadHisInfoRepository; + _webAccountConfig = webAccountConfig; _logger = logger; } @@ -611,5 +620,107 @@ namespace Myshipping.Application Rows = entities.Items.Select(t => t.Adapt()).ToList() }; } + + + #region 下载正本提单(可批量) + /// + /// 下载正本提单(可批量) + /// + /// 任务主键数组 + /// 返回结果 + [HttpPost("/TaskManage/DownloadOriginalTask")] + public async Task DownloadOriginalTask(string[] PKIds) + { + TaskManageOrderResultDto result = new TaskManageOrderResultDto(); + + try + { + var taskList = _taskBaseInfoRepository.AsQueryable().Where(t => PKIds.Contains(t.PK_ID)).ToList(); + + //获取个人对应的账户,这里GetAccountConfig逻辑优先取个人,个人没有配置取公司对应配置 + var userWebAccountConfig = _webAccountConfig.GetAccountConfig(CONST_WEB_ACCOUNT_TYPE, UserManager.UserId).GetAwaiter().GetResult(); + + if (userWebAccountConfig == null) + throw Oops.Bah($"个人/公司网站【{CONST_WEB_ACCOUNT_TYPE}】获取失败,请维护个人/公司网站账户信息"); + + taskList.ForEach(async tsk => { + + await InnerDownloadOriginalTask(tsk, userWebAccountConfig); + }); + + } + catch (Exception ex) + { + throw Oops.Bah($"下载正本提单异常,{0}", ex.Message); + } + + return result; + } + #endregion + + + private async Task InnerDownloadOriginalTask(TaskBaseInfo taskBaseInfo, DjyWebsiteAccountConfig webAccountConfig) + { + var result = new TaskManageOrderResultDto(); + + /* + 1、TaskOriginalDownloadHisInfo表中处理任务是succ/temp不允许重复下载。failure/timeout的记录可以再次发起下载。 + 2、从任务表提取RESULT_NOTE回执信息,里面包含了JSON数据 {"pageUrl":"http://www.cnc-ebusiness.com/ebusiness/bl/detail/AASM104300"} + 3、异步请求正本下载的链接,有超时时间。 + 4、下载完成后写入记录 + */ + + //正本下载URL + string originalUrl = string.Empty; + + try + { + var hisList = _taskOriginalDownloadHisInfoRepository + .Where(t => t.TASK_ID == taskBaseInfo.PK_ID).ToList(); + + if (hisList.Any(t => new string[] { "succ", "temp" }.Contains(t.STATUS))) + throw Oops.Bah("下载URL不存在,请用最新任务数据"); + + + if (string.IsNullOrWhiteSpace(taskBaseInfo.RESULT_NOTE)) + throw Oops.Bah("下载URL不存在,请用最新任务数据"); + + var resultObj = JSON.Deserialize(taskBaseInfo.RESULT_NOTE); + + originalUrl = resultObj.pageUrl.ToString(); + + if (string.IsNullOrWhiteSpace(originalUrl)) + throw Oops.Bah("解析下载URL不存在,请用最新任务数据"); + + DateTime startDate = DateTime.Now; + + TaskOriginalDownloadHisInfo taskOriginalDownloadHisInfo = new TaskOriginalDownloadHisInfo + { + PK_ID = IDGen.NextID().ToString(), + TASK_ID = taskBaseInfo.PK_ID, + REQUEST_URL = originalUrl, + CreatedUserId = UserManager.UserId, + CreatedUserName = UserManager.Name, + STATUS = "temp", + IS_TIMEOUT = 0, + START_DATE = startDate, + TenantId = UserManager.TENANT_ID, + TenantName = UserManager.TENANT_NAME + }; + + //写入记录 + _taskOriginalDownloadHisInfoRepository.Insert(taskOriginalDownloadHisInfo); + } + catch (Exception ex) + { + result.succ = false; + result.msg = ex.Message; + } + + return result; + } + + //private async Task Inner } + }