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.

104 lines
3.6 KiB

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<string> 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<EquipInfo>());
if (insertAsync.Id > 0)
result = "增加设备信息";
return result;
}
/// <summary>
/// 更新设备信息🔖
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<string> 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<EquipInfo>();
int updateResult = await _equipInfoRepository.UpdateAsync(config, true);
if (updateResult > 0)
result = "更新设备信息成功";
return result;
}
/// <summary>
/// 删除设备信息 🔖
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<string> 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;
}
}
}