|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
using Entity.DbModel.Station;
|
|
|
|
|
using System.Transactions;
|
|
|
|
|
using Entity.DbModel.Station;
|
|
|
|
|
using Entity.Dto.Req;
|
|
|
|
|
using HybirdFrameworkCore.Autofac.Attribute;
|
|
|
|
|
using HybirdFrameworkCore.Entity;
|
|
|
|
@ -11,12 +12,14 @@ namespace Service.Station;
|
|
|
|
|
public class BatteryOpModelDetailService: BaseServices<BatteryOpModelDetail>
|
|
|
|
|
{
|
|
|
|
|
private BatteryOpModelDetailRepository _batteryOpModelDetailRepository;
|
|
|
|
|
private BatteryOpModelRepository _batteryOpModelRepository;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public BatteryOpModelDetailService(BatteryOpModelDetailRepository dal)
|
|
|
|
|
public BatteryOpModelDetailService(BatteryOpModelDetailRepository dal,BatteryOpModelRepository dalBatteryOpModelRepository)
|
|
|
|
|
{
|
|
|
|
|
_batteryOpModelDetailRepository = dal;
|
|
|
|
|
BaseDal = dal;
|
|
|
|
|
_batteryOpModelRepository= dalBatteryOpModelRepository;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 电池运营模型详情分页列表 🔖
|
|
|
|
@ -51,6 +54,115 @@ public class BatteryOpModelDetailService: BaseServices<BatteryOpModelDetail>
|
|
|
|
|
var user = await _batteryOpModelDetailRepository.QueryByClauseAsync(u => u.Id == input.Id);
|
|
|
|
|
if (user == null)
|
|
|
|
|
throw new ArgumentException($"电池运营模型不存在");
|
|
|
|
|
return await _batteryOpModelDetailRepository.DeleteAsync(user);
|
|
|
|
|
// 删除模型
|
|
|
|
|
var isExistModel = await _batteryOpModelRepository.QueryByClauseAsync(u => u.ModelId == user.ModelId);
|
|
|
|
|
bool batteay = true;
|
|
|
|
|
if (isExistModel!=null)
|
|
|
|
|
{
|
|
|
|
|
batteay = await _batteryOpModelRepository.DeleteAsync(isExistModel);
|
|
|
|
|
}
|
|
|
|
|
// 删除模型详情
|
|
|
|
|
|
|
|
|
|
bool batteryOpModelDetail = await _batteryOpModelDetailRepository.DeleteAsync(user);
|
|
|
|
|
if (batteay && batteryOpModelDetail)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 增加电池运营模型 🔖
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<Result<string>> AddBatteryOpModelDetail(AddBatteryOpModelDetailReq input)
|
|
|
|
|
{
|
|
|
|
|
// 事务
|
|
|
|
|
using (var transactionScope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
|
|
|
|
|
{
|
|
|
|
|
List<BatteryOpModelDetail> batteryOpModelDetails = await _batteryOpModelDetailRepository.QueryAsync();
|
|
|
|
|
foreach (var detail in batteryOpModelDetails)
|
|
|
|
|
{
|
|
|
|
|
if (detail.ModelId == input.ModelId)
|
|
|
|
|
{
|
|
|
|
|
return Result<string>.Fail("模型id在模型详情表已存在");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (detail.StartTime == input.StartTime || detail.EndTime == input.EndTime)
|
|
|
|
|
{
|
|
|
|
|
return Result<string>.Fail("相同时间已经存在");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 检查两个表模型id是否已存在
|
|
|
|
|
var isExistModel = await _batteryOpModelRepository.QueryByClauseAsync(u => u.ModelId == input.ModelId);
|
|
|
|
|
if (isExistModel != null)
|
|
|
|
|
{
|
|
|
|
|
return Result<string>.Fail("模型id在模型详情表已存在");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var batteryOpModel = new BatteryOpModel
|
|
|
|
|
{
|
|
|
|
|
ModelId = input.ModelId
|
|
|
|
|
};
|
|
|
|
|
await _batteryOpModelDetailRepository.InsertAsync(input);
|
|
|
|
|
|
|
|
|
|
await _batteryOpModelRepository.InsertAsync(batteryOpModel);
|
|
|
|
|
|
|
|
|
|
var insertedDetail =
|
|
|
|
|
await _batteryOpModelDetailRepository.QueryByClauseAsync(u => u.ModelId == input.ModelId);
|
|
|
|
|
|
|
|
|
|
// 新增
|
|
|
|
|
transactionScope.Complete();
|
|
|
|
|
return Result<string>.Success("新增id:" + insertedDetail.Id);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual async Task<bool> UpdateBatteryOpModelDetail(UpdateBatteryOpModelDetailReq batteryOpReq)
|
|
|
|
|
{
|
|
|
|
|
List<BatteryOpModelDetail> batteryOpModelDetails = await _batteryOpModelDetailRepository.QueryAsync();
|
|
|
|
|
foreach (var detail in batteryOpModelDetails)
|
|
|
|
|
{
|
|
|
|
|
if (detail.ModelId == batteryOpReq.ModelId)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException($"模型id在模型详情表已存在");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (detail.StartTime == batteryOpReq.StartTime || detail.EndTime == batteryOpReq.EndTime)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException($"已存在相同时间");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var isExistModel = await _batteryOpModelRepository.QueryByClauseAsync(u => u.ModelId == batteryOpReq.ModelId);
|
|
|
|
|
|
|
|
|
|
if (isExistModel != null)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 通过id查找修改之前的模型id
|
|
|
|
|
var batteryOpModelDetail =
|
|
|
|
|
await _batteryOpModelDetailRepository.QueryByClauseAsync(u => u.Id == batteryOpReq.Id);
|
|
|
|
|
|
|
|
|
|
var batteryOpModel =
|
|
|
|
|
await _batteryOpModelRepository.QueryByClauseAsync(u => u.ModelId == batteryOpModelDetail.ModelId);
|
|
|
|
|
|
|
|
|
|
batteryOpModel.ModelId = batteryOpReq.ModelId;
|
|
|
|
|
|
|
|
|
|
bool updateModelDetail = await _batteryOpModelDetailRepository.UpdateAsync(batteryOpReq);
|
|
|
|
|
bool updateMode = await _batteryOpModelRepository.UpdateAsync(batteryOpModel);
|
|
|
|
|
|
|
|
|
|
if (updateModelDetail && updateMode)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|