VisaPriceRepository.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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.Financial;
  8. using OASystem.Domain.Entities.Groups;
  9. using OASystem.Domain.ViewModels.Financial;
  10. using OASystem.Domain.ViewModels.Groups;
  11. using OASystem.Infrastructure.Repositories.System;
  12. using OASystem.Infrastructure.Tools;
  13. using Org.BouncyCastle.Asn1.Cms;
  14. using System;
  15. using System.Collections.Generic;
  16. using System.Linq;
  17. using System.Security.Cryptography;
  18. using System.Text;
  19. using System.Threading.Tasks;
  20. namespace OASystem.Infrastructure.Repositories.Groups
  21. {
  22. public class VisaPriceRepository : BaseRepository<Grp_VisaInfo, VisaPriceDto>
  23. {
  24. private readonly IMapper _mapper;
  25. public VisaPriceRepository(SqlSugarClient sqlSugar,IMapper mapper)
  26. : base(sqlSugar)
  27. {
  28. _mapper=mapper;
  29. }
  30. /// <summary>
  31. /// 根据diid查询签证费用列表
  32. /// </summary>
  33. /// <param name="dto"></param>
  34. /// <returns></returns>
  35. public async Task<Result> PostVisaByDiId(VisaPriceDto dto)
  36. {
  37. Result result = new Result() { Code = -2, Msg = "未知错误" };
  38. if (dto.PortType==0 ||string.IsNullOrWhiteSpace(dto.PortType.ToString()))
  39. {
  40. return result = new Result() { Code = -1, Msg = "请传入PortType参数,请求端口分类 1 Web 2 Android 3 IOS" };
  41. }
  42. try
  43. {
  44. #region SQL条件拼接
  45. string sqlWhere = string.Empty;
  46. if (!string.IsNullOrWhiteSpace(dto.VisaClient))
  47. {
  48. sqlWhere += string.Format(@" And v.VisaClient like '%{0}%'", dto.VisaClient);
  49. }
  50. sqlWhere += string.Format(@"And v.DIId={0} and v.isdel={1}", dto.DiID, 0);
  51. string UserId = "";
  52. List<Grp_GroupsTaskAssignment> gtaUIdList = _sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(a => a.DIId == dto.DiID && a.IsDel == 0 && a.CTId == 80).ToList();
  53. foreach (Grp_GroupsTaskAssignment gta in gtaUIdList)
  54. UserId += gta.UId + ",";
  55. if (!string.IsNullOrWhiteSpace(UserId))
  56. {
  57. UserId = UserId.Substring(0, UserId.Length - 1);
  58. }
  59. sqlWhere += string.Format(@" And v.CreateUserId in ({0})", UserId);
  60. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  61. {
  62. Regex r = new Regex("And");
  63. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  64. }
  65. #endregion
  66. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  67. int endIndex = startIndex + dto.PageSize - 1;
  68. if (dto.PortType==1)
  69. {
  70. string sql = string.Format(@"select *,(select IsAuditGM from Grp_CreditCardPayment where CTable=80 and CId=v.Id) IsAuditGM,
  71. (select Name from Sys_SetData where isdel=0 and v.VisaCurrency=Id) VisaCurrencyStr from
  72. Grp_VisaInfo v {0} order by CreateTime desc",sqlWhere);
  73. List<VisaInfoView> infoViews = _sqlSugar.SqlQueryable<VisaInfoView>(sql).ToList();
  74. return result = new Result() { Code = 0, Msg = "查询成功!", Data = infoViews };
  75. }
  76. else if(dto.PortType==2 || dto.PortType==3)
  77. {
  78. string sql = string.Format(@"Select * From (
  79. Select row_number() over (order by v.Id Desc) as RowNumber,v.*,c.IsAuditGM,s.Name as VisaCurrencyStr
  80. From Grp_VisaInfo v
  81. Inner Join Grp_CreditCardPayment c On v.Id = c.CId and CTable=80
  82. Left Join Sys_SetData s On v.VisaCurrency = s.Id {0}
  83. ) temp Where RowNumber Between {1} and {2}", sqlWhere, startIndex, endIndex);
  84. List<VisaInfoView> infoViews = _sqlSugar.SqlQueryable<VisaInfoView>(sql).ToList();
  85. string CountSql = string.Format(@"Select COUNT(1) as Count From (
  86. Select v.*,c.IsAuditGM,s.Name as VisaCurrencyStr
  87. From Grp_VisaInfo v
  88. Inner Join Grp_CreditCardPayment c On v.Id = c.CId and CTable=80
  89. Left Join Sys_SetData s On v.VisaCurrency = s.Id {0}
  90. ) temp", sqlWhere);
  91. DataCount dataCount = _sqlSugar.SqlQueryable<DataCount>(CountSql).First();
  92. if (dataCount!=null)
  93. {
  94. int count = dataCount.Count;
  95. float totalPage = (float)count / dto.PageSize;//总页数
  96. if (totalPage == 0) totalPage = 1;
  97. else totalPage = (int)Math.Ceiling((double)totalPage);
  98. ListViewBase<VisaInfoView> rst = new ListViewBase<VisaInfoView>();
  99. rst.DataList = infoViews;
  100. rst.DataCount = count;
  101. rst.CurrPageIndex = dto.PageIndex;
  102. rst.CurrPageSize = dto.PageSize;
  103. return result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
  104. }
  105. }
  106. }
  107. catch (Exception)
  108. {
  109. return result = new Result() { Code = -2, Msg = "未知错误" };
  110. throw;
  111. }
  112. return result;
  113. }
  114. /// <summary>
  115. /// 根据签证费用Id查询单条数据及c表数据
  116. /// </summary>
  117. /// <param name="dto"></param>
  118. /// <returns></returns>
  119. public async Task<Result> PostVisaById(PostVisaByIdDto dto)
  120. {
  121. Result result = new Result() { Code = -2, Msg = "未知错误" };
  122. try
  123. {
  124. Grp_VisaInfo _VisaInfo = _sqlSugar.Queryable<Grp_VisaInfo>().First(a => a.Id == dto.Id && a.IsDel==0);
  125. Grp_CreditCardPayment _CreditCardPayment = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a=>a.CId==dto.Id && a.IsDel==0 && a.CTable==80);
  126. var data = new
  127. {
  128. _VisaInfo = _VisaInfo,
  129. _CreditCardPayment = _CreditCardPayment
  130. };
  131. return result = new Result() { Code = 0, Msg = "暂无数据!", Data = data };
  132. }
  133. catch (Exception ex)
  134. {
  135. return result = new Result() { Code = -2, Msg = "未知错误" };
  136. }
  137. }
  138. /// <summary>
  139. /// 签证费用录入操作(Status:1.新增,2.修改)
  140. /// </summary>
  141. /// <param name="dto"></param>
  142. /// <returns></returns>
  143. public async Task<Result> OpVisaPrice(OpVisaPriceDto dto)
  144. {
  145. Result result = new Result() { Code = -2, Msg = "未知错误" };
  146. BeginTran();
  147. try
  148. {
  149. int id = 0;
  150. Grp_VisaInfo grp_Visa1 = _mapper.Map<Grp_VisaInfo>(dto);
  151. Grp_CreditCardPayment c = _mapper.Map<Grp_CreditCardPayment>(dto);
  152. c.PayMoney = dto.VisaPrice;
  153. c.PaymentCurrency = dto.VisaCurrency;
  154. c.Remark = dto.CRemark;
  155. c.PayPercentage = 100;
  156. c.CTable = 80;
  157. c.CId = id;
  158. c.IsAuditGM = 0;
  159. if (c.PayDId == 72)
  160. {
  161. c.IsPay = 1;
  162. }
  163. c.RMBPrice = c.RMBPrice;
  164. c.DayRate = 1;
  165. Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == dto.DiId && a.IsDel == 0 && a.CTable == 80);
  166. List<CurrencyInfo> currencyInfos = new List<CurrencyInfo>();
  167. if (_TeamRate != null)
  168. {
  169. Sys_SetData _SetData = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == c.PaymentCurrency);
  170. if (_SetData!=null)
  171. {
  172. currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  173. CurrencyInfo CurrencyRate = currencyInfos.Where(a => a.CurrencyCode == _SetData.Name).First();
  174. if (CurrencyRate!=null)
  175. {
  176. c.RMBPrice = c.PayMoney * Convert.ToDecimal(CurrencyRate.Rate);
  177. c.DayRate = CurrencyRate.Rate;
  178. }
  179. }
  180. }
  181. if (dto.Status==1)//添加
  182. {
  183. 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);
  184. if (grp_Visa!=null)
  185. {
  186. return result = new Result() { Code = -1, Msg = "该笔费用已存在,请勿重复添加!" };
  187. }
  188. else
  189. {
  190. id = await AddAsyncReturnId(grp_Visa1);
  191. if (id!=0)
  192. {
  193. int cId = await _sqlSugar.Insertable(c).ExecuteReturnIdentityAsync();
  194. if (cId != 0)
  195. {
  196. result = new Result() { Code = 0, Msg = "添加成功!" };
  197. }
  198. else
  199. {
  200. RollbackTran();
  201. result = new Result() { Code = -1, Msg = "添加失败!" };
  202. }
  203. }
  204. else
  205. {
  206. RollbackTran();
  207. result = new Result() { Code = -1, Msg = "添加失败,请稍后重试!" };
  208. }
  209. }
  210. }
  211. else if (dto.Status==2)//修改
  212. {
  213. bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_VisaInfo
  214. {
  215. VisaClient = grp_Visa1.VisaClient,
  216. VisaPrice = grp_Visa1.VisaPrice,
  217. VisaCurrency = grp_Visa1.VisaCurrency,
  218. IsThird = grp_Visa1.IsThird,
  219. PassengerType = grp_Visa1.PassengerType,
  220. VisaNumber = grp_Visa1.VisaNumber,
  221. VisaFreeNumber = grp_Visa1.VisaFreeNumber,
  222. Remark = dto.Remark,
  223. });
  224. if (res)
  225. {
  226. int CTable = await _sqlSugar.Updateable<Grp_CreditCardPayment>().Where(a => a.CId == grp_Visa1.Id && a.CTable==80).SetColumns(a => new Grp_CreditCardPayment
  227. {
  228. PayDId = dto.PayDId,
  229. PayMoney = c.PayMoney,
  230. PaymentCurrency = c.PaymentCurrency,
  231. Payee = c.Payee,
  232. OrbitalPrivateTransfer = c.OrbitalPrivateTransfer,
  233. DayRate = c.DayRate,
  234. RMBPrice = c.RMBPrice,
  235. ConsumptionPatterns = c.ConsumptionPatterns,
  236. ConsumptionDate = c.ConsumptionDate,
  237. CTDId = c.CTDId,
  238. CompanyBankNo = c.CompanyBankNo,
  239. OtherBankName = c.OtherBankName,
  240. OtherSideNo = c.OtherSideNo,
  241. OtherSideName = c.OtherSideName,
  242. BankNo = c.BankNo,
  243. CardholderName = c.CardholderName,
  244. Remark = c.Remark,
  245. }).ExecuteCommandAsync();
  246. result = new Result() { Code = 0, Msg = "修改成功!" };
  247. }
  248. else
  249. {
  250. RollbackTran();
  251. result = new Result() { Code = -1, Msg = "修改失败,请稍后重试!" };
  252. }
  253. }
  254. CommitTran();
  255. }
  256. catch (Exception ex)
  257. {
  258. result = new Result() { Code = -2, Msg = "未知错误" };
  259. }
  260. return result;
  261. }
  262. }
  263. }