fix 二维码校验设备权限
This commit is contained in:
@@ -1,20 +0,0 @@
|
||||
namespace Dlhis.Basic.Api.Dto;
|
||||
|
||||
public class DishesMenuDetailDto
|
||||
{
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
public long MenuId { get; set; }
|
||||
|
||||
public long DishesId { get; set; }
|
||||
|
||||
public string DishesCode { get; set; }
|
||||
|
||||
public string DishesName { get; set; }
|
||||
|
||||
public decimal Price { get; set; }
|
||||
|
||||
public int Number { get; set; }
|
||||
|
||||
public int Version { get; set; }
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
using Dlhis.Basic.Api.Response;
|
||||
using Kurisu.RemoteCall.Attributes;
|
||||
using Kurisu.RemoteCall.Default;
|
||||
|
||||
namespace Dlhis.Basic.Api;
|
||||
|
||||
|
||||
[EnableRemoteClient(Name = "basic-service", BaseUrl = "${InternalRequest:BasicRequestUrl}")]
|
||||
public interface IDeviceGroupApi
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 获取分组下的设备
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <returns></returns>
|
||||
[Auth]
|
||||
[Get("/api/deviceGroups/devices")]
|
||||
Task<DefaultApiResult<List<DeviceUnderGroupResponse>>> GetDevicesByCodeAsync(Guid code);
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
using Dlhis.Basic.Api.Dto;
|
||||
using Dlhis.Basic.Api.Request;
|
||||
using Kurisu.RemoteCall.Attributes;
|
||||
using Kurisu.RemoteCall.Default;
|
||||
|
||||
namespace Dlhis.Basic.Api;
|
||||
|
||||
[EnableRemoteClient(Name = "basic-service", BaseUrl = "${InternalRequest:BasicRequestUrl}")]
|
||||
public interface IDevicePermissionApi
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取所有人的权限信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Post("/api/devicepermissions/all-permission")]
|
||||
Task<DefaultApiResult<PermissionUsersInfoDto>> GetPermissionUsersInfoAsync(List<string> userNos);
|
||||
|
||||
/// <summary>
|
||||
/// 重新生成权限
|
||||
/// </summary>
|
||||
/// <param name="beforeDto"></param>
|
||||
/// <returns></returns>
|
||||
[Post("/api/devicepermissions/re-permission")]
|
||||
Task<DefaultApiResult<int>> RePermissionUsersInfoAsync(PermissionUsersInfoDto beforeDto);
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
using Dlhis.Basic.Api.Dto;
|
||||
using Kurisu.RemoteCall.Attributes;
|
||||
using Kurisu.RemoteCall.Default;
|
||||
|
||||
namespace Dlhis.Basic.Api;
|
||||
|
||||
[EnableRemoteClient(Name = "basic-service", BaseUrl = "${InternalRequest:BasicRequestUrl}")]
|
||||
public interface IDishesMenuApi
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="date"></param>
|
||||
/// <param name="businessPlaceCode"></param>
|
||||
/// <param name="shiftType"></param>
|
||||
/// <param name="dishesCode"></param>
|
||||
/// <returns></returns>
|
||||
[Auth]
|
||||
[Get("/api/dishesMenus/checkdetail")]
|
||||
Task<DefaultApiResult<DishesMenuDetailDto>> GetBookingDishesDetailAsync(DateTime date, Guid businessPlaceCode, int shiftType, string dishesCode);
|
||||
}
|
||||
@@ -9,4 +9,8 @@ public interface IGainfoPermissionApi
|
||||
{
|
||||
[Post("/api/gainfoPermissions/reset")]
|
||||
Task<DefaultApiResult> ResetAsync(GainfoPermissionResetRequest request);
|
||||
|
||||
[Auth]
|
||||
[Get("/api/devicePermissions/userPermissionCodes")]
|
||||
Task<DefaultApiResult<List<Guid>>> GetPermissionsDeviceCodesAsync(string userCode);
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace Dlhis.Basic.Api.Request
|
||||
{
|
||||
public class GeneratePermissionIdRequest
|
||||
{
|
||||
public long Id { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
namespace Dlhis.Basic.Api.Response;
|
||||
|
||||
public class DeviceUnderGroupResponse
|
||||
{
|
||||
public Guid Code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设备唯一码,IP/MAC/SNO
|
||||
/// </summary>
|
||||
public string UniqueNo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 品牌
|
||||
/// </summary>
|
||||
public string Brand { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否启用
|
||||
/// </summary>
|
||||
public bool Enable { get; set; }
|
||||
}
|
||||
@@ -84,29 +84,12 @@ public class DevicePermissionsController : ControllerBase
|
||||
return await _devicePermissionService.GetGainfoPageByDeviceAsync(request);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前所有人的权限code
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
[HttpPost("all-permission")]
|
||||
[IgnoreTenant]
|
||||
public async Task<PermissionUsersInfoDto> GetPermissionUsersInfoAsync(List<string> userNos)
|
||||
{
|
||||
return await _devicePermissionService.GetPermissionUsersInfoAsync(userNos);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据权限code生成下发任务
|
||||
/// </summary>
|
||||
/// <param name="beforeDto"></param>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
[HttpGet("userPermissionCodes")]
|
||||
[IgnoreTenant]
|
||||
[HttpPost("re-permission")]
|
||||
public async Task<int> ReGeneratePermissionUsersInfoAsync(PermissionUsersInfoDto beforeDto)
|
||||
public async Task<List<Guid>> GetAssignDeviceCodesAsync(string userCode)
|
||||
{
|
||||
return await _devicePermissionService.ReGeneratePermissionUsersInfoAsync(beforeDto);
|
||||
return await _devicePermissionService.GetAssignDeviceCodesAsync(userCode);
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
|
||||
@@ -56,13 +56,9 @@ public interface IDevicePermissionService : IScopeDependency
|
||||
/// <summary>
|
||||
/// 获取用户所有设备权限
|
||||
/// </summary>
|
||||
/// <param name="userNo"></param>
|
||||
/// <param name="userCode"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<Guid>> GetAssignDeviceCodesAsync(string userNo);
|
||||
|
||||
Task<PermissionUsersInfoDto> GetPermissionUsersInfoAsync(List<string> userNos);
|
||||
|
||||
Task<int> ReGeneratePermissionUsersInfoAsync(PermissionUsersInfoDto beforeDto);
|
||||
Task<List<Guid>> GetAssignDeviceCodesAsync(string userCode);
|
||||
|
||||
Task<Pagination<DeviceGainfoResponse>> GetGainfoPageByDeviceAsync(DeviceWithGainfoRequest request);
|
||||
}
|
||||
@@ -300,100 +300,6 @@ public class DevicePermissionService : IDevicePermissionService
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<PermissionUsersInfoDto> GetPermissionUsersInfoAsync(List<string> userNos)
|
||||
{
|
||||
if (userNos.IsEmpty())
|
||||
userNos = await GetPermissionUserNosAsync();
|
||||
|
||||
var permissions = await GetAssignDeviceCodesInternalAsync(userNos);
|
||||
|
||||
return new PermissionUsersInfoDto
|
||||
{
|
||||
UserNos = userNos,
|
||||
PermissionInfos = permissions
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public async Task<int> ReGeneratePermissionUsersInfoAsync(PermissionUsersInfoDto beforeDto)
|
||||
{
|
||||
var userNos = beforeDto.UserNos;
|
||||
var before = beforeDto.PermissionInfos.ToDictionary(x => x.Key, x => x.Value, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
var current = await GetAssignDeviceCodesInternalAsync(userNos);
|
||||
|
||||
var devices = await _dbContext.Queryable<DeviceEntity>().Where(x => x.Enable).ToListAsync();
|
||||
var waitTasks = new List<DeviceTaskEntity>();
|
||||
|
||||
foreach (var userNo in userNos)
|
||||
{
|
||||
before.TryGetValue(userNo, out var beforeTenantDeviceCodes);
|
||||
beforeTenantDeviceCodes ??= new List<UserTenantDeviceCodeDto>();
|
||||
current.TryGetValue(userNo, out var currentTenantDeviceCodes);
|
||||
currentTenantDeviceCodes ??= new List<UserTenantDeviceCodeDto>();
|
||||
|
||||
var tenants = new HashSet<string>();
|
||||
foreach (var item in beforeTenantDeviceCodes)
|
||||
tenants.Add(item.Tenant);
|
||||
foreach (var item in currentTenantDeviceCodes)
|
||||
tenants.Add(item.Tenant);
|
||||
|
||||
foreach (var tenant in tenants)
|
||||
{
|
||||
var currentCodes = currentTenantDeviceCodes.FirstOrDefault(x => x.Tenant == tenant)?.Codes ?? new List<Guid>();
|
||||
var beforeCodes = beforeTenantDeviceCodes.FirstOrDefault(x => x.Tenant == tenant)?.Codes ?? new List<Guid>();
|
||||
|
||||
//被删除
|
||||
var deletedItems = beforeCodes.Where(x => !currentCodes.Contains(x)).ToList();
|
||||
//新增
|
||||
var addItems = currentCodes.Where(x => !beforeCodes.Contains(x)).ToList();
|
||||
|
||||
if (!deletedItems.Any() && !addItems.Any())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var deviceCodes = devices.Where(x => deletedItems.Contains(x.Code) || addItems.Contains(x.Code)).Select(x => x.Code).ToList();
|
||||
deletedItems = deletedItems.Where(x => deviceCodes.Contains(x)).ToList();
|
||||
addItems = addItems.Where(x => deviceCodes.Contains(x)).ToList();
|
||||
|
||||
//下发任务创建
|
||||
deletedItems.ForEach(x => waitTasks.Add(new DeviceTaskEntity
|
||||
{
|
||||
DeviceUniqueNo = devices.First(item => item.Code == x).UniqueNo,
|
||||
Status = DeviceTaskStatusEnumType.Wait,
|
||||
Type = DeviceTaskEnumType.Delete,
|
||||
CancellationId = 0,
|
||||
DeviceType = devices.First(item => item.Code == x).Type,
|
||||
UserNo = userNo,
|
||||
Version = 0,
|
||||
TenantId = tenant,
|
||||
Source = DeviceTaskSourceEnumType.Schedule
|
||||
}));
|
||||
|
||||
addItems.ForEach(x => waitTasks.Add(new DeviceTaskEntity
|
||||
{
|
||||
DeviceUniqueNo = devices.First(item => item.Code == x).UniqueNo,
|
||||
Status = DeviceTaskStatusEnumType.Wait,
|
||||
Type = DeviceTaskEnumType.Add,
|
||||
DeviceType = devices.First(item => item.Code == x).Type,
|
||||
UserNo = userNo,
|
||||
Version = 0,
|
||||
TenantId = tenant,
|
||||
Source = DeviceTaskSourceEnumType.Schedule
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
if (waitTasks.Any())
|
||||
{
|
||||
await _dbContext.InsertAsync(waitTasks);
|
||||
}
|
||||
|
||||
return waitTasks.Count;
|
||||
}
|
||||
|
||||
|
||||
public async Task<Pagination<DeviceGainfoResponse>> GetGainfoPageByDeviceAsync(DeviceWithGainfoRequest request)
|
||||
{
|
||||
var device = await _dbContext.Queryable<DeviceEntity>().Where(x => x.UniqueNo == request.DeviceUniqueNo).SingleAsync();
|
||||
@@ -536,44 +442,13 @@ public class DevicePermissionService : IDevicePermissionService
|
||||
/// <summary>
|
||||
/// 获取用户所有设备权限
|
||||
/// </summary>
|
||||
/// <param name="userNo"></param>
|
||||
/// <param name="userCode"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<Guid>> GetAssignDeviceCodesAsync(string userNo)
|
||||
public async Task<List<Guid>> GetAssignDeviceCodesAsync(string userCode)
|
||||
{
|
||||
var devices = await _dbContext.Queryable<DeviceEntity>().Where(x => x.Enable).ToListAsync();
|
||||
var deviceRegistries = await _dbContext.Queryable<DeviceRegistryEntity>().Where(x => !SqlFunc.IsNullOrEmpty(x.BusinessPlaceCode)).ToListAsync();
|
||||
|
||||
var gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.No == userNo).SingleAsync()
|
||||
?? await _dbContext.Queryable<GainfoEntity>().AS("GainfoLeave").Where(x => x.No == userNo).SingleAsync();
|
||||
|
||||
var gainfoGroups = await _dbContext.Queryable<GainfoGroupRelationshipEntity>().ToListAsync();
|
||||
|
||||
var devicePermissions = await _dbContext.Queryable<DevicePermissionEntity>().ToListAsync();
|
||||
var deviceGroups = await _dbContext.Queryable<DeviceGroupEntity>().ToListAsync();
|
||||
var deviceGroupCodes = deviceGroups.Select(x => x.Code).ToList();
|
||||
var deviceRelationships = await _dbContext.Queryable<DeviceGroupRelationshipEntity>().Where(x => deviceGroupCodes.Contains(x.GroupCode)).ToListAsync();
|
||||
var departments = await _dbContext.Queryable<DepartmentEntity>().ToListAsync();
|
||||
|
||||
|
||||
var isOutsource = await _dbContext.Queryable<OutsourceEntity>().AnyAsync(x => x.Code == gainfo.Code);
|
||||
|
||||
var enableFactoryPermissions = await _dbContext.Queryable<FactorySettingEntity>().ToListAsync();
|
||||
|
||||
var gainfoDto = new GainfoDto
|
||||
{
|
||||
Id = gainfo.Id,
|
||||
No = gainfo.No,
|
||||
Code = gainfo.Code,
|
||||
Name = gainfo.Name,
|
||||
Workplace = gainfo.Workplace,
|
||||
Factory = gainfo.Factory,
|
||||
DepartmentNo = gainfo.DepartmentNo,
|
||||
IsOutsource = isOutsource,
|
||||
EnableFactoryPermission = enableFactoryPermissions.FirstOrDefault(x => x.TenantId == gainfo.Factory)?.EnableOutsourceDown ?? true
|
||||
};
|
||||
|
||||
var result = GetAssignDeviceCodesInternal(gainfoDto, gainfoGroups, devicePermissions, deviceGroups, deviceRelationships, deviceRegistries, devices, departments);
|
||||
return result.SelectMany(x => x.Codes).ToList();
|
||||
var userNo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.Code == userCode || x.No == userCode).Select(x => x.No).SingleAsync();
|
||||
var result = await GetAssignDeviceCodesInternalAsync(new List<string> { userNo });
|
||||
return result.First().Value.SelectMany(x => x.Codes).ToList();
|
||||
}
|
||||
|
||||
//************************************************ help methods *******************************************************
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Dlhis.ScheduledTask.Common.Services;
|
||||
namespace Dlhis.Basic.Organization.Services;
|
||||
|
||||
public interface ISapBusinessTripService : IScopeDependency
|
||||
{
|
||||
@@ -40,7 +40,7 @@ public class GainfoPermissionService : IGainfoPermissionService
|
||||
}
|
||||
|
||||
//用户所有deviceCode权限
|
||||
var deviceCodes = await _devicePermissionService.GetAssignDeviceCodesAsync(gainfo.No);
|
||||
var deviceCodes = await _devicePermissionService.GetAssignDeviceCodesAsync(gainfo.Code);
|
||||
|
||||
return await _dbContext.Queryable<DeviceEntity>()
|
||||
.LeftJoin<DeviceRegistryEntity>((x, dr) => x.UniqueNo == dr.DeviceUniqueNo)
|
||||
@@ -164,7 +164,7 @@ public class GainfoPermissionService : IGainfoPermissionService
|
||||
gainfo.ThrowIfNull("档案数据不存在");
|
||||
|
||||
//获取人员的设备权限
|
||||
var deviceCodes = await _devicePermissionService.GetAssignDeviceCodesAsync(request.UserNo);
|
||||
var deviceCodes = await _devicePermissionService.GetAssignDeviceCodesAsync(gainfo!.Code);
|
||||
var devices = await _dbContext.Queryable<DeviceEntity>().Where(x => deviceCodes.Contains(x.Code)).ToListAsync();
|
||||
|
||||
var tasks = devices.Select(x => new DeviceTaskEntity
|
||||
|
||||
@@ -292,7 +292,7 @@ public class GainfoService : IGainfoService
|
||||
|
||||
await _dbContext.UpdateAsync(gainfo);
|
||||
|
||||
var deviceCodes = await _devicePermissionService.GetAssignDeviceCodesAsync(gainfo.No);
|
||||
var deviceCodes = await _devicePermissionService.GetAssignDeviceCodesAsync(gainfo.Code);
|
||||
|
||||
var dhDevices = await _dbContext.Queryable<DeviceEntity>().LeftJoin<DeviceTemplateEntity>((x, xt) => x.TemplateCode == xt.Code)
|
||||
.Where((x, xt) => xt.Name == "大华人脸机")
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
// using Dlhis.Entity.Basic.Entity;
|
||||
// using Dlhis.Entity.Device.Entities;
|
||||
// using Dlhis.Entity.Device.Enums;
|
||||
// using Dlhis.Entity.Sys.Entities;
|
||||
// using Dlhis.Entity.Sys.Enums;
|
||||
// using Dlhis.Entity.Visitor.Entity;
|
||||
// using Dlhis.Entity.Visitor.Enums;
|
||||
// using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
// using SqlSugar;
|
||||
//
|
||||
// namespace Dlhis.Basic.Organization.Services.Implements;
|
||||
//
|
||||
// public class SapBusinessTripService : ISapBusinessTripService
|
||||
// {
|
||||
// private readonly IJinkoJipService _jinkoJipService;
|
||||
// private readonly IDbContext _dbContext;
|
||||
// private readonly ILogger<SapBusinessTripService> _logger;
|
||||
//
|
||||
// public SapBusinessTripService(IJinkoJipService jinkoJipService, IDbContext dbContext , ILogger<SapBusinessTripService> logger)
|
||||
// {
|
||||
// _jinkoJipService = jinkoJipService;
|
||||
// _dbContext = dbContext;
|
||||
// _logger = logger;
|
||||
// }
|
||||
//
|
||||
// /// <inheritdoc />
|
||||
// public async Task HandlerBusinessTripsByFactoryAsync(string factory)
|
||||
// {
|
||||
// var today = DateTime.Today;
|
||||
// var yesterday = today.AddDays(-1);
|
||||
//
|
||||
// try
|
||||
// {
|
||||
// var tripResponse = await _jinkoJipService.GetTravelInfosByFactoryAsync(today, today, factory);
|
||||
// if (!tripResponse.Items.Any())
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// foreach (var tripInfoItem in tripResponse.Items.Where(x => x.Destination.IsPresent()))
|
||||
// {
|
||||
// if (await _dbContext.Queryable<BusinessTripEntity>().Where(x => x.Code == tripInfoItem.Code
|
||||
// && x.BeginDate == tripInfoItem.BeginDate
|
||||
// && x.EndDate == tripInfoItem.EndDate
|
||||
// && x.Destination == factory).AnyAsync())
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// var entity = tripInfoItem.Adapt<BusinessTripEntity>();
|
||||
// entity.Status = BusinessTripStatusEnumType.Wait;
|
||||
// await _dbContext.InsertAsync(entity);
|
||||
// }
|
||||
//
|
||||
// //获取今天和昨天的出差数据
|
||||
// var tripInfos = await _dbContext.Queryable<BusinessTripEntity>()
|
||||
// .Where(x => (SqlFunc.DateIsSame(x.BeginDate, today) && SqlFunc.DateIsSame(x.BeginDate, today))
|
||||
// || (SqlFunc.DateIsSame(x.BeginDate, yesterday) && SqlFunc.DateIsSame(x.BeginDate, yesterday)))
|
||||
// .Where(x => !SqlFunc.IsNullOrEmpty(x.Destination))
|
||||
// .Where(x => x.Destination == factory)
|
||||
// .ToListAsync();
|
||||
//
|
||||
// //获取分组信息
|
||||
// var tripGroup = await _dbContext.Queryable<DeviceGroupEntity>()
|
||||
// .Where(x => x.Type == DeviceTypeEnumType.Door)
|
||||
// .Where(x => x.TenantId == factory)
|
||||
// .Where(x => x.IsBusinessTrip)
|
||||
// .SingleAsync();
|
||||
//
|
||||
// var userCodes = tripInfos.Select(x => x.Code).Distinct().ToList();
|
||||
// var gainfos = await _dbContext.Queryable<GainfoEntity>().Where(x => userCodes.Contains(x.Code)).ToListAsync();
|
||||
//
|
||||
// foreach (var gainfo in gainfos)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// var myTripInfos = tripInfos.Where(x => x.Code == gainfo.Code).ToList();
|
||||
//
|
||||
// var yesterdayTripInfo = myTripInfos.FirstOrDefault(x => x.BeginDate == yesterday && x.EndDate == yesterday); //昨天出差数据
|
||||
// var todayTripInfo = myTripInfos.FirstOrDefault(x => x.BeginDate == today && x.EndDate == today); //今天出差数据
|
||||
//
|
||||
// //都为空不处理
|
||||
// if (yesterdayTripInfo == null && todayTripInfo == null) continue;
|
||||
//
|
||||
// //都不为空则更新数据状态
|
||||
// if (yesterdayTripInfo != null && todayTripInfo != null)
|
||||
// {
|
||||
// todayTripInfo.Status = BusinessTripStatusEnumType.Generated;
|
||||
// await _dbContext.UpdateAsync(todayTripInfo);
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// var beforeResult = await _devicePermissionApi.GetPermissionUsersInfoAsync(new List<string> { gainfo.Code });
|
||||
//
|
||||
// if (yesterdayTripInfo != null)
|
||||
// {
|
||||
// yesterdayTripInfo.Status = BusinessTripStatusEnumType.Deleted;
|
||||
// await _dbContext.Updateable<DevicePermissionEntity>()
|
||||
// .SetColumns(x => x.IsDeleted == true)
|
||||
// .Where(x => x.AssignType == AssignTypeEnumType.User)
|
||||
// .Where(x => x.AssignValue == gainfo.No)
|
||||
// .Where(x => x.UniqueType == DeviceAssignmentTypeEnumType.Group)
|
||||
// .Where(x => x.UniqueValue == tripGroup.Code)
|
||||
// .Where(x => x.Type == tripGroup.Type)
|
||||
// .Where(x => x.TenantId == factory)
|
||||
// .ExecuteCommandAsync();
|
||||
// await _dbContext.UpdateAsync(yesterdayTripInfo);
|
||||
// }
|
||||
//
|
||||
// if (yesterdayTripInfo == null)
|
||||
// {
|
||||
// todayTripInfo.Status = BusinessTripStatusEnumType.Generated;
|
||||
// await _dbContext.InsertAsync(new DevicePermissionEntity
|
||||
// {
|
||||
// AssignType = AssignTypeEnumType.User,
|
||||
// AssignValue = gainfo.No,
|
||||
// UniqueType = DeviceAssignmentTypeEnumType.Group,
|
||||
// UniqueValue = tripGroup.Code,
|
||||
// TenantId = factory,
|
||||
// Type = tripGroup.Type,
|
||||
// IsDeleted = false
|
||||
// });
|
||||
// await _dbContext.UpdateAsync(todayTripInfo);
|
||||
// }
|
||||
//
|
||||
// await _devicePermissionApi.RePermissionUsersInfoAsync(beforeResult.Data);
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// _logger.LogError(e, "出差自动下发任务失败:{message}", e.Message);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// _logger.LogError(e, "处理{factory}出差数据失败:{message}", factory, e.Message);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
@@ -16,6 +16,10 @@
|
||||
<None Remove="log\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Dlhis.Basic.Api\Dlhis.Basic.Api.csproj" />
|
||||
<ProjectReference Include="..\Dlhis.Entity\Dlhis.Entity.csproj" />
|
||||
|
||||
@@ -1,23 +1,31 @@
|
||||
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
|
||||
# 请参阅 https://aka.ms/customizecontainer 以了解如何自定义调试容器,以及 Visual Studio 如何使用此 Dockerfile 生成映像以更快地进行调试。
|
||||
|
||||
# 此阶段用于在快速模式(默认为调试配置)下从 VS 运行时
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
|
||||
WORKDIR /app
|
||||
EXPOSE 80
|
||||
|
||||
|
||||
# 此阶段用于生成服务项目
|
||||
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
WORKDIR /src
|
||||
COPY ["Src/Dlhis.Canteen/Dlhis.Canteen.csproj", "Src/Dlhis.Canteen/"]
|
||||
COPY ["Src/Dlhis.Basic.Api/Dlhis.Basic.Api.csproj", "Src/Dlhis.Basic.Api/"]
|
||||
COPY ["Src/Dlhis.Entity/Dlhis.Entity.csproj", "Src/Dlhis.Entity/"]
|
||||
COPY ["Src/Dlhis.DataPermission.Model/Dlhis.DataPermission.Model.csproj", "Src/Dlhis.DataPermission.Model/"]
|
||||
COPY ["Src/Dlhis.Sys.Api/Dlhis.Sys.Api.csproj", "Src/Dlhis.Sys.Api/"]
|
||||
RUN dotnet restore "Src/Dlhis.Canteen/Dlhis.Canteen.csproj"
|
||||
RUN dotnet restore "./Src/Dlhis.Canteen/Dlhis.Canteen.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/Src/Dlhis.Canteen"
|
||||
RUN dotnet build "Dlhis.Canteen.csproj" -c Release -o /app/build
|
||||
RUN dotnet build "./Dlhis.Canteen.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
||||
|
||||
# 此阶段用于发布要复制到最终阶段的服务项目
|
||||
FROM build AS publish
|
||||
RUN dotnet publish "Dlhis.Canteen.csproj" -c Release -o /app/publish /p:UseAppHost=false
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
RUN dotnet publish "./Dlhis.Canteen.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
|
||||
|
||||
# 此阶段在生产中使用,或在常规模式下从 VS 运行时使用(在不使用调试配置时为默认值)
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app/publish .
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Dlhis.Canteen.Order.Dto;
|
||||
using Dlhis.Basic.Api;
|
||||
using Dlhis.Canteen.Order.Dto;
|
||||
using Dlhis.Canteen.Order.Repository;
|
||||
using Dlhis.Canteen.Setting.Services;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
@@ -31,6 +32,7 @@ public class OrderService : IOrderService
|
||||
private readonly IBalanceRepository _balanceRepository;
|
||||
private readonly IOrderRepository _orderRepository;
|
||||
private readonly RedisCache _redisCache;
|
||||
private readonly IGainfoPermissionApi _gainfoPermissionApi;
|
||||
private readonly ILogger<OrderService> _logger;
|
||||
|
||||
public OrderService(ICanteenSettingService canteenSettingService,
|
||||
@@ -40,6 +42,7 @@ public class OrderService : IOrderService
|
||||
IBalanceRepository balanceRepository,
|
||||
IOrderRepository orderRepository,
|
||||
RedisCache redisCache,
|
||||
IGainfoPermissionApi gainfoPermissionApi,
|
||||
ILogger<OrderService> logger)
|
||||
{
|
||||
_canteenSettingService = canteenSettingService;
|
||||
@@ -49,6 +52,7 @@ public class OrderService : IOrderService
|
||||
_balanceRepository = balanceRepository;
|
||||
_orderRepository = orderRepository;
|
||||
_redisCache = redisCache;
|
||||
_gainfoPermissionApi = gainfoPermissionApi;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@@ -126,6 +130,19 @@ public class OrderService : IOrderService
|
||||
|
||||
//******************************************************* help methods ************************************************************/
|
||||
|
||||
private async Task CheckPermissionAsync(string userCode, string deviceUniqueNo)
|
||||
{
|
||||
var r = await _gainfoPermissionApi.GetPermissionsDeviceCodesAsync(userCode);
|
||||
if (r.Code != Kurisu.RemoteCall.Default.ApiStateCode.Success)
|
||||
{
|
||||
true.ThrowIfTrue(r.Msg);
|
||||
}
|
||||
|
||||
var code = await _dbContext.Queryable<DeviceEntity>().Where(x => x.UniqueNo == deviceUniqueNo).Select(x => x.Code).SingleAsync();
|
||||
r.Data.Contains(code).ThrowIfFalse("无权消费");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前消费人员
|
||||
/// </summary>
|
||||
@@ -142,6 +159,7 @@ public class OrderService : IOrderService
|
||||
if (request.UserUniqueNo.StartsWith("01"))
|
||||
{
|
||||
gainfo = await GetUserByQrCodeAsync(request.UserUniqueNo);
|
||||
await CheckPermissionAsync(gainfo.Code, request.DeviceUniqueNo);
|
||||
}
|
||||
else if (request.UserUniqueNo.StartsWith("02"))
|
||||
{
|
||||
|
||||
@@ -7,6 +7,15 @@
|
||||
},
|
||||
"dotnetRunMessages": true,
|
||||
"applicationUrl": "http://localhost:5008"
|
||||
},
|
||||
"Container (Dockerfile)": {
|
||||
"commandName": "Docker",
|
||||
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_URLS": "http://+:80"
|
||||
},
|
||||
"publishAllPorts": true,
|
||||
"useSSL": false
|
||||
}
|
||||
},
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json"
|
||||
|
||||
@@ -1,144 +0,0 @@
|
||||
using Dlhis.Basic.Api;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Dlhis.Entity.Sys.Entities;
|
||||
using Dlhis.Entity.Sys.Enums;
|
||||
using Dlhis.Entity.Visitor.Entity;
|
||||
using Dlhis.Entity.Visitor.Enums;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Mapster;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Dlhis.ScheduledTask.Common.Services.Implements;
|
||||
|
||||
public class SapBusinessTripService : ISapBusinessTripService
|
||||
{
|
||||
private readonly IJinkoJipService _jinkoJipService;
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly IDevicePermissionApi _devicePermissionApi;
|
||||
private readonly ILogger<SapBusinessTripService> _logger;
|
||||
|
||||
public SapBusinessTripService(IJinkoJipService jinkoJipService, IDbContext dbContext, IDevicePermissionApi devicePermissionApi, ILogger<SapBusinessTripService> logger)
|
||||
{
|
||||
_jinkoJipService = jinkoJipService;
|
||||
_dbContext = dbContext;
|
||||
_devicePermissionApi = devicePermissionApi;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task HandlerBusinessTripsByFactoryAsync(string factory)
|
||||
{
|
||||
var today = DateTime.Today;
|
||||
var yesterday = today.AddDays(-1);
|
||||
|
||||
try
|
||||
{
|
||||
var tripResponse = await _jinkoJipService.GetTravelInfosByFactoryAsync(today, today, factory);
|
||||
if (!tripResponse.Items.Any())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var tripInfoItem in tripResponse.Items.Where(x => x.Destination.IsPresent()))
|
||||
{
|
||||
if (await _dbContext.Queryable<BusinessTripEntity>().Where(x => x.Code == tripInfoItem.Code
|
||||
&& x.BeginDate == tripInfoItem.BeginDate
|
||||
&& x.EndDate == tripInfoItem.EndDate
|
||||
&& x.Destination == factory).AnyAsync())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var entity = tripInfoItem.Adapt<BusinessTripEntity>();
|
||||
entity.Status = BusinessTripStatusEnumType.Wait;
|
||||
await _dbContext.InsertAsync(entity);
|
||||
}
|
||||
|
||||
//获取今天和昨天的出差数据
|
||||
var tripInfos = await _dbContext.Queryable<BusinessTripEntity>()
|
||||
.Where(x => (SqlFunc.DateIsSame(x.BeginDate, today) && SqlFunc.DateIsSame(x.BeginDate, today))
|
||||
|| (SqlFunc.DateIsSame(x.BeginDate, yesterday) && SqlFunc.DateIsSame(x.BeginDate, yesterday)))
|
||||
.Where(x => !SqlFunc.IsNullOrEmpty(x.Destination))
|
||||
.Where(x => x.Destination == factory)
|
||||
.ToListAsync();
|
||||
|
||||
//获取分组信息
|
||||
var tripGroup = await _dbContext.Queryable<DeviceGroupEntity>()
|
||||
.Where(x => x.Type == DeviceTypeEnumType.Door)
|
||||
.Where(x => x.TenantId == factory)
|
||||
.Where(x => x.IsBusinessTrip)
|
||||
.SingleAsync();
|
||||
|
||||
var userCodes = tripInfos.Select(x => x.Code).Distinct().ToList();
|
||||
var gainfos = await _dbContext.Queryable<GainfoEntity>().Where(x => userCodes.Contains(x.Code)).ToListAsync();
|
||||
|
||||
foreach (var gainfo in gainfos)
|
||||
{
|
||||
try
|
||||
{
|
||||
var myTripInfos = tripInfos.Where(x => x.Code == gainfo.Code).ToList();
|
||||
|
||||
var yesterdayTripInfo = myTripInfos.FirstOrDefault(x => x.BeginDate == yesterday && x.EndDate == yesterday); //昨天出差数据
|
||||
var todayTripInfo = myTripInfos.FirstOrDefault(x => x.BeginDate == today && x.EndDate == today); //今天出差数据
|
||||
|
||||
//都为空不处理
|
||||
if (yesterdayTripInfo == null && todayTripInfo == null) continue;
|
||||
|
||||
//都不为空则更新数据状态
|
||||
if (yesterdayTripInfo != null && todayTripInfo != null)
|
||||
{
|
||||
todayTripInfo.Status = BusinessTripStatusEnumType.Generated;
|
||||
await _dbContext.UpdateAsync(todayTripInfo);
|
||||
continue;
|
||||
}
|
||||
|
||||
var beforeResult = await _devicePermissionApi.GetPermissionUsersInfoAsync(new List<string> { gainfo.Code });
|
||||
|
||||
if (yesterdayTripInfo != null)
|
||||
{
|
||||
yesterdayTripInfo.Status = BusinessTripStatusEnumType.Deleted;
|
||||
await _dbContext.Updateable<DevicePermissionEntity>()
|
||||
.SetColumns(x => x.IsDeleted == true)
|
||||
.Where(x => x.AssignType == AssignTypeEnumType.User)
|
||||
.Where(x => x.AssignValue == gainfo.No)
|
||||
.Where(x => x.UniqueType == DeviceAssignmentTypeEnumType.Group)
|
||||
.Where(x => x.UniqueValue == tripGroup.Code)
|
||||
.Where(x => x.Type == tripGroup.Type)
|
||||
.Where(x => x.TenantId == factory)
|
||||
.ExecuteCommandAsync();
|
||||
await _dbContext.UpdateAsync(yesterdayTripInfo);
|
||||
}
|
||||
|
||||
if (yesterdayTripInfo == null)
|
||||
{
|
||||
todayTripInfo.Status = BusinessTripStatusEnumType.Generated;
|
||||
await _dbContext.InsertAsync(new DevicePermissionEntity
|
||||
{
|
||||
AssignType = AssignTypeEnumType.User,
|
||||
AssignValue = gainfo.No,
|
||||
UniqueType = DeviceAssignmentTypeEnumType.Group,
|
||||
UniqueValue = tripGroup.Code,
|
||||
TenantId = factory,
|
||||
Type = tripGroup.Type,
|
||||
IsDeleted = false
|
||||
});
|
||||
await _dbContext.UpdateAsync(todayTripInfo);
|
||||
}
|
||||
|
||||
await _devicePermissionApi.RePermissionUsersInfoAsync(beforeResult.Data);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e, "出差自动下发任务失败:{message}", e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e, "处理{factory}出差数据失败:{message}", factory, e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user