IFinanceRateRepository.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. 
  2. using Dapper;
  3. using System.Threading.Tasks;
  4. using XYY.Core.Standard.Data.Infrastructure;
  5. using XYY.Model.Standard.Finance;
  6. namespace XYY.Data.Standard.Finance
  7. {
  8. public interface IFinance_RateRepository : IBaseRepository<Finance_Rate>
  9. {
  10. new Task Insert(Finance_Rate Finance_Rate);
  11. new Task Update(Finance_Rate finance_Rate);
  12. }
  13. public class Finance_RateRepository : BaseRepository<Finance_Rate>, IFinance_RateRepository
  14. {
  15. public Finance_RateRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
  16. {
  17. }
  18. async Task IFinance_RateRepository.Insert(Finance_Rate Finance_Rate)
  19. {
  20. string sql = $@"SELECT count(0)
  21. FROM Finance_Rate
  22. WHERE Currency='{Finance_Rate.Currency}' and (StartDate BETWEEN '{Finance_Rate.StartDate}' AND '{Finance_Rate.EndDate}' OR
  23. endDate BETWEEN '{Finance_Rate.StartDate}' AND '{Finance_Rate.EndDate}' OR
  24. '{Finance_Rate.StartDate}' BETWEEN startdate AND endDate OR
  25. '{Finance_Rate.EndDate}' BETWEEN startdate AND endDate)";
  26. int qty = _unitOfWork.Connection.QuerySingle<int>(sql, null, _unitOfWork.Transaction);
  27. if (qty > 0)
  28. throw new System.Exception("指定时间范围重叠");
  29. else
  30. await _unitOfWork.InsertAsync(Finance_Rate);
  31. }
  32. async Task IFinance_RateRepository.Update(Finance_Rate finance_Rate)
  33. {
  34. string sql = $@"SELECT count(0)
  35. FROM Finance_Rate
  36. WHERE Currency='{finance_Rate.Currency}' and Id<>{finance_Rate.Id} and(StartDate BETWEEN '{finance_Rate.StartDate}' AND '{finance_Rate.EndDate}' OR
  37. endDate BETWEEN '{finance_Rate.StartDate}' AND '{finance_Rate.EndDate}' OR
  38. '{finance_Rate.StartDate}' BETWEEN startdate AND endDate OR
  39. '{finance_Rate.EndDate}' BETWEEN startdate AND endDate)
  40. ";
  41. int qty = await _unitOfWork.Connection.QuerySingleAsync<int>(sql, null, _unitOfWork.Transaction);
  42. if (qty > 0)
  43. throw new System.Exception("指定时间范围重叠");
  44. else
  45. await _unitOfWork.UpdateAsync(finance_Rate);
  46. }
  47. }
  48. }