Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
solo-1
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
solo-1
Commits
e5ec2661
Commit
e5ec2661
authored
Apr 08, 2017
by
Liang Ding
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🚧
#12256 填充侧边栏分类模型
parent
183ba177
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
164 additions
and
110 deletions
+164
-110
src/main/java/org/b3log/solo/model/Common.java
src/main/java/org/b3log/solo/model/Common.java
+7
-2
src/main/java/org/b3log/solo/processor/util/Filler.java
src/main/java/org/b3log/solo/processor/util/Filler.java
+111
-103
src/main/java/org/b3log/solo/repository/CategoryRepository.java
...in/java/org/b3log/solo/repository/CategoryRepository.java
+12
-1
src/main/java/org/b3log/solo/repository/impl/CategoryRepositoryImpl.java
...rg/b3log/solo/repository/impl/CategoryRepositoryImpl.java
+32
-1
src/main/java/org/b3log/solo/service/ArticleQueryService.java
...main/java/org/b3log/solo/service/ArticleQueryService.java
+2
-3
No files found.
src/main/java/org/b3log/solo/model/Common.java
View file @
e5ec2661
...
...
@@ -20,7 +20,7 @@ package org.b3log.solo.model;
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="mailto:dongxu.wang@acm.org">Dongxu Wang</a>
* @version 1.
4.5.1, Nov 1, 2015
* @version 1.
5.5.1, Apr 8, 2017
* @since 0.3.1
*/
public
final
class
Common
{
...
...
@@ -35,6 +35,11 @@ public final class Common {
*/
public
static
final
String
MOST_USED_TAGS
=
"mostUsedTags"
;
/**
* Most used categories.
*/
public
static
final
String
MOST_USED_CATEGORIES
=
"mostUsedCategories"
;
/**
* Most comment count articles.
*/
...
...
@@ -174,7 +179,7 @@ public final class Common {
* Key of current user.
*/
public
static
final
String
CURRENT_USER
=
"currentUser"
;
/**
* Key of admin user.
*/
...
...
src/main/java/org/b3log/solo/processor/util/Filler.java
View file @
e5ec2661
This diff is collapsed.
Click to expand it.
src/main/java/org/b3log/solo/repository/CategoryRepository.java
View file @
e5ec2661
...
...
@@ -19,11 +19,13 @@ import org.b3log.latke.repository.Repository;
import
org.b3log.latke.repository.RepositoryException
;
import
org.json.JSONObject
;
import
java.util.List
;
/**
* Category repository.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.
1.0.1, Apr 1
, 2017
* @version 1.
2.0.1, Apr 8
, 2017
* @since 2.0.0
*/
public
interface
CategoryRepository
extends
Repository
{
...
...
@@ -80,4 +82,13 @@ public interface CategoryRepository extends Repository {
* @throws RepositoryException repository exception
*/
JSONObject
getByOrder
(
final
int
order
)
throws
RepositoryException
;
/**
* Gets most used categories (contains the most tags) with the specified number.
*
* @param num the specified number
* @return a list of most used categories, returns an empty list if not found
* @throws RepositoryException repository exception
*/
List
<
JSONObject
>
getMostUsedCategories
(
final
int
num
)
throws
RepositoryException
;
}
src/main/java/org/b3log/solo/repository/impl/CategoryRepositoryImpl.java
View file @
e5ec2661
...
...
@@ -18,16 +18,23 @@ package org.b3log.solo.repository.impl;
import
org.b3log.latke.Keys
;
import
org.b3log.latke.repository.*
;
import
org.b3log.latke.repository.annotation.Repository
;
import
org.b3log.latke.util.CollectionUtils
;
import
org.b3log.solo.model.Category
;
import
org.b3log.solo.model.Tag
;
import
org.b3log.solo.repository.CategoryRepository
;
import
org.json.JSONArray
;
import
org.json.JSONObject
;
import
java.text.Collator
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.List
;
/**
* Category repository.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.0.
0, Apr 1
, 2017
* @version 1.1.0.
1, Apr 8
, 2017
* @since 2.0.0
*/
@Repository
...
...
@@ -104,6 +111,20 @@ public class CategoryRepositoryImpl extends AbstractRepository implements Catego
return
array
.
optJSONObject
(
0
);
}
@Override
public
List
<
JSONObject
>
getMostUsedCategories
(
final
int
num
)
throws
RepositoryException
{
final
Query
query
=
new
Query
().
addSort
(
Category
.
CATEGORY_TAG_CNT
,
SortDirection
.
DESCENDING
).
setCurrentPageNum
(
1
).
setPageSize
(
num
).
setPageCount
(
1
);
final
JSONObject
result
=
get
(
query
);
final
JSONArray
array
=
result
.
optJSONArray
(
Keys
.
RESULTS
);
final
List
<
JSONObject
>
ret
=
CollectionUtils
.
jsonArrayToList
(
array
);
sortJSONCategoryList
(
ret
);
return
ret
;
}
@Override
public
JSONObject
getUpper
(
final
String
id
)
throws
RepositoryException
{
final
JSONObject
category
=
get
(
id
);
...
...
@@ -153,4 +174,14 @@ public class CategoryRepositoryImpl extends AbstractRepository implements Catego
return
array
.
optJSONObject
(
0
);
}
private
void
sortJSONCategoryList
(
final
List
<
JSONObject
>
tagJoList
)
{
Collections
.
sort
(
tagJoList
,
new
Comparator
<
JSONObject
>()
{
@Override
public
int
compare
(
final
JSONObject
o1
,
final
JSONObject
o2
)
{
return
Collator
.
getInstance
(
java
.
util
.
Locale
.
CHINA
).
compare
(
o1
.
optString
(
Tag
.
TAG_TITLE
),
o2
.
optString
(
Tag
.
TAG_TITLE
));
}
});
}
}
src/main/java/org/b3log/solo/service/ArticleQueryService.java
View file @
e5ec2661
...
...
@@ -142,9 +142,8 @@ public class ArticleQueryService {
pagination
.
put
(
Pagination
.
PAGINATION_PAGE_NUMS
,
(
Object
)
Collections
.
emptyList
());
try
{
final
JSONArray
categoryTags
=
categoryTagRepository
.
getByCategoryId
(
categoryId
,
1
,
Integer
.
MAX_VALUE
)
.
optJSONArray
(
Keys
.
RESULTS
);
final
JSONArray
categoryTags
=
categoryTagRepository
.
getByCategoryId
(
categoryId
,
1
,
Integer
.
MAX_VALUE
).
optJSONArray
(
Keys
.
RESULTS
);
if
(
categoryTags
.
length
()
<=
0
)
{
return
ret
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment