|
|
@@ -39,6 +39,7 @@ import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.validation.Valid;
|
|
|
import java.io.*;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.util.*;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -148,6 +149,8 @@ public class TrialSummaryClassificationConfigurationController extends BladeCont
|
|
|
fileInputStream = CommonUtil.getOSSInputStream(path);
|
|
|
}
|
|
|
String htmlString = IoUtil.readToString(fileInputStream);
|
|
|
+ htmlString= htmlString.replaceAll("title","trial");
|
|
|
+ htmlString= htmlString.replaceAll("trialsummaryreflection", "title");
|
|
|
Document doc = Jsoup.parse(htmlString);
|
|
|
Element table = doc.select("table").first();
|
|
|
doc.select("Col").remove();
|
|
|
@@ -248,7 +251,7 @@ public class TrialSummaryClassificationConfigurationController extends BladeCont
|
|
|
@ApiOperationSupport(order = 13)
|
|
|
@ApiOperation(value = "映射数据保存", notes = "传入TrialSummaryReflectionSaveDTO")
|
|
|
@RequestMapping(value = "/reflection/save", method = RequestMethod.POST)
|
|
|
- public R<Object> reflectionSave(@RequestBody TrialSummaryReflectionSaveDTO dto) {
|
|
|
+ public R<Object> reflectionSave(@RequestBody TrialSummaryReflectionSaveDTO dto) throws IOException {
|
|
|
if (ObjectUtil.isNotEmpty(dto.getClassId())) {
|
|
|
if (ObjectUtil.isEmpty(dto.getReflectionBeanList().size()) || dto.getReflectionBeanList().size() == 0) {
|
|
|
return R.success("操作成功");
|
|
|
@@ -298,6 +301,48 @@ public class TrialSummaryClassificationConfigurationController extends BladeCont
|
|
|
}
|
|
|
jdbcTemplate.batchUpdate(sqlInsert, batchArgs);
|
|
|
}
|
|
|
+ //设置html上的属性,添加一个属性,trialSummaryReflection
|
|
|
+ String file_path = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL);
|
|
|
+ String sys_file_net_url = ParamCache.getValue(CommonConstant.SYS_FILE_NET_URL);
|
|
|
+ String fileUrl = classificationConfiguration.getHtmlUrl();
|
|
|
+ File file1 = ResourceUtil.getFile(fileUrl);
|
|
|
+ InputStream fileInputStream;
|
|
|
+ if (file1.exists()) {
|
|
|
+ fileInputStream = new FileInputStream(file1);
|
|
|
+ } else {
|
|
|
+ String path = sys_file_net_url + fileUrl.replaceAll("//", "/").replaceAll(file_path, "").replaceAll("/www/wwwroot/Users/hongchuangyanfa/Desktop/", "");
|
|
|
+ fileInputStream = CommonUtil.getOSSInputStream(path);
|
|
|
+ }
|
|
|
+ String htmlString = IoUtil.readToString(fileInputStream);
|
|
|
+ Document doc = Jsoup.parse(htmlString);
|
|
|
+ List<Map<String, Object>> htmlData1 = reflectionHtmlData1(dto.getClassId() + "");
|
|
|
+ // 按htmlKeyName分组,合并相同位置的elementValue
|
|
|
+ Map<String, String> keyValueMap = new HashMap<>();
|
|
|
+ for (Map<String, Object> item : htmlData1) {
|
|
|
+ String htmlKeyName = (String) item.get("htmlKeyName");
|
|
|
+ String elementValue = (String) item.get("elementValue");
|
|
|
+ if (keyValueMap.containsKey(htmlKeyName)) {
|
|
|
+ // 如果已存在该key,则用/分隔追加
|
|
|
+ keyValueMap.put(htmlKeyName, keyValueMap.get(htmlKeyName) + "/" + elementValue);
|
|
|
+ } else {
|
|
|
+ keyValueMap.put(htmlKeyName, elementValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 在HTML中设置trialSummaryReflection属性
|
|
|
+ for (Map.Entry<String, String> entry : keyValueMap.entrySet()) {
|
|
|
+ String keyName = entry.getKey();
|
|
|
+ String elementValue = entry.getValue();
|
|
|
+ // 查找具有指定keyname属性的元素
|
|
|
+ Element element = doc.selectFirst("[keyname='" + keyName + "']");
|
|
|
+ if (element != null) {
|
|
|
+ // 设置trialSummaryReflection属性
|
|
|
+ element.attr("trialsummaryreflection", elementValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 修改HTML文档后,保存回原文件
|
|
|
+ try (FileOutputStream outputStream = new FileOutputStream(file1)) {
|
|
|
+ outputStream.write(doc.html().getBytes(StandardCharsets.UTF_8));
|
|
|
+ }
|
|
|
return R.success("操作成功");
|
|
|
}
|
|
|
}
|
|
|
@@ -329,6 +374,10 @@ public class TrialSummaryClassificationConfigurationController extends BladeCont
|
|
|
if (query.size() > 0) {
|
|
|
Set<Long> eleIds = query.stream().map(TrialSummaryExcelTabReflection::getElementId).collect(Collectors.toSet());
|
|
|
Map<Long, WbsFormElement> eleMap = wbsFormElementService.getBaseMapper().selectBatchIds(eleIds).stream().collect(Collectors.toMap(WbsFormElement::getId, Function.identity()));
|
|
|
+
|
|
|
+ // 用于按htmlKeyName分组
|
|
|
+ Map<String, List<Map<String, Object>>> groupedMaps = new HashMap<>();
|
|
|
+
|
|
|
for (TrialSummaryExcelTabReflection obj : query) {
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
map.put("id", obj.getId());
|
|
|
@@ -341,7 +390,28 @@ public class TrialSummaryClassificationConfigurationController extends BladeCont
|
|
|
map.put("elementValue", ObjectUtil.isNotEmpty(orDefault) ? orDefault.getEName() : null);
|
|
|
}
|
|
|
map.put("htmlKeyName", obj.getHtmlKeyName());
|
|
|
- maps.add(map);
|
|
|
+
|
|
|
+ // 按htmlKeyName分组
|
|
|
+ groupedMaps.computeIfAbsent(obj.getHtmlKeyName(), k -> new ArrayList<>()).add(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 合并相同htmlKeyName的条目
|
|
|
+ for (Map.Entry<String, List<Map<String, Object>>> entry : groupedMaps.entrySet()) {
|
|
|
+ List<Map<String, Object>> group = entry.getValue();
|
|
|
+ if (group.size() > 1) {
|
|
|
+ // 如果有多个相同的htmlKeyName,合并为一个
|
|
|
+ Map<String, Object> mergedMap = new HashMap<>();
|
|
|
+ mergedMap.put("htmlKeyName", entry.getKey());
|
|
|
+ mergedMap.put("elementValue", "多元素");
|
|
|
+ // 保留第一个条目的其他属性
|
|
|
+ mergedMap.put("id", group.get(0).get("id"));
|
|
|
+ mergedMap.put("trialTabId", group.get(0).get("trialTabId"));
|
|
|
+ mergedMap.put("elementId", group.get(0).get("elementId"));
|
|
|
+ maps.add(mergedMap);
|
|
|
+ } else {
|
|
|
+ // 只有一个条目,直接添加
|
|
|
+ maps.add(group.get(0));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -349,4 +419,33 @@ public class TrialSummaryClassificationConfigurationController extends BladeCont
|
|
|
return R.data(maps);
|
|
|
}
|
|
|
|
|
|
+ public List<Map<String, Object>> reflectionHtmlData1(@RequestParam String id) {
|
|
|
+ List<Map<String, Object>> maps = new LinkedList<>();
|
|
|
+ if (ObjectUtil.isNotEmpty(id)) {
|
|
|
+ TrialSummaryClassificationConfiguration clazz = iTrialSummaryClassificationConfigurationService.getById(id);
|
|
|
+ if (clazz != null) {
|
|
|
+ List<TrialSummaryExcelTabReflection> query = jdbcTemplate.query("SELECT * FROM m_trial_summary_excel_tab_reflection WHERE class_id = ?", new Object[]{id}, new BeanPropertyRowMapper<>(TrialSummaryExcelTabReflection.class));
|
|
|
+ if (query.size() > 0) {
|
|
|
+ Set<Long> eleIds = query.stream().map(TrialSummaryExcelTabReflection::getElementId).collect(Collectors.toSet());
|
|
|
+ Map<Long, WbsFormElement> eleMap = wbsFormElementService.getBaseMapper().selectBatchIds(eleIds).stream().collect(Collectors.toMap(WbsFormElement::getId, Function.identity()));
|
|
|
+ for (TrialSummaryExcelTabReflection obj : query) {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("id", obj.getId());
|
|
|
+ map.put("trialTabId", obj.getTrialTabId());
|
|
|
+ map.put("elementId", obj.getElementId());
|
|
|
+ if (TrialTableDataInfo.LONG_ID.equals(obj.getTrialTabId())) {
|
|
|
+ map.put("elementValue", TrialTableDataInfo.getElementName(obj.getElementKey()));
|
|
|
+ } else {
|
|
|
+ WbsFormElement orDefault = eleMap.getOrDefault(obj.getElementId(), null);
|
|
|
+ map.put("elementValue", ObjectUtil.isNotEmpty(orDefault) ? orDefault.getEName() : null);
|
|
|
+ }
|
|
|
+ map.put("htmlKeyName", obj.getHtmlKeyName());
|
|
|
+ maps.add(map);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return maps;
|
|
|
+ }
|
|
|
+
|
|
|
}
|