This commit is contained in:
lvleigang 2024-06-20 08:43:44 +08:00
commit 2adb827e0d
10 changed files with 691 additions and 339 deletions

26
pom.xml
View File

@ -244,12 +244,12 @@
</exclusions> </exclusions>
</dependency> </dependency>
<!-- 添加dm8 jdbc jar 包依赖--> <!-- &lt;!&ndash; 添加dm8 jdbc jar 包依赖&ndash;&gt;-->
<dependency> <!-- <dependency>-->
<groupId>com.dameng</groupId> <!-- <groupId>com.dameng</groupId>-->
<artifactId>Dm8JdbcDriver18</artifactId> <!-- <artifactId>Dm8JdbcDriver18</artifactId>-->
<version>8.1.1.49</version> <!-- <version>8.1.1.49</version>-->
</dependency> <!-- </dependency>-->
<dependency> <dependency>
@ -338,20 +338,6 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId> <artifactId>spring-boot-starter-cache</artifactId>
</dependency> </dependency>
<!-- JimuReport 积木报表 -->
<dependency>
<groupId>org.jeecgframework.jimureport</groupId>
<artifactId>jimureport-spring-boot-starter</artifactId>
<version>${jimureport.version}</version>
</dependency>
<!-- minio oss-->
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<version>${minio.version}</version>
<optional>true</optional>
</dependency>
<!-- postgresql驱动 --> <!-- postgresql驱动 -->
<dependency> <dependency>
<groupId>org.postgresql</groupId> <groupId>org.postgresql</groupId>

View File

@ -3,21 +3,15 @@ package com.hzya.frame.report.reportManage.service.impl;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.hzya.frame.basedao.service.impl.BaseService;
import com.hzya.frame.report.reportManage.dao.IReportManageDao;
import com.hzya.frame.report.reportManage.entity.JimuReportEntity; import com.hzya.frame.report.reportManage.entity.JimuReportEntity;
import com.hzya.frame.report.reportManage.entity.ReportManageEntity; import com.hzya.frame.report.reportManage.entity.ReportManageEntity;
import com.hzya.frame.report.reportManage.dao.IReportManageDao;
import com.hzya.frame.report.reportManage.service.IReportManageService; import com.hzya.frame.report.reportManage.service.IReportManageService;
import com.hzya.frame.sysnew.user.entity.SysUserEntity;
import com.hzya.frame.sysnew.userCompany.entity.SysUserCompanyEntity;
import com.hzya.frame.sysnew.userRoles.entity.SysUserRolesEntity;
import com.hzya.frame.util.AESUtil;
import com.hzya.frame.web.entity.BaseResult; import com.hzya.frame.web.entity.BaseResult;
import com.hzya.frame.web.entity.JsonResultEntity; import com.hzya.frame.web.entity.JsonResultEntity;
import dm.jdbc.d.U;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import javax.annotation.Resource; import org.springframework.stereotype.Service;
import com.hzya.frame.basedao.service.impl.BaseService;
import java.util.List; import java.util.List;
@ -111,14 +105,10 @@ public class ReportManageServiceImpl extends BaseService<ReportManageEntity, Str
} }
private boolean checkIsUse(ReportManageEntity entity) { private boolean checkIsUse(ReportManageEntity entity) {
ReportManageEntity checkUse = new ReportManageEntity(); ReportManageEntity checkUse = new ReportManageEntity();
checkUse.setReportId(entity.getReportId()); checkUse.setReportId(entity.getReportId());
if (reportManageDao.getCount(checkUse) > 0) { return reportManageDao.getCount(checkUse) <= 0;
return false;
}
return true;
} }
/** /**
@ -271,6 +261,7 @@ public class ReportManageServiceImpl extends BaseService<ReportManageEntity, Str
return BaseResult.getSuccessMessageEntity("获取报表成功", entity); return BaseResult.getSuccessMessageEntity("获取报表成功", entity);
} }
/** /**
* @param jsonObject * @param jsonObject
* @return com.hzya.frame.web.entity.JsonResultEntity * @return com.hzya.frame.web.entity.JsonResultEntity

View File

@ -159,6 +159,9 @@ public class SysApplicationDatabaseEntity extends BaseEntity {
case "3": //mysql case "3": //mysql
sourceTypeName = "mysql"; sourceTypeName = "mysql";
break; break;
case "4": //dm
sourceTypeName = "dm";
break;
default: default:
} }
} }

View File

@ -13,6 +13,8 @@ public class SysExtensionApiEntity {
private String querys; private String querys;
/** body */ /** body */
private String bodys; private String bodys;
//byteBodys
private byte[] byteBodys;
/** 发送方应用 */ /** 发送方应用 */
private SysApplicationEntity sendApp; private SysApplicationEntity sendApp;
/** 接收方应用 */ /** 接收方应用 */
@ -67,5 +69,13 @@ public class SysExtensionApiEntity {
public void setReceiveApi(SysApplicationApiEntity receiveApi) { public void setReceiveApi(SysApplicationApiEntity receiveApi) {
this.receiveApi = receiveApi; this.receiveApi = receiveApi;
} }
public byte[] getByteBodys() {
return byteBodys;
}
public void setByteBodys(byte[] byteBodys) {
this.byteBodys = byteBodys;
}
} }

View File

@ -417,4 +417,14 @@ public interface ISysApplicationService extends IBaseService<SysApplicationEntit
* @return * @return
**/ **/
JsonResultEntity enableOrDisableAppScript(JSONObject jsonObject); JsonResultEntity enableOrDisableAppScript(JSONObject jsonObject);
/****
* ESB请求转发重载方法,临时处理传入请求对象
* @content:
* @author 👻👻👻👻👻👻👻👻 gjh
* @date 2024-06-19 9:34
* @param
* @return com.hzya.frame.web.entity.JsonResultEntity
**/
JsonResultEntity externalCallInterfaceToESB(ServletRequest servletRequest, ServletResponse servletResponse);
} }

View File

@ -1,6 +1,5 @@
package com.hzya.frame.sysnew.application.service.impl; package com.hzya.frame.sysnew.application.service.impl;
import cn.dev33.satoken.exception.NotLoginException;
import cn.dev33.satoken.stp.StpUtil; import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
@ -11,6 +10,7 @@ import com.alibaba.fastjson.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DSTransactional; import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.hzya.frame.basedao.service.impl.BaseService;
import com.hzya.frame.serviceUtil.DsDataSourceUtil; import com.hzya.frame.serviceUtil.DsDataSourceUtil;
import com.hzya.frame.sysnew.application.api.dao.ISysApplicationApiDao; import com.hzya.frame.sysnew.application.api.dao.ISysApplicationApiDao;
import com.hzya.frame.sysnew.application.api.entity.SysApplicationApiDto; import com.hzya.frame.sysnew.application.api.entity.SysApplicationApiDto;
@ -25,14 +25,10 @@ import com.hzya.frame.sysnew.application.apiPara.dao.ISysApplicationApiParaDao;
import com.hzya.frame.sysnew.application.apiPara.entity.SysApplicationApiParaEntity; import com.hzya.frame.sysnew.application.apiPara.entity.SysApplicationApiParaEntity;
import com.hzya.frame.sysnew.application.apiType.dao.ISysApplicationApiTypeDao; import com.hzya.frame.sysnew.application.apiType.dao.ISysApplicationApiTypeDao;
import com.hzya.frame.sysnew.application.apiType.entity.SysApplicationApiTypeEntity; import com.hzya.frame.sysnew.application.apiType.entity.SysApplicationApiTypeEntity;
import com.hzya.frame.sysnew.application.dao.ISysApplicationDao;
import com.hzya.frame.sysnew.application.database.dao.ISysApplicationDatabaseDao; import com.hzya.frame.sysnew.application.database.dao.ISysApplicationDatabaseDao;
import com.hzya.frame.sysnew.application.database.entity.SysApplicationDatabaseEntity; import com.hzya.frame.sysnew.application.database.entity.SysApplicationDatabaseEntity;
import com.hzya.frame.sysnew.application.entity.SysApplicationDatasourceDto; import com.hzya.frame.sysnew.application.entity.*;
import com.hzya.frame.sysnew.application.entity.SysApplicationDto;
import com.hzya.frame.sysnew.application.entity.SysApplicationEntity;
import com.hzya.frame.sysnew.application.dao.ISysApplicationDao;
import com.hzya.frame.sysnew.application.entity.SysApplicationVo;
import com.hzya.frame.sysnew.application.entity.SysExtensionApiEntity;
import com.hzya.frame.sysnew.application.plugin.dao.ISysApplicationPluginDao; import com.hzya.frame.sysnew.application.plugin.dao.ISysApplicationPluginDao;
import com.hzya.frame.sysnew.application.plugin.entity.SysApplicationPluginDto; import com.hzya.frame.sysnew.application.plugin.entity.SysApplicationPluginDto;
import com.hzya.frame.sysnew.application.plugin.entity.SysApplicationPluginEntity; import com.hzya.frame.sysnew.application.plugin.entity.SysApplicationPluginEntity;
@ -47,17 +43,12 @@ import com.hzya.frame.sysnew.messageManageDetail.entity.SysMessageManageDetailEn
import com.hzya.frame.sysnew.messageManageLog.dao.ISysMessageManageLogDao; import com.hzya.frame.sysnew.messageManageLog.dao.ISysMessageManageLogDao;
import com.hzya.frame.sysnew.messageManageLog.entity.SysMessageManageLogEntity; import com.hzya.frame.sysnew.messageManageLog.entity.SysMessageManageLogEntity;
import com.hzya.frame.sysnew.messageManageLog.entity.SysMessageManageLogPageVo; import com.hzya.frame.sysnew.messageManageLog.entity.SysMessageManageLogPageVo;
import com.hzya.frame.sysnew.popedomInterface.entity.SysPopedomInterfaceEntity;
import com.hzya.frame.sysnew.sysInterface.entity.SysInterfaceEntity;
import com.hzya.frame.sysnew.user.entity.SysUserEntity;
import com.hzya.frame.sysnew.userRoles.entity.SysUserRolesEntity;
import com.hzya.frame.util.AESUtil; import com.hzya.frame.util.AESUtil;
import com.hzya.frame.util.IPHelper; import com.hzya.frame.util.IPHelper;
import com.hzya.frame.uuid.UUIDUtils; import com.hzya.frame.uuid.UUIDUtils;
import com.hzya.frame.web.action.ApplicationContextUtil; import com.hzya.frame.web.action.ApplicationContextUtil;
import com.hzya.frame.web.entity.BaseResult; import com.hzya.frame.web.entity.BaseResult;
import com.hzya.frame.web.entity.JsonResultEntity; import com.hzya.frame.web.entity.JsonResultEntity;
import com.hzya.frame.web.exception.BaseSystemException;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.client.config.RequestConfig; import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.CloseableHttpResponse;
@ -67,27 +58,17 @@ import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.task.TaskExecutor; import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.ServletRequest; import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse; import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import com.hzya.frame.basedao.service.impl.BaseService;
import org.springframework.util.ObjectUtils;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* 应用表(SysApplication)表服务实现类 * 应用表(SysApplication)表服务实现类
@ -2438,4 +2419,368 @@ public class SysApplicationServiceImpl extends BaseService<SysApplicationEntity,
return BaseResult.getSuccessMessageEntity("停用成功"); return BaseResult.getSuccessMessageEntity("停用成功");
} }
} }
@Override
public JsonResultEntity externalCallInterfaceToESB(ServletRequest servletRequest, ServletResponse servletResponse) {
//例如A应用发送数据到中台中台转发到B应用
HttpServletRequest request = (HttpServletRequest) servletRequest;
String oldbodys = ServletUtil.getBody(servletRequest);
Map<String, String> oldheaderMap = ServletUtil.getHeaderMap(request);
String oldquerys = request.getQueryString();
//应用key
String publicKey = request.getHeader("publicKey");
//应用密钥
String secretKey = request.getHeader("secretKey");
//appId
String appId = request.getHeader("appId");
//apiCode
String apiCode = request.getHeader("apiCode");
String ip = IPHelper.getIpAddr(request);
if (publicKey == null || "".equals(publicKey)) {
return BaseResult.getFailureMessageEntity("请先传递公钥");
}
if (secretKey == null || "".equals(secretKey)) {
return BaseResult.getFailureMessageEntity("请先传递密钥");
}
if (appId == null || "".equals(appId)) {
return BaseResult.getFailureMessageEntity("请先传递接收方应用");
}
if (apiCode == null || "".equals(apiCode)) {
return BaseResult.getFailureMessageEntity("请先传递发送接口");
}
logger.info("请求参数publicKey" + publicKey + "】secretKey" + secretKey + "】appId" + appId + "】apiCode" + apiCode);
//根据请求a应用的公钥密钥是否能查找到一条数据
SysApplicationEntity sendApp = getAppByPublicKeySecretKey(publicKey, secretKey);
if (sendApp == null) {
//saveLog(new SysApplicationEntity(), new SysApplicationEntity(), new SysApplicationApiEntity(), oldbodys, null, oldheaderMap, null, null, oldquerys, null, null, false,"公钥、密钥错误");
return BaseResult.getFailureMessageEntity("公钥、密钥错误,请联系管理员");
}
//判断应用是否启用
if (sendApp.getAppStatus() == null || !"1".equals(sendApp.getAppStatus())) {
saveLog(sendApp, new SysApplicationEntity(), new SysApplicationApiEntity(), oldbodys, null, oldheaderMap, null, null, oldquerys, null, null, false,sendApp.getName() + "应用未启用");
return BaseResult.getFailureMessageEntity(sendApp.getName() + "应用未启用,请联系管理员");
}
SysApplicationEntity receiveApp = getAppByAppId(appId);
if (receiveApp == null) {
saveLog(sendApp, new SysApplicationEntity(), new SysApplicationApiEntity(), oldbodys, null, oldheaderMap, null, null, oldquerys, null, null, false,"根据appId:" + appId + "未匹配到应用");
return BaseResult.getFailureMessageEntity("根据appId:" + appId + "未匹配到应用,请联系管理员");
}
//判断应用是否启用
if (receiveApp.getAppStatus() == null || !"1".equals(receiveApp.getAppStatus())) {
saveLog(sendApp, receiveApp, new SysApplicationApiEntity(), oldbodys, null, oldheaderMap, null, null, oldquerys, null, null, false,receiveApp.getName() + "应用未启用" );
return BaseResult.getFailureMessageEntity(receiveApp.getName() + "应用未启用,请联系管理员");
}
//判断应用接口是否启用
if (receiveApp.getInterfaceStatus() == null || !"1".equals(receiveApp.getInterfaceStatus())) {
saveLog(sendApp, receiveApp, new SysApplicationApiEntity(), oldbodys, null, oldheaderMap, null, null, oldquerys, null, null, false,receiveApp.getName() + "应用接口环境未启用" );
return BaseResult.getFailureMessageEntity(receiveApp.getName() + "应用接口环境未启用,请联系管理员");
}
SysApplicationApiEntity receiveApi = getApiByAppIdApiCode(receiveApp.getId(), apiCode);
if (receiveApi == null) {
saveLog(sendApp, receiveApp, receiveApi, oldbodys, null, oldheaderMap, null, null, oldquerys, null, null, false,receiveApp.getName() + ":" + apiCode + "未启用或者未创建" );
return BaseResult.getFailureMessageEntity(receiveApp.getName() + ":" + apiCode + "未启用或者未创建");
}
SysApplicationApiAuthEntity sysApplicationApiAuthEntity = getApiAuthByNameAppId(sendApp.getId(), receiveApp.getId());
if (sysApplicationApiAuthEntity == null) {
saveLog(sendApp, receiveApp, receiveApi, oldbodys, null, oldheaderMap, null, null, oldquerys, null, null, false,receiveApp.getName() + "应用权限配置错误" );
return BaseResult.getFailureMessageEntity(receiveApp.getName() + "应用权限配置错误");
}
if (sysApplicationApiAuthEntity.getSystemAddress() != null && !"".equals(sysApplicationApiAuthEntity.getSystemAddress())
&& !sysApplicationApiAuthEntity.getSystemAddress().contains(ip)) {
saveLog(sendApp, receiveApp, receiveApi, oldbodys, null, oldheaderMap, null, null, oldquerys, null, null, false,receiveApp.getName() + "发送应用" + receiveApp.getName() + "的ip白名单配置错误" );
return BaseResult.getFailureMessageEntity(receiveApp.getName() + "发送应用" + receiveApp.getName() + "的ip白名单配置错误");
}
SysApplicationApiAuthDetailEntity sysApplicationApiAuthDetailEntity = getApiAuthDetailByAppIdApiIdTripartiteSystemId(receiveApp.getId(), receiveApi.getId(), sysApplicationApiAuthEntity.getId());
if (sysApplicationApiAuthDetailEntity == null) {
saveLog(sendApp, receiveApp, receiveApi, oldbodys, null, oldheaderMap, null, null, oldquerys, null, null, false,receiveApi.getApiName() + "未授权给" + sendApp.getName() );
return BaseResult.getFailureMessageEntity(receiveApi.getApiName() + "未授权给" + sendApp.getName() + ",请联系管理员");
}
SysExtensionApiEntity sysExtensionApiEntity = new SysExtensionApiEntity();
List<String> a = Arrays.asList(new String[]{"apicode", "appid", "secretkey", "publickey", "x-forwarded-for", "cookie", "x-forwarded-proto", "x-real-ip", "content-length", "accept-language", "host", "content-type", "connection", "cache-control", "accept-encoding", "pragma", "accept", "user-agent"});
Map<String, String> headers = new HashMap<>();
if (receiveApi.getHeaderIn() != null && !"".equals(receiveApi.getHeaderIn())) {
JSONArray jsonArray = JSONArray.parseArray(receiveApi.getHeaderIn());
if (jsonArray != null && jsonArray.size() > 0) {
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject object1 = jsonArray.getJSONObject(i);
headers.put(object1.getString("parameterName"), object1.getString("example"));
}
}
}
if (oldheaderMap != null && oldheaderMap.size() > 0) {
for (Map.Entry<String, String> entry : oldheaderMap.entrySet()) {
if (!a.contains(entry.getKey())) {
headers.put(entry.getKey(), entry.getValue());
}
}
}
sysExtensionApiEntity.setSendApp(sendApp);
sysExtensionApiEntity.setReceiveApp(receiveApp);
sysExtensionApiEntity.setReceiveApi(receiveApi);
sysExtensionApiEntity.setHeaders(headers);
sysExtensionApiEntity.setQuerys(oldquerys);
sysExtensionApiEntity.setBodys(oldbodys);
Method[] methods = null;
Object object = null;
// 判断是否有内部api 是否扩展api 1启用 2停用
if (receiveApi.getExtensionApi() != null && "1".equals(receiveApi.getExtensionApi())
&& receiveApi.getBeanName() != null && !"".equals(receiveApi.getBeanName())
&& receiveApi.getFunName() != null && !"".equals(receiveApi.getFunName())
) {
//获取类
try {
object = ApplicationContextUtil.getBeanByName(receiveApi.getBeanName());
} catch (SecurityException e) {
}
//获取类下面的方法
methods = object.getClass().getMethods();
if (methods == null || methods.length == 0) {
return BaseResult.getFailureMessageEntity("未找到内部方法,请联系管理员");
}
for (Method m : methods) {
if (null != m) {
if (m.getName().equals(receiveApi.getFunName().trim())) {
try {
logger.info("invoke开始>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
sysExtensionApiEntity = (SysExtensionApiEntity) m.invoke(object, sysExtensionApiEntity);
logger.info("invoke结束>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
} catch (Exception e) {
logger.error("invokeException{}", e.getMessage());
return BaseResult.getFailureMessageEntity("内部方法执行错误,请联系管理员");
}
}
}
}
}
headers = sysExtensionApiEntity.getHeaders();
String querys = sysExtensionApiEntity.getQuerys();
byte[] byteBodys = sysExtensionApiEntity.getByteBodys();
//设置参数获取参数
StringBuffer url = new StringBuffer();
if(!receiveApi.getDestinationAddress().toLowerCase().startsWith("http")){
url.append(receiveApp.getInterfaceAddress());
}
url.append(receiveApi.getDestinationAddress());
if (querys != null) {
url.append("?");
url.append(querys);
}
Integer outTime = 6000;
if (receiveApi.getTimeoutPeriod() != null && !"".equals(receiveApi.getTimeoutPeriod())) {
outTime = Integer.valueOf(receiveApi.getTimeoutPeriod());
}
//1POST 2GET
String method = "POST";
if ("2".equals(receiveApi.getRequestMethod())) {
method = "GET";
}
//List<String> a = Arrays.asList(new String[]{"apicode", "appid", "secretkey", "publickey", "x-forwarded-for", "cookie", "x-forwarded-proto", "x-real-ip", "content-length", "accept-language", "host", "content-type", "connection", "cache-control", "accept-encoding", "pragma", "accept", "user-agent"});
//Map<String, String> headers = new HashMap<>();
//if (receiveApi.getHeaderIn() != null && !"".equals(receiveApi.getHeaderIn())) {
// JSONArray jsonArray = JSONArray.parseArray(receiveApi.getHeaderIn());
// if (jsonArray != null && jsonArray.size() > 0) {
// for (int i = 0; i < jsonArray.size(); i++) {
// JSONObject object1 = jsonArray.getJSONObject(i);
// headers.put(object1.getString("parameterName"), object1.getString("example"));
// }
// }
//}
//if (headerMap != null && headerMap.size() > 0) {
// for (Map.Entry<String, String> entry : headerMap.entrySet()) {
// if (!a.contains(entry.getKey())) {
// headers.put(entry.getKey(), entry.getValue());
// }
// }
//}
if ("POST".equals(method)) {
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
// HttpClient
CloseableHttpClient closeableHttpClient = httpClientBuilder.disableCookieManagement().build();
HttpPost post = new HttpPost(url.toString());
CloseableHttpResponse response = null;
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(outTime).build();
post.setConfig(requestConfig);//设置请求参数超时时间
if (headers != null && headers.size() > 0) {
for (String key : headers.keySet()) {
post.setHeader(key, headers.get(key));
}
}
byte[] body = null;
boolean flag = true;
try {
if (byteBodys != null && !"".equals(byteBodys)) {
ByteArrayEntity entity = new ByteArrayEntity(byteBodys);
entity.setContentType("application/json");
post.setEntity(entity);
}
response = closeableHttpClient.execute(post);
HttpEntity entity = response.getEntity();
synchronized (lock) {
body = EntityUtils.toByteArray(entity);
}
flag = true;
logger.info("返回结果:" +Base64.getEncoder().encodeToString(body));
} catch (Exception e) {
logger.error("请求错误:" + e.getMessage());
flag = false;
} finally {
try {
// 关闭响应对象
if (response != null) {
response.close();
}
// 关闭响应对象
if (closeableHttpClient != null) {
closeableHttpClient.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
logger.info("保存日志开始");
SysMessageManageLogEntity sysMessageManageLogEntity = saveLog(sendApp, receiveApp, receiveApi, oldbodys,Base64.getEncoder().encodeToString(byteBodys) , oldheaderMap,headers, headers, oldquerys,querys, body.toString(),true,null);
if (methods != null && methods.length > 0) {
for (Method m : methods) {
if (null != m) {
if (m.getName().equals(receiveApi.getFunName().trim()+"CallBack")) {
try {
logger.info("invoke开始>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
m.invoke(object, sysMessageManageLogEntity);
logger.info("invoke结束>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
} catch (Exception e) {
logger.error("invokeException{}", e.getMessage());
}
}
}
}
}
logger.info("保存日志结束");
if (flag) {
if (JSONUtil.isTypeJSON(body.toString())) {
JSONObject jsonObject = JSONObject.parseObject(body.toString());
if(sysMessageManageLogEntity.getStatus() != null && "3".equals(sysMessageManageLogEntity.getStatus())){
return BaseResult.getSuccessMessageEntity("转发成功", jsonObject);
}else {
return BaseResult.getFailureMessageEntity("转发失败", jsonObject);
}
} else {
if(sysMessageManageLogEntity.getStatus() != null && "3".equals(sysMessageManageLogEntity.getStatus())){
return BaseResult.getSuccessMessageEntity("转发成功", body);
}else {
return BaseResult.getFailureMessageEntity("转发失败", body);
}
}
} else {
return BaseResult.getFailureMessageEntity("转发失败", body);
}
} else {//GET
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
// HttpClient
CloseableHttpClient closeableHttpClient = httpClientBuilder.disableCookieManagement().build();
HttpGet get = new HttpGet(url.toString());
CloseableHttpResponse response = null;
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(outTime).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();
boolean flag = true;
try {
response = closeableHttpClient.execute(get);
HttpEntity entity = response.getEntity();
synchronized (lock) {
body.append(EntityUtils.toString(entity,"UTF-8"));
}
flag = true;
logger.info("返回结果:" + body);
} catch (Exception e) {
logger.error("请求错误:" + e.getMessage());
body.append(e.getMessage());
flag = false;
} finally {
try {
// 关闭响应对象
if (response != null) {
response.close();
}
// 关闭响应对象
if (closeableHttpClient != null) {
closeableHttpClient.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
logger.info("保存日志开始");
SysMessageManageLogEntity sysMessageManageLogEntity = saveLog(sendApp, receiveApp, receiveApi, oldbodys,Base64.getEncoder().encodeToString(byteBodys) , oldheaderMap,headers, headers, oldquerys,querys, body.toString(), true,null);
if (methods != null && methods.length > 0) {
for (Method m : methods) {
if (null != m) {
if (m.getName().equals(receiveApi.getFunName().trim()+"CallBack")) {
try {
logger.info("invoke开始>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
m.invoke(object, sysMessageManageLogEntity);
logger.info("invoke结束>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
} catch (Exception e) {
logger.error("invokeException{}", e.getMessage());
}
}
}
}
}
logger.info("保存日志结束");
if (flag) {
if (JSONUtil.isTypeJSON(body.toString())) {
JSONObject jsonObject = JSONObject.parseObject(body.toString());
if(sysMessageManageLogEntity.getStatus() != null && "3".equals(sysMessageManageLogEntity.getStatus())){
return BaseResult.getSuccessMessageEntity("转发成功", jsonObject);
}else {
return BaseResult.getFailureMessageEntity("转发失败", jsonObject);
}
} else {
if(sysMessageManageLogEntity.getStatus() != null && "3".equals(sysMessageManageLogEntity.getStatus())){
return BaseResult.getSuccessMessageEntity("转发成功", body);
}else {
return BaseResult.getFailureMessageEntity("转发失败", body);
}
}
} else {
return BaseResult.getFailureMessageEntity("转发失败", body);
}
}
}
} }

View File

@ -7,8 +7,6 @@ import com.hzya.frame.sysnew.grovy.service.IGroovyIntegrationService;
import com.hzya.frame.util.GroovyUtil; import com.hzya.frame.util.GroovyUtil;
import com.hzya.frame.web.entity.BaseResult; import com.hzya.frame.web.entity.BaseResult;
import com.hzya.frame.web.entity.JsonResultEntity; import com.hzya.frame.web.entity.JsonResultEntity;
import groovy.lang.GroovyClassLoader;
import groovy.lang.GroovyObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -25,28 +23,41 @@ import org.springframework.stereotype.Service;
public class GroovyIntegrationServiceImpl implements IGroovyIntegrationService { public class GroovyIntegrationServiceImpl implements IGroovyIntegrationService {
private static final Logger logger = LoggerFactory.getLogger(GroovyIntegrationServiceImpl.class); private static final Logger logger = LoggerFactory.getLogger(GroovyIntegrationServiceImpl.class);
// public static void main(String[] args) {
// HelloWorld helloWorld = new HelloWorld();
// System.out.println(helloWorld.sayHello());
// }
public static void main(String[] args) throws IllegalAccessException, InstantiationException {
GroovyClassLoader groovyClassLoader = new GroovyClassLoader();
// 动态编译和加载Groovy脚本
Class<?> groovyClass = groovyClassLoader.parseClass("println(\"1231231\")");
// 创建Groovy类的实例
GroovyObject groovyObject = (GroovyObject) groovyClass.newInstance();
// 执行Groovy脚本
JSONObject jsonObject = new JSONObject();
jsonObject.put("name", "张三");
Object returnObj = groovyObject.invokeMethod("run", jsonObject.toJSONString());
}
@Override @Override
public SysExtensionApiEntity groovyScriptExecution(JSONObject jsonObject) { public SysExtensionApiEntity groovyScriptExecution(JSONObject jsonObject) {
Object object = GroovyUtil.execute(jsonObject); Object object = GroovyUtil.execute(jsonObject);
return new SysExtensionApiEntity(); return new SysExtensionApiEntity();
} }
public static void main(String[] args) {
java.lang.String str = "{\"project_org\":\"\",\"modify_time\":\"2024-06-17 16:52:34\",\"project_duty_dept\":null,\"project_name\":\"凯伍德组织档案\",\"document_rule_num\":1,\"add_status\":\"0\",\"delete_status\":\"1\",\"project_dutier\":\"\",\"id\":\"fb12734c8267488b96833633e68a7abc\",\"data_status\":\"F\",\"modify_user_id\":\"c796fd9ba4c9f5ff3cc2fa41a040e443\",\"sorts\":1,\"project_memo\":\"\",\"document_rule\":\"XM-2024-06-17-00001\",\"create_user_id\":\"c796fd9ba4c9f5ff3cc2fa41a040e443\",\"create_time\":\"2024-06-17 16:42:18\",\"company_id\":null,\"project_sh_name\":\"\",\"project_code\":\"01004\",\"project_currtype\":\"\",\"update_status\":\"0\",\"sts\":\"Y\",\"org_id\":\"0\",\"project_parentpro\":\"\",\"project_bill_type\":\"\"}";
A88772 s = new A88772();
s .execute(str);
}
static class A88772 {
String execute(String jsonStr) {
com.alibaba.fastjson.JSONObject reqData = com.alibaba.fastjson.JSON.parseObject(jsonStr);
com.alibaba.fastjson.JSONObject returnObject = new com.alibaba.fastjson.JSONObject();
com.alibaba.fastjson.JSONObject ufinterfaceObject = new com.alibaba.fastjson.JSONObject();
ufinterfaceObject.put("billtype", "supplier"); ufinterfaceObject.put("isexchange", "Y");
ufinterfaceObject.put("replace", "Y"); ufinterfaceObject.put("sender", "OA");
ufinterfaceObject.put("account", "01"); ufinterfaceObject.put("groupcode", "00");
com.alibaba.fastjson.JSONObject billObject = new com.alibaba.fastjson.JSONObject();
com.alibaba.fastjson.JSONObject billheadObject = new com.alibaba.fastjson.JSONObject();
billheadObject.put("code", reqData.get("project_code")); billheadObject.put("supprop", "0");
billheadObject.put("custstate", "1"); billheadObject.put("pk_supplierclass", "S01");
billheadObject.put("pk_country", "CN"); billheadObject.put("pk_timezone", "P0800");
billheadObject.put("pk_format", "ZH-CN"); billheadObject.put("enablestate", "2");
billheadObject.put("name", reqData.get("project_sh_name")); billheadObject.put("pk_group", "00");
billheadObject.put("pk_org", "003"); billheadObject.put("taxpayerid", "087981489021135119");
returnObject.put("ufinterface",ufinterfaceObject); billObject.put("billhead", billheadObject); returnObject.put("bill",billObject);
System.out.println( returnObject.toJSONString());
return returnObject.toJSONString();
}
}
} }

View File

@ -1,16 +1,10 @@
package com.hzya.frame.u8c.ax.service.impl; package com.hzya.frame.u8c.ax.service.impl;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.hzya.frame.basedao.service.impl.BaseService;
import com.hzya.frame.u8c.ax.dao.IAxDao; import com.hzya.frame.u8c.ax.dao.IAxDao;
import com.hzya.frame.u8c.ax.entity.ArchivesEntity; import com.hzya.frame.u8c.ax.entity.*;
import com.hzya.frame.u8c.ax.entity.Ass;
import com.hzya.frame.u8c.ax.entity.Voucher;
import com.hzya.frame.u8c.ax.entity.VoucherDetails;
import com.hzya.frame.u8c.ax.entity.VoucherRoot;
import com.hzya.frame.u8c.ax.service.IAxService; import com.hzya.frame.u8c.ax.service.IAxService;
import com.hzya.frame.web.entity.BaseResult; import com.hzya.frame.web.entity.BaseResult;
import com.hzya.frame.web.entity.JsonResultEntity; import com.hzya.frame.web.entity.JsonResultEntity;
@ -22,14 +16,11 @@ import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.checkerframework.checker.units.qual.A; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.hzya.frame.basedao.service.impl.BaseService;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -218,6 +209,7 @@ public class AxServiceImpl extends BaseService<ArchivesEntity, String> implement
post.setHeader("publicKey", publicKey); post.setHeader("publicKey", publicKey);
post.setHeader("secretKey", secretKey); post.setHeader("secretKey", secretKey);
post.setHeader("appId", appId); post.setHeader("appId", appId);
post.setHeader("needStackTrace", jsonObject.getString("needStackTrace"));
switch (jsonObject.getString("voucherType")){ switch (jsonObject.getString("voucherType")){
case "add"://新增 case "add"://新增
post.setHeader("apiCode", pzApiCodexz); post.setHeader("apiCode", pzApiCodexz);

View File

@ -164,5 +164,9 @@ public class EntranceController {
public JsonResultEntity externalCallInterface(ServletRequest servletRequest, ServletResponse servletResponse) throws Exception { public JsonResultEntity externalCallInterface(ServletRequest servletRequest, ServletResponse servletResponse) throws Exception {
return sysApplicationService.externalCallInterface(servletRequest,servletResponse); return sysApplicationService.externalCallInterface(servletRequest,servletResponse);
} }
@RequestMapping(value = "/externalCallInterfaceToESB")
@ResponseBody
public JsonResultEntity externalCallInterfaceToESB(ServletRequest servletRequest, ServletResponse servletResponse) throws Exception {
return sysApplicationService.externalCallInterfaceToESB(servletRequest,servletResponse);
}
} }

View File

@ -116,9 +116,9 @@ public class AopDynamicRoutingDataSourceInit {
} else if ("sqlServer".equalsIgnoreCase(source_type)) { } else if ("sqlServer".equalsIgnoreCase(source_type)) {
driveClass = DataSourceUtilProperties.SQL2005DRIVER; driveClass = DataSourceUtilProperties.SQL2005DRIVER;
} }
// else if ("dm".equalsIgnoreCase(source_type)) { else if ("dm".equalsIgnoreCase(source_type)) {
// driveClass = DataSourceUtilProperties.dm; driveClass = DataSourceUtilProperties.dm;
// } }
try { try {
//测试连接 //测试连接
Class.forName(driveClass); Class.forName(driveClass);