[後台] 修改系統類別管理

This commit is contained in:
dev02 2022-10-20 17:25:47 +08:00
parent d4f0add911
commit da19a2becc
8 changed files with 241 additions and 212 deletions

View File

@ -805,7 +805,7 @@ namespace Backend.Controllers
try try
{ {
var rawDatas = await backendRepository.GetAllAsync<DeviceImportCheckTempRawData>("import_niagara_tag", null, null, "device_building_tag, device_system_tag, device_floor_tag, device_name_tag"); var rawDatas = await backendRepository.GetAllAsync<DeviceImportCheckTempRawData>("import_niagara_tag", "ORDER BY device_building_tag, device_system_tag, device_floor_tag, device_name_tag");
var rawDatas_Group_Building_tag = rawDatas.GroupBy(x => x.Device_building_tag).ToList(); var rawDatas_Group_Building_tag = rawDatas.GroupBy(x => x.Device_building_tag).ToList();
List<DeviceImportCheckTempFilter> tempFilters = new List<DeviceImportCheckTempFilter>(); List<DeviceImportCheckTempFilter> tempFilters = new List<DeviceImportCheckTempFilter>();
@ -877,7 +877,8 @@ namespace Backend.Controllers
di.device_floor_tag, di.device_floor_tag,
di.device_last_name_tag as device_name_tag, di.device_last_name_tag as device_name_tag,
di.device_serial_tag, di.device_serial_tag,
0 as device_disaster, 0 as Device_disasters,
0 as Device_disaster_type_text,
di.niagara_tags as device_number di.niagara_tags as device_number
FROM FROM
( (

View File

@ -13,6 +13,8 @@ namespace Backend.Controllers
{ {
private readonly IBackendRepository backendRepository; private readonly IBackendRepository backendRepository;
private string main_system_name = "device_system_category_layer2";
private string sub_system_name = "device_system_category_layer1";
public SystemCategoryController(IBackendRepository backendRepository) public SystemCategoryController(IBackendRepository backendRepository)
{ {
@ -29,15 +31,17 @@ namespace Backend.Controllers
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
[HttpPost] [HttpPost]
public async Task<ApiResult<List<SystemMain>>> SystemMainList() public async Task<ApiResult<List<VariableInfo>>> SystemMainList()
{ {
ApiResult<List<SystemMain>> apiResult = new ApiResult<List<SystemMain>>(); ApiResult<List<VariableInfo>> apiResult = new ApiResult<List<VariableInfo>>();
try try
{ {
var sWhere = "deleted = 0"; var sWhere = "deleted = 0 AND system_type = @System_type";
var systemMainList = await backendRepository.GetAllAsync<SystemMain>("main_system", sWhere, null, "priority ASC, created_at DESC"); var param = new { System_type = main_system_name };
var systemMainList = await backendRepository.GetAllAsync<VariableInfo>("variable", sWhere, param, "system_priority ASC, created_at DESC");
apiResult.Code = "0000"; apiResult.Code = "0000";
apiResult.Data = systemMainList; apiResult.Data = systemMainList;
@ -57,17 +61,17 @@ namespace Backend.Controllers
/// <param name="guid"></param> /// <param name="guid"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost] [HttpPost]
public async Task<ApiResult<SystemMain>> GetOneSystemMain(string guid) public async Task<ApiResult<VariableInfo>> GetOneSystemMain(int id)
{ {
ApiResult<SystemMain> apiResult = new ApiResult<SystemMain>(); ApiResult<VariableInfo> apiResult = new ApiResult<VariableInfo>();
try try
{ {
string sWhere = @$"deleted = @Deleted AND main_system_guid = @Guid"; string sWhere = @$"deleted = @Deleted AND id = @id";
object param = new { Deleted = 0, Guid = guid }; object param = new { Deleted = 0, id = id};
var systemMain = await backendRepository.GetOneAsync<SystemMain>("main_system", sWhere, param); var systemMain = await backendRepository.GetOneAsync<VariableInfo>("variable", sWhere, param);
apiResult.Code = "0000"; apiResult.Code = "0000";
apiResult.Data = systemMain; apiResult.Data = systemMain;
@ -87,81 +91,66 @@ namespace Backend.Controllers
/// <param name="post"></param> /// <param name="post"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost] [HttpPost]
public async Task<ApiResult<string>> SaveSystemMain(SystemMain post) public async Task<ApiResult<string>> SaveSystemMain(VariableInfo post)
{ {
ApiResult<string> apiResult = new ApiResult<string>(); ApiResult<string> apiResult = new ApiResult<string>();
try try
{ {
string sWhere = @$"deleted = @Deleted AND main_system_guid = @Guid"; string sWhere = @$"deleted = @Deleted AND id = @id";
object param = new { Deleted = 0, Guid = post.Main_system_guid }; object param = new { Deleted = 0, id = post.id };
var systemMain = await backendRepository.GetOneAsync<SystemMain>("main_system", sWhere, param); var systemMain = await backendRepository.GetOneAsync<VariableInfo>("variable", sWhere, param);
if (systemMain == null) if (systemMain == null)
{ {
//新增 //新增
//產生一組GUID //獲取最新的大類
var guid = Guid.NewGuid(); //系統大類GUID sWhere = @$"deleted = @Deleted AND system_type = @System_type";
param = new { Deleted = 0, System_type = main_system_name };
var sOrder = @"id DESC LIMIT 1";
var latestVariable = await backendRepository.GetOneAsync<VariableInfo>("variable", sWhere, param, sOrder);
Dictionary<string, object> systemMainDic = new Dictionary<string, object>() Dictionary<string, object> variableMainDic = new Dictionary<string, object>()
{ {
{ "@main_system_guid", guid}, { "@system_type", main_system_name},
{ "@full_name", post.Full_name}, { "@system_key", post.System_key},
{ "@code", post.Code}, { "@system_value", post.system_value},
{ "@created_by", myUserInfo.Userinfo_guid} { "@system_remark", "系統類別(第2層)"},
{ "@system_priority", latestVariable.system_priority + 1},
{ "@created_by", myUserInfo.Userinfo_guid},
{ "@created_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}
}; };
await backendRepository.AddOneByCustomTable(systemMainDic, "main_system"); await backendRepository.AddOneByCustomTable(variableMainDic, "variable");
apiResult.Code = "0000"; apiResult.Code = "0000";
apiResult.Msg = "新增成功"; apiResult.Msg = "新增成功";
} }
else else
{ {
Dictionary<string, object> systemMainDic = new Dictionary<string, object>() Dictionary<string, object> variableMainDic = new Dictionary<string, object>()
{ {
{ "@full_name", post.Full_name}, { "@system_key", post.System_key},
{ "@code", post.Code}, { "@system_value", post.system_value},
{ "@updated_by", myUserInfo.Userinfo_guid}, { "@updated_by", myUserInfo.Userinfo_guid},
{ "@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}, { "@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")},
}; };
await backendRepository.UpdateOneByCustomTable(systemMainDic, "main_system", "main_system_guid='" + systemMain.Main_system_guid + "'"); await backendRepository.UpdateOneByCustomTable(variableMainDic, "variable", "id='" + systemMain.id + "' AND deleted = 0");
var AuthCodes = await backendRepository.GetAllAsync<string>( var AuthCodes = await backendRepository.GetAllAsync<string>(
@$"select AuthCode from auth_page ap @$"select AuthCode
join sub_system ss on ss.sub_system_guid = ap.ShowView from auth_page ap
join main_system ms on ms.main_system_guid = ss.main_system_guid join variable sv on ap.ShowView = sv.system_value and sv.system_type = 'device_system_category_layer1'
where ms.main_system_guid = '{systemMain.Main_system_guid}'"); where sv.id = '{systemMain.id}'");
if(AuthCodes.Count > 0) if(AuthCodes.Count > 0)
{ {
await backendRepository.ExecuteSql($@"UPDATE auth_page await backendRepository.ExecuteSql($@"UPDATE auth_page
SET MainName = '{post.Full_name}' SET MainName = '{post.System_key}'
WHERE AuthCode IN @authCode;",new { authCode = AuthCodes }); WHERE AuthCode IN @authCode;",new { authCode = AuthCodes });
} }
#region
var auth_Pages = await backendRepository.GetAllAsync<Auth_page>("auth_page", "");
List<Dictionary<string, object>> authPagesDics = new List<Dictionary<string, object>>();
foreach (var auth_page in auth_Pages)
{
Dictionary<string, object> authPagesDic = new Dictionary<string, object>()
{
{ "@AuthCode", auth_page.AuthCode},
{ "@AuthType", auth_page.AuthType},
{ "@MainName", auth_page.MainName},
{ "@SubName", auth_page.SubName},
{ "@building_guid", auth_page.building_guid},
{ "@ShowView", auth_page.ShowView},
{ "@created_at", auth_page.created_at},
};
authPagesDics.Add(authPagesDic);
}
await backendRepository.ManualInsertBackgroundServiceTask("", "", "auth_page", "purge_all_insert", authPagesDics);
#endregion
apiResult.Code = "0000"; apiResult.Code = "0000";
apiResult.Msg = "修改成功"; apiResult.Msg = "修改成功";
@ -185,17 +174,17 @@ namespace Backend.Controllers
/// <param name="guid"></param> /// <param name="guid"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost] [HttpPost]
public async Task<ApiResult<string>> DeleteOneSystemMain(string guid) public async Task<ApiResult<string>> DeleteOneSystemMain(int id)
{ {
ApiResult<string> apiResult = new ApiResult<string>(); ApiResult<string> apiResult = new ApiResult<string>();
try try
{ {
string sWhere = @$"deleted = @Deleted AND main_system_guid = @Guid"; string sWhere = @$"deleted = @Deleted AND id = @id";
object param = new { Deleted = 0, Guid = guid }; object param = new { Deleted = 0, id = id };
var systemMain = await backendRepository.GetOneAsync<SystemMain>("main_system", sWhere, param); var systemMain = await backendRepository.GetOneAsync<VariableInfo>("variable", sWhere, param);
if (systemMain == null) if (systemMain == null)
{ {
@ -208,11 +197,11 @@ namespace Backend.Controllers
var sbuildMenu = $@"SELECT var sbuildMenu = $@"SELECT
b.full_name b.full_name
FROM building_menu bm FROM building_menu bm
LEFT JOIN building b ON bm.building_guid = b.building_guid AND b.deleted = 0 LEFT JOIN building b ON bm.building_tag = b.building_tag AND b.deleted = 0
WHERE bm.main_system_guid = @Guid WHERE bm.main_system_tag = @System_Value
GROUP BY b.full_name"; GROUP BY b.full_name";
var buildMenus = await backendRepository.GetAllAsync<string>(sbuildMenu, new { Guid = guid }); var buildMenus = await backendRepository.GetAllAsync<string>(sbuildMenu, new { System_Value = systemMain.system_value });
if (buildMenus.Count > 0) if (buildMenus.Count > 0)
{ {
apiResult.Code = "9997"; apiResult.Code = "9997";
@ -222,19 +211,20 @@ namespace Backend.Controllers
} }
//檢查底下是否有未刪除的系統小類 //檢查底下是否有未刪除的系統小類
string sSubWhere = @$"deleted = @Deleted AND main_system_guid = @Guid"; string sqlSub = @$"SELECT id FROM variable
object sub_param = new { Deleted = 0, Guid = systemMain.Main_system_guid }; WHERE deleted = @Deleted AND system_parent_id = @id";
var systemSubs = await backendRepository.GetAllAsync<SystemSub>("sub_system", sWhere, param); object sub_param = new { Deleted = 0, id = id };
var v = await backendRepository.GetAllAsync<VariableInfo>(sqlSub, sub_param);
if (systemSubs.Count > 0) if (v.Count > 0)
{ {
apiResult.Code = "9997"; apiResult.Code = "9997";
apiResult.Msg = "系統小類中尚有小類正在使用系統大類,故無法刪除"; apiResult.Msg = "系統小類中尚有小類正在使用系統大類,故無法刪除";
apiResult.Data = string.Join("<br>", systemSubs.Select(x => x.Full_name).ToList()); apiResult.Data = string.Join("<br>", v.Where(x => x.id == id).Select(x => x.System_key).ToList());
return apiResult; return apiResult;
} }
await backendRepository.DeleteOne(guid, "main_system", "main_system_guid"); await backendRepository.DeleteOne(id.ToString(), "variable", "id");
apiResult.Code = "0000"; apiResult.Code = "0000";
apiResult.Msg = "刪除成功"; apiResult.Msg = "刪除成功";
@ -243,7 +233,7 @@ namespace Backend.Controllers
{ {
apiResult.Code = "9999"; apiResult.Code = "9999";
apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
Logger.LogError("【" + controllerName + "/" + actionName + "】" + "main_system_guid=" + guid); Logger.LogError("【" + controllerName + "/" + actionName + "】" + "id=" + id);
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
} }
@ -256,18 +246,17 @@ namespace Backend.Controllers
/// <param name="main_system_guid"></param> /// <param name="main_system_guid"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost] [HttpPost]
public async Task<ApiResult<List<SystemSub>>> SystemSubList(string main_system_guid) public async Task<ApiResult<List<VariableInfo>>> SystemSubList(int id)
{ {
ApiResult<List<SystemSub>> apiResult = new ApiResult<List<SystemSub>>(); ApiResult<List<VariableInfo>> apiResult = new ApiResult<List<VariableInfo>>();
try try
{ {
var sWhere = @"deleted = @Deleted AND system_parent_id = @id";
var sWhere = @"deleted = @Deleted AND main_system_guid = @Main_system_guid"; object param = new { Deleted = 0, id = id};
object param = new { Deleted = 0, Main_system_guid = main_system_guid }; var systemSubs = await backendRepository.GetAllAsync<VariableInfo>("variable", sWhere, param, "system_priority ASC, created_at DESC");
var systemSubs = await backendRepository.GetAllAsync<SystemSub>("sub_system", sWhere, param, "priority ASC, created_at DESC");
apiResult.Code = "0000"; apiResult.Code = "0000";
apiResult.Data = systemSubs; apiResult.Data = systemSubs;
@ -287,17 +276,17 @@ namespace Backend.Controllers
/// <param name="guid"></param> /// <param name="guid"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost] [HttpPost]
public async Task<ApiResult<SystemSub>> GetOneSystemSub(string guid) public async Task<ApiResult<VariableInfo>> GetOneSystemSub(int id)
{ {
ApiResult<SystemSub> apiResult = new ApiResult<SystemSub>(); ApiResult<VariableInfo> apiResult = new ApiResult<VariableInfo>();
try try
{ {
string sWhere = @$"deleted = @Deleted AND sub_system_guid = @Guid"; string sWhere = @$"deleted = @Deleted AND id = @id";
object param = new { Deleted = 0, Guid = guid }; object param = new { Deleted = 0, id = id };
var systemSub = await backendRepository.GetOneAsync<SystemSub>("sub_system", sWhere, param); var systemSub = await backendRepository.GetOneAsync<VariableInfo>("variable", sWhere, param);
apiResult.Code = "0000"; apiResult.Code = "0000";
apiResult.Data = systemSub; apiResult.Data = systemSub;
@ -317,32 +306,40 @@ namespace Backend.Controllers
/// <param name="post"></param> /// <param name="post"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost] [HttpPost]
public async Task<ApiResult<string>> SaveSystemSub(SystemSub post) public async Task<ApiResult<string>> SaveSystemSub(VariableInfo post)
{ {
ApiResult<string> apiResult = new ApiResult<string>(); ApiResult<string> apiResult = new ApiResult<string>();
try try
{ {
string sWhere = @$"deleted = @Deleted AND sub_system_guid = @Guid"; string sWhere = @$"deleted = @Deleted AND id = @id";
object param = new { Deleted = 0, Guid = post.Sub_system_guid }; object param = new { Deleted = 0, id = post.id };
var systemSub = await backendRepository.GetOneAsync<SystemSub>("sub_system", sWhere, param); var systemSub = await backendRepository.GetOneAsync<VariableInfo>("variable", sWhere, param);
if (systemSub == null) if (systemSub == null)
{ {
//新增 //新增
//產生一組GUID //產生一組GUID
var guid = Guid.NewGuid(); //GUID //獲取最新的大類
sWhere = @$"deleted = @Deleted AND system_type = @System_type";
param = new { Deleted = 0, System_type = sub_system_name };
var sOrder = @"id DESC LIMIT 1";
var latestVariable = await backendRepository.GetOneAsync<VariableInfo>("variable", sWhere, param, sOrder);
Dictionary<string, object> systemSubDic = new Dictionary<string, object>() Dictionary<string, object> systemSubDic = new Dictionary<string, object>()
{ {
{ "@sub_system_guid", guid}, { "@system_type", sub_system_name},
{ "@main_system_guid", post.Main_system_guid}, { "@system_key", post.System_key},
{ "@full_name", post.Full_name}, { "@system_value", post.system_value},
{ "@created_by", myUserInfo.Userinfo_guid} { "@system_parent_id", post.system_parent_id},
{ "@system_remark", "系統類別(第1層)"},
{ "@system_priority", latestVariable.system_priority + 1},
{ "@created_by", myUserInfo.Userinfo_guid},
{ "@created_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}
}; };
await backendRepository.AddOneByCustomTable(systemSubDic, "sub_system"); await backendRepository.AddOneByCustomTable(systemSubDic, "variable");
apiResult.Code = "0000"; apiResult.Code = "0000";
apiResult.Msg = "新增成功"; apiResult.Msg = "新增成功";
@ -351,45 +348,26 @@ namespace Backend.Controllers
{ {
Dictionary<string, object> systemSubDic = new Dictionary<string, object>() Dictionary<string, object> systemSubDic = new Dictionary<string, object>()
{ {
{ "@full_name", post.Full_name},
{ "@system_key", post.System_key},
{ "@system_value", post.system_value},
{ "@updated_by", myUserInfo.Userinfo_guid}, { "@updated_by", myUserInfo.Userinfo_guid},
{ "@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}, { "@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")},
}; };
await backendRepository.UpdateOneByCustomTable(systemSubDic, "sub_system", "sub_system_guid='" + systemSub.Sub_system_guid + "'"); await backendRepository.UpdateOneByCustomTable(systemSubDic, "variable", "id='" + systemSub.id + "'");
var AuthCodes = await backendRepository.GetAllAsync<string>( var AuthCodes = await backendRepository.GetAllAsync<string>(
@$"select AuthCode from auth_page ap @$"select AuthCode from auth_page ap
where ap.ShowView = '{systemSub.Sub_system_guid}'"); where ap.ShowView = '{systemSub.id}'");
if (AuthCodes.Count > 0) if (AuthCodes.Count > 0)
{ {
await backendRepository.ExecuteSql($@"UPDATE auth_page await backendRepository.ExecuteSql($@"UPDATE auth_page
SET SubName = '{post.Full_name}' SET SubName = '{post.System_key}'
WHERE AuthCode IN @authCode;", new { authCode = AuthCodes }); WHERE AuthCode IN @authCode;", new { authCode = AuthCodes });
} }
#region
var auth_Pages = await backendRepository.GetAllAsync<Auth_page>("auth_page", "");
List<Dictionary<string, object>> authPagesDics = new List<Dictionary<string, object>>();
foreach (var auth_page in auth_Pages)
{
Dictionary<string, object> authPagesDic = new Dictionary<string, object>()
{
{ "@AuthCode", auth_page.AuthCode},
{ "@AuthType", auth_page.AuthType},
{ "@MainName", auth_page.MainName},
{ "@SubName", auth_page.SubName},
{ "@building_guid", auth_page.building_guid},
{ "@ShowView", auth_page.ShowView},
{ "@created_at", auth_page.created_at},
};
authPagesDics.Add(authPagesDic);
}
await backendRepository.ManualInsertBackgroundServiceTask("", "", "auth_page", "purge_all_insert", authPagesDics);
#endregion
apiResult.Code = "0000"; apiResult.Code = "0000";
apiResult.Msg = "修改成功"; apiResult.Msg = "修改成功";
} }
@ -412,17 +390,17 @@ namespace Backend.Controllers
/// <param name="guid"></param> /// <param name="guid"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost] [HttpPost]
public async Task<ApiResult<string>> DeleteOneSystemSub(string guid) public async Task<ApiResult<string>> DeleteOneSystemSub(string id)
{ {
ApiResult<string> apiResult = new ApiResult<string>(); ApiResult<string> apiResult = new ApiResult<string>();
try try
{ {
string sWhere = @$"deleted = @Deleted AND sub_system_guid = @Guid"; string sWhere = @$"deleted = @Deleted AND id = @id";
object param = new { Deleted = 0, Guid = guid }; object param = new { Deleted = 0, id = id };
var systemSub = await backendRepository.GetOneAsync<SystemSub>("sub_system", sWhere, param); var systemSub = await backendRepository.GetOneAsync<VariableInfo>("variable", sWhere, param);
if (systemSub == null) if (systemSub == null)
{ {
@ -433,13 +411,14 @@ namespace Backend.Controllers
//檢查是否有未刪除的區域選單 //檢查是否有未刪除的區域選單
var sbuildMenu = $@"SELECT var sbuildMenu = $@"SELECT
CONCAT(b.full_name, ' - ', ms.full_name) CONCAT(b.full_name, ' - ', v2.system_key)
FROM building_menu bm FROM building_menu bm
LEFT JOIN building b ON bm.building_guid = b.building_guid AND b.deleted = 0 LEFT JOIN building b ON bm.building_tag = b.building_tag AND b.deleted = 0
LEFT JOIN main_system ms ON bm.main_system_guid = ms.main_system_guid AND ms.deleted = 0 LEFT JOIN variable v1 ON bm.sub_system_tag = v1.system_value AND v1.deleted = 0
WHERE bm.sub_system_guid = @Guid"; LEFT JOIN variable v2 ON v1.system_parent_id = v2.id AND v1.deleted = 0
WHERE v1.id = @id";
var buildMenus = await backendRepository.GetAllAsync<string>(sbuildMenu, new { Guid = guid }); var buildMenus = await backendRepository.GetAllAsync<string>(sbuildMenu, new { id = id });
if (buildMenus.Count > 0) if (buildMenus.Count > 0)
{ {
apiResult.Code = "9997"; apiResult.Code = "9997";
@ -450,16 +429,15 @@ namespace Backend.Controllers
//檢查是否有未刪除的系統小類樓層 //檢查是否有未刪除的系統小類樓層
var ssubSystemFloor = $@"SELECT var ssubSystemFloor = $@"SELECT
CONCAT(b.full_name, ' - ', ms.full_name, ' - ', ss.full_name, ' - ', f.full_name) CONCAT(b.full_name, ' - ', v1.full_name, ' - ', v2.full_name, ' - ', f.full_name)
FROM sub_system_floor ssf FROM sub_system_floor ssf
LEFT JOIN building b ON ssf.building_guid = b.building_guid AND b.deleted = 0 LEFT JOIN building b ON ssf.building_tag = b.building_tag AND b.deleted = 0
LEFT JOIN main_system ms ON ssf.main_system_guid = ms.main_system_guid AND ms.deleted = 0 LEFT JOIN variable v2 ON v2.system_value = ssf.sub_system_tag AND v2.deleted = 0
LEFT JOIN sub_system ss ON ssf.sub_system_guid = ss.sub_system_guid AND ss.deleted = 0 LEFT JOIN variable v1 ON v1.system_parent_id = v1.id AND v1.deleted = 0
LEFT JOIN floor f ON ssf.floor_guid = f.floor_guid AND f.deleted = 0 LEFT JOIN floor f ON ssf.floor_guid = f.floor_guid AND f.deleted = 0
WHERE ssf.sub_system_guid = @Guid WHERE v2.id = @id AND ssf.deleted = 0";
AND ssf.deleted = 0";
var subSystemFloor = await backendRepository.GetAllAsync<string>(sbuildMenu, new { Guid = guid }); var subSystemFloor = await backendRepository.GetAllAsync<string>(sbuildMenu, new { id = id });
if (subSystemFloor.Count > 0) if (subSystemFloor.Count > 0)
{ {
apiResult.Code = "9997"; apiResult.Code = "9997";
@ -470,12 +448,12 @@ namespace Backend.Controllers
//檢查是否有未刪除的設備項目 //檢查是否有未刪除的設備項目
var sdeviceItem = $@"SELECT var sdeviceItem = $@"SELECT
di.full_name di.full_name
FROM device_item di FROM device_item di
WHERE di.deleted = 0 INNER JOIN variable v on di.device_name_tag = v.system_value
AND di.sub_system_guid = @Guid"; WHERE v.deleted = 0 AND v.id = @id AND di.deleted = 0";
var deviceItems = await backendRepository.GetAllAsync<string>(sdeviceItem, new { Guid = guid }); var deviceItems = await backendRepository.GetAllAsync<string>(sdeviceItem, new { id = id });
if (deviceItems.Count > 0) if (deviceItems.Count > 0)
{ {
apiResult.Code = "9997"; apiResult.Code = "9997";
@ -484,7 +462,7 @@ namespace Backend.Controllers
return apiResult; return apiResult;
} }
await backendRepository.DeleteOne(guid, "sub_system", "sub_system_guid"); await backendRepository.DeleteOne(id, "variable", "id");
apiResult.Code = "0000"; apiResult.Code = "0000";
apiResult.Msg = "刪除成功"; apiResult.Msg = "刪除成功";
@ -493,7 +471,7 @@ namespace Backend.Controllers
{ {
apiResult.Code = "9999"; apiResult.Code = "9999";
apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
Logger.LogError("【" + controllerName + "/" + actionName + "】" + "sub_system_guid=" + guid); Logger.LogError("【" + controllerName + "/" + actionName + "】" + "id=" + id);
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
} }
@ -510,10 +488,10 @@ namespace Backend.Controllers
//檢查是否有未刪除的區域選單 //檢查是否有未刪除的區域選單
if(device_Item.is_show_riserDiagram == 1) if(device_Item.is_show_riserDiagram == 1)
{ {
var sql_show_riserDiagram = $@"SELECT * FROM device_item di var sql_show_riserDiagram = $@"SELECT * FROM device_item di
WHERE di.sub_system_guid = @SubSystemGuid AND di.deleted = 0 AND is_show_riserDiagram = 1"; WHERE di.id = @id AND di.deleted = 0 AND is_show_riserDiagram = 1";
var is_show_riserDiagram = await backendRepository.GetAllAsync<string>(sql_show_riserDiagram, new { SubSystemGuid = device_Item.sub_system_guid }); var is_show_riserDiagram = await backendRepository.GetAllAsync<string>(sql_show_riserDiagram, new { id = device_Item.id });
if (is_show_riserDiagram.Count() > 0) if (is_show_riserDiagram.Count() > 0)
{ {
@ -523,16 +501,15 @@ namespace Backend.Controllers
} }
} }
if (device_Item.device_item_guid == null) if (device_Item.id == 0)
{ {
var main_tag = await backendRepository.GetOneAsync<string>($@"SELECT system_value FROM variable WHERE id = @id", new { id = device_Item.device_system_tag });
var sub_tag = await backendRepository.GetOneAsync<string>($@"SELECT system_value FROM variable WHERE id = @id", new { id = device_Item.device_name_tag });
//新增 //新增
//產生一組GUID
var guid = Guid.NewGuid(); //GUID
Dictionary<string, object> Device_itemDic = new Dictionary<string, object>() Dictionary<string, object> Device_itemDic = new Dictionary<string, object>()
{ {
{ "@device_item_guid", guid}, { "@device_system_tag", main_tag},
{ "@sub_system_guid", device_Item.sub_system_guid}, { "@device_name_tag", sub_tag},
{ "@full_name", device_Item.full_name}, { "@full_name", device_Item.full_name},
{ "@points", device_Item.points}, { "@points", device_Item.points},
{ "@unit", device_Item.unit}, { "@unit", device_Item.unit},
@ -540,6 +517,7 @@ namespace Backend.Controllers
{ "@is_show_riserDiagram", device_Item.is_show_riserDiagram}, { "@is_show_riserDiagram", device_Item.is_show_riserDiagram},
{ "@is_controll", device_Item.is_controll}, { "@is_controll", device_Item.is_controll},
{ "@is_bool", device_Item.is_bool}, { "@is_bool", device_Item.is_bool},
{ "@is_link", device_Item.is_link},
{ "@created_by", myUserInfo.Userinfo_guid}, { "@created_by", myUserInfo.Userinfo_guid},
}; };
await backendRepository.AddOneByCustomTable(Device_itemDic, "device_item"); await backendRepository.AddOneByCustomTable(Device_itemDic, "device_item");
@ -551,7 +529,6 @@ namespace Backend.Controllers
{ {
Dictionary<string, object> Device_itemDic = new Dictionary<string, object>() Dictionary<string, object> Device_itemDic = new Dictionary<string, object>()
{ {
{ "@sub_system_guid", device_Item.sub_system_guid},
{ "@full_name", device_Item.full_name}, { "@full_name", device_Item.full_name},
{ "@points", device_Item.points}, { "@points", device_Item.points},
{ "@unit", device_Item.unit}, { "@unit", device_Item.unit},
@ -559,11 +536,12 @@ namespace Backend.Controllers
{ "@is_show_riserDiagram", device_Item.is_show_riserDiagram}, { "@is_show_riserDiagram", device_Item.is_show_riserDiagram},
{ "@is_controll", device_Item.is_controll}, { "@is_controll", device_Item.is_controll},
{ "@is_bool", device_Item.is_bool}, { "@is_bool", device_Item.is_bool},
{ "@is_link", device_Item.is_link},
{ "@updated_by", myUserInfo.Userinfo_guid}, { "@updated_by", myUserInfo.Userinfo_guid},
{ "@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}, { "@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")},
}; };
await backendRepository.UpdateOneByCustomTable(Device_itemDic, "device_item", "device_item_guid='" + device_Item.device_item_guid + "'"); await backendRepository.UpdateOneByCustomTable(Device_itemDic, "device_item", "id='" + device_Item.id + "'");
apiResult.Code = "0000"; apiResult.Code = "0000";
apiResult.Msg = "修改成功"; apiResult.Msg = "修改成功";
@ -582,17 +560,21 @@ namespace Backend.Controllers
} }
[HttpPost] [HttpPost]
public async Task<ApiResult<List<Device_item>>> DeviceItemTable(string sub_system_guid) public async Task<ApiResult<List<Device_item>>> DeviceItemTable(int id)
{ {
ApiResult<List<Device_item>> apiResult = new ApiResult<List<Device_item>>(); ApiResult<List<Device_item>> apiResult = new ApiResult<List<Device_item>>();
try try
{ {
var sWhere = @"deleted = @Deleted AND sub_system_guid = @Sub_system_guid"; var sql = @"SELECT di.*
FROM device_item di
JOIN variable v1 ON di.device_name_tag = v1.system_value
JOIN variable v2 ON v1.system_parent_id = v2.id AND di.device_system_tag = v2.system_value
WHERE v1.id = @id AND di.deleted = @Deleted";
object param = new { Deleted = 0, Sub_system_guid = sub_system_guid }; object param = new { Deleted = 0, id = id };
var systemSubs = await backendRepository.GetAllAsync<Device_item>("device_item", sWhere, param, "created_at DESC"); var systemSubs = await backendRepository.GetAllAsync<Device_item>(sql, param);
apiResult.Code = "0000"; apiResult.Code = "0000";
apiResult.Data = systemSubs; apiResult.Data = systemSubs;
@ -607,15 +589,15 @@ namespace Backend.Controllers
} }
[HttpPost] [HttpPost]
public async Task<ApiResult<Device_item>> GetOneDeviceItem(string guid) public async Task<ApiResult<Device_item>> GetOneDeviceItem(int id)
{ {
ApiResult<Device_item> apiResult = new ApiResult<Device_item>(); ApiResult<Device_item> apiResult = new ApiResult<Device_item>();
try try
{ {
string sWhere = @$"deleted = @Deleted AND device_item_guid = @Guid"; string sWhere = @$"deleted = @Deleted AND id = @id";
object param = new { Deleted = 0, Guid = guid }; object param = new { Deleted = 0, id = id };
var Deviceitem = await backendRepository.GetOneAsync<Device_item>("device_item", sWhere, param); var Deviceitem = await backendRepository.GetOneAsync<Device_item>("device_item", sWhere, param);
@ -632,15 +614,15 @@ namespace Backend.Controllers
} }
[HttpPost] [HttpPost]
public async Task<ApiResult<string>> DeleteOneSystemSubDeviceItem(string guid) public async Task<ApiResult<string>> DeleteOneSystemSubDeviceItem(int id)
{ {
ApiResult<string> apiResult = new ApiResult<string>(); ApiResult<string> apiResult = new ApiResult<string>();
try try
{ {
string sWhere = @$"deleted = @Deleted AND device_item_guid = @Guid"; string sWhere = @$"deleted = @Deleted AND id = @id";
object param = new { Deleted = 0, Guid = guid }; object param = new { Deleted = 0, id = id};
var device_Item = await backendRepository.GetOneAsync<Device_item>("device_item", sWhere, param); var device_Item = await backendRepository.GetOneAsync<Device_item>("device_item", sWhere, param);
@ -651,7 +633,7 @@ namespace Backend.Controllers
return apiResult; return apiResult;
} }
await backendRepository.DeleteOne(guid, "device_item", "device_item_guid"); await backendRepository.DeleteOne(id.ToString(), "device_item", "id");
apiResult.Code = "0000"; apiResult.Code = "0000";
apiResult.Msg = "刪除成功"; apiResult.Msg = "刪除成功";
@ -660,7 +642,7 @@ namespace Backend.Controllers
{ {
apiResult.Code = "9999"; apiResult.Code = "9999";
apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
Logger.LogError("【" + controllerName + "/" + actionName + "】" + "device_item_guid=" + guid); Logger.LogError("【" + controllerName + "/" + actionName + "】" + "id=" + id);
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
} }
@ -672,7 +654,13 @@ namespace Backend.Controllers
ApiResult<bool> apiResult = new ApiResult<bool>(); ApiResult<bool> apiResult = new ApiResult<bool>();
try try
{ {
var point = await backendRepository.GetOneAsync<Device_item>("device_item", $" sub_system_guid = '{post.sub_system_guid}' and points = '{post.points}' and device_item_guid != '{post.device_item_guid}' and deleted = 0"); var sql = $@"SELECT *
FROM device_item di
INNER JOIN variable v ON di.device_name_tag = v.system_value
WHERE v.id = @SubId AND di.id != @Id AND points = @Points";
var param = new { SubId = post.subId, Points = post.points, id = post.id };
var point = await backendRepository.GetOneAsync<Device_item>(sql, param);
if (point != null) if (point != null)
{ {
apiResult.Data = true; apiResult.Data = true;
@ -700,9 +688,9 @@ namespace Backend.Controllers
try try
{ {
var tags = await backendRepository.GetAllAsync<Tags>( var tags = await backendRepository.GetAllAsync<Tags>(
@$"select * from (select dk.device_building_tag ,dk.device_name_tag,dk.device_system_tag from device_kind dk where dk.device_normal_point_guid = '{post.guid}') dkn @$"select * from (select dk.device_building_tag ,dk.device_name_tag,dk.device_system_tag from device_kind dk where dk.device_normal_point_id = @id) dkn
union(select dk.device_building_tag, dk.device_name_tag, dk.device_system_tag from device_kind dk where dk.device_close_point_guid = '{post.guid}') union(select dk.device_building_tag, dk.device_name_tag, dk.device_system_tag from device_kind dk where dk.device_close_point_id = @id)
union(select dk.device_building_tag, dk.device_name_tag, dk.device_system_tag from device_kind dk where dk.device_error_point_guid = '{post.guid}')"); union(select dk.device_building_tag, dk.device_name_tag, dk.device_system_tag from device_kind dk where dk.device_error_point_id = @id)", new { id = post.guid});
if (tags.Count == 0) if (tags.Count == 0)
{ {
@ -722,20 +710,24 @@ namespace Backend.Controllers
}; };
var unionsql = ""; var unionsql = "";
var last = tags.Last(); var last = tags.Last();
var sub_system = await backendRepository.GetOneAsync<VariableInfo>($@"SELECT * FROM variable WHERE id = @id", new { id = post.subguid });
foreach (var tag in tags) foreach (var tag in tags)
{ {
unionsql += $@"select d.building_guid,d.main_system_guid,d.sub_system_guid,d.device_name_tag from device d where d.sub_system_guid = '{post.subguid}' and d.device_building_tag = '{tag.device_building_tag}' and d.device_system_tag = '{tag.device_system_tag}' and d.device_name_tag = '{tag.device_name_tag}' group by d.building_guid,d.main_system_guid,d.sub_system_guid,d.device_name_tag"; unionsql += $@"select d.building_tag,d.device_system_tag,d.device_name_tag,d.device_last_name from device d where d.device_name_tag = '{sub_system.system_value}'
and d.device_building_tag = '{tag.device_building_tag}' and d.device_system_tag = '{tag.device_system_tag}' and d.device_name_tag = '{tag.device_name_tag}' group by d.building_guid,d.main_system_guid,d.sub_system_guid,d.device_name_tag";
if (!last.Equals(tag)) if (!last.Equals(tag))
{ {
unionsql += " union "; unionsql += " union ";
} }
} }
var sql = @$"select ms.full_name msname,b.full_name bname,s.full_name subname,de.device_name_tag from var sql = @$"select v1.system_key msname, b.full_name bname, v2.system_key subname,de.device_last_name as device_name_tag from
({unionsql}) de ({unionsql}) de
left join main_system ms on ms.main_system_guid = de.main_system_guid left join variable v1 on v1.system_value = de.device_system_tag and v1.system_type = @main_system_type
left join building b on b.building_guid = de.building_guid left join building b on b.building_tag = de.building_tag
left join sub_system s on s.sub_system_guid = de.sub_system_guid"; left join variable v2 on v2.system_value = de.device_name_tag and v1.system_type = @sub_system_type";
var names = await backendRepository.GetAllAsync<GetCheckName>(sql);
var param = new { main_system_type = main_system_name, sub_system_type = sub_system_name};
var names = await backendRepository.GetAllAsync<GetCheckName>(sql, param);
var count = 0; var count = 0;
foreach (var name in names) foreach (var name in names)
{ {

View File

@ -9,6 +9,7 @@ namespace Backend.Models
public class BuildInfo : Actor public class BuildInfo : Actor
{ {
public int Priority { get; set; } public int Priority { get; set; }
public string building_tag { get; set; }
public string Building_guid { get; set; } //區域GUID public string Building_guid { get; set; } //區域GUID
public string Full_name { get; set; } //區域名稱 public string Full_name { get; set; } //區域名稱
public string Ip_address { get; set; } //監控主機 IP public string Ip_address { get; set; } //監控主機 IP

View File

@ -53,11 +53,12 @@ namespace Backend.Models
public string Logo { get; set; } public string Logo { get; set; }
} }
public class Variable public class Variable : Actor
{ {
public string System_type { get; set; } public string System_type { get; set; }
public string System_key { get; set; } public string System_key { get; set; }
public string system_value { get; set; } public string system_value { get; set; }
} }
public class VariableInfo : Variable public class VariableInfo : Variable

View File

@ -30,8 +30,12 @@ namespace Backend.Models
public class Device_item : Actor public class Device_item : Actor
{ {
public int id { get; set; }
public string device_item_guid { get; set; } public string device_item_guid { get; set; }
public string sub_system_guid { get; set; } public string device_area_tag { get; set; }
public string device_building_tag { get; set; }
public string device_system_tag { get; set; }
public string device_name_tag { get; set; }
public string full_name { get; set; } public string full_name { get; set; }
public string points { get; set; } public string points { get; set; }
public string unit { get; set; } public string unit { get; set; }
@ -39,13 +43,14 @@ namespace Backend.Models
public byte is_show_riserDiagram { get; set; } public byte is_show_riserDiagram { get; set; }
public byte is_controll { get; set; } public byte is_controll { get; set; }
public byte is_bool { get; set; } public byte is_bool { get; set; }
public byte is_link { get; set; }
} }
public class Checksame public class Checksame
{ {
public string sub_system_guid { get; set; } public int id { get; set; }
public string subId { get; set; }
public string points { get; set; } public string points { get; set; }
public string device_item_guid { get; set; }
} }
public class Tags public class Tags

View File

@ -55,7 +55,7 @@
}, },
"columns": [ "columns": [
{ {
"data": "building_guid", "data": "building_tag",
"render": function (data, type, row, meta) { "render": function (data, type, row, meta) {
return meta.row + 1; return meta.row + 1;
} }
@ -87,7 +87,7 @@
], ],
//"order": [[2, "desc"]], //"order": [[2, "desc"]],
'createdRow': function (row, data, dataIndex) { 'createdRow': function (row, data, dataIndex) {
$(row).attr('data-guid', data.building_guid); $(row).attr('data-guid', data.building_tag);
}, },
"ajax": { "ajax": {
"url": "/BuildInfo/BuildInfoList", "url": "/BuildInfo/BuildInfoList",
@ -107,13 +107,13 @@
//樓層設定上方選單 //樓層設定上方選單
$("#BuildList").empty(); $("#BuildList").empty();
$.each(data, function (key, value) { $.each(data, function (key, value) {
$("#BuildList").append(`<button type="button" class="btn btn-outline-success waves-effect waves-themed ml-2 mb-2 btn-station" id="${value.building_guid}" onclick="clickBuilding('${value.building_guid}')">${value.full_name}</button>`); $("#BuildList").append(`<button type="button" class="btn btn-outline-success waves-effect waves-themed ml-2 mb-2 btn-station" id="${value.building_tag}" onclick="clickBuilding('${value.building_tag}')">${value.full_name}</button>`);
@*if (key == 0) { @*if (key == 0) {
selected_build_guid_top_name = value.full_name; selected_build_guid_top_name = value.full_name;
$("#BuildList").append(`<button type="button" class="btn btn-success waves-effect waves-themed ml-2 mb-2 btn-station" id="${value.building_guid}" onclick="clickBuilding('${value.building_guid}')">${value.full_name}</button>`); $("#BuildList").append(`<button type="button" class="btn btn-success waves-effect waves-themed ml-2 mb-2 btn-station" id="${value.building_tag}" onclick="clickBuilding('${value.building_tag}')">${value.full_name}</button>`);
} }
else { else {
$("#BuildList").append(`<button type="button" class="btn btn-outline-success waves-effect waves-themed ml-2 mb-2 btn-station" id="${value.building_guid}" onclick="clickBuilding('${value.building_guid}')">${value.full_name}</button>`); $("#BuildList").append(`<button type="button" class="btn btn-outline-success waves-effect waves-themed ml-2 mb-2 btn-station" id="${value.building_tag}" onclick="clickBuilding('${value.building_tag}')">${value.full_name}</button>`);
}*@ }*@
}); });
@ -129,7 +129,7 @@
var rowData = buildInfoTable.row(diff[i].node).data(); var rowData = buildInfoTable.row(diff[i].node).data();
var obj = { var obj = {
building_guid: rowData.building_guid, building_tag: rowData.building_tag,
priority: diff[i].newData priority: diff[i].newData
} }
@ -253,7 +253,7 @@
$("#save-building-btn").html('<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>').attr("disabled", true); $("#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 url = "/BuildInfo/SaveBuildInfo";
var send_data = { var send_data = {
Building_guid: selected_build_guid, building_tag: selected_build_guid,
Full_name: $('#build_name_modal').val(), Full_name: $('#build_name_modal').val(),
Ip_address: $('#ip_address_modal').val(), Ip_address: $('#ip_address_modal').val(),
Ip_port: $('#ip_port_modal').val() Ip_port: $('#ip_port_modal').val()
@ -557,7 +557,7 @@
maps = $('#map_file_modal')[0].files maps = $('#map_file_modal')[0].files
formData.append("Floor_guid", selected_floor_guid); formData.append("Floor_guid", selected_floor_guid);
formData.append("Building_guid", selected_build_guid_top); formData.append("building_tag", selected_build_guid_top);
formData.append("Full_name", $('#floor_name_modal').val()); formData.append("Full_name", $('#floor_name_modal').val());
if (maps.length > 0) { if (maps.length > 0) {

View File

@ -53,10 +53,10 @@
} }
}, },
{ {
"data": "full_name" "data": "system_key"
}, },
{ {
"data": "code" "data": "system_value"
}, },
{ {
"data": "created_at" "data": "created_at"
@ -67,7 +67,7 @@
} }
], ],
'createdRow': function (row, data, dataIndex) { 'createdRow': function (row, data, dataIndex) {
$(row).attr('data-guid', data.main_system_guid); $(row).attr('data-guid', data.id);
}, },
//"order": [[2, "desc"]], //"order": [[2, "desc"]],
"ajax": { "ajax": {
@ -89,12 +89,12 @@
$("#system-main-list").empty(); $("#system-main-list").empty();
$.each(data, function (key, value) { $.each(data, function (key, value) {
if (key == 0) { if (key == 0) {
selected_system_main_guid_top_name = value.full_name; selected_system_main_guid_top_name = value.system_key;
$("#system-main-list").append(`<button type="button" class="btn btn-success waves-effect waves-themed ml-2 mb-2 btn-station" id="${value.main_system_guid}" onclick="clickSystemMain('${value.main_system_guid}')">${value.full_name}</button>`); $("#system-main-list").append(`<button type="button" class="btn btn-success waves-effect waves-themed ml-2 mb-2 btn-station" id="${value.id}" onclick="clickSystemMain('${value.id}')">${value.system_key}</button>`);
$(`#${value.main_system_guid}`).trigger("click"); $(`#${value.id}`).trigger("click");
} }
else { else {
$("#system-main-list").append(`<button type="button" class="btn btn-outline-success waves-effect waves-themed ml-2 mb-2 btn-station" id="${value.main_system_guid}" onclick="clickSystemMain('${value.main_system_guid}')">${value.full_name}</button>`); $("#system-main-list").append(`<button type="button" class="btn btn-outline-success waves-effect waves-themed ml-2 mb-2 btn-station" id="${value.id}" onclick="clickSystemMain('${value.id}')">${value.system_key}</button>`);
} }
}); });
@ -115,7 +115,7 @@
var url = "/SystemCategory/GetOneSystemMain"; var url = "/SystemCategory/GetOneSystemMain";
var send_data = { var send_data = {
guid: selected_system_main_guid id: selected_system_main_guid
} }
$.post(url, send_data, function (rel) { $.post(url, send_data, function (rel) {
@ -129,8 +129,8 @@
return; return;
} }
else { else {
$("#system_main_name_modal").val(rel.data.full_name); $("#system_main_name_modal").val(rel.data.system_key);
$("#system_main_code_modal").val(rel.data.code); $("#system_main_code_modal").val(rel.data.system_value);
$("#system-main-modal").modal(); $("#system-main-modal").modal();
} }
@ -157,7 +157,7 @@
if (result.value) { if (result.value) {
var url = "/SystemCategory/DeleteOneSystemMain"; var url = "/SystemCategory/DeleteOneSystemMain";
var send_data = { var send_data = {
Guid: selected_system_main_guid id: selected_system_main_guid
} }
$.post(url, send_data, function (rel) { $.post(url, send_data, function (rel) {
if (rel.code != "0000") { if (rel.code != "0000") {
@ -226,9 +226,9 @@
var url = "/SystemCategory/SaveSystemMain"; var url = "/SystemCategory/SaveSystemMain";
var send_data = { var send_data = {
Main_system_guid: selected_system_main_guid, id: selected_system_main_guid,
Full_name: $('#system_main_name_modal').val(), System_key: $('#system_main_name_modal').val(),
Code: $('#system_main_code_modal').val() system_value : $('#system_main_code_modal').val()
} }
$.post(url, send_data, function (rel) { $.post(url, send_data, function (rel) {
@ -278,7 +278,10 @@
} }
}, },
{ {
"data": "full_name" "data": "system_key"
},
{
"data": "system_value"
}, },
{ {
"data": "created_at" "data": "created_at"
@ -289,14 +292,14 @@
} }
], ],
'createdRow': function (row, data, dataIndex) { 'createdRow': function (row, data, dataIndex) {
$(row).attr('data-guid', data.sub_system_guid); $(row).attr('data-guid', data.id);
}, },
//"order": [[2, "desc"]], //"order": [[2, "desc"]],
"ajax": { "ajax": {
"url": "/SystemCategory/SystemSubList", "url": "/SystemCategory/SystemSubList",
"type": "POST", "type": "POST",
"data": function (d) { "data": function (d) {
d.Main_system_guid = selected_system_main_guid d.id = selected_system_main_guid
}, },
"dataSrc": function (rel) { "dataSrc": function (rel) {
if (rel.code == "9999") { if (rel.code == "9999") {
@ -346,20 +349,23 @@
{ {
"data": "is_bool" "data": "is_bool"
}, },
{
"data": "is_link"
},
{ {
"data": null, "data": null,
"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>'
} }
], ],
'createdRow': function (row, data, dataIndex) { 'createdRow': function (row, data, dataIndex) {
$(row).attr('data-guid', data.device_item_guid); $(row).attr('data-guid', data.id);
}, },
//"order": [[2, "desc"]], //"order": [[2, "desc"]],
"ajax": { "ajax": {
"url": "/SystemCategory/DeviceItemTable", "url": "/SystemCategory/DeviceItemTable",
"type": "POST", "type": "POST",
"data": function (d) { "data": function (d) {
d.sub_system_guid = selected_system_sub_guid d.id = selected_system_sub_guid
}, },
"dataSrc": function (rel) { "dataSrc": function (rel) {
if (rel.code == "9999") { if (rel.code == "9999") {
@ -397,6 +403,12 @@
} else { } else {
rel.is_bool = "是" rel.is_bool = "是"
} }
if (rel.is_link == 0) {
rel.is_link = "否"
} else {
rel.is_link = "是"
}
}); });
return data; return data;
@ -416,7 +428,7 @@
var url = "/SystemCategory/GetOneSystemSub"; var url = "/SystemCategory/GetOneSystemSub";
var send_data = { var send_data = {
guid: selected_system_sub_guid id: selected_system_sub_guid
} }
$.post(url, send_data, function (rel) { $.post(url, send_data, function (rel) {
@ -431,7 +443,8 @@
} }
else { else {
$("#system_main_name").html(selected_system_main_guid_top_name) $("#system_main_name").html(selected_system_main_guid_top_name)
$("#system_sub_name_modal").val(rel.data.full_name); $("#system_sub_name_modal").val(rel.data.system_key);
$("#system_sub_code_modal").val(rel.data.system_value);
$("#system-sub-modal").modal(); $("#system-sub-modal").modal();
} }
@ -458,7 +471,7 @@
if (result.value) { if (result.value) {
var url = "/SystemCategory/DeleteOneSystemSub"; var url = "/SystemCategory/DeleteOneSystemSub";
var send_data = { var send_data = {
Guid: selected_system_sub_guid id: selected_system_sub_guid
} }
$.post(url, send_data, function (rel) { $.post(url, send_data, function (rel) {
if (rel.code != "0000") { if (rel.code != "0000") {
@ -539,9 +552,10 @@
var url = "/SystemCategory/SaveSystemSub"; var url = "/SystemCategory/SaveSystemSub";
var send_data = { var send_data = {
Sub_system_guid: selected_system_sub_guid, id: selected_system_sub_guid,
Main_system_guid: selected_system_main_guid, system_parent_id: selected_system_main_guid,
Full_name: $('#system_sub_name_modal').val(), system_key: $('#system_sub_name_modal').val(),
system_value: $('#system_sub_code_modal').val()
} }
$.post(url, send_data, function (rel) { $.post(url, send_data, function (rel) {
@ -610,9 +624,9 @@
var uurl = "/SystemCategory/HaveSamePoints"; var uurl = "/SystemCategory/HaveSamePoints";
var ssend_data = { var ssend_data = {
sub_system_guid: selected_system_sub_guid, subId: selected_system_sub_guid,
id: selected_system_device_item_guid,
points: $('#device_sub_points_modal').val(), points: $('#device_sub_points_modal').val(),
device_item_guid: selected_system_device_item_guid,
} }
$.post(uurl, ssend_data, function (rel) { $.post(uurl, ssend_data, function (rel) {
if (rel.code != "0000") { if (rel.code != "0000") {
@ -633,8 +647,9 @@
else { else {
var url = "/SystemCategory/Savedevice_item"; var url = "/SystemCategory/Savedevice_item";
var send_data = { var send_data = {
device_item_guid: selected_system_device_item_guid, id: selected_system_device_item_guid,
sub_system_guid: selected_system_sub_guid, device_system_tag: selected_system_main_guid,
device_name_tag: selected_system_sub_guid,
full_name: $('#device_sub_name_modal').val(), full_name: $('#device_sub_name_modal').val(),
points: $('#device_sub_points_modal').val(), points: $('#device_sub_points_modal').val(),
unit: $('#device_sub_unit_modal').val(), unit: $('#device_sub_unit_modal').val(),
@ -686,7 +701,7 @@
var url = "/SystemCategory/GetOneDeviceItem"; var url = "/SystemCategory/GetOneDeviceItem";
var send_data = { var send_data = {
guid: selected_system_device_item_guid id: selected_system_device_item_guid
} }
$.post(url, send_data, function (rel) { $.post(url, send_data, function (rel) {
@ -708,6 +723,7 @@
$("input[name='is_show_riserDiagram'][value='" + rel.data.is_show_riserDiagram + "']").prop("checked", true); $("input[name='is_show_riserDiagram'][value='" + rel.data.is_show_riserDiagram + "']").prop("checked", true);
$("input[name='is_controll'][value='" + rel.data.is_controll + "']").prop("checked", true); $("input[name='is_controll'][value='" + rel.data.is_controll + "']").prop("checked", true);
$("input[name='is_bool'][value='" + rel.data.is_bool + "']").prop("checked", true); $("input[name='is_bool'][value='" + rel.data.is_bool + "']").prop("checked", true);
$("input[name='is_link'][value='" + rel.data.is_link+ "']").prop("checked", true);
$("#device-sub-modal").modal(); $("#device-sub-modal").modal();
} }
@ -759,7 +775,7 @@
} else { } else {
var url = "/SystemCategory/DeleteOneSystemSubDeviceItem"; var url = "/SystemCategory/DeleteOneSystemSubDeviceItem";
var send_data = { var send_data = {
guid: selected_system_device_item_guid id: selected_system_device_item_guid
} }
$.post(url, send_data, function (rel) { $.post(url, send_data, function (rel) {
if (rel.code != "0000") { if (rel.code != "0000") {

View File

@ -17,6 +17,7 @@
<th>序</th> <th>序</th>
<th>系統大類</th> <th>系統大類</th>
<th>系統小類名稱</th> <th>系統小類名稱</th>
<th>系統小類代號</th>
<th>建立時間</th> <th>建立時間</th>
<th>功能</th> <th>功能</th>
</tr> </tr>
@ -50,6 +51,7 @@
<th>是否顯示於昇位圖(僅可擇一顯示)</th> <th>是否顯示於昇位圖(僅可擇一顯示)</th>
<th>是否加入 - 設備燈號中的點位選單</th> <th>是否加入 - 設備燈號中的點位選單</th>
<th>是否為布林值</th> <th>是否為布林值</th>
<th>是否與N4同步</th>
<th>功能</th> <th>功能</th>
</tr> </tr>
</thead> </thead>
@ -84,6 +86,10 @@
<label class="form-label" for="system_sub_name_modal"><span class="text-danger">*</span>小類名稱</label> <label class="form-label" for="system_sub_name_modal"><span class="text-danger">*</span>小類名稱</label>
<input type="text" id="system_sub_name_modal" class="form-control" name="system_sub_name_modal"> <input type="text" id="system_sub_name_modal" class="form-control" name="system_sub_name_modal">
</div> </div>
<div class="form-group col-12">
<label class="form-label" for="system_sub_code_modal"><span class="text-danger">*</span>代號</label>
<input type="text" id="system_sub_code_modal" class="form-control" name="system_sub_code_modal">
</div>
</div> </div>
</form> </form>
</div> </div>
@ -147,6 +153,13 @@
<label class="custom-control-label" for="is_bool">是否為布林值</label> <label class="custom-control-label" for="is_bool">是否為布林值</label>
</div> </div>
</div> </div>
<div class="form-group col-12">
<div class="col-12 mb-2 custom-control custom-checkbox align-content-center">
<input type="checkbox" class="custom-control-input" name="is_link" id="is_link" value="1" />
<label class="custom-control-label" for="is_link">是否與N4同步</label>
</div>
</div>
</div> </div>
</form> </form>
</div> </div>