liding
7 天以前 3728fa293e1faf4bf4f9bf41105b84ddb43dc82e
inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderTemplateServiceImpl.java
@@ -2,6 +2,7 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -17,6 +18,9 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
 * @author Administrator
@@ -67,7 +71,29 @@
        vo.setStandardTreeId(standardTreeId);
        if (standardTreeId != null) {
            List<StandardTreeTemplateBindingVo> bindings = standardTreeService.selectTemplateBindings(standardTreeId);
            vo.setTemplateBindings(bindings == null ? new ArrayList<>() : bindings);
            // 新保存的下单模板记录了实际保留的原始记录模板;旧模板没有该字段,沿用标准库绑定列表。
            JSONObject content = StringUtils.isBlank(template.getThing())
                    ? null : JSON.parseObject(template.getThing());
            JSONArray savedSelections = content == null ? null : content.getJSONArray("templateList");
            if (savedSelections == null) {
                vo.setTemplateBindings(bindings == null ? new ArrayList<>() : bindings);
            } else {
                Map<Integer, StandardTreeTemplateBindingVo> currentBindings = (bindings == null
                        ? new ArrayList<StandardTreeTemplateBindingVo>() : bindings).stream()
                        .collect(Collectors.toMap(StandardTreeTemplateBindingVo::getTemplateId,
                                Function.identity(), (first, ignored) -> first));
                List<StandardTreeTemplateBindingVo> selected = new ArrayList<>();
                for (int index = 0; index < savedSelections.size(); index++) {
                    JSONObject selection = savedSelections.getJSONObject(index);
                    if (selection == null) continue;
                    StandardTreeTemplateBindingVo binding = currentBindings.get(selection.getInteger("templateId"));
                    if (binding != null) {
                        binding.setSort(index);
                        selected.add(binding);
                    }
                }
                vo.setTemplateBindings(selected);
            }
        } else {
            vo.setTemplateBindings(new ArrayList<>());
        }