You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
2.1 KiB

using BBWYB.Common.Models;
using BBWYB.Server.Model.Db;
namespace BBWYB.Server.Business
{
public class UserBusiness : IDenpendency
{
private FreeSqlMultiDBManager fsqlManager;
public UserBusiness(FreeSqlMultiDBManager fsqlManager)
{
this.fsqlManager = fsqlManager;
}
/// <summary>
/// 获取指定用户的议价组信息
/// </summary>
/// <param name="userId"></param>
/// <param name="throwExWhenUserNotBelongYJ">当用户不属于议价组团队是否抛出错误</param>
/// <returns></returns>
/// <exception cref="BusinessException"></exception>
public (User user, Userdepartment mainTeam, bool isBargainTeam, Userdepartment? bargainTeam) GetisBargainTeamByUserId(string userId, bool throwExWhenUserNotBelongYJ = false)
{
var user = fsqlManager.MDSfsql.Select<User>(userId).ToOne();
if (user == null)
throw new BusinessException("用户不存在");
if (string.IsNullOrEmpty(user.DepartmentId))
throw new BusinessException("该用户没有归属部门");
var queryDeparmentIdList = new List<string>() { user.DepartmentId };
if (!string.IsNullOrEmpty(user.SonDepartmentIds))
queryDeparmentIdList.AddRange(user.SonDepartmentIds.Split(",", StringSplitOptions.RemoveEmptyEntries));
var departmentList = fsqlManager.MDSfsql.Select<Userdepartment>(queryDeparmentIdList).ToList();
if (departmentList.Count() == 0)
throw new BusinessException("未获取部门");
var mainTeam = departmentList.FirstOrDefault(d => d.Id == user.DepartmentId);
if (mainTeam == null)
throw new BusinessException("主部门不存在");
var bargainTeam = departmentList.FirstOrDefault(d => d.ParentDepartmentId == "1760971468360912896");
if (throwExWhenUserNotBelongYJ && bargainTeam == null)
throw new BusinessException("子部门不属于议价组");
return (user, mainTeam, bargainTeam != null, bargainTeam);
}
}
}