| | |
| | | using SqlSugar; |
| | | using Newtonsoft.Json; |
| | | using System.Text; |
| | | using OfficeOpenXml; |
| | | using OfficeOpenXml.Style; |
| | | |
| | | namespace MES.Service.service.Warehouse; |
| | | |
| | |
| | | throw new Exception("页码必须大于0"); |
| | | } |
| | | |
| | | if (!new[] { 10, 20, 50 }.Contains(searchDto.PageSize)) |
| | | { |
| | | throw new Exception("每页条数必须为10、20或50"); |
| | | } |
| | | // if (!new[] { 10, 20, 50 }.Contains(searchDto.PageSize)) |
| | | // { |
| | | // throw new Exception("每页条数必须为10、20或50"); |
| | | // } |
| | | |
| | | // 1. 查询XB_RACKING_TASK_SYXT_LOG中ItemBarcode和PalletCode的映射关系 |
| | | var allRackingTaskData = Db.Queryable<XbRackingTaskSyxtLog>() |
| | |
| | | throw; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 导出可退货物料库存为Excel |
| | | /// </summary> |
| | | /// <param name="searchDto">搜索请求参数</param> |
| | | /// <returns>Excel文件字节数组</returns> |
| | | public byte[] ExportReturnableStocksToExcel( |
| | | ReturnableStockSearchDto searchDto) |
| | | { |
| | | // 设置 EPPlus 许可证上下文(非商业用途) |
| | | ExcelPackage.LicenseContext = LicenseContext.NonCommercial; |
| | | |
| | | // 获取所有数据(不分页) |
| | | var tempSearchDto = new ReturnableStockSearchDto |
| | | { |
| | | PageIndex = 1, |
| | | PageSize = int.MaxValue, // 获取所有数据 |
| | | Conditions = searchDto.Conditions |
| | | }; |
| | | |
| | | // 调用查询方法获取数据 |
| | | var result = GetReturnableStocks(tempSearchDto); |
| | | var dataList = result.TbBillList; |
| | | |
| | | // 创建 Excel 文件 |
| | | using var package = new ExcelPackage(); |
| | | var worksheet = package.Workbook.Worksheets.Add("可退货物料库存"); |
| | | |
| | | // 设置表头 |
| | | var headers = new[] |
| | | { |
| | | "良品状态", |
| | | "是否成品", |
| | | "母托盘编号", |
| | | "仓库编码", |
| | | "仓库名称", |
| | | "虚拟库位", |
| | | "物料编号", |
| | | "物料名称", |
| | | "物料规格", |
| | | "物料数量", |
| | | "物料单位", |
| | | "入库时间", |
| | | "组织编码", |
| | | "组织名称", |
| | | "物料条码", |
| | | "库存状态" |
| | | }; |
| | | |
| | | // 写入表头 |
| | | for (int i = 0; i < headers.Length; i++) |
| | | { |
| | | worksheet.Cells[1, i + 1].Value = headers[i]; |
| | | worksheet.Cells[1, i + 1].Style.Font.Bold = true; |
| | | worksheet.Cells[1, i + 1].Style.Fill.PatternType = |
| | | ExcelFillStyle.Solid; |
| | | worksheet.Cells[1, i + 1].Style.Fill.BackgroundColor |
| | | .SetColor(System.Drawing.Color.LightGray); |
| | | worksheet.Cells[1, i + 1].Style.HorizontalAlignment = |
| | | ExcelHorizontalAlignment.Center; |
| | | } |
| | | |
| | | // 写入数据 |
| | | int row = 2; |
| | | foreach (var item in dataList) |
| | | { |
| | | worksheet.Cells[row, 1].Value = |
| | | item.IqcStatus == "1" ? "良品" : "不良品"; |
| | | worksheet.Cells[row, 2].Value = item.ItemType == "1" ? "成品" : "非成品"; |
| | | worksheet.Cells[row, 3].Value = item.StackCode; |
| | | worksheet.Cells[row, 4].Value = item.DepotCode; |
| | | worksheet.Cells[row, 5].Value = item.DepotName; |
| | | worksheet.Cells[row, 6].Value = item.DepotSectionsCode; |
| | | worksheet.Cells[row, 7].Value = item.ItemNo; |
| | | worksheet.Cells[row, 8].Value = item.ItemName; |
| | | worksheet.Cells[row, 9].Value = item.ItemModel; |
| | | worksheet.Cells[row, 10].Value = item.Quantity; |
| | | worksheet.Cells[row, 11].Value = item.ItemUnitName; |
| | | worksheet.Cells[row, 12].Value = |
| | | item.IndepDate?.ToString("yyyy-MM-dd HH:mm:ss"); |
| | | worksheet.Cells[row, 13].Value = item.OrgCode; |
| | | worksheet.Cells[row, 14].Value = item.OrgName; |
| | | worksheet.Cells[row, 15].Value = item.ItemBarcode; |
| | | worksheet.Cells[row, 16].Value = item.StockStatus; |
| | | row++; |
| | | } |
| | | |
| | | // 自动调整列宽 |
| | | worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns(); |
| | | |
| | | // 返回 Excel 文件字节数组 |
| | | return package.GetAsByteArray(); |
| | | } |
| | | } |