diff --git a/Src/Dlhis.Canteen/EMealVoucher/Controllers/EMealVoucherController.cs b/Src/Dlhis.Canteen/EMealVoucher/Controllers/EMealVoucherController.cs new file mode 100644 index 00000000..98e2f3ed --- /dev/null +++ b/Src/Dlhis.Canteen/EMealVoucher/Controllers/EMealVoucherController.cs @@ -0,0 +1,11 @@ +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; + +namespace Dlhis.Canteen.EMealVoucher.Controllers; + +[Authorize] +[Route("api/[controller]")] +[ApiController] +public class EMealVoucherController : ControllerBase +{ +} \ No newline at end of file diff --git a/Src/Dlhis.Entity/Canteen/Entities/EMealVoucherDetailEntity.cs b/Src/Dlhis.Entity/Canteen/Entities/EMealVoucherDetailEntity.cs new file mode 100644 index 00000000..b41f0533 --- /dev/null +++ b/Src/Dlhis.Entity/Canteen/Entities/EMealVoucherDetailEntity.cs @@ -0,0 +1,65 @@ +using Kurisu.AspNetCore.DataAccess.SqlSugar; +using SqlSugar; + +namespace Dlhis.Entity.Canteen.Entities; + +/// +/// 电子餐券明细 +/// +[SugarTable(TableName = "EMealVoucherDetail", TableDescription = "电子餐券明细")] +public class EMealVoucherDetailEntity : SugarBaseEntity +{ + /// + /// 主表id + /// + [SugarColumn(ColumnDescription = "主表id")] + public long VoucherId { get; set; } + + /// + /// 流水号 + /// + [SugarColumn(ColumnDescription = "流水号")] + public string No { get; set; } + + /// + /// 人员类型 + /// + [SugarColumn(ColumnDescription = "人员类型(新员工/外来人员)")] + public string UserType { get; set; } + + /// + /// 身份证 + /// + [SugarColumn(ColumnDescription = "序号")] + public string IdNo { get; set; } + + /// + /// 用餐人 + /// + [SugarColumn(ColumnDescription = "用餐人")] + public string Name { get; set; } + + /// + /// 手机号 + /// + [SugarColumn(ColumnDescription = "手机号")] + public string Phone { get; set; } + + /// + /// 就餐开始 + /// + [SugarColumn(ColumnDescription = "使用开始", ColumnDataType = "date")] + public DateTime Start { get; set; } + + /// + /// 就餐结束 + /// + [SugarColumn(ColumnDescription = "使用结束", ColumnDataType = "date")] + public DateTime End { get; set; } + + /// + /// 金额 + /// + [SugarColumn(ColumnDescription = "金额", ColumnDataType = "decimal(16,2)")] + public decimal Amount { get; set; } +} \ No newline at end of file diff --git a/Src/Dlhis.Entity/Canteen/Entities/EMealVoucherEntity.cs b/Src/Dlhis.Entity/Canteen/Entities/EMealVoucherEntity.cs new file mode 100644 index 00000000..7ff544aa --- /dev/null +++ b/Src/Dlhis.Entity/Canteen/Entities/EMealVoucherEntity.cs @@ -0,0 +1,78 @@ +using Dlhis.Entity.Canteen.Enums; +using Kurisu.AspNetCore.DataAccess.SqlSugar; +using SqlSugar; + +namespace Dlhis.Entity.Canteen.Entities; + +/// +/// 餐券 +/// +[SugarTable(TableName = "EMealVoucher", TableDescription = "电子餐券")] +public class EMealVoucherEntity : SugarBaseEntity +{ + /// + /// oa流程id + /// + [SugarColumn(ColumnDescription = "oa流程id", UniqueGroupNameList = new[] { "index_EMealVoucher_No" })] + public string No { get; set; } + + /// + /// 标题 + /// + [SugarColumn(ColumnDescription = "标题")] + public string Title { get; set; } + + /// + /// 申请人工号 + /// + [SugarColumn(ColumnDescription = "申请人工号", IndexGroupNameList = new[] { "index_EMealVoucher_Code" })] + public string Code { get; set; } + + /// + /// 成本中心 + /// + [SugarColumn(ColumnDescription = "成本中心")] + public string CostId { get; set; } + + /// + /// 来宾公司 + /// + [SugarColumn(ColumnDescription = "来宾来源")] + public string Source { get; set; } + + /// + /// 联系人 + /// + [SugarColumn(ColumnDescription = "手机号")] + public string Phone { get; set; } + + /// + /// 来宾人数 + /// + [SugarColumn(ColumnDescription = "来宾人数")] + public int Number { get; set; } + + /// + /// 就餐事由 + /// + [SugarColumn(ColumnDescription = "申请事由")] + public string Reason { get; set; } + + /// + /// 就餐次 + /// + [SugarColumn(ColumnDescription = "就餐次", ColumnDataType = "varchar(500)", IsJson = true)] + public List Shifts { get; set; } + + /// + /// 可消费厂区 + /// + [SugarColumn(ColumnDescription = "可消费厂区", ColumnDataType = "varchar(500)", IsJson = true)] + public List Factories { get; set; } + + /// + /// 申请日期 + /// + [SugarColumn(ColumnDescription = "申请日期")] + public DateTime Date { get; set; } +} \ No newline at end of file diff --git a/Src/Dlhis.Entity/Canteen/Entities/OaEMealVoucherDetailEntity.cs b/Src/Dlhis.Entity/Canteen/Entities/OaEMealVoucherDetailEntity.cs deleted file mode 100644 index 3dd6c1c5..00000000 --- a/Src/Dlhis.Entity/Canteen/Entities/OaEMealVoucherDetailEntity.cs +++ /dev/null @@ -1,84 +0,0 @@ -using SqlSugar; - -namespace Dlhis.Entity.Canteen.Entities; - -/// -/// OA餐券明细 -/// -[SugarTable(TableName = "OaEMealVoucherDetail", TableDescription = "OA餐券明细")] -public class OaEMealVoucherDetailEntity -{ - public long Id { get; set; } - - - [SugarColumn(ColumnDescription = "餐券id")] - public long VoucherId { get; set; } - - - [SugarColumn(ColumnDescription = "序号")] - public int Sequence { get; set; } - - - [SugarColumn(ColumnDescription = "用餐人情况(新员工/外来人员)")] - public string DinnerType { get; set; } - - /// - /// 身份证 - /// - [SugarColumn(ColumnDescription = "序号")] - public string IdNo { get; set; } - - /// - /// 用餐人 - /// - [SugarColumn(ColumnDescription = "用餐人")] - public string Name { get; set; } - - /// - /// 手机号 - /// - [SugarColumn(ColumnDescription = "手机号")] - public string Phone { get; set; } - - /// - /// 就餐开始 - /// - [SugarColumn(ColumnDescription = "就餐开始")] - public DateTime Start { get; set; } - - /// - /// 就餐结束 - /// - [SugarColumn(ColumnDescription = "就餐结束")] - public DateTime End { get; set; } - - /// - /// 就餐天数 - /// - [SugarColumn(ColumnDescription = "就餐天数")] - public int Days { get; set; } - - /// - /// 金额 - /// - [SugarColumn(ColumnDescription = "金额")] - public decimal Amount { get; set; } - - /// - /// 二维码 - /// - [SugarColumn(ColumnDescription = "二维码")] - public string QrCode { get; set; } - - /// - /// 状态 - /// - [SugarColumn(ColumnDescription = "状态,默认为R")] - public string Status { get; set; } - - /// - /// 信息 - /// - [SugarColumn(ColumnDescription = "信息/错误信息")] - public string Message { get; set; } -} \ No newline at end of file diff --git a/Src/Dlhis.Entity/Canteen/Entities/OaEMealVoucherEntity.cs b/Src/Dlhis.Entity/Canteen/Entities/OaEMealVoucherEntity.cs deleted file mode 100644 index 4756edeb..00000000 --- a/Src/Dlhis.Entity/Canteen/Entities/OaEMealVoucherEntity.cs +++ /dev/null @@ -1,122 +0,0 @@ -using SqlSugar; - -namespace Dlhis.Entity.Canteen.Entities; - -/// -/// OA餐券 -/// -[SugarTable(TableName = "OaEMealVoucher", TableDescription = "OA餐券")] -public class OaEMealVoucherEntity -{ - [SugarColumn(IsIdentity = true, IsPrimaryKey = true)] - public long Id { get; set; } - - /// - /// 标题 - /// - [SugarColumn(ColumnDescription = "标题")] - public string Title { get; set; } - - /// - /// 申请人工号 - /// - [SugarColumn(ColumnDescription = "申请人工号")] - public string UserCode { get; set; } - - /// - /// 申请人名称 - /// - [SugarColumn(ColumnDescription = "申请人名称")] - public string Name { get; set; } - - /// - /// 基地代码 - /// - [SugarColumn(ColumnDescription = "基地代码")] - public string TenantId { get; set; } - - /// - /// 基地名称 - /// - [SugarColumn(ColumnDescription = "基地名称")] - public string TenantName { get; set; } - - /// - /// 成本中心 - /// - [SugarColumn(ColumnDescription = "成本中心")] - public string CostId { get; set; } - - /// - /// 成本中心名称 - /// - [SugarColumn(ColumnDescription = "成本中心名称")] - public string CostName { get; set; } - - /// - /// 来宾公司 - /// - [SugarColumn(ColumnDescription = "来宾公司")] - public string Company { get; set; } - - /// - /// 联系人 - /// - [SugarColumn(ColumnDescription = "联系人")] - public string Phone { get; set; } - - /// - /// 来宾人数 - /// - [SugarColumn(ColumnDescription = "来宾人数")] - public int Num { get; set; } - - /// - /// 就餐食堂 - /// - [SugarColumn(ColumnDescription = "就餐食堂")] - public string Canteen { get; set; } - - /// - /// 就餐事由 - /// - [SugarColumn(ColumnDescription = "就餐事由")] - public string Reason { get; set; } - - /// - /// 就餐次 - /// - [SugarColumn(ColumnDescription = "就餐次")] - public string CanteenShift { get; set; } - - /// - /// oa流程id - /// - [SugarColumn(ColumnDescription = "oa流程id")] - public string OaId { get; set; } - - /// - /// 部门号 - /// - [SugarColumn(ColumnDescription = "部门号")] - public string DepartmentNo { get; set; } - - /// - /// 部门名称 - /// - [SugarColumn(ColumnDescription = "部门名称")] - public string DepartmentName { get; set; } - - - /// - /// 申请日期 - /// - [SugarColumn(ColumnDescription = "申请日期")] - public DateTime LogDate { get; set; } - - /// - /// 数据创建时间 - /// - [SugarColumn(ColumnDescription = "数据创建时间")] - public DateTime CreateTime { get; set; } -} \ No newline at end of file diff --git a/Src/Dlhis.External/Dlhis.External.csproj b/Src/Dlhis.External/Dlhis.External.csproj index 31384e4a..772581d6 100644 --- a/Src/Dlhis.External/Dlhis.External.csproj +++ b/Src/Dlhis.External/Dlhis.External.csproj @@ -13,6 +13,7 @@ + diff --git a/Src/Dlhis.External/EMealVoucher/Controllers/EMealVoucherController.cs b/Src/Dlhis.External/EMealVoucher/Controllers/EMealVoucherController.cs new file mode 100644 index 00000000..e065ddf7 --- /dev/null +++ b/Src/Dlhis.External/EMealVoucher/Controllers/EMealVoucherController.cs @@ -0,0 +1,29 @@ +using Dlhis.External.EMealVoucher.Request; +using Dlhis.External.EMealVoucher.Services; +using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop; +using Microsoft.AspNetCore.Mvc; + +namespace Dlhis.External.EMealVoucher.Controllers; + +[Route("api/[controller]")] +[ApiController] +public class EMealVoucherController : ControllerBase +{ + private readonly IEMealVoucherService _eMealVoucherService; + + public EMealVoucherController(IEMealVoucherService eMealVoucherService) + { + _eMealVoucherService = eMealVoucherService; + } + + /// + /// 接收 + /// + /// + [HttpPost("receive")] + [Transactional] + public async Task Receive(EMealVoucherReceiveRequest request) + { + await _eMealVoucherService.ReceiveAsync(request); + } +} \ No newline at end of file diff --git a/Src/Dlhis.External/EMealVoucher/Request/EMealVoucherReceiveRequest.cs b/Src/Dlhis.External/EMealVoucher/Request/EMealVoucherReceiveRequest.cs new file mode 100644 index 00000000..86f3aa3f --- /dev/null +++ b/Src/Dlhis.External/EMealVoucher/Request/EMealVoucherReceiveRequest.cs @@ -0,0 +1,144 @@ +using System.ComponentModel.DataAnnotations; + +namespace Dlhis.External.EMealVoucher.Request; + +public class EMealVoucherReceiveRequest : IValidatableObject +{ + /// + /// 流水号 + /// + [Required(ErrorMessage = "流水号不能为空")] + public string No { get; set; } + + /// + /// 标题 + /// + [Required(ErrorMessage = "标题不能为空")] + public string Title { get; set; } + + /// + /// 工号 + /// + [Required(ErrorMessage = "工号不能为空")] + public string Code { get; set; } + + /// + /// 手机号 + /// + [Required(ErrorMessage = "成本中心不能为空")] + public string Phone { get; set; } + + /// + /// 申请日期 + /// + public DateTime Date { get; set; } + + /// + /// 成本中心 + /// + [Required(ErrorMessage = "成本中心不能为空")] + public string CostId { get; set; } + + /// + /// 来宾来源 + /// + [Required(ErrorMessage = "来宾来源不能为空")] + public string Source { get; set; } + + /// + /// 来宾数量 + /// + [Range(1, int.MaxValue, ErrorMessage = "来宾数量有误")] + public int Number { get; set; } + + /// + /// 申请事由 + /// + [Required(ErrorMessage = "申请事由不能为空")] + public string Reason { get; set; } + + /// + /// 餐别组合 早餐1;午餐2;晚餐3;夜宵4,凌晨餐5 + /// + [MinLength(1, ErrorMessage = "消费厂区不能为空")] + [MaxLength(5, ErrorMessage = "消费厂区不能为空")] + public List Shifts { get; set; } + + /// + /// 餐券可消费厂区代码,逗号分隔 + /// + [MinLength(1, ErrorMessage = "消费厂区不能为空")] + public List Factories { get; set; } + + /// + /// 明细 + /// + [MinLength(1, ErrorMessage = "明细不能为空")] + public List Details { get; set; } + + public IEnumerable Validate(ValidationContext validationContext) + { + if (Number != Details.Count) + { + yield return new ValidationResult("来宾数量不匹配", new[] { nameof(Number) }); + } + } +} + +public class EMealVoucherReceiveDetailRequest : IValidatableObject +{ + /// + /// 用户类型 新员工/外来人员 + /// + [Required(ErrorMessage = "用户类型不可为空")] + public string UserType { get; set; } + + /// + /// 身份证号 + /// + [Required(ErrorMessage = "身份证号不可为空")] + public string IdNo { get; set; } + + /// + /// 姓名 + /// + [Required(ErrorMessage = "姓名不可为空")] + public string Name { get; set; } + + /// + /// 手机号 + /// + [MinLength(11, ErrorMessage = "手机号不合法")] + [MaxLength(11, ErrorMessage = "手机号不合法")] + public string Phone { get; set; } + + /// + /// 使用开始 + /// + public DateTime Start { get; set; } + + /// + /// 使用结束 + /// + public DateTime End { get; set; } + + /// + /// 金额 + /// + [Range(0.01, double.MaxValue)] + public decimal Amount { get; set; } + + + public IEnumerable Validate(ValidationContext validationContext) + { + if (End <= DateTime.Now) + { + yield return new ValidationResult("使用结束时间不可小于当前时间", new[] { nameof(End) }); + } + + if (Start >= End) + { + yield return new ValidationResult("使用开始,使用结束时间有误", new[] { nameof(Start) }); + } + } +} \ No newline at end of file diff --git a/Src/Dlhis.External/EMealVoucher/Services/IEMealVoucherService.cs b/Src/Dlhis.External/EMealVoucher/Services/IEMealVoucherService.cs new file mode 100644 index 00000000..fd6c8dab --- /dev/null +++ b/Src/Dlhis.External/EMealVoucher/Services/IEMealVoucherService.cs @@ -0,0 +1,8 @@ +using Dlhis.External.EMealVoucher.Request; + +namespace Dlhis.External.EMealVoucher.Services; + +public interface IEMealVoucherService : IScopeDependency +{ + Task ReceiveAsync(EMealVoucherReceiveRequest request); +} \ No newline at end of file diff --git a/Src/Dlhis.External/EMealVoucher/Services/Implements/EMealVoucherService.cs b/Src/Dlhis.External/EMealVoucher/Services/Implements/EMealVoucherService.cs new file mode 100644 index 00000000..9e12372a --- /dev/null +++ b/Src/Dlhis.External/EMealVoucher/Services/Implements/EMealVoucherService.cs @@ -0,0 +1,53 @@ +using Dlhis.Entity.Canteen.Entities; +using Dlhis.Entity.Canteen.Enums; +using Dlhis.External.EMealVoucher.Request; +using Kurisu.AspNetCore.DataAccess.SqlSugar.Services; +using Kurisu.AspNetCore.Utils.Extensions; + +namespace Dlhis.External.EMealVoucher.Services.Implements; + +public class EMealVoucherService : IEMealVoucherService +{ + private readonly IDbContext _dbContext; + + public EMealVoucherService(IDbContext dbContext) + { + _dbContext = dbContext; + } + + public async Task ReceiveAsync(EMealVoucherReceiveRequest request) + { + (await _dbContext.Queryable().Where(x => x.No == request.No).AnyAsync()).ThrowIfTrue($"{request.No}已存在"); + + var voucher = new EMealVoucherEntity + { + No = request.No, + Title = request.Title, + Code = request.Code, + CostId = request.CostId, + Source = request.Source, + Phone = request.Phone, + Number = request.Number, + Reason = request.Reason, + Shifts = request.Shifts.Select(x => (ShiftEnumType)x).ToList(), + Date = request.Date, + Factories = request.Factories + }; + + var details = request.Details.Select(x => new EMealVoucherDetailEntity + { + No = request.No, + UserType = x.UserType, + IdNo = x.IdNo, + Name = x.Name, + Phone = x.Phone, + Start = x.Start, + End = x.End, + Amount = x.Amount + }).ToList(); + + var id = await _dbContext.InsertReturnIdentityAsync(voucher); + details.ForEach(x => x.VoucherId = id); + await _dbContext.InsertAsync(details); + } +} \ No newline at end of file