⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pdfsurveyservices.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            ServiceUtil.returnError(ioe.getMessage());        }            return results;    }            /**     */    public static Map buildPdfFromSurveyResponse(DispatchContext dctx, Map context) {        GenericDelegator delegator = dctx.getDelegator();        //LocalDispatcher dispatcher = dctx.getDispatcher();        Map results = ServiceUtil.returnSuccess();        String surveyResponseId = (String)context.get("surveyResponseId");        String contentId = (String)context.get("contentId");        String surveyId = null;        Document document = new Document();        try {            if (UtilValidate.isNotEmpty(surveyResponseId)) {                GenericValue surveyResponse = delegator.findByPrimaryKey("SurveyResponse", UtilMisc.toMap("surveyResponseId", surveyResponseId));                if (surveyResponse != null) {                    surveyId = surveyResponse.getString("surveyId");                }            }            if (UtilValidate.isNotEmpty(surveyId) && UtilValidate.isEmpty(contentId)) {                GenericValue survey = delegator.findByPrimaryKey("Survey", UtilMisc.toMap("surveyId", surveyId));                if (survey != null) {                    String acroFormContentId = survey.getString("acroFormContentId");                    if (UtilValidate.isNotEmpty(acroFormContentId)) {                        context.put("contentId", acroFormContentId);                    }                }            }                    ByteArrayOutputStream baos = new ByteArrayOutputStream();            PdfWriter.getInstance(document, baos);                        List responses = delegator.findByAnd("SurveyResponseAnswer", UtilMisc.toMap("surveyResponseId", surveyResponseId));            Iterator iter = responses.iterator();            while (iter.hasNext()) {                String value = null;                GenericValue surveyResponseAnswer = (GenericValue) iter.next();                String surveyQuestionId = (String) surveyResponseAnswer.get("surveyQuestionId");                GenericValue surveyQuestion = delegator.findByPrimaryKey("SurveyQuestion", UtilMisc.toMap("surveyQuestionId", surveyQuestionId));                String questionType = surveyQuestion.getString("surveyQuestionTypeId");                // DEJ20060227 this isn't used, if needed in the future should get from SurveyQuestionAppl.externalFieldRef String fieldName = surveyQuestion.getString("description");                if ("OPTION".equals(questionType)) {                    value = surveyResponseAnswer.getString("surveyOptionSeqId");                } else if ("BOOLEAN".equals(questionType)) {                    value = surveyResponseAnswer.getString("booleanResponse");                } else if ("NUMBER_LONG".equals(questionType) || "NUMBER_CURRENCY".equals(questionType) || "NUMBER_FLOAT".equals(questionType)) {                    Double num = surveyResponseAnswer.getDouble("numericResponse");                    if (num != null) {                        value = num.toString();                    }                } else if ("SEPERATOR_LINE".equals(questionType) || "SEPERATOR_TEXT".equals(questionType)) {                    // not really a question; ingore completely                } else {                    value = surveyResponseAnswer.getString("textResponse");                }                Chunk chunk = new Chunk(surveyQuestion.getString("question") + ": " + value);                Paragraph p = new Paragraph(chunk);                document.add(p);            }            ByteWrapper outByteWrapper = new ByteWrapper(baos.toByteArray());            results.put("outByteWrapper", outByteWrapper);        } catch (GenericEntityException e) {            System.err.println(e.getMessage());            ServiceUtil.returnError(e.getMessage());        } catch (DocumentException e) {            System.err.println(e.getMessage());            ServiceUtil.returnError(e.getMessage());        }                return results;    }        /**     */    public static Map setAcroFieldsFromSurveyResponse(DispatchContext dctx, Map context) {        GenericDelegator delegator = dctx.getDelegator();        LocalDispatcher dispatcher = dctx.getDispatcher();        Map results = ServiceUtil.returnSuccess();        Map acroFieldMap = new HashMap();        String surveyResponseId = (String)context.get("surveyResponseId");        String acroFormContentId = null;            try {            String surveyId = null;            if (UtilValidate.isNotEmpty(surveyResponseId)) {                GenericValue surveyResponse = delegator.findByPrimaryKey("SurveyResponse", UtilMisc.toMap("surveyResponseId", surveyResponseId));                if (surveyResponse != null) {                    surveyId = surveyResponse.getString("surveyId");                }            }            if (UtilValidate.isNotEmpty(surveyId)) {                GenericValue survey = delegator.findByPrimaryKey("Survey", UtilMisc.toMap("surveyId", surveyId));                if (survey != null) {                    acroFormContentId = survey.getString("acroFormContentId");                }            }                        List responses = delegator.findByAnd("SurveyResponseAnswer", UtilMisc.toMap("surveyResponseId", surveyResponseId));            Iterator iter = responses.iterator();            while (iter.hasNext()) {                String value = null;                GenericValue surveyResponseAnswer = (GenericValue) iter.next();                String surveyQuestionId = (String) surveyResponseAnswer.get("surveyQuestionId");                GenericValue surveyQuestion = delegator.findByPrimaryKeyCache("SurveyQuestion", UtilMisc.toMap("surveyQuestionId", surveyQuestionId));                                List surveyQuestionApplList = EntityUtil.filterByDate(delegator.findByAndCache("SurveyQuestionAppl", UtilMisc.toMap("surveyId", surveyId, "surveyQuestionId", surveyQuestionId), UtilMisc.toList("-fromDate")), false);                GenericValue surveyQuestionAppl = EntityUtil.getFirst(surveyQuestionApplList);                                String questionType = surveyQuestion.getString("surveyQuestionTypeId");                String fieldName = surveyQuestionAppl.getString("externalFieldRef");                if ("OPTION".equals(questionType)) {                    value = surveyResponseAnswer.getString("surveyOptionSeqId");                } else if ("BOOLEAN".equals(questionType)) {                    value = surveyResponseAnswer.getString("booleanResponse");                } else if ("NUMBER_LONG".equals(questionType) || "NUMBER_CURRENCY".equals(questionType) || "NUMBER_FLOAT".equals(questionType)) {                    Double num = surveyResponseAnswer.getDouble("numericResponse");                    if (num != null) {                        value = num.toString();                    }                } else if ("SEPERATOR_LINE".equals(questionType) || "SEPERATOR_TEXT".equals(questionType)) {                    // not really a question; ingore completely                } else {                    value = surveyResponseAnswer.getString("textResponse");                }                acroFieldMap.put(fieldName, value);            }        } catch (GenericEntityException e) {            System.err.println(e.getMessage());            ServiceUtil.returnError(e.getMessage());        }                try {            ModelService modelService = dispatcher.getDispatchContext().getModelService("setAcroFields");            Map ctx = modelService.makeValid(context, "IN");            ctx.put("acroFieldMap", acroFieldMap);            ctx.put("contentId", acroFormContentId);            Map map = dispatcher.runSync("setAcroFields", ctx);            if (ServiceUtil.isError(map)) {                String errMsg = ServiceUtil.makeErrorMessage(map, null, null, null, null);                System.err.println(errMsg);                ServiceUtil.returnError(errMsg);            }            String pdfFileNameOut = (String)context.get("pdfFileNameOut");            ByteWrapper outByteWrapper = (ByteWrapper)map.get("outByteWrapper");            results.put("outByteWrapper", outByteWrapper);            if (UtilValidate.isNotEmpty(pdfFileNameOut)) {                FileOutputStream fos = new FileOutputStream(pdfFileNameOut);                fos.write(outByteWrapper.getBytes());                fos.close();            }        } catch(FileNotFoundException e) {            System.err.println(e.getMessage());            ServiceUtil.returnError(e.getMessage());        } catch(IOException e) {            System.err.println(e.getMessage());            ServiceUtil.returnError(e.getMessage());        } catch (GenericServiceException e) {            System.err.println(e.getMessage());            ServiceUtil.returnError(e.getMessage());        }                return results;    }        public static ByteWrapper getInputByteWrapper(Map context, GenericDelegator delegator) throws GeneralException {                ByteWrapper inputByteWrapper = (ByteWrapper)context.get("inputByteWrapper");                if (inputByteWrapper == null) {            String pdfFileNameIn = (String)context.get("pdfFileNameIn");            String contentId = (String)context.get("contentId");            if (UtilValidate.isNotEmpty(pdfFileNameIn)) {                try {                    FileInputStream fis = new FileInputStream(pdfFileNameIn);                    int c;                    ByteArrayOutputStream baos = new ByteArrayOutputStream();                    while ((c = fis.read()) != -1) baos.write(c);                    inputByteWrapper = new ByteWrapper(baos.toByteArray());                } catch(FileNotFoundException e) {                    throw(new GeneralException(e.getMessage()));                } catch(IOException e) {                    throw(new GeneralException(e.getMessage()));                }            } else if (UtilValidate.isNotEmpty(contentId)) {                try {                    Locale locale = (Locale)context.get("locale");                    String https = (String)context.get("https");                     String webSiteId = (String)context.get("webSiteId");                    String rootDir = (String)context.get("rootDir");                    GenericValue content = delegator.findByPrimaryKeyCache("Content", UtilMisc.toMap("contentId", contentId));                    String dataResourceId = content.getString("dataResourceId");                    inputByteWrapper = DataResourceWorker.getContentAsByteWrapper(delegator, dataResourceId, https, webSiteId, locale, rootDir);                } catch (GenericEntityException e) {                    throw(new GeneralException(e.getMessage()));                } catch (IOException e) {                    throw(new GeneralException(e.getMessage()));                }            }        }        return inputByteWrapper;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -