diff --git a/src/com/engine/secret/entity/unpack/ApplicationResource.java b/src/com/engine/secret/entity/unpack/ApplicationResource.java new file mode 100644 index 0000000..d778014 --- /dev/null +++ b/src/com/engine/secret/entity/unpack/ApplicationResource.java @@ -0,0 +1,24 @@ +package com.engine.secret.entity.unpack; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author:dxfeng + * @createTime: 2025/03/26 + * @version: 1.0 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class ApplicationResource { + private String id; + private String aid; + private String fid; + private String rid; + private String createdTime; + private String isDelete; +} diff --git a/src/com/engine/secret/entity/unpack/DataConfig.java b/src/com/engine/secret/entity/unpack/DataConfig.java new file mode 100644 index 0000000..1b61c13 --- /dev/null +++ b/src/com/engine/secret/entity/unpack/DataConfig.java @@ -0,0 +1,28 @@ +package com.engine.secret.entity.unpack; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * @author:dxfeng + * @createTime: 2025/03/26 + * @version: 1.0 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class DataConfig { + private String id; + private String mainTableName; + private String detailTableName; + private String rootPath; + List childDataConfig; + List detailList; + List fileList; + +} diff --git a/src/com/engine/secret/entity/unpack/DataConfigDetail.java b/src/com/engine/secret/entity/unpack/DataConfigDetail.java new file mode 100644 index 0000000..ef64197 --- /dev/null +++ b/src/com/engine/secret/entity/unpack/DataConfigDetail.java @@ -0,0 +1,21 @@ +package com.engine.secret.entity.unpack; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author:dxfeng + * @createTime: 2025/03/26 + * @version: 1.0 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class DataConfigDetail { + private String fieldName; + private String path; + private String condition; +} diff --git a/src/com/engine/secret/entity/unpack/FileConfig.java b/src/com/engine/secret/entity/unpack/FileConfig.java new file mode 100644 index 0000000..1ee4c91 --- /dev/null +++ b/src/com/engine/secret/entity/unpack/FileConfig.java @@ -0,0 +1,21 @@ +package com.engine.secret.entity.unpack; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author:dxfeng + * @createTime: 2025/03/26 + * @version: 1.0 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class FileConfig { + private String filedName; + private String fileId; + private String isFilled; +} diff --git a/src/com/engine/secret/entity/unpack/ResourceInfo.java b/src/com/engine/secret/entity/unpack/ResourceInfo.java new file mode 100644 index 0000000..7c45f0b --- /dev/null +++ b/src/com/engine/secret/entity/unpack/ResourceInfo.java @@ -0,0 +1,26 @@ +package com.engine.secret.entity.unpack; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author:dxfeng + * @createTime: 2025/03/26 + * @version: 1.0 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class ResourceInfo { + private String id; + private String fileName; + private String filePath; + private String fileSuffix; + private String virtualPath; + private String createdTime; + private String updatedTime; + private String isDelete; +} diff --git a/src/com/engine/secret/service/UnpackZipService.java b/src/com/engine/secret/service/UnpackZipService.java new file mode 100644 index 0000000..eb62b48 --- /dev/null +++ b/src/com/engine/secret/service/UnpackZipService.java @@ -0,0 +1,18 @@ +package com.engine.secret.service; + +import net.lingala.zip4j.model.FileHeader; + +import java.util.zip.ZipFile; + +/** + * @author:dxfeng + * @createTime: 2025/03/26 + * @version: 1.0 + */ +public interface UnpackZipService { + + void dataUnpack(ZipFile zipFile, FileHeader jsonFileHeader); + + void fileUnpack(); + +} diff --git a/src/com/engine/secret/service/impl/OfflineZipUnpackServiceImpl.java b/src/com/engine/secret/service/impl/OfflineZipUnpackServiceImpl.java new file mode 100644 index 0000000..5b82179 --- /dev/null +++ b/src/com/engine/secret/service/impl/OfflineZipUnpackServiceImpl.java @@ -0,0 +1,24 @@ +package com.engine.secret.service.impl; + +import com.engine.core.impl.Service; +import com.engine.secret.service.UnpackZipService; +import net.lingala.zip4j.model.FileHeader; + +import java.util.zip.ZipFile; + +/** + * @author:dxfeng + * @createTime: 2025/03/26 + * @version: 1.0 + */ +public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipService { + @Override + public void dataUnpack(ZipFile zipFile, FileHeader jsonFileHeader) { + + } + + @Override + public void fileUnpack() { + + } +} diff --git a/src/com/engine/secret/service/impl/QualificationApplicationServiceImpl.java b/src/com/engine/secret/service/impl/QualificationApplicationServiceImpl.java index 8d06e6c..62e200a 100644 --- a/src/com/engine/secret/service/impl/QualificationApplicationServiceImpl.java +++ b/src/com/engine/secret/service/impl/QualificationApplicationServiceImpl.java @@ -1,14 +1,24 @@ package com.engine.secret.service.impl; +import com.alibaba.fastjson.JSON; import com.engine.core.impl.Service; +import com.engine.secret.entity.unpack.DataConfig; +import com.engine.secret.entity.unpack.DataConfigDetail; +import com.engine.secret.entity.unpack.FileConfig; import com.engine.secret.exception.CustomizeRunTimeException; import com.engine.secret.service.QualificationApplicationService; +import com.engine.secret.util.ModeUtil; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import com.wbi.util.Util; import net.lingala.zip4j.ZipFile; -import net.lingala.zip4j.exception.ZipException; import net.lingala.zip4j.model.FileHeader; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.StringUtils; +import weaver.conn.RecordSet; import weaver.file.ImageFileManager; +import weaver.formmode.IgnoreCaseHashMap; import java.io.IOException; import java.io.InputStream; @@ -16,10 +26,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; /** * @author:dxfeng @@ -27,10 +34,14 @@ import java.util.Optional; * @version: 1.0 */ public class QualificationApplicationServiceImpl extends Service implements QualificationApplicationService { + + private static String CONFIG_TABLE_NAME = "uf_bmj_sjjxpz"; + private static String CONFIG_DETAIL_TABLE_NAME = "uf_bmj_sjjxpz_dt1"; + private static String FILE_DETAIL_TABLE_NAME = "uf_bmj_sjjxpz_dt2"; + @Override public Map parsingFiles(Map param) { try { - int fileId = 1627; String imageId = Util.null2String(param.get("imageId")); if (StringUtils.isBlank(imageId)) { throw new CustomizeRunTimeException("文件获取失败,请确认文件是否上传"); @@ -38,55 +49,74 @@ public class QualificationApplicationServiceImpl extends Service implements Qual Map returnMap = new HashMap<>(); // 根据文件id获取文件流 ImageFileManager manager = new ImageFileManager(); - manager.getImageFileInfoById(fileId); + manager.getImageFileInfoById(Integer.parseInt(imageId)); manager.getImageFileName(); InputStream inputStream = manager.getInputStream(); + Path tempZipFile = Files.createTempFile("temp", ".zip"); Files.copy(inputStream, tempZipFile, StandardCopyOption.REPLACE_EXISTING); String password = "zizhi102!"; + //解压文件,处理压缩包 unzipWithPassword(tempZipFile, Paths.get("output"), password); + + return returnMap; } catch (Exception e) { throw new CustomizeRunTimeException("文件解析失败", e); } } - private static void unzipWithPassword(Path zipFilePath, Path outputDir, String password) { + + /** + * 解压ZIP文件 + * + * @param zipFilePath + * @param outputDir + * @param password + */ + private void unzipWithPassword(Path zipFilePath, Path outputDir, String password) { try { ZipFile zipFile = new ZipFile(zipFilePath.toFile()); if (zipFile.isEncrypted()) { - zipFile.setPassword(password.toCharArray()); // 设置密码 + zipFile.setPassword(password.toCharArray()); } - // 遍历并解压所有文件 zipFile.extractAll(outputDir.toString()); - System.out.println("解压成功"); - // 12345678_资质申请附件/(database)data.json - - // 存储文件 // 遍历 ZIP 内文件(可选) List fileHeaders = zipFile.getFileHeaders(); + // 获取压缩包解析后的根目录 Optional commonRoot = fileHeaders.stream() .map(FileHeader::getFileName) .filter(path -> !path.trim().isEmpty()) - .map(path -> path.split("/")[0]) // 取第一级目录或文件名 + .map(path -> path.split("/")[0]) .distinct() .reduce((a, b) -> a.equals(b) ? a : null); - String rootPath = commonRoot.orElse(null); - Map fileHeaderMap = new HashMap<>(); + String rootPath = commonRoot.orElse(""); + // TODO 测试 后续删除 + Map fileHeaderMap = new HashMap<>(); for (FileHeader header : fileHeaders) { + if (header.isDirectory()) { + continue; + } System.out.println("文件: " + header.getFileName()); - fileHeaderMap.put(header.getFileName(),header); + fileHeaderMap.put(header.getFileName(), header); } - // 遍历配置表 + + // 获取数据文件,用于后续数据解析 + String jsonFileName = StringUtils.isBlank(rootPath) ? "(database)data.json" : rootPath + "/(database)data.json"; + FileHeader jsonFileHeader = zipFile.getFileHeader(jsonFileName); + if (jsonFileHeader != null) { + // 离线端方式 + offline(zipFile, jsonFileHeader); + } + + // TODO 兼容其他方式 - - - } catch (ZipException e) { + } catch (IOException e) { if (e.getMessage().contains("Wrong password")) { System.err.println("密码错误"); } else { @@ -100,4 +130,313 @@ public class QualificationApplicationServiceImpl extends Service implements Qual } } } + + /** + * 离线解析方式 + * + * @param zipFile + * @param jsonFileHeader + * @throws JsonProcessingException + */ + private void offline(ZipFile zipFile, FileHeader jsonFileHeader) throws JsonProcessingException { + // 解析JSON文件 + String jsonContent = parseJsonContent(zipFile, jsonFileHeader); + ObjectMapper mapper = new ObjectMapper(); + JsonNode rootNode = mapper.readTree(jsonContent); + List dataConfigList = getDataConfig("0"); + + if (CollectionUtils.isNotEmpty(dataConfigList)) { + // 遍历配置,读取配置文件,并插入数据 + for (DataConfig dataConfig : dataConfigList) { + String mainTableName = dataConfig.getMainTableName(); + String rootPath = dataConfig.getRootPath(); + // 字段对照关系 + List fieldDetailList = dataConfig.getDetailList(); + // 获取明细表相关信息 + List childDataConfigList = dataConfig.getChildDataConfig(); + List fileList = dataConfig.getFileList(); + + if (CollectionUtils.isNotEmpty(fieldDetailList)) { + if (StringUtils.isNotBlank(rootPath)) { + if (rootPath.contains("[*]")) { + rootPath = rootPath.replace("[*]", ""); + JsonNode jsonNode = rootNode.at(rootPath); + if (null == jsonNode) { + throw new CustomizeRunTimeException("数据解析失败,未找到对应字段:[" + rootPath + "]"); + } + if (!jsonNode.isArray()) { + throw new CustomizeRunTimeException("数据解析失败,未找到对应字段集合:[" + rootPath + "]"); + } + for (JsonNode node : jsonNode) { + int billId = insertMainTable(node, mainTableName, fieldDetailList); + if (billId < 0) { + continue; + } + dealDetailData(rootNode, billId, childDataConfigList); + // TODO 更新文件信息 + + } + } else { + JsonNode jsonNode = rootNode.at(rootPath); + int billId = insertMainTable(jsonNode, mainTableName, fieldDetailList); + if (billId < 0) { + continue; + } + dealDetailData(rootNode, billId, childDataConfigList); + } + } else { + int billId = insertMainTable(rootNode, mainTableName, fieldDetailList); + if (billId < 0) { + continue; + } + dealDetailData(rootNode, billId, childDataConfigList); + } + } + + + } + } + } + + /** + * 处理明细表数据 + * + * @param rootNode + * @param mainId + * @param childDataConfigList + */ + private void dealDetailData(JsonNode rootNode, int mainId, List childDataConfigList) { + if (CollectionUtils.isEmpty(childDataConfigList)) { + return; + } + for (DataConfig childDataConfig : childDataConfigList) { + String detailTableName = childDataConfig.getDetailTableName(); + // 获取字段对照关系数据 + List fieldList = childDataConfig.getDetailList(); + String rootPath = childDataConfig.getRootPath(); + if (StringUtils.isNotBlank(rootPath)) { + if (rootPath.contains("[*]")) { + rootPath = rootPath.replace("[*]", ""); + JsonNode jsonNode = rootNode.at(rootPath); + if (null == jsonNode) { + throw new CustomizeRunTimeException("数据解析失败,未找到对应字段:[" + rootPath + "]"); + } + if (!jsonNode.isArray()) { + throw new CustomizeRunTimeException("数据解析失败,未找到对应字段集合:[" + rootPath + "]"); + } + for (JsonNode node : jsonNode) { + insertDetailTable(node, detailTableName, mainId, fieldList); + } + } else { + JsonNode jsonNode = rootNode.at(rootPath); + insertDetailTable(jsonNode, detailTableName, mainId, fieldList); + + } + } else { + insertDetailTable(rootNode, detailTableName, mainId, fieldList); + } + } + } + + /** + * 构建主表数据,插入数据并返回数据ID + * + * @param jsonNode + * @param mainTableName + * @param fieldList + * @return + */ + private int insertMainTable(JsonNode jsonNode, String mainTableName, List fieldList) { + Map insertMap = new IgnoreCaseHashMap<>(); + + for (DataConfigDetail fieldDetail : fieldList) { + String fieldName = fieldDetail.getFieldName(); + String path = fieldDetail.getPath(); + String condition = fieldDetail.getCondition(); + JsonNode atNode = jsonNode.at(path); + if (null != atNode) { + String value = atNode.asText(); + // 判断是否满足条件 + if (StringUtils.isNotBlank(condition) && !value.equals(condition)) { + return -1; + } + insertMap.put(fieldName, value); + } + } + + int size = insertMap.size(); + if (size == 0) { + return -1; + } + String uuid = UUID.randomUUID().toString(); + insertMap.put("modeuuid", uuid); + int formModeId = ModeUtil.getModeIdByTableName(mainTableName); + insertMap.put("formmodeid", formModeId); + // 构建主表数据插入基本字段 + // TODO ModeUtil.buildModeInsertFields(insertMap, user.getUID()); + // 插入数据 + // TODO ModeUtil.insertData(insertMap, mainTableName); + // 数据权限重构,返回数据ID + // TODO return ModeUtil.refreshRight(uuid, mainTableName, formModeId, user.getUID()); + System.out.println("insertMainTable: " + JSON.toJSONString(insertMap)); + return 1; + } + + /** + * 插入明细表数据 + * + * @param jsonNode + * @param detailTableName + * @param mainId + * @param fieldList + */ + private void insertDetailTable(JsonNode jsonNode, String detailTableName, int mainId, List fieldList) { + Map insertMap = new IgnoreCaseHashMap<>(); + + for (DataConfigDetail fieldDetail : fieldList) { + String fieldName = fieldDetail.getFieldName(); + String path = fieldDetail.getPath(); + String condition = fieldDetail.getCondition(); + JsonNode atNode = jsonNode.at(path); + if (null != atNode) { + String value = atNode.asText(); + // 判断是否满足条件 + if (StringUtils.isNotBlank(condition) && !value.equals(condition)) { + return; + } + insertMap.put(fieldName, value); + } + } + + + int size = insertMap.size(); + if (size == 0) { + return; + } + insertMap.put("mainId", mainId); + System.out.println("insertDetailTable: " + JSON.toJSONString(insertMap)); + // 插入数据 + // TODO ModeUtil.insertData(insertMap, detailTableName); + } + + + /** + * 获取数据配置 + * + * @param type + * @return + */ + private List getDataConfig(String type) { + // 获取离线包的先关配置 + List dataConfigList = new ArrayList<>(); + RecordSet rs = new RecordSet(); + // TODO 表名,字段名待确定 + rs.executeQuery("select * from " + CONFIG_TABLE_NAME + " where xrbbm is not null and xrbbm !='' and sjbly = ?", type); + while (rs.next()) { + DataConfig dataConfig = new DataConfig(); + dataConfig.setId(rs.getString("id")); + dataConfig.setMainTableName(rs.getString("xrbbm")); + dataConfig.setDetailTableName(rs.getString("xrbmxb")); + dataConfig.setRootPath(rs.getString("gjd")); + // 获取字段对照关系数据 + List detailList = getDetailList(dataConfig.getId()); + dataConfig.setDetailList(detailList); + dataConfig.setFileList(getFileList(dataConfig.getId())); + // 获取明细表相关信息 + String detailTableName = dataConfig.getDetailTableName(); + if (StringUtils.isNotBlank(detailTableName)) { + List childDataConfig = getChildDataConfig(detailTableName, type); + dataConfig.setChildDataConfig(childDataConfig); + } + + dataConfigList.add(dataConfig); + } + return dataConfigList; + } + + /** + * 获取关联的明细表配置 + * + * @param detailTableName + * @param type + * @return + */ + private List getChildDataConfig(String detailTableName, String type) { + String[] detailNameArray = detailTableName.split(","); + List dataConfigList = new ArrayList<>(); + + for (String dtName : detailNameArray) { + RecordSet rs = new RecordSet(); + // TODO 表名,字段名待确定 + rs.executeQuery("select * from " + CONFIG_TABLE_NAME + " where (xrbbm is null or xrbbm ='') and xrbmxb = ? and sjbly = ?", dtName, type); + while (rs.next()) { + DataConfig dataConfig = new DataConfig(); + dataConfig.setId(rs.getString("id")); + dataConfig.setMainTableName(rs.getString("xrbbm")); + dataConfig.setDetailTableName(rs.getString("xrbmxb")); + dataConfig.setRootPath(rs.getString("gjd")); + // 获取字段对照关系数据 + List detailList = getDetailList(dataConfig.getId()); + dataConfig.setDetailList(detailList); + dataConfig.setFileList(getFileList(dataConfig.getId())); + dataConfigList.add(dataConfig); + } + } + return dataConfigList; + } + + + /** + * 获取字段对照关系 + * + * @param mainId + * @return + */ + private List getDetailList(String mainId) { + List detailList = new ArrayList<>(); + RecordSet rs = new RecordSet(); + rs.executeQuery("select * from " + CONFIG_DETAIL_TABLE_NAME + " where mainId = ?", mainId); + while (rs.next()) { + // TODO 表名,字段名待确定 + detailList.add(DataConfigDetail.builder().fieldName(rs.getString("zdm")).path(rs.getString("wjbs")).condition(rs.getString("tj")).build()); + } + return detailList; + } + + /** + * 获取文件对照关系 + * + * @param mainId + * @return + */ + private List getFileList(String mainId) { + List fileList = new ArrayList<>(); + RecordSet rs = new RecordSet(); + rs.executeQuery("select * from " + FILE_DETAIL_TABLE_NAME + " where mainId = ?", mainId); + while (rs.next()) { + // TODO 表名,字段名待确定 + fileList.add(FileConfig.builder().filedName(rs.getString("zdm")).fileId(rs.getString("wjbs")).isFilled(rs.getString("bzwj")).build()); + } + return fileList; + } + + + /** + * 获取JSON文件内容 + * + * @param zipFile + * @param header + * @return + */ + private static String parseJsonContent(ZipFile zipFile, FileHeader header) { + ObjectMapper mapper = new ObjectMapper(); + try (InputStream is = zipFile.getInputStream(header)) { + JsonNode rootNode = mapper.readTree(is); + return rootNode.toPrettyString(); + } catch (Exception e) { + throw new CustomizeRunTimeException(e); + } + } + + } diff --git a/src/com/engine/secret/util/ModeUtil.java b/src/com/engine/secret/util/ModeUtil.java new file mode 100644 index 0000000..c40fccb --- /dev/null +++ b/src/com/engine/secret/util/ModeUtil.java @@ -0,0 +1,324 @@ +package com.engine.secret.util; + +import com.engine.secret.exception.CustomizeRunTimeException; +import org.apache.commons.lang3.StringUtils; +import org.apache.poi.util.IOUtils; +import weaver.common.DateUtil; +import weaver.conn.RecordSet; +import weaver.docs.docs.*; +import weaver.file.ImageFileManager; +import weaver.formmode.IgnoreCaseHashMap; +import weaver.formmode.setup.ModeRightInfo; +import weaver.general.TimeUtil; +import weaver.general.Util; +import weaver.hrm.User; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +/** + * @author:dxfeng + * @createTime: 2025/03/26 + * @version: 1.0 + */ +public class ModeUtil { + + /** + * 生成附件ID + * + * @param inputStream + * @param filename + * @return + */ + public static int generateImageFileId(InputStream inputStream, String filename) { + int imageFileId; + try { + byte[] bytes = IOUtils.toByteArray(inputStream); + ImageFileManager ifm = new ImageFileManager(); + ifm.setData(bytes); + ifm.setImagFileName(filename); + imageFileId = ifm.saveImageFile(); + } catch (IOException e) { + throw new RuntimeException(e); + } + return imageFileId; + } + + /** + * 附件imageFieldId生成docId + * + * @param secCategory + * @param imageFieldId + * @param user + * @return + * @throws Exception + */ + public static int createDocId(int secCategory, int imageFieldId, User user) throws Exception { + ImageFileManager manager = new ImageFileManager(); + manager.getImageFileInfoById(imageFieldId); + String filenameqc = manager.getImageFileName(); + String filenamebc = filenameqc.substring(0, filenameqc.lastIndexOf(".")); + RecordSet rs = new RecordSet(); + DocManager dm = new DocManager(); + DocImageManager imgManger = new DocImageManager(); + + imgManger.setDocfiletype("2"); + + int docId = dm.getNextDocId(rs); + imgManger.setDocid(docId); + imgManger.setImagefileid(imageFieldId); + imgManger.setImagefilename(filenameqc); + imgManger.setIsextfile("1"); + imgManger.AddDocImageInfo(); + + String date = TimeUtil.getCurrentDateString(); + String time = TimeUtil.getOnlyCurrentTimeString(); + dm.setId(docId); + dm.setMaincategory(0); + dm.setSubcategory(0); + dm.setSeccategory(secCategory); + dm.setLanguageid(user.getLanguage()); + + dm.setDocstatus("1"); + dm.setDocsubject(filenamebc); + dm.setDoccreaterid(user.getUID()); + dm.setDocCreaterType(user.getLogintype()); + dm.setUsertype(user.getLogintype()); + dm.setOwnerid(user.getUID()); + dm.setOwnerType(user.getLogintype()); + dm.setDoclastmoduserid(user.getUID()); + dm.setDocLastModUserType(user.getLogintype()); + dm.setDoccreatedate(date); + dm.setDoclastmoddate(date); + dm.setDoccreatetime(time); + dm.setDoclastmodtime(time); + dm.setDoclangurage(user.getLanguage()); + dm.setKeyword(filenameqc); + dm.setIsapprover("0"); + dm.setIsreply(""); + dm.setDocdepartmentid(user.getUserDepartment()); + dm.setDocreplyable("1"); + dm.setAccessorycount(1); + dm.setParentids("" + docId); + dm.setUserid(user.getUID()); + DocCoder docCoder = new DocCoder(); + dm.setDocCode(docCoder.getDocCoder("" + secCategory)); + dm.setDocEditionId(dm.getNextEditionId(rs)); + dm.setDocEdition(1); + dm.AddDocInfo(); + dm.AddShareInfo(); + DocViewer DocViewer = new DocViewer(); + DocViewer.setDocShareByDoc("" + docId); + DocComInfo dc = new DocComInfo(); + dc.addDocInfoCache("" + docId); + return docId; + } + + /** + * 获取单个记录映射 + * + * @param rs RecordSet + * @return + */ + public static IgnoreCaseHashMap getSingleRecordMap(RecordSet rs) { + IgnoreCaseHashMap dataMap = new IgnoreCaseHashMap<>(); + if (rs.next()) { + String[] columnNames = rs.getColumnName(); + for (String columnName : columnNames) { + dataMap.put(columnName, parseBlankToNull(rs.getString(columnName))); + } + } + return dataMap; + } + + public static List> getRecordMapList(RecordSet rs) { + List> list = new ArrayList<>(); + while (rs.next()) { + String[] columnNames = rs.getColumnName(); + Map dataMap = new IgnoreCaseHashMap<>(); + for (String columnName : columnNames) { + dataMap.put(columnName.toLowerCase(), parseBlankToNull(rs.getString(columnName))); + } + list.add(dataMap); + } + return list; + } + + /** + * 插入数据 + * + * @param dataMap 数据集合 + * @param tableName 表名 + */ + public static void insertData(Map dataMap, String tableName) { + List fieldList = new ArrayList<>(); + List dataList = new ArrayList<>(); + List paramList = new ArrayList<>(); + + dataMap.forEach((key, value) -> { + if (null != value) { + String valueStr = String.valueOf(value); + if(StringUtils.isNotBlank(valueStr)) { + fieldList.add(key); + dataList.add(valueStr); + paramList.add("?"); + } + } + }); + String insertSql = " insert into " + tableName + "(" + StringUtils.join(fieldList, ",") + ") values (" + StringUtils.join(paramList, ",") + ")"; + RecordSet rs = new RecordSet(); + rs.executeUpdate(insertSql, dataList); + if (StringUtils.isNotBlank(rs.getExceptionMsg())) { + throw new CustomizeRunTimeException(rs.getExceptionMsg()); + } + } + + /** + * 根据ID更新数据 + * + * @param dataMap + * @param tableName + */ + public static void updateDataById(Map dataMap, String tableName) { + List fieldList = new ArrayList<>(); + List dataList = new ArrayList<>(); + String id = Util.null2String(dataMap.get("id")); + dataMap.remove("id"); + + dataMap.forEach((key, value) -> { + fieldList.add(key + " = ? "); + dataList.add(value); + }); + dataList.add(id); + String updateSql = "update " + tableName + " set " + StringUtils.join(fieldList, ",") + " where id = ? "; + RecordSet rs = new RecordSet(); + rs.executeUpdate(updateSql, dataList); + if (StringUtils.isNotBlank(rs.getExceptionMsg())) { + throw new CustomizeRunTimeException(rs.getExceptionMsg()); + } + } + + /** + * 更新数据 + * + * @param dataMap + * @param tableName + * @param whereSql + */ + public static void updateData(Map dataMap, String tableName, String whereSql) { + List fieldList = new ArrayList<>(); + List dataList = new ArrayList<>(); + dataMap.forEach((key, value) -> { + fieldList.add(key + " = ? "); + dataList.add(value); + }); + String updateSql = "update " + tableName + " set " + StringUtils.join(fieldList, ",") + whereSql; + RecordSet rs = new RecordSet(); + rs.executeUpdate(updateSql, dataList); + if (StringUtils.isNotBlank(rs.getExceptionMsg())) { + throw new CustomizeRunTimeException(rs.getExceptionMsg()); + } + } + + /** + * 删除数据 + * + * @param deleteSql + */ + public static void deleteData(String deleteSql) { + RecordSet rs = new RecordSet(); + rs.executeUpdate(deleteSql); + if (StringUtils.isNotBlank(rs.getExceptionMsg())) { + throw new CustomizeRunTimeException(rs.getExceptionMsg()); + } + } + + + /** + * 构建建模表基本数据 + * + * @param mainDataMap 参数集合 + */ + public static void buildModeInsertFields(Map mainDataMap, int userId) { + String dateTime = DateUtil.getFullDate(); + String[] dateSplit = dateTime.split(" "); + mainDataMap.put("modedatacreater", userId); + mainDataMap.put("modedatacreatedate", dateSplit[0]); + mainDataMap.put("modedatacreatetime", dateSplit[1]); + mainDataMap.put("modedatacreatertype", "0"); + } + + /** + * 构建建模表基本数据 + * + * @param mainDataMap 参数集合 + */ + public static void buildModeUpdateFields(Map mainDataMap, int userId) { + String dateTime = DateUtil.getFullDate(); + mainDataMap.put("modedatamodifier", userId); + mainDataMap.put("modedatamodifydatetime", dateTime); + } + + /** + * 建模表数据权限重构 + * + * @param uuid + * @param modeTable + * @param formModeId + */ + public static int refreshRight(String uuid, String modeTable, int formModeId, int creator) { + RecordSet rs = new RecordSet(); + rs.executeQuery("select id from " + modeTable + " where modeuuid='" + uuid + "'"); + if (rs.next()) { + //建模数据的id + int bid = Util.getIntValue(rs.getString("id")); + ModeRightInfo modeRightInfo = new ModeRightInfo(); + modeRightInfo.setNewRight(true); + //新建的时候添加共享 + modeRightInfo.editModeDataShare(creator, formModeId, bid); + return bid; + } + return -1; + } + + + /** + * 转换空字符串为null + * + * @param str 字符串 + * @return 转换后的字符串 + */ + public static Object parseBlankToNull(String str) { + return StringUtils.isBlank(str) ? null : str; + } + + /** + * 转换空字符串为null + * + * @param obj 对象 + * @return 转换后的字符串 + */ + public static String parseBlankToNull(Object obj) { + return Objects.isNull(obj) ? null : StringUtils.isBlank(obj.toString()) ? null : obj.toString(); + } + + /** + * 根据建模表名,获取建模ID + * + * @param modeTable + * @return + */ + public static int getModeIdByTableName(String modeTable) { + int formModeId = -1; + RecordSet rs = new RecordSet(); + rs.executeQuery("select id from modeinfo where formid =( select id from workflow_bill where tablename = ? ) and isdelete = 0 order by id", modeTable); + if (rs.next()) { + formModeId = rs.getInt("id"); + } + return formModeId; + } +}