RestaurantRepository.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. using AutoMapper;
  2. using NPOI.SS.Formula.Functions;
  3. using OASystem.Domain;
  4. using OASystem.Domain.Dtos.Groups;
  5. using OASystem.Domain.Dtos.System;
  6. using OASystem.Domain.Entities.Groups;
  7. using OASystem.Domain.ViewModels.Groups;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace OASystem.Infrastructure.Repositories.Groups
  14. {
  15. /// <summary>
  16. /// 餐厅信息 仓储
  17. /// </summary>
  18. public class RestaurantRepository : BaseRepository<Grp_RestaurantInfo, Grp_RestaurantInfo>
  19. {
  20. private readonly IMapper _mapper;
  21. private readonly JsonView _jsonView;
  22. public RestaurantRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
  23. {
  24. _mapper = mapper;
  25. _jsonView = new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "操作失败" };
  26. }
  27. /// <summary>
  28. /// 基础数据源
  29. /// </summary>
  30. /// <returns></returns>
  31. public async Task<JsonView> InitAsync()
  32. {
  33. var groupData = await _sqlSugar
  34. .Queryable<Grp_DelegationInfo>()
  35. .Where(x => x.IsDel == 0)
  36. .OrderByDescending(x => x.Id)
  37. .Select(x => new { Id = x.Id, GroupName = x.TeamName })
  38. .ToListAsync();
  39. var mealTypeData = new List<dynamic>() {
  40. new { Id = 1, Name = "早餐", DefaultStartTime = "08:00" },
  41. new { Id = 2, Name = "午餐", DefaultStartTime = "12:00" },
  42. new { Id = 3, Name = "晚餐", DefaultStartTime = "18:00" }
  43. };
  44. _jsonView.Code = StatusCodes.Status200OK;
  45. _jsonView.Msg = "操作成功!";
  46. _jsonView.Data = new { groupData = groupData ,mealType = mealTypeData };
  47. return _jsonView;
  48. }
  49. /// <summary>
  50. /// 详情
  51. /// </summary>
  52. /// <returns></returns>
  53. public async Task<JsonView> InfoAsync(int portType, int id)
  54. {
  55. if (!SharingStaticData.PortTypes.Contains(portType)) return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "端口类型错误!" };
  56. if (id < 1) return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = MsgTips.Id };
  57. var info = await _sqlSugar.Queryable<Grp_RestaurantInfo>()
  58. .Where(x => x.IsDel == 0 && x.Id == id)
  59. .FirstAsync();
  60. if (info == null) return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "数据未填写!", Data = new { } };
  61. var resData = _mapper.Map<RestaurantInfoView>(info);
  62. return new JsonView() { Code = StatusCodes.Status200OK, Msg = "操作成功!", Data = resData };
  63. }
  64. /// <summary>
  65. /// Item
  66. /// </summary>
  67. /// <returns></returns>
  68. public async Task<JsonView> ItemAsync(int portType, int groupId)
  69. {
  70. if (!SharingStaticData.PortTypes.Contains(portType)) return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "端口类型错误!" };
  71. if (groupId < 1) return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = MsgTips.DiId };
  72. var infos = await _sqlSugar
  73. .Queryable<Grp_RestaurantInfo, Sys_Users>((pi, u) => new JoinQueryInfos(JoinType.Left, pi.CreateUserId == u.Id))
  74. .Where((pi, u) => pi.IsDel == 0 && pi.GroupId == groupId)
  75. .OrderByDescending((pi, u) => pi.Date)
  76. .Select((pi, u) => new
  77. {
  78. pi.Id,
  79. //pi.GroupId,
  80. pi.Date,
  81. pi.StartTime,
  82. pi.EndTime,
  83. Type = pi.Type == 1 ? "早餐" : pi.Type == 2 ? "午餐" : pi.Type == 3 ? "晚餐" : "其他",
  84. pi.Name,
  85. pi.Address,
  86. pi.Tel,
  87. pi.Remark
  88. })
  89. .OrderByDescending(x => x.Date)
  90. .ToListAsync();
  91. if (!infos.Any()) return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "数据未填写!",Data = Array.Empty<dynamic>() };
  92. return new JsonView() { Code = StatusCodes.Status200OK, Msg = "操作成功!", Data = infos };
  93. }
  94. /// <summary>
  95. /// 操作
  96. /// </summary>
  97. /// <returns></returns>
  98. public async Task<JsonView> OpAsync(RestaurantOpDto dto)
  99. {
  100. int status = dto.Status;
  101. var info = _mapper.Map<Grp_RestaurantInfo>(dto);
  102. info.CreateUserId = dto.CurrUserId;
  103. if (status == 1)
  104. {
  105. //验重
  106. var isNull = await _sqlSugar.Queryable<Grp_RestaurantInfo>().Where(x => x.IsDel == 0 && x.GroupId == info.GroupId && x.Name.Equals(info.Name)).FirstAsync();
  107. if (isNull != null) return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "该团组下该餐厅名称已存在,不可重复添加!", Data = new { } };
  108. var infoId = await _sqlSugar.Insertable(info).ExecuteCommandAsync();
  109. if (infoId < 1) return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "添加失败!", Data = new { } };
  110. }
  111. else if (status == 2)
  112. {
  113. if (dto.Id < 1) return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = MsgTips.Id, Data = new { } };
  114. var infoId = await _sqlSugar.Updateable(info).IgnoreColumns(x => new { x.DeleteTime, x.DeleteUserId, x.CreateUserId, x.CreateTime, x.IsDel }).ExecuteCommandAsync();
  115. if (infoId < 1) return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "修改失败!", Data = new { } };
  116. }
  117. else new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "请传入有效的Status!", Data = new { } };
  118. return new JsonView() { Code = StatusCodes.Status200OK, Msg = "操作成功!", Data = new { } };
  119. }
  120. /// <summary>
  121. /// 操作
  122. /// </summary>
  123. /// <returns></returns>
  124. public async Task<JsonView> DelAsync(RestaurantDelDto dto)
  125. {
  126. int userId = dto.DeleteUserId;
  127. var id = dto.Id;
  128. if (userId < 1) return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = MsgTips.UserId, Data = new { } };
  129. if (id < 1) return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = MsgTips.Id, Data = new { } };
  130. var del = await _sqlSugar.Updateable<Grp_RestaurantInfo>()
  131. .SetColumns(x => new Grp_RestaurantInfo() { DeleteUserId = userId, DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), IsDel = 1 })
  132. .Where(x => x.Id == id)
  133. .ExecuteCommandAsync();
  134. if(del < 1) return new JsonView() { Code = StatusCodes.Status200OK, Msg = "删除失败!", Data = new { } };
  135. return new JsonView() { Code = StatusCodes.Status200OK, Msg = "操作成功!", Data = new { } };
  136. }
  137. }
  138. }