112 lines
4.2 KiB
C#
112 lines
4.2 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Logging;
|
|
using SolarPower.Models;
|
|
using SolarPower.Models.PowerStation;
|
|
using SolarPower.Repository.Interface;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace SolarPower.Controllers
|
|
{
|
|
public class AnalysisStationCombineController : MyBaseController<AnalysisStationCombineController>
|
|
{
|
|
|
|
private readonly IAnalysisStationCombineRepository analysisStationCombineRepository;
|
|
private readonly IPowerStationRepository powerStationRepository;
|
|
|
|
public AnalysisStationCombineController(
|
|
IAnalysisStationCombineRepository analysisStationCombineRepository,
|
|
IPowerStationRepository powerStationRepository) : base()
|
|
{
|
|
this.analysisStationCombineRepository = analysisStationCombineRepository;
|
|
this.powerStationRepository = powerStationRepository;
|
|
}
|
|
public IActionResult Index()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
public ApiResult<Dictionary<string, List<PowerStation>>> GetPowerStationCollapse(string filter)
|
|
{
|
|
ApiResult<Dictionary<string, List<PowerStation>>> apiResult = new ApiResult<Dictionary<string, List<PowerStation>>>();
|
|
|
|
try
|
|
{
|
|
List<string> where = new List<string>();
|
|
Dictionary<string, object> where_entities = new Dictionary<string, object>();
|
|
if (!string.IsNullOrEmpty(filter))
|
|
{
|
|
var temp_psname_where = $@" ps.Name LIKE CONCAT('%', @Filter, '%')";
|
|
where.Add(temp_psname_where);
|
|
|
|
where_entities.Add("Filter", filter);
|
|
}
|
|
|
|
var myPowerStations = myPowerStationService.GetMyPowerStationsGroupByCity(myUser, null, where, where_entities);
|
|
|
|
var siteDBNamePowerStationId = new Dictionary<string, List<PowerStation>>();
|
|
foreach (var powerStation in myPowerStations)
|
|
{
|
|
siteDBNamePowerStationId.Add(powerStation.CityName, powerStation.MyPowerStations.ToList());
|
|
}
|
|
|
|
apiResult.Code = "0000";
|
|
|
|
apiResult.Data = siteDBNamePowerStationId;
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
apiResult.Code = "9999";
|
|
Logger.LogError("【" + controllerName + "/" + actionName + "】");
|
|
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
|
}
|
|
|
|
apiResult.Msg = errorCode.GetString(apiResult.Code);
|
|
return apiResult;
|
|
}
|
|
|
|
public async Task<ApiResult<AnalysisStationCombine>> GetStationsCard(ChartInput post)
|
|
{
|
|
ApiResult<AnalysisStationCombine> apiResult = new ApiResult<AnalysisStationCombine>();
|
|
try
|
|
{
|
|
var GetPowerStationInfos = new AnalysisStationCombine();
|
|
GetPowerStationInfos = await analysisStationCombineRepository.GetPowerStationInfoList(post);
|
|
apiResult.Code = "0000";
|
|
apiResult.Data = GetPowerStationInfos;
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
apiResult.Code = "9999";
|
|
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
|
apiResult.Msg = errorCode.GetString(apiResult.Code);
|
|
}
|
|
|
|
|
|
return apiResult;
|
|
}
|
|
|
|
public async Task<ApiResult<List<Chartoutput>>> GetChart(ChartInput post)
|
|
{
|
|
ApiResult<List<Chartoutput>> apiResult = new ApiResult<List<Chartoutput>>();
|
|
|
|
try
|
|
{
|
|
var GetCharts = new List<Chartoutput>();
|
|
GetCharts = await analysisStationCombineRepository.GetChart(post);
|
|
apiResult.Code = "0000";
|
|
apiResult.Data = GetCharts;
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
apiResult.Code = "9999";
|
|
apiResult.Msg = errorCode.GetString(apiResult.Code);
|
|
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
|
}
|
|
return apiResult;
|
|
}
|
|
}
|
|
}
|