diff --git a/com.actionsoft.apps.coe.pal.datamigration/lib/com.actionsoft.apps.coe.pal.datamigration.jar b/com.actionsoft.apps.coe.pal.datamigration/lib/com.actionsoft.apps.coe.pal.datamigration.jar index df178116..e55e8045 100644 Binary files a/com.actionsoft.apps.coe.pal.datamigration/lib/com.actionsoft.apps.coe.pal.datamigration.jar and b/com.actionsoft.apps.coe.pal.datamigration/lib/com.actionsoft.apps.coe.pal.datamigration.jar differ diff --git a/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/DataMigrationController.java b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/DataMigrationController.java index 381ddc2e..a44c00c9 100644 --- a/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/DataMigrationController.java +++ b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/DataMigrationController.java @@ -26,9 +26,17 @@ public class DataMigrationController { return new DataMigrationWeb(uc).dataMigrate(wsId,groupValue,fileValue,fileName); } + /** + * 流程属性批量导入 + * @param uc + * @param wsId + * @param groupValue + * @param fileValue + * @return + */ @Mapping("com.actionsoft.apps.coe.pal.datamigration_process_attribute_import") - public String processAttributeImport(UserContext uc, String wsId,String groupValue,String fileValue,String fileName){ - return new DataMigrationWeb(uc).processAttributeImport(wsId,groupValue,fileValue,fileName); + public String processAttributeImport(UserContext uc, String wsId,String groupValue,String fileValue){ + return new DataMigrationWeb(uc).processAttributeImport(wsId,groupValue,fileValue); } @Mapping("com.actionsoft.apps.coe.pal.datamigration_IT_attribute_import") diff --git a/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/web/DataMigrationWeb.java b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/web/DataMigrationWeb.java index e5a16b44..1c0c7357 100644 --- a/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/web/DataMigrationWeb.java +++ b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/web/DataMigrationWeb.java @@ -126,185 +126,26 @@ public class DataMigrationWeb extends ActionWeb { * @param fileName * @return */ - public String processAttributeImport(String wsId, String groupValue, String fileValue, String fileName) { + public String processAttributeImport(String wsId, String groupValue, String fileValue) { ResponseObject ro = ResponseObject.newOkResponse(); //构建DCContext 获取上传文件 - DCContext fileDcContext = this.getFileDcContext(groupValue, fileValue, fileName); + DCContext fileDcContext = this.getFileDcContext(groupValue, fileValue); if (null == fileDcContext) { return ResponseObject.newErrResponse("文件参数异常").toString(); } - //解析Word文档 - WordUtil wordUtil = new WordUtil(); - boolean analysisFlag = wordUtil.analysisWordTable(fileDcContext.getFilePath()); -// boolean analysisFlag = wordUtil.analysisWordTable("/Users/actionsoft/Documents/IdeaWorkSpace/demo/src/main/resources/伊利集团流程制度类文件发布流程vf.doc"); - if (!analysisFlag) { - return ResponseObject.newErrResponse("文件解析异常").toString(); - } - - //获取解析后的文件名称,同名策略匹配pal寻找对应文件 - String repositoryName = wordUtil.getFileName(); - PALRepositoryModel importModel = this.getRepositoryByName(wsId, repositoryName); - if (null == importModel) { - return ResponseObject.newErrResponse("匹配pal文件异常,找不到同名文件").toString(); - } - - Map> fileFieldMap = wordUtil.getFileFieldMap(); - //获取导入文件对应的关联文件属性list - PALRepositoryPropertyDao propDao = new PALRepositoryPropertyDao(); - DesignerShapeRelationDao relationDao = new DesignerShapeRelationDao(); - List importPropertyList = propDao.getPropertysByPlid(importModel.getId(), ""); - for (PALRepositoryPropertyModel importProperty : importPropertyList) { - WordField wordField = fileFieldMap.get(importProperty.getPropertyName()); - //旧版本的映射字段支持 - if (null == wordField && wordUtil.getIsOldVersion()) { - Map oldWordMapping = wordUtil.getOldWordMapping(); - for (String s : oldWordMapping.keySet()) { - if (s.equals(importProperty.getPropertyName())) { - String s1 = oldWordMapping.get(s); - wordField = fileFieldMap.get(s1); - } - } -// wordField = fileFieldMap.get(oldWordMapping.get(importProperty.getPropertyName())); - } - if (null == wordField) { - continue; - } - //使用缓存获取具体建模属性 - PALRepositoryAttributeModel repositoryAttrModel = PALRepositoryAttributeCache.getAttributeByMethodIdAndAttrId(wsId, importModel.getMethodId(), importProperty.getPropertyId()); - if (null == repositoryAttrModel) { - continue; - } - if ("table".equals(repositoryAttrModel.getType())) { - //将解析的列表数据转化为数据存储json - JSONObject object = new JSONObject(); - object.put("name", importProperty.getPropertyName()); - JSONArray array = new JSONArray(); - List> tableFields = (List>) wordField.getData(); - if (!tableFields.isEmpty()) { - for (List value : tableFields) { - if (!value.isEmpty() && value.size() > 1) { - JSONObject obj = new JSONObject(); - obj.put("id", UUIDGener.getUUID()); - obj.put("name", value.get(0)); - obj.put("desc", value.get(1)); - array.add(obj); - } - } - } - if (array.size() > 0) { - //特殊处理表头 - PALMethodAttributeModel attributeModel = null; - List attributes = PALMethodCache.getPALMethodModelById(importModel.getMethodId()).getAttributes(); - for (PALMethodAttributeModel attribute : attributes) { - if (attribute.getType().equals(importProperty.getPropertyId())){ - attributeModel = attribute; - } - } - if (null == attributeModel || StringUtils.isEmpty(attributeModel.getRef())){ - array.getJSONObject(0).put("id", "table_head"); - }else{ - JSONObject attrRef = JSON.parseObject(attributeModel.getRef()); - array.getJSONObject(0).put("id", "table_head"); - array.getJSONObject(0).put("id", attrRef.get("firstColumn")); - array.getJSONObject(0).put("id", attrRef.get("secondColumn")); - } - } - object.put("table", array); - //更新数据库值 - importProperty.setPropertyValue(object.toJSONString()); - propDao.update(importProperty); - } else if ("awsorg".equals(repositoryAttrModel.getType())) { - //aws组织架构解析,多组结构解析 - String orgName = (String) wordField.getData(); - List awsOrgInfos = this.getOrgByName(orgName); - if (!awsOrgInfos.isEmpty()) { - //先更新property数据 [{"name":"部门3","id":"fdea04c8-502f-4367-82b7-a5ebe0ce5f67","type":"department"}] - importProperty.setPropertyValue(JSON.toJSONString(awsOrgInfos)); - propDao.update(importProperty); - - //先删除property关联关系,然后新增关系 - relationDao.deleteByAttrId(importModel.getId(), "", importProperty.getPropertyId()); - for (AwsOrgInfo awsOrgInfo : awsOrgInfos) { - DesignerShapeRelationModel model = new DesignerShapeRelationModel(); - model.setFileId(importModel.getId()); - model.setShapeId(""); - model.setShapeText(""); - model.setAttrId(importProperty.getPropertyId()); - model.setRelationFileId("00000000-0000-0000-0000-000000000000"); - model.setRelationShapeId("00000000-0000-0000-0000-000000000000"); - model.setRelationShapeText(JSON.toJSONString(awsOrgInfo)); - relationDao.insert(model); - } - } - } else if ("relation".equals(repositoryAttrModel.getType())) { - //关联文件 - List fileList = new ArrayList<>(); - List relations = (List) wordField.getData(); - for (String relation : relations) { - PALRepositoryModel repository = this.getRepositoryByName(wsId, this.trimFileName(relation)); - if (repository != null) { - fileList.add(repository); - } - - } - - //更新property数据 - String relationFileIds = ""; - for (PALRepositoryModel model : fileList) { - relationFileIds += model.getId() + ","; - } - if (relationFileIds.length() > 1) { - relationFileIds = relationFileIds.substring(0, relationFileIds.length() - 1); - } - JSONObject propertyJson = JSON.parseObject(importProperty.getPropertyValue()); - propertyJson.put("relationFileId", relationFileIds); - importProperty.setPropertyValue(propertyJson.toJSONString()); - propDao.update(importProperty); - - //先删除property关联关系,然后新增关系 - if (!fileList.isEmpty()) { - relationDao.deleteByAttrId(importModel.getId(), "", importProperty.getPropertyId()); - for (PALRepositoryModel repositoryModel : fileList) { - DesignerShapeRelationModel relationModel = new DesignerShapeRelationModel(); - relationModel.setFileId(importModel.getId()); - relationModel.setShapeId(""); - relationModel.setShapeText(""); - relationModel.setAttrId(importProperty.getPropertyId()); - relationModel.setRelationFileId(repositoryModel.getVersionId()); - relationModel.setRelationShapeId(""); - relationModel.setRelationShapeText(repositoryModel.getName()); - relationDao.insert(relationModel); - } - } - - } else if ("select".equals(repositoryAttrModel.getType()) || "select_m".equals(repositoryAttrModel.getType())) { - - } else if ("boolean".equals(repositoryAttrModel.getType())) { - - } else if ("DateTimePicker".equals(repositoryAttrModel.getType())) { - String time = (String) wordField.getData(); - try { - Date formatTime = new SimpleDateFormat("yyyy年MM月dd日").parse(time); - time = UtilDate.datetimeFormat(formatTime); - } catch (ParseException e) { - e.printStackTrace(); - } - //更新数据库值 - importProperty.setPropertyValue(time); - propDao.update(importProperty); - } else { - if (wordField.getData() instanceof String) { - //直接获取Word解析字符内容 - String value = (String) wordField.getData(); - //更新数据库值 - importProperty.setPropertyValue(value); - propDao.update(importProperty); + //批量解析文档 + File dirFile = new File(fileDcContext.getPath()); + File[] fileArr = dirFile.listFiles(); + new Thread(new Runnable() { + @Override + public void run() { + for (File file : fileArr) { + new DataMigrationWeb().analysisWord(wsId, file.getPath()); } } - - } + }).start(); return ro.toString(); } @@ -534,6 +375,187 @@ public class DataMigrationWeb extends ActionWeb { return index == null ? 0 : index; } + private ResponseObject analysisWord(String wsId,String filePath){ + //解析Word文档 + WordUtil wordUtil = new WordUtil(); + boolean analysisFlag = wordUtil.analysisWordTable(filePath); + if (!analysisFlag) { + return ResponseObject.newErrResponse("文件解析异常"); + } + + //获取解析后的文件名称,同名策略匹配pal寻找对应文件 + String repositoryName = wordUtil.getFileName(); + PALRepositoryModel importModel = this.getRepositoryByName(wsId, repositoryName); + if (null == importModel) { + return ResponseObject.newErrResponse("匹配pal文件异常,找不到同名文件"); + } + + Map> fileFieldMap = wordUtil.getFileFieldMap(); + //获取导入文件对应的关联文件属性list + PALRepositoryPropertyDao propDao = new PALRepositoryPropertyDao(); + DesignerShapeRelationDao relationDao = new DesignerShapeRelationDao(); + List importPropertyList = propDao.getPropertysByPlid(importModel.getId(), ""); + for (PALRepositoryPropertyModel importProperty : importPropertyList) { + WordField wordField = fileFieldMap.get(importProperty.getPropertyName()); + //旧版本的映射字段支持 + if (null == wordField && wordUtil.getIsOldVersion()) { + Map oldWordMapping = wordUtil.getOldWordMapping(); + for (String s : oldWordMapping.keySet()) { + if (s.equals(importProperty.getPropertyName())) { + String s1 = oldWordMapping.get(s); + wordField = fileFieldMap.get(s1); + } + } + } + if (null == wordField) { + continue; + } + //使用缓存获取具体建模属性 + PALRepositoryAttributeModel repositoryAttrModel = PALRepositoryAttributeCache.getAttributeByMethodIdAndAttrId(wsId, importModel.getMethodId(), importProperty.getPropertyId()); + if (null == repositoryAttrModel) { + continue; + } + if ("table".equals(repositoryAttrModel.getType())) { + //将解析的列表数据转化为数据存储json + JSONObject object = new JSONObject(); + object.put("name", importProperty.getPropertyName()); + JSONArray array = new JSONArray(); + List> tableFields = (List>) wordField.getData(); + if (!tableFields.isEmpty()) { + for (List value : tableFields) { + if (!value.isEmpty() && value.size() > 1) { + JSONObject obj = new JSONObject(); + obj.put("id", UUIDGener.getUUID()); + obj.put("name", value.get(0)); + obj.put("desc", value.get(1)); + array.add(obj); + } + } + } + if (array.size() > 0) { + //特殊处理表头 + PALMethodAttributeModel attributeModel = null; + List attributes = PALMethodCache.getPALMethodModelById(importModel.getMethodId()).getAttributes(); + for (PALMethodAttributeModel attribute : attributes) { + if (attribute.getType().equals(importProperty.getPropertyId())){ + attributeModel = attribute; + } + } + if (null == attributeModel || StringUtils.isEmpty(attributeModel.getRef())){ + array.getJSONObject(0).put("id", "table_head"); + }else{ + JSONObject attrRef = JSON.parseObject(attributeModel.getRef()); + array.getJSONObject(0).put("id", "table_head"); + array.getJSONObject(0).put("id", attrRef.get("firstColumn")); + array.getJSONObject(0).put("id", attrRef.get("secondColumn")); + } + } + object.put("table", array); + //更新数据库值 + importProperty.setPropertyValue(object.toJSONString()); + propDao.update(importProperty); + } else if ("awsorg".equals(repositoryAttrModel.getType())) { + //aws组织架构解析,多组结构解析 + String orgName = (String) wordField.getData(); + List awsOrgInfos = this.getOrgByName(orgName); + if (!awsOrgInfos.isEmpty()) { + //先更新property数据 [{"name":"部门3","id":"fdea04c8-502f-4367-82b7-a5ebe0ce5f67","type":"department"}] + importProperty.setPropertyValue(JSON.toJSONString(awsOrgInfos)); + propDao.update(importProperty); + + //先删除property关联关系,然后新增关系 + relationDao.deleteByAttrId(importModel.getId(), "", importProperty.getPropertyId()); + for (AwsOrgInfo awsOrgInfo : awsOrgInfos) { + DesignerShapeRelationModel model = new DesignerShapeRelationModel(); + model.setFileId(importModel.getId()); + model.setShapeId(""); + model.setShapeText(""); + model.setAttrId(importProperty.getPropertyId()); + model.setRelationFileId("00000000-0000-0000-0000-000000000000"); + model.setRelationShapeId("00000000-0000-0000-0000-000000000000"); + model.setRelationShapeText(JSON.toJSONString(awsOrgInfo)); + relationDao.insert(model); + } + } + } else if ("relation".equals(repositoryAttrModel.getType())) { + //关联文件 + List fileList = new ArrayList<>(); + List relations = (List) wordField.getData(); + for (String relation : relations) { + PALRepositoryModel repository = this.getRepositoryByName(wsId, this.trimFileName(relation)); + if (repository != null) { + fileList.add(repository); + } + } + + //更新property数据 + String relationFileIds = ""; + for (PALRepositoryModel model : fileList) { + relationFileIds += model.getId() + ","; + } + if (relationFileIds.length() > 1) { + relationFileIds = relationFileIds.substring(0, relationFileIds.length() - 1); + } + JSONObject propertyJson = JSON.parseObject(importProperty.getPropertyValue()); + propertyJson.put("relationFileId", relationFileIds); + importProperty.setPropertyValue(propertyJson.toJSONString()); + propDao.update(importProperty); + + //先删除property关联关系,然后新增关系 + if (!fileList.isEmpty()) { + relationDao.deleteByAttrId(importModel.getId(), "", importProperty.getPropertyId()); + for (PALRepositoryModel repositoryModel : fileList) { + DesignerShapeRelationModel relationModel = new DesignerShapeRelationModel(); + relationModel.setFileId(importModel.getId()); + relationModel.setShapeId(""); + relationModel.setShapeText(""); + relationModel.setAttrId(importProperty.getPropertyId()); + relationModel.setRelationFileId(repositoryModel.getVersionId()); + relationModel.setRelationShapeId(""); + relationModel.setRelationShapeText(repositoryModel.getName()); + relationDao.insert(relationModel); + } + } + + } else if ("select".equals(repositoryAttrModel.getType()) || "select_m".equals(repositoryAttrModel.getType())) { + + } else if ("boolean".equals(repositoryAttrModel.getType())) { + + } else if ("DateTimePicker".equals(repositoryAttrModel.getType())) { + String time = (String) wordField.getData(); + try { + Date formatTime = new SimpleDateFormat("yyyy年MM月dd日").parse(time); + time = UtilDate.datetimeFormat(formatTime); + } catch (ParseException e) { + e.printStackTrace(); + } + //更新数据库值 + importProperty.setPropertyValue(time); + propDao.update(importProperty); + } else { + if (wordField.getData() instanceof String) { + //直接获取Word解析字符内容 + String value = (String) wordField.getData(); + //更新数据库值 + importProperty.setPropertyValue(value); + propDao.update(importProperty); + } + } + + } + return ResponseObject.newOkResponse("导入成功"); + } + + private DCContext getFileDcContext(String groupValue, String fileValue) { + DCContext context = null; + + DCPluginProfile dcProfile = DCProfileManager.getDCProfile(Constant.APP_ID, Constant.UPFILE); + if (null != dcProfile) { + context = new DCContext(super.getContext(), dcProfile, Constant.APP_ID, groupValue, fileValue); + } + + return context; + } private DCContext getFileDcContext(String groupValue, String fileValue, String fileName) { DCContext context = null; diff --git a/com.actionsoft.apps.coe.pal.datamigration/web/com.actionsoft.apps.coe.pal.datamigration/action.xml b/com.actionsoft.apps.coe.pal.datamigration/web/com.actionsoft.apps.coe.pal.datamigration/action.xml index 0796186c..124e1a7e 100644 --- a/com.actionsoft.apps.coe.pal.datamigration/web/com.actionsoft.apps.coe.pal.datamigration/action.xml +++ b/com.actionsoft.apps.coe.pal.datamigration/web/com.actionsoft.apps.coe.pal.datamigration/action.xml @@ -10,7 +10,7 @@ - +