提交 dea50e99 authored 作者: hzh's avatar hzh

代码优化

上级 c6061c70
...@@ -78,7 +78,7 @@ public class ProductPropertyController { ...@@ -78,7 +78,7 @@ public class ProductPropertyController {
public R<List<ProductPropertyRespVO>> getPropertySimpleList() { public R<List<ProductPropertyRespVO>> getPropertySimpleList() {
List<ProductPropertyDO> list = productPropertyService.getPropertyList(); List<ProductPropertyDO> list = productPropertyService.getPropertyList();
return R.ok(convertList(list, property -> new ProductPropertyRespVO() // 只返回 id、name 属性 return R.ok(convertList(list, property -> new ProductPropertyRespVO() // 只返回 id、name 属性
.setId(property.getId()).setName(property.getName()))); .setId(property.getId()).setName(property.getName()).setType(property.getType())));
} }
} }
...@@ -17,6 +17,9 @@ public class ProductPropertyRespVO { ...@@ -17,6 +17,9 @@ public class ProductPropertyRespVO {
@Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "颜色") @Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "颜色")
private String name; private String name;
@Schema(description = "类型", example = "文本")
private String type;
@Schema(description = "备注", example = "颜色") @Schema(description = "备注", example = "颜色")
private String remark; private String remark;
......
...@@ -15,6 +15,9 @@ public class ProductPropertySaveReqVO { ...@@ -15,6 +15,9 @@ public class ProductPropertySaveReqVO {
@NotBlank(message = "名称不能为空") @NotBlank(message = "名称不能为空")
private String name; private String name;
@Schema(description = "类型")
private String type;
@Schema(description = "备注", example = "颜色") @Schema(description = "备注", example = "颜色")
private String remark; private String remark;
......
...@@ -67,6 +67,9 @@ public class ProductSkuSaveReqVO { ...@@ -67,6 +67,9 @@ public class ProductSkuSaveReqVO {
@Schema(description = "属性名字", example = "颜色") @Schema(description = "属性名字", example = "颜色")
private String propertyName; private String propertyName;
@Schema(description = "属性类型", example = "文本")
private String propertyType;
@Schema(description = "属性值编号", example = "10") @Schema(description = "属性值编号", example = "10")
private Long valueId; private Long valueId;
......
package org.dromara.mall.domain.product; package org.dromara.mall.domain.product;
import org.dromara.common.tenant.core.TenantEntity; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.*; import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import org.dromara.common.tenant.core.TenantEntity;
import org.dromara.mall.enums.product.spu.ProductPropertyTypeEnum;
import java.io.Serial; import java.io.Serial;
...@@ -29,6 +32,10 @@ public class ProductPropertyDO extends TenantEntity { ...@@ -29,6 +32,10 @@ public class ProductPropertyDO extends TenantEntity {
* SPU 单规格时,默认属性名字 * SPU 单规格时,默认属性名字
*/ */
public static final String NAME_DEFAULT = "默认"; public static final String NAME_DEFAULT = "默认";
/**
* SPU 单规格时,默认属性类型
*/
public static final String TYPE_DEFAULT = ProductPropertyTypeEnum.TEXT.name();
/** /**
* 编号 * 编号
...@@ -40,6 +47,10 @@ public class ProductPropertyDO extends TenantEntity { ...@@ -40,6 +47,10 @@ public class ProductPropertyDO extends TenantEntity {
* 名称 * 名称
*/ */
private String name; private String name;
/**
* 类型
*/
private String type;
/** /**
* 备注 * 备注
*/ */
......
package org.dromara.mall.enums.product.spu;
import lombok.Getter;
/**
* @author wenhe
*/
@Getter
public enum ProductPropertyTypeEnum {
/**
* 文本
*/
TEXT,
/**
* 日期
*/
DATE;
}
...@@ -2,6 +2,7 @@ package org.dromara.mall.service.product.impl; ...@@ -2,6 +2,7 @@ package org.dromara.mall.service.product.impl;
import cn.hutool.core.util.ObjUtil; import cn.hutool.core.util.ObjUtil;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.mall.util.object.BeanUtils; import org.dromara.common.mall.util.object.BeanUtils;
import org.dromara.common.mybatis.core.page.PageResult; import org.dromara.common.mybatis.core.page.PageResult;
import org.dromara.common.mybatis.core.query.LambdaQueryWrapperX; import org.dromara.common.mybatis.core.query.LambdaQueryWrapperX;
...@@ -56,6 +57,9 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { ...@@ -56,6 +57,9 @@ public class ProductPropertyServiceImpl implements ProductPropertyService {
// 插入 // 插入
ProductPropertyDO property = BeanUtils.toBean(createReqVO, ProductPropertyDO.class); ProductPropertyDO property = BeanUtils.toBean(createReqVO, ProductPropertyDO.class);
property.setDeptId(LoginHelper.getDeptId()); property.setDeptId(LoginHelper.getDeptId());
if (StringUtils.isEmpty(property.getType())) {
property.setType(ProductPropertyDO.TYPE_DEFAULT);
}
productPropertyMapper.insert(property); productPropertyMapper.insert(property);
// 返回 // 返回
return property.getId(); return property.getId();
...@@ -74,6 +78,7 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { ...@@ -74,6 +78,7 @@ public class ProductPropertyServiceImpl implements ProductPropertyService {
// 更新 // 更新
ProductPropertyDO updateObj = BeanUtils.toBean(updateReqVO, ProductPropertyDO.class); ProductPropertyDO updateObj = BeanUtils.toBean(updateReqVO, ProductPropertyDO.class);
updateObj.setType(null);
productPropertyMapper.updateById(updateObj); productPropertyMapper.updateById(updateObj);
// 更新 sku 相关属性 // 更新 sku 相关属性
productSkuService.updateSkuProperty(updateObj.getId(), updateObj.getName()); productSkuService.updateSkuProperty(updateObj.getId(), updateObj.getName());
......
...@@ -90,7 +90,7 @@ public class ProductSkuServiceImpl implements ProductSkuService { ...@@ -90,7 +90,7 @@ public class ProductSkuServiceImpl implements ProductSkuService {
ProductSkuSaveReqVO skuVO = skus.get(0); ProductSkuSaveReqVO skuVO = skus.get(0);
List<ProductSkuSaveReqVO.Property> properties = new ArrayList<>(); List<ProductSkuSaveReqVO.Property> properties = new ArrayList<>();
ProductSkuSaveReqVO.Property property = new ProductSkuSaveReqVO.Property() ProductSkuSaveReqVO.Property property = new ProductSkuSaveReqVO.Property()
.setPropertyId(ProductPropertyDO.ID_DEFAULT).setPropertyName(ProductPropertyDO.NAME_DEFAULT) .setPropertyId(ProductPropertyDO.ID_DEFAULT).setPropertyName(ProductPropertyDO.NAME_DEFAULT).setPropertyType(ProductPropertyDO.TYPE_DEFAULT)
.setValueId(ProductPropertyValueDO.ID_DEFAULT).setValueName(ProductPropertyValueDO.NAME_DEFAULT); .setValueId(ProductPropertyValueDO.ID_DEFAULT).setValueName(ProductPropertyValueDO.NAME_DEFAULT);
properties.add(property); properties.add(property);
skuVO.setProperties(properties); skuVO.setProperties(properties);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论