diff --git a/SolarPower/Controllers/PowerStationController.cs b/SolarPower/Controllers/PowerStationController.cs index 77eaf36..540ee3f 100644 --- a/SolarPower/Controllers/PowerStationController.cs +++ b/SolarPower/Controllers/PowerStationController.cs @@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using SolarPower.Models; +using SolarPower.Models.PowerStation; using SolarPower.Models.User; using SolarPower.Repository.Interface; @@ -16,10 +17,14 @@ namespace SolarPower.Controllers public class PowerStationController : MyBaseController { private readonly IUserRepository userRepository; + private readonly IPowerStationRepository powerStationRepository; - public PowerStationController(IUserRepository userRepository) : base() + public PowerStationController( + IUserRepository userRepository, + IPowerStationRepository powerStationRepository) : base() { this.userRepository = userRepository; + this.powerStationRepository = powerStationRepository; } public IActionResult Index() { @@ -46,7 +51,7 @@ namespace SolarPower.Controllers ApiResult> apiResult = new ApiResult>(); try { - EDFunction edFunction = new EDFunction(); + EDFunction edFunction = new EDFunction(); var companyId= Convert.ToInt32(edFunction.AESDecrypt(HttpContext.Session.GetString("CompanyId"))); //將公司id透過AES解密 var userSelectItemLists = await userRepository.GetUserSelectOptionListAsync(companyId); @@ -62,5 +67,154 @@ namespace SolarPower.Controllers apiResult.Msg = errorCode.GetString(apiResult.Code); return apiResult; } + + /// + /// 取得單一電站基本資料 + /// + /// + /// + [HttpPost] + public async Task> GetOnePowerStation(int id) + { + ApiResult apiResult = new ApiResult(); + + PowerStation powerStation = null; + + try + { + powerStation = await powerStationRepository.GetOneAsync(id); + + if (powerStation == null) + { + apiResult.Code = "9992"; + apiResult.Msg = errorCode.GetString(apiResult.Code); + return apiResult; + } + else if (powerStation.Id != myUser.CompanyId) + { + apiResult.Code = "9993"; + apiResult.Msg = errorCode.GetString(apiResult.Code); + return apiResult; + } + + apiResult.Code = "0000"; + apiResult.Data = powerStation; + + } + 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; + } + + /// + /// 新增 / 修改 電站基本資料 + /// + /// + /// + public async Task> SavePowerStationInfo(PostPowerStationInfo post) + { + ApiResult apiResult = new ApiResult(); + + PowerStation powerStation = null; + + try + { + powerStation = await powerStationRepository.GetOneAsync(post.Id); + + if(powerStation == null) + { + if (post.Id != 0) + { + apiResult.Code = "9992"; + apiResult.Msg = errorCode.GetString(apiResult.Code); + return apiResult; + } + + #region 新增電站資訊 + powerStation = new PowerStation() { + CompanyId = myUser.CompanyId, + CityId = post.CityId, + AreaId = post.AreaId, + Address = post.Address, + Name = post.Name, + IsEscrow = post.IsEscrow, + EscrowName = post.EscrowName, + ElectricityMeterAt = post.ElectricityMeterAt, + EstimatedRecoveryTime = post.EstimatedRecoveryTime, + GeneratingCapacity = post.GeneratingCapacity, + PowerRate = post.PowerRate, + Coordinate = post.Coordinate, + InverterBrand = post.InverterBrand, + InverterProductModel = post.InverterProductModel, + InverterAmount = post.InverterAmount, + PhotovoltaicPanelBrand = post.PhotovoltaicPanelBrand, + PhotovoltaicPanelProductModel = post.PhotovoltaicPanelProductModel, + PhotovoltaicPanelSpecification = post.PhotovoltaicPanelSpecification, + PhotovoltaicPanelAmount = post.PhotovoltaicPanelAmount, + CreatedBy = myUser.Id + }; + + List properties = new List() + { + "CompanyId", + "CityId", + "AreaId", + "Address", + "Name", + "IsEscrow", + "EscrowName", + "ElectricityMeterAt", + "EstimatedRecoveryTime", + "GeneratingCapacity", + "PowerRate", + "Coordinate", + "InverterBrand", + "InverterProductModel", + "InverterAmount", + "PhotovoltaicPanelBrand", + "PhotovoltaicPanelProductModel", + "PhotovoltaicPanelSpecification", + "PhotovoltaicPanelAmount", + "CreatedBy", + }; + + var id = await powerStationRepository.AddOneAsync(powerStation, properties); + + apiResult.Data = id.ToString(); + #endregion + } + else + { + if(powerStation.CompanyId != myUser.CompanyId) + { + apiResult.Code = "9993"; + apiResult.Msg = errorCode.GetString(apiResult.Code); + return apiResult; + } + + + #region 修改電站資訊 + #endregion + } + + apiResult.Code = "0000"; + apiResult.Msg = "修改成功"; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + string json = System.Text.Json.JsonSerializer.Serialize(post); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + json); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + + return apiResult; + } } } diff --git a/SolarPower/Models/ErrorCode.cs b/SolarPower/Models/ErrorCode.cs index 248099b..46d7dfd 100644 --- a/SolarPower/Models/ErrorCode.cs +++ b/SolarPower/Models/ErrorCode.cs @@ -17,6 +17,7 @@ namespace SolarPower.Models { { "0000", "OK" }, { "0001", "傳入參數錯誤。" }, + { "9992", "查無該電站資訊"}, { "9993", "無此權限操作"}, { "9994", "查無該公司角色"}, { "9995", "該統一編號已被使用。" }, diff --git a/SolarPower/Models/PowerStation.cs b/SolarPower/Models/PowerStation.cs new file mode 100644 index 0000000..ac9c806 --- /dev/null +++ b/SolarPower/Models/PowerStation.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace SolarPower.Models.PowerStation +{ + public class PowerStation : Created + { + public int Id { get; set; } + public int CompanyId { get; set; } + public int CityId { get; set; } //縣市 + public int AreaId { get; set; } //地區 + public string Address { get; set; } //地址 + public string Name { get; set; } //名稱 + //public string Code { get; set; } + public byte IsEscrow { get; set; } //是否被代管 + public string EscrowName { get; set; } //被代管公司 + public string ElectricityMeterAt { get; set; } //台電掛錶日 + public int EstimatedRecoveryTime { get; set; } //預計回收年限 + public double GeneratingCapacity { get; set; } //發電容量 + public double PowerRate { get; set; } //授電費率 + public string Coordinate { get; set; } //座標 + public string InverterBrand { get; set; } //逆變器廠牌 + public string InverterProductModel { get; set; } //逆變器型號 + public int InverterAmount { get; set; } //逆變器數量 + public string PhotovoltaicPanelBrand { get; set; } //光電板廠牌 + public string PhotovoltaicPanelProductModel { get; set; } //光電板型號 + public string PhotovoltaicPanelSpecification { get; set; } //光電板規格 + public int PhotovoltaicPanelAmount { get; set; } //光電板規格 + public string BoEFile { get; set; } //能源局檔案 + public int BoEDiscountRate { get; set; } //能源局折扣率 + public string BoEDeviceRegisterNumber { get; set; } //能源局設備登記編號 + public int BoERentRatio { get; set; } //能源局租金比例 + public string TPCContractNumber { get; set; } //台電契約編號 + public string TPCContractAt { get; set; } //台電簽約日期 + public int TPCSellDeadline { get; set; } //台電售電期限(年) + public string TPCPurchaseElectricityAt { get; set; } //台電正式購電日 + public string TPCSellElectricityAt { get; set; } //台電正式售電日 + public List LandBuildings { get; set; } //土地房屋資料 + + } + + public class LandBuilding : Created + { + public int Id { get; set; } + public int PowerStationId { get; set; } + public string Address { get; set; } + public string LeaseNotarizationAt { get; set; } //租約公證日期 + public string Landowner { get; set; } //地主姓名 + public string Purpose { get; set; } //房屋用途 + public int LeaseRate { get; set; } //租金比例 + public string Coordinate { get; set; } //經緯度 + public string Phone { get; set; } //電話 + + } + + public class PostPowerStationInfo + { + public int Id { get; set; } + public int CityId { get; set; } //縣市 + public int AreaId { get; set; } //地區 + public string Address { get; set; } //地址 + public string Name { get; set; } //名稱 + //public string Code { get; set; } + public byte IsEscrow { get; set; } //是否被代管 + public string EscrowName { get; set; } //被代管公司 + public string ElectricityMeterAt { get; set; } //台電掛錶日 + public int EstimatedRecoveryTime { get; set; } //預計回收年限 + public double GeneratingCapacity { get; set; } //發電容量 + public double PowerRate { get; set; } //授電費率 + public string Coordinate { get; set; } //座標 + public string InverterBrand { get; set; } //逆變器廠牌 + public string InverterProductModel { get; set; } //逆變器型號 + public int InverterAmount { get; set; } //逆變器數量 + public string PhotovoltaicPanelBrand { get; set; } //光電板廠牌 + public string PhotovoltaicPanelProductModel { get; set; } //光電板型號 + public string PhotovoltaicPanelSpecification { get; set; } //光電板規格 + public int PhotovoltaicPanelAmount { get; set; } //光電板規格 + } +} diff --git a/SolarPower/Repository/Implement/CompanyRepository.cs b/SolarPower/Repository/Implement/CompanyRepository.cs index 4de37af..d495d7c 100644 --- a/SolarPower/Repository/Implement/CompanyRepository.cs +++ b/SolarPower/Repository/Implement/CompanyRepository.cs @@ -548,7 +548,7 @@ namespace SolarPower.Repository.Implement `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 '人員標號', + `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`), diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs new file mode 100644 index 0000000..c86f08e --- /dev/null +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -0,0 +1,52 @@ +using Dapper; +using SolarPower.Helper; +using SolarPower.Models.PowerStation; +using SolarPower.Repository.Interface; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Threading.Tasks; + +namespace SolarPower.Repository.Implement +{ + public class PowerStationRepository : RepositoryBase, IPowerStationRepository + { + public PowerStationRepository(IDatabaseHelper databaseHelper) : base(databaseHelper) + { + tableName = "power_station"; + } + + public override async Task GetOneAsync(int id) + { + //base.GetOneAsync(id); + + PowerStation 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(sql, new { Id = id}); + + if(result!= null) + { + var sql_land_building = @"SELECT * FROM land_building WHERE Deleted = 0 AND PowerStationId = @PowerStationId"; + result.LandBuildings = (await conn.QueryAsync(sql_land_building, new { PowerStationId = result.Id })).ToList(); + } + } + catch (Exception exception) + { + throw exception; + } + finally + { + conn.Close(); + } + return result; + } + } + } +} diff --git a/SolarPower/Repository/Interface/IPowerStationRepository.cs b/SolarPower/Repository/Interface/IPowerStationRepository.cs new file mode 100644 index 0000000..1673730 --- /dev/null +++ b/SolarPower/Repository/Interface/IPowerStationRepository.cs @@ -0,0 +1,12 @@ +using SolarPower.Models.PowerStation; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace SolarPower.Repository.Interface +{ + public interface IPowerStationRepository : IRepositoryBase + { + } +} diff --git a/SolarPower/Startup.cs b/SolarPower/Startup.cs index 7ecc97e..eaec18b 100644 --- a/SolarPower/Startup.cs +++ b/SolarPower/Startup.cs @@ -64,6 +64,7 @@ namespace SolarPower services.AddScoped(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); services.AddScoped(); #endregion diff --git a/SolarPower/Views/PowerStation/Index.cshtml b/SolarPower/Views/PowerStation/Index.cshtml index 39700bf..af3d5f2 100644 --- a/SolarPower/Views/PowerStation/Index.cshtml +++ b/SolarPower/Views/PowerStation/Index.cshtml @@ -50,7 +50,7 @@
- + 新增電站 diff --git a/SolarPower/Views/PowerStation/PowerStationEdit.cshtml b/SolarPower/Views/PowerStation/PowerStationEdit.cshtml index c7f1895..5a93d45 100644 --- a/SolarPower/Views/PowerStation/PowerStationEdit.cshtml +++ b/SolarPower/Views/PowerStation/PowerStationEdit.cshtml @@ -29,22 +29,22 @@
-
+
@Html.Partial("_StationInfo")
-
+
@Html.Partial("_DeviceSetting")
-
+
@Html.Partial("_Operation")
-
+
@Html.Partial("_UploadImage")
@@ -84,36 +84,76 @@
@section Scripts{ - } \ No newline at end of file diff --git a/SolarPower/Views/PowerStation/_StationInfo.cshtml b/SolarPower/Views/PowerStation/_StationInfo.cshtml index 70e9ae9..3e8d3e7 100644 --- a/SolarPower/Views/PowerStation/_StationInfo.cshtml +++ b/SolarPower/Views/PowerStation/_StationInfo.cshtml @@ -5,98 +5,133 @@
電站基本資料
-
-
-

地址: 

- +
+
+ +
+ +
-
-

電站名稱:

- +
+ +
+ +
- -
- -
- -
-
-
-

電站代碼: 

- - -
-
-

電站名稱:

- - -
-
-

是否為代管 :

-

-

- - -
-

-
-
-

台電掛錶日 

- - -
-
-

預計回收年限:

- - -
-
-

資料建立:

- +
+
+ +
-
-
-

電廠發電容量 
(kW)

- - +
+
+ +
+

PEP-NTP001

+ @**@ +
-
-

運維人員:

- +
+ +
+

薪族鋸成

+ +
-
-

被代管公司 :

- - +
+ +
+

+

+ + +
+

+
-
-

授電費率:

- - +
+ +
+

2021-02-29

+ +
-
-

座標:

- - +
+ +
+
+ +
+

20

+ +
-
-

建立時間:

+
+ +
+

123123

+ +
+
+
+ +
+

台電電

+ +
+
+
+ +
+ +
+
+
+
+
+ +
+

123123

+ +
+
+
+ +
+

座標:

+ +
+
+
+ +
+

野員新之助

+
+
+
+ +
+

YYYY-MM-DD

+
@@ -105,19 +140,19 @@
逆變器
-

廠牌:AUO

- - + +

AUO

+
-

型號 :PM060MW2_305

- - + +

PM060MW2_305

+
-

數量:400

- - + +

400

+
@@ -125,24 +160,24 @@
光電板
-

廠牌:ABLYTEK

- - + +

ABLYTEK

+
-

規格 :1640×992×40

- - + +

1640×992×40

+
-

數量:1116

- - + +

1116

+
-

型號 :6MN6A295

- - + +

6MN6A295

+
@@ -160,12 +195,15 @@
經濟部能源局與台電資訊
@@ -173,42 +211,90 @@
經濟部能源局
-
-

能源局同意檔案:台北市內湖區中山路一段1001號

+
+ +
-
-

折扣率 :2018-01-01

+
+ +
+

123123

+ +
-
-

能源局設備登記編號:25.0726625,121.5725953

+
+ +
+

123123

+ +
-
-

租金比例 (%) 10

+
+ +
+

123123

+ +
台電資訊
-
-

契約編號 鋼鐵人

+
+ +
+

123123

+ +
-
-

售電期限(年) 20

+
+ +
+

123123

+ +
-
-

正式購電日 2018-10-01

+
+ +
+

123123

+ +
-
-

簽約日期 0828-123456

+
+ +
+

123123

+ +
-
-

每期抄錶日 10日

+
+ +
+

123123

+ +
-
-

正式售電日 2018-10-01



-

資料建立:蜘蛛人

-

建立時間:2018-10-01 12:00

+
+ +
+

123123

+ +
+
+
+
+
+ +
+
+
+
+
diff --git a/SolarPower/Views/User/Index.cshtml b/SolarPower/Views/User/Index.cshtml index 7fe9b55..2f474cc 100644 --- a/SolarPower/Views/User/Index.cshtml +++ b/SolarPower/Views/User/Index.cshtml @@ -470,23 +470,6 @@ } } }); - - @*roleAuthTable.on('order.dt search.dt', function () { - roleAuthTable.column(0, { - search: 'applied', - order: 'applied' - }).nodes().each(function (cell, i) { - i = i + 1; - var page = roleAuthTable.page.info(); - - var pageno = page.page; - - var length = page.length; - - var columnIndex = (i + pageno * length); - cell.innerHTML = columnIndex; - }) - });*@ //#endregion //#region 角色未加入權限列表 DataTable