浩鲸单点及菜单推送

feature-LeeD-20221025
李栋 2 years ago
parent 5b3b8bbd46
commit f4f8b92207

@ -47,7 +47,7 @@ public class MobileSsoLoginServiceImpl extends Service implements MobileSsoLogin
requestMap.put("app_access_token", accessToken);
//请求获取用户accessToken
baseBean.writeLog("getUserAccessToken:" + requestMap.toString());
String data = HttpUtils.doPost(userAccessTokenUrl, requestMap, null);
String data = HttpUtils.ssoLoginDoPost(userAccessTokenUrl, requestMap);
baseBean.writeLog("getUserAccessTokenResult:" + data);
JSONObject dataJson = JSONObject.parseObject(data);
String resultCode = dataJson.getString("resultCode");
@ -94,7 +94,7 @@ public class MobileSsoLoginServiceImpl extends Service implements MobileSsoLogin
requestMap.put("auth_code", authCode);
requestMap.put("app_access_token", accessToken);
baseBean.writeLog("getUserInfo:" + requestMap.toString());
String data = HttpUtils.doPost(userInfoUrl, requestMap, null);
String data = HttpUtils.ssoLoginDoPost(userInfoUrl, requestMap);
baseBean.writeLog("getUserInfoResult:" + data);
JSONObject dataJson = JSONObject.parseObject(data);
String resultCode = dataJson.getString("resultCode");
@ -134,7 +134,7 @@ public class MobileSsoLoginServiceImpl extends Service implements MobileSsoLogin
requestMap.put("appKey", appKey);
requestMap.put("appSecret", appSecret);
baseBean.writeLog("getAccessToken:" + requestMap.toString());
String data = HttpUtils.doPost(accessTokenUrl, requestMap, null);
String data = HttpUtils.ssoLoginDoPost(accessTokenUrl, requestMap);
baseBean.writeLog("getAccessTokenResult:" + data);
JSONObject dataJson = JSONObject.parseObject(data);
String resultCode = dataJson.getString("resultCode");

@ -49,14 +49,14 @@ public class WorkflowSyncCronJob extends BaseCronJob {
bb.writeLog("WorkflowSyncCronJob ALL start");
String currentTime = TimeUtil.getCurrentTimeString();
allSynchronizeWorkflow(bb, synchronizeFlowUrl, synchronizeUserUrl, center, workflowAuthTable, accountName, password);
writeTimeNode(timeNodeTable, currentTime, SYNC_ALL, TIME_NODE_USE_WORKFLOW_SYNC, timeNodeFormModeId);
writeTimeNode(bb, timeNodeTable, currentTime, SYNC_ALL, TIME_NODE_USE_WORKFLOW_SYNC, timeNodeFormModeId);
}
//增量同步使用增量同步方法
if (SYNC_INCREMENT.equals(syncType)) {
bb.writeLog("WorkflowSyncCronJob INCREMENT start");
String currentTime = TimeUtil.getCurrentTimeString();
IncrementSynchronizeWorkflow(bb, synchronizeFlowUrl, synchronizeUserUrl, center, workflowAuthTable, timeNodeTable, accountName, password);
writeTimeNode(timeNodeTable, currentTime, SYNC_INCREMENT, TIME_NODE_USE_WORKFLOW_SYNC, timeNodeFormModeId);
writeTimeNode(bb, timeNodeTable, currentTime, SYNC_INCREMENT, TIME_NODE_USE_WORKFLOW_SYNC, timeNodeFormModeId);
}
} catch (Exception e) {
bb.writeLog("流程推送异常", e.getMessage());
@ -136,31 +136,31 @@ public class WorkflowSyncCronJob extends BaseCronJob {
if (CollectionUtils.isNotEmpty(addWorkflowList)) {
for (Map<String, Object> workflowMap : addWorkflowList) {
String data = HttpUtils.doPost(synchronizeFlowUrl, workflowMap, headers);
bb.writeLog("增加流程", data);
bb.writeLog("增加流程" + workflowMap.get("flowCode"), data);
//无法判断流程的更改类型,所以在流程变动同时修改
workflowMap.put("actionType", ACTION_TYPE_UPDATE);
data = HttpUtils.doPost(synchronizeFlowUrl, workflowMap, headers);
bb.writeLog("修改流程", data);
bb.writeLog("修改流程" + workflowMap.get("flowCode"), data);
}
}
//删除人员要在删除流程之前执行
if (CollectionUtils.isNotEmpty(delUserList)) {
for (Map<String, Object> workflowMap : delUserList) {
String data = HttpUtils.doPost(synchronizeUserUrl, workflowMap, headers);
bb.writeLog("删除人员", data);
bb.writeLog("删除人员" + workflowMap.get("staffCode"), data);
}
}
if (CollectionUtils.isNotEmpty(delWorkflowList)) {
for (Map<String, Object> workflowMap : delWorkflowList) {
String data = HttpUtils.doPost(synchronizeFlowUrl, workflowMap, headers);
bb.writeLog("删除流程", data);
bb.writeLog("删除流程" + workflowMap.get("staffCode"), data);
}
}
//调用人员同步方法
if (CollectionUtils.isNotEmpty(addUserList)) {
for (Map<String, Object> workflowMap : addUserList) {
String data = HttpUtils.doPost(synchronizeUserUrl, workflowMap, headers);
bb.writeLog("增加人员", data);
bb.writeLog("增加人员" + workflowMap.get("staffCode"), data);
}
}
}
@ -238,9 +238,9 @@ public class WorkflowSyncCronJob extends BaseCronJob {
* @param timeNodeUse
* @param formmodeid id
*/
private void writeTimeNode(String timeNodeTable, String currentTime, String syncType, String timeNodeUse, String formmodeid) throws Exception {
private void writeTimeNode(BaseBean bb, String timeNodeTable, String currentTime, String syncType, String timeNodeUse, String formmodeid) throws Exception {
RecordSet recordSet = new RecordSet();
String sql = "SET IDENTITY_INSERT " + timeNodeTable + " ON insert into " + timeNodeTable + " (id,formmodeid,type,timenode,useto) values (?,?,?,?,?)";
String sql = "";
String dbType = recordSet.getDBType();
if ("mysql".equalsIgnoreCase(dbType)) {
sql = "insert into " + timeNodeTable + " (id,formmodeid,type,timenode,useto) values (?,?,?,?,?)";
@ -249,6 +249,7 @@ public class WorkflowSyncCronJob extends BaseCronJob {
} else if ("sqlserver".equalsIgnoreCase(dbType)) {
sql = "SET IDENTITY_INSERT " + timeNodeTable + " ON insert into " + timeNodeTable + " (id,formmodeid,type,timenode,useto) values (?,?,?,?,?)";
}
recordSet.executeUpdate(sql, IdGenerator.getNextId(timeNodeTable), formmodeid, syncType, currentTime, timeNodeUse);
boolean b = recordSet.executeUpdate(sql, IdGenerator.getNextId(timeNodeTable), formmodeid, syncType, currentTime, timeNodeUse);
bb.writeLog("writeTimeNode result:" + b);
}
}

@ -1,118 +0,0 @@
package weaver.interfaces.mq;
import com.alibaba.rocketmq.client.consumer.DefaultMQPushConsumer;
//import com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
//import com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
//import com.alibaba.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import com.alibaba.rocketmq.client.exception.MQClientException;
//import com.alibaba.rocketmq.common.message.MessageExt;
import com.alibaba.rocketmq.common.consumer.ConsumeFromWhere;
import com.alibaba.rocketmq.common.protocol.heartbeat.MessageModel;
import weaver.general.BaseBean;
import weaver.interfaces.comInfo.PropBean;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class RocketmqServlet extends HttpServlet {
@Override
public void init() throws ServletException
{
BaseBean bb = new BaseBean();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
bb.writeLog("initiated---进入时间:"+sdf.format(new Date()));
bb.writeLog("***** resource model initiated");
bb.writeLog("***** resource model initiated");
bb.writeLog("***** resource model initiated");
try{
//DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("portal-producer-group_nj");
//DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("cbec-consumer-group_nj_133");
//consumer.setNamesrvAddr("172.16.84.183:9001;172.16.84.187:9001");
// consumer.subscribe("dataSync_topic_nj", "BPM");
// consumer.setInstanceName("dataSync_topic_nj");
String consumerGroup = PropBean.getUfPropValue("consumerGroup");
bb.writeLog("consumerGroup:"+consumerGroup);
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(consumerGroup);
String namesrvAddr = PropBean.getUfPropValue("namesrvAddr");
bb.writeLog("namesrvAddr:"+namesrvAddr);
consumer.setNamesrvAddr(namesrvAddr);
String instanceName = PropBean.getUfPropValue("instanceName");
bb.writeLog("instanceName:"+instanceName);
consumer.setInstanceName(instanceName);
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
//consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_LAST_OFFSET);
String topic = PropBean.getUfPropValue("topic");
String subExpression = PropBean.getUfPropValue("subExpression");
bb.writeLog("topic:"+topic);
bb.writeLog("subExpression:"+subExpression);
consumer.subscribe(topic,subExpression);
consumer.setConsumeThreadMin(1);
consumer.setConsumeThreadMax(1);
consumer.setConsumeMessageBatchMaxSize(1);
consumer.setMessageModel(MessageModel.BROADCASTING);
consumer.registerMessageListener(new RocketMsgListener());
// consumer.registerMessageListener(new RocketMsgOrderListener());
/**
* Consumer使start<br>
*/
consumer.start();
bb.writeLog("Consumer Started.");
}catch (MQClientException e){
bb.writeLog("Consumer resource model initiated--MQClientException:"+e);
}
bb.writeLog("***** resource model initiated");
bb.writeLog("***** resource model initiated");
bb.writeLog("***** resource model initiated");
}
/**
* HttpServlet doGet
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
/**
* HttpServlet doPost
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
@Override
public void destroy()
{
// 什么也不做
}
}

File diff suppressed because it is too large Load Diff

@ -1,27 +1,25 @@
package weaver.interfaces.util;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import info.monitorenter.util.Entry;
import lombok.extern.slf4j.Slf4j;
import okhttp3.*;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContexts;
import org.apache.http.util.EntityUtils;
import org.springframework.util.Assert;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@ -36,10 +34,40 @@ public class HttpUtils {
public static final Gson gson = new Gson();
/**
* token
*
* @param url
* @param paramMap
* @param headers
* @return
*/
public static String ssoLoginDoPost(String url, Map<String, Object> paramMap) {
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, JSONObject.toJSONString(paramMap));
Request request = new Request.Builder()
.url(url)
.method("POST", body)
.addHeader("Content-Type", "application/json")
.build();
try {
Response response = client.newCall(request).execute();
return response.body().string();
} catch (Exception e) {
throw new RuntimeException("Exception occurred when send ssoLoginDoPost get token" + url + "]!" + e.getMessage());
}
}
public static String doPost(String url, Map<String, Object> paramMap, Map<String, String> headers) {
Assert.hasText(url, "Url is empty!");
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpClient httpClient = null;
try {
SSLConnectionSocketFactory scsf = new SSLConnectionSocketFactory(
SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build(),
NoopHostnameVerifier.INSTANCE);
httpClient = HttpClients.custom().setSSLSocketFactory(scsf).build();
HttpPost httpPost = new HttpPost(url);
if (MapUtils.isNotEmpty(paramMap)) {
StringEntity entity = new StringEntity(gson.toJson(paramMap), "UTF-8");
@ -59,13 +87,14 @@ public class HttpUtils {
return result;
} catch (Exception e) {
throw new RuntimeException("Exception occurred when send post request[url:" + url
+ ",paramMap:" + paramMap + "]!", e);
throw new RuntimeException("Exception occurred when send post request[url:" + url + "]!" + e.getMessage());
} finally {
try {
httpClient.close();
} catch (Exception e) {
//np
if (httpClient != null) {
try {
httpClient.close();
} catch (IOException e) {
throw new RuntimeException("Exception occurred when httpClient:" + e.getMessage());
}
}
}
}

@ -0,0 +1,148 @@
package weaver.interfaces.util;
/**
* @version 1.0
* @Title ecology-9
* @Company
* @CreateDate 2022/11/16
* @Description ${description}
* @Author Lee
*/
import com.alibaba.fastjson.JSONObject;
import com.customization.sendtodo.HttpRequestUtil;
import org.apache.commons.collections.MapUtils;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import java.io.*;
import java.net.*;
import java.util.HashMap;
import java.util.Map;
public class HttpUtils2 {
public static void main(String[] args) throws IOException {
HashMap<String, Object> requestMap = new HashMap<>();
requestMap.put("appKey", "2022111517310001-0m7929Wan81B7");
requestMap.put("appSecret", "f2blp7rpMb1iZbeb7Xv3eu6TtxbACW");
// requestMap.put("appKey", "D20220926160400001-4t08Rhu3l94");
// requestMap.put("appSecret", "080Jc0z4Bi0afVv93802e8UmHR2lVq");
// JSONObject jsonObject = new JSONObject(requestMap);
// String jsonString = JSONObject.toJSONString(requestMap);
// System.out.println(jsonString);
String s = HttpUtils.ssoLoginDoPost("https://sapp-test-idito.dito.ph:30443/open-apis/auth/v1/oauth/app_access_token", requestMap);
// String s = HttpUtils.ssoLoginDoPost("http://10.10.178.100/open-apis/auth/v1/oauth/app_access_token", requestMap);
System.out.println(s);
// String s = HttpRequestUtil.doPostByAuth("https://10.10.178.100/open-apis/auth/v1/oauth/app_access_token", jsonObject.toString(), null);
// System.out.println(s);
}
/**
* URL GET
*
* @param url URL
* @param param name1=value1&name2=value2
* @return
*/
public static String doGet(String url, String param) {
StringBuilder result = new StringBuilder();
BufferedReader in = null;
String urlNameString = url;
try {
if (param != null || param != "") {
urlNameString = urlNameString + "?" + param;
}
URL realUrl = new URL(urlNameString);
URLConnection connection = realUrl.openConnection();
connection.setRequestProperty("accept", "*/*");
connection.setRequestProperty("connection", "Keep-Alive");
connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
connection.connect();
// 定义 BufferedReader输入流来读取URL的响应
in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
result.append(line);
}
} catch (ConnectException e) {
e.printStackTrace();
} catch (SocketTimeoutException | ConnectTimeoutException e) {
e.printStackTrace();
//SocketTimeoutException是Java包下抛出的异常这定义了Socket读数据的超时时间即从server获取响应数据须要等待的时间当读取或者接收Socket超时会抛出SocketTimeoutException
System.out.println("sendGet SocketTimeoutException, url=" + url + ",param=" + param);
} catch (IOException e) {
e.printStackTrace();
System.out.println("sendGet IOException, url=" + url + ",param=" + param);
} catch (Exception e) {
e.printStackTrace();
System.out.println("sendGet Exception, url=" + url + ",param=" + param);
} finally {
try {
if (in != null) {
in.close();
}
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("sendGet Exception, url=" + url + ",param=" + param);
}
}
return result.toString();
}
/**
* post
*
* @param path url
* @param Info jsonobject
* @return
* @throws IOException
*/
public static String doPost(String path, JSONObject Info, Map<String, String> headers) throws IOException {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(path);
post.setHeader("Content-Type", "application/json");
if (MapUtils.isNotEmpty(headers)) {
for (String key : headers.keySet()) {
post.addHeader(key, headers.get(key));
}
}
String result = "";
try {
StringEntity s = new StringEntity(Info.toString(), "utf-8");
s.setContentEncoding("application/json");
post.setEntity(s);
// 发送请求
HttpResponse httpResponse = client.execute(post);
// 获取响应输入流
InputStream inStream = httpResponse.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(inStream, "utf-8"));
StringBuilder strber = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
strber.append(line + "\n");
}
inStream.close();
result = strber.toString();
} catch (Exception e) {
System.out.println("请求异常");
throw new RuntimeException(e);
}
return result;
}
}
Loading…
Cancel
Save