当前位置: 首页 > news >正文

做网站的系统营销策划方案范文

做网站的系统,营销策划方案范文,服务号微网站怎么做,家装设计包括哪些内容前言 直播间贡献榜是一种常见的直播平台功能,用于展示观众在直播过程中的贡献情况。它可以根据观众的互动行为和贡献值进行排名,并实时更新,以鼓励观众积极参与直播活动。 在直播间贡献榜中,每个观众都有一个对应的贡献值&#…

前言

直播间贡献榜是一种常见的直播平台功能,用于展示观众在直播过程中的贡献情况。它可以根据观众的互动行为和贡献值进行排名,并实时更新,以鼓励观众积极参与直播活动。

在直播间贡献榜中,每个观众都有一个对应的贡献值,贡献值用来衡量观众在直播过程中的贡献程度。观众的贡献值可以通过多种途径获得,比如送礼物、打赏主播等。

首先,我们需要创建一个贡献榜单,可以使用Redis的有序集合 (Sorted Set)结构来实现。在有序集合中,每个观众对应一个唯一的ID作为成员,而成员的分数表示观众的贡献值。可以根据观众每次送出礼物增加相应的贡献值。

当有新的观众参与直播并进行互动时,我们可以使用ZADD命令将其用户ID添加到贡献榜单中,并更新相应的贡献值。可以根据贡献值对观众进行排序,从而得到当前排名靠前的观众。

要实时更新贡献榜单,可以使用ZINCRBY命令增加观众的贡献值。当观众进行互动行为时,我们可以调用ZINCRBY命令增加相应观众的贡献值,并确保贡献榜单及时反映观众的最新贡献情况。

Redis实现命令

用户ID为Test1000的得到价值为1314的礼物时,以及获取排行榜时,命令如下。比如

# 增加排行榜用户数据ZINCRBY ROUND_LIST_CACHE_20221222 1314 Test1000# 展示用户榜单ZRANGE ROUND_LIST_CACHE_20221222 0 -1 WITHSCORES

JAVA简单逻辑代码实现 

1.Spring boot的yml配置文件,配置礼物队列

       
#yml配置文件配置队列 
GiftFlowOutput: content-type: application/jsondestination: gift_all_flow
GiftFlowInput: #礼物队列content-type: application/jsongroup: GiftAllFlowGroup

2.redis使用lua脚本增加榜单,保证多机并发原子性

//redis lua脚本配置
@Slf4j
@Configuration
public class RedisConfig {@Autowiredprivate JdkCacheHandler jdkCacheHandler;@Bean("zsetScoreScript")public RedisScript<Long> zsetScoreScript() {DefaultRedisScript<Long> redisScript = new DefaultRedisScript<>();redisScript.setScriptSource(new ResourceScriptSource(new ClassPathResource("/lua/zadd.lua")));redisScript.setResultType(Long.class);return redisScript;}
}

3。LUA脚本具体实现,保留3位有效礼物小数位,后面小数位用于同个时间刷礼物进行排序,目前这里只精确到了秒

local key=KEYS[1]
local member=KEYS[2]
local newValue=tonumber(string.format("%.16f",ARGV[1]))
local oldValue=redis.call('ZSCORE',key,member)
if type(oldValue) == 'boolean' thenredis.call('ZADD',key,newValue,member)return 1
elseredis.call('ZADD',key,tonumber(string.format("%.3f",oldValue))+newValue,member)return 1
end
return 0

 4.调用lua脚本,增加排行榜积分

@Component
@Slf4j
public class RankScoreUtilManager {private final static DecimalFormat format = new DecimalFormat(ActivityBase.TOTAL_FORMAT);@Autowiredprivate StringRedisTemplate redisTemplate;@Autowiredprivate ActivityTimeCache activityTimeCache;@Resource(name = "zsetScoreScript")private RedisScript<Long> zaddScript;/*** 添加分数到排行榜,可以并发的*/public void addScoreToRank(String cacheKey, String anchorId, BigDecimal integral, Date eventTime) {try {BigDecimal bigDecimal = dealScore(integral, activityTimeCache.getActivityDTO().getEndTime(), eventTime);String score = format.format(bigDecimal.doubleValue());Long execute = redisTemplate.execute(zaddScript, Arrays.asList(cacheKey, anchorId), score);log.warn("增加积分到排行榜integral={},anchorId={},score={},execute",integral,anchorId,score,execute);} catch (Exception e) {log.error("增加异常", e);}}private static BigDecimal dealScore(BigDecimal newScore, LocalDateTime activityEndTime, Date eventDate) {DecimalFormat format = new DecimalFormat(ActivityBase.VALID_FORMAT);String formatStr = format.format(EeBigDecimalUtil.scale(newScore, ActivityBase.VALID_SCALE, RoundingMode.DOWN).doubleValue());StringBuilder sb = new StringBuilder(32);//后面补个0,避免lua进1出错sb.append(formatStr).append('0');long n = EeDateUtil.getMilli(activityEndTime) - eventDate.getTime();String s = Long.toString(Math.abs(n) / 1000);for (int i = s.length(); i < ActivityBase.TIME_SCALE; i++) {sb.append('0');}sb.append(s);return new BigDecimal(sb.toString()).setScale(ActivityBase.TOTAL_SCALE, RoundingMode.DOWN);}}

5.配置礼物队列名称 

/**
* 监听礼物流水队列
*/
public interface AllGiftFlowProcessor {String OUTPUT = "GiftFlowOutput";@Output(OUTPUT)MessageChannel output();String INPUT = "GiftFlowInput";@Input(INPUT)SubscribableChannel input();
}

 6.监听礼物队列的listener,前面做了一些活动时间校验的判断,最关键的是最下面roundListBusiness.dealAnchorRoundList(dto);的方法


//监听礼物队列,处理相关业务逻辑,榜单的处理在最下面@Slf4j
@Service
public class AllGiftFlowListener {@Autowiredprivate RedisTemplate<String, String> redisTemplate;@Autowiredprivate AnchorLevelBusiness anchorLevelBusiness;private static final String cacheKey = "GIFT:TASK:INTER:EVENT:";@Autowiredprivate EeEnvironmentHolder eeEnvironmentHolder;@Autowiredprivate ActivityRoundDao activityRoundDao;@Autowiredprivate ActivityTimeCache activityTimeCache;@Autowiredprivate GiftConfigCache giftConfigCache;@Autowiredprivate GiftFlowProcessor giftFlowProcessor;@Autowiredprivate AnchorCache anchorCache;@Autowiredprivate RoundListBusiness roundListBusiness;@Autowiredprivate EeLog eeLog;@StreamListener(AllGiftFlowProcessor.INPUT)public void onReceive(ActivityGiftEventDTO dto) {MqConsumeRunner.run(dto.getEventId().toString(), dto, o -> dealMsgEvent(o), "TaskIntegralProcessor [{}]", dto);}private void dealMsgEvent(ActivityGiftEventDTO dto) {// 过滤非活动时间礼物ActivityDTO activityDTO = activityTimeCache.getActivityDTO();if (null == activityDTO) {return;}if (EeDateUtil.toLocalDateTime(dto.getEventDate()).isBefore(activityDTO.getStartTime())) {eeLog.info("礼物时间小于活动开始时间,丢弃礼物");return;}// 判断活动时间if (ActivityStatusEnum.NO_START == activityRoundDao.getActivityStatus()) {return;}// 过滤活动礼物if (giftConfigCache.getData().stream().noneMatch(o -> o.getGiftId().equals(dto.getGiftId()))) {eeLog.info("礼物id:{}不计算", dto.getGiftId());return;}Integer region = anchorCache.getRegionById(dto.getTarget());// 是否为签区域主播if (null == region || !ActivityBase.AnchorRegion.contains(region)) {eeLog.warn("该主播非签约或非参赛区域:{}", dto.getTarget());return;}// 是否重复消费礼物Boolean success = redisTemplate.opsForValue().setIfAbsent(cacheKey + dto.getEventId(), "", 15, TimeUnit.DAYS);if (success != null && !success) {eeLog.info("升级事件已处理:" + dto);return;}try {//监听礼物并且处理榜单(最主要的代码就这一句)roundListBusiness.dealAnchorRoundList(dto);} catch (Exception e) {log.error("处理榜单 fail.[" + dto + "]", e);}}}

 7.榜单的具体实现逻辑

@Component
@Slf4j
public class RoundListBusiness {//平台主播榜单private final static String CHRISTMAS_ROUND_ANCHOR_LIST = "CHRISTMAS:ROUND:ANCHOR:LIST";private final static String CHRISTMAS_ROUND_LIST_LOCK = "CHRISTMAS:ROUND:LIST:LOCK";@Autowiredprivate RankScoreUtilManager rankScoreUtilManager;@Autowiredprivate ActivityTimeCache activityTimeCache;@AutowiredRedisTemplate<String, String> redisTemplate;@Autowiredprivate AllGiftFlowProcessor allGiftFlowProcessor;/*** 处理榜单加分逻辑*/public void dealAnchorRoundList(ActivityGiftEventDTO dto) {ActivityDTO activityDTO = activityTimeCache.getActivityDTO();if (EeDateUtil.toLocalDateTime(dto.getEventDate()).isBefore(activityDTO.getStartTime())) {return;}if (!EeDateUtil.toLocalDateTime(dto.getEventDate()).isBefore(activityDTO.getEndTime())) {return;}//记录总的榜单流水try {//插入总的流水allGiftFlowProcessor.output().send(MessageBuilder.withPayload(dto).build());} catch (Exception e) {log.error("插入总的礼物流水异常dto={}", dto, e);}LocalDateTime now = LocalDateTime.now();if (!now.isBefore(activityDTO.getEndTime())) {//2.判断是否符合处理上一轮榜单的逻辑if (isThrowAwayBeforeGift(dto.getEventId(), now, activityDTO.getEndTime())) {log.warn("这里跳出了dto={},now={}", dto, EeDateUtil.format(now));return;}}dealRoundList(dto, dto.getTotalStarAmount());}/*** 处理主播榜单加分逻辑*/private void dealRoundList(ActivityGiftEventDTO dto, BigDecimal value) {//增加平台主播榜单incrAnchorListValue(CHRISTMAS_ROUND_ANCHOR_LIST, dto.getTarget(), value, dto.getEventDate());}/*** 具体加分方法*/public void incrAnchorListValue(String listCacheKey, String userId, BigDecimal value, Date eventTime) {if (EeStringUtil.isNotEmpty(listCacheKey)) {//增加榜单分数rankScoreUtilManager.addScoreToRank(listCacheKey, userId, value, eventTime);}}/*** 判断是否已经超过结算时间*/private boolean isThrowAwayBeforeGift(String eventId, LocalDateTime now, LocalDateTime endTime) {//如果当前时间超过了结算时间,直接丢弃礼物if (!now.isBefore(endTime.plusSeconds(ActivityBase.PROCESS_TS))) {log.error("主播榜单-当前时间超过了结算时间,直接丢弃礼物: {}", eventId);return true;}//如果上一轮的榜单已经锁定,丢弃礼物if (checkBlockRankList(CHRISTMAS_ROUND_ANCHOR_LIST)) {log.error("主播榜单-榜单被锁定后丢弃礼物: {}, {}", eventId, EeDateUtil.format(LocalDateTime.now()));return true;}return false;}/*** 判断结算时榜单是否已经被锁定*/public boolean checkBlockRankList(String listCacheKey) {Boolean cache = redisTemplate.opsForHash().hasKey(CHRISTMAS_ROUND_LIST_LOCK, listCacheKey);return null != cache && cache;}/*** 锁定榜单,把锁定的榜单都放入一个hash中*/public void setBlockRankList(String cacheKey) {redisTemplate.opsForHash().put(CHRISTMAS_ROUND_LIST_LOCK, cacheKey, EeDateUtil.format(LocalDateTime.now()));}
}

总结:目前这段代码只是实现了简单的日榜逻辑,还有一段结算的代码我没有复制出来,结算榜单无非就是在每天0点的时候结算前一天的榜单,对榜单前几名的主播进行礼物发放,后续将会更新几种复杂榜单的实现方式,包括:晋级榜单,积分晋级榜单,滚动日榜,滚动周榜,滚动月榜的一些实现方式


文章转载自:
http://superstructure.c7623.cn
http://questionmaster.c7623.cn
http://ghazi.c7623.cn
http://oeillade.c7623.cn
http://photoglyphy.c7623.cn
http://azygous.c7623.cn
http://blasphemy.c7623.cn
http://intransigence.c7623.cn
http://katrine.c7623.cn
http://headful.c7623.cn
http://tiptoe.c7623.cn
http://monist.c7623.cn
http://blin.c7623.cn
http://unreactive.c7623.cn
http://rubenesque.c7623.cn
http://varicose.c7623.cn
http://timework.c7623.cn
http://decalcification.c7623.cn
http://aortoiliac.c7623.cn
http://misattribution.c7623.cn
http://linac.c7623.cn
http://conceive.c7623.cn
http://megogigo.c7623.cn
http://somniloquy.c7623.cn
http://rimfire.c7623.cn
http://telegonus.c7623.cn
http://magi.c7623.cn
http://etruscan.c7623.cn
http://hlbb.c7623.cn
http://hattery.c7623.cn
http://mechanochemical.c7623.cn
http://lunkhead.c7623.cn
http://perissad.c7623.cn
http://quill.c7623.cn
http://decarbonization.c7623.cn
http://inconvertibility.c7623.cn
http://mosque.c7623.cn
http://leeriness.c7623.cn
http://qstol.c7623.cn
http://krameria.c7623.cn
http://floodtime.c7623.cn
http://suddenness.c7623.cn
http://boyd.c7623.cn
http://arcady.c7623.cn
http://hydrometrical.c7623.cn
http://asbestine.c7623.cn
http://uniseptate.c7623.cn
http://driography.c7623.cn
http://nine.c7623.cn
http://mothering.c7623.cn
http://versus.c7623.cn
http://recross.c7623.cn
http://silliness.c7623.cn
http://precession.c7623.cn
http://cervelat.c7623.cn
http://dishonesty.c7623.cn
http://contrivable.c7623.cn
http://tableaux.c7623.cn
http://chambered.c7623.cn
http://modish.c7623.cn
http://impubic.c7623.cn
http://vagodepressor.c7623.cn
http://ungues.c7623.cn
http://cupula.c7623.cn
http://feint.c7623.cn
http://commonness.c7623.cn
http://rubout.c7623.cn
http://inviolacy.c7623.cn
http://divaricator.c7623.cn
http://protoxide.c7623.cn
http://zootechny.c7623.cn
http://blissful.c7623.cn
http://accommodable.c7623.cn
http://commence.c7623.cn
http://kilnman.c7623.cn
http://gerundival.c7623.cn
http://unlimitedly.c7623.cn
http://onboard.c7623.cn
http://lamelliform.c7623.cn
http://soother.c7623.cn
http://logy.c7623.cn
http://orionid.c7623.cn
http://fucus.c7623.cn
http://exciton.c7623.cn
http://levoglucose.c7623.cn
http://ethic.c7623.cn
http://exhaustion.c7623.cn
http://vivify.c7623.cn
http://goblinry.c7623.cn
http://viborg.c7623.cn
http://toothful.c7623.cn
http://reconsider.c7623.cn
http://overdesign.c7623.cn
http://dynode.c7623.cn
http://smashup.c7623.cn
http://hallow.c7623.cn
http://duel.c7623.cn
http://sumpitan.c7623.cn
http://killed.c7623.cn
http://megaric.c7623.cn
http://www.zhongyajixie.com/news/85329.html

相关文章:

  • 沈阳微网站制作友链提交入口
  • 织梦如何做视频网站seo快速排名软件品牌
  • 做mro的b2b网站网络营销的八大能力
  • 网站建设专业简介国内外十大免费crm软件推荐
  • 佛山网站建设明细服务网站推广方案
  • wordpress js图片广州百度推广优化
  • 网站制作 代码编辑百度指数1000搜索量有多少
  • 网站怎么做兼容测试域名ip查询
  • 个安装wordpress百度seo营销公司
  • 什么网站做设计可以赚钱举例一个成功的网络营销案例
  • 精美ppt模板免费下载软件seo 工具推荐
  • 信誉好的企业网站开发合肥seo排名优化
  • 做微信的网站有哪些功能电脑软件推广平台
  • wordpress博客转换小程序快速排名优化推广价格
  • 福州做网站建设公司网站建设哪家公司好
  • 做社交网站有哪些适合推广的app有哪些
  • 好的做问卷调查的网站好福州seo公司排名
  • 专业建设思路与措施网站seo排名优化方法
  • 响应式网站实例网络营销主要做什么
  • 英文网站做百度权重有意义吗seo赚钱培训
  • 制作网站网站建设深圳网络推广有几种方法
  • 我国档案网站建设研究论文google网页搜索
  • 淘宝返利网站怎么做的网站排名优化培训
  • 诸城做网站的公司广州全网推广
  • 温州高端网站建设竞价推广开户
  • 电子商城网站制作湖南省人民政府
  • wordpress google字体 360西安网站seo
  • 烟台教育网站建设深圳靠谱网站建设公司
  • 上海注销营业执照流程沈阳seo关键词
  • .net作业做网站宁波seo在线优化方案公司