查询列表模型

master
tq 6 months ago
parent 28086f6c23
commit 84680f8cc1

@ -10,7 +10,7 @@ namespace Entity.Base
/// <summary> /// <summary>
/// 自增 /// 自增
/// </summary> /// </summary>
[SugarColumn(ColumnName = "id", ColumnDescription = "主键Id", IsPrimaryKey = true, IsIdentity = false)] [SugarColumn(ColumnName = "id", ColumnDescription = "主键Id", IsPrimaryKey = true, IsIdentity = true)]
public virtual long Id { get; set; } public virtual long Id { get; set; }
} }

@ -20,7 +20,7 @@ namespace Entity.DbModel.Station
/// Default: /// Default:
/// Nullable:False /// Nullable:False
/// </summary> /// </summary>
[SugarColumn(IsPrimaryKey=true,ColumnName="id")] [SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "id")]
public int Id {get;set;} public int Id {get;set;}
/// <summary> /// <summary>

@ -1,4 +1,5 @@
using Entity.DbModel.Station; using System.Transactions;
using Entity.DbModel.Station;
using Entity.Dto.Req; using Entity.Dto.Req;
using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.Entity; using HybirdFrameworkCore.Entity;
@ -11,12 +12,14 @@ namespace Service.Station;
public class BatteryOpModelDetailService: BaseServices<BatteryOpModelDetail> public class BatteryOpModelDetailService: BaseServices<BatteryOpModelDetail>
{ {
private BatteryOpModelDetailRepository _batteryOpModelDetailRepository; private BatteryOpModelDetailRepository _batteryOpModelDetailRepository;
private BatteryOpModelRepository _batteryOpModelRepository;
public BatteryOpModelDetailService(BatteryOpModelDetailRepository dal,BatteryOpModelRepository dalBatteryOpModelRepository)
public BatteryOpModelDetailService(BatteryOpModelDetailRepository dal)
{ {
_batteryOpModelDetailRepository = dal; _batteryOpModelDetailRepository = dal;
BaseDal = dal; BaseDal = dal;
_batteryOpModelRepository= dalBatteryOpModelRepository;
} }
/// <summary> /// <summary>
/// 电池运营模型详情分页列表 🔖 /// 电池运营模型详情分页列表 🔖
@ -51,6 +54,115 @@ public class BatteryOpModelDetailService: BaseServices<BatteryOpModelDetail>
var user = await _batteryOpModelDetailRepository.QueryByClauseAsync(u => u.Id == input.Id); var user = await _batteryOpModelDetailRepository.QueryByClauseAsync(u => u.Id == input.Id);
if (user == null) if (user == null)
throw new ArgumentException($"电池运营模型不存在"); 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;
}
} }

@ -3,6 +3,7 @@ using Entity.DbModel.Station;
using Entity.Dto.Req; using Entity.Dto.Req;
using HybirdFrameworkCore.Entity; using HybirdFrameworkCore.Entity;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Service.Init;
using Service.Station; using Service.Station;
namespace WebStarter.Controllers; namespace WebStarter.Controllers;
@ -22,18 +23,43 @@ public class BatteryOpModelDetailController
} }
/// <summary> /// <summary>
/// 获取电池运营模型分页列表 /// 获取电池运营模型列表
/// </summary> /// </summary>
/// <param name="input"></param> /// <param name="input"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost] [HttpPost]
[Route("page")] [Route("list")]
public async Task<PageResult<BatteryOpModelDetail>> BatteryOpModelPageList( public async Task<List<BatteryOpModelDetail>> BatteryOpModelPageList()
[FromBody] PageBatteryOpModelDetailReq input)
{ {
return await _batteryOpModelDetailService.Page(input); return await _batteryOpModelDetailService.QueryAsync();
}
/// <summary>
/// 增加电池运营模型
/// </summary>
/// <param name ="input"></param >
/// <returns></returns >
[HttpPost]
[Route("add")]
public async Task<Result<string>> AddBatteryOpModelDetail([FromBody] AddBatteryOpModelDetailReq input)
{
return await _batteryOpModelDetailService.AddBatteryOpModelDetail(input);
}
/// <summary>
/// 更新电池运营模型
/// </summary>
/// <param name="batteryOp"></param>
/// <returns></returns>
[HttpPost]
[Route("update")]
public async Task<Result<bool>> UpdateBatteryOpModelDetail([FromBody] UpdateBatteryOpModelDetailReq batteryOpReq)
{
var data = await _batteryOpModelDetailService.UpdateBatteryOpModelDetail(batteryOpReq);
if (data)
return Result<bool>.Success(data);
else
return Result<bool>.Fail(data);
} }
/// <summary> /// <summary>
/// 删除电池运营模型 /// 删除电池运营模型
/// </summary> /// </summary>

@ -66,4 +66,7 @@ CREATE TABLE `equip_alarm_process_record` (
`updated_time` datetime NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间' `updated_time` datetime NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间'
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '设备报警处理记录' ROW_FORMAT = DYNAMIC; ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '设备报警处理记录' ROW_FORMAT = DYNAMIC;
SET FOREIGN_KEY_CHECKS = 1; SET FOREIGN_KEY_CHECKS = 1;
-- 模型两个表id自增
ALTER TABLE battery_op_model MODIFY COLUMN id INT AUTO_INCREMENT;
ALTER TABLE battery_op_model_detail MODIFY COLUMN id INT AUTO_INCREMENT;

Loading…
Cancel
Save