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;
}
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;
}
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());
}
}
}
}
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);
}
}
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();
}
}
}
Aggregations