diff --git a/README.md b/README.md index 45b1b14171b48b0e299a63cb2b940ced26849f92..a8913d900bc90656eff92e98bc146e2f1ce814a7 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,7 @@ ## 🍒文档 - 项目文档:[开发文档](https://www.yuque.com/bootx/bootx-cloud/) +- 前端项目地址:[https://gitee.com/bootx/bootx-cloud-ui](https://gitee.com/bootx/bootx-cloud-ui) - 项目启动:[启动文档](https://www.yuque.com/bootx/bootx-cloud/vpi0gn) - 开发计划:[开发计划](https://www.yuque.com/bootx/bootx-cloud/xzmc6c) diff --git a/service-iam/service-iam-api/src/main/java/cn/bootx/iam/code/IamCode.java b/service-iam/service-iam-api/src/main/java/cn/bootx/iam/code/IamCode.java new file mode 100644 index 0000000000000000000000000000000000000000..1e4f29600b87ab2f333737902bc1442bc70d2f18 --- /dev/null +++ b/service-iam/service-iam-api/src/main/java/cn/bootx/iam/code/IamCode.java @@ -0,0 +1,14 @@ +package cn.bootx.iam.code; + +/** +* +* @author xxm +* @date 2021/7/14 +*/ +public interface IamCode { + /** + * 项目名称 + */ + String APPLICATION_NAME = "service-iam"; + +} diff --git a/service-iam/service-iam-api/src/main/java/cn/bootx/iam/dto/auth/AuthInfoResult.java b/service-iam/service-iam-api/src/main/java/cn/bootx/iam/dto/auth/AuthInfoResult.java index 2b22ec6d4a4d7ccadba2cad27166649e4a034697..be701a0339850de9dace359e703e13370b811a34 100644 --- a/service-iam/service-iam-api/src/main/java/cn/bootx/iam/dto/auth/AuthInfoResult.java +++ b/service-iam/service-iam-api/src/main/java/cn/bootx/iam/dto/auth/AuthInfoResult.java @@ -22,6 +22,8 @@ public class AuthInfoResult { private Long tid; /** 名称 */ private String name; + /** 账号 */ + private String account; /** 邮件 */ private String email; /** 手机号 */ diff --git a/service-iam/service-iam-api/src/main/java/cn/bootx/iam/dto/auth/AuthPasswordDto.java b/service-iam/service-iam-api/src/main/java/cn/bootx/iam/dto/auth/AuthPasswordDto.java index d2663bb549f384b110199fe93546f016a02ad50e..98ed265634816665009ec69927af3966b4c25fc9 100644 --- a/service-iam/service-iam-api/src/main/java/cn/bootx/iam/dto/auth/AuthPasswordDto.java +++ b/service-iam/service-iam-api/src/main/java/cn/bootx/iam/dto/auth/AuthPasswordDto.java @@ -29,9 +29,6 @@ public class AuthPasswordDto extends BaseDto implements Serializable { @ApiModelProperty(value = "用户主键", required = true) private Long uid; - @ApiModelProperty(value = "用户登录账号", required = true) - private String account; - @ApiModelProperty(value = "用户密码", required = true) private String password; diff --git a/service-iam/service-iam-api/src/main/java/cn/bootx/iam/dto/role/RoleDto.java b/service-iam/service-iam-api/src/main/java/cn/bootx/iam/dto/role/RoleDto.java index 24311cc071b16a4e690f5c33c48a5638df546dc7..a290c0813aeb4b0c1247e915cc8da9ce115539bf 100644 --- a/service-iam/service-iam-api/src/main/java/cn/bootx/iam/dto/role/RoleDto.java +++ b/service-iam/service-iam-api/src/main/java/cn/bootx/iam/dto/role/RoleDto.java @@ -1,7 +1,9 @@ package cn.bootx.iam.dto.role; +import cn.bootx.common.web.rest.dto.BaseDto; import io.swagger.annotations.ApiModel; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; import java.io.Serializable; @@ -9,15 +11,13 @@ import java.io.Serializable; /** * @author xxm */ +@EqualsAndHashCode(callSuper = true) @Data @Accessors(chain = true) @ApiModel("角色") -public class RoleDto implements Serializable { +public class RoleDto extends BaseDto implements Serializable { private static final long serialVersionUID = 5532196699667233754L; - /** 角色id */ - private Long id; - /** 角色code */ private String code; diff --git a/service-iam/service-iam-api/src/main/java/cn/bootx/iam/dto/user/UserInfoDto.java b/service-iam/service-iam-api/src/main/java/cn/bootx/iam/dto/user/UserInfoDto.java index 088f6c533b2ff7f3df5d630342e2d380f1ccd4e8..eb649ee8c8fd485a0555d719f3c01e5d35a3098f 100644 --- a/service-iam/service-iam-api/src/main/java/cn/bootx/iam/dto/user/UserInfoDto.java +++ b/service-iam/service-iam-api/src/main/java/cn/bootx/iam/dto/user/UserInfoDto.java @@ -22,6 +22,9 @@ public class UserInfoDto implements Serializable { @ApiModelProperty("名称") private String name; + @ApiModelProperty("账号") + private String account; + @ApiModelProperty("手机号") private String phone; @@ -37,9 +40,6 @@ public class UserInfoDto implements Serializable { @ApiModelProperty("注册时间") private LocalDateTime registerTime; - @ApiModelProperty("登录账号") - private String account; - @ApiModelProperty("token") private String token; diff --git a/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/code/CachingCode.java b/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/code/CachingCode.java new file mode 100644 index 0000000000000000000000000000000000000000..ef60e1b9a3e010427b651d270294a953ff69706f --- /dev/null +++ b/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/code/CachingCode.java @@ -0,0 +1,30 @@ +package cn.bootx.iam.code; + +/** +* 缓存名称 +* @author xxm +* @date 2021/6/16 +*/ +public interface CachingCode { + + /** 请求对应权限缓存 */ + String PERMISSION_PATH = "uc:permission:path"; + + /** 菜单对应权限缓存 */ + String PERMISSION_MENU = "uc:permission:menu"; + + /** 用户权限id关系缓存 */ + String USER_PERMISSION_ID = "uc:user:permission:id"; + + /** 用户请求权限id关系缓存 */ + String USER_PATH_ID = "uc:user:path:id"; + + /** 用户菜单权限id关系缓存 */ + String USER_MENU_ID = "uc:user:menu:id"; + + /** 用户请求权限关系缓存 */ + String USER_PATH = "uc:user:path"; + + /** 用户菜单权限关系缓存 */ + String USER_MENU = "uc:user:menu"; +} diff --git a/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/controller/LoginController.java b/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/controller/LoginController.java index 080c3c79d74309809138ed8f91f335139d1198da..e62808787b176866aa91c9046d011ed8620caa47 100644 --- a/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/controller/LoginController.java +++ b/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/controller/LoginController.java @@ -29,12 +29,6 @@ public class LoginController { return Res.ok(loginService.loginPassword(loginParam)); } - @ApiOperation("获取登录信息") - @GetMapping("/getUserInfo") - public ResResult getUserInfo(){ - return Res.ok(loginService.getUserInfo()); - } - @ApiOperation("退出") @PostMapping("/logout") public ResResult logout(){ diff --git a/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/controller/LoginUserController.java b/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/controller/LoginUserController.java index 2bd624b1d04fc3c370b8e13ba2aa4bf2cdaff0fe..b667224fb751e2ce29a1300e9d74f20c6e2f1a92 100644 --- a/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/controller/LoginUserController.java +++ b/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/controller/LoginUserController.java @@ -3,6 +3,7 @@ package cn.bootx.iam.controller; import cn.bootx.common.web.rest.Res; import cn.bootx.common.web.rest.ResResult; import cn.bootx.iam.core.login.service.LoginUserService; +import cn.bootx.iam.dto.auth.AuthInfoResult; import cn.bootx.iam.dto.login.MenuAndPermissionDto; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -18,7 +19,7 @@ import org.springframework.web.bind.annotation.RestController; */ @Api(tags = "登录用户接口") @RestController -@RequestMapping("/login/user/") +@RequestMapping("/login/user") @RequiredArgsConstructor public class LoginUserController { private final LoginUserService loginUserService; @@ -28,4 +29,10 @@ public class LoginUserController { public ResResult getUserPermission(){ return Res.ok(loginUserService.getUserPermission()); } + + @ApiOperation("获取登录信息") + @GetMapping("/getUserInfo") + public ResResult getUserInfo(){ + return Res.ok(loginUserService.getUserInfo()); + } } diff --git a/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/controller/RoleController.java b/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/controller/RoleController.java index d3650e73cef643350f2512c0c1b4a74a0dab4c1a..afc097892530cb8a3f7b73c98f8c84cb76fa021d 100644 --- a/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/controller/RoleController.java +++ b/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/controller/RoleController.java @@ -29,20 +29,14 @@ public class RoleController { private final RoleService roleService; @ApiOperation(value = "添加角色(返回角色对象)") - @ApiResponses(value = { - @ApiResponse(code = UcErrorCodes.ROLE_ALREADY_EXISTED, message = "角色已存在"), - }) @PostMapping(value = "/add") - public ResResult add(RoleDto roleDto){ + public ResResult add(@RequestBody RoleDto roleDto){ ValidationUtil.validateParam(roleDto); RoleDto result = roleService.add(roleDto); return Res.ok(result); } @ApiOperation(value = "删除角色") - @ApiResponses(value = { - @ApiResponse(code = UcErrorCodes.ROLE_NOT_EXISTED, message = "角色不存在"), - }) @DeleteMapping(value = "/delete") public ResResult delete(Long id){ roleService.delete(id); @@ -50,10 +44,6 @@ public class RoleController { } @ApiOperation(value = "修改角色(返回角色对象)") - @ApiResponses(value = { - @ApiResponse(code = UcErrorCodes.ROLE_NOT_EXISTED, message = "角色不存在"), - @ApiResponse(code = UcErrorCodes.ROLE_ALREADY_EXISTED, message = "角色名称已存在") - }) @PostMapping(value = "/update") public ResResult update(@RequestBody RoleDto roleDto){ ValidationUtil.validateParam(roleDto); diff --git a/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/auth/dao/AuthPasswordManager.java b/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/auth/dao/AuthPasswordManager.java index 12ca3fdad41b337684d64bee2de397294459d480..8e8e72dcdeef2380f921d582707619e0aba10168 100644 --- a/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/auth/dao/AuthPasswordManager.java +++ b/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/auth/dao/AuthPasswordManager.java @@ -23,18 +23,10 @@ public class AuthPasswordManager { return userAuthRepository.findByUidAndTid(uid,headerHolder.findTid()); } - public Optional findByAccount(String account) { - return userAuthRepository.findByAccountAndTid(account,headerHolder.findTid()); - } - public boolean existsByUid(Long uid) { return userAuthRepository.existsByUidAndTid(uid,headerHolder.findTid()); } - public boolean existsByAccount(String account) { - return userAuthRepository.existsByAccountAndTid(account,headerHolder.findTid()); - } - public Optional findById(Long id) { return userAuthRepository.findByIdAndTid(id,headerHolder.findTid()); } diff --git a/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/auth/dao/AuthPasswordRepository.java b/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/auth/dao/AuthPasswordRepository.java index a314bfa17f4545c8ee07d4a96c136627aa69091e..9e244e8567e0c3ea2962dbc421a6d37dfe3885b6 100644 --- a/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/auth/dao/AuthPasswordRepository.java +++ b/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/auth/dao/AuthPasswordRepository.java @@ -9,11 +9,7 @@ public interface AuthPasswordRepository extends JpaRepository Optional findByUidAndTid(Long id, Long tid); - Optional findByAccountAndTid(String account, Long tid); - boolean existsByUidAndTid(Long uid, Long tid); - boolean existsByAccountAndTid(String account, Long tid); - Optional findByIdAndTid(Long id, Long tid); } diff --git a/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/auth/entity/AuthPassword.java b/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/auth/entity/AuthPassword.java index e8815b1711cd7164e914b5b627add81529b15ae6..ce8d42709aca2853a9c941d962127cffbec826d4 100644 --- a/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/auth/entity/AuthPassword.java +++ b/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/auth/entity/AuthPassword.java @@ -29,9 +29,6 @@ public class AuthPassword extends JpaBaseEntity implements EntityBaseFunction new BizException("账号或密码错误")); - userInfoDto = Optional.ofNullable(userInfoService.findById(authPassword.getUid())) - .orElseThrow(UserInfoNotExistsException::new); + userInfoDto = userInfoService.findByAccount(loginParam.getAccount()); } + if (Objects.isNull(userInfoDto)){ + throw new UserInfoNotExistsException(); + } + AuthPassword authPassword = userAuthManager.findByUid(userInfoDto.getId()).orElseThrow(UserInfoNotExistsException::new); + // 3. 对比密码认证信息 String password = PasswordUtil.md5(loginParam.getPassword()); String passwordMd5 = PasswordUtil.md5(password, loginParam.getAccount()); diff --git a/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/login/service/LoginService.java b/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/login/service/LoginService.java index d01ad78eb36559413054ba0d69c685f6293bdd16..2dcc8e1adb12c2b387bd36232a8eeb56b979b2b8 100644 --- a/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/login/service/LoginService.java +++ b/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/login/service/LoginService.java @@ -68,15 +68,6 @@ public class LoginService { return null; } - public AuthInfoResult getUserInfo(){ - String accessToken = headerHolder.findAccessToken(); - LoginInfoBo loginInfo = userAuthTokenService.getLoginInfo(accessToken); - if (Objects.isNull(loginInfo)){ - return null; - } - return loginInfo.toResult().setToken(accessToken); - } - /** * 退出 */ @@ -100,6 +91,7 @@ public class LoginService { List roleIds = userRoleService.findRoleIdsByUser(userinfo.getId()); return new LoginInfoBo() .setClient(client) + .setAccount(userinfo.getAccount()) .setUid(userinfo.getId()) .setName(userinfo.getName()) .setPhone(userinfo.getPhone()) diff --git a/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/login/service/LoginUserService.java b/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/login/service/LoginUserService.java index d92e85ccc53a07cbd30bf375757c9aded18a87d4..1b17868a18856505f2728392a3b5cb3f5f279df1 100644 --- a/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/login/service/LoginUserService.java +++ b/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/login/service/LoginUserService.java @@ -3,12 +3,15 @@ package cn.bootx.iam.core.login.service; import cn.bootx.common.web.exception.BizException; import cn.bootx.iam.code.permission.PermissionCode; import cn.bootx.iam.core.role.service.RoleMenuService; +import cn.bootx.iam.core.session.domain.LoginInfoBo; +import cn.bootx.iam.core.session.service.UserAuthTokenService; import cn.bootx.iam.dto.auth.AuthInfoResult; import cn.bootx.iam.dto.login.LoginMenuDto; import cn.bootx.iam.dto.login.LoginMenuMetaDto; import cn.bootx.iam.dto.login.LoginPermissionDto; import cn.bootx.iam.dto.login.MenuAndPermissionDto; import cn.bootx.iam.dto.permission.PermissionMenuDto; +import cn.bootx.starter.headerholder.HeaderHolder; import cn.hutool.core.collection.CollUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -28,13 +31,27 @@ import java.util.stream.Collectors; public class LoginUserService { private final RoleMenuService roleMenuService; + private final UserAuthTokenService userAuthTokenService; private final LoginService loginService; + private final HeaderHolder headerHolder; + + /** + * 获取用户信息 + */ + public AuthInfoResult getUserInfo(){ + String accessToken = headerHolder.findAccessToken(); + LoginInfoBo loginInfo = userAuthTokenService.getLoginInfo(accessToken); + if (Objects.isNull(loginInfo)){ + return null; + } + return loginInfo.toResult().setToken(accessToken); + } /** * 查询用户路由菜单和按钮权限 */ public MenuAndPermissionDto getUserPermission(){ - AuthInfoResult userInfo = Optional.ofNullable(loginService.getUserInfo()) + AuthInfoResult userInfo = Optional.ofNullable(this.getUserInfo()) .orElseThrow(() -> new BizException("未登录")); List permissionsByUser = roleMenuService.findPermissionsByUser(userInfo.getUid()); diff --git a/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/role/dao/RoleManager.java b/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/role/dao/RoleManager.java index 26981e2847a586e03013598eaee49bef3a60a7cd..c4601dcd8a9bd0f47e2072cbf63d66e6a16830cb 100644 --- a/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/role/dao/RoleManager.java +++ b/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/role/dao/RoleManager.java @@ -26,17 +26,27 @@ public class RoleManager { private final HeaderHolder headerHolder; - public boolean existsByNameAndCode(String name, String code) { - return roleRepository.existsByNameAndCodeAndTid(name,code,headerHolder.findTid()); + public boolean existsByCode(String code) { + return roleRepository.existsByCodeAndTid(code,headerHolder.findTid()); + } + + + public boolean existsByName(String name) { + return roleRepository.existsByNameAndTid(name,headerHolder.findTid()); + } + + public boolean existsByCode(String code, Long id) { + return roleRepository.existsByCodeAndIdNotAndTid(code,id,headerHolder.findTid()); + } + + public boolean existsByName(String name, Long id) { + return roleRepository.existsByNameAndIdNotAndTid(name,id,headerHolder.findTid()); } public boolean existsById(Long id) { return roleRepository.existsByIdAndTid(id,headerHolder.findTid()); } - public boolean existsByNameAndCode(String name, String code, Long id) { - return roleRepository.existsByNameAndCodeAndIdNotAndTid(name,code,id,headerHolder.findTid()); - } public Optional findById(Long id) { return roleRepository.findByIdAndTid(id,headerHolder.findTid()); diff --git a/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/role/dao/RoleRepository.java b/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/role/dao/RoleRepository.java index 02cc8c79e1e6086f4655aa3ae443dcb46fccf37d..6e46d813c1a83cbeffdbf1fb9cbbbc9856f91d42 100644 --- a/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/role/dao/RoleRepository.java +++ b/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/role/dao/RoleRepository.java @@ -13,15 +13,20 @@ import java.util.Optional; */ public interface RoleRepository extends JpaRepository { - boolean existsByNameAndCodeAndTid(String name, String code, Long tid); + boolean existsByCodeAndTid(String code, Long tid); + + boolean existsByNameAndTid(String name, Long tid); boolean existsByIdAndTid(Long id, Long tid); - boolean existsByNameAndCodeAndIdNotAndTid(String name, String code, Long id, Long tid); + boolean existsByCodeAndIdNotAndTid(String code, Long id, Long tid); + + boolean existsByNameAndIdNotAndTid(String name, Long id, Long tid); Optional findByIdAndTid(Long id, Long tid); List findAllByTid(Long tid); List findAllByIdInAndTid(List ids, Long tid); + } diff --git a/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/role/service/RoleService.java b/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/role/service/RoleService.java index ab9aecd0b92a7386b45bd0151c600da81b647eb7..d92954664e9b318fcf2788a04ccbfe124dc1aeea 100644 --- a/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/role/service/RoleService.java +++ b/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/role/service/RoleService.java @@ -40,29 +40,16 @@ public class RoleService { @Transactional(rollbackFor = Exception.class) public RoleDto add(RoleDto roleDto) { //Name唯一性校验(名称code不能相同) - if (roleManager.existsByNameAndCode(roleDto.getName(),roleDto.getCode())){ + if (roleManager.existsByCode(roleDto.getName())){ + throw new RoleAlreadyExistedException(); + } + if (roleManager.existsByName(roleDto.getCode())){ throw new RoleAlreadyExistedException(); } Role role = Role.init(roleDto); return roleRepository.save(role).toDto(); } - /** - * 根据ID删除角色 - */ - @Transactional(rollbackFor = Exception.class) - public void delete(Long id) { - if (Objects.isNull(id) || !roleManager.existsById(id)){ - throw new RoleNotExistedException(); - } - // 存在当前角色用户的场合不允许删除 - if (userRoleManager.existsByRoleId(id)) { - throw new RoleAlreadyUsedException(); - } - // 删除角色信息 - roleRepository.deleteById(id); - } - /** * 修改角色 */ @@ -71,7 +58,10 @@ public class RoleService { Long id = roleDto.getId(); //Name唯一性校验(同一个租户下名称code不能相同) - if (roleManager.existsByNameAndCode(roleDto.getName(),roleDto.getCode(),id)){ + if (roleManager.existsByCode(roleDto.getCode(),id)){ + throw new RoleAlreadyExistedException(); + } + if (roleManager.existsByName(roleDto.getName(),id)){ throw new RoleAlreadyExistedException(); } @@ -81,6 +71,22 @@ public class RoleService { return roleRepository.save(role).toDto(); } + /** + * 根据ID删除角色 + */ + @Transactional(rollbackFor = Exception.class) + public void delete(Long id) { + if (Objects.isNull(id) || !roleManager.existsById(id)){ + throw new RoleNotExistedException(); + } + // 存在当前角色用户的场合不允许删除 + if (userRoleManager.existsByRoleId(id)) { + throw new RoleAlreadyUsedException(); + } + // 删除角色信息 + roleRepository.deleteById(id); + } + /** * 查询租户下所有的角色 */ diff --git a/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/session/domain/LoginInfoBo.java b/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/session/domain/LoginInfoBo.java index fd4fed093707a82b4f71bd06e0c8416e3cb89d96..192b4bbee6c5c1facbd2de342c937b0fc87bac6c 100644 --- a/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/session/domain/LoginInfoBo.java +++ b/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/session/domain/LoginInfoBo.java @@ -28,6 +28,8 @@ public class LoginInfoBo implements Serializable { private Long uid; /** 租户 */ private Long tid; + /** 账号 */ + private String account; /** 姓名 */ private String name; /** 邮件 */ diff --git a/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/user/dao/UserInfoManager.java b/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/user/dao/UserInfoManager.java index 299e269c88374b3a84111e60854a9f189cd68687..7d7a5e3cb4d78e1dfb2d3601514d492aa1de6672 100644 --- a/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/user/dao/UserInfoManager.java +++ b/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/user/dao/UserInfoManager.java @@ -24,12 +24,20 @@ public class UserInfoManager { return userInfoRepository.findByIdAndTid(id,headerHolder.findTid()); } - public boolean existsEmail(String email) { + public boolean existsByAccount(String account) { + return userInfoRepository.existsByAccountAndTid(account,headerHolder.findTid()); + } + + public boolean existsByEmail(String email) { return userInfoRepository.existsByEmailAndTid(email,headerHolder.findTid()); } - public boolean existsPhone(String phone) { - return userInfoRepository.existsByEmailAndTid(phone,headerHolder.findTid()); + public boolean existsByPhone(String phone) { + return userInfoRepository.existsByPhoneAndTid(phone,headerHolder.findTid()); + } + + public Optional findByAccount(String account) { + return userInfoRepository.findByAccountAndTid(account,headerHolder.findTid()); } public Optional findByEmail(String email) { diff --git a/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/user/dao/UserInfoRepository.java b/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/user/dao/UserInfoRepository.java index f3273a0874eded11c78a73fb02b6aade17436dd9..4e4e33c19519308cd0bfe8e454c090d27c9dd542 100644 --- a/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/user/dao/UserInfoRepository.java +++ b/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/user/dao/UserInfoRepository.java @@ -11,12 +11,19 @@ public interface UserInfoRepository extends JpaRepository { List findByIdInAndTid(List ids, Long tid); + boolean existsByIdAndTid(Long id, Long tid); + + boolean existsByAccountAndTid(String account, Long tid); + boolean existsByEmailAndTid(String email,Long tid); + boolean existsByPhoneAndTid(String phone,Long tid); + + Optional findByAccountAndTid(String account, Long tid); + Optional findByEmailAndTid(String email, Long tid); Optional findByPhoneAndTid(String phone, Long tid); - boolean existsByIdAndTid(Long id, Long tid); } diff --git a/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/user/entity/UserInfo.java b/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/user/entity/UserInfo.java index e0ba9687419662cb647e7d2090c1ba875e11bca3..c51af931837af562b799eb1ddb60c5e0994d80ff 100644 --- a/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/user/entity/UserInfo.java +++ b/service-iam/service-iam-impl/src/main/java/cn/bootx/iam/core/user/entity/UserInfo.java @@ -30,6 +30,9 @@ public class UserInfo extends JpaBaseEntity implements EntityBaseFunction1.1.0-SNAPSHOT - - cn.bootx - service-payment-center-domain - 1.1.0-SNAPSHOT - - diff --git a/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/code/pay/PayTransactionPurposeCode.java b/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/code/pay/PayTransactionPurposeCode.java new file mode 100644 index 0000000000000000000000000000000000000000..7db0184f215e25c4ec600c931cbef44a0f6e78d6 --- /dev/null +++ b/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/code/pay/PayTransactionPurposeCode.java @@ -0,0 +1,16 @@ +package cn.bootx.paymentcenter.code.pay; + +/** +* 交易目的 +* @author xxm +* @date 2021/2/24 +*/ +public interface PayTransactionPurposeCode { + + /** + * 支付目的 1.购买 2.换货 3.退货 + */ + int PURCHASE = 1; + int EXCHANGE = 2; + int RETURN = 3; +} diff --git a/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/code/pay/PayTransactionTypeCode.java b/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/code/pay/PayTransactionTypeCode.java new file mode 100644 index 0000000000000000000000000000000000000000..06e7cd9c5523b880a8fd89f3300c992e7a0c4021 --- /dev/null +++ b/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/code/pay/PayTransactionTypeCode.java @@ -0,0 +1,20 @@ +package cn.bootx.paymentcenter.code.pay; + +/** +* 交易类型(名目) +* @author xxm +* @date 2021/2/24 +*/ +public interface PayTransactionTypeCode { + + /** + * 交易支付类型名目 1.商品 2.补差价 3.退款 4.手续费 5.税款 6.额外费用 7.服务费用 + */ + int GOODS = 1; + int DIFFERENCE = 2; + int REFUND = 3; + int FEES = 4; + int FAXES = 5; + int EXTRA = 6; + int SERVICE = 7; +} diff --git a/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/dto/TransactionRefundRecordDto.java b/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/dto/TransactionRefundRecordDto.java new file mode 100644 index 0000000000000000000000000000000000000000..9747bb76a4e14443fc50359b332cd72b15785b1c --- /dev/null +++ b/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/dto/TransactionRefundRecordDto.java @@ -0,0 +1,39 @@ +package cn.bootx.paymentcenter.dto; + +import cn.bootx.common.web.rest.dto.BaseDto; +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +import java.io.Serializable; +import java.math.BigDecimal; + +/** +* @author xxm +* @date 2020/12/9 +*/ +@EqualsAndHashCode(callSuper = true) +@Data +@Accessors(chain = true) +@ApiModel("交易退款记录") +public class TransactionRefundRecordDto extends BaseDto implements Serializable { + + private static final long serialVersionUID = 4371362578623528078L; + private String transactionId; + + private int type; + + private int payType; + + private BigDecimal amount; + + private Long refundOrderId; + + private Long creator; + + private Long paymentId; + + private String account; + +} diff --git a/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/dto/pay/Buyer.java b/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/dto/pay/Buyer.java new file mode 100644 index 0000000000000000000000000000000000000000..0ad16541c82bdf6ff4ed8a45bf0568101ff62ffe --- /dev/null +++ b/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/dto/pay/Buyer.java @@ -0,0 +1,41 @@ +package cn.bootx.paymentcenter.dto.pay; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; + +/** +* 购买人 +* @author xxm +* @date 2020/12/10 +*/ +@Data +@Accessors(chain = true) +public class Buyer implements Serializable { + + private static final long serialVersionUID = 6421170311378917346L; + + @ApiModelProperty(value = "姓名") + private String name; + + @ApiModelProperty(value = "手机号") + private String phone; + + @ApiModelProperty(value = "邮件") + private String email; + + @ApiModelProperty(value = "ip") + private String ip; + + @ApiModelProperty(value = "代理") + private String userAgent; + + @ApiModelProperty(value = "代理商平台(windows,mac,iphone,Android等)") + private String userAgentType; + + @ApiModelProperty(value = "userClient") + private String userClient; + +} diff --git a/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/dto/payment/BasePaymentDto.java b/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/dto/payment/BasePaymentDto.java index b67a6f2cc2a02899ba645303937ec1be6364cece..dd6139ed23e2d16fe2e73f13b61a88a46b89aa4a 100644 --- a/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/dto/payment/BasePaymentDto.java +++ b/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/dto/payment/BasePaymentDto.java @@ -2,6 +2,8 @@ package cn.bootx.paymentcenter.dto.payment; import cn.bootx.common.web.rest.dto.BaseDto; import cn.bootx.paymentcenter.code.pay.PayStatusCode; +import cn.bootx.paymentcenter.code.pay.PayTransactionPurposeCode; +import cn.bootx.paymentcenter.code.pay.PayTransactionTypeCode; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; diff --git a/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/dto/payment/PaymentDto.java b/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/dto/payment/PaymentDto.java index 5c33149a9563992e25bbc5398ba0b884c29a8e4c..afa41b1182f243f4e9c0dcd24d81633c8a12f2bb 100644 --- a/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/dto/payment/PaymentDto.java +++ b/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/dto/payment/PaymentDto.java @@ -1,6 +1,8 @@ package cn.bootx.paymentcenter.dto.payment; import cn.bootx.common.web.rest.dto.BaseDto; +import cn.bootx.paymentcenter.code.pay.PayTransactionPurposeCode; +import cn.bootx.paymentcenter.code.pay.PayTransactionTypeCode; import cn.bootx.paymentcenter.dto.pay.PayTypeInfo; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; diff --git a/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/exception/payment/PaymentAmountAbnormalException.java b/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/exception/payment/PaymentAmountAbnormalException.java new file mode 100644 index 0000000000000000000000000000000000000000..0f622001e11f279aa31a22bcf44c5361888861e7 --- /dev/null +++ b/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/exception/payment/PaymentAmountAbnormalException.java @@ -0,0 +1,16 @@ +package cn.bootx.paymentcenter.exception.payment; + +import cn.bootx.common.web.exception.FatalException; +import cn.bootx.paymentcenter.code.PaymentCenterErrorCode; + +/** +* 异常金额 +* @author xxm +* @date 2020/12/8 +*/ +public class PaymentAmountAbnormalException extends FatalException { + + public PaymentAmountAbnormalException() { + super(PaymentCenterErrorCode.PAYMENT_AMOUNT_ABNORMAL, "异常金额"); + } +} \ No newline at end of file diff --git a/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/exception/payment/PaymentPayFailureException.java b/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/exception/payment/PaymentPayFailureException.java new file mode 100644 index 0000000000000000000000000000000000000000..77a33a1fe229c5b8e17122ad18bf244ac53bde68 --- /dev/null +++ b/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/exception/payment/PaymentPayFailureException.java @@ -0,0 +1,16 @@ +package cn.bootx.paymentcenter.exception.payment; + +import cn.bootx.common.web.exception.BizException; +import cn.bootx.paymentcenter.code.PaymentCenterErrorCode; + +/** +* 付款付款错误 +* @author xxm +* @date 2020/12/8 +*/ +public class PaymentPayFailureException extends BizException { + + public PaymentPayFailureException() { + super(PaymentCenterErrorCode.PAY_FAILURE, "支付失败"); + } +} \ No newline at end of file diff --git a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/controller/PaymentController.java b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/controller/PaymentController.java index a064e5163196692ec7e39b862baa3c90c922881a..cb9fdc6d09698905d7f06340fccfc7a39aa69f44 100644 --- a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/controller/PaymentController.java +++ b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/controller/PaymentController.java @@ -1,7 +1,9 @@ package cn.bootx.paymentcenter.controller; +import cn.bootx.common.web.rest.PageResult; import cn.bootx.common.web.rest.Res; import cn.bootx.common.web.rest.ResResult; +import cn.bootx.common.web.rest.param.PageParam; import cn.bootx.paymentcenter.core.payment.service.PaymentQueryService; import cn.bootx.paymentcenter.dto.pay.PayTypeInfo; import cn.bootx.paymentcenter.dto.payment.PaymentDto; @@ -18,26 +20,32 @@ import java.util.List; * @author xxm * @date 2021/6/28 */ -@Api(tags = "支付记录") +@Api(tags = "交易单") @RestController @RequestMapping("/payment") @RequiredArgsConstructor public class PaymentController { private final PaymentQueryService paymentQueryService; - @ApiOperation("根据id获取支付记录") + @ApiOperation("根据id获取") @GetMapping("/findById") public ResResult findById(Long id){ return Res.ok(paymentQueryService.findById(id)); } - @ApiOperation("根据userId获取支付记录列表") + @ApiOperation("根据userId获取列表") @GetMapping("/findByUser") public ResResult> findByUser(Long userid){ return Res.ok(paymentQueryService.findByUser(userid)); } - @ApiOperation("根据businessId获取支付记录列表") + @ApiOperation("分页查询") + @GetMapping("/page") + public ResResult> page(PageParam pageParam){ + return Res.ok(paymentQueryService.page(pageParam)); + } + + @ApiOperation("根据businessId获取列表") @GetMapping("/findByBusinessId") public ResResult> findByBusinessId(String businessId){ return Res.ok(paymentQueryService.findByBusinessId(businessId)); @@ -53,4 +61,5 @@ public class PaymentController { public ResResult> findPayTypeInfoById(Long id){ return Res.ok(paymentQueryService.findPayTypeInfoById(id)); } + } diff --git a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/payment/dao/PaymentManager.java b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/payment/dao/PaymentManager.java index 481ca310b6a3c763c5c0d4282d78ba1ee4c65307..0669a0a5c2a45cabeb370d731b5b34b8dfd7af8e 100644 --- a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/payment/dao/PaymentManager.java +++ b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/payment/dao/PaymentManager.java @@ -1,11 +1,15 @@ package cn.bootx.paymentcenter.core.payment.dao; +import cn.bootx.common.web.rest.param.PageParam; import cn.bootx.paymentcenter.code.pay.PayStatusCode; import cn.bootx.paymentcenter.core.payment.entity.Payment; import cn.bootx.paymentcenter.core.payment.entity.QPayment; import cn.bootx.starter.headerholder.HeaderHolder; +import cn.bootx.starter.jpa.utils.JpaUtils; +import com.querydsl.jpa.impl.JPAQuery; import com.querydsl.jpa.impl.JPAQueryFactory; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; @@ -86,4 +90,9 @@ public class PaymentManager { return paymentRepository.findByUserIdAndTid(userId,headerHolder.findTid()); } + public Page page(PageParam pageParam) { + QPayment q = QPayment.payment; + JPAQuery query = jpaQueryFactory.selectFrom(q); + return JpaUtils.queryPage(query,pageParam); + } } diff --git a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/payment/service/PaymentQueryService.java b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/payment/service/PaymentQueryService.java index e97aee25439adc3b0d88cd1596f5618470e04e07..428a5aa4f888164faf1b807a9c13e903539ffc72 100644 --- a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/payment/service/PaymentQueryService.java +++ b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/payment/service/PaymentQueryService.java @@ -1,9 +1,12 @@ package cn.bootx.paymentcenter.core.payment.service; +import cn.bootx.common.web.rest.PageResult; +import cn.bootx.common.web.rest.param.PageParam; import cn.bootx.paymentcenter.core.payment.dao.PaymentManager; import cn.bootx.paymentcenter.core.payment.entity.Payment; import cn.bootx.paymentcenter.dto.pay.PayTypeInfo; import cn.bootx.paymentcenter.dto.payment.PaymentDto; +import cn.bootx.starter.jpa.utils.JpaUtils; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -52,6 +55,9 @@ public class PaymentQueryService { .orElse(new ArrayList<>(1)); } + /** + * 根据id获取订单支付方式 + */ public List findPayTypeInfoById(Long id){ return paymentManager.findById(id) .map(Payment::getPayTypeInfos) @@ -66,4 +72,11 @@ public class PaymentQueryService { .map(Payment::toDto) .collect(Collectors.toList()); } + + /** + * 分页 + */ + public PageResult page(PageParam pageParam){ + return JpaUtils.convert2PageResult(paymentManager.page(pageParam)); + } } diff --git a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/paymodel/wallet/service/WalletPayService.java b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/paymodel/wallet/service/WalletPayService.java index 879e147b0a8183b78b5fa63488e7d127182860c0..eae16f9681c555b1b3f10483a86c554cefc1487e 100644 --- a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/paymodel/wallet/service/WalletPayService.java +++ b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/paymodel/wallet/service/WalletPayService.java @@ -10,9 +10,6 @@ import cn.bootx.paymentcenter.core.paymodel.wallet.entity.WalletLog; import cn.bootx.paymentcenter.dto.paymodel.wallet.WalletDto; import cn.bootx.paymentcenter.exception.waller.WalletLackOfBalanceException; import cn.bootx.paymentcenter.exception.waller.WalletLogError; -import cn.bootx.paymentcenter.exception.waller.WalletNotExistsException; -import cn.bootx.paymentcenter.param.refund.PayRefundDetailParam; -import cn.bootx.paymentcenter.param.refund.PayRefundParam; import cn.bootx.starter.headerholder.HeaderHolder; import cn.hutool.core.util.StrUtil; import com.google.common.collect.Lists; @@ -120,38 +117,6 @@ public class WalletPayService { } - /** - * 退款 - */ - @Transactional(rollbackFor = Exception.class) - public void refund(PayRefundParam payRefundParam, List payRefundDetailParams) { - - // 获取钱包 - Wallet wallet = walletManager.findById(payRefundParam.getWalletId()).orElseThrow(WalletNotExistsException::new); - - // 计算总退款金额 - BigDecimal totalRefundAmount = payRefundDetailParams.stream() - .map(PayRefundDetailParam::getRefundAmount) - .reduce(BigDecimal.ZERO, BigDecimal::add); - - walletManager.increaseBalance(payRefundParam.getWalletId(), totalRefundAmount, null); - - for (PayRefundDetailParam payRefundDetailParam : payRefundDetailParams) { - - WalletLog walletLog = new WalletLog() - .setAmount(payRefundDetailParam.getRefundAmount()) - .setPaymentId(payRefundDetailParam.getPaymentId()) - .setWalletId(wallet.getId()) - .setUserId(wallet.getUserId()) - .setType(WalletCode.WALLET_LOG_REFUND) - .setRemark(String.format("钱包退款金额 %.2f ", payRefundDetailParam.getRefundAmount())) - .setOperationSource(WalletCode.OPERATION_SOURCE_ADMIN) - .setBusinessId(String.valueOf(payRefundDetailParam.getOrderId())); - // save log - walletLogRepository.save(walletLog); - } - } - /** * 取消支付并返还金额 */ diff --git a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/task/PaySyncTask.java b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/task/PaySyncTask.java index 40364de03326c52ebf621852867169283ebe4fc3..ace85ed8f81c5735cdb2f23c73fcb6a0d15299fc 100644 --- a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/task/PaySyncTask.java +++ b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/task/PaySyncTask.java @@ -24,4 +24,5 @@ public class PaySyncTask { // payRemoteSyncService.syncPayStatus(); } + } diff --git a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/utils/PayTypeNameUtil.java b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/utils/PayTypeNameUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..eeccd9f837d9f30c0408a0c7f6c3dfeb637cf96b --- /dev/null +++ b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/utils/PayTypeNameUtil.java @@ -0,0 +1,54 @@ +package cn.bootx.paymentcenter.utils; + +import cn.bootx.paymentcenter.code.pay.PayTypeCode; + +/** +* +* @author xxm +* @date 2021/2/25 +*/ +public interface PayTypeNameUtil { + + /** + * 获取支付类型名称 + */ + static String getPayTypeName(int paymentType) { + String paymentName; + switch (paymentType) { + case PayTypeCode.ALI_PAY: + paymentName = "支付宝"; + break; + case PayTypeCode.WECHAT_PAY: + paymentName = "微信"; + break; + case PayTypeCode.CASH: + paymentName = "现金"; + break; + case PayTypeCode.WALLET: + paymentName = "钱包"; + break; + case PayTypeCode.POINT: + paymentName = "积分"; + break; + case PayTypeCode.CREDIT: + paymentName = "代金券"; + break; + case PayTypeCode.VOUCHER: + paymentName = "兑换券"; + break; + case PayTypeCode.CREDIT_CARD: + paymentName = "信用卡"; + break; + case PayTypeCode.APPLE_PAY: + paymentName = "Apple Pay"; + break; + case PayTypeCode.CHANNEL_PAY: + paymentName = "渠道方支付"; + break; + default: + paymentName = "未知方式"; + break; + } + return paymentName; + } +} diff --git a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/utils/RequestUtil.java b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/utils/RequestUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..cf2d211270a3871b509176dc40dfa6eaca3df6c2 --- /dev/null +++ b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/utils/RequestUtil.java @@ -0,0 +1,83 @@ +package cn.bootx.paymentcenter.utils; + +import cn.hutool.core.util.StrUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.servlet.http.HttpServletRequest; + +/** +* 请求工具类 +* @author xxm +* @date 2021/3/18 +*/ +public class RequestUtil { + + private static final Logger LOGGER = LoggerFactory.getLogger(RequestUtil.class); + + private RequestUtil() { + // do nothing + } + + /** + * 获取请求头信息 + */ + private static final String IP = "source_ip"; + private static final String AGENT = "source_agent"; + private static final String UNKNOW = "unknown"; + private static final String X_FORWARDED_FOR = "x-forwarded-for"; + private static final String PROXY_CLIENT_IP = "Proxy-Client-IP"; + private static final String WL_PROXY_CLIENT_IP = "WL-Proxy-Client-IP"; + private static final String HTTP_CLIENT_IP = "HTTP_CLIENT_IP"; + private static final String HTTP_X_FORWARDED_FOR = "HTTP_X_FORWARDED_FOR"; + private static final String SPLIT = ","; + + public static String analyzeIpAddress(HttpServletRequest request) { + + if (StrUtil.isNotBlank(request.getParameter(IP))) { + return request.getParameter(IP); + } + + String ip = request.getHeader(X_FORWARDED_FOR); + if (ip == null || ip.length() == 0 || UNKNOW.equalsIgnoreCase(ip)) { + ip = request.getHeader(PROXY_CLIENT_IP); + } + if (ip == null || ip.length() == 0 || UNKNOW.equalsIgnoreCase(ip)) { + ip = request.getHeader(WL_PROXY_CLIENT_IP); + } + if (ip == null || ip.length() == 0 || UNKNOW.equalsIgnoreCase(ip)) { + ip = request.getHeader(HTTP_CLIENT_IP); + } + if (ip == null || ip.length() == 0 || UNKNOW.equalsIgnoreCase(ip)) { + ip = request.getHeader(HTTP_X_FORWARDED_FOR); + } + if (ip == null || ip.length() == 0 || UNKNOW.equalsIgnoreCase(ip)) { + ip = request.getRemoteAddr(); + } + + if (ip.contains(SPLIT)) { + ip = ip.split(SPLIT)[0]; + } + return ip; + } + + private static final String USER_AGENT = "User-Agent"; + + public static String analyzeUserAgent(HttpServletRequest request) { + + if (StrUtil.isNotBlank(request.getParameter(AGENT))) { + return request.getParameter(AGENT); + } + return request.getHeader(USER_AGENT); + } + + private static final String USER_CLIENT= "userClient"; + + public static String analyzeUserClient(HttpServletRequest request) { + + if (StrUtil.isNotBlank(request.getParameter(USER_CLIENT))) { + return request.getParameter(USER_CLIENT); + } + return ""; + } +}