Browse Source

提交开源任务材料

10.0
LAPTOP-SB56SG4Q\86185 3 years ago
parent
commit
bde1328038
  1. BIN
      JSD-8802需求确认书.docx
  2. 5
      README.md
  3. BIN
      lib/finekit-10.0.jar
  4. 19
      plugin.xml
  5. 270
      src/main/java/com/fr/plugin/third/party/jsdiiac/BmpFlowUtils.java
  6. 615
      src/main/java/com/fr/plugin/third/party/jsdiiac/SqlUtils.java
  7. 192
      src/main/java/com/fr/plugin/third/party/jsdiiac/Utils.java
  8. 167
      src/main/java/com/fr/plugin/third/party/jsdiiac/config/CustomDataConfig.java
  9. 24
      src/main/java/com/fr/plugin/third/party/jsdiiac/config/DataConfigInitializeMonitor.java
  10. 13
      src/main/java/com/fr/plugin/third/party/jsdiiac/http/CustomHttpHandlerProvider.java
  11. 14
      src/main/java/com/fr/plugin/third/party/jsdiiac/http/CustomURLAliasProvider.java
  12. 364
      src/main/java/com/fr/plugin/third/party/jsdiiac/http/SendEsbMessageHttpHandler.java
  13. 90
      src/main/java/com/fr/plugin/third/party/jsdiiac/http/SessionGlobalRequestFilterProvider.java
  14. 46
      src/main/java/com/fr/plugin/third/party/jsdiiac/web/MainFilesComponent.java
  15. 19
      src/main/java/com/fr/plugin/third/party/jsdiiac/web/MainWebResourceProvider.java
  16. 16
      src/main/resources/com/fr/plugin/third/party/jsdiagb/web/main.js

BIN
JSD-8802需求确认书.docx

Binary file not shown.

5
README.md

@ -1,3 +1,6 @@
# open-JSD-8802
JSD-8802 BMP集成
JSD-8802 BMP集成\
免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\
仅作为开发者学习参考使用!禁止用于任何商业用途!\
为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系hugh处理。

BIN
lib/finekit-10.0.jar

Binary file not shown.

19
plugin.xml

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<plugin>
<id>com.fr.plugin.third.party.jsdiiac</id>
<name><![CDATA[BMP集成]]></name>
<active>yes</active>
<version>0.7</version>
<env-version>10.0</env-version>
<jartime>2019-01-01</jartime>
<vendor>fr.open</vendor>
<description><![CDATA[]]></description>
<change-notes><![CDATA[]]></change-notes>
<extra-decision>
<HttpHandlerProvider class="com.fr.plugin.third.party.jsdiiac.http.CustomHttpHandlerProvider"/>
<URLAliasProvider class="com.fr.plugin.third.party.jsdiiac.http.CustomURLAliasProvider"/>
<GlobalRequestFilterProvider class="com.fr.plugin.third.party.jsdiiac.http.SessionGlobalRequestFilterProvider"/>
</extra-decision>
<function-recorder class="com.fr.plugin.third.party.jsdiiac.config.DataConfigInitializeMonitor"/>
<lifecycle-monitor class="com.fr.plugin.third.party.jsdiiac.config.DataConfigInitializeMonitor"/>
</plugin>

270
src/main/java/com/fr/plugin/third/party/jsdiiac/BmpFlowUtils.java

@ -0,0 +1,270 @@
package com.fr.plugin.third.party.jsdiiac;
import com.fanruan.api.data.ConnectionKit;
import com.fanruan.api.data.TableDataKit;
import com.fanruan.api.log.LogKit;
import com.fanruan.api.util.StringKit;
import com.fr.base.ParameterMapNameSpace;
import com.fr.base.TableData;
import com.fr.general.data.DataModel;
import com.fr.general.data.TableDataException;
import com.fr.plugin.third.party.jsdiiac.config.CustomDataConfig;
import com.fr.script.Calculator;
import com.fr.stable.Primitive;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class BmpFlowUtils {
public static int getFlowDataMainRowCount(String dataId) throws TableDataException {
DataModel dataModel = getFlowDataMainDataModel(dataId);
if (dataModel == null) {
return 0;
}
int rowCount = dataModel.getRowCount();
if (rowCount <= 0) {
return 0;
}
return rowCount;
}
public static DataModel getFlowDataMainDataModel(String dataId) {
String tableDataName = CustomDataConfig.getInstance().getDataSetName();
DataModel dataModel = getDataDataModel(dataId, tableDataName);
return dataModel;
}
/**
* 获取流程ID
*
* @param dataId
* @return
* @throws TableDataException
*/
public static String getFlowId(String dataId) throws TableDataException {
DataModel dataModel = getFlowDataMainDataModel(dataId);
if (dataModel == null) {
return "";
}
int columnCount = dataModel.getColumnCount();
if (columnCount <= 0) {
return "";
}
int rowCount = dataModel.getRowCount();
if (rowCount <= 0) {
return "";
}
String value = getDataModelValueAt(dataModel, 0, 0);
return value;
}
/**
* 获取流程状态
*
* @param dataId
* @return
* @throws TableDataException
*/
public static String getFlowStatus(String dataId) throws TableDataException {
DataModel dataModel = getFlowDataMainDataModel(dataId);
if (dataModel == null) {
return "";
}
int columnCount = dataModel.getColumnCount();
if (columnCount <= 2) {
return "";
}
int rowCount = dataModel.getRowCount();
if (rowCount <= 0) {
return "";
}
String value = getDataModelValueAt(dataModel, 0, 2);
return value;
}
public static String getDataModelValueAt(DataModel dataModel, int row, int col) throws TableDataException {
Object value = dataModel.getValueAt(row, col);
if (value == null) {
return "";
}
if (value instanceof Primitive) {
return "";
}
String tempValue = String.valueOf(value);
return tempValue;
}
public static String getDataModelValueAt(DataModel dataModel, int row, String colName) throws TableDataException {
if ((dataModel == null) || (row <= -1) || (StringKit.isEmpty(colName))) {
return "";
}
colName = colName.toUpperCase();
int col = dataModel.getColumnIndex(colName);
if (col <= -1) {
return "";
}
Object value = dataModel.getValueAt(row, col);
if (value == null) {
return "";
}
if (value instanceof Primitive) {
return "";
}
String tempValue = String.valueOf(value);
return tempValue;
}
public static String createFlowId(String dataId) throws Exception {
String id = getUuid();
String sql = "update IT_BJB_IN_REGISTER_MAIN set id = '" + id + "'\n" +
"where BHID = '" + dataId + "'";
com.fr.data.impl.Connection dbConnect = ConnectionKit.getConnection(CustomDataConfig.getInstance().getDataConnection());
Connection connection = dbConnect.createConnection();
connection.setAutoCommit(true);
Statement pstmt = connection.createStatement();
pstmt.execute(sql);
pstmt.close();
connection.close();
return id;
}
/**
* 更新流程状态
*
* @param flowId
* @param status
* @return
* @throws Exception
*/
public static void updateFlowStatus(String flowId, String status) throws Exception {
String sql = "update IT_BJB_IN_REGISTER_MAIN set BPM_FLOW_STATUS = '" + status + "',\n" +
"BPM_STATUS_UPDATE_DATE= sysdate\n" +
"where ID = '" + flowId + "'";
com.fr.data.impl.Connection dbConnect = ConnectionKit.getConnection(CustomDataConfig.getInstance().getDataConnection());
Connection connection = dbConnect.createConnection();
connection.setAutoCommit(true);
Statement pstmt = connection.createStatement();
pstmt.execute(sql);
pstmt.close();
connection.close();
}
/**
* 更新流程状态
*
* @return
* @throws Exception
*/
public static void updateUpload(String batch_id,
String upload,
String boid,
String bpmurl) throws Exception {
String sql = "update dbo.RL_ZP_XQQD " +
"set date_time = '" + now() + "',\n" +
" upload = '" + upload + "',\n" +
" url = '" + bpmurl + "',\n" +
" strBOID = '" + boid + "'\n" +
"where batch_id = '" + batch_id + "'";
LogKit.info("BMP集成,更新SQL:\n" + sql);
com.fr.data.impl.Connection dbConnect = ConnectionKit.getConnection(CustomDataConfig.getInstance().getDataConnection());
Connection connection = dbConnect.createConnection();
connection.setAutoCommit(true);
Statement pstmt = connection.createStatement();
pstmt.execute(sql);
pstmt.close();
connection.close();
}
public static String now() {
SimpleDateFormat sdf = new SimpleDateFormat();
sdf.applyPattern("yyyy-MM-dd HH:mm:ss");
return sdf.format(new java.util.Date());
}
public static String getUuid() {
String uuid = UUID.randomUUID().toString().replace("-", "");
return uuid;
}
public synchronized static String getSysTime() {
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
Date date = new Date();
String nowData = format.format(date);
return nowData;
}
public synchronized static String getTimestamp() {
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmssSSS");
Date date = new Date();
String nowData = format.format(date);
return nowData;
}
public synchronized static String getRandomValue() {
int value = (int) (1 + Math.random() * (9999 - 1 + 1));
String tempValue = String.valueOf(value);
int len = tempValue.length();
String tempStr = tempValue;
if (len == 1) {
tempStr = "000" + tempValue;
} else if (len == 2) {
tempStr = "00" + tempValue;
} else if (len == 3) {
tempStr = "0" + tempValue;
}
return tempStr;
}
public static String getBizTransactionId() {
String tempValue = "HZBITB_E855_" + getTimestamp() + "_" + getRandomValue();
return tempValue;
}
public static DataModel getFlowDataDataModel(String dataId) {
String tableDataName = CustomDataConfig.getInstance().getDataSetName();
DataModel dataModel = getDataDataModel(dataId, tableDataName);
return dataModel;
}
public static DataModel getDataDataModel(String dataId, String dataSetName) {
if (StringKit.isEmpty(dataId) || StringKit.isEmpty(dataSetName)) {
return null;
}
TableData tableData = TableDataKit.findTableData(dataSetName);
if (tableData == null) {
return null;
}
Calculator cal = Calculator.createCalculator();
Map map = new HashMap();
map.put("P_BHID", dataId);
ParameterMapNameSpace space = ParameterMapNameSpace.create(map);
cal.pushNameSpace(space);
DataModel dataModel = tableData.createDataModel(cal);
return dataModel;
}
}

615
src/main/java/com/fr/plugin/third/party/jsdiiac/SqlUtils.java

@ -0,0 +1,615 @@
package com.fr.plugin.third.party.jsdiiac;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Random;
import java.util.UUID;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import com.fr.stable.StringUtils;
import com.fr.third.alibaba.druid.support.json.JSONUtils;
import com.fr.third.org.apache.http.auth.AuthScope;
import com.fr.third.org.apache.http.auth.UsernamePasswordCredentials;
import com.fr.third.org.apache.http.client.CredentialsProvider;
import com.fr.third.org.apache.http.client.methods.CloseableHttpResponse;
import com.fr.third.org.apache.http.client.methods.HttpPost;
import com.fr.third.org.apache.http.entity.StringEntity;
import com.fr.third.org.apache.http.impl.client.BasicCredentialsProvider;
import com.fr.third.org.apache.http.impl.client.CloseableHttpClient;
import com.fr.third.org.apache.http.impl.client.HttpClients;
import com.fr.third.org.apache.http.util.EntityUtils;
public class SqlUtils {
public static synchronized Connection getConn(HttpServletRequest request) throws RuntimeException {
Properties prop = new Properties();
try {
// 读取jdbc连接配置文件
prop.load(request.getServletContext().getResourceAsStream("/WEB-INF/db.properties"));
} catch (IOException e) {
throw new RuntimeException(e);
}
String driverClassName = prop.getProperty("jdbc.driverClassName");
String url = prop.getProperty("jdbc.url");
String username = prop.getProperty("jdbc.username");
String password = prop.getProperty("jdbc.password");
try {
Class.forName(driverClassName);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Connection conn;
try {
conn = DriverManager.getConnection(url, username, password);
conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
} catch (SQLException e) {
throw new RuntimeException(e);
}
return conn;
}
/**
* 更新状态为审批中
* @param connection
* @param xxzt 信息状态0数据入库1流程上传2流程回退,3流程结束
* @param strBOID 业务系统在接口传入的业务对象ID
* @param iProcInstID 该业务对象对应的创建的流程实例ID如果创建失败则该值无效置0
* @param bSuccess 表示创建流程实例是否成功1为成功0为创建失败
* @param procURL 返回的BPM流程URL
* @param strMessage BPM接口提供的信息反馈
* @return
* @throws SQLException
* @throws IOException
*/
public static int updateCreateResult(Connection connection,
String xxzt,
String strBOID,
String iProcInstID,
String bSuccess,
String procURL,
String strMessage
) throws SQLException, IOException {
PreparedStatement ptmt = null;
try {
Map<String, String> updateColumns = new HashMap<>();
updateColumns.put("date_time", now());
updateColumns.put("xxzt", xxzt);
updateColumns.put("iProcInstID", iProcInstID);
updateColumns.put("bSuccess", bSuccess);
updateColumns.put("procURL", procURL);
// updateColumns.put("strMessage", strMessage); // 表里无strMessage字段
ptmt = updateDynamically(connection, "dbo.RL_ZP_XQQD", "strBOID", strBOID, updateColumns);
int affect = ptmt.executeUpdate();
return affect;
} catch (SQLException e) {
throw e;
} finally {
close(null, ptmt, null);
}
}
/**
* 更新状态为退回
* @param connection
* @param xxzt 信息状态0数据入库1流程上传2流程回退,3流程结束
* @param strBOID 业务系统在接口传入的业务对象ID
* @param iProcInstID 该业务对象对应的创建的流程实例ID草稿步骤为0
* @param strStepName 审批时的步骤名称
* @param strApproverId 表示审批者用户ID
* @param eAction (审批过程中)退回发起人----2
* @param strComment 用户的审批意见备注
* @param dtTime 审批时间 yyyy-MM-dd hh:mm:ss
* @throws SQLException
* @throws IOException
*/
public static int updateRework(Connection connection,
String xxzt,
String strBOID,
String iProcInstID,
String strStepName,
String strApproverId,
String eAction,
String strComment,
String dtTime
) throws SQLException, IOException {
PreparedStatement ptmt = null;
try {
Map<String, String> updateColumns = new HashMap<>();
updateColumns.put("date_time", now());
updateColumns.put("xxzt", xxzt);
updateColumns.put("iProcInstID", iProcInstID);
updateColumns.put("strStepName", strStepName);
updateColumns.put("strApproverId", strApproverId);
updateColumns.put("eAction", eAction);
updateColumns.put("strComment", strComment);
updateColumns.put("dtTime", dtTime);
ptmt = updateDynamically(connection, "dbo.RL_ZP_XQQD", "strBOID", strBOID, updateColumns);
int affect = ptmt.executeUpdate();
return affect;
} catch (SQLException e) {
throw e;
} finally {
close(null, ptmt, null);
}
}
/**
* 更新状态为审批结束(通过作废)
* @param connection
* @param xxzt 信息状态0数据入库1流程上传2流程回退,3流程结束
* @param strBOID 业务系统在接口传入的业务对象ID
* @param iProcInstID 该业务对象对应的创建的流程实例ID
* @param eAction
* @param eProcessInstanceResult 1为审批通过2 为作废
* @param strComment 备注信息为BPM接口提供的信息反馈
* @param dtTime 审批时间 yyyy-MM-dd hh:mm:ss
* @throws SQLException
* @throws IOException
*/
public static int updateApproveClose(Connection connection,
String xxzt,
String strBOID,
String iProcInstID,
String eProcessInstanceResult,
String strComment,
String dtTime
) throws SQLException, IOException {
PreparedStatement ptmt = null;
try {
Map<String, String> updateColumns = new HashMap<>();
updateColumns.put("date_time", now());
updateColumns.put("end_time", now());
updateColumns.put("xxzt", xxzt);
updateColumns.put("eProcessInstanceResult", eProcessInstanceResult);
updateColumns.put("iProcInstID", iProcInstID);
updateColumns.put("dtTime", dtTime);
updateColumns.put("strComment", strComment);
ptmt = updateDynamically(connection, "dbo.RL_ZP_XQQD", "strBOID", strBOID, updateColumns);
int affect = ptmt.executeUpdate();
return affect;
} catch (SQLException e) {
throw e;
} finally {
close(null, ptmt, null);
}
}
/**
* 上传后设置状态
* @param connection
* @param batch_id
* @param upload
* @return
* @throws SQLException
* @throws IOException
*/
public static int updateUpload(Connection connection,
String batch_id,
String upload,
String boid,
String bpmurl
) throws SQLException, IOException {
PreparedStatement ptmt = null;
try {
Map<String, String> updateColumns = new HashMap<>();
updateColumns.put("date_time", now());
updateColumns.put("upload", upload);
updateColumns.put("strBOID", boid);
updateColumns.put("url", bpmurl);
ptmt = updateDynamically(connection, "dbo.RL_ZP_XQQD", "batch_id", batch_id, updateColumns);
int affect = ptmt.executeUpdate();
return affect;
} catch (SQLException e) {
throw e;
} finally {
close(null, ptmt, null);
}
}
public static synchronized void close(ResultSet rs, Statement ps, Connection connection) {
try {
if (rs != null) {
rs.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
try {
if (ps != null) {
ps.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
try {
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
public static String now() {
SimpleDateFormat sdf = new SimpleDateFormat();
sdf.applyPattern("yyyy-MM-dd HH:mm:ss");
return sdf.format(new java.util.Date());
}
public static String nowDate() {
SimpleDateFormat sdf = new SimpleDateFormat();
sdf.applyPattern("yyyyMMdd");
return sdf.format(new java.util.Date());
}
public static String nowContinuously() {
SimpleDateFormat sdf = new SimpleDateFormat();
sdf.applyPattern("yyyyMMddHHmmss");
return sdf.format(new java.util.Date());
}
/**
* 生成BIZTRANSACTIONID
* @param systemCode
* @return
*/
public static String getBIZTRANSACTIONID(String systemCode) {
SimpleDateFormat sdf = new SimpleDateFormat();
sdf.applyPattern("yyyyMMddHHmmssSSS");
String format = sdf.format(new java.util.Date());
String StringBase = "0123456789";
Random random = new Random();
StringBuilder sb = new StringBuilder(4);
for (int i = 0; i < 4; i++) {
sb.append(StringBase.charAt(random.nextInt(StringBase.length())));
}
String randomString = sb.toString();
return systemCode + "_" + format + "_" + randomString;
}
/**
* 根据sql查询表数据
* @param connection
* @param sql
* @return
* @throws SQLException
*/
public static List<Map<String, Object>> queryData(Connection connection, String sql) throws SQLException {
Statement ps = null;
ResultSet rs = null;
try {
ps = connection.createStatement();
rs = ps.executeQuery(sql);
ResultSetMetaData rsmd = rs.getMetaData();
int columnCount = rsmd.getColumnCount();
List<Map<String, Object>> list = new ArrayList<>();
while (rs.next()) {
Map<String, Object> row = new HashMap<>(columnCount);
for (int i = 0; i < columnCount; i++) {
Object columnVal = rs.getObject(i + 1);
if (columnVal instanceof java.sql.Clob) {
columnVal = rs.getString(i + 1);
}
String columnLabel = rsmd.getColumnLabel(i + 1);
row.put(columnLabel, columnVal);
}
list.add(row);
}
return list;
} catch (SQLException e) {
throw e;
} finally {
close(rs, ps, null);
}
}
/**
* 动态更新表字段
* @param connection
* @param tableName
* @param whereColumn
* @param whereValue
* @param updateColumns
* @return
* @throws SQLException
* @throws IOException
*/
public static PreparedStatement updateDynamically(Connection connection, String tableName, String whereColumn, String whereValue, Map<String, String> updateColumns ) throws SQLException, IOException {
String sqlBase = "update ${tableName} "
+ "set ${updateColumnList} "
+ "where ${whereColumn} = ? ";
Map<String, String> realUpdateColumns = updateColumns.entrySet().stream()
.filter(map -> StringUtils.isNotBlank(map.getValue()))
.collect(Collectors.toMap(map -> map.getKey(), map -> map.getValue()));
List<String> updateColumnList = new ArrayList<>(realUpdateColumns.keySet());
String joinColumnList = String.join(" , ", realUpdateColumns.keySet().stream().map(column -> column + " = ? ").collect(Collectors.toList()));
String replaceSql = sqlBase.replace("${tableName}", tableName).replace("${updateColumnList}", joinColumnList).replace("${whereColumn}", whereColumn);
PreparedStatement ptmt = connection.prepareStatement(replaceSql);
writeLogFile("replaceSql =======> " + replaceSql, SqlUtils.class);
for (int i = 0; i < updateColumnList.size(); i++) {
String value = updateColumns.get(updateColumnList.get(i));
ptmt.setString(i + 1, value);
writeLogFile(i + 1 + " ===> " + value, SqlUtils.class);
}
ptmt.setString(updateColumnList.size() + 1, whereValue);
return ptmt;
}
/**
* 根据key数组作为json解析层级节点
* @param o
* @param keyArr
* @return
*/
public static <T> T objToMap(Object o, String... keyArr) {
if (keyArr.length == 0) {
return (T) o;
} else {
Object childNode = ((Map<String, Object>) o).get(keyArr[0]);
return objToMap(childNode, Arrays.copyOfRange(keyArr, 1, keyArr.length));
}
}
public static void main(String[] args) throws IOException {
System.out.println(getBIZTRANSACTIONID("HBBITB_E902"));
System.exit(2);
System.out.println(nowContinuously());
writeLogFile("a啊", SqlUtils.class);
List<String> readLogFile = readLogFile();
System.out.println(readLogFile);
String url = "http://esbqas.sunac.com.cn:8001/WP_SUNAC/APP_PUBLIC_SERVICES/Proxy_Services/TA_BPM/PUBLIC_E902_WriteSAPXmlToBPM_PS";
String json = "{\r\n" +
" \"I_REQUEST\": {\r\n" +
" \"REQ_BASEINFO\": {\r\n" +
" \"REQ_SRC_SYS\": \"BS-HBBITB-D\",\r\n" +
" \"REQ_BSN_ID\": \"\",\r\n" +
" \"REQ_REPEAT_CYCLE\": \"\",\r\n" +
" \"REQ_RETRY_TIMES\": \"\",\r\n" +
" \"REQ_REPEAT_FLAG\": \"\",\r\n" +
" \"REQ_SEND_TIME\": \"20200916110927\",\r\n" +
" \"REQ_SYN_FLAG\": \"S\",\r\n" +
" \"COUNT\": \"1\",\r\n" +
" \"REQ_TAR_SYS\": \"BS-BPM-Q\",\r\n" +
" \"REQ_SERVER_NAME\": \"PUBLIC_E902_WriteSAPXmlToBPM\",\r\n" +
" \"REQ_TRACE_ID\": \"013c89e8-7a11-4633-8913-b64cc651a589\",\r\n" +
" \"BIZTRANSACTIONID\": \"HBBITB_E902_20200927132451000_0012\"\r\n" +
" },\r\n" +
" \"MESSAGE\": {\r\n" +
" \"REQ_ITEM\": {\r\n" +
" \"BTID\": \"FR_DM001_SelfBuyComputer\",\r\n" +
" \"BSID\": \"HZFR\",\r\n" +
" \"PROCINSTID\": \"0\",\r\n" +
" \"BOID\": \"11ca4821-04wq9-4ad5-bb08-ac8e241a0278112333a11as1145a11a\",\r\n" +
" \"USERID\": \"xiechen\",\r\n" +
" \"BSXML\": {\r\n" +
" \"DATA\": {\r\n" +
" \"BHID\": \"单据编号\",\r\n" +
" \"SUBMIT_TOPIC\": \"单据主题\",\r\n" +
" \"CITY\": \"城市公司\",\r\n" +
" \"SG_NUMBER\": \"申购条数\",\r\n" +
" \"AMOUNT\": \"11111\",\r\n" +
" \"BJBHD_URL\": \"附件汇总查询页面url\",\r\n" +
" \"SGD\": [\r\n" +
" {\r\n" +
" \"USER_NAME\": \"姓名\",\r\n" +
" \"USER_ID\": \"OA账号\",\r\n" +
" \"PROJECT\": \"项目/一级部门\",\r\n" +
" \"DEPARTMENT\": \"部门\",\r\n" +
" \"SUBMIT_DAY\": \"创建日期\",\r\n" +
" \"BRAND\": \"品牌\",\r\n" +
" \"MODEL\": \"电脑型号\",\r\n" +
" \"PRICE\": \"2222222\",\r\n" +
" \"PRICE_S\": \"33333333333\",\r\n" +
" \"SJ_PRICE\": \"44444444444\",\r\n" +
" \"CWGS\": \"费用承担公司\"\r\n" +
" }\r\n" +
" ]\r\n" +
" \r\n" +
" }\r\n" +
" }\r\n" +
" }\r\n" +
" }\r\n" +
" }\r\n" +
"}\r\n" +
"";
String postSendJson = postSendJson(null, json, url);
System.out.println(postSendJson);
}
/**
* 生成响应报文json
* @param RSP_REQ_TRACEID 请求消息 ID 值回传填写请求报文传过来的 UUID 值即可,即发送报文的 REQ_TRACE_ID 字段直接取值回传即可
* @param RSP_SRC_SYS 根据系统命名规范写入系统标识返回消息可以直接取值请求报文中的 REQ_TAR_SYS 字段
* @param RSP_TAR_SYS 根据系统命名规范写入系统标识返回消息可以直接取值请求报文中的 REQ_SRC_SYS 字段
* @param RSP_SERVER_NAME 方法名 ESB PO 顾问提供
* @param RSP_STATUS_CODE 2.5 接口响应码规范 RDFB 无异常S000 异常E0M0 M处理方内部出错 Y发送方报文有误无法处理
* @param RSP_STATUS_MSG 如处理失败填写具体失败原因
* @param BIZTRANSACTIONID 由调用接口服务的系统按照事务 ID 生成规则自行生成可以直接取值请求报文中的 BIZTRANSACTIONID字段
* @param code S000 成功 E0M0 失败
* @param RESULT 0成功 1失败
* @return
*/
public static String getReturnMessage(String RSP_REQ_TRACEID, String RSP_SRC_SYS, String RSP_TAR_SYS, String RSP_SERVER_NAME, String RSP_STATUS_CODE, String RSP_STATUS_MSG, String BIZTRANSACTIONID, String code, String ERRMESSAGE, String RESULT) {
/* String returnMessageBase = "{\r\n" +
"    \"E_RESPONSE\": {\r\n" +
"        \"RSP_BASEINFO\": {\r\n" +
"            \"RSP_TRACE_ID\": \"" + UUID.randomUUID().toString().replace("-", "") + "\",\r\n" +
"            \"RSP_REQ_TRACEID\": \"" + RSP_REQ_TRACEID + "\",\r\n" +
"            \"RSP_SEND_TIME\": " + SqlUtils.nowContinuously() + ",\r\n" +
"            \"RSP_SRC_SYS\": \"" + RSP_SRC_SYS + "\",\r\n" +
"            \"RSP_TAR_SYS\": \"" + RSP_TAR_SYS + "\",\r\n" +
"            \"RSP_SERVER_NAME\": \"" + RSP_SERVER_NAME + "\",\r\n" +
"            \"RSP_BSN_ID\": 0,\r\n" +
"            \"RSP_RETRY_TIMES\": 0,\r\n" +
"            \"RSP_STATUS_CODE\": \"" + RSP_STATUS_CODE + "\",\r\n" +
"            \"RSP_STATUS_MSG\": \"" + RSP_STATUS_MSG + "\",\r\n" +
"            \"BIZTRANSACTIONID\": \"" + BIZTRANSACTIONID + "\",\r\n" +
"            \"RESULT\": 0\r\n" +
"        },\r\n" +
"        \"MESSAGE\": {\r\n" +
"            \"RSP_ITEM\": {\r\n" +
"                \"CODE\": \"" + code + "\", \r\n" +
"                \"MESSAGE\": \"" + RSP_STATUS_MSG + "\"\r\n" +
"            }\r\n" +
"        }\r\n" +
"    }\r\n" +
"}";
*/
Map<String, Object> RSP_BASEINFO = new HashMap<>();
RSP_BASEINFO.put("RSP_TRACE_ID", UUID.randomUUID().toString().replace("-", ""));
RSP_BASEINFO.put("RSP_REQ_TRACEID", RSP_REQ_TRACEID);
RSP_BASEINFO.put("RSP_SEND_TIME", SqlUtils.nowContinuously());
RSP_BASEINFO.put("RSP_SRC_SYS", RSP_SRC_SYS);
RSP_BASEINFO.put("RSP_TAR_SYS", RSP_TAR_SYS);
RSP_BASEINFO.put("RSP_SERVER_NAME", RSP_SERVER_NAME);
RSP_BASEINFO.put("RSP_BSN_ID", 0);
RSP_BASEINFO.put("RSP_RETRY_TIMES", 0);
RSP_BASEINFO.put("RSP_STATUS_CODE", RSP_STATUS_CODE);
RSP_BASEINFO.put("RSP_STATUS_MSG", RSP_STATUS_MSG);
RSP_BASEINFO.put("BIZTRANSACTIONID", BIZTRANSACTIONID);
RSP_BASEINFO.put("RESULT", RESULT);
Map<String, Object> RSP_ITEM = new HashMap<>();
RSP_ITEM.put("CODE", code);
RSP_ITEM.put("MESSAGE", ERRMESSAGE);
Map<String, Object> MESSAGE = new HashMap<>();
MESSAGE.put("RSP_ITEM", RSP_ITEM);
Map<String, Object> E_RESPONSE = new HashMap<>();
E_RESPONSE.put("RSP_BASEINFO", RSP_BASEINFO);
E_RESPONSE.put("MESSAGE", MESSAGE);
Map<String, Object> result = new HashMap<>();
result.put("E_RESPONSE", E_RESPONSE);
return JSONUtils.toJSONString(result);
}
public static synchronized <T> void writeLogFile(String content, Class<T> clazz) throws IOException {
System.out.println(content);
try{
Files.createDirectory(Paths.get("esb_log"));
} catch (Exception e) {
}
Path curFile = Paths.get("esb_log/" + nowDate() + ".log");
String className = clazz.getSimpleName();
Files.write(curFile, (now() + "----" + className + "---" + content + "\n").getBytes("utf-8"), StandardOpenOption.CREATE, StandardOpenOption.APPEND);
}
public static synchronized List<String> readLogFile() throws IOException {
Path curFile = Paths.get("esb_log/" + nowDate() + ".log");
List<String> readAllLines = Files.readAllLines(curFile);
return readAllLines;
}
/**
* post调接口给esb发送数据
* @param request
* @param json
* @param url
* @return
* @throws IOException
*/
public static synchronized String postSendJson(HttpServletRequest request, String json, String url) throws IOException {
String user = "ESB_Q_PUBLIC";
String password = "publictest@esb";
Properties prop = new Properties();
try {
// 读取配置文件
prop.load(request.getServletContext().getResourceAsStream("/WEB-INF/db.properties"));
user = prop.getProperty("esb.username");
password = prop.getProperty("esb.password");
} catch (Throwable e) {
writeLogFile(e.getClass() + "==>" + e.getMessage(), SqlUtils.class);
}
// 创建用户信息
CredentialsProvider provider = new BasicCredentialsProvider();
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(user, password);
provider.setCredentials(AuthScope.ANY, credentials);
CloseableHttpClient client = null;
try {
client = HttpClients.custom().setDefaultCredentialsProvider(provider).build();
HttpPost post = new HttpPost(url);
post.setHeader("Content-Type", "application/json;charset=UTF-8");
writeLogFile("发送数据:" + json, SqlUtils.class);
StringEntity se = new StringEntity(json, "utf-8");
se.setContentEncoding("UTF-8");
se.setContentType("application/json");
post.setEntity(se);
CloseableHttpResponse response = client.execute(post);
writeLogFile("接口返回状态码:" + response.getStatusLine().getStatusCode(), SqlUtils.class);
if (response.getStatusLine().getStatusCode() < 200 || response.getStatusLine().getStatusCode() >= 400) {
throw new RuntimeException("接口返回状态码错误");
}
String resData = EntityUtils.toString(response.getEntity());
writeLogFile("接口返回:" + resData, SqlUtils.class);
client.close();
return resData;
} catch (Throwable e) {
writeLogFile("调接口异常:" + e, SqlUtils.class);
throw e;
} finally {
client.close();
}
}
}

192
src/main/java/com/fr/plugin/third/party/jsdiiac/Utils.java

@ -0,0 +1,192 @@
package com.fr.plugin.third.party.jsdiiac;
import com.fanruan.api.log.LogKit;
import com.fanruan.api.util.StringKit;
import com.fr.general.IOUtils;
import com.fr.third.org.apache.http.HttpEntity;
import com.fr.third.org.apache.http.HttpStatus;
import com.fr.third.org.apache.http.client.config.RequestConfig;
import com.fr.third.org.apache.http.client.methods.CloseableHttpResponse;
import com.fr.third.org.apache.http.client.methods.HttpGet;
import com.fr.third.org.apache.http.client.methods.HttpPost;
import com.fr.third.org.apache.http.conn.ssl.NoopHostnameVerifier;
import com.fr.third.org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import com.fr.third.org.apache.http.entity.StringEntity;
import com.fr.third.org.apache.http.impl.client.CloseableHttpClient;
import com.fr.third.org.apache.http.impl.client.HttpClients;
import com.fr.third.org.apache.http.ssl.SSLContextBuilder;
import com.fr.third.org.apache.http.ssl.TrustStrategy;
import com.fr.third.org.apache.http.util.EntityUtils;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
public class Utils {
/**
* 获取请求主体内容
* @param req
* @return
* @throws IOException
*/
public static String getHttpRequestBody(HttpServletRequest req) throws IOException {
if (req == null) {
return "";
}
ServletInputStream inputStream = req.getInputStream();
if (inputStream == null) {
return "";
}
String content = IOUtils.inputStream2String(inputStream);
if (StringKit.isEmpty(content)) {
return "";
}
return content;
}
public static String DEFAULT_USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36";
public static RequestConfig REQUEST_CONFIG = RequestConfig.custom()
.setConnectionRequestTimeout(30000)
.setSocketTimeout(30000) // 服务端相应超时
.setConnectTimeout(30000) // 建立socket链接超时时间
.build();
public static CloseableHttpClient createSSLClientDefault() {
try {
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
@Override
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
return true;
}
}).build();
HostnameVerifier hostnameVerifier = NoopHostnameVerifier.INSTANCE;
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
return HttpClients.custom().setSSLSocketFactory(sslsf).build();
} catch (Exception e) {
LogKit.error(e.getMessage(), e);
}
return HttpClients.createDefault();
}
public static synchronized CloseableHttpClient createHttpClient(String url) {
CloseableHttpClient httpClient = null;
if (StringKit.isEmpty(url)) {
httpClient = HttpClients.createDefault();
return httpClient;
}
if (url.startsWith("https://")) {
httpClient = createSSLClientDefault();
return httpClient;
}
httpClient = HttpClients.createDefault();
return httpClient;
}
public static synchronized String createHttpGetContent(CloseableHttpClient httpClient, String url) throws IOException {
if ((httpClient == null) || (StringKit.isEmpty(url))) {
return "";
}
HttpGet httpGet = new HttpGet(url);
httpGet.addHeader("User-Agent", Utils.DEFAULT_USER_AGENT);
httpGet.setConfig(Utils.REQUEST_CONFIG);
CloseableHttpResponse response = httpClient.execute(httpGet);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
response.close();
LogKit.info("http请求出错,http status:" + statusCode);
return "";
}
HttpEntity httpEntity = response.getEntity();
if (httpEntity == null) {
response.close();
LogKit.info("http请求出错,http响应内容为空");
return "";
}
String responseContent = EntityUtils.toString(httpEntity, "UTF-8");
response.close();
if (StringKit.isEmpty(responseContent)) {
LogKit.info("http请求出错,http响应内容为空1");
return "";
}
return responseContent;
}
public static synchronized String createHttpPostContent(CloseableHttpClient httpClient, String url, String bodyContent) throws IOException {
if ((httpClient == null) || (StringKit.isEmpty(url)) || (StringKit.isEmpty(bodyContent))) {
return "";
}
HttpPost httpPost = new HttpPost(url);
httpPost.addHeader("User-Agent", Utils.DEFAULT_USER_AGENT);
httpPost.setConfig(Utils.REQUEST_CONFIG);
StringEntity bodyEntity = new StringEntity(bodyContent, "UTF-8");
httpPost.setEntity(bodyEntity);
CloseableHttpResponse response = httpClient.execute(httpPost);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
response.close();
LogKit.info("http请求出错,http status:" + statusCode);
return "";
}
HttpEntity httpEntity = response.getEntity();
if (httpEntity == null) {
response.close();
LogKit.info("http请求出错,http响应内容为空");
return "";
}
String responseContent = EntityUtils.toString(httpEntity, "UTF-8");
response.close();
if (StringKit.isEmpty(responseContent)) {
LogKit.info("http请求出错,http响应内容为空1");
return "";
}
return responseContent;
}
/**
* 重定向
* @param res
* @param url
*/
public static void sendRedirect(HttpServletResponse res, String url) {
if ((res == null) || (StringKit.isEmpty(url))) {
return;
}
res.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
res.setHeader("Location", url);
}
/**
* 获取完整请求链接
*
* @param req 请求
* @return
*/
public static String getFullRequestUrl(HttpServletRequest req) {
if (req == null) {
return "";
}
String url = req.getRequestURL().toString();
String queryUrl = req.getQueryString();
if ((queryUrl == null) || "null".equalsIgnoreCase(queryUrl)) {
queryUrl = "";
} else {
queryUrl = "?" + queryUrl;
}
String fullUrl = url + queryUrl;
return fullUrl;
}
}

167
src/main/java/com/fr/plugin/third/party/jsdiiac/config/CustomDataConfig.java

@ -0,0 +1,167 @@
package com.fr.plugin.third.party.jsdiiac.config;
import com.fr.config.*;
import com.fr.config.holder.Conf;
import com.fr.config.holder.factory.Holders;
import java.util.concurrent.ConcurrentHashMap;
/**
* 配置数据保存
*/
@Visualization(category = "BMP集成配置")
public class CustomDataConfig extends DefaultConfiguration {
public String getNameSpace() {
return this.getClass().getName();
}
private static volatile CustomDataConfig config = null;
public static CustomDataConfig getInstance() {
if (config == null) {
config = ConfigContext.getConfigInstance(CustomDataConfig.class);
}
return config;
}
@Identifier(value = "esbUrl", name = "ESB发送链接", description = "", status = Status.SHOW)
private Conf<String> esbUrl = Holders.simple("");
@Identifier(value = "reqSrcSys", name = "发送方系统标识(REQ_SRC_SYS)", description = "", status = Status.SHOW)
private Conf<String> reqSrcSys = Holders.simple("");
@Identifier(value = "reqTarSys", name = "接收方系统标识(REQ_TAR_SYS)", description = "", status = Status.SHOW)
private Conf<String> reqTarSys = Holders.simple("");
@Identifier(value = "reqServerName", name = "服务方名称(REQ_SERVER_NAME)", description = "", status = Status.SHOW)
private Conf<String> reqServerName = Holders.simple("");
@Identifier(value = "esbUsername", name = "ESB用户名", description = "", status = Status.SHOW)
private Conf<String> esbUsername = Holders.simple("");
@Identifier(value = "esbPassword", name = "ESB密码", description = "", status = Status.SHOW)
private Conf<String> esbPassword = Holders.simple("");
@Identifier(value = "dataConnection", name = "数据库连接名称", description = "", status = Status.SHOW)
private Conf<String> dataConnection = Holders.simple("");
@Identifier(value = "dataSetName", name = "内容数据集名称", description = "", status = Status.SHOW)
private Conf<String> dataSetName = Holders.simple("");
@Identifier(value = "bmpUrl", name = "BMP服务器地址", description = "", status = Status.SHOW)
private Conf<String> bmpUrl = Holders.simple("");
@Identifier(value = "frUrl", name = "报表平台地址", description = "", status = Status.SHOW)
private Conf<String> frUrl = Holders.simple("");
@Identifier(value = "bmpFrUrl", name = "BMP跳转报表地址", description = "", status = Status.SHOW)
private Conf<String> bmpFrUrl = Holders.simple("");
public String getFrUrl() {
return frUrl.get();
}
public void setFrUrl(String frUrl) {
this.frUrl.set(frUrl);
}
public String getBmpFrUrl() {
return bmpFrUrl.get();
}
public void setBmpFrUrl(String bmpFrUrl) {
this.bmpFrUrl.set(bmpFrUrl);
}
public String getBmpUrl() {
return bmpUrl.get();
}
public void setBmpUrl(String bmpUrl) {
this.bmpUrl.set(bmpUrl);
}
public String getEsbUrl() {
return esbUrl.get();
}
public void setEsbUrl(String esbUrl) {
this.esbUrl.set(esbUrl);
}
public String getReqSrcSys() {
return reqSrcSys.get();
}
public void setReqSrcSys(String reqSrcSys) {
this.reqSrcSys.set(reqSrcSys);
}
public String getReqTarSys() {
return reqTarSys.get();
}
public void setReqTarSys(String reqTarSys) {
this.reqTarSys.set(reqTarSys);
}
public String getReqServerName() {
return reqServerName.get();
}
public void setReqServerName(String reqServerName) {
this.reqServerName.set(reqServerName);
}
public String getEsbUsername() {
return esbUsername.get();
}
public void setEsbUsername(String esbUsername) {
this.esbUsername.set(esbUsername);
}
public String getEsbPassword() {
return esbPassword.get();
}
public void setEsbPassword(String esbPassword) {
this.esbPassword.set(esbPassword);
}
public String getDataConnection() {
return dataConnection.get();
}
public void setDataConnection(String dataConnection) {
this.dataConnection.set(dataConnection);
}
public String getDataSetName() {
return dataSetName.get();
}
public void setDataSetName(String dataSetName) {
this.dataSetName.set(dataSetName);
}
@Override
public Object clone() throws CloneNotSupportedException {
CustomDataConfig cloned = (CustomDataConfig) super.clone();
cloned.esbUrl = (Conf<String>) esbUrl.clone();
cloned.reqSrcSys = (Conf<String>) reqSrcSys.clone();
cloned.reqTarSys = (Conf<String>) reqTarSys.clone();
cloned.reqServerName = (Conf<String>) reqServerName.clone();
cloned.esbUsername = (Conf<String>) esbUsername.clone();
cloned.esbPassword = (Conf<String>) esbPassword.clone();
cloned.dataConnection = (Conf<String>) dataConnection.clone();
cloned.dataSetName = (Conf<String>) dataSetName.clone();
cloned.bmpUrl = (Conf<String>) bmpUrl.clone();
return cloned;
}
}

24
src/main/java/com/fr/plugin/third/party/jsdiiac/config/DataConfigInitializeMonitor.java

@ -0,0 +1,24 @@
package com.fr.plugin.third.party.jsdiiac.config;
import com.fr.intelli.record.Focus;
import com.fr.intelli.record.Original;
import com.fr.plugin.context.PluginContext;
import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor;
import com.fr.record.analyzer.EnableMetrics;
/**
* 配置信息初始化
*/
@EnableMetrics
public class DataConfigInitializeMonitor extends AbstractPluginLifecycleMonitor {
@Override
@Focus(id = "com.fr.plugin.third.party.jsdiiac", text = "plugin-jsdiiac", source = Original.PLUGIN)
public void afterRun(PluginContext pluginContext) {
CustomDataConfig.getInstance();
}
@Override
public void beforeStop(PluginContext pluginContext) {
}
}

13
src/main/java/com/fr/plugin/third/party/jsdiiac/http/CustomHttpHandlerProvider.java

@ -0,0 +1,13 @@
package com.fr.plugin.third.party.jsdiiac.http;
import com.fr.decision.fun.impl.AbstractHttpHandlerProvider;
import com.fr.decision.fun.impl.BaseHttpHandler;
public class CustomHttpHandlerProvider extends AbstractHttpHandlerProvider {
@Override
public BaseHttpHandler[] registerHandlers() {
return new BaseHttpHandler[]{
new SendEsbMessageHttpHandler()
};
}
}

14
src/main/java/com/fr/plugin/third/party/jsdiiac/http/CustomURLAliasProvider.java

@ -0,0 +1,14 @@
package com.fr.plugin.third.party.jsdiiac.http;
import com.fr.decision.fun.impl.AbstractURLAliasProvider;
import com.fr.decision.webservice.url.alias.URLAlias;
import com.fr.decision.webservice.url.alias.URLAliasFactory;
public class CustomURLAliasProvider extends AbstractURLAliasProvider {
@Override
public URLAlias[] registerAlias() {
return new URLAlias[]{
URLAliasFactory.createPluginAlias("/jsdiiac/sendesbmessage", "/jsdiiac/sendesbmessage", true)
};
}
}

364
src/main/java/com/fr/plugin/third/party/jsdiiac/http/SendEsbMessageHttpHandler.java

@ -0,0 +1,364 @@
package com.fr.plugin.third.party.jsdiiac.http;
import com.fanruan.api.log.LogKit;
import com.fanruan.api.util.StringKit;
import com.fr.decision.fun.impl.BaseHttpHandler;
import com.fr.general.data.DataModel;
import com.fr.json.JSONObject;
import com.fr.plugin.third.party.jsdiiac.BmpFlowUtils;
import com.fr.plugin.third.party.jsdiiac.SqlUtils;
import com.fr.plugin.third.party.jsdiiac.Utils;
import com.fr.plugin.third.party.jsdiiac.config.CustomDataConfig;
import com.fr.third.alibaba.druid.support.json.JSONUtils;
import com.fr.third.alibaba.druid.util.StringUtils;
import com.fr.third.org.apache.http.auth.AuthScope;
import com.fr.third.org.apache.http.auth.UsernamePasswordCredentials;
import com.fr.third.org.apache.http.client.CredentialsProvider;
import com.fr.third.org.apache.http.client.methods.CloseableHttpResponse;
import com.fr.third.org.apache.http.client.methods.HttpPost;
import com.fr.third.org.apache.http.entity.StringEntity;
import com.fr.third.org.apache.http.impl.client.BasicCredentialsProvider;
import com.fr.third.org.apache.http.impl.client.CloseableHttpClient;
import com.fr.third.org.apache.http.impl.client.HttpClients;
import com.fr.third.org.apache.http.util.EntityUtils;
import com.fr.third.springframework.web.bind.annotation.RequestMethod;
import com.fr.web.utils.WebUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/**
*
*/
public class SendEsbMessageHttpHandler extends BaseHttpHandler {
@Override
public RequestMethod getMethod() {
return RequestMethod.POST;
}
@Override
public String getPath() {
return "/jsdiiac/sendesbmessage";
}
@Override
public boolean isPublic() {
return true;
}
@Override
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception {
res.setContentType("application/json; charset=utf-8");
String reqContent = Utils.getHttpRequestBody(req);
reqContent = StringKit.trim(reqContent);
if (StringKit.isEmpty(reqContent)) {
WebUtils.printAsString(res, "batch_id不能为空");
}
JSONObject reqJson = new JSONObject(reqContent);
String batchId = reqJson.getString("batch_id");
if (StringKit.isEmpty(batchId)) {
WebUtils.printAsString(res, "batch_id不能为空1");
}
LogKit.info("BMP集成,batch_id:" + batchId);
String BTID = "recruit_code";
String BSID = "HBFR";
DataModel dataModel = BmpFlowUtils.getFlowDataDataModel(batchId);
if (dataModel == null) {
LogKit.error("BPM流程业务数据提交,获取数据为空");
return;
}
int columnCount = dataModel.getColumnCount();
if (columnCount <= 0) {
LogKit.error("BPM流程业务数据提交,获取数据为空1");
return;
}
String xxzt = BmpFlowUtils.getDataModelValueAt(dataModel, 0, "XXZT");
String iProcInstID = BmpFlowUtils.getDataModelValueAt(dataModel, 0, "IPROCINSTID");
String strBOID = BmpFlowUtils.getDataModelValueAt(dataModel, 0, "IPROCINSTID");
String boid = "";
if (StringUtils.isEmpty(strBOID)) {
boid = UUID.randomUUID().toString();
LogKit.info("BPM流程业务数据提交,生成新的boid:" + boid);
} else {
boid = strBOID;
LogKit.info("BPM流程业务数据提交,使用旧的boid: " + boid);
}
String rzzz = BmpFlowUtils.getDataModelValueAt(dataModel, 0, "rzzz");
String zgs = BmpFlowUtils.getDataModelValueAt(dataModel, 0, "zgs");
String bzs = BmpFlowUtils.getDataModelValueAt(dataModel, 0, "bzs");
String zts = BmpFlowUtils.getDataModelValueAt(dataModel, 0, "zts");
String zw = BmpFlowUtils.getDataModelValueAt(dataModel, 0, "zw");
String zprs = BmpFlowUtils.getDataModelValueAt(dataModel, 0, "zprs");
String yxzj = BmpFlowUtils.getDataModelValueAt(dataModel, 0, "yxzj");
String tx = BmpFlowUtils.getDataModelValueAt(dataModel, 0, "tx");
String jj = BmpFlowUtils.getDataModelValueAt(dataModel, 0, "jj");
String dg_date = BmpFlowUtils.getDataModelValueAt(dataModel, 0, "dg_date");
String zdxl = BmpFlowUtils.getDataModelValueAt(dataModel, 0, "zdxl");
String sfgjg = BmpFlowUtils.getDataModelValueAt(dataModel, 0, "sfgjg");
String gjgwlx = BmpFlowUtils.getDataModelValueAt(dataModel, 0, "gjgwlx");
String xb = BmpFlowUtils.getDataModelValueAt(dataModel, 0, "xb");
String yxfy = BmpFlowUtils.getDataModelValueAt(dataModel, 0, "yxfy");
String zgnl = BmpFlowUtils.getDataModelValueAt(dataModel, 0, "zgnl");
String zwms = BmpFlowUtils.getDataModelValueAt(dataModel, 0, "zwms");
String gzzz = BmpFlowUtils.getDataModelValueAt(dataModel, 0, "gzzz");
String zryq = BmpFlowUtils.getDataModelValueAt(dataModel, 0, "zryq");
String gzdd = BmpFlowUtils.getDataModelValueAt(dataModel, 0, "gzdd");
String sfcb = BmpFlowUtils.getDataModelValueAt(dataModel, 0, "sfcb");
String fsubject = BmpFlowUtils.getDataModelValueAt(dataModel, 0, "fsubject");
String applicantname = BmpFlowUtils.getDataModelValueAt(dataModel, 0, "applicantname");
String applyorg = BmpFlowUtils.getDataModelValueAt(dataModel, 0, "applyorg");
String applydept = BmpFlowUtils.getDataModelValueAt(dataModel, 0, "applydept");
String applypost = BmpFlowUtils.getDataModelValueAt(dataModel, 0, "applypost");
String switchorg = BmpFlowUtils.getDataModelValueAt(dataModel, 0, "switchorg");
String create_time = BmpFlowUtils.getDataModelValueAt(dataModel, 0, "create_time");
String zaizhi_url = BmpFlowUtils.getDataModelValueAt(dataModel, 0, "zaizhi_url");
if (StringKit.isNotEmpty(zaizhi_url)) {
zaizhi_url = CustomDataConfig.getInstance().getFrUrl() + "?bmpFrUrlValue=" + zaizhi_url;
}
String cbrs = BmpFlowUtils.getDataModelValueAt(dataModel, 0, "cbrs");
String zpsy = BmpFlowUtils.getDataModelValueAt(dataModel, 0, "zpsy");
String zpsysm = BmpFlowUtils.getDataModelValueAt(dataModel, 0, "zpsysm");
String reqSrcSys = CustomDataConfig.getInstance().getReqSrcSys();
String reqTarSys = CustomDataConfig.getInstance().getReqTarSys();
String reqServerName = CustomDataConfig.getInstance().getReqServerName();
String sendEsbMessage = getSendEsbMessage(iProcInstID, boid, reqSrcSys, reqTarSys, reqServerName, batchId, rzzz, zgs, bzs, zts, zw, zprs, yxzj, tx, jj, dg_date, zdxl, sfgjg, gjgwlx, xb, yxfy, zgnl, zwms, gzzz, zryq, gzdd, sfcb,
fsubject, applicantname, applyorg, applydept, applypost, switchorg, create_time, zaizhi_url, cbrs, zpsy, zpsysm);
String returnMessage = "";
String esbUrl = CustomDataConfig.getInstance().getEsbUrl();
String esbReturnMessage = sendJson(sendEsbMessage, esbUrl);
if (StringKit.isEmpty(esbReturnMessage)) {
returnMessage = getSimpleReturnMessage(BTID, BSID, "500", "", "");
WebUtils.printAsString(res, returnMessage);
return;
}
Object esbReturnMessageObj = JSONUtils.parse(esbReturnMessage);
Map<String, String> esbReturnData = parseJsonMessage(esbReturnMessageObj);
if ("0".equals(esbReturnData.get("RESULT"))) {
// 拼出bpmurl入库,防止页面关闭无法找回
String bpmurl_server = CustomDataConfig.getInstance().getBmpUrl();
String bpmurl = bpmurl_server + "?BSID=" + BSID + "&BTID=" + BTID + "&BOID=" + boid;
BmpFlowUtils.updateUpload(batchId, "1", boid, bpmurl);
returnMessage = getSimpleReturnMessage(BTID, BSID, "200", "发送esb成功", boid);
} else {
returnMessage = getSimpleReturnMessage(BTID, BSID, "500", "", "");
}
LogKit.info("BMP集成," + returnMessage);
WebUtils.printAsString(res, returnMessage);
}
public static Map<String, String> parseJsonMessage(Object o) {
Map<String, String> result = new HashMap<>();
result.put("RESULT", SqlUtils.<String>objToMap(o, "E_RESPONSE", "RSP_BASEINFO", "RESULT"));
result.put("RSP_STATUS_CODE", SqlUtils.<String>objToMap(o, "E_RESPONSE", "RSP_BASEINFO", "RSP_STATUS_CODE"));
result.put("RSP_STATUS_MSG", SqlUtils.<String>objToMap(o, "E_RESPONSE", "RSP_BASEINFO", "RSP_STATUS_MSG"));
result.put("STATUSCODE", SqlUtils.<String>objToMap(o, "E_RESPONSE", "MESSAGE", "RSP_ITEM", "PI_RES_DATA", "STATUSCODE"));
result.put("STATUSMESSAGE", SqlUtils.<String>objToMap(o, "E_RESPONSE", "MESSAGE", "RSP_ITEM", "PI_RES_DATA", "STATUSMESSAGE"));
return result;
}
/**
* post调接口给esb发送数据
*
* @param json
* @param url
* @return
* @throws IOException
*/
public static synchronized String sendJson(String json, String url) throws IOException {
String user = "ESB_Q_PUBLIC";
String password = "publictest@esb";
user = CustomDataConfig.getInstance().getEsbUsername();
password = CustomDataConfig.getInstance().getEsbPassword();
// 创建用户信息
CredentialsProvider provider = new BasicCredentialsProvider();
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(user, password);
provider.setCredentials(AuthScope.ANY, credentials);
CloseableHttpClient client = null;
LogKit.info("BMP集成,请求BMP地址:" + url);
LogKit.info("BMP集成,ESB验证用户名:" + user + ",密码:" + password);
client = HttpClients.custom().setDefaultCredentialsProvider(provider).build();
HttpPost httpPost = new HttpPost(url);
/*
String authorizationStr = user + ":" + password;
String authorizationBase64 = new String(Base64.getEncoder().encode(authorizationStr.getBytes()));
httpPost.addHeader("Authorization", "Basic " + authorizationBase64);*/
httpPost.setHeader("Content-Type", "application/json;charset=UTF-8");
LogKit.info("BMP集成,发送数据:\n" + json);
StringEntity se = new StringEntity(json, "utf-8");
se.setContentEncoding("UTF-8");
se.setContentType("application/json");
httpPost.setEntity(se);
CloseableHttpResponse response = client.execute(httpPost);
LogKit.info("BMP集成,接口返回状态码:" + response.getStatusLine().getStatusCode());
if (response.getStatusLine().getStatusCode() != 200) {
LogKit.info("BMP集成,接口返回状态码错误");
client.close();
return "";
}
String resData = EntityUtils.toString(response.getEntity());
LogKit.info("BMP集成,接口返回:\n" + resData);
client.close();
return resData;
}
public static String getSendEsbMessage(String iProcInstID, String boid, String REQ_SRC_SYS, String REQ_TAR_SYS, String REQ_SERVER_NAME
, String batch_id
, String rzzz
, String zgs
, String bzs
, String zts
, String zw
, String zprs
, String yxzj
, String tx
, String jj
, String dg_date
, String zdxl
, String sfgjg
, String gjgwlx
, String xb
, String yxfy
, String zgnl
, String zwms
, String gzzz
, String zryq
, String gzdd
, String sfcb
, String FSubject
, String APPLICANTNAME
, String APPLYORG
, String APPLYDEPT
, String APPLYPOST
, String SWITCHORG
, String APPLYDATETIME
, String zaizhi_url
, String cbrs
, String zpsy
, String zpsysm
) {
Map<String, Object> REQ_BASEINFO = new HashMap<>();
REQ_BASEINFO.put("REQ_TRACE_ID", UUID.randomUUID().toString().replace("-", ""));
REQ_BASEINFO.put("REQ_SEND_TIME", SqlUtils.nowContinuously());
REQ_BASEINFO.put("REQ_SRC_SYS", REQ_SRC_SYS);
REQ_BASEINFO.put("REQ_TAR_SYS", REQ_TAR_SYS);
REQ_BASEINFO.put("REQ_SERVER_NAME", REQ_SERVER_NAME);
REQ_BASEINFO.put("REQ_SYN_FLAG", "S");
REQ_BASEINFO.put("BIZTRANSACTIONID", SqlUtils.getBIZTRANSACTIONID("HBBITB_E902")); // 接口编号,可能需要改
REQ_BASEINFO.put("REQ_SERVER_NAME", REQ_SERVER_NAME);
REQ_BASEINFO.put("REQ_BSN_ID", "");
REQ_BASEINFO.put("REQ_RETRY_TIMES", "");
REQ_BASEINFO.put("REQ_REPEAT_FLAG", "");
REQ_BASEINFO.put("REQ_REPEAT_CYCLE", "");
REQ_BASEINFO.put("COUNT", "1");
Map<String, Object> DATA = new HashMap<>();
DATA.put("batch_id", batch_id);
DATA.put("rzzz", rzzz);
DATA.put("zgs", zgs);
DATA.put("bzs", bzs);
DATA.put("zts", zts);
DATA.put("zw", zw);
DATA.put("zprs", zprs);
DATA.put("yxzj", yxzj);
DATA.put("tx", tx);
DATA.put("jj", jj);
DATA.put("dg_date", dg_date);
DATA.put("zdxl", zdxl);
DATA.put("sfgjg", sfgjg);
DATA.put("gjgwlx", gjgwlx);
DATA.put("xb", xb);
DATA.put("yxfy", yxfy);
DATA.put("zgnl", zgnl);
DATA.put("zwms", zwms);
DATA.put("gzzz", gzzz);
DATA.put("zryq", zryq);
DATA.put("gzdd", gzdd);
DATA.put("sfcb", sfcb);
DATA.put("zaizhi_url", zaizhi_url);
DATA.put("cbrs", cbrs);
DATA.put("zpsy", zpsy);
DATA.put("zpsysm", zpsysm);
DATA.put("FSubject", FSubject);
DATA.put("APPLICANTNAME", APPLICANTNAME);
DATA.put("APPLYORG", APPLYORG);
DATA.put("APPLYDEPT", APPLYDEPT);
DATA.put("APPLYPOST", APPLYPOST);
DATA.put("SWITCHORG", SWITCHORG);
DATA.put("APPLYDATETIME", APPLYDATETIME);
Map<String, Object> BSXML = new HashMap<>();
BSXML.put("DATA", DATA);
Map<String, Object> REQ_ITEM = new HashMap<>();
REQ_ITEM.put("BSXML", BSXML);
// 暂为固定值,可能要改
REQ_ITEM.put("BTID", "recruit_code");
REQ_ITEM.put("BSID", "HBFR");
REQ_ITEM.put("PROCINSTID", iProcInstID);
REQ_ITEM.put("BOID", boid);
REQ_ITEM.put("USERID", "xiechen");
Map<String, Object> MESSAGE = new HashMap<>();
MESSAGE.put("REQ_ITEM", REQ_ITEM);
Map<String, Object> I_REQUEST = new HashMap<>();
I_REQUEST.put("REQ_BASEINFO", REQ_BASEINFO);
I_REQUEST.put("MESSAGE", MESSAGE);
Map<String, Object> result = new HashMap<>();
result.put("I_REQUEST", I_REQUEST);
return JSONUtils.toJSONString(result);
}
/**
* 获取简单返回json
*
* @param code
* @param message
* @return
*/
public static String getSimpleReturnMessage(String BTID, String BSID, String code, String message, String boid) {
Map<String, Object> a = new HashMap<>();
a.put("code", code);
a.put("message", message);
a.put("BOID", boid);
a.put("BTID", BTID);
a.put("BSID", BSID);
return JSONUtils.toJSONString(a);
}
}

90
src/main/java/com/fr/plugin/third/party/jsdiiac/http/SessionGlobalRequestFilterProvider.java

@ -0,0 +1,90 @@
package com.fr.plugin.third.party.jsdiiac.http;
import com.fanruan.api.log.LogKit;
import com.fanruan.api.util.StringKit;
import com.fr.decision.fun.impl.AbstractGlobalRequestFilterProvider;
import com.fr.plugin.context.PluginContexts;
import com.fr.plugin.third.party.jsdiiac.Utils;
import com.fr.plugin.third.party.jsdiiac.config.CustomDataConfig;
import com.fr.third.springframework.web.util.UriUtils;
import com.fr.web.utils.WebUtils;
import javax.servlet.FilterChain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class SessionGlobalRequestFilterProvider extends AbstractGlobalRequestFilterProvider {
private static String DEFAULT_USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36";
@Override
public String filterName() {
return "com.fr.plugin.third.party.jsdiiac";
}
@Override
public String[] urlPatterns() {
return new String[]{"/decision", "/decision/*"};
}
@Override
public void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain filterChain) {
try {
if (!PluginContexts.currentContext().isAvailable()) {
LogKit.info("BMP集成,许可证过期");
filterChain.doFilter(req, res);
return;
}
String reqUrl = req.getRequestURL().toString();
String fullUrl = Utils.getFullRequestUrl(req);
String method = req.getMethod();
LogKit.info("BMP集成,记录访问地址:" + method + " " + fullUrl);
if (!"GET".equalsIgnoreCase(method)) {
filterChain.doFilter(req, res);
return;
}
if (reqUrl.indexOf("/remote/") >= 0) {
filterChain.doFilter(req, res);
return;
}
if (reqUrl.indexOf("/decision/login") >= 0) {
filterChain.doFilter(req, res);
return;
}
if (fullUrl.indexOf("/weixin/") >= 0) {
filterChain.doFilter(req, res);
return;
}
if (fullUrl.indexOf("/dingtalk/") >= 0) {
filterChain.doFilter(req, res);
return;
}
String bmpFrUrlValue = WebUtils.getHTTPRequestParameter(req, "bmpFrUrlValue");
if (StringKit.isNotEmpty(bmpFrUrlValue)) {
LogKit.info("BMP集成,bmpFrUrlValue:" + bmpFrUrlValue);
String tempValue = bmpFrUrlValue;
if (bmpFrUrlValue.indexOf("%") < 0) {
tempValue = UriUtils.encodeQueryParam(bmpFrUrlValue, "UTF-8");
}
String realUrl = CustomDataConfig.getInstance().getBmpFrUrl() + "&rzzz=" + tempValue;
LogKit.info("BMP集成,真实跳转地址:" + realUrl);
Utils.sendRedirect(res, realUrl);
return;
}
filterChain.doFilter(req, res);
} catch (Exception e) {
LogKit.error("BMP集成出错," + e.getMessage(), e);
}
}
}

46
src/main/java/com/fr/plugin/third/party/jsdiiac/web/MainFilesComponent.java

@ -0,0 +1,46 @@
package com.fr.plugin.third.party.jsdiiac.web;
import com.fr.web.struct.Component;
import com.fr.web.struct.Filter;
import com.fr.web.struct.browser.RequestClient;
import com.fr.web.struct.category.ScriptPath;
import com.fr.web.struct.category.StylePath;
public class MainFilesComponent extends Component {
public static final MainFilesComponent KEY = new MainFilesComponent();
private MainFilesComponent(){}
/**
* 返回需要引入的JS脚本路径
* @param client 请求客户端描述
* @return JS脚本路径
*/
public ScriptPath script(RequestClient client ) {
//如果不需要就直接返回 ScriptPath.EMPTY
return ScriptPath.build("com/fr/plugin/third/party/jsdiagb/web/main.js");
}
/**
* 返回需要引入的CSS样式路径
* @param client 请求客户端描述
* @return CSS样式路径
*/
public StylePath style(RequestClient client ) {
//如果不需要就直接返回 StylePath.EMPTY;
//return StylePath.build("com/fr/plugin/jscssinput/demo/demo.css");
return StylePath.EMPTY;
}
/**
* 通过给定的资源过滤器控制是否加载这个资源
* @return 资源过滤器
*/
public Filter filter() {
return new Filter(){
@Override
public boolean accept() {
//任何情况下我们都在平台组件加载时加载我们的组件
return true;
}
};
}
}

19
src/main/java/com/fr/plugin/third/party/jsdiiac/web/MainWebResourceProvider.java

@ -0,0 +1,19 @@
package com.fr.plugin.third.party.jsdiiac.web;
import com.fr.decision.fun.impl.AbstractWebResourceProvider;
import com.fr.decision.web.MainComponent;
import com.fr.web.struct.Atom;
public class MainWebResourceProvider extends AbstractWebResourceProvider {
@Override
public Atom attach() {
//在平台主组件加载时添加我们自己的组件
return MainComponent.KEY;
}
@Override
public Atom client() {
//我们自己要引入的组件
return MainFilesComponent.KEY;
}
}

16
src/main/resources/com/fr/plugin/third/party/jsdiagb/web/main.js

@ -0,0 +1,16 @@
$(function () {
var url = Dec.fineServletURL + "/url/jsd8061/oauth/config";
$.post(url,
function (data, status) {
if (status == "success") {
debugger;
var a = Dec.Logout;
var logoutUrl = data.loginUrl;
Dec.Logout = function () {
a();
//$.get(logoutUrl);
window.location.href = logoutUrl;
}
}
}, "json");
});
Loading…
Cancel
Save