diff --git a/src/WMS.Web.Api/Controllers/FileDownManagerController.cs b/src/WMS.Web.Api/Controllers/FileDownManagerController.cs new file mode 100644 index 00000000..b9ac525b --- /dev/null +++ b/src/WMS.Web.Api/Controllers/FileDownManagerController.cs @@ -0,0 +1,69 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using WMS.Web.Core; +using WMS.Web.Core.Dto; +using WMS.Web.Core.Internal.Results; +using WMS.Web.Domain.Infrastructure; +using WMS.Web.Domain.IService.Public; +using WMS.Web.Domain.Values; + +namespace WMS.Web.Api.Controllers +{ + /// + /// 上传下载中心 + /// + [Route("api/[controller]")] + [ApiController] + public class FileDownManagerController : ControllerBase + { + private readonly ILoginService _loginService; + private readonly IFileDownManagerRepositories _repositories; + public FileDownManagerController(ILoginService loginService, IFileDownManagerRepositories repositories) + { + _loginService = loginService; + _repositories = repositories; + } + + /// + /// 获取需要的状态列表 + /// + /// + [HttpGet] + [Route("GetStatus")] + public Task> GetStatus() + { + FileDownManagerStatusResponse response = new FileDownManagerStatusResponse(); + foreach (FileDownLoadOrderType enumv in Enum.GetValues(typeof(FileDownLoadOrderType))) + { + response.Type.Add((int)enumv, enumv.GetRemark()); + } + foreach (ExportStatus enumv in Enum.GetValues(typeof(ExportStatus))) + { + response.Status.Add((int)enumv, enumv.GetRemark()); + } + return Task.FromResult(Result.ReSuccess(response)); + } + + /// + /// 列表 + /// + /// + /// + [HttpPost] + [Route("FileDownManagerQuery")] + public async Task> FileDownManagerQuery(FileDownManagerRequest dto) + { + var loginInfo = _loginService.GetLoginInfo(this.HttpContext.Request.Headers["Authorization"]); + if (loginInfo == null) + return Result.ReFailure(ResultCodes.Token_Invalid_Error); + dto.SupplierId = loginInfo.UserInfo.SupplierId; + + var result = await _repositories.GetList(dto, loginInfo.UserInfo.CompanyId); + return Result.ReSuccess(result); + } + } +} diff --git a/src/WMS.Web.Api/Controllers/OutStockTaskController.cs b/src/WMS.Web.Api/Controllers/OutStockTaskController.cs index e6f4198a..15e35a27 100644 --- a/src/WMS.Web.Api/Controllers/OutStockTaskController.cs +++ b/src/WMS.Web.Api/Controllers/OutStockTaskController.cs @@ -1,16 +1,20 @@ using AutoMapper; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Options; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using WMS.Web.Core; using WMS.Web.Core.Dto; using WMS.Web.Core.Dto.OutStockTask; +using WMS.Web.Core.Help; using WMS.Web.Core.Internal.Results; using WMS.Web.Domain.Infrastructure; using WMS.Web.Domain.IService; using WMS.Web.Domain.IService.Public; +using WMS.Web.Domain.Options; using WMS.Web.Domain.Values; namespace WMS.Web.Api.Controllers @@ -27,14 +31,19 @@ namespace WMS.Web.Api.Controllers private readonly IOutStockTaskRepositories _repositories; private readonly IOutStockService _outStockService; private readonly IOutStockTaskService _outStockTaskService; + private readonly QiniuOptions _option; + private readonly IExportExcelService _exportExcelService; public OutStockTaskController(IMapper mapper, ILoginService loginService, - IOutStockTaskRepositories repositories, IOutStockService outStockService, IOutStockTaskService outStockTaskService) + IOutStockTaskRepositories repositories, IOutStockService outStockService, + IOutStockTaskService outStockTaskService, IOptions option, IExportExcelService exportExcelServic) { _mapper = mapper; _loginService = loginService; _repositories = repositories; _outStockService = outStockService; _outStockTaskService = outStockTaskService; + _option = option?.Value; + _exportExcelService = exportExcelServic; } /// /// 列表 @@ -54,6 +63,29 @@ namespace WMS.Web.Api.Controllers return result; } + /// + /// 导出 + /// + /// + /// + [HttpPost] + [Route("Export")] + public Task> Export([FromBody] OutStockTaskQueryRequest dto) + { + var loginInfo = _loginService.GetLoginInfo(this.HttpContext.Request.Headers["Authorization"]); + if (loginInfo == null) + return Task.FromResult(Result.ReFailure(ResultCodes.Token_Invalid_Error)); + string fileName = FileDownLoadOrderType.OutStockTask.GetRemark() + loginInfo.UserInfo.CompanyId + DateTime.Now.DateTimeToLongTimeStamp() + ".xlsx"; + string res = _option.Url + fileName; + + Task.Run(async () => + { + await _exportExcelService.ExportList(dto, fileName, loginInfo.UserInfo.StaffId, loginInfo.UserInfo.CompanyId, FileDownLoadOrderType.OutStockTask); + }); + + return Task.FromResult(Result.ReSuccess(res)); + } + /// /// 作废 /// diff --git a/src/WMS.Web.Api/Controllers/SysConfigController.cs b/src/WMS.Web.Api/Controllers/SysConfigController.cs index 918dca8b..a21d58e3 100644 --- a/src/WMS.Web.Api/Controllers/SysConfigController.cs +++ b/src/WMS.Web.Api/Controllers/SysConfigController.cs @@ -90,7 +90,14 @@ namespace WMS.Web.Api.Controllers { response.ShelfMethod.Add((int)enumv, enumv.GetRemark()); } - + foreach (FileDownLoadOrderType enumv in Enum.GetValues(typeof(OrderType))) + { + response.FileDownLoadOrderType.Add((int)enumv, enumv.GetRemark()); + } + foreach (ExportStatus enumv in Enum.GetValues(typeof(ExportStatus))) + { + response.ExportStatus.Add((int)enumv, enumv.GetRemark()); + } //2 //1 return Task.FromResult(Result.ReSuccess(response)); diff --git a/src/WMS.Web.Api/wwwroot/WMS.Web.Api.xml b/src/WMS.Web.Api/wwwroot/WMS.Web.Api.xml index 682db163..38e249e3 100644 --- a/src/WMS.Web.Api/wwwroot/WMS.Web.Api.xml +++ b/src/WMS.Web.Api/wwwroot/WMS.Web.Api.xml @@ -49,6 +49,24 @@ + + + 上传下载中心 + + + + + 获取需要的状态列表 + + + + + + 列表 + + + + 入库单-接口 @@ -286,6 +304,13 @@ + + + 导出 + + + + 作废 diff --git a/src/WMS.Web.Api/wwwroot/WMS.Web.Core.xml b/src/WMS.Web.Api/wwwroot/WMS.Web.Core.xml index f4e09a8f..5fa9c7a8 100644 --- a/src/WMS.Web.Api/wwwroot/WMS.Web.Core.xml +++ b/src/WMS.Web.Api/wwwroot/WMS.Web.Core.xml @@ -272,7 +272,7 @@ - 单据头ID + 箱ID @@ -480,6 +480,16 @@ 非采购上架方式 + + + 下载导出订单类型 + + + + + 下载导出状态 + + 客户 @@ -1045,6 +1055,111 @@ 备注 + + + 上传下载列表 + + + + + 单据类型(任务类型) + + + + + 状态 + + + + + 下单时间 开始 + + + + + 下单时间 结束 + + + + + 操作人 + + + + + 供应商用户Id + + + + + 上传下载列表 + + + + + 查询列表内容 + + + + + 总条数 + + + + + 上传下载列表 + + + + + 主键 订单编号 + + + + + 日期 + + + + + 单据类型(任务类型) + + + + + 状态(Key) + + + + + 状态 + + + + + 文件地址 + + + + + 操作人 + + + + + 失败原因 + + + + + 任务类型 + + + + + 状态 + + 采购订单物料明细和箱物料明细-对比请求对象 @@ -2847,12 +2962,12 @@ - 单据编号 + 出库任务单号 - 单据状态 + 出库状态 @@ -2907,7 +3022,7 @@ - 仓库ID + 仓库 diff --git a/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml b/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml index 20b39acb..2e8d04f8 100644 --- a/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml +++ b/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml @@ -311,6 +311,56 @@ 最新一次同步时间 + + + 文件下载类型 + + + + + 主键 订单编号 + + + + + 日期 + + + + + 单据类型(任务类型) + + + + + 状态 + + + + + 公司Id + + + + + 文件地址 + + + + + 操作人 + + + + + 失败原因 + + + + + 是否供应商用户 + + wms入库单 @@ -1339,6 +1389,13 @@ 备注 + + + 列表字段导出接口 + + + + 出入库回退记录-仓储接口 @@ -1475,6 +1532,26 @@ 定时任务最新一次时间管理 + + + 保存 + + + + + + + 编辑 + + + + + + + 获取销售列表 + + + wms入库单-仓储接口 @@ -1756,6 +1833,50 @@ 改箱 移箱服务 + + + 全字段导出数据 + + + + + + + + + + + + + + + 列表字段导出数据 + + + + + + + + + + + + + + + 列表页导出数据 + + + + + + + + + + + 入库单服务接口 @@ -1895,6 +2016,15 @@ 出库服务 + + + 上传文件 + + + + 是否开启自动删除 如果开启 3天后自动删除 导出的execl文件 + + 序列号服务 @@ -2474,6 +2604,31 @@ 老ops对接 + + + 七牛云 配置 + + + + + 访问key + + + + + 秘钥 + + + + + 区块文件夹 + + + + + 访问域名 + + Quartz定时任务-配置项 @@ -2702,6 +2857,33 @@ + + + 列表页导出 + + + + + + + + + + + + + 全字段导出 + + + + + + + + + + + 入库单服务 @@ -3583,6 +3765,15 @@ + + + 上传文件 + + + + + + 序列号服务 @@ -3804,6 +3995,36 @@ 客户 + + + 文件导出状态 + + + + + 正在导出 + + + + + 导出成功 + + + + + 导出失败 + + + + + 导出单据类型 + + + + + 出库任务单 + + 入库状态 diff --git a/src/WMS.Web.Core/Dto/BoxResponse.cs b/src/WMS.Web.Core/Dto/BoxResponse.cs index 7547db7d..6b5e66fd 100644 --- a/src/WMS.Web.Core/Dto/BoxResponse.cs +++ b/src/WMS.Web.Core/Dto/BoxResponse.cs @@ -10,7 +10,7 @@ namespace WMS.Web.Core.Dto public class BoxResponse { /// - /// 单据头ID + /// 箱ID /// public int Id { get; set; } /// diff --git a/src/WMS.Web.Core/Dto/EnumStatusResponse.cs b/src/WMS.Web.Core/Dto/EnumStatusResponse.cs index 0326b5f3..d24b3bc9 100644 --- a/src/WMS.Web.Core/Dto/EnumStatusResponse.cs +++ b/src/WMS.Web.Core/Dto/EnumStatusResponse.cs @@ -46,8 +46,15 @@ namespace WMS.Web.Core.Dto /// 非采购上架方式 /// public Dictionary ShelfMethod { get; set; } = new Dictionary(); + /// + /// 下载导出订单类型 + /// + public Dictionary FileDownLoadOrderType { get; set; } = new Dictionary(); + /// + /// 下载导出状态 + /// + public Dictionary ExportStatus { get; set; } = new Dictionary(); - - + } } diff --git a/src/WMS.Web.Core/Dto/FileDownManagerRequest.cs b/src/WMS.Web.Core/Dto/FileDownManagerRequest.cs new file mode 100644 index 00000000..ddb5a4ca --- /dev/null +++ b/src/WMS.Web.Core/Dto/FileDownManagerRequest.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace WMS.Web.Core.Dto +{ + /// + /// 上传下载列表 + /// + public class FileDownManagerRequest: PaginationBaseRequestDto + { + /// + /// 单据类型(任务类型) + /// + public int? Type { get; set; } + /// + /// 状态 + /// + public int? Status { get; set; } + /// + /// 下单时间 开始 + /// + public DateTime? BeginDate { get; set; } + /// + /// 下单时间 结束 + /// + public DateTime? EndDate { get; set; } + /// + /// 操作人 + /// + public string User { get; set; } + /// + /// 供应商用户Id + /// + public int? SupplierId { get; set; } = null; + } +} diff --git a/src/WMS.Web.Core/Dto/FileDownManagerResponse.cs b/src/WMS.Web.Core/Dto/FileDownManagerResponse.cs new file mode 100644 index 00000000..09b02aa7 --- /dev/null +++ b/src/WMS.Web.Core/Dto/FileDownManagerResponse.cs @@ -0,0 +1,73 @@ + +using System; +using System.Collections.Generic; +using System.Text; +using WMS.Web.Core.Help; + +namespace WMS.Web.Core.Dto +{ + /// + /// 上传下载列表 + /// + public class FileDownManagerResponse + { + public FileDownManagerResponse(List list, int? total) + { + this.List = list; + this.Total = total; + } + + /// + /// 查询列表内容 + /// + public List List { get; set; } = new List(); + /// + /// 总条数 + /// + public int? Total { get; set; } + } + + /// + /// 上传下载列表 + /// + public class FileDownInfoManagerResponse + { + public FileDownInfoManagerResponse() { } + public FileDownInfoManagerResponse(FileDownInfoManagerResponse response) + { + response.CopyPropertiesToD(this); + } + /// + /// 主键 订单编号 + /// + public int Id { get; set; } + /// + /// 日期 + /// + public string Date { get; set; } + /// + /// 单据类型(任务类型) + /// + public int Type { get; set; } + /// + /// 状态(Key) + /// + public int StatusKey { get; set; } + /// + /// 状态 + /// + public string Status { get; set; } + /// + /// 文件地址 + /// + public string FilePath { get; set; } + /// + /// 操作人 + /// + public string UserName { get; set; } + /// + /// 失败原因 + /// + public string Reason { get; set; } + } +} diff --git a/src/WMS.Web.Core/Dto/FileDownManagerStatusResponse.cs b/src/WMS.Web.Core/Dto/FileDownManagerStatusResponse.cs new file mode 100644 index 00000000..3da3cd8a --- /dev/null +++ b/src/WMS.Web.Core/Dto/FileDownManagerStatusResponse.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace WMS.Web.Core.Dto +{ + public class FileDownManagerStatusResponse + { + public FileDownManagerStatusResponse() { } + /// + /// 任务类型 + /// + public Dictionary Type { get; set; } = new Dictionary(); + /// + /// 状态 + /// + public Dictionary Status { get; set; } = new Dictionary(); + } +} diff --git a/src/WMS.Web.Core/Dto/OutStockTask/OutStockTaskQueryInfoResponse.cs b/src/WMS.Web.Core/Dto/OutStockTask/OutStockTaskQueryInfoResponse.cs index ddf32a57..e8b12e6c 100644 --- a/src/WMS.Web.Core/Dto/OutStockTask/OutStockTaskQueryInfoResponse.cs +++ b/src/WMS.Web.Core/Dto/OutStockTask/OutStockTaskQueryInfoResponse.cs @@ -1,4 +1,5 @@ -using System; +using Npoi.Mapper.Attributes; +using System; using System.Collections.Generic; using System.Text; @@ -12,90 +13,112 @@ namespace WMS.Web.Core.Dto.OutStockTask /// /// 单据Id /// + [Ignore] public int Id { get; set; } /// /// 明细Id /// + [Ignore] public int DetailId { get; set; } /// - /// 单据编号 + /// 出库任务单号 /// + [Column("出库任务单号")] public string BillNo { get; set; } /// - /// 单据状态 + /// 出库状态 /// + [Column("出库状态")] public string Status { get; set; } /// /// 单据类型 /// + [Column("出库类型")] public string Type { get; set; } /// /// 操作人(出库人) /// + [Column("出库人")] public string Operator { get; set; } /// /// 操作时间(出库时间) /// + [Column("出库时间")] public string OperateTime { get; set; } /// /// 来源单号 /// + [Column("来源单号")] public string SourceBillNo { get; set; } /// /// 销售订单号 /// + [Column("销售订单号")] public string SaleBillNo { get; set; } /// /// 发货组织 /// + [Column("发货组织")] public string DeliveryOrg { get; set; } /// /// 收货客户 /// + [Column("收货客户")] public string ReceiptCustomer { get; set; } /// /// 物料名称 /// + [Column("物料名称")] public string MaterialName { get; set; } /// /// 物料编码 /// + [Column("物料编码")] public string MaterialNumber { get; set; } /// /// 物料规格型号 /// + [Column("规格型号")] public string Specifications { get; set; } /// - /// 仓库ID + /// 仓库 /// + [Column("发货仓库")] public string Stock { get; set; } /// /// 应出库数量 /// + [Column("应出库数量")] public decimal AccruedQty { get; set; } /// /// 已出库数量 /// + [Column("已出库数量")] public decimal RealityQty { get; set; } /// /// 订单明细备注 /// + [Column("订单明细备注")] public string Remark { get; set; } /// /// 创建时间(erp那边的创建时间) /// + [Column("创建时间")] public string CreateTime { get; set; } /// /// 单位 /// + [Column("单位")] public string Unit { get; set; } /// /// 出库开始时间 /// + [Column("出库开始时间")] public string OutStockBeginTime { get; set; } /// /// 出库结束时间 /// + [Column("出库结束时间")] public string OutStockEndTime { get; set; } } } diff --git a/src/WMS.Web.Domain/Entitys/FileDownManager.cs b/src/WMS.Web.Domain/Entitys/FileDownManager.cs new file mode 100644 index 00000000..27819d83 --- /dev/null +++ b/src/WMS.Web.Domain/Entitys/FileDownManager.cs @@ -0,0 +1,84 @@ + +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Text; +using WMS.Web.Core; +using WMS.Web.Domain.Values; + +namespace WMS.Web.Domain.Entitys +{ + /// + /// 文件下载类型 + /// + [Serializable] + [Table("t_wms_file_down_manager")] + public class FileDownManager : EntityBase + { + public FileDownManager() { } + public FileDownManager(int userId, int companyId, FileDownLoadOrderType type, string path, int? supplierId = null) + { + this.UserId = userId; + this.CompanyId = companyId; + this.Type = type; + this.FilePath = path; + this.SupplierId = supplierId; + } + /// + /// 主键 订单编号 + /// + [Column("Id")] + public override int Id { get; set; } + /// + /// 日期 + /// + [Column("Date")] + public DateTime? Date { get; set; } = DateTime.Now; + /// + /// 单据类型(任务类型) + /// + [Column("Type")] + public FileDownLoadOrderType Type { get; set; } = FileDownLoadOrderType.OutStockTask; + /// + /// 状态 + /// + [Column("Status")] + public ExportStatus Status { get; set; } = ExportStatus.Ing; + /// + /// 公司Id + /// + [Column("CompanyId")] + public int CompanyId { get; set; } + /// + /// 文件地址 + /// + [Column("FilePath")] + public string FilePath { get; set; } + /// + /// 操作人 + /// + [Column("UserId")] + public int UserId { get; set; } + /// + /// 失败原因 + /// + [Column("Reason")] + public string Reason { get; set; } + /// + /// 是否供应商用户 + /// + [Column("SupplierId")] + public int? SupplierId { get; set; } + + public void Finish(bool IsSuccess, string reson) + { + if (IsSuccess) + this.Status = ExportStatus.Success; + else + { + this.Status = ExportStatus.Fail; + this.Reason = reson; + } + } + } +} diff --git a/src/WMS.Web.Domain/IService/IExportExcelService.cs b/src/WMS.Web.Domain/IService/IExportExcelService.cs new file mode 100644 index 00000000..43d739c3 --- /dev/null +++ b/src/WMS.Web.Domain/IService/IExportExcelService.cs @@ -0,0 +1,55 @@ +using Npoi.Mapper; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using WMS.Web.Core.Dto; +using WMS.Web.Domain.Values; + +namespace WMS.Web.Domain.IService +{ + public interface IExportExcelService + { + /// + /// 全字段导出数据 + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + Task ExportAll(Request request, string fileName, int userId,int companyId, FileDownLoadOrderType type, Mapper mapper = null, int? supplierId = null) where Request : PaginationBaseRequestDto; + /// + /// 列表字段导出数据 + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + Task ExportList(Request request, string fileName, int userId, int companyId, FileDownLoadOrderType type, Mapper mapper = null, int? supplierId = null) where Request : PaginationBaseRequestDto; + /// + /// 列表页导出数据 + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + Task Export(List dataList, string fileName,int userId,int companyId, FileDownLoadOrderType type, Mapper mapper = null, int? supplierId = null); + } +} diff --git a/src/WMS.Web.Domain/IService/IQiniuUploadService.cs b/src/WMS.Web.Domain/IService/IQiniuUploadService.cs new file mode 100644 index 00000000..8e92b821 --- /dev/null +++ b/src/WMS.Web.Domain/IService/IQiniuUploadService.cs @@ -0,0 +1,22 @@ + +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using System.Threading.Tasks; +using WMS.Web.Core.Internal.Results; + +namespace WMS.Web.Domain.IService +{ + public interface IQiniuUploadService + { + /// + /// 上传文件 + /// + /// + /// + /// 是否开启自动删除 如果开启 3天后自动删除 导出的execl文件 + /// + Task> Upload(string fileName, Stream stream,bool isAutoDelte= false); + } +} diff --git a/src/WMS.Web.Domain/Infrastructure/IAllFielRepositories.cs b/src/WMS.Web.Domain/Infrastructure/IAllFielRepositories.cs new file mode 100644 index 00000000..2ace75eb --- /dev/null +++ b/src/WMS.Web.Domain/Infrastructure/IAllFielRepositories.cs @@ -0,0 +1,26 @@ + +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using System.Threading.Tasks; + +namespace WMS.Web.Domain.Infrastructure +{ + public interface IAllFielRepositories + { + /// + /// 全字段导出接口 + /// + /// + /// + //Task<(object obj, int total)> GetListAllField(Request dto, int companyId); + + /// + /// 列表字段导出接口 + /// + /// + /// + Task<(object obj, int total)> GetListField(Request dto, int companyId); + } +} diff --git a/src/WMS.Web.Domain/Infrastructure/IFileDownManagerRepositories.cs b/src/WMS.Web.Domain/Infrastructure/IFileDownManagerRepositories.cs new file mode 100644 index 00000000..1f1bb96b --- /dev/null +++ b/src/WMS.Web.Domain/Infrastructure/IFileDownManagerRepositories.cs @@ -0,0 +1,31 @@ + +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using WMS.Web.Core.Dto; +using WMS.Web.Domain.Entitys; + +namespace WMS.Web.Domain.Infrastructure +{ + public interface IFileDownManagerRepositories + { + /// + /// 保存 + /// + /// + /// + Task Add(FileDownManager entity); + /// + /// 编辑 + /// + /// + /// + Task Edit(FileDownManager entity); + /// + /// 获取销售列表 + /// + /// + Task GetList(FileDownManagerRequest dto,int companyId); + } +} diff --git a/src/WMS.Web.Domain/Options/QiniuOptions.cs b/src/WMS.Web.Domain/Options/QiniuOptions.cs new file mode 100644 index 00000000..1f181db7 --- /dev/null +++ b/src/WMS.Web.Domain/Options/QiniuOptions.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace WMS.Web.Domain.Options +{ + /// + /// 七牛云 配置 + /// + public class QiniuOptions + { + /// + /// 访问key + /// + public string AccessKey { get; set; } + /// + /// 秘钥 + /// + public string SecretKey { get; set; } + /// + /// 区块文件夹 + /// + public string Bucket { get; set; } + /// + /// 访问域名 + /// + public string Url { get; set; } + //导出数据一页条数 + public int PageSize { get; set; } = 50000; + } +} diff --git a/src/WMS.Web.Domain/Services/ExportExcelService.cs b/src/WMS.Web.Domain/Services/ExportExcelService.cs new file mode 100644 index 00000000..71f5e52c --- /dev/null +++ b/src/WMS.Web.Domain/Services/ExportExcelService.cs @@ -0,0 +1,228 @@ + +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using Npoi.Mapper; +using System.IO; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using WMS.Web.Domain.IService; +using WMS.Web.Domain.Options; +using WMS.Web.Domain.Entitys; +using WMS.Web.Domain.Values; +using WMS.Web.Domain.Infrastructure; +using WMS.Web.Core.Dto; + +namespace WMS.Web.Domain.Services +{ + public class ExportExcelService : IExportExcelService + { + private readonly IQiniuUploadService _qiniuUploadService; + private readonly IServiceScopeFactory _serviceScopeFactory; + private readonly ILogger _logger; + private readonly QiniuOptions _option; + public ExportExcelService(IQiniuUploadService qiniuUploadService, IServiceScopeFactory serviceScopeFactory, + ILogger logger, IOptions option) + { + _qiniuUploadService = qiniuUploadService; + _serviceScopeFactory = serviceScopeFactory; + _logger = logger; + _option = option?.Value; + } + /// + /// 列表页导出 + /// + /// + /// + /// + /// + /// + /// + /// + /// + public async Task Export(List dataList, string fileName, int userId, int companyId, FileDownLoadOrderType type, Mapper mapper = null, int? supplierId = null) + { + FileDownManager entity = new FileDownManager(userId, companyId, type, _option.Url + fileName, supplierId); + using (var scope = _serviceScopeFactory.CreateScope()) + { + var _fileDownManagerService = scope.ServiceProvider.GetRequiredService(); + entity = await _fileDownManagerService.Add(entity); + List> listz = new List>(); + listz.Add(dataList); + + string msg = await Upload(listz, fileName, userId, type); + + entity.Finish(string.IsNullOrEmpty(msg) == true ? true : false, msg); + await _fileDownManagerService.Edit(entity); + return; + } + } + /// + /// 全字段导出 + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + public Task ExportAll(Request request, string fileName, int userId, int companyId, FileDownLoadOrderType type, Mapper mapper = null, int? supplierId = null) where Request : PaginationBaseRequestDto + { + return Task.CompletedTask; + //FileDownManager entity = new FileDownManager(userId, companyId, type, _option.Url + fileName, supplierId); + + //request.PageNo = 1; + //request.PageSize = _option.PageSize; + //List> listz = new List>(); + //string msg = ""; + //using (var scope = _serviceScopeFactory.CreateScope()) + //{ + // var _fileDownManagerService = scope.ServiceProvider.GetRequiredService(); + // entity = await _fileDownManagerService.Add(entity); + // try + // { + // var _service = scope.ServiceProvider.GetRequiredService>(); + // _logger.LogInformation($"{DateTime.Now}--开始访问数据"); + // var (obj, total) = await _service.GetListAllField(request, companyId); + // var list = (List)obj; + // var page = Math.Ceiling(Convert.ToDecimal(total) / _option.PageSize); + + // listz.Add(list); + // for (int i = 1; i < page; i++) + // { + // request.PageNo++; + // var (obj_f, total_f) = await _service.GetListAllField(request, companyId); + // var list_f = (List)obj_f; + // listz.Add(list_f); + // } + // _logger.LogInformation($"{DateTime.Now}--访问数据成功 总数:{total}"); + // } + // catch (Exception ex) + // { + // msg = $"未找到数据 {ex.ToString()}"; + // _logger.LogError($"导出异常:{ex.ToString()}"); + // } + + // if (!string.IsNullOrEmpty(msg)) + // { + // entity.Finish(false, msg); + // await _fileDownManagerService.Edit(entity); + // return; + // } + + // msg = await Upload(listz, fileName, userId, type); + + // entity.Finish(string.IsNullOrEmpty(msg) == true ? true : false, msg); + // await _fileDownManagerService.Edit(entity); + // return; + //} + } + + public async Task ExportList(Request request, string fileName, int userId, int companyId, FileDownLoadOrderType type, Mapper mapper = null, int? supplierId = null) where Request : PaginationBaseRequestDto + { + FileDownManager entity = new FileDownManager(userId, companyId, type, _option.Url + fileName, supplierId); + + request.PageNo = 1; + request.PageSize = _option.PageSize; + List> listz = new List>(); + string msg = ""; + using (var scope = _serviceScopeFactory.CreateScope()) + { + var _fileDownManagerService = scope.ServiceProvider.GetRequiredService(); + entity = await _fileDownManagerService.Add(entity); + try + { + var _service = scope.ServiceProvider.GetRequiredService>(); + _logger.LogInformation($"{DateTime.Now}--开始访问数据"); + var (obj, total) = await _service.GetListField(request, companyId); + var list = (List)obj; + var page = Math.Ceiling(Convert.ToDecimal(total) / _option.PageSize); + + listz.Add(list); + for (int i = 1; i < page; i++) + { + request.PageNo++; + var (obj_f, total_f) = await _service.GetListField(request, companyId); + var list_f = (List)obj_f; + listz.Add(list_f); + } + _logger.LogInformation($"{DateTime.Now}--访问数据成功 总数:{total}"); + } + catch (Exception ex) + { + msg = "未找到数据"; + _logger.LogError($"导出数据查询异常 {ex.ToString()}"); + } + + if (listz.Count <= 0) + { + entity.Finish(false, msg); + await _fileDownManagerService.Edit(entity); + return; + } + + msg = await Upload(listz, fileName, userId, type); + + entity.Finish(string.IsNullOrEmpty(msg) == true ? true : false, msg); + await _fileDownManagerService.Edit(entity); + return; + } + } + + private async Task Upload(List> dataList, string fileName, int userId, FileDownLoadOrderType type, Mapper mapper = null) + { + if (mapper == null) + mapper = new Mapper(); + + //第一个参数为导出Excel名称 + //第二个参数为Excel数据来源 + //第三个参数为导出的Sheet名称 + //overwrite参数如果是要覆盖已存在的Excel或者新建Excel则为true,如果在原有Excel上追加数据则为false + //xlsx参数是用于区分导出的数据格式为xlsx还是xls + MemoryStream stream = new MemoryStream(); + try + { + for (int i = 0; i < dataList.Count; i++) + { + mapper.Put(dataList[i], "sheet" + (i + 1), true); + } + mapper.Save(stream); + } + catch (Exception) + { + return "数据导入Execl异常"; + } + + + //mapper.Save(stream, dataList, "sheet1", overwrite: true, xlsx: true); + //,但是这里也踩到了一个坑,不过这个是 Npoi 的坑并不是 Npoi.Mapper 的坑, + // 那就是 Workbook.Write(stream)的时候会将 stream 关闭,如果继续操作这个 Stream 会报流已关闭的错误 + //所以这里 是把流先转成byte[] 再转回使用的流 + try + { + var middleByte = stream.ToArray(); + using (MemoryStream streamUpload = new MemoryStream(middleByte)) + { + var res = await _qiniuUploadService.Upload(fileName, streamUpload, true); + if (!res.Success) + { + _logger.LogError($"{DateTime.Now}--上传千牛云失败 原因:{res.Message}"); + return res.Message; + } + } + } + catch (Exception) + { + return "数据上传云端异常"; + } + + _logger.LogInformation($"{DateTime.Now}--导出成功"); + return ""; + } + } +} diff --git a/src/WMS.Web.Domain/Services/QiniuUploadService.cs b/src/WMS.Web.Domain/Services/QiniuUploadService.cs new file mode 100644 index 00000000..4f3c3fcb --- /dev/null +++ b/src/WMS.Web.Domain/Services/QiniuUploadService.cs @@ -0,0 +1,73 @@ +using Microsoft.Extensions.Options; +using Newtonsoft.Json; +using Qiniu.Http; +using Qiniu.Storage; +using Qiniu.Util; +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using System.Threading.Tasks; +using WMS.Web.Core.Internal.Results; +using WMS.Web.Domain.IService; +using WMS.Web.Domain.Options; + +namespace WMS.Web.Domain.Services +{ + public class QiniuUploadService : IQiniuUploadService + { + private readonly QiniuOptions _option; + public QiniuUploadService(IOptions option) + { + _option = option?.Value; + } + /// + /// 上传文件 + /// + /// + /// + /// + /// + public Task> Upload(string fileName, Stream stream, bool isAutoDelte = false) + { + // 生成(上传)凭证时需要使用此Mac + // 这个示例单独使用了一个Settings类,其中包含AccessKey和SecretKey + // 实际应用中,请自行设置您的AccessKey和SecretKey + Mac mac = new Mac(_option.AccessKey, _option.SecretKey); + + PutPolicy putPolicy = new PutPolicy(); + // 如果需要设置为"覆盖"上传(如果云端已有同名文件则覆盖),请使用 SCOPE = "BUCKET:KEY" + putPolicy.Scope = _option.Bucket + ":" + fileName; + // putPolicy.Scope = bucket; + // 上传策略有效期(对应于生成的凭证的有效期) + putPolicy.SetExpires(3600); + // 上传到云端多少天后自动删除该文件,如果不设置(即保持默认默认)则不删除 + if (isAutoDelte) + putPolicy.DeleteAfterDays = 7; + string jstr = putPolicy.ToJsonString(); + string token = Auth.CreateUploadToken(mac, jstr); + + Config config = new Config(); + // 空间对应的机房 华 东 ZONE_CN_East 华 北 ZONE_CN_North 华 南 ZONE_CN_Sout 北 美 ZONE_US_North 东南亚 ZONE_AS_Singapore + config.Zone = Zone.ZONE_CN_South; + // 是否使用https域名 + config.UseHttps = true; + // 上传是否使用cdn加速 + config.UseCdnDomains = true; + HttpResult result = null; + try + { + FormUploader fu = new FormUploader(config); + result = fu.UploadStream(stream, fileName, token, null); + if (result.Code == 200) + return Task.FromResult(Result.ReSuccess(_option.Url + fileName)); + } + catch (Exception ex) + { + Console.WriteLine(ex); + return Task.FromResult(Result.ReFailure("上传文件失败" + ex.ToString(), 0)); + } + return Task.FromResult(Result.ReFailure("上传文件失败" + JsonConvert.SerializeObject(result), 0)); + } + } +} diff --git a/src/WMS.Web.Domain/Values/ExportStatus.cs b/src/WMS.Web.Domain/Values/ExportStatus.cs new file mode 100644 index 00000000..33f1ede4 --- /dev/null +++ b/src/WMS.Web.Domain/Values/ExportStatus.cs @@ -0,0 +1,30 @@ + +using System; +using System.Collections.Generic; +using System.Text; +using WMS.Web.Core; + +namespace WMS.Web.Domain.Values +{ + /// + /// 文件导出状态 + /// + public enum ExportStatus + { + /// + /// 正在导出 + /// + [EnumRemark("正在导出")] + Ing = 0, + /// + /// 导出成功 + /// + [EnumRemark("导出成功")] + Success = 1, + /// + /// 导出失败 + /// + [EnumRemark("导出失败")] + Fail = 2 + } +} diff --git a/src/WMS.Web.Domain/Values/FileDownLoadOrderType.cs b/src/WMS.Web.Domain/Values/FileDownLoadOrderType.cs new file mode 100644 index 00000000..f18e4da8 --- /dev/null +++ b/src/WMS.Web.Domain/Values/FileDownLoadOrderType.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Text; +using WMS.Web.Core; + +namespace WMS.Web.Domain.Values +{ + /// + /// 导出单据类型 + /// + public enum FileDownLoadOrderType + { + /// + /// 出库任务单 + /// + [EnumRemark("出库任务单")] + OutStockTask = 1, + } +} diff --git a/src/WMS.Web.Repositories/Configuration/RepositoryDbContext.cs b/src/WMS.Web.Repositories/Configuration/RepositoryDbContext.cs index 729c827a..952dad35 100644 --- a/src/WMS.Web.Repositories/Configuration/RepositoryDbContext.cs +++ b/src/WMS.Web.Repositories/Configuration/RepositoryDbContext.cs @@ -68,6 +68,11 @@ namespace WMS.Web.Repositories.Configuration ent.ToTable("t_wms_sync_date"); ent.HasKey(x => x.Id); }); + builder.Entity(ent => + { + ent.ToTable("t_wms_file_down_manager"); + ent.HasKey(x => x.Id); + }); #region 出库单 @@ -253,6 +258,7 @@ namespace WMS.Web.Repositories.Configuration base.OnModelCreating(builder); } + public DbSet FileDownManager { get; set; } public DbSet SerialNumbers { get; set; } public DbSet ErpOpsSyncDate { get; set; } public DbSet SerialNumberOperate { get; set; } diff --git a/src/WMS.Web.Repositories/DependencyInjection/AppBuilder.cs b/src/WMS.Web.Repositories/DependencyInjection/AppBuilder.cs index 1842957d..92d2a455 100644 --- a/src/WMS.Web.Repositories/DependencyInjection/AppBuilder.cs +++ b/src/WMS.Web.Repositories/DependencyInjection/AppBuilder.cs @@ -177,6 +177,8 @@ namespace WMS.Web.Repositories.DependencyInjection Services.Configure(Configuration.GetSection("ErpOptions")); Services.AddOptions(); Services.Configure(Configuration.GetSection("OpsOptions")); + Services.AddOptions(); + Services.Configure(Configuration.GetSection("Qiniu")); } /// @@ -252,7 +254,8 @@ namespace WMS.Web.Repositories.DependencyInjection Services.AddTransient(); Services.AddTransient(); - + Services.AddTransient(); + Services.AddTransient(); Services.AddTransient(); diff --git a/src/WMS.Web.Repositories/DependencyInjection/AppBuilderExtensions.cs b/src/WMS.Web.Repositories/DependencyInjection/AppBuilderExtensions.cs index 4ed35dbb..268de92c 100644 --- a/src/WMS.Web.Repositories/DependencyInjection/AppBuilderExtensions.cs +++ b/src/WMS.Web.Repositories/DependencyInjection/AppBuilderExtensions.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Text; +using WMS.Web.Core.Dto.OutStockTask; using WMS.Web.Domain.Infrastructure; using WMS.Web.Repositories; using WMS.Web.Repositories.Configuration; @@ -36,7 +37,11 @@ namespace Microsoft.Extensions.DependencyInjection services.AddTransient(); services.AddTransient(); services.AddTransient(); - + + #region 导出 + services.AddTransient, OutStockTaskRepositories>(); + #endregion + services.AddTransient(); services.AddTransient(); @@ -44,7 +49,7 @@ namespace Microsoft.Extensions.DependencyInjection services.AddTransient(); services.AddTransient(); services.AddTransient(); - + services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/src/WMS.Web.Repositories/FileDownManagerRepositories.cs b/src/WMS.Web.Repositories/FileDownManagerRepositories.cs new file mode 100644 index 00000000..1be5e576 --- /dev/null +++ b/src/WMS.Web.Repositories/FileDownManagerRepositories.cs @@ -0,0 +1,103 @@ +using AutoMapper; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WMS.Web.Core; +using WMS.Web.Core.Dto; +using WMS.Web.Domain.Entitys; +using WMS.Web.Domain.Infrastructure; +using WMS.Web.Domain.IService.Public; +using WMS.Web.Domain.Values; +using WMS.Web.Domain.Values.Single; +using WMS.Web.Repositories.Configuration; + +namespace WMS.Web.Repositories +{ + public class FileDownManagerRepositories : IFileDownManagerRepositories + { + private readonly IMapper _mapper; + private readonly RepositoryDbContext _context; + private readonly ISingleDataService _singleDataService; + public FileDownManagerRepositories(RepositoryDbContext context, IMapper mapper, ISingleDataService singleDataService) + { + _mapper = mapper; + _context = context; + _singleDataService = singleDataService; + } + + public async Task Add(FileDownManager entity) + { + await _context.FileDownManager.AddAsync(entity); + await _context.SaveChangesAsync(); + + return entity; + } + + public async Task Edit(FileDownManager entity) + { + var res = await _context.FileDownManager + .FirstOrDefaultAsync(f => f.Id == entity.Id); + if (res == null) return null; + + _mapper.Map(entity, res); + + await _context.SaveChangesAsync(); + return res; + } + + public async Task GetList(FileDownManagerRequest dto, int companyId) + { + List userIds = new List(); + if (!string.IsNullOrEmpty(dto.User)) + userIds = _singleDataService.GetIdsBySingleName(SingleAction.Staffs, companyId, dto.User); + + var res = _context.FileDownManager + //.GroupJoin(_context.UcStaff, manager => manager.UserId, user => user.Id, (manager, user) => new { manager, user }) + // .SelectMany(x => x.user.DefaultIfEmpty(), (d, user) => new { d.manager, user }) + .OrderByDescending(o => o.Date) + .Where(w => w.CompanyId == companyId); + + + #region 条件 + if (!string.IsNullOrEmpty(dto.User)) + res = res.Where(w => userIds.Contains(w.UserId)); + if (dto.BeginDate != null) + res = res.Where(w => w.Date >= dto.BeginDate); + if (dto.EndDate != null) + res = res.Where(w => w.Date <= (dto.EndDate ?? DateTime.Now).AddHours(23).AddMinutes(59).AddSeconds(59)); + if (dto.Type != null) + res = res.Where(w => w.Type == (FileDownLoadOrderType)dto.Type); + + if (dto.SupplierId != null) + res = res.Where(w => w.SupplierId == dto.SupplierId); + + if (dto.Status != null) + { + if ((ExportStatus)dto.Status == ExportStatus.Ing) + res = res.Where(w => w.Status == ExportStatus.Ing && w.Date >= DateTime.Now.AddHours(-1)); + else if ((ExportStatus)dto.Status == ExportStatus.Fail) + res = res.Where(w => (w.Status == ExportStatus.Fail) || (w.Status == ExportStatus.Ing && w.Date < DateTime.Now.AddHours(-1))); + else + res = res.Where(w => w.Status == (ExportStatus)dto.Status); + } + #endregion + + int total = await res.CountAsync(); + var list = await res.Select(s => new FileDownInfoManagerResponse(_mapper.Map(s)) + { + StatusKey = (s.Status == ExportStatus.Ing && s.Date < DateTime.Now.AddHours(-1)) ? (int)ExportStatus.Fail : (int)s.Status, + Status = (s.Status == ExportStatus.Ing && s.Date < DateTime.Now.AddHours(-1)) ? ExportStatus.Fail.GetRemark() : s.Status.GetRemark(), + UserName = dto.SupplierId != null + ? _singleDataService.GetSingleData(SingleAction.Users, companyId, s.UserId) + : _singleDataService.GetSingleData(SingleAction.Staffs, companyId, s.UserId),//s.StaffName + }) + .Skip((dto.PageNo - 1) * dto.PageSize).Take(dto.PageSize) + .ToListAsync(); + + return new FileDownManagerResponse(list, total); + } + } +} diff --git a/src/WMS.Web.Repositories/OutStockTaskRepositories.cs b/src/WMS.Web.Repositories/OutStockTaskRepositories.cs index 21e32446..af812d35 100644 --- a/src/WMS.Web.Repositories/OutStockTaskRepositories.cs +++ b/src/WMS.Web.Repositories/OutStockTaskRepositories.cs @@ -20,7 +20,7 @@ using WMS.Web.Repositories.Configuration; namespace WMS.Web.Repositories { - public class OutStockTaskRepositories : IOutStockTaskRepositories + public class OutStockTaskRepositories : IAllFielRepositories, IOutStockTaskRepositories { private readonly IMapper _mapper; private readonly IServiceProvider _serviceProvider; @@ -425,5 +425,16 @@ namespace WMS.Web.Repositories .Select(s => s.BillNo) .ToListAsync(); } + + /// + /// 导出列表 + /// + /// + /// + /// + public async Task<(object obj, int total)> GetListField(OutStockTaskQueryRequest dto, int companyId) + { + return await GetListAsync(dto); + } } }