|
@@ -2,13 +2,22 @@ package com.zanxiang.game.data.serve.service.impl;
|
|
|
|
|
|
import com.zanxiang.erp.base.ErpServer;
|
|
|
import com.zanxiang.erp.base.rpc.IDingTalkMsgRpc;
|
|
|
+import com.zanxiang.game.data.serve.pojo.entity.AdsMonitorAlarm;
|
|
|
+import com.zanxiang.game.data.serve.pojo.vo.GameMonitorAlarmVO;
|
|
|
import com.zanxiang.game.data.serve.service.IGameMonitorAlarmService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
+import org.nutz.dao.Chain;
|
|
|
+import org.nutz.dao.Cnd;
|
|
|
import org.nutz.dao.Dao;
|
|
|
+import org.nutz.dao.Sqls;
|
|
|
+import org.nutz.dao.sql.Criteria;
|
|
|
+import org.nutz.dao.sql.Sql;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.time.LocalDateTime;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* @author tianhua
|
|
@@ -17,6 +26,7 @@ import java.time.LocalDateTime;
|
|
|
* @date 2023/12/13 16:24
|
|
|
*/
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class GameMonitorAlarmServiceImpl implements IGameMonitorAlarmService {
|
|
|
|
|
|
@Autowired
|
|
@@ -25,13 +35,113 @@ public class GameMonitorAlarmServiceImpl implements IGameMonitorAlarmService {
|
|
|
@DubboReference(providedBy = ErpServer.SERVER_DUBBO_NAME)
|
|
|
private IDingTalkMsgRpc dingTalkMsgRpc;
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public boolean sendMsgToUser() {
|
|
|
- LocalDateTime now = LocalDateTime.now();
|
|
|
- String msg = "这是一条测试钉钉消息,发送时间:" + now;
|
|
|
- dingTalkMsgRpc.sendByUserId(401L, msg);
|
|
|
-
|
|
|
+ //数据库查表
|
|
|
+ Sql sql = Sqls.create(getMonitorAlarmInfoSql());
|
|
|
+ sql.setCallback(Sqls.callback.entities());
|
|
|
+ sql.setEntity(dao.getEntity(GameMonitorAlarmVO.class));
|
|
|
+ dao.execute(sql);
|
|
|
+ //结果
|
|
|
+ try{
|
|
|
+ List<GameMonitorAlarmVO> list = sql.getList(GameMonitorAlarmVO.class).stream().map(vo -> {
|
|
|
+ String[] pitcherIds = vo.getPitcherId().split(",");
|
|
|
+ for (String pitcherId : pitcherIds) {
|
|
|
+ //发送给多个投手
|
|
|
+ dingTalkMsgRpc.sendByUserId(Long.valueOf(pitcherId), alarmStr(vo));
|
|
|
+ }
|
|
|
+ //更新的条件
|
|
|
+ Criteria cri = Cnd.cri();
|
|
|
+ if (vo.getId() != null) {
|
|
|
+ cri.where().andEquals("id", vo.getId());
|
|
|
+ }
|
|
|
+ if (vo.getDt() != null) {
|
|
|
+ cri.where().andEquals("dt", vo.getDt());
|
|
|
+ }
|
|
|
+ if (vo.getGameId() != null) {
|
|
|
+ cri.where().andEquals("gameId", vo.getGameId());
|
|
|
+ }
|
|
|
+ if (vo.getUserId() != null) {
|
|
|
+ cri.where().andEquals("userId", vo.getUserId());
|
|
|
+ }
|
|
|
+ dao.update(AdsMonitorAlarm.class, Chain.make("warn_status", 1), cri);
|
|
|
+ return vo;
|
|
|
+ }).toList();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("游戏监控告警出错,原因:{}", e.getMessage(), e);
|
|
|
+ }
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 生成告警信息字符串
|
|
|
+ */
|
|
|
+ private String alarmStr(GameMonitorAlarmVO vo) {
|
|
|
+ StringBuilder msgStr = new StringBuilder(0);
|
|
|
+ msgStr.append("游戏策略响应时间:")
|
|
|
+ .append(vo.getDt())
|
|
|
+ .append(" ;")
|
|
|
+ .append("\n")
|
|
|
+ .append("游戏名称:")
|
|
|
+ .append(vo.getGameName())
|
|
|
+ .append(" ;区服名称:")
|
|
|
+ .append(vo.getServerName())
|
|
|
+ .append(" ;")
|
|
|
+ .append("\n")
|
|
|
+ .append("用户ID:")
|
|
|
+ .append(vo.getUserId())
|
|
|
+ .append(" ;角色名称:")
|
|
|
+ .append(vo.getRoleName())
|
|
|
+ .append(" ;")
|
|
|
+ .append("\n")
|
|
|
+ .append("响应策略内容:")
|
|
|
+ .append(vo.getMessage())
|
|
|
+ .append(" ;")
|
|
|
+ .append("\n")
|
|
|
+ .append("该用户响应的策略属于:")
|
|
|
+ .append(vo.getConfigExplain());
|
|
|
+
|
|
|
+ return msgStr.toString();
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 游戏监控告警sql
|
|
|
+ * @return String
|
|
|
+ */
|
|
|
+ private String getMonitorAlarmInfoSql() {
|
|
|
+ return """
|
|
|
+ SELECT
|
|
|
+ a.dt ,
|
|
|
+ a.id ,
|
|
|
+ a.source_system ,
|
|
|
+ a.user_id ,
|
|
|
+ b.username ,
|
|
|
+ b.nickname ,
|
|
|
+ a.server_id ,
|
|
|
+ e.server_name ,
|
|
|
+ a.game_id ,
|
|
|
+ d.game_name ,
|
|
|
+ a.role_id ,
|
|
|
+ c.role_name ,
|
|
|
+ a.pitcher_id ,
|
|
|
+ a.message ,
|
|
|
+ a.config_explain ,
|
|
|
+ a.warn_status
|
|
|
+ FROM game_ads.ads_monitor_alarm a
|
|
|
+ LEFT JOIN dm_game_order.t_game_user b on a.source_system = b.source_system AND a.user_id = b.id
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT
|
|
|
+ source_system ,
|
|
|
+ role_id ,
|
|
|
+ role_name ,
|
|
|
+ ROW_NUMBER()over(partition by role_id , source_system order by update_time desc, user_id desc) as num
|
|
|
+ FROM dm_game_order.t_game_user_role
|
|
|
+ ) c on a.source_system = c.source_system AND a.role_id = c.role_id AND c.num = 1
|
|
|
+ LEFT JOIN dm_game_order.t_game d on a.source_system = d.source_system AND a.game_id = d.id
|
|
|
+ LEFT JOIN dm_game_order.t_game_server e on a.source_system = e.source_system AND a.game_id = e.game_id AND a.server_id = e.server_id
|
|
|
+ WHERE a.warn_status = 0
|
|
|
+ """;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|