using Microsoft.Extensions.DependencyInjection; using MySqlConnector; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Zxd.Core.Domain.Dto.Dncmsbase; using Zxd.Domain.Config; namespace Zxd.Core.Domain { internal class StatisticsDomain : IStatisticsDomain { private readonly IConfiguration _configuration; private readonly ICacheDomain _cacheDomain; private readonly IBaseRepository _dncmsbaseRepository; private readonly IBaseRepository _zxdRepository; private readonly IServiceProvider _serviceProvider; public StatisticsDomain(IConfiguration configuration, ICacheDomain cacheDomain, IBaseRepository dncmsbaseRepository, IBaseRepository zxdRepository, IServiceProvider serviceProvider) { _configuration = configuration; _cacheDomain = cacheDomain; _dncmsbaseRepository = dncmsbaseRepository; _zxdRepository = zxdRepository; _serviceProvider = serviceProvider; } public async Task GetMonthAttentionData(string year, string month) { var date = $"{year}-{month}"; var result = new MonthAttentionDto { Date = date, }; var starDate = DateTime.Parse(date).ToString("yyyy-MM-dd"); var endDate = DateTime.Parse(date).AddMonths(1).ToString("yyyy-MM-dd"); var param = new MySqlParameter[] { new MySqlParameter(){ DbType=System.Data.DbType.String,Value=starDate,ParameterName="starDate"}, new MySqlParameter(){ DbType=System.Data.DbType.String,Value=endDate,ParameterName="endDate"} }; using (var scope = _serviceProvider.CreateAsyncScope()) { var dncmsbaseRepository = scope.ServiceProvider.GetRequiredService>(); var deptSql = @"SELECT dt.title, t2.毛量 as only, t3.去重总数 as total, t1.去重新增量 as increment FROM (SELECT ta.deptid, ta.total as 去重新增量 FROM (SELECT a.deptid, COUNT(DISTINCT a.unionid) AS total FROM dncms.weworkexternalusersubscribe AS a WHERE a.regdate >= @starDate AND a.regdate < @endDate AND a.add_way<>202 AND a.repeattype <= 150 GROUP BY a.deptid) AS ta) t1 LEFT JOIN (SELECT ta.deptid, ta.total as 毛量 FROM (SELECT a.deptid, COUNT(*) AS total FROM dncms.weworkexternalusersubscribe AS a WHERE a.regdate >= @starDate AND a.regdate < @endDate AND a.add_way<>202 GROUP BY a.deptid) AS ta) t2 ON t1.deptid = t2.deptid LEFT JOIN (SELECT ta.deptid, ta.total as 去重总数 FROM (SELECT a.deptid, COUNT(DISTINCT a.unionid) AS total FROM dncms.weworkexternalusersubscribe AS a WHERE a.regdate >= @starDate AND a.regdate < @endDate AND a.add_way<>202 GROUP BY a.deptid) AS ta) t3 ON t1.deptid = t3.deptid LEFT JOIN dncmsbase.deptment dt on t1.deptid = dt.id ORDER BY dt.title;"; result.DeptData = await dncmsbaseRepository.ExecuteSqlToListAsync(deptSql, param); } using (var scope = _serviceProvider.CreateAsyncScope()) { var dncmsbaseRepository = scope.ServiceProvider.GetRequiredService>(); var conterSql = @" SELECT '懂牛软件业务中心' as title, COUNT(*) AS total, COUNT(DISTINCT a.unionid) AS increment FROM dncms.weworkexternalusersubscribe AS a WHERE a.regdate >= @starDate AND a.regdate < @endDate AND a.add_way<>202 AND a.repeattype<=100 AND deptid in (16,29,23,2,5,41) union SELECT '六合智投业务中心' as title, COUNT(*) AS total, COUNT(DISTINCT a.unionid) AS increment FROM dncms.weworkexternalusersubscribe AS a WHERE a.regdate >= @starDate AND a.regdate < @endDate AND a.add_way<>202 AND a.repeattype<=100 AND deptid in (27,33,32,40,43) union SELECT '东方股票业务中心' as title, COUNT(*) AS total, COUNT(DISTINCT a.unionid) AS increment FROM dncms.weworkexternalusersubscribe AS a WHERE a.regdate >= @starDate AND a.regdate < @endDate AND a.add_way<>202 AND a.repeattype<=100 AND deptid in (38,37,19,15,8) union SELECT '好股来投教中心' as title, COUNT(*) AS total, COUNT(DISTINCT a.unionid) AS increment FROM dncms.weworkexternalusersubscribe AS a WHERE a.regdate >= @starDate AND a.regdate < @endDate AND a.add_way<>202 AND a.repeattype<=100 AND deptid in (35,36,30,31);"; result.ConterData = await dncmsbaseRepository.ExecuteSqlToListAsync(conterSql, param); } return result; } } }