You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

273 lines
10 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Entity.Api.Req;
using Microsoft.AspNetCore.Mvc;
using System.ComponentModel;
using System.Text;
using System;
using System.Reflection;
using Entity.Api.Resp;
using Entity.DbModel.Station;
using HybirdFrameworkCore.Entity;
using Microsoft.VisualBasic;
using Newtonsoft.Json.Linq;
using Service.Init;
using Service.Station;
using Service.System;
namespace WebStarter.Controllers.BasicConfig
{
/// <summary>
/// 基础配置
/// </summary>
[ApiController]
[Route("api/[controller]")]
public class BaseConfigController
{
private readonly SysConfigService _sysConfigService;
private readonly ElecPriceModelVersionDetailServices _elecPriceModelVersionDetailServices;
private readonly ElecPriceModelVersionService _elecPriceModelVersionService;
public BaseConfigController(SysConfigService sysConfigService,
ElecPriceModelVersionDetailServices elecPriceModelVersionDetailServices,
ElecPriceModelVersionService priceModelVersionService)
{
_sysConfigService = sysConfigService;
_elecPriceModelVersionDetailServices = elecPriceModelVersionDetailServices;
_elecPriceModelVersionService = priceModelVersionService;
}
/// <summary>
/// 获取换电策略设置 、灯光日间时间、充电运营模式、营业时间段、换电运营模式
/// </summary>
[HttpPost("StationBaseConfig")]
public async Task<Result<StationConfigResp>> StationBaseConfig()
{
StationConfigResp stationBaseRespResp = new StationConfigResp();
stationBaseRespResp.SwapSoc = StaticStationInfo.SwapSoc;
stationBaseRespResp.SwapFinishChargeTime = StaticStationInfo.SwapFinishChargeTime;
stationBaseRespResp.StationWay = StaticStationInfo.StationWay;
stationBaseRespResp.Ceid = StaticStationInfo.Ceid;
stationBaseRespResp.AutoChargeEnabled = StaticStationInfo.AutoChargeEnabled;
stationBaseRespResp.Oid = StaticStationInfo.Oid;
stationBaseRespResp.StationStatus = StaticStationInfo.StationStatus;
stationBaseRespResp.ChargeSoc = StaticStationInfo.ChargeSoc;
return Result<StationConfigResp>.Success(stationBaseRespResp);
}
/// <summary>
/// 提交换电策略设置
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("SetStationConfig")]
public async Task<Result<bool>> SetStationConfig([FromBody] StationConfigReq input)
{
StaticStationInfo.SwapSoc = input.SwapSoc;
StaticStationInfo.StationStatus = input.StationStatus;
StaticStationInfo.StationWay = input.StationWay;
StaticStationInfo.SwapFinishChargeTime = input.SwapFinishChargeTime;
StaticStationInfo.AutoChargeEnabled = input.AutoChargeEnabled;
StaticStationInfo.ChargeSoc = input.ChargeSoc;
return Result<bool>.Success();
}
/// <summary>
/// 查询电价信息
/// </summary>
/// <param name="version">版本号</param>
/// <returns></returns>
[HttpGet("GetStationElecPriceInfoList/{version}")]
public async Task<Result<List<ElecPriceModelVersionDetailResp>>> GetStationElecPriceInfoList(int version)
{
List<ElecPriceModelVersionDetailResp> elecPriceModelVersionDetailResps =
new List<ElecPriceModelVersionDetailResp>();
var data = await _elecPriceModelVersionDetailServices.QueryListByClauseAsync(u => u.Version == version);
foreach (var item in data)
{
elecPriceModelVersionDetailResps.Add(new ElecPriceModelVersionDetailResp()
{
Id = item.Id,
Version = item.Version,
StartTime = new TimeSpan(item.StartHour, item.StartMinute, item.StartSecond),
EndTime = new TimeSpan(item.EndHour, item.EndMinute, item.EndSecond),
Price = item.Price,
Type = item.Type
});
}
return Result<List<ElecPriceModelVersionDetailResp>>.Success(elecPriceModelVersionDetailResps);
}
/// <summary>
/// 增加电价信息
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
[HttpPost("AddStationElecPriceInfoList")]
public async Task<Result<bool>> AddStationElecPriceInfoList(
[FromBody] List<ElecPriceModelVersionDetailReq> model)
{
if (null == model || model.Count == 0)
{
Result<bool>.Fail("参数不能为空");
}
List<ElecPriceModelVersionDetail> elecPriceModelVersionDetails = new List<ElecPriceModelVersionDetail>();
foreach (var item in model)
{
elecPriceModelVersionDetails.Add(new ElecPriceModelVersionDetail()
{
Version = item.Version,
StartHour = item.StartTime.Hour,
StartMinute = item.StartTime.Minute,
StartSecond = item.StartTime.Second,
EndHour = item.EndTime.Hour,
EndMinute = item.EndTime.Minute,
EndSecond = item.EndTime.Second,
Price = item.Price,
Type = item.Type
});
}
List<ElecPriceModelVersionDetail> modelFromDbs =
await _elecPriceModelVersionDetailServices.QueryListByClauseAsync(u => u.Version == model[0].Version);
if (modelFromDbs != null)
{
modelFromDbs.AddRange(elecPriceModelVersionDetails);
if (TimeListIfContains(modelFromDbs))
{
await _elecPriceModelVersionDetailServices.InsertAsync(elecPriceModelVersionDetails);
return Result<bool>.Success(true);
}
}
return Result<bool>.Fail("时间区间重复请检查");
}
/// <summary>
/// 更新电价信息
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
[HttpPost("UpdateStationElecPriceInfoList")]
public async Task<Result<bool>> UpdateStationElecPriceInfoList(
[FromBody] List<ElecPriceModelVersionDetailReq> model)
{
if (null == model || model.Count == 0)
{
Result<bool>.Fail("参数不能为空");
}
List<ElecPriceModelVersionDetail> elecPriceModelVersionDetails = new List<ElecPriceModelVersionDetail>();
foreach (var item in model)
{
elecPriceModelVersionDetails.Add(new ElecPriceModelVersionDetail()
{
Version = item.Version,
StartHour = item.StartTime.Hour,
StartMinute = item.StartTime.Minute,
StartSecond = item.StartTime.Second,
EndHour = item.EndTime.Hour,
EndMinute = item.EndTime.Minute,
EndSecond = item.EndTime.Second,
Price = item.Price,
Type = item.Type
});
}
if (!TimeListIfContains(elecPriceModelVersionDetails))
{
return Result<bool>.Fail("时间区间重复请检查");
}
List<ElecPriceModelVersionDetail> modelFromDbs =
await _elecPriceModelVersionDetailServices.QueryListByClauseAsync(u => u.Version == model[0].Version);
if (modelFromDbs != null)
{
await _elecPriceModelVersionDetailServices.DeleteAsync(i => i.Version == model[0].Version);
}
await _elecPriceModelVersionDetailServices.InsertAsync(elecPriceModelVersionDetails);
return Result<bool>.Success(true);
}
/// <summary>
/// List中判断一个时间段是否包含另一个时间段包括开始和结束时间的秒数
/// </summary>
/// <param name="timePeriods"></param>
/// <returns></returns>
[ApiExplorerSettings(IgnoreApi = true)]
public bool TimeListIfContains(List<ElecPriceModelVersionDetail> timePeriods)
{
bool notHasOverlap = true;
for (int i = 0; i < timePeriods.Count; i++)
{
if (timePeriods[i].StartHour != 0 && timePeriods[i].StartMinute != 0 && timePeriods[i].StartSecond != 0 && timePeriods[i].EndHour != 0 && timePeriods[i].EndMinute != 0 && timePeriods[i].EndSecond != 0)//排除开始和结束时间都是0点的不判断
{
for (int j = i + 1; j < timePeriods.Count; j++)
{
if (timePeriods[i].Contains(timePeriods[j]) || timePeriods[j].Contains(timePeriods[i]))
{
notHasOverlap = false;
return notHasOverlap;
}
}
}
}
return notHasOverlap;
}
/// <summary>
/// 删除电价信息
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpPost]
[Route("RemovePriceConfig/{id}")]
public Result<bool> RemovePriceConfig(int id)
{
if (_elecPriceModelVersionDetailServices.DeleteById(id))
{
return Result<bool>.Success(true,"删除成功");
}
else
{
return Result<bool>.Fail("删除失败");
}
}
/// <summary>
/// 设置类属性
/// </summary>
/// <param name="t"></param>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public bool SetConfigPorperty<T>(T t)
{
bool setResult = false;
PropertyInfo[] props = typeof(T).GetProperties();
foreach (PropertyInfo fieldInfo in props)
{
string newConstConfigInfo = "Station" + "." + fieldInfo.Name;
object getContent = fieldInfo.GetValue(t);
if (getContent != null)
setResult = _sysConfigService.Set(newConstConfigInfo, getContent);
}
return setResult;
}
}
}