fix 判断设备号是否存在进行下发和移除处理
This commit is contained in:
@@ -77,80 +77,85 @@ public class SapBusinessTripService : ISapBusinessTripService
|
||||
|
||||
var deviceCodes = await _dbContext.Queryable<DeviceGroupRelationshipEntity>().Where(x => x.GroupCode == tripGroup.Code).Select(x => x.DeviceCode).ToListAsync();
|
||||
|
||||
var userCodes = tripInfos.Select(x => x.Code).Distinct().ToList();
|
||||
var gainfos = await _dbContext.Queryable<GainfoEntity>().Where(x => userCodes.Contains(x.Code)).Select(x => new { x.No, x.Code }).ToListAsync();
|
||||
|
||||
foreach (var gainfo in gainfos)
|
||||
if (deviceCodes.Any())
|
||||
{
|
||||
try
|
||||
var userCodes = tripInfos.Select(x => x.Code).Distinct().ToList();
|
||||
var gainfos = await _dbContext.Queryable<GainfoEntity>().Where(x => userCodes.Contains(x.Code)).Select(x => new { x.No, x.Code }).ToListAsync();
|
||||
|
||||
foreach (var gainfo in gainfos)
|
||||
{
|
||||
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)
|
||||
try
|
||||
{
|
||||
todayTripInfo.Status = BusinessTripStatusEnumType.Generated;
|
||||
await _dbContext.UpdateAsync(todayTripInfo);
|
||||
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
|
||||
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();
|
||||
//都为空不处理
|
||||
if (yesterdayTripInfo == null && todayTripInfo == null) continue;
|
||||
|
||||
await _dbContext.UpdateAsync(yesterdayTripInfo);
|
||||
await _gainfoPermissionService.ResetPermissionsAsync(gainfo.No, DeviceTaskEnumType.Delete, deviceCodes);
|
||||
}
|
||||
//都不为空则更新数据状态
|
||||
if (yesterdayTripInfo != null && todayTripInfo != null)
|
||||
{
|
||||
todayTripInfo.Status = BusinessTripStatusEnumType.Generated;
|
||||
await _dbContext.UpdateAsync(todayTripInfo);
|
||||
|
||||
if (yesterdayTripInfo == null)
|
||||
{
|
||||
//todayTripInfo != null
|
||||
if (!await _dbContext.Queryable<DevicePermissionEntity>()
|
||||
//下发
|
||||
await _gainfoPermissionService.ResetPermissionsAsync(gainfo.No, DeviceTaskEnumType.Add, null);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (yesterdayTripInfo != null)
|
||||
{
|
||||
//todayTripInfo == 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)
|
||||
.AnyAsync())
|
||||
{
|
||||
await _dbContext.InsertAsync(new DevicePermissionEntity
|
||||
{
|
||||
AssignType = AssignTypeEnumType.User,
|
||||
AssignValue = gainfo.No,
|
||||
UniqueType = DeviceAssignmentTypeEnumType.Group,
|
||||
UniqueValue = tripGroup.Code,
|
||||
Type = tripGroup.Type,
|
||||
TenantId = factory
|
||||
});
|
||||
.ExecuteCommandAsync();
|
||||
|
||||
await _dbContext.UpdateAsync(yesterdayTripInfo);
|
||||
await _gainfoPermissionService.ResetPermissionsAsync(gainfo.No, DeviceTaskEnumType.Delete, deviceCodes);
|
||||
}
|
||||
|
||||
todayTripInfo.Status = BusinessTripStatusEnumType.Generated;
|
||||
await _dbContext.UpdateAsync(todayTripInfo);
|
||||
if (yesterdayTripInfo == null)
|
||||
{
|
||||
//todayTripInfo != null
|
||||
if (!await _dbContext.Queryable<DevicePermissionEntity>()
|
||||
.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)
|
||||
.AnyAsync())
|
||||
{
|
||||
await _dbContext.InsertAsync(new DevicePermissionEntity
|
||||
{
|
||||
AssignType = AssignTypeEnumType.User,
|
||||
AssignValue = gainfo.No,
|
||||
UniqueType = DeviceAssignmentTypeEnumType.Group,
|
||||
UniqueValue = tripGroup.Code,
|
||||
Type = tripGroup.Type,
|
||||
TenantId = factory
|
||||
});
|
||||
}
|
||||
|
||||
await _gainfoPermissionService.ResetPermissionsAsync(gainfo.No, DeviceTaskEnumType.Add, null);
|
||||
todayTripInfo.Status = BusinessTripStatusEnumType.Generated;
|
||||
await _dbContext.UpdateAsync(todayTripInfo);
|
||||
|
||||
await _gainfoPermissionService.ResetPermissionsAsync(gainfo.No, DeviceTaskEnumType.Add, null);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e, "出差自动下发任务失败:{message}", e.Message);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e, "出差自动下发任务失败:{message}", e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user