Merge remote-tracking branch 'origin/master'

This commit is contained in:
2023-12-22 21:52:47 +08:00
28 changed files with 1065 additions and 76 deletions

View File

@@ -0,0 +1,14 @@
package com.lovenav.service;
import com.lovenav.entity.Banners;
public interface BannersService {
// 跳转链接
String Jump_url(int id);
// 添加banner
String Add_banner(Banners banners);
// 删除banner
String Delete_banner(int id);
// 展示banner
String View_banner();
}

View File

@@ -10,7 +10,11 @@ public interface CommentService {
// 评论
String Reply1(Comment comment);
// 回复
String Reply2(Comment comment);
String Reply2(Comment comment,int id);
// 删除
String Delete(int id);
// 显示评论
String View_comment();
// 显示回复
String View_Reply(int id);
}

View File

@@ -1,5 +1,6 @@
package com.lovenav.service;
import com.alibaba.fastjson2.JSONArray;
import com.lovenav.entity.UrlCateList;
import java.util.List;
@@ -9,4 +10,8 @@ public interface UrlCateListService {
public int selectAndInsertUrlCate(String email , String cateName , String parent);
public List<UrlCateList> selectUrListByUserId(Integer userId);
public String countCateContainUrlNumber(String userId);
public JSONArray getUrl(String userId);
}

View File

@@ -0,0 +1,67 @@
package com.lovenav.service.serviceImpl;
import com.alibaba.fastjson.JSON;
import com.lovenav.dao.BannersDao;
import com.lovenav.entity.Banners;
import com.lovenav.service.BannersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.HashMap;
@Service
public class BannersServiceImpl implements BannersService {
@Autowired
private BannersDao bannersDao;
// 跳转链接
@Override
public String Jump_url(int id){
Banners banners = bannersDao.selectByPrimaryKey(id);
HashMap<String, Object> hashMap = new HashMap<>();
if(banners != null){
hashMap.put("url",banners.getUrl());
}else{
hashMap.put("code",500);
hashMap.put("msg","找不到指定链接");
}
return JSON.toJSONString(hashMap);
}
// 添加banner
@Override
public String Add_banner(Banners banners) {
int result = bannersDao.insert(banners);
HashMap<String, Object> hashMap = new HashMap<>();
if(result>0){
return JSON.toJSONString(banners);
}else{
hashMap.put("code",500);
hashMap.put("msg","添加banner失败");
return JSON.toJSONString(hashMap);
}
}
// 删除banner
@Override
public String Delete_banner(int id){
int result = bannersDao.deleteByPrimaryKey(id);
HashMap<String, Object> hashMap = new HashMap<>();
if(result>0){
hashMap.put("code",200);
hashMap.put("msg","删除成功");
return JSON.toJSONString(hashMap);
}else{
hashMap.put("code",500);
hashMap.put("msg","删除失败");
return JSON.toJSONString(hashMap);
}
}
// 展示banner
@Override
public String View_banner(){
List<Banners> list = bannersDao.selectByAllBanners();
return JSON.toJSONString(list);
}
}

View File

@@ -3,6 +3,7 @@ package com.lovenav.service.serviceImpl;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.lovenav.dao.CommentDao;
import com.lovenav.dao.UserDao;
import com.lovenav.entity.Comment;
import com.lovenav.service.CommentService;
import org.apache.ibatis.jdbc.Null;
@@ -13,10 +14,12 @@ import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
@Service("commentService")
@Service
public class CommentServiceImpl implements CommentService {
@Autowired
private CommentDao commentDao;
@Autowired
private UserDao userDao;
// 评论功能
@Override
public String Reply1(Comment comment){
@@ -32,18 +35,11 @@ public class CommentServiceImpl implements CommentService {
}
// 回复功能
@Override
public String Reply2(Comment comment){
List<Integer> list = commentDao.selectByRootId(comment.getRootCommentId());
if(list.size()<5){
commentDao.insert(comment);
return JSON.toJSONString(comment);
}else{
HashMap<String, Object> result = new HashMap<>();
result.put("code", 500);
result.put("msg", "回复超过上限");
String jsonString = JSONObject.toJSONString(result);
return JSON.toJSONString(result);
}
public String Reply2(Comment comment,int id){
String name = (userDao.selectByPrimaryKey(id)).getNickname();
HashMap<Comment,String> hashMap = new HashMap<>();
hashMap.put(comment, name);
return JSON.toJSONString(hashMap);
}
// 删除
@Override
@@ -67,7 +63,19 @@ public class CommentServiceImpl implements CommentService {
comment.setLikeCount(comment.getLikeCount()+1);
commentDao.updateByPrimaryKeySelective(comment);
HashMap<String, Long> hashMap = new HashMap<>();
hashMap.put("点赞成功:",comment.getLikeCount());
hashMap.put("点赞成功",comment.getLikeCount());
return JSON.toJSONString(hashMap);
}
// 显示评论
public String View_comment(){
List<Comment> list = commentDao.selectByAllComment();
return JSON.toJSONString(list);
}
// 显示回复
public String View_Reply(int id){
List<Comment> list = commentDao.selectByAllReply(id);
return JSON.toJSONString(list);
}
}

View File

@@ -1,16 +1,19 @@
package com.lovenav.service.serviceImpl;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.lovenav.dao.UrlCateListDao;
import com.lovenav.dao.UrlListDao;
import com.lovenav.dao.UserDao;
import com.lovenav.entity.UrlCateList;
import com.lovenav.entity.UrlList;
import com.lovenav.entity.User;
import com.lovenav.service.UrlCateListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
import java.util.*;
@Transactional
@Service("urlCateListService")
@@ -20,7 +23,8 @@ public class UrlCateListServiceImpl implements UrlCateListService {
@Autowired
UrlCateListDao urlCateListDao;
@Autowired
UrlListDao urlListDao;
@Autowired
UserDao userDao;
public int selectAndInsertUrlCate(String email , String cateName , String parent )
@@ -53,4 +57,75 @@ public class UrlCateListServiceImpl implements UrlCateListService {
public List<UrlCateList> selectUrListByUserId(Integer userId){
return urlCateListDao.selectUrListByUserId(userId);
}
public String countCateContainUrlNumber(String email){
User user = userDao.selectByEmail(email);
int userId = user.getId();
List<UrlCateList> urlCateLists =urlCateListDao.selectUrListByUserId(userId);
List<UrlList> urlLists = urlListDao.selectUrList();
HashMap<String,Integer> CateNumber = new HashMap<>();
for(UrlCateList urlCateList :urlCateLists)
{
CateNumber.put(urlCateList.getName(),0);
}
for(UrlList urlList : urlLists){
Long id = Long.valueOf(urlList.getCateId());
while(id!= 0)
{
for(UrlCateList urlCateList :urlCateLists)
{
if(id == Long.valueOf(urlCateList.getId())){
int cateNum = CateNumber.get(urlCateList.getName())+1;
CateNumber.put(urlCateList.getName(),cateNum);
id=Long.valueOf(urlCateList.getRootCateId());
break;
}
}
}
}
Iterator iterator = CateNumber.entrySet().iterator();
while(iterator.hasNext()) {
Map.Entry<String, Integer> entry=(Map.Entry<String, Integer>) iterator.next();
for(int i = 0; i<urlCateLists.size();i++)
{
UrlCateList urlCateList = urlCateLists.get(i);
if(urlCateList.getName().equals(entry.getKey()))
{
urlCateList.setUrlNumber(Long.valueOf(entry.getValue()));
urlCateListDao.updateByPrimaryKeySelective(urlCateList);
break;
}
}
}
return CateNumber.toString();
}
public JSONArray getUrl(String userId)
{
List<UrlCateList> urlCateLists =urlCateListDao.selectUrListByUserId(Integer.valueOf(userId));
List<UrlList> urlLists = urlListDao.selectUrList();
JSONArray jsonArray = new JSONArray();
for(UrlCateList urlCateList : urlCateLists)
{
int parentId = urlCateList.getId();
for(UrlList urlList : urlLists)
{
if(urlList.getCateId() == parentId)
{
JSONObject jsonObject = new JSONObject();
jsonObject.put(urlList.getName(),urlList.getUrl());
jsonArray.add(jsonObject);
break;
}
}
}
return jsonArray;
}
}