修改裝置管理、新增裝置子項目新增查詢功能
裝置設定: 裝置類型選擇改為讀取sensorType資料表 電站交叉分析: 選擇比較欄位(以sensorTypeDetail做更新) PowerStationRepository.cs -> 刪除已不使用的資料表判斷 debug -> 電站交叉分析中 設備有兩個導致查詢不了,增加查詢判斷
This commit is contained in:
parent
c7c1c0611b
commit
162338d3e9
@ -3,6 +3,8 @@ using Microsoft.Extensions.Logging;
|
|||||||
using SolarPower.Models;
|
using SolarPower.Models;
|
||||||
using SolarPower.Models.PowerStation;
|
using SolarPower.Models.PowerStation;
|
||||||
using SolarPower.Models.Role;
|
using SolarPower.Models.Role;
|
||||||
|
using SolarPower.Models.SensorType;
|
||||||
|
using SolarPower.Models.SensorDetail;
|
||||||
using SolarPower.Repository.Interface;
|
using SolarPower.Repository.Interface;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -14,10 +16,14 @@ namespace SolarPower.Controllers
|
|||||||
public class AnalysisStationInfoController : MyBaseController<AnalysisStationInfoController>
|
public class AnalysisStationInfoController : MyBaseController<AnalysisStationInfoController>
|
||||||
{
|
{
|
||||||
private readonly IPowerStationRepository powerStationRepository;
|
private readonly IPowerStationRepository powerStationRepository;
|
||||||
|
private readonly ISensorTypeRepository sensorTypeRepository;
|
||||||
|
private readonly ISensorDetailRepository sensorDetailRepository;
|
||||||
|
|
||||||
public AnalysisStationInfoController(IPowerStationRepository powerStationRepository) : base()
|
public AnalysisStationInfoController(IPowerStationRepository powerStationRepository, ISensorTypeRepository sensorTypeRepository, ISensorDetailRepository sensorDetailRepository) : base()
|
||||||
{
|
{
|
||||||
this.powerStationRepository = powerStationRepository;
|
this.powerStationRepository = powerStationRepository;
|
||||||
|
this.sensorTypeRepository = sensorTypeRepository;
|
||||||
|
this.sensorDetailRepository = sensorDetailRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IActionResult Index()
|
public IActionResult Index()
|
||||||
@ -67,7 +73,9 @@ namespace SolarPower.Controllers
|
|||||||
PowerStationId = psName_Group.First().PowerStationId,
|
PowerStationId = psName_Group.First().PowerStationId,
|
||||||
DeviceName = "電站總覽",
|
DeviceName = "電站總覽",
|
||||||
DeviceType = "PWS",
|
DeviceType = "PWS",
|
||||||
DeviceId = psName_Group.First().PowerStationId.ToString()
|
DeviceId = psName_Group.First().PowerStationId.ToString(),
|
||||||
|
SensorTypeId = psName_Group.First().SensorTypeId,
|
||||||
|
SensorTypeDetailId = psName_Group.First().SensorTypeDetailId
|
||||||
};
|
};
|
||||||
|
|
||||||
var temp = new List<PowerStationDevice>();
|
var temp = new List<PowerStationDevice>();
|
||||||
@ -153,7 +161,7 @@ namespace SolarPower.Controllers
|
|||||||
{ "KWH", "發電量"},
|
{ "KWH", "發電量"},
|
||||||
{ "IrrDay", "累計日照度"},
|
{ "IrrDay", "累計日照度"},
|
||||||
{ "Irradiance", "日照度"},
|
{ "Irradiance", "日照度"},
|
||||||
{ "KWHKWP", "發電小時"},
|
{ "KWHKWP", "日均發電度數"},
|
||||||
{ "PR", "PR %"},
|
{ "PR", "PR %"},
|
||||||
{ "SolarHour", "日照小時"},
|
{ "SolarHour", "日照小時"},
|
||||||
{ "Temperature", "模組溫度"},
|
{ "Temperature", "模組溫度"},
|
||||||
@ -552,7 +560,7 @@ namespace SolarPower.Controllers
|
|||||||
var YaxesKey = "";
|
var YaxesKey = "";
|
||||||
switch (device.Type)
|
switch (device.Type)
|
||||||
{
|
{
|
||||||
case "TPY": //日照計
|
case "TPY": //累積日照計
|
||||||
suffix = analysisDevice.MultipleYaxes["IrrDay"];
|
suffix = analysisDevice.MultipleYaxes["IrrDay"];
|
||||||
YaxesKey = "IrrDay";
|
YaxesKey = "IrrDay";
|
||||||
break;
|
break;
|
||||||
@ -572,7 +580,7 @@ namespace SolarPower.Controllers
|
|||||||
suffix = analysisDevice.MultipleYaxes["Vane"];
|
suffix = analysisDevice.MultipleYaxes["Vane"];
|
||||||
YaxesKey = "Vane";
|
YaxesKey = "Vane";
|
||||||
break;
|
break;
|
||||||
case "FOM": //落塵計
|
case "DST": //落塵計 FOM
|
||||||
suffix = analysisDevice.MultipleYaxes["Dust"];
|
suffix = analysisDevice.MultipleYaxes["Dust"];
|
||||||
YaxesKey = "Dust";
|
YaxesKey = "Dust";
|
||||||
break;
|
break;
|
||||||
@ -618,5 +626,121 @@ namespace SolarPower.Controllers
|
|||||||
apiResult.Msg = errorCode.GetString(apiResult.Code);
|
apiResult.Msg = errorCode.GetString(apiResult.Code);
|
||||||
return apiResult;
|
return apiResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 取得 裝置項目
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<ApiResult<SensorDetail>> GetOneSensorDetail(int id)
|
||||||
|
{
|
||||||
|
ApiResult<SensorDetail> apiResult = new ApiResult<SensorDetail>();
|
||||||
|
|
||||||
|
SensorDetail sensorDetails = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
sensorDetails = await sensorDetailRepository.GetOneSensorDetailAsync(id);
|
||||||
|
|
||||||
|
if (sensorDetails == null)
|
||||||
|
{
|
||||||
|
apiResult.Code = "9988";
|
||||||
|
apiResult.Msg = errorCode.GetString(apiResult.Code);
|
||||||
|
return apiResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
apiResult.Code = "0000";
|
||||||
|
apiResult.Data = sensorDetails;
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
apiResult.Code = "9999";
|
||||||
|
apiResult.Msg = errorCode.GetString(apiResult.Code);
|
||||||
|
Logger.LogError("【" + controllerName + "/" + actionName + "】" + "Id=" + id);
|
||||||
|
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return apiResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
//[HttpPost]
|
||||||
|
//public async Task<ApiResult<Dictionary<string, string>>> GetSensorCollapse(string filter)
|
||||||
|
//{
|
||||||
|
// //ApiResult<Dictionary<string, Dictionary<string, List<PowerStationDevice>>>> apiResult = new ApiResult<Dictionary<string, Dictionary<string, List<PowerStationDevice>>>>();
|
||||||
|
// ApiResult<Dictionary<string, string>> apiResult = new ApiResult<Dictionary<string, string>>();
|
||||||
|
// try
|
||||||
|
// {
|
||||||
|
// var powerStations = new List<PowerStation>();
|
||||||
|
|
||||||
|
// powerStations = myPowerStationService.GetMyPowerStations(myUser);
|
||||||
|
|
||||||
|
// var siteDBNamePowerStationId = new Dictionary<string, List<int>>();
|
||||||
|
|
||||||
|
// var powerStation_siteDB_Group = powerStations.GroupBy(x => x.SiteDB).ToList();
|
||||||
|
// foreach (var siteDB_Group in powerStation_siteDB_Group)
|
||||||
|
// {
|
||||||
|
// var powerStationIds = siteDB_Group.Select(x => x.Id).ToList();
|
||||||
|
// siteDBNamePowerStationId.Add(siteDB_Group.Key, powerStationIds);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// var powerStationDevices = await powerStationRepository.GetPowerStationDevice(siteDBNamePowerStationId, filter);
|
||||||
|
|
||||||
|
// //powerStationDevices = powerStationDevices.Where(x => x.DeviceId != null).ToList();
|
||||||
|
|
||||||
|
// var powerStationDevice_cityName_Group = powerStationDevices.GroupBy(x => x.CityName).ToList();
|
||||||
|
|
||||||
|
// var deviceCollapse = new Dictionary<string, Dictionary<string, List<PowerStationDevice>>>();
|
||||||
|
// foreach (var cityName_Group in powerStationDevice_cityName_Group)
|
||||||
|
// {
|
||||||
|
// var device_psName_Group = cityName_Group.GroupBy(x => x.PowerStationName).ToList();
|
||||||
|
|
||||||
|
// var deviceDic = new Dictionary<string, List<PowerStationDevice>>();
|
||||||
|
|
||||||
|
// foreach (var psName_Group in device_psName_Group)
|
||||||
|
// {
|
||||||
|
// //電站總覽
|
||||||
|
// PowerStationDevice powerStation = new PowerStationDevice()
|
||||||
|
// {
|
||||||
|
// CityName = cityName_Group.Key,
|
||||||
|
// PowerStationName = psName_Group.Key,
|
||||||
|
// PowerStationId = psName_Group.First().PowerStationId,
|
||||||
|
// DeviceName = "電站總覽",
|
||||||
|
// DeviceType = "PWS",
|
||||||
|
// DeviceId = psName_Group.First().PowerStationId.ToString(),
|
||||||
|
// SensorTypeId = psName_Group.First().SensorTypeId,
|
||||||
|
// SensorTypeDetailId = psName_Group.First().SensorTypeDetailId
|
||||||
|
// };
|
||||||
|
|
||||||
|
// var temp = new List<PowerStationDevice>();
|
||||||
|
// temp.Add(powerStation);
|
||||||
|
// foreach (var device in psName_Group)
|
||||||
|
// {
|
||||||
|
// if (!string.IsNullOrEmpty(device.DeviceId))
|
||||||
|
// {
|
||||||
|
// temp.Add(device);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// deviceDic.Add(psName_Group.Key, temp);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// deviceCollapse.Add(cityName_Group.Key, deviceDic);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// apiResult.Code = "0000";
|
||||||
|
|
||||||
|
// apiResult.Data = deviceCollapse;
|
||||||
|
// }
|
||||||
|
// catch (Exception exception)
|
||||||
|
// {
|
||||||
|
// apiResult.Code = "9999";
|
||||||
|
// Logger.LogError("【" + controllerName + "/" + actionName + "】");
|
||||||
|
// Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// apiResult.Msg = errorCode.GetString(apiResult.Code);
|
||||||
|
// return apiResult;
|
||||||
|
//}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,26 +9,26 @@ using SolarPower.Services.Interface;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using SolarPower.Models;
|
using SolarPower.Models;
|
||||||
using SolarPower.Models.SensorType;
|
using SolarPower.Models.SensorType;
|
||||||
|
using SolarPower.Models.SensorDetail;
|
||||||
|
|
||||||
namespace SolarPower.Controllers
|
namespace SolarPower.Controllers
|
||||||
{
|
{
|
||||||
public class SensorTypeController : MyBaseController<SensorTypeController>
|
public class SensorTypeController : MyBaseController<SensorTypeController>
|
||||||
{
|
{
|
||||||
private readonly ISensorTypeRepository sensorRepository;
|
private readonly ISensorTypeRepository sensorTypeRepository;
|
||||||
private string boeFilePath = "/upload/power_station/boe_file/";
|
private readonly ISensorDetailRepository sensorDetailRepository;
|
||||||
private string stationImageFilePath = "/upload/power_station/";
|
private string sensorTypeSaveAsPath = "";
|
||||||
private string powerSationSaveAsPath = "";
|
|
||||||
|
|
||||||
public SensorTypeController(ISensorTypeRepository sensorRepository) : base()
|
public SensorTypeController(ISensorTypeRepository sensorTypeRepository, ISensorDetailRepository sensorDetailRepository) : base()
|
||||||
{
|
{
|
||||||
this.sensorRepository = sensorRepository;
|
this.sensorTypeRepository = sensorTypeRepository;
|
||||||
|
this.sensorDetailRepository = sensorDetailRepository;
|
||||||
|
|
||||||
powerSationSaveAsPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "power_station");
|
sensorTypeSaveAsPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "sensor_type");
|
||||||
}
|
}
|
||||||
|
|
||||||
public IActionResult Index()
|
public IActionResult Index()
|
||||||
{
|
{
|
||||||
sensorRepository.GetAllSensorAsync();
|
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,15 +39,16 @@ namespace SolarPower.Controllers
|
|||||||
/// <param name="post"></param>
|
/// <param name="post"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<ApiResult<string>> SaveSensorType(SensorTypeInfo post)
|
public async Task<ApiResult<string>> SaveSensorType(SensorType post)
|
||||||
{
|
{
|
||||||
ApiResult<string> apiResult = new ApiResult<string>();
|
ApiResult<string> apiResult = new ApiResult<string>();
|
||||||
|
|
||||||
SensorType sensor = null;
|
SensorType sensor = null;
|
||||||
|
string nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
sensor = await sensorRepository.GetOneAsync(post.Id);
|
sensor = await sensorTypeRepository.GetOneAsync(post.Id);
|
||||||
|
|
||||||
if (sensor == null)
|
if (sensor == null)
|
||||||
{
|
{
|
||||||
@ -62,23 +63,25 @@ namespace SolarPower.Controllers
|
|||||||
#region 新增設備
|
#region 新增設備
|
||||||
sensor = new SensorType()
|
sensor = new SensorType()
|
||||||
{
|
{
|
||||||
UId = post.UId,
|
Deleted = 0,
|
||||||
Enabled = post.Enabled,
|
Enabled = post.Enabled,
|
||||||
SensorName = post.SensorName,
|
SensorName = post.SensorName,
|
||||||
SensorNameEn = post.SensorNameEn,
|
SensorEName = post.SensorEName,
|
||||||
CreatedBy = myUser.Id,
|
CreatedBy = myUser.Id,
|
||||||
|
CreatedAt = nowTime,
|
||||||
};
|
};
|
||||||
|
|
||||||
List<string> properties = new List<string>()
|
List<string> properties = new List<string>()
|
||||||
{
|
{
|
||||||
"UId",
|
"Deleted",
|
||||||
"Enabled",
|
"Enabled",
|
||||||
"SensorName",
|
"SensorName",
|
||||||
"SensorNameEn",
|
"SensorEName",
|
||||||
"CreatedBy",
|
"CreatedBy",
|
||||||
|
"CreatedAt"
|
||||||
};
|
};
|
||||||
|
|
||||||
var id = await sensorRepository.AddOneAsync(sensor, properties);
|
var id = await sensorTypeRepository.AddOneAsync(sensor, properties);
|
||||||
|
|
||||||
|
|
||||||
//var website_url = await powerStationRepository.GetOneVariableByName("WebSiteUrl");
|
//var website_url = await powerStationRepository.GetOneVariableByName("WebSiteUrl");
|
||||||
@ -97,8 +100,9 @@ namespace SolarPower.Controllers
|
|||||||
Id = sensor.Id,
|
Id = sensor.Id,
|
||||||
Enabled = post.Enabled,
|
Enabled = post.Enabled,
|
||||||
SensorName = post.SensorName,
|
SensorName = post.SensorName,
|
||||||
SensorNameEn = post.SensorNameEn,
|
SensorEName = post.SensorEName,
|
||||||
UpdatedBy = myUser.Id
|
UpdatedBy = myUser.Id,
|
||||||
|
UpdatedAt = nowTime,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -107,11 +111,13 @@ namespace SolarPower.Controllers
|
|||||||
"Id",
|
"Id",
|
||||||
"Enabled",
|
"Enabled",
|
||||||
"SensorName",
|
"SensorName",
|
||||||
"SensorNameEn",
|
"SensorEName",
|
||||||
"UpdatedBy",
|
"UpdatedBy",
|
||||||
|
"UpdatedAt"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
await sensorRepository.UpdateSensorInfo(update, properties);
|
await sensorTypeRepository.UpdateSensorInfo(update, properties);
|
||||||
apiResult.Code = "0000";
|
apiResult.Code = "0000";
|
||||||
apiResult.Msg = "儲存成功";
|
apiResult.Msg = "儲存成功";
|
||||||
#endregion
|
#endregion
|
||||||
@ -128,5 +134,369 @@ namespace SolarPower.Controllers
|
|||||||
return apiResult;
|
return apiResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 控制器DataTable
|
||||||
|
/// </summary>
|
||||||
|
/// <param name=""></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<ActionResult> SensorTypeDeviceTable()
|
||||||
|
{
|
||||||
|
ApiResult<List<SensorType>> apiResult = new ApiResult<List<SensorType>>();
|
||||||
|
List<SensorType> sensorTypes = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
sensorTypes = await sensorTypeRepository.GetAllSensorAsync();
|
||||||
|
foreach (SensorType a in sensorTypes)
|
||||||
|
{
|
||||||
|
switch (a.Enabled)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
a.EnabledName = "未啟用";
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
a.EnabledName = "啟用";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
a.EnabledName = "無資料";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
apiResult.Code = "0000";
|
||||||
|
apiResult.Data = sensorTypes;
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
apiResult.Code = "9999";
|
||||||
|
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
apiResult.Msg = errorCode.GetString(apiResult.Code);
|
||||||
|
var result = Json(new
|
||||||
|
{
|
||||||
|
data = apiResult
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 軟刪除單一裝置類型
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<ApiResult<string>> DeleteOneSensorType(int id)
|
||||||
|
{
|
||||||
|
ApiResult<string> apiResult = new ApiResult<string>();
|
||||||
|
|
||||||
|
SensorType sensor = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
sensor = await sensorTypeRepository.GetOneSensorType(id);
|
||||||
|
|
||||||
|
if (sensor == null)
|
||||||
|
{
|
||||||
|
apiResult.Code = "9998";
|
||||||
|
apiResult.Msg = errorCode.GetString(apiResult.Code);
|
||||||
|
return apiResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
await sensorTypeRepository.DeleteOne(sensor.Id);
|
||||||
|
|
||||||
|
apiResult.Code = "0000";
|
||||||
|
apiResult.Msg = "刪除成功";
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
apiResult.Code = "9999";
|
||||||
|
apiResult.Msg = errorCode.GetString(apiResult.Code);
|
||||||
|
Logger.LogError("【" + controllerName + "/" + actionName + "】" + "Id=" + id);
|
||||||
|
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return apiResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 取得單一裝置類型
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<ApiResult<SensorType>> GetOneSensorType(int id)
|
||||||
|
{
|
||||||
|
ApiResult<SensorType> apiResult = new ApiResult<SensorType>();
|
||||||
|
|
||||||
|
SensorType simpleSensorType = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
simpleSensorType = await sensorTypeRepository.GetOneSensorType(id);
|
||||||
|
|
||||||
|
if (simpleSensorType == null)
|
||||||
|
{
|
||||||
|
apiResult.Code = "9998";
|
||||||
|
apiResult.Msg = errorCode.GetString(apiResult.Code);
|
||||||
|
return apiResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
apiResult.Code = "0000";
|
||||||
|
apiResult.Data = simpleSensorType;
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
apiResult.Code = "9999";
|
||||||
|
Logger.LogError("【" + controllerName + "/" + actionName + "】" + "Id=" + id);
|
||||||
|
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
apiResult.Msg = errorCode.GetString(apiResult.Code);
|
||||||
|
return apiResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 新增 / 修改 設備-細項資料
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="post"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<ApiResult<string>> SaveSensorDetail(SensorDetail post)
|
||||||
|
{
|
||||||
|
ApiResult<string> apiResult = new ApiResult<string>();
|
||||||
|
|
||||||
|
SensorDetail sensorDetail = null;
|
||||||
|
|
||||||
|
string nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
sensorDetail = await sensorDetailRepository.GetOneAsync(post.Id);
|
||||||
|
|
||||||
|
if (sensorDetail == null)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (post.Id != 0)
|
||||||
|
{
|
||||||
|
apiResult.Code = "9998";//待定
|
||||||
|
apiResult.Msg = errorCode.GetString(apiResult.Code);
|
||||||
|
return apiResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
#region 新增設備-細項
|
||||||
|
sensorDetail = new SensorDetail()
|
||||||
|
{
|
||||||
|
Deleted = 0,
|
||||||
|
SensorTypeId = post.SensorTypeId,
|
||||||
|
ItemName = post.ItemName,
|
||||||
|
ItemEName = post.ItemEName,
|
||||||
|
HourType = post.HourType,
|
||||||
|
DayType = post.DayType,
|
||||||
|
MonthType = post.MonthType,
|
||||||
|
WarningURL = post.WarningURL,
|
||||||
|
UpperValue = post.UpperValue,
|
||||||
|
LowerValue = post.LowerValue,
|
||||||
|
CreatedBy = myUser.Id,
|
||||||
|
CreatedAt = nowTime
|
||||||
|
};
|
||||||
|
|
||||||
|
List<string> properties = new List<string>()
|
||||||
|
{
|
||||||
|
"Deleted",
|
||||||
|
"SensorTypeId",
|
||||||
|
"ItemName",
|
||||||
|
"ItemEName",
|
||||||
|
"HourType",
|
||||||
|
"DayType",
|
||||||
|
"MonthType",
|
||||||
|
"WarningURL",
|
||||||
|
"UpperValue",
|
||||||
|
"LowerValue",
|
||||||
|
"CreatedBy",
|
||||||
|
"CreatedAt"
|
||||||
|
};
|
||||||
|
|
||||||
|
var id = await sensorDetailRepository.AddOneAsync(sensorDetail, properties);
|
||||||
|
|
||||||
|
apiResult.Code = "0000";
|
||||||
|
apiResult.Msg = "儲存成功";
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#region 修改設備-細項
|
||||||
|
SensorDetail update = new SensorDetail()
|
||||||
|
{
|
||||||
|
Id = sensorDetail.Id,
|
||||||
|
SensorTypeId = post.SensorTypeId,
|
||||||
|
ItemName = post.ItemName,
|
||||||
|
ItemEName = post.ItemEName,
|
||||||
|
HourType = post.HourType,
|
||||||
|
DayType = post.DayType,
|
||||||
|
MonthType = post.MonthType,
|
||||||
|
WarningURL = post.WarningURL,
|
||||||
|
UpperValue = post.UpperValue,
|
||||||
|
LowerValue = post.LowerValue,
|
||||||
|
UpdatedBy = myUser.Id,
|
||||||
|
UpdatedAt = nowTime
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
List<string> properties = new List<string>()
|
||||||
|
{
|
||||||
|
"Id",
|
||||||
|
"SensorTypeId",
|
||||||
|
"ItemName",
|
||||||
|
"ItemEName",
|
||||||
|
"HourType",
|
||||||
|
"DayType",
|
||||||
|
"MonthType",
|
||||||
|
"WarningURL",
|
||||||
|
"UpperValue",
|
||||||
|
"LowerValue",
|
||||||
|
"UpdatedBy",
|
||||||
|
"UpdatedAt"
|
||||||
|
};
|
||||||
|
|
||||||
|
await sensorDetailRepository.UpdateSensorDetailInfo(update, properties);
|
||||||
|
apiResult.Code = "0000";
|
||||||
|
apiResult.Msg = "儲存成功";
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
apiResult.Code = "9999";
|
||||||
|
apiResult.Msg = errorCode.GetString(apiResult.Code);
|
||||||
|
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<List<SensorDetail>>> GetSensorDetail(int id)
|
||||||
|
{
|
||||||
|
ApiResult<List<SensorDetail>> apiResult = new ApiResult<List<SensorDetail>>();
|
||||||
|
|
||||||
|
List<SensorDetail> sensorDetails = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
sensorDetails = await sensorDetailRepository.GetAllSensorDetailAsync(id);
|
||||||
|
foreach (SensorDetail a in sensorDetails)
|
||||||
|
{
|
||||||
|
switch (a.HourType)
|
||||||
|
{
|
||||||
|
case "Sum":
|
||||||
|
a.HourTypeName = "總數";
|
||||||
|
break;
|
||||||
|
case "Max":
|
||||||
|
a.HourTypeName = "最大值";
|
||||||
|
break;
|
||||||
|
case "Min":
|
||||||
|
a.HourTypeName = "最小值";
|
||||||
|
break;
|
||||||
|
case "Avg":
|
||||||
|
a.HourTypeName = "平均值";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
a.HourTypeName = "無資料";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
switch (a.DayType)
|
||||||
|
{
|
||||||
|
case "Sum":
|
||||||
|
a.DayTypeName = "總數";
|
||||||
|
break;
|
||||||
|
case "Max":
|
||||||
|
a.DayTypeName = "最大值";
|
||||||
|
break;
|
||||||
|
case "Min":
|
||||||
|
a.DayTypeName = "最小值";
|
||||||
|
break;
|
||||||
|
case "Avg":
|
||||||
|
a.DayTypeName = "平均值";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
a.DayTypeName = "無資料";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
switch (a.MonthType)
|
||||||
|
{
|
||||||
|
case "Sum":
|
||||||
|
a.MonthTypeName = "總數";
|
||||||
|
break;
|
||||||
|
case "Max":
|
||||||
|
a.MonthTypeName = "最大值";
|
||||||
|
break;
|
||||||
|
case "Min":
|
||||||
|
a.MonthTypeName = "最小值";
|
||||||
|
break;
|
||||||
|
case "Avg":
|
||||||
|
a.MonthTypeName = "平均值";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
a.MonthTypeName = "無資料";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sensorDetails == null)
|
||||||
|
{
|
||||||
|
apiResult.Code = "9988";
|
||||||
|
apiResult.Msg = errorCode.GetString(apiResult.Code);
|
||||||
|
return apiResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
apiResult.Code = "0000";
|
||||||
|
apiResult.Data = sensorDetails;
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
apiResult.Code = "9999";
|
||||||
|
apiResult.Msg = errorCode.GetString(apiResult.Code);
|
||||||
|
Logger.LogError("【" + controllerName + "/" + actionName + "】" + "Id=" + id);
|
||||||
|
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return apiResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<ApiResult<string>> DeleteOneSensorDetail(int id)
|
||||||
|
{
|
||||||
|
ApiResult<string> apiResult = new ApiResult<string>();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var userPowerStation = sensorDetailRepository.GetOneAsync(id);
|
||||||
|
|
||||||
|
if (userPowerStation == null)
|
||||||
|
{
|
||||||
|
apiResult.Code = "9988";
|
||||||
|
apiResult.Msg = errorCode.GetString(apiResult.Code);
|
||||||
|
return apiResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
await sensorDetailRepository.DeleteOne(id);
|
||||||
|
|
||||||
|
apiResult.Code = "0000";
|
||||||
|
apiResult.Msg = "刪除成功";
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
apiResult.Code = "9999";
|
||||||
|
apiResult.Msg = errorCode.GetString(apiResult.Code);
|
||||||
|
Logger.LogError("【" + controllerName + "/" + actionName + "】" + "Id=" + id);
|
||||||
|
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return apiResult;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,6 +17,8 @@ namespace SolarPower.Models
|
|||||||
public string DeviceName { get; set; }
|
public string DeviceName { get; set; }
|
||||||
public string DeviceType { get; set; }
|
public string DeviceType { get; set; }
|
||||||
public string DeviceId { get; set; }
|
public string DeviceId { get; set; }
|
||||||
|
public string SensorTypeId { get; set; }
|
||||||
|
public string SensorTypeDetailId { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PostAnalysisStation
|
public class PostAnalysisStation
|
||||||
|
|||||||
31
SolarPower/Models/SensorDetail.cs
Normal file
31
SolarPower/Models/SensorDetail.cs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SolarPower.Models.SensorDetail
|
||||||
|
{
|
||||||
|
public class SensorDetail : Created
|
||||||
|
{
|
||||||
|
public int Id { get; set; } //編號
|
||||||
|
public int SensorTypeId { get; set; } //裝置類別編號
|
||||||
|
public int Deleted { get; set; } //是否刪除
|
||||||
|
public string ItemName { get; set; } //項目名稱
|
||||||
|
public string ItemEName { get; set; } //英文簡稱
|
||||||
|
public string HourType { get; set; } //小時數值類別
|
||||||
|
public string DayType { get; set; } //日數值類別
|
||||||
|
public string MonthType { get; set; } //月數值類別
|
||||||
|
public string WarningURL { get; set; } //警告網址
|
||||||
|
public int UpperValue { get; set; } //上限
|
||||||
|
public int LowerValue { get; set; } //下限
|
||||||
|
public string HourTypeName { get; set; } //小時數值類別的名稱
|
||||||
|
public string DayTypeName { get; set; } //日數值類別的名稱
|
||||||
|
public string MonthTypeName { get; set; } //月數值類別的名稱
|
||||||
|
|
||||||
|
private string updatedAt;
|
||||||
|
public int UpdatedBy { get; set; } //修改者
|
||||||
|
public string UpdatedAt { get { return Convert.ToDateTime(updatedAt).ToString("yyyy-MM-dd HH:mm:ss"); } set { updatedAt = value; } } //修改時間
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -7,25 +7,25 @@ using System.Threading.Tasks;
|
|||||||
namespace SolarPower.Models.SensorType
|
namespace SolarPower.Models.SensorType
|
||||||
{
|
{
|
||||||
//Base Class。如由其餘需求,使用繼承
|
//Base Class。如由其餘需求,使用繼承
|
||||||
public class SensorType : SensorTypeInfo
|
public class SensorType : Created
|
||||||
{
|
{
|
||||||
//public int Id { get; set; } //編號
|
public int Id { get; set; } //編號
|
||||||
public byte Deleted { get; set; } //是否刪除
|
public int Deleted { get; set; } //是否刪除
|
||||||
//public int UId { get; set; } //設備編號
|
public int Enabled { get; set; } //啟用
|
||||||
//public int Enabled { get; set; } //啟用
|
public string SensorName { get; set; } //sensor名稱
|
||||||
//public string SensorName { get; set; } //sensor名稱
|
public string SensorEName { get; set; } //sensor英文名稱
|
||||||
//public string SensorNameEn { get; set; } //sensor英文名稱
|
public string EnabledName { get; set; }//啟用
|
||||||
|
private string updatedAt;
|
||||||
|
public int UpdatedBy { get; set; } //修改者
|
||||||
|
public string UpdatedAt { get { return Convert.ToDateTime(updatedAt).ToString("yyyy-MM-dd HH:mm:ss"); } set { updatedAt = value; } } //修改時間
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
public class SensorTypeWithDetail
|
||||||
/// 設備
|
|
||||||
/// </summary>
|
|
||||||
public class SensorTypeInfo : UserInfo
|
|
||||||
{
|
{
|
||||||
public int UId { get; set; }//設備編號
|
public string SensorName { get; set; } //sensor名稱
|
||||||
public string SensorName { get; set; }//傳感器名稱
|
public string SensorEName { get; set; } //sensor英文名稱
|
||||||
public string SensorNameEn { get; set; }//傳感器英文名稱
|
public string ItemName { get; set; } //子項目名稱
|
||||||
public int Enabled { get; set; }//啟用
|
public string ItemEName { get; set; } //子項目英文名稱
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,6 +13,7 @@ using System.Text.Json;
|
|||||||
using SolarPower.Models;
|
using SolarPower.Models;
|
||||||
using SolarPower.Models.Role;
|
using SolarPower.Models.Role;
|
||||||
using SolarPower.Models.Company;
|
using SolarPower.Models.Company;
|
||||||
|
using SolarPower.Models.SensorType;
|
||||||
using MySql.Data.MySqlClient;
|
using MySql.Data.MySqlClient;
|
||||||
|
|
||||||
namespace SolarPower.Repository.Implement
|
namespace SolarPower.Repository.Implement
|
||||||
@ -967,15 +968,25 @@ namespace SolarPower.Repository.Implement
|
|||||||
var trans = conn.BeginTransaction();
|
var trans = conn.BeginTransaction();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string sql = @$"SELECT * FROM variable WHERE name = @name";
|
var sql = @$"SELECT
|
||||||
var json = await conn.QueryFirstOrDefaultAsync<SolarPower.Models.PowerStation.Variable>(sql, new { name = "Type" });
|
st.*,
|
||||||
Root jsonfor = JsonSerializer.Deserialize<Root>(json.value);
|
std.SensorTypeId AS SensorTypeId, std.Deleted AS ItemDeleted, std.ItemName AS ItemName, std.ItemEName AS ItemEName
|
||||||
foreach (Models.PowerStation.Type a in jsonfor.Type)
|
FROM sensor_type st
|
||||||
|
LEFT JOIN sensor_type_detail std ON st.Id = std.SensorTypeId AND std.Deleted = 0
|
||||||
|
WHERE st.Deleted = 0 ";
|
||||||
|
|
||||||
|
var json3 = (await conn.QueryAsync<SensorTypeWithDetail>(sql)).ToList();
|
||||||
|
foreach (SensorTypeWithDetail a in json3)
|
||||||
{
|
{
|
||||||
|
string subName = "";
|
||||||
|
if (a.ItemName != null)
|
||||||
|
{
|
||||||
|
subName = " - " + a.ItemName;
|
||||||
|
}
|
||||||
UserSelectItemList KeyValue = new UserSelectItemList
|
UserSelectItemList KeyValue = new UserSelectItemList
|
||||||
{
|
{
|
||||||
Value = a.EName,
|
Value = a.SensorEName,
|
||||||
Text = a.Name
|
Text = a.SensorName + subName
|
||||||
};
|
};
|
||||||
result.Add(KeyValue);
|
result.Add(KeyValue);
|
||||||
}
|
}
|
||||||
@ -992,6 +1003,7 @@ namespace SolarPower.Repository.Implement
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 新增裝置資料
|
/// 新增裝置資料
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -4457,7 +4469,9 @@ namespace SolarPower.Repository.Implement
|
|||||||
ps.Name AS PowerStationName,
|
ps.Name AS PowerStationName,
|
||||||
d.Name AS DeviceName,
|
d.Name AS DeviceName,
|
||||||
d.`Type` AS DeviceType,
|
d.`Type` AS DeviceType,
|
||||||
d.UID AS DeviceId
|
d.UID AS DeviceId,
|
||||||
|
d.SensorTypeId AS SensorTypeId,
|
||||||
|
d.SensorTypeDetailId AS SensorTypeDetailId
|
||||||
FROM power_station ps
|
FROM power_station ps
|
||||||
LEFT JOIN `city` c ON ps.CityId = c.Id
|
LEFT JOIN `city` c ON ps.CityId = c.Id
|
||||||
LEFT JOIN {powerStationDic.Key}.device d ON ps.Id = d.PowerStationId AND d.Deleted = 0 AND d.Enabled = 1 AND d.Status = 1
|
LEFT JOIN {powerStationDic.Key}.device d ON ps.Id = d.PowerStationId AND d.Deleted = 0 AND d.Enabled = 1 AND d.Status = 1
|
||||||
@ -4750,7 +4764,7 @@ namespace SolarPower.Repository.Implement
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var sql = @$"SELECT * FROM {db_name}.device d
|
var sql = @$"SELECT * FROM {db_name}.device d
|
||||||
WHERE d.PowerStationId = @PowerStationId AND UID IN @UID";
|
WHERE d.PowerStationId = @PowerStationId AND UID IN @UID AND Deleted = 0 AND Enabled = 1";
|
||||||
|
|
||||||
|
|
||||||
result = (await conn.QueryAsync<Device>(sql, new { PowerStationId = powerStationId, UID = deviceIds })).ToList();
|
result = (await conn.QueryAsync<Device>(sql, new { PowerStationId = powerStationId, UID = deviceIds })).ToList();
|
||||||
@ -5855,7 +5869,6 @@ namespace SolarPower.Repository.Implement
|
|||||||
{
|
{
|
||||||
"inv",
|
"inv",
|
||||||
"station",
|
"station",
|
||||||
"sensor",
|
|
||||||
"sensoravg",
|
"sensoravg",
|
||||||
};
|
};
|
||||||
// tables.Add("meter");
|
// tables.Add("meter");
|
||||||
@ -6149,8 +6162,7 @@ namespace SolarPower.Repository.Implement
|
|||||||
var sql = $@"SELECT * FROM
|
var sql = $@"SELECT * FROM
|
||||||
(SELECT count(*) ctAvg, a.SITEID AS Avg FROM {dbname}.s{code}01_sensoravg a ORDER BY a.ID DESC LIMIT 1) a,
|
(SELECT count(*) ctAvg, a.SITEID AS Avg FROM {dbname}.s{code}01_sensoravg a ORDER BY a.ID DESC LIMIT 1) a,
|
||||||
(SELECT count(*) ctInv_site, a.SITEID AS Inv_site,a.INVERTERID as Inv_inveter FROM {dbname}.s{code}01_inv a ORDER BY a.ID DESC LIMIT 1) b,
|
(SELECT count(*) ctInv_site, a.SITEID AS Inv_site,a.INVERTERID as Inv_inveter FROM {dbname}.s{code}01_inv a ORDER BY a.ID DESC LIMIT 1) b,
|
||||||
(SELECT count(*) ctStation, a.SITEID AS Station FROM {dbname}.s{code}01_station a ORDER BY a.ID DESC LIMIT 1) c,
|
(SELECT count(*) ctStation, a.SITEID AS Station FROM {dbname}.s{code}01_station a ORDER BY a.ID DESC LIMIT 1) c
|
||||||
(SELECT count(*) ctSensor, a.SITEID AS Sensor FROM {dbname}.s{code}01_sensor a ORDER BY a.ID DESC LIMIT 1) d
|
|
||||||
";
|
";
|
||||||
resule = await conn.QueryFirstOrDefaultAsync<Check4table>(sql);
|
resule = await conn.QueryFirstOrDefaultAsync<Check4table>(sql);
|
||||||
|
|
||||||
|
|||||||
105
SolarPower/Repository/Implement/SensorDetailRepository.cs
Normal file
105
SolarPower/Repository/Implement/SensorDetailRepository.cs
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using SolarPower.Models;
|
||||||
|
using SolarPower.Models.SensorDetail;
|
||||||
|
using SolarPower.Repository.Interface;
|
||||||
|
using Dapper;
|
||||||
|
using SolarPower.Helper;
|
||||||
|
using System.Data;
|
||||||
|
|
||||||
|
namespace SolarPower.Repository.Implement
|
||||||
|
{
|
||||||
|
public class SensorDetailRepository : RepositoryBase<SensorDetail>, ISensorDetailRepository
|
||||||
|
{
|
||||||
|
public SensorDetailRepository(IDatabaseHelper databaseHelper) : base(databaseHelper)
|
||||||
|
{
|
||||||
|
tableName = "sensor_type_detail";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 修改設備-細項資料
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entity"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task UpdateSensorDetailInfo(SensorDetail entity, List<string> properties)
|
||||||
|
{
|
||||||
|
GetProperties = typeof(SensorDetail).GetProperties();
|
||||||
|
using (IDbConnection conn = _databaseHelper.GetConnection())
|
||||||
|
{
|
||||||
|
conn.Open();
|
||||||
|
using (var trans = conn.BeginTransaction())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var sql = GenerateUpdateQuery(properties);
|
||||||
|
|
||||||
|
await conn.ExecuteAsync(sql, entity, trans);
|
||||||
|
|
||||||
|
trans.Commit();
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
trans.Rollback();
|
||||||
|
throw exception;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
conn.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 取得設備-細項資料
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sensorTypeId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<List<SensorDetail>> GetAllSensorDetailAsync(int sensorTypeId)
|
||||||
|
{
|
||||||
|
List<SensorDetail> result;
|
||||||
|
using (IDbConnection conn = _databaseHelper.GetConnection())
|
||||||
|
{
|
||||||
|
try//tableName
|
||||||
|
{
|
||||||
|
var sql = $"SELECT * FROM {tableName} WHERE deleted = 0 AND sensorTypeId = @SensorTypeId";
|
||||||
|
|
||||||
|
result = (await conn.QueryAsync<SensorDetail>(sql, new { SensorTypeId = sensorTypeId })).ToList();
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
throw exception;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 取得設備-細項資料
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<SensorDetail> GetOneSensorDetailAsync(int id)
|
||||||
|
{
|
||||||
|
SensorDetail result;
|
||||||
|
using (IDbConnection conn = _databaseHelper.GetConnection())
|
||||||
|
{
|
||||||
|
try//tableName
|
||||||
|
{
|
||||||
|
var sql = $"SELECT * FROM {tableName} WHERE deleted = 0 AND id = @Id";
|
||||||
|
|
||||||
|
result = await conn.QueryFirstOrDefaultAsync<SensorDetail>(sql, new { Id = id });
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
throw exception;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -23,11 +23,11 @@ namespace SolarPower.Repository.Implement
|
|||||||
List<SensorType> result;
|
List<SensorType> result;
|
||||||
using (IDbConnection conn = this._databaseHelper.GetConnection())
|
using (IDbConnection conn = this._databaseHelper.GetConnection())
|
||||||
{
|
{
|
||||||
try
|
try//tableName
|
||||||
{
|
{
|
||||||
var sql = $"SELECT Id, Deleted, Enabled, UID, SensorName, SensorNameEn FROM solar_master.sensor_type WHERE deleted = 0";
|
var sql = $"SELECT * FROM {tableName} WHERE deleted = 0";
|
||||||
|
|
||||||
result = (await conn.QueryAsync<SensorType>(sql)).ToList();
|
result = (await conn.QueryAsync<SensorType>(sql)).ToList();
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
@ -48,23 +48,13 @@ namespace SolarPower.Repository.Implement
|
|||||||
using (IDbConnection conn = _databaseHelper.GetConnection())
|
using (IDbConnection conn = _databaseHelper.GetConnection())
|
||||||
{
|
{
|
||||||
conn.Open();
|
conn.Open();
|
||||||
//var trans = conn.BeginTransaction();
|
|
||||||
using (var trans = conn.BeginTransaction())
|
using (var trans = conn.BeginTransaction())
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//string sql = GenerateInsertQueryWithCustomDBNameAndTable(properties, db_name, "device");
|
|
||||||
//await conn.ExecuteAsync(sql, DeviceInfo);
|
|
||||||
//trans.Commit();
|
|
||||||
|
|
||||||
//var sql2 = GenerateUpdateQuery(properties);
|
|
||||||
var sql = GenerateInsertQueryWithCustomTable(properties, "sensor_type");
|
var sql = GenerateInsertQueryWithCustomTable(properties, "sensor_type");
|
||||||
await conn.ExecuteAsync(sql, sensorInfo, trans);
|
await conn.ExecuteAsync(sql, sensorInfo, trans);
|
||||||
trans.Commit();
|
trans.Commit();
|
||||||
|
|
||||||
//string sql = $"INSERT INTO company_auth_page (CompanyId, AuthCode, CreatedBy) VALUES (@CompanyId, @AuthCode, @CreatedBy)";
|
|
||||||
//await conn.ExecuteAsync(sql, trans);
|
|
||||||
//trans.Commit();
|
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
@ -81,20 +71,20 @@ namespace SolarPower.Repository.Implement
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 透過sensorNameEn,取得單一筆資料
|
/// 透過sensorEName,取得單一筆資料
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sensorNameEn"></param>
|
/// <param name="sensorEName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<SensorType> GetOneByEnglishNameAsync(string sensorNameEn)
|
public async Task<SensorType> GetOneByEnglishNameAsync(string sensorEName)
|
||||||
{
|
{
|
||||||
SensorType result;
|
SensorType result;
|
||||||
using (IDbConnection conn = _databaseHelper.GetConnection())
|
using (IDbConnection conn = _databaseHelper.GetConnection())
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var sql = $"SELECT * FROM solar_master.sensor_type WHERE deleted = 0 AND sensorNameEn = @SensorNameEn";
|
var sql = $"SELECT * FROM {tableName} WHERE deleted = 0 AND sensorEName = @SensorEName";
|
||||||
|
|
||||||
result = await conn.QueryFirstOrDefaultAsync<SensorType>(sql, new { SensorName_En = sensorNameEn });
|
result = await conn.QueryFirstOrDefaultAsync<SensorType>(sql, new { SensorEName = sensorEName });
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
@ -138,5 +128,34 @@ namespace SolarPower.Repository.Implement
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 取得設備類型 透過id
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<SensorType> GetOneSensorType(int id)
|
||||||
|
{
|
||||||
|
SensorType result;
|
||||||
|
using (IDbConnection conn = this._databaseHelper.GetConnection())
|
||||||
|
{
|
||||||
|
conn.Open();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var sql = @$"SELECT * FROM {tableName} WHERE Deleted = 0 AND Id = @Id";
|
||||||
|
|
||||||
|
result = await conn.QueryFirstOrDefaultAsync<SensorType>(sql, new { Id = id });
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
throw exception;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
conn.Close();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
36
SolarPower/Repository/Interface/ISensorDetailRepository.cs
Normal file
36
SolarPower/Repository/Interface/ISensorDetailRepository.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using SolarPower.Models;
|
||||||
|
using SolarPower.Models.SensorDetail;
|
||||||
|
using SolarPower.Repository.Interface;
|
||||||
|
|
||||||
|
namespace SolarPower.Repository.Interface
|
||||||
|
{
|
||||||
|
public interface ISensorDetailRepository : IRepositoryBase<SensorDetail>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 修改設備-細項資料
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entity"></param>
|
||||||
|
/// <param name="properties"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task UpdateSensorDetailInfo(SensorDetail entity, List<string> properties);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 取得設備-細項資料
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sensorTypeId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<List<SensorDetail>> GetAllSensorDetailAsync(int sensorTypeId);
|
||||||
|
/// <summary>
|
||||||
|
/// 取得設備-單一細項資料
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<SensorDetail> GetOneSensorDetailAsync(int id);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -21,11 +21,11 @@ namespace SolarPower.Repository.Interface
|
|||||||
Task AddSensor(SensorType SensorInfo, List<string> properties);
|
Task AddSensor(SensorType SensorInfo, List<string> properties);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 透過sensorNameEn,取得單一筆資料
|
/// 透過sensorEName,取得單一筆資料
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sensorNameEn"></param>
|
/// <param name="sensorEName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<SensorType> GetOneByEnglishNameAsync(string sensorNameEn);
|
Task<SensorType> GetOneByEnglishNameAsync(string sensorEName);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 修改設備資料
|
/// 修改設備資料
|
||||||
@ -35,6 +35,12 @@ namespace SolarPower.Repository.Interface
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task UpdateSensorInfo(SensorType entity, List<string> properties);
|
Task UpdateSensorInfo(SensorType entity, List<string> properties);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 取得單一設備類型 透過 id
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<SensorType> GetOneSensorType(int id);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -83,6 +83,7 @@ namespace SolarPower
|
|||||||
services.AddTransient<INoticeScheduleRepository, NoticeScheduleRepository>();
|
services.AddTransient<INoticeScheduleRepository, NoticeScheduleRepository>();
|
||||||
services.AddTransient<IElectricitySoldRecordRepository, ElectricitySoldRecordRepository>();
|
services.AddTransient<IElectricitySoldRecordRepository, ElectricitySoldRecordRepository>();
|
||||||
services.AddTransient<ISensorTypeRepository, SensorTypeRepository>();
|
services.AddTransient<ISensorTypeRepository, SensorTypeRepository>();
|
||||||
|
services.AddTransient<ISensorDetailRepository, SensorDetailRepository>();
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
double loginExpireMinute = this.Configuration.GetValue<double>("LoginExpireMinute");
|
double loginExpireMinute = this.Configuration.GetValue<double>("LoginExpireMinute");
|
||||||
|
|||||||
@ -142,16 +142,20 @@
|
|||||||
{ key: "F", title: "頻率(Hz)", default: false }
|
{ key: "F", title: "頻率(Hz)", default: false }
|
||||||
]
|
]
|
||||||
var PYR_compare_col = [{ key: "Irradiance", title: "日照度", default: true }];
|
var PYR_compare_col = [{ key: "Irradiance", title: "日照度", default: true }];
|
||||||
|
var TPY_compare_col = [{ key: "IrrDay", title: "累積日照度", default: true }];
|
||||||
var ETR_compare_col = [{ key: "EnvTemperature", title: "環境溫度計", default: true }];
|
var ETR_compare_col = [{ key: "EnvTemperature", title: "環境溫度計", default: true }];
|
||||||
var MTR_compare_col = [{ key: "Temperature", title: "模組溫度", default: true }];
|
var MTR_compare_col = [{ key: "Temperature", title: "模組溫度", default: true }];
|
||||||
var EMM_compare_col = [{ key: "Humidity", title: "濕度", default: true }];
|
var EMM_compare_col = [{ key: "Humidity", title: "濕度", default: true }];
|
||||||
var VAN_compare_col = [{ key: "Vane", title: "風速", default: true }];
|
var VAN_compare_col = [{ key: "Vane", title: "風速", default: true }];
|
||||||
var FOM_compare_col = [{ key: "Dust", title: "落塵%", default: true }];
|
var DST_compare_col = [{ key: "Dust", title: "落塵%", default: true }];
|
||||||
|
var WIN_compare_col = [{ key: "Win", title: "風向", default: true }];
|
||||||
var current_compare_col = [];
|
var current_compare_col = [];
|
||||||
var default_compare_col = [];
|
var default_compare_col = [];
|
||||||
var selected_YAxis = [];
|
var selected_YAxis = [];
|
||||||
var analysisStationInfo;
|
var analysisStationInfo;
|
||||||
var chart;
|
var chart;
|
||||||
|
//Dictionary<string, string > sensor_type_detail_dictionary { get; set; };
|
||||||
|
var sensor_type_detail_dictionary;
|
||||||
|
|
||||||
$(function () {
|
$(function () {
|
||||||
$('#collapse').trigger("click");
|
$('#collapse').trigger("click");
|
||||||
@ -334,11 +338,13 @@
|
|||||||
var temp_obj = {
|
var temp_obj = {
|
||||||
powerStationId: $(this).attr("data-power-station-id"),
|
powerStationId: $(this).attr("data-power-station-id"),
|
||||||
deviceType: type,
|
deviceType: type,
|
||||||
deviceId: this.value
|
deviceId: this.value,
|
||||||
|
sensorTypeId: $(this).attr("data-sensor-type-id"),
|
||||||
|
sensorTypeDetailId: $(this).attr("data-sensor-type-detail-id")
|
||||||
}
|
}
|
||||||
|
|
||||||
selected_device.push(temp_obj);
|
selected_device.push(temp_obj);
|
||||||
|
GetItemInfo(temp_obj.sensorTypeDetailId);
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'PWS':
|
case 'PWS':
|
||||||
PushSpecifyCurrentCompareCol(PWS_compare_col);
|
PushSpecifyCurrentCompareCol(PWS_compare_col);
|
||||||
@ -346,24 +352,30 @@
|
|||||||
case 'PWR': //電錶
|
case 'PWR': //電錶
|
||||||
PushSpecifyCurrentCompareCol(PWR_compare_col);
|
PushSpecifyCurrentCompareCol(PWR_compare_col);
|
||||||
break;
|
break;
|
||||||
case 'PYR': //日照計
|
// case 'PYR': //日照計
|
||||||
PushSpecifyCurrentCompareCol(PYR_compare_col);
|
// PushSpecifyCurrentCompareCol(PYR_compare_col);
|
||||||
break;
|
// break;
|
||||||
case 'ETR': //環境溫度計
|
// case 'TPY': //累積日照
|
||||||
PushSpecifyCurrentCompareCol(ETR_compare_col);
|
// PushSpecifyCurrentCompareCol(TPY_compare_col);
|
||||||
break;
|
// break;
|
||||||
case 'MTR': //模組溫度計
|
// case 'ETR': //環境溫度計
|
||||||
PushSpecifyCurrentCompareCol(MTR_compare_col);
|
// PushSpecifyCurrentCompareCol(ETR_compare_col);
|
||||||
break;
|
// break;
|
||||||
case 'VAN': //風速計
|
// case 'MTR': //模組溫度計
|
||||||
PushSpecifyCurrentCompareCol(VAN_compare_col);
|
// PushSpecifyCurrentCompareCol(MTR_compare_col);
|
||||||
break;
|
// break;
|
||||||
case 'FOM': //落塵計
|
// case 'VAN': //風速計
|
||||||
PushSpecifyCurrentCompareCol(FOM_compare_col);
|
// PushSpecifyCurrentCompareCol(VAN_compare_col);
|
||||||
break;
|
// break;
|
||||||
case 'EMM': //環境濕度計
|
// case 'DST': //落塵計 FOM
|
||||||
PushSpecifyCurrentCompareCol(EMM_compare_col);
|
// PushSpecifyCurrentCompareCol(DST_compare_col);
|
||||||
break;
|
// break;
|
||||||
|
// case 'EMM': //環境濕度計
|
||||||
|
// PushSpecifyCurrentCompareCol(EMM_compare_col);
|
||||||
|
// break;
|
||||||
|
// case 'WIN': //風向計
|
||||||
|
// PushSpecifyCurrentCompareCol(WIN_compare_col);
|
||||||
|
// break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -392,6 +404,9 @@
|
|||||||
case 'PYR': //日照計
|
case 'PYR': //日照計
|
||||||
RemoveSpecifyCurrentCompareCol(PYR_compare_col);
|
RemoveSpecifyCurrentCompareCol(PYR_compare_col);
|
||||||
break;
|
break;
|
||||||
|
case 'TPY': //累積日照
|
||||||
|
RemoveSpecifyCurrentCompareCol(TPY_compare_col);
|
||||||
|
break;
|
||||||
case 'ETR': //環境溫度計
|
case 'ETR': //環境溫度計
|
||||||
RemoveSpecifyCurrentCompareCol(ETR_compare_col);
|
RemoveSpecifyCurrentCompareCol(ETR_compare_col);
|
||||||
break;
|
break;
|
||||||
@ -401,19 +416,22 @@
|
|||||||
case 'VAN': //風速計
|
case 'VAN': //風速計
|
||||||
RemoveSpecifyCurrentCompareCol(VAN_compare_col);
|
RemoveSpecifyCurrentCompareCol(VAN_compare_col);
|
||||||
break;
|
break;
|
||||||
case 'FOM': //落塵計
|
case 'DST': //落塵計 FOM
|
||||||
RemoveSpecifyCurrentCompareCol(VAN_compare_col);
|
RemoveSpecifyCurrentCompareCol(DST_compare_col);
|
||||||
break;
|
break;
|
||||||
case 'EMM': //環境濕度計
|
case 'EMM': //環境濕度計
|
||||||
RemoveSpecifyCurrentCompareCol(EMM_compare_col);
|
RemoveSpecifyCurrentCompareCol(EMM_compare_col);
|
||||||
break;
|
break;
|
||||||
|
case 'WIN': //風向計
|
||||||
|
RemoveSpecifyCurrentCompareCol(WIN_compare_col);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
current_compare_col = current_compare_col.filter(x => x.count > 0);
|
current_compare_col = current_compare_col.filter(x => x.count > 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ChangeCompareSelectOption()
|
ChangeCompareSelectOption();
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#js_list_accordion').on("change", 'input[name="selectedDeviceLayer2[]"]', function (event) {
|
$('#js_list_accordion').on("change", 'input[name="selectedDeviceLayer2[]"]', function (event) {
|
||||||
@ -516,9 +534,18 @@
|
|||||||
device_icon = '<i class="fal fa-tint"></i>';
|
device_icon = '<i class="fal fa-tint"></i>';
|
||||||
break;
|
break;
|
||||||
}*@
|
}*@
|
||||||
|
|
||||||
|
switch (device.sensorTypeDetailId) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
str += '<li class="list-group-item pr-0 d-flex justify-content-start">' +
|
str += '<li class="list-group-item pr-0 d-flex justify-content-start">' +
|
||||||
'<div class="mr-3">' +
|
'<div class="mr-3">' +
|
||||||
'<input type="checkbox" class="" name="selectedDeviceId[]" data-power-station-id="' + device.powerStationId + '" data-type="' + device.deviceType + '" value="' + device.deviceId + '">' +
|
'<input type="checkbox" class="" name="selectedDeviceId[]" data-power-station-id="' + device.powerStationId + '" data-type="' + device.deviceType + '" value="' + device.deviceId + '" data-sensor-type-id="' + device.sensorTypeId + '" data-sensor-type-detail-id="' + device.sensorTypeDetailId + '">' +
|
||||||
'</div>' +
|
'</div>' +
|
||||||
'<a href="javascript:void(0)">' + device_icon + device.deviceName + '</a>' +
|
'<a href="javascript:void(0)">' + device_icon + device.deviceName + '</a>' +
|
||||||
'</li>';
|
'</li>';
|
||||||
@ -552,6 +579,35 @@
|
|||||||
}, 'json');
|
}, 'json');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//在剛開始就在 sensor_type_detail 資料表中 取得ItemName
|
||||||
|
//#region
|
||||||
|
function GetItemInfo(itemId) {
|
||||||
|
|
||||||
|
//sensor_type_detail_dictionary = {''}
|
||||||
|
//my_dict = { 'first_name': 'eddie', 'last_name': 'kao', 'age': 30 }
|
||||||
|
|
||||||
|
var url = "/AnalysisStationInfo/GetOneSensorDetail/";
|
||||||
|
|
||||||
|
var send_data = {
|
||||||
|
id: itemId
|
||||||
|
}
|
||||||
|
|
||||||
|
$.post(url, send_data, function (rel) {
|
||||||
|
if (rel.code == "9999") {
|
||||||
|
toast_error(rel.msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (rel.code == "9998") {
|
||||||
|
toast_error(rel.msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var nowCompare_col = [{ key: rel.data.itemEName, title: rel.data.itemName, default: true }];
|
||||||
|
PushSpecifyCurrentCompareCol(nowCompare_col);
|
||||||
|
ChangeCompareSelectOption();
|
||||||
|
}, 'json');
|
||||||
|
}
|
||||||
|
//#endregion
|
||||||
|
|
||||||
//#region 加入已勾選的設備所要顯示得比較欄位
|
//#region 加入已勾選的設備所要顯示得比較欄位
|
||||||
function PushSpecifyCurrentCompareCol(compare_col) {
|
function PushSpecifyCurrentCompareCol(compare_col) {
|
||||||
$.each(compare_col, function (index, item) {
|
$.each(compare_col, function (index, item) {
|
||||||
|
|||||||
@ -36,10 +36,10 @@
|
|||||||
<table id="SensorType_table" class="table table-bordered table-hover m-0 text-center">
|
<table id="SensorType_table" class="table table-bordered table-hover m-0 text-center">
|
||||||
<thead class="thead-themed">
|
<thead class="thead-themed">
|
||||||
<tr>
|
<tr>
|
||||||
<th>設備編號</th>
|
<th>裝置編號</th>
|
||||||
<th>啟用</th>
|
<th>啟用</th>
|
||||||
<th>Sensor名稱</th>
|
<th>裝置名稱</th>
|
||||||
<th>Sensor英文名稱</th>
|
<th>英文簡稱</th>
|
||||||
<th>建立時間</th>
|
<th>建立時間</th>
|
||||||
<th>功能</th>
|
<th>功能</th>
|
||||||
</tr>
|
</tr>
|
||||||
@ -71,20 +71,16 @@
|
|||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="form-group col-lg-6">
|
<div class="form-group col-lg-6">
|
||||||
<label class="form-label" for="Sensor_Device_modal"><span class="text-danger">*</span>設備編號</label>
|
<label class="form-label" for="SensorType_Name_modal"><span class="text-danger">*</span>設備名稱</label>
|
||||||
<input type="text" id="Sensor_Device_modal" name="Sensor_Device_modal" class="form-control">
|
<input type="text" id="SensorType_Name_modal" name="SensorType_Name_modal" class="form-control">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group col-lg-6">
|
<div class="form-group col-lg-6">
|
||||||
<label class="form-label" for="Sensor_Name_modal"><span class="text-danger">*</span>設備名稱</label>
|
<label class="form-label" for="SensorType_EName_modal"><span class="text-danger">*</span>設備英文名稱</label>
|
||||||
<input type="text" id="Sensor_Name_modal" name="Sensor_Name_modal" class="form-control">
|
<input type="text" id="SensorType_EName_modal" name="SensorType_EName_modal" class="form-control">
|
||||||
</div>
|
|
||||||
<div class="form-group col-lg-6">
|
|
||||||
<label class="form-label" for="Sensor_EName_modal"><span class="text-danger">*</span>設備英文名稱</label>
|
|
||||||
<input type="text" id="Sensor_EName_modal" name="Sensor_EName_modal" class="form-control">
|
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group col-lg-3">
|
<div class="form-group col-lg-3">
|
||||||
<label class="form-label" for="Sensor_Enabled_modal">啟用</label>
|
<label class="form-label" for="SensorType_Enabled_modal">啟用</label>
|
||||||
<select class="form-control" id="Sensor_Enabled_modal">
|
<select class="form-control" id="SensorType_Enabled_modal">
|
||||||
<option value="0" action>未啟用</option>
|
<option value="0" action>未啟用</option>
|
||||||
<option value="1">啟用</option>
|
<option value="1">啟用</option>
|
||||||
</select>
|
</select>
|
||||||
@ -100,150 +96,475 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="modal fade" id="SensorDetail-modal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static" data-keyboard="false">
|
||||||
|
<div class="modal-dialog modal-dialog-centered modal-lg" role="document">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h4 class="modal-title">
|
||||||
|
裝置細項 - 新增
|
||||||
|
</h4>
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||||
|
<span aria-hidden="true"><i class="fal fa-times"></i></span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<form class="SensorDetail-form" id="SensorDetail-form">
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="form-group col-lg-6">
|
||||||
|
<label class="form-label" for="SensorDetail_SensorType_modal"><span class="text-danger">*</span>裝置類型</label>
|
||||||
|
<input type="text" id="SensorDetail_SensorType_modal" name="SensorDetail_SensorType_modal" class="form-control" disabled>
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-lg-6">
|
||||||
|
<label class="form-label" for="SensorDetail_ItemName_modal"><span class="text-danger">*</span>項目名稱</label>
|
||||||
|
<input type="text" id="SensorDetail_ItemName_modal" name="SensorDetail_ItemName_modal" class="form-control">
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-lg-6">
|
||||||
|
<label class="form-label" for="SensorDetail_ItemEName_modal"><span class="text-danger">*</span>英文簡稱</label>
|
||||||
|
<input type="text" id="SensorDetail_ItemEName_modal" name="SensorDetail_ItemEName_modal" class="form-control">
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-lg-6">
|
||||||
|
<label class="form-label" for="SensorDetail_WarningURL_modal"><span class="text-danger">*</span>警告網址</label>
|
||||||
|
<input type="text" id="SensorDetail_WarningURL_modal" name="SensorDetail_WarningURL_modal" class="form-control">
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-lg-3">
|
||||||
|
<label class="form-label" for="SensorDetail_HourType_modal">每小時取值類別</label>
|
||||||
|
<select class="form-control" id="SensorDetail_HourType_modal">
|
||||||
|
<option value="Sum" action>總數</option>
|
||||||
|
<option value="Max">最大值</option>
|
||||||
|
<option value="Avg">平均值</option>
|
||||||
|
<option value="Min">最小值</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-lg-3">
|
||||||
|
<label class="form-label" for="SensorDetail_DayType_modal">每日取值類別</label>
|
||||||
|
<select class="form-control" id="SensorDetail_DayType_modal">
|
||||||
|
<option value="Sum" action>總數</option>
|
||||||
|
<option value="Max">最大值</option>
|
||||||
|
<option value="Avg">平均值</option>
|
||||||
|
<option value="Min">最小值</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-lg-3">
|
||||||
|
<label class="form-label" for="SensorDetail_MonthType_modal">每月取值類別</label>
|
||||||
|
<select class="form-control" id="SensorDetail_MonthType_modal">
|
||||||
|
<option value="Sum" action>總數</option>
|
||||||
|
<option value="Max">最大值</option>
|
||||||
|
<option value="Avg">平均值</option>
|
||||||
|
<option value="Min">最小值</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-lg-6">
|
||||||
|
<label class="form-label" for="SensorDetail_UpperValue_modal"><span class="text-danger">*</span>上限值</label>
|
||||||
|
<input type="text" id="SensorDetail_UpperValue_modal" name="SensorDetail_UpperValue_modal" class="form-control">
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-lg-6">
|
||||||
|
<label class="form-label" for="SensorDetail_LowerValue_modal"><span class="text-danger">*</span>下限值</label>
|
||||||
|
<input type="text" id="SensorDetail_LowerValue_modal" name="SensorDetail_LowerValue_modal" class="form-control">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
|
||||||
|
<button type="button" class="btn btn-primary" onclick="SaveSensorDetail()">確定</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Modal 細項項目資訊 -->
|
||||||
|
<div class="modal fade" id="sensor-detail-modal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static" data-keyboard="false">
|
||||||
|
<div class="modal-dialog modal-dialog-centered modal-xl" role="document">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h4 class="modal-title">
|
||||||
|
</h4>
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||||
|
<span aria-hidden="true"><i class="fal fa-times"></i></span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<table id="sensor-detail-table" class="table table-bordered text-center">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>項目名稱</th>
|
||||||
|
<th>英文簡稱</th>
|
||||||
|
<th>小時的數值類別</th>
|
||||||
|
<th>天的數值類別</th>
|
||||||
|
<th>月的數值類別</th>
|
||||||
|
<th>警告URL</th>
|
||||||
|
<th>上限</th>
|
||||||
|
<th>下限</th>
|
||||||
|
<th>功能</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
@*<div class="col-12"> <a href="javascript:;" class="btn btn-success waves-effect waves-themed mb-3 " id="add-user-power-station" onclick="AddUserPowerStation(this)"><span class="fal fa-plus mr-1"></span> 增加項目</a> </div>*@
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
@section Scripts {
|
@section Scripts {
|
||||||
<script>
|
<script>
|
||||||
//var userTable; var roleTable; var roleAuthTable; var roleAuthNotJoinTable;
|
var SensorTypeDeviceTable;
|
||||||
//var selected_id = 0, selected_role_id = 0, selected_company_id = 0;
|
var selected_id = 0;
|
||||||
//var selected_tab = "";
|
var selected_type_id = 0;
|
||||||
|
|
||||||
//#region 新增裝置資料
|
//#region 新增裝置資料
|
||||||
function AddSensor() {
|
function AddSensor() {
|
||||||
selected_id = 0;
|
selected_id = 0;
|
||||||
document.getElementById('Sensor_Enabled_modal').disabled = false;
|
document.getElementById('SensorType_Enabled_modal').disabled = false;
|
||||||
$("#SensorType-modal .modal-title").html("裝置資料 - 新增");
|
$("#SensorType-modal .modal-title").html("裝置資料 - 新增");
|
||||||
$("#SensorType-form").trigger("reset");
|
$("#SensorType-form").trigger("reset");
|
||||||
$("#SensorType-modal").modal();
|
$("#SensorType-modal").modal();
|
||||||
}
|
}
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
//#region 使用者列表 DataTable
|
$(function () {
|
||||||
//userTable = $("#SensorType_table").DataTable({
|
//#region 裝置類型列表 DataTable
|
||||||
// "paging": true,
|
SensorTypeDeviceTable = $("#SensorType_table").DataTable({
|
||||||
// "lengthChange": false,
|
"paging": true,
|
||||||
// "searching": false,
|
"lengthChange": false,
|
||||||
// "ordering": true,
|
"searching": false,
|
||||||
// "info": true,
|
"ordering": true,
|
||||||
// "autoWidth": false,
|
"info": true,
|
||||||
// "responsive": false,
|
"autoWidth": false,
|
||||||
// "deferLoading": 0,
|
"responsive": false,
|
||||||
// "order": [[4, "desc"]],
|
"columns": [{
|
||||||
// "columns": [{
|
"data": "id"
|
||||||
// "data": "uId"
|
}, {
|
||||||
// }, {
|
"data": "enabledName"
|
||||||
// "data": "enabled"
|
}, {
|
||||||
// }, {
|
"data": "sensorName"
|
||||||
// "data": "name"
|
}, {
|
||||||
// }, {
|
"data": "sensorEName"
|
||||||
// "data": "englishName"
|
}, {
|
||||||
// }, {
|
"data": "createdAt"
|
||||||
// "data": "createdAt"
|
}, {
|
||||||
// }, {
|
"data": null,
|
||||||
// "data": null,
|
"defaultContent": '<button class="btn btn-success detail-btn">新增細項</button><button class="btn btn-primary edit-btn">修改</button> <button class="btn btn-danger del-btn">刪除</button>'
|
||||||
// "defaultContent": '<button class="btn btn-primary edit-btn">修改</button> <button class="btn btn-danger del-btn">刪除</button>'
|
}],
|
||||||
// }
|
"columnDefs": [{
|
||||||
// ],
|
'targets': 2,
|
||||||
// "columnDefs": [{
|
'searchable': false,
|
||||||
// 'targets': 2,
|
'orderable': false,
|
||||||
// 'searchable': false,
|
'render': function (data, type, full, meta) {
|
||||||
// 'orderable': false,
|
return '<a href="javascript:void(0);" onclick="GetSensorDetail(' + full.id + ')">' + data + '</a>';
|
||||||
// 'render': function (data, type, full, meta) {
|
}
|
||||||
// return '<a href="javascript:void(0);" onclick="GetUserPowerStation(' + full.id + ')">' + data + '</a>';
|
}],
|
||||||
// }
|
"language": {
|
||||||
// }],
|
"emptyTable": "查無資料",
|
||||||
// "language": {
|
"processing": "處理中...",
|
||||||
// "emptyTable": "查無資料",
|
"loadingRecords": "載入中...",
|
||||||
// "processing": "處理中...",
|
"lengthMenu": "顯示 _MENU_ 項結果",
|
||||||
// "loadingRecords": "載入中...",
|
"zeroRecords": "沒有符合的結果",
|
||||||
// "lengthMenu": "顯示 _MENU_ 項結果",
|
"info": "顯示第 _START_ 至 _END_ 項結果,共 _TOTAL_ 項",
|
||||||
// "zeroRecords": "沒有符合的結果",
|
"infoEmpty": "顯示第 0 至 0 項結果,共 0 項",
|
||||||
// "info": "顯示第 _START_ 至 _END_ 項結果,共 _TOTAL_ 項",
|
"infoFiltered": "(從 _MAX_ 項結果中過濾)",
|
||||||
// "infoEmpty": "顯示第 0 至 0 項結果,共 0 項",
|
"infoPostFix": "",
|
||||||
// "infoFiltered": "(從 _MAX_ 項結果中過濾)",
|
"search": "搜尋:",
|
||||||
// "infoPostFix": "",
|
"paginate": {
|
||||||
// "search": "搜尋:",
|
"first": "第一頁",
|
||||||
// "paginate": {
|
"previous": "上一頁",
|
||||||
// "first": "第一頁",
|
"next": "下一頁",
|
||||||
// "previous": "上一頁",
|
"last": "最後一頁"
|
||||||
// "next": "下一頁",
|
}
|
||||||
// "last": "最後一頁"
|
},
|
||||||
// },
|
'createdRow': function (row, data, dataIndex) {
|
||||||
// "aria": {
|
$(row).attr('data-id', data.id);
|
||||||
// "sortAscending": ": 升冪排列",
|
},
|
||||||
// "sortDescending": ": 降冪排列"
|
"ajax": {
|
||||||
// }
|
"url": "/SensorType/SensorTypeDeviceTable",
|
||||||
// },
|
"type": "POST",
|
||||||
// 'createdRow': function (row, data, dataIndex) {
|
"data": function (d) {
|
||||||
// $(row).attr('data-id', data.id);
|
//d.stationId = stationId;
|
||||||
// },
|
},
|
||||||
// "ajax": {
|
"dataSrc": function (rel) {
|
||||||
// "url": "/User/UserList",
|
if (rel.data.code == "9999") {
|
||||||
// "type": "POST",
|
toast_error(rel.data.msg);
|
||||||
// "data": function (d) {
|
return;
|
||||||
// d.SelectedCompanyId = $('#select_user_company_userManager_tab').val();
|
}
|
||||||
// d.Name = $('#user_name').val();
|
|
||||||
// d.SelectedRoleId = $('#select_company_role_userManager_tab').val();
|
|
||||||
// },
|
|
||||||
// "dataSrc": function (rel) {
|
|
||||||
// if (rel.data.code == "9999") {
|
|
||||||
// toast_error(rel.data.msg);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// data = rel.data.data;
|
data = rel.data.data;
|
||||||
|
|
||||||
// if (data == null || data.length == 0) {
|
if (data == null || data.length == 0) {
|
||||||
// this.data = [];
|
this.data = [];
|
||||||
// }
|
}
|
||||||
|
|
||||||
// return data;
|
return data;
|
||||||
// }
|
}
|
||||||
// },
|
},
|
||||||
// "error": function (xhr, error, thrown) {
|
"error": function (xhr, error, thrown) {
|
||||||
// console.log(xhr);
|
console.log(xhr);
|
||||||
// }
|
}
|
||||||
//});
|
});
|
||||||
|
//#endregion
|
||||||
|
});
|
||||||
|
|
||||||
|
//#region 儲存裝置類型資料
|
||||||
|
function SaveSensorType() {
|
||||||
|
var url = "/SensorType/SaveSensorType";
|
||||||
|
if ($("#SensorType-form").valid()) {
|
||||||
|
var send_data = {
|
||||||
|
Id: selected_id,
|
||||||
|
Enabled: $("#SensorType_Enabled_modal").val(),
|
||||||
|
SensorName: $("#SensorType_Name_modal").val(),
|
||||||
|
SensorEName: $("#SensorType_EName_modal").val()
|
||||||
|
}
|
||||||
|
$.post(url, send_data, function (rel) {
|
||||||
|
if (rel.code != "0000") {
|
||||||
|
toast_error(rel.msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
toast_ok(rel.msg);
|
||||||
|
$('#SensorType-modal').modal('hide');
|
||||||
|
SensorTypeDeviceTable.ajax.reload();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}, 'json');
|
||||||
|
}
|
||||||
|
}
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
//#region 儲存裝置資料
|
//#region 刪除使用者
|
||||||
//function SaveSensorType() {
|
$('#SensorType_table').on("click", "button.del-btn", function () {
|
||||||
|
selected_id = $(this).parents('tr').attr('data-id');
|
||||||
|
Swal.fire(
|
||||||
|
{
|
||||||
|
title: "刪除",
|
||||||
|
text: "你確定是否刪除此筆資料?",
|
||||||
|
type: "warning",
|
||||||
|
icon: 'warning',
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonText: "是",
|
||||||
|
cancelButtonText: "否"
|
||||||
|
}).then(function (result) {
|
||||||
|
if (result.value) {
|
||||||
|
//取得單一系統管理員
|
||||||
|
var url = "/SensorType/DeleteOneSensorType/";
|
||||||
|
var send_data = {
|
||||||
|
Id: selected_id
|
||||||
|
}
|
||||||
|
$.post(url, send_data, function (rel) {
|
||||||
|
if (rel.code != "0000") {
|
||||||
|
toast_error(rel.msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// if ($("#SensorType-form").valid()) {
|
toast_ok(rel.msg);
|
||||||
// var url = "/SensorType/SaveSensorType";
|
|
||||||
// var a = padLeft($("#Device_ColName_modal").val(), 2);
|
|
||||||
// var send_data = {
|
|
||||||
// Id: selected_id,
|
|
||||||
// PowerStationId: stationId,
|
|
||||||
// Name: $("#Device_Name_modal").val(),
|
|
||||||
// ControllerId: $("#Device_Controller_modal").val(),
|
|
||||||
// Type: $("#Device_Type_modal").val(),
|
|
||||||
// TypeName: $("#Device_Type_modal :selected").text(),
|
|
||||||
// Brand: $("#Device_Brand_modal").val(),
|
|
||||||
// ProductModel: $("#Device_ProductModel_modal").val(),
|
|
||||||
// //DBName: $("#Device_DBName_modal").val(),
|
|
||||||
// TableName: $("#SensorType_TableName_modal").val(),
|
|
||||||
// ColName: "SENSORAVG" + a,
|
|
||||||
// InstallDate: $("#Device_InstallDate_modal").val(),
|
|
||||||
// Status: $("#Device_Status_modal").val(),
|
|
||||||
// Enabled: $("#Device_Enabled_modal").val(),
|
|
||||||
// WarrantyDate: $("#Device_WarrantyDate_modal").val()
|
|
||||||
// }
|
|
||||||
// $.post(url, send_data, function (rel) {
|
|
||||||
// if (rel.code != "0000") {
|
|
||||||
// toast_error(rel.msg);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
// toast_ok(rel.msg);
|
|
||||||
// $('#Device-modal').modal('hide');
|
|
||||||
// DeviceTable.ajax.reload();
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
// }, 'json');
|
SensorTypeDeviceTable.ajax.reload();
|
||||||
// }
|
}, 'json');
|
||||||
//}
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
|
//#region 編輯裝置
|
||||||
|
$('#SensorType_table').on("click", "button.edit-btn", function () {
|
||||||
|
|
||||||
|
$("#SensorType-modal .modal-title").html("裝置資料 - 修改");
|
||||||
|
|
||||||
|
selected_id = $(this).parents('tr').attr('data-id');
|
||||||
|
|
||||||
|
//取得單一裝置
|
||||||
|
var url = "/SensorType/GetOneSensorType/";
|
||||||
|
|
||||||
|
var send_data = {
|
||||||
|
id: selected_id
|
||||||
|
}
|
||||||
|
|
||||||
|
$.post(url, send_data, function (rel) {
|
||||||
|
if (rel.code == "9999") {
|
||||||
|
toast_error(rel.msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (rel.code == "9998") {
|
||||||
|
toast_error(rel.msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#SensorType_Name_modal").val(rel.data.sensorName);
|
||||||
|
$("#SensorType_EName_modal").val(rel.data.sensorEName);
|
||||||
|
$("#SensorType_Enabled_modal").val(rel.data.enabled);
|
||||||
|
|
||||||
|
$("#SensorType-modal").modal();
|
||||||
|
}, 'json');
|
||||||
|
|
||||||
|
});
|
||||||
|
//#endregion
|
||||||
|
|
||||||
|
//#region 新增裝置-細項
|
||||||
|
$('#SensorType_table').on("click", "button.detail-btn", function () {
|
||||||
|
$("#SensorDetail-modal .modal-title").html("裝置細項 - 新增");
|
||||||
|
$("#SensorDetail-form").trigger("reset");
|
||||||
|
document.getElementById('SensorDetail_SensorType_modal').disabled = true;
|
||||||
|
selected_id = 0;
|
||||||
|
selected_type_id = $(this).parents('tr').attr('data-id');
|
||||||
|
|
||||||
|
|
||||||
|
//取得單一裝置
|
||||||
|
var url = "/SensorType/GetOneSensorType/";
|
||||||
|
|
||||||
|
var send_data = {
|
||||||
|
id: selected_type_id
|
||||||
|
}
|
||||||
|
|
||||||
|
$.post(url, send_data, function (rel) {
|
||||||
|
if (rel.code == "9999") {
|
||||||
|
toast_error(rel.msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (rel.code == "9998") {
|
||||||
|
toast_error(rel.msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//$("#SensorDetail_SensorType_modal").val(selected_type_id);
|
||||||
|
$("#SensorDetail_SensorType_modal").val(rel.data.sensorName);
|
||||||
|
|
||||||
|
$("#SensorDetail-modal").modal();
|
||||||
|
}, 'json');
|
||||||
|
});
|
||||||
|
//#endregion
|
||||||
|
|
||||||
|
//#region 儲存裝置細項資料
|
||||||
|
function SaveSensorDetail() {
|
||||||
|
var url = "/SensorType/SaveSensorDetail";
|
||||||
|
if ($("#SensorDetail-form").valid()) {
|
||||||
|
var send_data = {
|
||||||
|
Id: selected_id,
|
||||||
|
SensorTypeId: selected_type_id,
|
||||||
|
ItemName: $("#SensorDetail_ItemName_modal").val(),
|
||||||
|
ItemEName: $("#SensorDetail_ItemEName_modal").val(),
|
||||||
|
HourType: $("#SensorDetail_HourType_modal").val(),
|
||||||
|
DayType: $("#SensorDetail_DayType_modal").val(),
|
||||||
|
MonthType: $('#SensorDetail_MonthType_modal').val(),
|
||||||
|
WarningURL: $('#SensorDetail_WarningURL_modal').val(),
|
||||||
|
UpperValue: $('#SensorDetail_UpperValue_modal').val(),
|
||||||
|
LowerValue: $('#SensorDetail_LowerValue_modal').val()
|
||||||
|
}
|
||||||
|
$.post(url, send_data, function (rel) {
|
||||||
|
if (rel.code != "0000") {
|
||||||
|
toast_error(rel.msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
toast_ok(rel.msg);
|
||||||
|
$('#SensorDetail-modal').modal('hide');
|
||||||
|
SensorTypeDeviceTable.ajax.reload();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}, 'json');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//#endregion
|
||||||
|
|
||||||
|
//#region 裝置-細項資訊
|
||||||
|
function GetSensorDetail(id) {
|
||||||
|
var send_data = {
|
||||||
|
Id: id
|
||||||
|
}
|
||||||
|
|
||||||
|
var url_sensorType_info = "/SensorType/GetOneSensorType";
|
||||||
|
|
||||||
|
$.post(url_sensorType_info, send_data, function (rel) {
|
||||||
|
if (rel.code != "0000") {
|
||||||
|
toast_error(rel.msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#sensor-detail-modal .modal-title").html(rel.data.sensorName + "- 細項");
|
||||||
|
|
||||||
|
}, 'json');
|
||||||
|
|
||||||
|
UpdateSensorDetailTable(id, function (returnData) {
|
||||||
|
if (returnData) {
|
||||||
|
$("#sensor-detail-modal").modal();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
//#endregion
|
||||||
|
|
||||||
|
function UpdateSensorDetailTable(sensorType_id, callback) {
|
||||||
|
var url = "/SensorType/GetSensorDetail";
|
||||||
|
var send_data = {
|
||||||
|
Id: sensorType_id
|
||||||
|
}
|
||||||
|
|
||||||
|
$.post(url, send_data, function (rel) {
|
||||||
|
if (rel.code != "0000") {
|
||||||
|
toast_error(rel.msg);
|
||||||
|
callback(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
sensorDetailTable = $("#sensor-detail-table > tbody");
|
||||||
|
|
||||||
|
sensorDetailTable.empty();
|
||||||
|
rel.data.forEach(function (value, index) {
|
||||||
|
var str = "";
|
||||||
|
str += "<tr>";
|
||||||
|
str += "<td>" + value.itemName + "</td>";
|
||||||
|
str += "<td>" + value.itemEName + "</td>";
|
||||||
|
str += "<td>" + value.hourTypeName + "</td>";
|
||||||
|
str += "<td>" + value.dayTypeName + "</td>";
|
||||||
|
str += "<td>" + value.monthTypeName + "</td>";
|
||||||
|
str += "<td>" + value.warningURL + "</td>";
|
||||||
|
str += "<td>" + value.upperValue + "</td>";
|
||||||
|
str += "<td>" + value.lowerValue + "</td>";
|
||||||
|
str += "<td>" + '<button type="button" class="btn btn-danger btn-pills waves-effect waves-themed del-sensor-detail" data-id="' + value.id + '">刪除</button>' + "</td>";
|
||||||
|
str += "</tr>";
|
||||||
|
sensorDetailTable.append(str);
|
||||||
|
});
|
||||||
|
|
||||||
|
SensorTypeDeviceTable.ajax.reload();
|
||||||
|
|
||||||
|
callback(true);
|
||||||
|
}, 'json');
|
||||||
|
}
|
||||||
|
|
||||||
|
//#region 刪除裝置細項
|
||||||
|
$("#sensor-detail-table").on("click", "button.del-sensor-detail", function () {
|
||||||
|
selected_id = $(this).attr('data-id');
|
||||||
|
var del_btn = $(this);
|
||||||
|
Swal.fire(
|
||||||
|
{
|
||||||
|
title: "刪除",
|
||||||
|
text: "你確定是否刪除此筆資料?",
|
||||||
|
type: "warning",
|
||||||
|
icon: 'warning',
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonText: "是",
|
||||||
|
cancelButtonText: "否"
|
||||||
|
}).then(function (result) {
|
||||||
|
if (result.value) {
|
||||||
|
//取得單一裝置細項
|
||||||
|
var url = "/SensorType/DeleteOneSensorDetail/";
|
||||||
|
var send_data = {
|
||||||
|
Id: selected_id
|
||||||
|
}
|
||||||
|
$.post(url, send_data, function (rel) {
|
||||||
|
if (rel.code != "0000") {
|
||||||
|
toast_error(rel.msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
del_btn.parents("tr").remove();
|
||||||
|
toast_ok(rel.msg);
|
||||||
|
sensorDetailTable.ajax.reload();
|
||||||
|
}, 'json');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
}
|
}
|
||||||
@ -418,14 +418,14 @@
|
|||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
}
|
}
|
||||||
@*@if (ViewBag.myUser.Role.Layer == (int)RoleLayerEnum.PlatformAdmin || ViewBag.auths.Contains("SensorType"))
|
@if (ViewBag.myUser.Role.Layer == (int)RoleLayerEnum.PlatformAdmin || ViewBag.auths.Contains("SensorType"))
|
||||||
{
|
{
|
||||||
<li class="@(ViewData["MainNum"] == "7" && ViewData["SubNum"] == "3" ? "active" : "")">
|
<li class="@(ViewData["MainNum"] == "7" && ViewData["SubNum"] == "3" ? "active" : "")">
|
||||||
<a asp-controller="SensorType" asp-action="Index" title="裝置管理" data-filter-tags="utilities disabled item">
|
<a asp-controller="SensorType" asp-action="Index" title="裝置管理" data-filter-tags="utilities disabled item">
|
||||||
<span class="nav-link-text" data-i18n="nav.utilities_disabled_item">裝置管理</span>
|
<span class="nav-link-text" data-i18n="nav.utilities_disabled_item">裝置管理</span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
}*@
|
}
|
||||||
@*@if (ViewBag.auths.Contains("User"))
|
@*@if (ViewBag.auths.Contains("User"))
|
||||||
{
|
{
|
||||||
<li class="">
|
<li class="">
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user