private Result<EqpMetCdHeader> analysisCDheader(List<String> contentLines, Path imageFolderPath) {
        EqpMetCdHeader cdHeader = new EqpMetCdHeader();
        List<EqpMetCdHeaderApImage> apImageList = new ArrayList<>();
        int apImageScoreIndex = 0;
        boolean processResultFlag = false;
        for (String str : contentLines) {
            if (str.isEmpty()) {
                continue; // 跳过无效行
            }
            if (str.contains("/date")) {
                String date = StrListUtils.getLastSplitElement(str, " ");
                if (StringUtils.isBlank(date)) {
                    String errorMessage = "Cannot find report time";
                    log.error("Cannot find report time");
                    return Result.failure(errorMessage);
                }
                cdHeader.setReportTime(LocalDateTime.parse(date, DATE_TIME_FORMATTER));
            } else if (str.contains("/recipe_name")) {
                String recipeName = StrListUtils.getLastSplitElement(str, " ").replace("\"", "");
                String[] parts = recipeName.split("_");
                if (parts.length == 0 || parts[0].length() < 5) {
                    String errorMessage = "Cannot find recipe ID";
                    log.error(errorMessage);
                    return Result.failure(errorMessage);
                }
                cdHeader.setRecipeId(recipeName);
                cdHeader.setProdId(recipeName.split("_")[0].substring(0, 5));
            } else if (str.contains("/lot_id")) {
                String lotId = StrListUtils.getLastSplitElement(str, " ").replace("\"", "");
                cdHeader.setLotId(StringUtils.isBlank(lotId) ? "-" : lotId);
            } else if (str.contains("/wafer_id")) {
                String waferId = StrListUtils.getLastSplitElement(str, " ").replace("\"", "");
                if (StringUtils.isBlank(waferId)) {
                    String errorMessage = "Cannot find wafer ID";
                    log.error(errorMessage);
                    return Result.failure(errorMessage);
                }
                cdHeader.setWaferId(waferId);
            } else if (str.contains("_control_job_id")) {
                String controlJobId = StrListUtils.getLastSplitElement(str, " ").replace("\"", "");
                if (StringUtils.isBlank(controlJobId)) {
                    String errorMessage = "Cannot find control job ID";
                    log.error(errorMessage);
                    return Result.failure(errorMessage);
                }
                cdHeader.setControlJobId(controlJobId);
            } else if (str.contains("_process_job_id")) {
                String processJobId = StrListUtils.getLastSplitElement(str, " ").replace("\"", "");
                if (StringUtils.isBlank(processJobId)) {
                    String errorMessage = "Cannot find process job ID";
                    log.error(errorMessage);
                    return Result.failure(errorMessage);
                }
                cdHeader.setProcessJobId(processJobId);
            } else if (str.contains("~idw_info    map_offset")) {
                String mpaOffset = StrListUtils.getLastSplitElement(str, " ");
                String[] split = mpaOffset.split(",");
                if (split.length != 2) {
                    String errorMessage = "Invalid map_offset format: " + str;
                    log.error(errorMessage);
                    return Result.failure(errorMessage);
                }
                cdHeader.setMapOffsetX(new BigDecimal(split[0]).divide(new BigDecimal("1000"), 6,
                        RoundingMode.HALF_UP));
                cdHeader.setMapOffsetY(new BigDecimal(split[1]).divide(new BigDecimal("1000"), 6,
                        RoundingMode.HALF_UP));
            } else if (str.contains("~idw_info    map_origin")) {
                String mapOrigin = StrListUtils.getLastSplitElement(str, " ");
                String[] split = mapOrigin.split(",");
                if (split.length < 2) {
                    String errorMessage = "Invalid map_origin format: " + str;
                    log.error(errorMessage);
                    return Result.failure(errorMessage);
                }
                cdHeader.setMapOriginX(Long.parseLong(split[0]));
                cdHeader.setMapOriginY(Long.parseLong(split[1]));
            } else if (str.contains("~idw_info    array       : 0")) {
                String shotArray = StrListUtils.getLastSplitElement(str, " ");
                String[] split = shotArray.split(",");
                if (split.length < 2) {
                    String errorMessage = String.format("Invalid wafer shot format: %s", str);
                    log.error(errorMessage);
                    return Result.failure(errorMessage);
                }
                cdHeader.setWaferShotX(Long.parseLong(split[0]));
                cdHeader.setWaferShotY(Long.parseLong(split[1]));
            } else if (str.contains("~idw_info    array       : 1")) {
                String dieArray = StrListUtils.getLastSplitElement(str, " ");
                String[] split = dieArray.split(",");
                if (split.length < 2) {
                    log.error("Invalid shot die formart: " + str);
                    return null;
                }
                cdHeader.setShotDieX(Long.parseLong(split[0]));
                cdHeader.setShotDieY(Long.parseLong(split[1]));
            } else if (str.contains("~idw_info    pitch")) {
                String pitch = StrListUtils.getLastSplitElement(str, " ");
                String[] split = pitch.split(",");
                if (split.length < 2) {
                    log.error("Invalid pitch format: " + str);
                    return null;
                }
                cdHeader.setShotSizeX(new BigDecimal(split[0]).divide(new BigDecimal(1000), 6, RoundingMode.HALF_UP));
                cdHeader.setShotSizeY(new BigDecimal(split[1]).divide(new BigDecimal(1000), 6, RoundingMode.HALF_UP));
            } else if (str.contains("@slot_no")) {
                String slotNo = StrListUtils.getLastSplitElement(str, " ");
                if (StringUtils.isBlank(slotNo)) {
                    log.error("Cannot find slot ID");
                }
                cdHeader.setSlotId(slotNo);
            } else if (str.contains("@measure_start") && str.contains("20")) {
                String[] split = str.strip().split("\\s+");
                if (split.length != 3) {
                    log.error("Invalid measure_start format: " + str);
                    return null;
                }
                cdHeader.setMetStartTime(LocalDateTime.parse(split[1] + " " + split[2], MEASURE_TIME_FORMATTER));
            } else if (str.contains("@measure_end") && str.contains("20")) {
                String[] split = str.strip().split("\\s+");
                if (split.length != 3) {
                    log.error("Invalid measure_end format: " + str);
                    return null;
                }
                cdHeader.setMetEndTime(LocalDateTime.parse(split[1] + " " + split[2], MEASURE_TIME_FORMATTER));
            } else if (str.contains("@alignment_offset :")) {
                String lastElement = StrListUtils.getLastSplitElement(str, " ");
                if (lastElement == null) {
                    lastElement = ""; // 默认值
                }
                EqpMetCdHeaderApImage apImage = new EqpMetCdHeaderApImage()
                        .setId(idGenerator.nextId())
                        .setEqpMetCdHeaderSiteId("TODO")
                        .setOrderNo(apImageList.size() + 1)
                        .setImageOffset(lastElement.replace(",", "_"));
                apImageList.add(apImage);

            } else if (str.contains("@alignment_score  :")) {
                apImageScoreIndex++; // 递增索引
                if (apImageScoreIndex - 1 >= apImageList.size()) {
                    throw new IllegalStateException("Index out of bounds for alignment score");
                }
                EqpMetCdHeaderApImage apImage = apImageList.get(apImageScoreIndex - 1);
                String score = StrListUtils.getLastSplitElement(str, " ");
                apImage.setImageScore(score != null ? score.replace(",", ";") : null);
            } else if (str.contains("@ap_image_name")) {

                String imgPath = StrListUtils.getLastSplitElement(str, " ");
                String imageNo = StrListUtils.getLastSplitElement(imgPath.split("-")[0], "_");
                int apImageNameIndex = Integer.parseInt(imageNo.substring(1));
                Path imagePath = imageFolderPath.resolve(imgPath.replace(".jpeg", ".jpg"));
                int targetIndex = apImageNameIndex - 1;
                if (targetIndex < 0 || targetIndex >= apImageList.size()) {
                    throw new IllegalArgumentException("Invalid index: " + targetIndex);
                }
                EqpMetCdHeaderApImage target = apImageList.get(targetIndex);
                if (StringUtils.isBlank(target.getImagePath())) {
                    target.setImagePath(imagePath.toString());
                } else {
                    target.setImagePath(target.getImagePath() + ";" + imagePath);
                }
                target.setImageNo(imageNo);
                //TODO 这里有imageNo的逻辑
            } else if (str.contains("  $result")) {
                if (processResultFlag) {
                    continue;
                }
                //在之前会反复计算firstDieOrigin,sampleCenterX,reticleOrgX
                Long shotDieX = cdHeader.getShotDieX();
                Long shotDieY = cdHeader.getShotDieY();
                if (shotDieX == 0 || shotDieY == 0) {
                    log.error("shotDieX and shotDieY must not be zero.");//除0需要校验
                    return null;
                }

                BigDecimal mapOffsetX = cdHeader.getMapOffsetX();
                BigDecimal mapOffsetY = cdHeader.getMapOffsetY();
                Long waferShotX = cdHeader.getWaferShotX();
                Long waferShotY = cdHeader.getWaferShotY();

                BigDecimal dieW = cdHeader.getShotSizeX().divide(new BigDecimal(shotDieX), 6, RoundingMode.HALF_UP);
                BigDecimal dieH = cdHeader.getShotSizeY().divide(new BigDecimal(shotDieY), 6, RoundingMode.HALF_UP);

                BigDecimal shiftChipX = mapOffsetX
                        .subtract(new BigDecimal(shotDieX * waferShotX / 2))
                        .subtract(new BigDecimal((shotDieX * waferShotX) % 2).divide(new BigDecimal(2),
                                6, RoundingMode.HALF_UP));
                BigDecimal shiftChipY = mapOffsetY
                        .subtract(new BigDecimal(shotDieY * waferShotY / 2))
                        .subtract(new BigDecimal((shotDieY * waferShotY) % 2).divide(new BigDecimal(2),
                                6, RoundingMode.HALF_UP));


                BigDecimal firstDieX = mapOffsetX.add(shiftChipX.multiply(dieW));
                BigDecimal firstDieY = mapOffsetY.add(shiftChipY.multiply(dieH));
                long zeroDieX = cdHeader.getMapOriginX() % shotDieX;
                long zeroDieY = cdHeader.getMapOriginY() % shotDieY;
                cdHeader.setFirstDieOriginX(firstDieX);
                cdHeader.setFirstDieOriginY(firstDieY);
                cdHeader.setSampleCenterX(firstDieX.negate());
                cdHeader.setSampleCenterY(firstDieY.negate());
                cdHeader.setReticleOrgX(zeroDieX * -1);
                cdHeader.setReticleOrgY(zeroDieY * -1);
                processResultFlag = true;
            }
        }
        cdHeader.setApImageList(apImageList);
        return Result.success(cdHeader);
    }优化这段代码