using MySqlConnector; using System.Diagnostics; using Zxd.WebApi.Dto; using Zxd.WebApi.Impl; namespace Zxd.WebApi { public class AssignUserDomain : IAssignUserDomain { private readonly IBaseRepository _cmsrepository; private readonly IDeptmentDomain _deptmentDomain; public AssignUserDomain(IBaseRepository cmsrepository, IDeptmentDomain deptmentDomain) { _cmsrepository = cmsrepository; _deptmentDomain = deptmentDomain; } public async Task> GetAssignModels(string resId) { List res = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); var sql = @" SELECT distinct a.deptid FROM AssignUser2eid AS a join ( select a.appid,a.appuserid from usercenter a left join usercenter b on a.customerid = b.customerid WHERE b.resid = @resId ) AS b ON a.appid=b.appid AND a.appuserid=b.appuserid "; MySqlParameter[] param = new MySqlParameter[] { new MySqlParameter(){ DbType=System.Data.DbType.String,Value=resId,ParameterName="resId"}, }; var deptIdsList = await _cmsrepository.ExecuteSqlToListAsync(sql, param); stopWatch.Stop(); Log.Information($"GetAssignModels:{stopWatch.ElapsedMilliseconds}ms 【{deptIdsList.ToJson()}】"); foreach (var dept in deptIdsList) { AssignModel model = new AssignModel { DeptId = dept.deptid }; res.Add(model); } return res; } public async Task> GetAssignDetail(string resId) { List res = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); var sql = @" SELECT distinct a.deptid,a.eid,a.utime FROM AssignUser2eid AS a join ( select a.appid,a.appuserid from usercenter a left join usercenter b on a.customerid = b.customerid WHERE b.resid = @resId ) AS b ON a.appid=b.appid AND a.appuserid=b.appuserid"; MySqlParameter[] param = new MySqlParameter[] { new MySqlParameter(){ DbType=System.Data.DbType.String,Value=resId,ParameterName="resId"}, }; var deptIdsList = await _cmsrepository.ExecuteSqlToListAsync(sql, param); stopWatch.Stop(); Log.Information($"GetAssignDetail:{stopWatch.ElapsedMilliseconds}ms 【{deptIdsList.ToJson()}】"); deptIdsList = deptIdsList.OrderByDescending(n => n.Utime).ToList(); foreach (var dept in deptIdsList) { DbAssignUserEidModel model = new DbAssignUserEidModel { deptid = dept.deptid, eid = dept.eid, }; res.Add(model); } return res; } } }