123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- 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 sql = string.Format(@" SELECT
- ri.Id,
- ri.GroupId,
- ri.Date,
- ri.StartTime,
- ri.EndTime,
- CASE WHEN ri.Type = 1 THEN '早餐'
- WHEN ri.Type = 2 THEN '午餐'
- WHEN ri.Type = 3 THEN '晚餐'
- ELSE '其他'
- END AS 'Type',
- ri.Name,
- ri.Address,
- ri.Tel,
- ri.Remark,
- ri.CreateTime,
- u.CnName AS CreateUserName
- FROM
- Grp_RestaurantInfo ri
- LEFT JOIN Sys_Users u ON ri.CreateUserId = u.Id
- WHERE
- ri.IsDel = 0
- AND ri.GroupId = {0}
- ORDER BY
- ri.Date ASC
- ", groupId);
- var infos = await _sqlSugar.SqlQueryable<RestaurantItemView>(sql).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 { } };
- }
- }
- }
|