浏览代码

修复数据问题

kobe6258 1 天之前
父节点
当前提交
2a477da6c7

+ 2 - 0
qhtx-eta-integrator/qhtx-integrator-domain/src/main/java/com/qhtx/eta/domain/config/ETAConfigProperties.java

@@ -22,4 +22,6 @@ public class ETAConfigProperties {
      * 密钥
      */
     private String secretKey;
+
+    private String etaCategoryName;
 }

+ 19 - 11
qhtx-eta-integrator/qhtx-integrator-domain/src/main/java/com/qhtx/eta/domain/service/impl/DWIndexFrameServiceImpl.java

@@ -4,6 +4,7 @@ import com.alibaba.druid.util.StringUtils;
 import com.qhtx.eta.common.constant.ETAConstants;
 import com.qhtx.eta.common.eunms.ErrorEnum;
 import com.qhtx.eta.common.exception.ETAException;
+import com.qhtx.eta.domain.config.ETAConfigProperties;
 import com.qhtx.eta.domain.convert.DWIndexDTOConverter;
 import com.qhtx.eta.domain.convert.DWIndexDataDTOConverter;
 import com.qhtx.eta.domain.convert.DWIndexFrameDTOConverter;
@@ -15,6 +16,7 @@ import com.qhtx.eta.domain.utils.RedisUtils;
 import com.qhtx.eta.infra.datasource.DataSourceContextHolder;
 import com.qhtx.eta.infra.entity.dw.TDampDwLinkDetail;
 import com.qhtx.eta.infra.entity.dw.*;
+import com.qhtx.eta.infra.mapper.DWIndexFrameDao;
 import com.qhtx.eta.infra.service.*;
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
@@ -29,6 +31,7 @@ import javax.annotation.Resource;
 import java.util.*;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
 import com.qhtx.eta.common.eunms.DataSourceType;
@@ -37,6 +40,8 @@ import com.qhtx.eta.common.eunms.DataSourceType;
 @Slf4j
 public class DWIndexFrameServiceImpl implements DWIndexFrameService {
 
+    @Resource
+    private ETAConfigProperties etaConfigProperties;
     @Resource
     private RedisUtils redisUtils;
 
@@ -61,7 +66,8 @@ public class DWIndexFrameServiceImpl implements DWIndexFrameService {
     @Resource
     private TDampDwLinkDetailService tDampDwLinkDetailService;
 
-
+    @Resource
+    private DWIndexFrameDao dwIndexFrameDao;
     @Resource
     private TDampDwIndexService tDampDwIndexService;
     @Resource(name = "IndexDataThreadPool")
@@ -75,20 +81,22 @@ public class DWIndexFrameServiceImpl implements DWIndexFrameService {
     @Override
     public String generateTableCode() throws ETAException {
         if (!redisUtils.exist(ETAConstants.REDIS_INDEX_FRAME_TABLE_CODE_KEY)) {
-            throw new ETAException(ErrorEnum.DW_INDEX_TABLE_CODE_GET_ERROR);
-//            synchronized (this) {
-//                if (!redisUtils.exist(ETAConstants.REDIS_INDEX_FRAME_TABLE_CODE_KEY)) {
-//                    long currentTableCode = 100;
-//                    redisUtils.setNx(ETAConstants.REDIS_INDEX_FRAME_TABLE_CODE_KEY, currentTableCode, -1L, TimeUnit.SECONDS);
-//                }
-//            }
+            //   throw new ETAException(ErrorEnum.DW_INDEX_TABLE_CODE_GET_ERROR);
+            synchronized (this) {
+                if (!redisUtils.exist(ETAConstants.REDIS_INDEX_FRAME_TABLE_CODE_KEY)) {
+                    String maxTableCode = dwIndexFrameDao.getMaxTableCode();
+                    long maxData = maxTableCode == null ? 0L : Long.parseLong(maxTableCode.replaceAll(ETAConstants.INDEX_FRAME_TABLE_CODE_PREFIX, ""));
+                    redisUtils.setNX(ETAConstants.REDIS_INDEX_FRAME_TABLE_CODE_KEY, maxData);
+                }
+            }
         }
         return ETAConstants.INDEX_FRAME_TABLE_CODE_PREFIX + String.format("%07d", redisUtils.add(ETAConstants.REDIS_INDEX_FRAME_TABLE_CODE_KEY, 1L));
     }
 
     @Override
     public void processing(List<DWIndexFrameDTO> processList) {
-        DWIndexFrame hzIndexFrame = indexFrameService.getByCnName(ETAConstants.DW_INDEX_FRAME_PARENT_NAME);
+//        DWIndexFrame hzIndexFrame = indexFrameService.getByCnName(ETAConstants.DW_INDEX_FRAME_PARENT_NAME);
+        DWIndexFrame hzIndexFrame = indexFrameService.getByCnName(etaConfigProperties.getEtaCategoryName());
         if (hzIndexFrame == null) {
             log.info("未找到根节点,不同步eta指标目录");
             return;
@@ -248,9 +256,9 @@ public class DWIndexFrameServiceImpl implements DWIndexFrameService {
         }
         for (DWIndexFrameDTO dto : list) {
             if (Objects.equals(dto.getParentId(), node.getClassifyId())) {
-                String path = StringUtils.isEmpty(node.getPath().trim()) ? dto.getCnName() : node.getPath() + "|" + dto.getCnName();
+                String path = StringUtils.isEmpty(node.getPath().trim()) ? node.getName() + "|" + dto.getCnName() : node.getPath() + "|" + dto.getCnName();
                 String id = (dto.getId() == null || dto.getId().trim().isEmpty()) ? UUID.randomUUID().toString().replaceAll("-", "") : dto.getId();
-                String idPath = StringUtils.isEmpty(node.getPath().trim()) ? id : node.getIdPath() + "|" + id;
+                String idPath = StringUtils.isEmpty(node.getPath().trim()) ? node.getId() + "|" + id : node.getIdPath() + "|" + id;
                 FrameNode temp = new FrameNode();
                 temp.setId(id);
                 temp.setClassifyId(dto.getClassifyId());

+ 8 - 1
qhtx-eta-integrator/qhtx-integrator-domain/src/main/java/com/qhtx/eta/domain/utils/RedisUtils.java

@@ -53,10 +53,17 @@ public class RedisUtils {
     /**
      * set(带过期)
      */
-    public boolean setNx(String key, Object value, Long time, TimeUnit timeUnit) {
+    public boolean setNX(String key, Object value, Long time, TimeUnit timeUnit) {
         return redisTemplate.opsForValue().setIfAbsent(key, value, time, timeUnit);
     }
 
+    /**
+     * set(带过期)
+     */
+    public boolean setNX(String key, Object value) {
+        return redisTemplate.opsForValue().setIfAbsent(key, value);
+    }
+
     /**
      * 获取string类型缓存
      */

+ 1 - 1
qhtx-eta-integrator/qhtx-integrator-infra/src/main/java/com/qhtx/eta/infra/mapper/DWIndexFrameDao.java

@@ -11,7 +11,7 @@ public interface DWIndexFrameDao {
     void insertOrUpdate(@Param("item") DWIndexFrame dwIndexFrame);
 
 
-    long getMaxTableCode();
+    String getMaxTableCode();
 
     DWIndexFrame getByCnName(String cnName);
 }

+ 1 - 1
qhtx-eta-integrator/qhtx-integrator-infra/src/main/java/com/qhtx/eta/infra/service/IndexFrameService.java

@@ -7,7 +7,7 @@ import java.util.List;
 
 public interface IndexFrameService {
 
-    long getMaxTableCode();
+    String getMaxTableCode();
 
     DWIndexFrame getByCnName(String cnName);
 

+ 1 - 1
qhtx-eta-integrator/qhtx-integrator-infra/src/main/java/com/qhtx/eta/infra/service/impl/IndexFrameServiceImpl.java

@@ -24,7 +24,7 @@ public class IndexFrameServiceImpl implements IndexFrameService {
     private DWIndexDao dwIndexDao;
 
     @Override
-    public long getMaxTableCode() {
+    public String getMaxTableCode() {
         return dwIndexFrameDao.getMaxTableCode();
     }
 

+ 1 - 3
qhtx-eta-integrator/sql/init.sql

@@ -84,13 +84,11 @@ CREATE SEQUENCE SEQ_ETA_CLASSIFY_INDEX_MAPPING
     START WITH 1
     INCREMENT BY 1
     NOMAXVALUE;
-
 CREATE OR REPLACE TRIGGER trg_SEQ_ETA_CLASSIFY_insert
-                               BEFORE INSERT ON t_eta_CLASSIFY_INDEX_MAPPING
+                               BEFORE INSERT ON t_eta_CLASSIFY_INDEX_MAPPINGr
                                           FOR EACH ROW
 BEGIN
 SELECT SEQ_ETA_CLASSIFY_INDEX_MAPPING.NEXTVAL INTO :new.id FROM dual;
 END;
 
 
-