fix 代码优化
This commit is contained in:
@@ -23,4 +23,9 @@ public class DeviceGroupSaveRequest
|
||||
/// </summary>
|
||||
[EnumDataType(typeof(DeviceTypeEnumType))]
|
||||
public DeviceTypeEnumType? Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
public string Remark { get; set; }
|
||||
}
|
||||
|
||||
@@ -29,6 +29,11 @@ public class DeviceGroupTreeResponse
|
||||
/// </summary>
|
||||
public DeviceTypeEnumType? Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
public string Remark { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 分组类型描述
|
||||
/// </summary>
|
||||
|
||||
@@ -85,10 +85,32 @@ public class DevicePageResponse
|
||||
/// </summary>
|
||||
public bool Enable { get; set; }
|
||||
|
||||
|
||||
//*********************************************************附加信息**************************************************************/
|
||||
|
||||
/// <summary>
|
||||
/// 最后心跳时间
|
||||
/// </summary>
|
||||
public DateTime? LastHeartbeatTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否在线
|
||||
/// </summary>
|
||||
public bool IsOnline { get; set; }
|
||||
public bool IsOnline
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!LastHeartbeatTime.HasValue)
|
||||
return false;
|
||||
else
|
||||
{
|
||||
if (HeartbeatInterval <= 0)
|
||||
return true;
|
||||
else
|
||||
return LastHeartbeatTime.Value.AddSeconds(HeartbeatInterval * 3) >= DateTime.Now;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 消费总额
|
||||
@@ -103,7 +125,7 @@ public class DevicePageResponse
|
||||
/// <summary>
|
||||
/// 营业点code
|
||||
/// </summary>
|
||||
public string BusinessPlaceCode { get; set; }
|
||||
public Guid? BusinessPlaceCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 营业点名称
|
||||
|
||||
@@ -11,11 +11,9 @@ using Kurisu.Core.DataAccess.Dto;
|
||||
using Kurisu.SqlSugar.Extensions;
|
||||
using Kurisu.SqlSugar.Services;
|
||||
using Mapster;
|
||||
using MySqlX.XDevAPI.Relational;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using SqlSugar;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Dlhis.Basic.Device.Services.Implements;
|
||||
|
||||
@@ -32,73 +30,35 @@ public class DeviceService : IDeviceService
|
||||
{
|
||||
var page = await _dbContext.Queryable<DeviceEntity>()
|
||||
.LeftJoin<DeviceTemplateEntity>((d, dt) => d.TemplateCode == dt.Code)
|
||||
.LeftJoin<DeviceRegistryEntity>((d, dt, dr) => d.UniqueNo == dr.DeviceUniqueNo)
|
||||
.LeftJoin<BusinessPlaceEntity>((d, dt, dr, bp) => dr.BusinessPlaceCode == bp.Code)
|
||||
.WhereIF(request.Type.HasValue, (d, dt) => d.Type == request.Type)
|
||||
.Select((d, dt) => new DevicePageResponse
|
||||
.Select((d, dt, dr, bp) => new DevicePageResponse
|
||||
{
|
||||
FuncsStr = d.Funcs.ToString(),
|
||||
Brand = dt.Brand,
|
||||
Type = d.Type,
|
||||
BusinessPlaceCode = bp.Code,
|
||||
BusinessPlaceName = bp.Name,
|
||||
LastHeartbeatTime = dr.LastHeartbeatTime
|
||||
}, true)
|
||||
.ToPageListAsync(request);
|
||||
|
||||
var now = DateTime.Now;
|
||||
var deviceUniqueNos = page.Data.Select(x => x.UniqueNo).ToList();
|
||||
|
||||
var balanceRecords = await _dbContext.Queryable<BalanceRecordEntity>().Where(x => x.Type == BalanceRecordTypeEnumType.Out)
|
||||
.Where(x => deviceUniqueNos.Contains(x.DeviceInfo))
|
||||
.Select(x => new
|
||||
{
|
||||
x.Amount,
|
||||
x.UserCode
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
var deviceRegistries = await _dbContext.Queryable<DeviceRegistryEntity>()
|
||||
.LeftJoin<DeviceEntity>((x, d) => x.DeviceUniqueNo == d.UniqueNo)
|
||||
.Where(x => deviceUniqueNos.Contains(x.DeviceUniqueNo))
|
||||
.Select((x, d) => new
|
||||
{
|
||||
d.HeartbeatInterval,
|
||||
x.LastHeartbeatTime,
|
||||
x.DeviceUniqueNo,
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
var Registries = await _dbContext.Queryable<DeviceRegistryEntity>()
|
||||
.ToListAsync();
|
||||
var BusinessPlaces = await _dbContext.Queryable<BusinessPlaceEntity>()
|
||||
.ToListAsync();
|
||||
|
||||
foreach (var res in page.Data)
|
||||
{
|
||||
var regis = Registries.Where(x => x.DeviceUniqueNo == res.UniqueNo).FirstOrDefault();
|
||||
if (regis != null)
|
||||
{
|
||||
var place = BusinessPlaces.Where(x => x.Code == regis.BusinessPlaceCode).FirstOrDefault();
|
||||
if (place != null)
|
||||
{
|
||||
res.BusinessPlaceCode = regis.BusinessPlaceCode.ToString();
|
||||
res.BusinessPlaceName = place.Name;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
page.Data.ForEach(device =>
|
||||
{
|
||||
device.Amount = balanceRecords.Sum(x => x.Amount);
|
||||
device.UserCount = balanceRecords.DistinctBy(x => x.UserCode).Count();
|
||||
|
||||
var r = deviceRegistries.FirstOrDefault(x => x.DeviceUniqueNo == device.UniqueNo);
|
||||
if (r == null)
|
||||
{
|
||||
device.IsOnline = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (r.HeartbeatInterval <= 0)
|
||||
{
|
||||
device.IsOnline = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
device.IsOnline = r.LastHeartbeatTime.AddSeconds(r.HeartbeatInterval * 3) >= now;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return page;
|
||||
@@ -290,7 +250,7 @@ public class DeviceService : IDeviceService
|
||||
public async Task<DeviceNumberResponse> GetDeviceNumberAsync()
|
||||
{
|
||||
var devices = await _dbContext.Queryable<DeviceEntity>().Where(x => x.Type == DeviceTypeEnumType.Attendance || (x.Type == DeviceTypeEnumType.Door && x.AsAttendance)).ToListAsync();
|
||||
|
||||
|
||||
var offlineNumber = await GetOfflineDevicesCount(devices);
|
||||
|
||||
var res = new DeviceNumberResponse
|
||||
@@ -333,7 +293,7 @@ public class DeviceService : IDeviceService
|
||||
return x.LastHeartbeatTime.AddSeconds(x.HeartbeatInterval * 3) >= now;
|
||||
|
||||
})
|
||||
.Select(x => new
|
||||
.Select(x => new
|
||||
{
|
||||
UniqueNo = x.UniqueNo,
|
||||
})
|
||||
@@ -345,7 +305,7 @@ public class DeviceService : IDeviceService
|
||||
var list = devices.Where(x => offUniqueNos.Contains(x.UniqueNo)).ToList();
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async Task<Pagination<DevicePageResponse>> GetAttendanceTotalAsync(AttendanceTotalRequest request)
|
||||
{
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using Dlhis.Basic.Organization.Response;
|
||||
using Dlhis.Basic.Organization.Services;
|
||||
using Dlhis.User.Api.Response;
|
||||
using Dlhis.Basic.Organization.Services;
|
||||
using Dlhis.Sys.Api.Response;
|
||||
using Kurisu.AspNetCore.MVC;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
@@ -2,6 +2,11 @@
|
||||
|
||||
public class DepartmentTreeResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// 上级
|
||||
/// </summary>
|
||||
public string PNo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 部门号
|
||||
/// </summary>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Dlhis.User.Api.Response;
|
||||
using Dlhis.Sys.Api.Response;
|
||||
|
||||
namespace Dlhis.Basic.Organization.Services;
|
||||
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
using Dlhis.Basic.Organization.Request;
|
||||
using Dlhis.Basic.Organization.Response;
|
||||
using Dlhis.Basic.Organization.Response;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
using Kurisu.Core.User.Abstractions;
|
||||
using Kurisu.SqlSugar.Services;
|
||||
using Mapster;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Dlhis.Basic.Organization.Services.Implements;
|
||||
|
||||
public class DepartmentService : IDepartmentService
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly ICurrentUser _currentUser;
|
||||
|
||||
public DepartmentService(IDbContext dbContext)
|
||||
public DepartmentService(IDbContext dbContext, ICurrentUser currentUser)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_currentUser = currentUser;
|
||||
}
|
||||
|
||||
public async Task<List<DepartmentTreeResponse>> GetTreeAsync()
|
||||
{
|
||||
var departments = await _dbContext.Queryable<DepartmentEntity>().ToListAsync();
|
||||
var myTenants = _currentUser.GetUserClaim("tenants").Split(',').ToList();
|
||||
|
||||
var departments = await _dbContext.Queryable<DepartmentEntity>().Select<DepartmentTreeResponse>().ToListAsync();
|
||||
//00001000 一定是这个开头的
|
||||
var tops = departments.Where(x => x.PNo == "00001000").Adapt<List<DepartmentTreeResponse>>();
|
||||
var tops = departments.Where(x => x.PNo == "00001000").ToList();
|
||||
|
||||
tops.ForEach(x =>
|
||||
{
|
||||
@@ -32,13 +32,13 @@ public class DepartmentService : IDepartmentService
|
||||
return tops;
|
||||
}
|
||||
|
||||
private void RecursionGetNext(DepartmentTreeResponse current, List<DepartmentEntity> departments)
|
||||
private void RecursionGetNext(DepartmentTreeResponse current, List<DepartmentTreeResponse> data)
|
||||
{
|
||||
var next = departments.Where(x => x.PNo == current.No).ToList();
|
||||
current.Next = next.Adapt<List<DepartmentTreeResponse>>();
|
||||
var next = data.Where(x => x.PNo == current.No).ToList();
|
||||
current.Next = next;
|
||||
foreach (var item in next)
|
||||
{
|
||||
RecursionGetNext(item.Adapt<DepartmentTreeResponse>(), departments);
|
||||
RecursionGetNext(item, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Dlhis.Sys.Api;
|
||||
using Dlhis.User.Api.Response;
|
||||
using Dlhis.Sys.Api.Response;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Kurisu.Core.Result;
|
||||
using Kurisu.Core.User.Abstractions;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Dlhis.Sys.Api;
|
||||
using Dlhis.User.Api.Response;
|
||||
using Dlhis.Sys.Api.Response;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Kurisu.Core.DataAccess.Entity;
|
||||
using Kurisu.SqlSugar.Services;
|
||||
@@ -29,6 +29,8 @@ public class CreateDefinitelyGroupJob
|
||||
sqlSugarOptionsService.IgnoreTenant = true;
|
||||
}
|
||||
|
||||
private static readonly string _remark = "系统自动生成";
|
||||
|
||||
public async Task RunAsync()
|
||||
{
|
||||
_dbContext.Client.QueryFilter.ClearAndBackup<ITenantId>();
|
||||
@@ -77,6 +79,7 @@ public class CreateDefinitelyGroupJob
|
||||
Name = grp,
|
||||
IsDefault = grp.Equals("*自定义人员分组"),
|
||||
Editable = false,
|
||||
Remark = _remark,
|
||||
|
||||
CreatedBy = 1,
|
||||
CreateTime = DateTime.Now,
|
||||
@@ -103,6 +106,7 @@ public class CreateDefinitelyGroupJob
|
||||
Type = type,
|
||||
Name = grp,
|
||||
Editable = false,
|
||||
Remark = _remark,
|
||||
|
||||
CreatedBy = 1,
|
||||
CreateTime = DateTime.Now,
|
||||
@@ -126,6 +130,7 @@ public class CreateDefinitelyGroupJob
|
||||
Type = type,
|
||||
Name = workplaceName,
|
||||
Editable = false,
|
||||
Remark = _remark,
|
||||
|
||||
CreatedBy = 1,
|
||||
CreateTime = DateTime.Now,
|
||||
@@ -148,6 +153,7 @@ public class CreateDefinitelyGroupJob
|
||||
Type = type,
|
||||
Name = factoryName,
|
||||
Editable = false,
|
||||
Remark = _remark,
|
||||
|
||||
CreatedBy = 1,
|
||||
CreateTime = DateTime.Now,
|
||||
|
||||
@@ -57,6 +57,11 @@ public class DeviceTaskAssignmentResponse
|
||||
/// </summary>
|
||||
public string ResultMessage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 任务创建时间
|
||||
/// </summary>
|
||||
public DateTime CreateTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 数据状态最新修改时间
|
||||
/// </summary>
|
||||
|
||||
@@ -38,6 +38,7 @@ public class DeviceTaskAssignmentService : IDeviceTaskAssignmentService
|
||||
UserName = ga.Name,
|
||||
UserCode = ga.Code,
|
||||
Type = deviceTask.Type,
|
||||
CreateTime = deviceTask.CreateTime,
|
||||
LastUpdateTime = deviceTask.ModifiedTime
|
||||
})
|
||||
.ToPageListAsync(request);
|
||||
|
||||
Reference in New Issue
Block a user