|
@@ -9,15 +9,16 @@ import com.cyksj.common.util.Jsons;
|
|
|
import com.cyksj.dto.Result;
|
|
import com.cyksj.dto.Result;
|
|
|
import com.cyksj.enums.BusinessType;
|
|
import com.cyksj.enums.BusinessType;
|
|
|
import com.cyksj.enums.GatewayResponse;
|
|
import com.cyksj.enums.GatewayResponse;
|
|
|
-import com.cyksj.model.entity.GoodsDiscountPlusPurchaseRelation;
|
|
|
|
|
import com.cyksj.model.entity.GoodsDon;
|
|
import com.cyksj.model.entity.GoodsDon;
|
|
|
import com.cyksj.model.entity.GoodsDonSku;
|
|
import com.cyksj.model.entity.GoodsDonSku;
|
|
|
import com.cyksj.model.manage.request.ReqGoodsSpuInsert;
|
|
import com.cyksj.model.manage.request.ReqGoodsSpuInsert;
|
|
|
import com.cyksj.model.manage.views.GoodsDonViewer;
|
|
import com.cyksj.model.manage.views.GoodsDonViewer;
|
|
|
-import com.cyksj.redis.RedisService;
|
|
|
|
|
import com.cyksj.service.mange.CmsGoodsDonService;
|
|
import com.cyksj.service.mange.CmsGoodsDonService;
|
|
|
|
|
+import com.cyksj.service.mange.RefreshCacheService;
|
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
|
import com.ejlchina.searcher.SearchResult;
|
|
import com.ejlchina.searcher.SearchResult;
|
|
|
|
|
+import com.ejlchina.searcher.param.Operator;
|
|
|
|
|
+import com.ejlchina.searcher.util.MapBuilder;
|
|
|
import com.ejlchina.searcher.util.MapUtils;
|
|
import com.ejlchina.searcher.util.MapUtils;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -40,13 +41,13 @@ import java.util.Set;
|
|
|
@RequestMapping("/manage/goods")
|
|
@RequestMapping("/manage/goods")
|
|
|
public class CmsGoodsDonController {
|
|
public class CmsGoodsDonController {
|
|
|
|
|
|
|
|
- private final HttpServletRequest request;
|
|
|
|
|
|
|
+ private final HttpServletRequest request;
|
|
|
|
|
|
|
|
- private final BeanSearcher beanSearcher;
|
|
|
|
|
|
|
+ private final BeanSearcher beanSearcher;
|
|
|
|
|
|
|
|
- private final CmsGoodsDonService goodsDonService;
|
|
|
|
|
|
|
+ private final CmsGoodsDonService goodsDonService;
|
|
|
|
|
|
|
|
- private final RedisService redisService;
|
|
|
|
|
|
|
+ private final RefreshCacheService refreshCacheService;
|
|
|
|
|
|
|
|
@GetMapping("/get")
|
|
@GetMapping("/get")
|
|
|
public Result<SearchResult<GoodsDon>> get(){
|
|
public Result<SearchResult<GoodsDon>> get(){
|
|
@@ -56,135 +57,136 @@ public class CmsGoodsDonController {
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 商品详情
|
|
|
|
|
- */
|
|
|
|
|
- @GetMapping("/get/{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());
|
|
|
|
|
- if (goodsDonViewer.getType() == 1) {
|
|
|
|
|
- goodsDonSkus.forEach(sku -> {
|
|
|
|
|
- if (sku.getIsDp()) {
|
|
|
|
|
- sku.setDpSku(beanSearcher.searchAll(GoodsDiscountPlusPurchaseRelation.class, MapUtils.builder()
|
|
|
|
|
- .field(GoodsDiscountPlusPurchaseRelation::getSkuId, sku.getId())
|
|
|
|
|
- .build()));
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
- goodsDonViewer.setSkus(goodsDonSkus);
|
|
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult(goodsDonViewer);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 商品规格详情
|
|
|
|
|
- */
|
|
|
|
|
- @GetMapping("/get/sku/{id}")
|
|
|
|
|
- public Result<List<GoodsDonSku>> getSkuById(@PathVariable Long id, HttpServletRequest request) {
|
|
|
|
|
- List<GoodsDonSku> goodsDonSkus = beanSearcher.searchAll(GoodsDonSku.class, MapUtils.flatBuilder(request.getParameterMap()).field(GoodsDonSku::getGoodsId, id).build());
|
|
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult(goodsDonSkus);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 新增 商品spu
|
|
|
|
|
- */
|
|
|
|
|
- @PostMapping(value = "/post")
|
|
|
|
|
- @Log(module = "平台管理/新增平台", businessType = BusinessType.POST, isSaveRequestData = true)
|
|
|
|
|
- public Result<Long> spuInsert(@Validated @RequestBody ReqGoodsSpuInsert spu) throws Exception {
|
|
|
|
|
- // 新增商品
|
|
|
|
|
- GoodsDon goods = new GoodsDon();
|
|
|
|
|
- BeanUtil.copyProperties(spu, goods);
|
|
|
|
|
- if (StrUtil.isNotEmpty(goods.getRecommendTitle())) {
|
|
|
|
|
- if (CollUtil.isEmpty(spu.getRecommendGoodsList())) {
|
|
|
|
|
- throw BusinessRuntimeException.getInstance("请选择推荐的对应平台");
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- goodsDonService.save(goods);
|
|
|
|
|
- Set<String> keys = redisService.keys(RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "*");
|
|
|
|
|
- redisService.del(keys.toArray(String[]::new));
|
|
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult(goods.getId());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 修改 商品spu
|
|
|
|
|
- */
|
|
|
|
|
- @PutMapping(value = "/update")
|
|
|
|
|
- @Log(module = "平台管理/编辑平台", businessType = BusinessType.PUT, isSaveRequestData = true)
|
|
|
|
|
- public Result<String> spuUpdate(@Validated @RequestBody ReqGoodsSpuInsert spu) throws Exception{
|
|
|
|
|
- GoodsDon goods = new GoodsDon();
|
|
|
|
|
- BeanUtil.copyProperties(spu,goods);
|
|
|
|
|
- if (spu.getSpecialType() == null) {
|
|
|
|
|
- goods.setSpecialType(null);
|
|
|
|
|
- }
|
|
|
|
|
- if (StrUtil.isNotEmpty(goods.getRecommendTitle())) {
|
|
|
|
|
- if (CollUtil.isEmpty(spu.getRecommendGoodsList())) {
|
|
|
|
|
- throw BusinessRuntimeException.getInstance("请选择推荐的对应平台");
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- if (CollUtil.isNotEmpty(spu.getRecommendGoodsList())) {
|
|
|
|
|
- Set<Long> re_goodsIds = new HashSet<>(spu.getRecommendGoodsList());
|
|
|
|
|
- //去除自己
|
|
|
|
|
- re_goodsIds.remove(spu.getId());
|
|
|
|
|
- goods.setRecommendGoods(Jsons.toJson(re_goodsIds));
|
|
|
|
|
- }
|
|
|
|
|
- if (StrUtil.isEmpty(goods.getRecommendTitle())) {
|
|
|
|
|
- goods.setRecommendTitle(null);
|
|
|
|
|
- }
|
|
|
|
|
- if (StrUtil.isEmpty(goods.getVideo())) {
|
|
|
|
|
- goods.setVideo(null);
|
|
|
|
|
- }
|
|
|
|
|
- if (CollUtil.isNotEmpty(spu.getRecommendGoodsList())) {
|
|
|
|
|
- Set<Long> re_goodsIds = new HashSet<>(spu.getRecommendGoodsList());
|
|
|
|
|
- //去除自己
|
|
|
|
|
- re_goodsIds.remove(spu.getId());
|
|
|
|
|
- goods.setRecommendGoods(Jsons.toJson(re_goodsIds));
|
|
|
|
|
- }
|
|
|
|
|
- goodsDonService.updateById(goods);
|
|
|
|
|
- Set<String> keys = redisService.keys(RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "*");
|
|
|
|
|
- redisService.del(keys.toArray(String[]::new));
|
|
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- @PutMapping("/put/status/{id}")
|
|
|
|
|
- @Log(module = "平台管理/平台上下架", businessType = BusinessType.PUT, isSaveRequestData = true, isSaveResponseData = true)
|
|
|
|
|
- public Result<Boolean> updateStatus(@PathVariable Long id) {
|
|
|
|
|
- GoodsDon goods = goodsDonService.getById(id);
|
|
|
|
|
- if (goods == null) {
|
|
|
|
|
- throw BusinessRuntimeException.getInstance("平台不存在");
|
|
|
|
|
- }
|
|
|
|
|
- goods.setStatus(!goods.getStatus());
|
|
|
|
|
- goodsDonService.updateById(goods);
|
|
|
|
|
- Set<String> keys = redisService.keys(RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "*");
|
|
|
|
|
- redisService.del(keys.toArray(String[]::new));
|
|
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult(goods.getStatus());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @DeleteMapping("/delete/{id}")
|
|
|
|
|
- @Log(module = "平台管理/删除平台", businessType = BusinessType.DELETE, isSaveRequestData = true, isSaveResponseData = true)
|
|
|
|
|
- public Result<Long> deleteById(@PathVariable Long id) {
|
|
|
|
|
- GoodsDon goods = goodsDonService.getById(id);
|
|
|
|
|
- if (goods == null) {
|
|
|
|
|
- throw BusinessRuntimeException.getInstance("平台不存在");
|
|
|
|
|
- }
|
|
|
|
|
- goods.setDeleted(false);
|
|
|
|
|
- goodsDonService.updateById(goods);
|
|
|
|
|
- Set<String> keys = redisService.keys(RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "*");
|
|
|
|
|
- redisService.del(keys.toArray(String[]::new));
|
|
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult(id);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 获取所有平台列表
|
|
|
|
|
- */
|
|
|
|
|
- @GetMapping("/get/all")
|
|
|
|
|
- public Result<List<GoodsDon>> getAllGoodsList() {
|
|
|
|
|
- List<GoodsDon> goodsDons = beanSearcher.searchAll(GoodsDon.class, MapUtils.flatBuilder(request.getParameterMap())
|
|
|
|
|
- .field(GoodsDon::getDeleted,true)
|
|
|
|
|
- .onlySelect(GoodsDon::getId, GoodsDon::getCategory, GoodsDon::getType, GoodsDon::getTitle).build());
|
|
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult(goodsDons);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 商品详情
|
|
|
|
|
+ */
|
|
|
|
|
+ @GetMapping("/get/{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));
|
|
|
|
|
+ }
|
|
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(goodsDonViewer);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 商品规格详情
|
|
|
|
|
+ */
|
|
|
|
|
+ @GetMapping("/get/sku/{id}")
|
|
|
|
|
+ public Result<List<GoodsDonSku>> getSkuById(@PathVariable Long id, HttpServletRequest request) {
|
|
|
|
|
+ List<GoodsDonSku> goodsDonSkus = beanSearcher.searchAll(GoodsDonSku.class, MapUtils.flatBuilder(request.getParameterMap()).field(GoodsDonSku::getGoodsId, id)
|
|
|
|
|
+ .orderBy(GoodsDonSku::getSorted).asc()
|
|
|
|
|
+ .build());
|
|
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(goodsDonSkus);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 新增 商品spu
|
|
|
|
|
+ */
|
|
|
|
|
+ @PostMapping(value = "/post")
|
|
|
|
|
+ @Log(module = "平台管理/新增平台", businessType = BusinessType.POST, isSaveRequestData = true)
|
|
|
|
|
+ public Result<Long> spuInsert(@Validated @RequestBody ReqGoodsSpuInsert spu) throws Exception {
|
|
|
|
|
+ // 新增商品
|
|
|
|
|
+ GoodsDon goods = new GoodsDon();
|
|
|
|
|
+ if (spu.getSecondType() == null) {
|
|
|
|
|
+ spu.setSecondType(2);
|
|
|
|
|
+ }
|
|
|
|
|
+ BeanUtil.copyProperties(spu, goods);
|
|
|
|
|
+ if (StrUtil.isNotEmpty(goods.getRecommendTitle())) {
|
|
|
|
|
+ if (CollUtil.isEmpty(spu.getRecommendGoodsList())) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("请选择推荐的对应平台");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ goodsDonService.save(goods);
|
|
|
|
|
+ refreshCacheService.refreshYhHomePageCache();
|
|
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(goods.getId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 修改 商品spu
|
|
|
|
|
+ */
|
|
|
|
|
+ @PutMapping(value = "/update")
|
|
|
|
|
+ @Log(module = "平台管理/编辑平台", businessType = BusinessType.PUT, isSaveRequestData = true)
|
|
|
|
|
+ public Result<String> spuUpdate(@Validated @RequestBody ReqGoodsSpuInsert spu) throws Exception{
|
|
|
|
|
+ GoodsDon goods = new GoodsDon();
|
|
|
|
|
+ BeanUtil.copyProperties(spu,goods);
|
|
|
|
|
+ if (spu.getSpecialType() == null) {
|
|
|
|
|
+ goods.setSpecialType(null);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StrUtil.isNotEmpty(goods.getRecommendTitle())) {
|
|
|
|
|
+ if (CollUtil.isEmpty(spu.getRecommendGoodsList())) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("请选择推荐的对应平台");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (CollUtil.isNotEmpty(spu.getRecommendGoodsList())) {
|
|
|
|
|
+ Set<Long> re_goodsIds = new HashSet<>(spu.getRecommendGoodsList());
|
|
|
|
|
+ //去除自己
|
|
|
|
|
+ re_goodsIds.remove(spu.getId());
|
|
|
|
|
+ goods.setRecommendGoods(Jsons.toJson(re_goodsIds));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StrUtil.isEmpty(goods.getRecommendTitle())) {
|
|
|
|
|
+ goods.setRecommendTitle(null);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StrUtil.isEmpty(goods.getVideo())) {
|
|
|
|
|
+ goods.setVideo(null);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (CollUtil.isNotEmpty(spu.getRecommendGoodsList())) {
|
|
|
|
|
+ Set<Long> re_goodsIds = new HashSet<>(spu.getRecommendGoodsList());
|
|
|
|
|
+ //去除自己
|
|
|
|
|
+ re_goodsIds.remove(spu.getId());
|
|
|
|
|
+ goods.setRecommendGoods(Jsons.toJson(re_goodsIds));
|
|
|
|
|
+ }
|
|
|
|
|
+ goodsDonService.updateById(goods);
|
|
|
|
|
+ refreshCacheService.refreshYhHomePageCache();
|
|
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @PutMapping("/put/status/{id}")
|
|
|
|
|
+ @Log(module = "平台管理/平台上下架", businessType = BusinessType.PUT, isSaveRequestData = true, isSaveResponseData = true)
|
|
|
|
|
+ public Result<Boolean> updateStatus(@PathVariable Long id) {
|
|
|
|
|
+ GoodsDon goods = goodsDonService.getById(id);
|
|
|
|
|
+ if (goods == null) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("平台不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ goods.setStatus(!goods.getStatus());
|
|
|
|
|
+ goodsDonService.updateById(goods);
|
|
|
|
|
+ refreshCacheService.refreshYhHomePageCache();
|
|
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(goods.getStatus());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @DeleteMapping("/delete/{id}")
|
|
|
|
|
+ @Log(module = "平台管理/删除平台", businessType = BusinessType.DELETE, isSaveRequestData = true, isSaveResponseData = true)
|
|
|
|
|
+ public Result<Long> deleteById(@PathVariable Long id) {
|
|
|
|
|
+ GoodsDon goods = goodsDonService.getById(id);
|
|
|
|
|
+ if (goods == null) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("平台不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ goods.setDeleted(false);
|
|
|
|
|
+ goodsDonService.updateById(goods);
|
|
|
|
|
+ refreshCacheService.refreshYhHomePageCache();
|
|
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(id);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取所有平台列表
|
|
|
|
|
+ */
|
|
|
|
|
+ @GetMapping("/get/all")
|
|
|
|
|
+ public Result<List<GoodsDon>> getAllGoodsList(Boolean isNoBuyout) {
|
|
|
|
|
+ MapBuilder mapBuilder = MapUtils.flatBuilder(request.getParameterMap());
|
|
|
|
|
+ //过滤买断制 平台
|
|
|
|
|
+ String conditionSql;
|
|
|
|
|
+ if (isNoBuyout != null && isNoBuyout) {
|
|
|
|
|
+ mapBuilder.field(GoodsDon::getSpecialType).op(Operator.IsNull);
|
|
|
|
|
+ conditionSql = "(select count(*) from goods_don_sku sku where sku.goods_id = g.id and sku.months = 300) = 0";
|
|
|
|
|
+ } else {
|
|
|
|
|
+ conditionSql = "(special_type is null or special_type != 'giftCard')";
|
|
|
|
|
+ }
|
|
|
|
|
+ conditionSql += " and exists (select id from goods_don_sku sku where sku.goods_id = g.id limit 1)";
|
|
|
|
|
+ List<GoodsDon> goodsDons = beanSearcher.searchAll(GoodsDon.class, mapBuilder
|
|
|
|
|
+ .put("condition", conditionSql)
|
|
|
|
|
+ .field(GoodsDon::getDeleted, true)
|
|
|
|
|
+ .onlySelect(GoodsDon::getId, GoodsDon::getCategory, GoodsDon::getType, GoodsDon::getTitle, GoodsDon::getSecondType).build());
|
|
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(goodsDons);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|