diff --git a/SolarPower/Controllers/AnalysisInverterController.cs b/SolarPower/Controllers/AnalysisInverterController.cs index e2c4ff8..4905b0d 100644 --- a/SolarPower/Controllers/AnalysisInverterController.cs +++ b/SolarPower/Controllers/AnalysisInverterController.cs @@ -38,7 +38,7 @@ namespace SolarPower.Controllers } else { - powerStations = await powerStationRepository.GetPowerStationsByCompanyId(myUser.CompanyId); + powerStations = await powerStationRepository.GetPowerStationsByCompanyId(myUser); } var siteDBNamePowerStationId = new Dictionary>(); diff --git a/SolarPower/Controllers/AnalysisStationInfoController.cs b/SolarPower/Controllers/AnalysisStationInfoController.cs index 07e99fe..b502bc0 100644 --- a/SolarPower/Controllers/AnalysisStationInfoController.cs +++ b/SolarPower/Controllers/AnalysisStationInfoController.cs @@ -37,7 +37,7 @@ namespace SolarPower.Controllers } else { - powerStations = await powerStationRepository.GetPowerStationsByCompanyId(myUser.CompanyId); + powerStations = await powerStationRepository.GetPowerStationsByCompanyId(myUser); } var siteDBNamePowerStationId = new Dictionary>(); @@ -51,7 +51,7 @@ namespace SolarPower.Controllers var powerStationDevices = await powerStationRepository.GetPowerStationDevice(siteDBNamePowerStationId, filter); - powerStationDevices = powerStationDevices.Where(x => x.DeviceId != null).ToList(); + //powerStationDevices = powerStationDevices.Where(x => x.DeviceId != null).ToList(); var powerStationDevice_cityName_Group = powerStationDevices.GroupBy(x => x.CityName).ToList(); @@ -79,7 +79,10 @@ namespace SolarPower.Controllers temp.Add(powerStation); foreach (var device in psName_Group) { - temp.Add(device); + if(!string.IsNullOrEmpty(device.DeviceId)) + { + temp.Add(device); + } } deviceDic.Add(psName_Group.Key, temp); } diff --git a/SolarPower/Controllers/PowerStationController.cs b/SolarPower/Controllers/PowerStationController.cs index bb70699..ac02bae 100644 --- a/SolarPower/Controllers/PowerStationController.cs +++ b/SolarPower/Controllers/PowerStationController.cs @@ -2033,7 +2033,23 @@ namespace SolarPower.Controllers foreach (var solar in solaramount) { - solar.MainDisplay = Path.Combine(stationImageFilePath, solar.Id.ToString()) + "/" + solar.MainDisplay; + //判斷該檔案是否存在 + if (!string.IsNullOrEmpty(solar.MainDisplay)) + { + var fullFilePath = Directory.GetCurrentDirectory() + "/wwwroot" + Path.Combine(stationImageFilePath, solar.Id.ToString()) + "/" + solar.MainDisplay; + if (System.IO.File.Exists(fullFilePath)) + { + solar.MainDisplay = Path.Combine(stationImageFilePath, solar.Id.ToString()) + "/" + solar.MainDisplay; + } + else + { + solar.MainDisplay = Path.Combine("img", "blank.gif"); + } + } + else + { + solar.MainDisplay = Path.Combine("img", "blank.gif"); + } List deviceControllerid = await powerStationRepository.GetAllDeviceControllerId(solar.Id, solar.SiteDB); var InverterTable = await powerStationRepository.InverterTable(deviceControllerid, solar.SiteDB); solar.InverterAmount = InverterTable.Count; diff --git a/SolarPower/Controllers/StationOverviewController.cs b/SolarPower/Controllers/StationOverviewController.cs index fdc4547..4660c69 100644 --- a/SolarPower/Controllers/StationOverviewController.cs +++ b/SolarPower/Controllers/StationOverviewController.cs @@ -6,11 +6,11 @@ using SolarPower.Models.PowerStation; using SolarPower.Repository.Interface; using System; using System.Collections.Generic; +using System.Globalization; using System.IO; using System.Linq; using System.Net.Http; using System.Threading.Tasks; -using System.Globalization; namespace SolarPower.Controllers { @@ -52,7 +52,23 @@ namespace SolarPower.Controllers foreach (var solar in solaramount) { - solar.MainDisplay = Path.Combine(stationImageFilePath, solar.Id.ToString()) + "/" + solar.MainDisplay; + //判斷該檔案是否存在 + if (!string.IsNullOrEmpty(solar.MainDisplay)) + { + var fullFilePath = Directory.GetCurrentDirectory() + "/wwwroot" + Path.Combine(stationImageFilePath, solar.Id.ToString()) + "/" + solar.MainDisplay; + if (System.IO.File.Exists(fullFilePath)) + { + solar.MainDisplay = Path.Combine(stationImageFilePath, solar.Id.ToString()) + "/" + solar.MainDisplay; + } + else + { + solar.MainDisplay = Path.Combine("img", "blank.gif"); + } + } + else + { + solar.MainDisplay = Path.Combine("img", "blank.gif"); + } } apiResult.Data = solaramount; @@ -438,7 +454,7 @@ namespace SolarPower.Controllers { a.Function = @$"{a.FormId}"; } - if(a.NormalTime == "1970-01-01 08:00:00") + if (a.NormalTime == "1970-01-01 08:00:00") { a.NormalTime = ""; } @@ -491,12 +507,12 @@ namespace SolarPower.Controllers { List values = new List(); - foreach(var lable in inverterkwhBar.Labels) + foreach (var lable in inverterkwhBar.Labels) { var find = false; foreach (var value in inverterHistory) { - if(value.TIMESTAMP == lable) + if (value.TIMESTAMP == lable) { values.Add(value.KWH); find = true; diff --git a/SolarPower/Controllers/StationReportController.cs b/SolarPower/Controllers/StationReportController.cs index 3085960..7819911 100644 --- a/SolarPower/Controllers/StationReportController.cs +++ b/SolarPower/Controllers/StationReportController.cs @@ -1212,5 +1212,298 @@ namespace SolarPower.Controllers return apiResult; } + public FileResult ExportExcelmaxtable(string post) + { + var postObject = JsonConvert.DeserializeObject(post); + var workbook = new XSSFWorkbook(); + #region excel設定 + IFont font12 = workbook.CreateFont(); + font12.FontName = "新細明體"; + font12.FontHeightInPoints = 12; + ICellStyle style12 = workbook.CreateCellStyle(); + style12.SetFont(font12); + style12.Alignment = HorizontalAlignment.Center; + style12.VerticalAlignment = VerticalAlignment.Center; + IFont font12Times = workbook.CreateFont(); + font12Times.FontName = "Times New Roman"; + font12Times.FontHeightInPoints = 12; + IFont font18 = workbook.CreateFont(); + font18.FontName = "新細明體"; + font18.FontHeightInPoints = 18; + font18.IsBold = true; + ICellStyle styleTitle18 = workbook.CreateCellStyle(); + styleTitle18.SetFont(font18); + styleTitle18.Alignment = HorizontalAlignment.Center; + styleTitle18.VerticalAlignment = VerticalAlignment.Center; + ICellStyle styleLeft12 = workbook.CreateCellStyle(); + styleLeft12.SetFont(font12); + styleLeft12.Alignment = HorizontalAlignment.Left; + styleLeft12.VerticalAlignment = VerticalAlignment.Center; + ICellStyle styleLine12 = workbook.CreateCellStyle(); + styleLine12.SetFont(font12); + styleLine12.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center; + styleLine12.VerticalAlignment = VerticalAlignment.Center; + styleLine12.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin; + styleLine12.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin; + styleLine12.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin; + styleLine12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin; + ICellStyle stylein12 = workbook.CreateCellStyle(); + stylein12.SetFont(font12Times); + stylein12.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left; + stylein12.VerticalAlignment = VerticalAlignment.Center; + stylein12.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin; + stylein12.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin; + stylein12.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin; + stylein12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin; + stylein12.WrapText = true; + #endregion + var Formbody = GetMaxForm(postObject); + var sheet = workbook.CreateSheet("綜合報表"); + int RowPosition = 0; + int index = 0; + var citycount = Formbody.Result.Data.GroupBy(a => a.CityName).Count(); + RowPosition = citycount + 6; + IRow row; + ICell cell; + double kwhkwp = 0; + double kwp = 0; + CellRangeAddress region; + List cityArrays = new List(); + foreach (var form in Formbody.Result.Data) + { + index = 0; + row = sheet.CreateRow(RowPosition); + cell = row.CreateCell(index); + cell.SetCellValue(form.CityName+form.AreaName); + cell.CellStyle = styleLine12; + + index++; + cell = row.CreateCell(index); + cell.SetCellValue(form.PowerstationName); + cell.CellStyle = styleLine12; + + index++; + cell = row.CreateCell(index); + cell.SetCellValue(Math.Round(form.Kwh,2)); + cell.CellStyle = styleLine12; + + index++; + cell = row.CreateCell(index); + cell.SetCellValue(Math.Round(form.SolarHour,2)); + cell.CellStyle = styleLine12; + + index++; + cell = row.CreateCell(index); + cell.SetCellValue(Math.Round(form.AvgIrradiance,2)); + cell.CellStyle = styleLine12; + + index++; + cell = row.CreateCell(index); + cell.SetCellValue(Math.Round(form.AvgPR,2)); + cell.CellStyle = styleLine12; + + kwp += form.Kwh; + kwhkwp += form.AvgKWHKWP; + RowPosition++; + CityArray cityinfo = new CityArray + { + City = form.CityName, + Count = 1, + Kwh = form.Kwh, + SolarHour = form.SolarHour + }; + if( cityArrays.Where(a=>a.City == form.CityName).Count() > 0) + { + var city = cityArrays.Where(a => a.City == form.CityName).FirstOrDefault(); + city.Count += cityinfo.Count; + city.Kwh += cityinfo.Kwh; + city.SolarHour += cityinfo.SolarHour; + } + else + { + cityArrays.Add(cityinfo); + } + + + } + RowPosition = citycount + 6; + RowPosition--; + row = sheet.CreateRow(RowPosition); + index = 0; + List lasthead = new List() + { + "區域", + "電站名稱", + "發電量", + "發電小時", + "平均日照", + "PR" + }; + foreach (var head in lasthead) + { + sheet.SetColumnWidth(index, 4 * 160 * 8); + cell = row.CreateCell(index); + cell.SetCellValue(head); + cell.CellStyle = styleLine12; + index++; + } + + RowPosition--; + RowPosition -= citycount; + var cityRowPosition = RowPosition; + index = 0; + foreach(var cityArray in cityArrays) + { + index = 0; + row = sheet.CreateRow(cityRowPosition); + cell = row.CreateCell(index); + cell.SetCellValue(cityArray.City); + cell.CellStyle = styleLine12; + region = new CellRangeAddress(cityRowPosition, cityRowPosition, index, index + 1); + sheet.AddMergedRegion(region); + index++; + cell = row.CreateCell(index); + cell.CellStyle = styleLine12; + + index++; + cell = row.CreateCell(index); + cell.SetCellValue(Math.Round((cityArray.Kwh / cityArray.Count), 2)); + cell.CellStyle = styleLine12; + region = new CellRangeAddress(cityRowPosition, cityRowPosition, index, index + 1); + sheet.AddMergedRegion(region); + index++; + cell = row.CreateCell(index); + cell.CellStyle = styleLine12; + + + index++; + cell = row.CreateCell(index); + cell.SetCellValue(Math.Round((cityArray.SolarHour / cityArray.Count), 2)); + cell.CellStyle = styleLine12; + region = new CellRangeAddress(cityRowPosition, cityRowPosition, index, index + 1); + sheet.AddMergedRegion(region); + index++; + cell = row.CreateCell(index); + cell.CellStyle = styleLine12; + cityRowPosition++; + } + + index = 0; + RowPosition--; + row = sheet.CreateRow(RowPosition); + cell = row.CreateCell(index); + cell.SetCellValue("縣市"); + cell.CellStyle = styleLine12; + region = new CellRangeAddress(RowPosition, RowPosition, index, index + 1); + sheet.AddMergedRegion(region); + index++; + cell = row.CreateCell(index); + cell.CellStyle = styleLine12; + + index++; + cell = row.CreateCell(index); + cell.SetCellValue("平均發電量(kWp)"); + cell.CellStyle = styleLine12; + region = new CellRangeAddress(RowPosition, RowPosition, index, index + 1); + sheet.AddMergedRegion(region); + index++; + cell = row.CreateCell(index); + cell.CellStyle = styleLine12; + + index++; + cell = row.CreateCell(index); + cell.SetCellValue("發電時間(小時)"); + cell.CellStyle = styleLine12; + region = new CellRangeAddress(RowPosition, RowPosition, index, index + 1); + sheet.AddMergedRegion(region); + index++; + cell = row.CreateCell(index); + cell.CellStyle = styleLine12; + + RowPosition = 0; + index = 0; + row = sheet.CreateRow(RowPosition); + cell = row.CreateCell(index); + cell.SetCellValue("時間"); + cell.CellStyle = styleLine12; + region = new CellRangeAddress(RowPosition, RowPosition, index, index + 1); + sheet.AddMergedRegion(region); + index++; + cell = row.CreateCell(index); + cell.CellStyle = styleLine12; + + index ++; + cell = row.CreateCell(index); + cell.SetCellValue("發電量"); + cell.CellStyle = styleLine12; + region = new CellRangeAddress(RowPosition, RowPosition, index, index + 1); + sheet.AddMergedRegion(region); + index++; + cell = row.CreateCell(index); + cell.CellStyle = styleLine12; + + index++; + cell = row.CreateCell(index); + cell.SetCellValue("有效日照時數"); + cell.CellStyle = styleLine12; + region = new CellRangeAddress(RowPosition, RowPosition, index, index + 1); + sheet.AddMergedRegion(region); + index++; + cell = row.CreateCell(index); + cell.CellStyle = styleLine12; + + + + + RowPosition++; + row = sheet.CreateRow(RowPosition); + + index = 0; + cell = row.CreateCell(index); + cell.SetCellValue(postObject.Time); + cell.CellStyle = styleLine12; + region = new CellRangeAddress(RowPosition, RowPosition, index, index + 1); + sheet.AddMergedRegion(region); + index++; + cell = row.CreateCell(index); + cell.CellStyle = styleLine12; + + index++; + cell = row.CreateCell(index); + cell.SetCellValue(Math.Round(kwp,2)); + cell.CellStyle = styleLine12; + region = new CellRangeAddress(RowPosition, RowPosition, index, index + 1); + sheet.AddMergedRegion(region); + index++; + cell = row.CreateCell(index); + cell.CellStyle = styleLine12; + + index ++; + cell = row.CreateCell(index); + cell.SetCellValue(Math.Round(kwhkwp, 2)); + cell.CellStyle = styleLine12; + region = new CellRangeAddress(RowPosition, RowPosition, index, index + 1); + sheet.AddMergedRegion(region); + index++; + cell = row.CreateCell(index); + cell.CellStyle = styleLine12; + + + + + var ms = new NpoiMemoryStream + { + AllowClose = false + }; + workbook.Write(ms); + ms.Flush(); + ms.Seek(0, SeekOrigin.Begin); + var Datename = postObject.Time.Replace("-", ""); + return File(ms, "application/vnd.ms-excel", "FIC太陽能監控平台" + "_" + "綜合報表" + "_" + postObject.Userid + Datename + ".xlsx"); + } + + + + } } diff --git a/SolarPower/Models/ElectricitySoldRecord.cs b/SolarPower/Models/ElectricitySoldRecord.cs index 1dd8650..9ef01f4 100644 --- a/SolarPower/Models/ElectricitySoldRecord.cs +++ b/SolarPower/Models/ElectricitySoldRecord.cs @@ -14,6 +14,7 @@ namespace SolarPower.Models public string EndAt { get { return Convert.ToDateTime(endAt).ToString("yyyy-MM-dd"); } set { endAt = value; } } //結束時間 public int Kwh { get; set; }//購電度數 public float Money { get; set; }//售出金額 + public int Deleted { get; set; } } public class ElectricitySoldRecordTable : ElectricitySoldRecord diff --git a/SolarPower/Models/StationReport.cs b/SolarPower/Models/StationReport.cs index 89ed921..22a962c 100644 --- a/SolarPower/Models/StationReport.cs +++ b/SolarPower/Models/StationReport.cs @@ -85,13 +85,22 @@ namespace SolarPower.Models public string AreaName { get; set; } public string PowerstationName { get; set; } public int PowerstationId { get; set; } + public int PowerstationType { get; set; } public double Kwh { get; set; } public string PowerstationDB { get; set; } public double SolarHour { get; set; } public double AvgIrradiance { get; set; } public double AvgPR { get; set; } public double AvgKWHKWP { get; set; } + public double TodayMoney { get; set; } + } + public class CityArray + { + public string City { get; set; } + public double Kwh { get; set; } + public double SolarHour { get; set; } + public int Count { get; set; } } diff --git a/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs b/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs index 63c979c..748b33a 100644 --- a/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs +++ b/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs @@ -42,7 +42,7 @@ namespace SolarPower.Quartz.Jobs if (this.environment.IsDevelopment()) { - dateTime = DateTimeNow.AddHours(-1).ToString("yyyy-MM-dd HH"); + dateTime = "2021-08-06 10"; } logger.LogInformation("【CalcPowerStationJob】【任務開始】"); @@ -170,10 +170,22 @@ namespace SolarPower.Quartz.Jobs history.CARBON = history.KWH * carbonRate; //總減碳量(總發電量 * (0.554/1000)[抓資料庫值] calcPowerStation.Total_Carbon = history.TotalKWH * carbonRate; - history.TODAYCARBON = lastmoneyhistorybyhour.TODAYCARBON + history.KWH * carbonRate; - history.TOTALCARBON = lastmoneyhistorybyhour.TOTALCARBON + history.KWH * carbonRate; - history.TODAYMONEY = lastmoneyhistorybyhour.TODAYMONEY + history.KWH * powerStation.PowerRate; - history.TOTALMONEY = lastmoneyhistorybyhour.TOTALMONEY + history.KWH * powerStation.PowerRate; + + if(lastmoneyhistorybyhour != null) + { + history.TODAYCARBON = lastmoneyhistorybyhour.TODAYCARBON + history.KWH * carbonRate; + history.TOTALCARBON = lastmoneyhistorybyhour.TOTALCARBON + history.KWH * carbonRate; + history.TODAYMONEY = lastmoneyhistorybyhour.TODAYMONEY + history.KWH * powerStation.PowerRate; + history.TOTALMONEY = lastmoneyhistorybyhour.TOTALMONEY + history.KWH * powerStation.PowerRate; + } + else + { + history.TODAYCARBON = history.KWH * carbonRate; + history.TOTALCARBON = history.KWH * carbonRate; + history.TODAYMONEY = history.KWH * powerStation.PowerRate; + history.TOTALMONEY = history.KWH * powerStation.PowerRate; + } + #endregion #region 發電時間 @@ -347,206 +359,213 @@ namespace SolarPower.Quartz.Jobs } #endregion - #region step3. 將historiers INSERT 到 power_station_history_hour 資料表 - List history_properties = new List() + if (!this.environment.IsDevelopment()) { - "PowerStationId", - "TIMESTAMP", - "SITEID", - "SITETYPE", - "KWH", - "TODAYKWH", - "TOTALKWH", - "KWHKWP", - "PR", - "MP", - "SolarHour", - "MONEY", - "CARBON", - "TODAYMONEY", - "TOTALMONEY", - "TODAYCARBON", - "TOTALCARBON" - }; + #region step3. 將historiers INSERT 到 power_station_history_hour 資料表 + List history_properties = new List() + { + "PowerStationId", + "TIMESTAMP", + "SITEID", + "SITETYPE", + "KWH", + "TODAYKWH", + "TOTALKWH", + "KWHKWP", + "PR", + "MP", + "SolarHour", + "MONEY", + "CARBON", + "TODAYMONEY", + "TOTALMONEY", + "TODAYCARBON", + "TOTALCARBON" + }; - await powerStationRepository.AddPowerStationHistory(powerStationHistoriesHour, history_properties); - #endregion + await powerStationRepository.AddPowerStationHistory(powerStationHistoriesHour, history_properties); + #endregion - #region step4. 將Pyrheliometer History INSERT 到 sensor_history_hour 資料表 - List pyrheliometer_history_properties = new List() - { - "PowerStationId", - "TIMESTAMP", - "Irradiance" - }; + #region step4. 將Pyrheliometer History INSERT 到 sensor_history_hour 資料表 + List pyrheliometer_history_properties = new List() + { + "PowerStationId", + "TIMESTAMP", + "Irradiance" + }; - await powerStationRepository.AddPyrheliometerHistory(pyrheliometerHistoriesHour, pyrheliometer_history_properties); + await powerStationRepository.AddPyrheliometerHistory(pyrheliometerHistoriesHour, pyrheliometer_history_properties); - List Temp_history_properties = new List() - { - "PowerStationId", - "TIMESTAMP", - "Temperature" - }; + List Temp_history_properties = new List() + { + "PowerStationId", + "TIMESTAMP", + "Temperature" + }; - await powerStationRepository.AddTempHistory(TempHistoriesHour, Temp_history_properties); - #endregion + await powerStationRepository.AddTempHistory(TempHistoriesHour, Temp_history_properties); + #endregion - #region step5. calcPowerStations UPDATE 到 power_station 資料表 - List power_station_properties = new List() - { - "Id", - "kwh", - "Today_kwh", - "Total_kwh", - "today_kwhkwp", - "today_money", - "total_money", - "today_PR", - "today_carbon", - "total_carbon", - "today_irradiance", - "SolarHour", - "WeathersStationId", - "TodayWeatherTemp", - "TodayWeather", - "RateOfRain" - }; + #region step5. calcPowerStations UPDATE 到 power_station 資料表 + List power_station_properties = new List() + { + "Id", + "kwh", + "Today_kwh", + "Total_kwh", + "today_kwhkwp", + "today_money", + "total_money", + "today_PR", + "today_carbon", + "total_carbon", + "today_irradiance", + "SolarHour", + "WeathersStationId", + "TodayWeatherTemp", + "TodayWeather", + "RateOfRain" + }; - await powerStationRepository.UpdateList(calcPowerStations, power_station_properties); - #endregion + await powerStationRepository.UpdateList(calcPowerStations, power_station_properties); + #endregion - #region step6. 將 inverter INSERT 到 inverter_history_hour 資料表 - List inverter_history_properties = new List() - { - "PowerStationId", - "INVERTERID", - "TIMESTAMP", - "Irradiance", - "AC1V", - "AC1A", - "AC1W", - "AC1F", - "AC1WH", - "AC2V", - "AC2A", - "AC2W", - "AC2F", - "AC2WH", - "AC3V", - "AC3A", - "AC3W", - "AC3F", - "AC3WH", - "DC1V", - "DC1A", - "DC1W", - "DC1KW", - "DC1WH", - "DC2V", - "DC2A", - "DC2W", - "DC2KW", - "DC2WH", - "DC3V", - "DC3A", - "DC3W", - "DC3KW", - "DC3WH", - "DC4V", - "DC4A", - "DC4W", - "DC4KW", - "DC4WH", - "DC5V", - "DC5A", - "DC5W", - "DC5KW", - "DC5WH", - "PR", - "RA1", - "RA2", - "RA3", - "RA4", - "RA5", - "DCKW", - "ACKW", - "KWH", - "TODAYKWH", - "TOTALKWH", - "KWHKWP", - }; + #region step6. 將 inverter INSERT 到 inverter_history_hour 資料表 + List inverter_history_properties = new List() + { + "PowerStationId", + "INVERTERID", + "TIMESTAMP", + "Irradiance", + "AC1V", + "AC1A", + "AC1W", + "AC1F", + "AC1WH", + "AC2V", + "AC2A", + "AC2W", + "AC2F", + "AC2WH", + "AC3V", + "AC3A", + "AC3W", + "AC3F", + "AC3WH", + "DC1V", + "DC1A", + "DC1W", + "DC1KW", + "DC1WH", + "DC2V", + "DC2A", + "DC2W", + "DC2KW", + "DC2WH", + "DC3V", + "DC3A", + "DC3W", + "DC3KW", + "DC3WH", + "DC4V", + "DC4A", + "DC4W", + "DC4KW", + "DC4WH", + "DC5V", + "DC5A", + "DC5W", + "DC5KW", + "DC5WH", + "PR", + "RA1", + "RA2", + "RA3", + "RA4", + "RA5", + "DCKW", + "ACKW", + "KWH", + "TODAYKWH", + "TOTALKWH", + "KWHKWP", + }; - await powerStationRepository.AddInverterHistory(inverterHistories, inverter_history_properties); - #endregion + await powerStationRepository.AddInverterHistory(inverterHistories, inverter_history_properties); + #endregion - #region step6. 將 sensoravg INSERT 到 sensoravg_history_hour 資料表 - List sensoravg_history_properties = new List() - { - "PowerStationId", - "TIMESTAMP", - "SENSORAVG01", - "SENSORAVG02", - "SENSORAVG03", - "SENSORAVG04", - "SENSORAVG05", - "SENSORAVG06", - "SENSORAVG07", - "SENSORAVG08", - "SENSORAVG09", - "SENSORAVG10", - "SENSORAVG11", - "SENSORAVG12", - "SENSORAVG13", - "SENSORAVG14", - "SENSORAVG15", - "SENSORAVG16", - "SENSORAVG17", - "SENSORAVG18", - "SENSORAVG19", - "SENSORAVG20", - "SENSORAVG21", - "SENSORAVG22", - "SENSORAVG23", - "SENSORAVG24", - "SENSORAVG25", - "SENSORAVG26", - "SENSORAVG27", - "SENSORAVG28", - "SENSORAVG29", - "SENSORAVG30", - "SENSORAVG31", - "SENSORAVG32", - "SENSORAVG33", - "SENSORAVG34", - "SENSORAVG35", - "SENSORAVG36", - "SENSORAVG37", - "SENSORAVG38", - "SENSORAVG39", - "SENSORAVG40", - "SENSORAVG41", - "SENSORAVG42", - "SENSORAVG43", - "SENSORAVG44", - "SENSORAVG45", - "SENSORAVG46", - "SENSORAVG47", - "SENSORAVG48", - "SENSORAVG49", - "SENSORAVG50", - }; + #region step7. 將 sensoravg INSERT 到 sensoravg_history_hour 資料表 + List sensoravg_history_properties = new List() + { + "PowerStationId", + "TIMESTAMP", + "SENSORAVG01", + "SENSORAVG02", + "SENSORAVG03", + "SENSORAVG04", + "SENSORAVG05", + "SENSORAVG06", + "SENSORAVG07", + "SENSORAVG08", + "SENSORAVG09", + "SENSORAVG10", + "SENSORAVG11", + "SENSORAVG12", + "SENSORAVG13", + "SENSORAVG14", + "SENSORAVG15", + "SENSORAVG16", + "SENSORAVG17", + "SENSORAVG18", + "SENSORAVG19", + "SENSORAVG20", + "SENSORAVG21", + "SENSORAVG22", + "SENSORAVG23", + "SENSORAVG24", + "SENSORAVG25", + "SENSORAVG26", + "SENSORAVG27", + "SENSORAVG28", + "SENSORAVG29", + "SENSORAVG30", + "SENSORAVG31", + "SENSORAVG32", + "SENSORAVG33", + "SENSORAVG34", + "SENSORAVG35", + "SENSORAVG36", + "SENSORAVG37", + "SENSORAVG38", + "SENSORAVG39", + "SENSORAVG40", + "SENSORAVG41", + "SENSORAVG42", + "SENSORAVG43", + "SENSORAVG44", + "SENSORAVG45", + "SENSORAVG46", + "SENSORAVG47", + "SENSORAVG48", + "SENSORAVG49", + "SENSORAVG50", + }; + + await powerStationRepository.AddSensorAvgHistory(sensorAvgHistoryHour, sensoravg_history_properties); + #endregion + + #region step8. 新增天氣資訊 + List weather_observation_properties = new List() + { + "PowerStationId", + "ObsTime", + "Temp" + }; + await powerStationRepository.AddWeatherObservation(weatherObservations, weather_observation_properties); + #endregion + } - await powerStationRepository.AddSensorAvgHistory(sensorAvgHistoryHour, sensoravg_history_properties); - #endregion - List weather_observation_properties = new List() - { - "PowerStationId", - "ObsTime", - "Temp" - }; - await powerStationRepository.AddWeatherObservation(weatherObservations, weather_observation_properties); logger.LogInformation("【CalcPowerStationJob】【任務完成】"); } diff --git a/SolarPower/Repository/Implement/ElectricitySoldRecordRepository.cs b/SolarPower/Repository/Implement/ElectricitySoldRecordRepository.cs index d6b6c7f..1fdec5a 100644 --- a/SolarPower/Repository/Implement/ElectricitySoldRecordRepository.cs +++ b/SolarPower/Repository/Implement/ElectricitySoldRecordRepository.cs @@ -34,7 +34,7 @@ namespace SolarPower.Repository.Implement post.Time = post.Time.Replace("-", "~"); post.Time = post.Time.Replace("/", "-"); var time = post.Time.Split("~"); - sql = @$"SELECT es.`*`,ps.Name AS PowerStationName FROM electricity_sold_record es + sql = @$"SELECT es.*,ps.Name AS PowerStationName FROM electricity_sold_record es LEFT JOIN power_station ps ON es.PowerstationId = ps.Id WHERE es.StartAt BETWEEN '{time[0]}' AND '{time[1]}' AND es.PowerstationId IN @ids AND es.Deleted = 0"; break; @@ -43,18 +43,17 @@ namespace SolarPower.Repository.Implement post.Time = post.Time.Replace("-", "~"); post.Time = post.Time.Replace("/", "-"); var time1 = post.Time.Split("~"); - sql = @$"SELECT es.`*`,ps.Name AS PowerStationName FROM electricity_sold_record es + sql = @$"SELECT es.*,ps.Name AS PowerStationName FROM electricity_sold_record es LEFT JOIN power_station ps ON es.PowerstationId = ps.Id WHERE es.StartAt BETWEEN '{time1[0]}' AND '{time1[1]}' AND es.PowerstationId IN @ids AND es.Deleted = 0"; - sql = ""; break; case 2: - sql = @$"SELECT es.`*`,ps.Name AS PowerStationName FROM electricity_sold_record es + sql = @$"SELECT es.*,ps.Name AS PowerStationName FROM electricity_sold_record es LEFT JOIN power_station ps ON es.PowerstationId = ps.Id WHERE DATE_FORMAT(es.StartAt , '%Y-%m') = '{post.Time}' AND es.PowerstationId IN @ids AND es.Deleted = 0"; break; case 3: - sql = @$"SELECT es.`*`,ps.Name AS PowerStationName FROM electricity_sold_record es + sql = @$"SELECT es.*,ps.Name AS PowerStationName FROM electricity_sold_record es LEFT JOIN power_station ps ON es.PowerstationId = ps.Id WHERE DATE_FORMAT(es.StartAt , '%Y') = '{post.Time}' AND es.PowerstationId IN @ids AND es.Deleted = 0"; break; diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index f155e30..c6233f1 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -3710,16 +3710,26 @@ namespace SolarPower.Repository.Implement } } - public async Task> GetPowerStationsByCompanyId(int companyId) + public async Task> GetPowerStationsByCompanyId(MyUser myUser) { List result; using (IDbConnection conn = this._databaseHelper.GetConnection()) { try { - var sql = $"SELECT * FROM {tableName} WHERE Deleted = 0 AND CompanyId = @CompanyId"; + var sql = $"SELECT * FROM {tableName} ps"; - result = (await conn.QueryAsync(sql, new { CompanyId = companyId })).ToList(); + if (myUser.Role.Layer == 2) + { + sql += " WHERE ps.Deleted = 0 AND ps.CompanyId = @CompanyId "; + } + else + { + sql += @" LEFT JOIN power_station_operation_personnel op ON ps.Id = op.PowerStationId + WHERE ps.Deleted = 0 AND op.Deleted = 0 AND op.UserId = @UserId "; + } + + result = (await conn.QueryAsync(sql, new { CompanyId = myUser.CompanyId, UserId = myUser.Id })).ToList(); } catch (Exception exception) { diff --git a/SolarPower/Repository/Implement/StationReportRepository.cs b/SolarPower/Repository/Implement/StationReportRepository.cs index f9b407f..16d528d 100644 --- a/SolarPower/Repository/Implement/StationReportRepository.cs +++ b/SolarPower/Repository/Implement/StationReportRepository.cs @@ -265,13 +265,15 @@ namespace SolarPower.Repository.Implement a.Name AS 'AreaName', ps.Name AS 'PowerstationName', ps.SiteDB AS 'PowerstationDB', + ps.SolarType AS 'PowerstationType', + ps.Id as 'PowerStationId', n.* FROM power_station ps LEFT JOIN city c ON c.Id = ps.CityId LEFT JOIN area a ON a.Id = ps.AreaId left JOIN ( - SELECT SUM(a.SolarHour) SolarHour,SUM(a.Kwh) Kwh,AVG(b.PR) AvgPR,AVG(b.KWHKWP) AvgKWHKWP,AVG(c.Irradiance) AvgIrradiance,a.PowerStationId FROM + SELECT SUM(a.SolarHour) SolarHour,SUM(a.Kwh) Kwh,AVG(b.PR) AvgPR,AVG(b.KWHKWP) AvgKWHKWP,AVG(c.Irradiance) AvgIrradiance,SUM(b.TodayMoney) as 'TodayMoney',a.PowerStationId FROM ( SELECT Max(ps.SOLARHOUR) AS 'SolarHour',MAX(ps.TODAYKWH) 'Kwh' ,DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d ') AS 'time', ps.PowerStationId FROM power_station_history_hour ps @@ -280,7 +282,7 @@ namespace SolarPower.Repository.Implement ) a left JOIN ( - SELECT B.PR ,B.KWHKWP, DATE_FORMAT(A.bb,'%Y-%m-%d') time FROM + SELECT B.PR ,B.KWHKWP,B.TODAYMONEY AS 'TodayMoney', DATE_FORMAT(A.bb,'%Y-%m-%d') time FROM ( SELECT Max(ps.TIMESTAMP) AS bb FROM power_station_history_hour ps WHERE ps.PowerStationId IN @ids {wheretime} diff --git a/SolarPower/Repository/Interface/IPowerStationRepository.cs b/SolarPower/Repository/Interface/IPowerStationRepository.cs index 4fdd185..bf48ec1 100644 --- a/SolarPower/Repository/Interface/IPowerStationRepository.cs +++ b/SolarPower/Repository/Interface/IPowerStationRepository.cs @@ -546,7 +546,7 @@ namespace SolarPower.Repository.Interface Task CalcSensorAvgHistoryMonthDataByPowerStationId(string month, int powerStationId); Task AddSensorAvgHistoryMonthList(List entity, List properties); Task UpdateSensorAvgHistoryMonthList(List entity); - Task> GetPowerStationsByCompanyId(int companyId); + Task> GetPowerStationsByCompanyId(MyUser myUser); Task> GetPowerStationInverter(Dictionary> dic, string filter); Task> GetPowerStationDevice(Dictionary> dic, string filter); Task> GetInverterHistoryRowData(string nowDay, List entities); diff --git a/SolarPower/Views/AnalysisInverter/Index.cshtml b/SolarPower/Views/AnalysisInverter/Index.cshtml index 76adb1f..5675d47 100644 --- a/SolarPower/Views/AnalysisInverter/Index.cshtml +++ b/SolarPower/Views/AnalysisInverter/Index.cshtml @@ -21,7 +21,10 @@
@@ -217,7 +220,7 @@ PushSpecifyCurrentCompareCol(Single_day_compare_col); }) - function myfunc(div) { + @*function myfunc(div) { var className = div.getAttribute("class"); if (className == "fal fa-angle-left fa-lg py-3") { div.className = "fal fa-angle-right fa-lg py-3"; @@ -225,7 +228,7 @@ else { div.className = "fal fa-angle-left fa-lg py-3"; } - } + }*@ //#region 更換搜尋條件(日,日區間,月,年) function changeType(type, e) { diff --git a/SolarPower/Views/AnalysisStationCombine/Index.cshtml b/SolarPower/Views/AnalysisStationCombine/Index.cshtml index a9c6d13..6016f8c 100644 --- a/SolarPower/Views/AnalysisStationCombine/Index.cshtml +++ b/SolarPower/Views/AnalysisStationCombine/Index.cshtml @@ -25,7 +25,10 @@
@@ -591,7 +594,7 @@ //#endregion //#region 左邊的搜索欄位 - function myfunc(div) { + @*function myfunc(div) { var className = div.getAttribute("class"); if (className == "fal fa-angle-left fa-lg py-3") { div.className = "fal fa-angle-right fa-lg py-3"; @@ -599,7 +602,7 @@ else { div.className = "fal fa-angle-left fa-lg py-3"; } - } + }*@ $("#js_list_accordion_filter").change(function (e) { GetPowerStationCollapse($(this).val()); diff --git a/SolarPower/Views/AnalysisStationInfo/Index.cshtml b/SolarPower/Views/AnalysisStationInfo/Index.cshtml index 4937d55..29884d6 100644 --- a/SolarPower/Views/AnalysisStationInfo/Index.cshtml +++ b/SolarPower/Views/AnalysisStationInfo/Index.cshtml @@ -21,7 +21,10 @@
@@ -166,7 +169,7 @@ //#endregion }) - function myfunc(div) { + @*function myfunc(div) { var className = div.getAttribute("class"); if (className == "fal fa-angle-left fa-lg py-3") { div.className = "fal fa-angle-right fa-lg py-3"; @@ -174,7 +177,7 @@ else { div.className = "fal fa-angle-left fa-lg py-3"; } - } + }*@ //#region 更換搜尋條件(日,日區間,月,年) function changeType(type, e) { @@ -444,7 +447,7 @@ $.post(url, send_data, function (rel) { if (rel.code != "0000") { - toast_error(rel.data.msg); + toast_error(rel.msg); return; } diff --git a/SolarPower/Views/ElectricitySoldRecord/Index.cshtml b/SolarPower/Views/ElectricitySoldRecord/Index.cshtml index 32788f1..cb2ad94 100644 --- a/SolarPower/Views/ElectricitySoldRecord/Index.cshtml +++ b/SolarPower/Views/ElectricitySoldRecord/Index.cshtml @@ -594,7 +594,7 @@ } function Searchform() { - console.log(selecterd_powerstationId); +/* console.log(selecterd_powerstationId);*/ if (searchType == 0 || searchType == 1) { timerange = $('#DateGettext').val(); } diff --git a/SolarPower/Views/PowerStation/_StationInfo.cshtml b/SolarPower/Views/PowerStation/_StationInfo.cshtml index 088d8d9..b0ba183 100644 --- a/SolarPower/Views/PowerStation/_StationInfo.cshtml +++ b/SolarPower/Views/PowerStation/_StationInfo.cshtml @@ -187,7 +187,7 @@ -
+
@*
逆變器
@@ -216,31 +216,31 @@
*@ -
+
光電板
-
+
-
+
-
+
-
+
diff --git a/SolarPower/Views/StationOverview/StationOverviewInfo.cshtml b/SolarPower/Views/StationOverview/StationOverviewInfo.cshtml index 9980a74..19a2208 100644 --- a/SolarPower/Views/StationOverview/StationOverviewInfo.cshtml +++ b/SolarPower/Views/StationOverview/StationOverviewInfo.cshtml @@ -2403,53 +2403,41 @@ pointHoverRadius: 5, fill: false, data: listtemperature - },{ + }, { type: 'line', + label: '日照度(kWh/㎡)', + yAxisID: 'B', + borderColor: 'rgba(190, 45, 45,1)', + pointBackgroundColor: 'rgb(190, 45, 45,1)', + pointBorderColor: 'rgb(190, 45, 45,1)', + pointBorderWidth: 1, + borderWidth: 2, + pointRadius: 4, + pointHoverRadius: 5, + fill: false, + data: listirradiance + },{ + type: 'bar', label: 'PR(%)', yAxisID: 'D', - borderColor: 'rgba(68, 114, 196)', - pointBackgroundColor: 'rgb(68, 114, 196)', - pointBorderColor: 'rgb(68, 114, 196)', - pointBorderWidth: 1, - borderWidth: 2, - pointRadius: 4, - pointHoverRadius: 5, - fill: false, + backgroundColor: 'rgba(68, 114, 196)', + borderWidth: 1, data: listpr },{ - type: 'line', + type: 'bar', label: '發電小時', yAxisID: 'C', - borderColor: 'rgba(165, 165, 165)', - pointBackgroundColor: 'rgb(165, 165, 165)', - pointBorderColor: 'rgb(165, 165, 165)', - pointBorderWidth: 1, - borderWidth: 2, - pointRadius: 4, - pointHoverRadius: 5, - fill: false, + backgroundColor: 'rgba(165, 165, 165)', + borderWidth: 1, data: listsolarhour },{ - type: 'line', - label: '日照度(kWh/㎡)', - yAxisID: 'B', - borderColor: 'rgba(190, 45, 45,1)', - pointBackgroundColor: 'rgb(190, 45, 45,1)', - pointBorderColor: 'rgb(190, 45, 45,1)', - pointBorderWidth: 1, - borderWidth: 2, - pointRadius: 4, - pointHoverRadius: 5, - fill: false, - data: listirradiance - }, { - type: 'bar', - backgroundColor: 'rgba(103, 180, 172, 1)', - borderWidth: 1, - label: '發電量(kWh)', - yAxisID: 'A', - data: listkwh - }] + type: 'bar', + backgroundColor: 'rgba(103, 180, 172, 1)', + borderWidth: 1, + label: '發電量(kWh)', + yAxisID: 'A', + data: listkwh + }] }, options: { title: { diff --git a/SolarPower/Views/StationOverview/_Info.cshtml b/SolarPower/Views/StationOverview/_Info.cshtml index 269da22..a024541 100644 --- a/SolarPower/Views/StationOverview/_Info.cshtml +++ b/SolarPower/Views/StationOverview/_Info.cshtml @@ -157,29 +157,29 @@
-
-
+
+
光電板
-
+
-
+
-
+
-
+
diff --git a/SolarPower/Views/StationReport/Index.cshtml b/SolarPower/Views/StationReport/Index.cshtml index f5bcebc..d8d1c07 100644 --- a/SolarPower/Views/StationReport/Index.cshtml +++ b/SolarPower/Views/StationReport/Index.cshtml @@ -166,7 +166,10 @@
@@ -298,6 +301,7 @@ var nowpowerstation = null;//選擇電站 var haveinvertName = []; var nowform; + var xxx; $(function () { //#region 預設初始值 @@ -513,7 +517,7 @@ //#endregion //#region 左邊的搜索欄位 - function myfunc(div) { + @*function myfunc(div) { var className = div.getAttribute("class"); if (className == "fal fa-angle-left fa-lg py-3") { div.className = "fal fa-angle-right fa-lg py-3"; @@ -521,7 +525,7 @@ else { div.className = "fal fa-angle-left fa-lg py-3"; } - } + }*@ $("#js_list_accordion_filter").change(function (e) { GetPowerStationCollapse($(this).val()); @@ -943,8 +947,16 @@ FormType: nowform, PowerStation: selecterd_invert } - if (send_data.FormType != null && send_data.PowerStation.length != 0) { + if (send_data.FormType != null && send_data.PowerStation.length != 0 && send_data.FormType != 2) { window.location = "/StationReport/ExportExcel?post=" + JSON.stringify(send_data); + } else { + if (send_data.FormType != 2) { + toast_warning("請先選擇電站及報表類型"); + } + } + + if (send_data.PowerStation.length != 0 && send_data.FormType == 2) { + window.location = "/StationReport/ExportExcelmaxtable?post=" + JSON.stringify(send_data); } else { toast_warning("請先選擇電站及報表類型"); } @@ -974,6 +986,12 @@ } //下方 $.each(rel.data, function (index, data) { + var hirerate = 0; + if (data.powerstationType == 1) + { + hirerate = hire(data.powerstationDB, data.powerstationId); + } + var cityinfo = { city: data.cityName, kwp: data.kwh, @@ -1007,6 +1025,16 @@ StrInfoBody += "" + data.solarHour.toFixed(2) + ""; StrInfoBody += "" + data.avgIrradiance.toFixed(2) + ""; StrInfoBody += "" + data.avgPR.toFixed(2) + ""; + if (showmoney == 1) { + StrInfoBody += "" + data.todayMoney.toFixed(2) + ""; + + StrInfoBody += "" + (data.todayMoney * hirerate * 0.01).toFixed(2)+ ""; + + StrInfoBody += "" + data.todayMoney.toFixed(2) + ""; + } + + + StrInfoBody += ""; kwp += data.kwh; kwhkwp += data.avgKWHKWP; @@ -1051,5 +1079,61 @@ nowform = 2; }) } + + + function hire(db, id) + { + var hirerate = 0; + var dataTosent = + { + Sitedb: db, + PowerstationId: id + } + var posturl = "/StationReport/GetHireInfo"; + $.ajax({ + url: posturl, + type: "POST",//'GET', + dataType: 'json', + data: dataTosent, // 輸入的資料 + cache: false, + async: false, + success: function (response) { + $.each(response.data, function (index, value) { + hirerate += Number(value.leaseRate); + }) + } + }); + + + + + + //await $.post(posturl, dataTosent, function (rel) { + + // if (rel.code != "0000") { + // out_reject(); + // toast_error(rel.data.msg); + // return; + // } + + //}).promise(); + + return hirerate; + //return new Promise(function (out_resolve, out_reject) { + // $.post(posturl, dataTosent, function (rel) { + + // if (rel.code != "0000") { + // out_reject(); + // toast_error(rel.data.msg); + // return; + // } + // $.each(rel.data, function (index, value) { + // hirerate += Number(value.leaseRate); + // }) + // out_resolve(hirerate); + // }) + //}); + } + } \ No newline at end of file