shgx_tz_mom/ZR.Service/System/SysUserPostService.cs

71 lines
2.1 KiB
C#
Raw Normal View History

2021-08-23 16:57:25 +08:00
using Infrastructure.Attribute;
2022-09-21 21:43:05 +08:00
using SqlSugar;
2021-08-23 16:57:25 +08:00
using System.Linq;
using ZR.Model.System;
2021-09-16 19:35:17 +08:00
using ZR.Service.System.IService;
2021-08-23 16:57:25 +08:00
namespace ZR.Service.System
{
/// <summary>
/// 用户岗位
/// </summary>
[AppService(ServiceType = typeof(ISysUserPostService), ServiceLifetime = LifeTime.Transient)]
2022-09-21 21:43:05 +08:00
public class SysUserPostService : BaseService<SysUserPost>, ISysUserPostService
2021-08-23 16:57:25 +08:00
{
/// <summary>
/// 新增用户岗位信息
/// </summary>
/// <param name="user"></param>
public void InsertUserPost(SysUser user)
{
// 新增用户与岗位管理
2023-08-15 09:37:31 +08:00
List<SysUserPost> list = new();
2021-08-23 16:57:25 +08:00
foreach (var item in user.PostIds)
{
list.Add(new SysUserPost() { PostId = item, UserId = user.UserId });
}
2023-08-15 09:37:31 +08:00
InsertRange(list);
2021-08-23 16:57:25 +08:00
}
/// <summary>
/// 查询用户岗位集合
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
public List<long> GetUserPostsByUserId(long userId)
{
2022-09-21 21:43:05 +08:00
var list = GetList(f => f.UserId == userId);
2021-08-23 16:57:25 +08:00
return list.Select(x => x.PostId).ToList();
}
/// <summary>
/// 获取用户岗位
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
public string GetPostsStrByUserId(long userId)
{
2022-09-21 21:43:05 +08:00
var list = SelectPostsByUserId(userId);
2021-08-23 16:57:25 +08:00
return string.Join(',', list.Select(x => x.PostName));
}
2021-09-27 08:06:09 +08:00
2022-03-19 08:04:08 +08:00
public bool Delete(long userId)
2021-09-27 08:06:09 +08:00
{
2022-09-21 21:43:05 +08:00
return Delete(x => x.UserId == userId);
}
/// <summary>
/// 获取用户岗位
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
public List<SysPost> SelectPostsByUserId(long userId)
{
return Context.Queryable<SysPost, SysUserPost>((p, up) => new JoinQueryInfos(
JoinType.Left, up.PostId == p.PostId
)).Where((p, up) => up.UserId == userId)
.Select<SysPost>().ToList();
2021-09-27 08:06:09 +08:00
}
2021-08-23 16:57:25 +08:00
}
}