Authored by chenchao

创建服务类

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