HotelInquiryRepository.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. using AutoMapper;
  2. using MySqlX.XDevAPI.Common;
  3. using OASystem.Domain;
  4. using OASystem.Domain.Dtos.Groups;
  5. using OASystem.Domain.Entities.Groups;
  6. using OASystem.Domain.ViewModels.Groups;
  7. using OASystem.Domain.ViewModels.QiYeWeChat;
  8. using OASystem.Infrastructure.Repositories.System;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using Result = OASystem.Domain.Result;
  15. namespace OASystem.Infrastructure.Repositories.Groups
  16. {
  17. /// <summary>
  18. /// 酒店询价 仓储
  19. /// </summary>
  20. public class HotelInquiryRepository:BaseRepository<Grp_HotelInquiry,HotelInquiryView>
  21. {
  22. private readonly IMapper _mapper;
  23. private readonly SetDataRepository _setDataRep;
  24. /// <summary>
  25. /// Init
  26. /// </summary>
  27. /// <param name="sqlSugar"></param>
  28. public HotelInquiryRepository(SqlSugarClient sqlSugar, IMapper mapper, SetDataRepository setDataRep)
  29. : base(sqlSugar)
  30. {
  31. _mapper = mapper;
  32. _setDataRep = setDataRep;
  33. }
  34. /// <summary>
  35. /// 酒店询价
  36. /// 初始化数据
  37. /// </summary>
  38. /// <returns></returns>
  39. public async Task<Result> _Init()
  40. {
  41. var currDataResult = await _setDataRep.GetSetDataBySTId(_setDataRep, 66);
  42. dynamic currDatas = null;
  43. if (currDataResult.Code == 0) currDatas = currDataResult.Data;
  44. var data = new {
  45. CurrData = currDatas
  46. };
  47. return new Result() { Code = 0 ,Msg="操作成功!",Data = data };
  48. }
  49. /// <summary>
  50. /// 酒店询价
  51. /// Page 列表
  52. /// </summary>
  53. /// <param name="portType"></param>
  54. /// <param name="DiId"></param>
  55. /// <returns></returns>
  56. public async Task<Result> _PageItem(int pageIndex,int pageSize, int portType, int diId)
  57. {
  58. if (portType < 1 || portType > 3) return new Result() { Code = -1, Msg = MsgTips.Port};
  59. if (diId < 1) return new Result() { Code = -1, Msg = MsgTips.DiId };
  60. if (pageIndex < 1) return new Result() { Code = -1, Msg = MsgTips.PageIndex };
  61. if (pageIndex < 1) return new Result() { Code = -1, Msg = MsgTips.PageSize };
  62. string sql = string.Format(@$"SELECT
  63. hi.Id,
  64. hi.DiId,
  65. hi.City,
  66. hi.[Name],
  67. hi.[SelectDt],
  68. hi.CheckInDate,
  69. hi.CheckOutDate,
  70. hi.SinglePrice,
  71. hi.SingleQuantity,
  72. sd1.[Name] AS SingleCurrency,
  73. hi.DoublePrice,
  74. hi.DoubleQuantity,
  75. sd2.[Name] AS DoubleCurrency,
  76. hi.SuitePrice,
  77. hi.SuiteQuantity,
  78. sd3.[Name] AS SuiteCurrency,
  79. hi.OtherPrice,
  80. hi.OtherQuantity,
  81. sd4.[Name] AS OtherCurrency,
  82. hi.Remark,
  83. u.CnName AS CreateUserName,
  84. hi.CreateTime
  85. FROM
  86. Grp_HotelInquiry hi
  87. WITH
  88. (NoLock)
  89. LEFT JOIN Sys_Users u
  90. WITH
  91. (NoLock) ON hi.CreateUserId = u.Id
  92. LEFT JOIN Sys_SetData sd1
  93. WITH
  94. (NoLock) ON hi.SingleCurrency = sd1.Id
  95. LEFT JOIN Sys_SetData sd2
  96. WITH
  97. (NoLock) ON hi.DoubleCurrency = sd2.Id
  98. LEFT JOIN Sys_SetData sd3
  99. WITH
  100. (NoLock) ON hi.SuiteCurrency = sd3.Id
  101. LEFT JOIN Sys_SetData sd4
  102. WITH
  103. (NoLock) ON hi.OtherCurrency = sd4.Id
  104. WHERE
  105. hi.Isdel = 0
  106. AND hi.DiId = {diId}");
  107. if (portType == 1 || portType == 2 || portType == 3)
  108. {
  109. RefAsync<int> total = 0;
  110. var eqquiryDatas = await _sqlSugar.SqlQueryable<HotelInquiryItemView>(sql).OrderBy(it => it.checkInDate).ToPageListAsync(pageIndex, pageSize, total);
  111. return new Result() { Code = 0, Msg = MsgTips.Succeed, Data = new PageDataViewBase { Data = eqquiryDatas, Total = total } };
  112. }
  113. return new Result() { Code = -1, Msg = MsgTips.Fail };
  114. }
  115. /// <summary>
  116. /// info
  117. /// </summary>
  118. /// <param name="portType"></param>
  119. /// <param name="id"></param>
  120. /// <returns></returns>
  121. public async Task<Result> _Info(int portType, int id)
  122. {
  123. if (portType < 1 || portType > 3) return new Result() { Code = -1, Msg = MsgTips.Port };
  124. if (id < 1 ) return new Result() { Code = -1, Msg = MsgTips.Id };
  125. var info = await _sqlSugar.Queryable<Grp_HotelInquiry>()
  126. .Where(it => it.IsDel == 0 && it.Id == id)
  127. .Select(it =>
  128. new {
  129. it.Id,
  130. it.DiId,
  131. it.City,
  132. it.Name,
  133. it.Address,
  134. it.SelectDt,
  135. it.CheckInDate,
  136. it.CheckOutDate,
  137. it.SinglePrice,
  138. it.SingleQuantity,
  139. it.SingleCurrency,
  140. it.DoublePrice,
  141. it.DoubleQuantity,
  142. it.DoubleCurrency,
  143. it.SuitePrice,
  144. it.SuiteQuantity,
  145. it.SuiteCurrency,
  146. it.OtherPrice,
  147. it.OtherQuantity,
  148. it.OtherCurrency,
  149. it.Remark,
  150. })
  151. .FirstAsync();
  152. return new Result() { Code = 0, Msg = MsgTips.Succeed,Data = info };
  153. }
  154. /// <summary>
  155. /// Add Or Edit
  156. /// </summary>
  157. /// <param name="_dto"></param>
  158. /// <returns></returns>
  159. public async Task<Result> _AddOrEdit(HotelInquiryAddOrEditDto _dto)
  160. {
  161. #region 参数验证
  162. if (_dto.DiId < 1) return new Result() { Code = -1, Msg = MsgTips.DiId };
  163. if (_dto.Status < 1 || _dto.Status > 2) return new Result() { Code = -1, Msg = MsgTips.Status };
  164. #endregion
  165. Grp_HotelInquiry _HotelInquiry = _mapper.Map<Grp_HotelInquiry>(_dto);
  166. if (_dto.Status == 1)
  167. {
  168. var add = await _sqlSugar.Insertable(_HotelInquiry).ExecuteReturnIdentityAsync();
  169. if (add > 0 ) return new Result() { Code = 0, Msg = MsgTips.Succeed };
  170. }
  171. else if (_dto.Status == 2)
  172. {
  173. var update = await _sqlSugar.Updateable(_HotelInquiry)
  174. .IgnoreColumns(it =>
  175. new
  176. {
  177. it.CreateUserId,
  178. it.CreateTime,
  179. it.DeleteUserId,
  180. it.DeleteTime,
  181. it.IsDel
  182. })
  183. .WhereColumns(it =>
  184. new
  185. {
  186. it.Id
  187. })
  188. .ExecuteCommandAsync();
  189. if (update > 0) return new Result() { Code = 0, Msg = MsgTips.Succeed };
  190. }
  191. return new Result() { Code = -1, Msg = MsgTips.Fail };
  192. }
  193. /// <summary>
  194. /// Del
  195. /// </summary>
  196. /// <param name="_dto"></param>
  197. /// <returns></returns>
  198. public async Task<Result> _Del(int id,int userId)
  199. {
  200. #region 参数验证
  201. if (id < 1) return new Result() { Code = -1, Msg = MsgTips.Id };
  202. if (userId < 0) return new Result() { Code = -1, Msg = MsgTips.UserId };
  203. #endregion
  204. var del = await SoftDeleteByIdAsync<Grp_HotelInquiry>(id.ToString(), userId);
  205. if (del) return new Result() { Code = 0, Msg = MsgTips.Succeed };
  206. return new Result() { Code = -1, Msg = MsgTips.Fail };
  207. }
  208. }
  209. }