一系列接口

This commit is contained in:
cyk 2023-12-22 10:35:16 +08:00
parent 1201edf7d5
commit 92960b071b
19 changed files with 967 additions and 51 deletions

34
pom.xml
View File

@ -43,11 +43,6 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId> <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency> </dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<!--邮箱依赖配置--> <!--邮箱依赖配置-->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
@ -83,6 +78,11 @@
<artifactId>fastjson</artifactId> <artifactId>fastjson</artifactId>
<version>1.2.47</version> <version>1.2.47</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<dependency> <dependency>
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
@ -96,6 +96,30 @@
</dependency> </dependency>
<!-- jackson 2.x 相关依赖 -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.12.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.12.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.12.0</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.7.1</version>
</dependency>
</dependencies> </dependencies>
<dependencyManagement> <dependencyManagement>
<dependencies> <dependencies>

View File

@ -1,4 +1,81 @@
package com.lovenav.controller; package com.lovenav.controller;
import com.alibaba.fastjson2.JSONObject;
import com.lovenav.entity.UrlList;
import com.lovenav.filter.SensitiveFilter;
import com.lovenav.service.RedisService;
import com.lovenav.service.UrlListService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@RestController
@RequestMapping("/Search")
public class SearchController { public class SearchController {
private static Logger logger = LoggerFactory.getLogger(SearchController.class);
@Autowired
RedisService redisService ;
@Autowired
UrlListService urlListService;
@RequestMapping("/searchByInput")
public String searchByInput(String searchKey,String userId ) throws IOException {
String placeholder = "***";
//非法敏感词汇判断
SensitiveFilter filter = SensitiveFilter.getInstance();
String s = filter.replaceSensitiveWord(searchKey, 1, placeholder);
System.out.println(s);
int n = filter.CheckSensitiveWord(searchKey,0,2);
//存在非法字符
if(n > 0){
logger.info("这个人输入了非法字符--> {},不知道他到底要查什么~ userid--> {}",searchKey,1);
return setResult(500,"查询失败");
}
redisService.addSearchHistoryByUserId(userId, searchKey);
redisService.incrementScore(searchKey);
//返回网站数据
UrlList urlList = urlListService.selectUrListByInput(searchKey);
HashMap<String, Object> result = new HashMap<>();
result.put("code", 200);
result.put("msg", "查询成功");
result.put("data",urlList);
String jsonString = JSONObject.toJSONString(result);
return jsonString;
}
public String setResult(Integer code, String msg) {
HashMap<String, Object> result = new HashMap<>();
result.put("code", code);
result.put("msg", msg);
String jsonString = JSONObject.toJSONString(result);
return jsonString;
}
/**
* 获取个人历史数据列表
*/
@RequestMapping("/getSearchHistoryByUserId")
public String getSearchHistoryByUserId(String userId)
{
String res = "123";
return res;
}
/**
* 删除个人历史数据
*/
@RequestMapping("/delSearchHistoryByUserId")
public String delSearchHistoryByUserId(String userId, String searchKey){
String res = "123";
return res;
}
} }

View File

@ -0,0 +1,188 @@
package com.lovenav.controller;
import com.alibaba.fastjson2.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.lovenav.entity.UrlCateList;
import com.lovenav.entity.UrlList;
import com.lovenav.service.UrlCateListService;
import com.lovenav.service.UrlListService;
import com.lovenav.vo.CateAndUrl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@RestController
@RequestMapping("/UrlAndCate")
public class UrlAndCateController {
@Autowired
ObjectMapper objectMapper;
@Autowired
UrlCateListService urlCateListService;
@Autowired
UrlListService urlListService;
//处理JSON
@RequestMapping("/disposeJson")
public String disposeJson(@RequestBody String data2 ,String email)
{
String jsonString;
//先转换成ObjectMapper类型
ObjectNode objectNode = objectMapper.createObjectNode();
try {
JsonNode rootNode = objectMapper.readTree(data2);
disposeBookmarkFunction1(rootNode,"top",email);
HashMap<String, Object> result = new HashMap<>();
result.put("code", 200);
result.put("msg", "查询成功");
jsonString = JSONObject.toJSONString(result);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
return jsonString;
}
public void disposeBookmarkFunction1(JsonNode rootNode,String parent,String email)
{
for(int i=0;i<rootNode.size();i++)
{
JsonNode sonNode = rootNode.get(i);
if(String.valueOf(sonNode.get("folder")).equals("true")){
urlCateListService.selectAndInsertUrlCate(email,String.valueOf(sonNode.get("name")),parent);
JsonNode children = sonNode.get("children");
disposeBookmarkFunction1(children, String.valueOf(sonNode.get("name")),email);
}else{
String name = String.valueOf(sonNode.get("name"));
String url = String.valueOf(sonNode.get("url"));
String adddata = String.valueOf(sonNode.get("adddata"));
urlListService.selectCateAndInsertUrl(parent,name,"123",url,email);
System.out.println(name +"---" + url + "---" + adddata + "---" + parent );
}
}
return ;
}
//处理成JSON
@RequestMapping("/disposeBookmarkToJson")
public String disposeBookmarkToJson(Integer userId)
{
List<UrlCateList> urlCateLists = urlCateListService.selectUrListByUserId(userId);
List<UrlList> urlLists = urlListService.selectUrList();
List<CateAndUrl> cateAndUrlList = new ArrayList<>();
//预处理为CateAndUrl对象
for( int i = 0 ; i < urlCateLists.size() ; i++)
{
CateAndUrl cateAndUrl = new CateAndUrl();
cateAndUrl.setFloder("true");
cateAndUrl.setName(urlCateLists.get(i).getName());
cateAndUrl.setParentId(urlCateLists.get(i).getRootCateId());
cateAndUrl.setCateId(urlCateLists.get(i).getId());
cateAndUrlList.add(cateAndUrl);
}
for( int i = 0 ; i < urlLists.size() ; i++)
{
CateAndUrl cateAndUrl = new CateAndUrl();
cateAndUrl.setFloder("false");
cateAndUrl.setName(urlLists.get(i).getName());
cateAndUrl.setParentId(urlLists.get(i).getCateId());
cateAndUrl.setUrlId(urlLists.get(i).getId());
cateAndUrlList.add(cateAndUrl);
}
List<CateAndUrl> parentsList = new ArrayList<>();
//声明返回集合
List<CateAndUrl> resultList = new ArrayList<>();
//对全部数据进行遍历
for (CateAndUrl disease : cateAndUrlList) {
//判断是否是第一梯队或者说是树的根节点如果是根节点就加入到父类集合与返回集合
if (disease.getParentId() == 0) {
parentsList.add(disease);
resultList.add(disease);
} else {
//对于不是第一梯队的数据进行遍历
for (CateAndUrl parent : parentsList) {
//对数据的pid与父类集合中的父节点进行配对如果配对成功就把数据加入到父节点中的子节点集合
if (parent.getFloder().equals("true") ) {
if( parent.getCateId() == disease.getParentId())
{
parent.getChildUC().add(disease);
//当前数据有可能是别的数据的父节点加到父类容器
parentsList.add(disease);
break;
}
}
if (parent.getFloder().equals("false") ) {
if(parent.getUrlId() == disease.getParentId())
{
parent.getChildUC().add(disease);
//当前数据有可能是别的数据的父节点加到父类容器
parentsList.add(disease);
break;
}
}
}
}
}
ObjectMapper mapper = new ObjectMapper();
String Json;
HashMap<String, Object> result = new HashMap<>();
// java对象转换为json字符换
try {
Json = mapper.writeValueAsString(resultList);
result.put("code", 200);
result.put("msg", "处理成功");
result.put("data", resultList);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
return JSONObject.toJSONString(result);
}
public String setResult(Integer code, String msg) {
HashMap<String, Object> result = new HashMap<>();
result.put("code", code);
result.put("msg", msg);
String jsonString = JSONObject.toJSONString(result);
return jsonString;
}
//详情页面
@RequestMapping("/clickUrl")
public String clickUrl(String urlId)
{
UrlList urlList = urlListService.selectUrlListByUrlId(Long.valueOf(urlId));
HashMap<String, Object> result = new HashMap<>();
result.put("code", 200);
result.put("msg", "查询成功");
result.put("data",urlList);
String jsonString = JSONObject.toJSONString(result);
return jsonString;
}
}

View File

@ -1,9 +1,16 @@
package com.lovenav.dao; package com.lovenav.dao;
import com.lovenav.entity.UrlCateList; import com.lovenav.entity.UrlCateList;
import com.lovenav.entity.UrlList;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List;
@Repository @Repository
@Mapper
public interface UrlCateListDao { public interface UrlCateListDao {
int deleteByPrimaryKey(Integer id); int deleteByPrimaryKey(Integer id);
@ -16,4 +23,11 @@ public interface UrlCateListDao {
int updateByPrimaryKeySelective(UrlCateList record); int updateByPrimaryKeySelective(UrlCateList record);
int updateByPrimaryKey(UrlCateList record); int updateByPrimaryKey(UrlCateList record);
public UrlCateList selectCateByNameAnduserId(@Param("name")String name, @Param("userId") int userId);
public List<UrlCateList> selectUrListByUserId(Integer userId);
} }

View File

@ -1,9 +1,14 @@
package com.lovenav.dao; package com.lovenav.dao;
import com.lovenav.entity.UrlList; import com.lovenav.entity.UrlList;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List;
@Repository @Repository
@Mapper
public interface UrlListDao { public interface UrlListDao {
int deleteByPrimaryKey(Long id); int deleteByPrimaryKey(Long id);
@ -16,4 +21,12 @@ public interface UrlListDao {
int updateByPrimaryKeySelective(UrlList record); int updateByPrimaryKeySelective(UrlList record);
int updateByPrimaryKey(UrlList record); int updateByPrimaryKey(UrlList record);
public List<UrlList> selectUrList();
public UrlList selectUrListByInput(String input);
public UrlList selectUrlListByUrlId(Long urlId);
} }

View File

@ -2,9 +2,9 @@ package com.lovenav.dao;
import com.lovenav.entity.User; import com.lovenav.entity.User;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@Repository @Repository
@Mapper @Mapper
public interface UserDao { public interface UserDao {
@ -27,4 +27,5 @@ public interface UserDao {
int updateByEmail(User user); int updateByEmail(User user);
} }

View File

@ -21,7 +21,7 @@ public class UrlCateList implements Serializable {
/** /**
* 创建时间 * 创建时间
*/ */
private Integer createtime; private Long createtime;
/** /**
* url 数量 * url 数量

View File

@ -36,7 +36,7 @@ public class UrlList implements Serializable {
/** /**
* 创建时间 * 创建时间
*/ */
private Integer createtime; private Long createtime;
/** /**
* 访问数量 * 访问数量

View File

@ -0,0 +1,12 @@
package com.lovenav.service;
import com.lovenav.entity.UrlCateList;
import java.util.List;
public interface UrlCateListService {
public int selectAndInsertUrlCate(String email , String cateName , String parent);
public List<UrlCateList> selectUrListByUserId(Integer userId);
}

View File

@ -0,0 +1,13 @@
package com.lovenav.service;
import com.lovenav.entity.UrlList;
import java.util.List;
public interface UrlListService {
public int selectCateAndInsertUrl(String parent,String name , String icon ,String url ,String email );
public List<UrlList> selectUrList();
public UrlList selectUrListByInput(String input);
public UrlList selectUrlListByUrlId(Long urlId);
}

View File

@ -4,6 +4,7 @@ import com.lovenav.entity.User;
public interface UserService { public interface UserService {
public String sendEmailActivecode(User user); public String sendEmailActivecode(User user);

View File

@ -119,7 +119,8 @@ public class RedisServiceImpl implements RedisService {
if (result.size() > HOT_SEARCH_NUMBER) { if (result.size() > HOT_SEARCH_NUMBER) {
break; break;
} }
Long time = Long.valueOf(Objects.requireNonNull(valueOperations.get(val)));
Long time = Long.valueOf(Objects.requireNonNull(valueOperations.get("search:search-time:"+val)));
//返回最近一个月的数据 //返回最近一个月的数据
if ((now - time) < HOT_SEARCH_TIME) { if ((now - time) < HOT_SEARCH_TIME) {
result.add(val); result.add(val);
@ -134,7 +135,8 @@ public class RedisServiceImpl implements RedisService {
if (result.size() > HOT_SEARCH_NUMBER) { if (result.size() > HOT_SEARCH_NUMBER) {
break; break;
} }
Long time = Long.valueOf(Objects.requireNonNull(valueOperations.get(val))); System.out.println(valueOperations.get(val));
Long time = Long.valueOf(Objects.requireNonNull(valueOperations.get("search:search-time:"+val)));
//返回最近一个月的数据 //返回最近一个月的数据
if ((now - time) < HOT_SEARCH_TIME) { if ((now - time) < HOT_SEARCH_TIME) {
result.add(val); result.add(val);
@ -186,6 +188,7 @@ public class RedisServiceImpl implements RedisService {
// 没有的话就插入有的话的直接更新add是有就覆盖没有就插入 // 没有的话就插入有的话的直接更新add是有就覆盖没有就插入
zSetOperations.incrementScore(RedisKeyUtils.getHotSearchKey(), searchKey, 1); zSetOperations.incrementScore(RedisKeyUtils.getHotSearchKey(), searchKey, 1);
valueOperations.getAndSet(RedisKeyUtils.getSearchTimeKey(searchKey), String.valueOf(now)); valueOperations.getAndSet(RedisKeyUtils.getSearchTimeKey(searchKey), String.valueOf(now));
return 1L; return 1L;
}catch (Exception e){ }catch (Exception e){
logger.error("redis发生异常异常原因",e); logger.error("redis发生异常异常原因",e);

View File

@ -0,0 +1,56 @@
package com.lovenav.service.serviceImpl;
import com.lovenav.dao.UrlCateListDao;
import com.lovenav.dao.UserDao;
import com.lovenav.entity.UrlCateList;
import com.lovenav.entity.User;
import com.lovenav.service.UrlCateListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
@Transactional
@Service("urlCateListService")
public class UrlCateListServiceImpl implements UrlCateListService {
@Autowired
UrlCateListDao urlCateListDao;
@Autowired
UserDao userDao;
public int selectAndInsertUrlCate(String email , String cateName , String parent )
{
//找用户ID
User user = userDao.selectByEmail(email);
int userId = user.getId();
//找父标签有没有
UrlCateList cateParent = urlCateListDao.selectCateByNameAnduserId(parent,userId);
UrlCateList targetCate = new UrlCateList();
//设置属性
targetCate.setName(cateName);
targetCate.setUserId(userId);
Date date = new Date();
targetCate.setCreatetime(date.getTime());
if(cateParent != null)
{
targetCate.setRootCateId(cateParent.getId());
}else{
targetCate.setRootCateId(0);
}
//插入
int flag = urlCateListDao.insert(targetCate);
return flag;
}
public List<UrlCateList> selectUrListByUserId(Integer userId){
return urlCateListDao.selectUrListByUserId(userId);
}
}

View File

@ -0,0 +1,63 @@
package com.lovenav.service.serviceImpl;
import com.lovenav.dao.UrlCateListDao;
import com.lovenav.dao.UrlListDao;
import com.lovenav.dao.UserDao;
import com.lovenav.entity.UrlCateList;
import com.lovenav.entity.UrlList;
import com.lovenav.entity.User;
import com.lovenav.service.UrlListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
@Transactional
@Service("urlListService")
public class UrlLiserServiceImpl implements UrlListService {
@Autowired
UrlCateListDao urlCateListDao;
@Autowired
UrlListDao urlListDao;
@Autowired
UserDao userDao;
public int selectCateAndInsertUrl(String parent,String name , String icon ,String url ,String email)
{
//找用户ID
User user = userDao.selectByEmail(email);
int userId = user.getId();
UrlCateList urlCateList = urlCateListDao.selectCateByNameAnduserId(parent,userId);
UrlList urlList = new UrlList();
//设置属性
urlList.setCateId(urlCateList.getId());
urlList.setUrl(url);
urlList.setIcon(icon);
urlList.setName(name);
Date date = new Date();
urlList.setCreatetime(date.getTime());
urlList.setViews(Long.valueOf("0"));
int flag = urlListDao.insert(urlList);
return flag;
}
public List<UrlList> selectUrList(){
return urlListDao.selectUrList();
}
public UrlList selectUrListByInput(String input)
{
return urlListDao.selectUrListByInput(input);
}
public UrlList selectUrlListByUrlId(Long urlId)
{
UrlList urlList = urlListDao.selectUrlListByUrlId(urlId);
urlList.setViews(urlList.getViews()+1);
urlListDao.updateByPrimaryKeySelective(urlList);
return urlList;
}
}

View File

@ -8,43 +8,18 @@ import com.lovenav.service.UserService;
import com.lovenav.utils.MD5Utils; import com.lovenav.utils.MD5Utils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.text.SimpleDateFormat; import javax.annotation.Resource;
import java.util.Date; import java.util.Date;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@Transactional
@Service @Service("userService")
public class UserServiceImpl implements UserService { public class UserServiceImpl implements UserService {
@Autowired
@Resource
UserDao userDao; UserDao userDao;
@Override
public String sendEmailActivecode(User user) {
return EmailUtils.sendEmail(user);
}
@Override
public int UserRegister(User user) {
user.setRoleId(Byte.valueOf("1"));
user.setUserStatus(Byte.valueOf("1"));
user.setUserPassword(MD5Utils.md5(user.getUserPassword()));
Date date=new Date();
user.setUserRegistered(date);
return userDao.insert(user);
}
@Override
public User selectUserAlreadyExist(User user) {
System.out.println(user.getUserEmail());
User user1=userDao.selectByEmail(user.getUserEmail());
return user1;
}
@Override @Override
public User userLogin(User user) { public User userLogin(User user) {
boolean result; boolean result;
@ -82,5 +57,32 @@ public class UserServiceImpl implements UserService {
return userDao.updateByEmail(user); return userDao.updateByEmail(user);
} }
@Override
public String sendEmailActivecode(User user) {
return EmailUtils.sendEmail(user);
}
@Override
public int UserRegister(User user) {
user.setRoleId(Byte.valueOf("1"));
user.setUserStatus(Byte.valueOf("1"));
user.setUserPassword(MD5Utils.md5(user.getUserPassword()));
Date date=new Date();
user.setUserRegistered(date);
return userDao.insert(user);
}
@Override
public User selectUserAlreadyExist(User user) {
System.out.println(user.getUserEmail());
User user1=userDao.selectByEmail(user.getUserEmail());
return user1;
}
} }

View File

@ -0,0 +1,96 @@
package com.lovenav.vo;
import java.util.ArrayList;
import java.util.List;
public class CateAndUrl {
String name;
String icon;
String url;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getFloder() {
return floder;
}
public void setFloder(String floder) {
this.floder = floder;
}
public List<CateAndUrl> getChildUC() {
return childUC;
}
public void setChildUC(List<CateAndUrl> childUC) {
this.childUC = childUC;
}
@Override
public String toString() {
return "cateAndUrl{" +
"name='" + name + '\'' +
", icon='" + icon + '\'' +
", url='" + url + '\'' +
", floder='" + floder + '\'' +
", childUC=" + childUC +
'}';
}
public int getParentId() {
return parentId;
}
public void setParentId(int parentId) {
this.parentId = parentId;
}
String floder;
public Integer getCateId() {
return cateId;
}
public void setCateId(Integer cateId) {
this.cateId = cateId;
}
public Long getUrlId() {
return urlId;
}
public void setUrlId(Long urlId) {
this.urlId = urlId;
}
int parentId;
Integer cateId;
Long urlId;
List<CateAndUrl> childUC = new ArrayList<>();
}

View File

@ -4,7 +4,7 @@
<resultMap id="BaseResultMap" type="com.lovenav.entity.UrlCateList"> <resultMap id="BaseResultMap" type="com.lovenav.entity.UrlCateList">
<id column="id" jdbcType="INTEGER" property="id" /> <id column="id" jdbcType="INTEGER" property="id" />
<result column="name" jdbcType="VARCHAR" property="name" /> <result column="name" jdbcType="VARCHAR" property="name" />
<result column="createtime" jdbcType="INTEGER" property="createtime" /> <result column="createtime" jdbcType="BIGINT" property="createtime" />
<result column="url_number" jdbcType="BIGINT" property="urlNumber" /> <result column="url_number" jdbcType="BIGINT" property="urlNumber" />
<result column="weigh" jdbcType="BIGINT" property="weigh" /> <result column="weigh" jdbcType="BIGINT" property="weigh" />
<result column="status" jdbcType="TINYINT" property="status" /> <result column="status" jdbcType="TINYINT" property="status" />
@ -23,6 +23,23 @@
from ln_url_cate_list from ln_url_cate_list
where id = #{id,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}
</select> </select>
<select id="selectUrListByUserId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from ln_url_cate_list
where user_id = #{userId,jdbcType=INTEGER}
</select>
<select id="selectCateByNameAnduserId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from ln_url_cate_list
where name = #{name ,jdbcType=VARCHAR} and user_id = #{userId,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer"> <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from ln_url_cate_list delete from ln_url_cate_list
where id = #{id,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}
@ -32,7 +49,7 @@
weigh, `status`, need_login, weigh, `status`, need_login,
user_id, root_cate_id, ico user_id, root_cate_id, ico
) )
values (#{name,jdbcType=VARCHAR}, #{createtime,jdbcType=INTEGER}, #{urlNumber,jdbcType=BIGINT}, values (#{name,jdbcType=VARCHAR}, #{createtime,jdbcType=BIGINT}, #{urlNumber,jdbcType=BIGINT},
#{weigh,jdbcType=BIGINT}, #{status,jdbcType=TINYINT}, #{needLogin,jdbcType=TINYINT}, #{weigh,jdbcType=BIGINT}, #{status,jdbcType=TINYINT}, #{needLogin,jdbcType=TINYINT},
#{userId,jdbcType=INTEGER}, #{rootCateId,jdbcType=INTEGER}, #{ico,jdbcType=VARCHAR} #{userId,jdbcType=INTEGER}, #{rootCateId,jdbcType=INTEGER}, #{ico,jdbcType=VARCHAR}
) )
@ -73,7 +90,7 @@
#{name,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
</if> </if>
<if test="createtime != null"> <if test="createtime != null">
#{createtime,jdbcType=INTEGER}, #{createtime,jdbcType=BIGINT},
</if> </if>
<if test="urlNumber != null"> <if test="urlNumber != null">
#{urlNumber,jdbcType=BIGINT}, #{urlNumber,jdbcType=BIGINT},
@ -105,7 +122,7 @@
`name` = #{name,jdbcType=VARCHAR}, `name` = #{name,jdbcType=VARCHAR},
</if> </if>
<if test="createtime != null"> <if test="createtime != null">
createtime = #{createtime,jdbcType=INTEGER}, createtime = #{createtime,jdbcType=BIGINT},
</if> </if>
<if test="urlNumber != null"> <if test="urlNumber != null">
url_number = #{urlNumber,jdbcType=BIGINT}, url_number = #{urlNumber,jdbcType=BIGINT},
@ -134,7 +151,7 @@
<update id="updateByPrimaryKey" parameterType="com.lovenav.entity.UrlCateList"> <update id="updateByPrimaryKey" parameterType="com.lovenav.entity.UrlCateList">
update ln_url_cate_list update ln_url_cate_list
set `name` = #{name,jdbcType=VARCHAR}, set `name` = #{name,jdbcType=VARCHAR},
createtime = #{createtime,jdbcType=INTEGER}, createtime = #{createtime,jdbcType=BIGINT},
url_number = #{urlNumber,jdbcType=BIGINT}, url_number = #{urlNumber,jdbcType=BIGINT},
weigh = #{weigh,jdbcType=BIGINT}, weigh = #{weigh,jdbcType=BIGINT},
`status` = #{status,jdbcType=TINYINT}, `status` = #{status,jdbcType=TINYINT},

View File

@ -7,7 +7,7 @@
<result column="icon" jdbcType="VARCHAR" property="icon" /> <result column="icon" jdbcType="VARCHAR" property="icon" />
<result column="cate_id" jdbcType="INTEGER" property="cateId" /> <result column="cate_id" jdbcType="INTEGER" property="cateId" />
<result column="url" jdbcType="VARCHAR" property="url" /> <result column="url" jdbcType="VARCHAR" property="url" />
<result column="createtime" jdbcType="INTEGER" property="createtime" /> <result column="createtime" jdbcType="BIGINT" property="createtime" />
<result column="views" jdbcType="BIGINT" property="views" /> <result column="views" jdbcType="BIGINT" property="views" />
<result column="tags" jdbcType="VARCHAR" property="tags" /> <result column="tags" jdbcType="VARCHAR" property="tags" />
<result column="weigh" jdbcType="BIGINT" property="weigh" /> <result column="weigh" jdbcType="BIGINT" property="weigh" />
@ -30,6 +30,29 @@
from ln_url_list from ln_url_list
where id = #{id,jdbcType=BIGINT} where id = #{id,jdbcType=BIGINT}
</select> </select>
<select id="selectUrList" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from ln_url_list
</select>
<select id="selectUrListByInput" parameterType="java.lang.String" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from ln_url_list
where name like concat('%',#{input},'%')
</select>
<select id="selectUrlListByUrlId" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from ln_url_list
where id = #{urlId,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long"> <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from ln_url_list delete from ln_url_list
where id = #{id,jdbcType=BIGINT} where id = #{id,jdbcType=BIGINT}
@ -42,7 +65,7 @@
is_need_agent, is_ad, is_top, is_need_agent, is_ad, is_top,
is_encrypt) is_encrypt)
values (#{name,jdbcType=VARCHAR}, #{icon,jdbcType=VARCHAR}, #{cateId,jdbcType=INTEGER}, values (#{name,jdbcType=VARCHAR}, #{icon,jdbcType=VARCHAR}, #{cateId,jdbcType=INTEGER},
#{url,jdbcType=VARCHAR}, #{createtime,jdbcType=INTEGER}, #{views,jdbcType=BIGINT}, #{url,jdbcType=VARCHAR}, #{createtime,jdbcType=BIGINT}, #{views,jdbcType=BIGINT},
#{tags,jdbcType=VARCHAR}, #{weigh,jdbcType=BIGINT}, #{status,jdbcType=TINYINT}, #{tags,jdbcType=VARCHAR}, #{weigh,jdbcType=BIGINT}, #{status,jdbcType=TINYINT},
#{desc,jdbcType=VARCHAR}, #{needLogin,jdbcType=TINYINT}, #{agentHint,jdbcType=VARCHAR}, #{desc,jdbcType=VARCHAR}, #{needLogin,jdbcType=TINYINT}, #{agentHint,jdbcType=VARCHAR},
#{isNeedAgent,jdbcType=TINYINT}, #{isAd,jdbcType=TINYINT}, #{isTop,jdbcType=TINYINT}, #{isNeedAgent,jdbcType=TINYINT}, #{isAd,jdbcType=TINYINT}, #{isTop,jdbcType=TINYINT},
@ -114,7 +137,7 @@
#{url,jdbcType=VARCHAR}, #{url,jdbcType=VARCHAR},
</if> </if>
<if test="createtime != null"> <if test="createtime != null">
#{createtime,jdbcType=INTEGER}, #{createtime,jdbcType=BIGINT},
</if> </if>
<if test="views != null"> <if test="views != null">
#{views,jdbcType=BIGINT}, #{views,jdbcType=BIGINT},
@ -167,7 +190,7 @@
url = #{url,jdbcType=VARCHAR}, url = #{url,jdbcType=VARCHAR},
</if> </if>
<if test="createtime != null"> <if test="createtime != null">
createtime = #{createtime,jdbcType=INTEGER}, createtime = #{createtime,jdbcType=BIGINT},
</if> </if>
<if test="views != null"> <if test="views != null">
views = #{views,jdbcType=BIGINT}, views = #{views,jdbcType=BIGINT},
@ -211,7 +234,7 @@
icon = #{icon,jdbcType=VARCHAR}, icon = #{icon,jdbcType=VARCHAR},
cate_id = #{cateId,jdbcType=INTEGER}, cate_id = #{cateId,jdbcType=INTEGER},
url = #{url,jdbcType=VARCHAR}, url = #{url,jdbcType=VARCHAR},
createtime = #{createtime,jdbcType=INTEGER}, createtime = #{createtime,jdbcType=BIGINT},
views = #{views,jdbcType=BIGINT}, views = #{views,jdbcType=BIGINT},
tags = #{tags,jdbcType=VARCHAR}, tags = #{tags,jdbcType=VARCHAR},
weigh = #{weigh,jdbcType=BIGINT}, weigh = #{weigh,jdbcType=BIGINT},

View File

@ -1,13 +1,326 @@
package com.lovenav; package com.lovenav;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.lovenav.dao.UrlCateListDao;
import com.lovenav.dao.UrlListDao;
import com.lovenav.dao.UserDao;
import com.lovenav.entity.UrlCateList;
import com.lovenav.entity.UrlList;
import com.lovenav.filter.SensitiveFilter;
import com.lovenav.service.RedisService;
import com.lovenav.service.UrlCateListService;
import com.lovenav.service.UrlListService;
import com.lovenav.service.UserService;
import com.lovenav.vo.CateAndUrl;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.slf4j.Logger;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@SpringBootTest @SpringBootTest
class LoveNavApplicationTests { class LoveNavApplicationTests {
@Autowired
private RedisTemplate<String, Object> redisTemplate;
@Autowired
private StringRedisTemplate stringRedisTemplate;
@Autowired
RedisService redisService ;
@Autowired
UserService userService ;
@Autowired
UrlCateListService urlCateListService;
@Autowired
UrlListService urlListService;
@Autowired
UserDao userDao;
@Autowired
SensitiveFilter sensitiveFilter;
@Autowired
ObjectMapper objectMapper;
@Autowired
UrlCateListDao urlCateListDao;
@Autowired
UrlListDao urlListDao;
private static Logger logger = LoggerFactory.getLogger(LoveNavApplicationTests.class);
@Test @Test
void contextLoads() { void contextLoads() {
String userId = "2";
String searchKey="学习";
String abc = "[91片先生, bilibli, 学习, 阁楼]";
redisService.addSearchHistoryByUserId(userId, searchKey);
redisService.incrementScoreByUserId(searchKey);
redisService.incrementScore(searchKey);
// redisService.getSearchHistoryByUserId(userId);
// System.out.println(redisService.getSearchHistoryByUserId(userId));
System.out.println(redisService.getHotList(""));
}
@Test
void testStringRedisTemplate() {
stringRedisTemplate.opsForValue().set("name", "zhenyu");
//根据键值取出数据
System.out.println(stringRedisTemplate.opsForValue().get("name"));
}
@Test
void testServiceImpl() throws IOException {
String searchKey = "傻逼h";
String placeholder = "***";
//非法敏感词汇判断
SensitiveFilter filter = SensitiveFilter.getInstance();
String s = filter.replaceSensitiveWord(searchKey, 1, placeholder);
System.out.println(s);
int n = filter.CheckSensitiveWord(searchKey,0,2);
//存在非法字符
if(n > 0){
logger.info("这个人输入了非法字符--> {},不知道他到底要查什么~ userid--> {}",searchKey,1);
}
}
@Test
public void disposeBookmark()
{
String data = "\n" +
"[ {\n" +
"\"name\" :\"书签栏\",\n" +
"\"folder\":true,\n" +
"\"children\": [ {\n" +
"\"folder\":false,\n" +
"\"name\" :\"后阁楼_此处安放你的文字\",\n" +
"\"url\": \"http://lxqnsys.com/ hougelou/#/\"\n" +
"}]\n" +
"}, {\n" +
"\"name\" :\"我是文件夹\",\n" +
"\"folder\" : true,\n" +
"\"children\" : [{\n" +
"\"folder\":false,\n" +
"\"name\" :\"理想P卫T_一个简单优雅的在线PPT\",\n" +
"\"url\": \"http:// lxqnsys.com/ ppt/ \"\n" +
"}]\n" +
"\n" +
"}]";
String data1 = "[\n" +
" {\n" +
" \"name\":\"书签栏\",\n" +
" \"folder\":true,\n" +
" \"children\":[\n" +
" {\n" +
" \"folder\":false,\n" +
" \"name\":\"后阁楼_此处安放你的文字\",\n" +
" \"url\":\"http://lxqnsys.com/ hougelou/#/\"\n" +
" },\n" +
" {\n" +
" \"folder\":true,\n" +
" \"name\":\"seven\",\n" +
" \"url\":\"http://lxqnsys.com/ hougelou/#/\",\n" +
" \"children\":[]\n" +
" }\n" +
" ]\n" +
" },\n" +
" {\n" +
" \"name\":\"我是文件夹\",\n" +
" \"folder\":true,\n" +
" \"children\":[\n" +
" {\n" +
" \"folder\":false,\n" +
" \"name\":\"理想P卫T_一个简单优雅的在线PPT\",\n" +
" \"url\":\"http:// lxqnsys.com/ ppt/ \"\n" +
" }\n" +
" ]\n" +
" }\n" +
"]";
String data2="[\n" +
" {\n" +
" \"name\":\"书签栏\",\n" +
" \"folder\":true,\n" +
" \"children\":[\n" +
" {\n" +
" \"folder\":false,\n" +
" \"name\":\"后阁楼_此处安放你的文字\",\n" +
" \"url\":\"http://lxqnsys.com/ hougelou/#/\"\n" +
" },\n" +
" {\n" +
" \"folder\":true,\n" +
" \"name\":\"seven\",\n" +
" \"url\":\"http://lxqnsys.com/ hougelou/#/\",\n" +
" \"children\":[]\n" +
" }\n" +
" ]\n" +
" },\n" +
" {\n" +
" \"name\":\"我是文件夹\",\n" +
" \"folder\":true,\n" +
" \"children\":[\n" +
" {\n" +
" \"folder\":false,\n" +
" \"name\":\"理想P卫T_一个简单优雅的在线PPT\",\n" +
" \"url\":\"http:// lxqnsys.com/ ppt/ \"\n" +
" },\n" +
" {\n" +
" \"folder\":true,\n" +
" \"name\":\"eight\",\n" +
" \"url\":\"http://lxqnsys.com/ hougelou/#/\",\n" +
" \"children\":[]\n" +
" }\n" +
" ]\n" +
" }\n" +
"]";
String mes = "success";
//先转换成ObjectMapper类型
ObjectNode objectNode = objectMapper.createObjectNode();
try {
JsonNode rootNode = objectMapper.readTree(data2);
disposeBookmarkFunction1(rootNode,"top","fadas");
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
@Test
public void disposeBookmarkFunction1(JsonNode rootNode,String parent,String email)
{
for(int i=0;i<rootNode.size();i++)
{
JsonNode sonNode = rootNode.get(i);
if(String.valueOf(sonNode.get("folder")).equals("true")){
urlCateListService.selectAndInsertUrlCate(email,String.valueOf(sonNode.get("name")),parent);
JsonNode children = sonNode.get("children");
disposeBookmarkFunction1(children, String.valueOf(sonNode.get("name")),email);
}else{
String name = String.valueOf(sonNode.get("name"));
String url = String.valueOf(sonNode.get("url"));
String adddata = String.valueOf(sonNode.get("adddata"));
urlListService.selectCateAndInsertUrl(parent,name,"123",url,email);
System.out.println(name +"---" + url + "---" + adddata + "---" + parent );
}
}
return ;
}
@Test
public void disposeBookmarkToJson()
{
List<UrlCateList> urlCateLists = urlCateListDao.selectUrListByUserId(1);
List<UrlList> urlLists = urlListDao.selectUrList();
List<CateAndUrl> cateAndUrlList = new ArrayList<>();
//预处理为CateAndUrl对象
for( int i = 0 ; i < urlCateLists.size() ; i++)
{
CateAndUrl cateAndUrl = new CateAndUrl();
cateAndUrl.setFloder("true");
cateAndUrl.setName(urlCateLists.get(i).getName());
cateAndUrl.setParentId(urlCateLists.get(i).getRootCateId());
cateAndUrl.setCateId(urlCateLists.get(i).getId());
cateAndUrlList.add(cateAndUrl);
}
for( int i = 0 ; i < urlLists.size() ; i++)
{
CateAndUrl cateAndUrl = new CateAndUrl();
cateAndUrl.setFloder("false");
cateAndUrl.setName(urlLists.get(i).getName());
cateAndUrl.setParentId(urlLists.get(i).getCateId());
cateAndUrl.setUrlId(urlLists.get(i).getId());
cateAndUrlList.add(cateAndUrl);
}
List<CateAndUrl> parentsList = new ArrayList<>();
//声明返回集合
List<CateAndUrl> resultList = new ArrayList<>();
//对全部数据进行遍历
for (CateAndUrl disease : cateAndUrlList) {
//判断是否是第一梯队或者说是树的根节点如果是根节点就加入到父类集合与返回集合
if (disease.getParentId() == 0) {
parentsList.add(disease);
resultList.add(disease);
} else {
//对于不是第一梯队的数据进行遍历
for (CateAndUrl parent : parentsList) {
//对数据的pid与父类集合中的父节点进行配对如果配对成功就把数据加入到父节点中的子节点集合
if (parent.getFloder().equals("true") ) {
if( parent.getCateId() == disease.getParentId())
{
parent.getChildUC().add(disease);
//当前数据有可能是别的数据的父节点加到父类容器
parentsList.add(disease);
break;
}
}
if (parent.getFloder().equals("false") ) {
if(parent.getUrlId() == disease.getParentId())
{
parent.getChildUC().add(disease);
//当前数据有可能是别的数据的父节点加到父类容器
parentsList.add(disease);
break;
}
}
}
}
}
ObjectMapper mapper = new ObjectMapper();
// java对象转换为json字符换
try {
String Json = mapper.writeValueAsString(resultList);
System.out.println(Json);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
return ;
} }
} }