ddd
parent
a516b738ca
commit
05b6e8c4f3
|
@ -12,16 +12,26 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
* 获取当前线程变量中的 用户id、用户名称、Token等信息
|
||||
* 注意: 必须在网关通过请求头的方法传入,同时在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));
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue