Compare commits
11 Commits
a7a17667e4
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| c108742555 | |||
| dfccc03df8 | |||
| cf15298968 | |||
| 9f062492c4 | |||
| 4d20448b82 | |||
| b82dbacfee | |||
| a4020b9176 | |||
| ca86db8f66 | |||
| 417c2186c2 | |||
| 85d62459a6 | |||
| 704482ae0e |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -147,3 +147,4 @@ fabric.properties
|
||||
|
||||
!/.xcodemap/
|
||||
/tk-data-save.log
|
||||
/CLAUDE.md
|
||||
|
||||
2
pom.xml
2
pom.xml
@@ -88,7 +88,7 @@
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>r07</version>
|
||||
<version>30.1-jre</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
@@ -42,10 +42,10 @@ public class LogInterceptor {
|
||||
Object[] args = point.getArgs();
|
||||
String reqParam = "[" + StringUtils.join(args, ", ") + "]";
|
||||
// 输出请求日志
|
||||
// log.info("request start,id: {}, path: {}, ip: {}, params: {}", requestId, url,
|
||||
// httpServletRequest.getRemoteHost(), reqParam);
|
||||
log.info("request start,id: {}, path: {}, ip: {}", requestId, url,
|
||||
httpServletRequest.getRemoteHost());
|
||||
log.info("request start,id: {}, path: {}, ip: {}, params: {}", requestId, url,
|
||||
httpServletRequest.getRemoteHost(), reqParam);
|
||||
// log.info("request start,id: {}, path: {}, ip: {}", requestId, url,
|
||||
// httpServletRequest.getRemoteHost());
|
||||
// 执行原方法
|
||||
Object result = point.proceed();
|
||||
// 输出响应日志
|
||||
|
||||
@@ -5,9 +5,11 @@ import com.fasterxml.jackson.annotation.PropertyAccessor;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.rabbitmq.client.ConnectionFactory;
|
||||
import org.springframework.amqp.core.ExchangeBuilder;
|
||||
import org.springframework.amqp.core.HeadersExchange;
|
||||
import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
|
||||
import org.springframework.amqp.support.converter.MessageConverter;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -15,7 +17,17 @@ import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class RabbitMQConfig {
|
||||
|
||||
private static final String QUEUE = "HOST_INFO_QUEUE";
|
||||
private static final String LIVE_HOST_DETAIL_QUEUE = "LIVE_HOST_DETAIL";
|
||||
|
||||
public static final String EXCHANGE_NAME = "user.headers.exchange";
|
||||
|
||||
public static final String AI_CHAT_EXCHANGE_NAME = "ai.chat.headers.exchange";
|
||||
public static final String BIG_BROTHER_EXCHANGE_NAME = "big.brother.headers.exchange";
|
||||
public static final String WEB_AI_EXCHANGE_NAME = "web.ai.headers.exchange";
|
||||
|
||||
|
||||
|
||||
//创建队列
|
||||
//true:表示持久化
|
||||
@@ -26,12 +38,54 @@ public class RabbitMQConfig {
|
||||
return new Queue(QUEUE,true);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Queue liveHostDetailQueue(){
|
||||
return new Queue(LIVE_HOST_DETAIL_QUEUE,true);
|
||||
}
|
||||
|
||||
//
|
||||
// @Bean
|
||||
// public MessageConverter messageConverter(){
|
||||
// return new Jackson2JsonMessageConverter();
|
||||
// }
|
||||
|
||||
|
||||
|
||||
@Bean
|
||||
public HeadersExchange userHeadersExchange() {
|
||||
return ExchangeBuilder.headersExchange(EXCHANGE_NAME)
|
||||
.durable(true)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public HeadersExchange aiChatHeadersExchange() {
|
||||
return ExchangeBuilder.headersExchange(AI_CHAT_EXCHANGE_NAME)
|
||||
.durable(true)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public HeadersExchange bigBrotherHeadersExchange() {
|
||||
return ExchangeBuilder.headersExchange(BIG_BROTHER_EXCHANGE_NAME)
|
||||
.durable(true)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public HeadersExchange webAiHeadersExchange() {
|
||||
return ExchangeBuilder.headersExchange(WEB_AI_EXCHANGE_NAME)
|
||||
.durable(true)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public RabbitAdmin rabbitAdmin(ConnectionFactory cf) {
|
||||
return new RabbitAdmin(cf);
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public MessageConverter messageConverter() {
|
||||
ObjectMapper om = new ObjectMapper();
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
@@ -13,25 +14,24 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
public class RedisConfig {
|
||||
|
||||
|
||||
@Bean(name="redisTemplate")
|
||||
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {
|
||||
RedisTemplate<String, String> template = new RedisTemplate<>();
|
||||
RedisSerializer<String> redisSerializer = new StringRedisSerializer();
|
||||
@Bean
|
||||
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
|
||||
RedisTemplate<String, Object> template = new RedisTemplate<>();
|
||||
template.setConnectionFactory(factory);
|
||||
//key序列化方式
|
||||
template.setKeySerializer(redisSerializer);
|
||||
//value序列化
|
||||
template.setValueSerializer(redisSerializer);
|
||||
//value hashmap序列化
|
||||
template.setHashValueSerializer(redisSerializer);
|
||||
//key haspmap序列化
|
||||
template.setHashKeySerializer(redisSerializer);
|
||||
//
|
||||
|
||||
// 使用 JSON 序列化器
|
||||
GenericJackson2JsonRedisSerializer jsonSerializer = new GenericJackson2JsonRedisSerializer();
|
||||
|
||||
template.setKeySerializer(new StringRedisSerializer());
|
||||
template.setValueSerializer(jsonSerializer);
|
||||
template.setHashKeySerializer(new StringRedisSerializer());
|
||||
template.setHashValueSerializer(jsonSerializer);
|
||||
|
||||
template.afterPropertiesSet();
|
||||
return template;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/*
|
||||
* @author: ziin
|
||||
|
||||
@@ -2,15 +2,13 @@ package com.yupi.springbootinit.controller;
|
||||
|
||||
import com.yupi.springbootinit.common.BaseResponse;
|
||||
import com.yupi.springbootinit.common.ResultUtils;
|
||||
import com.yupi.springbootinit.model.dto.host.HostInfoDTO;
|
||||
import com.yupi.springbootinit.model.dto.host.QueryCountDTO;
|
||||
import com.yupi.springbootinit.model.entity.NewHosts;
|
||||
import com.yupi.springbootinit.model.entity.ServerLiveHostDetail;
|
||||
import com.yupi.springbootinit.model.vo.country.CountryInfoVO;
|
||||
import com.yupi.springbootinit.model.vo.hosts.NewHostsVO;
|
||||
import com.yupi.springbootinit.rabbitMQ.MQSender;
|
||||
import com.yupi.springbootinit.service.HostInfoService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -39,6 +37,12 @@ public class HostInfoController {
|
||||
return ResultUtils.success(true);
|
||||
}
|
||||
|
||||
@PostMapping("add_live_host_detail")
|
||||
public BaseResponse<Boolean> addLiveHostDetail(@RequestBody List<ServerLiveHostDetail> liveHostDetails){
|
||||
mqSender.liveHostDetailSend(liveHostDetails);
|
||||
return ResultUtils.success(true);
|
||||
}
|
||||
|
||||
@GetMapping("country_info")
|
||||
public BaseResponse<List<String>> getCountryInfo(@RequestParam(name = "countryName") String countryName){
|
||||
List<CountryInfoVO> countryInfo = hostInfoService.getCountryInfo(countryName);
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.yupi.springbootinit.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.yupi.springbootinit.model.entity.ServerLiveHostDetail;
|
||||
|
||||
/*
|
||||
* @author: ziin
|
||||
* @date: 2025/12/17 20:45
|
||||
*/
|
||||
|
||||
public interface ServerLiveHostDetailMapper extends BaseMapper<ServerLiveHostDetail> {
|
||||
}
|
||||
@@ -75,6 +75,9 @@ public class NewHosts {
|
||||
@ApiModelProperty(value = "主播国家", example = "中国")
|
||||
private String country;
|
||||
|
||||
@ApiModelProperty(value = "主播国家英文", example = "China")
|
||||
private String countryEng;
|
||||
|
||||
/**
|
||||
* 直播类型 娱乐,游戏
|
||||
*/
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||
import io.swagger.models.auth.In;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
@@ -109,7 +110,11 @@ public class ServerBigBrother {
|
||||
private Long tenantId;
|
||||
|
||||
@TableField(value = "create_time")
|
||||
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@TableField(value = "fans_level")
|
||||
private Integer fansLevel;
|
||||
|
||||
@TableField(value = "secUid")
|
||||
private String secUid;
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
package com.yupi.springbootinit.model.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.util.Date;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
/*
|
||||
* @author: ziin
|
||||
* @date: 2025/12/17 20:45
|
||||
*/
|
||||
|
||||
/**
|
||||
* 主播单场直播明细表
|
||||
*/
|
||||
@Data
|
||||
@TableName(value = "server_live_host_detail")
|
||||
public class ServerLiveHostDetail {
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 当前用户标识
|
||||
*/
|
||||
@TableField(value = "user_id")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 主播名称
|
||||
*/
|
||||
@TableField(value = "hosts_id")
|
||||
private String hostsId;
|
||||
|
||||
/**
|
||||
* 粉丝团人数
|
||||
*/
|
||||
@TableField(value = "fans_club_count")
|
||||
private Integer fansClubCount;
|
||||
|
||||
/**
|
||||
* 礼物之比
|
||||
*/
|
||||
@TableField(value = "lighted_vs_total_gifts")
|
||||
private String lightedVsTotalGifts;
|
||||
|
||||
/**
|
||||
* 直播开始时间(格式化)
|
||||
*/
|
||||
@TableField(value = "start_time_formatted")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date startTimeFormatted;
|
||||
|
||||
/**
|
||||
* 直播结束时间(格式化)
|
||||
*/
|
||||
@TableField(value = "end_time_formatted")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date endTimeFormatted;
|
||||
|
||||
/**
|
||||
* 获得的点赞数量
|
||||
*/
|
||||
@TableField(value = "like_count")
|
||||
private Integer likeCount;
|
||||
|
||||
/**
|
||||
* 持续时间(格式化)
|
||||
*/
|
||||
@TableField(value = "duration_formatted")
|
||||
private String durationFormatted;
|
||||
|
||||
/**
|
||||
* 记录创建时间
|
||||
*/
|
||||
@TableField(value = "create_time")
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 记录更新时间
|
||||
*/
|
||||
@TableField(value = "update_time")
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 租户 Id
|
||||
*/
|
||||
@TableField(value = "tenant_id")
|
||||
private Long tenantId;
|
||||
|
||||
/**
|
||||
* 是否删除
|
||||
*/
|
||||
@TableField(value = "deleted")
|
||||
private Byte deleted;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
@TableField(value = "updater")
|
||||
private String updater;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
@TableField(value = "creator")
|
||||
private String creator;
|
||||
}
|
||||
@@ -7,8 +7,10 @@ import com.yupi.springbootinit.common.ErrorCode;
|
||||
import com.yupi.springbootinit.exception.BusinessException;
|
||||
import com.yupi.springbootinit.model.entity.NewHosts;
|
||||
import com.yupi.springbootinit.model.entity.ServerBigBrother;
|
||||
import com.yupi.springbootinit.model.entity.ServerLiveHostDetail;
|
||||
import com.yupi.springbootinit.service.HostInfoService;
|
||||
import com.yupi.springbootinit.service.ServerBigBrotherService;
|
||||
import com.yupi.springbootinit.service.ServerLiveHostDetailService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
@@ -29,6 +31,9 @@ public class MQReceiver {
|
||||
@Resource
|
||||
private ServerBigBrotherService serverBigBrotherService;
|
||||
|
||||
@Resource
|
||||
private ServerLiveHostDetailService serverLiveHostDetailService;
|
||||
|
||||
|
||||
// //方法:接收消息
|
||||
// @RabbitListener(queues = "HOST_INFO_QUEUE")
|
||||
@@ -62,7 +67,7 @@ public class MQReceiver {
|
||||
}
|
||||
}
|
||||
|
||||
@RabbitListener(queues = "BIG_BROTHER_QUEUE",id = "bigbrother", autoStartup = "false")
|
||||
@RabbitListener(queues = "BIG_BROTHER_QUEUE",id = "bigbrother", autoStartup = "true")
|
||||
@Async("taskExecutor")
|
||||
public void bigBrotherReceive(ServerBigBrother bigBrotherList, Channel channel, Message message) throws IOException {
|
||||
long deliveryTag = message.getMessageProperties().getDeliveryTag();
|
||||
@@ -79,4 +84,18 @@ public class MQReceiver {
|
||||
throw new BusinessException(ErrorCode.QUEUE_CONSUMPTION_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
@RabbitListener(queues = "LIVE_HOST_DETAIL",id = "liveHostDetail", autoStartup = "true")
|
||||
@Async("taskExecutor")
|
||||
public void liveHostDetailReceive(List<ServerLiveHostDetail> details, Channel channel, Message message) throws IOException {
|
||||
long deliveryTag = message.getMessageProperties().getDeliveryTag();
|
||||
try {
|
||||
serverLiveHostDetailService.processLiveHostDetails(details);
|
||||
channel.basicAck(deliveryTag, false);
|
||||
} catch (Exception e) {
|
||||
channel.basicNack(deliveryTag, false, false);
|
||||
log.error("直播明细消息消费失败,数量: {}", details.size(), e);
|
||||
throw new BusinessException(ErrorCode.QUEUE_CONSUMPTION_FAILURE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,20 @@ package com.yupi.springbootinit.rabbitMQ;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import com.yupi.springbootinit.common.ErrorCode;
|
||||
import com.yupi.springbootinit.config.RabbitMQConfig;
|
||||
import com.yupi.springbootinit.exception.BusinessException;
|
||||
import com.yupi.springbootinit.model.entity.NewHosts;
|
||||
import com.yupi.springbootinit.model.entity.ServerBigBrother;
|
||||
import com.yupi.springbootinit.model.entity.ServerLiveHostDetail;
|
||||
import io.swagger.models.auth.In;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.core.HeadersExchange;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -16,7 +23,8 @@ import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class MQSender {
|
||||
|
||||
@Resource
|
||||
@@ -33,6 +41,16 @@ public class MQSender {
|
||||
throw new BusinessException(ErrorCode.QUEUE_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
//方法:发送直播明细消息
|
||||
public void liveHostDetailSend(List<ServerLiveHostDetail> list){
|
||||
try {
|
||||
rabbitTemplate.convertAndSend("LIVE_HOST_DETAIL",list);
|
||||
}catch (Exception e){
|
||||
throw new BusinessException(ErrorCode.QUEUE_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
//方法:发送消息
|
||||
public void bigBrotherSend(ServerBigBrother bigBrothers){
|
||||
try {
|
||||
@@ -45,4 +63,31 @@ public class MQSender {
|
||||
throw new BusinessException(ErrorCode.QUEUE_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void send(Long tenantId, Object payload) {
|
||||
// 发送消息,把 userId 放进 header
|
||||
rabbitTemplate.convertAndSend(RabbitMQConfig.AI_CHAT_EXCHANGE_NAME, "", payload, m -> {
|
||||
m.getMessageProperties().getHeaders().put("tenantId", tenantId);
|
||||
return m;
|
||||
});
|
||||
}
|
||||
|
||||
public void brotherSend(Long tenantId, Object payload) {
|
||||
// 发送消息,把 userId 放进 header
|
||||
rabbitTemplate.convertAndSend(RabbitMQConfig.BIG_BROTHER_EXCHANGE_NAME, "", payload, m -> {
|
||||
m.getMessageProperties().getHeaders().put("tenantId", tenantId);
|
||||
return m;
|
||||
});
|
||||
}
|
||||
|
||||
public void webAISend(Long tenantId, Object payload) {
|
||||
// 发送消息,把 userId 放进 header
|
||||
rabbitTemplate.convertAndSend(RabbitMQConfig.WEB_AI_EXCHANGE_NAME, "", payload, m -> {
|
||||
m.getMessageProperties().getHeaders().put("tenantId", tenantId);
|
||||
return m;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.yupi.springbootinit.service;
|
||||
|
||||
import com.yupi.springbootinit.model.entity.ServerLiveHostDetail;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/*
|
||||
* @author: ziin
|
||||
* @date: 2025/12/17 20:45
|
||||
*/
|
||||
|
||||
public interface ServerLiveHostDetailService extends IService<ServerLiveHostDetail>{
|
||||
|
||||
CompletableFuture<Void> processLiveHostDetails(List<ServerLiveHostDetail> details);
|
||||
|
||||
}
|
||||
@@ -1,28 +1,26 @@
|
||||
package com.yupi.springbootinit.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.yupi.springbootinit.mapper.CountryInfoMapper;
|
||||
import com.yupi.springbootinit.mapper.NewHostsMapper;
|
||||
import com.yupi.springbootinit.model.dto.host.QueryCountDTO;
|
||||
import com.yupi.springbootinit.model.entity.NewHosts;
|
||||
import com.yupi.springbootinit.model.vo.country.CountryInfoVO;
|
||||
import com.yupi.springbootinit.rabbitMQ.MQSender;
|
||||
import com.yupi.springbootinit.service.HostInfoService;
|
||||
import com.yupi.springbootinit.utils.JsonUtils;
|
||||
import com.yupi.springbootinit.utils.RedisUtils;
|
||||
import com.yupi.springbootinit.utils.SseEmitterUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StopWatch;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
|
||||
@@ -43,6 +41,13 @@ public class HostInfoServiceImpl extends ServiceImpl<NewHostsMapper, NewHosts> i
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
|
||||
@Resource
|
||||
private RedisUtils redisUtils;
|
||||
|
||||
@Resource
|
||||
private MQSender mqSender;
|
||||
|
||||
|
||||
//
|
||||
// private final RedisTemplate<String,Object> redisTemplate;
|
||||
//
|
||||
@@ -68,12 +73,31 @@ public class HostInfoServiceImpl extends ServiceImpl<NewHostsMapper, NewHosts> i
|
||||
JsonUtils.toJsonString(newHost));
|
||||
});
|
||||
}
|
||||
|
||||
// Boolean o = (Boolean) redisTemplate.opsForValue().get("ai_login:"+newHosts.get(0).getTenantId());
|
||||
if (redisUtils.hasKeyByPrefix("ai_login:"+ newHosts.get(0).getTenantId())) {
|
||||
newHosts.forEach(newHost -> {
|
||||
mqSender.send(newHost.getTenantId(),newHost);
|
||||
});
|
||||
|
||||
log.info("发送消息到队列{}, 消息数量: {}", newHosts.get(0).getTenantId(), newHosts.size());
|
||||
}
|
||||
|
||||
if (redisUtils.hasKeyByPrefix("webAI_login:"+ newHosts.get(0).getTenantId())) {
|
||||
newHosts.forEach(newHost -> {
|
||||
mqSender.webAISend(newHost.getTenantId(),newHost);
|
||||
});
|
||||
log.info("发送消息到队列WebAI{}, 消息数量: {}", newHosts.get(0).getTenantId(), newHosts.size());
|
||||
}
|
||||
|
||||
|
||||
stopWatch.stop();
|
||||
long totalTimeMillis = stopWatch.getTotalTimeMillis();
|
||||
log.info("当前存储数据量大小 {}, 存储花费: {}ms",newHosts.size(),totalTimeMillis);
|
||||
return CompletableFuture.completedFuture(null);
|
||||
} catch (Exception e) {
|
||||
// 将异常包装到Future,使调用方能处理
|
||||
log.error(e.getMessage());
|
||||
return CompletableFuture.failedFuture(e);
|
||||
}
|
||||
}
|
||||
@@ -124,7 +148,6 @@ public class HostInfoServiceImpl extends ServiceImpl<NewHostsMapper, NewHosts> i
|
||||
|
||||
@Override
|
||||
public void queryCount(QueryCountDTO queryCountDTO) {
|
||||
|
||||
redisTemplate.opsForValue().increment( "tkaccount:" + queryCountDTO.getTkAccount(),1);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.yupi.springbootinit.service.impl;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
||||
import com.yupi.springbootinit.rabbitMQ.MQSender;
|
||||
import com.yupi.springbootinit.utils.RedisUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -14,6 +16,8 @@ import com.yupi.springbootinit.model.entity.ServerBigBrother;
|
||||
import com.yupi.springbootinit.service.ServerBigBrotherService;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StopWatch;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
/*
|
||||
* @author: ziin
|
||||
* @date: 2025/6/24 16:19
|
||||
@@ -23,6 +27,12 @@ import org.springframework.util.StopWatch;
|
||||
@Slf4j
|
||||
public class ServerBigBrotherServiceImpl extends ServiceImpl<ServerBigBrotherMapper, ServerBigBrother> implements ServerBigBrotherService{
|
||||
|
||||
@Resource
|
||||
private RedisUtils redisUtils;
|
||||
|
||||
@Resource
|
||||
private MQSender mqSender;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveData(ServerBigBrother bigBrother) {
|
||||
@@ -34,6 +44,10 @@ public class ServerBigBrotherServiceImpl extends ServiceImpl<ServerBigBrotherMap
|
||||
ServerBigBrother serverBigBrother = baseMapper.selectOne(queryWrapper);
|
||||
if(serverBigBrother == null){
|
||||
save(bigBrother);
|
||||
if (redisUtils.hasKeyByPrefix("bigbrother_login:"+ bigBrother.getTenantId())) {
|
||||
mqSender.brotherSend(bigBrother.getTenantId(),bigBrother);
|
||||
log.info("发送消息到队列{}, 大哥 Id: {}", bigBrother.getTenantId(),bigBrother.getDisplayId());
|
||||
}
|
||||
stopWatch.stop();
|
||||
long totalTimeMillis = stopWatch.getTotalTimeMillis();
|
||||
log.info("当前存储花费: {}ms",totalTimeMillis);
|
||||
@@ -44,6 +58,10 @@ public class ServerBigBrotherServiceImpl extends ServiceImpl<ServerBigBrotherMap
|
||||
}
|
||||
bigBrother.setTotalGiftCoins(bigBrother.getHistoricHighCoins()+serverBigBrother.getTotalGiftCoins());
|
||||
updateById(bigBrother);
|
||||
if (redisUtils.hasKeyByPrefix("bigbrother_login:"+ bigBrother.getTenantId())) {
|
||||
mqSender.brotherSend(bigBrother.getTenantId(),bigBrother);
|
||||
log.info("发送消息到队列{}, 大哥 Id: {}", bigBrother.getTenantId(),bigBrother.getDisplayId());
|
||||
}
|
||||
stopWatch.stop();
|
||||
long totalTimeMillis = stopWatch.getTotalTimeMillis();
|
||||
log.info("当前更新花费: {}ms",totalTimeMillis);
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.yupi.springbootinit.service.impl;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.yupi.springbootinit.model.entity.ServerLiveHostDetail;
|
||||
import com.yupi.springbootinit.mapper.ServerLiveHostDetailMapper;
|
||||
import com.yupi.springbootinit.service.ServerLiveHostDetailService;
|
||||
/*
|
||||
* @author: ziin
|
||||
* @date: 2025/12/17 20:45
|
||||
*/
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class ServerLiveHostDetailServiceImpl extends ServiceImpl<ServerLiveHostDetailMapper, ServerLiveHostDetail> implements ServerLiveHostDetailService{
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> processLiveHostDetails(List<ServerLiveHostDetail> details) {
|
||||
try {
|
||||
saveBatch(details);
|
||||
log.info("直播明细数据存储成功,数量: {}", details.size());
|
||||
return CompletableFuture.completedFuture(null);
|
||||
} catch (Exception e) {
|
||||
log.error("直播明细数据存储失败", e);
|
||||
return CompletableFuture.failedFuture(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
38
src/main/java/com/yupi/springbootinit/utils/RedisUtils.java
Normal file
38
src/main/java/com/yupi/springbootinit/utils/RedisUtils.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package com.yupi.springbootinit.utils;
|
||||
|
||||
/*
|
||||
* @author: ziin
|
||||
* @date: 2025/8/27 20:35
|
||||
*/
|
||||
|
||||
import org.springframework.data.redis.core.Cursor;
|
||||
import org.springframework.data.redis.core.RedisCallback;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.ScanOptions;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
@Component
|
||||
public class RedisUtils {
|
||||
|
||||
|
||||
@Resource
|
||||
private RedisTemplate<String,Object> redisTemplate;
|
||||
|
||||
public boolean hasKeyByPrefix(String prefix) {
|
||||
return Boolean.TRUE.equals(
|
||||
redisTemplate.execute((RedisCallback<Boolean>) conn -> {
|
||||
try (Cursor<byte[]> cursor = conn.scan(
|
||||
ScanOptions.scanOptions()
|
||||
.match(prefix + ":*")
|
||||
.count(100) // 每次返回条数,可调整
|
||||
.build())) {
|
||||
return cursor.hasNext(); // 只要存在一条就返回 true
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,6 @@ import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* SQL 工具
|
||||
*
|
||||
* @author <a href="https://github.com/liyupi">程序员鱼皮</a>
|
||||
* @from <a href="https://yupi.icu">编程导航知识星球</a>
|
||||
*/
|
||||
public class SqlUtils {
|
||||
|
||||
|
||||
@@ -26,12 +26,13 @@
|
||||
<result column="uid" jdbcType="VARCHAR" property="uid" />
|
||||
<result column="ai_operation" jdbcType="TINYINT" property="aiOperation" />
|
||||
<result column="operation_status" jdbcType="TINYINT" property="operationStatus" />
|
||||
<result column="country_eng" jdbcType="VARCHAR" property="countryEng" />
|
||||
</resultMap>
|
||||
<sql id="Base_Column_List">
|
||||
<!--@mbg.generated-->
|
||||
id, hosts_id, hosts_level, hosts_coins, Invitation_type, online_fans, fans, fllowernum,
|
||||
yesterday_coins, country, hosts_kind, is_assigned, tenant_id, creator, create_time,
|
||||
updater, update_time, user_id, deleted, `uid`, ai_operation, operation_status
|
||||
updater, update_time, user_id, deleted, `uid`, ai_operation, operation_status,country_eng
|
||||
</sql>
|
||||
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
|
||||
<!--@mbg.generated-->
|
||||
@@ -50,12 +51,12 @@
|
||||
insert into server_new_hosts (hosts_id, hosts_level, hosts_coins,
|
||||
Invitation_type, online_fans,fans, fllowernum,
|
||||
yesterday_coins, country, hosts_kind,
|
||||
tenant_id, creator,create_time,uid
|
||||
tenant_id, creator,create_time,uid,country_eng
|
||||
)
|
||||
values (#{hostsId,jdbcType=VARCHAR}, #{hostsLevel,jdbcType=VARCHAR}, #{hostsCoins,jdbcType=INTEGER},
|
||||
#{invitationType,jdbcType=INTEGER}, #{onlineFans,jdbcType=INTEGER},#{fans,jdbcType=INTEGER}, #{fllowernum,jdbcType=INTEGER},
|
||||
#{yesterdayCoins,jdbcType=INTEGER}, #{country,jdbcType=VARCHAR}, #{hostsKind,jdbcType=VARCHAR},
|
||||
#{tenantId,jdbcType=BIGINT}, #{creator,jdbcType=BIGINT},#{createTime,jdbcType=TIMESTAMP},#{uid,jdbcType=VARCHAR})
|
||||
#{tenantId,jdbcType=BIGINT}, #{creator,jdbcType=BIGINT},#{createTime,jdbcType=TIMESTAMP},#{uid,jdbcType=VARCHAR},#{countryEng,jdbcType=VARCHAR})
|
||||
</insert>
|
||||
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.yupi.springbootinit.model.entity.NewHosts" useGeneratedKeys="true">
|
||||
<!--@mbg.generated-->
|
||||
@@ -201,14 +202,14 @@
|
||||
<!--@mbg.generated-->
|
||||
insert into server_new_hosts
|
||||
(hosts_id, hosts_level, hosts_coins, Invitation_type, online_fans,fans, fllowernum, yesterday_coins,
|
||||
country, hosts_kind, tenant_id, creator, user_id,create_time,uid)
|
||||
country, hosts_kind, tenant_id, creator, user_id,create_time,uid,country_eng)
|
||||
values
|
||||
<foreach collection="list" item="item" separator=",">
|
||||
(#{item.hostsId,jdbcType=VARCHAR}, #{item.hostsLevel,jdbcType=VARCHAR}, #{item.hostsCoins,jdbcType=INTEGER},
|
||||
#{item.invitationType,jdbcType=INTEGER}, #{item.onlineFans,jdbcType=INTEGER},#{item.fans,jdbcType=INTEGER},
|
||||
#{item.fllowernum,jdbcType=INTEGER}, #{item.yesterdayCoins,jdbcType=INTEGER}, #{item.country,jdbcType=VARCHAR},
|
||||
#{item.hostsKind,jdbcType=VARCHAR}, #{item.tenantId,jdbcType=BIGINT}, #{item.creator,jdbcType=INTEGER},#{item.userId,jdbcType=BIGINT},
|
||||
#{item.createTime,jdbcType=TIMESTAMP},#{item.uid,jdbcType=VARCHAR})
|
||||
#{item.createTime,jdbcType=TIMESTAMP},#{item.uid,jdbcType=VARCHAR},#{item.countryEng,jdbcType=VARCHAR})
|
||||
</foreach>
|
||||
</insert>
|
||||
</mapper>
|
||||
@@ -19,11 +19,13 @@
|
||||
<result column="owner_id" jdbcType="VARCHAR" property="ownerId" />
|
||||
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
|
||||
<result column="tenant_id" jdbcType="BIGINT" property="tenantId" />
|
||||
<result column="fans_level" jdbcType="INTEGER" property="fansLevel" />
|
||||
<result column="secUid" jdbcType="VARCHAR" property="secUid" />
|
||||
</resultMap>
|
||||
<sql id="Base_Column_List">
|
||||
<!--@mbg.generated-->
|
||||
id, display_id, user_id_str, nickname, `level`, hostcoins, follower_count, following_count,
|
||||
region, historic_high_coins, total_gift_coins, host_display_id, owner_id, create_time,
|
||||
update_time, creator, updater, deleted, tenant_id
|
||||
update_time, creator, updater, deleted, tenant_id,fans_level,secUid
|
||||
</sql>
|
||||
</mapper>
|
||||
29
src/main/resources/mapper/ServerLiveHostDetailMapper.xml
Normal file
29
src/main/resources/mapper/ServerLiveHostDetailMapper.xml
Normal file
@@ -0,0 +1,29 @@
|
||||
<?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.yupi.springbootinit.mapper.ServerLiveHostDetailMapper">
|
||||
<resultMap id="BaseResultMap" type="com.yupi.springbootinit.model.entity.ServerLiveHostDetail">
|
||||
<!--@mbg.generated-->
|
||||
<!--@Table server_live_host_detail-->
|
||||
<id column="id" jdbcType="BIGINT" property="id" />
|
||||
<result column="userId" jdbcType="BIGINT" property="userid" />
|
||||
<result column="hostsId" jdbcType="VARCHAR" property="hostsid" />
|
||||
<result column="fans_club_count" jdbcType="INTEGER" property="fansClubCount" />
|
||||
<result column="lighted_vs_total_gifts" jdbcType="VARCHAR" property="lightedVsTotalGifts" />
|
||||
<result column="start_time_formatted" jdbcType="VARCHAR" property="startTimeFormatted" />
|
||||
<result column="end_time_formatted" jdbcType="VARCHAR" property="endTimeFormatted" />
|
||||
<result column="like_count" jdbcType="INTEGER" property="likeCount" />
|
||||
<result column="duration_formatted" jdbcType="VARCHAR" property="durationFormatted" />
|
||||
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
|
||||
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
|
||||
<result column="tenant_id" jdbcType="BIGINT" property="tenantId" />
|
||||
<result column="deleted" jdbcType="TINYINT" property="deleted" />
|
||||
<result column="updater" jdbcType="VARCHAR" property="updater" />
|
||||
<result column="creator" jdbcType="VARCHAR" property="creator" />
|
||||
</resultMap>
|
||||
<sql id="Base_Column_List">
|
||||
<!--@mbg.generated-->
|
||||
id, userId, hostsId, fans_club_count, lighted_vs_total_gifts, start_time_formatted,
|
||||
end_time_formatted, like_count, duration_formatted, create_time, update_time, tenant_id,
|
||||
deleted, updater, creator
|
||||
</sql>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user