耗材关联问题
小程序 商品 问题
This commit is contained in:
@@ -2,17 +2,15 @@ package com.czg.controller.user;
|
||||
|
||||
import com.czg.constants.SystemConstants;
|
||||
import com.czg.product.param.ShopProductSkuParam;
|
||||
import com.czg.product.service.ConsInfoService;
|
||||
import com.czg.product.service.UProductService;
|
||||
import com.czg.product.vo.ShopGroupProductVo;
|
||||
import com.czg.product.vo.ShopProductInfoVo;
|
||||
import com.czg.product.vo.ShopProductSkuInfoVo;
|
||||
import com.czg.product.vo.ShopProductVo;
|
||||
import com.czg.product.vo.*;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.utils.AssertUtil;
|
||||
import com.czg.validator.ValidatorUtil;
|
||||
import com.czg.validator.group.DefaultGroup;
|
||||
import lombok.AllArgsConstructor;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -27,11 +25,13 @@ import java.util.List;
|
||||
* @author Tankaikai tankaikai@aliyun.com
|
||||
* @since 1.0 2025-02-16
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/user/product")
|
||||
public class UProductController {
|
||||
private final UProductService uProductService;
|
||||
@Resource
|
||||
private UProductService uProductService;
|
||||
@Resource
|
||||
private ConsInfoService consInfoService;
|
||||
|
||||
/**
|
||||
* 小程序点餐-热销商品列表
|
||||
@@ -40,9 +40,9 @@ public class UProductController {
|
||||
public CzgResult<List<ShopProductVo>> queryHotsProductList() {
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
List<ShopProductVo> list = uProductService.queryHotsProductList(shopId);
|
||||
list.forEach(prod -> {
|
||||
prod.setIsSaleTime(uProductService.calcIsSaleTime(prod.getDays(), prod.getStartTime(), prod.getEndTime()));
|
||||
});
|
||||
// list.forEach(prod -> {
|
||||
// prod.setIsSaleTime(uProductService.calcIsSaleTime(prod.getDays(), prod.getStartTime(), prod.getEndTime()));
|
||||
// });
|
||||
return CzgResult.success(list);
|
||||
}
|
||||
|
||||
@@ -66,6 +66,14 @@ public class UProductController {
|
||||
return CzgResult.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
@GetMapping("consStock")
|
||||
public CzgResult<List<ConsStockRecord>> getConsStockList(Long shopId) {
|
||||
return CzgResult.success(consInfoService.getConsStockList(shopId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序点餐-商品详情
|
||||
*
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.czg.product.vo;
|
||||
|
||||
import com.czg.product.dto.ProdSkuDTO;
|
||||
import com.czg.product.entity.ProdConsRelation;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
@@ -86,6 +87,8 @@ public class ShopProductVo implements Serializable {
|
||||
* 商品规格列表
|
||||
*/
|
||||
private List<ProdSkuDTO> skuList;
|
||||
private List<ProdConsRelation> prodConsRelations;
|
||||
|
||||
/**
|
||||
* 商品每周销售日 如:Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday
|
||||
*/
|
||||
|
||||
@@ -473,8 +473,6 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
entity.setRelatedRecommend(dto.getRelatedRecommendStr());
|
||||
super.save(entity);
|
||||
dto.setId(entity.getId());
|
||||
// 清除商品分类列表缓存
|
||||
clearProductCache(entity.getCategoryId());
|
||||
List<ProdSkuDTO> skuList = dto.getSkuList();
|
||||
if (CollUtil.isNotEmpty(skuList)) {
|
||||
List<ProdSku> prodSkuList = new ArrayList<>();
|
||||
@@ -491,9 +489,11 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
prodSkuMapper.insertBatch(prodSkuList);
|
||||
}
|
||||
ProdConsBindDTO prodConsBindDTO = new ProdConsBindDTO();
|
||||
prodConsBindDTO.setId(null);
|
||||
prodConsBindDTO.setId(entity.getId());
|
||||
prodConsBindDTO.setConsList(dto.getConsList());
|
||||
prodConsRelationService.saveProdConsRelation(prodConsBindDTO);
|
||||
// 清除商品分类列表缓存
|
||||
clearProductCache(entity.getCategoryId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -551,12 +551,10 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
List<Long> list = skuList.stream().map(ProdSkuDTO::getId).filter(Objects::nonNull).distinct().toList();
|
||||
skuIdList.removeAll(list);
|
||||
}
|
||||
// 清除商品分类列表缓存
|
||||
if (!old.getCategoryId().equals(dto.getCategoryId())) {
|
||||
clearProductCache(old.getCategoryId(), entity.getCategoryId());
|
||||
} else {
|
||||
clearProductCache(old.getCategoryId());
|
||||
}
|
||||
ProdConsBindDTO prodConsBindDTO = new ProdConsBindDTO();
|
||||
prodConsBindDTO.setId(dto.getId());
|
||||
prodConsBindDTO.setConsList(dto.getConsList());
|
||||
prodConsRelationService.saveProdConsRelation(prodConsBindDTO);
|
||||
if (CollUtil.isNotEmpty(skuIdList)) {
|
||||
// 逻辑删除无用的SKU数据
|
||||
UpdateChain.of(ProdSku.class)
|
||||
@@ -565,6 +563,12 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
.eq(ProdSku::getShopId, shopId)
|
||||
.update();
|
||||
}
|
||||
// 清除商品分类列表缓存
|
||||
if (!old.getCategoryId().equals(dto.getCategoryId())) {
|
||||
clearProductCache(old.getCategoryId(), entity.getCategoryId());
|
||||
} else {
|
||||
clearProductCache(old.getCategoryId());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,18 +11,15 @@ import com.czg.constants.SystemConstants;
|
||||
import com.czg.exception.CzgException;
|
||||
import com.czg.product.dto.ProdGroupRelationDTO;
|
||||
import com.czg.product.dto.ProdSkuDTO;
|
||||
import com.czg.product.entity.ProdGroup;
|
||||
import com.czg.product.entity.ProdGroupRelation;
|
||||
import com.czg.product.entity.ProdSku;
|
||||
import com.czg.product.entity.Product;
|
||||
import com.czg.product.entity.*;
|
||||
import com.czg.product.param.ShopProductSkuParam;
|
||||
import com.czg.product.service.ProdConsRelationService;
|
||||
import com.czg.product.service.UProductService;
|
||||
import com.czg.product.vo.ShopGroupProductVo;
|
||||
import com.czg.product.vo.ShopProductInfoVo;
|
||||
import com.czg.product.vo.ShopProductSkuInfoVo;
|
||||
import com.czg.product.vo.ShopProductVo;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.service.RedisService;
|
||||
import com.czg.service.product.mapper.ProdGroupMapper;
|
||||
import com.czg.service.product.mapper.ProdGroupRelationMapper;
|
||||
import com.czg.service.product.mapper.ProdSkuMapper;
|
||||
@@ -55,7 +52,8 @@ public class UProductServiceImpl extends ServiceImpl<ProductMapper, Product> imp
|
||||
private final ProdSkuMapper prodSkuMapper;
|
||||
private final ProdGroupMapper prodGroupMapper;
|
||||
private final ProdGroupRelationMapper prodGroupRelationMapper;
|
||||
private final RedisService redisService;
|
||||
private final ProdConsRelationService prodConsRelationService;
|
||||
|
||||
|
||||
@Override
|
||||
@Cacheable(value = CacheConstant.USER_CLIENT_HOTS_PRODUCT, key = "#shopId", unless = "#result.isEmpty()")
|
||||
@@ -67,6 +65,9 @@ public class UProductServiceImpl extends ServiceImpl<ProductMapper, Product> imp
|
||||
.eq(ProdSku::getIsGrounding, SystemConstants.OneZero.ONE)
|
||||
.eq(ProdSku::getIsDel, SystemConstants.OneZero.ZERO), ProdSkuDTO.class);
|
||||
item.setSkuList(skuList);
|
||||
item.setProdConsRelations(prodConsRelationService.list(query()
|
||||
.eq(ProdConsRelation::getProductId, item.getId())
|
||||
.eq(ProdConsRelation::getShopId, item.getShopId())));
|
||||
});
|
||||
return list;
|
||||
}
|
||||
@@ -85,6 +86,9 @@ public class UProductServiceImpl extends ServiceImpl<ProductMapper, Product> imp
|
||||
.eq(ProdSku::getIsGrounding, SystemConstants.OneZero.ONE)
|
||||
.eq(ProdSku::getIsDel, SystemConstants.OneZero.ZERO), ProdSkuDTO.class);
|
||||
item.setSkuList(skuList);
|
||||
item.setProdConsRelations(prodConsRelationService.list(query()
|
||||
.eq(ProdConsRelation::getProductId, item.getId())
|
||||
.eq(ProdConsRelation::getShopId, item.getShopId())));
|
||||
});
|
||||
Map<Long, ShopProductVo> productKv = productAllList.stream().collect(Collectors.toMap(ShopProductVo::getId, shopProductVo -> shopProductVo));
|
||||
List<Long> prodGroupIdList = groupList.stream().map(ShopGroupProductVo::getId).distinct().toList();
|
||||
|
||||
Reference in New Issue
Block a user