diff --git a/Src/Dlhis.Basic.Api/Dlhis.Basic.Api.csproj b/Src/Dlhis.Basic.Api/Dlhis.Basic.Api.csproj
index ae3784a1..2311965f 100644
--- a/Src/Dlhis.Basic.Api/Dlhis.Basic.Api.csproj
+++ b/Src/Dlhis.Basic.Api/Dlhis.Basic.Api.csproj
@@ -10,4 +10,8 @@
+
+
+
+
diff --git a/Src/Dlhis.Basic.Api/Response/BusinessPlaceDto.cs b/Src/Dlhis.Basic.Api/Dtos/BusinessPlaceDto.cs
similarity index 87%
rename from Src/Dlhis.Basic.Api/Response/BusinessPlaceDto.cs
rename to Src/Dlhis.Basic.Api/Dtos/BusinessPlaceDto.cs
index cffafdb3..15003d35 100644
--- a/Src/Dlhis.Basic.Api/Response/BusinessPlaceDto.cs
+++ b/Src/Dlhis.Basic.Api/Dtos/BusinessPlaceDto.cs
@@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
-namespace Dlhis.Basic.Api.Response
+namespace Dlhis.Basic.Api.Dtos
{
public class BusinessPlaceDto
{
diff --git a/Src/Dlhis.Basic.Api/IBusinessPlacePermissionsApi.cs b/Src/Dlhis.Basic.Api/IBusinessPlacePermissionsApi.cs
index 3b6be007..9d5cf5f4 100644
--- a/Src/Dlhis.Basic.Api/IBusinessPlacePermissionsApi.cs
+++ b/Src/Dlhis.Basic.Api/IBusinessPlacePermissionsApi.cs
@@ -1,4 +1,4 @@
-using Dlhis.Basic.Api.Response;
+using Dlhis.Basic.Api.Dtos;
using Kurisu.Core.Result;
using Kurisu.RemoteCall.Attributes;
@@ -9,5 +9,5 @@ public interface IBusinessPlacePermissionsApi
{
[Auth]
[Get("/api/businessplacepermissions/my")]
- Task> GetMyAsync();
+ Task>> GetMyAsync();
}
diff --git a/Src/Dlhis.Basic.Api/Response/GetMyResponse.cs b/Src/Dlhis.Basic.Api/Response/GetMyResponse.cs
deleted file mode 100644
index 9e2df3ee..00000000
--- a/Src/Dlhis.Basic.Api/Response/GetMyResponse.cs
+++ /dev/null
@@ -1,13 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace Dlhis.Basic.Api.Response
-{
- public class GetMyResponse
- {
- public List dtos { get; set; }
- }
-}
diff --git a/Src/Dlhis.Basic/Dishes/Response/DishesCategoryResponse.cs b/Src/Dlhis.Basic/Dishes/Response/DishesCategoryResponse.cs
index fdaca520..024d2606 100644
--- a/Src/Dlhis.Basic/Dishes/Response/DishesCategoryResponse.cs
+++ b/Src/Dlhis.Basic/Dishes/Response/DishesCategoryResponse.cs
@@ -2,6 +2,11 @@
public class DishesCategoryTreeResponse
{
+ ///
+ /// 营业点code
+ ///
+ public Guid BusinessPlaceCode { get; set; }
+
public Guid? PCode { get; set; }
public Guid Code { get; set; }
diff --git a/Src/Dlhis.Basic/Dishes/Services/Implements/DishesCategoryService.cs b/Src/Dlhis.Basic/Dishes/Services/Implements/DishesCategoryService.cs
index 8fda1dc2..58e2b6b2 100644
--- a/Src/Dlhis.Basic/Dishes/Services/Implements/DishesCategoryService.cs
+++ b/Src/Dlhis.Basic/Dishes/Services/Implements/DishesCategoryService.cs
@@ -1,5 +1,7 @@
-using Dlhis.Basic.Dishes.Request;
+using Dlhis.Basic.BusinessPlace.Services;
+using Dlhis.Basic.Dishes.Request;
using Dlhis.Basic.Dishes.Response;
+using Dlhis.Entity.Basic.Entity;
using Dlhis.Entity.Canteen.Entities;
using Kurisu.AspNetCore.Utils.Extensions;
using Kurisu.SqlSugar.Services;
@@ -10,15 +12,30 @@ namespace Dlhis.Basic.Dishes.Services.Implements;
public class DishesCategoryService : IDishesCategoryService
{
private readonly IDbContext _dbContext;
+ private readonly IBusinessPlacePermissionsService _businessPlacePermissionsService;
- public DishesCategoryService(IDbContext dbContext)
+ public DishesCategoryService(IDbContext dbContext, IBusinessPlacePermissionsService businessPlacePermissionsService)
{
_dbContext = dbContext;
+ _businessPlacePermissionsService = businessPlacePermissionsService;
}
public async Task> TreeAsync()
{
- var categories = await _dbContext.Queryable().Select().ToListAsync();
+ var mybCodes = await GetMyBusinessPlaceCodesAsync();
+
+ var categories = await _dbContext.Queryable()
+ .LeftJoin((x, bplace) => x.BusinessPlaceCode == bplace.Code)
+ .Where(x => mybCodes.Contains(x.BusinessPlaceCode))
+ .Select((x, bplace) => new DishesCategoryTreeResponse
+ {
+ BusinessPlaceCode = bplace.Code,
+ Code = x.Code,
+ Name = x.Name,
+ PCode = x.PCode,
+ })
+ .ToListAsync();
+
var tops = categories.Where(x => !x.PCode.HasValue).ToList();
tops.ForEach(x =>
@@ -31,6 +48,8 @@ public class DishesCategoryService : IDishesCategoryService
public async Task SaveAsync(DishesCategorySaveRequest request)
{
+ await CheckBusinessPlacePermissionAsync(request.BusinessPlaceCode);
+
if (!request.Id.HasValue)
{
var entity = request.Adapt();
@@ -62,4 +81,27 @@ public class DishesCategoryService : IDishesCategoryService
}
}
}
+
+ ///
+ /// 检查营业点权限
+ ///
+ ///
+ ///
+ private async Task CheckBusinessPlacePermissionAsync(Guid businessPlaceCode)
+ {
+ var codes = await GetMyBusinessPlaceCodesAsync();
+ codes.Contains(businessPlaceCode).ThrowIfFalse("无权操作当前营业点");
+ }
+
+
+ ///
+ /// 获取我管理的营业点
+ ///
+ ///
+ private async Task> GetMyBusinessPlaceCodesAsync()
+ {
+ var mybCodes = (await _businessPlacePermissionsService.GetMyAsync()).Select(x => x.Code).ToList();
+
+ return mybCodes;
+ }
}
diff --git a/Src/Dlhis.Basic/Dishes/Services/Implements/DishesMenuService.cs b/Src/Dlhis.Basic/Dishes/Services/Implements/DishesMenuService.cs
index cec11e46..1ab10afd 100644
--- a/Src/Dlhis.Basic/Dishes/Services/Implements/DishesMenuService.cs
+++ b/Src/Dlhis.Basic/Dishes/Services/Implements/DishesMenuService.cs
@@ -96,7 +96,7 @@ public class DishesMenuService : IDishesMenuService
//检验权限
var res = await _businessPlacePermissionsService.GetMyAsync();
- var myBps = res.dtos.Select(x => x.Code).ToList();
+ var myBps = res.Select(x => x.Code).ToList();
myBps.Contains(request.BusinessPlaceCode).ThrowIfFalse("非经营营业点,无法保存菜单");
diff --git a/Src/Dlhis.Basic/Dlhis.Basic.csproj b/Src/Dlhis.Basic/Dlhis.Basic.csproj
index 5c48837c..fa24f2db 100644
--- a/Src/Dlhis.Basic/Dlhis.Basic.csproj
+++ b/Src/Dlhis.Basic/Dlhis.Basic.csproj
@@ -17,7 +17,7 @@
-
+
diff --git a/Src/Dlhis.Basic/Organization/Response/GainfoPageResponse.cs b/Src/Dlhis.Basic/Organization/Response/GainfoPageResponse.cs
index 4b8faadd..a43b0cf8 100644
--- a/Src/Dlhis.Basic/Organization/Response/GainfoPageResponse.cs
+++ b/Src/Dlhis.Basic/Organization/Response/GainfoPageResponse.cs
@@ -1,5 +1,7 @@
using Dlhis.Entity.Basic.Enums;
+using Kurisu.AspNetCore.Utils.Converters;
using Kurisu.AspNetCore.Utils.Extensions;
+using Newtonsoft.Json;
namespace Dlhis.Basic.Organization.Response;
@@ -45,6 +47,7 @@ public class GainfoPageResponse
///
/// 身份证号
///
+ [JsonConverter(typeof(ObfuscateJsonConverter), 6)]
public string IdNo { get; set; }
///
@@ -86,6 +89,7 @@ public class GainfoPageResponse
///
/// 手机号码
///
+ [JsonConverter(typeof(ObfuscateJsonConverter), 4)]
public string Phone { get; set; }
///
diff --git a/Src/Dlhis.Basic/Places/Controllers/BusinessPlacePermissionsController.cs b/Src/Dlhis.Basic/Places/Controllers/BusinessPlacePermissionsController.cs
index e9bdf549..e5e7e0c0 100644
--- a/Src/Dlhis.Basic/Places/Controllers/BusinessPlacePermissionsController.cs
+++ b/Src/Dlhis.Basic/Places/Controllers/BusinessPlacePermissionsController.cs
@@ -4,11 +4,12 @@ using Dlhis.Basic.BusinessPlace.Services;
using Kurisu.Core.DataAccess.Dto;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
+using Dlhis.Basic.Places.Dtos;
namespace Dlhis.Basic.BusinessPlace.Controllers;
///
-/// 营业点管理
+/// 营业点权限管理
///
[Authorize]
[Route("api/[controller]")]
@@ -27,7 +28,7 @@ public class BusinessPlacePermissionsController
///
///
///
- [Authorize(Roles = "admin,tenant-admin")]
+ [Authorize(Roles = "admin,tenant-admin,businessplace-manager")]
[HttpGet("page")]
public async Task> GetPageAsync([FromQuery] BusinessPlacePermissionPageRequest request)
{
@@ -39,7 +40,7 @@ public class BusinessPlacePermissionsController
///
///
[HttpGet("my")]
- public async Task GetMy()
+ public async Task> GetMy()
{
return await _businessPlacePermissionsService.GetMyAsync();
}
@@ -56,4 +57,28 @@ public class BusinessPlacePermissionsController
{
await _businessPlacePermissionsService.SaveBusinessPlacePermissionAsync(request);
}
+
+ ///
+ /// 通过userid获取分配的营业点信息
+ ///
+ ///
+ ///
+ [Authorize(Roles = "admin,tenant-admin")]
+ [HttpGet("assignments/{userId}")]
+ public async Task> GetBusinessPlacePermissionByUserIdAsyc(int userId)
+ {
+ return await _businessPlacePermissionsService.GetBusinessPlacePermissionByUserIdAsyc(userId);
+ }
+
+ ///
+ /// 删除记录
+ ///
+ ///
+ ///
+ [Authorize(Roles = "admin,tenant-admin")]
+ [HttpDelete("{id}")]
+ public async Task DeleteAssignmentAsync(int id)
+ {
+ await _businessPlacePermissionsService.DeleteAssignmentAsync(id);
+ }
}
diff --git a/Src/Dlhis.Basic/Places/Dtos/BusinessPlaceDto.cs b/Src/Dlhis.Basic/Places/Dtos/BusinessPlaceDto.cs
new file mode 100644
index 00000000..1f8a04cd
--- /dev/null
+++ b/Src/Dlhis.Basic/Places/Dtos/BusinessPlaceDto.cs
@@ -0,0 +1,7 @@
+namespace Dlhis.Basic.Places.Dtos;
+
+public class BusinessPlaceDto
+{
+ public Guid Code { get; set; }
+ public string Name { get; set; }
+}
diff --git a/Src/Dlhis.Basic/Places/Response/BusinessPlaceDto.cs b/Src/Dlhis.Basic/Places/Response/BusinessPlaceDto.cs
deleted file mode 100644
index a5dd68f7..00000000
--- a/Src/Dlhis.Basic/Places/Response/BusinessPlaceDto.cs
+++ /dev/null
@@ -1,8 +0,0 @@
-namespace Dlhis.Basic.BusinessPlace.Response
-{
- public class BusinessPlaceDto
- {
- public Guid Code { get; set; }
- public string Name { get; set; }
- }
-}
diff --git a/Src/Dlhis.Basic/Places/Response/BusinessPlacePermissionPageResponse.cs b/Src/Dlhis.Basic/Places/Response/BusinessPlacePermissionPageResponse.cs
index cac2e41e..9a1273e2 100644
--- a/Src/Dlhis.Basic/Places/Response/BusinessPlacePermissionPageResponse.cs
+++ b/Src/Dlhis.Basic/Places/Response/BusinessPlacePermissionPageResponse.cs
@@ -7,7 +7,7 @@ public class BusinessPlacePermissionPageResponse
///
/// 用户id
///
- public string UserId { get; set; }
+ public int UserId { get; set; }
///
/// 用户name
diff --git a/Src/Dlhis.Basic/Places/Response/GetMyResponse.cs b/Src/Dlhis.Basic/Places/Response/GetMyResponse.cs
deleted file mode 100644
index 1a3b6fd2..00000000
--- a/Src/Dlhis.Basic/Places/Response/GetMyResponse.cs
+++ /dev/null
@@ -1,7 +0,0 @@
-namespace Dlhis.Basic.BusinessPlace.Response
-{
- public class GetMyResponse
- {
- public List dtos { get; set; }
- }
-}
diff --git a/Src/Dlhis.Basic/Places/Services/IBusinessPlacePermissionsService.cs b/Src/Dlhis.Basic/Places/Services/IBusinessPlacePermissionsService.cs
index d36816ee..5d069b56 100644
--- a/Src/Dlhis.Basic/Places/Services/IBusinessPlacePermissionsService.cs
+++ b/Src/Dlhis.Basic/Places/Services/IBusinessPlacePermissionsService.cs
@@ -1,6 +1,7 @@
using Dlhis.Basic.Places.Request;
using Dlhis.Basic.BusinessPlace.Response;
using Kurisu.Core.DataAccess.Dto;
+using Dlhis.Basic.Places.Dtos;
namespace Dlhis.Basic.BusinessPlace.Services;
@@ -10,5 +11,9 @@ public interface IBusinessPlacePermissionsService : IScopeDependency
Task SaveBusinessPlacePermissionAsync(BusinessPlacePermissionSaveRequest request);
- Task GetMyAsync();
+ Task> GetMyAsync();
+
+ Task> GetBusinessPlacePermissionByUserIdAsyc(int id);
+
+ Task DeleteAssignmentAsync(int id);
}
diff --git a/Src/Dlhis.Basic/Places/Services/Implements/BusinessPlacePermissionsService.cs b/Src/Dlhis.Basic/Places/Services/Implements/BusinessPlacePermissionsService.cs
index 2141ab41..1143a99b 100644
--- a/Src/Dlhis.Basic/Places/Services/Implements/BusinessPlacePermissionsService.cs
+++ b/Src/Dlhis.Basic/Places/Services/Implements/BusinessPlacePermissionsService.cs
@@ -5,6 +5,10 @@ using Kurisu.Core.DataAccess.Dto;
using Kurisu.Core.User.Abstractions;
using Kurisu.SqlSugar.Services;
using Mapster;
+using Dlhis.Basic.Places.Dtos;
+using Kurisu.SqlSugar.Extensions;
+using Dlhis.Sys.Api;
+using Microsoft.AspNetCore.Mvc;
namespace Dlhis.Basic.BusinessPlace.Services.Implements;
@@ -12,19 +16,39 @@ public class BusinessPlacePermissionsService : IBusinessPlacePermissionsService
{
private readonly IDbContext _dbContext;
private readonly ICurrentUser _currentUser;
+ private readonly IUserApi _userApi;
- public BusinessPlacePermissionsService(IDbContext dbContext, ICurrentUser currentUser)
+ public BusinessPlacePermissionsService(IDbContext dbContext, ICurrentUser currentUser, IUserApi userApi)
{
_dbContext = dbContext;
_currentUser = currentUser;
+ _userApi = userApi;
}
public async Task> GetPageAsync(BusinessPlacePermissionPageRequest request)
{
- throw new NotImplementedException();
+ var page = await _dbContext.Queryable()
+ .LeftJoin((x, bplace) => x.BusinessPlaceCode == bplace.Code)
+ .Select((x, bplace) => new BusinessPlacePermissionPageResponse
+ {
+ UserId = x.ManagerUserId,
+ BusinessPlaceCode = x.BusinessPlaceCode,
+ BusinessPlaceName = bplace.Name,
+ })
+ .ToPageListAsync(request);
+
+ var usersResult = await _userApi.GetUserByIdsAsync(page.Data.Select(x => x.UserId).Distinct().ToList());
+ var users = usersResult.Data;
+
+ page.Data.ForEach(item =>
+ {
+ item.UserName = users.FirstOrDefault(x => x.Id == item.UserId)?.UserName;
+ });
+
+ return page;
}
- public async Task GetMyAsync()
+ public async Task> GetMyAsync()
{
var userId = _currentUser.GetIntSubjectId();
@@ -34,15 +58,10 @@ public class BusinessPlacePermissionsService : IBusinessPlacePermissionsService
.Distinct()
.ToListAsync();
- var dtos = await _dbContext.Queryable()
+ return await _dbContext.Queryable()
.Where(x => guids.Contains(x.Code))
.Select()
.ToListAsync();
- var myResponse = new GetMyResponse
- {
- dtos = dtos
- };
- return myResponse;
}
public async Task SaveBusinessPlacePermissionAsync(BusinessPlacePermissionSaveRequest request)
@@ -63,4 +82,33 @@ public class BusinessPlacePermissionsService : IBusinessPlacePermissionsService
await _dbContext.InsertAsync(entity);
}
}
+
+ public async Task> GetBusinessPlacePermissionByUserIdAsyc(int id)
+ {
+ var infos = await _dbContext.Queryable()
+ .LeftJoin((x, bplace) => x.BusinessPlaceCode == bplace.Code)
+ .Where(x => x.ManagerUserId == id)
+ .Select((x, bplace) => new BusinessPlacePermissionPageResponse
+ {
+ UserId = x.ManagerUserId,
+ BusinessPlaceCode = x.BusinessPlaceCode,
+ BusinessPlaceName = bplace.Name,
+ })
+ .ToListAsync();
+
+ var userResult = await _userApi.GetUserByIdAsync(id);
+ var user = userResult.Data;
+
+ infos.ForEach(item =>
+ {
+ item.UserName = user?.UserName;
+ });
+
+ return infos;
+ }
+
+ public async Task DeleteAssignmentAsync(int id)
+ {
+ await _dbContext.Client.Deleteable().Where(x => x.Id == id).ExecuteCommandAsync();
+ }
}
diff --git a/Src/Dlhis.Canteen/Order/Controllers/OrdersController.cs b/Src/Dlhis.Canteen/Order/Controllers/OrdersController.cs
index fc1ee44e..67e49e62 100644
--- a/Src/Dlhis.Canteen/Order/Controllers/OrdersController.cs
+++ b/Src/Dlhis.Canteen/Order/Controllers/OrdersController.cs
@@ -6,7 +6,6 @@ using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop;
using Kurisu.Core.DataAccess.Dto;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
-using Org.BouncyCastle.Asn1.Ocsp;
namespace Dlhis.Canteen.Dishes.Controllers;
@@ -19,21 +18,12 @@ namespace Dlhis.Canteen.Dishes.Controllers;
public class OrdersController : ControllerBase
{
private readonly IOrderService _orderService;
+ private readonly IBookingOrderService _bookingOrderService;
- public OrdersController(IOrderService orderService)
+ public OrdersController(IOrderService orderService, IBookingOrderService bookingOrderService)
{
_orderService = orderService;
- }
-
- ///
- /// 订单分页
- ///
- ///
- ///
- [HttpGet("page")]
- public async Task> GetPageAsync([FromQuery] OrderPageRequest request)
- {
- return await _orderService.GetPageAsync(request);
+ _bookingOrderService = bookingOrderService;
}
///
@@ -60,39 +50,6 @@ public class OrdersController : ControllerBase
return await _orderService.AddAsync(request);
}
-
- ///
- /// 订餐
- ///
- ///
- [HttpPost("booking")]
- [Transactional]
- public async Task Booking(BookingMealRequest request)
- {
- await _orderService.BookingAsync(request);
- }
-
- /////
- ///// 获取详情
- /////
- /////
- /////
- //[HttpGet("details")]
- //public async Task> GetDetailsAsync(string no)
- //{
- // return await _orderService.GetDetailsAsync(no);
- //}
-
- ///
- /// 充值
- ///
- ///
- [HttpPost("recharge")]
- public async Task ReCharge()
- {
-
- }
-
///
/// 订单聚合数据
///
@@ -102,4 +59,28 @@ public class OrdersController : ControllerBase
{
return await _orderService.GetOrdersAggregationAsync(page);
}
+
+ //************************************************************** 订餐功能 **********************************************************************************
+
+ ///
+ /// 订餐
+ ///
+ ///
+ [HttpPost("booking")]
+ [Transactional]
+ public async Task Booking(BookingMealRequest request)
+ {
+ await _bookingOrderService.BookingAsync(request);
+ }
+
+ ///
+ /// 订单分页
+ ///
+ ///
+ ///
+ [HttpGet("booking/page")]
+ public async Task> GetBookingPageAsync([FromQuery] OrderBookingPageRequest request)
+ {
+ return await _bookingOrderService.GetBookingPageAsync(request);
+ }
}
diff --git a/Src/Dlhis.Canteen/Order/Request/OrderPageRequest.cs b/Src/Dlhis.Canteen/Order/Request/OrderBookingPageRequest.cs
similarity index 63%
rename from Src/Dlhis.Canteen/Order/Request/OrderPageRequest.cs
rename to Src/Dlhis.Canteen/Order/Request/OrderBookingPageRequest.cs
index ad268044..3dd0fc6d 100644
--- a/Src/Dlhis.Canteen/Order/Request/OrderPageRequest.cs
+++ b/Src/Dlhis.Canteen/Order/Request/OrderBookingPageRequest.cs
@@ -2,7 +2,7 @@
namespace Dlhis.Canteen.Order.Request;
-public class OrderPageRequest : PageDto
+public class OrderBookingPageRequest : PageDto
{
}
diff --git a/Src/Dlhis.Canteen/Order/Response/OrderBookingResponse.cs b/Src/Dlhis.Canteen/Order/Response/OrderBookingResponse.cs
new file mode 100644
index 00000000..419d1fc9
--- /dev/null
+++ b/Src/Dlhis.Canteen/Order/Response/OrderBookingResponse.cs
@@ -0,0 +1,34 @@
+namespace Dlhis.Canteen.Order.Response;
+
+public class OrderBookingResponse
+{
+ ///
+ /// 订单号
+ ///
+ public string No { get; set; }
+
+ ///
+ /// 备注
+ ///
+ public string Remark { get; set; }
+
+ ///
+ /// 配送地址
+ ///
+ public string DeliveryAddress { get; set; }
+
+ ///
+ /// 订单金额
+ ///
+ public decimal Amount { get; set; }
+
+ ///
+ /// 工号
+ ///
+ public string UserCode { get; set; }
+
+ ///
+ ///
+ ///
+ public string UserNo { get; set; }
+}
diff --git a/Src/Dlhis.Canteen/Order/Response/OrderResponse.cs b/Src/Dlhis.Canteen/Order/Response/OrderResponse.cs
deleted file mode 100644
index 0486b439..00000000
--- a/Src/Dlhis.Canteen/Order/Response/OrderResponse.cs
+++ /dev/null
@@ -1,5 +0,0 @@
-namespace Dlhis.Canteen.Order.Response;
-
-public class OrderResponse
-{
-}
diff --git a/Src/Dlhis.Canteen/Order/Services/IBookingOrderService.cs b/Src/Dlhis.Canteen/Order/Services/IBookingOrderService.cs
new file mode 100644
index 00000000..bbe5116c
--- /dev/null
+++ b/Src/Dlhis.Canteen/Order/Services/IBookingOrderService.cs
@@ -0,0 +1,21 @@
+using Dlhis.Canteen.Dishes.Request;
+using Dlhis.Canteen.Order.Request;
+using Dlhis.Canteen.Order.Response;
+using Kurisu.Core.DataAccess.Dto;
+
+namespace Dlhis.Canteen.Order.Services;
+
+public interface IBookingOrderService
+{
+ ///
+ /// 订餐
+ ///
+ ///
+ ///
+ Task BookingAsync(BookingMealRequest request);
+
+
+ Task> GetBookingPageAsync(OrderBookingPageRequest request);
+
+ Task CancelOrderAsync();
+}
diff --git a/Src/Dlhis.Canteen/Order/Services/IOrderService.cs b/Src/Dlhis.Canteen/Order/Services/IOrderService.cs
index 28c772df..c6ddb582 100644
--- a/Src/Dlhis.Canteen/Order/Services/IOrderService.cs
+++ b/Src/Dlhis.Canteen/Order/Services/IOrderService.cs
@@ -1,5 +1,4 @@
-using Dlhis.Canteen.Dishes.Request;
-using Dlhis.Canteen.Order.Request;
+using Dlhis.Canteen.Order.Request;
using Dlhis.Canteen.Order.Response;
using Kurisu.Core.DataAccess.Dto;
@@ -7,7 +6,7 @@ namespace Dlhis.Canteen.Order.Services;
public interface IOrderService : IScopeDependency
{
- Task> GetPageAsync(OrderPageRequest request);
+
Task AddAsync(OrderAddRequest request);
@@ -19,20 +18,5 @@ public interface IOrderService : IScopeDependency
///
Task DeviceConsume(OrderAddRequest request);
- ///
- /// 订餐
- ///
- ///
- ///
- Task BookingAsync(BookingMealRequest request);
-
-
- /////
- ///// 获取订单详情
- /////
- /////
- /////
- //Task> GetDetailsAsync(string no);
-
Task> GetOrdersAggregationAsync(PageDto page);
}
diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/BaseOrderService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/BaseOrderService.cs
new file mode 100644
index 00000000..ce759c46
--- /dev/null
+++ b/Src/Dlhis.Canteen/Order/Services/Implements/BaseOrderService.cs
@@ -0,0 +1,133 @@
+using Dlhis.Basic.Api;
+using Dlhis.Canteen.Setting.Services;
+using Dlhis.Entity.Basic.Entity;
+using Dlhis.Entity.Canteen.Enums;
+using Kurisu.AspNetCore.UnifyResultAndValidation;
+using Kurisu.AspNetCore.Utils.Extensions;
+using Kurisu.Core.User.Abstractions;
+using Kurisu.SqlSugar.Services;
+using Mapster;
+using SqlSugar;
+
+namespace Dlhis.Canteen.Order.Services.Implements;
+
+public abstract class BaseOrderService
+{
+ private readonly ICanteenSettingService _canteenSettingService;
+ private readonly IDbContext _dbContext;
+ private readonly ICurrentUser _currentUser;
+ private readonly IDevicePermissionApi _devicePermissionApi;
+ private readonly ILogger _logger;
+ private Dictionary _settings;
+
+ public BaseOrderService(ICanteenSettingService canteenSettingService,
+ IDbContext dbContext,
+ ICurrentUser currentUser,
+ IDevicePermissionApi devicePermissionApi,
+ ILogger logger)
+ {
+ _canteenSettingService = canteenSettingService;
+ _dbContext = dbContext;
+ _currentUser = currentUser;
+ _devicePermissionApi = devicePermissionApi;
+ _logger = logger;
+ }
+
+ protected BaseOrderService(ICanteenSettingService canteenSettingService)
+ {
+ _canteenSettingService = canteenSettingService;
+ }
+
+ protected IDbContext DbContext => _dbContext;
+
+ protected ICurrentUser CurrentUser => _currentUser;
+
+ ///
+ /// 检查权限
+ ///
+ ///
+ ///
+ ///
+ protected async Task CheckPermissionAsync(string userNo, string deviceUniqueNo)
+ {
+ var uniqueNosResult = await _devicePermissionApi.GetCanteenDeviceUniqueNosByUserNoAsync(userNo);
+ var uniqueNos = uniqueNosResult.Data;
+
+ uniqueNos.Contains(deviceUniqueNo).ThrowIfFalse("无消费权限");
+ }
+
+
+ ///
+ /// 设备并发更新 需要抛出VersionExceptions
+ ///
+ ///
+ ///
+ /// 并发冲突处理次数
+ ///
+ ///
+ ///
+ protected async Task ContinueUpdateAsync(Func func, int retry, string errorMessage = null)
+ {
+ for (int i = 0; i < retry; i++)
+ {
+ try
+ {
+ await func();
+ return;
+ }
+ catch (Exception ex) when (ex is VersionExceptions)
+ {
+ _logger.LogWarning(ex, ex.Message);
+ }
+ catch (Exception)
+ {
+ throw;
+ }
+ }
+
+ throw new UserFriendlyException(errorMessage ?? "操作失败,请重试");
+ }
+
+
+ ///
+ /// 获取参数配置
+ ///
+ ///
+ ///
+ ///
+ ///
+ protected async Task GetSettingAsync(CanteenSettingItemEnumType item, T defaultValue = default)
+ {
+ if (_settings == null)
+ {
+ 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();
+ }
+ _settings = await _canteenSettingService.GetUserSettingAsync(gainfo.No);
+ }
+
+
+ if (_settings.TryGetValue(item, out var v))
+ {
+ try
+ {
+ if (int.TryParse(v, out var n))
+ {
+ return n.Adapt();
+ }
+
+ return v.Adapt();
+ }
+ catch (Exception)
+ {
+ return defaultValue;
+ }
+ }
+
+ return defaultValue;
+ }
+}
diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/BookingOrderService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/BookingOrderService.cs
new file mode 100644
index 00000000..1561ecf0
--- /dev/null
+++ b/Src/Dlhis.Canteen/Order/Services/Implements/BookingOrderService.cs
@@ -0,0 +1,210 @@
+using Dlhis.Canteen.Dishes.Request;
+using Dlhis.Canteen.Order.Request;
+using Dlhis.Canteen.Order.Response;
+using Dlhis.Entity.Basic.Entity;
+using Dlhis.Entity.Canteen.Entities;
+using Dlhis.Entity.Canteen.Enums;
+using Kurisu.AspNetCore.Utils.Extensions;
+using Kurisu.AspNetCore.Utils;
+using Kurisu.Core.DataAccess.Dto;
+using Kurisu.SqlSugar.Services;
+using Kurisu.Core.User.Abstractions;
+using Dlhis.Canteen.Setting.Services;
+using Dlhis.Basic.Api;
+using Kurisu.SqlSugar.Extensions;
+using SqlSugar;
+using Mapster;
+
+namespace Dlhis.Canteen.Order.Services.Implements;
+
+public class BookingOrderService : BaseOrderService, IBookingOrderService
+{
+ private readonly IDbContext _dbContext;
+ private readonly ICurrentUser _currentUser;
+ private readonly IDisheMenuApi _disheMenuApi;
+
+ public BookingOrderService(ICanteenSettingService canteenSettingService, IDisheMenuApi disheMenuApi) : base(canteenSettingService)
+ {
+ _disheMenuApi = disheMenuApi;
+ }
+
+ public async Task BookingAsync(BookingMealRequest request)
+ {
+ var gainfo = await CheckExistsMyBookingsAsync(request.BookingDate, request.ShiftType);
+
+ var businessPlace = await _dbContext.Queryable().Where(x => x.Code == request.BusinessPlaceCode).FirstAsync();
+
+ //预定时间
+ var now = DateTime.Now;
+
+ var bookingDeadline = await GetSettingAsync(CanteenSettingItemEnumType.BookingDeadline) ?? new TimeOnly(20, 30, 00);
+ var dealLine = DateTime.Today.Add(bookingDeadline.ToTimeSpan());
+ (now >= dealLine).ThrowIfTrue("超出订餐时间");
+
+ //菜单存在
+ var menuDetailResult = await _disheMenuApi.GetBookingDishesDetailAsync(request.BookingDate, request.BusinessPlaceCode, (int)request.ShiftType, request.DishesCode);
+ var menuDetail = menuDetailResult.Data;
+ menuDetail.ThrowIfNull("预定失败,菜品已经下架");
+
+ var order = new CanteenOrderEntity
+ {
+ RequestJson = request.ToJson(),
+ ThirdNo = string.Empty,
+ Type = BalanceRecordTypeEnumType.Out,
+ ApplicationType = CanteenApplicaitonTypeEnumType.Booking,
+ Name = gainfo.Name,
+ Source = request.Source,
+ UserNo = gainfo.No,
+ UserCode = gainfo.Code,
+ Amount = -Math.Abs(menuDetail.Price),
+ BusinessPlaceCode = request.BusinessPlaceCode,
+ BusinessShiftCode = null,
+ ShiftType = request.ShiftType,
+ CostDate = now.Date,
+ CostId = gainfo.CostId,
+ DepartmentNo = gainfo.DepartmentNo,
+ DeviceUniqueNo = string.Empty,
+ DeliveryAddress = request.DeliveryAddress,
+
+ No = SnowFlakeHelper.Instance.NextId().ToString(),
+ SubsidiesFromMonth = now.ToString("yyyyMM"),
+ IsOffline = false,
+ IsCostCrossTenant = await GetSettingAsync(CanteenSettingItemEnumType.AllowCrossTenant),
+
+ OriginTenantId = gainfo.Factory,//人员可能跨基地消费
+
+ Status = BalanceRecordStatusEnumType.Valid,
+ OrderStatus = CanteenOrderStatusEnumType.Success,
+
+ CostDateTime = now,
+
+ //标识当前消费的基地
+ TenantId = businessPlace.TenantId,
+ };
+
+ var orderId = await _dbContext.InsertReturnIdentityAsync(order);
+ await ContinueUpdateAsync(async () =>
+ {
+ await _disheMenuApi.GetBookingDishesDetailAsync(request.BookingDate, request.BusinessPlaceCode, (int)request.ShiftType, request.DishesCode);
+ var menuDetail = menuDetailResult.Data;
+ menuDetail.ThrowIfNull("预定失败,菜品已经下架");
+ menuDetail.Number -= 1;
+
+ (menuDetail.Number < 0).ThrowIfTrue($"{menuDetail.DishesName}已售罄");
+
+ var mealInfo = await _dbContext.Queryable().Where(x => x.UserNo == order.UserNo).FirstAsync();
+ if (mealInfo == null)
+ {
+ await _dbContext.InsertAsync(new GainfoMealEntity
+ {
+ Balance = 0,
+ BalanceOfRecharge = 0,
+ BalanceOfSubsidies = 0,
+ UserCode = gainfo.Code,
+ UserNo = gainfo.No,
+ Version = 0,
+ });
+
+ (mealInfo == null).ThrowIfTrue("余额不足,无法消费");
+ }
+ //金额+-
+ mealInfo.Balance += order.Amount;
+ (mealInfo.Balance < 0).ThrowIfTrue("余额不足,无法消费");
+
+ var effect = await _dbContext.Updateable()
+ .SetColumns(x => x.Balance == mealInfo.Balance)
+ .SetColumns(x => x.Version == x.Version + 1)
+ .Where(x => x.UserNo == order.UserNo && x.Version == mealInfo.Version)//必须与查询时的version一致
+ .ExecuteCommandAsync();
+
+ if (effect <= 0) throw new VersionExceptions("更新版本冲突");
+
+ effect = await _dbContext.Updateable()
+ .SetColumns(x => x.Number == menuDetail.Number)
+ .SetColumns(x => x.Version == x.Version + 1)
+ .SetColumns(x => x.ModifiedTime == now)
+ .Where(x => x.Date == menuDetail.Date
+ && x.ShiftType == request.ShiftType
+ && x.BusinessPlaceCode == request.BusinessPlaceCode
+ && x.DishesCode == request.DishesCode
+ && x.Version == menuDetail.Version
+ )
+ .ExecuteCommandAsync();
+
+ if (effect <= 0) throw new VersionExceptions("更新版本冲突");
+
+ //写入记录
+ var balanceRecord = order.Adapt();
+ await _dbContext.InsertAsync(balanceRecord);
+
+ await _dbContext.InsertAsync(new CanteenOrderDetailEntity
+ {
+ OrderNo = order.No,
+ DishesCode = request.DishesCode,
+ Price = menuDetail.Price,
+ //Unit
+ Number = 1,
+ });
+
+ }, 10);
+ }
+
+
+ public async Task> GetBookingPageAsync(OrderBookingPageRequest request)
+ {
+ var page = await _dbContext.Queryable()
+ .LeftJoin((x, ga) => x.UserNo == ga.No)
+ .Select(x => new OrderBookingResponse
+ {
+ No = x.No,
+ DeliveryAddress = x.DeliveryAddress,
+ Remark = x.Remark,
+ Amount = x.Amount
+ })
+ .ToPageListAsync(request);
+
+ return page;
+ }
+
+ public async Task CancelOrderAsync()
+ {
+ throw new NotImplementedException();
+ }
+
+
+
+
+
+
+
+ ///
+ /// 检查我的订餐是否存在,存在抛出异常
+ ///
+ ///
+ ///
+ ///
+ private async Task CheckExistsMyBookingsAsync(DateTime bookingDate, ShiftEnumType shiftType)
+ {
+ 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 start = bookingDate.Date.AddDays(-1);
+ var end = start.AddDays(1).AddSeconds(-1);
+
+ var exists = await _dbContext.Queryable()
+ .Where(x => x.ApplicationType == CanteenApplicaitonTypeEnumType.Booking)
+ .Where(x => x.ShiftType == shiftType)
+ .Where(x => x.UserNo == gainfo.No)
+ .Where(x => x.CreateTime >= start && x.CreateTime <= end)
+ .AnyAsync();
+
+ exists.ThrowIfTrue("不可重复订餐");
+
+ return gainfo;
+ }
+}
diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs
index 87bf6d86..821b6610 100644
--- a/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs
+++ b/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs
@@ -18,193 +18,18 @@ using SqlSugar;
using Dlhis.Canteen.Order.Response;
using Dlhis.Canteen.Dishes;
using Dlhis.Canteen.Order.Request;
-using System.Numerics;
-using MySqlX.XDevAPI.Relational;
namespace Dlhis.Canteen.Order.Services.Implements;
-public class OrderService : IOrderService
+public class OrderService : BaseOrderService, IOrderService
{
- private readonly IDbContext _dbContext;
- private readonly ICanteenSettingService _canteenSettingService;
- private readonly IDevicePermissionApi _devicePermissionApi;
- private readonly ICurrentUser _currentUser;
- private readonly IDisheMenuApi _disheMenuApi;
- private readonly ILogger _logger;
-
- public OrderService(IDbContext dbContext,
- ICanteenSettingService canteenSettingService,
- IDevicePermissionApi devicePermissionApi,
- ICurrentUser currentUser,
- IDisheMenuApi disheMenuApi,
+ public OrderService(ICanteenSettingService canteenSettingService, IDbContext dbContext,
+ ICurrentUser currentUser, IDevicePermissionApi devicePermissionApi,
ILogger logger)
+ : base(canteenSettingService, dbContext, currentUser, devicePermissionApi, logger)
{
- _dbContext = dbContext;
- _canteenSettingService = canteenSettingService;
- _devicePermissionApi = devicePermissionApi;
- _currentUser = currentUser;
- _disheMenuApi = disheMenuApi;
- _logger = logger;
}
- public async Task> GetPageAsync(OrderPageRequest request)
- {
- var page = await _dbContext.Queryable()
- .Select()
- .ToPageListAsync(request);
-
- return page;
- }
-
- private async Task CheckPAsync(string userNo, string deviceUniqueNo)
- {
- var uniqueNosResult = await _devicePermissionApi.GetCanteenDeviceUniqueNosByUserNoAsync(userNo);
- var uniqueNos = uniqueNosResult.Data;
-
- uniqueNos.Contains(deviceUniqueNo).ThrowIfFalse("无消费权限");
- }
-
- public async Task BookingAsync(BookingMealRequest request)
- {
- var gainfo = await CheckExistsMyBookingsAsync(request.BookingDate, request.ShiftType);
-
- var businessPlace = await _dbContext.Queryable().Where(x => x.Code == request.BusinessPlaceCode).FirstAsync();
-
- //预定时间
- var now = DateTime.Now;
-
- var settings = await _canteenSettingService.GetUserSettingAsync(gainfo.Code);
- var bookingDeadline = GetSetting(settings, CanteenSettingItemEnumType.BookingDeadline) ?? new TimeOnly(20, 30, 00);
- var dealLine = DateTime.Today.Add(bookingDeadline.ToTimeSpan());
- (now >= dealLine).ThrowIfTrue("超出订餐时间");
-
- //菜单存在
- var menuDetailResult = await _disheMenuApi.GetBookingDishesDetailAsync(request.BookingDate, request.BusinessPlaceCode, (int)request.ShiftType, request.DishesCode);
- var menuDetail = menuDetailResult.Data;
- menuDetail.ThrowIfNull("预定失败,菜品已经下架");
-
- var order = new CanteenOrderEntity
- {
- RequestJson = request.ToJson(),
- ThirdNo = string.Empty,
- Type = BalanceRecordTypeEnumType.Out,
- ApplicationType = CanteenApplicaitonTypeEnumType.Booking,
- Name = gainfo.Name,
- Source = request.Source,
- UserNo = gainfo.No,
- UserCode = gainfo.Code,
- Amount = -Math.Abs(menuDetail.Price),
- BusinessPlaceCode = request.BusinessPlaceCode,
- BusinessShiftCode = null,
- ShiftType = request.ShiftType,
- CostDate = now.Date,
- CostId = gainfo.CostId,
- DepartmentNo = gainfo.DepartmentNo,
- DeviceUniqueNo = string.Empty,
- DeliveryAddress = request.DeliveryAddress,
-
- No = SnowFlakeHelper.Instance.NextId().ToString(),
- SubsidiesFromMonth = now.ToString("yyyyMM"),
- IsOffline = false,
- IsCostCrossTenant = GetSetting(settings, CanteenSettingItemEnumType.AllowCrossTenant),
-
- OriginTenantId = gainfo.Factory,//人员可能跨基地消费
-
- Status = BalanceRecordStatusEnumType.Valid,
- OrderStatus = CanteenOrderStatusEnumType.Successful,
-
- CostDateTime = now,
-
- //标识当前消费的基地
- TenantId = businessPlace.TenantId,
- };
-
- var orderId = await _dbContext.InsertReturnIdentityAsync(order);
- await ContinueUpdateAsync(async () =>
- {
- await _disheMenuApi.GetBookingDishesDetailAsync(request.BookingDate, request.BusinessPlaceCode, (int)request.ShiftType, request.DishesCode);
- var menuDetail = menuDetailResult.Data;
- menuDetail.ThrowIfNull("预定失败,菜品已经下架");
- menuDetail.Number -= 1;
-
- (menuDetail.Number < 0).ThrowIfTrue($"{menuDetail.DishesName}已售罄");
-
- var mealInfo = await _dbContext.Queryable().Where(x => x.UserNo == order.UserNo).FirstAsync();
- if (mealInfo == null)
- {
- await _dbContext.InsertAsync(new GainfoMealEntity
- {
- Balance = 0,
- BalanceOfRecharge = 0,
- BalanceOfSubsidies = 0,
- UserCode = gainfo.Code,
- UserNo = gainfo.No,
- Version = 0,
- });
-
- (mealInfo == null).ThrowIfTrue("余额不足,无法消费");
- }
- //金额+-
- mealInfo.Balance += order.Amount;
- (mealInfo.Balance < 0).ThrowIfTrue("余额不足,无法消费");
-
- var effect = await _dbContext.Updateable()
- .SetColumns(x => x.Balance == mealInfo.Balance)
- .SetColumns(x => x.Version == x.Version + 1)
- .Where(x => x.UserNo == order.UserNo && x.Version == mealInfo.Version)//必须与查询时的version一致
- .ExecuteCommandAsync();
-
- if (effect <= 0) throw new VersionExceptions("更新版本冲突");
-
- effect = await _dbContext.Updateable()
- .SetColumns(x => x.Number == menuDetail.Number)
- .SetColumns(x => x.Version == x.Version + 1)
- .SetColumns(x => x.ModifiedTime == now)
- .Where(x => x.Date == menuDetail.Date
- && x.ShiftType == request.ShiftType
- && x.BusinessPlaceCode == request.BusinessPlaceCode
- && x.DishesCode == request.DishesCode
- && x.Version == menuDetail.Version
- )
- .ExecuteCommandAsync();
-
- if (effect <= 0) throw new VersionExceptions("更新版本冲突");
-
- //写入记录
- var balanceRecord = order.Adapt();
- await _dbContext.InsertAsync(balanceRecord);
-
- await _dbContext.InsertAsync(new CanteenOrderDetailEntity
- {
- OrderNo = order.No,
- DishesCode = request.DishesCode,
- Price = menuDetail.Price,
- //Unit
- Number = 1,
- });
-
- }, 10);
- }
-
-
- //public async Task> GetDetailsAsync(string no)
- //{
- // return await _dbContext.Queryable()
- // .LeftJoin((x, d) => x.DishesCode == d.CustomCode)
- // .Where(x => x.OrderNo == no)
- // .Select((x, d) => new OrderDetailResponse
- // {
- // DishesCode = x.DishesCode,
- // Price = x.Price,
- // Name = d.Name,
- // Number = x.Number,
- // Unit = x.Unit,
- // ImageUrl = d.ImageUrl,
- // })
- // .ToListAsync();
- //}
-
-
public async Task DeviceConsume(OrderAddRequest request)
{
return await AddAsync(request);
@@ -216,21 +41,21 @@ public class OrderService : IOrderService
_ = long.TryParse(request.UserUniqueNo, out var userId);
//根据档案号
- var gainfo = await _dbContext.Queryable()
+ var gainfo = await DbContext.Queryable()
.Where(x => x.No == request.UserUniqueNo || x.Code == request.UserUniqueNo || x.Id == userId || x.CardNo == request.UserUniqueNo)
.FirstAsync();
gainfo.ThrowIfNull($"无消费权限");
//消费权限控制
- await CheckPAsync(gainfo.No, request.DeviceUniqueNo);
+ await CheckPermissionAsync(gainfo.No, request.DeviceUniqueNo);
- var canteenUserExists = await _dbContext.Queryable()
+ var canteenUserExists = await DbContext.Queryable()
.Where(x => x.UserNo == gainfo.No)
.AnyAsync();
if (!canteenUserExists)
{
- await _dbContext.InsertAsync(new GainfoMealEntity
+ await DbContext.InsertAsync(new GainfoMealEntity
{
UserNo = gainfo.No,
Balance = 0,
@@ -258,7 +83,7 @@ public class OrderService : IOrderService
}
//获取人员余额
- return await _dbContext.Queryable()
+ return await DbContext.Queryable()
.LeftJoin((ga, department) => ga.DepartmentNo == department.No)
.LeftJoin((ga, department, mealUser) => ga.No == mealUser.UserNo)
.Where(ga => ga.Id == gainfo.Id)
@@ -281,11 +106,11 @@ public class OrderService : IOrderService
///
private async Task ConsumeAsync(ConsumeRequest request, GainfoEntity gainfo)
{
- var device = await _dbContext.Queryable().Where(x => x.UniqueNo == request.DeviceUniqueNo).Where(x => x.Enable).FirstAsync();
+ var device = await DbContext.Queryable().Where(x => x.UniqueNo == request.DeviceUniqueNo).Where(x => x.Enable).FirstAsync();
device.ThrowIfNull("设备不存在或者尚未启用");
- var registry = await _dbContext.Queryable().Where(x => x.DeviceUniqueNo == request.DeviceUniqueNo).FirstAsync();
+ var registry = await DbContext.Queryable().Where(x => x.DeviceUniqueNo == request.DeviceUniqueNo).FirstAsync();
registry.ThrowIfNull("设备尚未注册");
- var businessPlaceInfo = await _dbContext.Queryable()
+ var businessPlaceInfo = await DbContext.Queryable()
.LeftJoin((x, sr) => x.Code == sr.PlaceCode)
.Where(x => x.Code == registry.BusinessPlaceCode)
.Select((x, sr) => new
@@ -298,7 +123,7 @@ public class OrderService : IOrderService
businessPlaceInfo.ThrowIfNull("营业点尚未设置");
//获取当前消费餐次
- var shifts = await _dbContext.Queryable().Where(x => x.ShiftCode == businessPlaceInfo.ShiftCode).ToListAsync();
+ var shifts = await DbContext.Queryable().Where(x => x.ShiftCode == businessPlaceInfo.ShiftCode).ToListAsync();
var shift = shifts.FirstOrDefault(x => new TimePeriod()
{
@@ -307,8 +132,7 @@ public class OrderService : IOrderService
}.IsPresent1(request.CostDateTime));
- var settings = await _canteenSettingService.GetUserSettingAsync(request.UserUniqueNo);
- var switchTime = GetSetting(settings, CanteenSettingItemEnumType.BusinessSwitchTime);
+ var switchTime = await GetSettingAsync(CanteenSettingItemEnumType.BusinessSwitchTime);
var shiftTimePeriod = new TimePeriod()
{
@@ -356,7 +180,7 @@ public class OrderService : IOrderService
No = SnowFlakeHelper.Instance.NextId().ToString(),
SubsidiesFromMonth = request.CostDateTime.ToString("yyyyMM"),
IsOffline = request.IsOffline,
- IsCostCrossTenant = GetSetting(settings, CanteenSettingItemEnumType.AllowCrossTenant),
+ IsCostCrossTenant = await GetSettingAsync(CanteenSettingItemEnumType.AllowCrossTenant),
OriginTenantId = gainfo.Factory,//人员可能跨基地消费
@@ -371,14 +195,14 @@ public class OrderService : IOrderService
TenantId = businessPlaceInfo.TenantId,
};
- var orderId = await _dbContext.InsertReturnIdentityAsync(order);
+ var orderId = await DbContext.InsertReturnIdentityAsync(order);
try
{
- await GenerateConsumeRecordAsync(orderId, settings, shifts, request.CostDateTime);
+ await GenerateConsumeRecordAsync(orderId, shifts, request.CostDateTime);
}
catch (Exception ex)
{
- await _dbContext.Updateable()
+ await DbContext.Updateable()
.SetColumns(x => x.OrderStatus == CanteenOrderStatusEnumType.Failure)
.SetColumns(x => x.Result == ex.Message)
.SetColumns(x => x.ModifiedTime == DateTime.Now)
@@ -388,8 +212,8 @@ public class OrderService : IOrderService
throw;
}
- await _dbContext.Updateable()
- .SetColumns(x => x.OrderStatus == CanteenOrderStatusEnumType.Successful)
+ await DbContext.Updateable()
+ .SetColumns(x => x.OrderStatus == CanteenOrderStatusEnumType.Success)
.SetColumns(x => x.ModifiedTime == DateTime.Now)
.Where(x => x.Id == orderId)
.ExecuteCommandAsync();
@@ -403,8 +227,6 @@ public class OrderService : IOrderService
///
private async Task RechargeAsync(RechargeRequest request, GainfoEntity gainfo)
{
- var settings = await _canteenSettingService.GetUserSettingAsync(request.UserUniqueNo);
-
var order = new CanteenOrderEntity
{
RequestJson = request.ToJson(),
@@ -425,7 +247,7 @@ public class OrderService : IOrderService
No = SnowFlakeHelper.Instance.NextId().ToString(),
SubsidiesFromMonth = request.CostDateTime.ToString("yyyyMM"),
- IsCostCrossTenant = GetSetting(settings, CanteenSettingItemEnumType.AllowCrossTenant),
+ IsCostCrossTenant = await GetSettingAsync(CanteenSettingItemEnumType.AllowCrossTenant),
OriginTenantId = gainfo.Factory,//人员可能跨基地消费
@@ -439,14 +261,14 @@ public class OrderService : IOrderService
TenantId = gainfo.Factory,
};
- var orderId = await _dbContext.InsertReturnIdentityAsync(order);
+ var orderId = await DbContext.InsertReturnIdentityAsync(order);
try
{
await GenerateRechargeRecordAsync(orderId);
}
catch (Exception ex)
{
- await _dbContext.Updateable()
+ await DbContext.Updateable()
.SetColumns(x => x.OrderStatus == CanteenOrderStatusEnumType.Failure)
.SetColumns(x => x.Result == ex.Message)
.Where(x => x.Id == orderId)
@@ -455,8 +277,8 @@ public class OrderService : IOrderService
throw;
}
- await _dbContext.Updateable()
- .SetColumns(x => x.OrderStatus == CanteenOrderStatusEnumType.Successful)
+ await DbContext.Updateable()
+ .SetColumns(x => x.OrderStatus == CanteenOrderStatusEnumType.Success)
.Where(x => x.Id == orderId)
.ExecuteCommandAsync();
}
@@ -464,15 +286,15 @@ public class OrderService : 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;
+ 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();
+ gainfo = await DbContext.Queryable().Where(x => x.Code == jinkoCode).FirstAsync();
}
- var pageResult = await _dbContext.Queryable().Where(x => x.UserNo == gainfo.No)
+ var pageResult = await DbContext.Queryable().Where(x => x.UserNo == gainfo.No)
.LeftJoin((x, bplace) => x.BusinessPlaceCode == bplace.Code)
.Where(x => x.ApplicationType == CanteenApplicaitonTypeEnumType.Booking)
.Select((x, bplace) => new OrderAggregationResponse
@@ -485,7 +307,7 @@ public class OrderService : IOrderService
//.LeftJoin((x, bplace, detail) => x.No == detail.OrderNo)
var nos = pageResult.Data.Select(x => x.No).ToList();
- var dtos = await _dbContext.Queryable()
+ var dtos = await DbContext.Queryable()
.LeftJoin((x, d) => x.DishesCode == d.CustomCode)
.Where(x => nos.Contains(x.OrderNo))
.Select((x, d) => new DishesDto
@@ -512,78 +334,17 @@ public class OrderService : IOrderService
//******************************************************* help methods ************************************************************/
- ///
- /// 设备并发更新 需要抛出VersionExceptions
- ///
- ///
- ///
- /// 并发冲突处理次数
- ///
- ///
- private async Task ContinueUpdateAsync(Func func, int retry)
- {
- for (int i = 0; i < retry; i++)
- {
- try
- {
- await func();
- return;
- }
- catch (Exception ex) when (ex is VersionExceptions)
- {
- _logger.LogWarning(ex, ex.Message);
- }
- catch (Exception)
- {
- throw;
- }
- }
-
- throw new UserFriendlyException("操作失败,请重试");
- }
-
-
- ///
- /// 获取参数配置
- ///
- ///
- ///
- ///
- ///
- ///
- private static T GetSetting(Dictionary settings, CanteenSettingItemEnumType item, T defaultValue = default)
- {
- if (settings.TryGetValue(item, out var v))
- {
- try
- {
- if (int.TryParse(v, out var n))
- {
- return n.Adapt();
- }
-
- return v.Adapt();
- }
- catch (Exception)
- {
- return defaultValue;
- }
- }
-
- return defaultValue;
- }
///
/// 验证参数
///
- ///
///
///
///
///
///
- private async Task Verify(Dictionary settings, List shifts, DateTime costDateTime, CanteenOrderEntity order)
+ private async Task Verify(List shifts, DateTime costDateTime, CanteenOrderEntity order)
{
//在线
if (!order.IsOffline)
@@ -599,15 +360,15 @@ public class OrderService : IOrderService
var beginOfDay = DateTime.Today;
var endOfDay = beginOfDay.AddHours(23).AddMinutes(59).AddSeconds(59);
- var balanceRecords = await _dbContext.Queryable()
+ var balanceRecords = await DbContext.Queryable()
.Where(x => x.UserNo == order.UserNo)
.Where(x => x.CreateTime >= beginOfDay && x.CreateTime <= endOfDay) //今天消费记录
.ToListAsync();
- var dayMarketCostMax = GetSetting(settings, CanteenSettingItemEnumType.DayMarketCostMax);
+ var dayMarketCostMax = await GetSettingAsync(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();
@@ -618,7 +379,7 @@ public class OrderService : IOrderService
}
}
- var allowRepeatInOneShift = GetSetting(settings, CanteenSettingItemEnumType.AllowRepeatInOneShift, true);
+ var allowRepeatInOneShift = await GetSettingAsync(CanteenSettingItemEnumType.AllowRepeatInOneShift, true);
if (!allowRepeatInOneShift)
{
//todo 餐次问题
@@ -629,7 +390,7 @@ public class OrderService : IOrderService
}
}
- var onceCostMax = GetSetting(settings, CanteenSettingItemEnumType.OnceCostMax);
+ var onceCostMax = await GetSettingAsync(CanteenSettingItemEnumType.OnceCostMax);
if (onceCostMax != default)
{
if (Math.Abs(order.Amount) > onceCostMax)
@@ -638,7 +399,7 @@ public class OrderService : IOrderService
}
}
- var dayCostMax = GetSetting(settings, CanteenSettingItemEnumType.DayCostMax);
+ var dayCostMax = await GetSettingAsync(CanteenSettingItemEnumType.DayCostMax);
if (dayCostMax != default)
{
var cost = balanceRecords.Where(x => x.Type == BalanceRecordTypeEnumType.Out).Sum(x => Math.Abs(x.Amount));
@@ -659,15 +420,15 @@ public class OrderService : IOrderService
///
private async Task GenerateRechargeRecordAsync(long orderId)
{
- var order = await _dbContext.Queryable().Where(x => x.Id == orderId).FirstAsync();
+ var order = await DbContext.Queryable().Where(x => x.Id == orderId).FirstAsync();
await ContinueUpdateAsync(async () =>
{
- var canteenUser = await _dbContext.Queryable().Where(x => x.UserNo == order.UserNo).FirstAsync();
+ var canteenUser = await DbContext.Queryable().Where(x => x.UserNo == order.UserNo).FirstAsync();
//金额+-
canteenUser.Balance += order.Amount;
- var effect = await _dbContext.Updateable()
+ var effect = await DbContext.Updateable()
.SetColumns(x => x.Balance == canteenUser.Balance)
.SetColumns(x => x.Version == x.Version + 1)
.Where(x => x.UserNo == order.UserNo && x.Version == canteenUser.Version)
@@ -677,7 +438,7 @@ public class OrderService : IOrderService
//写入记录
var balanceRecord = order.Adapt();
- await _dbContext.InsertAsync(balanceRecord);
+ await DbContext.InsertAsync(balanceRecord);
}, 5);
}
@@ -686,25 +447,24 @@ public class OrderService : IOrderService
/// 生成充值记录
///
///
- ///
///
///
///
///
///
- private async Task GenerateConsumeRecordAsync(long orderId, Dictionary settings, List shifts, DateTime costDateTime)
+ private async Task GenerateConsumeRecordAsync(long orderId, List shifts, DateTime costDateTime)
{
- var order = await _dbContext.Queryable().Where(x => x.Id == orderId).FirstAsync();
+ var order = await DbContext.Queryable().Where(x => x.Id == orderId).FirstAsync();
//校验
- await Verify(settings, shifts, costDateTime, order);
+ await Verify(shifts, costDateTime, order);
- var allowNoBalance = GetSetting(settings, CanteenSettingItemEnumType.AllowNoBalance);
+ var allowNoBalance = await GetSettingAsync(CanteenSettingItemEnumType.AllowNoBalance);
await ContinueUpdateAsync(async () =>
{
if (!allowNoBalance)
{
- var canteenUser = await _dbContext.Queryable().Where(x => x.UserNo == order.UserNo).FirstAsync();
+ var canteenUser = await DbContext.Queryable().Where(x => x.UserNo == order.UserNo).FirstAsync();
//金额+-
canteenUser.Balance += order.Amount;
if (canteenUser.Balance < 0)
@@ -712,7 +472,7 @@ public class OrderService : IOrderService
throw new UserFriendlyException("余额不足,无法消费");
}
- var effect = await _dbContext.Updateable()
+ var effect = await DbContext.Updateable()
.SetColumns(x => x.Balance == canteenUser.Balance)
.SetColumns(x => x.Version == x.Version + 1)
.Where(x => x.UserNo == order.UserNo && x.Version == canteenUser.Version)//必须与查询时的version一致
@@ -723,39 +483,10 @@ public class OrderService : IOrderService
//写入记录
var balanceRecord = order.Adapt();
- await _dbContext.InsertAsync(balanceRecord);
+ await DbContext.InsertAsync(balanceRecord);
}, 5);
}
- ///
- /// 检查我的订餐是否存在,存在抛出异常
- ///
- ///
- ///
- ///
- private async Task CheckExistsMyBookingsAsync(DateTime bookingDate, ShiftEnumType shiftType)
- {
- 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 start = bookingDate.Date.AddDays(-1);
- var end = start.AddDays(1).AddSeconds(-1);
-
- var exists = await _dbContext.Queryable()
- .Where(x => x.ApplicationType == CanteenApplicaitonTypeEnumType.Booking)
- .Where(x => x.ShiftType == shiftType)
- .Where(x => x.UserNo == gainfo.No)
- .Where(x => x.CreateTime >= start && x.CreateTime <= end)
- .AnyAsync();
-
- exists.ThrowIfTrue("不可重复订餐");
-
- return gainfo;
- }
}
diff --git a/Src/Dlhis.Entity/Basic/Entity/MealSupplementRecordEntity.cs b/Src/Dlhis.Entity/Canteen/Entities/MealSupplementRecordEntity.cs
similarity index 94%
rename from Src/Dlhis.Entity/Basic/Entity/MealSupplementRecordEntity.cs
rename to Src/Dlhis.Entity/Canteen/Entities/MealSupplementRecordEntity.cs
index ef31764d..7875ae74 100644
--- a/Src/Dlhis.Entity/Basic/Entity/MealSupplementRecordEntity.cs
+++ b/Src/Dlhis.Entity/Canteen/Entities/MealSupplementRecordEntity.cs
@@ -3,7 +3,7 @@ using Kurisu.SqlSugar;
using SqlSugar;
using SqlSugar.DbConvert;
-namespace Dlhis.Entity.Basic.Entity;
+namespace Dlhis.Entity.Canteen.Entities;
///
/// 餐补记录
@@ -12,7 +12,7 @@ namespace Dlhis.Entity.Basic.Entity;
public class MealSupplementRecordEntity : MealSupplementRequestRecordEntity
{
///
- /// 唯一号
+ /// 唯一号(流水号)
///
[SugarColumn(IsNullable = false, ColumnDescription = "唯一号", UniqueGroupNameList = new[] { "idx_MealSupplementRecord_UniqueId" })]
public override string UniqueId { get; set; }
@@ -41,6 +41,10 @@ public class MealSupplementRecordEntity : MealSupplementRequestRecordEntity
public bool Sync { get; set; }
}
+
+///
+/// 餐补请求记录
+///
[SugarTable(TableName = "MealSupplementRequestRecord", TableDescription = "餐补请求记录")]
public class MealSupplementRequestRecordEntity : SugarBaseEntity
{
diff --git a/Src/Dlhis.Entity/Canteen/Enums/BalanceRecordSourceEnumType.cs b/Src/Dlhis.Entity/Canteen/Enums/BalanceRecordSourceEnumType.cs
index 73c52bc0..ab2d91bc 100644
--- a/Src/Dlhis.Entity/Canteen/Enums/BalanceRecordSourceEnumType.cs
+++ b/Src/Dlhis.Entity/Canteen/Enums/BalanceRecordSourceEnumType.cs
@@ -57,12 +57,12 @@ public enum BalanceRecordSourceEnumType
///
/// 来自本基地补贴
///
- [Description("本基地补贴")]
+ [Description("本基地餐补")]
LocalTenantSubsidies = 300,
///
/// 来自其他基地补贴
///
- [Description("其他基地补贴")]
+ [Description("其他基地餐补")]
OtherTenantSubsidies,
}
\ No newline at end of file
diff --git a/Src/Dlhis.Entity/Canteen/Enums/CanteenOrderStatusEnumType.cs b/Src/Dlhis.Entity/Canteen/Enums/CanteenOrderStatusEnumType.cs
index 9a670e93..d1a689e5 100644
--- a/Src/Dlhis.Entity/Canteen/Enums/CanteenOrderStatusEnumType.cs
+++ b/Src/Dlhis.Entity/Canteen/Enums/CanteenOrderStatusEnumType.cs
@@ -3,9 +3,9 @@
namespace Dlhis.Entity.Canteen.Enums;
///
-/// 就餐订单状态
+/// 餐饮订单状态
///
-[Description("就餐订单状态")]
+[Description("餐饮订单状态")]
public enum CanteenOrderStatusEnumType
{
///
@@ -18,7 +18,7 @@ public enum CanteenOrderStatusEnumType
/// 成功
///
[Description("成功")]
- Successful = 1,
+ Success = 1,
///
/// 取消
diff --git a/Src/Dlhis.External/MealSupplement/Channel/MealSupplementHandler.cs b/Src/Dlhis.External/MealSupplement/Channel/MealSupplementHandler.cs
index 25622039..fad99d18 100644
--- a/Src/Dlhis.External/MealSupplement/Channel/MealSupplementHandler.cs
+++ b/Src/Dlhis.External/MealSupplement/Channel/MealSupplementHandler.cs
@@ -1,4 +1,4 @@
-using Dlhis.Entity.Basic.Entity;
+using Dlhis.Entity.Canteen.Entities;
using Dlhis.External.MealSupplement.Request;
using Kurisu.AspNetCore.EventBus.Abstractions;
using Kurisu.AspNetCore.EventBus.Abstractions.Handler;
diff --git a/Src/Dlhis.External/MealSupplement/Services/Implements/MealSupplementService.cs b/Src/Dlhis.External/MealSupplement/Services/Implements/MealSupplementService.cs
index 701b9430..bb1f1200 100644
--- a/Src/Dlhis.External/MealSupplement/Services/Implements/MealSupplementService.cs
+++ b/Src/Dlhis.External/MealSupplement/Services/Implements/MealSupplementService.cs
@@ -1,4 +1,4 @@
-using Dlhis.Entity.Basic.Entity;
+using Dlhis.Entity.Canteen.Entities;
using Dlhis.External.MealSupplement.Channel;
using Dlhis.External.MealSupplement.Request;
using Kurisu.AspNetCore.EventBus.Abstractions;
diff --git a/Src/Dlhis.Sys.Api/IUserApi.cs b/Src/Dlhis.Sys.Api/IUserApi.cs
index 643fce04..fba7db5f 100644
--- a/Src/Dlhis.Sys.Api/IUserApi.cs
+++ b/Src/Dlhis.Sys.Api/IUserApi.cs
@@ -10,4 +10,8 @@ public interface IUserApi
[Auth]
[Get("/api/users")]
Task> GetUserByIdAsync(int id);
+
+ [Auth]
+ [Post("/api/users/by-ids")]
+ Task>> GetUserByIdsAsync(List ids);
}
\ No newline at end of file
diff --git a/Src/Dlhis.Sys/Identity/Controllers/UsersController.cs b/Src/Dlhis.Sys/Identity/Controllers/UsersController.cs
index 229708bc..2a87166e 100644
--- a/Src/Dlhis.Sys/Identity/Controllers/UsersController.cs
+++ b/Src/Dlhis.Sys/Identity/Controllers/UsersController.cs
@@ -56,6 +56,13 @@ public class UsersController : ControllerBase
return await _userService.GetUserByIdAsync(id);
}
+ [Authorize]
+ [HttpPost("by-ids")]
+ public async Task> GetUserByIdsAsync(List ids)
+ {
+ return await _userService.GetUserByIdsAsync(ids);
+ }
+
///
/// 上传头像
///
diff --git a/Src/Dlhis.Sys/Identity/Services/IUserService.cs b/Src/Dlhis.Sys/Identity/Services/IUserService.cs
index 98932a32..619f6e78 100644
--- a/Src/Dlhis.Sys/Identity/Services/IUserService.cs
+++ b/Src/Dlhis.Sys/Identity/Services/IUserService.cs
@@ -15,4 +15,7 @@ public interface IUserService : IScopeDependency
Task GetUserByIdAsync(int id);
Task UploadUserAvatarAsync(UserAvatarUploadRequest request);
+
+
+ Task> GetUserByIdsAsync(List ids);
}
diff --git a/Src/Dlhis.Sys/Identity/Services/Implements/UserService.cs b/Src/Dlhis.Sys/Identity/Services/Implements/UserService.cs
index 55877e73..1f61bff3 100644
--- a/Src/Dlhis.Sys/Identity/Services/Implements/UserService.cs
+++ b/Src/Dlhis.Sys/Identity/Services/Implements/UserService.cs
@@ -12,11 +12,9 @@ public class UserService : IUserService
{
private readonly IDbContext _dbContext;
- public UserService(IDbContext dbContext, IConfiguration configuration)
+ public UserService(IDbContext dbContext)
{
- var identityConnection = configuration.GetSection("SqlSugarOptions:IdentityConnectionString").Value;
- dbContext.Client.CurrentConnectionConfig.ConnectionString = identityConnection;
- _dbContext = dbContext;
+ _dbContext = dbContext.ChangeDb("identity");
}
public async Task> GetPageAsync(UserPageRequest request)
@@ -63,4 +61,10 @@ public class UserService : IUserService
{
var user = await _dbContext.Queryable().Where(x => x.Id == request.UserNo).Select().FirstAsync();
}
+
+ public async Task> GetUserByIdsAsync(List ids)
+ {
+ var users = await _dbContext.Queryable().Where(x => ids.Contains(x.Id)).Select().ToListAsync();
+ return users;
+ }
}
diff --git a/Src/Dlhis.Sys/SqlSugarPack.cs b/Src/Dlhis.Sys/SqlSugarPack.cs
index 9458f466..98f4153a 100644
--- a/Src/Dlhis.Sys/SqlSugarPack.cs
+++ b/Src/Dlhis.Sys/SqlSugarPack.cs
@@ -16,7 +16,7 @@ public class SqlSugarPack : BaseAppPack
return new List
{
- new ConnectionConfig
+ new()
{
ConfigId = "identity",