You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
195 lines
6.4 KiB
C#
195 lines
6.4 KiB
C#
|
|
|
|
//----------SysPost开始----------
|
|
|
|
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Admin.Core.IRepository;
|
|
using Admin.Core.Model;
|
|
using Admin.Core.Common;
|
|
using System.Linq.Expressions;
|
|
using Admin.Core.IRepository.ISys;
|
|
using Admin.Core.IService.ISys;
|
|
using Admin.Core.Model.Sys;
|
|
|
|
namespace Admin.Core.Service.Sys
|
|
{
|
|
/// <summary>
|
|
/// 岗位信息表Service
|
|
/// </summary>
|
|
public partial class SysPostService : BaseServices<SysPost>, ISysPostService
|
|
{
|
|
IBaseRepository<SysPost> dal;
|
|
ISysUserPostRepository _sysUserPostRepository;
|
|
public SysPostService(IBaseRepository<SysPost> dal, ISysUserPostRepository sysUserPostRepository)
|
|
{
|
|
this.dal = dal;
|
|
BaseDal = dal;
|
|
_sysUserPostRepository = sysUserPostRepository;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 查询岗位信息集合
|
|
/// </summary>
|
|
/// <param name="pageQuery"> 岗位信息 </param>
|
|
/// <returns> 岗位信息集合 </returns>
|
|
public async Task<PageModel<SysPost>> SelectPostList(PageQuery<SysPost> pageQuery)
|
|
{
|
|
Expression<Func<SysPost, bool>> whereExpression = x => true;
|
|
if (pageQuery.Query.PostName.IsNotEmptyOrNull())
|
|
{
|
|
whereExpression = whereExpression.And(x => x.PostName.Contains(pageQuery.Query.PostName));
|
|
}
|
|
if (pageQuery.Query.PostCode.IsNotEmptyOrNull())
|
|
{
|
|
whereExpression = whereExpression.And(x => x.PostCode.Contains(pageQuery.Query.PostCode));
|
|
}
|
|
if (pageQuery.Query.Status.IsNotEmptyOrNull())
|
|
{
|
|
whereExpression = whereExpression.And(x => x.Status == pageQuery.Query.Status);
|
|
}
|
|
|
|
var data = await dal.QueryPageAsync(whereExpression, pageQuery.Page, pageQuery.PageSize, "PostSort asc");
|
|
|
|
return data;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询所有岗位
|
|
/// </summary>
|
|
/// <returns> 岗位列表 </returns>
|
|
public async Task<List<SysPost>> SelectPostAll()
|
|
{
|
|
return await dal.QueryAsync(x => x.Status == SysConst.ENABLE);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 通过岗位ID查询岗位信息
|
|
/// </summary>
|
|
/// <param name="postId"> 岗位ID </param>
|
|
/// <returns> 角色对象信息 </returns>
|
|
public async Task<SysPost> SelectPostById(int postId)
|
|
{
|
|
return await dal.QueryByIdAsync(postId);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据用户ID获取岗位选择框列表
|
|
/// </summary>
|
|
/// <param name="userId"> 用户ID </param>
|
|
/// <returns> 选中岗位ID列表 </returns>
|
|
public async Task<List<int>> SelectPostListByUserId(int userId)
|
|
{
|
|
var userPosts = await _sysUserPostRepository.QueryAsync(x => x.UserID == userId);
|
|
return userPosts.Select(x => (int)x.PostID).ToList();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 校验岗位名称是否唯一
|
|
/// </summary>
|
|
/// <param name="post"> 岗位信息 </param>
|
|
/// <returns> 结果 </returns>
|
|
public async Task<bool> CheckPostNameUnique(SysPost post)
|
|
{
|
|
Expression<Func<SysPost, bool>> whereExpression = x => true;
|
|
if (post.PostName.IsNotEmptyOrNull())
|
|
{
|
|
whereExpression = whereExpression.And(x => x.PostName == post.PostName);
|
|
}
|
|
if (post.PostID.IsNotEmptyOrNull() && post.PostID > 0)
|
|
{
|
|
whereExpression = whereExpression.And(x => x.PostID != post.PostID);
|
|
}
|
|
var posts = await dal.QueryAsync(whereExpression);
|
|
|
|
return posts.Count == 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 校验岗位编码是否唯一
|
|
/// </summary>
|
|
/// <param name="post"> 岗位信息 </param>
|
|
/// <returns> 结果 </returns>
|
|
public async Task<bool> CheckPostCodeUnique(SysPost post)
|
|
{
|
|
Expression<Func<SysPost, bool>> whereExpression = x => true;
|
|
if (post.PostCode.IsNotEmptyOrNull())
|
|
{
|
|
whereExpression = whereExpression.And(x => x.PostCode == post.PostCode);
|
|
}
|
|
if (post.PostID.IsNotEmptyOrNull() && post.PostID > 0)
|
|
{
|
|
whereExpression = whereExpression.And(x => x.PostID != post.PostID);
|
|
}
|
|
var posts = await dal.QueryAsync(whereExpression);
|
|
|
|
return posts.Count == 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 通过岗位ID查询岗位使用数量
|
|
/// </summary>
|
|
/// <param name="postIds"> 岗位ID </param>
|
|
/// <returns> 结果 </returns>
|
|
public async Task<int> CountUserPostById(List<int> postIds)
|
|
{
|
|
var userPosts = await _sysUserPostRepository.QueryAsync(x => postIds.Contains((int)x.PostID));
|
|
return userPosts.Count;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除岗位信息
|
|
/// </summary>
|
|
/// <param name="postId"> 岗位ID </param>
|
|
/// <returns> 结果 </returns>
|
|
public async Task<bool> DeletePostById(int postId)
|
|
{
|
|
return await dal.DeleteByIdAsync(postId);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 批量删除岗位信息
|
|
/// </summary>
|
|
/// <param name="postIds"> 需要删除的岗位ID </param>
|
|
/// <returns> 结果 </returns>
|
|
/// <exception cref="Exception"> 异常 </exception>
|
|
public async Task<bool> DeletePostByIds(List<int> postIds)
|
|
{
|
|
var posts = await dal.QueryAsync(x => postIds.Contains(x.PostID));
|
|
return await dal.DeletesAsync(posts);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 新增保存岗位信息
|
|
/// </summary>
|
|
/// <param name="post"> 岗位信息 </param>
|
|
/// <returns> 结果 </returns>
|
|
public async Task<int> InsertPost(SysPost post)
|
|
{
|
|
post.CreateTime = DateTime.Now;
|
|
post.UpdateTime = DateTime.Now;
|
|
return await dal.AddAsync(post);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改保存岗位信息
|
|
/// </summary>
|
|
/// <param name="post"> 岗位信息 </param>
|
|
/// <returns> 结果 </returns>
|
|
public async Task<bool> UpdatePost(SysPost post)
|
|
{
|
|
post.UpdateTime = DateTime.Now;
|
|
return await dal.UpdateAsync(post);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
//----------SysPost结束----------
|
|
|