VisaFeeInfoRepository.cs 16 KB

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