diff --git a/Src/Dlhis.Basic/BusinessPlace/Controllers/BusinessPlacesController.cs b/Src/Dlhis.Basic/BusinessPlace/Controllers/BusinessPlacesController.cs index 9649c414..44ada252 100644 --- a/Src/Dlhis.Basic/BusinessPlace/Controllers/BusinessPlacesController.cs +++ b/Src/Dlhis.Basic/BusinessPlace/Controllers/BusinessPlacesController.cs @@ -58,6 +58,17 @@ public class BusinessPlacesController : ControllerBase await _businessPlaceService.SaveAsync(request); } + /// + /// 营业点保存餐次 + /// + /// + /// + [HttpPost("shift/save")] + public async Task SaveShiftAsync(BusinessPlaceSaveShiftRequest request) + { + await _businessPlaceService.SaveShiftAsync(request); + } + /// /// 根据手工号获取餐别 /// diff --git a/Src/Dlhis.Basic/BusinessPlace/Request/BusinessPlaceSaveShiftRequest.cs b/Src/Dlhis.Basic/BusinessPlace/Request/BusinessPlaceSaveShiftRequest.cs new file mode 100644 index 00000000..23fc1140 --- /dev/null +++ b/Src/Dlhis.Basic/BusinessPlace/Request/BusinessPlaceSaveShiftRequest.cs @@ -0,0 +1,14 @@ +namespace Dlhis.Basic.BusinessPlace.Request; + +public class BusinessPlaceSaveShiftRequest +{ + /// + /// 营业点id + /// + public long Id { get; set; } + + /// + /// 餐次code + /// + public Guid ShiftCode { get; set; } +} diff --git a/Src/Dlhis.Basic/BusinessPlace/Services/IBusinessPlaceService.cs b/Src/Dlhis.Basic/BusinessPlace/Services/IBusinessPlaceService.cs index e012ce37..2ada296c 100644 --- a/Src/Dlhis.Basic/BusinessPlace/Services/IBusinessPlaceService.cs +++ b/Src/Dlhis.Basic/BusinessPlace/Services/IBusinessPlaceService.cs @@ -1,12 +1,16 @@ using Dlhis.Basic.BusinessPlace.Request; using Dlhis.Basic.BusinessPlace.Response; using Kurisu.Core.DataAccess.Dto; -using Kurisu.SqlSugar.Attributes; namespace Dlhis.Basic.BusinessPlace.Services; public interface IBusinessPlaceService : IScopeDependency { + /// + /// 营业点分页 + /// + /// + /// Task> GetPageAsync(BusinessPlacePageRequest request); /// @@ -15,6 +19,17 @@ public interface IBusinessPlaceService : IScopeDependency /// Task> GetOpenedListAsync(); - + /// + /// 保存营业点 + /// + /// + /// Task SaveAsync(BusinessPlaceSaveRequest request); + + /// + /// 营业点保存餐次 + /// + /// + /// + Task SaveShiftAsync(BusinessPlaceSaveShiftRequest request); } diff --git a/Src/Dlhis.Basic/BusinessPlace/Services/Implements/BusinessPlaceService.cs b/Src/Dlhis.Basic/BusinessPlace/Services/Implements/BusinessPlaceService.cs index 6e60570a..66fe18e8 100644 --- a/Src/Dlhis.Basic/BusinessPlace/Services/Implements/BusinessPlaceService.cs +++ b/Src/Dlhis.Basic/BusinessPlace/Services/Implements/BusinessPlaceService.cs @@ -22,46 +22,68 @@ public class BusinessPlaceService : IBusinessPlaceService public async Task> GetPageAsync(BusinessPlacePageRequest request) { - var page = await _dbContext.Queryable() + var page = await _dbContext.Queryable() .WhereIF(request.Search.IsPresent(), x => x.CustomCode.Contains(request.Search)) .WhereIF(request.Catalog.HasValue, x => x.Catalog == request.Catalog) .WhereIF(request.Status.HasValue, x => x.Status == request.Status) .WhereIF(request.Source.HasValue, x => x.Source == request.Source) .Select() .ToPageListAsync(request); - + return page; } public async Task> GetOpenedListAsync() { - return await _dbContext.Queryable() + return await _dbContext.Queryable() .Where(x => x.Status == CanteenBusinessPlaceStatusEnumType.Opened) .Select() .ToListAsync(); } - + public async Task SaveAsync(BusinessPlaceSaveRequest request) { await CheckExistsCustomCodeAsync(request); if (!request.Id.HasValue) { - var entity = request.Adapt(); + var entity = request.Adapt(); entity.Code = Guid.NewGuid(); await _dbContext.InsertAsync(entity); } else { - var entity = await _dbContext.Queryable().FirstAsync(x => x.Id == request.Id); + var entity = await _dbContext.Queryable().FirstAsync(x => x.Id == request.Id); request.Adapt(entity); await _dbContext.UpdateAsync(entity); } } + + public async Task SaveShiftAsync(BusinessPlaceSaveShiftRequest request) + { + var place = await _dbContext.Queryable().Where(x => x.Id == request.Id).FirstAsync(); + place.ThrowIfNull("营业点不存在"); + + var relationship = await _dbContext.Queryable().Where(x => x.PlaceCode == place.Code).FirstAsync(); + if (relationship == null) + { + await _dbContext.InsertAsync(new BusinessPlaceShiftRelationshipEntity + { + PlaceCode = place.Code, + ShiftCode = request.ShiftCode, + }); + } + else + { + relationship.ShiftCode = request.ShiftCode; + await _dbContext.UpdateAsync(relationship); + } + } + //*********************************************** help methods ***************************************************// /// @@ -71,7 +93,7 @@ public class BusinessPlaceService : IBusinessPlaceService /// private async Task CheckExistsCustomCodeAsync(BusinessPlaceSaveRequest request) { - var existsSameCustomCode = await _dbContext.Queryable() + var existsSameCustomCode = await _dbContext.Queryable() .Where(x => x.CustomCode == request.CustomCode) .WhereIF(request.Id.HasValue, x => x.Id != request.Id) .AnyAsync(); diff --git a/Src/Dlhis.Basic/BusinessShift/Controllers/BusinessShiftsController.cs b/Src/Dlhis.Basic/BusinessShift/Controllers/BusinessShiftsController.cs index 154bb984..6ec9592c 100644 --- a/Src/Dlhis.Basic/BusinessShift/Controllers/BusinessShiftsController.cs +++ b/Src/Dlhis.Basic/BusinessShift/Controllers/BusinessShiftsController.cs @@ -33,6 +33,16 @@ public class BusinessShiftsController : ControllerBase return await _businessPlaceShiftService.GetPageAsync(request); } + /// + /// 餐次列表 + /// + /// + [HttpGet("list")] + public async Task> GetListAsync() + { + return await _businessPlaceShiftService.GetListAsync(); + } + /// /// 餐次保存 /// diff --git a/Src/Dlhis.Basic/BusinessShift/Request/BusinessPlaceShiftPageRequest.cs b/Src/Dlhis.Basic/BusinessShift/Request/BusinessPlaceShiftPageRequest.cs index ed518c13..5ed2e3c2 100644 --- a/Src/Dlhis.Basic/BusinessShift/Request/BusinessPlaceShiftPageRequest.cs +++ b/Src/Dlhis.Basic/BusinessShift/Request/BusinessPlaceShiftPageRequest.cs @@ -4,5 +4,5 @@ namespace Dlhis.Basic.BusinessShift.Request; public class BusinessPlaceShiftPageRequest : PageDto { - public Guid? BusinessPlaceCode { get; set; } + } diff --git a/Src/Dlhis.Basic/BusinessShift/Request/BusinessPlaceShiftSaveMealShiftRequest.cs b/Src/Dlhis.Basic/BusinessShift/Request/BusinessPlaceShiftSaveMealShiftRequest.cs new file mode 100644 index 00000000..98e63fae --- /dev/null +++ b/Src/Dlhis.Basic/BusinessShift/Request/BusinessPlaceShiftSaveMealShiftRequest.cs @@ -0,0 +1,38 @@ +using System.ComponentModel.DataAnnotations; +using Kurisu.Core.CustomClass; + +namespace Dlhis.Basic.BusinessShift.Request; + +public class BusinessPlaceShiftSaveMealShiftRequest : IValidatableObject +{ + public long? Id { get; set; } + + /// + /// 餐次Code + /// + public Guid ShiftCode { get; set; } + + /// + /// mealshift + /// + public string ShiftType { get; set; } + + /// + /// 序号 + /// + public int Sequence { get; set; } = 100; + + /// + /// 时间段 + /// + public TimePeriod TimePeriod { get; set; } + + + public IEnumerable Validate(ValidationContext validationContext) + { + if (TimePeriod.Start == TimePeriod.End) + { + yield return new ValidationResult("时间段设置区间有误,开始时段不能等于结束时段.", new[] { nameof(TimePeriod) }); + } + } +} diff --git a/Src/Dlhis.Basic/BusinessShift/Request/BusinessPlaceShiftSaveRequest.cs b/Src/Dlhis.Basic/BusinessShift/Request/BusinessPlaceShiftSaveRequest.cs index 8353c298..82f1c25c 100644 --- a/Src/Dlhis.Basic/BusinessShift/Request/BusinessPlaceShiftSaveRequest.cs +++ b/Src/Dlhis.Basic/BusinessShift/Request/BusinessPlaceShiftSaveRequest.cs @@ -1,39 +1,20 @@ using System.ComponentModel.DataAnnotations; -using Kurisu.Core.CustomClass; namespace Dlhis.Basic.BusinessShift.Request; -public class BusinessPlaceShiftSaveRequest : IValidatableObject +public class BusinessPlaceShiftSaveRequest { public long? Id { get; set; } - /// - /// 营业点代号 - /// - [Required(ErrorMessage = "营业点不能为空")] - public Guid BusinessPlaceCode { get; set; } - /// /// 自定义代号 mealshift /// - [Required(ErrorMessage = "餐次编号不能为空")] + [Required(ErrorMessage = "餐次手工号不能为空")] public string CustomCode { get; set; } /// - /// 序号 + /// 餐次名称 /// - public int Sequence { get; set; } = 100; - - /// - /// 时间段 - /// - public TimePeriod TimePeriod { get; set; } - - public IEnumerable Validate(ValidationContext validationContext) - { - if (TimePeriod.Start == TimePeriod.End) - { - yield return new ValidationResult("时间段设置区间有误,开始时段不能等于结束时段.", new[] { nameof(TimePeriod) }); - } - } + [Required(ErrorMessage = "餐次名称")] + public string Name { get; set; } } diff --git a/Src/Dlhis.Basic/BusinessShift/Response/BusinessPlaceShiftResponse.cs b/Src/Dlhis.Basic/BusinessShift/Response/BusinessPlaceShiftResponse.cs index 5c6848a6..f0a9d504 100644 --- a/Src/Dlhis.Basic/BusinessShift/Response/BusinessPlaceShiftResponse.cs +++ b/Src/Dlhis.Basic/BusinessShift/Response/BusinessPlaceShiftResponse.cs @@ -4,21 +4,6 @@ public class BusinessPlaceShiftResponse { public long Id { get; set; } - /// - /// 营业点代号 - /// - public Guid BusinessPlaceCode { get; set; } - - /// - /// 营业点手工号 - /// - public string BusinessPlaceCustomCode { get; set; } - - /// - /// 营业点 - /// - public string BusinessPlace { get; set; } - /// /// 代号 /// @@ -33,14 +18,4 @@ public class BusinessPlaceShiftResponse /// 餐次名称 /// public string Name { get; set; } - - /// - /// 经营开始时间 - /// - public TimeOnly Start { get; set; } - - /// - /// 经营结束时间 - /// - public TimeOnly End { get; set; } } diff --git a/Src/Dlhis.Basic/BusinessShift/Response/BusinessPlaceShiftTinyResponse.cs b/Src/Dlhis.Basic/BusinessShift/Response/BusinessPlaceShiftTinyResponse.cs index cf2576ab..1e01e9db 100644 --- a/Src/Dlhis.Basic/BusinessShift/Response/BusinessPlaceShiftTinyResponse.cs +++ b/Src/Dlhis.Basic/BusinessShift/Response/BusinessPlaceShiftTinyResponse.cs @@ -2,11 +2,6 @@ public class BusinessPlaceShiftTinyResponse { - /// - /// 自定义代号 - /// - public string CustomCode { get; set; } - /// /// 餐次名称 /// diff --git a/Src/Dlhis.Basic/BusinessShift/Services/IBusinessPlaceShiftService.cs b/Src/Dlhis.Basic/BusinessShift/Services/IBusinessPlaceShiftService.cs index 3993951a..694c7948 100644 --- a/Src/Dlhis.Basic/BusinessShift/Services/IBusinessPlaceShiftService.cs +++ b/Src/Dlhis.Basic/BusinessShift/Services/IBusinessPlaceShiftService.cs @@ -9,7 +9,11 @@ public interface IBusinessPlaceShiftService : IScopeDependency { Task> GetPageAsync(BusinessPlaceShiftPageRequest request); + Task> GetListAsync(); + Task SaveAsync(BusinessPlaceShiftSaveRequest request); + Task SaveMealShiftsAsync(List requests); + Task GetShiftsByPlaceCustomCodeAsync(string placeCustomCode); } diff --git a/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs b/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs index aa263e38..941378eb 100644 --- a/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs +++ b/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs @@ -11,6 +11,7 @@ using Kurisu.SqlSugar.Attributes; using Kurisu.SqlSugar.Extensions; using Kurisu.SqlSugar.Services; using Mapster; +using Org.BouncyCastle.Asn1.Ocsp; namespace Dlhis.Basic.BusinessShift.Services.Implements; @@ -27,58 +28,81 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService public async Task> GetPageAsync(BusinessPlaceShiftPageRequest request) { - var page = await _dbContext.Queryable() - .LeftJoin((shift, place) => shift.BusinessPlaceCode == place.Code) - .LeftJoin((shift, place, type) => shift.Code.ToString() == type.Code) - .WhereIF(request.Search.IsPresent(), (shift, place) => shift.CustomCode.Contains(request.Search)) - .WhereIF(request.BusinessPlaceCode.HasValue, (shift, place) => shift.BusinessPlaceCode == request.BusinessPlaceCode) - .Select((shift, place, type) => new BusinessPlaceShiftResponse - { - Id = shift.Id, - BusinessPlaceCode = place.Code, - BusinessPlaceCustomCode = place.CustomCode, - BusinessPlace = place.Name, - Code = shift.Code, - CustomCode = shift.CustomCode, - Name = type.Display, - Start = shift.Start, - End = shift.End - }) + var page = await _dbContext.Queryable() + .WhereIF(request.Search.IsPresent(), (shift) => shift.CustomCode.Contains(request.Search) || shift.Name.Contains(request.Search)) + .Select() .ToPageListAsync(request); return page; } + public async Task> GetListAsync() + { + var result = await _dbContext.Queryable() + .Select().ToListAsync(); + + return result; + } + public async Task SaveAsync(BusinessPlaceShiftSaveRequest request) { - await CheckExistsCustomCodeAsync(request); - await DuplicateTimePeriodAsync(request); - await CheckPlaceExistsAsync(request.BusinessPlaceCode); - + await CheckExistsAsync(request); if (!request.Id.HasValue) { - var entity = request.Adapt(); + var entity = request.Adapt(); entity.Code = Guid.NewGuid(); - entity.Start = request.TimePeriod.Start.Value; - entity.End = request.TimePeriod.End.Value; - await _dbContext.InsertAsync(entity); } else { - var entity = await _dbContext.Queryable().FirstAsync(x => x.Id == request.Id); - entity.Adapt(request); + var entity = await _dbContext.Queryable().FirstAsync(x => x.Id == request.Id); + entity.ThrowIfNull("餐次不存在"); + request.Adapt(entity); await _dbContext.UpdateAsync(entity); } } + [Transactional] + public async Task SaveMealShiftsAsync(List requests) + { + var mealShifts = await GetMealShiftAsync(); + + foreach (var request in requests) + { + var shift = await CheckExistsShiftAsync(request.ShiftCode); + await CheckExistsMealShiftAsync(request); + await DuplicateTimePeriodAsync(request); + mealShifts.Contains(request.ShiftType).ThrowIfFalse($"{request.ShiftType}不存在"); + + if (!request.Id.HasValue) + { + var entity = request.Adapt(); + + entity.ShiftCode = shift.Code; + entity.ShiftCustomCode = shift.CustomCode; + entity.Start = request.TimePeriod.Start.Value; + entity.End = request.TimePeriod.End.Value; + + await _dbContext.InsertAsync(entity); + } + else + { + var entity = await _dbContext.Queryable().FirstAsync(x => x.Id == request.Id); + entity.ThrowIfNull("餐次不存在"); + + request.Adapt(entity); + await _dbContext.UpdateAsync(entity); + } + } + } + [IgnoreTenant] public async Task GetShiftsByPlaceCustomCodeAsync(string placeCustomCode) { - var place = await _dbContext.Queryable().Where(x => x.CustomCode == placeCustomCode).FirstAsync(); + var place = await _dbContext.Queryable().Where(x => x.CustomCode == placeCustomCode).FirstAsync(); if (place == null) { return new BusinessPlaceWithShiftResponse() @@ -87,8 +111,17 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService }; } - var shifts = await _dbContext.Queryable() - .Where(x => x.BusinessPlaceCode == place.Code) + var relationship = await _dbContext.Queryable().Where(x => x.PlaceCode == place.Code).FirstAsync(); + if (relationship == null) + { + return new BusinessPlaceWithShiftResponse() + { + Shifts = new List() + }; + } + + var shifts = await _dbContext.Queryable() + .Where(x => x.ShiftCode == relationship.ShiftCode) .OrderBy(x => x.Sequence) //排序 .ToListAsync(); @@ -97,15 +130,15 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService var tenantInfo = tenantResult.Data; var list = new List(); - foreach (CanteenBusinessShiftEntity shiftinfo in shifts) + foreach (BusinessShiftMealRelationshipEntity shiftinfo in shifts) { var name = _dbContext.Queryable() - .Where(x => x.Code == shiftinfo.CustomCode.ToString()) + .Where(x => x.Code == shiftinfo.ShiftType.ToString()) .Select(x => x.Display) .First(); + var shift = new BusinessPlaceShiftTinyResponse { - CustomCode = shiftinfo.CustomCode, Name = name, Start = shiftinfo.Start, End = shiftinfo.End @@ -122,24 +155,18 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService }; } + //*********************************************** help methods ***************************************************// - - private async Task CheckPlaceExistsAsync(Guid code) - { - var existsPlace = await _dbContext.Queryable().AnyAsync(x => x.Code == code); - existsPlace.ThrowIfFalse("营业点不存在,请检查."); - } - /// /// 时间段重合检查 /// /// /// - private async Task DuplicateTimePeriodAsync(BusinessPlaceShiftSaveRequest request) + private async Task DuplicateTimePeriodAsync(BusinessPlaceShiftSaveMealShiftRequest request) { - var periods = await _dbContext.Queryable() - .Where(x => x.BusinessPlaceCode == request.BusinessPlaceCode) + var periods = await _dbContext.Queryable() + .Where(x => x.ShiftCode == request.ShiftCode) .WhereIF(request.Id.HasValue, x => x.Id != request.Id) .Select(x => new TimePeriod { @@ -156,18 +183,41 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService /// - /// 检查重复手工号 + /// 检查重复 /// /// /// - private async Task CheckExistsCustomCodeAsync(BusinessPlaceShiftSaveRequest request) + private async Task CheckExistsAsync(BusinessPlaceShiftSaveRequest request) { - var existsSameCustomCode = await _dbContext.Queryable() - .Where(x => x.CustomCode == request.CustomCode) + var existsSameCustomCode = await _dbContext.Queryable() + .Where(x => x.CustomCode == request.CustomCode || x.Name == request.Name) .WhereIF(request.Id.HasValue, x => x.Id != request.Id) .AnyAsync(); - existsSameCustomCode.ThrowIfTrue($"自定义手工号[{request.CustomCode}]存在重复,请检查."); + existsSameCustomCode.ThrowIfTrue($"自定义手工号或者名称存在重复,请检查."); } + private async Task CheckExistsShiftAsync(Guid shiftCode) + { + var shift = await _dbContext.Queryable().Where(x => x.Code == shiftCode).FirstAsync(); + shift.ThrowIfNull("餐次不存在"); + + return shift; + } + + private async Task> GetMealShiftAsync() + { + return await _dbContext.Queryable().Where(x => x.Type == "mealshift").Select(x => x.Code).ToListAsync(); + } + + private async Task CheckExistsMealShiftAsync(BusinessPlaceShiftSaveMealShiftRequest request) + { + var exists = await _dbContext.Queryable() + .Where(x => x.ShiftCode == request.ShiftCode) + .Where(x => x.ShiftType == request.ShiftType) + .WhereIF(request.Id.HasValue, x => x.Id != request.Id) + .AnyAsync(); + + exists.ThrowIfTrue("重复设置!"); + } } diff --git a/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs b/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs index ad89e286..63a9d64c 100644 --- a/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs +++ b/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs @@ -4,7 +4,6 @@ using Dlhis.Basic.Device.Services; using Kurisu.Core.DataAccess.Dto; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Org.BouncyCastle.Asn1.Ocsp; namespace Dlhis.Basic.Device.Controllers; diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceConnectService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceConnectService.cs index e507e5e5..7dee0250 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceConnectService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceConnectService.cs @@ -23,7 +23,7 @@ public class DeviceConnectService : IDeviceConnectService [IgnoreTenant] public async Task ResigterAsync(DeviceResigterRequest request) { - var businessPlace = await _dbContext.Queryable().Where(x => x.CustomCode == request.BusinessCustomCode).FirstAsync(); + var businessPlace = await _dbContext.Queryable().Where(x => x.CustomCode == request.BusinessCustomCode).FirstAsync(); businessPlace.ThrowIfNull("营业点不存在"); var device = await GetEnableDeviceAsync(request.UniqueNo, false, request.DeployPlace, businessPlace.TenantId); @@ -71,7 +71,7 @@ public class DeviceConnectService : IDeviceConnectService var registry = await _dbContext.Queryable().Where(x => x.DeviceUniqueNo == request.UniqueNo).FirstAsync(); registry.ThrowIfNull($"{request.UniqueNo}的设备注册信息不存在,无法设置营业点"); - var businessPlace = await _dbContext.Queryable().Where(x => x.Code == request.BusinessPlaceCode).FirstAsync(); + var businessPlace = await _dbContext.Queryable().Where(x => x.Code == request.BusinessPlaceCode).FirstAsync(); businessPlace.ThrowIfNull("营业点不存在,无法设置到设备注册信息中"); //更新营业点信息 diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs index 3047a115..a8dfee90 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs @@ -65,7 +65,6 @@ public class DeviceGroupService : IDeviceGroupService { var entity = await _dbContext.Queryable().Where(x => x.Id == request.Id).FirstAsync(); entity.ThrowIfNull("设备组不存在,无法更新"); - entity.Editable.ThrowIfFalse("不可编辑当前组"); var nextDevices = await GetDevicesAsync(entity.Code); @@ -78,6 +77,7 @@ public class DeviceGroupService : IDeviceGroupService (request.Type.HasValue && request.Type != entity.Type && nextDevices.Any()).ThrowIfTrue("分组设备类型不匹配,无法修改类型"); } + request.Adapt(entity); await _dbContext.UpdateAsync(entity); } } @@ -106,7 +106,6 @@ public class DeviceGroupService : IDeviceGroupService var relationships = await _dbContext.Queryable().Where(x => x.GroupCode == request.GroupCode).ToListAsync(); await _dbContext.DeleteAsync(relationships); - var entities = request.DeviceCodes.Select(x => new DeviceGroupRelationshipEntity { GroupCode = request.GroupCode, diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs index e0c3d564..3aee41b7 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs @@ -9,7 +9,6 @@ using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Core.DataAccess.Dto; using Kurisu.SqlSugar.Attributes; using Kurisu.SqlSugar.Services; -using System.Collections.Generic; namespace Dlhis.Basic.Device.Services.Implements; diff --git a/Src/Dlhis.Basic/Organization/Controllers/GainfoGroupsController.cs b/Src/Dlhis.Basic/Organization/Controllers/GainfoGroupsController.cs index b578cf1a..42e765ba 100644 --- a/Src/Dlhis.Basic/Organization/Controllers/GainfoGroupsController.cs +++ b/Src/Dlhis.Basic/Organization/Controllers/GainfoGroupsController.cs @@ -50,7 +50,7 @@ public class GainfoGroupsController : ControllerBase /// /// /// - [HttpPost] + [HttpPost("save")] public async Task SaveAsync(GainfoGroupSaveRequest request) { await _gainfoGroupService.SaveAsync(request); diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs index 063353ca..59e76cd1 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs @@ -37,8 +37,8 @@ public class BalanceService : IBalanceService var page = await _dbContext.Queryable() .LeftJoin((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, bshift) => record.BusinessShiftCode == bshift.Code) + .LeftJoin((record, ga, department, bplace) => record.BusinessPlaceCode == bplace.Code) + .LeftJoin((record, ga, department, bplace, bshift) => record.BusinessShiftCode == bshift.Code) .LeftJoin((record, ga, department, bplace, bshift, type) => record.BusinessShiftCode.ToString() == type.Code) .WhereIF(request.SearchDateTimePeriod?.Start.HasValue == true, record => record.CostDate >= request.SearchDateTimePeriod.Start) .WhereIF(request.SearchDateTimePeriod?.End.HasValue == true, record => record.CostDate <= request.SearchDateTimePeriod.End) @@ -160,8 +160,8 @@ public class BalanceService : IBalanceService { var paeginfo = await _dbContext.Queryable() .LeftJoin((record, department) => record.DepartmentNo == department.No) - .LeftJoin((record, department, bplace) => record.BusinessPlaceCode == bplace.Code) - .LeftJoin((record, department, bplace, bshift) => record.BusinessShiftCode == bshift.Code) + .LeftJoin((record, department, bplace) => record.BusinessPlaceCode == bplace.Code) + .LeftJoin((record, department, bplace, bshift) => record.BusinessShiftCode == bshift.Code) .LeftJoin((record, department, bplace, bshift, type) => record.BusinessShiftCode.ToString() == type.Code) .WhereIF(!request.Name.IsEmpty(), record => record.Name == request.Name) .WhereIF(!request.DepartmentNo.IsEmpty(), record => record.DepartmentNo == request.DepartmentNo) @@ -436,8 +436,8 @@ public class BalanceService : IBalanceService var page = await _dbContext.Queryable() .LeftJoin((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, bshift) => record.BusinessShiftCode == bshift.Code) + .LeftJoin((record, ga, department, bplace) => record.BusinessPlaceCode == bplace.Code) + .LeftJoin((record, ga, department, bplace, bshift) => record.BusinessShiftCode == bshift.Code) .LeftJoin((record, ga, department, bplace, bshift, type) => record.BusinessShiftCode.ToString() == type.Code) .WhereIF(request.SearchDate.HasValue, record => record.CostDate >= start) .WhereIF(request.SearchDate.HasValue, record => record.CostDate <= end) @@ -492,8 +492,8 @@ public class BalanceService : IBalanceService var page = await _dbContext.Queryable() .LeftJoin((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, bshift) => record.BusinessShiftCode == bshift.Code) + .LeftJoin((record, ga, department, bplace) => record.BusinessPlaceCode == bplace.Code) + .LeftJoin((record, ga, department, bplace, bshift) => record.BusinessShiftCode == bshift.Code) .LeftJoin((record, ga, department, bplace, bshift, type) => record.BusinessShiftCode.ToString() == type.Code) .WhereIF(request.SearchDateTimePeriod?.Start.HasValue == true, record => record.CostDate >= request.SearchDateTimePeriod.Start) .WhereIF(request.SearchDateTimePeriod?.End.HasValue == true, record => record.CostDate <= request.SearchDateTimePeriod.End) @@ -557,7 +557,7 @@ public class BalanceService : IBalanceService var offCount = devices.Where(x => x.Enable == false).Count(); - var places = await _dbContext.Queryable() + var places = await _dbContext.Queryable() .ToListAsync(); var time = DateTime.Now.ToString("yyyy-MM-dd"); @@ -740,7 +740,7 @@ public class BalanceService : IBalanceService { var shiftCodeDict = new Dictionary(); - var shifts = await _dbContext.Queryable().ToListAsync(); + var shifts = await _dbContext.Queryable().ToListAsync(); //guid var breakfastCode = shifts.Where(x => x.CustomCode == "shift-breakfast").Select(x => x.Code).First().ToString(); diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs index baa80576..c16de272 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs @@ -6,7 +6,6 @@ using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Canteen.Entities; using Dlhis.Entity.Canteen.Enums; using Dlhis.Entity.Device.Entities; -using Dlhis.Entity.Sys.Entities; using Kurisu.AspNetCore.UnifyResultAndValidation; using Kurisu.AspNetCore.Utils; using Kurisu.AspNetCore.Utils.Extensions; @@ -66,10 +65,10 @@ public class OrderService : IOrderService } else { - _ = long.TryParse(request.UserUniqueNo, out userId); + _ = long.TryParse(request.UserUniqueNo, out userId); } var gainfo = await _dbContext.Queryable() - .Where(x => x.No == request.UserUniqueNo || x.Code == request.UserUniqueNo || x.Id == userId|| x.CardNo == card) + .Where(x => x.No == request.UserUniqueNo || x.Code == request.UserUniqueNo || x.Id == userId || x.CardNo == card) .FirstAsync(); @@ -134,11 +133,20 @@ public class OrderService : IOrderService device.ThrowIfNull("设备不存在或者尚未启用"); var registry = await _dbContext.Queryable().Where(x => x.DeviceUniqueNo == request.DeviceUniqueNo).FirstAsync(); registry.ThrowIfNull("设备尚未注册"); - var businessPlace = await _dbContext.Queryable().Where(x => x.Code == registry.BusinessPlaceCode).FirstAsync(); - businessPlace.ThrowIfNull("营业点尚未设置"); + var businessPlaceInfo = await _dbContext.Queryable() + .LeftJoin((x, sr) => x.Code == sr.PlaceCode) + .Where(x => x.Code == registry.BusinessPlaceCode) + .Select((x, sr) => new + { + x.Code, + sr.ShiftCode, + x.TenantId + }) + .FirstAsync(); + businessPlaceInfo.ThrowIfNull("营业点尚未设置"); //获取当前消费餐次 - var shifts = await _dbContext.Queryable().Where(x => x.BusinessPlaceCode == businessPlace.Code).ToListAsync(); + var shifts = await _dbContext.Queryable().Where(x => x.ShiftCode == businessPlaceInfo.ShiftCode).ToListAsync(); var shift = shifts.FirstOrDefault(x => new TimePeriod() { @@ -184,8 +192,9 @@ public class OrderService : IOrderService UserNo = gainfo.No, UserCode = gainfo.Code, Amount = request.Amount, - BusinessPlaceCode = businessPlace.Code, - BusinessShiftCode = shift?.Code, + BusinessPlaceCode = businessPlaceInfo.Code, + BusinessShiftCode = shift?.ShiftCode, + ShiftType = shift?.ShiftType, CostDate = costDate.Date, CostId = gainfo.CostId, DepartmentNo = gainfo.DepartmentNo, @@ -206,7 +215,7 @@ public class OrderService : IOrderService CostDateTime = request.CostDateTime, //标识当前消费的基地 - TenantId = businessPlace.TenantId, + TenantId = businessPlaceInfo.TenantId, }; var orderId = await _dbContext.InsertReturnIdentityAsync(order); @@ -364,7 +373,7 @@ public class OrderService : IOrderService /// /// /// - private async Task Verify(Dictionary settings, List shifts, DateTime costDateTime, CanteenOrderEntity order) + private async Task Verify(Dictionary settings, List shifts, DateTime costDateTime, CanteenOrderEntity order) { //在线 if (!order.IsOffline) @@ -388,7 +397,7 @@ public class OrderService : IOrderService var dayMarketCostMax = GetSetting(settings, CanteenSettingItemEnumType.DayMarketCostMax); if (dayMarketCostMax != default) { - var businessPlaceCodes = await _dbContext.Queryable() + var businessPlaceCodes = await _dbContext.Queryable() .Where(x => x.Catalog == CanteenBusinessPlaceCatalogEnumType.Supermarket) .Select(x => x.Code).ToListAsync(); @@ -473,7 +482,7 @@ public class OrderService : IOrderService /// /// /// - private async Task GenerateConsumeRecordAsync(long orderId, Dictionary settings, List shifts, DateTime costDateTime) + private async Task GenerateConsumeRecordAsync(long orderId, Dictionary settings, List shifts, DateTime costDateTime) { var order = await _dbContext.Queryable().Where(x => x.Id == orderId).FirstAsync(); //校验 diff --git a/Src/Dlhis.Entity/Basic/Entity/CanteenBusinessPlaceEntity.cs b/Src/Dlhis.Entity/Basic/Entity/BusinessPlaceEntity.cs similarity index 91% rename from Src/Dlhis.Entity/Basic/Entity/CanteenBusinessPlaceEntity.cs rename to Src/Dlhis.Entity/Basic/Entity/BusinessPlaceEntity.cs index 8af87c99..866f030a 100644 --- a/Src/Dlhis.Entity/Basic/Entity/CanteenBusinessPlaceEntity.cs +++ b/Src/Dlhis.Entity/Basic/Entity/BusinessPlaceEntity.cs @@ -9,8 +9,8 @@ namespace Dlhis.Entity.Basic.Entity; /// /// 营业点 /// -[SugarTable(TableName = "CanteenBusinessPlace", TableDescription = "营业点")] -public class CanteenBusinessPlaceEntity : SugarBaseEntity, ITenantId +[SugarTable(TableName = "BusinessPlace", TableDescription = "营业点")] +public class BusinessPlaceEntity : SugarBaseEntity, ITenantId { /// /// 代号 diff --git a/Src/Dlhis.Entity/Basic/Entity/BusinessPlaceShiftRelationshipEntity.cs b/Src/Dlhis.Entity/Basic/Entity/BusinessPlaceShiftRelationshipEntity.cs new file mode 100644 index 00000000..b4419ca8 --- /dev/null +++ b/Src/Dlhis.Entity/Basic/Entity/BusinessPlaceShiftRelationshipEntity.cs @@ -0,0 +1,18 @@ +using Kurisu.Core.DataAccess.Entity; +using Kurisu.SqlSugar; +using SqlSugar; + +namespace Dlhis.Entity.Basic.Entity; + +[SugarTable(TableName = "BusinessPlaceShiftRelationship", TableDescription = "营业点餐次关系")] +public class BusinessPlaceShiftRelationshipEntity : SugarBaseEntity, ITenantId +{ + [SugarColumn(ColumnDescription = "营业点code")] + public Guid PlaceCode { get; set; } + + + [SugarColumn(ColumnDescription = "餐次code")] + public Guid ShiftCode { get; set; } + + public string TenantId { get; set; } +} diff --git a/Src/Dlhis.Entity/Basic/Entity/BusinessShiftEntity.cs b/Src/Dlhis.Entity/Basic/Entity/BusinessShiftEntity.cs new file mode 100644 index 00000000..9893a6c6 --- /dev/null +++ b/Src/Dlhis.Entity/Basic/Entity/BusinessShiftEntity.cs @@ -0,0 +1,32 @@ +using Kurisu.Core.DataAccess.Entity; +using Kurisu.SqlSugar; +using SqlSugar; + +namespace Dlhis.Entity.Basic.Entity; + +/// +/// 营业点餐次 +/// +[SugarTable(TableName = "BusinessShift", TableDescription = "营业点餐次")] +public class BusinessShiftEntity : SugarBaseEntity, ITenantId +{ + /// + /// 代号 + /// + [SugarColumn(ColumnDescription = "code")] + public Guid Code { get; set; } + + /// + /// 自定义代号 + /// + [SugarColumn(ColumnDescription = "自定义手工号")] + public string CustomCode { get; set; } + + /// + /// 餐次名称 + /// + [SugarColumn(ColumnDescription = "餐次名称")] + public string Name { get; set; } + + public string TenantId { get; set; } +} \ No newline at end of file diff --git a/Src/Dlhis.Entity/Basic/Entity/CanteenBusinessShiftEntity.cs b/Src/Dlhis.Entity/Basic/Entity/BusinessShiftMealRelationshipEntity.cs similarity index 50% rename from Src/Dlhis.Entity/Basic/Entity/CanteenBusinessShiftEntity.cs rename to Src/Dlhis.Entity/Basic/Entity/BusinessShiftMealRelationshipEntity.cs index be1316ee..6172c059 100644 --- a/Src/Dlhis.Entity/Basic/Entity/CanteenBusinessShiftEntity.cs +++ b/Src/Dlhis.Entity/Basic/Entity/BusinessShiftMealRelationshipEntity.cs @@ -4,29 +4,26 @@ using SqlSugar; namespace Dlhis.Entity.Basic.Entity; -/// -/// 营业点餐次 -/// -[SugarTable(TableName = "CanteenBusinessShift", TableDescription = "营业点餐次")] -public class CanteenBusinessShiftEntity : SugarBaseEntity, ITenantId +[SugarTable(TableName = "BusinessShiftMealRelationship", TableDescription = "营业点餐次组合")] +public class BusinessShiftMealRelationshipEntity : SugarBaseEntity, ITenantId { /// - /// 营业点代号 + /// 餐次组合Code /// - [SugarColumn(ColumnDescription = "营业点code")] - public Guid BusinessPlaceCode { get; set; } + [SugarColumn(ColumnDescription = "餐次组合Code", UniqueGroupNameList = new[] { "idx_CanteenBusinessShiftRelationship_shiftcode_shifttype" })] + public Guid ShiftCode { get; set; } /// - /// 代号 + /// 餐次组合手工号 /// - [SugarColumn(ColumnDescription = "code")] - public Guid Code { get; set; } + [SugarColumn(ColumnDescription = "餐次组合手工号")] + public string ShiftCustomCode { get; set; } /// - /// 自定义代号 + /// 餐次 /// - [SugarColumn(ColumnDescription = "自定义手工号")] - public string CustomCode { get; set; } + [SugarColumn(ColumnDescription = "餐次", UniqueGroupNameList = new[] { "idx_CanteenBusinessShiftRelationship_shiftcode_shifttype" })] + public string ShiftType { get; set; } /// /// 经营开始时间 @@ -46,5 +43,6 @@ public class CanteenBusinessShiftEntity : SugarBaseEntity, ITenantId [SugarColumn(ColumnDescription = "序号")] public int Sequence { get; set; } + public string TenantId { get; set; } -} \ No newline at end of file +} diff --git a/Src/Dlhis.Entity/Canteen/Entities/BalanceRecordEntity.cs b/Src/Dlhis.Entity/Canteen/Entities/BalanceRecordEntity.cs index 3303970b..9b69d0ce 100644 --- a/Src/Dlhis.Entity/Canteen/Entities/BalanceRecordEntity.cs +++ b/Src/Dlhis.Entity/Canteen/Entities/BalanceRecordEntity.cs @@ -64,7 +64,7 @@ public class BalanceRecordEntity : SugarBaseEntity, ITenantId /// /// 营业点 /// - [SugarColumn(ColumnDescription = "营业点" , IsNullable = true)] + [SugarColumn(ColumnDescription = "营业点", IsNullable = true)] public Guid? BusinessPlaceCode { get; set; } /// @@ -73,6 +73,12 @@ public class BalanceRecordEntity : SugarBaseEntity, ITenantId [SugarColumn(ColumnDescription = "餐次", IsNullable = true)] public Guid? BusinessShiftCode { get; set; } + /// + /// 餐次段 + /// + [SugarColumn(ColumnDescription = "餐次段", IsNullable = true)] + public string ShiftType { get; set; } + /// /// 所属成本日期 ///