production-line.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. $("#date").datepicker({
  2. format: 'yyyy-mm-dd',
  3. language: "zh-CN",
  4. autoclose: true,
  5. todayBtn: "linked"
  6. }).on('changeDate', function () {
  7. zTreeOnClick();
  8. }).on('keydown', function (e) {
  9. return false;
  10. });
  11. var zTreeObj;
  12. var setting = {
  13. callback: {
  14. onClick: zTreeOnClick
  15. },
  16. view: {
  17. showIcon: false
  18. }
  19. };
  20. $.ajax({
  21. url: "/ProductionLine/GetProductionLineMachineTree",
  22. type: "GET",
  23. async: true,
  24. success: function (zNodes) {
  25. zTreeObj = $.fn.zTree.init($("#productionLineTree"), setting, zNodes);
  26. //zTreeObj.expandAll(false);
  27. var treeNode = zTreeObj.getNodes()[0];
  28. zTreeObj.selectNode(treeNode);
  29. zTreeOnClick();
  30. }
  31. });
  32. function shortcut(key) {
  33. if (key === -2) {
  34. var date = new Date();
  35. var d = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + (date.getDate() - 2);
  36. $("#date").val(d).datepicker('setDate', d);
  37. }
  38. if (key === -1) {
  39. var date = new Date();
  40. var d = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + (date.getDate() - 1);
  41. $("#date").val(d).datepicker('setDate', d);
  42. }
  43. if (key === 0) {
  44. var date = new Date();
  45. var d = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
  46. $("#date").val(d).datepicker('setDate', d);
  47. }
  48. }
  49. function zTreeOnClick() {
  50. var date = $("#date").val();
  51. var treeNode = zTreeObj.getSelectedNodes()[0];
  52. if (treeNode.level === 0) {
  53. $.ajax({
  54. url: "/ProductionLine/GetProductionLineDayData",
  55. type: "POST",
  56. contentType: "application/json",
  57. async: true,
  58. dataType: "json",
  59. data: JSON.stringify({
  60. "id": treeNode.id,
  61. "dateTime": date
  62. }),
  63. success: function (result) {
  64. statisticsLine(result.statistics);
  65. machines(result.machines);
  66. }
  67. });
  68. $.ajax({
  69. url: "/Fault/GetLineDayTop10Faults",
  70. type: "GET",
  71. contentType: "application/json",
  72. async: true,
  73. dataType: "json",
  74. data: {
  75. "lineId": treeNode.id,
  76. "day": date,
  77. "keywords": "安全门,门禁,提示上料,提示卸料"
  78. },
  79. success: function (result) {
  80. alarms(result);
  81. }
  82. });
  83. $("#line").attr("class", "tab-pane active")
  84. $("#machine").attr("class", "tab-pane")
  85. }
  86. if (treeNode.level === 1) {
  87. $.ajax({
  88. url: "/ProductionLine/GetMachineDayData",
  89. type: "POST",
  90. contentType: "application/json",
  91. async: true,
  92. dataType: "json",
  93. data: JSON.stringify({
  94. "id": treeNode.id,
  95. "dateTime": date
  96. }),
  97. success: function (result) {
  98. statistics(result.statistics);
  99. outPut(result.outPutPerHours);
  100. alarmsMachine(result.top5FaultRecords);
  101. }
  102. });
  103. $.ajax({
  104. url: "/Fault/GetMachineDayTop10Faults",
  105. type: "GET",
  106. contentType: "application/json",
  107. async: true,
  108. dataType: "json",
  109. data: {
  110. "machineId": treeNode.id,
  111. "day": date,
  112. "keywords": "安全门,门禁,提示上料,提示卸料"
  113. },
  114. success: function (result) {
  115. alarmsMachine(result);
  116. }
  117. });
  118. $("#line").attr("class", "tab-pane")
  119. $("#machine").attr("class", "tab-pane active")
  120. }
  121. }
  122. function statisticsLine(data) {
  123. if (data === null || data.length === 0) {
  124. $("#table_line_oee tbody").html("");
  125. var tr =
  126. "<tr>" +
  127. "<td align='center' colspan='6' >没有找到匹配的记录</td>" +
  128. "</tr>";
  129. $("#table_line_oee").append(tr);
  130. } else {
  131. $("#table_line_oee tbody").html("");
  132. for (var i = 0; i < data.length; i++) {
  133. var tr =
  134. "<tr>" +
  135. "<td>" + (i + 1) + "</td>" +
  136. "<td>" + data[i].moduleType + "</td>" +
  137. "<td>" + data[i].capacity + "</td>" +
  138. "<td>" + (data[i].availability === null ? "-" : (data[i].availability * 100).toFixed(1)) + "</td>" +
  139. "<td>" + (data[i].performance === null ? "-" : (data[i].performance * 100).toFixed(1)) + "</td>" +
  140. "<td>" + (data[i].oee === null ? "-" : (data[i].oee * 100).toFixed(1)) + "</td>" +
  141. "</tr>";
  142. $("#table_line_oee").append(tr);
  143. }
  144. }
  145. }
  146. function statistics(data) {
  147. if (data === null || data.length === 0) {
  148. $("#machine_oee tbody").html("");
  149. var tr =
  150. "<tr>" +
  151. "<td align='center' colspan='6' >没有找到匹配的记录</td>" +
  152. "</tr>";
  153. $("#machine_oee").append(tr);
  154. } else {
  155. $("#machine_oee tbody").html("");
  156. for (var i = 0; i < data.length; i++) {
  157. var tr =
  158. "<tr>" +
  159. "<td>" + (i + 1) + "</td>" +
  160. "<td>" + data[i].moduleType + "</td>" +
  161. "<td>" + data[i].capacity + "</td>" +
  162. "<td>" + (data[i].availability === null ? "-" : (data[i].availability * 100).toFixed(1)) + "</td>" +
  163. "<td>" + (data[i].performance === null ? "-" : (data[i].performance * 100).toFixed(1)) + "</td>" +
  164. "<td>" + (data[i].oee === null ? "-" : (data[i].oee * 100).toFixed(1)) + "</td>" +
  165. "</tr>";
  166. $("#machine_oee").append(tr);
  167. }
  168. }
  169. }
  170. function outPut(data) {
  171. if (data === null || data.length === 0) {
  172. $("#table3 tbody").html("");
  173. for (var i = 0; i < 1; i++) {
  174. var tr =
  175. "<tr>" +
  176. "<td align='center' colspan='10' >没有找到匹配的记录</td>" +
  177. "</tr>";
  178. $("#table3").append(tr);
  179. }
  180. $("#table4 tbody").html("");
  181. for (var i = 0; i < 1; i++) {
  182. var tr =
  183. "<tr>" +
  184. "<td align='center' colspan='10' >没有找到匹配的记录</td>" +
  185. "</tr>";
  186. $("#table4").append(tr);
  187. }
  188. } else {
  189. $("#table3 tbody").html("");
  190. var autoRunTime = 0;
  191. var alarmTime = 0;
  192. var idleTime = 0;
  193. var outPut = 0;
  194. var alarmSum = 0;
  195. var loadMATSum = 0;
  196. var loadMATTime = 0;
  197. var actualTT = 0;
  198. for (var i = 0; i < data.length / 2; i++) {
  199. var tr =
  200. "<tr>" +
  201. "<td>" + data[i].period + "</td>" +
  202. "<td>" + data[i].moduleType + "</td>" +
  203. "<td>" + data[i].autoRunTime + "</td>" +
  204. "<td>" + data[i].alarmTime + "</td>" +
  205. "<td>" + data[i].idleTime + "</td>" +
  206. "<td>" + data[i].outPut + "</td>" +
  207. "<td>" + data[i].actualTT + "</td>" +
  208. "<td>" + data[i].alarmSum + "</td>" +
  209. "<td>" + data[i].loadMATSum + "</td>" +
  210. "<td>" + data[i].loadMATTime + "</td>" +
  211. "</tr>";
  212. $("#table3").append(tr);
  213. autoRunTime += data[i].autoRunTime;
  214. alarmTime += data[i].alarmTime;
  215. idleTime += data[i].idleTime;
  216. outPut += data[i].outPut;
  217. alarmSum += data[i].alarmSum;
  218. loadMATSum += data[i].loadMATSum;
  219. loadMATTime += data[i].loadMATTime;
  220. actualTT += data[i].actualTT;
  221. }
  222. var tr =
  223. "<tr class='total'>" +
  224. "<td colspan='2'>合计</td>" +
  225. "<td>" + autoRunTime + "</td>" +
  226. "<td>" + alarmTime + "</td>" +
  227. "<td>" + idleTime + "</td>" +
  228. "<td>" + outPut + "</td>" +
  229. "<td>" + (actualTT / 12).toFixed(2) + "</td>" +
  230. "<td>" + alarmSum + "</td>" +
  231. "<td>" + loadMATSum + "</td>" +
  232. "<td>" + loadMATTime + "</td>" +
  233. "</tr>";
  234. $("#table3").append(tr);
  235. autoRunTime = 0;
  236. alarmTime = 0;
  237. idleTime = 0;
  238. outPut = 0;
  239. alarmSum = 0;
  240. loadMATSum = 0;
  241. loadMATTime = 0;
  242. actualTT = 0;
  243. $("#table4 tbody").html("");
  244. for (var i = 12; i < data.length; i++) {
  245. var tr =
  246. "<tr>" +
  247. "<td>" + data[i].period + "</td>" +
  248. "<td>" + data[i].moduleType + "</td>" +
  249. "<td>" + data[i].autoRunTime + "</td>" +
  250. "<td>" + data[i].alarmTime + "</td>" +
  251. "<td>" + data[i].idleTime + "</td>" +
  252. "<td>" + data[i].outPut + "</td>" +
  253. "<td>" + data[i].actualTT + "</td>" +
  254. "<td>" + data[i].alarmSum + "</td>" +
  255. "<td>" + data[i].loadMATSum + "</td>" +
  256. "<td>" + data[i].loadMATTime + "</td>" +
  257. "</tr>";
  258. $("#table4").append(tr);
  259. autoRunTime += data[i].autoRunTime;
  260. alarmTime += data[i].alarmTime;
  261. idleTime += data[i].idleTime;
  262. outPut += data[i].outPut;
  263. alarmSum += data[i].alarmSum;
  264. loadMATSum += data[i].loadMATSum;
  265. loadMATTime += data[i].loadMATTime;
  266. actualTT += data[i].actualTT;
  267. }
  268. var tr =
  269. "<tr class='total'>" +
  270. "<td colspan='2'>合计</td>" +
  271. "<td>" + autoRunTime + "</td>" +
  272. "<td>" + alarmTime + "</td>" +
  273. "<td>" + idleTime + "</td>" +
  274. "<td>" + outPut + "</td>" +
  275. "<td>" + (actualTT / 12).toFixed(2) + "</td>" +
  276. "<td>" + alarmSum + "</td>" +
  277. "<td>" + loadMATSum + "</td>" +
  278. "<td>" + loadMATTime + "</td>" +
  279. "</tr>";
  280. $("#table4").append(tr);
  281. }
  282. }
  283. function machines(data) {
  284. if (data === null || data.length === 0) {
  285. $("#table1 tbody").html("");
  286. for (var i = 0; i < 1; i++) {
  287. var tr =
  288. "<tr>" +
  289. "<td align='center' colspan='8' >没有找到匹配的记录</td>" +
  290. "</tr>";
  291. $("#table1").append(tr);
  292. }
  293. } else {
  294. $("#table1 tbody").html("");
  295. for (var i = 0; i < data.length; i++) {
  296. var td1 = "<td></td>";
  297. var td2 = "<td></td>";
  298. var td3 = "<td></td>";
  299. var td4 = "<td></td>";
  300. var td5 = "<td></td>";
  301. if (data[i].statistics !== null && data[i].statistics.length > 0) {
  302. td1 = "<td><ul style='list-style-type:none;padding-left:0px'>";
  303. td2 = "<td><ul style='list-style-type:none;padding-left:0px'>";
  304. td3 = "<td><ul style='list-style-type:none;padding-left:0px'>";
  305. td4 = "<td><ul style='list-style-type:none;padding-left:0px'>";
  306. td5 = "<td><ul style='list-style-type:none;padding-left:0px'>";
  307. for (var j = 0; j < data[i].statistics.length; j++) {
  308. td1 += "<li>" + data[i].statistics[j].moduleType + "</li>";
  309. td2 += "<li>" + data[i].statistics[j].capacity + "</li>";
  310. td3 += "<li>" + (data[i].statistics[j].availability * 100).toFixed(1) + "</li>";
  311. td4 += "<li>" + (data[i].statistics[j].performance * 100).toFixed(1) + "</li>";
  312. td5 += "<li>" + (data[i].statistics[j].oee * 100).toFixed(1) + "</li>";
  313. }
  314. td1 += "</ul></td>";
  315. td2 += "</ul></td>";
  316. td3 += "</ul></td>";
  317. td4 += "</ul></td>";
  318. td5 += "</ul></td>";
  319. }
  320. var tr =
  321. "<tr>" +
  322. "<td>" + (i + 1) + "</td>" +
  323. "<td>" + data[i].name + "</td>" +
  324. "<td>" + data[i].type + "</td>" +
  325. td1 + td2 + td3 + td4 + td5 +
  326. "</tr>";
  327. $("#table1").append(tr);
  328. }
  329. }
  330. }
  331. function alarms(data) {
  332. if (data === null || data.length === 0) {
  333. $("#table2 tbody").html("");
  334. for (var i = 0; i < 1; i++) {
  335. var tr =
  336. "<tr>" +
  337. "<td align='center' colspan='8' >没有找到匹配的记录</td>" +
  338. "</tr>";
  339. $("#table2").append(tr);
  340. }
  341. } else {
  342. $("#table2 tbody").html("");
  343. for (var i = 0; i < data.length; i++) {
  344. var tr =
  345. "<tr>" +
  346. "<td>" + (i + 1) + "</td>" +
  347. "<td>" + data[i].machineName + "</td>" +
  348. "<td>" + formatDate(data[i].startTime) + "</td>" +
  349. "<td>" + formatDate(data[i].endTime) + "</td>" +
  350. "<td>" + (data[i].machineState === 2 ? "自动" : "手动") + "</td>" +
  351. "<td>" + (data[i].duration).toFixed(3) + "</td>" +
  352. "<td>" + data[i].faultCode + "</td>" +
  353. "<td>" + data[i].faultInfo + "</td>" +
  354. "</tr>";
  355. $("#table2").append(tr);
  356. }
  357. }
  358. }
  359. function alarmsMachine(data) {
  360. if (data === null || data.length === 0) {
  361. $("#machine_alarm tbody").html("");
  362. for (var i = 0; i < 1; i++) {
  363. var tr =
  364. "<tr>" +
  365. "<td align='center' colspan='7' >没有找到匹配的记录</td>" +
  366. "</tr>";
  367. $("#machine_alarm").append(tr);
  368. }
  369. } else {
  370. $("#machine_alarm tbody").html("");
  371. for (var i = 0; i < data.length; i++) {
  372. var tr =
  373. "<tr>" +
  374. "<td>" + (i + 1) + "</td>" +
  375. "<td>" + formatDate(data[i].startTime) + "</td>" +
  376. "<td>" + formatDate(data[i].endTime) + "</td>" +
  377. "<td>" + (data[i].machineState === 2 ? "自动" : "手动") + "</td>" +
  378. "<td>" + (data[i].duration).toFixed(3) + "</td>" +
  379. "<td>" + data[i].faultCode + "</td>" +
  380. "<td>" + data[i].faultInfo + "</td>" +
  381. "</tr>";
  382. $("#machine_alarm").append(tr);
  383. }
  384. }
  385. }