post转发ssl认证去除

This commit is contained in:
lvleigang 2025-02-21 10:43:40 +08:00
parent 7ce0985852
commit 5d3ab059c6
7 changed files with 603 additions and 9 deletions

View File

@ -23,7 +23,7 @@ import java.util.Date;
import java.util.List;
/**
* 业务数据同步
* 未定合同号
*
* @author makejava
* @since 2024-06-21 13:52:35

View File

@ -1,8 +1,11 @@
package com.hzya.frame.plugin.businessData.dao;
import com.alibaba.fastjson.JSONObject;
import com.hzya.frame.basedao.dao.IBaseDao;
import com.hzya.frame.plugin.businessData.entity.BusinessEntity;
import java.util.List;
/**
* 客户档案(mdm_customer: table)表数据库访问层
*
@ -11,5 +14,10 @@ import com.hzya.frame.plugin.businessData.entity.BusinessEntity;
*/
public interface IBusinessDao extends IBaseDao<BusinessEntity, String> {
List<JSONObject> queryData(JSONObject saveData);
int saveData(JSONObject saveData);
int saveDetailData(JSONObject saveDetailData);
}

View File

@ -1,9 +1,12 @@
package com.hzya.frame.plugin.businessData.dao.impl;
import com.alibaba.fastjson.JSONObject;
import com.hzya.frame.basedao.dao.MybatisGenericDao;
import com.hzya.frame.plugin.businessData.dao.IBusinessDao;
import com.hzya.frame.plugin.businessData.entity.BusinessEntity;
import java.util.List;
/**
*
* @author makejava
@ -11,5 +14,19 @@ import com.hzya.frame.plugin.businessData.entity.BusinessEntity;
*/
public class BusinessDaoImpl extends MybatisGenericDao<BusinessEntity, String> implements IBusinessDao {
@Override
public List<JSONObject> queryData(JSONObject saveData) {
List<JSONObject> o = (List<JSONObject>) super.selectList(getSqlIdPrifx() + "queryData", saveData);
return o;
}
@Override
public int saveData(JSONObject saveData) {
return super.insert(getSqlIdPrifx() + "saveData", saveData);
}
@Override
public int saveDetailData(JSONObject saveData) {
return super.insert(getSqlIdPrifx() + "saveDetailData", saveData);
}
}

View File

@ -2,6 +2,133 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hzya.frame.plugin.businessData.dao.impl.BusinessDaoImpl">
<select id="queryData" resultType="com.alibaba.fastjson.JSONObject" parameterType="com.alibaba.fastjson.JSONObject">
select
*
from mdm_ccd
<trim prefix="where" prefixOverrides="and">
<if test="field0011 != null and field0011 != ''"> and field0011 = #{field0011} </if>
and sts = 'Y' and data_status != 'N'
</trim>
</select>
<insert id="saveData" parameterType="com.alibaba.fastjson.JSONObject">
insert into mdm_ccd(
<trim suffix="" suffixOverrides=",">
<if test="id != null and id != ''"> id , </if>
<if test="document_rule != null and document_rule != ''"> document_rule , </if>
<if test="document_rule_num != null"> document_rule_num , </if>
<if test="data_status != null and data_status != ''"> data_status , </if>
<if test="add_status != null and add_status != ''"> add_status , </if>
<if test="update_status != null and update_status != ''"> update_status , </if>
<if test="delete_status != null and delete_status != ''"> delete_status , </if>
<if test="sorts != null"> sorts , </if>
<if test="create_user_id != null and create_user_id != ''"> create_user_id , </if>
<if test="create_time != null"> create_time , </if>
<if test="modify_user_id != null and modify_user_id != ''"> modify_user_id , </if>
<if test="modify_time != null"> modify_time , </if>
<if test="sts != null and sts != ''"> sts , </if>
<if test="org_id != null and org_id != ''"> org_id , </if>
<if test="companyId != null and companyId != ''"> company_id , </if>
<if test="field0011 != null and field0011 != ''"> field0011 , </if>
<if test="field0001 != null and field0001 != ''"> field0001 , </if>
<if test="field0002 != null and field0002 != ''"> field0002 , </if>
<if test="field0012 != null and field0012 != ''"> field0012 , </if>
<if test="field0013 != null and field0013 != ''"> field0013 , </if>
<if test="field0014 != null and field0014 != ''"> field0014 , </if>
<if test="field0003 != null and field0003 != ''"> field0003 , </if>
<if test="field0015 != null and field0015 != ''"> field0015 , </if>
<if test="field0016 != null and field0016 != ''"> field0016 , </if>
<if test="field0017 != null and field0017 != ''"> field0017 , </if>
<if test="field0018 != null and field0018 != ''"> field0018 , </if>
<if test="field0019 != null and field0019 != ''"> field0019 , </if>
<if test="field0020 != null and field0020 != ''"> field0020 , </if>
<if test="field0021 != null and field0021 != ''"> field0021 , </if>
</trim>
)values
(
<trim suffix="" suffixOverrides=",">
<if test="id != null and id != ''"> #{id} , </if>
<if test="document_rule != null and document_rule != ''"> #{document_rule} , </if>
<if test="document_rule_num != null"> #{document_rule_num} , </if>
<if test="data_status != null and data_status != ''"> #{data_status} , </if>
<if test="add_status != null and add_status != ''"> #{add_status} , </if>
<if test="update_status != null and update_status != ''"> #{update_status} , </if>
<if test="delete_status != null and delete_status != ''"> #{delete_status} , </if>
<if test="sorts != null"> #{sorts} , </if>
<if test="create_user_id != null and create_user_id != ''"> #{create_user_id} , </if>
<if test="create_time != null"> #{create_time} , </if>
<if test="modify_user_id != null and modify_user_id != ''"> #{modify_user_id} , </if>
<if test="modify_time != null"> #{modify_time} , </if>
<if test="sts != null and sts != ''"> #{sts} , </if>
<if test="org_id != null and org_id != ''"> #{org_id} , </if>
<if test="companyId != null and companyId != ''"> #{company_id} , </if>
<if test="field0011 != null and field0011 != ''"> #{field0011} , </if>
<if test="field0001 != null and field0001 != ''"> #{field0001} , </if>
<if test="field0002 != null and field0002 != ''"> #{field0002} , </if>
<if test="field0012 != null and field0012 != ''"> #{field0012} , </if>
<if test="field0013 != null and field0013 != ''"> #{field0013} , </if>
<if test="field0014 != null and field0014 != ''"> #{field0014} , </if>
<if test="field0003 != null and field0003 != ''"> #{field0003} , </if>
<if test="field0015 != null and field0015 != ''"> #{field0015} , </if>
<if test="field0016 != null and field0016 != ''"> #{field0016} , </if>
<if test="field0017 != null and field0017 != ''"> #{field0017} , </if>
<if test="field0018 != null and field0018 != ''"> #{field0018} , </if>
<if test="field0019 != null and field0019 != ''"> #{field0019} , </if>
<if test="field0020 != null and field0020 != ''"> #{field0020} , </if>
<if test="field0021 != null and field0021 != ''"> #{field0021} , </if>
</trim>
)
</insert>
<insert id="saveDetailData" parameterType="com.alibaba.fastjson.JSONObject">
insert into mdm_ccd_detail(
<trim suffix="" suffixOverrides=",">
<if test="id != null and id != ''"> id , </if>
<if test="formmain_id != null and formmain_id != ''"> formmain_id , </if>
<if test="data_status != null and data_status != ''"> data_status , </if>
<if test="sorts != null"> sorts , </if>
<if test="create_user_id != null and create_user_id != ''"> create_user_id , </if>
<if test="create_time != null"> create_time , </if>
<if test="modify_user_id != null and modify_user_id != ''"> modify_user_id , </if>
<if test="modify_time != null"> modify_time , </if>
<if test="sts != null and sts != ''"> sts , </if>
<if test="org_id != null and org_id != ''"> org_id , </if>
<if test="companyId != null and companyId != ''"> company_id , </if>
<if test="field0004 != null and field0004 != ''"> field0004 , </if>
<if test="field0005 != null and field0005 != ''"> field0005 , </if>
<if test="field0022 != null and field0022 != ''"> field0022 , </if>
<if test="field0008 != null and field0008 != ''"> field0008 , </if>
<if test="field0006 != null and field0006 != ''"> field0006 , </if>
<if test="field0007 != null and field0007 != ''"> field0007 , </if>
<if test="field0009 != null and field0009 != ''"> field0009 , </if>
</trim>
)values
(
<trim suffix="" suffixOverrides=",">
<if test="id != null and id != ''"> #{id} , </if>
<if test="formmain_id != null and formmain_id != ''"> #{formmain_id} , </if>
<if test="data_status != null and data_status != ''"> #{data_status}, </if>
<if test="sorts != null"> #{sorts} , </if>
<if test="create_user_id != null and create_user_id != ''"> #{create_user_id} , </if>
<if test="create_time != null"> #{create_time} , </if>
<if test="modify_user_id != null and modify_user_id != ''"> #{modify_user_id} , </if>
<if test="modify_time != null"> #{modify_time} , </if>
<if test="sts != null and sts != ''"> #{sts} , </if>
<if test="org_id != null and org_id != ''"> #{org_id} , </if>
<if test="companyId != null and companyId != ''"> #{company_id} , </if>
<if test="field0004 != null and field0004 != ''"> #{field0004} , </if>
<if test="field0005 != null and field0005 != ''"> #{field0005} , </if>
<if test="field0022 != null and field0022 != ''"> #{field0022} , </if>
<if test="field0008 != null and field0008 != ''"> #{field0008} , </if>
<if test="field0006 != null and field0006 != ''"> #{field0006} , </if>
<if test="field0007 != null and field0007 != ''"> #{field0007} , </if>
<if test="field0009 != null and field0009 != ''"> #{field0009} , </if>
</trim>
)
</insert>
</mapper>

View File

@ -2,9 +2,11 @@ package com.hzya.frame.plugin.businessData.plugin;
import com.alibaba.fastjson.JSONObject;
import com.hzya.frame.base.PluginBaseEntity;
import com.hzya.frame.plugin.businessData.service.IBusinessService;
import com.hzya.frame.web.entity.JsonResultEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
/**
* 主数据同步
@ -15,6 +17,8 @@ import org.slf4j.LoggerFactory;
public class BusinessPluginInitializer extends PluginBaseEntity{
Logger logger = LoggerFactory.getLogger(BusinessPluginInitializer.class);
@Autowired
private IBusinessService businessService;
@Override
public void initialize() {
@ -49,7 +53,7 @@ public class BusinessPluginInitializer extends PluginBaseEntity{
public JsonResultEntity executeBusiness(JSONObject requestJson) {
try {
logger.info("======开始执行主数据信息同步========");
return null;
return businessService.getBusinessData(requestJson);
}catch (Exception e){
logger.info("======执行主数据同步失败:{}========",e.getMessage());
e.printStackTrace();

View File

@ -1,7 +1,10 @@
package com.hzya.frame.plugin.businessData.service;
import com.alibaba.fastjson.JSONObject;
import com.hzya.frame.basedao.service.IBaseService;
import com.hzya.frame.plugin.businessData.entity.BusinessEntity;
import com.hzya.frame.sysnew.application.entity.SysExtensionApiEntity;
import com.hzya.frame.web.entity.JsonResultEntity;
/**
*
@ -9,4 +12,6 @@ import com.hzya.frame.plugin.businessData.entity.BusinessEntity;
* @since 2024-06-21 13:52:35
*/
public interface IBusinessService extends IBaseService<BusinessEntity, String> {
JsonResultEntity getBusinessData(JSONObject requestJson);
SysExtensionApiEntity setData(SysExtensionApiEntity entity) throws Exception;
}

View File

@ -1,10 +1,48 @@
package com.hzya.frame.plugin.businessData.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hzya.frame.plugin.businessData.dao.IBusinessDao;
import com.hzya.frame.plugin.businessData.entity.BusinessEntity;
import com.hzya.frame.plugin.businessData.service.IBusinessService;
import com.hzya.frame.sysnew.application.database.entity.SysApplicationDatabaseEntity;
import com.hzya.frame.sysnew.application.entity.SysApplicationEntity;
import com.hzya.frame.sysnew.application.entity.SysExtensionApiEntity;
import com.hzya.frame.sysnew.comparison.controlsLog.dao.impl.ControlsLogDaoImpl;
import com.hzya.frame.sysnew.comparison.controlsLog.entity.ControlsLogEntity;
import com.hzya.frame.sysnew.comparison.dao.IComparisonDao;
import com.hzya.frame.sysnew.comparison.entity.ComparisonEntity;
import com.hzya.frame.uuid.UUIDLong;
import com.hzya.frame.uuid.UUIDUtils;
import com.hzya.frame.web.entity.BaseResult;
import com.hzya.frame.web.entity.JsonResultEntity;
import org.apache.http.HttpEntity;
import org.apache.http.client.config.RequestConfig;
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.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.TrustAllStrategy;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.http.util.EntityUtils;
import org.checkerframework.checker.units.qual.C;
import org.springframework.beans.factory.annotation.Autowired;
import com.hzya.frame.basedao.service.impl.BaseService;
import javax.net.ssl.SSLContext;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author makejava
* @since 2024-06-21 13:52:35
@ -12,10 +50,405 @@ import com.hzya.frame.basedao.service.impl.BaseService;
public class BusinessServiceImpl extends BaseService<BusinessEntity, String> implements IBusinessService {
private IBusinessDao businessDao;
@Autowired
private ControlsLogDaoImpl controlsLogDaoimpl;
@Autowired
private IComparisonDao comparisonDao;
@Autowired
public void setBusinessCustomerDao(IBusinessDao dao) {
this.businessDao = dao;
this.dao = dao;
}
@Override
public JsonResultEntity getBusinessData(JSONObject requestJson) {
//1调用token
String access_token = getToken();
if (access_token == null) {
return BaseResult.getFailureMessageEntity("token获取失败");
}
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String times = sdf.format(date);
times = "2025-02-08";//todo
//2调用接口获取数据
String queryCursor = null;
String startDate = times+" 00:00:00";
String endDate = times+" 23:59:59";
JSONArray datalist = new JSONArray();
sendBusinessData(datalist, access_token, queryCursor, startDate, endDate);
if(datalist != null && datalist.size() > 0){
for (int i = 0; i < datalist.size(); i++) {
JSONObject saveData = new JSONObject();
//3对照数据
JSONObject jsonObject = datalist.getJSONObject(i);
//field0011 申请单号
String field0011 = jsonObject.getString("serialNumber");
if(field0011 == null || "".equals(field0011) ){
continue;
}
saveData.put("field0011",field0011);
//判断是否有这个数据
List<JSONObject> checkData = businessDao.queryData(saveData);
if(checkData != null && checkData.size() > 0){
continue;
}
saveData.put("id", String.valueOf(UUIDLong.longUUID()));
saveData.put("create_user_id", "c796fd9ba4c9f5ff3cc2fa41a040e443");
saveData.put("modify_user_id", "c796fd9ba4c9f5ff3cc2fa41a040e443");
saveData.put("org_id", "0");
saveData.put("create_time", new Date());
saveData.put("modify_time", new Date());
saveData.put("sts", "Y");
saveData.put("data_status", "Y");//新增状态
saveData.put("add_status", "0");//新增状态
saveData.put("update_status", "1");//修改状态
saveData.put("delete_status", "1");//删除状态
ComparisonEntity comparisonEntityRule = new ComparisonEntity();
comparisonEntityRule.setRulePrefix("CCD");
comparisonEntityRule.setRuleMiddle("%Y-%m-%d");
comparisonEntityRule.setRuleSuffix(5);
comparisonEntityRule.setDbName("mdm_ccd");
ComparisonEntity comparisonEntityRuleGz = comparisonDao.queryComparisonRule(comparisonEntityRule);
saveData.put("document_rule", comparisonEntityRuleGz.getDocumentRule());//单据规则
saveData.put("document_rule_num", comparisonEntityRuleGz.getDocumentRuleNum());//单据规则流水号
saveData.put("field0001",jsonObject.getString("applyUser"));//申请人
saveData.put("field0002",jsonObject.getString("jobNumber"));//申请人工号
String oaToken = getOAToken("");
JSONObject user = getUser(jsonObject.getString("jobNumber"),oaToken);
saveData.put("field0012",user.getString("orgPostName"));
saveData.put("field0013",user.getString("orgDepartmentName"));
saveData.put("field0014",user.getString("telNumber"));
saveData.put("field0003",jsonObject.getString("startDateTime"));// 出差时间
saveData.put("field0015",jsonObject.getString("documentType"));
saveData.put("field0017",jsonObject.getString("dayValOfDuration"));// 出差时长()
saveData.put("field0018",jsonObject.getString("extshifouzhanhuichucha_109372_807255447"));// todo 是否境外出差
saveData.put("field0019",jsonObject.getString("extshifouxuyaoapecka_109372_294746269"));// todo 是否需要APEC卡
saveData.put("field0020",jsonObject.getString("extshifoujingwaichucha_109372_295886206"));// todo 是否展会出差
saveData.put("field0021",jsonObject.getString("reason"));// 出差事由
JSONArray detaildata = jsonObject.getJSONArray("businessDetailsSync");
if(detaildata != null && detaildata.size() > 0){
for (int i1 = 0; i1 < detaildata.size(); i1++) {
JSONObject saveDetailData = new JSONObject();
saveDetailData.put("field0004",detaildata.getJSONObject(i1).getString("startDateTime"));//明细表-出发时间
saveDetailData.put("field0005",detaildata.getJSONObject(i1).getString("stopDateTime"));//明细表-结束时间
saveDetailData.put("field0022",detaildata.getJSONObject(i1).getString("businessDuration"));//明细表-出差时长
if(detaildata.getJSONObject(i1).getString("businessVehicle") != null){// 明细表-交通工具
if("0".equals(detaildata.getJSONObject(i1).getString("businessVehicle"))){
saveDetailData.put("field0008","飞机");
}
if("1".equals(detaildata.getJSONObject(i1).getString("businessVehicle"))){
saveDetailData.put("field0008","火车");
}
if("2".equals(detaildata.getJSONObject(i1).getString("businessVehicle"))){
saveDetailData.put("field0008","汽车");
}
if("3".equals(detaildata.getJSONObject(i1).getString("businessVehicle"))){
saveDetailData.put("field0008","轮船");
}
}
saveDetailData.put("field0006",detaildata.getJSONObject(i1).getString("departurePlace"));//明细表-出发地
saveDetailData.put("field0007",detaildata.getJSONObject(i1).getString("destination"));//明细表-目的地
saveDetailData.put("field0009",detaildata.getJSONObject(i1).getString("expectedCost"));//明细表-预计费用
saveData.put("field0016",detaildata.getJSONObject(i1).getString("destination"));// 出差城市
saveDetailData.put("id", String.valueOf(UUIDLong.longUUID()));
saveDetailData.put("formmain_id", saveData.getString("id"));
saveDetailData.put("data_status", "Y");//新增状态
saveDetailData.put("create_user_id", "c796fd9ba4c9f5ff3cc2fa41a040e443");
saveDetailData.put("modify_user_id", "c796fd9ba4c9f5ff3cc2fa41a040e443");
saveDetailData.put("org_id", "0");
saveDetailData.put("create_time", new Date());
saveDetailData.put("modify_time", new Date());
saveDetailData.put("sts", "Y");
businessDao.saveDetailData(saveDetailData);
}
}
businessDao.saveData(saveData);
//5保存写入日志
ControlsLogEntity controlsLogEntity=new ControlsLogEntity();
controlsLogEntity.setId(UUIDUtils.getUUID());
controlsLogEntity.setFormmainId(saveData.getString("id"));
controlsLogEntity.setSourceName("数智中台");
controlsLogEntity.setCode("800004");
controlsLogEntity.setSourceData(jsonObject.toString());
controlsLogEntity.setOptionType("接口新增");
controlsLogEntity.setOptionName("数智中台");
controlsLogEntity.setDbName("mdm_ccd_option_log");
controlsLogEntity.setDataType("1");
controlsLogEntity.setCreate_user_id("c796fd9ba4c9f5ff3cc2fa41a040e443");
controlsLogEntity.setModify_user_id("c796fd9ba4c9f5ff3cc2fa41a040e443");
controlsLogEntity.setOrg_id("0");
controlsLogEntity.setRemark("插件新增");
controlsLogDaoimpl.saveControlsLog(saveData.getString("id"), "数智中台", "800004", jsonObject.toJSONString(), "接口新增", "数智中台", "mdm_ccd_option_log", "1","插件新增");
}
}
return BaseResult.getSuccessMessageEntity("处理成功");
}
private void sendBusinessData(JSONArray datalist, String access_token, String queryCursor, String startDate, String endDate) {
String url = "https://openapi.italent.cn/AttendanceOpen/api/v1/Business/GetApprovalCompletedBusinessListByDate";
Map<String, String> headers = new HashMap<>();
headers.put("Authorization", "Bearer " + access_token);
JSONObject jsonObject = new JSONObject();
jsonObject.put("startDate", startDate);
jsonObject.put("endDate", endDate);
jsonObject.put("pageSize", 100);
if (queryCursor != null) {
jsonObject.put("queryCursor", queryCursor);
}
String returndata = sendPost(url, headers, jsonObject.toString());
if (returndata != null && JSONObject.isValidObject(returndata)) {
JSONObject dataJson = JSONObject.parseObject(returndata);
if(dataJson != null && dataJson.getString("code") != null && "200".equals( dataJson.getString("code"))){
JSONObject data = dataJson.getJSONObject("data");
if(data != null ){
JSONArray businessList = data.getJSONArray("businessList");
if(!data.getBoolean("isLastPage")){
queryCursor = data.getString("sortCursor");
sendBusinessData(datalist, access_token, queryCursor, startDate, endDate);
}
if(businessList != null && businessList.size() > 0){
datalist.addAll(businessList);
}
}
}
}
}
private JSONObject getUser(String usercode,String access_token) {
JSONObject jsonObject = new JSONObject();
String url = "https://swoa.sunwave.com.cn:9999/seeyon/rest/orgMembers/code/"+usercode+"?pageNo=0&pageSize=100";
Map<String, String> headers = new HashMap<>();
headers.put("token",access_token);
String returndata = sendGet(url, headers);
if (returndata != null && JSONArray.isValidArray(returndata)) {
JSONArray dataJson = JSONObject.parseArray(returndata);
if(dataJson != null && dataJson.size() > 0){
for (int i = 0; i < dataJson.size(); i++) {
if(dataJson.getJSONObject(i).getString("code") != null && !"".equals(dataJson.getJSONObject(i).getString("code"))
&& usercode.toLowerCase().equals(dataJson.getJSONObject(i).getString("code").toLowerCase())){
jsonObject.put("telNumber",dataJson.getJSONObject(i).getString("telNumber"));
jsonObject.put("orgDepartmentName",dataJson.getJSONObject(i).getString("orgDepartmentName"));
jsonObject.put("orgPostName",dataJson.getJSONObject(i).getString("orgPostName"));
break;
}
}
}
}
return jsonObject;
}
private String getOAToken(String name) {
String url = "https://swoa.sunwave.com.cn:9999/seeyon/rest/token";
Map<String, String> headers = null;
String bodys = "{\"password\":\"64de4de7-23ce-4946-ac91-dd9e322d86e5\",\"userName\":\"beis\",\"loginName\":\""+name+"\"}";
String tokenData = sendPost(url, headers, bodys);
String access_token = null;
if (tokenData != null && JSONObject.isValidObject(tokenData)) {
JSONObject tokendataJson = JSONObject.parseObject(tokenData);
if (tokendataJson != null && tokendataJson.getString("id") != null) {
access_token = tokendataJson.getString("id");
}
}
return access_token;
}
private String getToken() {
String url = "https://openapi.italent.cn/token";
Map<String, String> headers = null;
String bodys = "{\"grant_type\":\"client_credentials\",\"app_key\":\"1CBEBF66FABD4A25A94DF8BB7B0074E7\",\"app_secret\":\"AEFCFCE92804440E89682A3B9FA9BBB8774DDF4FB812428AB7EC340C54CC472B\"}";
String tokenData = sendPost(url, headers, bodys);
String access_token = null;
if (tokenData != null && JSONObject.isValidObject(tokenData)) {
JSONObject tokendataJson = JSONObject.parseObject(tokenData);
if (tokendataJson != null && tokendataJson.getString("access_token") != null) {
access_token = tokendataJson.getString("access_token");
}
}
return access_token;
}
private String sendPost(String url, Map<String, String> headers, String bodys) {
SSLContext sslContext = null;
try {
sslContext = new SSLContextBuilder()
.loadTrustMaterial(null, TrustAllStrategy.INSTANCE)
.build();
} catch (Exception e) {
}
CloseableHttpClient closeableHttpClient = HttpClients.custom()
.setSSLContext(sslContext)
.setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE)
.build();
HttpPost post = new HttpPost(url);
CloseableHttpResponse response = null;
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(60000).build();
post.setConfig(requestConfig);//设置请求参数超时时间
if (headers != null && headers.size() > 0) {
for (String key : headers.keySet()) {
post.setHeader(key, headers.get(key));
}
}
StringBuilder body = new StringBuilder();
try {
if (bodys != null && !"".equals(bodys)) {
ByteArrayEntity entity = new ByteArrayEntity(bodys.getBytes("UTF-8"));
entity.setContentType("application/json");
post.setEntity(entity);
}
response = closeableHttpClient.execute(post);
HttpEntity entity = response.getEntity();
body.append(EntityUtils.toString(entity, "UTF-8"));
logger.info("返回结果:" + body);
} catch (Exception e) {
logger.error("请求错误:" + e.getMessage());
body = new StringBuilder();
} finally {
try {
// 关闭响应对象
if (response != null) {
response.close();
}
// 关闭响应对象
if (closeableHttpClient != null) {
closeableHttpClient.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return body.toString();
}
private String sendGet(String url, Map<String, String> headers) {
SSLContext sslContext = null;
try {
sslContext = new SSLContextBuilder()
.loadTrustMaterial(null, TrustAllStrategy.INSTANCE)
.build();
} catch (Exception e) {
}
CloseableHttpClient closeableHttpClient = HttpClients.custom()
.setSSLContext(sslContext)
.setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE)
.build();
// HttpClient
HttpGet get = new HttpGet(url);
CloseableHttpResponse response = null;
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(60000).build();
get.setConfig(requestConfig);//设置请求参数超时时间
if (headers != null && headers.size() > 0) {
for (String key : headers.keySet()) {
get.setHeader(key, headers.get(key));
}
}
StringBuilder body = new StringBuilder();
try {
response = closeableHttpClient.execute(get);
HttpEntity entity = response.getEntity();
body.append(EntityUtils.toString(entity,"UTF-8"));
logger.info("返回结果:" + body);
} catch (Exception e) {
logger.error("请求错误:" + e.getMessage());
body.append(e.getMessage());
} finally {
try {
// 关闭响应对象
if (response != null) {
response.close();
}
// 关闭响应对象
if (closeableHttpClient != null) {
closeableHttpClient.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return body.toString();
}
/**
* seeyon流程事件监听前置方法绑定数据源
* @param entity
* @return
* @throws Exception
*/
@Override
public SysExtensionApiEntity setData(SysExtensionApiEntity entity) throws Exception {
try {
JSONObject sendBody = new JSONObject();
String bodys = entity.getBodys();
Map<String, String> headers = entity.getHeaders();
JSONObject jsonObject = JSONObject.parseObject(bodys);
String loginName = jsonObject.getString("field0002");
String dataXml = getXml(jsonObject);
//处理xml数据
String oaToken = getOAToken(loginName);
headers.put("token",oaToken);
sendBody.put("token",oaToken);
sendBody.put("loginName",loginName);
sendBody.put("dataXml",dataXml);
entity.setBodys(sendBody.toJSONString());
} catch (Exception e) {
e.printStackTrace();
}
return entity;
}
private String getXml(JSONObject jsonObject) {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("<forms version=\\\"2.1\\\"><formExport><summary id=\\\"-3743349685075685398\\\" name=\\\"formmain_11769\\\"/><definitions><column id=\\\"field0011\\\" type=\\\"0\\\" name=\\\"申请单号\\\" isNullable=\\\"false\\\" length=\\\"100\\\"/><column id=\\\"field0001\\\" type=\\\"0\\\" name=\\\"申请人\\\" isNullable=\\\"false\\\" length=\\\"255\\\"/><column id=\\\"field0002\\\" type=\\\"0\\\" name=\\\"申请人工号\\\" isNullable=\\\"false\\\" length=\\\"255\\\"/><column id=\\\"field0012\\\" type=\\\"0\\\" name=\\\"申请人职位\\\" isNullable=\\\"false\\\" length=\\\"255\\\"/><column id=\\\"field0013\\\" type=\\\"0\\\" name=\\\"申请人部门\\\" isNullable=\\\"false\\\" length=\\\"255\\\"/><column id=\\\"field0014\\\" type=\\\"0\\\" name=\\\"申请人手机号\\\" isNullable=\\\"false\\\" length=\\\"255\\\"/><column id=\\\"field0003\\\" type=\\\"3\\\" name=\\\"出差时间\\\" isNullable=\\\"false\\\" length=\\\"255\\\"/><column id=\\\"field0015\\\" type=\\\"0\\\" name=\\\"出差类型\\\" isNullable=\\\"false\\\" length=\\\"255\\\"/><column id=\\\"field0016\\\" type=\\\"0\\\" name=\\\"出差城市\\\" isNullable=\\\"false\\\" length=\\\"255\\\"/><column id=\\\"field0017\\\" type=\\\"4\\\" name=\\\"出差时长\\\" isNullable=\\\"false\\\" length=\\\"20\\\"/><column id=\\\"field0018\\\" type=\\\"0\\\" name=\\\"是否境外出差\\\" isNullable=\\\"false\\\" length=\\\"100\\\"/><column id=\\\"field0019\\\" type=\\\"0\\\" name=\\\"是否需要APEC卡\\\" isNullable=\\\"false\\\" length=\\\"100\\\"/><column id=\\\"field0020\\\" type=\\\"0\\\" name=\\\"是否展会出差\\\" isNullable=\\\"false\\\" length=\\\"100\\\"/><column id=\\\"field0021\\\" type=\\\"0\\\" name=\\\"出差事由\\\" isNullable=\\\"false\\\" length=\\\"255\\\"/></definitions><values>");
stringBuffer.append("<column name=\\\"申请单号\\\"><value><![CDATA["+jsonObject.getString("field0011") != null?jsonObject.getString("field0011"):""+"]]></value></column>");
stringBuffer.append("<column name=\\\"申请人\\\"><value><![CDATA["+jsonObject.getString("field0001") != null?jsonObject.getString("field0001"):""+"]]></value></column>");
stringBuffer.append("<column name=\\\"申请人工号\\\"><value><![CDATA["+jsonObject.getString("field0002") != null?jsonObject.getString("field0002"):""+"]]></value></column>");
stringBuffer.append("<column name=\\\"申请人职位\\\"><value><![CDATA["+jsonObject.getString("field0012") != null?jsonObject.getString("field0012"):""+"]]></value></column>");
stringBuffer.append("<column name=\\\"申请人部门\\\"><value><![CDATA["+jsonObject.getString("field0013") != null?jsonObject.getString("field0013"):""+"]]></value></column>");
stringBuffer.append("<column name=\\\"申请人手机号\\\"><value><![CDATA["+jsonObject.getString("field0014") != null?jsonObject.getString("field0014"):""+"]]></value></column>");
stringBuffer.append("<column name=\\\"出差时间\\\"><value><![CDATA["+jsonObject.getString("field0003") != null?jsonObject.getString("field0003"):""+"]]></value></column>");
stringBuffer.append("<column name=\\\"出差类型\\\"><value><![CDATA["+jsonObject.getString("field0015") != null?jsonObject.getString("field0015"):""+"]]></value></column>");
stringBuffer.append("<column name=\\\"出差城市\\\"><value><![CDATA["+jsonObject.getString("field0016") != null?jsonObject.getString("field0016"):""+"]]></value></column>");
stringBuffer.append("<column name=\\\"出差时长\\\"><value><![CDATA["+jsonObject.getString("field0017") != null?jsonObject.getString("field0017"):""+"]]></value></column>");
stringBuffer.append("<column name=\\\"是否境外出差\\\"><value><![CDATA["+jsonObject.getString("field0018") != null?jsonObject.getString("field0018"):""+"]]></value></column>");
stringBuffer.append("<column name=\\\"是否需要APEC卡\\\"><value><![CDATA["+jsonObject.getString("field0019") != null?jsonObject.getString("field0019"):""+"]]></value></column>");
stringBuffer.append("<column name=\\\"是否展会出差\\\"><value><![CDATA["+jsonObject.getString("field0020") != null?jsonObject.getString("field0020"):""+"]]></value></column>");
stringBuffer.append("<column name=\\\"出差事由\\\"><value><![CDATA["+jsonObject.getString("field0021") != null?jsonObject.getString("field0021"):""+"]]></value></column>");
stringBuffer.append(" </values><subForms><subForm><definitions><column id=\\\"field0004\\\" type=\\\"2\\\" name=\\\"明细表-出发时间\\\" isNullable=\\\"false\\\" length=\\\"255\\\"/><column id=\\\"field0005\\\" type=\\\"2\\\" name=\\\"明细表-结束时间\\\" isNullable=\\\"false\\\" length=\\\"255\\\"/><column id=\\\"field0022\\\" type=\\\"4\\\" name=\\\"明细表-出差时长\\\" isNullable=\\\"false\\\" length=\\\"20\\\"/><column id=\\\"field0006\\\" type=\\\"0\\\" name=\\\"明细表-出发地\\\" isNullable=\\\"false\\\" length=\\\"255\\\"/><column id=\\\"field0007\\\" type=\\\"0\\\" name=\\\"明细表-目的地\\\" isNullable=\\\"false\\\" length=\\\"255\\\"/><column id=\\\"field0008\\\" type=\\\"0\\\" name=\\\"明细表-交通工具\\\" isNullable=\\\"false\\\" length=\\\"255\\\"/><column id=\\\"field0009\\\" type=\\\"4\\\" name=\\\"明细表-预计费用\\\" isNullable=\\\"false\\\" length=\\\"20\\\"/><column id=\\\"field0004\\\" type=\\\"2\\\" name=\\\"明细表-出发时间\\\" isNullable=\\\"false\\\" length=\\\"255\\\"/><column id=\\\"field0005\\\" type=\\\"2\\\" name=\\\"明细表-结束时间\\\" isNullable=\\\"false\\\" length=\\\"255\\\"/><column id=\\\"field0022\\\" type=\\\"4\\\" name=\\\"明细表-出差时长\\\" isNullable=\\\"false\\\" length=\\\"20\\\"/><column id=\\\"field0006\\\" type=\\\"0\\\" name=\\\"明细表-出发地\\\" isNullable=\\\"false\\\" length=\\\"255\\\"/><column id=\\\"field0007\\\" type=\\\"0\\\" name=\\\"明细表-目的地\\\" isNullable=\\\"false\\\" length=\\\"255\\\"/><column id=\\\"field0008\\\" type=\\\"0\\\" name=\\\"明细表-交通工具\\\" isNullable=\\\"false\\\" length=\\\"255\\\"/><column id=\\\"field0009\\\" type=\\\"4\\\" name=\\\"明细表-预计费用\\\" isNullable=\\\"false\\\" length=\\\"20\\\"/></definitions><values>");
//处理明细
JSONArray jsonArray = JSONArray.parseArray(jsonObject.getString("mdm_ccd_detail"));
if(jsonArray != null&& jsonArray.size() > 0){
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject detailObject = jsonArray.getJSONObject(i);
stringBuffer.append("<row>");
stringBuffer.append("<column name=\\\"明细表-出发时间\\\"><value><![CDATA["+detailObject.getString("field0004") != null?detailObject.getString("field0004"):""+"]]></value></column>");
stringBuffer.append("<column name=\\\"明细表-结束时间\\\"><value><![CDATA["+detailObject.getString("field0005") != null?detailObject.getString("field0005"):""+"]]></value></column>");
stringBuffer.append("<column name=\\\"明细表-出差时长\\\"><value><![CDATA["+detailObject.getString("field0022") != null?detailObject.getString("field0022"):""+"]]></value></column>");
stringBuffer.append("<column name=\\\"明细表-出发地\\\"><value><![CDATA["+detailObject.getString("field0006") != null?detailObject.getString("field0006"):""+"]]></value></column>");
stringBuffer.append("<column name=\\\"明细表-目的地\\\"><value><![CDATA["+detailObject.getString("field0007") != null?detailObject.getString("field0007"):""+"]]></value></column>");
stringBuffer.append("<column name=\\\"明细表-交通工具\\\"><value><![CDATA["+detailObject.getString("field0008") != null?detailObject.getString("field0008"):""+"]]></value></column>");
stringBuffer.append("<column name=\\\"明细表-预计费用\\\"><value><![CDATA["+detailObject.getString("field0009") != null?detailObject.getString("field0009"):""+"]]></value></column>");
stringBuffer.append("</row");
}
}
stringBuffer.append("</values></subForm></subForms></formExport></forms>");
return stringBuffer.toString();
}
}