From 073bffccfe13abbf83739e1bead4bc4e8ce59441 Mon Sep 17 00:00:00 2001 From: zpc Date: Sun, 8 Feb 2026 19:34:23 +0800 Subject: [PATCH] 12 --- .../Business/OdfPortsController.cs | 7 +- ZR.Model/Business/Dto/OdfPortsDto.cs | 74 ++++++++++++++ .../IBusinessService/IOdfPortsService.cs | 5 + ZR.Service/Business/OdfPortsService.cs | 97 +++++++++++++++++++ 4 files changed, 179 insertions(+), 4 deletions(-) diff --git a/ZR.Admin.WebApi/Controllers/Business/OdfPortsController.cs b/ZR.Admin.WebApi/Controllers/Business/OdfPortsController.cs index 0bfc7db..a221f6b 100644 --- a/ZR.Admin.WebApi/Controllers/Business/OdfPortsController.cs +++ b/ZR.Admin.WebApi/Controllers/Business/OdfPortsController.cs @@ -510,22 +510,21 @@ namespace ZR.Admin.WebApi.Controllers.Business } /// - /// 导出端口 + /// 导出端口(与导入模板格式一致) /// /// [Log(Title = "导出端口数据", BusinessType = BusinessType.EXPORT, IsSaveResponseData = false)] [HttpGet("export")] [ActionPermissionFilter(Permission = "odfports:export")] - public IActionResult Export([FromQuery] OdfPortsQueryDto parm) { - var list = _OdfPortsService.ExportList(parm).Result; + var list = _OdfPortsService.ExportListForImport(parm).Result; if (list == null || list.Count <= 0) { return ToResponse(ResultCode.FAIL, "没有要导出的数据"); } - var result = ExportExcelMini(list, "端口", "端口"); + var result = ExportExcelMini(list, "端口数据", "端口数据"); return ExportExcel(result.Item2, result.Item1); } /// diff --git a/ZR.Model/Business/Dto/OdfPortsDto.cs b/ZR.Model/Business/Dto/OdfPortsDto.cs index 59518dd..b64c021 100644 --- a/ZR.Model/Business/Dto/OdfPortsDto.cs +++ b/ZR.Model/Business/Dto/OdfPortsDto.cs @@ -645,4 +645,78 @@ namespace ZR.Model.Business.Dto /// public string FaultReason { get; set; } } + + /// + /// 端口导出对象(与导入模板格式一致,导出后可直接导入) + /// + public class OdfPortsExportForImportDto + { + [ExcelColumn(Name = "机房名称", Width = 15)] + [ExcelColumnName("机房名称")] + public string RoomName { get; set; } + + [ExcelColumn(Name = "机架名称", Width = 15)] + [ExcelColumnName("机架名称")] + public string RackName { get; set; } + + [ExcelColumn(Name = "机框名称", Width = 15)] + [ExcelColumnName("机框名称")] + public string FrameName { get; set; } + + [ExcelColumn(Name = "行号(1-6)", Width = 12)] + [ExcelColumnName("行号(1-6)")] + public int RowNumber { get; set; } + + [ExcelColumn(Name = "端口号(1-12)", Width = 12)] + [ExcelColumnName("端口号(1-12)")] + public int PortNumber { get; set; } + + [ExcelColumn(Name = "连接状态,0断开,1连接", Width = 20)] + [ExcelColumnName("连接状态,0断开,1连接")] + public int Status { get; set; } + + [ExcelColumn(Name = "备注", Width = 30)] + [ExcelColumnName("备注")] + public string Remarks { get; set; } + + [ExcelColumn(Name = "光衰值(dB)", Width = 12)] + [ExcelColumnName("光衰值(dB)")] + public string OpticalAttenuation { get; set; } + + [ExcelColumn(Name = "历史故障记录", Width = 30)] + [ExcelColumnName("历史故障记录")] + public string HistoryRemarks { get; set; } + + [ExcelColumn(Name = "部门名称", Width = 15)] + [ExcelColumnName("部门名称")] + public string DeptName { get; set; } + + [ExcelColumn(Name = "光缆段信息", Width = 25)] + [ExcelColumnName("光缆段信息")] + public string OpticalCableOffRemarks { get; set; } + + [ExcelColumn(Name = "设备型号", Width = 15)] + [ExcelColumnName("设备型号")] + public string EquipmentModel { get; set; } + + [ExcelColumn(Name = "业务类型", Width = 15)] + [ExcelColumnName("业务类型")] + public string BusinessType { get; set; } + + [ExcelColumn(Name = "业务名称", Width = 15)] + [ExcelColumnName("业务名称")] + public string YeWuMingCheng { get; set; } + + [ExcelColumn(Name = "1号端口", Width = 12)] + [ExcelColumnName("1号端口")] + public string One { get; set; } + + [ExcelColumn(Name = "2号端口", Width = 12)] + [ExcelColumnName("2号端口")] + public string Two { get; set; } + + [ExcelColumn(Name = "3号端口", Width = 12)] + [ExcelColumnName("3号端口")] + public string Three { get; set; } + } } \ No newline at end of file diff --git a/ZR.Service/Business/IBusinessService/IOdfPortsService.cs b/ZR.Service/Business/IBusinessService/IOdfPortsService.cs index 49c7a3e..54a7557 100644 --- a/ZR.Service/Business/IBusinessService/IOdfPortsService.cs +++ b/ZR.Service/Business/IBusinessService/IOdfPortsService.cs @@ -20,5 +20,10 @@ namespace ZR.Service.Business.IBusinessService PagedInfo ExportList(OdfPortsQueryDto parm); PagedInfo ExportList(OdfPortsQuerysDto parm); + + /// + /// 导出端口(与导入模板格式一致) + /// + PagedInfo ExportListForImport(OdfPortsQueryDto parm); } } diff --git a/ZR.Service/Business/OdfPortsService.cs b/ZR.Service/Business/OdfPortsService.cs index 3fa98dd..f46098d 100644 --- a/ZR.Service/Business/OdfPortsService.cs +++ b/ZR.Service/Business/OdfPortsService.cs @@ -172,6 +172,103 @@ namespace ZR.Service.Business return response; } + + /// + /// 导出端口(与导入模板格式一致,导出后可直接导入) + /// + /// + /// + public PagedInfo ExportListForImport(OdfPortsQueryDto parm) + { + parm.PageNum = 1; + parm.PageSize = 10000000; + parm.Sort = string.Empty; // 清除排序,避免字段不存在报错 + var predicate = QueryExp(parm); + + var response = Queryable() + .Where(predicate.ToExpression()) + .OrderBy("RoomId asc,RackId asc,FrameId asc,RowNumber asc,PortNumber Asc") + .Select((it) => new OdfPortsExportForImportDto() + { + RoomName = it.RoomName, + RackName = it.RackName, + FrameName = it.FrameName, + RowNumber = it.RowNumber, + PortNumber = it.PortNumber, + Status = it.Status, + Remarks = it.Remarks, + OpticalAttenuation = it.OpticalAttenuation, + HistoryRemarks = it.HistoryRemarks, + DeptName = it.DeptName, + OpticalCableOffRemarks = it.OpticalCableOffRemarks, + EquipmentModel = it.EquipmentModel, + BusinessType = it.BusinessType + }) + .ToPage(parm); + + // 反向解析 Remarks 字段,拆分出 业务名称、1号端口、2号端口、3号端口 + foreach (var item in response.Result) + { + ParseRemarksToFields(item); + } + + return response; + } + + /// + /// 反向解析 Remarks 字段 + /// 格式:{业务名称} {设备型号} {业务类型} {1号端口}/{2号端口}/{3号端口} + /// + private void ParseRemarksToFields(OdfPortsExportForImportDto item) + { + try + { + if (string.IsNullOrWhiteSpace(item.Remarks)) + { + item.YeWuMingCheng = ""; + item.One = ""; + item.Two = ""; + item.Three = ""; + return; + } + + var remarks = item.Remarks.Trim(); + + // 尝试按空格分割 + var parts = remarks.Split(' ', StringSplitOptions.RemoveEmptyEntries); + + if (parts.Length >= 1) + { + item.YeWuMingCheng = parts[0]; // 第一部分是业务名称 + } + + // 查找最后一个包含 "/" 的部分,那是端口信息 + var lastPart = parts.Length > 0 ? parts[parts.Length - 1] : ""; + if (lastPart.Contains("/")) + { + var portParts = lastPart.Split('/'); + item.One = portParts.Length > 0 ? portParts[0] : ""; + item.Two = portParts.Length > 1 ? portParts[1] : ""; + item.Three = portParts.Length > 2 ? portParts[2] : ""; + } + else + { + item.YeWuMingCheng = ""; + item.One = ""; + item.Two = ""; + item.Three = ""; + } + } + catch + { + // 解析失败,设为空 + item.YeWuMingCheng = ""; + item.One = ""; + item.Two = ""; + item.Three = ""; + } + } + /// /// 查询导出表达式 ///