iFinance_Customer_AccountRepository.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using XYY.Common.Standard;
  7. using XYY.Core.Standard.Data.Infrastructure;
  8. using XYY.Model.Standard.Finance;
  9. using Dapper;
  10. namespace XYY.Data.Standard.Finance
  11. {
  12. public interface IFinance_Customer_AccountRepository : IBaseRepository<Finance_Customer_Account>
  13. {
  14. Task<PageResult<View_Finance_Customer_Account>> GetPager(QueryModel querModel);
  15. Task<IEnumerable<Finance_Customer_AccountLog>> GetLogs(int Id);
  16. Task QuotaReduction(List<Finance_Customer_Account> dbModels);
  17. Task<IEnumerable<Finance_Customer_Account>> GetAccountList(DateTime startTime, DateTime endTime);
  18. }
  19. public class Finance_Customer_AccountRepository : BaseRepository<Finance_Customer_Account>, IFinance_Customer_AccountRepository
  20. {
  21. public Finance_Customer_AccountRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
  22. {
  23. }
  24. public Task<IEnumerable<Finance_Customer_AccountLog>> GetLogs(int Id)
  25. {
  26. return _unitOfWork.QueryAsync<Finance_Customer_AccountLog>(x => x.Id == Id);
  27. }
  28. public Task<PageResult<View_Finance_Customer_Account>> GetPager(QueryModel querModel)
  29. {
  30. return _unitOfWork.GetPagingListAsync<View_Finance_Customer_Account>(querModel,
  31. @"select a.IsActive,b.Id,b.updatetime,a.Id as CustomerId,isnull(a.Abbreviation, a.CompanyName) as CustomerAccountName,a.SalesmanUserId
  32. ,c.NickName as SealsmanUserName,b.Balance,b.Quota,b.RepaymentTermDay,b.OverdueRatio,b.CurrentOverdueDays,b.Currency,a.BillingCycle
  33. from User_Customer(nolock) a left join Finance_Customer_Account(nolock)b on a.Id=b.CustomerId
  34. left join User_Info(nolock) c on c.id=a.SalesmanUserId");
  35. }
  36. public async Task QuotaReduction(List<Finance_Customer_Account> dbModels)
  37. {
  38. var userName = _unitOfWork.CurrentName;
  39. StringBuilder sb = new StringBuilder();
  40. sb.Append($" update Finance_Customer_Account set Quota=ISNULL(BaseQuota,0),QuotaExpirationId=0,QuotaExpirationTime=null where Id in ({string.Join(",", dbModels.Select(x=>x.Id))}) ");
  41. sb.Append($@" insert into Finance_Customer_AccountLog([Id]
  42. ,[Field]
  43. ,[FieldDesc]
  44. ,[OldValue]
  45. ,[NewValue]
  46. ,[CreateUserName]
  47. ,[CreateTime])
  48. select id,'Quota','临时授信到期还原',isnull(Quota,0),ISNULL(BaseQuota,0),'{userName}',GETDATE() from Finance_Customer_Account(nolock)
  49. where Id in ({string.Join(",", dbModels.Select(x => x.Id))}) ");
  50. string sql = sb.ToString();
  51. await _unitOfWork.ExecuteAsync(sql);
  52. }
  53. public async Task<IEnumerable<Finance_Customer_Account>> GetAccountList(DateTime startTime, DateTime endTime)
  54. {
  55. string sql = $@"select * from Finance_Customer_Account where QuotaExpirationTime>='{startTime}' and QuotaExpirationTime<'{endTime}'";
  56. return await _unitOfWork.QueryBySqlAsync<Finance_Customer_Account>(sql);
  57. }
  58. }
  59. }