diff --git a/db/2pigxx.sql b/db/2pigxx.sql index 64ff058cf..bd51a285d 100644 --- a/db/2pigxx.sql +++ b/db/2pigxx.sql @@ -254,7 +254,9 @@ INSERT INTO `sys_dict_item` VALUES (59, 19, '1', '开', 'captcha_flag_types', ' INSERT INTO `sys_dict_item` VALUES (60, 20, '0', '否', 'enc_flag_types', '不加密', 0, ' ', ' ', '2020-11-18 06:55:31', '2020-11-18 06:55:31', '不加密-0', '0', 1); INSERT INTO `sys_dict_item` VALUES (61, 20, '1', '是', 'enc_flag_types', '加密', 1, ' ', ' ', '2020-11-18 06:55:51', '2020-11-18 06:55:51', '加密-1', '0', 1); INSERT INTO `sys_dict_item` VALUES (62, 15, 'MERGE_PAY', '聚合支付', 'channel_id', '聚合支付', 1, ' ', ' ', '2019-05-30 19:08:08', '2019-06-18 13:51:53', '聚合支付', '0', 1); -INSERT INTO `sys_dict_item` VALUES (63, 2, 'CAS', 'CAS登录', 'social_type', 'CAS 单点登录系统', 3, ' ', ' ', '2022-02-18 13:56:25', '2022-02-18 13:56:28', NULL, '0', 0); +INSERT INTO `sys_dict_item` VALUES (63, 2, 'CAS', 'CAS登录', 'social_type', 'CAS 单点登录系统', 3, ' ', ' ', '2022-02-18 13:56:25', '2022-02-18 13:56:28', NULL, '0', 1); +INSERT INTO `sys_dict_item` VALUES (64, 2, 'DINGTALK', '钉钉', 'social_type', '钉钉', 3, ' ', ' ', '2022-02-18 13:56:25', '2022-02-18 13:56:28', NULL, '0', 1); +INSERT INTO `sys_dict_item` VALUES (65, 2, 'WEIXIN_CP', '企业微信', 'social_type', '企业微信', 3, ' ', ' ', '2022-02-18 13:56:25', '2022-02-18 13:56:28', NULL, '0', 1); COMMIT; -- ---------------------------- @@ -364,6 +366,7 @@ INSERT INTO `sys_menu` VALUES (1400, '部门管理', NULL, '/admin/dept/index', INSERT INTO `sys_menu` VALUES (1401, '部门新增', 'sys_dept_add', NULL, 1400, NULL, 1, '0', '1', ' ', '2018-01-20 14:56:16', ' ', '2021-05-25 03:12:55', '0', 1); INSERT INTO `sys_menu` VALUES (1402, '部门修改', 'sys_dept_edit', NULL, 1400, NULL, 1, '0', '1', ' ', '2018-01-20 14:56:59', ' ', '2021-05-25 03:12:55', '0', 1); INSERT INTO `sys_menu` VALUES (1403, '部门删除', 'sys_dept_del', NULL, 1400, NULL, 1, '0', '1', ' ', '2018-01-20 14:57:28', ' ', '2021-05-25 03:12:55', '0', 1); +INSERT INTO `sys_menu` VALUES (1404, '互联同步', 'sys_connect_sync', NULL, 1400, NULL, 1, '0', '1', ' ', '2018-01-20 14:57:28', ' ', '2021-05-25 03:12:55', '0', 1); INSERT INTO `sys_menu` VALUES (1500, '租户管理', '', '/admin/tenant/index', 1000, 'icon-erji-zuhushouye', 5, '0', '0', ' ', '2018-01-20 13:17:19', ' ', '2022-01-27 11:59:14', '0', 1); INSERT INTO `sys_menu` VALUES (1501, '租户新增', 'admin_systenant_add', NULL, 1500, '1', 0, '0', '1', ' ', '2018-05-15 21:35:18', ' ', '2020-03-24 08:56:52', '0', 1); INSERT INTO `sys_menu` VALUES (1502, '租户修改', 'admin_systenant_edit', NULL, 1500, '1', 1, '0', '1', ' ', '2018-05-15 21:35:18', ' ', '2020-03-24 08:56:53', '0', 1); @@ -628,6 +631,7 @@ INSERT INTO `sys_role_menu` VALUES (1, 1400); INSERT INTO `sys_role_menu` VALUES (1, 1401); INSERT INTO `sys_role_menu` VALUES (1, 1402); INSERT INTO `sys_role_menu` VALUES (1, 1403); +INSERT INTO `sys_role_menu` VALUES (1, 1404); INSERT INTO `sys_role_menu` VALUES (1, 1500); INSERT INTO `sys_role_menu` VALUES (1, 1501); INSERT INTO `sys_role_menu` VALUES (1, 1502); diff --git a/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/config/AuthorizationServerConfiguration.java b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/config/AuthorizationServerConfiguration.java index daec7b1c6..fde86b55f 100644 --- a/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/config/AuthorizationServerConfiguration.java +++ b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/config/AuthorizationServerConfiguration.java @@ -30,7 +30,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpMethod; import org.springframework.security.authentication.AuthenticationManager; -import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer; import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter; import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; @@ -59,8 +58,6 @@ public class AuthorizationServerConfiguration extends AuthorizationServerConfigu private final AuthenticationManager authenticationManagerBean; - private final UserDetailsService pigxUserDetailsService; - private final AuthorizationCodeServices authorizationCodeServices; private final AuthenticationManager authenticationManager; diff --git a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/enums/LoginTypeEnum.java b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/enums/LoginTypeEnum.java index b2f99292d..60b604054 100644 --- a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/enums/LoginTypeEnum.java +++ b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/enums/LoginTypeEnum.java @@ -66,8 +66,12 @@ public enum LoginTypeEnum { /** * 钉钉 */ - dingtalk("DINGTALK", "钉钉"), + DINGTALK("DINGTALK", "钉钉"), + /** + * 企业微信 + */ + WEIXIN_CP("WEIXIN_CP", "企业微信"), /** * CAS 登录 */ diff --git a/pigx-common/pigx-common-sequence/src/main/java/com/pig4cloud/pigx/common/sequence/range/impl/db/provider/MssqlSqlProvider.java b/pigx-common/pigx-common-sequence/src/main/java/com/pig4cloud/pigx/common/sequence/range/impl/db/provider/MssqlSqlProvider.java new file mode 100644 index 000000000..df5551166 --- /dev/null +++ b/pigx-common/pigx-common-sequence/src/main/java/com/pig4cloud/pigx/common/sequence/range/impl/db/provider/MssqlSqlProvider.java @@ -0,0 +1,41 @@ +package com.pig4cloud.pigx.common.sequence.range.impl.db.provider; + +import com.baomidou.mybatisplus.annotation.DbType; +import org.springframework.stereotype.Component; + +/** + * 数据源提供者 + * + * @author hanyichao + * @date 2022-04-27 + * + * sql server + */ +@Component +public class MssqlSqlProvider implements SqlProvider { + + /** + * 获取表是否存在 + * @return 执行语句 + */ + @Override + public String getExistTableSql() { + return "SELECT TOP 1 * FROM sysObjects WHERE Id=OBJECT_ID(N'#tableName') AND xtype='U'"; + } + + /** + * 获取建表语句 + * @return + */ + @Override + public String getCreateTableSql() { + return "CREATE TABLE #tableName (id bigint NOT NULL,value bigint NOT NULL,name nvarchar (32) COLLATE " + + "Chinese_PRC_CI_AS NOT NULL,gmt_create datetime2 (7) NOT NULL,gmt_modified datetime2 (7) NOT NULL)"; + } + + @Override + public Boolean support(DbType dbType) { + return DbType.SQL_SERVER.equals(dbType); + } + +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/ConnectController.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/ConnectController.java index e139c4b8c..1d5d10896 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/ConnectController.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/ConnectController.java @@ -4,9 +4,9 @@ import com.pig4cloud.pigx.admin.api.entity.SysDept; import com.pig4cloud.pigx.admin.service.ConnectService; import com.pig4cloud.pigx.admin.service.SysDeptService; import com.pig4cloud.pigx.common.core.util.R; -import com.pig4cloud.pigx.common.security.annotation.Inner; import io.swagger.annotations.Api; import lombok.RequiredArgsConstructor; +import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -17,7 +17,6 @@ import org.springframework.web.bind.annotation.RestController; * @author lengleng * @date 2022/4/22 */ -@Inner(value = false) @RestController @RequiredArgsConstructor @RequestMapping("/connect") @@ -33,6 +32,7 @@ public class ConnectController { * @return */ @PostMapping("/sync/ding/user") + @PreAuthorize("@pms.hasPermission('sys_connect_sync')") public R syncUser() { for (SysDept sysDept : deptService.list()) { connectService.syncDingUser(sysDept.getDeptId()); @@ -45,6 +45,7 @@ public class ConnectController { * @return */ @PostMapping("/sync/ding/dept") + @PreAuthorize("@pms.hasPermission('sys_connect_sync')") public R syncDept() { return R.ok(connectService.syncDingDept()); } @@ -54,6 +55,7 @@ public class ConnectController { * @return */ @PostMapping("/sync/cp/user") + @PreAuthorize("@pms.hasPermission('sys_connect_sync')") public R syncCpUser() { return connectService.syncCpUser(); } @@ -63,6 +65,7 @@ public class ConnectController { * @return */ @PostMapping("/sync/cp/dept") + @PreAuthorize("@pms.hasPermission('sys_connect_sync')") public R syncCpDept() { return connectService.syncCpDept(); } diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/ConnectServiceImpl.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/ConnectServiceImpl.java index 26f956af7..32cb0d014 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/ConnectServiceImpl.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/ConnectServiceImpl.java @@ -2,6 +2,7 @@ package com.pig4cloud.pigx.admin.service.impl; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.convert.Convert; +import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONArray; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; @@ -132,10 +133,11 @@ public class ConnectServiceImpl implements ConnectService { JSONObject userResult = JSONUtil.parseObj(userGetResponse.getBody()); JSONObject userObj = JSONUtil.parseObj(userResult.get("result")); - boolean exist = users.stream().anyMatch(user -> user.getPhone().equals(userObj.getStr("mobile"))); + boolean exist = users.stream().filter(user -> StrUtil.isNotBlank(user.getPhone())) + .anyMatch(user -> user.getPhone().equals(userObj.getStr("mobile"))); - if (exist) { - log.info("用户已存在 {}", userid); + if (exist || StrUtil.isBlank(userObj.getStr("mobile"))) { + log.info("用户已存在或手机号不合法 {}", userid); continue; } @@ -209,7 +211,7 @@ public class ConnectServiceImpl implements ConnectService { List cpUserList; try { - cpUserList = wxCpService.getUserService().listByDepartment(0L, true, 0); + cpUserList = wxCpService.getUserService().listByDepartment(1L, true, 0); } catch (WxErrorException e) { log.error("获取企业微信用户列表失败", e); @@ -224,9 +226,10 @@ public class ConnectServiceImpl implements ConnectService { List userList = sysUserService.list(Wrappers.emptyWrapper()); for (WxCpUser cpUser : cpUserList) { - boolean exist = userList.stream().anyMatch(user -> user.getPhone().equals(cpUser.getMobile())); - if (exist) { - log.info("用户已存在跳过 {}", cpUser); + boolean exist = userList.stream().filter(user -> StrUtil.isNotBlank(user.getPhone())) + .anyMatch(user -> user.getPhone().equals(cpUser.getMobile())); + if (exist || StrUtil.isBlank(cpUser.getMobile())) { + log.info("用户已存在或手机号不合法跳过 {}", cpUser); continue; } @@ -247,7 +250,7 @@ public class ConnectServiceImpl implements ConnectService { private String getDingAccessToken() { SysSocialDetails dingTalk = sysSocialDetailsMapper.selectOne(Wrappers.lambdaQuery() - .eq(SysSocialDetails::getType, LoginTypeEnum.dingtalk.getType())); + .eq(SysSocialDetails::getType, LoginTypeEnum.DINGTALK.getType())); DingTalkClient client = new DefaultDingTalkClient(SecurityConstants.DING_OLD_GET_TOKEN); OapiGettokenRequest request = new OapiGettokenRequest(); @@ -265,13 +268,17 @@ public class ConnectServiceImpl implements ConnectService { } private WxCpDefaultConfigImpl getCpConfig() { + SysSocialDetails cp = sysSocialDetailsMapper.selectOne(Wrappers.lambdaQuery() + .eq(SysSocialDetails::getType, LoginTypeEnum.WEIXIN_CP.getType())); + WxCpDefaultConfigImpl config = new WxCpDefaultConfigImpl(); - config.setCorpId("wwdfd8cc3eb1127464"); // 设置微信企业号的appid - config.setCorpSecret("mrJAJwC0msVJ0-F30Iwop6B-w8eledxD66l3flrjX5w"); // 设置微信企业号的app + config.setCorpId(cp.getAppId()); // 设置微信企业号的appid + config.setCorpSecret(cp.getAppSecret()); // 设置微信企业号的app // corpSecret - config.setAgentId(1000003); // 设置微信企业号应用ID - config.setToken("lengleng"); // 设置微信企业号应用的token - config.setAesKey("pc49WfQMwDg2tDwHHP8gfLN6fRjkgDzS4WkYCumZCF1"); // 设置微信企业号应用的EncodingAESKey + JSONObject ext = JSONUtil.parseObj(cp.getExt()); + config.setAgentId(ext.getInt("agentId")); // 设置微信企业号应用ID + config.setToken(ext.getStr("token")); // 设置微信企业号应用的token + config.setAesKey(ext.getStr("aesKey")); // 设置微信企业号应用的EncodingAESKey return config; }