綜合報表(Excel)

This commit is contained in:
b110212000 2021-08-09 15:11:32 +08:00
parent a31611b625
commit 671535e692
4 changed files with 527 additions and 79 deletions

View File

@ -1257,6 +1257,16 @@ namespace SolarPower.Controllers
stylein12.WrapText = true; stylein12.WrapText = true;
#endregion #endregion
var Formbody = GetMaxForm(postObject); var Formbody = GetMaxForm(postObject);
Select_table select_Table = new Select_table
{
FormType = postObject.FormType,
SearchType = postObject.SearchType,
Time = postObject.Time,
PowerStation = 1,
Userid = postObject.Userid
};
var Formhead = GetTableHead(select_Table);//取head
var sheet = workbook.CreateSheet("綜合報表"); var sheet = workbook.CreateSheet("綜合報表");
int RowPosition = 0; int RowPosition = 0;
int index = 0; int index = 0;
@ -1301,6 +1311,45 @@ namespace SolarPower.Controllers
cell.SetCellValue(Math.Round(form.AvgPR,2)); cell.SetCellValue(Math.Round(form.AvgPR,2));
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
if (Formhead.Result.Data.ShowMoney == 1)
{
index++;
cell = row.CreateCell(index);
cell.SetCellValue(Math.Round(form.TodayMoney, 2));
cell.CellStyle = styleLine12;
PsIdAndSiteDB psIdAndSiteDB = new PsIdAndSiteDB()
{
PowerstationId = form.PowerstationId,
SiteDB = form.PowerstationDB
};
var LeaseRate = 0;
if(form.PowerstationType == 1)
{
var Hire = GetHireInfo(psIdAndSiteDB);
foreach (var a in Hire.Result.Data)
{
LeaseRate += Convert.ToInt32(a.LeaseRate);
}
}
index++;
cell = row.CreateCell(index);
cell.SetCellValue(Math.Round(form.TodayMoney * LeaseRate *0.01, 2));
cell.CellStyle = styleLine12;
index++;
cell = row.CreateCell(index);
cell.SetCellValue(Math.Round(form.TodayMoney, 2));
cell.CellStyle = styleLine12;
}
kwp += form.Kwh; kwp += form.Kwh;
kwhkwp += form.AvgKWHKWP; kwhkwp += form.AvgKWHKWP;
RowPosition++; RowPosition++;
@ -1338,6 +1387,12 @@ namespace SolarPower.Controllers
"平均日照", "平均日照",
"PR" "PR"
}; };
if (Formhead.Result.Data.ShowMoney == 1)
{
lasthead.Add("發電金額");
lasthead.Add("租金收入");
lasthead.Add("省電費用");
}
foreach (var head in lasthead) foreach (var head in lasthead)
{ {
sheet.SetColumnWidth(index, 4 * 160 * 8); sheet.SetColumnWidth(index, 4 * 160 * 8);
@ -1479,7 +1534,7 @@ namespace SolarPower.Controllers
index ++; index ++;
cell = row.CreateCell(index); cell = row.CreateCell(index);
cell.SetCellValue(Math.Round(kwhkwp, 2)); cell.SetCellValue(Math.Round(kwhkwp / Formbody.Result.Data.Count, 2));
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
region = new CellRangeAddress(RowPosition, RowPosition, index, index + 1); region = new CellRangeAddress(RowPosition, RowPosition, index, index + 1);
sheet.AddMergedRegion(region); sheet.AddMergedRegion(region);
@ -1501,7 +1556,354 @@ namespace SolarPower.Controllers
return File(ms, "application/vnd.ms-excel", "FIC太陽能監控平台" + "_" + "綜合報表" + "_" + postObject.Userid + Datename + ".xlsx"); return File(ms, "application/vnd.ms-excel", "FIC太陽能監控平台" + "_" + "綜合報表" + "_" + postObject.Userid + Datename + ".xlsx");
} }
public string ExportExcelmaxtableBackDownload(string post)
{
var postObject = JsonConvert.DeserializeObject<Select_table2>(post);
var workbook = new XSSFWorkbook();
#region excel設定
IFont font12 = workbook.CreateFont();
font12.FontName = "新細明體";
font12.FontHeightInPoints = 12;
ICellStyle style12 = workbook.CreateCellStyle();
style12.SetFont(font12);
style12.Alignment = HorizontalAlignment.Center;
style12.VerticalAlignment = VerticalAlignment.Center;
IFont font12Times = workbook.CreateFont();
font12Times.FontName = "Times New Roman";
font12Times.FontHeightInPoints = 12;
IFont font18 = workbook.CreateFont();
font18.FontName = "新細明體";
font18.FontHeightInPoints = 18;
font18.IsBold = true;
ICellStyle styleTitle18 = workbook.CreateCellStyle();
styleTitle18.SetFont(font18);
styleTitle18.Alignment = HorizontalAlignment.Center;
styleTitle18.VerticalAlignment = VerticalAlignment.Center;
ICellStyle styleLeft12 = workbook.CreateCellStyle();
styleLeft12.SetFont(font12);
styleLeft12.Alignment = HorizontalAlignment.Left;
styleLeft12.VerticalAlignment = VerticalAlignment.Center;
ICellStyle styleLine12 = workbook.CreateCellStyle();
styleLine12.SetFont(font12);
styleLine12.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
styleLine12.VerticalAlignment = VerticalAlignment.Center;
styleLine12.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
styleLine12.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
styleLine12.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
styleLine12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
ICellStyle stylein12 = workbook.CreateCellStyle();
stylein12.SetFont(font12Times);
stylein12.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
stylein12.VerticalAlignment = VerticalAlignment.Center;
stylein12.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
stylein12.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
stylein12.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
stylein12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
stylein12.WrapText = true;
#endregion
var Formbody = GetMaxForm(postObject);
Select_table select_Table = new Select_table
{
FormType = postObject.FormType,
SearchType = postObject.SearchType,
Time = postObject.Time,
PowerStation = 1,
Userid = postObject.Userid
};
var Formhead = GetTableHead(select_Table);//取head
var sheet = workbook.CreateSheet("綜合報表");
int RowPosition = 0;
int index = 0;
var citycount = Formbody.Result.Data.GroupBy(a => a.CityName).Count();
RowPosition = citycount + 6;
IRow row;
ICell cell;
double kwhkwp = 0;
double kwp = 0;
CellRangeAddress region;
List<CityArray> cityArrays = new List<CityArray>();
foreach (var form in Formbody.Result.Data)
{
index = 0;
row = sheet.CreateRow(RowPosition);
cell = row.CreateCell(index);
cell.SetCellValue(form.CityName + form.AreaName);
cell.CellStyle = styleLine12;
index++;
cell = row.CreateCell(index);
cell.SetCellValue(form.PowerstationName);
cell.CellStyle = styleLine12;
index++;
cell = row.CreateCell(index);
cell.SetCellValue(Math.Round(form.Kwh, 2));
cell.CellStyle = styleLine12;
index++;
cell = row.CreateCell(index);
cell.SetCellValue(Math.Round(form.SolarHour, 2));
cell.CellStyle = styleLine12;
index++;
cell = row.CreateCell(index);
cell.SetCellValue(Math.Round(form.AvgIrradiance, 2));
cell.CellStyle = styleLine12;
index++;
cell = row.CreateCell(index);
cell.SetCellValue(Math.Round(form.AvgPR, 2));
cell.CellStyle = styleLine12;
if (Formhead.Result.Data.ShowMoney == 1)
{
index++;
cell = row.CreateCell(index);
cell.SetCellValue(Math.Round(form.TodayMoney, 2));
cell.CellStyle = styleLine12;
PsIdAndSiteDB psIdAndSiteDB = new PsIdAndSiteDB()
{
PowerstationId = form.PowerstationId,
SiteDB = form.PowerstationDB
};
var LeaseRate = 0;
if (form.PowerstationType == 1)
{
var Hire = GetHireInfo(psIdAndSiteDB);
foreach (var a in Hire.Result.Data)
{
LeaseRate += Convert.ToInt32(a.LeaseRate);
}
}
index++;
cell = row.CreateCell(index);
cell.SetCellValue(Math.Round(form.TodayMoney * LeaseRate * 0.01, 2));
cell.CellStyle = styleLine12;
index++;
cell = row.CreateCell(index);
cell.SetCellValue(Math.Round(form.TodayMoney, 2));
cell.CellStyle = styleLine12;
}
kwp += form.Kwh;
kwhkwp += form.AvgKWHKWP;
RowPosition++;
CityArray cityinfo = new CityArray
{
City = form.CityName,
Count = 1,
Kwh = form.Kwh,
SolarHour = form.SolarHour
};
if (cityArrays.Where(a => a.City == form.CityName).Count() > 0)
{
var city = cityArrays.Where(a => a.City == form.CityName).FirstOrDefault();
city.Count += cityinfo.Count;
city.Kwh += cityinfo.Kwh;
city.SolarHour += cityinfo.SolarHour;
}
else
{
cityArrays.Add(cityinfo);
}
}
RowPosition = citycount + 6;
RowPosition--;
row = sheet.CreateRow(RowPosition);
index = 0;
List<string> lasthead = new List<string>()
{
"區域",
"電站名稱",
"發電量",
"發電小時",
"平均日照",
"PR"
};
if (Formhead.Result.Data.ShowMoney == 1)
{
lasthead.Add("發電金額");
lasthead.Add("租金收入");
lasthead.Add("省電費用");
}
foreach (var head in lasthead)
{
sheet.SetColumnWidth(index, 4 * 160 * 8);
cell = row.CreateCell(index);
cell.SetCellValue(head);
cell.CellStyle = styleLine12;
index++;
}
RowPosition--;
RowPosition -= citycount;
var cityRowPosition = RowPosition;
index = 0;
foreach (var cityArray in cityArrays)
{
index = 0;
row = sheet.CreateRow(cityRowPosition);
cell = row.CreateCell(index);
cell.SetCellValue(cityArray.City);
cell.CellStyle = styleLine12;
region = new CellRangeAddress(cityRowPosition, cityRowPosition, index, index + 1);
sheet.AddMergedRegion(region);
index++;
cell = row.CreateCell(index);
cell.CellStyle = styleLine12;
index++;
cell = row.CreateCell(index);
cell.SetCellValue(Math.Round((cityArray.Kwh / cityArray.Count), 2));
cell.CellStyle = styleLine12;
region = new CellRangeAddress(cityRowPosition, cityRowPosition, index, index + 1);
sheet.AddMergedRegion(region);
index++;
cell = row.CreateCell(index);
cell.CellStyle = styleLine12;
index++;
cell = row.CreateCell(index);
cell.SetCellValue(Math.Round((cityArray.SolarHour / cityArray.Count), 2));
cell.CellStyle = styleLine12;
region = new CellRangeAddress(cityRowPosition, cityRowPosition, index, index + 1);
sheet.AddMergedRegion(region);
index++;
cell = row.CreateCell(index);
cell.CellStyle = styleLine12;
cityRowPosition++;
}
index = 0;
RowPosition--;
row = sheet.CreateRow(RowPosition);
cell = row.CreateCell(index);
cell.SetCellValue("縣市");
cell.CellStyle = styleLine12;
region = new CellRangeAddress(RowPosition, RowPosition, index, index + 1);
sheet.AddMergedRegion(region);
index++;
cell = row.CreateCell(index);
cell.CellStyle = styleLine12;
index++;
cell = row.CreateCell(index);
cell.SetCellValue("平均發電量(kWp)");
cell.CellStyle = styleLine12;
region = new CellRangeAddress(RowPosition, RowPosition, index, index + 1);
sheet.AddMergedRegion(region);
index++;
cell = row.CreateCell(index);
cell.CellStyle = styleLine12;
index++;
cell = row.CreateCell(index);
cell.SetCellValue("發電時間(小時)");
cell.CellStyle = styleLine12;
region = new CellRangeAddress(RowPosition, RowPosition, index, index + 1);
sheet.AddMergedRegion(region);
index++;
cell = row.CreateCell(index);
cell.CellStyle = styleLine12;
RowPosition = 0;
index = 0;
row = sheet.CreateRow(RowPosition);
cell = row.CreateCell(index);
cell.SetCellValue("時間");
cell.CellStyle = styleLine12;
region = new CellRangeAddress(RowPosition, RowPosition, index, index + 1);
sheet.AddMergedRegion(region);
index++;
cell = row.CreateCell(index);
cell.CellStyle = styleLine12;
index++;
cell = row.CreateCell(index);
cell.SetCellValue("發電量");
cell.CellStyle = styleLine12;
region = new CellRangeAddress(RowPosition, RowPosition, index, index + 1);
sheet.AddMergedRegion(region);
index++;
cell = row.CreateCell(index);
cell.CellStyle = styleLine12;
index++;
cell = row.CreateCell(index);
cell.SetCellValue("有效日照時數");
cell.CellStyle = styleLine12;
region = new CellRangeAddress(RowPosition, RowPosition, index, index + 1);
sheet.AddMergedRegion(region);
index++;
cell = row.CreateCell(index);
cell.CellStyle = styleLine12;
RowPosition++;
row = sheet.CreateRow(RowPosition);
index = 0;
cell = row.CreateCell(index);
cell.SetCellValue(postObject.Time);
cell.CellStyle = styleLine12;
region = new CellRangeAddress(RowPosition, RowPosition, index, index + 1);
sheet.AddMergedRegion(region);
index++;
cell = row.CreateCell(index);
cell.CellStyle = styleLine12;
index++;
cell = row.CreateCell(index);
cell.SetCellValue(Math.Round(kwp, 2));
cell.CellStyle = styleLine12;
region = new CellRangeAddress(RowPosition, RowPosition, index, index + 1);
sheet.AddMergedRegion(region);
index++;
cell = row.CreateCell(index);
cell.CellStyle = styleLine12;
index++;
cell = row.CreateCell(index);
cell.SetCellValue(Math.Round(kwhkwp / Formbody.Result.Data.Count, 2));
cell.CellStyle = styleLine12;
region = new CellRangeAddress(RowPosition, RowPosition, index, index + 1);
sheet.AddMergedRegion(region);
index++;
cell = row.CreateCell(index);
cell.CellStyle = styleLine12;
var Datename = postObject.Time.Replace("-", "");
if (!Directory.Exists(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "report")))
{
Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "report"));
}
if (!Directory.Exists(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "report", Datename)))
{
Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "report", Datename));
}
var n = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "report", Datename, "FIC太陽能監控平台" + "_" + "綜合報表" + "_" + postObject.Userid + Datename + ".xlsx");
FileStream FS = new FileStream(n, FileMode.Create, FileAccess.Write);
workbook.Write(FS);
FS.Close();
return Path.Combine("\\" + "upload", "report", Datename, "FIC太陽能監控平台" + "_" + "綜合報表" + "_" + postObject.Userid + Datename + ".xlsx");
}
} }

View File

@ -46,7 +46,10 @@ namespace SolarPower.Quartz.Jobs
continue; continue;
} }
List<Excelpowerstation> sentdaypowerstations = powerstations.Where(x => x.EmailDayReport == 1).Select(a => new Excelpowerstation {Name = a.Name,Value = a.PowerStationId.ToString()}).ToList(); List<Excelpowerstation> sentdaypowerstations = powerstations.Where(x => x.EmailDayReport == 1).Select(a => new Excelpowerstation {Name = a.Name,Value = a.PowerStationId.ToString()}).ToList();
List<Excelpowerstation> sentMaxpowerstations = powerstations.Where(x => x.EmailComplexReport == 1).Select(a => new Excelpowerstation { Name = a.Name, Value = a.PowerStationId.ToString() }).ToList();
Controllers.StationReportController stationReportController = new Controllers.StationReportController(powerStationRepository, stationReportRepository); Controllers.StationReportController stationReportController = new Controllers.StationReportController(powerStationRepository, stationReportRepository);
//日報表
if (sentdaypowerstations.Count != 0) if (sentdaypowerstations.Count != 0)
{ {
Excel dayexcel = new Excel() Excel dayexcel = new Excel()
@ -57,7 +60,6 @@ namespace SolarPower.Quartz.Jobs
Time = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"), Time = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"),
Userid = user.Id Userid = user.Id
}; };
var stationReportName = stationReportController.ExportExcelBackDownload(JsonConvert.SerializeObject(dayexcel, Formatting.Indented)); var stationReportName = stationReportController.ExportExcelBackDownload(JsonConvert.SerializeObject(dayexcel, Formatting.Indented));
NoticeSchedule DaySchedule = new NoticeSchedule() NoticeSchedule DaySchedule = new NoticeSchedule()
{ {
@ -76,7 +78,71 @@ namespace SolarPower.Quartz.Jobs
"Type" "Type"
}; };
await noticeScheduleRepository.AddOneAsync(DaySchedule, properties); await noticeScheduleRepository.AddOneAsync(DaySchedule, properties);
} }
//綜合報表 每日
if(sentMaxpowerstations.Count>0)
{
Select_table2 maxdayexcel = new Select_table2()
{
FormType = 0,
PowerStation = sentMaxpowerstations,
SearchType = 0,
Time = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"),
Userid = user.Id
};
var stationMaxReportName = stationReportController.ExportExcelmaxtableBackDownload(JsonConvert.SerializeObject(maxdayexcel, Formatting.Indented));
NoticeSchedule MaxSchedule = new NoticeSchedule()
{
RecipientEmail = user.Email,
Subject = "綜合報表",
Attachment = stationMaxReportName,
RecipientName = user.Name,
Type = 1
};
List<string> properties = new List<string>()
{
"RecipientEmail",
"Subject",
"Attachment",
"RecipientName",
"Type"
};
await noticeScheduleRepository.AddOneAsync(MaxSchedule, properties);
if (DateTime.Now.ToString("dd") == "01")
{
Select_table2 maxmonthexcel = new Select_table2()
{
FormType = 0,
PowerStation = sentMaxpowerstations,
SearchType = 0,
Time = DateTime.Now.AddDays(-1).ToString("yyyy-MM"),
Userid = user.Id
};
var stationReportmaxmonthName = stationReportController.ExportExcelBackDownload(JsonConvert.SerializeObject(maxmonthexcel, Formatting.Indented));
NoticeSchedule MaxmonthSchedule = new NoticeSchedule()
{
RecipientEmail = user.Email,
Subject = "綜合報表",
Attachment = stationReportmaxmonthName,
RecipientName = user.Name,
Type = 1
};
List<string> properties2 = new List<string>()
{
"RecipientEmail",
"Subject",
"Attachment",
"RecipientName",
"Type"
};
await noticeScheduleRepository.AddOneAsync(MaxmonthSchedule, properties2);
}
}
if(DateTime.Now.ToString("dd")=="01") if(DateTime.Now.ToString("dd")=="01")
{ {
List<Excelpowerstation> sentmonthpowerstations = powerstations.Where(x => x.EmailMonthReport == 1).Select(a => new Excelpowerstation { Name = a.Name, Value = a.PowerStationId.ToString() }).ToList(); List<Excelpowerstation> sentmonthpowerstations = powerstations.Where(x => x.EmailMonthReport == 1).Select(a => new Excelpowerstation { Name = a.Name, Value = a.PowerStationId.ToString() }).ToList();

View File

@ -60,7 +60,7 @@ namespace SolarPower.Repository.Implement
GROUP_CONCAT(DISTINCT GROUP_CONCAT(DISTINCT
CONCAT('max(case when INVERTERID = ''', INVERTERID, ''' then a.KWH end) ''inv_', right(INVERTERID, 4), '''') CONCAT('max(case when INVERTERID = ''', INVERTERID, ''' then a.KWH end) ''inv_', right(INVERTERID, 4), '''')
) INTO @sql ) INTO @sql
FROM inverter_history_hour; FROM inverter_history_hour where powerstationId = {post.PowerStation};
SET @sql = CONCAT('SELECT DATE_FORMAT(a.TIMESTAMP,''%m-%d %H'') report_date, ', @sql, SET @sql = CONCAT('SELECT DATE_FORMAT(a.TIMESTAMP,''%m-%d %H'') report_date, ', @sql,
', b.KWH hourKWH, round((b.KWH / (SELECT MAX(TODAYKWH) FROM power_station_history_hour WHERE DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'') = ''{post.Time}'' and powerstationid = {post.PowerStation}))*100,2) ''hourKWHp'', d.irradiance ''irradiance'', d.Temperature ''temperature'', ', b.KWH hourKWH, round((b.KWH / (SELECT MAX(TODAYKWH) FROM power_station_history_hour WHERE DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'') = ''{post.Time}'' and powerstationid = {post.PowerStation}))*100,2) ''hourKWHp'', d.irradiance ''irradiance'', d.Temperature ''temperature'',
b.money ''hourmoney'', c.TODAYKWH ''totKWH'', c.KWHKWP ''totKWHKWP'', c.money ''totmoney'', stationName, powerRate daymoney, c.SOLARHOUR tothour,round(b.PR, 2) as pr b.money ''hourmoney'', c.TODAYKWH ''totKWH'', c.KWHKWP ''totKWHKWP'', c.money ''totmoney'', stationName, powerRate daymoney, c.SOLARHOUR tothour,round(b.PR, 2) as pr
@ -106,7 +106,7 @@ namespace SolarPower.Repository.Implement
GROUP_CONCAT(DISTINCT GROUP_CONCAT(DISTINCT
CONCAT('max(case when INVERTERID = ''', INVERTERID, ''' then round(a.KWH, 2) end) ''inv_', right(INVERTERID, 4), '''') CONCAT('max(case when INVERTERID = ''', INVERTERID, ''' then round(a.KWH, 2) end) ''inv_', right(INVERTERID, 4), '''')
) INTO @sql ) INTO @sql
FROM inverter_history_hour; FROM inverter_history_hour where powerstationId = {post.PowerStation};
SET @sql = CONCAT('SELECT DATE_FORMAT(a.TIMESTAMP,''%m/%d'') report_date, ', @sql, SET @sql = CONCAT('SELECT DATE_FORMAT(a.TIMESTAMP,''%m/%d'') report_date, ', @sql,
',b.TODAYKWH ''dayKWH'', round((b.TODAYKWH / c.monthKWH)*100,2) ''dayKWHp'', b.SOLARHOUR ''tothour'', b.KWHKWP ''KWHKWP'', b.PR, ',b.TODAYKWH ''dayKWH'', round((b.TODAYKWH / c.monthKWH)*100,2) ''dayKWHp'', b.SOLARHOUR ''tothour'', b.KWHKWP ''KWHKWP'', b.PR,
d.irradiance ''irradiance'', d.Temperature ''temperature'', b.money ''soldmoney'', d.irradiance ''irradiance'', d.Temperature ''temperature'', b.money ''soldmoney'',
@ -153,7 +153,7 @@ namespace SolarPower.Repository.Implement
GROUP_CONCAT(DISTINCT GROUP_CONCAT(DISTINCT
CONCAT('max(case when INVERTERID = ''', INVERTERID, ''' then round(a.KWH, 2) end) ''inv_', right(INVERTERID, 4), '''') CONCAT('max(case when INVERTERID = ''', INVERTERID, ''' then round(a.KWH, 2) end) ''inv_', right(INVERTERID, 4), '''')
) INTO @sql ) INTO @sql
FROM inverter_history_hour; FROM inverter_history_hour where powerstationId = {post.PowerStation};
SET @sql = CONCAT('SELECT DATE_FORMAT(a.TIMESTAMP,''%m/%d'') report_date, ', @sql, SET @sql = CONCAT('SELECT DATE_FORMAT(a.TIMESTAMP,''%m/%d'') report_date, ', @sql,
',b.TODAYKWH ''dayKWH'', round((b.TODAYKWH / c.monthKWH)*100,2) ''dayKWHp'', b.SOLARHOUR ''tothour'', b.KWHKWP ''KWHKWP'', b.PR, ',b.TODAYKWH ''dayKWH'', round((b.TODAYKWH / c.monthKWH)*100,2) ''dayKWHp'', b.SOLARHOUR ''tothour'', b.KWHKWP ''KWHKWP'', b.PR,
d.irradiance ''irradiance'', d.Temperature ''temperature'', b.money ''soldmoney'', d.irradiance ''irradiance'', d.Temperature ''temperature'', b.money ''soldmoney'',
@ -273,34 +273,43 @@ namespace SolarPower.Repository.Implement
LEFT JOIN area a ON a.Id = ps.AreaId LEFT JOIN area a ON a.Id = ps.AreaId
left JOIN left JOIN
( (
SELECT SUM(a.SolarHour) SolarHour,SUM(a.Kwh) Kwh,AVG(b.PR) AvgPR,AVG(b.KWHKWP) AvgKWHKWP,AVG(c.Irradiance) AvgIrradiance,SUM(b.TodayMoney) as 'TodayMoney',a.PowerStationId FROM SELECT a.SolarHour ,a.Kwh ,b.PR AvgPR,b.KWHKWP AvgKWHKWP,c.Irradiance AvgIrradiance,b.TodayMoney as 'TodayMoney',a.Id,a.time FROM
( (
SELECT Max(ps.SOLARHOUR) AS 'SolarHour',MAX(ps.TODAYKWH) 'Kwh' ,DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d ') AS 'time', ps.PowerStationId SELECT ps.Id,SUM(k.SolarHour) SolarHour,SUM(k.Kwh) Kwh , k.time FROM power_station ps
LEFT JOIN
(
SELECT Max(ps.SOLARHOUR) AS 'SolarHour',MAX(ps.TODAYKWH) 'Kwh' ,DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d %H:%i') AS 'time', ps.PowerStationId
FROM power_station_history_hour ps FROM power_station_history_hour ps
WHERE ps.PowerStationId IN @ids {wheretime} WHERE ps.PowerStationId IN @ids {wheretime}
GROUP BY DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d') GROUP BY DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d'),ps.PowerStationId
) k ON k.PowerStationId = ps.Id WHERE ps.Id IN @ids GROUP BY k.PowerStationId
) a ) a
left JOIN LEFT JOIN
( (
SELECT B.PR ,B.KWHKWP,B.TODAYMONEY AS 'TodayMoney', DATE_FORMAT(A.bb,'%Y-%m-%d') time FROM SELECT ps.Id,AVG(n.PR) PR,AVG(n.KWHKWP) KWHKWP,SUM(n.TodayMoney) TodayMoney FROM power_station ps
LEFT JOIN
(
SELECT B.PR ,B.KWHKWP,B.TODAYMONEY AS 'TodayMoney', DATE_FORMAT(A.bb,'%Y-%m-%d') 'time' ,B.PowerStationId FROM
( (
SELECT Max(ps.TIMESTAMP) AS bb FROM power_station_history_hour ps SELECT Max(ps.TIMESTAMP) AS bb FROM power_station_history_hour ps
WHERE ps.PowerStationId IN @ids {wheretime} WHERE ps.PowerStationId IN @ids {wheretime}
GROUP BY DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d') GROUP BY DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d'),ps.PowerStationId
) A ) A
LEFT JOIN power_station_history_hour B ON A.bb = B.TIMESTAMP LEFT JOIN power_station_history_hour B ON A.bb = B.TIMESTAMP
GROUP BY B.PowerStationId ,DATE_FORMAT(A.bb,'%Y-%m-%d')
)n ON ps.Id = n.PowerStationId WHERE ps.Id IN @ids GROUP BY n.PowerStationId
) b ) b
ON DATE_FORMAT(a.time,'%Y-%m-%d') = DATE_FORMAT(b.time,'%Y-%m-%d') ON a.Id = b.Id
LEFT JOIN LEFT JOIN
( (
SELECT SUM(ps.Irradiance) AS Irradiance , DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d') AS TIME SELECT SUM(ps.Irradiance) AS Irradiance , DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d') AS TIME ,ps.PowerStationId
from sensor_history_hour ps from sensor_history_hour ps
WHERE ps.PowerStationId IN @ids {wheretime} WHERE ps.PowerStationId IN @ids {wheretime}
GROUP BY DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d') GROUP BY DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d'),ps.PowerStationId
) c ) c
ON DATE_FORMAT(a.time,'%Y-%m-%d') = DATE_FORMAT(c.time,'%Y-%m-%d') ON a.Id = c.PowerStationId
) n GROUP BY a.Id,a.time
ON n.PowerStationId = ps.Id ) n ON n.Id = ps.Id
WHERE ps.Id IN @ids ORDER BY ps.CityId"; WHERE ps.Id IN @ids ORDER BY ps.CityId";
result = (await conn.QueryAsync<MaxFormbody>(sql,new { ids = ids})).ToList(); result = (await conn.QueryAsync<MaxFormbody>(sql,new { ids = ids})).ToList();
} }

View File

@ -739,7 +739,7 @@
var url = "/StationReport/GetForm"; var url = "/StationReport/GetForm";
$.post(url, send_data, function (rel) { $.post(url, send_data, function (rel) {
if (rel.code != "0000") { if (rel.code != "0000") {
toast_error(rel.data.msg); toast_error(rel.msg);
return; return;
} }
var sta = ""; var sta = "";
@ -1089,9 +1089,9 @@
var posturl = "/StationReport/GetHireInfo"; var posturl = "/StationReport/GetHireInfo";
$.ajax({ $.ajax({
url: posturl, url: posturl,
type: "POST",//'GET', type: "POST",
dataType: 'json', dataType: 'json',
data: dataTosent, // 輸入的資料 data: dataTosent,
cache: false, cache: false,
async: false, async: false,
success: function (response) { success: function (response) {
@ -1100,36 +1100,7 @@
}) })
} }
}); });
//await $.post(posturl, dataTosent, function (rel) {
// if (rel.code != "0000") {
// out_reject();
// toast_error(rel.data.msg);
// return;
// }
//}).promise();
return hirerate; return hirerate;
//return new Promise(function (out_resolve, out_reject) {
// $.post(posturl, dataTosent, function (rel) {
// if (rel.code != "0000") {
// out_reject();
// toast_error(rel.data.msg);
// return;
// }
// $.each(rel.data, function (index, value) {
// hirerate += Number(value.leaseRate);
// })
// out_resolve(hirerate);
// })
//});
} }
</script> </script>