報表匯出驗證

This commit is contained in:
b110212000 2021-10-05 17:20:08 +08:00
parent aab64ffa90
commit bc0950b815
5 changed files with 108 additions and 3 deletions

View File

@ -2186,6 +2186,46 @@ namespace SolarPower.Controllers
return Path.Combine("\\" + "upload", "report", Datename, "FIC太陽能監控平台" + "_" + "綜合報表" + "_" + postObject.Userid + Datename + ".xlsx"); return Path.Combine("\\" + "upload", "report", Datename, "FIC太陽能監控平台" + "_" + "綜合報表" + "_" + postObject.Userid + Datename + ".xlsx");
} }
public async Task<ApiResult<List<string>>> CheckExcel(Select_table2 post)
{
var ApiResult = new ApiResult<List<string>>();
var ErrorMessage = new List<string>();
foreach (var station in post.PowerStation)
{
var Id = Convert.ToInt32(station.Value);
var table = new Select_table()
{
FormType = post.FormType,
SearchType = post.SearchType,
PowerStation = Id,
Time = post.Time,
Userid = post.Userid
};
var checkinv = await stationReportRepository.Findhaveinv(table);
var getinvsql = checkinv[0] as IDictionary<string, object>;
if (getinvsql["mySelect"] == null)
{
ErrorMessage.Add(station.Name + "此時段無逆變器資料");
}
else
{
var cid = await stationReportRepository.CheckExcelAsync(table);
if (cid == 0)
{
ErrorMessage.Add(station.Name + "此時段資料未建立");
}
}
}
if(ErrorMessage.Count > 0)
{
ApiResult.Code = "9999";
ApiResult.Data = ErrorMessage;
}
else
{
ApiResult.Code = "0000";
}
return ApiResult;
}
} }
} }

View File

@ -257,6 +257,52 @@ namespace SolarPower.Repository.Implement
} }
} }
public async Task<int> CheckExcelAsync(Select_table post)
{
using (IDbConnection conn = _databaseHelper.GetConnection())
{
int a;
conn.Open();
try
{
string sql = "";
switch ( post.FormType )
{
case 0:
sql = @$"select Id from power_station_history_day where powerstationid = {post.PowerStation} and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') = '{post.Time}'";
break;
case 1:
if(post.SearchType == 2)
{
sql = @$"select Id from power_station_history_month where powerstationid = {post.PowerStation} and DATE_FORMAT(`TIMESTAMP`,'%Y-%m') = '{post.Time}'";
}
else
{
var times = post.Time.Replace('-', 'a').Replace('/', '-').Replace(" ", "").Split('a');
sql = @$"select Id from power_station_history_day where powerstationid = {post.PowerStation} and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') BETWEEN '{times[0]}' AND '{times[1]}'";
}
break;
case 3:
sql = @$"select Id from power_station_history_month where powerstationid = {post.PowerStation} and DATE_FORMAT(`TIMESTAMP`,'%Y') = '{post.Time}'";
break;
}
a = await conn.QueryFirstOrDefaultAsync<int>(sql);
}
catch (Exception exception)
{
throw exception;
}
finally
{
conn.Close();
}
return a;
}
}
public async Task<List<Landinfo>> GetHire (PsIdAndSiteDB post) public async Task<List<Landinfo>> GetHire (PsIdAndSiteDB post)
{ {
List<Landinfo> result = new List<Landinfo>(); List<Landinfo> result = new List<Landinfo>();

View File

@ -13,5 +13,6 @@ namespace SolarPower.Repository.Interface
Task<List<Landinfo>> GetHire(PsIdAndSiteDB post); Task<List<Landinfo>> GetHire(PsIdAndSiteDB post);
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);
} }
} }

View File

@ -1,5 +1,5 @@
@{ @{
ViewData["MainNum"] = "6"; ViewData["MainNum"] = "8";
ViewData["SubNum"] = "1"; ViewData["SubNum"] = "1";
ViewData["Title"] = "電站管理"; ViewData["Title"] = "電站管理";
} }

View File

@ -1225,7 +1225,25 @@
PowerStation: selecterd_invert PowerStation: selecterd_invert
} }
if (send_data.FormType != null && send_data.PowerStation.length != 0 && send_data.FormType != 2) { if (send_data.FormType != null && send_data.PowerStation.length != 0 && send_data.FormType != 2) {
window.location = "/StationReport/ExportExcel?post=" + JSON.stringify(send_data); $.post("/StationReport/CheckExcel", send_data, function (rel) {
if (rel.code == "0000") {
window.location = "/StationReport/ExportExcel?post=" + JSON.stringify(send_data);
return;
}
else
{
var text = "原因如下:<br\>";
$.each(rel.data, function (index, val) {
text += index + 1 + "." + val + "<br\>";
});
Swal.fire(
{
title: "Excel匯出失敗",
icon: 'warning',
html: text,
});
}
}, 'json');
} }
else else
{ {