Exemple #1
0
 /**
  * 自动修改SkU状态(上架/下架)
  *
  * @param invId 库存id
  */
 public void updateState(Long invId) {
   Inventory inventory = inventoryService.getInventory(invId);
   String state = inventory.getState();
   Date now = new Date();
   Long nowTimes = now.getTime();
   Long endTimes = 0l;
   try {
     endTimes = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(inventory.getEndAt()).getTime();
   } catch (ParseException e) {
     //            e.printStackTrace();
     Logger.error(Throwables.getStackTraceAsString(e));
   }
   if (!"D".equals(state)) {
     if ("P".equals(state)) {
       inventory.setState("Y");
       // 启动下架schedule
       Logger.info("sku " + inventory.getId() + "auto off shelves start...");
       try {
         // 等待上架schedule删除后创建下架schedule
         Thread.sleep(5000);
       } catch (InterruptedException e) {
         //                    e.printStackTrace();
         Logger.error(Throwables.getStackTraceAsString(e));
       }
       newScheduler.scheduleOnce(
           Duration.create(endTimes - nowTimes, TimeUnit.MILLISECONDS),
           inventoryAutoShelvesActor,
           inventory.getId());
     }
     if ("Y".equals(state)) {
       inventory.setState("D");
     }
     inventoryService.updateInventory(inventory);
     // 修改多样化价格状态
     VaryPrice varyPrice = new VaryPrice();
     varyPrice.setInvId(invId);
     List<VaryPrice> varyPriceList = varyPriceService.getVaryPriceBy(varyPrice);
     for (VaryPrice vp : varyPriceList) {
       vp.setStatus(inventory.getState());
       varyPriceService.updateVaryPrice(vp);
     }
     // sku自动下架
     if ("D".equals(inventory.getState())) {
       // 修改pin_sku的状态,正常状态的拼购商品置为下架
       List<PinSku> pinSkuList = pingouService.getPinSkuByInvId(inventory.getId());
       pinSkuList
           .stream()
           .filter(pinSku -> "Y".equals(pinSku.getStatus()))
           .forEach(
               pinSku -> {
                 pinSku.setStatus("D");
                 pinSku.setEndAt(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
                 pingouService.updatePinSku(pinSku);
               });
       // 修改subject_price的状态,正常状态的自定义价格商品置为下架
       List<SubjectPrice> subjectPriceList =
           subjectPriceService.getSbjPriceByInvId(inventory.getId());
       subjectPriceList
           .stream()
           .filter(subjectPrice -> "Y".equals(subjectPrice.getState()))
           .forEach(
               subjectPrice -> {
                 subjectPrice.setState("D");
                 subjectPriceService.sbjPriceUpd(subjectPrice);
               });
     }
   }
 }
 @Override
 public String convert(Thread arg0) {
   return String.valueOf(arg0.getId());
 }