|
|
@@ -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();
|
|
|
}
|
|
|
|