feat(商城): 添加商城商品详情接口

master
wayn 4 years ago
parent 6df16b6ba2
commit f58d683e0a

@ -13,4 +13,6 @@ import com.wayn.common.core.domain.shop.GoodsSpecification;
*/
public interface IGoodsSpecificationService extends IService<GoodsSpecification> {
Object getSpecificationVoList(Long goodsId);
}

@ -1,11 +1,17 @@
package com.wayn.common.core.service.shop.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wayn.common.core.domain.shop.GoodsSpecification;
import com.wayn.common.core.mapper.shop.GoodsSpecificationMapper;
import com.wayn.common.core.service.shop.IGoodsSpecificationService;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* <p>
*
@ -17,4 +23,50 @@ import org.springframework.stereotype.Service;
@Service
public class GoodsSpecificationServiceImpl extends ServiceImpl<GoodsSpecificationMapper, GoodsSpecification> implements IGoodsSpecificationService {
@Override
public List<VO> getSpecificationVoList(Long goodsId) {
List<GoodsSpecification> specificationList = list(new QueryWrapper<GoodsSpecification>().eq("goods_id", goodsId));
Map<String, VO> map = new HashMap<>();
List<VO> specificationVoList = new ArrayList<>();
for (GoodsSpecification goodsSpecification : specificationList) {
String specification = goodsSpecification.getSpecification();
VO goodsSpecificationVo = map.get(specification);
if (goodsSpecificationVo == null) {
goodsSpecificationVo = new VO();
goodsSpecificationVo.setName(specification);
List<GoodsSpecification> valueList = new ArrayList<>();
valueList.add(goodsSpecification);
goodsSpecificationVo.setValueList(valueList);
map.put(specification, goodsSpecificationVo);
specificationVoList.add(goodsSpecificationVo);
} else {
List<GoodsSpecification> valueList = goodsSpecificationVo.getValueList();
valueList.add(goodsSpecification);
}
}
return specificationVoList;
}
private class VO {
private String name;
private List<GoodsSpecification> valueList;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<GoodsSpecification> getValueList() {
return valueList;
}
public void setValueList(List<GoodsSpecification> valueList) {
this.valueList = valueList;
}
}
}

@ -1,18 +1,13 @@
package com.wayn.mobile.api.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
import com.wayn.common.core.domain.shop.GoodsSpecification;
import com.wayn.common.core.service.shop.IGoodsService;
import com.wayn.common.core.service.shop.IGoodsSpecificationService;
import com.wayn.common.util.R;
import com.wayn.mobile.api.service.IGoodsDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
@RestController
@ -20,18 +15,11 @@ import java.util.Map;
public class GoodsController {
@Autowired
private IGoodsService iGoodsService;
@Autowired
private IGoodsSpecificationService iGoodsSpecificationService;
private IGoodsDetailService iGoodsDetailService;
@PostMapping("detail")
public R detail(@RequestBody Map<String, Long> map) {
R success = R.success();
Long goodsId = map.get("goodsId");
List<GoodsSpecification> list = iGoodsSpecificationService.list(new QueryWrapper<GoodsSpecification>().eq("goods_id", goodsId));
success.add("goods", iGoodsService.getById(goodsId));
success.add("skuList", list);
return success;
return iGoodsDetailService.getGoodsDetailData(goodsId);
}
}

@ -4,7 +4,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wayn.common.base.BaseController;
import com.wayn.common.core.domain.shop.Goods;
import com.wayn.common.util.R;
import com.wayn.mobile.api.service.HomeService;
import com.wayn.mobile.api.service.IHomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
@ -16,17 +16,17 @@ import org.springframework.web.bind.annotation.RestController;
public class HomeController extends BaseController {
@Autowired
private HomeService homeService;
private IHomeService IHomeService;
@PostMapping("index")
public R index() {
return homeService.getHomeIndexData();
return IHomeService.getHomeIndexData();
}
@GetMapping("goodsList")
public R getGoodsList() {
Page<Goods> page = getPage();
return homeService.listGoodsPage(page);
return IHomeService.listGoodsPage(page);
}
}

@ -0,0 +1,8 @@
package com.wayn.mobile.api.service;
import com.wayn.common.util.R;
public interface IGoodsDetailService {
R getGoodsDetailData(Long goodsId);
}

@ -4,7 +4,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wayn.common.core.domain.shop.Goods;
import com.wayn.common.util.R;
public interface HomeService {
public interface IHomeService {
/**
* bannerListcategory ListnewGoodsListhotGoodsList

@ -0,0 +1,52 @@
package com.wayn.mobile.api.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wayn.common.core.domain.shop.GoodsProduct;
import com.wayn.common.core.service.shop.IGoodsProductService;
import com.wayn.common.core.service.shop.IGoodsService;
import com.wayn.common.core.service.shop.IGoodsSpecificationService;
import com.wayn.common.util.R;
import com.wayn.mobile.api.service.IGoodsDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.concurrent.*;
@Service
public class GoodsDetailServiceImpl implements IGoodsDetailService {
@Autowired
private IGoodsService iGoodsService;
@Autowired
private IGoodsSpecificationService iGoodsSpecificationService;
@Autowired
private IGoodsProductService iGoodsProductService;
@Override
public R getGoodsDetailData(Long goodsId) {
R success = R.success();
ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(10, 10,
0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<>(), r -> new Thread(r, "商品详情线程"));
Callable<Object> specificationCall = () -> iGoodsSpecificationService.getSpecificationVoList(goodsId);
Callable<List<GoodsProduct>> productCall = () -> iGoodsProductService.list(new QueryWrapper<GoodsProduct>().eq("goods_id", goodsId));
FutureTask<Object> specificationTask = new FutureTask<>(specificationCall);
FutureTask<List<GoodsProduct>> productTask = new FutureTask<>(productCall);
poolExecutor.submit(specificationTask);
poolExecutor.submit(productTask);
success.add("info", iGoodsService.getById(goodsId));
try {
success.add("specificationList", specificationTask.get());
success.add("productList", productTask.get());
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
} finally {
poolExecutor.shutdown();
}
return success;
}
}

@ -10,7 +10,7 @@ import com.wayn.common.core.service.shop.IBannerService;
import com.wayn.common.core.service.shop.ICategoryService;
import com.wayn.common.core.service.shop.IGoodsService;
import com.wayn.common.util.R;
import com.wayn.mobile.api.service.HomeService;
import com.wayn.mobile.api.service.IHomeService;
import com.wayn.mobile.framework.redis.RedisCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -19,7 +19,7 @@ import java.util.List;
import java.util.concurrent.*;
@Service
public class HomeServiceImpl implements HomeService {
public class IHomeServiceImpl implements IHomeService {
private static final String INDEX_DATA = "index_data";
Loading…
Cancel
Save