Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
65f76703b8
36
pom.xml
36
pom.xml
@ -48,6 +48,12 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-mail</artifactId>
|
<artifactId>spring-boot-starter-mail</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!--获取邮箱头像所需要的依赖 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hutool</groupId>
|
||||||
|
<artifactId>hutool-all</artifactId>
|
||||||
|
<version>5.3.7</version>
|
||||||
|
</dependency>
|
||||||
<!--解析HTML将其转成字符串 -->
|
<!--解析HTML将其转成字符串 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jsoup</groupId>
|
<groupId>org.jsoup</groupId>
|
||||||
@ -72,6 +78,17 @@
|
|||||||
<artifactId>java-jwt</artifactId>
|
<artifactId>java-jwt</artifactId>
|
||||||
<version>3.4.0</version>
|
<version>3.4.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!--文件上传依赖-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-fileupload</groupId>
|
||||||
|
<artifactId>commons-fileupload</artifactId>
|
||||||
|
<version>1.4</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-io</groupId>
|
||||||
|
<artifactId>commons-io</artifactId>
|
||||||
|
<version>2.5</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!--引入lombok-->
|
<!--引入lombok-->
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -111,11 +128,24 @@
|
|||||||
<artifactId>fastjson</artifactId>
|
<artifactId>fastjson</artifactId>
|
||||||
<version>1.2.47</version>
|
<version>1.2.47</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- IP归属地-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>org.lionsoul</groupId>
|
||||||
<artifactId>commons-lang3</artifactId>
|
<artifactId>ip2region</artifactId>
|
||||||
<version>3.4</version>
|
<version>2.6.5</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.springfox</groupId>
|
||||||
|
<artifactId>springfox-swagger2</artifactId>
|
||||||
|
<version>2.7.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.springfox</groupId>
|
||||||
|
<artifactId>springfox-swagger-ui</artifactId>
|
||||||
|
<version>2.7.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.fastjson2</groupId>
|
<groupId>com.alibaba.fastjson2</groupId>
|
||||||
|
@ -8,7 +8,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|||||||
public class MyWebConfigurer implements WebMvcConfigurer {
|
public class MyWebConfigurer implements WebMvcConfigurer {
|
||||||
@Override
|
@Override
|
||||||
public void addInterceptors(InterceptorRegistry registry) {
|
public void addInterceptors(InterceptorRegistry registry) {
|
||||||
registry.addInterceptor(new UserInterceptor()).addPathPatterns("/*/**").excludePathPatterns("/error","/login","/register","/findThePassword","/verifyCode","/sendActiveCode");
|
// registry.addInterceptor(new UserInterceptor()).addPathPatterns("/*/**").excludePathPatterns("/error","/login","/register","/findThePassword","/verifyCode","/sendActiveCode");
|
||||||
WebMvcConfigurer.super.addInterceptors(registry);
|
WebMvcConfigurer.super.addInterceptors(registry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
package com.lovenav.controller;
|
||||||
|
|
||||||
import com.lovenav.entity.Config;
|
import com.lovenav.entity.Config;
|
||||||
|
import com.lovenav.service.AttachmentService;
|
||||||
import com.lovenav.service.ConfigService;
|
import com.lovenav.service.ConfigService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
public class ConfigController {
|
public class ConfigController {
|
||||||
|
//配置文件操作
|
||||||
@Autowired
|
@Autowired
|
||||||
ConfigService configService;
|
ConfigService configService;
|
||||||
|
@Autowired
|
||||||
|
AttachmentService attachmentService;
|
||||||
@RequestMapping("/updateConfig")
|
@RequestMapping("/updateConfig")
|
||||||
public String updateConfig(Config config){
|
public String updateConfig(Config config){
|
||||||
if (configService.updateConfis(config)==1){
|
Date date=new Date();
|
||||||
return "更新成功";
|
int date1=Integer.valueOf(date.toString());
|
||||||
|
config.setUpdatetime(date1);
|
||||||
|
if (config==null){
|
||||||
|
return "配置文件不能为空!";
|
||||||
}
|
}
|
||||||
else {
|
if (configService.updateConfig(config)==1){
|
||||||
return "更新配置失败";
|
|
||||||
|
return "更新成功!";
|
||||||
}
|
}
|
||||||
|
else if (configService.updateConfig(config)==2){
|
||||||
|
return "不存在名称为"+config.getName()+"的配置文件,请先添加!";
|
||||||
}
|
}
|
||||||
@RequestMapping("/addConfig")
|
return "更新失败!";
|
||||||
|
}
|
||||||
|
@RequestMapping("/addConfigString")
|
||||||
public String addConfig(Config config){
|
public String addConfig(Config config){
|
||||||
if (config.getName()==null||config.getValue()==null){
|
if (config.getName()==null||config.getValue()==null){
|
||||||
return "属性值不能为空";
|
return "属性值不能为空";
|
||||||
}else {
|
}else {
|
||||||
|
Date date=new Date();
|
||||||
|
int date1=Integer.valueOf(date.toString());
|
||||||
|
config.setUpdatetime(date1);
|
||||||
return configService.addConfig(config);
|
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;
|
||||||
|
}
|
||||||
|
}
|
@ -1,15 +1,18 @@
|
|||||||
package com.lovenav.controller;
|
package com.lovenav.controller;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
|
import com.lovenav.entity.LoginLogs;
|
||||||
import com.lovenav.entity.UrlList;
|
import com.lovenav.entity.UrlList;
|
||||||
import com.lovenav.entity.User;
|
import com.lovenav.entity.User;
|
||||||
|
import com.lovenav.service.ConfigService;
|
||||||
|
import com.lovenav.service.LoginLogsService;
|
||||||
import com.lovenav.service.UserService;
|
import com.lovenav.service.UserService;
|
||||||
import com.lovenav.utils.MD5Utils;
|
import com.lovenav.utils.*;
|
||||||
import com.lovenav.utils.RandomValidateCode;
|
|
||||||
import com.lovenav.utils.TokenUtils;
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
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.mail.javamail.JavaMailSenderImpl;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
@ -34,6 +37,12 @@ public class UserController {
|
|||||||
UserService userService;
|
UserService userService;
|
||||||
@Autowired
|
@Autowired
|
||||||
TokenUtils tokenUtils;
|
TokenUtils tokenUtils;
|
||||||
|
@Autowired
|
||||||
|
LoginLogsService loginLogsService;
|
||||||
|
@Autowired
|
||||||
|
ConfigService configService;
|
||||||
|
@Autowired
|
||||||
|
IPutils iPutils;
|
||||||
//发送邮箱验证码
|
//发送邮箱验证码
|
||||||
ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(5);
|
ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(5);
|
||||||
//这个是我用户Service实现类可以自行替换
|
//这个是我用户Service实现类可以自行替换
|
||||||
@ -42,8 +51,14 @@ public class UserController {
|
|||||||
|
|
||||||
@GetMapping("/sendActiveCode")
|
@GetMapping("/sendActiveCode")
|
||||||
public String sendActiveCode(HttpSession session, User user){
|
public String sendActiveCode(HttpSession session, User user){
|
||||||
|
HashMap<String,String> configMap=new HashMap<>();
|
||||||
String activecode=userService.sendEmailActivecode(user);
|
configMap=configService.selectEmailConfig();
|
||||||
|
String activecode=userService.sendEmailActivecode(user,configMap);
|
||||||
|
if (activecode=="配置文件有错误"){
|
||||||
|
return "邮箱配置文件有错误,请重新确认!";
|
||||||
|
} else if (activecode=="该邮箱不存在") {
|
||||||
|
return "将要发送的邮箱不存在!";
|
||||||
|
}
|
||||||
session.setAttribute(user.getUserEmail(),activecode);
|
session.setAttribute(user.getUserEmail(),activecode);
|
||||||
scheduledExecutorService.schedule(new Runnable() {
|
scheduledExecutorService.schedule(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
@ -80,7 +95,8 @@ public class UserController {
|
|||||||
return "注册成功!";
|
return "注册成功!";
|
||||||
}
|
}
|
||||||
@RequestMapping(value = "/login",produces = {"application/json;charset=UTF-8"})
|
@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> result=new HashMap<>();
|
||||||
Map<String,Object> map=new HashMap<>();
|
Map<String,Object> map=new HashMap<>();
|
||||||
|
|
||||||
@ -99,9 +115,18 @@ public class UserController {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
String ip=IPutils.getIpAddress(request);
|
||||||
|
System.out.println(ip);
|
||||||
|
|
||||||
|
String locat= String.valueOf(IPutils.getLocation(ip));
|
||||||
User user1 = userService.userLogin(user);
|
User user1 = userService.userLogin(user);
|
||||||
|
|
||||||
if(user1!=null){
|
if(user1!=null){
|
||||||
|
loginLogs.setUserId(user1.getId());
|
||||||
|
loginLogs.setLoginIp(ip);
|
||||||
|
loginLogs.setLocation(locat);
|
||||||
|
loginLogsService.addLoginLogs(loginLogs);
|
||||||
result.put("code",200);
|
result.put("code",200);
|
||||||
map.put("userEmail",user1.getUserEmail());
|
map.put("userEmail",user1.getUserEmail());
|
||||||
map.put("userLogin",user1.getUserLogin());
|
map.put("userLogin",user1.getUserLogin());
|
||||||
@ -166,6 +191,9 @@ public class UserController {
|
|||||||
return map;
|
return map;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@RequestMapping("/getAllUsers")
|
||||||
|
public HashMap<Integer,Object> getAllUsers(){
|
||||||
|
return userService.getAllUsers();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package com.lovenav.dao;
|
package com.lovenav.dao;
|
||||||
|
|
||||||
import com.lovenav.entity.Attachment;
|
import com.lovenav.entity.Attachment;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
|
@Mapper
|
||||||
public interface AttachmentDao {
|
public interface AttachmentDao {
|
||||||
int deleteByPrimaryKey(Long id);
|
int deleteByPrimaryKey(Long id);
|
||||||
|
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
package com.lovenav.dao;
|
package com.lovenav.dao;
|
||||||
|
|
||||||
import com.lovenav.entity.LoginLogs;
|
import com.lovenav.entity.LoginLogs;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
@Mapper
|
||||||
@Repository
|
@Repository
|
||||||
public interface LoginLogsDao {
|
public interface LoginLogsDao {
|
||||||
int deleteByPrimaryKey(Integer id);
|
int deleteByPrimaryKey(Integer id);
|
||||||
@ -16,4 +17,8 @@ public interface LoginLogsDao {
|
|||||||
int updateByPrimaryKeySelective(LoginLogs record);
|
int updateByPrimaryKeySelective(LoginLogs record);
|
||||||
|
|
||||||
int updateByPrimaryKey(LoginLogs record);
|
int updateByPrimaryKey(LoginLogs record);
|
||||||
|
|
||||||
|
LoginLogs selectAlreadyExist(int userId);
|
||||||
|
|
||||||
|
int updateByUserId(LoginLogs record);
|
||||||
}
|
}
|
@ -1,9 +1,15 @@
|
|||||||
package com.lovenav.dao;
|
package com.lovenav.dao;
|
||||||
|
|
||||||
import com.lovenav.entity.UrlAccess;
|
import com.lovenav.entity.UrlAccess;
|
||||||
|
import org.apache.ibatis.annotations.MapKey;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
|
@Mapper
|
||||||
public interface UrlAccessDao {
|
public interface UrlAccessDao {
|
||||||
int deleteByPrimaryKey(Integer id);
|
int deleteByPrimaryKey(Integer id);
|
||||||
|
|
||||||
@ -14,6 +20,11 @@ public interface UrlAccessDao {
|
|||||||
UrlAccess selectByPrimaryKey(Integer id);
|
UrlAccess selectByPrimaryKey(Integer id);
|
||||||
|
|
||||||
int updateByPrimaryKeySelective(UrlAccess record);
|
int updateByPrimaryKeySelective(UrlAccess record);
|
||||||
|
UrlAccess selectAlreadyExist(UrlAccess urlAccess);
|
||||||
|
|
||||||
int updateByPrimaryKey(UrlAccess record);
|
int updateByPrimaryKey(UrlAccess record);
|
||||||
|
|
||||||
|
int updateByUrlId(UrlAccess record);
|
||||||
|
@MapKey("time")
|
||||||
|
HashMap<Date,Object> selectUrlAccess(UrlAccess urlAccess);
|
||||||
}
|
}
|
@ -1,10 +1,13 @@
|
|||||||
package com.lovenav.dao;
|
package com.lovenav.dao;
|
||||||
|
|
||||||
import com.lovenav.entity.User;
|
import com.lovenav.entity.User;
|
||||||
|
import org.apache.ibatis.annotations.MapKey;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
@Repository
|
@Repository
|
||||||
public interface UserDao {
|
public interface UserDao {
|
||||||
@ -26,6 +29,7 @@ public interface UserDao {
|
|||||||
User selectByUserLogin(String user_login);
|
User selectByUserLogin(String user_login);
|
||||||
|
|
||||||
int updateByEmail(User user);
|
int updateByEmail(User user);
|
||||||
|
@MapKey("id")
|
||||||
|
HashMap<Integer,Object> selectAllUsers();
|
||||||
|
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package com.lovenav.entity;
|
package com.lovenav.entity;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -57,7 +58,7 @@ public class Attachment implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* 创建时间
|
* 创建时间
|
||||||
*/
|
*/
|
||||||
private Integer createtime;
|
private Date createtime;
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
}
|
}
|
23
src/main/java/com/lovenav/entity/IpLocation.java
Normal file
23
src/main/java/com/lovenav/entity/IpLocation.java
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package com.lovenav.entity;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
@Data
|
||||||
|
public class IpLocation implements Serializable {
|
||||||
|
@ApiModelProperty("ip地址")
|
||||||
|
private String ip;
|
||||||
|
|
||||||
|
@ApiModelProperty("国家")
|
||||||
|
private String country;
|
||||||
|
|
||||||
|
@ApiModelProperty("省")
|
||||||
|
private String province;
|
||||||
|
|
||||||
|
@ApiModelProperty("省")
|
||||||
|
private String city;
|
||||||
|
|
||||||
|
@ApiModelProperty("服务商")
|
||||||
|
private String isp;
|
||||||
|
}
|
@ -22,7 +22,7 @@ public class LoginLogs implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* 用户id
|
* 用户id
|
||||||
*/
|
*/
|
||||||
private Byte userId;
|
private Integer userId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录时间
|
* 登录时间
|
||||||
|
@ -2,6 +2,8 @@ package com.lovenav.entity;
|
|||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -22,6 +24,7 @@ public class UrlAccess implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* 日期
|
* 日期
|
||||||
*/
|
*/
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
|
||||||
private Date time;
|
private Date time;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,9 +1,18 @@
|
|||||||
package com.lovenav.service;
|
package com.lovenav.service;
|
||||||
|
|
||||||
|
import com.lovenav.dao.AttachmentDao;
|
||||||
|
import com.lovenav.entity.Attachment;
|
||||||
|
import com.lovenav.entity.Config;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public interface AttachmentService {
|
public interface AttachmentService {
|
||||||
// public HashMap<String,String>storeFile(MultipartFile multipartFile);
|
HashMap<String,String> upload(MultipartFile file,String cate,Long id) throws IOException;
|
||||||
|
|
||||||
|
public HashMap<String,String>storeFile(MultipartFile multipartFile,String cate,Long id) throws IOException;
|
||||||
|
|
||||||
|
public Attachment selectAttachment(Long id);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,15 @@ import java.util.HashMap;
|
|||||||
|
|
||||||
public interface ConfigService {
|
public interface ConfigService {
|
||||||
public HashMap<String,Object>getAllConfig();
|
public HashMap<String,Object>getAllConfig();
|
||||||
public int updateConfis(Config config);
|
public int updateConfig(Config config);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public String addConfig(Config config);
|
public String addConfig(Config config);
|
||||||
|
|
||||||
|
HashMap<String, String> selectEmailConfig();
|
||||||
|
|
||||||
|
public Config selectAlreadyExist(Config config);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
9
src/main/java/com/lovenav/service/LoginLogsService.java
Normal file
9
src/main/java/com/lovenav/service/LoginLogsService.java
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package com.lovenav.service;
|
||||||
|
|
||||||
|
|
||||||
|
import com.lovenav.entity.LoginLogs;
|
||||||
|
|
||||||
|
public interface LoginLogsService {
|
||||||
|
public String addLoginLogs(LoginLogs loginLogs);
|
||||||
|
|
||||||
|
}
|
13
src/main/java/com/lovenav/service/UrlAccessService.java
Normal file
13
src/main/java/com/lovenav/service/UrlAccessService.java
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package com.lovenav.service;
|
||||||
|
|
||||||
|
import com.lovenav.entity.UrlAccess;
|
||||||
|
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public interface UrlAccessService {
|
||||||
|
public String inreaseUrlViews(UrlAccess urlAccess);
|
||||||
|
|
||||||
|
public HashMap<Date,Object> getUrlAccess(UrlAccess urlAccess);
|
||||||
|
}
|
@ -2,12 +2,12 @@ package com.lovenav.service;
|
|||||||
|
|
||||||
import com.lovenav.entity.User;
|
import com.lovenav.entity.User;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
|
||||||
public interface UserService {
|
public interface UserService {
|
||||||
|
|
||||||
public String sendEmailActivecode(User user);
|
public String sendEmailActivecode(User user, HashMap<String,String>configMap);
|
||||||
public int UserRegister(User user);
|
public int UserRegister(User user);
|
||||||
|
|
||||||
public User selectUserAlreadyExist(User user);
|
public User selectUserAlreadyExist(User user);
|
||||||
@ -16,4 +16,6 @@ public interface UserService {
|
|||||||
|
|
||||||
public int updatePassword(User user);
|
public int updatePassword(User user);
|
||||||
|
|
||||||
|
HashMap<Integer,Object> getAllUsers();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,14 @@
|
|||||||
package com.lovenav.service.serviceImpl;
|
package com.lovenav.service.serviceImpl;
|
||||||
|
|
||||||
|
import com.lovenav.dao.AttachmentDao;
|
||||||
|
import com.lovenav.dao.ConfigDao;
|
||||||
|
import com.lovenav.entity.Attachment;
|
||||||
|
import com.lovenav.entity.Config;
|
||||||
import com.lovenav.service.AttachmentService;
|
import com.lovenav.service.AttachmentService;
|
||||||
|
import com.lovenav.utils.MD5Utils;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.ResourceUtils;
|
import org.springframework.util.ResourceUtils;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
@ -14,45 +22,72 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
public class AttachmentServiceImpl implements AttachmentService {
|
public class AttachmentServiceImpl implements AttachmentService {
|
||||||
// @Override
|
@Autowired
|
||||||
// public HashMap<String, String> storeFile(MultipartFile multipartFile) {
|
AttachmentDao attachmentDao;
|
||||||
// HashMap<String,String> map = new HashMap<>();
|
|
||||||
// }
|
@Override
|
||||||
// File path = null;
|
public HashMap<String,String> upload(MultipartFile file,String cate,Long id) throws IOException {
|
||||||
//// try {
|
HashMap<String, String> map = storeFile(file,cate,id);
|
||||||
// path = new File(ResourceUtils.getURL("classpath:").getPath());
|
return map;
|
||||||
// File upload = new File(path.getAbsolutePath(),"static/img/");
|
}
|
||||||
// Date date=new Date();
|
@Override
|
||||||
//
|
public HashMap<String, String> storeFile(MultipartFile multipartFile,String cate,Long id) throws IOException {
|
||||||
// DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
HashMap<String,String> map = new HashMap<>();
|
||||||
// String date1=format.format(date);
|
Attachment attachment=new Attachment();
|
||||||
// String fileName = multipartFile.getOriginalFilename();//文件全名
|
File path = null;
|
||||||
// File parentDir = new File(upload.getAbsolutePath()+"/" + date1);
|
try {
|
||||||
// System.out.println(upload.getAbsolutePath());
|
path = new File(ResourceUtils.getURL("classpath:").getPath());
|
||||||
// System.out.println(fileName);
|
File upload = new File(path.getAbsolutePath(),"static/"+cate+"/");
|
||||||
// map
|
Date date=new Date();
|
||||||
// return
|
|
||||||
// if(!upload.exists()){
|
DateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||||
// upload.mkdirs();
|
DateFormat format1 = new SimpleDateFormat("yyyyMM");
|
||||||
// }
|
String date1=format.format(date);
|
||||||
// if(!parentDir.exists()){
|
String fileName = multipartFile.getOriginalFilename();//文件全名
|
||||||
// parentDir.mkdirs();
|
String date2=format1.format(date);
|
||||||
// }
|
File parentDir = new File(upload.getAbsolutePath()+"/" + date2);
|
||||||
// String suffix = suffix(fileName);//文件后缀
|
if(!upload.exists()){
|
||||||
// String relPath = "/" + yearMonth + "/" + "-" + UUID.randomUUID().toString().replaceAll("-","") + suffix;
|
upload.mkdirs();
|
||||||
// File fileUp = new File(upload.getAbsolutePath()+ relPath);
|
}
|
||||||
// file.transferTo(fileUp);
|
if(!parentDir.exists()){
|
||||||
// Map<String, String> map = new HashMap();
|
parentDir.mkdirs();
|
||||||
// map.put("url", "/img" + relPath);
|
}
|
||||||
// log.info(relPath);
|
String suffix = suffix(fileName);//文件后缀
|
||||||
// return map;
|
String finalFileName=UUID.randomUUID().toString().replaceAll("-","");
|
||||||
// } catch (FileNotFoundException e) {
|
String relPath = "/" + date2 + "/" + finalFileName + suffix;
|
||||||
// throw e;
|
File fileUp = new File(upload.getAbsolutePath()+ relPath);
|
||||||
// } catch (IOException e) {
|
|
||||||
// throw e;
|
attachment.setCreatetime(date);
|
||||||
// }
|
attachment.setFileName(finalFileName);
|
||||||
// }
|
attachment.setPath(upload.getAbsolutePath()+ "/" + date2 + "/");
|
||||||
|
attachment.setSuffix(suffix);
|
||||||
|
attachment.setMd5(MD5Utils.md5(upload.getAbsolutePath()+ relPath));
|
||||||
|
attachment.setStorage("local");
|
||||||
|
attachment.setId(id);
|
||||||
|
attachmentDao.insertSelective(attachment);
|
||||||
|
map.put("id", String.valueOf(attachment.getId()));
|
||||||
|
multipartFile.transferTo(fileUp);
|
||||||
|
map.put("url", "/img" + relPath);
|
||||||
|
log.info(relPath);
|
||||||
|
return map;
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Attachment selectAttachment(Long id) {
|
||||||
|
Attachment attachment=attachmentDao.selectByPrimaryKey(id);
|
||||||
|
return attachment;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String suffix(String fileName) {
|
||||||
|
int i = fileName.lastIndexOf('.');
|
||||||
|
return i == -1 ? "" : fileName.substring(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,10 @@ public class ConfigServiceImpl implements ConfigService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int updateConfis(Config config) {
|
public int updateConfig(Config config) {
|
||||||
|
if (configDao.selectByName(config.getName())==null){
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
return configDao.updateByName(config);
|
return configDao.updateByName(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,5 +38,36 @@ public class ConfigServiceImpl implements ConfigService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
//获得邮箱配置的信息,若没有值则采用默认信息
|
||||||
|
@Override
|
||||||
|
public HashMap<String, String> selectEmailConfig() {
|
||||||
|
HashMap<String,String> configMap= new HashMap<>();
|
||||||
|
if (configDao.selectByName("email_sendEmail").getValue()!=null){
|
||||||
|
configMap.put("email_sendEmail",configDao.selectByName("email_sendEmail").getValue());
|
||||||
|
}else {
|
||||||
|
configMap.put("email_sendEmail","482370576@qq.com");
|
||||||
|
return configMap;
|
||||||
|
}
|
||||||
|
if (configDao.selectByName("email_host").getValue()!=null){
|
||||||
|
configMap.put("email_host",configDao.selectByName("email_host").getValue());
|
||||||
|
}else {
|
||||||
|
configMap.put("email_host","smtp.qq.com");
|
||||||
|
return configMap;
|
||||||
|
}
|
||||||
|
if (configDao.selectByName("email_password").getValue()!=null){
|
||||||
|
configMap.put("email_password",configDao.selectByName("email_password").getValue());
|
||||||
|
}else {
|
||||||
|
configMap.put("email_password","ksuebkfenixhdbbh");
|
||||||
|
return configMap;
|
||||||
|
}
|
||||||
|
return configMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Config selectAlreadyExist(Config config) {
|
||||||
|
|
||||||
|
return configDao.selectByName(config.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,30 @@
|
|||||||
|
package com.lovenav.service.serviceImpl;
|
||||||
|
|
||||||
|
import com.lovenav.dao.LoginLogsDao;
|
||||||
|
import com.lovenav.entity.LoginLogs;
|
||||||
|
import com.lovenav.service.LoginLogsService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class LoginLogsServiceImpl implements LoginLogsService {
|
||||||
|
@Autowired
|
||||||
|
LoginLogsDao loginLogsDao;
|
||||||
|
@Override
|
||||||
|
public String addLoginLogs(LoginLogs loginLogs) {
|
||||||
|
Date date=new Date();
|
||||||
|
loginLogs.setLoginTime(date);
|
||||||
|
if (loginLogsDao.selectAlreadyExist(loginLogs.getUserId())==null){
|
||||||
|
if (loginLogsDao.insertSelective(loginLogs)!=1){
|
||||||
|
return "登录日志更新成功!";
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
if (loginLogsDao.updateByUserId(loginLogs)!=1){
|
||||||
|
return "登录日志更新失败!";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "更新登录日志失败";
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
package com.lovenav.service.serviceImpl;
|
||||||
|
|
||||||
|
import com.lovenav.dao.UrlAccessDao;
|
||||||
|
import com.lovenav.entity.UrlAccess;
|
||||||
|
import com.lovenav.service.UrlAccessService;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class UrlAccessServiceImpl implements UrlAccessService {
|
||||||
|
@Autowired
|
||||||
|
UrlAccessDao urlAccessDao;
|
||||||
|
@Override
|
||||||
|
public String inreaseUrlViews(UrlAccess urlAccess){
|
||||||
|
if (urlAccess.getUrlId()==null){
|
||||||
|
return "url的Id不能为空!";
|
||||||
|
}
|
||||||
|
Date date=new Date();
|
||||||
|
urlAccess.setTime(date);
|
||||||
|
urlAccess.setUrlId(2);
|
||||||
|
UrlAccess urlAccess1=urlAccessDao.selectAlreadyExist(urlAccess);
|
||||||
|
if (urlAccess1==null){
|
||||||
|
urlAccess.setViews(1L);
|
||||||
|
urlAccessDao.insertSelective(urlAccess);
|
||||||
|
}else {
|
||||||
|
urlAccess.setViews(urlAccess1.getViews()+1);
|
||||||
|
urlAccessDao.updateByUrlId(urlAccess);
|
||||||
|
}
|
||||||
|
return "更新成功!";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HashMap<Date, Object> getUrlAccess(UrlAccess urlAccess) {
|
||||||
|
HashMap<Date, Object> map=new HashMap<>();
|
||||||
|
map=urlAccessDao.selectUrlAccess(urlAccess);
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
}
|
@ -12,6 +12,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
|
||||||
@ -59,8 +60,15 @@ public class UserServiceImpl implements UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String sendEmailActivecode(User user) {
|
public HashMap<Integer, Object> getAllUsers() {
|
||||||
return EmailUtils.sendEmail(user);
|
HashMap<Integer, Object> map=new HashMap<>();
|
||||||
|
map=userDao.selectAllUsers();
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String sendEmailActivecode(User user, HashMap<String,String>configMap) {
|
||||||
|
return EmailUtils.sendEmail(user,configMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -5,6 +5,8 @@ package com.lovenav.utils;
|
|||||||
|
|
||||||
|
|
||||||
import com.lovenav.entity.User;
|
import com.lovenav.entity.User;
|
||||||
|
import com.sun.mail.smtp.SMTPSendFailedException;
|
||||||
|
import com.sun.mail.util.MailConnectException;
|
||||||
import org.jsoup.Jsoup;
|
import org.jsoup.Jsoup;
|
||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
|
|
||||||
@ -14,6 +16,7 @@ import javax.mail.internet.InternetAddress;
|
|||||||
import javax.mail.internet.MimeMessage;
|
import javax.mail.internet.MimeMessage;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -22,14 +25,18 @@ import java.util.Properties;
|
|||||||
* */
|
* */
|
||||||
public class EmailUtils {
|
public class EmailUtils {
|
||||||
|
|
||||||
public static String sendEmail(User user) {
|
public static String sendEmail(User user, HashMap<String,String> configMap) {
|
||||||
|
|
||||||
//邮箱 lx_teach@163.com
|
//邮箱 lx_teach@163.com
|
||||||
String myAccount = "482370576@qq.com";
|
// String myAccount = "482370576@qq.com";
|
||||||
//授权码 java168
|
// //授权码 java168
|
||||||
String myPass = "hlilinclupppbice";
|
// String myPass = "hlilinclupppbice";
|
||||||
//邮箱服务器
|
// //邮箱服务器
|
||||||
String SMTPHost = "smtp.qq.com";
|
// String SMTPHost = "smtp.qq.com";
|
||||||
|
String myAccount=configMap.get("email_sendEmail");
|
||||||
|
String myPass=configMap.get("email_password");
|
||||||
|
String SMTPHost = configMap.get("email_host");
|
||||||
|
|
||||||
//设置属性信息
|
//设置属性信息
|
||||||
Properties prop = new Properties();
|
Properties prop = new Properties();
|
||||||
//设置协议
|
//设置协议
|
||||||
@ -44,9 +51,13 @@ public class EmailUtils {
|
|||||||
//设置是否需要调试
|
//设置是否需要调试
|
||||||
session.setDebug(false);
|
session.setDebug(false);
|
||||||
//2、创建发送信息
|
//2、创建发送信息
|
||||||
MimeMessage message = createMsg(session, myAccount, user, activecode);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//4发送信息操作
|
//4发送信息操作
|
||||||
try {
|
try {
|
||||||
|
MimeMessage message = createMsg(session, myAccount, user, activecode);
|
||||||
Transport tran = session.getTransport();
|
Transport tran = session.getTransport();
|
||||||
//连接
|
//连接
|
||||||
tran.connect(myAccount, myPass);
|
tran.connect(myAccount, myPass);
|
||||||
@ -54,10 +65,18 @@ public class EmailUtils {
|
|||||||
tran.sendMessage(message, message.getAllRecipients());
|
tran.sendMessage(message, message.getAllRecipients());
|
||||||
//关闭
|
//关闭
|
||||||
tran.close();
|
tran.close();
|
||||||
} catch (Exception e) {
|
|
||||||
|
}catch (SMTPSendFailedException s){
|
||||||
|
s.printStackTrace();
|
||||||
|
return "该邮箱不存在";
|
||||||
|
}catch (MailConnectException m){
|
||||||
|
m.printStackTrace();
|
||||||
|
return "配置文件有错误";
|
||||||
|
}catch (Exception e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
return "配置文件有错误";}
|
||||||
|
|
||||||
return activecode;
|
return activecode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
105
src/main/java/com/lovenav/utils/IPutils.java
Normal file
105
src/main/java/com/lovenav/utils/IPutils.java
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
package com.lovenav.utils;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import cn.hutool.core.io.IoUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.lovenav.entity.IpLocation;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.lionsoul.ip2region.xdb.Searcher;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.FileCopyUtils;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class IPutils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字符常量0
|
||||||
|
*/
|
||||||
|
private static final String ZERO="0";
|
||||||
|
/**
|
||||||
|
* 本级ip
|
||||||
|
*/
|
||||||
|
private static final String LOCALHOST="127.0.0.1";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取客户端的IP地址
|
||||||
|
*/
|
||||||
|
public static String getIpAddress(HttpServletRequest request) {
|
||||||
|
|
||||||
|
String ipAddress = request.getHeader("X-Forwarded-For");
|
||||||
|
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
|
||||||
|
ipAddress = request.getHeader("Proxy-Client-IP");
|
||||||
|
}
|
||||||
|
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
|
||||||
|
ipAddress = request.getHeader("WL-Proxy-Client-IP");
|
||||||
|
}
|
||||||
|
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
|
||||||
|
ipAddress = request.getRemoteAddr();
|
||||||
|
if (LOCALHOST.equals(ipAddress)) {
|
||||||
|
// 根据网卡取本机配置的IP
|
||||||
|
InetAddress inet = null;
|
||||||
|
try {
|
||||||
|
inet = InetAddress.getLocalHost();
|
||||||
|
ipAddress = inet.getHostAddress();
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 对于通过多个代理转发的情况,取第一个非unknown的IP地址。
|
||||||
|
// 这里假设第一个IP为真实IP,后面的为代理IP。
|
||||||
|
if (ipAddress != null && ipAddress.length() > 15) {
|
||||||
|
if (ipAddress.indexOf(",") > 0) {
|
||||||
|
ipAddress = ipAddress.substring(0, ipAddress.indexOf(","));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ipAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据iP获取归属地信息
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static IpLocation getLocation(String ip) {
|
||||||
|
IpLocation location = new IpLocation();
|
||||||
|
location.setIp(ip);
|
||||||
|
try (InputStream inputStream = IPutils.class.getResourceAsStream("/ip2region.xdb");) {
|
||||||
|
byte[] bytes = IoUtil.readBytes(inputStream);
|
||||||
|
Searcher searcher = Searcher.newWithBuffer(bytes);
|
||||||
|
String region = searcher.search(ip);
|
||||||
|
if (StrUtil.isAllNotBlank(region)) {
|
||||||
|
// xdb返回格式 国家|区域|省份|城市|ISP,
|
||||||
|
// 只有中国的数据绝大部分精确到了城市,其他国家部分数据只能定位到国家,后前的选项全部是0
|
||||||
|
String[] result = region.split("\\|");
|
||||||
|
location.setCountry(ZERO.equals(result[0])?StrUtil.EMPTY:result[0]);
|
||||||
|
location.setProvince(ZERO.equals(result[2])?StrUtil.EMPTY:result[2]);
|
||||||
|
location.setCity(ZERO.equals(result[3])?StrUtil.EMPTY:result[3]);
|
||||||
|
location.setIsp(ZERO.equals(result[4])?StrUtil.EMPTY:result[4]);
|
||||||
|
}
|
||||||
|
searcher.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("ip地址解析异常,error:{}",e);
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
}
|
BIN
src/main/resources/ip2region.xdb
Normal file
BIN
src/main/resources/ip2region.xdb
Normal file
Binary file not shown.
@ -11,7 +11,7 @@
|
|||||||
<result column="width" jdbcType="DOUBLE" property="width" />
|
<result column="width" jdbcType="DOUBLE" property="width" />
|
||||||
<result column="height" jdbcType="DOUBLE" property="height" />
|
<result column="height" jdbcType="DOUBLE" property="height" />
|
||||||
<result column="storage" jdbcType="OTHER" property="storage" />
|
<result column="storage" jdbcType="OTHER" property="storage" />
|
||||||
<result column="createtime" jdbcType="INTEGER" property="createtime" />
|
<result column="createtime" jdbcType="TIMESTAMP" property="createtime" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
<sql id="Base_Column_List">
|
<sql id="Base_Column_List">
|
||||||
id, `path`, suffix, file_name, `size`, md5, width, height, `storage`, createtime
|
id, `path`, suffix, file_name, `size`, md5, width, height, `storage`, createtime
|
||||||
@ -32,9 +32,9 @@
|
|||||||
`storage`, createtime)
|
`storage`, createtime)
|
||||||
values (#{path,jdbcType=VARCHAR}, #{suffix,jdbcType=VARCHAR}, #{fileName,jdbcType=VARCHAR},
|
values (#{path,jdbcType=VARCHAR}, #{suffix,jdbcType=VARCHAR}, #{fileName,jdbcType=VARCHAR},
|
||||||
#{size,jdbcType=DOUBLE}, #{md5,jdbcType=VARCHAR}, #{width,jdbcType=DOUBLE}, #{height,jdbcType=DOUBLE},
|
#{size,jdbcType=DOUBLE}, #{md5,jdbcType=VARCHAR}, #{width,jdbcType=DOUBLE}, #{height,jdbcType=DOUBLE},
|
||||||
#{storage,jdbcType=OTHER}, #{createtime,jdbcType=INTEGER})
|
#{storage,jdbcType=OTHER}, #{createtime,jdbcType=TIMESTAMP})
|
||||||
</insert>
|
</insert>
|
||||||
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.lovenav.entity.Attachment" useGeneratedKeys="true">
|
<insert id="insertSelective" keyProperty="id" parameterType="com.lovenav.entity.Attachment" useGeneratedKeys="true">
|
||||||
insert into ln_attachment
|
insert into ln_attachment
|
||||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||||
<if test="path != null">
|
<if test="path != null">
|
||||||
@ -91,7 +91,7 @@
|
|||||||
#{storage,jdbcType=OTHER},
|
#{storage,jdbcType=OTHER},
|
||||||
</if>
|
</if>
|
||||||
<if test="createtime != null">
|
<if test="createtime != null">
|
||||||
#{createtime,jdbcType=INTEGER},
|
#{createtime,jdbcType=TIMESTAMP},
|
||||||
</if>
|
</if>
|
||||||
</trim>
|
</trim>
|
||||||
</insert>
|
</insert>
|
||||||
@ -123,7 +123,7 @@
|
|||||||
`storage` = #{storage,jdbcType=OTHER},
|
`storage` = #{storage,jdbcType=OTHER},
|
||||||
</if>
|
</if>
|
||||||
<if test="createtime != null">
|
<if test="createtime != null">
|
||||||
createtime = #{createtime,jdbcType=INTEGER},
|
createtime = #{createtime,jdbcType=TIMESTAMP},
|
||||||
</if>
|
</if>
|
||||||
</set>
|
</set>
|
||||||
where id = #{id,jdbcType=BIGINT}
|
where id = #{id,jdbcType=BIGINT}
|
||||||
@ -138,9 +138,7 @@
|
|||||||
width = #{width,jdbcType=DOUBLE},
|
width = #{width,jdbcType=DOUBLE},
|
||||||
height = #{height,jdbcType=DOUBLE},
|
height = #{height,jdbcType=DOUBLE},
|
||||||
`storage` = #{storage,jdbcType=OTHER},
|
`storage` = #{storage,jdbcType=OTHER},
|
||||||
createtime = #{createtime,jdbcType=INTEGER}
|
createtime = #{createtime,jdbcType=TIMESTAMP}
|
||||||
where id = #{id,jdbcType=BIGINT}
|
where id = #{id,jdbcType=BIGINT}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
@ -4,7 +4,7 @@
|
|||||||
<resultMap id="BaseResultMap" type="com.lovenav.entity.LoginLogs">
|
<resultMap id="BaseResultMap" type="com.lovenav.entity.LoginLogs">
|
||||||
<id column="id" jdbcType="INTEGER" property="id" />
|
<id column="id" jdbcType="INTEGER" property="id" />
|
||||||
<result column="login_ip" jdbcType="VARCHAR" property="loginIp" />
|
<result column="login_ip" jdbcType="VARCHAR" property="loginIp" />
|
||||||
<result column="user_id" jdbcType="TINYINT" property="userId" />
|
<result column="user_id" jdbcType="INTEGER" property="userId" />
|
||||||
<result column="login_time" jdbcType="TIMESTAMP" property="loginTime" />
|
<result column="login_time" jdbcType="TIMESTAMP" property="loginTime" />
|
||||||
<result column="location" jdbcType="VARCHAR" property="location" />
|
<result column="location" jdbcType="VARCHAR" property="location" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
@ -17,6 +17,12 @@
|
|||||||
from ln_login_logs
|
from ln_login_logs
|
||||||
where id = #{id,jdbcType=INTEGER}
|
where id = #{id,jdbcType=INTEGER}
|
||||||
</select>
|
</select>
|
||||||
|
<select id="selectAlreadyExist" resultType="com.lovenav.entity.LoginLogs">
|
||||||
|
select
|
||||||
|
<include refid="Base_Column_List" />
|
||||||
|
from ln_login_logs
|
||||||
|
where user_id = #{userId,jdbcType=INTEGER}
|
||||||
|
</select>
|
||||||
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
|
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
|
||||||
delete from ln_login_logs
|
delete from ln_login_logs
|
||||||
where id = #{id,jdbcType=INTEGER}
|
where id = #{id,jdbcType=INTEGER}
|
||||||
@ -24,7 +30,7 @@
|
|||||||
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.lovenav.entity.LoginLogs" useGeneratedKeys="true">
|
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.lovenav.entity.LoginLogs" useGeneratedKeys="true">
|
||||||
insert into ln_login_logs (login_ip, user_id, login_time,
|
insert into ln_login_logs (login_ip, user_id, login_time,
|
||||||
`location`)
|
`location`)
|
||||||
values (#{loginIp,jdbcType=VARCHAR}, #{userId,jdbcType=TINYINT}, #{loginTime,jdbcType=TIMESTAMP},
|
values (#{loginIp,jdbcType=VARCHAR}, #{userId,jdbcType=INTEGER}, #{loginTime,jdbcType=TIMESTAMP},
|
||||||
#{location,jdbcType=VARCHAR})
|
#{location,jdbcType=VARCHAR})
|
||||||
</insert>
|
</insert>
|
||||||
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.lovenav.entity.LoginLogs" useGeneratedKeys="true">
|
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.lovenav.entity.LoginLogs" useGeneratedKeys="true">
|
||||||
@ -48,7 +54,7 @@
|
|||||||
#{loginIp,jdbcType=VARCHAR},
|
#{loginIp,jdbcType=VARCHAR},
|
||||||
</if>
|
</if>
|
||||||
<if test="userId != null">
|
<if test="userId != null">
|
||||||
#{userId,jdbcType=TINYINT},
|
#{userId,jdbcType=INTEGER},
|
||||||
</if>
|
</if>
|
||||||
<if test="loginTime != null">
|
<if test="loginTime != null">
|
||||||
#{loginTime,jdbcType=TIMESTAMP},
|
#{loginTime,jdbcType=TIMESTAMP},
|
||||||
@ -65,7 +71,7 @@
|
|||||||
login_ip = #{loginIp,jdbcType=VARCHAR},
|
login_ip = #{loginIp,jdbcType=VARCHAR},
|
||||||
</if>
|
</if>
|
||||||
<if test="userId != null">
|
<if test="userId != null">
|
||||||
user_id = #{userId,jdbcType=TINYINT},
|
user_id = #{userId,jdbcType=INTEGER},
|
||||||
</if>
|
</if>
|
||||||
<if test="loginTime != null">
|
<if test="loginTime != null">
|
||||||
login_time = #{loginTime,jdbcType=TIMESTAMP},
|
login_time = #{loginTime,jdbcType=TIMESTAMP},
|
||||||
@ -79,9 +85,24 @@
|
|||||||
<update id="updateByPrimaryKey" parameterType="com.lovenav.entity.LoginLogs">
|
<update id="updateByPrimaryKey" parameterType="com.lovenav.entity.LoginLogs">
|
||||||
update ln_login_logs
|
update ln_login_logs
|
||||||
set login_ip = #{loginIp,jdbcType=VARCHAR},
|
set login_ip = #{loginIp,jdbcType=VARCHAR},
|
||||||
user_id = #{userId,jdbcType=TINYINT},
|
user_id = #{userId,jdbcType=INTEGER},
|
||||||
login_time = #{loginTime,jdbcType=TIMESTAMP},
|
login_time = #{loginTime,jdbcType=TIMESTAMP},
|
||||||
`location` = #{location,jdbcType=VARCHAR}
|
`location` = #{location,jdbcType=VARCHAR}
|
||||||
where id = #{id,jdbcType=INTEGER}
|
where id = #{id,jdbcType=INTEGER}
|
||||||
</update>
|
</update>
|
||||||
|
<update id="updateByUserId" parameterType="com.lovenav.entity.LoginLogs">
|
||||||
|
update ln_login_logs
|
||||||
|
<set>
|
||||||
|
<if test="loginIp != null">
|
||||||
|
login_ip = #{loginIp,jdbcType=VARCHAR},
|
||||||
|
</if>
|
||||||
|
<if test="loginTime != null">
|
||||||
|
login_time = #{loginTime,jdbcType=TIMESTAMP},
|
||||||
|
</if>
|
||||||
|
<if test="location != null">
|
||||||
|
`location` = #{location,jdbcType=VARCHAR},
|
||||||
|
</if>
|
||||||
|
</set>
|
||||||
|
where user_id = #{userId,jdbcType=INTEGER}
|
||||||
|
</update>
|
||||||
</mapper>
|
</mapper>
|
@ -15,6 +15,18 @@
|
|||||||
<include refid="Base_Column_List" />
|
<include refid="Base_Column_List" />
|
||||||
from ln_url_access
|
from ln_url_access
|
||||||
where id = #{id,jdbcType=INTEGER}
|
where id = #{id,jdbcType=INTEGER}
|
||||||
|
</select>
|
||||||
|
<select id="selectAlreadyExist" resultType="com.lovenav.entity.UrlAccess">
|
||||||
|
select
|
||||||
|
<include refid="Base_Column_List" />
|
||||||
|
from ln_url_access
|
||||||
|
where url_id = #{urlId,jdbcType=INTEGER} and date_format(time,'%y%m%d') >= date_format(#{time},'%y%m%d')
|
||||||
|
</select>
|
||||||
|
<select id="selectUrlAccess" resultType="java.util.HashMap">
|
||||||
|
select
|
||||||
|
<include refid="Base_Column_List" />
|
||||||
|
from ln_url_access
|
||||||
|
where url_id = #{urlId,jdbcType=INTEGER}
|
||||||
</select>
|
</select>
|
||||||
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
|
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
|
||||||
delete from ln_url_access
|
delete from ln_url_access
|
||||||
@ -73,4 +85,16 @@
|
|||||||
views = #{views,jdbcType=BIGINT}
|
views = #{views,jdbcType=BIGINT}
|
||||||
where id = #{id,jdbcType=INTEGER}
|
where id = #{id,jdbcType=INTEGER}
|
||||||
</update>
|
</update>
|
||||||
|
<update id="updateByUrlId" parameterType="com.lovenav.entity.UrlAccess">
|
||||||
|
update ln_url_access
|
||||||
|
<set>
|
||||||
|
<if test="time != null">
|
||||||
|
`time` = #{time,jdbcType=TIMESTAMP},
|
||||||
|
</if>
|
||||||
|
<if test="views != null">
|
||||||
|
views = #{views,jdbcType=BIGINT},
|
||||||
|
</if>
|
||||||
|
</set>
|
||||||
|
where url_id = #{urlId,jdbcType=INTEGER} and date_format(time,'%y%m%d') >= date_format(#{time},'%y%m%d')
|
||||||
|
</update>
|
||||||
</mapper>
|
</mapper>
|
@ -190,7 +190,11 @@
|
|||||||
from ln_user
|
from ln_user
|
||||||
where user_login = #{user_login,jdbcType=VARCHAR}
|
where user_login = #{user_login,jdbcType=VARCHAR}
|
||||||
</select>
|
</select>
|
||||||
|
<select id="selectAllUsers" resultType="java.util.HashMap">
|
||||||
|
select
|
||||||
|
<include refid="Base_Column_List" />
|
||||||
|
from ln_user
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
@ -1,21 +1,21 @@
|
|||||||
package com.lovenav;
|
package com.lovenav;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSON;
|
||||||
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
import com.lovenav.dao.UrlCateListDao;
|
import com.lovenav.dao.*;
|
||||||
import com.lovenav.dao.UrlListDao;
|
import com.lovenav.entity.Nav;
|
||||||
import com.lovenav.dao.UserDao;
|
import com.lovenav.entity.UrlAccess;
|
||||||
import com.lovenav.entity.UrlCateList;
|
import com.lovenav.entity.UrlCateList;
|
||||||
import com.lovenav.entity.UrlList;
|
import com.lovenav.entity.UrlList;
|
||||||
import com.lovenav.filter.SensitiveFilter;
|
import com.lovenav.filter.SensitiveFilter;
|
||||||
import com.lovenav.service.RedisService;
|
import com.lovenav.service.*;
|
||||||
import com.lovenav.service.UrlCateListService;
|
|
||||||
import com.lovenav.service.UrlListService;
|
|
||||||
import com.lovenav.service.UserService;
|
|
||||||
import com.lovenav.vo.CateAndUrl;
|
import com.lovenav.vo.CateAndUrl;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
@ -24,303 +24,34 @@ import org.springframework.data.redis.core.StringRedisTemplate;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.text.ParseException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@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);
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
UrlAccessService urlAccessService;
|
||||||
@Test
|
@Test
|
||||||
void contextLoads() {
|
void contextLoads() throws ParseException {
|
||||||
|
UrlAccess urlAccess=new UrlAccess();
|
||||||
String userId = "2";
|
urlAccess.setUrlId(2);
|
||||||
String searchKey="学习";
|
// urlAccess
|
||||||
String abc = "[91片先生, bilibli, 学习, 阁楼]";
|
System.out.println(urlAccessService.getUrlAccess(urlAccess));
|
||||||
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 ;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user