页面装修 review 修改
This commit is contained in:
parent
b582206003
commit
050f0bb6a2
|
@ -453,9 +453,9 @@ CREATE TABLE `trade_delivery_express` (
|
|||
DROP TABLE IF EXISTS `promotion_decorate_component`;
|
||||
CREATE TABLE `promotion_decorate_component` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '编号',
|
||||
`type` int NOT NULL COMMENT '页面类型',
|
||||
`component_code` varchar(64) NOT NULL COMMENT '组件编码',
|
||||
`component_value` json NOT NULL COMMENT '组件值:json 格式。包含配置和数据',
|
||||
`page_id` int NOT NULL COMMENT '所属页面id',
|
||||
`code` varchar(64) NOT NULL COMMENT '组件编码',
|
||||
`value` json NOT NULL COMMENT '组件值:json 格式。包含配置和数据',
|
||||
`status` tinyint NOT NULL DEFAULT 0 COMMENT '状态',
|
||||
`creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者',
|
||||
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
|
|
|
@ -7,22 +7,22 @@ import lombok.Getter;
|
|||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 装修页面类型枚举
|
||||
* 装修页面枚举
|
||||
*
|
||||
* @author jason
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum DecoratePageTypeEnum implements IntArrayValuable {
|
||||
public enum DecoratePageEnum implements IntArrayValuable {
|
||||
|
||||
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;
|
||||
/**
|
||||
* 页面名称
|
||||
*/
|
|
@ -4,7 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
|||
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.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 io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
|
@ -36,11 +36,11 @@ public class DecorateComponentController {
|
|||
|
||||
@GetMapping("/get-page-components")
|
||||
@Operation(summary = "获取装修页面组件")
|
||||
@Parameter(name = "type", description = "页面类型", required = true)
|
||||
@Parameter(name = "pageId", description = "页面 id", required = true)
|
||||
// TODO 加权限
|
||||
public CommonResult<DecorateComponentRespVO> getPageComponents(
|
||||
@RequestParam("type") @InEnum(DecoratePageTypeEnum.class) Integer type) {
|
||||
return success(INSTANCE.convert2(type, decorateComponentService.getPageComponents(type)));
|
||||
@RequestParam("pageId") @InEnum(DecoratePageEnum.class) Integer pageId) {
|
||||
return success(INSTANCE.convert2(pageId, decorateComponentService.getPageComponents(pageId)));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo;
|
||||
|
||||
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 lombok.Data;
|
||||
|
||||
|
@ -13,10 +13,10 @@ import java.util.List;
|
|||
@Schema(description = "管理后台 - 页面装修 Request VO ")
|
||||
@Data
|
||||
public class DecorateComponentReqVO {
|
||||
@Schema(description = "页面类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@NotNull(message = "页面类型不能为空")
|
||||
@InEnum(DecoratePageTypeEnum.class)
|
||||
private Integer type;
|
||||
@Schema(description = "页面 id ", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@NotNull(message = "页面 id 不能为空")
|
||||
@InEnum(DecoratePageEnum.class)
|
||||
private Integer pageId;
|
||||
|
||||
@Schema(description = "页面组件列表", requiredMode = Schema.RequiredMode.REQUIRED, example = "TODO")
|
||||
@NotEmpty(message = "页面组件列表不能为空")
|
||||
|
@ -31,11 +31,11 @@ public class DecorateComponentReqVO {
|
|||
|
||||
@Schema(description = "组件编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "nav-menu")
|
||||
@NotEmpty(message = "组件编码不能为空")
|
||||
private String componentCode;
|
||||
private String code;
|
||||
|
||||
@Schema(description = "组件对应值, json 字符串, 含内容配置,具体数据", requiredMode = Schema.RequiredMode.REQUIRED, example = "TODO")
|
||||
@NotEmpty(message = "组件值为空")
|
||||
private String componentValue;
|
||||
private String value;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,8 +9,8 @@ import java.util.List;
|
|||
@Data
|
||||
public class DecorateComponentRespVO {
|
||||
|
||||
@Schema(description = "页面类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Integer type;
|
||||
@Schema(description = "页面 id ", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Integer pageId;
|
||||
|
||||
@Schema(description = "页面组件", requiredMode = Schema.RequiredMode.REQUIRED, example = "TODO")
|
||||
private List<ComponentRespVO> components;
|
||||
|
@ -23,10 +23,10 @@ public class DecorateComponentRespVO {
|
|||
private Long id;
|
||||
|
||||
@Schema(description = "组件编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "nav-menu")
|
||||
private String componentCode;
|
||||
private String code;
|
||||
|
||||
@Schema(description = "组件的内容配置项", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "TODO")
|
||||
private String componentValue;
|
||||
private String value;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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.validation.InEnum;
|
||||
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 io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
|
@ -30,10 +30,10 @@ public class AppDecorateController {
|
|||
|
||||
@GetMapping("/get-page-components")
|
||||
@Operation(summary = "获取装修页面组件")
|
||||
@Parameter(name = "type", description = "页面类型", required = true)
|
||||
@Parameter(name = "pageId", description = "页面 id", required = true)
|
||||
public CommonResult<AppDecorateComponentRespVO> getPageComponents(
|
||||
@RequestParam("type") @InEnum(DecoratePageTypeEnum.class) Integer type) {
|
||||
return success(INSTANCE.appConvert(type, decorateComponentService.getPageComponents(type)));
|
||||
@RequestParam("pageId") @InEnum(DecoratePageEnum.class) Integer pageId) {
|
||||
return success(INSTANCE.appConvert(pageId, decorateComponentService.getPageComponents(pageId)));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,8 +9,8 @@ import java.util.List;
|
|||
@Data
|
||||
public class AppDecorateComponentRespVO {
|
||||
|
||||
@Schema(description = "页面类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Integer type;
|
||||
@Schema(description = "页面 id ", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Integer pageId;
|
||||
|
||||
@Schema(description = "页面组件", requiredMode = Schema.RequiredMode.REQUIRED, example = "TODO")
|
||||
private List<AppComponentRespVO> components;
|
||||
|
@ -19,14 +19,11 @@ public class AppDecorateComponentRespVO {
|
|||
@Data
|
||||
public static class AppComponentRespVO {
|
||||
|
||||
@Schema(description = "组件编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "组件编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "nav-menu")
|
||||
private String componentCode;
|
||||
private String code;
|
||||
|
||||
@Schema(description = "组件的内容配置项", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "TODO")
|
||||
private String componentValue;
|
||||
private String value;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -18,23 +18,23 @@ public interface DecorateComponentConvert {
|
|||
|
||||
DecorateComponentConvert INSTANCE = Mappers.getMapper(DecorateComponentConvert.class);
|
||||
|
||||
default List<DecorateComponentDO> convertList(Integer type, List<DecorateComponentReqVO.ComponentReqVO> components) {
|
||||
return CollectionUtils.convertList(components, c -> convert(type, c));
|
||||
default List<DecorateComponentDO> convertList(Integer pageId, List<DecorateComponentReqVO.ComponentReqVO> components) {
|
||||
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);
|
||||
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);
|
||||
|
||||
// ========== 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);
|
||||
return new AppDecorateComponentRespVO().setType(type).setComponents(components);
|
||||
return new AppDecorateComponentRespVO().setPageId(pageId).setComponents(components);
|
||||
}
|
||||
|
||||
AppComponentRespVO appConvert2(DecorateComponentDO bean);
|
||||
|
|
|
@ -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.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 com.baomidou.mybatisplus.annotation.*;
|
||||
|
||||
|
@ -24,23 +24,22 @@ public class DecorateComponentDO extends BaseDO {
|
|||
@TableId
|
||||
private Long id;
|
||||
|
||||
// TODO @jason:要不改成 page?貌似更合理;
|
||||
/**
|
||||
* 页面类型
|
||||
* 枚举 {@link DecoratePageTypeEnum#getType()}
|
||||
* 所属页面 id
|
||||
* 枚举 {@link DecoratePageEnum#getId()}
|
||||
*/
|
||||
private Integer type;
|
||||
private Integer pageId;
|
||||
|
||||
// TODO @jason:code、value,因为在 component
|
||||
/**
|
||||
* 组件编码
|
||||
* 枚举 {@link DecorateComponentEnum#getCode()}
|
||||
*/
|
||||
private String componentCode;
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 组件值:json 格式。包含配置和数据
|
||||
*/
|
||||
private String componentValue;
|
||||
private String value;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
|
|
|
@ -9,8 +9,8 @@ import java.util.List;
|
|||
@Mapper
|
||||
public interface DecorateComponentMapper extends BaseMapperX<DecorateComponentDO> {
|
||||
|
||||
default List<DecorateComponentDO> selectByPageType(Integer type){
|
||||
return selectList(DecorateComponentDO::getType, type);
|
||||
default List<DecorateComponentDO> selectByPage(Integer pageId){
|
||||
return selectList(DecorateComponentDO::getPageId, pageId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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.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;
|
||||
|
||||
|
@ -21,10 +21,10 @@ public interface DecorateComponentService {
|
|||
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);
|
||||
|
||||
}
|
||||
|
|
|
@ -29,9 +29,9 @@ public class DecorateComponentServiceImpl implements DecorateComponentService {
|
|||
@Override
|
||||
public void pageSave(DecorateComponentReqVO reqVO) {
|
||||
// 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.删除相关组件
|
||||
Set<Long> deleteIds = convertSet(oldList, DecorateComponentDO::getId);
|
||||
deleteIds.removeAll(convertSet(reqVO.getComponents(), ComponentReqVO::getId, vo->Objects.nonNull(vo.getId())));
|
||||
|
@ -41,8 +41,8 @@ public class DecorateComponentServiceImpl implements DecorateComponentService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<DecorateComponentDO> getPageComponents(Integer type) {
|
||||
return decorateComponentMapper.selectByPageType(type);
|
||||
public List<DecorateComponentDO> getPageComponents(Integer pageId) {
|
||||
return decorateComponentMapper.selectByPage(pageId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import java.util.ArrayList;
|
|||
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.DecoratePageTypeEnum.INDEX;
|
||||
import static cn.iocoder.yudao.module.promotion.enums.decorate.DecoratePageEnum.INDEX;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
|
||||
/**
|
||||
|
@ -36,10 +36,10 @@ public class DecorateComponentServiceImplTest extends BaseMockitoUnitTest {
|
|||
void testResp(){
|
||||
List<DecorateComponentDO> list = new ArrayList<>(1);
|
||||
DecorateComponentDO decorateDO = new DecorateComponentDO()
|
||||
.setType(INDEX.getType()).setComponentValue("")
|
||||
.setComponentCode(ROLLING_BANNER.getCode()).setId(1L);
|
||||
.setPageId(INDEX.getId()).setValue("")
|
||||
.setCode(ROLLING_BANNER.getCode()).setId(1L);
|
||||
list.add(decorateDO);
|
||||
//mock 方法
|
||||
Mockito.when(decorateComponentMapper.selectByPageType(eq(1))).thenReturn(list);
|
||||
Mockito.when(decorateComponentMapper.selectByPage(eq(1))).thenReturn(list);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue