test
This commit is contained in:
parent
25a199d8d4
commit
123e90b89e
|
|
@ -11,10 +11,12 @@ public class DebugUtil {
|
|||
}
|
||||
|
||||
// 标记结束点并返回执行时间(秒,保留三位小数)
|
||||
public static String end() {
|
||||
public static void printTime(String message) {
|
||||
long endTime = System.nanoTime();
|
||||
double duration = (endTime - startTime) / 1_000_000_000.0; // 转换为秒
|
||||
return String.format("%.3f", duration);
|
||||
String result = String.format("%s: %.3f", message, duration);
|
||||
out(result);
|
||||
startTime=System.nanoTime();
|
||||
}
|
||||
public static void out(Object object){
|
||||
if(object==null){
|
||||
|
|
|
|||
|
|
@ -243,29 +243,29 @@ public class SocialDirectoryService extends BaseService {
|
|||
*/
|
||||
public Page<SocialDirectoryView> search(String keyword, List<Integer> typeList, int pageNum, int pageSize) {
|
||||
|
||||
DebugUtil.start();
|
||||
|
||||
//mongodb分页
|
||||
Query query = new Query();
|
||||
query.addCriteria(Criteria.where("type").in(typeList));
|
||||
|
||||
|
||||
QueryWrapper<SocialDirectory> codeqw = new QueryWrapper<>();
|
||||
if (typeList.size() == 1) {
|
||||
codeqw.eq("type", typeList.get(0));
|
||||
} else {
|
||||
codeqw.in("type", typeList);
|
||||
if (!keyword.trim().isEmpty()) {
|
||||
query.addCriteria(new Criteria().orOperator(
|
||||
Criteria.where("code").regex(keyword, "i"),
|
||||
Criteria.where("name").regex(keyword, "i")
|
||||
// Criteria.where("keyword").regex(keyword, "i"),
|
||||
// Criteria.where("producer").regex(keyword, "i")
|
||||
));
|
||||
}
|
||||
|
||||
//模糊搜索
|
||||
if (keyword != null && !keyword.trim().isEmpty()) {
|
||||
codeqw.and(wrapper ->
|
||||
wrapper.like("name", keyword).or().like("code", keyword).or().like("keyword", keyword)
|
||||
);
|
||||
long count = mongoTemplate.count(query, SocialDirectoryMongodb.class, "social_directory");
|
||||
DebugUtil.printTime("查询数量耗时:");
|
||||
query.skip((long) (pageNum - 1) * pageSize).limit(pageSize);
|
||||
List<SocialDirectoryMongodb> mongodbList = mongoTemplate.find(query, SocialDirectoryMongodb.class, "social_directory");
|
||||
List<String> codeList = new ArrayList<>();
|
||||
for (SocialDirectoryMongodb mongodb : mongodbList) {
|
||||
codeList.add(mongodb.getCode());
|
||||
}
|
||||
// 执行查询
|
||||
|
||||
// return success(SelectPage(queryWrapper, page, size, iSocialDirectoryService));
|
||||
codeqw.select("code");
|
||||
long count = socialDirectoryMapper.selectCount(codeqw);
|
||||
codeqw.last("LIMIT " + pageSize + " OFFSET " + (pageNum - 1) * pageSize);
|
||||
List<String> codeList = socialDirectoryMapper.selectObjs(codeqw);
|
||||
DebugUtil.printTime("mongodb查询结束");
|
||||
if (codeList.isEmpty()) {
|
||||
Page<SocialDirectoryView> empty_result = new Page<>();
|
||||
empty_result.setList(new ArrayList<>());
|
||||
|
|
@ -280,7 +280,7 @@ public class SocialDirectoryService extends BaseService {
|
|||
List<SocialDirectoryUpinfo> socialDirectoryUpinfoList = socialDirectoryUpinfoMapper.selectList(queryWrapper);
|
||||
List<SocialDirectoryLimit> socialDirectoryLimitList = socialDirectoryLimitMapper.selectList(queryWrapper);
|
||||
List<SocialDirectorySelf> socialDirectorySelfList = socialDirectorySelfMapper.selectList(queryWrapper);
|
||||
|
||||
DebugUtil.printTime("查询数据库结束");
|
||||
Map<String, SocialDirectoryUpinfo> stringSocialDirectoryUpinfoMap = socialDirectoryUpinfoList.stream()
|
||||
.collect(Collectors.toMap(SocialDirectoryUpinfo::getCode, socialDirectoryUpinfo -> socialDirectoryUpinfo));
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue