123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- var result = {
- "result": true,
- "data": {}
- };
- var hw_measurement = Things["connNIITKDLibrary"].getIdWork({
- idWork: task_id /* STRING */
- });
- if (hw_measurement.indexOf("nameDevice") >= 0) {
- hw_measurement = JSON.parse(hw_measurement);
- var work_info = Things["2050MeasurementsLibrary"].get_work_info({
- work_name: work_id /* STRING */
- });
- var id = work_info.work_id;
- var dk = work_info.dk;
- var measurement = Things["2050MeasurementsLibrary"].get_mearurement_from_asusg_dev({
- work_id: id /* STRING */,
- dk: dk /* STRING */
- });
- logger.info("measurement_stage " + measurement_stage);
- var stageNumber = measurement_stage;
- stageNumber = stageNumber*1;
- var stage = "";
- switch (stageNumber) {
- case 0:
- stage = "До ремонта";
- break;
- case 1:
- stage = "Контрольный";
- break;
- case 2:
- stage = "После ремонта";
- break;
- default:
- throw new Error('Некорректно указан код этапа');
- }
- //var result = {"asd": hw_measurement[0].parameters[0].nameMeasuringUnit};
- //var arr = [];
- result.data.hw_measurements_status = "received";
- result.data.measurements = [];
- for (var i = 0; i < measurement.array.length; i++) {
- var characteristic_name = measurement.array[i].characteristic_name;
- var measurement_name = measurement.array[i].measurement_name;
- for (var j = 0; j < hw_measurement[0].parameters.length; j++) {
- if (stage === measurement.array[i].measurement_stage) {
- if (characteristic_name === hw_measurement[0].parameters[j].nameMeasuringUnit && measurement_name.indexOf(hw_measurement[0].parameters[j].name) >= 0) {
- var JSON = new Object();
- JSON.measurement_id = measurement.array[i].measurement_id;
- JSON.characteristic_id = measurement.array[i].characteristic_id;
- JSON.measurement_stage = measurement_stage;
- JSON.measurement_value = hw_measurement[0].parameters[j].value;
- JSON.is_hw_measurement = true;
- JSON.comment = hw_measurement[0].nameDevice + " " + hw_measurement[0].serialNum;
- JSON.equipement_name = hw_measurement[0].nameDevice + " " + hw_measurement[0].serialNum;
- var measurements_list = JSON;
- // var result = measurements_list;
- var writeWork = Things["2050MeasurementsLibrary"].write_work_measurements({
- work_id: work_id /* STRING */ ,
- measurements_list: measurements_list /* JSON */
- });
- if (writeWork.result && writeWork.result === true) {
- var measurements = Things["2050MeasurementsLibrary"].get_work_measurements({
- work_id: work_id /* STRING */
- });
- for (var z = 0; z < measurements.data.length; z++) {
- if (characteristic_name === hw_measurement[0].parameters[j].nameMeasuringUnit && measurements.data[z].measurement_name.indexOf(hw_measurement[0].parameters[j].name) >= 0 && measurement_stage == measurements.data[z].measurement_stage) {
- result.data.measurements.push(measurements.data[z]);
- }
- }
- } else {
- result = writeWork;
- }
- //arr.push(measurement.array[i]);
- //continue;
- } else if (characteristic_name === hw_measurement[0].parameters[j].name) {
- var JSON = new Object();
- JSON.measurement_id = measurement.array[i].measurement_id;
- JSON.characteristic_id = measurement.array[i].characteristic_id;
- JSON.measurement_stage = measurement_stage;
- JSON.measurement_value = hw_measurement[0].parameters[j].value;
- JSON.is_hw_measurement = true;
- JSON.comment = hw_measurement[0].nameDevice + " " + hw_measurement[0].serialNum;
- JSON.equipement_name = hw_measurement[0].nameDevice + " " + hw_measurement[0].serialNum;
- var measurements_list = JSON;
- // var result = measurements_list;
- var writeWork = Things["2050MeasurementsLibrary"].write_work_measurements({
- work_id: work_id /* STRING */ ,
- measurements_list: measurements_list /* JSON */
- });
- if (writeWork.result && writeWork.result === true) {
- var measurements = Things["2050MeasurementsLibrary"].get_work_measurements({
- work_id: work_id /* STRING */
- });
- for (var z = 0; z < measurements.data.length; z++) {
- if (measurement_stage == measurements.data[z].measurement_stage) {
- if (characteristic_name === hw_measurement[0].parameters[j].nameMeasuringUnit && measurements.data[z].measurement_name.indexOf(hw_measurement[0].parameters[j].name) >= 0) {
- result.data.measurements.push(measurements.data[z]);
- //continue;
- } else if (characteristic_name === hw_measurement[0].parameters[j].name) {
- result.data.measurements.push(measurements.data[z]);
- }
- }
- }
- } else {
- result = writeWork;
- }
- //arr.push(measurement.array[i]);
- }
- }
- }
- }
- } else {
- result = {
- "result": false,
- "Error": {
- "code":0001,
- "description": hw_measurement
- }
- };
- }
|