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.

94 lines
3.2 KiB

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 EquipNetInfoService : BaseServices<EquipNetInfo>
{
EquipNetInfoRepository _equipNetInfoRepository;
public EquipNetInfoService(EquipNetInfoRepository service)
{
_equipNetInfoRepository = service;
}
/// <summary>
/// 获取设备通信信息分页 🔖
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<PageResult<EquipNetInfo>> Page(PageEquipNetInfoReq input)
{
RefAsync<int> total = 0;
var items = await _equipNetInfoRepository.EquipNetInfoQueryPageAsync(
!string.IsNullOrEmpty(input.Code), u => u.Code.Contains(input.Code),
!string.IsNullOrEmpty(input.NetAddr), u => u.NetAddr.Contains(input.NetAddr),
!string.IsNullOrEmpty(input.NetPort), u => u.NetPort.Equals(input.NetPort),
input.PageNum, input.PageSize, total, input);
return new PageResult<EquipNetInfo>()
{
PageNum = input.PageNum,
PageSize = input.PageSize,
ToTal = total,
Rows = items,
};
}
/// <summary>
/// 增加设备通信信息🔖
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<string> AddEquipNetInfo(AddEquipNetInfoReq input)
{
string result = "";
var isExist =
await _equipNetInfoRepository.QueryByClauseAsync(u => u.Code == input.Code);
if (isExist != null)
result = "已存在同编码设备信息";
EquipNetInfo insertAsync = await _equipNetInfoRepository.InsertAsync(input.Adapt<EquipNetInfo>());
if (insertAsync.Id > 0)
result = "增加设备信息成功";
return result;
}
/// <summary>
/// 更新设备通信信息🔖
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<string> UpdateEquipNetInfo(UpdateEquipNetInfoReq input)
{
string result = "";
var isExist = await _equipNetInfoRepository.QueryByClauseAsync(u =>
(u.Code == input.Code) && u.Id != input.Id);
if (isExist != null)
result = "已存在同编码设备通信信息";
var config = input.Adapt<EquipNetInfo>();
int updateResult = await _equipNetInfoRepository.UpdateAsync(config, true);
if (updateResult > 0)
result = "更新设备通信信息成功";
return result;
}
/// <summary>
/// 删除设备通信信息 🔖
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<string> DeleteEquipNetInfo(DeleteEquipNetInfoReq input)
{
string result = "";
var config = await _equipNetInfoRepository.QueryByClauseAsync(u => u.Id == input.Id);
bool deleteResult = await _equipNetInfoRepository.DeleteAsync(config);
if (deleteResult)
result = "成功删除设备通信";
return result;
}
}