public UserDetails loadUserByUsername(String loginName)
      throws UsernameNotFoundException, DataAccessException {
    log.debug("*** Received parameter: loginName:" + loginName);
    if (loginName.contains(
        "%")) { // 表示是swing“办公助手”中访问v1/tickets过来的,有%表示用户登录名或分支编码有中文,已进行编码URLEncoder.encode(username,
      // "utf-8"),需要解码
      try {
        loginName = URLDecoder.decode(loginName, "utf-8");
      } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
      }
    }
    // loginName的格式为loginName~~companyCode
    User user = userManager.getUserByLoginNameAndBranchCode(loginName);

    //		try {
    //			Map<String, String> licence = License.getLicense();
    //			String dateString = licence.get("end_time");
    //			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    //			Date settingDate = df.parse(dateString);
    //			Date date = userManager.getUserTs(user.getCompanyId());
    //			if(date != null && settingDate.before(date)){
    //				log.error("licence invalidation");
    //				throw new UsernameNotFoundException("licence invalidation");
    //			}
    //		} catch (Exception e) {
    //			log.error("licence invalidation");
    //			throw new UsernameNotFoundException("licence invalidation");
    //		}

    if (isTenant) {
      isCompanyValidDate(user);
    }
    Company company = companyManager.getCompany(user.getCompanyId());
    Department subCompany = null;
    if (user.getSubCompanyId() != null) {
      subCompany = departmentManager.getDepartmentById(user.getSubCompanyId());
    }
    List<GrantedAuthority> authsList = getAuthorityByUser(user);

    log.debug("*** loadUserByUsername 结束");
    return createUserdetail(user, company, authsList, subCompany, loginName);
  }
  /*
   * 创建spring security使用的用户
   * userinfo:loginName~~companyCode
   */
  private com.norteksoft.acs.entity.security.User createUserdetail(
      User user,
      Company company,
      List<GrantedAuthority> authsList,
      Department subCompany,
      String userinfo) {
    com.norteksoft.acs.entity.security.User userdetail =
        new com.norteksoft.acs.entity.security.User(
            user.getId(),
            userinfo,
            user.getPassword(),
            user.getEmail(),
            user.getEnabled(),
            !user.getAccountExpired(),
            true,
            !user.getAccountLocked(),
            authsList.toArray(new GrantedAuthority[authsList.size()]),
            company.getId(),
            company.getCode(),
            company.getName(),
            user.getSecretGrade());
    userdetail.setLoginName(user.getLoginName());
    userdetail.setHonorificTitle(user.getHonorificName());
    userdetail.setTrueName(user.getName());
    userdetail.setRoleCodes(user.getRoleCodes());
    String theme = indexManager.getThemeByUser(user.getId(), company.getId());
    if (StringUtils.isEmpty(theme)) theme = getDefaultTheme();
    userdetail.setTheme(theme);

    String language =
        userCurrentLanguageManager.getUserLanguageByUserId(user.getId(), company.getId());
    if (StringUtils.isEmpty(language)) language = getDefaultLanguage();
    userdetail.setCurrentLanguage(language);

    userdetail.setSubCompanyId(user.getSubCompanyId());
    userdetail.setDepartmentId(user.getMainDepartmentId());
    if (subCompany != null) {
      userdetail.setSubCompanyCode(subCompany.getCode());
      userdetail.setSubCompanyName(subCompany.getName());
      userdetail.setSubCompanyShortTitle(subCompany.getShortTitle());
    }
    return userdetail;
  }