|
@@ -99,6 +99,40 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public void updateGoodsStatus(Integer goodsId, Integer status) {
|
|
|
+ if(Objects.isNull(goodsId)){
|
|
|
+ throw new BizException("请指定商品");
|
|
|
+ }
|
|
|
+ if(Objects.isNull(status)){
|
|
|
+ throw new BizException("请指定状态");
|
|
|
+ }
|
|
|
+ Goods goods = goodsDao.get(goodsId);
|
|
|
+ if(Objects.isNull(goods)){
|
|
|
+ throw new BizException("商品不存在");
|
|
|
+ }
|
|
|
+ if(StringUtils.isBlank(goods.getComplementGoodsIdList())){
|
|
|
+ if(status==0){
|
|
|
+ List<Goods> goodsList = goodsDao.getWithComplementGoodsAndStatus(goodsId, 1);
|
|
|
+ if(!CollectionUtils.isEmpty(goodsList)){
|
|
|
+ String goodsNames = StringUtils.join(goodsList.stream().map(Goods::getName).collect(Collectors.toList()));
|
|
|
+ throw new BizException("{}等商品还在销售中", goodsNames);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ if(status==1){
|
|
|
+ List<Integer> goodsIds = Arrays.stream(goods.getComplementGoodsIdList().split(",")).map(s -> Integer.valueOf(s)).collect(Collectors.toList());
|
|
|
+ List<Goods> goodList = goodsDao.getGoodies(goodsIds);
|
|
|
+ List<String> goodsNames = goodList.stream().filter(g -> YesOrNoEnum.NO.equals(g.getStatus())).map(Goods::getName).collect(Collectors.toList());
|
|
|
+ if(!CollectionUtils.isEmpty(goodsNames)){
|
|
|
+ throw new BizException("{}商品还未上架", StringUtils.join(goodsNames));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ goods.setStatus(status==0?YesOrNoEnum.NO:YesOrNoEnum.YES);
|
|
|
+ goodsDao.update(goods);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public List<Goods> findGoodsBySubId(Integer subjectId,String type) {
|
|
|
return goodsDao.findGoodsBySubId(subjectId,type);
|
|
|
}
|