Merge remote-tracking branch 'origin/feature/1.8.0-uniapp' into feature/1.8.0-uniapp

This commit is contained in:
YunaiV 2022-05-29 11:07:06 +08:00
commit 72019f727e
35 changed files with 505 additions and 628 deletions

View File

@ -171,7 +171,7 @@ VALUES ('商品导出', 'product:spu:export', 3, 5, @parentId, '', '', '', 0);
drop table if exists product_property;
create table product_property
(
id bigint comment '主键',
id bigint NOT NULL AUTO_INCREMENT comment '主键',
name varchar(64) comment '规格名称',
status tinyint comment '状态 0 开启 1 禁用',
create_time datetime default current_timestamp comment '创建时间',
@ -179,7 +179,7 @@ create table product_property
creator varchar(64) comment '创建人',
updater varchar(64) 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),
key idx_name ( name (32)) comment '规格名称索引'
) comment '规格名称' character set utf8mb4
@ -189,7 +189,7 @@ create table product_property
drop table if exists product_property_value;
create table product_property_value
(
id int comment '主键',
id bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
property_id bigint comment '规格键id',
name varchar(128) comment '规格值名字',
status tinyint comment '状态 1 开启 2 禁用',
@ -198,7 +198,7 @@ create table product_property_value
creator varchar(64) comment '创建人',
updater varchar(64) 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)
) comment '规格值' character set utf8mb4
collate utf8mb4_general_ci;
@ -207,7 +207,7 @@ create table product_property_value
drop table if exists product_spu;
create table product_spu
(
id int comment '主键',
id bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
name varchar(128) comment '商品名称',
sell_point varchar(128) not null comment '卖点',
description text not null comment '描述',
@ -223,7 +223,7 @@ create table product_spu
creator varchar(64) comment '创建人',
updater varchar(64) 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)
) comment '商品spu' character set utf8mb4
collate utf8mb4_general_ci;
@ -233,7 +233,7 @@ create table product_spu
drop table if exists product_sku;
create table product_sku
(
id int comment '主键',
id bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
spu_id bigint not null comment 'spu编号',
properties varchar(64) not null comment '规格值数组-json格式 [{propertId: , valueId: }, {propertId: , valueId: }]',
price int not null DEFAULT -1 comment '销售价格单位',
@ -247,7 +247,7 @@ create table product_sku
creator varchar(64) comment '创建人',
updater varchar(64) 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)
) comment '商品sku' character set utf8mb4
collate utf8mb4_general_ci;

View File

@ -1,12 +1,12 @@
package cn.iocoder.yudao.module.product.controller.admin.property;
import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO;
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.*;
@ -22,31 +22,30 @@ 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.property.vo.*;
import cn.iocoder.yudao.module.product.dal.dataobject.property.PropertyDO;
import cn.iocoder.yudao.module.product.convert.property.PropertyConvert;
import cn.iocoder.yudao.module.product.service.property.PropertyService;
import cn.iocoder.yudao.module.product.convert.property.ProductPropertyConvert;
import cn.iocoder.yudao.module.product.service.property.ProductPropertyService;
@Api(tags = "管理后台 - 规格名称")
@RestController
@RequestMapping("/product/property")
@Validated
public class PropertyController {
public class ProductPropertyController {
@Resource
private PropertyService propertyService;
private ProductPropertyService productPropertyService;
@PostMapping("/create")
@ApiOperation("创建规格名称")
@PreAuthorize("@ss.hasPermission('product:property:create')")
public CommonResult<Long> createProperty(@Valid @RequestBody PropertyCreateReqVO createReqVO) {
return success(propertyService.createProperty(createReqVO));
public CommonResult<Long> createProperty(@Valid @RequestBody ProductPropertyCreateReqVO createReqVO) {
return success(productPropertyService.createProperty(createReqVO));
}
@PutMapping("/update")
@ApiOperation("更新规格名称")
@PreAuthorize("@ss.hasPermission('product:property:update')")
public CommonResult<Boolean> updateProperty(@Valid @RequestBody PropertyUpdateReqVO updateReqVO) {
propertyService.updateProperty(updateReqVO);
public CommonResult<Boolean> updateProperty(@Valid @RequestBody ProductPropertyUpdateReqVO updateReqVO) {
productPropertyService.updateProperty(updateReqVO);
return success(true);
}
@ -55,7 +54,7 @@ public class PropertyController {
@ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
@PreAuthorize("@ss.hasPermission('product:property:delete')")
public CommonResult<Boolean> deleteProperty(@RequestParam("id") Long id) {
propertyService.deleteProperty(id);
productPropertyService.deleteProperty(id);
return success(true);
}
@ -63,38 +62,36 @@ public class PropertyController {
@ApiOperation("获得规格名称")
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
@PreAuthorize("@ss.hasPermission('product:property:query')")
public CommonResult<PropertyRespVO> getProperty(@RequestParam("id") Long id) {
PropertyDO property = propertyService.getProperty(id);
return success(PropertyConvert.INSTANCE.convert(property));
public CommonResult<ProductPropertyRespVO> getProperty(@RequestParam("id") Long id) {
return success(productPropertyService.getPropertyResp(id));
}
@GetMapping("/list")
@ApiOperation("获得规格名称列表")
@ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
@PreAuthorize("@ss.hasPermission('product:property:query')")
public CommonResult<List<PropertyRespVO>> getPropertyList(@RequestParam("ids") Collection<Long> ids) {
List<PropertyDO> list = propertyService.getPropertyList(ids);
return success(PropertyConvert.INSTANCE.convertList(list));
public CommonResult<List<ProductPropertyRespVO>> getPropertyList(@RequestParam("ids") Collection<Long> ids) {
List<ProductPropertyDO> list = productPropertyService.getPropertyList(ids);
return success(ProductPropertyConvert.INSTANCE.convertList(list));
}
@GetMapping("/page")
@ApiOperation("获得规格名称分页")
@PreAuthorize("@ss.hasPermission('product:property:query')")
public CommonResult<PageResult<PropertyRespVO>> getPropertyPage(@Valid PropertyPageReqVO pageVO) {
PageResult<PropertyDO> pageResult = propertyService.getPropertyPage(pageVO);
return success(PropertyConvert.INSTANCE.convertPage(pageResult));
public CommonResult<PageResult<ProductPropertyRespVO>> getPropertyPage(@Valid ProductPropertyPageReqVO pageVO) {
return success(productPropertyService.getPropertyListPage(pageVO));
}
@GetMapping("/export-excel")
@ApiOperation("导出规格名称 Excel")
@PreAuthorize("@ss.hasPermission('product:property:export')")
@OperateLog(type = EXPORT)
public void exportPropertyExcel(@Valid PropertyExportReqVO exportReqVO,
public void exportPropertyExcel(@Valid ProductPropertyExportReqVO exportReqVO,
HttpServletResponse response) throws IOException {
List<PropertyDO> list = propertyService.getPropertyList(exportReqVO);
List<ProductPropertyDO> list = productPropertyService.getPropertyList(exportReqVO);
// 导出 Excel
List<PropertyExcelVO> datas = PropertyConvert.INSTANCE.convertList02(list);
ExcelUtils.write(response, "规格名称.xls", "数据", PropertyExcelVO.class, datas);
List<ProductPropertyExcelVO> datas = ProductPropertyConvert.INSTANCE.convertList02(list);
ExcelUtils.write(response, "规格名称.xls", "数据", ProductPropertyExcelVO.class, datas);
}
}

View File

@ -10,7 +10,7 @@ import javax.validation.constraints.*;
* 如果子 VO 存在差异的字段请不要添加到这里影响 Swagger 文档生成
*/
@Data
public class PropertyBaseVO {
public class ProductPropertyBaseVO {
@ApiModelProperty(value = "规格名称")
private String name;

View File

@ -0,0 +1,20 @@
package cn.iocoder.yudao.module.product.controller.admin.property.vo;
import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.ProductPropertyValueCreateReqVO;
import lombok.*;
import io.swagger.annotations.*;
import javax.validation.constraints.NotNull;
import java.util.List;
@ApiModel("管理后台 - 规格名称创建 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ProductPropertyCreateReqVO extends ProductPropertyBaseVO {
@ApiModelProperty(value = "属性值")
@NotNull(message = "属性值不能为空")
List<ProductPropertyValueCreateReqVO> propertyValueList;
}

View File

@ -12,7 +12,7 @@ import com.alibaba.excel.annotation.ExcelProperty;
* @author 芋道源码
*/
@Data
public class PropertyExcelVO {
public class ProductPropertyExcelVO {
@ExcelProperty("主键")
private Long id;

View File

@ -10,7 +10,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
@ApiModel(value = "管理后台 - 规格名称 Excel 导出 Request VO", description = "参数和 PropertyPageReqVO 是一致的")
@Data
public class PropertyExportReqVO {
public class ProductPropertyExportReqVO {
@ApiModelProperty(value = "规格名称")
private String name;

View File

@ -12,7 +12,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class PropertyPageReqVO extends PageParam {
public class ProductPropertyPageReqVO extends PageParam {
@ApiModelProperty(value = "规格名称")
private String name;

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.product.controller.admin.property.vo;
import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.ProductPropertyValueRespVO;
import lombok.*;
import java.util.*;
import io.swagger.annotations.*;
@ -8,7 +9,7 @@ import io.swagger.annotations.*;
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class PropertyRespVO extends PropertyBaseVO {
public class ProductPropertyRespVO extends ProductPropertyBaseVO {
@ApiModelProperty(value = "主键", required = true)
private Long id;
@ -16,4 +17,7 @@ public class PropertyRespVO extends PropertyBaseVO {
@ApiModelProperty(value = "创建时间")
private Date createTime;
@ApiModelProperty(value = "属性值")
private List<ProductPropertyValueRespVO> propertyValueList;
}

View File

@ -1,18 +1,23 @@
package cn.iocoder.yudao.module.product.controller.admin.property.vo;
import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.ProductPropertyValueCreateReqVO;
import lombok.*;
import java.util.*;
import io.swagger.annotations.*;
import javax.validation.constraints.*;
import java.util.List;
@ApiModel("管理后台 - 规格名称更新 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class PropertyUpdateReqVO extends PropertyBaseVO {
public class ProductPropertyUpdateReqVO extends ProductPropertyBaseVO {
@ApiModelProperty(value = "主键", required = true)
@NotNull(message = "主键不能为空")
private Long id;
@ApiModelProperty(value = "属性值")
@NotNull(message = "属性值不能为空")
List<ProductPropertyValueCreateReqVO> propertyValueList;
}

View File

@ -1,14 +0,0 @@
package cn.iocoder.yudao.module.product.controller.admin.property.vo;
import lombok.*;
import java.util.*;
import io.swagger.annotations.*;
import javax.validation.constraints.*;
@ApiModel("管理后台 - 规格名称创建 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class PropertyCreateReqVO extends PropertyBaseVO {
}

View File

@ -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);
}
}

View File

@ -10,7 +10,7 @@ import javax.validation.constraints.*;
* 如果子 VO 存在差异的字段请不要添加到这里影响 Swagger 文档生成
*/
@Data
public class PropertyValueBaseVO {
public class ProductPropertyValueBaseVO {
@ApiModelProperty(value = "规格键id")
private Long propertyId;

View File

@ -1,14 +1,12 @@
package cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo;
import lombok.*;
import java.util.*;
import io.swagger.annotations.*;
import javax.validation.constraints.*;
@ApiModel("管理后台 - 规格值创建 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class PropertyValueCreateReqVO extends PropertyValueBaseVO {
public class ProductPropertyValueCreateReqVO extends ProductPropertyValueBaseVO {
}

View File

@ -8,7 +8,7 @@ import io.swagger.annotations.*;
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class PropertyValueRespVO extends PropertyValueBaseVO {
public class ProductPropertyValueRespVO extends ProductPropertyValueBaseVO {
@ApiModelProperty(value = "主键", required = true)
private Integer id;

View File

@ -1,7 +1,6 @@
package cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo;
import lombok.*;
import java.util.*;
import io.swagger.annotations.*;
import javax.validation.constraints.*;
@ -9,7 +8,7 @@ import javax.validation.constraints.*;
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class PropertyValueUpdateReqVO extends PropertyValueBaseVO {
public class ProductPropertyValueUpdateReqVO extends ProductPropertyValueBaseVO {
@ApiModelProperty(value = "主键", required = true)
@NotNull(message = "主键不能为空")

View File

@ -1,32 +0,0 @@
package cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo;
import lombok.*;
import java.util.*;
import io.swagger.annotations.*;
import com.alibaba.excel.annotation.ExcelProperty;
/**
* 规格值 Excel VO
*
* @author 芋道源码
*/
@Data
public class PropertyValueExcelVO {
@ExcelProperty("主键")
private Integer id;
@ExcelProperty("规格键id")
private Long propertyId;
@ExcelProperty("规格值名字")
private String name;
@ExcelProperty("状态: 1 开启 2 禁用")
private Integer status;
@ExcelProperty("创建时间")
private Date createTime;
}

View File

@ -1,32 +0,0 @@
package cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo;
import lombok.*;
import java.util.*;
import io.swagger.annotations.*;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import org.springframework.format.annotation.DateTimeFormat;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@ApiModel(value = "管理后台 - 规格值 Excel 导出 Request VO", description = "参数和 PropertyValuePageReqVO 是一致的")
@Data
public class PropertyValueExportReqVO {
@ApiModelProperty(value = "规格键id")
private Long propertyId;
@ApiModelProperty(value = "规格值名字")
private String name;
@ApiModelProperty(value = "状态: 1 开启 2 禁用")
private Integer status;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@ApiModelProperty(value = "开始创建时间")
private Date beginCreateTime;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@ApiModelProperty(value = "结束创建时间")
private Date endCreateTime;
}

View File

@ -1,34 +0,0 @@
package cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo;
import lombok.*;
import java.util.*;
import io.swagger.annotations.*;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import org.springframework.format.annotation.DateTimeFormat;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@ApiModel("管理后台 - 规格值分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class PropertyValuePageReqVO extends PageParam {
@ApiModelProperty(value = "规格键id")
private Long propertyId;
@ApiModelProperty(value = "规格值名字")
private String name;
@ApiModelProperty(value = "状态: 1 开启 2 禁用")
private Integer status;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@ApiModelProperty(value = "开始创建时间")
private Date beginCreateTime;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@ApiModelProperty(value = "结束创建时间")
private Date endCreateTime;
}

View File

@ -0,0 +1,34 @@
package cn.iocoder.yudao.module.product.convert.property;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.*;
/**
* 规格名称 Convert
*
* @author 芋道源码
*/
@Mapper
public interface ProductPropertyConvert {
ProductPropertyConvert INSTANCE = Mappers.getMapper(ProductPropertyConvert.class);
ProductPropertyDO convert(ProductPropertyCreateReqVO bean);
ProductPropertyDO convert(ProductPropertyUpdateReqVO bean);
ProductPropertyRespVO convert(ProductPropertyDO bean);
List<ProductPropertyRespVO> convertList(List<ProductPropertyDO> list);
PageResult<ProductPropertyRespVO> convertPage(PageResult<ProductPropertyDO> page);
List<ProductPropertyExcelVO> convertList02(List<ProductPropertyDO> list);
}

View File

@ -1,34 +0,0 @@
package cn.iocoder.yudao.module.product.convert.property;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.*;
import cn.iocoder.yudao.module.product.dal.dataobject.property.PropertyDO;
/**
* 规格名称 Convert
*
* @author 芋道源码
*/
@Mapper
public interface PropertyConvert {
PropertyConvert INSTANCE = Mappers.getMapper(PropertyConvert.class);
PropertyDO convert(PropertyCreateReqVO bean);
PropertyDO convert(PropertyUpdateReqVO bean);
PropertyRespVO convert(PropertyDO bean);
List<PropertyRespVO> convertList(List<PropertyDO> list);
PageResult<PropertyRespVO> convertPage(PageResult<PropertyDO> page);
List<PropertyExcelVO> convertList02(List<PropertyDO> list);
}

View File

@ -0,0 +1,34 @@
package cn.iocoder.yudao.module.product.convert.propertyvalue;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.dal.dataobject.propertyvalue.ProductPropertyValueDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.*;
/**
* 规格值 Convert
*
* @author 芋道源码
*/
@Mapper
public interface ProductPropertyValueConvert {
ProductPropertyValueConvert INSTANCE = Mappers.getMapper(ProductPropertyValueConvert.class);
ProductPropertyValueDO convert(ProductPropertyValueCreateReqVO bean);
ProductPropertyValueDO convert(ProductPropertyValueUpdateReqVO bean);
ProductPropertyValueRespVO convert(ProductPropertyValueDO bean);
List<ProductPropertyValueRespVO> convertList(List<ProductPropertyValueDO> list);
PageResult<ProductPropertyValueRespVO> convertPage(PageResult<ProductPropertyValueDO> page);
List<ProductPropertyValueDO> convertList03(List<ProductPropertyValueCreateReqVO> list);
}

View File

@ -1,34 +0,0 @@
package cn.iocoder.yudao.module.product.convert.propertyvalue;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.*;
import cn.iocoder.yudao.module.product.dal.dataobject.propertyvalue.PropertyValueDO;
/**
* 规格值 Convert
*
* @author 芋道源码
*/
@Mapper
public interface PropertyValueConvert {
PropertyValueConvert INSTANCE = Mappers.getMapper(PropertyValueConvert.class);
PropertyValueDO convert(PropertyValueCreateReqVO bean);
PropertyValueDO convert(PropertyValueUpdateReqVO bean);
PropertyValueRespVO convert(PropertyValueDO bean);
List<PropertyValueRespVO> convertList(List<PropertyValueDO> list);
PageResult<PropertyValueRespVO> convertPage(PageResult<PropertyValueDO> page);
List<PropertyValueExcelVO> convertList02(List<PropertyValueDO> list);
}

View File

@ -7,7 +7,6 @@ import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*;
// TODO @franky每个表名都加个 Product 前缀哈
/**
* 规格名称 DO
*
@ -21,7 +20,7 @@ import lombok.*;
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class PropertyDO extends BaseDO {
public class ProductPropertyDO extends BaseDO {
/**
* 主键
@ -35,7 +34,7 @@ public class PropertyDO extends BaseDO {
/**
* 状态 0 开启 1 禁用
*
* TODO @franky加个 枚举 {@link CommonStatusEnum} 这样就能更好的知道
* {@link CommonStatusEnum}
*/
private Integer status;

View File

@ -1,7 +1,7 @@
package cn.iocoder.yudao.module.product.dal.dataobject.propertyvalue;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.module.product.dal.dataobject.property.PropertyDO;
import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
@ -21,7 +21,7 @@ import lombok.*;
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class PropertyValueDO extends BaseDO {
public class ProductPropertyValueDO extends BaseDO {
/**
* 主键
@ -31,7 +31,7 @@ public class PropertyValueDO extends BaseDO {
/**
* 规格键 id
*
* TODO @franky加个 关联 {@link PropertyDO#getId()} 这样就能更好的知道
* TODO @franky加个 关联 {@link ProductPropertyDO#getId()} 这样就能更好的知道
*/
private Long propertyId;
/**

View File

@ -0,0 +1,36 @@
package cn.iocoder.yudao.module.product.dal.mysql.property;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.*;
/**
* 规格名称 Mapper
*
* @author 芋道源码
*/
@Mapper
public interface ProductPropertyMapper extends BaseMapperX<ProductPropertyDO> {
default PageResult<ProductPropertyDO> selectPage(ProductPropertyPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<ProductPropertyDO>()
.likeIfPresent(ProductPropertyDO::getName, reqVO.getName())
.eqIfPresent(ProductPropertyDO::getStatus, reqVO.getStatus())
.betweenIfPresent(ProductPropertyDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
.orderByDesc(ProductPropertyDO::getId));
}
default List<ProductPropertyDO> selectList(ProductPropertyExportReqVO reqVO) {
return selectList(new LambdaQueryWrapperX<ProductPropertyDO>()
.likeIfPresent(ProductPropertyDO::getName, reqVO.getName())
.eqIfPresent(ProductPropertyDO::getStatus, reqVO.getStatus())
.betweenIfPresent(ProductPropertyDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
.orderByDesc(ProductPropertyDO::getId));
}
}

View File

@ -1,36 +0,0 @@
package cn.iocoder.yudao.module.product.dal.mysql.property;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.product.dal.dataobject.property.PropertyDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.*;
/**
* 规格名称 Mapper
*
* @author 芋道源码
*/
@Mapper
public interface PropertyMapper extends BaseMapperX<PropertyDO> {
default PageResult<PropertyDO> selectPage(PropertyPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<PropertyDO>()
.likeIfPresent(PropertyDO::getName, reqVO.getName())
.eqIfPresent(PropertyDO::getStatus, reqVO.getStatus())
.betweenIfPresent(PropertyDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
.orderByDesc(PropertyDO::getId));
}
default List<PropertyDO> selectList(PropertyExportReqVO reqVO) {
return selectList(new LambdaQueryWrapperX<PropertyDO>()
.likeIfPresent(PropertyDO::getName, reqVO.getName())
.eqIfPresent(PropertyDO::getStatus, reqVO.getStatus())
.betweenIfPresent(PropertyDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
.orderByDesc(PropertyDO::getId));
}
}

View File

@ -0,0 +1,29 @@
package cn.iocoder.yudao.module.product.dal.mysql.propertyvalue;
import java.util.*;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.product.dal.dataobject.propertyvalue.ProductPropertyValueDO;
import org.apache.ibatis.annotations.Mapper;
/**
* 规格值 Mapper
*
* @author 芋道源码
*/
@Mapper
public interface ProductPropertyValueMapper extends BaseMapperX<ProductPropertyValueDO> {
default List<ProductPropertyValueDO> getPropertyValueListByPropertyId(List<Long> propertyIds){
return selectList(new LambdaQueryWrapperX<ProductPropertyValueDO>()
.inIfPresent(ProductPropertyValueDO::getPropertyId, propertyIds));
}
default void deletePropertyValueByPropertyId(Long propertyId){
LambdaQueryWrapperX<ProductPropertyValueDO> queryWrapperX = new LambdaQueryWrapperX<>();
queryWrapperX.eq(ProductPropertyValueDO::getPropertyId, propertyId)
.eq(ProductPropertyValueDO::getDeleted, false);
delete(queryWrapperX);
}
}

View File

@ -1,38 +0,0 @@
package cn.iocoder.yudao.module.product.dal.mysql.propertyvalue;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.product.dal.dataobject.propertyvalue.PropertyValueDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.*;
/**
* 规格值 Mapper
*
* @author 芋道源码
*/
@Mapper
public interface PropertyValueMapper extends BaseMapperX<PropertyValueDO> {
default PageResult<PropertyValueDO> selectPage(PropertyValuePageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<PropertyValueDO>()
.eqIfPresent(PropertyValueDO::getPropertyId, reqVO.getPropertyId())
.likeIfPresent(PropertyValueDO::getName, reqVO.getName())
.eqIfPresent(PropertyValueDO::getStatus, reqVO.getStatus())
.betweenIfPresent(PropertyValueDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
.orderByDesc(PropertyValueDO::getId));
}
default List<PropertyValueDO> selectList(PropertyValueExportReqVO reqVO) {
return selectList(new LambdaQueryWrapperX<PropertyValueDO>()
.eqIfPresent(PropertyValueDO::getPropertyId, reqVO.getPropertyId())
.likeIfPresent(PropertyValueDO::getName, reqVO.getName())
.eqIfPresent(PropertyValueDO::getStatus, reqVO.getStatus())
.betweenIfPresent(PropertyValueDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
.orderByDesc(PropertyValueDO::getId));
}
}

View File

@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.product.service.property;
import java.util.*;
import javax.validation.*;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.*;
import cn.iocoder.yudao.module.product.dal.dataobject.property.PropertyDO;
import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
/**
@ -11,7 +11,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
*
* @author 芋道源码
*/
public interface PropertyService {
public interface ProductPropertyService {
/**
* 创建规格名称
@ -19,14 +19,14 @@ public interface PropertyService {
* @param createReqVO 创建信息
* @return 编号
*/
Long createProperty(@Valid PropertyCreateReqVO createReqVO);
Long createProperty(@Valid ProductPropertyCreateReqVO createReqVO);
/**
* 更新规格名称
*
* @param updateReqVO 更新信息
*/
void updateProperty(@Valid PropertyUpdateReqVO updateReqVO);
void updateProperty(@Valid ProductPropertyUpdateReqVO updateReqVO);
/**
* 删除规格名称
@ -41,7 +41,7 @@ public interface PropertyService {
* @param id 编号
* @return 规格名称
*/
PropertyDO getProperty(Long id);
ProductPropertyDO getProperty(Long id);
/**
* 获得规格名称列表
@ -49,7 +49,7 @@ public interface PropertyService {
* @param ids 编号
* @return 规格名称列表
*/
List<PropertyDO> getPropertyList(Collection<Long> ids);
List<ProductPropertyDO> getPropertyList(Collection<Long> ids);
/**
* 获得规格名称分页
@ -57,7 +57,7 @@ public interface PropertyService {
* @param pageReqVO 分页查询
* @return 规格名称分页
*/
PageResult<PropertyDO> getPropertyPage(PropertyPageReqVO pageReqVO);
PageResult<ProductPropertyDO> getPropertyPage(ProductPropertyPageReqVO pageReqVO);
/**
* 获得规格名称列表, 用于 Excel 导出
@ -65,6 +65,15 @@ public interface PropertyService {
* @param exportReqVO 查询条件
* @return 规格名称列表
*/
List<PropertyDO> getPropertyList(PropertyExportReqVO exportReqVO);
List<ProductPropertyDO> getPropertyList(ProductPropertyExportReqVO exportReqVO);
/**
* 获取属性及属性值列表 分页
* @param pageReqVO
* @return
*/
PageResult<ProductPropertyRespVO> getPropertyListPage(ProductPropertyPageReqVO pageReqVO);
ProductPropertyRespVO getPropertyResp(Long id);
}

View File

@ -0,0 +1,143 @@
package cn.iocoder.yudao.module.product.service.property;
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.ProductPropertyCreateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.ProductPropertyUpdateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.ProductPropertyValueCreateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.ProductPropertyValueRespVO;
import cn.iocoder.yudao.module.product.convert.property.ProductPropertyConvert;
import cn.iocoder.yudao.module.product.convert.propertyvalue.ProductPropertyValueConvert;
import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO;
import cn.iocoder.yudao.module.product.dal.dataobject.propertyvalue.ProductPropertyValueDO;
import cn.iocoder.yudao.module.product.dal.mysql.property.ProductPropertyMapper;
import cn.iocoder.yudao.module.product.service.propertyvalue.ProductPropertyValueService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Collection;
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.module.product.enums.ErrorCodeConstants.PROPERTY_NOT_EXISTS;
/**
* 规格名称 Service 实现类
*
* @author 芋道源码
*/
@Service
@Validated
public class ProductPropertyServiceImpl implements ProductPropertyService {
@Resource
private ProductPropertyMapper productPropertyMapper;
@Resource
private ProductPropertyValueService productPropertyValueService;
@Override
@Transactional(rollbackFor = Exception.class)
public Long createProperty(ProductPropertyCreateReqVO createReqVO) {
// 插入
ProductPropertyDO property = ProductPropertyConvert.INSTANCE.convert(createReqVO);
productPropertyMapper.insert(property);
//插入属性值
List<ProductPropertyValueCreateReqVO> propertyValueList = createReqVO.getPropertyValueList();
List<ProductPropertyValueDO> productPropertyValueDOList = ProductPropertyValueConvert.INSTANCE.convertList03(propertyValueList);
productPropertyValueDOList.stream().forEach(x-> x.setPropertyId(property.getId()));
productPropertyValueService.batchInsert(productPropertyValueDOList);
// 返回
return property.getId();
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateProperty(ProductPropertyUpdateReqVO updateReqVO) {
// 校验存在
this.validatePropertyExists(updateReqVO.getId());
// 更新
ProductPropertyDO updateObj = ProductPropertyConvert.INSTANCE.convert(updateReqVO);
productPropertyMapper.updateById(updateObj);
//更新属性值先删后加
productPropertyValueService.deletePropertyValueByPropertyId(updateReqVO.getId());
List<ProductPropertyValueCreateReqVO> propertyValueList = updateReqVO.getPropertyValueList();
List<ProductPropertyValueDO> productPropertyValueDOList = ProductPropertyValueConvert.INSTANCE.convertList03(propertyValueList);
productPropertyValueDOList.stream().forEach(x-> x.setPropertyId(updateReqVO.getId()));
productPropertyValueService.batchInsert(productPropertyValueDOList);
}
@Override
public void deleteProperty(Long id) {
// 校验存在
this.validatePropertyExists(id);
// 删除
productPropertyMapper.deleteById(id);
//同步删除属性值
productPropertyValueService.deletePropertyValueByPropertyId(id);
}
private void validatePropertyExists(Long id) {
if (productPropertyMapper.selectById(id) == null) {
throw exception(PROPERTY_NOT_EXISTS);
}
}
@Override
public ProductPropertyDO getProperty(Long id) {
return productPropertyMapper.selectById(id);
}
@Override
public List<ProductPropertyDO> getPropertyList(Collection<Long> ids) {
return productPropertyMapper.selectBatchIds(ids);
}
@Override
public PageResult<ProductPropertyDO> getPropertyPage(ProductPropertyPageReqVO pageReqVO) {
return productPropertyMapper.selectPage(pageReqVO);
}
@Override
public List<ProductPropertyDO> getPropertyList(ProductPropertyExportReqVO 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<ProductPropertyValueDO> productPropertyValueDOList = productPropertyValueService.getPropertyValueListByPropertyId(propertyIds);
List<ProductPropertyValueRespVO> propertyValueRespVOList = ProductPropertyValueConvert.INSTANCE.convertList(productPropertyValueDOList);
//组装一对多
propertyRespVOPageResult.getList().stream().forEach(x->{
Long propertyId = x.getId();
List<ProductPropertyValueRespVO> 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<ProductPropertyValueDO> valueDOList = productPropertyValueService.getPropertyValueListByPropertyId(Arrays.asList(id));
List<ProductPropertyValueRespVO> propertyValueRespVOS = ProductPropertyValueConvert.INSTANCE.convertList(valueDOList);
//组装
propertyRespVO.setPropertyValueList(propertyValueRespVOS);
return propertyRespVO;
}
}

View File

@ -1,85 +0,0 @@
package cn.iocoder.yudao.module.product.service.property;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.PropertyCreateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.PropertyExportReqVO;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.PropertyPageReqVO;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.PropertyUpdateReqVO;
import cn.iocoder.yudao.module.product.convert.property.PropertyConvert;
import cn.iocoder.yudao.module.product.dal.dataobject.property.PropertyDO;
import cn.iocoder.yudao.module.product.dal.mysql.property.PropertyMapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PROPERTY_NOT_EXISTS;
/**
* 规格名称 Service 实现类
*
* @author 芋道源码
*/
@Service
@Validated
public class PropertyServiceImpl implements PropertyService {
@Resource
private PropertyMapper propertyMapper;
@Override
public Long createProperty(PropertyCreateReqVO createReqVO) {
// 插入
PropertyDO property = PropertyConvert.INSTANCE.convert(createReqVO);
propertyMapper.insert(property);
// 返回
return property.getId();
}
@Override
public void updateProperty(PropertyUpdateReqVO updateReqVO) {
// 校验存在
this.validatePropertyExists(updateReqVO.getId());
// 更新
PropertyDO updateObj = PropertyConvert.INSTANCE.convert(updateReqVO);
propertyMapper.updateById(updateObj);
}
@Override
public void deleteProperty(Long id) {
// 校验存在
this.validatePropertyExists(id);
// 删除
propertyMapper.deleteById(id);
}
private void validatePropertyExists(Long id) {
if (propertyMapper.selectById(id) == null) {
throw exception(PROPERTY_NOT_EXISTS);
}
}
@Override
public PropertyDO getProperty(Long id) {
return propertyMapper.selectById(id);
}
@Override
public List<PropertyDO> getPropertyList(Collection<Long> ids) {
return propertyMapper.selectBatchIds(ids);
}
@Override
public PageResult<PropertyDO> getPropertyPage(PropertyPageReqVO pageReqVO) {
return propertyMapper.selectPage(pageReqVO);
}
@Override
public List<PropertyDO> getPropertyList(PropertyExportReqVO exportReqVO) {
return propertyMapper.selectList(exportReqVO);
}
}

View File

@ -0,0 +1,88 @@
package cn.iocoder.yudao.module.product.service.propertyvalue;
import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.*;
import cn.iocoder.yudao.module.product.convert.propertyvalue.ProductPropertyValueConvert;
import cn.iocoder.yudao.module.product.dal.dataobject.propertyvalue.ProductPropertyValueDO;
import cn.iocoder.yudao.module.product.dal.mysql.propertyvalue.ProductPropertyValueMapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PROPERTY_VALUE_NOT_EXISTS;
/**
* 规格值 Service 实现类
*
* @author 芋道源码
*/
@Service
@Validated
public class ProductProductPropertyValueServiceImpl implements ProductPropertyValueService {
@Resource
private ProductPropertyValueMapper productPropertyValueMapper;
// TODO @franky这个合并到 property 他们本身是在一起的哈基本不存在只查询规格而不查询规格值
@Override
public Integer createPropertyValue(ProductPropertyValueCreateReqVO createReqVO) {
// 插入
ProductPropertyValueDO propertyValue = ProductPropertyValueConvert.INSTANCE.convert(createReqVO);
productPropertyValueMapper.insert(propertyValue);
// 返回
return propertyValue.getId();
}
@Override
public void updatePropertyValue(ProductPropertyValueUpdateReqVO updateReqVO) {
// 校验存在
this.validatePropertyValueExists(updateReqVO.getId());
// 更新
ProductPropertyValueDO updateObj = ProductPropertyValueConvert.INSTANCE.convert(updateReqVO);
productPropertyValueMapper.updateById(updateObj);
}
@Override
public void deletePropertyValue(Integer id) {
// 校验存在
this.validatePropertyValueExists(id);
// 删除
productPropertyValueMapper.deleteById(id);
}
private void validatePropertyValueExists(Integer id) {
if (productPropertyValueMapper.selectById(id) == null) {
throw exception(PROPERTY_VALUE_NOT_EXISTS);
}
}
@Override
public ProductPropertyValueDO getPropertyValue(Integer id) {
return productPropertyValueMapper.selectById(id);
}
@Override
public List<ProductPropertyValueDO> getPropertyValueList(Collection<Integer> ids) {
return productPropertyValueMapper.selectBatchIds(ids);
}
@Override
public void batchInsert(List<ProductPropertyValueDO> propertyValues) {
productPropertyValueMapper.insertBatch(propertyValues);
}
@Override
public List<ProductPropertyValueDO> getPropertyValueListByPropertyId(List<Long> propertyIds) {
return productPropertyValueMapper.getPropertyValueListByPropertyId(propertyIds);
}
@Override
public void deletePropertyValueByPropertyId(Long propertyId) {
productPropertyValueMapper.deletePropertyValueByPropertyId(propertyId);
}
}

View File

@ -3,15 +3,14 @@ package cn.iocoder.yudao.module.product.service.propertyvalue;
import java.util.*;
import javax.validation.*;
import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.*;
import cn.iocoder.yudao.module.product.dal.dataobject.propertyvalue.PropertyValueDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.dal.dataobject.propertyvalue.ProductPropertyValueDO;
/**
* 规格值 Service 接口
*
* @author 芋道源码
*/
public interface PropertyValueService {
public interface ProductPropertyValueService {
/**
* 创建规格值
@ -19,14 +18,14 @@ public interface PropertyValueService {
* @param createReqVO 创建信息
* @return 编号
*/
Integer createPropertyValue(@Valid PropertyValueCreateReqVO createReqVO);
Integer createPropertyValue(@Valid ProductPropertyValueCreateReqVO createReqVO);
/**
* 更新规格值
*
* @param updateReqVO 更新信息
*/
void updatePropertyValue(@Valid PropertyValueUpdateReqVO updateReqVO);
void updatePropertyValue(@Valid ProductPropertyValueUpdateReqVO updateReqVO);
/**
* 删除规格值
@ -41,7 +40,7 @@ public interface PropertyValueService {
* @param id 编号
* @return 规格值
*/
PropertyValueDO getPropertyValue(Integer id);
ProductPropertyValueDO getPropertyValue(Integer id);
/**
* 获得规格值列表
@ -49,22 +48,24 @@ public interface PropertyValueService {
* @param ids 编号
* @return 规格值列表
*/
List<PropertyValueDO> getPropertyValueList(Collection<Integer> ids);
List<ProductPropertyValueDO> getPropertyValueList(Collection<Integer> ids);
/**
* 获得规格值分页
*
* @param pageReqVO 分页查询
* @return 规格值分页
* 批量插入属性值
* @param propertyValues
*/
PageResult<PropertyValueDO> getPropertyValuePage(PropertyValuePageReqVO pageReqVO);
void batchInsert(List<ProductPropertyValueDO> propertyValues);
/**
* 获得规格值列表, 用于 Excel 导出
*
* @param exportReqVO 查询条件
* @return 规格值列表
* 根据属性id查询
* @param propertyIds
* @return
*/
List<PropertyValueDO> getPropertyValueList(PropertyValueExportReqVO exportReqVO);
List<ProductPropertyValueDO> getPropertyValueListByPropertyId(List<Long> propertyIds);
/**
* 根据属性id 删除
* @param propertyId
*/
void deletePropertyValueByPropertyId(Long propertyId);
}

View File

@ -1,87 +0,0 @@
package cn.iocoder.yudao.module.product.service.propertyvalue;
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.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.dal.dataobject.propertyvalue.PropertyValueDO;
import cn.iocoder.yudao.module.product.dal.mysql.propertyvalue.PropertyValueMapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PROPERTY_VALUE_NOT_EXISTS;
/**
* 规格值 Service 实现类
*
* @author 芋道源码
*/
@Service
@Validated
public class PropertyValueServiceImpl implements PropertyValueService {
@Resource
private PropertyValueMapper propertyValueMapper;
// TODO @franky这个合并到 property 他们本身是在一起的哈基本不存在只查询规格而不查询规格值
@Override
public Integer createPropertyValue(PropertyValueCreateReqVO createReqVO) {
// 插入
PropertyValueDO propertyValue = PropertyValueConvert.INSTANCE.convert(createReqVO);
propertyValueMapper.insert(propertyValue);
// 返回
return propertyValue.getId();
}
@Override
public void updatePropertyValue(PropertyValueUpdateReqVO updateReqVO) {
// 校验存在
this.validatePropertyValueExists(updateReqVO.getId());
// 更新
PropertyValueDO updateObj = PropertyValueConvert.INSTANCE.convert(updateReqVO);
propertyValueMapper.updateById(updateObj);
}
@Override
public void deletePropertyValue(Integer id) {
// 校验存在
this.validatePropertyValueExists(id);
// 删除
propertyValueMapper.deleteById(id);
}
private void validatePropertyValueExists(Integer id) {
if (propertyValueMapper.selectById(id) == null) {
throw exception(PROPERTY_VALUE_NOT_EXISTS);
}
}
@Override
public PropertyValueDO getPropertyValue(Integer id) {
return propertyValueMapper.selectById(id);
}
@Override
public List<PropertyValueDO> getPropertyValueList(Collection<Integer> ids) {
return propertyValueMapper.selectBatchIds(ids);
}
@Override
public PageResult<PropertyValueDO> getPropertyValuePage(PropertyValuePageReqVO pageReqVO) {
return propertyValueMapper.selectPage(pageReqVO);
}
@Override
public List<PropertyValueDO> getPropertyValueList(PropertyValueExportReqVO exportReqVO) {
return propertyValueMapper.selectList(exportReqVO);
}
}

View File

@ -24,16 +24,17 @@
<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
v-hasPermi="['product:property:create']">新增</el-button>
</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>
</el-row>
<!-- 列表 -->
<el-table v-loading="loading" :data="list">
<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">
<template slot-scope="scope">
<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-form-item>
<el-form-item
v-for="(domain, index) in form.propertyValues"
v-for="(domain, index) in form.propertyValueList"
:key="domain.key"
:prop="'propertyValues.' + index + '.value'"
:prop="'propertyValueList.' + index + '.name'"
:rules="{
required: true, message: '域名不能为空', trigger: 'blur'
required: true, message: '属性值不能为空', trigger: 'blur'
}"
>
<el-row>
<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 :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-row>
</el-form-item>
@ -134,8 +135,8 @@ export default {
form: {
name:'',
status:'',
propertyValues: [{
value: ''
propertyValueList: [{
name: ''
}],
},
//
@ -171,12 +172,10 @@ export default {
id: undefined,
name: undefined,
status: undefined,
propertyValueList: [{
name: ''
}]
};
this.form.propertyValues = [{
key:'',
value: ''
}];
console.log("this.form", this.form)
this.resetForm("form");
},
/** 搜索按钮操作 */
@ -194,7 +193,7 @@ export default {
handleAdd() {
this.reset();
this.open = true;
this.title = "添加规格名称";
this.title = "添加规格";
},
/** 修改按钮操作 */
handleUpdate(row) {
@ -203,7 +202,7 @@ export default {
getProperty(id).then(response => {
this.form = response.data;
this.open = true;
this.title = "修改规格名称";
this.title = "修改规格";
});
},
/** 提交按钮 */
@ -232,7 +231,7 @@ export default {
/** 删除按钮操作 */
handleDelete(row) {
const id = row.id;
this.$modal.confirm('是否确认删除规格名称编号为"' + id + '"的数据项?').then(function() {
this.$modal.confirm('是否确认删除规格名称为"' + row.name + '"的数据项?').then(function() {
return deleteProperty(id);
}).then(() => {
this.getList();
@ -256,17 +255,25 @@ export default {
}).catch(() => {});
},
removePropertyValue(item) {
var index = this.form.propertyValues.indexOf(item)
var index = this.form.propertyValueList.indexOf(item)
if (index !== -1) {
this.form.propertyValues.splice(index, 1)
this.form.propertyValueList.splice(index, 1)
}
},
addPropertyValue() {
console.log("this.form.propertyValues", this.form.propertyValues)
this.form.propertyValues.push({
value: '',
key: Date.now()
this.form.propertyValueList.push({
name: ''
});
},
formatList(list) {
let str = ''
for (var i = 0; i < list.length; i++) {
str += list[i].name;
if(i != list.length-1){
str+="/";
}
}
return str
}
}
};