using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using XYY.Common.Standard; using XYY.Core.Standard.Data.Infrastructure; using XYY.Model.Standard.Finance; using Dapper; namespace XYY.Data.Standard.Finance { public interface IFinance_Customer_AccountRepository : IBaseRepository { Task> GetPager(QueryModel querModel); Task> GetLogs(int Id); Task QuotaReduction(List dbModels); Task> GetAccountList(DateTime startTime, DateTime endTime); } public class Finance_Customer_AccountRepository : BaseRepository, IFinance_Customer_AccountRepository { public Finance_Customer_AccountRepository(IUnitOfWork unitOfWork) : base(unitOfWork) { } public Task> GetLogs(int Id) { return _unitOfWork.QueryAsync(x => x.Id == Id); } public Task> GetPager(QueryModel querModel) { return _unitOfWork.GetPagingListAsync(querModel, @"select a.IsActive,b.Id,b.updatetime,a.Id as CustomerId,isnull(a.Abbreviation, a.CompanyName) as CustomerAccountName,a.SalesmanUserId ,c.NickName as SealsmanUserName,b.Balance,b.Quota,b.RepaymentTermDay,b.OverdueRatio,b.CurrentOverdueDays,b.Currency,a.BillingCycle from User_Customer(nolock) a left join Finance_Customer_Account(nolock)b on a.Id=b.CustomerId left join User_Info(nolock) c on c.id=a.SalesmanUserId"); } public async Task QuotaReduction(List dbModels) { var userName = _unitOfWork.CurrentName; StringBuilder sb = new StringBuilder(); 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))}) "); sb.Append($@" insert into Finance_Customer_AccountLog([Id] ,[Field] ,[FieldDesc] ,[OldValue] ,[NewValue] ,[CreateUserName] ,[CreateTime]) select id,'Quota','临时授信到期还原',isnull(Quota,0),ISNULL(BaseQuota,0),'{userName}',GETDATE() from Finance_Customer_Account(nolock) where Id in ({string.Join(",", dbModels.Select(x => x.Id))}) "); string sql = sb.ToString(); await _unitOfWork.ExecuteAsync(sql); } public async Task> GetAccountList(DateTime startTime, DateTime endTime) { string sql = $@"select * from Finance_Customer_Account where QuotaExpirationTime>='{startTime}' and QuotaExpirationTime<'{endTime}'"; return await _unitOfWork.QueryBySqlAsync(sql); } } }