refactor: 命名统一调整

This commit is contained in:
Ray.Hao 2024-06-14 12:50:58 +08:00
parent 7ddef1f611
commit a9cffbda4a
19 changed files with 164 additions and 141 deletions

View File

@ -3,8 +3,12 @@ package com.youlai.mall.product.controller.admin;
import com.youlai.common.result.Result;
import com.youlai.common.web.model.Option;
import com.youlai.mall.product.model.form.CategoryForm;
import com.youlai.mall.product.model.vo.AttributeGroupVO;
import com.youlai.mall.product.model.vo.CategoryVO;
import com.youlai.mall.product.model.vo.SpecVO;
import com.youlai.mall.product.service.AttrService;
import com.youlai.mall.product.service.CategoryService;
import com.youlai.mall.product.service.SpecService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
@ -27,6 +31,8 @@ import java.util.List;
public class CategoryController {
private final CategoryService categoryService;
private final AttrService attrService;
private final SpecService specService;
@Operation(summary = "获取商品分类列表")
@GetMapping
@ -69,4 +75,22 @@ public class CategoryController {
return Result.success();
}
@Operation(summary = "获取属性列表")
@GetMapping("/{categoryId}/attributes")
public Result<List<AttributeGroupVO>> listAttributesByCategoryId(
@Parameter(description = "分类ID", example = "3") @PathVariable Long categoryId
) {
List<AttributeGroupVO> list = attrService.listAttributesByCategoryId(categoryId);
return Result.success(list);
}
@Operation(summary = "获取规格列表")
@GetMapping("/{categoryId}/specs")
public Result<List<SpecVO>> listSpecsByCategoryId(
@Parameter(description = "分类ID", example = "3") @PathVariable Long categoryId
) {
List<SpecVO> list = specService.listSpecsByCategoryId(categoryId);
return Result.success(list);
}
}

View File

@ -5,7 +5,7 @@ import com.youlai.mall.product.model.form.AttrForm;
import org.mapstruct.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.youlai.mall.product.model.vo.AttributePageVO;
import com.youlai.mall.product.model.vo.AttrPageVO;
import com.youlai.mall.product.model.bo.AttrBO;
@Mapper(componentModel = "spring")
@ -14,9 +14,9 @@ public interface AttrConverter {
@Mappings({
@Mapping(target = "inputTypeLabel", expression = "java(bo.getInputType()!=null? bo.getInputType().getLabel():\"\")")
})
AttributePageVO convertToPageVo(AttrBO bo);
AttrPageVO toPageVo(AttrBO bo);
Page<AttributePageVO> convertToPageVo(Page<AttrBO> bo);
Page<AttrPageVO> toPageVo(Page<AttrBO> bo);
AttrForm convertToForm(Attr entity);

View File

@ -27,5 +27,5 @@ public interface BrandConverter {
BrandPageVO convertToVo(Brand entity);
Page<BrandPageVO> convertToPageVo(Page<Brand> page);
Page<BrandPageVO> toPageVo(Page<Brand> page);
}

View File

@ -35,7 +35,7 @@ public interface AttrMapper extends BaseMapper<Attr> {
*
* @param categoryId 分类ID
*/
List<AttributeGroupVO> listBaseAttributes(Long categoryId);
List<AttributeGroupVO> listAttributesByCategoryId(Long categoryId);
/**
* 根据分类ID获取销售属性列表

View File

@ -5,8 +5,12 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.youlai.mall.product.model.bo.SpecBO;
import com.youlai.mall.product.model.query.SpecPageQuery;
import com.youlai.mall.product.model.vo.SpecPageVO;
import com.youlai.mall.product.model.vo.SpecVO;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* Mapper 接口
*
@ -24,6 +28,13 @@ public interface SpecMapper extends BaseMapper<Spec> {
* @param queryParams 查询参数
* @return
*/
Page<SpecBO> listPagedSpecs(Page<SpecBO> page, SpecPageQuery queryParams);
Page<SpecPageVO> listPagedSpecs(Page<SpecPageVO> page, SpecPageQuery queryParams);
/**
* 根据分类ID查询规格列表
*
* @param categoryId
* @return
*/
List<SpecVO> listSpecsByCategoryId(Long categoryId);
}

View File

@ -1,9 +1,7 @@
package com.youlai.mall.product.mapper;
import com.youlai.mall.product.model.entity.SpuImage;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.youlai.mall.product.model.bo.SpuImageBO;
import com.youlai.mall.product.model.entity.SpuImage;
import org.apache.ibatis.annotations.Mapper;
/**

View File

@ -1,22 +0,0 @@
package com.youlai.mall.product.model.bo;
import java.io.Serializable;
import lombok.Getter;
import lombok.Setter;
/**
* 商品图片
*
* @author Ray Hao
* @since 2024-04-14
*/
@Getter
@Setter
public class SpuImageBO implements Serializable {
private static final long serialVersionUID = 1L;
private Long spuId;
private String imgUrl;
}

View File

@ -29,25 +29,14 @@ public class Attr extends BaseEntity {
private String name;
/**
* 属性类型1基础属性2销售属性
* @see com.youlai.mall.product.enums.AttributeTypeEnum
*/
private AttributeTypeEnum type;
/**
* 输入方式1手动输入2从列表选择
* 输入方式1->手动输入2->列表选择
*/
private AttributeInputTypeEnum inputType;
/**
* 可选值列表以逗号分隔仅当输入方式为2时使用
*/
private String selectableValues;
/**
* 分类ID
*/
private Long categoryId;
private String options;
/**
* 排序

View File

@ -6,7 +6,7 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 分页查询对象
* 规格分页查询对象
*
* @author Ray Hao
* @since 2024-06-13
@ -19,4 +19,7 @@ public class SpecPageQuery extends BasePageQuery {
@Schema(description="关键字")
private String keywords;
@Schema(description="分类ID",example = "3")
private Long categoryId;
}

View File

@ -1,8 +1,6 @@
package com.youlai.mall.product.model.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.youlai.mall.product.enums.AttributeInputTypeEnum;
import com.youlai.mall.product.enums.AttributeTypeEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
@ -18,10 +16,9 @@ import java.time.LocalDateTime;
*/
@Getter
@Setter
@Schema(description = "属性")
public class AttributePageVO implements Serializable {
@Schema(description = "属性分页对象")
public class AttrPageVO implements Serializable {
private static final long serialVersionUID = 1L;
@Schema(description = "属性主键")
private Long id;

View File

@ -1,56 +1,37 @@
package com.youlai.mall.product.model.vo;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
/**
* VO
* 规格 VO
*
* @author Ray Hao
* @since 2024-06-13
*/
@Getter
@Setter
@Schema( description = "视图对象")
@Schema(description = "规格视图对象")
public class SpecVO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Schema(description = "规格ID")
private Long id;
@Schema(description = "属性名称")
@Schema(description = "规格名称")
private String name;
@Schema(description = "输入方式1手动输入2列表选择")
private Byte inputType;
@Schema(description = "可选值列表以逗号分隔仅当输入方式为2时使用")
private String options;
@Schema(description = "分类ID")
private Long categoryId;
@Schema(description = "排序")
private Short sort;
@Schema(description = "创建时间")
private LocalDateTime createTime;
@Schema(description = "更新时间")
private LocalDateTime updateTime;
@Schema(description = "逻辑删除标识0未删除1已删除")
private Byte isDeleted;
}

View File

@ -5,7 +5,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.youlai.mall.product.model.form.AttrForm;
import com.youlai.mall.product.model.query.AttributePageQuery;
import com.youlai.mall.product.model.vo.AttributeGroupVO;
import com.youlai.mall.product.model.vo.AttributePageVO;
import com.youlai.mall.product.model.vo.AttrPageVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youlai.mall.product.model.vo.AttributeVO;
@ -23,7 +23,7 @@ public interface AttrService extends IService<Attr> {
/**
* 属性分页列表
*/
IPage<AttributePageVO> listPagedAttributes(AttributePageQuery queryParams);
IPage<AttrPageVO> listPagedAttributes(AttributePageQuery queryParams);
/**
@ -61,7 +61,7 @@ public interface AttrService extends IService<Attr> {
*
* @param categoryId 商品分类ID
*/
List<AttributeGroupVO> listBaseAttributes(Long categoryId);
List<AttributeGroupVO> listAttributesByCategoryId(Long categoryId);
/**
* 获取销售属性列表

View File

@ -6,8 +6,12 @@ import com.youlai.mall.product.model.form.SpecForm;
import com.youlai.mall.product.model.query.SpecPageQuery;
import com.youlai.mall.product.model.vo.SpecPageVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youlai.mall.product.model.vo.SpecVO;
import java.util.List;
/**
* 服务类
* 规格接口层
*
* @author Ray Hao
* @since 2024-06-13
@ -16,7 +20,7 @@ public interface SpecService extends IService<Spec> {
/**
*分页列表
* 分页列表
*
* @return
*/
@ -58,4 +62,11 @@ public interface SpecService extends IService<Spec> {
*/
boolean deleteSpecs(String ids);
/**
* 根据分类ID获取规格列表
*
* @param categoryId 分类ID
* @return
*/
List<SpecVO> listSpecsByCategoryId(Long categoryId);
}

View File

@ -5,6 +5,7 @@ import com.youlai.mall.product.model.bo.AttrBO;
import com.youlai.mall.product.model.entity.Attr;
import com.youlai.mall.product.mapper.AttrMapper;
import com.youlai.mall.product.model.form.AttrForm;
import com.youlai.mall.product.model.vo.AttrPageVO;
import com.youlai.mall.product.model.vo.AttributeGroupVO;
import com.youlai.mall.product.model.vo.AttributeVO;
import com.youlai.mall.product.service.AttrService;
@ -12,7 +13,6 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.youlai.mall.product.model.query.AttributePageQuery;
import com.youlai.mall.product.model.vo.AttributePageVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -39,15 +39,15 @@ public class AttrServiceImpl extends ServiceImpl<AttrMapper, Attr> implements At
* 获取属性分页列表
*
* @param queryParams 查询参数
* @return {@link IPage<AttributePageVO>} 属性分页列表
* @return {@link IPage< AttrPageVO >} 属性分页列表
*/
@Override
public IPage<AttributePageVO> listPagedAttributes(AttributePageQuery queryParams) {
public IPage<AttrPageVO> listPagedAttributes(AttributePageQuery queryParams) {
Page<AttrBO> page = this.baseMapper.listPagedAttributes(
new Page<>(queryParams.getPageNum(), queryParams.getPageSize()),
queryParams
);
return attributeConverter.convertToPageVo(page);
return attributeConverter.toPageVo(page);
}
/**
@ -106,8 +106,8 @@ public class AttrServiceImpl extends ServiceImpl<AttrMapper, Attr> implements At
* @param categoryId 商品分类ID
*/
@Override
public List<AttributeGroupVO> listBaseAttributes(Long categoryId) {
return this.baseMapper.listBaseAttributes(categoryId);
public List<AttributeGroupVO> listAttributesByCategoryId(Long categoryId) {
return this.baseMapper.listAttributesByCategoryId(categoryId);
}
/**

View File

@ -44,7 +44,7 @@ public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand> implements
new LambdaQueryWrapper<Brand>().like(StrUtil.isNotBlank(keywords), Brand::getName, keywords)
.orderByAsc(Brand::getSort)
);
return brandConverter.convertToPageVo(page);
return brandConverter.toPageVo(page);
}
/**

View File

@ -2,6 +2,7 @@ package com.youlai.mall.product.service.impl;
import com.youlai.mall.product.model.entity.Spec;
import com.youlai.mall.product.mapper.SpecMapper;
import com.youlai.mall.product.model.vo.SpecVO;
import com.youlai.mall.product.service.SpecService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
@ -24,7 +25,7 @@ import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
/**
* 服务实现类
* 规格服务实现类
*
* @author Ray Hao
* @since 2024-06-13
@ -47,16 +48,12 @@ public class SpecServiceImpl extends ServiceImpl<SpecMapper, Spec> implements Sp
// 参数构建
int pageNum = queryParams.getPageNum();
int pageSize = queryParams.getPageSize();
Page<SpecBO> page = new Page<>(pageNum, pageSize);
Page<SpecPageVO> page = new Page<>(pageNum, pageSize);
// 格式化为数据库日期格式避免日期比较使用格式化函数导致索引失效
DateUtils.toDatabaseFormat(queryParams, "startTime", "endTime");
// 查询数据
Page<SpecBO> boPage = this.baseMapper.listPagedSpecs(page, queryParams);
// 实体转换
return specConverter.toPageVo(boPage);
return this.baseMapper.listPagedSpecs(page, queryParams);
}
/**
@ -92,7 +89,7 @@ public class SpecServiceImpl extends ServiceImpl<SpecMapper, Spec> implements Sp
* @return
*/
@Override
public boolean updateSpec(Long id,SpecForm formData) {
public boolean updateSpec(Long id, SpecForm formData) {
Spec entity = specConverter.toEntity(formData);
return this.updateById(entity);
}
@ -113,5 +110,16 @@ public class SpecServiceImpl extends ServiceImpl<SpecMapper, Spec> implements Sp
return this.removeByIds(idList);
}
/**
* 根据分类ID获取规格列表
*
* @param categoryId 分类ID
* @return
*/
@Override
public List<SpecVO> listSpecsByCategoryId(Long categoryId) {
return this.baseMapper.listSpecsByCategoryId(categoryId);
}
}

View File

@ -11,7 +11,7 @@
ag.create_time,
c.name AS category_name
FROM
pms_attribute_group ag
pms_attr_group ag
LEFT JOIN pms_category c on ag.category_id = c.id AND c.is_deleted = 0
<where>
ag.is_deleted = 0

View File

@ -15,8 +15,8 @@
t3.NAME categoryName,
t1.create_time
FROM
`pms_attribute` t1
LEFT JOIN pms_attribute_group t2 ON t1.attribute_group_id = t2.id
`pms_attr` t1
LEFT JOIN pms_attr_group t2 ON t1.attribute_group_id = t2.id
LEFT JOIN pms_category t3 ON t1.category_id = t3.id
<where>
t1.is_deleted = 0
@ -62,19 +62,18 @@
</resultMap>
<!-- 根据分类ID获取属性组&列表 -->
<select id="listBaseAttributes" resultMap="AttributeGroupMap">
<select id="listAttributesByCategoryId" resultMap="AttributeGroupMap">
SELECT
t1.id,
t1.`name`,
t2.id AS attribute_group_id,
t2.`name` AS attribute_group_name
FROM
pms_attribute t1
INNER JOIN pms_attribute_group t2 ON t1.attribute_group_id = t2.id AND t2.is_deleted = 0
pms_attr t1
INNER JOIN pms_attr_group t2 ON t1.attribute_group_id = t2.id AND t2.is_deleted = 0
WHERE
t1.category_id = #{categoryId}
AND t1.is_deleted = 0
AND t1.type = 1
ORDER BY
t2.sort,
t1.sort
@ -99,7 +98,7 @@
t1.input_type,
t1.options
FROM
pms_attribute t1
pms_attr t1
WHERE
t1.category_id = #{categoryId}
AND t1.is_deleted = 0

View File

@ -2,29 +2,24 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.youlai.mall.product.mapper.SpecMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.youlai.mall.product.model.entity.Spec">
<id column="id" property="id" />
<result column="name" property="name" />
<result column="input_type" property="inputType" />
<result column="options" property="options" />
<result column="category_id" property="categoryId" />
<result column="sort" property="sort" />
<result column="create_time" property="createTime" />
<result column="update_time" property="updateTime" />
<result column="is_deleted" property="isDeleted" />
<resultMap id="SpecPageMap" type="com.youlai.mall.product.model.vo.SpecPageVO">
<result column="id" property="id"/>
<result column="name" property="name"/>
<result column="input_type" property="inputType"/>
<result column="options"
property="options"
typeHandler="com.youlai.common.mybatis.handler.typehandler.CommaStringListHandler"
/>
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id, name, input_type, options, category_id, sort, create_time, update_time, is_deleted
</sql>
<!-- 分页列表 -->
<select id="listPagedSpecs" resultType="com.youlai.mall.product.model.bo.SpecBO">
<select id="listPagedSpecs" resultMap="SpecPageMap">
SELECT
<include refid="Base_Column_List"/>
id,
`name`,
input_type,
options,
create_time
FROM
pms_spec
<where>
@ -41,7 +36,36 @@
AND create_time &lt;= #{queryParams.endTime}
</if>
</where>
ORDER BY create_time DESC
ORDER BY
create_time DESC
</select>
<!-- 属性映射 -->
<resultMap id="SpecMap" type="com.youlai.mall.product.model.vo.SpecVO">
<result column="id" property="id"/>
<result column="name" property="name"/>
<result column="input_type" property="inputType"/>
<result column="options"
property="options"
typeHandler="com.youlai.common.mybatis.handler.typehandler.CommaStringListHandler"
/>
</resultMap>
<!-- 根据分类ID获取销售属性列表 -->
<select id="listSpecsByCategoryId" resultMap="SpecMap">
SELECT
t1.id,
t1.`name`,
t1.input_type,
t1.options
FROM
pms_attr t1
WHERE
t1.category_id = #{categoryId}
AND t1.is_deleted = 0
AND t1.type = 2
ORDER BY
t1.sort
</select>
</mapper>