Search in sources :

Example 1 with MailTemplateExample

use of com.itrus.portal.db.MailTemplateExample 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 2 with MailTemplateExample

use of com.itrus.portal.db.MailTemplateExample 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 3 with MailTemplateExample

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

the class MailTemplateController method add.

// 处理添加邮件模版
@RequestMapping(method = RequestMethod.POST, produces = "text/html")
public String add(MailTemplate mailTemplate, @RequestParam(value = "retpath", required = false) String retpath, Model uiModel) {
    if (null == mailTemplate.getProjectName() || StringUtils.isBlank(mailTemplate.getType()) || StringUtils.isBlank(mailTemplate.getName()) || StringUtils.isBlank(mailTemplate.getReceiver()) || StringUtils.isBlank(mailTemplate.getContent())) {
        uiModel.addAttribute("projectMap", getProjectMapOfAdmin());
        uiModel.addAttribute("message", "请提交完整的参数");
        return "mailtemplate/create";
    }
    String adminProject = getRoleProjects();
    if (adminProject != null && adminProject.equals(mailTemplate.getProjectName())) {
        return "status403";
    }
    // 一个项目下只能创建一个模版类型的消息模版
    MailTemplateExample mte = new MailTemplateExample();
    MailTemplateExample.Criteria mtCriteria = mte.or();
    mtCriteria.andProjectNameEqualTo(mailTemplate.getProjectName());
    mtCriteria.andTypeEqualTo(mailTemplate.getType());
    Integer count = sqlSession.selectOne("com.itrus.portal.db.MailTemplateMapper.countByExample", mte);
    if (count != 0) {
        uiModel.addAttribute("projectMap", getProjectMapOfAdmin());
        uiModel.addAttribute("message", "该项目下已经存在同样类型的模版消息");
        return "mailTemplate/create";
    }
    mailTemplate.setCreateTime(new Date());
    sqlSession.insert("com.itrus.portal.db.MailTemplateMapper.insert", mailTemplate);
    return "redirect:/mailtemplate/" + mailTemplate.getId();
}
Also used : MailTemplateExample(com.itrus.portal.db.MailTemplateExample) Date(java.util.Date) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with MailTemplateExample

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

the class MailTemplateController method update.

// 处理修改消息模版
@RequestMapping(method = RequestMethod.PUT, produces = "text/html")
public String update(@Valid MailTemplate mailTemplate, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
    if (bindingResult.hasErrors()) {
        uiModel.addAttribute("projectmap", getProjectMapOfAdmin());
        uiModel.addAttribute("mailTemplate", mailTemplate);
        return "mailtemplate/update";
    }
    MailTemplate mailTemplate0 = sqlSession.selectOne("com.itrus.portal.db.MailTemplateMapper.selectByPrimaryKey", mailTemplate.getId());
    mailTemplate.setCreateTime(mailTemplate0.getCreateTime());
    // 一个项目下只能创建一个模版类型的消息模版
    MailTemplateExample mte = new MailTemplateExample();
    MailTemplateExample.Criteria mtCriteria = mte.or();
    mtCriteria.andProjectNameEqualTo(mailTemplate.getProjectName());
    mtCriteria.andTypeEqualTo(mailTemplate.getType());
    Integer count = sqlSession.selectOne("com.itrus.portal.db.MailTemplateMapper.countByExample", mte);
    if ((mailTemplate0.getProjectName() == mailTemplate.getProjectName()) && count >= 2) {
        uiModel.addAttribute("projectMap", getProjectMapOfAdmin());
        uiModel.addAttribute("mailTemplate", mailTemplate);
        uiModel.addAttribute("message", "该项目下已经存在同样类型的模版消息");
        return "mailtemplate/update";
    }
    if ((mailTemplate0.getProjectName() != mailTemplate.getProjectName()) && count != 0) {
        uiModel.addAttribute("projectMap", getProjectMapOfAdmin());
        uiModel.addAttribute("mailTemplate", mailTemplate);
        uiModel.addAttribute("message", "该项目下已经存在同样类型的模版消息");
        return "mailtemplate/update";
    }
    // String adminProject = getRoleProjects();
    // if (adminProject != null
    // && (!adminProject.equals(msgTemplate0.getProject()) || !adminProject
    // .equals(msgTemplate.getProject()))) {
    // return "status403";
    // }
    sqlSession.update("com.itrus.portal.db.MailTemplateMapper.updateByPrimaryKey", mailTemplate);
    String oper = "修改消息模版";
    String info = "消息模板内容: " + mailTemplate.getContent();
    LogUtil.adminlog(sqlSession, oper, info);
    return "redirect:/mailtemplate/" + mailTemplate.getId();
}
Also used : MailTemplate(com.itrus.portal.db.MailTemplate) MailTemplateExample(com.itrus.portal.db.MailTemplateExample) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with MailTemplateExample

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

the class MailTemplateServiceImpl method getMailTemplatesByProjectIdAndType.

public MailTemplate getMailTemplatesByProjectIdAndType(Long projectId, String type) {
    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);
    criteria.andTypeEqualTo(type);
    mailTemplates = sqlsession.selectList("com.itrus.portal.db.MailTemplateMapper.selectByExample", mailTemplateExample);
    if (null != mailTemplates && !mailTemplates.isEmpty()) {
        return mailTemplates.get(0);
    } else {
        return null;
    }
}
Also used : MailTemplate(com.itrus.portal.db.MailTemplate) ArrayList(java.util.ArrayList) MailTemplateExample(com.itrus.portal.db.MailTemplateExample)

Aggregations

MailTemplateExample (com.itrus.portal.db.MailTemplateExample)5 MailTemplate (com.itrus.portal.db.MailTemplate)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)1