| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ProductionLineMonitor.Tools
- {
- /// <summary>
- /// Y6产线配置生成工具
- /// 用途:基于Y5的配置,自动生成Y6的产线和设备配置SQL脚本
- /// 使用方法:
- /// 1. 在Web项目中添加此类
- /// 2. 创建一个临时Controller或者在现有Controller中添加方法调用
- /// 3. 运行后会生成完整的SQL脚本
- /// </summary>
- public class Y6ConfigurationGenerator
- {
- /// <summary>
- /// 生成Y6配置的SQL脚本
- /// </summary>
- /// <param name="y5FrontLineId">Y5 Front产线ID</param>
- /// <param name="y5ChamberLineId">Y5 Chamber产线ID</param>
- /// <param name="y5BackLineId">Y5 Back产线ID</param>
- /// <returns>完整的SQL脚本</returns>
- 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();
- }
- /// <summary>
- /// 生成设备配置模板
- /// </summary>
- 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();
- }
- }
- /// <summary>
- /// 生成JavaScript配置代码
- /// </summary>
- 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();
- }
- /// <summary>
- /// 从数据库读取Y5配置并生成Y6配置
- /// 使用示例(在Controller中):
- /// </summary>
- /// <example>
- /// <code>
- /// [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);
- /// }
- /// </code>
- /// </example>
- }
- /// <summary>
- /// Y6配置数据传输对象
- /// </summary>
- public class Y6ConfigDto
- {
- public string Y6FrontLineId { get; set; }
- public string Y6ChamberLineId { get; set; }
- public string Y6BackLineId { get; set; }
- public List<Y6MachineDto> Y6FrontMachines { get; set; } = new List<Y6MachineDto>();
- public List<Y6MachineDto> Y6ChamberMachines { get; set; } = new List<Y6MachineDto>();
- public List<Y6MachineDto> Y6BackMachines { get; set; } = new List<Y6MachineDto>();
- }
- 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; }
- }
- }
|