From a6457abe8eb70f02aa1d036d221a8c70cc0493fb Mon Sep 17 00:00:00 2001 From: lbw Date: Thu, 9 Nov 2023 15:25:02 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20Introducing=20new=20features.=20?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=92=89=E9=92=89=E5=92=8C=E4=BC=81=E5=BE=AE?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/2pigxx.sql | 2 + .../pigx/admin/api/entity/SysUser.java | 12 +++ .../admin/handler/DingTalkLoginHandler.java | 86 +++++++++++++++++++ .../admin/handler/WeChatCPLoginHandler.java | 85 ++++++++++++++++++ 4 files changed, 185 insertions(+) create mode 100644 pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/handler/DingTalkLoginHandler.java create mode 100644 pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/handler/WeChatCPLoginHandler.java diff --git a/db/2pigxx.sql b/db/2pigxx.sql index 013fded06..c1d0289e0 100644 --- a/db/2pigxx.sql +++ b/db/2pigxx.sql @@ -1146,6 +1146,8 @@ CREATE TABLE `sys_user` ( `qq_openid` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT 'QQ openId', `gitee_login` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '码云标识', `osc_id` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '开源中国标识', + `wx_cp_userid` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '企业微信唯一ID', + `wx_ding_userid` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '钉钉唯一ID', `tenant_id` bigint(20) NOT NULL DEFAULT '0' COMMENT '所属租户ID', PRIMARY KEY (`user_id`) USING BTREE, KEY `user_wx_openid` (`wx_openid`) USING BTREE, diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysUser.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysUser.java index 175d58880..684d421fe 100644 --- a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysUser.java +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysUser.java @@ -167,6 +167,18 @@ public class SysUser implements Serializable { @Schema(description = "开源中国唯一标识") private String oscId; + /** + * 企微微信 userid + */ + @Schema(description = "企微微信 userid") + private String wxCpUserid; + + /** + * 钉钉 userid + */ + @Schema(description = "钉钉 userid") + private String wxDingUserid; + /** * 昵称 */ diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/handler/DingTalkLoginHandler.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/handler/DingTalkLoginHandler.java new file mode 100644 index 000000000..cdd2ab473 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/handler/DingTalkLoginHandler.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.admin.handler; + +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.pig4cloud.pigx.admin.api.dto.UserInfo; +import com.pig4cloud.pigx.admin.api.entity.SysUser; +import com.pig4cloud.pigx.admin.mapper.SysSocialDetailsMapper; +import com.pig4cloud.pigx.admin.service.SysUserService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * @author lengleng + * @date 2023-10-14 + * + * 钉钉登录 + */ +@Slf4j +@Component("DINGTALK") +@AllArgsConstructor +public class DingTalkLoginHandler extends AbstractLoginHandler { + + private final SysUserService sysUserService; + + private final SysSocialDetailsMapper sysSocialDetailsMapper; + + /** + * QQ登录传入code + *

+ * 通过code 调用qq 获取唯一标识 + * @param code + * @return + */ + @Override + public String identify(String code) { + // 企微唯一标识 + return "LengLeng"; + } + + /** + * openId 获取用户信息 + * @param openId + * @return + */ + @Override + public UserInfo info(String openId) { + SysUser user = sysUserService.getOne(Wrappers.query().lambda().eq(SysUser::getWxCpUserid, openId)); + + if (user == null) { + log.info("钉钉未绑定:{}", openId); + return null; + } + return sysUserService.findUserInfo(user); + } + + /** + * 绑定逻辑 + * @param user 用户实体 + * @param identify 渠道返回唯一标识 + * @return + */ + @Override + public Boolean bind(SysUser user, String identify) { + user.setWxCpUserid(identify); + sysUserService.updateById(user); + return true; + } + +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/handler/WeChatCPLoginHandler.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/handler/WeChatCPLoginHandler.java new file mode 100644 index 000000000..f6a70c5f8 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/handler/WeChatCPLoginHandler.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.admin.handler; + +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.pig4cloud.pigx.admin.api.dto.UserInfo; +import com.pig4cloud.pigx.admin.api.entity.SysUser; +import com.pig4cloud.pigx.admin.mapper.SysSocialDetailsMapper; +import com.pig4cloud.pigx.admin.service.SysUserService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * @author lengleng + * @date 2023-10-14 + * + * 企业微信登录 + */ +@Slf4j +@Component("CP") +@AllArgsConstructor +public class WeChatCPLoginHandler extends AbstractLoginHandler { + + private final SysUserService sysUserService; + + private final SysSocialDetailsMapper sysSocialDetailsMapper; + + /** + * QQ登录传入code + *

+ * 通过code 调用qq 获取唯一标识 + * @param code + * @return + */ + @Override + public String identify(String code) { + return "LengLeng"; + } + + /** + * openId 获取用户信息 + * @param openId + * @return + */ + @Override + public UserInfo info(String openId) { + SysUser user = sysUserService.getOne(Wrappers.query().lambda().eq(SysUser::getWxCpUserid, openId)); + + if (user == null) { + log.info("企业微信未绑定:{}", openId); + return null; + } + return sysUserService.findUserInfo(user); + } + + /** + * 绑定逻辑 + * @param user 用户实体 + * @param identify 渠道返回唯一标识 + * @return + */ + @Override + public Boolean bind(SysUser user, String identify) { + user.setWxCpUserid(identify); + sysUserService.updateById(user); + return true; + } + +}