|
@@ -31,7 +31,7 @@ public class AppGoodsService {
|
|
|
@Autowired
|
|
|
private SupportRepository supportRepository;
|
|
|
|
|
|
- public APIResult<List<GoodsVo>> findByIds(List<String> goodsIdList, String merchantId) {
|
|
|
+/* public APIResult<List<GoodsVo>> findByIds(List<String> goodsIdList, String merchantId) {
|
|
|
if (CollectionUtils.isEmpty(goodsIdList)) {
|
|
|
return APIResult.ok(new ArrayList<>());
|
|
|
}
|
|
@@ -108,5 +108,87 @@ public class AppGoodsService {
|
|
|
goodsVoList.add(goodsVo);
|
|
|
}
|
|
|
return APIResult.ok(goodsVoList);
|
|
|
+ }*/
|
|
|
+
|
|
|
+ /* --- rewrite 2018-05-14-------------------------------------- start */
|
|
|
+ public List<GoodsVo> findByIds(List<String> goodsIdList, String merchantId) {
|
|
|
+ if (CollectionUtils.isEmpty(goodsIdList)) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Goods> goodsList = goodsRepository.findByIds(goodsIdList, merchantId);
|
|
|
+
|
|
|
+ Map<String, Goods> goodsMap = new HashMap<>();
|
|
|
+ List<String> courseIdList = new ArrayList<>();
|
|
|
+ List<String> supportIdList = new ArrayList<>();
|
|
|
+ for (Goods goods : goodsList) {
|
|
|
+ String productId = goods.getPid();
|
|
|
+ ProductTypeEnum type = goods.getType();
|
|
|
+ if (ProductTypeEnum.COURSE.equals(type)) {
|
|
|
+ courseIdList.add(productId);
|
|
|
+ } else if (type.equals(ProductTypeEnum.SUPPORT)) {
|
|
|
+ supportIdList.add(productId);
|
|
|
+ }
|
|
|
+ String goodsId = goods.getId();
|
|
|
+ goodsMap.put(goodsId, goods);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Course> courseList = new ArrayList<>();
|
|
|
+ if (!CollectionUtils.isEmpty(courseIdList)) {
|
|
|
+ courseList = courseRepository.findByIds(courseIdList);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Support> supportList = new ArrayList<>();
|
|
|
+ if (!CollectionUtils.isEmpty(supportIdList)) {
|
|
|
+ supportList = supportRepository.findByIds(supportIdList);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 拿产品信息
|
|
|
+ Map<String, Course> courseMap = new HashMap<>();
|
|
|
+ for (Course course : courseList) {
|
|
|
+ String productId = course.getId();
|
|
|
+ courseMap.put(productId, course);
|
|
|
+ }
|
|
|
+ Map<String, Support> supportMap = new HashMap<>();
|
|
|
+ for (Support support : supportList) {
|
|
|
+ String productId = support.getId();
|
|
|
+ supportMap.put(productId, support);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 组装
|
|
|
+ List<GoodsVo> goodsVoList = new ArrayList<>();
|
|
|
+ for (String goodsId : goodsIdList) {
|
|
|
+ Goods goods = goodsMap.get(goodsId);
|
|
|
+ if (StringUtils.isEmpty(goods)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ GoodsVo goodsVo = new GoodsVo();
|
|
|
+ goodsVo.setId(goods.getId());
|
|
|
+ goodsVo.setPid(goods.getPid());
|
|
|
+ goodsVo.setType(goods.getType());
|
|
|
+ goodsVo.setChargeUnit(goods.getChargeUnit());
|
|
|
+ goodsVo.setTerminalPrice(goods.getTerminalPrice());
|
|
|
+ ProductTypeEnum type = goods.getType();
|
|
|
+ String productId = goods.getPid();
|
|
|
+ if (ProductTypeEnum.COURSE.equals(type)) {
|
|
|
+ Course course = courseMap.get(productId);
|
|
|
+ if (course != null) {
|
|
|
+ goodsVo.setTitle(course.getTitle());
|
|
|
+ goodsVo.setSubTitle(course.getSubTitle());
|
|
|
+ goodsVo.setCoverUrl(course.getCoverUrl());
|
|
|
+ }
|
|
|
+ } else if (ProductTypeEnum.SUPPORT.equals(type)) {
|
|
|
+ Support support = supportMap.get(productId);
|
|
|
+ if (support != null) {
|
|
|
+ goodsVo.setTitle(support.getTitle());
|
|
|
+ goodsVo.setSubTitle(support.getSubTitle());
|
|
|
+ goodsVo.setCoverUrl(support.getCoverUrl());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ goodsVoList.add(goodsVo);
|
|
|
+ }
|
|
|
+ return goodsVoList;
|
|
|
}
|
|
|
+
|
|
|
+ /* --- rewrite 2018-05-14-------------------------------------- end */
|
|
|
}
|