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.

360 lines
14 KiB

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 Entity.DbModel.System.SysBaseObject;
using HybirdFrameworkCore.Entity;
using Microsoft.VisualBasic;
using Newtonsoft.Json.Linq;
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;
}
#region RFID配置
// /// <summary>
// /// 预览
// /// 车型 的ASCLL、解析后信息
// /// </summary>
// [HttpPost("Preview")]
// public async BusinessTask<Result<RfidPreviewResp>> Preview([FromBody] RfidPreviewReq rfidPreviewReq)
// {
// RfidPreviewResp rfidPreviewRes = new RfidPreviewResp
// {
// AnalysisRfidInfo = "",
// GetAscllInfo = ""
// };
// //string strRfidRlt = ASCIIEncoding.ASCII.GetString(bytesRfid);
// return Result<RfidPreviewResp>.Success(rfidPreviewRes);
// }
// /// <summary>
// /// RFID写值
// /// </summary>
// [HttpGet("RfidWriteValue/{id}")]
// public async BusinessTask<Result<bool>> RfidWriteValue()
// {
// //string strResult = "";
// ////strHexVelNoRlt 16进制字符串 保存车辆信息
// //string strHexVelNoRlt = "";
// ////车辆VIN码
// //string strVelVin = txtVelVin.Text.Trim();
// ////车型号
// //string strVelType = txtVelType.Text.Trim();
// ////车辆MAC
// //string strVelMac = txtVelMac.Text.Trim();
// ////车牌号
// //string strVelNo = txtVelNo.Text.Trim();
// //if (!string.IsNullOrEmpty(strVelVin))
// //{
// // strResult += "C-" + strVelVin;
// //}
// //else
// //{
// // strResult += "C-" + " ";
// //}
// //if (!string.IsNullOrEmpty(strVelType))
// //{
// // strResult += "&" + strVelType;
// //}
// //else
// //{
// // strResult += "&" + " ";
// //}
// //if (!string.IsNullOrEmpty(strVelMac))
// //{
// // strResult += "&" + strVelMac.Replace(" ", "");
// //}
// //else
// //{
// // strResult += "&" + " ";
// //}
// //if (!string.IsNullOrEmpty(strVelNo))
// //{
// // Encoding toEcoding = Encoding.GetEncoding("gb2312");
// // byte[] bytesVelNo = toEcoding.GetBytes(strVelNo);
// // strHexVelNoRlt = ByteConvert.BytesToHexStr(bytesVelNo);
// //}
// //txtStartRfidCode.Text = strResult;
// //bytesRfid = System.Text.ASCIIEncoding.ASCII.GetBytes(strResult);
// //byte[] bytesEpc = System.Text.ASCIIEncoding.ASCII.GetBytes(strHexVelNoRlt);
// //_RfidRwTool.WriteRfidSingleTagResult(bytesRfid, bytesEpc);
// return Result<bool>.Success();
// }
// /// <summary>
// /// RFID 识别
// /// </summary>
// [HttpGet("RfidRecognition")]
// public async BusinessTask<Result<string>> RfidRecognition()
// {
// //TODO::识别RFID 信息
// return Result<string>.Success();
// }
// /// <summary>
// /// 车型号返回
// /// </summary>
// [HttpGet("VelType")]
// public async BusinessTask<Result<List<string>>> VelType()
// {
// List<string> list = new List<string>();
// return Result<List<string>>.Success();
// }
#endregion RFID配置
/// <summary>
/// 获取换电策略设置 、灯光日间时间、充电运营模式、营业时间段、换电运营模式
/// </summary>
[HttpPost("BaseSetStationConfigInfo")]
public async Task<Result<BaseSetStationConfigInfo>> BaseSetStationConfigInfo()
{
BaseSetStationConfigInfo stationBaseInfoResp = new BaseSetStationConfigInfo();
List<SysConfig> sysConfigs = await _sysConfigService.GetGroupList("Station");
foreach (var item in sysConfigs)
{
switch (item.Code)
{
case "LightDayStartTime":
stationBaseInfoResp.LigthStartTime = item.Value;
break;
case "LightDayEndTime":
stationBaseInfoResp.LigthEndTime = item.Value;
break;
case "SwapSoc":
stationBaseInfoResp.SetSwapSoc = Convert.ToInt32(item.Value);
break;
case "FullSoc":
stationBaseInfoResp.SetFullSoc = Convert.ToInt32(item.Value);
break;
case "ChargeType":
stationBaseInfoResp.ChargeType = Convert.ToInt32(item.Value);
break;
case "SwapType":
stationBaseInfoResp.SwapType = Convert.ToInt32(item.Value);
break;
case "BusinessStartHours":
stationBaseInfoResp.BusinessStartHours = item.Value;
break;
case "BusinessEndHours":
stationBaseInfoResp.BusinessEndHours = item.Value;
break;
}
}
stationBaseInfoResp.Version = await _elecPriceModelVersionService.GetNowVersion();
return Result<BaseSetStationConfigInfo>.Success(stationBaseInfoResp);
}
/// <summary>
/// 提交换电策略设置
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("SetReplacementStrategy")]
public async Task<Result<bool>> SetReplacementStrategy([FromBody] SetReplacementStrategyReq input)
{
bool setResult = SetConfigPorperty(input);
return Result<bool>.Success(setResult);
}
/// <summary>
/// 日间时间设置
/// </summary>
[HttpPost("SetDaytime")]
public async Task<Result<bool>> SetDaytime([FromBody] SetDayTimeReq input)
{
bool setResult = SetConfigPorperty(input);
return Result<bool>.Success(setResult);
}
/// <summary>
/// 充电运营模式 0手动充电1自动充电
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("SetChargingOperationMode")]
public async Task<Result<bool>> SetChargingOperationMode([FromBody] SetChargingOperationModeReq input)
{
bool setResult = SetConfigPorperty(input);
return Result<bool>.Success(setResult);
}
/// <summary>
/// 营业时间设置
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("SetBusinessHours")]
public async Task<Result<bool>> SetBusinessHours([FromBody] SetBusinessHoursReq input)
{
bool setResult = SetConfigPorperty(input);
return Result<bool>.Success(setResult);
}
/// <summary>
/// 换电运营模式1:自动2:手动
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("SetSwitchingOperaModeReq")]
public async Task<Result<bool>> SetSwitchingOperationMode([FromBody] SetSwitchingOperaModeReq input)
{
bool setResult = SetConfigPorperty(input);
return Result<bool>.Success(setResult);
}
/// <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()
{
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.Price
});
}
return Result<List<ElecPriceModelVersionDetailResp>>.Success(elecPriceModelVersionDetailResps);
}
/// <summary>
/// 增加电价信息
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
[HttpPost("AddStationElecPriceInfoList")]
public async Task<Result<bool>> AddStationElecPriceInfoList([FromBody] List<ElecPriceModelVersionDetail> model)
{
if (null == model || model.Count == 0)
{
Result<bool>.Fail("参数不能为空");
}
var queryByClauseAsync =
_elecPriceModelVersionDetailServices.QueryByClauseAsync(u => u.Version == model[0].Version);
if (queryByClauseAsync != null)
await _elecPriceModelVersionDetailServices.DeleteAsync(i => i.Version == model[0].Version);
if (TimeListIfContains(model))
{
await _elecPriceModelVersionDetailServices.InsertAsync(model);
return Result<bool>.Success(true);
}
return Result<bool>.Fail("时间区间重复请检查");
}
/// <summary>
/// 修改电价信息
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
[HttpPost("UpdateStationElecPriceInfo")]
public async Task<Result<bool>> UpdateStationElecPriceInfo([FromBody] List<ElecPriceModelVersionDetail> model)
{
if (null == model || model.Count == 0)
{
Result<bool>.Fail("参数不能为空");
}
var queryByClauseAsync =
_elecPriceModelVersionDetailServices.QueryByClauseAsync(u => u.Version == model[0].Version);
if (queryByClauseAsync != null)
await _elecPriceModelVersionDetailServices.DeleteAsync(i => i.Version == model[0].Version);
if (TimeListIfContains(model))
{
await _elecPriceModelVersionDetailServices.InsertAsync(model);
return Result<bool>.Success(true);
}
return Result<bool>.Fail("时间区间重复请检查");
}
/// <summary>
/// List中判断一个时间段是否包含另一个时间段包括开始和结束时间的秒数
/// </summary>
/// <param name="timePeriods"></param>
/// <returns></returns>
[ApiExplorerSettings(IgnoreApi = true)]
public bool TimeListIfContains(List<ElecPriceModelVersionDetail> timePeriods)
{
bool hasOverlap = false;
for (int i = 0; i < timePeriods.Count; i++)
{
for (int j = i + 1; j < timePeriods.Count; j++)
{
if (timePeriods[i].Contains(timePeriods[j]) || timePeriods[j].Contains(timePeriods[i]))
{
hasOverlap = true;
return hasOverlap;
}
}
}
return hasOverlap;
}
/// <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;
}
}
}