Commit 204a5ba28497cca1dfdfd1d4af4ac9985b955cde
1 parent
a270db82
规格增删改查接口及页面提交
Showing
13 changed files
with
172 additions
and
142 deletions
sql/mall.sql
| @@ -171,7 +171,7 @@ VALUES ('商品导出', 'product:spu:export', 3, 5, @parentId, '', '', '', 0); | @@ -171,7 +171,7 @@ VALUES ('商品导出', 'product:spu:export', 3, 5, @parentId, '', '', '', 0); | ||
| 171 | drop table if exists product_property; | 171 | drop table if exists product_property; |
| 172 | create table product_property | 172 | create table product_property |
| 173 | ( | 173 | ( |
| 174 | - id bigint comment '主键', | 174 | + id bigint NOT NULL AUTO_INCREMENT comment '主键', |
| 175 | name varchar(64) comment '规格名称', | 175 | name varchar(64) comment '规格名称', |
| 176 | status tinyint comment '状态: 0 开启 ,1 禁用', | 176 | status tinyint comment '状态: 0 开启 ,1 禁用', |
| 177 | create_time datetime default current_timestamp comment '创建时间', | 177 | create_time datetime default current_timestamp comment '创建时间', |
| @@ -179,7 +179,7 @@ create table product_property | @@ -179,7 +179,7 @@ create table product_property | ||
| 179 | creator varchar(64) comment '创建人', | 179 | creator varchar(64) comment '创建人', |
| 180 | updater varchar(64) comment '更新人', | 180 | updater varchar(64) comment '更新人', |
| 181 | tenant_id bigint NOT NULL DEFAULT '0' COMMENT '租户编号', | 181 | tenant_id bigint NOT NULL DEFAULT '0' COMMENT '租户编号', |
| 182 | - deleted bit(1) comment '状态', | 182 | + deleted bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', |
| 183 | primary key (id), | 183 | primary key (id), |
| 184 | key idx_name ( name (32)) comment '规格名称索引' | 184 | key idx_name ( name (32)) comment '规格名称索引' |
| 185 | ) comment '规格名称' character set utf8mb4 | 185 | ) comment '规格名称' character set utf8mb4 |
| @@ -189,7 +189,7 @@ create table product_property | @@ -189,7 +189,7 @@ create table product_property | ||
| 189 | drop table if exists product_property_value; | 189 | drop table if exists product_property_value; |
| 190 | create table product_property_value | 190 | create table product_property_value |
| 191 | ( | 191 | ( |
| 192 | - id int comment '主键', | 192 | + id bigint NOT NULL AUTO_INCREMENT COMMENT '主键', |
| 193 | property_id bigint comment '规格键id', | 193 | property_id bigint comment '规格键id', |
| 194 | name varchar(128) comment '规格值名字', | 194 | name varchar(128) comment '规格值名字', |
| 195 | status tinyint comment '状态: 1 开启 ,2 禁用', | 195 | status tinyint comment '状态: 1 开启 ,2 禁用', |
| @@ -198,7 +198,7 @@ create table product_property_value | @@ -198,7 +198,7 @@ create table product_property_value | ||
| 198 | creator varchar(64) comment '创建人', | 198 | creator varchar(64) comment '创建人', |
| 199 | updater varchar(64) comment '更新人', | 199 | updater varchar(64) comment '更新人', |
| 200 | tenant_id bigint NOT NULL DEFAULT '0' COMMENT '租户编号', | 200 | tenant_id bigint NOT NULL DEFAULT '0' COMMENT '租户编号', |
| 201 | - deleted bit(1) comment '状态', | 201 | + deleted bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', |
| 202 | primary key (id) | 202 | primary key (id) |
| 203 | ) comment '规格值' character set utf8mb4 | 203 | ) comment '规格值' character set utf8mb4 |
| 204 | collate utf8mb4_general_ci; | 204 | collate utf8mb4_general_ci; |
| @@ -207,7 +207,7 @@ create table product_property_value | @@ -207,7 +207,7 @@ create table product_property_value | ||
| 207 | drop table if exists product_spu; | 207 | drop table if exists product_spu; |
| 208 | create table product_spu | 208 | create table product_spu |
| 209 | ( | 209 | ( |
| 210 | - id int comment '主键', | 210 | + id bigint NOT NULL AUTO_INCREMENT COMMENT '主键', |
| 211 | name varchar(128) comment '商品名称', | 211 | name varchar(128) comment '商品名称', |
| 212 | sell_point varchar(128) not null comment '卖点', | 212 | sell_point varchar(128) not null comment '卖点', |
| 213 | description text not null comment '描述', | 213 | description text not null comment '描述', |
| @@ -223,7 +223,7 @@ create table product_spu | @@ -223,7 +223,7 @@ create table product_spu | ||
| 223 | creator varchar(64) comment '创建人', | 223 | creator varchar(64) comment '创建人', |
| 224 | updater varchar(64) comment '更新人', | 224 | updater varchar(64) comment '更新人', |
| 225 | tenant_id bigint NOT NULL DEFAULT '0' COMMENT '租户编号', | 225 | tenant_id bigint NOT NULL DEFAULT '0' COMMENT '租户编号', |
| 226 | - deleted bit(1) comment '状态', | 226 | + deleted bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', |
| 227 | primary key (id) | 227 | primary key (id) |
| 228 | ) comment '商品spu' character set utf8mb4 | 228 | ) comment '商品spu' character set utf8mb4 |
| 229 | collate utf8mb4_general_ci; | 229 | collate utf8mb4_general_ci; |
| @@ -233,7 +233,7 @@ create table product_spu | @@ -233,7 +233,7 @@ create table product_spu | ||
| 233 | drop table if exists product_sku; | 233 | drop table if exists product_sku; |
| 234 | create table product_sku | 234 | create table product_sku |
| 235 | ( | 235 | ( |
| 236 | - id int comment '主键', | 236 | + id bigint NOT NULL AUTO_INCREMENT COMMENT '主键', |
| 237 | spu_id bigint not null comment 'spu编号', | 237 | spu_id bigint not null comment 'spu编号', |
| 238 | properties varchar(64) not null comment '规格值数组-json格式, [{propertId: , valueId: }, {propertId: , valueId: }]', | 238 | properties varchar(64) not null comment '规格值数组-json格式, [{propertId: , valueId: }, {propertId: , valueId: }]', |
| 239 | price int not null DEFAULT -1 comment '销售价格,单位:分', | 239 | price int not null DEFAULT -1 comment '销售价格,单位:分', |
| @@ -247,7 +247,7 @@ create table product_sku | @@ -247,7 +247,7 @@ create table product_sku | ||
| 247 | creator varchar(64) comment '创建人', | 247 | creator varchar(64) comment '创建人', |
| 248 | updater varchar(64) comment '更新人', | 248 | updater varchar(64) comment '更新人', |
| 249 | tenant_id bigint NOT NULL DEFAULT '0' COMMENT '租户编号', | 249 | tenant_id bigint NOT NULL DEFAULT '0' COMMENT '租户编号', |
| 250 | - deleted bit(1) comment '状态', | 250 | + deleted bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', |
| 251 | primary key (id) | 251 | primary key (id) |
| 252 | ) comment '商品sku' character set utf8mb4 | 252 | ) comment '商品sku' character set utf8mb4 |
| 253 | collate utf8mb4_general_ci; | 253 | collate utf8mb4_general_ci; |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/ProductPropertyController.java
| @@ -63,8 +63,7 @@ public class ProductPropertyController { | @@ -63,8 +63,7 @@ public class ProductPropertyController { | ||
| 63 | @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) | 63 | @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) |
| 64 | @PreAuthorize("@ss.hasPermission('product:property:query')") | 64 | @PreAuthorize("@ss.hasPermission('product:property:query')") |
| 65 | public CommonResult<ProductPropertyRespVO> getProperty(@RequestParam("id") Long id) { | 65 | public CommonResult<ProductPropertyRespVO> getProperty(@RequestParam("id") Long id) { |
| 66 | - ProductPropertyDO property = productPropertyService.getProperty(id); | ||
| 67 | - return success(ProductPropertyConvert.INSTANCE.convert(property)); | 66 | + return success(productPropertyService.getPropertyResp(id)); |
| 68 | } | 67 | } |
| 69 | 68 | ||
| 70 | @GetMapping("/list") | 69 | @GetMapping("/list") |
| @@ -80,8 +79,7 @@ public class ProductPropertyController { | @@ -80,8 +79,7 @@ public class ProductPropertyController { | ||
| 80 | @ApiOperation("获得规格名称分页") | 79 | @ApiOperation("获得规格名称分页") |
| 81 | @PreAuthorize("@ss.hasPermission('product:property:query')") | 80 | @PreAuthorize("@ss.hasPermission('product:property:query')") |
| 82 | public CommonResult<PageResult<ProductPropertyRespVO>> getPropertyPage(@Valid ProductPropertyPageReqVO pageVO) { | 81 | public CommonResult<PageResult<ProductPropertyRespVO>> getPropertyPage(@Valid ProductPropertyPageReqVO pageVO) { |
| 83 | - PageResult<ProductPropertyDO> pageResult = productPropertyService.getPropertyPage(pageVO); | ||
| 84 | - return success(ProductPropertyConvert.INSTANCE.convertPage(pageResult)); | 82 | + return success(productPropertyService.getPropertyListPage(pageVO)); |
| 85 | } | 83 | } |
| 86 | 84 | ||
| 87 | @GetMapping("/export-excel") | 85 | @GetMapping("/export-excel") |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/vo/ProductPropertyCreateReqVO.java
| 1 | package cn.iocoder.yudao.module.product.controller.admin.property.vo; | 1 | package cn.iocoder.yudao.module.product.controller.admin.property.vo; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.PropertyValueCreateReqVO; | ||
| 3 | import lombok.*; | 4 | import lombok.*; |
| 4 | import io.swagger.annotations.*; | 5 | import io.swagger.annotations.*; |
| 5 | 6 | ||
| 7 | +import javax.validation.constraints.NotNull; | ||
| 8 | +import java.util.List; | ||
| 9 | + | ||
| 6 | @ApiModel("管理后台 - 规格名称创建 Request VO") | 10 | @ApiModel("管理后台 - 规格名称创建 Request VO") |
| 7 | @Data | 11 | @Data |
| 8 | @EqualsAndHashCode(callSuper = true) | 12 | @EqualsAndHashCode(callSuper = true) |
| 9 | @ToString(callSuper = true) | 13 | @ToString(callSuper = true) |
| 10 | public class ProductPropertyCreateReqVO extends ProductPropertyBaseVO { | 14 | public class ProductPropertyCreateReqVO extends ProductPropertyBaseVO { |
| 11 | 15 | ||
| 16 | + @ApiModelProperty(value = "属性值") | ||
| 17 | + @NotNull(message = "属性值不能为空") | ||
| 18 | + List<PropertyValueCreateReqVO> propertyValueList; | ||
| 19 | + | ||
| 12 | } | 20 | } |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/vo/ProductPropertyRespVO.java
| @@ -17,6 +17,7 @@ public class ProductPropertyRespVO extends ProductPropertyBaseVO { | @@ -17,6 +17,7 @@ public class ProductPropertyRespVO extends ProductPropertyBaseVO { | ||
| 17 | @ApiModelProperty(value = "创建时间") | 17 | @ApiModelProperty(value = "创建时间") |
| 18 | private Date createTime; | 18 | private Date createTime; |
| 19 | 19 | ||
| 20 | - private List<PropertyValueRespVO> propertyValueRespVOList; | 20 | + @ApiModelProperty(value = "属性值") |
| 21 | + private List<PropertyValueRespVO> propertyValueList; | ||
| 21 | 22 | ||
| 22 | } | 23 | } |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/vo/ProductPropertyUpdateReqVO.java
| 1 | package cn.iocoder.yudao.module.product.controller.admin.property.vo; | 1 | package cn.iocoder.yudao.module.product.controller.admin.property.vo; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.PropertyValueCreateReqVO; | ||
| 3 | import lombok.*; | 4 | import lombok.*; |
| 4 | import io.swagger.annotations.*; | 5 | import io.swagger.annotations.*; |
| 5 | import javax.validation.constraints.*; | 6 | import javax.validation.constraints.*; |
| 7 | +import java.util.List; | ||
| 6 | 8 | ||
| 7 | @ApiModel("管理后台 - 规格名称更新 Request VO") | 9 | @ApiModel("管理后台 - 规格名称更新 Request VO") |
| 8 | @Data | 10 | @Data |
| @@ -14,4 +16,8 @@ public class ProductPropertyUpdateReqVO extends ProductPropertyBaseVO { | @@ -14,4 +16,8 @@ public class ProductPropertyUpdateReqVO extends ProductPropertyBaseVO { | ||
| 14 | @NotNull(message = "主键不能为空") | 16 | @NotNull(message = "主键不能为空") |
| 15 | private Long id; | 17 | private Long id; |
| 16 | 18 | ||
| 19 | + @ApiModelProperty(value = "属性值") | ||
| 20 | + @NotNull(message = "属性值不能为空") | ||
| 21 | + List<PropertyValueCreateReqVO> propertyValueList; | ||
| 22 | + | ||
| 17 | } | 23 | } |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/propertyvalue/PropertyValueController.java deleted
| 1 | -package cn.iocoder.yudao.module.product.controller.admin.propertyvalue; | ||
| 2 | - | ||
| 3 | -import org.springframework.web.bind.annotation.*; | ||
| 4 | -import javax.annotation.Resource; | ||
| 5 | -import org.springframework.validation.annotation.Validated; | ||
| 6 | -import org.springframework.security.access.prepost.PreAuthorize; | ||
| 7 | -import io.swagger.annotations.*; | ||
| 8 | - | ||
| 9 | -import javax.validation.constraints.*; | ||
| 10 | -import javax.validation.*; | ||
| 11 | -import javax.servlet.http.*; | ||
| 12 | -import java.util.*; | ||
| 13 | -import java.io.IOException; | ||
| 14 | - | ||
| 15 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 16 | -import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 17 | -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||
| 18 | - | ||
| 19 | -import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | ||
| 20 | - | ||
| 21 | -import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | ||
| 22 | -import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; | ||
| 23 | - | ||
| 24 | -import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.*; | ||
| 25 | -import cn.iocoder.yudao.module.product.dal.dataobject.propertyvalue.PropertyValueDO; | ||
| 26 | -import cn.iocoder.yudao.module.product.convert.propertyvalue.PropertyValueConvert; | ||
| 27 | -import cn.iocoder.yudao.module.product.service.propertyvalue.PropertyValueService; | ||
| 28 | - | ||
| 29 | -@Api(tags = "管理后台 - 规格值") | ||
| 30 | -@RestController | ||
| 31 | -@RequestMapping("/product/property-value") | ||
| 32 | -@Validated | ||
| 33 | -public class PropertyValueController { | ||
| 34 | - | ||
| 35 | - @Resource | ||
| 36 | - private PropertyValueService propertyValueService; | ||
| 37 | - | ||
| 38 | - @PostMapping("/create") | ||
| 39 | - @ApiOperation("创建规格值") | ||
| 40 | - @PreAuthorize("@ss.hasPermission('product:property-value:create')") | ||
| 41 | - public CommonResult<Integer> createPropertyValue(@Valid @RequestBody PropertyValueCreateReqVO createReqVO) { | ||
| 42 | - return success(propertyValueService.createPropertyValue(createReqVO)); | ||
| 43 | - } | ||
| 44 | - | ||
| 45 | - @PutMapping("/update") | ||
| 46 | - @ApiOperation("更新规格值") | ||
| 47 | - @PreAuthorize("@ss.hasPermission('product:property-value:update')") | ||
| 48 | - public CommonResult<Boolean> updatePropertyValue(@Valid @RequestBody PropertyValueUpdateReqVO updateReqVO) { | ||
| 49 | - propertyValueService.updatePropertyValue(updateReqVO); | ||
| 50 | - return success(true); | ||
| 51 | - } | ||
| 52 | - | ||
| 53 | - @DeleteMapping("/delete") | ||
| 54 | - @ApiOperation("删除规格值") | ||
| 55 | - @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Integer.class) | ||
| 56 | - @PreAuthorize("@ss.hasPermission('product:property-value:delete')") | ||
| 57 | - public CommonResult<Boolean> deletePropertyValue(@RequestParam("id") Integer id) { | ||
| 58 | - propertyValueService.deletePropertyValue(id); | ||
| 59 | - return success(true); | ||
| 60 | - } | ||
| 61 | - | ||
| 62 | - @GetMapping("/get") | ||
| 63 | - @ApiOperation("获得规格值") | ||
| 64 | - @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Integer.class) | ||
| 65 | - @PreAuthorize("@ss.hasPermission('product:property-value:query')") | ||
| 66 | - public CommonResult<PropertyValueRespVO> getPropertyValue(@RequestParam("id") Integer id) { | ||
| 67 | - PropertyValueDO propertyValue = propertyValueService.getPropertyValue(id); | ||
| 68 | - return success(PropertyValueConvert.INSTANCE.convert(propertyValue)); | ||
| 69 | - } | ||
| 70 | - | ||
| 71 | - @GetMapping("/list") | ||
| 72 | - @ApiOperation("获得规格值列表") | ||
| 73 | - @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class) | ||
| 74 | - @PreAuthorize("@ss.hasPermission('product:property-value:query')") | ||
| 75 | - public CommonResult<List<PropertyValueRespVO>> getPropertyValueList(@RequestParam("ids") Collection<Integer> ids) { | ||
| 76 | - List<PropertyValueDO> list = propertyValueService.getPropertyValueList(ids); | ||
| 77 | - return success(PropertyValueConvert.INSTANCE.convertList(list)); | ||
| 78 | - } | ||
| 79 | - | ||
| 80 | - @GetMapping("/page") | ||
| 81 | - @ApiOperation("获得规格值分页") | ||
| 82 | - @PreAuthorize("@ss.hasPermission('product:property-value:query')") | ||
| 83 | - public CommonResult<PageResult<PropertyValueRespVO>> getPropertyValuePage(@Valid PropertyValuePageReqVO pageVO) { | ||
| 84 | - PageResult<PropertyValueDO> pageResult = propertyValueService.getPropertyValuePage(pageVO); | ||
| 85 | - return success(PropertyValueConvert.INSTANCE.convertPage(pageResult)); | ||
| 86 | - } | ||
| 87 | - | ||
| 88 | - @GetMapping("/export-excel") | ||
| 89 | - @ApiOperation("导出规格值 Excel") | ||
| 90 | - @PreAuthorize("@ss.hasPermission('product:property-value:export')") | ||
| 91 | - @OperateLog(type = EXPORT) | ||
| 92 | - public void exportPropertyValueExcel(@Valid PropertyValueExportReqVO exportReqVO, | ||
| 93 | - HttpServletResponse response) throws IOException { | ||
| 94 | - List<PropertyValueDO> list = propertyValueService.getPropertyValueList(exportReqVO); | ||
| 95 | - // 导出 Excel | ||
| 96 | - List<PropertyValueExcelVO> datas = PropertyValueConvert.INSTANCE.convertList02(list); | ||
| 97 | - ExcelUtils.write(response, "规格值.xls", "数据", PropertyValueExcelVO.class, datas); | ||
| 98 | - } | ||
| 99 | - | ||
| 100 | -} |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/propertyvalue/PropertyValueConvert.java
| @@ -31,4 +31,6 @@ public interface PropertyValueConvert { | @@ -31,4 +31,6 @@ public interface PropertyValueConvert { | ||
| 31 | 31 | ||
| 32 | List<PropertyValueExcelVO> convertList02(List<PropertyValueDO> list); | 32 | List<PropertyValueExcelVO> convertList02(List<PropertyValueDO> list); |
| 33 | 33 | ||
| 34 | + List<PropertyValueDO> convertList03(List<PropertyValueCreateReqVO> list); | ||
| 35 | + | ||
| 34 | } | 36 | } |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/propertyvalue/PropertyValueMapper.java
| @@ -35,4 +35,14 @@ public interface PropertyValueMapper extends BaseMapperX<PropertyValueDO> { | @@ -35,4 +35,14 @@ public interface PropertyValueMapper extends BaseMapperX<PropertyValueDO> { | ||
| 35 | .orderByDesc(PropertyValueDO::getId)); | 35 | .orderByDesc(PropertyValueDO::getId)); |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | + default List<PropertyValueDO> getPropertyValueListByPropertyId(List<Long> propertyIds){ | ||
| 39 | + return selectList(new LambdaQueryWrapperX<PropertyValueDO>() | ||
| 40 | + .inIfPresent(PropertyValueDO::getPropertyId, propertyIds)); | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + default void deletePropertyValueByPropertyId(Long propertyId){ | ||
| 44 | + LambdaQueryWrapperX<PropertyValueDO> queryWrapperX = new LambdaQueryWrapperX<>(); | ||
| 45 | + queryWrapperX.eq(PropertyValueDO::getPropertyId, propertyId).eq(PropertyValueDO::getDeleted, false); | ||
| 46 | + delete(queryWrapperX); | ||
| 47 | + } | ||
| 38 | } | 48 | } |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyService.java
| @@ -67,4 +67,13 @@ public interface ProductPropertyService { | @@ -67,4 +67,13 @@ public interface ProductPropertyService { | ||
| 67 | */ | 67 | */ |
| 68 | List<ProductPropertyDO> getPropertyList(ProductPropertyExportReqVO exportReqVO); | 68 | List<ProductPropertyDO> getPropertyList(ProductPropertyExportReqVO exportReqVO); |
| 69 | 69 | ||
| 70 | + /** | ||
| 71 | + * 获取属性及属性值列表 分页 | ||
| 72 | + * @param pageReqVO | ||
| 73 | + * @return | ||
| 74 | + */ | ||
| 75 | + PageResult<ProductPropertyRespVO> getPropertyListPage(ProductPropertyPageReqVO pageReqVO); | ||
| 76 | + | ||
| 77 | + ProductPropertyRespVO getPropertyResp(Long id); | ||
| 78 | + | ||
| 70 | } | 79 | } |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyServiceImpl.java
| @@ -4,15 +4,23 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; | @@ -4,15 +4,23 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | import cn.iocoder.yudao.module.product.controller.admin.property.vo.*; | 4 | import cn.iocoder.yudao.module.product.controller.admin.property.vo.*; |
| 5 | import cn.iocoder.yudao.module.product.controller.admin.property.vo.ProductPropertyCreateReqVO; | 5 | import cn.iocoder.yudao.module.product.controller.admin.property.vo.ProductPropertyCreateReqVO; |
| 6 | import cn.iocoder.yudao.module.product.controller.admin.property.vo.ProductPropertyUpdateReqVO; | 6 | import cn.iocoder.yudao.module.product.controller.admin.property.vo.ProductPropertyUpdateReqVO; |
| 7 | +import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.PropertyValueCreateReqVO; | ||
| 8 | +import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.PropertyValueRespVO; | ||
| 7 | import cn.iocoder.yudao.module.product.convert.property.ProductPropertyConvert; | 9 | import cn.iocoder.yudao.module.product.convert.property.ProductPropertyConvert; |
| 10 | +import cn.iocoder.yudao.module.product.convert.propertyvalue.PropertyValueConvert; | ||
| 8 | import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO; | 11 | import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO; |
| 12 | +import cn.iocoder.yudao.module.product.dal.dataobject.propertyvalue.PropertyValueDO; | ||
| 9 | import cn.iocoder.yudao.module.product.dal.mysql.property.ProductPropertyMapper; | 13 | import cn.iocoder.yudao.module.product.dal.mysql.property.ProductPropertyMapper; |
| 14 | +import cn.iocoder.yudao.module.product.service.propertyvalue.PropertyValueService; | ||
| 10 | import org.springframework.stereotype.Service; | 15 | import org.springframework.stereotype.Service; |
| 16 | +import org.springframework.transaction.annotation.Transactional; | ||
| 11 | import org.springframework.validation.annotation.Validated; | 17 | import org.springframework.validation.annotation.Validated; |
| 12 | 18 | ||
| 13 | import javax.annotation.Resource; | 19 | import javax.annotation.Resource; |
| 20 | +import java.util.Arrays; | ||
| 14 | import java.util.Collection; | 21 | import java.util.Collection; |
| 15 | import java.util.List; | 22 | import java.util.List; |
| 23 | +import java.util.stream.Collectors; | ||
| 16 | 24 | ||
| 17 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 25 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 18 | import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PROPERTY_NOT_EXISTS; | 26 | import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PROPERTY_NOT_EXISTS; |
| @@ -29,22 +37,39 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { | @@ -29,22 +37,39 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { | ||
| 29 | @Resource | 37 | @Resource |
| 30 | private ProductPropertyMapper productPropertyMapper; | 38 | private ProductPropertyMapper productPropertyMapper; |
| 31 | 39 | ||
| 40 | + @Resource | ||
| 41 | + private PropertyValueService propertyValueService; | ||
| 42 | + | ||
| 32 | @Override | 43 | @Override |
| 44 | + @Transactional(rollbackFor = Exception.class) | ||
| 33 | public Long createProperty(ProductPropertyCreateReqVO createReqVO) { | 45 | public Long createProperty(ProductPropertyCreateReqVO createReqVO) { |
| 34 | // 插入 | 46 | // 插入 |
| 35 | ProductPropertyDO property = ProductPropertyConvert.INSTANCE.convert(createReqVO); | 47 | ProductPropertyDO property = ProductPropertyConvert.INSTANCE.convert(createReqVO); |
| 36 | productPropertyMapper.insert(property); | 48 | productPropertyMapper.insert(property); |
| 49 | + | ||
| 50 | + //插入属性值 | ||
| 51 | + List<PropertyValueCreateReqVO> propertyValueList = createReqVO.getPropertyValueList(); | ||
| 52 | + List<PropertyValueDO> propertyValueDOList = PropertyValueConvert.INSTANCE.convertList03(propertyValueList); | ||
| 53 | + propertyValueDOList.stream().forEach(x-> x.setPropertyId(property.getId())); | ||
| 54 | + propertyValueService.batchInsert(propertyValueDOList); | ||
| 37 | // 返回 | 55 | // 返回 |
| 38 | return property.getId(); | 56 | return property.getId(); |
| 39 | } | 57 | } |
| 40 | 58 | ||
| 41 | @Override | 59 | @Override |
| 60 | + @Transactional(rollbackFor = Exception.class) | ||
| 42 | public void updateProperty(ProductPropertyUpdateReqVO updateReqVO) { | 61 | public void updateProperty(ProductPropertyUpdateReqVO updateReqVO) { |
| 43 | // 校验存在 | 62 | // 校验存在 |
| 44 | this.validatePropertyExists(updateReqVO.getId()); | 63 | this.validatePropertyExists(updateReqVO.getId()); |
| 45 | // 更新 | 64 | // 更新 |
| 46 | ProductPropertyDO updateObj = ProductPropertyConvert.INSTANCE.convert(updateReqVO); | 65 | ProductPropertyDO updateObj = ProductPropertyConvert.INSTANCE.convert(updateReqVO); |
| 47 | productPropertyMapper.updateById(updateObj); | 66 | productPropertyMapper.updateById(updateObj); |
| 67 | + //更新属性值,先删后加 | ||
| 68 | + propertyValueService.deletePropertyValueByPropertyId(updateReqVO.getId()); | ||
| 69 | + List<PropertyValueCreateReqVO> propertyValueList = updateReqVO.getPropertyValueList(); | ||
| 70 | + List<PropertyValueDO> propertyValueDOList = PropertyValueConvert.INSTANCE.convertList03(propertyValueList); | ||
| 71 | + propertyValueDOList.stream().forEach(x-> x.setPropertyId(updateReqVO.getId())); | ||
| 72 | + propertyValueService.batchInsert(propertyValueDOList); | ||
| 48 | } | 73 | } |
| 49 | 74 | ||
| 50 | @Override | 75 | @Override |
| @@ -53,6 +78,8 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { | @@ -53,6 +78,8 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { | ||
| 53 | this.validatePropertyExists(id); | 78 | this.validatePropertyExists(id); |
| 54 | // 删除 | 79 | // 删除 |
| 55 | productPropertyMapper.deleteById(id); | 80 | productPropertyMapper.deleteById(id); |
| 81 | + //同步删除属性值 | ||
| 82 | + propertyValueService.deletePropertyValueByPropertyId(id); | ||
| 56 | } | 83 | } |
| 57 | 84 | ||
| 58 | private void validatePropertyExists(Long id) { | 85 | private void validatePropertyExists(Long id) { |
| @@ -81,4 +108,36 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { | @@ -81,4 +108,36 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { | ||
| 81 | return productPropertyMapper.selectList(exportReqVO); | 108 | return productPropertyMapper.selectList(exportReqVO); |
| 82 | } | 109 | } |
| 83 | 110 | ||
| 111 | + @Override | ||
| 112 | + public PageResult<ProductPropertyRespVO> getPropertyListPage(ProductPropertyPageReqVO pageReqVO) { | ||
| 113 | + //获取属性列表 | ||
| 114 | + PageResult<ProductPropertyDO> pageResult = productPropertyMapper.selectPage(pageReqVO); | ||
| 115 | + PageResult<ProductPropertyRespVO> propertyRespVOPageResult = ProductPropertyConvert.INSTANCE.convertPage(pageResult); | ||
| 116 | + List<Long> propertyIds = propertyRespVOPageResult.getList().stream().map(x -> x.getId()).collect(Collectors.toList()); | ||
| 117 | + | ||
| 118 | + //获取属性值列表 | ||
| 119 | + List<PropertyValueDO> propertyValueDOList = propertyValueService.getPropertyValueListByPropertyId(propertyIds); | ||
| 120 | + List<PropertyValueRespVO> propertyValueRespVOList = PropertyValueConvert.INSTANCE.convertList(propertyValueDOList); | ||
| 121 | + //组装一对多 | ||
| 122 | + propertyRespVOPageResult.getList().stream().forEach(x->{ | ||
| 123 | + Long propertyId = x.getId(); | ||
| 124 | + List<PropertyValueRespVO> valueDOList = propertyValueRespVOList.stream().filter(v -> v.getPropertyId().equals(propertyId)).collect(Collectors.toList()); | ||
| 125 | + x.setPropertyValueList(valueDOList); | ||
| 126 | + }); | ||
| 127 | + return propertyRespVOPageResult; | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + @Override | ||
| 131 | + public ProductPropertyRespVO getPropertyResp(Long id) { | ||
| 132 | + //查询规格 | ||
| 133 | + ProductPropertyDO property = getProperty(id); | ||
| 134 | + ProductPropertyRespVO propertyRespVO = ProductPropertyConvert.INSTANCE.convert(property); | ||
| 135 | + //查询属性值 | ||
| 136 | + List<PropertyValueDO> valueDOList = propertyValueService.getPropertyValueListByPropertyId(Arrays.asList(id)); | ||
| 137 | + List<PropertyValueRespVO> propertyValueRespVOS = PropertyValueConvert.INSTANCE.convertList(valueDOList); | ||
| 138 | + //组装 | ||
| 139 | + propertyRespVO.setPropertyValueList(propertyValueRespVOS); | ||
| 140 | + return propertyRespVO; | ||
| 141 | + } | ||
| 142 | + | ||
| 84 | } | 143 | } |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/propertyvalue/PropertyValueService.java
| @@ -67,4 +67,22 @@ public interface PropertyValueService { | @@ -67,4 +67,22 @@ public interface PropertyValueService { | ||
| 67 | */ | 67 | */ |
| 68 | List<PropertyValueDO> getPropertyValueList(PropertyValueExportReqVO exportReqVO); | 68 | List<PropertyValueDO> getPropertyValueList(PropertyValueExportReqVO exportReqVO); |
| 69 | 69 | ||
| 70 | + /** | ||
| 71 | + * 批量插入属性值 | ||
| 72 | + * @param propertyValues | ||
| 73 | + */ | ||
| 74 | + void batchInsert(List<PropertyValueDO> propertyValues); | ||
| 75 | + | ||
| 76 | + /** | ||
| 77 | + * 根据属性id查询 | ||
| 78 | + * @param propertyIds | ||
| 79 | + * @return | ||
| 80 | + */ | ||
| 81 | + List<PropertyValueDO> getPropertyValueListByPropertyId(List<Long> propertyIds); | ||
| 82 | + | ||
| 83 | + /** | ||
| 84 | + * 根据属性id 删除 | ||
| 85 | + * @param propertyId | ||
| 86 | + */ | ||
| 87 | + void deletePropertyValueByPropertyId(Long propertyId); | ||
| 70 | } | 88 | } |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/propertyvalue/PropertyValueServiceImpl.java
| 1 | package cn.iocoder.yudao.module.product.service.propertyvalue; | 1 | package cn.iocoder.yudao.module.product.service.propertyvalue; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | -import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.PropertyValueCreateReqVO; | ||
| 5 | -import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.PropertyValueExportReqVO; | ||
| 6 | -import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.PropertyValuePageReqVO; | ||
| 7 | -import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.PropertyValueUpdateReqVO; | 4 | +import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.*; |
| 8 | import cn.iocoder.yudao.module.product.convert.propertyvalue.PropertyValueConvert; | 5 | import cn.iocoder.yudao.module.product.convert.propertyvalue.PropertyValueConvert; |
| 9 | import cn.iocoder.yudao.module.product.dal.dataobject.propertyvalue.PropertyValueDO; | 6 | import cn.iocoder.yudao.module.product.dal.dataobject.propertyvalue.PropertyValueDO; |
| 10 | import cn.iocoder.yudao.module.product.dal.mysql.propertyvalue.PropertyValueMapper; | 7 | import cn.iocoder.yudao.module.product.dal.mysql.propertyvalue.PropertyValueMapper; |
| @@ -84,4 +81,19 @@ public class PropertyValueServiceImpl implements PropertyValueService { | @@ -84,4 +81,19 @@ public class PropertyValueServiceImpl implements PropertyValueService { | ||
| 84 | return propertyValueMapper.selectList(exportReqVO); | 81 | return propertyValueMapper.selectList(exportReqVO); |
| 85 | } | 82 | } |
| 86 | 83 | ||
| 84 | + @Override | ||
| 85 | + public void batchInsert(List<PropertyValueDO> propertyValues) { | ||
| 86 | + propertyValueMapper.insertBatch(propertyValues); | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + @Override | ||
| 90 | + public List<PropertyValueDO> getPropertyValueListByPropertyId(List<Long> propertyIds) { | ||
| 91 | + return propertyValueMapper.getPropertyValueListByPropertyId(propertyIds); | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + @Override | ||
| 95 | + public void deletePropertyValueByPropertyId(Long propertyId) { | ||
| 96 | + propertyValueMapper.deletePropertyValueByPropertyId(propertyId); | ||
| 97 | + } | ||
| 98 | + | ||
| 87 | } | 99 | } |
yudao-ui-admin/src/views/mall/product/property/index.vue
| @@ -24,16 +24,17 @@ | @@ -24,16 +24,17 @@ | ||
| 24 | <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" | 24 | <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" |
| 25 | v-hasPermi="['product:property:create']">新增</el-button> | 25 | v-hasPermi="['product:property:create']">新增</el-button> |
| 26 | </el-col> | 26 | </el-col> |
| 27 | - <el-col :span="1.5"> | ||
| 28 | - <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading" | ||
| 29 | - v-hasPermi="['product:property:export']">导出</el-button> | ||
| 30 | - </el-col> | ||
| 31 | <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> | 27 | <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> |
| 32 | </el-row> | 28 | </el-row> |
| 33 | 29 | ||
| 34 | <!-- 列表 --> | 30 | <!-- 列表 --> |
| 35 | <el-table v-loading="loading" :data="list"> | 31 | <el-table v-loading="loading" :data="list"> |
| 36 | <el-table-column label="规格名称" align="center" prop="name" /> | 32 | <el-table-column label="规格名称" align="center" prop="name" /> |
| 33 | + <el-table-column label="规格名称" align="center" prop="propertyValueList"> | ||
| 34 | + <template slot-scope="scope"> | ||
| 35 | + <span>{{formatList(scope.row.propertyValueList)}}</span> | ||
| 36 | + </template> | ||
| 37 | + </el-table-column> | ||
| 37 | <el-table-column label="开启状态" align="center" prop="status"> | 38 | <el-table-column label="开启状态" align="center" prop="status"> |
| 38 | <template slot-scope="scope"> | 39 | <template slot-scope="scope"> |
| 39 | <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status"/> | 40 | <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status"/> |
| @@ -74,19 +75,19 @@ | @@ -74,19 +75,19 @@ | ||
| 74 | <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="addPropertyValue()">添加</el-button> | 75 | <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="addPropertyValue()">添加</el-button> |
| 75 | </el-form-item> | 76 | </el-form-item> |
| 76 | <el-form-item | 77 | <el-form-item |
| 77 | - v-for="(domain, index) in form.propertyValues" | 78 | + v-for="(domain, index) in form.propertyValueList" |
| 78 | :key="domain.key" | 79 | :key="domain.key" |
| 79 | - :prop="'propertyValues.' + index + '.value'" | 80 | + :prop="'propertyValueList.' + index + '.name'" |
| 80 | :rules="{ | 81 | :rules="{ |
| 81 | - required: true, message: '域名不能为空', trigger: 'blur' | 82 | + required: true, message: '属性值不能为空', trigger: 'blur' |
| 82 | }" | 83 | }" |
| 83 | > | 84 | > |
| 84 | <el-row> | 85 | <el-row> |
| 85 | <el-col :span="18"> | 86 | <el-col :span="18"> |
| 86 | - <el-input v-model="domain.value"></el-input> | 87 | + <el-input v-model="domain.name" size="mini"></el-input> |
| 87 | </el-col> | 88 | </el-col> |
| 88 | <el-col :span="6"> | 89 | <el-col :span="6"> |
| 89 | - <el-button @click.prevent="removePropertyValue(domain)">删除</el-button> | 90 | + <el-button style="margin-left: 20px;" size="mini" @click.prevent="removePropertyValue(domain)">删除</el-button> |
| 90 | </el-col> | 91 | </el-col> |
| 91 | </el-row> | 92 | </el-row> |
| 92 | </el-form-item> | 93 | </el-form-item> |
| @@ -134,8 +135,8 @@ export default { | @@ -134,8 +135,8 @@ export default { | ||
| 134 | form: { | 135 | form: { |
| 135 | name:'', | 136 | name:'', |
| 136 | status:'', | 137 | status:'', |
| 137 | - propertyValues: [{ | ||
| 138 | - value: '' | 138 | + propertyValueList: [{ |
| 139 | + name: '' | ||
| 139 | }], | 140 | }], |
| 140 | }, | 141 | }, |
| 141 | // 表单校验 | 142 | // 表单校验 |
| @@ -171,12 +172,10 @@ export default { | @@ -171,12 +172,10 @@ export default { | ||
| 171 | id: undefined, | 172 | id: undefined, |
| 172 | name: undefined, | 173 | name: undefined, |
| 173 | status: undefined, | 174 | status: undefined, |
| 175 | + propertyValueList: [{ | ||
| 176 | + name: '' | ||
| 177 | + }] | ||
| 174 | }; | 178 | }; |
| 175 | - this.form.propertyValues = [{ | ||
| 176 | - key:'', | ||
| 177 | - value: '' | ||
| 178 | - }]; | ||
| 179 | - console.log("this.form", this.form) | ||
| 180 | this.resetForm("form"); | 179 | this.resetForm("form"); |
| 181 | }, | 180 | }, |
| 182 | /** 搜索按钮操作 */ | 181 | /** 搜索按钮操作 */ |
| @@ -194,7 +193,7 @@ export default { | @@ -194,7 +193,7 @@ export default { | ||
| 194 | handleAdd() { | 193 | handleAdd() { |
| 195 | this.reset(); | 194 | this.reset(); |
| 196 | this.open = true; | 195 | this.open = true; |
| 197 | - this.title = "添加规格名称"; | 196 | + this.title = "添加规格"; |
| 198 | }, | 197 | }, |
| 199 | /** 修改按钮操作 */ | 198 | /** 修改按钮操作 */ |
| 200 | handleUpdate(row) { | 199 | handleUpdate(row) { |
| @@ -203,7 +202,7 @@ export default { | @@ -203,7 +202,7 @@ export default { | ||
| 203 | getProperty(id).then(response => { | 202 | getProperty(id).then(response => { |
| 204 | this.form = response.data; | 203 | this.form = response.data; |
| 205 | this.open = true; | 204 | this.open = true; |
| 206 | - this.title = "修改规格名称"; | 205 | + this.title = "修改规格"; |
| 207 | }); | 206 | }); |
| 208 | }, | 207 | }, |
| 209 | /** 提交按钮 */ | 208 | /** 提交按钮 */ |
| @@ -232,7 +231,7 @@ export default { | @@ -232,7 +231,7 @@ export default { | ||
| 232 | /** 删除按钮操作 */ | 231 | /** 删除按钮操作 */ |
| 233 | handleDelete(row) { | 232 | handleDelete(row) { |
| 234 | const id = row.id; | 233 | const id = row.id; |
| 235 | - this.$modal.confirm('是否确认删除规格名称编号为"' + id + '"的数据项?').then(function() { | 234 | + this.$modal.confirm('是否确认删除规格名称为"' + row.name + '"的数据项?').then(function() { |
| 236 | return deleteProperty(id); | 235 | return deleteProperty(id); |
| 237 | }).then(() => { | 236 | }).then(() => { |
| 238 | this.getList(); | 237 | this.getList(); |
| @@ -256,17 +255,25 @@ export default { | @@ -256,17 +255,25 @@ export default { | ||
| 256 | }).catch(() => {}); | 255 | }).catch(() => {}); |
| 257 | }, | 256 | }, |
| 258 | removePropertyValue(item) { | 257 | removePropertyValue(item) { |
| 259 | - var index = this.form.propertyValues.indexOf(item) | 258 | + var index = this.form.propertyValueList.indexOf(item) |
| 260 | if (index !== -1) { | 259 | if (index !== -1) { |
| 261 | - this.form.propertyValues.splice(index, 1) | 260 | + this.form.propertyValueList.splice(index, 1) |
| 262 | } | 261 | } |
| 263 | }, | 262 | }, |
| 264 | addPropertyValue() { | 263 | addPropertyValue() { |
| 265 | - console.log("this.form.propertyValues", this.form.propertyValues) | ||
| 266 | - this.form.propertyValues.push({ | ||
| 267 | - value: '', | ||
| 268 | - key: Date.now() | 264 | + this.form.propertyValueList.push({ |
| 265 | + name: '' | ||
| 269 | }); | 266 | }); |
| 267 | + }, | ||
| 268 | + formatList(list) { | ||
| 269 | + let str = '' | ||
| 270 | + for (var i = 0; i < list.length; i++) { | ||
| 271 | + str += list[i].name; | ||
| 272 | + if(i != list.length-1){ | ||
| 273 | + str+="/"; | ||
| 274 | + } | ||
| 275 | + } | ||
| 276 | + return str | ||
| 270 | } | 277 | } |
| 271 | } | 278 | } |
| 272 | }; | 279 | }; |