解決衝突系統監控衝突
This commit is contained in:
commit
1f0b2402ef
@ -56,6 +56,7 @@ namespace BackendWorkerService.Quartz.Jobs
|
|||||||
XmlDocument xmlDocument = new XmlDocument();
|
XmlDocument xmlDocument = new XmlDocument();
|
||||||
|
|
||||||
var sqlArchive = $@"SELECT system_value as Value, system_key as Name FROM variable WHERE deleted = 0 AND system_type = 'archiveConfig'";
|
var sqlArchive = $@"SELECT system_value as Value, system_key as Name FROM variable WHERE deleted = 0 AND system_type = 'archiveConfig'";
|
||||||
|
var saveToMSDB = await backgroundServiceRepository.GetOneAsync<string>("select system_value from variable where system_type = 'save_to_ms_db' and deleted = 0");
|
||||||
|
|
||||||
var variableArchive = await backgroundServiceRepository.GetAllAsync<KeyValue>(sqlArchive);
|
var variableArchive = await backgroundServiceRepository.GetAllAsync<KeyValue>(sqlArchive);
|
||||||
var electricMeterGuid = variableArchive.Where(x => x.Name == "ElectricMeterGuid").Select(x => x.Value).FirstOrDefault();
|
var electricMeterGuid = variableArchive.Where(x => x.Name == "ElectricMeterGuid").Select(x => x.Value).FirstOrDefault();
|
||||||
@ -126,6 +127,7 @@ namespace BackendWorkerService.Quartz.Jobs
|
|||||||
{
|
{
|
||||||
await task_Detail.InsertWorkTime("ArchiveElectricMeterDayJob", "Day", "任務開始");
|
await task_Detail.InsertWorkTime("ArchiveElectricMeterDayJob", "Day", "任務開始");
|
||||||
var preDay = now.AddDays(-1); //取得前一天
|
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 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"));
|
var endTimestamp = string.Format("{0}T23:59:59.000+08:00", preDay.ToString("yyyy-MM-dd"));
|
||||||
@ -258,8 +260,26 @@ namespace BackendWorkerService.Quartz.Jobs
|
|||||||
|
|
||||||
if (electericArchiveDayRawDatas.Count() > 0)
|
if (electericArchiveDayRawDatas.Count() > 0)
|
||||||
{
|
{
|
||||||
var sql = $@"
|
var sql = $@"CREATE TABLE IF NOT EXISTS `archive_electric_meter_day_{dbDateName}` (
|
||||||
UPDATE archive_electric_meter_day SET
|
`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;
|
||||||
|
|
||||||
|
SET FOREIGN_KEY_CHECKS = 1;
|
||||||
|
UPDATE archive_electric_meter_day_{dbDateName} SET
|
||||||
count_rawdata = @count_rawdata,
|
count_rawdata = @count_rawdata,
|
||||||
min_rawdata = @min_rawdata,
|
min_rawdata = @min_rawdata,
|
||||||
max_rawdata = @max_rawdata,
|
max_rawdata = @max_rawdata,
|
||||||
@ -273,8 +293,7 @@ namespace BackendWorkerService.Quartz.Jobs
|
|||||||
AND point = @point
|
AND point = @point
|
||||||
AND start_timestamp = @start_timestamp;
|
AND start_timestamp = @start_timestamp;
|
||||||
|
|
||||||
|
INSERT INTO archive_electric_meter_day_{dbDateName} (
|
||||||
INSERT INTO archive_electric_meter_day (
|
|
||||||
device_number,
|
device_number,
|
||||||
point,
|
point,
|
||||||
start_timestamp,
|
start_timestamp,
|
||||||
@ -303,8 +322,45 @@ namespace BackendWorkerService.Quartz.Jobs
|
|||||||
WHERE ROW_COUNT() = 0;";
|
WHERE ROW_COUNT() = 0;";
|
||||||
|
|
||||||
var mySql = $@"BEGIN TRANSACTION;
|
var mySql = $@"BEGIN TRANSACTION;
|
||||||
|
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,
|
||||||
|
[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,
|
||||||
|
[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_meter_day_{dbDateName}] 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]
|
||||||
|
|
||||||
UPDATE archive_electric_meter_day SET
|
ALTER TABLE [dbo].[archive_electric_meter_day_{dbDateName}] ADD CONSTRAINT [DF_archive_electric_meter_day_{dbDateName}_repeat_times] DEFAULT ((0)) FOR [repeat_times]
|
||||||
|
|
||||||
|
ALTER TABLE [dbo].[archive_electric_meter_day_{dbDateName}] ADD CONSTRAINT [DF_archive_electric_meter_day_{dbDateName}_created_at] DEFAULT (getdate()) FOR [created_at]
|
||||||
|
|
||||||
|
ALTER TABLE [dbo].[archive_electric_meter_day_{dbDateName}] ADD CONSTRAINT [DF_archive_electric_meter_day_{dbDateName}_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_meter_day_{dbDateName}', @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_meter_day_{dbDateName}', @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_meter_day_{dbDateName}', @level2type=N'COLUMN',@level2name=N'fail_reason'
|
||||||
|
END
|
||||||
|
|
||||||
|
UPDATE archive_electric_meter_day_{dbDateName} SET
|
||||||
count_rawdata = @count_rawdata,
|
count_rawdata = @count_rawdata,
|
||||||
min_rawdata = @min_rawdata,
|
min_rawdata = @min_rawdata,
|
||||||
max_rawdata = @max_rawdata,
|
max_rawdata = @max_rawdata,
|
||||||
@ -320,7 +376,7 @@ namespace BackendWorkerService.Quartz.Jobs
|
|||||||
|
|
||||||
IF @@ROWCOUNT = 0
|
IF @@ROWCOUNT = 0
|
||||||
BEGIN
|
BEGIN
|
||||||
INSERT INTO archive_electric_meter_day (
|
INSERT INTO archive_electric_meter_day_{dbDateName} (
|
||||||
device_number,
|
device_number,
|
||||||
point,
|
point,
|
||||||
start_timestamp,
|
start_timestamp,
|
||||||
@ -350,12 +406,33 @@ namespace BackendWorkerService.Quartz.Jobs
|
|||||||
|
|
||||||
COMMIT TRANSACTION;";
|
COMMIT TRANSACTION;";
|
||||||
await backgroundServiceRepository.ExecuteSql(sql, electericArchiveDayRawDatas);
|
await backgroundServiceRepository.ExecuteSql(sql, electericArchiveDayRawDatas);
|
||||||
await backgroundServiceMsSqlRepository.ExecuteSql(mySql, electericArchiveDayRawDatas);
|
if (!string.IsNullOrEmpty(saveToMSDB) && saveToMSDB == "1")
|
||||||
|
{
|
||||||
|
await backgroundServiceMsSqlRepository.ExecuteSql(mySql, electericArchiveDayRawDatas);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (waterArchiveDayRawDatas.Count() > 0)
|
if (waterArchiveDayRawDatas.Count() > 0)
|
||||||
{
|
{
|
||||||
var sql = $@"
|
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,
|
count_rawdata = @count_rawdata,
|
||||||
min_rawdata = @min_rawdata,
|
min_rawdata = @min_rawdata,
|
||||||
max_rawdata = @max_rawdata,
|
max_rawdata = @max_rawdata,
|
||||||
@ -370,7 +447,7 @@ namespace BackendWorkerService.Quartz.Jobs
|
|||||||
AND start_timestamp = @start_timestamp;
|
AND start_timestamp = @start_timestamp;
|
||||||
|
|
||||||
|
|
||||||
INSERT INTO archive_water_meter_day (
|
INSERT INTO archive_water_meter_day_{dbDateName} (
|
||||||
device_number,
|
device_number,
|
||||||
point,
|
point,
|
||||||
start_timestamp,
|
start_timestamp,
|
||||||
@ -399,8 +476,45 @@ namespace BackendWorkerService.Quartz.Jobs
|
|||||||
WHERE ROW_COUNT() = 0;";
|
WHERE ROW_COUNT() = 0;";
|
||||||
|
|
||||||
var mySql = $@"BEGIN TRANSACTION;
|
var mySql = $@"BEGIN TRANSACTION;
|
||||||
|
IF OBJECT_ID(N'dbo.archive_water_meter_day_{dbDateName}', N'U') is null
|
||||||
|
BEGIN
|
||||||
|
CREATE TABLE [dbo].[archive_water_meter_day_{dbDateName}](
|
||||||
|
[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,
|
||||||
|
[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_water_meter_day_{dbDateName}] 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]
|
||||||
|
|
||||||
UPDATE archive_water_meter_day SET
|
ALTER TABLE [dbo].[archive_water_meter_day_{dbDateName}] ADD CONSTRAINT [DF_archive_water_meter_day_{dbDateName}_repeat_times] DEFAULT ((0)) FOR [repeat_times]
|
||||||
|
|
||||||
|
ALTER TABLE [dbo].[archive_water_meter_day_{dbDateName}] ADD CONSTRAINT [DF_archive_water_meter_day_{dbDateName}_created_at] DEFAULT (getdate()) FOR [created_at]
|
||||||
|
|
||||||
|
ALTER TABLE [dbo].[archive_water_meter_day_{dbDateName}] ADD CONSTRAINT [DF_archive_water_meter_day_{dbDateName}_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_water_meter_day_{dbDateName}', @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_water_meter_day_{dbDateName}', @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_water_meter_day_{dbDateName}', @level2type=N'COLUMN',@level2name=N'fail_reason'
|
||||||
|
END
|
||||||
|
|
||||||
|
UPDATE archive_water_meter_day_{dbDateName} SET
|
||||||
count_rawdata = @count_rawdata,
|
count_rawdata = @count_rawdata,
|
||||||
min_rawdata = @min_rawdata,
|
min_rawdata = @min_rawdata,
|
||||||
max_rawdata = @max_rawdata,
|
max_rawdata = @max_rawdata,
|
||||||
@ -416,7 +530,7 @@ namespace BackendWorkerService.Quartz.Jobs
|
|||||||
|
|
||||||
IF @@ROWCOUNT = 0
|
IF @@ROWCOUNT = 0
|
||||||
BEGIN
|
BEGIN
|
||||||
INSERT INTO archive_water_meter_day (
|
INSERT INTO archive_water_meter_day_{dbDateName} (
|
||||||
device_number,
|
device_number,
|
||||||
point,
|
point,
|
||||||
start_timestamp,
|
start_timestamp,
|
||||||
@ -446,7 +560,10 @@ namespace BackendWorkerService.Quartz.Jobs
|
|||||||
|
|
||||||
COMMIT TRANSACTION;";
|
COMMIT TRANSACTION;";
|
||||||
await backgroundServiceRepository.ExecuteSql(sql, waterArchiveDayRawDatas);
|
await backgroundServiceRepository.ExecuteSql(sql, waterArchiveDayRawDatas);
|
||||||
await backgroundServiceMsSqlRepository.ExecuteSql(mySql, waterArchiveDayRawDatas);
|
if (!string.IsNullOrEmpty(saveToMSDB) && saveToMSDB == "1")
|
||||||
|
{
|
||||||
|
await backgroundServiceMsSqlRepository.ExecuteSql(mySql, waterArchiveDayRawDatas);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
await task_Detail.InsertWorkTime_End("ArchiveElectricMeterDayJob", "Day", "任務完成");
|
await task_Detail.InsertWorkTime_End("ArchiveElectricMeterDayJob", "Day", "任務完成");
|
||||||
}
|
}
|
||||||
@ -691,7 +808,10 @@ namespace BackendWorkerService.Quartz.Jobs
|
|||||||
|
|
||||||
COMMIT TRANSACTION;";
|
COMMIT TRANSACTION;";
|
||||||
await backgroundServiceRepository.ExecuteSql(sql, electricArchiveWeekRawDatas);
|
await backgroundServiceRepository.ExecuteSql(sql, electricArchiveWeekRawDatas);
|
||||||
await backgroundServiceMsSqlRepository.ExecuteSql(mySql, electricArchiveWeekRawDatas);
|
if (!string.IsNullOrEmpty(saveToMSDB) && saveToMSDB == "1")
|
||||||
|
{
|
||||||
|
await backgroundServiceMsSqlRepository.ExecuteSql(mySql, electricArchiveWeekRawDatas);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (waterArchiveWeekRawDatas.Count() > 0)
|
if (waterArchiveWeekRawDatas.Count() > 0)
|
||||||
@ -790,8 +910,10 @@ namespace BackendWorkerService.Quartz.Jobs
|
|||||||
|
|
||||||
COMMIT TRANSACTION;";
|
COMMIT TRANSACTION;";
|
||||||
await backgroundServiceRepository.ExecuteSql(sql, waterArchiveWeekRawDatas);
|
await backgroundServiceRepository.ExecuteSql(sql, waterArchiveWeekRawDatas);
|
||||||
await backgroundServiceMsSqlRepository.ExecuteSql(mySql, waterArchiveWeekRawDatas);
|
if (!string.IsNullOrEmpty(saveToMSDB) && saveToMSDB == "1")
|
||||||
|
{
|
||||||
|
await backgroundServiceMsSqlRepository.ExecuteSql(mySql, waterArchiveWeekRawDatas);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
await task_Detail.InsertWorkTime_End("ArchiveElectricMeterDayJob", "Week", "任務完成");
|
await task_Detail.InsertWorkTime_End("ArchiveElectricMeterDayJob", "Week", "任務完成");
|
||||||
}
|
}
|
||||||
@ -1035,7 +1157,10 @@ namespace BackendWorkerService.Quartz.Jobs
|
|||||||
|
|
||||||
COMMIT TRANSACTION;";
|
COMMIT TRANSACTION;";
|
||||||
await backgroundServiceRepository.ExecuteSql(sql, electricArchiveMonthRawDatas);
|
await backgroundServiceRepository.ExecuteSql(sql, electricArchiveMonthRawDatas);
|
||||||
await backgroundServiceMsSqlRepository.ExecuteSql(mySql, electricArchiveMonthRawDatas);
|
if (!string.IsNullOrEmpty(saveToMSDB) && saveToMSDB == "1")
|
||||||
|
{
|
||||||
|
await backgroundServiceMsSqlRepository.ExecuteSql(mySql, electricArchiveMonthRawDatas);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (waterArchiveMonthRawDatas.Count() > 0)
|
if (waterArchiveMonthRawDatas.Count() > 0)
|
||||||
{
|
{
|
||||||
@ -1130,7 +1255,10 @@ namespace BackendWorkerService.Quartz.Jobs
|
|||||||
|
|
||||||
COMMIT TRANSACTION;";
|
COMMIT TRANSACTION;";
|
||||||
await backgroundServiceRepository.ExecuteSql(sql, waterArchiveMonthRawDatas);
|
await backgroundServiceRepository.ExecuteSql(sql, waterArchiveMonthRawDatas);
|
||||||
await backgroundServiceMsSqlRepository.ExecuteSql(mySql, waterArchiveMonthRawDatas);
|
if (!string.IsNullOrEmpty(saveToMSDB) && saveToMSDB == "1")
|
||||||
|
{
|
||||||
|
await backgroundServiceMsSqlRepository.ExecuteSql(mySql, waterArchiveMonthRawDatas);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
await task_Detail.InsertWorkTime_End("ArchiveElectricMeterDayJob", "Month", "任務完成");
|
await task_Detail.InsertWorkTime_End("ArchiveElectricMeterDayJob", "Month", "任務完成");
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,7 @@ namespace BackendWorkerService.Services.Implement
|
|||||||
|
|
||||||
var variableArchive = await backgroundServiceRepository.GetAllAsync<KeyValue>(sqlArchive);
|
var variableArchive = await backgroundServiceRepository.GetAllAsync<KeyValue>(sqlArchive);
|
||||||
repeatTimes = Convert.ToInt32(variableArchive.Where(x => x.Name == "RepeatTimes").Select(x => x.Value).FirstOrDefault());
|
repeatTimes = Convert.ToInt32(variableArchive.Where(x => x.Name == "RepeatTimes").Select(x => x.Value).FirstOrDefault());
|
||||||
|
var saveToMSDB = await backgroundServiceRepository.GetOneAsync<string>("select system_value from variable where system_type = 'save_to_ms_db' and deleted = 0");
|
||||||
|
|
||||||
#region 取得obix 設定
|
#region 取得obix 設定
|
||||||
var sqlObix = $@"SELECT system_value as Value, system_key as Name FROM variable WHERE deleted = 0 AND system_type = 'obixConfig'";
|
var sqlObix = $@"SELECT system_value as Value, system_key as Name FROM variable WHERE deleted = 0 AND system_type = 'obixConfig'";
|
||||||
@ -324,7 +325,10 @@ namespace BackendWorkerService.Services.Implement
|
|||||||
{
|
{
|
||||||
var Mysql_error_update = string.Format(MYsql_update_format, targetTable);
|
var Mysql_error_update = string.Format(MYsql_update_format, targetTable);
|
||||||
var sql_error_update = string.Format(sql_update_format, targetTable);
|
var sql_error_update = string.Format(sql_update_format, targetTable);
|
||||||
await backgroundServiceMsSqlRepository.ExecuteSql(sql_error_update, electricArchiveDayRawDatas);
|
if (!string.IsNullOrEmpty(saveToMSDB) && saveToMSDB == "1")
|
||||||
|
{
|
||||||
|
await backgroundServiceMsSqlRepository.ExecuteSql(sql_error_update, electricArchiveDayRawDatas);
|
||||||
|
}
|
||||||
await backgroundServiceRepository.ExecuteSql(Mysql_error_update, electricArchiveDayRawDatas);
|
await backgroundServiceRepository.ExecuteSql(Mysql_error_update, electricArchiveDayRawDatas);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -405,7 +409,10 @@ namespace BackendWorkerService.Services.Implement
|
|||||||
{
|
{
|
||||||
var Mysql_error_update = string.Format(MYsql_update_format, targetTable);
|
var Mysql_error_update = string.Format(MYsql_update_format, targetTable);
|
||||||
var sql_error_update = string.Format(sql_update_format, targetTable);
|
var sql_error_update = string.Format(sql_update_format, targetTable);
|
||||||
await backgroundServiceMsSqlRepository.ExecuteSql(sql_error_update, waterArchiveDayRawDatas);
|
if (!string.IsNullOrEmpty(saveToMSDB) && saveToMSDB == "1")
|
||||||
|
{
|
||||||
|
await backgroundServiceMsSqlRepository.ExecuteSql(sql_error_update, waterArchiveDayRawDatas);
|
||||||
|
}
|
||||||
await backgroundServiceRepository.ExecuteSql(Mysql_error_update, waterArchiveDayRawDatas);
|
await backgroundServiceRepository.ExecuteSql(Mysql_error_update, waterArchiveDayRawDatas);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -489,7 +496,10 @@ namespace BackendWorkerService.Services.Implement
|
|||||||
{
|
{
|
||||||
var Mysql_error_update = string.Format(MYsql_update_format, targetTable);
|
var Mysql_error_update = string.Format(MYsql_update_format, targetTable);
|
||||||
var sql_error_update = string.Format(sql_update_format, targetTable);
|
var sql_error_update = string.Format(sql_update_format, targetTable);
|
||||||
await backgroundServiceMsSqlRepository.ExecuteSql(sql_error_update, electricArchiveWeekRawDatas);
|
if (!string.IsNullOrEmpty(saveToMSDB) && saveToMSDB == "1")
|
||||||
|
{
|
||||||
|
await backgroundServiceMsSqlRepository.ExecuteSql(sql_error_update, electricArchiveWeekRawDatas);
|
||||||
|
}
|
||||||
await backgroundServiceRepository.ExecuteSql(Mysql_error_update, electricArchiveWeekRawDatas);
|
await backgroundServiceRepository.ExecuteSql(Mysql_error_update, electricArchiveWeekRawDatas);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -570,7 +580,10 @@ namespace BackendWorkerService.Services.Implement
|
|||||||
{
|
{
|
||||||
var Mysql_error_update = string.Format(MYsql_update_format, targetTable);
|
var Mysql_error_update = string.Format(MYsql_update_format, targetTable);
|
||||||
var sql_error_update = string.Format(sql_update_format, targetTable);
|
var sql_error_update = string.Format(sql_update_format, targetTable);
|
||||||
await backgroundServiceMsSqlRepository.ExecuteSql(sql_error_update, waterArchiveWeekRawDatas);
|
if (!string.IsNullOrEmpty(saveToMSDB) && saveToMSDB == "1")
|
||||||
|
{
|
||||||
|
await backgroundServiceMsSqlRepository.ExecuteSql(sql_error_update, waterArchiveWeekRawDatas);
|
||||||
|
}
|
||||||
await backgroundServiceRepository.ExecuteSql(Mysql_error_update, waterArchiveWeekRawDatas);
|
await backgroundServiceRepository.ExecuteSql(Mysql_error_update, waterArchiveWeekRawDatas);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -657,7 +670,10 @@ namespace BackendWorkerService.Services.Implement
|
|||||||
{
|
{
|
||||||
var Mysql_error_update = string.Format(MYsql_update_format, targetTable);
|
var Mysql_error_update = string.Format(MYsql_update_format, targetTable);
|
||||||
var sql_error_update = string.Format(sql_update_format, targetTable);
|
var sql_error_update = string.Format(sql_update_format, targetTable);
|
||||||
await backgroundServiceMsSqlRepository.ExecuteSql(sql_error_update, electricArchiveMonthRawDatas);
|
if (!string.IsNullOrEmpty(saveToMSDB) && saveToMSDB == "1")
|
||||||
|
{
|
||||||
|
await backgroundServiceMsSqlRepository.ExecuteSql(sql_error_update, electricArchiveMonthRawDatas);
|
||||||
|
}
|
||||||
await backgroundServiceRepository.ExecuteSql(MYsql_update_format, electricArchiveMonthRawDatas);
|
await backgroundServiceRepository.ExecuteSql(MYsql_update_format, electricArchiveMonthRawDatas);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -741,7 +757,10 @@ namespace BackendWorkerService.Services.Implement
|
|||||||
{
|
{
|
||||||
var Mysql_error_update = string.Format(MYsql_update_format, targetTable);
|
var Mysql_error_update = string.Format(MYsql_update_format, targetTable);
|
||||||
var sql_error_update = string.Format(sql_update_format, targetTable);
|
var sql_error_update = string.Format(sql_update_format, targetTable);
|
||||||
await backgroundServiceMsSqlRepository.ExecuteSql(sql_error_update, waterArchiveMonthRawDatas);
|
if (!string.IsNullOrEmpty(saveToMSDB) && saveToMSDB == "1")
|
||||||
|
{
|
||||||
|
await backgroundServiceMsSqlRepository.ExecuteSql(sql_error_update, waterArchiveMonthRawDatas);
|
||||||
|
}
|
||||||
await backgroundServiceRepository.ExecuteSql(MYsql_update_format, waterArchiveMonthRawDatas);
|
await backgroundServiceRepository.ExecuteSql(MYsql_update_format, waterArchiveMonthRawDatas);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,13 +7,13 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"BackgroundServiceCron": {
|
"BackgroundServiceCron": {
|
||||||
"ExecutionBackgroundServicePlanJob": "0 0 1 * * ?",
|
"ExecutionBackgroundServicePlanJob": "0 0 2 * * ?",
|
||||||
"MessageNotificationJob": "0 0 1 * * ?",
|
"MessageNotificationJob": "0 0 2 * * ?",
|
||||||
"DataDeliveryJob": "0 0 1 * * ?",
|
"DataDeliveryJob": "0 0 2 * * ?",
|
||||||
"RegularUpdateDBTableJob": "0 0 1 * * ?",
|
"RegularUpdateDBTableJob": "0 0 2 * * ?",
|
||||||
"ParkingJob": "0 0 1 * * ?",
|
"ParkingJob": "0 0 2 * * ?",
|
||||||
"ArchiveElectricMeterHourJob": "0 0 1 * * ?",
|
"ArchiveElectricMeterHourJob": "0 0 2 * * ?",
|
||||||
"ArchiveElectricMeterDayJob": "0 0 1 * * ?",
|
"ArchiveElectricMeterDayJob": "0 0 2 * * ?",
|
||||||
"WeatherAPIJob": "0/5 * * * * ?"
|
"WeatherAPIJob": "0/5 * * * * ?"
|
||||||
},
|
},
|
||||||
"DBConfig": {
|
"DBConfig": {
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -52,22 +52,22 @@
|
|||||||
var forgeInvType = null;
|
var forgeInvType = null;
|
||||||
var forgeInvTypeDef = null;
|
var forgeInvTypeDef = null;
|
||||||
|
|
||||||
$(function () {
|
$(function () {
|
||||||
$(loadEle).Loading("start");
|
$(loadEle).Loading("start");
|
||||||
getBuildMenu((arr, data) => {
|
getBuildMenu((arr, data) => {
|
||||||
buildMenuData = data;
|
buildMenuData = data;
|
||||||
if (arr.indexOf(4) != -1) {
|
if (arr.indexOf(4) != -1) {
|
||||||
getFloDevList(arr[0] == 4 ? "left" : "right");
|
getFloDevList(arr[0] == 4 ? "left" : "right");
|
||||||
setLightColor();
|
setLightColor();
|
||||||
}
|
}
|
||||||
if (arr.indexOf(3) != -1) {
|
if (arr.indexOf(3) != -1) {
|
||||||
getHotspotPoint(() => {
|
getHotspotPoint(() => {
|
||||||
show3DModel(data.urn_3D);
|
show3DModel(data.urn_3D);
|
||||||
getInviForge();
|
getInviForge();
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// 依據 drawing type 決定呈現畫面
|
// 依據 drawing type 決定呈現畫面
|
||||||
function getHtmlByType(type = 0, data = {}) {
|
function getHtmlByType(type = 0, data = {}) {
|
||||||
@ -306,7 +306,80 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function lightDevForgeSpotLig(devObj) { }
|
// heatMap?.changeTemp(matchDevice.device_number, 0);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (data.point_name == "Temp") {
|
||||||
|
// heatMap?.changeTemp(
|
||||||
|
// data.device_number_full,
|
||||||
|
// !isNaN(parseInt(data.value)) ? parseInt(data.value) : 0
|
||||||
|
// );
|
||||||
|
// let devIdx = allDevList.findIndex(
|
||||||
|
// (x) => x.device_number == data.device_number_full
|
||||||
|
// );
|
||||||
|
// allDevList[devIdx]._temp = !isNaN(parseInt(data.value))
|
||||||
|
// ? parseInt(data.value)
|
||||||
|
// : 0;
|
||||||
|
// }
|
||||||
|
// if (
|
||||||
|
// data.point_name == norDevPoiName &&
|
||||||
|
// data.value == matchDevice.device_normal_point_value
|
||||||
|
// ) {
|
||||||
|
// //顯示正常燈號
|
||||||
|
// $(`#${matchDevice.device_number}_status`)
|
||||||
|
// .attr("data-light-type", "normal")
|
||||||
|
// .data("light-type", "normal");
|
||||||
|
// } else if (
|
||||||
|
// data.point_name == cloDevPoiName &&
|
||||||
|
// data.value == matchDevice.device_close_point_value
|
||||||
|
// ) {
|
||||||
|
// $(`#${matchDevice.device_number}_status`)
|
||||||
|
// .attr("data-light-type", "close")
|
||||||
|
// .data("light-type", "close");
|
||||||
|
// } else if (
|
||||||
|
// data.point_name == errDevPoiName &&
|
||||||
|
// data.value == matchDevice.device_error_point_value
|
||||||
|
// ) {
|
||||||
|
// $(`#${matchDevice.device_number}_status`)
|
||||||
|
// .attr("data-light-type", "error")
|
||||||
|
// .data("light-type", "error");
|
||||||
|
// }
|
||||||
|
// if (
|
||||||
|
// allDevList.length ===
|
||||||
|
// lightOnHotColorArr.length + lightOffHotColorArr.length
|
||||||
|
// ) {
|
||||||
|
// changeColorForHotspot(
|
||||||
|
// lightOnHotColorArr.map(({ spriteDbid }) => spriteDbid),
|
||||||
|
// null,
|
||||||
|
// true
|
||||||
|
// );
|
||||||
|
// changeColorForHotspot(
|
||||||
|
// lightOffHotColorArr.map(({ spriteDbid }) => spriteDbid),
|
||||||
|
// null,
|
||||||
|
// false
|
||||||
|
// );
|
||||||
|
|
||||||
|
// }
|
||||||
|
// $(loadEle).Loading("close");
|
||||||
|
|
||||||
|
// setLightColor();
|
||||||
|
// setForgeHotSpotColor(matchDevice);
|
||||||
|
// lightDevForgeSpotLig(matchDevice);
|
||||||
|
// // 從設備訂閱更新每個設備卡片即時點位
|
||||||
|
// setDevItemPoiValBySub(data);
|
||||||
|
// });
|
||||||
|
|
||||||
|
// myBaja.setSubscribeDeviceEndCallBack(function (data) {
|
||||||
|
// endPageLoading();
|
||||||
|
// if (data.findIndex((x) => x.point_name == "Temp") != -1) {
|
||||||
|
// // 顯示溫度條
|
||||||
|
// showHeat("[name=forgeHeatBar]");
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
|
function lightDevForgeSpotLig(devObj) { }
|
||||||
|
|
||||||
// 從設備訂閱更新每個設備卡片即時點位
|
// 從設備訂閱更新每個設備卡片即時點位
|
||||||
function setDevItemPoiValBySub(data) {
|
function setDevItemPoiValBySub(data) {
|
||||||
|
@ -74,6 +74,8 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
string sqlWhere = "";
|
string sqlWhere = "";
|
||||||
string sqlGroup = "";
|
string sqlGroup = "";
|
||||||
string sqlAvgRawData = "";
|
string sqlAvgRawData = "";
|
||||||
|
string dbDateName = startTime.Split("-")[0].ToString().PadLeft(4, '0') + startTime.Split("-")[1].ToString().PadLeft(2, '0');
|
||||||
|
|
||||||
if (input.floor_tag.Count > 0)
|
if (input.floor_tag.Count > 0)
|
||||||
sqlWhere = $@" and substring_index(substring_index(device_number, '_', 3), '_', -1) in @floor_tag ";
|
sqlWhere = $@" and substring_index(substring_index(device_number, '_', 3), '_', -1) in @floor_tag ";
|
||||||
|
|
||||||
@ -85,7 +87,7 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
else
|
else
|
||||||
sqlAvgRawData = " round(avg_rawdata, 2) as avg_rawdata, start_timestamp, end_timestamp ";
|
sqlAvgRawData = " round(avg_rawdata, 2) as avg_rawdata, start_timestamp, end_timestamp ";
|
||||||
|
|
||||||
var table = input.tableType == "year" ? "archive_electric_meter_day" : "archive_electric_meter_" + input.tableType;
|
var table = input.tableType == "year" ? "archive_electric_meter_month" : "archive_electric_meter_" + input.tableType + (input.tableType == "day" ? "_" + dbDateName : "");
|
||||||
var dateFormat = input.tableType == "day" || input.tableType == "week" ? "%Y-%m-%d" : input.tableType == "month" ? "%Y-%m" : input.tableType == "year" ? "%Y" : null;
|
var dateFormat = input.tableType == "day" || input.tableType == "week" ? "%Y-%m-%d" : input.tableType == "month" ? "%Y-%m" : input.tableType == "year" ? "%Y" : null;
|
||||||
var aemmEndDate = input.tableType == "year" ? $"year(DATE_ADD(fd.date, INTERVAL +1 {input.tableType}))" : $"DATE_ADD(fd.date, INTERVAL +1 {input.tableType})";
|
var aemmEndDate = input.tableType == "year" ? $"year(DATE_ADD(fd.date, INTERVAL +1 {input.tableType}))" : $"DATE_ADD(fd.date, INTERVAL +1 {input.tableType})";
|
||||||
var aemmStaDate = input.tableType == "year" ? "year(fd.date)" : "fd.date";
|
var aemmStaDate = input.tableType == "year" ? "year(fd.date)" : "fd.date";
|
||||||
@ -198,6 +200,7 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
: input.tableType == "month" ? (Int32.Parse(input.startTime.Split("-")[0]) + 1) + "-01-01"
|
: input.tableType == "month" ? (Int32.Parse(input.startTime.Split("-")[0]) + 1) + "-01-01"
|
||||||
: input.tableType == "year" ? (Int32.Parse(input.endTime) + 1).ToString() + "-01-01"
|
: input.tableType == "year" ? (Int32.Parse(input.endTime) + 1).ToString() + "-01-01"
|
||||||
: null;
|
: null;
|
||||||
|
string dbDateName = startTime.Split("-")[0].ToString().PadLeft(4, '0') + startTime.Split("-")[1].ToString().PadLeft(2, '0');
|
||||||
string sqlWhere = "";
|
string sqlWhere = "";
|
||||||
string sqlGroup = "";
|
string sqlGroup = "";
|
||||||
string sqlAvgRawData = "";
|
string sqlAvgRawData = "";
|
||||||
@ -212,7 +215,7 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
else
|
else
|
||||||
sqlAvgRawData = " round(avg_rawdata, 2) as avg_rawdata, start_timestamp, end_timestamp ";
|
sqlAvgRawData = " round(avg_rawdata, 2) as avg_rawdata, start_timestamp, end_timestamp ";
|
||||||
|
|
||||||
var table = input.tableType == "year" ? "archive_water_meter_day" : "archive_water_meter_" + input.tableType;
|
var table = input.tableType == "year" ? "archive_electric_meter_month" : "archive_electric_meter_" + input.tableType + (input.tableType == "day" ? "_" + dbDateName : "");
|
||||||
var dateFormat = input.tableType == "day" || input.tableType == "week" ? "%Y-%m-%d" : input.tableType == "month" ? "%Y-%m" : input.tableType == "year" ? "%Y" : null;
|
var dateFormat = input.tableType == "day" || input.tableType == "week" ? "%Y-%m-%d" : input.tableType == "month" ? "%Y-%m" : input.tableType == "year" ? "%Y" : null;
|
||||||
var sql = $@"set @i = -1;
|
var sql = $@"set @i = -1;
|
||||||
select fd.device_number, aemm.avg_rawdata, DATE_FORMAT(fd.date, @dateFormat) as timestamp
|
select fd.device_number, aemm.avg_rawdata, DATE_FORMAT(fd.date, @dateFormat) as timestamp
|
||||||
|
@ -1,14 +1,18 @@
|
|||||||
using FrontendWebApi.Models;
|
using FrontendWebApi.Models;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using Repository.BackendRepository.Interface;
|
using Repository.BackendRepository.Interface;
|
||||||
using Repository.FrontendRepository.Interface;
|
using Repository.FrontendRepository.Interface;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.Serialization.Formatters.Binary;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -37,8 +41,12 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
ApiResult<List<lightDevice>> apiResult = new ApiResult<List<lightDevice>>();
|
ApiResult<List<lightDevice>> apiResult = new ApiResult<List<lightDevice>>();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var floor_tag = await backendRepository.GetOneAsync<string>($@"
|
||||||
|
select full_name from floor where floor_guid = @floor_guid and deleted = 0
|
||||||
|
",new { floor_guid = post.floor_guid});
|
||||||
|
|
||||||
lightDevices = await backendRepository.GetAllAsync<lightDevice>($@"
|
lightDevices = await backendRepository.GetAllAsync<lightDevice>($@"
|
||||||
select * from device where building_guid = '{post.building_guid}' and sub_system_guid = '{post.sub_system_guid}' and floor_guid = '{post.floor_guid}' and deleted = 0 and status = 0 order by priority
|
select * from device where device_building_tag = '{post.building_tag}' and device_name_tag = '{post.sub_system_tag}' and device_floor_tag = '{floor_tag}' and deleted = 0 and status = 0 order by priority
|
||||||
");
|
");
|
||||||
|
|
||||||
if(!String.IsNullOrEmpty(post.schedule_guid))
|
if(!String.IsNullOrEmpty(post.schedule_guid))
|
||||||
@ -79,8 +87,29 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
ApiResult<string> apiResult = new ApiResult<string>();
|
ApiResult<string> apiResult = new ApiResult<string>();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if(String.IsNullOrEmpty(saveSchedule.light_schedule_guid))
|
// Operation_log 輸入參數
|
||||||
|
OperationInput opeInput = new OperationInput() { operation_type = 2 };
|
||||||
|
|
||||||
|
// 取得對應樓層資料
|
||||||
|
var targetFloor = await backendRepository.GetOneAsync<Floor>($@"
|
||||||
|
select * from floor where floor_guid = @floor_guid",
|
||||||
|
new { floor_guid = saveSchedule.floor_guid});
|
||||||
|
// 取得對應燈控排程主表資料
|
||||||
|
var targetScheduleLight = await backendRepository.GetOneAsync<SaveSchedule>($@"
|
||||||
|
select * from light_schedule where light_schedule_guid = @light_schedule_guid",
|
||||||
|
new { light_schedule_guid = saveSchedule.light_schedule_guid });
|
||||||
|
// 取得對應燈控排程設備資料
|
||||||
|
var targetScheduleDevice = await backendRepository.GetAllAsync<string>($@"
|
||||||
|
select device_guid from schedule_device where light_schedule_guid = @light_schedule_guid",
|
||||||
|
new { light_schedule_guid = saveSchedule.light_schedule_guid });
|
||||||
|
|
||||||
|
|
||||||
|
opeInput.building_tag = targetFloor.building_tag;
|
||||||
|
opeInput.floor_tag = targetFloor.full_name;
|
||||||
|
|
||||||
|
if (String.IsNullOrEmpty(saveSchedule.light_schedule_guid))
|
||||||
{
|
{
|
||||||
|
opeInput.action_name = "新增";
|
||||||
Dictionary<string, object> Schedule = new Dictionary<string, object>();
|
Dictionary<string, object> Schedule = new Dictionary<string, object>();
|
||||||
var newguid = Guid.NewGuid();
|
var newguid = Guid.NewGuid();
|
||||||
Schedule = new Dictionary<string, object>()
|
Schedule = new Dictionary<string, object>()
|
||||||
@ -95,6 +124,7 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
{ "@end_time", saveSchedule.end_time},
|
{ "@end_time", saveSchedule.end_time},
|
||||||
{ "@created_by", myUser.userinfo_guid}
|
{ "@created_by", myUser.userinfo_guid}
|
||||||
};
|
};
|
||||||
|
|
||||||
await backendRepository.AddOneByCustomTable(Schedule, "light_schedule");
|
await backendRepository.AddOneByCustomTable(Schedule, "light_schedule");
|
||||||
List<Dictionary<string, object>> ScheduleDevices = new List<Dictionary<string, object>>();
|
List<Dictionary<string, object>> ScheduleDevices = new List<Dictionary<string, object>>();
|
||||||
foreach (var a in saveSchedule.devicelist)
|
foreach (var a in saveSchedule.devicelist)
|
||||||
@ -107,10 +137,14 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
};
|
};
|
||||||
ScheduleDevices.Add(ScheduleDevice);
|
ScheduleDevices.Add(ScheduleDevice);
|
||||||
}
|
}
|
||||||
|
opeInput.parameter = JsonConvert.SerializeObject(saveSchedule);
|
||||||
|
|
||||||
await backendRepository.AddMutiByCustomTable(ScheduleDevices, "schedule_device");
|
await backendRepository.AddMutiByCustomTable(ScheduleDevices, "schedule_device");
|
||||||
|
await InsertOperation(opeInput);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
opeInput.action_name = "修改";
|
||||||
Dictionary<string, object> Schedule = new Dictionary<string, object>();
|
Dictionary<string, object> Schedule = new Dictionary<string, object>();
|
||||||
Schedule = new Dictionary<string, object>()
|
Schedule = new Dictionary<string, object>()
|
||||||
{
|
{
|
||||||
@ -124,6 +158,37 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
{ "@updated_by", myUser.userinfo_guid},
|
{ "@updated_by", myUser.userinfo_guid},
|
||||||
{ "@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}
|
{ "@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 比較欄位
|
||||||
|
List<string> compareTargetProps = new List<string>() { "full_name", "week", "cycle", "floor_guid", "start_time", "end_time" };
|
||||||
|
List<string> compareTargetValues = new List<string>();
|
||||||
|
|
||||||
|
Type modelType = saveSchedule.GetType();
|
||||||
|
// 根據每個欄位比較
|
||||||
|
foreach(var prop in compareTargetProps){
|
||||||
|
PropertyInfo propertyInfo = modelType.GetProperty(prop);
|
||||||
|
if (propertyInfo == null) continue;
|
||||||
|
// 比較 saveSchedule 與 targetSchedule
|
||||||
|
var value = propertyInfo.GetValue(saveSchedule,null)?.ToString();
|
||||||
|
var newValue = propertyInfo.GetValue(targetScheduleLight, null)?.ToString();
|
||||||
|
// 只要不對就是排程變更
|
||||||
|
if (value != newValue) {
|
||||||
|
saveSchedule.changeNames.Add("排程變更");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 判斷是否為狀態變更
|
||||||
|
if (targetScheduleLight.status != saveSchedule.status) {
|
||||||
|
saveSchedule.changeNames.Add("狀態變更");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 兩邊設備 guid 排序後比較
|
||||||
|
saveSchedule.devicelist.Sort();
|
||||||
|
targetScheduleDevice.Sort();
|
||||||
|
if (saveSchedule.devicelist != targetScheduleDevice) {
|
||||||
|
saveSchedule.changeNames.Add("設備變更");
|
||||||
|
}
|
||||||
|
|
||||||
await backendRepository.UpdateOneByCustomTable(Schedule, "light_schedule", $" light_schedule_guid = '{saveSchedule.light_schedule_guid}'");
|
await backendRepository.UpdateOneByCustomTable(Schedule, "light_schedule", $" light_schedule_guid = '{saveSchedule.light_schedule_guid}'");
|
||||||
await backendRepository.PurgeOneByGuidWithCustomDBNameAndTable("schedule_device", $" light_schedule_guid = '{saveSchedule.light_schedule_guid}'");
|
await backendRepository.PurgeOneByGuidWithCustomDBNameAndTable("schedule_device", $" light_schedule_guid = '{saveSchedule.light_schedule_guid}'");
|
||||||
List<Dictionary<string, object>> ScheduleDevices = new List<Dictionary<string, object>>();
|
List<Dictionary<string, object>> ScheduleDevices = new List<Dictionary<string, object>>();
|
||||||
@ -138,6 +203,12 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
ScheduleDevices.Add(ScheduleDevice);
|
ScheduleDevices.Add(ScheduleDevice);
|
||||||
}
|
}
|
||||||
await backendRepository.AddMutiByCustomTable(ScheduleDevices, "schedule_device");
|
await backendRepository.AddMutiByCustomTable(ScheduleDevices, "schedule_device");
|
||||||
|
|
||||||
|
opeInput.parameter = JsonConvert.SerializeObject(saveSchedule);
|
||||||
|
// 若有變更才寫入 operation_log
|
||||||
|
if (saveSchedule.changeNames.Count > 0) {
|
||||||
|
await InsertOperation(opeInput);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
apiResult.Code = "0000";
|
apiResult.Code = "0000";
|
||||||
apiResult.Data = "成功";
|
apiResult.Data = "成功";
|
||||||
@ -292,5 +363,33 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
}
|
}
|
||||||
return Ok(apiResult);
|
return Ok(apiResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<bool> InsertOperation(OperationInput input)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//記錄使用者操作紀錄
|
||||||
|
Dictionary<string, object> userOperatorLog = new Dictionary<string, object>()
|
||||||
|
{
|
||||||
|
{ "@user_guid", myUser.userinfo_guid },
|
||||||
|
{ "@operation_type", input.operation_type }, //1:名稱修改
|
||||||
|
{ "@building_tag", input.building_tag },
|
||||||
|
{ "@main_system_tag", input.main_system_tag },
|
||||||
|
{ "@sub_system_tag", input.sub_system_tag },
|
||||||
|
{ "@floor_tag", input.floor_tag },
|
||||||
|
{ "@device_guid", input.device_guid },
|
||||||
|
{ "@action_name", input.action_name },
|
||||||
|
{ "@parameter", JsonConvert.SerializeObject(input.parameter) },
|
||||||
|
};
|
||||||
|
|
||||||
|
await backendRepository.AddOneByCustomTable(userOperatorLog, "operation_log");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,5 +155,7 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
|
|
||||||
return apiResult;
|
return apiResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,8 @@ namespace FrontendWebApi.Models
|
|||||||
{
|
{
|
||||||
public class GetDevicePost
|
public class GetDevicePost
|
||||||
{
|
{
|
||||||
public string building_guid { get; set; }
|
public string building_tag { get; set; }
|
||||||
public string sub_system_guid { get; set; }
|
public string sub_system_tag { get; set; }
|
||||||
public string floor_guid { get; set; }
|
public string floor_guid { get; set; }
|
||||||
public string schedule_guid { get; set; }
|
public string schedule_guid { get; set; }
|
||||||
}
|
}
|
||||||
@ -33,6 +33,7 @@ namespace FrontendWebApi.Models
|
|||||||
public class SaveSchedule : Schedule
|
public class SaveSchedule : Schedule
|
||||||
{
|
{
|
||||||
public List<string> devicelist { get; set; }
|
public List<string> devicelist { get; set; }
|
||||||
|
public List<string> changeNames { get; set; } = new List<string>();
|
||||||
}
|
}
|
||||||
public class ScheduleTable : Schedule
|
public class ScheduleTable : Schedule
|
||||||
{
|
{
|
||||||
@ -44,7 +45,13 @@ namespace FrontendWebApi.Models
|
|||||||
public List<string> Floors { get; set; }
|
public List<string> Floors { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class ScheduleDevice
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string light_schedule_guid { get; set; }
|
||||||
|
public string device_guid { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ namespace FrontendWebApi.Models
|
|||||||
public string notice { get; set; }
|
public string notice { get; set; }
|
||||||
public string description { get; set; }
|
public string description { get; set; }
|
||||||
public string work_type_name
|
public string work_type_name
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
Dictionary<byte, string> name = new Dictionary<byte, string>()
|
Dictionary<byte, string> name = new Dictionary<byte, string>()
|
||||||
@ -118,7 +118,7 @@ namespace FrontendWebApi.Models
|
|||||||
}
|
}
|
||||||
|
|
||||||
public class Operation_Record_File : Actor
|
public class Operation_Record_File : Actor
|
||||||
{
|
{
|
||||||
public int id { get; set; }
|
public int id { get; set; }
|
||||||
public byte deleted { get; set; }
|
public byte deleted { get; set; }
|
||||||
public int record_id { get; set; }
|
public int record_id { get; set; }
|
||||||
@ -138,4 +138,23 @@ namespace FrontendWebApi.Models
|
|||||||
public DateTime? startdate { get; set; }
|
public DateTime? startdate { get; set; }
|
||||||
public DateTime? enddate { get; set; }
|
public DateTime? enddate { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class OperationInput
|
||||||
|
{
|
||||||
|
public int id { get; set; }
|
||||||
|
public string user_guid { get; set;}
|
||||||
|
public string building_tag { get; set; }
|
||||||
|
public string main_system_tag { get; set;}
|
||||||
|
public string sub_system_tag { get; set;}
|
||||||
|
public string floor_tag { get; set;}
|
||||||
|
public string device_guid { get; set;}
|
||||||
|
public short operation_type { get; set;}
|
||||||
|
public string parameter { get; set;}
|
||||||
|
public string action_name { get; set;}
|
||||||
|
public string value { get; set;}
|
||||||
|
public DateTime? created_at { get; set;}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -589,7 +589,7 @@ namespace Repository.BackendRepository.Implement
|
|||||||
select device_building_tag, device_system_tag, device_name_tag
|
select device_building_tag, device_system_tag, device_name_tag
|
||||||
from import_niagara_tag
|
from import_niagara_tag
|
||||||
group by device_building_tag, device_system_tag, device_name_tag
|
group by device_building_tag, device_system_tag, device_name_tag
|
||||||
) AS a ON b.device_building_tag = a.building_tag
|
) AS a ON b.building_tag = a.device_building_tag
|
||||||
and a.device_system_tag = b.main_system_tag and a.device_name_tag = b.sub_system_tag
|
and a.device_system_tag = b.main_system_tag and a.device_name_tag = b.sub_system_tag
|
||||||
SET b.is_link = 0
|
SET b.is_link = 0
|
||||||
WHERE b.building_tag IS NULL");
|
WHERE b.building_tag IS NULL");
|
||||||
|
Loading…
Reference in New Issue
Block a user