Search in sources :

Example 1 with MailTemplate

use of com.itrus.portal.db.MailTemplate in project portal by ixinportal.

the class MailTemplateController method show.

// 查看邮件模版
@RequestMapping(value = "/{id}", produces = "text/html")
public String show(@PathVariable("id") Long id, Model uiModel) {
    MailTemplate mailtemplate = sqlSession.selectOne("com.itrus.portal.db.MailTemplateMapper.selectByPrimaryKey", id);
    if (mailtemplate == null) {
        return "status403";
    }
    String adminProject = getRoleProjects();
    if (adminProject != null && adminProject.equals(mailtemplate.getProjectName())) {
        return "status403";
    }
    Project project = sqlSession.selectOne("com.itrus.portal.db.ProjectMapper.selectByPrimaryKey", mailtemplate.getProjectName());
    uiModel.addAttribute("mailtemplate", mailtemplate);
    uiModel.addAttribute("project", project);
    return "mailtemplate/show";
}
Also used : Project(com.itrus.portal.db.Project) MailTemplate(com.itrus.portal.db.MailTemplate) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with MailTemplate

use of com.itrus.portal.db.MailTemplate in project portal by ixinportal.

the class MailTemplateController method List.

// 邮件模版列表
@RequestMapping(produces = "text/html")
public String List(@RequestParam(value = "project", required = false) Long project, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size, Model uiModel) {
    uiModel.addAttribute("project", project);
    // page,size
    if (page == null || page < 1)
        page = 1;
    if (size == null || size < 1)
        size = 10;
    MailTemplateExample mte = new MailTemplateExample();
    MailTemplateExample.Criteria mtCriteria = mte.or();
    if (null != project) {
        mtCriteria.andProjectNameEqualTo(project);
    }
    Integer count = sqlSession.selectOne("com.itrus.portal.db.MailTemplateMapper.countByExample", mte);
    if (page > 1 && size * (page - 1) >= count) {
        page = (count + size - 1) / size;
    }
    // =====存放总记录数、总页数、当前页、一页显示的记录
    uiModel.addAttribute("count", count);
    uiModel.addAttribute("pages", (count + size - 1) / size);
    uiModel.addAttribute("page", page);
    uiModel.addAttribute("size", size);
    Integer offset = size * (page - 1);
    mte.setOffset(offset);
    mte.setLimit(size);
    mte.setOrderByClause("create_time desc");
    List<MailTemplate> mailTemplates = sqlSession.selectList("com.itrus.portal.db.MailTemplateMapper.selectByExample", mte);
    uiModel.addAttribute("mailTemplates", mailTemplates);
    uiModel.addAttribute("projectmap", getProjectMapOfAdmin());
    return "mailtemplate/list";
}
Also used : MailTemplate(com.itrus.portal.db.MailTemplate) MailTemplateExample(com.itrus.portal.db.MailTemplateExample) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with MailTemplate

use of com.itrus.portal.db.MailTemplate in project portal by ixinportal.

the class BaiWangEmailServiceImpl method sendEmailToUser.

public Map<String, Object> sendEmailToUser(ExtraBill bill) throws MessagingException, Exception {
    Map<String, Object> retMap = new HashMap<>();
    retMap.put("retCode", 0);
    Project project = projectService.selectByPrimaryKey(bill.getProject());
    ExtraProduct product = extraProductService.selectByPrimaryKey(bill.getExtraProduct());
    UserInfo userInfo = userInfoService.getUserInfoById(bill.getUniqueId());
    if (StringUtils.isBlank(userInfo.getEmail())) {
        retMap.put("retMsg", "尚未登记邮箱,请登记邮箱并验证");
        return retMap;
    }
    if (null == userInfo.getTrustEmail() || userInfo.getTrustEmail().equals(false)) {
        retMap.put("retMsg", "您的邮箱尚未通过验证,请验证通过后再处理");
        return retMap;
    }
    Enterprise enterprise = enterpriseService.getEnterpriseById(bill.getEnterprise());
    MailTemplate mailTemplate = mailTemplateService.getMailTemplatesByProjectIdAndType(bill.getProject(), ComNames.MAIL_TEMPLATE_BWDJTZ);
    if (null == mailTemplate) {
        retMap.put("retMsg", "服务端出现未知错误,请联系系统管理员,错误代码:bwtz001");
        LogUtil.syslog(sqlSession, "邮件模版异常", "项目:" + bill.getProject() + ", 未配置百望单机通知邮件模版");
        return retMap;
    }
    // 给订单对应的用户发送邮件信息
    String[] mailOfUser = new String[] { userInfo.getEmail() };
    Map<String, File> proxyMap = new HashMap<String, File>();
    String instructions = product.getInstructions();
    File filePath = extraProductService.getFilePathById(product.getId());
    if (!filePath.exists()) {
        filePath.mkdir();
    }
    File file = new File(filePath, instructions);
    proxyMap.put("单机版开票软件操作指南.fdf", file);
    String subject = mailTemplate.getName().replace("projectname", project.getName()).replace("productname", product.getAppName());
    Bwdjrecord bwdjrecord = bwdjRecordService.getBwdjrecordByExtraBillId(bill.getId());
    String content = mailTemplate.getContent().replace("downloadurl", bwdjrecord.getDownLoadUrl());
    sendEmailService.sendEmail(content, mailOfUser, subject, false, proxyMap);
    retMap.put("retCode", 1);
    return retMap;
}
Also used : Bwdjrecord(com.itrus.portal.db.Bwdjrecord) HashMap(java.util.HashMap) UserInfo(com.itrus.portal.db.UserInfo) Project(com.itrus.portal.db.Project) ExtraProduct(com.itrus.portal.db.ExtraProduct) Enterprise(com.itrus.portal.db.Enterprise) MailTemplate(com.itrus.portal.db.MailTemplate) File(java.io.File)

Example 4 with MailTemplate

use of com.itrus.portal.db.MailTemplate in project portal by ixinportal.

the class MailTemplateServiceImpl method getMailTemplatesByProjectId.

public List<MailTemplate> getMailTemplatesByProjectId(Long projectId) {
    List<MailTemplate> mailTemplates = new ArrayList<>();
    MailTemplateExample mailTemplateExample = new MailTemplateExample();
    MailTemplateExample.Criteria criteria = mailTemplateExample.or();
    // 如果projectid =0 则表示模版通用所有的项目
    List<Long> list = new ArrayList<>();
    list.add(0L);
    if (null != projectId) {
        list.add(projectId);
    }
    criteria.andProjectNameIn(list);
    mailTemplates = sqlsession.selectList("com.itrus.portal.db.MailTemplateMapper.selectByExample", mailTemplateExample);
    return mailTemplates;
}
Also used : MailTemplate(com.itrus.portal.db.MailTemplate) ArrayList(java.util.ArrayList) MailTemplateExample(com.itrus.portal.db.MailTemplateExample)

Example 5 with MailTemplate

use of com.itrus.portal.db.MailTemplate in project portal by ixinportal.

the class MailTemplateController method delete.

// 删除消息模版
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE, produces = "text/html")
public String delete(@PathVariable("id") Long id, HttpServletRequest request, Model uiModel) {
    MailTemplate mailtemplate = sqlSession.selectOne("com.itrus.portal.db.MailTemplateMapper.selectByPrimaryKey", id);
    if (mailtemplate == null) {
        uiModel.addAttribute("message", "未找到要删除消息");
    } else {
        String adminProject = getRoleProjects();
        if (adminProject != null && adminProject.equals(mailtemplate.getProjectName())) {
            return "status403";
        }
        try {
            sqlSession.delete("com.itrus.portal.db.MailTemplateMapper.deleteByPrimaryKey", id);
            String oper = "删除邮件模板";
            String info = "邮件内容: " + mailtemplate.getContent();
            LogUtil.adminlog(sqlSession, oper, info);
        } catch (Exception e) {
            uiModel.addAttribute("message", "要删除邮件模板存在关联,无法删除");
        }
    }
    return "redirect:/mailtemplate";
}
Also used : MailTemplate(com.itrus.portal.db.MailTemplate) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

MailTemplate (com.itrus.portal.db.MailTemplate)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 MailTemplateExample (com.itrus.portal.db.MailTemplateExample)4 Project (com.itrus.portal.db.Project)2 ArrayList (java.util.ArrayList)2 Bwdjrecord (com.itrus.portal.db.Bwdjrecord)1 Enterprise (com.itrus.portal.db.Enterprise)1 ExtraProduct (com.itrus.portal.db.ExtraProduct)1 UserInfo (com.itrus.portal.db.UserInfo)1 File (java.io.File)1 HashMap (java.util.HashMap)1