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