shaohongbo 3 vuotta sitten
vanhempi
commit
11de0e61b6

+ 2 - 2
src/main/java/com/persagy/apm/diagnose/feign/client/AlarmServiceClient.java

@@ -10,8 +10,8 @@ import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 
 
-//@FeignClient(name = "energy-alarm-service",url = "http://192.168.16.235:9977")
-@FeignClient(name = "energy-alarm-service")
+@FeignClient(name = "energy-alarm-service",url = "http://192.168.16.235:9977")
+//@FeignClient(name = "energy-alarm-service")
 public interface AlarmServiceClient {
 
     @PostMapping("/projectAlarmRuleObjRels/query")

+ 14 - 17
src/main/java/com/persagy/apm/diagnose/indicatorrecord/service/impl/MonitorIndicatorRecordServiceImpl.java

@@ -10,8 +10,6 @@ import com.persagy.apm.common.model.dto.Sort;
 import com.persagy.apm.diagnose.constant.EnumDataTimeType;
 import com.persagy.apm.diagnose.constant.EnumTimeType;
 import com.persagy.apm.diagnose.indicatorcompute.model.ProjectIndicatorCompute;
-import com.persagy.apm.diagnose.indicatorcompute.model.dto.AddProjectIndicatorComputeDTO;
-import com.persagy.apm.diagnose.indicatorcompute.model.dto.UpdateProjectIndicatorComputeDTO;
 import com.persagy.apm.diagnose.indicatorcompute.service.IProjectIndicatorComputeService;
 import com.persagy.apm.diagnose.indicatorrecord.dao.MonitorIndicatorRecordMapper;
 import com.persagy.apm.diagnose.indicatorrecord.model.ConvertMonitorIndicatorRecordTool;
@@ -21,7 +19,6 @@ import com.persagy.apm.diagnose.indicatorrecord.service.IMonitorIndicatorRecordS
 import com.persagy.apm.diagnose.service.CenterDataService;
 import com.persagy.apm.diagnose.service.EnergyAlarmServiceImpl;
 import com.persagy.apm.diagnose.service.dto.CalculateMethodDTO;
-import com.persagy.apm.diagnose.service.dto.MonitorIndicatorConfigDTO;
 import com.persagy.apm.diagnose.service.dto.ProjectDTO;
 import com.persagy.apm.diagnose.service.dto.TimeDataDTO;
 import com.persagy.apm.diagnose.timerecord.model.CalculateTimeRecord;
@@ -262,7 +259,6 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
                 sort.setColumn(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, sort.getColumn()));
                 queryWrapper.orderBy(true, sort.isAsc(), sort.getColumn());
             }
-
         }
 
         // todo 需判断使用like还是eq
@@ -290,11 +286,12 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
     @Async("asyncComputeDataExecutor")
     public Future<String> computeIndicatorData(ProjectDTO projectDTO, ProjectIndicatorCompute projectIndicatorCompute, CountDownLatch latch) throws Exception {
         long time = System.currentTimeMillis() + (20 * 1000);
-        if (!lockUtil.lock(projectDTO.getProjectId() + "_compute", String.valueOf(time))) {
-            // 获取不到锁,略过
-            return new AsyncResult<>("【监测指标数据计算线程】项目:" + projectDTO.getProjectId() + "被占用");
-        }
         try {
+            if (!lockUtil.lock(projectDTO.getProjectId() + "_compute", String.valueOf(time))) {
+                // 获取不到锁,略过
+                return new AsyncResult<>("【监测指标数据计算线程】项目:" + projectDTO.getProjectId() + "被占用");
+            }
+
             long start = System.currentTimeMillis();
             AsyncResult<String> projectDTO1 = computeProjectIndicatorData(projectDTO, projectIndicatorCompute);
             if (projectDTO1 != null) {
@@ -311,9 +308,9 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
     }
 
     private AsyncResult<String> computeProjectIndicatorData(ProjectDTO projectDTO, ProjectIndicatorCompute projectIndicatorCompute) throws Exception {
-        Object hget = redisUtil.hget(RedisUtil.TargetComputeTime, projectDTO.getProjectId());
-        if (hget != null && projectIndicatorCompute != null
-                && projectIndicatorCompute.getComputeRound() < Long.parseLong(hget.toString())) {
+        Object redisComputeRound = redisUtil.hget(RedisUtil.TargetComputeTime, projectDTO.getProjectId());
+        if (redisComputeRound != null && projectIndicatorCompute != null
+                && projectIndicatorCompute.getComputeRound() < Long.parseLong(redisComputeRound.toString())) {
             return new AsyncResult<>("【监测指标数据计算线程】当前项目:" + projectDTO.getProjectId() + "被占用");
         }
         //通过报警服务查询报警配置
@@ -438,11 +435,12 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
     @Async("asyncSendDataExecutor")
     public Future<String> sendIndicatorData(ProjectDTO projectDTO, CountDownLatch latch) throws Exception {
         long time = System.currentTimeMillis() + (20 * 1000);
-        if (!lockUtil.lock(projectDTO.getProjectId() + "_sendData", String.valueOf(time))) {
-            // 获取不到锁,略过
-            return new AsyncResult<>("【监测指标数据计算线程】:项目:" + projectDTO.getProjectId() + "被占用");
-        }
         try {
+            if (!lockUtil.lock(projectDTO.getProjectId() + "_sendData", String.valueOf(time))) {
+                // 获取不到锁,略过
+                return new AsyncResult<>("【监测指标数据计算线程】:项目:" + projectDTO.getProjectId() + "被占用");
+            }
+
             long start = System.currentTimeMillis();
             sendIndicatorDataToAlarmServer(projectDTO);
             long end = System.currentTimeMillis();
@@ -498,6 +496,7 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
         List<AlarmConfigItem> configItemList = getAlarmConfigItemList(projectDTO.getProjectId());
         if (CollectionUtils.isEmpty(configItemList)) {
             log.error("【发送监测指标数据线程】当前项目:" + projectDTO.getProjectId() + "为查询到报警条件");
+            return;
         }
 
         for (AlarmConfigItem alarmConfigItem : configItemList) {
@@ -582,8 +581,6 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
     private ConfigItemDataSendTimeDTO getConfigItemSendTimeDTO(ProjectDTO projectDTO, AlarmConfigItem alarmConfigItem) throws Exception {
         ConfigItemDataSendTimeDTO sendTimeDTO = (ConfigItemDataSendTimeDTO) redisUtil.hget(RedisUtil.PROJECT_ITEM_SEND_TIME + ":" + projectDTO.getProjectId(), alarmConfigItem.getId());
         if (sendTimeDTO == null) {
-            //第一次发送
-//            sendTimeDTO = ConfigItemDataSendTimeDTO.builder().objId(alarmConfigItem.getObjId()).configItemid(alarmConfigItem.getId()).lastSendTime(DateUtils.getStartTimeOfDay(new Date())).build();
             sendTimeDTO = ConfigItemDataSendTimeDTO.builder().objId(alarmConfigItem.getObjId()).configItemid(alarmConfigItem.getId()).lastSendTime(getDefultStartTime()).build();
         }
         return sendTimeDTO;

+ 4 - 21
src/main/java/com/persagy/apm/diagnose/service/ComputeIndicatorDataService.java

@@ -1,13 +1,9 @@
 package com.persagy.apm.diagnose.service;
 
 import com.persagy.apm.diagnose.indicatorcompute.model.ProjectIndicatorCompute;
-import com.persagy.apm.diagnose.indicatorcompute.model.dto.QueryProjectIndicatorComputeDTO;
 import com.persagy.apm.diagnose.indicatorcompute.service.IProjectIndicatorComputeService;
 import com.persagy.apm.diagnose.indicatorrecord.service.IMonitorIndicatorRecordService;
 import com.persagy.apm.diagnose.service.dto.ProjectDTO;
-import com.persagy.apm.diagnose.timerecord.model.CalculateTimeRecord;
-import com.persagy.apm.diagnose.timerecord.model.dto.QueryCalculateTimeRecordDTO;
-import com.persagy.apm.diagnose.timerecord.service.ICalculateTimeRecordService;
 import com.persagy.apm.diagnose.utils.CommonUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -19,8 +15,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.Future;
-import java.util.function.Function;
-import java.util.stream.Collectors;
 
 /**
  * @author leifeng
@@ -39,14 +33,12 @@ public class ComputeIndicatorDataService {
     @Autowired
     private IMonitorIndicatorRecordService monitorIndicatorRecordService;
 
-    @Autowired
-    private ICalculateTimeRecordService calculateTimeRecordService;
+
     @Autowired
     private IProjectIndicatorComputeService projectIndicatorComputeService;
 
 
     /**
-     * @throws
      * @title computeIndicatorData
      * @description 计算指标数据
      * @author leifeng
@@ -61,14 +53,9 @@ public class ComputeIndicatorDataService {
         Map<String, ProjectIndicatorCompute> projectIdAndProjectCompute = projectIndicatorComputeService.getProjectIdAndProjectCompute();
 
         List<Future<String>> futureList = new ArrayList<>();
-//        CountDownLatch latch = new CountDownLatch(projectDTOList.size());
-        CountDownLatch latch = new CountDownLatch(1);
+        CountDownLatch latch = new CountDownLatch(projectDTOList.size());
         for (ProjectDTO projectDTO : projectDTOList) {
-            if (!projectDTO.getProjectId().equals("Pj1101060001")) {
-                continue;
-            }
-            Future<String> stringFuture = monitorIndicatorRecordService.computeIndicatorData(projectDTO, projectIdAndProjectCompute.get(projectDTO.getProjectId()), latch);
-            futureList.add(stringFuture);
+            futureList.add(monitorIndicatorRecordService.computeIndicatorData(projectDTO, projectIdAndProjectCompute.get(projectDTO.getProjectId()), latch));
         }
         //等待所有任务执行完
         latch.await();
@@ -88,12 +75,8 @@ public class ComputeIndicatorDataService {
             return;
         }
         List<Future<String>> futureList = new ArrayList<>();
-//        CountDownLatch latch = new CountDownLatch(projectDTOList.size());
-        CountDownLatch latch = new CountDownLatch(1);
+        CountDownLatch latch = new CountDownLatch(projectDTOList.size());
         for (ProjectDTO projectDTO : projectDTOList) {
-            if (!projectDTO.getProjectId().equals("Pj1101060001")) {
-                continue;
-            }
             futureList.add(monitorIndicatorRecordService.sendIndicatorData(projectDTO, latch));
         }
         //等待所有任务执行完

+ 0 - 3
src/main/resources/bootstrap.yml

@@ -54,6 +54,3 @@ dmp:
     routingKey: routing-dmp-alarm     #报警定义变化路由键
     queue: eq-run-diagnose-alarm-queue              #中控订阅报警定义变化队列
 
-group:
-  alarm:
-    port: 9986