From d04ce71a37ee4ce3d1e52efa5a75255550779786 Mon Sep 17 00:00:00 2001 From: b110212000 Date: Tue, 10 Aug 2021 10:03:37 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=A0=B1=E8=A1=A8?= =?UTF-8?q?=E9=8C=AF=E8=AA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/StationReportController.cs | 21 +++++++++++++++---- SolarPower/Models/ErrorCode.cs | 1 + SolarPower/Views/StationReport/Index.cshtml | 10 ++++++--- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/SolarPower/Controllers/StationReportController.cs b/SolarPower/Controllers/StationReportController.cs index 3febd9a..42716e6 100644 --- a/SolarPower/Controllers/StationReportController.cs +++ b/SolarPower/Controllers/StationReportController.cs @@ -133,9 +133,21 @@ namespace SolarPower.Controllers ApiResult apiResult = new ApiResult(); try { - var a = await stationReportRepository.Gettablebody(post); - apiResult.Code = "0000"; - apiResult.Data = a; + + var checkinv = stationReportRepository.Findhaveinv(post); + var getinvsql = checkinv.Result[0] as IDictionary; + if (getinvsql["mySelect"] == null) + { + apiResult.Code = "9985"; + apiResult.Msg = errorCode.GetString(apiResult.Code); + } + else + { + var a = await stationReportRepository.Gettablebody(post); + apiResult.Code = "0000"; + apiResult.Data = a; + } + } catch (Exception exception) { @@ -741,7 +753,8 @@ namespace SolarPower.Controllers Userid = postObject.Userid }; var k = stationReportRepository.Findhaveinv(select_Table); - if(k.Result[0].values == null) + var getinvsql = k.Result[0] as IDictionary; + if (getinvsql["mySelect"] == null) { return ""; } diff --git a/SolarPower/Models/ErrorCode.cs b/SolarPower/Models/ErrorCode.cs index d88f4d7..bb221c5 100644 --- a/SolarPower/Models/ErrorCode.cs +++ b/SolarPower/Models/ErrorCode.cs @@ -20,6 +20,7 @@ namespace SolarPower.Models { "0002","請先刪除相關逆變器"}, { "0003","請先刪除相關設備"}, { "0004","請先移除相關逆變器綁定"}, + { "9985","該電站尚無逆變器資料"}, { "9986", "該帳號已被註冊,請重新輸入"}, { "9987", "查無該運維作業記錄檔案"}, { "9988", "查無該資料紀錄"}, diff --git a/SolarPower/Views/StationReport/Index.cshtml b/SolarPower/Views/StationReport/Index.cshtml index 1dc76a4..a8b8f94 100644 --- a/SolarPower/Views/StationReport/Index.cshtml +++ b/SolarPower/Views/StationReport/Index.cshtml @@ -742,14 +742,19 @@ var url = "/StationReport/GetForm"; $.post(url, send_data, function (rel) { if (rel.code != "0000") { - toast_error(rel.msg); + if (rel.code == "9985") { + toast_warning(rel.msg); + } else { + toast_error(rel.msg); + } + $('#TableBody').empty(); + $('#totbody').empty(); return; } var sta = ""; $('#TableBody').empty(); $('#totbody').empty(); $('#tothead').empty(); - if (form == 0) {//日報表 var thour = 0; var tpr = 0; @@ -934,7 +939,6 @@ haveinvertName = []; } $('.overflow-auto').show(); - nowform = form; }, 'json'); } From 2808c039e6882fc5aadb569853f8d6312fa5fa1e Mon Sep 17 00:00:00 2001 From: b110212000 Date: Tue, 10 Aug 2021 16:26:32 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E7=99=BC=E9=80=81=E5=A0=B1=E5=91=8A(?= =?UTF-8?q?=E5=AE=8C=E6=88=90)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/NoticeScheduleController.cs | 69 ++ SolarPower/DBSchema/solar_power_schema.sql | 5 + SolarPower/Models/NoticeSchedule.cs | 28 + .../Quartz/Jobs/CalcAvgPowerStationJob.cs | 20 +- .../Implement/NoticeScheduleRepository.cs | 66 ++ .../Implement/OperationRepository.cs | 4 +- .../Interface/INoticeScheduleRepository.cs | 1 + SolarPower/Views/NoticeSchedule/Index.cshtml | 658 ++++++++++++++++++ SolarPower/Views/Shared/_Layout.cshtml | 4 +- SolarPower/Views/StationReport/Index.cshtml | 1 - 10 files changed, 849 insertions(+), 7 deletions(-) create mode 100644 SolarPower/Controllers/NoticeScheduleController.cs create mode 100644 SolarPower/Views/NoticeSchedule/Index.cshtml diff --git a/SolarPower/Controllers/NoticeScheduleController.cs b/SolarPower/Controllers/NoticeScheduleController.cs new file mode 100644 index 0000000..b5bee75 --- /dev/null +++ b/SolarPower/Controllers/NoticeScheduleController.cs @@ -0,0 +1,69 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; +using SolarPower.Models; +using SolarPower.Repository.Interface; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace SolarPower.Controllers +{ + public class NoticeScheduleController : MyBaseController + { + private readonly INoticeScheduleRepository noticeScheduleRepository; + + public NoticeScheduleController(INoticeScheduleRepository noticeScheduleRepository) : base() + { + this.noticeScheduleRepository = noticeScheduleRepository; + } + + public IActionResult Index() + { + return View(); + } + + [HttpPost] + public async Task NoticeTable(NoticeTableSearch info) + { + List NoticeScheduleTable = new List(); + ApiResult> apiResult = new ApiResult>(); + try + { + NoticeScheduleTable = await noticeScheduleRepository.GetNoticeTable(info); + foreach(NoticeScheduleTable a in NoticeScheduleTable) + { + a.EmailTypeName = a.EmailType switch + { + 0 => "日報表", + 1 => "月報表", + 2 => "綜合報表", + 3 => "運維", + _ => "" + }; + a.IsDeliveryName = a.IsDelivery switch + { + 1 => "成功", + 2 => "失敗", + _ => "" + }; + } + apiResult.Code = "0000"; + apiResult.Data = NoticeScheduleTable; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = exception.ToString(); + + Logger.LogError("【" + controllerName + "/" + actionName + "】" + "info=" + System.Text.Json.JsonSerializer.Serialize(info)); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + var result = Json(new + { + data = apiResult + }); + return result; + } + } +} diff --git a/SolarPower/DBSchema/solar_power_schema.sql b/SolarPower/DBSchema/solar_power_schema.sql index e9d2291..d69b3d7 100644 --- a/SolarPower/DBSchema/solar_power_schema.sql +++ b/SolarPower/DBSchema/solar_power_schema.sql @@ -2108,6 +2108,11 @@ COMMENT='台電售電紀錄' COLLATE='utf8mb4_unicode_ci' ; +-- 新增定時發送通知排程表-欄位 20210810 +ALTER TABLE `notice_schedule` + ADD COLUMN `UserId` TINYINT(1) UNSIGNED NOT NULL COMMENT '帳號Id' AFTER `Type`, + ADD COLUMN `EmailType` TINYINT(1) UNSIGNED NULL DEFAULT NULL COMMENT '發送種類' AFTER `UserId`; + /*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */; /*!40014 SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1) */; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; diff --git a/SolarPower/Models/NoticeSchedule.cs b/SolarPower/Models/NoticeSchedule.cs index e121f95..a0c0d62 100644 --- a/SolarPower/Models/NoticeSchedule.cs +++ b/SolarPower/Models/NoticeSchedule.cs @@ -17,6 +17,8 @@ namespace SolarPower.Models public byte IsDelivery { get; set; } public string DeliveryAt { get; set; } public string Reason { get; set; } + public int UserId { get; set; } + public int EmailType { get; set; } } public class OperationPersonnel @@ -28,4 +30,30 @@ namespace SolarPower.Models public int EmailException { get; set; } public string Name { get; set; } } + public class NoticeScheduleTable + { + public int Id { get; set; } + public string RecipientName { get; set; } + public int UserId { get; set; } + public int EmailType { get; set; } + public string Subject { get; set; } + public byte IsDelivery { get; set; } + + private string deliveryAt; + public string DeliveryAt { get { return Convert.ToDateTime(deliveryAt).ToString("yyyy-MM-dd HH:mm:ss"); } set { deliveryAt = value; } } + + private string createdAt; + public string CreatedAt { get { return Convert.ToDateTime(createdAt).ToString("yyyy-MM-dd HH:mm:ss"); } set { createdAt = value; } } + public string IsDeliveryName { get; set; } + public string EmailTypeName { get; set; } + } + public class NoticeTableSearch + { + public int TimeType { get; set; } + public string TimeRange { get; set; } + public int FormType { get; set; } + public int CheckType { get; set; } + public List PowerstationIds { get; set; } + } + } diff --git a/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs b/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs index 12a3085..e11bfc4 100644 --- a/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs +++ b/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs @@ -67,6 +67,8 @@ namespace SolarPower.Quartz.Jobs { NoticeSchedule DaySchedule = new NoticeSchedule() { + UserId = user.Id, + EmailType = 0, RecipientEmail = user.Email, Subject = "日報表", Attachment = stationReportName, @@ -75,6 +77,8 @@ namespace SolarPower.Quartz.Jobs }; List properties = new List() { + "UserId", + "EmailType", "RecipientEmail", "Subject", "Attachment", @@ -98,6 +102,8 @@ namespace SolarPower.Quartz.Jobs var stationMaxReportName = stationReportController.ExportExcelmaxtableBackDownload(JsonConvert.SerializeObject(maxdayexcel, Formatting.Indented)); NoticeSchedule MaxSchedule = new NoticeSchedule() { + UserId = user.Id, + EmailType = 2, RecipientEmail = user.Email, Subject = "綜合報表", Attachment = stationMaxReportName, @@ -106,6 +112,8 @@ namespace SolarPower.Quartz.Jobs }; List properties = new List() { + "UserId", + "EmailType", "RecipientEmail", "Subject", "Attachment", @@ -131,10 +139,14 @@ namespace SolarPower.Quartz.Jobs Subject = "綜合報表", Attachment = stationReportmaxmonthName, RecipientName = user.Name, - Type = 1 + Type = 1, + UserId = user.Id, + EmailType = 2 }; List properties2 = new List() { + "UserId", + "EmailType", "RecipientEmail", "Subject", "Attachment", @@ -170,10 +182,14 @@ namespace SolarPower.Quartz.Jobs Subject = "月報表", Attachment = stationReportmonthName, RecipientName = user.Name, - Type = 1 + Type = 1, + UserId = user.Id, + EmailType = 1 }; List properties2 = new List() { + "UserId", + "EmailType", "RecipientEmail", "Subject", "Attachment", diff --git a/SolarPower/Repository/Implement/NoticeScheduleRepository.cs b/SolarPower/Repository/Implement/NoticeScheduleRepository.cs index 8ad9451..00eeabb 100644 --- a/SolarPower/Repository/Implement/NoticeScheduleRepository.cs +++ b/SolarPower/Repository/Implement/NoticeScheduleRepository.cs @@ -94,5 +94,71 @@ namespace SolarPower.Repository.Implement } } } + + public async Task> GetNoticeTable(NoticeTableSearch info) + { + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + conn.Open(); + var result = new List(); + using (var trans = conn.BeginTransaction()) + { + var EmailType = info.FormType switch + { + 99 => $"", + _ => $"AND ns.EmailType = {info.FormType}" + }; + var IsDelivery = info.CheckType switch + { + 0 => $"AND ns.IsDelivery != 0", + 1 => $"AND ns.IsDelivery = 1", + 2 => $"AND ns.IsDelivery = 2", + _ => $"", + }; + string time=""; + switch(info.TimeType) + { + case 0: + time = $"AND DATE_FORMAT(ns.DeliveryAt,'%Y-%m-%d') = '{info.TimeRange}'"; + break; + case 1: + var timechange = info.TimeRange.Replace(" ", "").Split("-"); + time = $"AND DATE_FORMAT(ns.DeliveryAt,'%Y/%m/%d') between '{timechange[0]}' and '{timechange[1]}'"; + break; + case 2: + time = $"AND DATE_FORMAT(ns.DeliveryAt,'%Y-%m') = '{info.TimeRange}'"; + break; + case 3: + time = $"AND DATE_FORMAT(ns.DeliveryAt,'%Y') = '{info.TimeRange}'"; + break; + } + + try + { + var sql = $@"SELECT psp.PowerStationId,ns.`*` + FROM power_station_operation_personnel psp + LEFT JOIN notice_schedule ns + ON ns.UserId = psp.UserId + WHERE psp.PowerStationId IN @ids + AND psp.Deleted = 0 + {EmailType} {IsDelivery} {time} + GROUP BY ns.Id ORDER BY ns.DeliveryAt desc"; + + result = (await conn.QueryAsync(sql,new { ids = info.PowerstationIds})).ToList(); + + } + catch (Exception exception) + { + trans.Rollback(); + throw exception; + } + finally + { + conn.Close(); + } + return result; + } + } + } } } diff --git a/SolarPower/Repository/Implement/OperationRepository.cs b/SolarPower/Repository/Implement/OperationRepository.cs index 907506f..2addb81 100644 --- a/SolarPower/Repository/Implement/OperationRepository.cs +++ b/SolarPower/Repository/Implement/OperationRepository.cs @@ -573,11 +573,11 @@ namespace SolarPower.Repository.Implement List value = new List() ; foreach (MyUser a in personal) { - value.Add($@"(1,'{a.Name}','{a.Email}','{Title}','{content}')"); + value.Add($@"(1,'{a.Name}','{a.Email}','{Title}','{content}',{a.Id},3)"); } string values = string.Join(",", value.ToArray()); - var sql = $"INSERT INTO `notice_schedule` (`Type`, `RecipientName`, `RecipientEmail`, `Subject`, `Content`) VALUES {values};"; + var sql = $"INSERT INTO `notice_schedule` (`Type`, `RecipientName`, `RecipientEmail`, `Subject`, `Content`,`UserId`,`EmailType`) VALUES {values};"; await conn.ExecuteAsync(sql,trans); diff --git a/SolarPower/Repository/Interface/INoticeScheduleRepository.cs b/SolarPower/Repository/Interface/INoticeScheduleRepository.cs index 5e60cee..0b4431e 100644 --- a/SolarPower/Repository/Interface/INoticeScheduleRepository.cs +++ b/SolarPower/Repository/Interface/INoticeScheduleRepository.cs @@ -11,5 +11,6 @@ namespace SolarPower.Repository.Interface Task> GetNotYetDelivery(); Task UpdateList(List noticeSchedules, List properties); Task> GetPowerStationOperationPersonnel(int Userid); + Task> GetNoticeTable(NoticeTableSearch info); } } diff --git a/SolarPower/Views/NoticeSchedule/Index.cshtml b/SolarPower/Views/NoticeSchedule/Index.cshtml new file mode 100644 index 0000000..f302c7b --- /dev/null +++ b/SolarPower/Views/NoticeSchedule/Index.cshtml @@ -0,0 +1,658 @@ +@{ + ViewData["MainNum"] = "4"; + ViewData["SubNum"] = "4"; + ViewData["Title"] = "報告發送記錄"; +} +@using SolarPower.Models.Role +@model RoleLayerEnum + +
+
+ + + +
+
+

+ @ViewData["Title"] +

+
+
+
+
+
+
+
+
+
+ + + + +
+
+
+ + +
+
+
+ +
+
+ +
+
+
+ +
+
+
+
+
+ + + + + +
+
+
+
+ + + +
+
+
+
+ +
+
+
+
+
+
+
+ + + + + + + + + + + + + +
編號任務建立時間發送對象發送內容發送狀態發送時間
+
+
+
+
+
+
+ +@section Scripts{ + +} \ No newline at end of file diff --git a/SolarPower/Views/Shared/_Layout.cshtml b/SolarPower/Views/Shared/_Layout.cshtml index b787054..23fd37c 100644 --- a/SolarPower/Views/Shared/_Layout.cshtml +++ b/SolarPower/Views/Shared/_Layout.cshtml @@ -276,8 +276,8 @@ 電廠發電效能統計 -
  • - +
  • + 報告發送記錄
  • diff --git a/SolarPower/Views/StationReport/Index.cshtml b/SolarPower/Views/StationReport/Index.cshtml index a8b8f94..c0faca1 100644 --- a/SolarPower/Views/StationReport/Index.cshtml +++ b/SolarPower/Views/StationReport/Index.cshtml @@ -1084,7 +1084,6 @@ }) } - function hire(db, id) { var hirerate = 0; From e81b7e2a2eabcfb718e9e13e46fa439de7ce3c89 Mon Sep 17 00:00:00 2001 From: b110212000 Date: Tue, 10 Aug 2021 16:45:54 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=97=A5=E6=9C=88?= =?UTF-8?q?=E5=A0=B1=E5=95=8F=E9=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SolarPower/Controllers/StationReportController.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/SolarPower/Controllers/StationReportController.cs b/SolarPower/Controllers/StationReportController.cs index 42716e6..345fbe5 100644 --- a/SolarPower/Controllers/StationReportController.cs +++ b/SolarPower/Controllers/StationReportController.cs @@ -743,7 +743,6 @@ namespace SolarPower.Controllers #endregion foreach (var powerstationid in postObject.PowerStation) { - var sheet = workbook.CreateSheet(powerstationid.Name); Select_table select_Table = new Select_table { FormType = postObject.FormType, @@ -756,8 +755,16 @@ namespace SolarPower.Controllers var getinvsql = k.Result[0] as IDictionary; if (getinvsql["mySelect"] == null) { - return ""; + if(postObject.PowerStation.Count > 1) + { + continue; + } + else + { + return ""; + } } + var sheet = workbook.CreateSheet(powerstationid.Name); var Formbody = GetForm(select_Table);//取body var Formhead = GetTableHead(select_Table);//取head int RowPosition = 0;