using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Hg.Core.Domain { internal class SysUserProtocolDomain : ISysUserProtocolDomain { private readonly IBaseRepository _zxdRepositrory; public SysUserProtocolDomain(IBaseRepository zxdRepositrory) { _zxdRepositrory = zxdRepositrory; } public async Task CheckResAge(string? resid) { return await _zxdRepositrory.GetRepository().Query() .AnyAsync(x => x.Resid == resid && x.Protocoltype == 6 && x.Status == 9); } public async Task SyncUserProtocolName() { var now = DateTime.Now.AddDays(-7); var data = await _zxdRepositrory.GetRepository().Query() .Where(x => x.Protocoltype == 6 && x.Ctime > now).ToListAsync(); if (!data.Any()) return; var resids = data.Select(x => x.Resid?.Trim()).Distinct().Where(x => !string.IsNullOrEmpty(x)).ToList(); var orders = await _zxdRepositrory.GetRepository().Query() .Where(x => new string[] { "180", "190", "200", "220" }.Contains(x.ORDERSTATUS) && resids.Contains(x.RESID)).Select(x => new { x.RESID, x.CNAME, x.CTIME }).ToListAsync(); if (!orders.Any()) return; var newData = new List(); foreach (var item in data) { var username = orders.Where(x => x.RESID == item.Resid?.Trim()).OrderByDescending(x => x.CTIME).Select(x => x.CNAME).FirstOrDefault(); if (username != item.Username) item.Username = username; newData.Add(item); } await _zxdRepositrory.GetRepository().BatchUpdateAsync(newData, x => new { x.Username }); } } }