企业新增时创建企业用户

This commit is contained in:
韩国东 2023-01-09 10:54:51 +08:00
parent ad01bea72a
commit ec18eec4ec
3 changed files with 213 additions and 1 deletions

View File

@ -2679,6 +2679,50 @@ public class BaseController {
return url; return url;
} }
/**
* 新增企业用户
* @version v1.0
* @author dong
* @date 2023/1/6 15:23
*/
public void handleEetUser(String entId)throws Exception{
SysEnterprise enterprise = sysEnterpriseMapper.selectByPrimaryKey(entId);
if(null != enterprise){
EntPost entPost = new EntPost();
String postId = RandomNumber.getUUid();
entPost.setPostId(postId);
entPost.setEnterpriseId(enterprise.getSysenterpriseid());
entPost.setName("法人");
entPost.setPostPath(postId);
entPost.setParentName("法人");
entPost.setCreateBy("");
entPost.setCreateTime(new Date());
entPost.setModifyBy("");
entPost.setModifyTime(new Date());
entPostMapper.insertEntPost(entPost);
EntUser entUser = new EntUser();
String userId = RandomNumber.getUUid();
entUser.setEntUserId(userId);
entUser.setPostId(postId);
entUser.setEnterpriseId(enterprise.getSysenterpriseid());
entUser.setAccount(enterprise.getEntname());
entUser.setName(enterprise.getLegalrepre());
entUser.setMobile(enterprise.getLrlinktel());
entUser.setPostPath(postId);
entUser.setPostPathName(entPost.getName());
entUser.setCreateBy("");
entUser.setCreateTime(new Date());
entUser.setPasswd(MD5.md5(constantsConfigure.getDefaultPasswd()));
entUserMapper.insert(entUser);
}
//存企业用户
/**/
}
/** /**
* 普查的时候 创建企业用户 * 普查的时候 创建企业用户
* @throws Exception * @throws Exception

View File

@ -656,6 +656,7 @@ public class PcCompanyController extends com.rzyc.controller.BaseController {
sysEnterprise.setQrCode(entQrCode(sysEnterprise.getSysenterpriseid())); sysEnterprise.setQrCode(entQrCode(sysEnterprise.getSysenterpriseid()));
sysEnterpriseMapper.insert(sysEnterprise); sysEnterpriseMapper.insert(sysEnterprise);
handleEetUser(sysEnterprise.getSysenterpriseid());
}else { }else {
SysEnterprise verifyEnterprise = sysEnterpriseMapper.selectByName(sysEnterpriseDo.getEntname(),sysEnterpriseDo.getSysenterpriseid()); SysEnterprise verifyEnterprise = sysEnterpriseMapper.selectByName(sysEnterpriseDo.getEntname(),sysEnterpriseDo.getSysenterpriseid());
if (null != verifyEnterprise){ if (null != verifyEnterprise){
@ -688,7 +689,7 @@ public class PcCompanyController extends com.rzyc.controller.BaseController {
//生成行业对应的企业责任清单 //生成行业对应的企业责任清单
saveEntInList(sysEnterprise.getWorkClassId(),sysEnterprise.getSysenterpriseid()); saveEntInList(sysEnterprise.getWorkClassId(),sysEnterprise.getSysenterpriseid());
//创建或者修改企业用户 //创建或者修改企业用户
createEntUser(sysEnterprise,sysUser.getChinaname(),sysUser); // createEntUser(sysEnterprise,sysUser.getChinaname(),sysUser);
//生成清单 //生成清单
handleEntList(sysEnterprise.getSysenterpriseid()); handleEntList(sysEnterprise.getSysenterpriseid());

View File

@ -0,0 +1,167 @@
package com.rzyc.test;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONArray;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
/**
* @author dong
* @date 2023-01-07 16:06
* @Version V1.0
*/
public class MainTest {
/**
* 模拟缓存服务
*/
private static final Map<String,String> SYSTEM_CACHE = new HashMap <>();
/**
* ecology系统发放的授权许可证(appid)
*/
private static final String APPID = "EEAA5436-7577-4BE0-8C6C-89E9D88805EA";
public static void main(String[] args) {
// testRestful("http://172.21.3.100:88","/api/system/appmanage/route",null);
String jsonStr = "{\"params\":{\"pagesize\":20,\"curpage\":1}}";
Map<String,Object> a = new HashMap<>();
Map<String,Object> b = new HashMap<>();
b.put("pagesize",20);
b.put("curpage",1);
a.put("params",b);
System.out.println("a ---> "+JSONArray.toJSONString(a));
testRestful("http://172.21.3.100:88","/api/hrm/resful/getHrmdepartmentWithPage",JSONArray.toJSONString(a));
}
/**
* 第一步
*
* 调用ecology注册接口,根据appid进行注册,将返回服务端公钥和Secret信息
*/
public static Map<String,Object> testRegist(String address){
//获取当前系统RSA加密的公钥
RSA rsa = new RSA();
String publicKey = rsa.getPublicKeyBase64();
String privateKey = rsa.getPrivateKeyBase64();
// 客户端RSA私钥
SYSTEM_CACHE.put("LOCAL_PRIVATE_KEY",privateKey);
// 客户端RSA公钥
SYSTEM_CACHE.put("LOCAL_PUBLIC_KEY",publicKey);
//调用ECOLOGY系统接口进行注册
String data = HttpRequest.post(address + "/api/ec/dev/auth/regist")
.header("appid",APPID)
.header("cpk",publicKey)
.timeout(2000)
.execute().body();
// 打印ECOLOGY响应信息
System.out.println("testRegist()"+data);
Map<String,Object> datas = JSONUtil.parseObj(data);
//ECOLOGY返回的系统公钥
SYSTEM_CACHE.put("SERVER_PUBLIC_KEY",StrUtil.nullToEmpty((String)datas.get("spk")));
//ECOLOGY返回的系统密钥
SYSTEM_CACHE.put("SERVER_SECRET",StrUtil.nullToEmpty((String)datas.get("secrit")));
return datas;
}
/**
* 第二步
*
* 通过第一步中注册系统返回信息进行获取token信息
*/
public static Map<String,Object> testGetoken(String address){
// 从系统缓存或者数据库中获取ECOLOGY系统公钥和Secret信息
String secret = SYSTEM_CACHE.get("SERVER_SECRET");
String spk = SYSTEM_CACHE.get("SERVER_PUBLIC_KEY");
// 如果为空,说明还未进行注册,调用注册接口进行注册认证与数据更新
if (Objects.isNull(secret)||Objects.isNull(spk)){
testRegist(address);
// 重新获取最新ECOLOGY系统公钥和Secret信息
secret = SYSTEM_CACHE.get("SERVER_SECRET");
spk = SYSTEM_CACHE.get("SERVER_PUBLIC_KEY");
}
// 公钥加密,所以RSA对象私钥为null
RSA rsa = new RSA(null,spk);
//对秘钥进行加密传输防止篡改数据
String encryptSecret = rsa.encryptBase64(secret,CharsetUtil.CHARSET_UTF_8,KeyType.PublicKey);
//调用ECOLOGY系统接口进行注册
String data = HttpRequest.post(address+ "/api/ec/dev/auth/applytoken")
.header("appid",APPID)
.header("secret",encryptSecret)
.header("time","3600")
.execute().body();
System.out.println("testGetoken()"+data);
Map<String,Object> datas = JSONUtil.parseObj(data);
//ECOLOGY返回的token
// TODO 为Token缓存设置过期时间
SYSTEM_CACHE.put("SERVER_TOKEN",StrUtil.nullToEmpty((String)datas.get("token")));
return datas;
}
/**
* 第三步
*
* 调用ecology系统的rest接口请求头部带上token和用户标识认证信息
*
* @param address ecology系统地址
* @param api rest api 接口地址(该测试代码仅支持GET请求)
* @param jsonParams 请求参数json串
*
* 注意ECOLOGY系统所有POST接口调用请求头请设置 "Content-Type","application/x-www-form-urlencoded; charset=utf-8"
*/
public static String testRestful(String address,String api,String jsonParams){
//ECOLOGY返回的token
String token= SYSTEM_CACHE.get("SERVER_TOKEN");
if (StrUtil.isEmpty(token)){
token = (String) testGetoken(address).get("token");
}
String spk = SYSTEM_CACHE.get("SERVER_PUBLIC_KEY");
//封装请求头参数
RSA rsa = new RSA(null,spk);
//对用户信息进行加密传输,暂仅支持传输OA用户ID
String encryptUserid = rsa.encryptBase64("1",CharsetUtil.CHARSET_UTF_8,KeyType.PublicKey);
//调用ECOLOGY系统接口
// String data = HttpRequest.get(address + api)
// .header("appid",APPID)
// .header("token",token)
// .header("userid",encryptUserid)
// .body(jsonParams)
// .execute().body();
//调用ECOLOGY系统接口
String data = HttpRequest.post(address + api)
.header("appid",APPID)
.header("token",token)
.header("userid",encryptUserid)
.body(jsonParams)
.execute().body();
System.out.println("testRestful()"+data);
return data;
}
}