Administrator 4 weeks ago
parent
commit
11d9c7e0dc
  1. 6
      src/main/java/org/hlrj/duobao_demo/controller/RecommendationController.java
  2. 28
      src/main/java/org/hlrj/duobao_demo/controller/SpecialTopicController.java
  3. 6
      src/main/java/org/hlrj/duobao_demo/controller/VideoDataController.java
  4. 4
      src/main/java/org/hlrj/duobao_demo/entity/Recommendation.java
  5. 2
      src/main/java/org/hlrj/duobao_demo/entity/VideoData.java
  6. 2
      src/main/java/org/hlrj/duobao_demo/mapper/RecommendationMapper.java
  7. 4
      src/main/java/org/hlrj/duobao_demo/mapper/SpecialTopicMapper.java
  8. 1
      src/main/java/org/hlrj/duobao_demo/mapper/VideoDataMapper.java
  9. 7
      src/main/java/org/hlrj/duobao_demo/service/IRecommendationService.java
  10. 5
      src/main/java/org/hlrj/duobao_demo/service/ISpecialTopicService.java
  11. 6
      src/main/java/org/hlrj/duobao_demo/service/IVideoDataService.java
  12. 6
      src/main/java/org/hlrj/duobao_demo/service/impl/RecommendationServiceImpl.java
  13. 6
      src/main/java/org/hlrj/duobao_demo/service/impl/SpecialTopicServiceImpl.java
  14. 5
      src/main/java/org/hlrj/duobao_demo/service/impl/VideoDataServiceImpl.java
  15. 83
      src/main/resources/mapper/RecommendationMapper.xml
  16. 82
      src/main/resources/mapper/SpecialTopicMapper.xml
  17. 9
      src/main/resources/mapper/VideoDateMapper.xml

6
src/main/java/org/hlrj/duobao_demo/controller/RecommendationController.java

@ -111,10 +111,10 @@ public class RecommendationController {
*/ */
@PostMapping("/addLike/{id}") @PostMapping("/addLike/{id}")
public Result addLike( @PathVariable Integer id){ public Result addLike( @PathVariable Integer id){
log.info("增加点赞操作:{}");
Recommendation recommendation1 = recommendationService.selectById(id);
log.info("点赞操作:{}");
recommendationService.isLiked(id);
recommendationService.addLike(recommendation1);
return Result.success(); return Result.success();
} }

28
src/main/java/org/hlrj/duobao_demo/controller/SpecialTopicController.java

@ -66,17 +66,23 @@ public class SpecialTopicController {
SpecialTopic specialTopic = specialTopicService.selectById(id); SpecialTopic specialTopic = specialTopicService.selectById(id);
return Result.success(specialTopic); return Result.success(specialTopic);
} }
/**
* 点赞数量加1
* @param id
* @return
*/
@PostMapping("/addLike/{id}")
public Result addLike(@PathVariable Integer id){
log.info("增加点赞操作:{}");
SpecialTopic specialTopic = specialTopicService.selectById(id);
specialTopicService.addLike(specialTopic);
// /**
// * 点赞数量加1
// * @param id
// * @return
// */
// @PostMapping("/addLike/{id}")
// public Result addLike(@PathVariable Integer id){
// log.info("增加点赞操作:{}");
// SpecialTopic specialTopic = specialTopicService.selectById(id);
//
// specialTopicService.addLike(specialTopic);
// return Result.success();
// }
@PostMapping("/isLikedById/{id}")
public Result isLikedById(@PathVariable Integer id) {
log.info("点赞操作:{}",id);
specialTopicService.isLikedById(id);
return Result.success(); return Result.success();
} }
} }

6
src/main/java/org/hlrj/duobao_demo/controller/VideoDataController.java

@ -47,4 +47,10 @@ public class VideoDataController {
iVideoDataService.delete(id); iVideoDataService.delete(id);
return Result.success(); return Result.success();
} }
@PostMapping("/isBookedById/{id}")
public Result isBookedById(@PathVariable Integer id) {
log.info("根据id进行预约:{}",id);
iVideoDataService.isBooked(id);
return Result.success();
}
} }

4
src/main/java/org/hlrj/duobao_demo/entity/Recommendation.java

@ -7,6 +7,7 @@ import java.time.LocalDateTime;
import java.io.Serializable; import java.io.Serializable;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import io.swagger.models.auth.In;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
@ -59,4 +60,7 @@ public class Recommendation implements Serializable {
@ApiModelProperty(value = "头像") @ApiModelProperty(value = "头像")
private String head; private String head;
@ApiModelProperty(value = "是否点赞")
private Integer isLiked;
} }

2
src/main/java/org/hlrj/duobao_demo/entity/VideoData.java

@ -45,5 +45,7 @@ public class VideoData implements Serializable {
private String head;//头像 private String head;//头像
private Integer isBooked;//是否预约
} }

2
src/main/java/org/hlrj/duobao_demo/mapper/RecommendationMapper.java

@ -22,4 +22,6 @@ public interface RecommendationMapper extends BaseMapper<Recommendation> {
void updateRecommendation(Recommendation recommendation); void updateRecommendation(Recommendation recommendation);
void addLike(Recommendation recommendation); void addLike(Recommendation recommendation);
void isLikedById(Integer id);
} }

4
src/main/java/org/hlrj/duobao_demo/mapper/SpecialTopicMapper.java

@ -13,5 +13,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
*/ */
public interface SpecialTopicMapper extends BaseMapper<SpecialTopic> { public interface SpecialTopicMapper extends BaseMapper<SpecialTopic> {
public void addLike(SpecialTopic specialTopic);
void isLikedById(Integer id);
} }

1
src/main/java/org/hlrj/duobao_demo/mapper/VideoDataMapper.java

@ -13,4 +13,5 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
*/ */
public interface VideoDataMapper extends BaseMapper<VideoData> { public interface VideoDataMapper extends BaseMapper<VideoData> {
void isBookedById(Integer id);
} }

7
src/main/java/org/hlrj/duobao_demo/service/IRecommendationService.java

@ -42,9 +42,10 @@ public interface IRecommendationService extends IService<Recommendation> {
*/ */
public void updateRecommendation(Recommendation recommendation); public void updateRecommendation(Recommendation recommendation);
/** /**
* 增加点赞操作
* @param recommendation
* 进行点赞操作
* @param id
*/ */
public void addLike(Recommendation recommendation);
public void isLiked(Integer id);
} }

5
src/main/java/org/hlrj/duobao_demo/service/ISpecialTopicService.java

@ -33,9 +33,10 @@ public interface ISpecialTopicService extends IService<SpecialTopic> {
*/ */
public SpecialTopic selectById(Integer id); public SpecialTopic selectById(Integer id);
/** /**
* 点赞设置 * 点赞设置
* @param specialTopic
* @param id
*/ */
public void addLike(SpecialTopic specialTopic);
public void isLikedById(Integer id);
} }

6
src/main/java/org/hlrj/duobao_demo/service/IVideoDataService.java

@ -25,4 +25,10 @@ public interface IVideoDataService extends IService<VideoData> {
* @param id * @param id
*/ */
public void delete(Integer id); public void delete(Integer id);
/**
* 根据id进行预订
* @param id
*/
public void isBooked(Integer id);
} }

6
src/main/java/org/hlrj/duobao_demo/service/impl/RecommendationServiceImpl.java

@ -51,9 +51,11 @@ public class RecommendationServiceImpl extends ServiceImpl<RecommendationMapper,
} }
@Override @Override
public void addLike(Recommendation recommendation) {
recommendationMapper.addLike(recommendation);
public void isLiked(Integer id) {
recommendationMapper.isLikedById(id);
} }
} }

6
src/main/java/org/hlrj/duobao_demo/service/impl/SpecialTopicServiceImpl.java

@ -40,7 +40,9 @@ public class SpecialTopicServiceImpl extends ServiceImpl<SpecialTopicMapper, Spe
} }
@Override @Override
public void addLike(SpecialTopic specialTopic) {
specialTopicMapper.addLike(specialTopic);
public void isLikedById(Integer id) {
specialTopicMapper.isLikedById(id);
} }
} }

5
src/main/java/org/hlrj/duobao_demo/service/impl/VideoDataServiceImpl.java

@ -34,4 +34,9 @@ public class VideoDataServiceImpl extends ServiceImpl<VideoDataMapper, VideoData
public void delete(Integer id) { public void delete(Integer id) {
videoDataMapper.deleteById(id); videoDataMapper.deleteById(id);
} }
@Override
public void isBooked(Integer id) {
videoDataMapper.isBookedById(id);
}
} }

83
src/main/resources/mapper/RecommendationMapper.xml

@ -14,41 +14,42 @@
<result column="shares" property="shares" /> <result column="shares" property="shares" />
<result column="source" property="source" /> <result column="source" property="source" />
<result column="head" property="head"/> <result column="head" property="head"/>
<result column="is_liked" property="isLiked"/>
</resultMap> </resultMap>
<!--点赞操作-->
<update id="addLike" parameterType="org.hlrj.duobao_demo.entity.Recommendation">
update Recommendation
<set>
<if test="imageUrl !=null and imageUrl!=''">
image_url=#{imageUrl},
</if>
<if test="title !=null and title!=''">
title=#{title},
</if>
<if test="author !=null and author!=''">
author=#{author},
</if>
<if test="publishTime !=null">
publish_time=#{publishTime},
</if>
<if test="comments !=null and comments!=''">
comments=#{comments},
</if>
<if test="shares !=null">
shares=#{shares},
</if>
<if test="source !=null">
source=#{source},
</if>
<if test="head !=null and head!=''">
head=#{head},
</if>
likes = likes + 1
</set>
where id = #{id}
<!-- &lt;!&ndash;点赞操作&ndash;&gt;-->
<!-- <update id="addLike" parameterType="org.hlrj.duobao_demo.entity.Recommendation">-->
<!-- update Recommendation-->
<!-- <set>-->
<!-- <if test="imageUrl !=null and imageUrl!=''">-->
<!-- image_url=#{imageUrl},-->
<!-- </if>-->
<!-- <if test="title !=null and title!=''">-->
<!-- title=#{title},-->
<!-- </if>-->
<!-- <if test="author !=null and author!=''">-->
<!-- author=#{author},-->
<!-- </if>-->
<!-- <if test="publishTime !=null">-->
<!-- publish_time=#{publishTime},-->
<!-- </if>-->
<!-- <if test="comments !=null and comments!=''">-->
<!-- comments=#{comments},-->
<!-- </if>-->
<!-- <if test="shares !=null">-->
<!-- shares=#{shares},-->
<!-- </if>-->
<!-- <if test="source !=null">-->
<!-- source=#{source},-->
<!-- </if>-->
<!-- <if test="head !=null and head!=''">-->
<!-- head=#{head},-->
<!-- </if>-->
<!-- likes = likes + 1-->
<!-- </set>-->
<!-- where id = #{id}-->
</update>
<!-- </update>-->
<!--更新操作--> <!--更新操作-->
<update id="updateRecommendation" parameterType="org.hlrj.duobao_demo.entity.Recommendation"> <update id="updateRecommendation" parameterType="org.hlrj.duobao_demo.entity.Recommendation">
update Recommendation update Recommendation
@ -78,7 +79,10 @@
source=#{source}, source=#{source},
</if> </if>
<if test="head !=null and head!=''"> <if test="head !=null and head!=''">
head=#{head}
head=#{head},
</if>
<if test="isLiked !=null and isLiked!=''">
isLiked=#{isLiked}
</if> </if>
@ -86,5 +90,18 @@
where id = #{id} where id = #{id}
</update> </update>
<update id="isLikedById" parameterType="java.lang.Integer">
UPDATE Recommendation
SET
is_liked = CASE
WHEN is_liked = 0 THEN 1
ELSE 0
END,
likes = CASE
WHEN is_liked = 0 THEN likes + 1
ELSE likes - 1
END
WHERE id = #{id}
</update>
</mapper> </mapper>

82
src/main/resources/mapper/SpecialTopicMapper.xml

@ -15,41 +15,55 @@
<result column="like_count" property="likeCount" /> <result column="like_count" property="likeCount" />
<result column="club" property="club"/> <result column="club" property="club"/>
</resultMap> </resultMap>
<!--点赞操作-->
<update id="addLike" parameterType="org.hlrj.duobao_demo.entity.SpecialTopic">
update Special_topic
<set>
<if test="mainTitle !=null and mainTitle!=''">
main_title=#{mainTitle},
</if>
<if test="sectionTitle !=null and sectionTitle!=''">
section_title=#{sectionTitle},
</if>
<if test="coverImg !=null and coverImg!=''">
cover_img=#{coverImg},
</if>
<if test="author !=null and author!=''">
author=#{author},
</if>
<if test="publishTime !=null and publishTime!=''">
publish_time=#{publishTime},
</if>
<if test="viewCount !=null">
view_count=#{viewCount},
</if>
<if test="commentCount !=null">
commentCount=#{commentCount},
</if>
<if test="club !=null and club!=''">
club=#{club},
</if>
<if test="head !=null and head!=''">
head=#{head},
</if>
like_count = like_count + 1
</set>
where id = #{id}
<update id="isLikedById" parameterType="java.lang.Integer">
UPDATE Special_topic
SET
is_liked = CASE
WHEN is_liked = 0 THEN 1
ELSE 0
END,
likes = CASE
WHEN is_liked = 0 THEN likes + 1
ELSE likes - 1
END
WHERE id = #{id}
</update> </update>
<!-- &lt;!&ndash;点赞操作&ndash;&gt;-->
<!-- <update id="addLike" parameterType="org.hlrj.duobao_demo.entity.SpecialTopic">-->
<!-- update Special_topic-->
<!-- <set>-->
<!-- <if test="mainTitle !=null and mainTitle!=''">-->
<!-- main_title=#{mainTitle},-->
<!-- </if>-->
<!-- <if test="sectionTitle !=null and sectionTitle!=''">-->
<!-- section_title=#{sectionTitle},-->
<!-- </if>-->
<!-- <if test="coverImg !=null and coverImg!=''">-->
<!-- cover_img=#{coverImg},-->
<!-- </if>-->
<!-- <if test="author !=null and author!=''">-->
<!-- author=#{author},-->
<!-- </if>-->
<!-- <if test="publishTime !=null and publishTime!=''">-->
<!-- publish_time=#{publishTime},-->
<!-- </if>-->
<!-- <if test="viewCount !=null">-->
<!-- view_count=#{viewCount},-->
<!-- </if>-->
<!-- <if test="commentCount !=null">-->
<!-- commentCount=#{commentCount},-->
<!-- </if>-->
<!-- <if test="club !=null and club!=''">-->
<!-- club=#{club},-->
<!-- </if>-->
<!-- <if test="head !=null and head!=''">-->
<!-- head=#{head},-->
<!-- </if>-->
<!-- like_count = like_count + 1-->
<!-- </set>-->
<!-- where id = #{id}-->
<!-- </update>-->
</mapper> </mapper>

9
src/main/resources/mapper/VideoDateMapper.xml

@ -12,6 +12,15 @@
<result column="publish_time" property="publishTime" /> <result column="publish_time" property="publishTime" />
<result column="description" property="description" /> <result column="description" property="description" />
<result column="head" property="head"/> <result column="head" property="head"/>
<result column="is_booked" property="isBooked"/>
</resultMap> </resultMap>
<update id="isBookedById" parameterType="java.lang.Integer">
UPDATE Video_data
SET is_booked = CASE
WHEN is_booked = 0 THEN 1
ELSE 0
END
WHERE id = #{id}
</update>
</mapper> </mapper>
Loading…
Cancel
Save