刪除電站
This commit is contained in:
parent
4f96b2ef92
commit
d2ab2b11ec
@ -3071,7 +3071,19 @@ namespace SolarPower.Controllers
|
||||
|
||||
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);
|
||||
|
||||
apiResult.Msg = "刪除成功";
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,13 +2,9 @@
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iis": {
|
||||
"applicationUrl": "http://localhost/SolarPower",
|
||||
"sslPort": 0
|
||||
},
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:63003",
|
||||
"sslPort": 0
|
||||
"applicationUrl": "http://localhost:57957/",
|
||||
"sslPort": 44361
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
|
||||
@ -5274,5 +5274,55 @@ namespace SolarPower.Repository.Implement
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -595,5 +595,7 @@ namespace SolarPower.Repository.Interface
|
||||
Task<List<PowerStationIdAndCity>> GetPowerStationsByCompanyIdWithfilterForGeneration(MyUser myUser, string filter);
|
||||
Task<List<AreaSelectItemList>> GetApicallItemList(int powerStationId, string dbname);
|
||||
Task<List<ApicallList>> GetApicallList(int PowerStationId, string Type);
|
||||
Task<List<string>> GetShareDevicePowerstationName(int Id, string DBname);
|
||||
Task DropShareDevice(int powerstationId, string DBname);
|
||||
}
|
||||
}
|
||||
|
||||
@ -514,36 +514,67 @@
|
||||
var selected_id = $(this).parents('tr').attr('data-id');
|
||||
var selected_cityid = $(this).parents('tr').attr('datacity-id');
|
||||
|
||||
Swal.fire(
|
||||
{
|
||||
title: "刪除",
|
||||
text: "你確定是否刪除此筆資料?",
|
||||
icon: 'warning',
|
||||
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();
|
||||
var url = "/PowerStation/GetShareDevicePowerstationName";
|
||||
var send_data = {
|
||||
Id: selected_id
|
||||
}
|
||||
$.post(url, send_data, function (rel) {
|
||||
if (rel.code != "0000") {
|
||||
toast_error(rel.msg);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
var stationName = "";
|
||||
if (rel.data.length != 0) {
|
||||
stationName = "此電站與 <br\><br\>"
|
||||
$.each(rel.data, function (index, val) {
|
||||
stationName += index + 1 + "." + val + "<br\>";
|
||||
});
|
||||
stationName += "<br\>以上電站共用設備<br\>刪除則將解除所有設備共用關係!<br\>"
|
||||
|
||||
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');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
@ -2611,7 +2611,6 @@
|
||||
ExceptionTable.ajax.reload();
|
||||
return;
|
||||
}
|
||||
|
||||
}, 'json');
|
||||
}
|
||||
}
|
||||
@ -2622,16 +2621,12 @@
|
||||
$("#Exception-modal .modal-title").html("異常設定資料 - 編輯");
|
||||
var tyname = $(this).parents('tr').attr('data-typename');
|
||||
selected_id = $(this).parents('tr').attr('data-id');
|
||||
|
||||
//取得單一異常設定資料
|
||||
var url = "/PowerStation/GetOneException/";
|
||||
|
||||
var send_data = {
|
||||
SelectedId: selected_id,
|
||||
PowerStationId: stationId,
|
||||
}
|
||||
|
||||
|
||||
$.post(url, send_data, function (rel) {
|
||||
if (rel.code != "0000") {
|
||||
toast_error(rel.msg);
|
||||
@ -3013,9 +3008,7 @@
|
||||
});
|
||||
|
||||
$('#power_station_operation_personnel').change(function () {
|
||||
//$(this).valid();
|
||||
if (stationId == 'new' || station_infocreate) {
|
||||
console.log($('#power_station_operation_personnel').val().length);
|
||||
if ($('#power_station_operation_personnel').val().length == 0) {
|
||||
$('#power_station_operation_personnel-error').show();
|
||||
} else {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user