VisaPriceRepository.cs 19 KB

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