mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-26 09:11:52 +08:00
规格增删改查接口及页面提交
This commit is contained in:
parent
a270db821d
commit
204a5ba284
16
sql/mall.sql
16
sql/mall.sql
@ -171,7 +171,7 @@ VALUES ('商品导出', 'product:spu:export', 3, 5, @parentId, '', '', '', 0);
|
|||||||
drop table if exists product_property;
|
drop table if exists product_property;
|
||||||
create table product_property
|
create table product_property
|
||||||
(
|
(
|
||||||
id bigint comment '主键',
|
id bigint NOT NULL AUTO_INCREMENT comment '主键',
|
||||||
name varchar(64) comment '规格名称',
|
name varchar(64) comment '规格名称',
|
||||||
status tinyint comment '状态: 0 开启 ,1 禁用',
|
status tinyint comment '状态: 0 开启 ,1 禁用',
|
||||||
create_time datetime default current_timestamp comment '创建时间',
|
create_time datetime default current_timestamp comment '创建时间',
|
||||||
@ -179,7 +179,7 @@ create table product_property
|
|||||||
creator varchar(64) comment '创建人',
|
creator varchar(64) comment '创建人',
|
||||||
updater varchar(64) comment '更新人',
|
updater varchar(64) comment '更新人',
|
||||||
tenant_id bigint NOT NULL DEFAULT '0' COMMENT '租户编号',
|
tenant_id bigint NOT NULL DEFAULT '0' COMMENT '租户编号',
|
||||||
deleted bit(1) comment '状态',
|
deleted bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
|
||||||
primary key (id),
|
primary key (id),
|
||||||
key idx_name ( name (32)) comment '规格名称索引'
|
key idx_name ( name (32)) comment '规格名称索引'
|
||||||
) comment '规格名称' character set utf8mb4
|
) comment '规格名称' character set utf8mb4
|
||||||
@ -189,7 +189,7 @@ create table product_property
|
|||||||
drop table if exists product_property_value;
|
drop table if exists product_property_value;
|
||||||
create table product_property_value
|
create table product_property_value
|
||||||
(
|
(
|
||||||
id int comment '主键',
|
id bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||||
property_id bigint comment '规格键id',
|
property_id bigint comment '规格键id',
|
||||||
name varchar(128) comment '规格值名字',
|
name varchar(128) comment '规格值名字',
|
||||||
status tinyint comment '状态: 1 开启 ,2 禁用',
|
status tinyint comment '状态: 1 开启 ,2 禁用',
|
||||||
@ -198,7 +198,7 @@ create table product_property_value
|
|||||||
creator varchar(64) comment '创建人',
|
creator varchar(64) comment '创建人',
|
||||||
updater varchar(64) comment '更新人',
|
updater varchar(64) comment '更新人',
|
||||||
tenant_id bigint NOT NULL DEFAULT '0' COMMENT '租户编号',
|
tenant_id bigint NOT NULL DEFAULT '0' COMMENT '租户编号',
|
||||||
deleted bit(1) comment '状态',
|
deleted bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
|
||||||
primary key (id)
|
primary key (id)
|
||||||
) comment '规格值' character set utf8mb4
|
) comment '规格值' character set utf8mb4
|
||||||
collate utf8mb4_general_ci;
|
collate utf8mb4_general_ci;
|
||||||
@ -207,7 +207,7 @@ create table product_property_value
|
|||||||
drop table if exists product_spu;
|
drop table if exists product_spu;
|
||||||
create table product_spu
|
create table product_spu
|
||||||
(
|
(
|
||||||
id int comment '主键',
|
id bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||||
name varchar(128) comment '商品名称',
|
name varchar(128) comment '商品名称',
|
||||||
sell_point varchar(128) not null comment '卖点',
|
sell_point varchar(128) not null comment '卖点',
|
||||||
description text not null comment '描述',
|
description text not null comment '描述',
|
||||||
@ -223,7 +223,7 @@ create table product_spu
|
|||||||
creator varchar(64) comment '创建人',
|
creator varchar(64) comment '创建人',
|
||||||
updater varchar(64) comment '更新人',
|
updater varchar(64) comment '更新人',
|
||||||
tenant_id bigint NOT NULL DEFAULT '0' COMMENT '租户编号',
|
tenant_id bigint NOT NULL DEFAULT '0' COMMENT '租户编号',
|
||||||
deleted bit(1) comment '状态',
|
deleted bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
|
||||||
primary key (id)
|
primary key (id)
|
||||||
) comment '商品spu' character set utf8mb4
|
) comment '商品spu' character set utf8mb4
|
||||||
collate utf8mb4_general_ci;
|
collate utf8mb4_general_ci;
|
||||||
@ -233,7 +233,7 @@ create table product_spu
|
|||||||
drop table if exists product_sku;
|
drop table if exists product_sku;
|
||||||
create table product_sku
|
create table product_sku
|
||||||
(
|
(
|
||||||
id int comment '主键',
|
id bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||||
spu_id bigint not null comment 'spu编号',
|
spu_id bigint not null comment 'spu编号',
|
||||||
properties varchar(64) not null comment '规格值数组-json格式, [{propertId: , valueId: }, {propertId: , valueId: }]',
|
properties varchar(64) not null comment '规格值数组-json格式, [{propertId: , valueId: }, {propertId: , valueId: }]',
|
||||||
price int not null DEFAULT -1 comment '销售价格,单位:分',
|
price int not null DEFAULT -1 comment '销售价格,单位:分',
|
||||||
@ -247,7 +247,7 @@ create table product_sku
|
|||||||
creator varchar(64) comment '创建人',
|
creator varchar(64) comment '创建人',
|
||||||
updater varchar(64) comment '更新人',
|
updater varchar(64) comment '更新人',
|
||||||
tenant_id bigint NOT NULL DEFAULT '0' COMMENT '租户编号',
|
tenant_id bigint NOT NULL DEFAULT '0' COMMENT '租户编号',
|
||||||
deleted bit(1) comment '状态',
|
deleted bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
|
||||||
primary key (id)
|
primary key (id)
|
||||||
) comment '商品sku' character set utf8mb4
|
) comment '商品sku' character set utf8mb4
|
||||||
collate utf8mb4_general_ci;
|
collate utf8mb4_general_ci;
|
||||||
|
@ -63,8 +63,7 @@ public class ProductPropertyController {
|
|||||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||||
@PreAuthorize("@ss.hasPermission('product:property:query')")
|
@PreAuthorize("@ss.hasPermission('product:property:query')")
|
||||||
public CommonResult<ProductPropertyRespVO> getProperty(@RequestParam("id") Long id) {
|
public CommonResult<ProductPropertyRespVO> getProperty(@RequestParam("id") Long id) {
|
||||||
ProductPropertyDO property = productPropertyService.getProperty(id);
|
return success(productPropertyService.getPropertyResp(id));
|
||||||
return success(ProductPropertyConvert.INSTANCE.convert(property));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
@ -80,8 +79,7 @@ public class ProductPropertyController {
|
|||||||
@ApiOperation("获得规格名称分页")
|
@ApiOperation("获得规格名称分页")
|
||||||
@PreAuthorize("@ss.hasPermission('product:property:query')")
|
@PreAuthorize("@ss.hasPermission('product:property:query')")
|
||||||
public CommonResult<PageResult<ProductPropertyRespVO>> getPropertyPage(@Valid ProductPropertyPageReqVO pageVO) {
|
public CommonResult<PageResult<ProductPropertyRespVO>> getPropertyPage(@Valid ProductPropertyPageReqVO pageVO) {
|
||||||
PageResult<ProductPropertyDO> pageResult = productPropertyService.getPropertyPage(pageVO);
|
return success(productPropertyService.getPropertyListPage(pageVO));
|
||||||
return success(ProductPropertyConvert.INSTANCE.convertPage(pageResult));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/export-excel")
|
@GetMapping("/export-excel")
|
||||||
|
@ -1,12 +1,20 @@
|
|||||||
package cn.iocoder.yudao.module.product.controller.admin.property.vo;
|
package cn.iocoder.yudao.module.product.controller.admin.property.vo;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.PropertyValueCreateReqVO;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
import io.swagger.annotations.*;
|
import io.swagger.annotations.*;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@ApiModel("管理后台 - 规格名称创建 Request VO")
|
@ApiModel("管理后台 - 规格名称创建 Request VO")
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@ToString(callSuper = true)
|
@ToString(callSuper = true)
|
||||||
public class ProductPropertyCreateReqVO extends ProductPropertyBaseVO {
|
public class ProductPropertyCreateReqVO extends ProductPropertyBaseVO {
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "属性值")
|
||||||
|
@NotNull(message = "属性值不能为空")
|
||||||
|
List<PropertyValueCreateReqVO> propertyValueList;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ public class ProductPropertyRespVO extends ProductPropertyBaseVO {
|
|||||||
@ApiModelProperty(value = "创建时间")
|
@ApiModelProperty(value = "创建时间")
|
||||||
private Date createTime;
|
private Date createTime;
|
||||||
|
|
||||||
private List<PropertyValueRespVO> propertyValueRespVOList;
|
@ApiModelProperty(value = "属性值")
|
||||||
|
private List<PropertyValueRespVO> propertyValueList;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
package cn.iocoder.yudao.module.product.controller.admin.property.vo;
|
package cn.iocoder.yudao.module.product.controller.admin.property.vo;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.PropertyValueCreateReqVO;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
import io.swagger.annotations.*;
|
import io.swagger.annotations.*;
|
||||||
import javax.validation.constraints.*;
|
import javax.validation.constraints.*;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@ApiModel("管理后台 - 规格名称更新 Request VO")
|
@ApiModel("管理后台 - 规格名称更新 Request VO")
|
||||||
@Data
|
@Data
|
||||||
@ -14,4 +16,8 @@ public class ProductPropertyUpdateReqVO extends ProductPropertyBaseVO {
|
|||||||
@NotNull(message = "主键不能为空")
|
@NotNull(message = "主键不能为空")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "属性值")
|
||||||
|
@NotNull(message = "属性值不能为空")
|
||||||
|
List<PropertyValueCreateReqVO> propertyValueList;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,100 +0,0 @@
|
|||||||
package cn.iocoder.yudao.module.product.controller.admin.propertyvalue;
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import org.springframework.validation.annotation.Validated;
|
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
|
||||||
import io.swagger.annotations.*;
|
|
||||||
|
|
||||||
import javax.validation.constraints.*;
|
|
||||||
import javax.validation.*;
|
|
||||||
import javax.servlet.http.*;
|
|
||||||
import java.util.*;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
||||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
|
||||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
|
||||||
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;
|
|
||||||
|
|
||||||
import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.*;
|
|
||||||
import cn.iocoder.yudao.module.product.dal.dataobject.propertyvalue.PropertyValueDO;
|
|
||||||
import cn.iocoder.yudao.module.product.convert.propertyvalue.PropertyValueConvert;
|
|
||||||
import cn.iocoder.yudao.module.product.service.propertyvalue.PropertyValueService;
|
|
||||||
|
|
||||||
@Api(tags = "管理后台 - 规格值")
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/product/property-value")
|
|
||||||
@Validated
|
|
||||||
public class PropertyValueController {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private PropertyValueService propertyValueService;
|
|
||||||
|
|
||||||
@PostMapping("/create")
|
|
||||||
@ApiOperation("创建规格值")
|
|
||||||
@PreAuthorize("@ss.hasPermission('product:property-value:create')")
|
|
||||||
public CommonResult<Integer> createPropertyValue(@Valid @RequestBody PropertyValueCreateReqVO createReqVO) {
|
|
||||||
return success(propertyValueService.createPropertyValue(createReqVO));
|
|
||||||
}
|
|
||||||
|
|
||||||
@PutMapping("/update")
|
|
||||||
@ApiOperation("更新规格值")
|
|
||||||
@PreAuthorize("@ss.hasPermission('product:property-value:update')")
|
|
||||||
public CommonResult<Boolean> updatePropertyValue(@Valid @RequestBody PropertyValueUpdateReqVO updateReqVO) {
|
|
||||||
propertyValueService.updatePropertyValue(updateReqVO);
|
|
||||||
return success(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeleteMapping("/delete")
|
|
||||||
@ApiOperation("删除规格值")
|
|
||||||
@ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Integer.class)
|
|
||||||
@PreAuthorize("@ss.hasPermission('product:property-value:delete')")
|
|
||||||
public CommonResult<Boolean> deletePropertyValue(@RequestParam("id") Integer id) {
|
|
||||||
propertyValueService.deletePropertyValue(id);
|
|
||||||
return success(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/get")
|
|
||||||
@ApiOperation("获得规格值")
|
|
||||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Integer.class)
|
|
||||||
@PreAuthorize("@ss.hasPermission('product:property-value:query')")
|
|
||||||
public CommonResult<PropertyValueRespVO> getPropertyValue(@RequestParam("id") Integer id) {
|
|
||||||
PropertyValueDO propertyValue = propertyValueService.getPropertyValue(id);
|
|
||||||
return success(PropertyValueConvert.INSTANCE.convert(propertyValue));
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/list")
|
|
||||||
@ApiOperation("获得规格值列表")
|
|
||||||
@ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
|
|
||||||
@PreAuthorize("@ss.hasPermission('product:property-value:query')")
|
|
||||||
public CommonResult<List<PropertyValueRespVO>> getPropertyValueList(@RequestParam("ids") Collection<Integer> ids) {
|
|
||||||
List<PropertyValueDO> list = propertyValueService.getPropertyValueList(ids);
|
|
||||||
return success(PropertyValueConvert.INSTANCE.convertList(list));
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/page")
|
|
||||||
@ApiOperation("获得规格值分页")
|
|
||||||
@PreAuthorize("@ss.hasPermission('product:property-value:query')")
|
|
||||||
public CommonResult<PageResult<PropertyValueRespVO>> getPropertyValuePage(@Valid PropertyValuePageReqVO pageVO) {
|
|
||||||
PageResult<PropertyValueDO> pageResult = propertyValueService.getPropertyValuePage(pageVO);
|
|
||||||
return success(PropertyValueConvert.INSTANCE.convertPage(pageResult));
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/export-excel")
|
|
||||||
@ApiOperation("导出规格值 Excel")
|
|
||||||
@PreAuthorize("@ss.hasPermission('product:property-value:export')")
|
|
||||||
@OperateLog(type = EXPORT)
|
|
||||||
public void exportPropertyValueExcel(@Valid PropertyValueExportReqVO exportReqVO,
|
|
||||||
HttpServletResponse response) throws IOException {
|
|
||||||
List<PropertyValueDO> list = propertyValueService.getPropertyValueList(exportReqVO);
|
|
||||||
// 导出 Excel
|
|
||||||
List<PropertyValueExcelVO> datas = PropertyValueConvert.INSTANCE.convertList02(list);
|
|
||||||
ExcelUtils.write(response, "规格值.xls", "数据", PropertyValueExcelVO.class, datas);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -31,4 +31,6 @@ public interface PropertyValueConvert {
|
|||||||
|
|
||||||
List<PropertyValueExcelVO> convertList02(List<PropertyValueDO> list);
|
List<PropertyValueExcelVO> convertList02(List<PropertyValueDO> list);
|
||||||
|
|
||||||
|
List<PropertyValueDO> convertList03(List<PropertyValueCreateReqVO> list);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -35,4 +35,14 @@ public interface PropertyValueMapper extends BaseMapperX<PropertyValueDO> {
|
|||||||
.orderByDesc(PropertyValueDO::getId));
|
.orderByDesc(PropertyValueDO::getId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default List<PropertyValueDO> getPropertyValueListByPropertyId(List<Long> propertyIds){
|
||||||
|
return selectList(new LambdaQueryWrapperX<PropertyValueDO>()
|
||||||
|
.inIfPresent(PropertyValueDO::getPropertyId, propertyIds));
|
||||||
|
}
|
||||||
|
|
||||||
|
default void deletePropertyValueByPropertyId(Long propertyId){
|
||||||
|
LambdaQueryWrapperX<PropertyValueDO> queryWrapperX = new LambdaQueryWrapperX<>();
|
||||||
|
queryWrapperX.eq(PropertyValueDO::getPropertyId, propertyId).eq(PropertyValueDO::getDeleted, false);
|
||||||
|
delete(queryWrapperX);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,4 +67,13 @@ public interface ProductPropertyService {
|
|||||||
*/
|
*/
|
||||||
List<ProductPropertyDO> getPropertyList(ProductPropertyExportReqVO exportReqVO);
|
List<ProductPropertyDO> getPropertyList(ProductPropertyExportReqVO exportReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取属性及属性值列表 分页
|
||||||
|
* @param pageReqVO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
PageResult<ProductPropertyRespVO> getPropertyListPage(ProductPropertyPageReqVO pageReqVO);
|
||||||
|
|
||||||
|
ProductPropertyRespVO getPropertyResp(Long id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,15 +4,23 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|||||||
import cn.iocoder.yudao.module.product.controller.admin.property.vo.*;
|
import cn.iocoder.yudao.module.product.controller.admin.property.vo.*;
|
||||||
import cn.iocoder.yudao.module.product.controller.admin.property.vo.ProductPropertyCreateReqVO;
|
import cn.iocoder.yudao.module.product.controller.admin.property.vo.ProductPropertyCreateReqVO;
|
||||||
import cn.iocoder.yudao.module.product.controller.admin.property.vo.ProductPropertyUpdateReqVO;
|
import cn.iocoder.yudao.module.product.controller.admin.property.vo.ProductPropertyUpdateReqVO;
|
||||||
|
import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.PropertyValueCreateReqVO;
|
||||||
|
import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.PropertyValueRespVO;
|
||||||
import cn.iocoder.yudao.module.product.convert.property.ProductPropertyConvert;
|
import cn.iocoder.yudao.module.product.convert.property.ProductPropertyConvert;
|
||||||
|
import cn.iocoder.yudao.module.product.convert.propertyvalue.PropertyValueConvert;
|
||||||
import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO;
|
import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO;
|
||||||
|
import cn.iocoder.yudao.module.product.dal.dataobject.propertyvalue.PropertyValueDO;
|
||||||
import cn.iocoder.yudao.module.product.dal.mysql.property.ProductPropertyMapper;
|
import cn.iocoder.yudao.module.product.dal.mysql.property.ProductPropertyMapper;
|
||||||
|
import cn.iocoder.yudao.module.product.service.propertyvalue.PropertyValueService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PROPERTY_NOT_EXISTS;
|
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PROPERTY_NOT_EXISTS;
|
||||||
@ -29,22 +37,39 @@ public class ProductPropertyServiceImpl implements ProductPropertyService {
|
|||||||
@Resource
|
@Resource
|
||||||
private ProductPropertyMapper productPropertyMapper;
|
private ProductPropertyMapper productPropertyMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private PropertyValueService propertyValueService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Long createProperty(ProductPropertyCreateReqVO createReqVO) {
|
public Long createProperty(ProductPropertyCreateReqVO createReqVO) {
|
||||||
// 插入
|
// 插入
|
||||||
ProductPropertyDO property = ProductPropertyConvert.INSTANCE.convert(createReqVO);
|
ProductPropertyDO property = ProductPropertyConvert.INSTANCE.convert(createReqVO);
|
||||||
productPropertyMapper.insert(property);
|
productPropertyMapper.insert(property);
|
||||||
|
|
||||||
|
//插入属性值
|
||||||
|
List<PropertyValueCreateReqVO> propertyValueList = createReqVO.getPropertyValueList();
|
||||||
|
List<PropertyValueDO> propertyValueDOList = PropertyValueConvert.INSTANCE.convertList03(propertyValueList);
|
||||||
|
propertyValueDOList.stream().forEach(x-> x.setPropertyId(property.getId()));
|
||||||
|
propertyValueService.batchInsert(propertyValueDOList);
|
||||||
// 返回
|
// 返回
|
||||||
return property.getId();
|
return property.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void updateProperty(ProductPropertyUpdateReqVO updateReqVO) {
|
public void updateProperty(ProductPropertyUpdateReqVO updateReqVO) {
|
||||||
// 校验存在
|
// 校验存在
|
||||||
this.validatePropertyExists(updateReqVO.getId());
|
this.validatePropertyExists(updateReqVO.getId());
|
||||||
// 更新
|
// 更新
|
||||||
ProductPropertyDO updateObj = ProductPropertyConvert.INSTANCE.convert(updateReqVO);
|
ProductPropertyDO updateObj = ProductPropertyConvert.INSTANCE.convert(updateReqVO);
|
||||||
productPropertyMapper.updateById(updateObj);
|
productPropertyMapper.updateById(updateObj);
|
||||||
|
//更新属性值,先删后加
|
||||||
|
propertyValueService.deletePropertyValueByPropertyId(updateReqVO.getId());
|
||||||
|
List<PropertyValueCreateReqVO> propertyValueList = updateReqVO.getPropertyValueList();
|
||||||
|
List<PropertyValueDO> propertyValueDOList = PropertyValueConvert.INSTANCE.convertList03(propertyValueList);
|
||||||
|
propertyValueDOList.stream().forEach(x-> x.setPropertyId(updateReqVO.getId()));
|
||||||
|
propertyValueService.batchInsert(propertyValueDOList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -53,6 +78,8 @@ public class ProductPropertyServiceImpl implements ProductPropertyService {
|
|||||||
this.validatePropertyExists(id);
|
this.validatePropertyExists(id);
|
||||||
// 删除
|
// 删除
|
||||||
productPropertyMapper.deleteById(id);
|
productPropertyMapper.deleteById(id);
|
||||||
|
//同步删除属性值
|
||||||
|
propertyValueService.deletePropertyValueByPropertyId(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validatePropertyExists(Long id) {
|
private void validatePropertyExists(Long id) {
|
||||||
@ -81,4 +108,36 @@ public class ProductPropertyServiceImpl implements ProductPropertyService {
|
|||||||
return productPropertyMapper.selectList(exportReqVO);
|
return productPropertyMapper.selectList(exportReqVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult<ProductPropertyRespVO> getPropertyListPage(ProductPropertyPageReqVO pageReqVO) {
|
||||||
|
//获取属性列表
|
||||||
|
PageResult<ProductPropertyDO> pageResult = productPropertyMapper.selectPage(pageReqVO);
|
||||||
|
PageResult<ProductPropertyRespVO> propertyRespVOPageResult = ProductPropertyConvert.INSTANCE.convertPage(pageResult);
|
||||||
|
List<Long> propertyIds = propertyRespVOPageResult.getList().stream().map(x -> x.getId()).collect(Collectors.toList());
|
||||||
|
|
||||||
|
//获取属性值列表
|
||||||
|
List<PropertyValueDO> propertyValueDOList = propertyValueService.getPropertyValueListByPropertyId(propertyIds);
|
||||||
|
List<PropertyValueRespVO> propertyValueRespVOList = PropertyValueConvert.INSTANCE.convertList(propertyValueDOList);
|
||||||
|
//组装一对多
|
||||||
|
propertyRespVOPageResult.getList().stream().forEach(x->{
|
||||||
|
Long propertyId = x.getId();
|
||||||
|
List<PropertyValueRespVO> valueDOList = propertyValueRespVOList.stream().filter(v -> v.getPropertyId().equals(propertyId)).collect(Collectors.toList());
|
||||||
|
x.setPropertyValueList(valueDOList);
|
||||||
|
});
|
||||||
|
return propertyRespVOPageResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ProductPropertyRespVO getPropertyResp(Long id) {
|
||||||
|
//查询规格
|
||||||
|
ProductPropertyDO property = getProperty(id);
|
||||||
|
ProductPropertyRespVO propertyRespVO = ProductPropertyConvert.INSTANCE.convert(property);
|
||||||
|
//查询属性值
|
||||||
|
List<PropertyValueDO> valueDOList = propertyValueService.getPropertyValueListByPropertyId(Arrays.asList(id));
|
||||||
|
List<PropertyValueRespVO> propertyValueRespVOS = PropertyValueConvert.INSTANCE.convertList(valueDOList);
|
||||||
|
//组装
|
||||||
|
propertyRespVO.setPropertyValueList(propertyValueRespVOS);
|
||||||
|
return propertyRespVO;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -67,4 +67,22 @@ public interface PropertyValueService {
|
|||||||
*/
|
*/
|
||||||
List<PropertyValueDO> getPropertyValueList(PropertyValueExportReqVO exportReqVO);
|
List<PropertyValueDO> getPropertyValueList(PropertyValueExportReqVO exportReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量插入属性值
|
||||||
|
* @param propertyValues
|
||||||
|
*/
|
||||||
|
void batchInsert(List<PropertyValueDO> propertyValues);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据属性id查询
|
||||||
|
* @param propertyIds
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<PropertyValueDO> getPropertyValueListByPropertyId(List<Long> propertyIds);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据属性id 删除
|
||||||
|
* @param propertyId
|
||||||
|
*/
|
||||||
|
void deletePropertyValueByPropertyId(Long propertyId);
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
package cn.iocoder.yudao.module.product.service.propertyvalue;
|
package cn.iocoder.yudao.module.product.service.propertyvalue;
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.PropertyValueCreateReqVO;
|
import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.*;
|
||||||
import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.PropertyValueExportReqVO;
|
|
||||||
import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.PropertyValuePageReqVO;
|
|
||||||
import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.PropertyValueUpdateReqVO;
|
|
||||||
import cn.iocoder.yudao.module.product.convert.propertyvalue.PropertyValueConvert;
|
import cn.iocoder.yudao.module.product.convert.propertyvalue.PropertyValueConvert;
|
||||||
import cn.iocoder.yudao.module.product.dal.dataobject.propertyvalue.PropertyValueDO;
|
import cn.iocoder.yudao.module.product.dal.dataobject.propertyvalue.PropertyValueDO;
|
||||||
import cn.iocoder.yudao.module.product.dal.mysql.propertyvalue.PropertyValueMapper;
|
import cn.iocoder.yudao.module.product.dal.mysql.propertyvalue.PropertyValueMapper;
|
||||||
@ -84,4 +81,19 @@ public class PropertyValueServiceImpl implements PropertyValueService {
|
|||||||
return propertyValueMapper.selectList(exportReqVO);
|
return propertyValueMapper.selectList(exportReqVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void batchInsert(List<PropertyValueDO> propertyValues) {
|
||||||
|
propertyValueMapper.insertBatch(propertyValues);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<PropertyValueDO> getPropertyValueListByPropertyId(List<Long> propertyIds) {
|
||||||
|
return propertyValueMapper.getPropertyValueListByPropertyId(propertyIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deletePropertyValueByPropertyId(Long propertyId) {
|
||||||
|
propertyValueMapper.deletePropertyValueByPropertyId(propertyId);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,16 +24,17 @@
|
|||||||
<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
|
<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
|
||||||
v-hasPermi="['product:property:create']">新增</el-button>
|
v-hasPermi="['product:property:create']">新增</el-button>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="1.5">
|
|
||||||
<el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading"
|
|
||||||
v-hasPermi="['product:property:export']">导出</el-button>
|
|
||||||
</el-col>
|
|
||||||
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
||||||
</el-row>
|
</el-row>
|
||||||
|
|
||||||
<!-- 列表 -->
|
<!-- 列表 -->
|
||||||
<el-table v-loading="loading" :data="list">
|
<el-table v-loading="loading" :data="list">
|
||||||
<el-table-column label="规格名称" align="center" prop="name" />
|
<el-table-column label="规格名称" align="center" prop="name" />
|
||||||
|
<el-table-column label="规格名称" align="center" prop="propertyValueList">
|
||||||
|
<template slot-scope="scope">
|
||||||
|
<span>{{formatList(scope.row.propertyValueList)}}</span>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
<el-table-column label="开启状态" align="center" prop="status">
|
<el-table-column label="开启状态" align="center" prop="status">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status"/>
|
<dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status"/>
|
||||||
@ -74,19 +75,19 @@
|
|||||||
<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="addPropertyValue()">添加</el-button>
|
<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="addPropertyValue()">添加</el-button>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item
|
<el-form-item
|
||||||
v-for="(domain, index) in form.propertyValues"
|
v-for="(domain, index) in form.propertyValueList"
|
||||||
:key="domain.key"
|
:key="domain.key"
|
||||||
:prop="'propertyValues.' + index + '.value'"
|
:prop="'propertyValueList.' + index + '.name'"
|
||||||
:rules="{
|
:rules="{
|
||||||
required: true, message: '域名不能为空', trigger: 'blur'
|
required: true, message: '属性值不能为空', trigger: 'blur'
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
<el-row>
|
<el-row>
|
||||||
<el-col :span="18">
|
<el-col :span="18">
|
||||||
<el-input v-model="domain.value"></el-input>
|
<el-input v-model="domain.name" size="mini"></el-input>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="6">
|
<el-col :span="6">
|
||||||
<el-button @click.prevent="removePropertyValue(domain)">删除</el-button>
|
<el-button style="margin-left: 20px;" size="mini" @click.prevent="removePropertyValue(domain)">删除</el-button>
|
||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
@ -134,8 +135,8 @@ export default {
|
|||||||
form: {
|
form: {
|
||||||
name:'',
|
name:'',
|
||||||
status:'',
|
status:'',
|
||||||
propertyValues: [{
|
propertyValueList: [{
|
||||||
value: ''
|
name: ''
|
||||||
}],
|
}],
|
||||||
},
|
},
|
||||||
// 表单校验
|
// 表单校验
|
||||||
@ -171,12 +172,10 @@ export default {
|
|||||||
id: undefined,
|
id: undefined,
|
||||||
name: undefined,
|
name: undefined,
|
||||||
status: undefined,
|
status: undefined,
|
||||||
|
propertyValueList: [{
|
||||||
|
name: ''
|
||||||
|
}]
|
||||||
};
|
};
|
||||||
this.form.propertyValues = [{
|
|
||||||
key:'',
|
|
||||||
value: ''
|
|
||||||
}];
|
|
||||||
console.log("this.form", this.form)
|
|
||||||
this.resetForm("form");
|
this.resetForm("form");
|
||||||
},
|
},
|
||||||
/** 搜索按钮操作 */
|
/** 搜索按钮操作 */
|
||||||
@ -194,7 +193,7 @@ export default {
|
|||||||
handleAdd() {
|
handleAdd() {
|
||||||
this.reset();
|
this.reset();
|
||||||
this.open = true;
|
this.open = true;
|
||||||
this.title = "添加规格名称";
|
this.title = "添加规格";
|
||||||
},
|
},
|
||||||
/** 修改按钮操作 */
|
/** 修改按钮操作 */
|
||||||
handleUpdate(row) {
|
handleUpdate(row) {
|
||||||
@ -203,7 +202,7 @@ export default {
|
|||||||
getProperty(id).then(response => {
|
getProperty(id).then(response => {
|
||||||
this.form = response.data;
|
this.form = response.data;
|
||||||
this.open = true;
|
this.open = true;
|
||||||
this.title = "修改规格名称";
|
this.title = "修改规格";
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
/** 提交按钮 */
|
/** 提交按钮 */
|
||||||
@ -232,7 +231,7 @@ export default {
|
|||||||
/** 删除按钮操作 */
|
/** 删除按钮操作 */
|
||||||
handleDelete(row) {
|
handleDelete(row) {
|
||||||
const id = row.id;
|
const id = row.id;
|
||||||
this.$modal.confirm('是否确认删除规格名称编号为"' + id + '"的数据项?').then(function() {
|
this.$modal.confirm('是否确认删除规格名称为"' + row.name + '"的数据项?').then(function() {
|
||||||
return deleteProperty(id);
|
return deleteProperty(id);
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
this.getList();
|
this.getList();
|
||||||
@ -256,17 +255,25 @@ export default {
|
|||||||
}).catch(() => {});
|
}).catch(() => {});
|
||||||
},
|
},
|
||||||
removePropertyValue(item) {
|
removePropertyValue(item) {
|
||||||
var index = this.form.propertyValues.indexOf(item)
|
var index = this.form.propertyValueList.indexOf(item)
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
this.form.propertyValues.splice(index, 1)
|
this.form.propertyValueList.splice(index, 1)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
addPropertyValue() {
|
addPropertyValue() {
|
||||||
console.log("this.form.propertyValues", this.form.propertyValues)
|
this.form.propertyValueList.push({
|
||||||
this.form.propertyValues.push({
|
name: ''
|
||||||
value: '',
|
|
||||||
key: Date.now()
|
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
formatList(list) {
|
||||||
|
let str = ''
|
||||||
|
for (var i = 0; i < list.length; i++) {
|
||||||
|
str += list[i].name;
|
||||||
|
if(i != list.length-1){
|
||||||
|
str+="/";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return str
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user