递龟分类修改

This commit is contained in:
xuwenbo
2020-09-14 15:40:26 +08:00
parent e5937d1850
commit 53b7c4431b

View File

@ -17,6 +17,7 @@ import co.yixiang.logging.aop.log.Log;
import co.yixiang.modules.aop.ForbidSubmit; import co.yixiang.modules.aop.ForbidSubmit;
import co.yixiang.modules.category.domain.YxStoreCategory; import co.yixiang.modules.category.domain.YxStoreCategory;
import co.yixiang.modules.category.service.YxStoreCategoryService; import co.yixiang.modules.category.service.YxStoreCategoryService;
import co.yixiang.modules.category.service.dto.YxStoreCategoryDto;
import co.yixiang.modules.product.domain.YxStoreProduct; import co.yixiang.modules.product.domain.YxStoreProduct;
import co.yixiang.modules.product.domain.YxStoreProductAttrResult; import co.yixiang.modules.product.domain.YxStoreProductAttrResult;
import co.yixiang.modules.product.domain.YxStoreProductAttrValue; import co.yixiang.modules.product.domain.YxStoreProductAttrValue;
@ -34,6 +35,8 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.additional.query.impl.LambdaQueryChainWrapper;
import com.google.common.collect.Maps;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
@ -42,6 +45,7 @@ import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@ -51,13 +55,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -99,9 +97,9 @@ public class StoreProductController {
List<YxStoreCategory> storeCategories = yxStoreCategoryService.lambdaQuery() List<YxStoreCategory> storeCategories = yxStoreCategoryService.lambdaQuery()
.eq(YxStoreCategory::getIsShow, ShopCommonEnum.SHOW_1.getValue()) .eq(YxStoreCategory::getIsShow, ShopCommonEnum.SHOW_1.getValue())
.list(); .list();
List<Map<String,Object>> cateList = new ArrayList<>(); List<Map<String,Object>> cateList = new LinkedList<>();
Map<String, Object> queryAll = yxStoreProductService.queryAll(criteria, pageable); Map<String, Object> queryAll = yxStoreProductService.queryAll(criteria, pageable);
queryAll.put("cateList", this.makeCate(storeCategories,cateList,0,1)); queryAll.put("cateList", this.makeCate(cateList));
return new ResponseEntity<>(queryAll,HttpStatus.OK); return new ResponseEntity<>(queryAll,HttpStatus.OK);
} }
@ -162,14 +160,8 @@ public class StoreProductController {
List<YxShippingTemplates> shippingTemplatesList = yxShippingTemplatesService.list(); List<YxShippingTemplates> shippingTemplatesList = yxShippingTemplatesService.list();
map.put("tempList", shippingTemplatesList); map.put("tempList", shippingTemplatesList);
//商品分类 List<Map<String,Object>> cateList = new LinkedList<>();
List<YxStoreCategory> storeCategories = yxStoreCategoryService.lambdaQuery() map.put("cateList", this.makeCate(cateList));
.eq(YxStoreCategory::getIsShow, ShopCommonEnum.SHOW_1.getValue())
.orderByAsc(YxStoreCategory::getPid)
.list();
List<Map<String,Object>> cateList = new ArrayList<>();
map.put("cateList", this.makeCate(storeCategories,cateList,0,1));
//商品规格 //商品规格
map.put("ruleList",yxStoreProductRuleService.list()); map.put("ruleList",yxStoreProductRuleService.list());
@ -238,50 +230,34 @@ public class StoreProductController {
/** /**
* 分类递归 * 分类
* @param data 分类列表
* @param pid 附件id
* @param level d等级
* @return list * @return list
*/ */
private List<Map<String,Object>> makeCate(List<YxStoreCategory> data,List<Map<String,Object>> cateList,int pid, int level) private List<Map<String,Object>> makeCate(List<Map<String,Object>> cateList)
{ {
String html = "|-----"; String html = "|-----";
String newHtml = ""; List<YxStoreCategory> storeCategories = yxStoreCategoryService.lambdaQuery()
.eq(YxStoreCategory::getIsShow, ShopCommonEnum.SHOW_1.getValue())
for (int i = 0; i < data.size(); i++) { .eq(YxStoreCategory::getPid, 0)
YxStoreCategory storeCategory = data.get(i); .list();
int catePid = storeCategory.getPid(); for (YxStoreCategory storeCategory : storeCategories) {
Map<String,Object> map = new HashMap<>(); Map<String,Object> map = new HashMap<>();
if(catePid == pid){ map.put("value",storeCategory.getId());
newHtml = String.join("", Collections.nCopies(level,html)); map.put("label",html + html + storeCategory.getCateName());
map.put("value",storeCategory.getId()); map.put("disabled",0);
map.put("label",newHtml + storeCategory.getCateName()); cateList.add(map);
if(storeCategory.getPid() == 0){ List<YxStoreCategory> categoriesChild = yxStoreCategoryService.lambdaQuery()
map.put("disabled",0); .eq(YxStoreCategory::getIsShow, ShopCommonEnum.SHOW_1.getValue())
}else{ .eq(YxStoreCategory::getPid, storeCategory.getId()).list();
map.put("disabled",1); for (YxStoreCategory categoryChild : categoriesChild) {
} Map<String,Object> childMap = new HashMap<>();
cateList.add(map); childMap.put("value",categoryChild.getId());
data.remove(i); childMap.put("label",html + categoryChild.getCateName());
childMap.put("disabled",1);
i--; cateList.add(childMap);
if(storeCategory.getPid() > 0){
this.makeCate(data,cateList,storeCategory.getPid(),level);
}else{
this.makeCate(data,cateList,storeCategory.getId(),level + 1);
}
} }
} }
return cateList; return cateList;
} }
} }