c hw meas.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. var result = {
  2. "result": true,
  3. "data": {}
  4. };
  5. var hw_measurement = Things["connNIITKDLibrary"].getIdWork({
  6. idWork: task_id /* STRING */
  7. });
  8. if (hw_measurement.indexOf("nameDevice") >= 0) {
  9. hw_measurement = JSON.parse(hw_measurement);
  10. var work_info = Things["2050MeasurementsLibrary"].get_work_info({
  11. work_name: work_id /* STRING */
  12. });
  13. var id = work_info.work_id;
  14. var dk = work_info.dk;
  15. var measurement = Things["2050MeasurementsLibrary"].get_mearurement_from_asusg_dev({
  16. work_id: id /* STRING */,
  17. dk: dk /* STRING */
  18. });
  19. logger.info("measurement_stage " + measurement_stage);
  20. var stageNumber = measurement_stage;
  21. stageNumber = stageNumber*1;
  22. var stage = "";
  23. switch (stageNumber) {
  24. case 0:
  25. stage = "До ремонта";
  26. break;
  27. case 1:
  28. stage = "Контрольный";
  29. break;
  30. case 2:
  31. stage = "После ремонта";
  32. break;
  33. default:
  34. throw new Error('Некорректно указан код этапа');
  35. }
  36. //var result = {"asd": hw_measurement[0].parameters[0].nameMeasuringUnit};
  37. //var arr = [];
  38. result.data.hw_measurements_status = "received";
  39. result.data.measurements = [];
  40. for (var i = 0; i < measurement.array.length; i++) {
  41. var characteristic_name = measurement.array[i].characteristic_name;
  42. var measurement_name = measurement.array[i].measurement_name;
  43. for (var j = 0; j < hw_measurement[0].parameters.length; j++) {
  44. if (stage === measurement.array[i].measurement_stage) {
  45. if (characteristic_name === hw_measurement[0].parameters[j].nameMeasuringUnit && measurement_name.indexOf(hw_measurement[0].parameters[j].name) >= 0) {
  46. var JSON = new Object();
  47. JSON.measurement_id = measurement.array[i].measurement_id;
  48. JSON.characteristic_id = measurement.array[i].characteristic_id;
  49. JSON.measurement_stage = measurement_stage;
  50. JSON.measurement_value = hw_measurement[0].parameters[j].value;
  51. JSON.is_hw_measurement = true;
  52. JSON.comment = hw_measurement[0].nameDevice + " " + hw_measurement[0].serialNum;
  53. JSON.equipement_name = hw_measurement[0].nameDevice + " " + hw_measurement[0].serialNum;
  54. var measurements_list = JSON;
  55. // var result = measurements_list;
  56. var writeWork = Things["2050MeasurementsLibrary"].write_work_measurements({
  57. work_id: work_id /* STRING */ ,
  58. measurements_list: measurements_list /* JSON */
  59. });
  60. if (writeWork.result && writeWork.result === true) {
  61. var measurements = Things["2050MeasurementsLibrary"].get_work_measurements({
  62. work_id: work_id /* STRING */
  63. });
  64. for (var z = 0; z < measurements.data.length; z++) {
  65. 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) {
  66. result.data.measurements.push(measurements.data[z]);
  67. }
  68. }
  69. } else {
  70. result = writeWork;
  71. }
  72. //arr.push(measurement.array[i]);
  73. //continue;
  74. } else if (characteristic_name === hw_measurement[0].parameters[j].name) {
  75. var JSON = new Object();
  76. JSON.measurement_id = measurement.array[i].measurement_id;
  77. JSON.characteristic_id = measurement.array[i].characteristic_id;
  78. JSON.measurement_stage = measurement_stage;
  79. JSON.measurement_value = hw_measurement[0].parameters[j].value;
  80. JSON.is_hw_measurement = true;
  81. JSON.comment = hw_measurement[0].nameDevice + " " + hw_measurement[0].serialNum;
  82. JSON.equipement_name = hw_measurement[0].nameDevice + " " + hw_measurement[0].serialNum;
  83. var measurements_list = JSON;
  84. // var result = measurements_list;
  85. var writeWork = Things["2050MeasurementsLibrary"].write_work_measurements({
  86. work_id: work_id /* STRING */ ,
  87. measurements_list: measurements_list /* JSON */
  88. });
  89. if (writeWork.result && writeWork.result === true) {
  90. var measurements = Things["2050MeasurementsLibrary"].get_work_measurements({
  91. work_id: work_id /* STRING */
  92. });
  93. for (var z = 0; z < measurements.data.length; z++) {
  94. if (measurement_stage == measurements.data[z].measurement_stage) {
  95. if (characteristic_name === hw_measurement[0].parameters[j].nameMeasuringUnit && measurements.data[z].measurement_name.indexOf(hw_measurement[0].parameters[j].name) >= 0) {
  96. result.data.measurements.push(measurements.data[z]);
  97. //continue;
  98. } else if (characteristic_name === hw_measurement[0].parameters[j].name) {
  99. result.data.measurements.push(measurements.data[z]);
  100. }
  101. }
  102. }
  103. } else {
  104. result = writeWork;
  105. }
  106. //arr.push(measurement.array[i]);
  107. }
  108. }
  109. }
  110. }
  111. } else {
  112. result = {
  113. "result": false,
  114. "Error": {
  115. "code":0001,
  116. "description": hw_measurement
  117. }
  118. };
  119. }