Compare commits
7 Commits
417c2186c2
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| dfccc03df8 | |||
| cf15298968 | |||
| 9f062492c4 | |||
| 4d20448b82 | |||
| b82dbacfee | |||
| a4020b9176 | |||
| ca86db8f66 |
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>
|
||||
|
||||
@@ -22,6 +22,12 @@ public class RabbitMQConfig {
|
||||
|
||||
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:表示持久化
|
||||
//队列在默认情况下放到内存,rabbitmq重启后就丢失了,如果希望重启后,队列
|
||||
@@ -46,6 +52,28 @@ public class RabbitMQConfig {
|
||||
.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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import com.yupi.springbootinit.model.entity.ServerBigBrother;
|
||||
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;
|
||||
@@ -28,6 +29,7 @@ public class MQSender {
|
||||
@Resource
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
|
||||
//方法:发送消息
|
||||
public void hostsSend(List<NewHosts> list){
|
||||
try {
|
||||
@@ -55,10 +57,27 @@ public class MQSender {
|
||||
|
||||
public void send(Long tenantId, Object payload) {
|
||||
// 发送消息,把 userId 放进 header
|
||||
rabbitTemplate.convertAndSend(RabbitMQConfig.EXCHANGE_NAME, "", payload, m -> {
|
||||
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;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -79,8 +79,16 @@ public class HostInfoServiceImpl extends ServiceImpl<NewHostsMapper, NewHosts> i
|
||||
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();
|
||||
@@ -140,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);
|
||||
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user