标签:iat set man service imp cas setter dstat framework
package org.rx.service.command.impl; import lombok.Getter; import lombok.Setter; import org.rx.core.NQuery; import org.rx.core.dto.media.MediaType; import org.rx.core.dto.media.AdvFoundStatus; import org.rx.core.dto.media.FindAdvResult; import org.rx.service.command.Command; import org.rx.service.command.HandleResult; import org.springframework.context.annotation.Scope; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; import javax.annotation.Resource; import static org.rx.core.Contract.require; @Order(22) @Component @Scope("prototype") public class BuyCmd implements Command { private static final String key = "买"; @Resource private FindAdvCmd findAdvCmd; @Getter @Setter private int step = 1; private int errorCount = 0; @Override public boolean peek(String message) { require(message); message = message.trim(); String goodsName = tryGetGoodsName(message); if (goodsName != null) { step = 2; return true; } return NQuery.of("买").contains(message); } @Override public HandleResult<String> handleMessage(String userId, String message) { require(userId, message); switch (step) { case 1: step = 2; return HandleResult.ok("一一一一我 买 商 品一一一一\n" + "亲,请回复如下格式:\n" + "买********\n" + "\n" + "如:买苹果手机", this); case 2: String goodsName = tryGetGoodsName(message); if (goodsName == null) { return HandleResult.ok("一一一一我 买 商 品一一一一\n" + "亲,回复格式错误,请回复如下格式:\n" + "买********\n" + "\n" + "如:买苹果手机", ++errorCount > 2 ? null : this); } for (MediaType mediaType : new MediaType[]{MediaType.Taobao, MediaType.Jd}) { FindAdvResult recommendAdv = findAdvCmd.getRecommendAdv(mediaType, goodsName, userId); if (recommendAdv != null && recommendAdv.getFoundStatus() == AdvFoundStatus.Ok) { return findAdvCmd.handleResult(userId, recommendAdv, null); } } return findAdvCmd.noAdv(); } return HandleResult.fail(); } private String tryGetGoodsName(String message) { if (!message.startsWith(key)) { return null; } return message.substring(1).trim(); } }
标签:iat set man service imp cas setter dstat framework
原文地址:https://www.cnblogs.com/Googler/p/11569631.html