private void initData() {

    typeData.clear();
    typeData.addAll(ToolType.allToolTypes());

    List<ToolsTray> bandejaList =
        dao.query(ToolsTray.class, Cnd.where("toolType", "=", C.TOOL_TYPE_TRAY_FOLDER));

    superData.clear();
    ToolsTray bandeja1 = new ToolsTray();
    bandeja1.setId(C.ROOT_PARENT_ID);
    bandeja1.setTrayName("--无父目录--");
    superData.add(bandeja1);
    superData.addAll(bandejaList);

    searchData.clear();
    ToolsTray bandeja = new ToolsTray();
    bandeja.setTrayName("--全部--");
    searchData.add(bandeja);
    searchData.add(bandeja1);
    searchData.addAll(bandejaList);

    tableData.clear();
    tableData.addAll(dao.query(ToolsTray.class, null));
  }
  public void search(ActionEvent event) {

    ToolsTray bandeja = (ToolsTray) searchCombo.getSelectionModel().getSelectedItem();
    List<ToolsTray> bandejaList;
    if (null == bandeja || null == bandeja.getId()) {
      bandejaList = dao.query(ToolsTray.class, null);
    } else {
      bandejaList = dao.query(ToolsTray.class, Cnd.where("parentId", "=", bandeja.getId()));
    }
    tableData.clear();
    tableData.addAll(bandejaList);
  }
  @Override
  public void init(NutConfig config) {
    Ioc ioc = config.getIoc();
    Dao dao = ioc.get(Dao.class);

    // 若必要的数据表不存在,则初始化数据库
    if (!dao.exists(User.class)) {
      dao.create(User.class, true);
      dao.create(Role.class, true);
      dao.create(Permission.class, true);
      FileSqlManager fm = new FileSqlManager("init_system_h2.sql");
      List<Sql> sqlList = fm.createCombo(fm.keys());
      dao.execute(sqlList.toArray(new Sql[sqlList.size()]));
      // 初始化用户密码(全部都是123)及salt
      List<User> userList = dao.query(User.class, null);
      for (User user : userList) {
        RandomNumberGenerator rng = new SecureRandomNumberGenerator();
        String salt = rng.nextBytes().toBase64();
        String hashedPasswordBase64 = new Sha256Hash("123", salt, 1024).toBase64();
        user.setSalt(salt);
        user.setPassword(hashedPasswordBase64);
        dao.update(user);
      }
    }

    // 设置 Shiro 的 securityManager
    SecurityManager securityManager = ioc.get(SecurityManager.class);
    SecurityUtils.setSecurityManager(securityManager);
  }
Beispiel #4
0
  @At
  @Ok("json")
  public JDataGrid list_grid(
      @Attr(scope = Scope.SESSION, value = "account") Account acc,
      @Param("::columns") List<?> columns,
      @Param("::search") Map<?, ?> search,
      int draw,
      int start,
      int length) {
    start = start / length;
    Pager pager = new Pager();
    pager.setPageNumber(start + 1);
    pager.setPageSize(length);

    Cnd cnd = Cnd.where("accountid", "=", acc.accountid);

    if (!Lang.isEmpty(search.get("value")) && !search.get("value").toString().equals("")) {
      cnd.and("name", "like", search.get("value"));
    }

    List<?> aaData = dao.query(Store.class, cnd);
    pager.setRecordCount(dao.count(Store.class, cnd));

    JDataGrid ret = new JDataGrid();
    ret.draw = draw;
    ret.data = aaData;
    ret.recordsTotal = pager.getRecordCount();
    ret.recordsFiltered = pager.getRecordCount();
    return ret;
  }
  private void resourceRelationFull(Resource resource) {
    List<Tag> tags;
    Sql sql_resource =
        Sqls.create(
            "select * from tag as t, resource_tag as rt where rt.resource_id = "
                + resource.getId()
                + " and rt.tag_id = t.id");
    sql_resource.setCallback(Sqls.callback.entities());
    sql_resource.setEntity(dao.getEntity(Tag.class));
    dao.execute(sql_resource);
    tags = sql_resource.getList(Tag.class);
    List<UserInfo> user = dao.query(UserInfo.class, Cnd.where("id", "=", resource.getAuthor()));
    if (user.size() > 0) {
      resource.setUserInfo(user.get(0));
    } else {
      System.out.print("resourceservice:用户id无效");
    }

    String tagString = ""; // 资源tag回填
    for (int i = 0; i < tags.size(); i++) {
      if (i < (tags.size() - 1)) {
        tagString = tagString + tags.get(i).getName() + ",";
      } else {
        tagString = tagString + tags.get(i).getName();
      }
    }

    resource.setTags(tagString);
    resource.setTagEntityList(tags);
  }
Beispiel #6
0
 @At
 @Ok("json")
 public Object list(@Attr(scope = Scope.SESSION, value = "account") Account acc) {
   Cnd cnd = Cnd.where("accountid", "=", acc.accountid);
   List<?> aaData = dao.query(Store.class, cnd);
   return aaData;
 }
Beispiel #7
0
 @At("/list_goodid/?")
 @Ok("json")
 public Object list_goodid(int id, @Attr(scope = Scope.SESSION, value = "account") Account acc) {
   Cnd cnd = Cnd.where("accountid", "=", acc.accountid);
   if (id != 0) {
     cnd.and(new Static("id in (select store_id from m_typelist where id=" + id + ")"));
   }
   List<?> aaData = dao.query(Store.class, cnd);
   return aaData;
 }
  /**
   * 分页查找 resource
   *
   * @param categoryId 分类id好好
   * @param order
   * @param pager
   * @return
   */
  public List<Resource> search(Integer categoryId, Integer tagId, String order, Pager pager) {
    List<Resource> query = null;

    if (categoryId != null) {
      query = dao.query(Resource.class, Cnd.where("categoryId", "=", categoryId).desc("id"), pager);
      if (pager != null) {
        pager.setRecordCount(dao.count(Resource.class, Cnd.where("categoryId", "=", categoryId)));
      }

    } else {
      query = dao.query(Resource.class, Cnd.orderBy().desc("id"), pager);
      if (pager != null) {
        pager.setRecordCount(dao.count(Resource.class));
      }
    }
    for (Resource resource : query) {
      resourceRelationFull(resource);
    }
    return query;
  }
Beispiel #9
0
  @Override
  public List<Item> listSameItems(long itemId) {
    Item item = dao.fetch(Item.class, itemId);
    if (null == item) {
      throw new AppRuntimeException("木有找到该item");
    }

    return dao.query(
        Item.class,
        Cnd.where("oid", "=", item.getOid()).and("skuMoreId", "=", item.getSkuMoreId()));
  }
Beispiel #10
0
  public List<Topic> getRecentTopics(int userId, Pager pager) {
    List<Topic> recent_topics =
        dao.query(Topic.class, Cnd.where("userId", "=", userId).desc("createTime"), pager);

    Map<Integer, UserProfile> authors = new HashMap<Integer, UserProfile>();
    if (!recent_topics.isEmpty()) {
      for (Topic topic : recent_topics) {
        fillTopic(topic, authors);
      }
    }
    pager.setRecordCount(dao.count(Topic.class, Cnd.where("userId", "=", userId)));
    return recent_topics;
  }
  /**
   * 分页查找 resource
   *
   * @param categoryId 分类id好好
   * @param order
   * @param pager
   * @return
   */
  public List<Resource> search(Integer categoryId, String order, Pager pager, Integer userId) {
    List<Resource> query = null;

    Cnd cnd = Cnd.NEW();
    if (userId != null) {
      cnd = cnd.and("author", "=", userId);
    }

    if (categoryId != null && categoryId != 0) {
      cnd = cnd.and("categoryId", "=", categoryId);
    }

    if (pager != null) {
      pager.setRecordCount(dao.count(Resource.class, cnd));
    }
    query = dao.query(Resource.class, cnd.desc("id"), pager);

    for (Resource resource : query) {
      resourceRelationFull(resource);
    }
    return query;
  }