/** * 验证 * * @param ds * @return */ private Map<String, Object> validator(Dataset ds) { Map<String, Object> validatorMap = new HashMap<String, Object>(); PageData rd = ds.getCurrentPageData(); if (rd == null) { return null; } Row[] rows = getValidatorRows(ds); if (rows == null || rows.length == 0) { return null; } int count = ds.getFieldCount(); if (count == 0) { return null; } // formElement错误提示信息类型 key-fieldId value-errorType Map<String, Integer> errorTypeMap = new HashMap<String, Integer>(); // formElement错误提示信息 key-fieldId value-errorMsg Map<String, String> formularMsgMap = new HashMap<String, String>(); // 保存时校验验证公式 HashMap<String, String> valueMap = new HashMap<String, String>(); HashMap<String, String> dataTypeMap = new HashMap<String, String>(); // DefaultEditFormularService editFormular = new DefaultEditFormularService(); // 保存多语主语种字段 Map<String, Field> multiMap = new HashMap<String, Field>(); /*LanguageVO[] lanVos = MultiLangContext.getInstance().getEnableLangVOs(); if (lanVos != null && lanVos.length > 0) { for (int i = 0; i < count; i++) { if (fs.getField(i).getExtendAttribute(Field.MDFIELD_MULTILANG) != null && IType.MULTILANGUAGE == (Integer) fs.getField(i).getExtendAttribute(Field.MDFIELD_MULTILANG).getValue()) { // 当前字段是多语字段并且是主语种字段 multiMap.put(fs.getField(i).getId(), fs.getField(i)); for (LanguageVO vo : lanVos) { multiMap.put(fs.getField(i).getId() + vo.getLangseq(), fs.getField(fs.getField(i).getId() + vo.getLangseq())); } } } }*/ for (int j = 0; j < rows.length; j++) { Row row = rows[j]; int rowIndex = ds.getRowIndex(row); if (row instanceof EmptyRow) { continue; } for (int k = 0; k < count; k++) { Field field = ds.getField(k); String fieldId = field.getId(); boolean isCurrLangField = false; // if (field.getExtendAttribute(Field.MDFIELD_MULTILANG) != null && IType.MULTILANGUAGE // == (Integer) field.getExtendAttribute(Field.MDFIELD_MULTILANG).getValue()) { // // 当前字段是多语字段并且是主语种字段 // } else if (multiMap.containsKey(fieldId) && // fieldId.endsWith(String.valueOf(MultiLangContext.getInstance().getCurrentLangSeq()))) { // // 当前字段是多语字段并且是当前语种字段 // isCurrLangField = true; // } else if (multiMap.containsKey(fieldId)) { // // 当前字段是多语字段并且不是当前语种字段,不进行校验. // continue; // } String value = null; if (row.getValue(k) != null) { value = String.valueOf(row.getValue(k)); value = value.trim(); } // if (isCurrLangField) { // fieldId = fieldId.substring(0, // fieldId.lastIndexOf(String.valueOf(MultiLangContext.getInstance().getCurrentLangSeq()))); // } if (!field.isPK()) { if (field.getSourceField() != null) { if (errorTypeMap.get(field.getSourceField() + "_" + rowIndex) != null) { errorTypeMap.put( fieldId + "_" + rowIndex, errorTypeMap.get(field.getSourceField() + "_" + rowIndex)); } else { field = ds.getField(field.getSourceField()); int index = ds.fieldToIndexById(field.getId()); value = row.getValue(index) instanceof String ? (String) row.getValue(index) : null; int type = Validator.validtor(ds.getField(fieldId), value); if (type != -1) { errorTypeMap.put(fieldId + "_" + rowIndex, type); } } } else { int type = Validator.validtor(ds.getField(fieldId), value); if (type != -1) { errorTypeMap.put(fieldId + "_" + rowIndex, type); } } } if (errorTypeMap.get(fieldId + "_" + rowIndex) != null) { // 平台校验未通过,不进行下面的校验. continue; } valueMap.put(field.getId(), value); dataTypeMap.put(field.getId(), field.getDataType()); if (field.getValidateFormula() != null) { Map<String, String> map = null; // editFormular.executeFormular(valueMap, field.getValidateFormula(), // dataTypeMap); if (map != null) { String forumValue = (String) map.get("formular_value"); if (forumValue != null && !forumValue.equals("$NULL$")) { LuiValidateException.putFormElementToMap( formularMsgMap, fieldId + "_" + rowIndex, forumValue); } } } } } validatorMap.put("errorTypeMap", errorTypeMap); validatorMap.put("formularMsgMap", formularMsgMap); return validatorMap; }