/**
  * 跳转到审核页面
  *
  * @param id
  * @param map
  * @return
  */
 @RequestMapping(value = "/toReview/{id}", method = RequestMethod.GET)
 public String preReview(@PathVariable Long id, Map<String, Object> map) {
   TransRecordReviewForm transRecordForm = new TransRecordReviewForm();
   transRecordForm.setResult(TransStatusEnum.S.getValue());
   transRecordForm.setTransRecordId(id);
   map.put("transRecordForm", transRecordForm);
   Long transRecordId = transRecordForm.getTransRecordId();
   if (null != transRecordId) {
     List<BizAttach> sumList = new ArrayList<BizAttach>();
     List<BizAttach> list =
         attachService.findByRefIdAndAttachTypeOrderByGmtCreateDesc(
             transRecordId, "biz_trans_record1");
     List<BizAttach> list2 =
         attachService.findByRefIdAndAttachTypeOrderByGmtCreateDesc(
             transRecordId, "biz_trans_record2");
     if (!CollectionUtils.isEmpty(list2)) {
       sumList.addAll(list2);
     }
     if (!CollectionUtils.isEmpty(list)) {
       sumList.addAll(list);
     }
     map.put("attachs", sumList);
   }
   return REVIEW;
 }
  /**
   * 批量删除文档
   *
   * @param entity
   * @return
   * @throws Exception
   */
  public static String deleteDocument(List<String> ids, Class clazz) throws Exception {
    List<String> luceneFields = ClassUtils.getLuceneFields(clazz);
    if (CollectionUtils.isEmpty(luceneFields)) {
      return "error";
    }
    if (CollectionUtils.isEmpty(ids)) {
      return "error";
    }
    String pkName = ClassUtils.getEntityInfoByClass(clazz).getPkName();
    // 索引写入配置
    IndexWriterConfig indexWriterConfig = new IndexWriterConfig(analyzer);
    // 获取索引目录文件
    Directory directory = getDirectory(clazz);
    if (directory == null) {
      return null;
    }
    IndexWriter indexWriter = new IndexWriter(directory, indexWriterConfig);
    for (String t : ids) {
      /*
       * Term term = new Term(pkName, t);
       * indexWriter.deleteDocuments(term);
       */
      // 获取读取的索引

      // QueryParser parser = new QueryParser(field, analyzer);
      QueryParser parser = new MultiFieldQueryParser(new String[] {pkName}, analyzer);
      // 需要查询的关键字
      Query query = parser.parse(t.toString());
      indexWriter.deleteDocuments(query);
    }
    indexWriter.commit();
    indexWriter.close(); // 记得关闭,否则删除不会被同步到索引文件中
    directory.close(); // 关闭目录
    return null;
  }
  /**
   * 获取当前登录用户的所有权限集合
   *
   * @param info
   * @return
   */
  public Collection<Permission> getPermissions(AuthorizationInfo info) {
    Set<Permission> permissions = new HashSet<Permission>();

    if (info != null) {
      Collection<Permission> perms = info.getObjectPermissions();
      if (!CollectionUtils.isEmpty(perms)) {
        permissions.addAll(perms);
      }
      perms = resolvePermissions(info.getStringPermissions());
      if (!CollectionUtils.isEmpty(perms)) {
        permissions.addAll(perms);
      }

      perms = resolveRolePermissions(info.getRoles());
      if (!CollectionUtils.isEmpty(perms)) {
        permissions.addAll(perms);
      }
    }

    if (permissions.isEmpty()) {
      return Collections.emptySet();
    } else {
      return Collections.unmodifiableSet(permissions);
    }
  }
 private Collection<Permission> resolveRolePermissions(Collection<String> roleNames) {
   Collection<Permission> perms = Collections.emptySet();
   RolePermissionResolver resolver = getRolePermissionResolver();
   if (resolver != null && !CollectionUtils.isEmpty(roleNames)) {
     perms = new LinkedHashSet<Permission>(roleNames.size());
     for (String roleName : roleNames) {
       Collection<Permission> resolved = resolver.resolvePermissionsInRole(roleName);
       if (!CollectionUtils.isEmpty(resolved)) {
         perms.addAll(resolved);
       }
     }
   }
   return perms;
 }
 /**
  * Serializes this object to the specified output stream for JDK Serialization.
  *
  * @param out output stream used for Object serialization.
  * @throws IOException if any of this object's fields cannot be written to the stream.
  * @since 1.0
  */
 private void writeObject(ObjectOutputStream out) throws IOException {
   out.defaultWriteObject();
   short alteredFieldsBitMask = getAlteredFieldsBitMask();
   out.writeShort(alteredFieldsBitMask);
   if (id != null) {
     out.writeObject(id);
   }
   if (startTimestamp != null) {
     out.writeObject(startTimestamp);
   }
   if (stopTimestamp != null) {
     out.writeObject(stopTimestamp);
   }
   if (lastAccessTime != null) {
     out.writeObject(lastAccessTime);
   }
   if (timeout != 0l) {
     out.writeLong(timeout);
   }
   if (expired) {
     out.writeBoolean(expired);
   }
   if (host != null) {
     out.writeUTF(host);
   }
   if (!CollectionUtils.isEmpty(attributes)) {
     out.writeObject(attributes);
   }
 }
 /**
  * 根据实体类查询结果
  *
  * @param clazz
  * @param page
  * @param searchkeyword
  * @return
  * @throws Exception
  */
 public static List searchDocument(Class clazz, Page page, String searchkeyword) throws Exception {
   List<String> luceneFields = ClassUtils.getLuceneFields(clazz);
   if (CollectionUtils.isEmpty(luceneFields)) {
     return null;
   }
   String[] fields = (String[]) luceneFields.toArray(new String[luceneFields.size()]);
   return searchDocument(clazz, page, fields, searchkeyword);
 }
Exemple #7
0
  /**
   * 删除组织机构
   *
   * @param id
   * @throws Exception
   */
  @Transactional(readOnly = false)
  public void deleteOrganization(String id) throws Exception {
    Customer customer = get(id);
    if (!CollectionUtils.isEmpty(mediaDao.findByOrganizationId(id))) {
      throw new Exception("此机构下属有媒体,暂时不能删除!");
    }

    userDao.delete(customer.getUsers());
    this.remove(customer);
  }
  /**
   * 根据实体类批量保存到索引,使用 LuceneSearch和LuceneField
   *
   * @param entity
   * @return
   * @throws Exception
   */
  public static <T> String saveDocument(List<T> list) throws Exception {
    if (CollectionUtils.isEmpty(list)) {
      return "error";
    }
    for (T t : list) {
      saveDocument(t);
    }

    return null;
  }
 @Override
 public CheckResult checkParams() {
   if (location.isEmpty()) {
     return new CheckResult(false, "Location Empty");
   }
   if (CollectionUtils.isEmpty(urlFilters)) {
     return new CheckResult(false, "Filter Empty");
   }
   return new CheckResult(true, "OK");
 }
 @RequestMapping(
     value = "/showDetailPer/{date}",
     method = {RequestMethod.GET, RequestMethod.POST})
 public String showDailyPer(Page page, @PathVariable String date, Map<String, Object> map) {
   List<BizFinanceTransDetail> list = financeTransDetailService.findByGmtCreate(page, date);
   List<Map<String, String>> tempList = new ArrayList<Map<String, String>>();
   Map<Long, BizMember> cacheMap = new HashMap<Long, BizMember>();
   if (!CollectionUtils.isEmpty(list)) {
     for (BizFinanceTransDetail detail : list) {
       Map<String, String> tempMap = new HashMap<String, String>();
       tempMap.put("id", detail.getId() + "");
       tempMap.put("date", DateUtil.date2String(detail.getGmtCreate(), BizConstant.DATE_FORMAT));
       tempMap.put("time", DateUtil.date2String(detail.getGmtCreate(), BizConstant.TIME_FORMAT));
       TransUserEnum enums = TransUserEnum.getEnum(detail.getTransUse());
       if (enums == (TransUserEnum.MEMBER_ATTENT)
           || enums == TransUserEnum.MEMBER_ATTENT_PROLONG) {
         String name = "大师";
         BizMember tempMem =
             cacheMap.get(detail.getTransUseId()) == null
                 ? memberService.get(detail.getTransUseId())
                 : cacheMap.get(detail.getTransUseId());
         if (null != tempMem) {
           name = "大师(" + tempMem.getName() + ")";
         }
         tempMap.put(
             "summary",
             StringUtils.replace(
                 TransUserEnum.getEnum(detail.getTransUse()).getName(), "大师", name));
       } else {
         tempMap.put("summary", TransUserEnum.getEnum(detail.getTransUse()).getName());
       }
       long out = 0;
       long in = 0;
       tempMap.put("left", detail.getSysLeft() + "");
       tempMap.put("type", TransTypeEnum.getEnum(detail.getTransType()).getName());
       switch (TransTypeEnum.getEnum(detail.getTransType())) {
         case IN:
           in = detail.getValue();
           break;
         case OUT:
           out = detail.getValue();
           break;
         default:
           break;
       }
       tempMap.put("out", out + "");
       tempMap.put("in", in + "");
       tempList.add(tempMap);
     }
     map.put("page", page);
     map.put("data", tempList);
   }
   return SHOW_DETAIL_PER;
 }
 private Collection<Permission> resolvePermissions(Collection<String> stringPerms) {
   Collection<Permission> perms = Collections.emptySet();
   PermissionResolver resolver = getPermissionResolver();
   if (resolver != null && !CollectionUtils.isEmpty(stringPerms)) {
     perms = new LinkedHashSet<Permission>(stringPerms.size());
     for (String strPermission : stringPerms) {
       Permission permission = getPermissionResolver().resolvePermission(strPermission);
       perms.add(permission);
     }
   }
   return perms;
 }
 /**
  * Returns a bit mask used during serialization indicating which fields have been serialized.
  * Fields that have been altered (not null and/or not retaining the class defaults) will be
  * serialized and have 1 in their respective index, fields that are null and/or retain class
  * default values have 0.
  *
  * @return a bit mask used during serialization indicating which fields have been serialized.
  * @since 1.0
  */
 private short getAlteredFieldsBitMask() {
   int bitMask = 0;
   bitMask = id != null ? bitMask | ID_BIT_MASK : bitMask;
   bitMask = startTimestamp != null ? bitMask | START_TIMESTAMP_BIT_MASK : bitMask;
   bitMask = stopTimestamp != null ? bitMask | STOP_TIMESTAMP_BIT_MASK : bitMask;
   bitMask = lastAccessTime != null ? bitMask | LAST_ACCESS_TIME_BIT_MASK : bitMask;
   bitMask = timeout != 0l ? bitMask | TIMEOUT_BIT_MASK : bitMask;
   bitMask = expired ? bitMask | EXPIRED_BIT_MASK : bitMask;
   bitMask = host != null ? bitMask | HOST_BIT_MASK : bitMask;
   bitMask = !CollectionUtils.isEmpty(attributes) ? bitMask | ATTRIBUTES_BIT_MASK : bitMask;
   return (short) bitMask;
 }
  /**
   * 根据实体类保存到索引,使用 LuceneSearch和LuceneField
   *
   * @param entity
   * @return
   * @throws Exception
   */
  public static synchronized String saveDocument(Object entity) throws Exception {
    // 获取索引的字段,为null则不进行保存
    List<String> luceneFields = ClassUtils.getLuceneFields(entity.getClass());
    if (CollectionUtils.isEmpty(luceneFields)) {
      return "error";
    }

    // 索引写入配置
    IndexWriterConfig indexWriterConfig = new IndexWriterConfig(analyzer);
    // 获取索引目录文件
    Directory directory = getDirectory(entity.getClass());
    if (directory == null) {
      return null;
    }
    IndexWriter indexWriter = new IndexWriter(directory, indexWriterConfig);
    Document doc = new Document();
    for (String fieldName : luceneFields) {

      PropertyDescriptor pd = new PropertyDescriptor(fieldName, entity.getClass());
      Method getMethod = pd.getReadMethod();
      /**
       * String typeStr = getMethod.getGenericReturnType().getTypeName(); Class type =
       * ClassUtils.getReturnType(fieldName, entity.getClass());
       */
      Object _obj = ClassUtils.getPropertieValue(fieldName, entity);

      if (_obj == null) {
        _obj = "";
      }
      String _value = _obj.toString();
      Field _field = null;
      /**
       * if ("java.lang.Integer".equals(typeStr)) { _field = new IntField(fieldName,
       * Integer.valueOf(_value), Store.YES); } if ("java.lang.String".equals(typeStr)) { _field =
       * new StringField(fieldName, _value, Store.YES); }
       */
      if (ClassUtils.getEntityInfoByEntity(entity).getPkName().equals(fieldName)) {
        _field =
            new StringField(
                ClassUtils.getEntityInfoByEntity(entity).getPkName(), _value, Store.YES);
      } else {
        _field = new Field(fieldName, _value, TextField.TYPE_STORED);
      }

      doc.add(_field);
    }
    indexWriter.addDocument(doc);
    indexWriter.commit();
    indexWriter.close();
    directory.close();
    return null;
  }
  /**
   * 向workbook中写入多数据源的数据(多个sheet的数据来源不同)//====后期增加
   *
   * @param workbook
   * @param mutilSheetMap key为sheet名称sheetTitle, value为表体数据tableDataList
   * @return
   */
  @Override
  public Workbook writeWorkbookMutilDatasoure(
      Workbook workbook, Map<String, List<List<String>>> mutilSheetMap, int headerNum) {

    if (workbook == null) workbook = new XSSFWorkbook();
    if (!CollectionUtils.isEmpty(mutilSheetMap)) {
      for (String sheetTitle : mutilSheetMap.keySet()) {
        List<List<String>> tableDataList = mutilSheetMap.get(sheetTitle);
        writeWorkbook(workbook, sheetTitle, tableDataList, 0); // 默认无表头			
      }
    }
    return workbook;
  }
 @RequestMapping(
     value = "/showLast",
     method = {RequestMethod.GET, RequestMethod.POST})
 public String showLast(Page page, String keywords, Map<String, Object> map) {
   List<BizTransRecordVO> records = transRecordService.findTransRecordToReview(page);
   List<Map<String, String>> recordList = new ArrayList<Map<String, String>>();
   if (!CollectionUtils.isEmpty(records)) {
     Map<Long, BizMember> cacheMap = new HashMap<Long, BizMember>();
     for (BizTransRecordVO vo : records) {
       Map<String, String> tempMap = new HashMap<String, String>();
       String name = "该用户已经被删除!";
       String memberNo = "无";
       String isVal = "";
       if (!StringUtils.isBlank(vo.getMemberId())) {
         Long memberId = Long.parseLong(vo.getMemberId());
         BizMember member =
             cacheMap.get(memberId) == null ? memberService.get(memberId) : cacheMap.get(memberId);
         name = member.getName();
         memberNo = member.getMemberNo();
         BizInvestion investion =
             investionService.findByMemberIdAndInvestDirection(
                 Long.parseLong(vo.getMemberId()), vo.getInvestType());
         if (null == investion) {
           isVal = "无";
         } else {
           isVal = StringUtils.equals(investion.getIsValidated(), "1") ? "赛" : "无";
         }
       }
       tempMap.put("id", vo.getId() + "");
       tempMap.put(
           "investTypeStr",
           InvestDirectionEnum.getInvestDirectionEnum(vo.getInvestType()).getName());
       tempMap.put("name", name);
       tempMap.put("memberNo", memberNo);
       tempMap.put("isVal", isVal);
       tempMap.put("origionValue", getRealString(vo.getOrigionValue()) + "");
       tempMap.put("currValue", getRealString(vo.getCurrValue()) + "");
       tempMap.put("lastDayValue", getRealString(vo.getLastDayValue()) + "");
       tempMap.put("fee", getRealString(vo.getFee()) + "");
       tempMap.put("gainsAndLosses", getRealString(vo.getGainsAndLosses()) + "");
       tempMap.put("currIncome", getRealString(vo.getCurrIncome()) + "");
       tempMap.put("currOutcome", getRealString(vo.getCurrOutcome()) + "");
       recordList.add(tempMap);
     }
   }
   map.put("page", page);
   map.put("records", recordList);
   map.put("keywords", keywords);
   return SHOW_LAST;
 }
 @RequestMapping(
     value = "/findAll",
     method = {RequestMethod.GET, RequestMethod.POST})
 public @ResponseBody String findAll(
     Page page, Map<String, Object> map, @RequestParam String type) {
   BizMember member = (BizMember) HttpReceiver.getHttpSession().getAttribute("member");
   if (null == member) {
     AjaxReturnInfo.returnErr("请您先首页登录!");
   }
   List<BizTransRecord> list = transRecordService.findAllByType(page, type);
   if (CollectionUtils.isEmpty(list)) {
     return PageUtils.toJsonString(page, new ArrayList<Map<String, String>>());
   }
   return PageUtils.toJsonString(page, list);
 }
 /** 授权 */
 protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
   String username = (String) principals.getPrimaryPrincipal();
   CmsUser user = cmsUserMng.findByUsername(username);
   CmsSite site = CmsThreadVariable.getSite();
   SimpleAuthorizationInfo auth = new SimpleAuthorizationInfo();
   if (user != null) {
     Set<String> viewPermissionSet = new HashSet<String>();
     Set<String> perms = user.getPerms(site.getId(), viewPermissionSet);
     if (!CollectionUtils.isEmpty(perms)) {
       // 权限加入AuthorizationInfo认证对象
       auth.setStringPermissions(perms);
     }
   }
   return auth;
 }
  /**
   * 批量修改文档
   *
   * @param entity
   * @return
   * @throws Exception
   */
  public static <T> String updateDocument(List<T> list) throws Exception {

    if (CollectionUtils.isEmpty(list)) {
      return null;
    }
    List<String> ids = new ArrayList<String>();
    Class clazz = list.get(0).getClass();
    for (T t : list) {
      String id = ClassUtils.getPKValue(t).toString();
      ids.add(id);
    }
    deleteDocument(ids, clazz);
    saveDocument(list);
    return null;
  }
Exemple #19
0
  /**
   * Authenticates a user and retrieves its information.
   *
   * @param token the authentication token
   * @throws AuthenticationException if there is an error during authentication.
   */
  @Override
  @SuppressWarnings("unchecked")
  protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token)
      throws AuthenticationException {
    CasToken casToken = (CasToken) token;
    if (token == null) {
      return null;
    }

    String ticket = (String) casToken.getCredentials();
    if (!StringUtils.hasText(ticket)) {
      return null;
    }

    TicketValidator ticketValidator = ensureTicketValidator();

    try {
      // contact CAS server to validate service ticket
      Assertion casAssertion = ticketValidator.validate(ticket, getCasService());
      // get principal, user id and attributes
      AttributePrincipal casPrincipal = casAssertion.getPrincipal();
      String userId = casPrincipal.getName();
      log.debug(
          "Validate ticket : {} in CAS server : {} to retrieve user : {}",
          new Object[] {ticket, getCasServerUrlPrefix(), userId});

      Map<String, Object> attributes = casPrincipal.getAttributes();
      // refresh authentication token (user id + remember me)
      casToken.setUserId(userId);
      String rememberMeAttributeName = getRememberMeAttributeName();
      String rememberMeStringValue = (String) attributes.get(rememberMeAttributeName);
      boolean isRemembered =
          rememberMeStringValue != null && Boolean.parseBoolean(rememberMeStringValue);
      if (isRemembered) {
        casToken.setRememberMe(true);
      }
      // create simple authentication info
      List<Object> principals = CollectionUtils.asList(userId, attributes);
      PrincipalCollection principalCollection =
          new SimplePrincipalCollection(principals, getName());
      return new SimpleAuthenticationInfo(principalCollection, ticket);
    } catch (TicketValidationException e) {
      throw new CasAuthenticationException("Unable to validate ticket [" + ticket + "]", e);
    }
  }
 @SuppressWarnings("unchecked")
 @Override
 public Set<K> keys() {
   try {
     Set<byte[]> keys = cache.keys(this.keyPrefix + "*");
     if (CollectionUtils.isEmpty(keys)) {
       return Collections.emptySet();
     } else {
       Set<K> newKeys = new HashSet<K>();
       for (byte[] key : keys) {
         newKeys.add((K) key);
       }
       return newKeys;
     }
   } catch (Throwable t) {
     throw new CacheException(t);
   }
 }
  /**
   * @param request
   * @param response
   * @param mappedValue
   * @return
   * @throws IOException 如果发生任何错误就抛出异常
   */
  @Override
  public boolean isAccessAllowed(
      ServletRequest request, ServletResponse response, Object mappedValue) throws IOException {
    Subject subject = getSubject(request, response);

    String[] rolesArray = (String[]) mappedValue;

    if (rolesArray == null || rolesArray.length == 0) {
      // no roles specified, so nothing to check - allow access.
      return true;
    }

    Set<String> roles = CollectionUtils.asSet(rolesArray);
    for (String role : roles) {
      if (subject.hasRole(role)) {
        return true;
      }
    }
    return false;
  }
 @Override
 public Collection<V> values() {
   try {
     Set<byte[]> keys = cache.keys(this.keyPrefix + "*");
     if (!CollectionUtils.isEmpty(keys)) {
       List<V> values = new ArrayList<V>(keys.size());
       for (byte[] key : keys) {
         @SuppressWarnings("unchecked")
         V value = get((K) key);
         if (value != null) {
           values.add(value);
         }
       }
       return Collections.unmodifiableList(values);
     } else {
       return Collections.emptyList();
     }
   } catch (Throwable t) {
     throw new CacheException(t);
   }
 }
  /**
   * 删除文档
   *
   * @param entity
   * @return
   * @throws Exception
   */
  public static synchronized String deleteDocument(Object id, Class clazz) throws Exception {
    List<String> luceneFields = ClassUtils.getLuceneFields(clazz);
    if (CollectionUtils.isEmpty(luceneFields)) {
      return "error";
    }

    String pkName = ClassUtils.getEntityInfoByClass(clazz).getPkName();
    // 索引写入配置
    IndexWriterConfig indexWriterConfig = new IndexWriterConfig(analyzer);
    // 获取索引目录文件
    Directory directory = getDirectory(clazz);
    if (directory == null) {
      return null;
    }
    IndexWriter indexWriter = new IndexWriter(directory, indexWriterConfig);
    // 需要查询的关键字
    // Query query = parser.parse(id.toString());
    String _id = ClassUtils.getEntityInfoByClass(clazz).getPkName();

    indexWriter.deleteDocuments(new Term(_id, id.toString()));
    // indexWriter.deleteDocuments(query);
    indexWriter.commit();
    indexWriter.close(); // 记得关闭,否则删除不会被同步到索引文件中
    directory.close(); // 关闭目录

    return null;
    /*
     * String pkName = ClassUtils.getEntityInfoByClass(clazz).getPkName();
     * // 索引写入配置 IndexWriterConfig indexWriterConfig = new
     * IndexWriterConfig(analyzer); // 获取索引目录文件 Directory directory =
     * getDirectory(clazz); if (directory == null) { return null; }
     * IndexWriter indexWriter = new IndexWriter(directory,
     * indexWriterConfig); Term term = new Term(pkName, id.toString());
     * indexWriter.deleteDocuments(term); indexWriter.commit();
     * indexWriter.close(); // 记得关闭,否则删除不会被同步到索引文件中 directory.close(); //
     * 关闭目录
     *
     * return null;
     */
  }