196 lines
7.0 KiB
C#
196 lines
7.0 KiB
C#
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 async Task<IActionResult> UpdateOdfFrames([FromBody] OdfFramesDto parm)
|
||
{
|
||
var modal = parm.Adapt<OdfFrames>().ToUpdate(HttpContext);
|
||
var oldModel = _OdfFramesService.GetById(parm.Id);
|
||
var response = _OdfFramesService.UpdateOdfFrames(modal);
|
||
if (response > 0)
|
||
{
|
||
var rortsName = oldModel.PortsName;
|
||
var frameId = modal.Id;
|
||
var rackId = modal.RackId;
|
||
|
||
if (oldModel.PortsName != modal.PortsName)
|
||
{
|
||
// 最直接的转换
|
||
await _OdfPortsService.UpdateAsync(
|
||
it => it.FrameId == frameId && it.RackId == rackId, // WHERE条件
|
||
it => new OdfPorts // SET部分
|
||
{
|
||
FrameName = modal.PortsName,
|
||
}
|
||
);
|
||
}
|
||
}
|
||
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, "删除框-信息"));
|
||
}
|
||
|
||
}
|
||
} |