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;