@Override public void recycleInvitationCode(Integer pageSize) { IConfigService configService = ServiceManager.getService(IConfigService.class); if (pageSize == null) { pageSize = PAGE_SIZE; } long id = 0; List<InvitationCode> codeList; List<InvitationCodeRecycle> recycles = new ArrayList<InvitationCodeRecycle>(); List<InvitationCode> codes = new ArrayList<InvitationCode>(); InvitationCodeRecycle recycle; while (true) { NotificationWriter writer = notificationDaoManager.getWriter(); codeList = writer.getInvitationCode(pageSize, id); // 得到将要reindex的orderId if (CollectionUtils.isEmpty(codeList)) break; Object status = writer.begin(); try { for (InvitationCode code : codeList) { // 过期 无效 if (InvitationCodeStatus.isRecycle( code.getExpirationTime(), configService.getConfig("INVITATION_CODE_OVERDUE_DATE", ShopConstant.BC_SHOP_ID), code.getStatus())) { recycle = new InvitationCodeRecycle(); if (code.getExpirationTime() < System.currentTimeMillis()) { recycle = recycle.fromInvitationCode(code); } recycle.setStatus(InvitationCodeStatus.INVALID_OVERDUE); recycles.add(recycle); codes.add(code); } else if (InvitationCodeStatus.isOverdue( code.getExpirationTime(), configService.getConfig("INVITATION_CODE_EFFECTIVE_DATE", ShopConstant.BC_SHOP_ID))) { // 过期 code.setStatus(InvitationCodeStatus.OVERDUE); writer.update(code); } } id = codeList.get(codeList.size() - 1).getId(); if (CollectionUtils.isNotEmpty(recycles)) { for (int i = 0, max = recycles.size(); i < max; i++) { writer.save(recycles.get(i)); writer.delete(InvitationCode.class, codes.get(i).getId()); } } writer.commit(status); } finally { writer.rollback(status); recycles.clear(); codes.clear(); } } }
/** * 根据前台查询条件 获得标准商品店铺采购统计 * * @param request * @param response * @param productSearchCondition * @return */ @RequestMapping(params = "method=getNormalProductStatByCondition") @ResponseBody public Object getNormalProductStatByCondition( HttpServletRequest request, HttpServletResponse response, ProductSearchCondition productSearchCondition) { try { Long shopId = WebUtil.getShopId(request); if (shopId == null) throw new Exception("shopId is null!"); if (productSearchCondition == null || productSearchCondition.getNormalProductStatType() == null) { return null; } List<Long> shopIdList = null; if (StringUtil.isNotEmpty(productSearchCondition.getShopVersion()) || productSearchCondition.getProvinceId() != null || productSearchCondition.getCityId() != null || productSearchCondition.getRegionId() != null) { IConfigService configService = ServiceManager.getService(IConfigService.class); List<Long> shopVersionIds = new ArrayList<Long>(); if ("REPAIR_VERSION".equals(productSearchCondition.getShopVersion())) { shopVersionIds.add(10000010017531654L); shopVersionIds.add(10000010017531655L); shopVersionIds.add(10000010039823882L); } else if ("WHOLESALER_VERSION".equals(productSearchCondition.getShopVersion())) { shopVersionIds.add(10000010017531657L); shopVersionIds.add(10000010037193619L); shopVersionIds.add(10000010037193620L); shopVersionIds.add(10000010017531653L); } shopIdList = configService.getShopByShopVersionAndArea( shopVersionIds.toArray(new Long[shopVersionIds.size()]), productSearchCondition.getProvinceId(), productSearchCondition.getCityId(), productSearchCondition.getRegionId()); if (CollectionUtils.isEmpty(shopIdList)) { return null; } } else { shopIdList = new ArrayList<Long>(); shopIdList.add(StatConstant.EMPTY_SHOP_ID); } productSearchCondition.setShopId(shopId); IProductService productService = ServiceManager.getService(IProductService.class); INormalProductStatService normalProductStatService = ServiceManager.getService(INormalProductStatService.class); Map<Long, NormalProductDTO> normalProductDTOMap = productService.getSimpleNormalProductDTO(productSearchCondition); if (MapUtils.isEmpty(normalProductDTOMap)) { return null; } Long[] normalProductIds = normalProductDTOMap.keySet().toArray(new Long[normalProductDTOMap.keySet().size()]); Pager pager = new Pager(); pager.setRowStart(productSearchCondition.getStart()); pager.setPageSize(productSearchCondition.getLimit()); NormalProductStatSearchResult normalProductStatSearchResult = normalProductStatService.getStatDateByCondition( shopIdList.toArray(new Long[shopIdList.size()]), normalProductIds, productSearchCondition.getNormalProductStatType(), pager, normalProductDTOMap); return normalProductStatSearchResult; } catch (Exception e) { LOG.error("normalProductStat.do method=getNormalProductStatByCondition"); LOG.error(productSearchCondition.toString()); LOG.error(e.getMessage(), e); } return null; }
@Override public List<InvitationCodeDTO> createInvitationCodes( InvitationCodeType invitationCodeType, OperatorType inviterType, Long inviterId, OperatorType inviteeType, List<Long> inviteeIds, Long expirationTime, boolean checkingDuplicated) throws Exception { List<InvitationCodeDTO> invitationCodeDTOList = new ArrayList<InvitationCodeDTO>(); if (inviterType == null || inviterId == null || inviteeType == null || CollectionUtil.isEmpty(inviteeIds)) { LOG.warn( "parameters can't be null:[inviterType:" + inviterType + ",inviterId:" + inviterId + ",inviteeType:" + inviteeType + ",inviteeIds:" + inviteeIds); return invitationCodeDTOList; } InvitationCodeDTO dto; String code; List<String> codeList = RandomUtils.randomAlphabeticList(inviteeIds.size()); IConfigService configService = ServiceManager.getService(IConfigService.class); String effectiveDate; if (checkingDuplicated) { long beginning = System.currentTimeMillis(); while (duplicatedInvitationCodeDuplicate(codeList)) { codeList = RandomUtils.randomAlphabeticList(inviteeIds.size()); if (System.currentTimeMillis() - beginning > CREATE_INVITATION_CODE_TIMEOUT) { throw new Exception("create invitationCode timeout exception!"); } } } for (int i = 0; i < codeList.size(); i++) { dto = new InvitationCodeDTO(); dto.setInviterId(inviterId); dto.setInviterType(inviterType); dto.setInviteeId(inviteeIds.get(i)); dto.setInviteeType(inviteeType); dto.setStatus(InvitationCodeStatus.EFFECTIVE); dto.setInviteTime(System.currentTimeMillis()); dto.setType(invitationCodeType); if (expirationTime == null) { effectiveDate = configService.getConfig("INVITATION_CODE_EFFECTIVE_DATE", ShopConstant.BC_SHOP_ID); if (StringUtil.isEmpty(effectiveDate)) { dto.setExpirationTime(System.currentTimeMillis() + DEFAULT_EXPIRATION_TIME); } else { dto.setExpirationTime( System.currentTimeMillis() + Long.valueOf( configService.getConfig( "INVITATION_CODE_EFFECTIVE_DATE", ShopConstant.BC_SHOP_ID))); } } else { dto.setExpirationTime(expirationTime); } code = codeList.get(i); dto.setCode(code); invitationCodeDTOList.add(dto); } saveInvitationCodes(invitationCodeDTOList); return invitationCodeDTOList; }