.NETAdmin/ZR.Admin.WebApi/Controllers/Business/OdfFramesController.cs
2025-08-06 09:46:50 +08:00

178 lines
6.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Microsoft.AspNetCore.Mvc;
using ZR.Model.Business.Dto;
using ZR.Model.Business;
using ZR.Service.Business.IBusinessService;
using ZR.Service.Business;
//创建时间2025-08-05
namespace ZR.Admin.WebApi.Controllers.Business
{
/// <summary>
/// 框-信息
/// </summary>
[Route("business/OdfFrames")]
public class OdfFramesController : BaseController
{
/// <summary>
/// 框-信息接口
/// </summary>
private readonly IOdfFramesService _OdfFramesService;
/// <summary>
/// 端口
/// </summary>
private readonly IOdfPortsService _OdfPortsService;
/// <summary>
/// 机架列表接口
/// </summary>
private readonly IOdfRacksService _OdfRacksService;
private readonly IOdfRoomsService _odfRooms;
public OdfFramesController(IOdfRacksService OdfRacksService, IOdfRoomsService odfRooms,
IOdfFramesService odfFramesService,
IOdfPortsService odfPortsService)
{
_OdfRacksService = OdfRacksService;
_odfRooms = odfRooms;
_OdfFramesService = odfFramesService;
_OdfPortsService = odfPortsService;
}
/// <summary>
/// 查询框-信息列表
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
[HttpGet("list")]
[ActionPermissionFilter(Permission = "odfframes:list")]
public IActionResult QueryOdfFrames([FromQuery] OdfFramesQueryDto parm)
{
var response = _OdfFramesService.GetList(parm);
return SUCCESS(response);
}
/// <summary>
/// 查询框-信息详情
/// </summary>
/// <param name="Id"></param>
/// <returns></returns>
[HttpGet("{Id}")]
[ActionPermissionFilter(Permission = "odfframes:query")]
public IActionResult GetOdfFrames(int Id)
{
var response = _OdfFramesService.GetInfo(Id);
var info = response.Adapt<OdfFramesDto>();
return SUCCESS(info);
}
/// <summary>
/// 添加框-信息
/// </summary>
/// <returns></returns>
[HttpPost]
[ActionPermissionFilter(Permission = "odfframes:add")]
[Log(Title = "框-信息", BusinessType = BusinessType.INSERT)]
public async Task<IActionResult> AddOdfFrames([FromBody] OdfFramesExpertDto parm)
{
var modal = parm.Adapt<OdfFrames>().ToCreate(HttpContext);
var rooms = _odfRooms.GetById(parm.RoomId);
if (rooms == null)
{
return ToResponse(ResultCode.FAIL, "机房不存在");
}
modal.DeptId = rooms.DeptId ?? 0;
modal.RackId = parm.RackId;
modal.PortsRow = parm.RowCount;
modal.PortsCol = parm.PortsCount;
modal.PortsCount = parm.RowCount * parm.PortsCount;
modal.UpdateAt = DateTime.Now;
modal.CreatedAt = DateTime.Now;
var response = _OdfFramesService.AddOdfFrames(modal);
var roomId = rooms.Id;
var roomName = rooms.RoomName;
var ra = _OdfRacksService.GetById(modal.RackId);
//添加机框结束
if (parm.RowCount > 0)
{
//添加行
if (parm.PortsCount > 0)
{
int index = 0;
//添加端口
var frame = response;
List<OdfPorts> ports = new List<OdfPorts>();
for (int row = 0; row < parm.RowCount; row++)
{
for (int port = 0; port < parm.PortsCount; port++)
{
ports.Add(new OdfPorts()
{
CreatedAt = DateTime.Now,
DeptId = rooms.DeptId ?? 0,
DeptName = rooms.DeptName,
RackId = frame.RackId,
RackName = ra.RackName,
RoomId = roomId,
RoomName = roomName,
FrameId = frame.Id,
FrameName = frame.PortsName,
Name = $"{(row + 1)}-{(port + 1)}",
RowNumber = row,
PortNumber = port,
OpticalAttenuation = "",
HistoryRemarks = "",
Remarks = "",
Status = parm.DefaultStatus,
UpdatedAt = DateTime.Now,
});
}
}
await _OdfPortsService.AsInsertable(ports).ExecuteReturnEntityAsync(true);
//如果超过100个机框则休眠一下防止服务器死机
index++;
if (index > 100)
{
Thread.Sleep(50);
index = 0;
}
}
}
return SUCCESS(response);
}
/// <summary>
/// 更新框-信息
/// </summary>
/// <returns></returns>
[HttpPut]
[ActionPermissionFilter(Permission = "odfframes:edit")]
[Log(Title = "框-信息", BusinessType = BusinessType.UPDATE)]
public IActionResult UpdateOdfFrames([FromBody] OdfFramesDto parm)
{
var modal = parm.Adapt<OdfFrames>().ToUpdate(HttpContext);
var response = _OdfFramesService.UpdateOdfFrames(modal);
return ToResponse(response);
}
/// <summary>
/// 删除框-信息
/// </summary>
/// <returns></returns>
[HttpPost("delete/{ids}")]
[ActionPermissionFilter(Permission = "odfframes:delete")]
[Log(Title = "框-信息", BusinessType = BusinessType.DELETE)]
public IActionResult DeleteOdfFrames([FromRoute] string ids)
{
var idArr = Tools.SplitAndConvert<int>(ids);
return ToResponse(_OdfFramesService.Delete(idArr, "删除框-信息"));
}
}
}