This commit is contained in:
cesar liu 2022-10-28 09:39:31 +08:00
commit 420d5ece7d
21 changed files with 4541 additions and 1142 deletions

View File

@ -646,7 +646,7 @@ namespace Backend.Controllers
{ {
var sqlString = @$"select v.id var sqlString = @$"select v.id
from building b from building b
join variable v on v.system_type = @system_type and system_key = N'3D' and v.deleted = 0 join variable v on v.system_type = @system_type and system_key = N'3D' and system_value = 'Y' and v.deleted = 0
where b.building_tag = @building_tag and (b.orgName_3D + b.saveName_3D) is not null;"; where b.building_tag = @building_tag and (b.orgName_3D + b.saveName_3D) is not null;";
KeyValue = await backendRepository.GetAllAsync<KeyValue>(sqlString, new { building_tag = post.building_tag, system_type = system_setting_type }); KeyValue = await backendRepository.GetAllAsync<KeyValue>(sqlString, new { building_tag = post.building_tag, system_type = system_setting_type });

View File

@ -201,8 +201,9 @@ namespace Backend.Controllers
LEFT JOIN device_kind dk ON dk.device_building_tag = d.device_building_tag AND dk.device_system_tag = d.device_system_tag AND dk.device_name_tag = d.device_name_tag LEFT JOIN device_kind dk ON dk.device_building_tag = d.device_building_tag AND dk.device_system_tag = d.device_system_tag AND dk.device_name_tag = d.device_name_tag
ORDER BY d.priority ASC, d.device_number ASC"; ORDER BY d.priority ASC, d.device_number ASC";
var devices = await backendRepository.GetAllAsync<Device>(sql, new { var devices = await backendRepository.GetAllAsync<Device>(sql, new
building_tag = post.building_tag, {
building_tag = post.building_tag,
main_system_tag = post.device_system_tag, main_system_tag = post.device_system_tag,
sub_system_tag = post.device_name_tag, sub_system_tag = post.device_name_tag,
floor_tag = post.device_floor_tag, floor_tag = post.device_floor_tag,
@ -269,7 +270,7 @@ namespace Backend.Controllers
JOIN floor f ON d.device_floor_tag = f.full_name JOIN floor f ON d.device_floor_tag = f.full_name
"; ";
object param = new { Deleted = 0, Device_guid = guid ,main_system_type = main_system_type , sub_system_type = sub_system_type }; object param = new { Deleted = 0, Device_guid = guid, main_system_type = main_system_type, sub_system_type = sub_system_type };
var device = await backendRepository.GetOneAsync<Device>(sql, param); var device = await backendRepository.GetOneAsync<Device>(sql, param);
@ -333,7 +334,7 @@ namespace Backend.Controllers
{ {
List<Dictionary<string, object>> deviceDics = new List<Dictionary<string, object>>(); List<Dictionary<string, object>> deviceDics = new List<Dictionary<string, object>>();
List<Dictionary<string, object>> device_disaster_dicts = new List<Dictionary<string, object>>(); List<Dictionary<string, object>> device_disaster_dicts = new List<Dictionary<string, object>>();
PostDeviceKind postDeviceKind = new PostDeviceKind();
using (var reader = new StreamReader(post.SelectedDevicesFile.OpenReadStream())) using (var reader = new StreamReader(post.SelectedDevicesFile.OpenReadStream()))
{ {
string content = reader.ReadToEnd(); string content = reader.ReadToEnd();
@ -345,12 +346,14 @@ namespace Backend.Controllers
var guid = Guid.NewGuid(); var guid = Guid.NewGuid();
var split = device.Device_number.Split('_'); var split = device.Device_number.Split('_');
var device_building_tag = !string.IsNullOrEmpty(split[0]) ? split[0] : ""; var device_area_tag = !string.IsNullOrEmpty(split[0]) ? split[0] : "";
var device_system_tag = !string.IsNullOrEmpty(split[1]) ? split[1] : ""; var device_building_tag = !string.IsNullOrEmpty(post.Building_tag) ? post.Building_tag : "";
var device_floor_tag = !string.IsNullOrEmpty(split[2]) ? split[2] : ""; var device_system_tag = !string.IsNullOrEmpty(post.Main_system_tag) ? post.Main_system_tag : "";
var device_name_tag = !string.IsNullOrEmpty(split[3]) ? split[3] : ""; var device_name_tag = !string.IsNullOrEmpty(post.Sub_system_tag) ? post.Sub_system_tag : "";
var device_serial_tag = !string.IsNullOrEmpty(split[4]) ? split[4] : ""; var device_floor_tag = !string.IsNullOrEmpty(post.Floor_tag) ? post.Floor_tag : "";
string device_master = null; var device_last_name = !string.IsNullOrEmpty(split[6]) ? split[6] : "";
var device_serial_tag = !string.IsNullOrEmpty(split[7]) ? split[7] : "";
string device_master = "NA";
//針對燈具加入master //針對燈具加入master
if (device.Device_system_category_layer3 == "L1" || device.Device_system_category_layer3 == "L2") if (device.Device_system_category_layer3 == "L1" || device.Device_system_category_layer3 == "L2")
@ -361,18 +364,27 @@ namespace Backend.Controllers
Dictionary<string, object> deviceDic = new Dictionary<string, object>() Dictionary<string, object> deviceDic = new Dictionary<string, object>()
{ {
{ "@device_guid", guid}, { "@device_guid", guid},
{ "@full_name", device_name_tag + device_serial_tag}, { "@device_area_tag", device_area_tag},
{ "@device_building_tag", device_building_tag}, { "@device_building_tag", device_building_tag},
{ "@device_system_tag", device_system_tag}, { "@device_system_tag", device_system_tag},
{ "@device_floor_tag", device_floor_tag}, { "@device_floor_tag", device_floor_tag},
{ "@device_name_tag", device_name_tag}, { "@device_name_tag", device_name_tag},
{ "@device_serial_tag", device_serial_tag}, { "@device_serial_tag", device_serial_tag},
{ "@device_last_name", device_last_name},
{ "@device_master", device_master}, { "@device_master", device_master},
{ "@device_number", device.Device_number}, { "@device_number", device.Device_number},
{ "@device_system_category_layer3", device.Device_system_category_layer3}, { "@device_system_category_layer3", device.Device_system_category_layer3},
{ "@created_by", myUserInfo.Userinfo_guid}, { "@created_by", myUserInfo.Userinfo_guid},
}; };
postDeviceKind = new PostDeviceKind()
{
Device_building_tag = device_building_tag,
Device_system_tag = device_system_tag,
Device_floor_tag = device_floor_tag,
Device_name_tag = device_name_tag,
};
deviceDics.Add(deviceDic); deviceDics.Add(deviceDic);
if (device.Device_disasters != null) if (device.Device_disasters != null)
@ -402,6 +414,8 @@ namespace Backend.Controllers
await ResetDeviceGroup(); //重新寫入設備群組 await ResetDeviceGroup(); //重新寫入設備群組
await AddDeviceKind(postDeviceKind);
apiResult.Code = "0000"; apiResult.Code = "0000";
apiResult.Msg = "修改成功"; apiResult.Msg = "修改成功";
@ -804,7 +818,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", null, null, "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>();
@ -963,8 +977,8 @@ namespace Backend.Controllers
FROM device d FROM device d
WHERE WHERE
d.device_building_tag = @building_tag d.device_building_tag = @building_tag
AND d.device_system_tag = @main_system_tag AND d.device_system_tag = @device_system_tag
AND d.device_name_tag = @sub_system_tag AND d.device_name_tag = @device_name_tag
-- AND d.floor_guid = @Floor_tag -- AND d.floor_guid = @Floor_tag
AND d.deleted = 0 AND d.deleted = 0
) d ) d
@ -1025,6 +1039,70 @@ namespace Backend.Controllers
return apiResult; return apiResult;
} }
public async Task AddDeviceKind(PostDeviceKind post)
{
string sWhere = @$"device_building_tag = @building_tag and device_system_tag = @system_tag and device_name_tag = @name_tag";
object param = new { building_tag = post.Device_building_tag, system_tag = post.Device_system_tag, name_tag = post.Device_name_tag };
var deviceKind = await backendRepository.GetOneAsync<DeviceKind>("device_kind", sWhere, param);
if (deviceKind == null)
{
//新增
//產生一組GUID
var guid = Guid.NewGuid();
//抓出點位名稱
//var point_name = new PointName();
//var sql_device_normal_point = @"SELECT n.points AS device_normal_point_name FROM (SELECT * FROM device_item di WHERE di.device_item_id = @device_normal_point_guid) n";
//point_name.Device_normal_point_name = await backendRepository.GetOneAsync<string>(sql_device_normal_point, new { device_normal_point_guid = post.Device_normal_point_guid });
//var sql_device_close_point = @"SELECT c.points AS device_close_point_name FROM (SELECT * FROM device_item di WHERE di.device_item_guid = @device_close_point_guid) c";
//point_name.Device_close_point_name = await backendRepository.GetOneAsync<string>(sql_device_close_point, new { device_close_point_guid = post.Device_close_point_guid });
//var sql_device_error_point = @"SELECT e.points AS device_error_point_name FROM (SELECT * FROM device_item di WHERE di.device_item_guid = @device_error_point_guid) e";
//point_name.Device_error_point_name = await backendRepository.GetOneAsync<string>(sql_device_error_point, new { device_error_point_guid = post.Device_error_point_guid });
Dictionary<string, object> deviceKindDic = new Dictionary<string, object>()
{
{ "@device_kind_guid", guid},
{ "@device_building_tag", post.Device_building_tag},
{ "@device_system_tag", post.Device_system_tag},
//{ "@device_floor_tag", post.Device_floor_tag},
{ "@device_name_tag", post.Device_name_tag},
{ "@device_image", null },
{ "@device_normal_text", post.Device_normal_text},
{ "@device_normal_point_guid", post.Device_normal_point_guid},
{ "@device_normal_point_name", null},
{ "@device_normal_point_col", post.Device_normal_point_col},
{ "@device_normal_point_value", post.Device_normal_point_value},
{ "@device_normal_color", post.Device_normal_color},
{ "@device_normal_flashing", post.Device_normal_flashing},
{ "@device_close_text", post.Device_close_text},
{ "@device_close_point_guid", post.Device_close_point_guid},
{ "@device_close_point_name", null},
{ "@device_close_point_col", post.Device_close_point_col},
{ "@device_close_point_value", post.Device_close_point_value},
{ "@device_close_color", post.Device_close_color},
{ "@device_close_flashing", post.Device_close_flashing},
{ "@device_error_text", post.Device_error_text},
{ "@device_error_point_guid", post.Device_error_point_guid},
{ "@device_error_point_name", null},
{ "@device_error_point_col", post.Device_error_point_col},
{ "@device_error_point_value", post.Device_error_point_value},
{ "@device_error_color", post.Device_error_color},
{ "@device_error_flashing", post.Device_error_flashing},
{ "@device_error_independent", post.Device_error_independent},
{ "@created_by", myUserInfo.Userinfo_guid}
};
await backendRepository.AddOneByCustomTable(deviceKindDic, "device_kind");
}
}
/// <summary> /// <summary>
/// 修改 設備基本資料 /// 修改 設備基本資料
/// </summary> /// </summary>
@ -1062,14 +1140,14 @@ namespace Backend.Controllers
//抓出點位名稱 //抓出點位名稱
var point_name = new PointName(); var point_name = new PointName();
var sql_device_normal_point = @"SELECT n.points AS device_normal_point_name FROM (SELECT * FROM device_item di WHERE di.device_item_guid = @device_normal_point_guid) n"; var sql_device_normal_point = @"SELECT n.points AS device_normal_point_name FROM (SELECT * FROM device_item di WHERE di.id = @device_normal_point_id) n";
point_name.Device_normal_point_name = await backendRepository.GetOneAsync<string>(sql_device_normal_point, new { device_normal_point_guid = post.Device_normal_point_guid }); point_name.Device_normal_point_name = await backendRepository.GetOneAsync<string>(sql_device_normal_point, new { device_normal_point_id = post.Device_normal_point_guid });
var sql_device_close_point = @"SELECT c.points AS device_close_point_name FROM (SELECT * FROM device_item di WHERE di.device_item_guid = @device_close_point_guid) c"; var sql_device_close_point = @"SELECT c.points AS device_close_point_name FROM (SELECT * FROM device_item di WHERE di.id = @device_close_point_id) c";
point_name.Device_close_point_name = await backendRepository.GetOneAsync<string>(sql_device_close_point, new { device_close_point_guid = post.Device_close_point_guid }); point_name.Device_close_point_name = await backendRepository.GetOneAsync<string>(sql_device_close_point, new { device_close_point_id = post.Device_close_point_guid });
var sql_device_error_point = @"SELECT e.points AS device_error_point_name FROM (SELECT * FROM device_item di WHERE di.device_item_guid = @device_error_point_guid) e"; var sql_device_error_point = @"SELECT e.points AS device_error_point_name FROM (SELECT * FROM device_item di WHERE di.id = @device_error_point_id) e";
point_name.Device_error_point_name = await backendRepository.GetOneAsync<string>(sql_device_error_point, new { device_error_point_guid = post.Device_error_point_guid }); point_name.Device_error_point_name = await backendRepository.GetOneAsync<string>(sql_device_error_point, new { device_error_point_id = post.Device_error_point_guid });
Dictionary<string, object> deviceKindDic = new Dictionary<string, object>() Dictionary<string, object> deviceKindDic = new Dictionary<string, object>()
{ {
@ -1119,23 +1197,23 @@ namespace Backend.Controllers
} }
#region #region
List<Repository.Models.FileInfo> fileInfos = new List<Repository.Models.FileInfo>(); //List<Repository.Models.FileInfo> fileInfos = new List<Repository.Models.FileInfo>();
if (post.Device_image_file != null) //if (post.Device_image_file != null)
{ //{
var split = post.Device_image_file.FileName.Split("."); // var split = post.Device_image_file.FileName.Split(".");
var fileName = guid + "." + split[split.Length - 1]; // var fileName = guid + "." + split[split.Length - 1];
var fullPath = Path.Combine(deviceKindFileSaveAsPath, fileName); // var fullPath = Path.Combine(deviceKindFileSaveAsPath, fileName);
Repository.Models.FileInfo fileInfo = new Repository.Models.FileInfo(); // Repository.Models.FileInfo fileInfo = new Repository.Models.FileInfo();
fileInfo.Folder = "device_icon"; // fileInfo.Folder = "device_icon";
fileInfo.OriginalFileName = null; // fileInfo.OriginalFileName = null;
fileInfo.FileName = fileName; // fileInfo.FileName = fileName;
fileInfo.File = fullPath; // fileInfo.File = fullPath;
fileInfos.Add(fileInfo); // fileInfos.Add(fileInfo);
await backendRepository.ManualInsertFileBackgroundServiceTask("", "", "device_kind", fileInfos); // await backendRepository.ManualInsertFileBackgroundServiceTask("", "", "device_kind", fileInfos);
} //}
#endregion #endregion
apiResult.Code = "0000"; apiResult.Code = "0000";
@ -1160,14 +1238,14 @@ namespace Backend.Controllers
//抓出點位名稱 //抓出點位名稱
var point_name = new PointName(); var point_name = new PointName();
var sql_device_normal_point = @"SELECT n.points AS device_normal_point_name FROM (SELECT * FROM device_item di WHERE di.device_item_guid = @device_normal_point_guid) n"; var sql_device_normal_point = @"SELECT n.points AS device_normal_point_name FROM (SELECT * FROM device_item di WHERE di.id = @device_normal_point_id) n";
point_name.Device_normal_point_name = await backendRepository.GetOneAsync<string>(sql_device_normal_point, new { device_normal_point_guid = post.Device_normal_point_guid }); point_name.Device_normal_point_name = await backendRepository.GetOneAsync<string>(sql_device_normal_point, new { device_normal_point_id = post.Device_normal_point_guid });
var sql_device_close_point = @"SELECT c.points AS device_close_point_name FROM (SELECT * FROM device_item di WHERE di.device_item_guid = @device_close_point_guid) c"; var sql_device_close_point = @"SELECT c.points AS device_close_point_name FROM (SELECT * FROM device_item di WHERE di.id = @device_close_point_id) c";
point_name.Device_close_point_name = await backendRepository.GetOneAsync<string>(sql_device_close_point, new { device_close_point_guid = post.Device_close_point_guid }); point_name.Device_close_point_name = await backendRepository.GetOneAsync<string>(sql_device_close_point, new { device_close_point_id = post.Device_close_point_guid });
var sql_device_error_point = @"SELECT e.points AS device_error_point_name FROM (SELECT * FROM device_item di WHERE di.device_item_guid = @device_error_point_guid) e"; var sql_device_error_point = @"SELECT e.points AS device_error_point_name FROM (SELECT * FROM device_item di WHERE di.id = @device_error_point_id) e";
point_name.Device_error_point_name = await backendRepository.GetOneAsync<string>(sql_device_error_point, new { device_error_point_guid = post.Device_error_point_guid }); point_name.Device_error_point_name = await backendRepository.GetOneAsync<string>(sql_device_error_point, new { device_error_point_id = post.Device_error_point_guid });
Dictionary<string, object> deviceKindDic = new Dictionary<string, object>() Dictionary<string, object> deviceKindDic = new Dictionary<string, object>()
{ {
@ -1217,23 +1295,23 @@ namespace Backend.Controllers
} }
#region #region
List<Repository.Models.FileInfo> fileInfos = new List<Repository.Models.FileInfo>(); //List<Repository.Models.FileInfo> fileInfos = new List<Repository.Models.FileInfo>();
if (post.Device_image_file != null) //if (post.Device_image_file != null)
{ //{
var split = post.Device_image_file.FileName.Split("."); // var split = post.Device_image_file.FileName.Split(".");
var fileName = image_guid + "." + split[split.Length - 1]; // var fileName = image_guid + "." + split[split.Length - 1];
var fullPath = Path.Combine(deviceKindFileSaveAsPath, fileName); // var fullPath = Path.Combine(deviceKindFileSaveAsPath, fileName);
Repository.Models.FileInfo fileInfo = new Repository.Models.FileInfo(); // Repository.Models.FileInfo fileInfo = new Repository.Models.FileInfo();
fileInfo.Folder = "device_icon"; // fileInfo.Folder = "device_icon";
fileInfo.OriginalFileName = deviceKind.Device_image; // fileInfo.OriginalFileName = deviceKind.Device_image;
fileInfo.FileName = fileName; // fileInfo.FileName = fileName;
fileInfo.File = fullPath; // fileInfo.File = fullPath;
fileInfos.Add(fileInfo); // fileInfos.Add(fileInfo);
await backendRepository.ManualInsertFileBackgroundServiceTask("", "", "device_kind", fileInfos); // await backendRepository.ManualInsertFileBackgroundServiceTask("", "", "device_kind", fileInfos);
} //}
#endregion #endregion
apiResult.Code = "0000"; apiResult.Code = "0000";
@ -1255,9 +1333,9 @@ namespace Backend.Controllers
private async Task ResetDeviceGroup() private async Task ResetDeviceGroup()
{ {
//先刪除整個device_group //先刪除整個device_group
var delete_group_sql = @"DROP TABLE IF EXISTS `device_group` ; var delete_group_sql = @"DROP TABLE IF EXISTS `device_group` ;
CREATE TABLE `device_group` ( CREATE TABLE `device_group` (
`id` int(11) NOT NULL, `id` int(11) NOT NULL AUTO_INCREMENT,
`device_disaster` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '', `device_disaster` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`device_building_tag` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'guid', `device_building_tag` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'guid',
`device_floor_guid` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'guid', `device_floor_guid` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'guid',
@ -1274,13 +1352,14 @@ namespace Backend.Controllers
INSERT INTO device_group (device_disaster, device_building_tag, device_floor_guid, device_system_category_layer2, device_system_category_layer3, device_amount) INSERT INTO device_group (device_disaster, device_building_tag, device_floor_guid, device_system_category_layer2, device_system_category_layer3, device_amount)
SELECT SELECT
dd.device_system_value AS device_disaster, dd.device_system_value AS device_disaster,
d.building_tag AS device_building_tag, d.device_building_tag AS device_building_tag,
d.floor_guid AS device_floor_guid, f.floor_guid AS device_floor_guid,
vv.device_system_category_layer2 AS device_system_category_layer2, vv.device_system_category_layer2 AS device_system_category_layer2,
d.device_system_category_layer3 AS device_system_category_layer3, d.device_system_category_layer3 AS device_system_category_layer3,
count(*) AS device_amount count(*) AS device_amount
FROM device d FROM device d
JOIN device_disaster dd ON d.device_guid = dd.device_guid JOIN device_disaster dd ON d.device_guid = dd.device_guid
JOIN floor f ON d.device_floor_tag = f.full_name
JOIN (SELECT JOIN (SELECT
v.system_value AS device_system_category_layer3, v.system_value AS device_system_category_layer3,
v2.system_value AS device_system_category_layer2 v2.system_value AS device_system_category_layer2
@ -1290,8 +1369,8 @@ namespace Backend.Controllers
) vv ON d.device_system_category_layer3 = vv.device_system_category_layer3 ) vv ON d.device_system_category_layer3 = vv.device_system_category_layer3
WHERE d.deleted = 0 WHERE d.deleted = 0
GROUP BY dd.device_system_value, GROUP BY dd.device_system_value,
d.building_tag, d.device_building_tag,
d.floor_guid, f.floor_guid,
vv.device_system_category_layer2, vv.device_system_category_layer2,
d.device_system_category_layer3"; d.device_system_category_layer3";
@ -1317,7 +1396,7 @@ namespace Backend.Controllers
deviceGroupsDics.Add(deviceGroupDic); deviceGroupsDics.Add(deviceGroupDic);
} }
await backendRepository.ManualInsertBackgroundServiceTask("", "", "device_group", "purge_all_insert", deviceGroupsDics);
#endregion #endregion
} }
@ -1386,7 +1465,7 @@ namespace Backend.Controllers
{ {
string sWhere = "device_master_guid = @Device_master_guid"; string sWhere = "device_master_guid = @Device_master_guid";
object param = new {Device_master_guid = guid }; object param = new { Device_master_guid = guid };
var deviceMaster = await backendRepository.GetOneAsync<DeviceMaster>("device_master", sWhere, param); var deviceMaster = await backendRepository.GetOneAsync<DeviceMaster>("device_master", sWhere, param);
@ -1438,7 +1517,7 @@ namespace Backend.Controllers
} }
string temp_device_master_number = null; string temp_device_master_number = null;
if (!string.IsNullOrEmpty( post.Device_building_tag) && !string.IsNullOrEmpty(post.Device_name_tag)) if (!string.IsNullOrEmpty(post.Device_building_tag) && !string.IsNullOrEmpty(post.Device_name_tag))
{ {
temp_device_master_number = post.Device_building_tag + "_" + post.Device_name_tag; temp_device_master_number = post.Device_building_tag + "_" + post.Device_name_tag;
} }
@ -1581,7 +1660,7 @@ namespace Backend.Controllers
try try
{ {
string sWhere = "deleted = 0 AND sub_system_tag = @Sub_system_tag"; string sWhere = "deleted = 0 AND device_name_tag = @Sub_system_tag";
object param = new { Sub_system_tag = sub_system_tag }; object param = new { Sub_system_tag = sub_system_tag };

View File

@ -175,8 +175,8 @@
</div> </div>
</div> </div>
</div> </div>
<div class="form-group col-12" id="" name="drawing_extend"> <div class="form-group col-12" id="build_menu_planimetric_modal_div" name="drawing_extend" >
<div class="col-12 mb-2 custom-control custom-checkbox align-content-center"> <div class="col-12 mb-2 custom-control custom-checkbox align-content-center" >
<input type="checkbox" class="custom-control-input" name="planimetric_click" id="planimetric_click" value="1" /> <input type="checkbox" class="custom-control-input" name="planimetric_click" id="planimetric_click" value="1" />
<label class="custom-control-label" for="planimetric_click">是否顯示平面圖</label> <label class="custom-control-label" for="planimetric_click">是否顯示平面圖</label>
</div> </div>
@ -263,7 +263,13 @@
<label class="form-label"><span class="text-danger">*</span>預設頁面</label> <label class="form-label"><span class="text-danger">*</span>預設頁面</label>
<div class="row" id="build_menu_drawing_modal_r"> <div class="row" id="build_menu_drawing_modal_r">
<div class="col"> <div class="col">
<input type="radio" name="drawing_r" id="drawing_4_r" value="4" checked> <input type="radio" name="drawing_r" id="drawing_0_r" value="0" checked>
<label for="drawing_0_r">
不顯示
</label>
</div>
<div class="col">
<input type="radio" name="drawing_r" id="drawing_4_r" value="4">
<label for="drawing_4_r"> <label for="drawing_4_r">
昇位圖 昇位圖
</label> </label>
@ -294,7 +300,7 @@
</div> </div>
</div> </div>
</div> </div>
<div class="form-group col-12" id="" name="drawing_extend_r"> <div class="form-group col-12" id="build_menu_planimetric_modal_div_r" name="drawing_extend_r">
<div class="col-12 mb-2 custom-control custom-checkbox align-content-center"> <div class="col-12 mb-2 custom-control custom-checkbox align-content-center">
<input type="checkbox" class="custom-control-input" name="planimetric_click_r" id="planimetric_click_r" value="1" /> <input type="checkbox" class="custom-control-input" name="planimetric_click_r" id="planimetric_click_r" value="1" />
<label class="custom-control-label" for="planimetric_click_r">是否顯示平面圖</label> <label class="custom-control-label" for="planimetric_click_r">是否顯示平面圖</label>
@ -973,7 +979,7 @@
$(drawingParent).find('[id^=build_menu_icon_click_url_width_height_modal_div]').hide(); $(drawingParent).find('[id^=build_menu_icon_click_url_width_height_modal_div]').hide();
$(drawingParent).find('[id^=build_menu_planimetric_floor_modal_div]').hide(); $(drawingParent).find('[id^=build_menu_planimetric_floor_modal_div]').hide();
$(drawingParent).find('[id^=build_menu_systemurl_modal_div]').hide(); $(drawingParent).find('[id^=build_menu_systemurl_modal_div]').hide();
$(drawingParent).find('[id^=build_menu_planimetric_modal_div]').show();
if ($(value).val() == 2) { if ($(value).val() == 2) {
$(drawingParent).find('[id^=planimetric_click]').attr("disabled", false); $(drawingParent).find('[id^=planimetric_click]').attr("disabled", false);
$(drawingParent).find('[id^=build_menu_systemurl_modal_div]').show(); $(drawingParent).find('[id^=build_menu_systemurl_modal_div]').show();
@ -992,6 +998,8 @@
$(drawingParent).find('[id^=build_menu_blankurl_modal_div]').show(); $(drawingParent).find('[id^=build_menu_blankurl_modal_div]').show();
} else if ($(value).val() == 3) { } else if ($(value).val() == 3) {
$(drawingParent).find('[id^=planimetric_click]').prop("checked", false).attr("disabled", true); $(drawingParent).find('[id^=planimetric_click]').prop("checked", false).attr("disabled", true);
} else {
$(drawingParent).find('[id^=build_menu_planimetric_modal_div]').hide();
} }
}) })

View File

@ -166,7 +166,7 @@
<div class="row mb-3 align-items-center justify-content-start"> <div class="row mb-3 align-items-center justify-content-start">
<div class="col-12"> <div class="col-12">
<div class="row mb-2 align-items-center justify-content-start"> <div class="row mb-2 align-items-center justify-content-start">
<span class="col-1">區域</span> <span class="col-1">棟別</span>
<div class="col-11 row"> <div class="col-11 row">
<div id="import-temp-building-tag-list" class="col-12"> <div id="import-temp-building-tag-list" class="col-12">
</div> </div>
@ -1494,10 +1494,10 @@
"url": "/DeviceManage/DeviceKindTableList", "url": "/DeviceManage/DeviceKindTableList",
"type": "POST", "type": "POST",
"data": function (d) { "data": function (d) {
d.Building_tag = selected_building_menu.building_tag ? selected_building_menu.building_tag : ""; d.building_tag = selected_building_menu.building_tag ? selected_building_menu.building_tag : "";
d.Main_system_tag = selected_building_menu.main_system ? selected_building_menu.main_system.main_system_tag : ""; d.device_system_tag = selected_building_menu.main_system ? selected_building_menu.main_system.main_system_tag : "";
d.Sub_system_tag = selected_building_menu.main_system ? selected_building_menu.main_system.sub_system ? selected_building_menu.main_system.sub_system.sub_system_tag : "" : ""; d.device_name_tag = selected_building_menu.main_system ? selected_building_menu.main_system.sub_system ? selected_building_menu.main_system.sub_system.sub_system_tag : "" : "";
d.Floor_tag = selected_floor_tag ? selected_floor_tag : ""; //d.Floor_tag = selected_floor_tag ? selected_floor_tag : "";
}, },
"dataSrc": function (rel) { "dataSrc": function (rel) {
if (rel.code == "9999") { if (rel.code == "9999") {
@ -1545,7 +1545,6 @@
return; return;
} }
else { else {
device_kind_data = rel.data; device_kind_data = rel.data;
//取得單一設備基本資料 //取得單一設備基本資料
@ -1575,9 +1574,9 @@
$("#device_close_point_name_modal").append($("<option />").val("").text("未選擇")); $("#device_close_point_name_modal").append($("<option />").val("").text("未選擇"));
$("#device_error_point_name_modal").append($("<option />").val("").text("未選擇")); $("#device_error_point_name_modal").append($("<option />").val("").text("未選擇"));
$.each(rel.data, function (index, val) { $.each(rel.data, function (index, val) {
$("#device_normal_point_name_modal").append($("<option />").val(val.device_item_guid).text(val.points)); $("#device_normal_point_name_modal").append($("<option />").val(val.id).text(val.points));
$("#device_close_point_name_modal").append($("<option />").val(val.device_item_guid).text(val.points)); $("#device_close_point_name_modal").append($("<option />").val(val.id).text(val.points));
$("#device_error_point_name_modal").append($("<option />").val(val.device_item_guid).text(val.points)); $("#device_error_point_name_modal").append($("<option />").val(val.id).text(val.points));
}); });
@ -2571,7 +2570,7 @@
//#region 變更新增設備基本資料modal的過濾條件 //#region 變更新增設備基本資料modal的過濾條件
function ChangeDeviceImportPanel(building_tag, system_tag = "", floor_tag = "") { function ChangeDeviceImportPanel(building_tag, system_tag = "", floor_tag = "") {
if (building_tag == undefined && building_tag == null || building_tag == "") { if (building_tag == undefined && building_tag == null || building_tag == "") {
toast_warning("請先選擇區域"); toast_warning("請先選擇棟別");
return; return;
} }
@ -2734,6 +2733,7 @@
var formData = new FormData(); var formData = new FormData();
formData.append("Building_tag", selectedBuilding_tag);
formData.append("Main_system_tag", selectedMain_system_tag); formData.append("Main_system_tag", selectedMain_system_tag);
formData.append("Sub_system_tag", selectedSub_system_tag); formData.append("Sub_system_tag", selectedSub_system_tag);
formData.append("Floor_tag", selectedFloor_tag); formData.append("Floor_tag", selectedFloor_tag);

View File

@ -139,7 +139,7 @@
</ul> </ul>
</li> </li>
} }
@if (ViewBag.role.Contains("EmergencySettingIndex") @*@if (ViewBag.role.Contains("EmergencySettingIndex")
|| ViewBag.role.Contains("EmergencyGroupingIndex") || ViewBag.role.Contains("EmergencyGroupingIndex")
|| ViewBag.role.Contains("RescueDeviceFireExtinguisher") || ViewBag.role.Contains("RescueDeviceFireExtinguisher")
|| ViewBag.role.Contains("RescueDeviceAED")) || ViewBag.role.Contains("RescueDeviceAED"))
@ -184,7 +184,7 @@
} }
</ul> </ul>
</li> </li>
} }*@
@*@if (ViewBag.role.Contains("EmergencyDeviceMenuIndex") @*@if (ViewBag.role.Contains("EmergencyDeviceMenuIndex")
|| ViewBag.role.Contains("EmergencyContactIndex") || ViewBag.role.Contains("EmergencyContactIndex")

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 2.0 MiB

View File

@ -17,7 +17,7 @@ using System.Linq;
using System.Net; using System.Net;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FrontendWebApi.Controllers namespace FrontendWebApi.ApiControllers
{ {
public class LoginController : Controller public class LoginController : Controller
{ {
@ -45,15 +45,9 @@ namespace FrontendWebApi.Controllers
this.frontendRepository = frontendRepository; this.frontendRepository = frontendRepository;
} }
public IActionResult Index(string jwt)
{
ViewBag.jwt = jwt;
return View();
}
[HttpPost] [HttpPost]
[Route("api/Login")] [Route("api/Login")]
public async Task<ActionResult<ApiResult<TnToken>>> Login(Login login) public async Task<ActionResult<ApiResult<TnToken>>> Login([FromBody] Login login)
{ {
ApiResult<TnToken> apiResult = new ApiResult<TnToken>(null); ApiResult<TnToken> apiResult = new ApiResult<TnToken>(null);
ErrorCode errorCode = new ErrorCode(); ErrorCode errorCode = new ErrorCode();
@ -67,6 +61,7 @@ namespace FrontendWebApi.Controllers
if (User == null) if (User == null)
{ {
apiResult.Code = "9998"; apiResult.Code = "9998";
apiResult.Msg = "查無此帳戶";
return Ok(apiResult); return Ok(apiResult);
} }
JwtLogin jwtLoing = new JwtLogin() JwtLogin jwtLoing = new JwtLogin()
@ -77,6 +72,7 @@ namespace FrontendWebApi.Controllers
userinfo_guid = User.userinfo_guid userinfo_guid = User.userinfo_guid
}; };
apiResult.Code = "0000"; apiResult.Code = "0000";
apiResult.Msg = "登入成功";
apiResult.Data = jwt.GenerateToken(jwtLoing); apiResult.Data = jwt.GenerateToken(jwtLoing);
} }
catch catch
@ -119,15 +115,15 @@ namespace FrontendWebApi.Controllers
{ {
//if (myUser.exp <= DateTime.Now.AddHours(-8).AddMinutes(10).Subtract(new DateTime(1970, 1, 1)).TotalSeconds) //if (myUser.exp <= DateTime.Now.AddHours(-8).AddMinutes(10).Subtract(new DateTime(1970, 1, 1)).TotalSeconds)
//{ //{
//取得當前登入使用者資訊 //取得當前登入使用者資訊
EDFunction edFunction = new EDFunction(); EDFunction edFunction = new EDFunction();
HttpContext.Session.SetString("MyApiAccount", edFunction.AESEncrypt(myUser.account)); //將帳號透過AES加密 HttpContext.Session.SetString("MyApiAccount", edFunction.AESEncrypt(myUser.account)); //將帳號透過AES加密
//} //}
} }
apiResult.Code = "0000"; apiResult.Code = "0000";
} }
catch(Exception exception) catch (Exception exception)
{ {
apiResult.Code = "9999"; apiResult.Code = "9999";
string json = System.Text.Json.JsonSerializer.Serialize(myUser.account); string json = System.Text.Json.JsonSerializer.Serialize(myUser.account);

View File

@ -2,6 +2,7 @@
using FrontendWebApi.Models; using FrontendWebApi.Models;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Repository.BackendRepository.Interface; using Repository.BackendRepository.Interface;
using Repository.BaseRepository.Interface; using Repository.BaseRepository.Interface;
using Repository.FrontendRepository.Interface; using Repository.FrontendRepository.Interface;
@ -38,5 +39,617 @@ namespace FrontendWebApi.ApiControllers
apiResult.Data = myUser; apiResult.Data = myUser;
return apiResult; return apiResult;
} }
/// <summary>
/// 帳號管理列表
/// </summary>
/// <returns></returns>
[HttpPost]
public async Task<ApiResult<List<UserManagerList>>> UserManagerList()
{
ApiResult<List<UserManagerList>> apiResult = new ApiResult<List<UserManagerList>>();
List<UserManagerList> userManagerList = new List<UserManagerList>();
try
{
var sqlString = @$"SELECT A.userinfo_guid, A.full_name, B.full_name AS 'Role_full_name', A.email, A.phone, A.created_at,A.Account ,B.layer
FROM userinfo A
LEFT JOIN role B ON A.role_guid=B.role_guid AND B.deleted='0'
WHERE A.deleted = 0
ORDER BY A.created_at DESC";
userManagerList = await backendRepository.GetAllAsync<UserManagerList>(sqlString);
apiResult.Code = "0000";
apiResult.Data = userManagerList;
}
catch (Exception exception)
{
apiResult.Code = "9999";
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
}
return apiResult;
}
/// <summary>
/// 角色管理列表
/// </summary>
/// <returns></returns>
[HttpPost]
public async Task<ApiResult<List<RoleManagerList>>> RoleManagerList(int post) //是否判斷layer 0:否 1:是
{
ApiResult<List<RoleManagerList>> apiResult = new ApiResult<List<RoleManagerList>>();
List<RoleManagerList> roleList = new List<RoleManagerList>();
try
{
var layersql = "";
if (post == 1)
{
layersql = "and A.layer = 1 ";
}
var sqlString = @$"SELECT *
FROM role A
WHERE A.deleted = 0 {layersql}
ORDER BY A.created_at DESC";
roleList = await backendRepository.GetAllAsync<RoleManagerList>(sqlString);
apiResult.Code = "0000";
apiResult.Data = roleList;
}
catch (Exception exception)
{
apiResult.Code = "9999";
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
}
return apiResult;
}
/// <summary>
/// 新增 / 修改 使用者
/// </summary>
/// <param name="post"></param>
/// <returns></returns>
[HttpPost]
public async Task<ApiResult<string>> SaveUser(SaveUserManager post)
{
ApiResult<string> apiResult = new ApiResult<string>();
UserInfos userInfo = null;
try
{
userInfo = await backendRepository.GetOneAsync<UserInfos>("userinfo", $"userinfo_guid='{post.Id.ToString()}'");
if (userInfo == null)
{
if (post.Id != "0")
{
apiResult.Code = "9998";
apiResult.Msg = "查無該使用者。";
return apiResult;
}
#region 使
//判斷帳號 是否已存在
var exist = await backendRepository.HasExistsWithGuid(post.Account, "userinfo", "account");
if (exist)
{
apiResult.Code = "9986";
apiResult.Msg = "該帳號已被註冊,請重新輸入";
return apiResult;
}
EDFunction edFunction = new EDFunction();
//隨機產生亂數密碼
Random random = new Random((int)DateTime.Now.Ticks);
const string chars = "ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz23456789";
string random_password = new string(Enumerable.Repeat(chars, 8).Select(s => s[random.Next(chars.Length)]).ToArray());
var newPassword = edFunction.GetSHA256Encryption(random_password);
//產生一組GUID
var guid = Guid.NewGuid(); //使用者GUID
Dictionary<string, object> userinfo = new Dictionary<string, object>();
userinfo = new Dictionary<string, object>()
{
{ "@userinfo_guid", guid},
{ "@Full_name", post.Name},
{ "@Email", post.Email},
{ "@Account", post.Account},
{ "@Password", newPassword},
{ "@Role_guid", post.RoleId},
{ "@Phone", post.Phone},
{ "@created_by", myUser.userinfo_guid}
};
await backendRepository.AddOneByCustomTable(userinfo, "userinfo");
var sWhere = "system_type = 'website_config' AND system_key = 'website_url'";
var website_url = await backendRepository.GetOneAsync<Variable>("variable", sWhere);
var sendSubject = "新增帳號成功";
var sendContent = $@"您的新密碼為:{random_password}
<br><a href='{website_url.system_value}' target='_blank'>{website_url.system_value}</a>";
Dictionary<string, object> insertNotify = new Dictionary<string, object>()
{
{ "@task_type", 0},
{ "@recipient_name", post.Name},
{ "@recipient_phone", post.Phone},
{ "@recipient_email", post.Email},
{ "@message_content", sendContent}
};
await backendRepository.AddOneByCustomTable(insertNotify, "background_service_message_notification_task");
apiResult.Code = "0000";
apiResult.Msg = "儲存成功";
#endregion
}
else
{
#region 使
Dictionary<string, object> userinfo = new Dictionary<string, object>();
var role = await backendRepository.GetOneAsync<byte>(@$"select layer from role where role_guid = '{post.RoleId}'");
var infoguid = await backendRepository.GetAllAsync<string>($@"select r.full_name from userinfo u
left join role r on u.role_guid = r.role_guid
where r.layer = 0 and u.userinfo_guid != '{post.Id}'");
if (infoguid.Count == 0 && role == 1)
{
apiResult.Code = "9998";
var getrolename = await backendRepository.GetOneAsync<string>("select r.full_name from role r where r.layer = 0");
apiResult.Msg = getrolename + "-僅剩一位<br>故無法儲存";
}
else
{
userinfo = new Dictionary<string, object>()
{
{ "@Full_name", post.Name},
{ "@Email", post.Email},
{ "@Role_guid", post.RoleId},
{ "@Phone", post.Phone},
{ "@updated_by", myUser.userinfo_guid},
{ "@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}
};
await backendRepository.UpdateOneByCustomTable(userinfo, "userinfo", $"userinfo_guid='{post.Id}'");
apiResult.Code = "0000";
apiResult.Msg = "儲存成功";
}
#endregion
}
}
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="guid"></param>
/// <returns></returns>
[HttpPost]
public async Task<ApiResult<SimpleUser>> GetOneUser(string guid)
{
ApiResult<SimpleUser> apiResult = new ApiResult<SimpleUser>();
SimpleUser simpleUser = null;
try
{
simpleUser = await backendRepository.GetOneAsync<SimpleUser>("userinfo", $"userinfo_guid='{guid}'");
if (simpleUser == null)
{
apiResult.Code = "9998";
apiResult.Msg = "查無該使用者。";
return apiResult;
}
apiResult.Code = "0000";
apiResult.Data = simpleUser;
}
catch (Exception exception)
{
apiResult.Code = "9999";
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
Logger.LogError("【" + controllerName + "/" + actionName + "】" + "Guid=" + guid);
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
}
return apiResult;
}
/// <summary>
/// 軟刪除單一使用者
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpPost]
public async Task<ApiResult<string>> DeleteOneUser(string guid)
{
ApiResult<string> apiResult = new ApiResult<string>();
SimpleUser simpleUser = null;
try
{
simpleUser = await backendRepository.GetOneAsync<SimpleUser>("userinfo", $"userinfo_guid='{guid}'");
if (simpleUser == null)
{
apiResult.Code = "9998";
apiResult.Msg = "查無該使用者。";
return apiResult;
}
await backendRepository.DeleteOne(guid, "userinfo", "userinfo_guid");
apiResult.Code = "0000";
apiResult.Msg = "刪除成功";
}
catch (Exception exception)
{
apiResult.Code = "9999";
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
Logger.LogError("【" + controllerName + "/" + actionName + "】" + "Guid=" + guid);
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
}
return apiResult;
}
/// <summary>
/// 新增 / 修改 角色
/// </summary>
/// <param name="post"></param>
/// <returns></returns>
[HttpPost]
public async Task<ApiResult<string>> SaveRole(PostRole post)
{
ApiResult<string> apiResult = new ApiResult<string>();
RoleManagerList roleManager = null;
try
{
roleManager = await backendRepository.GetOneAsync<RoleManagerList>("role", $"role_guid='{post.Id.ToString()}'");
if (roleManager == null)
{
if (post.Id != "0")
{
apiResult.Code = "9994";
apiResult.Msg = "查無該角色";
return apiResult;
}
#region
//產生一組GUID
var guid = Guid.NewGuid(); //角色GUID
Dictionary<string, object> role = new Dictionary<string, object>();
role = new Dictionary<string, object>()
{
{ "@role_guid", guid},
{ "@Full_name", post.Name},
{ "@created_by", myUser.userinfo_guid}
};
await backendRepository.AddOneByCustomTable(role, "role");
apiResult.Code = "0000";
apiResult.Msg = "儲存成功";
#endregion
}
else
{
#region
Dictionary<string, object> role = new Dictionary<string, object>();
role = new Dictionary<string, object>()
{
{ "@Full_name", post.Name},
{ "@updated_by", myUser.userinfo_guid},
{ "@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}
};
await backendRepository.UpdateOneByCustomTable(role, "role", $"role_guid='{post.Id}'");
apiResult.Code = "0000";
apiResult.Msg = "儲存成功";
#endregion
}
}
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="id"></param>
/// <returns></returns>
[HttpPost]
public async Task<ApiResult<SimpleRole>> GetOneRole(string guid)
{
ApiResult<SimpleRole> apiResult = new ApiResult<SimpleRole>();
SimpleRole simpleRole = null;
try
{
simpleRole = await backendRepository.GetOneAsync<SimpleRole>("role", $"role_guid='{guid}'");
if (simpleRole == null)
{
apiResult.Code = "9994";
apiResult.Msg = "查無該角色";
return apiResult;
}
apiResult.Code = "0000";
apiResult.Data = simpleRole;
}
catch (Exception exception)
{
apiResult.Code = "9999";
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
Logger.LogError("【" + controllerName + "/" + actionName + "】" + "Guid=" + guid);
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
}
return apiResult;
}
/// <summary>
/// 軟刪除單一角色
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpPost]
public async Task<ApiResult<string>> DeleteOneRole(string guid)
{
ApiResult<string> apiResult = new ApiResult<string>();
SimpleRole simpleRole = null;
try
{
simpleRole = await backendRepository.GetOneAsync<SimpleRole>("role", $"role_guid='{guid}'");
if (simpleRole == null)
{
apiResult.Code = "9998";
apiResult.Msg = "查無該角色";
return apiResult;
}
//檢查是否有使用者為該角色
var sWhere = $@"deleted = 0 AND role_guid = @Guid";
var userInfos = await backendRepository.GetAllAsync<UserInfos>("userinfo", sWhere, new { Guid = guid });
if (userInfos.Count > 0)
{
apiResult.Code = "9997";
apiResult.Msg = "帳號管理中尚有帳號正在使用該角色,故無法刪除";
return apiResult;
}
await backendRepository.DeleteOne(guid, "role", "role_guid");
apiResult.Code = "0000";
apiResult.Msg = "刪除成功";
}
catch (Exception exception)
{
apiResult.Code = "9999";
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
Logger.LogError("【" + controllerName + "/" + actionName + "】" + "Guid=" + guid);
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
}
return apiResult;
}
/// <summary>
/// 角色權限管理列表
/// </summary>
/// <returns></returns>
[HttpPost]
public async Task<ApiResult<List<RoleAuthList>>> RoleAuthList(PostRoleAuthFilter post)
{
ApiResult<List<RoleAuthList>> apiResult = new ApiResult<List<RoleAuthList>>();
List<RoleAuthList> roleAuthList = new List<RoleAuthList>();
try
{
var sqlString = @$"SELECT A.role_guid, A.AuthCode, B.full_name AS 'Role_full_name', C.AuthType, C.MainName, C.SubName, D.full_name AS 'Building_full_name', A.created_at
FROM role_auth A
LEFT JOIN role B ON A.role_guid=B.role_guid AND B.deleted=0
INNER JOIN auth_page C ON A.AuthCode=C.AuthCode
LEFT JOIN building D ON C.building_tag=D.building_tag AND D.deleted=0
WHERE A.role_guid='{post.SelectedRoleId}'
ORDER BY A.created_at DESC";
roleAuthList = await backendRepository.GetAllAsync<RoleAuthList>(sqlString);
apiResult.Code = "0000";
apiResult.Data = roleAuthList;
}
catch (Exception exception)
{
apiResult.Code = "9999";
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
}
return apiResult;
}
/// <summary>
/// 取得此角色未選擇的權限
/// </summary>
/// <param name="post"></param>
/// <returns></returns>
public async Task<ApiResult<List<AuthPage>>> GetRoleNotAuthPageList(PostRoleAuthFilter post)
{
ApiResult<List<AuthPage>> apiResult = new ApiResult<List<AuthPage>>();
List<AuthPage> authPage = new List<AuthPage>();
try
{
if (!string.IsNullOrEmpty(post.SelectedRoleId))
{
var buildingGuid = "";
if (post.SelectedBuild != "0")
{
buildingGuid = $" AND ap.building_tag = '{post.SelectedBuild}'";
}
var sqlString = @$" SELECT ap.AuthCode, ap.MainName, ap.SubName FROM auth_page ap
WHERE ap.AuthType='{post.SelectedAuthType}'
{buildingGuid}
AND ap.AuthCode NOT IN (
SELECT ra.AuthCode FROM role_auth ra
LEFT JOIN auth_page ap ON ra.AuthCode = ap.AuthCode
WHERE ra.role_guid = '{post.SelectedRoleId}'
{buildingGuid}
AND ap.AuthType='{post.SelectedAuthType}'
)";
authPage = await backendRepository.GetAllAsync<AuthPage>(sqlString);
}
apiResult.Code = "0000";
apiResult.Data = authPage;
}
catch (Exception exception)
{
apiResult.Code = "9999";
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
}
return apiResult;
}
/// <summary>
/// 新增 權限
/// </summary>
/// <param name="post"></param>
/// <returns></returns>
[HttpPost]
public async Task<ApiResult<string>> SaveRoleAuth(PostSaveRoleAuth post)
{
ApiResult<string> apiResult = new ApiResult<string>();
RoleManagerList roleManager = null;
try
{
roleManager = await backendRepository.GetOneAsync<RoleManagerList>("role", $"role_guid='{post.SelectedRoleId}'");
if (roleManager == null)
{
apiResult.Code = "9994";
apiResult.Msg = "查無該角色";
return apiResult;
}
else
{
if (post.SaveCheckAuth.Count > 0)
{
foreach (var item in post.SaveCheckAuth)
{
#region
Dictionary<string, object> roleAuth = new Dictionary<string, object>();
roleAuth = new Dictionary<string, object>()
{
{ "@role_guid", post.SelectedRoleId},
{ "@AuthCode", item},
{ "@created_by", myUser.userinfo_guid}
};
await backendRepository.AddOneByCustomTable(roleAuth, "role_auth");
#endregion
}
}
apiResult.Code = "0000";
apiResult.Msg = "儲存成功";
}
}
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>> DeleteOneRoleAuth(PostDeleteRoleAuth post)
{
ApiResult<string> apiResult = new ApiResult<string>();
RoleManagerList roleManager = null;
try
{
roleManager = await backendRepository.GetOneAsync<RoleManagerList>("role", $"role_guid='{post.RoleId}'");
if (roleManager == null)
{
apiResult.Code = "9994";
apiResult.Msg = "查無該角色";
return apiResult;
}
await backendRepository.PurgeOneByGuidWithCustomDBNameAndTable("role_auth", $"role_guid='{post.RoleId}' AND AuthCode='{post.AuthCode}'");
apiResult.Code = "0000";
apiResult.Msg = "刪除成功";
}
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;
}
} }
} }

View File

@ -1,232 +0,0 @@
using FrontendWebApi.Models;
using iTextSharp.text;
using iTextSharp.text.html.simpleparser;
using iTextSharp.text.pdf;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using Repository.BackendRepository.Interface;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace FrontendWebApi.Controllers
{
public class EmergencyContactController : MyBaseController<EmergencyContactController>
{
private readonly IBackendRepository backendRepository;
public EmergencyContactController(IBackendRepository backendRepository)
{
this.backendRepository = backendRepository;
}
public IActionResult Index()
{
return View();
}
[HttpPost]
public async Task<ActionResult> EmergencyContactTable (List<int> selectgroupidlist)
{
List<EmergencyContactTable> Emergency_member_tables = new List<EmergencyContactTable>();
ApiResult<List<EmergencyContactTable>> apiResult = new ApiResult<List<EmergencyContactTable>>();
try
{
Emergency_member_tables = await backendRepository.GetAllAsync<EmergencyContactTable>($@"
select v.system_key groupingName,va.system_key departmentName,* from emergency_member em left join variable v on em.grouping = v.id
left join (select * from variable vs where vs.system_type = 'department' and vs.deleted = 0) va on va.system_value = em.department
where em.grouping in @groupinglist and em.deleted = 0",new { groupinglist = selectgroupidlist });
apiResult.Code = "0000";
apiResult.Data = Emergency_member_tables;
}
catch (Exception exception)
{
apiResult.Code = "9999";
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
Logger.LogError("【" + controllerName + "/" + actionName + "】");
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
}
var result = Json(new
{
data = apiResult
});
return result;
}
public FileResult ExportPDF(string post)
{
var grouping = JsonConvert.DeserializeObject<export>(post);
var stream = new MemoryStream();
try
{
var Emergency_member_tables = backendRepository.GetAllAsync<EmergencyContactTable>($@"
select v.system_key groupingName,va.system_key departmentName,* from emergency_member em left join variable v on em.grouping = v.id
left join (select * from variable vs where vs.system_type = 'department' and vs.deleted = 0) va on va.system_value = em.department
where em.grouping in @groupinglist and em.deleted = 0", new { groupinglist = grouping.groupidlist });
using (var doc = new Document())
{
using (var writer = PdfWriter.GetInstance(doc, stream))
{
writer.CloseStream = false;
BaseFont BaseF = BaseFont.CreateFont("C:\\Windows\\Fonts\\kaiu.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font fontCh = new Font(BaseF, 14);
doc.Open();
PdfPTable table = new PdfPTable(new float[] { 1, 1, 1, 1, 1 ,1 });
table.TotalWidth = 480f;
table.LockedWidth = true;
PdfPCell header = new PdfPCell(new Phrase(grouping.disaster+"-聯絡清單", fontCh));
header.Colspan = 6;
table.AddCell(header);
table.AddCell(new Phrase("組別", fontCh));
table.AddCell(new Phrase("姓名", fontCh));
table.AddCell(new Phrase("部門", fontCh));
table.AddCell(new Phrase("電話", fontCh));
table.AddCell(new Phrase("LINE ID", fontCh));
table.AddCell(new Phrase("電子信箱", fontCh));
foreach(var group in Emergency_member_tables.Result)
{
table.AddCell(new Phrase(group.groupingName, fontCh));
table.AddCell(new Phrase(group.full_name, fontCh));
table.AddCell(new Phrase(group.departmentName, fontCh));
table.AddCell(new Phrase(group.phone, fontCh));
table.AddCell(new Phrase(group.lineid, fontCh));
table.AddCell(new Phrase(group.email, fontCh));
}
doc.Add(table);
doc.Close();
}
}
var bytes = stream.ToArray();
stream.Position = 0;
}
catch (Exception exception)
{
Logger.LogError("【" + controllerName + "/" + actionName + "】");
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
}
return File(stream, "application/pdf", grouping.disaster+"-聯絡清單.pdf");
}
public FileResult ExportExcel(string post)
{
var grouping = JsonConvert.DeserializeObject<export>(post);
var workbook = new XSSFWorkbook();
var ms = new NpoiMemoryStream
{
AllowClose = false
};
#region excel設定
IFont font12 = workbook.CreateFont();
font12.FontName = "新細明體";
font12.FontHeightInPoints = 12;
ICellStyle style12 = workbook.CreateCellStyle();
style12.SetFont(font12);
style12.Alignment = HorizontalAlignment.Center;
style12.VerticalAlignment = VerticalAlignment.Center;
IFont font12Times = workbook.CreateFont();
font12Times.FontName = "Times New Roman";
font12Times.FontHeightInPoints = 12;
IFont font18 = workbook.CreateFont();
font18.FontName = "新細明體";
font18.FontHeightInPoints = 18;
font18.IsBold = true;
ICellStyle styleTitle18 = workbook.CreateCellStyle();
styleTitle18.SetFont(font18);
styleTitle18.Alignment = HorizontalAlignment.Center;
styleTitle18.VerticalAlignment = VerticalAlignment.Center;
ICellStyle styleLeft12 = workbook.CreateCellStyle();
styleLeft12.SetFont(font12);
styleLeft12.Alignment = HorizontalAlignment.Left;
styleLeft12.VerticalAlignment = VerticalAlignment.Center;
ICellStyle styleLine12 = workbook.CreateCellStyle();
styleLine12.SetFont(font12);
styleLine12.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
styleLine12.VerticalAlignment = VerticalAlignment.Center;
styleLine12.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
styleLine12.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
styleLine12.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
styleLine12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
ICellStyle stylein12 = workbook.CreateCellStyle();
stylein12.SetFont(font12Times);
stylein12.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
stylein12.VerticalAlignment = VerticalAlignment.Center;
stylein12.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
stylein12.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
stylein12.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
stylein12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
stylein12.WrapText = true;
#endregion
try
{
var Emergency_member_tables = backendRepository.GetAllAsync<EmergencyContactTable>($@"
select v.system_key groupingName,va.system_key departmentName,* from emergency_member em left join variable v on em.grouping = v.id
left join (select * from variable vs where vs.system_type = 'department' and vs.deleted = 0) va on va.system_value = em.department
where em.grouping in @groupinglist and em.deleted = 0", new { groupinglist = grouping.groupidlist }).Result;
var sheet = workbook.CreateSheet(grouping.disaster+"-聯絡清單");
int RowPosition = 0;
IRow row = sheet.CreateRow(RowPosition);
sheet.SetColumnWidth(0, 4 * 160 * 6);
sheet.SetColumnWidth(1, 4 * 160 * 6);
sheet.SetColumnWidth(2, 4 * 160 * 6);
sheet.SetColumnWidth(3, 4 * 160 * 6);
sheet.SetColumnWidth(4, 4 * 160 * 6);
sheet.SetColumnWidth(5, 4 * 160 * 6);
ICell cell = row.CreateCell(0);
cell.SetCellValue("組別");
cell.CellStyle = styleLine12;
cell = row.CreateCell(1);
cell.SetCellValue("姓名");
cell.CellStyle = styleLine12;
cell = row.CreateCell(2);
cell.SetCellValue("部門");
cell.CellStyle = styleLine12;
cell = row.CreateCell(3);
cell.SetCellValue("電話");
cell.CellStyle = styleLine12;
cell = row.CreateCell(4);
cell.SetCellValue("LINE ID");
cell.CellStyle = styleLine12;
cell = row.CreateCell(5);
cell.SetCellValue("電子信箱");
cell.CellStyle = styleLine12;
foreach (var group in Emergency_member_tables)
{
RowPosition += 1;
row = sheet.CreateRow(RowPosition);
cell = row.CreateCell(0);
cell.SetCellValue(group.groupingName);
cell.CellStyle = style12;
cell = row.CreateCell(1);
cell.SetCellValue(group.full_name);
cell.CellStyle = style12;
cell = row.CreateCell(2);
cell.SetCellValue(group.departmentName);
cell.CellStyle = style12;
cell = row.CreateCell(3);
cell.SetCellValue(group.phone);
cell.CellStyle = style12;
cell = row.CreateCell(4);
cell.SetCellValue(group.lineid);
cell.CellStyle = style12;
cell = row.CreateCell(5);
cell.SetCellValue(group.email);
cell.CellStyle = style12;
}
workbook.Write(ms);
ms.Flush();
ms.Seek(0, SeekOrigin.Begin);
}
catch(Exception exception)
{
Logger.LogError("【" + controllerName + "/" + actionName + "】");
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
}
return File(ms, "application/vnd.ms-excel", grouping.disaster + "-聯絡清單.xlsx");
}
}
}

View File

@ -1,24 +0,0 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace FrontendWebApi.Controllers
{
public class EmergencyDeviceMenuController : MyBaseController<EmergencyDeviceMenuController>
{
private readonly ILogger<EmergencyDeviceMenuController> _logger;
public EmergencyDeviceMenuController(ILogger<EmergencyDeviceMenuController> logger)
{
_logger = logger;
}
public IActionResult Index()
{
return View();
}
}
}

View File

@ -1,142 +0,0 @@
using FrontendWebApi.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Repository.BackendRepository.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace FrontendWebApi.Controllers
{
public class EmergencyRecordController : MyBaseController<EmergencyRecordController>
{
private readonly IBackendRepository backendRepository;
public EmergencyRecordController(IBackendRepository backendRepository)
{
this.backendRepository = backendRepository;
}
public IActionResult Index()
{
return View();
}
[HttpPost]
public async Task<ApiResult<List<KeyValue>>> DisasterList()
{
ApiResult<List<KeyValue>> apiResult = new ApiResult<List<KeyValue>>();
List<KeyValue> Variable = new List<KeyValue>();
try
{
var sqlString = @$"select system_value as Value, system_key as Name from variable a where a.system_type = 'disaster' and a.deleted = 0";
Variable = await backendRepository.GetAllAsync<KeyValue>(sqlString);
apiResult.Code = "0000";
apiResult.Data = Variable;
}
catch (Exception exception)
{
apiResult.Code = "9999";
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
}
return apiResult;
}
[HttpPost]
public async Task<ApiResult<List<KeyValue>>> BuildInfoList()
{
ApiResult<List<KeyValue>> apiResult = new ApiResult<List<KeyValue>>();
List<KeyValue> KeyValue = new List<KeyValue>();
try
{
var sqlString = @$"select building_guid as Value, full_name as Name from building a where a.deleted = 0 and a.status = 0 ORDER BY A.priority ASC, A.created_at DESC";
KeyValue = await backendRepository.GetAllAsync<KeyValue>(sqlString);
apiResult.Code = "0000";
apiResult.Data = KeyValue;
}
catch (Exception exception)
{
apiResult.Code = "9999";
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
}
return apiResult;
}
[HttpPost]
public async Task<ActionResult> EmergencyRecordTable(EmergencyRecordEventPost post)
{
List<EmergencyRecordEventTable> EmergencyRecordEvent = new List<EmergencyRecordEventTable>();
ApiResult<List<EmergencyRecordEventTable>> apiResult = new ApiResult<List<EmergencyRecordEventTable>>();
try
{
var sqlplus = "";
if(post.selectaType != 2 )
{
sqlplus = $"and ee.type = '{post.selectaType}'";
}
if (post.dateranger != null)
{
var date = post.dateranger.Replace(" ", "").Split("-");
sqlplus += $"and ee.created_at between '{date[0].Replace(" / ", " - ")} 00:00:00' and '{date[1].Replace(" / ", " - ")} 23:59:59'";
}
EmergencyRecordEvent = await backendRepository.GetAllAsync<EmergencyRecordEventTable>($@"
select d.device_number device_name,v.system_key disaster_name,ee.*,b.full_name building_name from emergency_event ee
left join (select * from variable v where v.system_type = 'disaster') v on v.system_value = ee.disaster
left join device d on d.device_guid = ee.device_guid
left join building b on b.building_guid = ee.building_guid
where ee.deleted = 0 and ee.building_guid = '{post.selectaBuild}' and ee.disaster = '{post.selectaDisaster}' {sqlplus}
");
apiResult.Code = "0000";
apiResult.Data = EmergencyRecordEvent;
}
catch (Exception exception)
{
apiResult.Code = "9999";
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
Logger.LogError("【" + controllerName + "/" + actionName + "】");
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
}
var result = Json(new
{
data = apiResult
});
return result;
}
[HttpPost]
public async Task<ActionResult> EmergencyItemTable(string event_guid)
{
List<EmergencyRecordItem> EmergencyRecordEvent = new List<EmergencyRecordItem>();
ApiResult<List<EmergencyRecordItem>> apiResult = new ApiResult<List<EmergencyRecordItem>>();
try
{
EmergencyRecordEvent = await backendRepository.GetAllAsync<EmergencyRecordItem>($@"
select * from emergency_item where event_guid = '{event_guid}' order by created_at desc
");
apiResult.Code = "0000";
apiResult.Data = EmergencyRecordEvent;
}
catch (Exception exception)
{
apiResult.Code = "9999";
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
Logger.LogError("【" + controllerName + "/" + actionName + "】");
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
}
var result = Json(new
{
data = apiResult
});
return result;
}
}
}

View File

@ -1,25 +0,0 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace FrontendWebApi.Controllers
{
public class HomeController : MyBaseController<HomeController>
{
private readonly ILogger<HomeController> _logger;
public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}
public IActionResult Index()
{
return View();
}
}
}

View File

@ -1,167 +0,0 @@
using FrontendWebApi.Jwt;
using FrontendWebApi.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Configuration;
using Repository.BackendRepository.Interface;
using Repository.BaseRepository.Interface;
using Repository.FrontendRepository.Interface;
using Repository.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.Routing;
using System.Diagnostics;
namespace FrontendWebApi.Controllers
{
public class MyBaseController<T> : Controller where T : MyBaseController<T>
{
private ILogger<T> _logger;
protected ILogger<T> Logger => _logger ?? (_logger = HttpContext?.RequestServices.GetService<ILogger<T>>());
private IJwtHelpers jwt => HttpContext?.RequestServices.GetService<IJwtHelpers>();
private IFrontendRepository frontendRepository => HttpContext?.RequestServices.GetService<IFrontendRepository>();
public MyBaseController() { }
protected MyUserInfo myUserInfo = null;
protected JwtGet myUser;
protected string jwt_str = null;
protected bool jwtlife = true;
public string controllerName;
public string actionName;
public ErrorCode errorCode = new ErrorCode();
[Authorize]
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
EDFunction edFunction = new EDFunction();
var myAccount = edFunction.AESDecrypt(HttpContext.Session.GetString("MyApiAccount"));
controllerName = ControllerContext.RouteData.Values["controller"].ToString(); //controller名稱
actionName = ControllerContext.RouteData.Values["action"].ToString(); //action名稱
//紀錄當前PID
Process currentProcess = Process.GetCurrentProcess();
Dictionary<string, object> updateProcess = new Dictionary<string, object>();
updateProcess.Add("@system_value", currentProcess.Id.ToString());
frontendRepository.UpdateProcessPID(updateProcess, "variable", "system_type = 'watchDogCongfig' AND system_key = 'AlarmPID'");
bool isAjaxCall = filterContext.HttpContext.Request.Headers["x-requested-with"] == "XMLHttpRequest";
if (string.IsNullOrEmpty(myAccount))
{
if (isAjaxCall)
{
filterContext.HttpContext.Response.Clear();
filterContext.HttpContext.Response.StatusCode = 499;
return;
}
else
{
filterContext.Result = new RedirectToRouteResult(
new RouteValueDictionary
{
{"controller", "Login"},
{"action", "Index"}
});
return;
}
}
else
{
//取得當前登入使用者資訊
myUserInfo = frontendRepository.GetMyUserInfoByAccount<MyUserInfo>(myAccount);
var showview = frontendRepository.GetAllAsync<string>($@"select ap.ShowView from userinfo us
left join role_auth ra on ra.role_guid = us.role_guid
left join auth_page ap on ap.AuthCode = ra.AuthCode
where us.userinfo_guid = '{myUserInfo.Userinfo_guid}'");
myUserInfo.ShowView = showview.Result;
ViewBag.myUserInfo = myUserInfo;
ViewBag.role = showview.Result;
//var showviewt = new List<string>()
// {
// "EmergencyDeviceMenuIndex",
// "EmergencyContactIndex",
// "EmergencyRecordIndex",
// "RescueDeviceFireExtinguisher",
// "RescueDeviceAED",
// };
//ViewBag.role = showviewt;
}
//var ctx = filterContext.HttpContext;
//ctx.Response.Headers.Add("Access-Control-Allow-Origin", "*");
//ctx.Response.Headers.Add("Access-Control-Allow-Headers", "*");
//ctx.Response.Headers.Add("Access-Control-Allow-Credentials", "true");
//var a = User.Claims.Select(p => new { Type = p.Type, Value = p.Value }).ToList();
//myUser = new JwtGet()
//{
// account = User.Claims.Where(a => a.Type == "account").Select(e => e.Value).FirstOrDefault(),
// email = User.Claims.Where(a => a.Type == "email").Select(e => e.Value).FirstOrDefault(),
// full_name = User.Claims.Where(a => a.Type == "full_name").Select(e => e.Value).FirstOrDefault(),
// exp = User.Claims.Where(a => a.Type == "exp").Select(e => Convert.ToInt32(e.Value)).FirstOrDefault(),
// nbf = User.Claims.Where(a => a.Type == "nbf").Select(e => Convert.ToInt32(e.Value)).FirstOrDefault(),
// userinfo_guid = User.Claims.Where(a => a.Type == "userinfo_guid").Select(e => e.Value).FirstOrDefault(),
//};
//TODO 模擬JWT記得刪除
//myUser.account = "Bajascript";
//myUser.email = "asd@com";
//myUser.full_name = "野原廣志";
//myUser.exp = 3600;
//myUser.userinfo_guid = "1EF9CEAC-4DBF-E2BE-8B1D-CB3014E0DA17";
//if (myUser.exp == 0)
//{
// jwt_str = "Jwt Token不合法";
// jwtlife = false;
// ViewBag.myUserInfo = null;
// ViewBag.role = null;
//}
//else
//{
// if (myUser.exp <= DateTime.Now.AddHours(-8).AddMinutes(10).Subtract(new DateTime(1970, 1, 1)).TotalSeconds)
// {
// //取得當前登入使用者資訊
// myUserInfo = frontendRepository.GetMyUserInfoByAccount<MyUserInfo>(myUser.account);
// //var showview = frontendRepository.GetAllAsync<string>($@"select ap.ShowView from userinfo us
// // left join role_auth ra on ra.role_guid = us.role_guid
// // left join auth_page ap on ap.AuthCode = ra.AuthCode
// // where us.userinfo_guid = '{myUserInfo.Userinfo_guid}'");
// //myUserInfo.ShowView = showview.Result;
// ViewBag.myUserInfo = myUserInfo;
// var showviewt = new List<string>()
// {
// "EmergencyDeviceMenuIndex",
// "EmergencyContactIndex",
// "EmergencyRecordIndex",
// "RescueDeviceFireExtinguisher",
// "RescueDeviceAED",
// };
// //ViewBag.role = showview.Result;
// ViewBag.role = showviewt;
// jwtlife = true;
// JwtLogin jwtLoing = new JwtLogin()
// {
// account = myUser.account,
// email = myUser.email,
// full_name = myUser.full_name,
// userinfo_guid = myUser.userinfo_guid
// };
// jwt_str = jwt.GenerateToken(jwtLoing).token;
// }
//}
base.OnActionExecuting(filterContext);
}
}
}

View File

@ -1,34 +0,0 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using Repository.BackendRepository.Interface;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace FrontendWebApi.Controllers
{
public class RescueDeviceController : MyBaseController<RescueDeviceController>
{
private readonly IBackendRepository backendRepository;
public RescueDeviceController(IBackendRepository backendRepository)
{
this.backendRepository = backendRepository;
}
public IActionResult FireExtinguisher()
{
return View();
}
public IActionResult AED()
{
return View();
}
}
}

View File

@ -24,6 +24,7 @@ namespace FrontendWebApi.Models
/// </summary> /// </summary>
public string Password { get; set; } public string Password { get; set; }
} }
public class JwtLogin public class JwtLogin
{ {
public string userinfo_guid { get; set; } public string userinfo_guid { get; set; }
@ -31,6 +32,7 @@ namespace FrontendWebApi.Models
public string full_name { get; set; } public string full_name { get; set; }
public string email { get; set; } public string email { get; set; }
} }
public class JwtGet : JwtLogin public class JwtGet : JwtLogin
{ {
public int nbf { get; set; } public int nbf { get; set; }

View File

@ -45,4 +45,11 @@ namespace FrontendWebApi.Models
{ {
public int id { get; set; } public int id { get; set; }
} }
public class Variable : Actor
{
public string System_type { get; set; }
public string System_key { get; set; }
public string system_value { get; set; }
}
} }

View File

@ -15,10 +15,159 @@ namespace FrontendWebApi.Models
public string phone { get; set; } public string phone { get; set; }
public string tel { get; set; } public string tel { get; set; }
public string email { get; set; } public string email { get; set; }
public List<string> ShowView { get; set; }
} }
public class Login public class Login
{ {
public string account { get; set; } public string account { get; set; }
//public string password { get; set; } public string password { get; set; }
}
public enum UserStatusEnum : byte
{
Suspend = 0, //停權
Normal = 1, //正常
}
public class UserInfos : Actor
{
public string Userinfo_guid { get; set; }
public byte Deleted { get; set; } //是否刪除
public byte Status { get; set; } //狀態
public string StatusText //狀態文字
{
get
{
Dictionary<int, string> pairs = new Dictionary<int, string>()
{
{ 0, "停權"},
{ 1, "正常"},
};
return pairs[Status];
}
}
public string Role_guid { get; set; } //角色guid
public string Full_name { get; set; } //姓名
public string Account { get; set; } //帳號
public string Password { get; set; } //密碼
public string Tel { get; set; } //市話
public string Phone { get; set; } //手機
public string Email { get; set; } //信箱
}
public class UserManagerList : Actor
{
public string Userinfo_guid { get; set; }
public string Full_name { get; set; } //姓名
public string Role_full_name { get; set; } //角色名稱
public string Email { get; set; } //信箱
public string Phone { get; set; } //手機
public string Account { get; set; }
public byte Layer { get; set; }
}
public class RoleManagerList : Actor
{
public string Role_guid { get; set; }
public string Full_name { get; set; } //姓名
public byte Layer { get; set; }
}
public class SaveUserManager
{
public string Id { get; set; }
public string Name { get; set; } //姓名
public string Email { get; set; } //信箱
public string Account { get; set; } //帳號
public string Phone { get; set; } //手機號碼
public string RoleId { get; set; } //角色GUID
}
public class SimpleUser
{
public string Full_name { get; set; } //姓名
public string Account { get; set; } //帳號
public string Email { get; set; } //信箱
public string Phone { get; set; } //手機
public string Role_guid { get; set; } //角色GUID
}
public class PostRole
{
public string Id { get; set; }
public string Name { get; set; }
}
public class SimpleRole
{
public string Full_name { get; set; } //姓名
}
public class RoleAuthList : Actor
{
public string Role_guid { get; set; } //角色GUID
public string AuthCode { get; set; } //權限代碼
public string Role_full_name { get; set; } //角色名稱
public int AuthType { get; set; } //角色類型 1:前台 2:後台
public string AuthTypeText //角色類型文字
{
get
{
Dictionary<int, string> pairs = new Dictionary<int, string>()
{
{ 1, "前台"},
{ 2, "後台"},
};
return pairs[AuthType];
}
}
public string MainName { get; set; } //大項名稱
public string SubName { get; set; } //功能名稱
public string Building_full_name { get; set; } //區域名稱
}
public class PostRoleAuthFilter
{
public string SelectedRoleId { get; set; }
public string SelectedAuthType { get; set; }
public string SelectedBuild { get; set; }
}
public class AuthPage
{
public string AuthCode { get; set; }
public string MainName { get; set; }
public string SubName { get; set; }
}
public class PostSaveRoleAuth
{
public string SelectedRoleId { get; set; }
public List<string> SaveCheckAuth { get; set; }
//public FrontEndCheckAuth BackEndCheckAuth { get; set; }
}
public class PostDeleteRoleAuth
{
public string RoleId { get; set; }
public string AuthCode { get; set; }
}
//public class FrontEndCheckAuth
//{
// public string Building { get; set; }
// public List<string> SelectedAuth { get; set; }
//}
public class Auth_page
{
public string AuthCode { get; set; }
public byte AuthType { get; set; }
public string MainName { get; set; }
public string SubName { get; set; }
public string building_guid { get; set; }
public string ShowView { get; set; }
public string created_at { get; set; }
} }
} }

View File

@ -1,12 +1,10 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16 # Visual Studio Version 17
VisualStudioVersion = 16.0.31702.278 VisualStudioVersion = 17.3.32929.385
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FrontendWebApi", "FrontendWebApi\FrontendWebApi.csproj", "{E70B0F92-8E08-4BD5-9CEC-95A2ABC5071F}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FrontendWebApi", "FrontendWebApi\FrontendWebApi.csproj", "{E70B0F92-8E08-4BD5-9CEC-95A2ABC5071F}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Frontend", "Frontend\Frontend.csproj", "{4B65CA2A-AB4B-4113-B0E8-486828B07506}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Repository", "Repository\Repository.csproj", "{AE535279-C120-4DC7-AC07-5DB3C618F58C}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Repository", "Repository\Repository.csproj", "{AE535279-C120-4DC7-AC07-5DB3C618F58C}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Backend", "Backend\Backend.csproj", "{C0B93B4D-F0AF-4C80-ABF9-5C984425749C}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Backend", "Backend\Backend.csproj", "{C0B93B4D-F0AF-4C80-ABF9-5C984425749C}"
@ -15,10 +13,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BackendWorkerService", "Bac
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "z01_WinAPP", "z01_WinAPP\z01_WinAPP.csproj", "{28AC1ECB-436F-4AB8-91A0-1DC9A33708B2}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "z01_WinAPP", "z01_WinAPP\z01_WinAPP.csproj", "{28AC1ECB-436F-4AB8-91A0-1DC9A33708B2}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FrontendWorkerService", "FrontendWorkerService\FrontendWorkerService.csproj", "{7B02C712-3283-4948-8713-E341D61FF532}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AlarmMonitorWorkerService", "AlarmMonitorWorkerService\AlarmMonitorWorkerService.csproj", "{24404D5B-C372-41E1-A454-757A06E73CE9}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -29,10 +23,6 @@ Global
{E70B0F92-8E08-4BD5-9CEC-95A2ABC5071F}.Debug|Any CPU.Build.0 = Debug|Any CPU {E70B0F92-8E08-4BD5-9CEC-95A2ABC5071F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E70B0F92-8E08-4BD5-9CEC-95A2ABC5071F}.Release|Any CPU.ActiveCfg = Release|Any CPU {E70B0F92-8E08-4BD5-9CEC-95A2ABC5071F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E70B0F92-8E08-4BD5-9CEC-95A2ABC5071F}.Release|Any CPU.Build.0 = Release|Any CPU {E70B0F92-8E08-4BD5-9CEC-95A2ABC5071F}.Release|Any CPU.Build.0 = Release|Any CPU
{4B65CA2A-AB4B-4113-B0E8-486828B07506}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4B65CA2A-AB4B-4113-B0E8-486828B07506}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4B65CA2A-AB4B-4113-B0E8-486828B07506}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4B65CA2A-AB4B-4113-B0E8-486828B07506}.Release|Any CPU.Build.0 = Release|Any CPU
{AE535279-C120-4DC7-AC07-5DB3C618F58C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {AE535279-C120-4DC7-AC07-5DB3C618F58C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AE535279-C120-4DC7-AC07-5DB3C618F58C}.Debug|Any CPU.Build.0 = Debug|Any CPU {AE535279-C120-4DC7-AC07-5DB3C618F58C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AE535279-C120-4DC7-AC07-5DB3C618F58C}.Release|Any CPU.ActiveCfg = Release|Any CPU {AE535279-C120-4DC7-AC07-5DB3C618F58C}.Release|Any CPU.ActiveCfg = Release|Any CPU
@ -49,14 +39,6 @@ Global
{28AC1ECB-436F-4AB8-91A0-1DC9A33708B2}.Debug|Any CPU.Build.0 = Debug|Any CPU {28AC1ECB-436F-4AB8-91A0-1DC9A33708B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{28AC1ECB-436F-4AB8-91A0-1DC9A33708B2}.Release|Any CPU.ActiveCfg = Release|Any CPU {28AC1ECB-436F-4AB8-91A0-1DC9A33708B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{28AC1ECB-436F-4AB8-91A0-1DC9A33708B2}.Release|Any CPU.Build.0 = Release|Any CPU {28AC1ECB-436F-4AB8-91A0-1DC9A33708B2}.Release|Any CPU.Build.0 = Release|Any CPU
{7B02C712-3283-4948-8713-E341D61FF532}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7B02C712-3283-4948-8713-E341D61FF532}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7B02C712-3283-4948-8713-E341D61FF532}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7B02C712-3283-4948-8713-E341D61FF532}.Release|Any CPU.Build.0 = Release|Any CPU
{24404D5B-C372-41E1-A454-757A06E73CE9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{24404D5B-C372-41E1-A454-757A06E73CE9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{24404D5B-C372-41E1-A454-757A06E73CE9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{24404D5B-C372-41E1-A454-757A06E73CE9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -30,7 +30,7 @@ namespace tpDomeWinAPP.Service
{ {
bool result = false; bool result = false;
//tag //tag
InsertNiagaraTagList(dt, building); insertNiagaraTagList(dt, building);
insertItemFromNiagara(dt, building); insertItemFromNiagara(dt, building);
deviceComparison(); deviceComparison();
deviceItemComparison(); deviceItemComparison();
@ -39,7 +39,7 @@ namespace tpDomeWinAPP.Service
return result; return result;
} }
protected void InsertNiagaraTagList(List<device_value2> dt, string building) protected void insertNiagaraTagList(List<device_value2> dt, string building)
{ {
var ds2 = dt.GroupBy(x => new var ds2 = dt.GroupBy(x => new
{ {
@ -209,6 +209,7 @@ namespace tpDomeWinAPP.Service
conn.Open(); conn.Open();
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
StringBuilder sb2 = new StringBuilder();
sb.Append($@" SELECT m.* sb.Append($@" SELECT m.*
FROM import_niagara_tag m FROM import_niagara_tag m
LEFT JOIN device d LEFT JOIN device d
@ -237,11 +238,19 @@ namespace tpDomeWinAPP.Service
data.device_serial_tag + "', '" + data.device_serial_tag + "', '" +
data.niagara_tags + "', '" + data.niagara_tags + "', '" +
data.device_system_tag + "', now(), now() );"); data.device_system_tag + "', now(), now() );");
sb2.Append($@"INSERT device_kind (device_kind_guid, device_building_tag, device_system_tag, device_name_tag,
device_normal_flashing, device_close_flashing, device_error_flashing, device_error_independent,
created_by, created_at)
VALUES (uuid(), '" + data.device_building_tag + "', '" + data.device_system_tag + "', '" + data.device_name_tag +
"', 0, 0, 1, 0, 'B43E3CA7-96DD-4FC7-B6E6-974ACC3B0878', now());");
} }
if(sb.Length > 0) if(sb.Length > 0)
{ {
conn.Execute(sb.ToString()); conn.Execute(sb.ToString());
conn.Execute(sb2.ToString());
sb.Clear(); sb.Clear();
sb2.Clear();
} }
} }