VisaFeeInfoRepository.cs 11 KB

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