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.Init; using Service.Station; using Service.System; namespace WebStarter.Controllers.BasicConfig { /// /// 基础配置 /// [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配置 // /// // /// 预览 // /// 车型 的ASCLL、解析后信息 // /// // [HttpPost("Preview")] // public async BusinessTask> Preview([FromBody] RfidPreviewReq rfidPreviewReq) // { // RfidPreviewResp rfidPreviewRes = new RfidPreviewResp // { // AnalysisRfidInfo = "", // GetAscllInfo = "" // }; // //string strRfidRlt = ASCIIEncoding.ASCII.GetString(bytesRfid); // return Result.Success(rfidPreviewRes); // } // /// // /// RFID写值 // /// // [HttpGet("RfidWriteValue/{id}")] // public async BusinessTask> 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.Success(); // } // /// // /// RFID 识别 // /// // [HttpGet("RfidRecognition")] // public async BusinessTask> RfidRecognition() // { // //TODO::识别RFID 信息 // return Result.Success(); // } // /// // /// 车型号返回 // /// // [HttpGet("VelType")] // public async BusinessTask>> VelType() // { // List list = new List(); // return Result>.Success(); // } #endregion RFID配置 /// /// 获取换电策略设置 、灯光日间时间、充电运营模式、营业时间段、换电运营模式 /// [HttpPost("StationBaseConfig")] public async Task> 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; return Result.Success(stationBaseRespResp); } /// /// 提交换电策略设置 /// /// /// [HttpPost("SetStationConfig")] public async Task> SetStationConfig([FromBody] StationConfigReq input) { StaticStationInfo.SwapSoc = input.SwapSoc; StaticStationInfo.StationStatus = input.StationStatus; StaticStationInfo.SwapFinishChargeTime = input.SwapFinishChargeTime; StaticStationInfo.AutoChargeEnabled = input.AutoChargeEnabled; return Result.Success(); } /// /// 查询电价信息 /// /// 版本号 /// [HttpGet("GetStationElecPriceInfoList/{version}")] public async Task>> GetStationElecPriceInfoList(int version) { List elecPriceModelVersionDetailResps = new List(); 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.Type }); } return Result>.Success(elecPriceModelVersionDetailResps); } /// /// 增加电价信息 /// /// /// [HttpPost("AddStationElecPriceInfoList")] public async Task> AddStationElecPriceInfoList( [FromBody] List model) { if (null == model || model.Count == 0) { Result.Fail("参数不能为空"); } List elecPriceModelVersionDetails = new List(); 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 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.Success(true); } } return Result.Fail("时间区间重复请检查"); } /// /// 更新电价信息 /// /// /// [HttpPost("UpdateStationElecPriceInfoList")] public async Task> UpdateStationElecPriceInfoList( [FromBody] List model) { if (null == model || model.Count == 0) { Result.Fail("参数不能为空"); } List elecPriceModelVersionDetails = new List(); 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.Fail("时间区间重复请检查"); } List 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.Success(true); } /// /// List中判断一个时间段是否包含另一个时间段(包括开始和结束时间的秒数) /// /// /// [ApiExplorerSettings(IgnoreApi = true)] public bool TimeListIfContains(List timePeriods) { bool notHasOverlap = true; 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])) { notHasOverlap = false; return notHasOverlap; } } } return notHasOverlap; } /// /// 设置类属性 /// /// /// /// public bool SetConfigPorperty(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; } } }