Merge branch 'MCUT' of https://gitea.mjm-staging.developers-homelab.net/BIMS/BIMS into MCUT
This commit is contained in:
		
						commit
						a79a896641
					
				@ -162,12 +162,12 @@ namespace Backend.Controllers
 | 
			
		||||
                //obixApiConfig.UrlSlot =  variableObix.Where(x => x.Name == "url_slot").Select(x => x.Value).FirstOrDefault();
 | 
			
		||||
 | 
			
		||||
                var urlSlots = backendRepository.GetAllAsync<string>("select obixSlot from building where deleted = 0").Result;
 | 
			
		||||
                foreach(var us in urlSlots)
 | 
			
		||||
                {
 | 
			
		||||
                    var data = svc.obixHisQuery(obixApiConfig.ApiBase + "obix/config/Program/ObixQuery/query/", obixApiConfig.ApiBase + "obix/histories", us,
 | 
			
		||||
                //foreach(var us in urlSlots)
 | 
			
		||||
                //{
 | 
			
		||||
                    var data = svc.obixHisQuery(obixApiConfig.ApiBase + "obix/config/Program/ObixQuery/query/", obixApiConfig.ApiBase + "obix/histories", "",
 | 
			
		||||
                                obixApiConfig.UserName, obixApiConfig.Password);
 | 
			
		||||
                    ds.AddRange(data);
 | 
			
		||||
                }
 | 
			
		||||
               // }
 | 
			
		||||
                
 | 
			
		||||
                var buildings = backendRepository.GetAllAsync<string>("select building_tag from building where deleted = 0").Result;
 | 
			
		||||
                apiResult.Code = "0000";
 | 
			
		||||
@ -207,6 +207,25 @@ namespace Backend.Controllers
 | 
			
		||||
                    await niagaraDataSynchronizeRepository.CheckItemDiffFullNameAndCover(); // update device_item.fullname
 | 
			
		||||
                    await niagaraDataSynchronizeRepository.ItemCheckFullNameEmptyReplaceByDeviceName(); // 檢查device_item內FullName為空的值,以points取代
 | 
			
		||||
                    await niagaraDataSynchronizeRepository.CheckItemIsShowHistory();
 | 
			
		||||
 | 
			
		||||
                    #region 歷史資料處理
 | 
			
		||||
                    ds.Clear();
 | 
			
		||||
                    var sqlObix = $@"SELECT system_value as Value, system_key as Name FROM variable WHERE deleted = 0 AND system_type = 'obixConfig'";
 | 
			
		||||
                    var variableObix = backendRepository.GetAllAsync<Backend.Models.KeyValue>(sqlObix).Result;
 | 
			
		||||
                    var obixApiConfig = new Backend.Models.ObixApiConfig();
 | 
			
		||||
                    EDFunction ed = new EDFunction();
 | 
			
		||||
                    obixApiConfig.ApiBase = variableObix.Where(x => x.Name == "ApiBase").Select(x => x.Value).FirstOrDefault();
 | 
			
		||||
                    obixApiConfig.UserName = variableObix.Where(x => x.Name == "UserName").Select(x => x.Value).FirstOrDefault();
 | 
			
		||||
                    obixApiConfig.Password = variableObix.Where(x => x.Name == "Password").Select(x => x.Value).FirstOrDefault();
 | 
			
		||||
                    //obixApiConfig.UrlSlot =  variableObix.Where(x => x.Name == "url_slot").Select(x => x.Value).FirstOrDefault();
 | 
			
		||||
                    webRequestService svc = new webRequestService();
 | 
			
		||||
                    var data = svc.obixHisQuery_v2(obixApiConfig.ApiBase + "obix/config/Program/ObixQuery/query/", obixApiConfig.ApiBase + "obix/histories", "",
 | 
			
		||||
                                obixApiConfig.UserName, obixApiConfig.Password);
 | 
			
		||||
                    ds.AddRange(data);
 | 
			
		||||
                    // save to history 
 | 
			
		||||
                    await niagaraDataSynchronizeRepository.InsertItemFromNiagara_History(ds, building); // insert 暫存table import_niagara_item_history
 | 
			
		||||
                    #endregion
 | 
			
		||||
 | 
			
		||||
                    result = true;
 | 
			
		||||
 | 
			
		||||
                    apiResult.Code = "0000";
 | 
			
		||||
 | 
			
		||||
@ -131,6 +131,149 @@ namespace Backend.Services.Implement
 | 
			
		||||
            return result;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 獲取 niagara history 中的點位
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="bqlUrlString"></param>
 | 
			
		||||
        /// <param name="urlString"></param>
 | 
			
		||||
        /// <param name="slot"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public List<ImpNiaItem> obixHisQuery_v2(string bqlUrlString, string urlString, string slot, string acc, string pass)
 | 
			
		||||
        {
 | 
			
		||||
            //String username = "obixUser";
 | 
			
		||||
            //String password = "Admin123456";
 | 
			
		||||
            //String username = "stanGG";
 | 
			
		||||
            //String password = "St12345678";
 | 
			
		||||
            String username = acc;
 | 
			
		||||
            String password = pass;
 | 
			
		||||
            String encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password));
 | 
			
		||||
            String oneStationName = null;
 | 
			
		||||
            #region get control point data
 | 
			
		||||
            List<control_point> conPoint = new List<control_point>();
 | 
			
		||||
            String cp_API_Url = bqlUrlString;
 | 
			
		||||
 | 
			
		||||
            HttpWebRequest cp_Postrequest = (HttpWebRequest)WebRequest.Create(cp_API_Url);
 | 
			
		||||
            cp_Postrequest.Method = "POST";
 | 
			
		||||
            cp_Postrequest.Headers.Add("Authorization", "Basic " + encoded);
 | 
			
		||||
            cp_Postrequest.PreAuthenticate = true;
 | 
			
		||||
 | 
			
		||||
            //using (var streamWriter = new StreamWriter(cp_Postrequest.GetRequestStream()))
 | 
			
		||||
            //{
 | 
			
		||||
            //    string json = "<str val='" + slot + "bql: select * from control:ControlPoint'/>";
 | 
			
		||||
 | 
			
		||||
            //    streamWriter.Write(json);
 | 
			
		||||
            //}
 | 
			
		||||
            //HttpWebResponse cp_response = (HttpWebResponse)cp_Postrequest.GetResponse();
 | 
			
		||||
            //var cp_responseString = new StreamReader(cp_response.GetResponseStream()).ReadToEnd();
 | 
			
		||||
 | 
			
		||||
            //XmlDocument cp_xmlDoc = new XmlDocument();
 | 
			
		||||
            //cp_xmlDoc.LoadXml(cp_responseString);
 | 
			
		||||
 | 
			
		||||
            //string cp_jsonText = JsonConvert.SerializeXmlNode(cp_xmlDoc);
 | 
			
		||||
            //var cp_data = Welcome.FromJson(cp_jsonText);
 | 
			
		||||
 | 
			
		||||
            //foreach (var item in cp_data.Obj.Str)
 | 
			
		||||
            //{
 | 
			
		||||
            //    control_point row = new control_point();
 | 
			
		||||
            //    string[] s1 = item.Val.Split(',');
 | 
			
		||||
 | 
			
		||||
            //    string[] s2 = s1[0].Split('/');
 | 
			
		||||
            //    var displayName = s1[1].Split('=')[1];
 | 
			
		||||
 | 
			
		||||
            //    row.name = s1[0].Remove(s1[0].Length - 1, 1).Remove(0, 1);
 | 
			
		||||
            //    row.displayName = displayName;
 | 
			
		||||
            //    row.isHistory = false;
 | 
			
		||||
 | 
			
		||||
            //    conPoint.Add(row);
 | 
			
		||||
            //}
 | 
			
		||||
            #endregion
 | 
			
		||||
 | 
			
		||||
            #region main program
 | 
			
		||||
            List<ImpNiaItem> result = new List<ImpNiaItem>();
 | 
			
		||||
            String API_Url = urlString;
 | 
			
		||||
 | 
			
		||||
            HttpWebRequest Postrequest = (HttpWebRequest)WebRequest.Create(API_Url);
 | 
			
		||||
            Postrequest.Method = "GET";
 | 
			
		||||
            Postrequest.Headers.Add("Authorization", "Basic " + encoded);
 | 
			
		||||
            Postrequest.PreAuthenticate = true;
 | 
			
		||||
 | 
			
		||||
            HttpWebResponse response = (HttpWebResponse)Postrequest.GetResponse();
 | 
			
		||||
            var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
 | 
			
		||||
 | 
			
		||||
            XmlDocument xmlDoc = new XmlDocument();
 | 
			
		||||
            xmlDoc.LoadXml(responseString);
 | 
			
		||||
 | 
			
		||||
            // 1.循環所有的 station
 | 
			
		||||
            //ref https://stackoverflow.com/questions/642293/how-do-i-read-and-parse-an-xml-file-in-c
 | 
			
		||||
            foreach (XmlNode node in xmlDoc.DocumentElement.ChildNodes)
 | 
			
		||||
            {
 | 
			
		||||
                var stationName = node.Attributes["name"].InnerText; // WSP_Supervisor
 | 
			
		||||
                oneStationName = oneStationName ?? stationName;
 | 
			
		||||
                String API_Url2 = urlString + "/" + stationName; // http://192.168.0.136:8081/obix/histories/WSP_Supervisor
 | 
			
		||||
 | 
			
		||||
                HttpWebRequest Postrequest2 = (HttpWebRequest)WebRequest.Create(API_Url2);
 | 
			
		||||
                Postrequest2.Method = "GET";
 | 
			
		||||
                Postrequest2.Headers.Add("Authorization", "Basic " + encoded);
 | 
			
		||||
                Postrequest2.PreAuthenticate = true;
 | 
			
		||||
 | 
			
		||||
                HttpWebResponse response2 = (HttpWebResponse)Postrequest2.GetResponse();
 | 
			
		||||
                var responseString2 = new StreamReader(response2.GetResponseStream()).ReadToEnd();
 | 
			
		||||
 | 
			
		||||
                XmlDocument xmlDoc2 = new XmlDocument();
 | 
			
		||||
                xmlDoc2.LoadXml(responseString2);
 | 
			
		||||
                // 2.獲取 station 中全部的設備+點位
 | 
			
		||||
                foreach (XmlNode node2 in xmlDoc2.DocumentElement.ChildNodes)
 | 
			
		||||
                {
 | 
			
		||||
                    string tagName = node2.Attributes["name"].InnerText;
 | 
			
		||||
                    if (tagName.Split('_').Length == 9)
 | 
			
		||||
                    {
 | 
			
		||||
                        if (tagName.Split('_')[1].IndexOf("8F5") != -1)
 | 
			
		||||
                        {
 | 
			
		||||
                            string ss = tagName.Split('_')[1];
 | 
			
		||||
                        }
 | 
			
		||||
                        ImpNiaItem row = new ImpNiaItem();
 | 
			
		||||
                        row.device_area_tag = tagName.Split('_')[0];
 | 
			
		||||
                        row.device_building_tag = tagName.Split('_')[1];
 | 
			
		||||
                        row.device_system_tag = tagName.Split('_')[2];
 | 
			
		||||
                        row.device_name_tag = tagName.Split('_')[3];
 | 
			
		||||
                        row.device_floor_tag= tagName.Split('_')[4];
 | 
			
		||||
                        row.device_master_tag= tagName.Split('_')[5];
 | 
			
		||||
                        row.device_last_name_tag = tagName.Split('_')[6];
 | 
			
		||||
                        row.device_serial_tag = tagName.Split('_')[7];
 | 
			
		||||
                        row.device_point_name = tagName.Split('_')[8];
 | 
			
		||||
                        row.parent_path = stationName;
 | 
			
		||||
 | 
			
		||||
                        result.Add(row); 
 | 
			
		||||
                    }
 | 
			
		||||
                    else if (tagName.Split('_').Length == 6)
 | 
			
		||||
                    { //巨蛋 tag 5 段版本
 | 
			
		||||
                        ImpNiaItem row = new ImpNiaItem();
 | 
			
		||||
                        if (tagName.Split('_')[1] == "S") //for security system
 | 
			
		||||
                        {
 | 
			
		||||
                            row.device_building_tag = tagName.Split('_')[0];
 | 
			
		||||
                            row.device_system_tag = tagName.Split('_')[1];
 | 
			
		||||
                            row.device_floor_tag = tagName.Split('_')[2];
 | 
			
		||||
                            row.device_name_tag = tagName.Split('_')[3];
 | 
			
		||||
                            row.device_point_name = tagName.Split('_')[5];
 | 
			
		||||
                        }
 | 
			
		||||
                        else //for normal
 | 
			
		||||
                        {
 | 
			
		||||
                            row.device_building_tag = tagName.Split('_')[0];
 | 
			
		||||
                            //row.device_system_tag = tagName.Split('_')[1];
 | 
			
		||||
                            row.device_floor_tag = tagName.Split('_')[2];
 | 
			
		||||
                            row.device_name_tag = tagName.Split('_')[1];
 | 
			
		||||
                            row.device_point_name = tagName.Split('_')[5];
 | 
			
		||||
                        }
 | 
			
		||||
                        row.parent_path = stationName;
 | 
			
		||||
                        result.Add(row);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            #endregion
 | 
			
		||||
            return result.ToList();
 | 
			
		||||
            //return result.Where(x => x.full_name != null).ToList();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 獲取 niagara history 中的點位
 | 
			
		||||
        /// </summary>
 | 
			
		||||
@ -204,7 +347,7 @@ namespace Backend.Services.Implement
 | 
			
		||||
            xmlDoc.LoadXml(responseString);
 | 
			
		||||
 | 
			
		||||
            //ref https://stackoverflow.com/questions/642293/how-do-i-read-and-parse-an-xml-file-in-c
 | 
			
		||||
            foreach (XmlNode node in xmlDoc.DocumentElement.ChildNodes)
 | 
			
		||||
            foreach (XmlNode node in xmlDoc.DocumentElement.ChildNodes) //循環所有的 station
 | 
			
		||||
            {
 | 
			
		||||
                var stationName = node.Attributes["name"].InnerText; // WSP_Supervisor
 | 
			
		||||
                oneStationName = oneStationName ?? stationName;
 | 
			
		||||
@ -328,6 +471,8 @@ namespace Backend.Services.Implement
 | 
			
		||||
            return result.Where(x => x.full_name != null).ToList();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
       
 | 
			
		||||
 | 
			
		||||
        public List<Device_value_disaster> obixDevDisaster(string urlString, string bql, string tag_quantity, string acc, string pass, string dt)
 | 
			
		||||
        {
 | 
			
		||||
            List<Device_value_disaster> result = new List<Device_value_disaster>();
 | 
			
		||||
 | 
			
		||||
@ -7,6 +7,7 @@ using Microsoft.Extensions.Options;
 | 
			
		||||
using Newtonsoft.Json;
 | 
			
		||||
using Newtonsoft.Json.Linq;
 | 
			
		||||
using Quartz;
 | 
			
		||||
using Repository.BackendRepository.Implement;
 | 
			
		||||
using Repository.BackendRepository.Interface;
 | 
			
		||||
using Repository.Helper;
 | 
			
		||||
using System;
 | 
			
		||||
@ -47,6 +48,7 @@ namespace BackendWorkerService.Quartz.Jobs
 | 
			
		||||
        public async Task Execute(IJobExecutionContext context)
 | 
			
		||||
        {
 | 
			
		||||
            Task_Detail task_Detail = new Task_Detail(loggers, backgroundServiceRepository);
 | 
			
		||||
            string device_number = string.Empty;
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                if(await task_Detail.GetNeedWorkTask("ArchiveElectricMeterDayJob", "All"))
 | 
			
		||||
@ -159,8 +161,17 @@ namespace BackendWorkerService.Quartz.Jobs
 | 
			
		||||
                            List<Dictionary<string, object>> waterArchiveDayRawDatas = new List<Dictionary<string, object>>();
 | 
			
		||||
                            foreach (var deviceNumberPoint in electricDeviceNumberPoints)
 | 
			
		||||
                            {
 | 
			
		||||
                                var station = buildingStation.Where(x => x.system_key == deviceNumberPoint.DeviceNumber.Split("_")[1]).Select(x => x.system_value).FirstOrDefault();
 | 
			
		||||
                                archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
 | 
			
		||||
                                device_number = deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "");
 | 
			
		||||
                                var station = backgroundServiceRepository.GetOneAsync<string>($@"select parent_path from import_niagara_item_history where device_building_tag = '{device_number.Split("_")[1].Replace("$3", "")}' and 
 | 
			
		||||
                                    device_system_tag = '{device_number.Split("_")[2]}' and device_name_tag = '{device_number.Split("_")[3]}' 
 | 
			
		||||
                                    and device_floor_tag = '{device_number.Split("_")[4]}' and device_master_tag = '{device_number.Split("_")[5]}' 
 | 
			
		||||
                                    and device_last_name_tag = '{device_number.Split("_")[6]}' and device_serial_tag = '{device_number.Split("_")[7]}'
 | 
			
		||||
                                    and device_point_name = '{device_number.Split("_")[8]}'").Result;
 | 
			
		||||
                                if (string.IsNullOrEmpty(station))
 | 
			
		||||
                                {
 | 
			
		||||
                                    continue;
 | 
			
		||||
                                }
 | 
			
		||||
                                archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "")}/~historyRollup/");
 | 
			
		||||
                                //HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
 | 
			
		||||
                                archiveRequest.Method = "POST";
 | 
			
		||||
                                archiveRequest.Headers.Add("Authorization", "Basic " + encoded);
 | 
			
		||||
@ -216,8 +227,13 @@ namespace BackendWorkerService.Quartz.Jobs
 | 
			
		||||
                            }
 | 
			
		||||
                            foreach (var deviceNumberPoint in waterDeviceNumberPoints)
 | 
			
		||||
                            {
 | 
			
		||||
                                var station = buildingStation.Where(x => x.system_key == deviceNumberPoint.DeviceNumber.Split("_")[1]).Select(x => x.system_value).FirstOrDefault();
 | 
			
		||||
                                archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
 | 
			
		||||
                                device_number = deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "");
 | 
			
		||||
                                var station = backgroundServiceRepository.GetOneAsync<string>($@"select parent_path from import_niagara_item_history where device_building_tag = '{device_number.Split("_")[1].Replace("$3", "")}' and 
 | 
			
		||||
                                    device_system_tag = '{device_number.Split("_")[2]}' and device_name_tag = '{device_number.Split("_")[3]}' 
 | 
			
		||||
                                    and device_floor_tag = '{device_number.Split("_")[4]}' and device_master_tag = '{device_number.Split("_")[5]}' 
 | 
			
		||||
                                    and device_last_name_tag = '{device_number.Split("_")[6]}' and device_serial_tag = '{device_number.Split("_")[7]}'
 | 
			
		||||
                                    and device_point_name = '{device_number.Split("_")[8]}'").Result;
 | 
			
		||||
                                archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "")}/~historyRollup/");
 | 
			
		||||
                                //HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
 | 
			
		||||
                                archiveRequest.Method = "POST";
 | 
			
		||||
                                archiveRequest.Headers.Add("Authorization", "Basic " + encoded);
 | 
			
		||||
@ -628,8 +644,17 @@ namespace BackendWorkerService.Quartz.Jobs
 | 
			
		||||
                            List<Dictionary<string, object>> waterArchiveWeekRawDatas = new List<Dictionary<string, object>>();
 | 
			
		||||
                            foreach (var deviceNumberPoint in electricDeviceNumberPoints)
 | 
			
		||||
                            {
 | 
			
		||||
                                var station = buildingStation.Where(x => x.system_key == deviceNumberPoint.DeviceNumber.Split("_")[1]).Select(x => x.system_value).FirstOrDefault();
 | 
			
		||||
                                archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
 | 
			
		||||
                                device_number = deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "");
 | 
			
		||||
                                var station = backgroundServiceRepository.GetOneAsync<string>($@"select parent_path from import_niagara_item_history where device_building_tag = '{device_number.Split("_")[1].Replace("$3", "")}' and 
 | 
			
		||||
                                    device_system_tag = '{device_number.Split("_")[2]}' and device_name_tag = '{device_number.Split("_")[3]}' 
 | 
			
		||||
                                    and device_floor_tag = '{device_number.Split("_")[4]}' and device_master_tag = '{device_number.Split("_")[5]}' 
 | 
			
		||||
                                    and device_last_name_tag = '{device_number.Split("_")[6]}' and device_serial_tag = '{device_number.Split("_")[7]}'
 | 
			
		||||
                                    and device_point_name = '{device_number.Split("_")[8]}'").Result;
 | 
			
		||||
                                if (string.IsNullOrEmpty(station))
 | 
			
		||||
                                {
 | 
			
		||||
                                    continue;
 | 
			
		||||
                                }
 | 
			
		||||
                                archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "")}/~historyRollup/");
 | 
			
		||||
                                //HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
 | 
			
		||||
                                archiveRequest.Method = "POST";
 | 
			
		||||
                                archiveRequest.Headers.Add("Authorization", "Basic " + encoded);
 | 
			
		||||
@ -686,8 +711,13 @@ namespace BackendWorkerService.Quartz.Jobs
 | 
			
		||||
                            }
 | 
			
		||||
                            foreach (var deviceNumberPoint in waterDeviceNumberPoints)
 | 
			
		||||
                            {
 | 
			
		||||
                                var station = buildingStation.Where(x => x.system_key == deviceNumberPoint.DeviceNumber.Split("_")[1]).Select(x => x.system_value).FirstOrDefault();
 | 
			
		||||
                                archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
 | 
			
		||||
                                device_number = deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "");
 | 
			
		||||
                                var station = backgroundServiceRepository.GetOneAsync<string>($@"select parent_path from import_niagara_item_history where device_building_tag = '{device_number.Split("_")[1].Replace("$3", "")}' and 
 | 
			
		||||
                                    device_system_tag = '{device_number.Split("_")[2]}' and device_name_tag = '{device_number.Split("_")[3]}' 
 | 
			
		||||
                                    and device_floor_tag = '{device_number.Split("_")[4]}' and device_master_tag = '{device_number.Split("_")[5]}' 
 | 
			
		||||
                                    and device_last_name_tag = '{device_number.Split("_")[6]}' and device_serial_tag = '{device_number.Split("_")[7]}'
 | 
			
		||||
                                    and device_point_name = '{device_number.Split("_")[8]}'").Result;
 | 
			
		||||
                                archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "")}/~historyRollup/");
 | 
			
		||||
                                //HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
 | 
			
		||||
                                archiveRequest.Method = "POST";
 | 
			
		||||
                                archiveRequest.Headers.Add("Authorization", "Basic " + encoded);
 | 
			
		||||
@ -995,8 +1025,17 @@ namespace BackendWorkerService.Quartz.Jobs
 | 
			
		||||
                            List<Dictionary<string, object>> waterArchiveMonthRawDatas = new List<Dictionary<string, object>>();
 | 
			
		||||
                            foreach (var deviceNumberPoint in electricDeviceNumberPoints)
 | 
			
		||||
                            {
 | 
			
		||||
                                var station = buildingStation.Where(x => x.system_key == deviceNumberPoint.DeviceNumber.Split("_")[1]).Select(x => x.system_value).FirstOrDefault();
 | 
			
		||||
                                archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
 | 
			
		||||
                                device_number = deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "");
 | 
			
		||||
                                var station = backgroundServiceRepository.GetOneAsync<string>($@"select parent_path from import_niagara_item_history where device_building_tag = '{device_number.Split("_")[1].Replace("$3", "")}' and 
 | 
			
		||||
                                    device_system_tag = '{device_number.Split("_")[2]}' and device_name_tag = '{device_number.Split("_")[3]}' 
 | 
			
		||||
                                    and device_floor_tag = '{device_number.Split("_")[4]}' and device_master_tag = '{device_number.Split("_")[5]}' 
 | 
			
		||||
                                    and device_last_name_tag = '{device_number.Split("_")[6]}' and device_serial_tag = '{device_number.Split("_")[7]}'
 | 
			
		||||
                                    and device_point_name = '{device_number.Split("_")[8]}'").Result;
 | 
			
		||||
                                if (string.IsNullOrEmpty(station))
 | 
			
		||||
                                {
 | 
			
		||||
                                    continue;
 | 
			
		||||
                                }
 | 
			
		||||
                                archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "")}/~historyRollup/");
 | 
			
		||||
                                //HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
 | 
			
		||||
                                archiveRequest.Method = "POST";
 | 
			
		||||
                                archiveRequest.Headers.Add("Authorization", "Basic " + encoded);
 | 
			
		||||
@ -1052,8 +1091,13 @@ namespace BackendWorkerService.Quartz.Jobs
 | 
			
		||||
                            }
 | 
			
		||||
                            foreach (var deviceNumberPoint in waterDeviceNumberPoints)
 | 
			
		||||
                            {
 | 
			
		||||
                                var station = buildingStation.Where(x => x.system_key == deviceNumberPoint.DeviceNumber.Split("_")[1]).Select(x => x.system_value).FirstOrDefault();
 | 
			
		||||
                                archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
 | 
			
		||||
                                device_number = deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "");
 | 
			
		||||
                                var station = backgroundServiceRepository.GetOneAsync<string>($@"select parent_path from import_niagara_item_history where device_building_tag = '{device_number.Split("_")[1].Replace("$3", "")}' and 
 | 
			
		||||
                                    device_system_tag = '{device_number.Split("_")[2]}' and device_name_tag = '{device_number.Split("_")[3]}' 
 | 
			
		||||
                                    and device_floor_tag = '{device_number.Split("_")[4]}' and device_master_tag = '{device_number.Split("_")[5]}' 
 | 
			
		||||
                                    and device_last_name_tag = '{device_number.Split("_")[6]}' and device_serial_tag = '{device_number.Split("_")[7]}'
 | 
			
		||||
                                    and device_point_name = '{device_number.Split("_")[8]}'").Result;
 | 
			
		||||
                                archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "")}/~historyRollup/");
 | 
			
		||||
                                //HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
 | 
			
		||||
                                archiveRequest.Method = "POST";
 | 
			
		||||
                                archiveRequest.Headers.Add("Authorization", "Basic " + encoded);
 | 
			
		||||
@ -1354,35 +1398,105 @@ namespace BackendWorkerService.Quartz.Jobs
 | 
			
		||||
            {
 | 
			
		||||
                await task_Detail.WorkFail("ArchiveElectricMeterDayJob", "All", exception.ToString());
 | 
			
		||||
                logger.LogError("【ArchiveElectricMeterDayJob】【任務失敗】");
 | 
			
		||||
                logger.LogError("【ArchiveElectricMeterDayJob】【任務失敗】[Exception]:{0}", exception.ToString());
 | 
			
		||||
                logger.LogError("【ArchiveElectricMeterDayJob】【任務失敗】[Exception]:{0} {1}", exception.ToString());
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private List<Dictionary<string, object>> ArrangeRawData(DeviceNumberPoint deviceNumberPoint, JObject jsonResult)
 | 
			
		||||
        {
 | 
			
		||||
            List<Dictionary<string, object>> arrangeRawDatas = new List<Dictionary<string, object>>();
 | 
			
		||||
            var histories = jsonResult["obj"]["list"];
 | 
			
		||||
            var rawdateCount = Convert.ToInt32(jsonResult["obj"]["int"]["@val"].ToString());
 | 
			
		||||
 | 
			
		||||
            if(rawdateCount == 0)
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                return null;
 | 
			
		||||
            }
 | 
			
		||||
                var histories = jsonResult["obj"]["list"];
 | 
			
		||||
                var rawdateCount = Convert.ToInt32(jsonResult["obj"]["int"]["@val"].ToString());
 | 
			
		||||
 | 
			
		||||
            if (histories != null && histories.HasValues)
 | 
			
		||||
            {
 | 
			
		||||
                if (rawdateCount > 1)
 | 
			
		||||
                {   //多筆資料
 | 
			
		||||
                    foreach (var history in histories)
 | 
			
		||||
                    {
 | 
			
		||||
                if (rawdateCount == 0)
 | 
			
		||||
                {
 | 
			
		||||
                    return null;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (histories != null && histories.HasValues)
 | 
			
		||||
                {
 | 
			
		||||
                    if (rawdateCount > 1)
 | 
			
		||||
                    {   //多筆資料
 | 
			
		||||
                        foreach (var history in histories)
 | 
			
		||||
                        {
 | 
			
		||||
                            Dictionary<string, object> arrangeRawData = new Dictionary<string, object>();
 | 
			
		||||
                            arrangeRawData.Add("@device_number", deviceNumberPoint.DeviceNumber);
 | 
			
		||||
                            arrangeRawData.Add("@point", deviceNumberPoint.Point);
 | 
			
		||||
 | 
			
		||||
                            //時間
 | 
			
		||||
                            if (history["abstime"] != null && history["abstime"].HasValues)
 | 
			
		||||
                            {
 | 
			
		||||
                                foreach (var abstime in history["abstime"])
 | 
			
		||||
                                {
 | 
			
		||||
                                    var name = abstime["@name"].ToString();
 | 
			
		||||
                                    switch (name)
 | 
			
		||||
                                    {
 | 
			
		||||
                                        case "start":
 | 
			
		||||
                                            var startTimstamp = Convert.ToDateTime(abstime["@val"].ToString()).ToString("yyyy-MM-dd HH:mm:ss");
 | 
			
		||||
                                            arrangeRawData.Add("@start_timestamp", startTimstamp);
 | 
			
		||||
                                            break;
 | 
			
		||||
                                        case "end":
 | 
			
		||||
                                            var endTimstamp = Convert.ToDateTime(abstime["@val"].ToString()).ToString("yyyy-MM-dd HH:mm:ss");
 | 
			
		||||
                                            arrangeRawData.Add("@end_timestamp", endTimstamp);
 | 
			
		||||
                                            break;
 | 
			
		||||
                                    }
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
 | 
			
		||||
                            //區間內資料筆數
 | 
			
		||||
                            if (history["int"] != null && history["int"].HasValues)
 | 
			
		||||
                            {
 | 
			
		||||
                                var count = Convert.ToInt32(histories["obj"]["int"]["@val"].ToString());
 | 
			
		||||
                                arrangeRawData.Add("@count_rawdata", count);
 | 
			
		||||
                            }
 | 
			
		||||
 | 
			
		||||
                            //整合數值(最大、最小、平均、總和)
 | 
			
		||||
                            if (history["real"] != null && history["real"].HasValues)
 | 
			
		||||
                            {
 | 
			
		||||
                                foreach (var real in history["real"])
 | 
			
		||||
                                {
 | 
			
		||||
                                    var name = real["@name"].ToString();
 | 
			
		||||
                                    switch (name)
 | 
			
		||||
                                    {
 | 
			
		||||
                                        case "min":
 | 
			
		||||
                                            var min = real["@val"].ToString() == "NaN" ? -1 : Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float);
 | 
			
		||||
                                            arrangeRawData.Add("@min_rawdata", min);
 | 
			
		||||
                                            break;
 | 
			
		||||
                                        case "max":
 | 
			
		||||
                                            var max = real["@val"].ToString() == "NaN" ? -1 : Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float);
 | 
			
		||||
                                            arrangeRawData.Add("@max_rawdata", max);
 | 
			
		||||
                                            break;
 | 
			
		||||
                                        case "avg":
 | 
			
		||||
                                            var avg = real["@val"].ToString() == "NaN" ? -1 : Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float);
 | 
			
		||||
                                            arrangeRawData.Add("@avg_rawdata", avg);
 | 
			
		||||
                                            break;
 | 
			
		||||
                                        case "sum":
 | 
			
		||||
                                            var sum = real["@val"].ToString() == "NaN" ? -1 : Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float);
 | 
			
		||||
                                            arrangeRawData.Add("@sum_rawdata", sum);
 | 
			
		||||
                                            break;
 | 
			
		||||
                                    }
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                            arrangeRawData.Add("@is_complete", 1);
 | 
			
		||||
                            arrangeRawData.Add("@repeat_times", 0);
 | 
			
		||||
                            arrangeRawData.Add("@fail_reason", null);
 | 
			
		||||
                            arrangeRawData.Add("@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
 | 
			
		||||
 | 
			
		||||
                            arrangeRawDatas.Add(arrangeRawData);
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    else
 | 
			
		||||
                    {   //單筆資料
 | 
			
		||||
                        Dictionary<string, object> arrangeRawData = new Dictionary<string, object>();
 | 
			
		||||
                        arrangeRawData.Add("@device_number", deviceNumberPoint.DeviceNumber);
 | 
			
		||||
                        arrangeRawData.Add("@point", deviceNumberPoint.Point);
 | 
			
		||||
 | 
			
		||||
                        //時間
 | 
			
		||||
                        if (history["abstime"] != null && history["abstime"].HasValues)
 | 
			
		||||
                        if (histories["obj"]["abstime"] != null && histories["obj"]["abstime"].HasValues)
 | 
			
		||||
                        {
 | 
			
		||||
                            foreach (var abstime in history["abstime"])
 | 
			
		||||
                            foreach (var abstime in histories["obj"]["abstime"])
 | 
			
		||||
                            {
 | 
			
		||||
                                var name = abstime["@name"].ToString();
 | 
			
		||||
                                switch (name)
 | 
			
		||||
@ -1400,34 +1514,34 @@ namespace BackendWorkerService.Quartz.Jobs
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        //區間內資料筆數
 | 
			
		||||
                        if (history["int"] != null && history["int"].HasValues)
 | 
			
		||||
                        if (histories["obj"]["int"] != null && histories["obj"]["int"].HasValues)
 | 
			
		||||
                        {
 | 
			
		||||
                            var count = Convert.ToInt32(histories["obj"]["int"]["@val"].ToString());
 | 
			
		||||
                            arrangeRawData.Add("@count_rawdata", count);
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        //整合數值(最大、最小、平均、總和)
 | 
			
		||||
                        if (history["real"] != null && history["real"].HasValues)
 | 
			
		||||
                        if (histories["obj"]["real"] != null && histories["obj"]["real"].HasValues)
 | 
			
		||||
                        {
 | 
			
		||||
                            foreach (var real in history["real"])
 | 
			
		||||
                            foreach (var real in histories["obj"]["real"])
 | 
			
		||||
                            {
 | 
			
		||||
                                var name = real["@name"].ToString();
 | 
			
		||||
                                switch (name)
 | 
			
		||||
                                {
 | 
			
		||||
                                    case "min":
 | 
			
		||||
                                        var min = Convert.ToDecimal(real["@val"].ToString());
 | 
			
		||||
                                        var min = real["@val"].ToString() == "NaN" ? -1 : Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float);
 | 
			
		||||
                                        arrangeRawData.Add("@min_rawdata", min);
 | 
			
		||||
                                        break;
 | 
			
		||||
                                    case "max":
 | 
			
		||||
                                        var max = Convert.ToDecimal(real["@val"].ToString());
 | 
			
		||||
                                        var max = real["@val"].ToString() == "NaN" ? -1 : Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float);
 | 
			
		||||
                                        arrangeRawData.Add("@max_rawdata", max);
 | 
			
		||||
                                        break;
 | 
			
		||||
                                    case "avg":
 | 
			
		||||
                                        var avg = Convert.ToDecimal(real["@val"].ToString());
 | 
			
		||||
                                        var avg = real["@val"].ToString() == "NaN" ? -1 : Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float);
 | 
			
		||||
                                        arrangeRawData.Add("@avg_rawdata", avg);
 | 
			
		||||
                                        break;
 | 
			
		||||
                                    case "sum":
 | 
			
		||||
                                        var sum = Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float);
 | 
			
		||||
                                        var sum = real["@val"].ToString() == "NaN" ? -1 : Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float);
 | 
			
		||||
                                        arrangeRawData.Add("@sum_rawdata", sum);
 | 
			
		||||
                                        break;
 | 
			
		||||
                                }
 | 
			
		||||
@ -1441,76 +1555,17 @@ namespace BackendWorkerService.Quartz.Jobs
 | 
			
		||||
                        arrangeRawDatas.Add(arrangeRawData);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                else
 | 
			
		||||
                {   //單筆資料
 | 
			
		||||
                    Dictionary<string, object> arrangeRawData = new Dictionary<string, object>();
 | 
			
		||||
                    arrangeRawData.Add("@device_number", deviceNumberPoint.DeviceNumber);
 | 
			
		||||
                    arrangeRawData.Add("@point", deviceNumberPoint.Point);
 | 
			
		||||
 | 
			
		||||
                    //時間
 | 
			
		||||
                    if (histories["obj"]["abstime"] != null && histories["obj"]["abstime"].HasValues)
 | 
			
		||||
                    {
 | 
			
		||||
                        foreach (var abstime in histories["obj"]["abstime"])
 | 
			
		||||
                        {
 | 
			
		||||
                            var name = abstime["@name"].ToString();
 | 
			
		||||
                            switch (name)
 | 
			
		||||
                            {
 | 
			
		||||
                                case "start":
 | 
			
		||||
                                    var startTimstamp = Convert.ToDateTime(abstime["@val"].ToString()).ToString("yyyy-MM-dd HH:mm:ss");
 | 
			
		||||
                                    arrangeRawData.Add("@start_timestamp", startTimstamp);
 | 
			
		||||
                                    break;
 | 
			
		||||
                                case "end":
 | 
			
		||||
                                    var endTimstamp = Convert.ToDateTime(abstime["@val"].ToString()).ToString("yyyy-MM-dd HH:mm:ss");
 | 
			
		||||
                                    arrangeRawData.Add("@end_timestamp", endTimstamp);
 | 
			
		||||
                                    break;
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    //區間內資料筆數
 | 
			
		||||
                    if (histories["obj"]["int"] != null && histories["obj"]["int"].HasValues)
 | 
			
		||||
                    {
 | 
			
		||||
                        var count = Convert.ToInt32(histories["obj"]["int"]["@val"].ToString());
 | 
			
		||||
                        arrangeRawData.Add("@count_rawdata", count);
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    //整合數值(最大、最小、平均、總和)
 | 
			
		||||
                    if (histories["obj"]["real"] != null && histories["obj"]["real"].HasValues)
 | 
			
		||||
                    {
 | 
			
		||||
                        foreach (var real in histories["obj"]["real"])
 | 
			
		||||
                        {
 | 
			
		||||
                            var name = real["@name"].ToString();
 | 
			
		||||
                            switch (name)
 | 
			
		||||
                            {
 | 
			
		||||
                                case "min":
 | 
			
		||||
                                    var min = Convert.ToDecimal(real["@val"].ToString());
 | 
			
		||||
                                    arrangeRawData.Add("@min_rawdata", min);
 | 
			
		||||
                                    break;
 | 
			
		||||
                                case "max":
 | 
			
		||||
                                    var max = Convert.ToDecimal(real["@val"].ToString());
 | 
			
		||||
                                    arrangeRawData.Add("@max_rawdata", max);
 | 
			
		||||
                                    break;
 | 
			
		||||
                                case "avg":
 | 
			
		||||
                                    var avg = Convert.ToDecimal(real["@val"].ToString());
 | 
			
		||||
                                    arrangeRawData.Add("@avg_rawdata", avg);
 | 
			
		||||
                                    break;
 | 
			
		||||
                                case "sum":
 | 
			
		||||
                                    var sum = Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float);
 | 
			
		||||
                                    arrangeRawData.Add("@sum_rawdata", sum);
 | 
			
		||||
                                    break;
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    arrangeRawData.Add("@is_complete", 1);
 | 
			
		||||
                    arrangeRawData.Add("@repeat_times", 0);
 | 
			
		||||
                    arrangeRawData.Add("@fail_reason", null);
 | 
			
		||||
                    arrangeRawData.Add("@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
 | 
			
		||||
 | 
			
		||||
                    arrangeRawDatas.Add(arrangeRawData);
 | 
			
		||||
                }
 | 
			
		||||
                return arrangeRawDatas;
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception exception)
 | 
			
		||||
            {
 | 
			
		||||
                logger.LogError("【ArchiveElectricMeterDayJob】【任務失敗】");
 | 
			
		||||
                logger.LogError("【ArchiveElectricMeterDayJob】【任務失敗】[Exception]:{0}", exception.ToString());
 | 
			
		||||
                logger.LogError("【ArchiveElectricMeterDayJob】【任務失敗】[device_number]:{0}", deviceNumberPoint.FullDeviceNumberPoint);
 | 
			
		||||
                logger.LogError("【ArchiveElectricMeterDayJob】【任務失敗】[JsonString]:{0}", jsonResult.ToString());
 | 
			
		||||
                return arrangeRawDatas;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return arrangeRawDatas;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -189,7 +189,7 @@ namespace BackendWorkerService.Services.Implement
 | 
			
		||||
                //                                    <reltime name='interval' val = 'PT1H' />
 | 
			
		||||
                //                                </obj>";
 | 
			
		||||
 | 
			
		||||
                //            HttpWebRequest archiveHourRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
 | 
			
		||||
                //            HttpWebRequest archiveHourRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "")}/~historyRollup/");
 | 
			
		||||
                //            //HttpWebRequest archiveHourRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
 | 
			
		||||
                //            archiveHourRequest.Method = "POST";
 | 
			
		||||
                //            archiveHourRequest.Headers.Add("Authorization", "Basic " + encoded);
 | 
			
		||||
@ -280,8 +280,13 @@ namespace BackendWorkerService.Services.Implement
 | 
			
		||||
                                                    <reltime name='interval' val = 'PT1D' />
 | 
			
		||||
                                                </obj>";
 | 
			
		||||
 | 
			
		||||
                            var station = buildingStation.Where(x => x.system_key == deviceNumberPoint.DeviceNumber.Split("_")[1]).Select(x => x.system_value).FirstOrDefault();
 | 
			
		||||
                            HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
 | 
			
		||||
                            string device_number = deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "");
 | 
			
		||||
                            var station = backgroundServiceRepository.GetOneAsync<string>($@"select parent_path from import_niagara_item_history where device_building_tag = '{device_number.Split("_")[1].Replace("$3", "")}' and 
 | 
			
		||||
                                    device_system_tag = '{device_number.Split("_")[2]}' and device_name_tag = '{device_number.Split("_")[3]}' 
 | 
			
		||||
                                    and device_floor_tag = '{device_number.Split("_")[4]}' and device_master_tag = '{device_number.Split("_")[5]}' 
 | 
			
		||||
                                    and device_last_name_tag = '{device_number.Split("_")[6]}' and device_serial_tag = '{device_number.Split("_")[7]}'
 | 
			
		||||
                                    and device_point_name = '{device_number.Split("_")[8]}'").Result;
 | 
			
		||||
                            HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "")}/~historyRollup/");
 | 
			
		||||
                            //HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
 | 
			
		||||
                            archiveDayRequest.Method = "POST";
 | 
			
		||||
                            archiveDayRequest.Headers.Add("Authorization", "Basic " + encoded);
 | 
			
		||||
@ -371,8 +376,13 @@ namespace BackendWorkerService.Services.Implement
 | 
			
		||||
                                                    <reltime name='interval' val = 'PT1D' />
 | 
			
		||||
                                                </obj>";
 | 
			
		||||
 | 
			
		||||
                            var station = buildingStation.Where(x => x.system_key == deviceNumberPoint.DeviceNumber.Split("_")[1]).Select(x => x.system_value).FirstOrDefault();
 | 
			
		||||
                            HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
 | 
			
		||||
                            string device_number = deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "");
 | 
			
		||||
                            var station = backgroundServiceRepository.GetOneAsync<string>($@"select parent_path from import_niagara_item_history where device_building_tag = '{device_number.Split("_")[1].Replace("$3", "")}' and 
 | 
			
		||||
                                    device_system_tag = '{device_number.Split("_")[2]}' and device_name_tag = '{device_number.Split("_")[3]}' 
 | 
			
		||||
                                    and device_floor_tag = '{device_number.Split("_")[4]}' and device_master_tag = '{device_number.Split("_")[5]}' 
 | 
			
		||||
                                    and device_last_name_tag = '{device_number.Split("_")[6]}' and device_serial_tag = '{device_number.Split("_")[7]}'
 | 
			
		||||
                                    and device_point_name = '{device_number.Split("_")[8]}'").Result;
 | 
			
		||||
                            HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "")}/~historyRollup/");
 | 
			
		||||
                            //HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
 | 
			
		||||
                            archiveDayRequest.Method = "POST";
 | 
			
		||||
                            archiveDayRequest.Headers.Add("Authorization", "Basic " + encoded);
 | 
			
		||||
@ -460,8 +470,13 @@ namespace BackendWorkerService.Services.Implement
 | 
			
		||||
                                                <reltime name='interval' val = 'PT7D' />
 | 
			
		||||
                                            </obj>";
 | 
			
		||||
 | 
			
		||||
                        var station = buildingStation.Where(x => x.system_key == deviceNumberPoint.DeviceNumber.Split("_")[1]).Select(x => x.system_value).FirstOrDefault();
 | 
			
		||||
                        HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
 | 
			
		||||
                        string device_number = deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "");
 | 
			
		||||
                        var station = backgroundServiceRepository.GetOneAsync<string>($@"select parent_path from import_niagara_item_history where device_building_tag = '{device_number.Split("_")[1].Replace("$3", "")}' and 
 | 
			
		||||
                                    device_system_tag = '{device_number.Split("_")[2]}' and device_name_tag = '{device_number.Split("_")[3]}' 
 | 
			
		||||
                                    and device_floor_tag = '{device_number.Split("_")[4]}' and device_master_tag = '{device_number.Split("_")[5]}' 
 | 
			
		||||
                                    and device_last_name_tag = '{device_number.Split("_")[6]}' and device_serial_tag = '{device_number.Split("_")[7]}'
 | 
			
		||||
                                    and device_point_name = '{device_number.Split("_")[8]}'").Result;
 | 
			
		||||
                        HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "")}/~historyRollup/");
 | 
			
		||||
                        //HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
 | 
			
		||||
                        archiveWeekRequest.Method = "POST";
 | 
			
		||||
                        archiveWeekRequest.Headers.Add("Authorization", "Basic " + encoded);
 | 
			
		||||
@ -545,8 +560,13 @@ namespace BackendWorkerService.Services.Implement
 | 
			
		||||
                                                <reltime name='interval' val = 'PT7D' />
 | 
			
		||||
                                            </obj>";
 | 
			
		||||
 | 
			
		||||
                        var station = buildingStation.Where(x => x.system_key == deviceNumberPoint.DeviceNumber.Split("_")[1]).Select(x => x.system_value).FirstOrDefault();
 | 
			
		||||
                        HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
 | 
			
		||||
                        string device_number = deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "");
 | 
			
		||||
                        var station = backgroundServiceRepository.GetOneAsync<string>($@"select parent_path from import_niagara_item_history where device_building_tag = '{device_number.Split("_")[1].Replace("$3", "")}' and 
 | 
			
		||||
                                    device_system_tag = '{device_number.Split("_")[2]}' and device_name_tag = '{device_number.Split("_")[3]}' 
 | 
			
		||||
                                    and device_floor_tag = '{device_number.Split("_")[4]}' and device_master_tag = '{device_number.Split("_")[5]}' 
 | 
			
		||||
                                    and device_last_name_tag = '{device_number.Split("_")[6]}' and device_serial_tag = '{device_number.Split("_")[7]}'
 | 
			
		||||
                                    and device_point_name = '{device_number.Split("_")[8]}'").Result;
 | 
			
		||||
                        HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "")}/~historyRollup/");
 | 
			
		||||
                        //HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
 | 
			
		||||
                        archiveWeekRequest.Method = "POST";
 | 
			
		||||
                        archiveWeekRequest.Headers.Add("Authorization", "Basic " + encoded);
 | 
			
		||||
@ -636,8 +656,13 @@ namespace BackendWorkerService.Services.Implement
 | 
			
		||||
                                                <reltime name='interval' val = 'PT{dayInMonth}D' />
 | 
			
		||||
                                            </obj>";
 | 
			
		||||
 | 
			
		||||
                        var station = buildingStation.Where(x => x.system_key == deviceNumberPoint.DeviceNumber.Split("_")[1]).Select(x => x.system_value).FirstOrDefault();
 | 
			
		||||
                        HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
 | 
			
		||||
                        string device_number = deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "");
 | 
			
		||||
                        var station = backgroundServiceRepository.GetOneAsync<string>($@"select parent_path from import_niagara_item_history where device_building_tag = '{device_number.Split("_")[1].Replace("$3", "")}' and 
 | 
			
		||||
                                    device_system_tag = '{device_number.Split("_")[2]}' and device_name_tag = '{device_number.Split("_")[3]}' 
 | 
			
		||||
                                    and device_floor_tag = '{device_number.Split("_")[4]}' and device_master_tag = '{device_number.Split("_")[5]}' 
 | 
			
		||||
                                    and device_last_name_tag = '{device_number.Split("_")[6]}' and device_serial_tag = '{device_number.Split("_")[7]}'
 | 
			
		||||
                                    and device_point_name = '{device_number.Split("_")[8]}'").Result;
 | 
			
		||||
                        HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "")}/~historyRollup/");
 | 
			
		||||
                        //HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
 | 
			
		||||
                        archiveMonthRequest.Method = "POST";
 | 
			
		||||
                        archiveMonthRequest.Headers.Add("Authorization", "Basic " + encoded);
 | 
			
		||||
@ -724,8 +749,13 @@ namespace BackendWorkerService.Services.Implement
 | 
			
		||||
                                                <reltime name='interval' val = 'PT{dayInMonth}D' />
 | 
			
		||||
                                            </obj>";
 | 
			
		||||
 | 
			
		||||
                        var station = buildingStation.Where(x => x.system_key == deviceNumberPoint.DeviceNumber.Split("_")[1]).Select(x => x.system_value).FirstOrDefault();
 | 
			
		||||
                        HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
 | 
			
		||||
                        string device_number = deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "");
 | 
			
		||||
                        var station = backgroundServiceRepository.GetOneAsync<string>($@"select parent_path from import_niagara_item_history where device_building_tag = '{device_number.Split("_")[1].Replace("$3", "")}' and 
 | 
			
		||||
                                    device_system_tag = '{device_number.Split("_")[2]}' and device_name_tag = '{device_number.Split("_")[3]}' 
 | 
			
		||||
                                    and device_floor_tag = '{device_number.Split("_")[4]}' and device_master_tag = '{device_number.Split("_")[5]}' 
 | 
			
		||||
                                    and device_last_name_tag = '{device_number.Split("_")[6]}' and device_serial_tag = '{device_number.Split("_")[7]}'
 | 
			
		||||
                                    and device_point_name = '{device_number.Split("_")[8]}'").Result;
 | 
			
		||||
                        HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "")}/~historyRollup/");
 | 
			
		||||
                        //HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
 | 
			
		||||
                        archiveMonthRequest.Method = "POST";
 | 
			
		||||
                        archiveMonthRequest.Headers.Add("Authorization", "Basic " + encoded);
 | 
			
		||||
@ -855,15 +885,15 @@ namespace BackendWorkerService.Services.Implement
 | 
			
		||||
                                switch (name)
 | 
			
		||||
                                {
 | 
			
		||||
                                    case "min":
 | 
			
		||||
                                        var min = Convert.ToDecimal(real["@val"].ToString());
 | 
			
		||||
                                        var min = Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float);
 | 
			
		||||
                                        arrangeRawData.Add("@min_rawdata", min);
 | 
			
		||||
                                        break;
 | 
			
		||||
                                    case "max":
 | 
			
		||||
                                        var max = Convert.ToDecimal(real["@val"].ToString());
 | 
			
		||||
                                        var max = Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float);
 | 
			
		||||
                                        arrangeRawData.Add("@max_rawdata", max);
 | 
			
		||||
                                        break;
 | 
			
		||||
                                    case "avg":
 | 
			
		||||
                                        var avg = Convert.ToDecimal(real["@val"].ToString());
 | 
			
		||||
                                        var avg = Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float);
 | 
			
		||||
                                        arrangeRawData.Add("@avg_rawdata", avg);
 | 
			
		||||
                                        break;
 | 
			
		||||
                                    case "sum":
 | 
			
		||||
@ -923,15 +953,15 @@ namespace BackendWorkerService.Services.Implement
 | 
			
		||||
                            switch (name)
 | 
			
		||||
                            {
 | 
			
		||||
                                case "min":
 | 
			
		||||
                                    var min = Convert.ToDecimal(real["@val"].ToString());
 | 
			
		||||
                                    var min = Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float);
 | 
			
		||||
                                    arrangeRawData.Add("@min_rawdata", min);
 | 
			
		||||
                                    break;
 | 
			
		||||
                                case "max":
 | 
			
		||||
                                    var max = Convert.ToDecimal(real["@val"].ToString());
 | 
			
		||||
                                    var max = Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float);
 | 
			
		||||
                                    arrangeRawData.Add("@max_rawdata", max);
 | 
			
		||||
                                    break;
 | 
			
		||||
                                case "avg":
 | 
			
		||||
                                    var avg = Convert.ToDecimal(real["@val"].ToString());
 | 
			
		||||
                                    var avg = Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float);
 | 
			
		||||
                                    arrangeRawData.Add("@avg_rawdata", avg);
 | 
			
		||||
                                    break;
 | 
			
		||||
                                case "sum":
 | 
			
		||||
 | 
			
		||||
@ -283,8 +283,7 @@
 | 
			
		||||
 | 
			
		||||
            $('#devPointsList').html(strHtml);
 | 
			
		||||
 | 
			
		||||
            if (!hisFirst)
 | 
			
		||||
            {
 | 
			
		||||
            if (!hisFirst) {
 | 
			
		||||
                let start = new Date($('#his_startdate').val());
 | 
			
		||||
                let end = new Date(new Date().setDate(new Date($('#his_enddate input').val()).getDate() + 1));
 | 
			
		||||
 | 
			
		||||
@ -309,13 +308,27 @@
 | 
			
		||||
        var edt = new Date(new Date().setDate(sdt.getDate() + 1));
 | 
			
		||||
        start = start ?? sdt.toLocaleDateString();
 | 
			
		||||
        end = end ?? edt.toLocaleDateString();
 | 
			
		||||
        // callBackFromHistory();
 | 
			
		||||
        getHistoryDataByBaja(pageAct.deviceNumber + "_" + pageAct.deviceItem,
 | 
			
		||||
            new Date(start).getTime(),
 | 
			
		||||
            new Date(end).getTime(),
 | 
			
		||||
            pageAct.deviceName,
 | 
			
		||||
            pageAct.hisBuiName,
 | 
			
		||||
            callBackFromHistory);
 | 
			
		||||
 | 
			
		||||
        let sendData = {
 | 
			
		||||
            device_number: pageAct.deviceNumber,
 | 
			
		||||
            device_point: pageAct.deviceItem
 | 
			
		||||
        }
 | 
			
		||||
        objSendData.Data = sendData;
 | 
			
		||||
        let url = baseApiUrl + "/api/DevGetWay";
 | 
			
		||||
        ytAjax = new YourTeam.Ajax(url, objSendData, function (res) {
 | 
			
		||||
            if (res && res.code == "0000") {
 | 
			
		||||
                pageAct.hisBuiName = res.data;
 | 
			
		||||
                getHistoryDataByBaja(pageAct.deviceNumber + "_" + pageAct.deviceItem,
 | 
			
		||||
                    new Date(start).getTime(),
 | 
			
		||||
                    new Date(end).getTime(),
 | 
			
		||||
                    pageAct.deviceName,
 | 
			
		||||
                    pageAct.hisBuiName,
 | 
			
		||||
                    callBackFromHistory);
 | 
			
		||||
            }
 | 
			
		||||
            else {
 | 
			
		||||
                $(loadEle).Loading("close");
 | 
			
		||||
            }
 | 
			
		||||
        }, function (res) { $(loadEle).Loading("close"); }, "POST", true).send();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    function callBackFromHistory(res = '{"count":0,"data":[]}') {
 | 
			
		||||
@ -447,44 +460,44 @@
 | 
			
		||||
                v.type = pageAct.devicePoiName.split(" ")[0];
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
			let tag = "#historyTable";
 | 
			
		||||
            let tag = "#historyTable";
 | 
			
		||||
 | 
			
		||||
			let column_defs = [
 | 
			
		||||
				{ "targets": [0], "width": "20%", "sortable": true },
 | 
			
		||||
				{ "targets": [1], "width": "20%", "sortable": true },
 | 
			
		||||
				{ "targets": [2], "width": "20%", "sortable": true }
 | 
			
		||||
			];
 | 
			
		||||
            let column_defs = [
 | 
			
		||||
                { "targets": [0], "width": "20%", "sortable": true },
 | 
			
		||||
                { "targets": [1], "width": "20%", "sortable": true },
 | 
			
		||||
                { "targets": [2], "width": "20%", "sortable": true }
 | 
			
		||||
            ];
 | 
			
		||||
 | 
			
		||||
			let columns = [
 | 
			
		||||
				{
 | 
			
		||||
					"title": "類別",
 | 
			
		||||
					"data": "type"
 | 
			
		||||
				},
 | 
			
		||||
				{
 | 
			
		||||
					"title": "設備名稱",
 | 
			
		||||
					"data": "deviceName",
 | 
			
		||||
				},
 | 
			
		||||
				{
 | 
			
		||||
					"title": "數值",
 | 
			
		||||
					"data": "value",
 | 
			
		||||
					"render": function (data) {
 | 
			
		||||
						if (isNaN(data.toString())) {
 | 
			
		||||
							return data
 | 
			
		||||
						}
 | 
			
		||||
						return data.roundDecimal(2);
 | 
			
		||||
					}
 | 
			
		||||
				},
 | 
			
		||||
				{
 | 
			
		||||
					"title": "紀錄時間",
 | 
			
		||||
					"data": "timestamp",
 | 
			
		||||
					"render": function (data) {
 | 
			
		||||
						return displayDate(data, "datetime");
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
			];
 | 
			
		||||
            let columns = [
 | 
			
		||||
                {
 | 
			
		||||
                    "title": "類別",
 | 
			
		||||
                    "data": "type"
 | 
			
		||||
                },
 | 
			
		||||
                {
 | 
			
		||||
                    "title": "設備名稱",
 | 
			
		||||
                    "data": "deviceName",
 | 
			
		||||
                },
 | 
			
		||||
                {
 | 
			
		||||
                    "title": "數值",
 | 
			
		||||
                    "data": "value",
 | 
			
		||||
                    "render": function (data) {
 | 
			
		||||
                        if (isNaN(data.toString())) {
 | 
			
		||||
                            return data
 | 
			
		||||
                        }
 | 
			
		||||
                        return data.roundDecimal(2);
 | 
			
		||||
                    }
 | 
			
		||||
                },
 | 
			
		||||
                {
 | 
			
		||||
                    "title": "紀錄時間",
 | 
			
		||||
                    "data": "timestamp",
 | 
			
		||||
                    "render": function (data) {
 | 
			
		||||
                        return displayDate(data, "datetime");
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            ];
 | 
			
		||||
 | 
			
		||||
            historyTable = new YourTeam.JqDataTables.getTableByStatic(tag, data, columns, column_defs, null, null, null, null, "tpi");
 | 
			
		||||
            $(tag).DataTable().order([ 3, 'desc' ]);
 | 
			
		||||
            $(tag).DataTable().order([3, 'desc']);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -496,6 +509,7 @@
 | 
			
		||||
        v.starttime = (pageAct.dateType == "month" ? new Date($('#getmonth').val()) : new Date($('#his_startdate').val()));
 | 
			
		||||
        v.endtime = $('#his_enddate input').val() === "" ? null : new Date($('#his_enddate input').val());
 | 
			
		||||
        v.dateType = pageAct.dateType;
 | 
			
		||||
        v.device_number = pageAct.deviceNumber;
 | 
			
		||||
        objSendData.Data = v;
 | 
			
		||||
 | 
			
		||||
        $.ajax({
 | 
			
		||||
@ -535,25 +549,25 @@
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //選擇棟別
 | 
			
		||||
  function SelectBuild(e, building_tag) {
 | 
			
		||||
    $(loadEle).Loading("start");
 | 
			
		||||
    checkIsSelectedBuilding();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  function checkIsSelectedBuilding() {
 | 
			
		||||
    let result = false;
 | 
			
		||||
    let buildingRadios = $("[name=buildingRadio]:checked");
 | 
			
		||||
    buildingTag = null;
 | 
			
		||||
    if (buildingRadios && buildingRadios.length > 0) {
 | 
			
		||||
        $("[name=buildingRadio]").parent().removeClass("btn-info");
 | 
			
		||||
        $("[name=buildingRadio]").parent().addClass("btn-secondary");
 | 
			
		||||
        $("[name=buildingRadio]:checked").parent().removeClass("btn-secondary");
 | 
			
		||||
        $("[name=buildingRadio]:checked").parent().addClass("btn-info");
 | 
			
		||||
        buildingTag = buildingRadios.val(); //building tag
 | 
			
		||||
        pageAct.hisBuiName = buildingRadios.prop('id').split("-")[1];
 | 
			
		||||
        initList();
 | 
			
		||||
        result = true;
 | 
			
		||||
    function SelectBuild(e, building_tag) {
 | 
			
		||||
        $(loadEle).Loading("start");
 | 
			
		||||
        checkIsSelectedBuilding();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    function checkIsSelectedBuilding() {
 | 
			
		||||
        let result = false;
 | 
			
		||||
        let buildingRadios = $("[name=buildingRadio]:checked");
 | 
			
		||||
        buildingTag = null;
 | 
			
		||||
        if (buildingRadios && buildingRadios.length > 0) {
 | 
			
		||||
            $("[name=buildingRadio]").parent().removeClass("btn-info");
 | 
			
		||||
            $("[name=buildingRadio]").parent().addClass("btn-secondary");
 | 
			
		||||
            $("[name=buildingRadio]:checked").parent().removeClass("btn-secondary");
 | 
			
		||||
            $("[name=buildingRadio]:checked").parent().addClass("btn-info");
 | 
			
		||||
            buildingTag = buildingRadios.val(); //building tag
 | 
			
		||||
            pageAct.hisBuiName = buildingRadios.prop('id').split("-")[1];
 | 
			
		||||
            initList();
 | 
			
		||||
            result = true;
 | 
			
		||||
        }
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
    return result;
 | 
			
		||||
  }
 | 
			
		||||
</script>
 | 
			
		||||
@ -1,4 +1,5 @@
 | 
			
		||||
using FrontendWebApi.Models;
 | 
			
		||||
using Microsoft.AspNetCore.Localization;
 | 
			
		||||
using Microsoft.AspNetCore.Mvc;
 | 
			
		||||
using Microsoft.AspNetCore.Routing;
 | 
			
		||||
using Microsoft.Extensions.Logging;
 | 
			
		||||
@ -58,10 +59,13 @@ namespace FrontendWebApi.ApiControllers
 | 
			
		||||
            //    apiResult.Msg = "沒有資料匯入";
 | 
			
		||||
            //    return apiResult;
 | 
			
		||||
            //}
 | 
			
		||||
            var fileDateName = lhe.dateType == "today" ? lhe.starttime.ToString("yyyy-MM-dd")
 | 
			
		||||
            string fileDateName = lhe.dateType == "today" ? lhe.starttime.ToString("yyyy-MM-dd")
 | 
			
		||||
                                    : lhe.dateType == "month" ? lhe.starttime.ToString("yyyy-MM")
 | 
			
		||||
                                    : lhe.starttime.ToString("yyyy-MM-dd") + "_" + ((DateTime)lhe.endtime).ToString("yyyy-MM-dd");
 | 
			
		||||
            var fileName = "歷史資料_" + fileDateName + ".xlsx";
 | 
			
		||||
            string fileName = "歷史資料_" + fileDateName + ".xlsx";
 | 
			
		||||
            lhe.device_number = char.IsDigit(lhe.device_number.Split("_")[1][0]) 
 | 
			
		||||
                                ? lhe.device_number.Replace(lhe.device_number.Split("_")[1], "$3" + lhe.device_number.Split("_")[1]) 
 | 
			
		||||
                                : lhe.device_number;
 | 
			
		||||
            XSSFWorkbook workbook = new XSSFWorkbook();
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
@ -79,24 +83,21 @@ namespace FrontendWebApi.ApiControllers
 | 
			
		||||
                var buildStation = backendRepository.GetAllAsync<BuildStation>("select SUBSTRING_INDEX(system_value, '/', 1) system_value, system_key from variable where system_type = 'dashboard_total_elec' and deleted = 0 and (SUBSTRING_INDEX(system_value, '/', 1) != '' and SUBSTRING_INDEX(system_value, '/', 1) is not null)").Result;
 | 
			
		||||
 | 
			
		||||
                #region get device and device_item(point)
 | 
			
		||||
                var device = backendRepository.GetAllAsync<Device>($"select * from device where deleted = 0 and is_link = 1 and device_building_tag in ('{string.Join("','", building.Select(x => x.building_tag))}')").Result;
 | 
			
		||||
                var devicePoint = backendRepository.GetAllAsync<Device_item>($"select * from device_item where deleted = 0 and is_link = 1 and is_show_history = 1 and device_building_tag in ('{string.Join("','", building.Select(x => x.building_tag))}')").Result;
 | 
			
		||||
                var device = backendRepository.GetAllAsync<Device>($"select * from device where deleted = 0 and is_link = 1 and device_number = '{lhe.device_number}'").Result;
 | 
			
		||||
                var devicePoint = backendRepository.GetAllAsync<Device_item>($"select * from device_item where deleted = 0 and is_link = 1 and is_show_history = 1 and device_building_tag = '{lhe.device_number.Split("_")[1]}' and device_system_tag = '{lhe.device_number.Split("_")[2]}' and device_name_tag = '{lhe.device_number.Split("_")[3]}'").Result;
 | 
			
		||||
                #endregion
 | 
			
		||||
                List<DeviceNumberPoint> listDevicePoint = new List<DeviceNumberPoint>();
 | 
			
		||||
 | 
			
		||||
                #region combine device and point
 | 
			
		||||
                foreach (var d in device)
 | 
			
		||||
                var dp = devicePoint.Where(x => x.device_building_tag == lhe.device_number.Split("_")[1]).ToList();
 | 
			
		||||
                foreach (var point in dp)
 | 
			
		||||
                {
 | 
			
		||||
                    var dp = devicePoint.Where(x => x.device_building_tag == d.device_building_tag).ToList();
 | 
			
		||||
                    foreach (var point in dp)
 | 
			
		||||
                    {
 | 
			
		||||
                        DeviceNumberPoint deviceNumberPoint = new DeviceNumberPoint();
 | 
			
		||||
                        deviceNumberPoint.DeviceNumber = d.device_number;
 | 
			
		||||
                        deviceNumberPoint.Point = point.points;
 | 
			
		||||
                        deviceNumberPoint.FullDeviceNumberPoint = string.Format("{0}_{1}", d.device_number, point.points);
 | 
			
		||||
                    DeviceNumberPoint deviceNumberPoint = new DeviceNumberPoint();
 | 
			
		||||
                    deviceNumberPoint.DeviceNumber = lhe.device_number;
 | 
			
		||||
                    deviceNumberPoint.Point = point.points;
 | 
			
		||||
                    deviceNumberPoint.FullDeviceNumberPoint = string.Format("{0}_{1}", lhe.device_number, point.points);
 | 
			
		||||
 | 
			
		||||
                        listDevicePoint.Add(deviceNumberPoint);
 | 
			
		||||
                    }
 | 
			
		||||
                    listDevicePoint.Add(deviceNumberPoint);
 | 
			
		||||
                }
 | 
			
		||||
                #endregion
 | 
			
		||||
 | 
			
		||||
@ -117,35 +118,47 @@ namespace FrontendWebApi.ApiControllers
 | 
			
		||||
                    foreach (var d in listDevicePoint)
 | 
			
		||||
                    {
 | 
			
		||||
                        string buildingTag = d.DeviceNumber.Split("_")[1];
 | 
			
		||||
                        var station = buildStation.Where(x => x.system_key == buildingTag).Select(x => x.system_value).FirstOrDefault();
 | 
			
		||||
                        var archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{d.FullDeviceNumberPoint}/~historyRollup/");
 | 
			
		||||
                        archiveRequest.Method = "POST";
 | 
			
		||||
                        archiveRequest.Headers.Add("Authorization", "Basic " + encoded);
 | 
			
		||||
                        archiveRequest.PreAuthenticate = true;
 | 
			
		||||
                        var station = backendRepository.GetOneAsync<string>($@"select parent_path from import_niagara_item_history where device_building_tag = '{d.FullDeviceNumberPoint.Split("_")[1].Replace("$3", "")}' and 
 | 
			
		||||
                                    device_system_tag = '{d.FullDeviceNumberPoint.Split("_")[2]}' and device_name_tag = '{d.FullDeviceNumberPoint.Split("_")[3]}' 
 | 
			
		||||
                                    and device_floor_tag = '{d.FullDeviceNumberPoint.Split("_")[4]}' and device_master_tag = '{d.FullDeviceNumberPoint.Split("_")[5]}' 
 | 
			
		||||
                                    and device_last_name_tag = '{d.FullDeviceNumberPoint.Split("_")[6]}' and device_serial_tag = '{d.FullDeviceNumberPoint.Split("_")[7]}'
 | 
			
		||||
                                    and device_point_name = '{d.FullDeviceNumberPoint.Split("_")[8]}'").Result;
 | 
			
		||||
 | 
			
		||||
                        byte[] byteArray = Encoding.UTF8.GetBytes(historyQueryFilter);
 | 
			
		||||
                        using (Stream reqStream = archiveRequest.GetRequestStream())
 | 
			
		||||
                        if (!string.IsNullOrEmpty(station))
 | 
			
		||||
                        {
 | 
			
		||||
                            reqStream.Write(byteArray, 0, byteArray.Length);
 | 
			
		||||
                            var archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{d.FullDeviceNumberPoint.Replace("$3", "")}/~historyRollup/");
 | 
			
		||||
                            archiveRequest.Method = "POST";
 | 
			
		||||
                            archiveRequest.Headers.Add("Authorization", "Basic " + encoded);
 | 
			
		||||
                            archiveRequest.PreAuthenticate = true;
 | 
			
		||||
 | 
			
		||||
                            byte[] byteArray = Encoding.UTF8.GetBytes(historyQueryFilter);
 | 
			
		||||
                            using (Stream reqStream = archiveRequest.GetRequestStream())
 | 
			
		||||
                            {
 | 
			
		||||
                                reqStream.Write(byteArray, 0, byteArray.Length);
 | 
			
		||||
                            }
 | 
			
		||||
 | 
			
		||||
                            var archiveResponse = (HttpWebResponse)archiveRequest.GetResponse();
 | 
			
		||||
                            var archiveResponseContent = new StreamReader(archiveResponse.GetResponseStream()).ReadToEnd();
 | 
			
		||||
                            archiveResponse.Dispose();
 | 
			
		||||
                            archiveResponse.Close();
 | 
			
		||||
 | 
			
		||||
                            XmlDocument xmlDocument = new XmlDocument();
 | 
			
		||||
                            xmlDocument.LoadXml(archiveResponseContent);
 | 
			
		||||
                            var archiveJson = JsonConvert.SerializeXmlNode(xmlDocument);
 | 
			
		||||
                            var archiveJsonResult = (JObject)JsonConvert.DeserializeObject(archiveJson);
 | 
			
		||||
 | 
			
		||||
                            if (!archiveJsonResult.ContainsKey("err"))
 | 
			
		||||
                            {
 | 
			
		||||
                                var jsonDevice = new JsonDevice();
 | 
			
		||||
                                jsonDevice.deviceNumberPoint = d;
 | 
			
		||||
                                jsonDevice.json = archiveJsonResult;
 | 
			
		||||
                                jsonDevice.building_tag = buildingTag;
 | 
			
		||||
                                jd.Add(jsonDevice);
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        var archiveResponse = (HttpWebResponse)archiveRequest.GetResponse();
 | 
			
		||||
                        var archiveResponseContent = new StreamReader(archiveResponse.GetResponseStream()).ReadToEnd();
 | 
			
		||||
                        archiveResponse.Dispose();
 | 
			
		||||
                        archiveResponse.Close();
 | 
			
		||||
 | 
			
		||||
                        XmlDocument xmlDocument = new XmlDocument();
 | 
			
		||||
                        xmlDocument.LoadXml(archiveResponseContent);
 | 
			
		||||
                        var archiveJson = JsonConvert.SerializeXmlNode(xmlDocument);
 | 
			
		||||
                        var archiveJsonResult = (JObject)JsonConvert.DeserializeObject(archiveJson);
 | 
			
		||||
 | 
			
		||||
                        if (!archiveJsonResult.ContainsKey("err"))
 | 
			
		||||
                        else
 | 
			
		||||
                        {
 | 
			
		||||
                            var jsonDevice = new JsonDevice();
 | 
			
		||||
                            jsonDevice.deviceNumberPoint = d;
 | 
			
		||||
                            jsonDevice.json = archiveJsonResult;
 | 
			
		||||
                            jsonDevice.building_tag = buildingTag;
 | 
			
		||||
                            jd.Add(jsonDevice);
 | 
			
		||||
                            Logger.LogError("【Device GetWay Error】, device_number: " + d.FullDeviceNumberPoint);
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
@ -162,7 +175,7 @@ namespace FrontendWebApi.ApiControllers
 | 
			
		||||
                                HistoryExport hed = new HistoryExport();
 | 
			
		||||
                                hed.type = devicePoint.Where(x => x.device_building_tag == d.building_tag && x.points == ard["@point"].ToString()).Select(x => x.full_name).FirstOrDefault();
 | 
			
		||||
                                hed.deviceName = device.Where(x => x.device_number == ard["@device_number"].ToString()).Select(x => x.full_name).FirstOrDefault();
 | 
			
		||||
                                hed.value = (double)((decimal)ard["@avg_rawdata"]);
 | 
			
		||||
                                hed.value = ard["@avg_rawdata"].ToString() == "-1" ? "NaN" : Math.Round((decimal.Parse(ard["@avg_rawdata"].ToString(), System.Globalization.NumberStyles.Float)), 2).ToString();
 | 
			
		||||
                                hed.timestamp = Convert.ToDateTime(ard["@start_timestamp"].ToString());
 | 
			
		||||
                                hed.building_tag = d.building_tag;
 | 
			
		||||
                                he.Add(hed);
 | 
			
		||||
@ -173,12 +186,6 @@ namespace FrontendWebApi.ApiControllers
 | 
			
		||||
                #endregion
 | 
			
		||||
 | 
			
		||||
                #region export file progress
 | 
			
		||||
                //var filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "excel", "history");
 | 
			
		||||
 | 
			
		||||
                //if (!System.IO.Directory.Exists(filePath))
 | 
			
		||||
                //    System.IO.Directory.CreateDirectory(filePath);
 | 
			
		||||
 | 
			
		||||
                
 | 
			
		||||
                #region excel設定
 | 
			
		||||
                IFont font12 = workbook.CreateFont();
 | 
			
		||||
                font12.FontName = "新細明體";
 | 
			
		||||
@ -220,14 +227,16 @@ namespace FrontendWebApi.ApiControllers
 | 
			
		||||
                stylein12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
 | 
			
		||||
                stylein12.WrapText = true;
 | 
			
		||||
                #endregion
 | 
			
		||||
 | 
			
		||||
                foreach (var b in building)
 | 
			
		||||
                var data = he.ToList();
 | 
			
		||||
                if (data.Count > 0)
 | 
			
		||||
                {
 | 
			
		||||
                    var data = he.Where(x => x.building_tag == b.building_tag).ToList();
 | 
			
		||||
                    ISheet sheet = workbook.CreateSheet($"{b.full_name}歷史資料");
 | 
			
		||||
                    string lastDeviceItem = string.Empty;
 | 
			
		||||
                    int RowPosition = 0;
 | 
			
		||||
                    IRow row;
 | 
			
		||||
                    ISheet sheet;
 | 
			
		||||
                    #region set cell
 | 
			
		||||
                    IRow row = sheet.CreateRow(RowPosition);
 | 
			
		||||
                    sheet = workbook.CreateSheet($"{building.Where(x => x.building_tag == lhe.device_number.Split("_")[1]).Select(x => x.full_name).FirstOrDefault()}{"_" + data[0].type}");
 | 
			
		||||
                    row = sheet.CreateRow(RowPosition);
 | 
			
		||||
                    sheet.SetColumnWidth(0, 4 * 160 * 12);
 | 
			
		||||
                    sheet.SetColumnWidth(1, 4 * 160 * 12);
 | 
			
		||||
                    sheet.SetColumnWidth(2, 4 * 160 * 12);
 | 
			
		||||
@ -245,50 +254,66 @@ namespace FrontendWebApi.ApiControllers
 | 
			
		||||
                    cell.CellStyle = styleLine12;
 | 
			
		||||
                    #endregion
 | 
			
		||||
 | 
			
		||||
                    if (data.Count > 0)
 | 
			
		||||
                    foreach (var d in data)
 | 
			
		||||
                    {
 | 
			
		||||
                        foreach (var d in data)
 | 
			
		||||
                        if (RowPosition == 0 && lastDeviceItem == "")
 | 
			
		||||
                        {
 | 
			
		||||
                            RowPosition += 1;
 | 
			
		||||
                            lastDeviceItem = d.type; //第一次不用建立 sheet;
 | 
			
		||||
                        }
 | 
			
		||||
                        if (d.type != lastDeviceItem)
 | 
			
		||||
                        {
 | 
			
		||||
                            lastDeviceItem = d.type;
 | 
			
		||||
                            sheet = workbook.CreateSheet($"{building.Where(x => x.building_tag == lhe.device_number.Split("_")[1]).Select(x => x.full_name).FirstOrDefault()}{"_" + d.type}");
 | 
			
		||||
                            #region set cell
 | 
			
		||||
                            row = sheet.CreateRow(RowPosition);
 | 
			
		||||
                            for (var i = 0; i < 4; i++)
 | 
			
		||||
                            {
 | 
			
		||||
                                cell = row.CreateCell(i);
 | 
			
		||||
                                if (i == 0)
 | 
			
		||||
                                {
 | 
			
		||||
                                    cell.SetCellValue(d.type);
 | 
			
		||||
                                }
 | 
			
		||||
                                if (i == 1)
 | 
			
		||||
                                {
 | 
			
		||||
                                    cell.SetCellValue(d.deviceName);
 | 
			
		||||
                                }
 | 
			
		||||
                                if (i == 2)
 | 
			
		||||
                                {
 | 
			
		||||
                                    cell.SetCellValue(d.value);
 | 
			
		||||
                                }
 | 
			
		||||
                                if (i == 3)
 | 
			
		||||
                                {
 | 
			
		||||
                                    cell.SetCellValue(d.timestamp.ToString("yyyy-MM-dd HH:mm") + ":00");//
 | 
			
		||||
                                }
 | 
			
		||||
                            sheet.SetColumnWidth(0, 4 * 160 * 12);
 | 
			
		||||
                            sheet.SetColumnWidth(1, 4 * 160 * 12);
 | 
			
		||||
                            sheet.SetColumnWidth(2, 4 * 160 * 12);
 | 
			
		||||
                            sheet.SetColumnWidth(3, 4 * 160 * 12);
 | 
			
		||||
                            cell = row.CreateCell(0);
 | 
			
		||||
                            cell.SetCellValue("類型");
 | 
			
		||||
                            cell.CellStyle = styleLine12;
 | 
			
		||||
                            cell = row.CreateCell(1);
 | 
			
		||||
                            cell.SetCellValue("設備名稱");
 | 
			
		||||
                            cell.CellStyle = styleLine12;
 | 
			
		||||
                            cell = row.CreateCell(2);
 | 
			
		||||
                            cell.SetCellValue("數值");
 | 
			
		||||
                            cell = row.CreateCell(3);
 | 
			
		||||
                            cell.SetCellValue("記錄時間");
 | 
			
		||||
                            cell.CellStyle = styleLine12;
 | 
			
		||||
                            #endregion
 | 
			
		||||
                            RowPosition = 0;
 | 
			
		||||
                        }
 | 
			
		||||
                        else {
 | 
			
		||||
                            RowPosition += 1;
 | 
			
		||||
                        }
 | 
			
		||||
                        
 | 
			
		||||
                                cell.CellStyle = style12;
 | 
			
		||||
                        row = sheet.CreateRow(RowPosition);
 | 
			
		||||
                        for (var i = 0; i < 4; i++)
 | 
			
		||||
                        {
 | 
			
		||||
                            cell = row.CreateCell(i);
 | 
			
		||||
                            if (i == 0)
 | 
			
		||||
                            {
 | 
			
		||||
                                cell.SetCellValue(d.type);
 | 
			
		||||
                            }
 | 
			
		||||
                            if (i == 1)
 | 
			
		||||
                            {
 | 
			
		||||
                                cell.SetCellValue(d.deviceName);
 | 
			
		||||
                            }
 | 
			
		||||
                            if (i == 2)
 | 
			
		||||
                            {
 | 
			
		||||
                                cell.SetCellValue(d.value);
 | 
			
		||||
                            }
 | 
			
		||||
                            if (i == 3)
 | 
			
		||||
                            {
 | 
			
		||||
                                cell.SetCellValue(d.timestamp.ToString("yyyy-MM-dd HH:mm") + ":00");//
 | 
			
		||||
                            }
 | 
			
		||||
 | 
			
		||||
                            cell.CellStyle = style12;
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                
 | 
			
		||||
                
 | 
			
		||||
 | 
			
		||||
                //using (var fs = new FileStream(Path.Combine(filePath, fileName), FileMode.Create, FileAccess.Write))
 | 
			
		||||
                //{
 | 
			
		||||
                    //workbook.Write(fs);
 | 
			
		||||
                    
 | 
			
		||||
                //}
 | 
			
		||||
                #endregion
 | 
			
		||||
 | 
			
		||||
                //apiResult.Code = "0000";
 | 
			
		||||
                //apiResult.Data = "history/" + fileName;
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception exception)
 | 
			
		||||
            {
 | 
			
		||||
@ -451,7 +476,7 @@ namespace FrontendWebApi.ApiControllers
 | 
			
		||||
                List<DeviceItem> deviceItems = new List<DeviceItem>();
 | 
			
		||||
                var main_system_value = hf.device_number.Split('_')[2];
 | 
			
		||||
                var sub_system_value = hf.device_number.Split('_')[3];
 | 
			
		||||
                var building_tag = hf.device_number.Split('_')[1];
 | 
			
		||||
                var building_tag = char.IsDigit(hf.device_number.Split('_')[1][0]) ? "$3" + hf.device_number.Split('_')[1] : hf.device_number.Split('_')[1];
 | 
			
		||||
                var sqlString = $@"select * from device_item where deleted = 0 and device_system_tag = @main_system_value and device_name_tag = @sub_system_value and is_show_history = 1 and device_building_tag = @building_tag";
 | 
			
		||||
                deviceItems = await frontendRepository.GetAllAsync<DeviceItem>(sqlString, new { @main_system_value = main_system_value, @sub_system_value = sub_system_value, building_tag = building_tag });
 | 
			
		||||
 | 
			
		||||
@ -1391,19 +1416,19 @@ namespace FrontendWebApi.ApiControllers
 | 
			
		||||
                                switch (name)
 | 
			
		||||
                                {
 | 
			
		||||
                                    case "min":
 | 
			
		||||
                                        var min = Convert.ToDecimal(real["@val"].ToString());
 | 
			
		||||
                                        var min = real["@val"].ToString() == "NaN" ? -1 : Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float);
 | 
			
		||||
                                        arrangeRawData.Add("@min_rawdata", min);
 | 
			
		||||
                                        break;
 | 
			
		||||
                                    case "max":
 | 
			
		||||
                                        var max = Convert.ToDecimal(real["@val"].ToString());
 | 
			
		||||
                                        var max = real["@val"].ToString() == "NaN" ? -1 : Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float);
 | 
			
		||||
                                        arrangeRawData.Add("@max_rawdata", max);
 | 
			
		||||
                                        break;
 | 
			
		||||
                                    case "avg":
 | 
			
		||||
                                        var avg = Convert.ToDecimal(real["@val"].ToString());
 | 
			
		||||
                                        var avg = real["@val"].ToString() == "NaN" ? -1 : Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float);
 | 
			
		||||
                                        arrangeRawData.Add("@avg_rawdata", avg);
 | 
			
		||||
                                        break;
 | 
			
		||||
                                    case "sum":
 | 
			
		||||
                                        var sum = Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float);
 | 
			
		||||
                                        var sum = real["@val"].ToString() == "NaN" ? -1 : Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float);
 | 
			
		||||
                                        arrangeRawData.Add("@sum_rawdata", sum);
 | 
			
		||||
                                        break;
 | 
			
		||||
                                }
 | 
			
		||||
@ -1459,19 +1484,19 @@ namespace FrontendWebApi.ApiControllers
 | 
			
		||||
                            switch (name)
 | 
			
		||||
                            {
 | 
			
		||||
                                case "min":
 | 
			
		||||
                                    var min = Convert.ToDecimal(real["@val"].ToString());
 | 
			
		||||
                                    var min = real["@val"].ToString() == "NaN" ? -1 : Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float);
 | 
			
		||||
                                    arrangeRawData.Add("@min_rawdata", min);
 | 
			
		||||
                                    break;
 | 
			
		||||
                                case "max":
 | 
			
		||||
                                    var max = Convert.ToDecimal(real["@val"].ToString());
 | 
			
		||||
                                    var max = real["@val"].ToString() == "NaN" ? -1 : Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float);
 | 
			
		||||
                                    arrangeRawData.Add("@max_rawdata", max);
 | 
			
		||||
                                    break;
 | 
			
		||||
                                case "avg":
 | 
			
		||||
                                    var avg = Convert.ToDecimal(real["@val"].ToString());
 | 
			
		||||
                                    var avg = real["@val"].ToString() == "NaN" ? -1 : Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float);
 | 
			
		||||
                                    arrangeRawData.Add("@avg_rawdata", avg);
 | 
			
		||||
                                    break;
 | 
			
		||||
                                case "sum":
 | 
			
		||||
                                    var sum = Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float);
 | 
			
		||||
                                    var sum = real["@val"].ToString() == "NaN" ? -1 : Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float);
 | 
			
		||||
                                    arrangeRawData.Add("@sum_rawdata", sum);
 | 
			
		||||
                                    break;
 | 
			
		||||
                            }
 | 
			
		||||
 | 
			
		||||
@ -117,7 +117,7 @@ namespace FrontendWebApi.ApiControllers
 | 
			
		||||
                var aemmEndDate = input.tableType == "year" ? $"year(DATE_ADD(fd.date, INTERVAL +1 {input.tableType}))" : $"DATE_ADD(fd.date, INTERVAL +1 {input.tableType})";
 | 
			
		||||
                var aemmStaDate = input.tableType == "year" ? "year(fd.date)" : "fd.date";
 | 
			
		||||
                var sql = $@"set @i = -1;
 | 
			
		||||
                            select fd.device_number, aemm.avg_rawdata, DATE_FORMAT(fd.date, @dateFormat) as timestamp
 | 
			
		||||
                            select fd.device_number, case when aemm.avg_rawdata = -1 then 'NaN' when aemm.avg_rawdata is null then 0.00 else aemm.avg_rawdata end as avg_rawdata, DATE_FORMAT(fd.date, @dateFormat) as timestamp
 | 
			
		||||
                            from (
 | 
			
		||||
	                            select *
 | 
			
		||||
	                            from (
 | 
			
		||||
@ -164,7 +164,7 @@ namespace FrontendWebApi.ApiControllers
 | 
			
		||||
                foreach (var l in list)
 | 
			
		||||
                {
 | 
			
		||||
                    l.rawData = new List<HydroMeterRawDataOutput>();
 | 
			
		||||
                    l.device_full_name = await backendRepository.GetOneAsync<string>($"select full_name from device where device_number = '{l.device_number}' and deleted = 0");
 | 
			
		||||
                    l.device_full_name = await backendRepository.GetOneAsync<string>($"select full_name from device where device_number = '{l.device_number}'");
 | 
			
		||||
                    if (tag_quantity == "5")
 | 
			
		||||
                    {
 | 
			
		||||
                        l.rawData.AddRange(
 | 
			
		||||
@ -179,7 +179,7 @@ namespace FrontendWebApi.ApiControllers
 | 
			
		||||
                    }
 | 
			
		||||
                    l.building_name = await backendRepository.GetOneAsync<string>("select full_name from building where building_tag = @building_tag and deleted = 0",
 | 
			
		||||
                                        new { building_tag = l.building_tag });
 | 
			
		||||
                    l.total = l.rawData.Sum(x => x.avg_rawdata).ToString();
 | 
			
		||||
                    l.total = l.rawData.Where(x => x.avg_rawdata != "NaN").Sum(x => decimal.Parse(x.avg_rawdata ?? "0", System.Globalization.NumberStyles.Float)).ToString();
 | 
			
		||||
                    l.price = input.price.HasValue 
 | 
			
		||||
                                ? (Math.Round(input.price.Value, 2)).ToString() 
 | 
			
		||||
                                : Math.Round((await backendRepository.GetOneAsync<decimal>("select system_value from variable where system_type = 'ElectricPrice' and deleted = 0")), 2).ToString();
 | 
			
		||||
@ -289,7 +289,7 @@ namespace FrontendWebApi.ApiControllers
 | 
			
		||||
                var aemmEndDate = input.tableType == "year" ? $"year(DATE_ADD(fd.date, INTERVAL +1 {input.tableType}))" : $"DATE_ADD(fd.date, INTERVAL +1 {input.tableType})";
 | 
			
		||||
                var aemmStaDate = input.tableType == "year" ? "year(fd.date)" : "fd.date";
 | 
			
		||||
                var sql = $@"set @i = -1;
 | 
			
		||||
                            select fd.device_number, aemm.avg_rawdata, DATE_FORMAT(fd.date, @dateFormat) as timestamp
 | 
			
		||||
                            select fd.device_number, case when aemm.avg_rawdata = -1 then 'NaN' when aemm.avg_rawdata is null then 0.00 else aemm.avg_rawdata end as avg_rawdata, DATE_FORMAT(fd.date, @dateFormat) as timestamp
 | 
			
		||||
                            from (
 | 
			
		||||
	                            select *
 | 
			
		||||
	                            from (
 | 
			
		||||
@ -337,7 +337,7 @@ namespace FrontendWebApi.ApiControllers
 | 
			
		||||
                foreach (var l in list)
 | 
			
		||||
                {
 | 
			
		||||
                    l.rawData = new List<HydroMeterRawDataOutput>();
 | 
			
		||||
                    l.device_full_name = await backendRepository.GetOneAsync<string>($"select full_name from device where device_number = '{l.device_number}' and deleted = 0");
 | 
			
		||||
                    l.device_full_name = await backendRepository.GetOneAsync<string>($"select full_name from device where device_number = '{l.device_number}'");
 | 
			
		||||
                    if (tag_quantity == "5")
 | 
			
		||||
                    {
 | 
			
		||||
                        l.rawData.AddRange(
 | 
			
		||||
@ -352,7 +352,7 @@ namespace FrontendWebApi.ApiControllers
 | 
			
		||||
                    }
 | 
			
		||||
                    l.building_name = await backendRepository.GetOneAsync<string>("select full_name from building where building_tag = @building_tag and deleted = 0",
 | 
			
		||||
                                        new { building_tag = l.building_tag });
 | 
			
		||||
                    l.total = l.rawData.Sum(x => x.avg_rawdata).ToString();
 | 
			
		||||
                    l.total = l.rawData.Where(x => x.avg_rawdata != "NaN").Sum(x => decimal.Parse(x.avg_rawdata, System.Globalization.NumberStyles.Float)).ToString();
 | 
			
		||||
                    l.price = input.price.HasValue
 | 
			
		||||
                                ? (Math.Round(input.price.Value, 2)).ToString()
 | 
			
		||||
                                : Math.Round((await backendRepository.GetOneAsync<decimal>("select system_value from variable where system_type = 'WaterPrice' and deleted = 0")), 2).ToString();
 | 
			
		||||
 | 
			
		||||
@ -175,5 +175,47 @@ namespace FrontendWebApi.ApiControllers
 | 
			
		||||
            }
 | 
			
		||||
            return Ok(apiResult);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [HttpPost]
 | 
			
		||||
        [Route("api/DevGetWay")]
 | 
			
		||||
        public async Task<ActionResult<ApiResult<string>>> GetDevGetWay([FromBody] DeviceGetWayInput input)
 | 
			
		||||
        {
 | 
			
		||||
            ApiResult<string> apiResult = new ApiResult<string>(jwt_str);
 | 
			
		||||
            //check input
 | 
			
		||||
            if (input == null || string.IsNullOrEmpty(input.device_number) || string.IsNullOrEmpty(input.device_point))
 | 
			
		||||
            {
 | 
			
		||||
                apiResult.Code = "9998";
 | 
			
		||||
                apiResult.Msg = "資料輸入錯誤。";
 | 
			
		||||
                return Ok(apiResult);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                var getWayStr = await backendRepository.GetOneAsync<string>($@"select parent_path from import_niagara_item_history where device_building_tag = '{input.device_number.Split("_")[1]}'
 | 
			
		||||
                                    and device_system_tag = '{input.device_number.Split("_")[2]}' and device_name_tag = '{input.device_number.Split("_")[3]}' 
 | 
			
		||||
                                    and device_floor_tag = '{input.device_number.Split("_")[4]}' and device_master_tag = '{input.device_number.Split("_")[5]}' 
 | 
			
		||||
                                    and device_last_name_tag = '{input.device_number.Split("_")[6]}' and device_serial_tag = '{input.device_number.Split("_")[7]}'
 | 
			
		||||
                                    and device_point_name = '{input.device_point}'");
 | 
			
		||||
 | 
			
		||||
                //check string 
 | 
			
		||||
                if (string.IsNullOrEmpty(getWayStr))
 | 
			
		||||
                {
 | 
			
		||||
                    apiResult.Code = "9997";
 | 
			
		||||
                    apiResult.Msg = "資料獲取錯誤。";
 | 
			
		||||
                    return Ok(apiResult);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                apiResult.Data = getWayStr;
 | 
			
		||||
                apiResult.Code = "0000";
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception exception)
 | 
			
		||||
            {
 | 
			
		||||
                apiResult.Code = "9999";
 | 
			
		||||
                apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
 | 
			
		||||
                Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
 | 
			
		||||
                return Ok(apiResult);
 | 
			
		||||
            }
 | 
			
		||||
            return Ok(apiResult);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -195,5 +195,9 @@ namespace FrontendWebApi.Models
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public class DeviceGetWayInput
 | 
			
		||||
    { 
 | 
			
		||||
        public string device_number { get; set; }
 | 
			
		||||
        public string device_point { get; set; }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -292,13 +292,14 @@ namespace FrontendWebApi.Models
 | 
			
		||||
    public class HistoryExport
 | 
			
		||||
    {
 | 
			
		||||
        public string deviceName { get; set; }
 | 
			
		||||
        public double value { get; set; }
 | 
			
		||||
        public string value { get; set; }
 | 
			
		||||
        public DateTime timestamp { get; set; }
 | 
			
		||||
        public DateTime starttime { get; set; }
 | 
			
		||||
        public DateTime? endtime { get; set; }
 | 
			
		||||
        public string dateType { get; set; }
 | 
			
		||||
        public string type { get; set; }
 | 
			
		||||
        public string building_tag { get; set; }
 | 
			
		||||
        public string device_number { get; set; }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public class History_Building
 | 
			
		||||
 | 
			
		||||
@ -37,7 +37,7 @@ namespace FrontendWebApi.Models
 | 
			
		||||
    {
 | 
			
		||||
        public string timeStamp { get; set; }
 | 
			
		||||
        public string device_number { get; set; }
 | 
			
		||||
        public decimal avg_rawdata { get; set; }
 | 
			
		||||
        public string avg_rawdata { get; set; }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public class HydroMeterPriceInput
 | 
			
		||||
 | 
			
		||||
@ -183,27 +183,39 @@ namespace Repository.BackendRepository.Implement
 | 
			
		||||
                {
 | 
			
		||||
                    try
 | 
			
		||||
                    {
 | 
			
		||||
                        string sql = @" 
 | 
			
		||||
DROP TABLE IF EXISTS `import_niagara_item`;
 | 
			
		||||
CREATE TABLE `import_niagara_item`  (
 | 
			
		||||
  `id` int(11) NOT NULL AUTO_INCREMENT,
 | 
			
		||||
  `device_area_tag` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
 | 
			
		||||
  `device_building_tag` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
 | 
			
		||||
  `device_system_tag` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
 | 
			
		||||
  `device_name_tag` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
 | 
			
		||||
  `device_floor_tag` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
 | 
			
		||||
  `device_master_tag` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
 | 
			
		||||
  `device_last_name_tag` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
 | 
			
		||||
  `device_serial_tag` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
 | 
			
		||||
  `device_point_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
 | 
			
		||||
  `parent_path` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
 | 
			
		||||
  `is_history` bit(1) NULL DEFAULT b'0',
 | 
			
		||||
  `full_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
 | 
			
		||||
  `check_status` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
 | 
			
		||||
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
 | 
			
		||||
  PRIMARY KEY (`id`) USING BTREE
 | 
			
		||||
) ENGINE = InnoDB AUTO_INCREMENT = 271 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
 | 
			
		||||
 ";
 | 
			
		||||
                        await conn.ExecuteAsync(sql);
 | 
			
		||||
 | 
			
		||||
                        #region 刪除 import_niagara_item資料表中選取的棟別
 | 
			
		||||
                        foreach(var b in building)
 | 
			
		||||
                        {
 | 
			
		||||
                            string sql = @"CREATE TABLE IF NOT EXISTS `import_niagara_item` (
 | 
			
		||||
                                  `id` int(11) NOT NULL AUTO_INCREMENT,
 | 
			
		||||
                                  `device_area_tag` varchar(50) DEFAULT NULL,
 | 
			
		||||
                                  `device_building_tag` varchar(50) DEFAULT NULL,
 | 
			
		||||
                                  `device_system_tag` varchar(50) DEFAULT NULL,
 | 
			
		||||
                                  `device_name_tag` varchar(50) DEFAULT NULL,
 | 
			
		||||
                                  `device_point_name` varchar(50) DEFAULT NULL,
 | 
			
		||||
                                  `check_status` varchar(50) DEFAULT NULL,
 | 
			
		||||
                                  `parent_path` varchar(50) DEFAULT NULL,
 | 
			
		||||
                                  `full_name` varchar(50) DEFAULT NULL,
 | 
			
		||||
                                  PRIMARY KEY (`id`)
 | 
			
		||||
                                ) ENGINE=InnoDB AUTO_INCREMENT=59 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;";
 | 
			
		||||
                            await conn.ExecuteAsync(sql);
 | 
			
		||||
                            sql = "delete from import_niagara_item where device_building_tag = '" + b + "'";
 | 
			
		||||
                            await conn.ExecuteAsync(sql);
 | 
			
		||||
                        }
 | 
			
		||||
                        //foreach(var b in building)
 | 
			
		||||
                        //{
 | 
			
		||||
 | 
			
		||||
                        //    sql = "delete from import_niagara_item where device_building_tag = '" + b + "'";
 | 
			
		||||
                        //    await conn.ExecuteAsync(sql);
 | 
			
		||||
                        //}
 | 
			
		||||
                        #endregion
 | 
			
		||||
                        ds = ds.GroupBy(x => new {
 | 
			
		||||
                        ds = ds.GroupBy(x => new
 | 
			
		||||
                        {
 | 
			
		||||
                            device_area_tag = x.device_area_tag,
 | 
			
		||||
                            device_building_tag = x.device_building_tag,
 | 
			
		||||
                            device_system_tag = x.device_system_tag,
 | 
			
		||||
@ -229,17 +241,22 @@ namespace Repository.BackendRepository.Implement
 | 
			
		||||
                        #region 放入import_niagara_item資料表
 | 
			
		||||
                        foreach (var row in ds)
 | 
			
		||||
                        {
 | 
			
		||||
                            sb.Append($@" insert import_niagara_item(device_area_tag, device_building_tag, device_system_tag, device_name_tag, device_point_name, parent_path, full_name, is_history)
 | 
			
		||||
                                        values('"+
 | 
			
		||||
                            string ss = $@" insert import_niagara_item(device_area_tag, device_building_tag, device_system_tag, device_name_tag, 
 | 
			
		||||
                                                                       device_point_name, parent_path, full_name, is_history, created_at)
 | 
			
		||||
                                        values('" +
 | 
			
		||||
                                            row.device_area_tag + "', '" +
 | 
			
		||||
                                            row.device_building_tag + "', '" +
 | 
			
		||||
                                            row.device_system_tag + "', '" +
 | 
			
		||||
                                            row.device_name_tag + "', '" +
 | 
			
		||||
                                            //row.device_floor_tag + "', '" +
 | 
			
		||||
                                            //row.device_master_tag + "', '" +
 | 
			
		||||
                                            //row.device_last_name_tag + "', '" + 
 | 
			
		||||
                                            row.device_point_name + "', '" +
 | 
			
		||||
                                            row.parent_path + "', '" +
 | 
			
		||||
                                            row.full_name + "'," +
 | 
			
		||||
                                            row.isHistory +
 | 
			
		||||
                                            ");");
 | 
			
		||||
                                            row.isHistory + ", now() " +
 | 
			
		||||
                                            ");";
 | 
			
		||||
                            sb.Append(ss);
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        var isDome = await GetOneAsync<string>("select system_value from variable where deleted = 0 and system_type = 'project_name';");
 | 
			
		||||
@ -270,6 +287,96 @@ namespace Repository.BackendRepository.Implement
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public async Task InsertItemFromNiagara_History(List<ImpNiaItem> ds, List<string> building)
 | 
			
		||||
        {
 | 
			
		||||
            using (IDbConnection conn = GetDbConnection())
 | 
			
		||||
            {
 | 
			
		||||
                conn.Open();
 | 
			
		||||
                using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
 | 
			
		||||
                {
 | 
			
		||||
                    try
 | 
			
		||||
                    {
 | 
			
		||||
                        //改成每次都新增 
 | 
			
		||||
                        string sql = @"SET NAMES utf8mb4;
 | 
			
		||||
SET FOREIGN_KEY_CHECKS = 0;
 | 
			
		||||
 | 
			
		||||
-- ----------------------------
 | 
			
		||||
-- Table structure for import_niagara_item_history
 | 
			
		||||
-- ----------------------------
 | 
			
		||||
DROP TABLE IF EXISTS `import_niagara_item_history`;
 | 
			
		||||
CREATE TABLE `import_niagara_item_history`  (
 | 
			
		||||
  `id` int(11) NOT NULL AUTO_INCREMENT,
 | 
			
		||||
  `device_area_tag` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
 | 
			
		||||
  `device_building_tag` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
 | 
			
		||||
  `device_system_tag` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
 | 
			
		||||
  `device_name_tag` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
 | 
			
		||||
  `device_floor_tag` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
 | 
			
		||||
  `device_master_tag` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
 | 
			
		||||
  `device_last_name_tag` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
 | 
			
		||||
  `device_serial_tag` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
 | 
			
		||||
  `device_point_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
 | 
			
		||||
  `parent_path` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
 | 
			
		||||
  `is_history` bit(1) NULL DEFAULT b'0',
 | 
			
		||||
  `full_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
 | 
			
		||||
  `check_status` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
 | 
			
		||||
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
 | 
			
		||||
  PRIMARY KEY (`id`) USING BTREE
 | 
			
		||||
) ENGINE = InnoDB AUTO_INCREMENT = 271 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
 | 
			
		||||
 | 
			
		||||
SET FOREIGN_KEY_CHECKS = 1;";
 | 
			
		||||
                        await conn.ExecuteAsync(sql);
 | 
			
		||||
 | 
			
		||||
                        #region 刪除 import_niagara_item資料表中選取的棟別
 | 
			
		||||
                        //foreach (var b in building)
 | 
			
		||||
                        //{
 | 
			
		||||
 | 
			
		||||
                        //    sql = "delete from import_niagara_item_history where device_building_tag = '" + b + "'";
 | 
			
		||||
                        //    await conn.ExecuteAsync(sql);
 | 
			
		||||
                        //}
 | 
			
		||||
                        #endregion
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                        StringBuilder sb = new StringBuilder();
 | 
			
		||||
                        #region 放入import_niagara_item資料表
 | 
			
		||||
                        foreach (var row in ds)
 | 
			
		||||
                        {
 | 
			
		||||
                            string ss = $@" insert import_niagara_item_history(device_area_tag, device_building_tag, device_system_tag, device_name_tag, 
 | 
			
		||||
device_floor_tag,  device_master_tag, device_last_name_tag, device_serial_tag, device_point_name, parent_path, full_name, is_history, created_at)
 | 
			
		||||
                                        values('" +
 | 
			
		||||
                                            row.device_area_tag + "', '" +
 | 
			
		||||
                                            row.device_building_tag + "', '" +
 | 
			
		||||
                                            row.device_system_tag + "', '" +
 | 
			
		||||
                                            row.device_name_tag + "', '" +
 | 
			
		||||
                                            row.device_floor_tag + "', '" +
 | 
			
		||||
                                            row.device_master_tag + "', '" +
 | 
			
		||||
                                            row.device_last_name_tag + "', '" +
 | 
			
		||||
                                            row.device_serial_tag + "', '" +
 | 
			
		||||
                                            row.device_point_name + "', '" +
 | 
			
		||||
                                            row.parent_path + "', '" +
 | 
			
		||||
                                            row.full_name + "'," +
 | 
			
		||||
                                            row.isHistory + ", now() " +
 | 
			
		||||
                                            ");";
 | 
			
		||||
                            sb.Append(ss);
 | 
			
		||||
                        }
 | 
			
		||||
                        if (sb.Length > 0)
 | 
			
		||||
                        { 
 | 
			
		||||
                            await conn.ExecuteAsync(sb.ToString());
 | 
			
		||||
                            sb.Clear();
 | 
			
		||||
                        }
 | 
			
		||||
                        #endregion
 | 
			
		||||
                    }
 | 
			
		||||
                    catch (Exception exception)
 | 
			
		||||
                    {
 | 
			
		||||
                        throw exception;
 | 
			
		||||
                    }
 | 
			
		||||
                    finally
 | 
			
		||||
                    {
 | 
			
		||||
                        conn.Close();
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 比對 device
 | 
			
		||||
        /// </summary>
 | 
			
		||||
 | 
			
		||||
@ -28,6 +28,14 @@ namespace Repository.BackendRepository.Interface
 | 
			
		||||
        /// <param name="building"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        Task InsertItemFromNiagara(List<ImpNiaItem> ds, List<string> building);
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 同步N4至資料表 import_niagara_item_History
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="ds"></param>
 | 
			
		||||
        /// <param name="building"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        Task InsertItemFromNiagara_History(List<ImpNiaItem> ds, List<string> building);
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 比對 device
 | 
			
		||||
        /// </summary>
 | 
			
		||||
 | 
			
		||||
@ -117,7 +117,12 @@ namespace Repository.Models
 | 
			
		||||
        public string device_system_tag { get; set; }
 | 
			
		||||
        public string device_name_tag { get; set; }
 | 
			
		||||
        public string device_point_name { get; set; }
 | 
			
		||||
        public string device_floor_tag { get; set; }
 | 
			
		||||
        public string device_floor_tag { get; set; } //add by jiahao 2023-07-23
 | 
			
		||||
        public string device_master_tag { get; set; } //add by jiahao 2023-07-23
 | 
			
		||||
 | 
			
		||||
        public string device_last_name_tag { get; set; }//add by jiahao 2023-07-23
 | 
			
		||||
 | 
			
		||||
        public string device_serial_tag { get; set; }//add by jiahao 2023-07-23
 | 
			
		||||
 | 
			
		||||
        public string parent_path { get; set; }
 | 
			
		||||
        public string check_status { get; set; }
 | 
			
		||||
 | 
			
		||||
@ -18,8 +18,8 @@ namespace tpDomeWinAPP
 | 
			
		||||
            Application.SetHighDpiMode(HighDpiMode.SystemAware);
 | 
			
		||||
            Application.EnableVisualStyles();
 | 
			
		||||
            Application.SetCompatibleTextRenderingDefault(false);
 | 
			
		||||
           // Application.Run(new fmCheckTagName());
 | 
			
		||||
            Application.Run(new fmDecrypt());
 | 
			
		||||
            Application.Run(new fmCheckTagName());
 | 
			
		||||
            //Application.Run(new fmDecrypt());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user