Merge remote-tracking branch 'origin/master'

This commit is contained in:
2023-12-23 16:30:01 +08:00
20 changed files with 238 additions and 26 deletions

View File

@@ -1,6 +1,5 @@
package com.lovenav.controller;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.lovenav.entity.Banners;
import com.lovenav.service.BannersService;
import org.springframework.beans.factory.annotation.Autowired;

View File

@@ -1,19 +1,10 @@
package com.lovenav.controller;
import com.alibaba.fastjson2.JSONObject;
import com.lovenav.entity.Comment;
import com.lovenav.service.CommentService;
import com.lovenav.service.serviceImpl.CommentServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.HashMap;
@RestController
@RequestMapping("/comment")

View File

@@ -182,6 +182,100 @@ public class UrlAndCateController {
}
return JSONObject.toJSONString(result);
}
@RequestMapping("/disposeBookmarkExhibitedToJson")
public String disposeBookmarkExhibitedToJson()
{
List<UrlList> urlLists = urlListService.selectUrListByNeedLogin();
List<CateAndUrl> cateAndUrlList = new ArrayList<>();
Set<String> parentSet = new HashSet<>();
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);
String parentString = urlCateListService.selectUrListCateByUrlCateId(urlLists.get(i).getCateId());
String [] parentList = parentString.split(",");
for(String parent : parentList)
{
if(parent.equals("0")){
continue;
}
parentSet.add(parent);
}
}
for (String str : parentSet) {
UrlCateList urlCateList =urlCateListService.selectByPrimaryKey(Integer.valueOf(str));
CateAndUrl cateAndUrl = new CateAndUrl();
cateAndUrl.setFloder("true");
cateAndUrl.setName(urlCateList.getName());
cateAndUrl.setParentId(urlCateList.getRootCateId());
cateAndUrl.setCateId(urlCateList.getId());
cateAndUrlList.add(cateAndUrl);
}
Collections.reverse(cateAndUrlList);
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);

View File

@@ -21,5 +21,5 @@ public interface BannersDao {
int updateByPrimaryKey(Banners record);
List<Banners> selectByAllBanners();
List<Banners> selectAllBanners();
}

View File

@@ -22,7 +22,7 @@ public interface CommentDao {
int updateByPrimaryKey(Comment record);
List<Comment> selectByAllComment();
List<Comment> selectAllComment();
List<Comment> selectByAllReply(int id);
}

View File

@@ -30,4 +30,5 @@ public interface UrlCateListDao {
public List<UrlCateList> selectUrListByUserId(Integer userId);
public String selectUrListCateByUrlCateId(Integer cateId);
}

View File

@@ -29,5 +29,7 @@ public interface UrlListDao {
public UrlList selectUrlListByUrlId(Long urlId);
public List<UrlList> selectUrListByNeedLogin();
}

View File

@@ -2,9 +2,6 @@ package com.lovenav.entity;
import java.io.Serializable;
import java.util.Date;
import com.alibaba.fastjson2.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
/**

View File

@@ -14,4 +14,7 @@ public interface UrlCateListService {
public String countCateContainUrlNumber(String userId);
public JSONArray getUrl(String userId);
public String selectUrListCateByUrlCateId(Integer cateId);
public UrlCateList selectByPrimaryKey(Integer id);
}

View File

@@ -13,5 +13,5 @@ public interface UrlListService {
public int updateUrlStatusListById(UrlList urlList);
public List<UrlList> selectUrListByNeedLogin();
}

View File

@@ -1,6 +1,6 @@
package com.lovenav.service.serviceImpl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSON;
import com.lovenav.dao.BannersDao;
import com.lovenav.entity.Banners;
import com.lovenav.service.BannersService;
@@ -59,9 +59,8 @@ public class BannersServiceImpl implements BannersService {
}
// 展示banner
@Override
public String View_banner(){
List<Banners> list = bannersDao.selectByAllBanners();
List<Banners> list = bannersDao.selectAllBanners();
return JSON.toJSONString(list);
}
}

View File

@@ -6,11 +6,8 @@ import com.lovenav.dao.CommentDao;
import com.lovenav.dao.UserDao;
import com.lovenav.entity.Comment;
import com.lovenav.service.CommentService;
import org.apache.ibatis.jdbc.Null;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
@@ -69,7 +66,7 @@ public class CommentServiceImpl implements CommentService {
// 显示评论
public String View_comment(){
List<Comment> list = commentDao.selectByAllComment();
List<Comment> list = commentDao.selectAllComment();
return JSON.toJSONString(list);
}

View File

@@ -58,7 +58,14 @@ public class UrlCateListServiceImpl implements UrlCateListService {
return urlCateListDao.selectUrListByUserId(userId);
}
public String selectUrListCateByUrlCateId(Integer cateId){
return urlCateListDao.selectUrListCateByUrlCateId(cateId);
}
public UrlCateList selectByPrimaryKey(Integer id)
{
return urlCateListDao.selectByPrimaryKey(id);
}
public String countCateContainUrlNumber(String email){
User user = userDao.selectByEmail(email);

View File

@@ -41,6 +41,8 @@ public class UrlLiserServiceImpl implements UrlListService {
Date date = new Date();
urlList.setCreatetime(date.getTime());
urlList.setViews(Long.valueOf("0"));
Byte b = 0;
urlList.setNeedLogin(b);
int flag = urlListDao.insert(urlList);
return flag;
}
@@ -49,6 +51,13 @@ public class UrlLiserServiceImpl implements UrlListService {
return urlListDao.selectUrList();
}
public List<UrlList> selectUrListByNeedLogin(){
return urlListDao.selectUrListByNeedLogin();
}
public UrlList selectUrListByInput(String input)
{
return urlListDao.selectUrListByInput(input);

View File

@@ -0,0 +1,74 @@
package com.lovenav.utils;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import sun.net.www.protocol.http.HttpURLConnection;
import java.io.IOException;
import java.net.*;
import javax.net.ssl.HttpsURLConnection;
public class UrlCheckUtil {
/**
* 判断链接是否有效
* 输入链接
* 返回true或者false
*/
public static boolean isUrlValid(String strLink) {
URL url;
try {
url = new URL(strLink);
HttpURLConnection connt = (HttpURLConnection)url.openConnection();
connt.setRequestMethod("HEAD");
String strMessage = connt.getResponseMessage();
if (strMessage.compareTo("Not Found") == 0) {
return false;
}
connt.disconnect();
} catch (Exception e) {
return false;
}
return true;
}
public static String checkUrlConnection(String url) {
// 创建http POST请求
HttpGet httpGet = new HttpGet(url);
httpGet.setHeader("Content-Type", "application/json");
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(600)// 设置连接主机服务超时时间
.setConnectionRequestTimeout(1000)// 设置连接请求超时时间
.setSocketTimeout(1000)// 设置读取数据连接超时时间
.build();
// 为httpPost实例设置配置
httpGet.setConfig(requestConfig);
// 设置请求头
CloseableHttpClient httpclient = null;
CloseableHttpResponse response = null;
int statusCode = 404;
try {
httpclient = HttpClients.createDefault();// 创建Httpclient对象
response = httpclient.execute(httpGet);// 执行请求
statusCode = response.getStatusLine().getStatusCode();
}catch (SocketException e) {
return "404";
} catch (IOException e) {
System.out.println("报错");
return "404";
}
return String.valueOf(statusCode);
}
public static boolean CheckHttp(String address) throws URISyntaxException, MalformedURLException {
URL url = new URL(address);
URI uri = url.toURI();
System.out.println(uri.getScheme());
if(uri.getScheme().equals("https")){
return true;
}else
return false;
}
}