From bbfa1f563e09191302f07e28f545c7e5843df41e Mon Sep 17 00:00:00 2001 From: wayn <1669738430@qq.com> Date: Sat, 15 May 2021 14:26:46 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E5=95=86=E5=9F=8E):=20=E6=9B=B4?= =?UTF-8?q?=E6=96=B0readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- readme.md | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/readme.md b/readme.md index 8f84e02..6ef9c3b 100644 --- a/readme.md +++ b/readme.md @@ -101,6 +101,92 @@ List list = elasticDocument.search("goods", searchSourceBuilder, JSO 2. 订单消费者接受到订单消息后生成订单记录(未支付) 3. 用户点击支付按钮时,前端根据订单编号轮询订单信息查询接口,如果订单编号记录已经入库则进行后续支付操作,如果订单编号未入库则返回错误信息(订单异常) 4. 用户支付完成后在回调通知里更新订单状态为已支付 + +#### 6. 金刚区跳转使用策略模式 +```java +# 1. 定义金刚位跳转策略接口 +public interface DiamondJumpType { + + List getGoods(Page page, Diamond diamond); + + Integer getType(); +} + +# 2. 定义策略实现类,并使用@Component注解注入spring +@Component +public class CategoryStrategy implements DiamondJumpType { + + @Autowired + private GoodsMapper goodsMapper; + + @Override + public List getGoods(Page page, Diamond diamond) { + List cateList = Arrays.asList(diamond.getValueId()); + return goodsMapper.selectGoodsListPageByl2CateId(page, cateList).getRecords(); + } + + @Override + public Integer getType() { + return JumpTypeEnum.CATEGORY.getType(); + } +} +@Component +public class ColumnStrategy implements DiamondJumpType { + + @Autowired + private IColumnGoodsRelationService iColumnGoodsRelationService; + + @Autowired + private IGoodsService iGoodsService; + + @Override + public List getGoods(Page page, Diamond diamond) { + List goodsRelationList = iColumnGoodsRelationService.list(new QueryWrapper() + .eq("column_id", diamond.getValueId())); + List goodsIdList = goodsRelationList.stream().map(ColumnGoodsRelation::getGoodsId).collect(Collectors.toList()); + Page goodsPage = iGoodsService.page(page, new QueryWrapper().in("id", goodsIdList).eq("is_on_sale", true)); + return goodsPage.getRecords(); + } + + @Override + public Integer getType() { + return JumpTypeEnum.COLUMN.getType(); + } +} + +# 3. 定义策略上下文,通过构造器注入spring,定义map属性,通过key获取对应策略实现类 +@Component +public class DiamondJumpContext { + + private Map map = new HashMap<>(); + + /** + * 由spring自动注入DiamondJumpType子类 + * + * @param diamondJumpTypes 金刚位跳转类型集合 + */ + public DiamondJumpContext(List diamondJumpTypes) { + for (DiamondJumpType diamondJumpType : diamondJumpTypes) { + map.put(diamondJumpType.getType(), diamondJumpType); + } + } + + public DiamondJumpType getInstance(Integer jumpType) { + return map.get(jumpType); + } +} + +# 4.使用 +@Autowired +private DiamondJumpContext diamondJumpContext; + +@Test +public void test(){ + DiamondJumpType diamondJumpType = diamondJumpContext.getInstance(1); +} + +``` + - todo ## 文件目录