VisaFeeInfoRepository.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. /// <summary>
  146. /// 三公费用签证费用提示
  147. /// </summary>
  148. /// <param name="portType"></param>
  149. /// <param name="diId"></param>
  150. /// <returns></returns>
  151. public async Task<Result> EntryAndExitTips(int diId)
  152. {
  153. if (diId < 1) return _result = new Result() { Code = -1, Msg = "请传入有效的DiId参数" };
  154. var visaData = await _sqlSugar.Queryable<Grp_VisaFeeInfo>().Where(it => it.IsDel == 0).ToListAsync();
  155. List<int> ids = visaData.Select (it => it.CountryVisaFeeId).ToList();
  156. var visaCountryDatas = await _sqlSugar.Queryable< Res_CountryFeeCost >().Where(it => ids.Contains(it.Id)).ToListAsync();
  157. List<dynamic> datas = new List<dynamic>();
  158. string remark = "";
  159. decimal feeTotal = 0.00M;
  160. foreach (var item in visaData)
  161. {
  162. if (item.IsChecked == 1)
  163. {
  164. var countryData = visaCountryDatas.Find(it => it.Id == item.CountryVisaFeeId);
  165. decimal visaFeeTotal = countryData?.VisaPrice ?? 0.00M + item.AgencyFee + item.OtherFee;
  166. remark += $@"{countryData?.VisaCountry ?? ""}:签证总费用:{visaFeeTotal}元/人 其中(";
  167. if (countryData?.VisaPrice > 0) remark += $@"签证费用:{countryData?.VisaPrice.ToString("#0.00")}元、";
  168. if (item.AgencyFee > 0) remark += $@"代办费:{item.AgencyFee.ToString("#0.00")}元、";
  169. if (item.OtherFee > 0) remark += $@"其他费用:{item.OtherFee.ToString("#0.00")}元";
  170. if (visaFeeTotal > 0) remark = remark.Substring(0,remark.Length -1);
  171. remark += ");";
  172. feeTotal += visaFeeTotal;
  173. datas.Add(new
  174. {
  175. Country = countryData?.VisaCountry ?? "",
  176. visaFeeTotal = visaFeeTotal,
  177. VisaFee = countryData?.VisaPrice ?? 0.00M,
  178. item.AgencyFee,
  179. item.OtherFee
  180. });
  181. }
  182. }
  183. _result.Code = 0;
  184. _result.Data = new {
  185. feeTotal = feeTotal,
  186. data = datas,
  187. remark = remark
  188. };
  189. return _result;
  190. }
  191. }
  192. }