IUserCustomerRepository.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using XYY.Core.Standard.Data.Infrastructure;
  7. using XYY.Model.Standard;
  8. using Dapper;
  9. namespace XYY.Data.Standard
  10. {
  11. public interface IUserCustomerRepository : IBaseRepository<User_Customer>
  12. {
  13. Task<IEnumerable<User_Customer>> GetAllFreezeSoonCustomer(int inDays);
  14. Task<int> NoAlertFreezedUntil(string customerIds, int days);
  15. Task<int> DelayFreezed(string customerIds, int days);
  16. Task<List<int>> GetNSMPCustomer();
  17. }
  18. public class UserCustomerRepository : BaseRepository<User_Customer>, IUserCustomerRepository
  19. {
  20. public UserCustomerRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
  21. {
  22. }
  23. public async Task<IEnumerable<User_Customer>> GetAllFreezeSoonCustomer(int inDays)
  24. {
  25. var lastReceiveTime = DateTime.Now.AddDays(inDays).AddDays(-30);
  26. string from = lastReceiveTime.ToString("yyyy-MM-dd 00:00:00");
  27. string to = lastReceiveTime.ToString("yyyy-MM-dd 23:59:59");
  28. string beginTime = DateTime.Now.AddMonths(-6).ToString("yyyy-MM-dd");
  29. string sql = $@"with T as(
  30. select MAX(ReceiveTime) as LastReceiveTime,CustomerId from Order_Order nolock where ReceiveTime>'{beginTime}' and OrderStatus>=2 group by CustomerId
  31. )
  32. select c.* from User_Customer c inner join T on c.Id=t.CustomerId where IsActive=1 and (NextAlertFreezeTime is null or NextAlertFreezeTime<=getdate()) and LastReceiveTime>'{from}' and LastReceiveTime<'{to}'";
  33. var result = await base._unitOfWork.Connection.QueryAsync<User_Customer>(sql, transaction: null, commandTimeout: 900);
  34. return result;
  35. }
  36. public async Task<int> NoAlertFreezedUntil(string customerIds, int days)
  37. {
  38. DateTime nextTime = DateTime.Now.AddDays(days);
  39. var cids = customerIds.SplitToArray<int>(',');
  40. string sql = $"update User_Customer set NextAlertFreezeTime=@NextTime where Id in @ids";
  41. int count = await base._unitOfWork.Connection.ExecuteAsync(sql, param: new { NextTime = nextTime, ids = cids }, transaction: base._unitOfWork.Transaction);
  42. return count;
  43. }
  44. public async Task<int> DelayFreezed(string customerIds, int days)
  45. {
  46. var cids = customerIds.SplitToArray<int>(',');
  47. string sql = $"update User_Customer set UpdateTime= getdate() where Id in @ids";
  48. int count = await _unitOfWork.Connection.ExecuteAsync(sql, new { ids = cids }, transaction: base._unitOfWork.Transaction);
  49. return count;
  50. }
  51. public async Task<List<int>> GetNSMPCustomer()
  52. {
  53. string sql = @"select Id from User_Customer(nolock) where DeductionNode = 3";
  54. return (await _unitOfWork.Connection.QueryAsync<int>(sql)).ToList();
  55. }
  56. }
  57. }