金額顯示

This commit is contained in:
b110212000 2021-08-06 19:24:48 +08:00
parent 2e36250db2
commit a31611b625
8 changed files with 407 additions and 22 deletions

View File

@ -1211,5 +1211,298 @@ namespace SolarPower.Controllers
return apiResult;
}
public FileResult ExportExcelmaxtable(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);
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;
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"
};
foreach (var head in lasthead)
{
sheet.SetColumnWidth(index, 4 * 160 * 8);
cell = row.CreateCell(index);
cell.SetCellValue(head);
cell.CellStyle = styleLine12;
index++;
}
RowPosition--;
RowPosition -= citycount;
var cityRowPosition = RowPosition;
index = 0;
foreach(var cityArray in cityArrays)
{
index = 0;
row = sheet.CreateRow(cityRowPosition);
cell = row.CreateCell(index);
cell.SetCellValue(cityArray.City);
cell.CellStyle = styleLine12;
region = new CellRangeAddress(cityRowPosition, cityRowPosition, index, index + 1);
sheet.AddMergedRegion(region);
index++;
cell = row.CreateCell(index);
cell.CellStyle = styleLine12;
index++;
cell = row.CreateCell(index);
cell.SetCellValue(Math.Round((cityArray.Kwh / cityArray.Count), 2));
cell.CellStyle = styleLine12;
region = new CellRangeAddress(cityRowPosition, cityRowPosition, index, index + 1);
sheet.AddMergedRegion(region);
index++;
cell = row.CreateCell(index);
cell.CellStyle = styleLine12;
index++;
cell = row.CreateCell(index);
cell.SetCellValue(Math.Round((cityArray.SolarHour / cityArray.Count), 2));
cell.CellStyle = styleLine12;
region = new CellRangeAddress(cityRowPosition, cityRowPosition, index, index + 1);
sheet.AddMergedRegion(region);
index++;
cell = row.CreateCell(index);
cell.CellStyle = styleLine12;
cityRowPosition++;
}
index = 0;
RowPosition--;
row = sheet.CreateRow(RowPosition);
cell = row.CreateCell(index);
cell.SetCellValue("縣市");
cell.CellStyle = styleLine12;
region = new CellRangeAddress(RowPosition, RowPosition, index, index + 1);
sheet.AddMergedRegion(region);
index++;
cell = row.CreateCell(index);
cell.CellStyle = styleLine12;
index++;
cell = row.CreateCell(index);
cell.SetCellValue("平均發電量(kWp)");
cell.CellStyle = styleLine12;
region = new CellRangeAddress(RowPosition, RowPosition, index, index + 1);
sheet.AddMergedRegion(region);
index++;
cell = row.CreateCell(index);
cell.CellStyle = styleLine12;
index++;
cell = row.CreateCell(index);
cell.SetCellValue("發電時間(小時)");
cell.CellStyle = styleLine12;
region = new CellRangeAddress(RowPosition, RowPosition, index, index + 1);
sheet.AddMergedRegion(region);
index++;
cell = row.CreateCell(index);
cell.CellStyle = styleLine12;
RowPosition = 0;
index = 0;
row = sheet.CreateRow(RowPosition);
cell = row.CreateCell(index);
cell.SetCellValue("時間");
cell.CellStyle = styleLine12;
region = new CellRangeAddress(RowPosition, RowPosition, index, index + 1);
sheet.AddMergedRegion(region);
index++;
cell = row.CreateCell(index);
cell.CellStyle = styleLine12;
index ++;
cell = row.CreateCell(index);
cell.SetCellValue("發電量");
cell.CellStyle = styleLine12;
region = new CellRangeAddress(RowPosition, RowPosition, index, index + 1);
sheet.AddMergedRegion(region);
index++;
cell = row.CreateCell(index);
cell.CellStyle = styleLine12;
index++;
cell = row.CreateCell(index);
cell.SetCellValue("有效日照時數");
cell.CellStyle = styleLine12;
region = new CellRangeAddress(RowPosition, RowPosition, index, index + 1);
sheet.AddMergedRegion(region);
index++;
cell = row.CreateCell(index);
cell.CellStyle = styleLine12;
RowPosition++;
row = sheet.CreateRow(RowPosition);
index = 0;
cell = row.CreateCell(index);
cell.SetCellValue(postObject.Time);
cell.CellStyle = styleLine12;
region = new CellRangeAddress(RowPosition, RowPosition, index, index + 1);
sheet.AddMergedRegion(region);
index++;
cell = row.CreateCell(index);
cell.CellStyle = styleLine12;
index++;
cell = row.CreateCell(index);
cell.SetCellValue(Math.Round(kwp,2));
cell.CellStyle = styleLine12;
region = new CellRangeAddress(RowPosition, RowPosition, index, index + 1);
sheet.AddMergedRegion(region);
index++;
cell = row.CreateCell(index);
cell.CellStyle = styleLine12;
index ++;
cell = row.CreateCell(index);
cell.SetCellValue(Math.Round(kwhkwp, 2));
cell.CellStyle = styleLine12;
region = new CellRangeAddress(RowPosition, RowPosition, index, index + 1);
sheet.AddMergedRegion(region);
index++;
cell = row.CreateCell(index);
cell.CellStyle = styleLine12;
var ms = new NpoiMemoryStream
{
AllowClose = false
};
workbook.Write(ms);
ms.Flush();
ms.Seek(0, SeekOrigin.Begin);
var Datename = postObject.Time.Replace("-", "");
return File(ms, "application/vnd.ms-excel", "FIC太陽能監控平台" + "_" + "綜合報表" + "_" + postObject.Userid + Datename + ".xlsx");
}
}
}

View File

@ -14,6 +14,7 @@ namespace SolarPower.Models
public string EndAt { get { return Convert.ToDateTime(endAt).ToString("yyyy-MM-dd"); } set { endAt = value; } } //結束時間
public int Kwh { get; set; }//購電度數
public float Money { get; set; }//售出金額
public int Deleted { get; set; }
}
public class ElectricitySoldRecordTable : ElectricitySoldRecord

View File

@ -85,13 +85,22 @@ namespace SolarPower.Models
public string AreaName { get; set; }
public string PowerstationName { get; set; }
public int PowerstationId { get; set; }
public int PowerstationType { get; set; }
public double Kwh { get; set; }
public string PowerstationDB { get; set; }
public double SolarHour { get; set; }
public double AvgIrradiance { get; set; }
public double AvgPR { get; set; }
public double AvgKWHKWP { get; set; }
public double TodayMoney { get; set; }
}
public class CityArray
{
public string City { get; set; }
public double Kwh { get; set; }
public double SolarHour { get; set; }
public int Count { get; set; }
}

View File

@ -34,7 +34,7 @@ namespace SolarPower.Repository.Implement
post.Time = post.Time.Replace("-", "~");
post.Time = post.Time.Replace("/", "-");
var time = post.Time.Split("~");
sql = @$"SELECT es.`*`,ps.Name AS PowerStationName FROM electricity_sold_record es
sql = @$"SELECT es.*,ps.Name AS PowerStationName FROM electricity_sold_record es
LEFT JOIN power_station ps ON es.PowerstationId = ps.Id
WHERE es.StartAt BETWEEN '{time[0]}' AND '{time[1]}' AND es.PowerstationId IN @ids AND es.Deleted = 0";
break;
@ -43,18 +43,17 @@ namespace SolarPower.Repository.Implement
post.Time = post.Time.Replace("-", "~");
post.Time = post.Time.Replace("/", "-");
var time1 = post.Time.Split("~");
sql = @$"SELECT es.`*`,ps.Name AS PowerStationName FROM electricity_sold_record es
sql = @$"SELECT es.*,ps.Name AS PowerStationName FROM electricity_sold_record es
LEFT JOIN power_station ps ON es.PowerstationId = ps.Id
WHERE es.StartAt BETWEEN '{time1[0]}' AND '{time1[1]}' AND es.PowerstationId IN @ids AND es.Deleted = 0";
sql = "";
break;
case 2:
sql = @$"SELECT es.`*`,ps.Name AS PowerStationName FROM electricity_sold_record es
sql = @$"SELECT es.*,ps.Name AS PowerStationName FROM electricity_sold_record es
LEFT JOIN power_station ps ON es.PowerstationId = ps.Id
WHERE DATE_FORMAT(es.StartAt , '%Y-%m') = '{post.Time}' AND es.PowerstationId IN @ids AND es.Deleted = 0";
break;
case 3:
sql = @$"SELECT es.`*`,ps.Name AS PowerStationName FROM electricity_sold_record es
sql = @$"SELECT es.*,ps.Name AS PowerStationName FROM electricity_sold_record es
LEFT JOIN power_station ps ON es.PowerstationId = ps.Id
WHERE DATE_FORMAT(es.StartAt , '%Y') = '{post.Time}' AND es.PowerstationId IN @ids AND es.Deleted = 0";
break;

View File

@ -265,13 +265,15 @@ namespace SolarPower.Repository.Implement
a.Name AS 'AreaName',
ps.Name AS 'PowerstationName',
ps.SiteDB AS 'PowerstationDB',
ps.SolarType AS 'PowerstationType',
ps.Id as 'PowerStationId',
n.*
FROM power_station ps
LEFT JOIN city c ON c.Id = ps.CityId
LEFT JOIN area a ON a.Id = ps.AreaId
left JOIN
(
SELECT SUM(a.SolarHour) SolarHour,SUM(a.Kwh) Kwh,AVG(b.PR) AvgPR,AVG(b.KWHKWP) AvgKWHKWP,AVG(c.Irradiance) AvgIrradiance,a.PowerStationId FROM
SELECT SUM(a.SolarHour) SolarHour,SUM(a.Kwh) Kwh,AVG(b.PR) AvgPR,AVG(b.KWHKWP) AvgKWHKWP,AVG(c.Irradiance) AvgIrradiance,SUM(b.TodayMoney) as 'TodayMoney',a.PowerStationId FROM
(
SELECT Max(ps.SOLARHOUR) AS 'SolarHour',MAX(ps.TODAYKWH) 'Kwh' ,DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d ') AS 'time', ps.PowerStationId
FROM power_station_history_hour ps
@ -280,7 +282,7 @@ namespace SolarPower.Repository.Implement
) a
left JOIN
(
SELECT B.PR ,B.KWHKWP, DATE_FORMAT(A.bb,'%Y-%m-%d') time FROM
SELECT B.PR ,B.KWHKWP,B.TODAYMONEY AS 'TodayMoney', DATE_FORMAT(A.bb,'%Y-%m-%d') time FROM
(
SELECT Max(ps.TIMESTAMP) AS bb FROM power_station_history_hour ps
WHERE ps.PowerStationId IN @ids {wheretime}

View File

@ -594,7 +594,7 @@
}
function Searchform() {
console.log(selecterd_powerstationId);
/* console.log(selecterd_powerstationId);*/
if (searchType == 0 || searchType == 1) {
timerange = $('#DateGettext').val();
}

View File

@ -298,6 +298,7 @@
var nowpowerstation = null;//選擇電站
var haveinvertName = [];
var nowform;
var xxx;
$(function () {
//#region 預設初始值
@ -943,8 +944,16 @@
FormType: nowform,
PowerStation: selecterd_invert
}
if (send_data.FormType != null && send_data.PowerStation.length != 0) {
if (send_data.FormType != null && send_data.PowerStation.length != 0 && send_data.FormType != 2) {
window.location = "/StationReport/ExportExcel?post=" + JSON.stringify(send_data);
} else {
if (send_data.FormType != 2) {
toast_warning("請先選擇電站及報表類型");
}
}
if (send_data.PowerStation.length != 0 && send_data.FormType == 2) {
window.location = "/StationReport/ExportExcelmaxtable?post=" + JSON.stringify(send_data);
} else {
toast_warning("請先選擇電站及報表類型");
}
@ -974,6 +983,12 @@
}
//下方
$.each(rel.data, function (index, data) {
var hirerate = 0;
if (data.powerstationType == 1)
{
hirerate = hire(data.powerstationDB, data.powerstationId);
}
var cityinfo = {
city: data.cityName,
kwp: data.kwh,
@ -1007,6 +1022,16 @@
StrInfoBody += "<td>" + data.solarHour.toFixed(2) + "</td>";
StrInfoBody += "<td>" + data.avgIrradiance.toFixed(2) + "</td>";
StrInfoBody += "<td>" + data.avgPR.toFixed(2) + "</td>";
if (showmoney == 1) {
StrInfoBody += "<td>" + data.todayMoney.toFixed(2) + "</td>";
StrInfoBody += "<td>" + (data.todayMoney * hirerate * 0.01).toFixed(2)+ "</td>";
StrInfoBody += "<td>" + data.todayMoney.toFixed(2) + "</td>";
}
StrInfoBody += "</tr>";
kwp += data.kwh;
kwhkwp += data.avgKWHKWP;
@ -1051,5 +1076,61 @@
nowform = 2;
})
}
function hire(db, id)
{
var hirerate = 0;
var dataTosent =
{
Sitedb: db,
PowerstationId: id
}
var posturl = "/StationReport/GetHireInfo";
$.ajax({
url: posturl,
type: "POST",//'GET',
dataType: 'json',
data: dataTosent, // 輸入的資料
cache: false,
async: false,
success: function (response) {
$.each(response.data, function (index, value) {
hirerate += Number(value.leaseRate);
})
}
});
//await $.post(posturl, dataTosent, function (rel) {
// if (rel.code != "0000") {
// out_reject();
// toast_error(rel.data.msg);
// return;
// }
//}).promise();
return hirerate;
//return new Promise(function (out_resolve, out_reject) {
// $.post(posturl, dataTosent, function (rel) {
// if (rel.code != "0000") {
// out_reject();
// toast_error(rel.data.msg);
// return;
// }
// $.each(rel.data, function (index, value) {
// hirerate += Number(value.leaseRate);
// })
// out_resolve(hirerate);
// })
//});
}
</script>
}

View File

@ -7,26 +7,26 @@
}
},
"LoginExpireMinute": 60, //()
//"DBConfig": {
// "Server": "MVgHWzR3rGDgD57TUoFunA==",
// "port": "r4AoXMUDodcQjIzofGNCcg==",
// "Database": "z8TVtiXZ6MwgWbUEAOXA/fiHzd7c0iUhFqn1mHzxhKo=",
// "Root": "mWlR2HshQNhRRE34jg4kdg==",
// "Password": "y4uPqlH9ncTgR/I07qpwaA=="
//},
"DBConfig": {
"Server": "AVXfxd+IRlLtJ0MCi9HU1g==",
"port": "CrEmevYrUsSo7Mkb7Gxn8A==",
"Database": "CEyYZnO8B5+yTXQcFSsiBA==",
"Root": "Aph7AzoiwAmmBHCfS1rqeQ==",
"Password": "8WMHBEWuT0XoAB4kzduQHA=="
"Server": "MVgHWzR3rGDgD57TUoFunA==",
"port": "r4AoXMUDodcQjIzofGNCcg==",
"Database": "z8TVtiXZ6MwgWbUEAOXA/fiHzd7c0iUhFqn1mHzxhKo=",
"Root": "mWlR2HshQNhRRE34jg4kdg==",
"Password": "y4uPqlH9ncTgR/I07qpwaA=="
},
//"DBConfig": {
// "Server": "AVXfxd+IRlLtJ0MCi9HU1g==",
// "port": "CrEmevYrUsSo7Mkb7Gxn8A==",
// "Database": "CEyYZnO8B5+yTXQcFSsiBA==",
// "Root": "Aph7AzoiwAmmBHCfS1rqeQ==",
// "Password": "8WMHBEWuT0XoAB4kzduQHA=="
//},
"BackgroundServiceCron": {
"CalcPowerStationJob": "0 5 * * * ?",
"CalcAvgPowerStationJob": "0 0 2 * * ?",
"OperationScheduleJob": "0 0 2 * * ?",
"CalcInverter15minJob": "0 2/15 * * * ?",
"SendEmailJob": "0/10 * * * * ?"
"SendEmailJob": "0 0 3 * * ?"
},
"SMTPConfig": {
"Host": "smtp.gmail.com",