1. 暫時遷入

This commit is contained in:
Kai 2021-08-25 16:52:03 +08:00
parent c7a3fc3302
commit c2c9df6f36
9 changed files with 99 additions and 9 deletions

View File

@ -2,6 +2,7 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using SolarPower.Models; using SolarPower.Models;
using SolarPower.Models.PowerStation; using SolarPower.Models.PowerStation;
using SolarPower.Models.Role;
using SolarPower.Repository.Interface; using SolarPower.Repository.Interface;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -31,7 +32,7 @@ namespace SolarPower.Controllers
try try
{ {
var powerStations = new List<PowerStation>(); var powerStations = new List<PowerStation>();
if (IsPlatformLayer(myUser.Role.Layer)) if (myUser.Role.Layer == (int)RoleLayerEnum.PlatformAdmin)
{ {
powerStations = await powerStationRepository.GetAllAsync(); powerStations = await powerStationRepository.GetAllAsync();
} }

View File

@ -42,7 +42,8 @@ namespace SolarPower.Controllers
try try
{ {
List<int> powerStationIds = await powerStationRepository.GetPowerStationIdsByUserRole(myUser); //List<int> powerStationIds = await powerStationRepository.GetPowerStationIdsByUserRole(myUser);
List<int> powerStationIds = myUser.PowerStationSummaries.SelectMany(x => x.MyPowerStations.Select(y=> y.PowerStationId)).ToList();
var overview = await overviewRepository.GetOverviewByPowerStationIds(powerStationIds); var overview = await overviewRepository.GetOverviewByPowerStationIds(powerStationIds);
mapOverview.Today_kwh = overview.Today_kwh; mapOverview.Today_kwh = overview.Today_kwh;
mapOverview.Total_kwh = overview.Total_kwh; mapOverview.Total_kwh = overview.Total_kwh;

View File

@ -122,6 +122,7 @@ namespace SolarPower.Controllers
//取得當前使用者可以查看的電站 //取得當前使用者可以查看的電站
var myPowerStationSummaries = powerStationRepository.GetMyPowerStationSummary(myUser); var myPowerStationSummaries = powerStationRepository.GetMyPowerStationSummary(myUser);
myUser.PowerStationSummaries = myPowerStationSummaries;
ViewBag.myPowerStationSummaries = myPowerStationSummaries; ViewBag.myPowerStationSummaries = myPowerStationSummaries;
if (controllerName == "PowerStation" && actionName == "Edit") if (controllerName == "PowerStation" && actionName == "Edit")

View File

@ -248,6 +248,29 @@ namespace SolarPower.Controllers
return apiResult; return apiResult;
} }
[HttpPost]
public async Task<ApiResult<List<FirmlSelectItemList>>> GetFirmSelectOptionList(int powerStationId)
{
ApiResult<List<FirmlSelectItemList>> apiResult = new ApiResult<List<FirmlSelectItemList>>();
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;
}
/// <summary> /// <summary>
/// 取得單一電站基本資料 /// 取得單一電站基本資料
/// </summary> /// </summary>

View File

@ -51,6 +51,7 @@ namespace SolarPower.Models
public string Email { get; set; } public string Email { get; set; }
public MyCompany Company { get; set; } //公司資訊 public MyCompany Company { get; set; } //公司資訊
public MyRole Role { get; set; } //角色資訊 public MyRole Role { get; set; } //角色資訊
public List<MyPowerStationSummary> PowerStationSummaries { get; set; }
} }
/// <summary> /// <summary>

View File

@ -559,6 +559,13 @@ namespace SolarPower.Models.PowerStation
public string Text { get; set; } public string Text { get; set; }
public string Value { get; set; } public string Value { get; set; }
} }
public class FirmlSelectItemList
{
public string Text { get; set; }
public string Value { get; set; }
}
/// <summary> /// <summary>
/// 控制器 /// 控制器
/// </summary> /// </summary>

View File

@ -36,11 +36,11 @@ namespace SolarPower.Repository.Implement
FROM power_station ps FROM power_station ps
LEFT JOIN city c ON ps.CityId = c.Id"; LEFT JOIN city c ON ps.CityId = c.Id";
if (myUser.Role.Layer == 2) if (myUser.Role.Layer == (int)RoleLayerEnum.CompanyAdmin)
{ //公司管理員 { //公司管理員
sql += @" WHERE ps.Deleted = 0 AND ps.CompanyId = @CompanyId"; 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 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 "; WHERE ps.Deleted = 0 AND op.Deleted = 0 AND op.UserId = @UserId ";
@ -1568,6 +1568,29 @@ namespace SolarPower.Repository.Implement
return result; return result;
} }
} }
public async Task<List<FirmlSelectItemList>> GetFirmlSelectOptionListAsync(int powerStationId)
{
List<FirmlSelectItemList> 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<OperationPersonnelSelectItemList>(sql, new { PowerStationId = powerStationId })).ToList();
}
catch (Exception exception)
{
throw exception;
}
return result;
}
}
/// <summary> /// <summary>
/// 新增控制器 /// 新增控制器
/// </summary> /// </summary>

View File

@ -34,6 +34,7 @@ namespace SolarPower.Repository.Interface
Task<List<AreaSelectItemList>> GetAreaSelectOptionListAsync(int cityId); Task<List<AreaSelectItemList>> GetAreaSelectOptionListAsync(int cityId);
Task<List<OperationPersonnelSelectItemList>> GetOperationPersonnelSelectOptionListAsync(int powerStationId); Task<List<OperationPersonnelSelectItemList>> GetOperationPersonnelSelectOptionListAsync(int powerStationId);
Task<List<FirmlSelectItemList>> GetFimlSelectOptionListAsync(int powerStationId, string siteDB);
/// <summary> /// <summary>
/// 取得下拉式公司選單須為Deleted: 0、Status: 1 /// 取得下拉式公司選單須為Deleted: 0、Status: 1

View File

@ -200,6 +200,14 @@
</div> </div>
</div> </div>
</div> </div>
<div class="row mb-3 fix-div">
<div class="col-lg-6">
<div class="form-group">
<label class="form-label" for="fix_firm_modal">負責廠商</label>
<select></select>
</div>
</div>
</div>
<div class="row mb-3"> <div class="row mb-3">
<div class="col-lg-12"> <div class="col-lg-12">
@ -315,7 +323,7 @@
ids.push(String(rel.data[i].cityId)); ids.push(String(rel.data[i].cityId));
Allids.push(String(rel.data[i].cityId)); Allids.push(String(rel.data[i].cityId));
} }
$('#Allcity').trigger("click");
var send_data = { var send_data = {
cityid: ids cityid: ids
} }
@ -345,7 +353,9 @@
//預設查詢第一個 //預設查詢第一個
$("#power_station_select_modal").val($("#power_station_select_modal option:first").val()).trigger('change'); $("#power_station_select_modal").val($("#power_station_select_modal option:first").val()).trigger('change');
$('#Allcity').trigger("click");
operationRecodeTable.ajax.reload(); operationRecodeTable.ajax.reload();
}) })
}) })
//#endregion //#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($("<option />").val(val.value).text(val.text));
});
if (recode != null || recode != undefined) {
$("#work_person_select_modal").val(recode.workPersonId);
}
}
});
}); });
//#endregion //#endregion