VisaPriceRepository.cs 20 KB

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