Merge branch 'dev'

This commit is contained in:
fanxb 2021-09-15 22:43:08 +08:00
commit 86997b234f
36 changed files with 233 additions and 9050 deletions

View File

@ -21,6 +21,7 @@ public interface BookmarkApi {
* @author fanxb
* @param delete 是否删除问题数据
* @param userId userId
* @return 返回删除的数据
* @date 2021/3/17
**/
Set<String> dealBadBookmark(boolean delete, int userId);

View File

@ -1,5 +1,9 @@
package com.fanxb.bookmark.business.api;
/**
* @author fanxb
* @date 2021/8/20 下午2:12
*/
public interface UserApi {
/**
* 版本自增

View File

@ -13,7 +13,8 @@ import java.util.List;
/**
* Created with IntelliJ IDEA
* Created By Fxb
*
* @author fanxb
* Date: 2020/3/29
* Time: 13:08
*/

View File

@ -21,7 +21,7 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/bookmarkBackup")
public class BookmarkBackupController {
private BookmarkBackupService backupService;
private final BookmarkBackupService backupService;
@Autowired
public BookmarkBackupController(BookmarkBackupServiceImpl backupService) {
@ -31,7 +31,7 @@ public class BookmarkBackupController {
@PostMapping("/mysqlToEs")
public Result backupToEs() {
//异步执行同步任务
ThreadPoolUtil.execute(() -> backupService.backupToEs());
ThreadPoolUtil.execute(backupService::backupToEs);
return Result.success(null);
}
}

View File

@ -187,6 +187,7 @@ public interface BookmarkDao extends BaseMapper<Bookmark> {
/**
* 批量更新searchKey
*
* @param list list
* @author fanxb
* @date 2020/3/22 22:08
*/
@ -213,16 +214,28 @@ public interface BookmarkDao extends BaseMapper<Bookmark> {
@Update("update bookmark set visitNum=visitNum+1 where userId=#{userId} and bookmarkId=#{bookmarkId}")
void updateVisitNum(VisitNumPlus item);
/**
* 查询用户最常访问的几个书签
*
* @param userId 用户id
* @param num num
* @return java.util.List<com.fanxb.bookmark.common.entity.Bookmark>
* @author fanxb
* @date 2021/8/20 上午11:52
*/
@Select("select bookmarkId,name,url,icon from bookmark where userId=#{userId} and type=0 order by visitNum desc limit 0,#{num}")
List<Bookmark> selectPopular(@Param("userId") int userId, @Param("num") int num);
/**
* 获取某用户无icon的条目
*
* @param userId userId
* @param start 开始
* @param size 数量
* @return java.util.List<com.fanxb.bookmark.common.entity.Bookmark>
* @author fanxb
* @date 2021/3/11
**/
* @date 2021/8/20 下午12:02
*/
@Select("select userId,bookmarkId,url,icon from bookmark where userId=#{userId} and icon='' order by bookmarkId asc limit #{start},#{size}")
List<Bookmark> selectUserNoIcon(@Param("userId") int userId, @Param("start") int start, @Param("size") int size);
@ -238,12 +251,13 @@ public interface BookmarkDao extends BaseMapper<Bookmark> {
void updateIcon(@Param("bookmarkId") int bookmarkId, @Param("icon") String icon);
/**
* 获取某用户所有的id,bookmark
* 查询一个用户全部的书签路径
*
* @param userId userId
* @return java.util.List<com.fanxb.bookmark.common.entity.Bookmark>
* @author fanxb
* @date 2021/3/17
**/
* @date 2021/8/20 上午11:58
*/
@Select("select bookmarkId,path from bookmark where userId=#{userId}")
List<Bookmark> selectBookmarkIdPathByUserId(int userId);

View File

@ -8,7 +8,8 @@ import java.util.List;
/**
* Created with IntelliJ IDEA
* Created By Fxb
*
* @author fanxb
* Date: 2020/3/19
* Time: 0:05
*/

View File

@ -1,8 +1,7 @@
package com.fanxb.bookmark.business.bookmark.service;
/**
* Created with IntelliJ IDEA
* Created By Fxb
* @author fanxb
* Date: 2020/3/29
* Time: 12:43
*/
@ -20,6 +19,7 @@ public interface BookmarkBackupService {
/**
* Description: 将某个用户的书签数据mysql同步到es中
*
* @param userId 用户id
* @author fanxb
* @date 2019/7/26 11:27
*/

View File

@ -11,7 +11,8 @@ import java.util.Set;
/**
* Created with IntelliJ IDEA
* Created By Fxb
*
* @author fanxb
* Date: 2020/3/29
* Time: 12:25
*/
@ -48,6 +49,8 @@ public interface BookmarkService {
*
* @param stream 输入流
* @param path 存放路径
* @param userId userId
* @throws Exception 各种异常
* @author fanxb
* @date 2019/7/9 18:44
*/
@ -68,6 +71,7 @@ public interface BookmarkService {
*
* @param userId userId
* @param bookmark bookmark
* @return 更新后的icon
* @author fanxb
* @date 2019/7/17 14:42
*/

View File

@ -6,7 +6,8 @@ import java.util.List;
/**
* Created with IntelliJ IDEA
* Created By Fxb
*
* @author fanxb
* Date: 2020/3/18
* Time: 23:47
*/
@ -15,15 +16,15 @@ public interface PinYinService {
/**
* 分隔符
*/
static final String PARTITION = "||";
String PARTITION = "||";
/**
* 拼音接口路径
*/
static final String PATH = "/pinyinChange";
String PATH = "/pinyinChange";
/**
* 分页查询页大小
*/
static final int SIZE = 500;
int SIZE = 500;
/**
* 功能描述: 首次上线用于全量初始化

View File

@ -27,7 +27,8 @@ import java.util.stream.Collectors;
/**
* Created with IntelliJ IDEA
* Created By Fxb
*
* @author fanxb
* Date: 2020/3/18
* Time: 23:48
*/

View File

@ -12,7 +12,8 @@ import org.springframework.web.bind.annotation.RestController;
/**
* Created with IntelliJ IDEA
* Created By Fxb
*
* @author fanxb
* Date: 2020/3/10
* Time: 23:16
*/

View File

@ -1,10 +1,10 @@
package com.fanxb.bookmark.business.user.controller;
import com.alibaba.fastjson.JSONObject;
import com.fanxb.bookmark.business.user.service.OAuthService;
import com.fanxb.bookmark.business.user.service.OauthService;
import com.fanxb.bookmark.business.user.service.UserService;
import com.fanxb.bookmark.business.user.vo.LoginBody;
import com.fanxb.bookmark.business.user.vo.OAuthBody;
import com.fanxb.bookmark.business.user.vo.OauthBody;
import com.fanxb.bookmark.business.user.vo.RegisterBody;
import com.fanxb.bookmark.business.user.service.impl.UserServiceImpl;
import com.fanxb.bookmark.common.entity.Result;
@ -28,11 +28,11 @@ import javax.validation.Valid;
public class UserController {
private final UserServiceImpl userServiceImpl;
private final OAuthService oAuthService;
private final OauthService oAuthService;
private final UserService userService;
@Autowired
public UserController(UserServiceImpl userServiceImpl, OAuthService oAuthService, UserService userService) {
public UserController(UserServiceImpl userServiceImpl, OauthService oAuthService, UserService userService) {
this.userServiceImpl = userServiceImpl;
this.oAuthService = oAuthService;
this.userService = userService;
@ -142,7 +142,7 @@ public class UserController {
* @date 2021/3/10
*/
@PostMapping("oAuthLogin")
public Result oAuthLogin(@RequestBody OAuthBody body) {
public Result oAuthLogin(@RequestBody OauthBody body) {
return Result.success(oAuthService.oAuthCheck(body));
}

View File

@ -3,13 +3,16 @@ package com.fanxb.bookmark.business.user.dao;
import com.fanxb.bookmark.business.user.entity.Feedback;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Component;
/**
* Created with IntelliJ IDEA
* Created By Fxb
*
* @author fanxb
* Date: 2020/3/10
* Time: 23:14
*/
@Component
public interface FeedbackDao {
/**

View File

@ -63,6 +63,7 @@ public interface UserDao {
* Description: 根据用户id查询用户信息
*
* @param userId userId
* @param githubId githubId
* @return com.fanxb.bookmark.common.entity.User
* @author fanxb
* @date 2019/7/30 16:08

View File

@ -6,7 +6,8 @@ import javax.validation.constraints.NotEmpty;
/**
* Created with IntelliJ IDEA
* Created By Fxb
*
* @author fanxb
* Date: 2020/3/10
* Time: 23:13
*/

View File

@ -4,7 +4,8 @@ import com.fanxb.bookmark.business.user.entity.Feedback;
/**
* Created with IntelliJ IDEA
* Created By Fxb
*
* @author fanxb
* Date: 2020/3/10
* Time: 23:17
*/

View File

@ -1,8 +0,0 @@
package com.fanxb.bookmark.business.user.service;
import com.fanxb.bookmark.business.user.vo.OAuthBody;
public interface OAuthService {
String oAuthCheck(OAuthBody body);
}

View File

@ -0,0 +1,19 @@
package com.fanxb.bookmark.business.user.service;
import com.fanxb.bookmark.business.user.vo.OauthBody;
/**
* @author fanxb
* @date 2021/8/20 下午2:13
*/
public interface OauthService {
/**
* oauth登陆校验
*
* @param body body
* @return java.lang.String
* @author fanxb
* @date 2021/8/20 下午2:13
*/
String oAuthCheck(OauthBody body);
}

View File

@ -38,6 +38,7 @@ public interface UserService {
/**
* 获取当前用户的version
*
* @param userId userId
* @return int
* @author fanxb
* @date 2021/3/11
@ -56,6 +57,7 @@ public interface UserService {
* 检查所有用户的问题书签数据
*
* @param delete 是否删除问题数据
* @return 返回用户删除的数据
* @author fanxb
* @date 2021/3/17
**/

View File

@ -9,14 +9,19 @@ import org.springframework.stereotype.Service;
/**
* Created with IntelliJ IDEA
* Created By Fxb
*
* @author fanxb
* Date: 2020/3/10
* Time: 23:17
*/
@Service
public class FeedbackServiceImpl implements FeedbackService {
private final FeedbackDao feedbackDao;
@Autowired
private FeedbackDao feedbackDao;
public FeedbackServiceImpl(FeedbackDao feedbackDao) {
this.feedbackDao = feedbackDao;
}
@Override
public void addOne(Feedback feedback) {

View File

@ -1,12 +1,11 @@
package com.fanxb.bookmark.business.user.service.impl;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.fanxb.bookmark.business.user.dao.UserDao;
import com.fanxb.bookmark.business.user.service.OAuthService;
import com.fanxb.bookmark.business.user.service.OauthService;
import com.fanxb.bookmark.business.user.service.UserService;
import com.fanxb.bookmark.business.user.vo.OAuthBody;
import com.fanxb.bookmark.business.user.vo.OauthBody;
import com.fanxb.bookmark.common.constant.Constant;
import com.fanxb.bookmark.common.entity.User;
import com.fanxb.bookmark.common.exception.CustomException;
@ -33,7 +32,7 @@ import static com.fanxb.bookmark.business.user.service.UserService.SHORT_EXPIRE_
**/
@Service
@Slf4j
public class OAuthServiceImpl implements OAuthService {
public class OauthServiceImpl implements OauthService {
@Value("${OAuth.github.clientId}")
private String githubClientId;
@ -43,16 +42,16 @@ public class OAuthServiceImpl implements OAuthService {
private final UserService userService;
@Autowired
public OAuthServiceImpl(UserDao userDao, UserService userService) {
public OauthServiceImpl(UserDao userDao, UserService userService) {
this.userDao = userDao;
this.userService = userService;
}
@Override
@Transactional(rollbackFor = Exception.class)
public String oAuthCheck(OAuthBody body) {
public String oAuthCheck(OauthBody body) {
User current, other = new User();
if (StrUtil.equals(body.getType(), OAuthBody.GITHUB)) {
if (StrUtil.equals(body.getType(), OauthBody.GITHUB)) {
Map<String, String> header = new HashMap<>(2);
header.put("accept", "application/json");
String url = "https://github.com/login/oauth/access_token?client_id=" + githubClientId + "&client_secret=" + githubSecret + "&code=" + body.getCode();
@ -65,7 +64,7 @@ public class OAuthServiceImpl implements OAuthService {
JSONObject userInfo = HttpUtil.getObj("https://api.github.com/user", header, true);
other.setGithubId(userInfo.getLong("id"));
if (other.getGithubId() == null) {
log.error("github返回异常:{}", userInfo.toString());
log.error("github返回异常:{}", userInfo);
throw new CustomException("登陆异常,请稍后重试");
}
other.setEmail(userInfo.getString("email"));
@ -78,7 +77,7 @@ public class OAuthServiceImpl implements OAuthService {
} else {
throw new CustomException("不支持的登陆方式" + body.getType());
}
User newest = dealOAuth(current, other);
User newest = dealOauth(current, other);
return JwtUtil.encode(Collections.singletonMap("userId", String.valueOf(newest.getUserId())), Constant.jwtSecret
, body.isRememberMe() ? LONG_EXPIRE_TIME : SHORT_EXPIRE_TIME);
}
@ -92,7 +91,7 @@ public class OAuthServiceImpl implements OAuthService {
* @author fanxb
* @date 2021/3/11
**/
private User dealOAuth(User current, User other) {
private User dealOauth(User current, User other) {
if (current == null) {
//判断用户名是否可用
if (userDao.usernameExist(other.getUsername())) {

View File

@ -5,6 +5,10 @@ import com.fanxb.bookmark.business.user.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @author fanxb
* @date 2021/8/20 下午2:15
*/
@Service
public class UserApiImpl implements UserApi {
private final UserDao userDao;

View File

@ -39,6 +39,10 @@ import java.util.concurrent.TimeUnit;
@Service
@Slf4j
public class UserServiceImpl implements UserService {
/**
* 登陆最大重试次数
*/
private static final int LOGIN_COUNT = 5;
private final UserDao userDao;
private final StringRedisTemplate redisTemplate;
@ -115,7 +119,7 @@ public class UserServiceImpl implements UserService {
public String login(LoginBody body) {
String key = RedisConstant.getUserFailCountKey(body.getStr());
String count = redisTemplate.opsForValue().get(key);
if (count != null && Integer.parseInt(count) >= 5) {
if (count != null && Integer.parseInt(count) >= LOGIN_COUNT) {
redisTemplate.expire(key, 30, TimeUnit.MINUTES);
throw new FormDataException("您已连续输错密码5次请30分钟后再试或联系管理员处理");
}

View File

@ -9,7 +9,7 @@ import lombok.Data;
* @date 2021/3/10
**/
@Data
public class OAuthBody {
public class OauthBody {
public static final String GITHUB = "github";
/**
* 类别

View File

@ -0,0 +1,36 @@
package com.fanxb.bookmark.common.controller;
import com.fanxb.bookmark.common.entity.Result;
import com.fanxb.bookmark.common.service.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author fanxb
* @date 2021-09-15-下午9:55
*/
@RestController
@RequestMapping("/common/config")
public class ConfigController {
private final ConfigService configService;
@Autowired
public ConfigController(ConfigService configService) {
this.configService = configService;
}
/**
* 获取全局配置
*
* @return com.fanxb.bookmark.common.entity.Result
* @author fanxb
* @date 2021/9/15 下午9:56
*/
@GetMapping("/global")
public Result getGlobalConfig() {
return Result.success(configService.getGlobalConfig());
}
}

View File

@ -0,0 +1,21 @@
package com.fanxb.bookmark.common.service;
import java.util.Map;
/**
* 全局配置相关
*
* @author fanxb
* @date 2021-09-15-下午9:56
*/
public interface ConfigService {
/**
* 获取全局配置,用户无关是否登陆都能获取
*
* @return java.util.Map<java.lang.String, java.lang.String>
* @author fanxb
* @date 2021/9/15 下午9:58
*/
Map<String, Object> getGlobalConfig();
}

View File

@ -0,0 +1,23 @@
package com.fanxb.bookmark.common.service.impl;
import com.fanxb.bookmark.common.service.ConfigService;
import com.fanxb.bookmark.common.util.HttpUtil;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
/**
* @author fanxb
* @date 2021-09-15-下午9:59
*/
@Service
public class ConfigServiceImpl implements ConfigService {
@Override
public Map<String, Object> getGlobalConfig() {
Map<String, Object> res = new HashMap<>(1);
res.put("proxyExist", HttpUtil.getProxyExist());
return res;
}
}

View File

@ -4,6 +4,7 @@ import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fanxb.bookmark.common.exception.CustomException;
import lombok.Getter;
import okhttp3.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@ -27,15 +28,22 @@ import java.util.concurrent.TimeUnit;
*/
@Component
public class HttpUtil {
/**
* 是否存在代理环境
*/
@Getter
private static Boolean proxyExist = false;
@Value("${proxy.ip}")
private String proxyIp;
@Value("${proxy.port}")
private int proxyPort;
private String proxyPort;
private static final int IP_LENGTH = 15;
/**
* 使用代理环境
* 使用代理环境(如不存在代理配置那么此客户端也是非代理)
*/
private static OkHttpClient PROXY_CLIENT;
/**
@ -49,8 +57,9 @@ public class HttpUtil {
@PostConstruct
public void init() {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
if (StrUtil.isNotBlank(proxyIp)) {
builder.proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyIp, proxyPort)));
if (StrUtil.isNotBlank(proxyIp) && StrUtil.isNotBlank(proxyPort)) {
builder.proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyIp, Integer.parseInt(proxyPort))));
proxyExist = true;
}
PROXY_CLIENT = builder.connectTimeout(10, TimeUnit.SECONDS)
.readTimeout(60, TimeUnit.SECONDS)

View File

@ -0,0 +1,2 @@
INSERT INTO `bookmark`.`url`(`method`, `url`, `type`)
VALUES ('GET', '/common/config/global', 0);

View File

@ -1,6 +1,7 @@
.DS_Store
node_modules
/dist
yarn.lock
# local env files
.env.local

View File

@ -7,6 +7,10 @@
<script>
export default {
name: "App",
async created(){
//
await this.$store.dispatch("globalConfig/refreshServerConfig");
}
};
</script>

View File

@ -2,6 +2,7 @@ import localforage from "localforage";
import HttpUtil from "../../util/HttpUtil";
const USER_INFO = "userInfo";
const TOKEN = "token";
const SERVER_CONFIG = "serverConfig";
/**
* 存储全局配置
@ -22,13 +23,17 @@ const state = {
/**
* 是否移动端
*/
isPhone: false
isPhone: false,
/**
* 服务端全局配置
*/
[SERVER_CONFIG]: {}
};
const getters = {};
const actions = {
//初始化数据
//登陆后的,初始化数据
async init(context) {
if (context.state.isInit) {
return;
@ -64,6 +69,12 @@ const actions = {
context.commit(USER_INFO, null);
context.commit(TOKEN, null);
context.commit("isInit", false);
},
/**
* 从服务器读取全局配置
*/
async refreshServerConfig({ commit }) {
commit(SERVER_CONFIG, await HttpUtil.get("/common/config/global"));
}
};
@ -79,6 +90,9 @@ const mutations = {
},
isPhone(state, status) {
state.isPhone = status;
},
[SERVER_CONFIG](state, serverConfig) {
state[SERVER_CONFIG] = serverConfig;
}
};

View File

@ -36,7 +36,7 @@ const getters = {
};
const actions = {
//从缓存初始化数据
//登陆后的,从缓存初始化数据
async init(context) {
if (context.state.isInit || context.state.isIniting) {
return;

View File

@ -22,6 +22,7 @@ async function request(url, method, params, body, isForm, redirect) {
"jwt-token": vuex.state.globalConfig.token
}
};
//如果是表单类型的请求,添加请求头
if (isForm) {
options.headers["Content-Type"] = "multipart/form-data";
}
@ -40,12 +41,12 @@ async function request(url, method, params, body, isForm, redirect) {
if (code === 1) {
return data;
} else if (code === -1 && redirect) {
// 跳转到登陆页
//未登陆根据redirect参数判断是否需要跳转到登陆页
window.vueInstance.$message.error("您尚未登陆,请先登陆");
router.replace(`/public/login?redirect=${encodeURIComponent(router.currentRoute.fullPath)}`);
throw new Error(message);
} else if (code === 0) {
//通用异常,使用
//通用异常,使用error提示
window.vueInstance.$notification.error({
message: "异常",
description: message

View File

@ -24,7 +24,7 @@
</div>
<div class="thirdPart">
<span>第三方登陆</span>
<a-tooltip title="github登陆" class="oneIcon" placement="bottom">
<a-tooltip v-if="serverConfig.proxyExist" title="github登陆" class="oneIcon" placement="bottom">
<a-icon type="github" @click="toGithub" style="font-size:1.4em" />
</a-tooltip>
</div>
@ -37,13 +37,16 @@
<script>
import Header from "@/components/public/Switch.vue";
import httpUtil from "../../../util/HttpUtil.js";
import { mapMutations } from "vuex";
import { mapMutations ,mapState} from "vuex";
import HttpUtil from "../../../util/HttpUtil.js";
export default {
name: "Login",
components: {
Header,
},
computed:{
...mapState("globalConfig", ["serverConfig"])
},
data() {
return {
form: {

File diff suppressed because it is too large Load Diff