Zxd.Core/code/Zxd.WebApi/AssignUserDomain.cs

75 lines
3.2 KiB
C#

using MySqlConnector;
using System.Diagnostics;
using Zxd.WebApi.Dto;
using Zxd.WebApi.Impl;
namespace Zxd.WebApi
{
public class AssignUserDomain : IAssignUserDomain
{
private readonly IBaseRepository<DncmsbaseDbContext> _cmsrepository;
private readonly IDeptmentDomain _deptmentDomain;
public AssignUserDomain(IBaseRepository<DncmsbaseDbContext> cmsrepository, IDeptmentDomain deptmentDomain)
{
_cmsrepository = cmsrepository;
_deptmentDomain = deptmentDomain;
}
public async Task<List<AssignModel>> GetAssignModels(string resId)
{
List<AssignModel> res = new List<AssignModel>();
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<DbAssignUserModel>(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<List<DbAssignUserEidModel>> GetAssignDetail(string resId)
{
List<DbAssignUserEidModel> res = new List<DbAssignUserEidModel>();
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<DbAssignUserEidModel>(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;
}
}
}