using Attribute;
using Model;
using Service;
namespace Services
{
///
/// 用户岗位
///
[AppService(ServiceType = typeof(ISysUserPostService), ServiceLifetime = LifeTime.Transient)]
public class SysUserPostService : BaseService, ISysUserPostService
{
///
/// 新增用户岗位信息
///
///
public void InsertUserPost(SysUser user)
{
// 新增用户与岗位管理
List list = new();
foreach (var item in user.PostIds)
{
list.Add(new SysUserPost() { PostId = item, UserId = user.userId });
}
InsertRange(list);
}
///
/// 查询用户岗位集合
///
///
///
public List GetUserPostsByUserId(long userId)
{
var list = GetList(f => f.UserId == userId);
return list.Select(x => x.PostId).ToList();
}
///
/// 获取用户岗位
///
///
///
public string GetPostsStrByUserId(long userId)
{
var list = SelectPostsByUserId(userId);
return string.Join(',', list.Select(x => x.postName));
}
public bool Delete(long userId)
{
return Delete(x => x.UserId == userId);
}
///
/// 获取用户岗位
///
///
///
public List SelectPostsByUserId(long userId)
{
return Context.Queryable((p, up) => new JoinQueryInfos(
JoinType.Left, up.PostId == p.postId
)).Where((p, up) => up.UserId == userId)
.Select().ToList();
}
}
}