TeamRateRepository.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. using Newtonsoft.Json;
  2. using OASystem.Domain;
  3. using OASystem.Domain.Dtos.Financial;
  4. using OASystem.Domain.Dtos.Groups;
  5. using OASystem.Domain.Entities.Financial;
  6. using OASystem.Domain.ViewModels.Financial;
  7. using OASystem.Infrastructure.Repositories.System;
  8. using Serilog;
  9. using SqlSugar;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. namespace OASystem.Infrastructure.Repositories.Groups
  16. {
  17. /// <summary>
  18. /// 团组汇率 仓库
  19. /// </summary>
  20. public class TeamRateRepository : BaseRepository<Grp_TeamRate, TeamRateView>
  21. {
  22. private readonly SetDataRepository _setDataRep;
  23. private readonly DelegationInfoRepository _deleInfoRep;
  24. public TeamRateRepository(SqlSugarClient sqlSugar, SetDataRepository setDataRep, DelegationInfoRepository deleInfoRep)
  25. : base(sqlSugar)
  26. {
  27. _setDataRep = setDataRep;
  28. _deleInfoRep = deleInfoRep;
  29. }
  30. /// <summary>
  31. /// 团组汇率 Rep
  32. /// </summary>
  33. /// <param name="dto"></param>
  34. /// <returns></returns>
  35. public async Task<Result> GetGroupRateDataSource(TeamRateDto dto)
  36. {
  37. Result result = new() { Code = -2 };
  38. GroupNameDto groupNameDto = new GroupNameDto() { PortType = dto.PortType};
  39. var groups = await _deleInfoRep.GetGroupNameList(groupNameDto);
  40. var teamRateDatas = await _setDataRep.GetSetDataBySTId(_setDataRep, 66); // STid=66 全球币种
  41. dynamic _data = null;
  42. if (dto.PortType == 1)
  43. {
  44. List<Sys_SetData> sys_SetDatas = new List<Sys_SetData>();
  45. sys_SetDatas = JsonConvert.DeserializeObject<List<Sys_SetData>>(JsonConvert.SerializeObject(teamRateDatas.Data));
  46. List<TeamRateDescView> teamRateDescViews = new List<TeamRateDescView>();
  47. foreach (Sys_SetData item in sys_SetDatas)
  48. {
  49. teamRateDescViews.Add(new TeamRateDescView() {
  50. CurrencyName = item.Remark,
  51. CurrencyCode = item.Name,
  52. Rate = 0.0000M
  53. });
  54. }
  55. _data = new { GroupData = groups.Data, TeamRateData = teamRateDescViews };
  56. }
  57. else if (dto.PortType == 2)
  58. {
  59. }
  60. else if (dto.PortType == 3)
  61. {
  62. }
  63. result.Code = 0;
  64. result.Msg = "查询成功!";
  65. result.Data = _data;
  66. return result;
  67. }
  68. /// <summary>
  69. /// 团组汇率 更改数据
  70. /// </summary>
  71. /// <param name="dto"></param>
  72. /// <returns></returns>
  73. public async Task<Result> GetGroupRateChangeData()
  74. {
  75. Result result = new() { Code = -2 };
  76. string teamRateInfoSql = string.Format(@"Select * From Grp_TeamRate tr Where tr.IsDel = 0");
  77. var teamRateInfo = await _sqlSugar.SqlQueryable<Grp_TeamRate>(teamRateInfoSql).ToListAsync();
  78. dynamic _data = null;
  79. #region 团组汇率 - 详细汇率信息
  80. List<SetDataInfoView> otherCurrencyData1 = new List<SetDataInfoView>();
  81. var otherCurrencyData = await _setDataRep.GetSetDataBySTId(_setDataRep, 13);
  82. if (otherCurrencyData.Code == 0 && otherCurrencyData.Data != null)
  83. {
  84. string otherCurrencyStr = JsonConvert.SerializeObject(otherCurrencyData.Data);
  85. otherCurrencyData1 = JsonConvert.DeserializeObject<List<SetDataInfoView>>(otherCurrencyStr);
  86. //var otherCurrency = otherCurrencyData1
  87. }
  88. foreach (Grp_TeamRate item1 in teamRateInfo)
  89. {
  90. string rateStr = string.Empty;
  91. if (item1.RateU != 0) rateStr += "美元(USD):" + item1.RateU + "|";
  92. if (item1.RateE != 0) rateStr += "欧元(EUR):" + item1.RateE + "|";
  93. if (item1.RateJ != 0)
  94. rateStr += "日元(JPY):" + item1.RateJ + "|";
  95. if (item1.RateH != 0)
  96. rateStr += "港币(HKD):" + item1.RateH + "|";
  97. if (item1.RateN != 0)
  98. rateStr += "新西兰元(NZD):" + item1.RateN + "|";
  99. if (item1.RateS != 0)
  100. rateStr += "新加坡币(SGD):" + item1.RateS + "|";
  101. if (item1.RateA != 0)
  102. rateStr += "澳大利亚元(AUD):" + item1.RateA + "|";
  103. if (item1.RateC != 0)
  104. rateStr += "加拿大元(CAD):" + item1.RateC + "|";
  105. if (item1.RateT != 0)
  106. rateStr += "泰国铢(THB):" + item1.RateT + "|";
  107. if (item1.RateBL != 0)
  108. rateStr += "波兰兹罗提(PLN):" + item1.RateBL + "|";
  109. if (item1.RateHB != 0)
  110. rateStr += "韩国元(KRW):" + item1.RateHB + "|";
  111. if (item1.RateFJD != 0)
  112. rateStr += "斐济元(FJD):" + item1.RateFJD + "|";
  113. if (item1.RateTL != 0)
  114. rateStr += "土耳其里拉(TRY):" + item1.RateTL + "|";
  115. if (item1.RateRP != 0)
  116. rateStr += "印度尼西亚卢比(IDR):" + item1.RateRP + "|";
  117. if (item1.RatePeso != 0)
  118. rateStr += "菲律宾比索(PHP):" + item1.RatePeso + "|";
  119. if (item1.RateMYR != 0)
  120. rateStr += "林吉特(MYR):" + item1.RateMYR + "|";
  121. if (item1.RateCZK != 0)
  122. rateStr += "捷克货币(CZK):" + item1.RateCZK + "|";
  123. if (item1.RateMXN != 0)
  124. rateStr += "墨西哥比索(MXN):" + item1.RateMXN + "|";
  125. if (item1.RateMOP != 0)
  126. rateStr += "澳门元(MOP):" + item1.RateMOP + "|";
  127. if (item1.RateARS != 0)
  128. rateStr += "阿根廷比索(ARS):" + item1.RateARS + "|";
  129. if (item1.RateHUF != 0)
  130. rateStr += "匈牙利福林(HUF):" + item1.RateHUF + "|";
  131. if (item1.RateRUB != 0)
  132. rateStr += "卢布(RUB):" + item1.RateRUB + "|";
  133. SetDataInfoView setData = otherCurrencyData1.Where(x => x.Id == item1.OtherRateId).FirstOrDefault();
  134. if (setData != null)
  135. {
  136. if (item1.OtherPrice != 0)
  137. rateStr += string.Format("{0}({1}):{2}", setData.Remark, setData.Name, item1.OtherPrice);
  138. }
  139. else
  140. {
  141. if (rateStr.Length > 0)
  142. {
  143. rateStr = rateStr.Substring(0, rateStr.Length - 1);
  144. }
  145. }
  146. item1.Remark = rateStr;
  147. }
  148. #endregion
  149. try
  150. {
  151. var _result = _sqlSugar.Updateable(teamRateInfo)
  152. .UpdateColumns(it => new {it.Remark} ) //更新列
  153. .WhereColumns(it => new { it.DiId,it.CTable }) //更新条件
  154. .ExecuteCommand();
  155. result.Code = 0;
  156. result.Msg = "数据修改成功!";
  157. result.Data = _data;
  158. }
  159. catch (Exception ex)
  160. {
  161. result.Msg = ex.Message;
  162. }
  163. return result;
  164. }
  165. /// <summary>
  166. /// 团组汇率 Rep
  167. /// </summary>
  168. /// <param name="dto"></param>
  169. /// <returns></returns>
  170. public async Task<Result> GetGroupRateInfoByDiid(TeamRateInfoDto dto)
  171. {
  172. Result result = new() { Code = -2 };
  173. GroupInfoDto groupInfoDto = new GroupInfoDto() { Id = dto.Diid,PortType = dto.PortType, PageIndex = dto.PageIndex, PageSize = dto.PageSize };
  174. var groupInfo = await _deleInfoRep.GetGroupInfo(groupInfoDto);
  175. string teamRateInfoSql = string.Format(@"Select sd.Name,tr.* From Grp_TeamRate tr
  176. Left Join Sys_SetData sd On sd.IsDel=0 And sd.STid=16 And tr.CTable = sd.Id
  177. Where tr.DiId = {0} And tr.IsDel = 0",dto.Diid);
  178. var teamRateInfo = await _sqlSugar.SqlQueryable<TeamRateInfoView>(teamRateInfoSql).ToListAsync();
  179. dynamic _data = null;
  180. if (dto.PortType == 1)
  181. {
  182. #region 团组汇率 - 详细汇率信息
  183. //List<TeamRateModelView> teamRateModels = new List<TeamRateModelView>();
  184. //List<SetDataInfoView> otherCurrencyData1 = new List<SetDataInfoView>();
  185. //var otherCurrencyData = await _setDataRep.GetSetDataBySTId(_setDataRep, 13);
  186. //if (otherCurrencyData.Code == 0 && otherCurrencyData.Data != null)
  187. //{
  188. // string otherCurrencyStr = JsonConvert.SerializeObject(otherCurrencyData.Data);
  189. // otherCurrencyData1 = JsonConvert.DeserializeObject<List<SetDataInfoView>>(otherCurrencyStr);
  190. // //var otherCurrency = otherCurrencyData1
  191. //}
  192. //foreach (TeamRateInfoView item in teamRateInfo)
  193. //{
  194. // TeamRateModelView teamRateModelInfo = new TeamRateModelView();
  195. // foreach (TeamRateInfoView item1 in teamRateInfo)
  196. // {
  197. // if (item.CTable == item1.CTable)
  198. // {
  199. // teamRateModelInfo.CTableId = item1.CTable;
  200. // teamRateModelInfo.CTableName = item1.Name;
  201. // List<TeamRateDescView> teamRateDescViews = new List<TeamRateDescView>();
  202. // teamRateDescViews.Add(new TeamRateDescView() { CurrencyName = "美元", CurrencyCode = "USD", Rate = item1.RateU });
  203. // teamRateDescViews.Add(new TeamRateDescView() { CurrencyName = "欧元", CurrencyCode = "EUR", Rate = item1.RateE });
  204. // teamRateDescViews.Add(new TeamRateDescView() { CurrencyName = "日元", CurrencyCode = "JPY", Rate = item1.RateJ });
  205. // teamRateDescViews.Add(new TeamRateDescView() { CurrencyName = "港币", CurrencyCode = "HKD", Rate = item1.RateH });
  206. // teamRateDescViews.Add(new TeamRateDescView() { CurrencyName = "新西兰元", CurrencyCode = "NZD", Rate = item1.RateN });
  207. // teamRateDescViews.Add(new TeamRateDescView() { CurrencyName = "新加坡币", CurrencyCode = "SGD", Rate = item1.RateS });
  208. // teamRateDescViews.Add(new TeamRateDescView() { CurrencyName = "澳大利亚元", CurrencyCode = "AUD", Rate = item1.RateA });
  209. // teamRateDescViews.Add(new TeamRateDescView() { CurrencyName = "加拿大元", CurrencyCode = "CAD", Rate = item1.RateC });
  210. // teamRateDescViews.Add(new TeamRateDescView() { CurrencyName = "泰国铢", CurrencyCode = "THB", Rate = item1.RateT });
  211. // teamRateDescViews.Add(new TeamRateDescView() { CurrencyName = "波兰兹罗提", CurrencyCode = "PLN", Rate = item1.RateBL });
  212. // teamRateDescViews.Add(new TeamRateDescView() { CurrencyName = "韩国元", CurrencyCode = "KRW", Rate = item1.RateHB });
  213. // teamRateDescViews.Add(new TeamRateDescView() { CurrencyName = "斐济元", CurrencyCode = "FJD", Rate = item1.RateFJD });
  214. // teamRateDescViews.Add(new TeamRateDescView() { CurrencyName = "土耳其里拉", CurrencyCode = "TRY", Rate = item1.RateTL });
  215. // teamRateDescViews.Add(new TeamRateDescView() { CurrencyName = "印度尼西亚卢比", CurrencyCode = "IDR", Rate = item1.RateRP });
  216. // teamRateDescViews.Add(new TeamRateDescView() { CurrencyName = "菲律宾比索", CurrencyCode = "PHP", Rate = item1.RatePeso });
  217. // teamRateDescViews.Add(new TeamRateDescView() { CurrencyName = "林吉特", CurrencyCode = "MYR", Rate = item1.RateMYR });
  218. // teamRateDescViews.Add(new TeamRateDescView() { CurrencyName = "捷克货币", CurrencyCode = "CZK", Rate = item1.RateCZK });
  219. // teamRateDescViews.Add(new TeamRateDescView() { CurrencyName = "墨西哥比索", CurrencyCode = "MXN", Rate = item1.RateMXN });
  220. // teamRateDescViews.Add(new TeamRateDescView() { CurrencyName = "澳门元", CurrencyCode = "MOP", Rate = item1.RateMOP });
  221. // teamRateDescViews.Add(new TeamRateDescView() { CurrencyName = "阿根廷比索", CurrencyCode = "ARS", Rate = item1.RateARS });
  222. // teamRateDescViews.Add(new TeamRateDescView() { CurrencyName = "匈牙利福林", CurrencyCode = "HUF", Rate = item1.RateHUF });
  223. // teamRateDescViews.Add(new TeamRateDescView() { CurrencyName = "卢布", CurrencyCode = "RUB", Rate = item1.RateRUB });
  224. // SetDataInfoView setData = otherCurrencyData1.Where(x => x.Id == item1.OtherRateId).FirstOrDefault();
  225. // if (setData != null)
  226. // {
  227. // teamRateDescViews.Add(new TeamRateDescView() { CurrencyName = setData.Remark, CurrencyCode = setData.Name, Rate = item1.OtherPrice });
  228. // }
  229. // teamRateModelInfo.TeamRates = teamRateDescViews;
  230. // }
  231. // }
  232. // teamRateModels.Add(teamRateModelInfo);
  233. //}
  234. #endregion
  235. #region 团组汇率
  236. List<TeamRateModelView> teamRateModels = new List<TeamRateModelView>();
  237. foreach (TeamRateInfoView item in teamRateInfo)
  238. {
  239. TeamRateModelView teamRateModelInfo = new TeamRateModelView();
  240. teamRateModelInfo.Id = item.Id;
  241. teamRateModelInfo.CTableId = item.CTable;
  242. teamRateModelInfo.CTableName = item.Name;
  243. List<TeamRateDescView> teamRateDescViews = new List<TeamRateDescView>();
  244. #region 拆分remark里的汇率
  245. if (item.Remark.Contains("|"))
  246. {
  247. string[] currencyArr = item.Remark.Split("|");
  248. foreach (string currency in currencyArr)
  249. {
  250. string[] currency1 = currency.Split(":");
  251. string[] currency2 = currency1[0].Split("(");
  252. TeamRateDescView rateDescView = new TeamRateDescView() {
  253. CurrencyCode = currency2[1].Replace(")", "").TrimEnd(),
  254. CurrencyName = currency2[0],
  255. Rate = decimal.Parse(currency1[1]),
  256. };
  257. teamRateDescViews.Add(rateDescView);
  258. }
  259. }
  260. #endregion
  261. teamRateModelInfo.TeamRates = teamRateDescViews;
  262. teamRateModels.Add(teamRateModelInfo);
  263. }
  264. #endregion
  265. _data = new { GroupInfo = groupInfo.Data, TeamRateData = teamRateModels };
  266. }
  267. else if (dto.PortType == 2)
  268. {
  269. }
  270. else if (dto.PortType == 3)
  271. {
  272. }
  273. result.Code = 0;
  274. result.Msg = "查询成功!";
  275. result.Data = _data;
  276. return result;
  277. }
  278. /// <summary>
  279. /// 团组汇率 更新 or 添加
  280. /// </summary>
  281. /// <param name="dto"></param>
  282. /// <returns></returns>
  283. public async Task<Result> PostGroupRateUpdate(TeamRateUpdateDto dto)
  284. {
  285. Result result = new() { Code = -2 };
  286. List<Grp_TeamRate> teamRates = new List<Grp_TeamRate>();
  287. foreach (TeamRateUpdateInfo item in dto.teamRateUpdateInfos)
  288. {
  289. Grp_TeamRate teamRateInfo = new Grp_TeamRate();
  290. string currencyStr = string.Empty;
  291. foreach (TeamRateDescView currency in item.teamRates)
  292. {
  293. currencyStr += string.Format(@"{0}({1}):{2}|", currency.CurrencyName, currency.CurrencyCode, currency.Rate);
  294. }
  295. if (currencyStr.Length > 0)
  296. {
  297. currencyStr = currencyStr.Substring(0, currencyStr.Length - 1);
  298. }
  299. teamRateInfo.DiId = dto.DiId;
  300. teamRateInfo.CreateUserId = dto.CreateUserId;
  301. teamRateInfo.Id = item.Id;
  302. teamRateInfo.CreateTime = DateTime.Now;
  303. teamRateInfo.CTable = item.CTable;
  304. teamRateInfo.Remark = currencyStr;
  305. teamRates.Add(teamRateInfo);
  306. }
  307. int addCount = 0, updateCount = 0;
  308. if (dto.PortType == 1)
  309. {
  310. try
  311. {
  312. var x = _sqlSugar.Storageable(teamRates).ToStorage();
  313. addCount= x.AsInsertable.ExecuteCommand(); //不存在插入
  314. updateCount = x.AsUpdateable.ExecuteCommand(); //存在更新
  315. }
  316. catch (Exception ex)
  317. {
  318. result.Msg = ex.Message;
  319. }
  320. }
  321. else if (dto.PortType == 2)
  322. {
  323. }
  324. else if (dto.PortType == 3)
  325. {
  326. }
  327. result.Code = 0;
  328. result.Msg = string.Format(@"操作成功!添加:{0}条;更新:{1};", addCount,updateCount);
  329. return result;
  330. }
  331. /// <summary>
  332. /// 团组汇率 Rep
  333. /// 根据团组Id 查询汇率
  334. /// </summary>
  335. /// <param name="dto"></param>
  336. /// <returns></returns>
  337. public async Task<List<TeamRateModelView>> PostGroupRateInfoByDiId(int diId)
  338. {
  339. List<TeamRateModelView> teamRateModels = new List<TeamRateModelView>();
  340. string teamRateInfoSql = string.Format(@"Select sd.Name,tr.* From Grp_TeamRate tr
  341. Left Join Sys_SetData sd On sd.IsDel=0 And sd.STid=16 And tr.CTable = sd.Id
  342. Where tr.DiId = {0} And tr.IsDel = 0", diId);
  343. var teamRateInfo = await _sqlSugar.SqlQueryable<TeamRateInfoView>(teamRateInfoSql).ToListAsync();
  344. #region 团组汇率
  345. foreach (TeamRateInfoView item in teamRateInfo)
  346. {
  347. TeamRateModelView teamRateModelInfo = new TeamRateModelView();
  348. teamRateModelInfo.Id = item.Id;
  349. teamRateModelInfo.CTableId = item.CTable;
  350. teamRateModelInfo.CTableName = item.Name;
  351. List<TeamRateDescView> teamRateDescViews = new List<TeamRateDescView>();
  352. #region 拆分remark里的汇率
  353. if (item.Remark.Contains("|"))
  354. {
  355. string[] currencyArr = item.Remark.Split("|");
  356. foreach (string currency in currencyArr)
  357. {
  358. string[] currency1 = currency.Split(":");
  359. string[] currency2 = currency1[0].Split("(");
  360. TeamRateDescView rateDescView = new TeamRateDescView()
  361. {
  362. CurrencyCode = currency2[1].Replace(")", "").TrimEnd(),
  363. CurrencyName = currency2[0],
  364. Rate = decimal.Parse(currency1[1]),
  365. };
  366. teamRateDescViews.Add(rateDescView);
  367. }
  368. }
  369. #endregion
  370. teamRateModelInfo.TeamRates = teamRateDescViews;
  371. teamRateModels.Add(teamRateModelInfo);
  372. }
  373. #endregion
  374. return teamRateModels;
  375. }
  376. }
  377. }