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.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.baomidou.mybatisplus.mapper.Wrapper;
|
import com.baomidou.mybatisplus.plugins.Page;
|
import com.google.common.collect.Lists;
|
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;
|
import com.sinata.core.common.annotion.Permission;
|
import com.sinata.core.common.constant.factory.PageFactory;
|
import com.sinata.core.common.exception.BizExceptionEnum;
|
import com.sinata.core.log.LogObjectHolder;
|
import com.sinata.core.shiro.ShiroKit;
|
import com.sinata.core.util.Convert;
|
import com.sinata.core.util.DateUtils2;
|
import com.sinata.core.util.ExcelExportUtil;
|
import com.sinata.core.util.SpringContextHolder;
|
import com.sinata.modular.mall.model.*;
|
import com.sinata.modular.mall.service.*;
|
import org.apache.commons.collections.CollectionUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.ui.Model;
|
import org.springframework.util.StringUtils;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletResponse;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
/**
|
* 商品信息控制器
|
*
|
* @author goku
|
*/
|
@Controller
|
@RequestMapping("/mallGoods")
|
public class MallGoodsController extends BaseController {
|
|
private String PREFIX = "/mall/mallGoods/";
|
|
@Autowired
|
private IMallGoodsService mallGoodsService;
|
|
@Autowired
|
private IMallGroupSpecService groupSpecService;
|
|
@Autowired
|
private IMallGoodsSkuService mallGoodsSkuService;
|
|
@Autowired
|
private IMallClassifyOneService mallClassifyOneService;
|
|
@Autowired
|
private IMallGoodsSpecService mallGoodsSpecService;
|
|
@Autowired
|
private IMallGoodsDetailService mallGoodsDetailService;
|
@Autowired
|
private IMallGoodsSetService mallGoodsSetService;
|
|
@Resource
|
private IMallGoodsSpecService goodsSpecService;
|
|
@Resource
|
private IMallGoodsSpecValueService goodsSpecValueService;
|
|
@Resource
|
private IMallTagService mallTagService;
|
|
|
/**
|
* 跳转到商品信息首页
|
*/
|
@RequestMapping("")
|
public String index() {
|
return PREFIX + "mallGoods.html";
|
}
|
|
/**
|
* 跳转到添加商品信息
|
*/
|
@RequestMapping("/mallGoods_add")
|
public String mallGoodsAdd(Model model) {
|
// 查询所有标签
|
List<MallTag> mallTags = mallTagService.getMallTags();
|
model.addAttribute("mallTags", mallTags);
|
return PREFIX + "mallGoods_add.html";
|
}
|
|
/**
|
* 跳转到修改商品信息
|
*/
|
@RequestMapping("/mallGoods_update/{mallGoodsId}")
|
public String mallGoodsUpdate(@PathVariable Integer mallGoodsId, Model model) {
|
MallGoods mallGoods = mallGoodsService.selectById(mallGoodsId);
|
|
MallGoodsDetail goodsDetail = mallGoodsDetailService.selectById(mallGoodsId);
|
mallGoods.setIntroH5(goodsDetail.getIntroH5());
|
mallGoods.setIntroImage(goodsDetail.getIntroImage());
|
mallGoods.setPurchaseH5(goodsDetail.getPurchaseH5());
|
model.addAttribute("item", mallGoods);
|
|
MallGoodsSet goodsSet = mallGoodsSetService.selectById(mallGoodsId);
|
model.addAttribute("goodsSet", goodsSet);
|
|
// 查询所有标签
|
List<MallTag> mallTags = mallTagService.getMallTags();
|
model.addAttribute("mallTags", mallTags);
|
|
LogObjectHolder.me().set(mallGoods);
|
return PREFIX + "mallGoods_edit.html";
|
}
|
|
@ResponseBody
|
@GetMapping(value = "/getGoodsSpecData")
|
public List<MallGoodsSku> getGoodsSpecData(Integer goodsId) {
|
List<MallGoodsSku> skuList = mallGoodsSkuService.selectList(
|
new EntityWrapper<MallGoodsSku>()
|
.setSqlSelect("spec_ids id, grep_name, stock,price_sale,price_member")
|
.eq("goods_id", goodsId)
|
.eq("merchant_id", 0)
|
);
|
|
MallGoods mallGoods = mallGoodsService.selectById(goodsId);
|
|
String classifyName = "";
|
MallClassifyOne classifyOne = mallClassifyOneService.selectById(mallGoods.getClassifyIdOne());
|
if (classifyOne != null) {
|
classifyName = classifyOne.getClassifyName();
|
}
|
for (MallGoodsSku sku : skuList) {
|
sku.setClassifyName(classifyName);
|
}
|
return skuList;
|
}
|
|
/**
|
* 获取商品信息列表
|
*
|
* @param id 商品id
|
* @param state 商品状态
|
*/
|
@ResponseBody
|
@RequestMapping(value = "/list")
|
public Object list(String beginTime, String endTime, String goodsName, String id, Integer state, String goodsNo) {
|
Page<Map<String, Object>> page = new PageFactory().defaultPage();
|
|
page.setRecords(
|
wrapperList(page, beginTime, endTime, goodsName, id, state, goodsNo)
|
);
|
|
return super.packForBT(page);
|
}
|
|
public List<Map<String, Object>> wrapperList(Page<Map<String, Object>> page, String beginTime, String endTime, String goodsName, String id, Integer state, String goodsNo) {
|
Wrapper wrapper = new EntityWrapper<MallGoods>()
|
.eq("group_type", EnumMallGoodsGroupType.GOODS.index)
|
.eq("is_delete", 0)
|
.orderBy("id", false);
|
|
// 时间搜索
|
if (!StringUtils.isEmpty(beginTime)) {
|
wrapper.ge("create_time", beginTime + " 00:00:00");
|
}
|
if (!StringUtils.isEmpty(endTime)) {
|
wrapper.le("create_time", endTime + " 23:59:59");
|
}
|
|
if (!StringUtils.isEmpty(goodsName)) {
|
wrapper.like("goods_name", goodsName);
|
}
|
if (!StringUtils.isEmpty(id)) {
|
if (id.indexOf("sp") != -1) {
|
String idd = id.substring(id.indexOf("sp") + 2);
|
wrapper.eq("id", Integer.parseInt(idd));
|
} else {
|
wrapper.eq("id", Integer.parseInt(id));
|
}
|
}
|
if (state != null) {
|
wrapper.eq("state", state);
|
}
|
if (StrUtil.isNotBlank(goodsNo)) {
|
wrapper.like("goods_no", goodsNo);
|
}
|
|
// 查询所有标签
|
List<MallTag> mallTags = mallTagService.getMallTags();
|
|
// 查询数据列表
|
List<Map<String, Object>> list;
|
if (page != null) {
|
list = mallGoodsService.selectMapsPage(page, wrapper).getRecords();
|
} else {
|
list = mallGoodsService.selectMaps(wrapper);
|
}
|
|
// 规格列表
|
List<MallGoodsSpec> selectList = mallGoodsSpecService.selectList(new EntityWrapper<MallGoodsSpec>().setSqlSelect("id, spec_name"));
|
|
return list.stream().peek(m -> {
|
Object classObj = m.get("classifyIdOne");
|
if (classObj != null) {
|
m.put("classifyName", mallClassifyOneService.selectById(Convert.toInt(classObj)).getClassifyName());
|
}
|
|
// 封装规格名
|
List<String> specNameList = new ArrayList<>();
|
List<MallGoodsSku> skuList = mallGoodsSkuService.selectList(new EntityWrapper<MallGoodsSku>().eq("goods_id", m.get("id")).eq("merchant_id", 0));
|
for (MallGoodsSku sku : skuList) {
|
String[] spIds = sku.getSpecGrep().split(",");
|
for (String spId : spIds) {
|
for (MallGoodsSpec spec : selectList) {
|
if (spec.getId().toString().equals(spId)) {
|
specNameList.add(spec.getSpecName());
|
}
|
}
|
}
|
}
|
m.put("specNames", specNameList.stream().distinct().collect(Collectors.joining(",")));
|
|
m.put("merchantCount", mallGoodsSkuService.selectCount(
|
new EntityWrapper<MallGoodsSku>()
|
.eq("goods_id", m.get("id"))
|
.ne("merchant_id", 0)
|
.groupBy("goods_id")
|
));
|
|
Object tagIds = m.get("tagIds");
|
if (tagIds != null) {
|
m.put("tagIds", mallTagService.getTagListByGoodsId(mallTags, tagIds.toString()).stream().collect(Collectors.joining("、")));
|
}
|
}).collect(Collectors.toList());
|
}
|
|
@ResponseBody
|
@RequestMapping(value = "/export")
|
public void export(String beginTime, String endTime, String goodsName, String id, Integer state, String goodsNo, HttpServletResponse response) {
|
List<Map<String, Object>> list = wrapperList(null, beginTime, endTime, goodsName, id, state, goodsNo);
|
|
// 表格数据【封装】
|
List<List<Object>> dataList = new ArrayList<>();
|
|
// 头部列【封装】
|
List<Object> shellList = new ArrayList<>();
|
shellList.add("创建时间");
|
shellList.add("商品编号");
|
shellList.add("商品分类");
|
shellList.add("商品名称");
|
shellList.add("商品副标题");
|
shellList.add("商品标签");
|
shellList.add("规格");
|
shellList.add("销售量");
|
shellList.add("商品库存");
|
shellList.add("售卖门店数");
|
shellList.add("销售价");
|
shellList.add("会员价");
|
shellList.add("商品状态");
|
dataList.add(shellList);
|
|
// 详细数据列【封装】
|
for (Map<String, Object> map : list) {
|
shellList = new ArrayList<>();
|
shellList.add(map.get("createTime"));
|
shellList.add(map.get("goodsNo"));
|
shellList.add(map.get("classifyName"));
|
shellList.add(map.get("goodsName"));
|
shellList.add(map.get("goodsTitle"));
|
shellList.add(map.get("tagIds"));
|
shellList.add(map.get("specNames"));
|
shellList.add(map.get("buyCount"));
|
shellList.add(map.get("stock"));
|
shellList.add(map.get("merchantCount"));
|
shellList.add(map.get("priceSale"));
|
shellList.add(map.get("priceMember"));
|
shellList.add(EnumMallGoodsState.getMarkByIndex((Integer) map.get("state")));
|
dataList.add(shellList);
|
}
|
try {
|
String title = "商品信息";
|
// 调用工具类进行导出
|
ExcelExportUtil.easySheet(title + DateUtils2.formatDate(new Date(), "YYYYMMddHHmmSS"), title, dataList, response);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
@ResponseBody
|
@BussinessLog(value = "新增商品信息")
|
@RequestMapping(value = "/add")
|
public Object add(MallGoods mallGoods) {
|
if (mallGoods.getState() == null) {
|
mallGoods.setState(EnumMallGoodsState.FOR_SALE.getIndex());
|
}
|
|
if (StrUtil.isNotBlank(mallGoods.getIntroImage())) {
|
mallGoods.setGoodsImage(mallGoods.getIntroImage().split(",")[0]);
|
}
|
mallGoods.setGoodsSkus(JSONUtil.toList(mallGoods.getGoodsSkusJson(), MallGoodsSku.class));
|
if (mallGoods.getGoodsSkus() == null || CollUtil.isEmpty(mallGoods.getGoodsSkus())) {
|
return new ErrorTip(BizExceptionEnum.REQUEST_INVALIDATE.getCode(), "请添加商品规格不存在");
|
}
|
mallGoods.setGoodsSet(JSONUtil.toBean(mallGoods.getGoodsSetJson(), MallGoodsSet.class));
|
mallGoodsService.saveMallGoods(mallGoods);
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 修改商品信息
|
*/
|
@ResponseBody
|
@BussinessLog(value = "修改商品信息")
|
@RequestMapping(value = "/update")
|
public Object update(MallGoods mallGoods) {
|
MallGoods oldGoods = this.mallGoodsService.selectById(mallGoods.getId());
|
if (oldGoods == null) {
|
return new ErrorTip(BizExceptionEnum.REQUEST_INVALIDATE.getCode(), "商品不存在");
|
}
|
// MallGoodsDetail goodsDetail = this.mallGoodsDetailService.selectById(mallGoods.getId());
|
// if (oldGoods.getState() == EnumMallGoodsState.CMS_REFUSE_SALE.getIndex()
|
// || !StrUtil.equals(oldGoods.getGoodsName(),mallGoods.getGoodsName())
|
// || !StrUtil.equals(oldGoods.getGoodsImage(),mallGoods.getGoodsImage())
|
// || !StrUtil.equals(goodsDetail.getIntroImage(),mallGoods.getIntroImage())
|
// || !StrUtil.equals(goodsDetail.getIntroH5(),mallGoods.getIntroH5())) {
|
// mallGoods.setState(EnumMallGoodsState.WAIT_AUDIT.getIndex());
|
// }
|
if (StrUtil.isNotBlank(mallGoods.getIntroImage())) {
|
mallGoods.setGoodsImage(mallGoods.getIntroImage().split(",")[0]);
|
}
|
mallGoods.setGoodsSkus(JSONUtil.toList(mallGoods.getGoodsSkusJson(), MallGoodsSku.class));
|
if (mallGoods.getGoodsSkus() == null || CollUtil.isEmpty(mallGoods.getGoodsSkus())) {
|
return new ErrorTip(BizExceptionEnum.REQUEST_INVALIDATE.getCode(), "请添加商品规格不存在");
|
}
|
mallGoods.setGoodsSet(JSONUtil.toBean(mallGoods.getGoodsSetJson(), MallGoodsSet.class));
|
mallGoodsService.updateMallGoods(mallGoods);
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 删除/批量删除
|
*/
|
@Permission
|
@ResponseBody
|
@BussinessLog(value = "删除/批量删除商品信息")
|
@RequestMapping(value = "/delete")
|
public Object delete(@RequestParam String ids) {
|
String[] idArray = ids.split(",");
|
// 逻辑删除
|
mallGoodsService.updateForSet("is_delete = 1", new EntityWrapper<MallGoods>().in("id", idArray));
|
|
mallGoodsSkuService.delete(
|
new EntityWrapper<MallGoodsSku>()
|
.in("goods_id", idArray)
|
);
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 修改商品信息状态上下架和商品审核接口
|
*/
|
@ResponseBody
|
@BussinessLog(value = "修改商品信息状态")
|
@RequestMapping(value = "/updateState")
|
public Object updateState(Integer mallGoodsId, Integer state, String auditRemark) {
|
mallGoodsService.updateForSet("state = " + state + ",audit_remark = '" + auditRemark + "'", new EntityWrapper<MallGoods>().eq("id", mallGoodsId));
|
return SUCCESS_TIP;
|
}
|
|
@RequestMapping("/to_buyCount/{mallGoodsId}")
|
public String to_buyCount(@PathVariable Integer mallGoodsId, Model model) {
|
MallGoods mallGoods = mallGoodsService.selectById(mallGoodsId);
|
model.addAttribute("item", mallGoods);
|
return PREFIX + "mallGoods_buyCount.html";
|
}
|
|
@ResponseBody
|
@BussinessLog(value = "修改销售量")
|
@RequestMapping(value = "/updateBuyCount")
|
public Object updateBuyCount(Integer mallGoodsId, Integer buyCount) {
|
mallGoodsService.updateForSet("buy_count = " + buyCount, new EntityWrapper<MallGoods>().eq("id", mallGoodsId));
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 修改商品信息推荐
|
*/
|
@ResponseBody
|
@BussinessLog(value = "修改商品信息推荐")
|
@RequestMapping(value = "/updateRecommend")
|
public Object updateRecommend(Integer mallGoodsId, Integer isRecommend, Integer sort) {
|
mallGoodsService.updateForSet("is_recommend = " + isRecommend + ",sort=" + sort, new EntityWrapper<MallGoods>().eq("id", mallGoodsId));
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 跳转商品信息详情
|
*/
|
@RequestMapping(value = "/detail/{mallGoodsId}")
|
public Object detail(@PathVariable("mallGoodsId") Integer mallGoodsId, Model model) {
|
MallGoods mallGoods = mallGoodsService.selectById(mallGoodsId);
|
mallGoods.setMallClassifyOne(this.mallClassifyOneService.selectById(mallGoods.getClassifyIdOne()));
|
|
MallGoodsDetail goodsDetail = this.mallGoodsDetailService.selectById(mallGoods.getId());
|
if (goodsDetail == null) {
|
goodsDetail = new MallGoodsDetail();
|
}
|
|
// 查询所有标签
|
List<MallTag> mallTags = mallTagService.getMallTags();
|
mallGoods.setTagIds(mallTagService.getTagListByGoodsId(mallTags, mallGoods.getTagIds()).stream().collect(Collectors.joining("、")));
|
|
model.addAttribute("item", mallGoods);
|
model.addAttribute("mallGoodsState", EnumMallGoodsState.getMarkByIndex(mallGoods.getState()));
|
model.addAttribute("mallGoodsDetail", goodsDetail);
|
model.addAttribute("introImageList", goodsDetail.getIntroImage().split(","));
|
|
return PREFIX + "mallGoods_detail.html";
|
}
|
|
|
@RequestMapping(value = "/appView/{mallGoodsId}")
|
public Object appView(@PathVariable("mallGoodsId") Integer mallGoodsId, Model model) {
|
MallGoods mallGoods = mallGoodsService.selectById(mallGoodsId);
|
mallGoods.setMallClassifyOne(this.mallClassifyOneService.selectById(mallGoods.getClassifyIdOne()));
|
|
MallGoodsDetail goodsDetail = this.mallGoodsDetailService.selectById(mallGoods.getId());
|
if (goodsDetail == null) {
|
goodsDetail = new MallGoodsDetail();
|
}
|
|
model.addAttribute("item", mallGoods);
|
model.addAttribute("mallGoodsDetail", goodsDetail);
|
|
return PREFIX + "mallGoods_appView.html";
|
}
|
|
@RequestMapping("/mallGoodsList")
|
@ResponseBody
|
public Object mallGoodsList(Integer groupType) {
|
Wrapper wrapper = new EntityWrapper<MallGoods>().eq("is_delete", 0).orderBy("id", false);
|
if (Objects.nonNull(groupType) && groupType == -1) {
|
wrapper.ne("group_type", 0);
|
} else if (Objects.nonNull(groupType)) {
|
wrapper.eq("group_type", groupType);
|
}
|
List<MallGoods> goodsList = mallGoodsService.selectList(wrapper);
|
Set<Integer> goodsIdList = goodsList.stream().map(MallGoods::getId).collect(Collectors.toSet());
|
Wrapper skuWrapper = new EntityWrapper<MallGoodsSku>().in("goods_id", goodsIdList)
|
.eq("merchant_id", 0).orderBy("id", false);
|
List<MallGoodsSku> skuList = mallGoodsSkuService.selectList(skuWrapper);
|
List<HashMap<String, Object>> result = new ArrayList<>();
|
goodsList.forEach(goods -> {
|
List<MallGoodsSku> goodsSkuList = skuList.stream()
|
.filter(sku -> sku.getGoodsId().equals(goods.getId()))
|
.collect(Collectors.toList());
|
List<HashMap<String, Object>> goodsMapList = goodsSkuList.stream().map(sku -> {
|
HashMap<String, Object> goodMap = new HashMap<>();
|
//商品编号
|
goodMap.put("aGoodsNo", goods.getGoodsNo());
|
goodMap.put("bName", goods.getGoodsName());
|
goodMap.put("bbGrepName", sku.getGrepName());
|
goodMap.put("cGroupType", goods.getGroupType());
|
String groupTypName = goods.getGroupType() > 0 ? (goods.getGroupType() == 1 ? "黄金套餐"
|
: "钻石套餐") : "普通商品";
|
goodMap.put("cGroupTypeName", groupTypName);
|
goodMap.put("dPrice", goods.getPrice());
|
goodMap.put("dPriceDale", sku.getPriceSale());
|
goodMap.put("ePriceMember", sku.getPriceMember());
|
goodMap.put("fStock", sku.getStock());
|
goodMap.put("gBuyCount", goods.getBuyCount());
|
goodMap.put("hId", goods.getId());
|
goodMap.put("iSpecIds", sku.getSpecIds());
|
goodMap.put("jSkuId", sku.getId());
|
return goodMap;
|
}).collect(Collectors.toList());
|
result.addAll(goodsMapList);
|
});
|
/*for (int i = 0; i < result.size(); i++) {
|
for (int j = i+1; j < result.size(); j++) {
|
if (result.get(i).get("hId").equals(result.get(j).get("hId"))) {
|
result.get(j).put("bName","");
|
}
|
}
|
}*/
|
return new HashMap<String, Object>() {{
|
put("code", 200);
|
put("value", result);
|
}};
|
}
|
|
@ResponseBody
|
@BussinessLog(value = "获取商品分类")
|
@RequestMapping(value = "/getClassify")
|
public Object getClassify(@RequestParam(required = false) Integer oneClassifyId) {
|
if (oneClassifyId == null) {
|
return this.mallClassifyOneService.selectList(new EntityWrapper<MallClassifyOne>().eq("is_delete", EnumIsDelete.EXISTED.index));
|
} else {
|
return new ArrayList<>();
|
}
|
}
|
|
@BussinessLog(value = "获取商品规格")
|
@RequestMapping(value = "/getGoodsSpecs")
|
public Object getGoodsSpecs(Integer oneClassifyId, Integer twoClassifyId,@RequestParam(required = false) List<String> selectedItems, Model model) {
|
Wrapper<MallGoodsSpec> wrapper = new EntityWrapper<MallGoodsSpec>()
|
.eq("is_delete", EnumIsDelete.EXISTED.index)
|
.addFilter("concat(',',classify_id_one,',') like concat( '%,', {0}, ',%' )", oneClassifyId);
|
List<MallGoodsSpec> goodsSpecs = this.goodsSpecService.selectList(wrapper);
|
if (CollectionUtils.isEmpty(goodsSpecs)) {
|
goodsSpecs = Lists.newArrayList();
|
}
|
if (!selectedItems.isEmpty()) {
|
goodsSpecs = goodsSpecs.stream()
|
.filter(specs -> !selectedItems.contains(specs.getSpecName())).collect(
|
Collectors.toList());
|
}
|
model.addAttribute("goodsSpecs", goodsSpecs);
|
return PREFIX + "add_specs.html";
|
}
|
|
@ResponseBody
|
@BussinessLog(value = "获取商品规格的值")
|
@RequestMapping(value = "/getGoodsSpecValues")
|
public Object getGoodsSpecs(@RequestParam Integer specId) {
|
return this.goodsSpecValueService.selectList(new EntityWrapper<MallGoodsSpecValue>()
|
.eq("spec_id", specId));
|
}
|
|
@ResponseBody
|
@BussinessLog(value = "获取商品列表")
|
@GetMapping(value = "/goodsByClassList")
|
public List<MallGoods> goodsByClassList(@RequestParam Integer classId) {
|
return mallGoodsService.selectList(
|
new EntityWrapper<MallGoods>()
|
.eq("is_delete", 0)
|
.eq("group_type", EnumMallGoodsGroupType.GOODS.index)
|
.in("state", Arrays.asList(
|
EnumMallGoodsState.FOR_SALE.index
|
))
|
);
|
}
|
|
@ResponseBody
|
@BussinessLog(value = "获取商品列表")
|
@GetMapping(value = "/goodsByIdsList")
|
public List<MallGoods> goodsByIdsList(@RequestParam String ids) {
|
return mallGoodsService.selectList(
|
new EntityWrapper<MallGoods>()
|
.eq("group_type", EnumMallGoodsGroupType.GOODS.index)
|
.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;
|
}
|
}
|