营销:

1. 调整店铺装修接口
This commit is contained in:
YunaiV 2023-08-16 22:11:18 +08:00
parent a159a983a2
commit c3de25e760
14 changed files with 149 additions and 151 deletions

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.promotion.enums.decorate;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
@ -8,11 +9,44 @@ import lombok.Getter;
* @author jason
*/
@Getter
@AllArgsConstructor
@SuppressWarnings("JavadocLinkAsPlainText")
public enum DecorateComponentEnum {
NAV_MENU("nav-menu", "导航菜单"),
ROLLING_BANNER("rolling-banner", "滚动横幅广告"),
PRODUCT_CATEGORY("product-category", "商品分类");
/**
* 格式[{
* "name": "标题"
* "picUrl": "https://www.iocoder.cn/xxx.png",
* "url": "/pages/users/index"
* }]
*
* 最多 10
*/
MENU("menu", "菜单"),
/**
* 格式[{
* "name": "标题"
* "url": "/pages/users/index"
* }]
*/
ROLLING_NEWS("scrolling-news", "滚动新闻"),
/**
* 格式[{
* "picUrl": "https://www.iocoder.cn/xxx.png",
* "url": "/pages/users/index"
* }]
*/
SLIDE_SHOW("slide-show", "轮播图"),
/**
* 格式[{
* "name": "标题"
* "type": "类型", // besthotnewbenefitgood
* "tag": "标签" // 例如说多买多省
* }]
*
* 最多 4
*/
PRODUCT_RECOMMEND("product-recommend", "商品推荐");
/**
* 页面组件代码
@ -24,9 +58,4 @@ public enum DecorateComponentEnum {
*/
private final String desc;
DecorateComponentEnum(String code, String desc) {
this.code = code;
this.desc = desc;
}
}

View File

@ -17,12 +17,13 @@ public enum DecoratePageEnum implements IntArrayValuable {
INDEX(1, "首页");
private static final int[] ARRAYS = Arrays.stream(values()).mapToInt(DecoratePageEnum::getId).toArray();
private static final int[] ARRAYS = Arrays.stream(values()).mapToInt(DecoratePageEnum::getPage).toArray();
/**
* 页面 id
* 页面编号
*/
private final Integer id;
private final Integer page;
/**
* 页面名称
*/

View File

@ -0,0 +1,18 @@
### /promotion/decorate/save 保存页面装修组件
POST {{baseUrl}}/promotion/decorate/save
Content-Type: application/json
Authorization: Bearer {{token}}
tenant-id: {{adminTenentId}}
{
"page": 1,
"code": "slide-show",
"status": 0,
"value": "null"
}
### /promotion/decorate/list 获取指定页面的组件列表
GET {{baseUrl}}/promotion/decorate/list?page=1
Content-Type: application/json
Authorization: Bearer {{token}}
tenant-id: {{adminTenentId}}

View File

@ -2,45 +2,49 @@ package cn.iocoder.yudao.module.promotion.controller.admin.decorate;
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.DecorateComponentSaveReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo.DecorateComponentRespVO;
import cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo.DecorateComponentSaveReqVO;
import cn.iocoder.yudao.module.promotion.convert.decorate.DecorateComponentConvert;
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;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.module.promotion.convert.decorate.DecorateComponentConvert.INSTANCE;
@Tag(name = "管理后台 - 店铺页面装修")
@RestController
@RequestMapping("/promotion/decorate")
@Validated
public class DecorateComponentController {
@Resource
private DecorateComponentService decorateComponentService;
@PostMapping("/page-save")
@Operation(summary = "保存页面装修")
// TODO 加权限
public CommonResult<Boolean> savePageComponents(@Valid @RequestBody DecorateComponentSaveReqVO reqVO) {
decorateComponentService.savePageComponents(reqVO);
@PostMapping("/save")
@Operation(summary = "保存页面装修组件")
@PreAuthorize("@ss.hasPermission('promotion:decorate:save')")
public CommonResult<Boolean> saveDecorateComponent(@Valid @RequestBody DecorateComponentSaveReqVO reqVO) {
decorateComponentService.saveDecorateComponent(reqVO);
return success(true);
}
@GetMapping("/get-page-components")
@Operation(summary = "获取装修页面组件")
@Parameter(name = "pageId", description = "页面 id", required = true)
// TODO 加权限
public CommonResult<DecorateComponentRespVO> getPageComponents(
@RequestParam("pageId") @InEnum(DecoratePageEnum.class) Integer pageId) {
return success(INSTANCE.convert2(pageId, decorateComponentService.getPageComponents(pageId)));
@GetMapping("/list")
@Operation(summary = "获取指定页面的组件列表")
@Parameter(name = "page", description = "页面 id", required = true)
@PreAuthorize("@ss.hasPermission('promotion:decorate:query')")
public CommonResult<List<DecorateComponentRespVO>> getDecorateComponentListByPage(
@RequestParam("page") @InEnum(DecoratePageEnum.class) Integer page) {
return success(DecorateComponentConvert.INSTANCE.convertList02(
decorateComponentService.getDecorateComponentListByPage(page, null)));
}
}

View File

@ -3,31 +3,17 @@ package cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;
@Schema(description = "管理后台 - 页面装修 Resp VO")
@Data
public class DecorateComponentRespVO {
@Schema(description = "页面 id ", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer pageId;
@Schema(description = "组件编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "nav-menu")
private String code;
@Schema(description = "页面组件", requiredMode = Schema.RequiredMode.REQUIRED, example = "TODO")
private List<ComponentRespVO> components;
@Schema(description = "组件的内容配置项", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "TODO")
private String value;
@Schema(description = "管理后台 - 页面组件 Resp VO")
@Data
public static class ComponentRespVO {
@Schema(description = "组件编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Long id;
@Schema(description = "组件编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "nav-menu")
private String code;
@Schema(description = "组件的内容配置项", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "TODO")
private String value;
}
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer status;
}

View File

@ -5,10 +5,8 @@ import cn.iocoder.yudao.module.promotion.enums.decorate.DecoratePageEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;
@Schema(description = "管理后台 - 页面装修的保存 Request VO ")
@Data
@ -17,28 +15,17 @@ public class DecorateComponentSaveReqVO {
@Schema(description = "页面 id ", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "页面 id 不能为空")
@InEnum(DecoratePageEnum.class)
private Integer pageId;
private Integer page;
@Schema(description = "页面组件列表", requiredMode = Schema.RequiredMode.REQUIRED, example = "TODO")
@NotEmpty(message = "页面组件列表不能为空")
@Valid
private List<ComponentReqVO> components;
@Schema(description = "组件编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "nav-menu")
@NotEmpty(message = "组件编码不能为空")
private String code;
@Schema(description = "管理后台 - 页面装修组件 Request VO")
@Data
public static class ComponentReqVO {
@Schema(description = "组件对应值, json 字符串, 含内容配置,具体数据", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "组件值为空")
private String value;
@Schema(description = "组件编码", example = "1")
private Long id;
@Schema(description = "组件编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "nav-menu")
@NotEmpty(message = "组件编码不能为空")
private String code;
@Schema(description = "组件对应值, json 字符串, 含内容配置,具体数据", requiredMode = Schema.RequiredMode.REQUIRED, example = "TODO")
@NotEmpty(message = "组件值为空")
private String value;
}
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer status;
}

View File

@ -1,8 +1,10 @@
package cn.iocoder.yudao.module.promotion.controller.app.decorate;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
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.convert.decorate.DecorateComponentConvert;
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;
@ -15,9 +17,9 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.module.promotion.convert.decorate.DecorateComponentConvert.INSTANCE;
@Tag(name = "用户 APP - 店铺装修")
@RestController
@ -28,12 +30,13 @@ public class AppDecorateController {
@Resource
private DecorateComponentService decorateComponentService;
@GetMapping("/get-page-components")
@Operation(summary = "获取装修页面组件")
@Parameter(name = "pageId", description = "页面 id", required = true)
public CommonResult<AppDecorateComponentRespVO> getPageComponents(
@RequestParam("pageId") @InEnum(DecoratePageEnum.class) Integer pageId) {
return success(INSTANCE.appConvert(pageId, decorateComponentService.getPageComponents(pageId)));
@GetMapping("/get-component-list")
@Operation(summary = "获取指定页面的组件列表")
@Parameter(name = "page", description = "页面编号", required = true)
public CommonResult<List<AppDecorateComponentRespVO>> getDecorateComponentListByPage(
@RequestParam("page") @InEnum(DecoratePageEnum.class) Integer page) {
return success(DecorateComponentConvert.INSTANCE.convertList(
decorateComponentService.getDecorateComponentListByPage(page, CommonStatusEnum.ENABLE.getStatus())));
}
}

View File

@ -3,28 +3,14 @@ package cn.iocoder.yudao.module.promotion.controller.app.decorate.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;
@Schema(description = "用户 App - 页面装修 Resp VO")
@Schema(description = "用户 App - 页面组件 Resp VO")
@Data
public class AppDecorateComponentRespVO {
@Schema(description = "页面 id ", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer pageId;
@Schema(description = "组件编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "nav-menu")
private String code;
@Schema(description = "页面组件", requiredMode = Schema.RequiredMode.REQUIRED, example = "TODO")
private List<AppComponentRespVO> components;
@Schema(description = "用户 App - 页面组件 Resp VO")
@Data
public static class AppComponentRespVO {
@Schema(description = "组件编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "nav-menu")
private String code;
@Schema(description = "组件的内容配置项", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "TODO")
private String value;
}
@Schema(description = "组件的内容配置项", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "TODO")
private String value;
}

View File

@ -1,8 +1,7 @@
package cn.iocoder.yudao.module.promotion.convert.decorate;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo.DecorateComponentSaveReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo.DecorateComponentRespVO;
import cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo.DecorateComponentSaveReqVO;
import cn.iocoder.yudao.module.promotion.controller.app.decorate.vo.AppDecorateComponentRespVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.decorate.DecorateComponentDO;
import org.mapstruct.Mapper;
@ -10,33 +9,15 @@ import org.mapstruct.factory.Mappers;
import java.util.List;
import static cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo.DecorateComponentRespVO.*;
import static cn.iocoder.yudao.module.promotion.controller.app.decorate.vo.AppDecorateComponentRespVO.*;
@Mapper
public interface DecorateComponentConvert {
DecorateComponentConvert INSTANCE = Mappers.getMapper(DecorateComponentConvert.class);
default List<DecorateComponentDO> convertList(Integer pageId, List<DecorateComponentSaveReqVO.ComponentReqVO> components) {
return CollectionUtils.convertList(components, c -> convert(pageId, c));
}
List<DecorateComponentRespVO> convertList02(List<DecorateComponentDO> list);
default DecorateComponentRespVO convert2(Integer pageId, List<DecorateComponentDO> list) {
List<ComponentRespVO> components = CollectionUtils.convertList(list, this::convert3);
return new DecorateComponentRespVO().setPageId(pageId).setComponents(components);
}
DecorateComponentDO convert(DecorateComponentSaveReqVO bean);
DecorateComponentDO convert(Integer pageId, DecorateComponentSaveReqVO.ComponentReqVO reqVO);
ComponentRespVO convert3(DecorateComponentDO componentDO);
// ========== App convert ==========
default AppDecorateComponentRespVO appConvert(Integer pageId, List<DecorateComponentDO> list) {
List<AppComponentRespVO> components = CollectionUtils.convertList(list, this::appConvert2);
return new AppDecorateComponentRespVO().setPageId(pageId).setComponents(components);
}
AppComponentRespVO appConvert2(DecorateComponentDO bean);
List<AppDecorateComponentRespVO> convertList(List<DecorateComponentDO> list);
}

View File

@ -26,13 +26,14 @@ public class DecorateComponentDO extends BaseDO {
/**
* 所属页面 id
* 枚举 {@link DecoratePageEnum#getId()}
*
* 枚举 {@link DecoratePageEnum#getPage()}
*/
private Integer pageId;
private Integer page;
/**
* 组件编码
* 枚举 {@link DecorateComponentEnum#getCode()}
* 组件编码
* 枚举 {@link DecorateComponentEnum#getCode()}
*/
private String code;
@ -47,4 +48,5 @@ public class DecorateComponentDO extends BaseDO {
* 枚举 {@link CommonStatusEnum}
*/
private Integer status;
}

View File

@ -1,7 +1,8 @@
package cn.iocoder.yudao.module.promotion.dal.mysql.decorate;
import cn.iocoder.yudao.module.promotion.dal.dataobject.decorate.DecorateComponentDO;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.promotion.dal.dataobject.decorate.DecorateComponentDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@ -9,8 +10,15 @@ import java.util.List;
@Mapper
public interface DecorateComponentMapper extends BaseMapperX<DecorateComponentDO> {
default List<DecorateComponentDO> selectByPage(Integer pageId){
return selectList(DecorateComponentDO::getPageId, pageId);
default List<DecorateComponentDO> selectListByPageAndStatus(Integer page, Integer status) {
return selectList(new LambdaQueryWrapperX<DecorateComponentDO>()
.eq(DecorateComponentDO::getPage, page)
.eqIfPresent(DecorateComponentDO::getStatus, status));
}
default DecorateComponentDO selectByPageAndCode(Integer page, String code) {
return selectOne(DecorateComponentDO::getPage, page,
DecorateComponentDO::getCode, code);
}
}

View File

@ -14,17 +14,18 @@ import java.util.List;
public interface DecorateComponentService {
/**
* 店铺装修页面保存
* 保存页面的组件信息
*
* @param reqVO 请求 VO
*/
void savePageComponents(DecorateComponentSaveReqVO reqVO);
void saveDecorateComponent(DecorateComponentSaveReqVO reqVO);
/**
* 根据页面 id获取页面的组件信息
* 根据页面 id获取页面的组件信息
*
* @param pageId 页面类型 {@link DecoratePageEnum#getId()}
* @param page 页面编号 {@link DecoratePageEnum#getPage()}
* @param status 状态
*/
List<DecorateComponentDO> getPageComponents(Integer pageId);
List<DecorateComponentDO> getDecorateComponentListByPage(Integer page, Integer status);
}

View File

@ -1,19 +1,13 @@
package cn.iocoder.yudao.module.promotion.service.decorate;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo.DecorateComponentSaveReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo.DecorateComponentSaveReqVO.ComponentReqVO;
import cn.iocoder.yudao.module.promotion.convert.decorate.DecorateComponentConvert;
import cn.iocoder.yudao.module.promotion.dal.dataobject.decorate.DecorateComponentDO;
import cn.iocoder.yudao.module.promotion.dal.mysql.decorate.DecorateComponentMapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
import static cn.iocoder.yudao.module.promotion.convert.decorate.DecorateComponentConvert.INSTANCE;
/**
* 装修组件 Service 实现
@ -27,22 +21,20 @@ public class DecorateComponentServiceImpl implements DecorateComponentService {
private DecorateComponentMapper decorateComponentMapper;
@Override
public void savePageComponents(DecorateComponentSaveReqVO reqVO) {
// 1.新增或修改页面组件
List<DecorateComponentDO> oldList = decorateComponentMapper.selectByPage(reqVO.getPageId());
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())));
if (CollUtil.isNotEmpty(deleteIds)) {
decorateComponentMapper.deleteBatchIds(deleteIds);
public void saveDecorateComponent(DecorateComponentSaveReqVO reqVO) {
// 1. 如果存在则进行更新
DecorateComponentDO dbComponent = decorateComponentMapper.selectByPageAndCode(reqVO.getPage(), reqVO.getCode());
if (dbComponent != null) {
decorateComponentMapper.updateById(DecorateComponentConvert.INSTANCE.convert(reqVO).setId(dbComponent.getId()));
return;
}
// 2. 不存在则进行新增
decorateComponentMapper.insert(DecorateComponentConvert.INSTANCE.convert(reqVO));
}
@Override
public List<DecorateComponentDO> getPageComponents(Integer pageId) {
return decorateComponentMapper.selectByPage(pageId);
public List<DecorateComponentDO> getDecorateComponentListByPage(Integer page, Integer status) {
return decorateComponentMapper.selectListByPageAndStatus(page, status);
}
}

View File

@ -12,7 +12,7 @@ import org.mockito.Mockito;
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.DecorateComponentEnum.ROLLING_NEWS;
import static cn.iocoder.yudao.module.promotion.enums.decorate.DecoratePageEnum.INDEX;
import static org.mockito.ArgumentMatchers.eq;
@ -37,10 +37,10 @@ public class DecorateComponentServiceImplTest extends BaseMockitoUnitTest {
void testResp(){
List<DecorateComponentDO> list = new ArrayList<>(1);
DecorateComponentDO decorateDO = new DecorateComponentDO()
.setPageId(INDEX.getId()).setValue("")
.setCode(ROLLING_BANNER.getCode()).setId(1L);
.setPage(INDEX.getPage()).setValue("")
.setCode(ROLLING_NEWS.getCode()).setId(1L);
list.add(decorateDO);
//mock 方法
Mockito.when(decorateComponentMapper.selectByPage(eq(1))).thenReturn(list);
Mockito.when(decorateComponentMapper.selectListByPageAndStatus(eq(1))).thenReturn(list);
}
}