From cf7cedbd06268d64cc137f0be3ce3976bb7e3aec Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Sun, 5 Jul 2020 23:05:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=85=A5=20IDEA=20REST=20Client=20?= =?UTF-8?q?=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/admin/AdminController.http | 0 .../passport/AdminPassportController.http | 13 +++++ .../src/main/resources/http-client.env.json | 6 +++ .../biz/dto/account/AccountCreateDTO.java | 34 ------------ .../system/biz/dto/admin/AdminPageDTO.java | 26 --------- .../mall/system/rpc/api/admin/AdminRPC.java | 15 ------ .../mall/system/rpc/api/oauth2/OAuth2RPC.java | 14 ----- .../OAuth2AccessTokenAuthenticateRequest.java | 21 -------- .../rpc/response/admin/AdminResponse.java | 20 ------- .../oauth2/OAuth2AccessTokenResponse.java | 33 ------------ .../system/rpc/rpc/admin/AdminRPCImpl.java | 30 ----------- .../mall/system/api/OAuth2Service.java | 17 ------ .../mall/admin/convert/OAuth2Convert.java | 30 ----------- .../mall/admin/service/AdminServiceImpl.java | 48 ----------------- .../mall/admin/service/OAuth2ServiceImpl.java | 54 ------------------- .../application/convert/PassportConvert.java | 21 -------- 16 files changed, 19 insertions(+), 363 deletions(-) create mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/admin/AdminController.http create mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/AdminPassportController.http create mode 100644 management-web-app/src/main/resources/http-client.env.json delete mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/account/AccountCreateDTO.java delete mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/admin/AdminPageDTO.java delete mode 100644 system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/api/admin/AdminRPC.java delete mode 100644 system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/api/oauth2/OAuth2RPC.java delete mode 100644 system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/request/oauth2/OAuth2AccessTokenAuthenticateRequest.java delete mode 100644 system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/response/admin/AdminResponse.java delete mode 100644 system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/response/oauth2/OAuth2AccessTokenResponse.java delete mode 100644 system/system-rpc/src/main/java/cn/iocoder/mall/system/rpc/rpc/admin/AdminRPCImpl.java delete mode 100644 system/system-service-api/src/main/java/cn/iocoder/mall/system/api/OAuth2Service.java delete mode 100644 system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/OAuth2Convert.java delete mode 100644 system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/AdminServiceImpl.java delete mode 100644 system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/OAuth2ServiceImpl.java delete mode 100644 system/system-start/src/main/java/cn/iocoder/mall/system/application/convert/PassportConvert.java diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/admin/AdminController.http b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/admin/AdminController.http new file mode 100644 index 000000000..e69de29bb diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/AdminPassportController.http b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/AdminPassportController.http new file mode 100644 index 000000000..dd15e0e1b --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/AdminPassportController.http @@ -0,0 +1,13 @@ +### /passport/login 成功 +POST {{baseUrl}}/passport/login +Content-Type: application/x-www-form-urlencoded + +username=admin&password=buzhidao + +### /passport/login 密码不正确 +POST {{baseUrl}}/passport/login +Content-Type: application/x-www-form-urlencoded + +username=admin&password=1024 + +### diff --git a/management-web-app/src/main/resources/http-client.env.json b/management-web-app/src/main/resources/http-client.env.json new file mode 100644 index 000000000..5c4488e18 --- /dev/null +++ b/management-web-app/src/main/resources/http-client.env.json @@ -0,0 +1,6 @@ +{ + "local": { + "baseUrl": "http://127.0.0.1:18083/management-api/", + "accessToken": "yudaoyuanma" + } +} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/account/AccountCreateDTO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/account/AccountCreateDTO.java deleted file mode 100644 index d54c20773..000000000 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/account/AccountCreateDTO.java +++ /dev/null @@ -1,34 +0,0 @@ -package cn.iocoder.mall.system.biz.dto.account; - -import lombok.Data; -import lombok.experimental.Accessors; - -// TODO 注释 -@Data -@Accessors(chain = true) -public class AccountCreateDTO { - - /** - * 登陆账号 - */ - private String username; - /** - * 手机号 - */ - private String mobile; - /** - * 邮箱 - */ - private String email; - /** - * 密码 - * - * // TODO 芋艿 暂时明文 - */ - private String password; - /** - * 创建 IP - */ - private String createIp; - -} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/admin/AdminPageDTO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/admin/AdminPageDTO.java deleted file mode 100644 index 24d6fdb2f..000000000 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/admin/AdminPageDTO.java +++ /dev/null @@ -1,26 +0,0 @@ -package cn.iocoder.mall.system.biz.dto.admin; - -import cn.iocoder.common.framework.vo.PageParam; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.experimental.Accessors; - -/** - * 管理员模块 - 管理员分页 DTO - */ -@Data -@Accessors(chain = true) -@EqualsAndHashCode(callSuper = true) -public class AdminPageDTO extends PageParam { - - /** - * 真实名字,模糊匹配 - */ - private String name; - - /** - * 部门编号 - */ - private Integer departmentId; - -} diff --git a/system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/api/admin/AdminRPC.java b/system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/api/admin/AdminRPC.java deleted file mode 100644 index 741662843..000000000 --- a/system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/api/admin/AdminRPC.java +++ /dev/null @@ -1,15 +0,0 @@ -package cn.iocoder.mall.system.rpc.api.admin; - -import cn.iocoder.common.framework.vo.CommonResult; -import cn.iocoder.mall.system.rpc.response.admin.AdminResponse; - -/** - * Admin RPC 接口 - */ -public interface AdminRPC { - - CommonResult getAdmin(Integer id); - - CommonResult getAdminByAccountId(Integer accountId); - -} diff --git a/system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/api/oauth2/OAuth2RPC.java b/system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/api/oauth2/OAuth2RPC.java deleted file mode 100644 index b6260358e..000000000 --- a/system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/api/oauth2/OAuth2RPC.java +++ /dev/null @@ -1,14 +0,0 @@ -package cn.iocoder.mall.system.rpc.api.oauth2; - -import cn.iocoder.common.framework.vo.CommonResult; -import cn.iocoder.mall.system.rpc.request.oauth2.OAuth2AccessTokenAuthenticateRequest; -import cn.iocoder.mall.system.rpc.response.oauth2.OAuth2AccessTokenResponse; - -/** - * OAuth2 RPC 接口 - */ -public interface OAuth2RPC { - - CommonResult authenticate(OAuth2AccessTokenAuthenticateRequest request); - -} diff --git a/system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/request/oauth2/OAuth2AccessTokenAuthenticateRequest.java b/system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/request/oauth2/OAuth2AccessTokenAuthenticateRequest.java deleted file mode 100644 index 81fccf98c..000000000 --- a/system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/request/oauth2/OAuth2AccessTokenAuthenticateRequest.java +++ /dev/null @@ -1,21 +0,0 @@ -package cn.iocoder.mall.system.rpc.request.oauth2; - -import lombok.Data; -import lombok.experimental.Accessors; - -import javax.validation.constraints.NotNull; -import java.io.Serializable; - -/** - * OAuth2 模块 - 访问令牌认证 Request - */ -@Data -@Accessors(chain = true) -public class OAuth2AccessTokenAuthenticateRequest implements Serializable { - - @NotNull(message = "访问令牌不能为空") - private String accessToken; - @NotNull(message = "IP 不能为空") - private String ip; - -} diff --git a/system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/response/admin/AdminResponse.java b/system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/response/admin/AdminResponse.java deleted file mode 100644 index 8de29ee01..000000000 --- a/system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/response/admin/AdminResponse.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.mall.system.rpc.response.admin; - -import lombok.Data; -import lombok.experimental.Accessors; - -import java.io.Serializable; - -/** - * Admin 模块 - Admin 信息 Response - */ -@Data -@Accessors(chain = true) -public class AdminResponse implements Serializable { - - /** - * 管理员编号 - */ - private Integer id; - -} diff --git a/system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/response/oauth2/OAuth2AccessTokenResponse.java b/system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/response/oauth2/OAuth2AccessTokenResponse.java deleted file mode 100644 index eb397077a..000000000 --- a/system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/response/oauth2/OAuth2AccessTokenResponse.java +++ /dev/null @@ -1,33 +0,0 @@ -package cn.iocoder.mall.system.rpc.response.oauth2; - -import lombok.Data; -import lombok.experimental.Accessors; - -import java.io.Serializable; -import java.util.Date; - -/** - * OAuth2 认证 Response - */ -@Data -@Accessors(chain = true) -public class OAuth2AccessTokenResponse implements Serializable { - - /** - * 访问令牌 - */ - private String id; - /** - * 刷新令牌 - */ - private String refreshToken; - /** - * 账号编号 - */ - private Integer accountId; - /** - * 过期时间 - */ - private Date expiresTime; - -} diff --git a/system/system-rpc/src/main/java/cn/iocoder/mall/system/rpc/rpc/admin/AdminRPCImpl.java b/system/system-rpc/src/main/java/cn/iocoder/mall/system/rpc/rpc/admin/AdminRPCImpl.java deleted file mode 100644 index 2e1fb990d..000000000 --- a/system/system-rpc/src/main/java/cn/iocoder/mall/system/rpc/rpc/admin/AdminRPCImpl.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.iocoder.mall.system.rpc.rpc.admin; - -import cn.iocoder.common.framework.vo.CommonResult; -import cn.iocoder.mall.system.biz.bo.admin.AdminBO; -import cn.iocoder.mall.system.biz.service.admin.AdminService; -import cn.iocoder.mall.system.rpc.api.admin.AdminRPC; -import cn.iocoder.mall.system.rpc.convert.admn.AdminCovert; -import cn.iocoder.mall.system.rpc.response.admin.AdminResponse; -import org.apache.dubbo.config.annotation.Service; -import org.springframework.beans.factory.annotation.Autowired; - -@Service(version = "${dubbo.provider.AdminRPC.version}", validation = "true") -public class AdminRPCImpl implements AdminRPC { - - @Autowired - private AdminService adminService; - - @Override - public CommonResult getAdmin(Integer id) { - AdminBO adminBO = adminService.getAdmin(id); - return CommonResult.success(AdminCovert.INSTANCE.convert(adminBO)); - } - - @Override - public CommonResult getAdminByAccountId(Integer accountId) { - AdminBO adminBO = adminService.getAdminByAccountId(accountId); - return CommonResult.success(AdminCovert.INSTANCE.convert(adminBO)); - } - -} diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/system/api/OAuth2Service.java b/system/system-service-api/src/main/java/cn/iocoder/mall/system/api/OAuth2Service.java deleted file mode 100644 index 693943a16..000000000 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/system/api/OAuth2Service.java +++ /dev/null @@ -1,17 +0,0 @@ -package cn.iocoder.mall.system.api; - -import cn.iocoder.mall.system.api.dto.oauth2.OAuth2RemoveTokenByUserDTO; - -/** - * Oauth2 服务接口 - */ -public interface OAuth2Service { - - /** - * 基于用户移除 accessToken - * - * @param oauth2RemoveTokenDTO accessToken 信息 - */ - void removeToken(OAuth2RemoveTokenByUserDTO oauth2RemoveTokenDTO); - -} diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/OAuth2Convert.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/OAuth2Convert.java deleted file mode 100644 index f5d9ebc05..000000000 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/OAuth2Convert.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.iocoder.mall.admin.convert; - -import cn.iocoder.mall.system.api.bo.oauth2.OAuth2AccessTokenBO; -import cn.iocoder.mall.system.api.bo.oauth2.OAuth2AuthenticationBO; -import cn.iocoder.mall.admin.dataobject.OAuth2AccessTokenDO; -import org.mapstruct.Mapper; -import org.mapstruct.Mapping; -import org.mapstruct.Mappings; -import org.mapstruct.factory.Mappers; - -@Mapper -public interface OAuth2Convert { - - OAuth2Convert INSTANCE = Mappers.getMapper(OAuth2Convert.class); - - @Mappings({ - @Mapping(source = "id", target = "accessToken") - }) - OAuth2AccessTokenBO convertToAccessToken(OAuth2AccessTokenDO oauth2AccessTokenDO); - - default OAuth2AccessTokenBO convertToAccessTokenWithExpiresIn(OAuth2AccessTokenDO oauth2AccessTokenDO) { - return this.convertToAccessToken(oauth2AccessTokenDO) - .setExpiresIn(Math.max((int) ((oauth2AccessTokenDO.getExpiresTime().getTime() - System.currentTimeMillis()) / 1000), 0)); - } - - @Mappings({}) - OAuth2AuthenticationBO convertToAuthentication(OAuth2AccessTokenDO oauth2AccessTokenDO); - - -} diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/AdminServiceImpl.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/AdminServiceImpl.java deleted file mode 100644 index 52658dc3b..000000000 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/AdminServiceImpl.java +++ /dev/null @@ -1,48 +0,0 @@ -package cn.iocoder.mall.admin.service; - -import cn.iocoder.common.framework.enums.CommonStatusEnum; -import cn.iocoder.common.framework.enums.DeletedStatusEnum; -import cn.iocoder.common.framework.enums.UserTypeEnum; -import cn.iocoder.common.framework.util.CollectionUtil; -import cn.iocoder.common.framework.util.ServiceExceptionUtil; -import cn.iocoder.common.framework.vo.PageResult; -import cn.iocoder.mall.system.api.AdminService; -import cn.iocoder.mall.system.api.bo.admin.AdminBO; -import cn.iocoder.mall.system.api.bo.role.RoleBO; -import cn.iocoder.mall.system.api.constant.AdminConstants; -import cn.iocoder.mall.system.api.constant.AdminErrorCodeEnum; -import cn.iocoder.mall.system.api.dto.admin.*; -import cn.iocoder.mall.system.api.dto.oauth2.OAuth2RemoveTokenByUserDTO; -import cn.iocoder.mall.admin.convert.AdminConvert; -import cn.iocoder.mall.admin.dao.AdminMapper; -import cn.iocoder.mall.admin.dao.AdminRoleMapper; -import cn.iocoder.mall.admin.dataobject.AdminDO; -import cn.iocoder.mall.admin.dataobject.AdminRoleDO; -import cn.iocoder.mall.admin.dataobject.RoleDO; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Multimap; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.*; -import java.util.stream.Collectors; - -@Service -@org.apache.dubbo.config.annotation.Service(validation = "true", version = "${dubbo.provider.AdminService.version}") -public class AdminServiceImpl implements AdminService { - - @Autowired - private AdminMapper adminMapper; - @Autowired - private AdminRoleMapper adminRoleMapper; - - @Autowired - private OAuth2ServiceImpl oauth2Service; - @Autowired - private RoleServiceImpl roleService; - - - -} diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/OAuth2ServiceImpl.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/OAuth2ServiceImpl.java deleted file mode 100644 index 4cccbbbc5..000000000 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/OAuth2ServiceImpl.java +++ /dev/null @@ -1,54 +0,0 @@ -package cn.iocoder.mall.admin.service; - -import cn.iocoder.common.framework.util.ServiceExceptionUtil; -import cn.iocoder.mall.system.api.OAuth2Service; -import cn.iocoder.mall.system.api.bo.oauth2.OAuth2AccessTokenBO; -import cn.iocoder.mall.system.api.bo.oauth2.OAuth2AuthenticationBO; -import cn.iocoder.mall.system.api.constant.AdminErrorCodeEnum; -import cn.iocoder.mall.system.api.dto.oauth2.OAuth2CreateTokenDTO; -import cn.iocoder.mall.system.api.dto.oauth2.OAuth2GetTokenDTO; -import cn.iocoder.mall.system.api.dto.oauth2.OAuth2RefreshTokenDTO; -import cn.iocoder.mall.system.api.dto.oauth2.OAuth2RemoveTokenByUserDTO; -import cn.iocoder.mall.admin.convert.OAuth2Convert; -import cn.iocoder.mall.admin.dao.OAuth2AccessTokenMapper; -import cn.iocoder.mall.admin.dao.OAuth2RefreshTokenMapper; -import cn.iocoder.mall.admin.dataobject.OAuth2AccessTokenDO; -import cn.iocoder.mall.admin.dataobject.OAuth2RefreshTokenDO; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.Date; -import java.util.UUID; - -@Service -@org.apache.dubbo.config.annotation.Service(validation = "true", version = "${dubbo.provider.OAuth2Service.version:1.0.0}") -public class OAuth2ServiceImpl implements OAuth2Service { - - /** - * 访问令牌过期时间,单位:毫秒 - */ - @Value("${modules.oauth2-code-service.access-token-expire-time-millis}") - private int accessTokenExpireTimeMillis; - /** - * 刷新令牌过期时间,单位:毫秒 - */ - @Value("${modules.oauth2-code-service.refresh-token-expire-time-millis}") - private int refreshTokenExpireTimeMillis; - - @Autowired - private AdminServiceImpl adminService; - - @Override - @Transactional - public void removeToken(OAuth2RemoveTokenByUserDTO oauth2RemoveTokenByUserDTO) { - Integer userId = oauth2RemoveTokenByUserDTO.getUserId(); - Integer userType = oauth2RemoveTokenByUserDTO.getUserType(); - // 设置 access token 失效 - oauth2AccessTokenMapper.updateToInvalid(userId, userType); - // 设置 refresh token 失效 - oauth2RefreshTokenMapper.updateToInvalid(userId, userType); - } - -} diff --git a/system/system-start/src/main/java/cn/iocoder/mall/system/application/convert/PassportConvert.java b/system/system-start/src/main/java/cn/iocoder/mall/system/application/convert/PassportConvert.java deleted file mode 100644 index 2ca06657b..000000000 --- a/system/system-start/src/main/java/cn/iocoder/mall/system/application/convert/PassportConvert.java +++ /dev/null @@ -1,21 +0,0 @@ -package cn.iocoder.mall.system.application.convert; - -import cn.iocoder.common.framework.vo.CommonResult; -import cn.iocoder.mall.system.api.bo.oauth2.OAuth2AccessTokenBO; -import cn.iocoder.mall.system.application.vo.PassportLoginVO; -import org.mapstruct.Mapper; -import org.mapstruct.Mappings; -import org.mapstruct.factory.Mappers; - -@Mapper -public interface PassportConvert { - - PassportConvert INSTANCE = Mappers.getMapper(PassportConvert.class); - - @Mappings({}) - PassportLoginVO convert(OAuth2AccessTokenBO oauth2AccessTokenBO); - - @Mappings({}) - CommonResult convert(CommonResult oauth2AccessTokenBO); - -}