修正comment,banner接口

This commit is contained in:
sjm 2023-12-22 14:03:59 +08:00
parent 39048bbcfc
commit 7d3f10a7dc
11 changed files with 224 additions and 23 deletions

View File

@ -0,0 +1,40 @@
package com.lovenav.controller;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.lovenav.entity.Banners;
import com.lovenav.service.BannersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/banners")
public class BannersController {
@Autowired
private BannersService bannersService;
// 跳转链接
@RequestMapping(method = RequestMethod.GET, value = "/jump_url")
public String jump(int id){
return bannersService.Jump_url(id);
}
// 添加banner
@RequestMapping(method = RequestMethod.POST, value = "/add_banner")
public String add(@RequestBody Banners banners){
return bannersService.Add_banner(banners);
}
// 删除banner
@RequestMapping(method = RequestMethod.GET, value = "/delete_url")
public String delete(int id){
return bannersService.Delete_banner(id);
}
// 首页显示banner
@RequestMapping(method = RequestMethod.GET, value = "/view_banner")
public String view(){
return bannersService.View_banner();
}
}

View File

@ -21,15 +21,15 @@ public class CommentController {
@Autowired @Autowired
private CommentService commentService; private CommentService commentService;
// 评论功能 // 评论功能
@RequestMapping(method = RequestMethod.POST, value = "/reply_comment") @RequestMapping(method = RequestMethod.POST, value = "/comment")
public String Reply1(@RequestBody Comment comment){ public String Reply1(@RequestBody Comment comment){
return commentService.Reply1(comment); return commentService.Reply1(comment);
} }
// 回复功能 // 回复功能
@RequestMapping(method = RequestMethod.POST, value = "/comment") @RequestMapping(method = RequestMethod.POST, value = "/reply_comment")
public String Reply2(@RequestBody Comment comment){ public String Reply2(@RequestBody Comment comment,int id){
return commentService.Reply2(comment); return commentService.Reply2(comment,id);
} }
// 删除功能 // 删除功能
@RequestMapping(method = RequestMethod.GET, value = "/delete_comment") @RequestMapping(method = RequestMethod.GET, value = "/delete_comment")
@ -40,4 +40,10 @@ public class CommentController {
public String addLikeCount(int id){ public String addLikeCount(int id){
return commentService.AddLikeCount(id); return commentService.AddLikeCount(id);
} }
// 显示评论
@RequestMapping(method = RequestMethod.GET, value = "/view_comment")
public String View_comment(){
return commentService.View_comment();
}
} }

View File

@ -1,9 +1,13 @@
package com.lovenav.dao; package com.lovenav.dao;
import com.lovenav.entity.Banners; import com.lovenav.entity.Banners;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List;
@Repository @Repository
@Mapper
public interface BannersDao { public interface BannersDao {
int deleteByPrimaryKey(Integer id); int deleteByPrimaryKey(Integer id);
@ -16,4 +20,6 @@ public interface BannersDao {
int updateByPrimaryKeySelective(Banners record); int updateByPrimaryKeySelective(Banners record);
int updateByPrimaryKey(Banners record); int updateByPrimaryKey(Banners record);
List<Banners> selectByAllBanners();
} }

View File

@ -22,5 +22,5 @@ public interface CommentDao {
int updateByPrimaryKey(Comment record); int updateByPrimaryKey(Comment record);
List<Integer> selectByRootId(Integer rootid); List<Comment> selectByAllComment();
} }

View File

@ -2,6 +2,9 @@ package com.lovenav.entity;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
import com.alibaba.fastjson2.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data; import lombok.Data;
/** /**
@ -9,6 +12,57 @@ import lombok.Data;
*/ */
@Data @Data
public class Banners implements Serializable { public class Banners implements Serializable {
public Banners(){
this.bannerStatus = 0;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getImgUrl() {
return imgUrl;
}
public void setImgUrl(String imgUrl) {
this.imgUrl = imgUrl;
}
public Integer getWeigh() {
return weigh;
}
public void setWeigh(Integer weigh) {
this.weigh = weigh;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public Byte getBannerStatus() {
return bannerStatus;
}
public void setBannerStatus(Byte bannerStatus) {
this.bannerStatus = bannerStatus;
}
public Date getCreatetime() {
return createtime;
}
public void setCreatetime(Date createtime) {
this.createtime = createtime;
}
/** /**
* id * id
*/ */

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,9 @@ public interface CommentService {
// 评论 // 评论
String Reply1(Comment comment); String Reply1(Comment comment);
// 回复 // 回复
String Reply2(Comment comment); String Reply2(Comment comment,int id);
// 删除 // 删除
String Delete(int id); String Delete(int id);
// 显示评论
String View_comment();
} }

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

View File

@ -95,4 +95,12 @@
createtime = #{createtime,jdbcType=TIMESTAMP} createtime = #{createtime,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}
</update> </update>
<select id="selectByAllBanners" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
*
from ln_banners
</select>
</mapper> </mapper>

View File

@ -145,11 +145,13 @@
where id = #{id,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}
</update> </update>
<select id="selectByRootId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
<select id="selectByAllComment" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select select
id *
from ln_comment from ln_comment
where root_comment_id = #{rootCommentId,jdbcType=INTEGER} where root_comment_id = 0 and comment_status = 0
</select> </select>
</mapper> </mapper>