Search in sources :

Example 1 with ISysExprJobLogService

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

the class ExpressionJobExecuteCallable method call.

@Override
public ExpressionJobObj call() throws Exception {
    Date beginDatetime = new Date();
    String faultMsg = "";
    String runStatus = "";
    String logStatus = "";
    @SuppressWarnings("unchecked") ISysExprJobService<SysExprJobVO, TbSysExprJob, String> sysExprJobService = (ISysExprJobService<SysExprJobVO, TbSysExprJob, String>) AppContext.getBean("core.service.SysExprJobService");
    @SuppressWarnings("unchecked") ISysExprJobLogService<SysExprJobLogVO, TbSysExprJobLog, String> sysExprJobLogService = (ISysExprJobLogService<SysExprJobLogVO, TbSysExprJobLog, String>) AppContext.getBean("core.service.SysExprJobLogService");
    try {
        logger.info("[Expression-Job] (Start) ID: " + this.jobObj.getSysExprJob().getId() + " , NAME: " + this.jobObj.getSysExprJob().getName());
        if (StringUtils.isBlank(jobObj.getSysExpression().getContent())) {
            faultMsg = "No expression content!";
            runStatus = ExpressionJobConstants.RUNSTATUS_FAULT;
            logStatus = ExpressionJobConstants.LOGSTATUS_NO_EXECUTE;
            return this.jobObj;
        }
        if (YesNo.YES.equals(this.jobObj.getSysExprJob().getCheckFault()) && ExpressionJobConstants.RUNSTATUS_FAULT.equals(this.jobObj.getSysExprJob().getRunStatus())) {
            faultMsg = "Before proccess fault, cannot execute expression job!";
            runStatus = ExpressionJobConstants.RUNSTATUS_FAULT;
            logStatus = ExpressionJobConstants.LOGSTATUS_NO_EXECUTE;
            return this.jobObj;
        }
        this.jobObj.getSysExprJob().setRunStatus(ExpressionJobConstants.RUNSTATUS_PROCESS_NOW);
        sysExprJobService.updateObject(this.jobObj.getSysExprJob());
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("jobObj", this.jobObj);
        ScriptExpressionUtils.execute(jobObj.getSysExpression().getType(), jobObj.getSysExpression().getContent(), paramMap, paramMap);
        runStatus = ExpressionJobConstants.RUNSTATUS_SUCCESS;
        logStatus = ExpressionJobConstants.LOGSTATUS_SUCCESS;
    } catch (ServiceException se) {
        faultMsg = se.getMessage().toString();
        runStatus = ExpressionJobConstants.RUNSTATUS_FAULT;
        logStatus = ExpressionJobConstants.LOGSTATUS_FAULT;
        logger.error(se.getMessage().toString());
    } catch (Exception e) {
        faultMsg = e.getMessage().toString();
        if (e.getMessage() == null) {
            faultMsg = e.toString();
        } else {
            faultMsg = e.getMessage().toString();
        }
        runStatus = ExpressionJobConstants.RUNSTATUS_FAULT;
        logStatus = ExpressionJobConstants.LOGSTATUS_FAULT;
        logger.error(faultMsg);
    } finally {
        if (faultMsg.length() > 2000) {
            faultMsg = faultMsg.substring(0, 2000);
        }
        jobObj.getSysExprJob().setRunStatus(runStatus);
        jobObj.getSysExprJobLog().setFaultMsg(faultMsg);
        jobObj.getSysExprJobLog().setLogStatus(logStatus);
        jobObj.getSysExprJobLog().setId(jobObj.getSysExprJob().getId());
        jobObj.getSysExprJobLog().setBeginDatetime(beginDatetime);
        jobObj.getSysExprJobLog().setEndDatetime(new Date());
        sysExprJobService.updateObject(this.jobObj.getSysExprJob());
        DefaultResult<SysExprJobLogVO> jobLogResult = sysExprJobLogService.saveObject(jobObj.getSysExprJobLog());
        if (jobLogResult.getValue() != null) {
            jobObj.setSysExprJobLog(jobLogResult.getValue());
        }
        this.sendMail();
        logger.info("[Expression-Job] (End) ID: " + this.jobObj.getSysExprJob().getId() + " , NAME: " + this.jobObj.getSysExprJob().getName());
    }
    return this.jobObj;
}
Also used : ISysExprJobLogService(com.netsteadfast.greenstep.service.ISysExprJobLogService) SysExprJobVO(com.netsteadfast.greenstep.vo.SysExprJobVO) HashMap(java.util.HashMap) Date(java.util.Date) SysExprJobLogVO(com.netsteadfast.greenstep.vo.SysExprJobLogVO) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) TbSysExprJob(com.netsteadfast.greenstep.po.hbm.TbSysExprJob) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) TbSysExprJobLog(com.netsteadfast.greenstep.po.hbm.TbSysExprJobLog) ISysExprJobService(com.netsteadfast.greenstep.service.ISysExprJobService)

Aggregations

ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)1 TbSysExprJob (com.netsteadfast.greenstep.po.hbm.TbSysExprJob)1 TbSysExprJobLog (com.netsteadfast.greenstep.po.hbm.TbSysExprJobLog)1 ISysExprJobLogService (com.netsteadfast.greenstep.service.ISysExprJobLogService)1 ISysExprJobService (com.netsteadfast.greenstep.service.ISysExprJobService)1 SysExprJobLogVO (com.netsteadfast.greenstep.vo.SysExprJobLogVO)1 SysExprJobVO (com.netsteadfast.greenstep.vo.SysExprJobVO)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1