2026-07-02 18:13:56 +08:00
|
|
|
using Microsoft.EntityFrameworkCore;
|
2026-07-03 10:47:27 +08:00
|
|
|
using WCTDataMiner.Core.Data;
|
|
|
|
|
using WCTDataMiner.Core.Models;
|
2026-07-02 18:13:56 +08:00
|
|
|
|
2026-07-03 10:47:27 +08:00
|
|
|
namespace WCTDataMiner.Core.Services;
|
2026-07-02 18:13:56 +08:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 维度表管理服务 - 负责维度表的CRUD操作
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class DimensionService
|
|
|
|
|
{
|
|
|
|
|
private readonly WctMinerDbContext _context;
|
|
|
|
|
|
|
|
|
|
public DimensionService(WctMinerDbContext context)
|
|
|
|
|
{
|
|
|
|
|
_context = context;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取或创建TX面板维度
|
|
|
|
|
/// </summary>
|
|
|
|
|
public async Task<TxPanel> GetOrCreateTxPanelAsync(string name)
|
|
|
|
|
{
|
|
|
|
|
var existing = await _context.TxPanels
|
|
|
|
|
.FirstOrDefaultAsync(p => p.Name == name);
|
|
|
|
|
|
|
|
|
|
if (existing != null) return existing;
|
|
|
|
|
|
|
|
|
|
var newPanel = new TxPanel { Name = name };
|
|
|
|
|
_context.TxPanels.Add(newPanel);
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
return newPanel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取或创建TX硬件版本维度
|
|
|
|
|
/// </summary>
|
|
|
|
|
public async Task<TxHardware> GetOrCreateTxHardwareAsync(string version)
|
|
|
|
|
{
|
|
|
|
|
var existing = await _context.TxHardwares
|
|
|
|
|
.FirstOrDefaultAsync(h => h.Version == version);
|
|
|
|
|
|
|
|
|
|
if (existing != null) return existing;
|
|
|
|
|
|
|
|
|
|
var newHardware = new TxHardware { Version = version };
|
|
|
|
|
_context.TxHardwares.Add(newHardware);
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
return newHardware;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取或创建TX软件版本维度
|
|
|
|
|
/// </summary>
|
|
|
|
|
public async Task<TxSoftware> GetOrCreateTxSoftwareAsync(string version)
|
|
|
|
|
{
|
|
|
|
|
var existing = await _context.TxSoftwares
|
|
|
|
|
.FirstOrDefaultAsync(s => s.Version == version);
|
|
|
|
|
|
|
|
|
|
if (existing != null) return existing;
|
|
|
|
|
|
|
|
|
|
var newSoftware = new TxSoftware { Version = version };
|
|
|
|
|
_context.TxSoftwares.Add(newSoftware);
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
return newSoftware;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取或创建RX类型维度
|
|
|
|
|
/// </summary>
|
|
|
|
|
public async Task<RxType> GetOrCreateRxTypeAsync(string name)
|
|
|
|
|
{
|
|
|
|
|
var existing = await _context.RxTypes
|
|
|
|
|
.FirstOrDefaultAsync(r => r.Name == name);
|
|
|
|
|
|
|
|
|
|
if (existing != null) return existing;
|
|
|
|
|
|
|
|
|
|
var newRxType = new RxType { Name = name };
|
|
|
|
|
_context.RxTypes.Add(newRxType);
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
return newRxType;
|
|
|
|
|
}
|
|
|
|
|
}
|