1、预警aop优化,服务降级不执行预警方法
This commit is contained in:
parent
3c613d1ead
commit
da6a4dda62
|
|
@ -5,6 +5,7 @@ import cn.hutool.core.date.DateUnit;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.core.domain.R;
|
||||||
import com.xjs.annotation.ApiLog;
|
import com.xjs.annotation.ApiLog;
|
||||||
import com.xjs.business.log.RemoteLogFeign;
|
import com.xjs.business.log.RemoteLogFeign;
|
||||||
|
|
@ -30,6 +31,7 @@ import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||||
import static com.xjs.consts.ApiWarnHandleConst.NO;
|
import static com.xjs.consts.ApiWarnHandleConst.NO;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -70,8 +72,13 @@ public class ApiLogAspect {
|
||||||
LocalDateTime localDateTime2 = DateUtil.date().toLocalDateTime();
|
LocalDateTime localDateTime2 = DateUtil.date().toLocalDateTime();
|
||||||
long between = ChronoUnit.MILLIS.between(localDateTime1, localDateTime2);
|
long between = ChronoUnit.MILLIS.between(localDateTime1, localDateTime2);
|
||||||
log.info("调用接口耗费时间:{}ms", between);
|
log.info("调用接口耗费时间:{}ms", between);
|
||||||
//执行预警切入逻辑
|
//执行预警切入逻辑(降级不预警)
|
||||||
warning(between, joinPoint);
|
if (obj instanceof JSONObject) {
|
||||||
|
JSONObject jsonObject = (JSONObject) obj;
|
||||||
|
if (!jsonObject.containsKey(DEMOTE_ERROR)) {
|
||||||
|
warning(between, joinPoint);
|
||||||
|
}
|
||||||
|
}
|
||||||
return obj;
|
return obj;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
||||||
|
|
@ -24,4 +24,12 @@ public interface TopSearchService {
|
||||||
Integer deleteRepeat();
|
Integer deleteRepeat();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据日期获取历史热搜数据
|
||||||
|
* @param date 日期
|
||||||
|
* @return 热搜数据
|
||||||
|
*/
|
||||||
|
Map<String, List> getHistoryTopSearchByDate(String date);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
package com.xjs.topsearch.service.impl;
|
package com.xjs.topsearch.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateTime;
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.xjs.topsearch.domain.*;
|
import com.xjs.topsearch.domain.*;
|
||||||
import com.xjs.topsearch.factory.TopserachFactory;
|
import com.xjs.topsearch.factory.TopserachFactory;
|
||||||
import com.xjs.topsearch.service.*;
|
import com.xjs.topsearch.service.*;
|
||||||
|
|
@ -78,4 +81,25 @@ public class TopSearchServiceImpl implements TopSearchService {
|
||||||
log.info("thread id:{},清除微博热搜榜重复数据,重复数:{}", Thread.currentThread().getId(),weiboCount);
|
log.info("thread id:{},清除微博热搜榜重复数据,重复数:{}", Thread.currentThread().getId(),weiboCount);
|
||||||
return allNetworkCount+wechatCount+baiduCount+douyinCount+weiboCount;
|
return allNetworkCount+wechatCount+baiduCount+douyinCount+weiboCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, List> getHistoryTopSearchByDate(String date) {
|
||||||
|
DateTime dateTime = DateUtil.parseDate(date);
|
||||||
|
String dateStr = dateTime.toDateStr();
|
||||||
|
|
||||||
|
String StartDate = dateStr + " 00:00:00";
|
||||||
|
String EndDate = dateStr + " 23:59:59";
|
||||||
|
|
||||||
|
List<ApiTopsearchAllnetwork> allnetworkList = apiTopsearchAllnetworkService
|
||||||
|
.list(new QueryWrapper<ApiTopsearchAllnetwork>()
|
||||||
|
.between("create_time", StartDate, EndDate));
|
||||||
|
|
||||||
|
|
||||||
|
// todo 热搜榜历史数据显示实现
|
||||||
|
|
||||||
|
|
||||||
|
HashMap<String, List> hashMap = new HashMap<>();
|
||||||
|
hashMap.put("allnetworkList", allnetworkList);
|
||||||
|
return hashMap;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.xjs.topsearch.service.impl;
|
||||||
|
|
||||||
|
import com.xjs.XjsOpenApiApp;
|
||||||
|
import com.xjs.topsearch.service.TopSearchService;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-01-22
|
||||||
|
*/
|
||||||
|
@SpringBootTest(classes = XjsOpenApiApp.class)
|
||||||
|
class TopSearchServiceImplTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TopSearchService topSearchService;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getHistoryTopSearchByDate() {
|
||||||
|
|
||||||
|
Map<String, List> date = topSearchService.getHistoryTopSearchByDate("2022-01-22 20:20:20");
|
||||||
|
|
||||||
|
List allnetworkList = date.get("allnetworkList");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue