示例#1
0
 private void saveInvitationCodes(List<InvitationCodeDTO> dtoList) {
   if (CollectionUtil.isEmpty(dtoList)) return;
   NotificationWriter writer = notificationDaoManager.getWriter();
   Object status = writer.begin();
   InvitationCode code;
   try {
     for (InvitationCodeDTO dto : dtoList) {
       code = new InvitationCode();
       writer.save(code.fromDto(dto));
     }
     writer.commit(status);
   } finally {
     writer.rollback(status);
   }
 }
示例#2
0
 @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();
     }
   }
 }
示例#3
0
 @Override
 public void updateInvitationCodeToUsed(String code) {
   NotificationWriter writer = notificationDaoManager.getWriter();
   InvitationCodeDTO dto = writer.findInvitationCodeByCode(code);
   if (dto == null) {
     LOG.warn("can't find InvitationCode by code:{}", code);
     return;
   }
   Object status = writer.begin();
   try {
     InvitationCode invitationCode = writer.getById(InvitationCode.class, dto.getId());
     invitationCode.setStatus(InvitationCodeStatus.BE_USED);
     invitationCode.setUsageTime(System.currentTimeMillis());
     writer.save(invitationCode);
     writer.commit(status);
   } finally {
     writer.rollback(status);
   }
 }
示例#4
0
 public InvitationCodeDTO findInvitationCodeByCode(String code) {
   NotificationWriter writer = notificationDaoManager.getWriter();
   return writer.findInvitationCodeByCode(code.toLowerCase());
 }
示例#5
0
 private boolean duplicatedInvitationCodeDuplicate(List<String> codes) {
   NotificationWriter writer = notificationDaoManager.getWriter();
   return writer.countEffectiveInvitationCodeByCode(codes) > 0l;
 }