707 lines
40 KiB
JavaScript
707 lines
40 KiB
JavaScript
![]() |
//DashboardService
|
|||
|
define(["angularAMD",
|
|||
|
"text!module/moduleWIP/config/dashboard.json",
|
|||
|
"text!module/moduleCustomer/config/dashboard.json"
|
|||
|
],
|
|||
|
function(angularAMD, dashboardConfig, c_dashboardConfig) {
|
|||
|
angularAMD.factory('DashboardService', ['$rootScope', '$filter', '$translate', 'config', 'MMWService', "$http", "$timeout",
|
|||
|
function($rootScope, $filter, $translate, config, $MMWService, $http, $timeout) {
|
|||
|
var timer, Notification;
|
|||
|
|
|||
|
function startSignalR(callback) {
|
|||
|
if (!Notification) {
|
|||
|
Notification = $MMWService.createHub('Notification', {
|
|||
|
connected: callback,
|
|||
|
listeners: {
|
|||
|
"BroadCast": function(content) {
|
|||
|
|
|||
|
$timeout(function() {
|
|||
|
content = JSON.parse(content);
|
|||
|
for (var index in content.broadcast) {
|
|||
|
//推播作業站,設備
|
|||
|
|
|||
|
switch (config.cache.dashboard) {
|
|||
|
case 'lot':
|
|||
|
if (content.broadcast[index].SiteNo == config.cache.op) {
|
|||
|
broadcast_process(content.broadcast[index].List);
|
|||
|
}
|
|||
|
break;
|
|||
|
|
|||
|
case 'eqp':
|
|||
|
if (content.broadcast[index].SiteNo == config.cache.equipment) {
|
|||
|
broadcast_process(content.broadcast[index].List);
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
});
|
|||
|
} else {
|
|||
|
if (callback)
|
|||
|
callback();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
function stopSignalR(callback) {
|
|||
|
if (Notification && Notification) {
|
|||
|
Notification.disconnect();
|
|||
|
Notification = undefined;
|
|||
|
}
|
|||
|
if (callback)
|
|||
|
callback();
|
|||
|
}
|
|||
|
|
|||
|
function broadcast_process(aryCondition) {
|
|||
|
|
|||
|
//生產任務看板
|
|||
|
if (aryCondition.Content_DBLot) {
|
|||
|
for (var index in aryCondition.Content_DBLot) {
|
|||
|
|
|||
|
var aryshort = aryCondition.Content_DBLot[index];
|
|||
|
//判斷資料是新增還是刪除
|
|||
|
switch (aryshort.dataaction) {
|
|||
|
case 0:
|
|||
|
//新增
|
|||
|
//如果已有資料,就不再新增。
|
|||
|
var index_temp;
|
|||
|
var search = factory.dashboard['workLog'].production_info_detail.some(function(item, ary_index) { index_temp = ary_index; return item.plot_no == aryshort.plot_no && item.Dispatch == aryshort.Dispatch; });
|
|||
|
if (!search) {
|
|||
|
factory.dashboard['workLog'].production_info_detail.push({
|
|||
|
status: aryshort.status,
|
|||
|
qty: aryshort.qty,
|
|||
|
plot_no: aryshort.plot_no,
|
|||
|
finish_time: aryshort.finish_time,
|
|||
|
cur_br: aryshort.cur_br,
|
|||
|
arrivetime: aryshort.arrivetime,
|
|||
|
status_order: aryshort.status == 'C' ? 1 : 0,
|
|||
|
Dispatch: aryshort.Dispatch
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
break;
|
|||
|
case -1:
|
|||
|
//刪除
|
|||
|
var index_temp;
|
|||
|
var search = factory.dashboard['workLog'].production_info_detail.some(function(item, ary_index) { index_temp = ary_index; return item.plot_no == aryshort.plot_no && item.Dispatch == aryshort.Dispatch; });
|
|||
|
if (search) { factory.dashboard['workLog'].production_info_detail.splice(index_temp, 1); }
|
|||
|
|
|||
|
break;
|
|||
|
case 2:
|
|||
|
//修改
|
|||
|
var index_temp;
|
|||
|
var search = factory.dashboard['workLog'].production_info_detail.some(function(item, ary_index) { index_temp = ary_index; return item.plot_no == aryshort.plot_no && item.Dispatch == aryshort.Dispatch; });
|
|||
|
if (search) {
|
|||
|
var obj_temp = {
|
|||
|
status: aryshort.status,
|
|||
|
qty: aryshort.qty,
|
|||
|
plot_no: aryshort.plot_no,
|
|||
|
finish_time: aryshort.finish_time,
|
|||
|
cur_br: aryshort.cur_br,
|
|||
|
arrivetime: aryshort.arrivetime,
|
|||
|
status_order: aryshort.status == 'C' ? 1 : 0,
|
|||
|
Dispatch: aryshort.Dispatch
|
|||
|
};
|
|||
|
factory.dashboard['workLog'].production_info_detail[index_temp] = obj_temp;
|
|||
|
}
|
|||
|
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//上工人員看板
|
|||
|
if (aryCondition.Content_DBwork_member) {
|
|||
|
for (var index in aryCondition.Content_DBwork_member) {
|
|||
|
|
|||
|
var aryshort = aryCondition.Content_DBwork_member[index];
|
|||
|
//判斷資料是新增還是刪除
|
|||
|
switch (aryshort.dataaction) {
|
|||
|
case 0:
|
|||
|
//新增
|
|||
|
//如果已有資料,就不再新增。
|
|||
|
var index_temp;
|
|||
|
var search = factory.dashboard['workOperator'].work_member_detail.some(function(item, ary_index) { index_temp = ary_index; return item.employee_no == aryshort.employee_no && item.login_place == aryshort.login_place; });
|
|||
|
if (!search) { factory.dashboard['workOperator'].work_member_detail.push({ work_time: aryshort.work_time, employee_no: aryshort.employee_no, employee_name: aryshort.employee_name, login_place: aryshort.login_place, multi_operator_mode: aryshort.multi_operator_mode }); }
|
|||
|
|
|||
|
|
|||
|
break;
|
|||
|
case -1:
|
|||
|
//刪除
|
|||
|
var index_temp;
|
|||
|
var search = factory.dashboard['workOperator'].work_member_detail.some(function(item, ary_index) { index_temp = ary_index; return item.employee_no == aryshort.employee_no && item.login_place == aryshort.login_place; });
|
|||
|
if (search) { factory.dashboard['workOperator'].work_member_detail.splice(index_temp, 1); }
|
|||
|
|
|||
|
break;
|
|||
|
case 2:
|
|||
|
//修改 (先刪除後新增)
|
|||
|
var index_temp;
|
|||
|
var search = factory.dashboard['workOperator'].work_member_detail.some(function(item, ary_index) { index_temp = ary_index; return item.employee_no == aryshort.employee_no && item.login_place == aryshort.login_place; });
|
|||
|
if (search) {
|
|||
|
var obj_temp = { work_time: aryshort.work_time, employee_no: aryshort.employee_no, employee_name: aryshort.employee_name, login_place: aryshort.login_place, multi_operator_mode: aryshort.multi_operator_mode };
|
|||
|
factory.dashboard['workOperator'].work_member_detail[index_temp] = obj_temp;
|
|||
|
}
|
|||
|
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
//設備參數看板
|
|||
|
if (aryCondition.Content_DBRecipe) {
|
|||
|
for (var index in aryCondition.Content_DBRecipe) {
|
|||
|
//判斷資料是新增還是刪除
|
|||
|
var aryshort = aryCondition.Content_DBRecipe[index];
|
|||
|
//判斷資料是新增還是刪除
|
|||
|
switch (aryshort.dataaction) {
|
|||
|
case 0:
|
|||
|
//新增
|
|||
|
factory.dashboard['deviceInfo'].machine_property_detail.push({ property_no: aryshort.property_no, guideline_1: aryshort.guideline_1, guideline_2: aryshort.guideline_2, guideline_max: aryshort.guideline_max, guideline_min: aryshort.guideline_min, guideline_mode: aryshort.guideline_mode, need_alert: aryshort.need_alert, property_name: aryshort.property_name, property_value: aryshort.property_value });
|
|||
|
|
|||
|
break;
|
|||
|
case -1:
|
|||
|
//刪除
|
|||
|
var index_temp;
|
|||
|
var search = factory.dashboard['deviceInfo'].machine_property_detail.some(function(item, ary_index) { index_temp = ary_index; return item.property_no == aryshort.property_no; });
|
|||
|
if (search) { factory.dashboard['deviceInfo'].machine_property_detail.splice(index_temp, 1); }
|
|||
|
|
|||
|
break;
|
|||
|
case 2:
|
|||
|
//修改(先刪除後新增)
|
|||
|
if (index == 0) { factory.dashboard['deviceInfo'].machine_property_detail.length = 0; }
|
|||
|
|
|||
|
factory.dashboard['deviceInfo'].machine_property_detail.push({ property_no: aryshort.property_no, guideline_1: aryshort.guideline_1, guideline_2: aryshort.guideline_2, guideline_max: aryshort.guideline_max, guideline_min: aryshort.guideline_min, guideline_mode: aryshort.guideline_mode, need_alert: aryshort.need_alert, property_name: aryshort.property_name, property_value: aryshort.property_value });
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//上機物料看板
|
|||
|
if (aryCondition.Content_DBMaterial) {
|
|||
|
for (var index in aryCondition.Content_DBMaterial) {
|
|||
|
//判斷資料是新增還是刪除
|
|||
|
var aryshort = aryCondition.Content_DBMaterial[index];
|
|||
|
//判斷資料是新增還是刪除
|
|||
|
switch (aryshort.dataaction) {
|
|||
|
case 0:
|
|||
|
//新增
|
|||
|
factory.dashboard['workMaterial'].materials_detail.push({ materials_no: aryshort.materials_no, materials_name: aryshort.materials_name, materials_qty: aryshort.materials_qty, materials_unit: aryshort.materials_unit });
|
|||
|
|
|||
|
break;
|
|||
|
case -1:
|
|||
|
//刪除
|
|||
|
var index_temp;
|
|||
|
var search = factory.dashboard['workMaterial'].materials_detail.some(function(item, ary_index) { index_temp = ary_index; return item.materials_no == aryshort.materials_no; });
|
|||
|
if (search) { factory.dashboard['workMaterial'].materials_detail.splice(index_temp, 1); }
|
|||
|
|
|||
|
break;
|
|||
|
case 2:
|
|||
|
//修改
|
|||
|
var index_temp;
|
|||
|
var search = factory.dashboard['workMaterial'].materials_detail.some(function(item, ary_index) { index_temp = ary_index; return item.materials_no == aryshort.materials_no; });
|
|||
|
if (search) {
|
|||
|
var obj_temp = { materials_no: aryshort.materials_no, materials_name: aryshort.materials_name, materials_qty: aryshort.materials_qty, materials_unit: aryshort.materials_unit };
|
|||
|
factory.dashboard['workMaterial'].materials_detail[index_temp] = obj_temp;
|
|||
|
}
|
|||
|
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//品質狀態看板
|
|||
|
if (aryCondition.Content_quality_detail) {
|
|||
|
for (var index in aryCondition.Content_quality_detail) {
|
|||
|
//判斷資料是新增還是刪除
|
|||
|
var aryshort = aryCondition.Content_quality_detail[index];
|
|||
|
//判斷資料是新增還是刪除
|
|||
|
switch (aryshort.dataaction) {
|
|||
|
case 2:
|
|||
|
//修改
|
|||
|
try {
|
|||
|
|
|||
|
var obj_temp = { shift_work_qty: aryshort.shift_work_qty, shift_defect_qty: aryshort.shift_defect_qty, quality_guideline_y: aryshort.quality_guideline_y, quality_guideline_r: aryshort.quality_guideline_r };
|
|||
|
factory.dashboard['qualityStatus'].quality_detail = obj_temp;
|
|||
|
|
|||
|
var qty_rate = factory.dashboard['qualityStatus'].quality_detail.shift_defect_qty / factory.dashboard['qualityStatus'].quality_detail.shift_work_qty * 100;
|
|||
|
if (isNaN(qty_rate)) {
|
|||
|
factory.dashboard['qualityStatus'].quality_detail.qty_rate = 0;
|
|||
|
} else {
|
|||
|
factory.dashboard['qualityStatus'].quality_detail.qty_rate = qty_rate.toFixed(2);
|
|||
|
}
|
|||
|
|
|||
|
factory.dashboard['qualityStatus'].quality_detail.lightColor = lightColor(factory.dashboard['qualityStatus'].quality_detail);
|
|||
|
|
|||
|
} catch (e) {
|
|||
|
factory.dashboard['qualityStatus'].quality_detail.qty_rate = 0;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
function getEquipmentStatus(equipment, callback, isLoading) {
|
|||
|
if (isLoading == undefined) {
|
|||
|
isLoading = false;
|
|||
|
}
|
|||
|
$MMWService.sendToEAISrv({
|
|||
|
uri: 'KMI.machine_status_get_json',
|
|||
|
content: {
|
|||
|
machine_no: equipment,
|
|||
|
StationNo: config.setting.workStation,
|
|||
|
num_of_days: factory.dashboard['deviceInfo'].num_of_days
|
|||
|
},
|
|||
|
success: function(data) {
|
|||
|
if (callback)
|
|||
|
callback(data);
|
|||
|
},
|
|||
|
error: function(data) {
|
|||
|
//20170331 modify by Dustdusk for 當失敗時,isShowLoading為false則重新執行一次
|
|||
|
$rootScope.showAlert(data.Exception, function() {
|
|||
|
if (isLoading == false) {
|
|||
|
if (factory.isStart) {
|
|||
|
factory.getEquipmentStatus(equipment, callback, isLoading);
|
|||
|
}
|
|||
|
}
|
|||
|
});
|
|||
|
factory.dashboard['workOperator'].work_member_detail = undefined;
|
|||
|
factory.dashboard['qualityStatus'].quality_detail = undefined;
|
|||
|
factory.dashboard['workMaterial'].materials_detail = undefined;
|
|||
|
factory.dashboard['workLog'].production_info_detail = undefined;
|
|||
|
},
|
|||
|
netError: function() {
|
|||
|
//20170331 modify by Dustdusk for 當失敗時,isShowLoading為false則重新執行一次
|
|||
|
if (isLoading == false) {
|
|||
|
if (factory.isStart) {
|
|||
|
factory.getEquipmentStatus(equipment, callback, isLoading);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}, isLoading);
|
|||
|
}
|
|||
|
|
|||
|
function getWorkingInfo(equipment, dataType, callback, isLoading) {
|
|||
|
var accountno = config.cache.account;
|
|||
|
if (isLoading == undefined) {
|
|||
|
isLoading = false;
|
|||
|
}
|
|||
|
|
|||
|
$MMWService.sendToEAISrv({
|
|||
|
uri: 'KMI.machine_working_info_get_json',
|
|||
|
content: {
|
|||
|
login_employee_no: accountno,
|
|||
|
machine_no: equipment,
|
|||
|
data_type: dataType,
|
|||
|
workstation_no: config.setting.workStation
|
|||
|
},
|
|||
|
success: function(data) {
|
|||
|
if (callback)
|
|||
|
callback(data);
|
|||
|
},
|
|||
|
error: function(data) {
|
|||
|
//20170331 modify by Dustdusk for 當失敗時,isShowLoading為false則重新執行一次
|
|||
|
$rootScope.showAlert(data.Exception, function() {
|
|||
|
if (isLoading == false) {
|
|||
|
if (factory.isStart) {
|
|||
|
factory.getWorkingInfo(equipment, dataType, callback, isLoading);
|
|||
|
}
|
|||
|
}
|
|||
|
});
|
|||
|
},
|
|||
|
netError: function() {
|
|||
|
//20170331 modify by Dustdusk for 當失敗時,isShowLoading為false則重新執行一次
|
|||
|
if (isLoading == false) {
|
|||
|
if (factory.isStart) {
|
|||
|
factory.getWorkingInfo(equipment, dataType, callback, isLoading);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}, isLoading);
|
|||
|
}
|
|||
|
|
|||
|
function getWorkingInfo_byLot(opno, dataType, callback, isLoading) {
|
|||
|
var accountno = config.cache.account;
|
|||
|
if (isLoading == undefined) {
|
|||
|
isLoading = false;
|
|||
|
}
|
|||
|
|
|||
|
$MMWService.sendToEAISrv({
|
|||
|
uri: 'KMI.op_working_info_get_json',
|
|||
|
content: {
|
|||
|
login_employee_no: accountno,
|
|||
|
op_no: opno,
|
|||
|
data_type: dataType
|
|||
|
},
|
|||
|
success: function(data) {
|
|||
|
if (callback)
|
|||
|
callback(data);
|
|||
|
},
|
|||
|
error: function(data) {
|
|||
|
//20170331 modify by Dustdusk for 當失敗時,isShowLoading為false則重新執行一次
|
|||
|
$rootScope.showAlert(data.Exception, function() {
|
|||
|
if (isLoading == false) {
|
|||
|
if (factory.isStart) {
|
|||
|
factory.getWorkingInfo_byLot(opno, dataType, callback, isLoading);
|
|||
|
}
|
|||
|
}
|
|||
|
});
|
|||
|
},
|
|||
|
netError: function() {
|
|||
|
//20170331 modify by Dustdusk for 當失敗時,isShowLoading為false則重新執行一次
|
|||
|
if (isLoading == false) {
|
|||
|
if (factory.isStart) {
|
|||
|
factory.getWorkingInfo_byLot(opno, dataType, callback, isLoading);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}, isLoading);
|
|||
|
}
|
|||
|
|
|||
|
var count = 0;
|
|||
|
//取得dashboard的資料
|
|||
|
function getDashBoardData(options) {
|
|||
|
var dataType = options.dataType,
|
|||
|
callback = options.callback,
|
|||
|
isShowLoading = options.isShowLoading;
|
|||
|
token = factory.token = Math.floor(Math.random() * 10);
|
|||
|
|
|||
|
if (config.cache.dashboard == 'eqp') {
|
|||
|
var equipment = options.equipment;
|
|||
|
|
|||
|
factory.getEquipmentStatus(equipment, function(data) {
|
|||
|
if (token === factory.token) {
|
|||
|
//data = JSON.parse(data.Result);
|
|||
|
data = JSON.parse(data.ResultJson);
|
|||
|
//console.log('getEquipmentStatus : ',data);
|
|||
|
if (data.machine_info) {
|
|||
|
data.rate_detail = [];
|
|||
|
data.machine_info[0].machine_utilization_rate_detail.forEach(function(detail) {
|
|||
|
data.rate_detail.push({ label: detail.status, value: detail.work_min, color: 'rgb(' + detail.status_color + ')' });
|
|||
|
});
|
|||
|
angular.merge(factory.dashboard['deviceInfo'], data);
|
|||
|
factory.dashboard['deviceInfo'].rate_detail = data.rate_detail;
|
|||
|
factory.dashboard['deviceInfo'].total_time = factory.dashboard['deviceInfo'].total_time || 0;
|
|||
|
//20181108 modify by Dustdusk fro M#: 機台參數沒有更新
|
|||
|
factory.dashboard['deviceInfo'].machine_property_detail = data.machine_info[0].machine_property_detail;
|
|||
|
//判斷是否進入警告
|
|||
|
factory.filterAlert(factory.dashboard['deviceInfo'].machine_property_detail);
|
|||
|
factory.getWorkingInfo(equipment, dataType, function(data) {
|
|||
|
if (token === factory.token) {
|
|||
|
//data = JSON.parse(data.Result);
|
|||
|
data = JSON.parse(data.ResultJson);
|
|||
|
//console.log('getWorkingInfo : ',data);
|
|||
|
if (data.work_member_detail) {
|
|||
|
try {
|
|||
|
//人員上下工相關資料
|
|||
|
factory.dashboard['workOperator'].default_shift = data.shift;
|
|||
|
factory.dashboard['workOperator'].work_member_detail = data.work_member_detail;
|
|||
|
|
|||
|
//品質狀態相關資料
|
|||
|
try {
|
|||
|
data.quality_detail[0].shift_defect_qty = data.quality_detail[0].shift_defect_qty || 0;
|
|||
|
data.quality_detail[0].shift_work_qty = data.quality_detail[0].shift_work_qty || 0;
|
|||
|
var qty_rate = data.quality_detail[0].shift_defect_qty / data.quality_detail[0].shift_work_qty * 100;
|
|||
|
if (isNaN(qty_rate)) {
|
|||
|
data.quality_detail[0].qty_rate = 0;
|
|||
|
} else {
|
|||
|
data.quality_detail[0].qty_rate = qty_rate.toFixed(2);
|
|||
|
}
|
|||
|
data.quality_detail[0].lightColor = lightColor(data.quality_detail[0]);
|
|||
|
} catch (e) {
|
|||
|
data.quality_detail[0].qty_rate = 0;
|
|||
|
}
|
|||
|
factory.dashboard['qualityStatus'].quality_detail = data.quality_detail[0];
|
|||
|
|
|||
|
//上料相關資料
|
|||
|
factory.dashboard['workMaterial'].materials_detail = data.materials_detail;
|
|||
|
|
|||
|
//生產資訊
|
|||
|
factory.dashboard['workLog'].production_info_detail = data.production_info_detail;
|
|||
|
//測試用
|
|||
|
//factory.dashboard['workLog'].production_info_detail.push({status:'C',qty:'1.0000',plot_no:'ST1-W01-1604120009-001',finish_time:'2016-05-03 09:38'});
|
|||
|
|
|||
|
factory.dashboard.updateTime = new Date();
|
|||
|
if (callback)
|
|||
|
callback();
|
|||
|
} catch (e) {
|
|||
|
$rootScope.showAlert(e, function() {
|
|||
|
if (isShowLoading == false) {
|
|||
|
if (factory.isStart) {
|
|||
|
factory.getDashBoardData(options);
|
|||
|
}
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
} else {
|
|||
|
$rootScope.showAlert(data.SysMsg, function() {
|
|||
|
if (isShowLoading == false) {
|
|||
|
if (factory.isStart) {
|
|||
|
factory.getDashBoardData(options);
|
|||
|
}
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
} else {
|
|||
|
console.log('fail token');
|
|||
|
}
|
|||
|
}, isShowLoading);
|
|||
|
} else {
|
|||
|
$rootScope.showAlert(data.SysMsg, function() {
|
|||
|
if (isShowLoading == false) {
|
|||
|
if (factory.isStart) {
|
|||
|
factory.getDashBoardData(options);
|
|||
|
}
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
} else {
|
|||
|
console.log('fail token');
|
|||
|
}
|
|||
|
}, isShowLoading);
|
|||
|
|
|||
|
|
|||
|
|
|||
|
} else {
|
|||
|
var opno = options.opno;
|
|||
|
|
|||
|
factory.getWorkingInfo_byLot(opno, dataType, function(data) {
|
|||
|
if (token === factory.token) {
|
|||
|
//data = JSON.parse(data.Result);
|
|||
|
data = JSON.parse(data.ResultJson);
|
|||
|
console.log('getWorkingInfo_byLot : ', data);
|
|||
|
if (data.op_detail) {
|
|||
|
try {
|
|||
|
//作業站資訊
|
|||
|
angular.merge(factory.dashboard['opInfo'], data.op_detail[0]);
|
|||
|
|
|||
|
//人員上下工相關資料
|
|||
|
if (data.work_member_detail.length > 0) {
|
|||
|
factory.dashboard['workOperator'].multioperatormode = data.work_member_detail[0].multi_operator_mode;
|
|||
|
} else {
|
|||
|
factory.dashboard['workOperator'].multioperatormode = 0;
|
|||
|
}
|
|||
|
factory.dashboard['workOperator'].default_shift = data.shift;
|
|||
|
factory.dashboard['workOperator'].work_member_detail = data.work_member_detail;
|
|||
|
|
|||
|
//品質狀態相關資料
|
|||
|
try {
|
|||
|
data.quality_detail[0].shift_defect_qty = data.quality_detail[0].shift_defect_qty || 0;
|
|||
|
data.quality_detail[0].shift_work_qty = data.quality_detail[0].shift_work_qty || 0;
|
|||
|
var qty_rate = data.quality_detail[0].shift_defect_qty / data.quality_detail[0].shift_work_qty * 100;
|
|||
|
if (isNaN(qty_rate)) {
|
|||
|
data.quality_detail[0].qty_rate = 0;
|
|||
|
} else {
|
|||
|
data.quality_detail[0].qty_rate = qty_rate.toFixed(2);
|
|||
|
}
|
|||
|
data.quality_detail[0].lightColor = lightColor(data.quality_detail[0]);
|
|||
|
} catch (e) {
|
|||
|
data.quality_detail[0].qty_rate = 0;
|
|||
|
}
|
|||
|
factory.dashboard['qualityStatus'].quality_detail = data.quality_detail[0];
|
|||
|
|
|||
|
|
|||
|
//生產資訊
|
|||
|
factory.dashboard['workLog'].production_info_detail = data.production_info_detail;
|
|||
|
//測試用
|
|||
|
//factory.dashboard['workLog'].production_info_detail.push({status:'C',qty:'1.0000',plot_no:'ST1-W01-1604120009-001',finish_time:'2016-05-03 09:38'});
|
|||
|
|
|||
|
factory.dashboard.updateTime = new Date();
|
|||
|
if (callback)
|
|||
|
callback();
|
|||
|
} catch (e) {
|
|||
|
$rootScope.showAlert(e, function() {
|
|||
|
if (isShowLoading == false) {
|
|||
|
if (factory.isStart) {
|
|||
|
factory.getDashBoardData(options);
|
|||
|
}
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
} else {
|
|||
|
$rootScope.showAlert(data.SysMsg, function() {
|
|||
|
if (isShowLoading == false) {
|
|||
|
if (factory.isStart) {
|
|||
|
factory.getDashBoardData(options);
|
|||
|
}
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
} else {
|
|||
|
console.log('fail token');
|
|||
|
}
|
|||
|
}, isShowLoading);
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
//呼叫getDashBoardData, 設定時間到了以後再執行callback
|
|||
|
//並且只有在第一次開始的時候傳入true讓loading出現
|
|||
|
function dashboardTimer(callback, isFirst) {
|
|||
|
var equipment = config.cache.equipment;
|
|||
|
var opno = config.cache.workStation;
|
|||
|
|
|||
|
var dataType = '1111';
|
|||
|
|
|||
|
if (config.cache.dashboard == 'eqp') {
|
|||
|
factory.getDashBoardData({
|
|||
|
equipment: equipment,
|
|||
|
dataType: dataType,
|
|||
|
callback: function() {
|
|||
|
timer = setTimeout(function() {
|
|||
|
if (callback)
|
|||
|
callback(callback);
|
|||
|
}, config.setting.RefreshTime * 1000);
|
|||
|
},
|
|||
|
isShowLoading: isFirst
|
|||
|
});
|
|||
|
} else {
|
|||
|
factory.getDashBoardData({
|
|||
|
opno: opno,
|
|||
|
dataType: dataType,
|
|||
|
callback: function() {
|
|||
|
timer = setTimeout(function() {
|
|||
|
if (callback)
|
|||
|
callback(callback);
|
|||
|
}, config.setting.RefreshTime * 1000);
|
|||
|
},
|
|||
|
isShowLoading: isFirst
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
function lightColor(item) {
|
|||
|
if (item.qty_rate < item.quality_guideline_y) {
|
|||
|
return 'green';
|
|||
|
} else if (item.qty_rate >= item.quality_guideline_y && item.qty_rate < item.quality_guideline_r) {
|
|||
|
return 'yellow';
|
|||
|
} else if (item.qty_rate >= item.quality_guideline_r) {
|
|||
|
return 'red';
|
|||
|
}
|
|||
|
|
|||
|
return '';
|
|||
|
}
|
|||
|
|
|||
|
function filterAlert(machine_property_detail) {
|
|||
|
if (factory.alertStartHandler) {
|
|||
|
var alertList = [];
|
|||
|
for (var index in machine_property_detail) {
|
|||
|
var detail = machine_property_detail[index];
|
|||
|
if (detail.need_alert == 'Y') {
|
|||
|
alertList.push(detail);
|
|||
|
}
|
|||
|
}
|
|||
|
if (!factory.isShowAlert && alertList.length > 0) {
|
|||
|
factory.isShowAlert = true;
|
|||
|
factory.alertStartHandler(alertList);
|
|||
|
} else if (factory.isShowAlert && alertList.length == 0) {
|
|||
|
factory.isShowAlert = false;
|
|||
|
if (factory.alertStopHandler)
|
|||
|
factory.alertStopHandler();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
var factory = {};
|
|||
|
factory.isStart = false;
|
|||
|
|
|||
|
//2021-02-03 yenru,繼承前 先將標準DashBoard 與個案合併
|
|||
|
var temp_object = {};
|
|||
|
dashboardConfig = JSON.parse(dashboardConfig);
|
|||
|
c_dashboardConfig = JSON.parse(c_dashboardConfig);
|
|||
|
|
|||
|
for (var i = 0; i < Object.keys(c_dashboardConfig).length; i++) {
|
|||
|
|
|||
|
var subFlag = false;
|
|||
|
|
|||
|
for (var j = 0; j < Object.keys(dashboardConfig).length; j++) {
|
|||
|
|
|||
|
if (Object.keys(c_dashboardConfig)[i] == Object.keys(dashboardConfig)[j]) {
|
|||
|
subFlag = true;
|
|||
|
//合併,以個案為主
|
|||
|
dashboardConfig[Object.keys(dashboardConfig)[j]] = c_dashboardConfig[Object.keys(c_dashboardConfig)[i]];
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
//新增個案DashBoard
|
|||
|
if (subFlag == false) {
|
|||
|
temp_object[Object.keys(c_dashboardConfig)[i]] = c_dashboardConfig[Object.keys(c_dashboardConfig)[i]];
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
for (var k = 0; k < Object.keys(temp_object).length; k++) {
|
|||
|
dashboardConfig[Object.keys(temp_object)[k]] = temp_object[Object.keys(temp_object)[k]];
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
factory.dashboard = dashboardConfig;
|
|||
|
factory.getEquipmentStatus = getEquipmentStatus;
|
|||
|
factory.getWorkingInfo = getWorkingInfo;
|
|||
|
factory.getWorkingInfo_byLot = getWorkingInfo_byLot;
|
|||
|
factory.getDashBoardData = getDashBoardData;
|
|||
|
factory.startSignalR = startSignalR;
|
|||
|
factory.stopSignalR = stopSignalR;
|
|||
|
factory.filterAlert = filterAlert;
|
|||
|
factory.getDashboard = function(name) {
|
|||
|
return factory.dashboard[name];
|
|||
|
}
|
|||
|
//執行dashboardTimer以呼叫getDashBoardData, 並且時間到了之後再次執行dashboardTimer
|
|||
|
//並且只有在第一次開始的時候傳入true讓loading出現
|
|||
|
factory.startWatch = function() {
|
|||
|
factory.isStart = true;
|
|||
|
if (!timer) {
|
|||
|
dashboardTimer(dashboardTimer, true);
|
|||
|
} else {
|
|||
|
console.error('Dashboard is already start ... ');
|
|||
|
}
|
|||
|
}
|
|||
|
factory.stopWatch = function() {
|
|||
|
factory.isStart = false;
|
|||
|
clearTimeout(timer);
|
|||
|
timer = undefined;
|
|||
|
}
|
|||
|
factory.dashboardWarn = function(item) {
|
|||
|
if (item.guideline_mode == '1') {
|
|||
|
if ((+item.guideline_2) <= (+item.property_value))
|
|||
|
return 'is-warn';
|
|||
|
} else if (item.guideline_mode == '2') {
|
|||
|
if ((+item.guideline_1) >= (+item.property_value))
|
|||
|
return 'is-warn';
|
|||
|
} else if (item.guideline_mode == '3') {
|
|||
|
if ((+item.guideline_2) <= (+item.property_value) ||
|
|||
|
(+item.guideline_1) >= (+item.property_value)) {
|
|||
|
return 'is-warn';
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return '';
|
|||
|
}
|
|||
|
factory.isShowAlert = false;
|
|||
|
factory.alertStartHandler = undefined;
|
|||
|
factory.alertStopHandler = undefined;
|
|||
|
|
|||
|
return factory;
|
|||
|
}
|
|||
|
]);
|
|||
|
});
|