Search in sources :

Example 1 with CmsContentStatistics

use of com.publiccms.views.pojo.entities.CmsContentStatistics in project PublicCMS-preview by sanluan.

the class ContentController method contentRedirect.

/**
 * 内容链接重定向并计数
 *
 * @param id
 * @param request
 * @param response
 * @return view name
 */
@RequestMapping("redirect")
public String contentRedirect(Long id, HttpServletRequest request, HttpServletResponse response) {
    CmsContentStatistics contentStatistics = statisticsComponent.clicks(id);
    SysSite site = getSite(request);
    if (null != contentStatistics && null != contentStatistics.getEntity() && site.getId() == contentStatistics.getEntity().getSiteId()) {
        return REDIRECT + contentStatistics.getEntity().getUrl();
    } else {
        return REDIRECT + site.getDynamicPath();
    }
}
Also used : CmsContentStatistics(com.publiccms.views.pojo.entities.CmsContentStatistics) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with CmsContentStatistics

use of com.publiccms.views.pojo.entities.CmsContentStatistics in project PublicCMS-preview by sanluan.

the class StatisticsComponent method clicks.

/**
 * @param id
 * @return content statistics
 */
public CmsContentStatistics clicks(Long id) {
    if (CommonUtils.notEmpty(id)) {
        CmsContentStatistics contentStatistics = contentCache.get(id);
        if (null == contentStatistics) {
            contentStatistics = new CmsContentStatistics(id, 1, 0, 0, contentService.getEntity(id));
        } else {
            contentStatistics.setClicks(contentStatistics.getClicks() + 1);
        }
        List<CmsContentStatistics> list = contentCache.put(id, contentStatistics);
        if (CommonUtils.notEmpty(list)) {
            contentService.updateStatistics(list);
        }
        return contentStatistics;
    } else {
        return null;
    }
}
Also used : CmsContentStatistics(com.publiccms.views.pojo.entities.CmsContentStatistics)

Example 3 with CmsContentStatistics

use of com.publiccms.views.pojo.entities.CmsContentStatistics in project PublicCMS-preview by sanluan.

the class CmsContentService method updateStatistics.

/**
 * @param entitys
 */
public void updateStatistics(Collection<CmsContentStatistics> entitys) {
    for (CmsContentStatistics entityStatistics : entitys) {
        CmsContent entity = getEntity(entityStatistics.getId());
        if (null != entity) {
            entity.setClicks(entity.getClicks() + entityStatistics.getClicks());
            entity.setComments(entity.getComments() + entityStatistics.getComments());
            entity.setScores(entity.getScores() + entityStatistics.getScores());
        }
    }
}
Also used : CmsContent(com.publiccms.entities.cms.CmsContent) CmsContentStatistics(com.publiccms.views.pojo.entities.CmsContentStatistics)

Example 4 with CmsContentStatistics

use of com.publiccms.views.pojo.entities.CmsContentStatistics in project PublicCMS-preview by sanluan.

the class ContentClickDirective method execute.

@Override
public void execute(RenderHandler handler, SysApp app, SysUser user) throws IOException, Exception {
    Long id = handler.getLong("id");
    CmsContentStatistics contentStatistics = statisticsComponent.clicks(id);
    if (null != contentStatistics && null != contentStatistics.getEntity()) {
        handler.put("clicks", contentStatistics.getEntity().getClicks() + contentStatistics.getClicks());
    }
}
Also used : CmsContentStatistics(com.publiccms.views.pojo.entities.CmsContentStatistics)

Aggregations

CmsContentStatistics (com.publiccms.views.pojo.entities.CmsContentStatistics)4 CmsContent (com.publiccms.entities.cms.CmsContent)1 SysSite (com.publiccms.entities.sys.SysSite)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1