New file |
| | |
| | | package com.ots.common.enums; |
| | | |
| | | /** |
| | | * @author zhijie |
| | | * @date 2021/03/19 |
| | | * @Description: 报告邮件标题类 |
| | | */ |
| | | public enum ReportTitle { |
| | | ZH("姓名","Chinese", "%s的%s测评报告"), |
| | | US("Name","English", "%s's %s Report"), |
| | | TAI("ชื่อ","Thai", "รายงานการประเมิน %s ของ %s"), |
| | | ; |
| | | public final String field; |
| | | public final String langType; |
| | | public final String reportTitle; |
| | | |
| | | |
| | | |
| | | ReportTitle(String field,String langType, String reportTitle) { |
| | | this.field = field; |
| | | this.langType = langType; |
| | | this.reportTitle = reportTitle; |
| | | } |
| | | |
| | | public static String getReportTitle(String langType) { |
| | | ReportTitle[] types = ReportTitle.values(); |
| | | for (ReportTitle type : types) { |
| | | if (type.langType.equals(langType)) { |
| | | return type.reportTitle; |
| | | } |
| | | } |
| | | return ""; |
| | | } |
| | | |
| | | public static String getField(String langType) { |
| | | ReportTitle[] types = ReportTitle.values(); |
| | | for (ReportTitle type : types) { |
| | | if (type.langType.equals(langType)) { |
| | | return type.field; |
| | | } |
| | | } |
| | | return ""; |
| | | } |
| | | } |
| | |
| | | StringBuilder builder = new StringBuilder(); |
| | | if (os.toLowerCase().startsWith("mac")) { |
| | | builder.append("/Applications/LibreOffice.app/Contents/MacOS/soffice --headless --convert-to "); |
| | | } else if(os.contains("Windows")){ |
| | | builder.append("cmd /c start soffice --headless --convert-to "); |
| | | } else { |
| | | builder.append("libreoffice6.4 --headless --convert-to "); |
| | | } |
| | | |
| | | builder.append(type).append(" "); |
| | | builder.append("--outdir " + targetPath).append(" "); |
| | | builder.append(sourcePath).append(" "); |
| | |
| | | } |
| | | } catch (Exception e) { |
| | | } |
| | | return exec(builder.toString()); |
| | | return run_cmd(builder.toString()); |
| | | } |
| | | |
| | | public static String run_cmd(String strcmd) { |
| | | // |
| | | Runtime rt = Runtime.getRuntime(); //Runtime.getRuntime()返回当前应用程序的Runtime对象 |
| | | Process ps = null; //Process可以控制该子进程的执行或获取该子进程的信息。 |
| | | try { |
| | | ps = rt.exec(strcmd); //该对象的exec()方法指示Java虚拟机创建一个子进程执行指定的可执行程序,并返回与该子进程对应的Process对象实例。 |
| | | ps.waitFor(); //等待子进程完成再往下执行。 |
| | | } catch (IOException e1) { |
| | | e1.printStackTrace(); |
| | | } catch (InterruptedException e) { |
| | | // TODO Auto-generated catch block |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | int i = ps.exitValue(); //接收执行完毕的返回值 |
| | | if (i == 0) { |
| | | System.out.println("执行完成."); |
| | | } else { |
| | | System.out.println("执行失败."); |
| | | } |
| | | |
| | | ps.destroy(); //销毁子进程 |
| | | ps = null; |
| | | |
| | | return null; |
| | | } |
| | | |
| | | private static String exec(String command) { |
| | | String returnString = ""; |
| | | Runtime runTime = Runtime.getRuntime(); |
| | |
| | | private String reportDate; |
| | | |
| | | private String testToken; |
| | | |
| | | |
| | | /** |
| | | * 获取报告字典的code跟value |
| | | * @param thaiCalculationMap |
| | | * @param type |
| | | * @param langType |
| | | * @return |
| | | */ |
| | | public ReportResultData getTemplateParameters(Map<String, String> thaiCalculationMap, ReportTypeEnum type, LangTypeEnum langType) { |
| | | Map<String, Object> infoMap = new HashMap(); |
| | | infoMap.put("fullName", fullName); |
| | |
| | | infoMap.put("testToken", testToken); |
| | | Map textMap = new HashMap(); |
| | | Map waterDropsMap = new HashMap(); |
| | | //遍历初始化code字典值的value |
| | | getParamList(type).stream().forEach(p -> { |
| | | TLibraryCode calculate = p.calculate(thaiCalculationMap, langType); |
| | | //保存置换后文本字典 例:LIBCAQ0015 : 该候选人在抽象推理能力部分20题中回答正确的题数:<BoldText>14</BoldText> |
| | | textMap.put(p.getName(), Objects.isNull(calculate) || StringUtils.isBlank(calculate.getLangTypeContext(langType)) ? "N/A NONE" : calculate.getLangTypeContext(langType)); |
| | | //保存图片字典 例子:P_Abstract_context_waterDrops : 26.0 |
| | | if (Objects.nonNull(p.getMAQwaterDropsImages())) { |
| | | waterDropsMap.putAll(p.getMAQwaterDropsImages()); |
| | | } |
| | | }); |
| | | //保存之前传进来的题目ID跟一些个人信息 |
| | | textMap.putAll(thaiCalculationMap); |
| | | ReportResultData reportResultData = new ReportResultData(); |
| | | reportResultData.setTextMap(textMap); |
| | |
| | | public List<BaseCondition> getParamList(ReportTypeEnum reportTypeEnum) { |
| | | return init(reportTypeEnum); |
| | | } |
| | | |
| | | /** |
| | | * 初始化字典 |
| | | * @param reportTypeEnum |
| | | * @return |
| | | */ |
| | | private List<BaseCondition> init(ReportTypeEnum reportTypeEnum) { |
| | | List<BaseCondition> paramList = new ArrayList<>(); |
| | | |
| | |
| | | paramList.add(new WaterDropletContentPNumeric()); |
| | | return paramList; |
| | | } |
| | | |
| | | /** |
| | | * 初始化简单的字典code |
| | | * @return |
| | | */ |
| | | private List<String> getSimpleMessageCoreIds() { |
| | | return Arrays.asList("LIBCAQ0005", "LIBCAQ0006", "LIBCAQ0007", "LIBCAQ0008", "LIBCAQ0010", "LIBCAQ0020" |
| | | ,"LIBCAQ0030","LIBCAQ0040","LIBCAQ0050","LIBCAQ0060","LIBCAQ0070","LIBCAQ0080" |
| | |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 获取报告字典 |
| | | * @param map |
| | | * @param codeId |
| | | * @param langType |
| | | * @return |
| | | */ |
| | | public TLibraryCode getMaqReportLibrary(Map<String, String> map, String codeId, LangTypeEnum langType) { |
| | | if (Objects.isNull(codeId)) { |
| | | return null; |
| | |
| | | StringBuilder content = new StringBuilder(); |
| | | String[] split = codeId.split(","); |
| | | TLibraryCode result = new TLibraryCode(); |
| | | /** |
| | | * 根据字典CODE获取对应的字典详情 |
| | | */ |
| | | Arrays.stream(split).forEach(item -> { |
| | | TLibraryCode maqReportLibrary = CacheServiceFactory.getInstance().getMAQReportLibrary(item); |
| | | if (Objects.isNull(maqReportLibrary)) { |
| | |
| | | result.setLibraryCode(maqReportLibrary.getLibraryCode()); |
| | | } |
| | | }); |
| | | //设置对应语言的文字内容 |
| | | result.setLangTypeContext(content.toString(), langType); |
| | | //替换报告字典内容的变量 |
| | | dynamicParameterSubstitution(map, result, langType); |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 替换报告字典内容的变量 |
| | | * @param map |
| | | * @param maqReportLibrary |
| | | * @param langType |
| | | */ |
| | | public void dynamicParameterSubstitution(Map<String, String> map, TLibraryCode maqReportLibrary, LangTypeEnum langType) { |
| | | //根据报告字典内容 定位变量名位置 替换结果 |
| | | map.forEach((key, value) -> { |
| | | String content = maqReportLibrary.getLangTypeContext(langType); |
| | | String replaceStr = "%" + key + "%"; |