刪除電站
This commit is contained in:
parent
9dc7eca7fd
commit
4f96b2ef92
@ -3065,7 +3065,25 @@ namespace SolarPower.Controllers
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
public async Task<ApiResult<string>> DeletePowerStation (int stationId)
|
||||
{
|
||||
ApiResult<string> apiResult = new ApiResult<string>();
|
||||
|
||||
try
|
||||
{
|
||||
await powerStationRepository.DeleteOne(stationId);
|
||||
apiResult.Msg = "刪除成功";
|
||||
apiResult.Code = "0000";
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = errorCode.GetString(apiResult.Code);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + stationId);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
}
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
public JObject Fetch_PostWithJSONFormat(string url, string paramter)
|
||||
{
|
||||
|
||||
@ -85,6 +85,7 @@ namespace SolarPower.Models
|
||||
|
||||
public class MyPowerStationSummary
|
||||
{
|
||||
public int CityId { get; set; }
|
||||
public string CityName { get; set; }
|
||||
public int Amount { get; set; }
|
||||
public List<MyPowerStation> MyPowerStations { get; set; }
|
||||
|
||||
@ -64,6 +64,7 @@ namespace SolarPower.Repository.Implement
|
||||
foreach (var myPowerStationInfo in myPowerStationInfos_group)
|
||||
{
|
||||
MyPowerStationSummary myPowerStationSummary = new MyPowerStationSummary();
|
||||
myPowerStationSummary.CityId = myPowerStationInfo.First().CityId;
|
||||
myPowerStationSummary.CityName = myPowerStationInfo.First().CityName;
|
||||
myPowerStationSummary.Amount = myPowerStationInfo.Count();
|
||||
myPowerStationSummary.MyPowerStations = new List<MyPowerStation>();
|
||||
@ -1460,31 +1461,26 @@ namespace SolarPower.Repository.Implement
|
||||
using IDbConnection conn = _databaseHelper.GetConnection();
|
||||
List<SolarCityAmount> solaramount = new List<SolarCityAmount>();
|
||||
conn.Open();
|
||||
var trans = conn.BeginTransaction();
|
||||
try
|
||||
{
|
||||
if (User.Role.Layer == 0 || User.Role.Layer == 1)
|
||||
{
|
||||
var sql = "SELECT city.Id AS CityId, city.Name AS City,COUNT(*) AS Amount FROM power_station LEFT JOIN city ON power_station.CityId = city.Id GROUP BY power_station.CityId";
|
||||
var sql = "SELECT city.Id AS CityId, city.Name AS City,COUNT(*) AS Amount FROM power_station LEFT JOIN city ON power_station.CityId = city.Id WHERE Deleted = 0 GROUP BY power_station.CityId ORDER BY city.Id";
|
||||
solaramount = (await conn.QueryAsync<SolarCityAmount>(sql)).ToList();
|
||||
trans.Commit();
|
||||
}
|
||||
else if (User.Role.Layer == 2)
|
||||
{
|
||||
var sql = "SELECT city.Id AS CityId, city.Name AS City,COUNT(*) AS Amount FROM power_station LEFT JOIN city ON power_station.CityId = city.Id WHERE CompanyId = @CompanyId GROUP BY power_station.CityId ORDER BY power_station.CityId ";
|
||||
var sql = "SELECT city.Id AS CityId, city.Name AS City,COUNT(*) AS Amount FROM power_station LEFT JOIN city ON power_station.CityId = city.Id WHERE CompanyId = @CompanyId and Deleted = 0 GROUP BY power_station.CityId ORDER BY power_station.CityId";
|
||||
solaramount = (await conn.QueryAsync<SolarCityAmount>(sql, new { CompanyId = User.CompanyId })).ToList();
|
||||
trans.Commit();
|
||||
}
|
||||
else
|
||||
{
|
||||
var sql = "SELECT city.Id AS CityId, city.Name AS City,COUNT(*) AS Amount FROM power_station LEFT JOIN city ON power_station.CityId = city.Id LEFT JOIN power_station_operation_personnel ON power_station.Id = power_station_operation_personnel.PowerStationId WHERE UserId = @UserId GROUP BY power_station.CityId ORDER BY power_station.CityId";
|
||||
var sql = "SELECT city.Id AS CityId, city.Name AS City,COUNT(*) AS Amount FROM power_station LEFT JOIN city ON power_station.CityId = city.Id LEFT JOIN power_station_operation_personnel ON power_station.Id = power_station_operation_personnel.PowerStationId WHERE UserId = @UserId and Deleted = 0 GROUP BY power_station.CityId ORDER BY power_station.CityId";
|
||||
solaramount = (await conn.QueryAsync<SolarCityAmount>(sql, new { UserId = User.Id })).ToList();
|
||||
trans.Commit();
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
trans.Rollback();
|
||||
throw exception;
|
||||
}
|
||||
finally
|
||||
@ -1498,7 +1494,6 @@ namespace SolarPower.Repository.Implement
|
||||
using IDbConnection conn = _databaseHelper.GetConnection();
|
||||
List<PowerStation> powerstation = new List<PowerStation>();
|
||||
conn.Open();
|
||||
var trans = conn.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var ids = "";
|
||||
@ -1516,9 +1511,8 @@ namespace SolarPower.Repository.Implement
|
||||
FROM power_station ps
|
||||
LEFT JOIN city c ON ps.CityId = c.Id
|
||||
LEFT JOIN area a ON ps.AreaId = a.Id
|
||||
WHERE ps.CityId IN @IDs";
|
||||
WHERE ps.CityId IN @IDs and ps.Deleted = 0";
|
||||
powerstation = (await conn.QueryAsync<PowerStation>(sql, new { IDs = CityId })).ToList();
|
||||
trans.Commit();
|
||||
}
|
||||
else if (User.Role.Layer == 2)
|
||||
{
|
||||
@ -1527,9 +1521,8 @@ namespace SolarPower.Repository.Implement
|
||||
LEFT JOIN city c ON ps.CityId = c.Id
|
||||
LEFT JOIN area a ON ps.AreaId = a.Id
|
||||
WHERE ps.CityId IN @IDs
|
||||
AND ps.CompanyId=@CompanyId";
|
||||
AND ps.CompanyId=@CompanyId and ps.Deleted = 0";
|
||||
powerstation = (await conn.QueryAsync<PowerStation>(sql, new { IDs = CityId, CompanyId = User.CompanyId })).ToList();
|
||||
trans.Commit();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1538,14 +1531,12 @@ namespace SolarPower.Repository.Implement
|
||||
LEFT JOIN city c ON ps.CityId = c.Id
|
||||
LEFT JOIN area a ON ps.AreaId = a.Id
|
||||
LEFT JOIN power_station_operation_personnel psop ON ps.Id = psop.PowerStationId
|
||||
WHERE ps.CityId IN @IDs AND psop.Userid = @UserId";
|
||||
WHERE ps.CityId IN @IDs AND psop.Userid = @UserId and ps.Deleted = 0";
|
||||
powerstation = (await conn.QueryAsync<PowerStation>(sql, new { IDs = CityId, UserId = User.Id })).ToList();
|
||||
trans.Commit();
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
trans.Rollback();
|
||||
throw exception;
|
||||
}
|
||||
finally
|
||||
|
||||
@ -344,7 +344,7 @@
|
||||
<th>裝置容量(kWp)</th>
|
||||
<th>逆變器數量</th>
|
||||
<th>台電掛表日</th>
|
||||
<th></th>
|
||||
<th>功能</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@ -408,17 +408,26 @@
|
||||
@section Scripts{
|
||||
<script>
|
||||
var tablocation = "";
|
||||
var ids = new Array(0);
|
||||
var localurl = this.location.href;
|
||||
$(function () {
|
||||
|
||||
var localurl = this.location.href;
|
||||
Cityes();
|
||||
|
||||
$('.nav-tabs a[href="#tab-newtaipei"]').tab('show');
|
||||
|
||||
TableDisplay();
|
||||
});
|
||||
|
||||
function Cityes() {
|
||||
var url = "/PowerStation/GetSolarCitySummary";
|
||||
var ids = new Array(0)
|
||||
$.post(url, function (rel) {
|
||||
if (rel.code != "0000") {
|
||||
toast_error(rel.msg);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
$('#areaTab').empty();
|
||||
$.each(rel.data, function (index, val) {
|
||||
//電站區域
|
||||
if (index == 0) {
|
||||
@ -442,16 +451,16 @@
|
||||
$("#areaTab").find(".nav-item > a").first().click();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}, 'json');
|
||||
}
|
||||
|
||||
function addPowerStationCard(ids) {
|
||||
|
||||
function addPowerStationCard(idsd) {
|
||||
|
||||
//alert(ids);
|
||||
var url = "/PowerStation/GetSolarByCity";
|
||||
var send_data = {
|
||||
cityid: ids
|
||||
cityid: idsd
|
||||
}
|
||||
$.post(url, send_data, function (rel) {
|
||||
if (rel.code != "0000") {
|
||||
@ -459,7 +468,9 @@
|
||||
return;
|
||||
}
|
||||
else {
|
||||
|
||||
$.each(rel.data, function (index, val) {
|
||||
$('#solarTable' + val.cityId).find('tbody').empty();
|
||||
});
|
||||
$.each(rel.data, function (index, val) {
|
||||
//電站卡片
|
||||
$('#templateCard').find('.col-xl-2').attr('id', 'card' + val.id).clone().appendTo($('#solarCard' + val.cityId));
|
||||
@ -471,13 +482,13 @@
|
||||
$('#card' + val.id).find('#inverter_amount').text(val.inverterAmount);
|
||||
$('#card' + val.id).find('#electricity_meter_at').text(val.electricityMeterAt);
|
||||
|
||||
$('#solarTable' + val.cityId).find('tbody').append('<tr>' +
|
||||
$('#solarTable' + val.cityId).find('tbody').append('<tr data-id="' + val.id + '" datacity-id="' + val.cityId+'"">' +
|
||||
'<td>' + val.id + '</td>' +
|
||||
'<td>' + val.name + '</td>' +
|
||||
'<td>' + val.generatingCapacity.toFixed(2) + '</td>' +
|
||||
'<td>' + val.inverterAmount + '</td>' +
|
||||
'<td>' + val.electricityMeterAt + '</td>' +
|
||||
'<td><button type="button" class="btn btn-primary btn-pills waves-effect waves-themed" onclick="location.href=\'' + localurl + '/edit?stationId=' + val.id + '\'">選擇</button></td>' +
|
||||
'<td> <button type="button" class="btn btn-primary btn-pills waves-effect waves-themed" onclick="location.href=\'' + localurl + '/edit?stationId=' + val.id + '\'">選擇</button> <button type="button" class="btn btn-danger btn-pills waves-effect waves-themed del-btnto">刪除</button></td>' +
|
||||
|
||||
'</tr>');
|
||||
});
|
||||
@ -489,15 +500,53 @@
|
||||
}, 'json');
|
||||
}
|
||||
|
||||
$('.nav-tabs a[href="#tab-newtaipei"]').tab('show');
|
||||
|
||||
TableDisplay();
|
||||
});
|
||||
|
||||
|
||||
|
||||
function CardDisplay() {
|
||||
$('.TableArea').hide();
|
||||
$('.solarCard').show();
|
||||
|
||||
}
|
||||
|
||||
$(document).on("click", "button.del-btnto", function () {
|
||||
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();
|
||||
|
||||
Cityes();
|
||||
|
||||
}, 'json');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
function TableDisplay() {
|
||||
$('.TableArea').show();
|
||||
$('.solarCard').hide();
|
||||
|
||||
@ -205,7 +205,7 @@
|
||||
ViewData["SubNum"].ToString() == ViewBag.myPowerStationSummaries.IndexOf(myPowerStationSummary).ToString() ? "active open" : "")">
|
||||
<a href="javascript:void(0);" title="Category" data-filter-tags="utilities menu child sublevel item">
|
||||
<span class="nav-link-text" data-i18n="nav.category">@myPowerStationSummary.CityName</span>
|
||||
<span class="dl-ref bg-primary-500 hidden-nav-function-minify hidden-nav-function-top">@myPowerStationSummary.Amount</span>
|
||||
<span class="dl-ref bg-primary-500 hidden-nav-function-minify hidden-nav-function-top" id="ul-List-@myPowerStationSummary.CityId">@myPowerStationSummary.Amount</span>
|
||||
</a>
|
||||
<ul>
|
||||
|
||||
@ -213,7 +213,7 @@
|
||||
{
|
||||
<li class="@(ViewData["MainNum"].ToString() == "2" &&
|
||||
ViewData["SubNum"].ToString() == ViewBag.myPowerStationSummaries.IndexOf(myPowerStationSummary).ToString() &&
|
||||
ViewData["TagNum"].ToString() == myPowerStationSummary.MyPowerStations.IndexOf(myPowerStation).ToString() ? "active" : "")">
|
||||
ViewData["TagNum"].ToString() == myPowerStationSummary.MyPowerStations.IndexOf(myPowerStation).ToString() ? "active" : "")" id="li-List-@myPowerStation.PowerStationId">
|
||||
<a asp-controller="StationOverview" asp-action="Info" asp-route-stationId="@myPowerStation.PowerStationId" title="Sublevel Item" data-filter-tags="utilities menu child sublevel item">
|
||||
<span class="nav-link-text" data-i18n="nav.utilities_menu_child_sublevel_item">@myPowerStation.PowerStationName</span>
|
||||
</a>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user