全局搜索,我们把全局搜索提供,需要博客和资源修改新增的时候同步Context的文本
This commit is contained in:
8
src/main/java/com/quinn/common/EditText.java
Normal file
8
src/main/java/com/quinn/common/EditText.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package com.quinn.common;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class EditText {
|
||||
String text;
|
||||
}
|
||||
@@ -18,17 +18,12 @@ public interface QuinnConstant {
|
||||
* 登录超时时间
|
||||
*/
|
||||
int SESSION_TIME_OUT = 30 * 60;
|
||||
String SESSION_LOCK = "LOCK";
|
||||
|
||||
String SOURCE_KEY = "SOURCE_KEY_";
|
||||
/**
|
||||
* SESSION_ID
|
||||
*/
|
||||
String SESSION_ID = "SESSION_ID_";
|
||||
/**
|
||||
* PASSWORD //TODO 可以配置数据库MD5加密
|
||||
*/
|
||||
String SOURCE_PASSWORD = "926462";
|
||||
|
||||
String APPEND_PASSWORD = "wangna&limengqi";
|
||||
|
||||
|
||||
@@ -1,16 +1,49 @@
|
||||
package com.quinn.common;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* 排名不分先后,篮球迷勿喷
|
||||
*/
|
||||
public enum RoleType {
|
||||
/**
|
||||
* 管理员
|
||||
*/
|
||||
ADMIN,
|
||||
/**
|
||||
* 普通用户
|
||||
*/
|
||||
NORMAL,
|
||||
ADMIN("KOBE"),
|
||||
/**
|
||||
* VIP
|
||||
*/
|
||||
VIP
|
||||
VIP("VIP"),
|
||||
/**
|
||||
* 普通用户
|
||||
*/
|
||||
NORMAL("NORMAL");
|
||||
|
||||
String name;
|
||||
|
||||
RoleType(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据库存的权限是 KOBE VIP NORMAL
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public static RoleType parse(String name){
|
||||
if (StringUtils.isEmpty(name)){
|
||||
if (ADMIN.getName().equals(name)){
|
||||
return RoleType.ADMIN;
|
||||
}
|
||||
if (VIP.getName().equals(name)){
|
||||
return RoleType.VIP;
|
||||
}
|
||||
}
|
||||
return RoleType.NORMAL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
14
src/main/java/com/quinn/common/WangEdit.java
Normal file
14
src/main/java/com/quinn/common/WangEdit.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package com.quinn.common;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class WangEdit {
|
||||
|
||||
String type;
|
||||
|
||||
List<EditText> children;
|
||||
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import com.quinn.service.impl.UserServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
||||
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;
|
||||
@@ -11,6 +12,7 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
|
||||
@EnableWebSecurity
|
||||
@EnableGlobalMethodSecurity(prePostEnabled = true)
|
||||
public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -3,18 +3,15 @@ package com.quinn.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.quinn.common.RoleType;
|
||||
import com.quinn.pojo.About;
|
||||
import com.quinn.pojo.User;
|
||||
import com.quinn.service.AboutService;
|
||||
import com.quinn.service.UserService;
|
||||
import com.quinn.utils.QuinnUtils;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.management.relation.Role;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
@@ -31,9 +28,6 @@ public class AboutController extends BaseModelController {
|
||||
|
||||
@Resource
|
||||
AboutService aboutService;
|
||||
@Resource
|
||||
UserService userService;
|
||||
|
||||
|
||||
@GetMapping("/about")
|
||||
public String userIndexBlog(HttpServletRequest request,Model model){
|
||||
@@ -48,13 +42,8 @@ public class AboutController extends BaseModelController {
|
||||
}
|
||||
|
||||
@PostMapping("/about")
|
||||
public String saveSay(HttpServletRequest request, About about){
|
||||
String loginUserId = getLoginUserId(request);
|
||||
User user = userService.getOne(new QueryWrapper<User>().eq("uid", loginUserId));
|
||||
// 防止请求提交
|
||||
if (!RoleType.ADMIN.name().equals(user)){
|
||||
return "redirect:/about";
|
||||
}
|
||||
@PreAuthorize("hasAuthority('ADMIN')")
|
||||
public String saveSay(About about){
|
||||
about.setId(QuinnUtils.getUuid());
|
||||
about.setGmtCreate(QuinnUtils.getTime());
|
||||
// 结果
|
||||
@@ -62,6 +51,5 @@ public class AboutController extends BaseModelController {
|
||||
return "redirect:/about";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.quinn.common.Category;
|
||||
import com.quinn.pojo.*;
|
||||
import com.quinn.service.*;
|
||||
import com.quinn.utils.ContentUtil;
|
||||
import com.quinn.utils.QuinnUtils;
|
||||
import com.quinn.vo.*;
|
||||
import org.slf4j.Logger;
|
||||
@@ -98,6 +99,10 @@ public class BlogController extends BaseModelController{
|
||||
blog.setBid(QuinnUtils.getUuid());
|
||||
blog.setTitle(questionWriteForm.getTitle());
|
||||
blog.setContent(questionWriteForm.getContent());
|
||||
|
||||
String s = ContentUtil.toTextContentFromWangEdit(questionWriteForm.getContentJson());
|
||||
blog.setContentJson(s);
|
||||
|
||||
blog.setSort(0);
|
||||
blog.setViews(0);
|
||||
|
||||
@@ -165,6 +170,8 @@ public class BlogController extends BaseModelController{
|
||||
queryBlog.setTitle(blog.getTitle());
|
||||
queryBlog.setCategoryId(blog.getCategoryId());
|
||||
queryBlog.setContent(blog.getContent());
|
||||
String s = ContentUtil.toTextContentFromWangEdit(blog.getContentJson());
|
||||
queryBlog.setContentJson(s);
|
||||
queryBlog.setGmtUpdate(QuinnUtils.getTime());
|
||||
|
||||
blogService.updateById(queryBlog);
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.quinn.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.quinn.common.RoleType;
|
||||
import com.quinn.intergration.AttrIcon;
|
||||
import com.quinn.pojo.Invite;
|
||||
import com.quinn.pojo.User;
|
||||
import com.quinn.pojo.UserInfo;
|
||||
@@ -78,10 +79,11 @@ public class LoginController {
|
||||
// 构建用户对象
|
||||
User user = new User();
|
||||
user.setUid(QuinnUtils.getUuid()); // 用户唯一id
|
||||
user.setRoleId(RoleType.NORMAL.name());
|
||||
user.setRole(RoleType.NORMAL.name());
|
||||
user.setUsername(registerForm.getUsername());
|
||||
// 密码加密
|
||||
String bCryptPassword = new BCryptPasswordEncoder().encode(registerForm.getPassword());
|
||||
user.setAvatar(AttrIcon.INSTANCE.generateImgUrl(registerForm.getUsername()));
|
||||
user.setPassword(bCryptPassword);
|
||||
user.setGmtCreate(QuinnUtils.getTime());
|
||||
user.setLoginDate(QuinnUtils.getTime());
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -36,29 +37,42 @@ public class SearchController {
|
||||
CommentService commentService;
|
||||
@Resource
|
||||
SourceCategoryService sourceCategoryService;
|
||||
@Resource
|
||||
FindService findService;
|
||||
|
||||
@PostMapping("/search")
|
||||
@GetMapping("/search")
|
||||
public String searchAll(String findWhat,Model model){
|
||||
/**
|
||||
* 为空返回主页
|
||||
*/
|
||||
if (StringUtils.isEmpty(findWhat)){
|
||||
return "index";
|
||||
}
|
||||
/**
|
||||
* 新增资源
|
||||
*/
|
||||
if (QuinnConstant.NEW_SOURCE_PASSWORD.equals(findWhat)){
|
||||
List<SourceCategory> categoryList = sourceCategoryService.list(null);
|
||||
model.addAttribute("categoryList",categoryList);
|
||||
return "source/uploadSource";
|
||||
}
|
||||
/**
|
||||
* 新增公告
|
||||
*/
|
||||
if (QuinnConstant.APPEND_PASSWORD.equals(findWhat)){
|
||||
return "page/append";
|
||||
}
|
||||
/**
|
||||
* 修改资源
|
||||
*/
|
||||
if (findWhat.startsWith(QuinnConstant.EDIT_SOURCE_FIRST)){
|
||||
findWhat = findWhat.substring(findWhat.indexOf(QuinnConstant.EDIT_SOURCE_FIRST) + QuinnConstant.EDIT_SOURCE_FIRST.length());
|
||||
if (!StringUtils.isEmpty(findWhat) && findWhat.endsWith(QuinnConstant.EDIT_SOURCE_LAST)){
|
||||
findWhat = findWhat.substring(0,findWhat.lastIndexOf(QuinnConstant.EDIT_SOURCE_LAST));
|
||||
String modifyWhat = findWhat.substring(findWhat.indexOf(QuinnConstant.EDIT_SOURCE_FIRST) + QuinnConstant.EDIT_SOURCE_FIRST.length());
|
||||
if (!StringUtils.isEmpty(modifyWhat) && modifyWhat.endsWith(QuinnConstant.EDIT_SOURCE_LAST)){
|
||||
modifyWhat = modifyWhat.substring(0,modifyWhat.lastIndexOf(QuinnConstant.EDIT_SOURCE_LAST));
|
||||
}
|
||||
if (!StringUtils.isEmpty(findWhat)){
|
||||
Source source = sourceService.getOne(new QueryWrapper<Source>().eq("sid", findWhat));
|
||||
Source source = sourceService.getOne(new QueryWrapper<Source>().eq("sid", modifyWhat));
|
||||
if (source!=null){
|
||||
source.setKeyWord1(concatKeyWord(source.getKeyWord2()) + concatKeyWord(source.getKeyWord2()) + concatKeyWord(source.getKeyWord3()));
|
||||
model.addAttribute("source",source);
|
||||
// 分类信息
|
||||
List<SourceCategory> categoryList = sourceCategoryService.list(null);
|
||||
@@ -67,28 +81,20 @@ public class SearchController {
|
||||
}
|
||||
}
|
||||
}
|
||||
//TODO
|
||||
|
||||
/**
|
||||
* 正式开始,全局搜索
|
||||
*/
|
||||
MyPageParam myPageParam = new MyPageParam(1, 10);
|
||||
List<BlogWithUser> blogList = blogService.getBlogWithUserOrderBySort(myPageParam);
|
||||
List<FindResult> findList = findService.listFinds(findWhat, myPageParam);
|
||||
model.addAttribute("findWhat",findWhat);
|
||||
// 结果
|
||||
model.addAttribute("blogList",blogList);
|
||||
model.addAttribute("findList",findList);
|
||||
model.addAttribute("pageParam",myPageParam);
|
||||
|
||||
List<Blog> topBlogList = blogService.getTopBlog();
|
||||
model.addAttribute("topBlogList",topBlogList);
|
||||
|
||||
// 分类信息
|
||||
List<BlogCategory> categoryList = blogCategoryService.list(null);
|
||||
model.addAttribute("categoryList",categoryList);
|
||||
return "page/allsearch";
|
||||
}
|
||||
|
||||
private String concatKeyWord(String keyWord) {
|
||||
if (!StringUtils.isEmpty(keyWord)) {
|
||||
return keyWord + QuinnConstant.LINK_KEY_WORD;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -91,9 +91,6 @@ public class SourceController extends BaseModelController {
|
||||
if (!CollectionUtils.isEmpty(sourceList)){
|
||||
sourceList.forEach(x ->{
|
||||
x.setSourceLink(QuinnConstant.GUN);
|
||||
x.setKeyWord1(QuinnConstant.GUN);
|
||||
x.setKeyWord2(QuinnConstant.GUN);
|
||||
x.setKeyWord3(QuinnConstant.GUN);
|
||||
x.setSourceContent(QuinnConstant.GUN);
|
||||
});
|
||||
}
|
||||
@@ -114,9 +111,6 @@ public class SourceController extends BaseModelController {
|
||||
Source source = sourceService.view(sid,sessionId);
|
||||
if(source != null){
|
||||
source.setSourceLink(QuinnConstant.GUN);
|
||||
source.setKeyWord1(QuinnConstant.GUN);
|
||||
source.setKeyWord2(QuinnConstant.GUN);
|
||||
source.setKeyWord3(QuinnConstant.GUN);
|
||||
}
|
||||
model.addAttribute("source",source);
|
||||
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
package com.quinn.controller;
|
||||
|
||||
|
||||
import com.quinn.common.QuinnConstant;
|
||||
import com.quinn.service.SourceCategoryService;
|
||||
import com.quinn.service.SourceService;
|
||||
import com.quinn.vo.SourceDeleteForm;
|
||||
import com.quinn.vo.SourceUpdateForm;
|
||||
import com.quinn.vo.SourceWriteForm;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -25,49 +22,32 @@ import java.io.PrintWriter;
|
||||
* @since 2022-05-03
|
||||
*/
|
||||
@Controller
|
||||
@PreAuthorize("hasAuthority('ADMIN')")
|
||||
public class SourceUploadController {
|
||||
|
||||
@Resource
|
||||
SourceCategoryService sourceCategoryService;
|
||||
@Resource
|
||||
SourceService sourceService;
|
||||
|
||||
@PostMapping("/tracy/mcgrady/lmq/love/wn")
|
||||
@PostMapping("/source/oper")
|
||||
public synchronized String write(MultipartFile file, SourceWriteForm sourceWriteForm) throws IOException {
|
||||
if (!QuinnConstant.SOURCE_PASSWORD.equals(sourceWriteForm.getUploadPassWord())){
|
||||
return "error/check";
|
||||
}
|
||||
sourceService.uploadNewSource(file,sourceWriteForm);
|
||||
// 重定向到列表页面
|
||||
return "redirect:/source";
|
||||
}
|
||||
|
||||
// 编辑信息
|
||||
@PostMapping("/tracy/mcgrady/lmq/love/wn/update")
|
||||
@PostMapping("/source/oper/update")
|
||||
public String toEdit(MultipartFile file, SourceUpdateForm sourceUpdateForm) throws IOException {
|
||||
if (!QuinnConstant.SOURCE_PASSWORD.equals(sourceUpdateForm.getUploadPassWord())){
|
||||
return "error/check";
|
||||
}
|
||||
sourceService.updateSource(file,sourceUpdateForm);
|
||||
// 重定向详情页面
|
||||
return "redirect:/source/view/" + sourceUpdateForm.getSid();
|
||||
}
|
||||
|
||||
// 编辑信息
|
||||
@PostMapping("/tracy/mcgrady/lmq/love/wn/del")
|
||||
public void toEdit(HttpServletResponse response, SourceDeleteForm sourceDeleteForm) throws IOException {
|
||||
PrintWriter writer = response.getWriter();
|
||||
if (!QuinnConstant.SOURCE_PASSWORD.equals(sourceDeleteForm.getUploadPassWord())){
|
||||
writer.write("/error/check");
|
||||
writer.flush();
|
||||
writer.close();
|
||||
return;
|
||||
}
|
||||
sourceService.deleteSource(sourceDeleteForm.getSid());
|
||||
// 重定向详情页面
|
||||
writer.write("/source");
|
||||
writer.flush();
|
||||
writer.close();
|
||||
// 删除
|
||||
@GetMapping("/source/oper/del/{sid}")
|
||||
public String toDelete(@PathVariable("sid") String sid) {
|
||||
sourceService.deleteSource(sid);
|
||||
// 重定向到列表页面
|
||||
return "redirect:/source";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ public class UserController extends BaseModelController {
|
||||
public String userPageStar(UserNavReq navReq,Model model){
|
||||
// 用户信息回填
|
||||
userInfoCallBack(navReq.getUserId(),model);
|
||||
// 用户的论坛列表
|
||||
// 用户收藏列表
|
||||
if (navReq.getPageNum() < 1){
|
||||
navReq.setPageNum(1);
|
||||
}
|
||||
|
||||
@@ -37,7 +37,8 @@ public class UserInfoController extends BaseModelController {
|
||||
@GetMapping("/userinfo/setting")
|
||||
public String userSetting(HttpServletRequest request, Model model){
|
||||
String uid = getLoginUserId(request);
|
||||
// todo: 可扩展
|
||||
UserInfo userInfo = userInfoService.getById(uid);
|
||||
model.addAttribute("userInfo",userInfo);
|
||||
return "user/settings";
|
||||
}
|
||||
@PostMapping("/userinfo/update")
|
||||
|
||||
@@ -38,4 +38,10 @@ public enum AttrIcon {
|
||||
}
|
||||
return QuinnConstant.DEFAULT_ATTR_BASE64;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String limengqi = AttrIcon.INSTANCE.generateImg("limengqi");
|
||||
System.out.println(limengqi);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
22
src/main/java/com/quinn/mapper/FindMapper.java
Normal file
22
src/main/java/com/quinn/mapper/FindMapper.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package com.quinn.mapper;
|
||||
|
||||
import com.quinn.pojo.FindResult;
|
||||
import com.quinn.vo.MyPageParam;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author limqsh
|
||||
* @since 2022-05-08
|
||||
*/
|
||||
public interface FindMapper {
|
||||
|
||||
int countListFinds(String findWhat);
|
||||
|
||||
List<FindResult> listFinds(String findWhat, MyPageParam myPageParam);
|
||||
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.quinn.mapper.BlogStarMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.quinn.mapper.DownloadMapper">
|
||||
|
||||
</mapper>
|
||||
30
src/main/java/com/quinn/mapper/xml/FindMapper.xml
Normal file
30
src/main/java/com/quinn/mapper/xml/FindMapper.xml
Normal file
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.quinn.mapper.FindMapper">
|
||||
|
||||
<select id="countListFinds" resultType="int">
|
||||
select count(1) from (
|
||||
select 1 from qn_source a
|
||||
where a.source_name like CONCAT('%',#{findWhat},'%')
|
||||
or a.content_json like CONCAT('%',#{findWhat},'%')
|
||||
union all
|
||||
select 1 from qn_blog b
|
||||
where b.title like CONCAT('%',#{findWhat},'%')
|
||||
or b.content_json like CONCAT('%',#{findWhat},'%')
|
||||
) t
|
||||
</select>
|
||||
|
||||
<select id="listFinds" resultType="com.quinn.pojo.FindResult">
|
||||
select * from (
|
||||
select a.sid as topicId,'SOURCE' as category,a.gmt_create as gmtCreate,a.source_name as topicName,a.content_json as contentText from qn_source a
|
||||
where a.source_name like CONCAT('%',#{findWhat},'%')
|
||||
or a.content_json like CONCAT('%',#{findWhat},'%')
|
||||
union all
|
||||
select b.bid as topicId,'BLOG' as category,b.gmt_create as gmtCreate,b.title as topicName,b.content_json as contentText from qn_blog b
|
||||
where b.title like CONCAT('%',#{findWhat},'%')
|
||||
or b.content_json like CONCAT('%',#{findWhat},'%')
|
||||
) t order by gmtCreate
|
||||
limit #{myPageParam.pageNum},#{myPageParam.size}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.quinn.mapper.QuestionCategoryMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.quinn.mapper.QuestionMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.quinn.mapper.SayMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -41,6 +41,9 @@ public class Blog implements Serializable {
|
||||
@ApiModelProperty(value = "论坛内容")
|
||||
private String content;
|
||||
|
||||
@ApiModelProperty(value = "文本论坛内容")
|
||||
private String contentJson;
|
||||
|
||||
@ApiModelProperty(value = "排序 0 普通 1 置顶")
|
||||
private Integer sort;
|
||||
|
||||
|
||||
32
src/main/java/com/quinn/pojo/FindResult.java
Normal file
32
src/main/java/com/quinn/pojo/FindResult.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package com.quinn.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author limqsh
|
||||
* @since 2022-05-08
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
public class FindResult implements Serializable {
|
||||
|
||||
private String topicId;
|
||||
|
||||
private String category;
|
||||
|
||||
private Date gmtCreate;
|
||||
|
||||
private String topicName;
|
||||
|
||||
private String contentText;
|
||||
}
|
||||
@@ -43,14 +43,8 @@ public class Source implements Serializable {
|
||||
@ApiModelProperty(value = "资源内容")
|
||||
private String sourceContent;
|
||||
|
||||
@ApiModelProperty(value = "关键字1")
|
||||
private String keyWord1;
|
||||
|
||||
@ApiModelProperty(value = "关键字2")
|
||||
private String keyWord2;
|
||||
|
||||
@ApiModelProperty(value = "关键字3")
|
||||
private String keyWord3;
|
||||
@ApiModelProperty(value = "文本资源内容")
|
||||
private String contentJson;
|
||||
|
||||
@ApiModelProperty(value = "资源类型")
|
||||
private String sourceType;
|
||||
|
||||
@@ -35,8 +35,8 @@ public class User implements Serializable {
|
||||
@ApiModelProperty(value = "用户编号")
|
||||
private String uid;
|
||||
|
||||
@ApiModelProperty(value = "角色编号")
|
||||
private String roleId;
|
||||
@ApiModelProperty(value = "角色")
|
||||
private String role;
|
||||
|
||||
@ApiModelProperty(value = "用户名")
|
||||
private String username;
|
||||
|
||||
20
src/main/java/com/quinn/service/FindService.java
Normal file
20
src/main/java/com/quinn/service/FindService.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package com.quinn.service;
|
||||
|
||||
import com.quinn.pojo.FindResult;
|
||||
import com.quinn.vo.MyPageParam;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author limqsh
|
||||
* @since 2022-05-08
|
||||
*/
|
||||
public interface FindService {
|
||||
|
||||
List<FindResult> listFinds(String findWhat, MyPageParam myPageParam);
|
||||
|
||||
}
|
||||
@@ -26,9 +26,6 @@ import java.util.List;
|
||||
*/
|
||||
@Service
|
||||
public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements BlogService {
|
||||
|
||||
@Resource
|
||||
RedisUtils redisUtils;
|
||||
@Resource
|
||||
BlogMapper blogMapper;
|
||||
|
||||
@@ -66,12 +63,8 @@ public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements Bl
|
||||
|
||||
@Override
|
||||
public void addRecord(Blog blog, String sessionId) {
|
||||
String value = redisUtils.get(sessionId);
|
||||
if (StringUtils.isEmpty(value)){
|
||||
redisUtils.set(sessionId, QuinnConstant.SESSION_LOCK,QuinnConstant.SESSION_TIME_OUT);
|
||||
blog.setViews(blog.getViews()+1);
|
||||
updateById(blog);
|
||||
}
|
||||
blog.setViews(blog.getViews()+1);
|
||||
updateById(blog);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
36
src/main/java/com/quinn/service/impl/FindServiceImpl.java
Normal file
36
src/main/java/com/quinn/service/impl/FindServiceImpl.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package com.quinn.service.impl;
|
||||
|
||||
import com.quinn.mapper.FindMapper;
|
||||
import com.quinn.pojo.FindResult;
|
||||
import com.quinn.service.FindService;
|
||||
import com.quinn.vo.MyPageParam;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author limqsh
|
||||
* @since 2022-05-08
|
||||
*/
|
||||
@Service
|
||||
public class FindServiceImpl implements FindService {
|
||||
|
||||
@Resource
|
||||
FindMapper findMapper;
|
||||
|
||||
@Override
|
||||
public List<FindResult> listFinds(String findWhat, MyPageParam myPageParam) {
|
||||
int total = findMapper.countListFinds(findWhat);
|
||||
myPageParam.setTotal(total);
|
||||
if (total > 0){
|
||||
return findMapper.listFinds(findWhat,myPageParam);
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
@@ -10,6 +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;
|
||||
@@ -83,11 +84,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));
|
||||
String value = redisUtils.get(sessionId);
|
||||
if (StringUtils.isEmpty(value)){
|
||||
redisUtils.set(sessionId,QuinnConstant.SESSION_LOCK,QuinnConstant.SESSION_TIME_OUT);
|
||||
addDownLoadRecord(source);
|
||||
}
|
||||
addDownLoadRecord(source);
|
||||
return source;
|
||||
}
|
||||
|
||||
@@ -110,19 +107,8 @@ public class SourceServiceImpl extends ServiceImpl<SourceMapper, Source> impleme
|
||||
source.setSourceName(sourceWriteForm.getTitle());
|
||||
source.setDetail(sourceWriteForm.getSubContent());
|
||||
source.setSourceContent(sourceWriteForm.getContent());
|
||||
String keyWords = sourceWriteForm.getKeyWords();
|
||||
if (!StringUtils.isEmpty(keyWords)){
|
||||
//兼容中英文逗号
|
||||
keyWords = keyWords.replaceAll(",",",");
|
||||
String[] split = keyWords.split(QuinnConstant.LINK_KEY_WORD);
|
||||
source.setKeyWord1(split[0]);
|
||||
if (split.length > 1){
|
||||
source.setKeyWord2(split[1]);
|
||||
if (split.length > 2){
|
||||
source.setKeyWord3(split[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
String s = ContentUtil.toTextContentFromWangEdit(sourceWriteForm.getContentJson());
|
||||
sourceWriteForm.setContentJson(s);
|
||||
source.setSourceType(sourceWriteForm.getSourceType());
|
||||
source.setSourceLink(fileLink);
|
||||
|
||||
@@ -158,19 +144,8 @@ public class SourceServiceImpl extends ServiceImpl<SourceMapper, Source> impleme
|
||||
before.setSourceName(sourceUpdateForm.getSourceName());
|
||||
before.setDetail(sourceUpdateForm.getDetail());
|
||||
before.setSourceContent(sourceUpdateForm.getSourceContent());
|
||||
String keyWords = sourceUpdateForm.getKeyWords();
|
||||
if (!StringUtils.isEmpty(keyWords)){
|
||||
//兼容中英文逗号
|
||||
keyWords = keyWords.replaceAll(",",",");
|
||||
String[] split = keyWords.split(QuinnConstant.LINK_KEY_WORD);
|
||||
before.setKeyWord1(split[0]);
|
||||
if (split.length > 1){
|
||||
before.setKeyWord2(split[1]);
|
||||
if (split.length > 2){
|
||||
before.setKeyWord3(split[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
String s = ContentUtil.toTextContentFromWangEdit(sourceUpdateForm.getContentJson());
|
||||
before.setContentJson(s);
|
||||
before.setSourceType(sourceUpdateForm.getSourceType());
|
||||
before.setSourceLink(fileLink);
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -28,8 +27,6 @@ import java.util.List;
|
||||
* @author limqsh
|
||||
* @since 2020-06-28
|
||||
*/
|
||||
// UserDetailsService接口用于返回用户相关数据。
|
||||
// 它有loadUserByUsername()方法,根据username查询用户实体,可以实现该接口覆盖该方法,实现自定义获取用户过程。
|
||||
// 该接口实现类被DaoAuthenticationProvider 类使用,用于认证过程中载入用户信息。
|
||||
@Service
|
||||
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService,UserDetailsService {
|
||||
@@ -58,10 +55,12 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
session.setMaxInactiveInterval(QuinnConstant.SESSION_TIME_OUT);
|
||||
//创建一个集合来存放权限
|
||||
List<GrantedAuthority> authList = new ArrayList<GrantedAuthority>();
|
||||
RoleType[] values = RoleType.values();
|
||||
Arrays.stream(values).forEach(x->{
|
||||
authList.add(new SimpleGrantedAuthority("ROLE_" + x.name()));
|
||||
});
|
||||
RoleType roleType = RoleType.parse(user.getRole());
|
||||
if (roleType == null){
|
||||
roleType = RoleType.NORMAL;
|
||||
}
|
||||
SimpleGrantedAuthority authority = new SimpleGrantedAuthority(roleType.getName());
|
||||
authList.add(authority);
|
||||
//实例化UserDetails对象
|
||||
userDetails=new org.springframework.security.core.userdetails.User(s,password,
|
||||
true,
|
||||
|
||||
26
src/main/java/com/quinn/utils/ContentUtil.java
Normal file
26
src/main/java/com/quinn/utils/ContentUtil.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package com.quinn.utils;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.quinn.common.EditText;
|
||||
import com.quinn.common.WangEdit;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ContentUtil {
|
||||
|
||||
static String toTextContentFromWangEdit(String wangEdit){
|
||||
List<WangEdit> decode = JsonUtils.decode(wangEdit, new TypeReference<List<WangEdit>>(){});
|
||||
StringBuffer sb = new StringBuffer();
|
||||
decode.forEach(x->{
|
||||
List<EditText> children = x.getChildren();
|
||||
if (!CollectionUtils.isEmpty(children)){
|
||||
children.forEach(y ->{
|
||||
sb.append(y.getText());
|
||||
});
|
||||
}
|
||||
});
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
94
src/main/java/com/quinn/utils/JsonUtils.java
Normal file
94
src/main/java/com/quinn/utils/JsonUtils.java
Normal file
@@ -0,0 +1,94 @@
|
||||
package com.quinn.utils;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerationException;
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* USER: douya
|
||||
* DATE: 2017-11-01
|
||||
*/
|
||||
public class JsonUtils {
|
||||
|
||||
|
||||
/**
|
||||
* Logger for this class
|
||||
*/
|
||||
private static final Logger logger = LoggerFactory.getLogger(JsonUtils.class);
|
||||
|
||||
private final static ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
static {
|
||||
objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
|
||||
objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
|
||||
objectMapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
|
||||
objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
|
||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
}
|
||||
|
||||
private JsonUtils() {
|
||||
}
|
||||
|
||||
public static String encode(Object obj) {
|
||||
try {
|
||||
return objectMapper.writeValueAsString(obj);
|
||||
} catch (JsonGenerationException e) {
|
||||
logger.error("encode(Object)", e); //$NON-NLS-1$
|
||||
} catch (JsonMappingException e) {
|
||||
logger.error("encode(Object)", e); //$NON-NLS-1$
|
||||
} catch (IOException e) {
|
||||
logger.error("encode(Object)", e); //$NON-NLS-1$
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将json string反序列化成对象
|
||||
*
|
||||
* @param json
|
||||
* @param valueType
|
||||
* @return
|
||||
*/
|
||||
public static <T> T decode(String json, Class<T> valueType) {
|
||||
try {
|
||||
return objectMapper.readValue(json, valueType);
|
||||
} catch (JsonParseException e) {
|
||||
logger.error("decode(String, Class<T>)", e);
|
||||
} catch (JsonMappingException e) {
|
||||
logger.error("decode(String, Class<T>)", e);
|
||||
} catch (IOException e) {
|
||||
logger.error("decode(String, Class<T>)", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将json array反序列化为对象
|
||||
*
|
||||
* @param json
|
||||
* @param typeReference
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T decode(String json, TypeReference<T> typeReference) {
|
||||
try {
|
||||
return (T) objectMapper.readValue(json, typeReference);
|
||||
} catch (JsonParseException e) {
|
||||
logger.error("decode(String, JsonTypeReference<T>)", e);
|
||||
} catch (JsonMappingException e) {
|
||||
logger.error("decode(String, JsonTypeReference<T>)", e);
|
||||
} catch (IOException e) {
|
||||
logger.error("decode(String, JsonTypeReference<T>)", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,6 +14,8 @@ public class QuestionWriteForm {
|
||||
private String title;
|
||||
@ApiModelProperty(value = "内容")
|
||||
private String content;
|
||||
@ApiModelProperty(value = "文本内容")
|
||||
private String contentJson;
|
||||
|
||||
@ApiModelProperty(value = "分类")
|
||||
private Integer categoryId;
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
package com.quinn.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author limqsh
|
||||
* @since 2022-05-03
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
public class SourceDeleteForm {
|
||||
|
||||
@ApiModelProperty(value = "资源ID")
|
||||
private String sid;
|
||||
|
||||
@ApiModelProperty(value = "管理员密码")
|
||||
private String uploadPassWord;
|
||||
|
||||
}
|
||||
@@ -30,8 +30,8 @@ public class SourceUpdateForm {
|
||||
@ApiModelProperty(value = "资源内容")
|
||||
private String sourceContent;
|
||||
|
||||
@ApiModelProperty(value = "关键字")
|
||||
private String keyWords;
|
||||
@ApiModelProperty(value = "内容文本")
|
||||
private String contentJson;
|
||||
|
||||
@ApiModelProperty(value = "资源类型")
|
||||
private String sourceType;
|
||||
@@ -48,7 +48,4 @@ public class SourceUpdateForm {
|
||||
@ApiModelProperty(value = "英文名")
|
||||
private String enName;
|
||||
|
||||
@ApiModelProperty(value = "管理员密码")
|
||||
private String uploadPassWord;
|
||||
|
||||
}
|
||||
|
||||
@@ -16,10 +16,11 @@ public class SourceWriteForm {
|
||||
private String subContent;
|
||||
@ApiModelProperty(value = "内容")
|
||||
private String content;
|
||||
@ApiModelProperty(value = "内容文本")
|
||||
private String contentJson;
|
||||
|
||||
@ApiModelProperty(value = "英文名")
|
||||
private String enName;
|
||||
@ApiModelProperty(value = "摘要")
|
||||
private String keyWords;
|
||||
|
||||
@ApiModelProperty(value = "分类")
|
||||
private Integer categoryId;
|
||||
@@ -29,6 +30,4 @@ public class SourceWriteForm {
|
||||
@ApiModelProperty(value = "文档路径")
|
||||
private String sourceLink;
|
||||
|
||||
@ApiModelProperty(value = "管理员密码")
|
||||
private String uploadPassWord;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user