oa对接u8扩展类

This commit is contained in:
xiang2lin 2024-06-05 14:56:40 +08:00
parent 6997fb81ba
commit ef6eb4b807
1 changed files with 68 additions and 28 deletions

View File

@ -1,7 +1,11 @@
package com.hzya.frame.seeyon.service.impl; package com.hzya.frame.seeyon.service.impl;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.map.MapBuilder;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
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.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
@ -19,9 +23,7 @@ import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Date; import java.util.*;
import java.util.HashMap;
import java.util.Map;
/** /**
* @Description seeyon扩展类 * @Description seeyon扩展类
@ -31,7 +33,7 @@ import java.util.Map;
@Service(value = "seeyonExt") @Service(value = "seeyonExt")
public class SeeyonExtServiceImpl implements ISeeyonExtService { public class SeeyonExtServiceImpl implements ISeeyonExtService {
static final String KEY = "`o7eotan9ws8c:aj";
Logger logger = LogManager.getLogger(getClass()); Logger logger = LogManager.getLogger(getClass());
@Autowired @Autowired
@ -53,7 +55,7 @@ public class SeeyonExtServiceImpl implements ISeeyonExtService {
String businessDataStr = dataEntity.getBusinessDataStr();//oa表单参数 String businessDataStr = dataEntity.getBusinessDataStr();//oa表单参数
JSONObject businessData = JSON.parseObject(businessDataStr); JSONObject businessData = JSON.parseObject(businessDataStr);
String formApp = dataEntity.getFormApp(); String formApp = dataEntity.getFormApp();
SysExtensionApiEntity param = new SysExtensionApiEntity(); // SysExtensionApiEntity param = new SysExtensionApiEntity();
Map<String, String> headerMap = entity.getHeaders(); Map<String, String> headerMap = entity.getHeaders();
JSONObject hzyaExtData = dataEntity.getHzyaExtData();//扩展参数 JSONObject hzyaExtData = dataEntity.getHzyaExtData();//扩展参数
if (null == hzyaExtData){ if (null == hzyaExtData){
@ -62,21 +64,21 @@ public class SeeyonExtServiceImpl implements ISeeyonExtService {
//根据forApp组装不同参数 //根据forApp组装不同参数
switch (formApp){ switch (formApp){
case "-8691606453890363968":// case "-8691606453890363968"://
hzyaExtData.put("billCode", "cunhuoabc123456"); getInventory(businessData,entity,hzyaExtData);
getInventory(businessData,param);
break; break;
case "6223456019738676230": case "6223456019738676230":
getSupplier(businessData,param,hzyaExtData); getSupplier(businessData,entity,hzyaExtData);
break; break;
case "-9122508232154527168": case "-9122508232154527168":
getCustomer(businessData,param,hzyaExtData); getCustomer(businessData,entity,hzyaExtData);
break; break;
default: default:
param.setBodys("未匹配到表单当前formID"+ formApp); entity.setBodys("未匹配到表单当前formID"+ formApp);
logger.error("未匹配到表单当前formID"+formApp); logger.error("未匹配到表单当前formID"+formApp);
} }
headerMap.put("hzyaExtData", JSON.toJSONString(hzyaExtData)); headerMap.put("hzyaExtData", JSON.toJSONString(hzyaExtData));
return param; entity.setHeaders(headerMap);
return entity;
}catch (Exception e){ }catch (Exception e){
e.printStackTrace(); e.printStackTrace();
logger.error("执行英德赛OA存货同步U8接口报错{}", e); logger.error("执行英德赛OA存货同步U8接口报错{}", e);
@ -98,8 +100,9 @@ public class SeeyonExtServiceImpl implements ISeeyonExtService {
JSONObject targetData = JSON.parseObject(logEntity.getTargetData());//这个对象里的body是 发送到u8的请求报文 JSONObject targetData = JSON.parseObject(logEntity.getTargetData());//这个对象里的body是 发送到u8的请求报文
JSONObject sourceData = JSON.parseObject(logEntity.getSourceData()); JSONObject sourceData = JSON.parseObject(logEntity.getSourceData());
JSONObject sourceHeaders = sourceData.getJSONObject("header");//源数据header JSONObject sourceHeaders = sourceData.getJSONObject("header");//源数据header
JSONObject targetHeaders = targetData.getJSONObject("header");//源数据header
JSONObject sourceBody = sourceData.getJSONObject("body");//源数据body JSONObject sourceBody = sourceData.getJSONObject("body");//源数据body
JSONObject hzyaExtData = sourceHeaders.getJSONObject("hzyaExtData"); JSONObject hzyaExtData = targetHeaders.getJSONObject("hzyaExtData");// 这里刚开始用sourceHeaders取的2024-06-04 14:24:19改成从target里取因为从apipost请求后在source里取不到
JSONArray formMainIds = new JSONArray(); JSONArray formMainIds = new JSONArray();
formMainIds.add(sourceBody.getString("id")); formMainIds.add(sourceBody.getString("id"));
JSONObject param = new JSONObject(); JSONObject param = new JSONObject();
@ -108,19 +111,44 @@ public class SeeyonExtServiceImpl implements ISeeyonExtService {
param.put("formMainIds",formMainIds); param.put("formMainIds",formMainIds);
param.put("dataSourceCode","ydc_oa_sqlserver"); param.put("dataSourceCode","ydc_oa_sqlserver");
param.put("eventType",sourceBody.getString("eventType")); param.put("eventType",sourceBody.getString("eventType"));
//把返回的单号更新到oa档案表 //把返回的单号更新到oa档案表
String sql = ""; String returnDataStr = logEntity.getReturnData();
switch (formApp){ if (JSONUtil.isTypeJSON(returnDataStr)){
case "-8691606453890363968"://存货 JSONObject returnData = JSONObject.parseObject(returnDataStr);
sql = ""; String success = returnData.getString("success");
break; if ("true".equals(success)){
case "6223456019738676230"://供应商 JSONArray dataArr = returnData.getJSONArray("data");
sql = "update formmain_0229 set field0002 = '' where field0001 = "+hzyaExtData.getString("billCode"); if (null != dataArr){
break; String code = dataArr.getString(0);
case "-9122508232154527168"://客户 String sql = "";
sql = "update formmain_0230 set field0002 = '' where field0001 = "+hzyaExtData.getString("billCode"); switch (formApp){
break; case "-8691606453890363968"://存货
//todo 这里要看一下循环调用的时候 参数是什么样的再决定
sql = "";
break;
case "6223456019738676230"://供应商
sql = "update formmain_0229 set field0002 = "+ code + " where field0001 = "+hzyaExtData.getString("billCode");
break;
case "-9122508232154527168"://客户
sql = "update formmain_0230 set field0002 = "+ code + " where field0001 = "+hzyaExtData.getString("billCode");
break;
}
if (StrUtil.isNotEmpty(sql)){
String sign = SecureUtil.md5(sql);
String data = SecureUtil.aes(KEY.getBytes()).encryptHex(sql);
Map<String, String> headerMap = MapBuilder.<String, String>create(true)
.put("apiCode", "8000190001")
.put("publicKey","ZJYAlF4yjkjZaXmjLOUqsoGzTHAlWpoTdqT7/AEYaXIwpXNCe7eDIk+3zDUT+v578prj")
.put("secretKey","RJTPEoOSDdaBeoxoMs465tcTqy38bRag+12S7kIv2Lxd38wgLeVfWVl/ipVKVu8Qj3JzOP8MtA1LSGvL+2BWG8c/o7DKi92S4mr3zcGearA=")
.put("appId","800019")
.build();
JSONObject params = new JSONObject();
params.put("sign",sign);
params.put("data",data);
String body = HttpRequest.post("http://127.0.0.1:9999/kangarooDataCenterV3/entranceController/externalCallInterface").addHeaders(headerMap).body(JSON.toJSONString(params)).timeout(60000).execute().body();
}
}
}
} }
IntegrationTaskLivingDetailsEntity logDetails = new IntegrationTaskLivingDetailsEntity(); IntegrationTaskLivingDetailsEntity logDetails = new IntegrationTaskLivingDetailsEntity();
logDetails.setRootAppPk(JSON.toJSONString(param)); logDetails.setRootAppPk(JSON.toJSONString(param));
@ -151,11 +179,16 @@ public class SeeyonExtServiceImpl implements ISeeyonExtService {
} }
//存货参数组装 //存货参数组装
private SysExtensionApiEntity getInventory(JSONObject businessData,SysExtensionApiEntity param){ private SysExtensionApiEntity getInventory(JSONObject businessData,SysExtensionApiEntity param,JSONObject hzyaExtData){
if (null != businessData){ if (null != businessData){
//物料主表
JSONObject formmain0227 = businessData.getJSONObject("formmain_0227"); JSONObject formmain0227 = businessData.getJSONObject("formmain_0227");
//物料明细表
JSONArray formson0228Arr = businessData.getJSONArray("formson_0228"); JSONArray formson0228Arr = businessData.getJSONArray("formson_0228");
//用来放物料明细表的id
List<SysExtensionApiEntity> sysExtensionList = new ArrayList<>();
for (int i=0; i< formson0228Arr.size(); i++){ for (int i=0; i< formson0228Arr.size(); i++){
SysExtensionApiEntity sysExtensionApiEntity = new SysExtensionApiEntity();
JSONObject formson0228 = formson0228Arr.getJSONObject(i); JSONObject formson0228 = formson0228Arr.getJSONObject(i);
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("Token", "Hzya1314_CheckSkip"); jsonObject.put("Token", "Hzya1314_CheckSkip");
@ -169,10 +202,17 @@ public class SeeyonExtServiceImpl implements ISeeyonExtService {
//todo 这个没值 //todo 这个没值
oArchives.put("cGroupCode", "01"); oArchives.put("cGroupCode", "01");
oArchives.put("cComUnitCode", formson0228.getString("field0006")); oArchives.put("cComUnitCode", formson0228.getString("field0006"));
jsonObject.put("oArchives", oArchives); jsonObject.put("oArchives", oArchives);
param.setBodys(JSON.toJSONString(jsonObject)); sysExtensionApiEntity.setBodys(JSON.toJSONString(jsonObject));
JSONObject hzyaExt = new JSONObject();
hzyaExt.put("billCode",formson0228.getString("id"));
hzyaExt.put("formsonId",formson0228.getString("id"));
Map<String,String> headers = new HashMap<>();
headers.put("hzyaExtData",JSONObject.toJSONString(hzyaExt));
sysExtensionApiEntity.setHeaders(headers);
sysExtensionList.add(sysExtensionApiEntity);
} }
param.setList(sysExtensionList);
} }
return param; return param;
} }
@ -210,7 +250,7 @@ public class SeeyonExtServiceImpl implements ISeeyonExtService {
//专管业务员 //专管业务员
oArchives.put("cVenPPerson",formmain0225.getString("field0016")); oArchives.put("cVenPPerson",formmain0225.getString("field0016"));
//分管部门 //分管部门
oArchives.put("cVenDepart","field0013"); oArchives.put("cVenDepart",formmain0225.getString("field0013"));
jsonObject.put("oArchives", oArchives); jsonObject.put("oArchives", oArchives);
param.setBodys(JSON.toJSONString(jsonObject)); param.setBodys(JSON.toJSONString(jsonObject));
hzyaExtData.put("billCode", formmain0225.getString("field0001")); hzyaExtData.put("billCode", formmain0225.getString("field0001"));