TeamRateRepository.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860
  1. using Newtonsoft.Json;
  2. using NPOI.SS.Formula.PTG;
  3. using OASystem.Domain;
  4. using OASystem.Domain.Dtos.Financial;
  5. using OASystem.Domain.Dtos.Groups;
  6. using OASystem.Domain.Entities.Financial;
  7. using OASystem.Domain.Entities.Groups;
  8. using OASystem.Domain.ViewModels.Financial;
  9. using OASystem.Domain.ViewModels.Groups;
  10. using OASystem.Infrastructure.Repositories.System;
  11. using Serilog;
  12. using SqlSugar;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Diagnostics;
  16. using System.Linq;
  17. using System.Text;
  18. using System.Threading.Tasks;
  19. namespace OASystem.Infrastructure.Repositories.Groups
  20. {
  21. /// <summary>
  22. /// 团组汇率 仓库
  23. /// </summary>
  24. public class TeamRateRepository : BaseRepository<Grp_TeamRate, TeamRateView>
  25. {
  26. private readonly SetDataRepository _setDataRep;
  27. private readonly DelegationInfoRepository _deleInfoRep;
  28. public TeamRateRepository(SqlSugarClient sqlSugar, SetDataRepository setDataRep, DelegationInfoRepository deleInfoRep)
  29. : base(sqlSugar)
  30. {
  31. _setDataRep = setDataRep;
  32. _deleInfoRep = deleInfoRep;
  33. }
  34. /// <summary>
  35. /// 团组汇率 Rep
  36. /// </summary>
  37. /// <param name="dto"></param>
  38. /// <returns></returns>
  39. public async Task<Result> GetGroupRateDataSource(TeamRateDto dto)
  40. {
  41. Result result = new() { Code = -2 };
  42. Stopwatch stopwatch = Stopwatch.StartNew();
  43. GroupNameDto groupNameDto = new GroupNameDto() { PortType = dto.PortType };
  44. var groups = await _deleInfoRep.GetGroupNameList(groupNameDto);
  45. var teamRateDatas = await _setDataRep.GetSetDataBySTId(_setDataRep, 66); // STid=66 全球币种
  46. dynamic _data = null;
  47. if (dto.PortType == 1)
  48. {
  49. //List<Sys_SetData> sys_SetDatas = new List<Sys_SetData>();
  50. //sys_SetDatas = JsonConvert.DeserializeObject<List<Sys_SetData>>(JsonConvert.SerializeObject(teamRateDatas.Data));
  51. //List<TeamRateDescView> teamRateDescViews = new List<TeamRateDescView>();
  52. //teamRateDescViews = sys_SetDatas.Select(it => new TeamRateDescView() { CurrencyName = it.Remark, CurrencyCode = it.Name, Rate = 0.0000M }).ToList();
  53. ///*
  54. // * 放在首位币种
  55. // * 人民币 CNY Rate = 1,美元 USD,欧元 EUR,港币 HKD,日元 JPY ,澳大利 AUD,英镑 GBP
  56. // * 依次排序
  57. // */
  58. ////人民币
  59. //var cnyData = teamRateDescViews.Find(it => it.CurrencyCode.Equals("CNY"));
  60. //if (cnyData != null) { teamRateDescViews.Remove(cnyData); cnyData.Rate = 1.0000M; teamRateDescViews.Insert(0, cnyData); }
  61. ////美元
  62. //var usdData = teamRateDescViews.Find(it => it.CurrencyCode.Equals("USD"));
  63. //if (usdData != null) { teamRateDescViews.Remove(usdData); teamRateDescViews.Insert(1, usdData); }
  64. ////欧元
  65. //var eurData = teamRateDescViews.Find(it => it.CurrencyCode.Equals("EUR"));
  66. //if (eurData != null) { teamRateDescViews.Remove(eurData); teamRateDescViews.Insert(2, eurData); }
  67. ////港币
  68. //var hkdData = teamRateDescViews.Find(it => it.CurrencyCode.Equals("HKD"));
  69. //if (hkdData != null) { teamRateDescViews.Remove(hkdData); teamRateDescViews.Insert(3, hkdData); }
  70. ////日元
  71. //var jpyData = teamRateDescViews.Find(it => it.CurrencyCode.Equals("JPY"));
  72. //if (jpyData != null) { teamRateDescViews.Remove(jpyData); teamRateDescViews.Insert(4, jpyData); }
  73. ////澳大利
  74. //var audData = teamRateDescViews.Find(it => it.CurrencyCode.Equals("AUD"));
  75. //if (audData != null) { teamRateDescViews.Remove(audData); teamRateDescViews.Insert(5, audData); }
  76. ////英镑
  77. //var gbpData = teamRateDescViews.Find(it => it.CurrencyCode.Equals("GBP"));
  78. //if (gbpData != null) { teamRateDescViews.Remove(gbpData); teamRateDescViews.Insert(6, gbpData); }
  79. _data = new { GroupData = groups.Data, TeamRateData = await PostGroupTeamRateHot() };
  80. }
  81. else if (dto.PortType == 2)
  82. {
  83. }
  84. else if (dto.PortType == 3)
  85. {
  86. }
  87. stopwatch.Stop();
  88. result.Code = 0;
  89. result.Msg = $"查询成功!耗时:{stopwatch.ElapsedMilliseconds / 1000}s";
  90. result.Data = _data;
  91. return result;
  92. }
  93. /// <summary>
  94. /// 团组汇率 更改数据
  95. /// </summary>
  96. /// <param name="dto"></param>
  97. /// <returns></returns>
  98. public async Task<Result> GetGroupRateChangeData()
  99. {
  100. Result result = new() { Code = -2 };
  101. string teamRateInfoSql = string.Format(@"Select * From Grp_TeamRate tr Where tr.IsDel = 0");
  102. var teamRateInfo = await _sqlSugar.SqlQueryable<Grp_TeamRate>(teamRateInfoSql).ToListAsync();
  103. dynamic _data = null;
  104. #region 团组汇率 - 详细汇率信息
  105. List<SetDataInfoView> otherCurrencyData1 = new List<SetDataInfoView>();
  106. var otherCurrencyData = await _setDataRep.GetSetDataBySTId(_setDataRep, 13);
  107. if (otherCurrencyData.Code == 0 && otherCurrencyData.Data != null)
  108. {
  109. string otherCurrencyStr = JsonConvert.SerializeObject(otherCurrencyData.Data);
  110. otherCurrencyData1 = JsonConvert.DeserializeObject<List<SetDataInfoView>>(otherCurrencyStr);
  111. //var otherCurrency = otherCurrencyData1
  112. }
  113. foreach (Grp_TeamRate item1 in teamRateInfo)
  114. {
  115. string rateStr = string.Empty;
  116. if (item1.RateU != 0) rateStr += "美元(USD):" + item1.RateU + "|";
  117. if (item1.RateE != 0) rateStr += "欧元(EUR):" + item1.RateE + "|";
  118. if (item1.RateJ != 0)
  119. rateStr += "日元(JPY):" + item1.RateJ + "|";
  120. if (item1.RateH != 0)
  121. rateStr += "港币(HKD):" + item1.RateH + "|";
  122. if (item1.RateN != 0)
  123. rateStr += "新西兰元(NZD):" + item1.RateN + "|";
  124. if (item1.RateS != 0)
  125. rateStr += "新加坡币(SGD):" + item1.RateS + "|";
  126. if (item1.RateA != 0)
  127. rateStr += "澳大利亚元(AUD):" + item1.RateA + "|";
  128. if (item1.RateC != 0)
  129. rateStr += "加拿大元(CAD):" + item1.RateC + "|";
  130. if (item1.RateT != 0)
  131. rateStr += "泰国铢(THB):" + item1.RateT + "|";
  132. if (item1.RateBL != 0)
  133. rateStr += "波兰兹罗提(PLN):" + item1.RateBL + "|";
  134. if (item1.RateHB != 0)
  135. rateStr += "韩国元(KRW):" + item1.RateHB + "|";
  136. if (item1.RateFJD != 0)
  137. rateStr += "斐济元(FJD):" + item1.RateFJD + "|";
  138. if (item1.RateTL != 0)
  139. rateStr += "土耳其里拉(TRY):" + item1.RateTL + "|";
  140. if (item1.RateRP != 0)
  141. rateStr += "印度尼西亚卢比(IDR):" + item1.RateRP + "|";
  142. if (item1.RatePeso != 0)
  143. rateStr += "菲律宾比索(PHP):" + item1.RatePeso + "|";
  144. if (item1.RateMYR != 0)
  145. rateStr += "林吉特(MYR):" + item1.RateMYR + "|";
  146. if (item1.RateCZK != 0)
  147. rateStr += "捷克货币(CZK):" + item1.RateCZK + "|";
  148. if (item1.RateMXN != 0)
  149. rateStr += "墨西哥比索(MXN):" + item1.RateMXN + "|";
  150. if (item1.RateMOP != 0)
  151. rateStr += "澳门元(MOP):" + item1.RateMOP + "|";
  152. if (item1.RateARS != 0)
  153. rateStr += "阿根廷比索(ARS):" + item1.RateARS + "|";
  154. if (item1.RateHUF != 0)
  155. rateStr += "匈牙利福林(HUF):" + item1.RateHUF + "|";
  156. if (item1.RateRUB != 0)
  157. rateStr += "卢布(RUB):" + item1.RateRUB + "|";
  158. if (!string.IsNullOrEmpty(item1.OtherRateCode))
  159. {
  160. rateStr += $"{otherCurrencyData1.Find(it => it.Name.Equals(item1.OtherRateCode))?.Remark ?? "Unknown"}({item1.OtherRateCode}):{item1.OtherPrice}|";
  161. }
  162. if (!rateStr.Contains("CNY"))
  163. {
  164. rateStr += "人民币(CNY):1.0000|";
  165. }
  166. if (rateStr.Length > 0)
  167. {
  168. rateStr = rateStr.Substring(0, rateStr.Length - 1);
  169. }
  170. item1.Remark = rateStr;
  171. }
  172. #endregion
  173. try
  174. {
  175. var _result = _sqlSugar.Updateable(teamRateInfo)
  176. .UpdateColumns(it => new { it.Remark }) //更新列
  177. .WhereColumns(it => new { it.DiId, it.CTable }) //更新条件
  178. .ExecuteCommand();
  179. result.Code = 0;
  180. result.Msg = "数据修改成功!";
  181. result.Data = _data;
  182. }
  183. catch (Exception ex)
  184. {
  185. result.Msg = ex.Message;
  186. }
  187. return result;
  188. }
  189. /// <summary>
  190. /// 团组汇率 Rep
  191. /// </summary>
  192. /// <param name="dto"></param>
  193. /// <returns></returns>
  194. public async Task<Result> GetGroupRateInfoByDiid(TeamRateInfoDto dto)
  195. {
  196. Result result = new() { Code = -2 };
  197. GroupInfoDto groupInfoDto = new GroupInfoDto() { Id = dto.Diid, PortType = dto.PortType, PageIndex = dto.PageIndex, PageSize = dto.PageSize };
  198. var groupInfo = await _deleInfoRep.GetGroupInfo(groupInfoDto);
  199. string teamRateInfoSql = string.Format(@"Select sd.Name,tr.* From Grp_TeamRate tr
  200. Left Join Sys_SetData sd On sd.IsDel=0 And sd.STid=16 And tr.CTable = sd.Id
  201. Where tr.DiId = {0} And tr.IsDel = 0", dto.Diid);
  202. var teamRateInfo = await _sqlSugar.SqlQueryable<TeamRateInfoView>(teamRateInfoSql).ToListAsync();
  203. dynamic _data = null;
  204. if (dto.PortType == 1)
  205. {
  206. #region 团组汇率
  207. List<TeamRateModelView> teamRateModels = new List<TeamRateModelView>();
  208. foreach (TeamRateInfoView item in teamRateInfo)
  209. {
  210. TeamRateModelView teamRateModelInfo = new TeamRateModelView();
  211. teamRateModelInfo.Id = item.Id;
  212. teamRateModelInfo.CTableId = item.CTable;
  213. teamRateModelInfo.CTableName = item.Name;
  214. List<TeamRateDescView> teamRateDescViews = new List<TeamRateDescView>();
  215. #region 拆分remark里的汇率
  216. if (item.Remark.Contains("|"))
  217. {
  218. string[] currencyArr = item.Remark.Split("|");
  219. foreach (string currency in currencyArr)
  220. {
  221. string[] currency1 = currency.Split(":");
  222. string[] currency2 = currency1[0].Split("(");
  223. TeamRateDescView rateDescView = new TeamRateDescView()
  224. {
  225. CurrencyCode = currency2[1].Replace(")", "").TrimEnd(),
  226. CurrencyName = currency2[0],
  227. Rate = decimal.Parse(currency1[1]),
  228. };
  229. teamRateDescViews.Add(rateDescView);
  230. }
  231. }
  232. else
  233. {
  234. if (!string.IsNullOrEmpty(item.Remark))
  235. {
  236. string[] currency1 = item.Remark.Split(":");
  237. string[] currency2 = currency1[0].Split("(");
  238. TeamRateDescView rateDescView = new TeamRateDescView()
  239. {
  240. CurrencyCode = currency2[1].Replace(")", "").TrimEnd(),
  241. CurrencyName = currency2[0],
  242. Rate = decimal.Parse(currency1[1]),
  243. };
  244. teamRateDescViews.Add(rateDescView);
  245. }
  246. }
  247. #endregion
  248. teamRateModelInfo.TeamRates = teamRateDescViews;
  249. teamRateModels.Add(teamRateModelInfo);
  250. }
  251. #endregion
  252. _data = new { GroupInfo = groupInfo.Data, TeamRateData = teamRateModels };
  253. }
  254. else if (dto.PortType == 2)
  255. {
  256. }
  257. else if (dto.PortType == 3)
  258. {
  259. }
  260. result.Code = 0;
  261. result.Msg = "查询成功!";
  262. result.Data = _data;
  263. return result;
  264. }
  265. /// <summary>
  266. /// 团组汇率 更新 or 添加
  267. /// </summary>
  268. /// <param name="dto"></param>
  269. /// <returns></returns>
  270. public async Task<Result> PostGroupRateUpdate(TeamRateUpdateDto dto)
  271. {
  272. Result result = new() { Code = -2 };
  273. int addCount = 0, updateCount = 0;
  274. if (dto.PortType == 1)
  275. {
  276. try
  277. {
  278. _sqlSugar.BeginTran();
  279. int res = -1;
  280. foreach (TeamRateUpdateInfo item in dto.teamRateUpdateInfos)
  281. {
  282. Grp_TeamRate teamRateInfo = new Grp_TeamRate();
  283. string currencyStr = string.Empty;
  284. foreach (TeamRateDescView currency in item.teamRates)
  285. {
  286. currencyStr += string.Format(@"{0}({1}):{2}|", currency.CurrencyName, currency.CurrencyCode, currency.Rate);
  287. }
  288. if (currencyStr.Length > 0)
  289. {
  290. currencyStr = currencyStr.Substring(0, currencyStr.Length - 1);
  291. }
  292. teamRateInfo.DiId = dto.DiId;
  293. teamRateInfo.CreateUserId = dto.CreateUserId;
  294. teamRateInfo.Id = item.Id;
  295. teamRateInfo.CreateTime = DateTime.Now;
  296. teamRateInfo.CTable = item.CTable;
  297. teamRateInfo.Remark = currencyStr;
  298. var teamRateDetails = _sqlSugar.Queryable<Grp_TeamRate>().Where(it => it.DiId == dto.DiId && it.CTable == item.CTable).First();
  299. if (teamRateDetails == null) //添加
  300. {
  301. res = await _sqlSugar.Insertable(teamRateInfo).ExecuteCommandAsync();
  302. if (res > 0)
  303. {
  304. addCount++;
  305. }
  306. }
  307. else //修改
  308. {
  309. teamRateInfo.Id = teamRateDetails.Id;
  310. res = await _sqlSugar.Updateable(teamRateInfo)
  311. .UpdateColumns(it => it.Remark)
  312. .WhereColumns(it => new { it.DiId, it.CTable })
  313. .ExecuteCommandAsync();
  314. if (res > 0)
  315. {
  316. //团组汇率更改成功;更改C表对应汇率 及rmb金额
  317. var ccpInfos = _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(it => it.IsDel == 0 && it.DIId == dto.DiId && it.CTable == item.CTable).ToList();
  318. var currData = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 66).ToList();
  319. if (ccpInfos.Count > 0)
  320. {
  321. foreach (var ccpInfo in ccpInfos)
  322. {
  323. string currCode = currData.Find(it => it.Id == ccpInfo.PaymentCurrency)?.Name ?? "";
  324. decimal thisRate = item.teamRates.Find(it => it.CurrencyCode.Equals(currCode))?.Rate ?? 0.00M;
  325. if (thisRate > 0.00M)
  326. {
  327. ccpInfo.DayRate = thisRate;
  328. ccpInfo.RMBPrice = ccpInfo.PayMoney * thisRate;
  329. }
  330. }
  331. var ccpStatus = _sqlSugar.Updateable(ccpInfos)
  332. .UpdateColumns(it => new { it.DayRate, it.RMBPrice })
  333. .WhereColumns(it => it.Id)
  334. .ExecuteCommand();
  335. }
  336. updateCount++;
  337. }
  338. }
  339. if (res < 1)
  340. {
  341. _sqlSugar.RollbackTran();
  342. result.Msg = "操作失败!";
  343. break;
  344. }
  345. }
  346. if (res > 0)
  347. {
  348. _sqlSugar.CommitTran();
  349. result.Code = 0;
  350. result.Msg = "操作成功";
  351. }
  352. }
  353. catch (Exception ex)
  354. {
  355. result.Msg = ex.Message;
  356. }
  357. }
  358. else if (dto.PortType == 2)
  359. {
  360. }
  361. else if (dto.PortType == 3)
  362. {
  363. }
  364. result.Code = 0;
  365. result.Msg = string.Format(@"操作成功!添加:{0}条;更新:{1};", addCount, updateCount);
  366. return result;
  367. }
  368. /// <summary>
  369. /// 团组汇率 Rep
  370. /// 根据团组Id 查询汇率
  371. /// </summary>
  372. /// <param name="dto"></param>
  373. /// <returns></returns>
  374. public async Task<List<TeamRateModelView>> PostGroupRateInfoByDiId(int diId)
  375. {
  376. List<TeamRateModelView> teamRateModels = new List<TeamRateModelView>();
  377. string teamRateInfoSql = string.Format(@"Select sd.Name,tr.* From Grp_TeamRate tr
  378. Left Join Sys_SetData sd On sd.IsDel=0 And sd.STid=16 And tr.CTable = sd.Id
  379. Where tr.DiId = {0} And tr.IsDel = 0", diId);
  380. var teamRateInfo = await _sqlSugar.SqlQueryable<TeamRateInfoView>(teamRateInfoSql).ToListAsync();
  381. #region 团组汇率
  382. foreach (TeamRateInfoView item in teamRateInfo)
  383. {
  384. TeamRateModelView teamRateModelInfo = new TeamRateModelView();
  385. teamRateModelInfo.Id = item.Id;
  386. teamRateModelInfo.CTableId = item.CTable;
  387. teamRateModelInfo.CTableName = item.Name;
  388. //拆分remark里的汇率
  389. teamRateModelInfo.TeamRates = GroupCurrencySplittings(item.Remark);
  390. teamRateModels.Add(teamRateModelInfo);
  391. }
  392. #endregion
  393. return teamRateModels;
  394. }
  395. /// <summary>
  396. /// 更改团组对应模块 对应币种汇率
  397. /// </summary>
  398. /// <param name="diId">团组Id</param>
  399. /// <param name="cTableId">团组模块</param>
  400. /// <param name="currCode">币种code</param>
  401. /// <param name="currRate">币种汇率</param>
  402. /// <returns></returns>
  403. public async Task<bool> UpdateGroupRateByDiIdAndCTableId(int diId, int cTableId, string currCode, decimal currRate)
  404. {
  405. if (diId < 1) return false;
  406. if (cTableId < 1) return false;
  407. var _info = await PostGroupTeamRateByDiIdAndCTableId(1, diId, cTableId);
  408. TeamRateUpdateDto OPDto = new TeamRateUpdateDto();
  409. OPDto.DiId = diId;
  410. var teamRates = new List<TeamRateUpdateInfo>();
  411. if (_info == null)
  412. {
  413. var currData = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 66 && it.Name.Equals(currCode)).First();
  414. teamRates.Add(
  415. new TeamRateUpdateInfo()
  416. {
  417. Id = 0,
  418. CTable = cTableId,
  419. teamRates = new List<TeamRateDescView>
  420. {
  421. new TeamRateDescView()
  422. {
  423. CurrencyName = currData?.Remark,
  424. CurrencyCode = currCode,
  425. Rate = currRate
  426. }
  427. }
  428. }
  429. );
  430. }
  431. else
  432. {
  433. var rateCurrInfo = new TeamRateUpdateInfo();
  434. rateCurrInfo.CTable = cTableId;
  435. var currInfos = new List<TeamRateDescView>();
  436. foreach (var item in _info.TeamRates)
  437. {
  438. var currInfo = new TeamRateDescView();
  439. currInfo.CurrencyName = item.CurrencyName;
  440. currInfo.CurrencyCode = item.CurrencyCode;
  441. if (item.CurrencyCode.Equals(currCode)) currInfo.Rate = currRate;
  442. else currInfo.Rate = item.Rate;
  443. currInfos.Add(currInfo);
  444. }
  445. rateCurrInfo.teamRates = currInfos;
  446. teamRates.Add(rateCurrInfo);
  447. }
  448. OPDto.teamRateUpdateInfos = teamRates;
  449. await PostGroupRateUpdate(OPDto);
  450. return true;
  451. }
  452. /// <summary>
  453. /// 团组汇率币种拆分
  454. /// 团组币种按指定格式拆分 返回集合
  455. /// </summary>
  456. /// <param name="currStr"></param>
  457. /// <returns></returns>
  458. public List<TeamRateDescView> GroupCurrencySplittings(string currStr)
  459. {
  460. List<TeamRateDescView> _view = new List<TeamRateDescView>();
  461. if (!string.IsNullOrEmpty(currStr))
  462. {
  463. if (currStr.Contains("|"))
  464. {
  465. string[] currencyArr = currStr.Split("|");
  466. foreach (string currency in currencyArr)
  467. {
  468. _view.Add(GroupCurrencySplittingSingle(currency));
  469. }
  470. }
  471. else
  472. {
  473. _view.Add(GroupCurrencySplittingSingle(currStr));
  474. }
  475. }
  476. return _view;
  477. }
  478. /// <summary>
  479. /// 团组汇率币种拆分
  480. /// 团组币种按指定格式拆分 返回集合
  481. /// return TeamRateDescView
  482. /// </summary>
  483. /// <param name="currStr"></param>
  484. /// <returns></returns>
  485. public TeamRateDescView GroupCurrencySplittingSingle(string currStr)
  486. {
  487. TeamRateDescView _view = new TeamRateDescView();
  488. if (!string.IsNullOrEmpty(currStr))
  489. {
  490. string[] currency1 = currStr.Split(":");
  491. string[] currency2 = currency1[0].Split("(");
  492. _view = new TeamRateDescView()
  493. {
  494. CurrencyCode = currency2[1].Replace(")", "").TrimEnd(),
  495. CurrencyName = currency2[0],
  496. Rate = decimal.Parse(currency1[1]),
  497. };
  498. }
  499. return _view;
  500. }
  501. /// <summary>
  502. /// 团组汇率币种拆分 注意返回 实体类
  503. /// 团组币种按指定格式拆分 返回集合
  504. /// return TeamRateDescView
  505. /// </summary>
  506. /// <param name="currStr"></param>
  507. /// <returns></returns>
  508. public TeamRateDescAddCurrencyIdView GroupCurrencySplittingSingle(List<SetDataInfoView> currs,string currStr)
  509. {
  510. TeamRateDescAddCurrencyIdView _view = new TeamRateDescAddCurrencyIdView();
  511. if (!string.IsNullOrEmpty(currStr))
  512. {
  513. string[] currency1 = currStr.Split(":");
  514. string[] currency2 = currency1[0].Split("(");
  515. string currencyCode = currency2[1].Replace(")", "").TrimEnd();
  516. SetDataInfoView dataInfoView = new SetDataInfoView();
  517. dataInfoView = currs.Where(it => it.Name == currencyCode).FirstOrDefault();
  518. int currencyId = currs.Where(it => it.Name == currencyCode).FirstOrDefault().Id;
  519. _view = new TeamRateDescAddCurrencyIdView()
  520. {
  521. CurrencyId = dataInfoView.Id,
  522. CurrencyCode = currencyCode,
  523. CurrencyName = currency2[0],
  524. Rate = decimal.Parse(currency1[1]),
  525. };
  526. }
  527. return _view;
  528. }
  529. /// <summary>
  530. /// 团组汇率 币种 Item (来源:团组汇率)
  531. /// 根据 团组Id And 业务类型(CTable)Id
  532. /// api处理CTable = 285,默认返回CNY
  533. /// </summary>
  534. /// <param name="portType"></param>
  535. /// <param name="diId"></param>
  536. /// <param name="cTable"></param>
  537. /// <returns></returns>
  538. public async Task<TeamRateModelGeneralView> PostGroupTeamRateByDiIdAndCTableId(int portType, int diId, int cTable)
  539. {
  540. TeamRateModelGeneralView _view = new TeamRateModelGeneralView();
  541. if (diId < 1)
  542. {
  543. return _view;
  544. }
  545. if (cTable < 1)
  546. {
  547. return _view;
  548. }
  549. if (portType == 1 || portType == 2 || portType == 3)
  550. {
  551. string teamRateInfoSql = string.Format(@"Select sd.Name,tr.* From Grp_TeamRate tr
  552. Left Join Sys_SetData sd On sd.IsDel=0 And sd.STid=16 And tr.CTable = sd.Id
  553. Where tr.IsDel = 0 And tr.DiId = {0} And tr.CTable = {1}", diId, cTable);
  554. var teamRateInfo = _sqlSugar.SqlQueryable<TeamRateInfoView>(teamRateInfoSql).ToList();
  555. #region 团组汇率
  556. #region 单独处理Ctable 币种汇率 默认 为CNY
  557. if (cTable == 285)
  558. {
  559. _view = new TeamRateModelGeneralView()
  560. {
  561. Id = 0,
  562. CTableId = 285,
  563. CTableName = "其他款项与收款退还",
  564. TeamRates = new List<TeamRateDescAddCurrencyIdView>() {
  565. new TeamRateDescAddCurrencyIdView()
  566. {
  567. CurrencyId = 836,
  568. CurrencyCode = "CNY",
  569. CurrencyName = "人民币",
  570. Rate = 1.0000M,
  571. }
  572. }
  573. };
  574. return _view;
  575. }
  576. #endregion
  577. List<SetDataInfoView> currencyDatas = new List<SetDataInfoView>();
  578. #region 获取所有币种
  579. string sql = string.Format(@"select * from Sys_SetData where STid = {0} and isdel = 0", 66);
  580. var DBdata = _setDataRep.GetListBySqlWithNolock(sql);
  581. if (DBdata == null || DBdata.Count == 0)
  582. {
  583. return _view;
  584. }
  585. currencyDatas = DBdata.Select(x => new SetDataInfoView
  586. {
  587. Name = x.Name,
  588. Id = x.Id,
  589. Remark = x.Remark,
  590. }).ToList();
  591. #endregion
  592. foreach (TeamRateInfoView item in teamRateInfo)
  593. {
  594. TeamRateModelGeneralView teamRateModelInfo = new TeamRateModelGeneralView();
  595. teamRateModelInfo.Id = item.Id;
  596. teamRateModelInfo.CTableId = item.CTable;
  597. teamRateModelInfo.CTableName = item.Name;
  598. List<TeamRateDescAddCurrencyIdView> teamRateDescViews = new List<TeamRateDescAddCurrencyIdView>();
  599. #region 拆分remark里的汇率
  600. if (item.Remark.Contains("|"))
  601. {
  602. string[] currencyArr = item.Remark.Split("|");
  603. foreach (string currency in currencyArr)
  604. {
  605. teamRateDescViews.Add(GroupCurrencySplittingSingle(currencyDatas, currency));
  606. }
  607. }
  608. else
  609. {
  610. teamRateDescViews.Add(GroupCurrencySplittingSingle(currencyDatas, item.Remark));
  611. }
  612. #endregion
  613. if (teamRateDescViews.Count > 0)
  614. {
  615. teamRateDescViews = teamRateDescViews.OrderBy(it => it.CurrencyId).ToList();
  616. }
  617. teamRateModelInfo.TeamRates = teamRateDescViews;
  618. _view = teamRateModelInfo;
  619. }
  620. if (_view.TeamRates == null)
  621. {
  622. _view.TeamRates = new List<TeamRateDescAddCurrencyIdView>();
  623. }
  624. #endregion
  625. }
  626. return _view;
  627. }
  628. /// <summary>
  629. /// 获取团组相关模块的currencyList
  630. /// </summary>
  631. /// <param name="portType"></param>
  632. /// <param name="diId"></param>
  633. /// <param name="cTable"></param>
  634. /// <returns></returns>
  635. public async Task<List<TeamRateDescAddCurrencyIdView>> PostGroupTeamRateItemByDiIdAndCTableId(int portType, int diId, int cTable)
  636. {
  637. List<TeamRateDescAddCurrencyIdView> teamRateDescAddCurrencyIdViews = new List<TeamRateDescAddCurrencyIdView>();
  638. TeamRateModelGeneralView teamRateModelGeneralView = await PostGroupTeamRateByDiIdAndCTableId(portType, diId, cTable);
  639. teamRateDescAddCurrencyIdViews = teamRateModelGeneralView.TeamRates;
  640. return teamRateDescAddCurrencyIdViews;
  641. }
  642. /// <summary>
  643. /// 获取团组汇率 币种使用次数
  644. /// </summary>
  645. /// <returns></returns>
  646. public async Task<List<CurrencyHot>> PostGroupTeamRateHot()
  647. {
  648. List<CurrencyHot> _view = new List<CurrencyHot>();
  649. string teamRateInfoSql = string.Format(@"Select sd.Name,tr.* From Grp_TeamRate tr
  650. Left Join Sys_SetData sd On sd.IsDel=0 And sd.STid=16 And tr.CTable = sd.Id
  651. Where tr.IsDel = 0 ");
  652. var teamRateInfo = _sqlSugar.SqlQueryable<TeamRateInfoView>(teamRateInfoSql).ToList();
  653. #region 获取所有币种
  654. string sql = string.Format(@"Select * From Sys_SetData Where STid = {0} And IsDel = 0", 66);
  655. var currencyDatas = _sqlSugar.SqlQueryable<SetDataInfoView>(sql).ToList();
  656. _view = currencyDatas.Select(it => new CurrencyHot() { CurrencyId = it.Id, CurrencyCode = it.Name, CurrencyName = it.Remark}).ToList();
  657. #endregion
  658. List<TeamRateDescAddCurrencyIdView> teamRateDatas = new List<TeamRateDescAddCurrencyIdView>();
  659. foreach (TeamRateInfoView item in teamRateInfo)
  660. {
  661. List<TeamRateDescAddCurrencyIdView> teamRateDescViews = new List<TeamRateDescAddCurrencyIdView>();
  662. #region 拆分remark里的汇率
  663. if (item.Remark.Contains("|"))
  664. {
  665. string[] currencyArr = item.Remark.Split("|");
  666. foreach (string currency in currencyArr)
  667. {
  668. teamRateDescViews.Add(GroupCurrencySplittingSingle(currencyDatas, currency));
  669. }
  670. }
  671. else
  672. {
  673. teamRateDescViews.Add(GroupCurrencySplittingSingle(currencyDatas, item.Remark));
  674. }
  675. #endregion
  676. if (teamRateDescViews.Count > 0)
  677. {
  678. teamRateDescViews = teamRateDescViews.OrderBy(it => it.CurrencyId).ToList();
  679. teamRateDatas.AddRange(teamRateDescViews);
  680. }
  681. }
  682. foreach (var item in _view)
  683. {
  684. if (item.CurrencyId == 836) // 人民币
  685. {
  686. item.Rate = 1.0000M;
  687. }
  688. item.Number = teamRateDatas.Where(it => item.CurrencyId == it.CurrencyId).ToList().Count;
  689. }
  690. if (_view.Count > 0)
  691. {
  692. _view = _view.OrderByDescending(it => it.Number).ToList();
  693. }
  694. return _view;
  695. }
  696. }
  697. }