Search in sources :

Example 1 with CmsLottery

use of com.publiccms.entities.cms.CmsLottery in project PublicCMS-preview by sanluan.

the class CmsLotteryAdminController method save.

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

Example 2 with CmsLottery

use of com.publiccms.entities.cms.CmsLottery in project PublicCMS-preview by sanluan.

the class CmsLotteryAdminController 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);
    CmsLottery entity = service.getEntity(id);
    if (null != entity) {
        if (ControllerUtils.verifyNotEquals("siteId", site.getId(), entity.getSiteId(), model)) {
            return TEMPLATE_ERROR;
        }
        service.delete(id);
        logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "delete.lottery", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
    }
    return TEMPLATE_DONE;
}
Also used : LogOperate(com.publiccms.entities.log.LogOperate) SysSite(com.publiccms.entities.sys.SysSite) CmsLottery(com.publiccms.entities.cms.CmsLottery) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with CmsLottery

use of com.publiccms.entities.cms.CmsLottery in project PublicCMS-preview by sanluan.

the class LotteryDirective method execute.

@Override
public void execute(RenderHandler handler, SysApp app, SysUser user) throws IOException, Exception {
    Long lotteryId = handler.getLong("lotteryId");
    CmsLottery lottery = lotteryService.getEntity(lotteryId);
    SysSite site = getSite(handler);
    handler.put("result", "failure");
    if (null != lottery && site.getId() == lottery.getSiteId() && !lottery.isDisabled()) {
        if (lotteryUserService.getPage(lotteryId, user.getId(), true, null, null, null, null, null).getTotalCount() == 0) {
            if (lottery.getLotteryCount() - lotteryUserService.getPage(lotteryId, user.getId(), null, null, null, null, null, null).getTotalCount() > 0) {
                CmsLotteryUser entity = new CmsLotteryUser(lotteryId, user.getId(), false, false, RequestUtils.getIpAddress(handler.getRequest()), CommonUtils.getDate());
                entity.setUserId(user.getId());
                if (lottery.getFractions() > random.nextInt(lottery.getNumerator()) && lotteryService.updateLastGift(lotteryId) && lottery.getLotteryCount() > lotteryUserService.getPage(lotteryId, null, true, null, null, null, null, null).getTotalCount()) {
                    entity.setWinning(true);
                }
                lotteryUserService.save(entity);
                handler.put("result", "success");
                handler.put("winning", entity.isWinning());
            }
        }
    }
}
Also used : CmsLotteryUser(com.publiccms.entities.cms.CmsLotteryUser) CmsLottery(com.publiccms.entities.cms.CmsLottery) SysSite(com.publiccms.entities.sys.SysSite)

Example 4 with CmsLottery

use of com.publiccms.entities.cms.CmsLottery in project PublicCMS-preview by sanluan.

the class LotteryStatusDirective method execute.

@Override
public void execute(RenderHandler handler, SysApp app, SysUser user) throws IOException, Exception {
    Long lotteryId = handler.getLong("lotteryId");
    CmsLottery lottery = lotteryService.getEntity(lotteryId);
    SysSite site = getSite(handler);
    if (null != lottery && site.getId() == lottery.getSiteId() && !lottery.isDisabled()) {
        if (lotteryUserService.getPage(lotteryId, user.getId(), true, null, null, null, null, null).getTotalCount() == 0) {
            handler.put("winning", false);
            PageHandler page = lotteryUserService.getPage(lotteryId, user.getId(), null, null, null, null, null, null);
            handler.put("lastCount", lottery.getLotteryCount() - page.getTotalCount());
        } else {
            handler.put("winning", true);
        }
    } else {
        handler.put("error", true);
    }
}
Also used : PageHandler(com.publiccms.common.handler.PageHandler) CmsLottery(com.publiccms.entities.cms.CmsLottery) SysSite(com.publiccms.entities.sys.SysSite)

Example 5 with CmsLottery

use of com.publiccms.entities.cms.CmsLottery in project PublicCMS-preview by sanluan.

the class CmsLotteryDirective method execute.

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

Aggregations

CmsLottery (com.publiccms.entities.cms.CmsLottery)5 SysSite (com.publiccms.entities.sys.SysSite)4 LogOperate (com.publiccms.entities.log.LogOperate)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 PageHandler (com.publiccms.common.handler.PageHandler)1 CmsLotteryUser (com.publiccms.entities.cms.CmsLotteryUser)1 LinkedHashMap (java.util.LinkedHashMap)1