Browse Source

修复数据更新

kobe6258 2 months ago
parent
commit
85a6ec86f7

+ 1 - 3
qhtx-eta-integrator/qhtx-integrator-domain/src/main/java/com/qhtx/eta/domain/convert/DWIndexWithLinkCodeDTOConverter.java

@@ -1,11 +1,9 @@
 package com.qhtx.eta.domain.convert;
 
 import com.qhtx.eta.domain.entity.DWIndexWithLinkCodeDTO;
-import com.qhtx.eta.infra.entity.TEtaIndexMapping;
-import com.qhtx.eta.infra.entity.dw.DWIndex;
+import com.qhtx.eta.infra.entity.dw.TEtaIndexMapping;
 import com.qhtx.eta.infra.entity.dw.TDampDwIndex;
 import com.qhtx.eta.infra.entity.dw.TDampDwIndexLink;
-import com.qhtx.eta.infra.entity.dw.TDampDwLinkData;
 import org.mapstruct.Mapper;
 import org.mapstruct.factory.Mappers;
 

+ 1 - 2
qhtx-eta-integrator/qhtx-integrator-domain/src/main/java/com/qhtx/eta/domain/job/ETASyncJob.java

@@ -25,7 +25,7 @@ import com.qhtx.eta.domain.task.FixedDelayTaskRegistrar;
 import com.qhtx.eta.domain.task.SchedulingRunnable;
 import com.qhtx.eta.domain.utils.RedisUtils;
 import com.qhtx.eta.infra.datasource.DataSourceContextHolder;
-import com.qhtx.eta.infra.entity.TEtaIndexMapping;
+import com.qhtx.eta.infra.entity.dw.TEtaIndexMapping;
 import com.qhtx.eta.infra.entity.dw.*;
 import com.qhtx.eta.infra.enums.Frequency;
 import lombok.extern.slf4j.Slf4j;
@@ -366,7 +366,6 @@ public class ETASyncJob implements CommandLineRunner {
                                     @Override
                                     @Transactional(rollbackFor = Exception.class)
                                     protected void doInTransactionWithoutResult(@NotNull TransactionStatus status) {
-
                                         //将指标写入映射表
                                         etaIndexService.insert(etaIndexMapping);
                                         //现插入指标

+ 1 - 1
qhtx-eta-integrator/qhtx-integrator-domain/src/main/java/com/qhtx/eta/domain/service/ETAIndexService.java

@@ -1,6 +1,6 @@
 package com.qhtx.eta.domain.service;
 
-import com.qhtx.eta.infra.entity.TEtaIndexMapping;
+import com.qhtx.eta.infra.entity.dw.TEtaIndexMapping;
 
 public interface ETAIndexService {
     void insert(TEtaIndexMapping etaIndexMapping);

+ 14 - 8
qhtx-eta-integrator/qhtx-integrator-domain/src/main/java/com/qhtx/eta/domain/service/impl/DWIndexFrameServiceImpl.java

@@ -14,15 +14,15 @@ import com.qhtx.eta.domain.entity.DWIndexFrameDTO;
 import com.qhtx.eta.domain.entity.DWIndexWithLinkCodeDTO;
 import com.qhtx.eta.domain.service.DWIndexFrameService;
 import com.qhtx.eta.domain.utils.RedisUtils;
-import com.qhtx.eta.infra.annotation.UseDataSource;
 import com.qhtx.eta.infra.datasource.DataSourceContextHolder;
+import com.qhtx.eta.infra.entity.dw.TEtaIndexMapping;
 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;
 import org.jetbrains.annotations.NotNull;
+import org.mapstruct.ap.internal.util.Strings;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.TransactionStatus;
 import org.springframework.transaction.support.TransactionCallbackWithoutResult;
@@ -34,7 +34,6 @@ import java.text.SimpleDateFormat;
 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;
@@ -69,6 +68,8 @@ public class DWIndexFrameServiceImpl implements DWIndexFrameService {
     @Resource
     private TDampDwLinkDetailService tDampDwLinkDetailService;
 
+    @Resource
+    private TEtaIndexMappingService tEtaIndexMappingService;
     @Resource
     private TDampDwIndexService tDampDwIndexService;
     @Resource(name = "IndexDataThreadPool")
@@ -253,15 +254,20 @@ public class DWIndexFrameServiceImpl implements DWIndexFrameService {
             return;
         }
         //获取对接码的指标信息
-        List<TDampDwIndexLink> linkInfoList = tDampDwIndexLinkService.getLinkInfoByCode(dwIndex.getLinkCode());
-        if (linkInfoList == null || linkInfoList.isEmpty()) {
-            log.warn("对接码信息不存在,linkCode:{}", dwIndex.getLinkCode());
+//        List<TDampDwIndexLink> linkInfoList = tDampDwIndexLinkService.getLinkInfoByCode(dwIndex.getLinkCode());
+//        if (linkInfoList == null || linkInfoList.isEmpty()) {
+//            log.warn("对接码信息不存在,linkCode:{}", dwIndex.getLinkCode());
+//            return;
+//        }
+        TEtaIndexMapping mapping = tEtaIndexMappingService.queryByLinkCode(dwIndex.getLinkCode());
+        if (mapping == null || Strings.isEmpty(mapping.getIndexCode())) {
+            log.warn("对接码关联指标信息不存在,linkCode:{}", dwIndex.getLinkCode());
             return;
         }
         //根据指标名称过滤指标
         TDampDwIndex updateDwIndex = new TDampDwIndex();
-//        updateDwIndex.setIndexCode(linkInfo.getIndexCode());
-//        updateDwIndex.setFrameId(dwIndex.getFrameId());
+        updateDwIndex.setIndexCode(mapping.getIndexCode());
+        updateDwIndex.setFrameId(dwIndex.getFrameId());
         tDampDwIndexService.updateIndexInfo(updateDwIndex);
     }
 

+ 9 - 2
qhtx-eta-integrator/qhtx-integrator-domain/src/main/java/com/qhtx/eta/domain/service/impl/ETAIndexServiceImpl.java

@@ -1,15 +1,22 @@
 package com.qhtx.eta.domain.service.impl;
 
 import com.qhtx.eta.domain.service.ETAIndexService;
-import com.qhtx.eta.infra.entity.TEtaIndexMapping;
+import com.qhtx.eta.infra.entity.dw.TEtaIndexMapping;
+import com.qhtx.eta.infra.service.TEtaIndexMappingService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
+
 @Service
 @Slf4j
 public class ETAIndexServiceImpl implements ETAIndexService {
+
+    @Resource
+    private TEtaIndexMappingService tetaIndexMappingService;
+
     @Override
     public void insert(TEtaIndexMapping etaIndexMapping) {
-
+        tetaIndexMappingService.insert(etaIndexMapping);
     }
 }

+ 1 - 3
qhtx-eta-integrator/qhtx-integrator-infra/src/main/java/com/qhtx/eta/infra/entity/TEtaIndexMapping.java → qhtx-eta-integrator/qhtx-integrator-infra/src/main/java/com/qhtx/eta/infra/entity/dw/TEtaIndexMapping.java

@@ -1,4 +1,4 @@
-package com.qhtx.eta.infra.entity;
+package com.qhtx.eta.infra.entity.dw;
 
 import lombok.Data;
 
@@ -14,8 +14,6 @@ import java.io.Serializable;
 public class TEtaIndexMapping implements Serializable {
     private static final long serialVersionUID = 645472649937080427L;
 
-    private Integer id;
-
     private String indexCode;
 
     private String linkCode;

+ 4 - 4
qhtx-eta-integrator/qhtx-integrator-infra/src/main/java/com/qhtx/eta/infra/mapper/TEtaIndexMappingDao.java

@@ -1,6 +1,7 @@
 package com.qhtx.eta.infra.mapper;
 
-import com.qhtx.eta.infra.entity.TEtaIndexMapping;
+import com.qhtx.eta.infra.entity.dw.TEtaIndexMapping;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * (TEtaIndexMapping)表数据库访问层
@@ -19,7 +20,6 @@ public interface TEtaIndexMappingDao {
     TEtaIndexMapping queryById(Integer id);
 
 
-
     /**
      * 统计总行数
      *
@@ -34,8 +34,7 @@ public interface TEtaIndexMappingDao {
      * @param tEtaIndexMapping 实例对象
      * @return 影响行数
      */
-    int insert(TEtaIndexMapping tEtaIndexMapping);
-
+    int insert(@Param("entity") TEtaIndexMapping tEtaIndexMapping);
 
 
     /**
@@ -54,5 +53,6 @@ public interface TEtaIndexMappingDao {
      */
     int deleteById(Integer id);
 
+    TEtaIndexMapping queryByLinkCode(@Param("linkCode") String linkCode);
 }
 

+ 3 - 19
qhtx-eta-integrator/qhtx-integrator-infra/src/main/java/com/qhtx/eta/infra/service/TEtaIndexMappingService.java

@@ -1,6 +1,6 @@
 package com.qhtx.eta.infra.service;
 
-import com.qhtx.eta.infra.entity.TEtaIndexMapping;
+import com.qhtx.eta.infra.entity.dw.TEtaIndexMapping;
 
 /**
  * (TEtaIndexMapping)表服务接口
@@ -10,31 +10,14 @@ import com.qhtx.eta.infra.entity.TEtaIndexMapping;
  */
 public interface TEtaIndexMappingService {
 
-    /**
-     * 通过ID查询单条数据
-     *
-     * @param id 主键
-     * @return 实例对象
-     */
-    TEtaIndexMapping queryById(Integer id);
-
-
 
     /**
      * 新增数据
      *
      * @param tEtaIndexMapping 实例对象
-     * @return 实例对象
      */
-    TEtaIndexMapping insert(TEtaIndexMapping tEtaIndexMapping);
+    void insert(TEtaIndexMapping tEtaIndexMapping);
 
-    /**
-     * 修改数据
-     *
-     * @param tEtaIndexMapping 实例对象
-     * @return 实例对象
-     */
-    TEtaIndexMapping update(TEtaIndexMapping tEtaIndexMapping);
 
     /**
      * 通过主键删除数据
@@ -44,4 +27,5 @@ public interface TEtaIndexMappingService {
      */
     boolean deleteById(Integer id);
 
+    TEtaIndexMapping queryByLinkCode(String linkCode);
 }

+ 13 - 27
qhtx-eta-integrator/qhtx-integrator-infra/src/main/java/com/qhtx/eta/infra/service/impl/TEtaIndexMappingServiceImpl.java

@@ -1,8 +1,11 @@
 package com.qhtx.eta.infra.service.impl;
 
+import com.qhtx.eta.common.eunms.DataSourceType;
+import com.qhtx.eta.infra.annotation.UseDataSource;
 import com.qhtx.eta.infra.mapper.TEtaIndexMappingDao;
-import com.qhtx.eta.infra.entity.TEtaIndexMapping;
+import com.qhtx.eta.infra.entity.dw.TEtaIndexMapping;
 import com.qhtx.eta.infra.service.TEtaIndexMappingService;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
@@ -14,22 +17,12 @@ import javax.annotation.Resource;
  * @since 2025-01-14 10:32:26
  */
 @Service("tEtaIndexMappingService")
+@UseDataSource(dataSourceType = DataSourceType.DW)
+@Slf4j
 public class TEtaIndexMappingServiceImpl implements TEtaIndexMappingService {
     @Resource
     private TEtaIndexMappingDao tEtaIndexMappingDao;
 
-    /**
-     * 通过ID查询单条数据
-     *
-     * @param id 主键
-     * @return 实例对象
-     */
-    @Override
-    public TEtaIndexMapping queryById(Integer id) {
-        return this.tEtaIndexMappingDao.queryById(id);
-    }
-
-
     /**
      * 新增数据
      *
@@ -37,22 +30,10 @@ public class TEtaIndexMappingServiceImpl implements TEtaIndexMappingService {
      * @return 实例对象
      */
     @Override
-    public TEtaIndexMapping insert(TEtaIndexMapping tEtaIndexMapping) {
-        this.tEtaIndexMappingDao.insert(tEtaIndexMapping);
-        return tEtaIndexMapping;
+    public void insert(TEtaIndexMapping tEtaIndexMapping) {
+        tEtaIndexMappingDao.insert(tEtaIndexMapping);
     }
 
-    /**
-     * 修改数据
-     *
-     * @param tEtaIndexMapping 实例对象
-     * @return 实例对象
-     */
-    @Override
-    public TEtaIndexMapping update(TEtaIndexMapping tEtaIndexMapping) {
-        this.tEtaIndexMappingDao.update(tEtaIndexMapping);
-        return this.queryById(tEtaIndexMapping.getId());
-    }
 
     /**
      * 通过主键删除数据
@@ -64,4 +45,9 @@ public class TEtaIndexMappingServiceImpl implements TEtaIndexMappingService {
     public boolean deleteById(Integer id) {
         return this.tEtaIndexMappingDao.deleteById(id) > 0;
     }
+
+    @Override
+    public TEtaIndexMapping queryByLinkCode(String linkCode) {
+        return tEtaIndexMappingDao.queryByLinkCode(linkCode);
+    }
 }

+ 1 - 3
qhtx-eta-integrator/qhtx-integrator-infra/src/main/resources/mapper/TDampDwIndexDao.xml

@@ -79,9 +79,7 @@
     <update id="updateIndexInfo">
         update T_DAMP_DW_INDEX
         <set>
-            <if test="entity.frameId != null and entity.frameId != '' and ">
-                FRAME_ID = #{entity.frameId,jdbcType=VARCHAR}
-            </if>
+            FRAME_ID = #{entity.frameId,jdbcType=VARCHAR}
         </set>
         where INDEX_CODE = #{entity.indexCode,jdbcType=VARCHAR}
     </update>

+ 18 - 11
qhtx-eta-integrator/qhtx-integrator-infra/src/main/resources/mapper/TEtaIndexMappingDao.xml

@@ -2,7 +2,7 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.qhtx.eta.infra.mapper.TEtaIndexMappingDao">
 
-    <resultMap type="com.qhtx.eta.infra.entity.TEtaIndexMapping" id="TEtaIndexMappingMap">
+    <resultMap type="com.qhtx.eta.infra.entity.dw.TEtaIndexMapping" id="TEtaIndexMappingMap">
         <result property="id" column="ID" jdbcType="INTEGER"/>
         <result property="indexCode" column="INDEX_CODE" jdbcType="VARCHAR"/>
         <result property="etaEdbCode" column="ETA_EDB_CODE" jdbcType="VARCHAR"/>
@@ -10,15 +10,20 @@
 
     <!--查询单个-->
     <select id="queryById" resultMap="TEtaIndexMappingMap">
-        select IDINDEX_CODEETA_EDB_CODE
+        select INDEX_CODE, LINK_CODE
         from T_ETA_INDEX_MAPPING
         where ID = #{id}
     </select>
+    <select id="queryByLinkCode" resultMap="TEtaIndexMappingMap">
+        select INDEX_CODE, LINK_CODE
+        from T_ETA_INDEX_MAPPING
+        where LINK_CODE = #{linkCode}
+    </select>
 
     <!--查询指定行数据-->
     <select id="queryAllByLimit" resultMap="TEtaIndexMappingMap">
         select
-        IDINDEX_CODEETA_EDB_CODE
+        INDEX_CODE, LINK_CODE
         from T_ETA_INDEX_MAPPING
         <where>
             <if test="id != null">
@@ -52,27 +57,27 @@
     </select>
 
     <!--新增所有列-->
-    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
-        insert into T_ETA_INDEX_MAPPING(INDEX_CODEETA_EDB_CODE)
-        values (#{indexCode}#{etaEdbCode})
+    <insert id="insert" keyProperty="id" useGeneratedKeys="false">
+        insert into T_ETA_INDEX_MAPPING (INDEX_CODE, LINK_CODE)
+        values (#{entity.indexCode}, #{entity.linkCode})
     </insert>
 
     <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
-        insert into T_ETA_INDEX_MAPPING(INDEX_CODEETA_EDB_CODE)
+        insert into T_ETA_INDEX_MAPPING(INDEX_CODE, LINK_CODE)
         values
         <foreach collection="entities" item="entity" separator=",">
-        (#{entity.indexCode}#{entity.etaEdbCode})
+            (#{entity.indexCode},#{entity.linkCode})
         </foreach>
     </insert>
 
     <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
-        insert into T_ETA_INDEX_MAPPING(INDEX_CODEETA_EDB_CODE)
+        insert into T_ETA_INDEX_MAPPING(INDEX_CODE, LINK_CODE)
         values
         <foreach collection="entities" item="entity" separator=",">
             (#{entity.indexCode}#{entity.etaEdbCode})
         </foreach>
         on duplicate key update
-INDEX_CODE = values(INDEX_CODE)ETA_EDB_CODE = values(ETA_EDB_CODE)
+        INDEX_CODE = values(INDEX_CODE)ETA_EDB_CODE = values(ETA_EDB_CODE)
     </insert>
 
     <!--通过主键修改数据-->
@@ -91,7 +96,9 @@ INDEX_CODE = values(INDEX_CODE)ETA_EDB_CODE = values(ETA_EDB_CODE)
 
     <!--通过主键删除-->
     <delete id="deleteById">
-        delete from T_ETA_INDEX_MAPPING where ID = #{id}
+        delete
+        from T_ETA_INDEX_MAPPING
+        where ID = #{id}
     </delete>
 
 </mapper>

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

@@ -111,4 +111,20 @@ WHERE INDEX_CODE IN (
     FROM T_DAMP_DW_INDEX_LINK
     WHERE LINK_CODE LIKE 'ETA%'
 )
-  AND FREQUENCY LIKE '%度%';
+  AND FREQUENCY LIKE '%度%';
+
+
+
+/*
+ * 辅助表,用于建立指标与对接码之间的映射关系
+ */
+CREATE SEQUENCE SEQ_ETA_INDEX_MAPPING
+    START WITH 1
+    INCREMENT BY 1
+    NOMAXVALUE;
+CREATE OR REPLACE TRIGGER TRG_SEQ_ETA_INDEX_INSERT
+                               BEFORE INSERT ON T_ETA_INDEX_MAPPING
+                                          FOR EACH ROW
+BEGIN
+SELECT SEQ_ETA_INDEX_MAPPING.NEXTVAL INTO :new.id FROM dual;
+END;