VisaPriceRepository.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. 
  2. using AutoMapper;
  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 Org.BouncyCastle.Asn1.Cms;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Linq;
  15. using System.Security.Cryptography;
  16. using System.Text;
  17. using System.Threading.Tasks;
  18. namespace OASystem.Infrastructure.Repositories.Groups
  19. {
  20. public class VisaPriceRepository : BaseRepository<Grp_VisaInfo, VisaPriceDto>
  21. {
  22. private readonly IMapper _mapper;
  23. public VisaPriceRepository(SqlSugarClient sqlSugar,IMapper mapper)
  24. : base(sqlSugar)
  25. {
  26. _mapper=mapper;
  27. }
  28. /// <summary>
  29. /// 根据diid查询签证费用列表
  30. /// </summary>
  31. /// <param name="dto"></param>
  32. /// <returns></returns>
  33. public async Task<Result> PostVisaByDiId(VisaPriceDto dto)
  34. {
  35. Result result = new Result() { Code = -2, Msg = "未知错误" };
  36. try
  37. {
  38. string sqlWhere = string.Empty;
  39. if (!string.IsNullOrWhiteSpace(dto.VisaClient))
  40. {
  41. sqlWhere += string.Format(@" And v.VisaClient like '%{0}%'", dto.VisaClient);
  42. }
  43. sqlWhere += string.Format(@"And v.DIId={0} and v.isdel={1}", dto.DiID, 0);
  44. string UserId = "";
  45. List<Grp_GroupsTaskAssignment> gtaUIdList = _sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(a => a.DIId == dto.DiID && a.IsDel == 0 && a.CTId == 80).ToList();
  46. foreach (Grp_GroupsTaskAssignment gta in gtaUIdList)
  47. UserId += gta.UId + ",";
  48. if (!string.IsNullOrWhiteSpace(UserId))
  49. {
  50. UserId = UserId.Substring(0, UserId.Length - 1);
  51. }
  52. sqlWhere += string.Format(@" And v.CreateUserId in ({0})", UserId);
  53. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  54. {
  55. Regex r = new Regex("And");
  56. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  57. }
  58. string sql = string.Format(@"select *,(select IsAuditGM from Grp_CreditCardPayment where CTable=80 and CId=v.Id) IsAuditGM,(select Name from Sys_SetData where isdel=0 and v.VisaCurrency=Id) VisaCurrencyStr from Grp_VisaInfo v {0} order by CreateTime desc", sqlWhere);
  59. List<VisaInfoView> infoViews = _sqlSugar.SqlQueryable<VisaInfoView>(sql).ToList();
  60. if (infoViews.Count != 0)
  61. {
  62. if (dto.PageIndex != 0 && dto.PageSize != 0)
  63. {
  64. int count = infoViews.Count;
  65. float totalPage = (float)count / dto.PageSize;//总页数
  66. if (totalPage == 0) totalPage = 1;
  67. else totalPage = (int)Math.Ceiling((double)totalPage);
  68. List<VisaInfoView> visaInfosPage = new List<VisaInfoView>();
  69. for (int i = 0; i < dto.PageSize; i++)
  70. {
  71. var RowIndex = i + (dto.PageIndex - 1) * dto.PageSize;
  72. if (RowIndex < infoViews.Count)
  73. {
  74. visaInfosPage.Add(infoViews[RowIndex]);
  75. }
  76. else
  77. {
  78. break;
  79. }
  80. }
  81. ListViewBase<VisaInfoView> rst = new ListViewBase<VisaInfoView>();
  82. rst.DataList = visaInfosPage;
  83. rst.DataCount = count;
  84. rst.CurrPageIndex = dto.PageIndex;
  85. rst.CurrPageSize = dto.PageSize;
  86. return result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
  87. }
  88. else
  89. {
  90. return result = new Result() { Code = 0, Msg = "查询成功!", Data = infoViews };
  91. }
  92. }
  93. else
  94. {
  95. if (dto.PageIndex != 0 && dto.PageSize != 0)
  96. {
  97. ListViewBase<VisaInfoView> rst = new ListViewBase<VisaInfoView>();
  98. rst.DataList = infoViews;
  99. rst.DataCount = infoViews.Count;
  100. rst.CurrPageIndex = dto.PageIndex;
  101. rst.CurrPageSize = dto.PageSize;
  102. return result = new Result() { Code = 0, Msg = "暂无数据!", Data = rst };
  103. }
  104. else
  105. {
  106. return result = new Result() { Code = 0, Msg = "暂无数据!", Data = infoViews };
  107. }
  108. }
  109. }
  110. catch (Exception)
  111. {
  112. return result = new Result() { Code = -2, Msg = "未知错误" };
  113. throw;
  114. }
  115. }
  116. /// <summary>
  117. /// 根据签证费用Id查询单条数据及c表数据
  118. /// </summary>
  119. /// <param name="dto"></param>
  120. /// <returns></returns>
  121. public async Task<Result> PostVisaById(PostVisaByIdDto dto)
  122. {
  123. Result result = new Result() { Code = -2, Msg = "未知错误" };
  124. try
  125. {
  126. Grp_VisaInfo _VisaInfo = _sqlSugar.Queryable<Grp_VisaInfo>().First(a => a.Id == dto.Id && a.IsDel==0);
  127. Grp_CreditCardPayment _CreditCardPayment = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a=>a.CId==dto.Id && a.IsDel==0 && a.CTable==80);
  128. var data = new
  129. {
  130. _VisaInfo = _VisaInfo,
  131. _CreditCardPayment = _CreditCardPayment
  132. };
  133. return result = new Result() { Code = 0, Msg = "暂无数据!", Data = data };
  134. }
  135. catch (Exception ex)
  136. {
  137. return result = new Result() { Code = -2, Msg = "未知错误" };
  138. }
  139. }
  140. /// <summary>
  141. /// 签证费用录入操作(Status:1.新增,2.修改)
  142. /// </summary>
  143. /// <param name="dto"></param>
  144. /// <returns></returns>
  145. public async Task<Result> OpVisaPrice(OpVisaPriceDto dto)
  146. {
  147. Result result = new Result() { Code = -2, Msg = "未知错误" };
  148. BeginTran();
  149. try
  150. {
  151. int id = 0;
  152. Grp_VisaInfo grp_Visa1 = _mapper.Map<Grp_VisaInfo>(dto);
  153. Grp_CreditCardPayment c = _mapper.Map<Grp_CreditCardPayment>(dto);
  154. c.PayMoney = grp_Visa1.VisaPrice;
  155. Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == dto.DiId && a.IsDel == 0 && a.CTable == 80);
  156. if (_TeamRate != null)
  157. {
  158. int OtherRateId = 0;
  159. Sys_SetData setData = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == _TeamRate.OtherRateId);
  160. if (setData != null)
  161. {
  162. OtherRateId = setData.Id;
  163. }
  164. #region 汇率换算
  165. if (grp_Visa1.VisaCurrency == 49)
  166. {
  167. c.RMBPrice = c.PayMoney * _TeamRate.RateU;
  168. c.DayRate = _TeamRate.RateU;
  169. }
  170. else if (OtherRateId == grp_Visa1.VisaCurrency)
  171. {
  172. c.RMBPrice = c.PayMoney * _TeamRate.OtherPrice;
  173. c.DayRate = _TeamRate.OtherPrice;
  174. }
  175. else if (grp_Visa1.VisaCurrency == 51)
  176. {
  177. c.RMBPrice = c.PayMoney * _TeamRate.RateE;
  178. c.DayRate = _TeamRate.RateE;
  179. }
  180. else if (grp_Visa1.VisaCurrency == 50)
  181. {
  182. c.RMBPrice = c.PayMoney * _TeamRate.RateJ;
  183. c.DayRate = _TeamRate.RateJ;
  184. }
  185. else if (grp_Visa1.VisaCurrency == 55)
  186. {
  187. c.RMBPrice = c.PayMoney * _TeamRate.RateH;
  188. c.DayRate = _TeamRate.RateH;
  189. }
  190. else if (grp_Visa1.VisaCurrency == 56)
  191. {
  192. c.RMBPrice = c.PayMoney * _TeamRate.RateN;
  193. c.DayRate = _TeamRate.RateN;
  194. }
  195. else if (grp_Visa1.VisaCurrency == 65)
  196. {
  197. c.RMBPrice = c.PayMoney * _TeamRate.RateS;
  198. c.DayRate = _TeamRate.RateS;
  199. }
  200. else if (grp_Visa1.VisaCurrency == 54)
  201. {
  202. c.RMBPrice = c.PayMoney * _TeamRate.RateA;
  203. c.DayRate = _TeamRate.RateA;
  204. }
  205. else if (grp_Visa1.VisaCurrency == 53)
  206. {
  207. c.RMBPrice = c.PayMoney * _TeamRate.RateC;
  208. c.DayRate = _TeamRate.RateC;
  209. }
  210. else if (grp_Visa1.VisaCurrency == 63)
  211. {
  212. c.RMBPrice = c.PayMoney * _TeamRate.RateT;
  213. c.DayRate = _TeamRate.RateT;
  214. }
  215. else if (grp_Visa1.VisaCurrency == 68)
  216. {
  217. c.RMBPrice = c.PayMoney * _TeamRate.RateBL;
  218. c.DayRate = _TeamRate.RateBL;
  219. }
  220. else if (grp_Visa1.VisaCurrency == 69)
  221. {
  222. c.RMBPrice = c.PayMoney * _TeamRate.RateHB;
  223. c.DayRate = _TeamRate.RateHB;
  224. }
  225. else if (grp_Visa1.VisaCurrency == 336)
  226. {
  227. c.RMBPrice = c.PayMoney * _TeamRate.RateFJD;
  228. c.DayRate = _TeamRate.RateFJD;
  229. }
  230. else if (grp_Visa1.VisaCurrency == 337)
  231. {
  232. c.RMBPrice = c.PayMoney * _TeamRate.RateTL;
  233. c.DayRate = _TeamRate.RateTL;
  234. }
  235. else if (grp_Visa1.VisaCurrency == 338)
  236. {
  237. c.RMBPrice = c.PayMoney * _TeamRate.RateRP;
  238. c.DayRate = _TeamRate.RateRP;
  239. }
  240. else if (grp_Visa1.VisaCurrency == 341)
  241. {
  242. c.RMBPrice = c.PayMoney * _TeamRate.RatePeso;
  243. c.DayRate = _TeamRate.RatePeso;
  244. }
  245. else if (grp_Visa1.VisaCurrency == 342)
  246. {
  247. c.RMBPrice = c.PayMoney * _TeamRate.RateMYR;
  248. c.DayRate = _TeamRate.RateMYR;
  249. }
  250. else if (grp_Visa1.VisaCurrency == 344)
  251. {
  252. c.RMBPrice = c.PayMoney * _TeamRate.RateCZK;
  253. c.DayRate = _TeamRate.RateCZK;
  254. }
  255. else if (grp_Visa1.VisaCurrency == 345)
  256. {
  257. c.RMBPrice = c.PayMoney * _TeamRate.RateMXN;
  258. c.DayRate = _TeamRate.RateMXN;
  259. }
  260. else if (grp_Visa1.VisaCurrency == 354)
  261. {
  262. c.RMBPrice = c.PayMoney * _TeamRate.RateMOP;
  263. c.DayRate = _TeamRate.RateMOP;
  264. }
  265. else if (grp_Visa1.VisaCurrency == 359)
  266. {
  267. c.RMBPrice = c.PayMoney * _TeamRate.RateARS;
  268. c.DayRate = _TeamRate.RateARS;
  269. }
  270. else if (grp_Visa1.VisaCurrency == 361)
  271. {
  272. c.RMBPrice = c.PayMoney * _TeamRate.RateHUF;
  273. c.DayRate = _TeamRate.RateHUF;
  274. }
  275. else if (grp_Visa1.VisaCurrency == 362)
  276. {
  277. c.RMBPrice = c.PayMoney * _TeamRate.RateRUB;
  278. c.DayRate = _TeamRate.RateRUB;
  279. }
  280. else
  281. {
  282. c.DayRate = 1;
  283. c.RMBPrice = c.PayMoney;
  284. }
  285. }
  286. else
  287. {
  288. c.DayRate = 1;
  289. c.RMBPrice = c.PayMoney;
  290. }
  291. #endregion
  292. if (dto.Status==1)//添加
  293. {
  294. Grp_VisaInfo grp_Visa =_sqlSugar.Queryable<Grp_VisaInfo>().First(a=>a.IsDel==0 && a.VisaCurrency==dto.VisaCurrency && a.VisaPrice==dto.VisaPrice && a.VisaClient==dto.VisaClient);
  295. if (grp_Visa!=null)
  296. {
  297. return result = new Result() { Code = -1, Msg = "该笔费用已存在,请勿重复添加!" };
  298. }
  299. else
  300. {
  301. id = await AddAsyncReturnId(grp_Visa1);
  302. if (id!=0)
  303. {
  304. c.PayMoney = dto.VisaPrice;
  305. c.PaymentCurrency = dto.VisaCurrency;
  306. c.Remark = dto.CRemark;
  307. c.PayPercentage = 100;
  308. c.CTable = 80;
  309. c.CId=id;
  310. c.IsAuditGM = 0;
  311. if (c.PayDId == 72)
  312. {
  313. c.IsPay = 1;
  314. }
  315. int cId = await _sqlSugar.Insertable(c).ExecuteReturnIdentityAsync();
  316. if (cId != 0)
  317. {
  318. result = new Result() { Code = 0, Msg = "添加成功!" };
  319. }
  320. else
  321. {
  322. RollbackTran();
  323. result = new Result() { Code = -1, Msg = "添加失败!" };
  324. }
  325. }
  326. else
  327. {
  328. RollbackTran();
  329. result = new Result() { Code = -1, Msg = "添加失败,请稍后重试!" };
  330. }
  331. }
  332. }
  333. else if (dto.Status==2)//修改
  334. {
  335. bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_VisaInfo
  336. {
  337. VisaClient = grp_Visa1.VisaClient,
  338. VisaPrice = grp_Visa1.VisaPrice,
  339. VisaCurrency = grp_Visa1.VisaCurrency,
  340. IsThird = grp_Visa1.IsThird,
  341. PassengerType = grp_Visa1.PassengerType,
  342. VisaNumber = grp_Visa1.VisaNumber,
  343. VisaFreeNumber = grp_Visa1.VisaFreeNumber,
  344. Remark = dto.Remark,
  345. });
  346. if (res)
  347. {
  348. c.PayMoney = dto.VisaPrice;
  349. c.PaymentCurrency = dto.VisaCurrency;
  350. c.Remark = dto.CRemark;
  351. c.PayPercentage = 100;
  352. c.CTable = 80;
  353. int CTable = await _sqlSugar.Updateable<Grp_CreditCardPayment>().Where(a => a.CId == grp_Visa1.Id && a.CTable==80).SetColumns(a => new Grp_CreditCardPayment
  354. {
  355. PayDId = dto.PayDId,
  356. PayMoney = c.PayMoney,
  357. PaymentCurrency = c.PaymentCurrency,
  358. Payee = c.Payee,
  359. OrbitalPrivateTransfer = c.OrbitalPrivateTransfer,
  360. DayRate = c.DayRate,
  361. RMBPrice = c.RMBPrice,
  362. ConsumptionPatterns = c.ConsumptionPatterns,
  363. ConsumptionDate = c.ConsumptionDate,
  364. CTDId = c.CTDId,
  365. CompanyBankNo = c.CompanyBankNo,
  366. OtherBankName = c.OtherBankName,
  367. OtherSideNo = c.OtherSideNo,
  368. OtherSideName = c.OtherSideName,
  369. BankNo = c.BankNo,
  370. CardholderName = c.CardholderName,
  371. Remark = c.Remark,
  372. }).ExecuteCommandAsync();
  373. result = new Result() { Code = 0, Msg = "修改成功!" };
  374. }
  375. else
  376. {
  377. RollbackTran();
  378. result = new Result() { Code = -1, Msg = "修改失败,请稍后重试!" };
  379. }
  380. }
  381. CommitTran();
  382. }
  383. catch (Exception ex)
  384. {
  385. result = new Result() { Code = -2, Msg = "未知错误" };
  386. }
  387. return result;
  388. }
  389. }
  390. }