fix 功能调整

This commit is contained in:
2024-02-01 17:46:40 +08:00
parent 2f5f6be7d7
commit 28871aa450
23 changed files with 164 additions and 59 deletions

View File

@@ -2,12 +2,11 @@
using Dlhis.Basic.BusinessShift.Request;
using Dlhis.Basic.BusinessShift.Response;
using Dlhis.Entity.Basic.Entity;
using Dlhis.User.Api;
using Dlhis.Sys.Api;
using Kurisu.AspNetCore.Utils.Extensions;
using Kurisu.Core.CustomClass;
using Kurisu.Core.DataAccess.Dto;
using Kurisu.Core.Result;
using Kurisu.Core.User.Abstractions;
using Kurisu.SqlSugar.Attributes;
using Kurisu.SqlSugar.Extensions;
using Kurisu.SqlSugar.Services;
@@ -30,8 +29,8 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService
{
var page = await _dbContext.Queryable<CanteenBusinessShiftEntity>()
.LeftJoin<CanteenBusinessPlaceEntity>((shift, place) => shift.BusinessPlaceCode == place.Code)
.LeftJoin<BasicTypeEntity>((shift, place,type)=>shift.Code.ToString() == type.Code)
.WhereIF(request.Search.IsPresent(), (shift, place) => shift.CustomCode.Contains(request.Search) )
.LeftJoin<BasicTypeEntity>((shift, place, type) => shift.Code.ToString() == type.Code)
.WhereIF(request.Search.IsPresent(), (shift, place) => shift.CustomCode.Contains(request.Search))
.WhereIF(request.BusinessPlaceCode.HasValue, (shift, place) => shift.BusinessPlaceCode == request.BusinessPlaceCode)
.Select((shift, place, type) => new BusinessPlaceShiftResponse
{

View File

@@ -19,9 +19,9 @@ public class DeviceGroupSaveRequest
public string Name { get; set; }
/// <summary>
/// 设备组功能类型
/// 分类类型 DeviceTypeEnumType
/// </summary>
[Required(ErrorMessage = "设备组功能类型不能为空")]
[EnumDataType(typeof(DeviceGroupFunctionEnumType))]
public DeviceGroupFunctionEnumType Type { get; set; }
[Required(ErrorMessage = "分类不能为空")]
[EnumDataType(typeof(DeviceTypeEnumType))]
public DeviceTypeEnumType Type { get; set; }
}

View File

@@ -1,16 +1,19 @@
using Kurisu.Core.DataAccess.Dto;
using System.ComponentModel.DataAnnotations;
using Dlhis.Entity.Device.Enums;
using Kurisu.Core.DataAccess.Dto;
namespace Dlhis.Basic.Device.Request;
public class DevicePageRequest : PageDto
{
/// <summary>
/// 平台
/// 品牌
/// </summary>
public string Brand { get; set; }
/// <summary>
/// 设备唯一号
/// 设备分类 DeviceTypeEnumType
/// </summary>
public string UniqueNo { get; set; }
[EnumDataType(typeof(DeviceTypeEnumType))]
public DeviceTypeEnumType? Type { get; set; }
}

View File

@@ -33,11 +33,11 @@ public class DeviceSaveRequest
public List<DeviceFuncEnumType> Funcs { get; set; }
/// <summary>
/// 设备机功能类型
/// 设备类型 DeviceTypeEnumType
/// </summary>
[Required(ErrorMessage = "设备机功能类型不能为空")]
[EnumDataType(typeof(DeviceGroupFunctionEnumType))]
public DeviceGroupFunctionEnumType Type { get; set; }
[Required(ErrorMessage = "设备类型不能为空")]
[EnumDataType(typeof(DeviceTypeEnumType))]
public DeviceTypeEnumType Type { get; set; }
/// <summary>
/// 心跳间隔

View File

@@ -1,7 +1,5 @@
using Dlhis.Entity.Device.Enums;
using Google.Protobuf.WellKnownTypes;
using Kurisu.AspNetCore.Utils.Extensions;
using System.ComponentModel.DataAnnotations;
namespace Dlhis.Basic.Device.Response;
@@ -52,7 +50,7 @@ public class DevicePageResponse
/// <summary>
/// 设备机功能类型
/// </summary>
public DeviceGroupFunctionEnumType Type { get; set; }
public DeviceTypeEnumType Type { get; set; }
public string TypeDescription => Type.GetDescription();

View File

@@ -80,6 +80,7 @@ public class DeviceGroupService : IDeviceGroupService
group.ThrowIfNull("设备组不存在");
await CheckNoNextGroupAsync(group.Code);
await CheckGroupTypeMatchAsync(request, group);
//下发任务
await _devicePermissionService.GenerateDeviceTasksAsync(async () =>
@@ -87,7 +88,7 @@ public class DeviceGroupService : IDeviceGroupService
var relationships = await _dbContext.Queryable<DeviceGroupRelationshipEntity>().Where(x => x.GroupCode == request.GroupCode).ToListAsync();
await _dbContext.DeleteAsync(relationships);
request.DeviceCodes = await _dbContext.Queryable<DeviceEntity>().Where(x => request.DeviceCodes.Contains(x.Code)).Select(x => x.Code).ToListAsync();
var entities = request.DeviceCodes.Select(x => new DeviceGroupRelationshipEntity
{
GroupCode = request.GroupCode,
@@ -115,7 +116,7 @@ public class DeviceGroupService : IDeviceGroupService
/****************************************************** help methods *********************************************************/
/// <summary>
/// 检查
/// 检查父级分组存在设备
/// </summary>
/// <param name="pCode"></param>
/// <returns></returns>
@@ -139,6 +140,25 @@ public class DeviceGroupService : IDeviceGroupService
exists.ThrowIfTrue("存在下级设备分组");
}
/// <summary>
/// 检查分组分类匹配
/// </summary>
/// <param name="request"></param>
/// <param name="group"></param>
/// <returns></returns>
private async Task CheckGroupTypeMatchAsync(DeviceAssignRequest request, DeviceGroupEntity group)
{
var devices = await _dbContext.Queryable<DeviceEntity>().Where(x => request.DeviceCodes.Contains(x.Code)).ToListAsync();
//检查分组的分类控制
if (group.Type.HasValue)
{
devices.Any(x => x.Type != group.Type).ThrowIfTrue("存在设备类型有误,无法分配到当前分组");
}
//重新赋值到请求参数中
request.DeviceCodes = devices.Select(x => x.Code).ToList();
}
/// <summary>
/// 递归获取树

View File

@@ -28,11 +28,13 @@ public class DeviceService : IDeviceService
{
var page = await _dbContext.Queryable<DeviceEntity>()
.LeftJoin<DeviceTemplateEntity>((d, dt) => d.TemplateCode == dt.Code)
.WhereIF(request.Type.HasValue, (d, dt) => d.Type == request.Type)
.Select((d, dt) => new DevicePageResponse
{
FuncsStr = d.Funcs.ToString(),
Brand = dt.Brand,
Type = d.Type,
}, true)
.ToPageListAsync(request);
@@ -72,6 +74,18 @@ public class DeviceService : IDeviceService
var entity = await _dbContext.Queryable<DeviceEntity>().Where(x => x.Id == request.Id).FirstAsync();
entity.ThrowIfNull("设备不存在,无法更新");
//分类发生变化,检查是否存在分组
if (request.Type != entity.Type)
{
var existsG = await _dbContext.Queryable<DeviceGroupRelationshipEntity>()
.LeftJoin<DeviceGroupEntity>((dgr, dg) => dgr.GroupCode == dg.Code)
.Where((dgr, dg) => dgr.DeviceCode == entity.Code)
.Where((dgr, dg) => dg.Type != null)
.AnyAsync();
existsG.ThrowIfTrue("存在设备分组,不可修改设备分类");
}
var uniqueNo = entity.UniqueNo;
request.Adapt(entity).UniqueNo = uniqueNo;

View File

@@ -1,4 +1,4 @@
using Dlhis.User.Api;
using Dlhis.Sys.Api;
using Dlhis.User.Api.Response;
using Kurisu.AspNetCore.Utils.Extensions;
using Kurisu.Core.Result;

View File

@@ -7,15 +7,7 @@
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true,
"applicationUrl": "http://*:5002"
},
"Docker": {
"commandName": "Docker",
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger/index.html",
"environmentVariables": {
"ASPNETCORE_URLS": "http://+:80"
},
"publishAllPorts": true
"applicationUrl": "http://localhost:5002"
}
},
"$schema": "https://json.schemastore.org/launchsettings.json"

View File

@@ -43,10 +43,10 @@ public class DeviceEntity : SugarBaseEntity, ITenantId
public List<DeviceFuncEnumType> Funcs { get; set; }
/// <summary>
/// 设备机功能类型
/// 设备类型
/// </summary>
[SugarColumn(ColumnDescription = "设备机功能类型", ColumnDataType = "varchar(50)", SqlParameterDbType = typeof(EnumToStringConvert))]
public DeviceGroupFunctionEnumType Type { get; set; }
[SugarColumn(ColumnDescription = "设备类型", ColumnDataType = "varchar(50)", SqlParameterDbType = typeof(EnumToStringConvert))]
public DeviceTypeEnumType Type { get; set; }
/// <summary>
/// 部署点

View File

@@ -16,8 +16,8 @@ public class DeviceGroupEntity : SugarBaseEntity, ITenantId, ISoftDeleted
/// <summary>
/// 设备组功能类型
/// </summary>
[SugarColumn(ColumnDescription = "设备组功能类型", ColumnDataType = "varchar(50)", SqlParameterDbType = typeof(EnumToStringConvert))]
public DeviceGroupFunctionEnumType Type { get; set; }
[SugarColumn(IsNullable = true, ColumnDescription = "设备组功能类型", ColumnDataType = "varchar(50)", SqlParameterDbType = typeof(EnumToStringConvert))]
public DeviceTypeEnumType? Type { get; set; }
/// <summary>
/// 上级设备组code

View File

@@ -1,17 +1,12 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
namespace Dlhis.Entity.Device.Enums;
/// <summary>
/// 设备/设备组功能类型
///设备分类类型
/// </summary>
[Description("设备/设备组功能类型")]
public enum DeviceGroupFunctionEnumType
[Description("设备分类类型")]
public enum DeviceTypeEnumType
{
/// <summary>
/// 门禁
@@ -29,11 +24,11 @@ public enum DeviceGroupFunctionEnumType
/// 考勤
/// </summary>
[Description("考勤")]
Attendance = 3 ,
Attendance = 3,
/// <summary>
/// 门禁并作为考勤
/// </summary>
[Description("门禁并作为考勤")]
Access = 4,
DoorAndAttendance = 4,
}

View File

@@ -0,0 +1,16 @@
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
namespace Dlhis.Entity.Sys.Entities;
[SkipScan]
[SugarTable(TableName = "UserTenants")]
public class UserTenantEntity
{
public int Id { get; set; }
public int UserId { get; set; }
public string TenantCode { get; set; }
}

View File

@@ -28,8 +28,8 @@ public class DeviceUploadLogUploadRequest
/// <summary>
/// 日志类型
/// 记录类型
/// </summary>
[EnumDataType(typeof(DeviceUploadLogTypeEnumType))]
public DeviceUploadLogTypeEnumType Type { get; set; } = DeviceUploadLogTypeEnumType.Door;
public DeviceUploadLogTypeEnumType Type { get; set; } = DeviceUploadLogTypeEnumType.Attendance;
}

View File

@@ -1,4 +1,5 @@
using Dlhis.Entity.Basic.Entity;
using System.Linq.Expressions;
using Dlhis.Entity.Basic.Entity;
using Dlhis.Entity.Device.Entities;
using Dlhis.ScheduledTask.DeviceUploadLog.Request;
using Dlhis.ScheduledTask.DeviceUploadLog.Response;
@@ -7,6 +8,7 @@ using Kurisu.Core.DataAccess.Dto;
using Kurisu.SqlSugar.Attributes;
using Kurisu.SqlSugar.Extensions;
using Kurisu.SqlSugar.Services;
using SqlSugar;
namespace Dlhis.ScheduledTask.DeviceUploadLog.Services.Implements;
@@ -59,6 +61,20 @@ public class DeviceUploadLogService : IDeviceUploadLogService
[IgnoreTenant]
public async Task UploadLogsAsync(List<DeviceUploadLogUploadRequest> requests)
{
//判断存在的记录
Expression<Func<DeviceUploadLogEntity, bool>> where = LinqExpressionExtension.False<DeviceUploadLogEntity>();
requests.ForEach(p =>
{
where = where.Or(x => x.DeviceUniqueNo == p.DeviceUniqueNo && x.SerialNo == p.SerialNo && x.RaiseDateTime == p.RaiseDateTime);
});
//处理冗余的请求数据
var exists = await _dbContext.Queryable<DeviceUploadLogEntity>().Where(where).ToListAsync();
foreach (var item in exists)
{
requests.RemoveAll(x => x.DeviceUniqueNo == item.DeviceUniqueNo && x.SerialNo == item.SerialNo && x.RaiseDateTime == item.RaiseDateTime);
}
var nos = requests.Select(x => x.DeviceUniqueNo).ToList();
var devices = await _dbContext.Queryable<DeviceEntity>().Where(x => nos.Contains(x.UniqueNo)).ToListAsync();

View File

@@ -1,7 +1,7 @@
using System.Text;
using Dlhis.ScheduledTask.SyncSapInfo.Dto;
using Dlhis.ScheduledTask.SyncSapInfo.Response;
using Dlhis.User.Api;
using Dlhis.Sys.Api;
using Newtonsoft.Json;
namespace Dlhis.ScheduledTask.SyncSapInfo.Services.Implements;

View File

@@ -2,7 +2,7 @@
using Kurisu.Core.Result;
using Kurisu.RemoteCall.Attributes;
namespace Dlhis.User.Api;
namespace Dlhis.Sys.Api;
/// <summary>
/// 租户Api
@@ -34,4 +34,12 @@ public interface ITenantApi
[Auth]
[Get("/api/tenants/single")]
Task<DefaultApiResult<TenantResponse>> GetTenantByCodeAsync(string code);
/// <summary>
/// 获取我的管理的基地/租户
/// </summary>
/// <returns></returns>
[Auth]
[Get("/api/tenants/my")]
Task<DefaultApiResult<List<TenantResponse>>> GetMyTenantsAsync();
}

View File

@@ -2,7 +2,7 @@
using Kurisu.Core.Result;
using Kurisu.RemoteCall.Attributes;
namespace Dlhis.User.Api;
namespace Dlhis.Sys.Api;
[EnableRemoteClient(Name = "sys-service", BaseUrl = "${InternalRequest:SysRequestUrl}")]
public interface IUserApi

View File

@@ -61,4 +61,13 @@ public class TenantsController : ControllerBase
return await _tenantService.GetTenantByCode(code);
}
/// <summary>
/// 获取我的管理租户
/// </summary>
/// <returns></returns>
[HttpGet("my")]
public async Task<List<TenantResponse>> GetMyTenants()
{
return await _tenantService.GetMyTenantsAsync();
}
}

View File

@@ -11,4 +11,6 @@ public interface ITenantService : IScopeDependency
Task<List<TenantResponse>> GetListAsync();
Task<TenantResponse> GetTenantByCode(string code);
Task<List<TenantResponse>> GetMyTenantsAsync();
}

View File

@@ -3,6 +3,7 @@ using Dlhis.Sys.Identity.Request;
using Dlhis.Sys.Identity.Response;
using Kurisu.AspNetCore.Utils.Extensions;
using Kurisu.Core.DataAccess.Dto;
using Kurisu.Core.User.Abstractions;
using Kurisu.SqlSugar.Extensions;
using Kurisu.SqlSugar.Services;
@@ -11,12 +12,14 @@ namespace Dlhis.Sys.Identity.Services.Implements;
public class TenantService : ITenantService
{
private readonly IDbContext _dbContext;
private readonly ICurrentUser _currentUser;
public TenantService(IDbContext dbContext, IConfiguration configuration)
public TenantService(IDbContext dbContext, IConfiguration configuration, ICurrentUser currentUser)
{
var identityConnection = configuration.GetSection("SqlSugarOptions:IdentityConnectionString").Value;
dbContext.Client.CurrentConnectionConfig.ConnectionString = identityConnection;
_dbContext = dbContext;
_currentUser = currentUser;
}
public async Task<Pagination<TenantResponse>> GetPageAsync(TenantPageRequest request)
@@ -41,4 +44,26 @@ public class TenantService : ITenantService
.Select<TenantResponse>()
.FirstAsync();
}
public async Task<List<TenantResponse>> GetMyTenantsAsync()
{
var userId = _currentUser.GetIntSubjectId();
var myTenants = await _dbContext.Queryable<UserTenantEntity>()
.LeftJoin<TenantEntity>((ut, t) => ut.TenantCode == t.Code)
.Where(ut => ut.UserId == userId)
.Select((ut, t) => new TenantResponse
{
Id = t.Id,
Code = t.Code,
Name = t.Name,
})
.ToListAsync();
if (myTenants.IsEmpty())
{
myTenants = await GetListAsync();
}
return myTenants;
}
}

View File

@@ -7,6 +7,14 @@
},
"dotnetRunMessages": true,
"applicationUrl": "http://localhost:5004"
},
"Docker": {
"commandName": "Docker",
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
"environmentVariables": {
"ASPNETCORE_URLS": "http://+:80"
},
"publishAllPorts": true
}
},
"$schema": "https://json.schemastore.org/launchsettings.json"