You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
4.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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<EquipInfo>
{
EquipInfoRepository _equipInfoRepository;
public EquipInfoService(EquipInfoRepository service)
{
_equipInfoRepository = service;
this.BaseDal = service;
}
/// <summary>
/// 获取设备信息分页 🔖
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<PageResult<EquipInfo>> Page(PageEquipInfoReq input)
{
RefAsync<int> 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<EquipInfo>()
{
PageNum = input.PageNum,
PageSize = input.PageSize,
ToTal = total,
Rows = items,
};
}
/// <summary>
/// 增加设备信息🔖
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<Result<string>> AddEquipInfo(AddEquipInfoReq input)
{
var isExist =
await _equipInfoRepository.QueryByClauseAsync(u => u.Name == input.Name || u.Code == input.Code);
if (isExist != null)
{
return Result<string>.Fail("已存在同名或同编码设备信息");
}
EquipInfo insertAsync = await _equipInfoRepository.InsertAsync(input.Adapt<EquipInfo>());
if (insertAsync.Id > 0)
{
return Result<string>.Success("新增id" + insertAsync.Id);
}
return Result<string>.Fail("新增失败");
}
/// <summary>
/// 更新设备信息🔖
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<Result<string>> UpdateEquipInfo(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<string>.Fail("已存在同名或同编码设备信息");
}
var config = input.Adapt<EquipInfo>();
int updateResult = await _equipInfoRepository.UpdateAsync(config, true);
if (updateResult > 0)
{
return Result<string>.Success("修改成功");
}
return Result<string>.Fail("修改失败");
}
/// <summary>
/// 删除设备信息 🔖
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<Result<string>> DeleteEquipInfo(DeleteEquipInfoReq input)
{
var equipInfo = await _equipInfoRepository.QueryByClauseAsync(u => u.Id == input.Id);
if (equipInfo==null)
{
return Result<string>.Fail("id不存在");
}
bool deleteResult = await _equipInfoRepository.DeleteAsync(equipInfo);
if (deleteResult)
{
return Result<string>.Success("删除设备信息成功");
}
return Result<string>.Fail("删除失败");
}
}
}