Browse Source

添加餐厅信息管理功能

在 `Program.cs` 中初始化餐厅信息表。
在 `GroupsController.cs` 中引入 `RestaurantRepository`,并添加多个 API 方法以处理餐厅相关操作。
定义餐厅相关的 DTO 和实体类,包括 `RestaurantInfoDto`、`RestaurantOpDto`、`Grp_RestaurantInfo` 等。
在 `RestaurantRepository.cs` 中实现餐厅信息的仓储逻辑。
更新 `AutoMapper` 映射配置以支持餐厅数据模型的转换。
LEIYI 1 week ago
parent
commit
ca58c21e13

+ 1 - 0
OASystem/EntitySync/Program.cs

@@ -147,5 +147,6 @@ db.CodeFirst.SetStringDefaultLength(50).BackupTable().InitTables(new Type[]
     //typeof(Res_BasicInsuranceCost)//保险国家基础费用 
     //typeof(Grp_EnterExitCostPermission),//团组 - 出入境费用 --> 操作权限
     //typeof(Grp_EnterExitCostDraftPermission)//团组 - 出入境费用 --> 操作权限-草稿
+    typeof(Grp_RestaurantInfo)
 });
 Console.WriteLine("数据库结构同步完成!");

+ 96 - 3
OASystem/OASystem.Api/Controllers/GroupsController.cs

@@ -4,6 +4,7 @@ using Aspose.Words.Drawing;
 using Aspose.Words.Tables;
 using DiffMatchPatch;
 using Microsoft.AspNetCore.SignalR;
+using Microsoft.EntityFrameworkCore.Query.Internal;
 using NPOI.HSSF.UserModel;
 using NPOI.SS.UserModel;
 using NPOI.SS.Util;
@@ -103,6 +104,7 @@ namespace OASystem.API.Controllers
         private readonly List<int> _portTypeData;
         private readonly TableOperationRecordRepository _tableorRep;
         private readonly EnterExitCostDraftRepository _enterExitCostDraftRep;
+        private readonly RestaurantRepository _restaurantRep;
 
         /// <summary>
         /// 构造函数
@@ -144,6 +146,8 @@ namespace OASystem.API.Controllers
         /// <param name="ffrRep"></param>
         /// <param name="opinionaireRep"></param>
         /// <param name="tableorRep"></param>
+        /// <param name="enterExitCostDraftRep"></param>
+        /// <param name="restaurantRep"></param>
         public GroupsController(
             ILogger<GroupsController> logger,
             IMapper mapper,
@@ -181,7 +185,8 @@ namespace OASystem.API.Controllers
             ForeignReceivablesRepository ffrRep,
             OpinionaireRepository opinionaireRep,
             TableOperationRecordRepository tableorRep,
-            EnterExitCostDraftRepository enterExitCostDraftRep
+            EnterExitCostDraftRepository enterExitCostDraftRep,
+            RestaurantRepository restaurantRep
             )
         {
             _logger = logger;
@@ -237,6 +242,7 @@ namespace OASystem.API.Controllers
             _portTypeData = new List<int>() { 2, 3 };
             _tableorRep = tableorRep;
             _enterExitCostDraftRep = enterExitCostDraftRep;
+            _restaurantRep = restaurantRep;
 
         }
 
@@ -8857,11 +8863,11 @@ FROM
                 var permissions = new List<Grp_EnterExitCostPermission>();
                 if (userIds.Any())
                 {
-                    foreach (var userId in userIds)
+                    foreach (var userId1 in userIds)
                     {
                         permissions.Add(new Grp_EnterExitCostPermission() { 
                             GroupId = groupId,
-                            UserId = userId,
+                            UserId = userId1,
                             CreateUserId = dto.UserId
                         });
                     }
@@ -19810,6 +19816,93 @@ ORDER BY
 
         #endregion
 
+        #region 团组餐厅相关信息
+
+        /// <summary>
+        /// 团组相关餐厅信息
+        /// 基础数据(团组)
+        /// </summary>
+        /// <returns></returns>
+        [HttpGet]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> RestaurantInit()
+        {
+            return Ok(await _restaurantRep.InitAsync());
+        }
+
+        /// <summary>
+        /// 团组相关餐厅信息
+        /// Item
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> RestaurantItem(RestaurantItemDto dto)
+        {
+            int portType = dto.PortType,
+                groupId = dto.GroupId;
+            if (!SharingStaticData.PortTypes.Contains(portType)) return Ok(JsonView(false,MsgTips.Port));
+            if (groupId < 1) return Ok(JsonView(false, MsgTips.DiId));
+
+            return Ok(await _restaurantRep.ItemAsync(portType,groupId));
+        }
+
+        /// <summary>
+        /// 团组相关餐厅信息
+        /// Info
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> RestaurantInfo(RestaurantInfoDto dto)
+        {
+            int portType = dto.PortType,
+                id = dto.Id;
+            if (!SharingStaticData.PortTypes.Contains(portType)) return Ok(JsonView(false, MsgTips.Port));
+            if (id < 1) return Ok(JsonView(false, MsgTips.Id));
+
+            return Ok(await _restaurantRep.InfoAsync(portType, id));
+        }
+
+        /// <summary>
+        /// 团组相关餐厅信息
+        /// Op
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> RestaurantOp(RestaurantOpDto dto)
+        {
+            if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
+            if (dto.GroupId < 1) return Ok(JsonView(false, MsgTips.DiId));
+            if ( string.IsNullOrEmpty(dto.Name)) return Ok(JsonView(false, "餐厅名称为空!"));
+
+            return Ok(await _restaurantRep.OpAsync(dto));
+        }
+
+        /// <summary>
+        /// 团组相关餐厅信息
+        /// Del
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> RestaurantDel(RestaurantDelDto dto)
+        {
+            int userId = dto.DeleteUserId;
+            var id = dto.Id;
+
+            if (userId < 1) return Ok( JsonView(false, MsgTips.UserId));
+            if (id < 1) return Ok(JsonView(false, MsgTips.Id));
+
+            return Ok(await _restaurantRep.DelAsync(dto));
+        }
+        #endregion
+
         //        /// <summary>
         //        /// 
         //        /// </summary>

+ 7 - 0
OASystem/OASystem.Domain/AutoMappers/_baseMappingProfile.cs

@@ -116,6 +116,13 @@ namespace OASystem.Domain.AutoMappers
             CreateMap<OpDelegationEnDataDto, Grp_DelegationEnData>();
             #endregion
 
+            #region 餐厅资料
+
+
+            CreateMap<Grp_RestaurantInfo, RestaurantInfoView>();
+            CreateMap<RestaurantOpDto, Grp_RestaurantInfo>();
+            #endregion
+
             #region 出入境费用明细
 
             CreateMap<Grp_EnterExitCost, EnterExitCostInfoView>();

+ 37 - 0
OASystem/OASystem.Domain/Dtos/Groups/RestaurantDtos.cs

@@ -0,0 +1,37 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Domain.Dtos.Groups
+{
+    public class RestaurantDtos
+    {
+    }
+
+    public class RestaurantInfoDto : PortDtoBase
+    {
+        public int Id { get; set; }
+    }
+
+    public class RestaurantOpDto : ViewModels.Groups.RestaurantInfoView
+    {
+        public int CurrUserId { get; set; }
+
+        /// <summary>
+        /// 操作状态
+        /// 1 添加 2 编辑 
+        /// </summary>
+        public int Status { get; set; }
+    }
+
+    public class RestaurantItemDto : PortDtoBase
+    {
+        public int GroupId { get; set; }
+    }
+
+    public class RestaurantDelDto : DelBaseDto
+    {
+    }
+}

+ 64 - 0
OASystem/OASystem.Domain/Entities/Groups/Grp_RestaurantInfo.cs

@@ -0,0 +1,64 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Domain.Entities.Groups
+{
+    /// <summary>
+    /// 餐厅信息
+    /// </summary>
+    [SugarTable("Grp_RestaurantInfo", "餐厅信息")]
+    public  class Grp_RestaurantInfo : EntityBase
+    {
+        /// <summary>
+        /// 团组Id
+        /// </summary>
+        [SugarColumn(ColumnDescription = "团组Id", IsNullable = true, ColumnDataType = "int")]
+        public int GroupId { get; set; }
+
+        /// <summary>
+        /// 用餐日期(2024-12-31)
+        /// </summary>
+        [SugarColumn(ColumnDescription = "用餐日期(2024-12-31)", IsNullable = true, ColumnDataType = "varchar(30)")]
+        public string Date { get; set; }
+
+        /// <summary>
+        ///  用餐开始时间(08:00)
+        /// </summary>
+        [SugarColumn(ColumnDescription = " 用餐开始时间(08:00)", IsNullable = true, ColumnDataType = "varchar(30)")]
+        public string StartTime { get; set; }
+
+        /// <summary>
+        ///  用餐结束时间(10:00)
+        /// </summary>
+        [SugarColumn(ColumnDescription = " 用餐结束时间(10:00)", IsNullable = true, ColumnDataType = "varchar(30)")]
+        public string EndTime { get; set; }
+
+        /// <summary>
+        /// 用餐类型(1:早餐; 2:午餐; 3:晚餐;)
+        /// </summary>
+        [SugarColumn(ColumnDescription = "用餐类型(1:早餐; 2:午餐; 3:晚餐;)", IsNullable = true, ColumnDataType = "int")]
+        public int Type { get; set; }
+
+        /// <summary>
+        /// 餐厅名称
+        /// </summary>
+        [SugarColumn(ColumnDescription = "餐厅名称", IsNullable = true, ColumnDataType = "nvarchar(200)")]
+        public string Name { get; set; }
+
+        /// <summary>
+        /// 餐厅电话
+        /// </summary>
+        [SugarColumn(ColumnDescription = "餐厅电话", IsNullable = true, ColumnDataType = "nvarchar(100)")]
+        public string Tel { get; set; }
+
+        /// <summary>
+        /// 餐厅地址
+        /// </summary>
+        [SugarColumn(ColumnDescription = "餐厅地址", IsNullable = true, ColumnDataType = "nvarchar(300)")]
+        public string Address { get; set; }
+
+    }
+}

+ 62 - 0
OASystem/OASystem.Domain/ViewModels/Groups/RestaurantView.cs

@@ -0,0 +1,62 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Domain.ViewModels.Groups
+{
+    public class RestaurantView
+    {
+    }
+
+    public class RestaurantInfoView
+    {
+        public int Id { get; set; }
+
+        /// <summary>
+        /// 团组Id
+        /// </summary>
+        public int GroupId { get; set; }
+
+        /// <summary>
+        /// 用餐日期(2024-12-31)
+        /// </summary>
+        public string Date { get; set; }
+
+        /// <summary>
+        ///  用餐开始时间(08:00)
+        /// </summary>
+        public string StartTime { get; set; }
+
+        /// <summary>
+        ///  用餐结束时间(10:00)
+        /// </summary>
+        public string EndTime { get; set; }
+
+        /// <summary>
+        /// 用餐类型(1:早餐; 2:午餐; 3:晚餐;)
+        /// </summary>
+        public int Type { get; set; }
+
+        /// <summary>
+        /// 餐厅名称
+        /// </summary>
+        public string Name { get; set; }
+
+        /// <summary>
+        /// 餐厅电话
+        /// </summary>
+        public string Tel { get; set; }
+
+        /// <summary>
+        /// 餐厅地址
+        /// </summary>
+        public string Address { get; set; }
+
+        /// <summary>
+        /// 其他信息
+        /// </summary>
+        public string Remark { get; set; }
+    }
+}

+ 157 - 0
OASystem/OASystem.Infrastructure/Repositories/Groups/RestaurantRepository.cs

@@ -0,0 +1,157 @@
+using AutoMapper;
+using NPOI.SS.Formula.Functions;
+using OASystem.Domain;
+using OASystem.Domain.Dtos.Groups;
+using OASystem.Domain.Dtos.System;
+using OASystem.Domain.Entities.Groups;
+using OASystem.Domain.ViewModels.Groups;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Infrastructure.Repositories.Groups
+{
+    /// <summary>
+    /// 餐厅信息 仓储
+    /// </summary>
+    public class RestaurantRepository : BaseRepository<Grp_RestaurantInfo, Grp_RestaurantInfo>
+    {
+        private readonly IMapper _mapper;
+        private readonly JsonView _jsonView;
+        public RestaurantRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
+        {
+            _mapper = mapper;
+            _jsonView = new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "操作失败" };
+        }
+
+        /// <summary>
+        /// 基础数据源
+        /// </summary>
+        /// <returns></returns>
+        public async Task<JsonView> InitAsync()
+        {
+            var groupData = await _sqlSugar
+                .Queryable<Grp_DelegationInfo>()
+                .Where(x => x.IsDel == 0)
+                .OrderByDescending(x => x.Id)
+                .Select(x => new { Id = x.Id, GroupName = x.TeamName })
+                .ToListAsync();
+
+            var mealTypeData = new List<dynamic>() {
+                new { Id = 1, Name = "早餐", DefaultStartTime = "08:00" },
+                new { Id = 2, Name = "午餐", DefaultStartTime = "12:00" },
+                new { Id = 3, Name = "晚餐", DefaultStartTime = "18:00" }
+            };
+            _jsonView.Code = StatusCodes.Status200OK;
+            _jsonView.Msg = "操作成功!";
+            _jsonView.Data = new { groupData = groupData ,mealType = mealTypeData };
+            return _jsonView;
+        }
+
+        /// <summary>
+        /// 详情
+        /// </summary>
+        /// <returns></returns>
+        public async Task<JsonView> InfoAsync(int portType, int id)
+        {
+            if (!SharingStaticData.PortTypes.Contains(portType)) return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "端口类型错误!" };
+            if (id < 1) return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = MsgTips.Id };
+
+            var info = await _sqlSugar.Queryable<Grp_RestaurantInfo>()
+                .Where(x => x.IsDel == 0 && x.Id == id)
+                .FirstAsync();
+            if (info == null) return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "数据未填写!", Data = new { } };
+
+            var resData = _mapper.Map<RestaurantInfoView>(info);
+
+            return new JsonView() { Code = StatusCodes.Status200OK, Msg = "操作成功!", Data = resData };
+        }
+
+        /// <summary>
+        /// Item
+        /// </summary>
+        /// <returns></returns>
+        public async Task<JsonView> ItemAsync(int portType, int groupId)
+        {
+            if (!SharingStaticData.PortTypes.Contains(portType)) return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "端口类型错误!" };
+            if (groupId < 1) return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = MsgTips.DiId };
+
+            var infos = await _sqlSugar
+                .Queryable<Grp_RestaurantInfo, Sys_Users>((pi, u) => new JoinQueryInfos(JoinType.Left, pi.CreateUserId == u.Id))
+                .Where((pi, u) => pi.IsDel == 0 && pi.GroupId == groupId)
+                .OrderByDescending((pi, u) => pi.Date)
+                .Select((pi, u) => new
+                {
+                    pi.Id,
+                    //pi.GroupId,
+                    pi.Date,
+                    pi.StartTime,
+                    pi.EndTime,
+                    Type = pi.Type == 1 ? "早餐" : pi.Type == 2 ? "午餐" : pi.Type == 3 ? "晚餐" : "其他",
+                    pi.Name,
+                    pi.Address,
+                    pi.Tel,
+                    pi.Remark
+                })
+                .OrderByDescending(x => x.Date) 
+                .ToListAsync();
+            if (!infos.Any()) return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "数据未填写!",Data = Array.Empty<dynamic>() };
+
+            return new JsonView() { Code = StatusCodes.Status200OK, Msg = "操作成功!", Data = infos };
+        }
+
+        /// <summary>
+        /// 操作
+        /// </summary>
+        /// <returns></returns>
+        public async Task<JsonView> OpAsync(RestaurantOpDto dto)
+        {
+            int status = dto.Status;
+            var info = _mapper.Map<Grp_RestaurantInfo>(dto);
+            info.CreateUserId = dto.CurrUserId;
+            if (status == 1)
+            {
+                //验重
+                var isNull = await _sqlSugar.Queryable<Grp_RestaurantInfo>().Where(x => x.IsDel == 0 && x.GroupId == info.GroupId && x.Name.Equals(info.Name)).FirstAsync();
+                if (isNull != null) return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "该团组下该餐厅名称已存在,不可重复添加!", Data = new { } };
+
+                var infoId = await _sqlSugar.Insertable(info).ExecuteCommandAsync();
+                if (infoId < 1) return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "添加失败!", Data = new { } };
+            }
+            else if (status == 2)
+            {
+                if (dto.Id < 1) return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = MsgTips.Id, Data = new { } };
+
+                var infoId = await _sqlSugar.Updateable(info).IgnoreColumns(x => new { x.DeleteTime, x.DeleteUserId, x.CreateUserId, x.CreateTime, x.IsDel }).ExecuteCommandAsync();
+                if (infoId < 1) return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "修改失败!", Data = new { } };
+
+            }
+            else new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "请传入有效的Status!", Data = new { } };
+
+            return new JsonView() { Code = StatusCodes.Status200OK, Msg = "操作成功!", Data = new { } };
+        }
+
+        /// <summary>
+        /// 操作
+        /// </summary>
+        /// <returns></returns>
+        public async Task<JsonView> DelAsync(RestaurantDelDto dto)
+        {
+            int userId = dto.DeleteUserId;
+            var id = dto.Id;
+
+            if (userId < 1) return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = MsgTips.UserId, Data = new { } };
+            if (id < 1) return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = MsgTips.Id, Data = new { } };
+
+            var del = await _sqlSugar.Updateable<Grp_RestaurantInfo>()
+                .SetColumns(x => new Grp_RestaurantInfo() { DeleteUserId = userId, DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), IsDel = 1 })
+                .Where(x => x.Id == id)
+                .ExecuteCommandAsync();
+            if(del < 1) return new JsonView() { Code = StatusCodes.Status200OK, Msg = "删除失败!", Data = new { } };
+
+            return new JsonView() { Code = StatusCodes.Status200OK, Msg = "操作成功!", Data = new { } };
+        }
+    }
+}