電站資訊-逆變器監控: 逆變器在新增、修改、刪除時,會去更新inv_Status資料表;透過inv_Status顯示在逆變器監控中的逆變器狀態

This commit is contained in:
wanling040@gmail.com 2022-08-08 23:39:18 +08:00
parent 494c8d4142
commit 6934f9acac
4 changed files with 197 additions and 33 deletions

View File

@ -2474,6 +2474,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 +2558,24 @@ 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
};
List<string> propertiesForMasterInvs = new List<string>()
{
"DBName",
"Enabled",
"Status"
};
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 +2698,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 +3045,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)
{ {

View File

@ -627,7 +627,21 @@ 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; }//狀態
}
/// <summary> /// <summary>
/// 下拉式選單用 /// 下拉式選單用
/// </summary> /// </summary>

View File

@ -1906,6 +1906,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 +2008,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 +2030,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 id, InverterId
FROM {db_name}.inverter
WHERE Deleted = 0 AND 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 +2620,71 @@ 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 = GenerateUpdateQueryWithCustomTable(properties, "inv_status");
// 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)
{ {

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);
@ -634,5 +643,6 @@ namespace SolarPower.Repository.Interface
Task<List<PowerStation>> GetAllNoStatusAsync(); Task<List<PowerStation>> GetAllNoStatusAsync();
Task<string> CalcIrrDayHourHistoryPerHour(string dateTime, int powerStationId); Task<string> CalcIrrDayHourHistoryPerHour(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);
} }
} }