邮件模板回填富文本编辑器编辑后发送邮件【爬坑记录】

最近做了一个自动发邮件功能,页面选择订单后,根据产品类型判断选择打开弹窗的邮件模板,选择模板并把拉出富文本编辑器,将选的邮件模板回填到富文本编辑器,可进行在即编辑操作,发送邮件。摸索着完成了,记录一下爬坑经历,以免以后再次用到。

页面展示:

在这里插入图片描述
在这里插入图片描述
带有附件的邮件:
在这里插入图片描述


后台代码展示:

查看邮件模板:

    public String getQueryEmailTemplate() {
        String orderId = request.getParameter("orderID");
        if (orderId == null) {
            Result mResult = new Result();
            mResult.setStatusCode(300);
            mResult.setTitle("操作失败!");
            mResult.setMessage("订单号不能为空!");
            return new Gson().toJson(mResult);
        }
        logger.info("查询品牌下的邮件模板:");
        if (ObjectUtils.isEmpty(orderId)) {
            Result mResult = new Result();
            mResult.setStatusCode(300);
            mResult.setTitle("操作失败!");
            mResult.setMessage("找不到订单号!");
            return new Gson().toJson(mResult);
        }
        List<PageOrder> pageOrders = orderInfoService.queryOrderById(orderId);
        if (pageOrders == null || pageOrders.size() < 1) {
            Result mResult = new Result();
            mResult.setStatusCode(300);
            mResult.setTitle("操作失败!");
            mResult.setMessage("找不到订单信息!");
            return new Gson().toJson(mResult);
        }
        if (ObjectUtils.isEmpty(pageOrders.get(0).getProductNameZH())) {
            Result mResult = new Result();
            mResult.setStatusCode(300);
            mResult.setTitle("操作失败!");
            mResult.setMessage("找不到订单品牌信息!");
            return new Gson().toJson(mResult);
        }
        return queryEmailTemaplates(pageOrders);
    }

queryEmailTemaplates 方法是:封装处理邮件模板的方法

public static String queryEmailTemaplates(List<PageOrder> pageOrders) {
        List<ComboboxInfoVo> temolate = new ArrayList<>();
        if (pageOrders.get(0).getProductNameZH().contains(DIGICERT) || pageOrders.get(0).getProductNameZH().contains(SYMANTEC) || pageOrders.get(0).getProductNameZH().contains(GEOTRUST) || pageOrders.get(0).getProductNameZH().contains(THAWTE)) {
            // Digicert 区分 品牌类型
            if (Integer.parseInt(pageOrders.get(0).getProductType()) == ProductTypeEnum.OV.getValue() || Integer.parseInt(pageOrders.get(0).getProductType()) == ProductTypeEnum.EV.getValue()) {
                temolate.add(new ComboboxInfoVo.Builder("全部", "").build());
                temolate.add(new ComboboxInfoVo.Builder("全邮件", "Digicert_all_email").build());
                temolate.add(new ComboboxInfoVo.Builder("只发电话", "Digicert_phone").build());
                temolate.add(new ComboboxInfoVo.Builder("只发域名", "Digicert_domain").build());
                temolate.add(new ComboboxInfoVo.Builder("域名用DNS验证", "Digicert_dns_auth").build());
                temolate.add(new ComboboxInfoVo.Builder("域名用文件验证", "Digicert_file_auth").build());
                temolate.add(new ComboboxInfoVo.Builder("域名用邮箱验证邮件", "Digicert_email_auth").build());
                temolate.add(new ComboboxInfoVo.Builder("电话用邮箱验证邮件", "Digicert_email_auth_phone").build());
                temolate.add(new ComboboxInfoVo.Builder("证书签发邮件", "Digicert_cert_email").build());
                return new Gson().toJson(temolate);
            }
            if (Integer.parseInt(pageOrders.get(0).getProductType()) == 4) {
                temolate.add(new ComboboxInfoVo.Builder("全部", "").build());
                temolate.add(new ComboboxInfoVo.Builder("代码签名证书申请流程", "Digicert_CS_apply").build());
                return new Gson().toJson(temolate);
            }
        }
        if (pageOrders.get(0).getProductNameZH().contains(ENTRUST)) {
            temolate.add(new ComboboxInfoVo.Builder("全部", "").build());
            temolate.add(new ComboboxInfoVo.Builder("全邮件", "Entrust_all_email").build());
            temolate.add(new ComboboxInfoVo.Builder("只发域名", "Entrust_domain").build());
            temolate.add(new ComboboxInfoVo.Builder("域名用DNS验证", "Entrust_dns_auth").build());
            temolate.add(new ComboboxInfoVo.Builder("域名用文件验证", "Entrust_file_auth").build());
            temolate.add(new ComboboxInfoVo.Builder("域名用邮箱验证邮件", "Entrust_email_auth").build());
            return new Gson().toJson(temolate);
        }
        if (pageOrders.get(0).getProductNameZH().contains(GLOBALSIGN)) {
            temolate.add(new ComboboxInfoVo.Builder("全部", "").build());
            temolate.add(new ComboboxInfoVo.Builder("全邮件", "GlobalSign_all_email").build());
            temolate.add(new ComboboxInfoVo.Builder("只发域名", "GlobalSign_domain").build());
            temolate.add(new ComboboxInfoVo.Builder("订单信息确认删除邮件", "GlobalSign_orderInfo").build());
            temolate.add(new ComboboxInfoVo.Builder("域名用DNS验证", "GlobalSign_dns_auth").build());
            temolate.add(new ComboboxInfoVo.Builder("域名用文件验证", "GlobalSign_file_auth").build());
            temolate.add(new ComboboxInfoVo.Builder("域名用邮箱验证邮件", "GlobalSign_email_auth").build());
            return new Gson().toJson(temolate);
        }
        if (pageOrders.get(0).getProductNameZH().contains(SSL) || pageOrders.get(0).getProductNameZH().contains(ACTALIS)) {
            temolate.add(new ComboboxInfoVo.Builder("全部", "").build());
            temolate.add(new ComboboxInfoVo.Builder("全邮件", "Actalis_all_email").build());
            temolate.add(new ComboboxInfoVo.Builder("actalis证书-鉴证人员联系信息", "Actalis_cert").build());
            return new Gson().toJson(temolate);
        }
        if (pageOrders.get(0).getProductNameZH().contains(VTRUS)) {
            temolate.add(new ComboboxInfoVo.Builder("全部", "").build());
            temolate.add(new ComboboxInfoVo.Builder("全邮件", "vTrus_all_email").build());
            temolate.add(new ComboboxInfoVo.Builder("邮件1", "vTrus1").build());
            temolate.add(new ComboboxInfoVo.Builder("邮件2", "vTrus2").build());
            return new Gson().toJson(temolate);
        }
        return new Gson().toJson(temolate);
    }

生成邮件模板:将动态数据和模板整合出来

public String saveEmailTemplate() {
        String orderIdz = request.getParameter("orderID");
        String emailTempalte = request.getParameter("emailTempalte");
        if (emailTempalte == null) {
            Result mResult = new Result();
            mResult.setStatusCode(300);
            mResult.setTitle("操作失败!");
            mResult.setMessage("邮件模板不能为空!");
            return new Gson().toJson(mResult);
        }
        OrderInfo order = orderInfoService.selectOrderByOrderID(orderIdz);
        if (ObjectUtils.isEmpty(order)) {
            Result mResult = new Result();
            mResult.setStatusCode(300);
            mResult.setTitle("找不到订单号!");
            mResult.setMessage("找不到订单号!");
            return new Gson().toJson(mResult);
        }
        LoginUserInfo currUserInfo = (LoginUserInfo) request.getSession().getAttribute("CurrUserInfo");
        UserInfo userInfo = currUserInfo.getUserInfo();
        if (ObjectUtils.isEmpty(userInfo)) {
            Result mResult = new Result();
            mResult.setStatusCode(300);
            mResult.setTitle("操作失败!");
            mResult.setMessage("找不到当前用户信息!");
            return new Gson().toJson(mResult);
        }
        List<ContactInfo> contactInfos = contactInfoMapper.selectContactInfoByOrderID(orderIdz);
        // 获取CC
        List<ContactInfo> contactInfo = contactInfos
                .stream()
                .filter(contactInfox -> contactInfox.getContactType() == ContactTypeEnum.CC.getValue())
                .collect(Collectors.toList());
        // 获取CC
        List<ContactInfo> contactInfoTc = contactInfos
                .stream()
                .filter(contactInfox -> contactInfox.getContactType() == ContactTypeEnum.TC.getValue())
                .collect(Collectors.toList());
        if (ObjectUtils.isEmpty(contactInfo) || contactInfo.size() <= 0) {
            Result mResult = new Result();
            mResult.setStatusCode(300);
            mResult.setTitle("操作失败!");
            mResult.setMessage("找不到公司联系人信息!");
            return new Gson().toJson(mResult);
        }
        if (ObjectUtils.isEmpty(contactInfoTc) || contactInfo.size() <= 0) {
            Result mResult = new Result();
            mResult.setStatusCode(300);
            mResult.setTitle("操作失败!");
            mResult.setMessage("找不到技术联系人信息!");
            return new Gson().toJson(mResult);
        }
        HashMap<Object, Object> objectObjectHashMap = new HashMap<>(16);
        objectObjectHashMap.put("templateName", "symantecov.ftl");
        objectObjectHashMap.put("lawyerPath", "");
        chooseTemplate(objectObjectHashMap, emailTempalte, order);
        Map<String, Object> map = new HashMap<>(16);
        map.put("acUserName", new StringBuffer().append(contactInfo.get(0).getFirstName()).append(" ").append(contactInfo.get(0).getLastName()).toString());
        map.put("acTitle", contactInfo.get(0).getTitle());
        map.put("acEmail", contactInfo.get(0).getEmail());
        // 公司客户
        map.put("companyName", order.getCompanyName());
        // 域名
        map.put("commonName", order.getCommonName());
        // 技术联系人
        map.put("tcEmail", contactInfoTc.get(0).getEmail());
        // 鉴证人员姓名
        map.put("authName", userInfo.getUserName());
        // 鉴证人员 电话
        map.put("authPhone", userInfo.getPhoneNum());
        map.put("address", new StringBuffer().append(order.getAddress()).append(" ").append(order.getPostalCode()).toString());
        map.put("province", order.getState());
        map.put("city", order.getLocation());
        map.put("postCode", order.getPostalCode());
        map.put("orgName", new StringBuffer().append(order.getCompanyName()).append(" ").append(order.getOrganizationName()).toString());
        map.put("acPhone", contactInfo.get(0).getPhone());
        map.put("country", "中国");
        //生成html 字符串
        String content = WordUtils.saveEmailTemplate(map, (String) objectObjectHashMap.get("templateName"), (String) objectObjectHashMap.get("lawyerPath"));
        if (StringUtils.isBlank(content)) {
            Result mResult = new Result();
            mResult.setStatusCode(300);
            mResult.setTitle("操作失败!");
            mResult.setMessage("未获取到模板内容!");
            return new Gson().toJson(mResult);
        }
        Result mResult = new Result();
        mResult.setStatusCode(200);
        mResult.setFilePath(content);
        mResult.setTitle("操作成功!");
        mResult.setMessage("模板获取成功!");
        return new Gson().toJson(mResult);
    }

chooseTemplate: 方法是匹配页面传入的模板

 public static void chooseTemplate(HashMap<Object, Object> objectObjectHashMap, String emailTempalte, OrderInfo order) {
        switch (emailTempalte) {
            // Digicert 产品
            case "Digicert_all_email":
                objectObjectHashMap.put("templateName", "Digicert_all_email.ftl");
                objectObjectHashMap.put("lawyerPath", URL + File.separator + order.getCompanyName() + "-全邮件.doc");
                break;
            case "Digicert_phone":
                objectObjectHashMap.put("templateName", "Digicert_phone.ftl");
                objectObjectHashMap.put("lawyerPath", URL + File.separator + order.getCompanyName() + "-只发电话.doc");
                break;
            case "Digicert_domain":
                objectObjectHashMap.put("templateName", "Digicert_domain.ftl");
                objectObjectHashMap.put("lawyerPath", URL + File.separator + order.getCompanyName() + "-只发域名.doc");
                break;
            case "Digicert_dns_auth":
                objectObjectHashMap.put("templateName", "Digicert_dns_auth.ftl");
                objectObjectHashMap.put("lawyerPath", URL + File.separator + order.getCompanyName() + "-域名用DNS验证.doc");
                break;
            case "Digicert_file_auth":
                objectObjectHashMap.put("templateName", "Digicert_file_auth.ftl");
                objectObjectHashMap.put("lawyerPath", URL + File.separator + order.getCompanyName() + "-域名用文件验证.doc");
                break;
            case "Digicert_email_auth":
                objectObjectHashMap.put("templateName", "Digicert_email_auth.ftl");
                objectObjectHashMap.put("lawyerPath", URL + File.separator + order.getCompanyName() + "-域名用邮箱验证邮件.doc");
                break;
            case "Digicert_email_auth_phone":
                objectObjectHashMap.put("templateName", "Digicert_email_auth_phone.ftl");
                objectObjectHashMap.put("lawyerPath", URL + File.separator + order.getCompanyName() + "-电话用邮箱验证邮件.doc");
                break;
            case "Digicert_cert_email":
                objectObjectHashMap.put("templateName", "Digicert_cert_email.ftl");
                objectObjectHashMap.put("lawyerPath", URL + File.separator + order.getCompanyName() + "-证书签发邮件.doc");
                break;
            // 代码签名
            case "Digicert_CS_apply":
                objectObjectHashMap.put("templateName", "Digicert_CS_apply.ftl");
                objectObjectHashMap.put("lawyerPath", URL + File.separator + order.getCompanyName() + "-代码签名证书申请流程.doc");
                break;
            // Entrust
            case "Entrust_all_email":
                objectObjectHashMap.put("templateName", "Entrust_all_email.ftl");
                objectObjectHashMap.put("lawyerPath", URL + File.separator + order.getCompanyName() + "-全邮件.doc");
                break;
            case "Entrust_domain":
                objectObjectHashMap.put("templateName", "Entrust_domain.ftl");
                objectObjectHashMap.put("lawyerPath", URL + File.separator + order.getCompanyName() + "-只发域名.doc");
                break;
            case "Entrust_dns_auth":
                objectObjectHashMap.put("templateName", "Entrust_dns_auth.ftl");
                objectObjectHashMap.put("lawyerPath", URL + File.separator + order.getCompanyName() + "-域名用DNS验证.doc");
                break;
            case "Entrust_file_auth":
                objectObjectHashMap.put("templateName", "Entrust_file_auth.ftl");
                objectObjectHashMap.put("lawyerPath", URL + File.separator + order.getCompanyName() + "-域名用文件验证.doc");
                break;
            case "Entrust_email_auth":
                objectObjectHashMap.put("templateName", "Entrust_email_auth.ftl");
                objectObjectHashMap.put("lawyerPath", URL + File.separator + order.getCompanyName() + "-域名用邮箱验证邮件.doc");
                break;
            // GlobalSign
            case "GlobalSign_all_email":
                objectObjectHashMap.put("templateName", "GlobalSign_all_email.ftl");
                objectObjectHashMap.put("lawyerPath", URL + File.separator + order.getCompanyName() + "-全邮件.doc");
                break;
            case "GlobalSign_domain":
                objectObjectHashMap.put("templateName", "GlobalSign_domain.ftl");
                objectObjectHashMap.put("lawyerPath", URL + File.separator + order.getCompanyName() + "-只发域名.doc");
                break;
            case "GlobalSign_orderInfo":
                objectObjectHashMap.put("templateName", "GlobalSign_orderInfo.ftl");
                objectObjectHashMap.put("lawyerPath", URL + File.separator + order.getCompanyName() + "-订单信息确认删除邮件.doc");
                break;
            case "GlobalSign_dns_auth":
                objectObjectHashMap.put("templateName", "GlobalSign_dns_auth.ftl");
                objectObjectHashMap.put("lawyerPath", URL + File.separator + order.getCompanyName() + "-域名用DNS验证.doc");
                break;
            case "GlobalSign_file_auth":
                objectObjectHashMap.put("templateName", "GlobalSign_file_auth.ftl");
                objectObjectHashMap.put("lawyerPath", URL + File.separator + order.getCompanyName() + "-域名用文件验证.doc");
                break;
            case "GlobalSign_email_auth":
                objectObjectHashMap.put("templateName", "GlobalSign_email_auth.ftl");
                objectObjectHashMap.put("lawyerPath", URL + File.separator + order.getCompanyName() + "-域名用邮箱验证邮件.doc");
                break;
            // Actalis
            case "Actalis_all_email":
                objectObjectHashMap.put("templateName", "Actalis_all_email.ftl");
                objectObjectHashMap.put("lawyerPath", URL + File.separator + order.getCompanyName() + "-全邮件.doc");
                break;
            case "Actalis_cert":
                objectObjectHashMap.put("templateName", "Actalis_cert.ftl");
                objectObjectHashMap.put("lawyerPath", URL + File.separator + order.getCompanyName() + "-actalis证书-鉴证人员联系信息.doc");
                break;
            // VTRUS
            case "vTrus_all_email":
                objectObjectHashMap.put("templateName", "vTrus_all_email.ftl");
                objectObjectHashMap.put("lawyerPath", URL + File.separator + order.getCompanyName() + "-全邮件.doc");
                break;
            case "vTrus1":
                objectObjectHashMap.put("templateName", "vTrus1.ftl");
                objectObjectHashMap.put("lawyerPath", URL + File.separator + order.getCompanyName() + "-邮件1.doc");
                break;
            case "vTrus2":
                objectObjectHashMap.put("templateName", "vTrus2.ftl");
                objectObjectHashMap.put("lawyerPath", URL + File.separator + order.getCompanyName() + "-邮件2.doc");
                break;
            default:
                break;
        }
    }

saveEmailTemplate: 是处理数据和模板发方法,并将模板写入富文本编辑器中

    public static String saveEmailTemplate(Map dataMap, String templateName, String fileFullPath) {
        log.info("saveEmailTemplate:方法进入");
        StringWriter writer = null;
        try {
            // 创建配置实例
            Configuration configuration = new Configuration();
            // 设置编码
            configuration.setDefaultEncoding("GBK");
            // 设置处理空值
            configuration.setClassicCompatible(true);
            // 设置ftl模板文件加载方式
            String path = Thread.currentThread().getContextClassLoader().getResource("").getPath();
            configuration.setDirectoryForTemplateLoading(new File(path));
            Template template = configuration.getTemplate(templateName);
            writer = new StringWriter();
            template.process(dataMap, writer);
            writer.flush();
            return writer.toString();
        } catch (Exception e) {
            log.info("生成word文件出错:" + e.getMessage());
            e.printStackTrace();
            return e.getMessage();
        }
    }

发送邮件

发送邮件请跳转: 发送邮件配置和代码
富文本编辑器 使用的静态包

public String sendEmail(String orderID, String emailFtl, String emailTempalte) {
        logger.info("发送邮件订单号:{}" + orderID);
        if (ObjectUtils.isEmpty(emailFtl)) {
            Result mResult = new Result();
            mResult.setStatusCode(300);
            mResult.setTitle("操作失败!");
            mResult.setMessage("邮件模板不能为空!");
            return new Gson().toJson(mResult);
        }
        if (ObjectUtils.isEmpty(emailTempalte)) {
            Result mResult = new Result();
            mResult.setStatusCode(300);
            mResult.setTitle("操作失败!");
            mResult.setMessage("模板名称为空!");
            return new Gson().toJson(mResult);
        }
        LoginUserInfo currUserInfo = (LoginUserInfo) request.getSession().getAttribute("CurrUserInfo");
        UserInfo userInfo = currUserInfo.getUserInfo();
        if (ObjectUtils.isEmpty(userInfo)) {
            Result mResult = new Result();
            mResult.setStatusCode(300);
            mResult.setTitle("操作失败!");
            mResult.setMessage("找不到当前用户信息!");
            return new Gson().toJson(mResult);
        }
        List<PageOrder> pageOrders = orderInfoService.queryOrderById(orderID);
        if (pageOrders == null || pageOrders.size() < 1) {
            Result mResult = new Result();
            mResult.setStatusCode(300);
            mResult.setTitle("操作失败!");
            mResult.setMessage("找不到订单信息!");
            return new Gson().toJson(mResult);
        }
        List<ContactInfo> contactInfos = contactInfoMapper.selectContactInfoByOrderID(orderID);
        // 获取TC
        List<ContactInfo> contactInfoTc = contactInfos
                .stream()
                .filter(contactInfox -> contactInfox.getContactType() == ContactTypeEnum.TC.getValue())
                .collect(Collectors.toList());
        // 获取TC
        List<ContactInfo> contactInfo = contactInfos
                .stream()
                .filter(contactInfox -> contactInfox.getContactType() == ContactTypeEnum.CC.getValue())
                .collect(Collectors.toList());
        if (ObjectUtils.isEmpty(contactInfo) || contactInfo.size() <= 0) {
            Result mResult = new Result();
            mResult.setStatusCode(300);
            mResult.setTitle("操作失败!");
            mResult.setMessage("找不到公司联系人信息!");
            return new Gson().toJson(mResult);
        }
        if (ObjectUtils.isEmpty(contactInfoTc) || contactInfoTc.size() <= 0) {
            Result mResult = new Result();
            mResult.setStatusCode(300);
            mResult.setTitle("操作失败!");
            mResult.setMessage("找不到技术联系人信息!");
            return new Gson().toJson(mResult);
        }
        // 发送邮件 - 发送订单联系人 技术联系人,密送当前登录鉴证人员
        // 新建EmailModel接收对象
        EmailModel emailContext = new EmailModel();
        String emailTemplateName = emailTemplateName(emailTempalte, pageOrders);
        emailContext.setTitle(emailTemplateName);
        // 接收人
        emailContext.setTo(contactInfoTc.get(0).getEmail());
        // 抄送
        emailContext.setCc(contactInfo.get(0).getEmail());
        emailContext.setFrom("发邮件邮箱");
        emailContext.setFromName("名称");
        // 密送
        if (ObjectUtils.isEmpty(userInfo.getCompanyMail())) {
            emailContext.setBcc(userInfo.getPrivateMail());
        } else {
            emailContext.setBcc(userInfo.getCompanyMail());
        }
        Map<Object, Object> emailMap = new HashMap<>(16);
        String htmlBegin = "<html><head></head><body>";
        String htmlEnd = "</body></html>";
        StringBuilder builder = new StringBuilder();
        builder.append(htmlBegin);
        builder.append(emailFtl);
        builder.append(htmlEnd);
        emailMap.put("emailFtl", builder.toString());
        //附件
        List<Attachment> attachments = queryAttachments(emailTempalte, systemConfigService);
        emailContext.setAttachment(attachments);
        emailContext.setContext(emailMap);
        if (new MimeMailService(emailContext).sendEmailTemplate()) {
            Result mResult = new Result();
            mResult.setStatusCode(300);
            mResult.setTitle("邮件发送成功");
            mResult.setMessage("邮件成功发送到:" + emailContext.getTo() + "," + emailContext.getCc() + "!");
            return new Gson().toJson(mResult);
        } else {
            Result mResult = new Result();
            mResult.setStatusCode(300);
            mResult.setTitle("邮件发送失败");
            mResult.setMessage("邮件发送到:" + emailContext.getTo() + "," + emailContext.getCc() + "失败!");
            return new Gson().toJson(mResult);
        }
    }

emailTemplateName 方法 是处理主题名称

 public static String emailTemplateName(String emailTempalte, List<PageOrder> pageOrders) {
        logger.info("选择的模板:{}" + emailTempalte);
        if (ObjectUtils.isEmpty(pageOrders.get(0).getCompanyName())) {
            Result mResult = new Result();
            mResult.setStatusCode(300);
            mResult.setTitle("操作失败!");
            mResult.setMessage("找不到公司名称!");
            return new Gson().toJson(mResult);
        }
        if (pageOrders.get(0).getProductNameZH().contains(DIGICERT) || pageOrders.get(0).getProductNameZH().contains(SYMANTEC) || pageOrders.get(0).getProductNameZH().contains(GEOTRUST) || pageOrders.get(0).getProductNameZH().contains(THAWTE)) {
            if (Integer.parseInt(pageOrders.get(0).getProductType()) == ProductTypeEnum.OV.getValue() || Integer.parseInt(pageOrders.get(0).getProductType()) == ProductTypeEnum.EV.getValue()) {
                String emailTemplateName = new StringBuffer().append(pageOrders.get(0).getCompanyName()).append("公司-SSL证书审核验证流程").toString();
                return emailTemplateName;
            }
            if (Integer.parseInt(pageOrders.get(0).getProductType()) == 4) {
                String emailTemplateName = new StringBuffer().append(pageOrders.get(0).getCompanyName()).append("公司-代码签名审核验证流程").toString();
                return emailTemplateName;
            }
        }
        if (pageOrders.get(0).getProductNameZH().contains(ENTRUST)) {
            String emailTemplateName = new StringBuffer().append(pageOrders.get(0).getCompanyName()).append("公司-SSL证书审核验证流程").toString();
            return emailTemplateName;
        }
        if (pageOrders.get(0).getProductNameZH().contains(GLOBALSIGN)) {
            String emailTemplateName = new StringBuffer().append(pageOrders.get(0).getCompanyName()).append("公司-SSL证书审核验证流程").toString();
            return emailTemplateName;
        }
        if (pageOrders.get(0).getProductNameZH().contains(SSL) || pageOrders.get(0).getProductNameZH().contains(ACTALIS)) {
            String emailTemplateName = new StringBuffer().append(pageOrders.get(0).getCompanyName()).append("公司-SSL证书审核验证流程").toString();
            return emailTemplateName;
        }
        if (pageOrders.get(0).getProductNameZH().contains(VTRUS)) {
            String emailTemplateName = new StringBuffer().append(pageOrders.get(0).getCompanyName()).append("公司-SSL证书审核验证流程").toString();
            return emailTemplateName;
        }
        return null;
    }

模板:
在这里插入图片描述

前端代码展示:

前端页面需要引入 富文本编辑器的包

<a href="javascript:void(0)"
       data-toggle="topjui-menubutton"
       data-options="method:'openDialog',
           extend: '#productDg-toolbar',
           iconCls:'fa fa-hand-stop-o',
           btnCls: 'topjui-btn-orange',
           grid: {
           		uncheckedMsg:'请先勾选您要发邮件的订单',
           		type: 'datagrid',
            	id: 'productDg'
           	},
           dialog:{
               id:'emailTemplate',
               title:'邮件模板',
               modal: true,
               href:_ctx + 'auth/display?pageName=authenticTask_emailTemplate&orderID={orderID}',
               buttonsGroup:[
                   <%-- {text:'保存',url:_ctx + 'auth/operator?opName=emailTemplate&opType=saveEmailTemplate',iconCls:'fa fa-plus',handler:'ajaxForm',btnCls:'topjui-btn-green'},--%>
                   {text:'编辑模板',
					iconCls:'fa fa-save',
					handler:'emailSumit',
					btnCls:'topjui-btn-green'
					}
               ]
           }">邮件模板</a>

邮件模板选择

 // 邮件模板选择
    function emailSumit() {
        var orderID = $("input[name=orderID]").val();
        var emailTempalte = $("input[name=emailTempalte]").val();
        console.log("sss: " + emailTempalte)
        var $editDialog = $('<form></form>');
        $editDialog.iDialog({
            title: '邮件模板编辑',
            width: 1686,
            height: 810,
            closed: false,
            cache: false,
            href: '<%=request.getContextPath()%>/auth/display?pageName=editor_add&orderID='+orderID+'&emailTempalte='+emailTempalte,
            modal: true,
            buttons: [{
                text: '发送邮件',
                iconCls: 'fa fa-save',
                btnCls: 'topjui-btn-blue',
                handler: function () {
                    var emailFtl = $("textarea[name=emailFtl]").val();
                    var queryParams = {'orderID': orderID, 'emailFtl': emailFtl, 'emailTempalte': emailTempalte};
                    console.log("订单号+邮件模板", queryParams)
                    var url = _ctx + 'auth/operator?opName=emailTemplate&opType=sendEmail';
                    $.ajax({
                        url: url,
                        data: queryParams,
                        type: 'POST',
                        success: function (data) {
                            $.iMessager.progress('close');
                            if (data.statusCode == 200) {
                                $.iMessager.alert(data.title, data.message, 'info', function () {
                                    $editDialog.iDialog('close');
                                });
                            } else {
                                $.iMessager.alert('data.title', data.message, 'info');
                            }
                            loadPage();
                        }
                    })
                    // window.open(url);
                }
            }, {
                text: '关闭',
                iconCls: 'fa fa-close',
                btnCls: 'topjui-btn-red',
                handler: function () {
                    $editDialog.iDialog('close');
                }
            }],
            onLoad: function () {
                $("input[name=orderID]").val(orderID);
            }
        });

    }

模板页面:

<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8" %>
<div style="text-align: center;margin-top: 20px;">
    <input type="hidden" id="order_id" value="${orderID}">
    <div class="topjui-fluid">
        <fieldset>
            <legend>订单号</legend>
        </fieldset>
        <div class="topjui-row">
            <div class="topjui-col-sm6">
                <label class="topjui-form-label">订单号: </label>
                <div class="topjui-input-block">
                    <input type="text" name="orderID" id="orderID" style="
                        border: none;
                        font-size: 13px;
                        color: red;
                        margin-left: 14px;
                        height: 30px;
                        width: 217px;"
                           readonly/>
                </div>
            </div>
        </div>
        <fieldset>
            <legend>邮件模板</legend>
        </fieldset>
        <div class="topjui-row">
            <div class="topjui-col-sm9">
                <label class="topjui-form-label">邮件模板</label>
                <div class="topjui-input-block">
                    <input type="text" name="emailTempalte"
                           data-toggle="topjui-combobox"
                           data-options="url:'<%=request.getContextPath()%>/auth/operator?opName=emailTemplate&opType=queryEmailTemplate&orderID=${orderID}'">
                </div>
            </div>
        </div>
    </div>
</div>
<script type="application/javascript">
    $(function () {
        var val = $("#order_id").val();
        $("#orderID").val(val);
    })
</script>

富文本编辑器页面:

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<input type="hidden" id="uuid" name="uuid">
<input type="hidden" name="visitNums">
<input type="hidden" id="order_id" value="${orderID}">
<input type="hidden" id="email_tempalte" value="${emailTempalte}">
<div class="topjui-fluid">
    <fieldset>
        <legend>订单号</legend>
    </fieldset>
    <div class="topjui-row">
        <div class="topjui-col-sm6">
            <label class="topjui-form-label">订单号: </label>
            <div class="topjui-input-block">
                <input type="text" name="orderID" id="orderID" style="
                        border: none;
                        font-size: 13px;
                        color: red;
                        margin-left: 14px;
                        height: 30px;
                        width: 217px;"
                       readonly/>
            </div>
        </div>
    </div>
</div>
<table class="editTable">
    <tr>
        <fieldset>
            <legend>文本编辑器</legend>
        </fieldset>
        <td colspan="3">
            <textarea name="emailFtl" data-toggle="topjui-ueditor" data-options="id:'contentAddEditor'"></textarea>
        </td>
    </tr>
</table>
<script type="application/javascript">
    $(function () {
        var val = $("#order_id").val();
        $("#orderID").val(val);
        var email_tempalte = $("#email_tempalte").val();
        $("#emailTempalte").val(email_tempalte);
        getEmailTemplate(val, email_tempalte);
    })

    function getEmailTemplate(orderID, emailTempalte) {
        var url = '<%=request.getContextPath()%>/auth/operator?opName=emailTemplate&opType=saveEmailTemplate&orderID=' + orderID + '&emailTempalte=' + emailTempalte
        $.post(url, function (data) {
            if (data.statusCode == 200) {
                editorAssign(data.filePath);
                return;
            }
            alert(data.msg);
        });
    }

    function editorAssign(html) {
        var editor = UE.getEditor('contentAddEditor');
        editor.ready(function (editor) {
            UE.getEditor('contentAddEditor').execCommand('insertHtml', html);
        });
    }
</script>
<%--
<script th:inline="javascript" type="text/javascript">
    var ctx = /*[[@{/}]]*/'';
</script>
<script type="text/javascript" src="<%=request.getContextPath()%>/static/public/js/projectjs/ueditor.js" th:src="@{<%=request.getContextPath()%>/static/public/js/projectjs/ueditor.js}"></script>--%>
已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 成长之路 设计师:Amelia_0503 返回首页