public BaseResponse <GetOfficerListResult> GetOfficerList(GetOfficerListParameter parameter)
 {
     if (Validate(parameter))
     {
         return(officerManager.GetOfficerList(parameter));
     }
     else
     {
         BaseResponse <GetOfficerListResult> response = new BaseResponse <GetOfficerListResult>();
         response.IsSuccessful = false;
         response.Reason       = "JWT_ERR";
         return(response);
     }
 }
        public BaseResponse <GetOfficerListResult> GetOfficerList(GetOfficerListParameter parameter)
        {
            BaseResponse <GetOfficerListResult> response = new BaseResponse <GetOfficerListResult>();
            GetOfficerListResult result = new GetOfficerListResult();

            if (string.IsNullOrEmpty(parameter.Sort))
            {
                parameter.Sort  = "OfficerID";
                parameter.Order = "asc";
            }
            try
            {
                using (iCMSDbContext dbContext = new iCMSDbContext())
                {
                    var officerQuerable = dbContext.Officers.Where(t => !t.IsDeleted && t.IsOnService);

                    //test
                    var temp = officerQuerable.ToList();

                    var currentUser = dbContext.HBUsers.Where(t => !t.IsDeleted && t.UserID == parameter.CurrentUserID).FirstOrDefault();
                    if (currentUser == null)
                    {
                        throw new Exception("数据异常");
                    }
                    if (currentUser.RoleID == 4)//如果是二级管理员,则只返回本单位的干部
                    {
                        officerQuerable = officerQuerable.Where(t => t.OrganizationID == currentUser.OrganizationID);
                    }

                    if (parameter.OrganizationID.HasValue && parameter.OrganizationID.Value > 0)
                    {
                        officerQuerable = officerQuerable.Where(t => t.OrganizationID == parameter.OrganizationID);
                    }
                    if (parameter.LevelID.HasValue && parameter.LevelID.Value > 0)
                    {
                        officerQuerable = officerQuerable.Where(t => t.LevelID == parameter.LevelID.Value);
                    }

                    var officerLinq = from off in officerQuerable
                                      join org in dbContext.Organizations
                                      on off.OrganizationID equals org.OrganID
                                      into group1
                                      from g1 in group1
                                      //join pos in dbContext.OfficerPositionTypes.Where(t => !t.IsDeleted) on off.PositionStr equals pos.PositionID into group2
                                      //from g2 in group2
                                      join lev in dbContext.OfficerLevelTypes.Where(t => !t.IsDeleted) on off.LevelID equals lev.LevelID into group3
                                      from g3 in group3
                                      //where org.OrganFullName.ToUpper().Contains(parameter.Keyword.ToUpper()) || org.OrganCode.ToUpper().Contains(parameter.Keyword.ToUpper())
                                      select new OfficerDetailInfo
                    {
                        OfficerID        = off.OfficerID,
                        Name             = off.Name,
                        Gender           = off.Gender,
                        Birthday         = off.Birthday,
                        OrganizationName = g1.OrganFullName,
                        PositionID       = 0,            //g2.PositionID,
                        PositionName     = off.PositionStr,
                        LevelID          = g3.LevelID,
                        LevelName        = g3.LevelName,
                        OnOfficeDate     = off.OnOfficeDate,
                        OrganizationID   = off.OrganizationID,
                        CurrentScore     = off.CurrentScore,
                        IdentifyNumber   = off.IdentifyCardNumber
                    };


                    var temp2 = officerLinq.ToList();

                    if (!string.IsNullOrEmpty(parameter.Keyword))
                    {
                        officerLinq = officerLinq.Where(t => t.Name.Contains(parameter.Keyword) || t.IdentifyNumber.Contains(parameter.Keyword) || t.OrganizationName.Contains(parameter.Keyword));
                    }
                    ListSortDirection       sortOrder = parameter.Order.ToLower().Equals("asc") ? ListSortDirection.Ascending : ListSortDirection.Descending;
                    PropertySortCondition[] sortList  = new PropertySortCondition[]
                    {
                        new PropertySortCondition(parameter.Sort, sortOrder),
                        new PropertySortCondition("OfficerID", sortOrder),
                    };

                    officerLinq = officerLinq.OrderBy(sortList);
                    int count = officerLinq.Count();
                    if (parameter.Page > -1)
                    {
                        officerLinq = officerLinq
                                      .Skip((parameter.Page - 1) * parameter.PageSize)
                                      .Take(parameter.PageSize);
                    }

                    result.OfficerInfoList.AddRange(officerLinq.ToList());
                    result.Total    = count;
                    response.Result = result;

                    #region 操作日志
                    new LogManager().AddOperationLog(parameter.CurrentUserID, "获取积分申请详细信息", parameter.RequestIP);
                    #endregion

                    return(response);
                }
            }
            catch (Exception e)
            {
                response.IsSuccessful = false;
                response.Reason       = "获取单位列表发生异常";

                return(response);
            }
        }