Commit 3b1d74e2 authored by liming's avatar liming

点赞接口

parent 918dabed
......@@ -16,4 +16,8 @@
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
</dependencies>
</project>
\ No newline at end of file
package com.antai.sport.http.server.constants;
public class GameMode {
//漫游
public final static Integer TOUR = 10;
//日常赛
public final static Integer NORMAL_MATCH = 20;
//系列赛
public final static Integer SERIES_MATCH = 30;
//训练模式
public final static Integer COURSE_TRAINING = 40;
//团练
public final static Integer GROUP_TRAINING = 50;
}
......@@ -53,6 +53,11 @@ public class SportUserSummary implements Serializable {
*/
private Integer totalDuration;
/**
* 总点赞数
*/
private Integer totalPraiseNum;
/**
* 版本号
*/
......
......@@ -13,6 +13,7 @@ public interface PraiseConverter {
@Mappings({
@Mapping(source = "source.from", target = "fromId"),
@Mapping(source = "source.to", target = "toId"),
@Mapping(source = "source.gameMode",target = "type"),
@Mapping(source = "createTime",target = "createTime")
})
PraiseLog reqPraiseToPraiseLog(ReqPraise source, LocalDateTime createTime);
......
......@@ -7,12 +7,14 @@ import lombok.Data;
@Data
@ApiModel("点赞请求")
public class ReqPraise {
@ApiModelProperty("点赞类型 10:漫游 20:日常赛 30:系列赛 40:训练模式 50: 团练")
private Integer type;
@ApiModelProperty("点赞类型 10:漫游 20:日常赛 30:系列赛 40:课程训练 50: 团练")
private Integer gameMode;
@ApiModelProperty("源头数据id 比如漫游记录id 比赛赛事id 团练活动id等")
private Long sourceId;
@ApiModelProperty("点赞人")
private Long from;
@ApiModelProperty("被点赞人")
private Long to;
@ApiModelProperty("模式 1:骑行 2:跑步")
private Integer sportType;
}
......@@ -4,7 +4,11 @@ import com.antai.sport.http.server.repository.base.entity.PraiseLog;
import com.antai.sport.http.server.repository.base.mapper.PraiseLogMapper;
import com.antai.sport.http.server.server.api.business.praise.converter.PraiseConverter;
import com.antai.sport.http.server.server.api.business.praise.dto.ReqPraise;
import com.antai.sport.http.server.server.api.business.user.service.SportUserSummaryService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.time.LocalDateTime;
......@@ -17,8 +21,35 @@ public class PraiseService {
@Resource
private PraiseConverter praiseConverter;
@Resource
private SportUserSummaryService sportUserSummaryService;
/**
* 点赞操作
*
* @param param
*/
@Transactional(isolation = Isolation.READ_COMMITTED)
public void praise(ReqPraise param) {
PraiseLog praiseLog = praiseConverter.reqPraiseToPraiseLog(param, LocalDateTime.now());
praiseLogMapper.insert(praiseLog);
//更新被点赞人总点赞记录
sportUserSummaryService.updatePraise(param.getTo(), param.getSportType());
}
/**
* 查询某次游戏全部点赞数
*
* @param gameMode
* @param sourceId
* @param userId
* @return
*/
public Integer getActivityTotalPraise(Integer gameMode, Long sourceId, Long userId) {
QueryWrapper<PraiseLog> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("type", gameMode);
queryWrapper.eq("source_id", sourceId);
queryWrapper.eq("to_id", userId);
return praiseLogMapper.selectCount(queryWrapper);
}
}
package com.antai.sport.http.server.server.api.business.user.mapper;
import org.apache.ibatis.annotations.Param;
public interface SportUserSummaryBusinessMapper {
int updateUserPraise(@Param("userId") Long userId, @Param("sportType") Integer sportType);
}
package com.antai.sport.http.server.server.api.business.user.service;
import com.antai.sport.http.server.server.api.business.user.mapper.SportUserSummaryBusinessMapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
public class SportUserSummaryService {
@Resource
private SportUserSummaryBusinessMapper sportUserSummaryBusinessMapper;
public void updatePraise(Long userId, Integer sportType) {
sportUserSummaryBusinessMapper.updateUserPraise(userId, sportType);
}
}
package com.antai.sport.http.server.server.api.config;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class MybatisPlusConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
mybatisPlusInterceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
return mybatisPlusInterceptor;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.antai.sport.http.server.server.api.business.user.mapper.SportUserSummaryBusinessMapper">
<update id="updateUserPraise">
update sport_user_summary
set total_praise_num = ifnull(total_praise_num, 0) + 1
where user_id = #{userId} and type = #{sportType}
</update>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment