f-li.cn
Posted googler
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了f-li.cn相关的知识,希望对你有一定的参考价值。
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();
以上是关于f-li.cn的主要内容,如果未能解决你的问题,请参考以下文章