dos il y a 1 mois
Parent
commit
05ad65d97e

+ 4 - 0
game-business/src/main/java/com/game/business/mapper/AppUserMapper.java

@@ -7,6 +7,7 @@ import java.util.Map;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.game.business.domain.AppUser;
 import com.game.business.vo.ApiUserInfoVo;
+import com.game.business.vo.OffLineUserVo;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 import org.springframework.data.cache.CacheByNativeSql;
@@ -109,4 +110,7 @@ public interface AppUserMapper extends BaseMapper<AppUser> {
     ApiUserInfoVo getUserInfo(@Param("userId") long userId);
 
     Map<String, BigDecimal> getUserCount(Long userId);
+
+    List<OffLineUserVo> selectOffLineUser();
+
 }

+ 3 - 0
game-business/src/main/java/com/game/business/service/IAppUserService.java

@@ -8,6 +8,7 @@ import com.game.business.domain.AppUser;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.game.business.domain.FinTranRecord;
 import com.game.business.vo.ApiUserInfoVo;
+import com.game.business.vo.OffLineUserVo;
 
 /**
  * app用户Service接口
@@ -96,4 +97,6 @@ public interface IAppUserService extends IService<AppUser> {
     ApiUserInfoVo getUserInfo(Long userId);
 
     Map<String, BigDecimal> getUserCount(Long userId);
+
+    List<OffLineUserVo> selectOffLineUser();
 }

+ 6 - 0
game-business/src/main/java/com/game/business/service/impl/AppUserServiceImpl.java

@@ -14,6 +14,7 @@ import java.util.concurrent.TimeUnit;
 import com.game.business.domain.FinTranRecord;
 import com.game.business.service.IFinTranRecordService;
 import com.game.business.vo.ApiUserInfoVo;
+import com.game.business.vo.OffLineUserVo;
 import com.game.common.annotation.DataSource;
 import com.game.common.constant.finance.FinTranType1;
 import com.game.common.constant.finance.FinTranType2;
@@ -250,6 +251,11 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
         return appUserMapper.getUserCount(userId);
     }
 
+    @Override
+    public List<OffLineUserVo> selectOffLineUser() {
+        return appUserMapper.selectOffLineUser();
+    }
+
     @Override
     @DataSource(DataSourceType.SLAVE)
     public ApiUserInfoVo getUserInfo(Long userId) {

+ 34 - 1
game-business/src/main/java/com/game/business/task/AppUserCountTask.java

@@ -1,20 +1,24 @@
 package com.game.business.task;
 
 import cn.hutool.core.date.DateUtil;
-import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.dynamic.datasource.annotation.DSTransactional;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.game.business.domain.*;
 import com.game.business.service.*;
+import com.game.business.util.im.HttpClientUtils;
+import com.game.business.vo.OffLineUserVo;
 import com.game.common.constant.CacheConstants;
 import com.game.common.constant.finance.FinTranType1;
 import com.game.common.constant.finance.FinTranType2;
 import com.game.common.constant.finance.FinTranType3;
 import com.game.common.core.domain.HttpRet;
+import com.game.common.core.domain.R;
 import com.game.common.core.redis.RedisCache;
 import com.game.common.entity.KeyValue;
 import com.game.common.utils.DateUtils;
 import com.game.common.utils.StringUtils;
+import com.game.system.service.ISysConfigService;
 import lombok.extern.log4j.Log4j2;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -63,6 +67,9 @@ public class AppUserCountTask {
     @Autowired
     private IAppUserCountDividendService appUserCountDividendService;
 
+    @Autowired
+    private ISysConfigService sysConfigService;
+
     @Autowired
     private RedisCache redisCache;
 
@@ -694,4 +701,30 @@ public class AppUserCountTask {
             }
         }
     }
+
+    public void dealOffLive(){
+        List<OffLineUserVo> list = appUserService.selectOffLineUser();
+        if(null != list && list.size() > 0){
+            Date now = DateUtil.date();
+            list.forEach(e->{
+                if(now.getTime() - e.getOffTime().getTime() >= 1*60*1000){
+                    log.info("{}离线已超过1分钟,自动关播",e.getUserId());
+                    //离线超过一分钟 自动关播
+                    String url = sysConfigService.selectConfigByKey("sys_live_apiurl").concat("/api/live/httpOpenCloseLive");
+                    Map<String, String> map = new HashMap<>();
+                    map.put("roomId", String.valueOf(e.getRoomId()));
+                    map.put("liveType", "1");
+                    map.put("isLive", String.valueOf(e.getIsLive()));
+                    map.put("description", "关播");
+
+                    String res = HttpClientUtils.ajaxPost(url,map);
+                    if(org.apache.commons.lang3.StringUtils.isBlank(res) || !JSONObject.parseObject(res).getString("code").equals("1")){
+                        log.info("{}自动关播失败===============》》".concat(res),e.getUserId());
+                    }
+                }else{
+                    log.info("{}离线未超过1分钟,停止自动关播",e.getUserId());
+                }
+            });
+        }
+    }
 }

+ 17 - 0
game-business/src/main/java/com/game/business/vo/OffLineUserVo.java

@@ -0,0 +1,17 @@
+package com.game.business.vo;
+
+import lombok.Data;
+import java.util.Date;
+
+@Data
+public class OffLineUserVo {
+
+    private Long userId;
+
+    private Integer isLive;
+
+    private Long roomId;
+
+    private Date offTime;
+
+}

+ 5 - 0
game-business/src/main/resources/mapper/business/AppUserMapper.xml

@@ -875,4 +875,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             </if>
         </where>
     </select>
+
+    <select id="selectOffLineUser" resultType="com.game.business.vo.OffLineUserVo">
+        select a.userid as userId,b.islive as isLive,b.id as roomId,a.last_off_line_time as offTime from app_user as a inner join live_live as b on a.userid = b.user_id
+        where b.islive = 1 and online_status = 0
+    </select>
 </mapper>