Java tutorial
package com.sjdf.platform.attachment.helper; import com.sjdf.platform.CommonPlatformConstant; import com.sjdf.platform.attachment.vo.AttachmentHouseVo; import com.sjdf.platform.common.utils.DateUtils; import com.sjdf.platform.common.utils.PlatformUtils; import com.sjdf.platform.common.utils.Tools; import com.sjdf.platform.common.utils.base64.Base64; import com.sjdf.platform.dictionary.bean.*; import com.sjdf.platform.dictionary.cache.ConfigManager; import com.sjdf.platform.dictionary.cache.DictionaryHelper; import com.sjdf.platform.log.logger.SJDFLogger; import com.sjdf.platform.log.logger.SJDFLoggerFactory; import org.dom4j.Document; import org.dom4j.Element; import org.dom4j.Node; import org.dom4j.io.SAXReader; import java.io.*; import java.util.*; /** * Create at 2013-4-17 ?11:41:40 * ? * * @author frank */ public abstract class AttachmentHelper { /** */ private static final SJDFLogger LOGGER = SJDFLoggerFactory.getSJDFLogger(AttachmentHelper.class); /** ? */ public static final String SAVE_ROOT_PATH = ConfigManager.getInstance().getValue(AttachmentConfigure.class, AttachmentConfigure.COMMON_ATTACHMENT_SAVE_PATH); /** */ public static final String SLASH_SYMBOL = ConfigManager.getInstance().getValue(AssembleStringSymbols.class, AssembleStringSymbols.SLASH); /** ? */ public static final String HYPHEN_SYMBOL = ConfigManager.getInstance().getValue(AssembleStringSymbols.class, AssembleStringSymbols.HYPHEN); /** ?? */ public static final String EN_PERIOD_SYMBOL = ConfigManager.getInstance().getValue(AssembleStringSymbols.class, AssembleStringSymbols.EN_PERIOD); /** ? */ public static final String CONNPWD = ConfigManager.getInstance().getValue(RemoteAccess.class, RemoteAccess.CONNECTION_PASSWORD); /** ? */ public static final String COLON = ConfigManager.getInstance().getValue(AssembleStringSymbols.class, AssembleStringSymbols.COLON); /** ? */ public static final String SEMICOLON = ConfigManager.getInstance().getValue(AssembleStringSymbols.class, AssembleStringSymbols.SEMICOLON_SPACE); /** ? */ public static final String COMMA = ConfigManager.getInstance().getValue(AssembleStringSymbols.class, AssembleStringSymbols.COMMA); public static String parse(List<AttachmentHouseVo> attachmentVoList, String attachmentPath) { try { StringBuilder xml = new StringBuilder(CommonPlatformConstant.LENGTH_5120); xml.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); xml.append("<attachmentList>"); for (AttachmentHouseVo attachmentHouseVo : attachmentVoList) { xml.append(attachmentHouseVo.toXml(attachmentPath)); } xml.append("</attachmentList>"); return xml.toString(); } catch (Exception e) { LOGGER.error("?", e); } return null; } /** * ?XMLVO List * * @param xml XML * @return VO List */ @SuppressWarnings("unchecked") public static List<AttachmentHouseVo> parse(String xml) throws Exception { List<AttachmentHouseVo> attachmentVoList = new ArrayList<>(); SAXReader saxReader = new SAXReader(); try (InputStream is = new ByteArrayInputStream(xml.getBytes("UTF-8"))) { Document document = saxReader.read(is); Node node = document.selectSingleNode("/error"); if (node != null) { LOGGER.error(xml); throw new RuntimeException(((Element) node).getData().toString()); } Element root = (Element) document.selectSingleNode("/attachmentList"); List<Element> xmlDictionaryList = root.elements(); if (xmlDictionaryList != null && !xmlDictionaryList.isEmpty()) { for (Element element : xmlDictionaryList) { List<Element> xmlDictionary = element.elements(); AttachmentHouseVo attachmentHouseVo = new AttachmentHouseVo(); for (Element e : xmlDictionary) { if (e.elements().isEmpty() && (Tools.isEmpty(e.getData().toString()) || "null".equals(e.getData().toString()))) { continue; } if ("path".equals(e.getName())) { attachmentHouseVo.setPath(e.getData().toString()); } else if ("userId".equals(e.getName())) { attachmentHouseVo.setUserId(Long.valueOf(e.getData().toString())); } else if ("attachmentUseCode".equals(e.getName())) { attachmentHouseVo.setAttachmentUseCode(Long.valueOf(e.getData().toString())); } else if ("attachmentUseType".equals(e.getName())) { attachmentHouseVo.setAttachmentUseType(Long.valueOf(e.getData().toString())); } else if ("systemType".equals(e.getName())) { attachmentHouseVo.setSystemType(Long.valueOf(e.getData().toString())); } else if ("markDelete".equals(e.getName())) { attachmentHouseVo.setMarkDelete(Long.valueOf(e.getData().toString())); } else if ("remark".equals(e.getName())) { attachmentHouseVo.setRemark(e.getData().toString()); } else if ("byte".equals(e.getName())) { attachmentHouseVo.setAttachmentFileString(e.getData().toString()); } else if ("username".equals(e.getName())) { attachmentHouseVo.setUsername(e.getData().toString()); } else if ("whetherChanged".equals(e.getName())) { attachmentHouseVo.setWhetherChanged(Long.valueOf(e.getData().toString())); } else if ("format".equals(e.getName())) { attachmentHouseVo.setFormat(Long.valueOf(e.getData().toString())); } else if ("sourcePath".equals(e.getName())) { attachmentHouseVo.setSourcePath(e.getData().toString()); } else if ("subSystemPath".equals(e.getName())) { attachmentHouseVo.setSubSystemPath(e.getData().toString()); } else if ("attachmentId".equals(e.getName())) { attachmentHouseVo.setId(Long.valueOf(e.getData().toString())); } else if ("auditResult".equals(e.getName())) { attachmentHouseVo.setAuditResult(Long.valueOf(e.getData().toString())); } else if ("fontColor".equals(e.getName())) { attachmentHouseVo.setFontColor(Long.valueOf(e.getData().toString())); } else if ("createTime".equals(e.getName())) { attachmentHouseVo.setBeginDate(e.getData().toString()); } else if ("updateTime".equals(e.getName())) { attachmentHouseVo.setEndDate(e.getData().toString()); } else if ("attachmentUseTypeMark".equals(e.getName())) { attachmentHouseVo.setAttachmentUseTypeMark(e.getData().toString()); } else if ("attachmentSpecialMark".equals(e.getName())) { //? element? List<Element> ppgjzElementList = e.elements(); String specialMark; if (ppgjzElementList.isEmpty() && !Tools.isEmpty(e.getData().toString())) { specialMark = e.getData().toString(); } else { specialMark = parseAttachmentSpecialMark(attachmentHouseVo.getAttachmentUseType(), attachmentHouseVo.getAttachmentUseCode(), ppgjzElementList); } attachmentHouseVo.setAttachmentSpecialMark(specialMark); } } attachmentVoList.add(attachmentHouseVo); } } } return attachmentVoList; } /** * @param sourcePath ?Path * @param subSystemPath ?Path * ?Path?Path ? * @return true:Path?false:Path?? */ public static boolean verifyAttachmentPath(String sourcePath, String subSystemPath) { String source = sourcePath, subSystem = subSystemPath; try { if (Tools.isEmpty(source) && Tools.isEmpty(subSystem)) { return true; } if (!Tools.isEmpty(source)) { source = source.substring(source.lastIndexOf(SLASH_SYMBOL) + 1, source.length()); } if (!Tools.isEmpty(subSystem)) { subSystem = subSystem.substring(subSystem.lastIndexOf(SLASH_SYMBOL) + 1, subSystem.length()); } return source.equals(subSystem); } catch (Exception e) { LOGGER.error("?Path?Path ?", e); } return false; } /** * @param path * ??ID * @return ID */ public static String[] splitPath(String path) { String str = path; String[] splitPathArray = new String[CommonPlatformConstant.LENGTH_2]; try { if (Tools.isEmpty(str)) { return new String[0]; } //?ID str = str.substring(str.lastIndexOf(SLASH_SYMBOL) + 1, str.length()); String[] pathArray = str.split(HYPHEN_SYMBOL); splitPathArray[0] = pathArray[0]; splitPathArray[1] = pathArray[1].substring(0, pathArray[1].lastIndexOf(EN_PERIOD_SYMBOL)); return splitPathArray; } catch (Exception e) { LOGGER.error("??ID", e); return new String[0]; } } /** * @param voList VOList * VOList?Map * @return VO Map */ public static Map<Long, AttachmentHouseVo> voListToVoMap(List<AttachmentHouseVo> voList) { Map<Long, AttachmentHouseVo> attachmentHouseVoMap = new TreeMap<>(); for (AttachmentHouseVo attachmentHouseVo : voList) { attachmentHouseVoMap.put(Long.valueOf(splitPath(attachmentHouseVo.getPath())[0]), attachmentHouseVo); } return attachmentHouseVoMap; } /** * @param dir ?? * ? */ public static void makeDir(String dir) { try { //? File targetPath = new File(dir); if (!targetPath.exists()) { targetPath.mkdirs(); } } catch (Exception e) { LOGGER.error("?", e); } } /** * ?? * * @return ? */ public static String getDateDir() { return DateUtils.formatDateToYear(new Date()) + AttachmentHelper.SLASH_SYMBOL + DateUtils.formatDate(new Date()); } /** * VO?? */ public static void verifyAttachmentVoList(List<AttachmentHouseVo> voList, long operatorAction) throws Exception { //Builder StringBuilder errorBuilder = new StringBuilder(); for (AttachmentHouseVo attachmentHouseVo : voList) { attachmentHouseVo.verifySelf(errorBuilder, operatorAction); } //? if (!Tools.isEmpty(errorBuilder.toString())) { throw new Exception(errorBuilder.toString()); } } /** * @param filePath * ?? * @return ?? */ public static boolean deleteAttachment(String filePath) { try { if (Tools.isEmpty(filePath)) { return false; } File file = new File(filePath); if (file.isFile() && file.exists()) { file.delete(); return true; } else { return false; } } catch (Exception e) { LOGGER.error("??", e); return false; } } /** * * * @param inputStream ? * @param filePath * @param fileName ?? * @throws IOException */ public static File writerFile(InputStream inputStream, String filePath, String fileName) throws IOException { String path = filePath; BufferedInputStream bis = new BufferedInputStream(inputStream); File file = new File(path); if (!file.isDirectory()) { file.mkdir(); } path += "/" + fileName; File afterSavedFile = new File(path); BufferedOutputStream fos = new BufferedOutputStream(new FileOutputStream(path)); byte[] buffer = new byte[CommonPlatformConstant.LENGTH_1024 * CommonPlatformConstant.LENGTH_10]; for (int numRead; (numRead = bis.read(buffer)) > 0;) { fos.write(buffer, 0, numRead); } fos.flush(); fos.close(); bis.close(); return afterSavedFile; } /** * @param file ?file * @return BASE64Encoder?byte String * fileBASE64Encoder?byte String */ public static String getFileString(File file) { byte[] buffer = new byte[CommonPlatformConstant.LENGTH_1024]; int length; try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(file)); ByteArrayOutputStream out = new ByteArrayOutputStream()) { while ((length = in.read(buffer)) != -1) { out.write(buffer, 0, length); } return new String(Base64.encode(out.toByteArray(), Base64.ONE_LINE_LENGTH)); } catch (IOException e) { LOGGER.error("fileBASE64Encoder?byte String", e); return null; } } /** * @param fileString BASE64Encoder??String * @return byteNULL * BASE64Encoder??String ?byte */ public static byte[] fileStringToByte(String fileString) { try { return Base64.decode(fileString.getBytes()); } catch (Exception e) { LOGGER.error("BASE64Encoder??String ?byte", e); } return new byte[0]; } /** * @param fileString BASE64Encoder??String InputStream * @return InputStreamNULL */ public static InputStream fileStringToInputStream(String fileString) { try { return new ByteArrayInputStream(fileStringToByte(fileString)); } catch (Exception e) { LOGGER.error("BASE64Encoder??String InputStream", e); } return null; } /** * @param fromPath * @param toPath * ? * @return ??true ?false; */ public static boolean copyFile(String fromPath, String toPath) { try { int byteread; File oldfile = new File(fromPath); if (oldfile.exists()) { // InputStream inStream = new FileInputStream(fromPath); // File toFile = new File(toPath); FileOutputStream fs = new FileOutputStream(toFile); byte[] buffer = new byte[CommonPlatformConstant.LENGTH_2048]; while ((byteread = inStream.read(buffer)) != -1) { fs.write(buffer, 0, byteread); } inStream.close(); fs.close(); } return true; } catch (Exception e) { LOGGER.error("?", e); return false; } } /** * @param commonPath ??Path * ???Path ??Path * @return ?Path */ public static String getSubSystemPath(String commonPath) { String subSystemPath = null; try { if (Tools.isEmpty(commonPath)) { return ""; } String[] commonPathArray = commonPath.split(SLASH_SYMBOL); //?? if (commonPathArray.length == CommonPlatformConstant.LENGTH_2) { String suffix = commonPathArray[1]; subSystemPath = SLASH_SYMBOL + getDateDir() + SLASH_SYMBOL + suffix; } else { //? subSystemPath = commonPath.substring(1); subSystemPath = subSystemPath.substring(subSystemPath.indexOf(SLASH_SYMBOL)); } } catch (Exception e) { LOGGER.error("???Path ??Path", e); } return subSystemPath; } /** * @param attachmentRealPath ?? * ?????????,?DB? * @return */ public static String[] getResizePath(String attachmentRealPath) { String[] resizePath = new String[CommonPlatformConstant.LENGTH_4]; try { if (Tools.isEmpty(attachmentRealPath)) { return resizePath; } String fileName = attachmentRealPath.substring(attachmentRealPath.lastIndexOf(SLASH_SYMBOL) + 1); String resizeDirectory = SAVE_ROOT_PATH + attachmentRealPath.substring(0, attachmentRealPath.lastIndexOf(SLASH_SYMBOL) + 1) + ConfigManager.getInstance().getValue(AttachmentConfigure.class, AttachmentConfigure.COMMON_RESIZE_IMAGE); String allPath = resizeDirectory + SLASH_SYMBOL + fileName; String resizeDbPath = attachmentRealPath.substring(0, attachmentRealPath.lastIndexOf(SLASH_SYMBOL) + 1) + ConfigManager.getInstance().getValue(AttachmentConfigure.class, AttachmentConfigure.COMMON_RESIZE_IMAGE) + SLASH_SYMBOL + fileName; resizePath[0] = resizeDirectory; resizePath[1] = fileName; resizePath[CommonPlatformConstant.LENGTH_2] = allPath; resizePath[CommonPlatformConstant.LENGTH_3] = resizeDbPath; } catch (Exception e) { LOGGER.error("?????", e); } return resizePath; } public static String parseAttachmentSpecialMark(Long attachmentUseType, Long attachmentUseCode, List<Element> ppgjzElementList) { //?? List<String> ppgjzArray = new ArrayList<>(); try { // ? if (Tools.compareLong(attachmentUseType, AttachmentUseType.ATTACHMENT_USE_TYPE_PRE_APPROVAL_ATTACHMENT)) { //?? String domain = getValueOfElementByCondition(ppgjzElementList, KeyWordType.DOMAIN_NAME); ppgjzArray.add(domain); return splicePpgjz(ppgjzArray, SEMICOLON); } else { //--??????????????????? if (Tools.compareLong(attachmentUseCode, AttachmentUseCode.ATTACHMENT_USE_CODE_TAIWAN_COMPATRIOTS_CERTIFICATE) || Tools.compareLong(attachmentUseCode, AttachmentUseCode.ATTACHMENT_USE_CODE_GA_PASSPORT) || Tools.compareLong(attachmentUseCode, AttachmentUseCode.ATTACHMENT_USE_CODE_PASSPORT) || Tools.compareLong(attachmentUseCode, AttachmentUseCode.ATTACHMENT_USE_CODE_OFFICER_CERTIFICATE) || Tools.compareLong(attachmentUseCode, AttachmentUseCode.ATTACHMENT_USE_CODE_ID_CARD)) { //???? // String certificateNamePpgjz = getValueOfElementByCondition(ppgjzElementList, KeyWordType.NAME); //??? if (Tools.isEmpty(certificateNamePpgjz)) { certificateNamePpgjz = getValueOfElementByCondition(ppgjzElementList, KeyWordType.FIRM_NAME); } //???? String certificateIDCardPpgjz = getValueOfElementByCondition(ppgjzElementList, KeyWordType.CERTIFICATE_NUM); //???? String certificateAddrPpgjz = getValueOfElementByCondition(ppgjzElementList, KeyWordType.CERTIFICATE_ADDR); //??? if (certificateNamePpgjz != null && !"".equals(certificateNamePpgjz)) { ppgjzArray.add(certificateNamePpgjz);//?? } if (certificateIDCardPpgjz != null && !"".equals(certificateIDCardPpgjz)) { ppgjzArray.add(certificateIDCardPpgjz);//??? } if (certificateAddrPpgjz != null && !"".equals(certificateAddrPpgjz)) { ppgjzArray.add(certificateAddrPpgjz);//?? } return splicePpgjz(ppgjzArray, SEMICOLON); } //--? if (Tools.compareLong(attachmentUseCode, AttachmentUseCode.ATTACHMENT_USE_CODE_BUSINESS_LICENSE) || Tools.compareLong(attachmentUseCode, AttachmentUseCode.ATTACHMENT_USE_CODE_CAREER_LEGAL_CERTIFICATE) || Tools.compareLong(attachmentUseCode, AttachmentUseCode.ATTACHMENT_USE_CODE_SOCIETY_LEGAL_CERTIFICATE) || Tools.compareLong(attachmentUseCode, AttachmentUseCode.ATTACHMENT_USE_CODE_ARMY_CERTIFICATE) || Tools.compareLong(attachmentUseCode, AttachmentUseCode.ATTACHMENT_USE_CODE_ORGANIZATION_CERTIFICATE) || Tools.compareLong(attachmentUseCode, AttachmentUseCode.ATTACHMENT_UNIFIED_SOCIAL_CREDIT_CERTIFICATE) || Tools.compareLong(attachmentUseCode, AttachmentUseCode.ATTACHMENT_USE_CODE_MBFQY_DWDJ_CERTIFICATE) || Tools.compareLong(attachmentUseCode, AttachmentUseCode.ATTACHMENT_USE_CODE_LSSWS_ZYXK_CERTIFICATE) || Tools.compareLong(attachmentUseCode, AttachmentUseCode.ATTACHMENT_USE_CODE_JJH_CAREER_LEGAL_CERTIFICATE) || Tools.compareLong(attachmentUseCode, AttachmentUseCode.ATTACHMENT_USE_CODE_REGISTRATION_APPLICATION_FORM)) { //???? String firmName = getValueOfElementByCondition(ppgjzElementList, KeyWordType.FIRM_NAME); //???? String certificateIDCardPpgjz = getValueOfElementByCondition(ppgjzElementList, KeyWordType.CERTIFICATE_NUM); //???? String certificateAddrPpgjz = getValueOfElementByCondition(ppgjzElementList, KeyWordType.CERTIFICATE_ADDR); //??? ppgjzArray.add(firmName); ppgjzArray.add(certificateIDCardPpgjz); ppgjzArray.add(certificateAddrPpgjz); return splicePpgjz(ppgjzArray, SEMICOLON); } //-- if (Tools.compareLong(attachmentUseCode, AttachmentUseCode.ATTACHMENT_USE_CODE_WEB_RESP_PEOPLE_PHOTO)) { //???? String certificateNamePpgjz = getValueOfElementByCondition(ppgjzElementList, KeyWordType.NAME); //???? String certificateIDCardPpgjz = getValueOfElementByCondition(ppgjzElementList, KeyWordType.CERTIFICATE_NUM); //??? ppgjzArray.add(certificateNamePpgjz); ppgjzArray.add(certificateIDCardPpgjz); return splicePpgjz(ppgjzArray, SEMICOLON); } //--?? if (Tools.compareLong(attachmentUseCode, AttachmentUseCode.ATTACHMENT_USE_CODE_WEB_VERIFI_SINGLE)) { //???? String firmName = getValueOfElementByCondition(ppgjzElementList, KeyWordType.FIRM_NAME); //?? String domain = getValueOfElementByCondition(ppgjzElementList, KeyWordType.DOMAIN_NAME); //??? ppgjzArray.add(firmName); ppgjzArray.add(domain); return splicePpgjz(ppgjzArray, SEMICOLON); } //--? if (Tools.compareLong(attachmentUseCode, AttachmentUseCode.ATTACHMENT_USE_CODE_INFO_LETTERS_CERTIFICATE)) { //???? String firmName = getValueOfElementByCondition(ppgjzElementList, KeyWordType.FIRM_NAME); //?? String respPersonName = getValueOfElementByCondition(ppgjzElementList, KeyWordType.NAME); //??? ppgjzArray.add(firmName); ppgjzArray.add(respPersonName); return splicePpgjz(ppgjzArray, SEMICOLON); } //--??? if (Tools.compareLong(attachmentUseCode, AttachmentUseCode.ATTACHMENT_USE_CODE_DOMAIN_CERTIFICATE)) { //?? String domain = getValueOfElementByCondition(ppgjzElementList, KeyWordType.DOMAIN_NAME); //??? ppgjzArray.add(domain); return splicePpgjz(ppgjzArray, SEMICOLON); } //--? if (Tools.compareLong(attachmentUseCode, AttachmentUseCode.ATTACHMENT_USE_CODE_WEB_RESP_WARRANT_CERTIFICATE)) { //???? String firmName = getValueOfElementByCondition(ppgjzElementList, KeyWordType.FIRM_NAME); //?? String webName = getValueOfElementByCondition(ppgjzElementList, KeyWordType.WEB_NAME); //?? String domain = getValueOfElementByCondition(ppgjzElementList, KeyWordType.DOMAIN_NAME); //?? String respPersonName = getValueOfElementByCondition(ppgjzElementList, KeyWordType.NAME); //??? String respPersonIDCardNum = getValueOfElementByCondition(ppgjzElementList, KeyWordType.CERTIFICATE_NUM); //??? ppgjzArray.add(firmName); ppgjzArray.add(webName); ppgjzArray.add(domain); ppgjzArray.add(respPersonName); ppgjzArray.add(respPersonIDCardNum); return splicePpgjz(ppgjzArray, SEMICOLON); } // --? if (Tools.compareLong(attachmentUseCode, AttachmentUseCode.ATTACHMENT_USE_CODE_ZT_RESP_WARRANT_CERTIFICATE)) { // ???? String firmName = getValueOfElementByCondition(ppgjzElementList, KeyWordType.FIRM_NAME); // ?? String respPersonName = getValueOfElementByCondition(ppgjzElementList, KeyWordType.NAME); // ??? String respPersonIDCardNum = getValueOfElementByCondition(ppgjzElementList, KeyWordType.CERTIFICATE_NUM); // ??? ppgjzArray.add(firmName); ppgjzArray.add(respPersonName); ppgjzArray.add(respPersonIDCardNum); return splicePpgjz(ppgjzArray, SEMICOLON); } // --? if (Tools.compareLong(attachmentUseCode, AttachmentUseCode.ATTACHMENT_USE_CODE_POLICERECEIPT)) { // ?? String webName = getValueOfElementByCondition(ppgjzElementList, KeyWordType.WEB_NAME); ppgjzArray.add(webName); return splicePpgjz(ppgjzArray, SEMICOLON); } } } catch (Exception e) { LOGGER.error("", e); } return null; } /** * @param ppgjzElementList ?List * @param condition ? * ??ppgjzElementList? * @return ??, ?--> key:value */ private static String getValueOfElementByCondition(List<Element> ppgjzElementList, Long condition) { StringBuilder sb = new StringBuilder(); try { //?? for (Element tempElement : ppgjzElementList) { //?key String key = tempElement.attributeValue("key"); //?value String value = tempElement.attributeValue("value"); //key???? if (condition.toString().equals(key) && PlatformUtils.hasText(value)) { sb.append(key).append(COLON).append(value); break; } sb.setLength(0); } return sb.toString(); } catch (Exception e) { LOGGER.error("??ppgjzElementList?", e); } return null; } /** * @param ppgjzArray ?List * @param spliceStr * ? * @return ?? */ private static String splicePpgjz(List<String> ppgjzArray, String spliceStr) { StringBuilder sb = new StringBuilder(); try { for (int i = 0; i < ppgjzArray.size(); i++) { if (ppgjzArray.get(i) != null && !"".equals(ppgjzArray.get(i))) { sb.append(ppgjzArray.get(i)); if (i < ppgjzArray.size() - 1) { sb.append(spliceStr); } } else { sb.setLength(0); return null; } } return sb.toString(); } catch (Exception e) { LOGGER.error("?", e); } return null; } /** * @param referPpgjzStr ?? * @param parsePpgjzStr ?? * ???????? * @return true?false */ public static boolean compareAttachmentSpecialMark(String referPpgjzStr, String parsePpgjzStr) { //??, boolean flag = false; try { if (Tools.isEmpty(referPpgjzStr) || Tools.isEmpty(parsePpgjzStr)) { return flag; } //?? //?--? //????????? //?? //1."; "?baxc.getPpgjz(),? String[] sourcePpgjzArray = parsePpgjzStr.split(SEMICOLON); //--? String[] newPpgjzArray = referPpgjzStr.split(SEMICOLON); //?--???NULL if (sourcePpgjzArray.length != newPpgjzArray.length) { flag = false; } else { //?--??? for (String sourcePpgjzStr : sourcePpgjzArray) { //2.":"?sourcePpgjzStr String[] sourceUnit = sourcePpgjzStr.split(COLON); for (String unitStr : sourceUnit) { //unitStr?"," if (unitStr.contains(COMMA)) { //3.","?unitStr String[] sourceSmallUnit = unitStr.split(COMMA); for (String smallUnit : sourceSmallUnit) { if (!referPpgjzStr.contains(smallUnit)) { //??? flag = false; break; } else { flag = true; } } //??? if (!flag) { break; } } else { if (!referPpgjzStr.contains(unitStr)) { //??? flag = false; break; } else { flag = true; } } } //??? if (!flag) { break; } } } } catch (Exception e) { LOGGER.error( "????????", e); } return flag; } /** * ?map?(??value?) * * @return map?(??value?) */ public static Map<String, Long> getAttachmentFormatStringMap() { List<AttachmentFormat> attachmentFormatList = DictionaryHelper.getDictionary(AttachmentFormat.class); Map<String, Long> attachmentFormatMap = new HashMap<>(); for (AttachmentFormat attachmentFormat : attachmentFormatList) { attachmentFormatMap.put(attachmentFormat.getCnName(), attachmentFormat.getAttr()); } return attachmentFormatMap; } /** * @param specialMarkStr ? * ????Map * @return ?Map */ public static Map<Long, String> stringToSpecialMarkMap(String specialMarkStr) { Map<Long, String> specialMarkMap = new HashMap<>(); try { if (Tools.isEmpty(specialMarkStr)) { throw new NullPointerException(); } //1."; "?unitStr String[] specialMarkSemicolonArray = specialMarkStr.split(SEMICOLON); for (String semicolonStr : specialMarkSemicolonArray) { //2.":"?unitStr String[] sourceColonUnit = semicolonStr.split(COLON); specialMarkMap.put(Long.valueOf(sourceColonUnit[0]), sourceColonUnit[1]); } return specialMarkMap; } catch (Exception e) { LOGGER.error("????Map", e); throw e; } } }