This repo is archived. You can view files and clone it, but cannot push or open issues or pull requests.
SXS20240115/SRC/iMES_PAD/module/moduleWIP/program/mrs-eqp/mrs05/mrs05Service.js
2024-01-24 16:47:50 +08:00

652 lines
30 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

define(["angularAMD"], function (angularAMD) {
angularAMD.service('mrs05Service', ["$rootScope", "$filter", "$stateParams", "config", "DashboardService", "MMWService", '$mdDialog',
function ($rootScope, $filter, $stateParams, config, $DashboardService, $MMWService, $mdDialog) {
/***
* optins : {
* plotItem : {
* plot_no,
* op_seq,
* op_no
* work_station
* },
* close : function //關閉後呼叫的方法
* }
*/
this.init = function (options) {
function openDialog() {
$mdDialog.dialog('module/moduleWIP/program/mrs-eqp/mrs05/mrs05.html',
function (dialog) {
$rootScope.equipment = {};
initialDialogParameters(dialog);
if (dialog.equipmentNo != undefined) {
getQCList(dialog.equipmentNo, dialog.callByCheckIn, loadQcList);
}
function loadQcList(data) {
var tmp;
tmp = JSON.parse(data['kcWIP.clsLot.LoadWaitQCListData']);
ReplaceInspTypeInQcListWithValueList(tmp.WaitQCList, function (waitQCList) {
dialog.WaitQCList = waitQCList;
});
//BR進站時不顯示補點檢
if (!dialog.callByCheckIn) {
tmp = JSON.parse(data['kcWIP.clsLot.LoadReQCListData']);
ReplaceInspTypeInQcListWithValueList(tmp.ReQCList, function (reQCList) {
dialog.ReQCList = reQCList;
});
}
}
//ValueList相關
function ReplaceInspTypeInQcListWithValueList(qcList, callback) {
GetValueList('FRMEQPQCLISTSETUP', 'QCTYPE', function (valueList) {
if (valueList.length > 0) {
qcList.forEach(
qcListItem => {
var drSel = valueList.filter(valueListItem => {
return qcListItem.INSPTYPE == valueListItem.COLUMNVALUE;
});
if (drSel.length > 0) {
return qcListItem.InspTypeName = $filter('translate')('mrs05.QCTYPE.' + drSel[0].DISPLAYTEXT.toUpperCase());
}
}
);
}
if (callback) callback(qcList);
});
}
function GetValueList(pTableName, pColumnName, callback) {
var uri = [];
var content = [];
uri.push("kcSYS.clsValueList.LoadValueList");
content.push({
pTableName: pTableName,
pColumnName: pColumnName
});
$MMWService.sendToMESSrv_Multi({
uri: uri,
content: content,
success: function (data) {
if (data.Code == "0") {
var tmpJson = JSON.parse(data.ResultJson);
var tmp;
var index = 0;
tmp = JSON.parse(tmpJson[uri[index]]);
tmp = tmp[Object.keys(tmp)[0]];
if (callback) {
callback(tmp);
}
}
}
});
}
return {
confirm: function () {
//全填寫完才可存檔
for (var n in dialog.eqpQcListDetail) {
if (dialog.eqpQcListDetail[n].QCResult == -1) {
$rootScope.showAlert(dialog.eqpQcListDetail[n].QCITEM + $filter('translate')('mrs05.msg.notDefine'));
return;
}
}
prepareParameters(dialog);
addWIPEQPQCListLog(dialog, function (data) {
data = JSON.parse(data.ResultJson);
if (data.Result != 'fail') {
options.callBack(true);
dialog.hide();
} else {
$rootScope.showAlert(data.SysMsg);
}
});
},
background: {
click: function () {
dialog.hide();
if (typeof (feedback) == 'function')
feedback();
}
},
itemStatus: function (item) {
if (item.check_type == '0') {
if (item.std_value == item.CheckValue) {
//item.CheckResult = 'OK'
item.CheckResult = 0
return 'check-point-ok';
} else {
//item.CheckResult = 'NG'
item.CheckResult = 1
return 'check-point-notok';
}
} else if (item.check_type == '1') {
var isInterval = true;
if (item.range_min !== null) {
isInterval = isInterval && ((+item.range_min) <= (+item.CheckValue));
}
if (item.range_max !== null) {
isInterval = isInterval && ((+item.CheckValue) <= (+item.range_max));
}
if (isInterval) {
//item.CheckResult = 'OK'
item.CheckResult = 0
return 'check-point-ok';
} else {
//item.CheckResult = 'NG'
item.CheckResult = 1
return 'check-point-notok';
}
} else if (item.check_type == '3') { //20190312 KevinChang加入QC類別為3的CheckResult直接給0
item.CheckResult = 0
}
return '';
},
itemClick: function (item) {
//item.isClick = !item.isClick;
if (item.CheckValue == '0') {
//item.CheckResult = 'NG'
item.CheckResult = 1
item.CheckValue = 1;
} else {
//item.CheckResult = 'OK';
item.CheckResult = 0
item.CheckValue = 0;
}
},
type2Init: function (item) {
if (!item.CheckValue) {
//item.CheckResult = 'NG';
item.CheckResult = 1
item.CheckValue = 1;
}
},
back: function () {
dialog.hide();
if (options.close)
options.close();
},
cancel: function () {
dialog.eqpQcListDetail = [];
},
loadMachineChecklist: function (item) {
dialog.qcListNo = item.QCLISTNO;
dialog.qcListName = item.QCLISTNAME;
dialog.qcTaskNo = item.QCTASKNO;
dialog.inspType = item.INSPTYPE;
//移除EAI 架構直接呼叫KC
var uri = [];
var content = [];
//點檢序號
uri.push("kcWIP.clsWIP.GetQCListSerial");
content.push({
QCListSerialLeadString: getQCListSerialLeadString(item.QCLISTNO)
});
uri.push("kcEQP.clsEQPBasis.ShowEQPQCListBasis");
content.push({
QCListNo: item.QCLISTNO
});
//品管項目
uri.push("kcEQP.clsEQPBasis.ShowEQPQCListDetail");
content.push({
QCListNo: item.QCLISTNO
});
//設備
uri.push("kcEQP.clsEQPBasis.LoadEquipmentBasis");
content.push({
EquipmentNo: dialog.equipmentNo
});
getMachineChecklist(uri, content, function (data) {
data = JSON.parse(data.ResultJson);
if (Object.keys(data).length > 0) {
let temp;
//點檢序號
temp = JSON.parse(data['kcWIP.clsWIP.GetQCListSerial']);
dialog.qCListSerial = temp.ReturnValue;
temp = JSON.parse(data['kcEQP.clsEQPBasis.ShowEQPQCListBasis']);
temp = temp.ShowEQPQCListBasis;
if (temp.length > 0)
dialog.unValidAction = temp[0].UNVALIDACTION;
//品管項目
temp = JSON.parse(data['kcEQP.clsEQPBasis.ShowEQPQCListDetail']);
temp.ShowEQPQCListDetail = initialQcListDetail(temp.ShowEQPQCListDetail, dialog.qCListSerial);
dialog.expressionColQty = initialExpressionColQty(temp.ShowEQPQCListDetail);
dialog.eqpQcListDetail = temp.ShowEQPQCListDetail;
//設備類別、設備名稱
temp = JSON.parse(data['kcEQP.clsEQPBasis.LoadEquipmentBasis']);
temp = temp.EQPEquipmentBasis[0];
dialog.equipmentType = temp.EQUIPMENTTYPE;
dialog.equipmentName = temp.EQUIPMENTNAME;
}
});
},
inputValueCorrect: inputValueCorrect,
checkQCResult: checkQCResult,
switchQCResult: function (item) {
if (item.QCTYPE == 2) {
item.QCResult = (item.QCResult == 0) ? 1 : 0;
}
},
showCorrectIcon: showCorrectIcon,
showErrorIcon: showErrorIcon,
scanQrcode_eqp: function () {
$rootScope.$root.OpenScanner({
after: function (result) {
dialog.equipmentNo = result.text;
//20230324,13871,處理錯誤
//search_eqp({ eqpno: dialog.equipmentNo }, function (data) { });
getQCList(dialog.equipmentNo,dialog.callByCheckIn, loadQcList);
},
exception: function () {
//目前裝置無法使用相機
$rootScope.showAlert($filter('translate')('common.msg.camera_not_support'));
},
orientation: "landscape"
});
},
enter: function (event) {
if (event.keyCode == 13) {
getQCList(dialog.equipmentNo,dialog.callByCheckIn, loadQcList);
}
},
showEquipmentList: function () {
if (dialog.equipmentNoList == undefined) return;
if (dialog.equipmentNoList.length <= 0) return;
$rootScope.showSelect({
title: "{{'mrs05.title'|translate}}",
label: "MACHINE_NO",
code: "MACHINE_NO",
order: "MACHINE_NO",
selectCode: '',
list: dialog.equipmentNoList,
confirm: function (s_item, s_dialog) {
s_dialog.hide();
dialog.equipmentNo = s_item.MACHINE_NO;
getQCList(dialog.equipmentNo, dialog.callByCheckIn, loadQcList);
}
});
}
}
}
);
}
function search_eqp(content, callback) {
$rootScope.alertStatus(function (Status) {
if (Status == 1) {
return;
} else {
getAllMachineData_OP(content.eqpno, function (data) {
data = JSON.parse(data.ResultJson);
var dt = data["ds"]["query_result"];
if (dt.length > 0) {
dialog.listWorkStation = dt;
} else {
$rootScope.showAlert($filter('translate')('mrs00.msg.cantGet') + dialog.equipmentNo + $filter('translate')('mrs00.msg.machineInfo'));
dialog.equipmentNo = '';
dialog.listWorkStation = [];
}
});
}
});
}
function getAllMachineData_OP(strEQP, callback) {
$MMWService.sendToMESSrv({
uri: 'kcWIP.clsMDS.LoadEquipmentInfoByOP',
content: {
EquipmentNo: strEQP,
ds: []
},
success: function (data) {
if (callback)
callback(data);
}
});
}
function prepareParameters(para) {
para.qcResult = calculateTotalQCResult(para.eqpQcListDetail);
for (var n in para.eqpQcListDetail) {
para.eqpQcListDetail[n].D01 = para.eqpQcListDetail[n].InputValue;
}
}
function inputValueCorrect(inputVal, item) {
if (inputVal == '') return true;
if (inputVal == null) return true;
return checkInputValueCorrect(inputVal, item);
}
function showErrorIcon(item) {
var show = false;
//提示訊息
if (item.QCTYPE == 2) {
show = (item.QCResult != 0);
} else {//其他
show = !inputValueCorrect(item.InputValue, item)
if (item.INPUTDATACOUNT >= 2) show |= !inputValueCorrect(item.D02, item)
if (item.INPUTDATACOUNT >= 3) show |= !inputValueCorrect(item.D03, item)
if (item.INPUTDATACOUNT >= 4) show |= !inputValueCorrect(item.D04, item)
if (item.INPUTDATACOUNT >= 5) show |= !inputValueCorrect(item.D05, item)
if (item.INPUTDATACOUNT >= 6) show |= !inputValueCorrect(item.D06, item)
if (item.INPUTDATACOUNT >= 7) show |= !inputValueCorrect(item.D07, item)
if (item.INPUTDATACOUNT >= 8) show |= !inputValueCorrect(item.D08, item)
if (item.INPUTDATACOUNT >= 9) show |= !inputValueCorrect(item.D09, item)
if (item.INPUTDATACOUNT >= 10) show |= !inputValueCorrect(item.D10, item)
}
//給QCResult 附值
if (show) {
item.QCResult = 1;
}
return show;
}
function showCorrectIcon(item) {
var show = false;
//提示訊息
if (item.QCTYPE == 2) {
show = (item.QCResult == 0);
} else {//其他
if (allFieldsArefilled(item)) {
show = checkQCResult(item);
}
}
//給QCResult 附值
if (show) {
item.QCResult = 0;
} else if (!showErrorIcon(item)){
item.QCResult = -1;
}
return show;
}
function allFieldsArefilled(item) {
var result = (item.InputValue != '' && item.InputValue != null);
if (item.INPUTDATACOUNT >= 2) result &= (item.D02 != '' && item.D02 != null);
if (item.INPUTDATACOUNT >= 3) result &= (item.D03 != '' && item.D03 != null);
if (item.INPUTDATACOUNT >= 4) result &= (item.D04 != '' && item.D04 != null);
if (item.INPUTDATACOUNT >= 5) result &= (item.D05 != '' && item.D05 != null);
if (item.INPUTDATACOUNT >= 6) result &= (item.D06 != '' && item.D06 != null);
if (item.INPUTDATACOUNT >= 7) result &= (item.D07 != '' && item.D07 != null);
if (item.INPUTDATACOUNT >= 8) result &= (item.D08 != '' && item.D08 != null);
if (item.INPUTDATACOUNT >= 9) result &= (item.D09 != '' && item.D09 != null);
if (item.INPUTDATACOUNT >= 10) result &= (item.D10 != '' && item.D10 != null);
return result;
}
function checkQCResult(item) {
var result = checkInputValueCorrect(item.InputValue, item);
if (item.INPUTDATACOUNT >= 2) result &= checkInputValueCorrect(item.D02, item);
if (item.INPUTDATACOUNT >= 3) result &= checkInputValueCorrect(item.D03, item);
if (item.INPUTDATACOUNT >= 4) result &= checkInputValueCorrect(item.D04, item);
if (item.INPUTDATACOUNT >= 5) result &= checkInputValueCorrect(item.D05, item);
if (item.INPUTDATACOUNT >= 6) result &= checkInputValueCorrect(item.D06, item);
if (item.INPUTDATACOUNT >= 7) result &= checkInputValueCorrect(item.D07, item);
if (item.INPUTDATACOUNT >= 8) result &= checkInputValueCorrect(item.D08, item);
if (item.INPUTDATACOUNT >= 9) result &= checkInputValueCorrect(item.D09, item);
if (item.INPUTDATACOUNT >= 10) result &= checkInputValueCorrect(item.D10, item);
return result;
}
function checkInputValueCorrect(inputVal, item) {
switch (item.QCTYPE) {
case 0:
//標準值
if (inputVal == item.STDVALUE) {
return true;
}
break;
case 1:
//區間
let inputValue = parseInt(inputVal, 10);
let max = parseInt(item.MAXIVALUE, 10);
let min = parseInt(item.MINIVALUE, 10);
if (inputValue <= max) {
if (inputValue >= min) {
return true;
}
}
break;
case 2:
//顯示訊息
return (item.qcResult==0);
break;
case 3:
//輸入資料
if (inputVal != undefined && inputVal != '') {
return true;
}
break;
}
return false;
}
function initialDialogParameters(dialog) {
dialog.equipmentNoList = options.equipmentNoList;
dialog.equipmentNo = options.EquipmentNo;
dialog.equipmentType = "";
dialog.equipmentName = "";
dialog.qcListNo = "";
dialog.qcListName = "";
dialog.LotSerial = (options.LotSerial) ? options.LotSerial : "";
dialog.LogGroupSerial = (options.LogGroupSerial) ? options.LogGroupSerial : "";
dialog.callByCheckIn = (options.callByCheckIn) ? options.callByCheckIn : false;
dialog.eqpQcListDetail = [];
dialog.qCListSerial = "";
dialog.qcResult = -999;
dialog.description = "";
dialog.creator = config.cache.account;
dialog.unValidAction = -999;
dialog.expressionColQty = 1;
dialog.qcTaskNo = "";
dialog.inspType = -999;
}
function initialQcListDetail(qcListDetail, qCListSerial) {
for (var n in qcListDetail) {
qcListDetail[n]['QCListSerial'] = qCListSerial;
qcListDetail[n]['QCResult'] = (qcListDetail[n]['QCTYPE'] == 2) ? 0 : -1;
qcListDetail[n]['InputValue'] = "";
}
return qcListDetail
}
function initialExpressionColQty(qcListDetail) {
var result = 1;
for (var n in qcListDetail) {
if (qcListDetail[n]['INPUTDATACOUNT'] > result) {
result = qcListDetail[n]['INPUTDATACOUNT'];
}
}
return result
}
function calculateTotalQCResult(eqpQcListDetail) {
for (var n in eqpQcListDetail) {
if (eqpQcListDetail[n]['QCResult'] == -1) return -1
}
for (var n in eqpQcListDetail) {
if (eqpQcListDetail[n]['QCResult'] == 1) return 1
}
return 0;
}
function getQCListSerialLeadString(qcListNo) {
const today = new Date();
var mm = '' + (today.getMonth() + 1);
var dd = '' + today.getDate();
var yy = today.getFullYear().toString().slice(-2);
var result = qcListNo + yy + padStart(mm, 2, '0') + padStart(dd, 2, '0');
return result
}
function padStart(string, targetLength, padString = ' ') {
return (Array(targetLength).join(padString) + string)
.slice(-targetLength)
}
function getMachineChecklist(uri, content, callback) {
$MMWService.sendToMESSrv_Multi({
uri: uri,
content: content,
success: function (data) {
if (callback) callback(data);
}
});
}
function getQCList(equipment, callByCheckIn, callback) {
//移除EAI 架構直接呼叫KC
var uri = [];
var content = [];
//待點檢
uri.push("kcWIP.clsLot.LoadWaitQCListData");
content.push({
EquipmentNo: equipment,
CallByCheckIn: callByCheckIn
});
//補點檢
if (!callByCheckIn) {
uri.push("kcWIP.clsLot.LoadReQCListData");
content.push({
EquipmentNo: equipment
});
}
$MMWService.sendToMESSrv_Multi({
uri: uri,
content: content,
success: function (data) {
data = JSON.parse(data.ResultJson);
if (Object.keys(data).length > 0) {
callback(data);
}
}
});
}
function addWIPEQPQCListLog(para, callback) {
//移除EAI 架構直接呼叫KC
var uri = [];
var content = [];
//待點檢
uri.push("kcWIP.clsWIP.AddWIPEQPQCListLog");
content.push({
QCListSerial: para.qCListSerial,//ok
EquipmentNo: para.equipmentNo,//ok
QCListNo: para.qcListNo,//ok
LotSerial: para.LotSerial,
LogGroupSerial: para.LogGroupSerial,
QCResult: para.qcResult,
Description: para.description,
Creator: para.creator,
//CreateDate: para.createDate,
UnValidAction: para.unValidAction,
dtQCListDetail: para.eqpQcListDetail,
ExpressionColQty: para.expressionColQty,
QCTaskNo: para.qcTaskNo,
InspType: para.inspType
});
$MMWService.sendToMESSrv_Multi({
uri: uri,
content: content,
success: function (data) {
if (callback)
callback(data);
}
});
}
openDialog();
}
}]);
});