Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
软件工程实践2022年春W班
Followers
Project_Team4
提交
7c998b77
P
Project_Team4
项目概览
软件工程实践2022年春W班
/
Followers
/
Project_Team4
通知
10
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Project_Team4
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
7c998b77
编写于
5月 01, 2022
作者:
LKJKJOIUIU
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
收藏取消收藏接口
上级
9ab16508
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
99 addition
and
5 deletion
+99
-5
backend/src/main/java/com/nav/controller/PostController.java
backend/src/main/java/com/nav/controller/PostController.java
+4
-0
backend/src/main/java/com/nav/dao/PostDao.java
backend/src/main/java/com/nav/dao/PostDao.java
+33
-1
backend/src/main/java/com/nav/service/PostService.java
backend/src/main/java/com/nav/service/PostService.java
+10
-0
backend/src/main/java/com/nav/service/PostServiceImpl.java
backend/src/main/java/com/nav/service/PostServiceImpl.java
+18
-2
backend/src/main/resources/application.yml
backend/src/main/resources/application.yml
+1
-1
backend/src/main/resources/mapper/PostMapper.xml
backend/src/main/resources/mapper/PostMapper.xml
+33
-1
未找到文件。
backend/src/main/java/com/nav/controller/PostController.java
浏览文件 @
7c998b77
...
@@ -61,4 +61,8 @@ public class PostController {
...
@@ -61,4 +61,8 @@ public class PostController {
return
postService
.
getLifePostByTag
(
tag
);
return
postService
.
getLifePostByTag
(
tag
);
}
}
@GetMapping
(
"/post/CollectionCount/{userId}/{postId}"
)
public
CommonResult
updateCollectionCountById
(
@PathVariable
long
userId
,
@PathVariable
long
postId
)
{
return
postService
.
updateCollectionCountById
(
userId
,
postId
);
}
}
}
backend/src/main/java/com/nav/dao/PostDao.java
浏览文件 @
7c998b77
...
@@ -5,6 +5,7 @@ import com.nav.vo.result.LifePostResult;
...
@@ -5,6 +5,7 @@ import com.nav.vo.result.LifePostResult;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -42,7 +43,7 @@ public interface PostDao {
...
@@ -42,7 +43,7 @@ public interface PostDao {
* @param postId:文章id
* @param postId:文章id
* @return:int :点赞数
* @return:int :点赞数
**/
**/
public
int
updateLikeCountById
(
@Param
(
"userId"
)
long
userId
,
@Param
(
"postId"
)
long
postId
);
public
int
updateLikeCountById
(
@Param
(
"userId"
)
long
userId
,
@Param
(
"postId"
)
long
postId
,
@Param
(
"createTime"
)
Date
createTime
,
@Param
(
"modifiedTime"
)
Date
modifiedTime
);
/**
/**
* 方法说明:根据文章id更新浏览量
* 方法说明:根据文章id更新浏览量
...
@@ -90,4 +91,35 @@ public interface PostDao {
...
@@ -90,4 +91,35 @@ public interface PostDao {
* @return:int :点赞数
* @return:int :点赞数
**/
**/
public
int
updateDownLikeCountById
(
@Param
(
"userId"
)
long
userId
,
@Param
(
"postId"
)
long
postId
);
public
int
updateDownLikeCountById
(
@Param
(
"userId"
)
long
userId
,
@Param
(
"postId"
)
long
postId
);
/**
* 方法说明:根据用户id和文章id查找该用户是否收藏过
* @author zyx
* @date 2022/5/1 11:32
* @param userId:用户id
* @param postId:文章id
* @return:int :1已收藏,0未收藏
**/
public
int
selectCollectionById
(
@Param
(
"userId"
)
long
userId
,
@Param
(
"postId"
)
long
postId
);
/**
* 方法说明:根据用户id和文章id增加收藏数
* @author zyx
* @date 2022/5/1 11:35
* @param userId:用户id
* @param postId:文章id
* @return:int :收藏数
**/
public
int
updateCollectionCountById
(
@Param
(
"userId"
)
long
userId
,
@Param
(
"postId"
)
long
postId
,
@Param
(
"createTime"
)
Date
createTime
,
@Param
(
"modifiedTime"
)
Date
modifiedTime
);
/**
* 方法说明:根据用户id和文章id减少收藏数
* @author zyx
* @date 2022/5/1 11:37
* @param userId:用户id
* @param postId:文章id
* @return:int :收藏数
**/
public
int
updateDownCollectionCountById
(
@Param
(
"userId"
)
long
userId
,
@Param
(
"postId"
)
long
postId
);
}
}
backend/src/main/java/com/nav/service/PostService.java
浏览文件 @
7c998b77
...
@@ -109,4 +109,14 @@ public interface PostService {
...
@@ -109,4 +109,14 @@ public interface PostService {
* @return:com.nav.common.api.CommonResult
* @return:com.nav.common.api.CommonResult
**/
**/
public
CommonResult
updateLikeCount
(
long
userId
,
long
postId
);
public
CommonResult
updateLikeCount
(
long
userId
,
long
postId
);
/**
* 方法说明:先判断用户是否收藏过,如果已收藏,则取消收藏,否则收藏数加一
* @author zyx
* @date 2022/5/1 11:42
* @param userId:用户id
* @param postId:文章id
* @return:com.nav.common.api.CommonResult
**/
public
CommonResult
updateCollectionCountById
(
long
userId
,
long
postId
);
}
}
backend/src/main/java/com/nav/service/PostServiceImpl.java
浏览文件 @
7c998b77
...
@@ -9,7 +9,10 @@ import com.nav.vo.result.LifePostResult;
...
@@ -9,7 +9,10 @@ import com.nav.vo.result.LifePostResult;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
import
java.util.TimeZone
;
/**
/**
* 类说明
* 类说明
...
@@ -36,7 +39,7 @@ public class PostServiceImpl implements PostService{
...
@@ -36,7 +39,7 @@ public class PostServiceImpl implements PostService{
@Override
@Override
public
CommonResult
updateLikeCountById
(
long
userId
,
long
postId
)
{
public
CommonResult
updateLikeCountById
(
long
userId
,
long
postId
)
{
return
CommonResult
.
success
(
postDao
.
updateLikeCountById
(
userId
,
postId
),
"请求成功"
);
return
CommonResult
.
success
(
postDao
.
updateLikeCountById
(
userId
,
postId
,
new
Date
(),
new
Date
()
),
"请求成功"
);
}
}
@Override
@Override
...
@@ -74,7 +77,7 @@ public class PostServiceImpl implements PostService{
...
@@ -74,7 +77,7 @@ public class PostServiceImpl implements PostService{
@Override
@Override
public
CommonResult
updateLikeCount
(
long
userId
,
long
postId
)
{
public
CommonResult
updateLikeCount
(
long
userId
,
long
postId
)
{
int
isLike
=
getLikeById
(
userId
,
postId
);
int
isLike
=
getLikeById
(
userId
,
postId
);
if
(
isLike
=
=
1
){
if
(
isLike
>
=
1
){
//取消点赞
//取消点赞
return
updateDownLikeCountById
(
userId
,
postId
);
return
updateDownLikeCountById
(
userId
,
postId
);
}
}
...
@@ -83,4 +86,17 @@ public class PostServiceImpl implements PostService{
...
@@ -83,4 +86,17 @@ public class PostServiceImpl implements PostService{
return
updateLikeCountById
(
userId
,
postId
);
return
updateLikeCountById
(
userId
,
postId
);
}
}
}
}
@Override
public
CommonResult
updateCollectionCountById
(
long
userId
,
long
postId
)
{
int
isCollect
=
postDao
.
selectCollectionById
(
userId
,
postId
);
if
(
isCollect
>=
1
){
//取消收藏
return
CommonResult
.
success
(
postDao
.
updateDownCollectionCountById
(
userId
,
postId
),
"请求成功"
);
}
else
{
//收藏
return
CommonResult
.
success
(
postDao
.
updateCollectionCountById
(
userId
,
postId
,
new
Date
(),
new
Date
()),
"请求成功"
);
}
}
}
}
backend/src/main/resources/application.yml
浏览文件 @
7c998b77
...
@@ -4,7 +4,7 @@ server:
...
@@ -4,7 +4,7 @@ server:
spring
:
spring
:
datasource
:
datasource
:
driver-class-name
:
com.mysql.cj.jdbc.Driver
driver-class-name
:
com.mysql.cj.jdbc.Driver
url
:
jdbc:mysql://47.95.151.202/nav?useUnicode=true&characterEncoding=UTF-8&serverTimezone=
GMT
&allowMultiQueries=true
url
:
jdbc:mysql://47.95.151.202/nav?useUnicode=true&characterEncoding=UTF-8&serverTimezone=
Asia/Shanghai
&allowMultiQueries=true
username
:
root
username
:
root
password
:
Nav_123456
password
:
Nav_123456
servlet
:
servlet
:
...
...
backend/src/main/resources/mapper/PostMapper.xml
浏览文件 @
7c998b77
...
@@ -25,7 +25,7 @@
...
@@ -25,7 +25,7 @@
set like_count = like_count+1
set like_count = like_count+1
where id = #{postId};
where id = #{postId};
insert into praise_list(user_id,post_id
) values(#{userId},#{postId
});
insert into praise_list(user_id,post_id
,gmt_create,gmt_modified) values(#{userId},#{postId},#{createTime},#{modifiedTime
});
select like_count
select like_count
from post
from post
...
@@ -82,4 +82,36 @@
...
@@ -82,4 +82,36 @@
where post_id=#{postId} and user_id=#{userId};
where post_id=#{postId} and user_id=#{userId};
</select>
</select>
<select
id=
"selectCollectionById"
resultType=
"int"
>
select count(*)
from collection_list
where post_id=#{postId} and user_id=#{userId};
</select>
<!--收藏-->
<select
id=
"updateCollectionCountById"
resultType=
"int"
>
update post
set collection_count = collection_count+1
where id = #{postId};
insert into collection_list(user_id,post_id,gmt_create,gmt_modified) values(#{userId},#{postId},#{createTime},#{modifiedTime});
select collection_count
from post
where post.id = #{postId};
</select>
<!--取消收藏-->
<select
id=
"updateDownCollectionCountById"
resultType=
"int"
>
update post
set collection_count = collection_count-1
where id = #{postId};
delete from collection_list where post_id=#{postId} and user_id = #{userId};
select collection_count
from post
where post.id = #{postId};
</select>
</mapper>
</mapper>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录