VisaFeeInfoRepository.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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> _Update(VisaFeeAddAndUpdateDto dto)
  73. {
  74. if (dto.VisaFeeInfos.Count < 1) return _result = new Result() { Code = -1, Msg = "请传入有效的签证费用集合参数" };
  75. if (dto.PortType < 1 || dto.PortType > 3) return _result = new Result() { Code = -1, Msg = "请传入有效的portType参数" };
  76. List<Grp_VisaFeeInfo> visaInfos = new List<Grp_VisaFeeInfo>();
  77. BeginTran();
  78. bool visaFeeUpdate = false;
  79. foreach (var item in dto.VisaFeeInfos)
  80. {
  81. int countryVisaFeeId = 0;
  82. var info =await _countryFeeRep._InfoByCountryName(item.Country);
  83. if (info == null) //添加
  84. {
  85. int addId = _sqlSugar.Insertable(
  86. new Res_CountryFeeCost()
  87. {
  88. VisaCountry = item.Country,
  89. VisaPrice = item.VisaFee,
  90. LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  91. CreateUserId = dto.OpUserId,
  92. }).ExecuteReturnIdentity();
  93. if (addId > 0) countryVisaFeeId = addId;
  94. }
  95. else //修改
  96. {
  97. countryVisaFeeId = info.Id;
  98. if (item.VisaFee != info.VisaPrice) //价格不同的时候执行修改
  99. {
  100. Res_CountryFeeCost _CountryFeeCost = new Res_CountryFeeCost()
  101. {
  102. Id = info.Id,
  103. VisaPrice = item.VisaFee,
  104. LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  105. };
  106. int update1 = _sqlSugar.Updateable(_CountryFeeCost).UpdateColumns(it => new { it.VisaPrice, it.LastUpdateTime }).WhereColumns(it => it.Id).ExecuteCommand();
  107. if (update1 > 0)
  108. {
  109. visaFeeUpdate = true;
  110. }
  111. }
  112. }
  113. visaInfos.Add(new Grp_VisaFeeInfo()
  114. {
  115. Id = item.Id,
  116. DiId = dto.DiId,
  117. IsChecked = item.IsChecked,
  118. CountryVisaFeeId = countryVisaFeeId,
  119. AgencyFee = item.AgencyFee,
  120. OtherFee = item.OtherFee
  121. });
  122. }
  123. //执行删除
  124. var update = _sqlSugar.Updateable<Grp_VisaFeeInfo>().SetColumns(it => new Grp_VisaFeeInfo()
  125. {
  126. DeleteUserId = dto.OpUserId,
  127. DeleteTime = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"),
  128. IsDel = 1
  129. }).Where(it => it.DiId == dto.DiId).ExecuteCommand();
  130. var add = _sqlSugar.Insertable(visaInfos).ExecuteCommand();
  131. if (add > 0)
  132. {
  133. CommitTran();
  134. return new Result() {Code = 0 ,Msg = "操作成功!" };
  135. }
  136. RollbackTran();
  137. return _result;
  138. }
  139. /// <summary>
  140. /// 三公费用签证费用提示
  141. /// </summary>
  142. /// <param name="portType"></param>
  143. /// <param name="diId"></param>
  144. /// <returns></returns>
  145. public async Task<Result> EntryAndExitTips(int diId)
  146. {
  147. if (diId < 1) return _result = new Result() { Code = -1, Msg = "请传入有效的DiId参数" };
  148. var visaData = await _sqlSugar.Queryable<Grp_VisaFeeInfo>().Where(it => it.IsDel == 0 && it.DiId == diId).ToListAsync();
  149. List<int> ids = visaData.Select (it => it.CountryVisaFeeId).ToList();
  150. var visaCountryDatas = await _sqlSugar.Queryable<Res_CountryFeeCost>().Where(it => ids.Contains(it.Id)).ToListAsync();
  151. List<dynamic> datas = new List<dynamic>();
  152. string remark = "";
  153. decimal feeTotal = 0.00M;
  154. foreach (var item in visaData)
  155. {
  156. if (item.IsChecked == 1)
  157. {
  158. var countryData = visaCountryDatas.Find(it => it.Id == item.CountryVisaFeeId);
  159. decimal visaFeeTotal = countryData?.VisaPrice ?? 0.00M + item.AgencyFee + item.OtherFee;
  160. remark += $@"{countryData?.VisaCountry ?? ""}:签证总费用:{visaFeeTotal}元/人 其中(";
  161. if (countryData?.VisaPrice > 0) remark += $@"签证费用:{countryData?.VisaPrice.ToString("#0.00")}元、";
  162. if (item.AgencyFee > 0) remark += $@"代办费:{item.AgencyFee.ToString("#0.00")}元、";
  163. if (item.OtherFee > 0) remark += $@"其他费用:{item.OtherFee.ToString("#0.00")}元";
  164. if (visaFeeTotal > 0) remark = remark.Substring(0,remark.Length -1);
  165. remark += ");";
  166. feeTotal += visaFeeTotal;
  167. datas.Add(new
  168. {
  169. Country = countryData?.VisaCountry ?? "",
  170. visaFeeTotal = visaFeeTotal,
  171. VisaFee = countryData?.VisaPrice ?? 0.00M,
  172. item.AgencyFee,
  173. item.OtherFee
  174. });
  175. }
  176. }
  177. _result.Code = 0;
  178. _result.Data = new {
  179. feeTotal = feeTotal,
  180. data = datas,
  181. remark = remark
  182. };
  183. return _result;
  184. }
  185. }
  186. }