fix 数据where处理

This commit is contained in:
2024-06-26 18:23:06 +08:00
parent ee4dfc5fa5
commit 01bc681807
4 changed files with 115 additions and 15 deletions

View File

@@ -1,4 +1,5 @@
using System.Reflection; using System.Reflection;
using Dlhis.Entity.Basic.Entity;
using Kurisu.AspNetCore; using Kurisu.AspNetCore;
using Kurisu.AspNetCore.DataAccess.Entity; using Kurisu.AspNetCore.DataAccess.Entity;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services; using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
@@ -27,9 +28,21 @@ public class SysDataService : ISysDataService
var sql = $"select * from {table}"; var sql = $"select * from {table}";
if (type.IsAssignableTo(typeof(ITenantId))) if (type.IsAssignableTo(typeof(ITenantId)))
{ {
sql += $" where tenantId = '{tableName}'"; sql += $" where tenantId = '{factory}'";
} }
return await _dbContext.Client.SqlQueryable<object>(sql).ToListAsync(); switch (tableName)
{
case "Gainfo":
//sql = $"select * from Gainfo where factory = '{factory}'";
return await _dbContext.Queryable<GainfoEntity>().Where(x => x.Factory == factory).Select(x => (object)x).ToListAsync();
case "GainfoMeal":
{
var codes = await _dbContext.Queryable<GainfoEntity>().Where(x => x.Factory == factory).Select(x => x.Code).ToListAsync();
return await _dbContext.Queryable<GainfoMealEntity>().Where(x => codes.Contains(x.UserCode)).Select(x => (object)x).ToListAsync();
}
default:
return await _dbContext.Client.SqlQueryable<object>(sql).ToListAsync();
}
} }
} }

View File

@@ -1,9 +1,91 @@
using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Device.Enums;
using Kurisu.AspNetCore.DataAccess.Entity;
using Kurisu.AspNetCore.DataAccess.SqlSugar;
using Mapster;
using SqlSugar;
using SqlSugar.DbConvert;
namespace Dlhis.Middle.Entities namespace Dlhis.Middle.Entities
{ {
public class LocalDeviceEntity : DeviceEntity [SugarTable(TableName = "Device")]
public class LocalDeviceEntity : SugarBaseEntity , ITenantId
{ {
public new int Id { get; set; } public new int Id { get; set; }
/// <summary>
/// 设备code
/// </summary>
[SugarColumn(ColumnDescription = "设备code")]
public Guid Code { get; set; }
/// <summary>
/// 设备唯一码,IP/MAC/SNO
/// </summary>
[AdaptIgnore(MemberSide.Destination)]
[SugarColumn(ColumnDescription = "设备唯一码", IsNullable = false, UniqueGroupNameList = new[] { "Idx_Device_UniqueNo" })]
public string UniqueNo { get; set; }
/// <summary>
/// 心跳间隔
/// </summary>
[SugarColumn(ColumnDescription = "心跳检查间隔")]
public int HeartbeatInterval { get; set; }
/// <summary>
/// 供应商
/// </summary>
[SugarColumn(ColumnDescription = "供应商")]
public string Supplier { get; set; }
/// <summary>
/// 设备类型
/// </summary>
[SugarColumn(ColumnDescription = "设备类型", ColumnDataType = "varchar(50)", SqlParameterDbType = typeof(EnumToStringConvert))]
public DeviceTypeEnumType Type { get; set; }
/// <summary>
/// 部署点
/// </summary>
[SugarColumn(ColumnDescription = "部署点")]
public string DeployPlace { get; set; }
/// <summary>
/// 部署坐标
/// </summary>
[SugarColumn(ColumnDescription = "部署坐标")]
public string DeployPosition { get; set; }
/// <summary>
/// 部署方向
/// </summary>
[SugarColumn(ColumnDescription = "部署方向", ColumnDataType = "varchar(50)", SqlParameterDbType = typeof(EnumToStringConvert))]
public DeviceDeployDirectionEnumType? DeployDirection { get; set; }
/// <summary>
/// 模板code
/// </summary>
[SugarColumn(ColumnDescription = "模板code")]
public Guid? TemplateCode { get; set; }
/// <summary>
/// 连接信息
/// </summary>
[SugarColumn(ColumnDescription = "连接信息")]
public string ConnectionInfo { get; set; }
/// <summary>
/// 是否启用
/// </summary>
[SugarColumn(ColumnDataType = "bit", ColumnDescription = "是否启用")]
public bool Enable { get; set; }
/// <summary>
/// 是否作为考勤设备
/// </summary>
[SugarColumn(ColumnDataType = "bit", ColumnDescription = "是否作为考勤设备")]
public bool AsAttendance { get; set; }
public string TenantId { get; set; }
} }
} }

View File

@@ -51,14 +51,14 @@ public class Startup : DefaultStartup
var ds = scope.ServiceProvider.GetService<IDataDownloadService>(); var ds = scope.ServiceProvider.GetService<IDataDownloadService>();
ds.TruncateAsync().Wait(); ds.TruncateAsync().Wait();
ds.DownloadAsync<LocalDepartmentEntity>(factory).Wait(); ds.DownloadAsync<LocalDepartmentEntity>(factory).Wait();
// ds.DownloadAsync<LocalDeviceEntity>(factory).Wait(); ds.DownloadAsync<LocalDeviceEntity>(factory).Wait();
// ds.DownloadAsync<LocalDeviceRegistryEntity>(factory).Wait(); ds.DownloadAsync<LocalDeviceRegistryEntity>(factory).Wait();
// ds.DownloadAsync<LocalBusinessPlaceEntity>(factory).Wait(); ds.DownloadAsync<LocalBusinessPlaceEntity>(factory).Wait();
// ds.DownloadAsync<LocalBusinessShiftEntity>(factory).Wait(); ds.DownloadAsync<LocalBusinessShiftEntity>(factory).Wait();
// ds.DownloadAsync<LocalBusinessPlaceShiftRelationshipEntity>(factory).Wait(); ds.DownloadAsync<LocalBusinessPlaceShiftRelationshipEntity>(factory).Wait();
// ds.DownloadAsync<LocalBusinessShiftMealRelationshipEntity>(factory).Wait(); ds.DownloadAsync<LocalBusinessShiftMealRelationshipEntity>(factory).Wait();
//
// ds.DownloadAsync<LocalGainfoEntity>(factory).Wait(); ds.DownloadAsync<LocalGainfoEntity>(factory).Wait();
// ds.DownloadAsync<LocalGainfoMealEntity>(factory).Wait(); ds.DownloadAsync<LocalGainfoMealEntity>(factory).Wait();
} }
} }

View File

@@ -35,7 +35,12 @@ public class DataDownloadService : IDataDownloadService
var httpClient = _httpClientFactory.CreateClient("face"); var httpClient = _httpClientFactory.CreateClient("face");
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var requestUrl = QueryHelpers.AddQueryString($"https://{_hostName}/api/common/SysData/download", new Dictionary<string, string> var url = $"https://{_hostName}/api/common/SysData/download";
#if DEBUG
url = $"http://localhost:5001/api/SysData/download";
#endif
var requestUrl = QueryHelpers.AddQueryString(url, new Dictionary<string, string>
{ {
["factory"] = factory, ["factory"] = factory,
["tableName"] = typeof(T).GetCustomAttribute<SugarTable>()!.TableName ["tableName"] = typeof(T).GetCustomAttribute<SugarTable>()!.TableName