Search in sources :

Example 1 with SysTask

use of com.publiccms.entities.sys.SysTask in project PublicCMS-preview by sanluan.

the class SysTaskAdminController method delete.

/**
 * @param id
 * @param request
 * @param session
 * @param model
 * @return view name
 */
@RequestMapping("delete")
public String delete(Integer id, HttpServletRequest request, HttpSession session, ModelMap model) {
    SysSite site = getSite(request);
    SysTask entity = service.getEntity(id);
    if (null != entity) {
        if (ControllerUtils.verifyNotEquals("siteId", site.getId(), entity.getSiteId(), model)) {
            return TEMPLATE_ERROR;
        }
        service.delete(id);
        scheduledTask.delete(id);
        logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "delete.task", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
    }
    return TEMPLATE_DONE;
}
Also used : LogOperate(com.publiccms.entities.log.LogOperate) SysTask(com.publiccms.entities.sys.SysTask) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with SysTask

use of com.publiccms.entities.sys.SysTask in project PublicCMS-preview by sanluan.

the class SysTaskAdminController method runOnce.

/**
 * @param id
 * @param request
 * @param session
 * @param model
 * @return view name
 */
@RequestMapping("runOnce")
public String runOnce(Integer id, HttpServletRequest request, HttpSession session, ModelMap model) {
    SysSite site = getSite(request);
    SysTask entity = service.getEntity(id);
    if (null != entity) {
        if (ControllerUtils.verifyNotEquals("siteId", site.getId(), entity.getSiteId(), model)) {
            return TEMPLATE_ERROR;
        }
        scheduledTask.runOnce(site, id);
        logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "runOnce.task", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
    }
    return TEMPLATE_DONE;
}
Also used : LogOperate(com.publiccms.entities.log.LogOperate) SysTask(com.publiccms.entities.sys.SysTask) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with SysTask

use of com.publiccms.entities.sys.SysTask in project PublicCMS-preview by sanluan.

the class SysTaskAdminController method recreate.

/**
 * @param id
 * @param request
 * @param session
 * @param model
 * @return view name
 */
@RequestMapping("recreate")
public String recreate(Integer id, HttpServletRequest request, HttpSession session, ModelMap model) {
    SysSite site = getSite(request);
    SysTask entity = service.getEntity(id);
    if (null != entity) {
        if (ControllerUtils.verifyNotEquals("siteId", site.getId(), entity.getSiteId(), model)) {
            return TEMPLATE_ERROR;
        }
        service.updateStatus(id, ScheduledTask.TASK_STATUS_READY);
        scheduledTask.create(site, entity.getId(), entity.getCronExpression());
        logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "update.task", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
    }
    return TEMPLATE_DONE;
}
Also used : LogOperate(com.publiccms.entities.log.LogOperate) SysTask(com.publiccms.entities.sys.SysTask) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with SysTask

use of com.publiccms.entities.sys.SysTask in project PublicCMS-preview by sanluan.

the class ScheduledTask method init.

/**
 * @param startDate
 */
public void init(Date startDate) {
    if (null != scheduler) {
        @SuppressWarnings("unchecked") List<SysTask> sysTaskList = (List<SysTask>) sysTaskService.getPage(null, null, startDate, null, null).getList();
        for (SysTask sysTask : sysTaskList) {
            SysSite site = siteService.getEntity(sysTask.getSiteId());
            if (TASK_STATUS_ERROR == sysTask.getStatus()) {
                sysTaskService.updateStatus(sysTask.getId(), TASK_STATUS_READY);
            }
            create(site, sysTask.getId(), sysTask.getCronExpression());
            if (TASK_STATUS_PAUSE == sysTask.getStatus()) {
                pause(site, sysTask.getId());
            }
        }
    }
}
Also used : SysTask(com.publiccms.entities.sys.SysTask) List(java.util.List) SysSite(com.publiccms.entities.sys.SysSite)

Example 5 with SysTask

use of com.publiccms.entities.sys.SysTask in project PublicCMS-preview by sanluan.

the class SysTaskDirective method execute.

@Override
public void execute(RenderHandler handler) throws IOException, Exception {
    Integer id = handler.getInteger("id");
    SysSite site = getSite(handler);
    if (CommonUtils.notEmpty(id)) {
        SysTask entity = service.getEntity(id);
        if (null != entity && site.getId() == entity.getSiteId()) {
            handler.put("object", entity).render();
        }
    } else {
        Integer[] ids = handler.getIntegerArray("ids");
        if (CommonUtils.notEmpty(ids)) {
            List<SysTask> entityList = service.getEntitys(ids);
            Map<String, SysTask> map = new LinkedHashMap<>();
            for (SysTask entity : entityList) {
                if (site.getId() == entity.getSiteId()) {
                    map.put(String.valueOf(entity.getId()), entity);
                }
            }
            handler.put("map", map).render();
        }
    }
}
Also used : SysTask(com.publiccms.entities.sys.SysTask) SysSite(com.publiccms.entities.sys.SysSite) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

SysSite (com.publiccms.entities.sys.SysSite)9 SysTask (com.publiccms.entities.sys.SysTask)9 LogOperate (com.publiccms.entities.log.LogOperate)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 LogTask (com.publiccms.entities.log.LogTask)1 TemplateException (freemarker.template.TemplateException)1 IOException (java.io.IOException)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1