页面装修 review 修改

This commit is contained in:
jason 2023-06-24 21:09:49 +08:00
parent b582206003
commit 050f0bb6a2
13 changed files with 59 additions and 63 deletions

View File

@ -453,9 +453,9 @@ CREATE TABLE `trade_delivery_express` (
DROP TABLE IF EXISTS `promotion_decorate_component`; DROP TABLE IF EXISTS `promotion_decorate_component`;
CREATE TABLE `promotion_decorate_component` ( CREATE TABLE `promotion_decorate_component` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '编号', `id` bigint NOT NULL AUTO_INCREMENT COMMENT '编号',
`type` int NOT NULL COMMENT '页面类型', `page_id` int NOT NULL COMMENT '所属页面id',
`component_code` varchar(64) NOT NULL COMMENT '组件编码', `code` varchar(64) NOT NULL COMMENT '组件编码',
`component_value` json NOT NULL COMMENT '组件值json 格式包含配置和数据', `value` json NOT NULL COMMENT '组件值json 格式包含配置和数据',
`status` tinyint NOT NULL DEFAULT 0 COMMENT '状态', `status` tinyint NOT NULL DEFAULT 0 COMMENT '状态',
`creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者', `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',

View File

@ -7,22 +7,22 @@ import lombok.Getter;
import java.util.Arrays; import java.util.Arrays;
/** /**
* 装修页面类型枚举 * 装修页面枚举
* *
* @author jason * @author jason
*/ */
@AllArgsConstructor @AllArgsConstructor
@Getter @Getter
public enum DecoratePageTypeEnum implements IntArrayValuable { public enum DecoratePageEnum implements IntArrayValuable {
INDEX(1, "首页"); INDEX(1, "首页");
private static final int[] ARRAYS = Arrays.stream(values()).mapToInt(DecoratePageTypeEnum::getType).toArray(); private static final int[] ARRAYS = Arrays.stream(values()).mapToInt(DecoratePageEnum::getId).toArray();
/** /**
* 页面类型 * 页面 id
*/ */
private final Integer type; private final Integer id;
/** /**
* 页面名称 * 页面名称
*/ */

View File

@ -4,7 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.validation.InEnum; import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo.DecorateComponentReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo.DecorateComponentReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo.DecorateComponentRespVO; import cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo.DecorateComponentRespVO;
import cn.iocoder.yudao.module.promotion.enums.decorate.DecoratePageTypeEnum; import cn.iocoder.yudao.module.promotion.enums.decorate.DecoratePageEnum;
import cn.iocoder.yudao.module.promotion.service.decorate.DecorateComponentService; import cn.iocoder.yudao.module.promotion.service.decorate.DecorateComponentService;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
@ -36,11 +36,11 @@ public class DecorateComponentController {
@GetMapping("/get-page-components") @GetMapping("/get-page-components")
@Operation(summary = "获取装修页面组件") @Operation(summary = "获取装修页面组件")
@Parameter(name = "type", description = "页面类型", required = true) @Parameter(name = "pageId", description = "页面 id", required = true)
// TODO 加权限 // TODO 加权限
public CommonResult<DecorateComponentRespVO> getPageComponents( public CommonResult<DecorateComponentRespVO> getPageComponents(
@RequestParam("type") @InEnum(DecoratePageTypeEnum.class) Integer type) { @RequestParam("pageId") @InEnum(DecoratePageEnum.class) Integer pageId) {
return success(INSTANCE.convert2(type, decorateComponentService.getPageComponents(type))); return success(INSTANCE.convert2(pageId, decorateComponentService.getPageComponents(pageId)));
} }
} }

View File

@ -1,7 +1,7 @@
package cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo; package cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo;
import cn.iocoder.yudao.framework.common.validation.InEnum; import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.promotion.enums.decorate.DecoratePageTypeEnum; import cn.iocoder.yudao.module.promotion.enums.decorate.DecoratePageEnum;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
@ -13,10 +13,10 @@ import java.util.List;
@Schema(description = "管理后台 - 页面装修 Request VO ") @Schema(description = "管理后台 - 页面装修 Request VO ")
@Data @Data
public class DecorateComponentReqVO { public class DecorateComponentReqVO {
@Schema(description = "页面类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") @Schema(description = "页面 id ", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "页面类型不能为空") @NotNull(message = "页面 id 不能为空")
@InEnum(DecoratePageTypeEnum.class) @InEnum(DecoratePageEnum.class)
private Integer type; private Integer pageId;
@Schema(description = "页面组件列表", requiredMode = Schema.RequiredMode.REQUIRED, example = "TODO") @Schema(description = "页面组件列表", requiredMode = Schema.RequiredMode.REQUIRED, example = "TODO")
@NotEmpty(message = "页面组件列表不能为空") @NotEmpty(message = "页面组件列表不能为空")
@ -31,11 +31,11 @@ public class DecorateComponentReqVO {
@Schema(description = "组件编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "nav-menu") @Schema(description = "组件编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "nav-menu")
@NotEmpty(message = "组件编码不能为空") @NotEmpty(message = "组件编码不能为空")
private String componentCode; private String code;
@Schema(description = "组件对应值, json 字符串, 含内容配置,具体数据", requiredMode = Schema.RequiredMode.REQUIRED, example = "TODO") @Schema(description = "组件对应值, json 字符串, 含内容配置,具体数据", requiredMode = Schema.RequiredMode.REQUIRED, example = "TODO")
@NotEmpty(message = "组件值为空") @NotEmpty(message = "组件值为空")
private String componentValue; private String value;
} }
} }

View File

@ -9,8 +9,8 @@ import java.util.List;
@Data @Data
public class DecorateComponentRespVO { public class DecorateComponentRespVO {
@Schema(description = "页面类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") @Schema(description = "页面 id ", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer type; private Integer pageId;
@Schema(description = "页面组件", requiredMode = Schema.RequiredMode.REQUIRED, example = "TODO") @Schema(description = "页面组件", requiredMode = Schema.RequiredMode.REQUIRED, example = "TODO")
private List<ComponentRespVO> components; private List<ComponentRespVO> components;
@ -23,10 +23,10 @@ public class DecorateComponentRespVO {
private Long id; private Long id;
@Schema(description = "组件编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "nav-menu") @Schema(description = "组件编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "nav-menu")
private String componentCode; private String code;
@Schema(description = "组件的内容配置项", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "TODO") @Schema(description = "组件的内容配置项", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "TODO")
private String componentValue; private String value;
} }

View File

@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.promotion.controller.app.decorate;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.validation.InEnum; import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.promotion.controller.app.decorate.vo.AppDecorateComponentRespVO; import cn.iocoder.yudao.module.promotion.controller.app.decorate.vo.AppDecorateComponentRespVO;
import cn.iocoder.yudao.module.promotion.enums.decorate.DecoratePageTypeEnum; import cn.iocoder.yudao.module.promotion.enums.decorate.DecoratePageEnum;
import cn.iocoder.yudao.module.promotion.service.decorate.DecorateComponentService; import cn.iocoder.yudao.module.promotion.service.decorate.DecorateComponentService;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
@ -30,10 +30,10 @@ public class AppDecorateController {
@GetMapping("/get-page-components") @GetMapping("/get-page-components")
@Operation(summary = "获取装修页面组件") @Operation(summary = "获取装修页面组件")
@Parameter(name = "type", description = "页面类型", required = true) @Parameter(name = "pageId", description = "页面 id", required = true)
public CommonResult<AppDecorateComponentRespVO> getPageComponents( public CommonResult<AppDecorateComponentRespVO> getPageComponents(
@RequestParam("type") @InEnum(DecoratePageTypeEnum.class) Integer type) { @RequestParam("pageId") @InEnum(DecoratePageEnum.class) Integer pageId) {
return success(INSTANCE.appConvert(type, decorateComponentService.getPageComponents(type))); return success(INSTANCE.appConvert(pageId, decorateComponentService.getPageComponents(pageId)));
} }
} }

View File

@ -9,8 +9,8 @@ import java.util.List;
@Data @Data
public class AppDecorateComponentRespVO { public class AppDecorateComponentRespVO {
@Schema(description = "页面类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") @Schema(description = "页面 id ", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer type; private Integer pageId;
@Schema(description = "页面组件", requiredMode = Schema.RequiredMode.REQUIRED, example = "TODO") @Schema(description = "页面组件", requiredMode = Schema.RequiredMode.REQUIRED, example = "TODO")
private List<AppComponentRespVO> components; private List<AppComponentRespVO> components;
@ -19,14 +19,11 @@ public class AppDecorateComponentRespVO {
@Data @Data
public static class AppComponentRespVO { public static class AppComponentRespVO {
@Schema(description = "组件编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Long id;
@Schema(description = "组件编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "nav-menu") @Schema(description = "组件编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "nav-menu")
private String componentCode; private String code;
@Schema(description = "组件的内容配置项", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "TODO") @Schema(description = "组件的内容配置项", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "TODO")
private String componentValue; private String value;
} }

View File

@ -18,23 +18,23 @@ public interface DecorateComponentConvert {
DecorateComponentConvert INSTANCE = Mappers.getMapper(DecorateComponentConvert.class); DecorateComponentConvert INSTANCE = Mappers.getMapper(DecorateComponentConvert.class);
default List<DecorateComponentDO> convertList(Integer type, List<DecorateComponentReqVO.ComponentReqVO> components) { default List<DecorateComponentDO> convertList(Integer pageId, List<DecorateComponentReqVO.ComponentReqVO> components) {
return CollectionUtils.convertList(components, c -> convert(type, c)); return CollectionUtils.convertList(components, c -> convert(pageId, c));
} }
default DecorateComponentRespVO convert2(Integer type, List<DecorateComponentDO> list) { default DecorateComponentRespVO convert2(Integer pageId, List<DecorateComponentDO> list) {
List<ComponentRespVO> components = CollectionUtils.convertList(list, this::convert3); List<ComponentRespVO> components = CollectionUtils.convertList(list, this::convert3);
return new DecorateComponentRespVO().setType(type).setComponents(components); return new DecorateComponentRespVO().setPageId(pageId).setComponents(components);
} }
DecorateComponentDO convert(Integer type, DecorateComponentReqVO.ComponentReqVO reqVO); DecorateComponentDO convert(Integer pageId, DecorateComponentReqVO.ComponentReqVO reqVO);
ComponentRespVO convert3(DecorateComponentDO componentDO); ComponentRespVO convert3(DecorateComponentDO componentDO);
// ========== App convert ========== // ========== App convert ==========
default AppDecorateComponentRespVO appConvert(Integer type, List<DecorateComponentDO> list) { default AppDecorateComponentRespVO appConvert(Integer pageId, List<DecorateComponentDO> list) {
List<AppComponentRespVO> components = CollectionUtils.convertList(list, this::appConvert2); List<AppComponentRespVO> components = CollectionUtils.convertList(list, this::appConvert2);
return new AppDecorateComponentRespVO().setType(type).setComponents(components); return new AppDecorateComponentRespVO().setPageId(pageId).setComponents(components);
} }
AppComponentRespVO appConvert2(DecorateComponentDO bean); AppComponentRespVO appConvert2(DecorateComponentDO bean);

View File

@ -2,7 +2,7 @@ package cn.iocoder.yudao.module.promotion.dal.dataobject.decorate;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.module.promotion.enums.decorate.DecoratePageTypeEnum; import cn.iocoder.yudao.module.promotion.enums.decorate.DecoratePageEnum;
import cn.iocoder.yudao.module.promotion.enums.decorate.DecorateComponentEnum; import cn.iocoder.yudao.module.promotion.enums.decorate.DecorateComponentEnum;
import com.baomidou.mybatisplus.annotation.*; import com.baomidou.mybatisplus.annotation.*;
@ -24,23 +24,22 @@ public class DecorateComponentDO extends BaseDO {
@TableId @TableId
private Long id; private Long id;
// TODO @jason要不改成 page貌似更合理
/** /**
* 页面类型 * 所属页面 id
* 枚举 {@link DecoratePageTypeEnum#getType()} * 枚举 {@link DecoratePageEnum#getId()}
*/ */
private Integer type; private Integer pageId;
// TODO @jasoncodevalue因为在 component
/** /**
* 组件编码 * 组件编码
* 枚举 {@link DecorateComponentEnum#getCode()} * 枚举 {@link DecorateComponentEnum#getCode()}
*/ */
private String componentCode; private String code;
/** /**
* 组件值json 格式包含配置和数据 * 组件值json 格式包含配置和数据
*/ */
private String componentValue; private String value;
/** /**
* 状态 * 状态

View File

@ -9,8 +9,8 @@ import java.util.List;
@Mapper @Mapper
public interface DecorateComponentMapper extends BaseMapperX<DecorateComponentDO> { public interface DecorateComponentMapper extends BaseMapperX<DecorateComponentDO> {
default List<DecorateComponentDO> selectByPageType(Integer type){ default List<DecorateComponentDO> selectByPage(Integer pageId){
return selectList(DecorateComponentDO::getType, type); return selectList(DecorateComponentDO::getPageId, pageId);
} }
} }

View File

@ -2,7 +2,7 @@ package cn.iocoder.yudao.module.promotion.service.decorate;
import cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo.DecorateComponentReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo.DecorateComponentReqVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.decorate.DecorateComponentDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.decorate.DecorateComponentDO;
import cn.iocoder.yudao.module.promotion.enums.decorate.DecoratePageTypeEnum; import cn.iocoder.yudao.module.promotion.enums.decorate.DecoratePageEnum;
import java.util.List; import java.util.List;
@ -21,10 +21,10 @@ public interface DecorateComponentService {
void pageSave(DecorateComponentReqVO reqVO); void pageSave(DecorateComponentReqVO reqVO);
/** /**
* 根据页面类型获取页面的组件信息 * 根据页面 id获取页面的组件信息
* *
* @param type 页面类型 {@link DecoratePageTypeEnum#getType()} * @param pageId 页面类型 {@link DecoratePageEnum#getId()}
*/ */
List<DecorateComponentDO> getPageComponents(Integer type); List<DecorateComponentDO> getPageComponents(Integer pageId);
} }

View File

@ -29,9 +29,9 @@ public class DecorateComponentServiceImpl implements DecorateComponentService {
@Override @Override
public void pageSave(DecorateComponentReqVO reqVO) { public void pageSave(DecorateComponentReqVO reqVO) {
// 1.新增或修改页面组件 // 1.新增或修改页面组件
List<DecorateComponentDO> oldList = decorateComponentMapper.selectByPageType(reqVO.getType()); List<DecorateComponentDO> oldList = decorateComponentMapper.selectByPage(reqVO.getPageId());
decorateComponentMapper.saveOrUpdateBatch(INSTANCE.convertList(reqVO.getType(), reqVO.getComponents())); decorateComponentMapper.saveOrUpdateBatch(INSTANCE.convertList(reqVO.getPageId(), reqVO.getComponents()));
// 2.删除相关组件 // 2.删除相关组件
Set<Long> deleteIds = convertSet(oldList, DecorateComponentDO::getId); Set<Long> deleteIds = convertSet(oldList, DecorateComponentDO::getId);
deleteIds.removeAll(convertSet(reqVO.getComponents(), ComponentReqVO::getId, vo->Objects.nonNull(vo.getId()))); deleteIds.removeAll(convertSet(reqVO.getComponents(), ComponentReqVO::getId, vo->Objects.nonNull(vo.getId())));
@ -41,8 +41,8 @@ public class DecorateComponentServiceImpl implements DecorateComponentService {
} }
@Override @Override
public List<DecorateComponentDO> getPageComponents(Integer type) { public List<DecorateComponentDO> getPageComponents(Integer pageId) {
return decorateComponentMapper.selectByPageType(type); return decorateComponentMapper.selectByPage(pageId);
} }
} }

View File

@ -13,7 +13,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import static cn.iocoder.yudao.module.promotion.enums.decorate.DecorateComponentEnum.ROLLING_BANNER; import static cn.iocoder.yudao.module.promotion.enums.decorate.DecorateComponentEnum.ROLLING_BANNER;
import static cn.iocoder.yudao.module.promotion.enums.decorate.DecoratePageTypeEnum.INDEX; import static cn.iocoder.yudao.module.promotion.enums.decorate.DecoratePageEnum.INDEX;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
/** /**
@ -36,10 +36,10 @@ public class DecorateComponentServiceImplTest extends BaseMockitoUnitTest {
void testResp(){ void testResp(){
List<DecorateComponentDO> list = new ArrayList<>(1); List<DecorateComponentDO> list = new ArrayList<>(1);
DecorateComponentDO decorateDO = new DecorateComponentDO() DecorateComponentDO decorateDO = new DecorateComponentDO()
.setType(INDEX.getType()).setComponentValue("") .setPageId(INDEX.getId()).setValue("")
.setComponentCode(ROLLING_BANNER.getCode()).setId(1L); .setCode(ROLLING_BANNER.getCode()).setId(1L);
list.add(decorateDO); list.add(decorateDO);
//mock 方法 //mock 方法
Mockito.when(decorateComponentMapper.selectByPageType(eq(1))).thenReturn(list); Mockito.when(decorateComponentMapper.selectByPage(eq(1))).thenReturn(list);
} }
} }