diff --git a/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/constant/AdminErrorCodeEnum.java b/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/constant/AdminErrorCodeEnum.java index 1d8c3d1f4..0d5e9e00f 100644 --- a/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/constant/AdminErrorCodeEnum.java +++ b/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/constant/AdminErrorCodeEnum.java @@ -3,7 +3,7 @@ package cn.iocoder.mall.admin.api.constant; /** * 错误码枚举类 * - * 用户中心,使用 1-002-000-000 段 + * 管理员系统,使用 1-002-000-000 段 */ public enum AdminErrorCodeEnum { diff --git a/product/product-application/pom.xml b/product/product-application/pom.xml index 685d042d2..ba9cd1f7e 100644 --- a/product/product-application/pom.xml +++ b/product/product-application/pom.xml @@ -32,6 +32,17 @@ 1.0-SNAPSHOT + + + + + + + cn.iocoder.mall + admin-sdk + 1.0-SNAPSHOT + + org.springframework.boot spring-boot-starter-web @@ -92,6 +103,13 @@ 2.9.2 + + javax.servlet + servlet-api + 2.5 + provided + + diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/application/config/MVCConfiguration.java b/product/product-application/src/main/java/cn/iocoder/mall/product/application/config/MVCConfiguration.java index 20dc73906..4e50c7d49 100644 --- a/product/product-application/src/main/java/cn/iocoder/mall/product/application/config/MVCConfiguration.java +++ b/product/product-application/src/main/java/cn/iocoder/mall/product/application/config/MVCConfiguration.java @@ -1,6 +1,8 @@ package cn.iocoder.mall.product.application.config; +import cn.iocoder.common.framework.config.GlobalExceptionHandler; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; @@ -8,7 +10,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @EnableWebMvc @Configuration -//@Import(value = {GlobalExceptionHandler.class}) // 统一全局返回 +@Import(value = {GlobalExceptionHandler.class}) // 统一全局返回 public class MVCConfiguration implements WebMvcConfigurer { // @Autowired diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/application/controller/admins/AdminsProductCategoryController.java b/product/product-application/src/main/java/cn/iocoder/mall/product/application/controller/admins/AdminsProductCategoryController.java new file mode 100644 index 000000000..c1b3ecf7e --- /dev/null +++ b/product/product-application/src/main/java/cn/iocoder/mall/product/application/controller/admins/AdminsProductCategoryController.java @@ -0,0 +1,14 @@ +package cn.iocoder.mall.product.application.controller.admins; + +import io.swagger.annotations.Api; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("admins/product/category") +@Api("商品分类") +public class AdminsProductCategoryController { + + + +} \ No newline at end of file diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/application/controller/users/ProductCategoryController.java b/product/product-application/src/main/java/cn/iocoder/mall/product/application/controller/users/ProductCategoryController.java index f439f7433..b7857d249 100644 --- a/product/product-application/src/main/java/cn/iocoder/mall/product/application/controller/users/ProductCategoryController.java +++ b/product/product-application/src/main/java/cn/iocoder/mall/product/application/controller/users/ProductCategoryController.java @@ -3,7 +3,7 @@ package cn.iocoder.mall.product.application.controller.users; import cn.iocoder.mall.product.api.ProductCategoryService; import cn.iocoder.mall.product.api.bo.ProductCategoryBO; import cn.iocoder.mall.product.application.convert.ProductCategoryConvert; -import cn.iocoder.mall.product.application.vo.ProductCategoryVO; +import cn.iocoder.mall.product.application.vo.ProductCategorySimpleVO; import com.alibaba.dubbo.config.annotation.Reference; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -15,8 +15,8 @@ import org.springframework.web.bind.annotation.RestController; import java.util.List; -@RestController -@RequestMapping("user/product/category") +@RestController("productCategoryController_users") +@RequestMapping("users/product/category") @Api("商品分类") public class ProductCategoryController { @@ -26,7 +26,7 @@ public class ProductCategoryController { @GetMapping @ApiOperation("获得指定编号下的子分类的数组") @ApiImplicitParam(name = "pid", value = "指定分类编号", required = true, example = "0") - public List list(@RequestParam("pid") Integer pid) { + public List list(@RequestParam("pid") Integer pid) { List result = productCategoryService.getListByPid(pid); return ProductCategoryConvert.INSTANCE.convertToVO(result); } diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/application/convert/ProductCategoryConvert.java b/product/product-application/src/main/java/cn/iocoder/mall/product/application/convert/ProductCategoryConvert.java index 72a73663d..687715dbe 100644 --- a/product/product-application/src/main/java/cn/iocoder/mall/product/application/convert/ProductCategoryConvert.java +++ b/product/product-application/src/main/java/cn/iocoder/mall/product/application/convert/ProductCategoryConvert.java @@ -1,7 +1,7 @@ package cn.iocoder.mall.product.application.convert; import cn.iocoder.mall.product.api.bo.ProductCategoryBO; -import cn.iocoder.mall.product.application.vo.ProductCategoryVO; +import cn.iocoder.mall.product.application.vo.ProductCategorySimpleVO; import org.mapstruct.Mapper; import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; @@ -14,9 +14,9 @@ public interface ProductCategoryConvert { ProductCategoryConvert INSTANCE = Mappers.getMapper(ProductCategoryConvert.class); @Mappings({}) - ProductCategoryVO convertToVO(ProductCategoryBO category); + ProductCategorySimpleVO convertToVO(ProductCategoryBO category); - List convertToVO(List categoryList); + List convertToVO(List categoryList); } diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/ProductCategorySimpleVO.java b/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/ProductCategorySimpleVO.java new file mode 100644 index 000000000..49d4cf801 --- /dev/null +++ b/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/ProductCategorySimpleVO.java @@ -0,0 +1,40 @@ +package cn.iocoder.mall.product.application.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +@ApiModel("商品分类(简单)") +public class ProductCategorySimpleVO { + + @ApiModelProperty(value = "分类编号", required = true, example = "1") + private Integer id; + @ApiModelProperty(value = "分类名", required = true, example = "手机") + private String name; + @ApiModelProperty(value = "分类图片", notes = "一般情况下,只有根分类才有图片", example = "http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") + private String picUrl; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPicUrl() { + return picUrl; + } + + public void setPicUrl(String picUrl) { + this.picUrl = picUrl; + } + +} \ No newline at end of file diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/ProductCategoryTreeNodeVO.java b/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/ProductCategoryTreeNodeVO.java new file mode 100644 index 000000000..532e0401f --- /dev/null +++ b/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/ProductCategoryTreeNodeVO.java @@ -0,0 +1,10 @@ +package cn.iocoder.mall.product.application.vo; + +import io.swagger.annotations.ApiModel; + +@ApiModel("产品分类树节点 VO") +public class ProductCategoryTreeNodeVO { + + + +} \ No newline at end of file diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/ProductCategoryVO.java b/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/ProductCategoryVO.java index 910f1bef0..5b5c1c70c 100644 --- a/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/ProductCategoryVO.java +++ b/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/ProductCategoryVO.java @@ -1,40 +1,4 @@ package cn.iocoder.mall.product.application.vo; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; - -@ApiModel("商品分类") public class ProductCategoryVO { - - @ApiModelProperty(value = "分类编号", required = true, example = "1") - private Integer id; - @ApiModelProperty(value = "分类名", required = true, example = "手机") - private String name; - @ApiModelProperty(value = "分类图片", notes = "一般情况下,只有根分类才有图片", example = "http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") - private String picUrl; - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getPicUrl() { - return picUrl; - } - - public void setPicUrl(String picUrl) { - this.picUrl = picUrl; - } - -} \ No newline at end of file +} diff --git a/product/product-service-api/pom.xml b/product/product-service-api/pom.xml index e85bd9c75..24117697c 100644 --- a/product/product-service-api/pom.xml +++ b/product/product-service-api/pom.xml @@ -11,4 +11,17 @@ product-service-api + + + cn.iocoder.mall + common-framework + 1.0-SNAPSHOT + + + + org.hibernate.validator + hibernate-validator + + + \ No newline at end of file diff --git a/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/ProductCategoryService.java b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/ProductCategoryService.java index 90f8e4397..55bd12082 100644 --- a/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/ProductCategoryService.java +++ b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/ProductCategoryService.java @@ -1,11 +1,31 @@ package cn.iocoder.mall.product.api; +import cn.iocoder.common.framework.vo.CommonResult; 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 java.util.List; public interface ProductCategoryService { + /** + * @param pid 指定父分类编号 + * @return 返回指定分类编号的子产品分类们 + */ List getListByPid(Integer pid); + /** + * @return 返回所有产品分类们 + */ + List getAll(); + + CommonResult addProductCategory(Integer adminId, ProductCategoryAddDTO productCategoryAddDTO); + + CommonResult updateProductCategory(Integer adminId, ProductCategoryUpdateDTO productCategoryUpdateDTO); + + CommonResult updateProductCategoryStatus(Integer adminId, Integer productCategoryId, Integer status); + + CommonResult deleteProductCategory(Integer admin, Integer productCategoryId); + } \ No newline at end of file diff --git a/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/constant/ProductCategoryConstants.java b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/constant/ProductCategoryConstants.java new file mode 100644 index 000000000..1e83e5ad6 --- /dev/null +++ b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/constant/ProductCategoryConstants.java @@ -0,0 +1,19 @@ +package cn.iocoder.mall.product.api.constant; + +public class ProductCategoryConstants { + + /** + * 状态 - 开启 + */ + public static final Integer STATUS_ENABLE = 1; + /** + * 状态 - 关闭 + */ + public static final Integer STATUS_DISABLE = 1; + + /** + * 父分类编号 - 根节点 + */ + public static final Integer PID_ROOT = 0; + +} \ No newline at end of file diff --git a/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/constant/ProductErrorCodeEnum.java b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/constant/ProductErrorCodeEnum.java new file mode 100644 index 000000000..cf84493dc --- /dev/null +++ b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/constant/ProductErrorCodeEnum.java @@ -0,0 +1,35 @@ +package cn.iocoder.mall.product.api.constant; + +/** + * 错误码枚举类 + * + * 商品系统,使用 1-003-000-000 段 + */ +public enum ProductErrorCodeEnum { + + // ========== PRODUCT CATEGORY 模块 ========== + PRODUCT_CATEGORY_PARENT_NOT_EXISTS(1003001000, "父分类不存在"), + PRODUCT_CATEGORY_NOT_EXISTS(1003001001, "商品分类不存在"), + PRODUCT_CATEGORY_PARENT_NOT_SELF(1003001002, "不能设置自己为父分类"), + PRODUCT_CATEGORY_STATUS_EQUALS(1002002003, "商品分类已经是该状态"), + PRODUCT_CATEGORY_DELETE_ONLY_DISABLE(1002002004, "只有关闭的商品分类才可以删除"), + + ; + + private final int code; + private final String message; + + ProductErrorCodeEnum(int code, String message) { + this.code = code; + this.message = message; + } + + public int getCode() { + return code; + } + + public String getMessage() { + return message; + } + +} \ No newline at end of file diff --git a/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/dto/ProductCategoryAddDTO.java b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/dto/ProductCategoryAddDTO.java new file mode 100644 index 000000000..8c677c7b5 --- /dev/null +++ b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/dto/ProductCategoryAddDTO.java @@ -0,0 +1,81 @@ +package cn.iocoder.mall.product.api.dto; + +import javax.validation.constraints.NotNull; + +/** + * 商品分类添加 DTO + */ +public class ProductCategoryAddDTO { + + /** + * 父分类编号 + */ + @NotNull(message = "父分类编号不能为空") + private Integer pid; + /** + * 名称 + */ + @NotNull(message = "名称不能为空") + private String name; + /** + * 描述 + */ + @NotNull(message = "描述不能为空") + private String description; + /** + * 分类图片 + */ + @NotNull(message = "分类图片不能为空") + private String picUrl; + /** + * 排序值 + */ + @NotNull(message = "排序值不能为空") + private Integer sort; + + public Integer getPid() { + return pid; + } + + public ProductCategoryAddDTO setPid(Integer pid) { + this.pid = pid; + return this; + } + + public String getName() { + return name; + } + + public ProductCategoryAddDTO setName(String name) { + this.name = name; + return this; + } + + public String getDescription() { + return description; + } + + public ProductCategoryAddDTO setDescription(String description) { + this.description = description; + return this; + } + + public String getPicUrl() { + return picUrl; + } + + public ProductCategoryAddDTO setPicUrl(String picUrl) { + this.picUrl = picUrl; + return this; + } + + public Integer getSort() { + return sort; + } + + public ProductCategoryAddDTO setSort(Integer sort) { + this.sort = sort; + return this; + } + +} \ No newline at end of file diff --git a/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/dto/ProductCategoryUpdateDTO.java b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/dto/ProductCategoryUpdateDTO.java new file mode 100644 index 000000000..611b6e133 --- /dev/null +++ b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/dto/ProductCategoryUpdateDTO.java @@ -0,0 +1,94 @@ +package cn.iocoder.mall.product.api.dto; + +import javax.validation.constraints.NotNull; + +/** + * 商品分类更新 DTO + */ +public class ProductCategoryUpdateDTO { + + /** + * 编号 + */ + @NotNull(message = "编号不能为空") + private Integer id; + /** + * 父分类编号 + */ + @NotNull(message = "父分类编号不能为空") + private Integer pid; + /** + * 名称 + */ + @NotNull(message = "名称不能为空") + private String name; + /** + * 描述 + */ + @NotNull(message = "描述不能为空") + private String description; + /** + * 分类图片 + */ + @NotNull(message = "分类图片不能为空") + private String picUrl; + /** + * 排序值 + */ + @NotNull(message = "排序值不能为空") + private Integer sort; + + public Integer getPid() { + return pid; + } + + public ProductCategoryUpdateDTO setPid(Integer pid) { + this.pid = pid; + return this; + } + + public String getName() { + return name; + } + + public ProductCategoryUpdateDTO setName(String name) { + this.name = name; + return this; + } + + public String getDescription() { + return description; + } + + public ProductCategoryUpdateDTO setDescription(String description) { + this.description = description; + return this; + } + + public String getPicUrl() { + return picUrl; + } + + public ProductCategoryUpdateDTO setPicUrl(String picUrl) { + this.picUrl = picUrl; + return this; + } + + public Integer getSort() { + return sort; + } + + public ProductCategoryUpdateDTO setSort(Integer sort) { + this.sort = sort; + return this; + } + + public Integer getId() { + return id; + } + + public ProductCategoryUpdateDTO setId(Integer id) { + this.id = id; + return this; + } +} \ No newline at end of file diff --git a/product/product-service-impl/src/main/java/cn/iocoder/mall/product/convert/ProductCategoryConvert.java b/product/product-service-impl/src/main/java/cn/iocoder/mall/product/convert/ProductCategoryConvert.java index 969aa6ab1..e43f76604 100644 --- a/product/product-service-impl/src/main/java/cn/iocoder/mall/product/convert/ProductCategoryConvert.java +++ b/product/product-service-impl/src/main/java/cn/iocoder/mall/product/convert/ProductCategoryConvert.java @@ -1,6 +1,8 @@ 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; @@ -16,6 +18,13 @@ public interface ProductCategoryConvert { @Mappings({}) ProductCategoryBO convertToBO(ProductCategoryDO category); + @Mappings({}) List convertToBO(List categoryList); + @Mappings({}) + ProductCategoryDO convert(ProductCategoryAddDTO productCategoryAddDTO); + + @Mappings({}) + ProductCategoryDO convert(ProductCategoryUpdateDTO productCategoryUpdateDTO); + } \ No newline at end of file diff --git a/product/product-service-impl/src/main/java/cn/iocoder/mall/product/dao/ProductCategoryMapper.java b/product/product-service-impl/src/main/java/cn/iocoder/mall/product/dao/ProductCategoryMapper.java index e1c5a3988..1e4dc1755 100644 --- a/product/product-service-impl/src/main/java/cn/iocoder/mall/product/dao/ProductCategoryMapper.java +++ b/product/product-service-impl/src/main/java/cn/iocoder/mall/product/dao/ProductCategoryMapper.java @@ -12,4 +12,14 @@ public interface ProductCategoryMapper { List selectListByPidAndStatusOrderBySort(@Param("pid") Integer pid, @Param("status") Integer status); + List selectList(); + + ProductCategoryDO selectById(@Param("id") Integer id); + + void insert(ProductCategoryDO productCategoryDO); + + int update(ProductCategoryDO productCategoryDO); + + + } \ No newline at end of file diff --git a/product/product-service-impl/src/main/java/cn/iocoder/mall/product/dataobject/ProductCategoryDO.java b/product/product-service-impl/src/main/java/cn/iocoder/mall/product/dataobject/ProductCategoryDO.java index 47690acbb..b68542bd4 100644 --- a/product/product-service-impl/src/main/java/cn/iocoder/mall/product/dataobject/ProductCategoryDO.java +++ b/product/product-service-impl/src/main/java/cn/iocoder/mall/product/dataobject/ProductCategoryDO.java @@ -1,11 +1,11 @@ package cn.iocoder.mall.product.dataobject; -import java.util.Date; +import cn.iocoder.common.framework.dataobject.BaseDO; /** * 商品分类 */ -public class ProductCategoryDO { +public class ProductCategoryDO extends BaseDO { public static final Integer STATUS_ENABLE = 1; @@ -35,19 +35,11 @@ public class ProductCategoryDO { * 排序值 */ private Integer sort; - /** - * 创建时间 - */ - private Date createTime; - /** - * 最后更新时间 - */ - private Date updateTime; /** * 状态 * - * 1-正常 - * 2-删除 + * 1-开启 + * 2-关闭 */ private Integer status; @@ -55,72 +47,62 @@ public class ProductCategoryDO { return id; } - public void setId(Integer id) { + public ProductCategoryDO setId(Integer id) { this.id = id; + return this; } public Integer getPid() { return pid; } - public void setPid(Integer pid) { + public ProductCategoryDO setPid(Integer pid) { this.pid = pid; + return this; } public String getName() { return name; } - public void setName(String name) { + public ProductCategoryDO setName(String name) { this.name = name; + return this; } public String getDescription() { return description; } - public void setDescription(String description) { + public ProductCategoryDO setDescription(String description) { this.description = description; + return this; } public String getPicUrl() { return picUrl; } - public void setPicUrl(String picUrl) { + public ProductCategoryDO setPicUrl(String picUrl) { this.picUrl = picUrl; + return this; } public Integer getSort() { return sort; } - public void setSort(Integer sort) { + public ProductCategoryDO setSort(Integer sort) { this.sort = sort; - } - - public Date getCreateTime() { - return createTime; - } - - public void setCreateTime(Date createTime) { - this.createTime = createTime; - } - - public Date getUpdateTime() { - return updateTime; - } - - public void setUpdateTime(Date updateTime) { - this.updateTime = updateTime; + return this; } public Integer getStatus() { return status; } - public void setStatus(Integer status) { + public ProductCategoryDO setStatus(Integer status) { this.status = status; + return this; } - } \ No newline at end of file diff --git a/product/product-service-impl/src/main/java/cn/iocoder/mall/product/service/ProductCategoryServiceImpl.java b/product/product-service-impl/src/main/java/cn/iocoder/mall/product/service/ProductCategoryServiceImpl.java index 8d6367d7a..1a0915e72 100644 --- a/product/product-service-impl/src/main/java/cn/iocoder/mall/product/service/ProductCategoryServiceImpl.java +++ b/product/product-service-impl/src/main/java/cn/iocoder/mall/product/service/ProductCategoryServiceImpl.java @@ -1,13 +1,21 @@ package cn.iocoder.mall.product.service; +import cn.iocoder.common.framework.dataobject.BaseDO; +import cn.iocoder.common.framework.util.ServiceExceptionUtil; +import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.product.api.ProductCategoryService; import cn.iocoder.mall.product.api.bo.ProductCategoryBO; +import cn.iocoder.mall.product.api.constant.ProductCategoryConstants; +import cn.iocoder.mall.product.api.constant.ProductErrorCodeEnum; +import cn.iocoder.mall.product.api.dto.ProductCategoryAddDTO; +import cn.iocoder.mall.product.api.dto.ProductCategoryUpdateDTO; import cn.iocoder.mall.product.convert.ProductCategoryConvert; import cn.iocoder.mall.product.dao.ProductCategoryMapper; import cn.iocoder.mall.product.dataobject.ProductCategoryDO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.Date; import java.util.List; @Service // 实际上不用添加。添加的原因是,必须 Spring 报错提示 @@ -23,4 +31,87 @@ public class ProductCategoryServiceImpl implements ProductCategoryService { return ProductCategoryConvert.INSTANCE.convertToBO(categoryList); } + @Override + public List getAll() { + List categoryList = productCategoryMapper.selectList(); + return ProductCategoryConvert.INSTANCE.convertToBO(categoryList); + } + + @Override + public CommonResult addProductCategory(Integer adminId, ProductCategoryAddDTO productCategoryAddDTO) { + // 校验父分类是否存在 + if (ProductCategoryConstants.PID_ROOT.equals(productCategoryAddDTO.getPid()) + && productCategoryMapper.selectById(productCategoryAddDTO.getPid()) == null) { + return ServiceExceptionUtil.error(ProductErrorCodeEnum.PRODUCT_CATEGORY_PARENT_NOT_EXISTS.getCode()); + } + // 保存到数据库 + ProductCategoryDO productCategory = ProductCategoryConvert.INSTANCE.convert(productCategoryAddDTO) + .setStatus(ProductCategoryConstants.STATUS_ENABLE); + productCategory.setCreateTime(new Date()).setDeleted(BaseDO.DELETED_NO); + productCategoryMapper.insert(productCategory); + // TODO 操作日志 + // 返回成功 + return CommonResult.success(ProductCategoryConvert.INSTANCE.convertToBO(productCategory)); + } + + @Override + public CommonResult updateProductCategory(Integer adminId, ProductCategoryUpdateDTO productCategoryUpdateDTO) { + // 校验分类是否存在 + if (productCategoryMapper.selectById(productCategoryUpdateDTO.getId()) == null) { + return ServiceExceptionUtil.error(ProductErrorCodeEnum.PRODUCT_CATEGORY_NOT_EXISTS.getCode()); + } + // 校验不能设置自己为父分类 + if (productCategoryUpdateDTO.getId().equals(productCategoryUpdateDTO.getPid())) { + return ServiceExceptionUtil.error(ProductErrorCodeEnum.PRODUCT_CATEGORY_PARENT_NOT_SELF.getCode()); + } + // 校验父分类是否存在 + if (ProductCategoryConstants.PID_ROOT.equals(productCategoryUpdateDTO.getPid()) + && productCategoryMapper.selectById(productCategoryUpdateDTO.getPid()) == null) { + return ServiceExceptionUtil.error(ProductErrorCodeEnum.PRODUCT_CATEGORY_PARENT_NOT_EXISTS.getCode()); + } + // 更新到数据库 + ProductCategoryDO updateProductCategory = ProductCategoryConvert.INSTANCE.convert(productCategoryUpdateDTO); + productCategoryMapper.update(updateProductCategory); + // TODO 操作日志 + return CommonResult.success(true); + } + + @Override + public CommonResult updateProductCategoryStatus(Integer adminId, Integer productCategoryId, Integer status) { + // 校验分类是否存在 + ProductCategoryDO productCategory = productCategoryMapper.selectById(productCategoryId); + if (productCategory == null) { + return ServiceExceptionUtil.error(ProductErrorCodeEnum.PRODUCT_CATEGORY_NOT_EXISTS.getCode()); + } + // 如果状态相同,则返回错误 + if (productCategory.getStatus().equals(status)) { + return ServiceExceptionUtil.error(ProductErrorCodeEnum.PRODUCT_CATEGORY_STATUS_EQUALS.getCode()); + } + // 更新商品分类 + ProductCategoryDO updateProductCategory = new ProductCategoryDO().setStatus(status); + productCategoryMapper.update(updateProductCategory); + // TODO 操作日志 + return CommonResult.success(true); + } + + @Override + public CommonResult deleteProductCategory(Integer admin, Integer productCategoryId) { + // 校验分类是否存在 + ProductCategoryDO productCategory = productCategoryMapper.selectById(productCategoryId); + if (productCategory == null) { + return ServiceExceptionUtil.error(ProductErrorCodeEnum.PRODUCT_CATEGORY_NOT_EXISTS.getCode()); + } + // 只有禁用的商品分类才可以删除 + if (ProductCategoryConstants.STATUS_ENABLE.equals(productCategory.getStatus())) { + return ServiceExceptionUtil.error(ProductErrorCodeEnum.PRODUCT_CATEGORY_DELETE_ONLY_DISABLE.getCode()); + } + // TODO 芋艿:考虑下,是否需要判断下该分类下是否有商品 + // 标记删除商品分类 + ProductCategoryDO updateProductCategory = new ProductCategoryDO(); + updateProductCategory.setDeleted(BaseDO.DELETED_YES); + productCategoryMapper.update(updateProductCategory); + // TODO 操作日志 + return CommonResult.success(true); + } + } \ No newline at end of file diff --git a/product/product-service-impl/src/main/resources/config/application.yaml b/product/product-service-impl/src/main/resources/config/application.yaml index 80f856a19..af5940f4b 100644 --- a/product/product-service-impl/src/main/resources/config/application.yaml +++ b/product/product-service-impl/src/main/resources/config/application.yaml @@ -1,10 +1,10 @@ spring: # datasource datasource: - url: jdbc:mysql://127.0.0.1:33061/mall_product?useSSL=false + url: jdbc:mysql://180.167.213.26:13306/mall_product?useSSL=false&useUnicode=true&characterEncoding=UTF-8 driver-class-name: com.mysql.jdbc.Driver username: root - password: 123456 + password: ${MALL_MYSQL_PASSWORD} # mybatis mybatis: diff --git a/product/product-service-impl/src/main/resources/mapper/ProductCategoryMapper.xml b/product/product-service-impl/src/main/resources/mapper/ProductCategoryMapper.xml index 52f26f49e..7f8023b5d 100644 --- a/product/product-service-impl/src/main/resources/mapper/ProductCategoryMapper.xml +++ b/product/product-service-impl/src/main/resources/mapper/ProductCategoryMapper.xml @@ -2,14 +2,72 @@ + + id, pid, name, descrption, pic_url, + sort, status, create_time + + + - + + + + INSERT INTO product_category ( + pid, name, description, pic_url, sort, + status, create_time, deleted + ) VALUES ( + #{pid}, #{name}, #{description}, #{picUrl}, #{sort}, + #{status}, #{createTime}, #{deleted} + ) + + + + UPDATE resource + + + pid = #{pid}, + + + name = #{name}, + + + description = #{description}, + + + pic_url = #{picUrl}, + + + sort = #{sort}, + + + status = #{status}, + + + deleted = #{deleted} + + + WHERE id = #{id} + + + \ No newline at end of file diff --git a/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/constant/UserErrorCodeEnum.java b/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/constant/UserErrorCodeEnum.java index 281852c69..7577a6436 100644 --- a/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/constant/UserErrorCodeEnum.java +++ b/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/constant/UserErrorCodeEnum.java @@ -3,7 +3,7 @@ package cn.iocoder.mall.user.service.api.constant; /** * 错误码枚举类 * - * 用户中心,使用 1-001-000-000 段 + * 用户系统,使用 1-001-000-000 段 */ public enum UserErrorCodeEnum {