| | |
| | | package com.sinata.modular.mall.controller; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.json.JSONUtil; |
| | |
| | | import com.sinata.common.enums.EnumIsDelete; |
| | | import com.sinata.common.enums.mall.EnumMallGoodsGroupType; |
| | | import com.sinata.common.enums.mall.EnumMallGoodsState; |
| | | import com.sinata.common.model.GroupSpecGoodsSkuJsonVo; |
| | | import com.sinata.core.base.controller.BaseController; |
| | | import com.sinata.core.base.tips.ErrorTip; |
| | | import com.sinata.core.common.annotion.BussinessLog; |
| | |
| | | |
| | | @Autowired |
| | | private IMallGoodsService mallGoodsService; |
| | | |
| | | @Autowired |
| | | private IMallGroupSpecService groupSpecService; |
| | | |
| | | @Autowired |
| | | private IMallGoodsSkuService mallGoodsSkuService; |
| | |
| | | .in("id", ids.split(",")) |
| | | ); |
| | | } |
| | | |
| | | @ResponseBody |
| | | @BussinessLog(value = "获取商品列表") |
| | | @GetMapping(value = "/goodsByGoodsSpecId") |
| | | public List<Map<String, Object>> goodsByIdsList(String goodsIds, Integer groupSpecId, String oldGoodsSkuJson) { |
| | | List<MallGoods> goodsList = mallGoodsService.selectList( |
| | | new EntityWrapper<MallGoods>() |
| | | .eq("group_type", EnumMallGoodsGroupType.GOODS.index) |
| | | .in("id", goodsIds.split(",")) |
| | | ); |
| | | |
| | | List<Map<String, Object>> list; |
| | | if (groupSpecId != null) { |
| | | String goodsSkuJson = oldGoodsSkuJson; |
| | | if (StrUtil.isBlank(goodsSkuJson) || goodsSkuJson.equals("[]")) { |
| | | // 查询套餐规格组信息 |
| | | MallGroupSpec groupSpec = groupSpecService.selectById(groupSpecId); |
| | | goodsSkuJson = groupSpec.getGoodsSkuJson(); |
| | | } |
| | | |
| | | // 格式化套餐规格组数据 |
| | | List<GroupSpecGoodsSkuJsonVo> groupSpecGoodsSkuJsonVoList; |
| | | if (StrUtil.isBlank(goodsSkuJson) || goodsSkuJson.equals("[]")) { |
| | | groupSpecGoodsSkuJsonVoList = null; |
| | | } else { |
| | | groupSpecGoodsSkuJsonVoList = JSONUtil.parseArray(goodsSkuJson).toList(GroupSpecGoodsSkuJsonVo.class); |
| | | } |
| | | |
| | | list = goodsList.stream().map(o -> { |
| | | Map<String, Object> map = BeanUtil.beanToMap(o); |
| | | Integer goodsNum = 1; |
| | | if (groupSpecGoodsSkuJsonVoList != null) { |
| | | // 匹配商品数量 |
| | | for (GroupSpecGoodsSkuJsonVo groupSpecGoodsSkuJsonVo : groupSpecGoodsSkuJsonVoList) { |
| | | if (o.getId().equals(groupSpecGoodsSkuJsonVo.getGoodsId())) { |
| | | goodsNum = groupSpecGoodsSkuJsonVo.getGoodsNum(); |
| | | } |
| | | } |
| | | } |
| | | map.put("goodsNum", goodsNum); |
| | | return map; |
| | | }).collect(Collectors.toList()); |
| | | } else { |
| | | list = goodsList.stream().map(o -> { |
| | | Map<String, Object> map = BeanUtil.beanToMap(o); |
| | | map.put("goodsNum", 1); |
| | | return map; |
| | | }).collect(Collectors.toList()); |
| | | } |
| | | return list; |
| | | } |
| | | } |