加入專案檔案。
This commit is contained in:
parent
8dd1f67562
commit
dec698413b
20
AlarmMonitorWorkerService/AlarmMonitorWorkerService.csproj
Normal file
20
AlarmMonitorWorkerService/AlarmMonitorWorkerService.csproj
Normal file
@ -0,0 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Worker">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<UserSecretsId>dotnet-AlarmMonitorWorkerService-BB400DAF-C7FE-429A-A172-F3B07F094E0A</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.19" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="3.1.19" />
|
||||
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.2" />
|
||||
<PackageReference Include="Quartz" Version="3.4.0" />
|
||||
<PackageReference Include="Serilog.Extensions.Logging.File" Version="3.0.0" />
|
||||
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="6.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Repository\Repository.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
25
AlarmMonitorWorkerService/Models/EmergencyDevice.cs
Normal file
25
AlarmMonitorWorkerService/Models/EmergencyDevice.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace AlarmMonitorWorkerService.Models
|
||||
{
|
||||
public class AlarmorionString
|
||||
{
|
||||
public string device_number { get; set; }
|
||||
public string point { get; set; }
|
||||
public string source_path { get; set; }
|
||||
public string alarm_timestamp { get; set; }
|
||||
public string source_name { get; set; }
|
||||
public string source_msg { get; set; }
|
||||
}
|
||||
|
||||
public class DeviceInfo
|
||||
{
|
||||
public string device_number { get; set; }
|
||||
public string device_disaster_type_text { get; set; }
|
||||
public string device_name { get; set; }
|
||||
public string building_name { get; set; }
|
||||
public string floor_name { get; set; }
|
||||
}
|
||||
}
|
19
AlarmMonitorWorkerService/Models/Variable.cs
Normal file
19
AlarmMonitorWorkerService/Models/Variable.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace AlarmMonitorWorkerService.Models
|
||||
{
|
||||
public class Variable
|
||||
{
|
||||
public string System_type { get; set; }
|
||||
public string System_key { get; set; }
|
||||
public string system_value { get; set; }
|
||||
}
|
||||
|
||||
public class KeyValue
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Value { get; set; }
|
||||
}
|
||||
}
|
67
AlarmMonitorWorkerService/Program.cs
Normal file
67
AlarmMonitorWorkerService/Program.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using AlarmMonitorWorkerService.Quartz;
|
||||
using AlarmMonitorWorkerService.Quartz.Jobs;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Quartz;
|
||||
using Quartz.Impl;
|
||||
using Quartz.Spi;
|
||||
using Repository.BaseRepository.Implement;
|
||||
using Repository.BaseRepository.Interface;
|
||||
using Repository.FrontendRepository.Implement;
|
||||
using Repository.FrontendRepository.Interface;
|
||||
using Repository.Helper;
|
||||
using Repository.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AlarmMonitorWorkerService
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
CreateHostBuilder(args).Build().Run();
|
||||
}
|
||||
|
||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
Host.CreateDefaultBuilder(args)
|
||||
.UseWindowsService()
|
||||
.ConfigureServices((hostContext, services) =>
|
||||
{
|
||||
IConfiguration configuration = hostContext.Configuration;
|
||||
|
||||
#region DBHelper 注入
|
||||
services.Configure<DBConfig>(configuration.GetSection("DBConfig"));
|
||||
services.AddTransient<IDatabaseHelper, DatabaseHelper>();
|
||||
#endregion DBHelper 注入
|
||||
|
||||
#region Repository 注入
|
||||
//services.AddTransient<IBackendRepository, BackendRepository>();
|
||||
//services.AddTransient<IBackgroundServiceRepository, BackgroundServiceRepository>();
|
||||
services.AddTransient<IFrontendRepository, FrontendRepository>();
|
||||
services.AddTransient<IBaseRepository, BaseRepository>();
|
||||
#endregion Repository 注入
|
||||
|
||||
//添加Quartz服務
|
||||
services.AddTransient<IJobFactory, SingletonJobFactory>();
|
||||
services.AddTransient<ISchedulerFactory, StdSchedulerFactory>();
|
||||
services.AddHostedService<QuartzHostedService>();
|
||||
|
||||
#region 監控緊急應變畫面(設定3秒執行一次)
|
||||
services.AddSingleton<AlarmMonitorJob>();
|
||||
services.AddSingleton(
|
||||
new JobSchedule(jobType: typeof(AlarmMonitorJob), cronExpression: configuration.GetValue<string>("BackgroundServiceCron:AlarmMonitorJob"))
|
||||
);
|
||||
#endregion
|
||||
}).ConfigureLogging((hostContext, logFactory) => {
|
||||
IConfiguration configuration = hostContext.Configuration;
|
||||
|
||||
//logFactory.AddFile("Logs/log-{Date}.txt");
|
||||
logFactory.AddFile(configuration.GetValue<string>("LoggerPath") + "/log-{Date}.txt");
|
||||
});
|
||||
}
|
||||
}
|
10
AlarmMonitorWorkerService/Properties/launchSettings.json
Normal file
10
AlarmMonitorWorkerService/Properties/launchSettings.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"profiles": {
|
||||
"AlarmMonitorWorkerService": {
|
||||
"commandName": "Project",
|
||||
"environmentVariables": {
|
||||
"DOTNET_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
45
AlarmMonitorWorkerService/Quartz/JobSchedule.cs
Normal file
45
AlarmMonitorWorkerService/Quartz/JobSchedule.cs
Normal file
@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Text;
|
||||
|
||||
namespace AlarmMonitorWorkerService.Quartz
|
||||
{
|
||||
/// <summary>
|
||||
/// Job調度中間對象
|
||||
/// </summary>
|
||||
public class JobSchedule
|
||||
{
|
||||
public JobSchedule(Type jobType, string cronExpression)
|
||||
{
|
||||
this.JobType = jobType ?? throw new ArgumentNullException(nameof(jobType));
|
||||
CronExpression = cronExpression ?? throw new ArgumentNullException(nameof(cronExpression));
|
||||
}
|
||||
/// <summary>
|
||||
/// Job類型
|
||||
/// </summary>
|
||||
public Type JobType { get; private set; }
|
||||
/// <summary>
|
||||
/// Cron表達式
|
||||
/// </summary>
|
||||
public string CronExpression { get; private set; }
|
||||
/// <summary>
|
||||
/// Job狀態
|
||||
/// </summary>
|
||||
public JobStatus JobStatu { get; set; } = JobStatus.Init;
|
||||
}
|
||||
/// <summary>
|
||||
/// Job運行狀態
|
||||
/// </summary>
|
||||
public enum JobStatus : byte
|
||||
{
|
||||
[Description("初始化")]
|
||||
Init = 0,
|
||||
[Description("運行中")]
|
||||
Running = 1,
|
||||
[Description("調度中")]
|
||||
Scheduling = 2,
|
||||
[Description("已停止")]
|
||||
Stopped = 3,
|
||||
}
|
||||
}
|
211
AlarmMonitorWorkerService/Quartz/Jobs/AlarmMonitorJob.cs
Normal file
211
AlarmMonitorWorkerService/Quartz/Jobs/AlarmMonitorJob.cs
Normal file
@ -0,0 +1,211 @@
|
||||
using AlarmMonitorWorkerService.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Quartz;
|
||||
using Repository.FrontendRepository.Interface;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Data.Xml.Dom;
|
||||
using Windows.UI.Notifications;
|
||||
using System.IO;
|
||||
|
||||
namespace AlarmMonitorWorkerService.Quartz.Jobs
|
||||
{
|
||||
/// <summary>
|
||||
/// 監控緊急應變畫面是否有開啟
|
||||
/// </summary>
|
||||
[DisallowConcurrentExecution]
|
||||
class AlarmMonitorJob : IJob
|
||||
{
|
||||
private const string APP_ID = "WPF ToastNotificaiton Test";
|
||||
private readonly ILogger<AlarmMonitorJob> logger;
|
||||
private readonly IFrontendRepository frontendRepository;
|
||||
|
||||
public AlarmMonitorJob(
|
||||
ILogger<AlarmMonitorJob> logger,
|
||||
IFrontendRepository frontendRepository)
|
||||
{
|
||||
this.logger = logger;
|
||||
this.frontendRepository = frontendRepository;
|
||||
}
|
||||
|
||||
public async Task Execute(IJobExecutionContext context)
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.LogInformation("【AlarmMonitorJob】【任務開始】");
|
||||
//找出當前緊急應變的PID
|
||||
var sqlWatchDog = $@"SELECT system_value as Value, system_key as Name FROM variable WHERE deleted = 0 AND system_type = 'watchDogCongfig'";
|
||||
|
||||
var variable = await frontendRepository.GetAllAsync<KeyValue>(sqlWatchDog);
|
||||
var alarmPID = variable.Where(x => x.Name == "AlarmPID").Select(x => x.Value).FirstOrDefault();
|
||||
|
||||
var category = new PerformanceCounterCategory("Process");
|
||||
|
||||
var instances = category.GetInstanceNames();
|
||||
|
||||
var hasFound = false;
|
||||
foreach (var instance in instances)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var counter = new PerformanceCounter(category.CategoryName,
|
||||
"ID Process", instance, true))
|
||||
{
|
||||
int val = (int)counter.RawValue;
|
||||
if (val == Convert.ToInt32(alarmPID))
|
||||
{
|
||||
hasFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
var header = string.Empty;
|
||||
if (!hasFound)
|
||||
{
|
||||
header = "請開啟監控頁面";
|
||||
}
|
||||
|
||||
//找出異常的設備
|
||||
string sql = $@"SELECT
|
||||
amc.id,
|
||||
sl.source source_path,
|
||||
from_unixtime(amc.timestamp/1000,'%Y-%m-%d %H:%i:%s') alarm_timestamp ,
|
||||
temp_source.source_name,
|
||||
temp_msg.source_msg
|
||||
FROM alarmorion_orionalarmrecord amc
|
||||
JOIN (
|
||||
SELECT
|
||||
MAX(amc.alarm) ad,
|
||||
m.source
|
||||
FROM alarmorion_orionalarmsourceorder amc
|
||||
JOIN (
|
||||
SELECT * FROM alarmorion_orionalarmsource a
|
||||
WHERE substring(a.source,23,5) ='Arena'
|
||||
) m ON amc.alarmSource = m.id
|
||||
GROUP BY m.source
|
||||
) sl ON amc.id = sl.ad
|
||||
JOIN(
|
||||
SELECT
|
||||
val.alarm ,
|
||||
val.value AS source_name
|
||||
FROM alarmorion_orionalarmfacetvalue val
|
||||
JOIN alarmorion_orionalarmfacetname nam ON val.facetName = nam.id AND nam.facetName = 'sourceName'
|
||||
) temp_source ON amc.id = temp_source.alarm
|
||||
JOIN(
|
||||
SELECT
|
||||
val.alarm,
|
||||
val.value AS source_msg
|
||||
FROM alarmorion_orionalarmfacetvalue val
|
||||
JOIN alarmorion_orionalarmfacetname nam ON val.facetName = nam.id AND nam.facetName = 'msgText'
|
||||
) temp_msg ON amc.id = temp_msg.alarm
|
||||
WHERE amc.sourceState = 1";
|
||||
|
||||
var alarms = await frontendRepository.GetAllAsync<AlarmorionString>(sql);
|
||||
|
||||
//組出device_number
|
||||
List<string> tempDeviceNumbers = new List<string>();
|
||||
foreach (var alarm in alarms)
|
||||
{
|
||||
var alarmSplit = alarm.source_path.Split("|");
|
||||
var deviceSplit = alarmSplit[alarmSplit.Length - 1].Split("/");
|
||||
var device_number = deviceSplit[deviceSplit.Length - 3];
|
||||
var point = deviceSplit[deviceSplit.Length - 2];
|
||||
|
||||
alarm.device_number = device_number.Replace("$3", "");
|
||||
alarm.point = point;
|
||||
|
||||
tempDeviceNumbers.Add(device_number);
|
||||
}
|
||||
|
||||
//找出所有設備相關資訊
|
||||
var sql_device = $@"SELECT
|
||||
d.device_number,
|
||||
d.full_name AS device_name,
|
||||
b.full_name AS building_name,
|
||||
f.full_name AS floor_name,
|
||||
(SELECT
|
||||
v.system_key
|
||||
FROM device_disaster dd
|
||||
JOIN variable v ON v.deleted = 0 AND v.system_type = 'disaster' AND v.system_value = dd.device_system_value
|
||||
WHERE dd.device_guid = d.device_guid
|
||||
) AS Device_disaster_type_text
|
||||
FROM device d
|
||||
JOIN building b ON b.deleted = 0 AND d.building_guid = b.building_guid
|
||||
JOIN floor f ON f.deleted = 0 AND d.floor_guid = f.floor_guid
|
||||
WHERE d.deleted = 0 AND d.device_number IN @device_numbers";
|
||||
|
||||
var deviceInfos = await frontendRepository.GetAllAsync<DeviceInfo>(sql_device, new { device_numbers = tempDeviceNumbers.Distinct().ToList() });
|
||||
|
||||
var alarmFormat = @"{0}:{1} {2} {3} {4} {5}觸發";
|
||||
|
||||
List<string> alarmMsg = new List<string>();
|
||||
foreach (var alarm in alarms)
|
||||
{
|
||||
var selected_deviceinfo = deviceInfos.Where(x => x.device_number == alarm.device_number).FirstOrDefault();
|
||||
|
||||
if (selected_deviceinfo != null)
|
||||
{
|
||||
alarmMsg.Add(string.Format(alarmFormat,
|
||||
selected_deviceinfo.device_disaster_type_text,
|
||||
alarm.alarm_timestamp,
|
||||
selected_deviceinfo.building_name,
|
||||
selected_deviceinfo.floor_name,
|
||||
selected_deviceinfo.device_name,
|
||||
alarm.point));
|
||||
}
|
||||
}
|
||||
|
||||
GenerateToast("IBMS緊急應變通知", null, header, "", string.Join("\n", alarmMsg));
|
||||
logger.LogInformation("【AlarmMonitorJob】【任務完成】");
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError("【AlarmMonitorJob】【任務失敗】");
|
||||
logger.LogError("【AlarmMonitorJob】【任務失敗】[Exception]:{0}", exception.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public void GenerateToast(string appid, string imageFullPath, string h1, string h2, string p1)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
var template = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText04);
|
||||
|
||||
var textNodes = template.GetElementsByTagName("text");
|
||||
|
||||
textNodes[0].AppendChild(template.CreateTextNode(h1));
|
||||
textNodes[1].AppendChild(template.CreateTextNode(h2));
|
||||
textNodes[2].AppendChild(template.CreateTextNode(p1));
|
||||
|
||||
//if (File.Exists(imageFullPath))
|
||||
//{
|
||||
// XmlNodeList toastImageElements = template.GetElementsByTagName("image");
|
||||
// ((XmlElement)toastImageElements[0]).SetAttribute("src", imageFullPath);
|
||||
//}
|
||||
|
||||
IXmlNode toastNode = template.SelectSingleNode("/toast");
|
||||
((XmlElement)toastNode).SetAttribute("duration", "long");
|
||||
|
||||
var notifier = ToastNotificationManager.CreateToastNotifier(appid);
|
||||
var notification = new ToastNotification(template);
|
||||
|
||||
notifier.Show(notification);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
71
AlarmMonitorWorkerService/Quartz/QuartzHostedService.cs
Normal file
71
AlarmMonitorWorkerService/Quartz/QuartzHostedService.cs
Normal file
@ -0,0 +1,71 @@
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Quartz;
|
||||
using Quartz.Spi;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AlarmMonitorWorkerService.Quartz
|
||||
{
|
||||
public class QuartzHostedService : IHostedService
|
||||
{
|
||||
private readonly ISchedulerFactory _schedulerFactory;
|
||||
private readonly IJobFactory _jobFactory;
|
||||
private readonly IEnumerable<JobSchedule> _jobSchedules;
|
||||
public QuartzHostedService(ISchedulerFactory schedulerFactory, IJobFactory jobFactory, IEnumerable<JobSchedule> jobSchedules)
|
||||
{
|
||||
_schedulerFactory = schedulerFactory ?? throw new ArgumentNullException(nameof(schedulerFactory));
|
||||
_jobFactory = jobFactory ?? throw new ArgumentNullException(nameof(jobFactory));
|
||||
_jobSchedules = jobSchedules ?? throw new ArgumentNullException(nameof(jobSchedules));
|
||||
}
|
||||
public IScheduler Scheduler { get; set; }
|
||||
public async Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
|
||||
Scheduler = await _schedulerFactory.GetScheduler(cancellationToken);
|
||||
Scheduler.JobFactory = _jobFactory;
|
||||
foreach (var jobSchedule in _jobSchedules)
|
||||
{
|
||||
var job = CreateJob(jobSchedule);
|
||||
var trigger = CreateTrigger(jobSchedule);
|
||||
await Scheduler.ScheduleJob(job, trigger, cancellationToken);
|
||||
jobSchedule.JobStatu = JobStatus.Scheduling;
|
||||
}
|
||||
await Scheduler.Start(cancellationToken);
|
||||
foreach (var jobSchedule in _jobSchedules)
|
||||
{
|
||||
jobSchedule.JobStatu = JobStatus.Running;
|
||||
}
|
||||
}
|
||||
public async Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
await Scheduler?.Shutdown(cancellationToken);
|
||||
foreach (var jobSchedule in _jobSchedules)
|
||||
{
|
||||
|
||||
jobSchedule.JobStatu = JobStatus.Stopped;
|
||||
}
|
||||
}
|
||||
private static IJobDetail CreateJob(JobSchedule schedule)
|
||||
{
|
||||
var jobType = schedule.JobType;
|
||||
return JobBuilder
|
||||
.Create(jobType)
|
||||
.WithIdentity(jobType.FullName)
|
||||
.WithDescription(jobType.Name)
|
||||
.Build();
|
||||
}
|
||||
private static ITrigger CreateTrigger(JobSchedule schedule)
|
||||
{
|
||||
return TriggerBuilder
|
||||
.Create()
|
||||
.WithIdentity($"{schedule.JobType.FullName}.trigger")
|
||||
.WithCronSchedule(schedule.CronExpression)
|
||||
.WithDescription(schedule.CronExpression)
|
||||
.Build();
|
||||
}
|
||||
}
|
||||
}
|
26
AlarmMonitorWorkerService/Quartz/SingletonJobFactory.cs
Normal file
26
AlarmMonitorWorkerService/Quartz/SingletonJobFactory.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Quartz;
|
||||
using Quartz.Spi;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace AlarmMonitorWorkerService.Quartz
|
||||
{
|
||||
public class SingletonJobFactory : IJobFactory
|
||||
{
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
public SingletonJobFactory(IServiceProvider serviceProvider)
|
||||
{
|
||||
_serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
|
||||
}
|
||||
public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler)
|
||||
{
|
||||
return _serviceProvider.GetRequiredService(bundle.JobDetail.JobType) as IJob;
|
||||
}
|
||||
public void ReturnJob(IJob job)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
29
AlarmMonitorWorkerService/Worker.cs
Normal file
29
AlarmMonitorWorkerService/Worker.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AlarmMonitorWorkerService
|
||||
{
|
||||
public class Worker : BackgroundService
|
||||
{
|
||||
private readonly ILogger<Worker> _logger;
|
||||
|
||||
public Worker(ILogger<Worker> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
|
||||
await Task.Delay(1000, stoppingToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
28
AlarmMonitorWorkerService/appsettings.Development.json
Normal file
28
AlarmMonitorWorkerService/appsettings.Development.json
Normal file
@ -0,0 +1,28 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"BackgroundServiceCron": {
|
||||
"AlarmMonitorJob": "0/3 * * * * ?"
|
||||
},
|
||||
"DBConfig": {
|
||||
//"MySqlDBConfig": {
|
||||
// "Server": "TNi6aupYHPZT8ZU177KTKw==", //172.16.220.251
|
||||
// "Port": "mkF51jVbg40V5K5eTh2Ckw==",
|
||||
// "Database": "VvfWH/59gQguY2eA2xBCug==",
|
||||
// "Root": "IV8Ec1Ng2AWAnkBafXy2kg==",
|
||||
// "Password": "Jue6jMFRi11meN6xbdKwDA=="
|
||||
//},
|
||||
"MySqlDBConfig": {
|
||||
"Server": "FYlY+w0XDIz+jmF2rlZWJw==", //0.201
|
||||
"Port": "js2LutKe+rdjzdxMPQUrvQ==",
|
||||
"Database": "VJB2XC+lAtzuHObDGMVOAA==", //30
|
||||
"Root": "SzdxEgaJJ7tcTCrUl2zKsA==",
|
||||
"Password": "FVAPxztxpY4gJJKQ/se4bQ=="
|
||||
},
|
||||
}
|
||||
}
|
28
AlarmMonitorWorkerService/appsettings.json
Normal file
28
AlarmMonitorWorkerService/appsettings.json
Normal file
@ -0,0 +1,28 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"BackgroundServiceCron": {
|
||||
"AlarmMonitorJob": "0/3 * * * * ?"
|
||||
},
|
||||
"DBConfig": {
|
||||
"MySqlDBConfig": {
|
||||
"Server": "FYlY+w0XDIz+jmF2rlZWJw==", //0.201
|
||||
"Port": "js2LutKe+rdjzdxMPQUrvQ==",
|
||||
"Database": "VJB2XC+lAtzuHObDGMVOAA==", //30
|
||||
"Root": "SzdxEgaJJ7tcTCrUl2zKsA==",
|
||||
"Password": "FVAPxztxpY4gJJKQ/se4bQ=="
|
||||
}
|
||||
//"MySqlDBConfig": {
|
||||
// "Server": "ueFp+VFb200lhh1Uctc97WH0/tX6tfXYU2v1oxCWuuM=", //greencloud.fic.com.tw
|
||||
// "Port": "mkF51jVbg40V5K5eTh2Ckw==",
|
||||
// "Database": "VvfWH/59gQguY2eA2xBCug==",
|
||||
// "Root": "+plVKQ+enAqt7BYV2uMQng==",
|
||||
// "Password": "tWzphRxS8piHZiHpxRpzrg=="
|
||||
//},
|
||||
}
|
||||
}
|
12
Backend/.config/dotnet-tools.json
Normal file
12
Backend/.config/dotnet-tools.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"version": 1,
|
||||
"isRoot": true,
|
||||
"tools": {
|
||||
"dotnet-ef": {
|
||||
"version": "6.0.0",
|
||||
"commands": [
|
||||
"dotnet-ef"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
128
Backend/ApiControllers/DeviceApiController.cs
Normal file
128
Backend/ApiControllers/DeviceApiController.cs
Normal file
@ -0,0 +1,128 @@
|
||||
using Backend.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Repository.BackendRepository.Interface;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Backend.ApiControllers
|
||||
{
|
||||
public class DeviceApiController : MyBaseApiController<DeviceApiController>
|
||||
{
|
||||
private readonly IBackendRepository backendRepository;
|
||||
public DeviceApiController(IBackendRepository backendRepository)
|
||||
{
|
||||
this.backendRepository = backendRepository;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改設備名稱
|
||||
/// </summary>
|
||||
/// <param name="change"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Route("api/Device/SaveChangeName")]
|
||||
public async Task<ActionResult<ApiResult<string>>> SaveChangeName(ChangeName change)
|
||||
{
|
||||
ApiResult<string> apiResult = new ApiResult<string>();
|
||||
if (!jwtlife)
|
||||
{
|
||||
apiResult.Code = "5000";
|
||||
return BadRequest(apiResult);
|
||||
}
|
||||
try
|
||||
{
|
||||
if (change.ChooseTable == 0)
|
||||
{
|
||||
//一般設備
|
||||
var GetOne = await backendRepository.GetOneAsync<Device>("device", $" device_number = '{change.TagName}'");
|
||||
if (GetOne == null)
|
||||
{
|
||||
apiResult.Data = "查無資料";
|
||||
apiResult.Code = "0001";
|
||||
}
|
||||
else
|
||||
{
|
||||
//修改設備名稱
|
||||
Dictionary<string, object> ChangeN = new Dictionary<string, object>();
|
||||
ChangeN = new Dictionary<string, object>()
|
||||
{
|
||||
{ "@full_name", change.ChangeN},
|
||||
{ "@updated_at",DateTime.Now},
|
||||
};
|
||||
await backendRepository.UpdateOneByCustomTable(ChangeN, "device", $" device_number = '{change.TagName}'");
|
||||
|
||||
//記錄使用者操作紀錄
|
||||
Dictionary<string, object> userOperatorLog = new Dictionary<string, object>()
|
||||
{
|
||||
{ "@user_guid", myUser.userinfo_guid },
|
||||
{ "@operation_type", 1 }, //1:名稱修改
|
||||
{ "@building_guid", GetOne.Building_guid },
|
||||
{ "@main_system_guid", GetOne.Main_system_guid },
|
||||
{ "@sub_system_guid", GetOne.Sub_system_guid },
|
||||
{ "@floor_guid", GetOne.Floor_guid },
|
||||
{ "@device_guid", GetOne.Device_guid },
|
||||
{ "@action_name", "修改名稱" },
|
||||
{ "@parameter", JsonConvert.SerializeObject(change) },
|
||||
};
|
||||
|
||||
await backendRepository.AddOneByCustomTable(userOperatorLog, "operation_log");
|
||||
|
||||
apiResult.Data = "更改成功";
|
||||
apiResult.Code = "0000";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//燈控設備
|
||||
var GetOne = await backendRepository.GetOneAsync<string>("device_master", $" device_master_number = '{change.TagName}'");
|
||||
if (GetOne == null)
|
||||
{
|
||||
apiResult.Data = "查無資料";
|
||||
apiResult.Code = "0001";
|
||||
}
|
||||
else
|
||||
{
|
||||
Dictionary<string, object> ChangeN = new Dictionary<string, object>();
|
||||
ChangeN = new Dictionary<string, object>()
|
||||
{
|
||||
{ "@device_master_full_name", change.ChangeN},
|
||||
{ "@updated_at",DateTime.Now},
|
||||
};
|
||||
await backendRepository.UpdateOneByCustomTable(ChangeN, "device_master", $" device_master_number = '{change.TagName}'");
|
||||
|
||||
////記錄使用者操作紀錄
|
||||
//Dictionary<string, object> userOperatorLog = new Dictionary<string, object>()
|
||||
//{
|
||||
// { "@user_guid", myUser },
|
||||
// { "@operation_type", 1 }, //1:名稱修改
|
||||
// { "@building_guid", GetOne.Building_guid },
|
||||
// { "@main_system_guid", GetOne.Main_system_guid },
|
||||
// { "@sub_system_guid", GetOne.Sub_system_guid },
|
||||
// { "@floor_guid", GetOne.Floor_guid },
|
||||
// { "@device_guid", GetOne.Device_guid },
|
||||
// { "@action_name", "修改名稱" },
|
||||
// { "@parameter", JsonConvert.SerializeObject(change) },
|
||||
//};
|
||||
|
||||
//await backendRepository.AddOneByCustomTable(userOperatorLog, "operation_log");
|
||||
|
||||
apiResult.Data = "更改成功";
|
||||
apiResult.Code = "0000";
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
return Ok(apiResult);
|
||||
}
|
||||
return Ok(apiResult);
|
||||
}
|
||||
}
|
||||
}
|
81
Backend/ApiControllers/MyBaseApiController.cs
Normal file
81
Backend/ApiControllers/MyBaseApiController.cs
Normal file
@ -0,0 +1,81 @@
|
||||
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 Backend.Models;
|
||||
using Backend.Jwt;
|
||||
|
||||
namespace Backend.ApiControllers
|
||||
{
|
||||
public class MyBaseApiController<T> : Controller where T : MyBaseApiController<T>
|
||||
{
|
||||
|
||||
private ILogger<T> _logger;
|
||||
protected ILogger<T> Logger => _logger ?? (_logger = HttpContext?.RequestServices.GetService<ILogger<T>>());
|
||||
|
||||
private IJwtHelpers jwt => HttpContext?.RequestServices.GetService<IJwtHelpers>();
|
||||
//private IDatabaseHelper qqwt => HttpContext?.RequestServices.GetService<IDatabaseHelper>();
|
||||
public MyBaseApiController() { }
|
||||
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)
|
||||
{
|
||||
controllerName = ControllerContext.RouteData.Values["controller"].ToString(); //controller名稱
|
||||
actionName = ControllerContext.RouteData.Values["action"].ToString(); //action名稱
|
||||
|
||||
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");
|
||||
EDFunction edFunction = new EDFunction();
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
45
Backend/Backend.csproj
Normal file
45
Backend/Backend.csproj
Normal file
@ -0,0 +1,45 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<UserSecretsId>8a5f6c4d-4a50-40fa-aacf-a238bb8fb733</UserSecretsId>
|
||||
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="wwwroot\lib\jquery.lazy-master\**" />
|
||||
<Content Remove="wwwroot\lib\jquery.lazy-master\**" />
|
||||
<EmbeddedResource Remove="wwwroot\lib\jquery.lazy-master\**" />
|
||||
<None Remove="wwwroot\lib\jquery.lazy-master\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="Controllers\NpoiMemoryStream.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="iTextSharp" Version="5.5.13.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.21" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.1.20" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.5" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
<PackageReference Include="NPOI" Version="2.5.5" />
|
||||
<PackageReference Include="Serilog.Extensions.Logging.File" Version="2.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Repository\Repository.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Repository\Repository.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="wwwroot\upload\floor_map\" />
|
||||
<Folder Include="wwwroot\upload\device_icon\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ProjectExtensions><VisualStudio><UserProperties properties_4launchsettings_1json__JsonSchema="" /></VisualStudio></ProjectExtensions>
|
||||
|
||||
</Project>
|
588
Backend/Controllers/BuildInfoController.cs
Normal file
588
Backend/Controllers/BuildInfoController.cs
Normal file
@ -0,0 +1,588 @@
|
||||
using Backend.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
using Repository.BackendRepository.Interface;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using System.Transactions;
|
||||
|
||||
namespace Backend.Controllers
|
||||
{
|
||||
public class BuildInfoController : MybaseController<BuildInfoController>
|
||||
{
|
||||
private readonly IBackendRepository backendRepository;
|
||||
private string mapFileSaveAsPath = "";
|
||||
|
||||
public BuildInfoController(IBackendRepository backendRepository)
|
||||
{
|
||||
this.backendRepository = backendRepository;
|
||||
|
||||
mapFileSaveAsPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "floor_map");
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 區域基本資料列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<List<BuildInfo>>> BuildInfoList()
|
||||
{
|
||||
ApiResult<List<BuildInfo>> apiResult = new ApiResult<List<BuildInfo>>();
|
||||
List<BuildInfo> buildInfo = new List<BuildInfo>();
|
||||
|
||||
try
|
||||
{
|
||||
var sqlString = @$"SELECT A.priority, A.building_guid, A.full_name, A.ip_address, A.ip_port, (SELECT COUNT(*) FROM floor f WHERE f.deleted = 0 AND f.building_guid = A.building_guid) AS 'floorNum', A.created_at
|
||||
FROM building A
|
||||
WHERE A.deleted = 0
|
||||
ORDER BY A.priority ASC, A.created_at DESC";
|
||||
buildInfo = await backendRepository.GetAllAsync<BuildInfo>(sqlString);
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Data = buildInfo;
|
||||
}
|
||||
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>> SaveBuildInfo(BuildInfo post)
|
||||
{
|
||||
ApiResult<string> apiResult = new ApiResult<string>();
|
||||
|
||||
try
|
||||
{
|
||||
//判斷監控主機IP是否重複
|
||||
var judgeIPAddressRepeat = true;
|
||||
|
||||
var sWhere = $@"deleted = 0 AND ip_address = @ip_address AND ip_port = @ip_port AND building_guid != @building_guid";
|
||||
var buildInfos = await backendRepository.GetAllAsync<BuildInfo>("building", sWhere, new { ip_address = post.Ip_address, ip_port = post.Ip_port, building_guid = post.Building_guid });
|
||||
if (buildInfos.Count == 0)
|
||||
{
|
||||
judgeIPAddressRepeat = false;
|
||||
}
|
||||
|
||||
if (!judgeIPAddressRepeat)
|
||||
{
|
||||
//新增
|
||||
if (post.Building_guid == "0")
|
||||
{
|
||||
//產生一組GUID
|
||||
var guid = Guid.NewGuid(); //大樓GUID
|
||||
|
||||
//抓取當前的Priority
|
||||
var current_priority = await backendRepository.GetCurrentPriority("building");
|
||||
|
||||
Dictionary<string, object> building = new Dictionary<string, object>();
|
||||
building = new Dictionary<string, object>()
|
||||
{
|
||||
{ "@building_guid", guid},
|
||||
{ "@full_name", post.Full_name},
|
||||
{ "@ip_address", post.Ip_address},
|
||||
{ "@ip_port", post.Ip_port},
|
||||
{ "@priority", current_priority + 1},
|
||||
{ "@created_by", myUserInfo.Userinfo_guid}
|
||||
};
|
||||
await backendRepository.AddOneByCustomTable(building, "building");
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "新增成功";
|
||||
}
|
||||
else //修改
|
||||
{
|
||||
Dictionary<string, object> building = new Dictionary<string, object>();
|
||||
building = new Dictionary<string, object>()
|
||||
{
|
||||
{ "@full_name", post.Full_name},
|
||||
{ "@ip_address", post.Ip_address},
|
||||
{ "@ip_port", post.Ip_port},
|
||||
{ "@updated_by", myUserInfo.Userinfo_guid},
|
||||
{ "@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}
|
||||
};
|
||||
await backendRepository.UpdateOneByCustomTable(building, "building", "building_guid='" + post.Building_guid + "'");
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "修改成功";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
apiResult.Code = "0001";
|
||||
apiResult.Msg = "監控主機IP不可重複";
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
string json = System.Text.Json.JsonSerializer.Serialize(post);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + json);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
}
|
||||
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<string>> DeleteOneBuild(string guid)
|
||||
{
|
||||
var apiResult = new ApiResult<string>();
|
||||
try
|
||||
{
|
||||
string sWhere = @$"deleted = @Deleted AND building_guid = @Guid";
|
||||
|
||||
object param = new { Deleted = 0, Guid = guid };
|
||||
|
||||
var buildInfo = await backendRepository.GetOneAsync<BuildInfo>("building", sWhere, param);
|
||||
|
||||
if (buildInfo == null)
|
||||
{
|
||||
apiResult.Code = "9998";
|
||||
apiResult.Msg = "查無該區域資料";
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
//檢查是否有未刪除的區域選單
|
||||
var sbuildMenuWhere = $@"building_guid = @Guid";
|
||||
var buildMenus = await backendRepository.GetAllAsync<BuildMenu>("building_menu", sbuildMenuWhere, new { Guid = guid });
|
||||
|
||||
if (buildMenus.Count > 0)
|
||||
{
|
||||
apiResult.Code = "9997";
|
||||
apiResult.Msg = "區域選單中尚有選單正在使用該棟別,故無法刪除";
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
//檢查底下是否有未刪除的樓層
|
||||
var sfloorWhere = $@"deleted = 0 AND building_guid = @Guid";
|
||||
var floors = await backendRepository.GetAllAsync<BuildFloor>("floor", sfloorWhere, new { Guid = guid });
|
||||
|
||||
if (floors.Count > 0)
|
||||
{
|
||||
apiResult.Code = "9997";
|
||||
apiResult.Msg = "樓層設定中尚有以下樓層正在使用該棟別,故無法刪除";
|
||||
apiResult.Data = string.Join("<br>", floors.Select(x => x.Full_name).ToList());
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
await backendRepository.DeleteOne(guid, "building", "building_guid");
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "刪除成功";
|
||||
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + "building_guid=" + guid);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
}
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改棟別區域排列順序
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<List<string>>> ChangeBuildInfoPriority(PostBuildInfoPriority post)
|
||||
{
|
||||
ApiResult<List<string>> apiResult = new ApiResult<List<string>>();
|
||||
try
|
||||
{
|
||||
List<Dictionary<string, object>> building_priorities = new List<Dictionary<string, object>>();
|
||||
if (post.BuildInfoPriorities != null)
|
||||
{
|
||||
foreach (var building_priority in post.BuildInfoPriorities)
|
||||
{
|
||||
Dictionary<string, object> building_priority_dic = new Dictionary<string, object>();
|
||||
building_priority_dic = new Dictionary<string, object>()
|
||||
{
|
||||
{ "building_guid", building_priority.Building_guid},
|
||||
{ "@priority", building_priority.Priority},
|
||||
{ "@updated_by", myUserInfo.Userinfo_guid},
|
||||
{ "@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}
|
||||
};
|
||||
|
||||
building_priorities.Add(building_priority_dic);
|
||||
}
|
||||
|
||||
var sql = $@"UPDATE building SET priority = @priority, updated_by = @updated_by, updated_at=@updated_at WHERE building_guid = @building_guid";
|
||||
|
||||
await backendRepository.ExecuteSql(sql, building_priorities);
|
||||
|
||||
#region 新增至派送資料表
|
||||
await backendRepository.ManualInsertBackgroundServiceTask("", "", "building", "update_list", building_priorities);
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "修改成功";
|
||||
}
|
||||
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<List<BuildFloor>>> BuildFloorList(string BuildGuid)
|
||||
{
|
||||
ApiResult<List<BuildFloor>> apiResult = new ApiResult<List<BuildFloor>>();
|
||||
List<BuildFloor> buildInfo = new List<BuildFloor>();
|
||||
|
||||
try
|
||||
{
|
||||
var sqlString = @$"SELECT A.floor_guid, A.full_name, InitMapName + '.svg' AS 'initMapName', A.priority, A.created_at
|
||||
FROM floor A
|
||||
WHERE deleted = @deleted
|
||||
AND A.building_guid = @building_guid
|
||||
ORDER BY A.priority ASC";
|
||||
buildInfo = await backendRepository.GetAllAsync<BuildFloor>(sqlString, new { deleted = 0, building_guid = BuildGuid });
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Data = buildInfo;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
}
|
||||
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取得單一樓層設定
|
||||
/// </summary>
|
||||
/// <param name="guid"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<BuildFloor>> GetOneBuildFloor(string guid)
|
||||
{
|
||||
ApiResult<BuildFloor> apiResult = new ApiResult<BuildFloor>();
|
||||
|
||||
try
|
||||
{
|
||||
string sWhere = @$"deleted = @Deleted AND floor_guid = @Guid";
|
||||
|
||||
object param = new { Deleted = 0, Guid = guid };
|
||||
|
||||
var buildFloor = await backendRepository.GetOneAsync<BuildFloor>("floor", sWhere, param);
|
||||
|
||||
if (!string.IsNullOrEmpty(buildFloor.InitMapName))
|
||||
{
|
||||
buildFloor.MapUrl = "/upload/floor_map/" + buildFloor.Floor_guid + ".svg";
|
||||
}
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Data = buildFloor;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
}
|
||||
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新增 / 修改 樓層設定
|
||||
/// </summary>
|
||||
/// <param name="post"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<string>> SaveBuildFloor([FromForm] BuildFloor post)
|
||||
{
|
||||
ApiResult<string> apiResult = new ApiResult<string>();
|
||||
|
||||
try
|
||||
{
|
||||
string sWhere = @$"deleted = @Deleted AND floor_guid = @Guid";
|
||||
|
||||
object param = new { Deleted = 0, Guid = post.Floor_guid };
|
||||
|
||||
var buildFloor = await backendRepository.GetOneAsync<BuildFloor>("floor", sWhere, param);
|
||||
|
||||
if (buildFloor == null)
|
||||
{
|
||||
//新增
|
||||
//產生一組GUID
|
||||
var guid = Guid.NewGuid();
|
||||
var floor_map_guid = Guid.NewGuid();
|
||||
|
||||
//抓取當前的Priority
|
||||
var current_priority = await backendRepository.GetCurrentPriority("floor", "deleted = 0 AND building_guid = '" + post.Building_guid + "'");
|
||||
|
||||
Dictionary<string, object> floor = new Dictionary<string, object>();
|
||||
floor = new Dictionary<string, object>()
|
||||
{
|
||||
{ "@floor_guid", guid},
|
||||
{ "@building_guid", post.Building_guid},
|
||||
{ "@full_name", post.Full_name},
|
||||
{ "@InitMapName", post.InitMapName},
|
||||
{ "@floor_map_name", floor_map_guid},
|
||||
{ "@priority", current_priority + 1},
|
||||
{ "@created_by", myUserInfo.Userinfo_guid}
|
||||
};
|
||||
await backendRepository.AddOneByCustomTable(floor, "floor");
|
||||
|
||||
if (post.MapFile != null)
|
||||
{
|
||||
var split = post.MapFile.FileName.Split(".");
|
||||
var fileName = floor_map_guid + "." + split[split.Length - 1];
|
||||
|
||||
var fullPath = Path.Combine(mapFileSaveAsPath, fileName);
|
||||
|
||||
using (var stream = new FileStream(fullPath, FileMode.Create))
|
||||
{
|
||||
post.MapFile.CopyTo(stream);
|
||||
}
|
||||
}
|
||||
|
||||
#region 新增至派送資料表
|
||||
List<Repository.Models.FileInfo> fileInfos = new List<Repository.Models.FileInfo>();
|
||||
if (post.MapFile != null)
|
||||
{
|
||||
var split = post.MapFile.FileName.Split(".");
|
||||
var fileName = floor_map_guid + "." + split[split.Length - 1];
|
||||
|
||||
var fullPath = Path.Combine(mapFileSaveAsPath, fileName);
|
||||
|
||||
Repository.Models.FileInfo fileInfo = new Repository.Models.FileInfo();
|
||||
fileInfo.Folder = "floor_map";
|
||||
fileInfo.OriginalFileName = null;
|
||||
fileInfo.FileName = fileName;
|
||||
fileInfo.File = fullPath;
|
||||
|
||||
fileInfos.Add(fileInfo);
|
||||
await backendRepository.ManualInsertFileBackgroundServiceTask("", post.Building_guid, "floor", fileInfos);
|
||||
}
|
||||
#endregion
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "新增成功";
|
||||
}
|
||||
else //修改
|
||||
{
|
||||
Dictionary<string, object> floor = new Dictionary<string, object>();
|
||||
floor = new Dictionary<string, object>()
|
||||
{
|
||||
{ "@full_name", post.Full_name},
|
||||
{ "@InitMapName", post.InitMapName},
|
||||
{ "@updated_by", myUserInfo.Userinfo_guid},
|
||||
{ "@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}
|
||||
};
|
||||
await backendRepository.UpdateOneByCustomTable(floor, "floor", "floor_guid='" + post.Floor_guid + "'");
|
||||
|
||||
var floor_map_guid = Guid.NewGuid();
|
||||
if (post.MapFile != null)
|
||||
{
|
||||
//刪除原本檔案
|
||||
FolderFunction folderFunction = new FolderFunction();
|
||||
folderFunction.DeleteFile(Path.Combine(mapFileSaveAsPath, buildFloor.Floor_map_name + ".svg"));
|
||||
|
||||
Dictionary<string, object> floor_map_dic = new Dictionary<string, object>();
|
||||
floor_map_dic = new Dictionary<string, object>()
|
||||
{
|
||||
{ "@floor_map_name", floor_map_guid},
|
||||
};
|
||||
await backendRepository.UpdateOneByCustomTable(floor_map_dic, "floor", "floor_guid='" + post.Floor_guid + "'");
|
||||
|
||||
var split = post.MapFile.FileName.Split(".");
|
||||
var fileName = floor_map_guid + "." + split[split.Length - 1];
|
||||
|
||||
var fullPath = Path.Combine(mapFileSaveAsPath, fileName);
|
||||
|
||||
using (var stream = new FileStream(fullPath, FileMode.Create))
|
||||
{
|
||||
post.MapFile.CopyTo(stream);
|
||||
}
|
||||
}
|
||||
|
||||
#region 新增至派送資料表
|
||||
List<Repository.Models.FileInfo> fileInfos = new List<Repository.Models.FileInfo>();
|
||||
if (post.MapFile != null)
|
||||
{
|
||||
var split = post.MapFile.FileName.Split(".");
|
||||
var fileName = floor_map_guid + "." + split[split.Length - 1];
|
||||
|
||||
var fullPath = Path.Combine(mapFileSaveAsPath, fileName);
|
||||
|
||||
Repository.Models.FileInfo fileInfo = new Repository.Models.FileInfo();
|
||||
fileInfo.Folder = "floor_map";
|
||||
fileInfo.OriginalFileName = buildFloor.Floor_map_name + ".svg";
|
||||
fileInfo.FileName = fileName;
|
||||
fileInfo.File = fullPath;
|
||||
|
||||
fileInfos.Add(fileInfo);
|
||||
}
|
||||
await backendRepository.ManualInsertFileBackgroundServiceTask("", post.Building_guid, "floor", fileInfos);
|
||||
#endregion
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "修改成功";
|
||||
}
|
||||
}
|
||||
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>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<List<string>>> ChangeFloorPriority(PostFloorPriority post)
|
||||
{
|
||||
ApiResult<List<string>> apiResult = new ApiResult<List<string>>();
|
||||
try
|
||||
{
|
||||
List<Dictionary<string, object>> floor_priorities = new List<Dictionary<string, object>>();
|
||||
if (post.FloorPriorities != null)
|
||||
{
|
||||
foreach (var floor_priority in post.FloorPriorities)
|
||||
{
|
||||
Dictionary<string, object> floor_priority_dic = new Dictionary<string, object>();
|
||||
floor_priority_dic = new Dictionary<string, object>()
|
||||
{
|
||||
{ "@floor_guid", floor_priority.Floor_guid},
|
||||
{ "@priority", floor_priority.Priority},
|
||||
{ "@updated_by", myUserInfo.Userinfo_guid},
|
||||
{ "@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}
|
||||
};
|
||||
|
||||
floor_priorities.Add(floor_priority_dic);
|
||||
}
|
||||
|
||||
var sql = $@"UPDATE floor SET priority = @priority, updated_by = @updated_by, updated_at=@updated_at WHERE floor_guid = @floor_guid";
|
||||
|
||||
await backendRepository.ExecuteSql(sql, floor_priorities);
|
||||
|
||||
#region 新增至派送資料表
|
||||
await backendRepository.ManualInsertBackgroundServiceTask("", "", "floor", "update_list", floor_priorities);
|
||||
#endregion
|
||||
}
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "修改成功";
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
}
|
||||
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 刪除單一樓層設定
|
||||
/// </summary>
|
||||
/// <param name="guid"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<string>> DeleteOneFloor(string guid)
|
||||
{
|
||||
var apiResult = new ApiResult<string>();
|
||||
try
|
||||
{
|
||||
string sWhere = @$"deleted = @Deleted AND floor_guid = @Guid";
|
||||
|
||||
object param = new { Deleted = 0, Guid = guid };
|
||||
|
||||
var buildFloor = await backendRepository.GetOneAsync<BuildFloor>("floor", sWhere, param);
|
||||
|
||||
if (buildFloor == null)
|
||||
{
|
||||
apiResult.Code = "9998";
|
||||
apiResult.Msg = "查無該樓層設定";
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
//判斷區域選單是否還有使用該樓層
|
||||
var sub_system_where = $@"SELECT
|
||||
CONCAT(b.full_name, ' - ', ms.full_name, ' - ', ss.full_name)
|
||||
FROM (
|
||||
SELECT
|
||||
ssf.building_guid,
|
||||
ssf.main_system_guid,
|
||||
ssf.sub_system_guid
|
||||
FROM sub_system_floor ssf
|
||||
WHERE ssf.deleted = 0 AND floor_guid = @Guid
|
||||
) ssf
|
||||
LEFT JOIN building b ON ssf.building_guid = b.building_guid AND b.deleted = 0
|
||||
LEFT JOIN main_system ms ON ssf.main_system_guid = ms.main_system_guid AND ms.deleted = 0
|
||||
LEFT JOIN sub_system ss ON ssf.sub_system_guid = ss.sub_system_guid AND ss.deleted = 0";
|
||||
|
||||
var sub_system_floors = await backendRepository.GetAllAsync<string>(sub_system_where, new { Guid = guid });
|
||||
if (sub_system_floors.Count > 0)
|
||||
{
|
||||
apiResult.Code = "9997";
|
||||
apiResult.Msg = "區域選單中尚有以下選單正在使用該樓層,故無法刪除";
|
||||
apiResult.Data = string.Join("<br>", sub_system_floors);
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
await backendRepository.DeleteOne(guid, "floor", "floor_guid");
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "刪除成功";
|
||||
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + "floor_guid=" + guid);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
}
|
||||
return apiResult;
|
||||
}
|
||||
}
|
||||
}
|
557
Backend/Controllers/BuildMenuController.cs
Normal file
557
Backend/Controllers/BuildMenuController.cs
Normal file
@ -0,0 +1,557 @@
|
||||
using Backend.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Repository.BackendRepository.Interface;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Backend.Controllers
|
||||
{
|
||||
public class BuildMenuController : MybaseController<BuildMenuController>
|
||||
{
|
||||
private readonly IBackendRepository backendRepository;
|
||||
public BuildMenuController(IBackendRepository backendRepository)
|
||||
{
|
||||
this.backendRepository = backendRepository;
|
||||
}
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
[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<ApiResult<List<KeyValue>>> MainListBybuild(string build)
|
||||
{
|
||||
ApiResult<List<KeyValue>> apiResult = new ApiResult<List<KeyValue>>();
|
||||
List<KeyValue> KeyValue = new List<KeyValue>();
|
||||
|
||||
try
|
||||
{
|
||||
var sqlString = @$"select ms.main_system_guid value, ms.full_name name from (select main_system_guid from building_menu bm where bm.building_guid = '{build}' group by bm.main_system_guid ) bm left join main_system ms on ms.main_system_guid = bm.main_system_guid ORDER BY ms.priority ASC";
|
||||
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<ApiResult<List<KeyValue>>> MainList()
|
||||
{
|
||||
ApiResult<List<KeyValue>> apiResult = new ApiResult<List<KeyValue>>();
|
||||
List<KeyValue> KeyValue = new List<KeyValue>();
|
||||
try
|
||||
{
|
||||
var sqlString = @$"select ms.full_name Name,ms.main_system_guid Value from main_system ms where ms.deleted = 0 and ms.status = 0 ORDER BY ms.priority ASC";
|
||||
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<ApiResult<List<KeyValue>>> SubListNotAdd(SubListIn post)
|
||||
{
|
||||
ApiResult<List<KeyValue>> apiResult = new ApiResult<List<KeyValue>>();
|
||||
List<KeyValue> KeyValue = new List<KeyValue>();
|
||||
try
|
||||
{
|
||||
var sqlString = @$"select
|
||||
ss.sub_system_guid value,ss.full_name name
|
||||
from sub_system ss
|
||||
left join (
|
||||
select * from building_menu bm where bm.building_guid = '{post.build}') bm
|
||||
on ss.sub_system_guid = bm.sub_system_guid
|
||||
where bm.sub_system_guid is null and ss.deleted = 0 and ss.status = 0 and ss.main_system_guid = @guid ORDER BY ss.priority ASC, ss.created_at DESC";
|
||||
KeyValue = await backendRepository.GetAllAsync<KeyValue>(sqlString, new { guid = post.main });
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Data = KeyValue;
|
||||
}
|
||||
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;
|
||||
}
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<string>> SavebuildMenuModal(BuildMenu buildMenu)
|
||||
{
|
||||
ApiResult<string> apiResult = new ApiResult<string>();
|
||||
try
|
||||
{
|
||||
var get = await backendRepository.GetOneAsync<BuildMenu>("building_menu", $"building_guid = '{buildMenu.building_guid}' and main_system_guid = '{buildMenu.main_system_guid}' and sub_system_guid = '{buildMenu.sub_system_guid}'");
|
||||
if (get == null)
|
||||
{
|
||||
var dictionary = new Dictionary<string, object>()
|
||||
{
|
||||
{"@building_guid", buildMenu.building_guid},
|
||||
{"@main_system_guid",buildMenu.main_system_guid },
|
||||
{"@sub_system_guid", buildMenu.sub_system_guid},
|
||||
{"@drawing",buildMenu.drawing },
|
||||
{"@created_by",myUserInfo.Userinfo_guid },
|
||||
{"@planimetric_click",buildMenu.planimetric_click}
|
||||
};
|
||||
|
||||
if (buildMenu.drawing == 2)
|
||||
{
|
||||
if (buildMenu.system_url != null && buildMenu.system_url.CompareTo("http://") < 0 && buildMenu.system_url.CompareTo("https://") < 0)
|
||||
{
|
||||
//未包含http || https 抓該棟ip + port
|
||||
var building_where = @"deleted = 0 AND building_guid = @Building_guid";
|
||||
var building = await backendRepository.GetOneAsync<BuildInfo>("building", building_where, new { Building_guid = buildMenu.building_guid });
|
||||
|
||||
buildMenu.system_url = string.Format("http://{0}:{1}{2}", building.Ip_address, building.Ip_port, buildMenu.system_url);
|
||||
}
|
||||
|
||||
dictionary.Add("@system_url", buildMenu.system_url);
|
||||
}
|
||||
else if (buildMenu.drawing == 4)
|
||||
{
|
||||
if (buildMenu.system_url != null && buildMenu.system_url.CompareTo("http://") < 0 && buildMenu.system_url.CompareTo("https://") < 0)
|
||||
{
|
||||
//未包含http || https 抓該棟ip + port
|
||||
var building_where = @"deleted = 0 AND building_guid = @Building_guid";
|
||||
var building = await backendRepository.GetOneAsync<BuildInfo>("building", building_where, new { Building_guid = buildMenu.building_guid });
|
||||
|
||||
buildMenu.system_url = string.Format("http://{0}:{1}{2}", building.Ip_address, building.Ip_port, buildMenu.system_url);
|
||||
}
|
||||
|
||||
dictionary.Add("@riser_diagram_url", buildMenu.riser_diagram_url);
|
||||
dictionary.Add("@icon_click", buildMenu.icon_click);
|
||||
dictionary.Add("@icon_click_url", buildMenu.icon_click_url);
|
||||
dictionary.Add("@icon_click_url_width", buildMenu.icon_click_url_width);
|
||||
dictionary.Add("@icon_click_url_height", buildMenu.icon_click_url_height);
|
||||
}
|
||||
else if (buildMenu.drawing == 1)
|
||||
{
|
||||
dictionary.Add("@planimetric_floor_guid", buildMenu.planimetric_floor_guid);
|
||||
}
|
||||
|
||||
await backendRepository.AddOneByCustomTable(dictionary, "building_menu");
|
||||
|
||||
var max = await backendRepository.GetOneAsync<int>("select Max(CONVERT(int,SUBSTRING(AuthCode,2,5))) AuthCode from auth_page ap where ap.AuthCode like 'F%'");
|
||||
var page = await backendRepository.GetOneAsync<Auth_page>($"select ss.full_name SubName,ms.full_name MainName from sub_system ss left join main_system ms on ms.main_system_guid = ss.main_system_guid where ss.sub_system_guid = '{buildMenu.sub_system_guid}' and ms.main_system_guid = '{buildMenu.main_system_guid}'");
|
||||
|
||||
var pagedictionary = new Dictionary<string, object>()
|
||||
{
|
||||
{"@AuthCode", "F" +(max+1).ToString() },
|
||||
{"@AuthType", 1 },
|
||||
{"@MainName", page.MainName},
|
||||
{"@SubName",page.SubName},
|
||||
{"@building_guid",buildMenu.building_guid},
|
||||
{"@ShowView",buildMenu.sub_system_guid}
|
||||
};
|
||||
await backendRepository.AddOneByCustomTable(pagedictionary, "auth_page");
|
||||
|
||||
await backendRepository.ExecuteSql(@"DELETE FROM auth_page
|
||||
WHERE auth_page.AuthCode like 'F%';
|
||||
INSERT INTO auth_page (AuthCode,AuthType,MainName,SubName,building_guid,ShowView)
|
||||
SELECT 'F' + CONVERT(varchar,ROW_NUMBER() OVER(ORDER BY bm.building_guid ASC)) AuthCode,'1' AuthType,ms.full_name MainName,ss.full_name SubName,bm.building_guid,bm.sub_system_guid ShowView FROM building_menu bm
|
||||
left join main_system ms on ms.main_system_guid = bm.main_system_guid
|
||||
left join sub_system ss on ss.sub_system_guid = bm.sub_system_guid");
|
||||
|
||||
await backendRepository.ExecuteSql(@"delete a from role_auth a join role b on a.role_guid = b.role_guid where b.layer = 0;
|
||||
INSERT INTO role_auth (role_guid,AuthCode,created_by)
|
||||
SELECT r.role_guid,ap.AuthCode,'0' created_by FROM auth_page ap,role r
|
||||
WHERE r.layer = 0;");
|
||||
|
||||
#region 新增至派送資料表
|
||||
var sql = $@"SELECT ra.* FROM role_auth ra join role r on ra.role_guid = r.role_guid where r.layer = 0";
|
||||
var role_auths = await backendRepository.GetAllAsync<RoleAuthList>(sql);
|
||||
|
||||
List<Dictionary<string, object>> role_auth_dicts = new List<Dictionary<string, object>>();
|
||||
foreach (var role_auth in role_auths)
|
||||
{
|
||||
Dictionary<string, object> role_auth_dict = new Dictionary<string, object>()
|
||||
{
|
||||
{ "role_guid", role_auth.Role_guid},
|
||||
{ "@AuthCode", role_auth.AuthCode},
|
||||
};
|
||||
|
||||
role_auth_dicts.Add(role_auth_dict);
|
||||
}
|
||||
|
||||
await backendRepository.ManualInsertBackgroundServiceTask("", "", "role_auth", "purge_specify_insert", role_auth_dicts);
|
||||
#endregion
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "儲存成功";
|
||||
}
|
||||
else
|
||||
{
|
||||
var dictionary = new Dictionary<string, object>()
|
||||
{
|
||||
{"@drawing",buildMenu.drawing },
|
||||
{"@updated_by",myUserInfo.Userinfo_guid },
|
||||
{"@updated_at",DateTime.Now },
|
||||
{"@planimetric_click",buildMenu.planimetric_click}
|
||||
};
|
||||
if (buildMenu.drawing == 2)
|
||||
{
|
||||
if (buildMenu.system_url != null && buildMenu.system_url.CompareTo("http://") < 0 && buildMenu.system_url.CompareTo("https://") < 0)
|
||||
{
|
||||
//未包含http || https 抓該棟ip + port
|
||||
var building_where = @"deleted = 0 AND building_guid = @Building_guid";
|
||||
var building = await backendRepository.GetOneAsync<BuildInfo>("building", building_where, new { Building_guid = buildMenu.building_guid });
|
||||
|
||||
buildMenu.system_url = string.Format("http://{0}:{1}{2}", building.Ip_address, building.Ip_port, buildMenu.system_url);
|
||||
}
|
||||
|
||||
dictionary.Add("@system_url", buildMenu.system_url);
|
||||
}
|
||||
else if (buildMenu.drawing == 4)
|
||||
{
|
||||
if (buildMenu.system_url != null && buildMenu.system_url.CompareTo("http://") < 0 && buildMenu.system_url.CompareTo("https://") < 0)
|
||||
{
|
||||
//未包含http || https 抓該棟ip + port
|
||||
var building_where = @"deleted = 0 AND building_guid = @Building_guid";
|
||||
var building = await backendRepository.GetOneAsync<BuildInfo>("building", building_where, new { Building_guid = buildMenu.building_guid });
|
||||
|
||||
buildMenu.system_url = string.Format("http://{0}:{1}{2}", building.Ip_address, building.Ip_port, buildMenu.system_url);
|
||||
}
|
||||
|
||||
dictionary.Add("@riser_diagram_url", buildMenu.riser_diagram_url);
|
||||
dictionary.Add("@icon_click", buildMenu.icon_click);
|
||||
dictionary.Add("@icon_click_url", buildMenu.icon_click_url);
|
||||
dictionary.Add("@icon_click_url_width", buildMenu.icon_click_url_width);
|
||||
dictionary.Add("@icon_click_url_height", buildMenu.icon_click_url_height);
|
||||
}
|
||||
else if (buildMenu.drawing == 1)
|
||||
{
|
||||
dictionary.Add("@planimetric_floor_guid", buildMenu.planimetric_floor_guid);
|
||||
}
|
||||
|
||||
await backendRepository.UpdateOneByCustomTable(dictionary, "building_menu", $"building_guid = '{buildMenu.building_guid}' and main_system_guid = '{buildMenu.main_system_guid}' and sub_system_guid = '{buildMenu.sub_system_guid}'");
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "儲存成功";
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
string json = System.Text.Json.JsonSerializer.Serialize(buildMenu);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + json);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
}
|
||||
return apiResult;
|
||||
}
|
||||
[HttpPost]
|
||||
public async Task<ActionResult> BuildMenuTable(BuildMenuTablePost post)
|
||||
{
|
||||
List<BuildMenuTable> buildMenuTables = new List<BuildMenuTable>();
|
||||
ApiResult<List<BuildMenuTable>> apiResult = new ApiResult<List<BuildMenuTable>>();
|
||||
try
|
||||
{
|
||||
buildMenuTables = await backendRepository.GetAllAsync<BuildMenuTable>($@"select bm.*,
|
||||
case drawing when 1 then '樓層平面圖' when 2 then '系統圖' when 4 then '昇位圖' end drawing_name,
|
||||
case icon_click when 1 then '開' when 0 then '關' end icon_click_name,
|
||||
case planimetric_click when 1 then '開' when 0 then '關' end planimetric_click_name,
|
||||
ms.full_name main_system_guid_name, ss.full_name sub_system_guid_name,ff.full_name floor_guid_name
|
||||
from building_menu bm
|
||||
left join main_system ms on ms.main_system_guid = bm.main_system_guid
|
||||
left join sub_system ss on ss.sub_system_guid = bm.sub_system_guid
|
||||
left join floor ff on ff.floor_guid = bm.planimetric_floor_guid
|
||||
where bm.building_guid = '{post.build}' and bm.main_system_guid in @MainList ORDER BY ms.priority ASC, ss.priority ASC, ss.created_at DESC ", new { MainList = post.MainList });
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Data = buildMenuTables;
|
||||
}
|
||||
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<ApiResult<BuildMenuAddSub>> GetBuildMenu(MenuIn post)
|
||||
{
|
||||
ApiResult<BuildMenuAddSub> apiResult = new ApiResult<BuildMenuAddSub>();
|
||||
try
|
||||
{
|
||||
var BuildMenu = await backendRepository.GetOneAsync<BuildMenuAddSub>(
|
||||
$@"select *,ss.full_name sub_system_guid_name from building_menu bm
|
||||
left join sub_system ss on bm.sub_system_guid = ss.sub_system_guid
|
||||
where bm.building_guid = @bg and bm.main_system_guid = @msg and bm.sub_system_guid = @ssg", new { bg = post.build, msg = post.main, ssg = post.sub });
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Data = BuildMenu;
|
||||
}
|
||||
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;
|
||||
}
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<string>> DeleteBuildMenu(MenuIn post)
|
||||
{
|
||||
ApiResult<string> apiResult = new ApiResult<string>();
|
||||
try
|
||||
{
|
||||
await backendRepository.PurgeOneByGuidWithCustomDBNameAndTable("building_menu", $"building_guid = '{post.build}' and main_system_guid = '{post.main}' and sub_system_guid = '{post.sub}'");
|
||||
var authcode = await backendRepository.GetOneAsync<string>(@$"select AuthCode from auth_page where building_guid = '{post.build}' and ShowView = '{post.sub}'");
|
||||
if (authcode != null)
|
||||
{
|
||||
await backendRepository.PurgeOneByGuidWithCustomDBNameAndTable("role_auth", $" AuthCode = '{authcode}'");
|
||||
await backendRepository.PurgeOneByGuidWithCustomDBNameAndTable("auth_page", $" AuthCode = '{authcode}'");
|
||||
await backendRepository.ExecuteSql(@"delete a from role_auth a join role b on a.role_guid = b.role_guid where b.layer = 0;
|
||||
INSERT INTO role_auth (role_guid,AuthCode,created_by)
|
||||
SELECT r.role_guid,ap.AuthCode,'0' created_by FROM auth_page ap,role r
|
||||
WHERE r.layer = 0;");
|
||||
|
||||
#region 新增至派送資料表
|
||||
var sql = $@"SELECT ra.* FROM role_auth ra join role r on ra.role_guid = r.role_guid where r.layer = 0";
|
||||
var role_auths = await backendRepository.GetAllAsync<RoleAuthList>(sql);
|
||||
|
||||
List<Dictionary<string, object>> role_auth_dicts = new List<Dictionary<string, object>>();
|
||||
foreach (var role_auth in role_auths)
|
||||
{
|
||||
Dictionary<string, object> role_auth_dict = new Dictionary<string, object>()
|
||||
{
|
||||
{ "role_guid", role_auth.Role_guid},
|
||||
{ "@AuthCode", role_auth.AuthCode},
|
||||
};
|
||||
|
||||
role_auth_dicts.Add(role_auth_dict);
|
||||
}
|
||||
|
||||
await backendRepository.ManualInsertBackgroundServiceTask("", "", "role_auth", "purge_specify_insert", role_auth_dicts);
|
||||
#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;
|
||||
}
|
||||
[HttpPost]
|
||||
public async Task<ActionResult> BuildMenuFloorTable(MenuIn post)
|
||||
{
|
||||
List<BuildMenuFloorTable> buildMenuFloorTables = new List<BuildMenuFloorTable>();
|
||||
ApiResult<List<BuildMenuFloorTable>> apiResult = new ApiResult<List<BuildMenuFloorTable>>();
|
||||
try
|
||||
{
|
||||
buildMenuFloorTables = await backendRepository.GetAllAsync<BuildMenuFloorTable>($@"
|
||||
select f.full_name floor_guid_name,sf.*,ms.full_name main_system_guid_name,ss.full_name sub_system_guid_name
|
||||
from (select * from sub_system_floor ssf where ssf.building_guid = '{post.build}' and ssf.main_system_guid = '{post.main}' and ssf.sub_system_guid = '{post.sub}' and deleted = 0 and status = 0) sf
|
||||
left join floor f on sf.floor_guid = f.floor_guid
|
||||
left join main_system ms on ms.main_system_guid = sf.main_system_guid
|
||||
left join sub_system ss on ss.sub_system_guid = sf.sub_system_guid
|
||||
ORDER BY ms.priority, ss.priority, f.priority");
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Data = buildMenuFloorTables;
|
||||
}
|
||||
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<ApiResult<List<KeyValue>>> GetNotUsefloor(MenuIn post)
|
||||
{
|
||||
ApiResult<List<KeyValue>> apiResult = new ApiResult<List<KeyValue>>();
|
||||
List<KeyValue> KeyValue = new List<KeyValue>();
|
||||
try
|
||||
{
|
||||
var sqlString = @$"select fg.floor_guid value, fg.full_name name from
|
||||
(select * from floor fg where fg.building_guid = '{post.build}' and fg.deleted = 0 and fg.status = 0 ) fg
|
||||
left join (select * from sub_system_floor where building_guid = '{post.build}' and main_system_guid = '{post.main}' and sub_system_guid = '{post.sub}' and deleted = 0 and status = 0) ssf
|
||||
on ssf.floor_guid = fg.floor_guid
|
||||
where ssf.floor_guid is null ORDER BY fg.priority";
|
||||
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<ApiResult<string>> SaveAddsubfloor(MenuInfloor menuInfloor)
|
||||
{
|
||||
ApiResult<string> apiResult = new ApiResult<string>();
|
||||
try
|
||||
{
|
||||
var listdictionary = new List<Dictionary<string, object>>();
|
||||
|
||||
foreach (var a in menuInfloor.floorlist)
|
||||
{
|
||||
var dictionary = new Dictionary<string, object>()
|
||||
{
|
||||
{"@sub_system_floor_guid", Guid.NewGuid()},
|
||||
{"@building_guid",menuInfloor.build},
|
||||
{"@main_system_guid", menuInfloor.main},
|
||||
{"@sub_system_guid",menuInfloor.sub},
|
||||
{"@floor_guid",a},
|
||||
{"@created_by", myUserInfo.Userinfo_guid}
|
||||
};
|
||||
listdictionary.Add(dictionary);
|
||||
}
|
||||
await backendRepository.AddMutiByCustomTable(listdictionary, "sub_system_floor");
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "儲存成功";
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
string json = System.Text.Json.JsonSerializer.Serialize(menuInfloor);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + json);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
}
|
||||
return apiResult;
|
||||
}
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<string>> DeleteBuildFloorMenu(string subfloorguid)
|
||||
{
|
||||
ApiResult<string> apiResult = new ApiResult<string>();
|
||||
try
|
||||
{
|
||||
//檢查該樓層底下是否有設備
|
||||
var sql = $@"
|
||||
SELECT
|
||||
CONCAT(b.full_name, ' - ', ms.full_name, ' - ', ss.full_name , ' - ', f.full_name)
|
||||
FROM device d
|
||||
LEFT JOIN (
|
||||
SELECT *
|
||||
FROM sub_system_floor ssf
|
||||
WHERE ssf.deleted = 0 AND ssf.sub_system_floor_guid = @Guid) ssf
|
||||
ON d.deleted = 0
|
||||
AND d.building_guid = ssf.building_guid
|
||||
AND d.main_system_guid = ssf.main_system_guid
|
||||
AND d.sub_system_guid = ssf.sub_system_guid
|
||||
AND d.floor_guid = ssf.floor_guid
|
||||
LEFT JOIN building b ON b.deleted = 0 AND d.building_guid = b.building_guid
|
||||
LEFT JOIN main_system ms ON ms.deleted = 0 AND d.main_system_guid = ms.main_system_guid
|
||||
LEFT JOIN sub_system ss ON ss.deleted = 0 AND d.sub_system_guid = ss.sub_system_guid
|
||||
LEFT JOIN floor f ON f.deleted = 0 AND d.floor_guid = f.floor_guid
|
||||
WHERE ssf.sub_system_floor_guid = @Guid";
|
||||
|
||||
var sub_system_floors = await backendRepository.GetAllAsync<string>(sql, new { Guid = subfloorguid });
|
||||
if (sub_system_floors.Count > 0)
|
||||
{
|
||||
apiResult.Code = "9997";
|
||||
apiResult.Msg = "設備管理中尚有設備正在使用該選單樓層,故無法刪除";
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
await backendRepository.DeleteOne(subfloorguid, "sub_system_floor", "sub_system_floor_guid");
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "刪除成功";
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
string json = System.Text.Json.JsonSerializer.Serialize(subfloorguid);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + json);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
}
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<List<KeyValue>>> GetFloorInSubSystem(MenuIn post)
|
||||
{
|
||||
ApiResult<List<KeyValue>> apiResult = new ApiResult<List<KeyValue>>();
|
||||
List<KeyValue> KeyValue = new List<KeyValue>();
|
||||
try
|
||||
{
|
||||
var sqlString = @$"select floor.floor_guid Value,floor.full_name Name from sub_system_floor sf left join floor on sf.floor_guid = floor.floor_guid
|
||||
where sf.deleted = 0 and sf.status = 0 and sf.building_guid = '{post.build}' and sf.main_system_guid = '{post.main}' and sf.sub_system_guid = '{post.sub}'
|
||||
ORDER BY floor.priority, floor.created_at";
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
751
Backend/Controllers/DeviceImportController.cs
Normal file
751
Backend/Controllers/DeviceImportController.cs
Normal file
@ -0,0 +1,751 @@
|
||||
using Backend.Models;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
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.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Backend.Controllers
|
||||
{
|
||||
public class DeviceImportController : MybaseController<DeviceImportController>
|
||||
{
|
||||
private readonly IBackendRepository backendRepository;
|
||||
private readonly IDeviceImportRepository deviceImportRepository;
|
||||
|
||||
public DeviceImportController(IBackendRepository backendRepository, IDeviceImportRepository deviceImportRepository)
|
||||
{
|
||||
this.backendRepository = backendRepository;
|
||||
this.deviceImportRepository = deviceImportRepository;
|
||||
}
|
||||
|
||||
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 設備匯入列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<List<DeviceImport>>> RawDataList()
|
||||
{
|
||||
ApiResult<List<DeviceImport>> apiResult = new ApiResult<List<DeviceImport>>();
|
||||
List<DeviceImport> deviceImports = new List<DeviceImport>();
|
||||
|
||||
try
|
||||
{
|
||||
deviceImports = await backendRepository.GetAllAsync<DeviceImport>("device_import_temp", null, null, "device_result DESC,created_at DESC");
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Data = deviceImports;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
}
|
||||
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<string>> ImportRawDataFile(IFormFile[] import_files)
|
||||
{
|
||||
ApiResult<string> apiResult = new ApiResult<string>();
|
||||
|
||||
try
|
||||
{
|
||||
Dictionary<string, IWorkbook> workbooks = new Dictionary<string, IWorkbook>();
|
||||
|
||||
//List<IWorkbook> workbooks = new List<IWorkbook>();
|
||||
|
||||
#region 檢驗各檔案是否正確
|
||||
foreach (var import_file in import_files)
|
||||
{
|
||||
IWorkbook workbook;
|
||||
|
||||
var filename_ext = Path.GetExtension(import_file.FileName).ToLower();
|
||||
|
||||
if (filename_ext == ".xls")
|
||||
{
|
||||
workbook = new HSSFWorkbook(import_file.OpenReadStream());
|
||||
workbooks.Add($"{import_file.FileName}", workbook);
|
||||
}
|
||||
else if (filename_ext == ".xlsx")
|
||||
{
|
||||
workbook = new XSSFWorkbook(import_file.OpenReadStream());
|
||||
workbooks.Add($"{import_file.FileName}", workbook);
|
||||
}
|
||||
else
|
||||
{
|
||||
workbook = null;
|
||||
}
|
||||
|
||||
if (workbook == null)
|
||||
{
|
||||
apiResult.Code = "9998";
|
||||
apiResult.Msg = $"{import_file.FileName}該檔案失效,請重新操作。";
|
||||
|
||||
return apiResult;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
List<Dictionary<string, object>> deviceImports = new List<Dictionary<string, object>>();
|
||||
|
||||
//抓取系統類別(以供驗證判斷)
|
||||
var sWhere = @$"deleted = 0 AND system_type = @system_type";
|
||||
var system_category_param = new { system_type = "device_system_category_layer3" };
|
||||
var system_categories_layer3 = await backendRepository.GetAllAsync<Variable>("variable", sWhere, system_category_param);
|
||||
|
||||
var disaster_param = new { system_type = "disaster" };
|
||||
var disasters = await backendRepository.GetAllAsync<Variable>("variable", sWhere, disaster_param);
|
||||
var temp_building = ""; //預設的棟別(檢查用,整份excel需相同),目前只針對單一檔案情況,如後續有需再改成多檔情況。
|
||||
|
||||
#region 抓取每個檔案的資料
|
||||
foreach (var keyValuePair in workbooks)
|
||||
{
|
||||
IWorkbook workbook = keyValuePair.Value;
|
||||
|
||||
var total_sheet = workbook.NumberOfSheets;
|
||||
for (var sheet_num = 2; sheet_num < total_sheet - 1; sheet_num++)
|
||||
{
|
||||
var tags_name_index = -1;
|
||||
var system_category_index = -1; //系統類別
|
||||
var disaster_index = -1; //緊急應變程序(等同災害類別)
|
||||
var sheet = workbook.GetSheetAt(sheet_num);
|
||||
|
||||
//表頭
|
||||
IRow header = sheet.GetRow(sheet.FirstRowNum);
|
||||
List<int> columns = new List<int>();
|
||||
if (header != null)
|
||||
{
|
||||
for (int i = 0; i < header.LastCellNum; i++)
|
||||
{
|
||||
ICell cell = header.GetCell(i);
|
||||
if (cell != null)
|
||||
{
|
||||
var header_str = cell.ToString().ToLower();
|
||||
if (!string.IsNullOrEmpty(header_str) && header_str == "tags name")
|
||||
{
|
||||
tags_name_index = i;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(header_str) && header_str == "系統類別")
|
||||
{
|
||||
system_category_index = i;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(header_str) && header_str == "系統程式軟體")
|
||||
{
|
||||
IRow sub_header = sheet.GetRow(1);
|
||||
|
||||
for (int j = 0; j < sub_header.LastCellNum; j++)
|
||||
{
|
||||
ICell sub_cell = sub_header.GetCell(j);
|
||||
var sub_header_str = sub_cell.ToString().ToLower();
|
||||
if (!string.IsNullOrEmpty(sub_header_str) && sub_header_str == "緊急應變程序")
|
||||
{
|
||||
disaster_index = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (tags_name_index > 0 && system_category_index > 0 && disaster_index > 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//資料
|
||||
if (tags_name_index < 0 || system_category_index < 0 || disaster_index < 0)
|
||||
{
|
||||
List<string> errMsg = new List<string>();
|
||||
var result = $@"查無[{keyValuePair.Key}]在[{workbook.GetSheetName(sheet_num)}]分頁的";
|
||||
|
||||
if (tags_name_index < 0)
|
||||
{
|
||||
errMsg.Add($@"[tags name]");
|
||||
}
|
||||
|
||||
if (system_category_index < 0)
|
||||
{
|
||||
errMsg.Add($@"[系統類別]");
|
||||
}
|
||||
|
||||
if (disaster_index < 0)
|
||||
{
|
||||
errMsg.Add($@"[緊急應變程序]");
|
||||
}
|
||||
|
||||
Dictionary<string, object> deviceImport = new Dictionary<string, object>()
|
||||
{
|
||||
{ "@device_number", null},
|
||||
{ "@device_system_category_layer3", null},
|
||||
{ "@device_disaster", null},
|
||||
{ "@device_result", result + String.Join("、", errMsg)}
|
||||
};
|
||||
|
||||
deviceImports.Add(deviceImport);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (var i = sheet.FirstRowNum + 2; i < sheet.LastRowNum; i++)
|
||||
{
|
||||
|
||||
IRow row = sheet.GetRow(i);
|
||||
if (row != null)
|
||||
{
|
||||
List<string> errMsg = new List<string>();
|
||||
Dictionary<string, object> deviceImport = new Dictionary<string, object>();
|
||||
|
||||
ICell tags_name_cell = row.GetCell(tags_name_index);
|
||||
if (tags_name_cell != null)
|
||||
{
|
||||
var tempData = tags_name_cell.ToString().Trim();
|
||||
var system_category = string.Empty;
|
||||
var disaster = string.Empty;
|
||||
if (!string.IsNullOrEmpty(tempData))
|
||||
{
|
||||
var arr_tempData = tempData.Split('_');
|
||||
|
||||
#region tags name驗證條件
|
||||
if (string.IsNullOrEmpty(temp_building)) //抓第一筆當作該excel 比對棟別的依據
|
||||
{
|
||||
temp_building = arr_tempData[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (temp_building != arr_tempData[0])
|
||||
{
|
||||
errMsg.Add("資料棟別錯誤");
|
||||
}
|
||||
}
|
||||
|
||||
if (arr_tempData.Length != 5)
|
||||
{
|
||||
errMsg.Add("資料格式錯誤");
|
||||
}
|
||||
|
||||
if (arr_tempData[arr_tempData.Length - 1].Contains('~'))
|
||||
{
|
||||
errMsg.Add("設備流水號格式錯誤");
|
||||
}
|
||||
|
||||
if (arr_tempData[arr_tempData.Length - 1].Split('~').Length > 2)
|
||||
{
|
||||
errMsg.Add("設備流水號格式錯誤");
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 系統類別驗證條件
|
||||
ICell system_category_cell = row.GetCell(system_category_index);
|
||||
if (system_category_cell == null)
|
||||
{
|
||||
errMsg.Add(@"該設備的[系統類別]未填值");
|
||||
}
|
||||
else
|
||||
{
|
||||
system_category = system_category_cell.ToString().Trim();
|
||||
if (!string.IsNullOrEmpty(system_category))
|
||||
{
|
||||
var exist = system_categories_layer3.Exists(x => x.system_value == system_category);
|
||||
if (!exist)
|
||||
{
|
||||
errMsg.Add(@"該設備的[系統類別]不存在");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
errMsg.Add(@"該設備的[系統類別]未填值");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 緊急應變程序驗證條件
|
||||
ICell disaster_cell = row.GetCell(disaster_index);
|
||||
if (disaster_cell == null)
|
||||
{
|
||||
errMsg.Add(@"該設備的[緊急應變程序]未填值");
|
||||
}
|
||||
else
|
||||
{
|
||||
disaster = disaster_cell.ToString().Trim();
|
||||
if (!string.IsNullOrEmpty(disaster))
|
||||
{
|
||||
if (disaster != "0")
|
||||
{
|
||||
var exist = disasters.Exists(x => x.system_value == disaster);
|
||||
if (!exist)
|
||||
{
|
||||
errMsg.Add(@"該設備的[緊急應變程序]不存在");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
errMsg.Add(@"該設備的[緊急應變程序]未填值");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
if (errMsg.Count > 0)
|
||||
{
|
||||
deviceImport.Add("@device_number", tempData);
|
||||
deviceImport.Add("@device_system_category_layer3", system_category);
|
||||
deviceImport.Add("@device_disaster", disaster);
|
||||
deviceImport.Add("@device_result", String.Join(", ", errMsg));
|
||||
}
|
||||
else
|
||||
{
|
||||
deviceImport.Add("@device_number", tempData);
|
||||
deviceImport.Add("@device_system_category_layer3", system_category);
|
||||
deviceImport.Add("@device_disaster", disaster);
|
||||
deviceImport.Add("@device_result", null);
|
||||
}
|
||||
|
||||
deviceImports.Add(deviceImport);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
deviceImports = deviceImports.Distinct().ToList();
|
||||
|
||||
//先刪除整份資料表
|
||||
var sql = @"IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[device_import_temp]') AND type in (N'U'))
|
||||
BEGIN
|
||||
DROP TABLE [dbo].[device_import_temp];
|
||||
END
|
||||
CREATE TABLE [dbo].[device_import_temp](
|
||||
[id] [int] IDENTITY(1,1) NOT NULL,
|
||||
[device_number] [nvarchar](255) NULL,
|
||||
[device_system_category_layer3] [varchar](50) NULL,
|
||||
[device_disaster] [varchar](50) NULL,
|
||||
[device_result] [nvarchar](255) NULL,
|
||||
[created_at] [datetime] NULL,
|
||||
CONSTRAINT [PK_device_import_temp] PRIMARY KEY CLUSTERED
|
||||
(
|
||||
[id] ASC
|
||||
))
|
||||
ALTER TABLE [dbo].[device_import_temp] ADD CONSTRAINT [DF_device_import_temp_device_disaster] DEFAULT ((0)) FOR [device_disaster]
|
||||
ALTER TABLE [dbo].[device_import_temp] ADD CONSTRAINT [DF_device_import_temp_created_at] DEFAULT (getdate()) FOR [created_at]
|
||||
";
|
||||
await backendRepository.ExecuteSql(sql);
|
||||
|
||||
//如有發現錯誤,直接insert 至 device_import_temp,不做後續處理
|
||||
await backendRepository.AddMutiByCustomTable(deviceImports, "device_import_temp");
|
||||
|
||||
//var err = deviceImports.Where(x => x.ContainsKey("@device_result")).Select(x => x.Values).ToList();
|
||||
var err = deviceImports.SelectMany(x => x).Where(x => x.Key == "@device_result" && x.Value != null).ToList();
|
||||
if (err.Count > 0)
|
||||
{
|
||||
apiResult.Code = "9997";
|
||||
apiResult.Msg = "資料內容有誤,請重新匯入。";
|
||||
|
||||
return apiResult;
|
||||
}
|
||||
else
|
||||
{
|
||||
//拆分每一份資料
|
||||
List<Dictionary<string, object>> deviceImportChecks = new List<Dictionary<string, object>>(); //檢查OK的列表
|
||||
|
||||
|
||||
foreach (var deviceImport in deviceImports)
|
||||
{
|
||||
|
||||
object device_number = null;
|
||||
object device_system_category_layer3 = null;
|
||||
object device_disaster = null;
|
||||
deviceImport.TryGetValue("@device_number", out device_number);
|
||||
deviceImport.TryGetValue("@device_system_category_layer3", out device_system_category_layer3);
|
||||
deviceImport.TryGetValue("@device_disaster", out device_disaster);
|
||||
|
||||
var arr_device_number = device_number.ToString().Split('_');
|
||||
|
||||
//抓出是否為組數的設備
|
||||
var arr_device_number_final_col = arr_device_number[arr_device_number.Length - 1].Contains('~') ? arr_device_number[arr_device_number.Length - 1].Split('~') : null;
|
||||
if (arr_device_number_final_col != null && arr_device_number_final_col.Length > 0)
|
||||
{
|
||||
var start_num = Convert.ToInt32(arr_device_number_final_col[0].Trim());
|
||||
var end_num = Convert.ToInt32(arr_device_number_final_col[1].Trim());
|
||||
for (var i = start_num; i <= end_num; i++)
|
||||
{
|
||||
Dictionary<string, object> deviceImportCheck = new Dictionary<string, object>();
|
||||
var pre_device_number = String.Join('_', arr_device_number, 0, 4);
|
||||
deviceImportCheck.Add("@device_building_tag", arr_device_number[0]); //設備區域
|
||||
deviceImportCheck.Add("@device_system_tag", arr_device_number[1]); //設備系統別
|
||||
deviceImportCheck.Add("@device_floor_tag", arr_device_number[2]); //設備樓層
|
||||
deviceImportCheck.Add("@device_name_tag", arr_device_number[3]); //設備名稱
|
||||
|
||||
var pad = string.Empty;
|
||||
if(i < 10)
|
||||
{
|
||||
pad = i.ToString().PadLeft(2, '0');
|
||||
}
|
||||
else
|
||||
{
|
||||
pad = i.ToString();
|
||||
}
|
||||
deviceImportCheck.Add("@device_serial_tag", pad); //設備流水號
|
||||
|
||||
deviceImportCheck.Add("@device_number", pre_device_number + "_" + pad); //設備完整編號
|
||||
deviceImportCheck.Add("@device_system_category_layer3", device_system_category_layer3.ToString()); //系統類別(第3層)
|
||||
deviceImportCheck.Add("@device_disaster", device_disaster.ToString()); //緊急應變程序
|
||||
deviceImportCheck.Add("@is_correct", 0); //驗證是否正確
|
||||
|
||||
deviceImportChecks.Add(deviceImportCheck);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Dictionary<string, object> deviceImportCheck = new Dictionary<string, object>();
|
||||
var pre_device_number = String.Join('_', arr_device_number, 0, 3);
|
||||
deviceImportCheck.Add("@device_building_tag", arr_device_number[0]); //設備區域
|
||||
deviceImportCheck.Add("@device_system_tag", arr_device_number[1]); //設備系統別
|
||||
deviceImportCheck.Add("@device_floor_tag", arr_device_number[2]); //設備樓層
|
||||
deviceImportCheck.Add("@device_name_tag", arr_device_number[3]); //設備名稱
|
||||
deviceImportCheck.Add("@device_serial_tag", arr_device_number[4]); //設備流水號
|
||||
deviceImportCheck.Add("@device_number", device_number); //設備完整編號
|
||||
deviceImportCheck.Add("@device_system_category_layer3", device_system_category_layer3.ToString()); //系統類別(第3層)
|
||||
deviceImportCheck.Add("@device_disaster", device_disaster.ToString()); //緊急應變程序
|
||||
deviceImportCheck.Add("@is_correct", 0); //驗證是否正確
|
||||
|
||||
deviceImportChecks.Add(deviceImportCheck);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//針對棟別刪除檢查OK的設備查詢表
|
||||
var sDeleteWhere = $@"device_building_tag = '{temp_building}'";
|
||||
await backendRepository.PurgeOneByGuidWithCustomDBNameAndTable("device_import_ckeck_temp", sDeleteWhere);
|
||||
|
||||
//var sql_check = @"IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[device_import_ckeck_temp]') AND type in (N'U'))
|
||||
// BEGIN
|
||||
// DROP TABLE [dbo].[device_import_ckeck_temp]
|
||||
// END
|
||||
// CREATE TABLE [dbo].[device_import_ckeck_temp](
|
||||
// [id] [int] IDENTITY(1,1) NOT NULL,
|
||||
// [device_building_tag] [nvarchar](50) NULL,
|
||||
// [device_system_tag] [nvarchar](50) NULL,
|
||||
// [device_floor_tag] [nvarchar](50) NULL,
|
||||
// [device_kind] [nvarchar](50) NULL,
|
||||
// [device_name_tag] [nvarchar](50) NULL,
|
||||
// [device_serial_tag] [nvarchar](50) NULL,
|
||||
// [device_number] [nvarchar](255) NULL,
|
||||
// [device_system_category_layer3] [varchar](50) NULL,
|
||||
// [device_disaster] [varchar](50) NULL,
|
||||
// [created_at] [datetime] NULL,
|
||||
// CONSTRAINT [PK_device_import_ckeck_temp] PRIMARY KEY CLUSTERED
|
||||
// (
|
||||
// [id] ASC
|
||||
// ))
|
||||
|
||||
// ALTER TABLE [dbo].[device_import_ckeck_temp] ADD CONSTRAINT [DF_device_import_ckeck_temp_device_disaster] DEFAULT ((0)) FOR [device_disaster]
|
||||
// ALTER TABLE [dbo].[device_import_ckeck_temp] ADD CONSTRAINT [DF_device_import_ckeck_temp_created_at] DEFAULT (getdate()) FOR [created_at]
|
||||
// ";
|
||||
//await backendRepository.ExecuteSql(sql_check);
|
||||
|
||||
//檢查正確才寫入至check_temp資料表
|
||||
await backendRepository.AddMutiByCustomTable(deviceImportChecks, "device_import_ckeck_temp");
|
||||
}
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "匯入成功";
|
||||
#endregion
|
||||
}
|
||||
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<DeviceCheckFilter>>> GetRawDataCheckFilter()
|
||||
{
|
||||
ApiResult<List<DeviceCheckFilter>> apiResult = new ApiResult<List<DeviceCheckFilter>>();
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $@"
|
||||
SELECT
|
||||
ct.device_building_tag,
|
||||
ct.device_system_tag,
|
||||
ct.device_system_category_layer3
|
||||
FROM device_import_ckeck_temp ct
|
||||
GROUP BY ct.device_building_tag, ct.device_system_tag, ct.device_system_category_layer3
|
||||
";
|
||||
|
||||
var deviceCheckFilterRawDatas = await backendRepository.GetAllAsync<DeviceCheckFilterRawData>(sql);
|
||||
|
||||
List<DeviceCheckFilter> deviceCheckFilters = new List<DeviceCheckFilter>();
|
||||
|
||||
var deviceCheckFilterRawData_Group_Building_tag = deviceCheckFilterRawDatas.GroupBy(x => x.Device_building_tag).ToList();
|
||||
foreach (var deviceCheckFilterRawData_Building_tag in deviceCheckFilterRawData_Group_Building_tag)
|
||||
{
|
||||
DeviceCheckFilter deviceCheckFilter = new DeviceCheckFilter();
|
||||
deviceCheckFilter.Building_tag = deviceCheckFilterRawData_Building_tag.Key;
|
||||
|
||||
var sql_amount = @"SELECT COUNT(*) FROM device_import_ckeck_temp WHERE device_building_tag = @Device_building_tag";
|
||||
deviceCheckFilter.Building_amount = await backendRepository.GetOneAsync<int>(sql_amount, new { Device_building_tag = deviceCheckFilterRawData_Building_tag.Key });
|
||||
|
||||
deviceCheckFilter.System_tags = new List<DeviceCheckSystemTag>();
|
||||
|
||||
var deviceCheckFilterRawData_Group_System_tag = deviceCheckFilterRawData_Building_tag.GroupBy(x => x.Device_system_tag).ToList();
|
||||
foreach (var deviceCheckFilterRawData_System_tag in deviceCheckFilterRawData_Group_System_tag)
|
||||
{
|
||||
DeviceCheckSystemTag deviceCheckSystemTag = new DeviceCheckSystemTag();
|
||||
deviceCheckSystemTag.System_tag = deviceCheckFilterRawData_System_tag.Key;
|
||||
deviceCheckSystemTag.System_categories = new List<string>();
|
||||
|
||||
var deviceCheckFilterRawData_Group_System_category = deviceCheckFilterRawData_System_tag.GroupBy(x => x.Device_system_category_layer3).ToList();
|
||||
foreach (var deviceCheckFilterRawData_System_category in deviceCheckFilterRawData_Group_System_category)
|
||||
{
|
||||
deviceCheckSystemTag.System_categories.Add(deviceCheckFilterRawData_System_category.Key);
|
||||
}
|
||||
|
||||
deviceCheckFilter.System_tags.Add(deviceCheckSystemTag);
|
||||
}
|
||||
|
||||
deviceCheckFilters.Add(deviceCheckFilter);
|
||||
}
|
||||
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Data = deviceCheckFilters;
|
||||
}
|
||||
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<DeviceCheck>> DeviceCheckTableList(PostDeviceCheckFilter post)
|
||||
{
|
||||
ApiResult<DeviceCheck> apiResult = new ApiResult<DeviceCheck>();
|
||||
|
||||
try
|
||||
{
|
||||
string sWhere = "";
|
||||
string sSubTableWhere = " WHERE {0}.device_building_tag = @Device_building_tag";
|
||||
if (post.Abnormal == "all")
|
||||
{ //異常分類 為全選的時候,才可以指定選擇系統別、設備分類
|
||||
if (post.System_tag != "all")
|
||||
{
|
||||
sSubTableWhere += " AND {0}.device_system_tag = @Device_system_tag";
|
||||
}
|
||||
if (post.System_category != "all")
|
||||
{
|
||||
sSubTableWhere += " AND {0}.device_system_category_layer3 = @Device_system_category_layer3";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sWhere += @"WHERE ct.device_number IS NULL AND d.device_number IS NOT NULL
|
||||
-- OR ct.device_system_category_layer3 != d.device_system_category_layer3
|
||||
-- OR ct.disaster_system_value != d.device_disaster";
|
||||
}
|
||||
|
||||
string sql_temp = $@"
|
||||
SELECT
|
||||
ct.device_number AS check_temp_device_number,
|
||||
ct.device_system_category_layer3 AS check_temp_device_system_category_layer3,
|
||||
ct.system_category_system_key AS check_temp_device_system_category_layer3_key,
|
||||
ct.disaster_system_value AS check_temp_disaster,
|
||||
ct.disaster_system_key AS check_temp_disaster_key,
|
||||
d.device_number,
|
||||
d.device_system_category_layer3 AS device_system_category_layer3,
|
||||
d.system_key AS device_system_category_layer3_key,
|
||||
d.device_disaster,
|
||||
d.device_disaster_type_text,
|
||||
d.device_coordinate,
|
||||
CASE
|
||||
WHEN ct.device_number = d.device_number
|
||||
THEN 0
|
||||
ELSE 1
|
||||
END AS compare_device_number,
|
||||
CASE
|
||||
WHEN ct.device_system_category_layer3 = d.device_system_category_layer3
|
||||
THEN 0
|
||||
ELSE 1
|
||||
END AS compare_system_category_layer3,
|
||||
CASE
|
||||
WHEN ct.disaster_system_value = d.device_disaster
|
||||
THEN 0
|
||||
ELSE 1
|
||||
END AS compare_device_disaster
|
||||
FROM (
|
||||
SELECT
|
||||
ct.* ,
|
||||
v.system_type AS system_category_system_type,
|
||||
v.system_key AS system_category_system_key,
|
||||
v.system_value AS system_category_system_value,
|
||||
v2.system_type AS disaster_system_type,
|
||||
v2.system_key AS disaster_system_key,
|
||||
v2.system_value AS disaster_system_value
|
||||
FROM device_import_ckeck_temp ct
|
||||
LEFT JOIN variable v ON v.system_type = 'device_system_category_layer3' AND ct.device_system_category_layer3 = v.system_value
|
||||
LEFT JOIN variable v2 ON v2.system_type = 'disaster' AND v2.system_value = ct.device_disaster
|
||||
{{0}}
|
||||
) ct
|
||||
FULL JOIN (
|
||||
SELECT
|
||||
d.* ,
|
||||
v.system_type,
|
||||
v.system_key,
|
||||
v.system_value,
|
||||
(SELECT
|
||||
STRING_AGG( ISNULL(system_value, ' '), ',')
|
||||
FROM device_disaster dd
|
||||
JOIN variable v ON v.deleted = 0 AND v.system_type = 'disaster' AND v.system_value = dd.device_system_value
|
||||
WHERE dd.device_guid = d.device_guid
|
||||
) AS device_disaster,
|
||||
(SELECT
|
||||
STRING_AGG( ISNULL(system_key, ' '), ',')
|
||||
FROM device_disaster dd
|
||||
JOIN variable v ON v.deleted = 0 AND v.system_type = 'disaster' AND v.system_value = dd.device_system_value
|
||||
WHERE dd.device_guid = d.device_guid
|
||||
) AS device_disaster_type_text
|
||||
FROM device d
|
||||
LEFT JOIN variable v ON v.system_type = 'device_system_category_layer3' AND d.device_system_category_layer3 = v.system_value
|
||||
{{1}}
|
||||
AND d.deleted = 0
|
||||
|
||||
)d ON ct.device_number = d.device_number
|
||||
{{2}}
|
||||
ORDER BY d.device_number DESC
|
||||
";
|
||||
|
||||
var sql = string.Format(sql_temp, string.Format(sSubTableWhere, "ct"), string.Format(sSubTableWhere, "d"), sWhere);
|
||||
|
||||
var param = new { Device_building_tag = post.Building_tag, Device_system_tag = post.System_tag, Device_system_category_layer3 = post.System_category };
|
||||
|
||||
var deviceCheckTableList = await backendRepository.GetAllAsync<DeviceCheckTable>(sql, param);
|
||||
|
||||
sSubTableWhere = " WHERE {0}.device_building_tag = @Device_building_tag";
|
||||
|
||||
sWhere = @"WHERE ct.device_number IS NULL AND d.device_number IS NOT NULL
|
||||
-- OR ct.device_system_category_layer3 != d.device_system_category_layer3
|
||||
-- OR ct.disaster_system_value != d.device_disaster";
|
||||
|
||||
var sql_abnormal_amount = string.Format(sql_temp, string.Format(sSubTableWhere, "ct"), string.Format(sSubTableWhere, "d") + " AND d.deleted = 0", sWhere);
|
||||
|
||||
var abnormal = await backendRepository.GetAllAsync<DeviceCheckTable>(sql_abnormal_amount, param);
|
||||
|
||||
var abnormal_amount = abnormal.Count();
|
||||
|
||||
DeviceCheck deviceCheck = new DeviceCheck();
|
||||
deviceCheck.DeviceCheckAmount = abnormal_amount;
|
||||
deviceCheck.DeviceCheckTableList = deviceCheckTableList;
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Data = deviceCheck;
|
||||
}
|
||||
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<string>> DeviceCheckReplace(PostDeviceCheckFilter post)
|
||||
{
|
||||
ApiResult<string> apiResult = new ApiResult<string>();
|
||||
|
||||
try
|
||||
{
|
||||
//將該棟別的資料更換為正確
|
||||
string sql_update_correct = @"UPDATE device_import_ckeck_temp SET is_correct = 1 WHERE device_building_tag = @Device_building_tag";
|
||||
var param = new { Device_building_tag = post.Building_tag };
|
||||
await backendRepository.ExecuteSql(sql_update_correct, param);
|
||||
|
||||
//找出當前在device裡面有的,以供後續取代用
|
||||
string sql = @"
|
||||
SELECT
|
||||
ct.*,
|
||||
d.device_guid
|
||||
FROM (
|
||||
SELECT
|
||||
*
|
||||
FROM device_import_ckeck_temp ct
|
||||
WHERE ct.device_number IN (
|
||||
SELECT d.device_number
|
||||
FROM device d
|
||||
WHERE d.deleted = 0
|
||||
AND d.device_building_tag = @Device_building_tag
|
||||
)
|
||||
) ct
|
||||
LEFT JOIN device d ON d.deleted = 0 AND ct.device_number = d.device_number";
|
||||
|
||||
var check_temp_replaces = await backendRepository.GetAllAsync<Device_import_ckeck_temp_replace>(sql, param);
|
||||
|
||||
foreach (var check_temp_replace in check_temp_replaces)
|
||||
{
|
||||
Dictionary<string, object> device_replace = new Dictionary<string, object>()
|
||||
{
|
||||
{"@device_system_category_layer3", check_temp_replace.Device_system_category_layer3},
|
||||
};
|
||||
|
||||
List<Dictionary<string, object>> device_disaster_dicts = new List<Dictionary<string, object>>()
|
||||
{
|
||||
{ new Dictionary<string, object>() { { "@device_guid", check_temp_replace.Device_guid }, { "@device_system_value", check_temp_replace.Device_disaster } } }
|
||||
};
|
||||
|
||||
await deviceImportRepository.ReplaceOneDeviceInfo(check_temp_replace.Device_guid, device_replace, device_disaster_dicts);
|
||||
}
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "取代成功";
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
}
|
||||
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
1618
Backend/Controllers/DeviceManageController.cs
Normal file
1618
Backend/Controllers/DeviceManageController.cs
Normal file
File diff suppressed because it is too large
Load Diff
232
Backend/Controllers/EmergencyContactController.cs
Normal file
232
Backend/Controllers/EmergencyContactController.cs
Normal file
@ -0,0 +1,232 @@
|
||||
using Backend.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 Backend.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");
|
||||
}
|
||||
}
|
||||
}
|
50
Backend/Controllers/EmergencyDeviceMenuController.cs
Normal file
50
Backend/Controllers/EmergencyDeviceMenuController.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Repository.BackendRepository.Interface;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Backend.Controllers
|
||||
{
|
||||
public class EmergencyDeviceMenuController : MybaseController<EmergencyDeviceMenuController>
|
||||
{
|
||||
private readonly IBackendRepository backendRepository;
|
||||
public EmergencyDeviceMenuController(IBackendRepository backendRepository)
|
||||
{
|
||||
this.backendRepository = backendRepository;
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取得系統大類清單
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
//[HttpPost]
|
||||
//public async Task<ApiResult<List<SystemMain>>> SystemMainList()
|
||||
//{
|
||||
// ApiResult<List<SystemMain>> apiResult = new ApiResult<List<SystemMain>>();
|
||||
|
||||
// try
|
||||
// {
|
||||
// var sWhere = "deleted = 0";
|
||||
|
||||
// var systemMainList = await backendRepository.GetAllAsync<SystemMain>("main_system", sWhere, null, "priority ASC, created_at DESC");
|
||||
|
||||
// apiResult.Code = "0000";
|
||||
// apiResult.Data = systemMainList;
|
||||
// }
|
||||
// catch (Exception exception)
|
||||
// {
|
||||
// apiResult.Code = "9999";
|
||||
// Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
// }
|
||||
|
||||
// return apiResult;
|
||||
//}
|
||||
}
|
||||
}
|
278
Backend/Controllers/EmergencyGroupingController.cs
Normal file
278
Backend/Controllers/EmergencyGroupingController.cs
Normal file
@ -0,0 +1,278 @@
|
||||
using Backend.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 Backend.Controllers
|
||||
{
|
||||
public class EmergencyGroupingController : MybaseController<EmergencyGroupingController>
|
||||
{
|
||||
private readonly IBackendRepository backendRepository;
|
||||
public EmergencyGroupingController(IBackendRepository backendRepository)
|
||||
{
|
||||
this.backendRepository = backendRepository;
|
||||
}
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<List<KeyValue>>> Getdepartlist()
|
||||
{
|
||||
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 = 'department' 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<string>> SaveGrouping(SaveGrouping post)
|
||||
{
|
||||
ApiResult<string> apiResult = new ApiResult<string>();
|
||||
try
|
||||
{
|
||||
if(post.id == 0)
|
||||
{
|
||||
var value = await backendRepository.GetOneAsync<int>("select td.system_value from variable td where td.system_type = 'grouping' order by td.system_value desc");
|
||||
var dictionary = new Dictionary<string, object>()
|
||||
{
|
||||
{"@system_type", "grouping"},
|
||||
{"@system_key",post.name},
|
||||
{"@system_value", value + 1},
|
||||
{"@system_remark","急救編組"},
|
||||
{"@system_priority",post.priority},
|
||||
{"@system_parent_id", post.disaster}
|
||||
};
|
||||
await backendRepository.AddOneByCustomTable(dictionary, "variable");
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "新增成功";
|
||||
}
|
||||
else
|
||||
{
|
||||
var dictionary = new Dictionary<string, object>()
|
||||
{
|
||||
{"@system_key",post.name},
|
||||
{"@system_priority",post.priority}
|
||||
};
|
||||
await backendRepository.UpdateOneByCustomTable(dictionary, "variable", $" id = {post.id}");
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "儲存成功";
|
||||
}
|
||||
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
string json = System.Text.Json.JsonSerializer.Serialize(post);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + json);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + ex.Message);
|
||||
}
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult> Emergency_member_table(int grouping)
|
||||
{
|
||||
List<Emergency_member_table> Emergency_member_tables = new List<Emergency_member_table>();
|
||||
ApiResult<List<Emergency_member_table>> apiResult = new ApiResult<List<Emergency_member_table>>();
|
||||
try
|
||||
{
|
||||
Emergency_member_tables = await backendRepository.GetAllAsync<Emergency_member_table>($@"
|
||||
select v.system_key grouping_name,va.system_key department_name,* 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 = {grouping} and em.deleted = 0");
|
||||
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;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<List<KeyValueID>>> GetGroupingList (int system_parent_id)
|
||||
{
|
||||
ApiResult<List<KeyValueID>> apiResult = new ApiResult<List<KeyValueID>>();
|
||||
List<KeyValueID> keyvalue = new List<KeyValueID>();
|
||||
try
|
||||
{
|
||||
keyvalue = await backendRepository.GetAllAsync<KeyValueID>($"select id, system_key as name,system_value as value from variable where deleted = 0 and system_parent_id = {system_parent_id} and system_type = 'grouping' order by system_priority");
|
||||
apiResult.Data = keyvalue;
|
||||
apiResult.Code = "0000";
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + system_parent_id);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + ex.Message);
|
||||
}
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<SaveGrouping>> GetOneGrouping(int selectgroupid)
|
||||
{
|
||||
ApiResult<SaveGrouping> apiResult = new ApiResult<SaveGrouping>();
|
||||
try
|
||||
{
|
||||
var group = await backendRepository.GetOneAsync<SaveGrouping>($"select v.system_priority as priority,v.system_key as name,id from variable v where id = {selectgroupid} and deleted = 0");
|
||||
apiResult.Data = group;
|
||||
apiResult.Code = "0000";
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + selectgroupid);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + ex.Message);
|
||||
}
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<string>>DeleteOne(int selectgroupid)
|
||||
{
|
||||
ApiResult<string> apiResult = new ApiResult<string>();
|
||||
try
|
||||
{
|
||||
await backendRepository.DeleteOne(selectgroupid.ToString(), "variable", "id");
|
||||
apiResult.Msg = "刪除成功";
|
||||
apiResult.Code = "0000";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + selectgroupid);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + ex.Message);
|
||||
}
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<string>>SaveMember(Emergency_member post)
|
||||
{
|
||||
ApiResult<string> apiResult = new ApiResult<string>();
|
||||
try
|
||||
{
|
||||
if (post.emergency_member_guid == null)
|
||||
{
|
||||
var dictionary = new Dictionary<string, object>()
|
||||
{
|
||||
{"@emergency_member_guid", Guid.NewGuid()},
|
||||
{"@grouping",post.grouping},
|
||||
{"@full_name", post.full_name},
|
||||
{"@department",post.department},
|
||||
{"@phone",post.phone},
|
||||
{"@lineid", post.lineid},
|
||||
{"@email", post.email},
|
||||
{"@created_by",myUserInfo.Userinfo_guid }
|
||||
};
|
||||
await backendRepository.AddOneByCustomTable(dictionary, "emergency_member");
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "新增成功";
|
||||
}
|
||||
else
|
||||
{
|
||||
var dictionary = new Dictionary<string, object>()
|
||||
{
|
||||
{"@grouping",post.grouping},
|
||||
{"@full_name", post.full_name},
|
||||
{"@department",post.department},
|
||||
{"@phone",post.phone},
|
||||
{"@lineid", post.lineid},
|
||||
{"@email", post.email},
|
||||
{"@updated_by",myUserInfo.Userinfo_guid },
|
||||
{"@updated_at",DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }
|
||||
};
|
||||
await backendRepository.UpdateOneByCustomTable(dictionary, "emergency_member", $"emergency_member_guid = '{post.emergency_member_guid}'");
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "儲存成功";
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
string json = System.Text.Json.JsonSerializer.Serialize(post);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + json);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + ex.Message);
|
||||
}
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<Emergency_member>> GetOneMember(string guid)
|
||||
{
|
||||
ApiResult<Emergency_member> apiResult = new ApiResult<Emergency_member>();
|
||||
try
|
||||
{
|
||||
var member = await backendRepository.GetOneAsync<Emergency_member>("emergency_member", $"emergency_member_guid = '{guid}'");
|
||||
apiResult.Data = member;
|
||||
apiResult.Code = "0000";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + guid);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + ex.Message);
|
||||
}
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<string>> DeletedOneMember(string guid)
|
||||
{
|
||||
ApiResult<string> apiResult = new ApiResult<string>();
|
||||
try
|
||||
{
|
||||
await backendRepository.DeleteOne(guid, "emergency_member", "emergency_member_guid");
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "刪除成功";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + guid);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + ex.Message);
|
||||
}
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
94
Backend/Controllers/EmergencyRecordController.cs
Normal file
94
Backend/Controllers/EmergencyRecordController.cs
Normal file
@ -0,0 +1,94 @@
|
||||
using Backend.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 Backend.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<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;
|
||||
}
|
||||
}
|
||||
}
|
558
Backend/Controllers/EmergencySettingController.cs
Normal file
558
Backend/Controllers/EmergencySettingController.cs
Normal file
@ -0,0 +1,558 @@
|
||||
using Backend.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;
|
||||
using System.Transactions;
|
||||
|
||||
namespace Backend.Controllers
|
||||
{
|
||||
public class EmergencySettingController : MybaseController<EmergencySettingController>
|
||||
{
|
||||
private readonly IBackendRepository backendRepository;
|
||||
|
||||
public EmergencySettingController(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<KeyValueID>>> GetSettingList(int system_parent_id)
|
||||
{
|
||||
ApiResult<List<KeyValueID>> apiResult = new ApiResult<List<KeyValueID>>();
|
||||
List<KeyValueID> keyvalue = new List<KeyValueID>();
|
||||
try
|
||||
{
|
||||
keyvalue = await backendRepository.GetAllAsync<KeyValueID>($"select id, system_key as name,system_value as value from variable where deleted = 0 and system_parent_id = {system_parent_id} and system_type = 'DisasterSetting' order by system_priority");
|
||||
apiResult.Data = keyvalue;
|
||||
apiResult.Code = "0000";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + system_parent_id);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + ex.Message);
|
||||
}
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<string>> SaveSettingModal(SaveGrouping post)
|
||||
{
|
||||
ApiResult<string> apiResult = new ApiResult<string>();
|
||||
try
|
||||
{
|
||||
if (post.id == 0)
|
||||
{
|
||||
|
||||
var value = await backendRepository.GetOneAsync<int>("select td.system_value from variable td where td.system_type = 'DisasterSetting' order by cast(td.system_value as int) desc");
|
||||
var dictionary = new Dictionary<string, object>()
|
||||
{
|
||||
{"@system_type", "DisasterSetting"},
|
||||
{"@system_key",post.name},
|
||||
{"@system_value", value + 1},
|
||||
{"@system_remark","急救大步驟設定"},
|
||||
{"@system_priority",post.priority},
|
||||
{"@system_parent_id", post.disaster}
|
||||
};
|
||||
await backendRepository.AddOneByCustomTable(dictionary, "variable");
|
||||
|
||||
var Nid = await backendRepository.GetOneAsync<int>($"select id from variable where system_type = 'DisasterSetting' and system_key = N'{post.name}' and system_value = '{value + 1}'");
|
||||
|
||||
var dictionary2 = new Dictionary<string, object>()
|
||||
{
|
||||
{"@system_type", "Verify"},
|
||||
{"@system_key","驗證開關"},
|
||||
{"@system_remark","急救大步驟設定驗證開關"},
|
||||
{"@system_priority",0},
|
||||
{"@system_parent_id", Nid}
|
||||
};
|
||||
if (post.verify == 0)
|
||||
{
|
||||
dictionary2.Add("@system_value", 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
dictionary2.Add("@system_value", 1);
|
||||
}
|
||||
|
||||
await backendRepository.AddOneByCustomTable(dictionary2, "variable");
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "新增成功";
|
||||
}
|
||||
else
|
||||
{
|
||||
var dictionary = new Dictionary<string, object>()
|
||||
{
|
||||
{"@system_key",post.name},
|
||||
{"@system_priority",post.priority}
|
||||
};
|
||||
await backendRepository.UpdateOneByCustomTable(dictionary, "variable", $" id = {post.id}");
|
||||
if (post.verify == 0)
|
||||
{
|
||||
var dictionary2 = new Dictionary<string, object>()
|
||||
{
|
||||
{"@system_value",0}
|
||||
};
|
||||
await backendRepository.UpdateOneByCustomTable(dictionary2, "variable", $" system_type = 'Verify' and system_parent_id = '{post.id}'");
|
||||
}
|
||||
else
|
||||
{
|
||||
var haveVerify = await backendRepository.GetOneAsync<string>("variable", $"system_type = 'Verify' and system_parent_id = '{post.id}'");
|
||||
if (haveVerify == null)
|
||||
{
|
||||
var dictionary2 = new Dictionary<string, object>()
|
||||
{
|
||||
{"@system_type", "Verify"},
|
||||
{"@system_key","驗證開關"},
|
||||
{"@system_remark","急救大步驟設定驗證開關"},
|
||||
{"@system_priority",0},
|
||||
{"@system_parent_id", post.id},
|
||||
{"@system_value", 1}
|
||||
};
|
||||
await backendRepository.AddOneByCustomTable(dictionary2, "variable");
|
||||
}
|
||||
else
|
||||
{
|
||||
var dictionary2 = new Dictionary<string, object>()
|
||||
{
|
||||
{"@system_value",1}
|
||||
};
|
||||
await backendRepository.UpdateOneByCustomTable(dictionary2, "variable", $" system_type = 'Verify' and system_parent_id = '{post.id}'");
|
||||
}
|
||||
}
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "儲存成功";
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
string json = System.Text.Json.JsonSerializer.Serialize(post);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + json);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + ex.Message);
|
||||
}
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<string>> SaveSubSetting(EmergencySetting post)
|
||||
{
|
||||
ApiResult<string> apiResult = new ApiResult<string>();
|
||||
try
|
||||
{
|
||||
if (post.emergency_guid == null)
|
||||
{
|
||||
var dictionary = new Dictionary<string, object>()
|
||||
{
|
||||
{"@emergency_guid", Guid.NewGuid()},
|
||||
{"@priority",post.priority},
|
||||
{"@big_setting", post.big_setting},
|
||||
{"@full_name",post.full_name},
|
||||
{"@set_doing",post.set_doing},
|
||||
{"@url_text", post.url_text},
|
||||
{"@url_link", post.url_link},
|
||||
{"@not_answer",post.not_answer},
|
||||
{"@created_by",myUserInfo.Userinfo_guid }
|
||||
};
|
||||
await backendRepository.AddOneByCustomTable(dictionary, "emergency_setting");
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "新增成功";
|
||||
}
|
||||
else
|
||||
{
|
||||
var dictionary = new Dictionary<string, object>()
|
||||
{
|
||||
{"@priority",post.priority},
|
||||
{"@big_setting", post.big_setting},
|
||||
{"@full_name",post.full_name},
|
||||
{"@set_doing",post.set_doing},
|
||||
{"@url_text", post.url_text},
|
||||
{"@url_link", post.url_link},
|
||||
{"@not_answer",post.not_answer},
|
||||
{"@updated_by",myUserInfo.Userinfo_guid },
|
||||
{"@updated_at",DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }
|
||||
};
|
||||
await backendRepository.UpdateOneByCustomTable(dictionary, "emergency_setting", $"emergency_guid = '{post.emergency_guid}'");
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "儲存成功";
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
string json = System.Text.Json.JsonSerializer.Serialize(post);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + json);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + ex.Message);
|
||||
}
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult> Emergency_Setting_table(int selectsetting)
|
||||
{
|
||||
List<EmergencySettingTable> Emergency_Setting_tables = new List<EmergencySettingTable>();
|
||||
ApiResult<List<EmergencySettingTable>> apiResult = new ApiResult<List<EmergencySettingTable>>();
|
||||
try
|
||||
{
|
||||
Emergency_Setting_tables = await backendRepository.GetAllAsync<EmergencySettingTable>($@"
|
||||
select v.system_key big_setting_name,* from emergency_setting es left join variable v on es.big_setting = v.id
|
||||
where es.big_setting = {selectsetting} and es.deleted = 0 ");
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Data = Emergency_Setting_tables;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + selectsetting);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
}
|
||||
var result = Json(new
|
||||
{
|
||||
data = apiResult
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<SaveGrouping>> GetOnesetting(int selectsetting)
|
||||
{
|
||||
ApiResult<SaveGrouping> apiResult = new ApiResult<SaveGrouping>();
|
||||
try
|
||||
{
|
||||
var sql = $@"select v.system_priority as priority,v.system_key as name,s.system_value verify
|
||||
from variable v
|
||||
left join variable s on v.id = s.system_parent_id
|
||||
where v.id = {selectsetting} and v.deleted = 0";
|
||||
|
||||
var group = await backendRepository.GetOneAsync<SaveGrouping>(sql);
|
||||
apiResult.Data = group;
|
||||
apiResult.Code = "0000";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + selectsetting);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + ex.Message);
|
||||
}
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<string>> DeletedOneSubSetting(string guid)
|
||||
{
|
||||
ApiResult<string> apiResult = new ApiResult<string>();
|
||||
try
|
||||
{
|
||||
await backendRepository.DeleteOne(guid, "emergency_setting", "emergency_guid");
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "刪除成功";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + guid);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + ex.Message);
|
||||
}
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<EmergencySetting>> GetOneSubSetting(string guid)
|
||||
{
|
||||
ApiResult<EmergencySetting> apiResult = new ApiResult<EmergencySetting>();
|
||||
try
|
||||
{
|
||||
var SubSetting = await backendRepository.GetOneAsync<EmergencySetting>("emergency_setting", $"emergency_guid = '{guid}'");
|
||||
apiResult.Data = SubSetting;
|
||||
apiResult.Code = "0000";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + guid);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + ex.Message);
|
||||
}
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<string>> SaveAndOpenSimulationExercise(Eventpost eventpost)
|
||||
{
|
||||
ApiResult<string> apiResult = new ApiResult<string>();
|
||||
try
|
||||
{
|
||||
var newguid = Guid.NewGuid();
|
||||
var dictionary = new Dictionary<string, object>()
|
||||
{
|
||||
{"@emergency_event_guid",newguid},
|
||||
{"@disaster",eventpost.disaster},
|
||||
{"@building_guid", eventpost.build},
|
||||
{"@type",eventpost.type}
|
||||
};
|
||||
await backendRepository.AddOneByCustomTable(dictionary, "emergency_event");
|
||||
apiResult.Data = newguid.ToString();
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "新增成功";
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
string json = System.Text.Json.JsonSerializer.Serialize(eventpost);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + json);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + ex.Message);
|
||||
}
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<List<SaveGrouping>>> GetBigsetting(int disaster)
|
||||
{
|
||||
ApiResult<List<SaveGrouping>> apiResult = new ApiResult<List<SaveGrouping>>();
|
||||
try
|
||||
{
|
||||
var sql = $@"
|
||||
select
|
||||
v.id id,
|
||||
v.system_key name,
|
||||
f.system_value verify
|
||||
from variable v
|
||||
join variable f on v.id = f.system_parent_id and f.system_type = 'Verify'
|
||||
where v.system_type = 'DisasterSetting'
|
||||
and v.system_parent_id = '{disaster}'
|
||||
and v.deleted = 0
|
||||
order by v.system_priority";
|
||||
|
||||
|
||||
var list = await backendRepository.GetAllAsync<SaveGrouping>(sql);
|
||||
|
||||
apiResult.Data = list;
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "新增成功";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + disaster);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + ex.Message);
|
||||
}
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<List<EmergencySettingTable>>> GetEmergencySetting(int selectsetting)
|
||||
{
|
||||
List<EmergencySettingTable> Emergency_Setting_tables = new List<EmergencySettingTable>();
|
||||
ApiResult<List<EmergencySettingTable>> apiResult = new ApiResult<List<EmergencySettingTable>>();
|
||||
try
|
||||
{
|
||||
Emergency_Setting_tables = await backendRepository.GetAllAsync<EmergencySettingTable>($@"
|
||||
select v.system_key big_setting_name,* from emergency_setting es left join variable v on es.big_setting = v.id
|
||||
where es.big_setting = {selectsetting} and es.deleted = 0 order by es.priority");
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Data = Emergency_Setting_tables;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + selectsetting);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
}
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<EmergencyitemWithguid>> GetContentAndMakeItem(Emergencyitempost post)
|
||||
{
|
||||
|
||||
ApiResult<EmergencyitemWithguid> apiResult = new ApiResult<EmergencyitemWithguid>();
|
||||
try
|
||||
{
|
||||
var Emergency_Setting_tables = await backendRepository.GetOneAsync<EmergencyitemWithguid>($@"
|
||||
select v.system_key big_setting_name,* from emergency_setting es left join variable v on es.big_setting = v.id
|
||||
where es.emergency_guid = '{post.emergency_guid}'");
|
||||
|
||||
if(post.make_item == 1)
|
||||
{
|
||||
var haveguid = await backendRepository.GetOneAsync<string>($"select emergency_item_guid from emergency_item where event_guid = '{post.event_guid}' and big_setting = '{post.big_setting}' and step_setting = '{post.step_setting}'");
|
||||
if(haveguid == null)
|
||||
{
|
||||
var newguid = Guid.NewGuid();
|
||||
var dictionary = new Dictionary<string, object>()
|
||||
{
|
||||
{"@emergency_item_guid",newguid},
|
||||
{"@event_guid",post.event_guid},
|
||||
{"@big_setting", post.big_setting},
|
||||
{"@step_setting",post.step_setting},
|
||||
{"@created_by",myUserInfo.Userinfo_guid }
|
||||
};
|
||||
await backendRepository.AddOneByCustomTable(dictionary, "emergency_item");
|
||||
Emergency_Setting_tables.emergency_item_guid = newguid.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
Emergency_Setting_tables.emergency_item_guid = haveguid;
|
||||
}
|
||||
}
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Data = Emergency_Setting_tables;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<string>> NextStep (Itempost item)
|
||||
{
|
||||
ApiResult<string> apiResult = new ApiResult<string>();
|
||||
byte finish = 0;
|
||||
if(item.choose == 0)
|
||||
{
|
||||
finish = 1;
|
||||
}else
|
||||
{
|
||||
finish = 2;
|
||||
}
|
||||
try
|
||||
{
|
||||
var dictionary = new Dictionary<string, object>()
|
||||
{
|
||||
{"@finished",finish},
|
||||
{"@updated_by", myUserInfo.Userinfo_guid},
|
||||
{"@updated_at", DateTime.Now}
|
||||
};
|
||||
if(item.choose == 1)
|
||||
{
|
||||
dictionary.Add("@reason", item.reason );
|
||||
}
|
||||
await backendRepository.UpdateOneByCustomTable(dictionary, "emergency_item", $"emergency_item_guid = '{item.eventguid}'");
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "更新成功";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
string json = System.Text.Json.JsonSerializer.Serialize(item);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + json);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + ex.Message);
|
||||
}
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult> Dohistorytotable (string eventguid)
|
||||
{
|
||||
List<Eventitem> eventitems = new List<Eventitem>();
|
||||
ApiResult<List<Eventitem>> apiResult = new ApiResult<List<Eventitem>>();
|
||||
try
|
||||
{
|
||||
eventitems = await backendRepository.GetAllAsync<Eventitem>($"select * from emergency_item where event_guid = @Guid",new { Guid = $"{eventguid}" });
|
||||
apiResult.Data = eventitems;
|
||||
apiResult.Code = "0000";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + eventguid);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + ex.Message);
|
||||
}
|
||||
var result = Json(new
|
||||
{
|
||||
data = apiResult
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<bool>> CheckVerifybool(string pass)
|
||||
{
|
||||
ApiResult<bool> apiResult = new ApiResult<bool>();
|
||||
try
|
||||
{
|
||||
EDFunction edFunction = new EDFunction();
|
||||
string passto = "";
|
||||
if (pass != null)
|
||||
{
|
||||
passto = edFunction.GetSHA256Encryption(pass);
|
||||
}
|
||||
var Verify = await backendRepository.GetAllAsync<string>("userinfo", $" role_guid = 'B0556AD7-C1E1-47A1-A1F1-802E22714B33' and password = '{passto}'");
|
||||
|
||||
if(Verify.Count == 0)
|
||||
{
|
||||
apiResult.Data = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
apiResult.Data = true;
|
||||
}
|
||||
apiResult.Code = "0000";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + pass);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + ex.Message);
|
||||
}
|
||||
return apiResult;
|
||||
}
|
||||
}
|
||||
}
|
37
Backend/Controllers/HomeController.cs
Normal file
37
Backend/Controllers/HomeController.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using Backend.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Backend.Controllers
|
||||
{
|
||||
public class HomeController : MybaseController<HomeController>
|
||||
{
|
||||
private readonly ILogger<HomeController> _logger;
|
||||
|
||||
public HomeController(ILogger<HomeController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public IActionResult Privacy()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public IActionResult Error()
|
||||
{
|
||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
}
|
||||
}
|
||||
}
|
151
Backend/Controllers/LoginController.cs
Normal file
151
Backend/Controllers/LoginController.cs
Normal file
@ -0,0 +1,151 @@
|
||||
using Backend.Models;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
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 Backend.Controllers
|
||||
{
|
||||
public class LoginController : Controller
|
||||
{
|
||||
private readonly ILogger<LoginController> logger;
|
||||
private readonly IUserInfoRepository userInfoRepository;
|
||||
|
||||
public LoginController(ILogger<LoginController> logger,
|
||||
IUserInfoRepository userInfoRepository)
|
||||
{
|
||||
this.logger = logger;
|
||||
this.userInfoRepository = userInfoRepository;
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 表單post提交,準備登入
|
||||
/// </summary>
|
||||
/// <param name="form"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> IndexAsync(LoginViewModel login)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
UserInfo userInfo = null;
|
||||
EDFunction edFunction = new EDFunction();
|
||||
try
|
||||
{
|
||||
userInfo = await userInfoRepository.GetOneByAccountAsync<UserInfo>(login.Account);
|
||||
|
||||
if (userInfo == null)
|
||||
{
|
||||
ViewBag.errMsg = "帳號或密碼輸入錯誤";
|
||||
return View();
|
||||
}
|
||||
|
||||
string SHA256Pwd = edFunction.GetSHA256Encryption(login.Password);
|
||||
|
||||
if (string.Compare(userInfo.Password, SHA256Pwd) != 0)
|
||||
{
|
||||
ViewBag.errMsg = "帳號或密碼輸入錯誤";
|
||||
return View();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ViewBag.ErrMsg = "系統內部錯誤,請聯絡管理者。";
|
||||
string json = System.Text.Json.JsonSerializer.Serialize(login);
|
||||
logger.LogError("【Login/Index - 登入資訊】" + json);
|
||||
logger.LogError("【Login/Index】" + ex.Message);
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
HttpContext.Session.SetString("MyAccount", edFunction.AESEncrypt(userInfo.Account)); //將帳號透過AES加密
|
||||
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 登出,Action 記得別加上[Authorize],不管用戶是否登入,都可以執行SignOut
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IActionResult SignOut()
|
||||
{
|
||||
HttpContext.Session.Clear();
|
||||
|
||||
return RedirectToAction("Index", "Login");//導至登入頁
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 忘記密碼
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IActionResult ForgotPassword()
|
||||
{
|
||||
return View("~/Views/Login/ForgotPassword.cshtml");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取得新密碼
|
||||
/// </summary>
|
||||
/// <param name="form"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> ForgotPasswordAsync(ForgotPasswordViewModel forgot)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
string sWhere = @"deleted = @Deleted AND email = @Email";
|
||||
object param = new { Deleted = 0, Email = forgot.Email };
|
||||
var user = await userInfoRepository.GetOneAsync<UserInfo>("userinfo", sWhere, param);
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
ViewBag.errMsg = "查無此信箱";
|
||||
return View();
|
||||
}
|
||||
|
||||
//隨機產生亂數
|
||||
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());
|
||||
|
||||
EDFunction edFunction = new EDFunction();
|
||||
|
||||
var newPassword = edFunction.GetSHA256Encryption(random_password);
|
||||
|
||||
Dictionary<string, object> updateUserPasswordDic = new Dictionary<string, object>()
|
||||
{
|
||||
{ "@password", newPassword},
|
||||
{ "@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")},
|
||||
};
|
||||
|
||||
await userInfoRepository.UpdateOneByCustomTable(updateUserPasswordDic, "userinfo", "userinfo_guid='" + user.Userinfo_guid + "'");
|
||||
|
||||
//var sendSubject = "變更密碼成功";
|
||||
//var sendContent = $"您的新密碼為:{random_password}";
|
||||
|
||||
//List<string> recipientEmails = new List<string>()
|
||||
//{
|
||||
// user.Email
|
||||
//};
|
||||
|
||||
//sendEmailService.Send(recipientEmails, sendSubject, sendContent);
|
||||
|
||||
return RedirectToAction("Index", "Login");
|
||||
}
|
||||
}
|
||||
}
|
101
Backend/Controllers/MybaseController.cs
Normal file
101
Backend/Controllers/MybaseController.cs
Normal file
@ -0,0 +1,101 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Repository.BackendRepository.Interface;
|
||||
using Backend.Models;
|
||||
using Backend.Services.Implement;
|
||||
|
||||
namespace Backend.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 IBackendRepository backendRepository => HttpContext?.RequestServices.GetService<IBackendRepository>();
|
||||
private IUserInfoRepository userInfoRepository => HttpContext?.RequestServices.GetService<IUserInfoRepository>();
|
||||
|
||||
public string baseURL => HttpContext?.Request.Scheme + "://" + HttpContext?.Request.Host + "/";
|
||||
|
||||
public BackgroundService backgroundService;
|
||||
protected MyUserInfo myUserInfo = null;
|
||||
public string controllerName;
|
||||
public string actionName;
|
||||
public MybaseController() { }
|
||||
public override void OnActionExecuting(ActionExecutingContext filterContext)
|
||||
{
|
||||
EDFunction edFunction = new EDFunction();
|
||||
var myAccount = edFunction.AESDecrypt(HttpContext.Session.GetString("MyAccount"));
|
||||
controllerName = ControllerContext.RouteData.Values["controller"].ToString(); //controller名稱
|
||||
actionName = ControllerContext.RouteData.Values["action"].ToString(); //action名稱
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
backgroundService = new BackgroundService(backendRepository);
|
||||
|
||||
//取得當前登入使用者資訊
|
||||
myUserInfo = userInfoRepository.GetMyUserInfoByAccount<MyUserInfo>(myAccount);
|
||||
var showview = backendRepository.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;
|
||||
#region 記錄人員操作記錄
|
||||
var content = JsonConvert.SerializeObject(filterContext.ActionArguments);
|
||||
var parameter = content.CompareTo("{}") == 0 ? null : content;
|
||||
List<string> removeParam = new List<string>() { "ChangePassword" }; //移除不紀錄參數的actionName
|
||||
if (removeParam.Any(x => actionName.Contains(x)))
|
||||
{
|
||||
parameter = "{}";
|
||||
}
|
||||
|
||||
Dictionary<string, object> operatorLog = new Dictionary<string, object>();
|
||||
|
||||
operatorLog = new Dictionary<string, object>()
|
||||
{
|
||||
{ "@controller_name", controllerName},
|
||||
{ "@action_name", actionName},
|
||||
{ "@parameter", parameter},
|
||||
{ "@created_by", myUserInfo.Userinfo_guid}
|
||||
};
|
||||
|
||||
backendRepository.InsertOperatorLog(operatorLog, "operation_back_log");
|
||||
|
||||
//operatorLogRepository.Add(operatorLog, properties);
|
||||
#endregion
|
||||
}
|
||||
|
||||
}
|
||||
}
|
7
Backend/Controllers/NpoiMemoryStream.cs
Normal file
7
Backend/Controllers/NpoiMemoryStream.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace Backend.Controllers
|
||||
{
|
||||
internal class NpoiMemoryStream
|
||||
{
|
||||
public bool AllowClose { get; set; }
|
||||
}
|
||||
}
|
366
Backend/Controllers/RescueDeviceController.cs
Normal file
366
Backend/Controllers/RescueDeviceController.cs
Normal file
@ -0,0 +1,366 @@
|
||||
using Backend.Models;
|
||||
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 Backend.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();
|
||||
}
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<List<KeyValue>>> GetFloorByBuild (string Building)
|
||||
{
|
||||
ApiResult<List<KeyValue>> apiResult = new ApiResult<List<KeyValue>>();
|
||||
List<KeyValue> KeyValue = new List<KeyValue>();
|
||||
|
||||
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";
|
||||
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> RescueDeviceTable(RescueDeviceTableUse post)
|
||||
{
|
||||
|
||||
|
||||
List<RescueDeviceTable> RescueDeviceTables = new List<RescueDeviceTable>();
|
||||
ApiResult<List<RescueDeviceTable>> apiResult = new ApiResult<List<RescueDeviceTable>>();
|
||||
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");
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Data = RescueDeviceTables;
|
||||
}
|
||||
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<ApiResult<string>> ImportRescueDevice(ImportRescueDevice import)
|
||||
{
|
||||
ApiResult<string> apiResult = new ApiResult<string>();
|
||||
try
|
||||
{
|
||||
IWorkbook workbook;
|
||||
var filename_ext = Path.GetExtension(import.import_file.FileName).ToLower();
|
||||
if (filename_ext == ".xls")
|
||||
{
|
||||
workbook = new HSSFWorkbook(import.import_file.OpenReadStream());
|
||||
}
|
||||
else if (filename_ext == ".xlsx")
|
||||
{
|
||||
workbook = new XSSFWorkbook(import.import_file.OpenReadStream());
|
||||
}
|
||||
else
|
||||
{
|
||||
workbook = null;
|
||||
}
|
||||
if (workbook == null)
|
||||
{
|
||||
apiResult.Code = "9998";
|
||||
apiResult.Msg = $"{import.import_file.FileName}該檔案失效,請重新操作。";
|
||||
|
||||
return apiResult;
|
||||
}
|
||||
var sqlString = @$"select floor_guid as Value, full_name as Name from floor a where a.deleted = 0 and a.building_guid = '{import.building}' and a.status = 0 order by a.priority";
|
||||
var floor = await backendRepository.GetAllAsync<KeyValue>(sqlString);
|
||||
List<Dictionary<string, object>> deviceImports = new List<Dictionary<string, object>>();
|
||||
var sheet = workbook.GetSheetAt(0);
|
||||
IRow header = sheet.GetRow(sheet.FirstRowNum);
|
||||
ICell cell = header.GetCell(1);
|
||||
if(!string.IsNullOrEmpty(cell.ToString()) && cell.ToString()!= "設備編號")
|
||||
{
|
||||
apiResult.Code = "9998";
|
||||
apiResult.Msg = $"{import.import_file.FileName}該檔案格式錯誤,請重新操作。";
|
||||
|
||||
return apiResult;
|
||||
}
|
||||
cell = header.GetCell(0);
|
||||
if (!string.IsNullOrEmpty(cell.ToString()) && cell.ToString() != "樓層")
|
||||
{
|
||||
apiResult.Code = "9998";
|
||||
apiResult.Msg = $"{import.import_file.FileName}該檔案格式錯誤,請重新操作。";
|
||||
|
||||
return apiResult;
|
||||
}
|
||||
cell = header.GetCell(2);
|
||||
if (!string.IsNullOrEmpty(cell.ToString()) && cell.ToString() != "位置")
|
||||
{
|
||||
apiResult.Code = "9998";
|
||||
apiResult.Msg = $"{import.import_file.FileName}該檔案格式錯誤,請重新操作。";
|
||||
|
||||
return apiResult;
|
||||
}
|
||||
List<int> columns = new List<int>();
|
||||
for(var a = sheet.FirstRowNum + 1;a <= sheet.LastRowNum; a++)
|
||||
{
|
||||
var floorname = sheet.GetRow(a).GetCell(0).ToString();
|
||||
var floorguid = floor.Where(k => k.Name.ToString() == floorname).Select(d =>d.Value).FirstOrDefault();
|
||||
if(floorguid == null)
|
||||
{
|
||||
apiResult.Code = "9998";
|
||||
apiResult.Msg = $"{import.import_file.FileName}該檔案樓層名稱錯誤,請確認後重新操作。";
|
||||
return apiResult;
|
||||
}
|
||||
Dictionary<string, object> deviceImport = new Dictionary<string, object>();
|
||||
deviceImport.Add("@rescue_device_guid", Guid.NewGuid().ToString());
|
||||
deviceImport.Add("@rescue_device_id", sheet.GetRow(a).GetCell(1).ToString());
|
||||
deviceImport.Add("@floor_guid", floorguid);
|
||||
deviceImport.Add("@floor_name", sheet.GetRow(a).GetCell(0).ToString());
|
||||
deviceImport.Add("@location", sheet.GetRow(a).GetCell(2).ToString());
|
||||
deviceImport.Add("@rescue_device_kind", import.kind);
|
||||
deviceImport.Add("@building_guid", import.building);
|
||||
deviceImport.Add("@created_by", myUserInfo.Userinfo_guid);
|
||||
deviceImport.Add("@created_at", DateTime.Now);
|
||||
deviceImports.Add(deviceImport);
|
||||
}
|
||||
await backendRepository.PurgeOneByGuidWithCustomDBNameAndTable("rescue_device", $"building_guid = '{import.building}' and rescue_device_kind = {import.kind}");
|
||||
await backendRepository.AddMutiByCustomTable(deviceImports, "rescue_device");
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "匯入成功";
|
||||
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + ex.Message);
|
||||
}
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<string>> DeletedIt(string guid)
|
||||
{
|
||||
ApiResult<string> apiResult = new ApiResult<string>();
|
||||
try
|
||||
{
|
||||
await backendRepository.PurgeOneAsync(guid, "rescue_device", "rescue_device_guid");
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "刪除成功";
|
||||
}
|
||||
catch(Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】");
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
}
|
||||
return apiResult;
|
||||
}
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<RescueDevice>> GetLocation (string guid)
|
||||
{
|
||||
ApiResult<RescueDevice> apiResult = new ApiResult<RescueDevice>();
|
||||
try
|
||||
{
|
||||
var location = await backendRepository.GetOneAsync<RescueDevice>("rescue_device", $"rescue_device_guid = '{guid}'");
|
||||
|
||||
if(location == null)
|
||||
{
|
||||
apiResult.Code = "9998";
|
||||
apiResult.Msg = "資料不存在,請重新操作";
|
||||
}
|
||||
else
|
||||
{
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Data = location;
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】");
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + ex.Message);
|
||||
}
|
||||
|
||||
return apiResult;
|
||||
}
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<string>> SaveFireExtinguisher(SaveFireExtinguisher save)
|
||||
{
|
||||
ApiResult<string> apiResult = new ApiResult<string>();
|
||||
try
|
||||
{
|
||||
var a = new Dictionary<string, object>()
|
||||
{
|
||||
{"@location",save.location}
|
||||
};
|
||||
await backendRepository.UpdateOneByCustomTable(a, "rescue_device", $"rescue_device_guid = '{save.guid}'");
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "儲存成功";
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】");
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
public FileResult ExportExcel(string post)
|
||||
{
|
||||
var postObject = JsonConvert.DeserializeObject<Excel>(post);
|
||||
var workbook = new XSSFWorkbook();
|
||||
#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
|
||||
var devicename = "";
|
||||
if (postObject.kind == 0)
|
||||
{
|
||||
devicename = "滅火器";
|
||||
}
|
||||
else
|
||||
{
|
||||
devicename = "AED";
|
||||
}
|
||||
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");
|
||||
int RowPosition = 0;
|
||||
IRow row = sheet.CreateRow(RowPosition);
|
||||
ICell cell = row.CreateCell(1);
|
||||
sheet.SetColumnWidth(0, 4 * 160 * 12);
|
||||
sheet.SetColumnWidth(1, 4 * 160 * 12);
|
||||
sheet.SetColumnWidth(2, 4 * 160 * 12);
|
||||
cell.SetCellValue("設備編號");
|
||||
cell.CellStyle = styleLine12;
|
||||
cell = row.CreateCell(0);
|
||||
cell.SetCellValue("樓層");
|
||||
cell.CellStyle = styleLine12;
|
||||
cell = row.CreateCell(2);
|
||||
cell.SetCellValue("位置");
|
||||
cell.CellStyle = styleLine12;
|
||||
|
||||
foreach(var device in RescueDevices.Result)
|
||||
{
|
||||
RowPosition += 1;
|
||||
row = sheet.CreateRow(RowPosition);
|
||||
for(var a = 0 ; a < 3 ; a++)
|
||||
{
|
||||
cell = row.CreateCell(a);
|
||||
if (a == 1)
|
||||
{
|
||||
cell.SetCellValue(device.rescue_device_id);
|
||||
}
|
||||
if (a == 0)
|
||||
{
|
||||
cell.SetCellValue(device.floor_name);
|
||||
}
|
||||
if (a == 2)
|
||||
{
|
||||
cell.SetCellValue(device.location);
|
||||
}
|
||||
cell.CellStyle = style12;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
var ms = new NpoiMemoryStream
|
||||
{
|
||||
AllowClose = false
|
||||
};
|
||||
workbook.Write(ms);
|
||||
ms.Flush();
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
|
||||
return File(ms, "application/vnd.ms-excel", postObject.buildname + "-" + devicename + ".xlsx");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
173
Backend/Controllers/ServicePlanController.cs
Normal file
173
Backend/Controllers/ServicePlanController.cs
Normal file
@ -0,0 +1,173 @@
|
||||
using Backend.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 Backend.Controllers
|
||||
{
|
||||
public class ServicePlanController : MybaseController<ServicePlanController>
|
||||
{
|
||||
private readonly IBackendRepository backendRepository;
|
||||
public ServicePlanController(IBackendRepository backendRepository)
|
||||
{
|
||||
this.backendRepository = backendRepository;
|
||||
}
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public async Task<ApiResult<string>> SavePlan (BackgroundServicePlan plan)
|
||||
{
|
||||
ApiResult<string> apiResult = new ApiResult<string>();
|
||||
try
|
||||
{
|
||||
if (plan.Id == 0)
|
||||
{
|
||||
Dictionary<string, object> Plan = new Dictionary<string, object>()
|
||||
{
|
||||
{ "@status", plan.status},
|
||||
{ "@plan_name", plan.Plane_name},
|
||||
{ "@building_guid", plan.building_guid},
|
||||
{ "@target_table", plan.Target_table},
|
||||
{ "@execution_time", plan.Execution_time},
|
||||
{ "@execution_type", plan.Execution_type},
|
||||
{ "@start_time", plan.Start_time}
|
||||
};
|
||||
if(plan.End_time == "0001-01-01 00:00:00")
|
||||
{
|
||||
Plan.Add("@end_time", null);
|
||||
}
|
||||
else
|
||||
{
|
||||
Plan.Add("@end_time", plan.End_time);
|
||||
}
|
||||
|
||||
await backendRepository.AddOneByCustomTable(Plan, "background_service_plan");
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "新增成功";
|
||||
}
|
||||
else
|
||||
{
|
||||
Dictionary<string, object> Plan = new Dictionary<string, object>()
|
||||
{
|
||||
{ "@status", plan.status},
|
||||
{ "@plan_name", plan.Plane_name},
|
||||
{ "@building_guid", plan.building_guid},
|
||||
{ "@target_table", plan.Target_table},
|
||||
{ "@execution_time", plan.Execution_time},
|
||||
{ "@execution_type", plan.Execution_type},
|
||||
{ "@start_time", plan.Start_time}
|
||||
};
|
||||
if (plan.End_time == "0001-01-01 00:00:00")
|
||||
{
|
||||
Plan.Add("@end_time", null);
|
||||
}
|
||||
else
|
||||
{
|
||||
Plan.Add("@end_time", plan.End_time);
|
||||
}
|
||||
await backendRepository.UpdateOneByCustomTable(Plan, "background_service_plan", "id='" + plan.Id + "'");
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "修改成功";
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
string json = System.Text.Json.JsonSerializer.Serialize(plan);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + json);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
}
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
public async Task<ApiResult<List<PlanTable>>> GetPlanTable()
|
||||
{
|
||||
ApiResult<List<PlanTable>> apiResult = new ApiResult<List<PlanTable>>();
|
||||
try
|
||||
{
|
||||
var plans = await backendRepository.GetAllAsync<PlanTable>("select bsp.*,b.full_name building from background_service_plan bsp left join building b on bsp.building_guid = b.building_guid where bsp.deleted = 0 order by bsp.id desc");
|
||||
foreach(var plan in plans)
|
||||
{
|
||||
var timetype = plan.Execution_type switch
|
||||
{
|
||||
0 => "分",
|
||||
1 => "小時",
|
||||
2 => "天",
|
||||
3 => "週",
|
||||
4 => "月",
|
||||
_ => "",
|
||||
};
|
||||
|
||||
plan.execution = "每" + plan.Execution_time + timetype;
|
||||
|
||||
plan.time = plan.Start_time + @"<br>-<br>";
|
||||
if(plan.End_time != "0001-01-01 00:00:00")
|
||||
{
|
||||
plan.time += plan.End_time;
|
||||
}
|
||||
}
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Data = plans;
|
||||
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
}
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
public async Task<ApiResult<BackgroundServicePlan>> GetonePlan (int id)
|
||||
{
|
||||
ApiResult<BackgroundServicePlan> apiResult = new ApiResult<BackgroundServicePlan>();
|
||||
try
|
||||
{
|
||||
var plan = await backendRepository.GetOneAsync<BackgroundServicePlan>("background_service_plan", $" id = {id}");
|
||||
apiResult.Data = plan;
|
||||
apiResult.Code = "0000";
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + id);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
}
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<string>> DeletePlan(int id)
|
||||
{
|
||||
ApiResult<string> apiResult = new ApiResult<string>();
|
||||
|
||||
try
|
||||
{
|
||||
await backendRepository.DeleteOne(id.ToString(), "background_service_plan", "id");
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "刪除成功";
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + "id=" + id);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
}
|
||||
|
||||
return apiResult;
|
||||
}
|
||||
}
|
||||
}
|
804
Backend/Controllers/SystemCategoryController.cs
Normal file
804
Backend/Controllers/SystemCategoryController.cs
Normal file
@ -0,0 +1,804 @@
|
||||
using Backend.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 Backend.Controllers
|
||||
{
|
||||
public class SystemCategoryController : MybaseController<SystemCategoryController>
|
||||
{
|
||||
|
||||
private readonly IBackendRepository backendRepository;
|
||||
|
||||
public SystemCategoryController(IBackendRepository backendRepository)
|
||||
{
|
||||
this.backendRepository = backendRepository;
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取得系統大類清單
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<List<SystemMain>>> SystemMainList()
|
||||
{
|
||||
ApiResult<List<SystemMain>> apiResult = new ApiResult<List<SystemMain>>();
|
||||
|
||||
try
|
||||
{
|
||||
var sWhere = "deleted = 0";
|
||||
|
||||
var systemMainList = await backendRepository.GetAllAsync<SystemMain>("main_system", sWhere, null, "priority ASC, created_at DESC");
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Data = systemMainList;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
}
|
||||
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取得單一系統大類
|
||||
/// </summary>
|
||||
/// <param name="guid"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<SystemMain>> GetOneSystemMain(string guid)
|
||||
{
|
||||
ApiResult<SystemMain> apiResult = new ApiResult<SystemMain>();
|
||||
|
||||
try
|
||||
{
|
||||
string sWhere = @$"deleted = @Deleted AND main_system_guid = @Guid";
|
||||
|
||||
object param = new { Deleted = 0, Guid = guid };
|
||||
|
||||
var systemMain = await backendRepository.GetOneAsync<SystemMain>("main_system", sWhere, param);
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Data = systemMain;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
}
|
||||
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新增 / 修改 系統大類資料
|
||||
/// </summary>
|
||||
/// <param name="post"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<string>> SaveSystemMain(SystemMain post)
|
||||
{
|
||||
ApiResult<string> apiResult = new ApiResult<string>();
|
||||
|
||||
try
|
||||
{
|
||||
string sWhere = @$"deleted = @Deleted AND main_system_guid = @Guid";
|
||||
|
||||
object param = new { Deleted = 0, Guid = post.Main_system_guid };
|
||||
|
||||
var systemMain = await backendRepository.GetOneAsync<SystemMain>("main_system", sWhere, param);
|
||||
|
||||
if (systemMain == null)
|
||||
{
|
||||
//新增
|
||||
//產生一組GUID
|
||||
var guid = Guid.NewGuid(); //系統大類GUID
|
||||
|
||||
Dictionary<string, object> systemMainDic = new Dictionary<string, object>()
|
||||
{
|
||||
{ "@main_system_guid", guid},
|
||||
{ "@full_name", post.Full_name},
|
||||
{ "@code", post.Code},
|
||||
{ "@created_by", myUserInfo.Userinfo_guid}
|
||||
};
|
||||
await backendRepository.AddOneByCustomTable(systemMainDic, "main_system");
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "新增成功";
|
||||
}
|
||||
else
|
||||
{
|
||||
Dictionary<string, object> systemMainDic = new Dictionary<string, object>()
|
||||
{
|
||||
{ "@full_name", post.Full_name},
|
||||
{ "@code", post.Code},
|
||||
{ "@updated_by", myUserInfo.Userinfo_guid},
|
||||
{ "@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")},
|
||||
};
|
||||
|
||||
await backendRepository.UpdateOneByCustomTable(systemMainDic, "main_system", "main_system_guid='" + systemMain.Main_system_guid + "'");
|
||||
|
||||
var AuthCodes = await backendRepository.GetAllAsync<string>(
|
||||
@$"select AuthCode from auth_page ap
|
||||
join sub_system ss on ss.sub_system_guid = ap.ShowView
|
||||
join main_system ms on ms.main_system_guid = ss.main_system_guid
|
||||
where ms.main_system_guid = '{systemMain.Main_system_guid}'");
|
||||
|
||||
if(AuthCodes.Count > 0)
|
||||
{
|
||||
await backendRepository.ExecuteSql($@"UPDATE auth_page
|
||||
SET MainName = '{post.Full_name}'
|
||||
WHERE AuthCode IN @authCode;",new { authCode = AuthCodes });
|
||||
}
|
||||
|
||||
#region 新增至派送資料表
|
||||
var auth_Pages = await backendRepository.GetAllAsync<Auth_page>("auth_page", "");
|
||||
List<Dictionary<string, object>> authPagesDics = new List<Dictionary<string, object>>();
|
||||
foreach (var auth_page in auth_Pages)
|
||||
{
|
||||
Dictionary<string, object> authPagesDic = new Dictionary<string, object>()
|
||||
{
|
||||
{ "@AuthCode", auth_page.AuthCode},
|
||||
{ "@AuthType", auth_page.AuthType},
|
||||
{ "@MainName", auth_page.MainName},
|
||||
{ "@SubName", auth_page.SubName},
|
||||
{ "@building_guid", auth_page.building_guid},
|
||||
{ "@ShowView", auth_page.ShowView},
|
||||
{ "@created_at", auth_page.created_at},
|
||||
};
|
||||
|
||||
authPagesDics.Add(authPagesDic);
|
||||
}
|
||||
await backendRepository.ManualInsertBackgroundServiceTask("", "", "auth_page", "purge_all_insert", authPagesDics);
|
||||
#endregion
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.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="guid"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<string>> DeleteOneSystemMain(string guid)
|
||||
{
|
||||
ApiResult<string> apiResult = new ApiResult<string>();
|
||||
|
||||
try
|
||||
{
|
||||
string sWhere = @$"deleted = @Deleted AND main_system_guid = @Guid";
|
||||
|
||||
object param = new { Deleted = 0, Guid = guid };
|
||||
|
||||
var systemMain = await backendRepository.GetOneAsync<SystemMain>("main_system", sWhere, param);
|
||||
|
||||
if (systemMain == null)
|
||||
{
|
||||
apiResult.Code = "9998";
|
||||
apiResult.Msg = "查無該系統大類";
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
//檢查是否有未刪除的區域選單
|
||||
var sbuildMenu = $@"SELECT
|
||||
b.full_name
|
||||
FROM building_menu bm
|
||||
LEFT JOIN building b ON bm.building_guid = b.building_guid AND b.deleted = 0
|
||||
WHERE bm.main_system_guid = @Guid
|
||||
GROUP BY b.full_name";
|
||||
|
||||
var buildMenus = await backendRepository.GetAllAsync<string>(sbuildMenu, new { Guid = guid });
|
||||
if (buildMenus.Count > 0)
|
||||
{
|
||||
apiResult.Code = "9997";
|
||||
apiResult.Msg = "區域選單中尚有棟別正在使用該系統大類,故無法刪除";
|
||||
apiResult.Data = string.Join("<br>", buildMenus);
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
//檢查底下是否有未刪除的系統小類
|
||||
string sSubWhere = @$"deleted = @Deleted AND main_system_guid = @Guid";
|
||||
object sub_param = new { Deleted = 0, Guid = systemMain.Main_system_guid };
|
||||
var systemSubs = await backendRepository.GetAllAsync<SystemSub>("sub_system", sWhere, param);
|
||||
|
||||
if (systemSubs.Count > 0)
|
||||
{
|
||||
apiResult.Code = "9997";
|
||||
apiResult.Msg = "系統小類中尚有小類正在使用系統大類,故無法刪除";
|
||||
apiResult.Data = string.Join("<br>", systemSubs.Select(x => x.Full_name).ToList());
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
await backendRepository.DeleteOne(guid, "main_system", "main_system_guid");
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "刪除成功";
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + "main_system_guid=" + guid);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
}
|
||||
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取得系統小類清單
|
||||
/// </summary>
|
||||
/// <param name="main_system_guid"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<List<SystemSub>>> SystemSubList(string main_system_guid)
|
||||
{
|
||||
ApiResult<List<SystemSub>> apiResult = new ApiResult<List<SystemSub>>();
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
var sWhere = @"deleted = @Deleted AND main_system_guid = @Main_system_guid";
|
||||
|
||||
object param = new { Deleted = 0, Main_system_guid = main_system_guid };
|
||||
|
||||
var systemSubs = await backendRepository.GetAllAsync<SystemSub>("sub_system", sWhere, param, "priority ASC, created_at DESC");
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Data = systemSubs;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
}
|
||||
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取得單一系統小類
|
||||
/// </summary>
|
||||
/// <param name="guid"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<SystemSub>> GetOneSystemSub(string guid)
|
||||
{
|
||||
ApiResult<SystemSub> apiResult = new ApiResult<SystemSub>();
|
||||
|
||||
try
|
||||
{
|
||||
string sWhere = @$"deleted = @Deleted AND sub_system_guid = @Guid";
|
||||
|
||||
object param = new { Deleted = 0, Guid = guid };
|
||||
|
||||
var systemSub = await backendRepository.GetOneAsync<SystemSub>("sub_system", sWhere, param);
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Data = systemSub;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
}
|
||||
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新增 / 修改 系統小類資料
|
||||
/// </summary>
|
||||
/// <param name="post"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<string>> SaveSystemSub(SystemSub post)
|
||||
{
|
||||
ApiResult<string> apiResult = new ApiResult<string>();
|
||||
|
||||
try
|
||||
{
|
||||
string sWhere = @$"deleted = @Deleted AND sub_system_guid = @Guid";
|
||||
|
||||
object param = new { Deleted = 0, Guid = post.Sub_system_guid };
|
||||
|
||||
var systemSub = await backendRepository.GetOneAsync<SystemSub>("sub_system", sWhere, param);
|
||||
|
||||
if (systemSub == null)
|
||||
{
|
||||
//新增
|
||||
//產生一組GUID
|
||||
var guid = Guid.NewGuid(); //GUID
|
||||
|
||||
Dictionary<string, object> systemSubDic = new Dictionary<string, object>()
|
||||
{
|
||||
{ "@sub_system_guid", guid},
|
||||
{ "@main_system_guid", post.Main_system_guid},
|
||||
{ "@full_name", post.Full_name},
|
||||
{ "@created_by", myUserInfo.Userinfo_guid}
|
||||
};
|
||||
await backendRepository.AddOneByCustomTable(systemSubDic, "sub_system");
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "新增成功";
|
||||
}
|
||||
else
|
||||
{
|
||||
Dictionary<string, object> systemSubDic = new Dictionary<string, object>()
|
||||
{
|
||||
{ "@full_name", post.Full_name},
|
||||
{ "@updated_by", myUserInfo.Userinfo_guid},
|
||||
{ "@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")},
|
||||
};
|
||||
|
||||
await backendRepository.UpdateOneByCustomTable(systemSubDic, "sub_system", "sub_system_guid='" + systemSub.Sub_system_guid + "'");
|
||||
|
||||
var AuthCodes = await backendRepository.GetAllAsync<string>(
|
||||
@$"select AuthCode from auth_page ap
|
||||
where ap.ShowView = '{systemSub.Sub_system_guid}'");
|
||||
|
||||
if (AuthCodes.Count > 0)
|
||||
{
|
||||
await backendRepository.ExecuteSql($@"UPDATE auth_page
|
||||
SET SubName = '{post.Full_name}'
|
||||
WHERE AuthCode IN @authCode;", new { authCode = AuthCodes });
|
||||
}
|
||||
|
||||
#region 新增至派送資料表
|
||||
var auth_Pages = await backendRepository.GetAllAsync<Auth_page>("auth_page", "");
|
||||
List<Dictionary<string, object>> authPagesDics = new List<Dictionary<string, object>>();
|
||||
foreach (var auth_page in auth_Pages)
|
||||
{
|
||||
Dictionary<string, object> authPagesDic = new Dictionary<string, object>()
|
||||
{
|
||||
{ "@AuthCode", auth_page.AuthCode},
|
||||
{ "@AuthType", auth_page.AuthType},
|
||||
{ "@MainName", auth_page.MainName},
|
||||
{ "@SubName", auth_page.SubName},
|
||||
{ "@building_guid", auth_page.building_guid},
|
||||
{ "@ShowView", auth_page.ShowView},
|
||||
{ "@created_at", auth_page.created_at},
|
||||
};
|
||||
|
||||
authPagesDics.Add(authPagesDic);
|
||||
}
|
||||
await backendRepository.ManualInsertBackgroundServiceTask("", "", "auth_page", "purge_all_insert", authPagesDics);
|
||||
#endregion
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.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="guid"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<string>> DeleteOneSystemSub(string guid)
|
||||
{
|
||||
ApiResult<string> apiResult = new ApiResult<string>();
|
||||
|
||||
try
|
||||
{
|
||||
string sWhere = @$"deleted = @Deleted AND sub_system_guid = @Guid";
|
||||
|
||||
object param = new { Deleted = 0, Guid = guid };
|
||||
|
||||
var systemSub = await backendRepository.GetOneAsync<SystemSub>("sub_system", sWhere, param);
|
||||
|
||||
if (systemSub == null)
|
||||
{
|
||||
apiResult.Code = "9998";
|
||||
apiResult.Msg = "查無該系統小類";
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
//檢查是否有未刪除的區域選單
|
||||
var sbuildMenu = $@"SELECT
|
||||
CONCAT(b.full_name, ' - ', ms.full_name)
|
||||
FROM building_menu bm
|
||||
LEFT JOIN building b ON bm.building_guid = b.building_guid AND b.deleted = 0
|
||||
LEFT JOIN main_system ms ON bm.main_system_guid = ms.main_system_guid AND ms.deleted = 0
|
||||
WHERE bm.sub_system_guid = @Guid";
|
||||
|
||||
var buildMenus = await backendRepository.GetAllAsync<string>(sbuildMenu, new { Guid = guid });
|
||||
if (buildMenus.Count > 0)
|
||||
{
|
||||
apiResult.Code = "9997";
|
||||
apiResult.Msg = "區域選單中尚有選單正在使用該系統小類,故無法刪除";
|
||||
apiResult.Data = string.Join("<br>", buildMenus);
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
//檢查是否有未刪除的系統小類樓層
|
||||
var ssubSystemFloor = $@"SELECT
|
||||
CONCAT(b.full_name, ' - ', ms.full_name, ' - ', ss.full_name, ' - ', f.full_name)
|
||||
FROM sub_system_floor ssf
|
||||
LEFT JOIN building b ON ssf.building_guid = b.building_guid AND b.deleted = 0
|
||||
LEFT JOIN main_system ms ON ssf.main_system_guid = ms.main_system_guid AND ms.deleted = 0
|
||||
LEFT JOIN sub_system ss ON ssf.sub_system_guid = ss.sub_system_guid AND ss.deleted = 0
|
||||
LEFT JOIN floor f ON ssf.floor_guid = f.floor_guid AND f.deleted = 0
|
||||
WHERE ssf.sub_system_guid = @Guid
|
||||
AND ssf.deleted = 0";
|
||||
|
||||
var subSystemFloor = await backendRepository.GetAllAsync<string>(sbuildMenu, new { Guid = guid });
|
||||
if (subSystemFloor.Count > 0)
|
||||
{
|
||||
apiResult.Code = "9997";
|
||||
apiResult.Msg = "區域選單中尚有樓層正在使用該系統小類,故無法刪除";
|
||||
apiResult.Data = string.Join("<br>", subSystemFloor);
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
//檢查是否有未刪除的設備項目
|
||||
var sdeviceItem = $@"SELECT
|
||||
di.full_name
|
||||
FROM device_item di
|
||||
WHERE di.deleted = 0
|
||||
AND di.sub_system_guid = @Guid";
|
||||
|
||||
var deviceItems = await backendRepository.GetAllAsync<string>(sdeviceItem, new { Guid = guid });
|
||||
if (deviceItems.Count > 0)
|
||||
{
|
||||
apiResult.Code = "9997";
|
||||
apiResult.Msg = "設備項目中尚有項目正在使用該系統小類,故無法刪除";
|
||||
apiResult.Data = string.Join("<br>", deviceItems);
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
await backendRepository.DeleteOne(guid, "sub_system", "sub_system_guid");
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "刪除成功";
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + "sub_system_guid=" + guid);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
}
|
||||
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<string>> Savedevice_item(Device_item device_Item)
|
||||
{
|
||||
ApiResult<string> apiResult = new ApiResult<string>();
|
||||
|
||||
try
|
||||
{
|
||||
//檢查是否有未刪除的區域選單
|
||||
if(device_Item.is_show_riserDiagram == 1)
|
||||
{
|
||||
var sql_show_riserDiagram = $@"SELECT * FROM device_item di
|
||||
WHERE di.sub_system_guid = @SubSystemGuid AND di.deleted = 0 AND is_show_riserDiagram = 1";
|
||||
|
||||
var is_show_riserDiagram = await backendRepository.GetAllAsync<string>(sql_show_riserDiagram, new { SubSystemGuid = device_Item.sub_system_guid });
|
||||
|
||||
if (is_show_riserDiagram.Count() > 0)
|
||||
{
|
||||
apiResult.Code = "9998";
|
||||
apiResult.Msg = "請先取消已選擇顯示於昇位圖點位。";
|
||||
return apiResult;
|
||||
}
|
||||
}
|
||||
|
||||
if (device_Item.device_item_guid == null)
|
||||
{
|
||||
//新增
|
||||
//產生一組GUID
|
||||
var guid = Guid.NewGuid(); //GUID
|
||||
|
||||
Dictionary<string, object> Device_itemDic = new Dictionary<string, object>()
|
||||
{
|
||||
{ "@device_item_guid", guid},
|
||||
{ "@sub_system_guid", device_Item.sub_system_guid},
|
||||
{ "@full_name", device_Item.full_name},
|
||||
{ "@points", device_Item.points},
|
||||
{ "@unit", device_Item.unit},
|
||||
{ "@is_show", device_Item.is_show},
|
||||
{ "@is_show_riserDiagram", device_Item.is_show_riserDiagram},
|
||||
{ "@is_controll", device_Item.is_controll},
|
||||
{ "@is_bool", device_Item.is_bool},
|
||||
{ "@created_by", myUserInfo.Userinfo_guid},
|
||||
};
|
||||
await backendRepository.AddOneByCustomTable(Device_itemDic, "device_item");
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "新增成功";
|
||||
}
|
||||
else
|
||||
{
|
||||
Dictionary<string, object> Device_itemDic = new Dictionary<string, object>()
|
||||
{
|
||||
{ "@sub_system_guid", device_Item.sub_system_guid},
|
||||
{ "@full_name", device_Item.full_name},
|
||||
{ "@points", device_Item.points},
|
||||
{ "@unit", device_Item.unit},
|
||||
{ "@is_show", device_Item.is_show},
|
||||
{ "@is_show_riserDiagram", device_Item.is_show_riserDiagram},
|
||||
{ "@is_controll", device_Item.is_controll},
|
||||
{ "@is_bool", device_Item.is_bool},
|
||||
{ "@updated_by", myUserInfo.Userinfo_guid},
|
||||
{ "@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")},
|
||||
};
|
||||
|
||||
await backendRepository.UpdateOneByCustomTable(Device_itemDic, "device_item", "device_item_guid='" + device_Item.device_item_guid + "'");
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "修改成功";
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
string json = System.Text.Json.JsonSerializer.Serialize(device_Item);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + json);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
}
|
||||
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<List<Device_item>>> DeviceItemTable(string sub_system_guid)
|
||||
{
|
||||
ApiResult<List<Device_item>> apiResult = new ApiResult<List<Device_item>>();
|
||||
try
|
||||
{
|
||||
|
||||
var sWhere = @"deleted = @Deleted AND sub_system_guid = @Sub_system_guid";
|
||||
|
||||
object param = new { Deleted = 0, Sub_system_guid = sub_system_guid };
|
||||
|
||||
var systemSubs = await backendRepository.GetAllAsync<Device_item>("device_item", sWhere, param, "created_at DESC");
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Data = systemSubs;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
}
|
||||
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<Device_item>> GetOneDeviceItem(string guid)
|
||||
{
|
||||
ApiResult<Device_item> apiResult = new ApiResult<Device_item>();
|
||||
|
||||
try
|
||||
{
|
||||
string sWhere = @$"deleted = @Deleted AND device_item_guid = @Guid";
|
||||
|
||||
object param = new { Deleted = 0, Guid = guid };
|
||||
|
||||
var Deviceitem = await backendRepository.GetOneAsync<Device_item>("device_item", sWhere, param);
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Data = Deviceitem;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
}
|
||||
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<string>> DeleteOneSystemSubDeviceItem(string guid)
|
||||
{
|
||||
ApiResult<string> apiResult = new ApiResult<string>();
|
||||
|
||||
try
|
||||
{
|
||||
string sWhere = @$"deleted = @Deleted AND device_item_guid = @Guid";
|
||||
|
||||
object param = new { Deleted = 0, Guid = guid };
|
||||
|
||||
var device_Item = await backendRepository.GetOneAsync<Device_item>("device_item", sWhere, param);
|
||||
|
||||
if (device_Item == null)
|
||||
{
|
||||
apiResult.Code = "9998";
|
||||
apiResult.Msg = "查無該設備項目";
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
await backendRepository.DeleteOne(guid, "device_item", "device_item_guid");
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "刪除成功";
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + "device_item_guid=" + guid);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
}
|
||||
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
public async Task<ApiResult<bool>> HaveSamePoints(Checksame post)
|
||||
{
|
||||
ApiResult<bool> apiResult = new ApiResult<bool>();
|
||||
try
|
||||
{
|
||||
var point = await backendRepository.GetOneAsync<Device_item>("device_item", $" sub_system_guid = '{post.sub_system_guid}' and points = '{post.points}' and device_item_guid != '{post.device_item_guid}' and deleted = 0");
|
||||
if (point != null)
|
||||
{
|
||||
apiResult.Data = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
apiResult.Data = false;
|
||||
}
|
||||
apiResult.Code = "0000";
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
public async Task<ApiResult<Deletebool>> CheckCanDelete(guidandsubguid post)
|
||||
{
|
||||
ApiResult<Deletebool> apiResult = new ApiResult<Deletebool>();
|
||||
try
|
||||
{
|
||||
var tags = await backendRepository.GetAllAsync<Tags>(
|
||||
@$"select * from (select dk.device_building_tag ,dk.device_name_tag,dk.device_system_tag from device_kind dk where dk.device_normal_point_guid = '{post.guid}') dkn
|
||||
union(select dk.device_building_tag, dk.device_name_tag, dk.device_system_tag from device_kind dk where dk.device_close_point_guid = '{post.guid}')
|
||||
union(select dk.device_building_tag, dk.device_name_tag, dk.device_system_tag from device_kind dk where dk.device_error_point_guid = '{post.guid}')");
|
||||
|
||||
if (tags.Count == 0)
|
||||
{
|
||||
Deletebool deletebool = new Deletebool()
|
||||
{
|
||||
Delete = false,
|
||||
Reason = ""
|
||||
};
|
||||
apiResult.Data = deletebool;
|
||||
}
|
||||
else
|
||||
{
|
||||
Deletebool deletebool = new Deletebool()
|
||||
{
|
||||
Delete = true,
|
||||
Reason = ""
|
||||
};
|
||||
var unionsql = "";
|
||||
var last = tags.Last();
|
||||
foreach (var tag in tags)
|
||||
{
|
||||
unionsql += $@"select d.building_guid,d.main_system_guid,d.sub_system_guid,d.device_name_tag from device d where d.sub_system_guid = '{post.subguid}' and d.device_building_tag = '{tag.device_building_tag}' and d.device_system_tag = '{tag.device_system_tag}' and d.device_name_tag = '{tag.device_name_tag}' group by d.building_guid,d.main_system_guid,d.sub_system_guid,d.device_name_tag";
|
||||
if (!last.Equals(tag))
|
||||
{
|
||||
unionsql += " union ";
|
||||
}
|
||||
}
|
||||
var sql = @$"select ms.full_name msname,b.full_name bname,s.full_name subname,de.device_name_tag from
|
||||
({unionsql}) de
|
||||
left join main_system ms on ms.main_system_guid = de.main_system_guid
|
||||
left join building b on b.building_guid = de.building_guid
|
||||
left join sub_system s on s.sub_system_guid = de.sub_system_guid";
|
||||
var names = await backendRepository.GetAllAsync<GetCheckName>(sql);
|
||||
var count = 0;
|
||||
foreach (var name in names)
|
||||
{
|
||||
count++;
|
||||
deletebool.Reason += count.ToString() + "." + name.bname + "-" + name.msname + "-" + name.subname + "-" + name.device_name_tag + "<br>";
|
||||
}
|
||||
apiResult.Data = deletebool;
|
||||
}
|
||||
apiResult.Code = "0000";
|
||||
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
public async Task<ApiResult<Deletebool>> CheckCanSubDelete(string guid)
|
||||
{
|
||||
ApiResult<Deletebool> apiResult = new ApiResult<Deletebool>();
|
||||
try
|
||||
{
|
||||
var text = "";
|
||||
var item = await backendRepository.GetAllAsync<string>(@$"select device_item_guid from device_item where deleted = 0 and sub_system_guid = '{guid}'");
|
||||
if(item.Count > 0)
|
||||
{
|
||||
text += "項目還有尚未刪除<br>";
|
||||
}
|
||||
var menu = await backendRepository.GetAllAsync<string>($"select sub_system_guid from building_menu where sub_system_guid = '{guid}'");
|
||||
if (menu.Count > 0)
|
||||
{
|
||||
text += "區域選單還有尚未刪除<br>";
|
||||
}
|
||||
Deletebool deletebool = new Deletebool()
|
||||
{
|
||||
Delete = false,
|
||||
Reason = ""
|
||||
};
|
||||
if (text != "")
|
||||
{
|
||||
deletebool.Delete = true;
|
||||
deletebool.Reason = text;
|
||||
}
|
||||
else
|
||||
{
|
||||
deletebool.Delete = false;
|
||||
}
|
||||
apiResult.Data = deletebool;
|
||||
apiResult.Code = "0000";
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + guid);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
}
|
||||
return apiResult;
|
||||
}
|
||||
}
|
||||
}
|
640
Backend/Controllers/UserInfoController.cs
Normal file
640
Backend/Controllers/UserInfoController.cs
Normal file
@ -0,0 +1,640 @@
|
||||
using Backend.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 Backend.Controllers
|
||||
{
|
||||
public class UserInfoController : MybaseController<UserInfoController>
|
||||
{
|
||||
private readonly ILogger<UserInfoController> _logger;
|
||||
private readonly IBackendRepository backendRepository;
|
||||
|
||||
public UserInfoController(ILogger<UserInfoController> logger, IBackendRepository backendRepository)
|
||||
{
|
||||
_logger = logger;
|
||||
this.backendRepository = backendRepository;
|
||||
}
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
/// <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>();
|
||||
|
||||
UserInfo userInfo = null;
|
||||
|
||||
try
|
||||
{
|
||||
userInfo = await backendRepository.GetOneAsync<UserInfo>("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", myUserInfo.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", myUserInfo.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", myUserInfo.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", myUserInfo.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<UserInfo>("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_guid=D.building_guid 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_guid = '{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", myUserInfo.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;
|
||||
}
|
||||
}
|
||||
}
|
226
Backend/Controllers/VariableController.cs
Normal file
226
Backend/Controllers/VariableController.cs
Normal file
@ -0,0 +1,226 @@
|
||||
using Backend.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 Backend.Controllers
|
||||
{
|
||||
public class VariableController : MybaseController<VariableController>
|
||||
{
|
||||
private readonly IBackendRepository backendRepository;
|
||||
public VariableController(IBackendRepository backendRepository)
|
||||
{
|
||||
this.backendRepository = backendRepository;
|
||||
}
|
||||
|
||||
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SystemType列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<List<KeyValue>>> SystemTypeList()
|
||||
{
|
||||
ApiResult<List<KeyValue>> apiResult = new ApiResult<List<KeyValue>>();
|
||||
try
|
||||
{
|
||||
var sqlString = @$"SELECT DISTINCT system_type as Name, system_type as Value FROM variable v WHERE v.deleted = 0 ORDER BY v.system_type";
|
||||
var 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 系統變數資料列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<List<VariableInfo>>> VariableInfoList(PostVariableInfoFilter post)
|
||||
{
|
||||
ApiResult<List<VariableInfo>> apiResult = new ApiResult<List<VariableInfo>>();
|
||||
|
||||
try
|
||||
{
|
||||
var sWhere = "deleted = 0";
|
||||
|
||||
if (!string.IsNullOrEmpty(post.SelectedSystemType))
|
||||
{
|
||||
sWhere += " AND system_type = @SystemType";
|
||||
}
|
||||
|
||||
var variableInfos = await backendRepository.GetAllAsync<VariableInfo>("variable", sWhere, new { SystemType = post.SelectedSystemType }, "system_type, system_priority");
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Data = variableInfos;
|
||||
}
|
||||
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<VariableInfo>> GetOneVariable(int id)
|
||||
{
|
||||
ApiResult<VariableInfo> apiResult = new ApiResult<VariableInfo>();
|
||||
|
||||
try
|
||||
{
|
||||
string sWhere = @$"deleted = 0 AND id = @Id";
|
||||
|
||||
object param = new { Id = id };
|
||||
|
||||
var variableInfo = await backendRepository.GetOneAsync<VariableInfo>("variable", sWhere, param);
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Data = variableInfo;
|
||||
}
|
||||
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>> SaveVariable(VariableInfo post)
|
||||
{
|
||||
ApiResult<string> apiResult = new ApiResult<string>();
|
||||
|
||||
try
|
||||
{
|
||||
string sWhere = @$"deleted = 0 AND id = @Id";
|
||||
|
||||
object param = new { Id = post.id };
|
||||
|
||||
var variableInfo = await backendRepository.GetOneAsync<VariableInfo>("variable", sWhere, param);
|
||||
|
||||
if (variableInfo == null)
|
||||
{
|
||||
//新增
|
||||
|
||||
Dictionary<string, object> variableInfoDic = new Dictionary<string, object>()
|
||||
{
|
||||
{ "@system_type", post.System_type},
|
||||
{ "@system_key", post.System_key},
|
||||
{ "@system_value", post.system_value},
|
||||
{ "@system_remark", post.system_remark},
|
||||
{ "@system_priority", post.system_priority},
|
||||
{ "@system_parent_id", post.system_parent_id},
|
||||
{ "@created_by", myUserInfo.Userinfo_guid},
|
||||
};
|
||||
await backendRepository.AddOneByCustomTable(variableInfoDic, "variable");
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "新增成功";
|
||||
}
|
||||
else
|
||||
{
|
||||
Dictionary<string, object> variableInfoDic = new Dictionary<string, object>()
|
||||
{
|
||||
{ "@system_type", post.System_type},
|
||||
{ "@system_key", post.System_key},
|
||||
{ "@system_value", post.system_value},
|
||||
{ "@system_remark", post.system_remark},
|
||||
{ "@system_priority", post.system_priority},
|
||||
{ "@system_parent_id", post.system_parent_id},
|
||||
{ "@updated_by", myUserInfo.Userinfo_guid},
|
||||
{ "@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")},
|
||||
};
|
||||
|
||||
await backendRepository.UpdateOneByCustomTable(variableInfoDic, "variable", "id=" + variableInfo.id);
|
||||
|
||||
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="guid"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult<string>> DeleteOneVariable(int id)
|
||||
{
|
||||
ApiResult<string> apiResult = new ApiResult<string>();
|
||||
|
||||
try
|
||||
{
|
||||
string sWhere = @$"deleted = 0 AND id = @Id";
|
||||
|
||||
object param = new { Id = id };
|
||||
|
||||
var variableInfo = await backendRepository.GetOneAsync<VariableInfo>("variable", sWhere, param);
|
||||
|
||||
if (variableInfo == null)
|
||||
{
|
||||
apiResult.Code = "9998";
|
||||
apiResult.Msg = "查無該系統變數";
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
await backendRepository.DeleteOne(id.ToString(), "variable", "id");
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "刪除成功";
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + "id=" + id.ToString());
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
}
|
||||
|
||||
return apiResult;
|
||||
}
|
||||
}
|
||||
}
|
90
Backend/Jwt/JwtHelpers.cs
Normal file
90
Backend/Jwt/JwtHelpers.cs
Normal file
@ -0,0 +1,90 @@
|
||||
using Backend.Models;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
|
||||
namespace Backend.Jwt
|
||||
{
|
||||
public interface IJwtHelpers
|
||||
{
|
||||
TnToken GenerateToken(JwtLogin login);
|
||||
}
|
||||
public class JwtHelpers: IJwtHelpers
|
||||
{
|
||||
|
||||
private readonly IConfiguration _configuration;
|
||||
public JwtHelpers(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
}
|
||||
public TnToken GenerateToken(JwtLogin login)
|
||||
{
|
||||
var issuer = _configuration.GetValue<string>("JwtSettings:Issuer");
|
||||
var signKey = _configuration.GetValue<string>("JwtSettings:SignKey");
|
||||
var lifeseconds = _configuration.GetValue<int>("JwtSettings:JwtLifeSeconds");
|
||||
// 設定要加入到 JWT Token 中的聲明資訊(Claims)
|
||||
var claims = new List<Claim>();
|
||||
|
||||
// 在 RFC 7519 規格中(Section#4),總共定義了 7 個預設的 Claims,我們應該只用的到兩種!
|
||||
claims.Add(new Claim(JwtRegisteredClaimNames.Iss, issuer));
|
||||
//claims.Add(new Claim(JwtRegisteredClaimNames.NameId, login.CustomerNo.ToString()));
|
||||
//claims.Add(new Claim(JwtRegisteredClaimNames.Sub, login.Username)); // User.Identity.Name
|
||||
//claims.Add(new Claim(JwtRegisteredClaimNames.Aud, "The Audience"));
|
||||
//claims.Add(new Claim(JwtRegisteredClaimNames.Exp, DateTimeOffset.UtcNow.AddSeconds(expireSeconds).ToUnixTimeSeconds().ToString()));
|
||||
//claims.Add(new Claim(JwtRegisteredClaimNames.Nbf, DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString())); // 必須為數字
|
||||
//claims.Add(new Claim(JwtRegisteredClaimNames.Iat, DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString())); // 必須為數字
|
||||
//claims.Add(new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString())); // JWT ID
|
||||
|
||||
// 網路上常看到的這個 NameId 設定是多餘的
|
||||
//claims.Add(new Claim(JwtRegisteredClaimNames.NameId, userName));
|
||||
|
||||
// 這個 Claim 也以直接被 JwtRegisteredClaimNames.Sub 取代,所以也是多餘的
|
||||
//claims.Add(new Claim(ClaimTypes.Name, userName));
|
||||
|
||||
// 你可以自行擴充 "roles" 加入登入者該有的角色
|
||||
//claims.Add(new Claim("roles", "Users"));
|
||||
//claims.Add(new Claim("groupid", login.AreaCode));
|
||||
claims.Add(new Claim("userinfo_guid", login.userinfo_guid));
|
||||
claims.Add(new Claim("account", login.account));
|
||||
claims.Add(new Claim("full_name", login.full_name));
|
||||
claims.Add(new Claim("email", login.email));
|
||||
var userClaimsIdentity = new ClaimsIdentity(claims);
|
||||
|
||||
// 建立一組對稱式加密的金鑰,主要用於 JWT 簽章之用
|
||||
var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(signKey));
|
||||
|
||||
// HmacSha256 有要求必須要大於 128 bits,所以 key 不能太短,至少要 16 字元以上
|
||||
// https://stackoverflow.com/questions/47279947/idx10603-the-algorithm-hs256-requires-the-securitykey-keysize-to-be-greater
|
||||
var signingCredentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256Signature);
|
||||
|
||||
var now = DateTime.Now;
|
||||
var expires = DateTime.Now.AddSeconds(lifeseconds);
|
||||
|
||||
// 產出所需要的 JWT securityToken 物件,並取得序列化後的 Token 結果(字串格式)
|
||||
var tokenHandler = new JwtSecurityTokenHandler();
|
||||
|
||||
var jst = new JwtSecurityToken(
|
||||
issuer: issuer,//Token釋出者
|
||||
//audience: _options.Value.Audience,//Token接受者
|
||||
claims: claims,//攜帶的負載
|
||||
notBefore: now,//當前時間token生成時間
|
||||
expires: expires,//過期時間
|
||||
signingCredentials: signingCredentials
|
||||
);
|
||||
var serializeToken = tokenHandler.WriteToken(jst);
|
||||
|
||||
var data = new TnToken();
|
||||
data.token = serializeToken;
|
||||
data.type = "bearer";
|
||||
data.expires= lifeseconds;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
19
Backend/Jwt/JwtSettings.cs
Normal file
19
Backend/Jwt/JwtSettings.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Backend.Jwt
|
||||
{
|
||||
public class JwtSettings
|
||||
{
|
||||
/// <summary>
|
||||
/// Token釋出者
|
||||
/// </summary>
|
||||
public string Issuer { get; set; }
|
||||
/// <summary>
|
||||
/// 祕鑰
|
||||
/// </summary>
|
||||
public string SignKey { get; set; }
|
||||
}
|
||||
}
|
23
Backend/Jwt/TnToken.cs
Normal file
23
Backend/Jwt/TnToken.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System;
|
||||
|
||||
namespace Backend.Jwt
|
||||
{
|
||||
/// <summary>
|
||||
/// 存放Token 跟過期時間的類
|
||||
/// </summary>
|
||||
public class TnToken
|
||||
{
|
||||
/// <summary>
|
||||
/// token
|
||||
/// </summary>
|
||||
public string token { get; set; }
|
||||
/// <summary>
|
||||
/// type
|
||||
/// </summary>
|
||||
public string type { get; set; }
|
||||
/// <summary>
|
||||
/// 過期時間
|
||||
/// </summary>
|
||||
public int expires { get; set; }
|
||||
}
|
||||
}
|
22
Backend/Models/Archive.cs
Normal file
22
Backend/Models/Archive.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Backend.Models
|
||||
{
|
||||
public class ArchiveElectricMeter
|
||||
{
|
||||
public string Device_number { get; set; }
|
||||
public string Point { get; set; }
|
||||
public string Start_timestamp { get; set; }
|
||||
public string End_timestamp { get; set; }
|
||||
public int Count_rawdata { get; set; }
|
||||
public double Min_rawdata { get; set; }
|
||||
public double Max_rawdata { get; set; }
|
||||
public double Avg_rawdata { get; set; }
|
||||
public double Sum_rawdata { get; set; }
|
||||
public byte Is_complete { get; set; }
|
||||
public double Repeat_times { get; set; }
|
||||
}
|
||||
}
|
34
Backend/Models/BackgroundServiceMessageNotificationTask.cs
Normal file
34
Backend/Models/BackgroundServiceMessageNotificationTask.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Backend.Models
|
||||
{
|
||||
public enum MessageNotificationTaskType : byte
|
||||
{
|
||||
email = 0,
|
||||
sms = 1,
|
||||
line_notify = 2,
|
||||
}
|
||||
|
||||
public class BackgroundServiceMessageNotificationTask
|
||||
{
|
||||
private string complete_at;
|
||||
private string created_at;
|
||||
private string updated_at;
|
||||
public int Id { get; set; }
|
||||
public byte Task_type { get; set; }
|
||||
public string Recipient_name { get; set; }
|
||||
public string Recipient_phone { get; set; }
|
||||
public string Recipient_email { get; set; }
|
||||
public string Line_token { get; set; }
|
||||
public string Email_subject { get; set; }
|
||||
public string Message_content { get; set; }
|
||||
public int Repeat_times { get; set; }
|
||||
public byte Is_complete { get; set; }
|
||||
public string Complete_at { get { return Convert.ToDateTime(complete_at).ToString("yyyy-MM-dd HH:mm:ss"); } set { complete_at = value; } }
|
||||
public string Created_at { get { return Convert.ToDateTime(created_at).ToString("yyyy-MM-dd HH:mm:ss"); } set { created_at = value; } }
|
||||
public string Updated_at { get { return Convert.ToDateTime(updated_at).ToString("yyyy-MM-dd HH:mm:ss"); } set { updated_at = value; } }
|
||||
}
|
||||
}
|
44
Backend/Models/BackgroundServicePlan.cs
Normal file
44
Backend/Models/BackgroundServicePlan.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Backend.Models
|
||||
{
|
||||
public enum ExecutionTypeEnum : byte
|
||||
{
|
||||
Min = 0, //分
|
||||
Hour = 1, //時
|
||||
Day = 2, //天
|
||||
Week = 3, //週
|
||||
Month = 4 //月
|
||||
|
||||
}
|
||||
|
||||
public class BackgroundServicePlan
|
||||
{
|
||||
private string start_time;
|
||||
private string end_time;
|
||||
private string last_create_time;
|
||||
|
||||
public int Id { get; set; }
|
||||
public string Plane_name { get; set; }
|
||||
public string building_guid { get; set; }
|
||||
public string Target_table { get; set; }
|
||||
public int Execution_time { get; set; }
|
||||
public byte Execution_type { get; set; }
|
||||
public string Start_time { get { return Convert.ToDateTime(start_time).ToString("yyyy-MM-dd HH:mm:ss"); } set { start_time = value; } }
|
||||
public string End_time { get { return Convert.ToDateTime(end_time).ToString("yyyy-MM-dd HH:mm:ss"); } set { end_time = value; } }
|
||||
public string Last_create_time { get { return Convert.ToDateTime(last_create_time).ToString("yyyy-MM-dd HH:mm:ss"); } set { last_create_time = value; } }
|
||||
public int Repeat_times { get; set; }
|
||||
public byte status { get; set; }
|
||||
}
|
||||
|
||||
public class PlanTable: BackgroundServicePlan
|
||||
{
|
||||
public string building { get; set; }
|
||||
public string execution { get; set; }
|
||||
public string time { get; set; }
|
||||
}
|
||||
|
||||
}
|
40
Backend/Models/BackgroundServiceTask.cs
Normal file
40
Backend/Models/BackgroundServiceTask.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Backend.Models
|
||||
{
|
||||
public enum BackgroundServiceTaskType : byte
|
||||
{
|
||||
raw_data_archive = 0, //資料歸檔
|
||||
data_delivery = 1, //資料派送
|
||||
}
|
||||
|
||||
public class BackgroundServiceTask
|
||||
{
|
||||
private string complete_at;
|
||||
private string created_at;
|
||||
private string updated_at;
|
||||
public int Id { get; set; }
|
||||
public byte Task_type { get; set; }
|
||||
public string Target_ip { get; set; }
|
||||
public string Target_table { get; set; }
|
||||
public string Mode { get; set; }
|
||||
public string Target_data { get; set; }
|
||||
public string Target_files { get; set; }
|
||||
public int Repeat_times { get; set; }
|
||||
public byte Is_complete { get; set; }
|
||||
public string Complete_at { get { return Convert.ToDateTime(complete_at).ToString("yyyy-MM-dd HH:mm:ss"); } set { complete_at = value; } }
|
||||
public string Created_at { get { return Convert.ToDateTime(created_at).ToString("yyyy-MM-dd HH:mm:ss"); } set { created_at = value; } }
|
||||
public string Updated_at { get { return Convert.ToDateTime(updated_at).ToString("yyyy-MM-dd HH:mm:ss"); } set { updated_at = value; } }
|
||||
}
|
||||
|
||||
public class FileInfo
|
||||
{
|
||||
public string Folder { get; set; }
|
||||
public string OriginalFileName { get; set; }
|
||||
public string FileName { get; set; }
|
||||
public string File { get; set; }
|
||||
}
|
||||
}
|
73
Backend/Models/BuildMenu.cs
Normal file
73
Backend/Models/BuildMenu.cs
Normal file
@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Backend.Models
|
||||
{
|
||||
public class BuildMenu : Actor
|
||||
{
|
||||
public string building_guid { get; set; }
|
||||
public string main_system_guid { get; set; }
|
||||
public string sub_system_guid { get; set; }
|
||||
public byte drawing { get; set; }
|
||||
public byte icon_click { get; set; }
|
||||
public string icon_click_url { get; set; }
|
||||
public int icon_click_url_width { get; set; }
|
||||
public int icon_click_url_height { get; set; }
|
||||
public string system_url { get; set; }
|
||||
public string riser_diagram_url { get; set; }
|
||||
public byte planimetric_click { get; set; }
|
||||
public string planimetric_floor_guid { get; set; }
|
||||
}
|
||||
public class BuildMenuAddSub: BuildMenu
|
||||
{
|
||||
public string sub_system_guid_name { get; set; }
|
||||
}
|
||||
public class SubListIn
|
||||
{
|
||||
public string main { get; set; }
|
||||
public string build { get; set; }
|
||||
}
|
||||
public class BuildMenuTablePost
|
||||
{
|
||||
public string build { get; set; }
|
||||
public List<string> MainList { get; set; }
|
||||
}
|
||||
public class BuildMenuTable: BuildMenu
|
||||
{
|
||||
public string main_system_guid_name { get; set; }
|
||||
public string sub_system_guid_name { get; set; }
|
||||
public string drawing_name { get; set; }
|
||||
public string icon_click_name { get; set; }
|
||||
public string planimetric_click_name { get; set; }
|
||||
public string floor_guid_name { get; set; }
|
||||
}
|
||||
public class MenuIn : SubListIn
|
||||
{
|
||||
public string sub { get; set; }
|
||||
}
|
||||
public class BuildMenuFloor : Actor
|
||||
{
|
||||
public string sub_system_floor_guid { get; set; }
|
||||
public byte deleted { get; set; }
|
||||
public byte status { get; set; }
|
||||
public string building_guid { get; set; }
|
||||
public string main_system_guid { get; set; }
|
||||
public string sub_system_guid { get; set; }
|
||||
public string floor_guid { get; set; }
|
||||
}
|
||||
|
||||
public class BuildMenuFloorTable : BuildMenuFloor
|
||||
{
|
||||
public string main_system_guid_name { get; set; }
|
||||
public string sub_system_guid_name { get; set; }
|
||||
public string floor_guid_name { get; set; }
|
||||
|
||||
}
|
||||
public class MenuInfloor: MenuIn
|
||||
{
|
||||
public List<string> floorlist { get; set; }
|
||||
}
|
||||
|
||||
}
|
57
Backend/Models/BuildModel.cs
Normal file
57
Backend/Models/BuildModel.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Backend.Models
|
||||
{
|
||||
public class BuildInfo : Actor
|
||||
{
|
||||
public int Priority { get; set; }
|
||||
public string Building_guid { get; set; } //區域GUID
|
||||
public string Full_name { get; set; } //區域名稱
|
||||
public string Ip_address { get; set; } //監控主機 IP
|
||||
public string Ip_port { get; set; } //監控主機 IP port
|
||||
public string Ip_address_port { get { return Ip_address + ":" + Ip_port; } }
|
||||
public byte FloorNum { get; set; } //樓層數量
|
||||
//public string Created_at { get; set; } //建立時間
|
||||
}
|
||||
|
||||
public class BuildFloor : Actor
|
||||
{
|
||||
public string Floor_guid { get; set; } //樓層GUID
|
||||
public string Building_guid { get; set; } //區域GUID
|
||||
public string Full_name { get; set; } //建築名稱
|
||||
public string InitMapName { get; set; } //使用者命名平面圖檔檔名
|
||||
public string MapUrl { get; set; } //使用者命名平面圖檔檔名
|
||||
public string Floor_map_name { get; set; } //平面圖檔名
|
||||
public IFormFile MapFile { get; set; } //平面圖檔
|
||||
public int Priority { get; set; }
|
||||
}
|
||||
|
||||
public class SelectedBuildFloor
|
||||
{
|
||||
public string SelectedGuid { get; set; } //區域GUID
|
||||
}
|
||||
|
||||
public class PostBuildInfoPriority
|
||||
{
|
||||
public List<BuildInfoPriority> BuildInfoPriorities { get; set; }
|
||||
}
|
||||
public class BuildInfoPriority
|
||||
{
|
||||
public string Building_guid { get; set; } //區域GUID
|
||||
public int Priority { get; set; }
|
||||
}
|
||||
|
||||
public class PostFloorPriority
|
||||
{
|
||||
public List<FloorPriority> FloorPriorities { get; set; }
|
||||
}
|
||||
public class FloorPriority
|
||||
{
|
||||
public string Floor_guid { get; set; } //樓層GUID
|
||||
public int Priority { get; set; }
|
||||
}
|
||||
}
|
70
Backend/Models/BuildingCollapse.cs
Normal file
70
Backend/Models/BuildingCollapse.cs
Normal file
@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Backend.Models
|
||||
{
|
||||
public class BuildingMenuRawData
|
||||
{
|
||||
public string Building_guid { get; set; }
|
||||
public string bFull_name { get; set; }
|
||||
public int bPriority { get; set; }
|
||||
public string Main_system_guid { get; set; }
|
||||
public string mFull_name { get; set; }
|
||||
public int mPriority { get; set; }
|
||||
public string Sub_system_guid { get; set; }
|
||||
public string sFull_name { get; set; }
|
||||
public int sPriority { get; set; }
|
||||
}
|
||||
|
||||
public class BuildingCollapse : Actor
|
||||
{
|
||||
public string Building_guid { get; set; }
|
||||
public string Full_name { get; set; }
|
||||
public string Ip_address { get; set; }
|
||||
public int Priority { get; set; }
|
||||
public List<Main_system> Main_systems { get; set; }
|
||||
}
|
||||
public class Main_system
|
||||
{
|
||||
public string Main_system_guid { get; set; }
|
||||
public string Full_name { get; set; }
|
||||
public int Priority { get; set; }
|
||||
public string Code { get; set; }
|
||||
public List<Sub_system> Sub_systems { get; set; }
|
||||
}
|
||||
public class Sub_system
|
||||
{
|
||||
public string Sub_system_guid { get; set; }
|
||||
public string Full_name { get; set; }
|
||||
public int Priority { get; set; }
|
||||
public byte Drawing { get; set; }
|
||||
public byte Icon_click { get; set; }
|
||||
public string Icon_click_url { get; set; }
|
||||
public string System_url { get; set; }
|
||||
public List<Floor> Floors { get; set; }
|
||||
}
|
||||
public class Floor
|
||||
{
|
||||
public string Floor_guid { get; set; }
|
||||
public string Full_name { get; set; }
|
||||
public string InitMapName { get; set; }
|
||||
public string Floor_map_name { get; set; } //平面圖檔名
|
||||
public int Priority { get; set; }
|
||||
}
|
||||
|
||||
public class SubSystemFloorRawData
|
||||
{
|
||||
public string Sub_system_floor_guid { get; set; }
|
||||
public string Building_guid { get; set; }
|
||||
public string Main_system_guid { get; set; }
|
||||
public string Sub_system_guid { get; set; }
|
||||
public string Floor_guid { get; set; }
|
||||
public string fFull_name { get; set; }
|
||||
public string InitMapName { get; set; }
|
||||
public string Floor_map_name { get; set; }
|
||||
public string fPriority { get; set; }
|
||||
public int Priority { get; set; }
|
||||
}
|
||||
}
|
266
Backend/Models/Device.cs
Normal file
266
Backend/Models/Device.cs
Normal file
@ -0,0 +1,266 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Backend.Models
|
||||
{
|
||||
public class PostDeviceFilter
|
||||
{
|
||||
public string Building_guid { get; set; }
|
||||
public string Main_system_guid { get; set; }
|
||||
public string Sub_system_guid { get; set; }
|
||||
public string Floor_guid { get; set; }
|
||||
}
|
||||
|
||||
public class PostDeviceInfoAdd
|
||||
{
|
||||
public string Building_guid { get; set; }
|
||||
public string Main_system_guid { get; set; }
|
||||
public string Sub_system_guid { get; set; }
|
||||
public string Floor_guid { get; set; }
|
||||
public List<SelcectedDeviceAdd> SelectedDevices { get; set; }
|
||||
public IFormFile SelectedDevicesFile { get; set; }
|
||||
}
|
||||
|
||||
public class SelcectedDeviceAdd
|
||||
{
|
||||
public string Device_number { get; set; }
|
||||
public string Device_system_category_layer3 { get; set; }
|
||||
public string Device_disasters { get; set; }
|
||||
}
|
||||
|
||||
public class PostDeviceInfoEdit
|
||||
{
|
||||
public string Device_guid { get; set; }
|
||||
public string Full_name { get; set; }
|
||||
public string Device_coordinate_x { get; set; }
|
||||
public string Device_coordinate_y { get; set; }
|
||||
public List<string> Device_disasters { get; set; }
|
||||
public string Device_ip { get; set; }
|
||||
public string Device_port { get; set; }
|
||||
}
|
||||
|
||||
public class PostDeviceCoordinate
|
||||
{
|
||||
public string Device_guid { get; set; }
|
||||
public string Device_node_guid { get; set; }
|
||||
public string Coordinate { get; set; }
|
||||
}
|
||||
|
||||
public class Device : Actor
|
||||
{
|
||||
public string Device_guid { get; set; }
|
||||
public byte Deleted { get; set; }
|
||||
public byte Status { get; set; }
|
||||
public string Building_guid { get; set; }
|
||||
public string Building_full_name { get; set; }
|
||||
public string Main_system_guid { get; set; }
|
||||
public string Main_system_full_name { get; set; }
|
||||
public string Sub_system_guid { get; set; }
|
||||
public string Sub_system_full_name { get; set; }
|
||||
public string Floor_guid { get; set; }
|
||||
public string Floor_full_name { get; set; }
|
||||
public string Device_coordinate { get; set; }
|
||||
public string Device_full_name { get; set; }
|
||||
public string Device_number { get; set; } //設備編號
|
||||
public string Device_model { get; set; } //設備型號
|
||||
public string Device_disaster_type_text { get; set; }
|
||||
public string Device_system_category_layer3 { get; set; }
|
||||
public string Device_image { get; set; }
|
||||
public string Device_image_url { get; set; }
|
||||
public string Device_close_color { get; set; }
|
||||
public string Device_normal_color { get; set; }
|
||||
public string Device_error_color { get; set; }
|
||||
public string Device_flashing { get; set; }
|
||||
public string Device_ip { get; set; }
|
||||
public string Device_port { get; set; }
|
||||
public List<DeviceDisaster> Device_disasters { get; set; } //防災類型
|
||||
public List<DeviceNode> Device_nodes { get; set; } //設備子節點
|
||||
}
|
||||
|
||||
public class DeviceDisaster
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Device_system_type { get; set; }
|
||||
public string Device_system_value { get; set; }
|
||||
}
|
||||
|
||||
public class PostDeviceNode
|
||||
{
|
||||
public string Device_node_guid { get; set; }
|
||||
public string Device_guid { get; set; }
|
||||
public string Full_name { get; set; }
|
||||
public string Device_node_coordinate_x { get; set; }
|
||||
public string Device_node_coordinate_y { get; set; }
|
||||
}
|
||||
public class DeviceNode : Actor
|
||||
{
|
||||
public string Device_node_guid { get; set; }
|
||||
public string Device_guid { get; set; }
|
||||
public string Device_node_full_name { get; set; }
|
||||
public string Device_node_coordinate { get; set; }
|
||||
public int Priority { get; set; }
|
||||
}
|
||||
|
||||
public class PostDeviceKind
|
||||
{
|
||||
public string Device_kind_guid { get; set; }
|
||||
public string Device_building_tag { get; set; }
|
||||
public string Device_system_tag { get; set; }
|
||||
public string Device_floor_tag { get; set; }
|
||||
public string Device_name_tag { get; set; }
|
||||
public string Device_image { get; set; }
|
||||
public string InitDeviceName { get; set; }
|
||||
public IFormFile Device_image_file { get; set; } //設備種類圖檔
|
||||
public string Device_normal_text { get; set; }
|
||||
public string Device_normal_point_guid { get; set; }
|
||||
public string Device_normal_point_col { get; set; }
|
||||
public string Device_normal_point_value { get; set; }
|
||||
public string Device_normal_color { get; set; }
|
||||
public byte Device_normal_flashing { get; set; }
|
||||
public string Device_close_text { get; set; }
|
||||
public string Device_close_point_guid { get; set; }
|
||||
public string Device_close_point_col { get; set; }
|
||||
public string Device_close_point_value { get; set; }
|
||||
public string Device_close_color { get; set; }
|
||||
public byte Device_close_flashing { get; set; }
|
||||
public string Device_error_text { get; set; }
|
||||
public string Device_error_point_guid { get; set; }
|
||||
public string Device_error_point_col { get; set; }
|
||||
public string Device_error_point_value { get; set; }
|
||||
public string Device_error_color { get; set; }
|
||||
public byte Device_error_flashing { get; set; }
|
||||
public byte Device_error_independent { get; set; }
|
||||
}
|
||||
|
||||
public class DeviceKind
|
||||
{
|
||||
public string Device_kind_guid { get; set; }
|
||||
public string Device_building_tag { get; set; }
|
||||
public string Device_system_tag { get; set; }
|
||||
public string Device_floor_tag { get; set; }
|
||||
public string Device_name_tag { get; set; }
|
||||
public string Device_image { get; set; }
|
||||
public string Device_normal_text { get; set; }
|
||||
public string Device_normal_point_guid { get; set; }
|
||||
public string Device_normal_point_name { get; set; }
|
||||
public string Device_normal_point_col { get; set; }
|
||||
public string Device_normal_point_value { get; set; }
|
||||
public string Device_normal_color { get; set; }
|
||||
public byte Device_normal_flashing { get; set; }
|
||||
public string Device_close_text { get; set; }
|
||||
public string Device_close_point_guid { get; set; }
|
||||
public string Device_close_point_name { get; set; }
|
||||
public string Device_close_point_col { get; set; }
|
||||
public string Device_close_point_value { get; set; }
|
||||
public string Device_close_color { get; set; }
|
||||
public byte Device_close_flashing { get; set; }
|
||||
public string Device_error_text { get; set; }
|
||||
public string Device_error_point_guid { get; set; }
|
||||
public string Device_error_point_name { get; set; }
|
||||
public string Device_error_point_col { get; set; }
|
||||
public string Device_error_point_value { get; set; }
|
||||
public string Device_error_color { get; set; }
|
||||
public byte Device_error_flashing { get; set; }
|
||||
public byte Device_error_independent { get; set; }
|
||||
}
|
||||
|
||||
public class PointName
|
||||
{
|
||||
public string Device_normal_point_name { get; set; }
|
||||
public string Device_close_point_name { get; set; }
|
||||
public string Device_error_point_name { get; set; }
|
||||
}
|
||||
|
||||
public class DeviceImportCheckTempRawData
|
||||
{
|
||||
public string Device_building_tag { get; set; }
|
||||
public string Device_system_tag { get; set; }
|
||||
public string Device_floor_tag { get; set; }
|
||||
public string Device_name_tag { get; set; }
|
||||
public string Device_serial_tag { get; set; }
|
||||
public string Device_number { get; set; }
|
||||
public string Device_system_category_layer3 { get; set; }
|
||||
}
|
||||
|
||||
public class DeviceImportCheckTempFilter
|
||||
{
|
||||
public string Device_building_tag { get; set; }
|
||||
public List<ImportTempDeviceSystemTag> Device_system_tags { get; set; }
|
||||
}
|
||||
public class ImportTempDeviceSystemTag
|
||||
{
|
||||
public string Device_system_tag { get; set; }
|
||||
public List<ImportTempDeviceFloorTag> Device_floor_tags { get; set; }
|
||||
}
|
||||
|
||||
public class ImportTempDeviceFloorTag
|
||||
{
|
||||
public string Device_floor_tag { get; set; }
|
||||
public List<string> Device_name_tags { get; set; }
|
||||
}
|
||||
|
||||
public class DeviceImportCheckTemp : Actor
|
||||
{
|
||||
public string Device_building_tag { get; set; }
|
||||
public string Device_system_tag { get; set; }
|
||||
public string Device_floor_tag { get; set; }
|
||||
public string Device_name_tag { get; set; }
|
||||
public string Device_serial_tag { get; set; }
|
||||
public string Device_number { get; set; }
|
||||
public string Device_disasters { get; set; }
|
||||
public string Device_disaster_type_text { get; set; }
|
||||
public string Device_system_category_layer3 { get; set; }
|
||||
}
|
||||
|
||||
public class DeviceMaster : Actor
|
||||
{
|
||||
public string Device_master_guid { get; set; }
|
||||
public string Device_building_tag { get; set; }
|
||||
public string Device_name_tag { get; set; }
|
||||
public string Device_master_number { get; set; }
|
||||
public string Device_master_full_name { get; set; }
|
||||
public string Device_master_icon { get; set; }
|
||||
}
|
||||
|
||||
public class PostDeviceMaster
|
||||
{
|
||||
public string Device_master_guid { get; set; }
|
||||
public string Device_building_tag { get; set; }
|
||||
public string Device_name_tag { get; set; }
|
||||
public string Device_master_number { get; set; }
|
||||
public string Device_master_full_name { get; set; }
|
||||
public IFormFile Device_master_icon_file { get; set; } //設備種類圖檔
|
||||
}
|
||||
|
||||
public class DeviceGroup
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string device_disaster { get; set; }
|
||||
public string device_building_guid { get; set; }
|
||||
public string device_floor_guid { get; set; }
|
||||
public string device_system_category_layer2 { get; set; }
|
||||
public string device_system_category_layer3 { get; set; }
|
||||
public int device_amount { get; set; }
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 由API方式修改設備名稱
|
||||
/// </summary>
|
||||
public class ChangeName
|
||||
{
|
||||
public string TagName { get; set; }
|
||||
public string ChangeN { get; set; }
|
||||
public byte ChooseTable { get; set; }
|
||||
}
|
||||
|
||||
public class DeviceNumberPoint
|
||||
{
|
||||
public string DeviceNumber { get; set; }
|
||||
public string Point { get; set; }
|
||||
public string FullDeviceNumberPoint { get; set; }
|
||||
}
|
||||
}
|
88
Backend/Models/DeviceImport.cs
Normal file
88
Backend/Models/DeviceImport.cs
Normal file
@ -0,0 +1,88 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Backend.Models
|
||||
{
|
||||
|
||||
public class DeviceImport
|
||||
{
|
||||
private string created_at;
|
||||
public int Id { get; set; }
|
||||
public string Device_number { get; set; }
|
||||
public string Device_result { get; set; }
|
||||
public string Created_at { get { return Convert.ToDateTime(created_at).ToString("yyyy-MM-dd HH:mm:ss"); } set { created_at = value; } } //創建時間
|
||||
}
|
||||
|
||||
public class DeviceCheckFilterRawData
|
||||
{
|
||||
public string Device_building_tag { get; set; }
|
||||
public string Device_system_tag { get; set; }
|
||||
public string Device_system_category_layer3 { get; set; }
|
||||
}
|
||||
|
||||
public class Device_import_ckeck_temp_replace
|
||||
{
|
||||
public string Device_building_tag { get; set; }
|
||||
public string Device_system_tag { get; set; }
|
||||
public string Device_floor_tag { get; set; }
|
||||
public string Device_name_tag { get; set; }
|
||||
public string Device_serial_tag { get; set; }
|
||||
public string Device_number { get; set; }
|
||||
public string Device_system_category_layer3 { get; set; }
|
||||
public string Device_disaster { get; set; }
|
||||
public string Device_guid { get; set; }
|
||||
}
|
||||
|
||||
public class Device_replace_dict
|
||||
{
|
||||
public Dictionary<string, object> Device_replace { get; set; }
|
||||
public List<Dictionary<string, object>> Device_disaster_dicts { get; set; }
|
||||
}
|
||||
|
||||
public class DeviceCheckFilter
|
||||
{
|
||||
public string Building_tag { get; set; }
|
||||
public int Building_amount { get; set; }
|
||||
public List<DeviceCheckSystemTag> System_tags { get; set; }
|
||||
}
|
||||
|
||||
public class DeviceCheckSystemTag
|
||||
{
|
||||
public string System_tag { get; set; }
|
||||
public List<string> System_categories { get; set; }
|
||||
}
|
||||
|
||||
public class PostDeviceCheckFilter
|
||||
{
|
||||
public string Building_tag { get; set; }
|
||||
public string System_tag { get; set; }
|
||||
public string System_category { get; set; }
|
||||
public string Abnormal { get; set; }
|
||||
}
|
||||
|
||||
public class DeviceCheck
|
||||
{
|
||||
public int DeviceCheckAmount { get; set; }
|
||||
public List<DeviceCheckTable> DeviceCheckTableList { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public class DeviceCheckTable
|
||||
{
|
||||
public string Check_temp_device_number { get; set; } //check temp 資料表的 device_number
|
||||
public string Check_temp_device_system_category_layer3 { get; set; } //check temp 資料表的 system_category_layer3 value
|
||||
public string Check_temp_device_system_category_layer3_key { get; set; } //check temp 資料表的 system_category_layer3 key
|
||||
public string Check_temp_disaster_key { get; set; } //check temp 資料表的 disaster
|
||||
public string Device_number { get; set; } //device 資料表的 device_number
|
||||
public string Device_system_category_layer3 { get; set; } //device 資料表的 system_category_layer3 value
|
||||
public string Device_system_category_layer3_key { get; set; } //device 資料表的 system_category_layer3 key
|
||||
public string Device_disaster_type_text { get; set; } //device_disaster 資料表的 disaster
|
||||
public string Device_coordinate { get; set; } //device 資料表的 device_coordinate
|
||||
public byte Compare_device_number { get; set; } //比對2資料表的device_number
|
||||
public byte Compare_system_category_layer3 { get; set; } //比對2資料表的system_category_layer3
|
||||
public byte Compare_device_disaster { get; set; } //device 資料表的 device_disaster
|
||||
}
|
||||
}
|
30
Backend/Models/EmergencyContact.cs
Normal file
30
Backend/Models/EmergencyContact.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Backend.Models
|
||||
{
|
||||
public class EmergencyContact
|
||||
{
|
||||
public string emergency_member_guid { get; set; }
|
||||
public int grouping { get; set; }
|
||||
public string full_name { get; set; }
|
||||
public int department { get; set; }
|
||||
public string phone { get; set; }
|
||||
public string lineid { get; set; }
|
||||
public string email { get; set; }
|
||||
}
|
||||
|
||||
public class EmergencyContactTable: EmergencyContact
|
||||
{
|
||||
public string groupingName { get; set; }
|
||||
public string departmentName { get; set; }
|
||||
}
|
||||
|
||||
public class export
|
||||
{
|
||||
public List<int> groupidlist { get; set; }
|
||||
public string disaster { get; set; }
|
||||
}
|
||||
}
|
43
Backend/Models/EmergencyGrouping.cs
Normal file
43
Backend/Models/EmergencyGrouping.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Backend.Models
|
||||
{
|
||||
public class EmergencyGrouping
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
public class SaveGrouping
|
||||
{
|
||||
public int id { get; set; }
|
||||
public int priority { get; set; }
|
||||
public string name { get; set; }
|
||||
public string disaster { get; set; }
|
||||
public byte verify { get; set; }
|
||||
}
|
||||
|
||||
public class KeyValueID: KeyValue
|
||||
{
|
||||
public int id { get; set; }
|
||||
}
|
||||
|
||||
public class Emergency_member
|
||||