電站卡片縣市nav部分的後端
This commit is contained in:
parent
eaf6a4e9c6
commit
cbd26e09a6
@ -1220,5 +1220,28 @@ namespace SolarPower.Controllers
|
|||||||
|
|
||||||
return apiResult;
|
return apiResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 取得該使用者可看的所有電站分佈縣市以及各縣市電站數量
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<ApiResult<List<SolarCityAmount>>> GetSolarCitySummary()
|
||||||
|
{
|
||||||
|
ApiResult<List<SolarCityAmount>> apiResult = new ApiResult<List<SolarCityAmount>>();
|
||||||
|
List<SolarCityAmount> solaramount = new List<SolarCityAmount>();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
apiResult.Code = "0000";
|
||||||
|
solaramount = await powerStationRepository.GetSolarCitySummary(myUser);
|
||||||
|
apiResult.Data = solaramount;
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
apiResult.Code = "9999";
|
||||||
|
apiResult.Msg = exception.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return apiResult;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,7 +37,7 @@ namespace SolarPower.Helper
|
|||||||
var passwordStr = ed.DESDecrypt(dbConfig.Password);
|
var passwordStr = ed.DESDecrypt(dbConfig.Password);
|
||||||
|
|
||||||
//var connStr = $"server={serverStr};database={databaseStr};user={rootStr};password={passwordStr};charset=utf8;";
|
//var connStr = $"server={serverStr};database={databaseStr};user={rootStr};password={passwordStr};charset=utf8;";
|
||||||
var connStr = @"server=127.0.0.1;port=3308;database=solar_power;user=root;password=00000000;charset=utf8;";
|
var connStr = @"server=127.0.0.1;port=3306;database=solar_power;user=root;password=000000;charset=utf8;";
|
||||||
|
|
||||||
this._connectionString = connStr;
|
this._connectionString = connStr;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -364,4 +364,14 @@ namespace SolarPower.Models.PowerStation
|
|||||||
public string AlarmName { get; set; }
|
public string AlarmName { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 電站縣市分佈
|
||||||
|
/// </summary>
|
||||||
|
public class SolarCityAmount
|
||||||
|
{
|
||||||
|
public int CityId { get; set; }
|
||||||
|
public string City { get; set; }
|
||||||
|
public int Amount { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,6 +10,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using SolarPower.Models;
|
||||||
|
|
||||||
namespace SolarPower.Repository.Implement
|
namespace SolarPower.Repository.Implement
|
||||||
{
|
{
|
||||||
@ -809,5 +810,44 @@ namespace SolarPower.Repository.Implement
|
|||||||
}
|
}
|
||||||
return Num;
|
return Num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<List<SolarCityAmount>> GetSolarCitySummary(MyUser User)
|
||||||
|
{
|
||||||
|
using IDbConnection conn = _databaseHelper.GetConnection();
|
||||||
|
List<SolarCityAmount> solaramount = new List<SolarCityAmount>();
|
||||||
|
conn.Open();
|
||||||
|
var trans = conn.BeginTransaction();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (User.Role.Layer == 0 || User.Role.Layer == 1)
|
||||||
|
{
|
||||||
|
var sql = "SELECT city.Id AS CityId city.Name AS City,COUNT(*) AS Amount FROM power_station LEFT JOIN city ON power_station.CityId = city.Id GROUP BY power_station.CityId";
|
||||||
|
solaramount = (await conn.QueryAsync<SolarCityAmount>(sql)).ToList();
|
||||||
|
trans.Commit();
|
||||||
|
}
|
||||||
|
else if (User.Role.Layer == 2)
|
||||||
|
{
|
||||||
|
var sql = "SELECT city.Id AS CityId city.Name AS City,COUNT(*) AS Amount FROM power_station LEFT JOIN city ON power_station.CityId = city.Id WHERE CompanyId = @CompanyId GROUP BY power_station.CityId ORDER BY power_station.CityId ";
|
||||||
|
solaramount = (await conn.QueryAsync<SolarCityAmount>(sql, new { CompanyId = User.CompanyId })).ToList();
|
||||||
|
trans.Commit();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var sql = "SELECT city.Id AS CityId city.Name AS City,COUNT(*) AS Amount FROM power_station LEFT JOIN city ON power_station.CityId = city.Id LEFT JOIN power_station_operation_personnel ON power_station.Id = power_station_operation_personnel.PowerStationId WHERE UserId = @UserId GROUP BY power_station.CityId ORDER BY power_station.CityId";
|
||||||
|
solaramount = (await conn.QueryAsync<SolarCityAmount>(sql, new { UserId = User.Id })).ToList();
|
||||||
|
trans.Commit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
trans.Rollback();
|
||||||
|
throw exception;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
conn.Close();
|
||||||
|
}
|
||||||
|
return solaramount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using SolarPower.Models.PowerStation;
|
using SolarPower.Models;
|
||||||
|
using SolarPower.Models.PowerStation;
|
||||||
using SolarPower.Models.User;
|
using SolarPower.Models.User;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -188,5 +189,13 @@ namespace SolarPower.Repository.Interface
|
|||||||
/// <param name="Type"></param>
|
/// <param name="Type"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<string> GetFinalSerialNumber(int PowerStationId, string Type);
|
Task<string> GetFinalSerialNumber(int PowerStationId, string Type);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 取得電站分佈縣市以及數量
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="User"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<List<SolarCityAmount>> GetSolarCitySummary(MyUser User);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -410,7 +410,30 @@
|
|||||||
$(function () {
|
$(function () {
|
||||||
|
|
||||||
var localurl = this.location.href;
|
var localurl = this.location.href;
|
||||||
//電站區域Tab要佳LI
|
|
||||||
|
//#region 電站區域Tab
|
||||||
|
|
||||||
|
|
||||||
|
var url = "/PowerStation/GetSolarCitySummary";
|
||||||
|
$.post(url, function (rel) {
|
||||||
|
if (rel.code != "0000") {
|
||||||
|
toast_error(rel.msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$.each(rel.data, function (index, val) {
|
||||||
|
//alert(val.city + val.amount);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}, 'json');
|
||||||
|
|
||||||
|
|
||||||
|
//#endregion
|
||||||
|
|
||||||
|
//電站區域
|
||||||
$('#templateAreaTab').find('li').attr('id', 'AreaTabnewtaipei').clone().appendTo($('#areaTab'));
|
$('#templateAreaTab').find('li').attr('id', 'AreaTabnewtaipei').clone().appendTo($('#areaTab'));
|
||||||
$('#AreaTabnewtaipei').find('a').attr('href', '#tab-newtaipei');
|
$('#AreaTabnewtaipei').find('a').attr('href', '#tab-newtaipei');
|
||||||
$('#AreaTabnewtaipei').find('a').attr('class', 'nav-link fs-lg px-4');
|
$('#AreaTabnewtaipei').find('a').attr('class', 'nav-link fs-lg px-4');
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user