VisaFeeInfoRepository.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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="dto"></param>
  159. /// <returns></returns>
  160. public async Task<Result> _Update(VisaFeeAddAndUpdateDto dto)
  161. {
  162. if (dto.VisaFeeInfos.Count < 1) return _result = new Result() { Code = -1, Msg = "请传入有效的签证费用集合参数" };
  163. if (dto.PortType < 1 || dto.PortType > 3) return _result = new Result() { Code = -1, Msg = "请传入有效的portType参数" };
  164. List<Grp_VisaFeeInfo> visaInfos = new List<Grp_VisaFeeInfo>();
  165. BeginTran();
  166. //bool visaFeeUpdate = false;
  167. var countrys = dto.VisaFeeInfos.GroupBy(x => x.Country);
  168. foreach (var country in countrys)
  169. {
  170. int countryVisaFeeId = 0;
  171. decimal _grandBusinessAgencyFee = 0;
  172. decimal _pettyBusinessAgencyFee = 0;
  173. decimal _visaFee = 0;
  174. foreach (var item in country.ToList())
  175. {
  176. _visaFee = item.VisaFee;
  177. if (item.OBType == 1) _grandBusinessAgencyFee = item.AgencyFee;
  178. else if (item.OBType == 2) _pettyBusinessAgencyFee = item.AgencyFee;
  179. }
  180. var info = await _countryFeeRep._InfoByCountryName(country.Key);
  181. if (info == null) //添加
  182. {
  183. int addId = _sqlSugar.Insertable(
  184. new Res_CountryFeeCost()
  185. {
  186. VisaCountry = country.Key,
  187. VisaPrice = _visaFee,
  188. GrandBusinessAgencyFee = _grandBusinessAgencyFee,
  189. PettyBusinessAgencyFee = _pettyBusinessAgencyFee,
  190. LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  191. CreateUserId = dto.OpUserId,
  192. }).ExecuteReturnIdentity();
  193. if (addId > 0) countryVisaFeeId = addId;
  194. }
  195. else //修改
  196. {
  197. countryVisaFeeId = info.Id;
  198. if (_visaFee != info.VisaPrice) //价格不同的时候执行修改
  199. {
  200. Res_CountryFeeCost _CountryFeeCost = new Res_CountryFeeCost()
  201. {
  202. Id = info.Id,
  203. VisaPrice = _visaFee,
  204. GrandBusinessAgencyFee = _grandBusinessAgencyFee,
  205. PettyBusinessAgencyFee = _pettyBusinessAgencyFee,
  206. LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  207. };
  208. int update1 = _sqlSugar.Updateable(_CountryFeeCost).UpdateColumns(it => new { it.VisaPrice, it.LastUpdateTime }).WhereColumns(it => it.Id).ExecuteCommand();
  209. //if (update1 > 0)
  210. //{
  211. // visaFeeUpdate = true;
  212. //}
  213. }
  214. }
  215. foreach (var item in country.ToList())
  216. {
  217. visaInfos.Add(new Grp_VisaFeeInfo()
  218. {
  219. Id = item.Id,
  220. DiId = dto.DiId,
  221. IsChecked = item.IsChecked,
  222. CountryVisaFeeId = countryVisaFeeId,
  223. OBType = item.OBType,
  224. AgencyFee = item.AgencyFee,
  225. OtherFee = item.OtherFee
  226. });
  227. }
  228. }
  229. //执行删除
  230. var update = _sqlSugar.Updateable<Grp_VisaFeeInfo>().SetColumns(it => new Grp_VisaFeeInfo()
  231. {
  232. DeleteUserId = dto.OpUserId,
  233. DeleteTime = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"),
  234. IsDel = 1
  235. }).Where(it => it.DiId == dto.DiId).ExecuteCommand();
  236. var add = _sqlSugar.Insertable(visaInfos).ExecuteCommand();
  237. if (add > 0)
  238. {
  239. CommitTran();
  240. return new Result() {Code = 0 ,Msg = "操作成功!" };
  241. }
  242. RollbackTran();
  243. return _result;
  244. }
  245. /// <summary>
  246. /// 三公费用签证费用提示
  247. /// </summary>
  248. /// <param name="portType"></param>
  249. /// <param name="diId"></param>
  250. /// <returns></returns>
  251. public async Task<Result> EntryAndExitTips(int diId)
  252. {
  253. if (diId < 1) return _result = new Result() { Code = -1, Msg = "请传入有效的DiId参数" };
  254. var visaData = await _sqlSugar.Queryable<Grp_VisaFeeInfo>().Where(it => it.IsDel == 0 && it.DiId == diId).ToListAsync();
  255. List<int> ids = visaData.Select (it => it.CountryVisaFeeId).ToList();
  256. var visaCountryDatas = await _sqlSugar.Queryable<Res_CountryFeeCost>().Where(it => ids.Contains(it.Id)).ToListAsync();
  257. List<dynamic> datas = new List<dynamic>();
  258. string remark = "";
  259. decimal feeTotal = 0.00M;
  260. visaData = visaData.Where(it => it.IsChecked == 1).ToList();
  261. var visaData1 = visaData.GroupBy(it => it.CountryVisaFeeId);
  262. foreach (var kvp in visaData1)
  263. {
  264. var countryData = visaCountryDatas.Find(it => it.Id == kvp.Key);
  265. decimal _otherFee = kvp.FirstOrDefault()?.OtherFee ?? 0;
  266. decimal _visaFee = Convert.ToDecimal(countryData?.VisaPrice ?? 0.00M);
  267. decimal visaFeeTotal = _visaFee + _otherFee;
  268. decimal _agencyFee = 0;
  269. decimal _GrandBusinessAgencyFee = 0;
  270. decimal _PettyBusinessAgencyFee = 0;
  271. string remark1 = $"签证费:{_visaFee.ToString("#0.00")}元、";
  272. foreach (var item in kvp.ToList())
  273. {
  274. if (item.OBType == 1)
  275. {
  276. if (item.AgencyFee > 0)
  277. {
  278. remark1 += $@"大公务代办费:{item.AgencyFee.ToString("#0.00")}元、";
  279. _agencyFee += item.AgencyFee;
  280. _GrandBusinessAgencyFee = item.AgencyFee;
  281. }
  282. }
  283. else if (item.OBType == 1)
  284. {
  285. if (item.AgencyFee > 0)
  286. {
  287. remark1 += $@"小公务代办费:{item.AgencyFee.ToString("#0.00")}元、";
  288. _agencyFee += item.AgencyFee;
  289. _PettyBusinessAgencyFee = item.AgencyFee;
  290. }
  291. }
  292. }
  293. if (remark1.Length > 0) remark1 = remark1.Substring(0, remark1.Length - 1);
  294. if (_otherFee > 0) remark1 += $@"其他费用:{_otherFee.ToString("#0.00")}元";
  295. visaFeeTotal += (_GrandBusinessAgencyFee + _PettyBusinessAgencyFee);
  296. remark += $@"{countryData?.VisaCountry ?? ""}:签证总费用:{visaFeeTotal}元/人 其中({remark1});";
  297. feeTotal += visaFeeTotal;
  298. datas.Add(new
  299. {
  300. Country = countryData?.VisaCountry ?? "",
  301. visaFeeTotal = visaFeeTotal,
  302. VisaFee = countryData?.VisaPrice ?? 0.00M,
  303. GrandBusinessAgencyFee = _GrandBusinessAgencyFee,
  304. PettyBusinessAgencyFee = _PettyBusinessAgencyFee,
  305. OtherFee = _otherFee
  306. });
  307. }
  308. _result.Code = 0;
  309. _result.Data = new {
  310. feeTotal = feeTotal,
  311. data = datas,
  312. remark = remark
  313. };
  314. return _result;
  315. }
  316. }
  317. }