$("#date").datepicker({
format: 'yyyy-mm-dd',
language: "zh-CN",
autoclose: true,
todayBtn: "linked"
}).on('changeDate', function () {
zTreeOnClick();
}).on('keydown', function (e) {
return false;
});
var zTreeObj;
var setting = {
callback: {
onClick: zTreeOnClick
},
view: {
showIcon: false
}
};
$.ajax({
url: "/ProductionLine/GetProductionLineMachineTree",
type: "GET",
async: true,
success: function (zNodes) {
zTreeObj = $.fn.zTree.init($("#productionLineTree"), setting, zNodes);
//zTreeObj.expandAll(false);
var treeNode = zTreeObj.getNodes()[0];
zTreeObj.selectNode(treeNode);
zTreeOnClick();
}
});
function shortcut(key) {
if (key === -2) {
var date = new Date();
var d = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + (date.getDate() - 2);
$("#date").val(d).datepicker('setDate', d);
}
if (key === -1) {
var date = new Date();
var d = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + (date.getDate() - 1);
$("#date").val(d).datepicker('setDate', d);
}
if (key === 0) {
var date = new Date();
var d = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
$("#date").val(d).datepicker('setDate', d);
}
}
function zTreeOnClick() {
var date = $("#date").val();
var treeNode = zTreeObj.getSelectedNodes()[0];
if (treeNode.level === 0) {
$.ajax({
url: "/ProductionLine/GetProductionLineDayData",
type: "POST",
contentType: "application/json",
async: true,
dataType: "json",
data: JSON.stringify({
"id": treeNode.id,
"dateTime": date
}),
success: function (result) {
statisticsLine(result.statistics);
machines(result.machines);
}
});
$.ajax({
url: "/Fault/GetLineDayTop10Faults",
type: "GET",
contentType: "application/json",
async: true,
dataType: "json",
data: {
"lineId": treeNode.id,
"day": date,
"keywords": "安全门,门禁,提示上料,提示卸料"
},
success: function (result) {
alarms(result);
}
});
$("#line").attr("class", "tab-pane active")
$("#machine").attr("class", "tab-pane")
}
if (treeNode.level === 1) {
$.ajax({
url: "/ProductionLine/GetMachineDayData",
type: "POST",
contentType: "application/json",
async: true,
dataType: "json",
data: JSON.stringify({
"id": treeNode.id,
"dateTime": date
}),
success: function (result) {
statistics(result.statistics);
outPut(result.outPutPerHours);
alarmsMachine(result.top5FaultRecords);
}
});
$.ajax({
url: "/Fault/GetMachineDayTop10Faults",
type: "GET",
contentType: "application/json",
async: true,
dataType: "json",
data: {
"machineId": treeNode.id,
"day": date,
"keywords": "安全门,门禁,提示上料,提示卸料"
},
success: function (result) {
alarmsMachine(result);
}
});
$("#line").attr("class", "tab-pane")
$("#machine").attr("class", "tab-pane active")
}
}
function statisticsLine(data) {
if (data === null || data.length === 0) {
$("#table_line_oee tbody").html("");
var tr =
"
" +
"没有找到匹配的记录 | " +
"
";
$("#table_line_oee").append(tr);
} else {
$("#table_line_oee tbody").html("");
for (var i = 0; i < data.length; i++) {
var tr =
"" +
"" + (i + 1) + " | " +
"" + data[i].moduleType + " | " +
"" + data[i].capacity + " | " +
"" + (data[i].availability === null ? "-" : (data[i].availability * 100).toFixed(1)) + " | " +
"" + (data[i].performance === null ? "-" : (data[i].performance * 100).toFixed(1)) + " | " +
"" + (data[i].oee === null ? "-" : (data[i].oee * 100).toFixed(1)) + " | " +
"
";
$("#table_line_oee").append(tr);
}
}
}
function statistics(data) {
if (data === null || data.length === 0) {
$("#machine_oee tbody").html("");
var tr =
"" +
"没有找到匹配的记录 | " +
"
";
$("#machine_oee").append(tr);
} else {
$("#machine_oee tbody").html("");
for (var i = 0; i < data.length; i++) {
var tr =
"" +
"" + (i + 1) + " | " +
"" + data[i].moduleType + " | " +
"" + data[i].capacity + " | " +
"" + (data[i].availability === null ? "-" : (data[i].availability * 100).toFixed(1)) + " | " +
"" + (data[i].performance === null ? "-" : (data[i].performance * 100).toFixed(1)) + " | " +
"" + (data[i].oee === null ? "-" : (data[i].oee * 100).toFixed(1)) + " | " +
"
";
$("#machine_oee").append(tr);
}
}
}
function outPut(data) {
if (data === null || data.length === 0) {
$("#table3 tbody").html("");
for (var i = 0; i < 1; i++) {
var tr =
"" +
"没有找到匹配的记录 | " +
"
";
$("#table3").append(tr);
}
$("#table4 tbody").html("");
for (var i = 0; i < 1; i++) {
var tr =
"" +
"没有找到匹配的记录 | " +
"
";
$("#table4").append(tr);
}
} else {
$("#table3 tbody").html("");
var autoRunTime = 0;
var alarmTime = 0;
var idleTime = 0;
var outPut = 0;
var alarmSum = 0;
var loadMATSum = 0;
var loadMATTime = 0;
var actualTT = 0;
for (var i = 0; i < data.length / 2; i++) {
var tr =
"" +
"" + data[i].period + " | " +
"" + data[i].moduleType + " | " +
"" + data[i].autoRunTime + " | " +
"" + data[i].alarmTime + " | " +
"" + data[i].idleTime + " | " +
"" + data[i].outPut + " | " +
"" + data[i].actualTT + " | " +
"" + data[i].alarmSum + " | " +
"" + data[i].loadMATSum + " | " +
"" + data[i].loadMATTime + " | " +
"
";
$("#table3").append(tr);
autoRunTime += data[i].autoRunTime;
alarmTime += data[i].alarmTime;
idleTime += data[i].idleTime;
outPut += data[i].outPut;
alarmSum += data[i].alarmSum;
loadMATSum += data[i].loadMATSum;
loadMATTime += data[i].loadMATTime;
actualTT += data[i].actualTT;
}
var tr =
"" +
"合计 | " +
"" + autoRunTime + " | " +
"" + alarmTime + " | " +
"" + idleTime + " | " +
"" + outPut + " | " +
"" + (actualTT / 12).toFixed(2) + " | " +
"" + alarmSum + " | " +
"" + loadMATSum + " | " +
"" + loadMATTime + " | " +
"
";
$("#table3").append(tr);
autoRunTime = 0;
alarmTime = 0;
idleTime = 0;
outPut = 0;
alarmSum = 0;
loadMATSum = 0;
loadMATTime = 0;
actualTT = 0;
$("#table4 tbody").html("");
for (var i = 12; i < data.length; i++) {
var tr =
"" +
"" + data[i].period + " | " +
"" + data[i].moduleType + " | " +
"" + data[i].autoRunTime + " | " +
"" + data[i].alarmTime + " | " +
"" + data[i].idleTime + " | " +
"" + data[i].outPut + " | " +
"" + data[i].actualTT + " | " +
"" + data[i].alarmSum + " | " +
"" + data[i].loadMATSum + " | " +
"" + data[i].loadMATTime + " | " +
"
";
$("#table4").append(tr);
autoRunTime += data[i].autoRunTime;
alarmTime += data[i].alarmTime;
idleTime += data[i].idleTime;
outPut += data[i].outPut;
alarmSum += data[i].alarmSum;
loadMATSum += data[i].loadMATSum;
loadMATTime += data[i].loadMATTime;
actualTT += data[i].actualTT;
}
var tr =
"" +
"合计 | " +
"" + autoRunTime + " | " +
"" + alarmTime + " | " +
"" + idleTime + " | " +
"" + outPut + " | " +
"" + (actualTT / 12).toFixed(2) + " | " +
"" + alarmSum + " | " +
"" + loadMATSum + " | " +
"" + loadMATTime + " | " +
"
";
$("#table4").append(tr);
}
}
function machines(data) {
if (data === null || data.length === 0) {
$("#table1 tbody").html("");
for (var i = 0; i < 1; i++) {
var tr =
"" +
"没有找到匹配的记录 | " +
"
";
$("#table1").append(tr);
}
} else {
$("#table1 tbody").html("");
for (var i = 0; i < data.length; i++) {
var td1 = " | ";
var td2 = " | ";
var td3 = " | ";
var td4 = " | ";
var td5 = " | ";
if (data[i].statistics !== null && data[i].statistics.length > 0) {
td1 = "";
td2 = "";
td3 = "";
td4 = "";
td5 = "";
for (var j = 0; j < data[i].statistics.length; j++) {
td1 += "- " + data[i].statistics[j].moduleType + "
";
td2 += "- " + data[i].statistics[j].capacity + "
";
td3 += "- " + (data[i].statistics[j].availability * 100).toFixed(1) + "
";
td4 += "- " + (data[i].statistics[j].performance * 100).toFixed(1) + "
";
td5 += "- " + (data[i].statistics[j].oee * 100).toFixed(1) + "
";
}
td1 += " | ";
td2 += " | ";
td3 += " | ";
td4 += " | ";
td5 += " | ";
}
var tr =
"" +
"" + (i + 1) + " | " +
"" + data[i].name + " | " +
"" + data[i].type + " | " +
td1 + td2 + td3 + td4 + td5 +
"
";
$("#table1").append(tr);
}
}
}
function alarms(data) {
if (data === null || data.length === 0) {
$("#table2 tbody").html("");
for (var i = 0; i < 1; i++) {
var tr =
"" +
"没有找到匹配的记录 | " +
"
";
$("#table2").append(tr);
}
} else {
$("#table2 tbody").html("");
for (var i = 0; i < data.length; i++) {
var tr =
"" +
"" + (i + 1) + " | " +
"" + data[i].machineName + " | " +
"" + formatDate(data[i].startTime) + " | " +
"" + formatDate(data[i].endTime) + " | " +
"" + (data[i].machineState === 2 ? "自动" : "手动") + " | " +
"" + (data[i].duration).toFixed(3) + " | " +
"" + data[i].faultCode + " | " +
"" + data[i].faultInfo + " | " +
"
";
$("#table2").append(tr);
}
}
}
function alarmsMachine(data) {
if (data === null || data.length === 0) {
$("#machine_alarm tbody").html("");
for (var i = 0; i < 1; i++) {
var tr =
"" +
"没有找到匹配的记录 | " +
"
";
$("#machine_alarm").append(tr);
}
} else {
$("#machine_alarm tbody").html("");
for (var i = 0; i < data.length; i++) {
var tr =
"" +
"" + (i + 1) + " | " +
"" + formatDate(data[i].startTime) + " | " +
"" + formatDate(data[i].endTime) + " | " +
"" + (data[i].machineState === 2 ? "自动" : "手动") + " | " +
"" + (data[i].duration).toFixed(3) + " | " +
"" + data[i].faultCode + " | " +
"" + data[i].faultInfo + " | " +
"
";
$("#machine_alarm").append(tr);
}
}
}