366 lines
15 KiB
Java
366 lines
15 KiB
Java
|
|
package com.zhgd.xmgl.util;
|
|||
|
|
|
|||
|
|
import java.util.ArrayList;
|
|||
|
|
import java.util.List;
|
|||
|
|
|
|||
|
|
import org.apache.commons.lang.StringUtils;
|
|||
|
|
import org.apache.commons.logging.Log;
|
|||
|
|
import org.apache.commons.logging.LogFactory;
|
|||
|
|
import org.apache.http.HttpResponse;
|
|||
|
|
import org.apache.http.client.methods.HttpPost;
|
|||
|
|
import org.apache.http.entity.StringEntity;
|
|||
|
|
import org.apache.http.impl.client.HttpClients;
|
|||
|
|
import org.apache.http.util.EntityUtils;
|
|||
|
|
|
|||
|
|
import com.zhgd.xmgl.entity.vo.CompanyTypeBean;
|
|||
|
|
import com.zhgd.xmgl.entity.vo.PersonBean;
|
|||
|
|
import com.zhgd.xmgl.entity.vo.WorkTypeBean;
|
|||
|
|
|
|||
|
|
import cn.hutool.json.JSONArray;
|
|||
|
|
import cn.hutool.json.JSONObject;
|
|||
|
|
import cn.hutool.json.JSONUtil;
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 从沃尔获取项目数据
|
|||
|
|
*/
|
|||
|
|
public class PostToVankeUtils {
|
|||
|
|
private static Log logger = LogFactory.getLog(PostToVankeUtils.class);
|
|||
|
|
//public static String vkUrl="http://stg-gongdi.vanrui.com/";
|
|||
|
|
//public static String key="866aa746b11f42b887ba51babbb2aa7b";
|
|||
|
|
|
|||
|
|
//public static String vkUrl="https://gongdi.vanke.com/";
|
|||
|
|
//public static String key="bf2395ea4e5e452f851aba53c3c4a855";
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 获取万科数据工具类
|
|||
|
|
* @param url
|
|||
|
|
* @param jsondata
|
|||
|
|
* @return
|
|||
|
|
*/
|
|||
|
|
private static String getVnakeDataUtil(String url ,String jsondata,String key){
|
|||
|
|
String res = "";
|
|||
|
|
try {
|
|||
|
|
String jsonBase64 = java.util.Base64.getEncoder().encodeToString(jsondata.getBytes("UTF-8"));
|
|||
|
|
String sign = org.apache.commons.codec.digest.DigestUtils.md5Hex(jsonBase64 + ",key="+key);
|
|||
|
|
HttpPost post = new HttpPost(url+"?sign=" + sign);
|
|||
|
|
StringEntity entity = new StringEntity(jsondata, "UTF-8");
|
|||
|
|
entity.setContentType("application/json");
|
|||
|
|
post.setEntity(entity);
|
|||
|
|
HttpResponse response = HttpClients.createDefault().execute(post);
|
|||
|
|
res = EntityUtils.toString(response.getEntity(), "UTF-8");
|
|||
|
|
} catch (Exception throwables) {
|
|||
|
|
throwables.printStackTrace();
|
|||
|
|
}
|
|||
|
|
return res;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 获取万科企业类型
|
|||
|
|
*/
|
|||
|
|
private static List<CompanyTypeBean> getVankeComapnyTypeList(String url,String key){
|
|||
|
|
List<CompanyTypeBean> companyTypeLists = new ArrayList<>();
|
|||
|
|
String comapnyTypeList = getVnakeDataUtil(url+"/itbgp/api/getCompanyType","{}",key);
|
|||
|
|
logger.info("获取万科企业类型返回----"+comapnyTypeList);
|
|||
|
|
JSONObject jsonObject = new JSONObject(comapnyTypeList);
|
|||
|
|
JSONArray jsonArray = (JSONArray) jsonObject.get("data");
|
|||
|
|
companyTypeLists.clear();
|
|||
|
|
for (int i =0 ;i<jsonArray.size();i++){
|
|||
|
|
JSONObject copanytypebean = (JSONObject) jsonArray.get(i);
|
|||
|
|
CompanyTypeBean companyTypeBean = new CompanyTypeBean();
|
|||
|
|
companyTypeBean.setCompanyTypeId(Integer.parseInt(copanytypebean.get("id").toString()));
|
|||
|
|
companyTypeBean.setCompanyType(copanytypebean.get("companyTypeName").toString());
|
|||
|
|
companyTypeLists.add(companyTypeBean);
|
|||
|
|
}
|
|||
|
|
return companyTypeLists;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 添加万科企业
|
|||
|
|
* @param socialCode 企业信用代码
|
|||
|
|
* @param projectCode 项目编码
|
|||
|
|
* @param companyTypeName 企业类型
|
|||
|
|
* @param companyName 企业名称
|
|||
|
|
* @param companyLegalPerson 企业法人
|
|||
|
|
*/
|
|||
|
|
public static void sendAddComapny(String socialCode,String projectCode,String companyTypeName,String companyName,String companyLegalPerson,String serverUrl,String key){
|
|||
|
|
List<CompanyTypeBean> companyTypeLists =getVankeComapnyTypeList(serverUrl,key);
|
|||
|
|
int companyTypeId =-1,laowutype= -1;
|
|||
|
|
for (CompanyTypeBean companytype : companyTypeLists){
|
|||
|
|
if(companytype.getCompanyType().equals(companyTypeName)) {
|
|||
|
|
companyTypeId = companytype.getCompanyTypeId();
|
|||
|
|
}
|
|||
|
|
if(companytype.getCompanyType().contains("施工单位")){
|
|||
|
|
laowutype = companytype.getCompanyTypeId();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
if (companyTypeId == -1){
|
|||
|
|
companyTypeId = laowutype;
|
|||
|
|
}
|
|||
|
|
JSONObject jsonparam1Object = new JSONObject();
|
|||
|
|
jsonparam1Object.put("socialCode",socialCode);
|
|||
|
|
jsonparam1Object.put("companyName",companyName);
|
|||
|
|
jsonparam1Object.put("companyLegalPerson",companyLegalPerson);
|
|||
|
|
String modCompany = getVnakeDataUtil(serverUrl+"/itbgp/api/modCompany",jsonparam1Object.toString(),key);
|
|||
|
|
logger.info("添加万科企业返回----"+modCompany);
|
|||
|
|
JSONObject jsonparamObject = new JSONObject();
|
|||
|
|
jsonparamObject.put("socialCode",socialCode);
|
|||
|
|
jsonparamObject.put("projectCode",projectCode);
|
|||
|
|
jsonparamObject.put("companyTypeId",companyTypeId);
|
|||
|
|
jsonparamObject.put("isBind","1");
|
|||
|
|
String bindCompany = getVnakeDataUtil(serverUrl+"/itbgp/api/bindCompany",jsonparamObject.toString(),key);
|
|||
|
|
logger.info("万科绑定企业返回----"+bindCompany);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 删除万科企业
|
|||
|
|
* @param socialCode 企业信用代码
|
|||
|
|
* @param projectCode 项目编码
|
|||
|
|
* @param companyTypeName 企业类型
|
|||
|
|
|
|||
|
|
*/
|
|||
|
|
public static void sendDeleteComapny(String socialCode,String projectCode,String companyTypeName,String serverUrl,String key){
|
|||
|
|
List<CompanyTypeBean> companyTypeLists = getVankeComapnyTypeList(serverUrl,key);
|
|||
|
|
int companyTypeId =-1,laowutype= -1;
|
|||
|
|
for (CompanyTypeBean companytype : companyTypeLists){
|
|||
|
|
if(companytype.getCompanyType().equals(companyTypeName)) {
|
|||
|
|
companyTypeId = companytype.getCompanyTypeId();
|
|||
|
|
}
|
|||
|
|
if(companytype.getCompanyType().contains("施工单位")){
|
|||
|
|
laowutype = companytype.getCompanyTypeId();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
if (companyTypeId == -1){
|
|||
|
|
companyTypeId = laowutype;
|
|||
|
|
}
|
|||
|
|
JSONObject jsonparamObject = new JSONObject();
|
|||
|
|
jsonparamObject.put("socialCode",socialCode);
|
|||
|
|
jsonparamObject.put("projectCode",projectCode);
|
|||
|
|
jsonparamObject.put("companyTypeId",companyTypeId);
|
|||
|
|
jsonparamObject.put("isBind","0");
|
|||
|
|
String bindCompany = getVnakeDataUtil(serverUrl+"/itbgp/api/bindCompany",jsonparamObject.toString(),key);
|
|||
|
|
logger.info("删除万科企业返回----"+bindCompany);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 添加万科班组
|
|||
|
|
* @param groupName 班组名称
|
|||
|
|
* @param projectCode 项目编码
|
|||
|
|
* @param socialCode 班组所属的劳务公司统一社会信用代码
|
|||
|
|
*/
|
|||
|
|
public static void sendAddGroup(String groupName,String newGroupName,String projectCode,String socialCode,String serverUrl,String key){
|
|||
|
|
JSONObject jsonparamObject = new JSONObject();
|
|||
|
|
jsonparamObject.put("groupName",groupName);
|
|||
|
|
if(StringUtils.isNotEmpty(newGroupName)){
|
|||
|
|
jsonparamObject.put("newGroupName",newGroupName);
|
|||
|
|
}
|
|||
|
|
jsonparamObject.put("projectCode",projectCode);
|
|||
|
|
jsonparamObject.put("socialCode",socialCode);
|
|||
|
|
String modGroup = getVnakeDataUtil(serverUrl+"/itbgp/api/modGroup",jsonparamObject.toString(),key);
|
|||
|
|
|
|||
|
|
logger.info("-----添加万科班组返回----"+modGroup);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 添加万科班组
|
|||
|
|
* @param groupName 班组名称
|
|||
|
|
* @param projectCode 项目编码
|
|||
|
|
*/
|
|||
|
|
public static void sendDeleteGroup(String groupName,String projectCode,String serverUrl,String key){
|
|||
|
|
JSONObject jsonparamObject = new JSONObject();
|
|||
|
|
jsonparamObject.put("groupName",groupName);
|
|||
|
|
jsonparamObject.put("projectCode",projectCode);
|
|||
|
|
String modGroup = getVnakeDataUtil(serverUrl+"/itbgp/api/delGroup",jsonparamObject.toString(),key);
|
|||
|
|
logger.info("删除万科班组返回----"+modGroup);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 获取万科工种
|
|||
|
|
* @param projectCode 项目编码
|
|||
|
|
*/
|
|||
|
|
private static void getVankeWorkType(String projectCode,String serverUrl,String key){
|
|||
|
|
List<WorkTypeBean> workTypeBeanList = new ArrayList<>();
|
|||
|
|
JSONObject jsonparamObject = new JSONObject();
|
|||
|
|
jsonparamObject.put("projectCode",projectCode);
|
|||
|
|
String getWorkerType = getVnakeDataUtil(serverUrl+"/itbgp/api/getWorkerType",jsonparamObject.toString(),key);
|
|||
|
|
JSONObject jsonObject = new JSONObject(getWorkerType);
|
|||
|
|
JSONArray jsonArray = (JSONArray) jsonObject.get("data");
|
|||
|
|
workTypeBeanList.clear();
|
|||
|
|
for (int i =0 ;i<jsonArray.size();i++){
|
|||
|
|
JSONObject copanytypebean = (JSONObject) jsonArray.get(i);
|
|||
|
|
WorkTypeBean workTypeBean = new WorkTypeBean();
|
|||
|
|
workTypeBean.setTypeId(Integer.parseInt(copanytypebean.get("typeId").toString()));
|
|||
|
|
workTypeBean.setTypeName(copanytypebean.get("typeName").toString());
|
|||
|
|
workTypeBeanList.add(workTypeBean);
|
|||
|
|
}
|
|||
|
|
logger.info("获取万科工种返回----"+getWorkerType);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 上传人员照片
|
|||
|
|
* @param imageurl 照片URL
|
|||
|
|
* @param type 类型 1:人脸照片 2:抓拍照片
|
|||
|
|
*/
|
|||
|
|
private static String sendVankePhoto(String imageurl,String type,String serverUrl,String key){
|
|||
|
|
String url = "";
|
|||
|
|
try {
|
|||
|
|
JSONObject jsonparamObject = new JSONObject();
|
|||
|
|
jsonparamObject.put("type",type);
|
|||
|
|
jsonparamObject.put("imgData",Base64Util.getFileToBase64(imageurl));
|
|||
|
|
String comapnyTypeList = getVnakeDataUtil(serverUrl+"/itbgp/api/uploadImg",jsonparamObject.toString(),key);
|
|||
|
|
JSONObject jsonObject = new JSONObject(comapnyTypeList);
|
|||
|
|
url = jsonObject.get("url").toString();
|
|||
|
|
logger.info("上传照片返回----"+url);
|
|||
|
|
}catch (Exception e){
|
|||
|
|
e.printStackTrace();
|
|||
|
|
}
|
|||
|
|
return url;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 新增人员信息
|
|||
|
|
*/
|
|||
|
|
public static String sentAddPerson(PersonBean personBean ,String serverUrl,String key){
|
|||
|
|
String result=null;
|
|||
|
|
try {
|
|||
|
|
personBean.setPhotoUrl(sendVankePhoto(personBean.getPhotoUrl(),"1",serverUrl,key));
|
|||
|
|
personBean.setIdCardUpPhotoUrl(sendVankePhoto(personBean.getIdCardUpPhotoUrl(),"1",serverUrl,key));
|
|||
|
|
personBean.setIdCardDownPhotoUrl(sendVankePhoto(personBean.getIdCardDownPhotoUrl(),"1",serverUrl,key));
|
|||
|
|
personBean.setIdCardBigPhotoUrl(sendVankePhoto(personBean.getIdCardBigPhotoUrl(),"1",serverUrl,key));
|
|||
|
|
String str = JSONUtil.toJsonStr(personBean);
|
|||
|
|
String modWorker = getVnakeDataUtil(serverUrl+"/itbgp/api/modWorker",str,key);
|
|||
|
|
logger.info("----万科人员添加--"+personBean.getName()+"--"+personBean.getIdCard()+"--返回----"+modWorker);
|
|||
|
|
JSONObject jsonparamObject = new JSONObject();
|
|||
|
|
jsonparamObject.put("idCards",personBean.getIdCard());
|
|||
|
|
jsonparamObject.put("projectCode",personBean.getProjectCode());
|
|||
|
|
result = getVnakeDataUtil(serverUrl+"/itbgp/api/addRealName",jsonparamObject.toString(),key);
|
|||
|
|
logger.info("----万科人员实名认证--"+personBean.getName()+"--"+personBean.getIdCard()+"--返回----"+result);
|
|||
|
|
|
|||
|
|
}catch (Exception e){
|
|||
|
|
e.printStackTrace();
|
|||
|
|
}
|
|||
|
|
return result;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 删除人员信息
|
|||
|
|
* @param idCard 身份证号
|
|||
|
|
* @param projectCode 项目编码
|
|||
|
|
* @return
|
|||
|
|
*/
|
|||
|
|
public static String sentDeletePerson(String idCard,String projectCode ,String serverUrl,String key){
|
|||
|
|
String delWorker=null;
|
|||
|
|
try {
|
|||
|
|
JSONObject jsonparamObject = new JSONObject();
|
|||
|
|
jsonparamObject.put("idCard",idCard);
|
|||
|
|
jsonparamObject.put("projectCode",projectCode);
|
|||
|
|
delWorker = getVnakeDataUtil(serverUrl+"/itbgp/api/delWorker",jsonparamObject.toString(),key);
|
|||
|
|
logger.info("----万科人员删除返回----"+delWorker);
|
|||
|
|
}catch (Exception e){
|
|||
|
|
e.printStackTrace();
|
|||
|
|
}
|
|||
|
|
return delWorker;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 添加人脸识别设备
|
|||
|
|
* @param devCode 设备SN
|
|||
|
|
* @param devName 设备名称
|
|||
|
|
* @param direction 设备通行方向 1:进 2 出
|
|||
|
|
* @param projectCode 项目编码
|
|||
|
|
* @return
|
|||
|
|
*/
|
|||
|
|
public static void sentAddPassDev(String devCode,String devName,String direction,String projectCode ,String serverUrl,String key){
|
|||
|
|
try {
|
|||
|
|
JSONObject jsonparamObject = new JSONObject();
|
|||
|
|
jsonparamObject.put("devCode",devCode);
|
|||
|
|
jsonparamObject.put("devName",devName);
|
|||
|
|
jsonparamObject.put("direction",direction);
|
|||
|
|
jsonparamObject.put("projectCode",projectCode);
|
|||
|
|
jsonparamObject.put("isOnline",1);
|
|||
|
|
String uploadPassDev = getVnakeDataUtil(serverUrl+"/itbgp/api/uploadPassDev",jsonparamObject.toString(),key);
|
|||
|
|
logger.info("-----添加万科平台通行设备返回------"+uploadPassDev);
|
|||
|
|
}catch (Exception e){
|
|||
|
|
e.printStackTrace();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 添加安全培训
|
|||
|
|
* @param idCards 设备SN
|
|||
|
|
* @param projectCode 项目编码
|
|||
|
|
* @param eduCoursename 课程名称
|
|||
|
|
* @param eduType 1 入场安全教育
|
|||
|
|
* @return
|
|||
|
|
*/
|
|||
|
|
public static void sentAddSafeEducation(String idCards,String projectCode,String eduCoursename,String eduType ,String serverUrl,String key){
|
|||
|
|
try {
|
|||
|
|
JSONObject jsonparamObject = new JSONObject();
|
|||
|
|
jsonparamObject.put("idCards",idCards);
|
|||
|
|
jsonparamObject.put("projectCode",projectCode);
|
|||
|
|
jsonparamObject.put("eduCoursename",eduCoursename);
|
|||
|
|
jsonparamObject.put("eduType",eduType);
|
|||
|
|
String uploadPassDev = getVnakeDataUtil(serverUrl+"/itbgp/api/modSafeEducation",jsonparamObject.toString(),key);
|
|||
|
|
logger.info("-----添加万科安全培训----"+uploadPassDev);
|
|||
|
|
}catch (Exception e){
|
|||
|
|
e.printStackTrace();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 添加通行记录
|
|||
|
|
* @param devCode 设备SN
|
|||
|
|
* @param passType 通行方式 1 IC卡 2 人脸识别 3 指纹识别 5 二维码 6 蓝牙
|
|||
|
|
* @param direction 通行方向 1:进 2 出
|
|||
|
|
* @param projectCode 项目编码
|
|||
|
|
* @param passTime 通行时间 格式:2019-06-06 09:53:12
|
|||
|
|
* @param idCard 人员身份证号码
|
|||
|
|
* @return
|
|||
|
|
*/
|
|||
|
|
public static String sentAddPassRecord(String devCode,String passType,String direction,String projectCode,String passTime,String idCard ,String serverUrl,String key){
|
|||
|
|
String uploadPassDev=null;
|
|||
|
|
try {
|
|||
|
|
JSONObject jsonparamObject = new JSONObject();
|
|||
|
|
jsonparamObject.put("idCard",idCard);
|
|||
|
|
jsonparamObject.put("projectCode",projectCode);
|
|||
|
|
jsonparamObject.put("passTime",passTime);
|
|||
|
|
jsonparamObject.put("direction",direction);
|
|||
|
|
jsonparamObject.put("passType",passType);
|
|||
|
|
jsonparamObject.put("devCode",devCode);
|
|||
|
|
uploadPassDev = getVnakeDataUtil(serverUrl+"/itbgp/api/passRecord",jsonparamObject.toString(),key);
|
|||
|
|
logger.info("-----项目编号:"+projectCode+"-----idCard:"+idCard+"---添加万科平台通行记录返回"+uploadPassDev);
|
|||
|
|
}catch (Exception e){
|
|||
|
|
e.printStackTrace();
|
|||
|
|
}
|
|||
|
|
return uploadPassDev;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
public static void main(String[] args) {
|
|||
|
|
|
|||
|
|
//添加企业
|
|||
|
|
getVankeComapnyTypeList("http://stg-gongdi.vanrui.com","866aa746b11f42b887ba51babbb2aa7b");
|
|||
|
|
//sendAddComapny("91330783147520019P","20223137296","建设单位","中天建设集团有限公司","未知");
|
|||
|
|
//添加班组
|
|||
|
|
// addvankegroup("测试班组","20194184386","91440300MA5DF14Q0W");
|
|||
|
|
//获取工种
|
|||
|
|
// getvankeworktype("20194184386");
|
|||
|
|
//上传照片
|
|||
|
|
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
}
|