Search in sources :

Example 1 with MessageTemplateExample

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

the class MsgTemplateController method update.

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

Example 2 with MessageTemplateExample

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

the class MsgTemplateController method add.

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

Example 3 with MessageTemplateExample

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

the class MsgTemplateController 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;
    // String adminProject = getRoleProjects();
    // if (adminProject != null)
    // project = adminProject;
    MessageTemplateExample mte = new MessageTemplateExample();
    MessageTemplateExample.Criteria mtCriteria = mte.or();
    if (null != project) {
        mtCriteria.andProjectEqualTo(project);
    }
    Integer count = sqlSession.selectOne("com.itrus.portal.db.MessageTemplateMapper.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<MessageTemplate> msgTemplates = sqlSession.selectList("com.itrus.portal.db.MessageTemplateMapper.selectByExample", mte);
    uiModel.addAttribute("msgTemplates", msgTemplates);
    uiModel.addAttribute("projectmap", getProjectMapOfAdmin());
    return "msgtemplate/list";
}
Also used : MessageTemplate(com.itrus.portal.db.MessageTemplate) MessageTemplateExample(com.itrus.portal.db.MessageTemplateExample) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with MessageTemplateExample

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

the class MessageTemplateService method getMsgTemp.

public MessageTemplate getMsgTemp(Long projectId, String smsType) {
    MessageTemplate messageTemplate = null;
    MessageTemplateExample example = new MessageTemplateExample();
    MessageTemplateExample.Criteria criteria = example.or();
    criteria.andProjectEqualTo(projectId);
    criteria.andMessageTypeEqualTo(smsType);
    messageTemplate = sqlSession.selectOne("com.itrus.portal.db.MessageTemplateMapper.selectByExample", example);
    if (null != messageTemplate) {
        return messageTemplate;
    } else {
        MessageTemplateExample example1 = new MessageTemplateExample();
        MessageTemplateExample.Criteria criteria1 = example1.or();
        criteria1.andProjectEqualTo((long) 0);
        criteria1.andMessageTypeEqualTo(smsType);
        messageTemplate = sqlSession.selectOne("com.itrus.portal.db.MessageTemplateMapper.selectByExample", example1);
        return messageTemplate;
    }
}
Also used : MessageTemplate(com.itrus.portal.db.MessageTemplate) MessageTemplateExample(com.itrus.portal.db.MessageTemplateExample)

Aggregations

MessageTemplateExample (com.itrus.portal.db.MessageTemplateExample)4 MessageTemplate (com.itrus.portal.db.MessageTemplate)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 Date (java.util.Date)1