diff --git a/SolarPower/Models/Operation.cs b/SolarPower/Models/Operation.cs index 47ef2c1..fcbb6c9 100644 --- a/SolarPower/Models/Operation.cs +++ b/SolarPower/Models/Operation.cs @@ -121,6 +121,7 @@ namespace SolarPower.Models public int WorkType { get; set; } public string StartTime { get; set; } public string EndTime { get; set; } + public string Notice { get; set; } } public class OperationRecord : UserInfo diff --git a/SolarPower/Models/Overview.cs b/SolarPower/Models/Overview.cs index c066e52..7e12750 100644 --- a/SolarPower/Models/Overview.cs +++ b/SolarPower/Models/Overview.cs @@ -185,6 +185,7 @@ namespace SolarPower.Models public double Temp { get; set; } public double DiffSOLARHOUR { get; set; } public string TOTALTIME { get; set; } + public double KWHKWP { get; set; } } public class ExceptionEmailInfo diff --git a/SolarPower/Quartz/Jobs/ExceptionSchedule.cs b/SolarPower/Quartz/Jobs/ExceptionSchedule.cs index 0468504..80f7107 100644 --- a/SolarPower/Quartz/Jobs/ExceptionSchedule.cs +++ b/SolarPower/Quartz/Jobs/ExceptionSchedule.cs @@ -1,10 +1,13 @@ using Microsoft.Extensions.Logging; +using Newtonsoft.Json.Linq; using Quartz; using SolarPower.Models; using SolarPower.Repository.Interface; using System; using System.Collections.Generic; +using System.IO; using System.Linq; +using System.Net; using System.Threading; using System.Threading.Tasks; @@ -17,13 +20,15 @@ namespace SolarPower.Quartz.Jobs private readonly IOverviewRepository overviewRepository; private readonly INoticeScheduleRepository noticeScheduleRepository; private readonly IUserRepository userRepository; + private readonly IPowerStationRepository powerStationRepository; - public ExceptionSchedule(ILogger logger, IOverviewRepository overviewRepository,INoticeScheduleRepository noticeScheduleRepository,IUserRepository userRepository) + public ExceptionSchedule(ILogger logger, IOverviewRepository overviewRepository,INoticeScheduleRepository noticeScheduleRepository,IUserRepository userRepository,IPowerStationRepository powerStationRepository) { this.logger = logger; this.overviewRepository = overviewRepository; this.noticeScheduleRepository = noticeScheduleRepository; this.userRepository = userRepository; + this.powerStationRepository = powerStationRepository; } public async Task Execute(IJobExecutionContext context) @@ -71,6 +76,12 @@ namespace SolarPower.Quartz.Jobs "ExceptionId" }; await noticeScheduleRepository.AddOneAsync(DaySchedule, properties); + + var powerstation = await powerStationRepository.GetOneAsync(Exception.PowerStationId); + if(powerstation.line_token != null) + { + CallLineToken(Content, powerstation.line_token); + } } } } @@ -80,5 +91,33 @@ namespace SolarPower.Quartz.Jobs logger.LogError("【{0}】{1}", nameof(logger), exception.Message); } } + + public string CallLineToken(string message, string LineToken) + { + try + { + HttpWebRequest Postrequest = (HttpWebRequest)WebRequest.Create("https://notify-api.line.me/api/notify?message=" + message); + Postrequest.Method = "POST"; + Postrequest.Headers.Add("Authorization", "Bearer " + LineToken); + Postrequest.PreAuthenticate = true; + HttpWebResponse response = (HttpWebResponse)Postrequest.GetResponse(); + var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd(); + var final = JObject.Parse(responseString); + var get = final["status"].ToString(); + if (get != "200") + { + logger.LogError("CallLineToken發送Line接收失敗"); + //Logger.LogError("【" + controllerName + "/" + actionName + "】" + "CallLineToken發送Line接收失敗"); + } + return get; + } + catch (Exception ex) + { + logger.LogError("【{0}】CallLineToken: {1}", nameof(logger), ex.Message); + //Logger.LogError("【" + controllerName + "/" + actionName + "】" + "CallLineToken:" + ex); + throw ex; + } + } + } } \ No newline at end of file diff --git a/SolarPower/Quartz/Jobs/OperationScheduleJob.cs b/SolarPower/Quartz/Jobs/OperationScheduleJob.cs index b0c8935..c527148 100644 --- a/SolarPower/Quartz/Jobs/OperationScheduleJob.cs +++ b/SolarPower/Quartz/Jobs/OperationScheduleJob.cs @@ -105,7 +105,8 @@ namespace SolarPower.Quartz.Jobs PowerStationId = a.PowerStationId, StartTime = a.StartTime, CreatedBy = a.CreatedBy, - EndTime = endtime + EndTime = endtime, + Notice = a.Description }; List properties2 = new List() { @@ -113,7 +114,8 @@ namespace SolarPower.Quartz.Jobs "PowerStationId", "StartTime", "CreatedBy", - "EndTime" + "EndTime", + "Notice" }; await operationRepository.AddToRecord(record, properties2); diff --git a/SolarPower/Repository/Implement/OverviewRepository.cs b/SolarPower/Repository/Implement/OverviewRepository.cs index 9ddb72e..d239653 100644 --- a/SolarPower/Repository/Implement/OverviewRepository.cs +++ b/SolarPower/Repository/Implement/OverviewRepository.cs @@ -634,7 +634,7 @@ namespace SolarPower.Repository.Implement ( SELECT DENSE_RANK() OVER(ORDER BY C.TIMESTAMP) AS ROWID , (DENSE_RANK() OVER(ORDER BY C.TIMESTAMP)) - 1 AS PreROWID, - C.TIMESTAMP,{kwh} AS KWH,C.SOLARHOUR,C.PR,P.Irradiance,P.Temperature AS Temp + C.TIMESTAMP,{kwh} AS KWH,C.SOLARHOUR,C.PR,P.Irradiance,P.Temperature AS Temp ,C.KWHKWP FROM {usedb} C LEFT JOIN {pyrdb} P ON DATE_FORMAT(P.TIMESTAMP,'{timeGroup}') = DATE_FORMAT(C.TIMESTAMP,'{timeGroup}') AND P.PowerStationId = C.PowerStationId WHERE C.PowerStationId = {post.PowerstationId}{range2} GROUP BY C.TIMESTAMP ORDER BY C.TIMESTAMP diff --git a/SolarPower/Views/Operation/OperationRecord.cshtml b/SolarPower/Views/Operation/OperationRecord.cshtml index 14c4f70..bde456f 100644 --- a/SolarPower/Views/Operation/OperationRecord.cshtml +++ b/SolarPower/Views/Operation/OperationRecord.cshtml @@ -214,7 +214,7 @@
- +
@@ -684,6 +684,10 @@ $("#record-form").trigger("reset"); $("input[name=status_modal][value='" + 0 + "']").prop('checked', true); //狀態 $("#record_files_div > .row").empty(); + + + + $("#record-form-modal").modal(); } @@ -1011,6 +1015,9 @@ CreateRecordFileBox(RecordFileBox, value, true); }); + + + $("#record-form-modal").modal(); }, 'json'); });