Authored by chenchao

创建服务类

  1 +package com.yohoufo.order.event;
  2 +
  3 +import com.yohoufo.common.alarm.Event;
  4 +import lombok.AllArgsConstructor;
  5 +import lombok.Data;
  6 +import lombok.NoArgsConstructor;
  7 +import lombok.experimental.Builder;
  8 +
  9 +import java.math.BigDecimal;
  10 +
  11 +/**
  12 + * Created by chao.chen on 2018/12/4.
  13 + */
  14 +@Data
  15 +@Builder
  16 +@AllArgsConstructor
  17 +@NoArgsConstructor
  18 +public class LowerPriceFiredEvent extends Event {
  19 + Integer uid;
  20 + BigDecimal salePrice;
  21 + Integer storageId;
  22 +}
  1 +package com.yohoufo.order.service.handler;
  2 +
  3 +import com.google.common.eventbus.Subscribe;
  4 +import com.yohoufo.common.alarm.IEventHandler;
  5 +import com.yohoufo.order.event.LowerPriceFiredEvent;
  6 +import com.yohoufo.order.service.impl.SellerService;
  7 +import com.yohoufo.order.utils.LoggerUtils;
  8 +import org.slf4j.Logger;
  9 +import org.springframework.beans.factory.annotation.Autowired;
  10 +import org.springframework.stereotype.Component;
  11 +
  12 +/**
  13 + * Created by chao.chen on 2018/12/4.
  14 + */
  15 +@Component
  16 +public class LowerPriceFiredHandler implements IEventHandler<LowerPriceFiredEvent> {
  17 +
  18 + private final Logger logger = LoggerUtils.getSellerOrderLogger();
  19 +
  20 + @Autowired
  21 + private SellerService sellerService;
  22 +
  23 + @Override
  24 + @Subscribe
  25 + public void handle(LowerPriceFiredEvent event) {
  26 + logger.info("handle LowerPriceFiredEvent {}", event);
  27 + sellerService.lowerPriceFired(event.getUid(), event.getSalePrice(), event.getStorageId());
  28 + logger.info("finish handle LowerPriceFiredEvent {}", event);
  29 + }
  30 +}
  1 +package com.yohoufo.order.service.impl;
  2 +
  3 +import com.yohoufo.order.utils.LoggerUtils;
  4 +import org.slf4j.Logger;
  5 +import org.springframework.stereotype.Service;
  6 +
  7 +import java.math.BigDecimal;
  8 +
  9 +/**
  10 + * 卖家服务(竞价提醒)
  11 + *
  12 + * 卖家出售(发布或变价) 出更低价格的推送或者短信
  13 + * Created by chao.chen on 2018/12/4.
  14 + */
  15 +@Service
  16 +public class SellerService {
  17 +
  18 + private final Logger logger = LoggerUtils.getSellerOrderLogger();
  19 +
  20 + /**
  21 + * 需要考虑的是发布和变价是个不间断的操作,若高并发必影响调用者处理速度
  22 + * 还好,我已经把这个定义成非核心功能,可以异步实现
  23 + * @param whoReducePrice
  24 + * @param lowerSalePrice
  25 + * @param storageId
  26 + */
  27 + public void lowerPriceFired(Integer whoReducePrice, BigDecimal lowerSalePrice, Integer storageId){
  28 + logger.info("in lowerPriceFired, uid whoReducePrice {} lowerSalePrice {} storageId {}",
  29 + whoReducePrice, lowerSalePrice, storageId);
  30 +
  31 + //TODO finish blow step
  32 + // step 1: 找到所有出售中 & 指定storageId的skup &不是whoReducePrice这个uid & 价格高于lowerSalePrice(seller_order_goods表)集合 --> one sq1
  33 + // step 2:消息或短信 给所有的用户(多么贴心,也许以后可以干掉毒,然后收费^v^)
  34 + // step 2.1 超过多少数量 使用多线程并行处理
  35 + }
  36 +}