main
kgdxpr 2 years ago
parent f749c92567
commit ca35662cb3

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="AdditionalModuleElements">
<content url="file://$MODULE_DIR$" dumb="true">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resource" type="java-resource" />
</content>
</component>
</module>

@ -1,6 +1,5 @@
package Tools.TestUnit;
import com.dsideal.FengHuang.Util.MysqlAesUtil;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.Db;

@ -1,7 +1,6 @@
package Tools.mysql;
import com.dsideal.FengHuang.Util.CommonUtil;
import com.dsideal.FengHuang.Util.MysqlAesUtil;
import com.dsideal.FengHuang.Util.PkUtil;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;

@ -1,7 +1,6 @@
package Tools.mysql;
import com.dsideal.FengHuang.Util.CommonUtil;
import com.dsideal.FengHuang.Util.MysqlAesUtil;
import com.dsideal.FengHuang.Util.PkUtil;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;

@ -28,21 +28,21 @@ public class Full {
//OrgPerson.delAllDept(accessToken, rOrg);
//初始化组织机构
//OrgPerson.InitOrg(accessToken, rOrg);
// OrgPerson.InitOrg(accessToken, rOrg);
//同步人员
OrgPerson.initPerson(accessToken, rOrg,10);//这里限定了上限人数为10
// OrgPerson.initPerson(accessToken, rOrg,10);//这里限定了上限人数为10
//初始化角色组
//long groupId = RolePerson.createRoleGroup(accessToken, "义务教育阶段角色组");
//初始化角色
//RolePerson.initRole(accessToken, groupId);
// RolePerson.initRole(accessToken, groupId);
//同步人员角色信息
//RolePerson.initPersonRole(accessToken, rOrg);
RolePerson.initPersonRole(accessToken, rOrg);
// 记录全量同步完成时间
Model.finishInit();
// Model.finishInit();
CommonUtil.Print("恭喜,所有操作成功完成!");
}

@ -1,5 +1,10 @@
ALTER TABLE `dsideal_db`.`t_base_organization`
ADD COLUMN `dingtalk_dept_id` BIGINT NULL COMMENT '钉钉架构中机构的代码' AFTER `zydz`;
ALTER TABLE `dsideal_db`.`t_base_person`
ADD COLUMN `dingtalk_person_id` varchar(255) NULL COMMENT '钉钉架构中人员ID' AFTER `pay_rate`;
--ALTER TABLE `dsideal_db`.`t_base_person`
-- ADD COLUMN `dingtalk_person_id` varchar(255) NULL COMMENT '钉钉架构中人员ID' AFTER `pay_rate`;
-- 部门和角色ID用的是钉钉的人员ID用的是自已的

@ -29,7 +29,14 @@ public class OrgPerson {
req.setOrder(orderId);
req.setName(deptName);
if (isRoot) {
//是否限制本部门成员查看通讯录:
//true开启限制。开启后本部门成员只能看到限定范围内的通讯录
//false默认值不限制
req.setOuterDept(true);
//本部门成员是否只能看到所在部门及下级部门通讯录:
// true只能看到所在部门及下级部门通讯录
// false不能查看所有通讯录在通讯录中仅能看到自己
//当outer_dept为true时此参数生效。
req.setOuterDeptOnlySelf(true);
}
OapiV2DepartmentCreateResponse rsp = client.execute(req, access_token);
@ -238,7 +245,7 @@ public class OrgPerson {
createPerson(accessToken, deptId, person_id, person_name, tel, "教师");
DingTalkCommon.WriteActionTimes();
//回写标识
Model.writePersonDingTalkId(person_id);
// Model.writePersonDingTalkId(person_id);
CommonUtil.Print("成功加入人员:" + person_name);
}
}

@ -11,6 +11,7 @@ import com.jfinal.plugin.activerecord.Record;
import com.taobao.api.ApiException;
import java.util.*;
import java.util.stream.Collectors;
public class RolePerson {
@ -88,11 +89,26 @@ public class RolePerson {
public static void initPersonRole(String accessToken, Record rOrg) throws ApiException {
//获取云平台侧指定角色下人员信息
List<Record> listPeronRole = Model.getRolePersonReleation(rOrg);
for (Record record : listPeronRole) {
long dingtalk_role_id = record.getLong("dingtalk_role_id");
int person_id = record.getInt("person_id");
RolePerson.addRolePerson(accessToken, String.valueOf(dingtalk_role_id), String.valueOf(person_id));
DingTalkCommon.WriteActionTimes();
int batchSize = 20;
for (int i = 0; i < listPeronRole.size(); i += batchSize) {
int end = Math.min(i + batchSize, listPeronRole.size());
List<Record> batch = listPeronRole.subList(i, end);
// 在这里处理batch
processBatch(batch);
}
// for (Record record : listPeronRole) {
// long dingtalk_role_id = record.getLong("dingtalk_role_id");
// int person_id = record.getInt("person_id");
// RolePerson.addRolePerson(accessToken, String.valueOf(dingtalk_role_id), String.valueOf(person_id));
// DingTalkCommon.WriteActionTimes();
// }
}
private static void processBatch(List<Record> batch) {
String personIds = batch.stream().map(record -> record.getStr("person_id")).collect(Collectors.joining(","));
String roleIds = batch.stream().map(record -> record.getStr("dingtalk_role_id")).collect(Collectors.joining(","));
System.out.println(personIds);
System.out.println(roleIds);
}
}

@ -2,8 +2,6 @@ package com.dsideal.FengHuang.LoginPerson.Model;
import com.dsideal.FengHuang.Util.CommonUtil;
import com.dsideal.FengHuang.Util.IpUtil;
import com.dsideal.FengHuang.Util.MysqlAesUtil;
import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;

@ -2,7 +2,6 @@ package com.dsideal.FengHuang.Student.Model;
import com.dsideal.FengHuang.Util.CommonUtil;
import com.dsideal.FengHuang.Util.IpUtil;
import com.dsideal.FengHuang.Util.MysqlAesUtil;
import com.dsideal.FengHuang.Util.PkUtil;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;

@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.dsideal.FengHuang.Util.CommonUtil;
import com.dsideal.FengHuang.Util.IpUtil;
import com.dsideal.FengHuang.Util.MysqlAesUtil;
import com.dsideal.FengHuang.Util.PkUtil;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;

@ -1,56 +0,0 @@
package com.dsideal.FengHuang.Util;
import org.apache.commons.codec.binary.Base64;
import sun.misc.BASE64Encoder;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
public class Base64Util {
public static String imageToBase64(BufferedImage bufferedImage) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();//io流
try {
ImageIO.write(bufferedImage, "jpg", baos);//写入流中
} catch (IOException e) {
e.printStackTrace();
}
byte[] bytes = baos.toByteArray();//转换成字节
BASE64Encoder encoder = new BASE64Encoder();
String png_base64 = encoder.encodeBuffer(bytes).trim();//转换成base64串
png_base64 = png_base64.replaceAll("\n", "").replaceAll("\r", "");//删除 \r\n
return "data:image/jpg;base64," + png_base64;
}
/**
* FileBASE64
*
* @param file
* @return
*/
public static String fileToBase64(File file) {
return "data:image/png;base64," + Base64.encodeBase64String(fileToByte(file));
}
/**
* Filebyte[]
*
* @param file
* @return
*/
private static byte[] fileToByte(File file) {
byte[] fileBytes = null;
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
fileBytes = new byte[(int) file.length()];
fis.read(fileBytes);
fis.close();
} catch (Exception e) {
e.printStackTrace();
}
return fileBytes;
}
}

@ -1,88 +0,0 @@
package com.dsideal.FengHuang.Util;
import com.jfinal.kit.PropKit;
import com.jfinal.log.Log;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
@SuppressWarnings("unchecked")
public class MysqlAesUtil {
//在独立的main函数中使用下面的方式进行声明logback对象
private static Log log = Log.getLog(MysqlAesUtil.class);
/**
*
*
* 2019-01-07
* @param sSrc
* @return
* @throws Exception
*/
public static String Encrypt(String sSrc) throws Exception
{
String cKey=PropKit.get("AesPwd");
return Encrypt(sSrc,cKey);
}
/**
*
*
* 2019-01-07
* @param sSrc
* @return
*/
public static String Decrypt(String sSrc) {
String cKey=PropKit.get("AesPwd");
return Decrypt(sSrc,cKey);
}
// 加密
private static String Encrypt(String sSrc, String sKey) throws Exception {
if (sKey == null) {
log.info("Key为空null");
return null;
}
// 判断Key是否为16位
if (sKey.length() != 16) {
log.info("Key长度不是16位");
return null;
}
byte[] raw = sKey.getBytes("utf-8");
SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");//"算法/模式/补码方式"
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
byte[] encrypted = cipher.doFinal(sSrc.getBytes("utf-8"));
return new BASE64Encoder().encode(encrypted);//此处使用BASE64做转码功能同时能起到2次加密的作用。
}
// 解密
private static String Decrypt(String sSrc, String sKey) {
try {
// 判断Key是否正确
if (sKey == null) {
log.info("Key为空null");
return null;
}
// 判断Key是否为16位
if (sKey.length() != 16) {
log.info("Key长度不是16位");
return null;
}
byte[] raw = sKey.getBytes("utf-8");
SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, skeySpec);
byte[] encrypted1 = new BASE64Decoder().decodeBuffer(sSrc);//先用base64解密
try {
byte[] original = cipher.doFinal(encrypted1);
String originalString = new String(original,"utf-8");
return originalString;
} catch (Exception e) {
log.error(e.toString());
return sSrc;
}
} catch (Exception ex) {
log.error(ex.toString());
return sSrc;
}
}
}
Loading…
Cancel
Save