release- 听歌埋点

release-2024-08-08
pikaqiudeshujia 5 months ago
parent f7231f8f8d
commit ed43cc3bb7

@ -0,0 +1,27 @@
package com.luoo.comment.config;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class RabbitMQConfig {
@Bean
public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
RabbitTemplate template = new RabbitTemplate(connectionFactory);
template.setMessageConverter(new Jackson2JsonMessageConverter());
return template;
}
@Bean
public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(ConnectionFactory connectionFactory) {
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
factory.setConnectionFactory(connectionFactory);
factory.setMessageConverter(new Jackson2JsonMessageConverter());
return factory;
}
}

@ -0,0 +1,15 @@
package com.luoo.comment.dao;
import com.luoo.comment.pojo.MusicPoint;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
* @Author: yawei.huang
* @Package: com.luoo.comment.dao
* @Project: luoo_parent
* @Date: 2024/7/3 9:26
* @Filename: MusicPointDao
* @Describe:
*/
public interface MusicPointDao extends MongoRepository<MusicPoint, String> {
}

@ -0,0 +1,38 @@
package com.luoo.comment.listener;
import com.luoo.comment.pojo.MusicPoint;
import com.luoo.comment.service.MusicPointService;
import dto.MusicPointDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @Author: yawei.huang
* @Package: com.luoo.comment.listener
* @Project: luoo_parent
* @Date: 2024/7/3 9:32
* @Filename: MusicPointListener
* @Describe:
*/
@Component
@Slf4j
@RabbitListener(queues = "musicPoint")
public class MusicPointListener {
@Autowired
private MusicPointService musicPointService;
@RabbitHandler
public void receive(MusicPointDto message) {
log.info("message:{}", message);
MusicPoint musicPoint = new MusicPoint();
BeanUtils.copyProperties(message, musicPoint);
musicPointService.save(musicPoint);
}
}

@ -0,0 +1,70 @@
package com.luoo.comment.pojo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.util.Date;
/**
* @Author: yawei.huang
* @Package: com.luoo.comment.pojo
* @Project: luoo_parent
* @Date: 2024/7/3 9:14
* @Filename: musicPoint
* @Describe: ---/--
*/
@Data
public class MusicPoint implements Serializable {
@ApiModelProperty(value = "id")
private String _id;
@ApiModelProperty(value = "用户id")
private String userId;
@ApiModelProperty(value = "用户昵称")
private String userName;
@ApiModelProperty(value = "歌曲id")
private String songId;
@ApiModelProperty(value = "歌曲名称")
private String songName;
@ApiModelProperty(value = "期刊id")
private String journalId;
@ApiModelProperty(value = "期刊封面")
private String journalImage;
@ApiModelProperty(value = "专辑id")
private String albumId;
@ApiModelProperty(value = "专辑名称")
private String albumName;
@ApiModelProperty(value = "音乐人id")
private String artistId;
@ApiModelProperty(value = "音乐人名称")
private String artistName;
@ApiModelProperty(value = "厂牌id")
private String bandId;
@ApiModelProperty(value = "厂牌名称")
private String bandName;
@ApiModelProperty(value = "发生时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date eventTime;
@ApiModelProperty(value = "节点")
private String node;
}

@ -0,0 +1,28 @@
package com.luoo.comment.service;
import com.luoo.comment.dao.MusicPointDao;
import com.luoo.comment.pojo.MusicPoint;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
/**
* @Author: yawei.huang
* @Package: com.luoo.comment.service
* @Project: luoo_parent
* @Date: 2024/7/3 9:30
* @Filename: MusicPointService
* @Describe:
*/
@Service
public class MusicPointService {
@Resource
private MusicPointDao musicPointDao;
@Transactional(rollbackFor = Exception.class)
public void save(MusicPoint musicPoint) {
musicPointDao.save(musicPoint);
}
}

@ -0,0 +1,72 @@
package dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.util.Date;
/**
* @Author: yawei.huang
* @Package: com.luoo.comment.pojo
* @Project: luoo_parent
* @Date: 2024/7/3 9:14
* @Filename: musicPoint
* @Describe: ---/--
*/
@Data
public class MusicPointDto implements Serializable {
@ApiModelProperty(value = "id")
private String _id;
@ApiModelProperty(value = "用户id")
private String userId;
@ApiModelProperty(value = "用户昵称")
private String userName;
@ApiModelProperty(value = "歌曲id")
@NotBlank
private String songId;
@ApiModelProperty(value = "歌曲名称")
private String songName;
@ApiModelProperty(value = "期刊id")
private String journalId;
@ApiModelProperty(value = "期刊封面")
private String journalImage;
@ApiModelProperty(value = "专辑id")
private String albumId;
@ApiModelProperty(value = "专辑名称")
private String albumName;
@ApiModelProperty(value = "音乐人id")
private String artistId;
@ApiModelProperty(value = "音乐人名称")
private String artistName;
@ApiModelProperty(value = "厂牌id")
private String bandId;
@ApiModelProperty(value = "厂牌名称")
private String bandName;
@ApiModelProperty(value = "发生时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date eventTime;
@ApiModelProperty(value = "节点")
private String node;
}

@ -53,6 +53,6 @@ public interface UserClient {
* @param userId id * @param userId id
* @return * @return
*/ */
@GetMapping("/my/info/real/{userId}") @GetMapping("/my/info/real/name/{userId}")
Boolean getRealNameInfo(@PathVariable String userId); Boolean getRealNameInfo(@PathVariable String userId);
} }

@ -1,37 +1,34 @@
package com.luoo.music.controller; package com.luoo.music.controller;
import annotation.GlobalInterceptor;
import annotation.VerifyParam;
import api.PageResult;
import api.Result;
import api.StatusCode;
import com.luoo.music.dto.mapper.SongMapper; import com.luoo.music.dto.mapper.SongMapper;
import com.luoo.music.dto.request.CollectQueryReq; import com.luoo.music.dto.request.CollectQueryReq;
import com.luoo.music.dto.request.FuzzySearchReq;
import com.luoo.music.dto.request.RandomTopicReq; import com.luoo.music.dto.request.RandomTopicReq;
import com.luoo.music.dto.response.RandomTopicDTO; import com.luoo.music.dto.response.RandomTopicDTO;
import com.luoo.music.dto.response.SongRespDTO; import com.luoo.music.dto.response.SongRespDTO;
import com.luoo.music.pojo.JournalSong; import com.luoo.music.pojo.JournalSong;
import com.luoo.music.service.JournalService; import com.luoo.music.service.JournalService;
import com.luoo.music.service.JournalSongService; import com.luoo.music.service.JournalSongService;
import com.luoo.music.service.SongService;
import com.luoo.music.service.UserCollectInfoService; import com.luoo.music.service.UserCollectInfoService;
import com.luoo.music.util.DeviceTypeUtil; import com.luoo.music.util.DeviceTypeUtil;
import annotation.GlobalInterceptor;
import annotation.VerifyParam;
import api.PageResult;
import api.Result;
import api.StatusCode;
import constants.Constants; import constants.Constants;
import dto.MusicPointDto;
import dto.UserLoginDto; import dto.UserLoginDto;
import enums.CollectTypeEnum; import enums.CollectTypeEnum;
import enums.VerifyRegexEnum; import enums.VerifyRegexEnum;
import io.swagger.annotations.Api; import io.swagger.annotations.*;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import util.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import util.JwtUtil;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -52,6 +49,8 @@ public class SongController {
private RedisTemplate redisTemplate; private RedisTemplate redisTemplate;
@Autowired @Autowired
private JwtUtil jwtUtil; private JwtUtil jwtUtil;
@Autowired
private SongService songService;
@ApiOperation(value = "1.根据期刊号查询歌曲信息", notes = "若为游客期刊号须在最新10期内") @ApiOperation(value = "1.根据期刊号查询歌曲信息", notes = "若为游客期刊号须在最新10期内")
@GetMapping("/getByJournalNo/{journalNo}") @GetMapping("/getByJournalNo/{journalNo}")
@ -211,4 +210,13 @@ public class SongController {
songRespDTO.setHaveCollect(isCollect); songRespDTO.setHaveCollect(isCollect);
return Result.success(songRespDTO); return Result.success(songRespDTO);
} }
@ApiOperation(value = "5.用户听歌埋点处理", notes = "用户听歌埋点处理")
@PostMapping("/musicPoint")
public Result<Void> musicPoint(@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token,
@RequestBody @Validated MusicPointDto musicPoint) {
songService.musicPoint(token, musicPoint);
return Result.success();
}
} }

@ -6,6 +6,8 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import java.util.List;
/** /**
* @Author: yawei.huang * @Author: yawei.huang
* @Package: com.luoo.music.dao * @Package: com.luoo.music.dao
@ -19,4 +21,6 @@ public interface ArtistAlbumSongDao extends JpaRepository<ArtistAlbumSong, Strin
@Modifying @Modifying
@Query(value = "delete from tb_artist_album_song where album_id = ?", nativeQuery = true) @Query(value = "delete from tb_artist_album_song where album_id = ?", nativeQuery = true)
void deleteByAlbumId(String albumId); void deleteByAlbumId(String albumId);
List<ArtistAlbumSong> findAllBySongId(String songId);
} }

@ -1,9 +1,12 @@
package com.luoo.music.service; package com.luoo.music.service;
import com.luoo.music.dao.SongDao; import com.luoo.music.dao.*;
import com.luoo.music.dto.response.SongRespDTO; import com.luoo.music.pojo.*;
import com.luoo.music.pojo.Song; import constants.ErrorConstants;
import dto.MusicPointDto;
import dto.UserLoginDto;
import exception.BizException;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
@ -12,12 +15,14 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import util.IdWorker; import util.IdWorker;
import util.JwtUtil;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root; import javax.persistence.criteria.Root;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -30,11 +35,28 @@ public class SongService {
@Autowired @Autowired
private IdWorker idWorker; private IdWorker idWorker;
@Autowired
private JwtUtil jwtUtil;
@Autowired
private JournalSongDao journalSongDao;
@Autowired
private SongInfoDao songInfoDao;
@Autowired
private ArtistAlbumSongDao artistAlbumSongDao;
@Autowired
private ArtistAlbumDao artistAlbumDao;
@Autowired
private RabbitTemplate rabbitTemplate;
/** /**
* *
*/ */
public List<Song> findAll(){ public List<Song> findAll() {
return songDao.findAll(); return songDao.findAll();
} }
@ -44,13 +66,14 @@ public class SongService {
public Page<Song> findSearch(Map whereMap, int page, int size) { public Page<Song> findSearch(Map whereMap, int page, int size) {
Specification<Song> specification = createSpecification(whereMap); Specification<Song> specification = createSpecification(whereMap);
PageRequest pageRequest = PageRequest.of(page-1, size); PageRequest pageRequest = PageRequest.of(page - 1, size);
return songDao.findAll(specification, pageRequest); return songDao.findAll(specification, pageRequest);
} }
/** /**
* *
*
* @param whereMap * @param whereMap
* @return * @return
*/ */
@ -62,44 +85,49 @@ public class SongService {
/** /**
* ID * ID
*
* @param id * @param id
* @return * @return
*/ */
@Cacheable(value = "song",key = "#id") @Cacheable(value = "song", key = "#id")
public Song findById(String id) { public Song findById(String id) {
return songDao.findById(id).get(); return songDao.findById(id).get();
} }
/** /**
* *
*
* @param song * @param song
*/ */
public void add(Song song) { public void add(Song song) {
song.setId( idWorker.nextId()+"" ); song.setId(idWorker.nextId() + "");
songDao.save(song); songDao.save(song);
} }
/** /**
* *
*
* @param song * @param song
*/ */
@CacheEvict(value = "song",key = "#song.id") @CacheEvict(value = "song", key = "#song.id")
public void update(Song song) { public void update(Song song) {
songDao.save(song); songDao.save(song);
} }
/** /**
* *
*
* @param id * @param id
*/ */
@CacheEvict(value = "song",key = "#id") @CacheEvict(value = "song", key = "#id")
public void deleteById(String id) { public void deleteById(String id) {
songDao.deleteById(id); songDao.deleteById(id);
} }
/** /**
* *
*
* @param searchMap * @param searchMap
* @return * @return
*/ */
@ -111,38 +139,39 @@ public class SongService {
public Predicate toPredicate(Root<Song> root, CriteriaQuery<?> query, CriteriaBuilder cb) { public Predicate toPredicate(Root<Song> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
List<Predicate> predicateList = new ArrayList<Predicate>(); List<Predicate> predicateList = new ArrayList<Predicate>();
// ID // ID
if (searchMap.get("id")!=null && !"".equals(searchMap.get("id"))) { if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) {
predicateList.add(cb.like(root.get("id").as(String.class), "%"+(String)searchMap.get("id")+"%")); predicateList.add(cb.like(root.get("id").as(String.class), "%" + (String) searchMap.get("id") + "%"));
} }
// 专栏ID // 专栏ID
if (searchMap.get("name")!=null && !"".equals(searchMap.get("name"))) { if (searchMap.get("name") != null && !"".equals(searchMap.get("name"))) {
predicateList.add(cb.like(root.get("name").as(String.class), "%"+(String)searchMap.get("name")+"%")); predicateList.add(cb.like(root.get("name").as(String.class), "%" + (String) searchMap.get("name") + "%"));
} }
// 用户ID // 用户ID
if (searchMap.get("artist")!=null && !"".equals(searchMap.get("artist"))) { if (searchMap.get("artist") != null && !"".equals(searchMap.get("artist"))) {
predicateList.add(cb.like(root.get("artist").as(String.class), "%"+(String)searchMap.get("artist")+"%")); predicateList.add(cb.like(root.get("artist").as(String.class), "%" + (String) searchMap.get("artist") + "%"));
} }
// 剘刊号 // 剘刊号
if (searchMap.get("volid")!=null && !"".equals(searchMap.get("volid"))) { if (searchMap.get("volid") != null && !"".equals(searchMap.get("volid"))) {
predicateList.add(cb.like(root.get("volid").as(String.class), "%"+(String)searchMap.get("volid")+"%")); predicateList.add(cb.like(root.get("volid").as(String.class), "%" + (String) searchMap.get("volid") + "%"));
} }
// 标题 // 标题
if (searchMap.get("album")!=null && !"".equals(searchMap.get("album"))) { if (searchMap.get("album") != null && !"".equals(searchMap.get("album"))) {
predicateList.add(cb.like(root.get("album").as(String.class), "%"+(String)searchMap.get("album")+"%")); predicateList.add(cb.like(root.get("album").as(String.class), "%" + (String) searchMap.get("album") + "%"));
} }
// 文章正文 // 文章正文
if (searchMap.get("url")!=null && !"".equals(searchMap.get("url"))) { if (searchMap.get("url") != null && !"".equals(searchMap.get("url"))) {
predicateList.add(cb.like(root.get("url").as(String.class), "%"+(String)searchMap.get("url")+"%")); predicateList.add(cb.like(root.get("url").as(String.class), "%" + (String) searchMap.get("url") + "%"));
} }
return cb.and( predicateList.toArray(new Predicate[predicateList.size()])); return cb.and(predicateList.toArray(new Predicate[predicateList.size()]));
} }
}; };
} }
public List<Song> findByVolid(String volid){
public List<Song> findByVolid(String volid) {
return songDao.findSongsByVolid(volid); return songDao.findSongsByVolid(volid);
} }
@ -153,4 +182,42 @@ public class SongService {
public List<Song> orderByField(List<String> objectIds) { public List<Song> orderByField(List<String> objectIds) {
return songDao.orderByField(objectIds); return songDao.orderByField(objectIds);
} }
/**
*
*
* @param token token
* @param musicPoint
*/
public void musicPoint(String token, MusicPointDto musicPoint) {
UserLoginDto user = jwtUtil.getUserLoginDto(token);
if (user != null) {
musicPoint.setUserId(user.getUserId());
} else {
// 用户校验失败,请重新登录
throw new BizException(ErrorConstants.USER_VERIFICATION_FAILURE);
}
musicPoint.set_id(idWorker.nextId() + "");
SongInfo songById = songInfoDao.getSongById(musicPoint.getSongId());
musicPoint.setSongName(songById.getName());
List<JournalSong> bySongId = journalSongDao.findBySongId(musicPoint.getSongId());
if (!bySongId.isEmpty()) {
musicPoint.setJournalId(bySongId.get(0).getJournalNoSongId());
musicPoint.setJournalImage(bySongId.get(0).getImage());
}
List<ArtistAlbumSong> artistAlbumSongList = artistAlbumSongDao.findAllBySongId(musicPoint.getSongId());
if (!artistAlbumSongList.isEmpty()) {
musicPoint.setAlbumId(artistAlbumSongList.get(0).getAlbumId());
ArtistAlbum artistAlbum = artistAlbumDao.findById(artistAlbumSongList.get(0).getAlbumId()).get();
musicPoint.setAlbumName(artistAlbum.getName());
musicPoint.setArtistId(artistAlbum.getArtistId());
musicPoint.setArtistName(artistAlbum.getArtistName());
}
musicPoint.setEventTime(new Date());
rabbitTemplate.convertAndSend("musicPoint",musicPoint);
}
} }

Loading…
Cancel
Save