设备列表优化

master
tq 5 months ago
parent 2c4da93638
commit 43b99fbf1e

@ -36,6 +36,26 @@ public class PageEquipInfoReq : QueryPageModel
public class AddEquipInfoReq : EquipInfo public class AddEquipInfoReq : EquipInfo
{ {
/// <summary>
/// Desc:连接地址
/// Default:
/// Nullable:True
/// </summary>
public string NetAddr { get; set; }
/// <summary>
/// Desc:连接端口
/// Default:
/// Nullable:True
/// </summary>
public string NetPort { get; set; }
/// <summary>
/// Desc:目的地址;十六进制如0a,02,03,04
/// Default:
/// Nullable:True
/// </summary>
public string DestAddr { get; set; }
} }
public class UpdateEquipInfoReq : AddEquipInfoReq public class UpdateEquipInfoReq : AddEquipInfoReq

@ -0,0 +1,76 @@
namespace Entity.Dto.Resp;
/// <summary>
/// 设备信息resp
/// </summary>
public class EquipInfoResp
{
/// <summary>
/// Desc:id
/// Default:
/// Nullable:False
/// </summary>
public int Id { get; set; }
/// <summary>
/// Desc:设备编码
/// Default:
/// Nullable:True
/// </summary>
public string Code { get; set; }
/// <summary>
/// Desc:设备名称
/// Default:
/// Nullable:True
/// </summary>
public string Name { get; set; }
/// <summary>
/// Desc:设备类型编码 0交流1直流
/// Default:
/// Nullable:True
/// </summary>
public int? TypeCode { get; set; }
/// <summary>
/// Desc:设备状态;0-未知1-正常2-报警3-停用
/// Default:
/// Nullable:True
/// </summary>
public int? Status { get; set; }
/// <summary>
/// Desc:0-手动;1-自动充电
/// Default:
/// Nullable:True
/// </summary>
public int? AutoCharge { get; set; }
/// <summary>
/// 充电功率
/// </summary>
public float? ChargePower { get; set; }
/// <summary>
/// Desc:连接地址
/// Default:
/// Nullable:True
/// </summary>
public string NetAddr { get; set; }
/// <summary>
/// Desc:连接端口
/// Default:
/// Nullable:True
/// </summary>
public string NetPort { get; set; }
/// <summary>
/// Desc:目的地址;十六进制如0a,02,03,04
/// Default:
/// Nullable:True
/// </summary>
public string DestAddr { get; set; }
}

@ -9,7 +9,9 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using AutoMapper;
using Entity.Dto.Req; using Entity.Dto.Req;
using Entity.Dto.Resp;
using HybirdFrameworkCore.Entity; using HybirdFrameworkCore.Entity;
using Mapster; using Mapster;
using SqlSugar; using SqlSugar;
@ -20,10 +22,12 @@ namespace Service.Station
public class EquipInfoService : BaseServices<EquipInfo> public class EquipInfoService : BaseServices<EquipInfo>
{ {
EquipInfoRepository _equipInfoRepository; EquipInfoRepository _equipInfoRepository;
EquipNetInfoRepository _equipNetInfoRepository;
public EquipInfoService(EquipInfoRepository service) public EquipInfoService(EquipInfoRepository service,EquipNetInfoRepository repository)
{ {
_equipInfoRepository = service; _equipInfoRepository = service;
_equipNetInfoRepository = repository;
this.BaseDal = service; this.BaseDal = service;
} }
@ -32,20 +36,45 @@ namespace Service.Station
/// </summary> /// </summary>
/// <param name="input"></param> /// <param name="input"></param>
/// <returns></returns> /// <returns></returns>
public async Task<PageResult<EquipInfo>> Page(PageEquipInfoReq input) public async Task<PageResult<EquipInfoResp>> Page(PageEquipInfoReq input)
{ {
RefAsync<int> total = 0; RefAsync<int> total = 0;
var items = await _equipInfoRepository.EquipInfoQueryPageAsync(
List<EquipInfo> items = await _equipInfoRepository.EquipInfoQueryPageAsync(
!string.IsNullOrEmpty(input.Name), u => u.Name.Contains(input.Name), !string.IsNullOrEmpty(input.Name), u => u.Name.Contains(input.Name),
!string.IsNullOrEmpty(input.Code), u => u.Code.Contains(input.Code), !string.IsNullOrEmpty(input.Code), u => u.Code.Contains(input.Code),
input.Status.HasValue, u => u.Status == input.Status, input.Status.HasValue, u => u.Status == input.Status,
input.PageNum, input.PageSize, total, input); input.PageNum, input.PageSize, total, input);
return new PageResult<EquipInfo>()
List<EquipNetInfo> equipNetInfoList = await _equipNetInfoRepository.QueryAsync();
Dictionary<string,EquipNetInfo> equipNetInfoDict = equipNetInfoList.ToDictionary(e => e.Code);
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<EquipInfoResp, EquipInfo>().ReverseMap();
});
IMapper mapper = config.CreateMapper();
List<EquipInfoResp> respList = mapper.Map<List<EquipInfoResp>>(items);
foreach (var equipInfo in respList)
{
if (equipNetInfoDict.TryGetValue(equipInfo.Code, out var equipNetInfo))
{
equipInfo.NetAddr = equipNetInfo.NetAddr;
equipInfo.NetPort = equipNetInfo.NetPort;
equipInfo.DestAddr = equipNetInfo.DestAddr;
}
}
return new PageResult<EquipInfoResp>
{ {
PageNum = input.PageNum, PageNum = input.PageNum,
PageSize = input.PageSize, PageSize = input.PageSize,
ToTal = total, ToTal = total,
Rows = items, Rows = respList
}; };
} }
@ -56,15 +85,37 @@ namespace Service.Station
/// <returns></returns> /// <returns></returns>
public async Task<Result<string>> AddEquipInfo(AddEquipInfoReq input) public async Task<Result<string>> AddEquipInfo(AddEquipInfoReq input)
{ {
var isExist = var existingEquipInfoTask =
await _equipInfoRepository.QueryByClauseAsync(u => u.Name == input.Name || u.Code == input.Code); _equipInfoRepository.QueryByClauseAsync(u => u.Name == input.Name || u.Code == input.Code);
var existingNetInfoTask = _equipNetInfoRepository.QueryByClauseAsync(u => u.Code == input.Code);
await Task.WhenAll(existingEquipInfoTask, existingNetInfoTask);
var isExist = existingEquipInfoTask.Result;
var isNetInfoExist = existingNetInfoTask.Result;
if (isExist != null) if (isExist != null)
{ {
return Result<string>.Fail("已存在同名或同编码设备信息"); return Result<string>.Fail("已存在同名或同编码设备信息");
} }
EquipInfo insertAsync = await _equipInfoRepository.InsertAsync(input.Adapt<EquipInfo>()); if (isNetInfoExist != null)
if (insertAsync.Id > 0) {
return Result<string>.Fail("编码在通信设备配置表已存在");
}
var equipInfo = input.Adapt<EquipInfo>();
var equipNetInfo = input.Adapt<EquipNetInfo>();
var insertEquipInfoTask = _equipInfoRepository.InsertAsync(equipInfo);
var insertEquipNetInfoTask = _equipNetInfoRepository.InsertAsync(equipNetInfo);
await Task.WhenAll(insertEquipInfoTask, insertEquipNetInfoTask);
var insertAsync = insertEquipInfoTask.Result;
var insertAsyncNetInfo = insertEquipNetInfoTask.Result;
if (insertAsync.Id > 0 && insertAsyncNetInfo.Id > 0)
{ {
return Result<string>.Success("新增id" + insertAsync.Id); return Result<string>.Success("新增id" + insertAsync.Id);
} }
@ -79,16 +130,44 @@ namespace Service.Station
/// <returns></returns> /// <returns></returns>
public async Task<Result<string>> UpdateEquipInfo(UpdateEquipInfoReq input) public async Task<Result<string>> UpdateEquipInfo(UpdateEquipInfoReq input)
{ {
var isExist = await _equipInfoRepository.QueryByClauseAsync(u => var equipInfoTask = _equipInfoRepository.QueryByClauseAsync(u =>
(u.Name == input.Name || u.Code == input.Code) && u.Id != input.Id); (u.Name == input.Name || u.Code == input.Code) && u.Id != input.Id);
var equipNetInfoTask = _equipNetInfoRepository.QueryByClauseAsync(u => u.Code == input.Code);
await Task.WhenAll(equipInfoTask, equipNetInfoTask);
var isExist = equipInfoTask.Result;
var isExistNetInfo = equipNetInfoTask.Result;
if (isExist != null) if (isExist != null)
{ {
return Result<string>.Fail("已存在同名或同编码设备信息"); return Result<string>.Fail("已存在同名或同编码设备信息");
} }
var config = input.Adapt<EquipInfo>(); var config = input.Adapt<EquipInfo>();
int updateResult = await _equipInfoRepository.UpdateAsync(config, true); var configNetInfo = input.Adapt<EquipNetInfo>();
if (updateResult > 0)
EquipInfo equipInfo = await _equipInfoRepository.QueryByClauseAsync(u => u.Code == input.Code);
if (equipInfo != null && isExistNetInfo == null)
{
var equipNetInfo = input.Adapt<EquipNetInfo>();
var insertEquipNetInfoTask = await _equipNetInfoRepository.InsertAsync(equipNetInfo);
configNetInfo.Id = insertEquipNetInfoTask.Id;
}
else
{
configNetInfo.Id = isExistNetInfo.Id;
}
var updateEquipInfoTask = _equipInfoRepository.UpdateAsync(config, true);
var updateEquipNetInfoTask = _equipNetInfoRepository.UpdateAsync(configNetInfo, true);
await Task.WhenAll(updateEquipInfoTask, updateEquipNetInfoTask);
var updateResult = updateEquipInfoTask.Result;
var updateResultNetInfo = updateEquipNetInfoTask.Result;
if (updateResult > 0 && updateResultNetInfo > 0)
{ {
return Result<string>.Success("修改成功"); return Result<string>.Success("修改成功");
} }
@ -103,14 +182,29 @@ namespace Service.Station
/// <returns></returns> /// <returns></returns>
public async Task<Result<string>> DeleteEquipInfo(DeleteEquipInfoReq input) public async Task<Result<string>> DeleteEquipInfo(DeleteEquipInfoReq input)
{ {
// 查询 EquipInfo
var equipInfo = await _equipInfoRepository.QueryByClauseAsync(u => u.Id == input.Id); var equipInfo = await _equipInfoRepository.QueryByClauseAsync(u => u.Id == input.Id);
if (equipInfo==null) if (equipInfo == null)
{ {
return Result<string>.Fail("id不存在"); return Result<string>.Fail("id不存在");
}
// 查询 EquipNetInfo
var equipNetInfo = await _equipNetInfoRepository.QueryByClauseAsync(u => u.Code == equipInfo.Code);
if (equipNetInfo == null)
{
return Result<string>.Fail("设备通信列表不存在此编码");
} }
bool deleteResult = await _equipInfoRepository.DeleteAsync(equipInfo);
if (deleteResult) var deleteEquipInfoTask = _equipInfoRepository.DeleteAsync(equipInfo);
var deleteEquipNetInfoTask = _equipNetInfoRepository.DeleteAsync(equipNetInfo);
await Task.WhenAll(deleteEquipInfoTask, deleteEquipNetInfoTask);
var deleteResult = deleteEquipInfoTask.Result;
var deleteResultNetInfo = deleteEquipNetInfoTask.Result;
if (deleteResult && deleteResultNetInfo)
{ {
return Result<string>.Success("删除设备信息成功"); return Result<string>.Success("删除设备信息成功");
} }

@ -1,5 +1,6 @@
using Entity.DbModel.Station; using Entity.DbModel.Station;
using Entity.Dto.Req; using Entity.Dto.Req;
using Entity.Dto.Resp;
using HybirdFrameworkCore.Entity; using HybirdFrameworkCore.Entity;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Service.Station; using Service.Station;
@ -31,9 +32,9 @@ public class EquipInfoController
/// <returns></returns> /// <returns></returns>
[HttpPost] [HttpPost]
[Route("page")] [Route("page")]
public async Task<Result<PageResult<EquipInfo>>> Page(PageEquipInfoReq input) public async Task<Result<PageResult<EquipInfoResp>>> Page(PageEquipInfoReq input)
{ {
return Result<PageResult<EquipInfo>>.Success(await _equipInfoService.Page(input)); return Result<PageResult<EquipInfoResp>>.Success(await _equipInfoService.Page(input));
} }
/// <summary> /// <summary>

Loading…
Cancel
Save