Y6ConfigurationGenerator.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace ProductionLineMonitor.Tools
  6. {
  7. /// <summary>
  8. /// Y6产线配置生成工具
  9. /// 用途:基于Y5的配置,自动生成Y6的产线和设备配置SQL脚本
  10. /// 使用方法:
  11. /// 1. 在Web项目中添加此类
  12. /// 2. 创建一个临时Controller或者在现有Controller中添加方法调用
  13. /// 3. 运行后会生成完整的SQL脚本
  14. /// </summary>
  15. public class Y6ConfigurationGenerator
  16. {
  17. /// <summary>
  18. /// 生成Y6配置的SQL脚本
  19. /// </summary>
  20. /// <param name="y5FrontLineId">Y5 Front产线ID</param>
  21. /// <param name="y5ChamberLineId">Y5 Chamber产线ID</param>
  22. /// <param name="y5BackLineId">Y5 Back产线ID</param>
  23. /// <returns>完整的SQL脚本</returns>
  24. public static string GenerateY6ConfigurationSQL(
  25. string y5FrontLineId = "5FCDF694-6947-4C1F-B340-B70887F71DE0",
  26. string y5ChamberLineId = "1008BD16-CC70-4B07-BF61-6325EE9C9FC3",
  27. string y5BackLineId = "A9605A87-4124-4543-9AEE-6CF6FEC58322")
  28. {
  29. var sb = new StringBuilder();
  30. sb.AppendLine("-- ====================================================");
  31. sb.AppendLine("-- Y6产线和设备配置脚本(自动生成)");
  32. sb.AppendLine($"-- 生成时间: {DateTime.Now:yyyy-MM-dd HH:mm:ss}");
  33. sb.AppendLine("-- ====================================================");
  34. sb.AppendLine();
  35. // 生成新的GUID
  36. var y6FrontLineGuid = Guid.NewGuid().ToString().ToUpper();
  37. var y6ChamberLineGuid = Guid.NewGuid().ToString().ToUpper();
  38. var y6BackLineGuid = Guid.NewGuid().ToString().ToUpper();
  39. sb.AppendLine("-- ============== 步骤1: 创建Y6产线 ==============");
  40. sb.AppendLine();
  41. // Y6 Front 产线
  42. sb.AppendLine("-- Y6 Front 产线");
  43. sb.AppendLine("INSERT INTO ProductionLines (Id, Name, Floor, Line, LineName, [Order], HourDataTopic, MakeClassification, FactoryNo, RepresentativeDeviceId, CreateTime, UpdateTime)");
  44. sb.AppendLine($"VALUES ('{y6FrontLineGuid}', 'Y6 Front', 5, 6, 'Y6前段', 10, 'Y6/Front/HourData', 'EPD', 'T1', '', datetime('now'), datetime('now'));");
  45. sb.AppendLine();
  46. // Y6 Chamber 产线
  47. sb.AppendLine("-- Y6 Chamber 产线");
  48. sb.AppendLine("INSERT INTO ProductionLines (Id, Name, Floor, Line, LineName, [Order], HourDataTopic, MakeClassification, FactoryNo, RepresentativeDeviceId, CreateTime, UpdateTime)");
  49. sb.AppendLine($"VALUES ('{y6ChamberLineGuid}', 'Y6 Chamber', 5, 6, 'Y6腔室', 11, 'Y6/Chamber/HourData', 'EPD', 'T1', '', datetime('now'), datetime('now'));");
  50. sb.AppendLine();
  51. // Y6 Back 产线
  52. sb.AppendLine("-- Y6 Back 产线");
  53. sb.AppendLine("INSERT INTO ProductionLines (Id, Name, Floor, Line, LineName, [Order], HourDataTopic, MakeClassification, FactoryNo, RepresentativeDeviceId, CreateTime, UpdateTime)");
  54. sb.AppendLine($"VALUES ('{y6BackLineGuid}', 'Y6 Back', 5, 6, 'Y6后段', 12, 'Y6/Back/HourData', 'EPD', 'T1', '', datetime('now'), datetime('now'));");
  55. sb.AppendLine();
  56. sb.AppendLine("-- ============== 步骤2: 查询Y5设备配置 ==============");
  57. sb.AppendLine("-- 请根据以下查询结果,手动创建Y6设备");
  58. sb.AppendLine("-- 或使用下面的模板SQL,根据实际设备数量和配置进行调整");
  59. sb.AppendLine();
  60. sb.AppendLine($"-- SELECT * FROM Machines WHERE ProductionLineId = '{y5FrontLineId}'; -- Y5 Front设备");
  61. sb.AppendLine($"-- SELECT * FROM Machines WHERE ProductionLineId = '{y5ChamberLineId}'; -- Y5 Chamber设备");
  62. sb.AppendLine($"-- SELECT * FROM Machines WHERE ProductionLineId = '{y5BackLineId}'; -- Y5 Back设备");
  63. sb.AppendLine();
  64. sb.AppendLine("-- ============== 步骤3: JavaScript配置更新 ==============");
  65. sb.AppendLine("-- 请将以下GUID更新到 eyz-manufacturing-platform.js 文件中");
  66. sb.AppendLine();
  67. sb.AppendLine("/*");
  68. sb.AppendLine("在 eyz-manufacturing-platform.js 的 init() 方法中,将占位符替换为以下GUID:");
  69. sb.AppendLine();
  70. sb.AppendLine("else if (machine == \"Y6Front\") {");
  71. sb.AppendLine($" this.productline = \"{y6FrontLineGuid}\";");
  72. sb.AppendLine("}");
  73. sb.AppendLine("else if (machine == \"Y6Chamber\") {");
  74. sb.AppendLine($" this.productline = \"{y6ChamberLineGuid}\";");
  75. sb.AppendLine("}");
  76. sb.AppendLine("else if (machine == \"Y6Back\") {");
  77. sb.AppendLine($" this.productline = \"{y6BackLineGuid}\";");
  78. sb.AppendLine("}");
  79. sb.AppendLine("*/");
  80. sb.AppendLine();
  81. sb.AppendLine("-- ============== 步骤4: 访问URL ==============");
  82. sb.AppendLine("-- 配置完成后,可以通过以下URL访问Y6 OEE页面:");
  83. sb.AppendLine($"-- http://eapauto01.toc.eink.com/EYZManufacturingPlatform/Y5OEE?machine=Y6Front");
  84. sb.AppendLine($"-- http://eapauto01.toc.eink.com/EYZManufacturingPlatform/Y5OEE?machine=Y6Chamber");
  85. sb.AppendLine($"-- http://eapauto01.toc.eink.com/EYZManufacturingPlatform/Y5OEE?machine=Y6Back");
  86. sb.AppendLine();
  87. sb.AppendLine("-- ============== 步骤5: 设备配置模板 ==============");
  88. sb.AppendLine("-- 以下是设备创建模板,请根据实际需要调整");
  89. sb.AppendLine();
  90. // 生成设备配置模板
  91. GenerateMachineTemplate(sb, "Y6 Front", y6FrontLineGuid, "Y6Front", 3);
  92. GenerateMachineTemplate(sb, "Y6 Chamber", y6ChamberLineGuid, "Y6Chamber", 5);
  93. GenerateMachineTemplate(sb, "Y6 Back", y6BackLineGuid, "Y6Back", 3);
  94. return sb.ToString();
  95. }
  96. /// <summary>
  97. /// 生成设备配置模板
  98. /// </summary>
  99. private static void GenerateMachineTemplate(StringBuilder sb, string lineName, string lineId, string prefix, int count)
  100. {
  101. sb.AppendLine($"-- {lineName} 设备配置");
  102. for (int i = 1; i <= count; i++)
  103. {
  104. var machineGuid = Guid.NewGuid().ToString().ToUpper();
  105. var machineNum = i.ToString("00");
  106. sb.AppendLine($"INSERT INTO Machines (Id, ProductionLineId, ProductionLineOrder, IsInclusionLineStatistics, Name, Type, Topic, FaultTopic, OEEExtendSettings, IsShow, CreateTime, UpdateTime)");
  107. sb.AppendLine($"VALUES (");
  108. sb.AppendLine($" '{machineGuid}', -- 设备ID");
  109. sb.AppendLine($" '{lineId}', -- 产线ID");
  110. sb.AppendLine($" {i}, -- 产线顺序");
  111. sb.AppendLine($" 1, -- 是否计入线统计");
  112. sb.AppendLine($" '{prefix}{machineNum}', -- 设备名称");
  113. sb.AppendLine($" '{prefix.Replace("Y6", "")}', -- 设备类型");
  114. sb.AppendLine($" 'Y6/{prefix.Replace("Y6", "")}/{prefix}{machineNum}', -- Topic");
  115. sb.AppendLine($" 'Y6/{prefix.Replace("Y6", "")}/{prefix}{machineNum}/Fault', -- 故障Topic");
  116. sb.AppendLine($" '', -- OEE配置项(可根据需要配置)");
  117. sb.AppendLine($" 1, -- 是否展示");
  118. sb.AppendLine($" datetime('now'), -- 创建时间");
  119. sb.AppendLine($" datetime('now') -- 更新时间");
  120. sb.AppendLine($");");
  121. sb.AppendLine();
  122. }
  123. }
  124. /// <summary>
  125. /// 生成JavaScript配置代码
  126. /// </summary>
  127. public static string GenerateJavaScriptConfig(string y6FrontGuid, string y6ChamberGuid, string y6BackGuid)
  128. {
  129. var sb = new StringBuilder();
  130. sb.AppendLine("// Y6产线配置");
  131. sb.AppendLine("else if (machine == \"Y6Front\") {");
  132. sb.AppendLine($" this.productline = \"{y6FrontGuid}\";");
  133. sb.AppendLine("}");
  134. sb.AppendLine("else if (machine == \"Y6Chamber\") {");
  135. sb.AppendLine($" this.productline = \"{y6ChamberGuid}\";");
  136. sb.AppendLine("}");
  137. sb.AppendLine("else if (machine == \"Y6Back\") {");
  138. sb.AppendLine($" this.productline = \"{y6BackGuid}\";");
  139. sb.AppendLine("}");
  140. return sb.ToString();
  141. }
  142. /// <summary>
  143. /// 从数据库读取Y5配置并生成Y6配置
  144. /// 使用示例(在Controller中):
  145. /// </summary>
  146. /// <example>
  147. /// <code>
  148. /// [HttpGet]
  149. /// public IActionResult GenerateY6Config()
  150. /// {
  151. /// // 查询Y5产线配置
  152. /// var y5Lines = _unitOfWork.Repository&lt;ProductionLine&gt;()
  153. /// .GetList(x => x.Name.Contains("Y5"))
  154. /// .ToList();
  155. ///
  156. /// // 查询Y5设备配置
  157. /// var y5Machines = _unitOfWork.Repository&lt;Machine&gt;()
  158. /// .GetList(x => y5Lines.Select(l => l.Id).Contains(x.ProductionLineId))
  159. /// .ToList();
  160. ///
  161. /// // 生成SQL脚本
  162. /// var sql = Y6ConfigurationGenerator.GenerateY6ConfigurationSQL();
  163. ///
  164. /// // 返回文本文件
  165. /// return Content(sql, "text/plain", Encoding.UTF8);
  166. /// }
  167. /// </code>
  168. /// </example>
  169. }
  170. /// <summary>
  171. /// Y6配置数据传输对象
  172. /// </summary>
  173. public class Y6ConfigDto
  174. {
  175. public string Y6FrontLineId { get; set; }
  176. public string Y6ChamberLineId { get; set; }
  177. public string Y6BackLineId { get; set; }
  178. public List<Y6MachineDto> Y6FrontMachines { get; set; } = new List<Y6MachineDto>();
  179. public List<Y6MachineDto> Y6ChamberMachines { get; set; } = new List<Y6MachineDto>();
  180. public List<Y6MachineDto> Y6BackMachines { get; set; } = new List<Y6MachineDto>();
  181. }
  182. public class Y6MachineDto
  183. {
  184. public string Id { get; set; }
  185. public string Name { get; set; }
  186. public string Topic { get; set; }
  187. public string FaultTopic { get; set; }
  188. public int Order { get; set; }
  189. }
  190. }