1.debug: 水電表歸檔機制,結構調整
2.儲存於水電歸檔table 時需要先 四捨五入 3.報表匯出時,增加 join device 以過濾 deleted 的設備
This commit is contained in:
		
							parent
							
								
									b098c427fe
								
							
						
					
					
						commit
						48a90ece43
					
				@ -19,4 +19,8 @@ namespace Backend.Models
 | 
				
			|||||||
        public byte Is_complete { get; set; }
 | 
					        public byte Is_complete { get; set; }
 | 
				
			||||||
        public double Repeat_times { get; set; }
 | 
					        public double Repeat_times { get; set; }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    public class archiveTable
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        public string archive_yyyymm { get; set; }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -69,7 +69,7 @@ namespace BackendWorkerService.Quartz
 | 
				
			|||||||
            string Times = null;
 | 
					            string Times = null;
 | 
				
			||||||
            try
 | 
					            try
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                var sql = $@"select b.system_value from task_detail a
 | 
					                var sql = $@" select b.system_value from task_detail a
 | 
				
			||||||
                                join variable b on a.variable_id = b.id
 | 
					                                join variable b on a.variable_id = b.id
 | 
				
			||||||
                                where a.task = '{task}' and a.task_item = '{task_item}'";
 | 
					                                where a.task = '{task}' and a.task_item = '{task_item}'";
 | 
				
			||||||
                Times = await backendRepository.GetOneAsync<string>(sql);
 | 
					                Times = await backendRepository.GetOneAsync<string>(sql);
 | 
				
			||||||
@ -95,12 +95,16 @@ namespace BackendWorkerService.Quartz
 | 
				
			|||||||
                            where a.task = '{task}' and a.task_item = '{task_item}'";
 | 
					                            where a.task = '{task}' and a.task_item = '{task_item}'";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                var lastworkTime = await backendRepository.GetOneAsync<string>(sql);
 | 
					                var lastworkTime = await backendRepository.GetOneAsync<string>(sql);
 | 
				
			||||||
 | 
					                if (task_item == "Compensate")
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    string ss = "";
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                DateTime dateTime = lastworkTime != null ? Convert.ToDateTime(lastworkTime) : Convert.ToDateTime("1970-01-01 00:00:01");
 | 
					                DateTime dateTime = lastworkTime != null ? Convert.ToDateTime(lastworkTime) : Convert.ToDateTime("1970-01-01 00:00:01");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                var nextTime = CrontabSchedule.Parse(await GetWorkRule(task, task_item), new ParseOptions { IncludingSeconds = true } ).GetNextOccurrence(dateTime);
 | 
					                //取得 variable 中的 crob 時間設定 ex: 0 0/1 * * * *
 | 
				
			||||||
 | 
					                var crobTime = await GetWorkRule(task, task_item);
 | 
				
			||||||
 | 
					                var nextTime = CrontabSchedule.Parse(crobTime, new ParseOptions { IncludingSeconds = true } ).GetNextOccurrence(dateTime);
 | 
				
			||||||
                if (DateTime.Now >= nextTime)
 | 
					                if (DateTime.Now >= nextTime)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    return true;
 | 
					                    return true;
 | 
				
			||||||
 | 
				
			|||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@ -17,6 +17,10 @@ using Repository.BackendRepository.Interface;
 | 
				
			|||||||
using Repository.BackendRepository.Implement;
 | 
					using Repository.BackendRepository.Implement;
 | 
				
			||||||
using System.Threading.Tasks;
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
using Microsoft.AspNetCore.Mvc.Infrastructure;
 | 
					using Microsoft.AspNetCore.Mvc.Infrastructure;
 | 
				
			||||||
 | 
					using Microsoft.CodeAnalysis.CSharp.Syntax;
 | 
				
			||||||
 | 
					using BackendWorkerService.Quartz;
 | 
				
			||||||
 | 
					using BackendWorkerService.Quartz.Jobs;
 | 
				
			||||||
 | 
					using Microsoft.Extensions.Logging;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace BackendWorkerService.Services.Implement
 | 
					namespace BackendWorkerService.Services.Implement
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -25,12 +29,16 @@ namespace BackendWorkerService.Services.Implement
 | 
				
			|||||||
    /// </summary>
 | 
					    /// </summary>
 | 
				
			||||||
    public class ProcEletricMeterService
 | 
					    public class ProcEletricMeterService
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					        private readonly ILogger<ProcEletricMeterService> logger;
 | 
				
			||||||
        private readonly IBackgroundServiceRepository backgroundServiceRepository;
 | 
					        private readonly IBackgroundServiceRepository backgroundServiceRepository;
 | 
				
			||||||
        private readonly IBackgroundServiceMsSqlRepository backgroundServiceMsSqlRepository;
 | 
					        private readonly IBackgroundServiceMsSqlRepository backgroundServiceMsSqlRepository;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public ProcEletricMeterService(IBackgroundServiceRepository backgroundServiceRepository,
 | 
					        public ProcEletricMeterService(
 | 
				
			||||||
 | 
					            ILogger<ProcEletricMeterService> logger,
 | 
				
			||||||
 | 
					            IBackgroundServiceRepository backgroundServiceRepository,
 | 
				
			||||||
            IBackgroundServiceMsSqlRepository backgroundServiceMySqlRepository)
 | 
					            IBackgroundServiceMsSqlRepository backgroundServiceMySqlRepository)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
					            this.logger = logger;
 | 
				
			||||||
            this.backgroundServiceRepository = backgroundServiceRepository;
 | 
					            this.backgroundServiceRepository = backgroundServiceRepository;
 | 
				
			||||||
            this.backgroundServiceMsSqlRepository = backgroundServiceMySqlRepository;
 | 
					            this.backgroundServiceMsSqlRepository = backgroundServiceMySqlRepository;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@ -74,8 +82,9 @@ namespace BackendWorkerService.Services.Implement
 | 
				
			|||||||
                var MYsql_update_format = @"
 | 
					                var MYsql_update_format = @"
 | 
				
			||||||
                                            UPDATE {0} SET 
 | 
					                                            UPDATE {0} SET 
 | 
				
			||||||
                                                    count_rawdata = @count_rawdata,
 | 
					                                                    count_rawdata = @count_rawdata,
 | 
				
			||||||
                                                    min_rawdata = @min_rawdata,
 | 
					                                                    min_rawdata = round(@min_rawdata, 2),
 | 
				
			||||||
                                                    max_rawdata = @max_rawdata,
 | 
					                                                    max_rawdata = round(@max_rawdata, 2),
 | 
				
			||||||
 | 
					                                                    kwh_result = round(@max_rawdata, 2) - round(@min_rawdata, 2),
 | 
				
			||||||
                                                    avg_rawdata = @avg_rawdata,
 | 
					                                                    avg_rawdata = @avg_rawdata,
 | 
				
			||||||
                                                    sum_rawdata = @sum_rawdata,
 | 
					                                                    sum_rawdata = @sum_rawdata,
 | 
				
			||||||
                                                    is_complete = @is_complete,
 | 
					                                                    is_complete = @is_complete,
 | 
				
			||||||
@ -94,6 +103,7 @@ namespace BackendWorkerService.Services.Implement
 | 
				
			|||||||
                                                    count_rawdata,
 | 
					                                                    count_rawdata,
 | 
				
			||||||
                                                    min_rawdata,
 | 
					                                                    min_rawdata,
 | 
				
			||||||
                                                    max_rawdata,
 | 
					                                                    max_rawdata,
 | 
				
			||||||
 | 
					                                                    kwh_result,
 | 
				
			||||||
                                                    avg_rawdata,
 | 
					                                                    avg_rawdata,
 | 
				
			||||||
                                                    sum_rawdata,
 | 
					                                                    sum_rawdata,
 | 
				
			||||||
                                                    is_complete,
 | 
					                                                    is_complete,
 | 
				
			||||||
@ -105,8 +115,9 @@ namespace BackendWorkerService.Services.Implement
 | 
				
			|||||||
                                                    @start_timestamp,
 | 
					                                                    @start_timestamp,
 | 
				
			||||||
                                                    @end_timestamp,
 | 
					                                                    @end_timestamp,
 | 
				
			||||||
                                                    @count_rawdata,
 | 
					                                                    @count_rawdata,
 | 
				
			||||||
                                                    @min_rawdata,
 | 
					                                                    round(@min_rawdata, 2),
 | 
				
			||||||
                                                    @max_rawdata,
 | 
					                                                    round(@max_rawdata, 2),
 | 
				
			||||||
 | 
					                                                    round(@max_rawdata, 2) - round(@min_rawdata, 2),
 | 
				
			||||||
                                                    @avg_rawdata,
 | 
					                                                    @avg_rawdata,
 | 
				
			||||||
                                                    @sum_rawdata,
 | 
					                                                    @sum_rawdata,
 | 
				
			||||||
                                                    @is_complete,
 | 
					                                                    @is_complete,
 | 
				
			||||||
@ -118,8 +129,9 @@ namespace BackendWorkerService.Services.Implement
 | 
				
			|||||||
    
 | 
					    
 | 
				
			||||||
                                            UPDATE {0} SET 
 | 
					                                            UPDATE {0} SET 
 | 
				
			||||||
                                                    count_rawdata = @count_rawdata,
 | 
					                                                    count_rawdata = @count_rawdata,
 | 
				
			||||||
                                                    min_rawdata = @min_rawdata,
 | 
					                                                    min_rawdata = round(@min_rawdata, 2),
 | 
				
			||||||
                                                    max_rawdata = @max_rawdata,
 | 
					                                                    max_rawdata = round(@max_rawdata, 2),
 | 
				
			||||||
 | 
					                                                    kwh_result = round(@max_rawdata, 2) - round(@min_rawdata, 2),
 | 
				
			||||||
                                                    avg_rawdata = @avg_rawdata,
 | 
					                                                    avg_rawdata = @avg_rawdata,
 | 
				
			||||||
                                                    sum_rawdata = @sum_rawdata,
 | 
					                                                    sum_rawdata = @sum_rawdata,
 | 
				
			||||||
                                                    is_complete = @is_complete,
 | 
					                                                    is_complete = @is_complete,
 | 
				
			||||||
@ -140,6 +152,7 @@ namespace BackendWorkerService.Services.Implement
 | 
				
			|||||||
                                                    count_rawdata,
 | 
					                                                    count_rawdata,
 | 
				
			||||||
                                                    min_rawdata,
 | 
					                                                    min_rawdata,
 | 
				
			||||||
                                                    max_rawdata,
 | 
					                                                    max_rawdata,
 | 
				
			||||||
 | 
					                                                    kwh_result
 | 
				
			||||||
                                                    avg_rawdata,
 | 
					                                                    avg_rawdata,
 | 
				
			||||||
                                                    sum_rawdata,
 | 
					                                                    sum_rawdata,
 | 
				
			||||||
                                                    is_complete,
 | 
					                                                    is_complete,
 | 
				
			||||||
@ -151,8 +164,9 @@ namespace BackendWorkerService.Services.Implement
 | 
				
			|||||||
                                                    @start_timestamp,
 | 
					                                                    @start_timestamp,
 | 
				
			||||||
                                                    @end_timestamp,
 | 
					                                                    @end_timestamp,
 | 
				
			||||||
                                                    @count_rawdata,
 | 
					                                                    @count_rawdata,
 | 
				
			||||||
                                                    @min_rawdata,
 | 
					                                                    round(@min_rawdata, 2),
 | 
				
			||||||
                                                    @max_rawdata,
 | 
					                                                    round(@max_rawdata, 2),
 | 
				
			||||||
 | 
					                                                    round(@max_rawdata, 2) - round(@min_rawdata, 2),
 | 
				
			||||||
                                                    @avg_rawdata,
 | 
					                                                    @avg_rawdata,
 | 
				
			||||||
                                                    @sum_rawdata,
 | 
					                                                    @sum_rawdata,
 | 
				
			||||||
                                                    @is_complete,
 | 
					                                                    @is_complete,
 | 
				
			||||||
@ -250,17 +264,34 @@ namespace BackendWorkerService.Services.Implement
 | 
				
			|||||||
                #endregion 時歸檔補償
 | 
					                #endregion 時歸檔補償
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                #region 天歸檔補償
 | 
					                #region 天歸檔補償
 | 
				
			||||||
 | 
					                #region 電錶補償 day
 | 
				
			||||||
                string schema = await backgroundServiceRepository.GetOneAsync<string>(@"
 | 
					                string schema = await backgroundServiceRepository.GetOneAsync<string>(@"
 | 
				
			||||||
                                select system_value from variable where system_type = 'project_name' and deleted = 0");
 | 
					                                select system_value from variable where system_type = 'project_name' and deleted = 0");
 | 
				
			||||||
                //取得所有須補償的設備資訊
 | 
					                //取得所有須補償的設備資訊
 | 
				
			||||||
                targetTable = await backgroundServiceRepository.GetOneAsync<string>($@"
 | 
					                //targetTable = await backgroundServiceRepository.GetOneAsync<string>($@"
 | 
				
			||||||
                                select table_name
 | 
					                //                select table_name
 | 
				
			||||||
                                from information_schema.`TABLES`
 | 
					                //                from information_schema.`TABLES`
 | 
				
			||||||
                                where TABLE_NAME like 'archive_electric_meter_day%' and TABLE_SCHEMA = '{schema.Split('/')[0]}'
 | 
					                //                where TABLE_NAME like 'archive_electric_meter_day%' and TABLE_SCHEMA = '{schema.Split('/')[0]}'
 | 
				
			||||||
                                order by TABLE_NAME desc limit 1 ");
 | 
					                //                order by TABLE_NAME desc limit 1 "); 
 | 
				
			||||||
                if (!string.IsNullOrEmpty(targetTable))
 | 
					                var archiveTables = await backgroundServiceRepository.GetAllAsync<archiveTable>($@"
 | 
				
			||||||
 | 
					                                select archive_yyyymm from 
 | 
				
			||||||
 | 
						                            (
 | 
				
			||||||
 | 
							                             select  CONCAT(
 | 
				
			||||||
 | 
										                            'archive_electric_meter_day_',
 | 
				
			||||||
 | 
										                            year(start_timestamp), 
 | 
				
			||||||
 | 
										                            case when MONTH(start_timestamp) < 10 then CONCAT('0' , MONTH(start_timestamp))	else MONTH(start_timestamp) end 
 | 
				
			||||||
 | 
										                            ) archive_yyyymm 
 | 
				
			||||||
 | 
								                            from archive_electric_meter_month
 | 
				
			||||||
 | 
								                            where  point = 'KWH' and is_complete = 0
 | 
				
			||||||
 | 
						                            )a
 | 
				
			||||||
 | 
						                            group by archive_yyyymm");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                //if (!string.IsNullOrEmpty(targetTable))
 | 
				
			||||||
 | 
					                //{
 | 
				
			||||||
 | 
					                foreach (var tb_yyyymm in archiveTables)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    sql_error_day = string.Format(sql_error_format, targetTable);
 | 
					                    targetTable = tb_yyyymm.archive_yyyymm;
 | 
				
			||||||
 | 
					                    sql_error_day = $@"SELECT * FROM {targetTable} WHERE is_complete = 0 AND repeat_times < @RepeatTimes AND (point = 'KWH' or point = 'RCV')";
 | 
				
			||||||
                    var electric_error_days = await backgroundServiceRepository.GetAllAsync<ArchiveElectricMeter>(sql_error_day, new { RepeatTimes = repeatTimes });
 | 
					                    var electric_error_days = await backgroundServiceRepository.GetAllAsync<ArchiveElectricMeter>(sql_error_day, new { RepeatTimes = repeatTimes });
 | 
				
			||||||
                    List<Dictionary<string, object>> electricArchiveDayRawDatas = new List<Dictionary<string, object>>();
 | 
					                    List<Dictionary<string, object>> electricArchiveDayRawDatas = new List<Dictionary<string, object>>();
 | 
				
			||||||
                    if (electric_error_days.Count() > 0)
 | 
					                    if (electric_error_days.Count() > 0)
 | 
				
			||||||
@ -272,12 +303,17 @@ namespace BackendWorkerService.Services.Implement
 | 
				
			|||||||
                            deviceNumberPoint.Point = error_day.Point;
 | 
					                            deviceNumberPoint.Point = error_day.Point;
 | 
				
			||||||
                            deviceNumberPoint.FullDeviceNumberPoint = string.Format("{0}_{1}", error_day.Device_number, error_day.Point);
 | 
					                            deviceNumberPoint.FullDeviceNumberPoint = string.Format("{0}_{1}", error_day.Device_number, error_day.Point);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            var startTimestamp = string.Format("{0}+08:00", error_day.Start_timestamp.Replace(" ", "T"));
 | 
					                            //var startTimestamp = string.Format("{0}+08:00", error_day.Start_timestamp.Replace(" ", "T"));
 | 
				
			||||||
                            var endTimestamp = string.Format("{0}+08:00", error_day.End_timestamp.Replace(" ", "T"));
 | 
					                            //var startTimestamp = string.Format("{0}+08:00", DateTime.Parse(error_day.Start_timestamp).ToString("yyyy-MM-dd").Replace(" ", "T"));
 | 
				
			||||||
 | 
					                            var startTimestamp = string.Format("{0}T00:00:00.000+08:00", DateTime.Parse(error_day.Start_timestamp).ToString("yyyy-MM-dd").Replace(" ", "T"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                            //var endTimestamp = string.Format("{0}+08:00", error_day.End_timestamp.Replace(" ", "T"));
 | 
				
			||||||
 | 
					                            var endTimestamp = string.Format("{0}T00:00:10.000+08:00", DateTime.Parse(error_day.End_timestamp).AddDays(1).ToString("yyyy-MM-dd").Replace(" ", "T"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            var historyQueryFilter = $@"<obj is='obix: HistoryFilter'>
 | 
					                            var historyQueryFilter = $@"<obj is='obix: HistoryFilter'>
 | 
				
			||||||
                                                    <abstime name='start' val='{startTimestamp}' />
 | 
					                                                    <abstime name='start' val='{startTimestamp}' />
 | 
				
			||||||
                                                    <abstime name='end' val='{endTimestamp}' />
 | 
					                                                    <abstime name='end' val='{endTimestamp}' />
 | 
				
			||||||
                                                    <reltime name='interval' val = 'PT1D' />
 | 
					                                                    <reltime name='interval' val = 'PT2D' />
 | 
				
			||||||
                                                </obj>";
 | 
					                                                </obj>";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            string device_number = deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "");
 | 
					                            string device_number = deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "");
 | 
				
			||||||
@ -345,10 +381,50 @@ namespace BackendWorkerService.Services.Implement
 | 
				
			|||||||
                            {
 | 
					                            {
 | 
				
			||||||
                                await backgroundServiceMsSqlRepository.ExecuteSql(sql_error_update, electricArchiveDayRawDatas);
 | 
					                                await backgroundServiceMsSqlRepository.ExecuteSql(sql_error_update, electricArchiveDayRawDatas);
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                            #region 月總計
 | 
				
			||||||
 | 
					                            string yyyymm = targetTable.Split('_')[targetTable.Split('_').Length-1]; //取出 archive_electric_meter_day_202308 的最後一段 202308
 | 
				
			||||||
 | 
					                            string yyyy = yyyymm.Substring(0, 4);
 | 
				
			||||||
 | 
					                            string mm = yyyymm.Remove(0, 4);
 | 
				
			||||||
 | 
					                            //先清空 該月份的數據
 | 
				
			||||||
 | 
					                            string sql = @$"update archive_electric_meter_month set count_rawdata = 0, kwh_result = 0, max_rawdata = 0, 
 | 
				
			||||||
 | 
					                                                    min_rawdata = 0, repeat_times = 0, is_complete = 0, fail_reason = null, updated_at = null
 | 
				
			||||||
 | 
					                                          where `point` = 'KWH' and date(start_timestamp) = CONCAT('{yyyy}-{mm}', '-01'); ";                            
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                            try
 | 
				
			||||||
 | 
					                            {
 | 
				
			||||||
 | 
					                                await backgroundServiceRepository.ExecuteSql(sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                                sql = $@"update archive_electric_meter_month a 
 | 
				
			||||||
 | 
					                                            join (
 | 
				
			||||||
 | 
						                                            select device_number, `point` 
 | 
				
			||||||
 | 
							                                            , CONCAT('{yyyy}-{mm}', '-01') start_timestamp
 | 
				
			||||||
 | 
							                                            , LAST_DAY('{yyyy}/{mm}/01')	end_timestamp
 | 
				
			||||||
 | 
							                                            , sum(count_rawdata) count_rawdata
 | 
				
			||||||
 | 
							                                            , sum(kwh_result) kwh_result
 | 
				
			||||||
 | 
							                                            , max(max_rawdata) max_rawdata
 | 
				
			||||||
 | 
							                                            , MIN(min_rawdata) min_rawdata
 | 
				
			||||||
 | 
							                                            from {targetTable} where point = 'KWH'
 | 
				
			||||||
 | 
						                                            group by device_number, `point`  
 | 
				
			||||||
 | 
					                                            ) b on a.device_number = b.device_number and a.`point` = b.`point` and date(a.start_timestamp) = date(b.start_timestamp) 
 | 
				
			||||||
 | 
					                                            set a.count_rawdata = b.count_rawdata, a.kwh_result = b.kwh_result, a.max_rawdata = b.max_rawdata, a.min_rawdata = b.min_rawdata, a.is_complete = 1;";
 | 
				
			||||||
 | 
					                                await backgroundServiceRepository.ExecuteSql(sql);
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					                            catch (Exception ex)
 | 
				
			||||||
 | 
					                            {
 | 
				
			||||||
 | 
					                                //await task_Detail.WorkFail("ArchiveElectricMeterDayJob", "Compensate", ex.ToString());
 | 
				
			||||||
 | 
					                                logger.LogError("【ArchiveElectricMeterDayJob】【補償機制 - 月總計】【任務失敗】");
 | 
				
			||||||
 | 
					                                logger.LogError("【ArchiveElectricMeterDayJob】【補償機制 - 月總計】【任務失敗】[Exception]:{0}", ex.ToString() + Environment.NewLine + sql);
 | 
				
			||||||
 | 
					                            } 
 | 
				
			||||||
 | 
					                            #endregion 
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                #endregion 電錶補償 day
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                #region 水錶補償 day
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                targetTable = await backgroundServiceRepository.GetOneAsync<string>($@"
 | 
					                targetTable = await backgroundServiceRepository.GetOneAsync<string>($@"
 | 
				
			||||||
                                select table_name
 | 
					                                select table_name
 | 
				
			||||||
                                from information_schema.`TABLES`
 | 
					                                from information_schema.`TABLES`
 | 
				
			||||||
@ -368,12 +444,17 @@ namespace BackendWorkerService.Services.Implement
 | 
				
			|||||||
                            deviceNumberPoint.Point = error_day.Point;
 | 
					                            deviceNumberPoint.Point = error_day.Point;
 | 
				
			||||||
                            deviceNumberPoint.FullDeviceNumberPoint = string.Format("{0}_{1}", error_day.Device_number, error_day.Point);
 | 
					                            deviceNumberPoint.FullDeviceNumberPoint = string.Format("{0}_{1}", error_day.Device_number, error_day.Point);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            var startTimestamp = string.Format("{0}+08:00", error_day.Start_timestamp.Replace(" ", "T"));
 | 
					                            //var startTimestamp = string.Format("{0}+08:00", error_day.Start_timestamp.Replace(" ", "T"));
 | 
				
			||||||
                            var endTimestamp = string.Format("{0}+08:00", error_day.End_timestamp.Replace(" ", "T"));
 | 
					                            //var startTimestamp = string.Format("{0}+08:00", DateTime.Parse(error_day.Start_timestamp).ToString("yyyy-MM-dd").Replace(" ", "T"));
 | 
				
			||||||
 | 
					                            var startTimestamp = string.Format("{0}T00:00:00.000+08:00", DateTime.Parse(error_day.Start_timestamp).ToString("yyyy-MM-dd").Replace(" ", "T"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                            //var endTimestamp = string.Format("{0}+08:00", error_day.End_timestamp.Replace(" ", "T"));
 | 
				
			||||||
 | 
					                            var endTimestamp = string.Format("{0}T00:00:01.000+08:00", DateTime.Parse(error_day.End_timestamp).ToString("yyyy-MM-dd").Replace(" ", "T"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            var historyQueryFilter = $@"<obj is='obix: HistoryFilter'>
 | 
					                            var historyQueryFilter = $@"<obj is='obix: HistoryFilter'>
 | 
				
			||||||
                                                    <abstime name='start' val='{startTimestamp}' />
 | 
					                                                    <abstime name='start' val='{startTimestamp}' />
 | 
				
			||||||
                                                    <abstime name='end' val='{endTimestamp}' />
 | 
					                                                    <abstime name='end' val='{endTimestamp}' />
 | 
				
			||||||
                                                    <reltime name='interval' val = 'PT1D' />
 | 
					                                                    <reltime name='interval' val = 'PT2D' />
 | 
				
			||||||
                                                </obj>";
 | 
					                                                </obj>";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            string device_number = deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "");
 | 
					                            string device_number = deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "");
 | 
				
			||||||
@ -444,6 +525,8 @@ namespace BackendWorkerService.Services.Implement
 | 
				
			|||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					                #endregion 水錶補償 day
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                #endregion 天歸檔補償
 | 
					                #endregion 天歸檔補償
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                #region 週歸檔補償
 | 
					                #region 週歸檔補償
 | 
				
			||||||
@ -461,13 +544,17 @@ namespace BackendWorkerService.Services.Implement
 | 
				
			|||||||
                        deviceNumberPoint.Point = error_week.Point;
 | 
					                        deviceNumberPoint.Point = error_week.Point;
 | 
				
			||||||
                        deviceNumberPoint.FullDeviceNumberPoint = string.Format("{0}_{1}", error_week.Device_number, error_week.Point);
 | 
					                        deviceNumberPoint.FullDeviceNumberPoint = string.Format("{0}_{1}", error_week.Device_number, error_week.Point);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        var startTimestamp = string.Format("{0}+08:00", error_week.Start_timestamp.Replace(" ", "T"));
 | 
					                        //var startTimestamp = string.Format("{0}+08:00", error_week.Start_timestamp.Replace(" ", "T"));
 | 
				
			||||||
                        var endTimestamp = string.Format("{0}+08:00", error_week.End_timestamp.Replace(" ", "T"));
 | 
					                        var startTimestamp = string.Format("{0}T00:00:00.000+08:00", DateTime.Parse(error_week.Start_timestamp).ToString("yyyy-MM-dd").Replace(" ", "T"));
 | 
				
			||||||
 | 
					                        
 | 
				
			||||||
 | 
					                        //var endTimestamp = string.Format("{0}+08:00", error_week.End_timestamp.Replace(" ", "T"));
 | 
				
			||||||
 | 
					                        var endTimestamp = string.Format("{0}T00:00:01.000+08:00", DateTime.Parse(error_week.End_timestamp).ToString("yyyy-MM-dd").Replace(" ", "T"));
 | 
				
			||||||
 | 
					                        //var endTimestamp = string.Format("{0}T00:00:01.000+08:00", DateTime.Parse(error_week.End_timestamp).ToString("dd/MM/yyyy").Replace(" ", "T"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        var historyQueryFilter = $@"<obj is='obix: HistoryFilter'>
 | 
					                        var historyQueryFilter = $@"<obj is='obix: HistoryFilter'>
 | 
				
			||||||
                                                <abstime name='start' val='{startTimestamp}' />
 | 
					                                                <abstime name='start' val='{startTimestamp}' />
 | 
				
			||||||
                                                <abstime name='end' val='{endTimestamp}' />
 | 
					                                                <abstime name='end' val='{endTimestamp}' />
 | 
				
			||||||
                                                <reltime name='interval' val = 'PT7D' />
 | 
					                                                <reltime name='interval' val = 'PT8D' />
 | 
				
			||||||
                                            </obj>";
 | 
					                                            </obj>";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        string device_number = deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "");
 | 
					                        string device_number = deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "");
 | 
				
			||||||
@ -551,13 +638,14 @@ namespace BackendWorkerService.Services.Implement
 | 
				
			|||||||
                        deviceNumberPoint.Point = error_week.Point;
 | 
					                        deviceNumberPoint.Point = error_week.Point;
 | 
				
			||||||
                        deviceNumberPoint.FullDeviceNumberPoint = string.Format("{0}_{1}", error_week.Device_number, error_week.Point);
 | 
					                        deviceNumberPoint.FullDeviceNumberPoint = string.Format("{0}_{1}", error_week.Device_number, error_week.Point);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        var startTimestamp = string.Format("{0}+08:00", error_week.Start_timestamp.Replace(" ", "T"));
 | 
					                        //var startTimestamp = string.Format("{0}+08:00", error_week.Start_timestamp.Replace(" ", "T"));
 | 
				
			||||||
                        var endTimestamp = string.Format("{0}+08:00", error_week.End_timestamp.Replace(" ", "T"));
 | 
					                        //var endTimestamp = string.Format("{0}+08:00", error_week.End_timestamp.Replace(" ", "T"));
 | 
				
			||||||
 | 
					                        var startTimestamp = string.Format("{0}T00:00:00.000+08:00", DateTime.Parse(error_week.Start_timestamp).ToString("yyyy-MM-dd").Replace(" ", "T")); 
 | 
				
			||||||
 | 
					                        var endTimestamp = string.Format("{0}T00:00:01.000+08:00", DateTime.Parse(error_week.End_timestamp).ToString("yyyy-MM-dd").Replace(" ", "T"));
 | 
				
			||||||
                        var historyQueryFilter = $@"<obj is='obix: HistoryFilter'>
 | 
					                        var historyQueryFilter = $@"<obj is='obix: HistoryFilter'>
 | 
				
			||||||
                                                <abstime name='start' val='{startTimestamp}' />
 | 
					                                                <abstime name='start' val='{startTimestamp}' />
 | 
				
			||||||
                                                <abstime name='end' val='{endTimestamp}' />
 | 
					                                                <abstime name='end' val='{endTimestamp}' />
 | 
				
			||||||
                                                <reltime name='interval' val = 'PT7D' />
 | 
					                                                <reltime name='interval' val = 'PT8D' />
 | 
				
			||||||
                                            </obj>";
 | 
					                                            </obj>";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        string device_number = deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "");
 | 
					                        string device_number = deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "");
 | 
				
			||||||
@ -630,192 +718,199 @@ namespace BackendWorkerService.Services.Implement
 | 
				
			|||||||
                #endregion 週歸檔補償
 | 
					                #endregion 週歸檔補償
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                #region 月歸檔補償
 | 
					                #region 月歸檔補償
 | 
				
			||||||
                //取得所有須補償的設備資訊
 | 
					 | 
				
			||||||
                targetTable = "archive_electric_meter_month";
 | 
					 | 
				
			||||||
                var sql_error_month = string.Format(sql_error_format, targetTable);
 | 
					 | 
				
			||||||
                var electric_error_months = await backgroundServiceRepository.GetAllAsync<ArchiveElectricMeter>(sql_error_month, new { RepeatTimes = repeatTimes });
 | 
					 | 
				
			||||||
                List<Dictionary<string, object>> electricArchiveMonthRawDatas = new List<Dictionary<string, object>>();
 | 
					 | 
				
			||||||
                if (electric_error_months.Count() > 0)
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    foreach (var error_month in electric_error_months)
 | 
					 | 
				
			||||||
                    {
 | 
					 | 
				
			||||||
                        DeviceNumberPoint deviceNumberPoint = new DeviceNumberPoint();
 | 
					 | 
				
			||||||
                        deviceNumberPoint.DeviceNumber = error_month.Device_number;
 | 
					 | 
				
			||||||
                        deviceNumberPoint.Point = error_month.Point;
 | 
					 | 
				
			||||||
                        deviceNumberPoint.FullDeviceNumberPoint = string.Format("{0}_{1}", error_month.Device_number, error_month.Point);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        var startTimestamp = string.Format("{0}+08:00", error_month.Start_timestamp.Replace(" ", "T"));
 | 
					                ////取得所有須補償的設備資訊
 | 
				
			||||||
                        var endTimestamp = string.Format("{0}+08:00", error_month.End_timestamp.Replace(" ", "T"));
 | 
					                //targetTable = "archive_electric_meter_month";
 | 
				
			||||||
 | 
					                //var sql_error_month = string.Format(sql_error_format, targetTable);
 | 
				
			||||||
 | 
					                //var electric_error_months = await backgroundServiceRepository.GetAllAsync<ArchiveElectricMeter>(sql_error_month, new { RepeatTimes = repeatTimes });
 | 
				
			||||||
 | 
					                //List<Dictionary<string, object>> electricArchiveMonthRawDatas = new List<Dictionary<string, object>>();
 | 
				
			||||||
 | 
					                //if (electric_error_months.Count() > 0)
 | 
				
			||||||
 | 
					                //{
 | 
				
			||||||
 | 
					                //    foreach (var error_month in electric_error_months)
 | 
				
			||||||
 | 
					                //    {
 | 
				
			||||||
 | 
					                //        DeviceNumberPoint deviceNumberPoint = new DeviceNumberPoint();
 | 
				
			||||||
 | 
					                //        deviceNumberPoint.DeviceNumber = error_month.Device_number;
 | 
				
			||||||
 | 
					                //        deviceNumberPoint.Point = error_month.Point;
 | 
				
			||||||
 | 
					                //        deviceNumberPoint.FullDeviceNumberPoint = string.Format("{0}_{1}", error_month.Device_number, error_month.Point);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        var startDateTime = Convert.ToDateTime(error_month.Start_timestamp);
 | 
					                //        //var startTimestamp = string.Format("{0}+08:00", error_month.Start_timestamp.Replace(" ", "T"));
 | 
				
			||||||
                        var dayInMonth = DateTime.DaysInMonth(startDateTime.Year, startDateTime.Month);
 | 
					                //        //var endTimestamp = string.Format("{0}+08:00", error_month.End_timestamp.Replace(" ", "T"));
 | 
				
			||||||
 | 
					                //        var startTimestamp = string.Format("{0}T00:00:00.000+08:00", DateTime.Parse(error_month.Start_timestamp).ToString("yyyy-MM-dd").Replace(" ", "T"));
 | 
				
			||||||
                         
 | 
					                         
 | 
				
			||||||
                        var historyQueryFilter = $@"<obj is='obix: HistoryFilter'>
 | 
					                //        var endTimestamp = string.Format("{0}T00:00:01.000+08:00", DateTime.Parse(error_month.End_timestamp).ToString("yyyy-MM-dd").Replace(" ", "T"));
 | 
				
			||||||
                                                <abstime name='start' val='{startTimestamp}' />
 | 
					 | 
				
			||||||
                                                <abstime name='end' val='{endTimestamp}' />
 | 
					 | 
				
			||||||
                                                <reltime name='interval' val = 'PT{dayInMonth}D' />
 | 
					 | 
				
			||||||
                                            </obj>";
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        string device_number = deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "");
 | 
					                //        var startDateTime = Convert.ToDateTime(error_month.Start_timestamp);
 | 
				
			||||||
                        var station = backgroundServiceRepository.GetOneAsync<string>($@"select parent_path from import_niagara_item_history where device_building_tag = '{device_number.Split("_")[1].Replace("$3", "")}' and 
 | 
					                //        var dayInMonth = DateTime.DaysInMonth(startDateTime.Year, startDateTime.Month) + 1; //比原定的多加 1天
 | 
				
			||||||
                                    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);
 | 
					 | 
				
			||||||
                        archiveMonthRequest.PreAuthenticate = true;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        byte[] byteArray = Encoding.UTF8.GetBytes(historyQueryFilter);
 | 
					                //        var historyQueryFilter = $@"<obj is='obix: HistoryFilter'>
 | 
				
			||||||
                        using (Stream reqStream = archiveMonthRequest.GetRequestStream())
 | 
					                //                                <abstime name='start' val='{startTimestamp}' />
 | 
				
			||||||
                        {
 | 
					                //                                <abstime name='end' val='{endTimestamp}' />
 | 
				
			||||||
                            reqStream.Write(byteArray, 0, byteArray.Length);
 | 
					                //                                <reltime name='interval' val = 'PT{dayInMonth}D' />
 | 
				
			||||||
                        }
 | 
					                //                            </obj>";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        HttpWebResponse archiveMonthResponse = (HttpWebResponse)archiveMonthRequest.GetResponse();
 | 
					                //        string device_number = deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "");
 | 
				
			||||||
                        var archiveMonthResponseContent = new StreamReader(archiveMonthResponse.GetResponseStream()).ReadToEnd();
 | 
					                //        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);
 | 
				
			||||||
 | 
					                //        archiveMonthRequest.PreAuthenticate = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        xmlDocument.LoadXml(archiveMonthResponseContent);
 | 
					                //        byte[] byteArray = Encoding.UTF8.GetBytes(historyQueryFilter);
 | 
				
			||||||
                        string archiveMonthJson = JsonConvert.SerializeXmlNode(xmlDocument);
 | 
					                //        using (Stream reqStream = archiveMonthRequest.GetRequestStream())
 | 
				
			||||||
                        JObject archiveMonthJsonResult = (JObject)JsonConvert.DeserializeObject(archiveMonthJson);
 | 
					                //        {
 | 
				
			||||||
 | 
					                //            reqStream.Write(byteArray, 0, byteArray.Length);
 | 
				
			||||||
 | 
					                //        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        if (archiveMonthJsonResult.ContainsKey("err")) //抓取錯誤
 | 
					                //        HttpWebResponse archiveMonthResponse = (HttpWebResponse)archiveMonthRequest.GetResponse();
 | 
				
			||||||
                        {
 | 
					                //        var archiveMonthResponseContent = new StreamReader(archiveMonthResponse.GetResponseStream()).ReadToEnd();
 | 
				
			||||||
                            Dictionary<string, object> archiveMonthRawData = new Dictionary<string, object>();
 | 
					 | 
				
			||||||
                            archiveMonthRawData.Add("@device_number", error_month.Device_number);
 | 
					 | 
				
			||||||
                            archiveMonthRawData.Add("@point", error_month.Point);
 | 
					 | 
				
			||||||
                            archiveMonthRawData.Add("@start_timestamp", DateTime.Parse(error_month.Start_timestamp, System.Globalization.CultureInfo.CurrentCulture));
 | 
					 | 
				
			||||||
                            archiveMonthRawData.Add("@end_timestamp", DateTime.Parse(error_month.End_timestamp, System.Globalization.CultureInfo.CurrentCulture));
 | 
					 | 
				
			||||||
                            archiveMonthRawData.Add("@is_complete", 0);
 | 
					 | 
				
			||||||
                            archiveMonthRawData.Add("@repeat_times", ++error_month.Repeat_times);
 | 
					 | 
				
			||||||
                            archiveMonthRawData.Add("@fail_reason", archiveMonthJson);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            archiveMonthRawData.Add("@count_rawdata", 0);
 | 
					                //        xmlDocument.LoadXml(archiveMonthResponseContent);
 | 
				
			||||||
                            archiveMonthRawData.Add("@min_rawdata", 0);
 | 
					                //        string archiveMonthJson = JsonConvert.SerializeXmlNode(xmlDocument);
 | 
				
			||||||
                            archiveMonthRawData.Add("@max_rawdata", 0);
 | 
					                //        JObject archiveMonthJsonResult = (JObject)JsonConvert.DeserializeObject(archiveMonthJson);
 | 
				
			||||||
                            archiveMonthRawData.Add("@avg_rawdata", 0);
 | 
					 | 
				
			||||||
                            archiveMonthRawData.Add("@sum_rawdata", 0);
 | 
					 | 
				
			||||||
                            archiveMonthRawData.Add("@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            electricArchiveMonthRawDatas.Add(archiveMonthRawData);
 | 
					                //        if (archiveMonthJsonResult.ContainsKey("err")) //抓取錯誤
 | 
				
			||||||
                        }
 | 
					                //        {
 | 
				
			||||||
 | 
					                //            Dictionary<string, object> archiveMonthRawData = new Dictionary<string, object>();
 | 
				
			||||||
 | 
					                //            archiveMonthRawData.Add("@device_number", error_month.Device_number);
 | 
				
			||||||
 | 
					                //            archiveMonthRawData.Add("@point", error_month.Point);
 | 
				
			||||||
 | 
					                //            archiveMonthRawData.Add("@start_timestamp", DateTime.Parse(error_month.Start_timestamp, System.Globalization.CultureInfo.CurrentCulture));
 | 
				
			||||||
 | 
					                //            archiveMonthRawData.Add("@end_timestamp", DateTime.Parse(error_month.End_timestamp, System.Globalization.CultureInfo.CurrentCulture));
 | 
				
			||||||
 | 
					                //            archiveMonthRawData.Add("@is_complete", 0);
 | 
				
			||||||
 | 
					                //            archiveMonthRawData.Add("@repeat_times", ++error_month.Repeat_times);
 | 
				
			||||||
 | 
					                //            archiveMonthRawData.Add("@fail_reason", archiveMonthJson);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        if (archiveMonthJsonResult.ContainsKey("obj")) //表示可以讀取到內容
 | 
					                //            archiveMonthRawData.Add("@count_rawdata", 0);
 | 
				
			||||||
                        {
 | 
					                //            archiveMonthRawData.Add("@min_rawdata", 0);
 | 
				
			||||||
                            var ArrangeRawDatas = ArrangeRawData(deviceNumberPoint, archiveMonthJsonResult);
 | 
					                //            archiveMonthRawData.Add("@max_rawdata", 0);
 | 
				
			||||||
                            if (ArrangeRawDatas != null && ArrangeRawDatas.Count() > 0)
 | 
					                //            archiveMonthRawData.Add("@avg_rawdata", 0);
 | 
				
			||||||
                            {
 | 
					                //            archiveMonthRawData.Add("@sum_rawdata", 0);
 | 
				
			||||||
                                electricArchiveMonthRawDatas.AddRange(ArrangeRawDatas);
 | 
					                //            archiveMonthRawData.Add("@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
 | 
				
			||||||
                            }
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    if (electricArchiveMonthRawDatas.Count() > 0)
 | 
					                //            electricArchiveMonthRawDatas.Add(archiveMonthRawData);
 | 
				
			||||||
                    {
 | 
					                //        }
 | 
				
			||||||
                        var Mysql_error_update = string.Format(MYsql_update_format, targetTable);
 | 
					 | 
				
			||||||
                        var sql_error_update = string.Format(sql_update_format, targetTable);
 | 
					 | 
				
			||||||
                        if (!string.IsNullOrEmpty(saveToMSDB) && saveToMSDB == "1")
 | 
					 | 
				
			||||||
                        {
 | 
					 | 
				
			||||||
                            await backgroundServiceMsSqlRepository.ExecuteSql(sql_error_update, electricArchiveMonthRawDatas);
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                        await backgroundServiceRepository.ExecuteSql(Mysql_error_update, electricArchiveMonthRawDatas);
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                targetTable = "archive_water_meter_month";
 | 
					                //        if (archiveMonthJsonResult.ContainsKey("obj")) //表示可以讀取到內容
 | 
				
			||||||
                sql_error_month = string.Format(sql_error_format, targetTable);
 | 
					                //        {
 | 
				
			||||||
                var water_error_months = await backgroundServiceRepository.GetAllAsync<ArchiveElectricMeter>(sql_error_month, new { RepeatTimes = repeatTimes });
 | 
					                //            var ArrangeRawDatas = ArrangeRawData(deviceNumberPoint, archiveMonthJsonResult);
 | 
				
			||||||
                List<Dictionary<string, object>> waterArchiveMonthRawDatas = new List<Dictionary<string, object>>();
 | 
					                //            if (ArrangeRawDatas != null && ArrangeRawDatas.Count() > 0)
 | 
				
			||||||
                if (water_error_months.Count() > 0)
 | 
					                //            {
 | 
				
			||||||
                {
 | 
					                //                electricArchiveMonthRawDatas.AddRange(ArrangeRawDatas);
 | 
				
			||||||
                    foreach (var error_month in water_error_months)
 | 
					                //            }
 | 
				
			||||||
                    {
 | 
					                //        }
 | 
				
			||||||
                        DeviceNumberPoint deviceNumberPoint = new DeviceNumberPoint();
 | 
					                //    }
 | 
				
			||||||
                        deviceNumberPoint.DeviceNumber = error_month.Device_number;
 | 
					 | 
				
			||||||
                        deviceNumberPoint.Point = error_month.Point;
 | 
					 | 
				
			||||||
                        deviceNumberPoint.FullDeviceNumberPoint = string.Format("{0}_{1}", error_month.Device_number, error_month.Point);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        var startTimestamp = string.Format("{0}+08:00", error_month.Start_timestamp.Replace(" ", "T"));
 | 
					                //    if (electricArchiveMonthRawDatas.Count() > 0)
 | 
				
			||||||
                        var endTimestamp = string.Format("{0}+08:00", error_month.End_timestamp.Replace(" ", "T"));
 | 
					                //    {
 | 
				
			||||||
 | 
					                //        var Mysql_error_update = string.Format(MYsql_update_format, targetTable);
 | 
				
			||||||
 | 
					                //        var sql_error_update = string.Format(sql_update_format, targetTable);
 | 
				
			||||||
 | 
					                //        if (!string.IsNullOrEmpty(saveToMSDB) && saveToMSDB == "1")
 | 
				
			||||||
 | 
					                //        {
 | 
				
			||||||
 | 
					                //            await backgroundServiceMsSqlRepository.ExecuteSql(sql_error_update, electricArchiveMonthRawDatas);
 | 
				
			||||||
 | 
					                //        }
 | 
				
			||||||
 | 
					                //        await backgroundServiceRepository.ExecuteSql(Mysql_error_update, electricArchiveMonthRawDatas);
 | 
				
			||||||
 | 
					                //    }
 | 
				
			||||||
 | 
					                //}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        var startDateTime = Convert.ToDateTime(error_month.Start_timestamp);
 | 
					                //targetTable = "archive_water_meter_month";
 | 
				
			||||||
                        var dayInMonth = DateTime.DaysInMonth(startDateTime.Year, startDateTime.Month);
 | 
					                //sql_error_month = string.Format(sql_error_format, targetTable);
 | 
				
			||||||
 | 
					                //var water_error_months = await backgroundServiceRepository.GetAllAsync<ArchiveElectricMeter>(sql_error_month, new { RepeatTimes = repeatTimes });
 | 
				
			||||||
 | 
					                //List<Dictionary<string, object>> waterArchiveMonthRawDatas = new List<Dictionary<string, object>>();
 | 
				
			||||||
 | 
					                //if (water_error_months.Count() > 0)
 | 
				
			||||||
 | 
					                //{
 | 
				
			||||||
 | 
					                //    foreach (var error_month in water_error_months)
 | 
				
			||||||
 | 
					                //    {
 | 
				
			||||||
 | 
					                //        DeviceNumberPoint deviceNumberPoint = new DeviceNumberPoint();
 | 
				
			||||||
 | 
					                //        deviceNumberPoint.DeviceNumber = error_month.Device_number;
 | 
				
			||||||
 | 
					                //        deviceNumberPoint.Point = error_month.Point;
 | 
				
			||||||
 | 
					                //        deviceNumberPoint.FullDeviceNumberPoint = string.Format("{0}_{1}", error_month.Device_number, error_month.Point);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        var historyQueryFilter = $@"<obj is='obix: HistoryFilter'>
 | 
					                //        //var startTimestamp = string.Format("{0}+08:00", error_month.Start_timestamp.Replace(" ", "T"));
 | 
				
			||||||
                                                <abstime name='start' val='{startTimestamp}' />
 | 
					                //        //var endTimestamp = string.Format("{0}+08:00", error_month.End_timestamp.Replace(" ", "T"));
 | 
				
			||||||
                                                <abstime name='end' val='{endTimestamp}' />
 | 
					                //        var startTimestamp = string.Format("{0}T00:00:00.000+08:00", DateTime.Parse(error_month.Start_timestamp).ToString("yyyy-MM-dd").Replace(" ", "T"));
 | 
				
			||||||
                                                <reltime name='interval' val = 'PT{dayInMonth}D' />
 | 
					                //        var endTimestamp = string.Format("{0}T00:00:01.000+08:00", DateTime.Parse(error_month.End_timestamp).ToString("yyyy-MM-dd").Replace(" ", "T"));
 | 
				
			||||||
                                            </obj>";
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        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);
 | 
					 | 
				
			||||||
                        archiveMonthRequest.PreAuthenticate = true;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        byte[] byteArray = Encoding.UTF8.GetBytes(historyQueryFilter);
 | 
					                //        var startDateTime = Convert.ToDateTime(error_month.Start_timestamp);
 | 
				
			||||||
                        using (Stream reqStream = archiveMonthRequest.GetRequestStream())
 | 
					                //        var dayInMonth = DateTime.DaysInMonth(startDateTime.Year, startDateTime.Month) + 1; //比原定的多加 1天
 | 
				
			||||||
                        {
 | 
					 | 
				
			||||||
                            reqStream.Write(byteArray, 0, byteArray.Length);
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        HttpWebResponse archiveMonthResponse = (HttpWebResponse)archiveMonthRequest.GetResponse();
 | 
					                //        var historyQueryFilter = $@"<obj is='obix: HistoryFilter'>
 | 
				
			||||||
                        var archiveMonthResponseContent = new StreamReader(archiveMonthResponse.GetResponseStream()).ReadToEnd();
 | 
					                //                                <abstime name='start' val='{startTimestamp}' />
 | 
				
			||||||
 | 
					                //                                <abstime name='end' val='{endTimestamp}' />
 | 
				
			||||||
 | 
					                //                                <reltime name='interval' val = 'PT{dayInMonth}D' />
 | 
				
			||||||
 | 
					                //                            </obj>";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        xmlDocument.LoadXml(archiveMonthResponseContent);
 | 
					                //        string device_number = deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "");
 | 
				
			||||||
                        string archiveMonthJson = JsonConvert.SerializeXmlNode(xmlDocument);
 | 
					                //        var station = backgroundServiceRepository.GetOneAsync<string>($@"select parent_path from import_niagara_item_history where device_building_tag = '{device_number.Split("_")[1].Replace("$3", "")}' and 
 | 
				
			||||||
                        JObject archiveMonthJsonResult = (JObject)JsonConvert.DeserializeObject(archiveMonthJson);
 | 
					                //                    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);
 | 
				
			||||||
 | 
					                //        archiveMonthRequest.PreAuthenticate = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        if (archiveMonthJsonResult.ContainsKey("err")) //抓取錯誤
 | 
					                //        byte[] byteArray = Encoding.UTF8.GetBytes(historyQueryFilter);
 | 
				
			||||||
                        {
 | 
					                //        using (Stream reqStream = archiveMonthRequest.GetRequestStream())
 | 
				
			||||||
                            Dictionary<string, object> archiveMonthRawData = new Dictionary<string, object>();
 | 
					                //        {
 | 
				
			||||||
                            archiveMonthRawData.Add("@device_number", error_month.Device_number);
 | 
					                //            reqStream.Write(byteArray, 0, byteArray.Length);
 | 
				
			||||||
                            archiveMonthRawData.Add("@point", error_month.Point);
 | 
					                //        }
 | 
				
			||||||
                            archiveMonthRawData.Add("@start_timestamp", DateTime.Parse(error_month.Start_timestamp, System.Globalization.CultureInfo.CurrentCulture));
 | 
					 | 
				
			||||||
                            archiveMonthRawData.Add("@end_timestamp", DateTime.Parse(error_month.End_timestamp, System.Globalization.CultureInfo.CurrentCulture));
 | 
					 | 
				
			||||||
                            archiveMonthRawData.Add("@is_complete", 0);
 | 
					 | 
				
			||||||
                            archiveMonthRawData.Add("@repeat_times", ++error_month.Repeat_times);
 | 
					 | 
				
			||||||
                            archiveMonthRawData.Add("@fail_reason", archiveMonthJson);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            archiveMonthRawData.Add("@count_rawdata", 0);
 | 
					                //        HttpWebResponse archiveMonthResponse = (HttpWebResponse)archiveMonthRequest.GetResponse();
 | 
				
			||||||
                            archiveMonthRawData.Add("@min_rawdata", 0);
 | 
					                //        var archiveMonthResponseContent = new StreamReader(archiveMonthResponse.GetResponseStream()).ReadToEnd();
 | 
				
			||||||
                            archiveMonthRawData.Add("@max_rawdata", 0);
 | 
					 | 
				
			||||||
                            archiveMonthRawData.Add("@avg_rawdata", 0);
 | 
					 | 
				
			||||||
                            archiveMonthRawData.Add("@sum_rawdata", 0);
 | 
					 | 
				
			||||||
                            archiveMonthRawData.Add("@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            waterArchiveMonthRawDatas.Add(archiveMonthRawData);
 | 
					                //        xmlDocument.LoadXml(archiveMonthResponseContent);
 | 
				
			||||||
                        }
 | 
					                //        string archiveMonthJson = JsonConvert.SerializeXmlNode(xmlDocument);
 | 
				
			||||||
 | 
					                //        JObject archiveMonthJsonResult = (JObject)JsonConvert.DeserializeObject(archiveMonthJson);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        if (archiveMonthJsonResult.ContainsKey("obj")) //表示可以讀取到內容
 | 
					                //        if (archiveMonthJsonResult.ContainsKey("err")) //抓取錯誤
 | 
				
			||||||
                        {
 | 
					                //        {
 | 
				
			||||||
                            var ArrangeRawDatas = ArrangeRawData(deviceNumberPoint, archiveMonthJsonResult);
 | 
					                //            Dictionary<string, object> archiveMonthRawData = new Dictionary<string, object>();
 | 
				
			||||||
                            if (ArrangeRawDatas != null && ArrangeRawDatas.Count() > 0)
 | 
					                //            archiveMonthRawData.Add("@device_number", error_month.Device_number);
 | 
				
			||||||
                            {
 | 
					                //            archiveMonthRawData.Add("@point", error_month.Point);
 | 
				
			||||||
                                waterArchiveMonthRawDatas.AddRange(ArrangeRawDatas);
 | 
					                //            archiveMonthRawData.Add("@start_timestamp", DateTime.Parse(error_month.Start_timestamp, System.Globalization.CultureInfo.CurrentCulture));
 | 
				
			||||||
                            }
 | 
					                //            archiveMonthRawData.Add("@end_timestamp", DateTime.Parse(error_month.End_timestamp, System.Globalization.CultureInfo.CurrentCulture));
 | 
				
			||||||
                        }
 | 
					                //            archiveMonthRawData.Add("@is_complete", 0);
 | 
				
			||||||
                    }
 | 
					                //            archiveMonthRawData.Add("@repeat_times", ++error_month.Repeat_times);
 | 
				
			||||||
 | 
					                //            archiveMonthRawData.Add("@fail_reason", archiveMonthJson);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    if (waterArchiveMonthRawDatas.Count() > 0)
 | 
					                //            archiveMonthRawData.Add("@count_rawdata", 0);
 | 
				
			||||||
                    {
 | 
					                //            archiveMonthRawData.Add("@min_rawdata", 0);
 | 
				
			||||||
                        var Mysql_error_update = string.Format(MYsql_update_format, targetTable);
 | 
					                //            archiveMonthRawData.Add("@max_rawdata", 0);
 | 
				
			||||||
                        var sql_error_update = string.Format(sql_update_format, targetTable);
 | 
					                //            archiveMonthRawData.Add("@avg_rawdata", 0);
 | 
				
			||||||
                        if (!string.IsNullOrEmpty(saveToMSDB) && saveToMSDB == "1")
 | 
					                //            archiveMonthRawData.Add("@sum_rawdata", 0);
 | 
				
			||||||
                        {
 | 
					                //            archiveMonthRawData.Add("@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
 | 
				
			||||||
                            await backgroundServiceMsSqlRepository.ExecuteSql(sql_error_update, waterArchiveMonthRawDatas);
 | 
					
 | 
				
			||||||
                        }
 | 
					                //            waterArchiveMonthRawDatas.Add(archiveMonthRawData);
 | 
				
			||||||
                        await backgroundServiceRepository.ExecuteSql(Mysql_error_update, waterArchiveMonthRawDatas);
 | 
					                //        }
 | 
				
			||||||
                    }
 | 
					
 | 
				
			||||||
                }
 | 
					                //        if (archiveMonthJsonResult.ContainsKey("obj")) //表示可以讀取到內容
 | 
				
			||||||
 | 
					                //        {
 | 
				
			||||||
 | 
					                //            var ArrangeRawDatas = ArrangeRawData(deviceNumberPoint, archiveMonthJsonResult);
 | 
				
			||||||
 | 
					                //            if (ArrangeRawDatas != null && ArrangeRawDatas.Count() > 0)
 | 
				
			||||||
 | 
					                //            {
 | 
				
			||||||
 | 
					                //                waterArchiveMonthRawDatas.AddRange(ArrangeRawDatas);
 | 
				
			||||||
 | 
					                //            }
 | 
				
			||||||
 | 
					                //        }
 | 
				
			||||||
 | 
					                //    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                //    if (waterArchiveMonthRawDatas.Count() > 0)
 | 
				
			||||||
 | 
					                //    {
 | 
				
			||||||
 | 
					                //        var Mysql_error_update = string.Format(MYsql_update_format, targetTable);
 | 
				
			||||||
 | 
					                //        var sql_error_update = string.Format(sql_update_format, targetTable);
 | 
				
			||||||
 | 
					                //        if (!string.IsNullOrEmpty(saveToMSDB) && saveToMSDB == "1")
 | 
				
			||||||
 | 
					                //        {
 | 
				
			||||||
 | 
					                //            await backgroundServiceMsSqlRepository.ExecuteSql(sql_error_update, waterArchiveMonthRawDatas);
 | 
				
			||||||
 | 
					                //        }
 | 
				
			||||||
 | 
					                //        await backgroundServiceRepository.ExecuteSql(Mysql_error_update, waterArchiveMonthRawDatas);
 | 
				
			||||||
 | 
					                //    }
 | 
				
			||||||
 | 
					                //}
 | 
				
			||||||
                #endregion 月歸檔補償
 | 
					                #endregion 月歸檔補償
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                result = true;
 | 
					                result = true;
 | 
				
			||||||
@ -828,6 +923,92 @@ namespace BackendWorkerService.Services.Implement
 | 
				
			|||||||
            return result;
 | 
					            return result;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 獲取 Niagara 資料,並儲存於 List 中
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <param name="device_number"></param>
 | 
				
			||||||
 | 
					        /// <param name="xmlDocument"></param>
 | 
				
			||||||
 | 
					        /// <param name="DeviceNumberPoints"></param>
 | 
				
			||||||
 | 
					        /// <param name="obixApiConfig"></param>
 | 
				
			||||||
 | 
					        /// <param name="encoded"></param>
 | 
				
			||||||
 | 
					        /// <param name="startTimestamp"></param>
 | 
				
			||||||
 | 
					        /// <param name="endTimestamp"></param>
 | 
				
			||||||
 | 
					        /// <param name="historyQueryFilter"></param>
 | 
				
			||||||
 | 
					        /// <param name="waterArchiveDayRawDatas"></param>
 | 
				
			||||||
 | 
					        public void obixData_collect(XmlDocument xmlDocument, List<DeviceNumberPoint> DeviceNumberPoints, ObixApiConfig obixApiConfig, string encoded, string startTimestamp, string endTimestamp, string historyQueryFilter, List<Dictionary<string, object>> resultArchiveDayRawDatas)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            #region 水電錶 save to DB start
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            foreach (var deviceNumberPoint in DeviceNumberPoints)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                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 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);
 | 
				
			||||||
 | 
					                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.LoadXml(archiveResponseContent);
 | 
				
			||||||
 | 
					                var archiveJson = JsonConvert.SerializeXmlNode(xmlDocument);
 | 
				
			||||||
 | 
					                var archiveJsonResult = (JObject)JsonConvert.DeserializeObject(archiveJson);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                if (archiveJsonResult.ContainsKey("err")) //抓取錯誤
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    //logger.LogError("【ArchiveElectricMeterDayJob】【天歸檔】【取得資料失敗】");
 | 
				
			||||||
 | 
					                    //logger.LogError("【ArchiveElectricMeterDayJob】【天歸檔】【取得資料失敗】[錯誤內容]:{0}", archiveDayJsonResult);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    Dictionary<string, object> archiveDayRawData = new Dictionary<string, object>();
 | 
				
			||||||
 | 
					                    archiveDayRawData.Add("@device_number", deviceNumberPoint.DeviceNumber);
 | 
				
			||||||
 | 
					                    archiveDayRawData.Add("@point", deviceNumberPoint.Point);
 | 
				
			||||||
 | 
					                    archiveDayRawData.Add("@start_timestamp", startTimestamp.Replace("T", " ").Substring(0, 19));
 | 
				
			||||||
 | 
					                    archiveDayRawData.Add("@end_timestamp", endTimestamp.Replace("T", " ").Substring(0, 19));
 | 
				
			||||||
 | 
					                    archiveDayRawData.Add("@is_complete", 0);
 | 
				
			||||||
 | 
					                    archiveDayRawData.Add("@repeat_times", 0);
 | 
				
			||||||
 | 
					                    archiveDayRawData.Add("@fail_reason", archiveJson);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    archiveDayRawData.Add("@count_rawdata", 0);
 | 
				
			||||||
 | 
					                    archiveDayRawData.Add("@min_rawdata", 0);
 | 
				
			||||||
 | 
					                    archiveDayRawData.Add("@max_rawdata", 0);
 | 
				
			||||||
 | 
					                    archiveDayRawData.Add("@avg_rawdata", 0);
 | 
				
			||||||
 | 
					                    archiveDayRawData.Add("@sum_rawdata", 0);
 | 
				
			||||||
 | 
					                    archiveDayRawData.Add("@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    resultArchiveDayRawDatas.Add(archiveDayRawData);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                if (archiveJsonResult.ContainsKey("obj")) //表示可以讀取到內容
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    var ArrangeRawDatas = ArrangeRawData(deviceNumberPoint, archiveJsonResult);
 | 
				
			||||||
 | 
					                    if (ArrangeRawDatas != null && ArrangeRawDatas.Count() > 0)
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					                        resultArchiveDayRawDatas.AddRange(ArrangeRawDatas);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            #endregion 水電錶作業 save to DB end
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private List<Dictionary<string, object>> ArrangeRawData(DeviceNumberPoint deviceNumberPoint, JObject jsonResult)
 | 
					        private List<Dictionary<string, object>> ArrangeRawData(DeviceNumberPoint deviceNumberPoint, JObject jsonResult)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            List<Dictionary<string, object>> arrangeRawDatas = new List<Dictionary<string, object>>();
 | 
					            List<Dictionary<string, object>> arrangeRawDatas = new List<Dictionary<string, object>>();
 | 
				
			||||||
@ -969,6 +1150,7 @@ namespace BackendWorkerService.Services.Implement
 | 
				
			|||||||
                                    arrangeRawData.Add("@sum_rawdata", sum);
 | 
					                                    arrangeRawData.Add("@sum_rawdata", sum);
 | 
				
			||||||
                                    break;
 | 
					                                    break;
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -983,5 +1165,7 @@ namespace BackendWorkerService.Services.Implement
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            return arrangeRawDatas;
 | 
					            return arrangeRawDatas;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -7,6 +7,8 @@
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "LoggerPath": "C:\\inetpub\\Taipei_dome_background_service\\Logs",
 | 
					  "LoggerPath": "C:\\inetpub\\Taipei_dome_background_service\\Logs",
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  //MIN HOUR DOM MON DOW CMD
 | 
				
			||||||
  "BackgroundServiceCron": {
 | 
					  "BackgroundServiceCron": {
 | 
				
			||||||
    "ExecutionBackgroundServicePlanJob": "0 0 2 * * ?",
 | 
					    "ExecutionBackgroundServicePlanJob": "0 0 2 * * ?",
 | 
				
			||||||
    "MessageNotificationJob": "0 0 2 * * ?",
 | 
					    "MessageNotificationJob": "0 0 2 * * ?",
 | 
				
			||||||
@ -14,7 +16,7 @@
 | 
				
			|||||||
    "RegularUpdateDBTableJob": "0 0 2 * * ?",
 | 
					    "RegularUpdateDBTableJob": "0 0 2 * * ?",
 | 
				
			||||||
    "ParkingJob": "0 0 2 * * ?",
 | 
					    "ParkingJob": "0 0 2 * * ?",
 | 
				
			||||||
    "ArchiveElectricMeterHourJob": "0 0 2 * * ?",
 | 
					    "ArchiveElectricMeterHourJob": "0 0 2 * * ?",
 | 
				
			||||||
    "ArchiveElectricMeterDayJob": "0/5 * * * * ?",
 | 
					    "ArchiveElectricMeterDayJob": "0/5 * * * * ?", //每 5分鐘
 | 
				
			||||||
    "WeatherAPIJob": "0 0 2 * * ?"
 | 
					    "WeatherAPIJob": "0 0 2 * * ?"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "DBConfig": {
 | 
					  "DBConfig": {
 | 
				
			||||||
 | 
				
			|||||||
@ -175,7 +175,11 @@ namespace FrontendWebApi.ApiControllers
 | 
				
			|||||||
                                HistoryExport hed = new HistoryExport();
 | 
					                                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.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.deviceName = device.Where(x => x.device_number == ard["@device_number"].ToString()).Select(x => x.full_name).FirstOrDefault();
 | 
				
			||||||
                                hed.value = ard["@avg_rawdata"].ToString() == "-1" ? "NaN" : Math.Round((decimal.Parse(ard["@avg_rawdata"].ToString(), System.Globalization.NumberStyles.Float)), 2).ToString();
 | 
					                                // 四捨六入
 | 
				
			||||||
 | 
					                                //hed.value = ard["@avg_rawdata"].ToString() == "-1" ? "NaN" : Math.Round((decimal.Parse(ard["@avg_rawdata"].ToString(), System.Globalization.NumberStyles.Float)), 2).ToString();
 | 
				
			||||||
 | 
					                                // 四捨五入
 | 
				
			||||||
 | 
					                                //ref: Math.Round(Convert.ToDecimal(45.365), 2, MidpointRounding.AwayFromZero)
 | 
				
			||||||
 | 
					                                hed.value = ard["@avg_rawdata"].ToString() == "-1" ? "NaN" : Math.Round(Convert.ToDecimal(ard["@avg_rawdata"].ToString()), 2, MidpointRounding.AwayFromZero).ToString();                               
 | 
				
			||||||
                                hed.timestamp = Convert.ToDateTime(ard["@start_timestamp"].ToString());
 | 
					                                hed.timestamp = Convert.ToDateTime(ard["@start_timestamp"].ToString());
 | 
				
			||||||
                                hed.building_tag = d.building_tag;
 | 
					                                hed.building_tag = d.building_tag;
 | 
				
			||||||
                                he.Add(hed);
 | 
					                                he.Add(hed);
 | 
				
			||||||
 | 
				
			|||||||
@ -114,7 +114,7 @@ namespace FrontendWebApi.ApiControllers
 | 
				
			|||||||
                if (input.tableType == "year")
 | 
					                if (input.tableType == "year")
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    sqlGroup = $@" group by year(start_timestamp), year(end_timestamp), device_number ";
 | 
					                    sqlGroup = $@" group by year(start_timestamp), year(end_timestamp), device_number ";
 | 
				
			||||||
                    sqlAvgRawData = " round(avg(kwh_result), 2) as avg_rawdata, year(start_timestamp) as start_timestamp, year(end_timestamp) as end_timestamp ";
 | 
					                    sqlAvgRawData = " round(sum(kwh_result), 2) as avg_rawdata, year(start_timestamp) as start_timestamp, year(end_timestamp) as end_timestamp ";
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                else
 | 
					                else
 | 
				
			||||||
                    sqlAvgRawData = " round(kwh_result, 2) as avg_rawdata, start_timestamp, end_timestamp ";
 | 
					                    sqlAvgRawData = " round(kwh_result, 2) as avg_rawdata, start_timestamp, end_timestamp ";
 | 
				
			||||||
@ -138,14 +138,14 @@ namespace FrontendWebApi.ApiControllers
 | 
				
			|||||||
	                            select *
 | 
						                            select *
 | 
				
			||||||
	                            from (
 | 
						                            from (
 | 
				
			||||||
		                            (
 | 
							                            (
 | 
				
			||||||
			                            SELECT DATE(ADDDATE(@startTime, INTERVAL @i:=@i+1 {input.tableType})) AS date
 | 
								                            SELECT DATE(ADDDATE('{startTime}', INTERVAL @i:=@i+1 {input.tableType})) AS date
 | 
				
			||||||
                                        FROM {table}
 | 
					                                        FROM {table}
 | 
				
			||||||
			                            HAVING @i < TIMESTAMPDIFF({input.tableType}, @startTime, ADDDATE(@endTime, INTERVAL -1 DAY))
 | 
								                            HAVING @i < TIMESTAMPDIFF({input.tableType}, '{startTime}', ADDDATE('{endTime}' , INTERVAL -1 DAY))
 | 
				
			||||||
		                            ) d,
 | 
							                            ) d,
 | 
				
			||||||
		                            (   
 | 
							                            (   
 | 
				
			||||||
                                        select device_number
 | 
					                                        select device_number
 | 
				
			||||||
                                        from {table}
 | 
					                                        from {table}
 | 
				
			||||||
                                        where start_timestamp >= @startTime and end_timestamp < @endTime and point = 'KWH' {buildingSql}
 | 
					                                        where start_timestamp >= '{startTime}' and end_timestamp < '{endTime}'  and point = 'KWH' {buildingSql}
 | 
				
			||||||
                                        {sqlWhere} 
 | 
					                                        {sqlWhere} 
 | 
				
			||||||
                                        group by device_number
 | 
					                                        group by device_number
 | 
				
			||||||
                                    ) dn
 | 
					                                    ) dn
 | 
				
			||||||
@ -154,11 +154,13 @@ namespace FrontendWebApi.ApiControllers
 | 
				
			|||||||
                            left join (
 | 
					                            left join (
 | 
				
			||||||
	                            select device_number, {sqlAvgRawData}
 | 
						                            select device_number, {sqlAvgRawData}
 | 
				
			||||||
		                            from {table}
 | 
							                            from {table}
 | 
				
			||||||
 		                            where start_timestamp >= @startTime and end_timestamp < @endTime and point = 'KWH' {buildingSql}
 | 
					 		                            where start_timestamp >= '{startTime}' and end_timestamp < '{endTime}' and point = 'KWH' {buildingSql}
 | 
				
			||||||
                                    {sqlWhere} {sqlGroup}
 | 
					                                    {sqlWhere} {sqlGroup}
 | 
				
			||||||
                            ) aemm on aemm.start_timestamp >= {aemmStaDate} and aemm.end_timestamp < {aemmEndDate} and aemm.device_number = fd.device_number
 | 
					                            ) aemm on aemm.start_timestamp >= {aemmStaDate} and aemm.end_timestamp < {aemmEndDate} and aemm.device_number = fd.device_number
 | 
				
			||||||
 | 
					                            join device dc on fd.device_number = dc.device_number
 | 
				
			||||||
 | 
						                        where dc.deleted = 0
 | 
				
			||||||
                            order by fd.device_number, fd.date";
 | 
					                            order by fd.device_number, fd.date";
 | 
				
			||||||
                Logger.LogInformation("SQL = " + sql + " startTime=" + startTime + " endTime=" + endTime + " building=" + input.building_tag + " floor_tag = " + input.floor_tag);
 | 
					                Logger.LogInformation("0918 SQL = " + sql + Environment.NewLine + " startTime='" + startTime + "' endTime='" + endTime + "' building=" + input.building_tag );
 | 
				
			||||||
                var rawData = await backendRepository.GetAllAsync<HydroMeterRawDataOutput>(sql,
 | 
					                var rawData = await backendRepository.GetAllAsync<HydroMeterRawDataOutput>(sql,
 | 
				
			||||||
                                new { startTime = startTime, endtime = endTime, building_tag = input.building_tag, dateFormat = dateFormat });
 | 
					                                new { startTime = startTime, endtime = endTime, building_tag = input.building_tag, dateFormat = dateFormat });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -177,7 +179,7 @@ namespace FrontendWebApi.ApiControllers
 | 
				
			|||||||
                            .Select(x => new HydroMeterOutput { building_tag = x.Key.building_tag, floor_tag = x.Key.floor_tag, device_serial_tag = x.Key.device_serial_tag, device_master = x.Key.device_master, device_number = x.Key.device_number })
 | 
					                            .Select(x => new HydroMeterOutput { building_tag = x.Key.building_tag, floor_tag = x.Key.floor_tag, device_serial_tag = x.Key.device_serial_tag, device_master = x.Key.device_master, device_number = x.Key.device_number })
 | 
				
			||||||
                            .ToList();
 | 
					                            .ToList();
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					                int i = 0;
 | 
				
			||||||
                foreach (var l in list)
 | 
					                foreach (var l in list)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    l.rawData = new List<HydroMeterRawDataOutput>();
 | 
					                    l.rawData = new List<HydroMeterRawDataOutput>();
 | 
				
			||||||
@ -200,9 +202,11 @@ namespace FrontendWebApi.ApiControllers
 | 
				
			|||||||
                    l.price = input.price.HasValue 
 | 
					                    l.price = input.price.HasValue 
 | 
				
			||||||
                                ? (Math.Round(input.price.Value, 2)).ToString() 
 | 
					                                ? (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();
 | 
					                                : Math.Round((await backendRepository.GetOneAsync<decimal>("select system_value from variable where system_type = 'ElectricPrice' and deleted = 0")), 2).ToString();
 | 
				
			||||||
                    l.total_price = Math.Round((Decimal.Parse(l.total) * Decimal.Parse(l.price)), 2).ToString();
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                    
 | 
					                    
 | 
				
			||||||
 | 
					                    l.total_price = Math.Round((Decimal.Parse(l.total) * Decimal.Parse(l.price)), 2).ToString();
 | 
				
			||||||
 | 
					                    i++;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                Logger.LogInformation(" 筆數:" + i.ToString());
 | 
				
			||||||
                apiResult.Code = "0000";
 | 
					                apiResult.Code = "0000";
 | 
				
			||||||
                apiResult.Data = list;
 | 
					                apiResult.Data = list;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@ -467,6 +471,20 @@ namespace FrontendWebApi.ApiControllers
 | 
				
			|||||||
            styleLine12.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
 | 
					            styleLine12.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
 | 
				
			||||||
            styleLine12.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
 | 
					            styleLine12.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
 | 
				
			||||||
            styleLine12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
 | 
					            styleLine12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
 | 
				
			||||||
 | 
					            #region setting for data
 | 
				
			||||||
 | 
					            //IFont fontNumeric = workbook.CreateFont();
 | 
				
			||||||
 | 
					            //fontNumeric.FontName = "新細明體";
 | 
				
			||||||
 | 
					            //fontNumeric.FontHeightInPoints = 12;
 | 
				
			||||||
 | 
					            //ICellStyle styleLineNumeric = workbook.CreateCellStyle();
 | 
				
			||||||
 | 
					            //styleLineNumeric.SetFont(fontNumeric);
 | 
				
			||||||
 | 
					            //styleLineNumeric.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
 | 
				
			||||||
 | 
					            //styleLineNumeric.VerticalAlignment = VerticalAlignment.Center;
 | 
				
			||||||
 | 
					            //styleLineNumeric.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
 | 
				
			||||||
 | 
					            //styleLineNumeric.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
 | 
				
			||||||
 | 
					            //styleLineNumeric.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
 | 
				
			||||||
 | 
					            //styleLineNumeric.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
 | 
				
			||||||
 | 
					            #endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            ICellStyle stylein12 = workbook.CreateCellStyle();
 | 
					            ICellStyle stylein12 = workbook.CreateCellStyle();
 | 
				
			||||||
            stylein12.SetFont(font12Times);
 | 
					            stylein12.SetFont(font12Times);
 | 
				
			||||||
            stylein12.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
 | 
					            stylein12.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
 | 
				
			||||||
@ -482,7 +500,7 @@ namespace FrontendWebApi.ApiControllers
 | 
				
			|||||||
                if (r.Count > 0)
 | 
					                if (r.Count > 0)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    string buildingName = r.Select(x => x.building_name).FirstOrDefault();
 | 
					                    string buildingName = r.Select(x => x.building_name).FirstOrDefault();
 | 
				
			||||||
                    var sheet = workbook.CreateSheet($"{buildingName} 電表報表");
 | 
					                    var sheet = workbook.CreateSheet($"{r.Select( x=> x.device_full_name).FirstOrDefault()} 電表報表");
 | 
				
			||||||
                    int RowPosition = 0;
 | 
					                    int RowPosition = 0;
 | 
				
			||||||
                    #region set cell
 | 
					                    #region set cell
 | 
				
			||||||
                    IRow row = sheet.CreateRow(RowPosition);
 | 
					                    IRow row = sheet.CreateRow(RowPosition);
 | 
				
			||||||
@ -585,7 +603,7 @@ namespace FrontendWebApi.ApiControllers
 | 
				
			|||||||
            ms.Flush();
 | 
					            ms.Flush();
 | 
				
			||||||
            ms.Seek(0, SeekOrigin.Begin);
 | 
					            ms.Seek(0, SeekOrigin.Begin);
 | 
				
			||||||
            Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition");
 | 
					            Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition");
 | 
				
			||||||
            return File(ms, "application/vnd.ms", @$"電表報表{System.DateTime.Now.ToString("yyyyMMddHHmm")}.xlsx");
 | 
					            return File(ms, "application/vnd.ms", @$"{building}_電表報表{System.DateTime.Now.ToString("yyyyMMddHHmm")}.xlsx");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        [HttpPost]
 | 
					        [HttpPost]
 | 
				
			||||||
 | 
				
			|||||||
@ -19,8 +19,8 @@ namespace tpDomeWinAPP
 | 
				
			|||||||
            Application.EnableVisualStyles();
 | 
					            Application.EnableVisualStyles();
 | 
				
			||||||
            Application.SetCompatibleTextRenderingDefault(false);
 | 
					            Application.SetCompatibleTextRenderingDefault(false);
 | 
				
			||||||
            //Application.Run(new fmCheckTagName());
 | 
					            //Application.Run(new fmCheckTagName());
 | 
				
			||||||
            Application.Run(new fmKeke());
 | 
					            //Application.Run(new fmKeke());
 | 
				
			||||||
            //Application.Run(new fmDecrypt());
 | 
					            Application.Run(new fmDecrypt());
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										13
									
								
								z01_WinAPP/fmKeke.Designer.cs
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										13
									
								
								z01_WinAPP/fmKeke.Designer.cs
									
									
									
										generated
									
									
									
								
							@ -32,6 +32,7 @@
 | 
				
			|||||||
            lbMsg = new System.Windows.Forms.Label();
 | 
					            lbMsg = new System.Windows.Forms.Label();
 | 
				
			||||||
            loadData = new System.Windows.Forms.Button();
 | 
					            loadData = new System.Windows.Forms.Button();
 | 
				
			||||||
            dataGridView1 = new System.Windows.Forms.DataGridView();
 | 
					            dataGridView1 = new System.Windows.Forms.DataGridView();
 | 
				
			||||||
 | 
					            button1 = new System.Windows.Forms.Button();
 | 
				
			||||||
            ((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit();
 | 
					            ((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit();
 | 
				
			||||||
            splitContainer1.Panel1.SuspendLayout();
 | 
					            splitContainer1.Panel1.SuspendLayout();
 | 
				
			||||||
            splitContainer1.Panel2.SuspendLayout();
 | 
					            splitContainer1.Panel2.SuspendLayout();
 | 
				
			||||||
@ -48,6 +49,7 @@
 | 
				
			|||||||
            // 
 | 
					            // 
 | 
				
			||||||
            // splitContainer1.Panel1
 | 
					            // splitContainer1.Panel1
 | 
				
			||||||
            // 
 | 
					            // 
 | 
				
			||||||
 | 
					            splitContainer1.Panel1.Controls.Add(button1);
 | 
				
			||||||
            splitContainer1.Panel1.Controls.Add(lbMsg);
 | 
					            splitContainer1.Panel1.Controls.Add(lbMsg);
 | 
				
			||||||
            splitContainer1.Panel1.Controls.Add(loadData);
 | 
					            splitContainer1.Panel1.Controls.Add(loadData);
 | 
				
			||||||
            // 
 | 
					            // 
 | 
				
			||||||
@ -89,6 +91,16 @@
 | 
				
			|||||||
            dataGridView1.TabIndex = 0;
 | 
					            dataGridView1.TabIndex = 0;
 | 
				
			||||||
            dataGridView1.CellContentClick += dataGridView1_CellContentClick;
 | 
					            dataGridView1.CellContentClick += dataGridView1_CellContentClick;
 | 
				
			||||||
            // 
 | 
					            // 
 | 
				
			||||||
 | 
					            // button1
 | 
				
			||||||
 | 
					            // 
 | 
				
			||||||
 | 
					            button1.Location = new System.Drawing.Point(238, 32);
 | 
				
			||||||
 | 
					            button1.Name = "button1";
 | 
				
			||||||
 | 
					            button1.Size = new System.Drawing.Size(94, 29);
 | 
				
			||||||
 | 
					            button1.TabIndex = 1;
 | 
				
			||||||
 | 
					            button1.Text = "button1";
 | 
				
			||||||
 | 
					            button1.UseVisualStyleBackColor = true;
 | 
				
			||||||
 | 
					            button1.Click += button1_Click_1;
 | 
				
			||||||
 | 
					            // 
 | 
				
			||||||
            // fmKeke
 | 
					            // fmKeke
 | 
				
			||||||
            // 
 | 
					            // 
 | 
				
			||||||
            AutoScaleDimensions = new System.Drawing.SizeF(9F, 19F);
 | 
					            AutoScaleDimensions = new System.Drawing.SizeF(9F, 19F);
 | 
				
			||||||
@ -113,5 +125,6 @@
 | 
				
			|||||||
        private System.Windows.Forms.Button loadData;
 | 
					        private System.Windows.Forms.Button loadData;
 | 
				
			||||||
        private System.Windows.Forms.Label lbMsg;
 | 
					        private System.Windows.Forms.Label lbMsg;
 | 
				
			||||||
        private System.Windows.Forms.DataGridView dataGridView1;
 | 
					        private System.Windows.Forms.DataGridView dataGridView1;
 | 
				
			||||||
 | 
					        private System.Windows.Forms.Button button1;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -73,5 +73,13 @@ namespace z01_WinAPP
 | 
				
			|||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        private void button1_Click_1(object sender, EventArgs e)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            string targetTable = "archive_electric_meter_day_202308";
 | 
				
			||||||
 | 
					            string yyyymm = targetTable.Split('_')[targetTable.Split('_').Length - 1]; //取出 archive_electric_meter_day_202308 的最後一段 202308
 | 
				
			||||||
 | 
					            string yyyy = yyyymm.Substring(0, 4);
 | 
				
			||||||
 | 
					            string mm = yyyymm.Remove(0, 4);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -18,7 +18,7 @@
 | 
				
			|||||||
    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
 | 
					    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
 | 
				
			||||||
    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
 | 
					    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
 | 
				
			||||||
    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
 | 
					    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
 | 
				
			||||||
    <data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data>
 | 
					    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
 | 
				
			||||||
    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
 | 
					    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
 | 
				
			||||||
        <value>[base64 mime encoded serialized .NET Framework object]</value>
 | 
					        <value>[base64 mime encoded serialized .NET Framework object]</value>
 | 
				
			||||||
    </data>
 | 
					    </data>
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user