product
Yunfei Du 2024-03-11 09:30:00 +08:00
parent a516b738ca
commit 05b6e8c4f3
4 changed files with 74 additions and 2 deletions

View File

@ -12,16 +12,26 @@ import java.util.concurrent.ConcurrentHashMap;
* 线 idToken
* HeaderInterceptor
*
* 线
*
* TransmittableThreadLocal 线
* 使 ConcurrentHashMap 线
*
*
*
* @author muyu
*/
public class SecurityContextHolder {
private static final TransmittableThreadLocal<Map<String, Object>> THREAD_LOCAL = new TransmittableThreadLocal<>();
public static void set (String key, Object value) {
Map<String, Object> map = getLocalMap();
map.put(key, value == null ? StringUtils.EMPTY : value);
}
public static String get (String key) {
Map<String, Object> map = getLocalMap();
return Convert.toStr(map.getOrDefault(key, StringUtils.EMPTY));

View File

@ -19,6 +19,8 @@ import java.io.Serializable;
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> implements Serializable {
/**
*
*/
@ -33,6 +35,7 @@ public class Result<T> implements Serializable {
public static final int WARN = HttpStatus.WARN;
private static final long serialVersionUID = 1L;
private int code;
private String msg;
@ -101,6 +104,8 @@ public class Result<T> implements Serializable {
.build();
}
public static <T> Boolean isError (Result<T> ret) {
return !isSuccess(ret);
}

View File

@ -5,6 +5,7 @@ import com.muyu.product.domain.AttributeGroup;
import com.muyu.product.domain.AttributeInfo;
import com.muyu.product.domain.BrandInfo;
import lombok.*;
import lombok.experimental.SuperBuilder;
import java.util.List;
@ -15,7 +16,7 @@ import java.util.List;
* @Date 2024/3/3 8:15
*/
@Data
@Builder
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@ -33,4 +34,5 @@ public class CategoryParentCommonElementResp extends BaseEntity {
*
*/
private List<BrandInfo> brandInfoList;
}

View File

@ -1,7 +1,10 @@
package com.muyu.product.service.impl;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Stream;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@ -284,6 +287,11 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
public CategoryCommonElementResp getTemplateAttributeByCateGoryId(Long cateGoryId) {
ArrayList< Long > cateGoryIdList = new ArrayList<> ( );
getParentIdListByCateGoryId(cateGoryIdList,cateGoryId);
// 取出和品类相关联的属性组关系 - 中间表
LambdaQueryWrapper<AsCategoryAttributeGroup> asCategoryAttributeGroupLambdaQueryWrapper = new LambdaQueryWrapper<>(){{
eq(AsCategoryAttributeGroup::getCategoryId, cateGoryId);
@ -304,12 +312,48 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
))
.filter(TemplateAttributeGroupModel::isEffective)
.toList();
Set< Long > attributeIdSet = new HashSet<> ( );
if (!attributeGroupModelList.isEmpty()){
attributeIdSet.addAll(
attributeGroupModelList.stream()
.flatMap((Function<TemplateAttributeGroupModel, Stream<TemplateAttributeModel>>) templateAttributeGroupModel -> templateAttributeGroupModel.getAttributeList().stream())
.map(TemplateAttributeModel::getId)
.toList()
);
}
List<TemplateAttributeModel> templateAttributeModelList = new ArrayList<>();
LambdaQueryWrapper< AsCategoryAttribute > categoryAttributeLambdaQueryWrapper = new LambdaQueryWrapper<> ( );
categoryAttributeLambdaQueryWrapper.in ( AsCategoryAttribute::getCategoryId,cateGoryIdList );
List< AsCategoryAttribute > list = asCategoryAttributeService.list ( categoryAttributeLambdaQueryWrapper );
if (list!=null && !list.isEmpty ()){
list.stream ()
.map ( AsCategoryAttribute::getAttributeId )
.filter ( templateAttributeId -> !attributeIdSet.contains ( templateAttributeId ) )
.toList ();
attributeInfoService.listByIds ( templateAttributeModelList ).stream ()
.map ( AttributeInfo::buildTemplateModel )
.toList ();
}
//
List<TemplateAttributeModel> attributeModelList = new ArrayList<>();
if (!templateAttributeModelList.isEmpty ()){
attributeIdSet.addAll (
templateAttributeModelList.stream ().map ( TemplateAttributeModel::getId ).toList ()
);
}
LambdaQueryWrapper< AttributeInfo > attributeInfoLambdaQueryWrapper = new LambdaQueryWrapper<> ( );
attributeInfoLambdaQueryWrapper.notIn ( !attributeIdSet.isEmpty (),AttributeInfo::getId,attributeIdSet );
attributeInfoService.list (attributeInfoLambdaQueryWrapper).stream ().map ( AttributeInfo::buildTemplateModel ).toList ();
return CategoryCommonElementResp.builder()
.templateAttributeGroupList(attributeGroupModelList)
.templateAttributeList(templateAttributeModelList)
@ -317,12 +361,23 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
.build();
}
private void getParentIdListByCateGoryId(List< Long> parentIdList, Long cateGoryId) {
if (cateGoryId.equals ( 0L )){
return;
}
CategoryInfo categoryInfo = this.getById ( cateGoryId );
parentIdList.add ( categoryInfo.getId () );
getParentIdListByCateGoryId ( parentIdList,categoryInfo.getParentId () );
}
@Override
public List< BrandInfo > getBrand(Long categoryId) {
return null;
}
@Override
public List< AttributeInfo > getAttribute(Long categoryId) {
return null;