VisaPriceRepository.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  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
  84. From Grp_VisaInfo as v With(Nolock) left Join Grp_CreditCardPayment as c With(Nolock) On v.Id = c.CId
  85. And c.CTable = 80 And c.IsDel = 0 ", sqlWhere);
  86. List<VisaInfoView> infoViews = _sqlSugar.SqlQueryable<VisaInfoView>(sql).ToList();
  87. var parseIntValue = 0;
  88. var CrmIds = (from item in infoViews
  89. where item.VisaClient.Contains(",") || int.TryParse(item.VisaClient, out parseIntValue)
  90. select item.VisaClient).ToList();
  91. var strCrmIds = string.Join(',', CrmIds);
  92. List<Crm_DeleClient> clietArr = new List<Crm_DeleClient>();
  93. if (!string.IsNullOrWhiteSpace(strCrmIds))
  94. {
  95. sql = string.Format("SELECT * FROM Crm_DeleClient cdc where id in ({0}) and IsDel = 0", strCrmIds);
  96. clietArr = _sqlSugar.SqlQueryable<Crm_DeleClient>(sql).ToList();
  97. }
  98. Dictionary<int, string> dic_Currency = new Dictionary<int, string>();
  99. foreach (VisaInfoView view in infoViews)
  100. {
  101. if (dic_Currency.ContainsKey(view.VisaCurrency))
  102. {
  103. view.VisaCurrencyStr = dic_Currency[view.VisaCurrency];
  104. }
  105. else
  106. {
  107. List<Sys_SetData> temp_sdList = Query<Sys_SetData>(s => s.Id == view.VisaCurrency).ToList();
  108. if (temp_sdList.Count > 0)
  109. {
  110. view.VisaCurrencyStr = temp_sdList[0].Name;
  111. dic_Currency.Add(view.VisaCurrency, temp_sdList[0].Name);
  112. }
  113. else
  114. {
  115. view.VisaCurrencyStr = "未知";
  116. dic_Currency.Add(view.VisaCurrency, "未知");
  117. }
  118. }
  119. if (view.IsAuditGM == 0) view.IsAuditGMStr = "未审核";
  120. else if (view.IsAuditGM == 1) view.IsAuditGMStr = "已通过";
  121. else if (view.IsAuditGM == 2) view.IsAuditGMStr = "未通过";
  122. else if (view.IsAuditGM == 3) view.IsAuditGMStr = "自动审核";
  123. {
  124. if (view.VisaClient.Contains(","))
  125. {
  126. var splitArr = view.VisaClient.Split(',');
  127. var name = string.Empty;
  128. var i = 0;
  129. while (i < splitArr.Count())
  130. {
  131. if (int.TryParse(splitArr[i], out parseIntValue))
  132. {
  133. var clientObject = clietArr.Find(x => x.Id == parseIntValue);
  134. name += (clientObject?.LastName + clientObject?.FirstName);
  135. }
  136. i++;
  137. if (i < splitArr.Count())
  138. {
  139. name += " ";
  140. }
  141. }
  142. if (!string.IsNullOrWhiteSpace(name))
  143. {
  144. view.VisaClient = name.TrimEnd();
  145. }
  146. continue;
  147. }
  148. }
  149. if (int.TryParse(view.VisaClient, out parseIntValue))
  150. {
  151. var name = string.Empty;
  152. var clientObject = clietArr.Find(x => x.Id == parseIntValue);
  153. name += (clientObject?.LastName + clientObject?.FirstName);
  154. if (!string.IsNullOrWhiteSpace(name))
  155. {
  156. view.VisaClient = name;
  157. }
  158. continue;
  159. }
  160. }
  161. return result = new Result() { Code = 0, Msg = "查询成功!", Data = infoViews };
  162. }
  163. else if (dto.PortType == 2 || dto.PortType == 3)
  164. {
  165. string sql = string.Format(@"Select * From (
  166. Select row_number() over (order by v.Id Desc) as RowNumber,v.*,c.IsAuditGM,s.Name as VisaCurrencyStr
  167. From Grp_VisaInfo v
  168. left Join Grp_CreditCardPayment c On v.Id = c.CId and CTable=80 and c.isdel=0
  169. Left Join Sys_SetData s On v.VisaCurrency = s.Id {0}
  170. ) temp Where RowNumber Between {1} and {2}", sqlWhere, startIndex, endIndex);
  171. List<VisaInfoView> infoViews = _sqlSugar.SqlQueryable<VisaInfoView>(sql).ToList();
  172. var parseIntValue = 0;
  173. var CrmIds = (from item in infoViews
  174. where item.VisaClient.Contains(",") || int.TryParse(item.VisaClient, out parseIntValue)
  175. select item.VisaClient).ToList();
  176. var strCrmIds = string.Join(',', CrmIds);
  177. List<Crm_DeleClient> clietArr = new List<Crm_DeleClient>();
  178. if (!string.IsNullOrWhiteSpace(strCrmIds))
  179. {
  180. sql = string.Format("SELECT * FROM Crm_DeleClient cdc where id in ({0}) and IsDel = 0", strCrmIds);
  181. clietArr = _sqlSugar.SqlQueryable<Crm_DeleClient>(sql).ToList();
  182. }
  183. foreach (VisaInfoView view in infoViews)
  184. {
  185. if (view.IsAuditGM == 0) view.IsAuditGMStr = "未审核";
  186. else if (view.IsAuditGM == 1) view.IsAuditGMStr = "已通过";
  187. else if (view.IsAuditGM == 2) view.IsAuditGMStr = "未通过";
  188. else if (view.IsAuditGM == 3) view.IsAuditGMStr = "自动审核";
  189. {
  190. if (view.VisaClient.Contains(","))
  191. {
  192. var splitArr = view.VisaClient.Split(',');
  193. var name = string.Empty;
  194. var i = 0;
  195. while (i < splitArr.Count())
  196. {
  197. if (int.TryParse(splitArr[i], out parseIntValue))
  198. {
  199. var clientObject = clietArr.Find(x => x.Id == parseIntValue);
  200. name += (clientObject?.LastName + clientObject?.FirstName);
  201. }
  202. i++;
  203. if (i < splitArr.Count())
  204. {
  205. name += "[*TuT*]";
  206. }
  207. }
  208. if (!string.IsNullOrWhiteSpace(name))
  209. {
  210. view.VisaClient = name.TrimEnd();
  211. }
  212. continue;
  213. }
  214. }
  215. if (int.TryParse(view.VisaClient, out parseIntValue))
  216. {
  217. var name = string.Empty;
  218. var clientObject = clietArr.Find(x => x.Id == parseIntValue);
  219. name += (clientObject?.LastName + clientObject?.FirstName);
  220. if (!string.IsNullOrWhiteSpace(name))
  221. {
  222. view.VisaClient = name;
  223. }
  224. continue;
  225. }
  226. }
  227. string CountSql = string.Format(@"Select COUNT(1) as Count From (
  228. Select v.*,c.IsAuditGM,s.Name as VisaCurrencyStr
  229. From Grp_VisaInfo v
  230. left Join Grp_CreditCardPayment c On v.Id = c.CId and CTable=80 and c.isdel=0
  231. Left Join Sys_SetData s On v.VisaCurrency = s.Id {0}
  232. ) temp", sqlWhere);
  233. DataCount dataCount = _sqlSugar.SqlQueryable<DataCount>(CountSql).First();
  234. if (dataCount != null)
  235. {
  236. int count = dataCount.Count;
  237. float totalPage = (float)count / dto.PageSize;//总页数
  238. if (totalPage == 0) totalPage = 1;
  239. else totalPage = (int)Math.Ceiling((double)totalPage);
  240. ListViewBase<VisaInfoView> rst = new ListViewBase<VisaInfoView>();
  241. rst.DataList = infoViews;
  242. rst.DataCount = count;
  243. rst.CurrPageIndex = dto.PageIndex;
  244. rst.CurrPageSize = dto.PageSize;
  245. return result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
  246. }
  247. }
  248. }
  249. catch (Exception ex)
  250. {
  251. return result = new Result() { Code = -2, Msg = "未知错误" };
  252. throw;
  253. }
  254. return result;
  255. }
  256. /// <summary>
  257. /// 根据签证费用Id查询单条数据及c表数据
  258. /// </summary>
  259. /// <param name="dto"></param>
  260. /// <returns></returns>
  261. public async Task<Result> PostVisaById(PostVisaByIdDto dto)
  262. {
  263. Result result = new Result() { Code = -2, Msg = "未知错误" };
  264. try
  265. {
  266. Grp_VisaInfo _VisaInfo = _sqlSugar.Queryable<Grp_VisaInfo>().First(a => a.Id == dto.Id && a.IsDel == 0);
  267. Grp_CreditCardPayment _CreditCardPayment = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable == 80);
  268. var data = new
  269. {
  270. VisaInfo = _VisaInfo,
  271. CreditCardPayment = _CreditCardPayment
  272. };
  273. return result = new Result() { Code = 0, Msg = "暂无数据!", Data = data };
  274. }
  275. catch (Exception ex)
  276. {
  277. return result = new Result() { Code = -2, Msg = "未知错误" };
  278. }
  279. }
  280. /// <summary>
  281. /// 签证费用录入操作(Status:1.新增,2.修改)
  282. /// </summary>
  283. /// <param name="dto"></param>
  284. /// <returns></returns>
  285. public async Task<Result> OpVisaPrice(OpVisaPriceDto dto)
  286. {
  287. Result result = new Result() { Code = -2, Msg = "未知错误" };
  288. BeginTran();
  289. try
  290. {
  291. int id = 0;
  292. Grp_VisaInfo grp_Visa1 = _mapper.Map<Grp_VisaInfo>(dto);
  293. Grp_CreditCardPayment c = _mapper.Map<Grp_CreditCardPayment>(dto);
  294. c.PayMoney = dto.VisaPrice;
  295. c.PaymentCurrency = dto.VisaCurrency;
  296. c.Remark = dto.CRemark;
  297. c.PayPercentage = 100;
  298. c.CTable = 80;
  299. c.CId = dto.Id;
  300. c.IsAuditGM = 0;
  301. if (c.PayDId == 72)
  302. {
  303. c.IsPay = 1;
  304. }
  305. c.RMBPrice = c.PayMoney;
  306. c.DayRate = 1;
  307. Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == dto.DiId && a.IsDel == 0 && a.CTable == 80);
  308. List<CurrencyInfo> currencyInfos = new List<CurrencyInfo>();
  309. if (_TeamRate != null)
  310. {
  311. Sys_SetData _SetData = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == c.PaymentCurrency);
  312. if (_SetData != null)
  313. {
  314. currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  315. CurrencyInfo CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData.Name);
  316. if (CurrencyRate != null)
  317. {
  318. c.RMBPrice = c.PayMoney * Convert.ToDecimal(CurrencyRate.Rate);
  319. c.DayRate = CurrencyRate.Rate;
  320. }
  321. }
  322. }
  323. if (dto.Status == 1)//添加
  324. {
  325. 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);
  326. if (grp_Visa != null)
  327. {
  328. return result = new Result() { Code = -1, Msg = "该笔费用已存在,请勿重复添加!" };
  329. }
  330. else
  331. {
  332. id = await AddAsyncReturnId(grp_Visa1);
  333. if (id != 0)
  334. {
  335. c.CId = id;
  336. int cId = await _sqlSugar.Insertable(c).ExecuteReturnIdentityAsync();
  337. if (cId != 0)
  338. {
  339. result = new Result() { Code = 0, Msg = "添加成功!" };
  340. }
  341. else
  342. {
  343. RollbackTran();
  344. result = new Result() { Code = -1, Msg = "添加失败!" };
  345. }
  346. }
  347. else
  348. {
  349. RollbackTran();
  350. result = new Result() { Code = -1, Msg = "添加失败,请稍后重试!" };
  351. }
  352. }
  353. }
  354. else if (dto.Status == 2)//修改
  355. {
  356. bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_VisaInfo
  357. {
  358. VisaClient = grp_Visa1.VisaClient,
  359. VisaPrice = grp_Visa1.VisaPrice,
  360. VisaCurrency = grp_Visa1.VisaCurrency,
  361. IsThird = grp_Visa1.IsThird,
  362. PassengerType = grp_Visa1.PassengerType,
  363. VisaNumber = grp_Visa1.VisaNumber,
  364. VisaFreeNumber = grp_Visa1.VisaFreeNumber,
  365. Remark = dto.Remark,
  366. VisaDescription = dto.VisaDescription
  367. });
  368. if (res)
  369. {
  370. int CTable = await _sqlSugar.Updateable<Grp_CreditCardPayment>().Where(a => a.CId == grp_Visa1.Id && a.CTable == 80).SetColumns(a => new Grp_CreditCardPayment
  371. {
  372. PayDId = dto.PayDId,
  373. PayMoney = c.PayMoney,
  374. PaymentCurrency = c.PaymentCurrency,
  375. Payee = c.Payee,
  376. OrbitalPrivateTransfer = c.OrbitalPrivateTransfer,
  377. DayRate = c.DayRate,
  378. RMBPrice = c.RMBPrice,
  379. ConsumptionPatterns = c.ConsumptionPatterns,
  380. ConsumptionDate = c.ConsumptionDate,
  381. CTDId = c.CTDId,
  382. CompanyBankNo = c.CompanyBankNo,
  383. OtherBankName = c.OtherBankName,
  384. OtherSideNo = c.OtherSideNo,
  385. OtherSideName = c.OtherSideName,
  386. BankNo = c.BankNo,
  387. CardholderName = c.CardholderName,
  388. Remark = c.Remark,
  389. }).ExecuteCommandAsync();
  390. result = new Result() { Code = 0, Msg = "修改成功!" };
  391. }
  392. else
  393. {
  394. RollbackTran();
  395. result = new Result() { Code = -1, Msg = "修改失败,请稍后重试!" };
  396. }
  397. }
  398. CommitTran();
  399. }
  400. catch (Exception ex)
  401. {
  402. result = new Result() { Code = -2, Msg = ex.Message };
  403. }
  404. return result;
  405. }
  406. }
  407. }