VisaFeeInfoRepository.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. using AutoMapper;
  2. using OASystem.Domain;
  3. using OASystem.Domain.Dtos.Groups;
  4. using OASystem.Domain.Entities.Groups;
  5. using OASystem.Domain.Entities.Resource;
  6. using OASystem.Domain.ViewModels.Groups;
  7. using OASystem.Infrastructure.Repositories.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.Groups
  14. {
  15. /// <summary>
  16. /// 团组签证费用详情 info
  17. /// 仓储
  18. /// </summary>
  19. public class VisaFeeInfoRepository:BaseRepository<Grp_VisaFeeInfo,VisaInfoView>
  20. {
  21. private readonly IMapper _mapper;
  22. private Result _result;
  23. private readonly CountryFeeRepository _countryFeeRep;
  24. public VisaFeeInfoRepository(SqlSugarClient sqlSugar, IMapper mapper, CountryFeeRepository countryFeeRep)
  25. : base(sqlSugar)
  26. {
  27. _mapper = mapper;
  28. _result = new Result() { Code = -2,Msg = "操作失败!"};
  29. _countryFeeRep = countryFeeRep;
  30. }
  31. /// <summary>
  32. /// Init
  33. /// </summary>
  34. /// <param name="portType"></param>
  35. /// <param name="diId"></param>
  36. /// <returns></returns>
  37. public async Task<Result> _Init()
  38. {
  39. var data = await _sqlSugar.Queryable<Res_CountryFeeCost>().Where(it => it.IsDel == 0).ToListAsync();
  40. _result.Code = 0;
  41. _result.Data = data;
  42. _result.Msg = "操作成功!";
  43. return _result;
  44. }
  45. /// <summary>
  46. /// List
  47. /// </summary>
  48. /// <param name="portType"></param>
  49. /// <param name="diId"></param>
  50. /// <returns></returns>
  51. public async Task<Result> _List(int portType, int diId)
  52. {
  53. if (diId < 0) return _result = new Result() { Code = -1, Msg = "请传入有效的DiId参数" };
  54. if (portType < 1 || portType > 3) return _result = new Result() { Code = -1, Msg = "请传入有效的portType参数" };
  55. string sql = string.Format($@"Select vfi.Id,vfi.IsChecked,cfc.VisaCountry AS Country,cfc.VisaPrice As VisaFee,
  56. vfi.AgencyFee,vfi.OtherFee,vfi.Remark
  57. From Grp_VisaFeeInfo vfi
  58. Left Join Res_CountryFeeCost cfc On vfi.CountryVisaFeeId = cfc.Id
  59. Where vfi.Isdel = 0 And vfi.Diid = {diId}");
  60. var data = await _sqlSugar.SqlQueryable<VisaFeeInfosView>(sql).ToListAsync();
  61. _result.Code = 0;
  62. _result.Data = data;
  63. _result.Msg = "操作成功!";
  64. return _result;
  65. }
  66. /// <summary>
  67. /// List
  68. /// </summary>
  69. /// <param name="portType"></param>
  70. /// <param name="diId"></param>
  71. /// <returns></returns>
  72. public async Task<Result> _AddAndUpdate(VisaFeeAddAndUpdateDto dto)
  73. {
  74. if (dto.Status < 1 || dto.Status > 2) return _result = new Result() { Code = -1, Msg = "请传入有效的Status参数" };
  75. if (dto.VisaFeeInfos.Count < 1) return _result = new Result() { Code = -1, Msg = "请传入有效的签证费用集合参数" };
  76. if (dto.PortType < 1 || dto.PortType > 3) return _result = new Result() { Code = -1, Msg = "请传入有效的portType参数" };
  77. List<Grp_VisaFeeInfo> visaInfos = new List<Grp_VisaFeeInfo>();
  78. BeginTran();
  79. bool visaFeeUpdate = false;
  80. foreach (var item in dto.VisaFeeInfos)
  81. {
  82. int countryVisaFeeId = 0;
  83. var info =await _countryFeeRep._InfoByCountryName(item.Country);
  84. if (info == null) //添加
  85. {
  86. int addId = _sqlSugar.Insertable(
  87. new Res_CountryFeeCost()
  88. {
  89. VisaCountry = item.Country,
  90. VisaPrice = item.VisaFee,
  91. LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  92. CreateUserId = dto.OpUserId,
  93. }).ExecuteReturnIdentity();
  94. if (addId > 0) countryVisaFeeId = addId;
  95. }
  96. else //修改
  97. {
  98. countryVisaFeeId = info.Id;
  99. if (item.VisaFee != info.VisaPrice) //价格不同的时候执行修改
  100. {
  101. Res_CountryFeeCost _CountryFeeCost = new Res_CountryFeeCost()
  102. {
  103. Id = info.Id,
  104. VisaPrice = item.VisaFee,
  105. LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  106. };
  107. int update = _sqlSugar.Updateable(_CountryFeeCost).UpdateColumns(it => new { it.VisaPrice, it.LastUpdateTime }).WhereColumns(it => it.Id).ExecuteCommand();
  108. if (update > 0)
  109. {
  110. visaFeeUpdate = true;
  111. }
  112. }
  113. }
  114. visaInfos.Add(new Grp_VisaFeeInfo()
  115. {
  116. Id = item.Id,
  117. DiId = dto.DiId,
  118. IsChecked = item.IsChecked,
  119. CountryVisaFeeId = countryVisaFeeId,
  120. AgencyFee = item.AgencyFee,
  121. OtherFee = item.OtherFee
  122. });
  123. }
  124. if (dto.Status == 1) //添加
  125. {
  126. var add = _sqlSugar.Insertable(visaInfos).ExecuteCommand();
  127. if (add > 0)
  128. {
  129. CommitTran();
  130. return new Result() {Code = 0 ,Msg = "操作成功!" };
  131. }
  132. }
  133. else if (dto.Status == 2) //修改
  134. {
  135. var update = _sqlSugar.Updateable(visaInfos).IgnoreColumns(it => new { it.CreateUserId,it.CreateTime,it.IsDel }).WhereColumns(it => it.Id).ExecuteCommand();
  136. if (update > 0 || visaFeeUpdate)
  137. {
  138. CommitTran();
  139. return new Result() { Code = 0, Msg = "操作成功!" };
  140. }
  141. }
  142. RollbackTran();
  143. return _result;
  144. }
  145. }
  146. }