|
|
@@ -2,6 +2,7 @@ package com.cyksj.web.controller.manage.goods;
|
|
|
|
|
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.cyksj.common.annotation.Log;
|
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
@@ -24,6 +25,7 @@ import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
import java.util.Set;
|
|
|
|
|
|
@@ -58,8 +60,11 @@ public class CmsGoodsDonController {
|
|
|
* 商品详情
|
|
|
*/
|
|
|
@GetMapping("/get/{id}")
|
|
|
- public Result<GoodsDonViewer> getById(@PathVariable Long id) {
|
|
|
+ public Result<GoodsDonViewer> getById(@PathVariable Long id) throws Exception {
|
|
|
GoodsDonViewer goodsDonViewer = beanSearcher.searchFirst(GoodsDonViewer.class, MapUtils.builder().field(GoodsDonViewer::getId, id).build());
|
|
|
+ if (StrUtil.isNotBlank(goodsDonViewer.getRecommendGoods())) {
|
|
|
+ goodsDonViewer.setRecommendGoodsList(Jsons.parseList(goodsDonViewer.getRecommendGoods(), Long.class));
|
|
|
+ }
|
|
|
List<GoodsDonSku> goodsDonSkus = beanSearcher.searchAll(GoodsDonSku.class, MapUtils.builder().field(GoodsDonSku::getGoodsId, id).build());
|
|
|
goodsDonViewer.setSkus(goodsDonSkus);
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(goodsDonViewer);
|
|
|
@@ -85,12 +90,13 @@ public class CmsGoodsDonController {
|
|
|
GoodsDon goods = new GoodsDon();
|
|
|
BeanUtil.copyProperties(spu, goods);
|
|
|
if (StrUtil.isNotEmpty(goods.getRecommendTitle())) {
|
|
|
- if (StrUtil.isEmpty(spu.getRecommendGoods())) {
|
|
|
+ if (CollUtil.isEmpty(spu.getRecommendGoodsList())) {
|
|
|
throw BusinessRuntimeException.getInstance("请选择推荐的对应平台");
|
|
|
}
|
|
|
- String recommendGoods = spu.getRecommendGoods();
|
|
|
- Set<Long> goodsIds = Jsons.parseSet(recommendGoods, Long.class);
|
|
|
- goods.setRecommendGoods(Jsons.toJson(goodsIds));
|
|
|
+ Set<Long> re_goodsIds = new HashSet<>(spu.getRecommendGoodsList());
|
|
|
+ //去除自己
|
|
|
+ re_goodsIds.remove(spu.getId());
|
|
|
+ goods.setRecommendGoods(Jsons.toJson(re_goodsIds));
|
|
|
}
|
|
|
goodsDonService.save(goods);
|
|
|
Set<String> keys = redisService.keys(RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "*");
|
|
|
@@ -111,14 +117,13 @@ public class CmsGoodsDonController {
|
|
|
goods.setSpecialType(null);
|
|
|
}
|
|
|
if (StrUtil.isNotEmpty(goods.getRecommendTitle())) {
|
|
|
- if (StrUtil.isEmpty(spu.getRecommendGoods())) {
|
|
|
+ if (CollUtil.isEmpty(spu.getRecommendGoodsList())) {
|
|
|
throw BusinessRuntimeException.getInstance("请选择推荐的对应平台");
|
|
|
}
|
|
|
- String recommendGoods = spu.getRecommendGoods();
|
|
|
- Set<Long> goodsIds = Jsons.parseSet(recommendGoods, Long.class);
|
|
|
+ Set<Long> re_goodsIds = new HashSet<>(spu.getRecommendGoodsList());
|
|
|
//去除自己
|
|
|
- goodsIds.remove(spu.getId());
|
|
|
- goods.setRecommendGoods(Jsons.toJson(goodsIds));
|
|
|
+ re_goodsIds.remove(spu.getId());
|
|
|
+ goods.setRecommendGoods(Jsons.toJson(re_goodsIds));
|
|
|
}
|
|
|
if (StrUtil.isEmpty(goods.getRecommendTitle())) {
|
|
|
goods.setRecommendTitle(null);
|