diff --git a/WebStarter/Controllers/BasicConfig/BaseConfigController.cs b/WebStarter/Controllers/BasicConfig/BaseConfigController.cs index ec66407..f46c424 100644 --- a/WebStarter/Controllers/BasicConfig/BaseConfigController.cs +++ b/WebStarter/Controllers/BasicConfig/BaseConfigController.cs @@ -263,50 +263,85 @@ namespace WebStarter.Controllers.BasicConfig /// /// [HttpPost("AddStationElecPriceInfoList")] - public async Task> AddStationElecPriceInfoList([FromBody] List model) + public async Task> AddStationElecPriceInfoList([FromBody] List model) { if (null == model || model.Count == 0) { Result.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)) + + List elecPriceModelVersionDetails = new List(); + foreach (var item in model) { - await _elecPriceModelVersionDetailServices.InsertAsync(model); - return Result.Success(true); + 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("UpdateStationElecPriceInfo")] - public async Task> UpdateStationElecPriceInfo([FromBody] List model) + [HttpPost("UpdateStationElecPriceInfoList")] + public async Task> UpdateStationElecPriceInfoList([FromBody] List model) { if (null == model || model.Count == 0) { Result.Fail("参数不能为空"); } - - var queryByClauseAsync = - _elecPriceModelVersionDetailServices.QueryByClauseAsync(u => u.Version == model[0].Version); - if (queryByClauseAsync != null) + + List modelFromDbs = await _elecPriceModelVersionDetailServices.QueryListByClauseAsync(u => u.Version == model[0].Version); + if (modelFromDbs != null) + { await _elecPriceModelVersionDetailServices.DeleteAsync(i => i.Version == model[0].Version); - if (TimeListIfContains(model)) + } + + List elecPriceModelVersionDetails = new List(); + foreach (var item in model) { - await _elecPriceModelVersionDetailServices.InsertAsync(model); - return Result.Success(true); + 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)) + { + await _elecPriceModelVersionDetailServices.InsertAsync(elecPriceModelVersionDetails); + return Result.Success(true); + } return Result.Fail("时间区间重复请检查"); } @@ -319,7 +354,7 @@ namespace WebStarter.Controllers.BasicConfig [ApiExplorerSettings(IgnoreApi = true)] public bool TimeListIfContains(List timePeriods) { - bool hasOverlap = false; + bool hasOverlap = true; for (int i = 0; i < timePeriods.Count; i++) { @@ -327,7 +362,7 @@ namespace WebStarter.Controllers.BasicConfig { if (timePeriods[i].Contains(timePeriods[j]) || timePeriods[j].Contains(timePeriods[i])) { - hasOverlap = true; + hasOverlap = false; return hasOverlap; } }