Search in sources :

Example 1 with ISysMailHelperService

use of com.netsteadfast.greenstep.service.ISysMailHelperService in project bamboobsc by billchen198318.

the class ExpressionJobExecuteCallable method sendMail.

private void sendMail() {
    try {
        if (ExpressionJobConstants.CONTACT_MODE_NO.equals(this.jobObj.getSysExprJob().getContactMode())) {
            return;
        }
        if (ExpressionJobConstants.CONTACT_MODE_ONLY_FAULT.equals(this.jobObj.getSysExprJob().getContactMode()) && !ExpressionJobConstants.RUNSTATUS_FAULT.equals(this.jobObj.getSysExprJob().getRunStatus())) {
            return;
        }
        if (ExpressionJobConstants.CONTACT_MODE_ONLY_SUCCESS.equals(this.jobObj.getSysExprJob().getContactMode()) && !ExpressionJobConstants.RUNSTATUS_SUCCESS.equals(this.jobObj.getSysExprJob().getRunStatus())) {
            return;
        }
        String contact = StringUtils.defaultString(this.jobObj.getSysExprJob().getContact()).trim();
        if (StringUtils.isBlank(contact)) {
            return;
        }
        String subject = this.jobObj.getSysExprJob().getId() + " - " + this.jobObj.getSysExprJob().getName();
        String content = subject + Constants.HTML_BR;
        content += "Run status: " + this.jobObj.getSysExprJob().getRunStatus() + Constants.HTML_BR;
        content += "Start: " + this.jobObj.getSysExprJobLog().getBeginDatetime().toString() + Constants.HTML_BR;
        content += "End: " + this.jobObj.getSysExprJobLog().getEndDatetime().toString() + Constants.HTML_BR;
        if (ExpressionJobConstants.RUNSTATUS_FAULT.equals(this.jobObj.getSysExprJob().getRunStatus())) {
            content += Constants.HTML_BR;
            content += "Fault: " + Constants.HTML_BR;
            content += this.jobObj.getSysExprJobLog().getFaultMsg();
        }
        @SuppressWarnings("unchecked") ISysMailHelperService<SysMailHelperVO, TbSysMailHelper, String> sysMailHelperService = (ISysMailHelperService<SysMailHelperVO, TbSysMailHelper, String>) AppContext.getBean("core.service.SysMailHelperService");
        String mailId = SimpleUtils.getStrYMD("");
        SysMailHelperVO mailHelper = new SysMailHelperVO();
        mailHelper.setMailId(sysMailHelperService.findForMaxMailIdComplete(mailId));
        mailHelper.setMailFrom(MailClientUtils.getDefaultFrom());
        mailHelper.setMailTo(contact);
        mailHelper.setSubject(subject);
        mailHelper.setText(content.getBytes("utf8"));
        mailHelper.setRetainFlag(YesNo.NO);
        mailHelper.setSuccessFlag(YesNo.NO);
        sysMailHelperService.saveObject(mailHelper);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : TbSysMailHelper(com.netsteadfast.greenstep.po.hbm.TbSysMailHelper) SysMailHelperVO(com.netsteadfast.greenstep.vo.SysMailHelperVO) ISysMailHelperService(com.netsteadfast.greenstep.service.ISysMailHelperService) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException)

Aggregations

ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)1 TbSysMailHelper (com.netsteadfast.greenstep.po.hbm.TbSysMailHelper)1 ISysMailHelperService (com.netsteadfast.greenstep.service.ISysMailHelperService)1 SysMailHelperVO (com.netsteadfast.greenstep.vo.SysMailHelperVO)1