Merge branch 'Willy'

This commit is contained in:
b110212000 2021-08-26 16:46:09 +08:00
commit 1be7aebc1e
6 changed files with 228 additions and 36 deletions

View File

@ -1422,11 +1422,12 @@ namespace SolarPower.Controllers
public async Task<ApiResult<string>> SaveException(ExceptionModal exceptionModal)
{
ApiResult<string> apiResult = new ApiResult<string>();
var url = "10.1.100.138";
try
{
PowerStation powerStation = null;
powerStation = await powerStationRepository.GetOneAsync(exceptionModal.PowerStationId);
if (exceptionModal.Id == 0)
{
@ -1446,13 +1447,42 @@ namespace SolarPower.Controllers
"CreatedBy",
"PowerStationId",
"Id",
"LowerLimit",
"Type",
"UpperLimit",
"LowerLimit",
"UpperLimit"
};
if(Exception.LowerLimit == -9999)
{
Exception.LowerLimit = null;
}
if (Exception.UpperLimit != -9999)
{
Exception.UpperLimit = null;
}
await powerStationRepository.AddException(Exception, properties, powerStation.SiteDB);
Fetch_PostWithJSONFormat("http://" + url + ":8080/obix/config/Solar/S"+ powerStation.Code+ "01/API/PR_UpperLimit/set", exceptionModal.UpperLimit.ToString());
Fetch_PostWithJSONFormat("http://" + url + ":8080/obix/config/Solar/S" + powerStation.Code + "01/API/PR_LowerLimit/set", exceptionModal.LowerLimit.ToString());
var calllist = await powerStationRepository.GetApicallList(powerStation.Id, exceptionModal.Type);
foreach(var call in calllist )
{
if(call.LimitValue == 0)
{
if(exceptionModal.UpperLimit != -9999)
{
Fetch_PostWithJSONFormat($"http://{call.UrlSite}/obix/config/Solar/S{powerStation.Code}01/API/{call.UrlApi}/set", exceptionModal.UpperLimit.ToString());
}
}
else if(call.LimitValue == 1)
{
if (exceptionModal.LowerLimit != -9999)
{
Fetch_PostWithJSONFormat($"http://{call.UrlSite}/obix/config/Solar/S{powerStation.Code}01/API/{call.UrlApi}/set", exceptionModal.LowerLimit.ToString());
}
}
}
apiResult.Code = "0000";
apiResult.Msg = "新增成功";
@ -1475,13 +1505,42 @@ namespace SolarPower.Controllers
"CreatedBy",
"PowerStationId",
"Id",
"LowerLimit",
"Type",
"UpperLimit",
"LowerLimit",
"UpperLimit"
};
if (Exception.LowerLimit == -9999)
{
Exception.LowerLimit = null;
}
if (Exception.UpperLimit == -9999)
{
Exception.UpperLimit = null;
}
await powerStationRepository.UpdateException(Exception, properties, powerStation.SiteDB);
Fetch_PostWithJSONFormat("http://" + url + ":8080/obix/config/Solar/S" + powerStation.Code + "01/API/PR_UpperLimit/set", exceptionModal.UpperLimit.ToString());
Fetch_PostWithJSONFormat("http://" + url + ":8080/obix/config/Solar/S" + powerStation.Code + "01/API/PR_LowerLimit/set", exceptionModal.LowerLimit.ToString());
var calllist = await powerStationRepository.GetApicallList(powerStation.Id, exceptionModal.Type);
foreach (var call in calllist)
{
if (call.LimitValue == 0)
{
if (exceptionModal.UpperLimit != -9999)
{
Fetch_PostWithJSONFormat($"http://{call.UrlSite}/obix/config/Solar/S{powerStation.Code}01/API/{call.UrlApi}/set", exceptionModal.UpperLimit.ToString());
}
}
else if (call.LimitValue == 1)
{
if (exceptionModal.LowerLimit != -9999)
{
Fetch_PostWithJSONFormat($"http://{call.UrlSite}/obix/config/Solar/S{powerStation.Code}01/API/{call.UrlApi}/set", exceptionModal.LowerLimit.ToString());
}
}
}
apiResult.Code = "0000";
apiResult.Msg = "儲存成功";
@ -1517,10 +1576,6 @@ namespace SolarPower.Controllers
a.Function = @"
<button type='button' class='btn btn-primary btn-pills waves-effect waves-themed edit-btn'></button>
<button type='button' class='btn btn-danger btn-pills waves-effect waves-themed del-btn'></button>";
if (a.Type == 1)
{
a.TypeName = "PR值";
}
if (a.Alarm == 1)
{
a.AlarmName = "email通知";
@ -2988,6 +3043,29 @@ namespace SolarPower.Controllers
return apiResult;
}
[HttpPost]
public async Task<ApiResult<List<AreaSelectItemList>>> GetApicallItemList(int powerStationId)
{
ApiResult<List<AreaSelectItemList>> apiResult = new ApiResult<List<AreaSelectItemList>>();
try
{
var powerStation = await powerStationRepository.GetOneAsync(powerStationId);
var ItemLists = await powerStationRepository.GetApicallItemList(powerStationId, powerStation.SiteDB);
apiResult.Code = "0000";
apiResult.Data = ItemLists;
}
catch (Exception exception)
{
apiResult.Code = "9999";
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
}
apiResult.Msg = errorCode.GetString(apiResult.Code);
return apiResult;
}
public JObject Fetch_PostWithJSONFormat(string url, string paramter)
{

View File

@ -466,9 +466,9 @@ namespace SolarPower.Models.PowerStation
{
public int Id { get; set; }
public int PowerStationId { get; set; }
public byte Type { get; set; }
public decimal UpperLimit { get; set; }
public decimal LowerLimit { get; set; }
public string Type { get; set; }
public decimal? UpperLimit { get; set; }
public decimal? LowerLimit { get; set; }
public byte Alarm { get; set; }
}
@ -1034,4 +1034,12 @@ namespace SolarPower.Models.PowerStation
public string UID { get; set; }
}
public class ApicallList
{
public string UrlSite { get; set; }
public string UrlApi { get; set; }
public int LimitValue { get; set; }
public string Item { get; set; }
}
}

View File

@ -943,10 +943,18 @@ namespace SolarPower.Repository.Implement
List<ExceptionTable> Exception = new List<ExceptionTable>();
try
{
string sql = @$"SELECT pe.Type,pe.UpperLimit,pe.LowerLimit,pe.Alarm,ps.Code AS PowerStationCode ,ps.Name AS PowerStationName,pe.CreatedAt,pe.Id
string sql = @$"SELECT pe.Type,
pe.UpperLimit,
pe.LowerLimit,
api.ItemName AS TypeName,
pe.Alarm,ps.Code AS PowerStationCode ,
ps.Name AS PowerStationName,
pe.CreatedAt,
pe.Id
FROM {db_name}.power_station_exception pe
LEFT JOIN {db_name}.power_station ps ON pe.PowerStationId = ps.Id
WHERE pe.Deleted = 0 AND pe.PowerStationId = @StationId";
LEFT JOIN apicall api ON api.Item = pe.Type and ps.Id = api.PowerStationId
WHERE pe.Deleted = 0 AND pe.PowerStationId = @StationId GROUP BY pe.Id";
Exception = (await conn.QueryAsync<ExceptionTable>(sql, new { StationId = stationId })).ToList();
}
catch (Exception exception)
@ -5222,5 +5230,57 @@ namespace SolarPower.Repository.Implement
return result;
}
}
public async Task<List<AreaSelectItemList>> GetApicallItemList(int powerStationId,string dbname)
{
List<AreaSelectItemList> result;
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
try
{
var sql = $@"SELECT
aa.Item AS VALUE, aa.ItemName AS `text`
FROM
(
SELECT api.Item, api.ItemName
FROM apicall api
LEFT join
(SELECT * FROM {dbname}.power_station_exception ex WHERE ex.Deleted = 0) a
ON a.`Type` = api.Item
WHERE api.PowerStationId = {powerStationId}
AND ISNULL(a.Id)
GROUP BY api.Item
) aa
";
result = (await conn.QueryAsync<AreaSelectItemList>(sql)).ToList();
}
catch (Exception exception)
{
throw exception;
}
return result;
}
}
public async Task<List<ApicallList>> GetApicallList(int PowerStationId,string Type)
{
List<ApicallList> result;
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
try
{
var sql = $@"SELECT * FROM apicall WHERE PowerStationId = {PowerStationId} and Item = '{Type}' order by LimitValue";
result = (await conn.QueryAsync<ApicallList>(sql)).ToList();
}
catch (Exception exception)
{
throw exception;
}
return result;
}
}
}
}

View File

@ -593,5 +593,7 @@ namespace SolarPower.Repository.Interface
Task<InverterDetailModal> GetInverterInfoModal(int Id, string Time, string DB, string Table);
Task<List<PowerStationIdAndCity>> GetPowerStationsAllWithfilterForGeneration(string filter);
Task<List<PowerStationIdAndCity>> GetPowerStationsByCompanyIdWithfilterForGeneration(MyUser myUser, string filter);
Task<List<AreaSelectItemList>> GetApicallItemList(int powerStationId, string dbname);
Task<List<ApicallList>> GetApicallList(int PowerStationId, string Type);
}
}

View File

@ -722,6 +722,7 @@
},
'createdRow': function (row, data, dataIndex) {
$(row).attr('data-id', data.id);
$(row).attr('data-typename', data.typeName);
},
"ajax": {
"url": "/PowerStation/ExceptionTable",
@ -936,6 +937,13 @@
});
//#endregion
});
//#region 代管切換
@ -2552,6 +2560,7 @@
function AddException() {
selected_id = 0;
$("#Exception-modal .modal-title").html("異常設定資料 - 新增");
urlApicallItem();
$("#Exception-form").trigger("reset");
$("#Exception-modal").modal();
}
@ -2561,13 +2570,15 @@
function SaveException() {
if ($("#Exception-form").valid()) {
var url = "/PowerStation/SaveException";
var send_data = {
Id: selected_id,
PowerStationId: stationId,
Type: $("#Exception_Type_modal").val(),
UpperLimit: $("#Exception_UpperLimit_modal").val(),
LowerLimit: $("#Exception_LowerLimit_modal").val(),
UpperLimit: ($("#Exception_UpperLimit_modal").val() != "") ? $("#Exception_UpperLimit_modal").val() : "-9999",
LowerLimit: ($("#Exception_LowerLimit_modal").val() != "") ? $("#Exception_LowerLimit_modal").val() : "-9999",
Alarm: $("#Exception_Alarm_modal").val()
}
$.post(url, send_data, function (rel) {
@ -2590,7 +2601,7 @@
//#region 取一筆異常設定
$('#Exception_table').on("click", "button.edit-btn", function () {
$("#Exception-modal .modal-title").html("異常設定資料 - 編輯");
var tyname = $(this).parents('tr').attr('data-typename');
selected_id = $(this).parents('tr').attr('data-id');
//取得單一異常設定資料
@ -2607,8 +2618,9 @@
toast_error(rel.msg);
return;
}
$("#Exception_Type_modal").val(rel.data.type);
$("#Exception_Type_modal").empty();
$("#Exception_Type_modal").append($("<option />").val(rel.data.type).text(tyname));
$("#Exception_Type_modal").attr('disabled', true);
$("#Exception_Alarm_modal").val(rel.data.alarm);
$("#Exception_UpperLimit_modal").val(rel.data.upperLimit);
$("#Exception_LowerLimit_modal").val(rel.data.lowerLimit);
@ -2914,15 +2926,15 @@
//#endregion
$('#Exception_UpperLimit_modal').change(function () {
upper = $('#Exception_UpperLimit_modal').val();
$("#Exception_LowerLimit_modal").rules("remove");
$("#Exception_LowerLimit_modal").rules("add", {
required: true,
max: Number(upper),
min: 0
});
});
//$('#Exception_UpperLimit_modal').change(function () {
// upper = $('#Exception_UpperLimit_modal').val();
// $("#Exception_LowerLimit_modal").rules("remove");
// $("#Exception_LowerLimit_modal").rules("add", {
// required: true,
// max: Number(upper),
// min: 0
// });
//});
function padLeft(str, lenght) {
if (str.length >= lenght)
@ -2973,5 +2985,37 @@
}
});
function urlApicallItem()
{
var urlApicallItem = "/PowerStation/GetApicallItemList";
var send_data = {
powerStationId: stationId
}
$.post(urlApicallItem, send_data, function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
$("#Exception_Type_modal").empty();
if (rel.data.length > 0) {
$.each(rel.data, function (index, val) {
$("#Exception_Type_modal").append($("<option />").val(val.value).text(val.text));
});
$("#Exception_Type_modal").attr('disabled', false);
$("#savebtn").attr('disabled', false);
}
else {
$("#Exception_Type_modal").append($("<option />").val(0).text('無異常設定可新增'));
$("#Exception_Type_modal").attr('disabled', true);
$("#savebtn").attr('disabled', true);
}
});
}
</script>
}

View File

@ -46,18 +46,18 @@
<option value="1">PR值</option>
</select>
</div>
<div class="form-group col-lg-6">
<div class="form-group col-lg-6" style="visibility:hidden">
<label class="form-label" for="Exception_Alarm_modal"><span class="text-danger">*</span>警示方式</label>
<select class="form-control" id="Exception_Alarm_modal">
<option value="1">email通知</option>
</select>
</div>
<div class="form-group col-lg-6">
<label class="form-label" for="Exception_LowerLimit_modal"><span class="text-danger">*</span>下限</label>
<label class="form-label" for="Exception_LowerLimit_modal">下限</label>
<input type="number" id="Exception_LowerLimit_modal" name="Exception_LowerLimit_modal" class="form-control">
</div>
<div class="form-group col-lg-6">
<label class="form-label" for="Exception_UpperLimit_modal"><span class="text-danger">*</span>上限</label>
<label class="form-label" for="Exception_UpperLimit_modal">上限</label>
<input type="number" id="Exception_UpperLimit_modal" name="Exception_UpperLimit_modal" class="form-control">
</div>
@ -66,7 +66,7 @@
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
<button type="button" class="btn btn-primary" onclick="SaveException()">確定</button>
<button type="button" class="btn btn-primary" onclick="SaveException()" id="savebtn">確定</button>
</div>
</div>
</div>