Merge remote-tracking branch 'origin/master'

This commit is contained in:
2023-12-22 21:52:47 +08:00
28 changed files with 1065 additions and 76 deletions

View File

@@ -0,0 +1,30 @@
package com.lovenav.controller;
import com.alibaba.fastjson2.JSONObject;
import com.lovenav.dao.AuthDao;
import com.lovenav.entity.Auth;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.List;
@RestController
@RequestMapping("/Auth")
public class AuthController {
@Autowired
AuthDao authDao;
@RequestMapping("/retAllAuth")
public String retAllAuth(){
List<Auth> auths = authDao.selectAllAuth();
HashMap<String, Object> result = new HashMap<>();
result.put("code", 200);
result.put("msg", "查询结果");
result.put("data",auths);
String jsonString = JSONObject.toJSONString(result);
return jsonString;
}
}

View File

@@ -0,0 +1,40 @@
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;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/banners")
public class BannersController {
@Autowired
private BannersService bannersService;
// 跳转链接
@RequestMapping(method = RequestMethod.GET, value = "/jump_url")
public String jump(int id){
return bannersService.Jump_url(id);
}
// 添加banner
@RequestMapping(method = RequestMethod.POST, value = "/add_banner")
public String add(@RequestBody Banners banners){
return bannersService.Add_banner(banners);
}
// 删除banner
@RequestMapping(method = RequestMethod.GET, value = "/delete_url")
public String delete(int id){
return bannersService.Delete_banner(id);
}
// 首页显示banner
@RequestMapping(method = RequestMethod.GET, value = "/view_banner")
public String view(){
return bannersService.View_banner();
}
}

View File

@@ -21,15 +21,15 @@ public class CommentController {
@Autowired
private CommentService commentService;
// 评论功能
@RequestMapping(method = RequestMethod.POST, value = "/reply_comment")
@RequestMapping(method = RequestMethod.POST, value = "/comment")
public String Reply1(@RequestBody Comment comment){
return commentService.Reply1(comment);
}
// 回复功能
@RequestMapping(method = RequestMethod.POST, value = "/comment")
public String Reply2(@RequestBody Comment comment){
return commentService.Reply2(comment);
@RequestMapping(method = RequestMethod.POST, value = "/reply_comment")
public String Reply2(@RequestBody Comment comment,int id){
return commentService.Reply2(comment,id);
}
// 删除功能
@RequestMapping(method = RequestMethod.GET, value = "/delete_comment")
@@ -40,4 +40,16 @@ public class CommentController {
public String addLikeCount(int id){
return commentService.AddLikeCount(id);
}
// 显示评论
@RequestMapping(method = RequestMethod.GET, value = "/view_comment")
public String View_comment(){
return commentService.View_comment();
}
// 显示回复
@RequestMapping(method = RequestMethod.GET, value = "/view_reply")
public String View_reply(int id){
return commentService.View_Reply(id);
}
}

View File

@@ -0,0 +1,27 @@
package com.lovenav.controller;
import com.alibaba.fastjson.JSON;
import com.lovenav.utils.QRCodeUtil;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class QRCodeController {
private QRCodeUtil qrCodeUtil;
@RequestMapping(method = RequestMethod.GET, value = "/qrc")
public String QRCode(String url){
String text = url;
String logoPath ="src/main/resources/static/logo/NAV.png";
String destPath = "src/main/resources/static/qr";
try {
String url2 = qrCodeUtil.encode(text, logoPath, destPath, true);
String base64 = qrCodeUtil.getBase64(url2);
return JSON.toJSONString(base64);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

View File

@@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
@@ -42,6 +43,7 @@ public class SearchController {
redisService.addSearchHistoryByUserId(userId, searchKey);
redisService.incrementScoreByUserId(searchKey);
redisService.incrementScore(searchKey);
//返回网站数据
@@ -67,15 +69,41 @@ public class SearchController {
@RequestMapping("/getSearchHistoryByUserId")
public String getSearchHistoryByUserId(String userId)
{
String res = "123";
return res;
List<String> stringList = redisService.getSearchHistoryByUserId(userId);
HashMap<String, Object> result = new HashMap<>();
result.put("code", 200);
result.put("msg", "查询成功");
result.put("data",stringList);
String jsonString = JSONObject.toJSONString(result);
return jsonString;
}
/**
* 删除个人历史数据
*/
@RequestMapping("/delSearchHistoryByUserId")
public String delSearchHistoryByUserId(String userId, String searchKey){
String res = "123";
return res;
Long f = redisService.delSearchHistoryByUserId(userId,searchKey);
HashMap<String, Object> result = new HashMap<>();
result.put("code", 200);
result.put("msg", "删除结果");
result.put("data",f);
String jsonString = JSONObject.toJSONString(result);
return jsonString;
}
/**
* 根据searchKey搜索其相关最热的前十名 (如果searchKey为null空则返回redis存储的前十最热词条)
*/
@RequestMapping("/getHotList")
public String getHotList(String searchKey){
List<String> stringList = redisService.getHotList(searchKey);
HashMap<String, Object> result = new HashMap<>();
result.put("code", 200);
result.put("msg", "查询结果");
result.put("data",stringList);
String jsonString = JSONObject.toJSONString(result);
return jsonString;
}
}

View File

@@ -1,5 +1,7 @@
package com.lovenav.controller;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
@@ -10,15 +12,20 @@ import com.lovenav.entity.UrlList;
import com.lovenav.service.UrlCateListService;
import com.lovenav.service.UrlListService;
import com.lovenav.vo.CateAndUrl;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
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.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;
import java.io.*;
@RestController
@RequestMapping("/UrlAndCate")
public class UrlAndCateController {
@@ -43,6 +50,7 @@ public class UrlAndCateController {
try {
JsonNode rootNode = objectMapper.readTree(data2);
disposeBookmarkFunction1(rootNode,"top",email);
countCateContainUrlNumber(email);
HashMap<String, Object> result = new HashMap<>();
result.put("code", 200);
result.put("msg", "查询成功");
@@ -80,9 +88,9 @@ public class UrlAndCateController {
//处理成JSON
@RequestMapping("/disposeBookmarkToJson")
public String disposeBookmarkToJson(Integer userId)
public String disposeBookmarkToJson(String userId)
{
List<UrlCateList> urlCateLists = urlCateListService.selectUrListByUserId(userId);
List<UrlCateList> urlCateLists = urlCateListService.selectUrListByUserId(Integer.valueOf(userId));
List<UrlList> urlLists = urlListService.selectUrList();
List<CateAndUrl> cateAndUrlList = new ArrayList<>();
@@ -185,4 +193,90 @@ public class UrlAndCateController {
String jsonString = JSONObject.toJSONString(result);
return jsonString;
}
public String countCateContainUrlNumber(String email){
HashMap<String, Object> result = new HashMap<>();
result.put("code", 200);
result.put("msg", "查询成功");
result.put("data",urlCateListService.countCateContainUrlNumber(email));
String jsonString = JSONObject.toJSONString(result);
return jsonString;
}
//处理成JSON
// @RequestMapping("/disposeJsonToExcel")
// public String disposeJsonToExcel(String userId)
// {
//
// HashMap<String, Object> result = new HashMap<>();
// result.put("code", 200);
// result.put("msg", "查询成功");
// result.put("data",urlCateListService.getUrl(userId));
// String jsonString = JSONObject.toJSONString(result);
// return jsonString;
// }
/**
* json 转 excel
* @param jsonArray
* @return
* @throws IOException
*/
public HSSFWorkbook jsonToExcel(JSONArray jsonArray) throws IOException {
Set<String> keys = new HashSet<>();
// 创建HSSFWorkbook对象
HSSFWorkbook wb = new HSSFWorkbook();
// 创建HSSFSheet对象
HSSFSheet sheet = wb.createSheet("sheet0");
List<JSONObject> jsonObjects = jsonArray.toList(JSONObject.class);
// 创建HSSFRow对象
HSSFRow row ;
for (int i=0;i<jsonObjects.size();i++){
String temp = jsonObjects.get(i).keySet().toString();
String target = temp.substring(1,temp.length()-1);
keys.add(target);
}
for( int i =0 ;i<jsonObjects.size(); i++)
{
row = sheet.createRow(i);
HSSFCell cell = row.createCell(0);
String temp = jsonObjects.get(i).keySet().toString();
String target = temp.substring(1,temp.length()-1);
String target1 = temp.substring(2,temp.length()-2);
cell.setCellValue(target1);
cell = row.createCell(1);
cell.setCellValue(jsonObjects.get(i).get(target).toString().substring(2,temp.length()-2));
}
return wb;
}
@RequestMapping ("/dataDownload/excel")
@ResponseBody
public String exportExcel(String userId, HttpServletResponse response) {
try {
//此处为你的json数组
HSSFWorkbook sheets = jsonToExcel(urlCateListService.getUrl(userId));
// 配置文件下载
response.setHeader("content-type", "application/octet-stream");
response.setContentType("application/octet-stream");
// 下载文件能正常显示中文
response.setHeader("Content-Disposition", "attachment;filename=data.xls");
OutputStream os = response.getOutputStream();
sheets.write(os);
sheets.close();
os.close();
return null;
} catch (Exception e) {
e.printStackTrace();
HashMap<String, Object> result = new HashMap<>();
result.put("code", 500);
result.put("msg", "下载失败");
return JSON.toJSONString(result);
}
}
}