|
@@ -8,9 +8,7 @@ import com.jeeplus.modules.WorkKnowledgeBase.dao.WorkKnowledgeBaseDynamicInfoDao
|
|
|
import com.jeeplus.modules.WorkKnowledgeBase.dao.WorkKnowledgeBaseDynamicValueInfoDao;
|
|
import com.jeeplus.modules.WorkKnowledgeBase.dao.WorkKnowledgeBaseDynamicValueInfoDao;
|
|
|
import com.jeeplus.modules.WorkKnowledgeBase.dao.WorkKnowledgeBaseShareInfoDao;
|
|
import com.jeeplus.modules.WorkKnowledgeBase.dao.WorkKnowledgeBaseShareInfoDao;
|
|
|
import com.jeeplus.modules.WorkKnowledgeBase.dao.WorkKnowledgeBaseTreeInfoDao;
|
|
import com.jeeplus.modules.WorkKnowledgeBase.dao.WorkKnowledgeBaseTreeInfoDao;
|
|
|
-import com.jeeplus.modules.WorkKnowledgeBase.entity.WorkKnowledgeBaseDynamicInfo;
|
|
|
|
|
-import com.jeeplus.modules.WorkKnowledgeBase.entity.WorkKnowledgeBaseDynamicValueInfo;
|
|
|
|
|
-import com.jeeplus.modules.WorkKnowledgeBase.entity.WorkKnowledgeBaseShareInfo;
|
|
|
|
|
|
|
+import com.jeeplus.modules.WorkKnowledgeBase.entity.*;
|
|
|
import com.jeeplus.modules.sys.entity.Workattachment;
|
|
import com.jeeplus.modules.sys.entity.Workattachment;
|
|
|
import com.jeeplus.modules.sys.service.WorkattachmentService;
|
|
import com.jeeplus.modules.sys.service.WorkattachmentService;
|
|
|
import com.jeeplus.modules.sys.utils.UserUtils;
|
|
import com.jeeplus.modules.sys.utils.UserUtils;
|
|
@@ -108,6 +106,7 @@ public class WorkKnowledgeBaseShareService extends CrudService<WorkKnowledgeBase
|
|
|
for (Map<String, Object> map : list) {
|
|
for (Map<String, Object> map : list) {
|
|
|
map.put("uploadMode", entity.getUploadMode());
|
|
map.put("uploadMode", entity.getUploadMode());
|
|
|
}
|
|
}
|
|
|
|
|
+ // 处理附件url
|
|
|
workattachmentService.attachmentManageByUrlOnWorkKnowledgeBaseShare(list);
|
|
workattachmentService.attachmentManageByUrlOnWorkKnowledgeBaseShare(list);
|
|
|
page.setList(list);
|
|
page.setList(list);
|
|
|
} else {
|
|
} else {
|
|
@@ -220,4 +219,114 @@ public class WorkKnowledgeBaseShareService extends CrudService<WorkKnowledgeBase
|
|
|
public String getRootIdByNodeId(String nodeId) {
|
|
public String getRootIdByNodeId(String nodeId) {
|
|
|
return treeInfoDao.getRootIdByNodeId(nodeId);
|
|
return treeInfoDao.getRootIdByNodeId(nodeId);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 查询所有根节点(parent_id='0'的节点)
|
|
|
|
|
+ */
|
|
|
|
|
+ public List<WorkKnowledgeBaseTreeInfo> findRootNodes() {
|
|
|
|
|
+ return treeInfoDao.findRootNodes();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 导入知识库数据
|
|
|
|
|
+ * @param dataList Excel解析后的数据列表
|
|
|
|
|
+ * @param rootId 根节点id
|
|
|
|
|
+ * @return 导入结果描述
|
|
|
|
|
+ */
|
|
|
|
|
+ @Transactional(readOnly = false)
|
|
|
|
|
+ public String importData(List<WorkKnowledgeBaseImportInfo> dataList, String rootId) {
|
|
|
|
|
+ if (dataList == null || dataList.isEmpty()) {
|
|
|
|
|
+ return "导入数据为空!";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 查询该根节点下的动态字段配置,用于将导入字段映射为动态字段id
|
|
|
|
|
+ List<WorkKnowledgeBaseDynamicInfo> dynamicFields = dynamicInfoDao.findByRootId(rootId);
|
|
|
|
|
+ // 构建 fieldKey -> fieldId 的映射
|
|
|
|
|
+ Map<String, String> fieldKeyToIdMap = new HashMap<>();
|
|
|
|
|
+ for (WorkKnowledgeBaseDynamicInfo field : dynamicFields) {
|
|
|
|
|
+ fieldKeyToIdMap.put(field.getFieldKey(), field.getId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ int successCount = 0;
|
|
|
|
|
+ int failCount = 0;
|
|
|
|
|
+ StringBuilder failureMsg = new StringBuilder();
|
|
|
|
|
+
|
|
|
|
|
+ for (int i = 0; i < dataList.size(); i++) {
|
|
|
|
|
+ WorkKnowledgeBaseImportInfo importInfo = dataList.get(i);
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 1. 根据体系节点名称查找对应的树节点id
|
|
|
|
|
+ String systemNodeName = importInfo.getSystemNodeName();
|
|
|
|
|
+ if (StringUtils.isBlank(systemNodeName)) {
|
|
|
|
|
+ failCount++;
|
|
|
|
|
+ failureMsg.append("<br/>第").append(i + 2).append("行:体系节点名称为空,跳过;");
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ String treeNodeId = treeInfoDao.findIdByTreeName(systemNodeName.trim());
|
|
|
|
|
+ if (StringUtils.isBlank(treeNodeId)) {
|
|
|
|
|
+ failCount++;
|
|
|
|
|
+ failureMsg.append("<br/>第").append(i + 2).append("行:未找到体系节点[").append(systemNodeName).append("],跳过;");
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 标准名称为必填项
|
|
|
|
|
+ String standardName = importInfo.getStandardName();
|
|
|
|
|
+ if (StringUtils.isBlank(standardName)) {
|
|
|
|
|
+ failCount++;
|
|
|
|
|
+ failureMsg.append("<br/>第").append(i + 2).append("行:标准名称为空,跳过;");
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 新增 work_knowledge_base_share_info 记录
|
|
|
|
|
+ WorkKnowledgeBaseShareInfo shareInfo = new WorkKnowledgeBaseShareInfo();
|
|
|
|
|
+ shareInfo.setIsNewRecord(true);
|
|
|
|
|
+ shareInfo.setId(IdGen.uuid());
|
|
|
|
|
+ shareInfo.setTreeNodeId(treeNodeId);
|
|
|
|
|
+ shareInfo.setName(standardName.trim());
|
|
|
|
|
+ shareInfo.preInsert();
|
|
|
|
|
+ dao.insert(shareInfo);
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 将其余字段作为动态字段值插入
|
|
|
|
|
+ insertDynamicValue(shareInfo.getId(), "SerialNumber", importInfo.getStandardSystemCode(), fieldKeyToIdMap);
|
|
|
|
|
+ insertDynamicValue(shareInfo.getId(), "StandardNum", importInfo.getStandardNoOrDocumentNo(), fieldKeyToIdMap);
|
|
|
|
|
+ insertDynamicValue(shareInfo.getId(), "ForwardingNum", importInfo.getTransmitDocumentNo(), fieldKeyToIdMap);
|
|
|
|
|
+ insertDynamicValue(shareInfo.getId(), "IssuingDep", importInfo.getPublishDepartment(), fieldKeyToIdMap);
|
|
|
|
|
+ insertDynamicValue(shareInfo.getId(), "EffectiveDate", importInfo.getEffectiveDate() != null ? new java.text.SimpleDateFormat("yyyy-MM-dd").format(importInfo.getEffectiveDate()) : "", fieldKeyToIdMap);
|
|
|
|
|
+ insertDynamicValue(shareInfo.getId(), "StandardLevel", importInfo.getStandardLevel(), fieldKeyToIdMap);
|
|
|
|
|
+ insertDynamicValue(shareInfo.getId(), "VoltageLevel", importInfo.getVoltageLevel(), fieldKeyToIdMap);
|
|
|
|
|
+ insertDynamicValue(shareInfo.getId(), "ProjectType", importInfo.getProjectType(), fieldKeyToIdMap);
|
|
|
|
|
+ insertDynamicValue(shareInfo.getId(), "PreparationStatus", importInfo.getCompileStatus(), fieldKeyToIdMap);
|
|
|
|
|
+ insertDynamicValue(shareInfo.getId(), "SupersededStandardNum", importInfo.getReplacedStandardNoAndName(), fieldKeyToIdMap);
|
|
|
|
|
+ insertDynamicValue(shareInfo.getId(), "StandardRelationship", importInfo.getStandardRelation(), fieldKeyToIdMap);
|
|
|
|
|
+ insertDynamicValue(shareInfo.getId(), "remarks", importInfo.getRemark(), fieldKeyToIdMap);
|
|
|
|
|
+
|
|
|
|
|
+ successCount++;
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ failCount++;
|
|
|
|
|
+ failureMsg.append("<br/>第").append(i + 2).append("行导入失败:").append(e.getMessage()).append(";");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String resultMsg = "成功导入 " + successCount + " 条记录";
|
|
|
|
|
+ if (failCount > 0) {
|
|
|
|
|
+ resultMsg += ",失败 " + failCount + " 条:" + failureMsg.toString();
|
|
|
|
|
+ }
|
|
|
|
|
+ return resultMsg;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 插入单个动态字段值
|
|
|
|
|
+ */
|
|
|
|
|
+ private void insertDynamicValue(String fileId, String fieldKey, String fieldValue, Map<String, String> fieldKeyToIdMap) {
|
|
|
|
|
+ String dynamicFieldId = fieldKeyToIdMap.get(fieldKey);
|
|
|
|
|
+ if (StringUtils.isBlank(dynamicFieldId) || StringUtils.isBlank(fieldValue)) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ WorkKnowledgeBaseDynamicValueInfo valueInfo = new WorkKnowledgeBaseDynamicValueInfo();
|
|
|
|
|
+ valueInfo.setId(IdGen.uuid());
|
|
|
|
|
+ valueInfo.setFileId(fileId);
|
|
|
|
|
+ valueInfo.setDynamicFieldId(dynamicFieldId);
|
|
|
|
|
+ valueInfo.setFieldValue(fieldValue.trim());
|
|
|
|
|
+ valueInfo.preInsert();
|
|
|
|
|
+ dynamicValueInfoDao.insert(valueInfo);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|