From 75692b26da31d8806443ea286eba687258f30975 Mon Sep 17 00:00:00 2001 From: dev02 Date: Mon, 29 May 2023 17:10:19 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=BE=8C=E5=8F=B0]=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=8E=92=E7=A8=8B=E9=8C=AF=E8=AA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Quartz/Jobs/ArchiveElectricMeterDayJob.cs | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/BackendWorkerService/Quartz/Jobs/ArchiveElectricMeterDayJob.cs b/BackendWorkerService/Quartz/Jobs/ArchiveElectricMeterDayJob.cs index cf7fe03..e1f6670 100644 --- a/BackendWorkerService/Quartz/Jobs/ArchiveElectricMeterDayJob.cs +++ b/BackendWorkerService/Quartz/Jobs/ArchiveElectricMeterDayJob.cs @@ -322,7 +322,7 @@ namespace BackendWorkerService.Quartz.Jobs WHERE ROW_COUNT() = 0;"; var mySql = $@"BEGIN TRANSACTION; - IF OBJECT_ID(N'dbo.archive_water_meter_day_{dbDateName}', N'U') is null + IF OBJECT_ID(N'dbo.archive_electric_meter_day_{dbDateName}', N'U') is null BEGIN CREATE TABLE [dbo].[archive_electric_meter_day_{dbDateName}]( [device_number] [varchar](50) NOT NULL, @@ -414,7 +414,25 @@ namespace BackendWorkerService.Quartz.Jobs if (waterArchiveDayRawDatas.Count() > 0) { var sql = $@" - UPDATE archive_water_meter_day SET + CREATE TABLE IF NOT EXISTS `archive_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, + `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, + `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; + + UPDATE archive_water_meter_day_{dbDateName} SET count_rawdata = @count_rawdata, min_rawdata = @min_rawdata, max_rawdata = @max_rawdata, @@ -429,7 +447,7 @@ namespace BackendWorkerService.Quartz.Jobs AND start_timestamp = @start_timestamp; - INSERT INTO archive_water_meter_day ( + INSERT INTO archive_water_meter_day_{dbDateName} ( device_number, point, start_timestamp, @@ -496,7 +514,7 @@ namespace BackendWorkerService.Quartz.Jobs EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'失敗原因' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'archive_water_meter_day_{dbDateName}', @level2type=N'COLUMN',@level2name=N'fail_reason' END - UPDATE archive_water_meter_day SET + UPDATE archive_water_meter_day_{dbDateName} SET count_rawdata = @count_rawdata, min_rawdata = @min_rawdata, max_rawdata = @max_rawdata, @@ -512,7 +530,7 @@ namespace BackendWorkerService.Quartz.Jobs IF @@ROWCOUNT = 0 BEGIN - INSERT INTO archive_water_meter_day ( + INSERT INTO archive_water_meter_day_{dbDateName} ( device_number, point, start_timestamp,