流程同步-单点登录
parent
3c03a68f26
commit
8a5404cf25
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile default="true" name="Default" enabled="true" />
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,36 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="JavaDoc" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="TOP_LEVEL_CLASS_OPTIONS">
|
||||
<value>
|
||||
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||
<option name="REQUIRED_TAGS" value="" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="INNER_CLASS_OPTIONS">
|
||||
<value>
|
||||
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||
<option name="REQUIRED_TAGS" value="" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="METHOD_OPTIONS">
|
||||
<value>
|
||||
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||
<option name="REQUIRED_TAGS" value="@return@param@throws or @exception" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="FIELD_OPTIONS">
|
||||
<value>
|
||||
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||
<option name="REQUIRED_TAGS" value="" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="IGNORE_DEPRECATED" value="false" />
|
||||
<option name="IGNORE_JAVADOC_PERIOD" value="true" />
|
||||
<option name="IGNORE_DUPLICATED_THROWS" value="false" />
|
||||
<option name="IGNORE_POINT_TO_ITSELF" value="false" />
|
||||
<option name="myAdditionalJavadocTags" value="date" />
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
@ -0,0 +1,11 @@
|
||||
<component name="libraryTable">
|
||||
<library name="classbean">
|
||||
<CLASSES>
|
||||
<root url="file://$PROJECT_DIR$/../../weaver/ecology/classbean" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="file://$PROJECT_DIR$/../../weaver/ecology/classbean" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
@ -0,0 +1,13 @@
|
||||
<component name="libraryTable">
|
||||
<library name="lib">
|
||||
<CLASSES>
|
||||
<root url="file://$PROJECT_DIR$/../../weaver/ecology/WEB-INF/lib" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="file://$PROJECT_DIR$/../../weaver/ecology/WEB-INF/lib" />
|
||||
</SOURCES>
|
||||
<jarDirectory url="file://$PROJECT_DIR$/../../weaver/ecology/WEB-INF/lib" recursive="false" />
|
||||
<jarDirectory url="file://$PROJECT_DIR$/../../weaver/ecology/WEB-INF/lib" recursive="false" type="SOURCES" />
|
||||
</library>
|
||||
</component>
|
@ -0,0 +1,10 @@
|
||||
<component name="libraryTable">
|
||||
<library name="lib1">
|
||||
<CLASSES>
|
||||
<root url="file://$PROJECT_DIR$/../../weaver/Resin/lib" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
<jarDirectory url="file://$PROJECT_DIR$/../../weaver/Resin/lib" recursive="false" />
|
||||
</library>
|
||||
</component>
|
@ -0,0 +1,12 @@
|
||||
package com.api.dito.web;
|
||||
|
||||
|
||||
import javax.ws.rs.Path;
|
||||
|
||||
/**
|
||||
* @author Lee
|
||||
*/
|
||||
@Path("/dito/ssologin/action")
|
||||
public class SsoLoginAction extends com.engine.dito.web.SsoLoginAction {
|
||||
}
|
||||
|
@ -0,0 +1,39 @@
|
||||
package com.engine.dito.service;
|
||||
|
||||
import weaver.hrm.User;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Title ecology-9
|
||||
* @Company 泛微软件
|
||||
* @CreateDate 2022/10/26
|
||||
* @Description ${description}
|
||||
* @Author Lee
|
||||
*/
|
||||
public interface MobileSsoLoginService {
|
||||
/**
|
||||
* 获取应用accessToken
|
||||
* @param paramMap
|
||||
* @param paramUser
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> getAccessToken(Map<String, Object> paramMap, User paramUser);
|
||||
|
||||
/**
|
||||
* 获取userAccessToken
|
||||
* @param paramMap
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> getUserAccessToken(Map<String, Object> paramMap, User user);
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
* @param paramMap
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> getUserInfo(Map<String, Object> paramMap, User user);
|
||||
}
|
@ -0,0 +1,173 @@
|
||||
package com.engine.dito.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.cloudstore.dev.api.util.Util_DataCache;
|
||||
import com.engine.core.impl.Service;
|
||||
import com.engine.dito.service.MobileSsoLoginService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import weaver.general.BaseBean;
|
||||
import weaver.hrm.User;
|
||||
import weaver.interfaces.util.HttpUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.engine.dito.constant.DitoConstant.*;
|
||||
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Title ecology-9
|
||||
* @Company 泛微软件
|
||||
* @CreateDate 2022/10/26
|
||||
* @Description 单点登录
|
||||
* @Author Lee
|
||||
*/
|
||||
public class MobileSsoLoginServiceImpl extends Service implements MobileSsoLoginService {
|
||||
@Override
|
||||
public Map<String, Object> getUserAccessToken(Map<String, Object> paramMap, User user) {
|
||||
Map<String, Object> dataMap = new HashMap<>();
|
||||
BaseBean baseBean = new BaseBean();
|
||||
//从缓存中获取用户accessToken
|
||||
String userAccessTokenCache = (String) Util_DataCache.getObjVal(SSO_LOGIN_USER_ACCESS_TOKEN + user.getLoginid());
|
||||
if (returnTokenWithCache(dataMap, userAccessTokenCache)) {
|
||||
return dataMap;
|
||||
}
|
||||
//请求链接地址
|
||||
String userAccessTokenUrl = baseBean.getPropValue("weaverssologin", "userAccessTokenUrl");
|
||||
dataMap.put("api_status", false);
|
||||
try {
|
||||
String authCode = (String) paramMap.get("auth_code");
|
||||
//获取应用access_token
|
||||
String accessToken = getAccessToken();
|
||||
HashMap<String, Object> requestMap = new HashMap<>();
|
||||
requestMap.put("auth_code", authCode);
|
||||
requestMap.put("access_token", accessToken);
|
||||
//请求获取用户accessToken
|
||||
String data = HttpUtils.doPost(userAccessTokenUrl, requestMap, null);
|
||||
JSONObject dataJson = JSONObject.parseObject(data);
|
||||
String resultCode = dataJson.getString("resultCode");
|
||||
JSONObject resultJson = dataJson.getJSONObject("result");
|
||||
if (resultJson != null && SUCCESS_RESULT_CODE.equals(resultCode)) {
|
||||
baseBean.writeLog("获取userAccessToken", resultJson.toString());
|
||||
String userAccessToken = resultJson.getString("access_token");
|
||||
String expiresIn = resultJson.getString("expires_in");
|
||||
String refreshToken = resultJson.getString("refresh_token");
|
||||
//access_token加缓存
|
||||
Util_DataCache.setObjValWithRedis(SSO_LOGIN_ACCESS_TOKEN, refreshToken, Integer.parseInt(expiresIn));
|
||||
Util_DataCache.setObjValWithRedis(SSO_LOGIN_USER_ACCESS_TOKEN + user.getLoginid(), userAccessToken, Integer.parseInt(expiresIn));
|
||||
dataMap.put("api_status", true);
|
||||
dataMap.put("data", resultJson.getInnerMap());
|
||||
return dataMap;
|
||||
}
|
||||
baseBean.writeLog("获取userAccessToken失败", dataJson.toString());
|
||||
return dataMap;
|
||||
} catch (Exception e) {
|
||||
baseBean.writeLog("获取userAccessToken异常", e.getMessage());
|
||||
dataMap.put("api_status", false);
|
||||
dataMap.put("errorMsg", e.getMessage());
|
||||
return dataMap;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getUserInfo(Map<String, Object> paramMap, User user) {
|
||||
Map<String, Object> dataMap = new HashMap<>();
|
||||
BaseBean baseBean = new BaseBean();
|
||||
try {
|
||||
String authCode = (String) paramMap.get("auth_code");
|
||||
String accessToken = (String) Util_DataCache.getObjVal(SSO_LOGIN_ACCESS_TOKEN);
|
||||
if (StringUtils.isEmpty(accessToken)) {
|
||||
accessToken = getAccessToken();
|
||||
}
|
||||
// String userAccessToken = (String) Util_DataCache.getObjVal(SSO_LOGIN_USER_ACCESS_TOKEN + user.getLoginid());
|
||||
//请求链接地址
|
||||
String userInfoUrl = baseBean.getPropValue("weaverssologin", "userInfoUrl");
|
||||
dataMap.put("api_status", false);
|
||||
HashMap<String, Object> requestMap = new HashMap<>();
|
||||
requestMap.put("auth_code", authCode);
|
||||
requestMap.put("access_token", accessToken);
|
||||
String data = HttpUtils.doPost(userInfoUrl, requestMap, null);
|
||||
JSONObject dataJson = JSONObject.parseObject(data);
|
||||
String resultCode = dataJson.getString("resultCode");
|
||||
JSONObject resultJson = dataJson.getJSONObject("result");
|
||||
if (resultJson != null && SUCCESS_RESULT_CODE.equals(resultCode)) {
|
||||
baseBean.writeLog("获取用户信息状态码:", resultCode);
|
||||
dataMap.put("api_status", true);
|
||||
dataMap.put("data", resultJson.getInnerMap());
|
||||
return dataMap;
|
||||
}
|
||||
baseBean.writeLog("获取用户信息失败", dataJson.toString());
|
||||
return dataMap;
|
||||
} catch (Exception e) {
|
||||
baseBean.writeLog("获取用户信息异常", e.getMessage());
|
||||
dataMap.put("api_status", false);
|
||||
dataMap.put("errorMsg", e.getMessage());
|
||||
return dataMap;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getAccessToken(Map<String, Object> paramMap, User paramUser) {
|
||||
Map<String, Object> dataMap = new HashMap<>();
|
||||
BaseBean baseBean = new BaseBean();
|
||||
String accessTokenCache = (String) Util_DataCache.getObjVal(SSO_LOGIN_ACCESS_TOKEN);
|
||||
if (returnTokenWithCache(dataMap, accessTokenCache)) {
|
||||
return dataMap;
|
||||
}
|
||||
//请求链接地址
|
||||
String accessTokenUrl = baseBean.getPropValue("weaverssologin", "accessTokenUrl");
|
||||
String appKey = baseBean.getPropValue("weaverssologin", "appKey");
|
||||
String appSecret = baseBean.getPropValue("weaverssologin", "appSecret");
|
||||
dataMap.put("api_status", false);
|
||||
try {
|
||||
HashMap<String, Object> requestMap = new HashMap<>();
|
||||
requestMap.put("appKey", appKey);
|
||||
requestMap.put("appSecret", appSecret);
|
||||
String data = HttpUtils.doPost(accessTokenUrl, requestMap, null);
|
||||
JSONObject dataJson = JSONObject.parseObject(data);
|
||||
String resultCode = dataJson.getString("resultCode");
|
||||
JSONObject resultJson = dataJson.getJSONObject("result");
|
||||
if (resultJson != null && SUCCESS_RESULT_CODE.equals(resultCode)) {
|
||||
baseBean.writeLog("获取accessToken", resultJson.toString());
|
||||
String accessToken = resultJson.getString("access_token");
|
||||
String expiresIn = resultJson.getString("expires_in");
|
||||
Util_DataCache.setObjValWithRedis(SSO_LOGIN_ACCESS_TOKEN, accessToken, Integer.parseInt(expiresIn));
|
||||
dataMap.put("api_status", true);
|
||||
dataMap.put("data", resultJson.getInnerMap());
|
||||
return dataMap;
|
||||
}
|
||||
baseBean.writeLog("获取accessToken失败", dataJson.toString());
|
||||
return dataMap;
|
||||
} catch (Exception e) {
|
||||
baseBean.writeLog("获取accessToken异常", e.getMessage());
|
||||
dataMap.put("api_status", false);
|
||||
dataMap.put("errorMsg", e.getMessage());
|
||||
return dataMap;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean returnTokenWithCache(Map<String, Object> dataMap, String userAccessTokenCache) {
|
||||
if (StringUtils.isNotEmpty(userAccessTokenCache)) {
|
||||
dataMap.put("api_status", true);
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
resultMap.put("access_token", userAccessTokenCache);
|
||||
dataMap.put("data", resultMap);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private String getAccessToken() throws IOException {
|
||||
String accessToken = (String) Util_DataCache.getObjVal(SSO_LOGIN_ACCESS_TOKEN);
|
||||
if (StringUtils.isEmpty(accessToken)) {
|
||||
Map<String, Object> accessTokenMap = getAccessToken(null, null);
|
||||
Map data = (Map) accessTokenMap.get("data");
|
||||
accessToken = (String) data.get("access_token");
|
||||
}
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
package com.engine.dito.web;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.api.projectlistdemo2.ProjectListDemoAction;
|
||||
import com.engine.common.util.ParamUtil;
|
||||
import com.engine.common.util.ServiceUtil;
|
||||
import com.engine.dito.service.MobileSsoLoginService;
|
||||
import com.engine.dito.service.impl.MobileSsoLoginServiceImpl;
|
||||
import com.engine.projectlistdemo2.service.ProjectListService;
|
||||
import com.engine.projectlistdemo2.service.impl.ProjectListServiceImpl;
|
||||
import weaver.hrm.HrmUserVarify;
|
||||
import weaver.hrm.User;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Lee
|
||||
*/
|
||||
public class SsoLoginAction {
|
||||
private MobileSsoLoginService getService() {
|
||||
return ServiceUtil.getService(MobileSsoLoginServiceImpl.class);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/getAccessToken")
|
||||
@Produces({"application/json"})
|
||||
public String getAccessToken(@Context HttpServletRequest request, @Context HttpServletResponse response) {
|
||||
Map<String, Object> apidatas = new HashMap<>();
|
||||
try {
|
||||
User user = HrmUserVarify.getUser(request, response);
|
||||
apidatas = getService().getAccessToken(ParamUtil.request2Map(request), user);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
apidatas.put("api_status", false);
|
||||
apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
|
||||
}
|
||||
return JSONObject.toJSONString(apidatas);
|
||||
}
|
||||
|
||||
|
||||
@POST
|
||||
@Path("/getUserAccessToken")
|
||||
@Produces({"application/json"})
|
||||
public String getUserAccessToken(@Context HttpServletRequest request, @Context HttpServletResponse response) {
|
||||
Map<String, Object> apidatas = new HashMap<>();
|
||||
try {
|
||||
User user = HrmUserVarify.getUser(request, response);
|
||||
apidatas = getService().getUserAccessToken(ParamUtil.request2Map(request), user);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
apidatas.put("api_status", false);
|
||||
apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
|
||||
}
|
||||
return JSONObject.toJSONString(apidatas);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/getUserInfo")
|
||||
@Produces({"application/json"})
|
||||
public String getUserInfo(@Context HttpServletRequest request, @Context HttpServletResponse response) {
|
||||
Map<String, Object> apidatas = new HashMap<>();
|
||||
try {
|
||||
User user = HrmUserVarify.getUser(request, response);
|
||||
apidatas = getService().getUserInfo(ParamUtil.request2Map(request), user);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
apidatas.put("api_status", false);
|
||||
apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
|
||||
}
|
||||
return JSONObject.toJSONString(apidatas);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,202 @@
|
||||
package weaver.interfaces.job;
|
||||
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.general.BaseBean;
|
||||
import weaver.general.TimeUtil;
|
||||
import weaver.interfaces.schedule.BaseCronJob;
|
||||
import weaver.interfaces.util.HttpUtils;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static com.engine.dito.constant.DitoConstant.*;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Title ecology-9
|
||||
* @Company 泛微软件
|
||||
* @CreateDate 2022/10/27
|
||||
* @Description 新建流程推送门(包含发起人权限)
|
||||
* @Author Lee
|
||||
*/
|
||||
public class WorkflowSyncCronJob extends BaseCronJob {
|
||||
/**
|
||||
* 推送类型(0全量、1增量)
|
||||
*/
|
||||
private String syncType;
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
BaseBean bb = new BaseBean();
|
||||
bb.writeLog("开始推送流程");
|
||||
try {
|
||||
//推送流程url
|
||||
String synchronizeFlowUrl = bb.getPropValue("PORTAL_INFO", "synchronizeFlowUrl");
|
||||
//同步人员权限url
|
||||
String synchronizeUserUrl = bb.getPropValue("PORTAL_INFO", "synchronizeUserUrl");
|
||||
//新建流程推送到目录code
|
||||
String catalogueCode = bb.getPropValue("PORTAL_INFO", "catalogueCode");
|
||||
String workflowAuthTable = bb.getPropValue("PORTAL_INFO", "workflowAuthTable");
|
||||
String timeNodeTable = bb.getPropValue("PORTAL_INFO", "timeNodeTable");
|
||||
String accountName = bb.getPropValue("PORTAL_INFO", "accountName");
|
||||
String password = bb.getPropValue("PORTAL_INFO", "password");
|
||||
String timeNodeFormModeId = bb.getPropValue("PORTAL_INFO", "timeNodeFormModeId");
|
||||
//全量同步使用全量同步方法
|
||||
if (SYNC_ALL.equals(syncType)) {
|
||||
String currentTime = TimeUtil.getCurrentTimeString();
|
||||
allSynchronizeWorkflow(bb, synchronizeFlowUrl, synchronizeUserUrl, catalogueCode, workflowAuthTable, accountName, password);
|
||||
writeTimeNode(timeNodeTable, currentTime, SYNC_ALL, TIME_NODE_USE_WORKFLOW_SYNC, timeNodeFormModeId);
|
||||
}
|
||||
//增量同步使用增量同步方法
|
||||
if (SYNC_INCREMENT.equals(syncType)) {
|
||||
String currentTime = TimeUtil.getCurrentTimeString();
|
||||
IncrementSynchronizeWorkflow(bb, synchronizeFlowUrl, synchronizeUserUrl, catalogueCode, workflowAuthTable, timeNodeTable, accountName, password);
|
||||
writeTimeNode(timeNodeTable, currentTime, SYNC_INCREMENT, TIME_NODE_USE_WORKFLOW_SYNC, timeNodeFormModeId);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
bb.writeLog("流程推送异常", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void IncrementSynchronizeWorkflow(BaseBean bb, String synchronizeFlowUrl, String synchronizeUserUrl, String cataCode, String workflowAuthTable, String timeNodeTable, String accountName, String password) {
|
||||
RecordSet recordSet = new RecordSet();
|
||||
//查询时间节点表,上次流程推送增量同步的时间
|
||||
String timeSql = "select tbsj from " + timeNodeTable + " where tblx=? and zy=? order by tbsj desc";
|
||||
recordSet.executeQuery(timeSql, SYNC_INCREMENT, TIME_NODE_USE_WORKFLOW_SYNC);
|
||||
String preTime = "";
|
||||
if (recordSet.next()) {
|
||||
preTime = recordSet.getString("tbsj");
|
||||
}
|
||||
syncWorkflowByCondition(bb, synchronizeFlowUrl, synchronizeUserUrl, cataCode, workflowAuthTable, accountName, password, preTime);
|
||||
}
|
||||
|
||||
// 全量同步
|
||||
private void allSynchronizeWorkflow(BaseBean bb, String synchronizeFlowUrl, String synchronizeUserUrl, String cataCode, String workflowAuthTable, String accountName, String password) {
|
||||
syncWorkflowByCondition(bb, synchronizeFlowUrl, synchronizeUserUrl, cataCode, workflowAuthTable, accountName, password, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据不同条件请求同步方法
|
||||
*/
|
||||
private void syncWorkflowByCondition(BaseBean bb, String synchronizeFlowUrl, String synchronizeUserUrl, String cataCode, String workflowAuthTable, String accountName, String password, String timeCondition) {
|
||||
RecordSet recordSet = new RecordSet();
|
||||
ArrayList<Map<String, Object>> addWorkflowList = new ArrayList<>();
|
||||
ArrayList<Map<String, Object>> delWorkflowList = new ArrayList<>();
|
||||
ArrayList<Map<String, Object>> addUserList = new ArrayList<>();
|
||||
ArrayList<Map<String, Object>> delUserList = new ArrayList<>();
|
||||
//查询建模所有流程
|
||||
String workflowSql = "SELECT DISTINCT workflowselect as flowcode,workflowname as flowname,effective FROM " + workflowAuthTable +
|
||||
" WHERE effective IN (SELECT DISTINCT effective FROM " + workflowAuthTable + ")";
|
||||
if (StringUtils.isNotEmpty(timeCondition)) {
|
||||
workflowSql += " AND modedatamodifydatetime >=" + timeCondition;
|
||||
}
|
||||
recordSet.execute(workflowSql);
|
||||
//区分有效和无效的流程
|
||||
while (recordSet.next()) {
|
||||
String effective = recordSet.getString("effective");
|
||||
if (EFFECTIVE_YES.equals(effective)) {
|
||||
String flowcode = recordSet.getString("flowcode");
|
||||
String flowname = recordSet.getString("flowname");
|
||||
//拼接有效流程请求参数
|
||||
concatWorkflowCondition(cataCode, flowcode, flowname, ACTION_TYPE_ADD, addWorkflowList);
|
||||
//有效流程关联的人员参数拼接
|
||||
getUserConditionByWorkflow(cataCode, flowcode, flowname, ACTION_TYPE_ADD, addUserList, timeCondition);
|
||||
} else if (EFFECTIVE_NO.equals(effective)) {
|
||||
String flowcode = recordSet.getString("flowcode");
|
||||
String flowname = recordSet.getString("flowname");
|
||||
//拼接无效流程请求参数
|
||||
concatWorkflowCondition(cataCode, flowcode, flowname, ACTION_TYPE_DELETE, delWorkflowList);
|
||||
//无效流程关联的人员参数拼接
|
||||
getUserConditionByWorkflow(cataCode, flowcode, flowname, ACTION_TYPE_DELETE, delUserList, timeCondition);
|
||||
}
|
||||
}
|
||||
HashMap<String, String> headers = new HashMap<>();
|
||||
headers.put("Authorization", "Basic " + Base64.getUrlEncoder().encodeToString((accountName + ":" + password).getBytes()));
|
||||
//调用流程同步方法
|
||||
if (CollectionUtils.isNotEmpty(addWorkflowList)) {
|
||||
for (Map<String, Object> workflowMap : addUserList) {
|
||||
String data = HttpUtils.doPost(synchronizeFlowUrl, workflowMap, headers);
|
||||
bb.writeLog("增加流程", data);
|
||||
}
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(delWorkflowList)) {
|
||||
for (Map<String, Object> workflowMap : delWorkflowList) {
|
||||
String data = HttpUtils.doPost(synchronizeFlowUrl, workflowMap, headers);
|
||||
bb.writeLog("删除流程", data);
|
||||
}
|
||||
}
|
||||
//调用人员同步方法
|
||||
if (CollectionUtils.isNotEmpty(addUserList)) {
|
||||
for (Map<String, Object> workflowMap : addUserList) {
|
||||
String data = HttpUtils.doPost(synchronizeUserUrl, workflowMap, headers);
|
||||
bb.writeLog("增加人员", data);
|
||||
}
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(delUserList)) {
|
||||
for (Map<String, Object> workflowMap : delUserList) {
|
||||
String data = HttpUtils.doPost(synchronizeUserUrl, workflowMap, headers);
|
||||
bb.writeLog("删除人员", data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void concatWorkflowCondition(String cataCode, String flowcode, String flowname, String actionType, ArrayList<Map<String, Object>> workflowList) {
|
||||
Map<String, Object> workflowMap = new HashMap<>();
|
||||
workflowMap.put("flowcode", flowcode);
|
||||
workflowMap.put("flowname", flowname);
|
||||
workflowMap.put("actionType", actionType);
|
||||
workflowMap.put("cataCode", cataCode);
|
||||
workflowMap.put("urPC", "/bpm/workflow/request/CreateRequestForward.jsp?workflowid=" + flowcode);
|
||||
workflowMap.put("urApp", "/bpm/spa/workflow/static4mobileform/index.html#/req?iscreate=1&workflowid=" + flowcode);
|
||||
workflowList.add(workflowMap);
|
||||
}
|
||||
|
||||
private void getUserConditionByWorkflow(String cataCode, String flowcode, String flowname, String actionType, ArrayList<Map<String, Object>> userList, String timeCondition) {
|
||||
Map<String, Object> usermap = new HashMap<>();
|
||||
StringBuilder staffCodeBuilder = new StringBuilder();
|
||||
String userSql = "SELECT workcode as staffCode FROM uf_workflow_aut WHERE workflowselect=?";
|
||||
if (StringUtils.isNotEmpty(timeCondition)) {
|
||||
userSql += " AND modedatamodifydatetime >=" + timeCondition;
|
||||
}
|
||||
RecordSet rs = new RecordSet();
|
||||
rs.executeQuery(userSql, flowcode);
|
||||
while (rs.next()) {
|
||||
staffCodeBuilder.append(rs.getString("staffCode")).append("|");
|
||||
}
|
||||
usermap.put("flowcode", flowcode);
|
||||
usermap.put("flowname", flowname);
|
||||
//同步所需参数一并拼接
|
||||
usermap.put("actionType", actionType);
|
||||
usermap.put("cataCode", cataCode);
|
||||
usermap.put("staffCode", staffCodeBuilder.toString());
|
||||
userList.add(usermap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将同步时间写入时间节点表
|
||||
*
|
||||
* @param timeNodeTable 表名
|
||||
* @param syncType 同步类型
|
||||
* @param timeNodeUse 同步作用
|
||||
* @param formmodeid 模块id
|
||||
*/
|
||||
private void writeTimeNode(String timeNodeTable, String currentTime, String syncType, String timeNodeUse, String formmodeid) {
|
||||
RecordSet recordSet = new RecordSet();
|
||||
String sql = "insert into " + timeNodeTable + "(id,formmodeid,tblx,tbsj,zy) values(?,?,?,?,?)";
|
||||
recordSet.executeUpdate(sql, UUID.randomUUID(), formmodeid, syncType, currentTime, timeNodeUse);
|
||||
}
|
||||
|
||||
// 增量同步
|
||||
//接口查询portal_oa已同步的流程
|
||||
//查询ecology有效的流程
|
||||
//对比,portal_oa需要删除的流程
|
||||
//portal_oa需要新同步的流程
|
||||
//查询流程关联的workcode,以"|"为分隔符拼接成字符串
|
||||
//根据需要删除的流程数量循环调用同步方法
|
||||
//根据要新同步的流程数量循环调用同步方法
|
||||
//调用人员同步方法
|
||||
|
||||
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
package weaver.interfaces.mq;
|
||||
|
||||
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.common.message.MessageExt;
|
||||
import weaver.general.BaseBean;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class RocketMsgListener implements MessageListenerConcurrently {
|
||||
@Override
|
||||
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext consumeConcurrentlyContext) {
|
||||
BaseBean bb = new BaseBean();
|
||||
MessageExt msg = msgs.get(0);
|
||||
|
||||
RocketmqUtil rocketmqUtil = new RocketmqUtil();
|
||||
|
||||
try {
|
||||
|
||||
bb.writeLog("Consumer---3----"+new String(msg.getBody()));
|
||||
String msgdata = new String(msg.getBody(),"UTF-8");
|
||||
if(!"".equals(msgdata))
|
||||
{
|
||||
String data = msgdata.substring(msgdata.indexOf("{"));
|
||||
int errcount = rocketmqUtil.updateOrgData(data);
|
||||
bb.writeLog("Consumer---errcount---:"+errcount);
|
||||
}
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
bb.writeLog("Consumer---UnsupportedEncodingException---e:"+e);
|
||||
return ConsumeConcurrentlyStatus.RECONSUME_LATER;
|
||||
}
|
||||
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
|
||||
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,116 @@
|
||||
package weaver.interfaces.util;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import info.monitorenter.util.Entry;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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.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.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
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;
|
||||
|
||||
@Slf4j
|
||||
public class HttpUtils {
|
||||
|
||||
public static String doPost(String url) {
|
||||
return doPost(url, null, null);
|
||||
}
|
||||
|
||||
public static final Gson gson = new Gson();
|
||||
|
||||
public static String doPost(String url, Map<String, Object> paramMap, Map<String, String> headers) {
|
||||
Assert.hasText(url, "Url is empty!");
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
try {
|
||||
HttpPost httpPost = new HttpPost(url);
|
||||
if (MapUtils.isNotEmpty(paramMap)) {
|
||||
StringEntity entity = new StringEntity(gson.toJson(paramMap), "UTF-8");
|
||||
entity.setContentEncoding("UTF-8");
|
||||
entity.setContentType("application/json");
|
||||
httpPost.setEntity(entity);
|
||||
}
|
||||
if (MapUtils.isNotEmpty(headers)) {
|
||||
for (String key : headers.keySet()) {
|
||||
httpPost.addHeader(key, headers.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
CloseableHttpResponse response = httpClient.execute(httpPost);
|
||||
String result;
|
||||
result = getString(response);
|
||||
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Exception occurred when send post request[url:" + url
|
||||
+ ",paramMap:" + paramMap + "]!", e);
|
||||
} finally {
|
||||
try {
|
||||
httpClient.close();
|
||||
} catch (Exception e) {
|
||||
//np
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String getString(CloseableHttpResponse response) throws IOException {
|
||||
String result;
|
||||
try {
|
||||
StatusLine statusLine = response.getStatusLine();
|
||||
if (statusLine.getStatusCode() != HttpStatus.SC_OK) {
|
||||
throw new RuntimeException("Unexpected failure: " + statusLine.toString());
|
||||
}
|
||||
|
||||
HttpEntity resEntity = response.getEntity();
|
||||
if (resEntity != null) {
|
||||
result = EntityUtils.toString(resEntity, Charset.forName("UTF-8"));
|
||||
EntityUtils.consume(resEntity);
|
||||
} else {
|
||||
result = null;
|
||||
}
|
||||
} finally {
|
||||
response.close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static String doGet(String url, boolean mobile) {
|
||||
Assert.hasText(url, "Url is empty!");
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
try {
|
||||
HttpGet httpGet = new HttpGet(url);
|
||||
if (mobile) {
|
||||
httpGet.setHeader("user-agent",
|
||||
"Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1");
|
||||
}
|
||||
|
||||
CloseableHttpResponse response = httpClient.execute(httpGet);
|
||||
String result;
|
||||
result = getString(response);
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Exception occurred when send post request[url:" + url, e);
|
||||
} finally {
|
||||
try {
|
||||
httpClient.close();
|
||||
} catch (Exception e) {
|
||||
//np
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue