VisaPriceRepository.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. 
  2. using AutoMapper;
  3. using NPOI.SS.Formula.Functions;
  4. using OASystem.Domain;
  5. using OASystem.Domain.Dtos.Financial;
  6. using OASystem.Domain.Dtos.Groups;
  7. using OASystem.Domain.Entities.Customer;
  8. using OASystem.Domain.Entities.Financial;
  9. using OASystem.Domain.Entities.Groups;
  10. using OASystem.Domain.ViewModels.Financial;
  11. using OASystem.Domain.ViewModels.Groups;
  12. using OASystem.Infrastructure.Repositories.System;
  13. using OASystem.Infrastructure.Tools;
  14. using Org.BouncyCastle.Asn1.Cms;
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Drawing;
  18. using System.Linq;
  19. using System.Security.Cryptography;
  20. using System.Text;
  21. using System.Threading.Tasks;
  22. namespace OASystem.Infrastructure.Repositories.Groups
  23. {
  24. public class VisaPriceRepository : BaseRepository<Grp_VisaInfo, VisaPriceDto>
  25. {
  26. private readonly IMapper _mapper;
  27. public VisaPriceRepository(SqlSugarClient sqlSugar, IMapper mapper)
  28. : base(sqlSugar)
  29. {
  30. _mapper = mapper;
  31. }
  32. /// <summary>
  33. /// 根据diid查询签证费用列表
  34. /// </summary>
  35. /// <param name="dto"></param>
  36. /// <returns></returns>
  37. public async Task<Result> PostVisaByDiId(VisaPriceDto dto)
  38. {
  39. Result result = new Result() { Code = -2, Msg = "未知错误" };
  40. if (dto.PortType == 0 || string.IsNullOrWhiteSpace(dto.PortType.ToString()))
  41. {
  42. return result = new Result() { Code = -1, Msg = "请传入PortType参数,请求端口分类 1 Web 2 Android 3 IOS" };
  43. }
  44. try
  45. {
  46. #region SQL条件拼接
  47. string sqlWhere = string.Empty;
  48. if (!string.IsNullOrWhiteSpace(dto.VisaClient))
  49. {
  50. sqlWhere += string.Format(@" And v.VisaClient like '%{0}%'", dto.VisaClient);
  51. }
  52. sqlWhere += string.Format(@"And v.DIId={0} and v.isdel={1}", dto.DiID, 0);
  53. string UserId = "";
  54. List<Grp_GroupsTaskAssignment> gtaUIdList = _sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(a => a.DIId == dto.DiID && a.IsDel == 0 && a.CTId == 80).ToList();
  55. foreach (Grp_GroupsTaskAssignment gta in gtaUIdList)
  56. UserId += gta.UId + ",";
  57. if (!string.IsNullOrWhiteSpace(UserId))
  58. {
  59. UserId = UserId.Substring(0, UserId.Length - 1);
  60. }
  61. else
  62. {
  63. UserId = "0";
  64. }
  65. sqlWhere += string.Format(@" And v.CreateUserId in ({0})", UserId);
  66. if (dto.IsPaySign != -1)
  67. {
  68. sqlWhere += string.Format(@" And c.IsPay = {0} ", dto.IsPaySign);
  69. }
  70. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  71. {
  72. Regex r = new Regex("And");
  73. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  74. }
  75. #endregion
  76. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  77. int endIndex = startIndex + dto.PageSize - 1;
  78. if (dto.PortType == 1)
  79. {
  80. //string sql = string.Format(@"select *,(select IsAuditGM from Grp_CreditCardPayment where CTable=80 and CId=v.Id and IsDel=0) IsAuditGM,
  81. // (select Name from Sys_SetData where isdel=0 and v.VisaCurrency=Id) VisaCurrencyStr from
  82. // Grp_VisaInfo v {0} order by CreateTime desc",sqlWhere);
  83. string sql = string.Format(@" Select v.*, c.IsAuditGM,c.IsPay,sd.Name As 'PayName' From Grp_VisaInfo as v With(Nolock)
  84. left Join Grp_CreditCardPayment as c With(Nolock) On v.Id = c.CId
  85. Left Join Sys_SetData as sd With(Nolock) On c.PayDId = sd.Id
  86. {0}
  87. And c.CTable = 80 And c.IsDel = 0 ", sqlWhere);
  88. List<VisaInfoView> infoViews = _sqlSugar.SqlQueryable<VisaInfoView>(sql).ToList();
  89. var parseIntValue = 0;
  90. var CrmIds = (from item in infoViews
  91. where item.VisaClient.Contains(",") || int.TryParse(item.VisaClient, out parseIntValue)
  92. select item.VisaClient).ToList();
  93. var strCrmIds = string.Join(',', CrmIds);
  94. List<Crm_DeleClient> clietArr = new List<Crm_DeleClient>();
  95. if (!string.IsNullOrWhiteSpace(strCrmIds))
  96. {
  97. sql = string.Format("SELECT * FROM Crm_DeleClient cdc where id in ({0}) and IsDel = 0", strCrmIds);
  98. clietArr = _sqlSugar.SqlQueryable<Crm_DeleClient>(sql).ToList();
  99. }
  100. Dictionary<int, string> dic_Currency = new Dictionary<int, string>();
  101. foreach (VisaInfoView view in infoViews)
  102. {
  103. if (dic_Currency.ContainsKey(view.VisaCurrency))
  104. {
  105. view.VisaCurrencyStr = dic_Currency[view.VisaCurrency];
  106. }
  107. else
  108. {
  109. List<Sys_SetData> temp_sdList = Query<Sys_SetData>(s => s.Id == view.VisaCurrency).ToList();
  110. if (temp_sdList.Count > 0)
  111. {
  112. view.VisaCurrencyStr = temp_sdList[0].Name;
  113. dic_Currency.Add(view.VisaCurrency, temp_sdList[0].Name);
  114. }
  115. else
  116. {
  117. view.VisaCurrencyStr = "未知";
  118. dic_Currency.Add(view.VisaCurrency, "未知");
  119. }
  120. }
  121. if (view.IsAuditGM == 0) view.IsAuditGMStr = "未审核";
  122. else if (view.IsAuditGM == 1) view.IsAuditGMStr = "已通过";
  123. else if (view.IsAuditGM == 2) view.IsAuditGMStr = "未通过";
  124. else if (view.IsAuditGM == 3) view.IsAuditGMStr = "自动审核";
  125. {
  126. if (view.VisaClient.Contains(","))
  127. {
  128. var splitArr = view.VisaClient.Split(',');
  129. var name = string.Empty;
  130. var i = 0;
  131. while (i < splitArr.Count())
  132. {
  133. if (int.TryParse(splitArr[i], out parseIntValue))
  134. {
  135. var clientObject = clietArr.Find(x => x.Id == parseIntValue);
  136. name += (clientObject?.LastName + clientObject?.FirstName);
  137. }
  138. i++;
  139. if (i < splitArr.Count())
  140. {
  141. name += " ";
  142. }
  143. }
  144. if (!string.IsNullOrWhiteSpace(name))
  145. {
  146. view.VisaClient = name.TrimEnd();
  147. }
  148. continue;
  149. }
  150. }
  151. if (int.TryParse(view.VisaClient, out parseIntValue))
  152. {
  153. var name = string.Empty;
  154. var clientObject = clietArr.Find(x => x.Id == parseIntValue);
  155. name += (clientObject?.LastName + clientObject?.FirstName);
  156. if (!string.IsNullOrWhiteSpace(name))
  157. {
  158. view.VisaClient = name;
  159. }
  160. continue;
  161. }
  162. }
  163. return result = new Result() { Code = 0, Msg = "查询成功!", Data = infoViews };
  164. }
  165. else if (dto.PortType == 2 || dto.PortType == 3)
  166. {
  167. string sql = string.Format(@"Select * From (
  168. Select row_number() over (order by v.Id Desc) as RowNumber,v.*,c.IsAuditGM,s.Name as VisaCurrencyStr,s1.Name As 'PayName'
  169. From Grp_VisaInfo v
  170. Left Join Grp_CreditCardPayment c On v.Id = c.CId and CTable=80 and c.isdel=0
  171. Left Join Sys_SetData s On v.VisaCurrency = s.Id
  172. Left Join Sys_SetData s1 On c.PayDId = s1.Id {0}
  173. ) temp Where RowNumber Between {1} and {2}", sqlWhere, startIndex, endIndex);
  174. List<VisaInfoView> infoViews = _sqlSugar.SqlQueryable<VisaInfoView>(sql).ToList();
  175. var parseIntValue = 0;
  176. var CrmIds = (from item in infoViews
  177. where item.VisaClient.Contains(",") || int.TryParse(item.VisaClient, out parseIntValue)
  178. select item.VisaClient).ToList();
  179. var strCrmIds = string.Join(',', CrmIds);
  180. List<Crm_DeleClient> clietArr = new List<Crm_DeleClient>();
  181. if (!string.IsNullOrWhiteSpace(strCrmIds))
  182. {
  183. sql = string.Format("SELECT * FROM Crm_DeleClient cdc where id in ({0}) and IsDel = 0", strCrmIds);
  184. clietArr = _sqlSugar.SqlQueryable<Crm_DeleClient>(sql).ToList();
  185. }
  186. foreach (VisaInfoView view in infoViews)
  187. {
  188. if (view.IsAuditGM == 0) view.IsAuditGMStr = "未审核";
  189. else if (view.IsAuditGM == 1) view.IsAuditGMStr = "已通过";
  190. else if (view.IsAuditGM == 2) view.IsAuditGMStr = "未通过";
  191. else if (view.IsAuditGM == 3) view.IsAuditGMStr = "自动审核";
  192. {
  193. if (view.VisaClient.Contains(","))
  194. {
  195. var splitArr = view.VisaClient.Split(',');
  196. var name = string.Empty;
  197. var i = 0;
  198. while (i < splitArr.Count())
  199. {
  200. if (int.TryParse(splitArr[i], out parseIntValue))
  201. {
  202. var clientObject = clietArr.Find(x => x.Id == parseIntValue);
  203. name += (clientObject?.LastName + clientObject?.FirstName);
  204. }
  205. i++;
  206. if (i < splitArr.Count())
  207. {
  208. name += "[*TuT*]";
  209. }
  210. }
  211. if (!string.IsNullOrWhiteSpace(name))
  212. {
  213. view.VisaClient = name.TrimEnd();
  214. }
  215. continue;
  216. }
  217. }
  218. if (int.TryParse(view.VisaClient, out parseIntValue))
  219. {
  220. var name = string.Empty;
  221. var clientObject = clietArr.Find(x => x.Id == parseIntValue);
  222. name += (clientObject?.LastName + clientObject?.FirstName);
  223. if (!string.IsNullOrWhiteSpace(name))
  224. {
  225. view.VisaClient = name;
  226. }
  227. continue;
  228. }
  229. }
  230. string CountSql = string.Format(@"Select COUNT(1) as Count From (
  231. Select v.*,c.IsAuditGM,s.Name as VisaCurrencyStr
  232. From Grp_VisaInfo v
  233. left Join Grp_CreditCardPayment c On v.Id = c.CId and CTable=80 and c.isdel=0
  234. Left Join Sys_SetData s On v.VisaCurrency = s.Id {0}
  235. ) temp", sqlWhere);
  236. DataCount dataCount = _sqlSugar.SqlQueryable<DataCount>(CountSql).First();
  237. if (dataCount != null)
  238. {
  239. int count = dataCount.Count;
  240. float totalPage = (float)count / dto.PageSize;//总页数
  241. if (totalPage == 0) totalPage = 1;
  242. else totalPage = (int)Math.Ceiling((double)totalPage);
  243. ListViewBase<VisaInfoView> rst = new ListViewBase<VisaInfoView>();
  244. rst.DataList = infoViews;
  245. rst.DataCount = count;
  246. rst.CurrPageIndex = dto.PageIndex;
  247. rst.CurrPageSize = dto.PageSize;
  248. return result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
  249. }
  250. }
  251. }
  252. catch (Exception ex)
  253. {
  254. return result = new Result() { Code = -2, Msg = "未知错误" };
  255. throw;
  256. }
  257. return result;
  258. }
  259. /// <summary>
  260. /// 根据签证费用Id查询单条数据及c表数据
  261. /// </summary>
  262. /// <param name="dto"></param>
  263. /// <returns></returns>
  264. public async Task<Result> PostVisaById(PostVisaByIdDto dto)
  265. {
  266. Result result = new Result() { Code = -2, Msg = "未知错误" };
  267. try
  268. {
  269. Grp_VisaInfo _VisaInfo = _sqlSugar.Queryable<Grp_VisaInfo>().First(a => a.Id == dto.Id && a.IsDel == 0);
  270. Grp_CreditCardPayment _CreditCardPayment = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable == 80);
  271. var data = new
  272. {
  273. VisaInfo = _VisaInfo,
  274. CreditCardPayment = _CreditCardPayment
  275. };
  276. return result = new Result() { Code = 0, Msg = "暂无数据!", Data = data };
  277. }
  278. catch (Exception ex)
  279. {
  280. return result = new Result() { Code = -2, Msg = "未知错误" };
  281. }
  282. }
  283. /// <summary>
  284. /// 签证费用录入操作(Status:1.新增,2.修改)
  285. /// </summary>
  286. /// <param name="dto"></param>
  287. /// <returns></returns>
  288. public async Task<Result> OpVisaPrice(OpVisaPriceDto dto)
  289. {
  290. Result result = new Result() { Code = -2, Msg = "未知错误" };
  291. BeginTran();
  292. int id = 0;
  293. Grp_VisaInfo grp_Visa1 = _mapper.Map<Grp_VisaInfo>(dto);
  294. Grp_CreditCardPayment c = _mapper.Map<Grp_CreditCardPayment>(dto);
  295. c.PayMoney = dto.VisaPrice;
  296. c.PaymentCurrency = dto.VisaCurrency;
  297. c.Remark = dto.CRemark;
  298. c.PayPercentage = 100;
  299. c.CTable = 80;
  300. c.CId = dto.Id;
  301. c.IsAuditGM = 0;
  302. if (c.PayDId == 72) c.IsPay = 1;
  303. else c.IsPay = 0;
  304. c.RMBPrice = c.PayMoney;
  305. c.DayRate = 1.0000M;
  306. Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == dto.DiId && a.IsDel == 0 && a.CTable == 80);
  307. List<CurrencyInfo> currencyInfos = new List<CurrencyInfo>();
  308. if (_TeamRate != null)
  309. {
  310. Sys_SetData _SetData = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == c.PaymentCurrency);
  311. if (_SetData != null)
  312. {
  313. currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  314. CurrencyInfo CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData.Name);
  315. if (CurrencyRate != null)
  316. {
  317. c.RMBPrice = c.PayMoney * Convert.ToDecimal(CurrencyRate.Rate);
  318. c.DayRate = CurrencyRate.Rate;
  319. }
  320. }
  321. }
  322. if (dto.Status == 1)//添加
  323. {
  324. Grp_VisaInfo grp_Visa = _sqlSugar.Queryable<Grp_VisaInfo>()
  325. .First(a => a.IsDel == 0 &&
  326. a.VisaDescription.Equals(dto.VisaDescription) &&
  327. a.VisaCurrency == dto.VisaCurrency &&
  328. a.VisaPrice == dto.VisaPrice &&
  329. a.VisaClient == dto.VisaClient
  330. );
  331. if (grp_Visa != null)
  332. {
  333. return result = new Result() { Code = -1, Msg = "该笔费用已存在,请勿重复添加!" };
  334. }
  335. else
  336. {
  337. id = await AddAsyncReturnId(grp_Visa1);
  338. if (id != 0)
  339. {
  340. c.CId = id;
  341. int cId = await _sqlSugar.Insertable(c).ExecuteReturnIdentityAsync();
  342. if (cId != 0)
  343. {
  344. var data = new { ccpId = cId, sign = 1 };
  345. result = new Result() { Code = 0, Msg = "添加成功!", Data = data };
  346. }
  347. else
  348. {
  349. RollbackTran();
  350. result = new Result() { Code = -1, Msg = "添加失败!" };
  351. }
  352. }
  353. else
  354. {
  355. RollbackTran();
  356. result = new Result() { Code = -1, Msg = "添加失败,请稍后重试!" };
  357. }
  358. }
  359. }
  360. else if (dto.Status == 2)//修改
  361. {
  362. bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_VisaInfo
  363. {
  364. VisaClient = grp_Visa1.VisaClient,
  365. VisaPrice = grp_Visa1.VisaPrice,
  366. VisaCurrency = grp_Visa1.VisaCurrency,
  367. IsThird = grp_Visa1.IsThird,
  368. PassengerType = grp_Visa1.PassengerType,
  369. VisaNumber = grp_Visa1.VisaNumber,
  370. VisaFreeNumber = grp_Visa1.VisaFreeNumber,
  371. Remark = dto.Remark,
  372. VisaDescription = dto.VisaDescription
  373. });
  374. if (res)
  375. {
  376. int CTable = await _sqlSugar.Updateable<Grp_CreditCardPayment>()
  377. .Where(a => a.CId == grp_Visa1.Id && a.CTable == 80)
  378. .SetColumns(a => new Grp_CreditCardPayment
  379. {
  380. PayDId = dto.PayDId,
  381. IsPay = c.IsPay,
  382. PayMoney = c.PayMoney,
  383. PaymentCurrency = c.PaymentCurrency,
  384. Payee = c.Payee,
  385. OrbitalPrivateTransfer = c.OrbitalPrivateTransfer,
  386. DayRate = c.DayRate,
  387. RMBPrice = c.RMBPrice,
  388. ConsumptionPatterns = c.ConsumptionPatterns,
  389. ConsumptionDate = c.ConsumptionDate,
  390. CTDId = c.CTDId,
  391. CompanyBankNo = c.CompanyBankNo,
  392. OtherBankName = c.OtherBankName,
  393. OtherSideNo = c.OtherSideNo,
  394. OtherSideName = c.OtherSideName,
  395. BankNo = c.BankNo,
  396. CardholderName = c.CardholderName,
  397. Remark = c.Remark,
  398. })
  399. .ExecuteCommandAsync();
  400. var ccp = Query<Grp_CreditCardPayment>(a => a.CId == grp_Visa1.Id && a.CTable == 80).First();
  401. var data = new { ccpId = ccp.Id, sign = 2 };
  402. result = new Result() { Code = 0, Msg = "修改成功!", Data = data };
  403. }
  404. else
  405. {
  406. RollbackTran();
  407. result = new Result() { Code = -1, Msg = "修改失败,请稍后重试!" };
  408. }
  409. }
  410. CommitTran();
  411. return result;
  412. }
  413. }
  414. }