合并代码
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
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);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
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);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package cn.iocoder.mall.product.dataobject;
|
||||
|
||||
import cn.iocoder.common.framework.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;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,8 @@ dubbo:
|
||||
version: 1.0.0
|
||||
ProductSpuService:
|
||||
version: 1.0.0
|
||||
ProductBrandService:
|
||||
version: 1.0.0
|
||||
OAuth2Service:
|
||||
version: 1.0.0
|
||||
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
<?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>
|
||||
Reference in New Issue
Block a user