using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ProductionLineMonitor.Tools { /// /// Y6产线配置生成工具 /// 用途:基于Y5的配置,自动生成Y6的产线和设备配置SQL脚本 /// 使用方法: /// 1. 在Web项目中添加此类 /// 2. 创建一个临时Controller或者在现有Controller中添加方法调用 /// 3. 运行后会生成完整的SQL脚本 /// public class Y6ConfigurationGenerator { /// /// 生成Y6配置的SQL脚本 /// /// Y5 Front产线ID /// Y5 Chamber产线ID /// Y5 Back产线ID /// 完整的SQL脚本 public static string GenerateY6ConfigurationSQL( string y5FrontLineId = "5FCDF694-6947-4C1F-B340-B70887F71DE0", string y5ChamberLineId = "1008BD16-CC70-4B07-BF61-6325EE9C9FC3", string y5BackLineId = "A9605A87-4124-4543-9AEE-6CF6FEC58322") { var sb = new StringBuilder(); sb.AppendLine("-- ===================================================="); sb.AppendLine("-- Y6产线和设备配置脚本(自动生成)"); sb.AppendLine($"-- 生成时间: {DateTime.Now:yyyy-MM-dd HH:mm:ss}"); sb.AppendLine("-- ===================================================="); sb.AppendLine(); // 生成新的GUID var y6FrontLineGuid = Guid.NewGuid().ToString().ToUpper(); var y6ChamberLineGuid = Guid.NewGuid().ToString().ToUpper(); var y6BackLineGuid = Guid.NewGuid().ToString().ToUpper(); sb.AppendLine("-- ============== 步骤1: 创建Y6产线 =============="); sb.AppendLine(); // Y6 Front 产线 sb.AppendLine("-- Y6 Front 产线"); sb.AppendLine("INSERT INTO ProductionLines (Id, Name, Floor, Line, LineName, [Order], HourDataTopic, MakeClassification, FactoryNo, RepresentativeDeviceId, CreateTime, UpdateTime)"); sb.AppendLine($"VALUES ('{y6FrontLineGuid}', 'Y6 Front', 5, 6, 'Y6前段', 10, 'Y6/Front/HourData', 'EPD', 'T1', '', datetime('now'), datetime('now'));"); sb.AppendLine(); // Y6 Chamber 产线 sb.AppendLine("-- Y6 Chamber 产线"); sb.AppendLine("INSERT INTO ProductionLines (Id, Name, Floor, Line, LineName, [Order], HourDataTopic, MakeClassification, FactoryNo, RepresentativeDeviceId, CreateTime, UpdateTime)"); sb.AppendLine($"VALUES ('{y6ChamberLineGuid}', 'Y6 Chamber', 5, 6, 'Y6腔室', 11, 'Y6/Chamber/HourData', 'EPD', 'T1', '', datetime('now'), datetime('now'));"); sb.AppendLine(); // Y6 Back 产线 sb.AppendLine("-- Y6 Back 产线"); sb.AppendLine("INSERT INTO ProductionLines (Id, Name, Floor, Line, LineName, [Order], HourDataTopic, MakeClassification, FactoryNo, RepresentativeDeviceId, CreateTime, UpdateTime)"); sb.AppendLine($"VALUES ('{y6BackLineGuid}', 'Y6 Back', 5, 6, 'Y6后段', 12, 'Y6/Back/HourData', 'EPD', 'T1', '', datetime('now'), datetime('now'));"); sb.AppendLine(); sb.AppendLine("-- ============== 步骤2: 查询Y5设备配置 =============="); sb.AppendLine("-- 请根据以下查询结果,手动创建Y6设备"); sb.AppendLine("-- 或使用下面的模板SQL,根据实际设备数量和配置进行调整"); sb.AppendLine(); sb.AppendLine($"-- SELECT * FROM Machines WHERE ProductionLineId = '{y5FrontLineId}'; -- Y5 Front设备"); sb.AppendLine($"-- SELECT * FROM Machines WHERE ProductionLineId = '{y5ChamberLineId}'; -- Y5 Chamber设备"); sb.AppendLine($"-- SELECT * FROM Machines WHERE ProductionLineId = '{y5BackLineId}'; -- Y5 Back设备"); sb.AppendLine(); sb.AppendLine("-- ============== 步骤3: JavaScript配置更新 =============="); sb.AppendLine("-- 请将以下GUID更新到 eyz-manufacturing-platform.js 文件中"); sb.AppendLine(); sb.AppendLine("/*"); sb.AppendLine("在 eyz-manufacturing-platform.js 的 init() 方法中,将占位符替换为以下GUID:"); sb.AppendLine(); sb.AppendLine("else if (machine == \"Y6Front\") {"); sb.AppendLine($" this.productline = \"{y6FrontLineGuid}\";"); sb.AppendLine("}"); sb.AppendLine("else if (machine == \"Y6Chamber\") {"); sb.AppendLine($" this.productline = \"{y6ChamberLineGuid}\";"); sb.AppendLine("}"); sb.AppendLine("else if (machine == \"Y6Back\") {"); sb.AppendLine($" this.productline = \"{y6BackLineGuid}\";"); sb.AppendLine("}"); sb.AppendLine("*/"); sb.AppendLine(); sb.AppendLine("-- ============== 步骤4: 访问URL =============="); sb.AppendLine("-- 配置完成后,可以通过以下URL访问Y6 OEE页面:"); sb.AppendLine($"-- http://eapauto01.toc.eink.com/EYZManufacturingPlatform/Y5OEE?machine=Y6Front"); sb.AppendLine($"-- http://eapauto01.toc.eink.com/EYZManufacturingPlatform/Y5OEE?machine=Y6Chamber"); sb.AppendLine($"-- http://eapauto01.toc.eink.com/EYZManufacturingPlatform/Y5OEE?machine=Y6Back"); sb.AppendLine(); sb.AppendLine("-- ============== 步骤5: 设备配置模板 =============="); sb.AppendLine("-- 以下是设备创建模板,请根据实际需要调整"); sb.AppendLine(); // 生成设备配置模板 GenerateMachineTemplate(sb, "Y6 Front", y6FrontLineGuid, "Y6Front", 3); GenerateMachineTemplate(sb, "Y6 Chamber", y6ChamberLineGuid, "Y6Chamber", 5); GenerateMachineTemplate(sb, "Y6 Back", y6BackLineGuid, "Y6Back", 3); return sb.ToString(); } /// /// 生成设备配置模板 /// private static void GenerateMachineTemplate(StringBuilder sb, string lineName, string lineId, string prefix, int count) { sb.AppendLine($"-- {lineName} 设备配置"); for (int i = 1; i <= count; i++) { var machineGuid = Guid.NewGuid().ToString().ToUpper(); var machineNum = i.ToString("00"); sb.AppendLine($"INSERT INTO Machines (Id, ProductionLineId, ProductionLineOrder, IsInclusionLineStatistics, Name, Type, Topic, FaultTopic, OEEExtendSettings, IsShow, CreateTime, UpdateTime)"); sb.AppendLine($"VALUES ("); sb.AppendLine($" '{machineGuid}', -- 设备ID"); sb.AppendLine($" '{lineId}', -- 产线ID"); sb.AppendLine($" {i}, -- 产线顺序"); sb.AppendLine($" 1, -- 是否计入线统计"); sb.AppendLine($" '{prefix}{machineNum}', -- 设备名称"); sb.AppendLine($" '{prefix.Replace("Y6", "")}', -- 设备类型"); sb.AppendLine($" 'Y6/{prefix.Replace("Y6", "")}/{prefix}{machineNum}', -- Topic"); sb.AppendLine($" 'Y6/{prefix.Replace("Y6", "")}/{prefix}{machineNum}/Fault', -- 故障Topic"); sb.AppendLine($" '', -- OEE配置项(可根据需要配置)"); sb.AppendLine($" 1, -- 是否展示"); sb.AppendLine($" datetime('now'), -- 创建时间"); sb.AppendLine($" datetime('now') -- 更新时间"); sb.AppendLine($");"); sb.AppendLine(); } } /// /// 生成JavaScript配置代码 /// public static string GenerateJavaScriptConfig(string y6FrontGuid, string y6ChamberGuid, string y6BackGuid) { var sb = new StringBuilder(); sb.AppendLine("// Y6产线配置"); sb.AppendLine("else if (machine == \"Y6Front\") {"); sb.AppendLine($" this.productline = \"{y6FrontGuid}\";"); sb.AppendLine("}"); sb.AppendLine("else if (machine == \"Y6Chamber\") {"); sb.AppendLine($" this.productline = \"{y6ChamberGuid}\";"); sb.AppendLine("}"); sb.AppendLine("else if (machine == \"Y6Back\") {"); sb.AppendLine($" this.productline = \"{y6BackGuid}\";"); sb.AppendLine("}"); return sb.ToString(); } /// /// 从数据库读取Y5配置并生成Y6配置 /// 使用示例(在Controller中): /// /// /// /// [HttpGet] /// public IActionResult GenerateY6Config() /// { /// // 查询Y5产线配置 /// var y5Lines = _unitOfWork.Repository<ProductionLine>() /// .GetList(x => x.Name.Contains("Y5")) /// .ToList(); /// /// // 查询Y5设备配置 /// var y5Machines = _unitOfWork.Repository<Machine>() /// .GetList(x => y5Lines.Select(l => l.Id).Contains(x.ProductionLineId)) /// .ToList(); /// /// // 生成SQL脚本 /// var sql = Y6ConfigurationGenerator.GenerateY6ConfigurationSQL(); /// /// // 返回文本文件 /// return Content(sql, "text/plain", Encoding.UTF8); /// } /// /// } /// /// Y6配置数据传输对象 /// public class Y6ConfigDto { public string Y6FrontLineId { get; set; } public string Y6ChamberLineId { get; set; } public string Y6BackLineId { get; set; } public List Y6FrontMachines { get; set; } = new List(); public List Y6ChamberMachines { get; set; } = new List(); public List Y6BackMachines { get; set; } = new List(); } public class Y6MachineDto { public string Id { get; set; } public string Name { get; set; } public string Topic { get; set; } public string FaultTopic { get; set; } public int Order { get; set; } } }