From 43b99fbf1e38d6ed7f1ff26d231c0a736415f8cb Mon Sep 17 00:00:00 2001
From: tq <1916474859@qq,com>
Date: Mon, 1 Jul 2024 16:45:23 +0800
Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E5=88=97=E8=A1=A8=E4=BC=98?=
=?UTF-8?q?=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Entity/Dto/Req/EquipInfoReq.cs | 20 +++
Entity/Dto/Resp/EquipInfoResp.cs | 76 +++++++++++
Service/Station/EquipInfoService.cs | 124 +++++++++++++++---
WebStarter/Controllers/EquipInfoController.cs | 5 +-
4 files changed, 208 insertions(+), 17 deletions(-)
create mode 100644 Entity/Dto/Resp/EquipInfoResp.cs
diff --git a/Entity/Dto/Req/EquipInfoReq.cs b/Entity/Dto/Req/EquipInfoReq.cs
index 82e18b7..e50db98 100644
--- a/Entity/Dto/Req/EquipInfoReq.cs
+++ b/Entity/Dto/Req/EquipInfoReq.cs
@@ -36,6 +36,26 @@ public class PageEquipInfoReq : QueryPageModel
public class AddEquipInfoReq : EquipInfo
{
+ ///
+ /// Desc:连接地址
+ /// Default:
+ /// Nullable:True
+ ///
+ public string NetAddr { get; set; }
+
+ ///
+ /// Desc:连接端口
+ /// Default:
+ /// Nullable:True
+ ///
+ public string NetPort { get; set; }
+
+ ///
+ /// Desc:目的地址;(十六进制,如0a,02,03,04)
+ /// Default:
+ /// Nullable:True
+ ///
+ public string DestAddr { get; set; }
}
public class UpdateEquipInfoReq : AddEquipInfoReq
diff --git a/Entity/Dto/Resp/EquipInfoResp.cs b/Entity/Dto/Resp/EquipInfoResp.cs
new file mode 100644
index 0000000..9531751
--- /dev/null
+++ b/Entity/Dto/Resp/EquipInfoResp.cs
@@ -0,0 +1,76 @@
+namespace Entity.Dto.Resp;
+
+///
+/// 设备信息resp
+///
+public class EquipInfoResp
+{
+ ///
+ /// Desc:id
+ /// Default:
+ /// Nullable:False
+ ///
+ public int Id { get; set; }
+
+ ///
+ /// Desc:设备编码
+ /// Default:
+ /// Nullable:True
+ ///
+ public string Code { get; set; }
+
+ ///
+ /// Desc:设备名称
+ /// Default:
+ /// Nullable:True
+ ///
+ public string Name { get; set; }
+
+ ///
+ /// Desc:设备类型编码 0交流,1直流
+ /// Default:
+ /// Nullable:True
+ ///
+ public int? TypeCode { get; set; }
+
+ ///
+ /// Desc:设备状态;0-未知;1-正常;2-报警;3-停用
+ /// Default:
+ /// Nullable:True
+ ///
+ public int? Status { get; set; }
+
+ ///
+ /// Desc:0-手动;1-自动充电
+ /// Default:
+ /// Nullable:True
+ ///
+ public int? AutoCharge { get; set; }
+
+ ///
+ /// 充电功率
+ ///
+ public float? ChargePower { get; set; }
+
+
+ ///
+ /// Desc:连接地址
+ /// Default:
+ /// Nullable:True
+ ///
+ public string NetAddr { get; set; }
+
+ ///
+ /// Desc:连接端口
+ /// Default:
+ /// Nullable:True
+ ///
+ public string NetPort { get; set; }
+
+ ///
+ /// Desc:目的地址;(十六进制,如0a,02,03,04)
+ /// Default:
+ /// Nullable:True
+ ///
+ public string DestAddr { get; set; }
+}
\ No newline at end of file
diff --git a/Service/Station/EquipInfoService.cs b/Service/Station/EquipInfoService.cs
index c6ab83f..4979801 100644
--- a/Service/Station/EquipInfoService.cs
+++ b/Service/Station/EquipInfoService.cs
@@ -9,7 +9,9 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using AutoMapper;
using Entity.Dto.Req;
+using Entity.Dto.Resp;
using HybirdFrameworkCore.Entity;
using Mapster;
using SqlSugar;
@@ -20,10 +22,12 @@ namespace Service.Station
public class EquipInfoService : BaseServices
{
EquipInfoRepository _equipInfoRepository;
+ EquipNetInfoRepository _equipNetInfoRepository;
- public EquipInfoService(EquipInfoRepository service)
+ public EquipInfoService(EquipInfoRepository service,EquipNetInfoRepository repository)
{
_equipInfoRepository = service;
+ _equipNetInfoRepository = repository;
this.BaseDal = service;
}
@@ -32,20 +36,45 @@ namespace Service.Station
///
///
///
- public async Task> Page(PageEquipInfoReq input)
+ public async Task> Page(PageEquipInfoReq input)
{
RefAsync total = 0;
- var items = await _equipInfoRepository.EquipInfoQueryPageAsync(
+
+ List 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()
+
+ List equipNetInfoList = await _equipNetInfoRepository.QueryAsync();
+
+ Dictionary equipNetInfoDict = equipNetInfoList.ToDictionary(e => e.Code);
+
+
+ var config = new MapperConfiguration(cfg =>
+ {
+ cfg.CreateMap().ReverseMap();
+ });
+ IMapper mapper = config.CreateMapper();
+
+ List respList = mapper.Map>(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
{
PageNum = input.PageNum,
PageSize = input.PageSize,
ToTal = total,
- Rows = items,
+ Rows = respList
};
}
@@ -56,15 +85,37 @@ namespace Service.Station
///
public async Task> AddEquipInfo(AddEquipInfoReq input)
{
- var isExist =
- await _equipInfoRepository.QueryByClauseAsync(u => u.Name == input.Name || u.Code == input.Code);
+ var existingEquipInfoTask =
+ _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)
{
return Result.Fail("已存在同名或同编码设备信息");
}
- EquipInfo insertAsync = await _equipInfoRepository.InsertAsync(input.Adapt());
- if (insertAsync.Id > 0)
+ if (isNetInfoExist != null)
+ {
+ return Result.Fail("编码在通信设备配置表已存在");
+ }
+
+ var equipInfo = input.Adapt();
+ var equipNetInfo = input.Adapt();
+
+ 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.Success("新增id:" + insertAsync.Id);
}
@@ -79,16 +130,44 @@ namespace Service.Station
///
public async Task> 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);
+ 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)
{
return Result.Fail("已存在同名或同编码设备信息");
}
var config = input.Adapt();
- int updateResult = await _equipInfoRepository.UpdateAsync(config, true);
- if (updateResult > 0)
+ var configNetInfo = input.Adapt();
+
+ EquipInfo equipInfo = await _equipInfoRepository.QueryByClauseAsync(u => u.Code == input.Code);
+ if (equipInfo != null && isExistNetInfo == null)
+ {
+ var equipNetInfo = input.Adapt();
+ 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.Success("修改成功");
}
@@ -103,14 +182,29 @@ namespace Service.Station
///
public async Task> DeleteEquipInfo(DeleteEquipInfoReq input)
{
+ // 查询 EquipInfo
var equipInfo = await _equipInfoRepository.QueryByClauseAsync(u => u.Id == input.Id);
- if (equipInfo==null)
+ if (equipInfo == null)
{
return Result.Fail("id不存在");
+ }
+ // 查询 EquipNetInfo
+ var equipNetInfo = await _equipNetInfoRepository.QueryByClauseAsync(u => u.Code == equipInfo.Code);
+ if (equipNetInfo == null)
+ {
+ return Result.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.Success("删除设备信息成功");
}
diff --git a/WebStarter/Controllers/EquipInfoController.cs b/WebStarter/Controllers/EquipInfoController.cs
index 0e52921..d72df5f 100644
--- a/WebStarter/Controllers/EquipInfoController.cs
+++ b/WebStarter/Controllers/EquipInfoController.cs
@@ -1,5 +1,6 @@
using Entity.DbModel.Station;
using Entity.Dto.Req;
+using Entity.Dto.Resp;
using HybirdFrameworkCore.Entity;
using Microsoft.AspNetCore.Mvc;
using Service.Station;
@@ -31,9 +32,9 @@ public class EquipInfoController
///
[HttpPost]
[Route("page")]
- public async Task>> Page(PageEquipInfoReq input)
+ public async Task>> Page(PageEquipInfoReq input)
{
- return Result>.Success(await _equipInfoService.Page(input));
+ return Result>.Success(await _equipInfoService.Page(input));
}
///