Преглед изворни кода

Merge remote-tracking branch 'origin/jiapu_aijiuyi' into jiapu_aijiuyi

liyuliangjiazai пре 5 месеци
родитељ
комит
15fce22cc3

+ 150 - 19
code/backend/src/main/java/com/aijiuyi/admin/common/config/PlanDataInitializer.java

@@ -1,7 +1,9 @@
 package com.aijiuyi.admin.common.config;
 
+import com.aijiuyi.admin.entity.Acupoint;
 import com.aijiuyi.admin.entity.Plan;
 import com.aijiuyi.admin.entity.PlanStep;
+import com.aijiuyi.admin.mapper.AcupointMapper;
 import com.aijiuyi.admin.mapper.PlanMapper;
 import com.aijiuyi.admin.mapper.PlanStepMapper;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -9,6 +11,7 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.CommandLineRunner;
 import org.springframework.stereotype.Component;
+import org.springframework.util.StringUtils;
 
 import java.math.BigDecimal;
 import java.util.ArrayList;
@@ -27,10 +30,14 @@ public class PlanDataInitializer implements CommandLineRunner {
     @Autowired
     private PlanStepMapper planStepMapper;
 
+    @Autowired
+    private AcupointMapper acupointMapper;
+
     @Override
     public void run(String... args) {
         List<PlanSeed> seeds = buildSeeds();
         for (PlanSeed seed : seeds) {
+            boolean created = false;
             Plan plan = planMapper.selectOne(new LambdaQueryWrapper<Plan>()
                     .eq(Plan::getPlanCode, seed.planCode)
                     .last("limit 1"));
@@ -46,32 +53,156 @@ public class PlanDataInitializer implements CommandLineRunner {
                 plan.setUseCount(0);
                 fillPlan(plan, seed);
                 planMapper.insert(plan);
+                created = true;
             } else {
-                fillPlan(plan, seed);
-                planMapper.updateById(plan);
+                if (fillMissingPlanFields(plan, seed)) {
+                    planMapper.updateById(plan);
+                }
             }
 
-            planStepMapper.delete(new LambdaUpdateWrapper<PlanStep>()
-                    .eq(PlanStep::getPlanId, plan.getId()));
-
-            for (int i = 0; i < seed.steps.size(); i++) {
-                StepSeed stepSeed = seed.steps.get(i);
-                PlanStep step = new PlanStep();
-                step.setPlanId(plan.getId());
-                step.setStepOrder(i + 1);
-                step.setAcupointId(stepSeed.acupointId);
-                step.setAcupointName(stepSeed.acupointName);
-                step.setSide(stepSeed.side);
-                step.setTemperature(stepSeed.temperature);
-                step.setDuration(stepSeed.duration);
-                step.setTechniqueId(stepSeed.techniqueId);
-                step.setTechniqueName(stepSeed.techniqueName);
-                step.setRemark(stepSeed.remark);
-                planStepMapper.insert(step);
+            if (created || hasNoActiveSteps(plan.getId())) {
+                replaceStepsFromSeed(plan.getId(), seed);
+            } else {
+                repairDeletedAcupointReferences(plan.getId());
             }
         }
     }
 
+    private boolean hasNoActiveSteps(Long planId) {
+        Long count = planStepMapper.selectCount(new LambdaQueryWrapper<PlanStep>()
+                .eq(PlanStep::getPlanId, planId));
+        return count == null || count == 0;
+    }
+
+    private void replaceStepsFromSeed(Long planId, PlanSeed seed) {
+        planStepMapper.delete(new LambdaUpdateWrapper<PlanStep>()
+                .eq(PlanStep::getPlanId, planId));
+
+        for (int i = 0; i < seed.steps.size(); i++) {
+            StepSeed stepSeed = seed.steps.get(i);
+            Acupoint acupoint = resolveActiveAcupoint(stepSeed.acupointId, stepSeed.acupointName);
+            PlanStep step = new PlanStep();
+            step.setPlanId(planId);
+            step.setStepOrder(i + 1);
+            step.setAcupointId(acupoint != null ? acupoint.getId() : stepSeed.acupointId);
+            step.setAcupointName(acupoint != null ? acupoint.getName() : stepSeed.acupointName);
+            step.setSide(stepSeed.side);
+            step.setTemperature(stepSeed.temperature);
+            step.setDuration(stepSeed.duration);
+            step.setTechniqueId(stepSeed.techniqueId);
+            step.setTechniqueName(stepSeed.techniqueName);
+            step.setRemark(stepSeed.remark);
+            planStepMapper.insert(step);
+        }
+    }
+
+    private void repairDeletedAcupointReferences(Long planId) {
+        List<PlanStep> steps = planStepMapper.selectList(new LambdaQueryWrapper<PlanStep>()
+                .eq(PlanStep::getPlanId, planId));
+        for (PlanStep step : steps) {
+            Acupoint acupoint = findActiveById(step.getAcupointId());
+            if (acupoint != null) {
+                continue;
+            }
+            Acupoint replacement = resolveActiveAcupoint(null, step.getAcupointName());
+            if (replacement == null) {
+                continue;
+            }
+            PlanStep update = new PlanStep();
+            update.setId(step.getId());
+            update.setAcupointId(replacement.getId());
+            update.setAcupointName(replacement.getName());
+            planStepMapper.updateById(update);
+        }
+    }
+
+    private Acupoint resolveActiveAcupoint(Long acupointId, String acupointName) {
+        if (StringUtils.hasText(acupointName)) {
+            Acupoint byName = findActiveByName(acupointName);
+            if (byName != null) {
+                return byName;
+            }
+        }
+        return findActiveById(acupointId);
+    }
+
+    private Acupoint findActiveByName(String acupointName) {
+        String name = acupointName.trim();
+        Acupoint exact = selectActiveByName(name);
+        if (exact != null) {
+            return exact;
+        }
+        if (name.endsWith("\u7a74") && name.length() > 1) {
+            return selectActiveByName(name.substring(0, name.length() - 1));
+        }
+        return selectActiveByName(name + "\u7a74");
+    }
+
+    private Acupoint selectActiveByName(String acupointName) {
+        return acupointMapper.selectOne(new LambdaQueryWrapper<Acupoint>()
+                .eq(Acupoint::getName, acupointName)
+                .eq(Acupoint::getStatus, 1)
+                .orderByDesc(Acupoint::getUpdateTime)
+                .orderByDesc(Acupoint::getId)
+                .last("limit 1"));
+    }
+
+    private Acupoint findActiveById(Long acupointId) {
+        if (acupointId == null) {
+            return null;
+        }
+        Acupoint acupoint = acupointMapper.selectById(acupointId);
+        if (acupoint == null || !Integer.valueOf(1).equals(acupoint.getStatus())) {
+            return null;
+        }
+        return acupoint;
+    }
+
+    private boolean fillMissingPlanFields(Plan plan, PlanSeed seed) {
+        boolean changed = false;
+        if (!StringUtils.hasText(plan.getName())) {
+            plan.setName(seed.name);
+            changed = true;
+        }
+        if (plan.getModeType() == null) {
+            plan.setModeType(seed.modeType);
+            changed = true;
+        }
+        if (!StringUtils.hasText(plan.getEffectType()) && StringUtils.hasText(seed.effectType)) {
+            plan.setEffectType(seed.effectType);
+            changed = true;
+        }
+        if (plan.getApplicableGender() == null) {
+            plan.setApplicableGender(0);
+            changed = true;
+        }
+        if (plan.getAgeMin() == null) {
+            plan.setAgeMin(1);
+            changed = true;
+        }
+        if (plan.getAgeMax() == null) {
+            plan.setAgeMax(120);
+            changed = true;
+        }
+        if (plan.getAuthorType() == null) {
+            plan.setAuthorType(1);
+            changed = true;
+        }
+        if (!StringUtils.hasText(plan.getAuthorName())) {
+            plan.setAuthorName("ADMIN");
+            changed = true;
+        }
+        if (plan.getStatus() == null) {
+            plan.setStatus(1);
+            changed = true;
+        }
+        if (plan.getUseCount() == null) {
+            plan.setUseCount(0);
+            changed = true;
+        }
+        return changed;
+    }
+
     private void fillPlan(Plan plan, PlanSeed seed) {
         plan.setName(seed.name);
         plan.setModeType(seed.modeType);

+ 19 - 0
code/backend/src/main/java/com/aijiuyi/admin/service/impl/PlanServiceImpl.java

@@ -6,10 +6,12 @@ import com.aijiuyi.admin.common.exception.BusinessException;
 import com.aijiuyi.admin.common.util.LogUtil;
 import com.aijiuyi.admin.controller.dto.PlanQueryDTO;
 import com.aijiuyi.admin.controller.dto.PlanSaveDTO;
+import com.aijiuyi.admin.entity.Acupoint;
 import com.aijiuyi.admin.entity.AppUser;
 import com.aijiuyi.admin.entity.Plan;
 import com.aijiuyi.admin.entity.PlanStep;
 import com.aijiuyi.admin.entity.UserPlan;
+import com.aijiuyi.admin.mapper.AcupointMapper;
 import com.aijiuyi.admin.mapper.PlanMapper;
 import com.aijiuyi.admin.mapper.PlanStepMapper;
 import com.aijiuyi.admin.mapper.UserPlanMapper;
@@ -46,6 +48,9 @@ public class PlanServiceImpl extends ServiceImpl<PlanMapper, Plan> implements Pl
     @Autowired
     private PlanStepMapper planStepMapper;
 
+    @Autowired
+    private AcupointMapper acupointMapper;
+
     @Autowired
     private UserPlanMapper userPlanMapper;
 
@@ -419,13 +424,27 @@ public class PlanServiceImpl extends ServiceImpl<PlanMapper, Plan> implements Pl
     private void saveSteps(Long planId, List<PlanStep> steps) {
         for (int i = 0; i < steps.size(); i++) {
             PlanStep step = steps.get(i);
+            Acupoint acupoint = getActiveAcupoint(step.getAcupointId());
             step.setId(null);
             step.setPlanId(planId);
             step.setStepOrder(i + 1);
+            step.setAcupointId(acupoint.getId());
+            step.setAcupointName(acupoint.getName());
             planStepMapper.insert(step);
         }
     }
 
+    private Acupoint getActiveAcupoint(Long acupointId) {
+        if (acupointId == null) {
+            throw new BusinessException(ResultCode.ACUPOINT_NOT_FOUND);
+        }
+        Acupoint acupoint = acupointMapper.selectById(acupointId);
+        if (acupoint == null || !Integer.valueOf(1).equals(acupoint.getStatus())) {
+            throw new BusinessException(ResultCode.ACUPOINT_NOT_FOUND);
+        }
+        return acupoint;
+    }
+
     private void hideMasterUserPlans(Plan plan) {
         if (plan == null || !Integer.valueOf(MODE_TYPE_MASTER).equals(plan.getModeType())) {
             return;

+ 30 - 8
code/frontend/src/views/simulation/index.vue

@@ -339,7 +339,7 @@
               </text>
               <text :x="SVG_C7_X + 28" :y="currentSpineEndY + 6" font-size="10" fill="#0369a1" font-family="system-ui, sans-serif">脊柱终点</text>
 
-              <!-- C7 大椎穴标记 -->
+              <!-- C7 大椎穴常驻标记 -->
               <g :transform="`translate(${SVG_C7_X}, ${SVG_C7_Y})`">
                 <circle r="14" fill="none" stroke="#e85d5d" stroke-width="1" opacity="0.3">
                   <animate attributeName="r" values="8;16;8" dur="2.5s" repeatCount="indefinite" />
@@ -351,6 +351,12 @@
                 <line x1="0" y1="-11" x2="0" y2="-5" stroke="#e85d5d" stroke-width="1.8" stroke-linecap="round" />
                 <line x1="0" y1="5" x2="0" y2="11" stroke="#e85d5d" stroke-width="1.8" stroke-linecap="round" />
                 <text x="16" y="4" font-size="11" fill="#c24141" font-weight="700" font-family="system-ui, sans-serif">C7 大椎穴</text>
+                <g v-if="dazhuiMarker">
+                  <circle r="9" :fill="dazhuiMarker.color" stroke="#fff" stroke-width="2" />
+                  <text y="3" text-anchor="middle" font-size="8" font-weight="800" fill="#fff" font-family="system-ui, sans-serif" style="pointer-events:none">
+                    {{ dazhuiMarker.num }}
+                  </text>
+                </g>
               </g>
 
               <text x="208" y="24" font-size="10" fill="#94a3b8" font-family="system-ui, sans-serif">&uarr; 头侧</text>
@@ -359,7 +365,7 @@
               <text x="386" text-anchor="end" :y="SVG_C7_Y - 8" font-size="10" fill="#94a3b8" font-family="system-ui, sans-serif">右 (+X)</text>
 
               <!-- 穴位标记 -->
-              <g v-for="(m, idx) in markers" :key="idx">
+              <g v-for="(m, idx) in visualMarkers" :key="idx">
                 <circle :cx="m.x" :cy="m.y" r="12" :fill="m.color" opacity="0.18" />
                 <circle :cx="m.x" :cy="m.y" r="6" :fill="m.color" stroke="#fff" stroke-width="2" />
                 <text :x="m.x" :y="m.y + 4" text-anchor="middle" font-size="8" font-weight="800" fill="#fff" font-family="system-ui, sans-serif" style="pointer-events:none">
@@ -368,7 +374,7 @@
                 <!-- 步骤连接线 -->
                 <line
                   v-if="idx > 0"
-                  :x1="markers[idx-1].x" :y1="markers[idx-1].y"
+                  :x1="visualMarkers[idx-1].x" :y1="visualMarkers[idx-1].y"
                   :x2="m.x" :y2="m.y"
                   stroke="rgba(16,185,129,0.25)" stroke-width="1.5" stroke-dasharray="4 4"
                 />
@@ -401,7 +407,7 @@
           </div>
 
           <div v-if="unmappedSteps.length" class="visual-note">
-            <div class="visual-note-title">以下穴位未叠加到坐标系</div>
+            <div class="visual-note-title">以下穴位不属于背部穴位</div>
             <div class="visual-note-text">
               <span v-for="s in unmappedSteps" :key="s.stepOrder" class="visual-note-item">
                 {{ s.stepOrder }}. {{ s.acupointName }}
@@ -566,10 +572,19 @@ function bodyToSvgY(offsetYmm) {
   return SVG_C7_Y + Number(offsetYmm) * visualScale
 }
 
+function isDazhuiName(name) {
+  return String(name || '').includes('大椎')
+}
+
+function isDazhuiStep(step) {
+  return isDazhuiName(step?.acupointName)
+}
+
 function isBackVisualStep(step) {
+  if (isDazhuiStep(step)) return true
   if (step.offsetX == null || step.offsetY == null) return false
   if (FRONT_ACUPOINT_NAMES.has(step.acupointName)) return false
-  const isZeroFallback = Number(step.offsetX) === 0 && Number(step.offsetY) === 0 && step.acupointName !== '大椎穴'
+  const isZeroFallback = Number(step.offsetX) === 0 && Number(step.offsetY) === 0
   return !isZeroFallback
 }
 
@@ -578,7 +593,10 @@ const markers = computed(() => {
   return steps
     .filter(isBackVisualStep)
     .map((s, idx) => {
-      const { x, y } = bodyToSvg(s.offsetX, s.offsetY)
+      const isDazhui = isDazhuiStep(s)
+      const offsetX = isDazhui && s.offsetX == null ? 0 : s.offsetX
+      const offsetY = isDazhui && s.offsetY == null ? 0 : s.offsetY
+      const { x, y } = bodyToSvg(offsetX, offsetY)
       const techniqueColors = {
         '温和灸': '#10b981',
         '雀啄灸': '#f59e0b',
@@ -595,8 +613,8 @@ const markers = computed(() => {
         side: s.acupointSide,
         labelX: onRight ? x - 14 : x + 14,
         anchor: onRight ? 'end' : 'start',
-        rawOffsetX: s.offsetX,
-        rawOffsetY: s.offsetY,
+        rawOffsetX: offsetX,
+        rawOffsetY: offsetY,
         technique: s.techniqueName,
         temp: s.temperature,
         mins: s.duration || 0,
@@ -604,6 +622,10 @@ const markers = computed(() => {
     })
 })
 
+const dazhuiMarker = computed(() => markers.value.find((m) => isDazhuiName(m.name)) || null)
+
+const visualMarkers = computed(() => markers.value.filter((m) => !isDazhuiName(m.name)))
+
 const unmappedSteps = computed(() => {
   const steps = pushData.value?.scheme?.steps || []
   return steps.filter((s) => !isBackVisualStep(s))