商品属性组添加
parent
603a2f20e8
commit
94d0d2e0e9
|
@ -45,4 +45,11 @@ public class AsAttributeGroup extends BaseEntity {
|
||||||
private Long attributeId;
|
private Long attributeId;
|
||||||
|
|
||||||
|
|
||||||
|
public static AsAttributeGroup buildGroup (Long attributeGroupId,
|
||||||
|
Long attributeId) {
|
||||||
|
return AsAttributeGroup.builder()
|
||||||
|
.groupId(attributeGroupId)
|
||||||
|
.attributeId(attributeId)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
package com.muyu.product.domain.model;
|
||||||
|
|
||||||
|
import com.muyu.common.core.web.domain.BaseEntity;
|
||||||
|
import com.muyu.product.domain.AttributeGroup;
|
||||||
|
import com.muyu.product.domain.req.AttributeGroupSaveReq;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DongZl
|
||||||
|
* @description: 属性组添加模型
|
||||||
|
* @Date 2024-2-28 下午 03:16
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@SuperBuilder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class AttributeGroupSaveModel extends BaseEntity {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/** 组名称 */
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/** 状态 */
|
||||||
|
private String states;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 属性ID集合
|
||||||
|
*/
|
||||||
|
private List<Long> attributeIdList;
|
||||||
|
|
||||||
|
public static AttributeGroupSaveModel saveReqBuild (AttributeGroupSaveReq req){
|
||||||
|
return AttributeGroupSaveModel.builder()
|
||||||
|
.name(req.getName())
|
||||||
|
.states(req.getStates())
|
||||||
|
.attributeIdList(req.getAttributeIdList())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public AttributeGroup buildAttributeGroup () {
|
||||||
|
return AttributeGroup.builder()
|
||||||
|
.name(this.getName())
|
||||||
|
.states(this.getStates())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,8 @@
|
||||||
package com.muyu.product.domain.req;
|
package com.muyu.product.domain.req;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
@ -26,19 +28,21 @@ public class AttributeGroupSaveReq extends BaseEntity {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/** 属性组编号 */
|
/** 属性组编号 */
|
||||||
|
|
||||||
@ApiModelProperty(name = "属性组编号", value = "属性组编号")
|
@ApiModelProperty(name = "属性组编号", value = "属性组编号")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
/** 组名称 */
|
/** 组名称 */
|
||||||
|
|
||||||
@ApiModelProperty(name = "组名称", value = "组名称", required = true)
|
@ApiModelProperty(name = "组名称", value = "组名称", required = true)
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
/** 状态 */
|
/** 状态 */
|
||||||
|
|
||||||
@ApiModelProperty(name = "状态", value = "状态", required = true)
|
@ApiModelProperty(name = "状态", value = "状态", required = true)
|
||||||
private String states;
|
private String states;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 属性ID集合
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(name = "属性ID集合", value = "属性ID集合", required = true)
|
||||||
|
private List<Long> attributeIdList;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.muyu.product.controller;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import com.muyu.product.domain.model.AttributeGroupSaveModel;
|
||||||
import io.swagger.annotations.*;
|
import io.swagger.annotations.*;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
@ -83,7 +84,9 @@ public class AttributeGroupController extends BaseController {
|
||||||
@PostMapping
|
@PostMapping
|
||||||
@ApiOperation("新增属性组")
|
@ApiOperation("新增属性组")
|
||||||
public Result<String> add(@RequestBody AttributeGroupSaveReq attributeGroupSaveReq) {
|
public Result<String> add(@RequestBody AttributeGroupSaveReq attributeGroupSaveReq) {
|
||||||
return toAjax(attributeGroupService.save(AttributeGroup.saveBuild(attributeGroupSaveReq)));
|
return toAjax(
|
||||||
|
attributeGroupService.save(AttributeGroupSaveModel.saveReqBuild(attributeGroupSaveReq))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -102,7 +105,7 @@ public class AttributeGroupController extends BaseController {
|
||||||
*/
|
*/
|
||||||
@RequiresPermissions("product:attributeGroup:remove")
|
@RequiresPermissions("product:attributeGroup:remove")
|
||||||
@Log(title = "属性组", businessType = BusinessType.DELETE)
|
@Log(title = "属性组", businessType = BusinessType.DELETE)
|
||||||
@DeleteMapping("/{ids}")
|
@DeleteMapping("/{ids}")
|
||||||
@ApiOperation("删除属性组")
|
@ApiOperation("删除属性组")
|
||||||
@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = String.class, example = "1,2,3,4")
|
@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = String.class, example = "1,2,3,4")
|
||||||
public Result<String> remove(@PathVariable List<Long> ids) {
|
public Result<String> remove(@PathVariable List<Long> ids) {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.muyu.product.service;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import com.muyu.product.domain.AttributeGroup;
|
import com.muyu.product.domain.AttributeGroup;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.muyu.product.domain.model.AttributeGroupSaveModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 属性组Service接口
|
* 属性组Service接口
|
||||||
|
@ -19,4 +20,10 @@ public interface AttributeGroupService extends IService<AttributeGroup> {
|
||||||
*/
|
*/
|
||||||
public List<AttributeGroup> list(AttributeGroup attributeGroup);
|
public List<AttributeGroup> list(AttributeGroup attributeGroup);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存
|
||||||
|
* @param attributeGroupSaveModel 属性组保存模型
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
public Boolean save(AttributeGroupSaveModel attributeGroupSaveModel);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,20 @@
|
||||||
package com.muyu.product.service.impl;
|
package com.muyu.product.service.impl;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.muyu.common.core.utils.ObjUtils;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import com.muyu.product.mapper.AttributeGroupMapper;
|
|
||||||
import com.muyu.product.domain.AttributeGroup;
|
|
||||||
import com.muyu.product.service.AttributeGroupService;
|
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.muyu.common.core.utils.ObjUtils;
|
||||||
|
import com.muyu.product.domain.AsAttributeGroup;
|
||||||
|
import com.muyu.product.domain.AttributeGroup;
|
||||||
|
import com.muyu.product.domain.model.AttributeGroupSaveModel;
|
||||||
|
import com.muyu.product.mapper.AttributeGroupMapper;
|
||||||
|
import com.muyu.product.service.AsAttributeGroupService;
|
||||||
|
import com.muyu.product.service.AttributeGroupService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 属性组Service业务层处理
|
* 属性组Service业务层处理
|
||||||
|
@ -19,27 +24,55 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class AttributeGroupServiceImpl extends ServiceImpl<AttributeGroupMapper, AttributeGroup> implements AttributeGroupService {
|
public class AttributeGroupServiceImpl extends ServiceImpl<AttributeGroupMapper, AttributeGroup> implements AttributeGroupService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AsAttributeGroupService attributeGroupService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询属性组列表
|
* 查询属性组列表
|
||||||
*
|
*
|
||||||
* @param attributeGroup 属性组
|
* @param attributeGroup 属性组
|
||||||
|
*
|
||||||
* @return 属性组
|
* @return 属性组
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<AttributeGroup> list(AttributeGroup attributeGroup) {
|
public List<AttributeGroup> list (AttributeGroup attributeGroup) {
|
||||||
LambdaQueryWrapper<AttributeGroup> queryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<AttributeGroup> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
|
||||||
|
|
||||||
if (ObjUtils.notNull(attributeGroup.getName())){
|
if (ObjUtils.notNull(attributeGroup.getName())) {
|
||||||
queryWrapper.like(AttributeGroup::getName, attributeGroup.getName());
|
queryWrapper.like(AttributeGroup::getName, attributeGroup.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ObjUtils.notNull(attributeGroup.getStates())){
|
if (ObjUtils.notNull(attributeGroup.getStates())) {
|
||||||
queryWrapper.eq(AttributeGroup::getStates, attributeGroup.getStates());
|
queryWrapper.eq(AttributeGroup::getStates, attributeGroup.getStates());
|
||||||
}
|
}
|
||||||
|
|
||||||
return list(queryWrapper);
|
return list(queryWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存
|
||||||
|
*
|
||||||
|
* @param attributeGroupSaveModel 属性组保存模型
|
||||||
|
*
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public Boolean save (AttributeGroupSaveModel attributeGroupSaveModel) {
|
||||||
|
AttributeGroup attributeGroup = attributeGroupSaveModel.buildAttributeGroup();
|
||||||
|
boolean save = this.save(attributeGroup);
|
||||||
|
// 处理属性ID
|
||||||
|
Long attributeGroupId = attributeGroup.getId();
|
||||||
|
List<Long> attributeIdList = attributeGroupSaveModel.getAttributeIdList();
|
||||||
|
|
||||||
|
attributeGroupService.saveBatch(
|
||||||
|
attributeIdList.stream()
|
||||||
|
.map(attributeId -> AsAttributeGroup.buildGroup(attributeGroupId, attributeId))
|
||||||
|
.toList()
|
||||||
|
);
|
||||||
|
return save;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,10 @@ public class AttributeInfoServiceImpl extends ServiceImpl<AttributeInfoMapper, A
|
||||||
queryWrapper.like(AttributeInfo::getName, attributeInfo.getName());
|
queryWrapper.like(AttributeInfo::getName, attributeInfo.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ObjUtils.notNull(attributeInfo.getCode())){
|
||||||
|
queryWrapper.like(AttributeInfo::getCode, attributeInfo.getCode());
|
||||||
|
}
|
||||||
|
|
||||||
return list(queryWrapper);
|
return list(queryWrapper);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue