From 2c66b102313242b786cd02a74fd46a5f283a5a76 Mon Sep 17 00:00:00 2001 From: Kai Date: Tue, 22 Jun 2021 20:30:45 +0800 Subject: [PATCH 1/2] =?UTF-8?q?1.=20=E4=BF=AE=E6=94=B9=E9=9B=BB=E7=AB=99?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E7=82=BA=E4=B8=BB=E5=AD=90=E8=B3=87=E6=96=99?= =?UTF-8?q?=E5=BA=AB=202.=20DB=20development=20=E6=94=B9=E7=82=BA248?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SolarPower/Controllers/CompanyController.cs | 16 +- SolarPower/Controllers/MyBaseController.cs | 30 +- .../Controllers/PowerStationController.cs | 232 ++++--- SolarPower/Helper/DatabaseHelper.cs | 6 +- SolarPower/Models/Company.cs | 3 +- SolarPower/Models/MyBaseModel.cs | 6 + SolarPower/Models/PowerStation.cs | 19 +- .../Repository/Implement/CompanyRepository.cs | 311 +++++---- .../Implement/PowerStationRepository.cs | 253 ++++--- .../Repository/Implement/RepositoryBase.cs | 169 ++++- .../Interface/IPowerStationRepository.cs | 92 ++- .../Repository/Interface/IRepositoryBase.cs | 23 +- SolarPower/Views/Company/Index.cshtml | 6 +- SolarPower/Views/PowerStation/Index.cshtml | 4 +- .../PowerStation/PowerStationEdit.cshtml | 623 +++++++++--------- .../Views/PowerStation/_Exception.cshtml | 12 +- SolarPower/Views/Shared/_Layout.cshtml | 26 +- SolarPower/appsettings.Development.json | 6 +- 18 files changed, 1133 insertions(+), 704 deletions(-) diff --git a/SolarPower/Controllers/CompanyController.cs b/SolarPower/Controllers/CompanyController.cs index 3ee404f..f1fe043 100644 --- a/SolarPower/Controllers/CompanyController.cs +++ b/SolarPower/Controllers/CompanyController.cs @@ -280,9 +280,9 @@ namespace SolarPower.Controllers var id = await companyRepository.AddOneAsync(company, properties); - UpdateCompany updateCompany; - //處裡公司Logo圖片 + + #region 處理公司Logo圖片 if (post.LogoFile != null) { var split = post.LogoFile.FileName.Split("."); @@ -309,6 +309,7 @@ namespace SolarPower.Controllers await companyRepository.UpdateCompany(updateCompany, properties); } + #endregion #region 幫別間公司新增"公司管理員"之角色 Role role = new Role() @@ -332,23 +333,24 @@ namespace SolarPower.Controllers #region 新增公司DB及Table,公司DB編號規則 solar_com_(公司編號共四碼),ex:solar_com_0001 - var relationalDB = "solar_com_" + id.ToString().Trim().PadLeft(4, '0'); + //var siteDB = "solar_com" + id.ToString().Trim().PadLeft(4, '0'); + var siteDB = "solar_com" + id.ToString().Trim().PadLeft(4, '0') + "_test"; //修改 updateCompany = new UpdateCompany() { Id = id, - RelationalDB = relationalDB + SiteDB = siteDB }; properties = new List() { "Id", - "RelationalDB" + "SiteDB" }; await companyRepository.UpdateCompany(updateCompany, properties); - await companyRepository.CreatCompanyDB(relationalDB); + await companyRepository.CreatCompanyDB(siteDB); #endregion apiResult.Code = "0000"; @@ -357,7 +359,7 @@ namespace SolarPower.Controllers } else { - #region 修改使用者 + #region 修改公司 //先檢查統編是否已被使用 var exist = await companyRepository.GetOneNormalSimpleCompanyByTaxIDNumber(post.TaxIDNumber); diff --git a/SolarPower/Controllers/MyBaseController.cs b/SolarPower/Controllers/MyBaseController.cs index 3877051..7c52141 100644 --- a/SolarPower/Controllers/MyBaseController.cs +++ b/SolarPower/Controllers/MyBaseController.cs @@ -30,7 +30,6 @@ namespace SolarPower.Controllers protected ILogger Logger => _logger ?? (_logger = HttpContext?.RequestServices.GetService>()); private IUserRepository userRepository => HttpContext?.RequestServices.GetService(); - private IOperationRepository operationRepository => HttpContext?.RequestServices.GetService(); private ICompanyRepository companyRepository => HttpContext?.RequestServices.GetService(); private IRoleRepository roleRepository => HttpContext?.RequestServices.GetService(); private IOperatorLogRepository operatorLogRepository => HttpContext?.RequestServices.GetService(); @@ -125,5 +124,34 @@ namespace SolarPower.Controllers return false; } + + /// + /// 取得最新的流水號 + /// + /// 當前的 + /// + /// 0: PadLeft;1: PadRight + /// + public string GetLastSerialNumber(string current = "", int pad = 4, byte direction = 0) + { + var tempSerialNumber = 0; + if (!string.IsNullOrEmpty(current)) + { + tempSerialNumber = Convert.ToInt32(current) + 1; + } + else + { + tempSerialNumber = 1; + } + + if(direction == 0) + { + return tempSerialNumber.ToString().Trim().PadLeft(pad, '0'); + } + else + { + return tempSerialNumber.ToString().Trim().PadRight(pad, '0'); + } + } } } diff --git a/SolarPower/Controllers/PowerStationController.cs b/SolarPower/Controllers/PowerStationController.cs index 6ef4af8..9a4913e 100644 --- a/SolarPower/Controllers/PowerStationController.cs +++ b/SolarPower/Controllers/PowerStationController.cs @@ -18,6 +18,7 @@ namespace SolarPower.Controllers public class PowerStationController : MyBaseController { private readonly IUserRepository userRepository; + private readonly ICompanyRepository companyRepository; private readonly IPowerStationRepository powerStationRepository; private string boeFilePath = "/upload/power_station/boe_file/"; private string stationImageFilePath = "/upload/power_station/"; @@ -25,9 +26,11 @@ namespace SolarPower.Controllers public PowerStationController( IUserRepository userRepository, + ICompanyRepository companyRepository, IPowerStationRepository powerStationRepository) : base() { this.userRepository = userRepository; + this.companyRepository = companyRepository; this.powerStationRepository = powerStationRepository; powerSationSaveAsPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "power_station"); @@ -37,11 +40,6 @@ namespace SolarPower.Controllers return View(); } - public IActionResult Add() - { - return View("~/Views/PowerStation/PowerStationAdd.cshtml"); - } - public IActionResult Edit() { return View("~/Views/PowerStation/PowerStationEdit.cshtml"); @@ -73,6 +71,7 @@ namespace SolarPower.Controllers apiResult.Msg = errorCode.GetString(apiResult.Code); return apiResult; } + /// /// 取裝置類型下拉選單 /// @@ -209,6 +208,9 @@ namespace SolarPower.Controllers { powerStation = await powerStationRepository.GetOneAsync(post.Id); + //取得該公司DB Name + var company = await companyRepository.GetOneAsync(myUser.CompanyId); + if (powerStation == null) { if (post.Id != 0) @@ -219,20 +221,13 @@ namespace SolarPower.Controllers } #region 新增電站資訊 - //取得電站該縣市的Zipcode var zipcode = await powerStationRepository.GetCityAreaZipcodeAsync(post.AreaId); + //取得電站該縣市地區最後流水號 - var lastSerialNumber = await powerStationRepository.GetLastSerialNumberByCityAreaIdAsync(post.CityId, post.AreaId); - var tempSerialNumber = 0; - if (!string.IsNullOrEmpty(lastSerialNumber)) - { - tempSerialNumber = Convert.ToInt32(lastSerialNumber) + 1; - } - else - { - tempSerialNumber = 1; - } + var currentSerialNumber = await powerStationRepository.GetLastSerialNumberByCityAreaIdAsync(post.CityId, post.AreaId); + + var tempSerialNumber = GetLastSerialNumber(currentSerialNumber); var codeFormat = "{0}-{1}-{2}"; @@ -243,8 +238,8 @@ namespace SolarPower.Controllers AreaId = post.AreaId, Address = post.Address, Name = post.Name, - Code = String.Format(codeFormat, zipcode.City, zipcode.Area, tempSerialNumber.ToString().PadLeft(4, '0')), - SerialNumber = tempSerialNumber.ToString().PadLeft(4, '0'), + Code = String.Format(codeFormat, zipcode.City, zipcode.Area, tempSerialNumber), + SerialNumber = tempSerialNumber, IsEscrow = post.IsEscrow, EscrowName = post.EscrowName, ElectricityMeterAt = post.ElectricityMeterAt, @@ -259,6 +254,7 @@ namespace SolarPower.Controllers PhotovoltaicPanelProductModel = post.PhotovoltaicPanelProductModel, PhotovoltaicPanelSpecification = post.PhotovoltaicPanelSpecification, PhotovoltaicPanelAmount = post.PhotovoltaicPanelAmount, + SiteDB = company.SiteDB, CreatedBy = myUser.Id }; @@ -285,10 +281,11 @@ namespace SolarPower.Controllers "PhotovoltaicPanelProductModel", "PhotovoltaicPanelSpecification", "PhotovoltaicPanelAmount", + "SiteDB", "CreatedBy" }; - var id = await powerStationRepository.AddOneAsync(powerStation, properties); + var id = await powerStationRepository.AddOnePowerStationAsync(powerStation, properties, company.SiteDB); #region 新增土地與房屋資訊 var city = await powerStationRepository.GetOneCityByIdAsync(post.CityId); @@ -307,7 +304,7 @@ namespace SolarPower.Controllers "PowerStationId", "CreatedBy" }; - await powerStationRepository.AddOneLandBuildingInfo(landBuilding, landBuildingProperties); + await powerStationRepository.AddOneLandBuildingInfo(landBuilding, landBuildingProperties, company.SiteDB); #endregion #region 新增運維人員 @@ -333,7 +330,7 @@ namespace SolarPower.Controllers "CreatedBy", }; - await powerStationRepository.AddOperationPersonnelAsync(insertOperationPersonnels, properties); + await powerStationRepository.AddOperationPersonnelAsync(insertOperationPersonnels, operationPersonnelProperties, company.SiteDB); } #endregion @@ -401,11 +398,11 @@ namespace SolarPower.Controllers "UpdatedBy", }; - await powerStationRepository.UpdatePowerStationInfo(update, properties); + await powerStationRepository.UpdatePowerStationInfo(update, properties, powerStation.SiteDB); List origOperationPersonnels = null; //原先的運維人員 - origOperationPersonnels = await powerStationRepository.GetOperationPersonnelIdsByPowerStatioinId(powerStation.Id); + origOperationPersonnels = await powerStationRepository.GetOperationPersonnelIdsByPowerStatioinId(powerStation.Id, powerStation.SiteDB); //判斷新進來的資料是否要歸類到新增 or 刪除 #region 刪除電站運維人員編號 @@ -424,7 +421,7 @@ namespace SolarPower.Controllers } //刪除運維人員 - await powerStationRepository.DeleteOperationPersonnel(deleteOperationPersonnels); + await powerStationRepository.DeleteOperationPersonnel(deleteOperationPersonnels, powerStation.SiteDB); #endregion #region 新增電站運維人員 @@ -452,7 +449,7 @@ namespace SolarPower.Controllers "CreatedBy", }; - await powerStationRepository.AddOperationPersonnelAsync(insertOperationPersonnels, operationPersonnelProperties); + await powerStationRepository.AddOperationPersonnelAsync(insertOperationPersonnels, operationPersonnelProperties, powerStation.SiteDB); } #endregion @@ -559,11 +556,13 @@ namespace SolarPower.Controllers "UpdatedBy", }; - await powerStationRepository.UpdateBoETPCInfo(update, properties); + await powerStationRepository.UpdateBoETPCInfo(update, properties, powerStation.SiteDB); #endregion } + //重新取得資料 powerStation = await powerStationRepository.GetOneAsync(powerStation.Id); + //替能源局換檔案路徑 if (!string.IsNullOrEmpty(powerStation.BoEFile)) { @@ -619,7 +618,7 @@ namespace SolarPower.Controllers return apiResult; } - landBuilding = await powerStationRepository.GetOneLandBuildingInfo(post.Id); + landBuilding = await powerStationRepository.GetOneLandBuildingInfo(post.Id, powerStation.SiteDB); if (landBuilding == null) { @@ -659,7 +658,7 @@ namespace SolarPower.Controllers "CreatedBy" }; - var id = await powerStationRepository.AddOneLandBuildingInfo(landBuilding, properties); + var id = await powerStationRepository.AddOneLandBuildingInfo(landBuilding, properties, powerStation.SiteDB); apiResult.Code = "0000"; apiResult.Msg = "儲存成功"; @@ -695,7 +694,7 @@ namespace SolarPower.Controllers "UpdatedBy", }; - await powerStationRepository.UpdateLandBuildingInfo(update, properties); + await powerStationRepository.UpdateLandBuildingInfo(update, properties, powerStation.SiteDB); apiResult.Code = "0000"; apiResult.Msg = "修改成功"; @@ -715,6 +714,7 @@ namespace SolarPower.Controllers return apiResult; } + /// /// 新增/修改 運維資料 /// @@ -723,8 +723,13 @@ namespace SolarPower.Controllers public async Task> SaveOperation(OperationInfo post) { ApiResult apiResult = new ApiResult(); + + PowerStation powerStation = null; + try { + powerStation = await powerStationRepository.GetOneAsync(post.PowerStationId); + if (post.Id == 0) { OperationInfo operation = new OperationInfo() @@ -749,7 +754,7 @@ namespace SolarPower.Controllers "PowerStationId", "Type" }; - await powerStationRepository.AddOperation(operation, properties); + await powerStationRepository.AddOperation(operation, properties, powerStation.SiteDB); apiResult.Code = "0000"; apiResult.Msg = "新增成功"; @@ -778,7 +783,7 @@ namespace SolarPower.Controllers "PowerStationId", "Type" }; - await powerStationRepository.UpdateOperation(operation, properties); + await powerStationRepository.UpdateOperation(operation, properties, powerStation.SiteDB); apiResult.Code = "0000"; apiResult.Msg = "儲存成功"; } @@ -787,25 +792,34 @@ namespace SolarPower.Controllers catch (Exception exception) { apiResult.Code = "9999"; - apiResult.Msg = exception.ToString(); + 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; } + /// /// 運維資料DataTable /// /// - /// + /// public async Task OperationTable(int stationId) { List operationTable = new List(); ApiResult> apiResult = new ApiResult>(); + + PowerStation powerStation = null; + try { - apiResult.Code = "0000"; - operationTable = await powerStationRepository.OperationTable(stationId); + + powerStation = await powerStationRepository.GetOneAsync(stationId); + + operationTable = await powerStationRepository.OperationTable(stationId, powerStation.SiteDB); foreach (OperationTable a in operationTable) { a.Function = @" @@ -825,13 +839,15 @@ namespace SolarPower.Controllers } } + apiResult.Code = "0000"; apiResult.Data = operationTable; - } catch (Exception exception) { apiResult.Code = "9999"; - apiResult.Msg = exception.ToString(); + apiResult.Msg = errorCode.GetString(apiResult.Code); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + "stationId = " + stationId); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); } var result = Json(new { @@ -840,41 +856,52 @@ namespace SolarPower.Controllers return result; } + /// /// 取得一筆 運維 資料 /// - /// + /// /// - public async Task> GetOneOperation(int id) + public async Task> GetOneOperation(PostPowerStationIdAndSelectedId post) { - OperationInfo operation = new OperationInfo(); ApiResult apiResult = new ApiResult(); + + PowerStation powerStation = null; try { + powerStation = await powerStationRepository.GetOneAsync(post.PowerStationId); + apiResult.Code = "0000"; - operation = await powerStationRepository.OneOperationInfo(id); + var operation = await powerStationRepository.OneOperationInfo(post.SelectedId, powerStation.SiteDB); apiResult.Data = operation; } catch (Exception exception) { apiResult.Code = "9999"; - apiResult.Msg = exception.ToString(); + 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; } + /// /// 刪除 運維 資料 /// /// /// - public async Task> DeleteOneOperation(int id) + public async Task> DeleteOneOperation(PostPowerStationIdAndSelectedId post) { ApiResult apiResult = new ApiResult(); - OperationInfo operation = new OperationInfo(); + + PowerStation powerStation = null; try { - operation = await powerStationRepository.OneOperationInfo(id); + powerStation = await powerStationRepository.GetOneAsync(post.PowerStationId); + + var operation = await powerStationRepository.OneOperationInfo(post.SelectedId, powerStation.SiteDB); if (operation == null) { @@ -883,7 +910,7 @@ namespace SolarPower.Controllers return apiResult; } - await powerStationRepository.DeleteOneOtherTable(operation.Id, "operation_firm"); + await powerStationRepository.DeleteOneByIdWithCustomDBNameAndTable(operation.Id, powerStation.SiteDB, "operation_firm"); apiResult.Code = "0000"; apiResult.Msg = "刪除成功"; @@ -892,12 +919,14 @@ namespace SolarPower.Controllers { apiResult.Code = "9999"; apiResult.Msg = errorCode.GetString(apiResult.Code); - Logger.LogError("【" + controllerName + "/" + actionName + "】" + "Id=" + id); + string json = System.Text.Json.JsonSerializer.Serialize(post); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + json); Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); } return apiResult; } + /// /// 新增 / 修改 裝置資料 /// @@ -1034,21 +1063,24 @@ namespace SolarPower.Controllers }); return result; } + /// /// 軟刪除單一土地房屋資訊 /// /// /// [HttpPost] - public async Task> DeleteLandBuildingInfo(int id) + public async Task> DeleteLandBuildingInfo(PostPowerStationIdAndSelectedId post) { ApiResult apiResult = new ApiResult(); - + PowerStation powerStation = null; LandBuilding landBuilding; try { - landBuilding = await powerStationRepository.GetOneLandBuildingInfo(id); + powerStation = await powerStationRepository.GetOneAsync(post.PowerStationId); + + landBuilding = await powerStationRepository.GetOneLandBuildingInfo(post.SelectedId, powerStation.SiteDB); if (landBuilding == null) { @@ -1057,7 +1089,7 @@ namespace SolarPower.Controllers return apiResult; } - await powerStationRepository.DeleteOneLandBuildingInfo(landBuilding.Id); + await powerStationRepository.DeleteOneLandBuildingInfo(landBuilding.Id, powerStation.SiteDB); apiResult.Code = "0000"; apiResult.Msg = "刪除成功"; @@ -1067,12 +1099,14 @@ namespace SolarPower.Controllers { apiResult.Code = "9999"; apiResult.Msg = errorCode.GetString(apiResult.Code); - Logger.LogError("【" + controllerName + "/" + actionName + "】" + "Id=" + id); + string json = System.Text.Json.JsonSerializer.Serialize(post); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + json); Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); } return apiResult; } + /// /// 取單一設備資料 /// @@ -1096,6 +1130,7 @@ namespace SolarPower.Controllers return apiResult; } + /// /// 刪除設備 /// @@ -1116,7 +1151,8 @@ namespace SolarPower.Controllers return apiResult; } - await powerStationRepository.DeleteOneOtherTable(Device.Id, "device"); + //TODO + //await powerStationRepository.DeleteOneByIdWithCustomDBNameAndTable(Device.Id, "device"); apiResult.Code = "0000"; apiResult.Msg = "刪除成功"; @@ -1131,6 +1167,7 @@ namespace SolarPower.Controllers return apiResult; } + /// /// 新增/修改異常 /// @@ -1287,7 +1324,8 @@ namespace SolarPower.Controllers return apiResult; } - await powerStationRepository.DeleteOneOtherTable(Exception.Id, "power_station_exception"); + //TODO + //await powerStationRepository.DeleteOneOtherTable(Exception.Id, "power_station_exception"); apiResult.Code = "0000"; apiResult.Msg = "刪除成功"; @@ -1303,7 +1341,6 @@ namespace SolarPower.Controllers return apiResult; } - /// /// 取得所有電站圖片 /// @@ -1328,7 +1365,15 @@ namespace SolarPower.Controllers } else { - powerStationImages = await powerStationRepository.GetAllPowerStationImageAsync(powerStationId); + + if(powerStation.CompanyId != myUser.CompanyId) + { + apiResult.Code = "9993"; + apiResult.Msg = errorCode.GetString(apiResult.Code); + return apiResult; + } + + powerStationImages = await powerStationRepository.GetAllPowerStationImageAsync(powerStationId, powerStation.SiteDB); foreach (var stationImage in powerStationImages) { @@ -1424,13 +1469,13 @@ namespace SolarPower.Controllers "CreatedBy" }; - await powerStationRepository.AddPowerStationImageAsync(powerStationImages, properties); + await powerStationRepository.AddPowerStationImageAsync(powerStationImages, properties, powerStation.SiteDB); } #endregion #region 重新取得圖片資訊 powerStationImages = null; - powerStationImages = await powerStationRepository.GetAllPowerStationImageAsync(powerStation.Id); + powerStationImages = await powerStationRepository.GetAllPowerStationImageAsync(powerStation.Id, powerStation.SiteDB); foreach (var stationImage in powerStationImages) { @@ -1460,15 +1505,17 @@ namespace SolarPower.Controllers /// /// /// - public async Task> DeletePowerStationImage(int id) + public async Task> DeletePowerStationImage(PostPowerStationIdAndSelectedId post) { ApiResult apiResult = new ApiResult(); + PowerStation powerStation; PowerStationImage powerStationImage; - try { - powerStationImage = await powerStationRepository.GetOnePowerStationImageAsync(id); + powerStation = await powerStationRepository.GetOneAsync(post.PowerStationId); + + powerStationImage = await powerStationRepository.GetOnePowerStationImageAsync(post.SelectedId, powerStation.SiteDB); if (powerStationImage == null) { @@ -1477,7 +1524,14 @@ namespace SolarPower.Controllers return apiResult; } - await powerStationRepository.DeleteOnePowerStationImage(id); + if (powerStation.CompanyId != myUser.CompanyId) + { + apiResult.Code = "9993"; + apiResult.Msg = errorCode.GetString(apiResult.Code); + return apiResult; + } + + await powerStationRepository.DeleteOnePowerStationImage(powerStationImage.Id, powerStation.SiteDB); apiResult.Code = "0000"; apiResult.Msg = "刪除成功"; @@ -1486,7 +1540,8 @@ namespace SolarPower.Controllers { apiResult.Code = "9999"; apiResult.Msg = errorCode.GetString(apiResult.Code); - Logger.LogError("【" + controllerName + "/" + actionName + "】" + "Id=" + id); + string json = System.Text.Json.JsonSerializer.Serialize(post); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + json); Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); } @@ -1502,11 +1557,13 @@ namespace SolarPower.Controllers { ApiResult apiResult = new ApiResult(); + PowerStation powerStation; PowerStationImage powerStationImage; - try { - powerStationImage = await powerStationRepository.GetOnePowerStationImageAsync(post.TargetImageId); + powerStation = await powerStationRepository.GetOneAsync(post.PowerStationId); + + powerStationImage = await powerStationRepository.GetOnePowerStationImageAsync(post.TargetImageId, powerStation.SiteDB); if (powerStationImage == null) { @@ -1515,11 +1572,18 @@ namespace SolarPower.Controllers return apiResult; } + if (powerStation.CompanyId != myUser.CompanyId) + { + apiResult.Code = "9993"; + apiResult.Msg = errorCode.GetString(apiResult.Code); + return apiResult; + } + UpdataPowerStationImage updata = new UpdataPowerStationImage(); List properties = new List(); //找出原本的圖片 - var origMainDisplay = await powerStationRepository.GetMainDisplayAsync(post.PowerStationId); + var origMainDisplay = await powerStationRepository.GetMainDisplayAsync(post.PowerStationId, powerStation.SiteDB); if (origMainDisplay != null) { updata = new UpdataPowerStationImage() @@ -1536,7 +1600,7 @@ namespace SolarPower.Controllers "UpdatedBy" }; - await powerStationRepository.UpdatePowerStationImage(updata, properties); + await powerStationRepository.UpdatePowerStationImage(updata, properties, powerStation.SiteDB); } // 更新被選擇的圖維卡片顯示圖 @@ -1554,7 +1618,7 @@ namespace SolarPower.Controllers "UpdatedBy" }; - await powerStationRepository.UpdatePowerStationImage(updata, properties); + await powerStationRepository.UpdatePowerStationImage(updata, properties, powerStation.SiteDB); apiResult.Code = "0000"; apiResult.Msg = "修改卡片顯示圖成功"; @@ -1596,7 +1660,14 @@ namespace SolarPower.Controllers } else { - powerStationSingleLines = await powerStationRepository.GetAllPowerStationSingleLineAsync(powerStationId); + if (powerStation.CompanyId != myUser.CompanyId) + { + apiResult.Code = "9993"; + apiResult.Msg = errorCode.GetString(apiResult.Code); + return apiResult; + } + + powerStationSingleLines = await powerStationRepository.GetAllPowerStationSingleLineAsync(powerStationId, powerStation.SiteDB); foreach (var singleLine in powerStationSingleLines) { @@ -1692,13 +1763,13 @@ namespace SolarPower.Controllers "CreatedBy" }; - await powerStationRepository.AddPowerStationSingleLineAsync(powerStationSingleLines, properties); + await powerStationRepository.AddPowerStationSingleLineAsync(powerStationSingleLines, properties, powerStation.SiteDB); } #endregion #region 重新取得圖片資訊 powerStationSingleLines = null; - powerStationSingleLines = await powerStationRepository.GetAllPowerStationSingleLineAsync(powerStation.Id); + powerStationSingleLines = await powerStationRepository.GetAllPowerStationSingleLineAsync(powerStation.Id, powerStation.SiteDB); foreach (var singleLine in powerStationSingleLines) { @@ -1728,15 +1799,25 @@ namespace SolarPower.Controllers /// /// /// - public async Task> DeletePowerStationSingleLine(int id) + public async Task> DeletePowerStationSingleLine(PostPowerStationIdAndSelectedId post) { ApiResult apiResult = new ApiResult(); + PowerStation powerStation; PowerStationSingleLine powerStationSingleLine; try { - powerStationSingleLine = await powerStationRepository.GetOnePowerStationSingleLineAsync(id); + powerStation = await powerStationRepository.GetOneAsync(post.PowerStationId); + + if (powerStation.CompanyId != myUser.CompanyId) + { + apiResult.Code = "9993"; + apiResult.Msg = errorCode.GetString(apiResult.Code); + return apiResult; + } + + powerStationSingleLine = await powerStationRepository.GetOnePowerStationSingleLineAsync(post.SelectedId, powerStation.SiteDB); if (powerStationSingleLine == null) { @@ -1745,7 +1826,7 @@ namespace SolarPower.Controllers return apiResult; } - await powerStationRepository.DeleteOnePowerStationSingleLine(id); + await powerStationRepository.DeleteOnePowerStationSingleLine(powerStationSingleLine.Id, powerStation.SiteDB); apiResult.Code = "0000"; apiResult.Msg = "刪除成功"; @@ -1754,7 +1835,8 @@ namespace SolarPower.Controllers { apiResult.Code = "9999"; apiResult.Msg = errorCode.GetString(apiResult.Code); - Logger.LogError("【" + controllerName + "/" + actionName + "】" + "Id=" + id); + string json = System.Text.Json.JsonSerializer.Serialize(post); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + json); Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); } diff --git a/SolarPower/Helper/DatabaseHelper.cs b/SolarPower/Helper/DatabaseHelper.cs index b359893..06cc142 100644 --- a/SolarPower/Helper/DatabaseHelper.cs +++ b/SolarPower/Helper/DatabaseHelper.cs @@ -32,9 +32,9 @@ namespace SolarPower.Helper EDFunction ed = new EDFunction(); var serverStr = ed.AESDecrypt(dbConfig.Server); - var databaseStr = ed.DESDecrypt(dbConfig.Database); - var rootStr = ed.DESDecrypt(dbConfig.Root); - var passwordStr = ed.DESDecrypt(dbConfig.Password); + var databaseStr = ed.AESDecrypt(dbConfig.Database); + var rootStr = ed.AESDecrypt(dbConfig.Root); + var passwordStr = ed.AESDecrypt(dbConfig.Password); //var connStr = $"server={serverStr};database={databaseStr};user={rootStr};password={passwordStr};charset=utf8;"; var connStr = @"server=127.0.0.1;database=solar_power;user=root;password=000000;charset=utf8;"; diff --git a/SolarPower/Models/Company.cs b/SolarPower/Models/Company.cs index e1b2ecf..cda8470 100644 --- a/SolarPower/Models/Company.cs +++ b/SolarPower/Models/Company.cs @@ -22,6 +22,7 @@ namespace SolarPower.Models.Company public string Phone { get; set; } public string Address { get; set; } public int RegisterUpperLimit { get; set; } //註冊上限 + public string SiteDB { get; set; } //公司各自DB } /// @@ -51,7 +52,7 @@ namespace SolarPower.Models.Company public string TaxIDNumber { get; set; } //統一編號 public string Phone { get; set; } //電話 public string Address { get; set; } - public string RelationalDB { get; set; } //關聯的公司自己資料庫 + public string SiteDB { get; set; } //關聯的公司自己資料庫 public int RegisterUpperLimit { get; set; } //註冊上限 } diff --git a/SolarPower/Models/MyBaseModel.cs b/SolarPower/Models/MyBaseModel.cs index 5fde68a..00e4ee2 100644 --- a/SolarPower/Models/MyBaseModel.cs +++ b/SolarPower/Models/MyBaseModel.cs @@ -63,4 +63,10 @@ namespace SolarPower.Models public byte Layer { get; set; } //角色層級 public List Auths { get; set; } //可操作頁面 } + + public class Variable + { + public string Name { get; set; } + public string Value { get; set; } + } } diff --git a/SolarPower/Models/PowerStation.cs b/SolarPower/Models/PowerStation.cs index 054182d..84fe51f 100644 --- a/SolarPower/Models/PowerStation.cs +++ b/SolarPower/Models/PowerStation.cs @@ -101,6 +101,17 @@ namespace SolarPower.Models.PowerStation set { tpcPurchaseElectricityAt = value; } } public List LandBuildings { get; set; } //土地房屋資料 + public byte SolarType { get; set; } //電站類型 + public double kwh { get; set; } // + public double Today_kwh { get; set; } //今日發電量 + public double Total_kwh { get; set; } //總發電量 + public double kwhkwp { get; set; } + public double PR { get; set; } + public double MP { get; set; } + public double SolarHour { get; set; } //總運轉小時 + public string SiteDB { get; set; } //電站 DB name: solar_com + public string TodayWeather { get; set; } //今日天氣 + public double TodayWeatherTemp { get; set; } //今日溫度 public string CreatorName { get; set; } //創建者名稱 } @@ -288,9 +299,13 @@ namespace SolarPower.Models.PowerStation public string Email { get; set; }//Email } - public class OperationStationId + /// + /// 針對電站管理的運維、設備及異常設定 + /// + public class PostPowerStationIdAndSelectedId { - public int stationId { get; set; } + public int PowerStationId { get; set; } + public int SelectedId { get; set; } } public class OperationTable : OperationInfo diff --git a/SolarPower/Repository/Implement/CompanyRepository.cs b/SolarPower/Repository/Implement/CompanyRepository.cs index d495d7c..3d77eb4 100644 --- a/SolarPower/Repository/Implement/CompanyRepository.cs +++ b/SolarPower/Repository/Implement/CompanyRepository.cs @@ -20,7 +20,6 @@ namespace SolarPower.Repository.Implement tableName = "company"; } - /// /// 取得下拉式公司選單,須為Deleted: 0 /// @@ -413,9 +412,9 @@ namespace SolarPower.Repository.Implement /// /// 創建公司自己的DB /// - /// + /// /// - public async Task CreatCompanyDB(string dbName) + public async Task CreatCompanyDB(string db_name) { using (IDbConnection conn = this._databaseHelper.GetConnection()) { @@ -425,148 +424,184 @@ namespace SolarPower.Repository.Implement try { var sql = @$" - -- 傾印 資料庫結構 - CREATE DATABASE IF NOT EXISTS `{dbName}`; - USE `{dbName}`; + -- 傾印 子資料庫結構 + CREATE DATABASE IF NOT EXISTS `{db_name}`; + USE `{db_name}`; - -- 傾印 資料表 device 結構 - CREATE TABLE IF NOT EXISTS `device` ( - `Id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `Deleted` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否刪除, 0:否 1:是', - `UID` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '設備編號,縣市 +區域+電廠流水號(0001~9999)+設備類別(字母:3碼) + SN(設備流水號;3碼)', - `PowerStationId` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '所屬電站編號', - `Name` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '名稱', - `Type` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '類型', - `Brand` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '廠牌', - `ProductModel` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '型號', - `DBName` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `TableName` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `ColName` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `Remark` text COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `CreatedBy` int(10) unsigned NOT NULL COMMENT '建立者', - `CreatedAt` timestamp NOT NULL DEFAULT current_timestamp() COMMENT '建立時間', - `UpdatedBy` int(10) unsigned DEFAULT NULL COMMENT '修改者', - `UpdatedAt` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp() COMMENT '修改時間', - PRIMARY KEY (`Id`) USING BTREE, - KEY `IDX_01` (`Deleted`) USING BTREE, - KEY `IDX_02` (`UID`,`PowerStationId`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='裝置列表'; + -- 傾印 資料表 device 結構 + CREATE TABLE IF NOT EXISTS `device` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `Deleted` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否刪除, 0:否 1:是', + `UID` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '設備編號,縣市 +區域+電廠流水號(0001~9999)+設備類別(字母:3碼) + SN(設備流水號;3碼)', + `PowerStationId` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '所屬電站編號', + `Name` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '名稱', + `Type` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '類型', + `TypeName` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '類型名稱', + `Brand` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '廠牌', + `ProductModel` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '型號', + `DBName` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `TableName` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `ColName` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `Remark` text COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `CreatedBy` int(10) unsigned NOT NULL COMMENT '建立者', + `CreatedAt` timestamp NOT NULL DEFAULT current_timestamp() COMMENT '建立時間', + `UpdatedBy` int(10) unsigned DEFAULT NULL COMMENT '修改者', + `UpdatedAt` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp() COMMENT '修改時間', + PRIMARY KEY (`Id`) USING BTREE, + KEY `IDX_01` (`Deleted`) USING BTREE, + KEY `IDX_02` (`UID`,`PowerStationId`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='裝置列表'; - -- 傾印 資料表 land_building 結構 - CREATE TABLE IF NOT EXISTS `land_building` ( - `Id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `Deleted` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否刪除, 0:否 1:是', - `PowerStationId` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '所屬電站編號', - `Address` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '地址', - `LeaseNotarizationAt` timestamp NULL DEFAULT NULL COMMENT '租約公證日期', - `Landowner` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '地主姓名', - `Purpose` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '房屋用途', - `LeaseRate` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '租金比例(%)', - `Coordinate` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '座標', - `phone` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '電話', - `CreatedBy` int(10) unsigned NOT NULL COMMENT '建立者', - `CreatedAt` timestamp NOT NULL DEFAULT current_timestamp() COMMENT '建立時間', - `UpdatedBy` int(10) unsigned DEFAULT NULL COMMENT '修改者', - `UpdatedAt` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp() COMMENT '修改時間', - PRIMARY KEY (`Id`), - KEY `IDX_01` (`Deleted`,`PowerStationId`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='土地與房屋'; + -- 傾印 資料表 land_building 結構 + CREATE TABLE IF NOT EXISTS `land_building` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `Deleted` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否刪除, 0:否 1:是', + `PowerStationId` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '所屬電站編號', + `Address` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '地址', + `LeaseNotarizationAt` timestamp NULL DEFAULT NULL COMMENT '租約公證日期', + `Landowner` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '地主姓名', + `Purpose` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '房屋用途', + `LeaseRate` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '租金比例(%)', + `Coordinate` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '座標', + `Phone` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '電話', + `CreatedBy` int(10) unsigned NOT NULL COMMENT '建立者', + `CreatedAt` timestamp NOT NULL DEFAULT current_timestamp() COMMENT '建立時間', + `UpdatedBy` int(10) unsigned DEFAULT NULL COMMENT '修改者', + `UpdatedAt` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp() COMMENT '修改時間', + PRIMARY KEY (`Id`), + KEY `IDX_01` (`Deleted`,`PowerStationId`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='土地與房屋'; - -- 傾印 資料表 operation_firm 結構 - CREATE TABLE IF NOT EXISTS `operation_firm` ( - `Id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `Deleted` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否刪除, 0:否 1:是', - `PowerStationId` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '所屬電站編號', - `Name` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '名稱', - `Type` tinyint(4) NOT NULL DEFAULT 0 COMMENT '廠商類別,0:施工 1:清洗 2:運維', - `ContactPerson` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '聯絡人', - `Phone` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '電話', - `Email` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Email', - `CreatedBy` int(10) unsigned NOT NULL COMMENT '建立者', - `CreatedAt` timestamp NOT NULL DEFAULT current_timestamp() COMMENT '建立時間', - `UpdatedBy` int(10) unsigned DEFAULT NULL COMMENT '修改者', - `UpdatedAt` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp() COMMENT '修改時間', - PRIMARY KEY (`Id`), - KEY `IDX_01` (`Deleted`,`PowerStationId`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='運維廠商'; + -- 傾印 資料表 operation_firm 結構 + CREATE TABLE IF NOT EXISTS `operation_firm` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `Deleted` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否刪除, 0:否 1:是', + `PowerStationId` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '所屬電站編號', + `Name` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '名稱', + `Type` tinyint(4) NOT NULL DEFAULT 0 COMMENT '廠商類別,0:施工 1:清洗 2:運維', + `ContactPerson` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '聯絡人', + `Phone` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '電話', + `Email` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Email', + `CreatedBy` int(10) unsigned NOT NULL COMMENT '建立者', + `CreatedAt` timestamp NOT NULL DEFAULT current_timestamp() COMMENT '建立時間', + `UpdatedBy` int(10) unsigned DEFAULT NULL COMMENT '修改者', + `UpdatedAt` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp() COMMENT '修改時間', + PRIMARY KEY (`Id`), + KEY `IDX_01` (`Deleted`,`PowerStationId`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='運維廠商'; - -- 傾印 資料表 power_station 結構 - CREATE TABLE IF NOT EXISTS `power_station` ( - `Id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `Deleted` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否刪除, 0:否 1:是', - `CompanyId` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '公司編號', - `Name` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '名稱', - `Code` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '電站代碼,縣市+區域+流水號 ', - `IsEscrow` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否為代管,0:否 1:是', - `EscrowName` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '代管名稱', - `ElectricityMeterAt` timestamp NULL DEFAULT NULL COMMENT '台電掛錶日', - `EstimatedRecoveryTime` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '預估回收時間', - `GeneratingCapacity` decimal(10,1) NOT NULL DEFAULT 0.0 COMMENT '電廠發電容量,單位(千瓦)', - `PowerRate` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '受電費率', - `Coordinate` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '座標', - `InverterBrand` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '逆變器廠牌', - `InverterProductModel` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '逆變器型號', - `InverterAmount` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '逆變器數量', - `PhotovoltaicPanelBrand` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '光電板廠牌', - `PhotovoltaicPanelProductModel` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '光電板型號', - `PhotovoltaicPanelSpecification` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '光電板規格', - `PhotovoltaicPanelAmount` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '光電板數量', - `BoEFile` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '能源局檔案', - `BoEDiscountRate` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '能源局折扣率', - `BoEDeviceRegisterNumber` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '能源局設備登記編號', - `BoERentRatio` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '能源局租金比率,單位(%)', - `TPCContractNumber` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '台電契約編號', - `TPCContractAt` timestamp NULL DEFAULT NULL COMMENT '台電簽約日期', - `TPCSellDeadline` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '台電售電期限,單位(年)', - `TPCMeterReading` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '台電每期抄錶日', - `TPCPurchaseElectricityAt` timestamp NULL DEFAULT NULL COMMENT '台電正式購電日', - `TPCSellElectricityAt` timestamp NULL DEFAULT NULL COMMENT '台電正式售電日', - `CreatedBy` int(10) unsigned NOT NULL COMMENT '建立者', - `CreatedAt` timestamp NOT NULL DEFAULT current_timestamp() COMMENT '建立時間', - `UpdatedBy` int(10) unsigned DEFAULT NULL COMMENT '修改者', - `UpdatedAt` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp() COMMENT '修改時間', - PRIMARY KEY (`Id`), - KEY `IDX_01` (`Deleted`), - KEY `IDX_02` (`CompanyId`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='電站資料'; + -- 傾印 資料表 power_station 結構 + CREATE TABLE IF NOT EXISTS `power_station` ( + `Id` int(10) unsigned NOT NULL DEFAULT 0, + `Deleted` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否刪除, 0:否 1:是', + `CompanyId` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '公司編號', + `CityId` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '電站縣市', + `AreaId` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '電站區域', + `Address` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '電站詳細地址', + `Name` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '名稱', + `Code` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '電站代碼,縣市+區域+四碼流水號', + `SerialNumber` varchar(4) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '四碼流水號', + `IsEscrow` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否為代管,0:否 1:是', + `EscrowName` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '代管名稱', + `ElectricityMeterAt` timestamp NULL DEFAULT NULL COMMENT '台電掛錶日', + `EstimatedRecoveryTime` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '預估回收時間', + `GeneratingCapacity` decimal(10,1) NOT NULL DEFAULT 0.0 COMMENT '電廠發電容量,單位(千瓦)', + `PowerRate` decimal(10,3) NOT NULL DEFAULT 0.000 COMMENT '受電費率', + `Coordinate` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '座標', + `InverterBrand` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '逆變器廠牌', + `InverterProductModel` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '逆變器型號', + `InverterAmount` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '逆變器數量', + `PhotovoltaicPanelBrand` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '光電板廠牌', + `PhotovoltaicPanelProductModel` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '光電板型號', + `PhotovoltaicPanelSpecification` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '光電板規格', + `PhotovoltaicPanelAmount` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '光電板數量', + `BoEFileName` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '能源局原檔案名', + `BoEFile` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '能源局檔案', + `BoEDiscountRate` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '能源局折扣率', + `BoEDeviceRegisterNumber` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '能源局設備登記編號', + `BoERentRatio` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '能源局租金比率,單位(%)', + `TPCContractNumber` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '台電契約編號', + `TPCContractAt` timestamp NULL DEFAULT NULL COMMENT '台電簽約日期', + `TPCSellDeadline` int(10) unsigned DEFAULT 0 COMMENT '台電售電期限,單位(年)', + `TPCMeterReading` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '台電每期抄錶日', + `TPCPurchaseElectricityAt` timestamp NULL DEFAULT NULL COMMENT '台電正式購電日', + `TPCSellElectricityAt` timestamp NULL DEFAULT NULL COMMENT '台電正式售電日', + `kwh` decimal(10,3) unsigned NOT NULL DEFAULT 0.000, + `Today_kwh` decimal(10,3) unsigned NOT NULL DEFAULT 0.000 COMMENT '今日發電量', + `Total_kwh` decimal(10,3) unsigned NOT NULL DEFAULT 0.000 COMMENT '總發電量', + `kwhkwp` decimal(10,3) unsigned NOT NULL DEFAULT 0.000, + `PR` decimal(5,2) unsigned NOT NULL DEFAULT 0.00 COMMENT '電站Pr值', + `MP` decimal(5,2) unsigned NOT NULL DEFAULT 0.00, + `SolarHour` decimal(5,2) unsigned NOT NULL DEFAULT 0.00 COMMENT '總運轉小時', + `SiteDB` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '0.000' COMMENT '電站 DB name: solar_com', + `TodayWeather` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '0.000' COMMENT '今日天氣', + `TodayWeatherTemp` decimal(5,2) unsigned NOT NULL DEFAULT 0.00 COMMENT '今日溫度', + `CreatedBy` int(10) unsigned NOT NULL COMMENT '建立者', + `CreatedAt` timestamp NOT NULL DEFAULT current_timestamp() COMMENT '建立時間', + `UpdatedBy` int(10) unsigned DEFAULT NULL COMMENT '修改者', + `UpdatedAt` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp() COMMENT '修改時間', + PRIMARY KEY (`Id`), + KEY `IDX_01` (`Deleted`), + KEY `IDX_02` (`CompanyId`), + KEY `IDX_03` (`CityId`,`AreaId`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='電站資料'; - -- 傾印 資料表 power_station_image 結構 - CREATE TABLE IF NOT EXISTS `power_station_image` ( - `Id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `Deleted` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否刪除, 0:否 1:是', - `PowerStationId` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '電站編號', - `IsMainDisplay` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否主要顯示圖片, 0:否 1:是', - ` image` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '圖片檔名', - `CreatedBy` int(10) unsigned NOT NULL COMMENT '建立者', - `CreatedAt` timestamp NOT NULL DEFAULT current_timestamp() COMMENT '建立時間', - PRIMARY KEY (`Id`), - KEY `IDX_01` (`Deleted`,`IsMainDisplay`,`PowerStationId`) USING BTREE - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='電站資料'; + -- 傾印 資料表 power_station_exception 結構 + CREATE TABLE IF NOT EXISTS `power_station_exception` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `Deleted` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否刪除, 0:否 1:是', + `PowerStationId` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '電站編號', + `Type` tinyint(4) NOT NULL DEFAULT 0 COMMENT '類型,0:PR值', + `UpperLimit` decimal(10,2) NOT NULL DEFAULT 0.00 COMMENT '上限值', + `LowerLimit` decimal(10,2) NOT NULL DEFAULT 0.00 COMMENT '下限值', + `Alarm` tinyint(4) NOT NULL DEFAULT 0 COMMENT '警報方式,0:email通知', + `CreatedBy` int(10) unsigned NOT NULL COMMENT '建立者', + `CreatedAt` timestamp NOT NULL DEFAULT current_timestamp() COMMENT '建立時間', + `UpdatedBy` int(10) unsigned DEFAULT NULL COMMENT '修改者', + `UpdatedAt` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp() COMMENT '修改時間', + PRIMARY KEY (`Id`), + KEY `IDX_01` (`Deleted`,`PowerStationId`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='電站異常值設定'; - -- 傾印 資料表 power_station_operation_personnel 結構 - CREATE TABLE IF NOT EXISTS `power_station_operation_personnel` ( - `Id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `Deleted` tinyint(4) NOT NULL DEFAULT 0, - `PowerStationId` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '電站編號', - `UserId` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '人員編號', - `CreatedBy` int(10) unsigned NOT NULL COMMENT '建立者', - `CreatedAt` timestamp NOT NULL DEFAULT current_timestamp() COMMENT '建立時間', - PRIMARY KEY (`Id`), - KEY `IDX_01` (`Deleted`), - KEY `IDX_02` (`PowerStationId`,`UserId`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='電站運維人員'; + -- 傾印 資料表 power_station_image 結構 + CREATE TABLE IF NOT EXISTS `power_station_image` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `Deleted` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否刪除, 0:否 1:是', + `PowerStationId` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '電站編號', + `IsMainDisplay` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否主要顯示圖片, 0:否 1:是', + `Image` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '圖片檔名', + `CreatedBy` int(10) unsigned NOT NULL COMMENT '建立者', + `CreatedAt` timestamp NOT NULL DEFAULT current_timestamp() COMMENT '建立時間', + `UpdatedBy` int(10) unsigned DEFAULT NULL COMMENT '修改者', + `UpdatedAt` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp() COMMENT '修改時間', + PRIMARY KEY (`Id`), + KEY `IDX_01` (`Deleted`,`IsMainDisplay`,`PowerStationId`) USING BTREE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='電站資料'; - -- 傾印 資料表 power_station_single_line_diagram 結構 - CREATE TABLE IF NOT EXISTS `power_station_single_line_diagram` ( - `Id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `Deleted` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否刪除, 0:否 1:是', - `PowerStationId` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '電站編號', - ` image` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '圖片檔名', - `CreatedBy` int(10) unsigned NOT NULL COMMENT '建立者', - `CreatedAt` timestamp NOT NULL DEFAULT current_timestamp() COMMENT '建立時間', - PRIMARY KEY (`Id`), - KEY `IDX_01` (`Deleted`,`PowerStationId`) USING BTREE - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='電站單線圖'; + -- 傾印 資料表 power_station_operation_personnel 結構 + CREATE TABLE IF NOT EXISTS `power_station_operation_personnel` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `Deleted` tinyint(4) NOT NULL DEFAULT 0, + `PowerStationId` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '電站編號', + `UserId` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '人員編號', + `CreatedBy` int(10) unsigned NOT NULL COMMENT '建立者', + `CreatedAt` timestamp NOT NULL DEFAULT current_timestamp() COMMENT '建立時間', + PRIMARY KEY (`Id`), + KEY `IDX_01` (`Deleted`), + KEY `IDX_02` (`PowerStationId`,`UserId`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='電站運維人員'; + + -- 傾印 資料表 power_station_single_line_diagram 結構 + CREATE TABLE IF NOT EXISTS `power_station_single_line_diagram` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `Deleted` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否刪除, 0:否 1:是', + `PowerStationId` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '電站編號', + `Image` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '圖片檔名', + `CreatedBy` int(10) unsigned NOT NULL COMMENT '建立者', + `CreatedAt` timestamp NOT NULL DEFAULT current_timestamp() COMMENT '建立時間', + PRIMARY KEY (`Id`), + KEY `IDX_01` (`Deleted`,`PowerStationId`) USING BTREE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='電站單線圖'; "; await conn.ExecuteAsync(sql, trans); diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index fb0c6d3..68141b0 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -32,7 +32,7 @@ namespace SolarPower.Repository.Implement try { var sql = $"SELECT Id AS Value, Name AS Text FROM city"; - + result = (await conn.QueryAsync(sql)).ToList(); } catch (Exception exception) @@ -116,7 +116,7 @@ namespace SolarPower.Repository.Implement } /// - /// 取得縣市地區代碼 + /// 透過地區編號,取得縣市地區代碼 /// /// /// @@ -186,14 +186,17 @@ namespace SolarPower.Repository.Implement LEFT JOIN user u ON ps.CreatedBy = u.Id WHERE ps.Deleted = 0 AND ps.Id = @Id"; - result = await conn.QueryFirstOrDefaultAsync(sql, new { Id = id}); + result = await conn.QueryFirstOrDefaultAsync(sql, new { Id = id }); - if(result!= null) + if (result != null) { - var sql_operation_personnel = @"SELECT UserId FROM power_station_operation_personnel op WHERE Deleted = 0 AND op.PowerStationId = @PowerStationId"; + + var db_name = result.SiteDB; + + var sql_operation_personnel = @$"SELECT UserId FROM {db_name}.power_station_operation_personnel op WHERE Deleted = 0 AND op.PowerStationId = @PowerStationId"; result.OperationPersonnelIds = (await conn.QueryAsync(sql_operation_personnel, new { PowerStationId = result.Id })).ToList(); - var sql_land_building = @$"SELECT lb.*, u.Name AS CreatorName FROM land_building lb + var sql_land_building = @$"SELECT lb.*, u.Name AS CreatorName FROM {db_name}.land_building lb LEFT JOIN user u ON lb.CreatedBy = u.Id WHERE lb.Deleted = 0 AND PowerStationId = @PowerStationId"; result.LandBuildings = (await conn.QueryAsync(sql_land_building, new { PowerStationId = result.Id })).ToList(); @@ -212,11 +215,61 @@ namespace SolarPower.Repository.Implement } /// - /// 修改電站基本資訊 + /// 新增電站資料至 主、子資料庫 /// /// + /// + /// /// - public async Task UpdatePowerStationInfo(UpdatePowerStationInfo entity, List properties) + public async Task AddOnePowerStationAsync(PowerStation entity, List properties, string db_name) + { + int id; int sub_count; + using (IDbConnection conn = _databaseHelper.GetConnection()) + { + conn.Open(); + using (var trans = conn.BeginTransaction()) + { + try + { + //新增資料 至主資料庫 + string sql = GenerateInsertQuery(properties); + + sql += "SELECT LAST_INSERT_ID();"; + + id = (await conn.QueryAsync(sql, entity, trans)).Single(); + + //新增資料 至子資料庫 + properties.Add("Id"); + entity.Id = id; + + string sub_sql = GenerateInsertQueryWithCustomDBNameAndTable(properties, db_name, tableName); + sub_count = await conn.ExecuteAsync(sub_sql, entity, trans); + + trans.Commit(); + } + catch (Exception exception) + { + trans.Rollback(); + throw exception; + } + finally + { + conn.Close(); + } + } + + return id; + } + } + + /// + /// 修改主、子資料庫電站基本資訊 + /// + /// + /// + /// + /// + public async Task UpdatePowerStationInfo(UpdatePowerStationInfo entity, List properties, string db_name) { using (IDbConnection conn = this._databaseHelper.GetConnection()) @@ -226,10 +279,14 @@ namespace SolarPower.Repository.Implement { try { + //修改主資料庫 var sql = GenerateUpdateQuery(properties); - await conn.ExecuteAsync(sql, entity, trans); + //修改子資料庫 + var sub_sql = GenerateUpdateQueryWithCustomDBNameAndTable(properties, db_name, tableName); + await conn.ExecuteAsync(sub_sql, entity, trans); + trans.Commit(); } catch (Exception exception) @@ -246,13 +303,14 @@ namespace SolarPower.Repository.Implement } /// - /// 修改能源局與台電資訊 + /// 修改主、子資料庫能源局與台電資訊 /// /// + /// + /// /// - public async Task UpdateBoETPCInfo(UpdateBoETPCInfo entity, List properties) + public async Task UpdateBoETPCInfo(UpdateBoETPCInfo entity, List properties, string db_name) { - using (IDbConnection conn = this._databaseHelper.GetConnection()) { conn.Open(); @@ -260,10 +318,14 @@ namespace SolarPower.Repository.Implement { try { + //修改主資料庫 var sql = GenerateUpdateQuery(properties); - await conn.ExecuteAsync(sql, entity, trans); + //修改子資料庫 + var sub_sql = GenerateUpdateQueryWithCustomDBNameAndTable(properties, db_name, tableName); + await conn.ExecuteAsync(sub_sql, entity, trans); + trans.Commit(); } catch (Exception exception) @@ -283,8 +345,9 @@ namespace SolarPower.Repository.Implement /// 新增 土地房屋資訊 /// /// + /// /// - public async Task GetOneLandBuildingInfo(int id) + public async Task GetOneLandBuildingInfo(int id, string db_name) { LandBuilding result; using (IDbConnection conn = _databaseHelper.GetConnection()) @@ -292,7 +355,7 @@ namespace SolarPower.Repository.Implement conn.Open(); try { - var sql = @"SELECT * FROM land_building WHERE Deleted =0 AND Id = @Id"; + var sql = @$"SELECT * FROM {db_name}.land_building WHERE Deleted = 0 AND Id = @Id"; result = await conn.QueryFirstOrDefaultAsync(sql, new { Id = id }); } @@ -314,8 +377,9 @@ namespace SolarPower.Repository.Implement /// /// /// + /// /// - public async Task AddOneLandBuildingInfo(LandBuilding entity, List properties) + public async Task AddOneLandBuildingInfo(LandBuilding entity, List properties, string db_name) { int id; using (IDbConnection conn = _databaseHelper.GetConnection()) @@ -323,7 +387,7 @@ namespace SolarPower.Repository.Implement conn.Open(); try { - string sql = GenerateInsertQueryWithCustomTable(properties, "land_building"); + string sql = GenerateInsertQueryWithCustomDBNameAndTable(properties, db_name, "land_building"); sql += "SELECT LAST_INSERT_ID();"; @@ -347,8 +411,9 @@ namespace SolarPower.Repository.Implement /// /// /// + /// /// - public async Task UpdateLandBuildingInfo(UpdateLandBuilding entity, List properties) + public async Task UpdateLandBuildingInfo(UpdateLandBuilding entity, List properties, string db_name) { using (IDbConnection conn = this._databaseHelper.GetConnection()) { @@ -357,7 +422,7 @@ namespace SolarPower.Repository.Implement { try { - var sql = GenerateUpdateQueryWithCustomTable(properties, "land_building"); + var sql = GenerateUpdateQueryWithCustomDBNameAndTable(properties, db_name, "land_building"); await conn.ExecuteAsync(sql, entity, trans); @@ -380,8 +445,9 @@ namespace SolarPower.Repository.Implement /// 軟刪除土地房屋資訊 /// /// + /// /// - public async Task DeleteOneLandBuildingInfo(int id) + public async Task DeleteOneLandBuildingInfo(int id, string db_name) { using (IDbConnection conn = this._databaseHelper.GetConnection()) { @@ -390,7 +456,7 @@ namespace SolarPower.Repository.Implement { try { - var sql = $"UPDATE land_building SET deleted = 1 WHERE id = @Id"; + var sql = $"UPDATE {db_name}.land_building SET Deleted = 1 WHERE Id = @Id"; await conn.ExecuteAsync(sql, new { Id = id }, trans); @@ -414,8 +480,9 @@ namespace SolarPower.Repository.Implement /// /// /// + /// /// - public async Task AddOperation(OperationInfo operation, List properties) + public async Task AddOperation(OperationInfo operation, List properties, string db_name) { using (IDbConnection conn = _databaseHelper.GetConnection()) { @@ -423,7 +490,7 @@ namespace SolarPower.Repository.Implement conn.Open(); try { - string sql = GenerateInsertQueryWithCustomTable(properties, "operation_firm"); + string sql = GenerateInsertQueryWithCustomDBNameAndTable(properties, db_name, "operation_firm"); count = await conn.ExecuteAsync(sql, operation); @@ -440,24 +507,34 @@ namespace SolarPower.Repository.Implement return count; } } + /// /// 運維DataTable /// /// + /// /// - public async Task> OperationTable (int stationId) + public async Task> OperationTable(int stationId, string db_name) { - + using (IDbConnection conn = _databaseHelper.GetConnection()) { List operation = new List(); conn.Open(); try { - string sql = @$"SELECT operation_firm.Name, + string sql = @$"SELECT + operation_firm.Name, operation_firm.PowerStationId, - operation_firm.Id,operation_firm.ContactPerson,operation_firm.Phone,operation_firm.Email,user.Name AS CreatedName,operation_firm.CreatedAt,operation_firm.Type - FROM operation_firm LEFT JOIN user ON operation_firm.CreatedBy = user.id WHERE operation_firm.Deleted = 0 AND operation_firm.PowerStationId = @StationId"; + operation_firm.Id, + operation_firm.ContactPerson, + operation_firm.Phone, + operation_firm.Email, + user.Name AS CreatedName, + operation_firm.CreatedAt,operation_firm.Type + FROM {db_name}.operation_firm + LEFT JOIN user ON operation_firm.CreatedBy = user.id + WHERE operation_firm.Deleted = 0 AND operation_firm.PowerStationId = @StationId"; operation = (await conn.QueryAsync(sql, new { StationId = stationId })).ToList(); } @@ -476,8 +553,9 @@ namespace SolarPower.Repository.Implement /// 選取單一運維 /// /// + /// /// - public async Task OneOperationInfo (int id) + public async Task OneOperationInfo(int id, string db_name) { using (IDbConnection conn = _databaseHelper.GetConnection()) { @@ -485,7 +563,7 @@ namespace SolarPower.Repository.Implement conn.Open(); try { - string sql = @$"SELECT * FROM operation_firm WHERE Id = @Id"; + string sql = @$"SELECT * FROM {db_name}.operation_firm WHERE Id = @Id"; operation = await conn.QueryFirstOrDefaultAsync(sql, new { Id = id }); } @@ -500,30 +578,23 @@ namespace SolarPower.Repository.Implement return operation; } } + /// /// 更新運維 /// /// /// + /// /// - public async Task UpdateOperation(OperationInfo operation , List properties) + public async Task UpdateOperation(OperationInfo operation, List properties, string db_name) { using IDbConnection conn = _databaseHelper.GetConnection(); conn.Open(); var trans = conn.BeginTransaction(); try { - var updateQuery = new StringBuilder($"UPDATE operation_firm SET "); - properties.ForEach(property => - { - if (!property.Equals("Id")) - { - updateQuery.Append($"{property}=@{property},"); - } - }); - updateQuery.Remove(updateQuery.Length - 1, 1); //remove last comma - updateQuery.Append(" WHERE id = @Id"); - await conn.ExecuteAsync(updateQuery.ToString(), operation, trans); + var sql = GenerateUpdateQueryWithCustomDBNameAndTable(properties, db_name, "operation_firm"); + await conn.ExecuteAsync(sql, operation, trans); trans.Commit(); } catch (Exception exception) @@ -549,9 +620,9 @@ namespace SolarPower.Repository.Implement try { string sql = @$"SELECT * FROM variable WHERE name = @name"; - var json = await conn.QueryFirstOrDefaultAsync(sql, new { name = "Type" }); + var json = await conn.QueryFirstOrDefaultAsync(sql, new { name = "Type" }); Root jsonfor = JsonSerializer.Deserialize(json.value); - foreach(Models.PowerStation.Type a in jsonfor.Type) + foreach (Models.PowerStation.Type a in jsonfor.Type) { UserSelectItemList KeyValue = new UserSelectItemList { @@ -598,7 +669,7 @@ namespace SolarPower.Repository.Implement { conn.Close(); } - + } /// /// 修改裝置資料 @@ -816,8 +887,9 @@ namespace SolarPower.Repository.Implement /// 透過電站編號,取得該電站的運維人員編號 /// /// + /// /// - public async Task> GetOperationPersonnelIdsByPowerStatioinId(int powerStationId) + public async Task> GetOperationPersonnelIdsByPowerStatioinId(int powerStationId, string db_name) { List result; using (IDbConnection conn = this._databaseHelper.GetConnection()) @@ -825,7 +897,7 @@ namespace SolarPower.Repository.Implement conn.Open(); try { - var sql = @$"SELECT UserId FROM power_station_operation_personnel WHERE Deleted = 0 AND PowerStationId = @PowerStationId"; + var sql = @$"SELECT UserId FROM {db_name}.power_station_operation_personnel WHERE Deleted = 0 AND PowerStationId = @PowerStationId"; result = (await conn.QueryAsync(sql, new { PowerStationId = powerStationId })).ToList(); } @@ -846,8 +918,9 @@ namespace SolarPower.Repository.Implement /// /// /// + /// /// - public async Task AddOperationPersonnelAsync(List entity, List properties) + public async Task AddOperationPersonnelAsync(List entity, List properties, string db_name) { int count; using (IDbConnection conn = _databaseHelper.GetConnection()) @@ -855,7 +928,7 @@ namespace SolarPower.Repository.Implement conn.Open(); try { - string sql = GenerateInsertQueryWithCustomTable(properties, "power_station_operation_personnel"); + string sql = GenerateInsertQueryWithCustomDBNameAndTable(properties, db_name, "power_station_operation_personnel"); count = await conn.ExecuteAsync(sql, entity); } @@ -876,8 +949,9 @@ namespace SolarPower.Repository.Implement /// 軟刪除電站運維人員 /// /// + /// /// - public async Task DeleteOperationPersonnel(List operationPersonnels) + public async Task DeleteOperationPersonnel(List operationPersonnels, string db_name) { using (IDbConnection conn = this._databaseHelper.GetConnection()) { @@ -886,7 +960,7 @@ namespace SolarPower.Repository.Implement { try { - var sql = $"UPDATE power_station_operation_personnel SET deleted = 1 WHERE PowerStationId = @PowerStationId AND UserId = @UserId"; + var sql = $"UPDATE {db_name}.power_station_operation_personnel SET Deleted = 1 WHERE PowerStationId = @PowerStationId AND UserId = @UserId"; await conn.ExecuteAsync(sql, operationPersonnels, trans); @@ -909,27 +983,33 @@ namespace SolarPower.Repository.Implement /// 電站管理 新增電站圖片 /// /// - /// + /// /// - public async Task AddPowerStationImageAsync(List entity, List properties) + public async Task AddPowerStationImageAsync(List entity, List properties, string db_name) { int count; using (IDbConnection conn = _databaseHelper.GetConnection()) { conn.Open(); - try + using (var trans = conn.BeginTransaction()) { - string sql = GenerateInsertQueryWithCustomTable(properties, "power_station_image"); + try + { + string sql = GenerateInsertQueryWithCustomDBNameAndTable(properties, db_name, "power_station_image"); - count = await conn.ExecuteAsync(sql, entity); - } - catch (Exception exception) - { - throw exception; - } - finally - { - conn.Close(); + count = await conn.ExecuteAsync(sql, entity, trans); + + trans.Commit(); + } + catch (Exception exception) + { + trans.Rollback(); + throw exception; + } + finally + { + conn.Close(); + } } return count; @@ -940,15 +1020,16 @@ namespace SolarPower.Repository.Implement /// 電站管理 取得所有電站圖片的資料 /// /// + /// /// - public async Task> GetAllPowerStationImageAsync(int powerStationId) + public async Task> GetAllPowerStationImageAsync(int powerStationId, string db_name) { List result; using (IDbConnection conn = this._databaseHelper.GetConnection()) { try { - var sql = $"SELECT * FROM power_station_image WHERE Deleted = 0 AND PowerStationId = @PowerStationId"; + var sql = $"SELECT * FROM {db_name}.power_station_image WHERE Deleted = 0 AND PowerStationId = @PowerStationId"; result = (await conn.QueryAsync(sql, new { PowerStationId = powerStationId })).ToList(); } @@ -964,15 +1045,16 @@ namespace SolarPower.Repository.Implement /// 電站管理 取得單一電站圖片的資料 /// /// + /// /// - public async Task GetOnePowerStationImageAsync(int id) + public async Task GetOnePowerStationImageAsync(int id, string db_name) { PowerStationImage result; using (IDbConnection conn = this._databaseHelper.GetConnection()) { try { - var sql = $"SELECT * FROM power_station_image WHERE Deleted = 0 AND Id = @Id"; + var sql = $"SELECT * FROM {db_name}.power_station_image WHERE Deleted = 0 AND Id = @Id"; result = await conn.QueryFirstOrDefaultAsync(sql, new { Id = id }); } @@ -988,8 +1070,9 @@ namespace SolarPower.Repository.Implement /// 軟刪除 單一電站圖片 /// /// + /// /// - public async Task DeleteOnePowerStationImage(int id) + public async Task DeleteOnePowerStationImage(int id, string db_name) { using (IDbConnection conn = this._databaseHelper.GetConnection()) { @@ -998,7 +1081,7 @@ namespace SolarPower.Repository.Implement { try { - var sql = $"UPDATE power_station_image SET deleted = 1 WHERE id = @Id"; + var sql = $"UPDATE {db_name}.power_station_image SET Deleted = 1 WHERE id = @Id"; await conn.ExecuteAsync(sql, new { Id = id }, trans); @@ -1021,15 +1104,16 @@ namespace SolarPower.Repository.Implement /// 電站管理 取得主要卡片顯示圖 /// /// + /// /// - public async Task GetMainDisplayAsync(int powerStationId) + public async Task GetMainDisplayAsync(int powerStationId, string db_name) { PowerStationImage result; using (IDbConnection conn = this._databaseHelper.GetConnection()) { try { - var sql = $"SELECT * FROM power_station_image WHERE Deleted = 0 AND IsMainDisplay = 1 AND PowerStationId = @PowerStationId"; + var sql = $"SELECT * FROM {db_name}.power_station_image WHERE Deleted = 0 AND IsMainDisplay = 1 AND PowerStationId = @PowerStationId"; result = await conn.QueryFirstOrDefaultAsync(sql, new { PowerStationId = powerStationId }); } @@ -1046,8 +1130,9 @@ namespace SolarPower.Repository.Implement /// /// /// + /// /// - public async Task UpdatePowerStationImage(UpdataPowerStationImage image, List properties) + public async Task UpdatePowerStationImage(UpdataPowerStationImage image, List properties, string db_name) { using (IDbConnection conn = this._databaseHelper.GetConnection()) { @@ -1056,7 +1141,7 @@ namespace SolarPower.Repository.Implement { try { - var sql = GenerateUpdateQueryWithCustomTable(properties, "power_station_image"); + var sql = GenerateUpdateQueryWithCustomDBNameAndTable(properties, db_name, "power_station_image"); await conn.ExecuteAsync(sql, image, trans); @@ -1080,8 +1165,9 @@ namespace SolarPower.Repository.Implement /// /// /// + /// /// - public async Task AddPowerStationSingleLineAsync(List entity, List properties) + public async Task AddPowerStationSingleLineAsync(List entity, List properties, string db_name) { int count; using (IDbConnection conn = _databaseHelper.GetConnection()) @@ -1089,7 +1175,7 @@ namespace SolarPower.Repository.Implement conn.Open(); try { - string sql = GenerateInsertQueryWithCustomTable(properties, "power_station_single_line_diagram"); + string sql = GenerateInsertQueryWithCustomDBNameAndTable(properties, db_name, "power_station_single_line_diagram"); count = await conn.ExecuteAsync(sql, entity); } @@ -1110,15 +1196,16 @@ namespace SolarPower.Repository.Implement /// 電站管理 取得所有單線圖的資料 /// /// + /// /// - public async Task> GetAllPowerStationSingleLineAsync(int powerStationId) + public async Task> GetAllPowerStationSingleLineAsync(int powerStationId, string db_name) { List result; using (IDbConnection conn = this._databaseHelper.GetConnection()) { try { - var sql = $"SELECT * FROM power_station_single_line_diagram WHERE Deleted = 0 AND PowerStationId = @PowerStationId"; + var sql = $"SELECT * FROM {db_name}.power_station_single_line_diagram WHERE Deleted = 0 AND PowerStationId = @PowerStationId"; result = (await conn.QueryAsync(sql, new { PowerStationId = powerStationId })).ToList(); } @@ -1134,15 +1221,16 @@ namespace SolarPower.Repository.Implement /// 電站管理 取得單一單線圖的資料 /// /// + /// /// - public async Task GetOnePowerStationSingleLineAsync(int id) + public async Task GetOnePowerStationSingleLineAsync(int id, string db_name) { PowerStationSingleLine result; using (IDbConnection conn = this._databaseHelper.GetConnection()) { try { - var sql = $"SELECT * FROM power_station_single_line_diagram WHERE Deleted = 0 AND Id = @Id"; + var sql = $"SELECT * FROM {db_name}.power_station_single_line_diagram WHERE Deleted = 0 AND Id = @Id"; result = await conn.QueryFirstOrDefaultAsync(sql, new { Id = id }); } @@ -1158,8 +1246,9 @@ namespace SolarPower.Repository.Implement /// 軟刪除 單一單線圖 /// /// + /// /// - public async Task DeleteOnePowerStationSingleLine(int id) + public async Task DeleteOnePowerStationSingleLine(int id, string db_name) { using (IDbConnection conn = this._databaseHelper.GetConnection()) { @@ -1168,7 +1257,7 @@ namespace SolarPower.Repository.Implement { try { - var sql = $"UPDATE power_station_single_line_diagram SET deleted = 1 WHERE id = @Id"; + var sql = $"UPDATE {db_name}.power_station_single_line_diagram SET deleted = 1 WHERE id = @Id"; await conn.ExecuteAsync(sql, new { Id = id }, trans); diff --git a/SolarPower/Repository/Implement/RepositoryBase.cs b/SolarPower/Repository/Implement/RepositoryBase.cs index 7f20ed9..93baa13 100644 --- a/SolarPower/Repository/Implement/RepositoryBase.cs +++ b/SolarPower/Repository/Implement/RepositoryBase.cs @@ -1,6 +1,7 @@  using Dapper; using SolarPower.Helper; +using SolarPower.Models; using SolarPower.Repository.Interface; using System; using System.Collections.Generic; @@ -36,19 +37,25 @@ namespace SolarPower.Repository.Implement using (IDbConnection conn = _databaseHelper.GetConnection()) { conn.Open(); - try + using (var trans = conn.BeginTransaction()) { - string sql = GenerateInsertQuery(properties); + try + { + string sql = GenerateInsertQuery(properties); - count = await conn.ExecuteAsync(sql, entity); - } - catch (Exception exception) - { - throw exception; - } - finally - { - conn.Close(); + count = await conn.ExecuteAsync(sql, entity, trans); + + trans.Commit(); + } + catch (Exception exception) + { + trans.Rollback(); + throw exception; + } + finally + { + conn.Close(); + } } return count; @@ -67,27 +74,33 @@ namespace SolarPower.Repository.Implement using (IDbConnection conn = _databaseHelper.GetConnection()) { conn.Open(); - try + using (var trans = conn.BeginTransaction()) { - string sql = GenerateInsertQuery(properties); + try + { + string sql = GenerateInsertQuery(properties); - sql += "SELECT LAST_INSERT_ID();"; + sql += "SELECT LAST_INSERT_ID();"; - id = (await conn.QueryAsync(sql, entity)).Single(); - } - catch (Exception exception) - { - throw exception; - } - finally - { - conn.Close(); + id = (await conn.QueryAsync(sql, entity, trans)).Single(); + + trans.Commit(); + } + catch (Exception exception) + { + trans.Rollback(); + throw exception; + } + finally + { + conn.Close(); + } } return id; } } - + /// /// 透過Id,軟刪除單一筆資料 @@ -123,12 +136,13 @@ namespace SolarPower.Repository.Implement } } /// - /// 透過Id,軟刪除單一筆資料(不同資料表) + /// 透過Id、db_name、table_name,刪除指定的資料庫之資料表的一筆資料 /// /// - /// + /// + /// /// - public virtual async Task DeleteOneOtherTable(int id,string table_name) + public virtual async Task DeleteOneByIdWithCustomDBNameAndTable(int id, string db_name, string table_name) { using (IDbConnection conn = this._databaseHelper.GetConnection()) { @@ -137,7 +151,7 @@ namespace SolarPower.Repository.Implement { try { - var sql = $"UPDATE {table_name} SET deleted = 1 WHERE id = @Id"; + var sql = $"UPDATE {db_name}.{table_name} SET Deleted = 1 WHERE Id = @Id"; await conn.ExecuteAsync(sql, new { Id = id }, trans); @@ -152,7 +166,6 @@ namespace SolarPower.Repository.Implement { conn.Close(); } - } } } @@ -270,6 +283,56 @@ namespace SolarPower.Repository.Implement } } + /// + /// 透過name list,取得指定的多筆設定變數 + /// + /// + /// 回傳為字典格式 + public virtual async Task> GetDictVariableByNames(List names) + { + Dictionary dict; + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + try + { + var sql = $"SELECT * FROM variable WHERE Name IN @Names"; + + var result = (await conn.QueryAsync(sql, new { Names = names })).ToList(); + + dict = result.ToDictionary(x => x.Name, x => x.Value); + } + catch (Exception exception) + { + throw exception; + } + return dict; + } + } + + /// + /// 透過name,取得單一設定變數 + /// + /// + /// + public virtual async Task GetOneVariableByName(string name) + { + string result; + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + try + { + var sql = $"SELECT * FROM variable WHERE Name = @Name"; + + result = await conn.QueryFirstOrDefaultAsync(sql, new { Name = name }); + } + catch (Exception exception) + { + throw exception; + } + return result; + } + } + /// /// 產生Insert語句 /// @@ -303,7 +366,7 @@ namespace SolarPower.Repository.Implement /// protected string GenerateInsertQueryWithCustomTable(List properties, string table_name) { - var insertQuery = new StringBuilder($"INSERT INTO {table_name} "); + var insertQuery = new StringBuilder($"INSERT INTO `{table_name}` "); insertQuery.Append("("); @@ -322,6 +385,34 @@ namespace SolarPower.Repository.Implement return insertQuery.ToString(); } + /// + /// 產生Insert語句,可選擇自己要加入資料庫及資料表 + /// + /// + /// 欲新增至目標資料庫 + /// 欲新增至目標資料表 + /// + protected string GenerateInsertQueryWithCustomDBNameAndTable(List properties, string db_name, string table_name) + { + var insertQuery = new StringBuilder($"INSERT INTO `{db_name}`.`{table_name}` "); + + insertQuery.Append("("); + + properties.ForEach(prop => { insertQuery.Append($"`{table_name}`.{prop},"); }); + + insertQuery + .Remove(insertQuery.Length - 1, 1) + .Append(") VALUES ("); + + properties.ForEach(prop => { insertQuery.Append($"@{prop},"); }); + + insertQuery + .Remove(insertQuery.Length - 1, 1) + .Append(");"); + + return insertQuery.ToString(); + } + /// /// 產生Update語句 /// @@ -368,5 +459,23 @@ namespace SolarPower.Repository.Implement return updateQuery.ToString(); } + + protected string GenerateUpdateQueryWithCustomDBNameAndTable(List properties, string db_name, string table_name) + { + var updateQuery = new StringBuilder($"UPDATE {db_name}.{table_name} SET "); + + properties.ForEach(property => + { + if (!property.Equals("Id")) + { + updateQuery.Append($"{table_name}.{property}=@{property},"); + } + }); + + updateQuery.Remove(updateQuery.Length - 1, 1); //remove last comma + updateQuery.Append(" WHERE id = @Id"); + + return updateQuery.ToString(); + } } } diff --git a/SolarPower/Repository/Interface/IPowerStationRepository.cs b/SolarPower/Repository/Interface/IPowerStationRepository.cs index 73c0ddc..ffcb98a 100644 --- a/SolarPower/Repository/Interface/IPowerStationRepository.cs +++ b/SolarPower/Repository/Interface/IPowerStationRepository.cs @@ -54,27 +54,39 @@ namespace SolarPower.Repository.Interface Task GetLastSerialNumberByCityAreaIdAsync(int cityId, int areaId); /// - /// 修改電站基本資訊 + /// 新增電站資料至 主、子資料庫 /// /// /// + /// /// - Task UpdatePowerStationInfo(UpdatePowerStationInfo entity, List properties); + Task AddOnePowerStationAsync(PowerStation entity, List properties, string db_name); /// - /// 修改能源局與台電資訊 + /// 修改主、子資料庫電站基本資訊 /// /// /// + /// /// - Task UpdateBoETPCInfo(UpdateBoETPCInfo entity, List properties); + Task UpdatePowerStationInfo(UpdatePowerStationInfo entity, List properties, string db_name); + + /// + /// 修改主、子資料庫能源局與台電資訊 + /// + /// + /// + /// + /// + Task UpdateBoETPCInfo(UpdateBoETPCInfo entity, List properties, string db_name); /// /// 取得 土地房屋資訊 /// /// + /// /// - Task GetOneLandBuildingInfo(int id); + Task GetOneLandBuildingInfo(int id, string db_name); /// /// 新增 土地房屋資訊 @@ -82,53 +94,65 @@ namespace SolarPower.Repository.Interface /// /// /// - Task AddOneLandBuildingInfo(LandBuilding entity, List properties); + Task AddOneLandBuildingInfo(LandBuilding entity, List properties, string db_name); /// /// 更新 土地房屋資訊 /// /// /// + /// /// - Task UpdateLandBuildingInfo(UpdateLandBuilding entity, List properties); + Task UpdateLandBuildingInfo(UpdateLandBuilding entity, List properties, string db_name); /// /// 軟刪除土地房屋資訊 /// /// + /// /// - Task DeleteOneLandBuildingInfo(int id); + Task DeleteOneLandBuildingInfo(int id, string db_name); + /// /// 新增運維 /// /// /// + /// /// - Task AddOperation(OperationInfo operation, List properties); + Task AddOperation(OperationInfo operation, List properties, string db_name); + /// /// 運維dataTable /// /// + /// /// - Task> OperationTable (int stationId); + Task> OperationTable (int stationId, string db_name); + /// /// 取一筆運維 /// /// + /// /// - Task OneOperationInfo (int stationId); + Task OneOperationInfo (int stationId, string db_name); + /// /// 更新運維 /// /// /// + /// /// - Task UpdateOperation(OperationInfo operation, List properties); + Task UpdateOperation(OperationInfo operation, List properties, string db_name); + /// /// 裝置類型下拉式選單 /// /// Task> DeviceType(); + /// /// 新增 裝置 /// @@ -155,12 +179,14 @@ namespace SolarPower.Repository.Interface /// /// Task> ExceptionTable(int stationId); + /// /// 取單一筆DeviceInfo /// /// /// Task OneDeviceInfo(int id); + /// /// 新增 異常設定 /// @@ -168,12 +194,14 @@ namespace SolarPower.Repository.Interface /// /// Task AddException(ExceptionModal Exception, List properties); + /// /// 取一筆異常設定 /// /// /// Task OneException(int id); + /// /// 更新異常設定 /// @@ -181,6 +209,7 @@ namespace SolarPower.Repository.Interface /// /// Task UpdateException(ExceptionModal Exception, List properties); + /// /// 取最後一個設備流水號 /// @@ -193,95 +222,108 @@ namespace SolarPower.Repository.Interface /// 透過電站編號,取得該電站的運維人員編號 /// /// + /// /// - Task> GetOperationPersonnelIdsByPowerStatioinId(int powerStationId); + Task> GetOperationPersonnelIdsByPowerStatioinId(int powerStationId, string db_name); /// /// 新增電站運維人員 /// /// /// + /// /// - Task AddOperationPersonnelAsync(List entity, List properties); + Task AddOperationPersonnelAsync(List entity, List properties, string db_name); /// /// 軟刪除電站運維人員 /// /// + /// /// - Task DeleteOperationPersonnel(List operationPersonnels); + Task DeleteOperationPersonnel(List operationPersonnels, string db_name); /// /// 電站管理 新增電站圖片 /// /// /// + /// /// - Task AddPowerStationImageAsync(List entity, List properties); + Task AddPowerStationImageAsync(List entity, List properties, string db_name); /// /// 電站管理 取得所有電站圖片的資料 /// /// + /// /// - Task> GetAllPowerStationImageAsync(int powerStationId); + Task> GetAllPowerStationImageAsync(int powerStationId, string db_name); /// /// 電站管理 取得單一電站圖片的資料 /// /// + /// /// - Task GetOnePowerStationImageAsync(int id); + Task GetOnePowerStationImageAsync(int id, string db_name); /// /// 軟刪除 單一電站圖片 /// /// + /// /// - Task DeleteOnePowerStationImage(int id); + Task DeleteOnePowerStationImage(int id, string db_name); /// /// 電站管理 取得主要卡片顯示圖 /// /// + /// /// - Task GetMainDisplayAsync(int powerStationId); + Task GetMainDisplayAsync(int powerStationId, string db_name); /// /// 電站管理 更新上傳圖片 /// /// /// + /// /// - Task UpdatePowerStationImage(UpdataPowerStationImage image, List properties); + Task UpdatePowerStationImage(UpdataPowerStationImage image, List properties, string db_name); /// /// 電站管理 新增單線圖 /// /// /// + /// /// - Task AddPowerStationSingleLineAsync(List entity, List properties); + Task AddPowerStationSingleLineAsync(List entity, List properties, string db_name); /// /// 電站管理 取得所有單線圖的資料 /// /// + /// /// - Task> GetAllPowerStationSingleLineAsync(int powerStationId); + Task> GetAllPowerStationSingleLineAsync(int powerStationId, string db_name); /// /// 電站管理 取得單一單線圖的資料 /// /// + /// /// - Task GetOnePowerStationSingleLineAsync(int id); + Task GetOnePowerStationSingleLineAsync(int id, string db_name); /// /// 軟刪除 單一單線圖 /// /// + /// /// - Task DeleteOnePowerStationSingleLine(int id); + Task DeleteOnePowerStationSingleLine(int id, string db_name); } } diff --git a/SolarPower/Repository/Interface/IRepositoryBase.cs b/SolarPower/Repository/Interface/IRepositoryBase.cs index 42f719d..1d119ab 100644 --- a/SolarPower/Repository/Interface/IRepositoryBase.cs +++ b/SolarPower/Repository/Interface/IRepositoryBase.cs @@ -36,7 +36,6 @@ namespace SolarPower.Repository.Interface /// Task AddOneAsync(T entity, List properties); - /// /// 修改資料 /// @@ -58,13 +57,29 @@ namespace SolarPower.Repository.Interface /// /// Task PurgeOneAsync(int id); + /// - /// 透過Id,軟刪除單一筆資料(不同資料表) + /// 透過Id、db_name、table_name,刪除指定的資料庫之資料表的一筆資料 /// /// - /// + /// + /// /// - Task DeleteOneOtherTable(int id, string tablename); + Task DeleteOneByIdWithCustomDBNameAndTable(int id, string db_name, string table_name); + + /// + /// 透過name list,取得指定的多筆設定變數 + /// + /// + /// 回傳為字典格式 + Task> GetDictVariableByNames(List names); + + /// + /// 透過name,取得單一設定變數 + /// + /// + /// + Task GetOneVariableByName(string name); } } diff --git a/SolarPower/Views/Company/Index.cshtml b/SolarPower/Views/Company/Index.cshtml index 1744094..3048d38 100644 --- a/SolarPower/Views/Company/Index.cshtml +++ b/SolarPower/Views/Company/Index.cshtml @@ -1,7 +1,7 @@ @{ - ViewData["MainNum"] = "6"; - ViewData["SubNum"] = "2"; - ViewData["Title"] = "客戶公司管理"; + ViewData["MainNum"] = "7"; + ViewData["SubNum"] = "1"; + ViewData["Title"] = "公司管理"; } @using SolarPower.Models.Role @model RoleLayerEnum diff --git a/SolarPower/Views/PowerStation/Index.cshtml b/SolarPower/Views/PowerStation/Index.cshtml index e3c6b98..dba4d51 100644 --- a/SolarPower/Views/PowerStation/Index.cshtml +++ b/SolarPower/Views/PowerStation/Index.cshtml @@ -1,7 +1,7 @@ @{ - ViewData["MainNum"] = "6"; + ViewData["MainNum"] = "2"; ViewData["SubNum"] = "1"; - ViewData["Title"] = "電站資料管理"; + ViewData["Title"] = "電站管理"; }