亳州位置汇聚修改
parent
fd026067bb
commit
3a814fc911
|
|
@ -52,6 +52,8 @@ public interface RemoteUserService {
|
|||
*/
|
||||
LoginUser getUserInfoByEmail(String email, String tenantId) throws UserException;
|
||||
|
||||
LoginUser getUserInfoByIdCard(String idCard, String tenantId) throws UserException;
|
||||
|
||||
/**
|
||||
* 通过openid查询用户信息
|
||||
*
|
||||
|
|
|
|||
|
|
@ -3,10 +3,12 @@ package org.dromara.auth.controller;
|
|||
import cn.dev33.satoken.exception.NotLoginException;
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.net.URLDecoder;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.zhyd.oauth.model.AuthResponse;
|
||||
|
|
@ -19,8 +21,11 @@ import org.dromara.auth.domain.vo.LoginVo;
|
|||
import org.dromara.auth.domain.vo.TenantListVo;
|
||||
import org.dromara.auth.form.RegisterBody;
|
||||
import org.dromara.auth.form.SocialLoginBody;
|
||||
import org.dromara.auth.form.SsoLoginBody;
|
||||
import org.dromara.auth.properties.DsSsoProperties;
|
||||
import org.dromara.auth.service.IAuthStrategy;
|
||||
import org.dromara.auth.service.SysLoginService;
|
||||
import org.dromara.auth.util.RSAUtil;
|
||||
import org.dromara.common.core.constant.UserConstants;
|
||||
import org.dromara.common.core.domain.R;
|
||||
import org.dromara.common.core.domain.model.LoginBody;
|
||||
|
|
@ -49,6 +54,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* token 控制
|
||||
|
|
@ -61,6 +67,8 @@ import java.util.concurrent.TimeUnit;
|
|||
public class TokenController {
|
||||
|
||||
private final SocialProperties socialProperties;
|
||||
|
||||
private final DsSsoProperties ssoProperties;
|
||||
private final SysLoginService sysLoginService;
|
||||
private final ScheduledExecutorService scheduledExecutorService;
|
||||
|
||||
|
|
@ -110,6 +118,55 @@ public class TokenController {
|
|||
return R.ok(loginVo);
|
||||
}
|
||||
|
||||
@RequestMapping("/jzLogin")
|
||||
public void wjyLogin(HttpServletRequest request, HttpServletResponse response) throws Exception{
|
||||
System.out.print("进入jzLogin");
|
||||
String userInfo = request.getParameter("userInfo");
|
||||
log.info("接收userInfo={}",userInfo);
|
||||
String privateKey = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAMSmBCx1ghaVLT/x96ERi9lo3XY/dzKFc9y5f7RtPJihU6fijX4eFSNrhJAjnP2pkJfCXLEmaPznmoUfrUhmq3yeXNzRNILQ+XAUcGkX13oMqW9qM/u5ZHlBnBwMiCZVOZ4pmaZ+hgA8jiNjhh1AqBkRpbvlfnlyC0fBv5FcXOQ3AgMBAAECgYBhfp2bHTc90v/4MBLBfF2FkIQb2CNUnO1whVdXMMFWOsWq+puD5447XVb/z2hKKwNQ+j/SZGSw3nKxhZ73wk9KPkGo9o4gjdwbgo6Qnk8sGQFpCg+5aFH1CgMy5PaM2ZcxbPOfO7tardS1D9u3Vm88688Qdk5sLLWkf6JuNP6LIQJBAPQ4w4qMOfI7Uss90A7/SGHWUjzLvsEv5eq/jXpRhJnyX5tHDCgPCq4CQKwBfUbzdapMtsf065aZCWZR51+V3g0CQQDOIeYX3TTDadzg/cC8tG/AVnxbsoY2Cy9fXmzJCfXIOxZPQIL1WF7HDveTXRxhp6CjSkzVcFJ9K1MFbl/WCf5TAkBqqawFg87/E5fKelm3Yxlq2Z8bPGU4nMHO8BBLXvUKA4hsGfCeQkuIyiUSuqfLaCN42H5wAHEwWfB4BseFwL+1AkBgqfrp4/0TSnifNcAFfiQNsUD+C1juzQ35DiG7oSUWMcdDgQAop7lCZd1pyLc/gElPac9gJB06v29eU6UzjVorAkEAymdUmrgcezAi+aMA0+QcenvPiom3jQkduvfBjOiSLSWm5oB8+mMlExl8Vm9FtKMms6zOs/LcTZzxonl//oe4Ag==";
|
||||
com.alibaba.fastjson.JSONObject json = null;
|
||||
if (needsUrlDecode(userInfo)){
|
||||
byte[] b1 = RSAUtil.decrypt(privateKey, URLDecoder.decode(userInfo, StandardCharsets.UTF_8));
|
||||
json = com.alibaba.fastjson.JSONObject.parseObject(new String(b1));
|
||||
}else {
|
||||
byte[] b1 = RSAUtil.decrypt(privateKey, userInfo);
|
||||
json = com.alibaba.fastjson.JSONObject.parseObject(new String(b1));
|
||||
}
|
||||
|
||||
log.info("解码后用户信息={}",json.toString());
|
||||
String identityNo = json.getString("cardNo");
|
||||
// String identityNo = "340321199705196996";
|
||||
/* String identityNo = request.getParameter("userInfo");
|
||||
String policeId = "999013";*/
|
||||
String clientId = "e5cd7e4891bf95d1d19206ce24a7b32e";
|
||||
String grantType = "sso";
|
||||
RemoteClientVo clientVo = remoteClientService.queryByClientId(clientId);
|
||||
SsoLoginBody loginBody = new SsoLoginBody();
|
||||
loginBody.setClientId(clientId);
|
||||
loginBody.setGrantType(grantType);
|
||||
loginBody.setIdcard(identityNo);
|
||||
LoginVo loginVo = IAuthStrategy.login(JsonUtils.toJsonString(loginBody), clientVo, grantType);
|
||||
response.sendRedirect(ssoProperties.getRedirctUrl()+loginVo.getAccessToken()+"&clientId="+loginVo.getClientId());
|
||||
}
|
||||
|
||||
|
||||
private static final Pattern ENCODED_PATTERN = Pattern.compile("%[0-9A-Fa-f]{2}");
|
||||
|
||||
/**
|
||||
* 判断给定的字符串是否包含URL编码的内容(即可能需要解码)
|
||||
* @param str 待检查的字符串
|
||||
* @return true 表示字符串包含URL编码模式,建议尝试解码;false 表示没有发现编码模式
|
||||
*/
|
||||
public static boolean needsUrlDecode(String str) {
|
||||
if (str == null || str.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
return ENCODED_PATTERN.matcher(str).find();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 第三方获取Token
|
||||
*
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
package org.dromara.auth.form;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.dromara.common.core.domain.model.LoginBody;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class SsoLoginBody extends LoginBody {
|
||||
|
||||
//身份证号码
|
||||
private String idcard;
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package org.dromara.auth.properties;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Data
|
||||
@Configuration
|
||||
@RefreshScope
|
||||
@ConfigurationProperties(prefix = "ds.sso")
|
||||
public class DsSsoProperties {
|
||||
|
||||
private String url;
|
||||
|
||||
private String clientId;
|
||||
|
||||
private String clientSecret;
|
||||
|
||||
//返回前端的地址
|
||||
private String redirctUrl;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
package org.dromara.auth.service.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.SaLoginModel;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.dromara.auth.domain.vo.LoginVo;
|
||||
import org.dromara.auth.form.SsoLoginBody;
|
||||
import org.dromara.auth.service.IAuthStrategy;
|
||||
import org.dromara.auth.service.SysLoginService;
|
||||
import org.dromara.common.json.utils.JsonUtils;
|
||||
import org.dromara.common.satoken.utils.LoginHelper;
|
||||
import org.dromara.system.api.RemoteUserService;
|
||||
import org.dromara.system.api.domain.vo.RemoteClientVo;
|
||||
import org.dromara.system.api.model.LoginUser;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/*
|
||||
* 单点登录
|
||||
* 不用密码 根据jwt解析到的身份证登录
|
||||
* */
|
||||
@Slf4j
|
||||
@Service("sso" + IAuthStrategy.BASE_NAME)
|
||||
@RequiredArgsConstructor
|
||||
public class SsoAuthStrategy implements IAuthStrategy {
|
||||
|
||||
|
||||
private final SysLoginService loginService;
|
||||
|
||||
@DubboReference
|
||||
private RemoteUserService remoteUserService;
|
||||
|
||||
@Override
|
||||
public LoginVo login(String body, RemoteClientVo client) {
|
||||
SsoLoginBody loginBody = JsonUtils.parseObject(body, SsoLoginBody.class);
|
||||
// ValidatorUtils.validate(loginBody);
|
||||
String tenantId = loginBody.getTenantId();
|
||||
String idcard = loginBody.getIdcard();
|
||||
LoginUser loginUser = remoteUserService.getUserInfoByIdCard(idcard, tenantId);
|
||||
// loginService.checkLogin(LoginType.PASSWORD, tenantId, username); //此处不需要验证
|
||||
loginUser.setClientKey(client.getClientKey());
|
||||
loginUser.setDeviceType(client.getDeviceType());
|
||||
SaLoginModel model = new SaLoginModel();
|
||||
model.setDevice(client.getDeviceType());
|
||||
// 自定义分配 不同用户体系 不同 token 授权时间 不设置默认走全局 yml 配置
|
||||
// 例如: 后台用户30分钟过期 app用户1天过期
|
||||
model.setTimeout(client.getTimeout());
|
||||
model.setActiveTimeout(client.getActiveTimeout());
|
||||
model.setExtra(LoginHelper.CLIENT_KEY, client.getClientId());
|
||||
// 生成token
|
||||
LoginHelper.login(loginUser, model);
|
||||
|
||||
LoginVo loginVo = new LoginVo();
|
||||
loginVo.setAccessToken(StpUtil.getTokenValue());
|
||||
loginVo.setExpireIn(StpUtil.getTokenTimeout());
|
||||
loginVo.setClientId(client.getClientId());
|
||||
return loginVo;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,215 @@
|
|||
package org.dromara.auth.util;
|
||||
|
||||
|
||||
import cn.hutool.core.net.URLDecoder;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
|
||||
import javax.crypto.BadPaddingException;
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.IllegalBlockSizeException;
|
||||
import javax.crypto.NoSuchPaddingException;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.*;
|
||||
import java.security.interfaces.RSAPrivateKey;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
import java.security.spec.PKCS8EncodedKeySpec;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
||||
/**
|
||||
* 非对称加密算法RSA算法组件 非对称算法一般是用来传送对称加密算法的密钥来使用的,相对于DH算法,RSA算法只需要一方构造密钥,不需要
|
||||
* 大费周章的构造各自本地的密钥对了。DH算法只能算法非对称算法的底层实现。而RSA算法算法实现起来较为简单
|
||||
*
|
||||
* @author kfchen
|
||||
* @version 1.0.1
|
||||
* @date 2019-09-12
|
||||
*/
|
||||
public class RSAUtil {
|
||||
|
||||
public static final String KEY_ALGORITHM = "RSA";
|
||||
|
||||
private static org.bouncycastle.jce.provider.BouncyCastleProvider bouncyCastleProvider = null;
|
||||
|
||||
/**
|
||||
* 取唯一BouncyCastleProvider
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static synchronized org.bouncycastle.jce.provider.BouncyCastleProvider getBcpInstance() {
|
||||
if (bouncyCastleProvider == null) {
|
||||
bouncyCastleProvider = new org.bouncycastle.jce.provider.BouncyCastleProvider();
|
||||
}
|
||||
return bouncyCastleProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* 私钥解密过程
|
||||
*
|
||||
* @param privateKeyStr 私钥
|
||||
* @param data 密文数据
|
||||
* @return 明文
|
||||
* @throws Exception 解密过程中的异常信息
|
||||
*/
|
||||
public static byte[] decryptForJSEncrypt(String privateKeyStr, String data)
|
||||
throws Exception {
|
||||
RSAPrivateKey privateKey = loadPrivateKeyByStr(privateKeyStr);
|
||||
if (privateKey == null) {
|
||||
throw new Exception("解密私钥为空, 请设置");
|
||||
}
|
||||
Cipher cipher = null;
|
||||
try {
|
||||
// 使用默认RSA
|
||||
cipher = Cipher.getInstance("RSA");
|
||||
byte[] cipherData = Base64.decodeBase64(data.getBytes());
|
||||
cipher.init(Cipher.DECRYPT_MODE, privateKey);
|
||||
byte[] output = cipher.doFinal(cipherData);
|
||||
return output;
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new Exception("无此解密算法");
|
||||
} catch (NoSuchPaddingException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} catch (InvalidKeyException e) {
|
||||
throw new Exception("解密私钥非法,请检查");
|
||||
} catch (IllegalBlockSizeException e) {
|
||||
throw new Exception("密文长度非法");
|
||||
} catch (BadPaddingException e) {
|
||||
throw new Exception("密文数据已损坏");
|
||||
}
|
||||
}
|
||||
|
||||
public static RSAPrivateKey loadPrivateKeyByStr(String privateKeyStr)
|
||||
throws Exception {
|
||||
try {
|
||||
byte[] buffer = Base64.decodeBase64(privateKeyStr);
|
||||
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(buffer);
|
||||
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
|
||||
return (RSAPrivateKey) keyFactory.generatePrivate(keySpec);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new Exception("无此算法");
|
||||
} catch (InvalidKeySpecException e) {
|
||||
throw new Exception("私钥非法");
|
||||
} catch (NullPointerException e) {
|
||||
throw new Exception("私钥数据为空");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* * 解密 *
|
||||
*
|
||||
* @param privateKey 解密的密钥 *
|
||||
* @param data 已经加密的数据 *
|
||||
* @return 解密后的明文 *
|
||||
* @throws Exception
|
||||
*/
|
||||
public static byte[] decrypt(String privateKey, String data) throws Exception {
|
||||
try {
|
||||
byte[] raw = decryptBASE64(data);
|
||||
// 对密钥解密
|
||||
byte[] keyBytes = decryptBASE64(privateKey);
|
||||
// 取得私钥
|
||||
PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(keyBytes);
|
||||
KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM);
|
||||
PrivateKey pk = keyFactory.generatePrivate(pkcs8KeySpec);
|
||||
|
||||
Cipher cipher = Cipher.getInstance("RSA", getBcpInstance());
|
||||
cipher.init(cipher.DECRYPT_MODE, pk);
|
||||
int blockSize = cipher.getBlockSize();
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream(64);
|
||||
int j = 0;
|
||||
|
||||
while (raw.length - j * blockSize > 0) {
|
||||
bout.write(cipher.doFinal(raw, j * blockSize, blockSize));
|
||||
j++;
|
||||
}
|
||||
return bout.toByteArray();
|
||||
} catch (Exception e) {
|
||||
throw new Exception(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加密<br>
|
||||
* 用私钥加密
|
||||
*
|
||||
* @param data
|
||||
* @param key
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static byte[] encryptByPrivateKey(byte[] data, String key) throws Exception {
|
||||
// 对密钥解密
|
||||
byte[] keyBytes = decryptBASE64(key);
|
||||
// 取得私钥
|
||||
PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(keyBytes);
|
||||
KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM);
|
||||
Key privateKey = keyFactory.generatePrivate(pkcs8KeySpec);
|
||||
// 对数据加密
|
||||
Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm());
|
||||
cipher.init(Cipher.ENCRYPT_MODE, privateKey);
|
||||
return cipher.doFinal(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* base64解密
|
||||
*/
|
||||
public static byte[] decryptBASE64(String key) {
|
||||
return Base64.decodeBase64(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* base64加密
|
||||
*/
|
||||
public static String encryptBASE64(byte[] bytes) {
|
||||
return Base64.encodeBase64String(bytes);
|
||||
}
|
||||
|
||||
// 预编译正则表达式,匹配 % 后跟两个十六进制字符
|
||||
private static final Pattern ENCODED_PATTERN = Pattern.compile("%[0-9A-Fa-f]{2}");
|
||||
|
||||
/**
|
||||
* 判断给定的字符串是否包含URL编码的内容(即可能需要解码)
|
||||
* @param str 待检查的字符串
|
||||
* @return true 表示字符串包含URL编码模式,建议尝试解码;false 表示没有发现编码模式
|
||||
*/
|
||||
public static boolean needsUrlDecode(String str) {
|
||||
if (str == null || str.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
return ENCODED_PATTERN.matcher(str).find();
|
||||
}
|
||||
|
||||
/**
|
||||
* main
|
||||
*/
|
||||
public static void main(String[] args) throws Exception {
|
||||
String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC7V+wyxy6D+lBNHfz1eSF7NJ3QSpAJ/9P+4uDv8w1MKm0lzQKmbNJEHaKr3zzQzlRrWdo675DuqVtCtMVCR1oha5ONEaxo8uYazTSOlLRVDEjL/JDcIQIL+1Zn7p/pu3UusmHVxQQTFftxK7MS6uWd/TeNr5sYmseT27922rNlVQIDAQAB";//RSACoder.getPublicKey(keyMap);
|
||||
// String privateKey = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBALtX7DLHLoP6UE0d/PV5IXs0ndBKkAn/0/7i4O/zDUwqbSXNAqZs0kQdoqvfPNDOVGtZ2jrvkO6pW0K0xUJHWiFrk40RrGjy5hrNNI6UtFUMSMv8kNwhAgv7Vmfun+m7dS6yYdXFBBMV+3ErsxLq5Z39N42vmxiax5Pbv3bas2VVAgMBAAECgYA2KtzTbb3oUQbI1WPfge+JVRRQNk7hZUPhja3mEwuEOzwl0tnyTsKZCUyQj1JhOVc1Vtx/b+ci6nrFlcj3OfQ3+NXhShUSnAXopjlL/1TNA5WNDqqlG8R0IaA/zvqmcr9j55idGvGAcN7Us/EWZjqWNFkZ7jJhUDwXNRtjCpqhIQJBAOF1sMqZKAVdE8ugYTw8XgPWcO/CFd/UKNP/IReC7/i36zDIwnFinPEa5vmvPk5ff3B4K482N7vS0ztGQeTUGhkCQQDUuHd0EmuQYI5VYbpeEIBJ8uTnEJ/9Jik3FqAxJpo5+vRuxYb6Ul57rMMP0vlTwm92NXhRwVVmQLML81kqzwSdAkBKlVRWsTO8En5p7jQ8aPvw6Q+TQPFbiiO3fb7EuFwKO01iZgds2uJwICYokwBZjN3rptVCGv109NlL0oIZ4NCBAkAhU/WDPg+UQ0yJnBIzAqrW6zNp8HTgmMYEV4spqD6pruP1JwWK2rTq85psNEXUFbaY8q+zP3M93g0vZiUmS+ERAkEA0lBhEJcJWhc9WPoWLqA5HKxUoKkJzgC2ljeTxtz6oY/YdLErq4FUcM3RIGG6kYqMIjrZfww+jqjJ4v8lIZgh4A==";//RSACoder.getPrivateKey(keyMap);
|
||||
String privateKey = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAMSmBCx1ghaVLT/x96ERi9lo3XY/dzKFc9y5f7RtPJihU6fijX4eFSNrhJAjnP2pkJfCXLEmaPznmoUfrUhmq3yeXNzRNILQ+XAUcGkX13oMqW9qM/u5ZHlBnBwMiCZVOZ4pmaZ+hgA8jiNjhh1AqBkRpbvlfnlyC0fBv5FcXOQ3AgMBAAECgYBhfp2bHTc90v/4MBLBfF2FkIQb2CNUnO1whVdXMMFWOsWq+puD5447XVb/z2hKKwNQ+j/SZGSw3nKxhZ73wk9KPkGo9o4gjdwbgo6Qnk8sGQFpCg+5aFH1CgMy5PaM2ZcxbPOfO7tardS1D9u3Vm88688Qdk5sLLWkf6JuNP6LIQJBAPQ4w4qMOfI7Uss90A7/SGHWUjzLvsEv5eq/jXpRhJnyX5tHDCgPCq4CQKwBfUbzdapMtsf065aZCWZR51+V3g0CQQDOIeYX3TTDadzg/cC8tG/AVnxbsoY2Cy9fXmzJCfXIOxZPQIL1WF7HDveTXRxhp6CjSkzVcFJ9K1MFbl/WCf5TAkBqqawFg87/E5fKelm3Yxlq2Z8bPGU4nMHO8BBLXvUKA4hsGfCeQkuIyiUSuqfLaCN42H5wAHEwWfB4BseFwL+1AkBgqfrp4/0TSnifNcAFfiQNsUD+C1juzQ35DiG7oSUWMcdDgQAop7lCZd1pyLc/gElPac9gJB06v29eU6UzjVorAkEAymdUmrgcezAi+aMA0+QcenvPiom3jQkduvfBjOiSLSWm5oB8+mMlExl8Vm9FtKMms6zOs/LcTZzxonl//oe4Ag==";
|
||||
// 私钥解密 "abcd#123456"
|
||||
String s1 = "pa+6STSQ5ZK94/xMzLE4VCFnbYgan1oUADGv0N07fu1QXfzuVoLLDPyPbduFQwxVB1ZFbkrJIhB56ZtkdqN0A12bNQ13MylyfJfL3NJTUJYukINmAOB8WgB8t9ZIyH2EZRK6YbtGgy2MS6YsisJ93G4ofrEHkv4r3nnl++9ZUzE=";
|
||||
// String userInfo = "Hwlfh/41CulvHFgenFTv%2BUiyN2CaXz9s0ypdy9yN1TkrtNARpfkpgjDJF7ZETfdmNDNRedkdOeNThZB0Ma23UQ5RHD4dr6DWV9LhZisxpY1nm3IN49F/Pz9Z0CUh//ttXT0f35B86UXwNni0ITLgfH0kMCA9aoShmtU0eg01EqB9CthbVeCKjVudYnR4VG%2B%2Bb%2BStYNnFpa0pcyPvf8F5GtPPuQGQYn9SbfL52i8gEFPi3oshVxlQBzi9yy/r%2BL%2B8LtiBp1ojeGe6n1D0HB8/RRqPWn7PxXKHvqCiwmHTkDClJlXNdWxzkZPzZSMi5nrL9QEZSGQ91oSHzlI/suUKWg==";
|
||||
// byte[] b1 = decrypt(privateKey, URLDecoder.decode(userInfo, StandardCharsets.UTF_8) );
|
||||
String userInfo = "iu6HWB0lqozQ5UQxvtZDy2CdlMSOaJ4fXHduRLtQpnzj/m5pAbaOyWZ0rUe+sqIc887XgdTjNODEeFtM6adgBmS6DZmzAYIt+6I/o5Me7HUVl/EpMwO1PlT98lz/mzOXdPHGZTv/6DLXEDxR3fr17agP6oXq/YbrPsClJ1e5K/qpxNxCqgEv03Kl7gM27ZHBs0PCkUyzv8Wj3yES28tTYpJyKKK4LZvEt1S7c+g9WT+GgjO9tLEh4lUxyVKmBEAJfKcrCQzcu8e3E8yRjNdtqyk3/XTF/kagoSTHFqt3EHxdQBXM8XM2xzkZNcdohaWD7JuaiWXHsuLCtYVO5dYY+Q==";
|
||||
JSONObject json = null;
|
||||
if (needsUrlDecode(userInfo)){
|
||||
byte[] b1 = RSAUtil.decrypt(privateKey, URLDecoder.decode(userInfo, StandardCharsets.UTF_8));
|
||||
json = JSONObject.parseObject(new String(b1));
|
||||
}else {
|
||||
byte[] b1 = RSAUtil.decrypt(privateKey, userInfo);
|
||||
json = JSONObject.parseObject(new String(b1));
|
||||
}
|
||||
byte[] b1 = decrypt(privateKey, userInfo);
|
||||
System.out.println(new String(b1));
|
||||
// JSONObject json = JSONObject.parseObject(new String(b1));
|
||||
|
||||
// 私钥加密 "abcd#123456"
|
||||
String s2 = "abcd#123456";
|
||||
byte[] b2 = encryptByPrivateKey(s2.getBytes(),privateKey);
|
||||
// 转base64字符串后作为参数发送
|
||||
String s = encryptBASE64(b2);
|
||||
// System.out.println(s);
|
||||
}
|
||||
}
|
||||
|
|
@ -33,13 +33,11 @@ public class BaseEntity implements Serializable {
|
|||
/**
|
||||
* 创建部门
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private String createDept;
|
||||
|
||||
/**
|
||||
* 创建者
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Long createBy;
|
||||
|
||||
/**
|
||||
|
|
@ -51,7 +49,6 @@ public class BaseEntity implements Serializable {
|
|||
/**
|
||||
* 更新者
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private Long updateBy;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -106,6 +106,9 @@ public class SysUser extends TenantEntity {
|
|||
private String manageDeptId;
|
||||
|
||||
|
||||
private String idCard;
|
||||
|
||||
|
||||
public SysUser(Long userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,6 +87,8 @@ public class SysUserBo extends BaseEntity {
|
|||
*/
|
||||
private String remark;
|
||||
|
||||
private String idCard;
|
||||
|
||||
/**
|
||||
* 角色组
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -114,6 +114,8 @@ public class SysUserVo implements Serializable {
|
|||
private Date createTime;
|
||||
|
||||
private String manageDeptId;
|
||||
|
||||
private String idCard;
|
||||
/**
|
||||
* 部门名
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -140,6 +140,29 @@ public class RemoteUserServiceImpl implements RemoteUserService {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过身份证查询用户信息
|
||||
*
|
||||
* @param idCard 身份证
|
||||
* @param tenantId 租户id
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public LoginUser getUserInfoByIdCard(String idCard, String tenantId) throws UserException {
|
||||
return TenantHelper.dynamic(tenantId, () -> {
|
||||
SysUserVo sysUser = userMapper.selectVoOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getIdCard, idCard));
|
||||
if (ObjectUtil.isNull(sysUser)) {
|
||||
throw new UserException("user.not.exists", idCard);
|
||||
}
|
||||
if (UserStatus.DISABLE.getCode().equals(sysUser.getStatus())) {
|
||||
throw new UserException("user.blocked", idCard);
|
||||
}
|
||||
// 框架登录不限制从什么表查询 只要最终构建出 LoginUser 即可
|
||||
// 此处可根据登录用户的数据不同 自行创建 loginUser 属性不够用继承扩展就行了
|
||||
return buildLoginUser(sysUser);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过openid查询用户信息
|
||||
*
|
||||
|
|
|
|||
|
|
@ -47,6 +47,6 @@ public interface SysDeptMapper extends BaseMapperPlus<SysDept, SysDeptVo> {
|
|||
|
||||
List<SysDeptVo> deviceStaticsByDeptId(@Param("deviceType")String deviceType, @Param("deptId")String deptId);
|
||||
|
||||
List<SysDept> jzDept(String updateTime);
|
||||
List<SysDeptVo> jzDept(String updateTime);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,4 +88,12 @@ public interface SysUserMapper extends BaseMapperPlus<SysUser, SysUserVo> {
|
|||
})
|
||||
int updateById(@Param(Constants.ENTITY) SysUser user);
|
||||
|
||||
List<SysUser> jzUser(String updateTime);
|
||||
|
||||
Page<SysUser> jzUserPage(@Param("page") Page<SysUser> page, @Param(Constants.WRAPPER) Wrapper<SysUser> queryWrapper);
|
||||
|
||||
int insertUser(SysUser user);
|
||||
|
||||
int updateUser(SysUser user);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package org.dromara.system.schedule;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.date.DateUnit;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
|
|
@ -8,6 +9,7 @@ import com.alibaba.fastjson.JSONArray;
|
|||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.dromara.system.domain.SysDept;
|
||||
import org.dromara.system.domain.vo.SysDeptVo;
|
||||
import org.dromara.system.service.ISysDeptService;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
|
@ -84,4 +86,41 @@ public class JzDeptSchedule {
|
|||
}
|
||||
|
||||
|
||||
@RequestMapping("/insertJzDeptAll")
|
||||
public void insertJzDeptAll(){
|
||||
List<SysDeptVo> list = deptService.jzDpet("");
|
||||
List<SysDeptVo> sysList = new ArrayList<>();
|
||||
for (SysDeptVo dept : list) {
|
||||
if (!"1".equals(dept.getStatus())){
|
||||
continue; //删除的不入库
|
||||
}
|
||||
dept.setStatus("0");
|
||||
dept.setShortName(dept.getDeptName());
|
||||
sysList.add(dept);
|
||||
}
|
||||
deptService.insertBatch(BeanUtil.copyToList(sysList, SysDept.class));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Scheduled(cron = "0 0 0/1 * * ?")
|
||||
public void jzDeptNew(){
|
||||
Date time = DateUtil.offsetHour(new Date(),-1);
|
||||
List<SysDeptVo> list = deptService.jzDpet(DateUtil.formatDateTime(time));
|
||||
List<SysDeptVo> sysList = new ArrayList<>();
|
||||
for (SysDeptVo dept : list) {
|
||||
if ("1".equals(dept.getStatus())){
|
||||
dept.setStatus("0");
|
||||
}else {
|
||||
dept.setStatus("1");
|
||||
}
|
||||
dept.setShortName(dept.getDeptName());
|
||||
sysList.add(dept);
|
||||
}
|
||||
deptService.insertORUpdate(BeanUtil.copyToList(sysList, SysDept.class));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,62 @@
|
|||
package org.dromara.system.schedule;
|
||||
|
||||
import cn.dev33.satoken.secure.BCrypt;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import org.dromara.system.domain.SysUser;
|
||||
import org.dromara.system.service.ISysUserService;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
public class JzUserSchedule {
|
||||
|
||||
private final ISysUserService userService;
|
||||
|
||||
@RequestMapping("/insertJzUserAll")
|
||||
public void insertJzUserAll(int pageNum,int pageSize){
|
||||
PageQuery query = new PageQuery();
|
||||
query.setPageNum(pageNum);
|
||||
query.setPageSize(pageSize);
|
||||
Page<SysUser> page = userService.jzUserPage(query);
|
||||
List<SysUser> jzlist = page.getRecords();
|
||||
List<SysUser> syslist = new ArrayList<>();
|
||||
for (SysUser user: jzlist) {
|
||||
if (user.getStatus().equals("-99")){
|
||||
continue;
|
||||
}
|
||||
user.setStatus("0");
|
||||
user.setPassword(BCrypt.hashpw("123456"));
|
||||
user.setManageDeptId(user.getDeptId());
|
||||
syslist.add(user);
|
||||
}
|
||||
userService.insertBatch(syslist);
|
||||
}
|
||||
|
||||
// @Scheduled(cron = "0 0 0/1 * * ?")
|
||||
public void jzUser(){
|
||||
Date time = DateUtil.offsetHour(new Date(),-1);
|
||||
List<SysUser> jzlist = userService.jzUser(DateUtil.formatDateTime(time));
|
||||
List<SysUser> syslist = new ArrayList<>();
|
||||
for (SysUser user: jzlist) {
|
||||
if (user.getStatus().equals("-99")){
|
||||
user.setStatus("1");
|
||||
}else {
|
||||
user.setStatus("0");
|
||||
}
|
||||
user.setPassword(BCrypt.hashpw("123456"));
|
||||
user.setManageDeptId(user.getDeptId());
|
||||
syslist.add(user);
|
||||
}
|
||||
userService.insertORUpdate(syslist);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -140,7 +140,9 @@ public interface ISysDeptService {
|
|||
|
||||
List<SysDeptVo> deviceStatics(String deviceType,String manageDeptId);
|
||||
|
||||
List<SysDept> jzDpet(String updateTime);
|
||||
List<SysDeptVo> jzDpet(String updateTime);
|
||||
|
||||
boolean insertBatch(List<SysDept> list);
|
||||
|
||||
boolean insertORUpdate(List<SysDept> list);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
package org.dromara.system.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
import org.dromara.system.domain.SysUser;
|
||||
import org.dromara.system.domain.bo.SysUserBo;
|
||||
import org.dromara.system.domain.vo.SysUserExportVo;
|
||||
import org.dromara.system.domain.vo.SysUserVo;
|
||||
|
|
@ -268,4 +270,15 @@ public interface ISysUserService {
|
|||
*/
|
||||
List<Long> selectUserIdsByRoleIds(List<Long> roleIds);
|
||||
|
||||
/*
|
||||
* 警综用户
|
||||
* */
|
||||
List<SysUser> jzUser(String updateTime);
|
||||
|
||||
Page<SysUser> jzUserPage(PageQuery pageQuery);
|
||||
|
||||
boolean insertBatch(List<SysUser> list);
|
||||
|
||||
boolean insertORUpdate(List<SysUser> list);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -390,10 +390,16 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|||
|
||||
@Override
|
||||
@DS("slave")
|
||||
public List<SysDept> jzDpet(String updateTime) {
|
||||
public List<SysDeptVo> jzDpet(String updateTime) {
|
||||
return baseMapper.jzDept(updateTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean insertBatch(List<SysDept> list) {
|
||||
return baseMapper.insertBatch(list,500);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean insertORUpdate(List<SysDept> list) {
|
||||
List<BatchResult> batchResults = baseMapper.insertOrUpdate(list);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
|
|||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
|
|
@ -626,4 +627,46 @@ public class SysUserServiceImpl implements ISysUserService {
|
|||
return ObjectUtil.isNull(sysUser) ? null : sysUser.getEmail();
|
||||
}
|
||||
|
||||
@Override
|
||||
@DS("slave")
|
||||
public List<SysUser> jzUser(String updateTime) {
|
||||
return baseMapper.jzUser(updateTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
@DS("slave")
|
||||
public Page<SysUser> jzUserPage(PageQuery pageQuery) {
|
||||
LambdaQueryWrapper<SysUser> lqw = new LambdaQueryWrapper<>();
|
||||
lqw.eq(SysUser::getUserType,"SYS");
|
||||
lqw.orderByAsc(SysUser::getUserId);
|
||||
Page<SysUser> userPage = baseMapper.jzUserPage(pageQuery.build(),lqw);
|
||||
return userPage;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean insertBatch(List<SysUser> list) {
|
||||
|
||||
return baseMapper.insertBatch(list,1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean insertORUpdate(List<SysUser> list) {
|
||||
for (SysUser user : list) {
|
||||
SysUser u = baseMapper.selectOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUserName,user.getUserName()).last("limit 1"));
|
||||
if (null != u){
|
||||
user.setUserId(u.getUserId());
|
||||
baseMapper.updateUser(user);
|
||||
}else {
|
||||
baseMapper.insertUser(user);
|
||||
SysUserRole userRole = new SysUserRole();
|
||||
userRole.setRoleId(4l);
|
||||
userRole.setUserId(user.getUserId());
|
||||
userRoleMapper.insert(userRole);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,5 +69,68 @@
|
|||
select count(*) from sys_user where del_flag = '0' and user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<select id="jzUser" resultMap="SysUserResult">
|
||||
select user_id,dept_id,user_name,nick_name,phonenumber,sex,status,idcard id_card from sys_user
|
||||
where user_type = 'SYS' and dept_id like '3416%'
|
||||
<if test="updateTime != null and '' != updateTime ">
|
||||
and update_time >= #{updateTime}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="jzUserPage" resultMap="SysUserResult">
|
||||
select user_id,dept_id,user_name,nick_name,phonenumber,sex,status,idcard id_card from sys_user
|
||||
${ew.getCustomSqlSegment}
|
||||
</select>
|
||||
|
||||
<insert id="insertUser" parameterType="org.dromara.system.domain.SysUser">
|
||||
insert into sys_user(
|
||||
<if test="userId != null and userId != 0">user_id,</if>
|
||||
<if test="deptId != null and deptId != 0">dept_id,</if>
|
||||
<if test="userName != null and userName != ''">user_name,</if>
|
||||
<if test="nickName != null and nickName != ''">nick_name,</if>
|
||||
<if test="userType != null and userType != ''">user_type,</if>
|
||||
<if test="email != null and email != ''">email,</if>
|
||||
<if test="phonenumber != null and phonenumber != ''">phonenumber,</if>
|
||||
<if test="sex != null and sex != ''">sex,</if>
|
||||
<if test="password != null and password != ''">password,</if>
|
||||
<if test="status != null and status != ''">status,</if>
|
||||
<if test="manageDeptId != null and manageDeptId != ''">manage_dept_id,</if>
|
||||
<if test="idCard != null and idCard != ''">id_card,</if>
|
||||
create_time
|
||||
)values(
|
||||
<if test="userId != null and userId != ''">#{userId},</if>
|
||||
<if test="deptId != null and deptId != ''">#{deptId},</if>
|
||||
<if test="userName != null and userName != ''">#{userName},</if>
|
||||
<if test="nickName != null and nickName != ''">#{nickName},</if>
|
||||
<if test="userType != null and userType != ''">#{userType},</if>
|
||||
<if test="email != null and email != ''">#{email},</if>
|
||||
<if test="phonenumber != null and phonenumber != ''">#{phonenumber},</if>
|
||||
<if test="sex != null and sex != ''">#{sex},</if>
|
||||
<if test="password != null and password != ''">#{password},</if>
|
||||
<if test="status != null and status != ''">#{status},</if>
|
||||
<if test="manageDeptId != null and manageDeptId != ''">#{manageDeptId},</if>
|
||||
<if test="idCard != null and idCard != ''">#{idCard},</if>
|
||||
#{createTime}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="updateUser" parameterType="org.dromara.system.domain.SysUser">
|
||||
update sys_user
|
||||
<set>
|
||||
<if test="deptId != null and deptId != 0">dept_id = #{deptId},</if>
|
||||
<if test="userName != null and userName != ''">user_name = #{userName},</if>
|
||||
<if test="idCard != null and idCard != ''">id_card = #{idCard},</if>
|
||||
<if test="nickName != null and nickName != ''">nick_name = #{nickName},</if>
|
||||
<if test="email != null ">email = #{email},</if>
|
||||
<if test="phonenumber != null ">phonenumber = #{phonenumber},</if>
|
||||
<if test="sex != null and sex != ''">sex = #{sex},</if>
|
||||
<if test="password != null and password != ''">password = #{password},</if>
|
||||
<if test="status != null and status != ''">status = #{status},</if>
|
||||
<if test="manageDeptId != null manageDeptId != ''">manage_dept_id = #{manageDeptId},</if>
|
||||
update_time = #{updateTime}
|
||||
</set>
|
||||
where user_id = #{userId}
|
||||
</update>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
|
|
|||
Loading…
Reference in New Issue