[後端] 修改前台 緊急使用api

This commit is contained in:
dev02 2023-05-19 11:18:38 +08:00
parent 9e33f4c368
commit 1ce1e8400b
8 changed files with 40 additions and 425 deletions

View File

@ -90,7 +90,7 @@ namespace FrontendWebApi.ApiControllers
try try
{ {
Emergency_member_tables = await backendRepository.GetAllAsync<EmergencyContactTable>($@" 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 select v.system_key groupingName,va.system_key departmentName, em.* 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 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 }); where em.grouping in @groupinglist and em.deleted = 0", new { groupinglist = selectgroupidlist });
apiResult.Code = "0000"; apiResult.Code = "0000";
@ -120,7 +120,7 @@ namespace FrontendWebApi.ApiControllers
try try
{ {
var Emergency_member_tables = await backendRepository.GetAllAsync<EmergencyContactTable>($@" var 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 select v.system_key groupingName,va.system_key departmentName, em.* 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 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 = post.groupidlist }); where em.grouping in @groupinglist and em.deleted = 0", new { groupinglist = post.groupidlist });
using (var doc = new Document()) using (var doc = new Document())
@ -236,7 +236,7 @@ namespace FrontendWebApi.ApiControllers
try try
{ {
var Emergency_member_tables = await backendRepository.GetAllAsync<EmergencyContactTable>($@" var 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 select v.system_key groupingName,va.system_key departmentName, em.* 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 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 = post.groupidlist }); where em.grouping in @groupinglist and em.deleted = 0", new { groupinglist = post.groupidlist });
var sheet = workbook.CreateSheet(post.disaster + "-聯絡清單"); var sheet = workbook.CreateSheet(post.disaster + "-聯絡清單");

View File

@ -125,7 +125,7 @@ namespace FrontendWebApi.ApiControllers
d.device_guid, d.device_guid,
d.device_number, d.device_number,
d.full_name AS device_name, d.full_name AS device_name,
d.building_guid, d.device_building_tag,
b.full_name AS building_name, b.full_name AS building_name,
CONCAT(b.ip_address , ':', b.ip_port) AS ip_address, CONCAT(b.ip_address , ':', b.ip_port) AS ip_address,
v.layer2, v.layer2,
@ -137,27 +137,27 @@ namespace FrontendWebApi.ApiControllers
floor.full_name floorname, floor.full_name floorname,
floor.floor_guid floorguid floor.floor_guid floorguid
from from
(SELECT * (SELECT *
FROM device d FROM device d
WHERE d.deleted = 0 WHERE d.deleted = 0
AND d.building_guid = '{selectdevice.selectbuilding}' AND d.device_building_tag = '{selectdevice.selectbuilding}'
AND d.floor_guid in @floor AND d.device_floor_tag in @floor
AND d.device_system_category_layer3 IN @layer3) d AND d.device_name_tag IN @layer3) d
left join floor on floor.floor_guid = d.floor_guid left join floor on floor.full_name = d.device_floor_tag and floor.building_tag = d.device_building_tag
left join ( left join (
SELECT SELECT
v.*, v.*,
v2.system_key AS layer2_name, v2.system_key AS layer2_name,
v2.system_value AS layer2 v2.system_value AS layer2
FROM ( FROM (
select * select *
from variable v from variable v
where v.system_type = 'device_system_category_layer3') v where v.system_type = 'device_system_category_layer3') v
LEFT JOIN variable v2 ON v2.deleted = 0 AND v.system_parent_id = v2.id LEFT JOIN variable v2 ON v2.deleted = 0 AND v.system_parent_id = v2.id
) v on v.system_value = d.device_system_category_layer3 ) v on v.system_value = d.device_system_category_layer3
left join device_disaster dd on dd.device_guid = d.device_guid left join device_disaster dd on dd.device_guid = d.device_guid
left join (select * from variable v where v.system_type = 'disaster') ddd on ddd.system_value = dd.device_system_value left join (select * from variable v where v.system_type = 'disaster') ddd on ddd.system_value = dd.device_system_value
LEFT JOIN building b ON b.deleted = 0 AND d.building_guid = b.building_guid LEFT JOIN building b ON b.deleted = 0 AND d.device_building_tag = b.building_tag
where dd.device_system_value IN @disasters where dd.device_system_value IN @disasters
ORDER BY d.device_number ORDER BY d.device_number
"; ";
@ -451,7 +451,7 @@ namespace FrontendWebApi.ApiControllers
try try
{ {
Emergency_member_tables = await backendRepository.GetAllAsync<EmergencyContactTable>($@" 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 select v.system_key groupingName,va.system_key departmentName, em.* 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 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 }); where em.grouping in @groupinglist and em.deleted = 0", new { groupinglist = selectgroupidlist });
apiResult.Code = "0000"; apiResult.Code = "0000";
@ -486,13 +486,16 @@ namespace FrontendWebApi.ApiControllers
try try
{ {
getDeviceGroup = await backendRepository.GetAllAsync<EmergencyDeviceGroup>($@" getDeviceGroup = await backendRepository.GetAllAsync<EmergencyDeviceGroup>($@"
select dg.*,vd.system_key disater_name,b.full_name building_name,f.full_name floor_name,v2.system_key system_category_layer2,v3.system_key system_category_layer3 from (SELECT * FROM device_group dg WHERE dg.device_disaster != 0) dg select dg.*,vd.system_key disater_name,b.full_name building_name,f.full_name floor_name,v2.system_key system_category_layer2,v3.system_key system_category_layer3
left join (select * from variable v where v.system_type = 'disaster' and v.deleted = 0) vd on vd.system_value = dg.device_disaster from (
left join building b on b.building_guid = dg.device_building_guid SELECT *
left join floor f on f.floor_guid = dg.device_floor_guid FROM device_group dg WHERE dg.device_disaster != 0) dg
left join (select * from variable v where v.system_type = 'device_system_category_layer2' and v.deleted = 0) v2 on v2.system_value = dg.device_system_category_layer2 left join (select * from variable v where v.system_type = 'disaster' and v.deleted = 0) vd on vd.system_value = dg.device_disaster
left join (select * from variable v where v.system_type = 'device_system_category_layer3' and v.deleted = 0) v3 on v3.system_value = dg.device_system_category_layer3 left join building b on b.building_tag = dg.device_building_guid
order by vd.system_priority,b.priority,f.priority,v2.system_priority,v3.system_priority"); left join floor f on f.floor_guid = dg.device_floor_guid
left join (select * from variable v where v.system_type = 'device_system_category_layer2' and v.deleted = 0) v2 on v2.system_value = dg.device_system_category_layer2
left join (select * from variable v where v.system_type = 'device_system_category_layer3' and v.deleted = 0) v3 on v3.system_value = dg.device_system_category_layer3
order by vd.system_priority,b.priority,f.priority,v2.system_priority,v3.system_priority");
var dis = getDeviceGroup.GroupBy(a => a.device_disaster); var dis = getDeviceGroup.GroupBy(a => a.device_disaster);
//finalDeviceGroup.disaster = new List<KeyValue>(); //finalDeviceGroup.disaster = new List<KeyValue>();

View File

@ -35,7 +35,7 @@ namespace FrontendWebApi.ApiControllers
try try
{ {
var sqlString = @$"select building_guid as Value, full_name as Name from building a where a.deleted = 0 and a.status = 0"; var sqlString = @$"select building_tag as Value, full_name as Name from building a where a.deleted = 0 and a.status = 0";
KeyValue = await backendRepository.GetAllAsync<KeyValue>(sqlString); KeyValue = await backendRepository.GetAllAsync<KeyValue>(sqlString);
apiResult.Code = "0000"; apiResult.Code = "0000";
@ -74,8 +74,8 @@ namespace FrontendWebApi.ApiControllers
select d.device_number device_name,v.system_key disaster_name,ee.*,b.full_name building_name from emergency_event ee 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 (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 device d on d.device_guid = ee.device_guid
left join building b on b.building_guid = ee.building_guid left join building b on b.building_tag = ee.building_tag
where ee.deleted = 0 and ee.building_guid = '{post.selectaBuild}' and ee.disaster = '{post.selectaDisaster}' {sqlplus} where ee.deleted = 0 and ee.building_tag = '{post.selectaBuild}' and ee.disaster = '{post.selectaDisaster}' {sqlplus}
"); ");
apiResult.Code = "0000"; apiResult.Code = "0000";
apiResult.Data = EmergencyRecordEvent; apiResult.Data = EmergencyRecordEvent;

View File

@ -33,7 +33,7 @@ namespace FrontendWebApi.ApiControllers
try try
{ {
var sqlString = @$"select floor_guid as Value, full_name as Name from floor a where a.deleted = 0 and a.building_guid = '{Building}' and a.status = 0 order by a.priority"; var sqlString = @$"select floor_guid as Value, full_name as Name from floor a where a.deleted = 0 and a.building_tag = '{Building}' and a.status = 0 order by a.priority";
KeyValue = await backendRepository.GetAllAsync<KeyValue>(sqlString); KeyValue = await backendRepository.GetAllAsync<KeyValue>(sqlString);
apiResult.Code = "0000"; apiResult.Code = "0000";
@ -61,7 +61,7 @@ namespace FrontendWebApi.ApiControllers
ApiResult<List<RescueDeviceTable>> apiResult = new ApiResult<List<RescueDeviceTable>>(); ApiResult<List<RescueDeviceTable>> apiResult = new ApiResult<List<RescueDeviceTable>>();
try try
{ {
RescueDeviceTables = await backendRepository.GetAllAsync<RescueDeviceTable>("rescue_device", $"building_guid = '{post.build}' and floor_guid in @floors and rescue_device_kind = {post.kind}", new { floors = post.floors }, "floor_name"); RescueDeviceTables = await backendRepository.GetAllAsync<RescueDeviceTable>("rescue_device", $"building_tag = '{post.build}' and floor_guid in @floors and rescue_device_kind = {post.kind}", new { floors = post.floors }, "floor_name");
apiResult.Code = "0000"; apiResult.Code = "0000";
apiResult.Data = RescueDeviceTables; apiResult.Data = RescueDeviceTables;
} }
@ -88,7 +88,7 @@ namespace FrontendWebApi.ApiControllers
try 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"; var sqlString = @$"select building_tag 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); KeyValue = await backendRepository.GetAllAsync<KeyValue>(sqlString);
apiResult.Code = "0000"; apiResult.Code = "0000";
@ -159,7 +159,7 @@ namespace FrontendWebApi.ApiControllers
devicename = "AED"; devicename = "AED";
} }
var sheet = workbook.CreateSheet(devicename); var sheet = workbook.CreateSheet(devicename);
var RescueDevices = backendRepository.GetAllAsync<RescueDevice>("rescue_device", $"building_guid = '{postObject.build}' and rescue_device_kind = {postObject.kind}",null, "floor_name"); var RescueDevices = backendRepository.GetAllAsync<RescueDevice>("rescue_device", $"building_tag = '{postObject.build}' and rescue_device_kind = {postObject.kind}",null, "floor_name");
int RowPosition = 0; int RowPosition = 0;
IRow row = sheet.CreateRow(RowPosition); IRow row = sheet.CreateRow(RowPosition);
ICell cell = row.CreateCell(1); ICell cell = row.CreateCell(1);

View File

@ -27,206 +27,5 @@ namespace FrontendWebApi.Controllers
{ {
return View(); 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

@ -44,99 +44,5 @@ namespace FrontendWebApi.Controllers
return apiResult; 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

@ -51,94 +51,5 @@ namespace FrontendWebApi.Controllers
ViewBag.ProjectName = backendRepository.GetOneAsync<string>("select system_key from variable where deleted = 0 and system_type = 'project_name';").Result; ViewBag.ProjectName = backendRepository.GetOneAsync<string>("select system_key from variable where deleted = 0 and system_type = 'project_name';").Result;
return View(); return View();
} }
[HttpPost]
[Route("api/Login")]
public async Task<ActionResult<ApiResult<TnToken>>> Login(Login login)
{
ApiResult<TnToken> apiResult = new ApiResult<TnToken>(null);
ErrorCode errorCode = new ErrorCode();
try
{
ControllerContext.HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
EDFunction eDFunction = new EDFunction();
//string SHA256Pwd = eDFunction.GetSHA256Encryption(login.password);
var User = await backendRepository.GetOneAsync<User>("userinfo", @$"account = '{login.account}' and deleted = 0");
if (User == null)
{
apiResult.Code = "9998";
return Ok(apiResult);
}
JwtLogin jwtLoing = new JwtLogin()
{
account = User.account,
email = User.email,
full_name = User.full_name,
userinfo_guid = User.userinfo_guid
};
apiResult.Code = "0000";
apiResult.Data = jwt.GenerateToken(jwtLoing);
}
catch
{
apiResult.Code = "9999";
return BadRequest(apiResult);
}
return Ok(apiResult);
}
[HttpPost]
public async Task<ActionResult<ApiResult<string>>> CheckJwt()
{
ApiResult<string> apiResult = new ApiResult<string>(null);
ErrorCode errorCode = new ErrorCode();
try
{
var ctx = ControllerContext.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(),
};
if (myUser.exp == 0)
{
jwt_str = "Jwt Token不合法";
jwtlife = false;
}
else
{
//if (myUser.exp <= DateTime.Now.AddHours(-8).AddMinutes(10).Subtract(new DateTime(1970, 1, 1)).TotalSeconds)
//{
//取得當前登入使用者資訊
EDFunction edFunction = new EDFunction();
HttpContext.Session.SetString("MyApiAccount", edFunction.AESEncrypt(myUser.account)); //將帳號透過AES加密
//}
}
apiResult.Code = "0000";
}
catch(Exception exception)
{
apiResult.Code = "9999";
string json = System.Text.Json.JsonSerializer.Serialize(myUser.account);
logger.LogError("【Login/Index - 登入資訊】" + json);
logger.LogError("【Login/Index】" + exception.Message);
return Ok(apiResult);
}
return Ok(apiResult);
}
} }
} }

View File

@ -25,13 +25,9 @@ namespace FrontendWebApi.Controllers
{ {
private ILogger<T> _logger; private ILogger<T> _logger;
protected ILogger<T> Logger => _logger ?? (_logger = HttpContext?.RequestServices.GetService<ILogger<T>>()); protected ILogger<T> Logger => _logger ?? (_logger = HttpContext?.RequestServices.GetService<ILogger<T>>());
private IBackendRepository backendRepository => HttpContext?.RequestServices.GetService<IBackendRepository>();
private IJwtHelpers jwt => HttpContext?.RequestServices.GetService<IJwtHelpers>(); private IJwtHelpers jwt => HttpContext?.RequestServices.GetService<IJwtHelpers>();
private IFrontendRepository frontendRepository => HttpContext?.RequestServices.GetService<IFrontendRepository>(); private IFrontendRepository frontendRepository => HttpContext?.RequestServices.GetService<IFrontendRepository>();
public BackgroundService backgroundService;
public MyBaseController() { } public MyBaseController() { }
protected MyUserInfo myUserInfo = null; protected MyUserInfo myUserInfo = null;
protected JwtGet myUser; protected JwtGet myUser;