This commit is contained in:
cesar liu 2022-08-17 09:40:31 +08:00
commit a759f1e58d
36 changed files with 978 additions and 836 deletions

View File

@ -12,6 +12,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Transactions; using System.Transactions;
using System.Text.RegularExpressions;
namespace SolarPower.Controllers namespace SolarPower.Controllers
{ {
@ -676,6 +677,8 @@ namespace SolarPower.Controllers
_ => "" _ => ""
}; };
var user = await userRepository.GetOneAsync(person); var user = await userRepository.GetOneAsync(person);
if (user.Email != null && IsValidEmail(user.Email))
{
NoticeSchedule schedule = new NoticeSchedule() NoticeSchedule schedule = new NoticeSchedule()
{ {
EmailType = 3, EmailType = 3,
@ -688,6 +691,7 @@ namespace SolarPower.Controllers
}; };
noticeSchedules.Add(schedule); noticeSchedules.Add(schedule);
} }
}
properties = new List<string>() properties = new List<string>()
{ {
"UserId", "UserId",
@ -699,8 +703,11 @@ namespace SolarPower.Controllers
"Type", "Type",
"ExceptionId" "ExceptionId"
}; };
if (noticeSchedules.Count > 0)
{
await noticeScheduleRepository.AddAnyThing<List<NoticeSchedule>>(noticeSchedules, properties, "notice_schedule"); await noticeScheduleRepository.AddAnyThing<List<NoticeSchedule>>(noticeSchedules, properties, "notice_schedule");
} }
}
if (post.FixFirm != 0) if (post.FixFirm != 0)
{ {
@ -714,6 +721,8 @@ namespace SolarPower.Controllers
}; };
//var powerstation = await powerStationRepository.GetOneAsync(post.PowerStationId); //var powerstation = await powerStationRepository.GetOneAsync(post.PowerStationId);
var firm = await operationRepository.GetOneWithCustomDBNameAndTableAsync<OperationInfo>(post.FixFirm, powerstations.SiteDB, "operation_firm"); var firm = await operationRepository.GetOneWithCustomDBNameAndTableAsync<OperationInfo>(post.FixFirm, powerstations.SiteDB, "operation_firm");
if (firm.Email != null && IsValidEmail(firm.Email))
{
NoticeSchedule schedule = new NoticeSchedule() NoticeSchedule schedule = new NoticeSchedule()
{ {
EmailType = 3, EmailType = 3,
@ -723,6 +732,7 @@ namespace SolarPower.Controllers
Subject = powerstations.Name + "-" + fixtype + "-" + post.WorkTime, Subject = powerstations.Name + "-" + fixtype + "-" + post.WorkTime,
Content = "維修項目" + post.FixDo + "</br>注意事項 :" + post.Notice, Content = "維修項目" + post.FixDo + "</br>注意事項 :" + post.Notice,
}; };
properties = new List<string>() properties = new List<string>()
{ {
"UserId", "UserId",
@ -737,6 +747,7 @@ namespace SolarPower.Controllers
await noticeScheduleRepository.AddAnyThing<NoticeSchedule>(schedule, properties, "notice_schedule"); await noticeScheduleRepository.AddAnyThing<NoticeSchedule>(schedule, properties, "notice_schedule");
} }
} }
}
//using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Suppress)) //using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Suppress))
//{ //{
@ -898,6 +909,8 @@ namespace SolarPower.Controllers
_ => "" _ => ""
}; };
var user = await userRepository.GetOneAsync(person); var user = await userRepository.GetOneAsync(person);
if (user.Email != null && IsValidEmail(user.Email))
{
NoticeSchedule schedule = new NoticeSchedule() NoticeSchedule schedule = new NoticeSchedule()
{ {
EmailType = 3, EmailType = 3,
@ -910,6 +923,7 @@ namespace SolarPower.Controllers
}; };
noticeSchedules.Add(schedule); noticeSchedules.Add(schedule);
} }
}
properties = new List<string>() properties = new List<string>()
{ {
"UserId", "UserId",
@ -921,8 +935,11 @@ namespace SolarPower.Controllers
"Type", "Type",
"ExceptionId" "ExceptionId"
}; };
if (noticeSchedules.Count > 0)
{
await noticeScheduleRepository.AddAnyThing<List<NoticeSchedule>>(noticeSchedules, properties, "notice_schedule"); await noticeScheduleRepository.AddAnyThing<List<NoticeSchedule>>(noticeSchedules, properties, "notice_schedule");
} }
}
if (post.FixFirm != 0) if (post.FixFirm != 0)
{ {
//var powerstations = await powerStationRepository.GetOneAsync(post.PowerStationId); //var powerstations = await powerStationRepository.GetOneAsync(post.PowerStationId);
@ -935,6 +952,8 @@ namespace SolarPower.Controllers
}; };
// var powerstation = await powerStationRepository.GetOneAsync(post.PowerStationId); // var powerstation = await powerStationRepository.GetOneAsync(post.PowerStationId);
var firm = await operationRepository.GetOneWithCustomDBNameAndTableAsync<OperationInfo>(post.FixFirm, powerstations.SiteDB, "operation_firm"); var firm = await operationRepository.GetOneWithCustomDBNameAndTableAsync<OperationInfo>(post.FixFirm, powerstations.SiteDB, "operation_firm");
if (firm.Email != null && IsValidEmail(firm.Email))
{
NoticeSchedule schedule = new NoticeSchedule() NoticeSchedule schedule = new NoticeSchedule()
{ {
EmailType = 3, EmailType = 3,
@ -944,6 +963,7 @@ namespace SolarPower.Controllers
Subject = powerstations.Name + "-" + fixtype + "-" + post.WorkTime, Subject = powerstations.Name + "-" + fixtype + "-" + post.WorkTime,
Content = "維修項目:" + post.FixDo + "</br>注意事項 :" + post.Notice, Content = "維修項目:" + post.FixDo + "</br>注意事項 :" + post.Notice,
}; };
properties = new List<string>() properties = new List<string>()
{ {
"UserId", "UserId",
@ -956,8 +976,7 @@ namespace SolarPower.Controllers
"ExceptionId" "ExceptionId"
}; };
await noticeScheduleRepository.AddAnyThing<NoticeSchedule>(schedule, properties, "notice_schedule"); await noticeScheduleRepository.AddAnyThing<NoticeSchedule>(schedule, properties, "notice_schedule");
}
} }
} }
@ -1325,5 +1344,11 @@ namespace SolarPower.Controllers
} }
} }
bool IsValidEmail(string strIn)
{
// Return true if strIn is in valid e-mail format.
return Regex.IsMatch(strIn, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
}
} }
} }

View File

@ -1177,7 +1177,9 @@ namespace SolarPower.Controllers
"Status", "Status",
"Enabled", "Enabled",
"InstallDate", "InstallDate",
"BrandNum" "BrandNum",
"SensorTypeId",
"SensorTypeDetailId"
}; };
if (Device.WarrantyDate != "0001-01-01") if (Device.WarrantyDate != "0001-01-01")
{ {
@ -1246,7 +1248,9 @@ namespace SolarPower.Controllers
"Status", "Status",
"Enabled", "Enabled",
"InstallDate", "InstallDate",
"BrandNum" "BrandNum",
"SensorTypeId",
"SensorTypeDetailId"
}; };
if (Device.WarrantyDate != "0001-01-01") if (Device.WarrantyDate != "0001-01-01")
{ {
@ -2474,6 +2478,27 @@ namespace SolarPower.Controllers
} }
await powerStationRepository.AddInverter(inverter, properties, powerStation.SiteDB); await powerStationRepository.AddInverter(inverter, properties, powerStation.SiteDB);
#region master底下的inv_Status inverter
InverterForMaster inverterForMasterInvs = new InverterForMaster()
{
DBName = powerStation.SiteDB,
InverterId = deviceController.ControllerId + Newnum,
Deleted = 0,
Enabled = post.Enabled,
Status = post.Status
};
List<string> propertiesForMasterInvs = new List<string>()
{
"DBName",
"InverterId",
"Deleted",
"Enabled",
"Status"
};
await powerStationRepository.AddMasterInverter(inverterForMasterInvs, propertiesForMasterInvs);
#endregion
BackFillSchedule backFillSchedule = new BackFillSchedule() BackFillSchedule backFillSchedule = new BackFillSchedule()
{ {
UID = deviceController.ControllerId + Newnum, UID = deviceController.ControllerId + Newnum,
@ -2537,6 +2562,26 @@ namespace SolarPower.Controllers
properties.Add("WarrantyDate"); properties.Add("WarrantyDate");
} }
await powerStationRepository.UpdateInverter(inverter, properties, powerStation.SiteDB); await powerStationRepository.UpdateInverter(inverter, properties, powerStation.SiteDB);
#region master底下的inv_Status更新inverter
InverterForMaster inverterForMasterInvs = new InverterForMaster()
{
DBName = powerStation.SiteDB,
Enabled = post.Enabled,
Status = post.Status,
Id = post.Id
};
List<string> propertiesForMasterInvs = new List<string>()
{
"DBName",
"Enabled",
"Status",
"Id"
};
await powerStationRepository.UpdateMasterInverter(inverterForMasterInvs, propertiesForMasterInvs);
#endregion
await powerStationRepository.StationStatus(post.PowerStationId, 0); await powerStationRepository.StationStatus(post.PowerStationId, 0);
await powerStationRepository.StationStatus(post.PowerStationId, 0, powerStation.SiteDB + "."); await powerStationRepository.StationStatus(post.PowerStationId, 0, powerStation.SiteDB + ".");
apiResult.Code = "0000"; apiResult.Code = "0000";
@ -2659,6 +2704,15 @@ namespace SolarPower.Controllers
await powerStationRepository.DeleteOneByIdWithCustomDBNameAndTable(post.SelectedId, powerStation.SiteDB, "inverter"); await powerStationRepository.DeleteOneByIdWithCustomDBNameAndTable(post.SelectedId, powerStation.SiteDB, "inverter");
var inverter = await powerStationRepository.GetOneMasterInverter(post.SelectedId, powerStation.SiteDB);
if (inverter == null )
{
apiResult.Code = "0001";
apiResult.Msg = "該電站沒有啟用的逆變器";
return apiResult;
}
await powerStationRepository.DeleteOneMasterInverter(inverter.InverterId, "inv_status");
apiResult.Code = "0000"; apiResult.Code = "0000";
apiResult.Msg = "刪除成功"; apiResult.Msg = "刪除成功";
} }
@ -2997,7 +3051,7 @@ namespace SolarPower.Controllers
apiResult.Msg = "該電站沒有啟用的逆變器"; apiResult.Msg = "該電站沒有啟用的逆變器";
return apiResult; return apiResult;
} }
var inverterIds = inverters.Where(x => x.Enabled == 1).Select(x => new { InverterId = x.InverterId, Type = x.Status,Name = x.InverterName}).ToList(); var inverterIds = inverters.Where(x => x.Enabled == 1).Select(x => new { InverterId = x.InverterId, Type = x.InverterStatus, Name = x.InverterName}).ToList();
var inverterIdsname = inverterIds.Select(x => x.InverterId).ToList(); var inverterIdsname = inverterIds.Select(x => x.InverterId).ToList();
if (inverterIds.Count > 0) if (inverterIds.Count > 0)
{ {
@ -3271,7 +3325,7 @@ namespace SolarPower.Controllers
{ {
status.Add($"s{powerStation.Code}01_inv SITEID錯誤"); status.Add($"s{powerStation.Code}01_inv SITEID錯誤");
} }
if (powerStation.Code + "01" != sitecheck.Inv_inveter.Substring(0,11) && sitecheck.Inv_inveter != null) if (sitecheck.Inv_inveter != null && powerStation.Code + "01" != sitecheck.Inv_inveter.Substring(0,11))
{ {
status.Add($"s{powerStation.Code}01_Inv inveter格式錯誤"); status.Add($"s{powerStation.Code}01_Inv inveter格式錯誤");
} }

View File

@ -267,10 +267,14 @@ namespace SolarPower.Controllers
#region body //RowPosition = 1 #region body //RowPosition = 1
RowPosition++; RowPosition++;
var thour = ""; var tpr = ""; var tkwh = ""; var kWhkwp = ""; var ntd = ""; var ntdone = "";var GeneratingCapacity = "";var AverageDailyProfit = ""; var thour = ""; var tpr = ""; var tkwh = ""; var kWhkwp = ""; var ntd = ""; var ntdone = "";var GeneratingCapacity = "";var AverageDailyProfit = "";
int vForDataCount = 0;
foreach (dynamic body in Formbody.Result.Data) foreach (dynamic body in Formbody.Result.Data)
{ {
index = 0; index = 0;
var dbody = body as IDictionary<string, object>; var dbody = body as IDictionary<string, object>;
if (vForDataCount < (Formbody.Result.Data.Count - 1))//最後一筆(總計),不須取值
{
vForDataCount++;
thour = Checknull(Math.Round(Convert.ToDouble(dbody["tothour"]), 2).ToString()); thour = Checknull(Math.Round(Convert.ToDouble(dbody["tothour"]), 2).ToString());
tpr = Checknull(Math.Round(Convert.ToDouble(dbody["pr"]), 2).ToString()); tpr = Checknull(Math.Round(Convert.ToDouble(dbody["pr"]), 2).ToString());
tkwh = Checknull(Math.Round(Convert.ToDouble(dbody["totKWH"]), 2).ToString()); tkwh = Checknull(Math.Round(Convert.ToDouble(dbody["totKWH"]), 2).ToString());
@ -278,13 +282,17 @@ namespace SolarPower.Controllers
ntd = Checknull(Math.Round(Convert.ToDouble(dbody["totmoney"]), 2).ToString()); ntd = Checknull(Math.Round(Convert.ToDouble(dbody["totmoney"]), 2).ToString());
GeneratingCapacity = Checknull(Math.Round(Convert.ToDouble(dbody["GeneratingCapacity"]), 2).ToString()); GeneratingCapacity = Checknull(Math.Round(Convert.ToDouble(dbody["GeneratingCapacity"]), 2).ToString());
double kwp = Convert.ToDouble(tkwh) / Convert.ToDouble(GeneratingCapacity);
kWhkwp = Checknull(Math.Round(kwp, 2).ToString());
double onemoney = Convert.ToDouble(ntd) / Convert.ToDouble(tkwh); double onemoney = Convert.ToDouble(ntd) / Convert.ToDouble(tkwh);
if (double.IsNaN(onemoney)) if (double.IsNaN(onemoney))
{ {
onemoney = 0; onemoney = 0;
} }
ntdone = Checknull(Math.Round(onemoney, 4).ToString()); ntdone = Checknull(Math.Round(onemoney, 2).ToString());
AverageDailyProfit = Checknull(Math.Round((Convert.ToDouble(ntd) / Convert.ToDouble(GeneratingCapacity)), 2).ToString()); AverageDailyProfit = Checknull(Math.Round((Convert.ToDouble(ntd) / Convert.ToDouble(GeneratingCapacity)), 2).ToString());
}
row = sheet.CreateRow(RowPosition); row = sheet.CreateRow(RowPosition);
cell = row.CreateCell(index); cell = row.CreateCell(index);
@ -302,7 +310,7 @@ namespace SolarPower.Controllers
List<string> bodynames = new List<string>(){ List<string> bodynames = new List<string>(){
"hourKWH", "hourKWH",
"hourKWHp", "hourKWHp",
"irradiance", "irrDayHour",
"temperature" "temperature"
}; };
if (Formhead.Result.Data.ShowMoney == 1) if (Formhead.Result.Data.ShowMoney == 1)
@ -467,11 +475,14 @@ namespace SolarPower.Controllers
var monthGeneratingCapacity = ""; var monthGeneratingCapacity = "";
var check_hire = false; var check_hire = false;
var sitedb = ""; var sitedb = "";
vForDataCount = 0;
foreach (dynamic body in Formbody.Result.Data) foreach (dynamic body in Formbody.Result.Data)
{ {
index2 = 0; index2 = 0;
var dbody = body as IDictionary<string, object>; var dbody = body as IDictionary<string, object>;
if (vForDataCount < (Formbody.Result.Data.Count - 1))//最後一筆(總計),不須取值
{
vForDataCount++;
avghour = (Convert.ToDouble(dbody["tothour"].ToString()) + Convert.ToDouble(avghour)).ToString(); avghour = (Convert.ToDouble(dbody["tothour"].ToString()) + Convert.ToDouble(avghour)).ToString();
avgKWHKWP = (Convert.ToDouble(dbody["KWHKWP"].ToString()) + Convert.ToDouble(avgKWHKWP)).ToString(); avgKWHKWP = (Convert.ToDouble(dbody["KWHKWP"].ToString()) + Convert.ToDouble(avgKWHKWP)).ToString();
avgdayKWH = (Convert.ToDouble(dbody["dayKWH"].ToString()) + Convert.ToDouble(avgdayKWH)).ToString(); avgdayKWH = (Convert.ToDouble(dbody["dayKWH"].ToString()) + Convert.ToDouble(avgdayKWH)).ToString();
@ -479,6 +490,12 @@ namespace SolarPower.Controllers
monthmoney = dbody["monthmoney"] == null ? "0" : dbody["monthmoney"].ToString(); monthmoney = dbody["monthmoney"] == null ? "0" : dbody["monthmoney"].ToString();
monthmoneyone = (Convert.ToDouble(dbody["monthmoneyone"].ToString()) + Convert.ToDouble(monthmoneyone)).ToString(); monthmoneyone = (Convert.ToDouble(dbody["monthmoneyone"].ToString()) + Convert.ToDouble(monthmoneyone)).ToString();
monthGeneratingCapacity = Checknull(Math.Round(Convert.ToDouble(dbody["GeneratingCapacity"]), 2).ToString()); monthGeneratingCapacity = Checknull(Math.Round(Convert.ToDouble(dbody["GeneratingCapacity"]), 2).ToString());
double kwp = Convert.ToDouble(monthKWH) / Convert.ToDouble(monthGeneratingCapacity);
avgKWHKWP = Checknull(Math.Round(kwp, 2).ToString());
}
if (dbody["SolarType"].ToString() == "1" && Formhead.Result.Data.ShowMoney == 1)//檢驗是否為租用 if (dbody["SolarType"].ToString() == "1" && Formhead.Result.Data.ShowMoney == 1)//檢驗是否為租用
{ {
check_hire = true; check_hire = true;
@ -533,7 +550,7 @@ namespace SolarPower.Controllers
#region //RowPosition = body + 2 #region //RowPosition = body + 2
RowPosition += 2;//空兩行 RowPosition += 2;//空兩行
index = 0; index = 0;
var Useday = Formbody.Result.Data.Count; var Useday = (Formbody.Result.Data.Count - 1);//最後一筆為總計故減1
row = sheet.CreateRow(RowPosition); row = sheet.CreateRow(RowPosition);
//cell = row.CreateCell(index); //cell = row.CreateCell(index);
@ -610,7 +627,7 @@ namespace SolarPower.Controllers
if (Formhead.Result.Data.ShowMoney == 1) if (Formhead.Result.Data.ShowMoney == 1)
{ {
cell = row.CreateCell(index); cell = row.CreateCell(index);
cell.SetCellValue(Math.Round(Convert.ToDouble(monthmoney) / Convert.ToDouble(monthGeneratingCapacity), 3)); cell.SetCellValue(Math.Round(Convert.ToDouble(monthmoney) / Convert.ToDouble(monthGeneratingCapacity), 2));
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
index++; index++;
cell = row.CreateCell(index); cell = row.CreateCell(index);
@ -618,7 +635,7 @@ namespace SolarPower.Controllers
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
index++; index++;
cell = row.CreateCell(index); cell = row.CreateCell(index);
cell.SetCellValue(Math.Round(Convert.ToDouble(monthmoneyone) / Useday, 4)); cell.SetCellValue(Math.Round(Convert.ToDouble(monthmoneyone) / Useday, 2));
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
index++; index++;
cell = row.CreateCell(index); cell = row.CreateCell(index);
@ -741,11 +758,15 @@ namespace SolarPower.Controllers
check_hire = false; check_hire = false;
sitedb = ""; sitedb = "";
monthGeneratingCapacity = ""; monthGeneratingCapacity = "";
string days = "0";
vForDataCount = 0;
foreach (dynamic body in Formbody.Result.Data) foreach (dynamic body in Formbody.Result.Data)
{ {
index3 = 0; index3 = 0;
var dbody = body as IDictionary<string, object>; var dbody = body as IDictionary<string, object>;
if (vForDataCount < (Formbody.Result.Data.Count - 1))//最後一筆(總計),不須取值
{
vForDataCount++;
avghour = (Convert.ToDouble(dbody["tothour"].ToString()) + Convert.ToDouble(avghour)).ToString(); avghour = (Convert.ToDouble(dbody["tothour"].ToString()) + Convert.ToDouble(avghour)).ToString();
avgKWHKWP = (Convert.ToDouble(dbody["KWHKWP"].ToString()) + Convert.ToDouble(avgKWHKWP)).ToString(); avgKWHKWP = (Convert.ToDouble(dbody["KWHKWP"].ToString()) + Convert.ToDouble(avgKWHKWP)).ToString();
avgdayKWH = (Convert.ToDouble(dbody["dayKWH"].ToString()) + Convert.ToDouble(avgdayKWH)).ToString(); avgdayKWH = (Convert.ToDouble(dbody["dayKWH"].ToString()) + Convert.ToDouble(avgdayKWH)).ToString();
@ -753,6 +774,8 @@ namespace SolarPower.Controllers
monthmoney = dbody["monthmoney"] == null ? "0" : dbody["monthmoney"].ToString(); monthmoney = dbody["monthmoney"] == null ? "0" : dbody["monthmoney"].ToString();
monthmoneyone = (Convert.ToDouble(dbody["monthmoneyone"].ToString()) + Convert.ToDouble(monthmoneyone)).ToString(); monthmoneyone = (Convert.ToDouble(dbody["monthmoneyone"].ToString()) + Convert.ToDouble(monthmoneyone)).ToString();
monthGeneratingCapacity = Checknull(Math.Round(Convert.ToDouble(dbody["GeneratingCapacity"]), 2).ToString()); monthGeneratingCapacity = Checknull(Math.Round(Convert.ToDouble(dbody["GeneratingCapacity"]), 2).ToString());
days = Checknull(Math.Round(Convert.ToDouble(dbody["Days"])).ToString());
}
if (dbody["SolarType"].ToString() == "1" && Formhead.Result.Data.ShowMoney == 1)//檢驗是否為租用 if (dbody["SolarType"].ToString() == "1" && Formhead.Result.Data.ShowMoney == 1)//檢驗是否為租用
{ {
check_hire = true; check_hire = true;
@ -807,7 +830,7 @@ namespace SolarPower.Controllers
#region //RowPosition = body + 2 #region //RowPosition = body + 2
RowPosition += 2;//空兩行 RowPosition += 2;//空兩行
index = 0; index = 0;
Useday = Formbody.Result.Data.Count; Useday = (Formbody.Result.Data.Count - 1);//最後一筆為總計故減1
row = sheet.CreateRow(RowPosition); row = sheet.CreateRow(RowPosition);
cell = row.CreateCell(index); cell = row.CreateCell(index);
@ -819,6 +842,10 @@ namespace SolarPower.Controllers
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
index++; index++;
cell = row.CreateCell(index); cell = row.CreateCell(index);
cell.SetCellValue("裝置容量");
cell.CellStyle = styleLine12;
index++;
cell = row.CreateCell(index);
cell.SetCellValue("發電量平均(kWh)(月)"); cell.SetCellValue("發電量平均(kWh)(月)");
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
index++; index++;
@ -856,7 +883,11 @@ namespace SolarPower.Controllers
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
index++; index++;
cell = row.CreateCell(index); cell = row.CreateCell(index);
cell.SetCellValue(Math.Round(Convert.ToDouble(avgKWHKWP) / Useday, 2)); cell.SetCellValue(Math.Round(Convert.ToDouble(monthKWH) / Convert.ToDouble(monthGeneratingCapacity), 2));
cell.CellStyle = styleLine12;
index++;
cell = row.CreateCell(index);
cell.SetCellValue(Math.Round(Convert.ToDouble(monthGeneratingCapacity), 2));///
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
index++; index++;
cell = row.CreateCell(index); cell = row.CreateCell(index);
@ -878,7 +909,7 @@ namespace SolarPower.Controllers
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
index++; index++;
cell = row.CreateCell(index); cell = row.CreateCell(index);
cell.SetCellValue(Math.Round(Convert.ToDouble(monthmoney) / Convert.ToDouble(monthGeneratingCapacity) / Useday / 30, 2));//一個月為30天 cell.SetCellValue(Math.Round(Convert.ToDouble(monthmoney) / Convert.ToDouble(monthGeneratingCapacity) / Convert.ToDouble(days), 2));//一個月為30天 Useday / 30
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
index++; index++;
} }
@ -976,7 +1007,10 @@ namespace SolarPower.Controllers
{ {
AllowClose = false AllowClose = false
}; };
string companyName = postObject.PowerStation[0].Name;
int powerStationId = int.Parse(postObject.PowerStation[0].Value);
var getCompany = stationReportRepository.GetCompanyNameByPowerStationId(powerStationId);
string companyName = getCompany.Result;
workbook.Write(ms); workbook.Write(ms);
ms.Flush(); ms.Flush();
ms.Seek(0, SeekOrigin.Begin); ms.Seek(0, SeekOrigin.Begin);
@ -1073,7 +1107,7 @@ namespace SolarPower.Controllers
var getinvsql = k.Result[0] as IDictionary<string, object>; var getinvsql = k.Result[0] as IDictionary<string, object>;
if (getinvsql["mySelect"] == null) if (getinvsql["mySelect"] == null)
{ {
if(postObject.PowerStation.Count > 1) if(postObject.PowerStation.Count > 1)//因為有總計 所以最少會有一筆
{ {
continue; continue;
} }
@ -1084,7 +1118,7 @@ namespace SolarPower.Controllers
} }
var sheet = workbook.CreateSheet(powerstationid.Name); var sheet = workbook.CreateSheet(powerstationid.Name);
var Formbody = GetForm(select_Table);//取body var Formbody = GetForm(select_Table);//取body
if(Formbody.Result.Data.Count == 0) if(Formbody.Result.Data.Count <= 1)
{ {
continue; continue;
} }
@ -1139,11 +1173,14 @@ namespace SolarPower.Controllers
#region body //RowPosition = 1 #region body //RowPosition = 1
RowPosition++; RowPosition++;
var thour = ""; var tpr = ""; var tkwh = ""; var kWhkwp = ""; var ntd = ""; var ntdone = ""; var GeneratingCapacity = ""; var AverageDailyProfit = ""; var thour = ""; var tpr = ""; var tkwh = ""; var kWhkwp = ""; var ntd = ""; var ntdone = ""; var GeneratingCapacity = ""; var AverageDailyProfit = "";
int vForDataCount = 0;
foreach (dynamic body in Formbody.Result.Data) foreach (dynamic body in Formbody.Result.Data)
{ {
index = 0; index = 0;
var dbody = body as IDictionary<string, object>; var dbody = body as IDictionary<string, object>;
if (vForDataCount < (Formbody.Result.Data.Count - 1))//最後一筆為總計,不須取值
{
vForDataCount++;
thour = Checknull(Math.Round(Convert.ToDouble(dbody["tothour"]), 2).ToString()); thour = Checknull(Math.Round(Convert.ToDouble(dbody["tothour"]), 2).ToString());
tpr = Checknull(Math.Round(Convert.ToDouble(dbody["pr"]), 2).ToString()); tpr = Checknull(Math.Round(Convert.ToDouble(dbody["pr"]), 2).ToString());
tkwh = Checknull(Math.Round(Convert.ToDouble(dbody["totKWH"]), 2).ToString()); tkwh = Checknull(Math.Round(Convert.ToDouble(dbody["totKWH"]), 2).ToString());
@ -1151,13 +1188,17 @@ namespace SolarPower.Controllers
ntd = Checknull(Math.Round(Convert.ToDouble(dbody["totmoney"]), 2).ToString()); ntd = Checknull(Math.Round(Convert.ToDouble(dbody["totmoney"]), 2).ToString());
GeneratingCapacity = Checknull(Math.Round(Convert.ToDouble(dbody["GeneratingCapacity"]), 2).ToString()); GeneratingCapacity = Checknull(Math.Round(Convert.ToDouble(dbody["GeneratingCapacity"]), 2).ToString());
double kwp = Convert.ToDouble(tkwh) / Convert.ToDouble(GeneratingCapacity);
kWhkwp = Checknull(Math.Round(kwp, 2).ToString());
double onemoney = Convert.ToDouble(ntd) / Convert.ToDouble(tkwh); double onemoney = Convert.ToDouble(ntd) / Convert.ToDouble(tkwh);
if (double.IsNaN(onemoney)) if (double.IsNaN(onemoney))
{ {
onemoney = 0; onemoney = 0;
} }
ntdone = Checknull(Math.Round(onemoney, 4).ToString()); ntdone = Checknull(Math.Round(onemoney, 2).ToString());
AverageDailyProfit = Checknull(Math.Round((Convert.ToDouble(ntd) / Convert.ToDouble(GeneratingCapacity)), 2).ToString()); AverageDailyProfit = Checknull(Math.Round((Convert.ToDouble(ntd) / Convert.ToDouble(GeneratingCapacity)), 2).ToString());
}
row = sheet.CreateRow(RowPosition); row = sheet.CreateRow(RowPosition);
cell = row.CreateCell(index); cell = row.CreateCell(index);
@ -1175,7 +1216,7 @@ namespace SolarPower.Controllers
List<string> bodynames = new List<string>(){ List<string> bodynames = new List<string>(){
"hourKWH", "hourKWH",
"hourKWHp", "hourKWHp",
"irradiance", "irrDayHour",
"temperature" "temperature"
}; };
if (Formhead.Result.Data.ShowMoney == 1) if (Formhead.Result.Data.ShowMoney == 1)
@ -1341,11 +1382,14 @@ namespace SolarPower.Controllers
var monthGeneratingCapacity = ""; var monthGeneratingCapacity = "";
var check_hire = false; var check_hire = false;
var sitedb = ""; var sitedb = "";
vForDataCount = 0;
foreach (dynamic body in Formbody.Result.Data) foreach (dynamic body in Formbody.Result.Data)
{ {
index2 = 0; index2 = 0;
var dbody = body as IDictionary<string, object>; var dbody = body as IDictionary<string, object>;
if (vForDataCount < (Formbody.Result.Data.Count - 1))//最後一筆為總計,不須取值
{
vForDataCount++;
avghour = (Convert.ToDouble(dbody["tothour"].ToString()) + Convert.ToDouble(avghour)).ToString(); avghour = (Convert.ToDouble(dbody["tothour"].ToString()) + Convert.ToDouble(avghour)).ToString();
avgKWHKWP = (Convert.ToDouble(dbody["KWHKWP"].ToString()) + Convert.ToDouble(avgKWHKWP)).ToString(); avgKWHKWP = (Convert.ToDouble(dbody["KWHKWP"].ToString()) + Convert.ToDouble(avgKWHKWP)).ToString();
avgdayKWH = (Convert.ToDouble(dbody["dayKWH"].ToString()) + Convert.ToDouble(avgdayKWH)).ToString(); avgdayKWH = (Convert.ToDouble(dbody["dayKWH"].ToString()) + Convert.ToDouble(avgdayKWH)).ToString();
@ -1353,6 +1397,11 @@ namespace SolarPower.Controllers
monthmoney = dbody["monthmoney"] == null ? "0" : dbody["monthmoney"].ToString(); monthmoney = dbody["monthmoney"] == null ? "0" : dbody["monthmoney"].ToString();
monthmoneyone = (Convert.ToDouble(dbody["monthmoneyone"].ToString()) + Convert.ToDouble(monthmoneyone)).ToString(); monthmoneyone = (Convert.ToDouble(dbody["monthmoneyone"].ToString()) + Convert.ToDouble(monthmoneyone)).ToString();
monthGeneratingCapacity = Checknull(Math.Round(Convert.ToDouble(dbody["GeneratingCapacity"]), 2).ToString()); monthGeneratingCapacity = Checknull(Math.Round(Convert.ToDouble(dbody["GeneratingCapacity"]), 2).ToString());
double kwp = Convert.ToDouble(monthKWH) / Convert.ToDouble(monthGeneratingCapacity);
avgKWHKWP = Checknull(Math.Round(kwp, 2).ToString());
}
if (dbody["SolarType"].ToString() == "1" && Formhead.Result.Data.ShowMoney == 1)//檢驗是否為租用 if (dbody["SolarType"].ToString() == "1" && Formhead.Result.Data.ShowMoney == 1)//檢驗是否為租用
{ {
check_hire = true; check_hire = true;
@ -1407,7 +1456,7 @@ namespace SolarPower.Controllers
#region //RowPosition = body + 2 #region //RowPosition = body + 2
RowPosition += 2;//空兩行 RowPosition += 2;//空兩行
index = 0; index = 0;
var Useday = Formbody.Result.Data.Count; var Useday = (Formbody.Result.Data.Count - 1);//最後一筆為總計故減1
row = sheet.CreateRow(RowPosition); row = sheet.CreateRow(RowPosition);
//cell = row.CreateCell(index); //cell = row.CreateCell(index);
@ -1484,7 +1533,7 @@ namespace SolarPower.Controllers
if (Formhead.Result.Data.ShowMoney == 1) if (Formhead.Result.Data.ShowMoney == 1)
{ {
cell = row.CreateCell(index); cell = row.CreateCell(index);
cell.SetCellValue(Math.Round(Convert.ToDouble(monthmoney) / Convert.ToDouble(monthGeneratingCapacity), 3)); cell.SetCellValue(Math.Round(Convert.ToDouble(monthmoney) / Convert.ToDouble(monthGeneratingCapacity), 2));
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
index++; index++;
cell = row.CreateCell(index); cell = row.CreateCell(index);
@ -1492,7 +1541,7 @@ namespace SolarPower.Controllers
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
index++; index++;
cell = row.CreateCell(index); cell = row.CreateCell(index);
cell.SetCellValue(Math.Round(Convert.ToDouble(monthmoneyone) / Useday, 4)); cell.SetCellValue(Math.Round(Convert.ToDouble(monthmoneyone) / Useday, 2));
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
index++; index++;
cell = row.CreateCell(index); cell = row.CreateCell(index);
@ -1591,7 +1640,9 @@ namespace SolarPower.Controllers
{ {
Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "report", Datename)); Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "report", Datename));
} }
string companyName = postObject.PowerStation[0].Name; int powerStationId = int.Parse(postObject.PowerStation[0].Value);
var getCompany = stationReportRepository.GetCompanyNameByPowerStationId(powerStationId);
string companyName = getCompany.Result;
var n = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "report", Datename, companyName + "_" + name + "報表" + "_" + postObject.Userid + Datename + ".xlsx"); var n = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "report", Datename, companyName + "_" + name + "報表" + "_" + postObject.Userid + Datename + ".xlsx");
FileStream FS = new FileStream(n, FileMode.Create, FileAccess.Write); FileStream FS = new FileStream(n, FileMode.Create, FileAccess.Write);
workbook.Write(FS); workbook.Write(FS);
@ -1732,7 +1783,7 @@ namespace SolarPower.Controllers
index++; index++;
cell = row.CreateCell(index); cell = row.CreateCell(index);
cell.SetCellValue(Math.Round(form.AvgKWHKWP, 2));//日均發電度數 cell.SetCellValue(Math.Round((form.Kwh/form.GeneratingCapacity), 2));//日均發電度數
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
index++; index++;
@ -1797,7 +1848,7 @@ namespace SolarPower.Controllers
{ {
City = form.CityName, City = form.CityName,
Count = 1, Count = 1,
Kwh = form.TotalKWH, Kwh = form.Kwh,
SolarHour = form.SolarHour, SolarHour = form.SolarHour,
Kwhkwp = form.AvgKWHKWP, Kwhkwp = form.AvgKWHKWP,
GeneratingCapacity = form.GeneratingCapacity GeneratingCapacity = form.GeneratingCapacity
@ -1829,7 +1880,7 @@ namespace SolarPower.Controllers
"電站類型", "電站類型",
"掛錶日期", "掛錶日期",
"躉售費率", "躉售費率",
"每kw日均獲利", "日均獲利",
"日均發電度數", "日均發電度數",
"發電量", "發電量",
//"平均日照", //"平均日照",
@ -1879,7 +1930,7 @@ namespace SolarPower.Controllers
index++; index++;
cell = row.CreateCell(index); cell = row.CreateCell(index);
cell.SetCellValue(Math.Round(cityArray.Kwh, 3)); cell.SetCellValue(Math.Round(cityArray.Kwh, 2));
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
region = new CellRangeAddress(cityRowPosition, cityRowPosition, index, index + 1); region = new CellRangeAddress(cityRowPosition, cityRowPosition, index, index + 1);
sheet.AddMergedRegion(region); sheet.AddMergedRegion(region);
@ -2017,7 +2068,9 @@ namespace SolarPower.Controllers
{ {
AllowClose = false AllowClose = false
}; };
string companyName = postObject.PowerStation[0].Name; int powerStationId = int.Parse(postObject.PowerStation[0].Value);
var getCompany = stationReportRepository.GetCompanyNameByPowerStationId(powerStationId);
string companyName = getCompany.Result;
workbook.Write(ms); workbook.Write(ms);
ms.Flush(); ms.Flush();
ms.Seek(0, SeekOrigin.Begin); ms.Seek(0, SeekOrigin.Begin);
@ -2236,7 +2289,7 @@ namespace SolarPower.Controllers
"電站類型", "電站類型",
"掛錶日期", "掛錶日期",
"躉售費率", "躉售費率",
"每kw日均獲利", "日均獲利",
"日均發電度數", "日均發電度數",
"發電量", "發電量",
//"平均日照", //"平均日照",
@ -2428,7 +2481,9 @@ namespace SolarPower.Controllers
{ {
Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "report", Datename)); Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "report", Datename));
} }
string companyName = postObject.PowerStation[0].Name; int powerStationId = int.Parse(postObject.PowerStation[0].Value);
var getCompany = stationReportRepository.GetCompanyNameByPowerStationId(powerStationId);
string companyName = getCompany.Result;
var n = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "report", Datename, companyName + "_" + "綜合比較" + "_" + postObject.Userid + Datename + ".xlsx"); var n = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "report", Datename, companyName + "_" + "綜合比較" + "_" + postObject.Userid + Datename + ".xlsx");
FileStream FS = new FileStream(n, FileMode.Create, FileAccess.Write); FileStream FS = new FileStream(n, FileMode.Create, FileAccess.Write);
workbook.Write(FS); workbook.Write(FS);

View File

@ -204,6 +204,8 @@ namespace SolarPower.Models
/// </summary> /// </summary>
public double IrrDay { get; set; } public double IrrDay { get; set; }
public double IrrDayHour { get; set; } public double IrrDayHour { get; set; }
public double GeneratingCapacity { get; set; }
public int days { get; set; }
} }
public class ExceptionEmailInfo public class ExceptionEmailInfo

View File

@ -442,6 +442,8 @@ namespace SolarPower.Models.PowerStation
public string InstallDate { get { return Convert.ToDateTime(installDate).ToString("yyyy-MM-dd"); } set { installDate = value; } } //安裝日期 public string InstallDate { get { return Convert.ToDateTime(installDate).ToString("yyyy-MM-dd"); } set { installDate = value; } } //安裝日期
public string BrandNum { get; set; }//廠商序號 public string BrandNum { get; set; }//廠商序號
public string WarrantyDate { get { return Convert.ToDateTime(warrantyDate).ToString("yyyy-MM-dd"); } set { warrantyDate = value; } } //保固日期 public string WarrantyDate { get { return Convert.ToDateTime(warrantyDate).ToString("yyyy-MM-dd"); } set { warrantyDate = value; } } //保固日期
public int SensorTypeId { get; set; }
public int SensorTypeDetailId { get; set; }
} }
public class Device : DeviceInfo public class Device : DeviceInfo
@ -627,7 +629,22 @@ namespace SolarPower.Models.PowerStation
public string EnabledName { get; set; } public string EnabledName { get; set; }
public string StatusName { get; set; } public string StatusName { get; set; }
public string PyrheliometerName { get; set; } public string PyrheliometerName { get; set; }
public int InverterStatus { get; set; }
} }
/// <summary>
/// Master底下的逆變器資料表
/// </summary>
public class InverterForMaster
{
public string DBName { get; set; }//資料庫名稱
public string InverterId { get; set; }//逆變器id
public int Deleted { get; set; }//是否刪除
public int Enabled { get; set; }//是否啟用
public int Status { get; set; }//狀態
public int Id { get; set; }
}
/// <summary> /// <summary>
/// 下拉式選單用 /// 下拉式選單用
/// </summary> /// </summary>

View File

@ -53,7 +53,7 @@ namespace SolarPower.Quartz.Jobs
logger.LogInformation("【CalcPowerStationJob】【開始取得電站資料】"); logger.LogInformation("【CalcPowerStationJob】【開始取得電站資料】");
var powerStations = await powerStationRepository.GetAllAsync(); var powerStations = await powerStationRepository.GetAllAsync();
logger.LogInformation("【CalcPowerStationJob】【取得成功電站資料】"); logger.LogInformation("【CalcPowerStationJob】【取得成功電站資料】");
logger.LogInformation("【CalcPowerStationJob】【電站資料】 - {0}", System.Text.Json.JsonSerializer.Serialize(powerStations)); logger.LogInformation("【CalcPowerStationJob】【電站資料");
#endregion #endregion
List<PowerStationHistory> powerStationHistoriesHour = new List<PowerStationHistory>(); List<PowerStationHistory> powerStationHistoriesHour = new List<PowerStationHistory>();
@ -269,7 +269,7 @@ namespace SolarPower.Quartz.Jobs
#endregion #endregion
#region for calcPowerStation #region for calcPowerStation
var dateTimeforPowerStation = DateTime.Now.ToString("yyyy-MM-dd");//取當天 var dateTimeforPowerStation = DateTime.Now.AddHours(-1).ToString("yyyy-MM-dd");//取當天
logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的每小時歷史資料 for calcPowerStation】", powerStation.Code, dateTimeforPowerStation); logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的每小時歷史資料 for calcPowerStation】", powerStation.Code, dateTimeforPowerStation);
var history_for_powerStation = await powerStationRepository.GetPowerStationHistoryPerHourForPowerStation(dateTimeforPowerStation, full_table_name); var history_for_powerStation = await powerStationRepository.GetPowerStationHistoryPerHourForPowerStation(dateTimeforPowerStation, full_table_name);
if (history_for_powerStation == null) if (history_for_powerStation == null)
@ -608,14 +608,31 @@ namespace SolarPower.Quartz.Jobs
sensorHistory.IrrDay = TPYHistory.IrrDay; sensorHistory.IrrDay = TPYHistory.IrrDay;
logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的累計日照量的平均值】", powerStation.Code, dateTime); logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的累計日照量的平均值】", powerStation.Code, dateTime);
logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的相減的累計日照量】", powerStation.Code, dateTime); logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的相減的累計日照量】", powerStation.Code, dateTime);
var ss = await powerStationRepository.CalcIrrDayHourHistoryPerHour(dateTime, powerStation.Id); var twoHourAgoIrrDay = await powerStationRepository.CalcIrrDayHistoryPerTwoHour(dateTime, powerStation.Id);
if (ss != null) if (twoHourAgoIrrDay != null)
{ {
sensorHistory.IrrDayHour = double.Parse(ss);
if (DateTimeNow.AddHours(-1).Hour == 0)//半夜12點的值
{
sensorHistory.IrrDayHour = 0;
}
else
{
sensorHistory.IrrDayHour = sensorHistory.IrrDay - double.Parse(twoHourAgoIrrDay);// 前一小時的IrrDay - 前兩小時的IrrDay
}
logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的相減的累計日照量】", powerStation.Code, dateTime); logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的相減的累計日照量】", powerStation.Code, dateTime);
} }
else
{
sensorHistory.IrrDayHour = 0;
}
} }
else
{
sensorHistory.IrrDay = 0;
sensorHistory.IrrDayHour = 0;
}
} }
} }
catch (Exception ex) catch (Exception ex)
@ -1073,98 +1090,5 @@ namespace SolarPower.Quartz.Jobs
} }
} }
public async Task setHistoryPerHourForPowerStation(string dateTime, string full_table_name, PowerStation powerStation)
{
var calcPowerStation = new PowerStation();
calcPowerStation.Id = powerStation.Id;
var history_for_powerStation = await powerStationRepository.GetPowerStationHistoryPerHourForPowerStation(dateTime, full_table_name);
if (history_for_powerStation == null)
{
//logger.LogWarning("【CalcPowerStationJob】【查無電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime);
//每小時發電量(直接填寫
calcPowerStation.kwh = 0;
//今日發電量(直接填寫
calcPowerStation.Today_kWh = 0;
//總發電量(直接填寫
calcPowerStation.Total_kWh = 0;
}
else
{
//每小時發電量(直接填寫
calcPowerStation.kwh = history_for_powerStation.KWH;
//今日發電量(直接填寫
calcPowerStation.Today_kWh = history_for_powerStation.TodayKWh;
//總發電量(直接填寫
calcPowerStation.Total_kWh = history_for_powerStation.TotalKWH;
#region
history_for_powerStation.MONEY = history_for_powerStation.KWH * powerStation.PowerRate;
history_for_powerStation.TODAYMONEY = history_for_powerStation.TodayKWh * powerStation.PowerRate;
history_for_powerStation.TOTALMONEY = history_for_powerStation.TotalKWH * powerStation.PowerRate;
//即時發電金額
switch (powerStation.SolarType)
{
case (int)SolarTypeEnum.SelfSold: //自建躉售
//今日發電金額 計算方式todaykWh * 授電費率
calcPowerStation.Today_Money = history_for_powerStation.TodayKWh * powerStation.PowerRate;
////總發電金額 計算方式totalkWh * 授電費率
calcPowerStation.Total_Money = history_for_powerStation.TotalKWH * powerStation.PowerRate;
break;
case (int)SolarTypeEnum.HireSold: //租建躉售
//找出該電站的所有土地房屋資訊
var landBuildings = await powerStationRepository.GetAllLandBuildingInfoByPowerStationId(powerStation.Id, powerStation.SiteDB);
var sumLeaseRate = 0.00;
var avgLeaseRate = 0.00;
foreach (var landBuilding in landBuildings)
{
sumLeaseRate += landBuilding.LeaseRate;
}
calcPowerStation.Today_Money = history_for_powerStation.TodayKWh * powerStation.PowerRate * sumLeaseRate / 100;
calcPowerStation.Total_Money = history_for_powerStation.TotalKWH * powerStation.PowerRate * sumLeaseRate / 100;
break;
case (int)SolarTypeEnum.SelfUse: //自建自用
//今日發電金額 計算方式todaykWh * 授電費率
calcPowerStation.Today_Money = history_for_powerStation.TodayKWh * powerStation.PowerRate;
//總發電金額 計算方式totalkWh * 授電費率
calcPowerStation.Total_Money = history_for_powerStation.TotalKWH * powerStation.PowerRate;
break;
}
#endregion
#region PR
//直接填寫
calcPowerStation.Today_PR = history_for_powerStation.PR;
#endregion
#region
carbonRate = Convert.ToDouble(await powerStationRepository.GetOneVariableByName("CarbonRate"));
history_for_powerStation.CARBON = history_for_powerStation.KWH * carbonRate;
history_for_powerStation.TODAYCARBON = history_for_powerStation.TodayKWh * carbonRate;
history_for_powerStation.TOTALCARBON = history_for_powerStation.TotalKWH * carbonRate;
//今日減碳量( 今日發電量 * (0.554/1000)[抓資料庫值]
calcPowerStation.Today_Carbon = history_for_powerStation.TodayKWh * carbonRate;
//總減碳量(總發電量 * (0.554/1000)[抓資料庫值]
calcPowerStation.Total_Carbon = history_for_powerStation.TotalKWH * carbonRate;
#endregion
#region
calcPowerStation.SolarHour = history_for_powerStation.SolarHour;
#endregion
}
}
} }
} }

View File

@ -10,6 +10,7 @@ using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Text.RegularExpressions;
namespace SolarPower.Quartz.Jobs namespace SolarPower.Quartz.Jobs
{ {
@ -248,6 +249,8 @@ namespace SolarPower.Quartz.Jobs
}; };
var stationReportName = stationReportController.ExportExcelBackDownload(JsonConvert.SerializeObject(dayexcel, Formatting.Indented)); var stationReportName = stationReportController.ExportExcelBackDownload(JsonConvert.SerializeObject(dayexcel, Formatting.Indented));
if (stationReportName != "") if (stationReportName != "")
{
if (user.Email != null && IsValidEmail(user.Email))
{ {
NoticeSchedule DaySchedule = new NoticeSchedule() NoticeSchedule DaySchedule = new NoticeSchedule()
{ {
@ -272,6 +275,7 @@ namespace SolarPower.Quartz.Jobs
await noticeScheduleRepository.AddOneAsync(DaySchedule, properties); await noticeScheduleRepository.AddOneAsync(DaySchedule, properties);
} }
} }
}
//綜合報表 每日 //綜合報表 每日
if (sentMaxpowerstations.Count != 0) if (sentMaxpowerstations.Count != 0)
{ {
@ -284,6 +288,8 @@ namespace SolarPower.Quartz.Jobs
Userid = user.Id Userid = user.Id
}; };
var stationMaxReportName = stationReportController.ExportExcelmaxtableBackDownload(JsonConvert.SerializeObject(maxdayexcel, Formatting.Indented)); var stationMaxReportName = stationReportController.ExportExcelmaxtableBackDownload(JsonConvert.SerializeObject(maxdayexcel, Formatting.Indented));
if (user.Email != null && IsValidEmail(user.Email))
{
NoticeSchedule MaxSchedule = new NoticeSchedule() NoticeSchedule MaxSchedule = new NoticeSchedule()
{ {
UserId = user.Id, UserId = user.Id,
@ -305,6 +311,7 @@ namespace SolarPower.Quartz.Jobs
"Type" "Type"
}; };
await noticeScheduleRepository.AddOneAsync(MaxSchedule, properties); await noticeScheduleRepository.AddOneAsync(MaxSchedule, properties);
}
if (DateTime.Now.ToString("dd") == "01") if (DateTime.Now.ToString("dd") == "01")
{ {
@ -317,6 +324,8 @@ namespace SolarPower.Quartz.Jobs
Userid = user.Id Userid = user.Id
}; };
var stationReportmaxmonthName = stationReportController.ExportExcelBackDownload(JsonConvert.SerializeObject(maxmonthexcel, Formatting.Indented)); var stationReportmaxmonthName = stationReportController.ExportExcelBackDownload(JsonConvert.SerializeObject(maxmonthexcel, Formatting.Indented));
if (user.Email != null && IsValidEmail(user.Email))
{
NoticeSchedule MaxmonthSchedule = new NoticeSchedule() NoticeSchedule MaxmonthSchedule = new NoticeSchedule()
{ {
RecipientEmail = user.Email, RecipientEmail = user.Email,
@ -339,6 +348,7 @@ namespace SolarPower.Quartz.Jobs
}; };
await noticeScheduleRepository.AddOneAsync(MaxmonthSchedule, properties2); await noticeScheduleRepository.AddOneAsync(MaxmonthSchedule, properties2);
} }
}
} }
@ -359,6 +369,8 @@ namespace SolarPower.Quartz.Jobs
}; };
var stationReportmonthName = stationReportController.ExportExcelBackDownload(JsonConvert.SerializeObject(monthexcel, Formatting.Indented)); var stationReportmonthName = stationReportController.ExportExcelBackDownload(JsonConvert.SerializeObject(monthexcel, Formatting.Indented));
if (stationReportmonthName != "") if (stationReportmonthName != "")
{
if (user.Email != null && IsValidEmail(user.Email))
{ {
NoticeSchedule MonthSchedule = new NoticeSchedule() NoticeSchedule MonthSchedule = new NoticeSchedule()
{ {
@ -382,6 +394,7 @@ namespace SolarPower.Quartz.Jobs
}; };
await noticeScheduleRepository.AddOneAsync(MonthSchedule, properties2); await noticeScheduleRepository.AddOneAsync(MonthSchedule, properties2);
} }
}
} }
@ -437,5 +450,11 @@ namespace SolarPower.Quartz.Jobs
return tempSerialNumber.ToString().Trim().PadRight(pad, '0'); return tempSerialNumber.ToString().Trim().PadRight(pad, '0');
} }
} }
bool IsValidEmail(string strIn)
{
// Return true if strIn is in valid e-mail format.
return Regex.IsMatch(strIn, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
}
} }
} }

View File

@ -9,6 +9,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Net.Mail; using System.Net.Mail;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Text.RegularExpressions;
namespace SolarPower.Quartz.Jobs namespace SolarPower.Quartz.Jobs
{ {
@ -43,6 +44,7 @@ namespace SolarPower.Quartz.Jobs
var updateNoticeSchedules = new List<NoticeSchedule>(); var updateNoticeSchedules = new List<NoticeSchedule>();
foreach (var notice in noticeSchedules) foreach (var notice in noticeSchedules)
{ {
if (notice.RecipientEmail != null && IsValidEmail(notice.RecipientEmail)) {
var attachments = new List<string>(); var attachments = new List<string>();
var recipientEmails = new List<string>() var recipientEmails = new List<string>()
{ {
@ -84,6 +86,7 @@ namespace SolarPower.Quartz.Jobs
await noticeScheduleRepository.UpdateList(updateNoticeSchedules, properties); await noticeScheduleRepository.UpdateList(updateNoticeSchedules, properties);
} }
}
logger.LogInformation("【SendEmailJob】【任務完成】"); logger.LogInformation("【SendEmailJob】【任務完成】");
} }
@ -160,5 +163,12 @@ namespace SolarPower.Quartz.Jobs
} }
} }
bool IsValidEmail(string strIn)
{
// Return true if strIn is in valid e-mail format.
return Regex.IsMatch(strIn, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
}
} }
} }

View File

@ -7,6 +7,7 @@ using System.Collections.Generic;
using System.Data; using System.Data;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Text.RegularExpressions;
namespace SolarPower.Repository.Implement namespace SolarPower.Repository.Implement
{ {
@ -647,17 +648,22 @@ namespace SolarPower.Repository.Implement
{ {
List<string> value = new List<string>(); List<string> value = new List<string>();
foreach (MyUser a in personal) foreach (MyUser a in personal)
{
if (a.Email != null && IsValidEmail(a.Email))
{ {
value.Add($@"(1,'{a.Name}','{a.Email}','{Title}','{content}',{a.Id}, {emailType})"); value.Add($@"(1,'{a.Name}','{a.Email}','{Title}','{content}',{a.Id}, {emailType})");
} }
}
string values = string.Join(",", value.ToArray()); string values = string.Join(",", value.ToArray());
if (value.Count > 0)
{
var sql = $"INSERT INTO `notice_schedule` (`Type`, `RecipientName`, `RecipientEmail`, `Subject`, `Content`,`UserId`,`EmailType`) VALUES {values};"; var sql = $"INSERT INTO `notice_schedule` (`Type`, `RecipientName`, `RecipientEmail`, `Subject`, `Content`,`UserId`,`EmailType`) VALUES {values};";
await conn.ExecuteAsync(sql, trans); await conn.ExecuteAsync(sql, trans);
trans.Commit(); trans.Commit();
} }
}
catch (Exception exception) catch (Exception exception)
{ {
trans.Rollback(); trans.Rollback();
@ -797,5 +803,11 @@ namespace SolarPower.Repository.Implement
} }
} }
bool IsValidEmail(string strIn)
{
// Return true if strIn is in valid e-mail format.
return Regex.IsMatch(strIn, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
}
} }
} }

View File

@ -731,12 +731,18 @@ namespace SolarPower.Repository.Implement
// LEFT JOIN sensor_history_month P ON P.`TIMESTAMP` = C.`TIMESTAMP` AND P.PowerStationId = C.PowerStationId // LEFT JOIN sensor_history_month P ON P.`TIMESTAMP` = C.`TIMESTAMP` AND P.PowerStationId = C.PowerStationId
// WHERE C.PowerStationId = {post.PowerstationId} // WHERE C.PowerStationId = {post.PowerstationId}
// GROUP BY left(c.`TIMESTAMP`, 4) ORDER BY C.`TIMESTAMP` "; // GROUP BY left(c.`TIMESTAMP`, 4) ORDER BY C.`TIMESTAMP` ";
sql = $@" select left(c.`TIMESTAMP`, 4) AS `TIMESTAMP`, sum(monthKWH) AS KWH, round(AVG(PR), 2) AS PR , round(AVG(PR), 2) AS avgPR , sql = $@"select * from (
ifnull(avg( P.IrrDay), 0) irrDay, avg(P.Temperature) AS Temp select left(c.`TIMESTAMP`, 4) AS `TIMESTAMP`, sum(monthKWH) AS KWH, round(AVG(PR), 2) AS PR , round(AVG(PR), 2) AS avgPR ,
ifnull(avg( P.IrrDay), 0) irrDay, avg(P.Temperature) AS Temp, ps.GeneratingCapacity AS GeneratingCapacity
FROM power_station_history_month C FROM power_station_history_month C
LEFT JOIN sensor_history_month P ON DATE_FORMAT(P.TIMESTAMP, '%Y') = DATE_FORMAT(C.TIMESTAMP, '%Y') AND P.PowerStationId = C.PowerStationId LEFT JOIN sensor_history_month P ON DATE_FORMAT(P.TIMESTAMP, '%Y-%M') = DATE_FORMAT(C.TIMESTAMP, '%Y-%M') AND P.PowerStationId = C.PowerStationId
LEFT JOIN power_station ps ON ps.id = C.PowerStationId
WHERE C.PowerStationId = {post.PowerstationId} WHERE C.PowerStationId = {post.PowerstationId}
group by left(c.`TIMESTAMP`, 4) "; group by left(c.`TIMESTAMP`, 4)
)x join
(
select year(timestamp) yyyy, count(*) days from sensor_history_day where PowerStationId = {post.PowerstationId} group by year(timestamp)
)y on x.`TIMESTAMP` = y.yyyy";
break; break;
} }

View File

@ -1018,6 +1018,10 @@ namespace SolarPower.Repository.Implement
var trans = conn.BeginTransaction(); var trans = conn.BeginTransaction();
try try
{ {
string getSensorTypeId = $@"SELECT id from sensor_type
WHERE SensorEName = '{DeviceInfo.Type}' AND Deleted = 0";
DeviceInfo.SensorTypeId = await conn.QueryFirstOrDefaultAsync<int>(getSensorTypeId);
DeviceInfo.SensorTypeDetailId = DeviceInfo.SensorTypeId;
string sql = GenerateInsertQueryWithCustomDBNameAndTable(properties, db_name, "device"); string sql = GenerateInsertQueryWithCustomDBNameAndTable(properties, db_name, "device");
await conn.ExecuteAsync(sql, DeviceInfo); await conn.ExecuteAsync(sql, DeviceInfo);
@ -1050,6 +1054,11 @@ namespace SolarPower.Repository.Implement
var trans = conn.BeginTransaction(); var trans = conn.BeginTransaction();
try try
{ {
string getSensorTypeId = $@"SELECT id from sensor_type
WHERE SensorEName = '{DeviceInfo.Type}' AND Deleted = 0";
DeviceInfo.SensorTypeId = await conn.QueryFirstOrDefaultAsync<int>(getSensorTypeId);
DeviceInfo.SensorTypeDetailId = DeviceInfo.SensorTypeId;
var updateQuery = GenerateUpdateQueryWithCustomDBNameAndTable(properties, db_name, "device"); var updateQuery = GenerateUpdateQueryWithCustomDBNameAndTable(properties, db_name, "device");
await conn.ExecuteAsync(updateQuery.ToString(), DeviceInfo, trans); await conn.ExecuteAsync(updateQuery.ToString(), DeviceInfo, trans);
trans.Commit(); trans.Commit();
@ -1906,6 +1915,34 @@ namespace SolarPower.Repository.Implement
} }
} }
/// <summary>
/// 在master.inv_status資料表中 新增逆變器
/// </summary>
/// <param name="inverter"></param>
/// <param name="properties"></param>
/// <returns></returns>
public async Task AddMasterInverter(InverterForMaster inverter, List<string> properties)
{
using (IDbConnection conn = _databaseHelper.GetConnection())
{
int count;
conn.Open();
try
{
var sql = GenerateInsertQueryWithCustomTable(properties, "inv_status");
count = await conn.ExecuteAsync(sql, inverter);
}
catch (Exception exception)
{
throw exception;
}
finally
{
conn.Close();
}
}
}
/// <summary> /// <summary>
/// 取得控制器所有id /// 取得控制器所有id
/// </summary> /// </summary>
@ -1980,11 +2017,12 @@ namespace SolarPower.Repository.Implement
try try
{ {
string sql = @$"SELECT string sql = @$"SELECT
inv.*, con.ControllerId AS ControllerName,user.Name As CreatedName,de.UID AS PyrheliometerName inv.*, con.ControllerId AS ControllerName,user.Name As CreatedName,de.UID AS PyrheliometerName, invs.status AS InverterStatus
FROM {db_name}.inverter inv FROM {db_name}.inverter inv
LEFT JOIN {db_name}.controller con ON inv.ControllerId = con.id LEFT JOIN {db_name}.controller con ON inv.ControllerId = con.id
LEFT JOIN user ON inv.CreatedBy = user.id LEFT JOIN user ON inv.CreatedBy = user.id
LEFT JOIN {db_name}.device de ON inv.Pyrheliometer = de.id LEFT JOIN {db_name}.device de ON inv.Pyrheliometer = de.id
LEFT JOIN inv_status invs ON inv.InverterId = invs.InverterId
WHERE inv.Deleted = 0 AND inv.ControllerId IN @Controllerid"; WHERE inv.Deleted = 0 AND inv.ControllerId IN @Controllerid";
inverterTable = (await conn.QueryAsync<InverterTable>(sql, new { Controllerid = controllerid }, commandTimeout: 600)).ToList(); inverterTable = (await conn.QueryAsync<InverterTable>(sql, new { Controllerid = controllerid }, commandTimeout: 600)).ToList();
@ -2001,6 +2039,39 @@ namespace SolarPower.Repository.Implement
} }
} }
/// <summary>
/// 取單一逆變器
/// </summary>
/// <param name="id"></param>
/// <param name="db_name"></param>
/// <returns></returns>
public async Task<InverterTable> GetOneMasterInverter(int id, string db_name)
{
using (IDbConnection conn = _databaseHelper.GetConnection())
{
InverterTable inverter = new InverterTable();
conn.Open();
try
{
string sql = $@"SELECT a.InverterId
FROM solar_master.inv_status a join {db_name}.inverter b on a.inverterid = b.inverterid
WHERE a.Deleted = 0 AND b.Id = {id}";
inverter = (await conn.QueryFirstOrDefaultAsync<InverterTable>(sql, commandTimeout: 600));
}
catch (Exception exception)
{
throw exception;
}
finally
{
conn.Close();
}
return inverter;
}
}
/// <summary> /// <summary>
/// 其餘電站列表 /// 其餘電站列表
/// </summary> /// </summary>
@ -2558,41 +2629,75 @@ namespace SolarPower.Repository.Implement
} }
} }
//public virtual async Task DeleteOneInverter(int id, string db_name, string table_name) public async Task<int> UpdateMasterInverter(InverterForMaster entity, List<string> properties)
//{ {
// using (IDbConnection conn = this._databaseHelper.GetConnection()) int count;
// { using (IDbConnection conn = _databaseHelper.GetConnection())
// conn.Open(); {
// using (var trans = conn.BeginTransaction()) conn.Open();
// { using (var trans = conn.BeginTransaction())
// try {
// { try
// var sql = $"UPDATE {db_name}.{table_name} SET Deleted = 1 WHERE Id = @Id"; {
string sql = $@"UPDATE solar_master.inv_status a join {entity.DBName}.inverter b on a.inverterid = b.inverterid
SET
a.Enabled = {entity.Enabled},
a.Status = {entity.Status}
WHERE b.id = {entity.Id}";
// await conn.ExecuteAsync(sql, new { Id = id }, trans); count = await conn.ExecuteAsync(sql, entity, trans);
// string updateToInv_Status = @"DROP TABLE IF EXISTS solar_master.`inv_status`; trans.Commit();
// create table solar_master.inv_status }
// select * from solar_master.v_company_inv catch (Exception exception)
// where enabled = 1; {
// ALTER TABLE solar_master.`inv_status` ADD INDEX inv_status_index (`inverterid`);"; trans.Rollback();
throw exception;
}
finally
{
conn.Close();
}
}
// await conn.ExecuteAsync(updateToInv_Status, new { Id = id }, trans); return count;
}
}
// trans.Commit(); /// <summary>
// } /// 透過table_name、inverterId軟刪除指定資料表的單一筆inverter
// catch (Exception exception) /// </summary>
// { /// <param name="inverterId"></param>
// trans.Rollback(); /// <param name="table_name"></param>
// throw exception; /// <returns></returns>
// } public async Task DeleteOneMasterInverter(string inverterId, string table_name)
// finally {
// { using (IDbConnection conn = this._databaseHelper.GetConnection())
// conn.Close(); {
// } conn.Open();
// } using (var trans = conn.BeginTransaction())
// } {
//} try
{
var sql = $"UPDATE {table_name} SET Deleted = 1 WHERE InverterId = {inverterId}";
await conn.ExecuteAsync(sql, trans);
trans.Commit();
}
catch (Exception exception)
{
trans.Rollback();
throw exception;
}
finally
{
conn.Close();
}
}
}
}
public async Task<List<DeviceInfo>> GetListPyrheliometerByPowerStationId(int powerStationId, string db_name) public async Task<List<DeviceInfo>> GetListPyrheliometerByPowerStationId(int powerStationId, string db_name)
{ {
@ -6447,36 +6552,21 @@ namespace SolarPower.Repository.Implement
} }
} }
public async Task<string> CalcIrrDayHourHistoryPerHour(string dateTime, int powerStationId) public async Task<string> CalcIrrDayHistoryPerTwoHour(string dateTime, int powerStationId)
{ {
string result; string result;
using (IDbConnection conn = this._databaseHelper.GetConnection()) using (IDbConnection conn = this._databaseHelper.GetConnection())
{ {
try try
{ {
//var sql = $@"update sensor_history_hour a join
// (
// select powerstationID, `TIMESTAMP`, irrday -
// (select irrday from sensor_history_hour where powerstationID = {powerStationId} and LEFT(`TIMESTAMP`, 13 ) = '{Convert.ToDateTime(dateTime).AddHours(-1).ToString("yyyy-MM-dd HH")}' limit 1) irrdayhour
// from sensor_history_hour z
// where powerstationID = {powerStationId} and LEFT(z.`TIMESTAMP`, 13 ) = '{Convert.ToDateTime(dateTime).ToString("yyyy-MM-dd HH")}'
// ) b on a.powerstationID = b.powerstationID and a.`TIMESTAMP` = b.`TIMESTAMP`
// Set a.irrdayhour = b.irrdayhour where a.powerstationID = {powerStationId}";
string d1 = dateTime + ":00:00"; string d1 = dateTime + ":00:00";
//string sql = $@"update sensor_history_hour a join //string sql = $@" select irrday -
// (
// select powerstationID, `TIMESTAMP`, irrday -
// (select irrday from sensor_history_hour where powerstationID = {powerStationId} and LEFT(`TIMESTAMP`, 13 ) = '{Convert.ToDateTime(d1).AddHours(-1).ToString("yyyy-MM-dd HH")}' limit 1) irrdayhour // (select irrday from sensor_history_hour where powerstationID = {powerStationId} and LEFT(`TIMESTAMP`, 13 ) = '{Convert.ToDateTime(d1).AddHours(-1).ToString("yyyy-MM-dd HH")}' limit 1) irrdayhour
// from sensor_history_hour z // from sensor_history_hour z
// where powerstationID = {powerStationId} and LEFT(z.`TIMESTAMP`, 13 ) = '{dateTime}' // where powerstationID = {powerStationId} and LEFT(z.`TIMESTAMP`, 13 ) = '{dateTime}' ";
// ) b on a.powerstationID = b.powerstationID and a.`TIMESTAMP` = b.`TIMESTAMP` string sql = $@" select IrrDay
// Set a.irrdayhour = case when b.irrdayhour < 0 then 0 else b.irrdayhour end
// where a.powerstationID = {powerStationId}";
//result = await conn.QueryFirstOrDefaultAsync<PyrheliometerHistory>(sql, commandTimeout: 600);
string sql = $@" select irrday -
(select irrday from sensor_history_hour where powerstationID = {powerStationId} and LEFT(`TIMESTAMP`, 13 ) = '{Convert.ToDateTime(d1).AddHours(-1).ToString("yyyy-MM-dd HH")}' limit 1) irrdayhour
from sensor_history_hour z from sensor_history_hour z
where powerstationID = {powerStationId} and LEFT(z.`TIMESTAMP`, 13 ) = '{dateTime}' "; where powerstationID = {powerStationId} and LEFT(z.`TIMESTAMP`, 13 ) = '{Convert.ToDateTime(d1).AddHours(-1).ToString("yyyy-MM-dd HH")}' ";
result = await conn.QueryFirstOrDefaultAsync<string>(sql, commandTimeout: 600); result = await conn.QueryFirstOrDefaultAsync<string>(sql, commandTimeout: 600);
} }
catch (Exception exception) catch (Exception exception)

View File

@ -114,9 +114,9 @@ namespace SolarPower.Repository.Implement
select * from temp_inv select * from temp_inv
union union
SELECT '' report_date, {inv} SELECT '' report_date, {inv}
round(sum(hourKWH), 2) hourKWH, round(sum(hourKWHp), 2) hourKWHp, round(avg(irrDay),2) irrDay, round(avg(irrDayHour),2) irrDayHour, round(sum(hourKWH), 2) hourKWH, round(sum(hourKWHp), 2) hourKWHp, round(sum(irrDay),2) irrDay, round(sum(irrDayHour),2) irrDayHour,
round( avg(temperature), 2) temperature, round(sum(hourmoney), 2) hourmoney, round(avg(totKWH), 2) totKWH, round(avg(totKWHKWP),2) totKWHKWP, round(avg(totmoney),2) totmoney, '' stationName, round( avg(temperature), 2) temperature, round(sum(hourmoney), 2) hourmoney, round(sum(totKWH), 2) totKWH, round(sum(totKWHKWP),2) totKWHKWP, round(sum(totmoney),2) totmoney, '' stationName,
round( avg(daymoney), 2) daymoney, round(avg(tothour), 2) tothour, round(avg(pr), 2) pr, avg(GeneratingCapacity) GeneratingCapacity round( sum(daymoney), 2) daymoney, round(sum(tothour), 2) tothour, round(sum(pr), 2) pr, avg(GeneratingCapacity) GeneratingCapacity
from temp_inv2 a; "; from temp_inv2 a; ";
break; break;
@ -166,7 +166,7 @@ namespace SolarPower.Repository.Implement
SELECT '' report_date, {inv} SELECT '' report_date, {inv}
round(sum(dayKWH), 2) dayKWH, round(sum(dayKWHp), 2) dayKWHp, round(max(tothour), 2) tothour, round(avg(KWHKWP), 2) KWHKWP, round(avg(PR), 2) PR, round(sum(dayKWH), 2) dayKWH, round(sum(dayKWHp), 2) dayKWHp, round(max(tothour), 2) tothour, round(avg(KWHKWP), 2) KWHKWP, round(avg(PR), 2) PR,
GeneratingCapacity, round(sum(irradiance), 2) irradiance, round(avg(temperature), 2) temperature, round(sum(soldmoney), 2) soldmoney, GeneratingCapacity, round(sum(irradiance), 2) irradiance, round(avg(temperature), 2) temperature, round(sum(soldmoney), 2) soldmoney,
round(monthKWH, 2) monthKWH, monthmoney, stationName, monthmoneyone, SolarType, SiteDB, IrrDay round(monthKWH, 2) monthKWH, monthmoney, stationName, monthmoneyone, SolarType, SiteDB, round(avg(IrrDay), 2) IrrDay
from temp_inv2 a; "; from temp_inv2 a; ";
} }
else else
@ -264,7 +264,7 @@ namespace SolarPower.Repository.Implement
SELECT '' report_date, {inv} SELECT '' report_date, {inv}
round(sum(dayKWH), 2) dayKWH, round(sum(dayKWHp), 2) dayKWHp, round(max(tothour), 2) tothour, avg(KWHKWP) KWHKWP, round(avg(PR), 2) PR, round(sum(dayKWH), 2) dayKWH, round(sum(dayKWHp), 2) dayKWHp, round(max(tothour), 2) tothour, avg(KWHKWP) KWHKWP, round(avg(PR), 2) PR,
GeneratingCapacity, round(sum(irradiance), 2) irradiance, round(avg(temperature), 2) temperature, round(sum(soldmoney), 2) soldmoney, GeneratingCapacity, round(sum(irradiance), 2) irradiance, round(avg(temperature), 2) temperature, round(sum(soldmoney), 2) soldmoney,
round( monthKWH,2) monthKWH , monthmoney, stationName, monthmoneyone, SolarType, SiteDB, round(IrrDay , 2) IrrDay round( monthKWH,2) monthKWH , monthmoney, stationName, monthmoneyone, SolarType, SiteDB, round(avg(IrrDay), 2) IrrDay
from temp_inv2 a; "; from temp_inv2 a; ";
} }
@ -315,12 +315,24 @@ namespace SolarPower.Repository.Implement
// EXECUTE stmt; // EXECUTE stmt;
// DEALLOCATE PREPARE stmt;"; // DEALLOCATE PREPARE stmt;";
#endregion #endregion
DateTime firstDay = new DateTime(int.Parse(post.Time), 01, 01);
DateTime lastDay;
if (DateTime.Now.Year == int.Parse(post.Time))
{
lastDay = DateTime.Now.Date;
}
else
{
lastDay = new DateTime(int.Parse(post.Time), 12, 31);
}
string days = (lastDay - firstDay).TotalDays.ToString();
sql = @$" DROP TABLE IF EXISTS temp_inv; sql = @$" DROP TABLE IF EXISTS temp_inv;
create TEMPORARY TABLE temp_inv as create TEMPORARY TABLE temp_inv as
SELECT DATE_FORMAT(a.report_date,'%Y/%m') report_date, {inv} SELECT DATE_FORMAT(a.report_date,'%Y/%m') report_date, {inv}
b.todayKWH 'dayKWH', round((b.todayKWH / c.monthKWH)*100,2) 'dayKWHp', b.SOLARHOUR 'tothour', b.KWHKWP 'KWHKWP', b.PR,z.GeneratingCapacity, b.todayKWH 'dayKWH', round((b.todayKWH / c.monthKWH)*100,2) 'dayKWHp', b.SOLARHOUR 'tothour', b.KWHKWP 'KWHKWP', b.PR,z.GeneratingCapacity,
d.irradiance 'irradiance', d.Temperature 'temperature', b.money 'soldmoney', d.irradiance 'irradiance', d.Temperature 'temperature', b.money 'soldmoney',
c.monthKWH 'monthKWH', c.money 'monthmoney', stationName, powerRate 'monthmoneyone',SolarType,SiteDB, d.IrrDay c.monthKWH 'monthKWH', c.money 'monthmoney', stationName, powerRate 'monthmoneyone',SolarType,SiteDB, d.IrrDay, {days} Days
FROM report_invday a left join FROM report_invday a left join
( # inv ( # inv
select powerStationid, DATE_FORMAT(TIMESTAMP,'%Y-%m') report_date, siteid, sitetype, select powerStationid, DATE_FORMAT(TIMESTAMP,'%Y-%m') report_date, siteid, sitetype,
@ -358,7 +370,7 @@ namespace SolarPower.Repository.Implement
SELECT '' report_date, {inv} SELECT '' report_date, {inv}
round(sum(dayKWH), 2) dayKWH, round(sum(dayKWHp), 2) dayKWHp, round(max(tothour), 2) tothour, avg(KWHKWP) KWHKWP, round(avg(PR), 2) PR, round(sum(dayKWH), 2) dayKWH, round(sum(dayKWHp), 2) dayKWHp, round(max(tothour), 2) tothour, avg(KWHKWP) KWHKWP, round(avg(PR), 2) PR,
GeneratingCapacity, round(sum(irradiance), 2) irradiance, avg(temperature) temperature, round(sum(soldmoney), 2) soldmoney, GeneratingCapacity, round(sum(irradiance), 2) irradiance, avg(temperature) temperature, round(sum(soldmoney), 2) soldmoney,
round(monthKWH, 2) monthKWH, monthmoney, stationName, monthmoneyone, SolarType, SiteDB, IrrDay round(monthKWH, 2) monthKWH, monthmoney, stationName, monthmoneyone, SolarType, SiteDB, round(avg(IrrDay), 2) IrrDay, 0
from temp_inv2 a; "; from temp_inv2 a; ";
break; break;
@ -805,5 +817,35 @@ namespace SolarPower.Repository.Implement
return a; return a;
} }
} }
public async Task<string> GetCompanyNameByPowerStationId(int powerStationId)
{
string result;
using (IDbConnection conn = _databaseHelper.GetConnection())
{
conn.Open();
try
{
var sql = @$"SELECT c.Name
FROM power_station ps
LEFT JOIN company c ON ps.CompanyId = c.id
WHERE ps.id = {powerStationId} AND ps.Deleted = 0";
result = await conn.QueryFirstOrDefaultAsync<string>(sql);
}
catch (Exception exception)
{
throw exception;
}
finally
{
conn.Close();
}
return result;
}
}
} }
} }

View File

@ -399,6 +399,13 @@ namespace SolarPower.Repository.Interface
/// <returns></returns> /// <returns></returns>
Task AddInverter(Inverter inverter, List<string> properties, string db_name); Task AddInverter(Inverter inverter, List<string> properties, string db_name);
/// <summary> /// <summary>
/// 新增Master逆變器
/// </summary>
/// <param name="inverter"></param>
/// <param name="properties"></param>
/// <returns></returns>
Task AddMasterInverter(InverterForMaster inverter, List<string> properties);
/// <summary>
/// 取得控制器所有id /// 取得控制器所有id
/// </summary> /// </summary>
Task<List<int>> GetAllDeviceControllerId(int stationId, string db_name); Task<List<int>> GetAllDeviceControllerId(int stationId, string db_name);
@ -539,6 +546,8 @@ namespace SolarPower.Repository.Interface
Task<int> UpdatePyrheliometerHistoryMonthList(List<PyrheliometerHistory> entity); Task<int> UpdatePyrheliometerHistoryMonthList(List<PyrheliometerHistory> entity);
Task<int> UpdateInverter(Inverter entity, List<string> properties, string db_name); Task<int> UpdateInverter(Inverter entity, List<string> properties, string db_name);
Task<int> UpdateMasterInverter(InverterForMaster entity, List<string> properties);
Task DeleteOneMasterInverter(string inverterId, string table_name);
Task<A> Getonediv<A>(string where, string db_name, string table_name); Task<A> Getonediv<A>(string where, string db_name, string table_name);
@ -632,7 +641,8 @@ namespace SolarPower.Repository.Interface
Task AlertColStationTableColumn(string dbname, string code); Task AlertColStationTableColumn(string dbname, string code);
Task<List<PowerStation>> GetAllNoStatusAsync(); Task<List<PowerStation>> GetAllNoStatusAsync();
Task<string> CalcIrrDayHourHistoryPerHour(string dateTime, int powerStationId); Task<string> CalcIrrDayHistoryPerTwoHour(string dateTime, int powerStationId);
Task<PowerStationHistory> GetPowerStationHistoryPerHourForPowerStation(string dateTime, string table_name); Task<PowerStationHistory> GetPowerStationHistoryPerHourForPowerStation(string dateTime, string table_name);
Task<InverterTable> GetOneMasterInverter(int id, string db_name);
} }
} }

View File

@ -14,5 +14,6 @@ namespace SolarPower.Repository.Interface
Task<List<MaxFormbody>> GetMaxtablebody(Select_table2 post); Task<List<MaxFormbody>> GetMaxtablebody(Select_table2 post);
Task<dynamic> Findhaveinv(Select_table post); Task<dynamic> Findhaveinv(Select_table post);
Task<int> CheckExcelAsync(Select_table post); Task<int> CheckExcelAsync(Select_table post);
Task<string> GetCompanyNameByPowerStationId(int powerStationId);
} }
} }

View File

@ -4,16 +4,8 @@
ViewData["Title"] = "逆變器交叉分析"; ViewData["Title"] = "逆變器交叉分析";
} }
<link rel="stylesheet" href="~/css/loading.css" /> <div class="d-flex justify-content-center text-secondary" style="top: 10%; transform: translateY(50%); z-index: 100; position: relative;">
<div class="loadEffect" id="loading" style="top: 10%;"> <div class="spinner-border" role="status" style="width: 3rem; height: 3rem; display:none;" id="loading"></div>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div> </div>
<div class="container-fluid"> <div class="container-fluid">

View File

@ -6,16 +6,8 @@
@using SolarPower.Models.Role @using SolarPower.Models.Role
@model RoleLayerEnum @model RoleLayerEnum
<link rel="stylesheet" href="~/css/loading.css" /> <div class="d-flex justify-content-center text-secondary" style="top: 10%; transform: translateY(50%); z-index: 100; position: relative;">
<div class="loadEffect" id="loading" style="top: 10%;"> <div class="spinner-border" role="status" style="width: 3rem; height: 3rem; display:none;" id="loading"></div>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div> </div>
<div class="container-fluid"> <div class="container-fluid">

View File

@ -4,16 +4,8 @@
ViewData["Title"] = "電站交叉分析"; ViewData["Title"] = "電站交叉分析";
} }
<link rel="stylesheet" href="~/css/loading.css" /> <div class="d-flex justify-content-center text-secondary" style="top: 10%; transform: translateY(50%); z-index: 100; position: relative;">
<div class="loadEffect" id="loading" style="top: 10%;"> <div class="spinner-border" role="status" style="width: 3rem; height: 3rem; display:none;" id="loading"></div>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div> </div>
<div class="container-fluid"> <div class="container-fluid">

View File

@ -19,16 +19,8 @@
</div> </div>
<!-- Your main content goes below here: --> <!-- Your main content goes below here: -->
<link rel="stylesheet" href="~/css/loading.css" /> <div class="d-flex justify-content-center text-secondary" style="top: 10%; transform: translateY(50%); z-index: 100; position: relative;">
<div class="loadEffect" id="loading" style="top: 10%;"> <div class="spinner-border" role="status" style="width: 3rem; height: 3rem; display:none;" id="loading"></div>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div> </div>
<div class="row"> <div class="row">

View File

@ -6,16 +6,8 @@
@using SolarPower.Models.Role @using SolarPower.Models.Role
@model RoleLayerEnum @model RoleLayerEnum
<link rel="stylesheet" href="~/css/loading.css" /> <div class="d-flex justify-content-center text-secondary" style="top: 10%; transform: translateY(50%); z-index: 100; position: relative;">
<div class="loadEffect" id="loading" style="top: 10%;"> <div class="spinner-border" role="status" style="width: 3rem; height: 3rem; display:none;" id="loading"></div>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div> </div>
<div class="container-fluid"> <div class="container-fluid">

View File

@ -12,16 +12,8 @@
<li class="position-absolute pos-top pos-right d-none d-sm-block"><span class="js-get-date"></span></li> <li class="position-absolute pos-top pos-right d-none d-sm-block"><span class="js-get-date"></span></li>
</ol> </ol>
<link rel="stylesheet" href="~/css/loading.css" /> <div class="d-flex justify-content-center text-secondary" style="top: 10%; transform: translateY(50%); z-index: 100; position: relative;">
<div class="loadEffect" id="loading" style="top: 10%;"> <div class="spinner-border" role="status" style="width: 3rem; height: 3rem; display:none;" id="loading"></div>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div> </div>
<div class="row"> <div class="row">

View File

@ -25,20 +25,8 @@
<!-- icheck bootstrap --> <!-- icheck bootstrap -->
<link href="~/lib/icheck-bootstrap/icheck-bootstrap.min.css" rel="stylesheet" /> <link href="~/lib/icheck-bootstrap/icheck-bootstrap.min.css" rel="stylesheet" />
<!-- Theme style --> <!-- Theme style -->
<link rel="stylesheet" href="~/css/loading.css" />
</head> </head>
<body> <body>
<div class="loadEffect" id="loading" style="top: 50%;">
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
<div class="blankpage-form-field"> <div class="blankpage-form-field">
<div class="page-logo m-0 w-100 align-items-center justify-content-center rounded border-bottom-left-radius-0 border-bottom-right-radius-0 px-4"> <div class="page-logo m-0 w-100 align-items-center justify-content-center rounded border-bottom-left-radius-0 border-bottom-right-radius-0 px-4">
@ -87,6 +75,10 @@
<source src="~/media/video/cc.webm" type="video/webm"> <source src="~/media/video/cc.webm" type="video/webm">
<source src="~/media/video/cc.mp4" type="video/mp4"> <source src="~/media/video/cc.mp4" type="video/mp4">
</video> </video>
<div class="d-flex justify-content-center text-secondary" style="transform: translateY(1150%);">
<div class="spinner-border" role="status" id="loading" style="display: none"></div>
</div>
@* @*
<div class="login-box"> <div class="login-box">

View File

@ -11,16 +11,8 @@
<!-- Your main content goes below here: --> <!-- Your main content goes below here: -->
<link rel="stylesheet" href="~/css/loading.css" /> <div class="d-flex justify-content-center text-secondary" style="top: 10%; transform: translateY(50%); z-index: 100; position: relative; ">
<div class="loadEffect" id="loading" style="top: 10%;"> <div class="spinner-border" role="status" style="width: 3rem; height: 3rem; display:none;" id="loading"></div>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div> </div>
@*<div class="row mb-5">*@ @*<div class="row mb-5">*@

View File

@ -6,16 +6,8 @@
@using SolarPower.Models.Role @using SolarPower.Models.Role
@model RoleLayerEnum @model RoleLayerEnum
<link rel="stylesheet" href="~/css/loading.css" /> <div class="d-flex justify-content-center text-secondary" style="top: 10%; transform: translateY(50%); z-index: 100; position: relative;">
<div class="loadEffect" id="loading" style="top: 10%;"> <div class="spinner-border" role="status" style="width: 3rem; height: 3rem; display:none;" id="loading"></div>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div> </div>
<div class="container-fluid"> <div class="container-fluid">

View File

@ -6,16 +6,8 @@
@using SolarPower.Models.Role @using SolarPower.Models.Role
@model RoleLayerEnum @model RoleLayerEnum
<link rel="stylesheet" href="~/css/loading.css" /> <div class="d-flex justify-content-center text-secondary" style="top: 10%; transform: translateY(50%); z-index: 100; position: relative;">
<div class="loadEffect" id="loading" style="top: 10%;"> <div class="spinner-border" role="status" style="width: 3rem; height: 3rem; display:none;" id="loading"></div>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div> </div>
<ol class="breadcrumb page-breadcrumb"> <ol class="breadcrumb page-breadcrumb">

View File

@ -17,16 +17,8 @@
</h1> </h1>
</div> </div>
<link rel="stylesheet" href="~/css/loading.css" /> <div class="d-flex justify-content-center text-secondary" style="top: 10%; transform: translateY(50%); z-index: 100; position: relative;">
<div class="loadEffect" id="loading" style="top: 10%;"> <div class="spinner-border" role="status" style="width: 3rem; height: 3rem; display:none;" id="loading"></div>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div> </div>
<!-- Your main content goes below here: --> <!-- Your main content goes below here: -->

View File

@ -6,16 +6,8 @@
@using SolarPower.Models.Role @using SolarPower.Models.Role
@model RoleLayerEnum @model RoleLayerEnum
<link rel="stylesheet" href="~/css/loading.css" /> <div class="d-flex justify-content-center text-secondary" style="top: 10%; transform: translateY(50%); z-index: 100; position: relative;">
<div class="loadEffect" id="loading" style="top: 10%;"> <div class="spinner-border" role="status" style="width: 3rem; height: 3rem; display:none;" id="loading"></div>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div> </div>
<div class="container-fluid"> <div class="container-fluid">

View File

@ -6,16 +6,8 @@
@using SolarPower.Models.Role @using SolarPower.Models.Role
@model RoleLayerEnum @model RoleLayerEnum
<link rel="stylesheet" href="~/css/loading.css" /> <div class="d-flex justify-content-center text-secondary" style="top: 10%; transform: translateY(50%); z-index: 100; position: relative;">
<div class="loadEffect" id="loading" style="top: 10%;"> <div class="spinner-border" role="status" style="width: 3rem; height: 3rem; display:none;" id="loading"></div>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div> </div>
<ol class="breadcrumb page-breadcrumb"> <ol class="breadcrumb page-breadcrumb">

View File

@ -16,16 +16,8 @@
<!-- Your main content goes below here: --> <!-- Your main content goes below here: -->
<link rel="stylesheet" href="~/css/loading.css" /> <div class="d-flex justify-content-center text-secondary" style="top: 10%; transform: translateY(50%); z-index: 100; position: relative;">
<div class="loadEffect" id="loading" style="top: 10%;"> <div class="spinner-border" role="status" style="width: 3rem; height: 3rem; display:none;" id="loading"></div>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div> </div>
<div class="row"> <div class="row">

View File

@ -19,16 +19,8 @@
</div> </div>
<!-- Your main content goes below here: --> <!-- Your main content goes below here: -->
<link rel="stylesheet" href="~/css/loading.css" /> <div class="d-flex justify-content-center text-secondary" style="top: 10%; transform: translateY(50%); z-index: 100; position: relative;">
<div class="loadEffect" id="loading" style="top: 10%;"> <div class="spinner-border" role="status" style="width: 3rem; height: 3rem; display:none;" id="loading"></div>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div> </div>
<div class="row"> <div class="row">

View File

@ -12,16 +12,8 @@
<!-- Your main content goes below here: --> <!-- Your main content goes below here: -->
<link rel="stylesheet" href="~/css/loading.css" /> <div class="d-flex justify-content-center text-secondary" style="top: 10%; transform: translateY(50%); z-index: 100; position: relative;">
<div class="loadEffect" id="loading" style="top: 10%;"> <div class="spinner-border" role="status" style="width: 3rem; height: 3rem; display:none;" id="loading"></div>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div> </div>
<div class="row"> <div class="row">

View File

@ -13,16 +13,8 @@
<li class="position-absolute pos-top pos-right d-none d-sm-block"><span class="js-get-date"></span></li> <li class="position-absolute pos-top pos-right d-none d-sm-block"><span class="js-get-date"></span></li>
</ol>*@ </ol>*@
<link rel="stylesheet" href="~/css/loading.css" /> <div class="d-flex justify-content-center text-secondary" style="top: 10%; transform: translateY(50%); z-index: 100; position: relative;">
<div class="loadEffect" id="loading" style="top: 10%;"> <div class="spinner-border" role="status" style="width: 3rem; height: 3rem; display:none;" id="loading"></div>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div> </div>
<div class="row"> <div class="row">
@ -1331,6 +1323,45 @@
} }
//#endregion //#endregion
//#region 刪除檔案
$('#record_files_div').on("click", "a.del-operation-record-file-btn", function () {
var selectedFileId = $(this).attr("data-id");
var div = $(this).parents(".col-auto");
Swal.fire({
title: "刪除",
text: "你確定是否刪除此筆資料?",
type: "warning",
icon: 'warning',
showCancelButton: true,
confirmButtonText: "是",
cancelButtonText: "否"
}).then(function (result) {
if (result.value) {
var url = "/Operation/DeleteOperationRecordFile";
var send_data = {
ReocdeId: selected_id,
SelectedId: selectedFileId
}
$.post(url, send_data, function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
operationRecordTable.ajax.reload();
toast_ok(rel.msg);
div.remove();
}, 'json');
}
});
});
//#endregion
//#region 異常 //#region 異常
//#region 改變日期(異常) //#region 改變日期(異常)
@ -1646,7 +1677,7 @@
status = 1; status = 1;
} }
$("input[name=status_modal_opRecord][value='" + status + "']").prop('checked', true); //狀態 $("input[name=status_modal_opRecord][value='" + status + "']").prop('checked', true); //狀態
$('#work_person_select_modal').val(record.workPersonId).trigger("change");; $('#work_person_select_modal').val(record.workPersonIds).trigger("change");
if (work_type != 2) { if (work_type != 2) {
$(".fix-div").hide(); $(".fix-div").hide();
} else { } else {
@ -2656,6 +2687,8 @@
var times = 1; var times = 1;
var ALLkwhkwp = 0; var ALLkwhkwp = 0;
var kwhkwp = 0; var kwhkwp = 0;
var ALLDays = 0;
var ALLavgdaykwh = 0;
$.each(rel.data, function (index, val) { $.each(rel.data, function (index, val) {
@ -2683,6 +2716,7 @@
//暫時先執行到這--->取kwhkwp //暫時先執行到這--->取kwhkwp
var nowDisplayIrrDay = 0; var nowDisplayIrrDay = 0;
var avgdaykwh = 0;
if (val.length != 0) { if (val.length != 0) {
if (groupType != 6) { if (groupType != 6) {
@ -2690,7 +2724,7 @@
if (groupType == 0 && kwhkwp < val.kwhkwp.toFixed(2)) { if (groupType == 0 && kwhkwp < val.kwhkwp.toFixed(2)) {
kwhkwp = val.kwhkwp.toFixed(2); kwhkwp = val.kwhkwp.toFixed(2);
} }
if (groupType != 0) { if (groupType != 0 && groupType != 3) {
ALLkwhkwp += val.kwhkwp; ALLkwhkwp += val.kwhkwp;
kwhkwp = (ALLkwhkwp / times).toFixed(2); kwhkwp = (ALLkwhkwp / times).toFixed(2);
times++; times++;
@ -2699,16 +2733,25 @@
nowDisplayIrrDay = val.irrDayHour.toFixed(2); nowDisplayIrrDay = val.irrDayHour.toFixed(2);
} }
else { else {
nowDisplayIrrDay = val.irradiance.toFixed(2); nowDisplayIrrDay = val.irrDay.toFixed(2);
}
if (groupType == 3)
{
ALLDays += val.days;
avgdaykwh = (val.kwh / val.generatingCapacity / val.days);
ALLavgdaykwh += avgdaykwh;
}
else
{
avgdaykwh = val.kwhkwp;
} }
// console.log(val); // console.log(val);
diffSOLARHOURALL = val.solarhour; diffSOLARHOURALL = val.solarhour;
$('#HistoryDetailTable').append('<tr>' + $('#HistoryDetailTable').append('<tr>' +
'<td>' + val.timestamp + '</td>' + '<td>' + val.timestamp + '</td>' +
'<td>' + (toThousands(val.kwh.toFixed(2))) + '</td>' + '<td>' + (toThousands(val.kwh.toFixed(2))) + '</td>' +
'<td>' + (toThousands(val.kwhkwp.toFixed(2))) + '</td>' + '<td>' + (toThousands(avgdaykwh.toFixed(2))) + '</td>' +//val.kwhkwp
'<td>' + (toThousands(nowDisplayIrrDay)) + '</td>' + //irrDay '<td>' + (toThousands(nowDisplayIrrDay)) + '</td>' +
//'<td>' + val.irradiance.toFixed(2) + '</td>' +
'<td>' + (toThousands(val.pr.toFixed(2))) + '</td>' + '<td>' + (toThousands(val.pr.toFixed(2))) + '</td>' +
'<td>' + (toThousands(val.temp.toFixed(2))) + '</td>' + '<td>' + (toThousands(val.temp.toFixed(2))) + '</td>' +
'</tr>'); '</tr>');
@ -2721,25 +2764,33 @@
listtemperature.push(parseFloat(val.temp.toFixed(2))); listtemperature.push(parseFloat(val.temp.toFixed(2)));
listsolarhour.push(parseFloat(val.solarhour.toFixed(2))); listsolarhour.push(parseFloat(val.solarhour.toFixed(2)));
listpr.push(parseFloat(val.pr.toFixed(2))); listpr.push(parseFloat(val.pr.toFixed(2)));
listkwhkwp.push(parseFloat(val.kwhkwp.toFixed(2))); listkwhkwp.push(parseFloat(avgdaykwh));//val.kwhkwp
} }
else else
{ {
if (groupType == 0 && kwhkwp < val.kwhkwp.toFixed(2)) { if (groupType == 0 && kwhkwp < val.kwhkwp.toFixed(2)) {
kwhkwp = val.kwhkwp.toFixed(2); kwhkwp = val.kwhkwp.toFixed(2);
} }
if (groupType != 0) { if (groupType != 0 && groupType != 3) {
ALLkwhkwp += val.kwhkwp; ALLkwhkwp += val.kwhkwp;
kwhkwp = (ALLkwhkwp / times).toFixed(2); kwhkwp = (ALLkwhkwp / times).toFixed(2);
times++; times++;
} }
if (groupType == 3) {
ALLDays += val.days;
avgdaykwh = (val.kwh / val.generatingCapacity / val.days);
ALLavgdaykwh += avgdaykwh;
}
else {
avgdaykwh = val.kwhkwp;
}
diffSOLARHOURALL += val.diffSOLARHOUR; diffSOLARHOURALL += val.diffSOLARHOUR;
$('#HistoryDetailTable').append('<tr>' + $('#HistoryDetailTable').append('<tr>' +
'<td>' + val.timestamp + '</td>' + '<td>' + val.timestamp + '</td>' +
'<td>' + (toThousands(val.kwh.toFixed(2))) + '</td>' + '<td>' + (toThousands(val.kwh.toFixed(2))) + '</td>' +
'<td>' + (toThousands(val.kwhkwp.toFixed(2))) + '</td>' + '<td>' + (toThousands(avgdaykwh.toFixed(2))) + '</td>' +//val.kwhkwp
'<td>' + (toThousands(val.irrDay.toFixed(2))) + '</td>' +
//'<td>' + val.irradiance.toFixed(2) + '</td>' +
'<td>' + (toThousands(val.pr.toFixed(2))) + '</td>' + '<td>' + (toThousands(val.pr.toFixed(2))) + '</td>' +
'<td>' + (toThousands(val.temp.toFixed(2))) + '</td>' + '<td>' + (toThousands(val.temp.toFixed(2))) + '</td>' +
'</tr>'); '</tr>');
@ -2752,7 +2803,7 @@
listtemperature.push(parseFloat(val.temp.toFixed(2))); listtemperature.push(parseFloat(val.temp.toFixed(2)));
listsolarhour.push(parseFloat(val.solarhour.toFixed(2))); listsolarhour.push(parseFloat(val.solarhour.toFixed(2)));
listpr.push(parseFloat(val.pr.toFixed(2))); listpr.push(parseFloat(val.pr.toFixed(2)));
listkwhkwp.push(parseFloat(val.kwhkwp.toFixed(2))); listkwhkwp.push(parseFloat(avgdaykwh));//val.kwhkwp
} }
} }
}) })
@ -2874,10 +2925,18 @@
} }
else else
{ {
var avgK = 0;
if (groupType == 3) {
avgK = (ALLavgdaykwh / rel.data.length).toFixed(2);//(kwhALL / rel.data[0].generatingCapacity / ALLDays).toFixed(2);
}
else {
avgK = kwhkwp;
}
$('#HistoryTotalTable').append('<tr>' + $('#HistoryTotalTable').append('<tr>' +
'<td>' + TimestampALL + '</td>' + '<td>' + TimestampALL + '</td>' +
'<td>' + (toThousands(kwhALL.toFixed(2))) + '</td>' + '<td>' + (toThousands(kwhALL.toFixed(2))) + '</td>' +
'<td>' + (toThousands(kwhkwp)) + '</td>' + '<td>' + (toThousands(avgK)) + '</td>' +
//'<td>' + irradianceALL.toFixed(2) + '</td>' + // 改成累積日照 by jiahao 2022-04-30 00:444 //'<td>' + irradianceALL.toFixed(2) + '</td>' + // 改成累積日照 by jiahao 2022-04-30 00:444
'<td>' + (toThousands(avgIrr_day.toFixed(2))) + '</td>' + '<td>' + (toThousands(avgIrr_day.toFixed(2))) + '</td>' +
'<td>' + (toThousands(avgPR.toFixed(2))) + '</td>' + '<td>' + (toThousands(avgPR.toFixed(2))) + '</td>' +

View File

@ -219,7 +219,7 @@
</div> </div>
<div class="mb-3 d-flex justify-content-start"> <div class="mb-3 d-flex justify-content-start">
<div class="pr-3"> <div class="pr-3">
<button type="button" class="btn btn-primary waves-effect waves-themed" onclick="ExportExcel()"><span class="fal fa-file-excel mr-1"></span> 匯出</button> <button type="button" class="btn btn-primary waves-effect waves-themed ml-1 btn-report" onclick="ExportExcel()" id="exportBtn"><span class="fal fa-file-excel mr-1"></span> 匯出</button>
</div> </div>
<div class="row"> <div class="row">
<div class="pr-3" id="selectOneStation"> <div class="pr-3" id="selectOneStation">
@ -874,7 +874,7 @@
str += "<th>掛錶日期</th>"; str += "<th>掛錶日期</th>";
/*str += "<th>裝置容量</th>";*/ /*str += "<th>裝置容量</th>";*/
str += "<th>躉售費率</th>"; str += "<th>躉售費率</th>";
str += "<th>每kw日均獲利</th>"; str += "<th>日均獲利</th>";
str += "<th>日均發電度數</th>"; str += "<th>日均發電度數</th>";
str += "<th>發電量</th>"; str += "<th>發電量</th>";
str += "<th>PR</th>"; str += "<th>PR</th>";
@ -1024,25 +1024,27 @@
sta += "<td>" + toThousands(Number(inverter[i]).toFixed(2)) + "</td>"; sta += "<td>" + toThousands(Number(inverter[i]).toFixed(2)) + "</td>";
} }
}); });
sta += "<td>" + toThousands(Number(inverter.hourKWH)) + "</td>"; sta += "<td>" + ((inverter.hourKWH == null) ? 0 : toThousands(Number(inverter.hourKWH).toFixed(2))) + "</td>";
sta += "<td>" + toThousands(Number(inverter.hourKWHp)) + "</td>"; sta += "<td>" + ((inverter.hourKWHp == null) ? 0 : toThousands(Number(inverter.hourKWHp).toFixed(2))) + "</td>";
sta += "<td>" + toThousands(Number(inverter.irrDayHour)) + "</td>"; // body 小時平均日照度 irradiance sta += "<td>" + ((inverter.irrDayHour == null) ? 0 : toThousands(Number(inverter.irrDayHour).toFixed(2))) + "</td>"; // body 小時平均日照度 irradiance
sta += "<td>" + toThousands(Number(inverter.temperature)) + "</td>"; //body 小時平均模組溫度 sta += "<td>" + ((inverter.temperature == null) ? 0 : toThousands(Number(inverter.temperature).toFixed(2))) + "</td>";//body 小時平均模組溫度
if (showmoney == 1) { if (showmoney == 1) {
sta += "<td>" + toThousands(Math.round(Number(inverter.hourmoney))) + "</td>"; sta += "<td>" + ((inverter.hourmoney == null) ? 0 : toThousands(Number(inverter.hourmoney).toFixed(2))) + "</td>";
} }
sta += "</tr>"; sta += "</tr>";
if (index < rel.data.length - 1) {
thour = inverter.tothour ? inverter.tothour.toFixed(2) : 0; thour = inverter.tothour ? inverter.tothour.toFixed(2) : 0;
tpr = inverter.pr ? inverter.pr.toFixed(2) : 0; tpr = inverter.pr ? inverter.pr.toFixed(2) : 0;
tkwh = inverter.totKWH ? inverter.totKWH.toFixed(2) : 0; tkwh = inverter.totKWH ? inverter.totKWH.toFixed(2) : 0;
kWhkwp = inverter.totKWHKWP ? inverter.totKWHKWP.toFixed(2) : 0; // 日報 有效發電小時 //kWhkwp = inverter.totKWHKWP ? inverter.totKWHKWP.toFixed(2) : 0; // 日報 有效發電小時
ntd = inverter.totmoney ? Math.round(inverter.totmoney) : 0; kWhkwp = inverter.totKWHKWP ? (inverter.totKWH / inverter.GeneratingCapacity).toFixed(2) : 0; // 日報 有效發電小時
ntdone = inverter.totmoney / inverter.totKWH ? Math.round(inverter.totmoney / inverter.totKWH * 10000) / 10000 : 0; ntd = inverter.totmoney ? inverter.totmoney.toFixed(2) : 0;
GeneratingCapacity = inverter.GeneratingCapacity; ntdone = inverter.totmoney / inverter.totKWH ? (inverter.totmoney / inverter.totKWH).toFixed(2) : 0;
averageDailyProfit = ntd / GeneratingCapacity ? Math.round(ntd / GeneratingCapacity * 10000) / 10000 : 0; GeneratingCapacity = inverter.GeneratingCapacity ? inverter.GeneratingCapacity.toFixed(2) : 0;
averageDailyProfit = ntd / GeneratingCapacity ? (ntd / GeneratingCapacity).toFixed(2) : 0;
}
}) })
var stc = "<tr>"; var stc = "<tr>";
/* stc += "<th>" + '日照小時' + "</th>";*/
stc += "<th>" + '日均發電度數' + "</th>"; stc += "<th>" + '日均發電度數' + "</th>";
stc += "<th>" + 'PR%' + "</th>"; stc += "<th>" + 'PR%' + "</th>";
stc += "<th>" + '日發電量(kWh)' + "</th>"; stc += "<th>" + '日發電量(kWh)' + "</th>";
@ -1057,14 +1059,14 @@
var stb = "<tr>"; var stb = "<tr>";
/* stb += "<td>" + thour + "</td>";*/ /* stb += "<td>" + thour + "</td>";*/
stb += "<td>" + toThousands(kWhkwp) + "</td>"; //header - 有效發電小時 stb += "<td>" + toThousands(kWhkwp) + "</td>"; //header - 有效發電小時 kWhkwp
stb += "<td>" + toThousands(tpr) + "</td>"; // stb += "<td>" + toThousands(tpr) + "</td>"; //
stb += "<td>" + toThousands(tkwh) + "</td>"; stb += "<td>" + toThousands(tkwh) + "</td>";
stb += "<td>" + toThousands(GeneratingCapacity) + "</td>"; stb += "<td>" + toThousands(GeneratingCapacity) + "</td>";
if (showmoney == 1) { if (showmoney == 1) {
stb += "<td>" + toThousands(Math.round(ntd)) + "</td>"; stb += "<td>" + toThousands(ntd) + "</td>";
stb += "<td>" + Math.round(ntdone * 10000) / 10000 + "</td>"; stb += "<td>" + toThousands(ntdone) + "</td>";
stb += "<td>" + toThousands(Math.round(averageDailyProfit)) + "</td>"; stb += "<td>" + toThousands(averageDailyProfit) + "</td>";
} }
stb += "</tr>"; stb += "</tr>";
@ -1095,32 +1097,34 @@
if (inverter[i] == null) { if (inverter[i] == null) {
sta += "<td>" + 0 + "</td>"; sta += "<td>" + 0 + "</td>";
} else { } else {
sta += "<td>" + toThousands(inverter[i]) + "</td>"; sta += "<td>" + toThousands(inverter[i].toFixed(2)) + "</td>";
} }
}); });
sta += "<td>" + toThousands(inverter.dayKWH) + "</td>"; sta += "<td>" + ((inverter.dayKWH == null) ? 0 : toThousands(inverter.dayKWH.toFixed(2))) + "</td>";
sta += "<td>" + ((inverter.dayKWHp == null) ? 0 : toThousands(inverter.dayKWHp)) + "</td>"; sta += "<td>" + ((inverter.dayKWHp == null) ? 0 : toThousands(inverter.dayKWHp.toFixed(2))) + "</td>";
sta += "<td>" + inverter.tothour + "</td>"; sta += "<td>" + ((inverter.tothour == null) ? 0 : toThousands(inverter.tothour.toFixed(2))) + "</td>";
sta += "<td>" + toThousands(inverter.KWHKWP) + "</td>"; sta += "<td>" + ((inverter.KWHKWP == null) ? 0 : toThousands(inverter.KWHKWP.toFixed(2))) + "</td>";
sta += "<td>" + ((inverter.PR == null) ? 0 : toThousands(inverter.PR.toFixed(2))) + "</td>"; sta += "<td>" + ((inverter.PR == null) ? 0 : toThousands(inverter.PR.toFixed(2))) + "</td>";
sta += "<td>" + ((inverter.IrrDay == null) ? 0 : toThousands(inverter.IrrDay)) + "</td>"; sta += "<td>" + ((inverter.IrrDay == null) ? 0 : toThousands(inverter.IrrDay.toFixed(2))) + "</td>";
sta += "<td>" + inverter.temperature + "</td>"; sta += "<td>" + ((inverter.temperature == null) ? 0 : toThousands(inverter.temperature.toFixed(2))) + "</td>";
if (showmoney == 1) { if (showmoney == 1) {
sta += "<td>" + toThousands(Math.round(inverter.soldmoney)) + "</td>"; sta += "<td>" + ((inverter.soldmoney == null) ? 0 : toThousands(inverter.soldmoney.toFixed(2))) + "</td>";
} }
sta += "</tr>"; sta += "</tr>";
if (index < rel.data.length - 1) {
avghour += inverter.tothour ? inverter.tothour : 0; avghour += inverter.tothour ? inverter.tothour : 0;
avgKWHKWP += inverter.KWHKWP ? inverter.KWHKWP : 0; avgKWHKWP += inverter.KWHKWP ? inverter.KWHKWP : 0;
avgdayKWH += inverter.dayKWH ? inverter.dayKWH : 0; avgdayKWH += inverter.dayKWH ? inverter.dayKWH : 0;
monthKWH = inverter.monthKWH ? inverter.monthKWH : 0; monthKWH = inverter.monthKWH ? inverter.monthKWH : 0;
monthmoney = inverter.monthmoney ? inverter.monthmoney : 0; monthmoney = inverter.monthmoney ? inverter.monthmoney : 0;
}
if (inverter.SolarType == 1) { if (inverter.SolarType == 1) {
check_hire = true; check_hire = true;
sitedb = inverter.SiteDB sitedb = inverter.SiteDB
} }
GeneratingCapacity = inverter.GeneratingCapacity; GeneratingCapacity = inverter.GeneratingCapacity;
averageDailyProfit = monthmoney / GeneratingCapacity ? Math.round(monthmoney / GeneratingCapacity * 10000) / 10000 : 0; averageDailyProfit = monthmoney / GeneratingCapacity ? (monthmoney / GeneratingCapacity) : 0;
}) })
monthday = (rel.data.length - 1);//最後一筆是總計 monthday = (rel.data.length - 1);//最後一筆是總計
monthmoneyone = rel.data[0].monthmoneyone ? rel.data[0].monthmoneyone : 0; monthmoneyone = rel.data[0].monthmoneyone ? rel.data[0].monthmoneyone : 0;
@ -1159,16 +1163,16 @@
} }
else { else {
/*stb += "<td>" + (avghour / monthday).toFixed(2) + "</td>";*/ /*stb += "<td>" + (avghour / monthday).toFixed(2) + "</td>";*/
stb += "<td>" + toThousands((avgKWHKWP / monthday).toFixed(2)) + "</td>"; stb += "<td>" + toThousands((monthKWH / GeneratingCapacity / monthday).toFixed(2)) + "</td>";
stb += "<td>" + toThousands((avgdayKWH / monthday).toFixed(2)) + "</td>"; stb += "<td>" + toThousands((monthKWH / monthday).toFixed(2)) + "</td>";
stb += "<td>" + toThousands(monthKWH) + "</td>"; stb += "<td>" + toThousands(monthKWH.toFixed(2)) + "</td>";
stb += "<td>" + toThousands(GeneratingCapacity) + "</td>"; stb += "<td>" + toThousands(GeneratingCapacity.toFixed(2)) + "</td>";
if (showmoney == 1) { if (showmoney == 1) {
stb += "<td>" + toThousands((monthmoney / GeneratingCapacity).toFixed(3)) + "</td>"; stb += "<td>" + toThousands((monthmoney / GeneratingCapacity).toFixed(2)) + "</td>";
stb += "<td>" + toThousands(Math.round(monthmoney)) + "</td>"; stb += "<td>" + toThousands(monthmoney.toFixed(2)) + "</td>";
stb += "<td>" + monthmoneyone + "</td>"; stb += "<td>" + toThousands(monthmoneyone.toFixed(2)) + "</td>";
stb += "<td>" + toThousands(Math.round(averageDailyProfit / monthday)) + "</td>"; stb += "<td>" + toThousands((averageDailyProfit / monthday).toFixed(2)) + "</td>";
} }
stb += "<td>" + monthday + "</td>"; stb += "<td>" + monthday + "</td>";
stb += "</tr>"; stb += "</tr>";
@ -1191,8 +1195,8 @@
std += "<tr>"; std += "<tr>";
std += "<td>" + value.landowner + "</td>"; std += "<td>" + value.landowner + "</td>";
std += "<td>" + value.leaseRate + "%" + "</td>"; std += "<td>" + value.leaseRate + "%" + "</td>";
std += "<td>" + toThousands(Math.round(monthmoney * value.leaseRate / 100)) + "</td>"; std += "<td>" + toThousands((monthmoney * value.leaseRate / 100).toFixed(2)) + "</td>";
std += "<td>" + toThousands(Math.round(monthmoney * value.leaseRate / 100 * 1.05)) + "</td>"; std += "<td>" + toThousands((monthmoney * value.leaseRate / 100 * 1.05).toFixed(2)) + "</td>";
std += "</tr>"; std += "</tr>";
}) })
$('#HireTableBody').append(std); $('#HireTableBody').append(std);
@ -1217,6 +1221,8 @@
var monthmoneyone = 0; var monthmoneyone = 0;
var monthday = 0; var monthday = 0;
var averageDailyProfit = 0; var averageDailyProfit = 0;
var generatingCapacity = 0;
var days = 0;
var sta = ""; var sta = "";
var check_hire = false; var check_hire = false;
var sitedb = ""; var sitedb = "";
@ -1227,27 +1233,28 @@
if (inverter[i] == null) { if (inverter[i] == null) {
sta += "<td>" + 0 + "</td>"; sta += "<td>" + 0 + "</td>";
} else { } else {
sta += "<td>" + toThousands(inverter[i]) + "</td>"; sta += "<td>" + toThousands(inverter[i].toFixed(2)) + "</td>";
} }
}); });
sta += "<td>" + toThousands(inverter.dayKWH) + "</td>"; sta += "<td>" + ((inverter.dayKWH == null) ? 0 : toThousands(inverter.dayKWH.toFixed(2))) + "</td>";
sta += "<td>" + toThousands(inverter.dayKWHp) + "</td>"; sta += "<td>" + ((inverter.dayKWHp == null) ? 0 : toThousands(inverter.dayKWHp.toFixed(2))) + "</td>";
sta += "<td>" + toThousands(inverter.tothour) + "</td>"; sta += "<td>" + ((inverter.tothour == null) ? 0 : toThousands(inverter.tothour.toFixed(2))) + "</td>";
sta += "<td>" + toThousands(inverter.KWHKWP) + "</td>"; sta += "<td>" + ((inverter.KWHKWP == null) ? 0 : toThousands(inverter.KWHKWP.toFixed(2))) + "</td>";
sta += "<td>" + toThousands(inverter.PR.toFixed(2)) + "</td>"; sta += "<td>" + ((inverter.PR == null) ? 0 : toThousands(inverter.PR.toFixed(2))) + "</td>";
sta += "<td>" + toThousands(inverter.irradiance) + "</td>"; sta += "<td>" + ((inverter.irradiance == null) ? 0 : toThousands(inverter.irradiance.toFixed(2))) + "</td>";
sta += "<td>" + toThousands(inverter.temperature) + "</td>"; sta += "<td>" + ((inverter.temperature == null) ? 0 : toThousands(inverter.temperature.toFixed(2))) + "</td>";
if (showmoney == 1) { if (showmoney == 1) {
sta += "<td>" + toThousands(Math.round(inverter.soldmoney)) + "</td>"; sta += "<td>" + ((inverter.soldmoney == null) ? 0 : toThousands(inverter.soldmoney.toFixed(2))) + "</td>";
} }
sta += "</tr>"; sta += "</tr>";
avghour += inverter.tothour ? inverter.tothour : 0; avghour += inverter.tothour ? inverter.tothour : 0;
avgKWHKWP += inverter.KWHKWP ? inverter.KWHKWP : 0; avgKWHKWP += inverter.KWHKWP ? inverter.KWHKWP : 0;
avgdayKWH += inverter.dayKWH ? inverter.dayKWH : 0; avgdayKWH += inverter.dayKWH ? inverter.dayKWH : 0;
monthKWH = inverter.monthKWH ? toThousands(inverter.monthKWH) : 0; monthKWH = inverter.monthKWH ? inverter.monthKWH : 0;
monthmoney = inverter.monthmoney ? inverter.monthmoney : 0; monthmoney = inverter.monthmoney ? inverter.monthmoney : 0;
generatingCapacity = inverter.GeneratingCapacity ? inverter.GeneratingCapacity : 0;
averageDailyProfit = monthmoney / inverter.GeneratingCapacity ? Math.round(monthmoney / inverter.GeneratingCapacity * 10000) / 10000 : 0; averageDailyProfit = monthmoney / inverter.GeneratingCapacity ? (monthmoney / inverter.GeneratingCapacity) : 0;
if (inverter.SolarType == 1) { if (inverter.SolarType == 1) {
check_hire = true; check_hire = true;
@ -1255,13 +1262,16 @@
} }
}) })
monthday = rel.data.length; monthday = (rel.data.length - 1);
monthmoneyone = rel.data[0].monthmoneyone ? rel.data[0].monthmoneyone : 0; monthmoneyone = rel.data[0].monthmoneyone ? rel.data[0].monthmoneyone : 0;
//ntdone = inverter.totmoney / inverter.totKWH ? (inverter.totmoney / inverter.totKWH).toFixed(2) : 0;
days = rel.data[0].Days;
var stc = "<tr>"; var stc = "<tr>";
stc += "<th>" + '日照平均(月)' + "</th>"; stc += "<th>" + '日照平均(月)' + "</th>";
stc += "<th>" + '日均發電度數(月)' + "</th>"; stc += "<th>" + '日均發電度數(月)' + "</th>";
stc += "<th>" + '裝置容量' + "</th>";
stc += "<th>" + '發電量平均(kWh)(月)' + "</th>"; stc += "<th>" + '發電量平均(kWh)(月)' + "</th>";
stc += "<th>" + '發電量(kWh)(年)' + "</th>"; stc += "<th>" + '發電量(kWh)(年)' + "</th>";
if (showmoney == 1) { if (showmoney == 1) {
@ -1287,16 +1297,18 @@
stb += "</tr>"; stb += "</tr>";
} }
else { else {
stb += "<td>" + (avghour / monthday).toFixed(2) + "</td>"; stb += "<td>" + toThousands((avghour / monthday).toFixed(2)) + "</td>";
stb += "<td>" + (avgKWHKWP / monthday).toFixed(2) + "</td>"; stb += "<td>" + toThousands((monthKWH / generatingCapacity).toFixed(2)) + "</td>";
stb += "<td>" + toThousands((avgdayKWH / monthday).toFixed(2)) + "</td>"; stb += "<td>" + toThousands(generatingCapacity.toFixed(2)) + "</td>";
stb += "<td>" + monthKWH + "</td>"; stb += "<td>" + toThousands((monthKWH / monthday).toFixed(2)) + "</td>";
stb += "<td>" + toThousands(monthKWH.toFixed(2)) + "</td>";
if (showmoney == 1) { if (showmoney == 1) {
stb += "<td>" + toThousands(Math.round(monthmoney)) + "</td>"; stb += "<td>" + toThousands(monthmoney.toFixed(2)) + "</td>";
stb += "<td>" + monthmoneyone + "</td>"; stb += "<td>" + toThousands(monthmoneyone.toFixed(2)) + "</td>";
stb += "<td>" + toThousands(Math.round((averageDailyProfit / monthday / 30 * 10000) / 10000)) + "</td>"; stb += "<td>" + toThousands((averageDailyProfit / days).toFixed(2)) + "</td>";
} }
stb += "<td>" + monthday + "</td>"; stb += "<td>" + toThousands(monthday) + "</td>";
stb += "</tr>"; stb += "</tr>";
} }
var std = ""; var std = "";
@ -1317,8 +1329,8 @@
std += "<tr>"; std += "<tr>";
std += "<td>" + value.landowner + "</td>"; std += "<td>" + value.landowner + "</td>";
std += "<td>" + toThousands(value.leaseRate) + "%" + "</td>"; std += "<td>" + toThousands(value.leaseRate) + "%" + "</td>";
std += "<td>" + toThousands(Math.round(monthmoney * value.leaseRate / 100)) + "</td>"; std += "<td>" + toThousands((monthmoney * value.leaseRate / 100).toFixed(2)) + "</td>";
std += "<td>" + toThousands(Math.round(monthmoney * value.leaseRate / 100 * 1.05)) + "</td>"; std += "<td>" + toThousands((monthmoney * value.leaseRate / 100 * 1.05).toFixed(2)) + "</td>";
std += "</tr>"; std += "</tr>";
}) })
$('#HireTableBody').append(std); $('#HireTableBody').append(std);
@ -1355,18 +1367,18 @@
if (inverter[i] == null) { if (inverter[i] == null) {
sta += "<td>" + 0 + "</td>"; sta += "<td>" + 0 + "</td>";
} else { } else {
sta += "<td>" + toThousands(inverter[i]) + "</td>"; sta += "<td>" + toThousands(inverter[i].toFixed(2)) + "</td>";
} }
}); });
sta += "<td>" + toThousands(inverter.dayKWH) + "</td>"; sta += "<td>" + ((inverter.dayKWH == null) ? 0 : toThousands(inverter.dayKWH.toFixed(2))) + "</td>";
sta += "<td>" + ((inverter.dayKWHp == null) ? 0 : toThousands(inverter.dayKWHp)) + "</td>"; sta += "<td>" + ((inverter.dayKWHp == null) ? 0 : toThousands(inverter.dayKWHp.toFixed(2))) + "</td>";
sta += "<td>" + inverter.tothour + "</td>"; sta += "<td>" + ((inverter.tothour == null) ? 0 : toThousands(inverter.tothour.toFixed(2))) + "</td>";
sta += "<td>" + toThousands(inverter.KWHKWP) + "</td>"; sta += "<td>" + ((inverter.KWHKWP == null) ? 0 : toThousands(inverter.KWHKWP.toFixed(2))) + "</td>";
sta += "<td>" + ((inverter.PR == null) ? 0 : toThousands(inverter.PR.toFixed(2))) + "</td>"; sta += "<td>" + ((inverter.PR == null) ? 0 : toThousands(inverter.PR.toFixed(2))) + "</td>";
sta += "<td>" + ((inverter.IrrDay == null) ? 0 : toThousands(inverter.IrrDay)) + "</td>"; sta += "<td>" + ((inverter.IrrDay == null) ? 0 : toThousands(inverter.IrrDay.toFixed(2))) + "</td>";
sta += "<td>" + inverter.temperature + "</td>"; sta += "<td>" + ((inverter.temperature == null) ? 0 : toThousands(inverter.temperature.toFixed(2))) + "</td>";
if (showmoney == 1) { if (showmoney == 1) {
sta += "<td>" + toThousands(Math.round(inverter.soldmoney)) + "</td>"; sta += "<td>" + ((inverter.soldmoney == null) ? 0 : toThousands(inverter.soldmoney.toFixed(2))) + "</td>";
} }
sta += "</tr>"; sta += "</tr>";
avghour += inverter.tothour ? inverter.tothour : 0; avghour += inverter.tothour ? inverter.tothour : 0;
@ -1381,9 +1393,9 @@
sitedb = inverter.SiteDB sitedb = inverter.SiteDB
} }
GeneratingCapacity = inverter.GeneratingCapacity; GeneratingCapacity = inverter.GeneratingCapacity;
averageDailyProfit = monthmoney / GeneratingCapacity ? Math.round(monthmoney / GeneratingCapacity * 10000) / 10000 : 0; averageDailyProfit = monthmoney / GeneratingCapacity ? (monthmoney / GeneratingCapacity) : 0;
}) })
monthday = rel.data.length; monthday = (rel.data.length - 1);
var stc = "<tr>"; var stc = "<tr>";
@ -1419,18 +1431,19 @@
} }
else { else {
/*stb += "<td>" + (avghour / monthday).toFixed(2) + "</td>";*/ /*stb += "<td>" + (avghour / monthday).toFixed(2) + "</td>";*/
stb += "<td>" + toThousands((avgKWHKWP / monthday).toFixed(2)) + "</td>"; //stb += "<td>" + toThousands((avgKWHKWP / monthday).toFixed(2)) + "</td>";
stb += "<td>" + toThousands((monthKWH / GeneratingCapacity).toFixed(2)) + "</td>";
stb += "<td>" + toThousands((avgdayKWH / monthday).toFixed(2)) + "</td>"; stb += "<td>" + toThousands((avgdayKWH / monthday).toFixed(2)) + "</td>";
stb += "<td>" + toThousands(monthKWH) + "</td>"; stb += "<td>" + toThousands(monthKWH.toFixed(2)) + "</td>";
stb += "<td>" + toThousands(GeneratingCapacity) + "</td>"; stb += "<td>" + toThousands(GeneratingCapacity.toFixed(2)) + "</td>";
if (showmoney == 1) { if (showmoney == 1) {
stb += "<td>" + toThousands((monthmoney / GeneratingCapacity).toFixed(3)) + "</td>"; stb += "<td>" + toThousands((monthmoney / GeneratingCapacity).toFixed(2)) + "</td>";
stb += "<td>" + toThousands(Math.round(monthmoney)) + "</td>"; stb += "<td>" + toThousands(monthmoney.toFixed(2)) + "</td>";
stb += "<td>" + Math.round(monthmoneyone / monthday * 10000) / 10000 + "</td>"; stb += "<td>" + toThousands(monthmoneyone / monthday.toFixed(2)) + "</td>";
stb += "<td>" + toThousands(Math.round(averageDailyProfit / monthday)) + "</td>"; stb += "<td>" + toThousands((averageDailyProfit / monthday).toFixed(2)) + "</td>";
} }
stb += "<td>" + monthday + "</td>"; stb += "<td>" + toThousands(monthday) + "</td>";
stb += "</tr>"; stb += "</tr>";
} }
var std = ""; var std = "";
@ -1451,8 +1464,8 @@
std += "<tr>"; std += "<tr>";
std += "<td>" + value.landowner + "</td>"; std += "<td>" + value.landowner + "</td>";
std += "<td>" + value.leaseRate + "%" + "</td>"; std += "<td>" + value.leaseRate + "%" + "</td>";
std += "<td>" + toThousands(Math.round(monthmoney * value.leaseRate / 100)) + "</td>"; std += "<td>" + toThousands((monthmoney * value.leaseRate / 100).toFixed(2)) + "</td>";
std += "<td>" + toThousands(Math.round(monthmoney * value.leaseRate / 100 * 1.05)) + "</td>"; std += "<td>" + toThousands((monthmoney * value.leaseRate / 100 * 1.05).toFixed(2)) + "</td>";
std += "</tr>"; std += "</tr>";
}) })
$('#HireTableBody').append(std); $('#HireTableBody').append(std);
@ -1477,6 +1490,8 @@
} }
function ExportExcel() { function ExportExcel() {
$("#exportBtn").html('<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>').attr("disabled", true);
var send_data = var send_data =
{ {
SearchType: searchType, SearchType: searchType,
@ -1491,10 +1506,12 @@
$("#post").val(JSON.stringify(send_data)); $("#post").val(JSON.stringify(send_data));
document.report.action = "StationReport/ExportExcel"; document.report.action = "StationReport/ExportExcel";
document.report.submit(); document.report.submit();
$("#exportBtn").html('<span class="fal fa-file-excel mr-1"></span> 匯出').attr("disabled", false);
return; return;
} }
else else
{ {
$("#exportBtn").html('<span class="fal fa-file-excel mr-1"></span> 匯出').attr("disabled", false);
var text = "原因如下:<br\>"; var text = "原因如下:<br\>";
$.each(rel.data, function (index, val) { $.each(rel.data, function (index, val) {
text += index + 1 + "." + val + "<br\>"; text += index + 1 + "." + val + "<br\>";
@ -1517,6 +1534,7 @@
{ {
window.location = "/StationReport/ExportExcelmaxtable?post=" + JSON.stringify(send_data); window.location = "/StationReport/ExportExcelmaxtable?post=" + JSON.stringify(send_data);
} }
$("#exportBtn").html('<span class="fal fa-file-excel mr-1"></span> 匯出').attr("disabled", false);
} }
} }
// 綜合比較 // 綜合比較
@ -1625,17 +1643,17 @@
/*StrInfoBody += "<td>" + data.generatingCapacity.toFixed(2) + "</td>";*/ /*StrInfoBody += "<td>" + data.generatingCapacity.toFixed(2) + "</td>";*/
StrInfoBody += "<td>" + data.powerRate.toFixed(2) + "</td>"; StrInfoBody += "<td>" + data.powerRate.toFixed(2) + "</td>";
StrInfoBody += "<td>" + toThousands((data.todayMoney / data.generatingCapacity / data.days).toFixed(2)) + "</td>";//每kw日均獲利 StrInfoBody += "<td>" + toThousands((data.todayMoney / data.generatingCapacity / data.days).toFixed(2)) + "</td>";//每kw日均獲利
StrInfoBody += "<td>" + toThousands(data.avgKWHKWP.toFixed(2)) + "</td>"; // 日均發電度數 StrInfoBody += "<td>" + toThousands((data.kwh / data.generatingCapacity).toFixed(2)) + "</td>"; // 日均發電度數
StrInfoBody += "<td>" + toThousands(data.kwh.toFixed(2)) + "</td>"; // 發電量 StrInfoBody += "<td>" + toThousands(data.kwh.toFixed(2)) + "</td>"; // 發電量
/*StrInfoBody += "<td>" + toThousands(data.irradiance.toFixed(2)) + "</td>"; // 累積日照*/ /*StrInfoBody += "<td>" + toThousands(data.irradiance.toFixed(2)) + "</td>"; // 累積日照*/
StrInfoBody += "<td>" + toThousands(data.avgPR.toFixed(2)) + "</td>"; StrInfoBody += "<td>" + toThousands(data.avgPR.toFixed(2)) + "</td>";
if (showmoney == 1) { if (showmoney == 1) {
StrInfoBody += "<td>" + toThousands(Math.round(data.todayMoney, 2)) + "</td>"; StrInfoBody += "<td>" + toThousands(data.todayMoney.toFixed(2)) + "</td>";
StrInfoBody += "<td>" + Math.round(data.todayMoney * hirerate * 0.01, 2)+ "</td>"; StrInfoBody += "<td>" + toThousands((data.todayMoney * hirerate * 0.01).toFixed(2)) + "</td>";
StrInfoBody += "<td>" + toThousands(Math.round(data.todayMoney, 2)) + "</td>"; StrInfoBody += "<td>" + toThousands(data.todayMoney.toFixed(2)) + "</td>";
} }
@ -1650,7 +1668,7 @@
$.each(CityArray, function (index, data) { $.each(CityArray, function (index, data) {
CityInfoBody += "<tr>"; CityInfoBody += "<tr>";
CityInfoBody += "<td>" + data.city + "</td>"; CityInfoBody += "<td>" + data.city + "</td>";
CityInfoBody += "<td>" + data.generatingCapacity.toFixed(2) + "</td>"; CityInfoBody += "<td>" + toThousands(data.generatingCapacity.toFixed(2)) + "</td>";
CityInfoBody += "<td>" + toThousands(data.kwp.toFixed(2)) + "</td>"; CityInfoBody += "<td>" + toThousands(data.kwp.toFixed(2)) + "</td>";
CityInfoBody += "<td>" + toThousands((data.kwp / data.generatingCapacity).toFixed(2)) + "</td>"; CityInfoBody += "<td>" + toThousands((data.kwp / data.generatingCapacity).toFixed(2)) + "</td>";
CityInfoBody += "</tr>"; CityInfoBody += "</tr>";

View File

@ -11,16 +11,8 @@
<li class="position-absolute pos-top pos-right d-none d-sm-block"><span class="js-get-date"></span></li> <li class="position-absolute pos-top pos-right d-none d-sm-block"><span class="js-get-date"></span></li>
</ol> </ol>
<link rel="stylesheet" href="~/css/loading.css" /> <div class="d-flex justify-content-center text-secondary" style="top: 10%; transform: translateY(50%); z-index: 100; position: relative;">
<div class="loadEffect" id="loading" style="top: 10%;"> <div class="spinner-border" role="status" style="width: 3rem; height: 3rem; display:none;" id="loading"></div>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div> </div>
<div class="row"> <div class="row">

View File

@ -1,86 +0,0 @@
.loadEffect {
z-index: 9999;
left: 50%;
transform: translate(-50%,-50%);
width: 100px;
height: 100px;
position: absolute;
margin: 0 auto;
margin-top: 100px;
display: none;
}
.loadEffect span {
display: inline-block;
width: 13px;
height: 13px;
border-radius: 50%;
background: black;
position: absolute;
-webkit-animation: load 1.04s ease infinite;
}
@-webkit-keyframes load {
0% {
opacity: 1;
}
100% {
opacity: 0.2;
}
}
.loadEffect span:nth-child(1) {
left: 0;
top: 50%;
margin-top: -8px;
-webkit-animation-delay: 0.13s;
}
.loadEffect span:nth-child(2) {
left: 14px;
top: 14px;
-webkit-animation-delay: 0.26s;
}
.loadEffect span:nth-child(3) {
left: 50%;
top: 0;
margin-left: -8px;
-webkit-animation-delay: 0.39s;
}
.loadEffect span:nth-child(4) {
top: 14px;
right: 14px;
-webkit-animation-delay: 0.52s;
}
.loadEffect span:nth-child(5) {
right: 0;
top: 50%;
margin-top: -8px;
-webkit-animation-delay: 0.65s;
}
.loadEffect span:nth-child(6) {
right: 14px;
bottom: 14px;
-webkit-animation-delay: 0.78s;
}
.loadEffect span:nth-child(7) {
bottom: 0;
left: 50%;
margin-left: -8px;
-webkit-animation-delay: 0.91s;
}
.loadEffect span:nth-child(8) {
bottom: 14px;
left: 14px;
-webkit-animation-delay: 1.04s;
}

View File

@ -14,7 +14,7 @@ namespace solarApp.Service
public class getStationSvc public class getStationSvc
{ {
string Connection1 = ConfigurationManager.ConnectionStrings["mySql"].ConnectionString; string Connection1 = ConfigurationManager.ConnectionStrings["mySql"].ConnectionString;
protected string tableName = "power_station"; protected string tableName = "power_station_for_calc_test";//"power_station";
/// <summary> /// <summary>
/// 電站 Raw Data /// 電站 Raw Data
/// </summary> /// </summary>

View File

@ -9,6 +9,7 @@ using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using solarApp.Service; using solarApp.Service;
using solarApp.Model; using solarApp.Model;
//using System.Text.RegularExpressions;
namespace solarApp namespace solarApp
{ {
@ -699,5 +700,24 @@ namespace solarApp
autoTask = false; autoTask = false;
lbMsgTitle.Text = System.DateTime.Now.ToString() + " invdayhour - 完成!"; lbMsgTitle.Text = System.DateTime.Now.ToString() + " invdayhour - 完成!";
} }
//test for email format
//private void button3_Click(object sender, EventArgs e)
//{
// if(IsValidEmail(textBox2.Text))
// {
// label3.Text = "OK";
// }
// else
// {
// label3.Text = "X";
// }
//}
//bool IsValidEmail(string strIn)
//{
// // Return true if strIn is in valid e-mail format.
// return Regex.IsMatch(strIn, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
//}
} }
} }