1、增加访问数量
2、主页的样式修改 3、头像自定义实现 4、注册修改为自动跳转到登录页面,登录失败友好提示,不进行跳转页面处理 5、博客增加私密的功能
This commit is contained in:
@@ -17,20 +17,22 @@ public interface QuinnConstant {
|
||||
/**
|
||||
* 登录超时时间
|
||||
*/
|
||||
int SESSION_TIME_OUT = 30 * 60;
|
||||
int SESSION_TIME_OUT = 90 * 60;
|
||||
|
||||
String SOURCE_KEY = "SOURCE_KEY_";
|
||||
String SESSION_VIEW_KEY = "NO-ADD";
|
||||
/**
|
||||
* SESSION_ID
|
||||
*/
|
||||
String SESSION_ID = "SESSION_ID_";
|
||||
|
||||
String APPEND_PASSWORD = "wangna&limengqi";
|
||||
String APPEND_PASSWORD = "#append_about";
|
||||
|
||||
String NEW_SOURCE_PASSWORD = "limengqi&wangna";
|
||||
String NEW_SOURCE_PASSWORD = "#upload_source";
|
||||
|
||||
String EDIT_SOURCE_FIRST = "lw@";
|
||||
String EDIT_SOURCE_LAST = "#";
|
||||
String EDIT_SOURCE_FIRST = "#edit@";
|
||||
String EDIT_SOURCE_LAST = "@";
|
||||
|
||||
String DEFAULT_ATTR_BASE64 = "/images/avatar/quinn.png";
|
||||
String DEFAULT_ATTR_BASE64 = "/images/avatar/a1.png";
|
||||
|
||||
String DEFAULT_ATTR = "/images/avatar/a#.png";
|
||||
}
|
||||
|
||||
9
src/main/java/com/quinn/common/QuinnException.java
Normal file
9
src/main/java/com/quinn/common/QuinnException.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package com.quinn.common;
|
||||
|
||||
public class QuinnException extends RuntimeException{
|
||||
|
||||
public QuinnException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,18 +8,8 @@ import org.springframework.security.config.annotation.method.configuration.Enabl
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.security.web.AuthenticationEntryPoint;
|
||||
import org.springframework.security.web.authentication.AuthenticationEntryPointFailureHandler;
|
||||
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
@EnableWebSecurity
|
||||
@EnableGlobalMethodSecurity(prePostEnabled = true)
|
||||
@@ -37,10 +27,12 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
// .permitAll(); //无条件允许访问
|
||||
// 访问权限
|
||||
http.authorizeRequests()
|
||||
.antMatchers("/","/index").permitAll()
|
||||
.antMatchers("/register","/login","/toLogin").permitAll()
|
||||
.antMatchers("/","/index","/favicon.ico").permitAll()
|
||||
.antMatchers("/register","/login","/toLogin","/checkLogin").permitAll()
|
||||
.antMatchers("/source","/source/view/*").permitAll()
|
||||
.antMatchers("/blog","/blog/read/*").permitAll()
|
||||
.antMatchers("/search/**").permitAll()
|
||||
.antMatchers("//about").permitAll()
|
||||
.antMatchers("/hotspot").permitAll()
|
||||
.antMatchers("/blog/**").authenticated()
|
||||
.antMatchers("/source/**").authenticated()
|
||||
@@ -54,7 +46,6 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
.passwordParameter("password")
|
||||
.loginPage("/toLogin")
|
||||
.loginProcessingUrl("/login") // 登陆表单提交请求
|
||||
.failureForwardUrl("/loginError")
|
||||
.defaultSuccessUrl("/index"); // 设置默认登录成功后跳转的页面
|
||||
|
||||
// 注销配置
|
||||
@@ -63,8 +54,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
http.csrf().disable();//关闭csrf功能:跨站请求伪造,默认只能通过post方式提交logout请求
|
||||
http.logout().logoutSuccessUrl("/");
|
||||
|
||||
// 记住我配置
|
||||
http.rememberMe().rememberMeParameter("remember");
|
||||
// 记住我配置 默认为remember-me
|
||||
// http.rememberMe().rememberMeParameter("remember");
|
||||
}
|
||||
|
||||
// 用户授权验证
|
||||
|
||||
@@ -36,7 +36,7 @@ public class Swagger2Config {
|
||||
.title("Quinn-Api")
|
||||
.description("Quinn-Api")
|
||||
.version("1.0")
|
||||
.contact(new Contact("Quinn", "http://quinn.com", "24736743@qq.com"))
|
||||
.contact(new Contact("Quinn", "https://www.qnforever.top", "540344226@qq.com"))
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ public class AboutController extends BaseModelController {
|
||||
return "page/about";
|
||||
}
|
||||
|
||||
@PostMapping("/about")
|
||||
@PostMapping("/about/append")
|
||||
@PreAuthorize("hasAuthority('ADMIN')")
|
||||
public String saveSay(About about){
|
||||
about.setId(QuinnUtils.getUuid());
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.quinn.common.Category;
|
||||
import com.quinn.pojo.*;
|
||||
import com.quinn.service.*;
|
||||
import com.quinn.utils.ContentUtil;
|
||||
import com.quinn.utils.CovertEmojStr;
|
||||
import com.quinn.utils.QuinnUtils;
|
||||
import com.quinn.vo.*;
|
||||
import org.slf4j.Logger;
|
||||
@@ -43,10 +44,10 @@ public class BlogController extends BaseModelController{
|
||||
|
||||
// 列表展示
|
||||
@GetMapping("/blog")
|
||||
public String blogList(Model model){
|
||||
|
||||
public String blogList(HttpServletRequest request,Model model){
|
||||
String loginUserId = getLoginUserId(request);
|
||||
MyPageParam myPageParam = new MyPageParam(1, 10);
|
||||
List<BlogWithUser> blogList = blogService.getBlogWithUserOrderBySort(myPageParam);
|
||||
List<BlogWithUser> blogList = blogService.getBlogWithUserOrderBySort(loginUserId,myPageParam);
|
||||
// 结果
|
||||
model.addAttribute("blogList",blogList);
|
||||
model.addAttribute("pageParam",myPageParam);
|
||||
@@ -62,13 +63,14 @@ public class BlogController extends BaseModelController{
|
||||
}
|
||||
|
||||
@PostMapping("/blog")
|
||||
public String blogListPage(NavReq navReq, Model model){
|
||||
public String blogListPage(HttpServletRequest request,NavReq navReq, Model model){
|
||||
String loginUserId = getLoginUserId(request);
|
||||
// 用户的论坛列表
|
||||
if (navReq.getPageNum() < 1){
|
||||
navReq.setPageNum(1);
|
||||
}
|
||||
MyPageParam myPageParam = new MyPageParam(navReq.getPageNum(),navReq.getLimit());
|
||||
List<BlogWithUser> blogList = blogService.getBlogWithUserOrderBySort(myPageParam);
|
||||
List<BlogWithUser> blogList = blogService.getBlogWithUserOrderBySort(loginUserId,myPageParam);
|
||||
// 结果
|
||||
model.addAttribute("blogList",blogList);
|
||||
model.addAttribute("pageParam",myPageParam);
|
||||
@@ -98,10 +100,10 @@ public class BlogController extends BaseModelController{
|
||||
|
||||
blog.setBid(QuinnUtils.getUuid());
|
||||
blog.setTitle(questionWriteForm.getTitle());
|
||||
blog.setContent(questionWriteForm.getContent());
|
||||
blog.setContent(CovertEmojStr.coverStr(questionWriteForm.getContent()));
|
||||
|
||||
String s = ContentUtil.toTextContentFromWangEdit(questionWriteForm.getContentJson());
|
||||
blog.setContentJson(s);
|
||||
blog.setContentJson(CovertEmojStr.coverStr(s));
|
||||
|
||||
blog.setSort(0);
|
||||
blog.setViews(0);
|
||||
@@ -166,11 +168,10 @@ public class BlogController extends BaseModelController{
|
||||
@PostMapping("/blog/editor")
|
||||
public String editor(Blog blog){
|
||||
Blog queryBlog = blogService.getOne(new QueryWrapper<Blog>().eq("bid", blog.getBid()));
|
||||
|
||||
queryBlog.setTitle(blog.getTitle());
|
||||
queryBlog.setCategoryId(blog.getCategoryId());
|
||||
queryBlog.setContent(blog.getContent());
|
||||
String s = ContentUtil.toTextContentFromWangEdit(blog.getContentJson());
|
||||
queryBlog.setContent(CovertEmojStr.coverStr(blog.getContent()));
|
||||
String s = ContentUtil.toTextContentFromWangEdit(CovertEmojStr.coverStr(blog.getContentJson()));
|
||||
queryBlog.setContentJson(s);
|
||||
queryBlog.setGmtUpdate(QuinnUtils.getTime());
|
||||
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
package com.quinn.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.quinn.common.QuinnException;
|
||||
import com.quinn.common.RoleType;
|
||||
import com.quinn.intergration.AttrIcon;
|
||||
import com.quinn.intergration.SendBMail;
|
||||
import com.quinn.pojo.Invite;
|
||||
import com.quinn.pojo.User;
|
||||
import com.quinn.pojo.UserInfo;
|
||||
import com.quinn.service.InviteService;
|
||||
import com.quinn.service.UserInfoService;
|
||||
import com.quinn.service.UserService;
|
||||
import com.quinn.task.SendAsyncEmail;
|
||||
import com.quinn.utils.AsyncTaskUtil;
|
||||
import com.quinn.utils.QuinnUtils;
|
||||
import com.quinn.vo.CheckLoginForm;
|
||||
import com.quinn.vo.RegisterForm;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
@@ -40,10 +43,22 @@ public class LoginController {
|
||||
return "index";
|
||||
}
|
||||
|
||||
@PostMapping("/loginError")
|
||||
public String error(Model model){
|
||||
model.addAttribute("loginMsg","错误的用户名或者密码!");
|
||||
return "forget";
|
||||
@PostMapping("/checkLogin")
|
||||
public void checkLogin(HttpServletResponse response,CheckLoginForm loginForm) throws IOException {
|
||||
PrintWriter writer = response.getWriter();
|
||||
User user = userService.getOne(new QueryWrapper<User>().eq("username", loginForm.getUsername()));
|
||||
String isOk = "no";
|
||||
if (user != null){
|
||||
// checkPassword
|
||||
String password = user.getPassword();
|
||||
boolean check = new BCryptPasswordEncoder().matches(loginForm.getPassword(),password);
|
||||
if (check){
|
||||
isOk = "ok";
|
||||
}
|
||||
}
|
||||
writer.write(isOk);
|
||||
writer.flush();
|
||||
writer.close();
|
||||
}
|
||||
|
||||
@GetMapping("/toLogin")
|
||||
@@ -57,27 +72,49 @@ public class LoginController {
|
||||
}
|
||||
|
||||
// 注册业务
|
||||
@PostMapping("/register")
|
||||
public String register(HttpServletResponse response,RegisterForm registerForm, Model model) throws IOException {
|
||||
@PostMapping("/checkRegister")
|
||||
public void checkRegister(HttpServletResponse response,RegisterForm registerForm) throws IOException {
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
PrintWriter writer = response.getWriter();
|
||||
// 表单密码重复判断
|
||||
if (!registerForm.getPassword().equals(registerForm.getRepassword())){
|
||||
return toResult(writer,"两次输入密码不一致!");
|
||||
toResult(writer,"两次输入密码不一致!");
|
||||
}
|
||||
// 用户名已存在
|
||||
User hasUser = userService.getOne(new QueryWrapper<User>().eq("username", registerForm.getUsername()));
|
||||
if (hasUser!=null){
|
||||
return toResult(writer,"用户名太热门了,请更换用户名");
|
||||
toResult(writer,"用户名太热门了,请更换用户名");
|
||||
}
|
||||
// 验证邀请码
|
||||
Invite invite = inviteService.getOne(new QueryWrapper<Invite>().eq("code", registerForm.getCode()));
|
||||
if (invite==null){
|
||||
toResult(writer,"注册码不存在!");
|
||||
}
|
||||
if (!invite.getApplyEmail().equals(registerForm.getEmail())){
|
||||
toResult(writer,"请使用申请注册码邮箱注册用户!");
|
||||
}
|
||||
}
|
||||
|
||||
// 注册业务
|
||||
@PostMapping("/register")
|
||||
public String register(RegisterForm registerForm, Model model) throws IOException {
|
||||
// 表单密码重复判断
|
||||
if (!registerForm.getPassword().equals(registerForm.getRepassword())){
|
||||
throw new QuinnException("防爬虫,两次输入密码不一致!");
|
||||
}
|
||||
// 用户名已存在
|
||||
User hasUser = userService.getOne(new QueryWrapper<User>().eq("username", registerForm.getUsername()));
|
||||
if (hasUser!=null){
|
||||
throw new QuinnException("防爬虫,用户名太热门了,请更换用户名");
|
||||
}
|
||||
|
||||
// 验证邀请码
|
||||
Invite invite = inviteService.getOne(new QueryWrapper<Invite>().eq("code", registerForm.getCode()));
|
||||
if (invite==null){
|
||||
return toResult(writer,"注册码不存在!");
|
||||
throw new QuinnException("防爬虫,注册码不存在!");
|
||||
}
|
||||
if (invite.getApplyEmail().equals(registerForm.getEmail())){
|
||||
return toResult(writer,"请使用申请注册码邮箱注册用户!");
|
||||
if (!invite.getApplyEmail().equals(registerForm.getEmail())){
|
||||
throw new QuinnException("防爬虫,请使用申请注册码邮箱注册用户!");
|
||||
}
|
||||
// 构建用户对象
|
||||
User user = new User();
|
||||
@@ -99,16 +136,15 @@ public class LoginController {
|
||||
inviteService.updateById(invite);
|
||||
userInfoService.save(new UserInfo().setUid(user.getUid()).setEmail(registerForm.getEmail()));
|
||||
// 发送注册成功通知邮件
|
||||
SendBMail.INSTANCE.sendWelcome(registerForm.getUsername(),registerForm.getEmail());
|
||||
AsyncTaskUtil.INSTANCE.submit(new SendAsyncEmail(registerForm.getUsername(),registerForm.getEmail()));
|
||||
// 注册成功,重定向到登录页面
|
||||
return "redirect:/toLogin";
|
||||
}
|
||||
|
||||
private String toResult(PrintWriter writer, String msg) {
|
||||
private void toResult(PrintWriter writer, String msg) {
|
||||
writer.write(msg);
|
||||
writer.flush();
|
||||
writer.close();
|
||||
return "register";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ public class SearchController extends BaseModelController{
|
||||
}
|
||||
String loginUserId = getLoginUserId(request);
|
||||
User uid = userService.getOne(new QueryWrapper<User>().eq("uid", loginUserId));
|
||||
if (RoleType.ADMIN.getName().equals(uid.getRole())){
|
||||
if (uid != null && RoleType.ADMIN.getName().equals(uid.getRole())){
|
||||
String result = doAdmin(findWhat, model);
|
||||
if (!QuinnConstant.GUN.equals(result)){
|
||||
return result;
|
||||
|
||||
@@ -138,16 +138,17 @@ public class SourceController extends BaseModelController {
|
||||
* @throws IOException
|
||||
*/
|
||||
@PostMapping("/source/download/{sid}")
|
||||
public void download(HttpServletResponse response, @PathVariable("sid") String sid) throws IOException {
|
||||
public void download(HttpServletRequest request,HttpServletResponse response, @PathVariable("sid") String sid) throws IOException {
|
||||
String sessionId = getSessionId(request);
|
||||
Source source = sourceService.getOne(new QueryWrapper<Source>().eq("sid", sid));
|
||||
if (source!=null){
|
||||
if (SourceType.OSS.name().equals(source.getSourceType())){
|
||||
//通知浏览器以附件形式下载
|
||||
response.setHeader("Content-Disposition",
|
||||
"attachment;filename=" + source.getEnName() + QuinnConstant.LINK_SUFFIX + source.getFileType());
|
||||
this.sourceService.downloadSource(response,source);
|
||||
sourceService.downloadSource(response,source,sessionId);
|
||||
}else {
|
||||
this.sourceService.downloadForBaidu(response,source);
|
||||
sourceService.downloadForBaidu(response,source,sessionId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,22 @@ public enum AttrIcon {
|
||||
INSTANCE;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
* 用户名 使用第三方生成工具
|
||||
* @param name
|
||||
*/
|
||||
public String generateThirdUrl(String name) {
|
||||
String attrUrl = "https://api.multiavatar.com/";
|
||||
return attrUrl + name + ".png";
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户名 为提高效率,使用本地生成工具算法
|
||||
* @param name
|
||||
*/
|
||||
public String generateImgUrl(String name) {
|
||||
String attrUrl = "https://api.multiavatar.com/";
|
||||
return attrUrl + name + ".png";
|
||||
int num = name.hashCode();
|
||||
int index = num % 15;
|
||||
return QuinnConstant.DEFAULT_ATTR.replace("#",index + "");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,9 +49,4 @@ public enum AttrIcon {
|
||||
return QuinnConstant.DEFAULT_ATTR_BASE64;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String limengqi = AttrIcon.INSTANCE.generateImg("limengqi");
|
||||
System.out.println(limengqi);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,9 +19,9 @@ public interface BlogMapper extends BaseMapper<Blog> {
|
||||
|
||||
List<Blog> getTopBlog();
|
||||
|
||||
List<BlogWithUser> getBlogWithUserOrderBySort(MyPageParam myPageParam);
|
||||
int getBlogWithUserOrderBySortCount(String userId);
|
||||
|
||||
List<BlogWithUser> getBlogWithUser(MyPageParam myPageParam);
|
||||
List<BlogWithUser> getBlogWithUserOrderBySort(String userId,MyPageParam myPageParam);
|
||||
|
||||
List<BlogWithUser> getMyBlogs(String userId,MyPageParam myPageParam);
|
||||
}
|
||||
|
||||
@@ -9,22 +9,21 @@
|
||||
order by (views + star) desc limit 7
|
||||
</select>
|
||||
|
||||
<select id="getBlogWithUserOrderBySort" parameterType="com.quinn.vo.MyPageParam" resultType="com.quinn.pojo.BlogWithUser">
|
||||
select a.id,a.bid,a.title,a.sort,a.views,a.author_id,a.category_id,a.category_name,a.gmt_create,a.gmt_update
|
||||
,b.username,b.avatar,
|
||||
(select count(1) from qn_star c where c.topic_id = a.bid and c.topic_category = 'BLOG') as star
|
||||
from qn_blog a,qn_user b
|
||||
where a.author_id = b.uid order by a.sort desc,a.gmt_create desc
|
||||
limit #{pageNum},#{size}
|
||||
<select id="getBlogWithUserOrderBySortCount" resultType="int">
|
||||
select count(1)
|
||||
from qn_blog a
|
||||
where (case when a.category_id = '1' then a.author_id = #{userId} else 1 end)
|
||||
</select>
|
||||
|
||||
<select id="getBlogWithUser" parameterType="com.quinn.vo.MyPageParam" resultType="com.quinn.pojo.BlogWithUser">
|
||||
<select id="getBlogWithUserOrderBySort" resultType="com.quinn.pojo.BlogWithUser">
|
||||
select a.id,a.bid,a.title,a.sort,a.views,a.author_id,a.category_id,a.category_name,a.gmt_create,a.gmt_update
|
||||
,b.username,b.avatar,
|
||||
(select count(1) from qn_star c where c.topic_id = a.bid and c.topic_category = 'BLOG') as star
|
||||
from qn_blog a,qn_user b
|
||||
where a.author_id = b.uid order by a.gmt_create desc
|
||||
limit #{pageNum},#{size}
|
||||
where a.author_id = b.uid
|
||||
and (case when a.category_id = '1' then a.author_id = #{userId} else 1 end)
|
||||
order by a.sort desc,a.gmt_create desc
|
||||
limit #{myPageParam.pageNum},#{myPageParam.size}
|
||||
</select>
|
||||
|
||||
<select id="getMyBlogs" resultType="com.quinn.pojo.BlogWithUser">
|
||||
|
||||
@@ -20,9 +20,7 @@ public interface BlogService extends IService<Blog> {
|
||||
|
||||
List<Blog> getTopBlog();
|
||||
|
||||
List<BlogWithUser> getBlogWithUserOrderBySort(MyPageParam myPageParam);
|
||||
|
||||
List<BlogWithUser> getBlogWithUser(MyPageParam myPageParam);
|
||||
List<BlogWithUser> getBlogWithUserOrderBySort(String userId,MyPageParam myPageParam);
|
||||
|
||||
List<BlogWithUser> getMyBlogs(String userId,MyPageParam myPageParam);
|
||||
|
||||
|
||||
@@ -31,9 +31,9 @@ public interface SourceService extends IService<Source> {
|
||||
* @param source
|
||||
* @throws IOException
|
||||
*/
|
||||
void downloadSource(HttpServletResponse response, Source source) throws IOException;
|
||||
void downloadSource(HttpServletResponse response, Source source,String sessionId) throws IOException;
|
||||
|
||||
void downloadForBaidu(HttpServletResponse response, Source source) throws IOException;
|
||||
void downloadForBaidu(HttpServletResponse response, Source source,String sessionId) throws IOException;
|
||||
|
||||
/**
|
||||
* 点击对应的资源
|
||||
|
||||
@@ -28,6 +28,8 @@ import java.util.List;
|
||||
public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements BlogService {
|
||||
@Resource
|
||||
BlogMapper blogMapper;
|
||||
@Resource
|
||||
RedisUtils redisUtils;
|
||||
|
||||
@Override
|
||||
public List<Blog> getTopBlog(){
|
||||
@@ -41,17 +43,10 @@ public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements Bl
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlogWithUser> getBlogWithUserOrderBySort(MyPageParam myPageParam) {
|
||||
int count = count(null);
|
||||
public List<BlogWithUser> getBlogWithUserOrderBySort(String userId,MyPageParam myPageParam) {
|
||||
int count = blogMapper.getBlogWithUserOrderBySortCount(userId);
|
||||
myPageParam.setTotal(count);
|
||||
return blogMapper.getBlogWithUserOrderBySort(myPageParam);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlogWithUser> getBlogWithUser(MyPageParam myPageParam) {
|
||||
int count = count(null);
|
||||
myPageParam.setTotal(count);
|
||||
return blogMapper.getBlogWithUser(myPageParam);
|
||||
return blogMapper.getBlogWithUserOrderBySort(userId,myPageParam);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -63,8 +58,12 @@ public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements Bl
|
||||
|
||||
@Override
|
||||
public void addRecord(Blog blog, String sessionId) {
|
||||
blog.setViews(blog.getViews()+1);
|
||||
updateById(blog);
|
||||
String value = redisUtils.get(sessionId + blog.getBid());
|
||||
if (!QuinnConstant.SESSION_VIEW_KEY.equals(value)){
|
||||
blog.setViews(blog.getViews()+1);
|
||||
redisUtils.set(sessionId + blog.getBid(),QuinnConstant.SESSION_VIEW_KEY,QuinnConstant.SESSION_TIME_OUT);
|
||||
updateById(blog);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,10 +10,7 @@ import com.quinn.pojo.SourceCategory;
|
||||
import com.quinn.pojo.SourceWithStar;
|
||||
import com.quinn.service.SourceService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.quinn.utils.ContentUtil;
|
||||
import com.quinn.utils.OSSClientUtil;
|
||||
import com.quinn.utils.QuinnUtils;
|
||||
import com.quinn.utils.RedisUtils;
|
||||
import com.quinn.utils.*;
|
||||
import com.quinn.vo.MyPageParam;
|
||||
import com.quinn.vo.QuerySource;
|
||||
import com.quinn.vo.SourceUpdateForm;
|
||||
@@ -52,9 +49,9 @@ public class SourceServiceImpl extends ServiceImpl<SourceMapper, Source> impleme
|
||||
SourceMapper sourceMapper;
|
||||
|
||||
@Override
|
||||
public void downloadSource(HttpServletResponse response, Source source) throws IOException {
|
||||
public void downloadSource(HttpServletResponse response, Source source,String sessionId) throws IOException {
|
||||
String sourceLink = source.getSourceLink();
|
||||
addDownLoadRecord(source);
|
||||
addDownLoadRecord(source,sessionId);
|
||||
// 读取文件内容。
|
||||
BufferedInputStream in = new BufferedInputStream(ossClientUtil.downloadFile(sourceLink));
|
||||
BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());
|
||||
@@ -73,8 +70,8 @@ public class SourceServiceImpl extends ServiceImpl<SourceMapper, Source> impleme
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadForBaidu(HttpServletResponse response, Source source) throws IOException {
|
||||
addDownLoadRecord(source);
|
||||
public void downloadForBaidu(HttpServletResponse response, Source source,String sessionId) throws IOException {
|
||||
addDownLoadRecord(source,sessionId);
|
||||
PrintWriter writer = response.getWriter();
|
||||
writer.write(source.getSourceLink());
|
||||
writer.flush();
|
||||
@@ -84,7 +81,7 @@ public class SourceServiceImpl extends ServiceImpl<SourceMapper, Source> impleme
|
||||
@Override
|
||||
public Source view(String sid,String sessionId) {
|
||||
Source source = getOne(new QueryWrapper<Source>().eq("sid", sid));
|
||||
addDownLoadRecord(source);
|
||||
addDownLoadRecord(source,sessionId);
|
||||
return source;
|
||||
}
|
||||
|
||||
@@ -105,9 +102,9 @@ public class SourceServiceImpl extends ServiceImpl<SourceMapper, Source> impleme
|
||||
source.setEnName(sourceWriteForm.getEnName());
|
||||
source.setFileType(fileType);
|
||||
source.setSourceName(sourceWriteForm.getTitle());
|
||||
source.setDetail(sourceWriteForm.getSubContent());
|
||||
source.setDetail(CovertEmojStr.coverStr(sourceWriteForm.getSubContent()));
|
||||
source.setSourceContent(sourceWriteForm.getContent());
|
||||
String s = ContentUtil.toTextContentFromWangEdit(sourceWriteForm.getContentJson());
|
||||
String s = ContentUtil.toTextContentFromWangEdit(CovertEmojStr.coverStr(sourceWriteForm.getContentJson()));
|
||||
sourceWriteForm.setContentJson(s);
|
||||
source.setSourceType(sourceWriteForm.getSourceType());
|
||||
source.setSourceLink(fileLink);
|
||||
@@ -143,8 +140,8 @@ public class SourceServiceImpl extends ServiceImpl<SourceMapper, Source> impleme
|
||||
before.setFileType(fileType);
|
||||
before.setSourceName(sourceUpdateForm.getSourceName());
|
||||
before.setDetail(sourceUpdateForm.getDetail());
|
||||
before.setSourceContent(sourceUpdateForm.getSourceContent());
|
||||
String s = ContentUtil.toTextContentFromWangEdit(sourceUpdateForm.getContentJson());
|
||||
before.setSourceContent(CovertEmojStr.coverStr(sourceUpdateForm.getSourceContent()));
|
||||
String s = ContentUtil.toTextContentFromWangEdit(CovertEmojStr.coverStr(sourceUpdateForm.getContentJson()));
|
||||
before.setContentJson(s);
|
||||
before.setSourceType(sourceUpdateForm.getSourceType());
|
||||
before.setSourceLink(fileLink);
|
||||
@@ -189,23 +186,20 @@ public class SourceServiceImpl extends ServiceImpl<SourceMapper, Source> impleme
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新页码
|
||||
* 更新热度
|
||||
* @param source
|
||||
*/
|
||||
private void addDownLoadRecord(Source source) {
|
||||
private void addDownLoadRecord(Source source,String sessionId) {
|
||||
/** 使用redis记录访问量可以降低数据库压力,但是时效性就会降低,
|
||||
* 需要不断跑批处理,用户量小或者单实例不推荐这么做
|
||||
* 我们此处是为了实现session级别不能恶意刷热度
|
||||
*/
|
||||
// int downTimes = 0;
|
||||
// if (StringUtils.isEmpty(downLoadTime)){
|
||||
// downTimes = source.getDownRecord() + 1;
|
||||
// }else {
|
||||
// downTimes = Integer.parseInt(downLoadTime) + 1;
|
||||
// }
|
||||
int downTimes = source.getDownRecord() + 1;
|
||||
redisUtils.set(QuinnConstant.SOURCE_KEY + source.getSid(),downTimes + "");
|
||||
source.setDownRecord(source.getDownRecord() + 1);
|
||||
updateById(source);
|
||||
String value = redisUtils.get(sessionId + source.getSid());
|
||||
if (!QuinnConstant.SESSION_VIEW_KEY.equals(value)){
|
||||
source.setDownRecord(source.getDownRecord() + 1);
|
||||
redisUtils.set(sessionId + source.getSid(),QuinnConstant.SESSION_VIEW_KEY,QuinnConstant.SESSION_TIME_OUT);
|
||||
updateById(source);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
22
src/main/java/com/quinn/task/SendAsyncEmail.java
Normal file
22
src/main/java/com/quinn/task/SendAsyncEmail.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package com.quinn.task;
|
||||
|
||||
import com.quinn.intergration.SendBMail;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SendAsyncEmail implements Runnable{
|
||||
|
||||
String username;
|
||||
|
||||
String email;
|
||||
|
||||
public SendAsyncEmail(String username, String email) {
|
||||
this.username = username;
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
SendBMail.INSTANCE.sendWelcome(username,email);
|
||||
}
|
||||
}
|
||||
@@ -1,52 +1,17 @@
|
||||
package com.quinn.task;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.quinn.common.QuinnConstant;
|
||||
import com.quinn.pojo.Source;
|
||||
import com.quinn.service.SourceService;
|
||||
import com.quinn.utils.RedisUtils;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author limqsh
|
||||
*/
|
||||
@Component
|
||||
//@Component
|
||||
public class UpdateViewTask {
|
||||
|
||||
@Resource
|
||||
SourceService sourceService;
|
||||
|
||||
@Resource
|
||||
RedisUtils redisUtils;
|
||||
|
||||
/**
|
||||
* 每小时执行一次
|
||||
*/
|
||||
@Scheduled(cron = "0 0 */1 * * ?")
|
||||
// @Scheduled(cron = "0 0 */1 * * ?")
|
||||
public void execute(){
|
||||
List<String> keys = redisUtils.scan(QuinnConstant.SOURCE_KEY);
|
||||
// List<Source> list = sourceService.list(null);
|
||||
if (!CollectionUtils.isEmpty(keys)){
|
||||
keys.forEach(x->{
|
||||
Source source = sourceService.getById(getIdFromKey(x,QuinnConstant.SOURCE_KEY));
|
||||
if (source != null && !StringUtils.isEmpty(source.getSourceName())){
|
||||
source.setDownRecord(Integer.parseInt(redisUtils.get(x)));
|
||||
sourceService.updateById(source);
|
||||
redisUtils.del(x);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private String getIdFromKey(String key,String keyType){
|
||||
return key.substring(keyType.length());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
16
src/main/java/com/quinn/utils/AsyncTaskUtil.java
Normal file
16
src/main/java/com/quinn/utils/AsyncTaskUtil.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package com.quinn.utils;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public enum AsyncTaskUtil {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
ExecutorService executorService = Executors.newCachedThreadPool();
|
||||
|
||||
public void submit(Runnable runnable){
|
||||
executorService.submit(runnable);
|
||||
}
|
||||
|
||||
}
|
||||
12
src/main/java/com/quinn/utils/CovertEmojStr.java
Normal file
12
src/main/java/com/quinn/utils/CovertEmojStr.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package com.quinn.utils;
|
||||
|
||||
import com.github.binarywang.java.emoji.EmojiConverter;
|
||||
|
||||
public class CovertEmojStr {
|
||||
|
||||
public static String coverStr(String before){
|
||||
EmojiConverter emojiConverter = EmojiConverter.getInstance();
|
||||
return emojiConverter.toHtml(before);
|
||||
}
|
||||
|
||||
}
|
||||
19
src/main/java/com/quinn/vo/CheckLoginForm.java
Normal file
19
src/main/java/com/quinn/vo/CheckLoginForm.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package com.quinn.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
public class CheckLoginForm {
|
||||
|
||||
@ApiModelProperty(value = "用户名")
|
||||
private String username;
|
||||
|
||||
@ApiModelProperty(value = "密码")
|
||||
private String password;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user