diff --git a/SolarPower/Controllers/AnalysisStationInfoController.cs b/SolarPower/Controllers/AnalysisStationInfoController.cs index 7ebccc2..2a53c51 100644 --- a/SolarPower/Controllers/AnalysisStationInfoController.cs +++ b/SolarPower/Controllers/AnalysisStationInfoController.cs @@ -2,6 +2,7 @@ using Microsoft.Extensions.Logging; using SolarPower.Models; using SolarPower.Models.PowerStation; +using SolarPower.Models.Role; using SolarPower.Repository.Interface; using System; using System.Collections.Generic; @@ -31,7 +32,7 @@ namespace SolarPower.Controllers try { var powerStations = new List(); - if (IsPlatformLayer(myUser.Role.Layer)) + if (myUser.Role.Layer == (int)RoleLayerEnum.PlatformAdmin) { powerStations = await powerStationRepository.GetAllAsync(); } diff --git a/SolarPower/Controllers/MapOverviewController.cs b/SolarPower/Controllers/MapOverviewController.cs index db1a316..d69950c 100644 --- a/SolarPower/Controllers/MapOverviewController.cs +++ b/SolarPower/Controllers/MapOverviewController.cs @@ -42,7 +42,8 @@ namespace SolarPower.Controllers try { - List powerStationIds = await powerStationRepository.GetPowerStationIdsByUserRole(myUser); + //List powerStationIds = await powerStationRepository.GetPowerStationIdsByUserRole(myUser); + List powerStationIds = myUser.PowerStationSummaries.SelectMany(x => x.MyPowerStations.Select(y=> y.PowerStationId)).ToList(); var overview = await overviewRepository.GetOverviewByPowerStationIds(powerStationIds); mapOverview.Today_kwh = overview.Today_kwh; mapOverview.Total_kwh = overview.Total_kwh; diff --git a/SolarPower/Controllers/MyBaseController.cs b/SolarPower/Controllers/MyBaseController.cs index 5a469f7..272ff57 100644 --- a/SolarPower/Controllers/MyBaseController.cs +++ b/SolarPower/Controllers/MyBaseController.cs @@ -122,6 +122,7 @@ namespace SolarPower.Controllers //取得當前使用者可以查看的電站 var myPowerStationSummaries = powerStationRepository.GetMyPowerStationSummary(myUser); + myUser.PowerStationSummaries = myPowerStationSummaries; ViewBag.myPowerStationSummaries = myPowerStationSummaries; if (controllerName == "PowerStation" && actionName == "Edit") diff --git a/SolarPower/Controllers/PowerStationController.cs b/SolarPower/Controllers/PowerStationController.cs index c07a2b6..389d759 100644 --- a/SolarPower/Controllers/PowerStationController.cs +++ b/SolarPower/Controllers/PowerStationController.cs @@ -248,6 +248,29 @@ namespace SolarPower.Controllers return apiResult; } + [HttpPost] + public async Task>> GetFirmSelectOptionList(int powerStationId) + { + ApiResult> apiResult = new ApiResult>(); + try + { + var powerStation = await powerStationRepository.GetOneAsync(powerStationId); + + var firmSelectItemLists = await powerStationRepository.GetFimlSelectOptionListAsync(powerStationId, powerStation.SiteDB); + + apiResult.Code = "0000"; + apiResult.Data = firmSelectItemLists; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + + apiResult.Msg = errorCode.GetString(apiResult.Code); + return apiResult; + } + /// /// 取得單一電站基本資料 /// diff --git a/SolarPower/Models/MyBaseModel.cs b/SolarPower/Models/MyBaseModel.cs index 98ec112..95569ae 100644 --- a/SolarPower/Models/MyBaseModel.cs +++ b/SolarPower/Models/MyBaseModel.cs @@ -51,6 +51,7 @@ namespace SolarPower.Models public string Email { get; set; } public MyCompany Company { get; set; } //公司資訊 public MyRole Role { get; set; } //角色資訊 + public List PowerStationSummaries { get; set; } } /// diff --git a/SolarPower/Models/PowerStation.cs b/SolarPower/Models/PowerStation.cs index 5ee250f..11e3389 100644 --- a/SolarPower/Models/PowerStation.cs +++ b/SolarPower/Models/PowerStation.cs @@ -559,6 +559,13 @@ namespace SolarPower.Models.PowerStation public string Text { get; set; } public string Value { get; set; } } + + public class FirmlSelectItemList + { + public string Text { get; set; } + public string Value { get; set; } + } + /// /// 控制器 /// diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index d25863a..5abf259 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -36,11 +36,11 @@ namespace SolarPower.Repository.Implement FROM power_station ps LEFT JOIN city c ON ps.CityId = c.Id"; - if (myUser.Role.Layer == 2) + if (myUser.Role.Layer == (int)RoleLayerEnum.CompanyAdmin) { //公司管理員 sql += @" WHERE ps.Deleted = 0 AND ps.CompanyId = @CompanyId"; } - else if (myUser.Role.Layer == 3) + else if (myUser.Role.Layer == (int)RoleLayerEnum.PlatformUser || myUser.Role.Layer == (int)RoleLayerEnum.CompanyUser) { sql += @" LEFT JOIN power_station_operation_personnel op ON ps.Id = op.PowerStationId WHERE ps.Deleted = 0 AND op.Deleted = 0 AND op.UserId = @UserId "; @@ -1568,6 +1568,29 @@ namespace SolarPower.Repository.Implement return result; } } + + public async Task> GetFirmlSelectOptionListAsync(int powerStationId) + { + List result; + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + try + { + var sql = @$"SELECT u.Id AS Value, u.Name AS Text + FROM power_station_operation_personnel op + LEFT JOIN user u ON op.UserId = u.Id + WHERE op.Deleted = 0 AND op.PowerStationId = @PowerStationId"; + + result = (await conn.QueryAsync(sql, new { PowerStationId = powerStationId })).ToList(); + } + catch (Exception exception) + { + throw exception; + } + return result; + } + } + /// /// 新增控制器 /// diff --git a/SolarPower/Repository/Interface/IPowerStationRepository.cs b/SolarPower/Repository/Interface/IPowerStationRepository.cs index a0f1843..fe5aa13 100644 --- a/SolarPower/Repository/Interface/IPowerStationRepository.cs +++ b/SolarPower/Repository/Interface/IPowerStationRepository.cs @@ -34,6 +34,7 @@ namespace SolarPower.Repository.Interface Task> GetAreaSelectOptionListAsync(int cityId); Task> GetOperationPersonnelSelectOptionListAsync(int powerStationId); + Task> GetFimlSelectOptionListAsync(int powerStationId, string siteDB); /// /// 取得下拉式公司選單,須為Deleted: 0、Status: 1 diff --git a/SolarPower/Views/Operation/OperationRecord.cshtml b/SolarPower/Views/Operation/OperationRecord.cshtml index 51812a7..f2a269b 100644 --- a/SolarPower/Views/Operation/OperationRecord.cshtml +++ b/SolarPower/Views/Operation/OperationRecord.cshtml @@ -44,7 +44,7 @@ -
+
@@ -55,7 +55,7 @@
- +
@@ -189,7 +189,7 @@
- +
@@ -200,6 +200,14 @@
+
+
+
+ + +
+
+
@@ -266,7 +274,7 @@ var datepicker; var AllpoweridsType = true; var AllidsType = true; - var status = 1; //1:完成 0:未完成 + var status = 1; //1:完成 0:未完成 var Searchtype = false; //#region Array.Remove @@ -315,7 +323,7 @@ ids.push(String(rel.data[i].cityId)); Allids.push(String(rel.data[i].cityId)); } - $('#Allcity').trigger("click"); + var send_data = { cityid: ids } @@ -345,7 +353,9 @@ //預設查詢第一個 $("#power_station_select_modal").val($("#power_station_select_modal option:first").val()).trigger('change'); + $('#Allcity').trigger("click"); operationRecodeTable.ajax.reload(); + }) }) //#endregion @@ -378,6 +388,28 @@ } } }); + + //查詢該電站的廠商 + var url_power_station_firm = "/PowerStation/GetFirmSelectOptionList"; + + $.post(url_power_station_firm, send_data, function (rel) { + if (rel.code != "0000") { + toast_error(rel.msg); + return; + } + + $("#work_person_select_modal").empty(); + if (rel.data.length > 0) { + + $.each(rel.data, function (index, val) { + $("#work_person_select_modal").append($("