diff --git a/src/com/engine/secret/entity/unpack/DataConfig.java b/src/com/engine/secret/entity/unpack/DataConfig.java index 1b61c13..a2ebc58 100644 --- a/src/com/engine/secret/entity/unpack/DataConfig.java +++ b/src/com/engine/secret/entity/unpack/DataConfig.java @@ -19,6 +19,7 @@ import java.util.List; public class DataConfig { private String id; private String mainTableName; + private String relatedField; private String detailTableName; private String rootPath; List childDataConfig; diff --git a/src/com/engine/secret/service/impl/QualificationApplicationServiceImpl.java b/src/com/engine/secret/service/impl/QualificationApplicationServiceImpl.java index 549b6db..a4e917b 100644 --- a/src/com/engine/secret/service/impl/QualificationApplicationServiceImpl.java +++ b/src/com/engine/secret/service/impl/QualificationApplicationServiceImpl.java @@ -7,11 +7,13 @@ import com.engine.secret.entity.unpack.*; import com.engine.secret.exception.CustomizeRunTimeException; import com.engine.secret.service.QualificationApplicationService; import com.engine.secret.util.ConfigUtil; +import com.engine.secret.util.FieldConvertUtil; 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 com.weaver.formmodel.data.model.Formfield; import net.lingala.zip4j.ZipFile; import net.lingala.zip4j.model.FileHeader; import org.apache.commons.collections.CollectionUtils; @@ -54,19 +56,29 @@ public class QualificationApplicationServiceImpl extends Service implements Qual Map imageFileMap; + String relatedFlowId; + @Override public Map parsingFiles(Map param) { try { - String imageId = Util.null2String(param.get("imageId")); - if (StringUtils.isBlank(imageId)) { + String docId = Util.null2String(param.get("docId")); + String requestId = Util.null2String(param.get("requestId")); + if (StringUtils.isBlank(docId)) { throw new CustomizeRunTimeException("文件获取失败,请确认文件是否上传"); } - baseBean.writeLog("imageId==" + imageId); + baseBean.writeLog("docId==" + docId); + + if (StringUtils.isBlank(requestId)) { + throw new CustomizeRunTimeException("流程关联失败,未获取到流程ID,请保存后重试"); + } + + baseBean.writeLog("requestId==" + requestId); + relatedFlowId = requestId; // docId 转为换imageFileId DocImageManager imgManger = new DocImageManager(); - imgManger.setDocid(Integer.parseInt(imageId)); + imgManger.setDocid(Integer.parseInt(docId)); imgManger.selectDocImageInfo(); imgManger.next(); String imageFileId = imgManger.getImagefileid(); @@ -87,10 +99,9 @@ public class QualificationApplicationServiceImpl extends Service implements Qual uploadCatalogue = Convert.toInt(uploadCatalogueStr, -1); baseBean.writeLog("uploadCatalogue==" + uploadCatalogue); - Map returnMap = new HashMap<>(); // 根据文件id获取文件流 ImageFileManager manager = new ImageFileManager(); - manager.getImageFileInfoById(Integer.parseInt(imageId)); + manager.getImageFileInfoById(Integer.parseInt(imageFileId)); manager.getImageFileName(); InputStream inputStream = manager.getInputStream(); @@ -105,8 +116,7 @@ public class QualificationApplicationServiceImpl extends Service implements Qual unzipWithPassword(tempZipFile, Paths.get("output"), unzipPwd); baseBean.writeLog("压缩包处理完成"); - - return returnMap; + return new HashMap<>(); } catch (Exception e) { throw new CustomizeRunTimeException(e.getMessage(), e); } @@ -208,6 +218,7 @@ public class QualificationApplicationServiceImpl extends Service implements Qual // 遍历配置,读取配置文件,并插入数据 for (DataConfig dataConfig : dataConfigList) { String mainTableName = dataConfig.getMainTableName(); + String relatedField = dataConfig.getRelatedField(); String rootPath = dataConfig.getRootPath(); baseBean.writeLog("rootPath==" + rootPath); // 字段对照关系 @@ -216,6 +227,10 @@ public class QualificationApplicationServiceImpl extends Service implements Qual List childDataConfigList = dataConfig.getChildDataConfig(); List fileList = dataConfig.getFileList(); + List formFieldList = ModeUtil.getFieldList(mainTableName); + Map mainTableFieldMap = formFieldList.stream().filter(item -> item.getViewtype() == 0).collect(Collectors.toMap(Formfield::getFieldname, item -> item, (k1, k2) -> k1)); + + if (CollectionUtils.isNotEmpty(fieldDetailList)) { if (StringUtils.isNotBlank(rootPath)) { if (rootPath.contains("[*]")) { @@ -228,28 +243,28 @@ public class QualificationApplicationServiceImpl extends Service implements Qual throw new CustomizeRunTimeException("数据解析失败,未找到对应字段集合:[" + rootPath + "]"); } for (JsonNode node : jsonNode) { - int billId = insertMainTable(node, mainTableName, fieldDetailList); + int billId = insertMainTable(node, mainTableName, relatedField, fieldDetailList, mainTableFieldMap); if (billId < 0) { continue; } - dealDetailData(rootNode, billId, childDataConfigList); + dealDetailData(rootNode, billId, childDataConfigList, formFieldList); dealFileList(billId, fileList, mainTableName, false); } } else { JsonNode jsonNode = rootNode.at(rootPath); - int billId = insertMainTable(jsonNode, mainTableName, fieldDetailList); + int billId = insertMainTable(jsonNode, mainTableName, relatedField, fieldDetailList, mainTableFieldMap); if (billId < 0) { continue; } - dealDetailData(rootNode, billId, childDataConfigList); + dealDetailData(rootNode, billId, childDataConfigList, formFieldList); dealFileList(billId, fileList, mainTableName, false); } } else { - int billId = insertMainTable(rootNode, mainTableName, fieldDetailList); + int billId = insertMainTable(rootNode, mainTableName, relatedField, fieldDetailList, mainTableFieldMap); if (billId < 0) { continue; } - dealDetailData(rootNode, billId, childDataConfigList); + dealDetailData(rootNode, billId, childDataConfigList, formFieldList); dealFileList(billId, fileList, mainTableName, false); } } @@ -266,12 +281,14 @@ public class QualificationApplicationServiceImpl extends Service implements Qual * @param mainId * @param childDataConfigList */ - private void dealDetailData(JsonNode rootNode, int mainId, List childDataConfigList) throws Exception { + private void dealDetailData(JsonNode rootNode, int mainId, List childDataConfigList, List formFieldList) throws Exception { if (CollectionUtils.isEmpty(childDataConfigList)) { return; } for (DataConfig childDataConfig : childDataConfigList) { String detailTableName = childDataConfig.getDetailTableName(); + Map detailTableFieldMap = formFieldList.stream().filter(item -> detailTableName.equals(item.getDetailtable())).collect(Collectors.toMap(Formfield::getFieldname, item -> item, (k1, k2) -> k1)); + // 获取字段对照关系数据 List fieldList = childDataConfig.getDetailList(); List fileList = childDataConfig.getFileList(); @@ -293,15 +310,15 @@ public class QualificationApplicationServiceImpl extends Service implements Qual throw new CustomizeRunTimeException("数据解析失败,未找到对应字段集合:[" + rootPath + "]"); } for (JsonNode node : jsonNode) { - insertDetailTable(node, detailTableName, mainId, fieldList); + insertDetailTable(node, detailTableName, mainId, fieldList, detailTableFieldMap); } } else { JsonNode jsonNode = rootNode.at(rootPath); - insertDetailTable(jsonNode, detailTableName, mainId, fieldList); + insertDetailTable(jsonNode, detailTableName, mainId, fieldList, detailTableFieldMap); } } else { - insertDetailTable(rootNode, detailTableName, mainId, fieldList); + insertDetailTable(rootNode, detailTableName, mainId, fieldList, detailTableFieldMap); } } } @@ -312,10 +329,11 @@ public class QualificationApplicationServiceImpl extends Service implements Qual * * @param jsonNode * @param mainTableName + * @param relatedField * @param fieldList * @return */ - private int insertMainTable(JsonNode jsonNode, String mainTableName, List fieldList) { + private int insertMainTable(JsonNode jsonNode, String mainTableName, String relatedField, List fieldList, Map mainTableFieldMap) throws Exception { Map insertMap = new IgnoreCaseHashMap<>(); for (DataConfigDetail fieldDetail : fieldList) { @@ -329,7 +347,13 @@ public class QualificationApplicationServiceImpl extends Service implements Qual if (StringUtils.isNotBlank(condition) && !value.equals(condition)) { return -1; } - insertMap.put(fieldName, value); + // 根据字段类型 转换Value的值 + Formfield formfield = mainTableFieldMap.get(fieldName.toLowerCase()); + if (null == formfield) { + continue; + } + Object reallyValue = FieldConvertUtil.getReallyValue(formfield, value); + insertMap.put(fieldName, reallyValue); } } @@ -337,6 +361,9 @@ public class QualificationApplicationServiceImpl extends Service implements Qual if (size == 0) { return -1; } + if (StringUtils.isNotBlank(relatedField)) { + insertMap.put(relatedField, relatedFlowId); + } String uuid = UUID.randomUUID().toString(); insertMap.put("modeuuid", uuid); int formModeId = ModeUtil.getModeIdByTableName(mainTableName); @@ -358,7 +385,7 @@ public class QualificationApplicationServiceImpl extends Service implements Qual * @param mainId * @param fieldList */ - private void insertDetailTable(JsonNode jsonNode, String detailTableName, int mainId, List fieldList) { + private void insertDetailTable(JsonNode jsonNode, String detailTableName, int mainId, List fieldList, Map mainTableFieldMap) throws Exception { Map insertMap = new IgnoreCaseHashMap<>(); for (DataConfigDetail fieldDetail : fieldList) { @@ -372,7 +399,13 @@ public class QualificationApplicationServiceImpl extends Service implements Qual if (StringUtils.isNotBlank(condition) && !value.equals(condition)) { return; } - insertMap.put(fieldName, value); + // 根据字段类型 转换Value的值 + Formfield formfield = mainTableFieldMap.get(fieldName.toLowerCase()); + if (null == formfield) { + continue; + } + Object reallyValue = FieldConvertUtil.getReallyValue(formfield, value); + insertMap.put(fieldName, reallyValue); } } @@ -480,6 +513,7 @@ public class QualificationApplicationServiceImpl extends Service implements Qual DataConfig dataConfig = new DataConfig(); dataConfig.setId(rs.getString("id")); dataConfig.setMainTableName(rs.getString("main_table")); + dataConfig.setRelatedField(rs.getString("related_field")); dataConfig.setDetailTableName(rs.getString("detail_tables")); dataConfig.setRootPath(rs.getString("root_path")); // 获取字段对照关系数据 diff --git a/src/com/engine/secret/util/FieldConvertUtil.java b/src/com/engine/secret/util/FieldConvertUtil.java new file mode 100644 index 0000000..c537825 --- /dev/null +++ b/src/com/engine/secret/util/FieldConvertUtil.java @@ -0,0 +1,143 @@ +package com.engine.secret.util; + +import com.weaver.formmodel.data.model.Formfield; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.validator.GenericValidator; +import weaver.conn.RecordSet; +import weaver.general.Util; +import weaver.hrm.definedfield.HrmFieldManager; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; + +/** + * @author:dxfeng + * @createTime: 2025/04/02 + * @version: 1.0 + */ +public class FieldConvertUtil { + + /** + * 转换存入数据库的值 + * + * @param formfield + * @param value + * @return + * @throws Exception + */ + public static Object getReallyValue(Formfield formfield, String value) throws Exception { + if (StringUtils.isBlank(value)) { + return null; + } + RecordSet rs = new RecordSet(); + Object object = null; + String type = Util.null2String(formfield.getType()); + switch (formfield.getFieldhtmltype()) { + case "1": + // INPUT + if ("2".equals(type)) { + object = new BigDecimal(value).intValue(); + } else if ("3".equals(type)) { + object = new BigDecimal(value).floatValue(); + } else if ("1".equals(type)) { + object = value; + } else { + try { + object = new BigDecimal(value).toPlainString(); + } catch (NumberFormatException ignore) { + object = value; + } + } + break; + case "3": + // BROWSER + org.json.JSONObject jsonObject = new org.json.JSONObject(); + jsonObject.put("fieldhtmltype", formfield.getFieldhtmltype()); + jsonObject.put("type", type); + jsonObject.put("fieldvalue", value); + if ("161".equals(type) || "162".equals(type)) { + jsonObject.put("dmlurl", formfield.getFielddbtype()); + } else { + jsonObject.put("dmlurl", type); + } + + jsonObject.put("fieldid", 0); + object = HrmFieldManager.getReallyFieldvalue(jsonObject); + // 如果是日期,校验日期的合法性 + if ("2".equals(type)) { + boolean isDate = GenericValidator.isDate(Util.null2String(object), "yyyy-MM-dd", true); + if (!isDate) { + rs.writeLog("日期格式校验失败,object==" + Util.null2String(object)); + object = ""; + } + } + break; + case "5": + // 区分单选、复选、下拉框 + switch (type) { + case "1": + case "3": + // 下拉框、单选框 + object = ModeUtil.getSelectValue(formfield, value); + if (StringUtils.isBlank(Util.null2String(object))) { + if (isNumberOrCommaSeparatedNumbers(value)) { + object = value; + } + } + break; + case "2": + if (StringUtils.isNotBlank(value)) { + List selectValues = new ArrayList<>(); + // 兼容分隔符 + String separator = ","; + if (value.contains("、")) { + separator = "、"; + } + String[] split = value.split(","); + for (String s : split) { + selectValues.add(ModeUtil.getSelectValue(formfield, s)); + } + object = StringUtils.join(selectValues, separator); + if (StringUtils.isBlank(Util.null2String(object))) { + if (isNumberOrCommaSeparatedNumbers(value)) { + object = value; + } + } + } + break; + default: + break; + } + + break; + case "4": + // CHECKBOX + case "6": + // FILEUPLOAD + break; + case "7": + // TEXT + case "2": + // TEXTAREA + default: + object = value; + break; + } + return object; + } + + + /** + * 校验字符串是否为纯数字或逗号分隔的数字 + * + * @param str + * @return + */ + public static boolean isNumberOrCommaSeparatedNumbers(String str) { + // 正则表达式匹配纯数字或逗号分隔的数字 + // 允许前后有空格,数字之间用逗号分隔 + String regex = "^\\s*\\d+(\\s*,\\s*\\d+)*\\s*$"; + return str.matches(regex); + } +} diff --git a/src/com/engine/secret/util/ModeUtil.java b/src/com/engine/secret/util/ModeUtil.java index eabe216..4395ad7 100644 --- a/src/com/engine/secret/util/ModeUtil.java +++ b/src/com/engine/secret/util/ModeUtil.java @@ -1,6 +1,8 @@ package com.engine.secret.util; import com.engine.secret.exception.CustomizeRunTimeException; +import com.weaver.formmodel.data.manager.FormInfoManager; +import com.weaver.formmodel.data.model.Formfield; import org.apache.commons.lang3.StringUtils; import org.apache.poi.util.IOUtils; import weaver.common.DateUtil; @@ -124,8 +126,8 @@ public class ModeUtil { * @param rs RecordSet * @return */ - public static IgnoreCaseHashMap getSingleRecordMap(RecordSet rs) { - IgnoreCaseHashMap dataMap = new IgnoreCaseHashMap<>(); + public static IgnoreCaseHashMap getSingleRecordMap(RecordSet rs) { + IgnoreCaseHashMap dataMap = new IgnoreCaseHashMap<>(); if (rs.next()) { String[] columnNames = rs.getColumnName(); for (String columnName : columnNames) { @@ -162,7 +164,7 @@ public class ModeUtil { dataMap.forEach((key, value) -> { if (null != value) { String valueStr = String.valueOf(value); - if(StringUtils.isNotBlank(valueStr)) { + if (StringUtils.isNotBlank(valueStr)) { fieldList.add(key); dataList.add(valueStr); paramList.add("?"); @@ -322,5 +324,77 @@ public class ModeUtil { return formModeId; } + public static List getFieldList(String tableName) { + int formId = getFormIdByTableName(tableName); + return FormInfoManager.getInstance().getAllField(formId); + } + + public static List getFieldList(int formId) { + return FormInfoManager.getInstance().getAllField(formId); + } + + /** + * 根据表名,获取表单ID + * + * @param modeTable + * @return + */ + public static int getFormIdByTableName(String modeTable) { + int formId = -1; + RecordSet rs = new RecordSet(); + rs.executeQuery("select id from workflow_bill where tablename = ? ", modeTable); + if (rs.next()) { + formId = rs.getInt("id"); + } + return formId; + } + + /** + * 获取表单下拉框展示文本 + * + * @param formId 表单ID + * @param fieldName 字段明湖曾 + * @param value 下拉框值 + * @return + */ + public static String getSelectName(String formId, String fieldName, String value) { + String cancelReason = ""; + RecordSet rs = new RecordSet(); + rs.executeQuery("select selectname from workflow_selectitem where fieldid =( select id from workflow_billfield where billid = ? and fieldname = ? ) and selectvalue = ?", formId, fieldName, value); + if (rs.next()) { + cancelReason = rs.getString("selectname"); + } + return cancelReason; + } + + /** + * 获取表单下拉框值 + * + * @param formId 表单ID + * @param fieldName 字段明湖曾 + * @param selectName 下拉框展示内容 + * @return + */ + public static String getSelectValue(String formId, String fieldName, String selectName) { + String selectValue = ""; + RecordSet rs = new RecordSet(); + rs.executeQuery("select selectvalue from workflow_selectitem where fieldid =( select id from workflow_billfield where billid = ? and fieldname = ? ) and selectname = ?", formId, fieldName, selectName); + if (rs.next()) { + selectValue = rs.getString("selectvalue"); + } + return selectValue; + } + + public static String getSelectValue(Formfield formfield, String selectName) { + String selectValue = ""; + RecordSet rs = new RecordSet(); + String detailTable = formfield.getDetailtable(); + rs.executeQuery("select selectvalue from workflow_selectitem where fieldid =( select id from workflow_billfield where billid = ? and fieldname = ? and detailtable = ? ) and selectname = ?", formfield.getBillid(), formfield.getFieldname(), Util.null2String(detailTable),selectName); + if (rs.next()) { + selectValue = rs.getString("selectvalue"); + } + return selectValue; + } + }