From 2d8b4339c5fe8bd0bd537311b0cf373a4d71ce00 Mon Sep 17 00:00:00 2001 From: Gitea Date: Tue, 28 Feb 2023 08:54:43 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E7=AE=A1=E7=90=86=E6=89=80?= =?UTF-8?q?=E6=9C=89=E6=A8=A1=E5=9D=97=E4=BB=A5=E5=8F=8A=E5=95=86=E5=93=81?= =?UTF-8?q?=E7=AE=A1=E7=90=86BUG=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demo/zygoods/service/IZyGoodsService.java | 3 ++ .../service/impl/ZyGoodsServiceImpl.java | 42 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/zygoods/service/IZyGoodsService.java b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/zygoods/service/IZyGoodsService.java index c25dfaa0..27f410d7 100644 --- a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/zygoods/service/IZyGoodsService.java +++ b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/zygoods/service/IZyGoodsService.java @@ -1,5 +1,6 @@ package org.jeecg.modules.demo.zygoods.service; +import org.jeecg.modules.demo.ordergoods.entity.OrderGoodsJk; import org.jeecg.modules.demo.zygoods.entity.ZyGoods; import com.baomidou.mybatisplus.extension.service.IService; @@ -13,5 +14,7 @@ import java.util.List; */ public interface IZyGoodsService extends IService { public List selectByMainId(String mainId); + //随机获取商品 + List SJgetOrder(); } diff --git a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/zygoods/service/impl/ZyGoodsServiceImpl.java b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/zygoods/service/impl/ZyGoodsServiceImpl.java index 90463972..8e5531e3 100644 --- a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/zygoods/service/impl/ZyGoodsServiceImpl.java +++ b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/zygoods/service/impl/ZyGoodsServiceImpl.java @@ -1,5 +1,7 @@ package org.jeecg.modules.demo.zygoods.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import org.jeecg.modules.demo.ordergoods.entity.OrderGoodsJk; import org.jeecg.modules.demo.zygoods.entity.ZyGoods; import org.jeecg.modules.demo.zygoods.mapper.ZyGoodsMapper; import org.jeecg.modules.demo.zygoods.service.IZyGoodsService; @@ -8,6 +10,7 @@ import org.springframework.stereotype.Service; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import java.util.ArrayList; import java.util.List; /** @@ -26,4 +29,43 @@ public class ZyGoodsServiceImpl extends ServiceImpl impl return zyGoodsMapper.selectByMainId(mainId); } + /** + * 随机获取商品 + * @return + */ + @Override + public List SJgetOrder() { + List orderGoodsJkList = new ArrayList<>(); + QueryWrapper wrapper = new QueryWrapper<>(); + List goodsList = baseMapper.selectList(wrapper); + if(goodsList.size()>10){ + //随机取商品数(1-5)个 + int number = (int)(Math.random()*5)+1; + for(int i = 0 ; i < number ; i++){ + //goodsList的随机下标数 + int numberxb = (int)(Math.random()*goodsList.size()); + //随机取商品数量(1-5)个 + int numbersl = (int)(Math.random()*5)+1; + OrderGoodsJk orderGoodsJk = new OrderGoodsJk(); + orderGoodsJk.setGoodsId(goodsList.get(numberxb).getId()); + orderGoodsJk.setGoodsNum(numbersl); + orderGoodsJkList.add(orderGoodsJk); + } + }else{ + if(goodsList.size()>0){ + //goodsList的随机下标数 + int numberxb1 = (int)(Math.random()*goodsList.size()); + //随机取商品数量(1-5)个 + int numbersl = (int)(Math.random()*5)+1; + OrderGoodsJk orderGoodsJk = new OrderGoodsJk(); + orderGoodsJk.setGoodsId(goodsList.get(numberxb1).getId()); + orderGoodsJk.setGoodsNum(numbersl); + orderGoodsJkList.add(orderGoodsJk); + } + + } + + return orderGoodsJkList; + } + }