Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
1e3f589326
19
pom.xml
19
pom.xml
@ -139,13 +139,30 @@
|
||||
<artifactId>javase</artifactId>
|
||||
<version>3.3.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.ws.commons.axiom</groupId>
|
||||
<artifactId>base64-utils</artifactId>
|
||||
<version>1.4.0</version>
|
||||
</dependency>
|
||||
|
||||
<!--检测URl依赖-->
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.5.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpcore</artifactId>
|
||||
<version>4.4.14</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- jackson 2.x 相关依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
|
@ -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;
|
||||
|
@ -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")
|
||||
|
@ -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);
|
||||
|
@ -21,5 +21,5 @@ public interface BannersDao {
|
||||
|
||||
int updateByPrimaryKey(Banners record);
|
||||
|
||||
List<Banners> selectByAllBanners();
|
||||
List<Banners> selectAllBanners();
|
||||
}
|
@ -22,7 +22,7 @@ public interface CommentDao {
|
||||
|
||||
int updateByPrimaryKey(Comment record);
|
||||
|
||||
List<Comment> selectByAllComment();
|
||||
List<Comment> selectAllComment();
|
||||
|
||||
List<Comment> selectByAllReply(int id);
|
||||
}
|
@ -30,4 +30,5 @@ public interface UrlCateListDao {
|
||||
|
||||
|
||||
public List<UrlCateList> selectUrListByUserId(Integer userId);
|
||||
public String selectUrListCateByUrlCateId(Integer cateId);
|
||||
}
|
@ -29,5 +29,7 @@ public interface UrlListDao {
|
||||
|
||||
public UrlList selectUrlListByUrlId(Long urlId);
|
||||
|
||||
public List<UrlList> selectUrListByNeedLogin();
|
||||
|
||||
|
||||
}
|
@ -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;
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
|
@ -13,5 +13,5 @@ public interface UrlListService {
|
||||
|
||||
public int updateUrlStatusListById(UrlList urlList);
|
||||
|
||||
|
||||
public List<UrlList> selectUrListByNeedLogin();
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
74
src/main/java/com/lovenav/utils/UrlCheckUtil.java
Normal file
74
src/main/java/com/lovenav/utils/UrlCheckUtil.java
Normal 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;
|
||||
}
|
||||
|
||||
}
|
@ -97,10 +97,11 @@
|
||||
</update>
|
||||
|
||||
|
||||
<select id="selectByAllBanners" parameterType="java.lang.Integer" resultMap="BaseResultMap">
|
||||
<select id="selectAllBanners" parameterType="java.lang.Integer" resultMap="BaseResultMap">
|
||||
select
|
||||
*
|
||||
from ln_banners
|
||||
where banner_status = 0;
|
||||
</select>
|
||||
|
||||
</mapper>
|
@ -146,7 +146,7 @@
|
||||
</update>
|
||||
|
||||
|
||||
<select id="selectByAllComment" parameterType="java.lang.Integer" resultMap="BaseResultMap">
|
||||
<select id="selectAllComment" parameterType="java.lang.Integer" resultMap="BaseResultMap">
|
||||
select
|
||||
*
|
||||
from ln_comment
|
||||
|
@ -13,6 +13,10 @@
|
||||
<result column="root_cate_id" jdbcType="INTEGER" property="rootCateId" />
|
||||
<result column="ico" jdbcType="VARCHAR" property="ico" />
|
||||
</resultMap>
|
||||
|
||||
|
||||
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id, `name`, createtime, url_number, weigh, `status`, need_login, user_id, root_cate_id,
|
||||
ico
|
||||
@ -38,6 +42,16 @@
|
||||
where name = #{name ,jdbcType=VARCHAR} and user_id = #{userId,jdbcType=INTEGER}
|
||||
</select>
|
||||
|
||||
<select id="selectUrListCateByUrlCateId" parameterType="java.lang.Integer" resultType="java.lang.String">
|
||||
SELECT t3.isparent
|
||||
FROM(SELECT t1.*,
|
||||
IF (FIND_IN_SET(id, @ids) > 0,@ids := CONCAT( root_cate_id,',', @ids),'0') AS isparent
|
||||
FROM(SELECT t.id,t.root_cate_id,t.name
|
||||
FROM ln_url_cate_list AS t
|
||||
ORDER BY t.id DESC) t1,
|
||||
(SELECT @ids := #{cateId ,jdbcType=INTEGER}) t2) t3
|
||||
WHERE t3.isparent != '0' and t3.id =#{cateId ,jdbcType=INTEGER}
|
||||
</select>
|
||||
|
||||
|
||||
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
|
||||
|
@ -37,6 +37,13 @@
|
||||
from ln_url_list
|
||||
</select>
|
||||
|
||||
<select id="selectUrListByNeedLogin" resultMap="BaseResultMap">
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
from ln_url_list
|
||||
where need_login = 1
|
||||
</select>
|
||||
|
||||
<select id="selectUrListByInput" parameterType="java.lang.String" resultMap="BaseResultMap">
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
|
Loading…
Reference in New Issue
Block a user