From 6880fc0c1987744011f6ea8f54044ebe5c52bcdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9B=9B=E5=8F=B6=E8=8D=89?= <362692680@qq.com> Date: Thu, 24 Mar 2022 09:45:27 +0000 Subject: [PATCH 01/46] =?UTF-8?q?update=20yudao-ui-admin/src/views/bpm/mod?= =?UTF-8?q?el/modelEditor.vue.=20=E9=BB=98=E8=AE=A4=E6=B5=81=E7=A8=8B?= =?UTF-8?q?=E5=BC=95=E6=93=8Eflowable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-ui-admin/src/views/bpm/model/modelEditor.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yudao-ui-admin/src/views/bpm/model/modelEditor.vue b/yudao-ui-admin/src/views/bpm/model/modelEditor.vue index f6b8183ffc..19413d0408 100644 --- a/yudao-ui-admin/src/views/bpm/model/modelEditor.vue +++ b/yudao-ui-admin/src/views/bpm/model/modelEditor.vue @@ -39,7 +39,7 @@ export default { simulation: true, labelEditing: false, labelVisible: false, - prefix: "activiti", + prefix: "flowable", headerButtonSize: "mini", additionalModel: [CustomContentPadProvider, CustomPaletteProvider] }, From 3cd135850ec0f6d5d43027870de03a2b191388e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=89=E8=B4=9E?= Date: Wed, 30 Mar 2022 17:21:24 +0800 Subject: [PATCH 02/46] =?UTF-8?q?=E6=96=B0=E5=BB=BA=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E5=85=B3=E8=81=94=E8=A1=A8=E7=BB=B4=E6=8A=A4=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=B2=97=E4=BD=8D=E5=85=B3=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/ruoyi-vue-pro.sql | 19 ++++++ .../dal/dataobject/dept/UserPostDO.java | 35 +++++++++++ .../system/dal/mysql/dept/UserPostMapper.java | 10 ++++ .../dal/mysql/user/AdminUserMapper.java | 3 + .../system/service/dept/UserPostService.java | 16 +++++ .../service/dept/UserPostServiceImpl.java | 19 ++++++ .../service/user/AdminUserServiceImpl.java | 58 +++++++++++++++++-- 7 files changed, 154 insertions(+), 6 deletions(-) create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/dept/UserPostDO.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/UserPostMapper.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/dept/UserPostService.java create mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/dept/UserPostServiceImpl.java diff --git a/sql/ruoyi-vue-pro.sql b/sql/ruoyi-vue-pro.sql index 96183a703a..cee359d62e 100644 --- a/sql/ruoyi-vue-pro.sql +++ b/sql/ruoyi-vue-pro.sql @@ -2414,6 +2414,25 @@ CREATE TABLE `pay_refund` ( BEGIN; COMMIT; + +-- ---------------------------- +-- Table structure for system_user_post +-- ---------------------------- +DROP TABLE IF EXISTS `system_user_post`; +CREATE TABLE `system_user_post` ( + `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'id', + `user_id` bigint NOT NULL DEFAULT '0' COMMENT '用户ID', + `post_id` bigint NOT NULL DEFAULT '0' COMMENT '岗位ID', + `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '创建者', + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '更新者', + `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', + `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', + `tenant_id` bigint NOT NULL DEFAULT '0' COMMENT '租户编号', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB AUTO_INCREMENT=112 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='部门表'; + + -- ---------------------------- -- Table structure for system_dept -- ---------------------------- diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/dept/UserPostDO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/dept/UserPostDO.java new file mode 100644 index 0000000000..02401977ee --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/dept/UserPostDO.java @@ -0,0 +1,35 @@ +package cn.iocoder.yudao.module.system.dal.dataobject.dept; + +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import com.baomidou.mybatisplus.annotation.DbType; +import com.baomidou.mybatisplus.annotation.KeySequence; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 用户和岗位关联 + * + * @author ruoyi + */ +@TableName("system_user_post") +@Data +@EqualsAndHashCode(callSuper = true) +public class UserPostDO extends BaseDO { + + /** + * 自增主键 + */ + @TableId + private Long id; + /** + * 用户 ID + */ + private Long userId; + /** + * 角色 ID + */ + private Long postId; + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/UserPostMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/UserPostMapper.java new file mode 100644 index 0000000000..0e9345a861 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/UserPostMapper.java @@ -0,0 +1,10 @@ +package cn.iocoder.yudao.module.system.dal.mysql.dept; + +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.system.dal.dataobject.dept.UserPostDO; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface UserPostMapper extends BaseMapperX { + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/user/AdminUserMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/user/AdminUserMapper.java index be4b5ea218..68acb7dcd3 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/user/AdminUserMapper.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/user/AdminUserMapper.java @@ -61,5 +61,8 @@ public interface AdminUserMapper extends BaseMapperX { return selectList(AdminUserDO::getDeptId, deptIds); } + default List selectListByIds(List userIdList) { + return selectList(new LambdaQueryWrapperX().in(AdminUserDO::getId, userIdList)); + } } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/dept/UserPostService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/dept/UserPostService.java new file mode 100644 index 0000000000..4299c5cbe2 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/dept/UserPostService.java @@ -0,0 +1,16 @@ +package cn.iocoder.yudao.module.system.service.dept; + +import cn.iocoder.yudao.module.system.dal.dataobject.dept.UserPostDO; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 工作流的表单定义 Mapper 接口 + *

+ * + * @author anzhen + * @since 2022-03-03 + */ +public interface UserPostService extends IService { + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/dept/UserPostServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/dept/UserPostServiceImpl.java new file mode 100644 index 0000000000..5be2e17d08 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/dept/UserPostServiceImpl.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.system.service.dept; + +import cn.iocoder.yudao.module.system.dal.dataobject.dept.UserPostDO; +import cn.iocoder.yudao.module.system.dal.mysql.dept.UserPostMapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +/** + *

+ * 工作流的表单定义 Mapper 接口 + *

+ * + * @author anzhen + * @since 2022-03-03 + */ +@Service +public class UserPostServiceImpl extends ServiceImpl implements UserPostService { + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java index 32f0a8e8cb..6457e84e86 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java @@ -13,12 +13,15 @@ import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfi import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.*; import cn.iocoder.yudao.module.system.convert.user.UserConvert; import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; +import cn.iocoder.yudao.module.system.dal.dataobject.dept.UserPostDO; import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; import cn.iocoder.yudao.module.system.dal.mysql.user.AdminUserMapper; import cn.iocoder.yudao.module.system.service.dept.DeptService; import cn.iocoder.yudao.module.system.service.dept.PostService; +import cn.iocoder.yudao.module.system.service.dept.UserPostService; import cn.iocoder.yudao.module.system.service.permission.PermissionService; import cn.iocoder.yudao.module.system.service.tenant.TenantService; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.google.common.annotations.VisibleForTesting; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; @@ -29,6 +32,7 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.io.InputStream; import java.util.*; +import java.util.stream.Collectors; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; @@ -59,11 +63,14 @@ public class AdminUserServiceImpl implements AdminUserService { @Resource private TenantService tenantService; + @Resource + private UserPostService userPostService; + @Resource private FileApi fileApi; @Override - + @Transactional(rollbackFor = Exception.class) public Long createUser(UserCreateReqVO reqVO) { // 校验账户配合 tenantService.handleTenantInfo(tenant -> { @@ -80,10 +87,22 @@ public class AdminUserServiceImpl implements AdminUserService { user.setStatus(CommonStatusEnum.ENABLE.getStatus()); // 默认开启 user.setPassword(passwordEncoder.encode(reqVO.getPassword())); // 加密密码 userMapper.insert(user); + Set postIds = user.getPostIds(); + if (!org.springframework.util.CollectionUtils.isEmpty(postIds)) { + ArrayList userPostList = new ArrayList<>(); + for (Long postId : postIds) { + UserPostDO entity = new UserPostDO(); + entity.setUserId(entity.getUserId()); + entity.setPostId(postId); + userPostList.add(entity); + } + userPostService.saveBatch(userPostList); + } return user.getId(); } @Override + @Transactional(rollbackFor = Exception.class) public void updateUser(UserUpdateReqVO reqVO) { // 校验正确性 this.checkCreateOrUpdate(reqVO.getId(), reqVO.getUsername(), reqVO.getMobile(), reqVO.getEmail(), @@ -91,6 +110,19 @@ public class AdminUserServiceImpl implements AdminUserService { // 更新用户 AdminUserDO updateObj = UserConvert.INSTANCE.convert(reqVO); userMapper.updateById(updateObj); + Set postIds = updateObj.getPostIds(); + if (!org.springframework.util.CollectionUtils.isEmpty(postIds)) { + for (Long postId : postIds) { + UserPostDO entity = new UserPostDO(); + entity.setUserId(reqVO.getId()); + entity.setPostId(postId); + userPostService.saveOrUpdate(entity, + Wrappers.lambdaUpdate(UserPostDO.class) + .eq(UserPostDO::getUserId, entity.getUserId()) + .eq(UserPostDO::getPostId, entity.getPostId()) + ); + } + } } @Override @@ -154,6 +186,7 @@ public class AdminUserServiceImpl implements AdminUserService { } @Override + @Transactional(rollbackFor = Exception.class) public void deleteUser(Long id) { // 校验用户存在 this.checkUserExists(id); @@ -161,6 +194,8 @@ public class AdminUserServiceImpl implements AdminUserService { userMapper.deleteById(id); // 删除用户关联数据 permissionService.processUserDeleted(id); + + userPostService.remove(Wrappers.lambdaUpdate(UserPostDO.class).eq(UserPostDO::getUserId, id)); } @Override @@ -191,11 +226,22 @@ public class AdminUserServiceImpl implements AdminUserService { if (CollUtil.isEmpty(postIds)) { return Collections.emptyList(); } - // 过滤不符合条件的 - // TODO 芋艿:暂时只能内存过滤。解决方案:1、新建一个关联表;2、基于 where + 函数;3、json 字段,适合 mysql 8+ 版本 - List users = userMapper.selectList(); - users.removeIf(user -> !CollUtil.containsAny(user.getPostIds(), postIds)); - return users; + List userIdList = userPostService + .lambdaQuery() + .in(UserPostDO::getPostId, postIds) + .list() + .stream() + .map(UserPostDO::getUserId) + .distinct() + .collect(Collectors.toList()); + if (userIdList.isEmpty()) { + return Collections.emptyList(); + } + return userMapper + .selectListByIds(userIdList) + .stream() + .peek(user -> user.setPassword(null)) + .collect(Collectors.toList()); } @Override From 5fc1101900cf929d1dde909254ac469610126db7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=89=E8=B4=9E?= Date: Thu, 31 Mar 2022 09:11:02 +0800 Subject: [PATCH 03/46] =?UTF-8?q?1=E3=80=81=E5=85=B3=E8=81=94=E8=A1=A8?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E9=A2=9D=E5=A4=96=E7=9A=84service=E3=80=82?= =?UTF-8?q?=202=E3=80=81service=E4=B8=AD=E5=88=A0=E9=99=A4mybatis=20plus?= =?UTF-8?q?=20=E7=9A=84=E6=93=8D=E4=BD=9C=EF=BC=8C=E6=8A=80=E6=9C=AF?= =?UTF-8?q?=E5=92=8C=E4=B8=9A=E5=8A=A1=E8=A7=A3=E8=80=A6=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/dal/mysql/dept/UserPostMapper.java | 43 ++++++++++ .../system/service/dept/UserPostService.java | 16 ---- .../service/dept/UserPostServiceImpl.java | 19 ---- .../service/user/AdminUserServiceImpl.java | 86 +++++++++++-------- .../src/test/resources/sql/clean.sql | 1 + .../src/test/resources/sql/create_tables.sql | 14 +++ 6 files changed, 107 insertions(+), 72 deletions(-) delete mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/dept/UserPostService.java delete mode 100644 yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/dept/UserPostServiceImpl.java diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/UserPostMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/UserPostMapper.java index 0e9345a861..a5f1fce840 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/UserPostMapper.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/UserPostMapper.java @@ -1,10 +1,53 @@ package cn.iocoder.yudao.module.system.dal.mysql.dept; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.system.dal.dataobject.dept.UserPostDO; import org.apache.ibatis.annotations.Mapper; +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; + @Mapper public interface UserPostMapper extends BaseMapperX { + default List selectIdList(Long id) { + return selectList(new LambdaQueryWrapperX() + .eq(UserPostDO::getUserId, id) + .select(UserPostDO::getPostId) + ) + .stream() + .map(UserPostDO::getPostId) + .collect(Collectors.toList()); + + } + + default void insertList(Long userId, Collection createPostIds) { + List list = createPostIds + .stream() + .map(postId -> { + UserPostDO entity = new UserPostDO(); + entity.setUserId(userId); + entity.setPostId(postId); + return entity; + }) + .collect(Collectors.toList()); + insertBatch(list); + } + + default void deleteByUserAndPost(Long userId, Collection deletePostIds) { + delete(new LambdaQueryWrapperX() + .eq(UserPostDO::getUserId, userId) + .in(UserPostDO::getPostId, deletePostIds)); + } + + default List getUserIdByPostIds(Collection postIds) { + return selectList(new LambdaQueryWrapperX() + .in(UserPostDO::getPostId, postIds)) + .stream() + .map(UserPostDO::getUserId) + .distinct() + .collect(Collectors.toList()); + } } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/dept/UserPostService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/dept/UserPostService.java deleted file mode 100644 index 4299c5cbe2..0000000000 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/dept/UserPostService.java +++ /dev/null @@ -1,16 +0,0 @@ -package cn.iocoder.yudao.module.system.service.dept; - -import cn.iocoder.yudao.module.system.dal.dataobject.dept.UserPostDO; -import com.baomidou.mybatisplus.extension.service.IService; - -/** - *

- * 工作流的表单定义 Mapper 接口 - *

- * - * @author anzhen - * @since 2022-03-03 - */ -public interface UserPostService extends IService { - -} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/dept/UserPostServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/dept/UserPostServiceImpl.java deleted file mode 100644 index 5be2e17d08..0000000000 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/dept/UserPostServiceImpl.java +++ /dev/null @@ -1,19 +0,0 @@ -package cn.iocoder.yudao.module.system.service.dept; - -import cn.iocoder.yudao.module.system.dal.dataobject.dept.UserPostDO; -import cn.iocoder.yudao.module.system.dal.mysql.dept.UserPostMapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import org.springframework.stereotype.Service; - -/** - *

- * 工作流的表单定义 Mapper 接口 - *

- * - * @author anzhen - * @since 2022-03-03 - */ -@Service -public class UserPostServiceImpl extends ServiceImpl implements UserPostService { - -} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java index 6457e84e86..29b8426769 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.system.service.user; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.io.IoUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; @@ -10,15 +11,20 @@ import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.module.infra.api.file.FileApi; import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdatePasswordReqVO; import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.*; +import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserCreateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserExportReqVO; +import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserImportExcelVO; +import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserImportRespVO; +import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserPageReqVO; +import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserUpdateReqVO; import cn.iocoder.yudao.module.system.convert.user.UserConvert; import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; import cn.iocoder.yudao.module.system.dal.dataobject.dept.UserPostDO; import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; +import cn.iocoder.yudao.module.system.dal.mysql.dept.UserPostMapper; import cn.iocoder.yudao.module.system.dal.mysql.user.AdminUserMapper; import cn.iocoder.yudao.module.system.service.dept.DeptService; import cn.iocoder.yudao.module.system.service.dept.PostService; -import cn.iocoder.yudao.module.system.service.dept.UserPostService; import cn.iocoder.yudao.module.system.service.permission.PermissionService; import cn.iocoder.yudao.module.system.service.tenant.TenantService; import com.baomidou.mybatisplus.core.toolkit.Wrappers; @@ -31,15 +37,28 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.io.InputStream; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.stream.Collectors; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_COUNT_MAX; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_EMAIL_EXISTS; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_IMPORT_LIST_IS_EMPTY; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_IS_DISABLE; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_MOBILE_EXISTS; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_NOT_EXISTS; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_PASSWORD_FAILED; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_USERNAME_EXISTS; /** * 后台用户 Service 实现类 - * * @author 芋道源码 */ @Service("adminUserService") @@ -64,7 +83,7 @@ public class AdminUserServiceImpl implements AdminUserService { private TenantService tenantService; @Resource - private UserPostService userPostService; + private UserPostMapper userPostMapper; @Resource private FileApi fileApi; @@ -81,7 +100,7 @@ public class AdminUserServiceImpl implements AdminUserService { }); // 校验正确性 this.checkCreateOrUpdate(null, reqVO.getUsername(), reqVO.getMobile(), reqVO.getEmail(), - reqVO.getDeptId(), reqVO.getPostIds()); + reqVO.getDeptId(), reqVO.getPostIds()); // 插入用户 AdminUserDO user = UserConvert.INSTANCE.convert(reqVO); user.setStatus(CommonStatusEnum.ENABLE.getStatus()); // 默认开启 @@ -89,14 +108,14 @@ public class AdminUserServiceImpl implements AdminUserService { userMapper.insert(user); Set postIds = user.getPostIds(); if (!org.springframework.util.CollectionUtils.isEmpty(postIds)) { - ArrayList userPostList = new ArrayList<>(); + List userPostList = new ArrayList<>(); for (Long postId : postIds) { UserPostDO entity = new UserPostDO(); entity.setUserId(entity.getUserId()); entity.setPostId(postId); userPostList.add(entity); } - userPostService.saveBatch(userPostList); + userPostMapper.insertBatch(userPostList); } return user.getId(); } @@ -106,23 +125,25 @@ public class AdminUserServiceImpl implements AdminUserService { public void updateUser(UserUpdateReqVO reqVO) { // 校验正确性 this.checkCreateOrUpdate(reqVO.getId(), reqVO.getUsername(), reqVO.getMobile(), reqVO.getEmail(), - reqVO.getDeptId(), reqVO.getPostIds()); + reqVO.getDeptId(), reqVO.getPostIds()); // 更新用户 AdminUserDO updateObj = UserConvert.INSTANCE.convert(reqVO); userMapper.updateById(updateObj); + // 更新岗位 Set postIds = updateObj.getPostIds(); - if (!org.springframework.util.CollectionUtils.isEmpty(postIds)) { - for (Long postId : postIds) { - UserPostDO entity = new UserPostDO(); - entity.setUserId(reqVO.getId()); - entity.setPostId(postId); - userPostService.saveOrUpdate(entity, - Wrappers.lambdaUpdate(UserPostDO.class) - .eq(UserPostDO::getUserId, entity.getUserId()) - .eq(UserPostDO::getPostId, entity.getPostId()) - ); - } + Long userId = reqVO.getId(); + List dbPostIds = userPostMapper.selectIdList(userId); + // 计算新增和删除的岗位编号 + Collection createPostIds = CollUtil.subtract(postIds, dbPostIds); + Collection deletePostIds = CollUtil.subtract(dbPostIds, postIds); + // 执行新增和删除。对于已经授权的菜单,不用做任何处理 + if (!CollectionUtil.isEmpty(createPostIds)) { + userPostMapper.insertList(userId, createPostIds); } + if (!CollectionUtil.isEmpty(deletePostIds)) { + userPostMapper.deleteByUserAndPost(userId, deletePostIds); + } + } @Override @@ -194,8 +215,8 @@ public class AdminUserServiceImpl implements AdminUserService { userMapper.deleteById(id); // 删除用户关联数据 permissionService.processUserDeleted(id); - - userPostService.remove(Wrappers.lambdaUpdate(UserPostDO.class).eq(UserPostDO::getUserId, id)); + // 删除用户岗位 + userPostMapper.delete(Wrappers.lambdaUpdate(UserPostDO.class).eq(UserPostDO::getUserId, id)); } @Override @@ -226,14 +247,7 @@ public class AdminUserServiceImpl implements AdminUserService { if (CollUtil.isEmpty(postIds)) { return Collections.emptyList(); } - List userIdList = userPostService - .lambdaQuery() - .in(UserPostDO::getPostId, postIds) - .list() - .stream() - .map(UserPostDO::getUserId) - .distinct() - .collect(Collectors.toList()); + List userIdList = userPostMapper.getUserIdByPostIds(postIds); if (userIdList.isEmpty()) { return Collections.emptyList(); } @@ -289,7 +303,6 @@ public class AdminUserServiceImpl implements AdminUserService { /** * 获得部门条件:查询指定部门的子部门编号们,包括自身 - * * @param deptId 部门编号 * @return 部门编号集合 */ @@ -298,7 +311,7 @@ public class AdminUserServiceImpl implements AdminUserService { return Collections.emptySet(); } Set deptIds = CollectionUtils.convertSet(deptService.getDeptsByParentIdFromCache( - deptId, true), DeptDO::getId); + deptId, true), DeptDO::getId); deptIds.add(deptId); // 包括自身 return deptIds; } @@ -386,7 +399,6 @@ public class AdminUserServiceImpl implements AdminUserService { /** * 校验旧密码 - * * @param id 用户 id * @param oldPassword 旧密码 */ @@ -408,12 +420,12 @@ public class AdminUserServiceImpl implements AdminUserService { throw exception(USER_IMPORT_LIST_IS_EMPTY); } UserImportRespVO respVO = UserImportRespVO.builder().createUsernames(new ArrayList<>()) - .updateUsernames(new ArrayList<>()).failureUsernames(new LinkedHashMap<>()).build(); + .updateUsernames(new ArrayList<>()).failureUsernames(new LinkedHashMap<>()).build(); importUsers.forEach(importUser -> { // 校验,判断是否有不符合的原因 try { checkCreateOrUpdate(null, null, importUser.getMobile(), importUser.getEmail(), - importUser.getDeptId(), null); + importUser.getDeptId(), null); } catch (ServiceException ex) { respVO.getFailureUsernames().put(importUser.getUsername(), ex.getMessage()); return; @@ -422,7 +434,7 @@ public class AdminUserServiceImpl implements AdminUserService { AdminUserDO existUser = userMapper.selectByUsername(importUser.getUsername()); if (existUser == null) { userMapper.insert(UserConvert.INSTANCE.convert(importUser) - .setPassword(passwordEncoder.encode(userInitPassword))); // 设置默认密码 + .setPassword(passwordEncoder.encode(userInitPassword))); // 设置默认密码 respVO.getCreateUsernames().add(importUser.getUsername()); return; } diff --git a/yudao-module-system/yudao-module-system-impl/src/test/resources/sql/clean.sql b/yudao-module-system/yudao-module-system-impl/src/test/resources/sql/clean.sql index c709513b11..23e8cda253 100644 --- a/yudao-module-system/yudao-module-system-impl/src/test/resources/sql/clean.sql +++ b/yudao-module-system/yudao-module-system-impl/src/test/resources/sql/clean.sql @@ -4,6 +4,7 @@ DELETE FROM "system_role"; DELETE FROM "system_role_menu"; DELETE FROM "system_menu"; DELETE FROM "system_user_role"; +DELETE FROM "system_user_post"; DELETE FROM "system_dict_type"; DELETE FROM "system_user_session"; DELETE FROM "system_post"; diff --git a/yudao-module-system/yudao-module-system-impl/src/test/resources/sql/create_tables.sql b/yudao-module-system/yudao-module-system-impl/src/test/resources/sql/create_tables.sql index 5db3692e5a..cef6b1424f 100644 --- a/yudao-module-system/yudao-module-system-impl/src/test/resources/sql/create_tables.sql +++ b/yudao-module-system/yudao-module-system-impl/src/test/resources/sql/create_tables.sql @@ -145,6 +145,20 @@ CREATE TABLE IF NOT EXISTS "system_post" ( PRIMARY KEY ("id") ) COMMENT '岗位信息表'; +CREATE TABLE IF NOT EXISTS `system_user_post`( + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, + "user_id" bigint DEFAULT NULL, + "post_id" bigint DEFAULT NULL, + "creator" varchar(64) DEFAULT '', + "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updater" varchar(64) DEFAULT '', + "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + "deleted" bit NOT NULL DEFAULT FALSE, + "tenant_id" bigint not null default '0', + PRIMARY KEY (`id`) +) COMMENT ='部门表'; + + CREATE TABLE IF NOT EXISTS "system_notice" ( "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, "title" varchar(50) NOT NULL COMMENT '公告标题', From 78c132e68dd823bf059ae0fbe817eedeb22f619d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=89=E8=B4=9E?= Date: Thu, 31 Mar 2022 13:18:37 +0800 Subject: [PATCH 04/46] fix user id is null --- .../yudao/module/system/service/user/AdminUserServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java index 29b8426769..e651b1513e 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java @@ -111,7 +111,7 @@ public class AdminUserServiceImpl implements AdminUserService { List userPostList = new ArrayList<>(); for (Long postId : postIds) { UserPostDO entity = new UserPostDO(); - entity.setUserId(entity.getUserId()); + entity.setUserId(user.getId()); entity.setPostId(postId); userPostList.add(entity); } From 47447ded6b771894ab0e9e8c2ad4e4be248b0547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=89=E8=B4=9E?= Date: Wed, 6 Apr 2022 13:58:08 +0800 Subject: [PATCH 05/46] =?UTF-8?q?code=20review=20=E7=BC=96=E7=A0=81?= =?UTF-8?q?=E8=A7=84=E8=8C=83=E7=BB=9F=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/dal/mysql/dept/UserPostMapper.java | 37 ++++---------- .../dal/mysql/user/AdminUserMapper.java | 3 -- .../service/user/AdminUserServiceImpl.java | 51 +++++++++++++------ 3 files changed, 45 insertions(+), 46 deletions(-) diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/UserPostMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/UserPostMapper.java index a5f1fce840..f91ce2ef69 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/UserPostMapper.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/UserPostMapper.java @@ -3,51 +3,34 @@ package cn.iocoder.yudao.module.system.dal.mysql.dept; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.system.dal.dataobject.dept.UserPostDO; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import org.apache.ibatis.annotations.Mapper; import java.util.Collection; import java.util.List; -import java.util.stream.Collectors; @Mapper public interface UserPostMapper extends BaseMapperX { - default List selectIdList(Long id) { + default List selectIdList(Long id) { return selectList(new LambdaQueryWrapperX() .eq(UserPostDO::getUserId, id) - .select(UserPostDO::getPostId) - ) - .stream() - .map(UserPostDO::getPostId) - .collect(Collectors.toList()); + .select(UserPostDO::getPostId)); } - default void insertList(Long userId, Collection createPostIds) { - List list = createPostIds - .stream() - .map(postId -> { - UserPostDO entity = new UserPostDO(); - entity.setUserId(userId); - entity.setPostId(postId); - return entity; - }) - .collect(Collectors.toList()); - insertBatch(list); - } - - default void deleteByUserAndPost(Long userId, Collection deletePostIds) { + default void deleteByUserIdAndPostId(Long userId, Collection deletePostIds) { delete(new LambdaQueryWrapperX() .eq(UserPostDO::getUserId, userId) .in(UserPostDO::getPostId, deletePostIds)); } - default List getUserIdByPostIds(Collection postIds) { + default List selectUserIdByPostIds(Collection postIds) { return selectList(new LambdaQueryWrapperX() - .in(UserPostDO::getPostId, postIds)) - .stream() - .map(UserPostDO::getUserId) - .distinct() - .collect(Collectors.toList()); + .in(UserPostDO::getPostId, postIds)); + } + + default void deleteByUserId(Long userId){ + delete(Wrappers.lambdaUpdate(UserPostDO.class).eq(UserPostDO::getUserId, userId)); } } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/user/AdminUserMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/user/AdminUserMapper.java index 68acb7dcd3..be4b5ea218 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/user/AdminUserMapper.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/user/AdminUserMapper.java @@ -61,8 +61,5 @@ public interface AdminUserMapper extends BaseMapperX { return selectList(AdminUserDO::getDeptId, deptIds); } - default List selectListByIds(List userIdList) { - return selectList(new LambdaQueryWrapperX().in(AdminUserDO::getId, userIdList)); - } } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java index e651b1513e..5be5ff16f4 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java @@ -107,15 +107,14 @@ public class AdminUserServiceImpl implements AdminUserService { user.setPassword(passwordEncoder.encode(reqVO.getPassword())); // 加密密码 userMapper.insert(user); Set postIds = user.getPostIds(); - if (!org.springframework.util.CollectionUtils.isEmpty(postIds)) { - List userPostList = new ArrayList<>(); - for (Long postId : postIds) { + if (CollectionUtil.isNotEmpty(postIds)) { + List insertUserPostList = CollectionUtils.convertList(postIds, postId -> { UserPostDO entity = new UserPostDO(); entity.setUserId(user.getId()); entity.setPostId(postId); - userPostList.add(entity); - } - userPostMapper.insertBatch(userPostList); + return entity; + }); + userPostMapper.insertBatch(insertUserPostList); } return user.getId(); } @@ -130,20 +129,40 @@ public class AdminUserServiceImpl implements AdminUserService { AdminUserDO updateObj = UserConvert.INSTANCE.convert(reqVO); userMapper.updateById(updateObj); // 更新岗位 + updateUserPost(reqVO, updateObj); + + } + + private void updateUserPost(UserUpdateReqVO reqVO, AdminUserDO updateObj) { Set postIds = updateObj.getPostIds(); Long userId = reqVO.getId(); - List dbPostIds = userPostMapper.selectIdList(userId); + List dbPostIds = userPostMapper.selectIdList(userId) + .stream() + .map(UserPostDO::getPostId) + .collect(Collectors.toList()); // 计算新增和删除的岗位编号 Collection createPostIds = CollUtil.subtract(postIds, dbPostIds); Collection deletePostIds = CollUtil.subtract(dbPostIds, postIds); // 执行新增和删除。对于已经授权的菜单,不用做任何处理 if (!CollectionUtil.isEmpty(createPostIds)) { - userPostMapper.insertList(userId, createPostIds); + List list = createUserPost(userId, createPostIds); + userPostMapper.insertBatch(list); } if (!CollectionUtil.isEmpty(deletePostIds)) { - userPostMapper.deleteByUserAndPost(userId, deletePostIds); + userPostMapper.deleteByUserIdAndPostId(userId, deletePostIds); } + } + private List createUserPost(Long userId, Collection createPostIds) { + return createPostIds + .stream() + .map(postId -> { + UserPostDO entity = new UserPostDO(); + entity.setUserId(userId); + entity.setPostId(postId); + return entity; + }) + .collect(Collectors.toList()); } @Override @@ -216,7 +235,7 @@ public class AdminUserServiceImpl implements AdminUserService { // 删除用户关联数据 permissionService.processUserDeleted(id); // 删除用户岗位 - userPostMapper.delete(Wrappers.lambdaUpdate(UserPostDO.class).eq(UserPostDO::getUserId, id)); + userPostMapper.deleteByUserId(id); } @Override @@ -247,15 +266,15 @@ public class AdminUserServiceImpl implements AdminUserService { if (CollUtil.isEmpty(postIds)) { return Collections.emptyList(); } - List userIdList = userPostMapper.getUserIdByPostIds(postIds); + List userIdList = userPostMapper.selectUserIdByPostIds(postIds) + .stream() + .map(UserPostDO::getUserId) + .distinct() + .collect(Collectors.toList());; if (userIdList.isEmpty()) { return Collections.emptyList(); } - return userMapper - .selectListByIds(userIdList) - .stream() - .peek(user -> user.setPassword(null)) - .collect(Collectors.toList()); + return userMapper.selectBatchIds(userIdList); } @Override From 17167c24d17647c0facb070b3cc741a34629ab43 Mon Sep 17 00:00:00 2001 From: anzhen Date: Fri, 15 Apr 2022 15:56:47 +0800 Subject: [PATCH 06/46] =?UTF-8?q?code=20review=20=E7=BC=96=E7=A0=81?= =?UTF-8?q?=E8=A7=84=E8=8C=83=E7=BB=9F=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/ruoyi-vue-pro.sql | 6 ++++-- .../module/system/dal/mysql/dept/UserPostMapper.java | 10 ++++------ .../system/service/user/AdminUserServiceImpl.java | 3 +-- .../src/test/resources/sql/create_tables.sql | 2 +- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/sql/ruoyi-vue-pro.sql b/sql/ruoyi-vue-pro.sql index cee359d62e..1276115db6 100644 --- a/sql/ruoyi-vue-pro.sql +++ b/sql/ruoyi-vue-pro.sql @@ -2430,8 +2430,10 @@ CREATE TABLE `system_user_post` ( `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', `tenant_id` bigint NOT NULL DEFAULT '0' COMMENT '租户编号', PRIMARY KEY (`id`) USING BTREE -) ENGINE=InnoDB AUTO_INCREMENT=112 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='部门表'; - +) ENGINE=InnoDB AUTO_INCREMENT=112 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='用户岗位表'; +insert into system_user_post (user_id, post_id, creator, create_time, updater, update_time, deleted, tenant_id) value (1,1,'admin',current_timestamp,'admin',current_timestamp,false,1); +insert into system_user_post (user_id, post_id, creator, create_time, updater, update_time, deleted, tenant_id) value (100,1,'admin',current_timestamp,'admin',current_timestamp,false,1); +insert into system_user_post (user_id, post_id, creator, create_time, updater, update_time, deleted, tenant_id) value (114,3,'admin',current_timestamp,'admin',current_timestamp,false,1); -- ---------------------------- -- Table structure for system_dept diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/UserPostMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/UserPostMapper.java index f91ce2ef69..cf81124851 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/UserPostMapper.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/UserPostMapper.java @@ -14,18 +14,16 @@ public interface UserPostMapper extends BaseMapperX { default List selectIdList(Long id) { return selectList(new LambdaQueryWrapperX() - .eq(UserPostDO::getUserId, id) - .select(UserPostDO::getPostId)); - + .eq(UserPostDO::getUserId, id)); } - default void deleteByUserIdAndPostId(Long userId, Collection deletePostIds) { + default void deleteByUserIdAndPostId(Long userId, Collection postIds) { delete(new LambdaQueryWrapperX() .eq(UserPostDO::getUserId, userId) - .in(UserPostDO::getPostId, deletePostIds)); + .in(UserPostDO::getPostId, postIds)); } - default List selectUserIdByPostIds(Collection postIds) { + default List selectListByPostIds(Collection postIds) { return selectList(new LambdaQueryWrapperX() .in(UserPostDO::getPostId, postIds)); } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java index 5be5ff16f4..b90d5cf739 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java @@ -27,7 +27,6 @@ import cn.iocoder.yudao.module.system.service.dept.DeptService; import cn.iocoder.yudao.module.system.service.dept.PostService; import cn.iocoder.yudao.module.system.service.permission.PermissionService; import cn.iocoder.yudao.module.system.service.tenant.TenantService; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.google.common.annotations.VisibleForTesting; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; @@ -266,7 +265,7 @@ public class AdminUserServiceImpl implements AdminUserService { if (CollUtil.isEmpty(postIds)) { return Collections.emptyList(); } - List userIdList = userPostMapper.selectUserIdByPostIds(postIds) + List userIdList = userPostMapper.selectListByPostIds(postIds) .stream() .map(UserPostDO::getUserId) .distinct() diff --git a/yudao-module-system/yudao-module-system-impl/src/test/resources/sql/create_tables.sql b/yudao-module-system/yudao-module-system-impl/src/test/resources/sql/create_tables.sql index cef6b1424f..a3097b3ec9 100644 --- a/yudao-module-system/yudao-module-system-impl/src/test/resources/sql/create_tables.sql +++ b/yudao-module-system/yudao-module-system-impl/src/test/resources/sql/create_tables.sql @@ -156,7 +156,7 @@ CREATE TABLE IF NOT EXISTS `system_user_post`( "deleted" bit NOT NULL DEFAULT FALSE, "tenant_id" bigint not null default '0', PRIMARY KEY (`id`) -) COMMENT ='部门表'; +) COMMENT ='用户岗位表'; CREATE TABLE IF NOT EXISTS "system_notice" ( From 4a91dcb3bf798c881963383915396dbce1160dbf Mon Sep 17 00:00:00 2001 From: zwy Date: Tue, 19 Apr 2022 15:23:11 +0800 Subject: [PATCH 07/46] =?UTF-8?q?:sparkles:=20=E3=80=90=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E3=80=91=20=E6=B7=BB=E5=8A=A0=20=E5=BE=AE?= =?UTF-8?q?=E4=BF=A1native=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client/impl/PayClientFactoryImpl.java | 2 + .../client/impl/wx/WXNativePayClient.java | 146 ++++++++++++++++++ .../pay/core/enums/PayChannelEnum.java | 2 + 3 files changed, 150 insertions(+) create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXNativePayClient.java diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/PayClientFactoryImpl.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/PayClientFactoryImpl.java index 647152196b..ffe40bc3d3 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/PayClientFactoryImpl.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/PayClientFactoryImpl.java @@ -7,6 +7,7 @@ import cn.iocoder.yudao.framework.pay.core.client.PayClientFactory; import cn.iocoder.yudao.framework.pay.core.client.impl.alipay.AlipayPayClientConfig; import cn.iocoder.yudao.framework.pay.core.client.impl.alipay.AlipayQrPayClient; import cn.iocoder.yudao.framework.pay.core.client.impl.alipay.AlipayWapPayClient; +import cn.iocoder.yudao.framework.pay.core.client.impl.wx.WXNativePayClient; import cn.iocoder.yudao.framework.pay.core.client.impl.wx.WXPayClientConfig; import cn.iocoder.yudao.framework.pay.core.client.impl.wx.WXPubPayClient; import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum; @@ -63,6 +64,7 @@ public class PayClientFactoryImpl implements PayClientFactory { case WX_PUB: return (AbstractPayClient) new WXPubPayClient(channelId, (WXPayClientConfig) config); case WX_LITE: return (AbstractPayClient) new WXPubPayClient(channelId, (WXPayClientConfig) config); case WX_APP: return (AbstractPayClient) new WXPubPayClient(channelId, (WXPayClientConfig) config); + case WX_NATIVE: return (AbstractPayClient) new WXNativePayClient(channelId, (WXPayClientConfig) config); case ALIPAY_WAP: return (AbstractPayClient) new AlipayWapPayClient(channelId, (AlipayPayClientConfig) config); case ALIPAY_QR: return (AbstractPayClient) new AlipayQrPayClient(channelId, (AlipayPayClientConfig) config); case ALIPAY_APP: return (AbstractPayClient) new AlipayQrPayClient(channelId, (AlipayPayClientConfig) config); diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXNativePayClient.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXNativePayClient.java new file mode 100644 index 0000000000..87fa69645e --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXNativePayClient.java @@ -0,0 +1,146 @@ +package cn.iocoder.yudao.framework.pay.core.client.impl.wx; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.lang.Assert; +import cn.hutool.core.util.StrUtil; +import cn.iocoder.yudao.framework.common.util.io.FileUtils; +import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; +import cn.iocoder.yudao.framework.pay.core.client.PayCommonResult; +import cn.iocoder.yudao.framework.pay.core.client.dto.*; +import cn.iocoder.yudao.framework.pay.core.client.impl.AbstractPayClient; +import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum; +import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult; +import com.github.binarywang.wxpay.bean.order.WxPayNativeOrderResult; +import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest; +import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderV3Request; +import com.github.binarywang.wxpay.bean.result.enums.TradeTypeEnum; +import com.github.binarywang.wxpay.config.WxPayConfig; +import com.github.binarywang.wxpay.constant.WxPayConstants; +import com.github.binarywang.wxpay.exception.WxPayException; +import com.github.binarywang.wxpay.service.WxPayService; +import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl; +import lombok.extern.slf4j.Slf4j; + +import java.util.Objects; + +import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString; +import static cn.iocoder.yudao.framework.pay.core.client.impl.wx.WXCodeMapping.CODE_SUCCESS; +import static cn.iocoder.yudao.framework.pay.core.client.impl.wx.WXCodeMapping.MESSAGE_SUCCESS; + +/** + * @Description: Native支付 + * @author: zwy + * @date: 2022年04月18日 17:00 + */ +@Slf4j +public class WXNativePayClient extends AbstractPayClient { + private WxPayService client; + + public WXNativePayClient(Long channelId, WXPayClientConfig config) { + super(channelId, PayChannelEnum.WX_PUB.getCode(), config, new WXCodeMapping()); + } + + @Override + protected void doInit() { + WxPayConfig payConfig = new WxPayConfig(); + BeanUtil.copyProperties(config, payConfig, "keyContent"); + payConfig.setTradeType(WxPayConstants.TradeType.JSAPI); // 设置使用 JS API 支付方式 +// if (StrUtil.isNotEmpty(config.getKeyContent())) { +// payConfig.setKeyContent(config.getKeyContent().getBytes(StandardCharsets.UTF_8)); +// } + if (StrUtil.isNotEmpty(config.getPrivateKeyContent())) { + // weixin-pay-java 存在 BUG,无法直接设置内容,所以创建临时文件来解决 + payConfig.setPrivateKeyPath(FileUtils.createTempFile(config.getPrivateKeyContent()).getPath()); + } + if (StrUtil.isNotEmpty(config.getPrivateCertContent())) { + // weixin-pay-java 存在 BUG,无法直接设置内容,所以创建临时文件来解决 + payConfig.setPrivateCertPath(FileUtils.createTempFile(config.getPrivateCertContent()).getPath()); + } + // 真实客户端 + this.client = new WxPayServiceImpl(); + client.setConfig(payConfig); + } + + @Override + public PayCommonResult doUnifiedOrder(PayOrderUnifiedReqDTO reqDTO) { + // 这里原生的返回的是支付的 url 所以直接使用string接收 + //"invokeResponse": "weixin://wxpay/bizpayurl?pr=EGYAem7zz" + String responseV3; + try { + switch (config.getApiVersion()) { + case WXPayClientConfig.API_VERSION_V2: + responseV3 = unifiedOrderV2(reqDTO).getCodeUrl(); + break; + case WXPayClientConfig.API_VERSION_V3: + responseV3 = this.unifiedOrderV3(reqDTO); + break; + default: + throw new IllegalArgumentException(String.format("未知的 API 版本(%s)", config.getApiVersion())); + } + } catch (WxPayException e) { + log.error("[unifiedOrder][request({}) 发起支付失败,原因({})]", toJsonString(reqDTO), e); + return PayCommonResult.build(ObjectUtils.defaultIfNull(e.getErrCode(), e.getReturnCode(), "CustomErrorCode"), + ObjectUtils.defaultIfNull(e.getErrCodeDes(), e.getCustomErrorMsg()), null, codeMapping); + } + return PayCommonResult.build(CODE_SUCCESS, MESSAGE_SUCCESS, responseV3, codeMapping); + } + + private WxPayNativeOrderResult unifiedOrderV2(PayOrderUnifiedReqDTO reqDTO) throws WxPayException { + //前端 + String trade_type = reqDTO.getChannelExtras().get("trade_type"); + // 构建 WxPayUnifiedOrderRequest 对象 + WxPayUnifiedOrderRequest request = WxPayUnifiedOrderRequest + .newBuilder() + .outTradeNo(reqDTO.getMerchantOrderId()) + .body(reqDTO.getBody()) + .totalFee(reqDTO.getAmount().intValue()) // 单位分 +// .timeExpire(DateUtil.format(reqDTO.getExpireTime(), "yyyyMMddHHmmss")) + .spbillCreateIp(reqDTO.getUserIp()) + .tradeType(WxPayConstants.TradeType.NATIVE) + .notifyUrl(reqDTO.getNotifyUrl()) + .productId(trade_type) + .build(); + // 执行请求 + return client.createOrder(request); + } + + private String unifiedOrderV3(PayOrderUnifiedReqDTO reqDTO) throws WxPayException { + // 构建 WxPayUnifiedOrderRequest 对象 + WxPayUnifiedOrderV3Request request = new WxPayUnifiedOrderV3Request(); + request.setOutTradeNo(reqDTO.getMerchantOrderId()); + request.setDescription(reqDTO.getBody()); + request.setAmount(new WxPayUnifiedOrderV3Request.Amount().setTotal(reqDTO.getAmount().intValue())); // 单位分 + request.setSceneInfo(new WxPayUnifiedOrderV3Request.SceneInfo().setPayerClientIp(reqDTO.getUserIp())); + request.setNotifyUrl(reqDTO.getNotifyUrl()); + // 执行请求 +// log.info("支付字段request:{}",request.getTimeExpire()); + + return client.createOrderV3(TradeTypeEnum.NATIVE, request); + } + + + @Override + public PayOrderNotifyRespDTO parseOrderNotify(PayNotifyDataDTO data) throws WxPayException { + WxPayOrderNotifyResult notifyResult = client.parseOrderNotifyResult(data.getBody()); + Assert.isTrue(Objects.equals(notifyResult.getResultCode(), "SUCCESS"), "支付结果非 SUCCESS"); + // 转换结果 + return PayOrderNotifyRespDTO.builder().orderExtensionNo(notifyResult.getOutTradeNo()) + .channelOrderNo(notifyResult.getTransactionId()).channelUserId(notifyResult.getOpenid()) + .successTime(DateUtil.parse(notifyResult.getTimeEnd(), "yyyyMMddHHmmss")) + .data(data.getBody()).build(); + } + + @Override + public PayRefundNotifyDTO parseRefundNotify(PayNotifyDataDTO notifyData) { + //TODO 需要实现 + throw new UnsupportedOperationException("需要实现"); + } + + + @Override + protected PayCommonResult doUnifiedRefund(PayRefundUnifiedReqDTO reqDTO) throws Throwable { + //TODO 需要实现 + throw new UnsupportedOperationException(); + } +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/enums/PayChannelEnum.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/enums/PayChannelEnum.java index fccbab84b1..a708faf8ea 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/enums/PayChannelEnum.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/enums/PayChannelEnum.java @@ -20,6 +20,8 @@ public enum PayChannelEnum { WX_PUB("wx_pub", "微信 JSAPI 支付", WXPayClientConfig.class), // 公众号网页 WX_LITE("wx_lite", "微信小程序支付", WXPayClientConfig.class), WX_APP("wx_app", "微信 App 支付", WXPayClientConfig.class), + WX_NATIVE("wx_native", "微信 native 支付", WXPayClientConfig.class), + ALIPAY_PC("alipay_pc", "支付宝 PC 网站支付", AlipayPayClientConfig.class), ALIPAY_WAP("alipay_wap", "支付宝 Wap 网站支付", AlipayPayClientConfig.class), From 29a384989b4dea2d52564a9a20098f96e4cd5754 Mon Sep 17 00:00:00 2001 From: zwy Date: Tue, 19 Apr 2022 17:38:43 +0800 Subject: [PATCH 08/46] =?UTF-8?q?:sparkles:=20=E3=80=90=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E3=80=91=20=E6=B7=BB=E5=8A=A0=20=E5=BE=AE?= =?UTF-8?q?=E4=BF=A1native=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/pay/core/client/impl/wx/WXNativePayClient.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXNativePayClient.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXNativePayClient.java index 87fa69645e..e6e5ed779e 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXNativePayClient.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXNativePayClient.java @@ -38,14 +38,14 @@ public class WXNativePayClient extends AbstractPayClient { private WxPayService client; public WXNativePayClient(Long channelId, WXPayClientConfig config) { - super(channelId, PayChannelEnum.WX_PUB.getCode(), config, new WXCodeMapping()); + super(channelId, PayChannelEnum.WX_NATIVE.getCode(), config, new WXCodeMapping()); } @Override protected void doInit() { WxPayConfig payConfig = new WxPayConfig(); BeanUtil.copyProperties(config, payConfig, "keyContent"); - payConfig.setTradeType(WxPayConstants.TradeType.JSAPI); // 设置使用 JS API 支付方式 + payConfig.setTradeType(WxPayConstants.TradeType.NATIVE); // 设置使用 native 支付方式 // if (StrUtil.isNotEmpty(config.getKeyContent())) { // payConfig.setKeyContent(config.getKeyContent().getBytes(StandardCharsets.UTF_8)); // } @@ -97,7 +97,6 @@ public class WXNativePayClient extends AbstractPayClient { .totalFee(reqDTO.getAmount().intValue()) // 单位分 // .timeExpire(DateUtil.format(reqDTO.getExpireTime(), "yyyyMMddHHmmss")) .spbillCreateIp(reqDTO.getUserIp()) - .tradeType(WxPayConstants.TradeType.NATIVE) .notifyUrl(reqDTO.getNotifyUrl()) .productId(trade_type) .build(); From d06ed39155e0f0add9ab2989d8d42289a747aec7 Mon Sep 17 00:00:00 2001 From: Hobo Date: Fri, 22 Apr 2022 16:49:58 +0800 Subject: [PATCH 09/46] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E7=94=9F=E6=88=90=E5=99=A8=E7=9A=84vue=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E4=B8=AD=EF=BC=8C=E5=AF=BC=E5=87=BA=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E3=80=90xxx.xls=E3=80=91=E6=97=B6=EF=BC=8C=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=90=8D=E4=B8=8D=E6=AD=A3=E7=A1=AE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/codegen/vue/views/index.vue.vm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yudao-module-infra/yudao-module-infra-impl/src/main/resources/codegen/vue/views/index.vue.vm b/yudao-module-infra/yudao-module-infra-impl/src/main/resources/codegen/vue/views/index.vue.vm index aac0c27b67..049c6c7827 100644 --- a/yudao-module-infra/yudao-module-infra-impl/src/main/resources/codegen/vue/views/index.vue.vm +++ b/yudao-module-infra/yudao-module-infra-impl/src/main/resources/codegen/vue/views/index.vue.vm @@ -390,7 +390,7 @@ export default { this.exportLoading = true; return export${simpleClassName}Excel(params); }).then(response => { - this.$download.excel(response, '${table.classComment}.xls'); + this.#[[$]]#download.excel(response, '${table.classComment}.xls'); this.exportLoading = false; }).catch(() => {}); } From c51bbb81b529de587f1722ccc83cf7c7e025e927 Mon Sep 17 00:00:00 2001 From: dearliuliu0522 Date: Sat, 23 Apr 2022 18:15:37 +0800 Subject: [PATCH 10/46] =?UTF-8?q?=E3=80=90=E4=BF=AE=E5=A4=8D=E3=80=91?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90=E5=AF=B9=E8=AF=9D=E6=A1=86?= =?UTF-8?q?=E7=9A=84=E6=97=A5=E6=9C=9F=E9=80=89=E6=8B=A9=E5=99=A8=EF=BC=8C?= =?UTF-8?q?=E5=9C=A8=E7=BC=96=E8=BE=91=E6=83=85=E5=86=B5=E4=B8=8B=E4=B8=8D?= =?UTF-8?q?=E8=83=BD=E5=9B=9E=E6=98=BE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/codegen/vue/views/index.vue.vm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue/views/index.vue.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue/views/index.vue.vm index aac0c27b67..2caafd9508 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue/views/index.vue.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue/views/index.vue.vm @@ -160,7 +160,7 @@ #elseif($column.htmlType == "datetime")## 时间框 - + #elseif($column.htmlType == "textarea")## 文本框 From 802a7b0a30b0327f446700df4a1dfaf04aabc064 Mon Sep 17 00:00:00 2001 From: zwy Date: Tue, 26 Apr 2022 16:47:06 +0800 Subject: [PATCH 11/46] =?UTF-8?q?:sparkles:=20=E3=80=90=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E3=80=91=20=E4=BF=AE=E6=94=B9=E6=97=B6?= =?UTF-8?q?=E9=97=B4=20=E6=A0=BC=E5=BC=8F=20yyyyMMddHHmmss=20=E4=B8=BA=20y?= =?UTF-8?q?yyy-MM-dd'T'HH:mm:ssXXX?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pay/core/client/impl/wx/WXNativePayClient.java | 10 +++------- .../pay/core/client/impl/wx/WXPubPayClient.java | 4 ++-- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXNativePayClient.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXNativePayClient.java index e6e5ed779e..f0074c0441 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXNativePayClient.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXNativePayClient.java @@ -28,11 +28,7 @@ import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString import static cn.iocoder.yudao.framework.pay.core.client.impl.wx.WXCodeMapping.CODE_SUCCESS; import static cn.iocoder.yudao.framework.pay.core.client.impl.wx.WXCodeMapping.MESSAGE_SUCCESS; -/** - * @Description: Native支付 - * @author: zwy - * @date: 2022年04月18日 17:00 - */ + @Slf4j public class WXNativePayClient extends AbstractPayClient { private WxPayService client; @@ -95,7 +91,7 @@ public class WXNativePayClient extends AbstractPayClient { .outTradeNo(reqDTO.getMerchantOrderId()) .body(reqDTO.getBody()) .totalFee(reqDTO.getAmount().intValue()) // 单位分 -// .timeExpire(DateUtil.format(reqDTO.getExpireTime(), "yyyyMMddHHmmss")) + .timeExpire(DateUtil.format(reqDTO.getExpireTime(), "yyyy-MM-dd'T'HH:mm:ssXXX")) .spbillCreateIp(reqDTO.getUserIp()) .notifyUrl(reqDTO.getNotifyUrl()) .productId(trade_type) @@ -126,7 +122,7 @@ public class WXNativePayClient extends AbstractPayClient { // 转换结果 return PayOrderNotifyRespDTO.builder().orderExtensionNo(notifyResult.getOutTradeNo()) .channelOrderNo(notifyResult.getTransactionId()).channelUserId(notifyResult.getOpenid()) - .successTime(DateUtil.parse(notifyResult.getTimeEnd(), "yyyyMMddHHmmss")) + .successTime(DateUtil.parse(notifyResult.getTimeEnd(), "yyyy-MM-dd'T'HH:mm:ssXXX")) .data(data.getBody()).build(); } diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXPubPayClient.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXPubPayClient.java index 5d5809ae3b..866405e795 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXPubPayClient.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXPubPayClient.java @@ -98,7 +98,7 @@ public class WXPubPayClient extends AbstractPayClient { // TODO 芋艿:貌似没 title? .body(reqDTO.getBody()) .totalFee(reqDTO.getAmount().intValue()) // 单位分 - .timeExpire(DateUtil.format(reqDTO.getExpireTime(), "yyyyMMddHHmmss")) + .timeExpire(DateUtil.format(reqDTO.getExpireTime(), "yyyy-MM-dd'T'HH:mm:ssXXX")) .spbillCreateIp(reqDTO.getUserIp()) .openid(getOpenid(reqDTO)) .notifyUrl(reqDTO.getNotifyUrl()) @@ -114,7 +114,7 @@ public class WXPubPayClient extends AbstractPayClient { // TODO 芋艿:貌似没 title? request.setDescription(reqDTO.getBody()); request.setAmount(new WxPayUnifiedOrderV3Request.Amount().setTotal(reqDTO.getAmount().intValue())); // 单位分 - request.setTimeExpire(DateUtil.format(reqDTO.getExpireTime(), "yyyyMMddHHmmss")); + request.setTimeExpire(DateUtil.format(reqDTO.getExpireTime(), "yyyy-MM-dd'T'HH:mm:ssXXX")); request.setPayer(new WxPayUnifiedOrderV3Request.Payer().setOpenid(getOpenid(reqDTO))); request.setSceneInfo(new WxPayUnifiedOrderV3Request.SceneInfo().setPayerClientIp(reqDTO.getUserIp())); request.setNotifyUrl(reqDTO.getNotifyUrl()); From 6505906565725d352c7e298f2a5dad8e472afef8 Mon Sep 17 00:00:00 2001 From: zwy Date: Tue, 26 Apr 2022 18:03:19 +0800 Subject: [PATCH 12/46] =?UTF-8?q?:bug:=20=E3=80=90=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E6=A8=A1=E5=9D=97BUG=E3=80=91=20=E4=BF=AE=E6=94=B9=E6=97=B6?= =?UTF-8?q?=E9=97=B4=20=E6=A0=BC=E5=BC=8F=20yyyyMMddHHmmss=20=E4=B8=BA=20y?= =?UTF-8?q?yyy-MM-dd'T'HH:mm:ssXXX?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 支付宝 获取支付回调对象 --- .../impl/alipay/AbstractAlipayClient.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AbstractAlipayClient.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AbstractAlipayClient.java index 7cb24145a8..913e29c50a 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AbstractAlipayClient.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AbstractAlipayClient.java @@ -18,6 +18,7 @@ import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import java.nio.charset.StandardCharsets; +import java.util.HashMap; import java.util.Map; import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString; @@ -54,7 +55,8 @@ public abstract class AbstractAlipayClient extends AbstractPayClient params = data.getParams(); + Map params = strToMap(data.getBody()); + return PayOrderNotifyRespDTO.builder().orderExtensionNo(params.get("out_trade_no")) .channelOrderNo(params.get("trade_no")).channelUserId(params.get("seller_id")) .tradeStatus(params.get("trade_status")) @@ -64,7 +66,7 @@ public abstract class AbstractAlipayClient extends AbstractPayClient params = notifyData.getParams(); + Map params = strToMap(notifyData.getBody()); PayRefundNotifyDTO notifyDTO = PayRefundNotifyDTO.builder().channelOrderNo(params.get("trade_no")) .tradeNo(params.get("out_trade_no")) .reqNo(params.get("out_biz_no")) @@ -128,4 +130,17 @@ public abstract class AbstractAlipayClient extends AbstractPayClient strToMap(String s) { + Map stringStringMap = new HashMap<>(); + //调整时间格式 + String s3 = s.replaceAll("%3A", ":"); + //获取map + String s4 = s3.replace("+", " "); + String[] split = s4.split("&"); + for (String s1 : split) { + String[] split1 = s1.split("="); + stringStringMap.put(split1[0], split1[1]); + } + return stringStringMap; + } } From 7227664f7796843589906354501a530fff07a20d Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 26 Apr 2022 23:36:26 +0800 Subject: [PATCH 13/46] =?UTF-8?q?=E8=BF=9B=E4=B8=80=E6=AD=A5=E9=87=8D?= =?UTF-8?q?=E6=9E=84=E7=A4=BE=E4=BA=A4=E7=99=BB=E9=99=86=E7=9A=84=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/YudaoSocialAutoConfiguration.java | 6 +++ .../controller/admin/auth/AuthController.java | 32 ++++---------- ...qVO.java => AuthSocialBindLoginReqVO.java} | 4 +- ...VO.java => AuthSocialQuickLoginReqVO.java} | 4 +- .../admin/socail/SocialUserController.java | 42 ++++++++++++++++++ .../user/vo/profile/UserProfileRespVO.java | 4 +- .../system/convert/auth/AuthConvert.java | 7 ++- .../convert/social/SocialUserConvert.java | 19 ++++++++ .../dataobject/social/SocialUserBindDO.java | 1 - .../config/SecurityConfiguration.java | 14 +++--- .../system/service/auth/AdminAuthService.java | 16 ++----- .../service/auth/AdminAuthServiceImpl.java | 37 ++++++---------- .../src/main/resources/application-dev.yaml | 4 -- .../src/main/resources/application-local.yaml | 4 -- yudao-ui-admin/src/api/login.js | 43 ++++--------------- yudao-ui-admin/src/api/menu.js | 2 +- yudao-ui-admin/src/api/system/socialUser.js | 26 +++++++++++ yudao-ui-admin/src/store/modules/user.js | 6 +-- yudao-ui-admin/src/utils/constants.js | 6 --- yudao-ui-admin/src/views/login.vue | 1 - .../views/system/user/profile/userSocial.vue | 11 ++--- 21 files changed, 155 insertions(+), 134 deletions(-) rename yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/vo/auth/{AuthSocialLogin2ReqVO.java => AuthSocialBindLoginReqVO.java} (92%) rename yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/vo/auth/{AuthSocialLoginReqVO.java => AuthSocialQuickLoginReqVO.java} (90%) create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/SocialUserController.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/social/SocialUserConvert.java create mode 100644 yudao-ui-admin/src/api/system/socialUser.js diff --git a/yudao-framework/yudao-spring-boot-starter-biz-social/src/main/java/cn/iocoder/yudao/framework/social/config/YudaoSocialAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-biz-social/src/main/java/cn/iocoder/yudao/framework/social/config/YudaoSocialAutoConfiguration.java index a6c468af50..fcae86c5e7 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-social/src/main/java/cn/iocoder/yudao/framework/social/config/YudaoSocialAutoConfiguration.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-social/src/main/java/cn/iocoder/yudao/framework/social/config/YudaoSocialAutoConfiguration.java @@ -1,6 +1,9 @@ package cn.iocoder.yudao.framework.social.config; +import cn.hutool.core.util.ReflectUtil; import cn.iocoder.yudao.framework.social.core.YudaoAuthRequestFactory; +import com.xkcoding.http.HttpUtil; +import com.xkcoding.http.support.hutool.HutoolImpl; import com.xkcoding.justauth.autoconfigure.JustAuthProperties; import lombok.extern.slf4j.Slf4j; import me.zhyd.oauth.cache.AuthStateCache; @@ -23,6 +26,9 @@ public class YudaoSocialAutoConfiguration { @Bean @ConditionalOnProperty(prefix = "justauth", value = "enabled", havingValue = "true", matchIfMissing = true) public YudaoAuthRequestFactory yudaoAuthRequestFactory(JustAuthProperties properties, AuthStateCache authStateCache) { + // 需要修改 HttpUtil 使用的实现,避免类报错 + HttpUtil.setHttp(new HutoolImpl()); + // 创建 YudaoAuthRequestFactory return new YudaoAuthRequestFactory(properties, authStateCache); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.java index fe31c20b4c..8cb7762817 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.java @@ -36,7 +36,7 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti @Api(tags = "管理后台 - 认证") @RestController -@RequestMapping("/system") // 暂时不跟 /auth 结尾 +@RequestMapping("/system/auth") // 暂时不跟 /auth 结尾 @Validated @Slf4j public class AuthController { @@ -80,7 +80,7 @@ public class AuthController { return success(AuthConvert.INSTANCE.convert(user, roleList, menuList)); } - @GetMapping("list-menus") + @GetMapping("/list-menus") @ApiOperation("获得登录用户的菜单列表") public CommonResult> getMenus() { // 获得用户拥有的菜单列表 @@ -105,36 +105,22 @@ public class AuthController { return CommonResult.success(socialUserService.getAuthorizeUrl(type, redirectUri)); } - @PostMapping("/social-login") - @ApiOperation("社交登录,使用 code 授权码") + @PostMapping("/social-quick-login") + @ApiOperation("社交快捷登录,使用 code 授权码") @OperateLog(enable = false) // 避免 Post 请求被记录操作日志 - public CommonResult socialLogin(@RequestBody @Valid AuthSocialLoginReqVO reqVO) { + public CommonResult socialQuickLogin(@RequestBody @Valid AuthSocialQuickLoginReqVO reqVO) { String token = authService.socialLogin(reqVO, getClientIP(), getUserAgent()); // 返回结果 return success(AuthLoginRespVO.builder().token(token).build()); } - @PostMapping("/social-login2") - @ApiOperation("社交登录,使用 code 授权码 + 账号密码") + @PostMapping("/social-bind-login") + @ApiOperation("社交绑定登录,使用 code 授权码 + 账号密码") @OperateLog(enable = false) // 避免 Post 请求被记录操作日志 - public CommonResult socialLogin2(@RequestBody @Valid AuthSocialLogin2ReqVO reqVO) { - String token = authService.socialLogin2(reqVO, getClientIP(), getUserAgent()); + public CommonResult socialBindLogin(@RequestBody @Valid AuthSocialBindLoginReqVO reqVO) { + String token = authService.socialBindLogin(reqVO, getClientIP(), getUserAgent()); // 返回结果 return success(AuthLoginRespVO.builder().token(token).build()); } - @PostMapping("/social-bind") - @ApiOperation("社交绑定,使用 code 授权码") - public CommonResult socialBind(@RequestBody @Valid AuthSocialBindReqVO reqVO) { - authService.socialBind(getLoginUserId(), reqVO); - return CommonResult.success(true); - } - - @DeleteMapping("/social-unbind") - @ApiOperation("取消社交绑定") - public CommonResult socialUnbind(@RequestBody AuthSocialUnbindReqVO reqVO) { - socialUserService.unbindSocialUser(getLoginUserId(), UserTypeEnum.ADMIN.getValue(), reqVO.getType(), reqVO.getUnionId()); - return CommonResult.success(true); - } - } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/vo/auth/AuthSocialLogin2ReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/vo/auth/AuthSocialBindLoginReqVO.java similarity index 92% rename from yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/vo/auth/AuthSocialLogin2ReqVO.java rename to yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/vo/auth/AuthSocialBindLoginReqVO.java index 725a52d8cb..71f5cfe9fd 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/vo/auth/AuthSocialLogin2ReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/vo/auth/AuthSocialBindLoginReqVO.java @@ -14,12 +14,12 @@ import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; import javax.validation.constraints.Pattern; -@ApiModel("管理后台 - 社交登录 Request VO,使用 code 授权码 + 账号密码") +@ApiModel("管理后台 - 社交绑定登录 Request VO,使用 code 授权码 + 账号密码") @Data @NoArgsConstructor @AllArgsConstructor @Builder -public class AuthSocialLogin2ReqVO { +public class AuthSocialBindLoginReqVO { @ApiModelProperty(value = "社交平台的类型", required = true, example = "10", notes = "参见 UserSocialTypeEnum 枚举值") @InEnum(SocialTypeEnum.class) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/vo/auth/AuthSocialLoginReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/vo/auth/AuthSocialQuickLoginReqVO.java similarity index 90% rename from yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/vo/auth/AuthSocialLoginReqVO.java rename to yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/vo/auth/AuthSocialQuickLoginReqVO.java index 4f51bcb989..2bec43691a 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/vo/auth/AuthSocialLoginReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/vo/auth/AuthSocialQuickLoginReqVO.java @@ -12,12 +12,12 @@ import lombok.NoArgsConstructor; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; -@ApiModel("管理后台 - 社交登录 Request VO,使用 code 授权码") +@ApiModel("管理后台 - 社交快捷登录 Request VO,使用 code 授权码") @Data @NoArgsConstructor @AllArgsConstructor @Builder -public class AuthSocialLoginReqVO { +public class AuthSocialQuickLoginReqVO { @ApiModelProperty(value = "社交平台的类型", required = true, example = "10", notes = "参见 UserSocialTypeEnum 枚举值") @InEnum(SocialTypeEnum.class) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/SocialUserController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/SocialUserController.java new file mode 100644 index 0000000000..c29fe8aa7e --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/SocialUserController.java @@ -0,0 +1,42 @@ +package cn.iocoder.yudao.module.system.controller.admin.socail; + +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialBindReqVO; +import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialUnbindReqVO; +import cn.iocoder.yudao.module.system.convert.social.SocialUserConvert; +import cn.iocoder.yudao.module.system.service.social.SocialUserService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.validation.Valid; + +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; + +@Api(tags = "管理后台 - 社交用户") +@RestController +@RequestMapping("/system/social-user") +@Validated +public class SocialUserController { + + @Resource + private SocialUserService socialUserService; + + @PostMapping("/bind") + @ApiOperation("社交绑定,使用 code 授权码") + public CommonResult socialBind(@RequestBody @Valid AuthSocialBindReqVO reqVO) { + socialUserService.bindSocialUser(SocialUserConvert.INSTANCE.convert(getLoginUserId(), UserTypeEnum.ADMIN.getValue(), reqVO)); + return CommonResult.success(true); + } + + @DeleteMapping("/unbind") + @ApiOperation("取消社交绑定") + public CommonResult socialUnbind(@RequestBody AuthSocialUnbindReqVO reqVO) { + socialUserService.unbindSocialUser(getLoginUserId(), UserTypeEnum.ADMIN.getValue(), reqVO.getType(), reqVO.getUnionId()); + return CommonResult.success(true); + } + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/profile/UserProfileRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/profile/UserProfileRespVO.java index c0b77f0f2d..c14a2903dd 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/profile/UserProfileRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/profile/UserProfileRespVO.java @@ -96,8 +96,8 @@ public class UserProfileRespVO extends UserBaseVO { @ApiModelProperty(value = "社交平台的类型", required = true, example = "10", notes = "参见 SocialTypeEnum 枚举类") private Integer type; - @ApiModelProperty(value = "社交的全局编号", required = true, example = "IPRmJ0wvBptiPIlGEZiPewGwiEiE") - private String unionId; + @ApiModelProperty(value = "社交用户的 openid", required = true, example = "IPRmJ0wvBptiPIlGEZiPewGwiEiE") + private String openid; } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/auth/AuthConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/auth/AuthConvert.java index c52328cc0d..2f19e7d840 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/auth/AuthConvert.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/auth/AuthConvert.java @@ -72,9 +72,8 @@ public interface AuthConvert { return CollectionUtils.filterList(treeNodeMap.values(), node -> MenuIdEnum.ROOT.getId().equals(node.getParentId())); } - SocialUserBindReqDTO convert(Long userId, Integer userType, AuthSocialBindReqVO reqVO); - SocialUserBindReqDTO convert(Long userId, Integer userType, AuthSocialLogin2ReqVO reqVO); - SocialUserBindReqDTO convert(Long userId, Integer userType, AuthSocialLoginReqVO reqVO); - SocialUserUnbindReqDTO convert(Long userId, Integer userType, AuthSocialUnbindReqVO reqVO); + SocialUserBindReqDTO convert(Long userId, Integer userType, AuthSocialBindLoginReqVO reqVO); + + SocialUserBindReqDTO convert(Long userId, Integer userType, AuthSocialQuickLoginReqVO reqVO); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/social/SocialUserConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/social/SocialUserConvert.java new file mode 100644 index 0000000000..f27186e17a --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/social/SocialUserConvert.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.system.convert.social; + +import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO; +import cn.iocoder.yudao.module.system.api.social.dto.SocialUserUnbindReqDTO; +import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialBindReqVO; +import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialUnbindReqVO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface SocialUserConvert { + + SocialUserConvert INSTANCE = Mappers.getMapper(SocialUserConvert.class); + + SocialUserBindReqDTO convert(Long userId, Integer userType, AuthSocialBindReqVO reqVO); + + SocialUserUnbindReqDTO convert(Long userId, Integer userType, AuthSocialUnbindReqVO reqVO); + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/social/SocialUserBindDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/social/SocialUserBindDO.java index 09626621e1..dcebb069b8 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/social/SocialUserBindDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/social/SocialUserBindDO.java @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.system.dal.dataobject.social; import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; import com.baomidou.mybatisplus.annotation.TableName; import lombok.*; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/framework/security/config/SecurityConfiguration.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/framework/security/config/SecurityConfiguration.java index 53b99ce8cf..9a5d36ab88 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/framework/security/config/SecurityConfiguration.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/framework/security/config/SecurityConfiguration.java @@ -18,14 +18,18 @@ public class SecurityConfiguration { @Override public void customize(ExpressionUrlAuthorizationConfigurer.ExpressionInterceptUrlRegistry registry) { - // 登录的接口,可匿名访问 - registry.antMatchers(buildAdminApi("/system/login")).anonymous(); + // 登录的接口 + registry.antMatchers(buildAdminApi("/system/auth/login")).permitAll(); + // 社交登陆的接口 + registry.antMatchers(buildAdminApi("/system/auth/social-auth-redirect")).permitAll(); + registry.antMatchers(buildAdminApi("/system/auth/social-quick-login")).permitAll(); + registry.antMatchers(buildAdminApi("/system/auth/social-bind-login")).permitAll(); // 验证码的接口 - registry.antMatchers(buildAdminApi("/system/captcha/**")).anonymous(); + registry.antMatchers(buildAdminApi("/system/captcha/**")).permitAll(); // 获得租户编号的接口 - registry.antMatchers(buildAdminApi("/system/tenant/get-id-by-name")).anonymous(); + registry.antMatchers(buildAdminApi("/system/tenant/get-id-by-name")).permitAll(); // 短信回调 API - registry.antMatchers(buildAdminApi("/system/sms/callback/**")).anonymous(); + registry.antMatchers(buildAdminApi("/system/sms/callback/**")).permitAll(); } }; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthService.java index 36ef97972d..c78f59cb18 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthService.java @@ -25,31 +25,23 @@ public interface AdminAuthService extends SecurityAuthFrameworkService { String login(@Valid AuthLoginReqVO reqVO, String userIp, String userAgent); /** - * 社交登录,使用 code 授权码 + * 社交快捷登录,使用 code 授权码 * * @param reqVO 登录信息 * @param userIp 用户 IP * @param userAgent 用户 UA * @return 身份令牌,使用 JWT 方式 */ - String socialLogin(@Valid AuthSocialLoginReqVO reqVO, String userIp, String userAgent); + String socialLogin(@Valid AuthSocialQuickLoginReqVO reqVO, String userIp, String userAgent); /** - * 社交登录,使用 code 授权码 + 账号密码 + * 社交绑定登录,使用 code 授权码 + 账号密码 * * @param reqVO 登录信息 * @param userIp 用户 IP * @param userAgent 用户 UA * @return 身份令牌,使用 JWT 方式 */ - String socialLogin2(@Valid AuthSocialLogin2ReqVO reqVO, String userIp, String userAgent); - - /** - * 社交绑定,使用 code 授权码 - * - * @param userId 用户编号 - * @param reqVO 绑定信息 - */ - void socialBind(Long userId, @Valid AuthSocialBindReqVO reqVO); + String socialBindLogin(@Valid AuthSocialBindLoginReqVO reqVO, String userIp, String userAgent); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java index efe3d578d7..9159fd0f86 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java @@ -9,9 +9,9 @@ import cn.iocoder.yudao.framework.security.core.LoginUser; import cn.iocoder.yudao.framework.security.core.authentication.MultiUsernamePasswordAuthenticationToken; import cn.iocoder.yudao.module.system.api.logger.dto.LoginLogCreateReqDTO; import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthLoginReqVO; +import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialBindLoginReqVO; import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialBindReqVO; -import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialLogin2ReqVO; -import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialLoginReqVO; +import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialQuickLoginReqVO; import cn.iocoder.yudao.module.system.convert.auth.AuthConvert; import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; import cn.iocoder.yudao.module.system.enums.logger.LoginLogTypeEnum; @@ -22,7 +22,6 @@ import cn.iocoder.yudao.module.system.service.permission.PermissionService; import cn.iocoder.yudao.module.system.service.social.SocialUserService; import cn.iocoder.yudao.module.system.service.user.AdminUserService; import lombok.extern.slf4j.Slf4j; -import me.zhyd.oauth.model.AuthUser; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.security.authentication.AuthenticationManager; @@ -82,7 +81,7 @@ public class AdminAuthServiceImpl implements AdminAuthService { throw new UsernameNotFoundException(username); } // 创建 LoginUser 对象 - return this.buildLoginUser(user); + return buildLoginUser(user); } @Override @@ -92,19 +91,19 @@ public class AdminAuthServiceImpl implements AdminAuthService { if (user == null) { throw new UsernameNotFoundException(String.valueOf(userId)); } - this.createLoginLog(user.getUsername(), LoginLogTypeEnum.LOGIN_MOCK, LoginResultEnum.SUCCESS); + createLoginLog(user.getUsername(), LoginLogTypeEnum.LOGIN_MOCK, LoginResultEnum.SUCCESS); // 创建 LoginUser 对象 - return this.buildLoginUser(user); + return buildLoginUser(user); } @Override public String login(AuthLoginReqVO reqVO, String userIp, String userAgent) { // 判断验证码是否正确 - this.verifyCaptcha(reqVO); + verifyCaptcha(reqVO); // 使用账号密码,进行登录 - LoginUser loginUser = this.login0(reqVO.getUsername(), reqVO.getPassword()); + LoginUser loginUser = login0(reqVO.getUsername(), reqVO.getPassword()); // 缓存登陆用户到 Redis 中,返回 sessionId 编号 return createUserSessionAfterLoginSuccess(loginUser, LoginLogTypeEnum.LOGIN_USERNAME, userIp, userAgent); @@ -192,7 +191,7 @@ public class AdminAuthServiceImpl implements AdminAuthService { } @Override - public String socialLogin(AuthSocialLoginReqVO reqVO, String userIp, String userAgent) { + public String socialLogin(AuthSocialQuickLoginReqVO reqVO, String userIp, String userAgent) { // 使用 code 授权码,进行登录。然后,获得到绑定的用户编号 Long userId = socialUserService.getBindUserId(UserTypeEnum.ADMIN.getValue(), reqVO.getType(), reqVO.getCode(), reqVO.getState()); @@ -207,24 +206,18 @@ public class AdminAuthServiceImpl implements AdminAuthService { } // 创建 LoginUser 对象 - LoginUser loginUser = this.buildLoginUser(user); - - // 绑定社交用户(更新) - socialUserService.bindSocialUser(AuthConvert.INSTANCE.convert(loginUser.getId(), getUserType().getValue(), reqVO)); + LoginUser loginUser = buildLoginUser(user); // 缓存登录用户到 Redis 中,返回 sessionId 编号 return createUserSessionAfterLoginSuccess(loginUser, LoginLogTypeEnum.LOGIN_SOCIAL, userIp, userAgent); } @Override - public String socialLogin2(AuthSocialLogin2ReqVO reqVO, String userIp, String userAgent) { - // 使用 code 授权码,进行登录 - socialUserService.authSocialUser(reqVO.getType(), reqVO.getCode(), reqVO.getState()); - + public String socialBindLogin(AuthSocialBindLoginReqVO reqVO, String userIp, String userAgent) { // 使用账号密码,进行登录。 - LoginUser loginUser = this.login0(reqVO.getUsername(), reqVO.getPassword()); + LoginUser loginUser = login0(reqVO.getUsername(), reqVO.getPassword()); - // 绑定社交用户(新增) + // 绑定社交用户 socialUserService.bindSocialUser(AuthConvert.INSTANCE.convert(loginUser.getId(), getUserType().getValue(), reqVO)); // 缓存登录用户到 Redis 中,返回 sessionId 编号 @@ -238,12 +231,6 @@ public class AdminAuthServiceImpl implements AdminAuthService { return userSessionService.createUserSession(loginUser, userIp, userAgent); } - @Override - public void socialBind(Long userId, AuthSocialBindReqVO reqVO) { - // 绑定社交用户(新增) - socialUserService.bindSocialUser(AuthConvert.INSTANCE.convert(userId, getUserType().getValue(), reqVO)); - } - @Override public void logout(String token) { // 查询用户信息 diff --git a/yudao-server/src/main/resources/application-dev.yaml b/yudao-server/src/main/resources/application-dev.yaml index a2f191b7ba..256c5beb88 100644 --- a/yudao-server/src/main/resources/application-dev.yaml +++ b/yudao-server/src/main/resources/application-dev.yaml @@ -186,10 +186,6 @@ yudao: justauth: enabled: true type: - GITEE: # Gitee - client-id: ee61f0374a4c6c404a8717094caa7a410d76950e45ff60348015830c519ba5c1 - client-secret: 7c044a5671be3b051414db0cf2cec6ad702dd298d2416ba24ceaf608e6fa26f9 - ignore-check-redirect-uri: true DINGTALK: # 钉钉 client-id: dingvrnreaje3yqvzhxg client-secret: i8E6iZyDvZj51JIb0tYsYfVQYOks9Cq1lgryEjFRqC79P3iJcrxEwT6Qk2QvLrLI diff --git a/yudao-server/src/main/resources/application-local.yaml b/yudao-server/src/main/resources/application-local.yaml index 1b4b038df4..0d5f777d01 100644 --- a/yudao-server/src/main/resources/application-local.yaml +++ b/yudao-server/src/main/resources/application-local.yaml @@ -196,10 +196,6 @@ yudao: justauth: enabled: true type: - GITEE: # Gitee - client-id: ee61f0374a4c6c404a8717094caa7a410d76950e45ff60348015830c519ba5c1 - client-secret: 7c044a5671be3b051414db0cf2cec6ad702dd298d2416ba24ceaf608e6fa26f9 - ignore-check-redirect-uri: true DINGTALK: # 钉钉 client-id: dingvrnreaje3yqvzhxg client-secret: i8E6iZyDvZj51JIb0tYsYfVQYOks9Cq1lgryEjFRqC79P3iJcrxEwT6Qk2QvLrLI diff --git a/yudao-ui-admin/src/api/login.js b/yudao-ui-admin/src/api/login.js index 740f497955..ffe83fb5f3 100644 --- a/yudao-ui-admin/src/api/login.js +++ b/yudao-ui-admin/src/api/login.js @@ -9,7 +9,7 @@ export function login(username, password, code, uuid) { uuid } return request({ - url: '/system/login', + url: '/system/auth/login', method: 'post', data: data }) @@ -18,7 +18,7 @@ export function login(username, password, code, uuid) { // 获取用户详细信息 export function getInfo() { return request({ - url: '/system/get-permission-info', + url: '/system/auth/get-permission-info', method: 'get' }) } @@ -43,15 +43,15 @@ export function getCodeImg() { // 社交授权的跳转 export function socialAuthRedirect(type, redirectUri) { return request({ - url: '/system/social-auth-redirect?type=' + type + '&redirectUri=' + redirectUri, + url: '/system/auth/social-auth-redirect?type=' + type + '&redirectUri=' + redirectUri, method: 'get' }) } -// 社交登录,使用 code 授权码 -export function socialLogin(type, code, state) { +// 社交快捷登录,使用 code 授权码 +export function socialQuickLogin(type, code, state) { return request({ - url: '/system/social-login', + url: '/system/auth/social-quick-login', method: 'post', data: { type, @@ -61,10 +61,10 @@ export function socialLogin(type, code, state) { }) } -// 社交登录,使用 code 授权码 + + 账号密码 -export function socialLogin2(type, code, state, username, password) { +// 社交绑定登录,使用 code 授权码 + + 账号密码 +export function socialBindLogin(type, code, state, username, password) { return request({ - url: '/system/social-login2', + url: '/system/auth/social-bind-login', method: 'post', data: { type, @@ -75,28 +75,3 @@ export function socialLogin2(type, code, state, username, password) { } }) } - -// 社交绑定,使用 code 授权码 -export function socialBind(type, code, state) { - return request({ - url: '/system/social-bind', - method: 'post', - data: { - type, - code, - state, - } - }) -} - -// 取消社交绑定 -export function socialUnbind(type, unionId) { - return request({ - url: '/system/social-unbind', - method: 'delete', - data: { - type, - unionId - } - }) -} diff --git a/yudao-ui-admin/src/api/menu.js b/yudao-ui-admin/src/api/menu.js index 48df3dd554..0939be7575 100644 --- a/yudao-ui-admin/src/api/menu.js +++ b/yudao-ui-admin/src/api/menu.js @@ -3,7 +3,7 @@ import request from '@/utils/request' // 获取路由 export const getRouters = () => { return request({ - url: '/system/list-menus', + url: '/system/auth/list-menus', method: 'get' }) } diff --git a/yudao-ui-admin/src/api/system/socialUser.js b/yudao-ui-admin/src/api/system/socialUser.js new file mode 100644 index 0000000000..39149cb609 --- /dev/null +++ b/yudao-ui-admin/src/api/system/socialUser.js @@ -0,0 +1,26 @@ +import request from "@/utils/request"; + +// 社交绑定,使用 code 授权码 +export function socialBind(type, code, state) { + return request({ + url: '/system/social-user/bind', + method: 'post', + data: { + type, + code, + state, + } + }) +} + +// 取消社交绑定 +export function socialUnbind(type, unionId) { + return request({ + url: '/system/social-user/unbind', + method: 'delete', + data: { + type, + unionId + } + }) +} diff --git a/yudao-ui-admin/src/store/modules/user.js b/yudao-ui-admin/src/store/modules/user.js index 78da4ece41..d3cbf4886e 100644 --- a/yudao-ui-admin/src/store/modules/user.js +++ b/yudao-ui-admin/src/store/modules/user.js @@ -1,4 +1,4 @@ -import {login, logout, getInfo, socialLogin, socialLogin2} from '@/api/login' +import {login, logout, getInfo, socialQuickLogin, socialBindLogin} from '@/api/login' import { getToken, setToken, removeToken } from '@/utils/auth' const user = { @@ -57,7 +57,7 @@ const user = { const state = userInfo.state const type = userInfo.type return new Promise((resolve, reject) => { - socialLogin(type, code, state).then(res => { + socialQuickLogin(type, code, state).then(res => { res = res.data; setToken(res.token) commit('SET_TOKEN', res.token) @@ -76,7 +76,7 @@ const user = { const username = userInfo.username.trim() const password = userInfo.password return new Promise((resolve, reject) => { - socialLogin2(type, code, state, username, password).then(res => { + socialBindLogin(type, code, state, username, password).then(res => { res = res.data; setToken(res.token) commit('SET_TOKEN', res.token) diff --git a/yudao-ui-admin/src/utils/constants.js b/yudao-ui-admin/src/utils/constants.js index f1e69a2461..91950e03dd 100644 --- a/yudao-ui-admin/src/utils/constants.js +++ b/yudao-ui-admin/src/utils/constants.js @@ -71,12 +71,6 @@ export const InfraApiErrorLogProcessStatusEnum = { * 用户的社交平台的类型枚举 */ export const SystemUserSocialTypeEnum = { - // GITEE: { - // title: "码云", - // type: 10, - // source: "gitee", - // img: "https://cdn.jsdelivr.net/gh/justauth/justauth-oauth-logo@1.11/gitee.png", - // }, DINGTALK: { title: "钉钉", type: 20, diff --git a/yudao-ui-admin/src/views/login.vue b/yudao-ui-admin/src/views/login.vue index 95ddb98620..3e05bbb840 100644 --- a/yudao-ui-admin/src/views/login.vue +++ b/yudao-ui-admin/src/views/login.vue @@ -176,7 +176,6 @@ export default { }); }, doSocialLogin(socialTypeEnum) { - // console.log("开始Oauth登录...%o", socialTypeEnum.code); // 设置登录中 this.loading = true; // 计算 redirectUri diff --git a/yudao-ui-admin/src/views/system/user/profile/userSocial.vue b/yudao-ui-admin/src/views/system/user/profile/userSocial.vue index 670ee423d9..2e41a4cd48 100644 --- a/yudao-ui-admin/src/views/system/user/profile/userSocial.vue +++ b/yudao-ui-admin/src/views/system/user/profile/userSocial.vue @@ -7,7 +7,7 @@