创建新 user 服务项目

This commit is contained in:
YunaiV
2020-04-20 22:58:12 +08:00
parent bdff67b7b3
commit cc9696938a
39 changed files with 595 additions and 362 deletions

View File

@@ -2,13 +2,22 @@ package cn.iocoder.mall.user.application;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.boot.context.config.ConfigFileApplicationListener;
@SpringBootApplication(scanBasePackages = {"cn.iocoder.mall.user"})
@EnableAsync(proxyTargetClass = true)
@SpringBootApplication(scanBasePackages = {"cn.iocoder.mall.system"})
public class UserApplication {
/**
* 设置需要读取的配置文件的名字。
* 基于 {@link org.springframework.boot.context.config.ConfigFileApplicationListener#CONFIG_NAME_PROPERTY} 实现。
*/
private static final String CONFIG_NAME_VALUE = "biz,rest,rpc,application";
public static void main(String[] args) {
// 设置环境变量
System.setProperty(ConfigFileApplicationListener.CONFIG_NAME_PROPERTY, CONFIG_NAME_VALUE);
// 启动 Spring Boot 应用
SpringApplication.run(UserApplication.class, args);
}

View File

@@ -1,73 +0,0 @@
package cn.iocoder.mall.user.application.controller.admins;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.user.api.UserService;
import cn.iocoder.mall.user.api.bo.UserPageBO;
import cn.iocoder.mall.user.api.dto.UserPageDTO;
import cn.iocoder.mall.user.api.dto.UserUpdateDTO;
import cn.iocoder.mall.user.application.convert.UserConvert;
import cn.iocoder.mall.user.application.vo.admins.AdminsUserPageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;
import static cn.iocoder.common.framework.vo.CommonResult.success;
@RestController
@RequestMapping("/admins/user")
@Api("用户模块")
public class AdminsUserController {
@Reference(validation = "true", version = "${dubbo.provider.UserService.version}")
private UserService userService;
// 分页
@GetMapping("/page")
@ApiOperation(value = "用户分页")
@ApiImplicitParams({
@ApiImplicitParam(name = "nickname", value = "昵称,模糊匹配", example = "小王"),
@ApiImplicitParam(name = "pageNo", value = "页码,从 1 开始", example = "1"),
@ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, example = "10"),
})
public CommonResult<AdminsUserPageVO> page(@RequestParam(value = "nickname", required = false) String nickname,
@RequestParam(value = "status", required = false) Integer status,
@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
UserPageDTO userPageDTO = new UserPageDTO().setNickname(nickname).setStatus(status)
.setPageNo(pageNo).setPageSize(pageSize);
// 查询分页
UserPageBO result = userService.getUserPage(userPageDTO);
// 转换结果
return success(UserConvert.INSTANCE.convert(result));
}
@PostMapping("/update")
@ApiOperation(value = "更新用户基本信息")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "用户编号", required = true, example = "1"),
@ApiImplicitParam(name = "nickname", value = "昵称", required = true, example = "小王"),
@ApiImplicitParam(name = "avatar", value = "头像", required = true, example = "http://www.iocoder.cn/xxx.jpg"),
})
public CommonResult<Boolean> update(@RequestParam("id") Integer id,
@RequestParam("nickname") String nickname,
@RequestParam("avatar") String avatar) {
UserUpdateDTO userUpdateDTO = new UserUpdateDTO().setId(id).setNickname(nickname).setNickname(nickname).setAvatar(avatar);
// 更新
return success(userService.updateUser(userUpdateDTO));
}
@PostMapping("/update_status")
@ApiOperation(value = "更新用户状态")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "用户编号", required = true, example = "1"),
@ApiImplicitParam(name = "status", value = "状态。1 - 开启2 - 禁用", required = true, example = "1"),
})
public CommonResult<Boolean> updateStatus(@RequestParam("id") Integer id,
@RequestParam("status") Integer status) {
return success(userService.updateUserStatus(id, status));
}
}

View File

@@ -1,56 +0,0 @@
package cn.iocoder.mall.user.application.controller.users;
import cn.iocoder.common.framework.constant.UserTypeEnum;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.system.api.OAuth2Service;
import cn.iocoder.mall.system.api.bo.oauth2.OAuth2AccessTokenBO;
import cn.iocoder.mall.system.api.dto.oauth2.OAuth2RefreshTokenDTO;
import cn.iocoder.mall.user.api.UserService;
import io.swagger.annotations.Api;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import static cn.iocoder.common.framework.vo.CommonResult.success;
@RestController
@RequestMapping("users/passport")
@Api("Passport 模块")
public class PassportController {
@Reference(validation = "true", version = "${dubbo.consumer.OAuth2Service.version}")
private OAuth2Service oauth2Service;
@Reference(validation = "true", version = "${dubbo.provider.UserService.version}")
private UserService userService;
// TODO 功能:手机密码登陆
// @PostMapping("/mobile/pwd/login")
// public OAuth2AccessToken mobileLogin(@RequestParam("mobile") String mobile,
// @RequestParam("password") String password) {
// return oauth2Service.getAccessToken(clientId, clientSecret, mobile, password);
// }
// TODO 芋艿,改绑手机号
// TODO 功能qq 登陆
@PostMapping("/qq/login")
public String qqLogin() {
return null;
}
// TODO 功能qq 绑定
@PostMapping("/qq/bind")
public String qqBind() {
return null;
}
@PostMapping("/refresh_token") // TODO 功能:刷新 token
public CommonResult<OAuth2AccessTokenBO> refreshToken(@RequestParam("refreshToken") String refreshToken) {
return success(oauth2Service.refreshToken(new OAuth2RefreshTokenDTO().setRefreshToken(refreshToken)
.setUserType(UserTypeEnum.USER.getValue())));
}
// TODO 功能:退出,销毁 token
}

View File

@@ -1,79 +0,0 @@
package cn.iocoder.mall.user.application.controller.users;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.user.api.UserAddressService;
import cn.iocoder.mall.user.api.bo.UserAddressBO;
import cn.iocoder.mall.user.api.dto.UserAddressAddDTO;
import cn.iocoder.mall.user.api.dto.UserAddressUpdateDTO;
import cn.iocoder.mall.user.application.convert.UserAddressConvert;
import cn.iocoder.mall.user.application.po.UserAddressAddPO;
import cn.iocoder.mall.user.application.po.UserAddressUpdatePO;
import cn.iocoder.mall.user.sdk.context.UserSecurityContextHolder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 用户地址
*
* @author Sin
* @time 2019-04-06 14:11
*/
@RestController
@RequestMapping("users/address")
@Api(value = "用户地址API")
public class UserAddressController {
@Reference(validation = "true", version = "${dubbo.provider.UserAddressService.version}")
private UserAddressService userAddressService;
@PostMapping("add")
@ApiOperation(value = "用户地址-添加")
public CommonResult addAddress(@Validated UserAddressAddPO userAddressAddPO) {
Integer userId = UserSecurityContextHolder.getContext().getUserId();
UserAddressAddDTO userAddressAddDTO = UserAddressConvert.INSTANCE.convert(userAddressAddPO);
userAddressAddDTO.setUserId(userId);
return userAddressService.addAddress(userAddressAddDTO);
}
@PutMapping("update")
@ApiOperation(value = "用户地址-更新")
public CommonResult updateAddress(@Validated UserAddressUpdatePO userAddressUpdatePO) {
Integer userId = UserSecurityContextHolder.getContext().getUserId();
UserAddressUpdateDTO userAddressUpdateDTO = UserAddressConvert.INSTANCE.convert(userAddressUpdatePO);
userAddressUpdateDTO.setUserId(userId);
return userAddressService.updateAddress(userAddressUpdateDTO);
}
@DeleteMapping("remove")
@ApiOperation(value = "用户地址-删除")
public CommonResult removeAddress(@RequestParam("id") Integer id) {
Integer userId = UserSecurityContextHolder.getContext().getUserId();
return userAddressService.removeAddress(userId, id);
}
@GetMapping("list")
@ApiOperation(value = "用户地址列表")
public CommonResult<List<UserAddressBO>> addressList() {
Integer userId = UserSecurityContextHolder.getContext().getUserId();
return userAddressService.addressList(userId);
}
@GetMapping("address")
@ApiOperation(value = "获取地址")
public CommonResult<UserAddressBO> getAddress(@RequestParam("id") Integer id) {
Integer userId = UserSecurityContextHolder.getContext().getUserId();
return userAddressService.getAddress(userId, id);
}
@GetMapping("default_address")
@ApiOperation(value = "获取默认地址")
public CommonResult<UserAddressBO> getDefaultAddress() {
Integer userId = UserSecurityContextHolder.getContext().getUserId();
return userAddressService.getDefaultAddress(userId);
}
}

View File

@@ -1,56 +0,0 @@
package cn.iocoder.mall.user.application.controller.users;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.user.api.UserService;
import cn.iocoder.mall.user.api.bo.UserBO;
import cn.iocoder.mall.user.api.dto.UserUpdateDTO;
import cn.iocoder.mall.user.application.convert.UserConvert;
import cn.iocoder.mall.user.application.vo.users.UsersUserVO;
import cn.iocoder.mall.user.sdk.annotation.RequiresLogin;
import cn.iocoder.mall.user.sdk.context.UserSecurityContextHolder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;
import static cn.iocoder.common.framework.vo.CommonResult.success;
@RestController
@RequestMapping("/users/user")
@Api("用户模块")
public class UserController {
@Reference(validation = "true", version = "${dubbo.provider.UserService.version}")
private UserService userService;
@GetMapping("/info")
@RequiresLogin
@ApiOperation(value = "用户信息")
public CommonResult<UsersUserVO> info() {
UserBO userResult = userService.getUser(UserSecurityContextHolder.getContext().getUserId());
return success(UserConvert.INSTANCE.convert2(userResult));
}
@PostMapping("/update_avatar")
@RequiresLogin
@ApiOperation(value = "更新头像")
public CommonResult<Boolean> updateAvatar(@RequestParam("avatar") String avatar) {
// 创建
UserUpdateDTO userUpdateDTO = new UserUpdateDTO().setId(UserSecurityContextHolder.getContext().getUserId())
.setAvatar(avatar);
// 更新头像
return success(userService.updateUser(userUpdateDTO));
}
@PostMapping("/update_nickname")
@RequiresLogin
@ApiOperation(value = "更新昵称")
public CommonResult<Boolean> updateNickname(@RequestParam("nickname") String nickname) {
// 创建
UserUpdateDTO userUpdateDTO = new UserUpdateDTO().setId(UserSecurityContextHolder.getContext().getUserId())
.setNickname(nickname);
// 更新头像
return success(userService.updateUser(userUpdateDTO));
}
}

View File

@@ -1,25 +0,0 @@
package cn.iocoder.mall.user.application.convert;
import cn.iocoder.mall.user.application.po.UserAddressAddPO;
import cn.iocoder.mall.user.application.po.UserAddressUpdatePO;
import cn.iocoder.mall.user.api.dto.UserAddressAddDTO;
import cn.iocoder.mall.user.api.dto.UserAddressUpdateDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
/**
* @author Sin
* @time 2019-04-06 14:19
*/
@Mapper
public interface UserAddressConvert {
UserAddressConvert INSTANCE = Mappers.getMapper(UserAddressConvert.class);
@Mappings({})
UserAddressAddDTO convert(UserAddressAddPO userAddressAddPO);
@Mappings({})
UserAddressUpdateDTO convert(UserAddressUpdatePO userAddressUpdatePO);
}

View File

@@ -1,22 +0,0 @@
package cn.iocoder.mall.user.application.convert;
import cn.iocoder.mall.user.api.bo.UserBO;
import cn.iocoder.mall.user.api.bo.UserPageBO;
import cn.iocoder.mall.user.application.vo.admins.AdminsUserPageVO;
import cn.iocoder.mall.user.application.vo.users.UsersUserVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
@Mapper
public interface UserConvert {
UserConvert INSTANCE = Mappers.getMapper(UserConvert.class);
@Mappings({})
AdminsUserPageVO convert(UserPageBO result);
@Mappings({})
UsersUserVO convert2(UserBO result);
}

View File

@@ -1,59 +0,0 @@
package cn.iocoder.mall.user.application.po;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
/**
* 用户地址 add
*
* @author Sin
* @time 2019-04-06 14:13
*/
@ApiModel("用户地址")
@Data
@Accessors(chain = true)
public class UserAddressAddPO implements Serializable {
/**
* 收件区域编号
*/
@ApiModelProperty("区域编号")
@NotNull(message = "区域编号不能为空!")
private String areaNo;
/**
* 收件人名称
*/
@ApiModelProperty("收件人名称")
@NotNull(message = "请填写收人信息!")
private String name;
/**
* 收件手机号
*/
@ApiModelProperty("收件手机号")
@NotNull(message = "手机号为不能为空!")
@Size(min = 11, max = 11, message = "手机号为 11 位!")
private String mobile;
/**
* 收件详细地址
*/
@ApiModelProperty("收件详细地址")
@NotEmpty(message = "详细地址不能为空")
@Length(min = 10, max = 100, message = "地址在 10 ~ 100 字之间!")
private String address;
/**
* 收件详细地址
*/
@ApiModelProperty("默认地址")
@NotNull(message = "默认地址不能为空")
private Integer hasDefault;
}

View File

@@ -1,61 +0,0 @@
package cn.iocoder.mall.user.application.po;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
/**
* 用户地址 add
*
* @author Sin
* @time 2019-04-06 14:13
*/
@ApiModel("用户地址-更新")
@Data
@Accessors(chain = true)
public class UserAddressUpdatePO implements Serializable {
/**
* 收件区域编号
*/
@ApiModelProperty("地址编号")
@NotNull(message = "地址编号为空!")
private Integer id;
/**
* 收件区域编号
*/
@ApiModelProperty("区域编号")
@NotNull(message = "区域编号不能为空!")
private String areaNo;
/**
* 收件人名称
*/
@ApiModelProperty("收件人名称")
@NotNull(message = "请填写收人信息!")
private String name;
/**
* 收件手机号
*/
@ApiModelProperty("收件手机号")
@NotNull(message = "手机号为不能为空!")
@Size(min = 11, max = 11, message = "手机号为 11 位!")
private String mobile;
/**
* 收件详细地址
*/
@ApiModelProperty("收件详细地址")
@NotNull(message = "详细地址不能为空")
@Size(min = 10, max = 100, message = "地址在 10 ~ 100 字之间!")
private String address;
/**
* 是否设置默认
*/
@ApiModelProperty("是否设置默认")
@NotNull(message = "是否设置默认不能为空")
private Integer hasDefault;
}

View File

@@ -1,20 +0,0 @@
package cn.iocoder.mall.user.application.vo.admins;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.List;
@ApiModel("用户分页 VO")
@Data
@Accessors(chain = true)
public class AdminsUserPageVO {
@ApiModelProperty(value = "用户数组")
private List<AdminsUserVO> list;
@ApiModelProperty(value = "用户总数")
private Integer total;
}

View File

@@ -1,28 +0,0 @@
package cn.iocoder.mall.user.application.vo.admins;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
@ApiModel("用户 VO")
@Data
@Accessors(chain = true)
public class AdminsUserVO {
@ApiModelProperty(value = "用户编号", required = true, example = "1")
private Integer id;
@ApiModelProperty(value = "手机号", required = true, example = "15601691300")
private String mobile;
@ApiModelProperty(value = "昵称", required = true, example = "小王")
private String nickname;
@ApiModelProperty(value = "头像", required = true, example = "http://www.iocoder.cn/xxx.jpg")
private String avatar;
@ApiModelProperty(value = "账号状态", required = true, example = "1")
private Integer status;
@ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式")
private Date createTime;
}

View File

@@ -1,20 +0,0 @@
package cn.iocoder.mall.user.application.vo.users;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
@ApiModel("认证令牌 VO")
@Data
@Accessors(chain = true)
public class UsersAccessTokenVO {
@ApiModelProperty(value = "访问令牌", required = true, example = "2e3d7635c15e47e997611707a237859f")
private String accessToken;
@ApiModelProperty(value = "刷新令牌", required = true, example = "d091e7c35bbb4313b0f557a6ef23d033")
private String refreshToken;
@ApiModelProperty(value = "过期时间,单位:秒", required = true, example = "2879")
private Integer expiresIn;
}

View File

@@ -1,20 +0,0 @@
package cn.iocoder.mall.user.application.vo.users;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
@ApiModel("手机注册结果 VO")
@Data
@Accessors(chain = true)
public class UsersMobileRegisterVO {
@ApiModelProperty(value = "访问令牌", required = true, example = "2e3d7635c15e47e997611707a237859f")
private String accessToken;
@ApiModelProperty(value = "刷新令牌", required = true, example = "d091e7c35bbb4313b0f557a6ef23d033")
private String refreshToken;
@ApiModelProperty(value = "过期时间,单位:秒", required = true, example = "2879")
private Integer expiresIn;
}

View File

@@ -1,22 +0,0 @@
package cn.iocoder.mall.user.application.vo.users;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
@ApiModel("用户信息 VO")
@Data
@Accessors(chain = true)
public class UsersUserVO {
@ApiModelProperty(value = "用户编号", required = true, example = "123")
private Integer id;
@ApiModelProperty(value = "手机号", required = true, example = "15601691300")
private String mobile;
@ApiModelProperty(value = "昵称", required = true, example = "小王")
private String nickname;
@ApiModelProperty(value = "头像", required = true, example = "http://www.iocoder.cn/xxx.jpg")
private String avatar;
}

View File

@@ -1,6 +0,0 @@
swagger:
enable: true
title: 用户子系统
description: 用户子系统
version: 1.0.0
base-package: cn.iocoder.mall.user.application.controller

View File

@@ -1,32 +1,8 @@
spring:
# Application 的配置项
application:
name: user-application
# Profile 的配置项
profiles:
active: local
# Spring Cloud 配置项
cloud:
# Spring Cloud Sentinel 配置项
sentinel:
transport:
dashboard: s1.iocoder.cn:12088 # Sentinel Dashboard 服务地址
eager: true # 项目启动时,直接连接到 Sentinel
# server
server:
port: 18082
servlet:
context-path: /user-api/
swagger:
enable: true # 暂时不去掉
title: 用户子系统
description: 用户子系统
version: 1.0.0
base-package: cn.iocoder.mall.user.application.controller
management:
endpoints:
web:
exposure:
include: health,info,env,metrics,prometheus
metrics:
enabled: true