Commit 6b8c2628 by jinfeng.wang

fix

parent c3376926
......@@ -2,7 +2,6 @@ package com.mobvista.apptag.controller;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.PageHelper;
import com.mobvista.apptag.config.WebSecurityConfig;
import com.mobvista.apptag.entity.Feat;
import com.mobvista.apptag.entity.Tag;
......@@ -88,7 +87,6 @@ public class TagController {
@RequestParam(name = "ruleCode", required = false) String ruleCode,
@RequestParam(name = "styleCode", required = false) String styleCode,
@RequestParam(name = "themeCode", required = false) String themeCode) {
System.out.println("packageName=" + packageName + ",categoryCode=" + categoryCode);
Map<String, String> codeMap = new HashMap<String, String>();
Map<String, String> featMap = featService.getMap();
......@@ -142,10 +140,10 @@ public class TagController {
@ResponseBody
public PageUtil list(@SessionAttribute(WebSecurityConfig.SESSION_KEY) String userName,
@RequestBody Query query, @RequestParam(name = "tag", required = false, defaultValue = "0") int tag) {
PageHelper.startPage(query.getOffset() / query.getLimit() + 1, query.getLimit());
String search = query.getSearch();
List<Tag> tags = tagDao.list(search, tag);
int total = tagDao.count(search, tag);
// PageHelper.startPage(query.getOffset() / query.getLimit() + 1, query.getLimit());
// String search = query.getSearch();
List<Tag> tags = tagService.list(userName, query);
int total = tagService.count(userName, query);
PageUtil pageUtil = new PageUtil(tags, total);
return pageUtil;
}
......
package com.mobvista.apptag.service;
import com.mobvista.apptag.entity.Tag;
import com.mobvista.apptag.utils.Query;
import java.util.List;
/**
* @author wangjf
......@@ -11,5 +14,7 @@ public interface TagService {
Tag find(String packageName);
// List<Tag> list(int pageNum, int pageSize);
List<Tag> list(String userId, Query query);
int count(String userId, Query query);
}
\ No newline at end of file
package com.mobvista.apptag.service.impl;
import com.github.pagehelper.PageHelper;
import com.mobvista.apptag.entity.Tag;
import com.mobvista.apptag.entity.User;
import com.mobvista.apptag.mapper.TagDao;
import com.mobvista.apptag.mapper.UserDao;
import com.mobvista.apptag.service.TagService;
import com.mobvista.apptag.utils.Query;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import java.util.*;
@Service("tagService")
public class TagServiceImpl implements TagService {
......@@ -61,6 +60,47 @@ public class TagServiceImpl implements TagService {
return tagDao.find(packageName);
}
@Override
public List<Tag> list(String userId, Query query) {
User user = userDao.find(userId);
List<Tag> results;
PageHelper.startPage(query.getOffset() / query.getLimit() + 1, query.getLimit());
results = tagDao.list(query.getSearch().toLowerCase(), 3);
List<Tag> results2 = new ArrayList<>();
for (Tag tag : 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
public int count(String userId, Query query) {
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;
}
/*
@Override
public List<Tag> list(int pageNum, int pageSize) {
......
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