刪除電站

This commit is contained in:
b110212000 2021-09-02 10:52:03 +08:00
parent 4f96b2ef92
commit d2ab2b11ec
6 changed files with 147 additions and 41 deletions

View File

@ -3071,7 +3071,19 @@ namespace SolarPower.Controllers
try try
{ {
var powerstation = await powerStationRepository.GetOneAsync(stationId);
if (powerstation == null)
{
apiResult.Code = "9992";
apiResult.Msg = errorCode.GetString(apiResult.Code);
return apiResult;
}
await powerStationRepository.DeleteOneByIdWithCustomDBNameAndTable(stationId, powerstation.SiteDB, "power_station");
await powerStationRepository.DropShareDevice(stationId, powerstation.SiteDB);
await powerStationRepository.DeleteOne(stationId); await powerStationRepository.DeleteOne(stationId);
apiResult.Msg = "刪除成功"; apiResult.Msg = "刪除成功";
apiResult.Code = "0000"; apiResult.Code = "0000";
} }
@ -3121,5 +3133,27 @@ namespace SolarPower.Controllers
} }
} }
public async Task<ApiResult<List<string>>> GetShareDevicePowerstationName (int Id)
{
ApiResult<List<string>> apiResult = new ApiResult<List<string>>();
List<string> names = new List<string>();
try
{
var powerStation = await powerStationRepository.GetOneAsync(Id);
names = await powerStationRepository.GetShareDevicePowerstationName(Id, powerStation.SiteDB);
apiResult.Code = "0000";
apiResult.Data = names;
}
catch (Exception exception)
{
apiResult.Code = "9999";
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
}
return apiResult;
}
} }
} }

View File

@ -2,13 +2,9 @@
"iisSettings": { "iisSettings": {
"windowsAuthentication": false, "windowsAuthentication": false,
"anonymousAuthentication": true, "anonymousAuthentication": true,
"iis": {
"applicationUrl": "http://localhost/SolarPower",
"sslPort": 0
},
"iisExpress": { "iisExpress": {
"applicationUrl": "http://localhost:63003", "applicationUrl": "http://localhost:57957/",
"sslPort": 0 "sslPort": 44361
} }
}, },
"profiles": { "profiles": {

View File

@ -5274,5 +5274,55 @@ namespace SolarPower.Repository.Implement
return result; return result;
} }
} }
public async Task<List<string>> GetShareDevicePowerstationName (int Id , string DBname)
{
List<string> result;
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
try
{
var sql = $@"SELECT ps.Name FROM {DBname}.sharedevice sh
LEFT JOIN power_station ps ON ps.Id = sh.PowerStationId
WHERE sh.DeviceId IN
(SELECT Id FROM {DBname}.device WHERE PowerStationId = {Id}) group BY ps.Name";
result = (await conn.QueryAsync<string>(sql)).ToList();
}
catch (Exception exception)
{
throw exception;
}
return result;
}
}
public async Task DropShareDevice(int powerstationId ,string DBname)
{
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
conn.Open();
using (var trans = conn.BeginTransaction())
{
try
{
var sql = $"DELETE FROM {DBname}.sharedevice WHERE DeviceId IN (SELECT Id FROM {DBname}.device WHERE PowerStationId = {powerstationId} )";
await conn.ExecuteAsync(sql, trans);
trans.Commit();
}
catch (Exception exception)
{
trans.Rollback();
throw exception;
}
finally
{
conn.Close();
}
}
}
}
} }
} }

View File

@ -595,5 +595,7 @@ namespace SolarPower.Repository.Interface
Task<List<PowerStationIdAndCity>> GetPowerStationsByCompanyIdWithfilterForGeneration(MyUser myUser, string filter); Task<List<PowerStationIdAndCity>> GetPowerStationsByCompanyIdWithfilterForGeneration(MyUser myUser, string filter);
Task<List<AreaSelectItemList>> GetApicallItemList(int powerStationId, string dbname); Task<List<AreaSelectItemList>> GetApicallItemList(int powerStationId, string dbname);
Task<List<ApicallList>> GetApicallList(int PowerStationId, string Type); Task<List<ApicallList>> GetApicallList(int PowerStationId, string Type);
Task<List<string>> GetShareDevicePowerstationName(int Id, string DBname);
Task DropShareDevice(int powerstationId, string DBname);
} }
} }

View File

@ -514,36 +514,67 @@
var selected_id = $(this).parents('tr').attr('data-id'); var selected_id = $(this).parents('tr').attr('data-id');
var selected_cityid = $(this).parents('tr').attr('datacity-id'); var selected_cityid = $(this).parents('tr').attr('datacity-id');
Swal.fire( var url = "/PowerStation/GetShareDevicePowerstationName";
{ var send_data = {
title: "刪除", Id: selected_id
text: "你確定是否刪除此筆資料?", }
icon: 'warning', $.post(url, send_data, function (rel) {
showCancelButton: true, if (rel.code != "0000") {
confirmButtonText: "是", toast_error(rel.msg);
cancelButtonText: "否" return;
}).then(function (result) { }
if (result.value) { else {
//刪除單一運維紀錄 var stationName = "";
var url = "/PowerStation/DeletePowerStation/"; if (rel.data.length != 0) {
var send_data = { stationName = "此電站與 <br\><br\>"
stationId: selected_id $.each(rel.data, function (index, val) {
} stationName += index + 1 + "." + val + "<br\>";
$.post(url, send_data, function (rel) { });
if (rel.code == "9999") { stationName += "<br\>以上電站共用設備<br\>刪除則將解除所有設備共用關係!<br\>"
toast_error(rel.msg);
return;
}
toast_ok(rel.msg);
var cityamount = $('#ul-List-' + selected_cityid).text();
$('#ul-List-' + selected_cityid).text(cityamount - 1);
$('#li-List-' + selected_id).hide();
Cityes();
}, 'json');
} }
}); var text = stationName + "請問確定是否刪除該電站? <br\>"
Swal.fire(
{
title: "刪除",
icon: 'warning',
html: text,
showCancelButton: true,
confirmButtonText: "刪除",
cancelButtonText: "取消"
}).then(function (result) {
if (result.value) {
//刪除電站
var url = "/PowerStation/DeletePowerStation/";
var send_data = {
stationId: selected_id
}
$.post(url, send_data, function (rel) {
if (rel.code == "9999") {
toast_error(rel.msg);
return;
}
toast_ok(rel.msg);
var cityamount = $('#ul-List-' + selected_cityid).text();
$('#ul-List-' + selected_cityid).text(cityamount - 1);
$('#li-List-' + selected_id).hide();
Cityes();
}, 'json');
}
});
return;
}
}, 'json');
}); });

View File

@ -2611,7 +2611,6 @@
ExceptionTable.ajax.reload(); ExceptionTable.ajax.reload();
return; return;
} }
}, 'json'); }, 'json');
} }
} }
@ -2622,16 +2621,12 @@
$("#Exception-modal .modal-title").html("異常設定資料 - 編輯"); $("#Exception-modal .modal-title").html("異常設定資料 - 編輯");
var tyname = $(this).parents('tr').attr('data-typename'); var tyname = $(this).parents('tr').attr('data-typename');
selected_id = $(this).parents('tr').attr('data-id'); selected_id = $(this).parents('tr').attr('data-id');
//取得單一異常設定資料 //取得單一異常設定資料
var url = "/PowerStation/GetOneException/"; var url = "/PowerStation/GetOneException/";
var send_data = { var send_data = {
SelectedId: selected_id, SelectedId: selected_id,
PowerStationId: stationId, PowerStationId: stationId,
} }
$.post(url, send_data, function (rel) { $.post(url, send_data, function (rel) {
if (rel.code != "0000") { if (rel.code != "0000") {
toast_error(rel.msg); toast_error(rel.msg);
@ -3013,9 +3008,7 @@
}); });
$('#power_station_operation_personnel').change(function () { $('#power_station_operation_personnel').change(function () {
//$(this).valid();
if (stationId == 'new' || station_infocreate) { if (stationId == 'new' || station_infocreate) {
console.log($('#power_station_operation_personnel').val().length);
if ($('#power_station_operation_personnel').val().length == 0) { if ($('#power_station_operation_personnel').val().length == 0) {
$('#power_station_operation_personnel-error').show(); $('#power_station_operation_personnel-error').show();
} else { } else {