Merge remote-tracking branch 'origin/master'

This commit is contained in:
cyk
2023-12-25 13:29:05 +08:00
57 changed files with 1099 additions and 459 deletions

View File

@@ -1,9 +1,18 @@
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 java.io.IOException;
import java.util.HashMap;
import java.util.Map;
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);
}

View File

@@ -6,7 +6,15 @@ import java.util.HashMap;
public interface ConfigService {
public HashMap<String,Object>getAllConfig();
public int updateConfis(Config config);
public int updateConfig(Config config);
public String addConfig(Config config);
HashMap<String, String> selectEmailConfig();
public Config selectAlreadyExist(Config config);
}

View File

@@ -0,0 +1,9 @@
package com.lovenav.service;
import com.lovenav.entity.LoginLogs;
public interface LoginLogsService {
public String addLoginLogs(LoginLogs loginLogs);
}

View 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);
}

View File

@@ -8,10 +8,10 @@ import java.util.List;
public interface UrlCateListService {
public int selectAndInsertUrlCate(String email , String cateName , String parent);
public int selectAndInsertUrlCate(Integer userId , String cateName , String parent,String icon);
public List<UrlCateList> selectUrListByUserId(Integer userId);
public String countCateContainUrlNumber(String userId);
public String countCateContainUrlNumber(Integer userId);
public JSONArray getUrl(String userId);
public String selectUrListCateByUrlCateId(Integer cateId);

View File

@@ -6,7 +6,7 @@ import java.util.List;
public interface UrlListService {
public int selectCateAndInsertUrl(String parent,String name , String icon ,String url ,String email );
public int selectCateAndInsertUrl(String parent,String name , String icon ,String url ,Integer userId );
public List<UrlList> selectUrList();
public UrlList selectUrListByInput(String input);
public UrlList selectUrlListByUrlId(Long urlId);

View File

@@ -2,12 +2,12 @@ package com.lovenav.service;
import com.lovenav.entity.User;
import java.util.HashMap;
public interface UserService {
public String sendEmailActivecode(User user);
public String sendEmailActivecode(User user, HashMap<String,String>configMap);
public int UserRegister(User user);
public User selectUserAlreadyExist(User user);
@@ -16,4 +16,6 @@ public interface UserService {
public int updatePassword(User user);
HashMap<Integer,Object> getAllUsers();
}

View File

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

View File

@@ -5,6 +5,8 @@ import com.alibaba.fastjson2.JSONObject;
import com.lovenav.dao.CommentDao;
import com.lovenav.dao.UserDao;
import com.lovenav.entity.Comment;
import com.lovenav.entity.CommentNode;
import com.lovenav.entity.User;
import com.lovenav.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -64,10 +66,16 @@ public class CommentServiceImpl implements CommentService {
return JSON.toJSONString(hashMap);
}
// 显示评论
// 显示一级评论和用户信息
public String View_comment(){
List<Comment> list = commentDao.selectAllComment();
return JSON.toJSONString(list);
List<Comment> list_comment = commentDao.selectAllComment();
HashMap<Comment, User> result = new HashMap<>();
for(int i=0;i<list_comment.size();++i){
int user_id = list_comment.get(i).getUserId();
User user = userDao.selectByPrimaryKey(user_id);
result.put(list_comment.get(i),user );
}
return JSON.toJSONString(result);
}
// 显示回复
@@ -75,4 +83,57 @@ public class CommentServiceImpl implements CommentService {
List<Comment> list = commentDao.selectByAllReply(id);
return JSON.toJSONString(list);
}
private boolean addNode (List<CommentNode> firstList, CommentNode commentNode ) {
//循环添加
for (CommentNode node : firstList) {
//判断留言的上一段是否是这条留言(判断这条回复,是否是当前评论的回复)
if (node.getId().equals(commentNode.getRootCommentId())) {
//是添加返回true
node.getNextNodes().add(commentNode);
return true;
} else {
//否则递归继续判断
if (node.getNextNodes().size() != 0) {
if (addNode(node.getNextNodes(), commentNode)) {
return true;
}
}
}
}
return false;
}
/**
* 功能描述将查出来的lastId不为null的回复都添加到第一层Node集合中
*
* @param firstList 第一层评论集合(链表)
* @param thenList 非第一层评论集合(链表)
* @return 所有评论集合(非第一层评论集合对应添加到第一层评论集合,返回)
*/
private List<CommentNode> addAllNode ( List<CommentNode> firstList, List<CommentNode> thenList ) {
while (thenList.size() != 0) {
int size = thenList.size();
for (int i = 0; i < size; i++) {
if (addNode(firstList, new CommentNode(thenList.get(i)))) {
thenList.remove(i);
i--;
size--;
}
}
}
return firstList;
}
public List<CommentNode> queryObserveByBlogId ( Integer UrlId ) {
//所有未处理的一级评论集合
List<CommentNode> firstCommentList = commentDao.queryFirstCommentList(UrlId);
//所有未处理的二级评论集合
List<CommentNode> secondCommentList = commentDao.querySecondCommentList(UrlId);
//将二级评论用链表的方式添加到一级评论
List<CommentNode> list = addAllNode(firstCommentList, secondCommentList);
return list;
}
}

View File

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

View File

@@ -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 "更新登录日志失败";
}
}

View File

@@ -22,39 +22,80 @@ public class QRCServiceImpl implements QRCService{
private CollectIconListDao collectIconListDao;
public String QR(CollectIconList collect) throws Exception {
String logoPath ="src/main/resources/static/logo/NAV.png";
String logoPath = "src/main/resources/static/logo/NAV.png";
String destPath = "src/main/resources/static/qr";
// 通过传入collect的url_id查找相同网址图片列表
// List<CollectIconList> collectIconList = collectIconListDao.selectByUrlid(collect.getUrl_id());
// 通过collect的url_id查找网址id对应网址
UrlList urlList = urlListDao.selectByPrimaryKey(Long.valueOf(collect.getUrl_id()));
List<CollectIconList> list = collectIconListDao.selectByUrlid(collect.getUrl_id());
if(list.size()==0){
if(urlList != null){
// 将icon下载到本地并存储本地路径
// 如果表中没有可以插入
if (list.size() == 0) {
// 如果icon是url
if(QRCodeUtil.notBase64(collect.getIcon_url())){
String icon_url = QRCodeUtil.downloadPicture(collect.getIcon_url());
collect.setIcon_url(icon_url);
// 获取网址url
String url = urlList.getUrl();
// 将网址生成二维码并返回本地路径
// 将网址生成二维码并返回本地路径
String url_wait = QRCodeUtil.encode(url, logoPath, destPath, true);
// 为collect设置二维码本地路径
collect.setQr_url(url_wait);
collectIconListDao.insert(collect);
String base64 = QRCodeUtil.ImageToBase64(url_wait);
collectIconListDao.insert(collect);
return JSON.toJSONString(base64);
}else{
HashMap<String,Object> result = new HashMap<>();
result.put("code",500);
result.put("msg", "找不到对应网址");
return JSON.toJSONString(result);
}
}else{
String url_wait = list.get(0).getQr_url();
String base64 = QRCodeUtil.ImageToBase64(url_wait);
return JSON.toJSONString(base64);
else {
String base64str = QRCodeUtil.delete_profix(collect.getIcon_url());
String icon_url = QRCodeUtil.GenerateImage(base64str,"src/main/resources/static/icon");
collect.setIcon_url(icon_url);
String url = urlList.getUrl();
String url_wait = QRCodeUtil.encode(url, logoPath, destPath, true);
collect.setQr_url(url_wait);
String base64 = QRCodeUtil.ImageToBase64(url_wait);
collectIconListDao.insert(collect);
return JSON.toJSONString(base64);
}
} else {
return JSON.toJSONString(QRCodeUtil.ImageToBase64(list.get(0).getQr_url()));
}
}
//// 通过传入collect的url_id查找相同网址图片列表
//// List<CollectIconList> collectIconList = collectIconListDao.selectByUrlid(collect.getUrl_id());
//
//// 通过collect的url_id查找网址id对应网址
// UrlList urlList = urlListDao.selectByPrimaryKey(Long.valueOf(collect.getUrl_id()));
//
// List<CollectIconList> list = collectIconListDao.selectByUrlid(collect.getUrl_id());
// if(list.size()==0){
// if(urlList != null && collect.getIcon_url()!=null){
//// 将icon下载到本地并存储本地路径
// String icon_url = QRCodeUtil.downloadPicture(collect.getIcon_url());
// collect.setIcon_url(icon_url);
//
//
//// 为collect设置二维码本地路径
// collect.setQr_url(url_wait);
// collectIconListDao.insert(collect);
// String base64 = QRCodeUtil.ImageToBase64(url_wait);
// return JSON.toJSONString(base64);
// }else if(urlList != null && collect.getIcon_url()==null){
//// 获取网址url
// String url = urlList.getUrl();
// String url_wait = QRCodeUtil.encode(url, logoPath, destPath, true);
//// 为collect设置二维码本地路径
// collect.setQr_url(url_wait);
// collectIconListDao.insert(collect);
// String base64 = QRCodeUtil.ImageToBase64(url_wait);
// return JSON.toJSONString(base64);
// }
// }else{
// String url_wait = list.get(0).getQr_url();
// String base64 = QRCodeUtil.ImageToBase64(url_wait);
// return JSON.toJSONString(base64);
// }
// return null;
// }
}

View File

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

View File

@@ -27,22 +27,24 @@ public class UrlCateListServiceImpl implements UrlCateListService {
UrlListDao urlListDao;
@Autowired
UserDao userDao;
public int selectAndInsertUrlCate(String email , String cateName , String parent )
public int selectAndInsertUrlCate(Integer userId , String cateName , String parent,String icon )
{
//找用户ID
User user = userDao.selectByEmail(email);
int userId = user.getId();
parent = parent.substring(1,parent.length()-1);
//找父标签有没有
UrlCateList cateParent = urlCateListDao.selectCateByNameAnduserId(parent,userId);
UrlCateList targetCate = new UrlCateList();
//设置属性
targetCate.setName(cateName);
targetCate.setName(cateName.substring(1,cateName.length()-1));
targetCate.setUserId(userId);
Date date = new Date();
targetCate.setCreatetime(date.getTime());
targetCate.setWeigh(Long.valueOf(0));
targetCate.setStatus(Byte.valueOf(0+""));
targetCate.setNeedLogin(Byte.valueOf(0+""));
targetCate.setIco(icon);
if(cateParent != null)
{
targetCate.setRootCateId(cateParent.getId());
@@ -85,10 +87,9 @@ public class UrlCateListServiceImpl implements UrlCateListService {
return urlCateListDao.selectByPrimaryKey(id);
}
public String countCateContainUrlNumber(String email){
User user = userDao.selectByEmail(email);
int userId = user.getId();
List<UrlCateList> urlCateLists =urlCateListDao.selectUrListByUserId(userId);
public String countCateContainUrlNumber(Integer userId){
List<UrlCateList> urlCateLists =urlCateListDao.selectUrListByUserId(3);
List<UrlList> urlLists = urlListDao.selectUrList();
HashMap<String,Integer> CateNumber = new HashMap<>();
@@ -96,24 +97,27 @@ public class UrlCateListServiceImpl implements UrlCateListService {
{
CateNumber.put(urlCateList.getName(),0);
}
for(UrlList urlList : urlLists){
Long id = Long.valueOf(urlList.getCateId());
while(id!= 0)
for(UrlList urlList : urlLists){
String parentString = urlCateListDao.selectUrListCateByUrlCateId(urlList.getCateId());
if (parentString == null) continue;
String [] strings = parentString.split(",");
for(String str :strings)
{
if(str.equals("0")) continue;
for(UrlCateList urlCateList :urlCateLists)
{
if(id == Long.valueOf(urlCateList.getId())){
if(urlCateList.getId() == Integer.valueOf(str)){
int cateNum = CateNumber.get(urlCateList.getName())+1;
CateNumber.put(urlCateList.getName(),cateNum);
id=Long.valueOf(urlCateList.getRootCateId());
System.out.println(urlCateList.getName());
break;
}
}
}
}
Iterator iterator = CateNumber.entrySet().iterator();
while(iterator.hasNext()) {

View File

@@ -25,22 +25,29 @@ public class UrlLiserServiceImpl implements UrlListService {
UrlListDao urlListDao;
@Autowired
UserDao userDao;
public int selectCateAndInsertUrl(String parent,String name , String icon ,String url ,String email)
public int selectCateAndInsertUrl(String parent,String name , String icon ,String url ,Integer userId)
{
//找用户ID
User user = userDao.selectByEmail(email);
int userId = user.getId();
parent = parent.substring(1,parent.length()-1);
UrlCateList urlCateList = urlCateListDao.selectCateByNameAnduserId(parent,userId);
UrlList urlList = new UrlList();
if (urlCateList == null)
{
urlList.setCateId(0);
}else{
urlList.setCateId(urlCateList.getId());
}
//设置属性
urlList.setCateId(urlCateList.getId());
urlList.setUrl(url);
urlList.setIcon(icon);
urlList.setName(name);
urlList.setName(name.substring(1,name.length()-1));
Date date = new Date();
urlList.setCreatetime(date.getTime());
urlList.setViews(Long.valueOf("0"));
urlList.setIsNeedAgent(Byte.valueOf(0+""));
urlList.setIsAd(Byte.valueOf(0+""));
urlList.setIsTop(Byte.valueOf(0+""));
urlList.setStatus(Byte.valueOf(0+""));
Byte b = 0;
urlList.setNeedLogin(b);
int flag = urlListDao.insert(urlList);

View File

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