Commit 07a80da8 by jinfeng.wang

fix

parent 6b8c2628
...@@ -34,12 +34,15 @@ public interface TagDao { ...@@ -34,12 +34,15 @@ public interface TagDao {
@Result(property = "install", column = "install"), @Result(property = "tag", column = "tag"), @Result(property = "install", column = "install"), @Result(property = "tag", column = "tag"),
@Result(property = "userId", column = "user_id"), @Result(property = "userId", column = "user_id"),
@Result(property = "updateTime", column = "update_time")}) @Result(property = "updateTime", column = "update_time")})
List<Tag> list(String search, int tag); List<Tag> list(String search, int tag, String userId);
class ListMapperProvider { class ListMapperProvider {
public String list(String search, int tag) { public String list(String search, int tag, String userId) {
String sql = "SELECT * FROM tag_list WHERE tag < " + tag; String sql = "SELECT * FROM tag_list WHERE tag < " + tag;
if (StringUtils.isNotBlank(userId)) {
sql += " AND user_id NOT LIKE '%" + userId + "%'";
}
if (StringUtils.isNotBlank(search)) { if (StringUtils.isNotBlank(search)) {
sql += " AND LOWER(package_name) LIKE '%" + search + "%'"; sql += " AND LOWER(package_name) LIKE '%" + search + "%'";
} }
...@@ -83,11 +86,14 @@ public interface TagDao { ...@@ -83,11 +86,14 @@ public interface TagDao {
*/ */
@SelectProvider(type = CountMapperProvider.class, method = "count") @SelectProvider(type = CountMapperProvider.class, method = "count")
int count(String search, int tag); int count(String search, int tag, String userId);
class CountMapperProvider { class CountMapperProvider {
public String count(String search, int tag) { public String count(String search, int tag, String userId) {
String sql = "SELECT COUNT(1) FROM tag_list WHERE tag < " + tag; String sql = "SELECT COUNT(1) FROM tag_list WHERE tag < " + tag;
if (StringUtils.isNotBlank(userId)) {
sql += " AND user_id NOT LIKE '%" + userId + "%'";
}
if (StringUtils.isNotBlank(search)) { if (StringUtils.isNotBlank(search)) {
sql += " AND LOWER(package_name) LIKE '%" + search + "%'"; sql += " AND LOWER(package_name) LIKE '%" + search + "%'";
} }
......
...@@ -65,47 +65,15 @@ public class TagServiceImpl implements TagService { ...@@ -65,47 +65,15 @@ public class TagServiceImpl implements TagService {
User user = userDao.find(userId); User user = userDao.find(userId);
List<Tag> results; List<Tag> results;
PageHelper.startPage(query.getOffset() / query.getLimit() + 1, query.getLimit()); PageHelper.startPage(query.getOffset() / query.getLimit() + 1, query.getLimit());
results = tagDao.list(query.getSearch().toLowerCase(), 3); results = tagDao.list(query.getSearch().toLowerCase(), 3, user.getUserId());
List<Tag> results2 = new ArrayList<>();
for (Tag tag : results) { return results;
if (StringUtils.isBlank(tag.getUserId())) {
results2.add(tag);
} else {
String[] userIds = tag.getUserId().split(",");
Set<String> userSet = new HashSet<>(Arrays.asList(userIds));
if (!userSet.contains(user.getUserId())) {
results2.add(tag);
}
}
}
return results2;
} }
@Override @Override
public int count(String userId, Query query) { public int count(String userId, Query query) {
User user = userDao.find(userId); User user = userDao.find(userId);
List<Tag> results;
results = tagDao.list(query.getSearch().toLowerCase(), 3);
int count = 0;
for (Tag tag : results) {
if (StringUtils.isBlank(tag.getUserId())) {
count += 1;
} else {
String[] userIds = tag.getUserId().split(",");
Set<String> userSet = new HashSet<>(Arrays.asList(userIds));
if (!userSet.contains(user.getUserId())) {
count += 1;
}
}
}
return count;
}
/* return tagDao.count(query.getSearch().toLowerCase(), 3, user.getUserId());
@Override
public List<Tag> list(int pageNum, int pageSize) {
PageHelper.startPage(pageNum, pageSize);
return tagDao.list(1);
} }
*/
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment