diff --git a/common/common-framework/src/main/java/cn/iocoder/common/framework/validator/InEnumValidator.java b/common/common-framework/src/main/java/cn/iocoder/common/framework/validator/InEnumValidator.java index 7ddd5bc55..692b5fb73 100644 --- a/common/common-framework/src/main/java/cn/iocoder/common/framework/validator/InEnumValidator.java +++ b/common/common-framework/src/main/java/cn/iocoder/common/framework/validator/InEnumValidator.java @@ -25,6 +25,10 @@ public class InEnumValidator implements ConstraintValidator { @Override public boolean isValid(Integer value, ConstraintValidatorContext context) { + // 为空时,默认不校验,即认为通过 + if (value == null) { + return true; + } // 校验通过 if (values.contains(value)) { return true; diff --git a/common/common-framework/src/main/java/cn/iocoder/common/framework/validator/MobileValidator.java b/common/common-framework/src/main/java/cn/iocoder/common/framework/validator/MobileValidator.java index 8397cace0..326f6cc73 100644 --- a/common/common-framework/src/main/java/cn/iocoder/common/framework/validator/MobileValidator.java +++ b/common/common-framework/src/main/java/cn/iocoder/common/framework/validator/MobileValidator.java @@ -1,5 +1,6 @@ package cn.iocoder.common.framework.validator; +import cn.iocoder.common.framework.util.StringUtils; import cn.iocoder.common.framework.util.ValidationUtil; import javax.validation.ConstraintValidator; @@ -13,6 +14,11 @@ public class MobileValidator implements ConstraintValidator { @Override public boolean isValid(String value, ConstraintValidatorContext context) { + // 如果手机号为空,默认不校验,即校验通过 + if (!StringUtils.hasText(value)) { + return true; + } + // 校验手机 return ValidationUtil.isMobile(value); } diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/product/ProducctCategoryController.http b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/product/ProductCategoryController.http similarity index 100% rename from management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/product/ProducctCategoryController.http rename to management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/product/ProductCategoryController.http diff --git a/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/category/dto/ProductCategoryListQueryReqDTO.java b/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/category/dto/ProductCategoryListQueryReqDTO.java index 649ef3587..ed168e7d2 100644 --- a/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/category/dto/ProductCategoryListQueryReqDTO.java +++ b/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/category/dto/ProductCategoryListQueryReqDTO.java @@ -1,5 +1,7 @@ package cn.iocoder.mall.productservice.rpc.category.dto; +import cn.iocoder.common.framework.enums.CommonStatusEnum; +import cn.iocoder.common.framework.validator.InEnum; import lombok.Data; import lombok.experimental.Accessors; @@ -16,5 +18,10 @@ public class ProductCategoryListQueryReqDTO implements Serializable { * 父编号 */ private Integer pid; + /** + * 状态 + */ + @InEnum(value = CommonStatusEnum.class, message = "状态必须是 {value}") + private Integer status; } diff --git a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/convert/brand/ProductBrandConvert.java b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/convert/brand/ProductBrandConvert.java index c81dd9e3d..9c8a221f7 100644 --- a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/convert/brand/ProductBrandConvert.java +++ b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/convert/brand/ProductBrandConvert.java @@ -12,6 +12,7 @@ import cn.iocoder.mall.productservice.service.brand.bo.ProductBrandPageBO; import cn.iocoder.mall.productservice.service.brand.bo.ProductBrandUpdateBO; import com.baomidou.mybatisplus.core.metadata.IPage; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; import org.mapstruct.factory.Mappers; import java.util.List; @@ -29,6 +30,7 @@ public interface ProductBrandConvert { List convertList(List list); + @Mapping(source = "records", target = "list") PageResult convertPage(IPage page); ProductBrandCreateBO convert(ProductBrandCreateReqDTO bean); @@ -42,4 +44,5 @@ public interface ProductBrandConvert { ProductBrandPageBO convert(ProductBrandPageReqDTO bean); PageResult convertPage(PageResult page); + } diff --git a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/dal/mysql/mapper/category/ProductCategoryMapper.java b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/dal/mysql/mapper/category/ProductCategoryMapper.java index 5b4e4cd7d..8bede9aa2 100644 --- a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/dal/mysql/mapper/category/ProductCategoryMapper.java +++ b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/dal/mysql/mapper/category/ProductCategoryMapper.java @@ -17,7 +17,8 @@ public interface ProductCategoryMapper extends BaseMapper { } default List selectList(ProductCategoryListQueryBO listQueryBO) { - return selectList(new QueryWrapperX().eqIfPresent("pid", listQueryBO.getPid())); + return selectList(new QueryWrapperX().eqIfPresent("pid", listQueryBO.getPid()) + .eqIfPresent("status", listQueryBO.getStatus())); } } diff --git a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/service/category/bo/ProductCategoryListQueryBO.java b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/service/category/bo/ProductCategoryListQueryBO.java index c843eafaa..1c3ed7600 100644 --- a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/service/category/bo/ProductCategoryListQueryBO.java +++ b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/service/category/bo/ProductCategoryListQueryBO.java @@ -1,5 +1,7 @@ package cn.iocoder.mall.productservice.service.category.bo; +import cn.iocoder.common.framework.enums.CommonStatusEnum; +import cn.iocoder.common.framework.validator.InEnum; import lombok.Data; import lombok.experimental.Accessors; @@ -14,5 +16,10 @@ public class ProductCategoryListQueryBO { * 父编号 */ private Integer pid; + /** + * 状态 + */ + @InEnum(value = CommonStatusEnum.class, message = "状态必须是 {value}") + private Integer status; } diff --git a/product-service-project/product-service-app/src/main/resources/application.yaml b/product-service-project/product-service-app/src/main/resources/application.yaml index 98e91e118..1216dffa9 100644 --- a/product-service-project/product-service-app/src/main/resources/application.yaml +++ b/product-service-project/product-service-app/src/main/resources/application.yaml @@ -37,7 +37,7 @@ dubbo: ProductCategoryRpc: version: 1.0.0 ProductBrandRpc: - verion: 1.0.0 + version: 1.0.0 # Dubbo 服务消费者的配置 consumer: ErrorCodeRpc: diff --git a/user-web-app/pom.xml b/user-web-app/pom.xml index 176c28e97..d9acaa42a 100644 --- a/user-web-app/pom.xml +++ b/user-web-app/pom.xml @@ -53,6 +53,12 @@ user-service-api 1.0-SNAPSHOT + + + cn.iocoder.mall + product-service-api + 1.0-SNAPSHOT + cn.iocoder.mall diff --git a/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/product/ProductCategoryController.http b/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/product/ProductCategoryController.http new file mode 100644 index 000000000..efdc57c9b --- /dev/null +++ b/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/product/ProductCategoryController.http @@ -0,0 +1,4 @@ +### /user-address/get-default 成功 +GET {{user-api-base-url}}/product-category/list?pid=0 + +### diff --git a/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/product/ProductCategoryController.java b/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/product/ProductCategoryController.java new file mode 100644 index 000000000..25e79d7ec --- /dev/null +++ b/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/product/ProductCategoryController.java @@ -0,0 +1,40 @@ +package cn.iocoder.mall.userweb.controller.product; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.userweb.controller.product.vo.category.ProductCategoryRespVO; +import cn.iocoder.mall.userweb.manager.product.ProductCategoryManager; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +import static cn.iocoder.common.framework.vo.CommonResult.success; + +/** +* 商品分类 Controller +*/ +@RestController +@RequestMapping("/product-category") +@Api(tags = "商品分类") +@Validated +// TODO 芋艿:稍后迁移到 shop-web-app 服务下 +public class ProductCategoryController { + + @Autowired + private ProductCategoryManager productCategoryManager; + + @GetMapping("/list") + @ApiOperation("获得商品分类的列表") + @ApiImplicitParam(name = "pid", value = "父分类编号", required = true, example = "1024") + public CommonResult> listProductCategories(@RequestParam("pid") Integer pid) { + return success(productCategoryManager.listProductCategories(pid)); + } + +} diff --git a/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/product/vo/category/ProductCategoryRespVO.java b/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/product/vo/category/ProductCategoryRespVO.java new file mode 100644 index 000000000..b059eb773 --- /dev/null +++ b/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/product/vo/category/ProductCategoryRespVO.java @@ -0,0 +1,18 @@ +package cn.iocoder.mall.userweb.controller.product.vo.category; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@ApiModel("商品分类 Response VO") +@Data +public class ProductCategoryRespVO { + + @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/xx.jpg") + private String picUrl; + +} diff --git a/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/product/vo/package-info.java b/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/product/vo/package-info.java new file mode 100644 index 000000000..f2877ca69 --- /dev/null +++ b/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/product/vo/package-info.java @@ -0,0 +1 @@ +package cn.iocoder.mall.userweb.controller.product.vo; diff --git a/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/user/UserController.java b/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/user/UserController.java index 892f860a7..a08cbaa51 100644 --- a/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/user/UserController.java +++ b/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/user/UserController.java @@ -6,11 +6,10 @@ import cn.iocoder.mall.userweb.controller.user.vo.UserRespVO; import cn.iocoder.mall.userweb.manager.user.UserManager; import cn.iocoder.security.annotations.RequiresAuthenticate; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import static cn.iocoder.common.framework.vo.CommonResult.success; @@ -25,31 +24,27 @@ public class UserController { @ApiOperation(value = "用户信息") @GetMapping("/info") @RequiresAuthenticate - public CommonResult info() { + public CommonResult getUserInfo() { UserRespVO user = userManager.getUser(UserSecurityContextHolder.getUserId()); return success(user); } -// @PostMapping("/update_avatar") -// @RequiresLogin -// @ApiOperation(value = "更新头像") -// public CommonResult updateAvatar(@RequestParam("avatar") String avatar) { -// // 创建 -// UserUpdateDTO userUpdateDTO = new UserUpdateDTO().setId(UserSecurityContextHolder.getContext().getUserId()) -// .setAvatar(avatar); -// // 更新头像 -// return success(userService.updateUser(userUpdateDTO)); -// } + @PostMapping("/update-avatar") + @RequiresAuthenticate + @ApiOperation(value = "更新头像") + @ApiImplicitParam(name = "avatar", value = "头像", required = true, example = "http://www.iocoder.cn/xxx.png") + public CommonResult updateUserAvatar(@RequestParam("avatar") String avatar) { + userManager.updateUserAvatar(UserSecurityContextHolder.getUserId(), avatar); + return success(true); + } -// @PostMapping("/update_nickname") -// @RequiresLogin -// @ApiOperation(value = "更新昵称") -// public CommonResult updateNickname(@RequestParam("nickname") String nickname) { -// // 创建 -// UserUpdateDTO userUpdateDTO = new UserUpdateDTO().setId(UserSecurityContextHolder.getContext().getUserId()) -// .setNickname(nickname); -// // 更新头像 -// return success(userService.updateUser(userUpdateDTO)); -// } + @PostMapping("/update-nickname") + @RequiresAuthenticate + @ApiOperation(value = "更新昵称") + @ApiImplicitParam(name = "nickname", value = "昵称", required = true, example = "蠢艿艿") + public CommonResult updateUserNickname(@RequestParam("nickname") String nickname) { + userManager.updateUserNickname(UserSecurityContextHolder.getUserId(), nickname); + return success(true); + } } diff --git a/user-web-app/src/main/java/cn/iocoder/mall/userweb/convert/product/ProductCategoryConvert.java b/user-web-app/src/main/java/cn/iocoder/mall/userweb/convert/product/ProductCategoryConvert.java new file mode 100644 index 000000000..21ca625dd --- /dev/null +++ b/user-web-app/src/main/java/cn/iocoder/mall/userweb/convert/product/ProductCategoryConvert.java @@ -0,0 +1,17 @@ +package cn.iocoder.mall.userweb.convert.product; + +import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryRespDTO; +import cn.iocoder.mall.userweb.controller.product.vo.category.ProductCategoryRespVO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +@Mapper +public interface ProductCategoryConvert { + + ProductCategoryConvert INSTANCE = Mappers.getMapper(ProductCategoryConvert.class); + + List convertList(List list); + +} diff --git a/user-web-app/src/main/java/cn/iocoder/mall/userweb/manager/product/ProductCategoryManager.java b/user-web-app/src/main/java/cn/iocoder/mall/userweb/manager/product/ProductCategoryManager.java new file mode 100644 index 000000000..801f591bc --- /dev/null +++ b/user-web-app/src/main/java/cn/iocoder/mall/userweb/manager/product/ProductCategoryManager.java @@ -0,0 +1,33 @@ +package cn.iocoder.mall.userweb.manager.product; + +import cn.iocoder.common.framework.enums.CommonStatusEnum; +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.productservice.rpc.category.ProductCategoryRpc; +import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryListQueryReqDTO; +import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryRespDTO; +import cn.iocoder.mall.userweb.controller.product.vo.category.ProductCategoryRespVO; +import cn.iocoder.mall.userweb.convert.product.ProductCategoryConvert; +import org.apache.dubbo.config.annotation.Reference; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import java.util.List; + +/** + * Product 分类 Manager + */ +@Service +@Validated +public class ProductCategoryManager { + + @Reference(version = "${dubbo.consumer.ProductCategoryRpc.version}") + private ProductCategoryRpc productCategoryRpc; + + public List listProductCategories(Integer pid) { + CommonResult> listProductCategoriesResult = productCategoryRpc.listProductCategories( + new ProductCategoryListQueryReqDTO().setPid(pid).setStatus(CommonStatusEnum.ENABLE.getValue())); + listProductCategoriesResult.checkError(); + return ProductCategoryConvert.INSTANCE.convertList(listProductCategoriesResult.getData()); + } + +} diff --git a/user-web-app/src/main/java/cn/iocoder/mall/userweb/manager/user/UserManager.java b/user-web-app/src/main/java/cn/iocoder/mall/userweb/manager/user/UserManager.java index b28df9638..c0dbed600 100644 --- a/user-web-app/src/main/java/cn/iocoder/mall/userweb/manager/user/UserManager.java +++ b/user-web-app/src/main/java/cn/iocoder/mall/userweb/manager/user/UserManager.java @@ -3,6 +3,7 @@ package cn.iocoder.mall.userweb.manager.user; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.userservice.rpc.user.UserRpc; import cn.iocoder.mall.userservice.rpc.user.dto.UserRespDTO; +import cn.iocoder.mall.userservice.rpc.user.dto.UserUpdateReqDTO; import cn.iocoder.mall.userweb.controller.user.vo.UserRespVO; import cn.iocoder.mall.userweb.convert.user.UserConvert; import org.apache.dubbo.config.annotation.DubboReference; @@ -20,4 +21,14 @@ public class UserManager { return UserConvert.INSTANCE.convert(userResult.getData()); } + public void updateUserAvatar(Integer userId, String avatar) { + CommonResult updateUserResult = userRpc.updateUser(new UserUpdateReqDTO().setId(userId).setAvatar(avatar)); + updateUserResult.checkError(); + } + + public void updateUserNickname(Integer userId, String nickname) { + CommonResult updateUserResult = userRpc.updateUser(new UserUpdateReqDTO().setId(userId).setNickname(nickname)); + updateUserResult.checkError(); + } + } diff --git a/user-web-app/src/main/resources/application.yml b/user-web-app/src/main/resources/application.yml index aba33d1f5..d47e5b3f5 100644 --- a/user-web-app/src/main/resources/application.yml +++ b/user-web-app/src/main/resources/application.yml @@ -37,6 +37,8 @@ dubbo: version: 1.0.0 UserAddressRpc: version: 1.0.0 + ProductCategoryRpc: + version: 1.0.0 # Swagger 配置项 swagger: