fix 修复已知问题
This commit is contained in:
@@ -38,12 +38,7 @@ public class BusinessPlaceShiftSaveMealShiftRequest : IValidatableObject
|
|||||||
yield return new ValidationResult("时间段配置错误", new[] { nameof(TimePeriod) });
|
yield return new ValidationResult("时间段配置错误", new[] { nameof(TimePeriod) });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TimePeriod!.Start == null || TimePeriod!.End == null)
|
if (TimePeriod!.Start == TimePeriod.End)
|
||||||
{
|
|
||||||
yield return new ValidationResult("时间段配置错误", new[] { nameof(TimePeriod) });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TimePeriod!.Start == TimePeriod!.End)
|
|
||||||
{
|
{
|
||||||
yield return new ValidationResult("时间段设置区间有误,开始时段不能等于结束时段.", new[] { nameof(TimePeriod) });
|
yield return new ValidationResult("时间段设置区间有误,开始时段不能等于结束时段.", new[] { nameof(TimePeriod) });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -455,7 +455,7 @@ public class DevicePermissionService : IDevicePermissionService
|
|||||||
|
|
||||||
var isOutsource = await _dbContext.Queryable<OutsourceEntity>().AnyAsync(x => x.Code == gainfo.Code);
|
var isOutsource = await _dbContext.Queryable<OutsourceEntity>().AnyAsync(x => x.Code == gainfo.Code);
|
||||||
|
|
||||||
var enableFactoryPermissions = await _dbContext.Queryable<OutsourceSettingEntity>().ToListAsync();
|
var enableFactoryPermissions = await _dbContext.Queryable<FactorySettingEntity>().ToListAsync();
|
||||||
|
|
||||||
var gainfoDto = new GainfoDto
|
var gainfoDto = new GainfoDto
|
||||||
{
|
{
|
||||||
@@ -467,7 +467,7 @@ public class DevicePermissionService : IDevicePermissionService
|
|||||||
Factory = gainfo.Factory,
|
Factory = gainfo.Factory,
|
||||||
DepartmentNo = gainfo.DepartmentNo,
|
DepartmentNo = gainfo.DepartmentNo,
|
||||||
IsOutsource = isOutsource,
|
IsOutsource = isOutsource,
|
||||||
EnableFactoryPermission = enableFactoryPermissions.FirstOrDefault(x => x.TenantId == gainfo.Factory)?.EnableFactory ?? true
|
EnableFactoryPermission = enableFactoryPermissions.FirstOrDefault(x => x.TenantId == gainfo.Factory)?.EnableOutsourceDown ?? true
|
||||||
};
|
};
|
||||||
|
|
||||||
var result = GetAssignDeviceCodesInternal(gainfoDto, gainfoGroups, devicePermissions, deviceGroups, deviceRelationships, deviceRegistries, devices, departments);
|
var result = GetAssignDeviceCodesInternal(gainfoDto, gainfoGroups, devicePermissions, deviceGroups, deviceRelationships, deviceRegistries, devices, departments);
|
||||||
@@ -627,7 +627,7 @@ public class DevicePermissionService : IDevicePermissionService
|
|||||||
.Select(x => x.Code)
|
.Select(x => x.Code)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
var enableFactoryPermissions = await _dbContext.Queryable<OutsourceSettingEntity>().ToListAsync();
|
var enableFactoryPermissions = await _dbContext.Queryable<FactorySettingEntity>().ToListAsync();
|
||||||
|
|
||||||
var gainfoGroupRelationships = await _dbContext.Queryable<GainfoGroupRelationshipEntity>().Where(x => userNos.Contains(x.UserNo)).ToListAsync();
|
var gainfoGroupRelationships = await _dbContext.Queryable<GainfoGroupRelationshipEntity>().Where(x => userNos.Contains(x.UserNo)).ToListAsync();
|
||||||
var devicePermissions = await _dbContext.Queryable<DevicePermissionEntity>().ToListAsync();
|
var devicePermissions = await _dbContext.Queryable<DevicePermissionEntity>().ToListAsync();
|
||||||
@@ -648,7 +648,7 @@ public class DevicePermissionService : IDevicePermissionService
|
|||||||
Factory = gainfo.Factory,
|
Factory = gainfo.Factory,
|
||||||
DepartmentNo = gainfo.DepartmentNo,
|
DepartmentNo = gainfo.DepartmentNo,
|
||||||
IsOutsource = outsourceCodes.Any(x => x == gainfo.Code),
|
IsOutsource = outsourceCodes.Any(x => x == gainfo.Code),
|
||||||
EnableFactoryPermission = enableFactoryPermissions.FirstOrDefault(x => x.TenantId == gainfo.Factory)?.EnableFactory ?? true
|
EnableFactoryPermission = enableFactoryPermissions.FirstOrDefault(x => x.TenantId == gainfo.Factory)?.EnableOutsourceDown ?? true
|
||||||
};
|
};
|
||||||
|
|
||||||
var codes = GetAssignDeviceCodesInternal(gainfoDto, gainfoGroupRelationships, devicePermissions, deviceGroups, deviceRelationships, registries, devices, departments);
|
var codes = GetAssignDeviceCodesInternal(gainfoDto, gainfoGroupRelationships, devicePermissions, deviceGroups, deviceRelationships, registries, devices, departments);
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public class GainfoQrCodeController : ControllerBase
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="isNeedRefresh">是否主动刷新</param>
|
/// <param name="isNeedRefresh">是否主动刷新</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet("consumer")]
|
[HttpGet("consume")]
|
||||||
public async Task<string> GetMyQrCode(bool isNeedRefresh = false)
|
public async Task<string> GetMyQrCode(bool isNeedRefresh = false)
|
||||||
{
|
{
|
||||||
return await _gainfoQrCodeService.GetMyQrCodeAsync(isNeedRefresh);
|
return await _gainfoQrCodeService.GetMyQrCodeAsync(isNeedRefresh);
|
||||||
|
|||||||
@@ -10,6 +10,6 @@ public class GainfoFacePageRequest : PageDto
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 厂区
|
/// 厂区
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Required(ErrorMessage = "厂区不可为空")]
|
[MinLength(1, ErrorMessage = "厂区不可为空")]
|
||||||
public string Factory { get; set; }
|
public string Factories { get; set; }
|
||||||
}
|
}
|
||||||
@@ -53,6 +53,16 @@ public class GainfoCurrentResponse
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string Factory { get; set; }
|
public string Factory { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 卡类型
|
||||||
|
/// </summary>
|
||||||
|
public int? CardType { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 卡类型名称
|
||||||
|
/// </summary>
|
||||||
|
public string CardTypeName { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 就餐信息
|
/// 就餐信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -141,6 +141,11 @@ public class GainfoDetailResponse
|
|||||||
public DateTime? EntryDate { get; set; }
|
public DateTime? EntryDate { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
public int? CardType { get; set; }
|
||||||
|
|
||||||
|
public string CardTypeName { get; set; }
|
||||||
|
|
||||||
|
|
||||||
//***********************************************************************************************************************
|
//***********************************************************************************************************************
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
namespace Dlhis.Basic.Organization.Response;
|
using Dlhis.Entity.Basic.Enums;
|
||||||
|
using Kurisu.AspNetCore.Utils.Extensions;
|
||||||
|
|
||||||
|
namespace Dlhis.Basic.Organization.Response;
|
||||||
|
|
||||||
public class GainfoMealResponse
|
public class GainfoMealResponse
|
||||||
{
|
{
|
||||||
@@ -39,4 +42,14 @@ public class GainfoMealResponse
|
|||||||
/// 餐补总额
|
/// 餐补总额
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public decimal? MealSupplementAmount { get; set; }
|
public decimal? MealSupplementAmount { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 档案状态
|
||||||
|
/// </summary>
|
||||||
|
public GainfoStatusEnumType Status { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 档案状态中文
|
||||||
|
/// </summary>
|
||||||
|
public string StatusDesc => Status.GetDescription();
|
||||||
}
|
}
|
||||||
@@ -26,11 +26,6 @@ public class GainfoPageResponse
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 外文名字
|
|
||||||
/// </summary>
|
|
||||||
public string NameEn { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 工号
|
/// 工号
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -91,6 +86,11 @@ public class GainfoPageResponse
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string DepartmentNo { get; set; }
|
public string DepartmentNo { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 部门名称
|
||||||
|
/// </summary>
|
||||||
|
public string DepartmentName { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 民族代码
|
/// 民族代码
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -51,12 +51,14 @@ public class GainfoFaceService : IGainfoFaceService
|
|||||||
|
|
||||||
public async Task<GainfoFacePageSummaryResponse> GetPageAsync(GainfoFacePageRequest request)
|
public async Task<GainfoFacePageSummaryResponse> GetPageAsync(GainfoFacePageRequest request)
|
||||||
{
|
{
|
||||||
var userCodes = await _dbContext.Queryable<GainfoEntity>().Where(x => x.Factory == request.Factory).Select(x => x.Code).ToListAsync();
|
var factories = request.Factories;
|
||||||
|
|
||||||
|
var userCodes = await _dbContext.Queryable<GainfoEntity>().Where(x => factories.Contains(x.Factory)).Select(x => x.Code).ToListAsync();
|
||||||
var existsFaceCodes = await _faceDbContext.Queryable<GainfoFaceEntity>().Where(x => userCodes.Contains(x.UserCode)).Select(x => x.UserCode).ToListAsync();
|
var existsFaceCodes = await _faceDbContext.Queryable<GainfoFaceEntity>().Where(x => userCodes.Contains(x.UserCode)).Select(x => x.UserCode).ToListAsync();
|
||||||
|
|
||||||
var list = await _dbContext.Queryable<GainfoEntity>()
|
var list = await _dbContext.Queryable<GainfoEntity>()
|
||||||
.LeftJoin<DepartmentEntity>((x, d) => x.DepartmentNo == d.No)
|
.LeftJoin<DepartmentEntity>((x, d) => x.DepartmentNo == d.No)
|
||||||
.Where(x => x.Factory == request.Factory)
|
.Where(x => factories.Contains(x.Factory))
|
||||||
.WhereIF(request.Exists.HasValue && request.Exists.Value, x => existsFaceCodes.Contains(x.Code))
|
.WhereIF(request.Exists.HasValue && request.Exists.Value, x => existsFaceCodes.Contains(x.Code))
|
||||||
.WhereIF(request.Exists.HasValue && !request.Exists.Value, x => !existsFaceCodes.Contains(x.Code))
|
.WhereIF(request.Exists.HasValue && !request.Exists.Value, x => !existsFaceCodes.Contains(x.Code))
|
||||||
.WhereIF(request.Search.IsPresent(), x => x.Code == request.Search)
|
.WhereIF(request.Search.IsPresent(), x => x.Code == request.Search)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using Dlhis.Basic.Organization.Request;
|
using Dlhis.Basic.Organization.Request;
|
||||||
using Dlhis.Basic.Organization.Response;
|
using Dlhis.Basic.Organization.Response;
|
||||||
using Dlhis.Entity.Basic.Entity;
|
using Dlhis.Entity.Basic.Entity;
|
||||||
|
using Dlhis.Entity.Basic.Enums;
|
||||||
using Dlhis.Entity.Canteen.Entities;
|
using Dlhis.Entity.Canteen.Entities;
|
||||||
using Dlhis.Entity.Canteen.Enums;
|
using Dlhis.Entity.Canteen.Enums;
|
||||||
using Kurisu.AspNetCore.Authentication.Abstractions;
|
using Kurisu.AspNetCore.Authentication.Abstractions;
|
||||||
@@ -47,7 +48,8 @@ public class GainfoMealService : IGainfoMealService
|
|||||||
UserCode = meal.UserCode,
|
UserCode = meal.UserCode,
|
||||||
UserName = SqlFunc.IsNull(gainfo.Name, gainfoLeave.Name),
|
UserName = SqlFunc.IsNull(gainfo.Name, gainfoLeave.Name),
|
||||||
UserNo = SqlFunc.IsNull(gainfo.No, gainfoLeave.No),
|
UserNo = SqlFunc.IsNull(gainfo.No, gainfoLeave.No),
|
||||||
DepartmentName = SqlFunc.IsNull(dept1.Name, dept2.Name)
|
DepartmentName = SqlFunc.IsNull(dept1.Name, dept2.Name),
|
||||||
|
Status = SqlFunc.IsNullOrEmpty(gainfo.No) ? GainfoStatusEnumType.Leave : GainfoStatusEnumType.Working
|
||||||
})
|
})
|
||||||
.ToPageListAsync(request);
|
.ToPageListAsync(request);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using Dlhis.Basic.Device.Services;
|
using Dlhis.Basic.Device.Services;
|
||||||
using Dlhis.Basic.Organization.Request;
|
using Dlhis.Basic.Organization.Request;
|
||||||
using Dlhis.Entity.Basic.Entity;
|
using Dlhis.Entity.Basic.Entity;
|
||||||
|
using Dlhis.Entity.Sys.Entities;
|
||||||
using Kurisu.AspNetCore.Authentication.Abstractions;
|
using Kurisu.AspNetCore.Authentication.Abstractions;
|
||||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||||
using Kurisu.AspNetCore.Utils.Extensions;
|
using Kurisu.AspNetCore.Utils.Extensions;
|
||||||
@@ -32,15 +33,15 @@ public class GainfoOutsourceSettingService : IGainfoOutsourceSettingService
|
|||||||
{
|
{
|
||||||
var currentTenantId = _currentUser.GetStringTenantId();
|
var currentTenantId = _currentUser.GetStringTenantId();
|
||||||
|
|
||||||
(!request.Id.HasValue && await _dbContext.Queryable<OutsourceSettingEntity>()
|
(!request.Id.HasValue && await _dbContext.Queryable<FactorySettingEntity>()
|
||||||
.Where(x => x.TenantId == currentTenantId)
|
.Where(x => x.TenantId == currentTenantId)
|
||||||
.AnyAsync()).ThrowIfTrue("保存失败,请检查参数");
|
.AnyAsync()).ThrowIfTrue("保存失败,请检查参数");
|
||||||
|
|
||||||
if (!request.Id.HasValue)
|
if (!request.Id.HasValue)
|
||||||
{
|
{
|
||||||
var entity = new OutsourceSettingEntity
|
var entity = new FactorySettingEntity
|
||||||
{
|
{
|
||||||
EnableFactory = request.EnableFactory,
|
EnableOutsourceDown = request.EnableFactory,
|
||||||
TenantId = currentTenantId
|
TenantId = currentTenantId
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -48,10 +49,10 @@ public class GainfoOutsourceSettingService : IGainfoOutsourceSettingService
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var entity = await _dbContext.Queryable<OutsourceSettingEntity>().Where(x => x.Id == request.Id).SingleAsync();
|
var entity = await _dbContext.Queryable<FactorySettingEntity>().Where(x => x.Id == request.Id).SingleAsync();
|
||||||
entity.ThrowIfNull("数据不存在,保存失败");
|
entity.ThrowIfNull("数据不存在,保存失败");
|
||||||
|
|
||||||
entity.EnableFactory = request.EnableFactory;
|
entity.EnableOutsourceDown = request.EnableFactory;
|
||||||
|
|
||||||
await _dbContext.UpdateAsync(entity);
|
await _dbContext.UpdateAsync(entity);
|
||||||
}
|
}
|
||||||
@@ -62,10 +63,9 @@ public class GainfoOutsourceSettingService : IGainfoOutsourceSettingService
|
|||||||
public async Task<object> GetSettingAsync()
|
public async Task<object> GetSettingAsync()
|
||||||
{
|
{
|
||||||
var currentTenantId = _currentUser.GetStringTenantId();
|
var currentTenantId = _currentUser.GetStringTenantId();
|
||||||
return await _dbContext.Queryable<OutsourceSettingEntity>().Where(x => x.TenantId == currentTenantId).Select(x => new
|
return await _dbContext.Queryable<FactorySettingEntity>().Where(x => x.TenantId == currentTenantId).Select(x => new
|
||||||
{
|
{
|
||||||
x.Id,
|
x.Id, EnableFactory = x.EnableOutsourceDown
|
||||||
x.EnableFactory
|
|
||||||
}).SingleAsync();
|
}).SingleAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -17,11 +17,13 @@ public class GainfoQrCodeService : IGainfoQrCodeService
|
|||||||
_currentUser = currentUser;
|
_currentUser = currentUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task<string> GetMyQrCodeAsync(bool isNeedRefresh = false)
|
public async Task<string> GetMyQrCodeAsync(bool isNeedRefresh = false)
|
||||||
{
|
{
|
||||||
var jinkoCode = _currentUser.GetUserClaim("jinko-code");
|
var jinkoCode = _currentUser.GetUserClaim("jinko-code");
|
||||||
jinkoCode.IsEmpty().ThrowIfTrue("无法获取二维码");
|
if (jinkoCode.IsEmpty())
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
var now = DateTime.Now;
|
var now = DateTime.Now;
|
||||||
var gainfoQrCode = await _dbContext.Queryable<GainfoQrCodeEntity>().SingleAsync(x => x.UserCode == jinkoCode);
|
var gainfoQrCode = await _dbContext.Queryable<GainfoQrCodeEntity>().SingleAsync(x => x.UserCode == jinkoCode);
|
||||||
@@ -53,11 +55,9 @@ public class GainfoQrCodeService : IGainfoQrCodeService
|
|||||||
private static string GenerateQrCode(string code)
|
private static string GenerateQrCode(string code)
|
||||||
{
|
{
|
||||||
var ts = DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
var ts = DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
||||||
//var gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.Code == code).SingleAsync();
|
|
||||||
//var qrCode = string.Concat("consumer", ":", code, ":", Guid.NewGuid()).Replace("-", "");
|
|
||||||
var qrCode = string.Concat("consumer", ":", code, ":");
|
var qrCode = string.Concat("consumer", ":", code, ":");
|
||||||
|
|
||||||
return qrCode.ToArray().Select(x =>
|
return "01" + qrCode.ToArray().Select(x =>
|
||||||
{
|
{
|
||||||
var b = Encoding.ASCII.GetBytes(x.ToString());
|
var b = Encoding.ASCII.GetBytes(x.ToString());
|
||||||
int i = b[0];
|
int i = b[0];
|
||||||
|
|||||||
@@ -88,7 +88,11 @@ public class GainfoService : IGainfoService
|
|||||||
gainfo.Name.Contains(request.Search)
|
gainfo.Name.Contains(request.Search)
|
||||||
|| gainfo.Code == request.Search
|
|| gainfo.Code == request.Search
|
||||||
|| gainfo.IdNo == request.Search)
|
|| gainfo.IdNo == request.Search)
|
||||||
.Select<GainfoPageResponse>()
|
.LeftJoin<DepartmentEntity>((x, department) => x.DepartmentNo == department.No)
|
||||||
|
.Select((x, department) => new GainfoPageResponse
|
||||||
|
{
|
||||||
|
DepartmentName = department.Name
|
||||||
|
}, true)
|
||||||
.ToPageListAsync(request);
|
.ToPageListAsync(request);
|
||||||
|
|
||||||
|
|
||||||
@@ -142,8 +146,9 @@ public class GainfoService : IGainfoService
|
|||||||
var info = await _gainfoStore.Queryable(GainfoStatusEnumType.Working)
|
var info = await _gainfoStore.Queryable(GainfoStatusEnumType.Working)
|
||||||
.LeftJoin<DepartmentEntity>((ga, department) => ga.DepartmentNo == department.No)
|
.LeftJoin<DepartmentEntity>((ga, department) => ga.DepartmentNo == department.No)
|
||||||
.LeftJoin<GainfoMealEntity>((ga, department, mealUser) => ga.No == mealUser.UserNo)
|
.LeftJoin<GainfoMealEntity>((ga, department, mealUser) => ga.No == mealUser.UserNo)
|
||||||
|
.LeftJoin<BasicTypeEntity>((ga, department, mealUser, type) => type.Code == ga.CardType.ToString() && type.Type == "timeperiod")
|
||||||
.Where((ga, department) => ga.Id == gainfo.Id)
|
.Where((ga, department) => ga.Id == gainfo.Id)
|
||||||
.Select((ga, department, mealUser) => new GainfoCurrentResponse
|
.Select((ga, department, mealUser, type) => new GainfoCurrentResponse
|
||||||
{
|
{
|
||||||
UserNo = ga.No,
|
UserNo = ga.No,
|
||||||
Birthday = ga.Birthday,
|
Birthday = ga.Birthday,
|
||||||
@@ -156,7 +161,9 @@ public class GainfoService : IGainfoService
|
|||||||
MealInfo = new GainfoCurrentMealInfoResponse
|
MealInfo = new GainfoCurrentMealInfoResponse
|
||||||
{
|
{
|
||||||
Balance = mealUser.Balance
|
Balance = mealUser.Balance
|
||||||
}
|
},
|
||||||
|
CardType = ga.CardType,
|
||||||
|
CardTypeName = type.Display
|
||||||
}).SingleAsync();
|
}).SingleAsync();
|
||||||
|
|
||||||
if (info != null)
|
if (info != null)
|
||||||
@@ -265,8 +272,9 @@ public class GainfoService : IGainfoService
|
|||||||
var info = await _gainfoStore.Queryable(request.Status)
|
var info = await _gainfoStore.Queryable(request.Status)
|
||||||
.LeftJoin<DepartmentEntity>((ga, de) => ga.DepartmentNo == de.No)
|
.LeftJoin<DepartmentEntity>((ga, de) => ga.DepartmentNo == de.No)
|
||||||
.LeftJoin<PositionEntity>((ga, de, pos) => ga.PositionNo == pos.No)
|
.LeftJoin<PositionEntity>((ga, de, pos) => ga.PositionNo == pos.No)
|
||||||
|
.LeftJoin<BasicTypeEntity>((ga, de, pos, type) => type.Code == ga.CardType.ToString() && type.Type == "timeperiod")
|
||||||
.Where(ga => ga.No == request.No)
|
.Where(ga => ga.No == request.No)
|
||||||
.Select((ga, de, pos) => new GainfoDetailResponse
|
.Select((ga, de, pos, type) => new GainfoDetailResponse
|
||||||
{
|
{
|
||||||
No = ga.No,
|
No = ga.No,
|
||||||
SapNo = ga.SapNo,
|
SapNo = ga.SapNo,
|
||||||
@@ -295,6 +303,8 @@ public class GainfoService : IGainfoService
|
|||||||
|
|
||||||
DepartmentName = de.Name,
|
DepartmentName = de.Name,
|
||||||
Position = pos.Name,
|
Position = pos.Name,
|
||||||
|
CardType = ga.CardType,
|
||||||
|
CardTypeName = type.Display
|
||||||
})
|
})
|
||||||
.SingleAsync();
|
.SingleAsync();
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,15 @@ public class MealSupplementRecordRequest : PageDto, IValidatableObject
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string Factory { get; set; }
|
public string Factory { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 部门号
|
||||||
|
/// </summary>
|
||||||
|
public string DepartmentNo { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 人事范围
|
||||||
|
/// </summary>
|
||||||
|
public string Werks { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 餐补日期范围
|
/// 餐补日期范围
|
||||||
|
|||||||
@@ -45,7 +45,9 @@ public class MealSupplementRecordResponse
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string Factory { get; set; }
|
public string Factory { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 备注
|
||||||
|
/// </summary>
|
||||||
public string Remark { get; set; }
|
public string Remark { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -63,5 +65,18 @@ public class MealSupplementRecordResponse
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Sync { get; set; }
|
public bool Sync { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 创建时间
|
||||||
|
/// </summary>
|
||||||
public DateTime CreateTime { get; set; }
|
public DateTime CreateTime { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 部门名称
|
||||||
|
/// </summary>
|
||||||
|
public string DepartmentName { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 人事范围
|
||||||
|
/// </summary>
|
||||||
|
public string Werks { get; set; }
|
||||||
}
|
}
|
||||||
@@ -32,13 +32,16 @@ public class MealSupplementRecordService : IMealSupplementRecordService
|
|||||||
{
|
{
|
||||||
var page = await _dbContext.Queryable<MealSupplementRecordEntity>()
|
var page = await _dbContext.Queryable<MealSupplementRecordEntity>()
|
||||||
.LeftJoin<GainfoEntity>((x, ga) => x.Code == ga.Code)
|
.LeftJoin<GainfoEntity>((x, ga) => x.Code == ga.Code)
|
||||||
|
.LeftJoin<DepartmentEntity>((x, ga, department) => ga.DepartmentNo == department.No)
|
||||||
.WhereIF(request.Status.HasValue, x => x.Status == request.Status)
|
.WhereIF(request.Status.HasValue, x => x.Status == request.Status)
|
||||||
.WhereIF(request.Sync.HasValue, x => x.Sync == request.Sync)
|
.WhereIF(request.Sync.HasValue, x => x.Sync == request.Sync)
|
||||||
.WhereIF(request.Workplace.IsPresent(), x => x.Workplace == request.Workplace)
|
.WhereIF(request.Workplace.IsPresent(), x => x.Workplace == request.Workplace)
|
||||||
.WhereIF(request.Factory.IsPresent(), x => x.Factory == request.Factory)
|
.WhereIF(request.Factory.IsPresent(), x => x.Factory == request.Factory)
|
||||||
|
.WhereIF(request.DepartmentNo.IsPresent(), (x, ga) => ga.DepartmentNo == request.DepartmentNo)
|
||||||
|
.WhereIF(request.Werks.IsPresent(), (x, ga) => ga.Werks == request.Werks)
|
||||||
.WhereIF(request.DateTimePeriod.HasValue(), x => x.Date >= request.DateTimePeriod.Start && x.Date <= request.DateTimePeriod.End)
|
.WhereIF(request.DateTimePeriod.HasValue(), x => x.Date >= request.DateTimePeriod.Start && x.Date <= request.DateTimePeriod.End)
|
||||||
.WhereIF(request.Search.IsPresent(), (x, ga) => x.Code == request.Search || ga.Name == request.Search)
|
.WhereIF(request.Search.IsPresent(), (x, ga) => x.Code == request.Search || ga.Name == request.Search)
|
||||||
.Select((x, ga) => new MealSupplementRecordResponse
|
.Select((x, ga, department) => new MealSupplementRecordResponse
|
||||||
{
|
{
|
||||||
Amount = x.Amount,
|
Amount = x.Amount,
|
||||||
Code = x.Code,
|
Code = x.Code,
|
||||||
@@ -51,7 +54,9 @@ public class MealSupplementRecordService : IMealSupplementRecordService
|
|||||||
UserName = ga.Name,
|
UserName = ga.Name,
|
||||||
Workplace = x.Workplace,
|
Workplace = x.Workplace,
|
||||||
Factory = x.Factory,
|
Factory = x.Factory,
|
||||||
CreateTime = x.CreateTime
|
CreateTime = x.CreateTime,
|
||||||
|
DepartmentName = department.Name,
|
||||||
|
Werks = ga.Werks
|
||||||
})
|
})
|
||||||
.ToPageListAsync(request);
|
.ToPageListAsync(request);
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ public class OrdersController : ControllerBase
|
|||||||
_logger.LogInformation("消费请求:{json}. 耗时记录:{log}", request.ToJson(), result.Logs.Join("\r\n"));
|
_logger.LogInformation("消费请求:{json}. 耗时记录:{log}", request.ToJson(), result.Logs.Join("\r\n"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
//ignore
|
//ignore
|
||||||
}
|
}
|
||||||
@@ -90,7 +90,7 @@ public class OrdersController : ControllerBase
|
|||||||
_logger.LogInformation("消费请求:{json}. 耗时记录:{log}", request.ToJson(), result.Logs.Join("\r\n"));
|
_logger.LogInformation("消费请求:{json}. 耗时记录:{log}", request.ToJson(), result.Logs.Join("\r\n"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
//ignore
|
//ignore
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Dlhis.Entity.Basic.Enums;
|
||||||
using Dlhis.Entity.Canteen.Enums;
|
using Dlhis.Entity.Canteen.Enums;
|
||||||
using Kurisu.AspNetCore.CustomClass;
|
using Kurisu.AspNetCore.CustomClass;
|
||||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||||
@@ -28,14 +29,19 @@ public class BalanceRecordPageRequest : PageDto, IValidatableObject
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTimePeriod SearchDateTimePeriod { get; set; }
|
public DateTimePeriod SearchDateTimePeriod { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 档案状态
|
||||||
|
/// </summary>
|
||||||
|
[EnumDataType(typeof(GainfoStatusEnumType))]
|
||||||
|
public GainfoStatusEnumType? GainfoStatus { get; set; }
|
||||||
|
|
||||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||||
{
|
{
|
||||||
if (SearchDateTimePeriod != null)
|
GainfoStatus ??= GainfoStatusEnumType.Working;
|
||||||
|
|
||||||
|
if (SearchDateTimePeriod?.End != null)
|
||||||
{
|
{
|
||||||
if (SearchDateTimePeriod.End.HasValue)
|
SearchDateTimePeriod.End = SearchDateTimePeriod.End.Value.AddDays(1).AddSeconds(-1);
|
||||||
{
|
|
||||||
SearchDateTimePeriod.End = SearchDateTimePeriod.End.Value.AddDays(1).AddSeconds(-1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
yield break;
|
yield break;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using Dlhis.Canteen.Order.Request;
|
|||||||
using Dlhis.Canteen.Order.Response;
|
using Dlhis.Canteen.Order.Response;
|
||||||
using Dlhis.Canteen.Setting.Services;
|
using Dlhis.Canteen.Setting.Services;
|
||||||
using Dlhis.Entity.Basic.Entity;
|
using Dlhis.Entity.Basic.Entity;
|
||||||
|
using Dlhis.Entity.Basic.Enums;
|
||||||
using Dlhis.Entity.Canteen.Entities;
|
using Dlhis.Entity.Canteen.Entities;
|
||||||
using Dlhis.Entity.Canteen.Enums;
|
using Dlhis.Entity.Canteen.Enums;
|
||||||
using Dlhis.Entity.Device;
|
using Dlhis.Entity.Device;
|
||||||
@@ -45,7 +46,8 @@ public class BalanceService : IBalanceService
|
|||||||
public async Task<Pagination<BalanceRecordResponse>> GetPageAsync(BalanceRecordPageRequest request)
|
public async Task<Pagination<BalanceRecordResponse>> GetPageAsync(BalanceRecordPageRequest request)
|
||||||
{
|
{
|
||||||
var page = await _dbContext.Queryable<BalanceRecordEntity>()
|
var page = await _dbContext.Queryable<BalanceRecordEntity>()
|
||||||
.LeftJoin<GainfoEntity>((record, ga) => record.UserNo == ga.No)
|
.LeftJoinIF<GainfoEntity>(request.GainfoStatus == GainfoStatusEnumType.Working, (record, ga) => record.UserNo == ga.No)
|
||||||
|
.LeftJoinIF<GainfoLeaveEntity>(request.GainfoStatus == GainfoStatusEnumType.Leave, (record, ga) => record.UserNo == ga.No)
|
||||||
.LeftJoin<DepartmentEntity>((record, ga, department) => ga.DepartmentNo == department.No)
|
.LeftJoin<DepartmentEntity>((record, ga, department) => ga.DepartmentNo == department.No)
|
||||||
.LeftJoin<BusinessPlaceEntity>((record, ga, department, bPlace) => record.BusinessPlaceCode == bPlace.Code)
|
.LeftJoin<BusinessPlaceEntity>((record, ga, department, bPlace) => record.BusinessPlaceCode == bPlace.Code)
|
||||||
.LeftJoin<CanteenOrderEntity>((record, ga, department, bPlace, order) => record.No == order.No)
|
.LeftJoin<CanteenOrderEntity>((record, ga, department, bPlace, order) => record.No == order.No)
|
||||||
|
|||||||
@@ -36,88 +36,31 @@ public class OrderService : BaseOrderService, IOrderService
|
|||||||
_serviceProvider = serviceProvider;
|
_serviceProvider = serviceProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设备消费
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public async Task<OrderResultResponseWithLogs> DeviceConsume(OrderAddRequest request)
|
public async Task<OrderResultResponseWithLogs> DeviceConsume(OrderAddRequest request)
|
||||||
{
|
{
|
||||||
return await AddAsync(request);
|
return await AddAsync(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设备消费
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public async Task<OrderResultResponseWithLogs> AddAsync(OrderAddRequest request)
|
public async Task<OrderResultResponseWithLogs> AddAsync(OrderAddRequest request)
|
||||||
{
|
{
|
||||||
_sw = new Stopwatch();
|
_sw = new Stopwatch();
|
||||||
|
|
||||||
//尝试匹配userId
|
var gainfo = await GetUserAsync(request);
|
||||||
var s = long.TryParse(request.UserUniqueNo, out var userId);
|
|
||||||
|
|
||||||
//根据档案号
|
|
||||||
var gainfo = await DbContext.Queryable<GainfoEntity>()
|
|
||||||
.WhereIF(request.Source == BalanceRecordSourceEnumType.Card, x => x.CardNo == request.UserUniqueNo)
|
|
||||||
.WhereIF(request.Source != BalanceRecordSourceEnumType.Card && !request.IsUserId, x => x.Code == request.UserUniqueNo)
|
|
||||||
.WhereIF(request.Source != BalanceRecordSourceEnumType.Card && request.IsUserId && s, x => x.Id == userId)
|
|
||||||
.SingleAsync();
|
|
||||||
|
|
||||||
if (gainfo == null && request.IsOffline)
|
|
||||||
{
|
|
||||||
gainfo = await DbContext.Queryable<GainfoEntity>().AS("GainfoLeave")
|
|
||||||
.WhereIF(request.Source == BalanceRecordSourceEnumType.Card, x => x.CardNo == request.UserUniqueNo)
|
|
||||||
.WhereIF(request.Source != BalanceRecordSourceEnumType.Card && !request.IsUserId, x => x.Code == request.UserUniqueNo)
|
|
||||||
.WhereIF(request.Source != BalanceRecordSourceEnumType.Card && request.IsUserId && s, x => x.IdentityUserId == userId)
|
|
||||||
.FirstAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
_logs.Add("获取人员耗时:" + _sw.ElapsedMilliseconds);
|
_logs.Add("获取人员耗时:" + _sw.ElapsedMilliseconds);
|
||||||
_sw.Restart();
|
_sw.Restart();
|
||||||
|
|
||||||
var message = string.Empty;
|
var message = await ToDoAsync(request, gainfo);
|
||||||
|
|
||||||
if (request.IsOffline)
|
|
||||||
{
|
|
||||||
if (request.ThirdNo.IsPresent())
|
|
||||||
{
|
|
||||||
var redisCache = _serviceProvider.GetService<RedisCache>();
|
|
||||||
|
|
||||||
await using var handler = await redisCache.LockAsync($"consume:device:{request.ThirdNo}");
|
|
||||||
if (handler.Acquired)
|
|
||||||
{
|
|
||||||
if (await ToCheckAsync(request.ThirdNo))
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await HandleOfflineAsync(request.Adapt<ConsumeRequest>(), gainfo);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Logger.LogError(ex, "离线入库错误: 订单号:{no} .{message}", request.ThirdNo, ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await HandleOfflineAsync(request.Adapt<ConsumeRequest>(), gainfo);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Logger.LogError(ex, "离线入库错误: 订单号:{no} .{message}", request.ThirdNo, ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
gainfo.ThrowIfNull("无消费权限");
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
(await DbContext.Queryable<GainfoMealEntity>().Where(x => x.UserCode == gainfo.Code).AnyAsync()).ThrowIfFalse("就餐余额不足");
|
|
||||||
await ConsumeAsync(request.Adapt<ConsumeRequest>(), gainfo);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
message = ex.Message;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//获取人员余额
|
//获取人员余额
|
||||||
var data = await DbContext.Queryable<GainfoMealEntity>()
|
var data = await DbContext.Queryable<GainfoMealEntity>()
|
||||||
@@ -151,7 +94,262 @@ public class OrderService : BaseOrderService, IOrderService
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<bool> ToCheckAsync(string thirdNo)
|
|
||||||
|
public async Task<Pagination<OrderAggregationResponse>> GetOrdersAggregationAsync(PageDto page)
|
||||||
|
{
|
||||||
|
var subjectId = CurrentUser.GetIntSubjectId();
|
||||||
|
var gainfo = await DbContext.Queryable<GainfoEntity>().Where(x => x.IdentityUserId == subjectId).FirstAsync();
|
||||||
|
var jinkoCode = CurrentUser.GetUserClaim("jinko-code") ?? string.Empty;
|
||||||
|
if (jinkoCode.IsPresent())
|
||||||
|
{
|
||||||
|
gainfo = await DbContext.Queryable<GainfoEntity>().Where(x => x.Code == jinkoCode).FirstAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
var pageResult = await DbContext.Queryable<CanteenOrderEntity>().Where(x => x.UserNo == gainfo.No)
|
||||||
|
.LeftJoin<BusinessPlaceEntity>((x, bPlace) => x.BusinessPlaceCode == bPlace.Code)
|
||||||
|
.Where(x => x.ApplicationType == CanteenApplicationTypeEnumType.Booking)
|
||||||
|
.OrderBy(x => x.CreateTime, OrderByType.Desc)
|
||||||
|
.Select((x, bPlace) => new OrderAggregationResponse
|
||||||
|
{
|
||||||
|
No = x.No,
|
||||||
|
BusinessPlaceName = bPlace.Name,
|
||||||
|
CreateTime = x.CreateTime,
|
||||||
|
Remark = x.Remark,
|
||||||
|
OrderStatus = x.OrderStatus,
|
||||||
|
})
|
||||||
|
.ToPageListAsync(page);
|
||||||
|
|
||||||
|
var nos = pageResult.Data.Select(x => x.No).ToList();
|
||||||
|
var dtos = await DbContext.Queryable<CanteenOrderDetailEntity>()
|
||||||
|
.LeftJoin<DishesEntity>((x, d) => x.DishesCode == d.CustomCode)
|
||||||
|
.Where(x => nos.Contains(x.OrderNo))
|
||||||
|
.Select((x, d) => new DishesDto
|
||||||
|
{
|
||||||
|
No = x.OrderNo,
|
||||||
|
DishesCode = x.DishesCode,
|
||||||
|
Name = d.Name,
|
||||||
|
ImageUrl = d.ImageUrl,
|
||||||
|
Number = x.Number,
|
||||||
|
Price = x.Price,
|
||||||
|
})
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
|
||||||
|
pageResult.Data.ForEach(item => { item.Dishes = dtos.Where(x => x.No == item.No).ToList(); });
|
||||||
|
|
||||||
|
return pageResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
//******************************************************* help methods ************************************************************/
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取当前消费人员
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private async Task<GainfoEntity> GetUserAsync(OrderAddRequest request)
|
||||||
|
{
|
||||||
|
//尝试匹配userId
|
||||||
|
var s = long.TryParse(request.UserUniqueNo, out var userId);
|
||||||
|
GainfoEntity gainfo = null;
|
||||||
|
|
||||||
|
if (request.Source == BalanceRecordSourceEnumType.QrCode)
|
||||||
|
{
|
||||||
|
if (request.UserUniqueNo.StartsWith("01"))
|
||||||
|
{
|
||||||
|
gainfo = await GetUserByQrCodeAsync(request.UserUniqueNo);
|
||||||
|
}
|
||||||
|
else if (request.UserUniqueNo.StartsWith("02"))
|
||||||
|
{
|
||||||
|
request.Source = BalanceRecordSourceEnumType.EVoucher;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//根据档案号
|
||||||
|
gainfo = await DbContext.Queryable<GainfoEntity>()
|
||||||
|
.WhereIF(request.Source == BalanceRecordSourceEnumType.Card, x => x.CardNo == request.UserUniqueNo)
|
||||||
|
.WhereIF(request.Source != BalanceRecordSourceEnumType.Card && !request.IsUserId, x => x.Code == request.UserUniqueNo)
|
||||||
|
.WhereIF(request.Source != BalanceRecordSourceEnumType.Card && request.IsUserId && s, x => x.Id == userId)
|
||||||
|
.SingleAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//在线
|
||||||
|
if (!request.IsOffline)
|
||||||
|
{
|
||||||
|
gainfo.ThrowIfNull("无法识别,无权消费");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.IsOffline)
|
||||||
|
{
|
||||||
|
//兼容hpt尚未删除人员后产生的消费数据
|
||||||
|
gainfo ??= await DbContext.Queryable<GainfoEntity>().AS("GainfoLeave")
|
||||||
|
.WhereIF(request.Source == BalanceRecordSourceEnumType.Card, x => x.CardNo == request.UserUniqueNo)
|
||||||
|
.WhereIF(request.Source != BalanceRecordSourceEnumType.Card && !request.IsUserId, x => x.Code == request.UserUniqueNo)
|
||||||
|
.WhereIF(request.Source != BalanceRecordSourceEnumType.Card && request.IsUserId && s, x => x.IdentityUserId == userId)
|
||||||
|
.FirstAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
return gainfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取成本日期
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="shift"></param>
|
||||||
|
/// <param name="costDateTime"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private async Task<DateTime> GetCostDateAsync(BusinessShiftMealRelationshipEntity shift, DateTime costDateTime)
|
||||||
|
{
|
||||||
|
var switchTime = await GetSettingAsync<TimeOnly?>(string.Empty, shift.TenantId, CanteenSettingItemEnumType.BusinessSwitchTime);
|
||||||
|
|
||||||
|
var costDate = costDateTime.Date;
|
||||||
|
|
||||||
|
if (!switchTime.HasValue)
|
||||||
|
{
|
||||||
|
return costDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
var beginOfDay = costDateTime.Date;
|
||||||
|
|
||||||
|
var setTime = beginOfDay.Add(switchTime.Value.ToTimeSpan());
|
||||||
|
if (costDateTime < setTime)
|
||||||
|
costDate = costDateTime.Date.AddDays(-1);
|
||||||
|
|
||||||
|
return costDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 验证参数
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="order"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <exception cref="UserFriendlyException"></exception>
|
||||||
|
private async Task Verify(CanteenOrderEntity order)
|
||||||
|
{
|
||||||
|
var beginOfDay = DateTime.Today;
|
||||||
|
var endOfDay = beginOfDay.AddDays(1).AddSeconds(-1);
|
||||||
|
|
||||||
|
//今天所有消费记录
|
||||||
|
var todayAllBalanceRecords = await DbContext.Queryable<BalanceRecordEntity>()
|
||||||
|
.Where(x => x.UserNo == order.UserNo)
|
||||||
|
.Where(x => x.Type == BalanceRecordTypeEnumType.Out)
|
||||||
|
.Where(x => x.Status == BalanceRecordStatusEnumType.Valid)
|
||||||
|
.Where(x => x.CreateTime >= beginOfDay && x.CreateTime <= endOfDay)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
//超市营业点
|
||||||
|
var supermarketCodes = await DbContext.Queryable<BusinessPlaceEntity>()
|
||||||
|
.Where(x => x.Catalog == CanteenBusinessPlaceCatalogEnumType.Supermarket)
|
||||||
|
.Select(x => x.Code)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
//一天消费金额
|
||||||
|
var dayCostMax = await GetSettingAsync<decimal>(order.UserNo, order.TenantId, CanteenSettingItemEnumType.DayCostMax);
|
||||||
|
if (dayCostMax != default)
|
||||||
|
{
|
||||||
|
//消费记录一定会有营业点代码!.Value是安全用法
|
||||||
|
var cost = todayAllBalanceRecords
|
||||||
|
.Where(x => !supermarketCodes.Contains(x.BusinessPlaceCode!.Value)) //filter supermarket
|
||||||
|
.Sum(x => Math.Abs(x.Amount));
|
||||||
|
|
||||||
|
(cost + Math.Abs(order.Amount) > dayCostMax).ThrowIfTrue($"超出当天消费限制{dayCostMax}元,无法消费");
|
||||||
|
}
|
||||||
|
|
||||||
|
//一次消费金额
|
||||||
|
var onceCostMax = await GetSettingAsync<decimal>(order.UserNo, order.TenantId, CanteenSettingItemEnumType.OnceCostMax);
|
||||||
|
if (onceCostMax != default)
|
||||||
|
{
|
||||||
|
(Math.Abs(order.Amount) > onceCostMax).ThrowIfTrue($"单次消费金额不能超出{onceCostMax}元");
|
||||||
|
}
|
||||||
|
|
||||||
|
//超市消费限额
|
||||||
|
if (order.BusinessPlaceCode.HasValue && supermarketCodes.Contains(order.BusinessPlaceCode.Value))
|
||||||
|
{
|
||||||
|
var dayMarketCostMax = await GetSettingAsync<decimal>(order.UserNo, order.TenantId, CanteenSettingItemEnumType.DayMarketCostMax);
|
||||||
|
if (dayMarketCostMax != default)
|
||||||
|
{
|
||||||
|
var cost = todayAllBalanceRecords.Where(x => x.BusinessPlaceCode.HasValue)
|
||||||
|
.Where(x => supermarketCodes.Contains(x.BusinessPlaceCode.Value))
|
||||||
|
.Sum(x => Math.Abs(x.Amount));
|
||||||
|
|
||||||
|
(cost + Math.Abs(order.Amount) > dayMarketCostMax).ThrowIfTrue($"超出当天超市消费限制{dayMarketCostMax},无法消费");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//重复餐次消费
|
||||||
|
var allowRepeatInOneShift = await GetSettingAsync(order.UserNo, order.TenantId, CanteenSettingItemEnumType.AllowRepeatInOneShift, true);
|
||||||
|
if (!allowRepeatInOneShift)
|
||||||
|
{
|
||||||
|
var costCount = todayAllBalanceRecords.Count(x => x.ShiftType == order.ShiftType);
|
||||||
|
(costCount > 1).ThrowIfTrue($"{order.ShiftType?.GetDescription()}不允许多次消费");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 生成充值记录
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="orderId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <exception cref="UserFriendlyException"></exception>
|
||||||
|
/// <exception cref="VersionExceptions"></exception>
|
||||||
|
private async Task GenerateConsumeRecordAsync(long orderId)
|
||||||
|
{
|
||||||
|
var order = await DbContext.Queryable<CanteenOrderEntity>().Where(x => x.Id == orderId).SingleAsync();
|
||||||
|
//校验
|
||||||
|
await Verify(order);
|
||||||
|
_logs.Add("消费请求校验:" + _sw.ElapsedMilliseconds);
|
||||||
|
_sw.Restart();
|
||||||
|
|
||||||
|
|
||||||
|
await CommonHelper.RetryAsync(async () =>
|
||||||
|
{
|
||||||
|
var gainfoMeal = await DbContext.Queryable<GainfoMealEntity>().Where(x => x.UserNo == order.UserNo).SingleAsync();
|
||||||
|
//金额+-
|
||||||
|
gainfoMeal.Balance += order.Amount;
|
||||||
|
(gainfoMeal.Balance < 0).ThrowIfTrue("余额不足,无法消费");
|
||||||
|
|
||||||
|
await DbContext.Updateable<GainfoMealEntity>()
|
||||||
|
.SetColumns(x => x.Balance == gainfoMeal.Balance)
|
||||||
|
.SetColumns(x => x.Version == x.Version + 1)
|
||||||
|
.SetColumns(x => x.ModifiedTime == DateTime.Now)
|
||||||
|
.Where(x => x.UserNo == order.UserNo && x.Version == gainfoMeal.Version) //必须与查询时的version一致
|
||||||
|
.ExecuteCommandThrowVersionAsync();
|
||||||
|
|
||||||
|
//写入记录
|
||||||
|
var balanceRecord = order.Adapt<BalanceRecordEntity>();
|
||||||
|
await DbContext.InsertAsync(balanceRecord);
|
||||||
|
}, 5);
|
||||||
|
|
||||||
|
_logs.Add("消费写入:" + _sw.ElapsedMilliseconds);
|
||||||
|
_sw.Restart();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 根据二维码获取消费用户
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="qrCode"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private async Task<GainfoEntity> GetUserByQrCodeAsync(string qrCode)
|
||||||
|
{
|
||||||
|
var gainfoQrCode = await DbContext.Queryable<GainfoQrCodeEntity>().Where(x => x.QrCode == qrCode).SingleAsync();
|
||||||
|
gainfoQrCode.ThrowIfNull("消费码已过期");
|
||||||
|
(gainfoQrCode.ModifiedTime.AddMinutes(1) > DateTime.Now).ThrowIfTrue("消费码已过期");
|
||||||
|
|
||||||
|
return await DbContext.Queryable<GainfoEntity>().Where(x => x.Code == gainfoQrCode.UserCode).SingleAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 检查是否可以离线消费
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="thirdNo"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private async Task<bool> ToCheckAbleOfflineConsumeAsync(string thirdNo)
|
||||||
{
|
{
|
||||||
var order = await DbContext.Queryable<CanteenOrderEntity>()
|
var order = await DbContext.Queryable<CanteenOrderEntity>()
|
||||||
.Where(x => x.ThirdNo == thirdNo)
|
.Where(x => x.ThirdNo == thirdNo)
|
||||||
@@ -163,15 +361,15 @@ public class OrderService : BaseOrderService, IOrderService
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!order.IsOffline && order.OrderStatus != CanteenOrderStatusEnumType.Success)
|
//存在在线order数据,但是状态未成功
|
||||||
{
|
return !order.IsOffline && order.OrderStatus != CanteenOrderStatusEnumType.Success;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 离线消费处理
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <param name="gainfo"></param>
|
||||||
private async Task HandleOfflineAsync(ConsumeRequest request, GainfoEntity gainfo)
|
private async Task HandleOfflineAsync(ConsumeRequest request, GainfoEntity gainfo)
|
||||||
{
|
{
|
||||||
var registry = await DbContext.Queryable<DeviceRegistryEntity>()
|
var registry = await DbContext.Queryable<DeviceRegistryEntity>()
|
||||||
@@ -240,34 +438,26 @@ public class OrderService : BaseOrderService, IOrderService
|
|||||||
|
|
||||||
await DbContext.InsertReturnIdentityAsync(order);
|
await DbContext.InsertReturnIdentityAsync(order);
|
||||||
|
|
||||||
var allowNoBalance = await GetSettingAsync<bool>(gainfo.No, businessPlaceInfo.TenantId, CanteenSettingItemEnumType.AllowNoBalance);
|
|
||||||
|
|
||||||
await CommonHelper.RetryAsync(async () =>
|
await CommonHelper.RetryAsync(async () =>
|
||||||
{
|
{
|
||||||
if (!allowNoBalance)
|
var redisCache = _serviceProvider.GetService<RedisCache>();
|
||||||
|
await using var handler = await redisCache.LockAsync($"gainfo:meal:{order.UserNo}", retryInterval: TimeSpan.FromSeconds(1));
|
||||||
|
if (handler.Acquired)
|
||||||
{
|
{
|
||||||
GainfoMealEntity gainfoMeal = null;
|
var gainfoMeal = await DbContext.Queryable<GainfoMealEntity>().Where(x => x.UserNo == order.UserNo).FirstAsync();
|
||||||
var redisCache = _serviceProvider.GetService<RedisCache>();
|
if (gainfoMeal == null)
|
||||||
using (var handler = await redisCache.LockAsync($"gainfo:meal:{order.UserNo}", retryInterval: TimeSpan.FromSeconds(1)))
|
|
||||||
{
|
{
|
||||||
if (handler.Acquired)
|
gainfoMeal = new GainfoMealEntity
|
||||||
{
|
{
|
||||||
gainfoMeal = await DbContext.Queryable<GainfoMealEntity>().Where(x => x.UserNo == order.UserNo).FirstAsync();
|
Balance = 0,
|
||||||
if (gainfoMeal == null)
|
BalanceOfRecharge = 0,
|
||||||
{
|
BalanceOfSubsidies = 0,
|
||||||
gainfoMeal = new GainfoMealEntity
|
Version = 0,
|
||||||
{
|
UserNo = order.UserNo,
|
||||||
Balance = 0,
|
UserCode = order.UserCode,
|
||||||
BalanceOfRecharge = 0,
|
};
|
||||||
BalanceOfSubsidies = 0,
|
|
||||||
Version = 0,
|
|
||||||
UserNo = order.UserNo,
|
|
||||||
UserCode = order.UserCode,
|
|
||||||
};
|
|
||||||
|
|
||||||
await DbContext.InsertAsync(gainfoMeal);
|
await DbContext.InsertAsync(gainfoMeal);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//金额+-
|
//金额+-
|
||||||
@@ -279,11 +469,11 @@ public class OrderService : BaseOrderService, IOrderService
|
|||||||
.SetColumns(x => x.ModifiedTime == DateTime.Now)
|
.SetColumns(x => x.ModifiedTime == DateTime.Now)
|
||||||
.Where(x => x.UserNo == order.UserNo && x.Version == gainfoMeal.Version) //必须与查询时的version一致
|
.Where(x => x.UserNo == order.UserNo && x.Version == gainfoMeal.Version) //必须与查询时的version一致
|
||||||
.ExecuteCommandThrowVersionAsync();
|
.ExecuteCommandThrowVersionAsync();
|
||||||
}
|
|
||||||
|
|
||||||
//写入记录
|
//写入记录
|
||||||
var balanceRecord = order.Adapt<BalanceRecordEntity>();
|
var balanceRecord = order.Adapt<BalanceRecordEntity>();
|
||||||
await DbContext.InsertAsync(balanceRecord);
|
await DbContext.InsertAsync(balanceRecord);
|
||||||
|
}
|
||||||
}, 5);
|
}, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -409,196 +599,63 @@ public class OrderService : BaseOrderService, IOrderService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Pagination<OrderAggregationResponse>> GetOrdersAggregationAsync(PageDto page)
|
|
||||||
{
|
|
||||||
var subjectId = CurrentUser.GetIntSubjectId();
|
|
||||||
var gainfo = await DbContext.Queryable<GainfoEntity>().Where(x => x.IdentityUserId == subjectId).FirstAsync();
|
|
||||||
var jinkoCode = CurrentUser.GetUserClaim("jinko-code") ?? string.Empty;
|
|
||||||
if (jinkoCode.IsPresent())
|
|
||||||
{
|
|
||||||
gainfo = await DbContext.Queryable<GainfoEntity>().Where(x => x.Code == jinkoCode).FirstAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
var pageResult = await DbContext.Queryable<CanteenOrderEntity>().Where(x => x.UserNo == gainfo.No)
|
|
||||||
.LeftJoin<BusinessPlaceEntity>((x, bPlace) => x.BusinessPlaceCode == bPlace.Code)
|
|
||||||
.Where(x => x.ApplicationType == CanteenApplicationTypeEnumType.Booking)
|
|
||||||
.OrderBy(x => x.CreateTime, OrderByType.Desc)
|
|
||||||
.Select((x, bPlace) => new OrderAggregationResponse
|
|
||||||
{
|
|
||||||
No = x.No,
|
|
||||||
BusinessPlaceName = bPlace.Name,
|
|
||||||
CreateTime = x.CreateTime,
|
|
||||||
Remark = x.Remark,
|
|
||||||
OrderStatus = x.OrderStatus,
|
|
||||||
})
|
|
||||||
.ToPageListAsync(page);
|
|
||||||
|
|
||||||
var nos = pageResult.Data.Select(x => x.No).ToList();
|
|
||||||
var dtos = await DbContext.Queryable<CanteenOrderDetailEntity>()
|
|
||||||
.LeftJoin<DishesEntity>((x, d) => x.DishesCode == d.CustomCode)
|
|
||||||
.Where(x => nos.Contains(x.OrderNo))
|
|
||||||
.Select((x, d) => new DishesDto
|
|
||||||
{
|
|
||||||
No = x.OrderNo,
|
|
||||||
DishesCode = x.DishesCode,
|
|
||||||
Name = d.Name,
|
|
||||||
ImageUrl = d.ImageUrl,
|
|
||||||
Number = x.Number,
|
|
||||||
Price = x.Price,
|
|
||||||
})
|
|
||||||
.ToListAsync();
|
|
||||||
|
|
||||||
|
|
||||||
pageResult.Data.ForEach(item => { item.Dishes = dtos.Where(x => x.No == item.No).ToList(); });
|
|
||||||
|
|
||||||
return pageResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
//******************************************************* help methods ************************************************************/
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取成本日期
|
/// 分支处理在线/离线消费
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="shift"></param>
|
/// <param name="request"></param>
|
||||||
/// <param name="costDateTime"></param>
|
/// <param name="gainfo"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private async Task<DateTime> GetCostDateAsync(BusinessShiftMealRelationshipEntity shift, DateTime costDateTime)
|
private async Task<string> ToDoAsync(OrderAddRequest request, GainfoEntity gainfo)
|
||||||
{
|
{
|
||||||
var switchTime = await GetSettingAsync<TimeOnly?>(string.Empty, shift.TenantId, CanteenSettingItemEnumType.BusinessSwitchTime);
|
var message = "消费成功";
|
||||||
|
if (request.IsOffline)
|
||||||
var costDate = costDateTime.Date;
|
|
||||||
|
|
||||||
if (switchTime.HasValue)
|
|
||||||
{
|
{
|
||||||
var beginOfDay = costDateTime.Date;
|
if (request.ThirdNo.IsPresent())
|
||||||
|
|
||||||
var setTime = beginOfDay.Add(switchTime.Value.ToTimeSpan());
|
|
||||||
if (costDateTime < setTime)
|
|
||||||
costDate = costDateTime.Date.AddDays(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return costDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 验证参数
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="order"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
/// <exception cref="UserFriendlyException"></exception>
|
|
||||||
private async Task Verify(CanteenOrderEntity order)
|
|
||||||
{
|
|
||||||
var beginOfDay = DateTime.Today;
|
|
||||||
var endOfDay = beginOfDay.AddDays(1).AddSeconds(-1);
|
|
||||||
|
|
||||||
//今天所有消费记录
|
|
||||||
var todayAllBalanceRecords = await DbContext.Queryable<BalanceRecordEntity>()
|
|
||||||
.Where(x => x.UserNo == order.UserNo)
|
|
||||||
.Where(x => x.Type == BalanceRecordTypeEnumType.Out)
|
|
||||||
.Where(x => x.Status == BalanceRecordStatusEnumType.Valid)
|
|
||||||
.Where(x => x.CreateTime >= beginOfDay && x.CreateTime <= endOfDay)
|
|
||||||
.ToListAsync();
|
|
||||||
|
|
||||||
//超市营业点
|
|
||||||
var supermarketCodes = await DbContext.Queryable<BusinessPlaceEntity>()
|
|
||||||
.Where(x => x.Catalog == CanteenBusinessPlaceCatalogEnumType.Supermarket)
|
|
||||||
.Select(x => x.Code)
|
|
||||||
.ToListAsync();
|
|
||||||
|
|
||||||
//一天消费金额
|
|
||||||
var dayCostMax = await GetSettingAsync<decimal>(order.UserNo, order.TenantId, CanteenSettingItemEnumType.DayCostMax);
|
|
||||||
if (dayCostMax != default)
|
|
||||||
{
|
|
||||||
//must has business place code, use .Value is safe
|
|
||||||
var cost = todayAllBalanceRecords
|
|
||||||
.Where(x => !supermarketCodes.Contains(x.BusinessPlaceCode.Value)) //filter supermarket
|
|
||||||
.Sum(x => Math.Abs(x.Amount));
|
|
||||||
(cost + Math.Abs(order.Amount) > dayCostMax).ThrowIfTrue($"超出当天消费限制{dayCostMax}元,无法消费");
|
|
||||||
}
|
|
||||||
|
|
||||||
//一次消费金额
|
|
||||||
var onceCostMax = await GetSettingAsync<decimal>(order.UserNo, order.TenantId, CanteenSettingItemEnumType.OnceCostMax);
|
|
||||||
if (onceCostMax != default)
|
|
||||||
{
|
|
||||||
(Math.Abs(order.Amount) > onceCostMax).ThrowIfTrue($"单次消费金额不能超出{onceCostMax}元");
|
|
||||||
}
|
|
||||||
|
|
||||||
//超市消费限额
|
|
||||||
var dayMarketCostMax = await GetSettingAsync<decimal>(order.UserNo, order.TenantId, CanteenSettingItemEnumType.DayMarketCostMax);
|
|
||||||
if (dayMarketCostMax != default)
|
|
||||||
{
|
|
||||||
//current businessplace is supermarket
|
|
||||||
if (order.BusinessPlaceCode.HasValue && supermarketCodes.Contains(order.BusinessPlaceCode.Value))
|
|
||||||
{
|
{
|
||||||
var cost = todayAllBalanceRecords.Where(x => x.BusinessPlaceCode.HasValue)
|
var redisCache = _serviceProvider.GetService<RedisCache>();
|
||||||
.Where(x => supermarketCodes.Contains(x.BusinessPlaceCode.Value))
|
|
||||||
.Sum(x => Math.Abs(x.Amount));
|
|
||||||
|
|
||||||
(cost + Math.Abs(order.Amount) > dayMarketCostMax).ThrowIfTrue($"超出当天超市消费限制{dayMarketCostMax},无法消费");
|
await using var handler = await redisCache.LockAsync($"consume:device:{request.ThirdNo}");
|
||||||
|
if (handler.Acquired)
|
||||||
|
{
|
||||||
|
if (await ToCheckAbleOfflineConsumeAsync(request.ThirdNo))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await HandleOfflineAsync(request.Adapt<ConsumeRequest>(), gainfo);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.LogError(ex, "离线入库错误: 订单号:{no} .{message}", request.ThirdNo, ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await HandleOfflineAsync(request.Adapt<ConsumeRequest>(), gainfo);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.LogError(ex, "离线入库错误: 订单号:{no} .{message}", request.ThirdNo, ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
(await DbContext.Queryable<GainfoMealEntity>().Where(x => x.UserCode == gainfo.Code).AnyAsync()).ThrowIfFalse("就餐余额不足");
|
||||||
|
await ConsumeAsync(request.Adapt<ConsumeRequest>(), gainfo);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
message = ex.Message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//重复餐次消费
|
return message;
|
||||||
var allowRepeatInOneShift = await GetSettingAsync(order.UserNo, order.TenantId, CanteenSettingItemEnumType.AllowRepeatInOneShift, true);
|
|
||||||
if (!allowRepeatInOneShift)
|
|
||||||
{
|
|
||||||
var costCount = todayAllBalanceRecords.Count(x => x.ShiftType == order.ShiftType);
|
|
||||||
(costCount > 1).ThrowIfTrue($"{order.ShiftType?.GetDescription()}不允许多次消费");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 生成充值记录
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="orderId"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
/// <exception cref="UserFriendlyException"></exception>
|
|
||||||
/// <exception cref="VersionExceptions"></exception>
|
|
||||||
private async Task GenerateConsumeRecordAsync(long orderId)
|
|
||||||
{
|
|
||||||
var order = await DbContext.Queryable<CanteenOrderEntity>().Where(x => x.Id == orderId).SingleAsync();
|
|
||||||
//校验
|
|
||||||
await Verify(order);
|
|
||||||
_logs.Add("消费请求校验:" + _sw.ElapsedMilliseconds);
|
|
||||||
_sw.Restart();
|
|
||||||
|
|
||||||
|
|
||||||
await CommonHelper.RetryAsync(async () =>
|
|
||||||
{
|
|
||||||
var gainfoMeal = await DbContext.Queryable<GainfoMealEntity>().Where(x => x.UserNo == order.UserNo).SingleAsync();
|
|
||||||
//金额+-
|
|
||||||
gainfoMeal.Balance += order.Amount;
|
|
||||||
(gainfoMeal.Balance < 0).ThrowIfTrue("余额不足,无法消费");
|
|
||||||
|
|
||||||
await DbContext.Updateable<GainfoMealEntity>()
|
|
||||||
.SetColumns(x => x.Balance == gainfoMeal.Balance)
|
|
||||||
.SetColumns(x => x.Version == x.Version + 1)
|
|
||||||
.SetColumns(x => x.ModifiedTime == DateTime.Now)
|
|
||||||
.Where(x => x.UserNo == order.UserNo && x.Version == gainfoMeal.Version) //必须与查询时的version一致
|
|
||||||
.ExecuteCommandThrowVersionAsync();
|
|
||||||
|
|
||||||
//写入记录
|
|
||||||
var balanceRecord = order.Adapt<BalanceRecordEntity>();
|
|
||||||
await DbContext.InsertAsync(balanceRecord);
|
|
||||||
}, 5);
|
|
||||||
|
|
||||||
_logs.Add("消费写入:" + _sw.ElapsedMilliseconds);
|
|
||||||
_sw.Restart();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 根据二维码获取消费用户
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="qrCode"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
private async Task<string> GetUserNoByQrCodeAsync(string qrCode)
|
|
||||||
{
|
|
||||||
var gainfoQrCode = await DbContext.Queryable<GainfoQrCodeEntity>().Where(x => x.QrCode == qrCode).SingleAsync();
|
|
||||||
gainfoQrCode.ThrowIfNull("消费码已过期");
|
|
||||||
(gainfoQrCode.ModifiedTime.AddMinutes(1) > DateTime.Now).ThrowIfTrue("消费码已过期");
|
|
||||||
|
|
||||||
return gainfoQrCode.UserCode;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -36,12 +36,6 @@ public class GainfoEntity : SugarBaseEntity
|
|||||||
[SugarColumn(ColumnDescription = "姓名")]
|
[SugarColumn(ColumnDescription = "姓名")]
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 外文名字
|
|
||||||
/// </summary>
|
|
||||||
[SugarColumn(ColumnDescription = "外文名字")]
|
|
||||||
public string NameEn { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 学工号
|
/// 学工号
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
using Kurisu.AspNetCore.DataAccess.Entity;
|
|
||||||
using Kurisu.AspNetCore.DataAccess.SqlSugar;
|
|
||||||
using SqlSugar;
|
|
||||||
|
|
||||||
namespace Dlhis.Entity.Basic.Entity;
|
|
||||||
|
|
||||||
[SugarTable(TableName = "OutsourceSetting", TableDescription = "外包人员配置")]
|
|
||||||
public class OutsourceSettingEntity : SugarBaseEntity, ITenantId
|
|
||||||
{
|
|
||||||
[SugarColumn(ColumnDataType = "bit")]
|
|
||||||
public bool EnableFactory { get; set; }
|
|
||||||
|
|
||||||
public string TenantId { get; set; }
|
|
||||||
}
|
|
||||||
32
Src/Dlhis.Entity/Sys/Entities/FactorySettingEntity.cs
Normal file
32
Src/Dlhis.Entity/Sys/Entities/FactorySettingEntity.cs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
using Kurisu.AspNetCore.DataAccess.Entity;
|
||||||
|
using Kurisu.AspNetCore.DataAccess.SqlSugar;
|
||||||
|
using SqlSugar;
|
||||||
|
|
||||||
|
namespace Dlhis.Entity.Sys.Entities;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 厂区配置
|
||||||
|
/// </summary>
|
||||||
|
[SugarTable(TableName = "FactorySetting", TableDescription = "厂区配置")]
|
||||||
|
public class FactorySettingEntity : SugarBaseEntity, ITenantId
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 是否启用外包自动下发
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(ColumnDataType = "bit", ColumnDescription = "是否启用外包自动下发")]
|
||||||
|
public bool EnableOutsourceDown { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 档案二维码过期时间
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(ColumnDescription = "档案二维码过期时间")]
|
||||||
|
public int UserQrCodeExpiration { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 电子餐券二维码过期时间
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(ColumnDescription = "电子餐券二维码过期时间")]
|
||||||
|
public int EMealVoucherQrCodeExpiration { get; set; }
|
||||||
|
|
||||||
|
public string TenantId { get; set; }
|
||||||
|
}
|
||||||
@@ -15,9 +15,9 @@ public interface IJinkoJIPService : ISingletonDependency
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="begin"></param>
|
/// <param name="begin"></param>
|
||||||
/// <param name="end"></param>
|
/// <param name="end"></param>
|
||||||
/// <param name="departmentNos"></param>
|
/// <param name="fatory"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<SapBusinessTripInfoResponse> GetTravelInfosByDepartmentsAsync(DateTime begin, DateTime end, List<string> departmentNos);
|
Task<SapBusinessTripInfoResponse> GetTravelInfosByFactoryAsync(DateTime begin, DateTime end, string fatory);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取出差信息
|
/// 获取出差信息
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Dlhis.ScheduledTask.Common.Services;
|
||||||
|
|
||||||
|
public interface ISapBusinessTripService : IScopeDependency
|
||||||
|
{
|
||||||
|
Task HandlerBusinessTripsByFactoryAsync(string factory);
|
||||||
|
}
|
||||||
@@ -95,25 +95,26 @@ public class JinkoJIPService : IJinkoJIPService
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task<SapBusinessTripInfoResponse> GetTravelInfosByDepartmentsAsync(DateTime begin, DateTime end, List<string> departmentNos)
|
public async Task<SapBusinessTripInfoResponse> GetTravelInfosByFactoryAsync(DateTime begin, DateTime end, string factory)
|
||||||
{
|
{
|
||||||
const string apiUrl = "/JIP/HCM/HCM_TRAVELINFO";
|
const string apiUrl = "/JIP/HCM/HCM_TRAVELINFO";
|
||||||
|
|
||||||
var beginDay = begin.ToString("yyyyMMdd");
|
var beginDay = begin.ToString("yyyyMMdd");
|
||||||
var endDay = end.ToString("yyyyMMdd");
|
var endDay = end.ToString("yyyyMMdd");
|
||||||
|
|
||||||
var d = departmentNos.Select(x => new
|
|
||||||
{
|
|
||||||
IV_ORGID = x
|
|
||||||
});
|
|
||||||
|
|
||||||
//IV_GONGH IV_ORGID
|
|
||||||
//IT_2002GH
|
|
||||||
var obj = new
|
var obj = new
|
||||||
{
|
{
|
||||||
|
I_PAGE = 1,
|
||||||
|
I_LINE = 500,
|
||||||
IV_BEGDA = beginDay,
|
IV_BEGDA = beginDay,
|
||||||
IV_ENDDA = endDay,
|
IV_ENDDA = endDay,
|
||||||
IT_2002OR = d
|
IT_CCMDD = new List<object>
|
||||||
|
{
|
||||||
|
new
|
||||||
|
{
|
||||||
|
IV_CCMDD = factory
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var body = obj.ToJson();
|
var body = obj.ToJson();
|
||||||
|
|||||||
@@ -0,0 +1,149 @@
|
|||||||
|
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 lastDay = today.AddDays(-1);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var tripResponse = await _jinkoJipService.GetTravelInfosByFactoryAsync(today, today, factory);
|
||||||
|
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).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, lastDay) && SqlFunc.DateIsSame(x.BeginDate, lastDay)))
|
||||||
|
.Where(x => !SqlFunc.IsNullOrEmpty(x.Destination))
|
||||||
|
.Where(x => x.Status == BusinessTripStatusEnumType.Wait)
|
||||||
|
.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)
|
||||||
|
{
|
||||||
|
var myTripInfos = tripInfos.Where(x => x.Code == gainfo.Code).ToList();
|
||||||
|
|
||||||
|
var todayTripInfo = myTripInfos.FirstOrDefault(x => x.BeginDate == today && x.EndDate == today);
|
||||||
|
var lastDayTripInfo = myTripInfos.FirstOrDefault(x => x.BeginDate == lastDay && x.EndDate == lastDay);
|
||||||
|
|
||||||
|
bool isGenerateOrDeleted = false;
|
||||||
|
|
||||||
|
if (lastDayTripInfo == null && todayTripInfo != null)
|
||||||
|
{
|
||||||
|
isGenerateOrDeleted = true;
|
||||||
|
todayTripInfo.Status = BusinessTripStatusEnumType.Generated;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lastDayTripInfo != null && todayTripInfo == null)
|
||||||
|
{
|
||||||
|
lastDayTripInfo.Status = BusinessTripStatusEnumType.Deleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lastDayTripInfo != null && todayTripInfo != null)
|
||||||
|
{
|
||||||
|
todayTripInfo.Status = BusinessTripStatusEnumType.Generated;
|
||||||
|
await _dbContext.UpdateAsync(todayTripInfo);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var beforeResult = await _devicePermissionApi.GetPermissionUsersInfoAsync(new List<string> { gainfo.Code });
|
||||||
|
|
||||||
|
if (isGenerateOrDeleted)
|
||||||
|
{
|
||||||
|
await _dbContext.InsertAsync(new DevicePermissionEntity
|
||||||
|
{
|
||||||
|
AssignType = AssignTypeEnumType.User,
|
||||||
|
AssignValue = gainfo.No,
|
||||||
|
UniqueType = DeviceAssignmentTypeEnumType.Group,
|
||||||
|
UniqueValue = tripGroup.Code,
|
||||||
|
TenantId = factory,
|
||||||
|
Type = tripGroup.Type,
|
||||||
|
IsDeleted = false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
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 _devicePermissionApi.RePermissionUsersInfoAsync(beforeResult.Data);
|
||||||
|
|
||||||
|
if (lastDayTripInfo != null)
|
||||||
|
await _dbContext.UpdateAsync(lastDayTripInfo);
|
||||||
|
|
||||||
|
if (todayTripInfo != null)
|
||||||
|
await _dbContext.UpdateAsync(todayTripInfo);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.LogError(e, "出差自动下发任务失败:{message}", e.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.LogError(e, "处理{factory}出差数据失败:{message}", factory, e.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,15 +1,6 @@
|
|||||||
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.Entities;
|
||||||
using Dlhis.Entity.Sys.Enums;
|
|
||||||
using Dlhis.Entity.Visitor.Entity;
|
|
||||||
using Dlhis.Entity.Visitor.Enums;
|
|
||||||
using Dlhis.ScheduledTask.Attributes;
|
using Dlhis.ScheduledTask.Attributes;
|
||||||
using Dlhis.ScheduledTask.Common.Services;
|
using Dlhis.ScheduledTask.Common.Services;
|
||||||
using Kurisu.AspNetCore.Utils.Extensions;
|
|
||||||
using Mapster;
|
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
|
|
||||||
namespace Dlhis.ScheduledTask.Jobs;
|
namespace Dlhis.ScheduledTask.Jobs;
|
||||||
@@ -17,163 +8,23 @@ namespace Dlhis.ScheduledTask.Jobs;
|
|||||||
[RecurringJob(nameof(SyncBusinessTripJob), "0 0 1 1/1 * ? ", Name = "SAP同步出差信息")]
|
[RecurringJob(nameof(SyncBusinessTripJob), "0 0 1 1/1 * ? ", Name = "SAP同步出差信息")]
|
||||||
public class SyncBusinessTripJob : BaseJob
|
public class SyncBusinessTripJob : BaseJob
|
||||||
{
|
{
|
||||||
private readonly IDevicePermissionApi _devicePermissionApi;
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public SyncBusinessTripJob(IServiceProvider serviceProvider, IDevicePermissionApi devicePermissionApi) : base(serviceProvider)
|
public SyncBusinessTripJob(IServiceProvider serviceProvider) : base(serviceProvider)
|
||||||
{
|
{
|
||||||
_devicePermissionApi = devicePermissionApi;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override async Task RunAsync(IServiceProvider serviceProvider)
|
protected override async Task RunAsync(IServiceProvider serviceProvider)
|
||||||
{
|
{
|
||||||
var jipService = serviceProvider.GetService<IJinkoJIPService>();
|
var sapBusinessTripService = serviceProvider.GetService<ISapBusinessTripService>();
|
||||||
var today = DateTime.Today;
|
|
||||||
var lastDay = today.AddDays(-1);
|
|
||||||
|
|
||||||
var departments = await DbContext.Queryable<DepartmentEntity>().ToListAsync();
|
var identityDbContext = DbContext.ChangeDb("identity");
|
||||||
var tops = departments.Where(x => x.PNo == "00001000").ToList();
|
var factories = await identityDbContext.Queryable<TenantEntity>().Where(x => !SqlFunc.IsNullOrEmpty(x.PCode)).ToListAsync();
|
||||||
var validDepartments = tops.ToList();
|
|
||||||
tops.ForEach(x => RecursionGetNext(x, departments, validDepartments));
|
|
||||||
|
|
||||||
foreach (var departmentNos in validDepartments.Select(x => x.No).Chunk(5))
|
foreach (var factory in factories)
|
||||||
{
|
{
|
||||||
try
|
await sapBusinessTripService.HandlerBusinessTripsByFactoryAsync(factory.Code);
|
||||||
{
|
|
||||||
var tripResponse = await jipService.GetTravelInfosByDepartmentsAsync(today, today, departmentNos.ToList());
|
|
||||||
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).AnyAsync())
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var entity = tripInfoItem.Adapt<BusinessTripEntity>();
|
|
||||||
entity.Status = BusinessTripStatusEnumType.Wait;
|
|
||||||
await DbContext.InsertAsync(entity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Logger.LogError(e, "获取部门出差数据执行失败:{message}", e.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//获取今天和昨天的出差数据
|
|
||||||
var tripInfos = await DbContext.Queryable<BusinessTripEntity>()
|
|
||||||
.Where(x => (SqlFunc.DateIsSame(x.BeginDate, today) && SqlFunc.DateIsSame(x.BeginDate, today))
|
|
||||||
|| (SqlFunc.DateIsSame(x.BeginDate, lastDay) && SqlFunc.DateIsSame(x.BeginDate, lastDay)))
|
|
||||||
.Where(x => !SqlFunc.IsNullOrEmpty(x.Destination))
|
|
||||||
.Where(x => x.Status == BusinessTripStatusEnumType.Wait)
|
|
||||||
.ToListAsync();
|
|
||||||
|
|
||||||
var factoryIds = tripInfos.Select(x => x.Destination).Distinct().ToList();
|
|
||||||
var tripGroups = await DbContext.Queryable<DeviceGroupEntity>()
|
|
||||||
.Where(x => x.Type == DeviceTypeEnumType.Door)
|
|
||||||
.Where(x => factoryIds.Contains(x.TenantId)).Where(x => x.IsBusinessTrip)
|
|
||||||
.ToListAsync();
|
|
||||||
|
|
||||||
var userCodes = tripInfos.Select(x => x.Code).Distinct().ToList();
|
|
||||||
var gainfos = await DbContext.Queryable<GainfoEntity>().Where(x => userCodes.Contains(x.Code)).ToListAsync();
|
|
||||||
|
|
||||||
foreach (var code in userCodes)
|
|
||||||
{
|
|
||||||
var gainfo = gainfos.FirstOrDefault(x => x.Code == code);
|
|
||||||
if (gainfo == null)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var factoryTripInfos in tripInfos.Where(x => x.Code == code).GroupBy(x => x.Destination))
|
|
||||||
{
|
|
||||||
var tripGroup = tripGroups.FirstOrDefault(x => x.TenantId == factoryTripInfos.Key);
|
|
||||||
if (tripGroup == null)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var todayTripInfo = factoryTripInfos.FirstOrDefault(x => x.BeginDate == today && x.EndDate == today);
|
|
||||||
var lastDayTripInfo = factoryTripInfos.FirstOrDefault(x => x.BeginDate == lastDay && x.EndDate == lastDay);
|
|
||||||
|
|
||||||
bool isGenerateOrDeleted = false;
|
|
||||||
|
|
||||||
if (lastDayTripInfo == null && todayTripInfo != null)
|
|
||||||
{
|
|
||||||
isGenerateOrDeleted = true;
|
|
||||||
todayTripInfo.Status = BusinessTripStatusEnumType.Generated;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lastDayTripInfo != null && todayTripInfo == null)
|
|
||||||
{
|
|
||||||
lastDayTripInfo.Status = BusinessTripStatusEnumType.Deleted;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lastDayTripInfo != null && todayTripInfo != null)
|
|
||||||
{
|
|
||||||
todayTripInfo.Status = BusinessTripStatusEnumType.Generated;
|
|
||||||
await DbContext.UpdateAsync(todayTripInfo);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var beforeResult = await _devicePermissionApi.GetPermissionUsersInfoAsync(new List<string> { code });
|
|
||||||
|
|
||||||
if (isGenerateOrDeleted)
|
|
||||||
{
|
|
||||||
await DbContext.InsertAsync(new DevicePermissionEntity
|
|
||||||
{
|
|
||||||
AssignType = AssignTypeEnumType.User,
|
|
||||||
AssignValue = gainfo.No,
|
|
||||||
UniqueType = DeviceAssignmentTypeEnumType.Group,
|
|
||||||
UniqueValue = tripGroup.Code,
|
|
||||||
TenantId = factoryTripInfos.Key,
|
|
||||||
Type = tripGroup.Type,
|
|
||||||
IsDeleted = false
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
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 == factoryTripInfos.Key)
|
|
||||||
.ExecuteCommandAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
await _devicePermissionApi.RePermissionUsersInfoAsync(beforeResult.Data);
|
|
||||||
|
|
||||||
if (lastDayTripInfo != null)
|
|
||||||
await DbContext.UpdateAsync(lastDayTripInfo);
|
|
||||||
|
|
||||||
if (todayTripInfo != null)
|
|
||||||
await DbContext.UpdateAsync(todayTripInfo);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Logger.LogError(e, "出差自动下发任务失败:{message}", e.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//************************************************************************************************************************************************
|
|
||||||
|
|
||||||
private static void RecursionGetNext(DepartmentEntity current, List<DepartmentEntity> data, List<DepartmentEntity> result)
|
|
||||||
{
|
|
||||||
var next = data.Where(x => x.PNo == current.No).ToList();
|
|
||||||
foreach (var item in next)
|
|
||||||
{
|
|
||||||
result.Add(item);
|
|
||||||
RecursionGetNext(item, data, result);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,6 @@ public class Startup : DefaultStartup
|
|||||||
{
|
{
|
||||||
base.Configure(app, env);
|
base.Configure(app, env);
|
||||||
|
|
||||||
|
|
||||||
var token = app.ApplicationServices.GetService<IJinkoJIPService>().IssueToken();
|
var token = app.ApplicationServices.GetService<IJinkoJIPService>().IssueToken();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
using Dlhis.Entity.Device.Entities;
|
||||||
|
|
||||||
|
namespace Dlhis.ScheduledTask.TaskAssignment.Dto;
|
||||||
|
|
||||||
|
public class DeviceTimePeriodDto : DeviceTimePeriodEntity
|
||||||
|
{
|
||||||
|
public string CardName { get; set; }
|
||||||
|
}
|
||||||
@@ -36,5 +36,5 @@ public class TaskDto
|
|||||||
|
|
||||||
public DeviceTaskStatusEnumType Status { get; set; }
|
public DeviceTaskStatusEnumType Status { get; set; }
|
||||||
|
|
||||||
public List<DeviceTimePeriodEntity> TimePeriods { get; set; }
|
public List<DeviceTimePeriodDto> TimePeriods { get; set; }
|
||||||
}
|
}
|
||||||
@@ -14,7 +14,6 @@ using Dlhis.ScheduledTask.TaskAssignment.Dto;
|
|||||||
using Kurisu.AspNetCore.CustomClass;
|
using Kurisu.AspNetCore.CustomClass;
|
||||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
|
using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
|
||||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||||
using Mapster;
|
|
||||||
|
|
||||||
namespace Dlhis.ScheduledTask.TaskAssignment.Services.Implements;
|
namespace Dlhis.ScheduledTask.TaskAssignment.Services.Implements;
|
||||||
|
|
||||||
@@ -112,8 +111,8 @@ public class AssignmentService : IAssignmentService
|
|||||||
dto.Info = item.TimePeriods.Select(t => new TimePeriodToDeviceResponse
|
dto.Info = item.TimePeriods.Select(t => new TimePeriodToDeviceResponse
|
||||||
{
|
{
|
||||||
Id = t.CardType,
|
Id = t.CardType,
|
||||||
Name = t.CardType == 2 ? "行政卡" : "车间卡",
|
Name = t.CardName,
|
||||||
Enable = true,
|
Enable = item.EnableTimePeriod,
|
||||||
Sections = t.Sections.Select(s => new TimePeriodWeekDaySection
|
Sections = t.Sections.Select(s => new TimePeriodWeekDaySection
|
||||||
{
|
{
|
||||||
DayOfWeek = s.DayOfWeek,
|
DayOfWeek = s.DayOfWeek,
|
||||||
@@ -121,7 +120,7 @@ public class AssignmentService : IAssignmentService
|
|||||||
{
|
{
|
||||||
Enable = p.Enable,
|
Enable = p.Enable,
|
||||||
Start = p.Enable ? p.Start : new TimeOnly(00, 00, 00),
|
Start = p.Enable ? p.Start : new TimeOnly(00, 00, 00),
|
||||||
End = p.Enable ? p.End : new TimeOnly(00, 00, 00),
|
End = p.Enable ? p.End : new TimeOnly(00, 00, 00)
|
||||||
}).ToList()
|
}).ToList()
|
||||||
}).ToList()
|
}).ToList()
|
||||||
});
|
});
|
||||||
@@ -387,8 +386,13 @@ public class AssignmentService : IAssignmentService
|
|||||||
var templateCodes = devices.Select(x => x.TemplateCode).Distinct().ToList();
|
var templateCodes = devices.Select(x => x.TemplateCode).Distinct().ToList();
|
||||||
var deviceCodes = devices.Select(x => x.Code).Distinct().ToList();
|
var deviceCodes = devices.Select(x => x.Code).Distinct().ToList();
|
||||||
var settings = await _dbContext.Queryable<DeviceTimePeriodEntity>()
|
var settings = await _dbContext.Queryable<DeviceTimePeriodEntity>()
|
||||||
|
.LeftJoin<BasicTypeEntity>((x, type) => x.CardType.ToString() == type.Code && type.Type == "timeperiod")
|
||||||
.Where(x => (x.AssignType == DeviceTimePeriodAssignEnumType.Template && templateCodes.Contains(x.Value))
|
.Where(x => (x.AssignType == DeviceTimePeriodAssignEnumType.Template && templateCodes.Contains(x.Value))
|
||||||
|| (x.AssignType == DeviceTimePeriodAssignEnumType.Device && deviceCodes.Contains(x.Value)))
|
|| (x.AssignType == DeviceTimePeriodAssignEnumType.Device && deviceCodes.Contains(x.Value)))
|
||||||
|
.Select((x, type) => new DeviceTimePeriodDto()
|
||||||
|
{
|
||||||
|
CardName = type.Display
|
||||||
|
}, true)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public class Startup
|
|||||||
services.AddEndpointsApiExplorer();
|
services.AddEndpointsApiExplorer();
|
||||||
services.AddSwaggerGen(c =>
|
services.AddSwaggerGen(c =>
|
||||||
{
|
{
|
||||||
c.SwaggerDoc("v1", new OpenApiInfo { Title = "Gateway API", Version = "v1", Description = "# gateway api..." });
|
c.SwaggerDoc("v1", new OpenApiInfo { Title = "Gateway API", Version = "v1", Description = "gateway api" });
|
||||||
});
|
});
|
||||||
|
|
||||||
services.AddOcelot();
|
services.AddOcelot();
|
||||||
|
|||||||
@@ -33,17 +33,6 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"UpstreamPathTemplate": "/api/user/{url}",
|
|
||||||
"DownstreamPathTemplate": "/api/{url}",
|
|
||||||
"DownstreamScheme": "http",
|
|
||||||
"DownstreamHostAndPorts": [
|
|
||||||
{
|
|
||||||
"Host": "localhost",
|
|
||||||
"Port": 5004
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"UpstreamPathTemplate": "/api/basic/{url}",
|
"UpstreamPathTemplate": "/api/basic/{url}",
|
||||||
"DownstreamPathTemplate": "/api/{url}",
|
"DownstreamPathTemplate": "/api/{url}",
|
||||||
|
|||||||
@@ -33,17 +33,6 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"UpstreamPathTemplate": "/api/user/{url}",
|
|
||||||
"DownstreamPathTemplate": "/api/{url}",
|
|
||||||
"DownstreamScheme": "http",
|
|
||||||
"DownstreamHostAndPorts": [
|
|
||||||
{
|
|
||||||
"Host": "192.168.199.30",
|
|
||||||
"Port": 31004
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"UpstreamPathTemplate": "/api/basic/{url}",
|
"UpstreamPathTemplate": "/api/basic/{url}",
|
||||||
"DownstreamPathTemplate": "/api/{url}",
|
"DownstreamPathTemplate": "/api/{url}",
|
||||||
|
|||||||
Reference in New Issue
Block a user