物料对称修改

This commit is contained in:
lvleigang 2025-04-23 09:16:02 +08:00
parent 56008918fa
commit 73f8f5c908
5 changed files with 311 additions and 5 deletions

View File

@ -52,10 +52,10 @@ public class FinancialReportPluginInitializer extends PluginBaseEntity{
@Override @Override
public JsonResultEntity executeBusiness(JSONObject requestJson) { public JsonResultEntity executeBusiness(JSONObject requestJson) {
try { try {
logger.info("======开始执行进项全量发票主数据信息同步========"); logger.info("======开始执行财务信息同步========");
return incomeInvoiceService.sendFinancialReportPlugin(requestJson); return incomeInvoiceService.sendFinancialReportPlugin(requestJson);
}catch (Exception e){ }catch (Exception e){
logger.info("======执行进项全量发票主数据同步失败:{}========",e.getMessage()); logger.info("======执行财务同步失败:{}========",e.getMessage());
e.printStackTrace(); e.printStackTrace();
} }
return null; return null;

View File

@ -702,13 +702,13 @@ public class IncomeInvoiceServiceImpl extends BaseService<IncomeInvoiceEntity, S
} }
if(businessData.getString("field0007").equals("2")){//财报 if(businessData.getString("field0007").equals("2")){//财报
return sendFinancialReport(businessData);
} }
if(businessData.getString("field0007").equals("3")){//进项发票 if(businessData.getString("field0007").equals("3")){//进项发票
return BaseResult.getFailureMessageEntity("数据类型错误");
} }
if(businessData.getString("field0007").equals("4")){//销项发票 if(businessData.getString("field0007").equals("4")){//销项发票
return BaseResult.getFailureMessageEntity("数据类型错误");
} }
return BaseResult.getSuccessMessageEntity("推送数据成功"); return BaseResult.getSuccessMessageEntity("推送数据成功");
default: default:
@ -717,6 +717,20 @@ public class IncomeInvoiceServiceImpl extends BaseService<IncomeInvoiceEntity, S
}
/**
* @Author lvleigang
* @Description 发送财报数据
* @Date 5:28 下午 2025/4/22
* @param businessData
* @return com.hzya.frame.web.entity.JsonResultEntity
**/
private JsonResultEntity sendFinancialReport(JSONObject businessData) {
@ -800,5 +814,8 @@ public class IncomeInvoiceServiceImpl extends BaseService<IncomeInvoiceEntity, S
// //
// //
//return BaseResult.getSuccessMessageEntity("执行成功"); //return BaseResult.getSuccessMessageEntity("执行成功");
return null;
} }
} }

View File

@ -64,6 +64,9 @@ public class ApplicationCache {
case "2": // case "2": //
o = applicationApiMap.get(key); o = applicationApiMap.get(key);
break; break;
case "5": //
o = applicationApiMap.get(key);
break;
case "3": // case "3": //
o = applicationApiAuthMap.get(key); o = applicationApiAuthMap.get(key);
break; break;
@ -96,6 +99,7 @@ public class ApplicationCache {
if(receiveApiList != null && receiveApiList.size() > 0){ if(receiveApiList != null && receiveApiList.size() > 0){
for (int i = 0; i < receiveApiList.size(); i++) { for (int i = 0; i < receiveApiList.size(); i++) {
applicationApiMap.put("appId"+receiveApiList.get(i).getAppId()+"apiCode"+receiveApiList.get(i).getApiCode(), receiveApiList.get(i)); applicationApiMap.put("appId"+receiveApiList.get(i).getAppId()+"apiCode"+receiveApiList.get(i).getApiCode(), receiveApiList.get(i));
applicationApiMap.put("apiId"+receiveApiList.get(i).getId(), receiveApiList.get(i));
} }
} }
break; break;

View File

@ -64,6 +64,13 @@ public interface ISeeYonInterFace {
* @throws Exception * @throws Exception
*/ */
SysExtensionApiEntity colEventPre(SysExtensionApiEntity sysExtensionApi)throws Exception; SysExtensionApiEntity colEventPre(SysExtensionApiEntity sysExtensionApi)throws Exception;
/**
* seeyon流程事件监听前置方法绑定数据源
* @param entity
* @return
* @throws Exception
*/
SysExtensionApiEntity getToken(SysExtensionApiEntity entity) throws Exception;
/** /**
* seeyon流程事件监听 * seeyon流程事件监听
* @param jsonObject * @param jsonObject

View File

@ -6,6 +6,7 @@ import cn.hutool.core.map.MapBuilder;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil; import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
@ -13,22 +14,34 @@ import com.hzya.frame.seeyon.dao.ISeeYonInterFaceDao;
import com.hzya.frame.seeyon.entity.OAWorkflowEventDataEntity; import com.hzya.frame.seeyon.entity.OAWorkflowEventDataEntity;
import com.hzya.frame.seeyon.entity.SeeYonInterFaceEntity; import com.hzya.frame.seeyon.entity.SeeYonInterFaceEntity;
import com.hzya.frame.seeyon.service.ISeeYonInterFace; import com.hzya.frame.seeyon.service.ISeeYonInterFace;
import com.hzya.frame.sys.sysenum.SysEnum;
import com.hzya.frame.sysnew.application.api.entity.SysApplicationApiEntity; import com.hzya.frame.sysnew.application.api.entity.SysApplicationApiEntity;
import com.hzya.frame.sysnew.application.api.service.ISysApplicationApiService; import com.hzya.frame.sysnew.application.api.service.ISysApplicationApiService;
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.SysApplicationEntity; import com.hzya.frame.sysnew.application.entity.SysApplicationEntity;
import com.hzya.frame.sysnew.application.entity.SysExtensionApiEntity; import com.hzya.frame.sysnew.application.entity.SysExtensionApiEntity;
import com.hzya.frame.sysnew.application.service.impl.ApplicationCache;
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 com.hzya.frame.web.exception.BaseSystemException;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
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.HttpPost;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -54,6 +67,10 @@ public class SeeYonInterFaceImpl implements ISeeYonInterFace {
private ISysApplicationDatabaseDao sysApplicationDatabaseDao; private ISysApplicationDatabaseDao sysApplicationDatabaseDao;
@Autowired @Autowired
private ISysApplicationApiService sysApplicationApiService; private ISysApplicationApiService sysApplicationApiService;
@Value("${zt.url}")
private String url ;
@Resource
private ApplicationCache applicationCache;
/** /**
* 定义所支持的事件静态代码块 * 定义所支持的事件静态代码块
*/ */
@ -504,4 +521,265 @@ public class SeeYonInterFaceImpl implements ISeeYonInterFace {
} }
return null; return null;
} }
@Override
public SysExtensionApiEntity getToken(SysExtensionApiEntity entity) {
Map<String, String> headers = entity.getHeaders();
SysApplicationApiEntity sysApplicationEntity = entity.getReceiveApi();
SysApplicationEntity sendApp = entity.getSendApp();
SysApplicationEntity receiveApp = entity.getReceiveApp();
if("1".equals(sysApplicationEntity.getNeedLogin()) && sysApplicationEntity.getAuthenticationPort() != null){
SysApplicationApiEntity loginApi = getApiByAppIdApiCode(sysApplicationEntity.getAuthenticationPort());
if (null == loginApi) {
return entity;
}
String rzquerys = getQuery(loginApi,null,null);
Map<String, String> headersa = new HashMap<>();
headersa.put("publicKey", sendApp.getPublicKey());
headersa.put("secretKey", sendApp.getSecretKey());
headersa.put("appId", receiveApp.getAppId().toString());
headersa.put("apiCode", loginApi.getApiCode().toString());
Map<String, String> rzheaders = getHeaders(loginApi,headersa,null);
String rzbodys = getBodys(loginApi,null,null);
JsonResultEntity rzjsonResultEntity = sendData(loginApi,rzheaders,rzbodys,rzquerys);
if (!rzjsonResultEntity.isFlag()) {
return entity;
}
JSONObject attritube = JSONObject.parseObject(rzjsonResultEntity.getAttribute().toString());
headers.put("token",attritube.getJSONObject("attribute").getString("id"));
}
entity.setHeaders(headers);
return entity;
}
private SysApplicationApiEntity getApiByAppIdApiCode(String apiId) {
String str = "apiId" + apiId ;
Object o = applicationCache.get("5", str);
if (o != null) {
return (SysApplicationApiEntity) o;
}
return null;
}
private JsonResultEntity sendData(SysApplicationApiEntity applicationApiEntity, Map<String, String> headers ,String bodys ,String querys) {
StringBuffer urls = new StringBuffer(url);
if (querys != null) {
urls.append("?");
urls.append(querys);
}
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
// HttpClient
CloseableHttpClient closeableHttpClient = httpClientBuilder.disableCookieManagement().build();
HttpPost post = new HttpPost(urls.toString());
CloseableHttpResponse response = null;
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(Integer.valueOf(applicationApiEntity.getTimeoutPeriod())).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();
boolean flag = true;
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"));
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();
}
}
if (flag) {
if (JSONUtil.isTypeJSON(body.toString())) {
JsonResultEntity jsonResultEntity = JSONObject.parseObject(body.toString(),JsonResultEntity.class);
if(jsonResultEntity.isFlag()){
return BaseResult.getSuccessMessageEntity("转发成功", body);
}else {
return BaseResult.getFailureMessageEntity("转发失败", body);
}
}else {
return BaseResult.getFailureMessageEntity("转发失败", body);
}
} else {
return BaseResult.getFailureMessageEntity("转发失败", body);
}
}
private String getBodys(SysApplicationApiEntity loginApi,String sendDatastr, JSONObject loginData) {
JSONObject sendData = new JSONObject();
if(sendDatastr != null ){
sendData = JSONObject.parseObject(sendDatastr);
}
if(loginData == null){
loginData = new JSONObject();
}
if (loginApi.getBodyIn() != null && !"".equals(loginApi.getBodyIn())) {
if (JSONUtil.isTypeJSONArray(loginApi.getBodyIn())) {
JSONArray headerbodyArray = JSON.parseArray(loginApi.getBodyIn());
JSONObject bodyjson = headerbodyArray.getJSONObject(0);
JSONArray headerArray = bodyjson.getJSONArray("children");
for (int i = 0; i < headerArray.size(); i++) {
//获取到第一个数据
JSONObject querys = headerArray.getJSONObject(i);
if (SysEnum.FUNDAMENTAL.getValue().equals(querys.getString(SysEnum.PARAMETERTYPE.getValue()))) {//认证类型
String query = querys.getString(SysEnum.EXAMPLE.getValue());
if (query != null && !"".equals(query)) {
sendData.put(querys.getString(SysEnum.PARAMETERNAME.getValue()),query);
}
}
}
}
}
return sendData.toString();
}
private Map<String, String> getHeaders(SysApplicationApiEntity loginApi,Map<String, String> map,JSONObject loginData) {
if(loginData == null){
loginData = new JSONObject();
}
if (loginApi.getHeaderIn() != null && !"".equals(loginApi.getHeaderIn())) {
if (JSONUtil.isTypeJSONArray(loginApi.getHeaderIn())) {
JSONArray headerArray = JSON.parseArray(loginApi.getHeaderIn());
for (int i = 0; i < headerArray.size(); i++) {
JSONObject querys = headerArray.getJSONObject(i);
//query 只有基本类型不用循环判断下级
//判断参数是否有值
//获取对象下面的层级数据
if (SysEnum.AUTHPORT.getValue().equals(querys.getString(SysEnum.PARAMETERTYPE.getValue()))) {//认证类型
String query = querys.getString(SysEnum.EXAMPLE.getValue());
if (query != null && !"".equals(query)) {
JSONArray example = JSONArray.parseArray(query);
String logValue = getObjectValue(loginData, example);
map.put(querys.getString(SysEnum.PARAMETERNAME.getValue()), logValue);
}
} else {
if (querys.getString(SysEnum.EXAMPLE.getValue()) != null && !"".equals(querys.getString(SysEnum.EXAMPLE.getValue()))) {//入参没有值用实例值如果没有不添加
if(map.get(querys.getString(SysEnum.PARAMETERNAME.getValue())) == null){
map.put(querys.getString(SysEnum.PARAMETERNAME.getValue()), querys.getString(SysEnum.EXAMPLE.getValue()));
}
} else {//没有值直接拼接
if(map.get(querys.getString(SysEnum.PARAMETERNAME.getValue())) == null){
map.put(querys.getString(SysEnum.PARAMETERNAME.getValue()), "");
}
}
}
}
}
}
return map;
}
/**
* @param loginData
* @param example
* @return java.lang.String
* @Author lvleigang
* @Description 根据jsonArray 获取jsonobject中的值
* @Date 11:47 上午 2023/8/31
**/
private String getObjectValue(JSONObject loginData, JSONArray example) {
String values = "";
if (example != null && example.size() > 0) {
for (int i = 0; i < example.size(); i++) {
if (loginData.getString(example.getString(i)) != null && !"".equals(loginData.getString(example.getString(i)))) {
if (i == (example.size() - 1)) {
values = loginData.getString(example.getString(i));
} else {
loginData = JSONObject.parseObject(loginData.getString(example.getString(i)));
}
} else {
return values;
}
}
}
return values;
}
private String getQuery(SysApplicationApiEntity loginApi,String sendDatastr,JSONObject loginData) {
Map<String, String> map = new HashMap<>();
if(sendDatastr != null){
String[] parts = sendDatastr.split("&");
if(parts != null && parts.length > 0){
for (int i = 0; i < parts.length; i++) {
String[] part = parts[i].split("=");
if(part != null && part.length >=2 ){
for (int a = 0; a < part.length; a++) {
map.put(part[0],part[1]);
}
}
}
}
}
if(loginData == null){
loginData = new JSONObject();
}
if (loginApi.getQueryIn() != null && !"".equals(loginApi.getQueryIn())) {
if (JSONUtil.isTypeJSONArray(loginApi.getQueryIn())) {
JSONArray headerArray = JSON.parseArray(loginApi.getQueryIn());
for (int i = 0; i < headerArray.size(); i++) {
JSONObject querys = headerArray.getJSONObject(i);
//query 只有基本类型不用循环判断下级
//判断参数是否有值
//获取对象下面的层级数据
if (SysEnum.AUTHPORT.getValue().equals(querys.getString(SysEnum.PARAMETERTYPE.getValue()))) {//认证类型
String query = querys.getString(SysEnum.EXAMPLE.getValue());
if (query != null && !"".equals(query)) {
JSONArray example = JSONArray.parseArray(query);
String logValue = getObjectValue(loginData, example);
map.put(querys.getString(SysEnum.PARAMETERNAME.getValue()), logValue);
}
} else {
//不是认证类型直接取值
if (querys.getString(SysEnum.EXAMPLE.getValue()) != null && !"".equals(querys.getString(SysEnum.EXAMPLE.getValue()))) {//入参没有值用实例值如果没有不添加
if(map.get(querys.getString(SysEnum.PARAMETERNAME.getValue())) == null){
map.put(querys.getString(SysEnum.PARAMETERNAME.getValue()), querys.getString(SysEnum.EXAMPLE.getValue()));
}
} else {//没有值直接拼接
if(map.get(querys.getString(SysEnum.PARAMETERNAME.getValue())) == null){
map.put(querys.getString(SysEnum.PARAMETERNAME.getValue()), "");
}
}
}
}
}
}
StringBuffer returnStr = new StringBuffer();
if(map != null && map.size() > 0){
for (String key : map.keySet()) {
if("".equals(returnStr)){
returnStr.append(key).append("=").append(map.get(key));
}else {
returnStr.append("&").append(key).append("=").append(map.get(key));
}
}
}
return returnStr.toString();
}
} }