更新 时间段判断

master
lch 6 months ago
parent c488288ad7
commit bc715a35e4

@ -263,50 +263,85 @@ namespace WebStarter.Controllers.BasicConfig
/// <param name="model"></param>
/// <returns></returns>
[HttpPost("AddStationElecPriceInfoList")]
public async Task<Result<bool>> AddStationElecPriceInfoList([FromBody] List<ElecPriceModelVersionDetail> model)
public async Task<Result<bool>> AddStationElecPriceInfoList([FromBody] List<ElecPriceModelVersionDetailReq> 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))
List<ElecPriceModelVersionDetail> elecPriceModelVersionDetails = new List<ElecPriceModelVersionDetail>();
foreach (var item in model)
{
elecPriceModelVersionDetails.Add(new ElecPriceModelVersionDetail()
{
await _elecPriceModelVersionDetailServices.InsertAsync(model);
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("UpdateStationElecPriceInfo")]
public async Task<Result<bool>> UpdateStationElecPriceInfo([FromBody] List<ElecPriceModelVersionDetail> model)
[HttpPost("UpdateStationElecPriceInfoList")]
public async Task<Result<bool>> UpdateStationElecPriceInfoList([FromBody] List<ElecPriceModelVersionDetailReq> model)
{
if (null == model || model.Count == 0)
{
Result<bool>.Fail("参数不能为空");
}
var queryByClauseAsync =
_elecPriceModelVersionDetailServices.QueryByClauseAsync(u => u.Version == model[0].Version);
if (queryByClauseAsync != null)
List<ElecPriceModelVersionDetail> 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<ElecPriceModelVersionDetail> elecPriceModelVersionDetails = new List<ElecPriceModelVersionDetail>();
foreach (var item in model)
{
await _elecPriceModelVersionDetailServices.InsertAsync(model);
return Result<bool>.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<bool>.Success(true);
}
return Result<bool>.Fail("时间区间重复请检查");
}
@ -319,7 +354,7 @@ namespace WebStarter.Controllers.BasicConfig
[ApiExplorerSettings(IgnoreApi = true)]
public bool TimeListIfContains(List<ElecPriceModelVersionDetail> 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;
}
}

Loading…
Cancel
Save