1. 修改 帳號管理的 使用者電站

This commit is contained in:
Kai 2021-06-28 20:57:09 +08:00
parent f47598a5ef
commit 913b06bbf2
8 changed files with 347 additions and 15 deletions

View File

@ -433,5 +433,69 @@ namespace SolarPower.Controllers
return apiResult; return apiResult;
} }
[HttpPost]
public async Task<ApiResult<List<UserPowerStation>>> GetUserPowerStation(int id)
{
ApiResult<List<UserPowerStation>> apiResult = new ApiResult<List<UserPowerStation>>();
List<UserPowerStation> userPowerStations = null;
try
{
userPowerStations = await userRepository.GetUserPowerStationAsync(id);
if (userPowerStations == null)
{
apiResult.Code = "9988";
apiResult.Msg = errorCode.GetString(apiResult.Code);
return apiResult;
}
apiResult.Code = "0000";
apiResult.Data = userPowerStations;
}
catch (Exception exception)
{
apiResult.Code = "9999";
apiResult.Msg = errorCode.GetString(apiResult.Code);
Logger.LogError("【" + controllerName + "/" + actionName + "】" + "Id=" + id);
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
}
return apiResult;
}
[HttpPost]
public async Task<ApiResult<string>> DeleteOneUserPowerStation(int id)
{
ApiResult<string> apiResult = new ApiResult<string>();
try
{
var userPowerStation = userRepository.GetOneUserPowerStationAsync(id);
if (userPowerStation == null)
{
apiResult.Code = "9988";
apiResult.Msg = errorCode.GetString(apiResult.Code);
return apiResult;
}
await userRepository.DeleteOneUserPowerStationAsync(id);
apiResult.Code = "0000";
apiResult.Msg = "刪除成功";
}
catch (Exception exception)
{
apiResult.Code = "9999";
apiResult.Msg = errorCode.GetString(apiResult.Code);
Logger.LogError("【" + controllerName + "/" + actionName + "】" + "Id=" + id);
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
}
return apiResult;
}
} }
} }

View File

@ -60,6 +60,7 @@ namespace SolarPower.Models.User
public string Account { get; set; } //帳號 public string Account { get; set; } //帳號
public byte Status { get; set; } //狀態 public byte Status { get; set; } //狀態
public int CompanyId { get; set; } //公司編號 public int CompanyId { get; set; } //公司編號
public string CompanyName { get; set; } //公司名稱
public string Email { get; set; } //信箱 public string Email { get; set; } //信箱
public string Phone { get; set; } //手機 public string Phone { get; set; } //手機
public int RoleId { get; set; } //角色編號 public int RoleId { get; set; } //角色編號
@ -135,5 +136,14 @@ namespace SolarPower.Models.User
public string Value { get; set; } public string Value { get; set; }
} }
public class UserPowerStation
{
public int Id { get; set; }
public string PowerStationName { get; set; }
public string Code { get; set; }
public string EscrowName { get; set; }
}
} }

View File

@ -147,7 +147,12 @@ namespace SolarPower.Repository.Implement
conn.Open(); conn.Open();
try try
{ {
var sql = $"SELECT * FROM {tableName} WHERE deleted = 0 AND id = @Id"; var sql = @$"SELECT
u.*,
c.Name AS CompanyName
FROM {tableName} u
LEFT JOIN company c ON u.CompanyId = c.Id
WHERE u.Deleted = 0 AND u.Id = @Id";
result = await conn.QueryFirstOrDefaultAsync<SimpleUser>(sql, new { Id = id }); result = await conn.QueryFirstOrDefaultAsync<SimpleUser>(sql, new { Id = id });
} }
@ -247,10 +252,12 @@ namespace SolarPower.Repository.Implement
var sql = @$"SELECT var sql = @$"SELECT
u.*, u.*,
c.Name AS CompanyName, c.Name AS CompanyName,
r.Name AS RoleName r.Name AS RoleName,
opc.SPStationAmount
FROM {tableName} u FROM {tableName} u
LEFT JOIN company c ON u.CompanyId = c.Id LEFT JOIN company c ON u.CompanyId = c.Id
LEFT JOIN role r ON u.RoleId = r.Id LEFT JOIN role r ON u.RoleId = r.Id
LEFT JOIN (SELECT op.UserId, COUNT(*) AS SPStationAmount FROM power_station_operation_personnel op WHERE op.Deleted = 0 GROUP BY op.UserId) opc ON u.Id = opc.UserId
WHERE u.Deleted = 0"; WHERE u.Deleted = 0";
if (filter.SelectedCompanyId > 0) if (filter.SelectedCompanyId > 0)
@ -269,6 +276,7 @@ namespace SolarPower.Repository.Implement
} }
result = (await conn.QueryAsync<UserDateTable>(sql, filter)).ToList(); result = (await conn.QueryAsync<UserDateTable>(sql, filter)).ToList();
} }
catch (Exception exception) catch (Exception exception)
{ {
@ -305,5 +313,106 @@ namespace SolarPower.Repository.Implement
return result; return result;
} }
} }
/// <summary>
/// 透過使用者Id取得該使用者所有管理的電站
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
public async Task<List<UserPowerStation>> GetUserPowerStationAsync(int userId)
{
List<UserPowerStation> result;
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
try
{
var sql = @$"SELECT
op.Id,
ps.Code,
ps.Name AS PowerStationName,
CASE ps.IsEscrow WHEN 1 THEN CONCAT(ps.EscrowName, '()')
WHEN 0 THEN c.Name
END AS EscrowName
FROM power_station_operation_personnel op
LEFT JOIN power_station ps ON op.PowerStationId = ps.Id
LEFT JOIN company c ON ps.CompanyId = c.Id
WHERE op.Deleted = 0 AND op.UserId = @UserId";
result = (await conn.QueryAsync<UserPowerStation>(sql, new { UserId = userId })).ToList();
}
catch (Exception exception)
{
throw exception;
}
return result;
}
}
/// <summary>
/// 透過Id取得該使用者單一管理的電站
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public async Task<UserPowerStation> GetOneUserPowerStationAsync(int id)
{
UserPowerStation result;
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
try
{
var sql = @$"SELECT
op.Id,
ps.Code,
ps.Name,
CASE ps.IsEscrow WHEN 1 THEN CONCAT(ps.EscrowName, '()')
WHEN 0 THEN c.Name
END AS EscrowName
FROM power_station_operation_personnel op
LEFT JOIN power_station ps ON op.PowerStationId = ps.Id
LEFT JOIN company c ON ps.CompanyId = c.Id
WHERE op.Deleted = 0 AND op.Id = @Id";
result = await conn.QueryFirstOrDefaultAsync<UserPowerStation>(sql, new { Id = id });
}
catch (Exception exception)
{
throw exception;
}
return result;
}
}
/// <summary>
/// 透過編號,軟刪除使用者電站
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public async Task DeleteOneUserPowerStationAsync(int id)
{
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
conn.Open();
using (var trans = conn.BeginTransaction())
{
try
{
var sql = $"UPDATE power_station_operation_personnel SET deleted = 1 WHERE Id = @Id";
await conn.ExecuteAsync(sql, new { Id = id }, trans);
trans.Commit();
}
catch (Exception exception)
{
trans.Rollback();
throw exception;
}
finally
{
conn.Close();
}
}
}
}
} }
} }

View File

@ -74,5 +74,26 @@ namespace SolarPower.Repository.Interface
/// <param name="CompanyId"></param> /// <param name="CompanyId"></param>
/// <returns></returns> /// <returns></returns>
Task<List<UserSelectItemList>> GetUserSelectOptionListAsync(int CompanyId); Task<List<UserSelectItemList>> GetUserSelectOptionListAsync(int CompanyId);
/// <summary>
/// 透過使用者Id取得該使用者所有管理的電站
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
Task<List<UserPowerStation>> GetUserPowerStationAsync(int userId);
/// <summary>
/// 透過Id取得該使用者單一管理的電站
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
Task<UserPowerStation> GetOneUserPowerStationAsync(int id);
/// <summary>
/// 透過Id刪除該使用者所管理的電站
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
Task DeleteOneUserPowerStationAsync(int id);
} }
} }

View File

@ -95,6 +95,7 @@
<None Include="wwwroot\img\favicon\site.webmanifest" /> <None Include="wwwroot\img\favicon\site.webmanifest" />
<None Include="wwwroot\img\logo-flat.svg" /> <None Include="wwwroot\img\logo-flat.svg" />
<None Include="wwwroot\img\logo-gradient.svg" /> <None Include="wwwroot\img\logo-gradient.svg" />
<None Include="wwwroot\img\logo.png_" />
<None Include="wwwroot\img\logo.svg" /> <None Include="wwwroot\img\logo.svg" />
<None Include="wwwroot\img\svg\pattern-1.svg" /> <None Include="wwwroot\img\svg\pattern-1.svg" />
<None Include="wwwroot\img\svg\pattern-2.svg" /> <None Include="wwwroot\img\svg\pattern-2.svg" />
@ -103,6 +104,7 @@
<None Include="wwwroot\js\app.bundle.js" /> <None Include="wwwroot\js\app.bundle.js" />
<None Include="wwwroot\js\datagrid\datatables\datatables.bundle.js" /> <None Include="wwwroot\js\datagrid\datatables\datatables.bundle.js" />
<None Include="wwwroot\js\datagrid\datatables\datatables.export.js" /> <None Include="wwwroot\js\datagrid\datatables\datatables.export.js" />
<None Include="wwwroot\js\daterangepicker.js" />
<None Include="wwwroot\js\dependency\moment\moment.js" /> <None Include="wwwroot\js\dependency\moment\moment.js" />
<None Include="wwwroot\js\formplugins\bootstrap-colorpicker\bootstrap-colorpicker.js" /> <None Include="wwwroot\js\formplugins\bootstrap-colorpicker\bootstrap-colorpicker.js" />
<None Include="wwwroot\js\formplugins\bootstrap-datepicker\bootstrap-datepicker.js" /> <None Include="wwwroot\js\formplugins\bootstrap-datepicker\bootstrap-datepicker.js" />
@ -117,6 +119,8 @@
<None Include="wwwroot\js\formplugins\smartwizard\smartwizard.js" /> <None Include="wwwroot\js\formplugins\smartwizard\smartwizard.js" />
<None Include="wwwroot\js\formplugins\summernote\summernote.js" /> <None Include="wwwroot\js\formplugins\summernote\summernote.js" />
<None Include="wwwroot\js\i18n\i18n.js" /> <None Include="wwwroot\js\i18n\i18n.js" />
<None Include="wwwroot\js\image.zoom.js" />
<None Include="wwwroot\js\jquery.table2excel.min.js" />
<None Include="wwwroot\js\json-path-picker\json-path-picker.js" /> <None Include="wwwroot\js\json-path-picker\json-path-picker.js" />
<None Include="wwwroot\js\miscellaneous\fullcalendar\fullcalendar.bundle.js" /> <None Include="wwwroot\js\miscellaneous\fullcalendar\fullcalendar.bundle.js" />
<None Include="wwwroot\js\miscellaneous\jqvmap\jqvmap.bundle.js" /> <None Include="wwwroot\js\miscellaneous\jqvmap\jqvmap.bundle.js" />

View File

@ -12,9 +12,9 @@
<meta name="msapplication-tap-highlight" content="no"> <meta name="msapplication-tap-highlight" content="no">
<!-- base css --> <!-- base css -->
<link id="vendorsbundle" rel="stylesheet" media="screen, print" href="~/css/vendors.bundle.css"> <link id="vendorsbundle" rel="stylesheet" media="screen, print" href="~/css/vendors.bundle.css" asp-append-version="true">
<link id="appbundle" rel="stylesheet" media="screen, print" href="~/css/app.bundle.css"> <link id="appbundle" rel="stylesheet" media="screen, print" href="~/css/app.bundle.css" asp-append-version="true">
<link id="mytheme" rel="stylesheet" media="screen, print" href="~/css/themes/cust-theme-15.css"> <link id="mytheme" rel="stylesheet" media="screen, print" href="~/css/themes/cust-theme-15.css" asp-append-version="true">
<link id="myskin" rel="stylesheet" media="screen, print" href="~/css/skins/skin-master.css"> <link id="myskin" rel="stylesheet" media="screen, print" href="~/css/skins/skin-master.css">
<!-- Place favicon.ico in the root directory --> <!-- Place favicon.ico in the root directory -->
@ -39,7 +39,7 @@
<link rel="stylesheet" type="text/css" media="all" href="~/css/daterangepicker.css"> <link rel="stylesheet" type="text/css" media="all" href="~/css/daterangepicker.css">
</head> </head>
<body class="mod-bg-1"> <body class="mod-bg-1 mod-nav-link">
<!-- BEGIN Page Wrapper --> <!-- BEGIN Page Wrapper -->
<div class="page-wrapper"> <div class="page-wrapper">
@ -166,6 +166,7 @@
</li> </li>
</ul> </ul>
</li> </li>
<li class="@(ViewData["MainNum"] == "5" ? "active open" : "")"> <li class="@(ViewData["MainNum"] == "5" ? "active open" : "")">
<a href="#" title="Category" data-filter-tags="category"> <a href="#" title="Category" data-filter-tags="category">
<i class="fal fa-alien"></i> <i class="fal fa-alien"></i>
@ -173,14 +174,13 @@
</a> </a>
<ul> <ul>
<li class=""> <li class="">
<a href="javascript:void(0);" title="即時告警管理" data-filter-tags="utilities disabled item"> <a href="0alert.html" title="即時告警管理" data-filter-tags="utilities disabled item">
<span class="nav-link-text" data-i18n="nav.utilities_disabled_item">即時告警管理</span> <span class="nav-link-text" data-i18n="nav.utilities_disabled_item">即時告警管理</span>
</a> </a>
</li> </li>
</ul> </ul>
</li> </li>
<li class="@(ViewData["MainNum"] == "6" ? "active open" : "")"> <li class="@(ViewData["MainNum"] == "6" ? "active open" : "")">
<a href="#" title="Category" data-filter-tags="category"> <a href="#" title="Category" data-filter-tags="category">
<i class="fal fa-alien"></i> <i class="fal fa-alien"></i>
@ -192,7 +192,7 @@
<span class="nav-link-text" data-i18n="nav.utilities_disabled_item">定期計畫建立</span> <span class="nav-link-text" data-i18n="nav.utilities_disabled_item">定期計畫建立</span>
</a> </a>
</li> </li>
<li class=""> <li class="@(ViewData["MainNum"] == "6" && ViewData["SubNum"] == "2" ? "active" : "")">
<a asp-controller="Operation" asp-action="Record" title="運維作業記錄" data-filter-tags="utilities disabled item"> <a asp-controller="Operation" asp-action="Record" title="運維作業記錄" data-filter-tags="utilities disabled item">
<span class="nav-link-text" data-i18n="nav.utilities_disabled_item">運維作業記錄</span> <span class="nav-link-text" data-i18n="nav.utilities_disabled_item">運維作業記錄</span>
</a> </a>

View File

@ -21,10 +21,10 @@
<img src="img/asus.png" id="company-logo"><span id="company-name">華碩電腦</span> <img src="img/asus.png" id="company-logo"><span id="company-name">華碩電腦</span>
</h1> </h1>
</div> </div>
<ul class="nav nav-tabs nav-tabs-clean" id="tabs" role="tablist"> <ul class="nav nav-tabs" id="tabs" role="tablist">
<li class="nav-item"><a class="nav-link active" data-toggle="tab" href="#tab-user-manager" role="tab">帳號管理</a></li> <li class="nav-item"><a class="nav-link active" data-toggle="tab" href="#tab-user-manager" role="tab"><i class="fal fa-home text-success"></i> <span class="hidden-sm-down ml-1">帳號管理</span></a></li>
<li class="nav-item"><a class="nav-link" data-toggle="tab" href="#tab-role-manager" role="tab">角色管理</a></li> <li class="nav-item"><a class="nav-link" data-toggle="tab" href="#tab-role-manager" role="tab"><i class="fal fa-user text-primary"></i> <span class="hidden-sm-down ml-1">角色管理</span></a></li>
<li class="nav-item"><a class="nav-link" data-toggle="tab" href="#tab-role-auth" role="tab">角色權限</a></li> <li class="nav-item"><a class="nav-link" data-toggle="tab" href="#tab-role-auth" role="tab"><i class="fal fa-cog text-danger"></i> <span class="hidden-sm-down ml-1">角色權限</span></a></li>
</ul> </ul>
<div class="tab-content p-3"> <div class="tab-content p-3">
<div class="tab-pane fade show active" id="tab-user-manager" role="tabpanel" aria-labelledby="tab-user-manager"> <div class="tab-pane fade show active" id="tab-user-manager" role="tabpanel" aria-labelledby="tab-user-manager">
@ -260,6 +260,14 @@
"defaultContent": '<button class="btn btn-primary edit-btn">修改</button> <button class="btn btn-danger del-btn">刪除</button>' "defaultContent": '<button class="btn btn-primary edit-btn">修改</button> <button class="btn btn-danger del-btn">刪除</button>'
} }
], ],
"columnDefs": [{
'targets': 2,
'searchable': false,
'orderable': false,
'render': function (data, type, full, meta) {
return '<a href="javascript:void(0);" onclick="GetUserPowerStation(' + full.id + ')">' + data + '</a>';
}
}],
"language": { "language": {
"emptyTable": "無資料...", "emptyTable": "無資料...",
"processing": "處理中...", "processing": "處理中...",
@ -767,6 +775,88 @@
} }
//#endregion //#endregion
//#region 使用者電站資訊
function GetUserPowerStation(id) {
var send_data = {
Id: id
}
var url_user_info = "/User/GetOneUser";
$.post(url_user_info, send_data, function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
$("#user-power-station-modal .modal-title").html(rel.data.companyName + "" + rel.data.name);
}, 'json');
var url = "/User/GetUserPowerStation"
$.post(url, send_data, function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
userPowerStationTable = $("#user-power-station-table > tbody");
userPowerStationTable.empty();
rel.data.forEach(function (value, index) {
var str = "";
str += "<tr>";
str += "<td>" + value.code + "</td>";
str += "<td>" + value.powerStationName + "</td>";
str += "<td>" + value.escrowName + "</td>";
str += "<td>" + '<button type="button" class="btn btn-danger btn-pills waves-effect waves-themed del-user-power-station" data-id="' + value.id + '">刪除</button>' + "</td>";
str += "</tr>";
userPowerStationTable.append(str);
});
$("#user-power-station-modal").modal();
}, 'json');
}
//#endregion
//#region 刪除使用者電站
$("#user-power-station-table").on("click", "button.del-user-power-station", function () {
selected_id = $(this).attr('data-id');
var del_btn = $(this);
Swal.fire(
{
title: "刪除",
text: "你確定是否刪除此筆資料?",
type: "warning",
icon: 'warning',
showCancelButton: true,
confirmButtonText: "是",
cancelButtonText: "否"
}).then(function (result) {
if (result.value) {
//取得單一系統管理員
var url = "/User/DeleteOneUserPowerStation/";
var send_data = {
Id: selected_id
}
$.post(url, send_data, function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
del_btn.parents("tr").remove();
toast_ok(rel.msg);
}, 'json');
}
});
});
//#endregion
//#endregion //#endregion
//#region 角色管理Tab //#region 角色管理Tab

View File

@ -113,9 +113,43 @@
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button> <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
<button type="button" class="btn btn-primary" onclick="SaveUser()">確定</button> <button type="button" class="btn btn-primary" data-dismiss="modal">確定</button>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<!-- /.Modal 人員基本資料 --> <!-- /.Modal 人員基本資料 -->
<!-- Modal 人員電站資訊 -->
<div class="modal fade" id="user-power-station-modal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog modal-dialog-centered modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">
</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true"><i class="fal fa-times"></i></span>
</button>
</div>
<div class="modal-body">
<table id="user-power-station-table" class="table table-bordered text-center">
<thead>
<tr>
<th>電站代碼</th>
<th>電站名稱</th>
<th>公司</th>
<th>功能</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
<button type="button" class="btn btn-primary" onclick="SaveUser()">確定</button>
</div>
</div>
</div>
</div>
<!-- /.Modal 人員電站資訊 -->