From e0770140b4d47a39757e9d31c410d15a067b870e Mon Sep 17 00:00:00 2001 From: liguoyang Date: Wed, 31 Jul 2024 10:15:17 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=E5=B7=B2=E7=9F=A5?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessPlaceShiftSaveMealShiftRequest.cs | 7 +- .../Implements/DevicePermissionService.cs | 8 +- .../Controllers/GainfoQrCodeController.cs | 2 +- .../Request/GainfoFacePageRequest.cs | 4 +- .../Response/GainfoCurrentResponse.cs | 12 +- .../Response/GainfoDetailResponse.cs | 5 + .../Response/GainfoMealResponse.cs | 15 +- .../Response/GainfoPageResponse.cs | 14 +- .../Services/Implements/GainfoFaceService.cs | 8 +- .../Services/Implements/GainfoMealService.cs | 4 +- .../GainfoOutsourceSettingService.cs | 16 +- .../Implements/GainfoQrCodeService.cs | 10 +- .../Services/Implements/GainfoService.cs | 18 +- .../Request/MealSupplementRecordRequest.cs | 9 + .../Response/MealSupplementRecordResponse.cs | 17 +- .../Implements/MealSupplementRecordService.cs | 9 +- .../Order/Controllers/OrdersController.cs | 4 +- .../Order/Request/BalanceRecordPageRequest.cs | 18 +- .../Services/Implements/BalanceService.cs | 4 +- .../Order/Services/Implements/OrderService.cs | 625 ++++++++++-------- Src/Dlhis.Entity/Basic/Entity/GainfoEntity.cs | 6 - .../Basic/Entity/OutsourceSettingEntity.cs | 14 - .../Sys/Entities/FactorySettingEntity.cs | 32 + .../Common/Services/IJinkoJIPService.cs | 4 +- .../Services/ISapBusinessTripService.cs | 6 + .../Services/Implements/JinkoJIPService.cs | 21 +- .../Implements/SapBusinessTripService.cs | 149 +++++ .../Jobs/SyncBusinessTripJob.cs | 161 +---- Src/Dlhis.ScheduledTask/Program.cs | 3 +- .../TaskAssignment/Dto/DeviceTimePeriodDto.cs | 8 + .../TaskAssignment/Dto/TaskDto.cs | 2 +- .../Services/Implements/AssignmentService.cs | 12 +- Src/Gateway/Startup.cs | 2 +- Src/Gateway/ocelot.Development.json | 11 - Src/Gateway/ocelot.json | 11 - 35 files changed, 695 insertions(+), 556 deletions(-) delete mode 100644 Src/Dlhis.Entity/Basic/Entity/OutsourceSettingEntity.cs create mode 100644 Src/Dlhis.Entity/Sys/Entities/FactorySettingEntity.cs create mode 100644 Src/Dlhis.ScheduledTask/Common/Services/ISapBusinessTripService.cs create mode 100644 Src/Dlhis.ScheduledTask/Common/Services/Implements/SapBusinessTripService.cs create mode 100644 Src/Dlhis.ScheduledTask/TaskAssignment/Dto/DeviceTimePeriodDto.cs diff --git a/Src/Dlhis.Basic/BusinessShift/Request/BusinessPlaceShiftSaveMealShiftRequest.cs b/Src/Dlhis.Basic/BusinessShift/Request/BusinessPlaceShiftSaveMealShiftRequest.cs index 8093c05a..20203d9a 100644 --- a/Src/Dlhis.Basic/BusinessShift/Request/BusinessPlaceShiftSaveMealShiftRequest.cs +++ b/Src/Dlhis.Basic/BusinessShift/Request/BusinessPlaceShiftSaveMealShiftRequest.cs @@ -38,12 +38,7 @@ public class BusinessPlaceShiftSaveMealShiftRequest : IValidatableObject yield return new ValidationResult("时间段配置错误", new[] { nameof(TimePeriod) }); } - if (TimePeriod!.Start == null || TimePeriod!.End == null) - { - yield return new ValidationResult("时间段配置错误", new[] { nameof(TimePeriod) }); - } - - if (TimePeriod!.Start == TimePeriod!.End) + if (TimePeriod!.Start == TimePeriod.End) { yield return new ValidationResult("时间段设置区间有误,开始时段不能等于结束时段.", new[] { nameof(TimePeriod) }); } diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs index 54d4c654..788fa493 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs @@ -455,7 +455,7 @@ public class DevicePermissionService : IDevicePermissionService var isOutsource = await _dbContext.Queryable().AnyAsync(x => x.Code == gainfo.Code); - var enableFactoryPermissions = await _dbContext.Queryable().ToListAsync(); + var enableFactoryPermissions = await _dbContext.Queryable().ToListAsync(); var gainfoDto = new GainfoDto { @@ -467,7 +467,7 @@ public class DevicePermissionService : IDevicePermissionService Factory = gainfo.Factory, DepartmentNo = gainfo.DepartmentNo, 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); @@ -627,7 +627,7 @@ public class DevicePermissionService : IDevicePermissionService .Select(x => x.Code) .ToListAsync(); - var enableFactoryPermissions = await _dbContext.Queryable().ToListAsync(); + var enableFactoryPermissions = await _dbContext.Queryable().ToListAsync(); var gainfoGroupRelationships = await _dbContext.Queryable().Where(x => userNos.Contains(x.UserNo)).ToListAsync(); var devicePermissions = await _dbContext.Queryable().ToListAsync(); @@ -648,7 +648,7 @@ public class DevicePermissionService : IDevicePermissionService Factory = gainfo.Factory, DepartmentNo = gainfo.DepartmentNo, 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); diff --git a/Src/Dlhis.Basic/Organization/Controllers/GainfoQrCodeController.cs b/Src/Dlhis.Basic/Organization/Controllers/GainfoQrCodeController.cs index c043c07b..c15939c1 100644 --- a/Src/Dlhis.Basic/Organization/Controllers/GainfoQrCodeController.cs +++ b/Src/Dlhis.Basic/Organization/Controllers/GainfoQrCodeController.cs @@ -24,7 +24,7 @@ public class GainfoQrCodeController : ControllerBase /// /// 是否主动刷新 /// - [HttpGet("consumer")] + [HttpGet("consume")] public async Task GetMyQrCode(bool isNeedRefresh = false) { return await _gainfoQrCodeService.GetMyQrCodeAsync(isNeedRefresh); diff --git a/Src/Dlhis.Basic/Organization/Request/GainfoFacePageRequest.cs b/Src/Dlhis.Basic/Organization/Request/GainfoFacePageRequest.cs index 9f9c325d..edfc4bd4 100644 --- a/Src/Dlhis.Basic/Organization/Request/GainfoFacePageRequest.cs +++ b/Src/Dlhis.Basic/Organization/Request/GainfoFacePageRequest.cs @@ -10,6 +10,6 @@ public class GainfoFacePageRequest : PageDto /// /// 厂区 /// - [Required(ErrorMessage = "厂区不可为空")] - public string Factory { get; set; } + [MinLength(1, ErrorMessage = "厂区不可为空")] + public string Factories { get; set; } } \ No newline at end of file diff --git a/Src/Dlhis.Basic/Organization/Response/GainfoCurrentResponse.cs b/Src/Dlhis.Basic/Organization/Response/GainfoCurrentResponse.cs index 2404010f..06f3b3db 100644 --- a/Src/Dlhis.Basic/Organization/Response/GainfoCurrentResponse.cs +++ b/Src/Dlhis.Basic/Organization/Response/GainfoCurrentResponse.cs @@ -53,8 +53,18 @@ public class GainfoCurrentResponse /// public string Factory { get; set; } + /// + /// 卡类型 + /// + public int? CardType { get; set; } + + /// + /// 卡类型名称 + /// + public string CardTypeName { get; set; } + /// /// 就餐信息 /// public GainfoCurrentMealInfoResponse MealInfo { get; set; } -} +} \ No newline at end of file diff --git a/Src/Dlhis.Basic/Organization/Response/GainfoDetailResponse.cs b/Src/Dlhis.Basic/Organization/Response/GainfoDetailResponse.cs index e3a57347..3891996b 100644 --- a/Src/Dlhis.Basic/Organization/Response/GainfoDetailResponse.cs +++ b/Src/Dlhis.Basic/Organization/Response/GainfoDetailResponse.cs @@ -141,6 +141,11 @@ public class GainfoDetailResponse public DateTime? EntryDate { get; set; } + public int? CardType { get; set; } + + public string CardTypeName { get; set; } + + //*********************************************************************************************************************** /// diff --git a/Src/Dlhis.Basic/Organization/Response/GainfoMealResponse.cs b/Src/Dlhis.Basic/Organization/Response/GainfoMealResponse.cs index 639bc76c..33c7472d 100644 --- a/Src/Dlhis.Basic/Organization/Response/GainfoMealResponse.cs +++ b/Src/Dlhis.Basic/Organization/Response/GainfoMealResponse.cs @@ -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 { @@ -39,4 +42,14 @@ public class GainfoMealResponse /// 餐补总额 /// public decimal? MealSupplementAmount { get; set; } + + /// + /// 档案状态 + /// + public GainfoStatusEnumType Status { get; set; } + + /// + /// 档案状态中文 + /// + public string StatusDesc => Status.GetDescription(); } \ No newline at end of file diff --git a/Src/Dlhis.Basic/Organization/Response/GainfoPageResponse.cs b/Src/Dlhis.Basic/Organization/Response/GainfoPageResponse.cs index 6bb69669..f2508852 100644 --- a/Src/Dlhis.Basic/Organization/Response/GainfoPageResponse.cs +++ b/Src/Dlhis.Basic/Organization/Response/GainfoPageResponse.cs @@ -8,7 +8,7 @@ namespace Dlhis.Basic.Organization.Response; public class GainfoPageResponse { public long Id { get; set; } - + public string No { get; set; } /// @@ -26,11 +26,6 @@ public class GainfoPageResponse /// public string Name { get; set; } - /// - /// 外文名字 - /// - public string NameEn { get; set; } - /// /// 工号 /// @@ -51,7 +46,7 @@ public class GainfoPageResponse /// [JsonConverter(typeof(ObfuscateProviderJsonConverter), 6)] public string IdNo { get; set; } - + /// /// 手机号码 /// @@ -91,6 +86,11 @@ public class GainfoPageResponse /// public string DepartmentNo { get; set; } + /// + /// 部门名称 + /// + public string DepartmentName { get; set; } + /// /// 民族代码 /// diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoFaceService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoFaceService.cs index e08538fc..f38d79b9 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoFaceService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoFaceService.cs @@ -51,12 +51,14 @@ public class GainfoFaceService : IGainfoFaceService public async Task GetPageAsync(GainfoFacePageRequest request) { - var userCodes = await _dbContext.Queryable().Where(x => x.Factory == request.Factory).Select(x => x.Code).ToListAsync(); + var factories = request.Factories; + + var userCodes = await _dbContext.Queryable().Where(x => factories.Contains(x.Factory)).Select(x => x.Code).ToListAsync(); var existsFaceCodes = await _faceDbContext.Queryable().Where(x => userCodes.Contains(x.UserCode)).Select(x => x.UserCode).ToListAsync(); var list = await _dbContext.Queryable() .LeftJoin((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.Search.IsPresent(), x => x.Code == request.Search) @@ -275,7 +277,7 @@ public class GainfoFaceService : IGainfoFaceService _logger.LogWarning("相同的人脸照片更新忽略"); return; } - + face.ModifiedBy = _currentUser.GetIntSubjectId(); face.ModifiedTime = DateTime.Now; face.Face = request.Face; diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoMealService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoMealService.cs index f8d863cb..93249cff 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoMealService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoMealService.cs @@ -1,6 +1,7 @@ using Dlhis.Basic.Organization.Request; using Dlhis.Basic.Organization.Response; using Dlhis.Entity.Basic.Entity; +using Dlhis.Entity.Basic.Enums; using Dlhis.Entity.Canteen.Entities; using Dlhis.Entity.Canteen.Enums; using Kurisu.AspNetCore.Authentication.Abstractions; @@ -47,7 +48,8 @@ public class GainfoMealService : IGainfoMealService UserCode = meal.UserCode, UserName = SqlFunc.IsNull(gainfo.Name, gainfoLeave.Name), 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); diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoOutsourceSettingService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoOutsourceSettingService.cs index dfcee0e0..f8f4e151 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoOutsourceSettingService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoOutsourceSettingService.cs @@ -1,6 +1,7 @@ using Dlhis.Basic.Device.Services; using Dlhis.Basic.Organization.Request; using Dlhis.Entity.Basic.Entity; +using Dlhis.Entity.Sys.Entities; using Kurisu.AspNetCore.Authentication.Abstractions; using Kurisu.AspNetCore.DataAccess.SqlSugar.Services; using Kurisu.AspNetCore.Utils.Extensions; @@ -32,15 +33,15 @@ public class GainfoOutsourceSettingService : IGainfoOutsourceSettingService { var currentTenantId = _currentUser.GetStringTenantId(); - (!request.Id.HasValue && await _dbContext.Queryable() + (!request.Id.HasValue && await _dbContext.Queryable() .Where(x => x.TenantId == currentTenantId) .AnyAsync()).ThrowIfTrue("保存失败,请检查参数"); if (!request.Id.HasValue) { - var entity = new OutsourceSettingEntity + var entity = new FactorySettingEntity { - EnableFactory = request.EnableFactory, + EnableOutsourceDown = request.EnableFactory, TenantId = currentTenantId }; @@ -48,10 +49,10 @@ public class GainfoOutsourceSettingService : IGainfoOutsourceSettingService } else { - var entity = await _dbContext.Queryable().Where(x => x.Id == request.Id).SingleAsync(); + var entity = await _dbContext.Queryable().Where(x => x.Id == request.Id).SingleAsync(); entity.ThrowIfNull("数据不存在,保存失败"); - entity.EnableFactory = request.EnableFactory; + entity.EnableOutsourceDown = request.EnableFactory; await _dbContext.UpdateAsync(entity); } @@ -62,10 +63,9 @@ public class GainfoOutsourceSettingService : IGainfoOutsourceSettingService public async Task GetSettingAsync() { var currentTenantId = _currentUser.GetStringTenantId(); - return await _dbContext.Queryable().Where(x => x.TenantId == currentTenantId).Select(x => new + return await _dbContext.Queryable().Where(x => x.TenantId == currentTenantId).Select(x => new { - x.Id, - x.EnableFactory + x.Id, EnableFactory = x.EnableOutsourceDown }).SingleAsync(); } } \ No newline at end of file diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoQrCodeService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoQrCodeService.cs index 0caa230b..647b6a06 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoQrCodeService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoQrCodeService.cs @@ -17,11 +17,13 @@ public class GainfoQrCodeService : IGainfoQrCodeService _currentUser = currentUser; } - public async Task GetMyQrCodeAsync(bool isNeedRefresh = false) { var jinkoCode = _currentUser.GetUserClaim("jinko-code"); - jinkoCode.IsEmpty().ThrowIfTrue("无法获取二维码"); + if (jinkoCode.IsEmpty()) + { + return null; + } var now = DateTime.Now; var gainfoQrCode = await _dbContext.Queryable().SingleAsync(x => x.UserCode == jinkoCode); @@ -53,11 +55,9 @@ public class GainfoQrCodeService : IGainfoQrCodeService private static string GenerateQrCode(string code) { var ts = DateTimeOffset.Now.ToUnixTimeMilliseconds(); - //var gainfo = await _dbContext.Queryable().Where(x => x.Code == code).SingleAsync(); - //var qrCode = string.Concat("consumer", ":", code, ":", Guid.NewGuid()).Replace("-", ""); var qrCode = string.Concat("consumer", ":", code, ":"); - return qrCode.ToArray().Select(x => + return "01" + qrCode.ToArray().Select(x => { var b = Encoding.ASCII.GetBytes(x.ToString()); int i = b[0]; diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs index 54685dcb..808c3082 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs @@ -88,7 +88,11 @@ public class GainfoService : IGainfoService gainfo.Name.Contains(request.Search) || gainfo.Code == request.Search || gainfo.IdNo == request.Search) - .Select() + .LeftJoin((x, department) => x.DepartmentNo == department.No) + .Select((x, department) => new GainfoPageResponse + { + DepartmentName = department.Name + }, true) .ToPageListAsync(request); @@ -142,8 +146,9 @@ public class GainfoService : IGainfoService var info = await _gainfoStore.Queryable(GainfoStatusEnumType.Working) .LeftJoin((ga, department) => ga.DepartmentNo == department.No) .LeftJoin((ga, department, mealUser) => ga.No == mealUser.UserNo) + .LeftJoin((ga, department, mealUser, type) => type.Code == ga.CardType.ToString() && type.Type == "timeperiod") .Where((ga, department) => ga.Id == gainfo.Id) - .Select((ga, department, mealUser) => new GainfoCurrentResponse + .Select((ga, department, mealUser, type) => new GainfoCurrentResponse { UserNo = ga.No, Birthday = ga.Birthday, @@ -156,7 +161,9 @@ public class GainfoService : IGainfoService MealInfo = new GainfoCurrentMealInfoResponse { Balance = mealUser.Balance - } + }, + CardType = ga.CardType, + CardTypeName = type.Display }).SingleAsync(); if (info != null) @@ -265,8 +272,9 @@ public class GainfoService : IGainfoService var info = await _gainfoStore.Queryable(request.Status) .LeftJoin((ga, de) => ga.DepartmentNo == de.No) .LeftJoin((ga, de, pos) => ga.PositionNo == pos.No) + .LeftJoin((ga, de, pos, type) => type.Code == ga.CardType.ToString() && type.Type == "timeperiod") .Where(ga => ga.No == request.No) - .Select((ga, de, pos) => new GainfoDetailResponse + .Select((ga, de, pos, type) => new GainfoDetailResponse { No = ga.No, SapNo = ga.SapNo, @@ -295,6 +303,8 @@ public class GainfoService : IGainfoService DepartmentName = de.Name, Position = pos.Name, + CardType = ga.CardType, + CardTypeName = type.Display }) .SingleAsync(); diff --git a/Src/Dlhis.Canteen/MealSupplementRecord/Request/MealSupplementRecordRequest.cs b/Src/Dlhis.Canteen/MealSupplementRecord/Request/MealSupplementRecordRequest.cs index 4fb105c3..6dbe02f4 100644 --- a/Src/Dlhis.Canteen/MealSupplementRecord/Request/MealSupplementRecordRequest.cs +++ b/Src/Dlhis.Canteen/MealSupplementRecord/Request/MealSupplementRecordRequest.cs @@ -28,6 +28,15 @@ public class MealSupplementRecordRequest : PageDto, IValidatableObject /// public string Factory { get; set; } + /// + /// 部门号 + /// + public string DepartmentNo { get; set; } + + /// + /// 人事范围 + /// + public string Werks { get; set; } /// /// 餐补日期范围 diff --git a/Src/Dlhis.Canteen/MealSupplementRecord/Response/MealSupplementRecordResponse.cs b/Src/Dlhis.Canteen/MealSupplementRecord/Response/MealSupplementRecordResponse.cs index c8f86168..ac65fb76 100644 --- a/Src/Dlhis.Canteen/MealSupplementRecord/Response/MealSupplementRecordResponse.cs +++ b/Src/Dlhis.Canteen/MealSupplementRecord/Response/MealSupplementRecordResponse.cs @@ -45,7 +45,9 @@ public class MealSupplementRecordResponse /// public string Factory { get; set; } - + /// + /// 备注 + /// public string Remark { get; set; } /// @@ -63,5 +65,18 @@ public class MealSupplementRecordResponse /// public bool Sync { get; set; } + /// + /// 创建时间 + /// public DateTime CreateTime { get; set; } + + /// + /// 部门名称 + /// + public string DepartmentName { get; set; } + + /// + /// 人事范围 + /// + public string Werks { get; set; } } \ No newline at end of file diff --git a/Src/Dlhis.Canteen/MealSupplementRecord/Services/Implements/MealSupplementRecordService.cs b/Src/Dlhis.Canteen/MealSupplementRecord/Services/Implements/MealSupplementRecordService.cs index 07e903ea..3e6e677c 100644 --- a/Src/Dlhis.Canteen/MealSupplementRecord/Services/Implements/MealSupplementRecordService.cs +++ b/Src/Dlhis.Canteen/MealSupplementRecord/Services/Implements/MealSupplementRecordService.cs @@ -32,13 +32,16 @@ public class MealSupplementRecordService : IMealSupplementRecordService { var page = await _dbContext.Queryable() .LeftJoin((x, ga) => x.Code == ga.Code) + .LeftJoin((x, ga, department) => ga.DepartmentNo == department.No) .WhereIF(request.Status.HasValue, x => x.Status == request.Status) .WhereIF(request.Sync.HasValue, x => x.Sync == request.Sync) .WhereIF(request.Workplace.IsPresent(), x => x.Workplace == request.Workplace) .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.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, Code = x.Code, @@ -51,7 +54,9 @@ public class MealSupplementRecordService : IMealSupplementRecordService UserName = ga.Name, Workplace = x.Workplace, Factory = x.Factory, - CreateTime = x.CreateTime + CreateTime = x.CreateTime, + DepartmentName = department.Name, + Werks = ga.Werks }) .ToPageListAsync(request); diff --git a/Src/Dlhis.Canteen/Order/Controllers/OrdersController.cs b/Src/Dlhis.Canteen/Order/Controllers/OrdersController.cs index 7ac40969..51e0027c 100644 --- a/Src/Dlhis.Canteen/Order/Controllers/OrdersController.cs +++ b/Src/Dlhis.Canteen/Order/Controllers/OrdersController.cs @@ -57,7 +57,7 @@ public class OrdersController : ControllerBase _logger.LogInformation("消费请求:{json}. 耗时记录:{log}", request.ToJson(), result.Logs.Join("\r\n")); } } - catch (Exception e) + catch (Exception) { //ignore } @@ -90,7 +90,7 @@ public class OrdersController : ControllerBase _logger.LogInformation("消费请求:{json}. 耗时记录:{log}", request.ToJson(), result.Logs.Join("\r\n")); } } - catch (Exception e) + catch (Exception) { //ignore } diff --git a/Src/Dlhis.Canteen/Order/Request/BalanceRecordPageRequest.cs b/Src/Dlhis.Canteen/Order/Request/BalanceRecordPageRequest.cs index 59e53968..ed941e98 100644 --- a/Src/Dlhis.Canteen/Order/Request/BalanceRecordPageRequest.cs +++ b/Src/Dlhis.Canteen/Order/Request/BalanceRecordPageRequest.cs @@ -1,4 +1,5 @@ using System.ComponentModel.DataAnnotations; +using Dlhis.Entity.Basic.Enums; using Dlhis.Entity.Canteen.Enums; using Kurisu.AspNetCore.CustomClass; using Kurisu.AspNetCore.DataAccess.Dto; @@ -28,16 +29,21 @@ public class BalanceRecordPageRequest : PageDto, IValidatableObject /// public DateTimePeriod SearchDateTimePeriod { get; set; } + /// + /// 档案状态 + /// + [EnumDataType(typeof(GainfoStatusEnumType))] + public GainfoStatusEnumType? GainfoStatus { get; set; } + public IEnumerable 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; } -} +} \ No newline at end of file diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs index eaa72903..fd831b10 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs @@ -3,6 +3,7 @@ using Dlhis.Canteen.Order.Request; using Dlhis.Canteen.Order.Response; using Dlhis.Canteen.Setting.Services; using Dlhis.Entity.Basic.Entity; +using Dlhis.Entity.Basic.Enums; using Dlhis.Entity.Canteen.Entities; using Dlhis.Entity.Canteen.Enums; using Dlhis.Entity.Device; @@ -45,7 +46,8 @@ public class BalanceService : IBalanceService public async Task> GetPageAsync(BalanceRecordPageRequest request) { var page = await _dbContext.Queryable() - .LeftJoin((record, ga) => record.UserNo == ga.No) + .LeftJoinIF(request.GainfoStatus == GainfoStatusEnumType.Working, (record, ga) => record.UserNo == ga.No) + .LeftJoinIF(request.GainfoStatus == GainfoStatusEnumType.Leave, (record, ga) => record.UserNo == ga.No) .LeftJoin((record, ga, department) => ga.DepartmentNo == department.No) .LeftJoin((record, ga, department, bPlace) => record.BusinessPlaceCode == bPlace.Code) .LeftJoin((record, ga, department, bPlace, order) => record.No == order.No) diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs index 51c5b2e5..9d3eb1a9 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs @@ -36,88 +36,31 @@ public class OrderService : BaseOrderService, IOrderService _serviceProvider = serviceProvider; } + /// + /// 设备消费 + /// + /// + /// public async Task DeviceConsume(OrderAddRequest request) { return await AddAsync(request); } - + /// + /// 设备消费 + /// + /// + /// public async Task AddAsync(OrderAddRequest request) { _sw = new Stopwatch(); - //尝试匹配userId - var s = long.TryParse(request.UserUniqueNo, out var userId); - - //根据档案号 - var gainfo = await DbContext.Queryable() - .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().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(); - } + var gainfo = await GetUserAsync(request); _logs.Add("获取人员耗时:" + _sw.ElapsedMilliseconds); _sw.Restart(); - var message = string.Empty; - - if (request.IsOffline) - { - if (request.ThirdNo.IsPresent()) - { - var redisCache = _serviceProvider.GetService(); - - await using var handler = await redisCache.LockAsync($"consume:device:{request.ThirdNo}"); - if (handler.Acquired) - { - if (await ToCheckAsync(request.ThirdNo)) - { - try - { - await HandleOfflineAsync(request.Adapt(), gainfo); - } - catch (Exception ex) - { - Logger.LogError(ex, "离线入库错误: 订单号:{no} .{message}", request.ThirdNo, ex.Message); - } - } - } - } - else - { - try - { - await HandleOfflineAsync(request.Adapt(), gainfo); - } - catch (Exception ex) - { - Logger.LogError(ex, "离线入库错误: 订单号:{no} .{message}", request.ThirdNo, ex.Message); - } - } - } - else - { - gainfo.ThrowIfNull("无消费权限"); - - try - { - (await DbContext.Queryable().Where(x => x.UserCode == gainfo.Code).AnyAsync()).ThrowIfFalse("就餐余额不足"); - await ConsumeAsync(request.Adapt(), gainfo); - } - catch (Exception ex) - { - message = ex.Message; - } - } + var message = await ToDoAsync(request, gainfo); //获取人员余额 var data = await DbContext.Queryable() @@ -151,7 +94,262 @@ public class OrderService : BaseOrderService, IOrderService }; } - private async Task ToCheckAsync(string thirdNo) + + public async Task> GetOrdersAggregationAsync(PageDto page) + { + var subjectId = CurrentUser.GetIntSubjectId(); + var gainfo = await DbContext.Queryable().Where(x => x.IdentityUserId == subjectId).FirstAsync(); + var jinkoCode = CurrentUser.GetUserClaim("jinko-code") ?? string.Empty; + if (jinkoCode.IsPresent()) + { + gainfo = await DbContext.Queryable().Where(x => x.Code == jinkoCode).FirstAsync(); + } + + var pageResult = await DbContext.Queryable().Where(x => x.UserNo == gainfo.No) + .LeftJoin((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() + .LeftJoin((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 ************************************************************/ + + /// + /// 获取当前消费人员 + /// + /// + /// + private async Task 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() + .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().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; + } + + + /// + /// 获取成本日期 + /// + /// + /// + /// + private async Task GetCostDateAsync(BusinessShiftMealRelationshipEntity shift, DateTime costDateTime) + { + var switchTime = await GetSettingAsync(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; + } + + + /// + /// 验证参数 + /// + /// + /// + /// + private async Task Verify(CanteenOrderEntity order) + { + var beginOfDay = DateTime.Today; + var endOfDay = beginOfDay.AddDays(1).AddSeconds(-1); + + //今天所有消费记录 + var todayAllBalanceRecords = await DbContext.Queryable() + .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() + .Where(x => x.Catalog == CanteenBusinessPlaceCatalogEnumType.Supermarket) + .Select(x => x.Code) + .ToListAsync(); + + //一天消费金额 + var dayCostMax = await GetSettingAsync(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(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(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()}不允许多次消费"); + } + } + + + /// + /// 生成充值记录 + /// + /// + /// + /// + /// + private async Task GenerateConsumeRecordAsync(long orderId) + { + var order = await DbContext.Queryable().Where(x => x.Id == orderId).SingleAsync(); + //校验 + await Verify(order); + _logs.Add("消费请求校验:" + _sw.ElapsedMilliseconds); + _sw.Restart(); + + + await CommonHelper.RetryAsync(async () => + { + var gainfoMeal = await DbContext.Queryable().Where(x => x.UserNo == order.UserNo).SingleAsync(); + //金额+- + gainfoMeal.Balance += order.Amount; + (gainfoMeal.Balance < 0).ThrowIfTrue("余额不足,无法消费"); + + await DbContext.Updateable() + .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(); + await DbContext.InsertAsync(balanceRecord); + }, 5); + + _logs.Add("消费写入:" + _sw.ElapsedMilliseconds); + _sw.Restart(); + } + + /// + /// 根据二维码获取消费用户 + /// + /// + /// + private async Task GetUserByQrCodeAsync(string qrCode) + { + var gainfoQrCode = await DbContext.Queryable().Where(x => x.QrCode == qrCode).SingleAsync(); + gainfoQrCode.ThrowIfNull("消费码已过期"); + (gainfoQrCode.ModifiedTime.AddMinutes(1) > DateTime.Now).ThrowIfTrue("消费码已过期"); + + return await DbContext.Queryable().Where(x => x.Code == gainfoQrCode.UserCode).SingleAsync(); + } + + + /// + /// 检查是否可以离线消费 + /// + /// + /// + private async Task ToCheckAbleOfflineConsumeAsync(string thirdNo) { var order = await DbContext.Queryable() .Where(x => x.ThirdNo == thirdNo) @@ -163,15 +361,15 @@ public class OrderService : BaseOrderService, IOrderService return true; } - if (!order.IsOffline && order.OrderStatus != CanteenOrderStatusEnumType.Success) - { - return true; - } - - return false; + //存在在线order数据,但是状态未成功 + return !order.IsOffline && order.OrderStatus != CanteenOrderStatusEnumType.Success; } - + /// + /// 离线消费处理 + /// + /// + /// private async Task HandleOfflineAsync(ConsumeRequest request, GainfoEntity gainfo) { var registry = await DbContext.Queryable() @@ -240,34 +438,26 @@ public class OrderService : BaseOrderService, IOrderService await DbContext.InsertReturnIdentityAsync(order); - var allowNoBalance = await GetSettingAsync(gainfo.No, businessPlaceInfo.TenantId, CanteenSettingItemEnumType.AllowNoBalance); - await CommonHelper.RetryAsync(async () => { - if (!allowNoBalance) + var redisCache = _serviceProvider.GetService(); + await using var handler = await redisCache.LockAsync($"gainfo:meal:{order.UserNo}", retryInterval: TimeSpan.FromSeconds(1)); + if (handler.Acquired) { - GainfoMealEntity gainfoMeal = null; - var redisCache = _serviceProvider.GetService(); - using (var handler = await redisCache.LockAsync($"gainfo:meal:{order.UserNo}", retryInterval: TimeSpan.FromSeconds(1))) + var gainfoMeal = await DbContext.Queryable().Where(x => x.UserNo == order.UserNo).FirstAsync(); + if (gainfoMeal == null) { - if (handler.Acquired) + gainfoMeal = new GainfoMealEntity { - gainfoMeal = await DbContext.Queryable().Where(x => x.UserNo == order.UserNo).FirstAsync(); - if (gainfoMeal == null) - { - gainfoMeal = new GainfoMealEntity - { - Balance = 0, - BalanceOfRecharge = 0, - BalanceOfSubsidies = 0, - Version = 0, - UserNo = order.UserNo, - UserCode = order.UserCode, - }; + Balance = 0, + 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) .Where(x => x.UserNo == order.UserNo && x.Version == gainfoMeal.Version) //必须与查询时的version一致 .ExecuteCommandThrowVersionAsync(); - } - //写入记录 - var balanceRecord = order.Adapt(); - await DbContext.InsertAsync(balanceRecord); + //写入记录 + var balanceRecord = order.Adapt(); + await DbContext.InsertAsync(balanceRecord); + } }, 5); } @@ -372,7 +562,7 @@ public class OrderService : BaseOrderService, IOrderService var orderId = await DbContext.InsertReturnIdentityAsync(order); _logs.Add("临时order写入:" + _sw.ElapsedMilliseconds); _sw.Restart(); - + try { await GenerateConsumeRecordAsync(orderId); @@ -409,196 +599,63 @@ public class OrderService : BaseOrderService, IOrderService } } - public async Task> GetOrdersAggregationAsync(PageDto page) - { - var subjectId = CurrentUser.GetIntSubjectId(); - var gainfo = await DbContext.Queryable().Where(x => x.IdentityUserId == subjectId).FirstAsync(); - var jinkoCode = CurrentUser.GetUserClaim("jinko-code") ?? string.Empty; - if (jinkoCode.IsPresent()) - { - gainfo = await DbContext.Queryable().Where(x => x.Code == jinkoCode).FirstAsync(); - } - - var pageResult = await DbContext.Queryable().Where(x => x.UserNo == gainfo.No) - .LeftJoin((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() - .LeftJoin((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 ************************************************************/ /// - /// 获取成本日期 + /// 分支处理在线/离线消费 /// - /// - /// + /// + /// /// - private async Task GetCostDateAsync(BusinessShiftMealRelationshipEntity shift, DateTime costDateTime) + private async Task ToDoAsync(OrderAddRequest request, GainfoEntity gainfo) { - var switchTime = await GetSettingAsync(string.Empty, shift.TenantId, CanteenSettingItemEnumType.BusinessSwitchTime); - - var costDate = costDateTime.Date; - - if (switchTime.HasValue) + var message = "消费成功"; + if (request.IsOffline) { - var beginOfDay = costDateTime.Date; - - var setTime = beginOfDay.Add(switchTime.Value.ToTimeSpan()); - if (costDateTime < setTime) - costDate = costDateTime.Date.AddDays(-1); - } - - return costDate; - } - - - /// - /// 验证参数 - /// - /// - /// - /// - private async Task Verify(CanteenOrderEntity order) - { - var beginOfDay = DateTime.Today; - var endOfDay = beginOfDay.AddDays(1).AddSeconds(-1); - - //今天所有消费记录 - var todayAllBalanceRecords = await DbContext.Queryable() - .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() - .Where(x => x.Catalog == CanteenBusinessPlaceCatalogEnumType.Supermarket) - .Select(x => x.Code) - .ToListAsync(); - - //一天消费金额 - var dayCostMax = await GetSettingAsync(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(order.UserNo, order.TenantId, CanteenSettingItemEnumType.OnceCostMax); - if (onceCostMax != default) - { - (Math.Abs(order.Amount) > onceCostMax).ThrowIfTrue($"单次消费金额不能超出{onceCostMax}元"); - } - - //超市消费限额 - var dayMarketCostMax = await GetSettingAsync(order.UserNo, order.TenantId, CanteenSettingItemEnumType.DayMarketCostMax); - if (dayMarketCostMax != default) - { - //current businessplace is supermarket - if (order.BusinessPlaceCode.HasValue && supermarketCodes.Contains(order.BusinessPlaceCode.Value)) + if (request.ThirdNo.IsPresent()) { - var cost = todayAllBalanceRecords.Where(x => x.BusinessPlaceCode.HasValue) - .Where(x => supermarketCodes.Contains(x.BusinessPlaceCode.Value)) - .Sum(x => Math.Abs(x.Amount)); + var redisCache = _serviceProvider.GetService(); - (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(), gainfo); + } + catch (Exception ex) + { + Logger.LogError(ex, "离线入库错误: 订单号:{no} .{message}", request.ThirdNo, ex.Message); + } + } + } + } + else + { + try + { + await HandleOfflineAsync(request.Adapt(), gainfo); + } + catch (Exception ex) + { + Logger.LogError(ex, "离线入库错误: 订单号:{no} .{message}", request.ThirdNo, ex.Message); + } + } + } + else + { + try + { + (await DbContext.Queryable().Where(x => x.UserCode == gainfo.Code).AnyAsync()).ThrowIfFalse("就餐余额不足"); + await ConsumeAsync(request.Adapt(), gainfo); + } + catch (Exception ex) + { + message = ex.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()}不允许多次消费"); - } - } - - - /// - /// 生成充值记录 - /// - /// - /// - /// - /// - private async Task GenerateConsumeRecordAsync(long orderId) - { - var order = await DbContext.Queryable().Where(x => x.Id == orderId).SingleAsync(); - //校验 - await Verify(order); - _logs.Add("消费请求校验:" + _sw.ElapsedMilliseconds); - _sw.Restart(); - - - await CommonHelper.RetryAsync(async () => - { - var gainfoMeal = await DbContext.Queryable().Where(x => x.UserNo == order.UserNo).SingleAsync(); - //金额+- - gainfoMeal.Balance += order.Amount; - (gainfoMeal.Balance < 0).ThrowIfTrue("余额不足,无法消费"); - - await DbContext.Updateable() - .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(); - await DbContext.InsertAsync(balanceRecord); - }, 5); - - _logs.Add("消费写入:" + _sw.ElapsedMilliseconds); - _sw.Restart(); - } - - /// - /// 根据二维码获取消费用户 - /// - /// - /// - private async Task GetUserNoByQrCodeAsync(string qrCode) - { - var gainfoQrCode = await DbContext.Queryable().Where(x => x.QrCode == qrCode).SingleAsync(); - gainfoQrCode.ThrowIfNull("消费码已过期"); - (gainfoQrCode.ModifiedTime.AddMinutes(1) > DateTime.Now).ThrowIfTrue("消费码已过期"); - - return gainfoQrCode.UserCode; + return message; } } \ No newline at end of file diff --git a/Src/Dlhis.Entity/Basic/Entity/GainfoEntity.cs b/Src/Dlhis.Entity/Basic/Entity/GainfoEntity.cs index 5ebc92f8..d57329c8 100644 --- a/Src/Dlhis.Entity/Basic/Entity/GainfoEntity.cs +++ b/Src/Dlhis.Entity/Basic/Entity/GainfoEntity.cs @@ -36,12 +36,6 @@ public class GainfoEntity : SugarBaseEntity [SugarColumn(ColumnDescription = "姓名")] public string Name { get; set; } - /// - /// 外文名字 - /// - [SugarColumn(ColumnDescription = "外文名字")] - public string NameEn { get; set; } - /// /// 学工号 /// diff --git a/Src/Dlhis.Entity/Basic/Entity/OutsourceSettingEntity.cs b/Src/Dlhis.Entity/Basic/Entity/OutsourceSettingEntity.cs deleted file mode 100644 index 7a218bd0..00000000 --- a/Src/Dlhis.Entity/Basic/Entity/OutsourceSettingEntity.cs +++ /dev/null @@ -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; } -} \ No newline at end of file diff --git a/Src/Dlhis.Entity/Sys/Entities/FactorySettingEntity.cs b/Src/Dlhis.Entity/Sys/Entities/FactorySettingEntity.cs new file mode 100644 index 00000000..2c1cb8e2 --- /dev/null +++ b/Src/Dlhis.Entity/Sys/Entities/FactorySettingEntity.cs @@ -0,0 +1,32 @@ +using Kurisu.AspNetCore.DataAccess.Entity; +using Kurisu.AspNetCore.DataAccess.SqlSugar; +using SqlSugar; + +namespace Dlhis.Entity.Sys.Entities; + +/// +/// 厂区配置 +/// +[SugarTable(TableName = "FactorySetting", TableDescription = "厂区配置")] +public class FactorySettingEntity : SugarBaseEntity, ITenantId +{ + /// + /// 是否启用外包自动下发 + /// + [SugarColumn(ColumnDataType = "bit", ColumnDescription = "是否启用外包自动下发")] + public bool EnableOutsourceDown { get; set; } + + /// + /// 档案二维码过期时间 + /// + [SugarColumn(ColumnDescription = "档案二维码过期时间")] + public int UserQrCodeExpiration { get; set; } + + /// + /// 电子餐券二维码过期时间 + /// + [SugarColumn(ColumnDescription = "电子餐券二维码过期时间")] + public int EMealVoucherQrCodeExpiration { get; set; } + + public string TenantId { get; set; } +} \ No newline at end of file diff --git a/Src/Dlhis.ScheduledTask/Common/Services/IJinkoJIPService.cs b/Src/Dlhis.ScheduledTask/Common/Services/IJinkoJIPService.cs index 50d3567c..5533267d 100644 --- a/Src/Dlhis.ScheduledTask/Common/Services/IJinkoJIPService.cs +++ b/Src/Dlhis.ScheduledTask/Common/Services/IJinkoJIPService.cs @@ -15,9 +15,9 @@ public interface IJinkoJIPService : ISingletonDependency /// /// /// - /// + /// /// - Task GetTravelInfosByDepartmentsAsync(DateTime begin, DateTime end, List departmentNos); + Task GetTravelInfosByFactoryAsync(DateTime begin, DateTime end, string fatory); /// /// 获取出差信息 diff --git a/Src/Dlhis.ScheduledTask/Common/Services/ISapBusinessTripService.cs b/Src/Dlhis.ScheduledTask/Common/Services/ISapBusinessTripService.cs new file mode 100644 index 00000000..183f3278 --- /dev/null +++ b/Src/Dlhis.ScheduledTask/Common/Services/ISapBusinessTripService.cs @@ -0,0 +1,6 @@ +namespace Dlhis.ScheduledTask.Common.Services; + +public interface ISapBusinessTripService : IScopeDependency +{ + Task HandlerBusinessTripsByFactoryAsync(string factory); +} \ No newline at end of file diff --git a/Src/Dlhis.ScheduledTask/Common/Services/Implements/JinkoJIPService.cs b/Src/Dlhis.ScheduledTask/Common/Services/Implements/JinkoJIPService.cs index 2f336f97..9ed40b41 100644 --- a/Src/Dlhis.ScheduledTask/Common/Services/Implements/JinkoJIPService.cs +++ b/Src/Dlhis.ScheduledTask/Common/Services/Implements/JinkoJIPService.cs @@ -95,25 +95,26 @@ public class JinkoJIPService : IJinkoJIPService } - public async Task GetTravelInfosByDepartmentsAsync(DateTime begin, DateTime end, List departmentNos) + public async Task GetTravelInfosByFactoryAsync(DateTime begin, DateTime end, string factory) { const string apiUrl = "/JIP/HCM/HCM_TRAVELINFO"; var beginDay = begin.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 { + I_PAGE = 1, + I_LINE = 500, IV_BEGDA = beginDay, IV_ENDDA = endDay, - IT_2002OR = d + IT_CCMDD = new List + { + new + { + IV_CCMDD = factory + } + } }; var body = obj.ToJson(); @@ -166,7 +167,7 @@ public class JinkoJIPService : IJinkoJIPService I_WORKCODE = userCode, I_PHOTO_STR = base64 }; - + var body = obj.ToJson(); var content = new StringContent(body, Encoding.UTF8, "application/json"); diff --git a/Src/Dlhis.ScheduledTask/Common/Services/Implements/SapBusinessTripService.cs b/Src/Dlhis.ScheduledTask/Common/Services/Implements/SapBusinessTripService.cs new file mode 100644 index 00000000..87d30c21 --- /dev/null +++ b/Src/Dlhis.ScheduledTask/Common/Services/Implements/SapBusinessTripService.cs @@ -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 _logger; + + public SapBusinessTripService(IJinkoJIPService jinkoJipService, IDbContext dbContext, IDevicePermissionApi devicePermissionApi, ILogger logger) + { + _jinkoJipService = jinkoJipService; + _dbContext = dbContext; + _devicePermissionApi = devicePermissionApi; + _logger = logger; + } + + /// + 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().Where(x => x.Code == tripInfoItem.Code + && x.BeginDate == tripInfoItem.BeginDate + && x.EndDate == tripInfoItem.EndDate).AnyAsync()) + { + continue; + } + + var entity = tripInfoItem.Adapt(); + entity.Status = BusinessTripStatusEnumType.Wait; + await _dbContext.InsertAsync(entity); + } + + //获取今天和昨天的出差数据 + var tripInfos = await _dbContext.Queryable() + .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() + .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().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 { 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() + .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); + } + } + } +} \ No newline at end of file diff --git a/Src/Dlhis.ScheduledTask/Jobs/SyncBusinessTripJob.cs b/Src/Dlhis.ScheduledTask/Jobs/SyncBusinessTripJob.cs index 6027d7f7..4f95110a 100644 --- a/Src/Dlhis.ScheduledTask/Jobs/SyncBusinessTripJob.cs +++ b/Src/Dlhis.ScheduledTask/Jobs/SyncBusinessTripJob.cs @@ -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.Enums; -using Dlhis.Entity.Visitor.Entity; -using Dlhis.Entity.Visitor.Enums; using Dlhis.ScheduledTask.Attributes; using Dlhis.ScheduledTask.Common.Services; -using Kurisu.AspNetCore.Utils.Extensions; -using Mapster; using SqlSugar; namespace Dlhis.ScheduledTask.Jobs; @@ -17,163 +8,23 @@ namespace Dlhis.ScheduledTask.Jobs; [RecurringJob(nameof(SyncBusinessTripJob), "0 0 1 1/1 * ? ", Name = "SAP同步出差信息")] public class SyncBusinessTripJob : BaseJob { - private readonly IDevicePermissionApi _devicePermissionApi; /// - public SyncBusinessTripJob(IServiceProvider serviceProvider, IDevicePermissionApi devicePermissionApi) : base(serviceProvider) + public SyncBusinessTripJob(IServiceProvider serviceProvider) : base(serviceProvider) { - _devicePermissionApi = devicePermissionApi; } /// protected override async Task RunAsync(IServiceProvider serviceProvider) { - var jipService = serviceProvider.GetService(); - var today = DateTime.Today; - var lastDay = today.AddDays(-1); + var sapBusinessTripService = serviceProvider.GetService(); - var departments = await DbContext.Queryable().ToListAsync(); - var tops = departments.Where(x => x.PNo == "00001000").ToList(); - var validDepartments = tops.ToList(); - tops.ForEach(x => RecursionGetNext(x, departments, validDepartments)); + var identityDbContext = DbContext.ChangeDb("identity"); + var factories = await identityDbContext.Queryable().Where(x => !SqlFunc.IsNullOrEmpty(x.PCode)).ToListAsync(); - foreach (var departmentNos in validDepartments.Select(x => x.No).Chunk(5)) + foreach (var factory in factories) { - try - { - var tripResponse = await jipService.GetTravelInfosByDepartmentsAsync(today, today, departmentNos.ToList()); - foreach (var tripInfoItem in tripResponse.Items.Where(x => x.Destination.IsPresent())) - { - if (await DbContext.Queryable().Where(x => x.Code == tripInfoItem.Code - && x.BeginDate == tripInfoItem.BeginDate - && x.EndDate == tripInfoItem.EndDate).AnyAsync()) - { - continue; - } - - var entity = tripInfoItem.Adapt(); - entity.Status = BusinessTripStatusEnumType.Wait; - await DbContext.InsertAsync(entity); - } - } - catch (Exception e) - { - Logger.LogError(e, "获取部门出差数据执行失败:{message}", e.Message); - } - } - - - //获取今天和昨天的出差数据 - var tripInfos = await DbContext.Queryable() - .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() - .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().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 { 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() - .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 data, List result) - { - var next = data.Where(x => x.PNo == current.No).ToList(); - foreach (var item in next) - { - result.Add(item); - RecursionGetNext(item, data, result); + await sapBusinessTripService.HandlerBusinessTripsByFactoryAsync(factory.Code); } } } \ No newline at end of file diff --git a/Src/Dlhis.ScheduledTask/Program.cs b/Src/Dlhis.ScheduledTask/Program.cs index de8f3289..999976ce 100644 --- a/Src/Dlhis.ScheduledTask/Program.cs +++ b/Src/Dlhis.ScheduledTask/Program.cs @@ -25,8 +25,7 @@ public class Startup : DefaultStartup public override void Configure(IApplicationBuilder app, IWebHostEnvironment env) { base.Configure(app, env); - - + var token = app.ApplicationServices.GetService().IssueToken(); } } \ No newline at end of file diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Dto/DeviceTimePeriodDto.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Dto/DeviceTimePeriodDto.cs new file mode 100644 index 00000000..0b7f3672 --- /dev/null +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Dto/DeviceTimePeriodDto.cs @@ -0,0 +1,8 @@ +using Dlhis.Entity.Device.Entities; + +namespace Dlhis.ScheduledTask.TaskAssignment.Dto; + +public class DeviceTimePeriodDto : DeviceTimePeriodEntity +{ + public string CardName { get; set; } +} \ No newline at end of file diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Dto/TaskDto.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Dto/TaskDto.cs index d9af2b3e..71044069 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Dto/TaskDto.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Dto/TaskDto.cs @@ -36,5 +36,5 @@ public class TaskDto public DeviceTaskStatusEnumType Status { get; set; } - public List TimePeriods { get; set; } + public List TimePeriods { get; set; } } \ No newline at end of file diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs index a1ce09a6..6e5f68bf 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs @@ -14,7 +14,6 @@ using Dlhis.ScheduledTask.TaskAssignment.Dto; using Kurisu.AspNetCore.CustomClass; using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions; using Kurisu.AspNetCore.DataAccess.SqlSugar.Services; -using Mapster; namespace Dlhis.ScheduledTask.TaskAssignment.Services.Implements; @@ -112,8 +111,8 @@ public class AssignmentService : IAssignmentService dto.Info = item.TimePeriods.Select(t => new TimePeriodToDeviceResponse { Id = t.CardType, - Name = t.CardType == 2 ? "行政卡" : "车间卡", - Enable = true, + Name = t.CardName, + Enable = item.EnableTimePeriod, Sections = t.Sections.Select(s => new TimePeriodWeekDaySection { DayOfWeek = s.DayOfWeek, @@ -121,7 +120,7 @@ public class AssignmentService : IAssignmentService { Enable = p.Enable, 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() }); @@ -387,8 +386,13 @@ public class AssignmentService : IAssignmentService var templateCodes = devices.Select(x => x.TemplateCode).Distinct().ToList(); var deviceCodes = devices.Select(x => x.Code).Distinct().ToList(); var settings = await _dbContext.Queryable() + .LeftJoin((x, type) => x.CardType.ToString() == type.Code && type.Type == "timeperiod") .Where(x => (x.AssignType == DeviceTimePeriodAssignEnumType.Template && templateCodes.Contains(x.Value)) || (x.AssignType == DeviceTimePeriodAssignEnumType.Device && deviceCodes.Contains(x.Value))) + .Select((x, type) => new DeviceTimePeriodDto() + { + CardName = type.Display + }, true) .ToListAsync(); diff --git a/Src/Gateway/Startup.cs b/Src/Gateway/Startup.cs index 7f462d5e..df6632a6 100644 --- a/Src/Gateway/Startup.cs +++ b/Src/Gateway/Startup.cs @@ -18,7 +18,7 @@ public class Startup services.AddEndpointsApiExplorer(); 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(); diff --git a/Src/Gateway/ocelot.Development.json b/Src/Gateway/ocelot.Development.json index 7e569f4e..e1aaacf0 100644 --- a/Src/Gateway/ocelot.Development.json +++ b/Src/Gateway/ocelot.Development.json @@ -33,17 +33,6 @@ } ] }, - { - "UpstreamPathTemplate": "/api/user/{url}", - "DownstreamPathTemplate": "/api/{url}", - "DownstreamScheme": "http", - "DownstreamHostAndPorts": [ - { - "Host": "localhost", - "Port": 5004 - } - ] - }, { "UpstreamPathTemplate": "/api/basic/{url}", "DownstreamPathTemplate": "/api/{url}", diff --git a/Src/Gateway/ocelot.json b/Src/Gateway/ocelot.json index 26b30a73..1134886a 100644 --- a/Src/Gateway/ocelot.json +++ b/Src/Gateway/ocelot.json @@ -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}", "DownstreamPathTemplate": "/api/{url}",