|
|
@@ -10,6 +10,7 @@ import org.apache.commons.lang.StringUtils;
|
|
|
import org.jsoup.Jsoup;
|
|
|
import org.jsoup.nodes.Document;
|
|
|
import org.jsoup.nodes.Element;
|
|
|
+import org.jsoup.select.Elements;
|
|
|
import org.springblade.common.constant.CommonConstant;
|
|
|
import org.springblade.common.utils.CommonUtil;
|
|
|
import org.springblade.common.utils.SnowFlakeUtil;
|
|
|
@@ -39,9 +40,11 @@ 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;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
@@ -147,6 +150,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();
|
|
|
@@ -211,35 +216,43 @@ public class TrialSummaryClassificationConfigurationController extends BladeCont
|
|
|
@RequestMapping(value = "/input/detail", method = RequestMethod.GET)
|
|
|
public R<Object> inputDetail(@RequestParam String classId, @RequestParam String keyName) {
|
|
|
TrialSummaryClassificationConfiguration classificationConfiguration = iTrialSummaryClassificationConfigurationService.getById(classId);
|
|
|
+ List<Map<String, String>> r=new ArrayList<>();
|
|
|
if (classificationConfiguration != null && ObjectUtil.isNotEmpty(classificationConfiguration.getExcelId())) {
|
|
|
String sql = "SELECT * FROM m_trial_summary_excel_tab_reflection WHERE excel_id = ? AND html_key_name = ?";
|
|
|
- TrialSummaryExcelTabReflection obj = jdbcTemplate.query(sql, new Object[]{classificationConfiguration.getExcelId(), keyName}, new BeanPropertyRowMapper<>(TrialSummaryExcelTabReflection.class)).stream().findAny().orElse(null);
|
|
|
- if (obj != null) {
|
|
|
- if (TrialTableDataInfo.LONG_ID.equals(obj.getTrialTabId())) {
|
|
|
- Map<String, String> map = new HashMap<>();
|
|
|
- map.put("id", obj.getId().toString());
|
|
|
- map.put("tabName", TrialTableDataInfo.TBN_CH);
|
|
|
- map.put("elementName", TrialTableDataInfo.getElementName(obj.getElementKey()));
|
|
|
- return R.data(map);
|
|
|
- }
|
|
|
- WbsTreePrivate trialTab = wbsTreePrivateServiceImpl.getBaseMapper().getByPKeyId(obj.getTrialTabId());
|
|
|
- WbsFormElement element = wbsFormElementService.getById(obj.getElementId());
|
|
|
- if (trialTab != null && element != null) {
|
|
|
- Map<String, String> map = new HashMap<>();
|
|
|
- map.put("id", obj.getId().toString());
|
|
|
- map.put("tabName", ObjectUtil.isNotEmpty(trialTab.getFullName()) ? trialTab.getFullName() : trialTab.getNodeName());
|
|
|
- map.put("elementName", element.getEName());
|
|
|
- return R.data(map);
|
|
|
+ List<TrialSummaryExcelTabReflection> list = jdbcTemplate.query(sql, new Object[]{classificationConfiguration.getExcelId(), keyName}, new BeanPropertyRowMapper<>(TrialSummaryExcelTabReflection.class));
|
|
|
+ if (list != null) {
|
|
|
+ for (TrialSummaryExcelTabReflection obj : list) {
|
|
|
+ if (TrialTableDataInfo.LONG_ID.equals(obj.getTrialTabId())) {
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ map.put("id", obj.getId().toString());
|
|
|
+ map.put("tabName", TrialTableDataInfo.TBN_CH);
|
|
|
+ map.put("elementName", TrialTableDataInfo.getElementName(obj.getElementKey()));
|
|
|
+ map.put("trialTabId",TrialTableDataInfo.LONG_ID+"");
|
|
|
+ map.put("elementId",TrialTableDataInfo.getElementId(obj.getElementKey())+"");
|
|
|
+ r.add( map);
|
|
|
+ }else {
|
|
|
+ WbsTreePrivate trialTab = wbsTreePrivateServiceImpl.getBaseMapper().getByPKeyId(obj.getTrialTabId());
|
|
|
+ WbsFormElement element = wbsFormElementService.getById(obj.getElementId());
|
|
|
+ if (trialTab != null && element != null) {
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ map.put("id", obj.getId().toString());
|
|
|
+ map.put("tabName", ObjectUtil.isNotEmpty(trialTab.getFullName()) ? trialTab.getFullName() : trialTab.getNodeName());
|
|
|
+ map.put("elementName", element.getEName());
|
|
|
+ map.put("trialTabId",obj.getTrialTabId()+"");
|
|
|
+ map.put("elementId",obj.getElementId()+"");
|
|
|
+ r.add(map);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- return R.data(null);
|
|
|
+ return R.data(r);
|
|
|
}
|
|
|
|
|
|
@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("操作成功");
|
|
|
@@ -248,37 +261,89 @@ public class TrialSummaryClassificationConfigurationController extends BladeCont
|
|
|
if (classificationConfiguration != null && ObjectUtil.isNotEmpty(classificationConfiguration.getExcelId())) {
|
|
|
List<TrialSummaryReflectionSaveDTO.ReflectionBean> reflectionBeanList = dto.getReflectionBeanList();
|
|
|
Set<TrialSummaryReflectionSaveDTO.ReflectionBean> collect = new HashSet<>(reflectionBeanList);
|
|
|
+ Set<TrialSummaryReflectionSaveDTO.ReflectionBean> updateList = collect.stream().filter(bean -> ObjectUtil.isNotEmpty(bean.getId())).collect(Collectors.toSet());
|
|
|
+ Set<TrialSummaryReflectionSaveDTO.ReflectionBean> insertList = collect.stream().filter(bean -> ObjectUtil.isEmpty(bean.getId())).collect(Collectors.toSet());
|
|
|
+
|
|
|
List<String> keyNameList = collect.stream()
|
|
|
.map(bean -> "'" + bean.getHtmlKeyName() + "'")
|
|
|
.collect(Collectors.toList());
|
|
|
if (keyNameList.size() <= 0) {
|
|
|
throw new ServiceException("入参异常,未获取到htmlKeyName");
|
|
|
}
|
|
|
-
|
|
|
- String sqlDel = "DELETE FROM m_trial_summary_excel_tab_reflection WHERE excel_id = ? AND class_id = ? AND html_key_name IN (" +
|
|
|
- StringUtils.join(keyNameList, ",") + ")";
|
|
|
- List<Object> paramsDel = new ArrayList<>();
|
|
|
- paramsDel.add(classificationConfiguration.getExcelId());
|
|
|
- paramsDel.add(classificationConfiguration.getId());
|
|
|
- jdbcTemplate.update(sqlDel, paramsDel.toArray());
|
|
|
-
|
|
|
- String sqlInsert = "INSERT INTO m_trial_summary_excel_tab_reflection(id,class_id,excel_id,trial_tab_id,element_id,html_key_name,trial_tab_name,element_key) VALUES (?,?,?,?,?,?,?,?)";
|
|
|
- List<Object[]> batchArgs = new ArrayList<>();
|
|
|
- for (TrialSummaryReflectionSaveDTO.ReflectionBean reflectionBean : collect) {
|
|
|
- Object[] paramsInsert = {
|
|
|
- SnowFlakeUtil.getId(),
|
|
|
- classificationConfiguration.getId(),
|
|
|
- classificationConfiguration.getExcelId(),
|
|
|
- reflectionBean.getTrialTabId(),
|
|
|
- reflectionBean.getElementId(),
|
|
|
- reflectionBean.getHtmlKeyName(),
|
|
|
- reflectionBean.getTrialTabName(),
|
|
|
- reflectionBean.getElementKey()
|
|
|
- };
|
|
|
- batchArgs.add(paramsInsert);
|
|
|
+ // 批量更新已有记录
|
|
|
+ if (!updateList.isEmpty()) {
|
|
|
+ String sqlUpdate = "UPDATE m_trial_summary_excel_tab_reflection SET trial_tab_id = ?, element_id = ? WHERE id = ?";
|
|
|
+ List<Object[]> updateBatchArgs = new ArrayList<>();
|
|
|
+ for (TrialSummaryReflectionSaveDTO.ReflectionBean reflectionBean : updateList) {
|
|
|
+ Object[] paramsUpdate = {
|
|
|
+ reflectionBean.getTrialTabId(),
|
|
|
+ reflectionBean.getElementId(),
|
|
|
+ reflectionBean.getId()
|
|
|
+ };
|
|
|
+ updateBatchArgs.add(paramsUpdate);
|
|
|
+ }
|
|
|
+ jdbcTemplate.batchUpdate(sqlUpdate, updateBatchArgs);
|
|
|
+ }
|
|
|
+ if (!insertList.isEmpty()){
|
|
|
+ String sqlInsert = "INSERT INTO m_trial_summary_excel_tab_reflection(id,class_id,excel_id,trial_tab_id,element_id,html_key_name,trial_tab_name,element_key) VALUES (?,?,?,?,?,?,?,?)";
|
|
|
+ List<Object[]> batchArgs = new ArrayList<>();
|
|
|
+ for (TrialSummaryReflectionSaveDTO.ReflectionBean reflectionBean : insertList) {
|
|
|
+ Object[] paramsInsert = {
|
|
|
+ SnowFlakeUtil.getId(),
|
|
|
+ classificationConfiguration.getId(),
|
|
|
+ classificationConfiguration.getExcelId(),
|
|
|
+ reflectionBean.getTrialTabId(),
|
|
|
+ reflectionBean.getElementId(),
|
|
|
+ reflectionBean.getHtmlKeyName(),
|
|
|
+ reflectionBean.getTrialTabName(),
|
|
|
+ reflectionBean.getElementKey()
|
|
|
+ };
|
|
|
+ batchArgs.add(paramsInsert);
|
|
|
+ }
|
|
|
+ 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属性的元素
|
|
|
+ Elements element = doc.select("[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));
|
|
|
}
|
|
|
- jdbcTemplate.batchUpdate(sqlInsert, batchArgs);
|
|
|
-
|
|
|
return R.success("操作成功");
|
|
|
}
|
|
|
}
|
|
|
@@ -310,6 +375,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());
|
|
|
@@ -322,7 +391,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));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -330,4 +420,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;
|
|
|
+ }
|
|
|
+
|
|
|
}
|