Search in sources :

Example 1 with TemplateResultObj

use of com.netsteadfast.greenstep.model.TemplateResultObj in project bamboobsc by billchen198318.

the class SystemMessagePublishServiceImpl method process.

private String process(String sessionId, String refreshUUID, List<TbSysMsgNotice> sysMsgNotices) throws ServiceException, Exception {
    if (sysMsgNotices == null || sysMsgNotices.size() < 1) {
        return "";
    }
    Date sysDate = new Date();
    StringBuilder sb = new StringBuilder();
    for (TbSysMsgNotice msgNotice : sysMsgNotices) {
        String key = sessionId + ":uuid_" + refreshUUID + ":" + msgNotice.getNoticeId();
        if (messagePublishMap.get(key) != null) {
            continue;
        }
        if (!this.isPublishDateTimeRange(msgNotice, sysDate)) {
            // 日期區間不合
            continue;
        }
        //msgNotice.setTitle( TemplateUtils.processTemplateHtmlContent(msgNotice.getTitle()) );
        //msgNotice.setMessage( TemplateUtils.processTemplateHtmlContent(msgNotice.getMessage()) );
        TbSysMsgNotice dataObj = new TbSysMsgNotice();
        dataObj.setTitle(TemplateUtils.escapeHtml4TemplateHtmlContent(msgNotice.getTitle()));
        dataObj.setMessage(TemplateUtils.escapeHtml4TemplateHtmlContent(msgNotice.getMessage()));
        TemplateResultObj result = TemplateUtils.getResult(TemplateCode.TPLMSG0002, dataObj);
        dataObj = null;
        sb.append(result.getContent());
        messagePublishMap.put(key, YesNo.YES);
    }
    return sb.toString();
}
Also used : TbSysMsgNotice(com.netsteadfast.greenstep.po.hbm.TbSysMsgNotice) TemplateResultObj(com.netsteadfast.greenstep.model.TemplateResultObj) Date(java.util.Date)

Example 2 with TemplateResultObj

use of com.netsteadfast.greenstep.model.TemplateResultObj in project bamboobsc by billchen198318.

the class SystemCalendarNoteLogicServiceImpl method createMailHelper.

private void createMailHelper(SysCalendarNoteVO note) {
    if (null == note || super.isBlank(note.getOid())) {
        return;
    }
    if (!YesNo.YES.equals(note.getAlert())) {
        return;
    }
    if (super.isBlank(note.getContact())) {
        return;
    }
    String[] receiveMail = note.getContact().trim().split(Constants.ID_DELIMITER);
    String mailId = SimpleUtils.getStrYMD("");
    for (String toMail : receiveMail) {
        try {
            TemplateResultObj result = TemplateUtils.getResult(TemplateCode.TPLMSG0001, note);
            String content = result.getContent();
            if (StringUtils.isBlank(content)) {
                content = note.getNote();
            }
            SysMailHelperVO mailHelper = new SysMailHelperVO();
            mailHelper.setMailId(this.sysMailHelperService.findForMaxMailIdComplete(mailId));
            mailHelper.setMailFrom(MailClientUtils.getDefaultFrom());
            mailHelper.setMailTo(toMail);
            mailHelper.setSubject(note.getTitle());
            mailHelper.setText(content.getBytes("utf8"));
            mailHelper.setRetainFlag(YesNo.NO);
            mailHelper.setSuccessFlag(YesNo.NO);
            this.sysMailHelperService.saveObject(mailHelper);
        } catch (ServiceException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) TemplateResultObj(com.netsteadfast.greenstep.model.TemplateResultObj) SysMailHelperVO(com.netsteadfast.greenstep.vo.SysMailHelperVO) IOException(java.io.IOException) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException)

Example 3 with TemplateResultObj

use of com.netsteadfast.greenstep.model.TemplateResultObj in project bamboobsc by billchen198318.

the class SystemCalendarNoteHistoryAction method generateContent.

private void generateContent() throws ControllerException, AuthorityException, ServiceException, Exception {
    String date = this.getFields().get("date");
    if (!SimpleUtils.isDate(date)) {
        return;
    }
    date = date.replaceAll("/", "").replaceAll("-", "");
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("account", super.getAccountId());
    params.put("date", date);
    Map<String, String> orderParams = new LinkedHashMap<String, String>();
    orderParams.put("time", "ASC");
    List<TbSysCalendarNote> searchList = sysCalendarNoteService.findListByParams2(params, null, null, orderParams);
    if (searchList == null || searchList.size() < 1) {
        this.message = "";
        return;
    }
    StringBuilder sb = new StringBuilder();
    for (TbSysCalendarNote calendarNote : searchList) {
        calendarNote.setTitle(TemplateUtils.escapeHtml4TemplateHtmlContent(calendarNote.getTitle()));
        calendarNote.setNote(TemplateUtils.escapeHtml4TemplateHtmlContent(calendarNote.getNote()));
        TemplateResultObj result = TemplateUtils.getResult(TemplateCode.TPLMSG0001, calendarNote);
        sb.append(result.getContent());
    }
    this.message = sb.toString();
}
Also used : TbSysCalendarNote(com.netsteadfast.greenstep.po.hbm.TbSysCalendarNote) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TemplateResultObj(com.netsteadfast.greenstep.model.TemplateResultObj) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with TemplateResultObj

use of com.netsteadfast.greenstep.model.TemplateResultObj in project bamboobsc by billchen198318.

the class TemplateUtils method getResult.

/**
	 * 產生 template 結果
	 * Map 值放入 title 與 message
	 * 
	 * @param templateId	樣板id
	 * @param dataObj		資料來源
	 * @return
	 * @throws ServiceException
	 * @throws Exception
	 */
public static TemplateResultObj getResult(String templateId, Object dataObj) throws ServiceException, Exception {
    if (StringUtils.isBlank(templateId) || null == dataObj) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK));
    }
    TemplateResultObj resultObj = new TemplateResultObj();
    SysTemplateVO sysTemplate = loadSysTemplate(templateId);
    List<TbSysTemplateParam> sysTemplateParamList = loadSysTemplateParam(templateId);
    Map<String, Object> titleParams = getTemplateParamMap(IS_TITLE, sysTemplateParamList, dataObj);
    Map<String, Object> msgParams = getTemplateParamMap(IS_MESSAGE, sysTemplateParamList, dataObj);
    resultObj.setTitle(processTemplate(sysTemplate.getTitle(), titleParams));
    resultObj.setContent(processTemplate(sysTemplate.getMessage(), msgParams));
    return resultObj;
}
Also used : ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) SysTemplateVO(com.netsteadfast.greenstep.vo.SysTemplateVO) TbSysTemplateParam(com.netsteadfast.greenstep.po.hbm.TbSysTemplateParam) TemplateResultObj(com.netsteadfast.greenstep.model.TemplateResultObj)

Example 5 with TemplateResultObj

use of com.netsteadfast.greenstep.model.TemplateResultObj in project bamboobsc by billchen198318.

the class HistoryItemScoreNoticeHandler method createContent.

private void createContent(List<BbMonitorItemScore> monitorItemScoresSrc, StringBuilder out) throws ServiceException, Exception {
    // create mail content
    List<MonitorItemScoreVO> monitorItemScores = HistoryItemScoreReportContentQueryUtils.fill2ValueObjectList(monitorItemScoresSrc);
    BscScoreColorUtils.loadScoreColors();
    for (MonitorItemScoreVO itemScore : monitorItemScores) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("title", itemScore.getName());
        paramMap.put("date", SimpleUtils.getStrYMD(itemScore.getDateVal(), "/"));
        paramMap.put("frequency", BscMeasureDataFrequency.getFrequencyMap(false).get(frequency));
        paramMap.put("score", itemScore.getScore());
        paramMap.put("organization", itemScore.getOrganizationName());
        paramMap.put("employee", itemScore.getEmployeeName());
        paramMap.put("bgColor", BscScoreColorUtils.getBackgroundColor(Float.parseFloat(itemScore.getScore())));
        paramMap.put("fnColor", BscScoreColorUtils.getFontColor(Float.parseFloat(itemScore.getScore())));
        TemplateResultObj result = TemplateUtils.getResult(TemplateCode.TPLMSG0003, paramMap);
        if (result.getContent() != null) {
            out.append(result.getContent());
        }
    }
}
Also used : HashMap(java.util.HashMap) TemplateResultObj(com.netsteadfast.greenstep.model.TemplateResultObj) MonitorItemScoreVO(com.netsteadfast.greenstep.vo.MonitorItemScoreVO)

Aggregations

TemplateResultObj (com.netsteadfast.greenstep.model.TemplateResultObj)5 ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)2 HashMap (java.util.HashMap)2 TbSysCalendarNote (com.netsteadfast.greenstep.po.hbm.TbSysCalendarNote)1 TbSysMsgNotice (com.netsteadfast.greenstep.po.hbm.TbSysMsgNotice)1 TbSysTemplateParam (com.netsteadfast.greenstep.po.hbm.TbSysTemplateParam)1 MonitorItemScoreVO (com.netsteadfast.greenstep.vo.MonitorItemScoreVO)1 SysMailHelperVO (com.netsteadfast.greenstep.vo.SysMailHelperVO)1 SysTemplateVO (com.netsteadfast.greenstep.vo.SysTemplateVO)1 IOException (java.io.IOException)1 Date (java.util.Date)1 LinkedHashMap (java.util.LinkedHashMap)1