[後台] 修改區域設定

This commit is contained in:
dev02 2022-10-20 23:27:00 +08:00
parent bf61f7aef6
commit abf63105ef
5 changed files with 167 additions and 117 deletions

View File

@ -19,6 +19,8 @@ namespace Backend.Controllers
{
private readonly IBackendRepository backendRepository;
private string mapFileSaveAsPath = "";
private string main_system_name = "device_system_category_layer2";
private string sub_system_name = "device_system_category_layer1";
public BuildInfoController(IBackendRepository backendRepository)
{
@ -44,7 +46,7 @@ namespace Backend.Controllers
try
{
var sqlString = @$"SELECT A.priority, A.building_guid, A.full_name, A.ip_address, A.ip_port, (SELECT COUNT(*) FROM floor f WHERE f.deleted = 0 AND f.building_guid = A.building_guid) AS 'floorNum', A.created_at
var sqlString = @$"SELECT A.priority, A.building_tag, A.full_name, A.ip_address, A.ip_port, (SELECT COUNT(*) FROM floor f WHERE f.deleted = 0 AND f.building_tag = A.building_tag) AS 'floorNum', A.created_at
FROM building A
WHERE A.deleted = 0
ORDER BY A.priority ASC, A.created_at DESC";
@ -78,8 +80,8 @@ namespace Backend.Controllers
//判斷監控主機IP是否重複
var judgeIPAddressRepeat = true;
var sWhere = $@"deleted = 0 AND ip_address = @ip_address AND ip_port = @ip_port AND building_guid != @building_guid";
var buildInfos = await backendRepository.GetAllAsync<BuildInfo>("building", sWhere, new { ip_address = post.Ip_address, ip_port = post.Ip_port, building_guid = post.Building_guid });
var sWhere = $@"deleted = 0 AND ip_address = @ip_address AND ip_port = @ip_port AND building_tag != @building_tag";
var buildInfos = await backendRepository.GetAllAsync<BuildInfo>("building", sWhere, new { ip_address = post.Ip_address, ip_port = post.Ip_port, building_tag = post.building_tag });
if (buildInfos.Count == 0)
{
judgeIPAddressRepeat = false;
@ -87,19 +89,25 @@ namespace Backend.Controllers
if (!judgeIPAddressRepeat)
{
//新增
if (post.Building_guid == "0")
{
//產生一組GUID
var guid = Guid.NewGuid(); //大樓GUID
//Check for duplicate building tag
sWhere = $@"deleted = 0 AND building_tag = @Building_tag";
buildInfos = await backendRepository.GetAllAsync<BuildInfo>("building", sWhere, new { building_tag = post.building_tag });
if (buildInfos.Count > 0)
{
apiResult.Code = "0002";
apiResult.Msg = "區域代號不可重複";
return apiResult;
}
//新增
//抓取當前的Priority
var current_priority = await backendRepository.GetCurrentPriority("building");
Dictionary<string, object> building = new Dictionary<string, object>();
building = new Dictionary<string, object>()
{
{ "@building_guid", guid},
{ "@building_tag", post.building_tag},
{ "@full_name", post.Full_name},
{ "@ip_address", post.Ip_address},
{ "@ip_port", post.Ip_port},
@ -111,7 +119,48 @@ namespace Backend.Controllers
apiResult.Code = "0000";
apiResult.Msg = "新增成功";
}
else //修改
else
{
apiResult.Code = "0001";
apiResult.Msg = "監控主機IP不可重複";
}
}
catch (Exception exception)
{
apiResult.Code = "9999";
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
string json = System.Text.Json.JsonSerializer.Serialize(post);
Logger.LogError("【" + controllerName + "/" + actionName + "】" + json);
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
}
return apiResult;
}
/// <summary>
/// 新增 / 修改 區域基本資料
/// </summary>
/// <param name="post"></param>
/// <returns></returns>
[HttpPost]
public async Task<ApiResult<string>> EditBuildInfo(BuildInfo post)
{
ApiResult<string> apiResult = new ApiResult<string>();
try
{
//判斷監控主機IP是否重複
var judgeIPAddressRepeat = true;
var sWhere = $@"deleted = 0 AND ip_address = @ip_address AND ip_port = @ip_port AND building_tag != @building_tag";
var buildInfos = await backendRepository.GetAllAsync<BuildInfo>("building", sWhere, new { ip_address = post.Ip_address, ip_port = post.Ip_port, building_tag = post.building_tag });
if (buildInfos.Count == 0)
{
judgeIPAddressRepeat = false;
}
if (!judgeIPAddressRepeat)
{
Dictionary<string, object> building = new Dictionary<string, object>();
building = new Dictionary<string, object>()
@ -122,12 +171,11 @@ namespace Backend.Controllers
{ "@updated_by", myUserInfo.Userinfo_guid},
{ "@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}
};
await backendRepository.UpdateOneByCustomTable(building, "building", "building_guid='" + post.Building_guid + "'");
await backendRepository.UpdateOneByCustomTable(building, "building", "building_tag='" + post.building_tag + "'");
apiResult.Code = "0000";
apiResult.Msg = "修改成功";
}
}
else
{
apiResult.Code = "0001";
@ -148,14 +196,14 @@ namespace Backend.Controllers
}
[HttpPost]
public async Task<ApiResult<string>> DeleteOneBuild(string guid)
public async Task<ApiResult<string>> DeleteOneBuild(string tag)
{
var apiResult = new ApiResult<string>();
try
{
string sWhere = @$"deleted = @Deleted AND building_guid = @Guid";
string sWhere = @$"deleted = @Deleted AND building_tag = @Tag";
object param = new { Deleted = 0, Guid = guid };
object param = new { Deleted = 0, Tag = tag };
var buildInfo = await backendRepository.GetOneAsync<BuildInfo>("building", sWhere, param);
@ -167,8 +215,8 @@ namespace Backend.Controllers
}
//檢查是否有未刪除的區域選單
var sbuildMenuWhere = $@"building_guid = @Guid";
var buildMenus = await backendRepository.GetAllAsync<BuildMenu>("building_menu", sbuildMenuWhere, new { Guid = guid });
var sbuildMenuWhere = $@"building_tag = @Tag";
var buildMenus = await backendRepository.GetAllAsync<BuildMenu>("building_menu", sbuildMenuWhere, new { Tag = tag });
if (buildMenus.Count > 0)
{
@ -178,8 +226,8 @@ namespace Backend.Controllers
}
//檢查底下是否有未刪除的樓層
var sfloorWhere = $@"deleted = 0 AND building_guid = @Guid";
var floors = await backendRepository.GetAllAsync<BuildFloor>("floor", sfloorWhere, new { Guid = guid });
var sfloorWhere = $@"deleted = 0 AND building_tag = @tag";
var floors = await backendRepository.GetAllAsync<BuildFloor>("floor", sfloorWhere, new { Tag = tag });
if (floors.Count > 0)
{
@ -189,7 +237,7 @@ namespace Backend.Controllers
return apiResult;
}
await backendRepository.DeleteOne(guid, "building", "building_guid");
await backendRepository.DeleteOne(tag, "building", "building_tag");
apiResult.Code = "0000";
apiResult.Msg = "刪除成功";
@ -199,7 +247,7 @@ namespace Backend.Controllers
{
apiResult.Code = "9999";
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
Logger.LogError("【" + controllerName + "/" + actionName + "】" + "building_guid=" + guid);
Logger.LogError("【" + controllerName + "/" + actionName + "】" + "building_tag=" + tag);
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
}
return apiResult;
@ -223,7 +271,7 @@ namespace Backend.Controllers
Dictionary<string, object> building_priority_dic = new Dictionary<string, object>();
building_priority_dic = new Dictionary<string, object>()
{
{ "building_guid", building_priority.Building_guid},
{ "building_tag", building_priority.Building_tag},
{ "@priority", building_priority.Priority},
{ "@updated_by", myUserInfo.Userinfo_guid},
{ "@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}
@ -232,14 +280,9 @@ namespace Backend.Controllers
building_priorities.Add(building_priority_dic);
}
var sql = $@"UPDATE building SET priority = @priority, updated_by = @updated_by, updated_at=@updated_at WHERE building_guid = @building_guid";
var sql = $@"UPDATE building SET priority = @priority, updated_by = @updated_by, updated_at=@updated_at WHERE building_tag = @building_tag";
await backendRepository.ExecuteSql(sql, building_priorities);
#region
await backendRepository.ManualInsertBackgroundServiceTask("", "", "building", "update_list", building_priorities);
#endregion
}
apiResult.Code = "0000";
@ -261,7 +304,7 @@ namespace Backend.Controllers
/// <param name="post"></param>
/// <returns></returns>
[HttpPost]
public async Task<ApiResult<List<BuildFloor>>> BuildFloorList(string BuildGuid)
public async Task<ApiResult<List<BuildFloor>>> BuildFloorList(string build_tag)
{
ApiResult<List<BuildFloor>> apiResult = new ApiResult<List<BuildFloor>>();
List<BuildFloor> buildInfo = new List<BuildFloor>();
@ -271,9 +314,9 @@ namespace Backend.Controllers
var sqlString = @$"SELECT A.floor_guid, A.full_name, InitMapName + '.svg' AS 'initMapName', A.priority, A.created_at
FROM floor A
WHERE deleted = @deleted
AND A.building_guid = @building_guid
AND A.building_tag = @building_tag
ORDER BY A.priority ASC";
buildInfo = await backendRepository.GetAllAsync<BuildFloor>(sqlString, new { deleted = 0, building_guid = BuildGuid });
buildInfo = await backendRepository.GetAllAsync<BuildFloor>(sqlString, new { deleted = 0, building_tag = build_tag });
apiResult.Code = "0000";
apiResult.Data = buildInfo;
@ -348,13 +391,13 @@ namespace Backend.Controllers
var floor_map_guid = Guid.NewGuid();
//抓取當前的Priority
var current_priority = await backendRepository.GetCurrentPriority("floor", "deleted = 0 AND building_guid = '" + post.Building_guid + "'");
var current_priority = await backendRepository.GetCurrentPriority("floor", "deleted = 0 AND building_tag = '" + post.Building_tag + "'");
Dictionary<string, object> floor = new Dictionary<string, object>();
floor = new Dictionary<string, object>()
{
{ "@floor_guid", guid},
{ "@building_guid", post.Building_guid},
{ "@building_tag", post.Building_tag},
{ "@full_name", post.Full_name},
{ "@InitMapName", post.InitMapName},
{ "@floor_map_name", floor_map_guid},
@ -376,26 +419,6 @@ namespace Backend.Controllers
}
}
#region
List<Repository.Models.FileInfo> fileInfos = new List<Repository.Models.FileInfo>();
if (post.MapFile != null)
{
var split = post.MapFile.FileName.Split(".");
var fileName = floor_map_guid + "." + split[split.Length - 1];
var fullPath = Path.Combine(mapFileSaveAsPath, fileName);
Repository.Models.FileInfo fileInfo = new Repository.Models.FileInfo();
fileInfo.Folder = "floor_map";
fileInfo.OriginalFileName = null;
fileInfo.FileName = fileName;
fileInfo.File = fullPath;
fileInfos.Add(fileInfo);
await backendRepository.ManualInsertFileBackgroundServiceTask("", post.Building_guid, "floor", fileInfos);
}
#endregion
apiResult.Code = "0000";
apiResult.Msg = "新增成功";
}
@ -436,26 +459,6 @@ namespace Backend.Controllers
}
}
#region
List<Repository.Models.FileInfo> fileInfos = new List<Repository.Models.FileInfo>();
if (post.MapFile != null)
{
var split = post.MapFile.FileName.Split(".");
var fileName = floor_map_guid + "." + split[split.Length - 1];
var fullPath = Path.Combine(mapFileSaveAsPath, fileName);
Repository.Models.FileInfo fileInfo = new Repository.Models.FileInfo();
fileInfo.Folder = "floor_map";
fileInfo.OriginalFileName = buildFloor.Floor_map_name + ".svg";
fileInfo.FileName = fileName;
fileInfo.File = fullPath;
fileInfos.Add(fileInfo);
}
await backendRepository.ManualInsertFileBackgroundServiceTask("", post.Building_guid, "floor", fileInfos);
#endregion
apiResult.Code = "0000";
apiResult.Msg = "修改成功";
}
@ -502,10 +505,6 @@ namespace Backend.Controllers
var sql = $@"UPDATE floor SET priority = @priority, updated_by = @updated_by, updated_at=@updated_at WHERE floor_guid = @floor_guid";
await backendRepository.ExecuteSql(sql, floor_priorities);
#region
await backendRepository.ManualInsertBackgroundServiceTask("", "", "floor", "update_list", floor_priorities);
#endregion
}
apiResult.Code = "0000";
@ -547,20 +546,20 @@ namespace Backend.Controllers
//判斷區域選單是否還有使用該樓層
var sub_system_where = $@"SELECT
CONCAT(b.full_name, ' - ', ms.full_name, ' - ', ss.full_name)
CONCAT(b.full_name, ' - ', v1.system_key, ' - ', v2.system_key)
FROM (
SELECT
ssf.building_guid,
ssf.main_system_guid,
ssf.sub_system_guid
ssf.building_tag,
ssf.main_system_tag,
ssf.sub_system_tag
FROM sub_system_floor ssf
WHERE ssf.deleted = 0 AND floor_guid = @Guid
WHERE ssf.deleted = 0 AND ssf.floor_tag = @floor_tag
) ssf
LEFT JOIN building b ON ssf.building_guid = b.building_guid AND b.deleted = 0
LEFT JOIN main_system ms ON ssf.main_system_guid = ms.main_system_guid AND ms.deleted = 0
LEFT JOIN sub_system ss ON ssf.sub_system_guid = ss.sub_system_guid AND ss.deleted = 0";
LEFT JOIN building b ON ssf.building_tag = b.building_tag AND b.deleted = 0
LEFT JOIN variable v1 ON ssf.main_system_tag = v1.system_value AND v1.system_type = @main_system_type AND v1.deleted = 0
LEFT JOIN variable v2 ON ssf.sub_system_tag = v2.system_value AND v2.system_type = @sub_system_type AND v2.deleted = 0";
var sub_system_floors = await backendRepository.GetAllAsync<string>(sub_system_where, new { Guid = guid });
var sub_system_floors = await backendRepository.GetAllAsync<string>(sub_system_where, new { floor_tag = buildFloor.Full_name, main_system_type = main_system_name, sub_system_type = sub_system_name });
if (sub_system_floors.Count > 0)
{
apiResult.Code = "9997";

View File

@ -23,6 +23,7 @@ namespace Backend.Models
{
public string Floor_guid { get; set; } //樓層GUID
public string Building_guid { get; set; } //區域GUID
public string Building_tag { get; set; } //區域GUID
public string Full_name { get; set; } //建築名稱
public string InitMapName { get; set; } //使用者命名平面圖檔檔名
public string MapUrl { get; set; } //使用者命名平面圖檔檔名
@ -43,6 +44,7 @@ namespace Backend.Models
public class BuildInfoPriority
{
public string Building_guid { get; set; } //區域GUID
public string Building_tag { get; set; } //區域TAG
public int Priority { get; set; }
}

View File

@ -163,6 +163,9 @@
selected_build_guid = $(this).parents('tr').attr('data-guid');
$('#build-modal .modal-title').html("區域基本資料 - 修改");
$('#build_name_tag').val(selected_build_guid);
$('#build_name_tag').prop('disabled', true);
$("#save-building-btn").attr("onClick", "EditBuild()");
$('#build_name_modal').val($(this).parents('tr')[0].children[1].innerText);
$('#ip_address_modal').val($(this).parents('tr')[0].children[2].innerText);
$('#ip_port_modal').val($(this).parents('tr')[0].children[3].innerText);
@ -187,7 +190,7 @@
if (result.value) {
var url = "/BuildInfo/DeleteOneBuild/";
var send_data = {
guid: selected_build_guid
tag: selected_build_guid
}
$.post(url, send_data, function (rel) {
if (rel.code == "9999") {
@ -218,7 +221,9 @@
function AddBuild() {
selected_build_guid = "0";
BuildInfoValidate.resetForm();
$("#save-building-btn").attr("onClick", "SaveBuild()");
$("#build-modal .modal-title").html("區域基本資料 - 新增");
$('#build_name_tag').prop('disabled', false);
$("#build-form").trigger("reset");
$("#build-modal").modal();
@ -252,6 +257,41 @@
if ($("#build-form").valid()) {
$("#save-building-btn").html('<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>').attr("disabled", true);
var url = "/BuildInfo/SaveBuildInfo";
var send_data = {
building_tag: $('#build_name_tag').val(),
Full_name: $('#build_name_modal').val(),
Ip_address: $('#ip_address_modal').val(),
Ip_port: $('#ip_port_modal').val()
}
$.post(url, send_data, function (rel) {
$("#save-building-btn").html('確定').attr("disabled", false);
if (rel.code != "0000") {
if (rel.code == "9999") {
toast_error(rel.msg);
}
else {
toast_warning(rel.msg);
}
return;
}
else {
toast_ok(rel.msg);
buildInfoTable.ajax.reload(null, false);
$('#build-modal').modal('hide');
return;
}
}, 'json')
.fail(function (xhr, status, error) {
$("#save-building-btn").html('確定').attr("disabled", false);
});
}
}
function EditBuild() {
if ($("#build-form").valid()) {
$("#save-building-btn").html('<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>').attr("disabled", true);
var url = "/BuildInfo/EditBuildInfo";
var send_data = {
building_tag: selected_build_guid,
Full_name: $('#build_name_modal').val(),
@ -342,7 +382,7 @@
"url": "/BuildInfo/BuildFloorList",
"type": "POST",
"data": function (d) {
d.BuildGuid = selected_build_guid_top;
d.build_tag = selected_build_guid_top;
},
"dataSrc": function (rel) {
if (rel.code == "9999") {

View File

@ -40,6 +40,10 @@
<div class="modal-body">
<form class="user-form" id="build-form">
<div class="row">
<div class="form-group col-12">
<label class="form-label" for="build_name_tag"><span class="text-danger">*</span>代碼</label>
<input type="text" id="build_name_tag" class="form-control" name="build_name_tag">
</div>
<div class="form-group col-12">
<label class="form-label" for="build_name_modal"><span class="text-danger">*</span>區域名稱</label>
<input type="text" id="build_name_modal" class="form-control" name="build_name_modal">

View File

@ -0,0 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
<path d="M30,1h40l29,29v40l-29,29h-40l-29-29v-40z" stroke="#000" fill="none"/>
<path d="M31,3h38l28,28v38l-28,28h-38l-28-28v-38z" fill="#a23"/>
<text x="50" y="68" font-size="48" fill="#FFF" text-anchor="middle"><![CDATA[410]]></text>
</svg>

After

Width:  |  Height:  |  Size: 313 B