商品品牌的迁移,准备和前端管理后台对接
This commit is contained in:
@@ -1,12 +0,0 @@
|
||||
package cn.iocoder.mall.product.config;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
@Configuration
|
||||
@MapperScan("cn.iocoder.mall.product.dao") // 扫描对应的 Mapper 接口
|
||||
@EnableTransactionManagement(proxyTargetClass = true) // 启动事务管理。为什么使用 proxyTargetClass 参数,参见 https://blog.csdn.net/huang_550/article/details/76492600
|
||||
public class DatabaseConfiguration {
|
||||
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package cn.iocoder.mall.product.config;
|
||||
|
||||
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.mall.product.api.constant.ProductErrorCodeEnum;
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.event.EventListener;
|
||||
|
||||
@Configuration
|
||||
public class ServiceExceptionConfiguration {
|
||||
|
||||
@EventListener(ApplicationReadyEvent.class) // 可参考 https://www.cnblogs.com/ssslinppp/p/7607509.html
|
||||
public void initMessages() {
|
||||
// 从 service_exception_message.properties 加载错误码的方案
|
||||
// Properties properties;
|
||||
// try {
|
||||
// properties = PropertiesLoaderUtils.loadAllProperties("classpath:service_exception_message.properties");
|
||||
// } catch (IOException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
for (ProductErrorCodeEnum item : ProductErrorCodeEnum.values()) {
|
||||
ServiceExceptionUtil.put(item.getCode(), item.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package cn.iocoder.mall.product.convert;
|
||||
|
||||
import cn.iocoder.mall.product.api.bo.ProductBrandBO;
|
||||
import cn.iocoder.mall.product.api.dto.ProductBrandAddDTO;
|
||||
import cn.iocoder.mall.product.api.dto.ProductBrandUpdateDTO;
|
||||
import cn.iocoder.mall.product.dataobject.ProductBrandDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ProductBrandConvert {
|
||||
|
||||
ProductBrandConvert INSTANCE = Mappers.getMapper(ProductBrandConvert.class);
|
||||
|
||||
@Mappings({})
|
||||
List<ProductBrandBO> convert(List<ProductBrandDO> brands);
|
||||
|
||||
@Mappings({})
|
||||
ProductBrandBO convert(ProductBrandDO brand);
|
||||
|
||||
@Mappings({})
|
||||
ProductBrandDO convert(ProductBrandUpdateDTO brand);
|
||||
|
||||
@Mappings({})
|
||||
ProductBrandDO convert(ProductBrandAddDTO brand);
|
||||
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package cn.iocoder.mall.product.convert;
|
||||
|
||||
import cn.iocoder.mall.product.api.bo.ProductCategoryBO;
|
||||
import cn.iocoder.mall.product.api.dto.ProductCategoryAddDTO;
|
||||
import cn.iocoder.mall.product.api.dto.ProductCategoryUpdateDTO;
|
||||
import cn.iocoder.mall.product.dataobject.ProductCategoryDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ProductCategoryConvert {
|
||||
|
||||
ProductCategoryConvert INSTANCE = Mappers.getMapper(ProductCategoryConvert.class);
|
||||
|
||||
@Mappings({})
|
||||
ProductCategoryBO convertToBO(ProductCategoryDO category);
|
||||
|
||||
@Mappings({})
|
||||
List<ProductCategoryBO> convertToBO(List<ProductCategoryDO> categoryList);
|
||||
|
||||
@Mappings({})
|
||||
ProductCategoryDO convert(ProductCategoryAddDTO productCategoryAddDTO);
|
||||
|
||||
@Mappings({})
|
||||
ProductCategoryDO convert(ProductCategoryUpdateDTO productCategoryUpdateDTO);
|
||||
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
package cn.iocoder.mall.product.dao;
|
||||
|
||||
import cn.iocoder.mall.product.dataobject.ProductBrandDO;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface ProductBrandMapper {
|
||||
|
||||
/**
|
||||
* 根据 id 获取数据
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
ProductBrandDO selectById(@Param("id") Integer id);
|
||||
|
||||
/**
|
||||
* 根据 name 获取数据
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
ProductBrandDO selectByName(@Param("name") String name);
|
||||
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
* @param name 名称
|
||||
* @param description 描述
|
||||
* @param status 状态 1开启 2禁用
|
||||
* @param offset 偏移量
|
||||
* @param limit 数量
|
||||
* @return
|
||||
*/
|
||||
List<ProductBrandDO> selectListByParams(@Param("name") String name,
|
||||
@Param("description") String description,
|
||||
@Param("status") Integer status,
|
||||
@Param("offset") Integer offset,
|
||||
@Param("limit") Integer limit);
|
||||
|
||||
/**
|
||||
* 分页数量统计
|
||||
* @param name 名称
|
||||
* @param description 描述
|
||||
* @param status 状态 1开启 2禁用
|
||||
* @return
|
||||
*/
|
||||
Integer selectListCountByParams(@Param("name") String name,
|
||||
@Param("description") String description,
|
||||
@Param("status") Integer status);
|
||||
|
||||
/**
|
||||
* 新增数据
|
||||
* @param productBrandDO
|
||||
*/
|
||||
void insert(ProductBrandDO productBrandDO);
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
* @param productBrandDO
|
||||
*/
|
||||
void update(ProductBrandDO productBrandDO);
|
||||
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package cn.iocoder.mall.product.dao;
|
||||
|
||||
import cn.iocoder.mall.product.dataobject.ProductCategoryDO;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface ProductCategoryMapper {
|
||||
|
||||
List<ProductCategoryDO> selectListByPidAndStatusOrderBySort(@Param("pid") Integer pid,
|
||||
@Param("status") Integer status);
|
||||
|
||||
List<ProductCategoryDO> selectList();
|
||||
|
||||
ProductCategoryDO selectById(@Param("id") Integer id);
|
||||
|
||||
List<ProductCategoryDO> selectByIds(@Param("ids") Collection<Integer> ids);
|
||||
|
||||
void insert(ProductCategoryDO productCategoryDO);
|
||||
|
||||
int update(ProductCategoryDO productCategoryDO);
|
||||
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package cn.iocoder.mall.product.dataobject;
|
||||
|
||||
import cn.iocoder.mall.mybatis.core.dataobject.DeletableDO;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* Product 品牌
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductBrandDO extends DeletableDO {
|
||||
|
||||
/**
|
||||
* 规格编号
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 图片地址
|
||||
*/
|
||||
private String picUrl;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*
|
||||
* 1-开启
|
||||
* 2-禁用
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
package cn.iocoder.mall.product.dataobject;
|
||||
|
||||
import cn.iocoder.mall.mybatis.core.dataobject.DeletableDO;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 商品分类
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductCategoryDO extends DeletableDO {
|
||||
|
||||
/**
|
||||
* 分类编号
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 父分类编号
|
||||
*
|
||||
* 如果不存在父级,则 pid = 0 。
|
||||
*/
|
||||
private Integer pid;
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 分类图片
|
||||
*/
|
||||
private String picUrl;
|
||||
/**
|
||||
* 排序值
|
||||
*/
|
||||
private Integer sort;
|
||||
/**
|
||||
* 状态
|
||||
*
|
||||
* 1-开启
|
||||
* 2-关闭
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
package cn.iocoder.mall.product.service;
|
||||
|
||||
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.mall.product.api.ProductBrandService;
|
||||
import cn.iocoder.mall.product.api.bo.ProductBrandBO;
|
||||
import cn.iocoder.mall.product.api.bo.ProductBrangPageBO;
|
||||
import cn.iocoder.mall.product.api.constant.ProductErrorCodeEnum;
|
||||
import cn.iocoder.mall.product.api.dto.ProductBrandAddDTO;
|
||||
import cn.iocoder.mall.product.api.dto.ProductBrandPageDTO;
|
||||
import cn.iocoder.mall.product.api.dto.ProductBrandUpdateDTO;
|
||||
import cn.iocoder.mall.product.convert.ProductBrandConvert;
|
||||
import cn.iocoder.mall.product.dao.ProductBrandMapper;
|
||||
import cn.iocoder.mall.product.dataobject.ProductBrandDO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 商品规格 Service 实现类
|
||||
*
|
||||
* @see ProductBrandDO
|
||||
*/
|
||||
@Service
|
||||
@org.apache.dubbo.config.annotation.Service(validation = "true", version = "${dubbo.provider.ProductBrandService.version}")
|
||||
public class ProductBrandServiceImpl implements ProductBrandService {
|
||||
|
||||
@Autowired
|
||||
private ProductBrandMapper productBrandMapper;
|
||||
|
||||
/**
|
||||
* 获取品牌分页数据
|
||||
* @param productBrandPageDTO 分页参数
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ProductBrangPageBO getProductBrandPage(ProductBrandPageDTO productBrandPageDTO) {
|
||||
ProductBrangPageBO productBrangPageBO = new ProductBrangPageBO();
|
||||
// 查询分页数据
|
||||
int offset = (productBrandPageDTO.getPageNo() - 1) * productBrandPageDTO.getPageSize();
|
||||
productBrangPageBO.setBrands(
|
||||
ProductBrandConvert.INSTANCE.convert(
|
||||
productBrandMapper.selectListByParams(productBrandPageDTO.getName(),
|
||||
productBrandPageDTO.getDescription(),
|
||||
productBrandPageDTO.getStatus(),
|
||||
offset, productBrandPageDTO.getPageSize())));
|
||||
// 查询分页总数
|
||||
productBrangPageBO.setCount(productBrandMapper.selectListCountByParams(productBrandPageDTO.getName(),
|
||||
productBrandPageDTO.getDescription(),
|
||||
productBrandPageDTO.getStatus()));
|
||||
return productBrangPageBO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取品牌明细
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ProductBrandBO getProductBrand(Integer id) {
|
||||
ProductBrandBO productBrandBO = new ProductBrandBO();
|
||||
productBrandBO = ProductBrandConvert.INSTANCE.convert(productBrandMapper.selectById(id));
|
||||
return productBrandBO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加品牌
|
||||
* @param adminId
|
||||
* @param productBrandAddDTO 添加参数
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ProductBrandBO addProductBrand(Integer adminId, ProductBrandAddDTO productBrandAddDTO) {
|
||||
// 校验品牌名不重复
|
||||
if (productBrandMapper.selectByName(productBrandAddDTO.getName()) != null) {
|
||||
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_BRAND_EXIST.getCode());
|
||||
}
|
||||
ProductBrandDO productBrandDO = new ProductBrandDO();
|
||||
productBrandDO = ProductBrandConvert.INSTANCE.convert(productBrandAddDTO);
|
||||
productBrandMapper.insert(productBrandDO);
|
||||
return ProductBrandConvert.INSTANCE.convert(productBrandDO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新品牌
|
||||
* @param adminId
|
||||
* @param productBrandUpdateDTO 更新参数
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Boolean updateProductBrand(Integer adminId, ProductBrandUpdateDTO productBrandUpdateDTO) {
|
||||
ProductBrandDO productBrandDO = new ProductBrandDO();
|
||||
productBrandDO = ProductBrandConvert.INSTANCE.convert(productBrandUpdateDTO);
|
||||
productBrandMapper.update(productBrandDO);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="cn.iocoder.mall.product.dao.ProductBrandMapper">
|
||||
|
||||
<sql id="FIELDS">
|
||||
id, name, description, pic_url, status, create_time
|
||||
</sql>
|
||||
|
||||
<select id="selectById" parameterType="Integer" resultType="ProductBrandDO">
|
||||
SELECT
|
||||
<include refid="FIELDS" />
|
||||
FROM product_brand
|
||||
WHERE id = #{id}
|
||||
AND deleted = 0
|
||||
</select>
|
||||
|
||||
<select id="selectByName" parameterType="String" resultType="ProductBrandDO">
|
||||
SELECT
|
||||
<include refid="FIELDS" />
|
||||
FROM product_brand
|
||||
WHERE name = #{name}
|
||||
AND deleted = 0
|
||||
</select>
|
||||
|
||||
|
||||
<insert id="insert" parameterType="ProductBrandDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
|
||||
INSERT INTO product_brand (
|
||||
name, description, pic_url, status, create_time, deleted
|
||||
) VALUES (
|
||||
#{name}, #{description}, #{picUrl}, #{status}, #{createTime}, #{deleted}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="update" parameterType="ProductBrandDO">
|
||||
UPDATE product_brand
|
||||
<set>
|
||||
<if test="name != null">
|
||||
name = #{name},
|
||||
</if>
|
||||
<if test="description != null">
|
||||
description = #{description},
|
||||
</if>
|
||||
<if test="picUrl != null">
|
||||
pic_url = #{picUrl},
|
||||
</if>
|
||||
<if test="status != null">
|
||||
status = #{status},
|
||||
</if>
|
||||
<if test="deleted != null">
|
||||
deleted = #{deleted}
|
||||
</if>
|
||||
</set>
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
|
||||
|
||||
<select id="selectListByParams" resultType="ProductBrandDO">
|
||||
SELECT
|
||||
<include refid="FIELDS" />
|
||||
FROM product_brand
|
||||
<where>
|
||||
deleted = 0
|
||||
<if test="name != null">
|
||||
AND name LIKE "%"#{name}"%"
|
||||
</if>
|
||||
<if test="description != null">
|
||||
AND description LIKE "%"#{description}"%"
|
||||
</if>
|
||||
<if test="status != null">
|
||||
AND status = #{status}
|
||||
</if>
|
||||
</where>
|
||||
LIMIT #{offset}, #{limit}
|
||||
</select>
|
||||
|
||||
<select id="selectListCountByParams" resultType="Integer">
|
||||
SELECT
|
||||
COUNT(1)
|
||||
FROM product_brand
|
||||
<where>
|
||||
deleted = 0
|
||||
<if test="name != null">
|
||||
AND name LIKE "%"#{name}"%"
|
||||
</if>
|
||||
<if test="description != null">
|
||||
AND description LIKE "%"#{description}"%"
|
||||
</if>
|
||||
<if test="status != null">
|
||||
AND status = #{status}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -1,84 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="cn.iocoder.mall.product.dao.ProductCategoryMapper">
|
||||
|
||||
<sql id="FIELDS">
|
||||
id, pid, name, description, pic_url,
|
||||
sort, status, create_time
|
||||
</sql>
|
||||
|
||||
<select id="selectListByPidAndStatusOrderBySort" resultType="ProductCategoryDO">
|
||||
SELECT
|
||||
<include refid="FIELDS" />
|
||||
FROM product_category
|
||||
WHERE pid = #{pid}
|
||||
AND status = #{status}
|
||||
AND deleted = 0
|
||||
ORDER BY sort ASC
|
||||
</select>
|
||||
|
||||
<select id="selectList" resultType="ProductCategoryDO">
|
||||
SELECT
|
||||
<include refid="FIELDS" />
|
||||
FROM product_category
|
||||
WHERE deleted = 0
|
||||
</select>
|
||||
|
||||
<select id="selectById" parameterType="Integer" resultType="ProductCategoryDO">
|
||||
SELECT
|
||||
<include refid="FIELDS" />
|
||||
FROM product_category
|
||||
WHERE id = #{id}
|
||||
AND deleted = 0
|
||||
</select>
|
||||
|
||||
<select id="selectByIds" resultType="ProductCategoryDO">
|
||||
SELECT
|
||||
<include refid="FIELDS" />
|
||||
FROM product_category
|
||||
WHERE id IN
|
||||
<foreach collection="ids" item="id" separator="," open="(" close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
AND deleted = 0
|
||||
</select>
|
||||
|
||||
<insert id="insert" parameterType="ProductCategoryDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
|
||||
INSERT INTO product_category (
|
||||
pid, name, description, pic_url, sort,
|
||||
status, create_time, deleted
|
||||
) VALUES (
|
||||
#{pid}, #{name}, #{description}, #{picUrl}, #{sort},
|
||||
#{status}, #{createTime}, #{deleted}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="update" parameterType="ProductCategoryDO">
|
||||
UPDATE product_category
|
||||
<set>
|
||||
<if test="pid != null">
|
||||
pid = #{pid},
|
||||
</if>
|
||||
<if test="name != null">
|
||||
name = #{name},
|
||||
</if>
|
||||
<if test="description != null">
|
||||
description = #{description},
|
||||
</if>
|
||||
<if test="picUrl != null">
|
||||
pic_url = #{picUrl},
|
||||
</if>
|
||||
<if test="sort != null">
|
||||
sort = #{sort},
|
||||
</if>
|
||||
<if test="status != null">
|
||||
status = #{status},
|
||||
</if>
|
||||
<if test="deleted != null">
|
||||
deleted = #{deleted}
|
||||
</if>
|
||||
</set>
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user