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;
|
||||
}
|
||||
}
|
@@ -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