fix 修改营业点分页模糊搜索条件
This commit is contained in:
@@ -100,7 +100,7 @@ public class BusinessPlacesController : ControllerBase
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("devicenos")]
|
||||
public async Task<List<DeviceCodeNameDetail>> GetDevicesByCode([FromQuery]BusinessPlaceGetByCodeRequest request)
|
||||
public async Task<Pagination<DeviceCodeNameDetail>> GetDevicesByCode([FromQuery]BusinessPlaceGetByCodeRequest request)
|
||||
{
|
||||
return await _businessPlaceShiftService.GetDevicesByCode(request);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,8 @@ public class BusinessPlaceService : IBusinessPlaceService
|
||||
var page = await _dbContext.Queryable<BusinessPlaceEntity>()
|
||||
.LeftJoin<BusinessPlaceShiftRelationshipEntity>((x, ps) => x.Code == ps.PlaceCode)
|
||||
.LeftJoin<BusinessShiftEntity>((x, ps, s) => s.Code == ps.ShiftCode)
|
||||
.WhereIF(request.Search.IsPresent(), x => x.CustomCode.Contains(request.Search))
|
||||
.WhereIF(request.Search.IsPresent(), x => x.CustomCode.Contains(request.Search)
|
||||
|| x.Code.ToString().Contains(request.Search) || x.Name.Contains(request.Search))
|
||||
.WhereIF(request.Catalog.HasValue, x => x.Catalog == request.Catalog)
|
||||
.WhereIF(request.Status.HasValue, x => x.Status == request.Status)
|
||||
.WhereIF(request.Source.HasValue, x => x.Source == request.Source)
|
||||
|
||||
@@ -18,5 +18,5 @@ public interface IBusinessPlaceShiftService : IScopeDependency
|
||||
|
||||
Task<BusinessPlaceWithShiftResponse> GetShiftsByPlaceCustomCodeAsync(string placeCustomCode);
|
||||
|
||||
Task<List<DeviceCodeNameDetail>> GetDevicesByCode(BusinessPlaceGetByCodeRequest request);
|
||||
Task<Pagination<DeviceCodeNameDetail>> GetDevicesByCode(BusinessPlaceGetByCodeRequest request);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ using Kurisu.Core.Result;
|
||||
using Kurisu.SqlSugar.Extensions;
|
||||
using Kurisu.SqlSugar.Services;
|
||||
using Mapster;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Dlhis.Basic.BusinessShift.Services.Implements;
|
||||
|
||||
@@ -190,7 +191,7 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<List<DeviceCodeNameDetail>> GetDevicesByCode(BusinessPlaceGetByCodeRequest request)
|
||||
public async Task<Pagination<DeviceCodeNameDetail>> GetDevicesByCode(BusinessPlaceGetByCodeRequest request)
|
||||
{
|
||||
var regiss = await _dbContext.Queryable<DeviceRegistryEntity>()
|
||||
.Where(x => x.BusinessPlaceCode.ToString() == request.Code)
|
||||
@@ -216,7 +217,19 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
//分页
|
||||
var startIndex = (request.PageIndex - 1) * request.PageSize;
|
||||
var pagedData = list.Skip(startIndex).Take(request.PageSize).ToList();
|
||||
|
||||
var pagination = new Pagination<DeviceCodeNameDetail>
|
||||
{
|
||||
PageIndex = request.PageIndex,
|
||||
PageSize = request.PageSize,
|
||||
Total = list.Count, // 使用原始列表的总数进行分页
|
||||
Data = pagedData
|
||||
};
|
||||
|
||||
return pagination;
|
||||
}
|
||||
|
||||
//*********************************************** help methods ***************************************************//
|
||||
|
||||
@@ -101,7 +101,12 @@ public class DevicePageResponse
|
||||
public int UserCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设备营业点
|
||||
/// 营业点code
|
||||
/// </summary>
|
||||
public List<PlaceCodeNameDetil> detils { get; set; }
|
||||
public string BusinessPlaceCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 营业点名称
|
||||
/// </summary>
|
||||
public string BusinessPlaceName { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
namespace Dlhis.Basic.Device.Response
|
||||
{
|
||||
public class PlaceCodeNameDetil
|
||||
{
|
||||
public string BusinessPlaceCode { get; set; }
|
||||
public string BusinessPlaceName { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ using MySqlX.XDevAPI.Relational;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using SqlSugar;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Dlhis.Basic.Device.Services.Implements;
|
||||
|
||||
@@ -65,28 +66,16 @@ public class DeviceService : IDeviceService
|
||||
|
||||
foreach (var res in page.Data)
|
||||
{
|
||||
var list = new List<PlaceCodeNameDetil>();
|
||||
var regis = Registries.Where(x => x.DeviceUniqueNo == res.UniqueNo).ToList();
|
||||
if (regis!=null && regis.Count>0)
|
||||
var regis = Registries.Where(x => x.DeviceUniqueNo == res.UniqueNo).FirstOrDefault();
|
||||
if (regis != null)
|
||||
{
|
||||
foreach (var re in regis)
|
||||
var place = BusinessPlaces.Where(x => x.Code == regis.BusinessPlaceCode).FirstOrDefault();
|
||||
if (place != null)
|
||||
{
|
||||
var place = BusinessPlaces.Where(x => x.Code == re.BusinessPlaceCode)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (place != null)
|
||||
{
|
||||
var detil = new PlaceCodeNameDetil
|
||||
{
|
||||
BusinessPlaceCode = re.BusinessPlaceCode.ToString(),
|
||||
BusinessPlaceName = place.Name
|
||||
};
|
||||
list.Add(detil);
|
||||
}
|
||||
|
||||
}
|
||||
res.BusinessPlaceCode = regis.BusinessPlaceCode.ToString();
|
||||
res.BusinessPlaceName = place.Name;
|
||||
}
|
||||
}
|
||||
res.detils = list;
|
||||
|
||||
}
|
||||
page.Data.ForEach(device =>
|
||||
|
||||
@@ -600,25 +600,42 @@ public class BalanceService : IBalanceService
|
||||
/// <returns></returns>
|
||||
private async Task<List<DeviceEntity>> GetOfflineDevicesCount(List<DeviceEntity> devices)
|
||||
{
|
||||
var nos = devices.Select(x => x.UniqueNo).ToList();
|
||||
var deviceRegistrys = await _dbContext.Queryable<DeviceRegistryEntity>()
|
||||
.Where(x => nos.Contains(x.DeviceUniqueNo))
|
||||
var now = DateTime.Now;
|
||||
|
||||
var deviceUniqueNos = devices.Select(x => x.UniqueNo).ToList();
|
||||
|
||||
var deviceRegistries = await _dbContext.Queryable<DeviceRegistryEntity>()
|
||||
.LeftJoin<DeviceEntity>((x, d) => x.DeviceUniqueNo == d.UniqueNo)
|
||||
.Where(x => deviceUniqueNos.Contains(x.DeviceUniqueNo))
|
||||
.Select((x, d) => new
|
||||
{
|
||||
UniqueNo = d.UniqueNo,
|
||||
d.HeartbeatInterval,
|
||||
x.LastHeartbeatTime
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
var list = new List<DeviceEntity>();
|
||||
foreach (var device in devices)
|
||||
{
|
||||
var regis = deviceRegistrys.FirstOrDefault(x => x.DeviceUniqueNo == device.UniqueNo);
|
||||
if (regis == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
TimeSpan timeDifference = DateTime.Now - regis.LastHeartbeatTime;
|
||||
if (timeDifference.TotalSeconds > (device.HeartbeatInterval * 3))
|
||||
{
|
||||
list.Add(device);
|
||||
}
|
||||
}
|
||||
var OnlineDevices = deviceRegistries
|
||||
.Where(x =>
|
||||
{
|
||||
if (x.HeartbeatInterval <= 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return x.LastHeartbeatTime.AddSeconds(x.HeartbeatInterval * 3) >= now;
|
||||
|
||||
})
|
||||
.Select(x => new
|
||||
{
|
||||
UniqueNo = x.UniqueNo,
|
||||
})
|
||||
.ToList();
|
||||
var onlineUniqueNos = new List<string>();
|
||||
OnlineDevices.ForEach(x => onlineUniqueNos.Add(x.UniqueNo));
|
||||
|
||||
var offUniqueNos = deviceUniqueNos.Except(onlineUniqueNos).ToList();
|
||||
var list = devices.Where(x => offUniqueNos.Contains(x.UniqueNo)).ToList();
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user