TicketBlackCodeRepository.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. using AutoMapper;
  2. using OASystem.Domain;
  3. using OASystem.Domain.Dtos.Resource;
  4. using OASystem.Domain.Entities.Groups;
  5. using OASystem.Domain.Entities.Resource;
  6. using OASystem.Domain.ViewModels.Groups;
  7. using OASystem.Domain.ViewModels.Resource;
  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.Resource
  14. {
  15. public class TicketBlackCodeRepository : BaseRepository<Air_TicketBlackCode, TicketBlackCodeView>
  16. {
  17. private readonly IMapper _mapper;
  18. public TicketBlackCodeRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
  19. {
  20. _mapper = mapper;
  21. }
  22. /// <summary>
  23. /// 黑屏代码操作(Status:1.新增,2.修改)
  24. /// </summary>
  25. /// <param name="dto"></param>
  26. /// <returns></returns>
  27. /// <exception cref="NotImplementedException"></exception>
  28. public async Task<Result> OpTicketBlackCode(OpTicketBlackCodeDto dto)
  29. {
  30. Result result = new Result() { Code = -2, Msg = "未知错误" };
  31. try
  32. {
  33. if (dto.Status == 1)//添加
  34. {
  35. Air_TicketBlackCode _TicketBlackCode = await _sqlSugar.Queryable<Air_TicketBlackCode>().FirstAsync(a=>a.IsDel==0 && a.BlackCode==dto.BlackCode);//查询是否存在
  36. if (_TicketBlackCode != null)
  37. {
  38. return result = new Result() { Code = -1, Msg = "该信息已存在,请勿重复添加!" };
  39. }
  40. else//不存在,可添加
  41. {
  42. Air_TicketBlackCode air_TicketBlack = _mapper.Map<Air_TicketBlackCode>(dto);
  43. int id = await _sqlSugar.Insertable(air_TicketBlack).ExecuteReturnIdentityAsync();
  44. if (id == 0)
  45. {
  46. return result = new Result() { Code = -1, Msg = "添加失败!" };
  47. }
  48. return result = new Result() { Code = 0, Msg = "添加成功!", Data = new { Id = id } };
  49. }
  50. }
  51. else if (dto.Status == 2)//修改
  52. {
  53. bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Air_TicketBlackCode
  54. {
  55. DiId=dto.DiId,
  56. BlackCode=dto.BlackCode,
  57. Price=dto.Price,
  58. NowPrice=dto.NowPrice,
  59. BCPrice=dto.BCPrice,
  60. ECPrice=dto.ECPrice,
  61. CreateUserId = dto.CreateUserId,
  62. Remark = dto.Remark,
  63. });
  64. if (!res)
  65. {
  66. return result = new Result() { Code = -1, Msg = "修改失败!" };
  67. }
  68. return result = new Result() { Code = 0, Msg = "修改成功!", Data = new { Id = dto.Id } };
  69. }
  70. else
  71. {
  72. return result = new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
  73. }
  74. }
  75. catch (Exception ex)
  76. {
  77. return result = new Result() { Code = -2, Msg = "程序错误!" };
  78. }
  79. }
  80. public async Task<Result> QueryTicketBlackCodeByDiId(QueryTicketBlackCodeByDiIdDto dto)
  81. {
  82. Result result = new Result() { Code = -2, Msg = "未知错误" };
  83. try
  84. {
  85. string sqlWhere = string.Empty;
  86. sqlWhere += string.Format(@" And a.IsDel={0} And a.DiId={1}", 0, dto.DiId);
  87. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  88. {
  89. Regex r = new Regex("And");
  90. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  91. }
  92. string sql = string.Format(@"select *,(select CnName from Sys_Users where id=a.CreateUserId) as CreateName from Air_TicketBlackCode a {0}", sqlWhere);
  93. List<TicketBlackCodeView> _TicketBlackCodes = await _sqlSugar.SqlQueryable<TicketBlackCodeView>(sql).ToListAsync();
  94. Grp_DelegationInfo _DelegationInfo=await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(a=>a.IsDel==0 && a.Id==dto.DiId);
  95. if (_TicketBlackCodes.Count!=0)
  96. {
  97. return result = new Result()
  98. {
  99. Code = 0,
  100. Msg = "查询成功",
  101. Data = new
  102. {
  103. TicketBlackCodes= _TicketBlackCodes,
  104. DelegationInfo= _DelegationInfo
  105. },
  106. };
  107. }
  108. else
  109. {
  110. return result = new Result()
  111. {
  112. Code = 0,
  113. Msg = "暂无数据",
  114. Data = new
  115. {
  116. TicketBlackCodes = _TicketBlackCodes,
  117. DelegationInfo = _DelegationInfo
  118. },
  119. };
  120. }
  121. }
  122. catch (Exception)
  123. {
  124. return result;
  125. throw;
  126. }
  127. }
  128. public async Task<Result> QueryTicketBlackCodeById(QueryTicketBlackCodeByIdDto dto)
  129. {
  130. Result result = new Result() { Code = -2, Msg = "未知错误" };
  131. try
  132. {
  133. //查询成本和团组信息
  134. Grp_GroupCostParameter _GroupCostParameter = _sqlSugar.Queryable<Grp_GroupCostParameter>().First(a => a.DiId == dto.DiId && a.IsDel==0);//团组成本
  135. AirGroupCostParameterView _AirgroupCostParameter = _mapper.Map<AirGroupCostParameterView>(_GroupCostParameter);
  136. Grp_DelegationInfo _DelegationInfo=_sqlSugar.Queryable<Grp_DelegationInfo>().First(a=>a.Id == dto.DiId && a.IsDel==0);//团组信息
  137. Air_TicketBlackCode _TicketBlackCode=new Air_TicketBlackCode();
  138. if (dto.Id!=0 && !string.IsNullOrWhiteSpace(dto.Id.ToString()))
  139. {
  140. _TicketBlackCode = _sqlSugar.Queryable<Air_TicketBlackCode>().First(a => a.IsDel==0 && a.Id==dto.Id);
  141. return result = new Result()
  142. {
  143. Code = 0,
  144. Msg = "查询成功!",
  145. Data = new
  146. {
  147. GroupCostParameter = _AirgroupCostParameter,
  148. DelegationInfo = _DelegationInfo,
  149. TicketBlackCode = _TicketBlackCode
  150. },
  151. };
  152. }
  153. else
  154. {
  155. return result = new Result()
  156. {
  157. Code = 0,
  158. Msg = "查询成功!",
  159. Data = new
  160. {
  161. GroupCostParameter = _AirgroupCostParameter,
  162. DelegationInfo = _DelegationInfo,
  163. },
  164. };
  165. }
  166. }
  167. catch (Exception)
  168. {
  169. return result;
  170. throw;
  171. }
  172. }
  173. }
  174. }