From c35aeb2f2ef57d906e69f2c0ccf286e31fda7972 Mon Sep 17 00:00:00 2001 From: "jay.chang" Date: Thu, 1 Feb 2024 15:06:59 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=B7=A8=E8=9B=8B?= =?UTF-8?q?=E6=B0=B4=E9=9B=BB=E6=AD=B8=E6=AA=94=E9=82=8F=E8=BC=AF=EF=BC=8C?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=9C=88=E6=AD=B8=E6=AA=94sql=E6=9C=83?= =?UTF-8?q?=E8=87=AA=E5=8B=95=E5=BB=BA=E7=AB=8Btable=E8=AA=9E=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BackendWorkerService/Program.cs | 24 +-- .../Quartz/Jobs/ArchiveElectricMeterDayJob.cs | 170 +++++++++++++++--- .../appsettings.Development.json | 2 +- 3 files changed, 160 insertions(+), 36 deletions(-) diff --git a/BackendWorkerService/Program.cs b/BackendWorkerService/Program.cs index 6fdac3c..7521b31 100644 --- a/BackendWorkerService/Program.cs +++ b/BackendWorkerService/Program.cs @@ -121,12 +121,12 @@ namespace BackendWorkerService //); //#endregion - #region 停車場管理(設定每 5秒 執行一次) - services.AddSingleton(); - services.AddSingleton( - new JobSchedule(jobType: typeof(ParkingJob), cronExpression: configuration.GetValue("BackgroundServiceCron:ParkingJob")) - ); - #endregion + //#region 停車場管理(設定每 5秒 執行一次) + //services.AddSingleton(); + //services.AddSingleton( + //new JobSchedule(jobType: typeof(ParkingJob), cronExpression: configuration.GetValue("BackgroundServiceCron:ParkingJob")) + //); + //#endregion //#region 電錶歸檔(設定每 小時 執行一次) //services.AddSingleton(); @@ -142,12 +142,12 @@ namespace BackendWorkerService ); #endregion - #region 定時取得氣象API - services.AddSingleton(); - services.AddSingleton( - new JobSchedule(jobType: typeof(Quartz.Jobs.WeatherAPIJob), cronExpression: configuration.GetValue("BackgroundServiceCron:WeatherAPIJob")) - ); - #endregion + //#region 定時取得氣象API + //services.AddSingleton(); + //services.AddSingleton( + //new JobSchedule(jobType: typeof(Quartz.Jobs.WeatherAPIJob), cronExpression: configuration.GetValue("BackgroundServiceCron:WeatherAPIJob")) + //); + //#endregion }).ConfigureLogging((hostContext, logFactory) => { IConfiguration configuration = hostContext.Configuration; diff --git a/BackendWorkerService/Quartz/Jobs/ArchiveElectricMeterDayJob.cs b/BackendWorkerService/Quartz/Jobs/ArchiveElectricMeterDayJob.cs index aeb8626..45ebe99 100644 --- a/BackendWorkerService/Quartz/Jobs/ArchiveElectricMeterDayJob.cs +++ b/BackendWorkerService/Quartz/Jobs/ArchiveElectricMeterDayJob.cs @@ -141,8 +141,8 @@ namespace BackendWorkerService.Quartz.Jobs try { await task_Detail.InsertWorkTime("ArchiveElectricMeterDayJob", "Day", "瘞湧餉”憭拐遙憪"); - //var preDay = now.AddDays(-1); //敺銝憭 - //var dbDateName = preDay.Year.ToString().PadLeft(4, '0') + preDay.Month.ToString().PadLeft(2, '0'); + var preDay = now.AddDays(-1); //敺銝憭 + var dbDateName = preDay.Year.ToString().PadLeft(4, '0') + preDay.Month.ToString().PadLeft(2, '0'); //var startTimestamp = string.Format("{0}T00:00:00.000+08:00", preDay.ToString("yyyy-MM-dd")); //var endTimestamp = string.Format("{0}T23:59:59.000+08:00", preDay.ToString("yyyy-MM-dd")); @@ -153,17 +153,11 @@ namespace BackendWorkerService.Quartz.Jobs // // "; - #region 敺甈 交唳典予箸迫 - - var preDay = now.AddDays(-1); //敺銝憭 - - var dbDateName = preDay.Year.ToString().PadLeft(4, '0') + preDay.Month.ToString().PadLeft(2, '0'); - - #endregion - //Stopwatch stopWatch = new Stopwatch(); //stopWatch.Start(); + #region 敺甈 交唳典予箸迫 + //瘥閮剖鞈 List> electericArchiveDayRawDatas = new List>(); List> waterArchiveDayRawDatas = new List>(); @@ -173,8 +167,10 @@ namespace BackendWorkerService.Quartz.Jobs var endDay = System.DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"); foreach (DateTime day in EachDay(startDay, endDay)) { - var sDay = string.Format("{0}T00:00:00.000+08:00", day.ToString("yyyy-MM-dd").Replace(" ", "T")); - var eDay = string.Format("{0}T00:15:00.000+08:00", day.AddDays(1).ToString("yyyy-MM-dd").Replace(" ", "T")); + //var sDay = string.Format("{0}T00:00:00.000+08:00", day.ToString("yyyy-MM-dd").Replace(" ", "T")); // 撌刻冽迨啁撖阡狼00:15:00鞈 + var sDay = string.Format("{0}T23:59:59.000+08:00", day.AddDays(-1).ToString("yyyy-MM-dd").Replace(" ", "T")); // 撌刻冽迨啁撖阡狼00:00:00鞈 + + var eDay = string.Format("{0}T00:00:00.000+08:00", day.AddDays(1).ToString("yyyy-MM-dd").Replace(" ", "T")); string historyQueryFilter = $@" @@ -252,11 +248,13 @@ namespace BackendWorkerService.Quartz.Jobs foreach (var deviceNumberPoint in waterDeviceNumberPoints) { var startDay = deviceNumberPoint.archive_lastDate.ToString("yyyy-MM-dd"); - var endDay = System.DateTime.Now.ToString("yyyy-MM-dd"); + var endDay = System.DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"); foreach (DateTime day in EachDay(startDay, endDay)) { - var sDay = string.Format("{0}T00:00:00.000+08:00", day.ToString("yyyy-MM-dd").Replace(" ", "T")); - var eDay = string.Format("{0}T00:15:00.000+08:00", day.AddDays(1).ToString("yyyy-MM-dd").Replace(" ", "T")); + //var sDay = string.Format("{0}T00:00:00.000+08:00", day.ToString("yyyy-MM-dd").Replace(" ", "T")); // 撌刻冽迨啁撖阡狼00:15:00鞈 + var sDay = string.Format("{0}T23:59:59.000+08:00", day.AddDays(-1).ToString("yyyy-MM-dd").Replace(" ", "T")); // 撌刻冽迨啁撖阡狼00:00:00鞈 + + var eDay = string.Format("{0}T00:00:00.000+08:00", day.AddDays(1).ToString("yyyy-MM-dd").Replace(" ", "T")); string historyQueryFilter = $@" @@ -334,7 +332,7 @@ namespace BackendWorkerService.Quartz.Jobs } } - + #endregion //stopWatch.Stop(); //logger.LogInformation("ArchiveElectricMeterDayJob憭拇飛瑼賣炎撽[敺鞈梯祥]{0} 瘥怎", stopWatch.ElapsedMilliseconds); @@ -1090,22 +1088,24 @@ namespace BackendWorkerService.Quartz.Jobs try { await task_Detail.InsertWorkTime("ArchiveElectricMeterDayJob", "Month", "瘞湧餉”隞餃憪"); - var FirstDay = now.AddDays(-now.Day + 1); - //var LastDay = now.AddMonths(1).AddDays(-now.AddMonths(1).Day); - var LastDay = FirstDay.AddMonths(1); + var preDay = now.AddDays(-1); //敺銝憭 + + var dayInMonth = DateTime.DaysInMonth(preDay.Year, preDay.Month); + var FirstDay = preDay.AddDays(- dayInMonth + 1); + //var LastDay = now.AddMonths(1).AddDays(-now.AddMonths(1).Day); // 舀啗府敺銝憭 + var LastDay = FirstDay.AddMonths(1); //雿撖阡閰脫蝚砌憭 - var dayInMonth = DateTime.DaysInMonth(now.Year, now.Month); - var startTimestamp = string.Format("{0}T00:00:00.000+08:00", FirstDay.ToString("yyyy-MM-dd")); + var startTimestamp = string.Format("{0}T23:59:59.000+08:00", FirstDay.AddDays(-1).ToString("yyyy-MM-dd")); // 撌刻閬璅豢臬 //var endTimestamp = string.Format("{0}T23:59:59.000+08:00", LastDay.ToString("yyyy-MM-dd")); - var endTimestamp = string.Format("{0}T00:15:00.000+08:00", LastDay.ToString("yyyy-MM-dd")); // 240131 jay for dome + var endTimestamp = string.Format("{0}T00:00:00.000+08:00", LastDay.ToString("yyyy-MM-dd")); // 240131 jay for dome var historyQueryFilter = $@" - + "; //Stopwatch stopWatch = new Stopwatch(); @@ -1258,7 +1258,29 @@ namespace BackendWorkerService.Quartz.Jobs if (electricArchiveMonthRawDatas.Count() > 0) { var sql = $@" + CREATE TABLE IF NOT EXISTS `archive_electric_water_meter_month` ( + `device_number` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL, + `point` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL, + `start_timestamp` datetime(6) NOT NULL, + `end_timestamp` datetime(6) NULL DEFAULT NULL, + `count_rawdata` int(11) NULL DEFAULT NULL, + `min_rawdata` decimal(15, 3) NULL DEFAULT NULL, + `max_rawdata` decimal(15, 3) NULL DEFAULT NULL, + `sub_result` decimal(15, 3) NULL DEFAULT NULL, + `avg_rawdata` decimal(15, 3) NULL DEFAULT NULL, + `sum_rawdata` decimal(15, 3) NULL DEFAULT NULL, + `is_complete` tinyint(3) UNSIGNED NULL DEFAULT NULL COMMENT '臬血嚗0:芸 1:摰', + `repeat_times` int(11) NULL DEFAULT 0 COMMENT '銴甈⊥', + `fail_reason` varchar(4000) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '憭望', + `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, + `updated_at` datetime(6) NULL DEFAULT NULL, + PRIMARY KEY (`device_number`, `point`, `start_timestamp`) USING BTREE + ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = DYNAMIC; + + SET FOREIGN_KEY_CHECKS = 1; UPDATE archive_electric_water_meter_month SET + start_timestamp = @start_timestamp, + end_timestamp = @end_timestamp, count_rawdata = @count_rawdata, min_rawdata = @min_rawdata, max_rawdata = @max_rawdata, @@ -1304,8 +1326,48 @@ namespace BackendWorkerService.Quartz.Jobs WHERE ROW_COUNT() = 0;"; var mySql = $@"BEGIN TRANSACTION; + IF OBJECT_ID(N'dbo.archive_electric_water_meter_month', N'U') is null + BEGIN + CREATE TABLE [dbo].[archive_electric_water_meter_month]( + [device_number] [varchar](50) NOT NULL, + [point] [varchar](20) NOT NULL, + [start_timestamp] [datetime] NOT NULL, + [end_timestamp] [datetime] NULL, + [count_rawdata] [int] NULL, + [min_rawdata] [decimal](15, 3) NULL, + [max_rawdata] [decimal](15, 3) NULL, + [sub_result] [decimal](15, 3) NULL, + [avg_rawdata] [decimal](15, 3) NULL, + [sum_rawdata] [decimal](15, 3) NULL, + [is_complete] [tinyint] NULL, + [repeat_times] [int] NULL, + [fail_reason] [nvarchar](max) NULL, + [created_at] [datetime] NULL, + [updated_at] [datetime] NULL, + CONSTRAINT [PK_archive_electric_water_meter_month] PRIMARY KEY CLUSTERED + ( + [device_number] ASC, + [point] ASC, + [start_timestamp] ASC + )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] + ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] + + ALTER TABLE [dbo].[archive_electric_water_meter_month] ADD CONSTRAINT [DF_archive_electric_water_meter_month_repeat_times] DEFAULT ((0)) FOR [repeat_times] + + ALTER TABLE [dbo].[archive_electric_water_meter_month] ADD CONSTRAINT [DF_archive_electric_water_meter_month_created_at] DEFAULT (getdate()) FOR [created_at] + + ALTER TABLE [dbo].[archive_electric_water_meter_month] ADD CONSTRAINT [DF_archive_electric_water_meter_month_updated_at] DEFAULT (NULL) FOR [updated_at] + + EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'臬血嚗0:芸 1:摰' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'archive_electric_water_meter_month', @level2type=N'COLUMN',@level2name=N'is_complete' + + EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'銴甈⊥' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'archive_electric_water_meter_month', @level2type=N'COLUMN',@level2name=N'repeat_times' + + EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'憭望' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'archive_electric_water_meter_month', @level2type=N'COLUMN',@level2name=N'fail_reason' + END UPDATE archive_electric_water_meter_month SET + start_timestamp = @start_timestamp, + end_timestamp = @end_timestamp, count_rawdata = @count_rawdata, min_rawdata = @min_rawdata, max_rawdata = @max_rawdata, @@ -1362,7 +1424,29 @@ namespace BackendWorkerService.Quartz.Jobs if (waterArchiveMonthRawDatas.Count() > 0) { var sql = $@" + CREATE TABLE IF NOT EXISTS `archive_electric_water_meter_month` ( + `device_number` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL, + `point` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL, + `start_timestamp` datetime(6) NOT NULL, + `end_timestamp` datetime(6) NULL DEFAULT NULL, + `count_rawdata` int(11) NULL DEFAULT NULL, + `min_rawdata` decimal(15, 3) NULL DEFAULT NULL, + `max_rawdata` decimal(15, 3) NULL DEFAULT NULL, + `sub_result` decimal(15, 3) NULL DEFAULT NULL, + `avg_rawdata` decimal(15, 3) NULL DEFAULT NULL, + `sum_rawdata` decimal(15, 3) NULL DEFAULT NULL, + `is_complete` tinyint(3) UNSIGNED NULL DEFAULT NULL COMMENT '臬血嚗0:芸 1:摰', + `repeat_times` int(11) NULL DEFAULT 0 COMMENT '銴甈⊥', + `fail_reason` varchar(4000) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '憭望', + `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, + `updated_at` datetime(6) NULL DEFAULT NULL, + PRIMARY KEY (`device_number`, `point`, `start_timestamp`) USING BTREE + ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = DYNAMIC; + + SET FOREIGN_KEY_CHECKS = 1; UPDATE archive_electric_water_meter_month SET + start_timestamp = @start_timestamp, + end_timestamp = @end_timestamp, count_rawdata = @count_rawdata, min_rawdata = @min_rawdata, max_rawdata = @max_rawdata, @@ -1408,8 +1492,48 @@ namespace BackendWorkerService.Quartz.Jobs WHERE ROW_COUNT() = 0;"; var mySql = $@"BEGIN TRANSACTION; + IF OBJECT_ID(N'dbo.archive_electric_water_meter_month', N'U') is null + BEGIN + CREATE TABLE [dbo].[archive_electric_water_meter_month]( + [device_number] [varchar](50) NOT NULL, + [point] [varchar](20) NOT NULL, + [start_timestamp] [datetime] NOT NULL, + [end_timestamp] [datetime] NULL, + [count_rawdata] [int] NULL, + [min_rawdata] [decimal](15, 3) NULL, + [max_rawdata] [decimal](15, 3) NULL, + [sub_result] [decimal](15, 3) NULL, + [avg_rawdata] [decimal](15, 3) NULL, + [sum_rawdata] [decimal](15, 3) NULL, + [is_complete] [tinyint] NULL, + [repeat_times] [int] NULL, + [fail_reason] [nvarchar](max) NULL, + [created_at] [datetime] NULL, + [updated_at] [datetime] NULL, + CONSTRAINT [PK_archive_electric_water_meter_month] PRIMARY KEY CLUSTERED + ( + [device_number] ASC, + [point] ASC, + [start_timestamp] ASC + )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] + ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] + + ALTER TABLE [dbo].[archive_electric_water_meter_month] ADD CONSTRAINT [DF_archive_electric_water_meter_month_repeat_times] DEFAULT ((0)) FOR [repeat_times] + + ALTER TABLE [dbo].[archive_electric_water_meter_month] ADD CONSTRAINT [DF_archive_electric_water_meter_month_created_at] DEFAULT (getdate()) FOR [created_at] + + ALTER TABLE [dbo].[archive_electric_water_meter_month] ADD CONSTRAINT [DF_archive_electric_water_meter_month_updated_at] DEFAULT (NULL) FOR [updated_at] + + EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'臬血嚗0:芸 1:摰' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'archive_electric_water_meter_month', @level2type=N'COLUMN',@level2name=N'is_complete' + + EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'銴甈⊥' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'archive_electric_water_meter_month', @level2type=N'COLUMN',@level2name=N'repeat_times' + + EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'憭望' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'archive_electric_water_meter_month', @level2type=N'COLUMN',@level2name=N'fail_reason' + END UPDATE archive_electric_water_meter_month SET + start_timestamp = @start_timestamp, + end_timestamp = @end_timestamp, count_rawdata = @count_rawdata, min_rawdata = @min_rawdata, max_rawdata = @max_rawdata, diff --git a/BackendWorkerService/appsettings.Development.json b/BackendWorkerService/appsettings.Development.json index 1a5d4fd..9dd0d11 100644 --- a/BackendWorkerService/appsettings.Development.json +++ b/BackendWorkerService/appsettings.Development.json @@ -19,7 +19,7 @@ }, "DBConfig": { "MySqlDBConfig": { - "Server": "CYGthbCeGtAXT4s1NOSJHQ==", //0.202 + "Server": "CYGthbCeGtAXT4s1NOSJHQ==", //0.132 "Port": "mkF51jVbg40V5K5eTh2Ckw==", //3306 //"Database": "VJB2XC+lAtzuHObDGMVOAA==", //30 //"Database": "IgYBsgG2VLKKxFb64j7LOA==", //wsp From 151e54356419b0eb47776c093039cc6ad2791206 Mon Sep 17 00:00:00 2001 From: "jay.chang" Date: Thu, 1 Feb 2024 17:40:49 +0800 Subject: [PATCH 2/5] =?UTF-8?q?[WebAPI]=E6=B0=B4=E9=9B=BB=E5=A0=B1?= =?UTF-8?q?=E8=A1=A8API=E5=9B=9E=E5=82=B3=E5=80=BC=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FrontendWebApi/ApiControllers/TenantBillController.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/FrontendWebApi/ApiControllers/TenantBillController.cs b/FrontendWebApi/ApiControllers/TenantBillController.cs index b78f3a8..d2a85d8 100644 --- a/FrontendWebApi/ApiControllers/TenantBillController.cs +++ b/FrontendWebApi/ApiControllers/TenantBillController.cs @@ -109,6 +109,7 @@ namespace FrontendWebApi.ApiControllers apiResult.Msg = "啣冽嗅仃"; if (exception.Message.Contains($" for key 'PRIMARY'")) { + apiResult.Code = "0001"; apiResult.Msg = "撌脫詨雿輻刻"; } Logger.LogError("" + controllerName + "/" + actionName + "" + exception.Message); @@ -143,6 +144,7 @@ namespace FrontendWebApi.ApiControllers apiResult.Msg = "靽格孵仃"; if (exception.Message.Contains($"a foreign key constraint")) { + apiResult.Code = "0001"; apiResult.Msg = "瘞湧餃梯”隞閰脩冽塚⊥靽格孵蝔晞"; } Logger.LogError("" + controllerName + "/" + actionName + "" + exception.Message); @@ -170,6 +172,7 @@ namespace FrontendWebApi.ApiControllers apiResult.Msg = "芷斤冽嗅仃"; if (exception.Message.Contains($"a foreign key constraint")) { + apiResult.Code = "0001"; apiResult.Msg = "瘞湧餃梯”隞閰脩冽塚⊥芷扎"; } Logger.LogError("" + controllerName + "/" + actionName + "" + exception.Message); @@ -250,13 +253,13 @@ namespace FrontendWebApi.ApiControllers } if (start_timestamp == "") { - apiResult.Code = "9999"; + apiResult.Code = "0001"; apiResult.Msg = "隢豢韏瑕交"; return apiResult; } if (end_timestamp == "") { - apiResult.Code = "9999"; + apiResult.Code = "0001"; apiResult.Msg = "隢豢蝯交"; return apiResult; } @@ -300,7 +303,7 @@ namespace FrontendWebApi.ApiControllers // $"updated_at = '{updated_at}', " + // $"tenant_guid = '{tb.tenant_guid}' " + // $"WHERE device_number = '{tb.device_number}'"; - apiResult.Code = "9999"; + apiResult.Code = "0001"; apiResult.Msg = "隢豢銝隞"; return apiResult; } From 30457e621fcf165c8efb272aab581f31d98c8755 Mon Sep 17 00:00:00 2001 From: "jay.chang" Date: Mon, 5 Feb 2024 11:10:32 +0800 Subject: [PATCH 3/5] =?UTF-8?q?[BackendWorkerService]=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=B0=B4=E9=9B=BB=E5=A0=B1=E8=A1=A8=E6=AD=B8=E6=AA=94=E9=82=8F?= =?UTF-8?q?=E8=BC=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Quartz/Jobs/ArchiveElectricMeterDayJob.cs | 61 +++++++++++++------ 1 file changed, 41 insertions(+), 20 deletions(-) diff --git a/BackendWorkerService/Quartz/Jobs/ArchiveElectricMeterDayJob.cs b/BackendWorkerService/Quartz/Jobs/ArchiveElectricMeterDayJob.cs index 45ebe99..386a1ff 100644 --- a/BackendWorkerService/Quartz/Jobs/ArchiveElectricMeterDayJob.cs +++ b/BackendWorkerService/Quartz/Jobs/ArchiveElectricMeterDayJob.cs @@ -140,6 +140,7 @@ namespace BackendWorkerService.Quartz.Jobs { try { + await task_Detail.InsertWorkTime("ArchiveElectricMeterDayJob", "Day", "瘞湧餉”憭拐遙憪"); var preDay = now.AddDays(-1); //敺銝憭 var dbDateName = preDay.Year.ToString().PadLeft(4, '0') + preDay.Month.ToString().PadLeft(2, '0'); @@ -167,10 +168,10 @@ namespace BackendWorkerService.Quartz.Jobs var endDay = System.DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"); foreach (DateTime day in EachDay(startDay, endDay)) { - //var sDay = string.Format("{0}T00:00:00.000+08:00", day.ToString("yyyy-MM-dd").Replace(" ", "T")); // 撌刻冽迨啁撖阡狼00:15:00鞈 - var sDay = string.Format("{0}T23:59:59.000+08:00", day.AddDays(-1).ToString("yyyy-MM-dd").Replace(" ", "T")); // 撌刻冽迨啁撖阡狼00:00:00鞈 + var sDay = string.Format("{0}T00:00:00.000+08:00", day.ToString("yyyy-MM-dd").Replace(" ", "T")); // 撌刻冽迨啁撖阡狼00:15:00鞈 + //var sDay = string.Format("{0}T23:59:59.000+08:00", day.AddDays(-1).ToString("yyyy-MM-dd").Replace(" ", "T")); // 撌刻冽迨啁撖阡狼00:00:00鞈 - var eDay = string.Format("{0}T00:00:00.000+08:00", day.AddDays(1).ToString("yyyy-MM-dd").Replace(" ", "T")); + var eDay = string.Format("{0}T00:15:00.000+08:00", day.AddDays(1).ToString("yyyy-MM-dd").Replace(" ", "T")); string historyQueryFilter = $@" @@ -251,10 +252,10 @@ namespace BackendWorkerService.Quartz.Jobs var endDay = System.DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"); foreach (DateTime day in EachDay(startDay, endDay)) { - //var sDay = string.Format("{0}T00:00:00.000+08:00", day.ToString("yyyy-MM-dd").Replace(" ", "T")); // 撌刻冽迨啁撖阡狼00:15:00鞈 - var sDay = string.Format("{0}T23:59:59.000+08:00", day.AddDays(-1).ToString("yyyy-MM-dd").Replace(" ", "T")); // 撌刻冽迨啁撖阡狼00:00:00鞈 + var sDay = string.Format("{0}T00:00:00.000+08:00", day.ToString("yyyy-MM-dd").Replace(" ", "T")); // 撌刻冽迨啁撖阡狼00:15:00鞈 + //var sDay = string.Format("{0}T23:59:59.000+08:00", day.AddDays(-1).ToString("yyyy-MM-dd").Replace(" ", "T")); // 撌刻冽迨啁撖阡狼00:00:00鞈 - var eDay = string.Format("{0}T00:00:00.000+08:00", day.AddDays(1).ToString("yyyy-MM-dd").Replace(" ", "T")); + var eDay = string.Format("{0}T00:15:00.000+08:00", day.AddDays(1).ToString("yyyy-MM-dd").Replace(" ", "T")); string historyQueryFilter = $@" @@ -338,7 +339,11 @@ namespace BackendWorkerService.Quartz.Jobs if (electericArchiveDayRawDatas.Count() > 0) { - var sql = $@"CREATE TABLE IF NOT EXISTS `archive_electric_water_meter_day_{dbDateName}` ( + foreach (var row in electericArchiveDayRawDatas) + { + row.TryGetValue("@start_timestamp", out var yyyymmData); + dbDateName = System.DateTime.Parse(yyyymmData.ToString()).ToString("yyyyMM"); + var sql = $@"CREATE TABLE IF NOT EXISTS `archive_electric_water_meter_day_{dbDateName}` ( `device_number` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL, `point` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL, `start_timestamp` datetime(6) NOT NULL, @@ -405,7 +410,7 @@ namespace BackendWorkerService.Quartz.Jobs update device set archive_lastDate = @start_timestamp, archive_lastActionDate = @updated_at where device_number = @device_number;"; //archive_lastDate 甈∪ 嚗archive_lastActionDate 祆活雿璆剜 - var mySql = $@"BEGIN TRANSACTION; + var mySql = $@"BEGIN TRANSACTION; IF OBJECT_ID(N'dbo.archive_electric_water_meter_day_{dbDateName}', N'U') is null BEGIN CREATE TABLE [dbo].[archive_electric_water_meter_day_{dbDateName}]( @@ -493,15 +498,20 @@ namespace BackendWorkerService.Quartz.Jobs END COMMIT TRANSACTION;"; - await backgroundServiceRepository.ExecuteSql(sql, electericArchiveDayRawDatas); - if (!string.IsNullOrEmpty(saveToMSDB) && saveToMSDB == "1") - { - await backgroundServiceMsSqlRepository.ExecuteSql(mySql, electericArchiveDayRawDatas); + await backgroundServiceRepository.ExecuteSql(sql, row); + if (!string.IsNullOrEmpty(saveToMSDB) && saveToMSDB == "1") + { + await backgroundServiceMsSqlRepository.ExecuteSql(mySql, row); + } } } if (waterArchiveDayRawDatas.Count() > 0) { - var sql = $@" + foreach (var row in waterArchiveDayRawDatas) + { + row.TryGetValue("@start_timestamp", out var yyyymmData); + dbDateName = System.DateTime.Parse(yyyymmData.ToString()).ToString("yyyyMM"); + var sql = $@" CREATE TABLE IF NOT EXISTS `archive_electric_water_meter_day_{dbDateName}` ( `device_number` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL, `point` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL, @@ -569,7 +579,7 @@ namespace BackendWorkerService.Quartz.Jobs update device set archive_lastDate = @start_timestamp, archive_lastActionDate = @updated_at where device_number = @device_number;"; //archive_lastDate 甈∪ 嚗archive_lastActionDate 祆活雿璆剜 - var mySql = $@"BEGIN TRANSACTION; + var mySql = $@"BEGIN TRANSACTION; IF OBJECT_ID(N'dbo.archive_electric_water_meter_day_{dbDateName}', N'U') is null BEGIN CREATE TABLE [dbo].[archive_electric_water_meter_day_{dbDateName}]( @@ -657,10 +667,11 @@ namespace BackendWorkerService.Quartz.Jobs END COMMIT TRANSACTION;"; - await backgroundServiceRepository.ExecuteSql(sql, waterArchiveDayRawDatas); - if (!string.IsNullOrEmpty(saveToMSDB) && saveToMSDB == "1") - { - await backgroundServiceMsSqlRepository.ExecuteSql(mySql, waterArchiveDayRawDatas); + await backgroundServiceRepository.ExecuteSql(sql, row); + if (!string.IsNullOrEmpty(saveToMSDB) && saveToMSDB == "1") + { + await backgroundServiceMsSqlRepository.ExecuteSql(mySql, row); + } } } await task_Detail.InsertWorkTime_End("ArchiveElectricMeterDayJob", "Day", "隞餃摰"); @@ -1097,9 +1108,11 @@ namespace BackendWorkerService.Quartz.Jobs - var startTimestamp = string.Format("{0}T23:59:59.000+08:00", FirstDay.AddDays(-1).ToString("yyyy-MM-dd")); // 撌刻閬璅豢臬 + //var startTimestamp = string.Format("{0}T23:59:59.000+08:00", FirstDay.AddDays(-1).ToString("yyyy-MM-dd")); // 撌刻閬璅豢臬 + var startTimestamp = string.Format("{0}T00:00:00.000+08:00", FirstDay.ToString("yyyy-MM-dd")); + //var endTimestamp = string.Format("{0}T23:59:59.000+08:00", LastDay.ToString("yyyy-MM-dd")); - var endTimestamp = string.Format("{0}T00:00:00.000+08:00", LastDay.ToString("yyyy-MM-dd")); // 240131 jay for dome + var endTimestamp = string.Format("{0}T00:15:00.000+08:00", LastDay.ToString("yyyy-MM-dd")); // 240131 jay for dome var historyQueryFilter = $@" @@ -1644,6 +1657,14 @@ namespace BackendWorkerService.Quartz.Jobs for (var day = strtday.Date; day.Date <= endday.Date; day = day.AddDays(1)) yield return day; } + public IEnumerable EachMonth(string from, string thru) + { + var strtday = DateTime.Parse(from); + var endday = DateTime.Parse(thru); + for (var _month = strtday.Date; _month.Month <= endday.Month; _month = _month.AddDays(1)) + yield return _month; + + } private List> ArrangeRawData(DeviceNumberPoint deviceNumberPoint, JObject jsonResult) { List> arrangeRawDatas = new List>(); From 0615483bb4a80a39c21ce6a51478f91f07493c20 Mon Sep 17 00:00:00 2001 From: "jay.chang" Date: Mon, 5 Feb 2024 13:24:01 +0800 Subject: [PATCH 4/5] =?UTF-8?q?[BackendWorkerService]=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=9C=88=E6=AD=B8=E6=AA=94=E8=B5=B7=E8=A8=96=E6=99=82=E9=96=93?= =?UTF-8?q?=E9=82=8F=E8=BC=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Quartz/Jobs/ArchiveElectricMeterDayJob.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/BackendWorkerService/Quartz/Jobs/ArchiveElectricMeterDayJob.cs b/BackendWorkerService/Quartz/Jobs/ArchiveElectricMeterDayJob.cs index 386a1ff..39c05fc 100644 --- a/BackendWorkerService/Quartz/Jobs/ArchiveElectricMeterDayJob.cs +++ b/BackendWorkerService/Quartz/Jobs/ArchiveElectricMeterDayJob.cs @@ -6,6 +6,7 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using NPOI.SS.Formula.Functions; using Quartz; using Repository.BackendRepository.Interface; using Repository.Helper; @@ -140,7 +141,7 @@ namespace BackendWorkerService.Quartz.Jobs { try { - + await task_Detail.InsertWorkTime("ArchiveElectricMeterDayJob", "Day", "瘞湧餉”憭拐遙憪"); var preDay = now.AddDays(-1); //敺銝憭 var dbDateName = preDay.Year.ToString().PadLeft(4, '0') + preDay.Month.ToString().PadLeft(2, '0'); @@ -674,7 +675,7 @@ namespace BackendWorkerService.Quartz.Jobs } } } - await task_Detail.InsertWorkTime_End("ArchiveElectricMeterDayJob", "Day", "隞餃摰"); + await task_Detail.InsertWorkTime_End("ArchiveElectricMeterDayJob", "Day", "瘞湧餉”憭拐遙摰"); } catch (Exception exception) { @@ -1102,9 +1103,9 @@ namespace BackendWorkerService.Quartz.Jobs var preDay = now.AddDays(-1); //敺銝憭 var dayInMonth = DateTime.DaysInMonth(preDay.Year, preDay.Month); - var FirstDay = preDay.AddDays(- dayInMonth + 1); + var FirstDay = new DateTime(preDay.Year, preDay.Month, 1); //var LastDay = now.AddMonths(1).AddDays(-now.AddMonths(1).Day); // 舀啗府敺銝憭 - var LastDay = FirstDay.AddMonths(1); //雿撖阡閰脫蝚砌憭 + var LastDay = now; @@ -1600,7 +1601,7 @@ namespace BackendWorkerService.Quartz.Jobs await backgroundServiceMsSqlRepository.ExecuteSql(mySql, waterArchiveMonthRawDatas); } } - await task_Detail.InsertWorkTime_End("ArchiveElectricMeterDayJob", "Month", "隞餃摰"); + await task_Detail.InsertWorkTime_End("ArchiveElectricMeterDayJob", "Month", "瘞湧餉”隞餃摰"); } catch (Exception exception) { From 5ab5319116c9b4ba7ef93167154f919e839e89f1 Mon Sep 17 00:00:00 2001 From: "jay.chang" Date: Tue, 6 Feb 2024 07:28:36 +0800 Subject: [PATCH 5/5] =?UTF-8?q?[Webapi]=E6=B0=B4=E9=9B=BB=E5=A0=B1?= =?UTF-8?q?=E8=A1=A8=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BackendWorkerService.csproj | 1 + .../ApiControllers/TenantBillController.cs | 187 ++++++++++++------ FrontendWebApi/appsettings.Development.json | 15 +- 3 files changed, 134 insertions(+), 69 deletions(-) diff --git a/BackendWorkerService/BackendWorkerService.csproj b/BackendWorkerService/BackendWorkerService.csproj index 0bcb027..06a89c1 100644 --- a/BackendWorkerService/BackendWorkerService.csproj +++ b/BackendWorkerService/BackendWorkerService.csproj @@ -7,6 +7,7 @@ + diff --git a/FrontendWebApi/ApiControllers/TenantBillController.cs b/FrontendWebApi/ApiControllers/TenantBillController.cs index d2a85d8..0ced42d 100644 --- a/FrontendWebApi/ApiControllers/TenantBillController.cs +++ b/FrontendWebApi/ApiControllers/TenantBillController.cs @@ -19,6 +19,7 @@ using Microsoft.Extensions.Configuration; using Serilog.Core; using static FrontendWebApi.ApiControllers.TenantBillController; using System.Reflection; +using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -110,7 +111,7 @@ namespace FrontendWebApi.ApiControllers if (exception.Message.Contains($" for key 'PRIMARY'")) { apiResult.Code = "0001"; - apiResult.Msg = "撌脫詨雿輻刻"; + apiResult.Msg = "撌脫詨冽嗚"; } Logger.LogError("" + controllerName + "/" + actionName + "" + exception.Message); } @@ -193,14 +194,7 @@ namespace FrontendWebApi.ApiControllers string building_tag = tb.building_tag; string ElecOrWater = tableType == "elec" ? "E4" : "W1"; string sqlString = null; - if (building_tag == "ALL") - { - sqlString = - $"SELECT bill_id,a.device_number,a.full_name,start_timestamp,end_timestamp,result,bill,tenant_name,tenant_guid " + - $"from {TenantBilltable} a join device b on a.device_number =b.device_number" + - $"where a.device_name_tag = '{ElecOrWater}' "; - } - else if (building_tag == "D2") + if (building_tag == "D2") { sqlString = $"SELECT bill_id,a.device_number,a.full_name,start_timestamp,end_timestamp,result,bill,tenant_name,tenant_guid " + @@ -251,22 +245,82 @@ namespace FrontendWebApi.ApiControllers startMonth = tb.start_timestamp.Split("-")[0] + tb.start_timestamp.Split("-")[1]; endMonth = tb.end_timestamp.Split("-")[0] + tb.end_timestamp.Split("-")[1]; } - if (start_timestamp == "") - { - apiResult.Code = "0001"; - apiResult.Msg = "隢豢韏瑕交"; - return apiResult; - } - if (end_timestamp == "") - { - apiResult.Code = "0001"; - apiResult.Msg = "隢豢蝯交"; - return apiResult; - } - - if (startMonth == endMonth) + else { sqlString = + $@"UPDATE {TenantBilltable} + set tenant_name = (SELECT tenant_name from archive_electric_meter_tenant_list WHERE tenant_guid = '{tb.tenant_guid}'), + result = 0, + bill= 0, + start_timestamp = '{start_timestamp}', + end_timestamp = '{end_timestamp}', + updated_at = '{updated_at}', + tenant_guid = '{tb.tenant_guid}' + WHERE device_number = '{tb.device_number}'"; + + await backendRepository.ExecuteSql(sqlString); + + + apiResult.Code = "0000"; + apiResult.Data = "靽格寞"; + return apiResult; + } + if (tb.tenant_guid != "" && tb.tenant_guid != null) + { + if (startMonth == endMonth) + { + sqlString = + $"UPDATE {TenantBilltable} " + + $"set tenant_name = (SELECT tenant_name from archive_electric_meter_tenant_list WHERE tenant_guid = '{tb.tenant_guid}'), start_timestamp = '{start_timestamp}',end_timestamp = '{end_timestamp}' , " + + $"result= " + + $"(select sum(sub_result) " + + $"from archive_electric_water_meter_day_{startMonth} " + + $"WHERE device_number = '{tb.device_number}' and start_timestamp BETWEEN '{start_timestamp}' and '{end_timestamp}' " + + $"GROUP BY device_number) , " + + $"bill = " + + $"ROUND(result *(SELECT {bill_per} from {TenantListtable} WHERE tenant_guid = '{tb.tenant_guid}') ), " + + $"updated_at = '{updated_at}', " + + $"tenant_guid = '{tb.tenant_guid}' " + + $"WHERE device_number = '{tb.device_number}'"; + } + else + { + string month = ""; + DateTime date1 = DateTime.Parse(start_timestamp); + DateTime date2 = DateTime.Parse(end_timestamp); + int monthsApart = ((date2.Year - date1.Year) * 12) + date2.Month - date1.Month; + for (var i = 1; i <= monthsApart; i++) + { + month += $@"UNION ALL + SELECT start_timestamp,device_number, sub_result + FROM archive_electric_water_meter_day_{date1.AddMonths(i).ToString("yyyyMM")} + WHERE device_number = '{tb.device_number}' "; + } + sqlString = + $@"UPDATE {TenantBilltable} + set tenant_name = (SELECT tenant_name from archive_electric_meter_tenant_list WHERE tenant_guid = '{tb.tenant_guid}'), start_timestamp = '{start_timestamp}',end_timestamp = '{end_timestamp}' , + result= + (SELECT sum(sub_result) + FROM ( + SELECT start_timestamp,device_number, sub_result + FROM archive_electric_water_meter_day_{startMonth} + WHERE device_number = '{tb.device_number}' "+ + $@"{month}" + + $@" ) combined_result + WHERE start_timestamp BETWEEN '{start_timestamp}' and '{end_timestamp}' + GROUP BY device_number) , + bill = + ROUND(result *(SELECT {bill_per} from {TenantListtable} WHERE tenant_guid = '{tb.tenant_guid}') ), + updated_at = '{updated_at}', + tenant_guid = '{tb.tenant_guid}' + WHERE device_number = '{tb.device_number}'"; + } + } + else + { + if (startMonth == endMonth) + { + sqlString = $"UPDATE {TenantBilltable} " + $"set tenant_name = (SELECT tenant_name from archive_electric_meter_tenant_list WHERE tenant_guid = '{tb.tenant_guid}'), start_timestamp = '{start_timestamp}',end_timestamp = '{end_timestamp}' , " + $"result= " + @@ -274,39 +328,44 @@ namespace FrontendWebApi.ApiControllers $"from archive_electric_water_meter_day_{startMonth} " + $"WHERE device_number = '{tb.device_number}' and start_timestamp BETWEEN '{start_timestamp}' and '{end_timestamp}' " + $"GROUP BY device_number) , " + - $"bill = " + - $"ROUND(result *(SELECT {bill_per} from {TenantListtable} WHERE tenant_guid = '{tb.tenant_guid}') ), " + + $"bill = 0 ," + $"updated_at = '{updated_at}', " + $"tenant_guid = '{tb.tenant_guid}' " + $"WHERE device_number = '{tb.device_number}'"; + } + else + { + string month = ""; + DateTime date1 = DateTime.Parse(start_timestamp); + DateTime date2 = DateTime.Parse(end_timestamp); + int monthsApart = ((date2.Year - date1.Year) * 12) + date2.Month - date1.Month; + for (var i = 1; i <= monthsApart; i++) + { + month += $@"UNION ALL + SELECT start_timestamp,device_number, sub_result + FROM archive_electric_water_meter_day_{date1.AddMonths(i).ToString("yyyyMM")} + WHERE device_number = '{tb.device_number}' "; + } + sqlString = + $@"UPDATE {TenantBilltable} + set tenant_name = (SELECT tenant_name from archive_electric_meter_tenant_list WHERE tenant_guid = '{tb.tenant_guid}'), start_timestamp = '{start_timestamp}',end_timestamp = '{end_timestamp}' , + result= + (SELECT sum(sub_result) + FROM ( + SELECT start_timestamp,device_number, sub_result + FROM archive_electric_water_meter_day_{startMonth} + WHERE device_number = '{tb.device_number}' " + + $@"{month}" + + $@" ) combined_result + WHERE start_timestamp BETWEEN '{start_timestamp}' and '{end_timestamp}' + GROUP BY device_number) , + bill = 0, + updated_at = '{updated_at}', + tenant_guid = '{tb.tenant_guid}' + WHERE device_number = '{tb.device_number}'"; + } } - else - { - //sqlString = - // $"UPDATE {TenantBilltable} " + - // $"set tenant_name = (SELECT tenant_name from archive_electric_meter_tenant_list WHERE tenant_guid = '{tb.tenant_guid}'), start_timestamp = '{start_timestamp}',end_timestamp = '{end_timestamp}' , " + - // $"result= " + - // $"(SELECT sum(sub_result) " + - // $"FROM ( " + - // $" SELECT start_timestamp,device_number, sub_result " + - // $" FROM archive_electric_water_meter_day_{startMonth} " + - // $" WHERE device_number = '{tb.device_number}' " + - // $" UNION ALL " + - // $" SELECT start_timestamp,device_number, sub_result " + - // $" FROM archive_electric_water_meter_day_{endMonth} " + - // $" WHERE device_number = '{tb.device_number}' " + - // $") combined_result " + - // $"WHERE start_timestamp BETWEEN '{start_timestamp}' and '{end_timestamp}' " + - // $"GROUP BY device_number) ," + - // $"bill = " + - // $"ROUND(result *(SELECT {bill_per} from {TenantListtable} WHERE tenant_guid = '{tb.tenant_guid}') ), " + - // $"updated_at = '{updated_at}', " + - // $"tenant_guid = '{tb.tenant_guid}' " + - // $"WHERE device_number = '{tb.device_number}'"; - apiResult.Code = "0001"; - apiResult.Msg = "隢豢銝隞"; - return apiResult; - } + await backendRepository.ExecuteSql(sqlString); @@ -319,6 +378,11 @@ namespace FrontendWebApi.ApiControllers { apiResult.Code = "9999"; apiResult.Msg = "靽格寞偌餃梯”憭望"; + if (exception.Message.Contains($"doesn't exist")) + { + apiResult.Code = "0001"; + apiResult.Msg = "詨典∟"; + } Logger.LogError("" + controllerName + "/" + actionName + "" + exception.Message); } @@ -335,16 +399,15 @@ namespace FrontendWebApi.ApiControllers { string sqlString = $@"SELECT - a.tenant_name,a.start_timestamp,a.end_timestamp,bill_perKWH,bill_perRCV, - SUM(CASE WHEN device_name_tag = 'E4' THEN result ELSE 0 END) AS elec_result, - SUM(CASE WHEN device_name_tag = 'W1' THEN result ELSE 0 END) AS water_result, - SUM(CASE WHEN device_name_tag = 'E4' THEN bill ELSE 0 END) AS elec_bill, - SUM(CASE WHEN device_name_tag = 'W1' THEN bill ELSE 0 END) AS water_bill, - SUM(bill) AS total_bill - FROM archive_electric_meter_tenant_bill a - JOIN archive_electric_meter_tenant_list b on a.tenant_guid = b.tenant_guid - GROUP BY a.tenant_name - HAVING SUM(bill) != 0"; + a.tenant_name,min(a.start_timestamp)as start_timestamp,max(a.end_timestamp) as end_timestamp,bill_perKWH,bill_perRCV, + SUM(CASE WHEN device_name_tag = 'E4' THEN result ELSE 0 END) AS elec_result, + SUM(CASE WHEN device_name_tag = 'W1' THEN result ELSE 0 END) AS water_result, + SUM(CASE WHEN device_name_tag = 'E4' THEN bill ELSE 0 END) AS elec_bill, + SUM(CASE WHEN device_name_tag = 'W1' THEN bill ELSE 0 END) AS water_bill, + SUM(bill) AS total_bill + FROM archive_electric_meter_tenant_bill a + JOIN archive_electric_meter_tenant_list b on a.tenant_guid = b.tenant_guid + GROUP BY a.tenant_name;"; outputBill = await backendRepository.GetAllAsync(sqlString); string filePath = CreateOutputForm(outputBill); diff --git a/FrontendWebApi/appsettings.Development.json b/FrontendWebApi/appsettings.Development.json index 84e653e..15b59c3 100644 --- a/FrontendWebApi/appsettings.Development.json +++ b/FrontendWebApi/appsettings.Development.json @@ -13,18 +13,19 @@ "JwtLifeSeconds": 3600 }, "FilePath": { - "OutputForm": "D:\\jay.chang\\dome\\FrontendWebApi\\wwwroot\\upload\\OutputForm\\", //瘞湧餃梯” 瑼獢脣雿蝵 - "OutputFormTemplate": "D:\\jay.chang\\dome\\FrontendWebApi\\wwwroot\\upload\\OutputFormTemplate\\import.html", // 瘞湧餃梯”蝭祆雿蝵 - "Image": "D:\\jay.chang\\dome\\FrontendWebApi\\wwwroot\\upload\\OutputFormTemplate\\dome.png" // 蝝啁 + "OutputForm": "C:\\jay.chang\\ibms\\FrontendWebApi\\wwwroot\\upload\\OutputForm\\", //瘞湧餃梯” 瑼獢脣雿蝵 + "OutputFormTemplate": "C:\\jay.chang\\ibms\\FrontendWebApi\\wwwroot\\upload\\OutputFormTemplate\\import.html", // 瘞湧餃梯”蝭祆雿蝵 + "Image": "C:\\jay.chang\\ibms\\FrontendWebApi\\wwwroot\\img\\dome.png" // 蝝啁 }, "DBConfig": { "MySqlDBConfig": { - "Server": "FYlY+w0XDIz+jmF2rlZWJw==", //0.201 - "Port": "js2LutKe+rdjzdxMPQUrvQ==", + //"Server": "FYlY+w0XDIz+jmF2rlZWJw==", //0.201 + "Server": "CYGthbCeGtAXT4s1NOSJHQ==", //0.132 + "Port": "mkF51jVbg40V5K5eTh2Ckw==", //3306 //"Database": "VJB2XC+lAtzuHObDGMVOAA==", //30 //"Database": "IgYBsgG2VLKKxFb64j7LOA==", //wsp - //"Database": "7gWfmZ28HGIJZbxEbK+0yg==", //tpe_dome_dome - "Database": "+5RAiFLJVU+LRyDxF1K/pcLZaoZa4k/thZqF6xKoCag=", //dome_online_0821 + "Database": "7gWfmZ28HGIJZbxEbK+0yg==", //tpe_dome_dome + //"Database": "+5RAiFLJVU+LRyDxF1K/pcLZaoZa4k/thZqF6xKoCag=", //dome_online_0821 //"Database": "siTUcDaC/g2yGTMFWD72Kg==", //tpe_dome_hotel //"Database": "iuaY0h0+TWkir44/eZLDqw==", //tpe_dome_office //"Database": "Rq7Gn4x6LwBvVtl7GY8LbA==", //MCUT