using Entity.Ammeter; using Entity.DbModel; using Entity.DbModel.Station; using HybirdFrameworkCore.Autofac.Attribute; using Repository.Ammeter; using Repository.Station; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Entity.Dto.Req; using HybirdFrameworkCore.Entity; using Mapster; using SqlSugar; namespace Service.Station { [Scope("SingleInstance")] public class EquipInfoService : BaseServices { EquipInfoRepository _equipInfoRepository; public EquipInfoService(EquipInfoRepository service) { _equipInfoRepository = service; this.BaseDal = service; } /// /// 获取设备信息分页 🔖 /// /// /// 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.HasValue, u => u.Status == input.Status, input.PageNum, input.PageSize, total, input); return new PageResult() { PageNum = input.PageNum, PageSize = input.PageSize, ToTal = total, Rows = items, }; } /// /// 增加设备信息🔖 /// /// /// public async Task AddEquipInfo(AddEquipInfoReq input) { string result = ""; var isExist = await _equipInfoRepository.QueryByClauseAsync(u => u.Name == input.Name || u.Code == input.Code); if (isExist != null) result = "已存在同名或同编码设备信息"; EquipInfo insertAsync = await _equipInfoRepository.InsertAsync(input.Adapt()); if (insertAsync.Id > 0) result = "增加设备信息"; return result; } /// /// 更新设备信息🔖 /// /// /// public async Task UpdateEquipInfo(UpdateEquipInfoReq input) { string result = ""; var isExist = await _equipInfoRepository.QueryByClauseAsync(u => (u.Name == input.Name || u.Code == input.Code) && u.Id != input.Id); if (isExist != null) result = "已存在同名或同编码设备信息"; var config = input.Adapt(); int updateResult = await _equipInfoRepository.UpdateAsync(config, true); if (updateResult > 0) result = "更新设备信息成功"; return result; } /// /// 删除设备信息 🔖 /// /// /// public async Task DeleteEquipInfo(DeleteEquipInfoReq input) { string result = ""; var config = await _equipInfoRepository.QueryByClauseAsync(u => u.Id == input.Id); bool deleteResult = await _equipInfoRepository.DeleteAsync(config); if (deleteResult) result = "删除设备信息成功"; return result; } } }