VisaPriceRepository.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. else
  60. {
  61. UserId = "0";
  62. }
  63. sqlWhere += string.Format(@" And v.CreateUserId in ({0})", UserId);
  64. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  65. {
  66. Regex r = new Regex("And");
  67. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  68. }
  69. #endregion
  70. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  71. int endIndex = startIndex + dto.PageSize - 1;
  72. if (dto.PortType==1)
  73. {
  74. string sql = string.Format(@"select *,(select IsAuditGM from Grp_CreditCardPayment where CTable=80 and CId=v.Id) IsAuditGM,
  75. (select Name from Sys_SetData where isdel=0 and v.VisaCurrency=Id) VisaCurrencyStr from
  76. Grp_VisaInfo v {0} order by CreateTime desc",sqlWhere);
  77. List<VisaInfoView> infoViews = _sqlSugar.SqlQueryable<VisaInfoView>(sql).ToList();
  78. return result = new Result() { Code = 0, Msg = "查询成功!", Data = infoViews };
  79. }
  80. else if(dto.PortType==2 || dto.PortType==3)
  81. {
  82. string sql = string.Format(@"Select * From (
  83. Select row_number() over (order by v.Id Desc) as RowNumber,v.*,c.IsAuditGM,s.Name as VisaCurrencyStr
  84. From Grp_VisaInfo v
  85. left Join Grp_CreditCardPayment c On v.Id = c.CId and CTable=80
  86. Left Join Sys_SetData s On v.VisaCurrency = s.Id {0}
  87. ) temp Where RowNumber Between {1} and {2}", sqlWhere, startIndex, endIndex);
  88. List<VisaInfoView> infoViews = _sqlSugar.SqlQueryable<VisaInfoView>(sql).ToList();
  89. string CountSql = string.Format(@"Select COUNT(1) as Count From (
  90. Select v.*,c.IsAuditGM,s.Name as VisaCurrencyStr
  91. From Grp_VisaInfo v
  92. left Join Grp_CreditCardPayment c On v.Id = c.CId and CTable=80
  93. Left Join Sys_SetData s On v.VisaCurrency = s.Id {0}
  94. ) temp", sqlWhere);
  95. DataCount dataCount = _sqlSugar.SqlQueryable<DataCount>(CountSql).First();
  96. if (dataCount!=null)
  97. {
  98. int count = dataCount.Count;
  99. float totalPage = (float)count / dto.PageSize;//总页数
  100. if (totalPage == 0) totalPage = 1;
  101. else totalPage = (int)Math.Ceiling((double)totalPage);
  102. ListViewBase<VisaInfoView> rst = new ListViewBase<VisaInfoView>();
  103. rst.DataList = infoViews;
  104. rst.DataCount = count;
  105. rst.CurrPageIndex = dto.PageIndex;
  106. rst.CurrPageSize = dto.PageSize;
  107. return result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
  108. }
  109. }
  110. }
  111. catch (Exception)
  112. {
  113. return result = new Result() { Code = -2, Msg = "未知错误" };
  114. throw;
  115. }
  116. return result;
  117. }
  118. /// <summary>
  119. /// 根据签证费用Id查询单条数据及c表数据
  120. /// </summary>
  121. /// <param name="dto"></param>
  122. /// <returns></returns>
  123. public async Task<Result> PostVisaById(PostVisaByIdDto dto)
  124. {
  125. Result result = new Result() { Code = -2, Msg = "未知错误" };
  126. try
  127. {
  128. Grp_VisaInfo _VisaInfo = _sqlSugar.Queryable<Grp_VisaInfo>().First(a => a.Id == dto.Id && a.IsDel==0);
  129. Grp_CreditCardPayment _CreditCardPayment = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a=>a.CId==dto.Id && a.IsDel==0 && a.CTable==80);
  130. var data = new
  131. {
  132. _VisaInfo = _VisaInfo,
  133. _CreditCardPayment = _CreditCardPayment
  134. };
  135. return result = new Result() { Code = 0, Msg = "暂无数据!", Data = data };
  136. }
  137. catch (Exception ex)
  138. {
  139. return result = new Result() { Code = -2, Msg = "未知错误" };
  140. }
  141. }
  142. /// <summary>
  143. /// 签证费用录入操作(Status:1.新增,2.修改)
  144. /// </summary>
  145. /// <param name="dto"></param>
  146. /// <returns></returns>
  147. public async Task<Result> OpVisaPrice(OpVisaPriceDto dto)
  148. {
  149. Result result = new Result() { Code = -2, Msg = "未知错误" };
  150. BeginTran();
  151. try
  152. {
  153. int id = 0;
  154. Grp_VisaInfo grp_Visa1 = _mapper.Map<Grp_VisaInfo>(dto);
  155. Grp_CreditCardPayment c = _mapper.Map<Grp_CreditCardPayment>(dto);
  156. c.PayMoney = dto.VisaPrice;
  157. c.PaymentCurrency = dto.VisaCurrency;
  158. c.Remark = dto.CRemark;
  159. c.PayPercentage = 100;
  160. c.CTable = 80;
  161. c.CId = dto.Id;
  162. c.IsAuditGM = 0;
  163. if (c.PayDId == 72)
  164. {
  165. c.IsPay = 1;
  166. }
  167. c.RMBPrice = c.RMBPrice;
  168. c.DayRate = 1;
  169. Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == dto.DiId && a.IsDel == 0 && a.CTable == 80);
  170. List<CurrencyInfo> currencyInfos = new List<CurrencyInfo>();
  171. if (_TeamRate != null)
  172. {
  173. Sys_SetData _SetData = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == c.PaymentCurrency);
  174. if (_SetData!=null)
  175. {
  176. currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  177. CurrencyInfo CurrencyRate = currencyInfos.Where(a => a.CurrencyCode == _SetData.Name).First();
  178. if (CurrencyRate!=null)
  179. {
  180. c.RMBPrice = c.PayMoney * Convert.ToDecimal(CurrencyRate.Rate);
  181. c.DayRate = CurrencyRate.Rate;
  182. }
  183. }
  184. }
  185. if (dto.Status==1)//添加
  186. {
  187. 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);
  188. if (grp_Visa!=null)
  189. {
  190. return result = new Result() { Code = -1, Msg = "该笔费用已存在,请勿重复添加!" };
  191. }
  192. else
  193. {
  194. id = await AddAsyncReturnId(grp_Visa1);
  195. if (id!=0)
  196. {
  197. c.CId = id;
  198. int cId = await _sqlSugar.Insertable(c).ExecuteReturnIdentityAsync();
  199. if (cId != 0)
  200. {
  201. result = new Result() { Code = 0, Msg = "添加成功!" };
  202. }
  203. else
  204. {
  205. RollbackTran();
  206. result = new Result() { Code = -1, Msg = "添加失败!" };
  207. }
  208. }
  209. else
  210. {
  211. RollbackTran();
  212. result = new Result() { Code = -1, Msg = "添加失败,请稍后重试!" };
  213. }
  214. }
  215. }
  216. else if (dto.Status==2)//修改
  217. {
  218. bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_VisaInfo
  219. {
  220. VisaClient = grp_Visa1.VisaClient,
  221. VisaPrice = grp_Visa1.VisaPrice,
  222. VisaCurrency = grp_Visa1.VisaCurrency,
  223. IsThird = grp_Visa1.IsThird,
  224. PassengerType = grp_Visa1.PassengerType,
  225. VisaNumber = grp_Visa1.VisaNumber,
  226. VisaFreeNumber = grp_Visa1.VisaFreeNumber,
  227. Remark = dto.Remark,
  228. });
  229. if (res)
  230. {
  231. int CTable = await _sqlSugar.Updateable<Grp_CreditCardPayment>().Where(a => a.CId == grp_Visa1.Id && a.CTable==80).SetColumns(a => new Grp_CreditCardPayment
  232. {
  233. PayDId = dto.PayDId,
  234. PayMoney = c.PayMoney,
  235. PaymentCurrency = c.PaymentCurrency,
  236. Payee = c.Payee,
  237. OrbitalPrivateTransfer = c.OrbitalPrivateTransfer,
  238. DayRate = c.DayRate,
  239. RMBPrice = c.RMBPrice,
  240. ConsumptionPatterns = c.ConsumptionPatterns,
  241. ConsumptionDate = c.ConsumptionDate,
  242. CTDId = c.CTDId,
  243. CompanyBankNo = c.CompanyBankNo,
  244. OtherBankName = c.OtherBankName,
  245. OtherSideNo = c.OtherSideNo,
  246. OtherSideName = c.OtherSideName,
  247. BankNo = c.BankNo,
  248. CardholderName = c.CardholderName,
  249. Remark = c.Remark,
  250. }).ExecuteCommandAsync();
  251. result = new Result() { Code = 0, Msg = "修改成功!" };
  252. }
  253. else
  254. {
  255. RollbackTran();
  256. result = new Result() { Code = -1, Msg = "修改失败,请稍后重试!" };
  257. }
  258. }
  259. CommitTran();
  260. }
  261. catch (Exception ex)
  262. {
  263. result = new Result() { Code = -2, Msg = "未知错误" };
  264. }
  265. return result;
  266. }
  267. }
  268. }