Przeglądaj źródła

feat(indicator): 实体/Mapper 支持统一指标层(cols/新表/幂等upsert)

iwt 3 dni temu
rodzic
commit
3e062d44c9

+ 35 - 0
cfc-backend/src/main/java/com/etotem/cfc/entity/IndicatorCorrelation.java

@@ -0,0 +1,35 @@
+package com.etotem.cfc.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+@Data
+@TableName("indicator_correlations")
+public class IndicatorCorrelation {
+    @TableId(type = IdType.AUTO)
+    private Long id;
+    private Long definitionIdA;
+    private Long definitionIdB;
+    private String relationType;
+    private String direction;
+    private BigDecimal manualStrength;
+    private BigDecimal computedStrength;
+    private String method;
+    private Integer sampleSize;
+    private String confidence;
+    private BigDecimal effectiveStrength;
+    private Integer manualLocked;
+    private String cohortScope;
+    private String status;
+    private Date computedAt;
+    private Long createdBy;
+    private String description;
+    private String sourceNote;
+    private Date createdAt;
+    private Date updatedAt;
+}

+ 15 - 0
cfc-backend/src/main/java/com/etotem/cfc/entity/IndicatorDefinition.java

@@ -19,6 +19,11 @@ public class IndicatorDefinition {
     private String refRange;
     private Integer sortOrder;
     private Integer status;
+    private String sourceKind;
+    private String reportTypeScope;
+    private String valueType;
+    private String goodDirection;
+    private String dimensionCode;
     private Date createdAt;
     private Date updatedAt;
 
@@ -44,6 +49,16 @@ public class IndicatorDefinition {
     public void setSortOrder(Integer sortOrder) { this.sortOrder = sortOrder; }
     public Integer getStatus() { return status; }
     public void setStatus(Integer status) { this.status = status; }
+    public String getSourceKind() { return sourceKind; }
+    public void setSourceKind(String sourceKind) { this.sourceKind = sourceKind; }
+    public String getReportTypeScope() { return reportTypeScope; }
+    public void setReportTypeScope(String reportTypeScope) { this.reportTypeScope = reportTypeScope; }
+    public String getValueType() { return valueType; }
+    public void setValueType(String valueType) { this.valueType = valueType; }
+    public String getGoodDirection() { return goodDirection; }
+    public void setGoodDirection(String goodDirection) { this.goodDirection = goodDirection; }
+    public String getDimensionCode() { return dimensionCode; }
+    public void setDimensionCode(String dimensionCode) { this.dimensionCode = dimensionCode; }
     public Date getCreatedAt() { return createdAt; }
     public void setCreatedAt(Date createdAt) { this.createdAt = createdAt; }
     public Date getUpdatedAt() { return updatedAt; }

+ 24 - 0
cfc-backend/src/main/java/com/etotem/cfc/entity/IndicatorMappingRule.java

@@ -0,0 +1,24 @@
+package com.etotem.cfc.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+@TableName("indicator_mapping_rules")
+public class IndicatorMappingRule {
+    @TableId(type = IdType.AUTO)
+    private Long id;
+    private String sourceType;
+    private String rawName;
+    private String aliasText;
+    private Long definitionId;
+    private String matchType;
+    private Integer priority;
+    private Integer status;
+    private Date createdAt;
+    private Date updatedAt;
+}

+ 18 - 0
cfc-backend/src/main/java/com/etotem/cfc/entity/IndicatorValue.java

@@ -16,6 +16,12 @@ public class IndicatorValue {
     private String value;
     private BigDecimal numericValue;
     private String remark;
+    private Long subjectId;
+    private Long familyId;
+    private Long reportId;
+    private java.sql.Date reportDate;
+    private String unit;
+    private String status;
     private Date recordedAt;
 
     public Long getId() { return id; }
@@ -32,6 +38,18 @@ public class IndicatorValue {
     public void setNumericValue(BigDecimal numericValue) { this.numericValue = numericValue; }
     public String getRemark() { return remark; }
     public void setRemark(String remark) { this.remark = remark; }
+    public Long getSubjectId() { return subjectId; }
+    public void setSubjectId(Long subjectId) { this.subjectId = subjectId; }
+    public Long getFamilyId() { return familyId; }
+    public void setFamilyId(Long familyId) { this.familyId = familyId; }
+    public Long getReportId() { return reportId; }
+    public void setReportId(Long reportId) { this.reportId = reportId; }
+    public java.sql.Date getReportDate() { return reportDate; }
+    public void setReportDate(java.sql.Date reportDate) { this.reportDate = reportDate; }
+    public String getUnit() { return unit; }
+    public void setUnit(String unit) { this.unit = unit; }
+    public String getStatus() { return status; }
+    public void setStatus(String status) { this.status = status; }
     public Date getRecordedAt() { return recordedAt; }
     public void setRecordedAt(Date recordedAt) { this.recordedAt = recordedAt; }
 }

+ 7 - 0
cfc-backend/src/main/java/com/etotem/cfc/mapper/IndicatorCorrelationMapper.java

@@ -0,0 +1,7 @@
+package com.etotem.cfc.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.etotem.cfc.entity.IndicatorCorrelation;
+
+public interface IndicatorCorrelationMapper extends BaseMapper<IndicatorCorrelation> {
+}

+ 7 - 0
cfc-backend/src/main/java/com/etotem/cfc/mapper/IndicatorMappingRuleMapper.java

@@ -0,0 +1,7 @@
+package com.etotem.cfc.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.etotem.cfc.entity.IndicatorMappingRule;
+
+public interface IndicatorMappingRuleMapper extends BaseMapper<IndicatorMappingRule> {
+}

+ 14 - 2
cfc-backend/src/main/java/com/etotem/cfc/mapper/IndicatorValueMapper.java

@@ -2,8 +2,20 @@ package com.etotem.cfc.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.etotem.cfc.entity.IndicatorValue;
-import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Insert;
+import org.apache.ibatis.annotations.Param;
 
-@Mapper
 public interface IndicatorValueMapper extends BaseMapper<IndicatorValue> {
+
+    /** 幂等写:同 (source_type, source_id, definition_id) 覆盖更新(uk_source_definition) */
+    @Insert("INSERT INTO indicator_values " +
+            "(source_type, source_id, definition_id, value, numeric_value, remark, " +
+            " subject_id, family_id, report_id, report_date, unit, status, recorded_at) " +
+            "VALUES (#{v.sourceType}, #{v.sourceId}, #{v.definitionId}, #{v.value}, #{v.numericValue}, #{v.remark}, " +
+            " #{v.subjectId}, #{v.familyId}, #{v.reportId}, #{v.reportDate}, #{v.unit}, #{v.status}, NOW()) " +
+            "ON DUPLICATE KEY UPDATE " +
+            " value = VALUES(value), numeric_value = VALUES(numeric_value), remark = VALUES(remark), " +
+            " subject_id = VALUES(subject_id), family_id = VALUES(family_id), report_id = VALUES(report_id), " +
+            " report_date = VALUES(report_date), unit = VALUES(unit), status = VALUES(status), recorded_at = NOW()")
+    int upsertMapping(@Param("v") IndicatorValue v);
 }

+ 30 - 0
cfc-backend/src/test/java/com/etotem/cfc/service/IndicatorValueMapperTest.java

@@ -0,0 +1,30 @@
+package com.etotem.cfc.service;
+
+import com.etotem.cfc.entity.IndicatorValue;
+import com.etotem.cfc.mapper.IndicatorValueMapper;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+import java.math.BigDecimal;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
+/** IndicatorValueMapper.upsertMapping 仅做 SQL 注解绑定验证(mock 层) */
+class IndicatorValueMapperTest {
+
+    @Test
+    void upsertMappingAnnotationCompiles() {
+        IndicatorValueMapper mapper = Mockito.mock(IndicatorValueMapper.class);
+        IndicatorValue v = new IndicatorValue();
+        v.setSourceType("gut_flora");
+        v.setSourceId(10L);
+        v.setDefinitionId(3L);
+        v.setValue("12.8");
+        v.setNumericValue(new BigDecimal("12.8"));
+        when(mapper.upsertMapping(any(IndicatorValue.class))).thenReturn(1);
+        int result = mapper.upsertMapping(v);
+        assertEquals(1, result);
+    }
+}