diff --git a/manager-admin/src/main/java/com/hshh/evaluation/bean/DraftWeightData.java b/manager-admin/src/main/java/com/hshh/evaluation/bean/DraftWeightData.java deleted file mode 100644 index b994301..0000000 --- a/manager-admin/src/main/java/com/hshh/evaluation/bean/DraftWeightData.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.hshh.evaluation.bean; - -import java.util.List; -import java.util.Map; -import lombok.Data; - -/** - * 模板权重暂存数据. - * - * @author LiDongYU - * @since 2025/7/22 - */ -@Data -public class DraftWeightData { - - /** - * 页面定义的临时key. - */ - private String key; - /** - * 父指标ID. - */ - private Integer parentIndicationId; - /** - * 模板ID. - */ - private Integer templateId; - - /** - * 表头map linkedMap. key是指标id,value是 {id,name} - */ - private Map headerMap; - - /** - * 页面中指标表的权重信息设置.key 为fromIndicatorId+"_"+toIndicatorId. - */ - private List> weight; - -} diff --git a/manager-admin/src/main/java/com/hshh/evaluation/controller/AssistantTemplateController.java b/manager-admin/src/main/java/com/hshh/evaluation/controller/AssistantTemplateController.java index 5b183c1..d89937f 100644 --- a/manager-admin/src/main/java/com/hshh/evaluation/controller/AssistantTemplateController.java +++ b/manager-admin/src/main/java/com/hshh/evaluation/controller/AssistantTemplateController.java @@ -1,12 +1,14 @@ package com.hshh.evaluation.controller; -import com.hshh.evaluation.bean.DraftWeightData; +import com.hshh.evaluation.bean.DynamicTable; import com.hshh.evaluation.bean.MetricMapperWeightBean; -import com.hshh.evaluation.entity.EvaluationTemplate; +import com.hshh.evaluation.bean.MetricTableHeaderBean; import com.hshh.evaluation.entity.EvaluationTemplateWeight; import com.hshh.indicator.entity.Indicator; +import com.hshh.indicator.service.IndicatorService; +import com.hshh.indicator.service.impl.IndicatorServiceImpl; import com.hshh.system.common.bean.BaseController; -import com.hshh.system.common.util.DraftStore; +import com.hshh.system.common.bean.SpringContextHolder; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; @@ -41,84 +43,100 @@ public class AssistantTemplateController extends BaseController { } /** - * 组装历史权重数据. + * 把数据库中的明细数据转化为页面约定的数据类型. * - * @param evaluationTemplate 当前模板数据 - * @return 评估数据列表 + * @param detailList 数据库数据 + * @return 页面约定的权重列表 */ - @SuppressWarnings("unchecked") - protected Map unitWeightMap( - EvaluationTemplate evaluationTemplate) { - - // 获取缓存中的数据 - Map cacheData = DraftStore.get(evaluationTemplate.getDraftKey(), - Map.class); - if (cacheData == null) { - if (evaluationTemplate.getCurrentPagePartData() != null) { - - Map defaultMap = new LinkedHashMap<>(); - DraftWeightData weightData = createDefaultDraftWeightData(evaluationTemplate); - defaultMap.put(weightData.getParentIndicationId(), weightData); - return defaultMap; - } - - } - - //cacheData数据结构 父ID-->当前id下子指标的权重信息 - //查看当前页面上传的最后一次指标权重信息;用当前页面的数据更新缓存或者增加缓存 - if (evaluationTemplate.getCurrentPagePartData() != null) { - - int parentId = evaluationTemplate.getCurrentPagePartData().get(0).get(0).getParentId(); - cacheData.remove(parentId); - //构建一个简易的只包含实际当前表格中的数据的暂存对象类,供后面合并 - DraftWeightData draftWeightData = createDefaultDraftWeightData(evaluationTemplate); - - cacheData.put(parentId, draftWeightData); - } - - return cacheData; + protected List convertEvaluationTemplateWeightList( + List detailList) { + List list = new ArrayList<>(); + detailList.forEach(detail -> { + MetricMapperWeightBean weightBean = new MetricMapperWeightBean(); + weightBean.setRowNum(detail.getRowNum()); + weightBean.setValue(detail.getWeight()); + weightBean.setRowId(detail.getFromIndicatorId()); + weightBean.setColId(detail.getToIndicatorId()); + weightBean.setParentId(detail.getIndicatorParentId()); + list.add(weightBean); + }); + return list; } - private DraftWeightData createDefaultDraftWeightData(EvaluationTemplate evaluationTemplate) { - int pid = evaluationTemplate.getCurrentPagePartData().get(0).get(0).getParentId(); - DraftWeightData draftWeightData = new DraftWeightData(); - draftWeightData.setTemplateId(evaluationTemplate.getId()); - draftWeightData.setWeight(evaluationTemplate.getCurrentPagePartData()); - draftWeightData.setParentIndicationId(pid); - draftWeightData.setKey(evaluationTemplate.getDraftKey()); - return draftWeightData; - } - - /** - * 当一个指标下面只有一个孩子时,填充默认权重1. + * 创建表格头. * - * @param lonelyChild 只有自己,没有其他节点和他同级 - * @param unitWeightDataMap 当前已经设置的权重信息. + * @param children 子指标 + * @return 表格头信息 */ - - protected void paddingDefaultValueWhenParentHasOnlyLonelyChild(List lonelyChild, - Map unitWeightDataMap) { - for (Indicator indicator : lonelyChild) { - if (!unitWeightDataMap.containsKey(indicator.getParentId())) { - List> singleRowList = new ArrayList<>(); - List list = new ArrayList<>(); - MetricMapperWeightBean weightBean = new MetricMapperWeightBean(); - list.add(weightBean); - singleRowList.add(list); - weightBean.setParentId(indicator.getParentId()); - weightBean.setValue("1"); - weightBean.setRowId(indicator.getId()); - weightBean.setColId(indicator.getId()); - weightBean.setRowNum(1); - DraftWeightData draftWeightData = new DraftWeightData(); - draftWeightData.setParentIndicationId(indicator.getParentId()); - draftWeightData.setWeight(singleRowList); - ; - unitWeightDataMap.put(indicator.getParentId(), draftWeightData); - } - } + protected Map createTableHeaderMap(List children) { + List headerBeans = new ArrayList<>(); + children.forEach(a -> { + MetricTableHeaderBean bean = new MetricTableHeaderBean(); + bean.setId(a.getId()); + bean.setName(a.getName()); + headerBeans.add(bean); + }); + Map headerMap = new LinkedHashMap<>(); + headerBeans.forEach(header -> { + headerMap.put(header.getId(), header); + }); + return headerMap; } + /** + * 从数据库创建一个空的默认映射列表. + * + * @param parentIndicatorId 父指标 + * @param children 子指标 + * @param i 行号 + * @return 默认映射列表 + */ + protected List createEmptyMapperList(Integer parentIndicatorId, + List children, int i) { + List innerList = new ArrayList<>(); + for (Indicator child : children) { + MetricMapperWeightBean weightBean = new MetricMapperWeightBean(); + //行ID + weightBean.setRowId(children.get(i).getId()); + //列Id + weightBean.setColId(child.getId()); + //初始默认为1 + weightBean.setValue("1") + ; + + weightBean.setRowNum(i + 1); + weightBean.setParentId(parentIndicatorId); + innerList.add(weightBean); + } + return innerList; + } + + /** + * 从数据库创建动态表. + * + * @param indicatePid 父节点指标 + * @return 动态表 + */ + protected DynamicTable createNewDynamicFromDatabase(Integer indicatePid) { + DynamicTable dynamicTable = new DynamicTable(); + //查询当前指标的子指标 + IndicatorService indicatorService = SpringContextHolder.getBean(IndicatorServiceImpl.class); + List children = indicatorService.queryChildren(indicatePid); + + //设置头信息 + dynamicTable.setHeaderMap(createTableHeaderMap(children)); + + //设置权重信息 + List> weight = new ArrayList<>(); + for (int i = 0; i < children.size(); i++) { + List innerList = createEmptyMapperList(indicatePid, children, i + ); + weight.add(innerList); + } + + dynamicTable.setWeight(weight); + return dynamicTable; + } } diff --git a/manager-admin/src/main/java/com/hshh/evaluation/controller/EvaluationTemplateController.java b/manager-admin/src/main/java/com/hshh/evaluation/controller/EvaluationTemplateController.java index 5527a50..b4e6a64 100644 --- a/manager-admin/src/main/java/com/hshh/evaluation/controller/EvaluationTemplateController.java +++ b/manager-admin/src/main/java/com/hshh/evaluation/controller/EvaluationTemplateController.java @@ -1,6 +1,5 @@ package com.hshh.evaluation.controller; -import com.hshh.evaluation.bean.DraftWeightData; import com.hshh.evaluation.bean.DynamicTable; import com.hshh.evaluation.bean.MetricComputeRequest; import com.hshh.evaluation.bean.MetricComputerResponse; @@ -23,15 +22,12 @@ import com.hshh.system.common.bean.OperateResult; import com.hshh.system.common.bean.PaginationBean; import com.hshh.system.common.enums.ErrorCode; import com.hshh.system.common.enums.ErrorMessage; -import com.hshh.system.common.util.DraftStore; import io.swagger.v3.oas.annotations.Operation; import java.time.LocalDateTime; import java.util.ArrayList; -import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; import javax.annotation.Resource; import javax.validation.Valid; import lombok.extern.slf4j.Slf4j; @@ -103,6 +99,7 @@ public class EvaluationTemplateController extends AssistantTemplateController { return "project_template/list"; } + /** * 导航到增加页面. * @@ -115,43 +112,6 @@ public class EvaluationTemplateController extends AssistantTemplateController { return "project_template/add"; } - /** - * 获取指标树. - * - * @param id 指标ID - * @return 指标树 - */ - @GetMapping("/metricTree/{id}/{templateId}") - @ResponseBody - public OperateResult> metricTree(@PathVariable("id") Integer id, - @PathVariable("templateId") Integer templateId) { - if (id == null) { - return OperateResult.success(new ArrayList<>()); - } - //查询指标权重树 - Map weightMap = evaluationTemplateIndicatorWeightService.getEvaluationTemplateIndicatorWeightMap( - id, templateId); - Map> weightDetailMap = evaluationTemplateDetailWeightService.groupByParentIndicatorId( - id, templateId); - List jsTreeList = indicatorService.metricTree(id); - //开始给指标设置权重,指标名称后挂在权重信息;并在data属性中,增加子节点-子节点的权重信息 - setWeightToTree(jsTreeList, weightMap, weightDetailMap); - return OperateResult.success(jsTreeList); - } - - private void setWeightToTree(List jsTreeList, Map weightMap, - Map> weightDetailMap) { - jsTreeList.forEach(tree -> { - if (weightMap.containsKey((int) tree.getOriginalId())) { - tree.getData().put("weight", weightMap.get((int) tree.getOriginalId())); - - } - if(weightDetailMap.containsKey((int) tree.getOriginalId())) { - tree.getData().put("weightDetail", weightDetailMap.get((int) tree.getOriginalId())); - } - setWeightToTree(tree.getChildren(), weightMap, weightDetailMap); - }); - } /** * 保存模板. 必须设置指标;设置完成权重,才成成功提交 @@ -182,23 +142,17 @@ public class EvaluationTemplateController extends AssistantTemplateController { } - //1.合并权重数据 - Map unitWeightDataMap = unitWeightMap(evaluationTemplate); +// //1.合并权重数据 +// Map unitWeightDataMap = unitWeightMap(evaluationTemplate); +// +// //2.填充数据;如果一个指标下面只有一个孩子,则默认填充为1 +// List lonelyChild = indicatorService.queryLonelyChild( +// evaluationTemplate.getIndicatorTopId()); +// +// paddingDefaultValueWhenParentHasOnlyLonelyChild(lonelyChild, unitWeightDataMap); - //2.填充数据;如果一个指标下面只有一个孩子,则默认填充为1 - List lonelyChild = indicatorService.queryLonelyChild( - evaluationTemplate.getIndicatorTopId()); - - paddingDefaultValueWhenParentHasOnlyLonelyChild(lonelyChild, unitWeightDataMap); - - //3.开始验证完整性/一致性 - String validateWholeMessage = validate(evaluationTemplate.getIndicatorTopId(), - unitWeightDataMap); - if (!validateWholeMessage.isEmpty()) { - return OperateResult.error(null, validateWholeMessage, ErrorCode.BUSINESS_ERROR.getCode()); - } - //4. 提交 - evaluationTemplateService.saveWhole(evaluationTemplate, unitWeightDataMap); +// //4. 提交 +// evaluationTemplateService.saveWhole(evaluationTemplate, unitWeightDataMap); return OperateResult.success(); } @@ -238,7 +192,67 @@ public class EvaluationTemplateController extends AssistantTemplateController { return OperateResult.success(template); } + /** + * 获取指标树. + * + * @param id 指标ID + * @return 指标树 + */ + @GetMapping("/metricTree/{id}/{templateId}") + @ResponseBody + public OperateResult> metricTree(@PathVariable("id") Integer id, + @PathVariable("templateId") Integer templateId) { + if (id == null) { + return OperateResult.success(new ArrayList<>()); + } + //查询指标权重树 + Map weightMap = evaluationTemplateIndicatorWeightService.getEvaluationTemplateIndicatorWeightMap( + id, templateId); + Map> weightDetailMap = evaluationTemplateDetailWeightService.groupByParentIndicatorId( + id, templateId); + List jsTreeList = indicatorService.metricTree(id); + //开始给指标设置权重,指标名称后挂在权重信息;并在data属性中,增加子节点-子节点的权重信息 + setWeightToTree(jsTreeList, weightMap, weightDetailMap); + return OperateResult.success(jsTreeList); + } + private void setWeightToTree(List jsTreeList, Map weightMap, + Map> weightDetailMap) { + if (jsTreeList == null) { + return; + } + jsTreeList.forEach(tree -> { + if (weightMap.containsKey((int) tree.getOriginalId())) { + tree.getData().put("weight", weightMap.get((int) tree.getOriginalId())); + + } else { + tree.getData().put("weight", 1); + } + if (weightDetailMap.containsKey((int) tree.getOriginalId())) { + tree.getData().put("weightDetail", + convertEvaluationTemplateWeightList(weightDetailMap.get((int) tree.getOriginalId()))); + } + setWeightToTree(tree.getChildren(), weightMap, weightDetailMap); + }); + } + + + + + /** + * 获取指标编辑/新增时的table表格. + * + * @param indicateId 指标ID + * @param model session容器 + * @return table.html + */ + @GetMapping("/tablePage") + public String tablePage(Integer indicateId, Model model) { + model.addAttribute("data", createNewDynamicFromDatabase(indicateId)); + model.addAttribute("indicateId", indicateId); + return "project_template/table"; + + } /** * 计算指标,当设置变化时触发. @@ -272,91 +286,11 @@ public class EvaluationTemplateController extends AssistantTemplateController { H.children.forEach(child -> { MetricComputerResponse response = new MetricComputerResponse(); response.setId(child.name); - response.setWeight(String.format("%.2f", child.globalWeight)); + response.setWeight(String.format("%.4f", child.globalWeight)); responseList.add(response); }); return OperateResult.success(responseList); } - /** - * 验证指标权重完整性/一致性. - * - * @param indicatorTopId 指标顶级ID - * @param weightByParentIdMap 已经设置的权重Map - * @return 验证提示结果 - */ - private String validate(Integer indicatorTopId, - Map weightByParentIdMap) { - //所有topId=indicatorTopId列表 - List list = indicatorService.queryByTopId(indicatorTopId); - // key=指标ID value=指标数据 - Map indicatorMap = list.stream() - .collect(Collectors.toMap(Indicator::getId, a -> a)); - Map> parentMap = list.stream().filter(a -> a.getParentId() != null) - .collect(Collectors.groupingBy(Indicator::getParentId)); - StringBuffer sb = new StringBuffer(); - parentMap.forEach((indicatorId, children) -> { - //完整性 - if (!weightByParentIdMap.containsKey(indicatorId)) { - String indicatorName = - indicatorMap.get(indicatorId) == null ? "" : indicatorMap.get(indicatorId).getName(); - sb.append(indicatorName).append("没有设置权重
\n"); - } - if (weightByParentIdMap.get(indicatorId) != null) { - //一致性 - List> childWeightList = weightByParentIdMap.get(indicatorId) - .getWeight(); - consistencyValidate(sb, childWeightList, indicatorMap); - } - }); - - return sb.toString(); - } - - /** - * 验证一致性. 假设有三个指标 A,B,C A--AA AB,AC |B--BB BA BC| C--CC CA CB. - * - * @param sb 提示消息 - * @param childWeightList 要验证的数据 - * @param indicatorMap 指标map key=id value=指标 - */ - private void consistencyValidate(StringBuffer sb, - List> childWeightList, Map indicatorMap) { - if (childWeightList != null && childWeightList.size() > 1) { - //获取第一行记录作为标准 - List firstRow = childWeightList.get(0); - //获取A指标ID - Integer firstFormIndicatorId = firstRow.get(0).getRowId(); - //把第一行的数据,用rowId+"_+colId作为键,value为值 - Map firstRowMap = new HashMap<>(); - - firstRow.forEach(child -> { - firstRowMap.put(child.getRowId() + "_" + child.getColId(), - Double.parseDouble(child.getValue())); - }); - for (int i = 1; i < childWeightList.size(); i++) { - List weightBeanList = childWeightList.get(i); - for (int j = 1; j < weightBeanList.size(); j++) { - //获取第一行她的from指标值 AB - Double abValue = firstRowMap.get( - firstFormIndicatorId + "_" + weightBeanList.get(j).getRowId()); - //获取AC - Double acValue = firstRowMap.get( - firstFormIndicatorId + "_" + weightBeanList.get(j).getColId()); - //获取BC - double bcValue = Double.parseDouble(weightBeanList.get(j).getValue()); - if (bcValue > 1 && acValue.compareTo(abValue) > 0) { - sb.append(indicatorMap.get(weightBeanList.get(j).getRowId())).append("必须小于1") - .append("
\n"); - } - if (bcValue < 1 && acValue.compareTo(abValue) < 0) { - sb.append(indicatorMap.get(weightBeanList.get(j).getRowId())).append("必须大于1") - .append("
\n"); - } - - } - } - } - } } diff --git a/manager-admin/src/main/java/com/hshh/evaluation/entity/EvaluationTemplateIndicatorWeight.java b/manager-admin/src/main/java/com/hshh/evaluation/entity/EvaluationTemplateIndicatorWeight.java index cea4d1b..d562204 100644 --- a/manager-admin/src/main/java/com/hshh/evaluation/entity/EvaluationTemplateIndicatorWeight.java +++ b/manager-admin/src/main/java/com/hshh/evaluation/entity/EvaluationTemplateIndicatorWeight.java @@ -27,7 +27,7 @@ public class EvaluationTemplateIndicatorWeight implements Serializable { private Integer indicatorId; - private Double weight; + private String weight; } diff --git a/manager-admin/src/main/java/com/hshh/evaluation/entity/EvaluationTemplateWeight.java b/manager-admin/src/main/java/com/hshh/evaluation/entity/EvaluationTemplateWeight.java index ba083f0..a0a7c09 100644 --- a/manager-admin/src/main/java/com/hshh/evaluation/entity/EvaluationTemplateWeight.java +++ b/manager-admin/src/main/java/com/hshh/evaluation/entity/EvaluationTemplateWeight.java @@ -42,7 +42,7 @@ public class EvaluationTemplateWeight implements Serializable { /** * 权重. */ - private Double weight; + private String weight; /** * 父指标ID. diff --git a/manager-admin/src/main/java/com/hshh/evaluation/service/EvaluationTemplateService.java b/manager-admin/src/main/java/com/hshh/evaluation/service/EvaluationTemplateService.java index 770e40f..b2799ce 100644 --- a/manager-admin/src/main/java/com/hshh/evaluation/service/EvaluationTemplateService.java +++ b/manager-admin/src/main/java/com/hshh/evaluation/service/EvaluationTemplateService.java @@ -1,7 +1,6 @@ package com.hshh.evaluation.service; import com.baomidou.mybatisplus.extension.service.IService; -import com.hshh.evaluation.bean.DraftWeightData; import com.hshh.evaluation.entity.EvaluationTemplate; import com.hshh.system.common.bean.PaginationBean; import java.util.List; diff --git a/manager-admin/src/main/java/com/hshh/evaluation/service/impl/EvaluationTemplateServiceImpl.java b/manager-admin/src/main/java/com/hshh/evaluation/service/impl/EvaluationTemplateServiceImpl.java index bd589bd..72b381a 100644 --- a/manager-admin/src/main/java/com/hshh/evaluation/service/impl/EvaluationTemplateServiceImpl.java +++ b/manager-admin/src/main/java/com/hshh/evaluation/service/impl/EvaluationTemplateServiceImpl.java @@ -2,7 +2,6 @@ package com.hshh.evaluation.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.hshh.evaluation.bean.DraftWeightData; import com.hshh.evaluation.entity.EvaluationTemplate; import com.hshh.evaluation.entity.EvaluationTemplateWeight; import com.hshh.evaluation.mapper.EvaluationTemplateMapper; diff --git a/manager-admin/src/main/resources/templates/indicator/list.html b/manager-admin/src/main/resources/templates/indicator/list.html index dcdaa28..c1669d2 100644 --- a/manager-admin/src/main/resources/templates/indicator/list.html +++ b/manager-admin/src/main/resources/templates/indicator/list.html @@ -314,13 +314,16 @@ //获取选中的根节点 let id = $( 'input[name="radio_names"]:checked').val(); - let url = document.getElementById("_rootPath").value + "indicator/" + id; - let http = new HttpClient(); - http.get(url, function (error, res, xhr) { + if(id){ + let url = document.getElementById("_rootPath").value + "indicator/" + id; + let http = new HttpClient(); + http.get(url, function (error, res, xhr) { + + d3TreeData = res.result; + renderTree(); + }, "indicatorForm") + } - d3TreeData = res.result; - renderTree(); - }, "indicatorForm") } // 递归加 parent 属性 diff --git a/manager-admin/src/main/resources/templates/project_template/list.html b/manager-admin/src/main/resources/templates/project_template/list.html index 7760538..956e2fa 100644 --- a/manager-admin/src/main/resources/templates/project_template/list.html +++ b/manager-admin/src/main/resources/templates/project_template/list.html @@ -147,30 +147,23 @@ obj.templateName = document.getElementById("templateForm")["templateName"].value; obj.templateMemo = document.getElementById("templateForm")["templateMemo"].value; obj.indicatorTopId = document.getElementById("templateForm")["indicatorTopId"].value; - obj.draftKey = document.getElementById("templateForm")["draftKey"].value; - let pageMapData = getRowsTableData(); + const inst = $('#metric_tree').jstree(true); - if (pageMapData && pageMapData.length > 0) { + const flat = inst.get_json('#', { flat: true, no_data: false }); + flat.forEach(n => { + console.log(`[id=${n.id}] parent=${n.parent} text="${n.text}"`, n.data || {}); + }); - obj.currentPagePartData = pageMapData; - } - let url = document.getElementById("_rootPath").value + "evaluation/evaluationTemplate/save"; - let http = new HttpClient(); - http.post(url, obj, function (error, res, xhr) { - closeDialog("modal-full-width"); - document.getElementById("_evaluation_evaluationTemplate_").click(); - - }, "templateForm", null) } // 根据指标ID获取指标树 function metricTree(id) { let templateId = document.getElementById("templateForm")["id"].value; - if(!templateId||templateId===""){ - templateId="0" + if (!templateId || templateId === "") { + templateId = "0" } const url = document.getElementById("_rootPath").value - + "evaluation/evaluationTemplate/metricTree/" + id+"/" + templateId; + + "evaluation/evaluationTemplate/metricTree/" + id + "/" + templateId; const http = new HttpClient(); http.get(url, function (error, res, xhr) { @@ -202,89 +195,32 @@ let id = data.node.id || ""; id = id.replace(/^tree_/, ""); - draftDataAddAndGetData(id); + getTablePage(id); }); }, "templateForm"); } - //暂存旧数据+获取表数据 - function draftDataAddAndGetData(id) { - - //首先判断是否存在历史表格. - let headerData = getTableHeadData(); - - if (!headerData || headerData.size === 0) { - - //去数据 - getTablePage(id); - - } else { - - let obj = {}; - obj.templateId = document.getElementById("templateForm")["id"].value; - obj.key = document.getElementById("templateForm")["draftKey"].value; - obj.headerMap = mapToObject(headerData); - - obj.weight = getRowsTableData(); - - if (obj.weight.length > 0) { - - //获取父ID - obj.parentIndicationId = obj.weight[0][0].parentId; - let url = document.getElementById("_rootPath").value - + "evaluation/evaluationTemplate/receiveDraft"; - let http = new HttpClient(); - //暂存数据 - http.post(url, obj, function (error, res, xhr) { - getTablePage(id); - - }, null, null) - } - } - - } - - //获取表头元素 - function getTableHeadData() { - let tr = document.getElementById("dynamic_header_tr"); - if (!tr) { - return null; - } - let thList = tr.querySelectorAll('th'); - - let map = new Map(); - for (let i = 1; i < thList.length; i++) { - let th = thList[i]; - - let obj = {}; - obj.id = parseInt(th.getAttribute('data-value')); - obj.name = th.getAttribute('data-name'); - map.set(obj.id, obj); - } - - return map; - } - //绘制表格 function getTablePage(indicatorId) { - const templateId = document.getElementById("templateForm")["id"].value; + const url = document.getElementById("_rootPath").value - + "evaluation/evaluationTemplate/getDraftData"; - let obj = {}; - //页面key - obj.key = document.getElementById("templateForm")["draftKey"].value; - //父ID - obj.parentIndicationId = indicatorId; - //模板ID - obj.templateId = templateId; + + "evaluation/evaluationTemplate/tablePage?indicateId=" + indicatorId; let http = new HttpClient(); - http.post(url, obj, function (error, res, xhr) { + http.get(url, function (error, res, xhr) { document.getElementById("table_area").innerHTML = res; - }, null, null) + //绘制当前选中的指标下的children值 + const inst = $('#metric_tree').jstree(true); + + const node =inst.get_selected(true)[0]; + if(node.data.children){ + console.log(node.data.children); + } + + }, null) } @@ -316,14 +252,18 @@ postObj.metric = metric; postObj.weightList = getRowsTableData(); http.post(url, postObj, function (error, res, xhr) { - const $tree = $('#metric_tree'); + const inst = $('#metric_tree').jstree(true); + const selected = inst.get_selected(); // 返回选中节点 id 数组 + const selectTreeId = selected[0]; + const parentNode = inst.get_node(selectTreeId); + parentNode.data.children = postObj.weightList; res.result.forEach(element => { let id = "tree_" + element.id; - let node = $tree.jstree(true).get_node(id, false); + let node = inst.get_node(id, false); let name = node.text.replace(/\([^)]*\)/g, ""); name = name + "(" + element.weight + ")"; - - $tree.jstree(true).rename_node(node, name); + node.data.weight = element.weight; + inst.rename_node(node, name); }) }, null, null) } @@ -416,4 +356,24 @@ } return map; } + //获取表头元素 + function getTableHeadData() { + let tr = document.getElementById("dynamic_header_tr"); + if (!tr) { + return null; + } + let thList = tr.querySelectorAll('th'); + + let map = new Map(); + for (let i = 1; i < thList.length; i++) { + let th = thList[i]; + + let obj = {}; + obj.id = parseInt(th.getAttribute('data-value')); + obj.name = th.getAttribute('data-name'); + map.set(obj.id, obj); + } + + return map; + } \ No newline at end of file diff --git a/manager-admin/src/main/resources/templates/project_template/table.html b/manager-admin/src/main/resources/templates/project_template/table.html index 2d782f6..16a086c 100644 --- a/manager-admin/src/main/resources/templates/project_template/table.html +++ b/manager-admin/src/main/resources/templates/project_template/table.html @@ -7,31 +7,29 @@ - -