zoujiajian 2 лет назад
Родитель
Сommit
425a10cd6b

+ 2 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/GoodsDonCategoryRelate.java

@@ -15,4 +15,6 @@ public class GoodsDonCategoryRelate extends BaseEntity{
 	private Long goodsId;
 
 	private Long category;
+
+	private Integer sorted;
 }

+ 1 - 0
netflix-dao/src/main/java/com/cyksj/model/views/GoodsDonCategoryDetailView.java

@@ -17,6 +17,7 @@ import java.util.Date;
 @Setter
 @SearchBean(tables = "goods_don g left join goods_don_category_relate gcr on gcr.goods_id = g.id" +
 		" left join goods_don_category gc on gc.id = gcr.category",
+		where = ":condition:",
 		groupBy = "g.id,g.title,g.status,g.deleted,g.logo,g.type,g.sort_by,g.virtual_sold,g.created_time,g.update_time")
 public class GoodsDonCategoryDetailView {
 	@DbField("g.id")

+ 6 - 4
netflix-dao/src/main/java/com/cyksj/model/views/GoodsDonCategoryGoodsView.java

@@ -16,16 +16,18 @@ import lombok.Setter;
 @Setter
 @SearchBean(tables = "goods_don g left join goods_don_category_relate gcr on gcr.goods_id = g.id" +
 		" left join goods_don_category gc on gc.id = gcr.category",
-		where = "g.deleted is true :category:",
-		groupBy = "g.id,g.title,g.status,g.sort_by")
+		where = "g.deleted is true and g.status is true")
 public class GoodsDonCategoryGoodsView {
 
 	@DbField("g.id")
 	private Long goodsId;
 
-	@DbField("group_concat(gc.name)")
+	@DbField("gc.name")
 	private String categoryName;
 
+	@DbField("gcr.category")
+	private Long category;
+
 	@DbField("g.title")
 	private String title;
 
@@ -41,6 +43,6 @@ public class GoodsDonCategoryGoodsView {
 	@DbIgnore
 	private Integer click;
 
-	@DbField("g.sort_by")
+	@DbField("gcr.sorted")
 	private Integer sorted;
 }

+ 126 - 0
netflix-dao/src/main/java/com/cyksj/model/views/GoodsFrontListCategoryView.java

@@ -0,0 +1,126 @@
+package com.cyksj.model.views;
+
+import com.cyksj.model.entity.GoodsDon;
+import com.ejlchina.searcher.bean.DbField;
+import com.ejlchina.searcher.bean.DbIgnore;
+import com.ejlchina.searcher.bean.SearchBean;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.math.BigDecimal;
+import java.util.List;
+
+/**
+ * 项目名: yhlxj2
+ * 文件名: GoodsFrontListCategoryView
+ * 创建者: JavaZou
+ * 创建时间:2023/10/12 14:40
+ */
+@Getter
+@Setter
+@SearchBean(tables = "goods_don g left join goods_don_category_relate gcr on gcr.goods_id = g.id",
+		where = "g.deleted is true and g.status is true :condition:",
+		orderBy = "gcr.sorted asc, g.id")
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class GoodsFrontListCategoryView {
+	@DbField("g.id")
+	private Long id;
+
+	/**
+	 * 商品名称
+	 */
+	@DbField("g.title")
+	private String title;
+
+	/**
+	 * 标签
+	 */
+	@DbField("g.tags")
+	private String tags;
+
+	/**
+	 * 缩略图
+	 */
+	@DbField("g.logo")
+	private String logo;
+
+	/**
+	 * 背景图
+	 */
+	@DbField("g.img")
+	private String img;
+
+	/**
+	 * 分类
+	 * 1、AI  2、流媒体
+	 */
+	@DbField("g.category")
+	private Long category;
+
+	/**
+	 * 类型
+	 */
+	@DbField("g.type")
+	private Integer type;
+
+	@DbField("g.second_type")
+	private Integer secondType;
+
+	@DbField("g.special_type")
+	private GoodsDon.SpecialType specialType;
+
+	/**
+	 * 最低规格价格
+	 */
+	@DbField("g.min_price")
+	private BigDecimal price;
+
+	/**
+	 * 最低规格月份
+	 */
+	@DbField("g.min_months")
+	private Integer months;
+
+	/**
+	 * 最低规格天数
+	 */
+	@DbField("g.min_days")
+	private Integer days;
+
+	/**
+	 * 已售
+	 */
+	@DbField("g.virtual_sold")
+	private Integer sold;
+
+	@DbIgnore
+	private BigDecimal specificPrice;
+
+	@DbIgnore
+	private Long specificSkuId;
+
+	@DbField("g.pay_desc")
+	private String payDesc;
+
+	/**
+	 * 是否是特定价格平台
+	 */
+	@DbField("g.is_sp")
+	private Boolean isSp;
+
+	/**
+	 * 购买通知信息
+	 */
+	@DbIgnore
+	private String notifyMsg;
+
+	@DbIgnore
+	private List<GoodsDonSkuFrontView> skuList;
+
+	@DbIgnore
+	private GoodsDonSpecFrontView specs;
+
+	@DbIgnore
+	private OrderCommentFrontView comments;
+}

+ 128 - 0
netflix-dao/src/main/java/com/cyksj/model/views/YhShopGoodsFrontCategoryView.java

@@ -0,0 +1,128 @@
+package com.cyksj.model.views;
+
+import com.cyksj.model.entity.GoodsDon;
+import com.ejlchina.searcher.bean.DbField;
+import com.ejlchina.searcher.bean.DbIgnore;
+import com.ejlchina.searcher.bean.SearchBean;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.math.BigDecimal;
+import java.util.List;
+
+/**
+ * 项目名: yhlxj2
+ * 文件名: YhShopGoodsFrontCategoryView
+ * 创建者: JavaZou
+ * 创建时间:2023/10/12 14:44
+ */
+@Getter
+@Setter
+@SearchBean(tables = "(select ys.goods_id,min(ys.price) as price from yh_shop_goods_sku ys left join goods_don_sku sku on sku.id = ys.sku_id where sku.status is true and ys.status is true and ys.deleted is true :yhsId: group by ys.goods_id) yg" +
+		" inner join goods_don g on g.id = yg.goods_id" +
+		" left join goods_don_category_relate gcr on gcr.goods_id = g.id",
+		where = "g.deleted is true and g.status is true and g.is_distribute is true :condition:",
+		orderBy = "gcr.sorted asc, g.id")
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class YhShopGoodsFrontCategoryView {
+	@DbField("g.id")
+	private Long id;
+
+	/**
+	 * 商品名称
+	 */
+	@DbField("g.title")
+	private String title;
+
+	/**
+	 * 标签
+	 */
+	@DbField("g.tags")
+	private String tags;
+
+	/**
+	 * 缩略图
+	 */
+	@DbField("g.logo")
+	private String logo;
+
+	/**
+	 * 背景图
+	 */
+	@DbField("g.img")
+	private String img;
+
+	/**
+	 * 类型
+	 */
+	@DbField("g.type")
+	private Integer type;
+
+	/**
+	 * 分类
+	 * 1、AI  2、流媒体
+	 */
+	@DbField("gcr.category")
+	private Long category;
+
+	@DbField("g.second_type")
+	private Integer secondType;
+
+	@DbField("g.special_type")
+	private GoodsDon.SpecialType specialType;
+
+	/**
+	 * 店铺最低规格价格
+	 */
+	@DbField("yg.price")
+	private BigDecimal price;
+
+	/**
+	 * 最低规格月份
+	 */
+	@DbField("g.min_months")
+	private Integer months;
+
+	/**
+	 * 最低规格天数
+	 */
+	@DbField("g.min_days")
+	private Integer days;
+
+	/**
+	 * 已售
+	 */
+	@DbField("g.virtual_sold")
+	private Integer sold;
+
+	@DbIgnore
+	private BigDecimal specificPrice;
+
+	@DbIgnore
+	private Long specificSkuId;
+
+	@DbField("g.pay_desc")
+	private String payDesc;
+
+	/**
+	 * 是否是特定价格平台
+	 */
+	@DbField("g.is_sp")
+	private Boolean isSp;
+
+	/**
+	 * 购买通知信息
+	 */
+	@DbIgnore
+	private String notifyMsg;
+
+	@DbIgnore
+	private List<YhShopGoodsSkuFrontView> skuList;
+
+	@DbIgnore
+	private GoodsDonSpecFrontView specs;
+
+	@DbIgnore
+	private OrderCommentFrontView comments;
+}

+ 13 - 0
netflix-service/src/main/java/com/cyksj/service/mange/GoodsDonCategoryRelateService.java

@@ -0,0 +1,13 @@
+package com.cyksj.service.mange;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.cyksj.model.entity.GoodsDonCategoryRelate;
+
+/**
+ * 项目名: yhlxj2
+ * 文件名: GoodsDonCategoryRelateService
+ * 创建者: JavaZou
+ * 创建时间:2023/10/12 14:34
+ */
+public interface GoodsDonCategoryRelateService extends IService<GoodsDonCategoryRelate> {
+}

+ 19 - 0
netflix-service/src/main/java/com/cyksj/service/mange/goods/GoodsDonCategoryRelateServiceImpl.java

@@ -0,0 +1,19 @@
+package com.cyksj.service.mange.goods;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.cyksj.mapper.GoodsDonCategoryRelateMapper;
+import com.cyksj.model.entity.GoodsDonCategoryRelate;
+import com.cyksj.service.mange.GoodsDonCategoryRelateService;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Service;
+
+/**
+ * 项目名: yhlxj2
+ * 文件名: GoodsDonCategoryRelateServiceImpl
+ * 创建者: JavaZou
+ * 创建时间:2023/10/12 14:34
+ */
+@Service
+@RequiredArgsConstructor
+public class GoodsDonCategoryRelateServiceImpl extends ServiceImpl<GoodsDonCategoryRelateMapper, GoodsDonCategoryRelate> implements GoodsDonCategoryRelateService {
+}

+ 10 - 9
netflix-web/src/main/java/com/cyksj/web/controller/goods/GoodsDonController.java

@@ -793,7 +793,7 @@ public class GoodsDonController {
 	@GetMapping("/get/categoryGoods")
 	public Result<? extends Object> getGoodsByCategory(Long cgy, String customId) {
 		if (StrUtil.isNotBlank(customId)) {
-			Result<List<YhShopGoodsFrontView>> shopGoods = getShopCategoryGoods(yhShopFrontService.getYhsIdByCustomId(customId), cgy);
+			Result<List<YhShopGoodsFrontCategoryView>> shopGoods = getShopCategoryGoods(yhShopFrontService.getYhsIdByCustomId(customId), cgy);
 			return shopGoods;
 		}
 		String categoryGoodsKey = RedisService.key.YH_HOME_PAGHE_CACHE.getEnvName() + "category:goods";
@@ -804,14 +804,14 @@ public class GoodsDonController {
 		if (o == null) {
 			MapBuilder mapBuilder = MapUtils.flatBuilder(request.getParameterMap());
 			if (cgy != null) {
-				String condition = String.format(" and id in (select goods_id from goods_don_category_relate where category = %s)", cgy);
+				String condition = String.format(" and gcr.category = %s", cgy);
 				mapBuilder.put("condition", condition);
 			}
-			List<GoodsFrontListView> goodsFrontListViews = beanSearcher.searchAll(GoodsFrontListView.class, mapBuilder.build());
+			List<GoodsFrontListCategoryView> goodsFrontListViews = beanSearcher.searchAll(GoodsFrontListCategoryView.class, mapBuilder.build());
 			redisService.setNx(categoryGoodsKey, goodsFrontListViews, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + 10 * 60);
 			o = redisService.get(categoryGoodsKey);
 		}
-		List<GoodsFrontListView> goodsFrontListViews = Jsons.parseList(o, GoodsFrontListView.class);
+		List<GoodsFrontListCategoryView> goodsFrontListViews = Jsons.parseList(o, GoodsFrontListCategoryView.class);
 		DateTime now = DateTime.now();
 		goodsFrontListViews.forEach(data -> {
 			Integer sold = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
@@ -823,7 +823,7 @@ public class GoodsDonController {
 	}
 
 	@GetMapping("/get/shop/categoryGoods/{yhsId}")
-	public Result<List<YhShopGoodsFrontView>> getShopCategoryGoods(@PathVariable Long yhsId, Long category) {
+	public Result<List<YhShopGoodsFrontCategoryView>> getShopCategoryGoods(@PathVariable Long yhsId, Long category) {
 		String categoryGoodsKey = RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getEnvName() + yhsId + ":category";
 		if (category != null) {
 			categoryGoodsKey += ":" + category;
@@ -831,16 +831,17 @@ public class GoodsDonController {
 		Object value = redisService.get(categoryGoodsKey);
 		if (value == null) {
 			MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
-			String condition = String.format("and yhs_id = %s", yhsId);
+			builder.put("yhsId", String.format(" and yhs_id = %s", yhsId));
+			String condition = StrUtil.EMPTY;
 			if (category != null) {
-				condition += String.format(" and ys.goods_id in (select goods_id from goods_don_category_relate where category = %s)", category);
+				condition += String.format(" and gcr.category = %s", category);
 			}
 			builder.put("condition", condition);
-			List<YhShopGoodsFrontView> list = beanSearcher.searchAll(YhShopGoodsFrontView.class, builder.build());
+			List<YhShopGoodsFrontCategoryView> list = beanSearcher.searchAll(YhShopGoodsFrontCategoryView.class, builder.build());
 			redisService.setNx(categoryGoodsKey, list, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + 5 * 60);
 			value = redisService.get(categoryGoodsKey);
 		}
-		List<YhShopGoodsFrontView> list = Jsons.parseList(value, YhShopGoodsFrontView.class);
+		List<YhShopGoodsFrontCategoryView> list = Jsons.parseList(value, YhShopGoodsFrontCategoryView.class);
 		DateTime now = DateTime.now();
 		list.forEach(data -> {
 			Integer sold = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)

+ 25 - 12
netflix-web/src/main/java/com/cyksj/web/controller/manage/goods/CmsGoodsDonCategoryController.java

@@ -1,5 +1,6 @@
 package com.cyksj.web.controller.manage.goods;
 
+import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.lang.Assert;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.cyksj.common.exception.BusinessRuntimeException;
@@ -9,10 +10,12 @@ import com.cyksj.mapper.GoodsClickUserRecordMapper;
 import com.cyksj.model.entity.GoodsClickUserRecord;
 import com.cyksj.model.entity.GoodsDon;
 import com.cyksj.model.entity.GoodsDonCategory;
+import com.cyksj.model.entity.GoodsDonCategoryRelate;
 import com.cyksj.model.views.GoodsDonCategoryGoodsView;
 import com.cyksj.model.views.GoodsDonCategoryView;
 import com.cyksj.redis.RedisService;
 import com.cyksj.service.mange.CmsGoodsDonService;
+import com.cyksj.service.mange.GoodsDonCategoryRelateService;
 import com.cyksj.service.mange.GoodsDonCategoryService;
 import com.ejlchina.searcher.BeanSearcher;
 import com.ejlchina.searcher.SearchResult;
@@ -23,6 +26,7 @@ import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Set;
 
@@ -46,6 +50,8 @@ public class CmsGoodsDonCategoryController {
 
 	private final CmsGoodsDonService goodsDonService;
 
+	private final GoodsDonCategoryRelateService goodsDonCategoryRelateService;
+
 	private final RedisService redisService;
 
 	/**
@@ -133,11 +139,8 @@ public class CmsGoodsDonCategoryController {
 	 * 分类平台列表
 	 */
 	@GetMapping("/get/goods")
-	public Result<SearchResult<GoodsDonCategoryGoodsView>> getCategoryGoodsView(Long category) {
+	public Result<SearchResult<GoodsDonCategoryGoodsView>> getCategoryGoodsView() {
 		MapBuilder mapBuilder = MapUtils.flatBuilder(request.getParameterMap());
-		if (category != null) {
-			mapBuilder.put("category", String.format(" and gcr.category = %s", category));
-		}
 		SearchResult<GoodsDonCategoryGoodsView> search = beanSearcher.search(GoodsDonCategoryGoodsView.class, mapBuilder.build());
 		search.getDataList().forEach(data->{
 			Integer count = goodsClickUserRecordMapper.selectCount(Wrappers.lambdaQuery(GoodsClickUserRecord.class)
@@ -151,15 +154,25 @@ public class CmsGoodsDonCategoryController {
 	 * 修改平台排序
 	 */
 	@PutMapping("/sort/goods")
-	public Result<String> sortGoods(@RequestBody GoodsDonCategoryGoodsView request) {
-		Long goodsId = request.getGoodsId();
-		Integer sorted = request.getSorted();
-		Assert.notNull(goodsId, "平台不存在");
-		GoodsDon byId = goodsDonService.getById(goodsId);
-		if (request.getSorted() != null) {
-			byId.setSortBy(sorted);
-			goodsDonService.updateById(byId);
+	public Result<String> sortGoods(@RequestBody List<GoodsDonCategoryGoodsView> request) {
+		List<GoodsDonCategoryRelate> updateList = new ArrayList<>(request.size());
+		request.forEach(data->{
+			Long goodsId = data.getGoodsId();
+			Integer sorted = data.getSorted();
+			GoodsDonCategoryRelate relate = goodsDonCategoryRelateService.getOne(Wrappers.lambdaQuery(GoodsDonCategoryRelate.class)
+					.eq(GoodsDonCategoryRelate::getCategory, data.getCategory())
+					.eq(GoodsDonCategoryRelate::getGoodsId, goodsId).last("limit 1"));
+			if (sorted != null && sorted != relate.getSorted()) {
+				relate.setSorted(sorted);
+				updateList.add(relate);
+			}
+		});
+		if (CollUtil.isNotEmpty(updateList)) {
+			goodsDonCategoryRelateService.updateBatchById(updateList);
+			Set<String> keys = redisService.keys(RedisService.key.YH_HOME_PAGHE_CACHE.getEnvName() + "*");
+			redisService.del(keys.toArray(String[]::new));
 		}
+
 		return GatewayResponse.SUCCESS.newBuilder().toResult();
 	}