Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
package com.lovenav.controller;
|
||||
|
||||
import com.lovenav.entity.Attachment;
|
||||
import com.lovenav.entity.Config;
|
||||
import com.lovenav.service.AttachmentService;
|
||||
import com.lovenav.service.ConfigService;
|
||||
import org.apache.catalina.core.ApplicationContext;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.context.support.ServletContextResource;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.servlet.ServletContext;
|
||||
import java.io.*;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static java.lang.System.out;
|
||||
|
||||
@RestController
|
||||
public class AttachmentController {
|
||||
//附件上传
|
||||
@Autowired
|
||||
AttachmentService attachmentService;
|
||||
@Autowired
|
||||
ConfigService configService;
|
||||
//上传附件
|
||||
@RequestMapping("/uploadfile")
|
||||
public HashMap<String, String> uploadFile(MultipartFile multipartFile,String cate,Config config) throws IOException {//@RequestPart("photos") MultipartFile multipartFile
|
||||
HashMap<String,String> map=new HashMap<>();
|
||||
Long id=null;
|
||||
if (multipartFile==null){
|
||||
map.put("msg","文件不能为空!");
|
||||
return map;
|
||||
}
|
||||
out.println(multipartFile.getOriginalFilename());
|
||||
map=attachmentService.upload(multipartFile,cate,id);
|
||||
config.setValue(map.get("id"));
|
||||
config.setType("image");
|
||||
map.put("msg",configService.addConfig(config));
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@GetMapping(value = "/getAttachment",produces =MediaType.IMAGE_JPEG_VALUE)//,produces = MediaType.IMAGE_JPEG_VALUE
|
||||
@ResponseBody
|
||||
public ResponseEntity getAttachment(Config config) throws Exception {
|
||||
byte[] bytes1 ;
|
||||
Config config1=configService.selectAlreadyExist(config);
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
if (config1==null){
|
||||
bytes1= "没有该Config!".getBytes();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
return new ResponseEntity<byte[]>(bytes1, headers, HttpStatus.NOT_FOUND);
|
||||
}
|
||||
Attachment attachment =attachmentService.selectAttachment(Long.valueOf(config1.getValue()));
|
||||
if (attachment==null){
|
||||
bytes1= "没有该Attachment!".getBytes();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
return new ResponseEntity<byte[]>(bytes1, headers, HttpStatus.NOT_FOUND);
|
||||
}
|
||||
String fileUrl=attachment.getPath()+attachment.getFileName()+attachment.getSuffix();
|
||||
out.println(fileUrl);
|
||||
out.println(attachment.getSuffix().replace(".",""));
|
||||
File file = new File(fileUrl);
|
||||
FileInputStream inputStream = new FileInputStream(file);
|
||||
byte[] bytes = new byte[inputStream.available()];
|
||||
inputStream.read(bytes, 0, inputStream.available());
|
||||
//设置ContentType的值 IMAGE_JPEG在浏览器返回图片
|
||||
if(attachment.getSuffix().replace(".","").equals("png")){
|
||||
headers.setContentType(MediaType.IMAGE_PNG);
|
||||
}else if (attachment.getSuffix().replace(".","").equals("jpeg")){
|
||||
headers.setContentType(MediaType.IMAGE_JPEG);
|
||||
}else{
|
||||
bytes= "没有该文件!".getBytes();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
return new ResponseEntity<byte[]>(bytes, headers, HttpStatus.NOT_FOUND);
|
||||
}
|
||||
// 内容是字节流
|
||||
return new ResponseEntity<byte[]>(bytes, headers, HttpStatus.OK);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,30 +1,47 @@
|
||||
package com.lovenav.controller;
|
||||
|
||||
import com.lovenav.entity.Config;
|
||||
import com.lovenav.service.AttachmentService;
|
||||
import com.lovenav.service.ConfigService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@RestController
|
||||
public class ConfigController {
|
||||
//配置文件操作
|
||||
@Autowired
|
||||
ConfigService configService;
|
||||
@Autowired
|
||||
AttachmentService attachmentService;
|
||||
@RequestMapping("/updateConfig")
|
||||
public String updateConfig(Config config){
|
||||
if (configService.updateConfis(config)==1){
|
||||
return "更新成功";
|
||||
Date date=new Date();
|
||||
int date1=Integer.valueOf(date.toString());
|
||||
config.setUpdatetime(date1);
|
||||
if (config==null){
|
||||
return "配置文件不能为空!";
|
||||
}
|
||||
else {
|
||||
return "更新配置失败";
|
||||
if (configService.updateConfig(config)==1){
|
||||
|
||||
return "更新成功!";
|
||||
}
|
||||
else if (configService.updateConfig(config)==2){
|
||||
return "不存在名称为"+config.getName()+"的配置文件,请先添加!";
|
||||
}
|
||||
return "更新失败!";
|
||||
}
|
||||
@RequestMapping("/addConfig")
|
||||
@RequestMapping("/addConfigString")
|
||||
public String addConfig(Config config){
|
||||
if (config.getName()==null||config.getValue()==null){
|
||||
return "属性值不能为空";
|
||||
}else {
|
||||
Date date=new Date();
|
||||
int date1=Integer.valueOf(date.toString());
|
||||
config.setUpdatetime(date1);
|
||||
return configService.addConfig(config);
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,36 @@
|
||||
package com.lovenav.controller;
|
||||
|
||||
import com.lovenav.entity.UrlAccess;
|
||||
import com.lovenav.service.UrlAccessService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
||||
@RestController
|
||||
public class UrlAccessController {
|
||||
|
||||
@Autowired
|
||||
UrlAccessService urlAccessService;
|
||||
|
||||
//浏览url,访问量加1
|
||||
@RequestMapping("/addUrlAccessViews")
|
||||
public String addUrlAccessViews(UrlAccess urlAccess){
|
||||
String result=urlAccessService.inreaseUrlViews(urlAccess);
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping("/getUrlAccess")
|
||||
public HashMap<Date, Object> getUrlAccess(UrlAccess urlAccess){
|
||||
HashMap<Date,Object> map=new HashMap<>();
|
||||
map=urlAccessService.getUrlAccess(urlAccess);
|
||||
if (map.isEmpty()){
|
||||
Date date=new Date();
|
||||
map.put(date,"查不到该数据");
|
||||
return map;
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
@@ -13,6 +13,7 @@ import com.lovenav.entity.UrlList;
|
||||
import com.lovenav.service.UrlCateListService;
|
||||
import com.lovenav.service.UrlListService;
|
||||
import com.lovenav.vo.CateAndUrl;
|
||||
import io.swagger.models.auth.In;
|
||||
import org.apache.poi.hssf.usermodel.HSSFCell;
|
||||
import org.apache.poi.hssf.usermodel.HSSFRow;
|
||||
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
||||
@@ -53,15 +54,15 @@ public class UrlAndCateController {
|
||||
UserDao userDao;
|
||||
//处理JSON
|
||||
@RequestMapping("/disposeJson")
|
||||
public String disposeJson(@RequestBody String data2 ,String email)
|
||||
public String disposeJson(@RequestBody String data2 ,Integer userId)
|
||||
{
|
||||
String jsonString;
|
||||
//先转换成ObjectMapper类型
|
||||
ObjectNode objectNode = objectMapper.createObjectNode();
|
||||
try {
|
||||
JsonNode rootNode = objectMapper.readTree(data2);
|
||||
disposeBookmarkFunction1(rootNode,"top",email);
|
||||
countCateContainUrlNumber(email);
|
||||
disposeBookmarkFunction1(rootNode,"top",userId);
|
||||
countCateContainUrlNumber(userId);
|
||||
HashMap<String, Object> result = new HashMap<>();
|
||||
result.put("code", 200);
|
||||
result.put("msg", "查询成功");
|
||||
@@ -71,23 +72,35 @@ public class UrlAndCateController {
|
||||
}
|
||||
return jsonString;
|
||||
}
|
||||
public void disposeBookmarkFunction1(JsonNode rootNode,String parent,String email)
|
||||
public void disposeBookmarkFunction1(JsonNode rootNode,String parent,Integer userId)
|
||||
{
|
||||
|
||||
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);
|
||||
if(String.valueOf(sonNode.get("type")).equals("\"folder\"")){
|
||||
String icon = String.valueOf(sonNode.get("icon"));
|
||||
System.out.println(icon.length());
|
||||
if (icon.length() == 2) icon ="https://imgbed.landaiqing.space/img/1/2023/12/25/1_6588644cb1f03_1703437387965_20231225.webp";
|
||||
else{
|
||||
icon=icon.substring(1,icon.length()-1);
|
||||
}
|
||||
urlCateListService.selectAndInsertUrlCate(userId,String.valueOf(sonNode.get("name")),parent,icon);
|
||||
JsonNode children = sonNode.get("children");
|
||||
disposeBookmarkFunction1(children, String.valueOf(sonNode.get("name")),email);
|
||||
disposeBookmarkFunction1(children, String.valueOf(sonNode.get("name")),userId);
|
||||
|
||||
}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 );
|
||||
String url = String.valueOf(sonNode.get("href")).substring(1,String.valueOf(sonNode.get("href")).length()-1);
|
||||
String icon = String.valueOf(sonNode.get("icon"));
|
||||
if (icon.length() == 2 )
|
||||
{
|
||||
icon="https://imgbed.landaiqing.space/img/1/2023/12/25/1_6588644cb1f03_1703437387965_20231225.webp";
|
||||
}else{
|
||||
icon =icon.substring(1,String.valueOf(sonNode.get("icon")).length()-1);
|
||||
}
|
||||
urlListService.selectCateAndInsertUrl(parent,name,icon , url,userId);
|
||||
// System.out.println(name +"---" + url + "---" + parent );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -110,13 +123,14 @@ public class UrlAndCateController {
|
||||
cateAndUrl.setName(urlCateList.getName());
|
||||
cateAndUrl.setParentId(urlCateList.getRootCateId());
|
||||
cateAndUrl.setCateId(urlCateList.getId());
|
||||
cateAndUrl.setNumber(urlCateList.getUrlNumber());
|
||||
cateAndUrlList.add(cateAndUrl);
|
||||
}
|
||||
for( int i = 0 ; i < urlLists.size() ; i++){
|
||||
UrlList urlList = urlLists.get(i);
|
||||
if(urlList.getStatus() == 0 ) continue;
|
||||
if(urlList.getStatus() == 1 ) continue;
|
||||
for(CateAndUrl cateAndUrl1 : cateAndUrlList) {
|
||||
if (urlList.getCateId() == cateAndUrl1.getCateId())
|
||||
if (String.valueOf(urlList.getCateId()).equals(cateAndUrl1.getCateId()+""))
|
||||
{
|
||||
CateAndUrl cateAndUrl = new CateAndUrl();
|
||||
cateAndUrl.setFloder("false");
|
||||
@@ -169,11 +183,11 @@ public class UrlAndCateController {
|
||||
List<UrlList> urlLists = urlListService.selectUrListByNeedLogin();
|
||||
List<CateAndUrl> cateAndUrlList = new ArrayList<>();
|
||||
Set<String> parentSet = new HashSet<>();
|
||||
List<Integer> integers = new ArrayList<>();
|
||||
for( int i = 0 ; i < urlLists.size() ; i++)
|
||||
{
|
||||
String parentString = urlCateListService.selectUrListCateByUrlCateId(urlLists.get(i).getCateId());
|
||||
String [] parentList = parentString.split(",");
|
||||
System.out.println(parentString);
|
||||
for(String parent : parentList)
|
||||
{
|
||||
if(parent.equals("0")){
|
||||
@@ -182,8 +196,13 @@ public class UrlAndCateController {
|
||||
parentSet.add(parent);
|
||||
}
|
||||
}
|
||||
|
||||
for (String str : parentSet) {
|
||||
for(String str : parentSet)
|
||||
{
|
||||
integers.add(Integer.valueOf(str));
|
||||
}
|
||||
Collections.sort(integers);
|
||||
for (Integer str : integers) {
|
||||
System.out.println(str);
|
||||
UrlCateList urlCateList =urlCateListService.selectByPrimaryKey(Integer.valueOf(str));
|
||||
CateAndUrl cateAndUrl = new CateAndUrl();
|
||||
cateAndUrl.setFloder("true");
|
||||
@@ -283,11 +302,11 @@ public class UrlAndCateController {
|
||||
}
|
||||
|
||||
|
||||
public String countCateContainUrlNumber(String email){
|
||||
public String countCateContainUrlNumber(Integer userId){
|
||||
HashMap<String, Object> result = new HashMap<>();
|
||||
result.put("code", 200);
|
||||
result.put("msg", "查询成功");
|
||||
result.put("data",urlCateListService.countCateContainUrlNumber(email));
|
||||
result.put("data",urlCateListService.countCateContainUrlNumber(userId));
|
||||
String jsonString = JSONObject.toJSONString(result);
|
||||
return jsonString;
|
||||
}
|
||||
@@ -444,12 +463,13 @@ public class UrlAndCateController {
|
||||
public String disposeBookmarkExhibitedToJsonNew(){
|
||||
List<UrlList> urlLists = urlListService.selectUrListByNeedLogin();
|
||||
List<CateAndUrl> cateAndUrlList = new ArrayList<>();
|
||||
CateAndUrl pub = new CateAndUrl();
|
||||
Set<String> parentSet = new HashSet<>();
|
||||
for( int i = 0 ; i < urlLists.size() ; i++)
|
||||
{
|
||||
String parentString = urlCateListService.selectUrListCateByUrlCateId(urlLists.get(i).getCateId());
|
||||
if(parentString == null) continue;
|
||||
String [] parentList = parentString.split(",");
|
||||
System.out.println(parentString);
|
||||
for(String parent : parentList)
|
||||
{
|
||||
if(parent.equals("0")){
|
||||
@@ -458,18 +478,22 @@ public class UrlAndCateController {
|
||||
parentSet.add(parent);
|
||||
}
|
||||
}
|
||||
for (String str : parentSet) {
|
||||
List<String> ls=Arrays.asList(parentSet.toArray(new String[0]));
|
||||
Collections.sort(ls);
|
||||
for (String str : ls) {
|
||||
System.out.println(str);
|
||||
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());
|
||||
cateAndUrl.setNumber(urlCateList.getUrlNumber());
|
||||
cateAndUrlList.add(cateAndUrl);
|
||||
}
|
||||
for( int i = 0 ; i < urlLists.size() ; i++){
|
||||
UrlList urlList = urlLists.get(i);
|
||||
if(urlList.getStatus() == 0 ) continue ;
|
||||
if(urlList.getStatus() == 1 ) continue ;
|
||||
CateAndUrl cateAndUrl = new CateAndUrl();
|
||||
cateAndUrl.setFloder("false");
|
||||
cateAndUrl.setName(urlList.getName());
|
||||
@@ -489,13 +513,27 @@ public class UrlAndCateController {
|
||||
cateAndUrl.setIsAd(urlList.getIsAd());
|
||||
cateAndUrl.setIsTop(urlList.getIsTop());
|
||||
cateAndUrl.setIsEncrypt(urlList.getIsEncrypt());
|
||||
int flag =0 ;
|
||||
for(CateAndUrl cateAndUrl1 : cateAndUrlList){
|
||||
if(cateAndUrl.getParentId() == cateAndUrl1.getCateId())
|
||||
if(String.valueOf(urlList.getCateId()).equals(cateAndUrl1.getCateId()+""))
|
||||
{
|
||||
flag = 1;
|
||||
cateAndUrl1.getChildUC().add(cateAndUrl);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(flag == 0)
|
||||
{
|
||||
pub.setName("默认文件夹");
|
||||
|
||||
pub.getChildUC().add(cateAndUrl);
|
||||
}
|
||||
}
|
||||
|
||||
if(pub.getChildUC().size()!=0)
|
||||
{
|
||||
pub.setNumber(Long.valueOf(pub.getChildUC().size()));
|
||||
cateAndUrlList.add(pub);
|
||||
}
|
||||
return JSONObject.toJSONString(cateAndUrlList);
|
||||
|
||||
@@ -529,6 +567,7 @@ public class UrlAndCateController {
|
||||
cateAndUrl.setName(urlCateList.getName());
|
||||
cateAndUrl.setParentId(urlCateList.getRootCateId());
|
||||
cateAndUrl.setCateId(urlCateList.getId());
|
||||
cateAndUrl.setNumber(urlCateList.getUrlNumber());
|
||||
cateAndUrlList.add(cateAndUrl);
|
||||
}
|
||||
|
||||
@@ -630,7 +669,7 @@ public class UrlAndCateController {
|
||||
|
||||
}
|
||||
|
||||
urlCateListService.countCateContainUrlNumber(userDao.selectByPrimaryKey(Integer.valueOf(userId)).getUserEmail());
|
||||
urlCateListService.countCateContainUrlNumber(userDao.selectByPrimaryKey(Integer.valueOf(userId)).getId());
|
||||
result.put("code", 200);
|
||||
result.put("msg", "处理成功");
|
||||
return JSONObject.toJSONString(result);
|
||||
|
@@ -1,15 +1,18 @@
|
||||
package com.lovenav.controller;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.lovenav.entity.LoginLogs;
|
||||
import com.lovenav.entity.UrlList;
|
||||
import com.lovenav.entity.User;
|
||||
import com.lovenav.service.ConfigService;
|
||||
import com.lovenav.service.LoginLogsService;
|
||||
import com.lovenav.service.UserService;
|
||||
import com.lovenav.utils.MD5Utils;
|
||||
import com.lovenav.utils.RandomValidateCode;
|
||||
import com.lovenav.utils.TokenUtils;
|
||||
import com.lovenav.utils.*;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpRequest;
|
||||
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
@@ -34,6 +37,12 @@ public class UserController {
|
||||
UserService userService;
|
||||
@Autowired
|
||||
TokenUtils tokenUtils;
|
||||
@Autowired
|
||||
LoginLogsService loginLogsService;
|
||||
@Autowired
|
||||
ConfigService configService;
|
||||
@Autowired
|
||||
IPutils iPutils;
|
||||
//发送邮箱验证码
|
||||
ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(5);
|
||||
//这个是我用户Service实现类可以自行替换
|
||||
@@ -42,8 +51,14 @@ public class UserController {
|
||||
|
||||
@GetMapping("/sendActiveCode")
|
||||
public String sendActiveCode(HttpSession session, User user){
|
||||
|
||||
String activecode=userService.sendEmailActivecode(user);
|
||||
HashMap<String,String> configMap=new HashMap<>();
|
||||
configMap=configService.selectEmailConfig();
|
||||
String activecode=userService.sendEmailActivecode(user,configMap);
|
||||
if (activecode=="配置文件有错误"){
|
||||
return "邮箱配置文件有错误,请重新确认!";
|
||||
} else if (activecode=="该邮箱不存在") {
|
||||
return "将要发送的邮箱不存在!";
|
||||
}
|
||||
session.setAttribute(user.getUserEmail(),activecode);
|
||||
scheduledExecutorService.schedule(new Runnable() {
|
||||
@Override
|
||||
@@ -80,7 +95,8 @@ public class UserController {
|
||||
return "注册成功!";
|
||||
}
|
||||
@RequestMapping(value = "/login",produces = {"application/json;charset=UTF-8"})
|
||||
public Map<String,Object>login(User user,String code,HttpSession session){
|
||||
public Map<String,Object>login(User user, String code, HttpSession session, HttpServletRequest request){
|
||||
LoginLogs loginLogs=new LoginLogs();
|
||||
Map<String,Object> result=new HashMap<>();
|
||||
Map<String,Object> map=new HashMap<>();
|
||||
|
||||
@@ -99,9 +115,18 @@ public class UserController {
|
||||
return result;
|
||||
}
|
||||
|
||||
User user1 = userService.userLogin(user);
|
||||
|
||||
String ip=IPutils.getIpAddress(request);
|
||||
System.out.println(ip);
|
||||
|
||||
String locat= String.valueOf(IPutils.getLocation(ip));
|
||||
User user1 = userService.userLogin(user);
|
||||
|
||||
if(user1!=null){
|
||||
loginLogs.setUserId(user1.getId());
|
||||
loginLogs.setLoginIp(ip);
|
||||
loginLogs.setLocation(locat);
|
||||
loginLogsService.addLoginLogs(loginLogs);
|
||||
result.put("code",200);
|
||||
map.put("userEmail",user1.getUserEmail());
|
||||
map.put("userLogin",user1.getUserLogin());
|
||||
@@ -166,6 +191,9 @@ public class UserController {
|
||||
return map;
|
||||
|
||||
}
|
||||
|
||||
@RequestMapping("/getAllUsers")
|
||||
public HashMap<Integer,Object> getAllUsers(){
|
||||
return userService.getAllUsers();
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user