...
|
...
|
@@ -38,77 +38,80 @@ public class ProductGoodsLogicService { |
|
|
private StorageService storageService;
|
|
|
|
|
|
/**
|
|
|
* @return
|
|
|
*
|
|
|
*/
|
|
|
public List<ProductGoodsBO> getData(List<Integer> productIds) {
|
|
|
// 解析product_good视图
|
|
|
//构建productColorsMap
|
|
|
List<ProductColor> productColors = productColorMapper.getAll();
|
|
|
if(CollectionUtils.isEmpty(productColors)){
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
Map<Integer, String> productColorsMap = new HashMap<>();
|
|
|
for (ProductColor p : productColors) {
|
|
|
productColorsMap.put(p.getId(), p.getColorCode() == null ? "" : p.getColorCode());
|
|
|
}
|
|
|
// 获取Goods数据
|
|
|
List<Goods> goodss = goodsMapper.selectListByProductIds(productIds);
|
|
|
// 解析goods_cover_image 视图
|
|
|
|
|
|
|
|
|
List<Goods> goodsList = goodsMapper.selectListByProductIds(productIds);
|
|
|
List<Integer> goodsIds = goodsMapper.getIdByProductIds(productIds);
|
|
|
List<GoodsCoverImage> goodsCoverImages = new ArrayList<GoodsCoverImage>();
|
|
|
List<Storage> storages = new ArrayList<>();
|
|
|
List<GoodsCoverImage> goodsCoverImageList = new ArrayList<GoodsCoverImage>();
|
|
|
List<Storage> storageList = new ArrayList<>();
|
|
|
if (goodsIds != null && !goodsIds.isEmpty()) {
|
|
|
goodsCoverImages = goodsCoverImageMapper.selectGoodsCoverImage(goodsIds);
|
|
|
storages = storageService.getStoragesByGoodsIds(goodsIds);
|
|
|
goodsCoverImageList = goodsCoverImageMapper.selectGoodsCoverImage(goodsIds);
|
|
|
storageList = storageService.getStoragesByGoodsIds(goodsIds);
|
|
|
}
|
|
|
//获取goods对应的库存
|
|
|
Map<Integer, Integer> storagesMap = new HashMap<>();
|
|
|
if (!CollectionUtils.isEmpty(storages)) {
|
|
|
for (Storage storage : storages) {
|
|
|
if (storagesMap.containsKey(storage.getGoodsId())) {
|
|
|
storagesMap.put(storage.getGoodsId(), storage.getStorageNum() + storagesMap.get(storage.getGoodsId()));
|
|
|
//构建storageListMap
|
|
|
Map<Integer, Integer> storageListMap = new HashMap<>();
|
|
|
if (!CollectionUtils.isEmpty(storageList)) {
|
|
|
for (Storage storage : storageList) {
|
|
|
if (storageListMap.containsKey(storage.getGoodsId())) {
|
|
|
storageListMap.put(storage.getGoodsId(), storage.getStorageNum() + storageListMap.get(storage.getGoodsId()));
|
|
|
} else {
|
|
|
storagesMap.put(storage.getGoodsId(), storage.getStorageNum());
|
|
|
storageListMap.put(storage.getGoodsId(), storage.getStorageNum());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//构建goodsCoverImagesMap
|
|
|
Map<Integer, GoodsCoverImage> goodsCoverImagesMap = new HashMap<>();
|
|
|
// 用goodsId作为key
|
|
|
for (GoodsCoverImage g : goodsCoverImages) {
|
|
|
if (goodsCoverImagesMap.containsKey(g.getGoodsId())) {
|
|
|
GoodsCoverImage goodsCoverImage = goodsCoverImagesMap.get(g.getGoodsId());
|
|
|
if (StringUtils.isBlank(goodsCoverImage.getCover_1()) && !StringUtils.isBlank((g.getCover_1()))) {
|
|
|
goodsCoverImage.setCover_1(g.getCover_1());
|
|
|
for (GoodsCoverImage coverImage : goodsCoverImageList) {
|
|
|
if (goodsCoverImagesMap.containsKey(coverImage.getGoodsId())) {
|
|
|
GoodsCoverImage goodsCoverImage = goodsCoverImagesMap.get(coverImage.getGoodsId());
|
|
|
if (StringUtils.isBlank(goodsCoverImage.getCover_1()) && !StringUtils.isBlank((coverImage.getCover_1()))) {
|
|
|
goodsCoverImage.setCover_1(coverImage.getCover_1());
|
|
|
}
|
|
|
if (StringUtils.isBlank(goodsCoverImage.getCover_2()) && !StringUtils.isBlank((g.getCover_2()))) {
|
|
|
goodsCoverImage.setCover_2(g.getCover_2());
|
|
|
if (StringUtils.isBlank(goodsCoverImage.getCover_2()) && !StringUtils.isBlank((coverImage.getCover_2()))) {
|
|
|
goodsCoverImage.setCover_2(coverImage.getCover_2());
|
|
|
}
|
|
|
} else {
|
|
|
goodsCoverImagesMap.put(g.getGoodsId(), g);
|
|
|
goodsCoverImagesMap.put(coverImage.getGoodsId(), coverImage);
|
|
|
}
|
|
|
}
|
|
|
// 构造product_good视图
|
|
|
|
|
|
//根据productId分组
|
|
|
List<ProductGoodBO> productGoodBOs = new ArrayList<>();
|
|
|
for (Goods g : goodss) {
|
|
|
for (Goods goods : goodsList) {
|
|
|
ProductGoodBO productGoodBO = new ProductGoodBO();
|
|
|
productGoodBO.setProduct_id(g.getProductId());
|
|
|
productGoodBO.setIsDefault(g.getIsDefault() == null ? "" : g.getIsDefault());
|
|
|
this.buildGoods(g, productGoodBO, productColorsMap, goodsCoverImagesMap, storagesMap);
|
|
|
productGoodBO.setProduct_id(goods.getProductId());
|
|
|
productGoodBO.setIsDefault(goods.getIsDefault() == null ? "" : goods.getIsDefault());
|
|
|
this.buildGoods(goods, productGoodBO, productColorsMap, goodsCoverImagesMap, storageListMap);
|
|
|
productGoodBOs.add(productGoodBO);
|
|
|
}
|
|
|
// 构建product_goods视图
|
|
|
Map<Integer, JSONArray> productGoodsMap = new HashMap<>();
|
|
|
for (ProductGoodBO p : productGoodBOs) {
|
|
|
if (productGoodsMap.containsKey(p.getProduct_id())) {
|
|
|
if (p.getGoodList() != null) {
|
|
|
JSONArray jsonArray = productGoodsMap.get(p.getProduct_id());
|
|
|
jsonArray.add(p.getGoodList());
|
|
|
productGoodsMap.put(p.getProduct_id(), jsonArray);
|
|
|
for (ProductGoodBO productGoodBO : productGoodBOs) {
|
|
|
if (productGoodsMap.containsKey(productGoodBO.getProduct_id())) {
|
|
|
if (productGoodBO.getGoodList() != null) {
|
|
|
JSONArray jsonArray = productGoodsMap.get(productGoodBO.getProduct_id());
|
|
|
jsonArray.add(productGoodBO.getGoodList());
|
|
|
productGoodsMap.put(productGoodBO.getProduct_id(), jsonArray);
|
|
|
}
|
|
|
} else {
|
|
|
JSONArray jsonArray = new JSONArray();
|
|
|
jsonArray.add(p.getGoodList());
|
|
|
productGoodsMap.put(p.getProduct_id(), jsonArray);
|
|
|
jsonArray.add(productGoodBO.getGoodList());
|
|
|
productGoodsMap.put(productGoodBO.getProduct_id(), jsonArray);
|
|
|
}
|
|
|
}
|
|
|
List<ProductGoodsBO> productGoodsBOs = new ArrayList<>();
|
|
|
// 塞入productGoodss 顺便把GoodList加上[]包裹
|
|
|
for (Map.Entry<Integer, JSONArray> entry : productGoodsMap.entrySet()) {
|
|
|
ProductGoodsBO pg = new ProductGoodsBO();
|
|
|
pg.setProductId(entry.getKey());
|
...
|
...
|
@@ -119,30 +122,34 @@ public class ProductGoodsLogicService { |
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 拼装goods_list字段
|
|
|
* 拼装goodsList字段
|
|
|
*/
|
|
|
private void buildGoods(Goods g, ProductGoodBO productGoodBO, Map<Integer, String> productColorsMap, Map<Integer, GoodsCoverImage> goodsCoverImagesMap, Map<Integer, Integer> storagesMap) {
|
|
|
private void buildGoods(Goods goods, ProductGoodBO productGoodBO, Map<Integer, String> productColorsMap, Map<Integer, GoodsCoverImage> goodsCoverImagesMap, Map<Integer, Integer> storageMap) {
|
|
|
JSONObject jsonObj = new JSONObject();
|
|
|
jsonObj.put("goods_id", String.valueOf(g.getId()));
|
|
|
jsonObj.put("color_name", StringUtils.isBlank(g.getColorName())? "" : g.getColorName());
|
|
|
//来自Goods
|
|
|
jsonObj.put("goods_id", String.valueOf(goods.getId()));
|
|
|
jsonObj.put("color_name", StringUtils.isBlank(goods.getColorName())? "" : goods.getColorName());
|
|
|
jsonObj.put("images_url", StringUtils.isBlank(goods.getColorImage()) ? "" : goods.getColorImage());
|
|
|
jsonObj.put("is_default", StringUtils.isBlank(goods.getIsDefault())? "" : goods.getIsDefault());
|
|
|
jsonObj.put("color_id", goods.getColorId() == null ? "" : goods.getColorId().toString());
|
|
|
jsonObj.put("status", goods.getStatus() == null ? "" : goods.getStatus().toString());
|
|
|
jsonObj.put("product_skc", goods.getProductSkc() == null ? "" : goods.getProductSkc());
|
|
|
jsonObj.put("color_value", "");
|
|
|
//来自productColorsMap
|
|
|
String colorCode = productColorsMap.get(goods.getColorId());
|
|
|
jsonObj.put("color_code", StringUtils.isBlank(colorCode) ? "" : colorCode);
|
|
|
//来自goodsCoverImagesMap
|
|
|
GoodsCoverImage goodsCoverImage = goodsCoverImagesMap.get(goods.getId());
|
|
|
String cover_1 = "";
|
|
|
String cover_2 = "";
|
|
|
GoodsCoverImage goodsCoverImage = goodsCoverImagesMap.get(g.getId());
|
|
|
if (goodsCoverImage != null) {
|
|
|
cover_1 = goodsCoverImage.getCover_1();
|
|
|
cover_2 = goodsCoverImage.getCover_2();
|
|
|
}
|
|
|
jsonObj.put("cover_1", StringUtils.isBlank(cover_1) ? "" : cover_1);
|
|
|
jsonObj.put("cover_2", StringUtils.isBlank(cover_2) ? "" : cover_2);
|
|
|
jsonObj.put("color_id", g.getColorId() == null ? "" : g.getColorId().toString());
|
|
|
jsonObj.put("status", g.getStatus() == null ? "" : g.getStatus().toString());
|
|
|
String colorCode = productColorsMap.get(g.getColorId());
|
|
|
jsonObj.put("color_code", StringUtils.isBlank(colorCode) ? "" : colorCode);
|
|
|
jsonObj.put("color_value", "");
|
|
|
jsonObj.put("images_url", StringUtils.isBlank(g.getColorImage()) ? "" : g.getColorImage());
|
|
|
jsonObj.put("product_skc", g.getProductSkc() == null ? "" : g.getProductSkc());
|
|
|
jsonObj.put("is_default", StringUtils.isBlank(g.getIsDefault())? "" : g.getIsDefault());
|
|
|
jsonObj.put("storage_num", storagesMap.get(g.getId()) == null ? 0 : storagesMap.get(g.getId()));
|
|
|
//来自storageMap
|
|
|
jsonObj.put("storage_num", storageMap.get(goods.getId()) == null ? 0 : storageMap.get(goods.getId()));
|
|
|
productGoodBO.setGoodList(jsonObj);
|
|
|
}
|
|
|
|
...
|
...
|
|