VisaFeeInfoRepository.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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.OBType,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. var countrys = dto.VisaFeeInfos.GroupBy(x => x.Country);
  80. foreach (var country in countrys)
  81. {
  82. int countryVisaFeeId = 0;
  83. decimal _grandBusinessAgencyFee = 0;
  84. decimal _pettyBusinessAgencyFee = 0;
  85. decimal _visaFee = 0;
  86. foreach (var item in country.ToList())
  87. {
  88. _visaFee = item.VisaFee;
  89. if (item.OBType == 1) _grandBusinessAgencyFee = item.AgencyFee;
  90. else if (item.OBType == 2) _pettyBusinessAgencyFee = item.AgencyFee;
  91. }
  92. var info = await _countryFeeRep._InfoByCountryName(country.Key);
  93. if (info == null) //添加
  94. {
  95. int addId = _sqlSugar.Insertable(
  96. new Res_CountryFeeCost()
  97. {
  98. VisaCountry = country.Key,
  99. VisaPrice = _visaFee,
  100. GrandBusinessAgencyFee = _grandBusinessAgencyFee,
  101. PettyBusinessAgencyFee = _pettyBusinessAgencyFee,
  102. LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  103. CreateUserId = dto.OpUserId,
  104. }).ExecuteReturnIdentity();
  105. if (addId > 0) countryVisaFeeId = addId;
  106. }
  107. else //修改
  108. {
  109. countryVisaFeeId = info.Id;
  110. if (_visaFee != info.VisaPrice) //价格不同的时候执行修改
  111. {
  112. Res_CountryFeeCost _CountryFeeCost = new Res_CountryFeeCost()
  113. {
  114. Id = info.Id,
  115. VisaPrice = _visaFee,
  116. GrandBusinessAgencyFee = _grandBusinessAgencyFee,
  117. PettyBusinessAgencyFee = _pettyBusinessAgencyFee,
  118. LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  119. };
  120. int update1 = _sqlSugar.Updateable(_CountryFeeCost).UpdateColumns(it => new { it.VisaPrice, it.LastUpdateTime }).WhereColumns(it => it.Id).ExecuteCommand();
  121. if (update1 > 0)
  122. {
  123. visaFeeUpdate = true;
  124. }
  125. }
  126. }
  127. foreach (var item in country.ToList())
  128. {
  129. visaInfos.Add(new Grp_VisaFeeInfo()
  130. {
  131. Id = item.Id,
  132. DiId = dto.DiId,
  133. IsChecked = item.IsChecked,
  134. CountryVisaFeeId = countryVisaFeeId,
  135. OBType = item.OBType,
  136. AgencyFee = item.AgencyFee,
  137. OtherFee = item.OtherFee
  138. });
  139. }
  140. }
  141. //执行删除
  142. var update = _sqlSugar.Updateable<Grp_VisaFeeInfo>().SetColumns(it => new Grp_VisaFeeInfo()
  143. {
  144. DeleteUserId = dto.OpUserId,
  145. DeleteTime = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"),
  146. IsDel = 1
  147. }).Where(it => it.DiId == dto.DiId).ExecuteCommand();
  148. var add = _sqlSugar.Insertable(visaInfos).ExecuteCommand();
  149. if (add > 0)
  150. {
  151. CommitTran();
  152. return new Result() {Code = 0 ,Msg = "操作成功!" };
  153. }
  154. RollbackTran();
  155. return _result;
  156. }
  157. /// <summary>
  158. /// 三公费用签证费用提示
  159. /// </summary>
  160. /// <param name="portType"></param>
  161. /// <param name="diId"></param>
  162. /// <returns></returns>
  163. public async Task<Result> EntryAndExitTips(int diId)
  164. {
  165. if (diId < 1) return _result = new Result() { Code = -1, Msg = "请传入有效的DiId参数" };
  166. var visaData = await _sqlSugar.Queryable<Grp_VisaFeeInfo>().Where(it => it.IsDel == 0 && it.DiId == diId).ToListAsync();
  167. List<int> ids = visaData.Select (it => it.CountryVisaFeeId).ToList();
  168. var visaCountryDatas = await _sqlSugar.Queryable<Res_CountryFeeCost>().Where(it => ids.Contains(it.Id)).ToListAsync();
  169. List<dynamic> datas = new List<dynamic>();
  170. string remark = "";
  171. decimal feeTotal = 0.00M;
  172. visaData = visaData.Where(it => it.IsChecked == 1).ToList();
  173. var visaData1 = visaData.GroupBy(it => it.CountryVisaFeeId);
  174. foreach (var kvp in visaData1)
  175. {
  176. var countryData = visaCountryDatas.Find(it => it.Id == kvp.Key);
  177. decimal _otherFee = kvp.FirstOrDefault()?.OtherFee ?? 0;
  178. decimal visaFeeTotal = Convert.ToDecimal(countryData?.VisaPrice ?? 0.00M) + _otherFee;
  179. decimal _agencyFee = 0;
  180. decimal _GrandBusinessAgencyFee = 0;
  181. decimal _PettyBusinessAgencyFee = 0;
  182. remark += $@"{countryData?.VisaCountry ?? ""}:签证总费用:{visaFeeTotal}元/人 其中(";
  183. foreach (var item in kvp.ToList())
  184. {
  185. if (item.OBType == 1)
  186. {
  187. if (item.AgencyFee > 0)
  188. {
  189. remark += $@"大公务代办费:{item.AgencyFee.ToString("#0.00")}元、";
  190. _agencyFee += item.AgencyFee;
  191. _GrandBusinessAgencyFee = item.AgencyFee;
  192. }
  193. }
  194. else if (item.OBType == 1)
  195. {
  196. if (item.AgencyFee > 0)
  197. {
  198. remark += $@"小公务代办费:{item.AgencyFee.ToString("#0.00")}元、";
  199. _agencyFee += item.AgencyFee;
  200. _PettyBusinessAgencyFee = item.AgencyFee;
  201. }
  202. }
  203. }
  204. if (_otherFee > 0) remark += $@"其他费用:{_otherFee.ToString("#0.00")}元";
  205. remark += ");";
  206. feeTotal += visaFeeTotal;
  207. datas.Add(new
  208. {
  209. Country = countryData?.VisaCountry ?? "",
  210. visaFeeTotal = visaFeeTotal,
  211. VisaFee = countryData?.VisaPrice ?? 0.00M,
  212. GrandBusinessAgencyFee = _GrandBusinessAgencyFee,
  213. PettyBusinessAgencyFee = _PettyBusinessAgencyFee,
  214. OtherFee = _otherFee
  215. });
  216. }
  217. _result.Code = 0;
  218. _result.Data = new {
  219. feeTotal = feeTotal,
  220. data = datas,
  221. remark = remark
  222. };
  223. return _result;
  224. }
  225. }
  226. }