VisaFeeInfoRepository.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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. private readonly DelegationInfoRepository _groupRep;
  25. public VisaFeeInfoRepository(SqlSugarClient sqlSugar, IMapper mapper, CountryFeeRepository countryFeeRep, DelegationInfoRepository groupRep)
  26. : base(sqlSugar)
  27. {
  28. _mapper = mapper;
  29. _result = new Result() { Code = -2,Msg = "操作失败!"};
  30. _countryFeeRep = countryFeeRep;
  31. _groupRep = groupRep;
  32. }
  33. /// <summary>
  34. /// Init
  35. /// </summary>
  36. /// <param name="portType"></param>
  37. /// <param name="diId"></param>
  38. /// <returns></returns>
  39. public async Task<Result> _Init()
  40. {
  41. var data = await _sqlSugar.Queryable<Res_CountryFeeCost>().Where(it => it.IsDel == 0).ToListAsync();
  42. _result.Code = 0;
  43. _result.Data = data;
  44. _result.Msg = "操作成功!";
  45. return _result;
  46. }
  47. /// <summary>
  48. /// List
  49. /// </summary>
  50. /// <param name="portType"></param>
  51. /// <param name="diId"></param>
  52. /// <returns></returns>
  53. public async Task<Result> _List(int portType, int diId)
  54. {
  55. if (diId < 0) return _result = new Result() { Code = -1, Msg = "请传入有效的DiId参数" };
  56. if (portType < 1 || portType > 3) return _result = new Result() { Code = -1, Msg = "请传入有效的portType参数" };
  57. string sql = string.Format($@"Select vfi.Id,vfi.IsChecked,cfc.VisaCountry AS Country,cfc.VisaPrice As VisaFee,
  58. vfi.OBType,vfi.AgencyFee,vfi.OtherFee,vfi.Remark
  59. From Grp_VisaFeeInfo vfi
  60. Left Join Res_CountryFeeCost cfc On vfi.CountryVisaFeeId = cfc.Id
  61. Where vfi.Isdel = 0 And vfi.Diid = {diId}");
  62. var data = await _sqlSugar.SqlQueryable<VisaFeeInfosView>(sql).ToListAsync();
  63. //默认十行 雷怡 2024-26-08 11:26:40
  64. if (data.Count == 0)
  65. {
  66. var groupInfo = await _groupRep.PostShareGroupInfo(new ShareGroupInfoDto() { PortType = 1, Id = diId });
  67. List<string> countrys = new List<string>();
  68. if (groupInfo.Code == 0)
  69. {
  70. countrys = _groupRep.GroupSplitCountry((groupInfo.Data as Web_ShareGroupInfoView)?.VisitCountry ?? "");
  71. }
  72. if (countrys.Count > 0)
  73. {
  74. int dataRow = 0;
  75. foreach (var country in countrys)
  76. {
  77. var countryInfo = _sqlSugar.Queryable<Res_CountryFeeCost>().Where(it => it.IsDel == 0 && it.VisaCountry.Equals(country)).First();
  78. if (countryInfo != null)
  79. {
  80. data.Add(new VisaFeeInfosView()
  81. {
  82. IsChecked = 0,
  83. Country = country,
  84. VisaFee = countryInfo.VisaPrice,
  85. OBType = 1,
  86. AgencyFee = countryInfo.GrandBusinessAgencyFee
  87. });
  88. data.Add(new VisaFeeInfosView()
  89. {
  90. IsChecked = 0,
  91. Country = country,
  92. VisaFee = countryInfo.VisaPrice,
  93. OBType = 2,
  94. AgencyFee = countryInfo.PettyBusinessAgencyFee
  95. });
  96. }
  97. else
  98. {
  99. data.Add(new VisaFeeInfosView()
  100. {
  101. IsChecked = 0,
  102. Country = country,
  103. OBType = 1,
  104. });
  105. data.Add(new VisaFeeInfosView()
  106. {
  107. IsChecked = 0,
  108. Country = country,
  109. OBType = 2,
  110. });
  111. }
  112. }
  113. if (data.Count < 10)
  114. {
  115. int defaultRow = 10 - data.Count;
  116. for (int i = 0; i < defaultRow; i++)
  117. {
  118. data.Add(new VisaFeeInfosView()
  119. {
  120. Id = 0,
  121. OBType = 1
  122. });
  123. }
  124. }
  125. }
  126. else
  127. {
  128. for (int i = 0; i < 10; i++)
  129. {
  130. data.Add(new VisaFeeInfosView()
  131. {
  132. Id = 0,
  133. OBType = 1
  134. });
  135. }
  136. }
  137. }
  138. else if (data.Count <= 10)
  139. {
  140. int defaultRow = 10 - data.Count;
  141. for (int i = 0; i < defaultRow; i++)
  142. {
  143. data.Add(new VisaFeeInfosView()
  144. {
  145. Id = 0,
  146. OBType = 1
  147. });
  148. }
  149. }
  150. _result.Code = 0;
  151. _result.Data = data;
  152. _result.Msg = "操作成功!";
  153. return _result;
  154. }
  155. /// <summary>
  156. /// List
  157. /// </summary>
  158. /// <param name="portType"></param>
  159. /// <param name="diId"></param>
  160. /// <returns></returns>
  161. public async Task<Result> _Update(VisaFeeAddAndUpdateDto dto)
  162. {
  163. if (dto.VisaFeeInfos.Count < 1) return _result = new Result() { Code = -1, Msg = "请传入有效的签证费用集合参数" };
  164. if (dto.PortType < 1 || dto.PortType > 3) return _result = new Result() { Code = -1, Msg = "请传入有效的portType参数" };
  165. List<Grp_VisaFeeInfo> visaInfos = new List<Grp_VisaFeeInfo>();
  166. BeginTran();
  167. bool visaFeeUpdate = false;
  168. var countrys = dto.VisaFeeInfos.GroupBy(x => x.Country);
  169. foreach (var country in countrys)
  170. {
  171. int countryVisaFeeId = 0;
  172. decimal _grandBusinessAgencyFee = 0;
  173. decimal _pettyBusinessAgencyFee = 0;
  174. decimal _visaFee = 0;
  175. foreach (var item in country.ToList())
  176. {
  177. _visaFee = item.VisaFee;
  178. if (item.OBType == 1) _grandBusinessAgencyFee = item.AgencyFee;
  179. else if (item.OBType == 2) _pettyBusinessAgencyFee = item.AgencyFee;
  180. }
  181. var info = await _countryFeeRep._InfoByCountryName(country.Key);
  182. if (info == null) //添加
  183. {
  184. int addId = _sqlSugar.Insertable(
  185. new Res_CountryFeeCost()
  186. {
  187. VisaCountry = country.Key,
  188. VisaPrice = _visaFee,
  189. GrandBusinessAgencyFee = _grandBusinessAgencyFee,
  190. PettyBusinessAgencyFee = _pettyBusinessAgencyFee,
  191. LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  192. CreateUserId = dto.OpUserId,
  193. }).ExecuteReturnIdentity();
  194. if (addId > 0) countryVisaFeeId = addId;
  195. }
  196. else //修改
  197. {
  198. countryVisaFeeId = info.Id;
  199. if (_visaFee != info.VisaPrice) //价格不同的时候执行修改
  200. {
  201. Res_CountryFeeCost _CountryFeeCost = new Res_CountryFeeCost()
  202. {
  203. Id = info.Id,
  204. VisaPrice = _visaFee,
  205. GrandBusinessAgencyFee = _grandBusinessAgencyFee,
  206. PettyBusinessAgencyFee = _pettyBusinessAgencyFee,
  207. LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  208. };
  209. int update1 = _sqlSugar.Updateable(_CountryFeeCost).UpdateColumns(it => new { it.VisaPrice, it.LastUpdateTime }).WhereColumns(it => it.Id).ExecuteCommand();
  210. if (update1 > 0)
  211. {
  212. visaFeeUpdate = true;
  213. }
  214. }
  215. }
  216. foreach (var item in country.ToList())
  217. {
  218. visaInfos.Add(new Grp_VisaFeeInfo()
  219. {
  220. Id = item.Id,
  221. DiId = dto.DiId,
  222. IsChecked = item.IsChecked,
  223. CountryVisaFeeId = countryVisaFeeId,
  224. OBType = item.OBType,
  225. AgencyFee = item.AgencyFee,
  226. OtherFee = item.OtherFee
  227. });
  228. }
  229. }
  230. //执行删除
  231. var update = _sqlSugar.Updateable<Grp_VisaFeeInfo>().SetColumns(it => new Grp_VisaFeeInfo()
  232. {
  233. DeleteUserId = dto.OpUserId,
  234. DeleteTime = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"),
  235. IsDel = 1
  236. }).Where(it => it.DiId == dto.DiId).ExecuteCommand();
  237. var add = _sqlSugar.Insertable(visaInfos).ExecuteCommand();
  238. if (add > 0)
  239. {
  240. CommitTran();
  241. return new Result() {Code = 0 ,Msg = "操作成功!" };
  242. }
  243. RollbackTran();
  244. return _result;
  245. }
  246. /// <summary>
  247. /// 三公费用签证费用提示
  248. /// </summary>
  249. /// <param name="portType"></param>
  250. /// <param name="diId"></param>
  251. /// <returns></returns>
  252. public async Task<Result> EntryAndExitTips(int diId)
  253. {
  254. if (diId < 1) return _result = new Result() { Code = -1, Msg = "请传入有效的DiId参数" };
  255. var visaData = await _sqlSugar.Queryable<Grp_VisaFeeInfo>().Where(it => it.IsDel == 0 && it.DiId == diId).ToListAsync();
  256. List<int> ids = visaData.Select (it => it.CountryVisaFeeId).ToList();
  257. var visaCountryDatas = await _sqlSugar.Queryable<Res_CountryFeeCost>().Where(it => ids.Contains(it.Id)).ToListAsync();
  258. List<dynamic> datas = new List<dynamic>();
  259. string remark = "";
  260. decimal feeTotal = 0.00M;
  261. visaData = visaData.Where(it => it.IsChecked == 1).ToList();
  262. var visaData1 = visaData.GroupBy(it => it.CountryVisaFeeId);
  263. foreach (var kvp in visaData1)
  264. {
  265. var countryData = visaCountryDatas.Find(it => it.Id == kvp.Key);
  266. decimal _otherFee = kvp.FirstOrDefault()?.OtherFee ?? 0;
  267. decimal _visaFee = Convert.ToDecimal(countryData?.VisaPrice ?? 0.00M);
  268. decimal visaFeeTotal = _visaFee + _otherFee;
  269. decimal _agencyFee = 0;
  270. decimal _GrandBusinessAgencyFee = 0;
  271. decimal _PettyBusinessAgencyFee = 0;
  272. string remark1 = $"签证费:{_visaFee.ToString("#0.00")}元、";
  273. foreach (var item in kvp.ToList())
  274. {
  275. if (item.OBType == 1)
  276. {
  277. if (item.AgencyFee > 0)
  278. {
  279. remark1 += $@"大公务代办费:{item.AgencyFee.ToString("#0.00")}元、";
  280. _agencyFee += item.AgencyFee;
  281. _GrandBusinessAgencyFee = item.AgencyFee;
  282. }
  283. }
  284. else if (item.OBType == 1)
  285. {
  286. if (item.AgencyFee > 0)
  287. {
  288. remark1 += $@"小公务代办费:{item.AgencyFee.ToString("#0.00")}元、";
  289. _agencyFee += item.AgencyFee;
  290. _PettyBusinessAgencyFee = item.AgencyFee;
  291. }
  292. }
  293. }
  294. if (remark1.Length > 0) remark1 = remark1.Substring(0, remark1.Length - 1);
  295. if (_otherFee > 0) remark1 += $@"其他费用:{_otherFee.ToString("#0.00")}元";
  296. visaFeeTotal += (_GrandBusinessAgencyFee + _PettyBusinessAgencyFee);
  297. remark += $@"{countryData?.VisaCountry ?? ""}:签证总费用:{visaFeeTotal}元/人 其中({remark1});";
  298. feeTotal += visaFeeTotal;
  299. datas.Add(new
  300. {
  301. Country = countryData?.VisaCountry ?? "",
  302. visaFeeTotal = visaFeeTotal,
  303. VisaFee = countryData?.VisaPrice ?? 0.00M,
  304. GrandBusinessAgencyFee = _GrandBusinessAgencyFee,
  305. PettyBusinessAgencyFee = _PettyBusinessAgencyFee,
  306. OtherFee = _otherFee
  307. });
  308. }
  309. _result.Code = 0;
  310. _result.Data = new {
  311. feeTotal = feeTotal,
  312. data = datas,
  313. remark = remark
  314. };
  315. return _result;
  316. }
  317. }
  318. }