规格新增

master
hbr 2024-03-09 14:08:59 +08:00
parent 90ec9846a3
commit 0b98947165
5 changed files with 46 additions and 39 deletions

View File

@ -23,6 +23,10 @@ public class RuleInfoEditReq extends BaseEntity {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** 规格名称 */
@ApiModelProperty(name = "主键", value = "主键")
private Integer id;
/** 规格名称 */ /** 规格名称 */
@ApiModelProperty(name = "规格名称", value = "规格名称") @ApiModelProperty(name = "规格名称", value = "规格名称")
private String name; private String name;
@ -31,4 +35,7 @@ public class RuleInfoEditReq extends BaseEntity {
@ApiModelProperty(name = "规格状态", value = "规格状态") @ApiModelProperty(name = "规格状态", value = "规格状态")
private String status; private String status;
@ApiModelProperty(name = "规格备注", value = "规格备注")
private String remark;
} }

View File

@ -36,6 +36,8 @@ import com.muyu.common.core.web.page.TableDataInfo;
@RestController @RestController
@RequestMapping("/attribute") @RequestMapping("/attribute")
public class AttributeInfoController extends BaseController { public class AttributeInfoController extends BaseController {
@Autowired @Autowired
private AttributeInfoService attributeInfoService; private AttributeInfoService attributeInfoService;
@ -83,7 +85,8 @@ public class AttributeInfoController extends BaseController {
@PostMapping @PostMapping
@ApiOperation("新增商品属性") @ApiOperation("新增商品属性")
public Result<String> add(@RequestBody AttributeInfoSaveReq attributeInfoSaveReq) { public Result<String> add(@RequestBody AttributeInfoSaveReq attributeInfoSaveReq) {
return toAjax(attributeInfoService.save(AttributeInfo.saveBuild(attributeInfoSaveReq))); AttributeInfo attributeInfo = AttributeInfo.saveBuild(attributeInfoSaveReq);
return attributeInfoService.save(attributeInfo) ? success(attributeInfo.getId()) : error();
} }
/** /**

View File

@ -40,10 +40,6 @@ public class AsAttributeGroupServiceImpl extends ServiceImpl<AsAttributeGroupMap
queryWrapper.eq(AsAttributeGroup::getAttributeId, asAttributeGroup.getAttributeId()); queryWrapper.eq(AsAttributeGroup::getAttributeId, asAttributeGroup.getAttributeId());
} }
return list(queryWrapper); return list(queryWrapper);
} }
} }

View File

@ -299,74 +299,75 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
*/ */
@Override @Override
public CategoryCommonElementResp getTemplateAttributeByCateGoryId (Long cateGoryId) { public CategoryCommonElementResp getTemplateAttributeByCateGoryId (Long cateGoryId) {
ArrayList<Long> cateGoryIdList = new ArrayList<>(); List<Long> cateGoryIdList = new ArrayList<>();
getParentIdListByCateGoryId(cateGoryIdList,cateGoryId); getParentIdListByCateGoryId(cateGoryIdList, cateGoryId);
LambdaQueryWrapper<AsCategoryAttributeGroup> asCategoryAttributeGroupLambdaQueryWrapper = new LambdaQueryWrapper<>() {{ // 取出和品类相关联的属性组关系 - 中间表
LambdaQueryWrapper<AsCategoryAttributeGroup> asCategoryAttributeGroupLambdaQueryWrapper = new LambdaQueryWrapper<>(){{
in(AsCategoryAttributeGroup::getCategoryId, cateGoryIdList); in(AsCategoryAttributeGroup::getCategoryId, cateGoryIdList);
}}; }};
List<AsCategoryAttributeGroup> categoryAttributeGroupList = asCategoryAttributeGroupService.list(asCategoryAttributeGroupLambdaQueryWrapper); List<AsCategoryAttributeGroup> categoryAttributeGroupList = asCategoryAttributeGroupService.list(asCategoryAttributeGroupLambdaQueryWrapper);
List<TemplateAttributeGroupModel> attributeGroupModelList = categoryAttributeGroupList.stream() List<TemplateAttributeGroupModel> attributeGroupModelList = categoryAttributeGroupList.stream()
.map(asCategoryAttributeGroup -> TemplateAttributeGroupModel.attributeGroupBuild( .map(asCategoryAttributeGroup -> TemplateAttributeGroupModel.attributeGroupBuild(
attributeGroupService.getById(asCategoryAttributeGroup.getAttributeGroupId()), attributeGroupService.getById(asCategoryAttributeGroup.getAttributeGroupId()),
attributeGroupId -> { attributeGroupId -> {
LambdaQueryWrapper<AsAttributeGroup> asAttributeGroupLambdaQueryWrapper = new LambdaQueryWrapper<>() {{ LambdaQueryWrapper<AsAttributeGroup> asAttributeGroupQueryWrapper = new LambdaQueryWrapper<>() {{
eq(AsAttributeGroup::getGroupId, asCategoryAttributeGroup.getAttributeGroupId()); eq(AsAttributeGroup::getGroupId, asCategoryAttributeGroup.getAttributeGroupId());
}}; }};
List<Long> attributeList = asAttributeGroupService.list(asAttributeGroupLambdaQueryWrapper).stream() List<Long> attributeIdList = asAttributeGroupService.list(asAttributeGroupQueryWrapper).stream()
.map(AsAttributeGroup::getAttributeId) .map(AsAttributeGroup::getAttributeId)
.toList(); .toList();
if (attributeList.isEmpty()) { if (attributeIdList.isEmpty()){
return new ArrayList<>(); return new ArrayList<>();
} }
return attributeInfoService.listByIds(attributeList).stream() return attributeInfoService.listByIds(attributeIdList).stream()
.map(AttributeInfo::buildTemplateModel) .map(AttributeInfo::buildTemplateModel)
.toList(); .toList();
} }
)) ))
.filter(TemplateAttributeGroupModel::isEffective) .filter(TemplateAttributeGroupModel::isEffective)
.toList(); .toList();
// 查重集合
Set<Long> attributeIdSet = new HashSet<>(); Set<Long> attributeIdSet = new HashSet<>();
// 获取组内所有的属性Id
if (!attributeGroupModelList.isEmpty()){ if (!attributeGroupModelList.isEmpty()){
attributeIdSet.addAll( attributeIdSet.addAll(
attributeGroupModelList.stream() attributeGroupModelList.stream()
.flatMap((Function<? super TemplateAttributeGroupModel,Stream<TemplateAttributeModel>>) templateAttributeGroupModel -> templateAttributeGroupModel.getAttributeList().stream()) .flatMap((Function<TemplateAttributeGroupModel, Stream<TemplateAttributeModel>>) templateAttributeGroupModel -> templateAttributeGroupModel.getAttributeList().stream())
.map(TemplateAttributeModel::getId) .map(TemplateAttributeModel::getId)
.toList() .toList()
); );
} }
List<TemplateAttributeModel> templateAttributeModelList =new ArrayList<>();
LambdaQueryWrapper<AsCategoryAttribute> categoryAttributeLambdaQueryWrapper=new LambdaQueryWrapper<>(); List<TemplateAttributeModel> templateAttributeModelList = new ArrayList<>();
categoryAttributeLambdaQueryWrapper.in(AsCategoryAttribute::getCategoryId,cateGoryIdList); LambdaQueryWrapper<AsCategoryAttribute> categoryAttributeQueryWrapper = new LambdaQueryWrapper<>();
List<AsCategoryAttribute> asCategoryAttributeList=asCategoryAttributeService.list(categoryAttributeLambdaQueryWrapper); categoryAttributeQueryWrapper.in(AsCategoryAttribute::getCategoryId, cateGoryIdList);
List<Long> templateAttributeIdList = asCategoryAttributeList.stream() List<AsCategoryAttribute> asCategoryAttributeList = asCategoryAttributeService.list(categoryAttributeQueryWrapper);
.map(AsCategoryAttribute::getAttributeId) if (asCategoryAttributeList != null && !asCategoryAttributeList.isEmpty()){
.filter(templateAttributeId -> !attributeIdSet.contains(templateAttributeId)) List<Long> templateAttributeIdList = asCategoryAttributeList.stream()
.toList(); .map(AsCategoryAttribute::getAttributeId)
if (asCategoryAttributeList!=null && ! asCategoryAttributeList.isEmpty()) .filter(templateAttributeId -> !attributeIdSet.contains(templateAttributeId))
asCategoryAttributeList.stream() .toList();
.map(AsCategoryAttribute::getAttributeId) templateAttributeModelList = attributeInfoService.listByIds(templateAttributeIdList).stream()
.filter(templateAttributeId -> !attributeIdSet.contains(templateAttributeId)) .map(AttributeInfo::buildTemplateModel)
.toList(); .toList();
templateAttributeModelList=attributeInfoService.listByIds(templateAttributeIdList).stream() }
.map(AttributeInfo::buildTemplateModel)
.toList(); List<TemplateAttributeModel> attributeModelList = new ArrayList<>();
List<TemplateAttributeModel> attributeModelList=new ArrayList<>();
if (!templateAttributeModelList.isEmpty()){ if (!templateAttributeModelList.isEmpty()){
attributeIdSet.addAll( attributeIdSet.addAll(
templateAttributeModelList.stream().map(TemplateAttributeModel::getId).toList() templateAttributeModelList.stream().map(TemplateAttributeModel::getId).toList()
); );
} }
LambdaQueryWrapper<AttributeInfo> attributeInfoLambdaQueryWrapper=new LambdaQueryWrapper<>(); LambdaQueryWrapper<AttributeInfo> attributeInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
attributeInfoLambdaQueryWrapper.notIn(!attributeIdSet.isEmpty(),AttributeInfo::getId,attributeIdSet); attributeInfoLambdaQueryWrapper.notIn(!attributeIdSet.isEmpty(), AttributeInfo::getId, attributeIdSet);
attributeModelList=attributeInfoService.list(attributeInfoLambdaQueryWrapper).stream().map(AttributeInfo::buildTemplateModel).toList(); attributeModelList = attributeInfoService.list(attributeInfoLambdaQueryWrapper).stream().map(AttributeInfo::buildTemplateModel).toList();
return CategoryCommonElementResp.builder() return CategoryCommonElementResp.builder()
.templateAttributeGroupList(attributeGroupModelList) .templateAttributeGroupList(attributeGroupModelList)
.templateAttributeList(templateAttributeModelList)
.attributeList(attributeModelList) .attributeList(attributeModelList)
.build(); .build();
} }
} }

View File

@ -14,10 +14,10 @@ spring:
nacos: nacos:
discovery: discovery:
# 服务注册地址 # 服务注册地址
server-addr: 127.0.0.1:8848 server-addr: 122.51.111.225:8848
config: config:
# 配置中心地址 # 配置中心地址
server-addr: 127.0.0.1:8848 server-addr: 122.51.111.225:8848
# 配置文件格式 # 配置文件格式
file-extension: yml file-extension: yml
# 共享配置 # 共享配置