|
|
|
@ -1,5 +1,6 @@
|
|
|
|
using System;
|
|
|
|
using System;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using CncModels.Dto;
|
|
|
|
using CncModels.Dto;
|
|
|
|
using CncModels.Dto.CollectAddress;
|
|
|
|
using CncModels.Dto.CollectAddress;
|
|
|
|
using CncRepository.Interface;
|
|
|
|
using CncRepository.Interface;
|
|
|
|
@ -17,14 +18,20 @@ namespace CncService.Impl
|
|
|
|
private readonly ICollectAddressRepository _collectAddressRepository;
|
|
|
|
private readonly ICollectAddressRepository _collectAddressRepository;
|
|
|
|
private readonly IMachineRepository _machineRepository;
|
|
|
|
private readonly IMachineRepository _machineRepository;
|
|
|
|
private readonly IBrandRepository _brandRepository;
|
|
|
|
private readonly IBrandRepository _brandRepository;
|
|
|
|
|
|
|
|
private readonly IWorkshopRepository _workshopRepository;
|
|
|
|
|
|
|
|
private readonly ICollectRawRepository _collectRawRepository;
|
|
|
|
|
|
|
|
|
|
|
|
public CollectAddressService(ICollectAddressRepository collectAddressRepository,
|
|
|
|
public CollectAddressService(ICollectAddressRepository collectAddressRepository,
|
|
|
|
IMachineRepository machineRepository,
|
|
|
|
IMachineRepository machineRepository,
|
|
|
|
IBrandRepository brandRepository)
|
|
|
|
IBrandRepository brandRepository,
|
|
|
|
|
|
|
|
IWorkshopRepository workshopRepository,
|
|
|
|
|
|
|
|
ICollectRawRepository collectRawRepository)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_collectAddressRepository = collectAddressRepository;
|
|
|
|
_collectAddressRepository = collectAddressRepository;
|
|
|
|
_machineRepository = machineRepository;
|
|
|
|
_machineRepository = machineRepository;
|
|
|
|
_brandRepository = brandRepository;
|
|
|
|
_brandRepository = brandRepository;
|
|
|
|
|
|
|
|
_workshopRepository = workshopRepository;
|
|
|
|
|
|
|
|
_collectRawRepository = collectRawRepository;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public PagedResult<CollectAddressListItem> GetList(CollectAddressQuery query)
|
|
|
|
public PagedResult<CollectAddressListItem> GetList(CollectAddressQuery query)
|
|
|
|
@ -94,5 +101,73 @@ namespace CncService.Impl
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return _collectAddressRepository.ToggleEnabled(id);
|
|
|
|
return _collectAddressRepository.ToggleEnabled(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
|
|
|
public List<CollectAddressMachineItem> GetMachines(int collectAddressId)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var machines = _machineRepository.GetEnabledByAddressId(collectAddressId);
|
|
|
|
|
|
|
|
var result = new List<CollectAddressMachineItem>();
|
|
|
|
|
|
|
|
foreach (var m in machines)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
string workshopName = null;
|
|
|
|
|
|
|
|
if (m.WorkshopId > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var workshop = _workshopRepository.GetById(m.WorkshopId);
|
|
|
|
|
|
|
|
if (workshop != null) workshopName = workshop.Name;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
result.Add(new CollectAddressMachineItem
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
MachineName = m.Name ?? m.DeviceCode,
|
|
|
|
|
|
|
|
DeviceCode = m.DeviceCode,
|
|
|
|
|
|
|
|
WorkshopName = workshopName,
|
|
|
|
|
|
|
|
IsOnline = m.IsOnline == 1,
|
|
|
|
|
|
|
|
ProgramName = m.LastProgramName
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
|
|
|
public List<CollectAddressRecordItem> GetCollectRecords(int collectAddressId)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var paged = _collectRawRepository.GetByAddressId(collectAddressId, 1, 20);
|
|
|
|
|
|
|
|
var result = new List<CollectAddressRecordItem>();
|
|
|
|
|
|
|
|
foreach (var r in paged.Items)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
result.Add(new CollectAddressRecordItem
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
RequestTime = r.RequestTime.ToString("yyyy-MM-dd HH:mm:ss"),
|
|
|
|
|
|
|
|
Duration = r.ResponseDuration ?? 0,
|
|
|
|
|
|
|
|
IsSuccess = r.IsSuccess == 1,
|
|
|
|
|
|
|
|
MachineCount = 0, // 采集服务运行时从JSON解析得到
|
|
|
|
|
|
|
|
MachineName = ""
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
|
|
|
public CollectAddressRawJsonResponse GetRawJson(int collectAddressId, string recordId = null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// 优先按 recordId(请求时间)查找,否则取最新一条
|
|
|
|
|
|
|
|
CollectRaw raw = null;
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(recordId))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var paged = _collectRawRepository.GetByAddressId(collectAddressId, 1, 100);
|
|
|
|
|
|
|
|
DateTime dt;
|
|
|
|
|
|
|
|
if (DateTime.TryParse(recordId, out dt))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
raw = paged.Items.FirstOrDefault(r => r.RequestTime.ToString("yyyy-MM-dd HH:mm:ss") == recordId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (raw == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
raw = _collectRawRepository.GetLatestByAddressId(collectAddressId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return new CollectAddressRawJsonResponse
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
RawJson = raw?.RawJson ?? "[]"
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|