@Override
  protected void executeJob(JobExecutionContext jobExecutionContext) throws JobExecutionException {
    if (isLock()) {
      return;
    }
    try {

      INotificationService notificationService =
          ServiceManager.getService(INotificationService.class);
      List<PromotionMsgJobDTO> jobDTOs = notificationService.getCurrentPromotionMsgJobDTO();
      if (CollectionUtil.isEmpty(jobDTOs)) {
        return;
      }
      IMessageService messageService = ServiceManager.getService(IMessageService.class);
      List<Long> jobIdList = new ArrayList<Long>();
      Result result = new Result();
      for (PromotionMsgJobDTO jobDTO : jobDTOs) {
        messageService.sendPromotionMsg(result, jobDTO.getMessageDTO());
        jobIdList.add(jobDTO.getId());
      }
      notificationService.updateFinishedPromotionMsgJob(jobIdList);
    } catch (Exception e) {
      LOG.error(e.getMessage(), e);
    } finally {
      lock = false;
    }
  }
 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);
   }
 }
  @Override
  public void saveProductCategoryRelation(
      Long shopId, Long productCategoryId, Long productLocalInfoId) {
    ProductWriter productWriter = productDaoManager.getWriter();
    Object status = productWriter.begin();
    try {
      ProductCategoryRelation productCategoryRelation =
          CollectionUtil.getFirst(
              productWriter.getProductCategoryRelations(shopId, productLocalInfoId));
      if (productCategoryRelation == null) {
        productCategoryRelation = new ProductCategoryRelation();
        productCategoryRelation.setShopId(shopId);
        productCategoryRelation.setProductLocalInfoId(productLocalInfoId);
      }

      productCategoryRelation.setProductCategoryId(productCategoryId);
      productWriter.saveOrUpdate(productCategoryRelation);
      productWriter.commit(status);
    } finally {
      productWriter.rollback(status);
    }
  }
 @Override
 public String createInvitationCode(
     InvitationCodeType invitationCodeType,
     OperatorType inviterType,
     Long inviterId,
     OperatorType inviteeType,
     Long inviteeId,
     Long expirationTime)
     throws Exception {
   if (inviteeId == null) throw new Exception("parameters can't be null:[inviteeId:" + inviteeId);
   List<Long> inviteeIds = new ArrayList<Long>();
   inviteeIds.add(inviteeId);
   List<InvitationCodeDTO> invitationCodeDTOList =
       createInvitationCodes(
           invitationCodeType,
           inviterType,
           inviterId,
           inviteeType,
           inviteeIds,
           expirationTime,
           true);
   if (CollectionUtil.isEmpty(invitationCodeDTOList)) return null;
   return invitationCodeDTOList.get(0).getCode();
 }
Exemple #5
0
 @Override
 public String buildMenu(long shopVersionId, long shopId, long userId, long userGroupId)
     throws Exception {
   Set<Long> resourceIds = new HashSet<Long>();
   List<Resource> resourceList =
       ServiceManager.getService(IResourceService.class)
           .getAllResourcesByUserGroupId(shopVersionId, userGroupId);
   for (Resource r : resourceList) {
     if (ResourceType.menu == r.getType()) {
       resourceIds.add(r.getId());
     }
   }
   Map<String, MenuRootResponse> menuRootResponseMap = new HashMap<String, MenuRootResponse>();
   List<MenuDTO> parents = new ArrayList<MenuDTO>();
   if (CollectionUtil.isNotEmpty(resourceIds)) {
     List<MenuDTO> menuDTOList =
         ServiceManager.getService(IResourceService.class).getMenuByResourceIds(resourceIds);
     //      List<UserSwitch> userSwitches =
     // ServiceManager.getService(IUserService.class).getUserSwitch(shopId);
     boolean isRepairPickingSwitchOn =
         ServiceManager.getService(IUserService.class).isRepairPickingSwitchOn(shopId);
     Iterator iterator = menuDTOList.iterator();
     MenuDTO menuDTO;
     while (iterator.hasNext()) {
       menuDTO = (MenuDTO) iterator.next();
       // 特殊过滤
       if (MenuType.TXN_INVENTORY_MANAGE_REPAIR_PICKING.name().equals(menuDTO.getMenuName())
           && !isRepairPickingSwitchOn) {
         iterator.remove();
       }
       // 页面配置开关
       if (MenuType.WEB_SYSTEM_SETTINGS_CUSTOM_CONFIG_PAGE_CONFIG
               .name()
               .equals(menuDTO.getMenuName())
           && !ConfigUtils.isCustomizerConfigOpen()) {
         iterator.remove();
       }
       if (menuDTO.getParentId() == null) {
         parents.add(menuDTO);
         iterator.remove();
       }
     }
     List<MenuItemResponse> menuItemResponseList;
     MenuItemResponse response;
     MenuRootResponse rootResponse;
     for (MenuDTO root : parents) {
       root.buildTree(root, menuDTOList);
       // 根据logic 做具体处理
       //        sort(shopVersionId, root);
       root.reBuildTreeForSort();
       menuItemResponseList = new ArrayList<MenuItemResponse>();
       for (MenuDTO menu : root.getChildren()) {
         //          if (menu.getChildren().size() > 1) {
         //            String href = "";
         //            //特殊root menu 需要连接
         //            if
         // (MenuType.AUTO_ACCESSORY_ONLINE_ORDER_CENTER.name().equals(menu.getMenuName())
         //                || MenuType.VEHICLE_CONSTRUCTION.name().equals(menu.getMenuName())) {
         //              href = root.getHref();
         //            }
         response = new MenuItemResponse(menu.getLabel(), menu.getHref(), menu.getMenuName());
         for (MenuDTO m : menu.getChildren()) {
           response
               .getItem()
               .add(new MenuItemResponse(m.getLabel(), m.getHref(), m.getMenuName()));
         }
         //          } else {
         //            response = new MenuItemResponse(menu.getLabel(), menu.getHref(),
         // menu.getMenuName());
         //          }
         menuItemResponseList.add(response);
       }
       rootResponse = new MenuRootResponse(root.getLabel(), root.getHref(), root.getMenuName());
       rootResponse.setItem(menuItemResponseList);
       menuRootResponseMap.put(root.getMenuName(), rootResponse);
     }
   }
   return JsonUtil.mapToJson(menuRootResponseMap);
 }
 @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;
 }