URL访问量,用户地址,日志登录,附件上传,下载,配置文件上传
This commit is contained in:
@@ -1,6 +1,14 @@
|
||||
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.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.web.multipart.MultipartFile;
|
||||
|
||||
@@ -14,45 +22,72 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class AttachmentServiceImpl implements AttachmentService {
|
||||
// @Override
|
||||
// public HashMap<String, String> storeFile(MultipartFile multipartFile) {
|
||||
// HashMap<String,String> map = new HashMap<>();
|
||||
// }
|
||||
// File path = null;
|
||||
//// try {
|
||||
// path = new File(ResourceUtils.getURL("classpath:").getPath());
|
||||
// File upload = new File(path.getAbsolutePath(),"static/img/");
|
||||
// Date date=new Date();
|
||||
//
|
||||
// DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
// String date1=format.format(date);
|
||||
// String fileName = multipartFile.getOriginalFilename();//文件全名
|
||||
// File parentDir = new File(upload.getAbsolutePath()+"/" + date1);
|
||||
// System.out.println(upload.getAbsolutePath());
|
||||
// System.out.println(fileName);
|
||||
// map
|
||||
// return
|
||||
// if(!upload.exists()){
|
||||
// upload.mkdirs();
|
||||
// }
|
||||
// if(!parentDir.exists()){
|
||||
// parentDir.mkdirs();
|
||||
// }
|
||||
// String suffix = suffix(fileName);//文件后缀
|
||||
// String relPath = "/" + yearMonth + "/" + "-" + UUID.randomUUID().toString().replaceAll("-","") + suffix;
|
||||
// File fileUp = new File(upload.getAbsolutePath()+ relPath);
|
||||
// file.transferTo(fileUp);
|
||||
// Map<String, String> map = new HashMap();
|
||||
// map.put("url", "/img" + relPath);
|
||||
// log.info(relPath);
|
||||
// return map;
|
||||
// } catch (FileNotFoundException e) {
|
||||
// throw e;
|
||||
// } catch (IOException e) {
|
||||
// throw e;
|
||||
// }
|
||||
// }
|
||||
@Autowired
|
||||
AttachmentDao attachmentDao;
|
||||
|
||||
@Override
|
||||
public HashMap<String,String> upload(MultipartFile file,String cate,Long id) throws IOException {
|
||||
HashMap<String, String> map = storeFile(file,cate,id);
|
||||
return map;
|
||||
}
|
||||
@Override
|
||||
public HashMap<String, String> storeFile(MultipartFile multipartFile,String cate,Long id) throws IOException {
|
||||
HashMap<String,String> map = new HashMap<>();
|
||||
Attachment attachment=new Attachment();
|
||||
File path = null;
|
||||
try {
|
||||
path = new File(ResourceUtils.getURL("classpath:").getPath());
|
||||
File upload = new File(path.getAbsolutePath(),"static/"+cate+"/");
|
||||
Date date=new Date();
|
||||
|
||||
DateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
DateFormat format1 = new SimpleDateFormat("yyyyMM");
|
||||
String date1=format.format(date);
|
||||
String fileName = multipartFile.getOriginalFilename();//文件全名
|
||||
String date2=format1.format(date);
|
||||
File parentDir = new File(upload.getAbsolutePath()+"/" + date2);
|
||||
if(!upload.exists()){
|
||||
upload.mkdirs();
|
||||
}
|
||||
if(!parentDir.exists()){
|
||||
parentDir.mkdirs();
|
||||
}
|
||||
String suffix = suffix(fileName);//文件后缀
|
||||
String finalFileName=UUID.randomUUID().toString().replaceAll("-","");
|
||||
String relPath = "/" + date2 + "/" + finalFileName + suffix;
|
||||
File fileUp = new File(upload.getAbsolutePath()+ relPath);
|
||||
|
||||
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
|
||||
public int updateConfis(Config config) {
|
||||
public int updateConfig(Config config) {
|
||||
if (configDao.selectByName(config.getName())==null){
|
||||
return 2;
|
||||
}
|
||||
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 java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
||||
@@ -59,8 +60,15 @@ public class UserServiceImpl implements UserService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String sendEmailActivecode(User user) {
|
||||
return EmailUtils.sendEmail(user);
|
||||
public HashMap<Integer, Object> getAllUsers() {
|
||||
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
|
||||
|
Reference in New Issue
Block a user