|
@@ -8,6 +8,7 @@ import com.zanxiang.game.data.serve.service.IGameMonitorAlarmService;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
import org.nutz.dao.Chain;
|
|
import org.nutz.dao.Chain;
|
|
import org.nutz.dao.Cnd;
|
|
import org.nutz.dao.Cnd;
|
|
import org.nutz.dao.Dao;
|
|
import org.nutz.dao.Dao;
|
|
@@ -18,7 +19,11 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @author tianhua
|
|
* @author tianhua
|
|
@@ -46,37 +51,64 @@ public class GameMonitorAlarmServiceImpl implements IGameMonitorAlarmService {
|
|
dao.execute(sql);
|
|
dao.execute(sql);
|
|
//结果
|
|
//结果
|
|
log.info("查询告警信息结束");
|
|
log.info("查询告警信息结束");
|
|
- try{
|
|
|
|
|
|
+ try {
|
|
List<GameMonitorAlarmVO> list1 = sql.getList(GameMonitorAlarmVO.class);
|
|
List<GameMonitorAlarmVO> list1 = sql.getList(GameMonitorAlarmVO.class);
|
|
log.info("告警信息:{}", list1);
|
|
log.info("告警信息:{}", list1);
|
|
- if (CollectionUtils.isEmpty(list1)){
|
|
|
|
|
|
+ if (CollectionUtils.isEmpty(list1)) {
|
|
log.info("没有告警信息");
|
|
log.info("没有告警信息");
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
+ //用type==4进行分组
|
|
|
|
+ Map<Boolean, List<GameMonitorAlarmVO>> partitionedMap = list1.stream()
|
|
|
|
+ .collect(Collectors.partitioningBy(vo -> vo.getConfigType() == 4));
|
|
|
|
+ List<GameMonitorAlarmVO> listWithType4 = partitionedMap.get(true);
|
|
|
|
+
|
|
|
|
+ //如果有type==4的,则每个投手的消息整合为1条告警
|
|
|
|
+ if (CollectionUtils.isNotEmpty(listWithType4)) {
|
|
|
|
+ Map<String, List<GameMonitorAlarmVO>> map = new HashMap<>();
|
|
|
|
+ for (GameMonitorAlarmVO vo : listWithType4) {
|
|
|
|
+ String[] pitcherIds = vo.getPitcherId().split("-");
|
|
|
|
+ for (String pitcherId : pitcherIds) {
|
|
|
|
+ if (map.get(pitcherId) != null) {
|
|
|
|
+ map.get(pitcherId).add(vo);
|
|
|
|
+ }else {
|
|
|
|
+ ArrayList<GameMonitorAlarmVO> newList = new ArrayList<>();
|
|
|
|
+ newList.add(vo);
|
|
|
|
+ map.put(pitcherId,newList);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ for (String pitcherId : map.keySet()) {
|
|
|
|
+ List<GameMonitorAlarmVO> gameMonitorAlarmVOS = map.get(pitcherId);
|
|
|
|
+ StringBuilder msgStr = new StringBuilder(0);
|
|
|
|
+ //把消息拼成一条
|
|
|
|
+ for (int i = 0; i < gameMonitorAlarmVOS.size(); i++) {
|
|
|
|
+ String s = alarmStr(gameMonitorAlarmVOS.get(i),i);
|
|
|
|
+ msgStr.append(s);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ log.info("type类型为4的告警信息,投手id:{}",pitcherId);
|
|
|
|
+ dingTalkMsgRpc.sendByUserId(Long.valueOf(pitcherId), new String(msgStr));
|
|
|
|
+ log.info("type类型为4的告警信息发送成功,投手id:{}",pitcherId);
|
|
|
|
+ }
|
|
|
|
+ for (GameMonitorAlarmVO vo : listWithType4) {
|
|
|
|
+ Criteria cri = getCriteria(vo);
|
|
|
|
+ dao.update(AdsMonitorAlarm.class, Chain.make("warn_status", 1), cri);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //如果没有type==4的,则每个投手的消息单独发送
|
|
|
|
+ List<GameMonitorAlarmVO> listWithoutType4 = partitionedMap.get(false);
|
|
log.info("准备发送告警信息");
|
|
log.info("准备发送告警信息");
|
|
- for (GameMonitorAlarmVO vo : list1) {
|
|
|
|
|
|
+ for (GameMonitorAlarmVO vo : listWithoutType4) {
|
|
String[] pitcherIds = vo.getPitcherId().split("-");
|
|
String[] pitcherIds = vo.getPitcherId().split("-");
|
|
for (String pitcherId : pitcherIds) {
|
|
for (String pitcherId : pitcherIds) {
|
|
//发送给多个投手
|
|
//发送给多个投手
|
|
log.info("发送告警信息给投手:{}", pitcherId);
|
|
log.info("发送告警信息给投手:{}", pitcherId);
|
|
- dingTalkMsgRpc.sendByUserId(Long.valueOf(pitcherId), alarmStr(vo));
|
|
|
|
|
|
+ dingTalkMsgRpc.sendByUserId(Long.valueOf(pitcherId), alarmStr(vo,null));
|
|
log.info("发送告警信息给投手:{}成功", pitcherId);
|
|
log.info("发送告警信息给投手:{}成功", pitcherId);
|
|
}
|
|
}
|
|
- //更新的条件
|
|
|
|
- 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());
|
|
|
|
- }
|
|
|
|
- log.info("更新告警信息状态");
|
|
|
|
|
|
+ Criteria cri = getCriteria(vo);
|
|
dao.update(AdsMonitorAlarm.class, Chain.make("warn_status", 1), cri);
|
|
dao.update(AdsMonitorAlarm.class, Chain.make("warn_status", 1), cri);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -86,11 +118,76 @@ public class GameMonitorAlarmServiceImpl implements IGameMonitorAlarmService {
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public boolean sendMsgToUserTest() {
|
|
|
|
+ Sql sql = Sqls.create(getMonitorAlarmInfoSql());
|
|
|
|
+ sql.setCallback(Sqls.callback.entities());
|
|
|
|
+ sql.setEntity(dao.getEntity(GameMonitorAlarmVO.class));
|
|
|
|
+ dao.execute(sql);
|
|
|
|
+ List<GameMonitorAlarmVO> list1 = sql.getList(GameMonitorAlarmVO.class);
|
|
|
|
+ //用type==4进行分组
|
|
|
|
+ Map<Boolean, List<GameMonitorAlarmVO>> partitionedMap = list1.stream()
|
|
|
|
+ .collect(Collectors.partitioningBy(vo -> vo.getConfigType() == 4));
|
|
|
|
+ List<GameMonitorAlarmVO> listWithType4 = partitionedMap.get(true);
|
|
|
|
+ //如果有type==4的,则每个投手的消息整合为1条告警
|
|
|
|
+ if (CollectionUtils.isNotEmpty(listWithType4)) {
|
|
|
|
+ Map<String, List<GameMonitorAlarmVO>> map = new HashMap<>();
|
|
|
|
+ for (GameMonitorAlarmVO vo : listWithType4) {
|
|
|
|
+ String[] pitcherIds = vo.getPitcherId().split("-");
|
|
|
|
+ for (String pitcherId : pitcherIds) {
|
|
|
|
+ if (map.get(pitcherId) != null) {
|
|
|
|
+ map.get(pitcherId).add(vo);
|
|
|
|
+ }else {
|
|
|
|
+ ArrayList<GameMonitorAlarmVO> newList = new ArrayList<>();
|
|
|
|
+ newList.add(vo);
|
|
|
|
+ map.put(pitcherId,newList);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ for (String pitcherId : map.keySet()) {
|
|
|
|
+ List<GameMonitorAlarmVO> gameMonitorAlarmVOS = map.get(pitcherId);
|
|
|
|
+ StringBuilder msgStr = new StringBuilder(0);
|
|
|
|
+ //把消息拼成一条
|
|
|
|
+ for (int i = 0; i < gameMonitorAlarmVOS.size(); i++) {
|
|
|
|
+ String s = alarmStr(gameMonitorAlarmVOS.get(i),i);
|
|
|
|
+ msgStr.append(s);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ log.info("type类型为4的告警信息,投手id:{}",pitcherId);
|
|
|
|
+ log.info("type类型为4的告警信息:{}",msgStr);
|
|
|
|
+ log.info("type类型为4的告警信息发送成功,投手id:{}",pitcherId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Criteria getCriteria(GameMonitorAlarmVO 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());
|
|
|
|
+ }
|
|
|
|
+ log.info("更新告警信息状态");
|
|
|
|
+ return cri;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 生成告警信息字符串
|
|
* 生成告警信息字符串
|
|
*/
|
|
*/
|
|
- private String alarmStr(GameMonitorAlarmVO vo) {
|
|
|
|
|
|
+ private String alarmStr(GameMonitorAlarmVO vo,Integer index) {
|
|
StringBuilder msgStr = new StringBuilder(0);
|
|
StringBuilder msgStr = new StringBuilder(0);
|
|
|
|
+ if(index!=null){
|
|
|
|
+ msgStr.append("【"+(index+1)+"】 \n");
|
|
|
|
+ }
|
|
msgStr.append("游戏策略响应时间:")
|
|
msgStr.append("游戏策略响应时间:")
|
|
.append(vo.getDt())
|
|
.append(vo.getDt())
|
|
.append(" ;")
|
|
.append(" ;")
|
|
@@ -112,13 +209,16 @@ public class GameMonitorAlarmServiceImpl implements IGameMonitorAlarmService {
|
|
.append(" ;")
|
|
.append(" ;")
|
|
.append("\n")
|
|
.append("\n")
|
|
.append("该用户响应的策略属于:")
|
|
.append("该用户响应的策略属于:")
|
|
- .append(vo.getConfigExplain());
|
|
|
|
|
|
+ .append(vo.getConfigExplain())
|
|
|
|
+ .append(";")
|
|
|
|
+ .append("\n");
|
|
|
|
|
|
return msgStr.toString();
|
|
return msgStr.toString();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 游戏监控告警sql
|
|
* 游戏监控告警sql
|
|
|
|
+ *
|
|
* @return String
|
|
* @return String
|
|
*/
|
|
*/
|
|
private String getMonitorAlarmInfoSql() {
|
|
private String getMonitorAlarmInfoSql() {
|
|
@@ -139,6 +239,7 @@ public class GameMonitorAlarmServiceImpl implements IGameMonitorAlarmService {
|
|
a.pitcher_id ,
|
|
a.pitcher_id ,
|
|
a.message ,
|
|
a.message ,
|
|
a.config_explain ,
|
|
a.config_explain ,
|
|
|
|
+ a.config_type,
|
|
a.warn_status
|
|
a.warn_status
|
|
FROM game_ads.ads_monitor_alarm a
|
|
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 dm_game_order.t_game_user b on a.source_system = b.source_system AND a.user_id = b.id
|
|
@@ -155,6 +256,6 @@ public class GameMonitorAlarmServiceImpl implements IGameMonitorAlarmService {
|
|
WHERE a.warn_status = 0
|
|
WHERE a.warn_status = 0
|
|
""";
|
|
""";
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|