first commit
This commit is contained in:
377
src/main/java/com/example/sso/util/BeiSenTest.java
Normal file
377
src/main/java/com/example/sso/util/BeiSenTest.java
Normal file
@ -0,0 +1,377 @@
|
||||
package com.example.sso.util;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@Slf4j
|
||||
public class BeiSenTest {
|
||||
private static String app_key = "F493FDF0DA9B4DF3A826530B568E6BAF";
|
||||
private static String app_secret = "B9BAA96975C74DB8AF07EB5D5243F56DE2FAE0ED37D64797AB2487EA3F8011CD";
|
||||
private static int i=0;
|
||||
public static void main(String[] args) {
|
||||
// 同步职工数据
|
||||
// try {
|
||||
//// deleteUser(608421892);
|
||||
// } catch (NoSuchAlgorithmException e) {
|
||||
// e.printStackTrace();
|
||||
// } catch (KeyManagementException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
|
||||
// //修改职工基础信息数据
|
||||
try {
|
||||
JSONArray beiSens = JDYUtil.getAllDriversBeiSen();//查询
|
||||
JSONArray drivers = JDYUtil.getAllDrivers();//查询
|
||||
JSONObject orgNos=JDYUtil.getOrgNos();
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
for (Object o : drivers) {
|
||||
HashMap<String, Object> driver = (HashMap<String, Object>) o;
|
||||
jsonObject.put((String) driver.get("shjh") + "@yinjian.com", driver);
|
||||
}
|
||||
String token=getToken();
|
||||
int i=0;
|
||||
for (Object o : beiSens) {
|
||||
i=i+1;
|
||||
JSONObject driver = (JSONObject) o;
|
||||
String xm=driver.getString("xm");
|
||||
if (xm.equals("宋乃庆")){
|
||||
if (jsonObject.getJSONObject(driver.getString("zhanghao"))!=null){
|
||||
BeiSenTest.updateUser(jsonObject.getJSONObject(driver.getString("zhanghao")),driver.getInteger("oid"),orgNos,token);
|
||||
System.out.println(jsonObject.getJSONObject(driver.getString("zhanghao")));
|
||||
//更新简道云数据
|
||||
JDYUtil.updateBeiSenId(jsonObject.getJSONObject(driver.getString("zhanghao")).
|
||||
getString("_id"),driver.getString("oid"));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// JSONArray drivers=JDYUtil.getAllDrivers();//查询
|
||||
// JSONObject orgNos=JDYUtil.getOrgNos();
|
||||
// JSONArray deps=new JSONArray();
|
||||
// for (Object o:drivers){
|
||||
// HashMap<String,Object> driver=(HashMap<String,Object>)o;
|
||||
//// try {
|
||||
////// BeiSenTest.updateUser(driver,(String) driver.get("shfzhh"),orgNos);
|
||||
//// } catch (NoSuchAlgorithmException e) {
|
||||
//// e.printStackTrace();
|
||||
//// } catch (KeyManagementException e) {
|
||||
//// e.printStackTrace();
|
||||
//// }
|
||||
// }
|
||||
// Set set=new HashSet();//创建set集合
|
||||
// for (int i=0;i<deps.size();i++){
|
||||
// set.add(deps.get(i));//数组中的数据循环加入集合中
|
||||
// }
|
||||
// deps=JSONArray.parseArray(set.toString());//转化为数组
|
||||
// System.out.println(deps.toJSONString());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建人员信息
|
||||
* @return
|
||||
* @throws NoSuchAlgorithmException
|
||||
* @throws KeyManagementException
|
||||
*/
|
||||
public static void createUser(JSONObject driver, JSONObject orgNos,JSONArray deps) throws NoSuchAlgorithmException, KeyManagementException {
|
||||
String url = "https://openapi.italent.cn/TenantBaseExternal/api/v5/Employee/Create";
|
||||
JSONObject body = new JSONObject();
|
||||
body.put("employeeInformation", "client_credentials");
|
||||
JSONObject employeeInformation = new JSONObject();
|
||||
employeeInformation.put("name", driver.get("xm"));//姓名:张三
|
||||
employeeInformation.put("email",driver.get("yxbs"));//邮箱
|
||||
employeeInformation.put("iDNumber", driver.get("shfzhh"));//身份证号码
|
||||
// employeeInformation.put("email", driver.get("shjh") + "@yinjian.com");//邮箱
|
||||
employeeInformation.put("mobilePhone", driver.get("shjh"));//身份证号码
|
||||
JSONObject employmentRecord = new JSONObject();
|
||||
employmentRecord.put("entryDate", driver.get("lrrq"));//入职日期\
|
||||
employeeInformation.put("emergencyContactPhone", driver.get("shjh"));//身份证号码
|
||||
employmentRecord.put("probation", 0);//试用期,无试用期为0
|
||||
String name = (String) driver.get("name");//
|
||||
String uu=(String) driver.get("ssbm") + (String) driver.get("fs");
|
||||
for (String str : orgNos.keySet()) {
|
||||
if (str.equals(driver.get("ssbm"))) {
|
||||
employmentRecord.put("OIdDepartment", orgNos.getInteger(str));//试用期,无试用期为0
|
||||
break;
|
||||
}
|
||||
}
|
||||
Integer O=employmentRecord.getInteger("OIdDepartment");
|
||||
if (O==null){
|
||||
deps.add(uu);
|
||||
System.out.println("");
|
||||
}
|
||||
employmentRecord.put("originalId", driver.get("shfzhh"));//外部编码ID
|
||||
String ssbm = (String) driver.get("ssbm");//所属部门
|
||||
String ssbm1 = "景城利华";
|
||||
if(ssbm.equals(ssbm1)){
|
||||
employmentRecord.put("employmentType", "5cc3e855-f9b8-4cec-8860-b89d945ba615");//人员类别
|
||||
}else {
|
||||
employmentRecord.put("employmentType", "020c47b0-74b7-4a75-b454-e9905f64e1fc");//人员类别
|
||||
}
|
||||
//employmentRecord.put("employmentType", "020c47b0-74b7-4a75-b454-e9905f64e1fc");//人员类别
|
||||
employmentRecord.put("oIdJobPost", "149359");//职务
|
||||
body.put("employeeInformation", employeeInformation);
|
||||
body.put("employmentRecord", employmentRecord);
|
||||
JSONObject jsonObject = JSON.parseObject(HttpUtil.sendPost(url, body.toJSONString(), getToken()));
|
||||
System.out.println(jsonObject.toJSONString());
|
||||
// JSONObject jsonObject = JSON.parseObject(HttpUtil.sendPost(url, body.toJSONString(), getToken()));
|
||||
// System.out.println(jsonObject.toJSONString());
|
||||
// return jsonObject.getString("access_token");
|
||||
}
|
||||
|
||||
|
||||
public static String getToken() throws NoSuchAlgorithmException, KeyManagementException {
|
||||
String url = "https://openapi.italent.cn/token";
|
||||
JSONObject body = new JSONObject();
|
||||
body.put("grant_type", "client_credentials");
|
||||
body.put("app_key", app_key);
|
||||
body.put("app_secret", app_secret);
|
||||
JSONObject jsonObject = JSON.parseObject(HttpUtil.sendPost(url, body.toJSONString()));
|
||||
return jsonObject.getString("access_token");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建人员信息
|
||||
*
|
||||
* @return
|
||||
* @throws NoSuchAlgorithmException
|
||||
* @throws KeyManagementException
|
||||
*/
|
||||
public static void createUser(JSONObject driver, JSONObject orgNos,String id) throws NoSuchAlgorithmException, KeyManagementException {
|
||||
String token=getToken();
|
||||
if (true){
|
||||
String url = "https://openapi.italent.cn/TenantBaseExternal/api/v5/Employee/Create";
|
||||
JSONObject body = new JSONObject();
|
||||
body.put("employeeInformation", "client_credentials");
|
||||
JSONObject employeeInformation = new JSONObject();
|
||||
employeeInformation.put("name", driver.get("xm"));//姓名:张三
|
||||
employeeInformation.put("email",driver.get("yxbs"));//邮箱
|
||||
// employeeInformation.put("originalId",driver.get("shfzhh"));//外部ID
|
||||
employeeInformation.put("iDNumber", driver.get("shfzhh"));//身份证号码
|
||||
employeeInformation.put("mobilePhone", driver.get("shjh"));//电话号码
|
||||
employeeInformation.put("emergencyContactPhone", driver.get("shjh"));//电话
|
||||
JSONObject employmentRecord = new JSONObject();
|
||||
String dang = TimeUtil.dang();
|
||||
employmentRecord.put("entryDate",dang /*TimeUtil.timeConversion1(driver.getString("lrrq"))*/ );//入职日期
|
||||
employmentRecord.put("probation", 0);//试用期,无试用期为0
|
||||
String name = (String) driver.get("name");//
|
||||
for (String str : orgNos.keySet()) {
|
||||
if (str.equals(driver.getString("fs"))){
|
||||
employmentRecord.put("OIdDepartment", orgNos.getInteger(str));//试用期,无试用期为0
|
||||
break;
|
||||
}
|
||||
}
|
||||
//区分是否TY,TY的人员类别为"5cc3e855-f9b8-4cec-8860-b89d945ba615",其余为"020c47b0-74b7-4a75-b454-e9905f64e1fc"
|
||||
/* String ssbm = (String) driver.get("ssbm");//所属部门
|
||||
String ssbm1 = "景城利华";
|
||||
if(ssbm.equals(ssbm1)){
|
||||
employmentRecord.put("employmentType", "5cc3e855-f9b8-4cec-8860-b89d945ba615");//人员类别
|
||||
}else {
|
||||
employmentRecord.put("employmentType", "020c47b0-74b7-4a75-b454-e9905f64e1fc");//人员类别
|
||||
}*/
|
||||
employmentRecord.put("employmentType", "70b80df9-c88c-4e2c-ab3d-a3a0a59d7d4c");
|
||||
//employmentRecord.put("employmentType", "020c47b0-74b7-4a75-b454-e9905f64e1fc");//人员类别
|
||||
employmentRecord.put("oIdJobPost", "149359");//职务
|
||||
body.put("employeeInformation", employeeInformation);
|
||||
body.put("employmentRecord", employmentRecord);
|
||||
JSONObject jsonObject = JSON.parseObject(HttpUtil.sendPost(url, body.toJSONString(),token));
|
||||
JSONObject returnData=jsonObject.getJSONObject("data");
|
||||
System.out.println(driver.get("shfzhh")+"的创建账户动作返回为:"+jsonObject.toJSONString());
|
||||
if (jsonObject.getString("code").equals("200")){
|
||||
JDYUtil.updateBeiSenId(id,returnData.getString("userId"));
|
||||
}else {
|
||||
updateUser(driver,driver.getInteger("beisen_id"),orgNos,token);
|
||||
}
|
||||
}else {
|
||||
//如果不是新增则修改数据
|
||||
updateUser(driver,driver.getInteger("beisen_id"),orgNos,token);
|
||||
}
|
||||
// return jsonObject.getString("access_token");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static void createUserss(String xm, String yxbs, String shfzhh, String shjh, String fs, String beisen_id, JSONObject orgNos,String id) throws NoSuchAlgorithmException, KeyManagementException {
|
||||
String token = getToken();
|
||||
Integer beisenid = 0;
|
||||
if (true) {
|
||||
String url = "https://openapi.italent.cn/TenantBaseExternal/api/v5/Employee/Create";
|
||||
JSONObject body = new JSONObject();
|
||||
body.put("employeeInformation", "client_credentials");
|
||||
JSONObject employeeInformation = new JSONObject();
|
||||
employeeInformation.put("name", xm);//姓名:张三
|
||||
employeeInformation.put("email", yxbs);//邮箱
|
||||
// employeeInformation.put("originalId",driver.get("shfzhh"));//外部ID
|
||||
employeeInformation.put("iDNumber", shfzhh);//身份证号码
|
||||
employeeInformation.put("mobilePhone", shjh);//电话号码
|
||||
employeeInformation.put("emergencyContactPhone", shjh);//电话
|
||||
JSONObject employmentRecord = new JSONObject();
|
||||
String dang = TimeUtil.dang();
|
||||
employmentRecord.put("entryDate", dang /*TimeUtil.timeConversion1(driver.getString("lrrq"))*/);//入职日期
|
||||
employmentRecord.put("probation", 0);//试用期,无试用期为0
|
||||
|
||||
for (String str : orgNos.keySet()) {
|
||||
if (str.equals(fs)) {
|
||||
employmentRecord.put("OIdDepartment", orgNos.getInteger(str));//试用期,无试用期为0
|
||||
break;
|
||||
}
|
||||
}
|
||||
//区分是否TY,TY的人员类别为"5cc3e855-f9b8-4cec-8860-b89d945ba615",其余为"020c47b0-74b7-4a75-b454-e9905f64e1fc"
|
||||
/* String ssbm = (String) driver.get("ssbm");//所属部门
|
||||
String ssbm1 = "景城利华";
|
||||
if(ssbm.equals(ssbm1)){
|
||||
employmentRecord.put("employmentType", "5cc3e855-f9b8-4cec-8860-b89d945ba615");//人员类别
|
||||
}else {
|
||||
employmentRecord.put("employmentType", "020c47b0-74b7-4a75-b454-e9905f64e1fc");//人员类别
|
||||
}*/
|
||||
employmentRecord.put("employmentType", "70b80df9-c88c-4e2c-ab3d-a3a0a59d7d4c");
|
||||
//employmentRecord.put("employmentType", "020c47b0-74b7-4a75-b454-e9905f64e1fc");//人员类别
|
||||
employmentRecord.put("oIdJobPost", "149359");//职务
|
||||
body.put("employeeInformation", employeeInformation);
|
||||
body.put("employmentRecord", employmentRecord);
|
||||
JSONObject jsonObject = JSON.parseObject(HttpUtil.sendPost(url, body.toJSONString(), token));
|
||||
JSONObject returnData = jsonObject.getJSONObject("data");
|
||||
System.out.println(shfzhh + "的创建账户动作返回为:" + jsonObject.toJSONString());
|
||||
if (jsonObject.getString("code").equals("200")) {
|
||||
String userId = JDYUtil.updateBeiSenId(id, returnData.getString("userId"));
|
||||
log.info(userId);
|
||||
|
||||
} else {
|
||||
beisenid = Integer.parseInt(beisen_id);
|
||||
updateUserss(xm, yxbs, shfzhh, shjh, fs, beisenid, orgNos, token);
|
||||
}
|
||||
} else {
|
||||
//如果不是新增则修改数据
|
||||
updateUserss(xm, yxbs, shfzhh, shjh, fs, beisenid, orgNos, token);
|
||||
}
|
||||
// return jsonObject.getString("access_token");
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改人员信息
|
||||
*
|
||||
* @return
|
||||
* @throws NoSuchAlgorithmException
|
||||
* @throws KeyManagementException
|
||||
*/
|
||||
public static void updateUser(JSONObject driver, Integer id,JSONObject orgNos,String token) throws NoSuchAlgorithmException, KeyManagementException {
|
||||
String url = "https://openapi.italent.cn/TenantBaseExternal/api/v5/Employee/UpdateEmployee";
|
||||
JSONObject body = new JSONObject();
|
||||
body.put("employeeInformation", "client_credentials");
|
||||
JSONObject employeeInformation = new JSONObject();
|
||||
employeeInformation.put("name", driver.get("xm"));//姓名:张三
|
||||
employeeInformation.put("email",driver.get("yxbs"));//邮箱
|
||||
// employeeInformation.put("originalId",driver.get("shfzhh"));//外部ID
|
||||
employeeInformation.put("iDNumber", driver.get("shfzhh"));//身份证号码
|
||||
employeeInformation.put("mobilePhone", driver.get("shjh"));//电话号码
|
||||
employeeInformation.put("emergencyContactPhone", driver.get("shjh"));//电话
|
||||
JSONObject employmentRecord = new JSONObject();
|
||||
|
||||
/* String ssbm = (String) driver.get("ssbm");//所属部门
|
||||
String ssbm1 = "景城利华";
|
||||
if(ssbm.equals(ssbm1)){
|
||||
employmentRecord.put("employmentType", "5cc3e855-f9b8-4cec-8860-b89d945ba615");//人员类别
|
||||
}else {
|
||||
employmentRecord.put("employmentType", "020c47b0-74b7-4a75-b454-e9905f64e1fc");//人员类别
|
||||
}*/
|
||||
employmentRecord.put("employmentType", "70b80df9-c88c-4e2c-ab3d-a3a0a59d7d4c");
|
||||
//employmentRecord.put("employmentType", "020c47b0-74b7-4a75-b454-e9905f64e1fc");//人员类别
|
||||
for (String str : orgNos.keySet()) {
|
||||
if (str.equals(driver.get("fs"))) {
|
||||
employmentRecord.put("OIdDepartment", orgNos.getInteger(str));//试用期,无试用期为0
|
||||
break;
|
||||
}
|
||||
}
|
||||
employmentRecord.put("oIdJobPost", "149359");//职务
|
||||
body.put("employeeInformation", employeeInformation);
|
||||
body.put("employmentRecord", employmentRecord);
|
||||
body.put("userId", id);
|
||||
JSONObject jsonObject = JSON.parseObject(HttpUtil.sendPost(url, body.toJSONString(),token));
|
||||
System.out.println(jsonObject.toJSONString());
|
||||
// return jsonObject.getString("access_token");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static void updateUserss(String xm, String yxbs, String shfzhh, String shjh, String fs, Integer id,JSONObject orgNos,String token) throws NoSuchAlgorithmException, KeyManagementException {
|
||||
String url = "https://openapi.italent.cn/TenantBaseExternal/api/v5/Employee/UpdateEmployee";
|
||||
JSONObject body = new JSONObject();
|
||||
body.put("employeeInformation", "client_credentials");
|
||||
JSONObject employeeInformation = new JSONObject();
|
||||
employeeInformation.put("name", xm);//姓名:张三
|
||||
employeeInformation.put("email",yxbs);//邮箱
|
||||
// employeeInformation.put("originalId",driver.get("shfzhh"));//外部ID
|
||||
employeeInformation.put("iDNumber", shfzhh);//身份证号码
|
||||
employeeInformation.put("mobilePhone", shjh);//电话号码
|
||||
employeeInformation.put("emergencyContactPhone", fs);//电话
|
||||
JSONObject employmentRecord = new JSONObject();
|
||||
|
||||
/* String ssbm = (String) driver.get("ssbm");//所属部门
|
||||
String ssbm1 = "景城利华";
|
||||
if(ssbm.equals(ssbm1)){
|
||||
employmentRecord.put("employmentType", "5cc3e855-f9b8-4cec-8860-b89d945ba615");//人员类别
|
||||
}else {
|
||||
employmentRecord.put("employmentType", "020c47b0-74b7-4a75-b454-e9905f64e1fc");//人员类别
|
||||
}*/
|
||||
employmentRecord.put("employmentType", "70b80df9-c88c-4e2c-ab3d-a3a0a59d7d4c");
|
||||
//employmentRecord.put("employmentType", "020c47b0-74b7-4a75-b454-e9905f64e1fc");//人员类别
|
||||
for (String str : orgNos.keySet()) {
|
||||
if (str.equals(fs)) {
|
||||
employmentRecord.put("OIdDepartment", orgNos.getInteger(str));//试用期,无试用期为0
|
||||
break;
|
||||
}
|
||||
}
|
||||
employmentRecord.put("oIdJobPost", "149359");//职务
|
||||
body.put("employeeInformation", employeeInformation);
|
||||
body.put("employmentRecord", employmentRecord);
|
||||
body.put("userId", id);
|
||||
JSONObject jsonObject = JSON.parseObject(HttpUtil.sendPost(url, body.toJSONString(),token));
|
||||
System.out.println(jsonObject.toJSONString());
|
||||
// return jsonObject.getString("access_token");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 离职人员信息
|
||||
*
|
||||
* @return
|
||||
* @throws NoSuchAlgorithmException
|
||||
* @throws KeyManagementException
|
||||
*/
|
||||
public static void deleteUser(Integer id) throws NoSuchAlgorithmException, KeyManagementException {
|
||||
String url = "https://openapi.italent.cn/TenantBaseExternal/api/v5/Employee/Dimission";
|
||||
JSONObject body = new JSONObject();
|
||||
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
|
||||
JSONObject employmentRecord = new JSONObject();
|
||||
try {
|
||||
employmentRecord.put("lastWorkDate",df.format(new Date()));//最后工作日期
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
body.put("employmentRecord", employmentRecord);
|
||||
body.put("userId", id);
|
||||
JSONObject jsonObject = JSON.parseObject(HttpUtil.sendPost(url, body.toJSONString(), getToken()));
|
||||
System.out.println(jsonObject.toJSONString());
|
||||
// return jsonObject.getString("access_token");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user