refactor:代码规范修改

This commit is contained in:
fanxb 2021-08-20 14:25:34 +08:00
parent b8baf22387
commit b8f3d4f3b7
24 changed files with 108 additions and 49 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

@ -62,7 +62,8 @@ public interface UserDao {
/**
* Description: 根据用户id查询用户信息
*
* @param userId userId
* @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";
/**
* 类别