1226 lines
		
	
	
		
			50 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			1226 lines
		
	
	
		
			50 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
let baja_subscribe_device_callback_func; //設定BQL訂閱之後要回傳的Function
 | 
						||
let baja_subscribe_end_device_callback_func; //設定BQL訂閱結束之後要回傳的Function
 | 
						||
//let baja_my_user_account_func;    //取得帳號資料要回傳的Function
 | 
						||
var ordPath; //當前點選選單的tag,用來抓出設備路徑,例如:旅館棟->H,消防偵煙器->F3
 | 
						||
 | 
						||
let baja_subscribe_alarm_callback_func; //設定 alarm BQL訂閱之後要回傳的Function
 | 
						||
let baja_subscribe_end_alarm_callback_func; //設定 alarm BQL訂閱結束之後要回傳的Function
 | 
						||
var ordPathForAlarm; //當前點選選單的tag,用來抓出alarm路徑
 | 
						||
 | 
						||
let baja_subscribe_electricmeter_callback_func;
 | 
						||
let baja_subscribe_end_electricmeter_callback_func;
 | 
						||
var ordPathForElectricmeter;
 | 
						||
 | 
						||
var startPageLoading; // 開始 loading
 | 
						||
var endPageLoading; // 開始 loading
 | 
						||
//window.baja = null;
 | 
						||
//require(['baja!'], function (baja) {
 | 
						||
//    window.baja = baja;
 | 
						||
//})
 | 
						||
 | 
						||
window.tolSubList = [];
 | 
						||
 | 
						||
var user_name = "";
 | 
						||
 | 
						||
class subscriptionDevices {
 | 
						||
  constructor() {
 | 
						||
    this.ordPath = {};
 | 
						||
    this.changeCallback = null;
 | 
						||
    this.changeEndCallback = null;
 | 
						||
  }
 | 
						||
 | 
						||
  setSubscribeDevicesByBql = function (tempOrdPath) {
 | 
						||
    this.ordPath = tempOrdPath;
 | 
						||
    this.BajaSubscribeDevicesByBql();
 | 
						||
  };
 | 
						||
 | 
						||
  setSubscribeDevicesCallBack = function (callBackFunc) {
 | 
						||
    // console.log(callBackFunc)
 | 
						||
    if (callBackFunc != undefined && callBackFunc != null) {
 | 
						||
      this.changeCallback = callBackFunc;
 | 
						||
    }
 | 
						||
  };
 | 
						||
  // BQL訂閱結束回傳的Function
 | 
						||
  setSubscribeDeviceEndCallBack = function (callBackFunc) {
 | 
						||
    if (callBackFunc != undefined && callBackFunc != null) {
 | 
						||
      this.changeEndCallback = callBackFunc;
 | 
						||
    }
 | 
						||
  };
 | 
						||
 | 
						||
  BajaSubscribeDevicesByBql = function () {
 | 
						||
    let _this = this;
 | 
						||
    require(["baja!"], function (baja) {
 | 
						||
      console.log("進入Function 準備執行BQL訂閱");
 | 
						||
      startPageLoading ? startPageLoading() : "";
 | 
						||
      var init_start = new Date(Date.now());
 | 
						||
      var sub = new baja.Subscriber();
 | 
						||
 | 
						||
      sub.attach(
 | 
						||
        "changed",
 | 
						||
        function (prop) {
 | 
						||
          if (prop.getName() === "out") {
 | 
						||
            var out_value = this.getOutDisplay();
 | 
						||
            var target_device_number = this.$parent
 | 
						||
              .getDisplayName()
 | 
						||
              .split("_")
 | 
						||
              .slice(0, 5)
 | 
						||
              .join("_");
 | 
						||
            var point_name = this.getDisplayName();
 | 
						||
 | 
						||
            //依據Facets判斷回傳的內容值為何
 | 
						||
            var facets_split = this.getFacets1().$cEncStr.split("|");
 | 
						||
            var facets_arr = [];
 | 
						||
            facets_split.forEach(function (item, index) {
 | 
						||
              facets_arr.push(item.split("=s:"));
 | 
						||
            });
 | 
						||
 | 
						||
            var facets = facets_arr.reduce(
 | 
						||
              (obj, cur) => ({ ...obj, [cur[0]]: cur[1] }),
 | 
						||
              {}
 | 
						||
            );
 | 
						||
 | 
						||
            var point_out_split = this.getOutDisplay().split(" ");
 | 
						||
 | 
						||
            let key = Object.keys(facets).find(
 | 
						||
              (k) => facets[k] === point_out_split[0]
 | 
						||
            );
 | 
						||
 | 
						||
            if (key == undefined) {
 | 
						||
              key = point_out_split[0];
 | 
						||
            }
 | 
						||
 | 
						||
            var modify_target_device = {
 | 
						||
              device_number: target_device_number ? target_device_number : null,
 | 
						||
              device_number_full: this.$parent.getSlotPath().$names.join("_"),
 | 
						||
              point_name: point_name ? point_name : null,
 | 
						||
              value: key,
 | 
						||
            };
 | 
						||
            if (
 | 
						||
              _this.changeCallback != undefined &&
 | 
						||
              _this.changeCallback != null
 | 
						||
            ) {
 | 
						||
              _this.changeCallback(modify_target_device, true); //第2參數用在平面圖,刷新畫面
 | 
						||
            }
 | 
						||
          }
 | 
						||
        },
 | 
						||
        function (err) {
 | 
						||
          console.log(err);
 | 
						||
        }
 | 
						||
      );
 | 
						||
 | 
						||
      //使用bql語法
 | 
						||
      // var building_tag = "H";
 | 
						||
      // var system_tag = "M10";
 | 
						||
      // baja.Ord.make(`ip:greencloud.fic.com.tw|foxs:|station:|slot:/Arena/${building_tag}/${system_tag}|bql:select name, displayname, slotPath, out.value, out from control:ControlPoint`)
 | 
						||
      console.log(
 | 
						||
        `local:|foxs:${port}|station:|slot:/${_this.ordPath.area_tag}/${_this.ordPath.building_tag
 | 
						||
        }/${_this.ordPath.system_tag}/${_this.ordPath.name_tag}${_this.ordPath.flo_tag ? `/${_this.ordPath.flo_tag}` : ""
 | 
						||
        }|bql:select name, displayname, slotPath, out.value, out, facets  from control:ControlPoint`
 | 
						||
      );
 | 
						||
      baja.Ord.make(
 | 
						||
        `local:|foxs:${port}|station:|slot:/${_this.ordPath.area_tag}/${_this.ordPath.building_tag
 | 
						||
        }/${_this.ordPath.system_tag}/${_this.ordPath.name_tag}${_this.ordPath.flo_tag ? `/${_this.ordPath.flo_tag}` : ""
 | 
						||
        }|bql:select name, displayname, slotPath, out.value, out, facets  from control:ControlPoint`
 | 
						||
      ).get(function (table) {
 | 
						||
        var tableStart, tableFinish;
 | 
						||
        var subStart, subFinish;
 | 
						||
        var component_index = 0;
 | 
						||
        var total_component_index = 0;
 | 
						||
        var totalTargetDevice = [];
 | 
						||
        var readBqlFinish = new Date(Date.now());
 | 
						||
        // $("#readPath-finish-timestamp").html(readBqlFinish.toISOString());
 | 
						||
        // $("#readPath-finish-time").html((readBqlFinish.getTime() - init_start.getTime()) / 1000 + "sec");
 | 
						||
        console.log(
 | 
						||
          "讀取路徑完成-花費時間",
 | 
						||
          (readBqlFinish.getTime() - init_start.getTime()) / 1000 + "sec"
 | 
						||
        );
 | 
						||
        table.cursor({
 | 
						||
          before: function () {
 | 
						||
            totalTargetDevice = [];
 | 
						||
            tableStart = new Date(Date.now());
 | 
						||
            $("#table-start-timestamp").html(tableStart.toISOString());
 | 
						||
          },
 | 
						||
          each: function (item, index) {
 | 
						||
            if (index < 1) {
 | 
						||
              subStart = new Date(Date.now());
 | 
						||
              $("#sub-start").html(subStart.toISOString());
 | 
						||
            }
 | 
						||
            $("#sub-number").html(index + 1);
 | 
						||
            total_component_index = index;
 | 
						||
 | 
						||
            var target_device_number_split =
 | 
						||
              this.getDisplay("slotPath").split("/");
 | 
						||
            var target_device_number = target_device_number_split[8];
 | 
						||
            //console.log(target_device_number);
 | 
						||
            var point_name = this.getDisplay("name");
 | 
						||
            var facets = this.getDisplay("facets");
 | 
						||
 | 
						||
            //依據Facets判斷回傳的內容值為何
 | 
						||
            var facets_split = facets.split(",");
 | 
						||
            var facets_arr = [];
 | 
						||
            facets_split.forEach(function (item, index) {
 | 
						||
              facets_arr.push(item.split("="));
 | 
						||
            });
 | 
						||
 | 
						||
            facets = facets_arr.reduce(
 | 
						||
              (obj, cur) => ({ ...obj, [cur[0]]: cur[1] }),
 | 
						||
              {}
 | 
						||
            );
 | 
						||
 | 
						||
            var point_out_split = this.getDisplay("out").split(" ");
 | 
						||
 | 
						||
            let key = Object.keys(facets).find(
 | 
						||
              (k) => facets[k] === point_out_split[0]
 | 
						||
            );
 | 
						||
 | 
						||
            if (key == undefined) {
 | 
						||
              key = point_out_split[0];
 | 
						||
            }
 | 
						||
 | 
						||
            var modify_target_device = {
 | 
						||
              device_number: target_device_number ? target_device_number : null,
 | 
						||
              device_number_full: this.getDisplay("slotPath")
 | 
						||
                .split("slot:")[1]
 | 
						||
                .split("/")
 | 
						||
                .slice(1, -1)
 | 
						||
                .join("_"),
 | 
						||
              point_name: point_name ? point_name : null,
 | 
						||
              value: key,
 | 
						||
            };
 | 
						||
            totalTargetDevice.push(modify_target_device);
 | 
						||
            //取得component當下就更新設備點位
 | 
						||
            // if (_this.changeCallback != undefined && _this.changeCallback != null) {
 | 
						||
            //     _this.changeCallback(modify_target_device);
 | 
						||
            // }
 | 
						||
            if (pageAct.sysSubTag === "L1") {
 | 
						||
              if (
 | 
						||
                point_name === "SSC" ||
 | 
						||
                point_name === "TRIP" ||
 | 
						||
                point_name === "ONOFF"
 | 
						||
              ) {
 | 
						||
                if (
 | 
						||
                  _this.changeCallback != undefined &&
 | 
						||
                  _this.changeCallback != null
 | 
						||
                ) {
 | 
						||
                  _this.changeCallback(modify_target_device, true); //第2參數用在平面圖,刷新畫面
 | 
						||
                  baja.Ord.make(
 | 
						||
                    `local:|foxs:${port}|station:|` +
 | 
						||
                      this.getDisplay("slotPath")
 | 
						||
                  )
 | 
						||
                    .get()
 | 
						||
                    .then(function (component) {
 | 
						||
                      // console.log("component",component)
 | 
						||
                      component_index++;
 | 
						||
                      var target_device_number = component.$parent
 | 
						||
                        .getDisplayName()
 | 
						||
                        .split("_")
 | 
						||
                        .slice(0, 5)
 | 
						||
                        .join("_");
 | 
						||
 | 
						||
                      var out_value = component.getOutDisplay();
 | 
						||
                      var target_device_number = component.$parent
 | 
						||
                        .getDisplayName()
 | 
						||
                        .split("_")
 | 
						||
                        .slice(0, 5)
 | 
						||
                        .join("_");
 | 
						||
                      var point_name = component.getDisplayName();
 | 
						||
                      //依據Facets判斷回傳的內容值為何
 | 
						||
                      var facets_split = component
 | 
						||
                        .getFacets1()
 | 
						||
                        .$cEncStr.split("|");
 | 
						||
                      var facets_arr = [];
 | 
						||
                      facets_split.forEach(function (item, index) {
 | 
						||
                        facets_arr.push(item.split("=s:"));
 | 
						||
                      });
 | 
						||
 | 
						||
                      var facets = facets_arr.reduce(
 | 
						||
                        (obj, cur) => ({ ...obj, [cur[0]]: cur[1] }),
 | 
						||
                        {}
 | 
						||
                      );
 | 
						||
 | 
						||
                      var point_out_split = component
 | 
						||
                        .getOutDisplay()
 | 
						||
                        .split(" ");
 | 
						||
 | 
						||
                      let key = Object.keys(facets).find(
 | 
						||
                        (k) => facets[k] === point_out_split[0]
 | 
						||
                      );
 | 
						||
 | 
						||
                      if (key == undefined) {
 | 
						||
                        key = point_out_split[0];
 | 
						||
                      }
 | 
						||
 | 
						||
                      var modify_target_device = {
 | 
						||
                        device_number: target_device_number
 | 
						||
                          ? target_device_number
 | 
						||
                          : null,
 | 
						||
                        device_number_full: component.$parent
 | 
						||
                          .getSlotPath()
 | 
						||
                          .$names.join("_"),
 | 
						||
                        point_name: point_name ? point_name : null,
 | 
						||
                        value: key,
 | 
						||
                      };
 | 
						||
 | 
						||
                      if (pageAct.sysSubTag === "L1") {
 | 
						||
                        if (
 | 
						||
                          point_name === "SSC" ||
 | 
						||
                          point_name === "TRIP" ||
 | 
						||
                          point_name === "ONOFF"
 | 
						||
                        ) {
 | 
						||
                          if (
 | 
						||
                            _this.changeCallback != undefined &&
 | 
						||
                            _this.changeCallback != null
 | 
						||
                          ) {
 | 
						||
                            _this.changeCallback(modify_target_device, true); //第2參數用在平面圖,刷新畫面
 | 
						||
                          }
 | 
						||
                        }
 | 
						||
                      } else {
 | 
						||
                        if (
 | 
						||
                          _this.changeCallback != undefined &&
 | 
						||
                          _this.changeCallback != null
 | 
						||
                        ) {
 | 
						||
                          _this.changeCallback(modify_target_device, true); //第2參數用在平面圖,刷新畫面
 | 
						||
                        }
 | 
						||
                      }
 | 
						||
 | 
						||
                      // //依據Facets判斷回傳的內容值為何
 | 
						||
                      // var facets_split = component.getFacets1().$cEncStr.split('|');
 | 
						||
                      // var facets_arr = [];
 | 
						||
                      // facets_split.forEach(function (item, index) {
 | 
						||
                      //   facets_arr.push(item.split('=s:'));
 | 
						||
                      // });
 | 
						||
 | 
						||
                      // var facets = facets_arr.reduce((obj, cur) => ({ ...obj, [cur[0]]: cur[1] }), {})
 | 
						||
 | 
						||
                      // var point_out_split = component.getOutDisplay().split(' ');
 | 
						||
 | 
						||
                      // let key = Object.keys(facets).find(k => facets[k] === point_out_split[0]);
 | 
						||
 | 
						||
                      // if (key == undefined) {
 | 
						||
                      //   key = point_out_split[0];
 | 
						||
                      // }
 | 
						||
 | 
						||
                      // var modify_target_device = {
 | 
						||
                      //   "device_number": target_device_number ? target_device_number : null,
 | 
						||
                      //   "point_name": point_name ? point_name : null,
 | 
						||
                      //   "value": key
 | 
						||
                      // }
 | 
						||
 | 
						||
                      // //取得component當下就更新設備點位
 | 
						||
                      // if (baja_subscribe_device_callback_func != undefined && baja_subscribe_device_callback_func != null) {
 | 
						||
                      //   if (component_index == total_component_index) {
 | 
						||
                      //     baja_subscribe_device_callback_func(modify_target_device, true);
 | 
						||
                      //   }
 | 
						||
                      //   else {
 | 
						||
                      //     baja_subscribe_device_callback_func(modify_target_device);
 | 
						||
                      //   }
 | 
						||
                      // }
 | 
						||
 | 
						||
                      if (pageAct.sysSubTag === "L1") {
 | 
						||
                        if (
 | 
						||
                          point_name === "SSC" ||
 | 
						||
                          point_name === "TRIP" ||
 | 
						||
                          point_name === "ONOFF"
 | 
						||
                        ) {
 | 
						||
                          sub.subscribe({
 | 
						||
                            comps: component,
 | 
						||
                          });
 | 
						||
                        }
 | 
						||
                      } else {
 | 
						||
                        sub.subscribe({
 | 
						||
                          comps: component,
 | 
						||
                        });
 | 
						||
                      }
 | 
						||
 | 
						||
                      // sub.subscribe({
 | 
						||
                      //     comps: component,
 | 
						||
                      // });
 | 
						||
                      tolSubList.push(sub);
 | 
						||
                      subFinish = new Date(Date.now());
 | 
						||
                      $("#sub-end").html(subFinish.toISOString());
 | 
						||
                      $("#sub-time").html(
 | 
						||
                        (subFinish.getTime() - subStart.getTime()) / 1000 +
 | 
						||
                          "sec"
 | 
						||
                      );
 | 
						||
                      // console.log("訂閱完成時間", (subFinish.getTime() - subStart.getTime()) / 1000 + "sec");
 | 
						||
                    });
 | 
						||
                }
 | 
						||
              }
 | 
						||
            } else {
 | 
						||
              if (
 | 
						||
                _this.changeCallback != undefined &&
 | 
						||
                _this.changeCallback != null
 | 
						||
              ) {
 | 
						||
                _this.changeCallback(modify_target_device, true); //第2參數用在平面圖,刷新畫面
 | 
						||
                baja.Ord.make(
 | 
						||
                  `local:|foxs:${port}|station:|` + this.getDisplay("slotPath")
 | 
						||
                )
 | 
						||
                  .get()
 | 
						||
                  .then(function (component) {
 | 
						||
                    component_index++;
 | 
						||
                    var target_device_number = component.$parent
 | 
						||
                      .getDisplayName()
 | 
						||
                      .split("_")
 | 
						||
                      .slice(0, 5)
 | 
						||
                      .join("_");
 | 
						||
 | 
						||
                    var out_value = component.getOutDisplay();
 | 
						||
                    var target_device_number = component.$parent
 | 
						||
                      .getDisplayName()
 | 
						||
                      .split("_")
 | 
						||
                      .slice(0, 5)
 | 
						||
                      .join("_");
 | 
						||
                    var point_name = component.getDisplayName();
 | 
						||
                    //依據Facets判斷回傳的內容值為何
 | 
						||
                    var facets_split = component
 | 
						||
                      .getFacets1()
 | 
						||
                      .$cEncStr.split("|");
 | 
						||
                    var facets_arr = [];
 | 
						||
                    facets_split.forEach(function (item, index) {
 | 
						||
                      facets_arr.push(item.split("=s:"));
 | 
						||
                    });
 | 
						||
 | 
						||
                    var facets = facets_arr.reduce(
 | 
						||
                      (obj, cur) => ({ ...obj, [cur[0]]: cur[1] }),
 | 
						||
                      {}
 | 
						||
                    );
 | 
						||
 | 
						||
                    var point_out_split = component.getOutDisplay().split(" ");
 | 
						||
 | 
						||
                    let key = Object.keys(facets).find(
 | 
						||
                      (k) => facets[k] === point_out_split[0]
 | 
						||
                    );
 | 
						||
 | 
						||
                    if (key == undefined) {
 | 
						||
                      key = point_out_split[0];
 | 
						||
                    }
 | 
						||
 | 
						||
                    var modify_target_device = {
 | 
						||
                      device_number: target_device_number
 | 
						||
                        ? target_device_number
 | 
						||
                        : null,
 | 
						||
                      device_number_full: component.$parent
 | 
						||
                        .getSlotPath()
 | 
						||
                        .$names.join("_"),
 | 
						||
                      point_name: point_name ? point_name : null,
 | 
						||
                      value: key,
 | 
						||
                    };
 | 
						||
 | 
						||
                    if (pageAct.sysSubTag === "L1") {
 | 
						||
                      if (
 | 
						||
                        point_name === "SSC" ||
 | 
						||
                        point_name === "TRIP" ||
 | 
						||
                        point_name === "ONOFF"
 | 
						||
                      ) {
 | 
						||
                        if (
 | 
						||
                          _this.changeCallback != undefined &&
 | 
						||
                          _this.changeCallback != null
 | 
						||
                        ) {
 | 
						||
                          _this.changeCallback(modify_target_device, true); //第2參數用在平面圖,刷新畫面
 | 
						||
                        }
 | 
						||
                      }
 | 
						||
                    } else {
 | 
						||
                      if (
 | 
						||
                        _this.changeCallback != undefined &&
 | 
						||
                        _this.changeCallback != null
 | 
						||
                      ) {
 | 
						||
                        _this.changeCallback(modify_target_device, true); //第2參數用在平面圖,刷新畫面
 | 
						||
                      }
 | 
						||
                    }
 | 
						||
 | 
						||
                    // //依據Facets判斷回傳的內容值為何
 | 
						||
                    // var facets_split = component.getFacets1().$cEncStr.split('|');
 | 
						||
                    // var facets_arr = [];
 | 
						||
                    // facets_split.forEach(function (item, index) {
 | 
						||
                    //   facets_arr.push(item.split('=s:'));
 | 
						||
                    // });
 | 
						||
 | 
						||
                    // var facets = facets_arr.reduce((obj, cur) => ({ ...obj, [cur[0]]: cur[1] }), {})
 | 
						||
 | 
						||
                    // var point_out_split = component.getOutDisplay().split(' ');
 | 
						||
 | 
						||
                    // let key = Object.keys(facets).find(k => facets[k] === point_out_split[0]);
 | 
						||
 | 
						||
                    // if (key == undefined) {
 | 
						||
                    //   key = point_out_split[0];
 | 
						||
                    // }
 | 
						||
 | 
						||
                    // var modify_target_device = {
 | 
						||
                    //   "device_number": target_device_number ? target_device_number : null,
 | 
						||
                    //   "point_name": point_name ? point_name : null,
 | 
						||
                    //   "value": key
 | 
						||
                    // }
 | 
						||
 | 
						||
                    // //取得component當下就更新設備點位
 | 
						||
                    // if (baja_subscribe_device_callback_func != undefined && baja_subscribe_device_callback_func != null) {
 | 
						||
                    //   if (component_index == total_component_index) {
 | 
						||
                    //     baja_subscribe_device_callback_func(modify_target_device, true);
 | 
						||
                    //   }
 | 
						||
                    //   else {
 | 
						||
                    //     baja_subscribe_device_callback_func(modify_target_device);
 | 
						||
                    //   }
 | 
						||
                    // }
 | 
						||
 | 
						||
                    if (pageAct.sysSubTag === "L1") {
 | 
						||
                      if (
 | 
						||
                        point_name === "SSC" ||
 | 
						||
                        point_name === "TRIP" ||
 | 
						||
                        point_name === "ONOFF"
 | 
						||
                      ) {
 | 
						||
                        sub.subscribe({
 | 
						||
                          comps: component,
 | 
						||
                        });
 | 
						||
                      }
 | 
						||
                    } else {
 | 
						||
                      sub.subscribe({
 | 
						||
                        comps: component,
 | 
						||
                      });
 | 
						||
                    }
 | 
						||
 | 
						||
                    // sub.subscribe({
 | 
						||
                    //     comps: component,
 | 
						||
                    // });
 | 
						||
                    tolSubList.push(sub);
 | 
						||
                    subFinish = new Date(Date.now());
 | 
						||
                    $("#sub-end").html(subFinish.toISOString());
 | 
						||
                    $("#sub-time").html(
 | 
						||
                      (subFinish.getTime() - subStart.getTime()) / 1000 + "sec"
 | 
						||
                    );
 | 
						||
                    // console.log("訂閱完成時間", (subFinish.getTime() - subStart.getTime()) / 1000 + "sec");
 | 
						||
                  });
 | 
						||
              }
 | 
						||
            }
 | 
						||
          },
 | 
						||
          after: function () {
 | 
						||
            tableFinish = new Date(Date.now());
 | 
						||
            // $("#table-finish-timestamp").html(tableFinish.toISOString());
 | 
						||
            // $("#table-time").html((tableFinish.getTime() - tableStart.getTime()) / 1000 + "sec");
 | 
						||
            //取得component當下就更新設備點位
 | 
						||
            if (
 | 
						||
              _this.changeEndCallback != undefined &&
 | 
						||
              _this.changeEndCallback != null
 | 
						||
            ) {
 | 
						||
              _this.changeEndCallback(totalTargetDevice);
 | 
						||
            }
 | 
						||
            endPageLoading ? endPageLoading() : "";
 | 
						||
            console.log(
 | 
						||
              "表格完成時間",
 | 
						||
              (tableFinish.getTime() - tableStart.getTime()) / 1000 + "sec"
 | 
						||
            );
 | 
						||
          },
 | 
						||
          limit: -1,
 | 
						||
          offset: 0,
 | 
						||
        });
 | 
						||
      });
 | 
						||
    });
 | 
						||
  };
 | 
						||
}
 | 
						||
 | 
						||
//function subscriptionDevices() {
 | 
						||
//    // 用BQL的方式去訂閱
 | 
						||
//    this.setSubscribeDevicesByBql = function (tempOrdPath) {
 | 
						||
//        ordPath = tempOrdPath;
 | 
						||
//        BajaSubscribeDevicesByBql();
 | 
						||
//    };
 | 
						||
//    // BQL去訂閱回傳的Function
 | 
						||
//    this.setSubscribeDevicesCallBack = function (callBackFunc) {
 | 
						||
//        if (callBackFunc != undefined && callBackFunc != null) {
 | 
						||
//            baja_subscribe_device_callback_func = callBackFunc;
 | 
						||
//        }
 | 
						||
//    }
 | 
						||
//    // BQL訂閱結束回傳的Function
 | 
						||
//    this.setSubscribeDeviceEndCallBack = function (callBackFunc) {
 | 
						||
//        if (callBackFunc != undefined && callBackFunc != null) {
 | 
						||
//            baja_subscribe_end_device_callback_func = callBackFunc;
 | 
						||
//        }
 | 
						||
//    }
 | 
						||
 | 
						||
//}
 | 
						||
 | 
						||
function subscriptionAlarms() {
 | 
						||
  // 用BQL的方式去訂閱
 | 
						||
  this.setSubscribeAlarmsByBql = function (tempOrdPath) {
 | 
						||
    BajaSubscribeAlarmsByBql(tempOrdPath);
 | 
						||
  };
 | 
						||
  // BQL去訂閱回傳的Function
 | 
						||
  this.setSubscribeAlarmsCallBack = function (callBackFunc) {
 | 
						||
    if (callBackFunc != undefined && callBackFunc != null) {
 | 
						||
      baja_subscribe_alarm_callback_func = callBackFunc;
 | 
						||
    }
 | 
						||
  };
 | 
						||
  // BQL訂閱結束回傳的Function
 | 
						||
  this.setSubscribeAlarmEndCallBack = function (callBackFunc) {
 | 
						||
    if (callBackFunc != undefined && callBackFunc != null) {
 | 
						||
      baja_subscribe_end_alarm_callback_func = callBackFunc;
 | 
						||
    }
 | 
						||
  };
 | 
						||
}
 | 
						||
 | 
						||
function subscriptionElectricmeter() {
 | 
						||
  // 用BQL的方式去訂閱
 | 
						||
  this.setSubscribeElectricmeterByBql = function (tempOrdPath) {
 | 
						||
    if (tempOrdPath.devicePath?.includes("/")) {
 | 
						||
      let newDevPath = [];
 | 
						||
      for (var tag of tempOrdPath.devicePath?.split("/")) {
 | 
						||
        if (!isNaN(parseInt(tag.slice(0, 1)))) {
 | 
						||
          tag = "$3" + tag;
 | 
						||
        }
 | 
						||
        newDevPath.push(tag);
 | 
						||
      }
 | 
						||
      tempOrdPath.devicePath = newDevPath.join("/");
 | 
						||
    }
 | 
						||
    BajaSubscribeElectricmeterByBql(tempOrdPath);
 | 
						||
  };
 | 
						||
  // BQL去訂閱回傳的Function
 | 
						||
  this.setSubscribeElectricmeterCallBack = function (callBackFunc) {
 | 
						||
    if (callBackFunc != undefined && callBackFunc != null) {
 | 
						||
      baja_subscribe_electricmeter_callback_func = callBackFunc;
 | 
						||
    }
 | 
						||
  };
 | 
						||
  // BQL訂閱結束回傳的Function
 | 
						||
  this.setSubscribeElectricmeterEndCallBack = function (callBackFunc) {
 | 
						||
    if (callBackFunc != undefined && callBackFunc != null) {
 | 
						||
      baja_subscribe_end_electricmeter_callback_func = callBackFunc;
 | 
						||
    }
 | 
						||
  };
 | 
						||
}
 | 
						||
 | 
						||
function MyBaja() {
 | 
						||
  // 取得使用者帳號
 | 
						||
  this.setMyUserAccount = function (callBackFunc = null) {
 | 
						||
    require(["baja!"], function (baja) {
 | 
						||
      user_name = baja.getUserName();
 | 
						||
      callBackFunc ? callBackFunc(user_name) : "";
 | 
						||
    });
 | 
						||
  };
 | 
						||
}
 | 
						||
 | 
						||
/**
 | 
						||
 * 使用者透過BQL指定路徑去訂閱設備點位
 | 
						||
 */
 | 
						||
//function BajaSubscribeDevicesByBql() {
 | 
						||
 | 
						||
//    require(['baja!'], function (baja) {
 | 
						||
//        console.log("進入Function 準備執行BQL訂閱");
 | 
						||
//        startPageLoading ? startPageLoading() : ""
 | 
						||
//        var init_start = new Date(Date.now());
 | 
						||
//        var sub = new baja.Subscriber();
 | 
						||
 | 
						||
//        sub.attach('changed', function (prop) {
 | 
						||
//            if (prop.getName() === 'out') {
 | 
						||
//                var out_value = this.getOutDisplay();
 | 
						||
//                var target_device_number = this.$parent.getDisplayName().split('_').slice(0, 5).join('_');
 | 
						||
//                var point_name = this.getDisplayName();
 | 
						||
 | 
						||
//                //依據Facets判斷回傳的內容值為何
 | 
						||
//                var facets_split = this.getFacets1().$cEncStr.split('|');
 | 
						||
//                var facets_arr = [];
 | 
						||
//                facets_split.forEach(function (item, index) {
 | 
						||
//                    facets_arr.push(item.split('=s:'));
 | 
						||
//                });
 | 
						||
 | 
						||
//                var facets = facets_arr.reduce((obj, cur) => ({ ...obj, [cur[0]]: cur[1] }), {})
 | 
						||
 | 
						||
//                var point_out_split = this.getOutDisplay().split(' ');
 | 
						||
 | 
						||
//                let key = Object.keys(facets).find(k => facets[k] === point_out_split[0]);
 | 
						||
 | 
						||
//                if (key == undefined) {
 | 
						||
//                    key = point_out_split[0];
 | 
						||
//                }
 | 
						||
 | 
						||
//                var modify_target_device = {
 | 
						||
//                    "device_number": target_device_number ? target_device_number : null,
 | 
						||
//                    "device_number_full": this.$parent.getSlotPath().$names.join("_"),
 | 
						||
//                    "point_name": point_name ? point_name : null,
 | 
						||
//                    "value": key
 | 
						||
//                }
 | 
						||
 | 
						||
//                if (baja_subscribe_device_callback_func != undefined && baja_subscribe_device_callback_func != null) {
 | 
						||
//                    baja_subscribe_device_callback_func(modify_target_device, true); //第2參數用在平面圖,刷新畫面
 | 
						||
//                }
 | 
						||
//            }
 | 
						||
//        }, function (err) {
 | 
						||
//            console.log(err)
 | 
						||
//        });
 | 
						||
 | 
						||
//        //使用bql語法
 | 
						||
//        // var building_tag = "H";
 | 
						||
//        // var system_tag = "M10";
 | 
						||
//        // baja.Ord.make(`ip:greencloud.fic.com.tw|foxs:|station:|slot:/Arena/${building_tag}/${system_tag}|bql:select name, displayname, slotPath, out.value, out from control:ControlPoint`)
 | 
						||
//        console.log(`local:|foxs:${port}|station:|slot:/${_this.ordPath.area_tag}/${ordPath.building_tag}/${ordPath.system_tag}/${ordPath.name_tag}|bql:select name, displayname, slotPath, out.value, out, facets  from control:ControlPoint`);
 | 
						||
//        baja.Ord.make(`local:|foxs:${port}|station:|slot:/${_this.ordPath.area_tag}/${ordPath.building_tag}/${ordPath.system_tag}/${ordPath.name_tag}|bql:select name, displayname, slotPath, out.value, out, facets  from control:ControlPoint`)
 | 
						||
//            .get(
 | 
						||
//                function (table) {
 | 
						||
//                    var tableStart, tableFinish;
 | 
						||
//                    var subStart, subFinish;
 | 
						||
//                    var component_index = 0;
 | 
						||
//                    var total_component_index = 0;
 | 
						||
//                    var totalTargetDevice = [];
 | 
						||
//                    var readBqlFinish = new Date(Date.now());
 | 
						||
//                    // $("#readPath-finish-timestamp").html(readBqlFinish.toISOString());
 | 
						||
//                    // $("#readPath-finish-time").html((readBqlFinish.getTime() - init_start.getTime()) / 1000 + "sec");
 | 
						||
//                    console.log("讀取路徑完成-花費時間", (readBqlFinish.getTime() - init_start.getTime()) / 1000 + "sec");
 | 
						||
//                    table.cursor({
 | 
						||
//                        before: function () {
 | 
						||
//                            totalTargetDevice = [];
 | 
						||
//                            tableStart = new Date(Date.now());
 | 
						||
//                            $("#table-start-timestamp").html(tableStart.toISOString());
 | 
						||
//                            render_start = new Date(Date.now());
 | 
						||
 | 
						||
//                        },
 | 
						||
//                        each: function (item, index) {
 | 
						||
//                            if (index < 1) {
 | 
						||
//                                subStart = new Date(Date.now());
 | 
						||
//                                $("#sub-start").html(subStart.toISOString());
 | 
						||
//                            }
 | 
						||
//                            $("#sub-number").html(index + 1);
 | 
						||
//                            total_component_index = index;
 | 
						||
 | 
						||
//                            var target_device_number_split = this.getDisplay("slotPath").split('/');
 | 
						||
//                            var target_device_number = target_device_number_split[8];
 | 
						||
//                            //console.log(target_device_number);
 | 
						||
//                            var point_name = this.getDisplay("name");
 | 
						||
//                            var facets = this.getDisplay("facets");
 | 
						||
 | 
						||
//                            //依據Facets判斷回傳的內容值為何
 | 
						||
//                            var facets_split = facets.split(',');
 | 
						||
//                            var facets_arr = [];
 | 
						||
//                            facets_split.forEach(function (item, index) {
 | 
						||
//                                facets_arr.push(item.split('='));
 | 
						||
//                            });
 | 
						||
 | 
						||
//                            facets = facets_arr.reduce((obj, cur) => ({ ...obj, [cur[0]]: cur[1] }), {})
 | 
						||
 | 
						||
//                            var point_out_split = this.getDisplay("out").split(' ');
 | 
						||
 | 
						||
//                            let key = Object.keys(facets).find(k => facets[k] === point_out_split[0]);
 | 
						||
 | 
						||
//                            if (key == undefined) {
 | 
						||
//                                key = point_out_split[0];
 | 
						||
//                            }
 | 
						||
 | 
						||
//                            var modify_target_device = {
 | 
						||
//                                "device_number": target_device_number ? target_device_number : null,
 | 
						||
//                                "device_number_full": this.getDisplay("slotPath").split("slot:")[1].split('/').slice(1, -1).join("_"),
 | 
						||
//                                "point_name": point_name ? point_name : null,
 | 
						||
//                                "value": key
 | 
						||
//                            }
 | 
						||
//                            totalTargetDevice.push(modify_target_device);
 | 
						||
//                            //取得component當下就更新設備點位
 | 
						||
//                            if (baja_subscribe_device_callback_func != undefined && baja_subscribe_device_callback_func != null) {
 | 
						||
//                                baja_subscribe_device_callback_func(modify_target_device);
 | 
						||
//                            }
 | 
						||
 | 
						||
//                            baja.Ord.make(`local:|foxs:${port}|station:|` + this.getDisplay("slotPath"))
 | 
						||
//                                .get()
 | 
						||
//                                .then(function (component) {
 | 
						||
//                                    component_index++;
 | 
						||
//                                    var target_device_number = component.$parent.getDisplayName().split('_').slice(0, 5).join('_');
 | 
						||
//                                    var point_name = component.getDisplayName();
 | 
						||
 | 
						||
//                                    // //依據Facets判斷回傳的內容值為何
 | 
						||
//                                    // var facets_split = component.getFacets1().$cEncStr.split('|');
 | 
						||
//                                    // var facets_arr = [];
 | 
						||
//                                    // facets_split.forEach(function (item, index) {
 | 
						||
//                                    //   facets_arr.push(item.split('=s:'));
 | 
						||
//                                    // });
 | 
						||
 | 
						||
//                                    // var facets = facets_arr.reduce((obj, cur) => ({ ...obj, [cur[0]]: cur[1] }), {})
 | 
						||
 | 
						||
//                                    // var point_out_split = component.getOutDisplay().split(' ');
 | 
						||
 | 
						||
//                                    // let key = Object.keys(facets).find(k => facets[k] === point_out_split[0]);
 | 
						||
 | 
						||
//                                    // if (key == undefined) {
 | 
						||
//                                    //   key = point_out_split[0];
 | 
						||
//                                    // }
 | 
						||
 | 
						||
//                                    // var modify_target_device = {
 | 
						||
//                                    //   "device_number": target_device_number ? target_device_number : null,
 | 
						||
//                                    //   "point_name": point_name ? point_name : null,
 | 
						||
//                                    //   "value": key
 | 
						||
//                                    // }
 | 
						||
 | 
						||
//                                    // //取得component當下就更新設備點位
 | 
						||
//                                    // if (baja_subscribe_device_callback_func != undefined && baja_subscribe_device_callback_func != null) {
 | 
						||
//                                    //   if (component_index == total_component_index) {
 | 
						||
//                                    //     baja_subscribe_device_callback_func(modify_target_device, true);
 | 
						||
//                                    //   }
 | 
						||
//                                    //   else {
 | 
						||
//                                    //     baja_subscribe_device_callback_func(modify_target_device);
 | 
						||
//                                    //   }
 | 
						||
//                                    // }
 | 
						||
 | 
						||
//                                    sub.subscribe({
 | 
						||
//                                        comps: component,
 | 
						||
//                                    });
 | 
						||
//                                    tolSubList.push(sub);
 | 
						||
//                                    subFinish = new Date(Date.now());
 | 
						||
//                                    $("#sub-end").html(subFinish.toISOString());
 | 
						||
//                                    $("#sub-time").html((subFinish.getTime() - subStart.getTime()) / 1000 + "sec");
 | 
						||
//                                    // console.log("訂閱完成時間", (subFinish.getTime() - subStart.getTime()) / 1000 + "sec");
 | 
						||
//                                });
 | 
						||
//                        },
 | 
						||
//                        after: function () {
 | 
						||
//                            tableFinish = new Date(Date.now());
 | 
						||
//                            // $("#table-finish-timestamp").html(tableFinish.toISOString());
 | 
						||
//                            // $("#table-time").html((tableFinish.getTime() - tableStart.getTime()) / 1000 + "sec");
 | 
						||
//                            //取得component當下就更新設備點位
 | 
						||
//                            if (baja_subscribe_end_device_callback_func != undefined && baja_subscribe_end_device_callback_func != null) {
 | 
						||
//                                baja_subscribe_end_device_callback_func(totalTargetDevice);
 | 
						||
//                            }
 | 
						||
//                            endPageLoading ? endPageLoading() : ""
 | 
						||
//                            console.log("表格完成時間", (tableFinish.getTime() - tableStart.getTime()) / 1000 + "sec");
 | 
						||
//                        },
 | 
						||
//                        limit: -1,
 | 
						||
//                        offset: 0
 | 
						||
//                    });
 | 
						||
//                });
 | 
						||
//    })
 | 
						||
//}
 | 
						||
 | 
						||
/**
 | 
						||
 * 使用者透過BQL指定路徑去訂閱Alarm
 | 
						||
 */
 | 
						||
function BajaSubscribeAlarmsByBql(ordPathForAlarm) {
 | 
						||
  require(["baja!"], function (baja) {
 | 
						||
    console.log("進入Function 準備執行BQL訂閱");
 | 
						||
    var init_start = new Date(Date.now());
 | 
						||
    var sub = new baja.Subscriber();
 | 
						||
    startPageLoading ? startPageLoading() : "";
 | 
						||
    sub.attach("changed", function (prop) {
 | 
						||
      if (prop.getName() === "out") {
 | 
						||
        var sourceState =
 | 
						||
          this.$map.$map.in10.$val.$map.$map.value.$display == "true"
 | 
						||
            ? "Offnormal"
 | 
						||
            : "Normal";
 | 
						||
 | 
						||
        var modify_target_device = {
 | 
						||
          system:
 | 
						||
            ordPathForAlarm.area_tag +
 | 
						||
            "_" +
 | 
						||
            ordPathForAlarm.building_tag +
 | 
						||
            "_" +
 | 
						||
            ordPathForAlarm.system_tag +
 | 
						||
            "_" +
 | 
						||
            ordPathForAlarm.name_tag,
 | 
						||
          sourceState: sourceState ? sourceState : null,
 | 
						||
        };
 | 
						||
 | 
						||
        if (
 | 
						||
          baja_subscribe_alarm_callback_func != undefined &&
 | 
						||
          baja_subscribe_alarm_callback_func != null
 | 
						||
        ) {
 | 
						||
          baja_subscribe_alarm_callback_func(modify_target_device);
 | 
						||
        }
 | 
						||
      }
 | 
						||
    });
 | 
						||
 | 
						||
    //使用bql語法
 | 
						||
    // console.log(`local:|foxs:${port}|alarm:|bql:select top 1 timestamp, sourceState, normalTime where alarmData.sourceName like '%${ordPathForAlarm.area_tag}_${ordPathForAlarm.building_tag}_${ordPathForAlarm.system_tag}_${ordPathForAlarm.name_tag}_%' order by timestamp desc`);
 | 
						||
    baja.Ord.make(
 | 
						||
      `local:|foxs:${port}|alarm:|bql:select top 1 timestamp, sourceState, alarmData, alarmData.sourceName, normalTime where alarmData.sourceName like '%${ordPathForAlarm.area_tag}_${ordPathForAlarm.building_tag}_${ordPathForAlarm.system_tag}_${ordPathForAlarm.name_tag}_%' order by timestamp desc`
 | 
						||
    ).get(function (table) {
 | 
						||
      var tableStart, tableFinish;
 | 
						||
      var subStart, subFinish;
 | 
						||
      var totalTargetDevice = [];
 | 
						||
      var component_index = 0;
 | 
						||
      var total_component_index = 0;
 | 
						||
      var readBqlFinish = new Date(Date.now());
 | 
						||
      console.log(
 | 
						||
        "讀取路徑完成-花費時間",
 | 
						||
        (readBqlFinish.getTime() - init_start.getTime()) / 1000 + "sec"
 | 
						||
      );
 | 
						||
 | 
						||
      table.cursor({
 | 
						||
        before: function () {
 | 
						||
          totalTargetDevice = [];
 | 
						||
          tableStart = new Date(Date.now());
 | 
						||
          render_start = new Date(Date.now());
 | 
						||
        },
 | 
						||
        each: function (item, index) {
 | 
						||
          if (index < 1) {
 | 
						||
            subStart = new Date(Date.now());
 | 
						||
          }
 | 
						||
          total_component_index = index;
 | 
						||
 | 
						||
          var sourceState = this.getDisplay("sourceState");
 | 
						||
          //var sourceName = (item.$map.$map.alarmData$2esourceName.$display).replace('_', '/');
 | 
						||
          var sourceNameArray =
 | 
						||
            item.$map.$map.alarmData$2esourceName.$display.split("_");
 | 
						||
          var slotPath =
 | 
						||
            sourceNameArray[0] +
 | 
						||
            "/" +
 | 
						||
            sourceNameArray[1] +
 | 
						||
            "/" +
 | 
						||
            sourceNameArray[2] +
 | 
						||
            "/" +
 | 
						||
            sourceNameArray[3] +
 | 
						||
            "/" +
 | 
						||
            sourceNameArray[4] +
 | 
						||
            "/" +
 | 
						||
            sourceNameArray[5] +
 | 
						||
            "/" +
 | 
						||
            sourceNameArray[6] +
 | 
						||
            "/" +
 | 
						||
            sourceNameArray[7] +
 | 
						||
            "/" +
 | 
						||
            sourceNameArray[8];
 | 
						||
          var normalTime = this.getDisplay("normalTime");
 | 
						||
 | 
						||
          var modify_target_device = {
 | 
						||
            system:
 | 
						||
              ordPathForAlarm.area_tag +
 | 
						||
              "_" +
 | 
						||
              ordPathForAlarm.building_tag +
 | 
						||
              "_" +
 | 
						||
              ordPathForAlarm.system_tag +
 | 
						||
              "_" +
 | 
						||
              ordPathForAlarm.name_tag,
 | 
						||
            sourceState: sourceState ? sourceState : null,
 | 
						||
          };
 | 
						||
          totalTargetDevice.push(modify_target_device);
 | 
						||
          //取得component當下就更新設備點位
 | 
						||
          if (
 | 
						||
            baja_subscribe_alarm_callback_func != undefined &&
 | 
						||
            baja_subscribe_alarm_callback_func != null
 | 
						||
          ) {
 | 
						||
            baja_subscribe_alarm_callback_func(modify_target_device);
 | 
						||
          }
 | 
						||
 | 
						||
          baja.Ord.make("local:|foxs:|station:|slot:/" + slotPath)
 | 
						||
            .get()
 | 
						||
            .then(function (component) {
 | 
						||
              component_index++;
 | 
						||
 | 
						||
              sub.subscribe({
 | 
						||
                comps: component,
 | 
						||
              });
 | 
						||
 | 
						||
              subFinish = new Date(Date.now());
 | 
						||
              console.log(
 | 
						||
                "訂閱完成時間",
 | 
						||
                (subFinish.getTime() - subStart.getTime()) / 1000 + "sec"
 | 
						||
              );
 | 
						||
            });
 | 
						||
        },
 | 
						||
        after: function () {
 | 
						||
          tableFinish = new Date(Date.now());
 | 
						||
          if (
 | 
						||
            baja_subscribe_end_alarm_callback_func != undefined &&
 | 
						||
            baja_subscribe_end_alarm_callback_func != null
 | 
						||
          ) {
 | 
						||
            baja_subscribe_end_alarm_callback_func(totalTargetDevice);
 | 
						||
          }
 | 
						||
          endPageLoading ? endPageLoading() : "";
 | 
						||
          console.log(
 | 
						||
            "表格完成時間",
 | 
						||
            (tableFinish.getTime() - tableStart.getTime()) / 1000 + "sec"
 | 
						||
          );
 | 
						||
        },
 | 
						||
        limit: -1,
 | 
						||
        offset: 0,
 | 
						||
      });
 | 
						||
    });
 | 
						||
  });
 | 
						||
}
 | 
						||
 | 
						||
/**
 | 
						||
 * 使用者透過BQL指定路徑去訂閱 electricmeter
 | 
						||
 */
 | 
						||
function BajaSubscribeElectricmeterByBql(
 | 
						||
  ordPathForElectricmeter,
 | 
						||
  callback = null
 | 
						||
) {
 | 
						||
  require(["baja!"], function (baja) {
 | 
						||
    //console.log("進入Function 準備執行BQL訂閱");
 | 
						||
    startPageLoading ? startPageLoading() : "";
 | 
						||
    var init_start = new Date(Date.now());
 | 
						||
    var sub = new baja.Subscriber();
 | 
						||
 | 
						||
    sub.attach(
 | 
						||
      "changed",
 | 
						||
      function (prop) {
 | 
						||
        if (prop.getName() === "out") {
 | 
						||
          var out_value = this.getOutDisplay();
 | 
						||
          var target_device_number = this.$parent
 | 
						||
            .getName()
 | 
						||
            .split("_")
 | 
						||
            .slice(0, 5)
 | 
						||
            .join("_");
 | 
						||
 | 
						||
          var point_name = this.getDisplayName();
 | 
						||
 | 
						||
          //依據Facets判斷回傳的內容值為何
 | 
						||
          var facets_split = this.getFacets1().$cEncStr.split("|");
 | 
						||
          var facets_arr = [];
 | 
						||
          facets_split.forEach(function (item, index) {
 | 
						||
            facets_arr.push(item.split("=s:"));
 | 
						||
          });
 | 
						||
 | 
						||
          var facets = facets_arr.reduce(
 | 
						||
            (obj, cur) => ({ ...obj, [cur[0]]: cur[1] }),
 | 
						||
            {}
 | 
						||
          );
 | 
						||
 | 
						||
          var point_out_split = this.getOutDisplay().split(" ");
 | 
						||
 | 
						||
          let key = Object.keys(facets).find(
 | 
						||
            (k) => facets[k] === point_out_split[0]
 | 
						||
          );
 | 
						||
 | 
						||
          if (key == undefined) {
 | 
						||
            key = point_out_split[0];
 | 
						||
          }
 | 
						||
 | 
						||
          var modify_target_device = {
 | 
						||
            device_number: target_device_number ? target_device_number : null,
 | 
						||
            //"device_number_full": this.$parent.getSlotPath().$names.join("_"),
 | 
						||
            point_name: point_name ? point_name : null,
 | 
						||
            value: key,
 | 
						||
          };
 | 
						||
 | 
						||
          if (callback !== null) {
 | 
						||
            callback([modify_target_device]);
 | 
						||
          }
 | 
						||
 | 
						||
          if (
 | 
						||
            baja_subscribe_electricmeter_callback_func != undefined &&
 | 
						||
            baja_subscribe_electricmeter_callback_func != null
 | 
						||
          ) {
 | 
						||
            baja_subscribe_electricmeter_callback_func(
 | 
						||
              modify_target_device,
 | 
						||
              true
 | 
						||
            ); //第2參數用在平面圖,刷新畫面
 | 
						||
          }
 | 
						||
        }
 | 
						||
      },
 | 
						||
      function (err) {
 | 
						||
        console.log(err);
 | 
						||
      }
 | 
						||
    );
 | 
						||
 | 
						||
    //使用bql語法
 | 
						||
    console.log(
 | 
						||
      `local:|foxs:${port}|station:|slot:/${ordPathForElectricmeter.devicePath}|bql:select name, out, out.value, slotPath, facets from control:ControlPoint`
 | 
						||
    );
 | 
						||
    baja.Ord.make(
 | 
						||
      `local:|foxs:${port}|station:|slot:/${ordPathForElectricmeter.devicePath}|bql:select name, out, out.value, slotPath, facets from control:ControlPoint`
 | 
						||
    )
 | 
						||
      .get()
 | 
						||
      .then(function (table) {
 | 
						||
        console.log('table',table);
 | 
						||
        
 | 
						||
        var tableStart, tableFinish;
 | 
						||
        var subStart, subFinish;
 | 
						||
        var component_index = 0;
 | 
						||
        var total_component_index = 0;
 | 
						||
        var totalTargetDevice = [];
 | 
						||
        var readBqlFinish = new Date(Date.now());
 | 
						||
        //console.log("讀取路徑完成-花費時間", (readBqlFinish.getTime() - init_start.getTime()) / 1000 + "sec");
 | 
						||
        table.cursor({
 | 
						||
          before: function () {
 | 
						||
            totalTargetDevice = [];
 | 
						||
            tableStart = new Date(Date.now());
 | 
						||
            $("#table-start-timestamp").html(tableStart.toISOString());
 | 
						||
            render_start = new Date(Date.now());
 | 
						||
          },
 | 
						||
          each: function (item, index) {
 | 
						||
            if (index < 1) {
 | 
						||
              subStart = new Date(Date.now());
 | 
						||
              $("#sub-start").html(subStart.toISOString());
 | 
						||
            }
 | 
						||
            $("#sub-number").html(index + 1);
 | 
						||
            total_component_index = index;
 | 
						||
 | 
						||
            var target_device_number_split =
 | 
						||
              this.getDisplay("slotPath").split("/");
 | 
						||
            var target_device_number = target_device_number_split[8];
 | 
						||
            //console.log(target_device_number);
 | 
						||
            var point_name = this.getDisplay("name");
 | 
						||
            var facets = this.getDisplay("facets");
 | 
						||
 | 
						||
            //依據Facets判斷回傳的內容值為何
 | 
						||
            var facets_split = facets.split(",");
 | 
						||
            var facets_arr = [];
 | 
						||
            facets_split.forEach(function (item, index) {
 | 
						||
              facets_arr.push(item.split("="));
 | 
						||
            });
 | 
						||
 | 
						||
            facets = facets_arr.reduce(
 | 
						||
              (obj, cur) => ({ ...obj, [cur[0]]: cur[1] }),
 | 
						||
              {}
 | 
						||
            );
 | 
						||
 | 
						||
            var point_out_split = this.getDisplay("out").split(" ");
 | 
						||
 | 
						||
            let key = Object.keys(facets).find(
 | 
						||
              (k) => facets[k] === point_out_split[0]
 | 
						||
            );
 | 
						||
 | 
						||
            if (key == undefined) {
 | 
						||
              key = point_out_split[0];
 | 
						||
            }
 | 
						||
 | 
						||
            var modify_target_device = {
 | 
						||
              device_number: target_device_number ? target_device_number : null,
 | 
						||
              //"device_number_full": this.getDisplay("slotPath").split("slot:")[1].split('/').slice(1, -1).join("_"),
 | 
						||
              point_name: point_name ? point_name : null,
 | 
						||
              value: key,
 | 
						||
            };
 | 
						||
            totalTargetDevice.push(modify_target_device);
 | 
						||
            //取得component當下就更新設備點位
 | 
						||
            if (
 | 
						||
              baja_subscribe_electricmeter_callback_func != undefined &&
 | 
						||
              baja_subscribe_electricmeter_callback_func != null
 | 
						||
            ) {
 | 
						||
              baja_subscribe_electricmeter_callback_func(modify_target_device);
 | 
						||
            }
 | 
						||
 | 
						||
            baja.Ord.make(
 | 
						||
              `local:|foxs:${port}|station:|` + this.getDisplay("slotPath")
 | 
						||
            )
 | 
						||
              .get()
 | 
						||
              .then(function (component) {
 | 
						||
                component_index++;
 | 
						||
                //var target_device_number = component.$parent.getDisplayName().split('_').slice(0, 5).join('_');
 | 
						||
                //var point_name = component.getDisplayName();
 | 
						||
 | 
						||
                sub.subscribe({
 | 
						||
                  comps: component,
 | 
						||
                });
 | 
						||
                tolSubList.push(sub);
 | 
						||
                subFinish = new Date(Date.now());
 | 
						||
                $("#sub-end").html(subFinish.toISOString());
 | 
						||
                $("#sub-time").html(
 | 
						||
                  (subFinish.getTime() - subStart.getTime()) / 1000 + "sec"
 | 
						||
                );
 | 
						||
              // console.log("訂閱完成時間", (subFinish.getTime() - subStart.getTime()) / 1000 + "sec");
 | 
						||
              });
 | 
						||
          },
 | 
						||
          after: function () {
 | 
						||
            tableFinish = new Date(Date.now());
 | 
						||
            if (callback !== null) {
 | 
						||
              callback(totalTargetDevice);
 | 
						||
            }
 | 
						||
            if (
 | 
						||
              baja_subscribe_end_electricmeter_callback_func != undefined &&
 | 
						||
              baja_subscribe_end_electricmeter_callback_func != null
 | 
						||
            ) {
 | 
						||
              baja_subscribe_end_electricmeter_callback_func(totalTargetDevice);
 | 
						||
            }
 | 
						||
            endPageLoading ? endPageLoading() : "";
 | 
						||
            //console.log("表格完成時間", (tableFinish.getTime() - tableStart.getTime()) / 1000 + "sec");
 | 
						||
          },
 | 
						||
          limit: -1,
 | 
						||
          offset: 0,
 | 
						||
        });
 | 
						||
      });
 | 
						||
  });
 | 
						||
}
 | 
						||
 | 
						||
// function getAlarmCountByBaja(callback) {
 | 
						||
//     var _result = "";
 | 
						||
//     var _index = 0;
 | 
						||
 | 
						||
//     require(['baja!'], function (baja) {
 | 
						||
//         baja.Ord.make("local:|foxs:|alarm:|bql:select timestamp, ackState, alarmData, alarmData.sourceName, sourceState, uuid, alarmData.msgText, normalTime where sourceState = 'offnormal' order by timestamp desc").get()
 | 
						||
//             .then(function (table) {
 | 
						||
//                 return table.cursor({
 | 
						||
//                     each: function (record) {
 | 
						||
//                         _index++;
 | 
						||
//                     },
 | 
						||
//                     after: function () {
 | 
						||
//                         _result += '{' + '"count": ' + _index;
 | 
						||
//                         _result += '}';
 | 
						||
//                         if (typeof callback === 'function') {
 | 
						||
//                             callback(_result);
 | 
						||
//                         }
 | 
						||
//                     },
 | 
						||
//                     limit: -1,
 | 
						||
//                     offset: 0
 | 
						||
//                 });
 | 
						||
//             });
 | 
						||
//     });
 | 
						||
// }
 | 
						||
 | 
						||
// /**
 | 
						||
//  * [首頁] 查詢復歸數量
 | 
						||
//  * @param {any} callback
 | 
						||
//  */
 | 
						||
//  function getRecoverCountByBaja(callback) {
 | 
						||
//     var _result = "";
 | 
						||
//     var _index = 0;
 | 
						||
 | 
						||
//     require(['baja!'], function (baja) {
 | 
						||
//         baja.Ord.make("local:|foxs:|alarm:|bql:select timestamp, ackState, alarmData, alarmData.sourceName, sourceState, uuid, alarmData.msgText, normalTime where normalTime != null order by timestamp desc").get()
 | 
						||
//             .then(function (table) {
 | 
						||
//                 return table.cursor({
 | 
						||
//                     each: function (record) {
 | 
						||
//                         _index++;
 | 
						||
//                     },
 | 
						||
//                     after: function () {
 | 
						||
//                         _result += '{' + '"count": ' + _index;
 | 
						||
//                         _result += '}';
 | 
						||
//                         if (typeof callback === 'function') {
 | 
						||
//                             callback(_result);
 | 
						||
//                         }
 | 
						||
//                     },
 | 
						||
//                     limit: -1,
 | 
						||
//                     offset: 0
 | 
						||
//                 });
 | 
						||
//             });
 | 
						||
//     });
 | 
						||
// }
 | 
						||
 | 
						||
// function getCheckedAckedCountByBaja(callback) {
 | 
						||
//     var _result = "";
 | 
						||
//     var _index = 0;
 | 
						||
 | 
						||
//     require(['baja!'], function (baja) {
 | 
						||
//         baja.Ord.make("local:|foxs:|alarm:|bql:select timestamp, ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime from openAlarms where ackState ='acked' order by timestamp asc").get()
 | 
						||
//             .then(function (table) {
 | 
						||
//                 return table.cursor({
 | 
						||
//                     each: function (record) {
 | 
						||
//                         _index++;
 | 
						||
//                     },
 | 
						||
//                     after: function () {
 | 
						||
//                         _result += '{' + '"count": ' + _index;
 | 
						||
//                         _result += '}';
 | 
						||
//                         if (typeof callback === 'function') {
 | 
						||
//                             callback(_result);
 | 
						||
//                         }
 | 
						||
//                     },
 | 
						||
//                     limit: -1,
 | 
						||
//                     offset: 0
 | 
						||
//                 });
 | 
						||
//             });
 | 
						||
//     });
 | 
						||
// }
 | 
						||
 | 
						||
// function getUnCheckedAckedCountByBaja(callback) {
 | 
						||
//     var _result = "";
 | 
						||
//     var _index = 0;
 | 
						||
 | 
						||
//     require(['baja!'], function (baja) {
 | 
						||
//         baja.Ord.make("local:|foxs:|alarm:|bql:select timestamp, ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime from openAlarms where ackState ='unacked' order by timestamp asc").get()
 | 
						||
//             .then(function (table) {
 | 
						||
//                 return table.cursor({
 | 
						||
//                     each: function (record) {
 | 
						||
//                         _index++;
 | 
						||
//                     },
 | 
						||
//                     after: function () {
 | 
						||
//                         _result += '{' + '"count": ' + _index;
 | 
						||
//                         _result += '}';
 | 
						||
//                         if (typeof callback === 'function') {
 | 
						||
//                             callback(_result);
 | 
						||
//                         }
 | 
						||
//                     },
 | 
						||
//                     limit: -1,
 | 
						||
//                     offset: 0
 | 
						||
//                 });
 | 
						||
//             });
 | 
						||
//     });
 | 
						||
// }
 |