feat:首页图加载优化,增加OneNav导入支持
This commit is contained in:
parent
405a2e05ed
commit
523698a967
@ -29,6 +29,11 @@
|
|||||||
<artifactId>pinyin</artifactId>
|
<artifactId>pinyin</artifactId>
|
||||||
<version>0.3.1</version>
|
<version>0.3.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.xerial</groupId>
|
||||||
|
<artifactId>sqlite-jdbc</artifactId>
|
||||||
|
<version>3.44.1.0</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ public class BookmarkController {
|
|||||||
*/
|
*/
|
||||||
@RequestMapping("/uploadBookmarkFile")
|
@RequestMapping("/uploadBookmarkFile")
|
||||||
public Result uploadFile(@RequestParam("file") MultipartFile file, @RequestParam("path") String path) throws Exception {
|
public Result uploadFile(@RequestParam("file") MultipartFile file, @RequestParam("path") String path) throws Exception {
|
||||||
bookmarkService.parseBookmarkFile(UserContextHolder.get().getUserId(), file.getInputStream(), path);
|
bookmarkService.parseBookmarkFile(UserContextHolder.get().getUserId(), file, path);
|
||||||
return Result.success(null);
|
return Result.success(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package com.fanxb.bookmark.business.bookmark.service;
|
|||||||
import com.fanxb.bookmark.business.bookmark.entity.BookmarkEs;
|
import com.fanxb.bookmark.business.bookmark.entity.BookmarkEs;
|
||||||
import com.fanxb.bookmark.business.bookmark.entity.MoveNodeBody;
|
import com.fanxb.bookmark.business.bookmark.entity.MoveNodeBody;
|
||||||
import com.fanxb.bookmark.common.entity.po.Bookmark;
|
import com.fanxb.bookmark.common.entity.po.Bookmark;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -54,7 +55,7 @@ public interface BookmarkService {
|
|||||||
* @author fanxb
|
* @author fanxb
|
||||||
* @date 2019/7/9 18:44
|
* @date 2019/7/9 18:44
|
||||||
*/
|
*/
|
||||||
void parseBookmarkFile(int userId, InputStream stream, String path) throws Exception;
|
void parseBookmarkFile(int userId, MultipartFile file, String path) throws Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description: 详情
|
* Description: 详情
|
||||||
|
@ -2,10 +2,8 @@ package com.fanxb.bookmark.business.bookmark.service.impl;
|
|||||||
|
|
||||||
import cn.hutool.core.codec.Base64Decoder;
|
import cn.hutool.core.codec.Base64Decoder;
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
import cn.hutool.core.util.*;
|
||||||
import cn.hutool.core.util.CharsetUtil;
|
|
||||||
import cn.hutool.core.util.HashUtil;
|
import cn.hutool.core.util.HashUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.fanxb.bookmark.business.api.UserApi;
|
import com.fanxb.bookmark.business.api.UserApi;
|
||||||
import com.fanxb.bookmark.business.bookmark.constant.FileConstant;
|
import com.fanxb.bookmark.business.bookmark.constant.FileConstant;
|
||||||
@ -38,7 +36,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.awt.print.Book;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -49,6 +49,10 @@ import java.nio.charset.Charset;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.Statement;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -81,18 +85,25 @@ public class BookmarkServiceImpl implements BookmarkService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void parseBookmarkFile(int userId, InputStream stream, String path) throws Exception {
|
public void parseBookmarkFile(int userId, MultipartFile file, String path) throws Exception {
|
||||||
Document doc = Jsoup.parse(stream, "utf-8", "");
|
List<Bookmark> bookmarks = new ArrayList<>();
|
||||||
Elements elements = doc.select("html>body>dl>dt");
|
|
||||||
//获取当前层sort最大值
|
//获取当前层sort最大值
|
||||||
Integer sortBase = bookmarkDao.selectMaxSort(userId, path);
|
Integer sortBase = bookmarkDao.selectMaxSort(userId, path);
|
||||||
if (sortBase == null) {
|
if (sortBase == null) {
|
||||||
sortBase = 0;
|
sortBase = 0;
|
||||||
}
|
}
|
||||||
List<Bookmark> bookmarks = new ArrayList<>();
|
if (file.getOriginalFilename().endsWith(".db3")) {
|
||||||
|
//处理db文件
|
||||||
|
readFromOneEnv(bookmarks, userId, file, path, sortBase);
|
||||||
|
} else {
|
||||||
|
InputStream stream = file.getInputStream();
|
||||||
|
Document doc = Jsoup.parse(stream, "utf-8", "");
|
||||||
|
Elements elements = doc.select("html>body>dl>dt");
|
||||||
for (int i = 0, length = elements.size(); i < length; i++) {
|
for (int i = 0, length = elements.size(); i < length; i++) {
|
||||||
dealBookmark(userId, elements.get(i), path, sortBase + i, bookmarks);
|
dealBookmark(userId, elements.get(i), path, sortBase + i, bookmarks);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//每一千条处理插入一次,批量更新搜索字段
|
//每一千条处理插入一次,批量更新搜索字段
|
||||||
List<Bookmark> tempList = new ArrayList<>(1000);
|
List<Bookmark> tempList = new ArrayList<>(1000);
|
||||||
for (int i = 0; i < bookmarks.size(); i++) {
|
for (int i = 0; i < bookmarks.size(); i++) {
|
||||||
@ -151,6 +162,57 @@ public class BookmarkServiceImpl implements BookmarkService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理oneenv的导出
|
||||||
|
*
|
||||||
|
* @param bookmarks 书签列表
|
||||||
|
* @param userId 用户id
|
||||||
|
* @param file file
|
||||||
|
* @param path path
|
||||||
|
* @param sort sort
|
||||||
|
*/
|
||||||
|
private void readFromOneEnv(List<Bookmark> bookmarks, int userId, MultipartFile file, String path, int sort) {
|
||||||
|
String filePath = CommonConstant.fileSavePath + "/files/" + IdUtil.simpleUUID() + ".db3";
|
||||||
|
try {
|
||||||
|
file.transferTo(FileUtil.newFile(filePath));
|
||||||
|
try (Connection conn = DriverManager.getConnection("jdbc:sqlite:" + filePath)) {
|
||||||
|
Statement stat = conn.createStatement();
|
||||||
|
ResultSet rs = stat.executeQuery("select * from on_categorys");
|
||||||
|
Map<Long, Bookmark> folderMap = new HashMap<>();
|
||||||
|
Map<Long, Integer> childSortBaseMap = new HashMap<>();
|
||||||
|
while (rs.next()) {
|
||||||
|
long addTime = rs.getLong("add_time");
|
||||||
|
Bookmark folder = new Bookmark(userId, path, StrUtil.nullToEmpty(rs.getString("name")), addTime == 0 ? System.currentTimeMillis() : addTime * 1000, sort++);
|
||||||
|
int childSortBase = 0;
|
||||||
|
if (insertOne(folder)) {
|
||||||
|
childSortBase = ObjectUtil.defaultIfNull(bookmarkDao.selectMaxSort(userId, path), 0);
|
||||||
|
}
|
||||||
|
long id = rs.getLong("id");
|
||||||
|
folderMap.put(id, folder);
|
||||||
|
childSortBaseMap.put(id, childSortBase);
|
||||||
|
}
|
||||||
|
rs.close();
|
||||||
|
rs = stat.executeQuery("select * from on_links");
|
||||||
|
while (rs.next()) {
|
||||||
|
long fId = rs.getLong("fid");
|
||||||
|
long addTime = rs.getLong("add_time");
|
||||||
|
int tempSort = childSortBaseMap.get(fId);
|
||||||
|
childSortBaseMap.put(fId, tempSort + 1);
|
||||||
|
Bookmark folder = folderMap.get(fId);
|
||||||
|
String curPath = folder == null ? "" : folder.getPath() + "." + folder.getBookmarkId();
|
||||||
|
Bookmark bookmark = new Bookmark(userId, curPath, StrUtil.nullToEmpty(rs.getString("title"))
|
||||||
|
, StrUtil.nullToEmpty(rs.getString("url")), "", addTime == 0 ? System.currentTimeMillis() : addTime * 1000, tempSort);
|
||||||
|
bookmarks.add(bookmark);
|
||||||
|
insertOne(bookmark);
|
||||||
|
}
|
||||||
|
rs.close();
|
||||||
|
stat.close();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description: 插入一条书签,如果已经存在同名书签将跳过
|
* Description: 插入一条书签,如果已经存在同名书签将跳过
|
||||||
*
|
*
|
||||||
@ -288,7 +350,7 @@ public class BookmarkServiceImpl implements BookmarkService {
|
|||||||
int size = 100;
|
int size = 100;
|
||||||
int start = 0;
|
int start = 0;
|
||||||
List<Bookmark> deal;
|
List<Bookmark> deal;
|
||||||
while ((deal = bookmarkDao.selectUserNoIcon(userId, start, size)).size() > 0) {
|
while (!(deal = bookmarkDao.selectUserNoIcon(userId, start, size)).isEmpty()) {
|
||||||
start += size;
|
start += size;
|
||||||
deal.forEach(item -> {
|
deal.forEach(item -> {
|
||||||
String icon = getIconPath(item.getUrl(), null, null);
|
String icon = getIconPath(item.getUrl(), null, null);
|
||||||
|
@ -69,9 +69,7 @@ public class ConfigServiceImpl implements ConfigService {
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
str = getBingImg();
|
str = getBingImg();
|
||||||
if (str != null) {
|
|
||||||
stringRedisTemplate.opsForValue().set(RedisConstant.BING_IMG, str, 2, TimeUnit.HOURS);
|
stringRedisTemplate.opsForValue().set(RedisConstant.BING_IMG, str, 2, TimeUnit.HOURS);
|
||||||
}
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
:data="{ path: form.path }"
|
:data="{ path: form.path }"
|
||||||
:headers="{ 'jwt-token': token }"
|
:headers="{ 'jwt-token': token }"
|
||||||
action="/bookmark/api/bookmark/uploadBookmarkFile"
|
action="/bookmark/api/bookmark/uploadBookmarkFile"
|
||||||
|
accept=".html,.db3"
|
||||||
@change="fileChange"
|
@change="fileChange"
|
||||||
>
|
>
|
||||||
<p class="ant-upload-drag-icon">
|
<p class="ant-upload-drag-icon">
|
||||||
|
@ -4,6 +4,7 @@ module.exports = {
|
|||||||
devtool: "source-map"
|
devtool: "source-map"
|
||||||
},
|
},
|
||||||
devServer: {
|
devServer: {
|
||||||
|
port: 4531,
|
||||||
proxy: {
|
proxy: {
|
||||||
"/bookmark/api": {
|
"/bookmark/api": {
|
||||||
//这里最好有一个 /
|
//这里最好有一个 /
|
||||||
|
Loading…
x
Reference in New Issue
Block a user