diff --git a/SolarPower/Controllers/StationOverviewController.cs b/SolarPower/Controllers/StationOverviewController.cs index 252a5ed..bc5d830 100644 --- a/SolarPower/Controllers/StationOverviewController.cs +++ b/SolarPower/Controllers/StationOverviewController.cs @@ -385,6 +385,10 @@ namespace SolarPower.Controllers { a.Function = @$"{a.FormId}"; } + if (a.NormalTime == "1970-01-01 08:00:00") + { + a.NormalTime = ""; + } } apiResult.Code = "0000"; @@ -430,6 +434,10 @@ namespace SolarPower.Controllers { a.Function = @$"{a.FormId}"; } + if(a.NormalTime == "1970-01-01 08:00:00") + { + a.NormalTime = ""; + } } apiResult.Code = "0000"; diff --git a/SolarPower/Controllers/StationReportController.cs b/SolarPower/Controllers/StationReportController.cs index 266f096..e49d663 100644 --- a/SolarPower/Controllers/StationReportController.cs +++ b/SolarPower/Controllers/StationReportController.cs @@ -75,10 +75,10 @@ namespace SolarPower.Controllers return apiResult; } - public async Task>> GetTableHead(Select_table post) + public async Task> GetTableHead(Select_table post) { - ApiResult> apiResult = new ApiResult>(); - List inverter = new List(); + ApiResult apiResult = new ApiResult(); + InvAndMoney inverter = new InvAndMoney(); try { var powerStation = await powerStationRepository.GetOneAsync(post.PowerStation); @@ -88,10 +88,17 @@ namespace SolarPower.Controllers apiResult.Msg = "需加入查詢電站"; return apiResult; } - inverter = await stationReportRepository.GetInverterId(powerStation.SiteDB,post); - for (int i = 0;i lasthead = new List() { "小時發電量(kWh)", "小時發電量百分比(%)", "小時平均日照度(W/㎡)", - "小時平均模組溫度(°C)", - "小時售電金額(NTD)", + "小時平均模組溫度(°C)" }; + if(Formhead.Result.Data.ShowMoney == 1) + { + lasthead.Add("小時售電金額(NTD)"); + } + + foreach (var head in lasthead) { @@ -248,20 +260,23 @@ namespace SolarPower.Controllers cell.SetCellValue(b); cell.CellStyle = styleLine12; index++; - foreach (var head in Formhead.Result.Data) + foreach (var head in Formhead.Result.Data.Inv) { cell = row.CreateCell(index); cell.SetCellValue(dbody[head] == null ? "0" : dbody[head].ToString()); cell.CellStyle = styleLine12; index++; } - string[] bodynames = { + List bodynames = new List(){ "hourKWH", "hourKWHp", "irradiance", - "temperature", - "hourmoney", + "temperature" }; + if (Formhead.Result.Data.ShowMoney == 1) + { + bodynames.Add("hourmoney"); + } foreach (var bodyname in bodynames) { cell = row.CreateCell(index); @@ -313,6 +328,7 @@ namespace SolarPower.Controllers cell.CellStyle = styleLine12; RowPosition++; + index = 0; row = sheet.CreateRow(RowPosition); cell = row.CreateCell(index); @@ -323,24 +339,30 @@ namespace SolarPower.Controllers cell.CellStyle = styleLine12; RowPosition++; - index = 0; - row = sheet.CreateRow(RowPosition); - cell = row.CreateCell(index); - cell.SetCellValue("日售電金額(NTD):"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(1); - cell.SetCellValue(ntd); - cell.CellStyle = styleLine12; - RowPosition++; - index = 0; - row = sheet.CreateRow(RowPosition); - cell = row.CreateCell(index); - cell.SetCellValue("日售電單價(NTD):"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(1); - cell.SetCellValue(ntdone); - cell.CellStyle = styleLine12; + if (Formhead.Result.Data.ShowMoney == 1) + { + index = 0; + row = sheet.CreateRow(RowPosition); + cell = row.CreateCell(index); + cell.SetCellValue("日售電金額(NTD):"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(1); + cell.SetCellValue(ntd); + cell.CellStyle = styleLine12; + RowPosition++; + + index = 0; + row = sheet.CreateRow(RowPosition); + cell = row.CreateCell(index); + cell.SetCellValue("日售電單價(NTD):"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(1); + cell.SetCellValue(ntdone); + cell.CellStyle = styleLine12; + } + + #endregion break; @@ -354,7 +376,7 @@ namespace SolarPower.Controllers sheet.SetColumnWidth(index2, 4 * 160 * 8); index2++; - foreach (var head in Formhead.Result.Data) + foreach (var head in Formhead.Result.Data.Inv) { cell2 = row2.CreateCell(index2); cell2.SetCellValue(head); @@ -363,7 +385,7 @@ namespace SolarPower.Controllers index2++; } - string[] lasthead2 = + List lasthead2 = new List() { "日發電量(kWh)", "日發電量百分比(%)", @@ -371,10 +393,13 @@ namespace SolarPower.Controllers "kWH/kWP", "PR%", "日平均日照度(W/㎡)", - "日平均模組溫度(°C)", - "日售電金額(NTD)" + "日平均模組溫度(°C)" + }; - + if (Formhead.Result.Data.ShowMoney == 1) + { + lasthead2.Add("日售電金額(NTD)"); + } foreach (var head in lasthead2) { cell2 = row2.CreateCell(index2); @@ -401,7 +426,7 @@ namespace SolarPower.Controllers monthKWH = dbody["monthKWH"] == null ? "0": dbody["monthKWH"].ToString(); monthmoney = dbody["monthmoney"] == null ? "0" : dbody["monthmoney"].ToString(); monthmoneyone = (Convert.ToDouble(dbody["monthmoneyone"].ToString()) + Convert.ToDouble(monthmoneyone)).ToString(); - if (dbody["SolarType"].ToString() == "1")//檢驗是否為租用 + if (dbody["SolarType"].ToString() == "1" && Formhead.Result.Data.ShowMoney == 1)//檢驗是否為租用 { check_hire = true; sitedb = dbody["SiteDB"].ToString(); @@ -413,23 +438,26 @@ namespace SolarPower.Controllers cell2.SetCellValue(b); cell2.CellStyle = styleLine12; index2++; - foreach (var head in Formhead.Result.Data) + foreach (var head in Formhead.Result.Data.Inv) { cell2 = row2.CreateCell(index2); cell2.SetCellValue(dbody[head] == null ? "0": dbody[head].ToString()); cell2.CellStyle = styleLine12; index2++; } - string[] bodynames = { + List bodynames = new List(){ "dayKWH", "dayKWHp", "tothour", "KWHKWP", "PR", "irradiance", - "temperature", - "soldmoney" + "temperature" }; + if (Formhead.Result.Data.ShowMoney == 1) + { + bodynames.Add("soldmoney"); + } foreach (var bodyname in bodynames) { cell2 = row2.CreateCell(index2); @@ -471,14 +499,17 @@ namespace SolarPower.Controllers cell.SetCellValue("月發電量(kWh)"); cell.CellStyle = styleLine12; index++; - cell = row.CreateCell(index); - cell.SetCellValue("月售電金額(NTD)"); - cell.CellStyle = styleLine12; - index++; - cell = row.CreateCell(index); - cell.SetCellValue("月售電單價(NTD)"); - cell.CellStyle = styleLine12; - index++; + if (Formhead.Result.Data.ShowMoney == 1) + { + cell = row.CreateCell(index); + cell.SetCellValue("月售電金額(NTD)"); + cell.CellStyle = styleLine12; + index++; + cell = row.CreateCell(index); + cell.SetCellValue("月售電單價(NTD)"); + cell.CellStyle = styleLine12; + index++; + } cell = row.CreateCell(index); cell.SetCellValue("月售電天數"); cell.CellStyle = styleLine12; @@ -505,14 +536,17 @@ namespace SolarPower.Controllers cell.SetCellValue(monthKWH); cell.CellStyle = styleLine12; index++; - cell = row.CreateCell(index); - cell.SetCellValue(monthmoney); - cell.CellStyle = styleLine12; - index++; - cell = row.CreateCell(index); - cell.SetCellValue(Math.Round(Convert.ToDouble(monthmoneyone) / Useday,2)); - cell.CellStyle = styleLine12; - index++; + if (Formhead.Result.Data.ShowMoney == 1) + { + cell = row.CreateCell(index); + cell.SetCellValue(monthmoney); + cell.CellStyle = styleLine12; + index++; + cell = row.CreateCell(index); + cell.SetCellValue(Math.Round(Convert.ToDouble(monthmoneyone) / Useday, 2)); + cell.CellStyle = styleLine12; + index++; + } cell = row.CreateCell(index); cell.SetCellValue(Useday); cell.CellStyle = styleLine12; @@ -581,8 +615,15 @@ namespace SolarPower.Controllers } } - - + var name = ""; + if(postObject.FormType == 0) + { + name = "日"; + } + else + { + name = "月"; + } var ms = new NpoiMemoryStream @@ -592,7 +633,7 @@ namespace SolarPower.Controllers workbook.Write(ms); ms.Flush(); ms.Seek(0, SeekOrigin.Begin); - return File(ms, "application/vnd.ms-excel", "text.xlsx"); + return File(ms, "application/vnd.ms-excel", name+"報表.xlsx"); } public string Checknull(string a) diff --git a/SolarPower/Controllers/UserController.cs b/SolarPower/Controllers/UserController.cs index 72931e1..f560519 100644 --- a/SolarPower/Controllers/UserController.cs +++ b/SolarPower/Controllers/UserController.cs @@ -597,5 +597,29 @@ namespace SolarPower.Controllers return apiResult; } + + [HttpPost] + public async Task> DeleteOneGetEmail(IdAndTypeByEmail post) + { + ApiResult apiResult = new ApiResult(); + + try + { + await userRepository.DeleteOneGetEmail(post); + apiResult.Code = "0000"; + apiResult.Msg = "更改成功"; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = errorCode.GetString(apiResult.Code); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + + return apiResult; + } + + + } } diff --git a/SolarPower/DBSchema/solar_power_schema.sql b/SolarPower/DBSchema/solar_power_schema.sql index 357a5d1..48636c4 100644 --- a/SolarPower/DBSchema/solar_power_schema.sql +++ b/SolarPower/DBSchema/solar_power_schema.sql @@ -2082,6 +2082,14 @@ ENGINE=InnoDB +-- 新增帳號是否接收通知權限 20210730 +ALTER TABLE `power_station_operation_personnel` + ADD COLUMN `EmailDayReport` TINYINT(1) NOT NULL DEFAULT '1' COMMENT '接收Email日報 0:不接收 1:接收' AFTER `UserId`, + ADD COLUMN `EmailMonthReport` TINYINT(1) NOT NULL DEFAULT '1' COMMENT '接收Email月報 0:不接收 1:接收' AFTER `EmailDayReport`, + ADD COLUMN `EmailComplexReport` TINYINT(1) NOT NULL DEFAULT '1' COMMENT '接收Email綜合報告 0:不接收 1:接收' AFTER `EmailMonthReport`, + ADD COLUMN `EmailException` TINYINT(1) NOT NULL DEFAULT '1' COMMENT '接收Email異常通知 0:不接收 1:接收' AFTER `EmailComplexReport`; + + /*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */; /*!40014 SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1) */; diff --git a/SolarPower/Models/StationReport.cs b/SolarPower/Models/StationReport.cs index 4d4e3b0..dbe5a15 100644 --- a/SolarPower/Models/StationReport.cs +++ b/SolarPower/Models/StationReport.cs @@ -18,6 +18,12 @@ namespace SolarPower.Models public string PowerStationName { get; set; } } + public class InvAndMoney + { + public List Inv { get; set; } + public int ShowMoney { get; set; } +} + public class Select_table { public int SearchType { get; set; } diff --git a/SolarPower/Models/User.cs b/SolarPower/Models/User.cs index 52a2c03..4fcddf6 100644 --- a/SolarPower/Models/User.cs +++ b/SolarPower/Models/User.cs @@ -142,6 +142,10 @@ namespace SolarPower.Models.User public string PowerStationName { get; set; } public string Code { get; set; } public string EscrowName { get; set; } + public byte EmailDayReport { get; set; } + public byte EmailMonthReport { get; set; } + public byte EmailComplexReport { get; set; } + public byte EmailException { get; set; } } public class PostUserPowerStation @@ -149,4 +153,10 @@ namespace SolarPower.Models.User public int PowerStationId { get; set; } public int UserId { get; set; } } + public class IdAndTypeByEmail + { + public int Id { get; set; } + public int Type { get; set; } + public int Check { get; set; } + } } diff --git a/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs b/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs index c3f75b4..a37afa6 100644 --- a/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs +++ b/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs @@ -65,7 +65,7 @@ namespace SolarPower.Quartz.Jobs #region 氣象觀測(取資料) logger.LogInformation("【CalcPowerStationJob】【開始取得氣象觀測】"); var client = new HttpClient(); - var UVUri = "https://opendata.cwb.gov.tw/api/v1/rest/datastore/O-A0003-001?Authorization=CWB-EA24220B-DDCC-4188-84E5-AD37A0E03F80"; + var UVUri = "https://opendata.cwb.gov.tw/api/v1/rest/datastore/O-A0003-001?Authorization=CWB-EA24220B-DDCC-4188-84E5-AD37A0E03F80&elementName=TIME,TEMP"; HttpResponseMessage response = client.GetAsync(UVUri).Result; String jsonUVs = response.Content.ReadAsStringAsync().Result.ToString(); Root2 observation = JsonConvert.DeserializeObject(jsonUVs); diff --git a/SolarPower/Repository/Implement/UserRepository.cs b/SolarPower/Repository/Implement/UserRepository.cs index 1c560ea..ba98624 100644 --- a/SolarPower/Repository/Implement/UserRepository.cs +++ b/SolarPower/Repository/Implement/UserRepository.cs @@ -330,12 +330,17 @@ namespace SolarPower.Repository.Implement op.Id, ps.Code, ps.Name AS PowerStationName, + op.EmailDayReport, + op.EmailMonthReport, + op.EmailComplexReport, + op.EmailException, CASE ps.IsEscrow WHEN 1 THEN CONCAT(ps.EscrowName, '(代管)') WHEN 0 THEN c.Name END AS EscrowName FROM power_station_operation_personnel op LEFT JOIN power_station ps ON op.PowerStationId = ps.Id LEFT JOIN company c ON ps.CompanyId = c.Id + LEFT JOIN user us ON us.Id = @UserId WHERE op.Deleted = 0 AND op.UserId = @UserId"; result = (await conn.QueryAsync(sql, new { UserId = userId })).ToList(); @@ -442,5 +447,49 @@ namespace SolarPower.Repository.Implement return result; } } + + public async Task DeleteOneGetEmail(IdAndTypeByEmail post) + { + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + conn.Open(); + using (var trans = conn.BeginTransaction()) + { + try + { + var changetype = ""; + switch (post.Type) + { + case 0: + changetype = "EmailDayReport"; + break; + case 1: + changetype = "EmailMonthReport"; + break; + case 2: + changetype = "EmailComplexReport"; + break; + case 3: + changetype = "EmailException"; + break; + } + var sql = @$"UPDATE power_station_operation_personnel SET {changetype} = {post.Check} WHERE Id = @Id"; + + await conn.ExecuteAsync(sql, new { Id = post.Id }, trans); + + trans.Commit(); + } + catch (Exception exception) + { + trans.Rollback(); + throw exception; + } + finally + { + conn.Close(); + } + } + } + } } } diff --git a/SolarPower/Repository/Interface/IUserRepository.cs b/SolarPower/Repository/Interface/IUserRepository.cs index a169b29..a49cf00 100644 --- a/SolarPower/Repository/Interface/IUserRepository.cs +++ b/SolarPower/Repository/Interface/IUserRepository.cs @@ -102,5 +102,7 @@ namespace SolarPower.Repository.Interface /// /// Task> GetCompanyPowerStationAsync(int companyId, int userId); + + Task DeleteOneGetEmail(IdAndTypeByEmail post); } } diff --git a/SolarPower/Views/StationReport/Index.cshtml b/SolarPower/Views/StationReport/Index.cshtml index cf5f888..9b180b2 100644 --- a/SolarPower/Views/StationReport/Index.cshtml +++ b/SolarPower/Views/StationReport/Index.cshtml @@ -642,7 +642,7 @@ $('#TableHead').empty(); var str = ""; str += "Date"; - $.each(rel.data, function (index, inverter) { + $.each(rel.data.inv, function (index, inverter) { haveinvertName.push(inverter); str += "" + inverter + ""; }) @@ -653,7 +653,9 @@ str += "小時
發電量
百分比
(%)"; str += "小時
平均
日照度
(W/㎡)"; str += "小時
平均
模組
溫度
(°C)"; - str += "小時
售電
金額
(NTD)"; + if (rel.data.showMoney == 1) { + str += "小時
售電
金額
(NTD)"; + } break; case 1: str += "日
發電量
(kWh)"; @@ -663,13 +665,15 @@ str += "PR%"; str += "日
平均
日照度
(W/㎡)"; str += "日
平均
模組溫度
(°C)"; - str += "日
售電金額
(NTD)"; + if (rel.data.showMoney == 1) { + str += "日
售電金額
(NTD)"; + } break; } str += ""; $('#TableHead').append(str); - tablebody(form); + tablebody(form, rel.data.showMoney); }, 'json'); @@ -680,7 +684,7 @@ tablehand(form); } - function tablebody(form) + function tablebody(form,showmoney) { var send_data = { @@ -722,7 +726,9 @@ sta += "" + Number(inverter.hourKWHp) + ""; sta += "" + Number(inverter.irradiance) + ""; sta += "" + Number(inverter.temperature) + ""; - sta += "" + Number(inverter.hourmoney) + ""; + if (showmoney == 1) { + sta += "" + Number(inverter.hourmoney) + ""; + } sta += ""; thour = inverter.tothour ? inverter.tothour.toFixed(2) : 0; tpr = inverter.pr ? inverter.pr.toFixed(2) : 0; @@ -736,8 +742,10 @@ stc += "" + 'kWH/kWP' + ""; stc += "" + 'PR%' + ""; stc += "" + '日發電量(kWh)' + ""; - stc += "" + '日售電金額(NTD)' + ""; - stc += "" + '日售電單價(NTD)' + ""; + if (showmoney == 1) { + stc += "" + '日售電金額(NTD)' + ""; + stc += "" + '日售電單價(NTD)' + ""; + } stc += ""; @@ -746,8 +754,10 @@ stb += "" + kWhkwp + ""; stb += "" + tpr + ""; stb += "" + tkwh + ""; - stb += "" + ntd + ""; - stb += "" + ntdone + ""; + if (showmoney == 1) { + stb += "" + ntd + ""; + stb += "" + ntdone + ""; + } stb += ""; @@ -784,7 +794,9 @@ sta += "" + inverter.PR + ""; sta += "" + inverter.irradiance + ""; sta += "" + inverter.temperature + ""; - sta += "" + inverter.soldmoney + ""; + if (showmoney == 1) { + sta += "" + inverter.soldmoney + ""; + } sta += ""; avghour += inverter.tothour ? inverter.tothour : 0; avgKWHKWP += inverter.KWHKWP ? inverter.KWHKWP : 0; @@ -808,8 +820,10 @@ stc += "" + '日kWH/kWP平均' + ""; stc += "" + '日發電量平均(kWh)' + ""; stc += "" + '月發電量(kWh)' + ""; - stc += "" + '月售電金額(NTD)' + ""; - stc += "" + '月售電單價(NTD)' + ""; + if (showmoney == 1) { + stc += "" + '月售電金額(NTD)' + ""; + stc += "" + '月售電單價(NTD)' + ""; + } stc += "" + '月售電天數' + ""; stc += ""; @@ -830,13 +844,15 @@ stb += "" + (avgKWHKWP / monthday).toFixed(2) + ""; stb += "" + (avgdayKWH / monthday).toFixed(2) + ""; stb += "" + monthKWH + ""; - stb += "" + monthmoney + ""; - stb += "" + (monthmoneyone / monthday).toFixed(2) + ""; + if (showmoney == 1) { + stb += "" + monthmoney + ""; + stb += "" + (monthmoneyone / monthday).toFixed(2) + ""; + } stb += "" + monthday + ""; stb += ""; } var std = ""; - if (check_hire == true) + if (check_hire == true && showmoney == 1) { var dataTosent = { diff --git a/SolarPower/Views/User/Index.cshtml b/SolarPower/Views/User/Index.cshtml index 31d3eae..7ac90f3 100644 --- a/SolarPower/Views/User/Index.cshtml +++ b/SolarPower/Views/User/Index.cshtml @@ -764,6 +764,44 @@ //#endregion + $("#user-power-station-table").on("click", "input.custom-control-input", function () { + selected_id = $(this).attr('data-id'); + var clicktype = $(this).attr('id'); + var usetypename = clicktype.split("-"); + var usetype = 0; + var check = 0; + switch (usetypename[1]) + { + case "emailDayReport": usetype = 0; break; + case "emailMonthReport": usetype = 1; break; + case "emailComplexReport": usetype = 2; break; + case "emailException": usetype = 3; break; + } + if (this.checked) { + check = 1; + } + else { + check = 0; + } + + + var url = "/User/DeleteOneGetEmail/"; + var send_data = { + Id: selected_id, + Type: usetype, + Check: check + } + $.post(url, send_data, function (rel) { + if (rel.code != "0000") { + toast_error(rel.msg); + return; + } + toast_ok(rel.msg); + + }, 'json'); + }) + + //#region 新增使用者管理電站 function AddUserPowerStation(e) { @@ -849,6 +887,32 @@ str += "" + value.code + ""; str += "" + value.powerStationName + ""; str += "" + value.escrowName + ""; + if (value.emailDayReport == 0) { + str += "" + "
"+ ""; + } + else + { + str += "" + "
" + ""; + } + if (value.emailMonthReport == 0) { + str += "" + "
" + ""; + } + else { + str += "" + "
" + ""; + } + if (value.emailComplexReport == 0) { + str += "" + "
" + ""; + } + else { + str += "" + "
" + ""; + } + if (value.emailException == 0) { + str += "" + "
" + ""; + } + else { + str += "" + "
" + ""; + } + str += "" + '' + ""; str += ""; diff --git a/SolarPower/Views/User/_UserManager.cshtml b/SolarPower/Views/User/_UserManager.cshtml index dc4a293..63fc01a 100644 --- a/SolarPower/Views/User/_UserManager.cshtml +++ b/SolarPower/Views/User/_UserManager.cshtml @@ -137,6 +137,10 @@ 電站代碼 電站名稱 公司 + 收email日報 + 收email月報 + 收email綜合報告 + 收email異常通知 功能