using System.ComponentModel; using Entity.Base; using Entity.DbModel.Station; using Entity.Dto.Req; using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Entity; using Mapster; using Repository.Station; using SqlSugar; namespace Service.Station; [Scope("SingleInstance")] public class EquipInfoService : BaseServices { private readonly EquipInfoRepository _equipInfoRepository; public EquipInfoService(EquipInfoRepository equipInfoRepository) { _equipInfoRepository = equipInfoRepository; } /// /// 获取分页列表 🔖 /// /// 查询参数 /// 分页列表 public async Task> Page(PageEquipInfoReq input) { RefAsync total = 0; var items = await _equipInfoRepository.EquipInfoQueryPageAsync( !string.IsNullOrEmpty(input.Name), u => u.Name.Contains(input.Name), !string.IsNullOrEmpty(input.Code), u => u.Code.Contains(input.Code), input.Status != null, (u => input.Status != null && u.Status.Equals(input.Status.Value)), input.Page, input.PageSize, total, input); return SqlSugarPagedExtensions.CreateSqlSugarPagedList(items, total, input.Page, input.PageSize); } /// /// 修改充电模式配置 🔖 /// /// 修改参数 /// 修改结果 [DisplayName("更新充电模式配置")] public async Task> UpdateEquipInfoReq(UpdateEquipInfoReq input) { var isExist = await _equipInfoRepository.QueryByClauseAsync (u => (u.Name == input.Name || u.Code == input.Code) && u.Id != input.Id); if (isExist != null) { return Result.Fail(false, "已存在同名或同编码参数配置"); } var config = input.Adapt(); int affectedRows = await _equipInfoRepository.UpdateAsync(config, true); // 判断是否更新成功 if (affectedRows > 0) { return Result.Success(true, "修改成功"); } return Result.Fail(false, "修改失败"); } /// /// 删除充电模式配置 🔖 /// /// 删除参数 /// 删除结果 [DisplayName("删除充电模式配置")] public async Task> DeleteEquipInfoReq(DeleteEquipInfoReq input) { var config = await _equipInfoRepository.QueryByClauseAsync(u => u.Id == input.Id); bool deleteResult = await _equipInfoRepository.DeleteAsync(config); if (deleteResult) return Result.Success(true, "修改成功"); return Result.Fail(true, "删除成功"); } }