first commit

This commit is contained in:
lijiazhuo
2025-09-26 14:16:20 +08:00
commit a106338949
36 changed files with 4721 additions and 0 deletions

View File

@ -0,0 +1,15 @@
package com.example.sso;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
@EnableScheduling
public class SsoApplication {
public static void main(String[] args) {
SpringApplication.run(SsoApplication.class, args);
}
}

View File

@ -0,0 +1,23 @@
package com.example.sso.config;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.validation.annotation.Validated;
//import javax.validation.constraints.NotBlank;
@Configuration
@ConfigurationProperties(prefix = "sso")
@NoArgsConstructor
@AllArgsConstructor
@Validated
@Getter
@Setter
public class SSOConfig {
private String acs;
private String secret;
}

View File

@ -0,0 +1,117 @@
package com.example.sso.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.sso.config.SSOConfig;
import com.example.sso.dao.J9051Dao;
import com.example.sso.dao.J9052Dao;
import com.example.sso.dao.J9053Dao;
import com.example.sso.dao.J905Dao;
import com.example.sso.service.JDYAuthService;
import com.example.sso.service.SSOService;
import com.example.sso.util.BeiSenTest;
import com.example.sso.util.J905Util;
import com.example.sso.util.JDYUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.Date;
import java.util.HashMap;
@RestController
@NoArgsConstructor
@AllArgsConstructor
class BeiSenController {
@Getter @Setter @Autowired private SSOConfig ssoConfig;
private JSONObject limitIpInfo_dep1 = new JSONObject();
private JSONObject limitIpInfo_dep2 = new JSONObject();
private JSONObject limitIpInfo_dep3 = new JSONObject();
private JSONObject limitIpInfo_dep4 = new JSONObject();
private JSONObject limitIpInfo_dep5 = new JSONObject();
private JSONObject limitIpInfo_dep6 = new JSONObject();
@Getter @Setter @Autowired private SSOService ssoService;
@Getter @Setter @Autowired private JDYAuthService jdyAuthService;
Logger logger = LoggerFactory.getLogger(getClass());
/**
* 创建人员信息
*/
@GetMapping("/createPerson")
public void yxMes() throws KeyManagementException, NoSuchAlgorithmException {
try {
JSONArray drivers=JDYUtil.getAllDrivers();//查询
for (Object o:drivers){
JSONObject driver=(JSONObject)o;
JSONObject orgNos=JDYUtil.getOrgNos();
BeiSenTest.createUser(driver,orgNos,"");
}
}catch (Exception e) {
e.printStackTrace();
}
}
/**
* 接收简道云新增的人员数据
*/
@PostMapping("/createPerson_jdy")
public void yxMes3(@RequestBody JSONObject driver){
try {
logger.info(driver.toJSONString());
if (driver.getJSONObject("data").getString("status").equals("已择车") ||
driver.getJSONObject("data").getString("status").equals("运营")){
//if (driver.getJSONObject("data").getString("status").equals("运营")){
//这个情况说明上车,创建账户
JSONObject orgNos=JDYUtil.getOrgNos();
JSONObject data=driver.getJSONObject("data");
BeiSenTest.createUser(data,orgNos,driver.getJSONObject("data").getString("_id"));
}else if (driver.getJSONObject("data").getString("status").equals("已下车")){
//}else if (driver.getJSONObject("data").getString("status").equals("已下车")||
//driver.getJSONObject("data").getString("status").equals("休医疗期")){
BeiSenTest.deleteUser(driver.getJSONObject("data").getInteger("beisen_id"));
}
}catch (Exception e) {
e.printStackTrace();
}
}
/**
* 更新人员数据信息,修护职务、身份证号码信息
*/
@GetMapping("/updatePersonData")
public void yxMes2(){
//修改职工基础信息数据
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);
}
for (Object o : beiSens) {
JSONObject driver = (JSONObject) o;
if (jsonObject.getJSONObject(driver.getString("zhanghao"))!=null){
// BeiSenTest.updateUser(driver,driver.getString("oid"),orgNos);
// System.out.println(jsonObject.getJSONObject(driver.getString("zhanghao")));
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,365 @@
package com.example.sso.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.sso.config.SSOConfig;
import com.example.sso.dao.J9051Dao;
import com.example.sso.dao.J9052Dao;
import com.example.sso.dao.J9053Dao;
import com.example.sso.dao.J905Dao;
import com.example.sso.service.*;
import com.example.sso.util.J905Util;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.Date;
@RestController
@NoArgsConstructor
@AllArgsConstructor
class SSOController {
@Getter @Setter @Autowired private SSOConfig ssoConfig;
private JSONObject limitIpInfo_dep1 = new JSONObject();
private JSONObject limitIpInfo_dep2 = new JSONObject();
private JSONObject limitIpInfo_dep3 = new JSONObject();
private JSONObject limitIpInfo_dep4 = new JSONObject();
private JSONObject limitIpInfo_dep5 = new JSONObject();
private JSONObject limitIpInfo_dep6 = new JSONObject();
@Getter @Setter @Autowired private SSOService ssoService;
@Getter @Setter @Autowired private JDYAuthService jdyAuthService;
Logger logger = LoggerFactory.getLogger(getClass());
/**
* 查询SIM卡号车牌号和终端号的对应关系
* @param jsonMes
* @param httpServletRequest
* @return
* @throws KeyManagementException
* @throws NoSuchAlgorithmException
*/
@PostMapping("/mdnVcn/getPageList")
public JSONObject yxMes(@RequestBody JSONObject jsonMes,HttpServletRequest httpServletRequest) throws KeyManagementException, NoSuchAlgorithmException {
try {
String ip = httpServletRequest.getRemoteAddr();
if (limitIpInfo_dep1.getJSONObject(ip) == null) {
limitIpInfo_dep1.put(ip, initializationIP());
try {
String key=jsonMes.getString("key");
if (key.equals("5fff9123eadbae0007b9ce3e")){
JSONArray jsonArray=J905Dao.getAllSims();
return J905Util.returnOK(jsonArray);
}else{
return J905Util.returnLoser(400,"秘钥错误");//秘钥错误
}
} catch (Exception e) {
e.printStackTrace();
}
} else {
JSONObject limitInfo = limitIpInfo_dep1.getJSONObject(ip);
Long time = (new Date().getTime() - limitInfo.getLong("time")) / 1000;//秒
//logger.info(ip+":还需等待"+time);
if (time>=60) {
limitIpInfo_dep1.put(ip, initializationIP());
try {
String key=jsonMes.getString("key");
if (key.equals("5fff9123eadbae0007b9ce3e")){
JSONArray jsonArray=J905Dao.getAllSims();
return J905Util.returnOK(jsonArray);
}else{
return J905Util.returnLoser(400,"秘钥错误");//秘钥错误
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
return J905Util.returnLoser(402,"接口频率超出限制1分钟内允许调取一次请稍后再试");//秘钥错误
}catch (Exception e){
e.printStackTrace();
return J905Util.returnLoser(401,"系统查询异常,请联系开发人员");
}
}
/**
* 查询车队
* @param jsonMes
* @param httpServletRequest
* @return
* @throws KeyManagementException
* @throws NoSuchAlgorithmException
*/
@PostMapping("/vDwnoFzr/getPageList")
public JSONObject vDwnoFzr(@RequestBody JSONObject jsonMes,HttpServletRequest httpServletRequest) throws KeyManagementException, NoSuchAlgorithmException {
try {
String ip = httpServletRequest.getRemoteAddr();
if (limitIpInfo_dep2.getJSONObject(ip) == null) {
limitIpInfo_dep2.put(ip, initializationIP());
try {
String key=jsonMes.getString("key");
if (key.equals("5fff9123eadbae0007b9ce3e")){
JSONArray jsonArray=J905Dao.getAllSims();
return J905Util.returnOK(jsonArray);
}else{
return J905Util.returnLoser(400,"秘钥错误");//秘钥错误
}
} catch (Exception e) {
e.printStackTrace();
}
} else {
JSONObject limitInfo = limitIpInfo_dep2.getJSONObject(ip);
Long time = (new Date().getTime() - limitInfo.getLong("time")) / 1000;//秒
//logger.info(ip+":还需等待"+time);
if (time>=60) {
limitIpInfo_dep2.put(ip, initializationIP());
try {
String key=jsonMes.getString("key");
if (key.equals("5fff9123eadbae0007b9ce3e")){
JSONArray jsonArray=J905Dao.getAllSims();
return J905Util.returnOK(jsonArray);
}else{
return J905Util.returnLoser(400,"秘钥错误");//秘钥错误
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
return J905Util.returnLoser(402,"接口频率超出限制1分钟内允许调取一次请稍后再试");//秘钥错误
}catch (Exception e){
e.printStackTrace();
return J905Util.returnLoser(401,"系统查询异常,请联系开发人员");
}
}
/**
* 查询车辆
* @param jsonMes
* @param httpServletRequest
* @return
* @throws KeyManagementException
* @throws NoSuchAlgorithmException
*/
@PostMapping("/VGpsCheliang/getPageList")
public JSONObject VGpsCheliang(@RequestBody JSONObject jsonMes,HttpServletRequest httpServletRequest) throws KeyManagementException, NoSuchAlgorithmException {
try {
String ip = httpServletRequest.getRemoteAddr();
if (limitIpInfo_dep3.getJSONObject(ip) == null) {
limitIpInfo_dep3.put(ip, initializationIP());
try {
String key=jsonMes.getString("key");
if (key.equals("5fff9123eadbae0007b9ce3e")){
JSONArray jsonArray=J905Dao.getVGpsCheliangs();
return J905Util.returnOK(jsonArray);
}else{
return J905Util.returnLoser(400,"秘钥错误");//秘钥错误
}
} catch (Exception e) {
e.printStackTrace();
}
} else {
JSONObject limitInfo = limitIpInfo_dep3.getJSONObject(ip);
Long time = (new Date().getTime() - limitInfo.getLong("time")) / 1000;//秒
//logger.info(ip+":还需等待"+time);
if (time>=60) {
limitIpInfo_dep3.put(ip, initializationIP());
try {
String key=jsonMes.getString("key");
if (key.equals("5fff9123eadbae0007b9ce3e")){
JSONArray jsonArray=J905Dao.getVGpsCheliangs();
return J905Util.returnOK(jsonArray);
}else{
return J905Util.returnLoser(400,"秘钥错误");//秘钥错误
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
return J905Util.returnLoser(402,"接口频率超出限制1分钟内允许调取一次请稍后再试");//秘钥错误
}catch (Exception e){
e.printStackTrace();
return J905Util.returnLoser(401,"系统查询异常,请联系开发人员");
}
}
/**
* 查询驾驶员
* @param jsonMes
* @param httpServletRequest
* @return
* @throws KeyManagementException
* @throws NoSuchAlgorithmException
*/
@PostMapping("/vGpsJiashiyuan/getPageList")
public JSONObject vGpsJiashiyuan(@RequestBody JSONObject jsonMes,HttpServletRequest httpServletRequest) throws KeyManagementException, NoSuchAlgorithmException {
try {
String ip = httpServletRequest.getRemoteAddr();
if (limitIpInfo_dep4.getJSONObject(ip) == null) {
limitIpInfo_dep4.put(ip, initializationIP());
try {
String key=jsonMes.getString("key");
if (key.equals("5fff9123eadbae0007b9ce3e")){
JSONArray jsonArray= J9051Dao.getAllJiashiyuans();
return J905Util.returnOK(jsonArray);
}else{
return J905Util.returnLoser(400,"秘钥错误");//秘钥错误
}
} catch (Exception e) {
e.printStackTrace();
}
} else {
JSONObject limitInfo = limitIpInfo_dep4.getJSONObject(ip);
Long time = (new Date().getTime() - limitInfo.getLong("time")) / 1000;//秒
//logger.info(ip+":还需等待"+time);
if (time>=60) {
limitIpInfo_dep4.put(ip, initializationIP());
try {
String key=jsonMes.getString("key");
if (key.equals("5fff9123eadbae0007b9ce3e")){
JSONArray jsonArray=J9051Dao.getAllJiashiyuans();
return J905Util.returnOK(jsonArray);
}else{
return J905Util.returnLoser(400,"秘钥错误");//秘钥错误
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
return J905Util.returnLoser(402,"接口频率超出限制1分钟内允许调取一次请稍后再试");//秘钥错误
}catch (Exception e){
e.printStackTrace();
return J905Util.returnLoser(401,"系统查询异常,请联系开发人员");
}
}
/**
* 查询驾驶员和车辆关系
* @param jsonMes
* @param httpServletRequest
* @return
* @throws KeyManagementException
* @throws NoSuchAlgorithmException
*/
@PostMapping("/vGpsHetong/getPageList")
public JSONObject vGpsHetong(@RequestBody JSONObject jsonMes,HttpServletRequest httpServletRequest) throws KeyManagementException, NoSuchAlgorithmException {
try {
String ip = httpServletRequest.getRemoteAddr();
if (limitIpInfo_dep5.getJSONObject(ip) == null) {
limitIpInfo_dep5.put(ip, initializationIP());
try {
String key=jsonMes.getString("key");
if (key.equals("5fff9123eadbae0007b9ce3e")){
JSONArray jsonArray= J9052Dao.getAllvGpsHetongs();
for (Object o:jsonArray){
JSONObject jsonObject=(JSONObject)o;
String hphm=jsonObject.getString("hphm");
if (hphm.contains("")){
System.out.println("");
}
}
return J905Util.returnOK(jsonArray);
}else{
return J905Util.returnLoser(400,"秘钥错误");//秘钥错误
}
} catch (Exception e) {
e.printStackTrace();
}
} else {
JSONObject limitInfo = limitIpInfo_dep5.getJSONObject(ip);
Long time = (new Date().getTime() - limitInfo.getLong("time")) / 1000;//秒
//logger.info(ip+":还需等待"+time);
if (time>=60) {
limitIpInfo_dep5.put(ip, initializationIP());
try {
String key=jsonMes.getString("key");
if (key.equals("5fff9123eadbae0007b9ce3e")){
JSONArray jsonArray=J9052Dao.getAllvGpsHetongs();
return J905Util.returnOK(jsonArray);
}else{
return J905Util.returnLoser(400,"秘钥错误");//秘钥错误
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
return J905Util.returnLoser(402,"接口频率超出限制1分钟内允许调取一次请稍后再试");//秘钥错误
}catch (Exception e){
e.printStackTrace();
return J905Util.returnLoser(401,"系统查询异常,请联系开发人员");
}
}
/**
* 查询历史人车对应关系
* @param jsonMes
* @param httpServletRequest
* @return
* @throws KeyManagementException
* @throws NoSuchAlgorithmException
*/
@PostMapping("/vGpsLiShiHeTong/getPageList")
public JSONObject vGpsLiShiHeTong(@RequestBody JSONObject jsonMes,HttpServletRequest httpServletRequest) throws KeyManagementException, NoSuchAlgorithmException {
try {
String ip = httpServletRequest.getRemoteAddr();
if (limitIpInfo_dep6.getJSONObject(ip) == null) {
limitIpInfo_dep6.put(ip, initializationIP());
try {
String key=jsonMes.getString("key");
if (key.equals("5fff9123eadbae0007b9ce3e")){
JSONArray jsonArray= J9053Dao.getAllvGpsLiShiHeTong();
return J905Util.returnOK(jsonArray);
}else{
return J905Util.returnLoser(400,"秘钥错误");//秘钥错误
}
} catch (Exception e) {
e.printStackTrace();
}
} else {
JSONObject limitInfo = limitIpInfo_dep6.getJSONObject(ip);
Long time = (new Date().getTime() - limitInfo.getLong("time")) / 1000;//秒
//logger.info(ip+":还需等待"+time);
if (time>=180) {
limitIpInfo_dep6.put(ip, initializationIP());
try {
String key=jsonMes.getString("key");
if (key.equals("5fff9123eadbae0007b9ce3e")){
JSONArray jsonArray=J9053Dao.getAllvGpsLiShiHeTong();
return J905Util.returnOK(jsonArray);
}else{
return J905Util.returnLoser(400,"秘钥错误");//秘钥错误
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
return J905Util.returnLoser(402,"接口频率超出限制3分钟内允许调取一次请稍后再试");//秘钥错误
}catch (Exception e){
e.printStackTrace();
return J905Util.returnLoser(401,"系统查询异常,请联系开发人员");
}
}
private JSONObject initializationIP() {
JSONObject info = new JSONObject();
info.put("time", new Date().getTime());
info.put("num", 1);
return info;
}
}

View File

@ -0,0 +1,102 @@
package com.example.sso.dao;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.sso.util.APIUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class J9051Dao {
public static void main(String[] args) {
getAllJiashiyuans();
}
/**
*
* @param
* @return
*/
public static JSONArray getAllJiashiyuans() {
//需要修改 appid entryid apikey
APIUtils api = new APIUtils("628eeaace7f28c00089a60cc", "5c9d82c72ceed93a0d9ebca4","BkIyzlh1onqnqu9cQ3ralDQBjECn97ex");
final List<Map<String, Object>> condList = new ArrayList<Map<String, Object>>();
//因为想查询大于50的数据所以创建一个数组
JSONArray jsonArray = new JSONArray();
//在这个数组里面放一个数值类型的数字,用来判断查询范围
jsonArray.add("");
condList.add(new HashMap<String, Object>() {
{
put("field", "vcn");//查新字段的名称/别名
put("method", "nq");//判断的方法
put("value", jsonArray);//查询的条件
}
});
Map<String, Object> filter = new HashMap<String, Object>() {
{
put("rel", "and");
put("cond", condList);
}
};
//字段别名
List<Map<String, Object>> datas = api.getFormData(10000, new String[]{"jsy_id","xm","xb","shfzhh","whchd","xzhzh","lxdh","shjh","jshzhh","zhjchx","lingzhengriqi","status","jdkh","jjlxr",
"jg","zp","createTime","tuizuriqi","sfzzm","sfzbm","yhkh","xhhy","gahy","lhh","gsmc","gsdh","jszzy","jszfy"},
//姓名
//性别
//身份号码
//文化程度
//居民身份证住址
//联系电话
//手机号码
//驾驶证档案编号
//准驾车型
//初次领证日期
//驾驶员状态
//监督卡号
//紧急联系人手机号
filter, null);
if (datas == null) {
return null;
}
if (datas.size() == 0) {
return null;
}
int i = 1;
if (datas != null && datas.size() != 0) {
while (i != 0) {
if (datas.size() > (i * 10000 - 1)) {
String id = (String) (datas.get(i * 10000 - 1).get("_id"));
List<Map<String, Object>> data = findData(api, filter, id);
if (data == null) {
i = 0;
} else {
datas.addAll(data);
i = i + 1;
}
} else {
i = 0;
}
}
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("list", datas);
return jsonObject.getJSONArray("list");
}
private static List<Map<String, Object>> findData(APIUtils api, Map<String, Object> filter, String id) {
List<Map<String, Object>> datas = api.getFormData(10000, new String[]{"jsy_id","xm","xb","shfzhh","whchd","xzhzh","lxdh","shjh","jshzhh","zhjchx","lingzhengriqi","status","jdkh","jjlxr",
"jg","zp","createTime","tuizuriqi","sfzzm","sfzbm","yhkh","xhhy","gahy","lhh","gsmc","gsdh","jszzy","jszfy"},
filter, id);
if (datas == null) {
return null;
}
if (datas.size() == 0) {
return null;
}
return datas;
}
}

View File

@ -0,0 +1,97 @@
package com.example.sso.dao;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.sso.util.APIUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class J9052Dao {
public static void main(String[] args) {
JSONArray jsonArray= J9052Dao.getAllvGpsHetongs();
for (Object o:jsonArray){
JSONObject jsonObject=(JSONObject)o;
String hphm=jsonObject.getString("hphm");
if (hphm.contains("BD98508")){
System.out.println("");
}
}
}
/**
*
* @param
* @return
*/
public static JSONArray getAllvGpsHetongs() {
//需要修改 appid entryid apikey
APIUtils api = new APIUtils("628eeaace7f28c00089a60cc", "62b80148c6c1af0007f8a824","BkIyzlh1onqnqu9cQ3ralDQBjECn97ex");
final List<Map<String, Object>> condList = new ArrayList<Map<String, Object>>();
//因为想查询大于50的数据所以创建一个数组
JSONArray jsonArray = new JSONArray();
//在这个数组里面放一个数值类型的数字,用来判断查询范围
jsonArray.add("");
condList.add(new HashMap<String, Object>() {
{
put("field", "shfzhh");//查新字段的名称/别名
put("method", "nq");//判断的方法
put("value", jsonArray);//查询的条件
}
});
Map<String, Object> filter = new HashMap<String, Object>() {
{
put("rel", "and");
put("cond", condList);
}
};
//字段别名
List<Map<String, Object>> datas = api.getFormData(10000, new String[]{"shfzhh","hphm","xgrq","zhzhrq"},//身份证号,车牌号码,承包合同开始日期,承包合同终止日期
//身份号码
//车牌号码
//承包合同开始日期
filter, null);
if (datas == null) {
return null;
}
if (datas.size() == 0) {
return null;
}
int i = 1;
if (datas != null && datas.size() != 0) {
while (i != 0) {
if (datas.size() > (i * 10000 - 1)) {
String id = (String) (datas.get(i * 10000 - 1).get("_id"));
List<Map<String, Object>> data = findData(api, filter, id);
if (data == null) {
i = 0;
} else {
datas.addAll(data);
i = i + 1;
}
} else {
i = 0;
}
}
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("list", datas);
return jsonObject.getJSONArray("list");
}
private static List<Map<String, Object>> findData(APIUtils api, Map<String, Object> filter, String id) {
List<Map<String, Object>> datas = api.getFormData(10000, new String[]{"shfzhh","hphm","xgrq","zhzhrq"},
filter, id);
if (datas == null) {
return null;
}
if (datas.size() == 0) {
return null;
}
return datas;
}
}

View File

@ -0,0 +1,206 @@
package com.example.sso.dao;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.sso.util.APIUtils;
import com.example.sso.util.TimeUtil;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class J9053Dao {
public static void main(String[] args) {
getAllvGpsLiShiHeTong();
}
/**
* @param
* @return
*/
public static JSONArray getAllvGpsLiShiHeTong() {
//需要修改 appid entryid apikey
APIUtils api = new APIUtils("628eeaace7f28c00089a60cc", "62b817f0a5b6a3000714e456", "BkIyzlh1onqnqu9cQ3ralDQBjECn97ex");
final List<Map<String, Object>> condList = new ArrayList<Map<String, Object>>();
//因为想查询大于50的数据所以创建一个数组
JSONArray jsonArray = new JSONArray();
//在这个数组里面放一个数值类型的数字,用来判断查询范围
jsonArray.add("");
condList.add(new HashMap<String, Object>() {
{
put("field", "shfzhh");//查新字段的名称/别名
put("method", "nq");//判断的方法
put("value", jsonArray);//查询的条件
}
});
Map<String, Object> filter = new HashMap<String, Object>() {
{
put("rel", "and");
put("cond", condList);
}
};
//字段别名
List<Map<String, Object>> datas = api.getFormData(10000, new String[]{"shfzhh", "hphm", "xgrq","kshrq"},//身份证号,车牌号码,退租日期,承包合同开始日期
//身份号码
//车牌号码
//承包合同开始日期
filter, null);
if (datas == null) {
return null;
}
if (datas.size() == 0) {
return null;
}
int i = 1;
if (datas != null && datas.size() != 0) {
while (i != 0) {
if (datas.size() > (i * 10000 - 1)) {
String id = (String) (datas.get(i * 10000 - 1).get("_id"));
List<Map<String, Object>> data = findData(api, filter, id);
if (data == null) {
i = 0;
} else {
datas.addAll(data);
i = i + 1;
}
} else {
i = 0;
}
}
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("list", datas);
return jsonObject.getJSONArray("list");
}
private static List<Map<String, Object>> findData(APIUtils api, Map<String, Object> filter, String id) {
List<Map<String, Object>> datas = api.getFormData(10000, new String[]{"shfzhh", "hphm", "xgrq","kshrq"},
filter, id);
if (datas == null) {
return null;
}
if (datas.size() == 0) {
return null;
}
return datas;
}
/**
* 更新客户报备数据
*
* @throws Exception
*/
public static void createTuiJianBiao(JSONObject jsonObject) {
try {
APIUtils api = new APIUtils("628eeaace7f28c00089a60cc", "63c0af1e6a928200087c72d5", "BkIyzlh1onqnqu9cQ3ralDQBjECn97ex");
Map<String, Object> map1;
map1 = new HashMap<String, Object>() {
{
//推荐人邮箱
put("tuijian_recommendemail", new HashMap<String, Object>() {{
put("value", jsonObject.getString("tuijian_recommendEmail"));
}});
put("beituijian_mobile", new HashMap<String, Object>() {{
put("value", jsonObject.getString("beituijian_mobile"));
}});
put("tuijian_recommendmobile", new HashMap<String, Object>() {{
put("value", jsonObject.getString("tuijian_recommendMobile"));
}});
put("tuijian_employeeid", new HashMap<String, Object>() {{
put("value", jsonObject.getString("tuijian_employeeId"));
}});
put("beituijian_eamil", new HashMap<String, Object>() {{
put("value", jsonObject.getString("beituijian_mobile"));
}});
put("tuijian_recommendertype", new HashMap<String, Object>() {{
put("value", jsonObject.getString("tuijian_recommenderType"));
}});
put("beituijian_name", new HashMap<String, Object>() {{
put("value", jsonObject.getString("beituijian_name"));
}});
put("tuijian_recommendname", new HashMap<String, Object>() {{
put("value", jsonObject.getString("tuijian_recommendName"));
}});
put("recommendertype", new HashMap<String, Object>() {{
put("value", jsonObject.getString("recommenderType"));
}});
put("beituijian_certificatenumber", new HashMap<String, Object>() {{
put("value", jsonObject.getString("beituijian_certificateNumber"));
}});
put("delivertime", new HashMap<String, Object>() {{
put("value", jsonObject.getString("deliverTime"));
}});
put("department_name", new HashMap<String, Object>() {{
put("value", jsonObject.getString("department_name"));
}});
}
};
//把封装好的数据创建至简道云
api.createData(map1);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 更新客户报备数据
*
* @throws Exception
*/
public static void updateTuiJianBiao(String id, JSONObject jsonObject) {
try {
APIUtils api = new APIUtils("628eeaace7f28c00089a60cc", "63c0af1e6a928200087c72d5", "BkIyzlh1onqnqu9cQ3ralDQBjECn97ex");
Map<String, Object> map1;
map1 = new HashMap<String, Object>() {
{
//推荐人邮箱
put("tuijian_recommendemail", new HashMap<String, Object>() {{
put("value", jsonObject.getString("tuijian_recommendEmail"));
}});
put("beituijian_mobile", new HashMap<String, Object>() {{
put("value", jsonObject.getString("beituijian_mobile"));
}});
put("tuijian_recommendmobile", new HashMap<String, Object>() {{
put("value", jsonObject.getString("tuijian_recommendMobile"));
}});
put("tuijian_employeeid", new HashMap<String, Object>() {{
put("value", jsonObject.getString("tuijian_employeeId"));
}});
put("beituijian_eamil", new HashMap<String, Object>() {{
put("value", jsonObject.getString("beituijian_mobile"));
}});
put("tuijian_recommendertype", new HashMap<String, Object>() {{
put("value", jsonObject.getString("tuijian_recommenderType"));
}});
put("beituijian_name", new HashMap<String, Object>() {{
put("value", jsonObject.getString("beituijian_name"));
}});
put("tuijian_recommendname", new HashMap<String, Object>() {{
put("value", jsonObject.getString("tuijian_recommendName"));
}});
put("recommendertype", new HashMap<String, Object>() {{
put("value", jsonObject.getString("recommenderType"));
}});
put("beituijian_certificatenumber", new HashMap<String, Object>() {{
put("value", jsonObject.getString("beituijian_certificateNumber"));
}});
put("delivertime", new HashMap<String, Object>() {{
put("value", jsonObject.getString("deliverTime"));
}});
put("department_name", new HashMap<String, Object>() {{
put("value", jsonObject.getString("department_name"));
}});
}
};
//把封装好的数据创建至简道云
api.updateData(id, map1);
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,158 @@
package com.example.sso.dao;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.sso.util.APIUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class J905Dao {
public static void main(String[] args) {
getVGpsCheliangs();
}
/**
* 查询SIM卡号车牌号和终端号的对应关系
* @param
* @return
*/
public static JSONArray getAllSims() {
//需要修改 appid entryid apikey
APIUtils api = new APIUtils("628eeaace7f28c00089a60cc", "5673d2535dee5e584224e3e9","BkIyzlh1onqnqu9cQ3ralDQBjECn97ex");
final List<Map<String, Object>> condList = new ArrayList<Map<String, Object>>();
//因为想查询大于50的数据所以创建一个数组
JSONArray jsonArray = new JSONArray();
//在这个数组里面放一个数值类型的数字,用来判断查询范围
jsonArray.add("");
condList.add(new HashMap<String, Object>() {
{
put("field", "vcn");//查新字段的名称/别名
put("method", "nq");//判断的方法
put("value", jsonArray);//查询的条件
}
});
Map<String, Object> filter = new HashMap<String, Object>() {
{
put("rel", "and");
put("cond", condList);
}
};
//字段别名
List<Map<String, Object>> datas = api.getFormData(10000, new String[]{"vcn","mdn","mdn905","jjqbh"},//车牌号产品序列号UIM卡号计价器号
filter, null);
if (datas == null) {
return null;
}
if (datas.size() == 0) {
return null;
}
int i = 1;
if (datas != null && datas.size() != 0) {
while (i != 0) {
if (datas.size() > (i * 10000 - 1)) {
String id = (String) (datas.get(i * 10000 - 1).get("_id"));
List<Map<String, Object>> data = findData(api, filter, id);
if (data == null) {
i = 0;
} else {
datas.addAll(data);
i = i + 1;
}
} else {
i = 0;
}
}
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("list", datas);
return jsonObject.getJSONArray("list");
}
private static List<Map<String, Object>> findData(APIUtils api, Map<String, Object> filter, String id) {
List<Map<String, Object>> datas = api.getFormData(10000, new String[]{"vcn","mdn","mdn905","jjqbh"},//车牌号产品序列号UIM卡号计价器号
filter, id);
if (datas == null) {
return null;
}
if (datas.size() == 0) {
return null;
}
return datas;
}
/**
* 查询车辆
* @param
* @return
*/
public static JSONArray getVGpsCheliangs() {
//需要修改 appid entryid apikey
APIUtils api = new APIUtils("628eeaace7f28c00089a60cc", "5673d2535dee5e584224e3e9","BkIyzlh1onqnqu9cQ3ralDQBjECn97ex");
final List<Map<String, Object>> condList = new ArrayList<Map<String, Object>>();
//因为想查询大于50的数据所以创建一个数组
JSONArray jsonArray = new JSONArray();
//在这个数组里面放一个数值类型的数字,用来判断查询范围
jsonArray.add("");
condList.add(new HashMap<String, Object>() {
{
put("field", "vcn");//查新字段的名称/别名
put("method", "nq");//判断的方法
put("value", jsonArray);//查询的条件
}
});
Map<String, Object> filter = new HashMap<String, Object>() {
{
put("rel", "and");
put("cond", condList);
}
};
//字段别名
List<Map<String, Object>> datas = api.getFormData(10000, new String[]{"dw","ssh","vcn","chp",
"xh","ys","djrq","chlzht","jch","pshh","shyxzh","chjh","shynx","dqzht","zhtxf","yyfsh","lhyyf"},//所属部门(文本),分司,车牌号码,品牌,型号,颜色 ,注册登记日期,班制,简称,喷饰号,使用性质,车架号,使用年限,当前状态,状态细分,运营方式,联合运营方
filter, null);
if (datas == null) {
return null;
}
if (datas.size() == 0) {
return null;
}
int i = 1;
if (datas != null && datas.size() != 0) {
while (i != 0) {
if (datas.size() > (i * 10000 - 1)) {
String id = (String) (datas.get(i * 10000 - 1).get("_id"));
List<Map<String, Object>> data = getVGpsCheliangs_zi(api, filter, id);
if (data == null) {
i = 0;
} else {
datas.addAll(data);
i = i + 1;
}
} else {
i = 0;
}
}
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("list", datas);
return jsonObject.getJSONArray("list");
}
private static List<Map<String, Object>> getVGpsCheliangs_zi(APIUtils api, Map<String, Object> filter, String id) {
List<Map<String, Object>> datas = api.getFormData(10000, new String[]{"dw","ssh","vcn","chp",
"xh","ys","djrq","chlzht","jch","pshh","shyxzh","chjh","shynx","dqzht","zhtxf","yyfsh","lhyyf"},
filter, id);
if (datas == null) {
return null;
}
if (datas.size() == 0) {
return null;
}
return datas;
}
}

View File

@ -0,0 +1,227 @@
package com.example.sso.schedule;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.sso.dao.J9053Dao;
import com.example.sso.util.HttpUtil;
import com.example.sso.util.JDYUtil;
import com.example.sso.util.TimeUtil;
import com.example.sso.util.WXUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.sql.Time;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Component
public class ScheduleDep {
private static String app_key = "F493FDF0DA9B4DF3A826530B568E6BAF";
private static String app_secret = "B9BAA96975C74DB8AF07EB5D5243F56DE2FAE0ED37D64797AB2487EA3F8011CD";
@Scheduled(cron = "0 0 5 * * ?")//0 00 00 1 4,7,10,1 ?\
public static void SynDep() throws KeyManagementException, NoSuchAlgorithmException {
try {
getApplysByPhaseStatusCode();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
try {
getApplysByPhaseStatusCode();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
}
}
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 updateUser(JSONObject driver, Integer id) 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("iDNumber", driver.get("shfzhh"));//身份证号码
JSONObject employmentRecord = new JSONObject();
employmentRecord.put("originalId", driver.get("shfzhh"));//外部编码ID
employmentRecord.put("employmentType", "020c47b0-74b7-4a75-b454-e9905f64e1fc");//人员类别
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(), getToken()));
System.out.println(jsonObject.toJSONString());
// return jsonObject.getString("access_token");
}
/**
* 获取人员数据
*
* @return
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
*/
public static void getApplysByPhaseStatusCode() throws NoSuchAlgorithmException, KeyManagementException {
String url = "https://openapi.italent.cn/RecruitV6/api/v1/Apply/GetApplysByPhaseStatusCode";
JSONObject body = new JSONObject();
body.put("startTime", TimeUtil.getEarly6Month());
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss");
body.put("endTime", df.format(new Date()));
body.put("phaseCode", "S001");
body.put("statusCode", "U001");
JSONObject jsonObject = JSON.parseObject(HttpUtil.sendPost(url, body.toJSONString(), getToken()));
System.out.println(jsonObject.toJSONString());
JSONArray jsonArray = jsonObject.getJSONObject("data").getJSONArray("items");
// while (jsonObject.getJSONObject("data").getString("nextBatchId")!=null){
// body.put("batchId",jsonObject.getJSONObject("data").getString("nextBatchId"));
// JSONObject jsonObject1 =JSON.parseObject(HttpUtil.sendPost(url, body.toJSONString(), getToken()));
// JSONArray jsonArray1 = jsonObject1.getJSONObject("data").getJSONArray("items");
// jsonArray.addAll(jsonArray1);
// }
JSONObject jsonObject1 = new JSONObject();
JSONObject beitui = JDYUtil.getAllTuiJian();
for (Object o : jsonArray) {
JSONObject data = (JSONObject) o;
JSONObject applicantLite = data.getJSONObject("applicantLite");
if (data.getJSONObject("jobLite").getString("jobTitle").equals("出租车驾驶员")) {
String applyId = data.getString("applyId");
// JSONObject applicantLite = data.getJSONObject("applicantLite");
jsonObject1.put("beituijian_certificateNumber", applicantLite.getString("certificateNumber"));//身份证号码
jsonObject1.put("beituijian_name", applicantLite.getString("name"));//姓名
jsonObject1.put("beituijian_eamil", applicantLite.getString("eamil"));//身份证号码
jsonObject1.put("beituijian_mobile", applicantLite.getString("mobile"));//身份证号码
try {
getReferrerListByApplyId(applyId, jsonObject1);
} catch (Exception e) {
e.printStackTrace();
}
if (beitui.getString(jsonObject1.getString("beituijian_certificateNumber")) == null) {
J9053Dao.createTuiJianBiao(jsonObject1);
} else {
J9053Dao.updateTuiJianBiao(beitui.getJSONObject(jsonObject1.getString("beituijian_certificateNumber")).getString("_id"), jsonObject1);
}
jsonObject1.clear();
}
}
// return jsonObject.getString("access_token");
}
/**
* 根据申请ID获取推荐人相关信息
* @return
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
*/
public static JSONObject getReferrerListByApplyId(String guid, JSONObject jsonObject) throws NoSuchAlgorithmException, KeyManagementException, ParseException {
String url = "https://openapi.italent.cn/RecruitV6/api/v1/Recommend/GetReferrerListByApplyId?applyId=" + guid;
JSONObject jsonObject1 = JSON.parseObject(HttpUtil.sendGet(url, getToken()));
System.out.println(jsonObject1.toJSONString());
JSONArray jsonArray = jsonObject1.getJSONArray("data");
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss");
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
Date date = null;
for (Object o : jsonArray) {
JSONObject jsonObject2 = (JSONObject) o;
String deliverTime = jsonObject2.getString("deliverTime");
if (deliverTime != null) {
deliverTime = deliverTime.split("\\.")[0];
deliverTime = dateFormat.format(df.parse(deliverTime));
}
if (date == null) {
date = df.parse(deliverTime);
}
Boolean isEffective = jsonObject2.getBoolean("isEffective");
String recommendName = jsonObject2.getString("recommendName");
String recommendEmail = jsonObject2.getString("recommendEmail");
String recommendMobile = jsonObject2.getString("recommendMobile");
if (recommendEmail != null && recommendMobile != null
&& !recommendEmail.equals("") && !recommendMobile.equals("")) {
if (date != null) {
if (date.before(df.parse(deliverTime)) || date.equals(df.parse(deliverTime))) {
jsonObject.put("tuijian_recommendMobile", jsonObject2.getString("recommendMobile"));
jsonObject.put("tuijian_recommendName", jsonObject2.getString("recommendName"));
jsonObject.put("tuijian_recommendEmail", jsonObject2.getString("recommendEmail"));
jsonObject.put("tuijian_employeeId", jsonObject2.getString("employeeId"));
jsonObject.put("tuijian_recommenderType", jsonObject2.getString("recommenderType"));//推荐人类型
jsonObject.put("department_name", jsonObject2.getString("departmentName"));//推荐人类型
jsonObject.put("deliverTime", TimeUtil.timeConversion(deliverTime));//申请时间
}
}
}
if (date != null) {
if (deliverTime != null) {
if (date.before(df.parse(deliverTime))) {
date = df.parse(deliverTime);
}
}
}
}
return jsonObject;
// return jsonObject.getString("access_token");
}
/**
* 创建人员信息
*
* @return
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
*/
public static void createUser(HashMap<String, Object> driver, JSONObject orgNos) 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("email", driver.get("shjh") + "@yinjian.com");//邮箱
JSONObject employmentRecord = new JSONObject();
employmentRecord.put("entryDate", driver.get("lrrq"));//入职日期
employmentRecord.put("probation", 0);//试用期无试用期为0
String name = (String) driver.get("name");//
for (String str : orgNos.keySet()) {
if (str.contains((String) driver.get("ssbm") + (String) driver.get("fs"))) {
employmentRecord.put("OIdDepartment", orgNos.getInteger(str));//试用期无试用期为0
}
}
body.put("employeeInformation", employeeInformation);
body.put("employmentRecord", employmentRecord);
JSONObject jsonObject = JSON.parseObject(HttpUtil.sendPost(url, body.toJSONString(), getToken()));
System.out.println(jsonObject.toJSONString());
// return jsonObject.getString("access_token");
}
}

View File

@ -0,0 +1,219 @@
package com.example.sso.schedule;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.sso.dao.J9053Dao;
import com.example.sso.util.BeiSenTest;
import com.example.sso.util.HttpUtil;
import com.example.sso.util.JDYUtil;
import com.example.sso.util.TimeUtil;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
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.List;
import java.util.Map;
@Component
public class ScheduleDep1 {
private static String app_key = "F493FDF0DA9B4DF3A826530B568E6BAF";
private static String app_secret = "B9BAA96975C74DB8AF07EB5D5243F56DE2FAE0ED37D64797AB2487EA3F8011CD";
// @Scheduled(cron = "0 35 1 * * ?")//0 00 00 1 4,7,10,1 ?\
// public static void SynDep() throws KeyManagementException, NoSuchAlgorithmException {
// try {
// List<Map<String, Object>> drivers=JDYUtil.getAllDrivers1();//查询
// for (Map<String, Object> driver:drivers){
// Integer integer=Integer.valueOf((String) driver.get("oid"));
// BeiSenTest.deleteUser(integer);
// }
// }catch (Exception e) {
// e.printStackTrace();
// }
// }
// public static void main(String[] args) {
// try {
// getApplysByPhaseStatusCode();
// } catch (NoSuchAlgorithmException e) {
// e.printStackTrace();
// } catch (KeyManagementException e) {
// e.printStackTrace();
// }
// }
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 updateUser(JSONObject driver, Integer id) 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("iDNumber", driver.get("shfzhh"));//身份证号码
JSONObject employmentRecord = new JSONObject();
employmentRecord.put("originalId", driver.get("shfzhh"));//外部编码ID
employmentRecord.put("employmentType", "020c47b0-74b7-4a75-b454-e9905f64e1fc");//人员类别
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(), getToken()));
System.out.println(jsonObject.toJSONString());
// return jsonObject.getString("access_token");
}
/**
* 获取人员数据
*
* @return
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
*/
public static void getApplysByPhaseStatusCode() throws NoSuchAlgorithmException, KeyManagementException {
String url = "https://openapi.italent.cn/RecruitV6/api/v1/Apply/GetApplysByPhaseStatusCode";
JSONObject body = new JSONObject();
body.put("startTime", "2020-12-08T12:23:00");
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss");
body.put("endTime", df.format(new Date()));
body.put("phaseCode", "S001");
body.put("statusCode", "U001");
JSONObject jsonObject = JSON.parseObject(HttpUtil.sendPost(url, body.toJSONString(), getToken()));
System.out.println(jsonObject.toJSONString());
JSONArray jsonArray=jsonObject.getJSONObject("data").getJSONArray("items");
JSONObject jsonObject1=new JSONObject();
JSONObject beitui=JDYUtil.getAllTuiJian();
for (Object o:jsonArray){
JSONObject data=(JSONObject)o;
if (data.getJSONObject("jobLite").getString("jobTitle").equals("出租车驾驶员")){
String applyId=data.getString("applyId");
JSONObject applicantLite=data.getJSONObject("applicantLite");
if (applicantLite.getString("name").equals("吕玲")){
System.out.println("");
}
jsonObject1.put("beituijian_certificateNumber",applicantLite.getString("certificateNumber"));//身份证号码
jsonObject1.put("beituijian_name",applicantLite.getString("name"));//姓名
jsonObject1.put("beituijian_eamil",applicantLite.getString("eamil"));//身份证号码
jsonObject1.put("beituijian_mobile",applicantLite.getString("mobile"));//身份证号码
try {
getReferrerListByApplyId(applyId,jsonObject1);
} catch (Exception e) {
e.printStackTrace();
}
if (beitui.getString(jsonObject1.getString("beituijian_certificateNumber"))==null){
J9053Dao.createTuiJianBiao(jsonObject1);
}else {
J9053Dao.updateTuiJianBiao(beitui.getJSONObject(jsonObject1.getString("beituijian_certificateNumber")).getString("_id"),jsonObject1);
}
}
}
// return jsonObject.getString("access_token");
}
/**
* 根据申请ID获取推荐人相关信息
* @return
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
*/
public static JSONObject getReferrerListByApplyId(String guid,JSONObject jsonObject) throws NoSuchAlgorithmException, KeyManagementException, ParseException {
String url = "https://openapi.italent.cn/RecruitV6/api/v1/Recommend/GetReferrerListByApplyId?applyId="+guid;
JSONObject jsonObject1 = JSON.parseObject(HttpUtil.sendGet(url,getToken()));
System.out.println(jsonObject1.toJSONString());
JSONArray jsonArray=jsonObject1.getJSONArray("data");
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss");
SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
Date date=null;
for (Object o:jsonArray){
JSONObject jsonObject2=(JSONObject)o;
String deliverTime =jsonObject2.getString("deliverTime");
if (deliverTime!=null){
deliverTime=deliverTime.split("\\.")[0];
deliverTime=dateFormat.format(df.parse(deliverTime));
}
if (date==null){
date=df.parse(deliverTime);
}
Boolean isEffective=jsonObject2.getBoolean("isEffective");
String recommendName=jsonObject2.getString("recommendName");
String recommendEmail=jsonObject2.getString("recommendEmail");
String recommendMobile=jsonObject2.getString("recommendMobile");
if (recommendName!=null&&recommendEmail!=null&&recommendMobile!=null
&!recommendName.equals("")&&!recommendEmail.equals("")&&!recommendMobile.equals("")){
if (date!=null){
if (date.before(df.parse(deliverTime))||date.equals(df.parse(deliverTime))){
jsonObject.put("tuijian_recommendMobile",jsonObject2.getString("recommendMobile"));
jsonObject.put("tuijian_recommendName",jsonObject2.getString("recommendName"));
jsonObject.put("tuijian_recommendEmail",jsonObject2.getString("recommendEmail"));
jsonObject.put("tuijian_employeeId",jsonObject2.getString("employeeId"));
jsonObject.put("tuijian_recommenderType",jsonObject2.getString("recommenderType"));//推荐人类型
jsonObject.put("department_name",jsonObject2.getString("departmentName"));//推荐人类型
jsonObject.put("deliverTime", TimeUtil.timeConversion(deliverTime));//申请时间
}
}
}
if (date!=null){
if (deliverTime!=null){
if (date.before(df.parse(deliverTime))){
date=df.parse(deliverTime);
}
}
}
}
return jsonObject;
// return jsonObject.getString("access_token");
}
/**
* 创建人员信息
*
* @return
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
*/
public static void createUser(HashMap<String, Object> driver, JSONObject orgNos) 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("email", driver.get("shjh") + "@yinjian.com");//邮箱
JSONObject employmentRecord = new JSONObject();
employmentRecord.put("entryDate", driver.get("lrrq"));//入职日期
employmentRecord.put("probation", 0);//试用期无试用期为0
String name = (String) driver.get("name");//
for (String str : orgNos.keySet()) {
if (str.contains((String) driver.get("ssbm") + (String) driver.get("fs"))) {
employmentRecord.put("OIdDepartment", orgNos.getInteger(str));//试用期无试用期为0
}
}
body.put("employeeInformation", employeeInformation);
body.put("employmentRecord", employmentRecord);
JSONObject jsonObject = JSON.parseObject(HttpUtil.sendPost(url, body.toJSONString(), getToken()));
System.out.println(jsonObject.toJSONString());
// return jsonObject.getString("access_token");
}
}

View File

@ -0,0 +1,402 @@
package com.example.sso.schedule;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.sso.dao.J9053Dao;
import com.example.sso.util.APIUtils;
import com.example.sso.util.HttpUtil;
import com.example.sso.util.JDYUtil;
import com.example.sso.util.TimeUtil;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* 处理当日下车又上车相关人员
* 这部分人,不能使用修改接口,应在第二天使用新增接口遍历
*/
@Component
public class ScheduleLiZhiPerson {
private static String app_key = "F493FDF0DA9B4DF3A826530B568E6BAF";
private static String app_secret = "B9BAA96975C74DB8AF07EB5D5243F56DE2FAE0ED37D64797AB2487EA3F8011CD";
@Scheduled(cron = "0 20 5 * * ?")//0 00 00 1 4,7,10,1 ?\
// public static void main(String[] args) {
// try {
// SynDep();
// } catch (KeyManagementException e) {
// e.printStackTrace();
// } catch (NoSuchAlgorithmException e) {
// e.printStackTrace();
// }
// }
public static void SynDep() throws KeyManagementException, NoSuchAlgorithmException {
try {
JSONArray drivers = getAllLiShangDriver();//查询下车又上车的所有相关人员
for (Object o : drivers) {
JSONObject driver = (JSONObject) o;
String _id = driver.getString("_id");
String shfzhh = (String) driver.get("shfzhh");//获取当前人员身份证号码
JSONObject person = findPersonById_Card(shfzhh);//查询驾驶员信息表里该驾驶员的数据
JSONObject orgNos = JDYUtil.getOrgNos();
String integer=createUser(person, orgNos, person.getString("_id"));//创建该人员
if (integer.contains("200")){
APIUtils api = new APIUtils("628eeaace7f28c00089a60cc", "6434f517e34c130008183344", "BkIyzlh1onqnqu9cQ3ralDQBjECn97ex");
api.deleteData(_id);
}else {
updateBeiSenStatus(_id,integer);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 修改简道云订单数据状态字段
* @param id
* @param
* @return
*/
public static void updateBeiSenStatus(String id,String status){
APIUtils api = new APIUtils("628eeaace7f28c00089a60cc", "6434f517e34c130008183344", "BkIyzlh1onqnqu9cQ3ralDQBjECn97ex");
Map<String, Object> data = new HashMap<String, Object>() {{
put("status", new HashMap<String, Object>() {{
put("value", status);
}});
}};
api.updateData(id, data);
}
// public static void main(String[] args) {
// try {
// JSONArray drivers = getAllLiShangDriver();//查询下车又上车的所有相关人员
// for (Object o : drivers) {
// JSONObject driver = (JSONObject) o;
// String shfzhh = (String) driver.get("shfzhh");//获取当前人员身份证号码
// JSONObject person = findPersonById_Card(shfzhh);//查询驾驶员信息表里该驾驶员的数据
// JSONObject orgNos = JDYUtil.getOrgNos();
// createUser(person, orgNos, person.getString("_id"));//创建该人员
// }
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
/**
* 查询下车又上车的所有相关人员
*
* @param
* @return
*/
public static JSONArray getAllLiShangDriver() {
//需要修改 appid entryid apikey
APIUtils api = new APIUtils("628eeaace7f28c00089a60cc", "6434f517e34c130008183344", "BkIyzlh1onqnqu9cQ3ralDQBjECn97ex");
final List<Map<String, Object>> condList = new ArrayList<Map<String, Object>>();
//因为想查询大于50的数据所以创建一个数组
JSONArray jsonArray = new JSONArray();
//在这个数组里面放一个数值类型的数字,用来判断查询范围
jsonArray.add("");
condList.add(new HashMap<String, Object>() {
{
put("field", "xm");//查新字段的名称/别名
put("method", "nq");//判断的方法
put("value", jsonArray);//查询的条件
}
});
Map<String, Object> filter = new HashMap<String, Object>() {
{
put("rel", "and");
put("cond", condList);
}
};
//字段别名
List<Map<String, Object>> datas = api.getFormData(10000, new String[]{"shfzhh"},//身份证号码
filter, null);
if (datas == null) {
return null;
}
if (datas.size() == 0) {
return null;
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("list", datas);
return jsonObject.getJSONArray("list");
}
/**
* 根据身份证查询驾驶员信息表数据
*/
public static JSONObject findPersonById_Card(String id_card_num) {
//需要修改 appid entryid apikey
APIUtils api = new APIUtils("628eeaace7f28c00089a60cc", "5c9d82c72ceed93a0d9ebca4", "BkIyzlh1onqnqu9cQ3ralDQBjECn97ex");
final List<Map<String, Object>> condList = new ArrayList<Map<String, Object>>();
//因为想查询大于50的数据所以创建一个数组
JSONArray jsonArray = new JSONArray();
//在这个数组里面放一个数值类型的数字,用来判断查询范围
jsonArray.add(id_card_num);
condList.add(new HashMap<String, Object>() {
{
put("field", "shfzhh");//查新字段的名称/别名
put("method", "eq");//判断的方法
put("value", jsonArray);//查询的条件
}
});
Map<String, Object> filter = new HashMap<String, Object>() {
{
put("rel", "and");
put("cond", condList);
}
};
//字段别名
List<Map<String, Object>> datas = api.getFormData(10000, new String[]{"xm", "ssbm",
"fs", "yxbs", "lrrq", "shjh", "shfzhh", "shjh", "beisen_id"},//身份证号码
filter, null);
if (datas == null) {
return null;
}
if (datas.size() == 0) {
return null;
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("list", datas);
JSONArray jsonArray1 = new JSONArray();
for (Map<String, Object> o : datas) {
String time = (String) o.get("lrrq");
if (time != null) {
o.put("lrrq", TimeUtil.timeConversion2(time));
}
jsonArray1.add(o);
}
return jsonArray1.getJSONObject(0);
}
/**
* 创建人员信息
*
* @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((String) driver.get("ssbm") + (String) driver.get("fs")+"司")) {
// 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
// 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 String createUser(JSONObject driver, JSONObject orgNos, String id) throws NoSuchAlgorithmException, KeyManagementException {
String token = getToken();
// if (driver.getString("beisen_id") == null || driver.getString("beisen_id").equals("")) {
try {
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();
employmentRecord.put("entryDate", driver.get("lrrq"));//入职日期
employmentRecord.put("probation", 0);//试用期无试用期为0
String name = (String) driver.get("name");//
for (String str : orgNos.keySet()) {
if (str.equals(driver.get("fs"))) {
employmentRecord.put("OIdDepartment", orgNos.getInteger(str));//试用期无试用期为0
break;
}
}
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"));
}
return jsonObject.toJSONString();
}catch (Exception e){
e.printStackTrace();
return "同步异常";
}
// } else {
//如果不是新增则修改数据
// updateUser(driver, driver.getInteger("beisen_id"), orgNos, token);
// }
// 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 (driver.getString("beisen_id")==null||driver.getString("beisen_id").equals("")){
// 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();
// employmentRecord.put("entryDate", driver.get("lrrq"));//入职日期
// employmentRecord.put("probation", 0);//试用期无试用期为0
// String name = (String) driver.get("name");//
// employmentRecord.put("OIdDepartment",600186);//试用期无试用期为0
// body.put("employeeInformation", employeeInformation);
// body.put("employmentRecord", employmentRecord);
// JSONObject jsonObject = JSON.parseObject(HttpUtil.sendPost(url, body.toJSONString(),token));
// JSONObject returnData=jsonObject.getJSONObject("data");
// try {
// if (returnData!=null){
// System.out.println(driver.get("shfzhh")+"的创建账户动作返回为:"+jsonObject.toJSONString());
// if (jsonObject.getString("code").equals("200")){
// JDYUtil.updateBeiSenId(id,returnData.getString("userId"));
// }
// }
// }catch (Exception e){
// e.printStackTrace();
// }
// }else {
// //如果不是新增则修改数据
// updateUser(driver,driver.getInteger("beisen_id"),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();
employmentRecord.put("employmentType", "020c47b0-74b7-4a75-b454-e9905f64e1fc");//人员类别
for (String str : orgNos.keySet()) {
if (str.equals((String) driver.get("ssbm") + (String) 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");
}
/**
* 离职人员信息
*
* @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");
}
}

View File

@ -0,0 +1,27 @@
package com.example.sso.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.example.sso.util.HttpUtil;
import lombok.NoArgsConstructor;
import org.springframework.stereotype.Service;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
@Service
@NoArgsConstructor
public class JDYAuthService {
public static final String GET_USERINFO_URL = "http://10.165.35.44/cgi-bin/user/getuserinfo?access_token=ACCESS_TOKEN&code=CODE";
public String getUserID(String accessToken, String code) throws NoSuchAlgorithmException, KeyManagementException {
//1.获取请求的url
String get_userInfo_url = GET_USERINFO_URL.replace("ACCESS_TOKEN", accessToken)
.replace("CODE", code);
//2.调用接口,发送请求,获取成员信息
JSONObject jsonObject = JSON.parseObject(HttpUtil.sendGet(get_userInfo_url,accessToken));
return jsonObject.getString("UserId");
}
}

View File

@ -0,0 +1,44 @@
package com.example.sso.service;
import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTVerifier;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.interfaces.DecodedJWT;
import com.example.sso.config.SSOConfig;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Calendar;
import java.util.Date;
@Service
@NoArgsConstructor
@AllArgsConstructor
public class SSOService {
@Getter @Setter @Autowired private SSOConfig ssoConfig;
public String getResponse(String request,String username) {
Algorithm algorithm = Algorithm.HMAC256("");
JWTVerifier verifier = JWT.require(algorithm)
.withIssuer("com.jiandaoyun")
.build();
// DecodedJWT decoded = verifier.verify(request);
// if (!"sso_req".equals(decoded.getClaim("type").asString())) {
// return "";
// }
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
calendar.add(Calendar.HOUR_OF_DAY, 1);
return JWT.create()
.withIssuer("com.jiandaoyun")
.withClaim("type", "sso_res")
.withClaim("username", username)
.withAudience("com.jiandaoyun")
.withExpiresAt(calendar.getTime())
.sign(algorithm);
}
}

View File

@ -0,0 +1,503 @@
package com.example.sso.util;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.codec.Charsets;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicHeader;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.http.ssl.TrustStrategy;
import javax.net.ssl.SSLContext;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class APIUtils {
public static final String WEBSITE = "https://www.jiyuankeshang.com";
private static boolean retryIfRateLimited = true;
private String urlGetWidgets;
private String urlGetFormData;
private String urlRetrieveData;
private String urlUpdateData;
private String urlCreateData;
private String urlDeleteData;
private String urlCreateUSer;
private String urlCreatePerson;
private String urlCreatePersonAll;
private String urlCreateDep;
private String urlCreateDepAll;
private String urlGetDepartment;
private String urlGetPeople;
private String urlDeletePeople;
private static String apiKey;
/**
* @param appId - 应用id
* @param entryId - 表单id
* @param apiKey - apiKey
*/
public APIUtils(String appId, String entryId, String apiKey) {
this.apiKey = apiKey;
this.initUrl(appId, entryId);
}
public Map<String, Object> createPerson (Map<String, Object> person) {
Map<String, Object> data = null;
try {
Map<String, Object> result = (Map<String, Object>) this.sendRequest("POST",urlCreatePerson, person);
} catch (Exception e) {
e.printStackTrace();
}
return data;
}
public Map<String, Object> createDep (Map<String, Object> person) {
Map<String, Object> data = null;
try {
Map<String, Object> result = (Map<String, Object>) this.sendRequest("POST",urlCreatePerson, person);
data = (Map<String, Object>) result.get("department");
} catch (Exception e) {
e.printStackTrace();
}
return data;
}
private void initUrl (String appId, String entryId) {
urlGetWidgets = WEBSITE + "/api/v1/app/" + appId + "/entry/" + entryId + "/widgets";
urlGetFormData = WEBSITE + "/api/v1/app/" + appId + "/entry/" + entryId + "/data";
urlRetrieveData = WEBSITE + "/api/v1/app/" + appId + "/entry/" + entryId + "/data_retrieve";
urlUpdateData = WEBSITE + "/api/v1/app/" + appId + "/entry/" + entryId + "/data_update";
urlCreateData = WEBSITE + "/api/v3/app/" + appId + "/entry/" + entryId + "/data_create";
urlDeleteData = WEBSITE + "/api/v1/app/" + appId + "/entry/" + entryId + "/data_delete";
urlCreatePerson=WEBSITE+"/api/v2/user/create";
urlCreateUSer = WEBSITE + "/api/v2/user/create";
urlCreateDep=WEBSITE+"/api/v2/department/create";
urlCreateDepAll=WEBSITE+"/api/v2/department/import";
urlCreatePersonAll=WEBSITE+"/api/v2/user/import";
urlGetDepartment=WEBSITE+"/api/v2/department/1/department_list";
urlGetPeople=WEBSITE + "/api/v2/department/1/member_list";
urlDeletePeople=WEBSITE+"/api/v2/user/batch_delete";
}
public static HttpClient getSSLHttpClient() throws Exception {
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
//信任所有
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
return true;
}
}).build();
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext);
return HttpClients.custom().setSSLSocketFactory(sslsf).build();
}
/**
* 获取部门成员信息
* @param - 创建数据内容
* @return 更新后的数据
*/
public Map<String, Object> deletePeopleBatch(Map<String,Object> map) {
Map<String, Object> data = null;
try {
Map<String, Object> result = (Map<String, Object>) this.sendRequest("POST",urlDeletePeople, map);
return result;
// data = (Map<String, Object>) result.get("department");
} catch (Exception e) {
e.printStackTrace();
}
return data;
}
/**
* 获取请求头信息
* @return
*/
public static Header[] getHttpHeaders() {
List<Header> headerList = new ArrayList<Header>();
headerList.add(new BasicHeader("Authorization", "Bearer " + apiKey));
headerList.add(new BasicHeader("Content-Type", "application/json;charset=utf-8"));
return headerList.toArray(new Header[headerList.size()]);
}
/**
* 查询人员信息
* @param username - 创建数据内容
* @return 更新后的数据
*/
public Map<String, Object> findPerson (String username) {
Map<String, Object> data = null;
try {
Map<String, Object> result = (Map<String, Object>) this.sendRequest("POST",WEBSITE + "/api/v2/user/"+username+"/user_retrieve", new HashMap<>());
data = (Map<String, Object>) result.get("data");
} catch (Exception e) {
e.printStackTrace();
}
return data;
}
/**
* 发送HTTP请求
* @param method - HTTP动词 { GET|POST }
* @param url - 请求路径
* @param data - 请求的数据
* @throws Exception
*/
public static Object sendRequest (String method, String url, Map<String, Object> data) throws Exception {
HttpClient client = getSSLHttpClient();
Header[] headers = getHttpHeaders();
HttpRequestBase request;
method = method.toUpperCase();
if ("GET".equals(method)) {
// GET请求
URIBuilder uriBuilder = new URIBuilder(url);
if (data != null) {
// 添加请求参数
for(Map.Entry<String, Object> entry : data.entrySet()) {
uriBuilder.addParameter(entry.getKey(), (String) entry.getValue());
}
}
request = new HttpGet(uriBuilder.build());
} else if ("POST".equals(method)) {
// POST请求
request = new HttpPost(url);
ObjectMapper mapper = new ObjectMapper();
HttpEntity entity = new StringEntity(mapper.writeValueAsString(data), Charsets.UTF_8);
((HttpPost) request).setEntity(entity);
} else {
throw new RuntimeException("不支持的HTTP动词");
}
// 设置请求头
request.setHeaders(headers);
// 发送请求并获取返回结果
HttpResponse response = client.execute(request);
int statusCode = response.getStatusLine().getStatusCode();
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> result = (Map<String, Object>) mapper.readValue(response.getEntity().getContent(), Object.class);
if (statusCode >= 400) {
// 请求错误
if ((Integer) result.get("code") == 8303 && retryIfRateLimited) {
// 频率超限1s后重试
Thread.sleep(1000);
return sendRequest(method, url, data);
} else {
return result;
}
} else {
// 处理返回结果
return result;
}
}
/**
* 获取表单字段
* @return 表单字段
*/
public List<Map<String, Object>> getFormWidgets () {
List<Map<String, Object>> widgets = null;
try {
Map<String, Object> result = (Map<String, Object>) this.sendRequest("POST", urlGetWidgets, new HashMap<String, Object>());
widgets = (List<Map<String, Object>>) result.get("widgets");
} catch (Exception e) {
e.printStackTrace();
}
return widgets;
}
public List<Map<String, Object>> createUser(String username, String name, Integer[] departments){
Map<String, Object> data = null;
try {
Map<String, Object> requestData = new HashMap<String, Object>();
requestData.put("username",username);
requestData.put("name",name);
requestData.put("departments",departments);
Map<String, Object> result = (Map<String, Object>) this.sendRequest("POST",urlCreateUSer, requestData);
data = (Map<String, Object>) result.get("data");
}catch (Exception e) {
e.printStackTrace();
}
return (List<Map<String, Object>>) data;
}
/**
* 按条件获取表单数据
* @param limit - 数据条数
* @param fields - 显示的字段
* @param filter - 过滤条件
* @param dataId - 上次取数的最后一个数据id
* @return - 返回的数据
*/
public List<Map<String, Object>> getFormData (final int limit, final String[] fields, final Map<String, Object> filter, String dataId) {
List<Map<String, Object>> data = null;
try {
// 构造请求数据
Map<String, Object> requestData = new HashMap<String, Object>() {
{
put("limit", limit);
put("fields", fields);
put("filter", filter);
}
};
if (dataId != null) {
requestData.put("data_id", dataId);
}
Map<String, Object> result = (Map<String, Object>) this.sendRequest("POST", urlGetFormData, requestData);
data = (List<Map<String, Object>>) result.get("data");
} catch (Exception e) {
e.printStackTrace();
}
return data;
}
/**
* 按条件获取全部表单数据
* @return 表单数据
*/
public List<Map<String, Object>> getAllFormData (String[] fields, Map<String, Object> filter) {
List<Map<String, Object>> dataList = new ArrayList<Map<String, Object>>();
String offset = null;
do {
List<Map<String, Object>> data = this.getFormData(100, fields, filter, offset);
// 获取返回的数据
if (data == null || data.isEmpty()) {
// 已经获取全部的数据
offset = null;
} else {
// 获取最后一条数据的id
offset = (String) data.get(data.size() - 1).get("_id");
dataList.addAll(data);
}
} while (offset != null);
return dataList;
}
/**
* 搜索单条数据
* @param dataId - 要查询的数据id
* @return 表单数据
*/
public Map<String, Object> retrieveData (String dataId) {
Map<String, Object> data = null;
try {
Map<String, Object> requestData = new HashMap<String, Object>();
requestData.put("data_id", dataId);
Map<String, Object> result = (Map<String, Object>) this.sendRequest("POST", urlRetrieveData, requestData);
data = (Map<String, Object>) result.get("data");
} catch (Exception e) {
e.printStackTrace();
}
return data;
}
/**
* 新增部门
* @param - 创建数据内容
* @return 更新后的数据
*/
public Map<String, Object> createDataDep (Map<String, Object> requestData) {
Map<String, Object> data = null;
try {
Map<String, Object> result = (Map<String, Object>) this.sendRequest("POST",urlCreateDep, requestData);
// data = (Map<String, Object>) result.get("department");
} catch (Exception e) {
e.printStackTrace();
}
return data;
}
/**
* 批量创建部门
* @param - 创建数据内容
* @return 更新后的数据
*/
public Map<String, Object> createDataDepAll (Map<String, Object> requestData) {
Map<String, Object> data = null;
try {
Map<String, Object> result = (Map<String, Object>) this.sendRequest("POST",urlCreateDepAll, requestData);
// data = (Map<String, Object>) result.get("department");
} catch (Exception e) {
e.printStackTrace();
}
return data;
}
/**
* 批量创建人员
* @param - 创建数据内容
* @return 更新后的数据
*/
public Map<String, Object> createDataPersonAll (Map<String, Object> requestData) {
Map<String, Object> data = null;
try {
Map<String, Object> result = (Map<String, Object>) this.sendRequest("POST",urlCreatePersonAll, requestData);
System.out.println(result);
return result;
// data = (Map<String, Object>) result.get("department");
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* 获取部门信息
* @param - 创建数据内容
* @return 更新后的数据
*/
public Map<String, Object> getDepartment() {
Map<String, Object> map=new HashMap<>();
map.put("has_child",1);
Map<String, Object> data = null;
try {
Map<String, Object> result = (Map<String, Object>) this.sendRequest("POST",urlGetDepartment,map);
System.out.println(result);
return result;
// data = (Map<String, Object>) result.get("department");
} catch (Exception e) {
e.printStackTrace();
}
return data;
}
/**
* 获取部门成员信息
* @param - 创建数据内容
* @return 更新后的数据
*/
public Map<String, Object> getDepartmentPerson(String dno) {
Map<String, Object> map=new HashMap<>();
// map.put("has_child",1);
Map<String, Object> data = null;
try {
Map<String, Object> result = (Map<String, Object>) this.sendRequest("POST",WEBSITE+"/api/v2/department/"+dno+"/member_list",map);
return result;
// data = (Map<String, Object>) result.get("department");
} catch (Exception e) {
e.printStackTrace();
}
return data;
}
public Map<String, Object> deleteDepartment(Integer no) {
Map<String, Object> map=new HashMap<>();
map.put("has_child",1);
Map<String, Object> data = null;
try {
Map<String, Object> result = (Map<String, Object>) this.sendRequest("POST",WEBSITE+"/api/v2/department/"+no+"/delete",new HashMap<>());
System.out.println(result);
return result;
// data = (Map<String, Object>) result.get("department");
} catch (Exception e) {
e.printStackTrace();
}
return data;
}
// /**
// * 新增部门
// * @param - 创建数据内容
// * @return 更新后的数据
// */
// public Map<String, Object> createDataDep (Map<String, Object> requestData) {
// Map<String, Object> data = null;
// try {
// Map<String, Object> result = (Map<String, Object>) this.sendRequest("POST",urlCreateDep, requestData);
// data = (Map<String, Object>) result.get("data");
// } catch (Exception e) {
// e.printStackTrace();
// }
// return data;
// }
/**
* 创建单条数据
* @param rawData - 创建数据内容
* @return 更新后的数据
*/
public Map<String, Object> createData (Map<String, Object> rawData) {
Map<String, Object> data = null;
try {
Map<String, Object> requestData = new HashMap<String, Object>();
requestData.put("data", rawData);
requestData.put("is_start_workflow",true);
Map<String, Object> result = (Map<String, Object>) this.sendRequest("POST",urlCreateData, requestData);
data = (Map<String, Object>) result.get("data");
} catch (Exception e) {
e.printStackTrace();
}
return data;
}
/**
* 获取所有的人在简道云
* @return 更新后的数据
*/
public List<Map<String,Object>> getAllPeople () {
List<Map<String,Object>> data = null;
try {
Map<String, Object> requestData = new HashMap<String, Object>();
requestData.put("has_child",true);
// System.out.println("准备发起HTTP请求"+urlGetPeople);
Map<String, Object> result = (Map<String, Object>) this.sendRequest("POST",urlGetPeople, requestData);
data = (List<Map<String,Object>>) result.get("users");
} catch (Exception e) {
e.printStackTrace();
}
return data;
}
/**
* 更新单条数据
* @return 更新结果
*/
public Map<String, Object> updateData (String dataId, Map<String, Object> update) {
Map<String, Object> data = null;
try {
Map<String, Object> requestData = new HashMap<String, Object>();
requestData.put("data_id", dataId);
requestData.put("data", update);
Map<String, Object> result = (Map<String, Object>) this.sendRequest("POST", urlUpdateData, requestData);
data = (Map<String, Object>) result.get("data");
} catch (Exception e) {
e.printStackTrace();
}
return data;
}
/**
* 删除单条数据
* @return 删除结果
*/
public Map<String, String> deleteData (String dataId) {
Map<String, String> result = null;
try {
Map<String, Object> requestData = new HashMap<String, Object>();
requestData.put("data_id", dataId);
result = (Map<String, String>) this.sendRequest("POST", urlDeleteData, requestData);
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
}

View File

@ -0,0 +1,274 @@
package com.example.sso.util;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
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;
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();
employmentRecord.put("entryDate", 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.get("fs"))){
employmentRecord.put("OIdDepartment", orgNos.getInteger(str));//试用期无试用期为0
break;
}
}
//区分是否TYTY的人员类别为"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", "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");
}
/**
* 修改人员信息
*
* @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", "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");
}
/**
* 离职人员信息
*
* @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");
}
}

View File

@ -0,0 +1,293 @@
package com.example.sso.util;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.*;
public class BeiSenTest1 {
private static String app_key = "F493FDF0DA9B4DF3A826530B568E6BAF";
private static String app_secret = "B9BAA96975C74DB8AF07EB5D5243F56DE2FAE0ED37D64797AB2487EA3F8011CD";
private static int i = 0;
public static void main(String[] args) {
try {
JSONArray drivers = JDYUtil.getAllDrivers1();//查询
for (Object o : drivers) {
JSONObject driver=(JSONObject)o;
String shfzhh = (String) driver.get("shfzhh");//身份证号码
JSONObject person = findPersonById_Card(shfzhh);
JSONObject orgNos = JDYUtil.getOrgNos();
createUser(person, orgNos, person.getString("_id"));
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 根据身份证查询驾驶员信息表数据
*/
public static JSONObject findPersonById_Card(String id_card_num) {
//需要修改 appid entryid apikey
APIUtils api = new APIUtils("628eeaace7f28c00089a60cc", "5c9d82c72ceed93a0d9ebca4", "AXtEol6d7l0w2l5dUuqvhbg2kjzfYv6r");
final List<Map<String, Object>> condList = new ArrayList<Map<String, Object>>();
//因为想查询大于50的数据所以创建一个数组
JSONArray jsonArray = new JSONArray();
//在这个数组里面放一个数值类型的数字,用来判断查询范围
jsonArray.add(id_card_num);
condList.add(new HashMap<String, Object>() {
{
put("field", "shfzhh");//查新字段的名称/别名
put("method", "eq");//判断的方法
put("value", jsonArray);//查询的条件
}
});
Map<String, Object> filter = new HashMap<String, Object>() {
{
put("rel", "and");
put("cond", condList);
}
};
//字段别名
List<Map<String, Object>> datas = api.getFormData(10000, new String[]{"xm", "ssbm",
"fs","yxbs","lrrq","shjh","shfzhh","shjh","beisen_id"},//身份证号码
filter, null);
if (datas == null) {
return null;
}
if (datas.size() == 0) {
return null;
}
JSONObject jsonObject=new JSONObject();
jsonObject.put("list",datas);
JSONArray jsonArray1=new JSONArray();
for (Map<String, Object> o:datas){
String time=(String) o.get("lrrq");
if (time!=null){
o.put("lrrq",TimeUtil.timeConversion2(time));
}
jsonArray1.add(o);
}
return jsonArray1.getJSONObject(0);
}
/**
* 创建人员信息
*
* @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((String) driver.get("ssbm") + (String) driver.get("fs")+"司")) {
// 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
// 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 (driver.getString("beisen_id") == null || driver.getString("beisen_id").equals("")) {
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();
employmentRecord.put("entryDate", driver.get("lrrq"));//入职日期
employmentRecord.put("probation", 0);//试用期无试用期为0
String name = (String) driver.get("name");//
for (String str : orgNos.keySet()) {
if (str.equals(driver.get("fs"))) {
employmentRecord.put("OIdDepartment", orgNos.getInteger(str));//试用期无试用期为0
break;
}
}
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);
// }
// 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 (driver.getString("beisen_id")==null||driver.getString("beisen_id").equals("")){
// 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();
// employmentRecord.put("entryDate", driver.get("lrrq"));//入职日期
// employmentRecord.put("probation", 0);//试用期无试用期为0
// String name = (String) driver.get("name");//
// employmentRecord.put("OIdDepartment",600186);//试用期无试用期为0
// body.put("employeeInformation", employeeInformation);
// body.put("employmentRecord", employmentRecord);
// JSONObject jsonObject = JSON.parseObject(HttpUtil.sendPost(url, body.toJSONString(),token));
// JSONObject returnData=jsonObject.getJSONObject("data");
// try {
// if (returnData!=null){
// System.out.println(driver.get("shfzhh")+"的创建账户动作返回为:"+jsonObject.toJSONString());
// if (jsonObject.getString("code").equals("200")){
// JDYUtil.updateBeiSenId(id,returnData.getString("userId"));
// }
// }
// }catch (Exception e){
// e.printStackTrace();
// }
// }else {
// //如果不是新增则修改数据
// updateUser(driver,driver.getInteger("beisen_id"),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();
employmentRecord.put("employmentType", "020c47b0-74b7-4a75-b454-e9905f64e1fc");//人员类别
for (String str : orgNos.keySet()) {
if (str.equals((String) driver.get("ssbm") + (String) 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");
}
/**
* 离职人员信息
*
* @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");
}
}

View File

@ -0,0 +1,265 @@
package com.example.sso.util;
import java.io.IOException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.http.Consts;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.socket.ConnectionSocketFactory;
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
/** * Http工具类发送Http请求 Get请求请将参数放在url中 Post请求请将参数放在Map中 * * @author 程高伟 * @date 2017年1月5日 下午6:03:50 */
public class HttpUtil {
// private static final Logger log = LoggerFactory.getLogger(HttpUtil.class);
private static final CloseableHttpClient httpclient = HttpClients.createDefault();
private static final String userAgent = "Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.87 Safari/537.36";
public static SSLContext createIgnoreVerifySSL() throws NoSuchAlgorithmException, KeyManagementException {
SSLContext sc = SSLContext.getInstance("SSLv3");
// 实现一个X509TrustManager接口用于绕过验证不用修改里面的方法
X509TrustManager trustManager = new X509TrustManager() {
@Override
public void checkClientTrusted(
java.security.cert.X509Certificate[] paramArrayOfX509Certificate,
String paramString) throws CertificateException {
}
@Override
public void checkServerTrusted(
java.security.cert.X509Certificate[] paramArrayOfX509Certificate,
String paramString) throws CertificateException {
}
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
};
sc.init(null, new TrustManager[] { trustManager }, null);
return sc;
}
/** * 发送HttpGet请求 * * @param url * 请求地址 * @return 返回字符串 */
public static String sendGet(String url,String token) throws KeyManagementException, NoSuchAlgorithmException {
SSLContext sslcontext = createIgnoreVerifySSL();
// 设置协议http和https对应的处理socket链接工厂的对象
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.INSTANCE)
.register("https", new SSLConnectionSocketFactory(sslcontext))
.build();
PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(connManager).build();
String result = null;
CloseableHttpResponse response = null;
try {
HttpGet httpGet = new HttpGet(url);
httpGet.setHeader("User-Agent", userAgent);
httpGet.setHeader("Authorization", "Bearer "+token);
response = httpClient.execute(httpGet);
HttpEntity entity = response.getEntity();
if (entity != null) {
result = EntityUtils.toString(entity,"UTF-8");
}
} catch (Exception e) {
// log.error("处理失败 {}" + e);
e.printStackTrace();
} finally {
if (response != null) {
try {
response.close();
} catch (IOException e) {
// // log.error(e.getMessage());
}
}
}
return result;
}
/** * 发送HttpPost请求参数为json字符串 * * @param url * @param jsonStr * @return */
public static String sendPost(String url, String jsonStr,String token) throws KeyManagementException, NoSuchAlgorithmException {
//采用绕过验证的方式处理https请求
SSLContext sslcontext = createIgnoreVerifySSL();
// 设置协议http和https对应的处理socket链接工厂的对象
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.INSTANCE)
.register("https", new SSLConnectionSocketFactory(sslcontext))
.build();
PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(connManager).build();
String result = null;
// 字符串编码
StringEntity entity = new StringEntity(jsonStr, Consts.UTF_8);
// 设置content-type
entity.setContentType("application/json");
HttpPost httpPost = new HttpPost(url);
// 防止被当成攻击添加的
httpPost.setHeader("User-Agent", userAgent);
httpPost.setHeader("Authorization", "Bearer "+token);
// 接收参数设置
httpPost.setHeader("Accept", "application/json");
httpPost.setEntity(entity);
CloseableHttpResponse response = null;
try {
response = httpClient.execute(httpPost);
HttpEntity httpEntity = response.getEntity();
result = EntityUtils.toString(httpEntity);
} catch (IOException e) {
// // log.error(e.getMessage());
} finally {
// 关闭CloseableHttpResponse
if (response != null) {
try {
response.close();
} catch (IOException e) {
// // log.error(e.getMessage());
}
}
}
return result;
}
/** * 发送HttpPost请求参数为map * * @param url * 请求地址 * @param map * 请求参数 * @return 返回字符串 */
public static String sendPost(String url, Map<String, String> map) {
// 设置参数
List<NameValuePair> formparams = new ArrayList<NameValuePair>();
for (Map.Entry<String, String> entry : map.entrySet()) {
formparams.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
}
// 编码
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(formparams, Consts.UTF_8);
// 取得HttpPost对象
HttpPost httpPost = new HttpPost(url);
// 防止被当成攻击添加的
httpPost.setHeader("User-Agent", userAgent);
// 参数放入Entity
httpPost.setEntity(formEntity);
CloseableHttpResponse response = null;
String result = null;
try {
// 执行post请求
response = httpclient.execute(httpPost);
// 得到entity
HttpEntity entity = response.getEntity();
// 得到字符串
result = EntityUtils.toString(entity);
} catch (IOException e) {
// log.error(e.getMessage());
} finally {
if (response != null) {
try {
response.close();
} catch (IOException e) {
// log.error(e.getMessage());
}
}
}
return result;
}
/** * 发送HttpPost请求参数为json字符串 * * @param url * @param jsonStr * @return */
public static String sendPost(String url, String jsonStr) throws KeyManagementException, NoSuchAlgorithmException {
//采用绕过验证的方式处理https请求
SSLContext sslcontext = createIgnoreVerifySSL();
// 设置协议http和https对应的处理socket链接工厂的对象
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.INSTANCE)
.register("https", new SSLConnectionSocketFactory(sslcontext))
.build();
PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(connManager).build();
String result = null;
// 字符串编码
StringEntity entity = new StringEntity(jsonStr, Consts.UTF_8);
// 设置content-type
entity.setContentType("application/json");
HttpPost httpPost = new HttpPost(url);
// 防止被当成攻击添加的
httpPost.setHeader("User-Agent", userAgent);
httpPost.setHeader("Authorization", "Bearer ");
// 接收参数设置
httpPost.setHeader("Accept", "application/json");
httpPost.setEntity(entity);
CloseableHttpResponse response = null;
try {
response = httpClient.execute(httpPost);
HttpEntity httpEntity = response.getEntity();
result = EntityUtils.toString(httpEntity);
} catch (IOException e) {
// log.error(e.getMessage());
} finally {
// 关闭CloseableHttpResponse
if (response != null) {
try {
response.close();
} catch (IOException e) {
// log.error(e.getMessage());
}
}
}
System.out.println(result);
return result;
}
/** * 发送不带参数的HttpPost请求 * * @param url * @return */
public static String sendPost(String url) {
String result = null;
// 得到一个HttpPost对象
HttpPost httpPost = new HttpPost(url);
// 防止被当成攻击添加的
httpPost.setHeader("User-Agent", userAgent);
CloseableHttpResponse response = null;
try {
// 执行HttpPost请求并得到一个CloseableHttpResponse
response = httpclient.execute(httpPost);
// 从CloseableHttpResponse中拿到HttpEntity
HttpEntity entity = response.getEntity();
// 将HttpEntity转换为字符串
result = EntityUtils.toString(entity);
} catch (IOException e) {
// log.error(e.getMessage());
} finally {
// 关闭CloseableHttpResponse
if (response != null) {
try {
response.close();
} catch (IOException e) {
// log.error(e.getMessage());
}
}
}
return result;
}
}

View File

@ -0,0 +1,33 @@
package com.example.sso.util;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
public class J905Util {
/**
* 请求成功
* @param data
* @return
*/
public static JSONObject returnOK(JSONArray data){
JSONObject jsonObject=new JSONObject();
jsonObject.put("code",2000);
jsonObject.put("message","操作成功");
jsonObject.put("result",data);
return jsonObject;
}
/**
* 请求失败
* @param
* @return
*/
public static JSONObject returnLoser(int num,String meg){
JSONObject jsonObject=new JSONObject();
jsonObject.put("code",num);
jsonObject.put("message",meg);
return jsonObject;
}
}

View File

@ -0,0 +1,482 @@
package com.example.sso.util;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import java.util.*;
public class JDYUtil {
public static void main(String[] args) {
// JSONArray drivers=JDYUtil.getAllDrivers();//查询
// for (Object o:drivers){
// HashMap<String,Object> driver=(HashMap<String,Object>)o;
// updateToJDY((String) driver.get("_id"),(String) driver.get("shjh")+"@yinjian.com");
// }
getAllOtherPer();
}
public static List<Map<String, Object>> getAllOtherPerson() {
//需要修改 appid entryid apikey
APIUtils api = new APIUtils("5e129b2a041dd80006ab6f68", "639e03a23bd359000afb50e4", "jPK0bjd46jhmjdrRgi8Txts9wuKeqFA1");
final List<Map<String, Object>> condList = new ArrayList<Map<String, Object>>();
//因为想查询大于50的数据所以创建一个数组
JSONArray jsonArray = new JSONArray();
//在这个数组里面放一个数值类型的数字,用来判断查询范围
jsonArray.add("");
condList.add(new HashMap<String, Object>() {
{
put("field", "name");//查新字段的名称/别名
put("method", "nq");//判断的方法
put("value", jsonArray);//查询的条件
}
});
Map<String, Object> filter = new HashMap<String, Object>() {
{
put("rel", "and");
put("cond", condList);
}
};
//字段别名
List<Map<String, Object>> datas = api.getFormData(15000, new String[]{"_id", "", "",""},
filter, null);
if (datas == null) {
return null;
}
if (datas.size() == 0) {
return null;
}
int i=0;
Double sum=0.0;
for (Map<String, Object> o:datas){
HashMap<String,Object> map=(HashMap<String,Object>)o.get("_widget_1671300003467");
String name=(String) map.get("name");
if (name.equals("Taryn-章婷婷")){
i=i+1;
try {
Double fen=(Double)o.get("_widget_1671300003485");
sum=sum+fen;
}catch (Exception e){
int fen=(int)o.get("_widget_1671300003485");
sum=sum+fen;
}
}
}
Double age=sum/i;
return datas;
}
public static JSONObject getAllTuiJian() {
//需要修改 appid entryid apikey
APIUtils api = new APIUtils("628eeaace7f28c00089a60cc", "63c0af1e6a928200087c72d5", "BkIyzlh1onqnqu9cQ3ralDQBjECn97ex");
final List<Map<String, Object>> condList = new ArrayList<Map<String, Object>>();
//因为想查询大于50的数据所以创建一个数组
JSONArray jsonArray = new JSONArray();
//在这个数组里面放一个数值类型的数字,用来判断查询范围
jsonArray.add("");
condList.add(new HashMap<String, Object>() {
{
put("field", "beituijian_certificatenumber");//查新字段的名称/别名
put("method", "nq");//判断的方法
put("value", jsonArray);//查询的条件
}
});
Map<String, Object> filter = new HashMap<String, Object>() {
{
put("rel", "and");
put("cond", condList);
}
};
//字段别名
List<Map<String, Object>> datas = api.getFormData(15000, new String[]{"_id", "beituijian_certificatenumber", "beituijian_name"},
filter, null);
if (datas == null) {
return null;
}
if (datas.size() == 0) {
return null;
}
JSONObject jsonObject=new JSONObject();
for (Map<String, Object> map:datas){
String beituijian_certificatenumber=(String) map.get("beituijian_certificatenumber");
jsonObject.put(beituijian_certificatenumber,map);
}
return jsonObject;
}
public static List<Map<String, Object>> getAllOtherPer() {
//需要修改 appid entryid apikey
APIUtils api = new APIUtils("5e129b2a041dd80006ab6f68", "6396f5fbdcc24b000ae1e9ac", "jPK0bjd46jhmjdrRgi8Txts9wuKeqFA1");
final List<Map<String, Object>> condList = new ArrayList<Map<String, Object>>();
//因为想查询大于50的数据所以创建一个数组
JSONArray jsonArray = new JSONArray();
//在这个数组里面放一个数值类型的数字,用来判断查询范围
jsonArray.add("");
condList.add(new HashMap<String, Object>() {
{
put("field", "name");//查新字段的名称/别名
put("method", "nq");//判断的方法
put("value", jsonArray);//查询的条件
}
});
Map<String, Object> filter = new HashMap<String, Object>() {
{
put("rel", "and");
put("cond", condList);
}
};
//字段别名
List<Map<String, Object>> datas = api.getFormData(15000, new String[]{"_id", "", "",""},
filter, null);
if (datas == null) {
return null;
}
if (datas.size() == 0) {
return null;
}
int i=0;
Double sum=0.0;
for (Map<String, Object> o:datas){
// HashMap<String,Object> map=();
// String name=(String) map.get("name");
if (o.get("_widget_1665547160471").equals("组长")){
i=i+1;
try {
// Double fen=(Double)o.get("_widget_1671300003485");
// sum=sum+fen;
}catch (Exception e){
// int fen=(int)o.get("_widget_1671300003485");
// sum=sum+fen;
}
}
}
Double age=sum/i;
return datas;
}
/**
* 查询每个人的承包金标准 分别为 承包金(月份)、个税、保养费、调度费、社保 组成
* @param
* @return
*/
public static JSONArray getAllDrivers() {
//需要修改 appid entryid apikey
APIUtils api = new APIUtils("628eeaace7f28c00089a60cc", "5c9d82c72ceed93a0d9ebca4", "BkIyzlh1onqnqu9cQ3ralDQBjECn97ex");
final List<Map<String, Object>> condList = new ArrayList<Map<String, Object>>();
//因为想查询大于50的数据所以创建一个数组
JSONArray jsonArray = new JSONArray();
//在这个数组里面放一个数值类型的数字,用来判断查询范围
jsonArray.add("运营");
JSONArray jsonArray2 = new JSONArray();
//在这个数组里面放一个数值类型的数字,用来判断查询范围
jsonArray2.add("");
// JSONArray jsonArray3 = new JSONArray();
//在这个数组里面放一个数值类型的数字,用来判断查询范围
// jsonArray3.add("23分");
condList.add(new HashMap<String, Object>() {
{
put("field", "status");//查新字段的名称/别名
put("method", "eq");//判断的方法
put("value", jsonArray);//查询的条件
}
});
condList.add(new HashMap<String, Object>() {
{
put("field", "beisen_id");//查新字段的名称/别名
put("method", "empty");//判断的方法
// put("value", jsonArray2);//查询的条件
}
});
// condList.add(new HashMap<String, Object>() {
// {
// put("field", "fs");//查新字段的名称/别名
// put("method", "eq");//判断的方法
// put("value", jsonArray3);//查询的条件
// }
// });
Map<String, Object> filter = new HashMap<String, Object>() {
{
put("rel", "and");
put("cond", condList);
}
};
//字段别名
List<Map<String, Object>> datas = api.getFormData(10000, new String[]{"xm", "ssbm",
"fs","yxbs","lrrq","shjh","shfzhh","shjh","beisen_id"},//姓名,所属部门,分司
filter, null);
if (datas == null) {
return null;
}
if (datas.size() == 0) {
return null;
}
int i=1;
if (datas!=null&&datas.size()!=0){
while (i!=0){
if (datas.size()>(i*10000-1)){
String id=(String) (datas.get(i*10000-1).get("_id"));
List<Map<String, Object>> data=findData(api,filter,id);
if (data==null){
i=0;
}else {
datas.addAll(data);
i=i+1;
}
}else {
i=0;
}
}
}
JSONObject jsonObject=new JSONObject();
jsonObject.put("list",datas);
JSONArray jsonArray1=new JSONArray();
for (Map<String, Object> o:datas){
String time=(String) o.get("lrrq");
if (time!=null){
o.put("lrrq",TimeUtil.timeConversion1(time));
}
jsonArray1.add(o);
}
return jsonArray1;
}
/**
* 查询每个人的承包金标准 分别为 承包金(月份)、个税、保养费、调度费、社保 组成
* @param
* @return
*/
public static JSONArray getAllDrivers1() {
//需要修改 appid entryid apikey
APIUtils api = new APIUtils("628eeaace7f28c00089a60cc", "6437906af93cf400083ddb7b", "BkIyzlh1onqnqu9cQ3ralDQBjECn97ex");
final List<Map<String, Object>> condList = new ArrayList<Map<String, Object>>();
//因为想查询大于50的数据所以创建一个数组
JSONArray jsonArray = new JSONArray();
//在这个数组里面放一个数值类型的数字,用来判断查询范围
jsonArray.add("");
condList.add(new HashMap<String, Object>() {
{
put("field", "xm");//查新字段的名称/别名
put("method", "nq");//判断的方法
put("value", jsonArray);//查询的条件
}
});
Map<String, Object> filter = new HashMap<String, Object>() {
{
put("rel", "and");
put("cond", condList);
}
};
//字段别名
List<Map<String, Object>> datas = api.getFormData(10000, new String[]{"shfzhh"},//身份证号码
filter, null);
if (datas == null) {
return null;
}
if (datas.size() == 0) {
return null;
}
JSONObject jsonObject=new JSONObject();
jsonObject.put("list",datas);
return jsonObject.getJSONArray("list");
}
/**
* 查询北森导入数据人员信息表
* @param
* @return
*/
public static JSONArray getAllDriversBeiSen() {
//需要修改 appid entryid apikey
APIUtils api = new APIUtils("628eeaace7f28c00089a60cc", "63be479b8d5076000a259361", "BkIyzlh1onqnqu9cQ3ralDQBjECn97ex");
final List<Map<String, Object>> condList = new ArrayList<Map<String, Object>>();
//因为想查询大于50的数据所以创建一个数组
JSONArray jsonArray = new JSONArray();
//在这个数组里面放一个数值类型的数字,用来判断查询范围
jsonArray.add("");
condList.add(new HashMap<String, Object>() {
{
put("field", "zhanghao");//查新字段的名称/别名
put("method", "nq");//判断的方法
put("value", jsonArray);//查询的条件
}
});
condList.add(new HashMap<String, Object>() {
{
put("field", "beisen_id");//查新字段的名称/别名
put("method", "eq");//判断的方法
put("value", jsonArray);//查询的条件
}
});
Map<String, Object> filter = new HashMap<String, Object>() {
{
put("rel", "and");
put("cond", condList);
}
};
//字段别名
List<Map<String, Object>> datas = api.getFormData(10000, new String[]{"xm","zhanghao",
"oid","beisen_id"},//姓名,所属部门,分司,
filter, null);
if (datas == null) {
return null;
}
if (datas.size() == 0) {
return null;
}
int i=1;
if (datas!=null&&datas.size()!=0){
while (i!=0){
if (datas.size()>(i*10000-1)){
String id=(String) (datas.get(i*10000-1).get("_id"));
List<Map<String, Object>> data=findData1(api,filter,id);
if (data==null){
i=0;
}else {
datas.addAll(data);
i=i+1;
}
}else {
i=0;
}
}
}
JSONObject jsonObject=new JSONObject();
jsonObject.put("list",datas);
return jsonObject.getJSONArray("list");
}
/**
* 查询
* @param
* @return
*/
public static JSONObject getOrgNos() {
//需要修改 appid entryid apikey
APIUtils api = new APIUtils("628eeaace7f28c00089a60cc", "63b67cbb8de4d3000a4c60e2", "BkIyzlh1onqnqu9cQ3ralDQBjECn97ex");
final List<Map<String, Object>> condList = new ArrayList<Map<String, Object>>();
//因为想查询大于50的数据所以创建一个数组
JSONArray jsonArray = new JSONArray();
//在这个数组里面放一个数值类型的数字,用来判断查询范围
jsonArray.add("");
condList.add(new HashMap<String, Object>() {
{
put("field", "status");//查新字段的名称/别名
put("method", "nq");//判断的方法
put("value", jsonArray);//查询的条件
}
});
Map<String, Object> filter = new HashMap<String, Object>() {
{
put("rel", "and");
put("cond", condList);
}
};
//字段别名
List<Map<String, Object>> datas = api.getFormData(10000, new String[]{"name", "zuzhidanyuan_id"},
//姓名,所属部门,分司
filter, null);
if (datas == null) {
return null;
}
if (datas.size() == 0) {
return null;
}
JSONObject jsonObject=new JSONObject();
for (Map<String, Object> data:datas){
jsonObject.put((String) data.get("name"),data.get("zuzhidanyuan_id"));
}
return jsonObject;
}
private static List<Map<String, Object>> findData(APIUtils api,Map<String, Object> filter,String id){
List<Map<String, Object>> datas = api.getFormData(10000, new String[]{"xm", "ssbm",
"fs","yxbs","lrrq","shjh","shfzhh","shjh"},
filter, id);
if (datas == null) {
return null;
}
if (datas.size() == 0) {
return null;
}
return datas;
}
private static List<Map<String, Object>> findData1(APIUtils api,Map<String, Object> filter,String id){
List<Map<String, Object>> datas = api.getFormData(10000, new String[]{"xm", "ssbm",
"fs","yxbs","lrrq","shjh","shfzhh"},
filter, id);
if (datas == null) {
return null;
}
if (datas.size() == 0) {
return null;
}
return datas;
}
/**
* 修改简道云订单数据状态字段
* @param id
* @param
* @return
*/
public static void updateToJDY(String id,String yxbs){
APIUtils api = new APIUtils("628eeaace7f28c00089a60cc", "5c9d82c72ceed93a0d9ebca4", "BkIyzlh1onqnqu9cQ3ralDQBjECn97ex");
Map<String, Object> data = new HashMap<String, Object>() {{
put("yxbs", new HashMap<String, Object>() {{
put("value", yxbs);
}});
}};
api.updateData(id, data);
}
/**
* 修改简道云订单数据状态字段
* @param id
* @param
* @return
*/
public static void updateBeiSenId(String id,String beisen_id){
APIUtils api = new APIUtils("628eeaace7f28c00089a60cc", "5c9d82c72ceed93a0d9ebca4", "BkIyzlh1onqnqu9cQ3ralDQBjECn97ex");
Map<String, Object> data = new HashMap<String, Object>() {{
put("beisen_id", new HashMap<String, Object>() {{
put("value", beisen_id);
}});
}};
api.updateData(id, data);
}
/**
* 修改简道云订单数据状态字段
* @param id
* @param
* @return
*/
public static void createToJDY(String id,String yxbs){
APIUtils api = new APIUtils("628eeaace7f28c00089a60cc", "5c9d82c72ceed93a0d9ebca4", "BkIyzlh1onqnqu9cQ3ralDQBjECn97ex");
Map<String, Object> data = new HashMap<String, Object>() {{
put("yxbs", new HashMap<String, Object>() {{
put("value", yxbs);
}});
}};
api.updateData(id, data);
}
}

View File

@ -0,0 +1,94 @@
package com.example.sso.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
public class TimeUtil {
/**
* 由于时区的原因,调整时区
* @return
*/
public static String timeConversion(String time){
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
Date time_Date=sf.parse(time);
Calendar calendar=Calendar.getInstance();
calendar.setTime(time_Date);
calendar.add(Calendar.HOUR_OF_DAY, -8);// before 8 hour
return df.format(calendar.getTime());
} catch (ParseException e) {
e.printStackTrace();
}
return "";
}
/**
* 由于时区的原因,调整时区
* @return
*/
public static String timeConversion1(String time){
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
try {
Date time_Date=sf.parse(time);
Calendar calendar=Calendar.getInstance();
calendar.setTime(time_Date);
// calendar.add(Calendar.DAY_OF_MONTH,+2);
calendar.add(Calendar.HOUR_OF_DAY, +8);// before 8 hour
return df.format(calendar.getTime());
} catch (ParseException e) {
e.printStackTrace();
}
return "";
}
/**
* 由于时区的原因,调整时区
* @return
*/
public static String timeConversion2(String time){
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
try {
Date time_Date=sf.parse(time);
Calendar calendar=Calendar.getInstance();
calendar.setTime(time_Date);
calendar.add(Calendar.DAY_OF_MONTH,+1);
calendar.add(Calendar.HOUR_OF_DAY, +8);// before 8 hour
return df.format(calendar.getTime());
} catch (ParseException e) {
e.printStackTrace();
}
return "";
}
public static void main(String[] args) {
getEarly6Month();
}
/**
* 由于时区的原因,调整时区
* @return
*/
public static String getEarly6Month(){
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
try {
Date time_Date=new Date();
Calendar calendar=Calendar.getInstance();
calendar.setTime(time_Date);
// calendar.add(Calendar.DAY_OF_MONTH,+2);
calendar.add(Calendar.DAY_OF_MONTH, -1);// before 8 hour
return df.format(calendar.getTime());
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
}

View File

@ -0,0 +1,12 @@
package com.example.sso.util;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
public class WXUtil {
}

View File

@ -0,0 +1,8 @@
sso:
acs: https://www.jiandaoyun.com/sso/custom/59bb7045f3b3ab31f241bbf1/acs
secret:
server:
port: 12336
#正式环境
# port: 8080
#测试环境

View File

@ -0,0 +1,27 @@
package com.example.sso;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
//import org.junit.Test;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
@SpringBootTest
class SsoApplicationTests {
// @Test
void context() {
String json = "[{\"name\":\"1111\",\"code\":\"123\"},{\"name\":\"1111\",\"code\":\"123\"},{\"name\":\"1234\",\"code\":\"111\"}]";
List list = JSONObject.parseArray(json);
HashSet hs = new HashSet(list);
String jsonSet = JSON.toJSONString(hs);
JSONArray newjsonarray= new JSONArray(Collections.singletonList(jsonSet));
System.out.println(newjsonarray);
}
}