LAPTOP-SB56SG4Q\86185
3 years ago
32 changed files with 2090 additions and 1 deletions
Binary file not shown.
@ -1,3 +1,6 @@
|
||||
# open-JSD-7837 |
||||
|
||||
JSD-7837开源任务材料 |
||||
JSD-7453 7837 开源任务代码\ |
||||
免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\ |
||||
仅作为开发者学习参考使用!禁止用于任何商业用途!\ |
||||
为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系hugh处理。 |
@ -0,0 +1,3 @@
|
||||
url=jdbc:oracle:thin:@127.0.0.1:1521:databasename |
||||
username=root |
||||
psd=123 |
Binary file not shown.
@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin> |
||||
<id>com.fr.plugin.sso</id> |
||||
<name><![CDATA[流程插件]]></name> |
||||
<active>yes</active> |
||||
<version>1.0.24</version> |
||||
<env-version>10.0</env-version> |
||||
<jartime>2018-07-31</jartime> |
||||
<vendor>author</vendor> |
||||
<description><![CDATA[流程插件]]></description> |
||||
<change-notes><![CDATA[ |
||||
]]></change-notes> |
||||
<main-package>com.fr.plugin.it</main-package> |
||||
<lifecycle-monitor class="com.fr.plugin.it.config.simple.DemoInitializeMonitor"/> |
||||
|
||||
<extra-core> |
||||
<LocaleFinder class="com.fr.plugin.it.config.simple.PluginLocaleFinderBridge"/> |
||||
<FunctionDefineProvider class="com.fr.plugin.it.function.StartFlow" name="startWorkflow" description="启动流程"/> |
||||
<FunctionDefineProvider class="com.fr.plugin.it.function.Return" name="returnWorkItem" description="驳回工作任务"/> |
||||
<FunctionDefineProvider class="com.fr.plugin.it.function.ReturnToStart" name="returnWorkflowToStart" description="驳回工作任务到开始"/> |
||||
<FunctionDefineProvider class="com.fr.plugin.it.function.Submit" name="submitWorkItem" description="提交工作任务"/> |
||||
<FunctionDefineProvider class="com.fr.plugin.it.function.Cancel" name="cancelInstances" description="批量取消流程"/> |
||||
<FunctionDefineProvider class="com.fr.plugin.it.function.CancelWithRemark" name="cancelInstanceWithRemark" description="取消流程"/> |
||||
<FunctionDefineProvider class="com.fr.plugin.it.function.Restart" name="reStartWorkflow" description="重新激活流程"/> |
||||
</extra-core> |
||||
<extra-decision> |
||||
<HttpHandlerProvider class="com.fr.plugin.it.handler.ExtendAttrHandlerProvider"/> |
||||
<URLAliasProvider class="com.fr.plugin.it.handler.URLAliasProvide"/> |
||||
</extra-decision> |
||||
|
||||
<function-recorder class="com.fr.plugin.it.config.simple.account.PluginSimpleConfig"/> |
||||
</plugin> |
@ -0,0 +1,357 @@
|
||||
package com.fr.plugin.it.api; |
||||
import com.fr.json.JSONArray; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.plugin.it.config.simple.account.PluginSimpleConfig; |
||||
import com.fr.plugin.it.utils.*; |
||||
|
||||
import java.util.*; |
||||
|
||||
public class FlowApi { |
||||
//启动流程
|
||||
public static String startFlow(Object[] object){ |
||||
PluginSimpleConfig psc = PluginSimpleConfig.getInstance(); |
||||
String startUrl = psc.getStart(); |
||||
|
||||
String workflowCode = String.valueOf(object[0]); |
||||
String userCode = String.valueOf(object[1]); |
||||
String finishStart = String.valueOf(object[2]); |
||||
String jsonDataItems = String.valueOf(object[3]); |
||||
String subJsonDataItems = ""; |
||||
// String.valueOf(object[4]);
|
||||
|
||||
String jsonDataItemsStr = getJSONDataStr(jsonDataItems); |
||||
|
||||
if(Utils.isNullStr(jsonDataItemsStr)){ |
||||
jsonDataItemsStr = ""; |
||||
} |
||||
|
||||
String subJsonDataItemsStr = getJSONDataStr(subJsonDataItems); |
||||
|
||||
if(Utils.isNullStr(subJsonDataItemsStr)){ |
||||
subJsonDataItemsStr = ""; |
||||
} |
||||
|
||||
Map<String,String> param = new HashMap<String,String>(); |
||||
|
||||
param.put("workflowCode",workflowCode); |
||||
param.put("userCode",userCode); |
||||
param.put("finishStart",finishStart); |
||||
param.put("jsonDataItems",jsonDataItemsStr); |
||||
param.put("subJsonDataItems",subJsonDataItemsStr); |
||||
|
||||
String result = HttpUtils.HttpPostWWWForm(startUrl,null,param); |
||||
String re2 =XMLUtils.xmlToList(result); |
||||
|
||||
Map<String,String> param2 = new HashMap<String,String>(); |
||||
|
||||
param2.put("workflowCode",workflowCode); |
||||
param2.put("userCode",userCode); |
||||
param2.put("finishStart",finishStart); |
||||
param2.put("jsonDataItems",jsonDataItems); |
||||
param2.put("subJsonDataItems",subJsonDataItems); |
||||
|
||||
insertToDB(param2,"startWorkflow",re2); |
||||
|
||||
return re2; |
||||
} |
||||
|
||||
//驳回工作任务
|
||||
public static String return1(Object[] object){ |
||||
PluginSimpleConfig psc = PluginSimpleConfig.getInstance(); |
||||
String startUrl = psc.getReturn1(); |
||||
|
||||
String userCode = String.valueOf(object[0]); |
||||
String workItemId = String.valueOf(object[1]); |
||||
String commentText = String.valueOf(object[2]); |
||||
|
||||
Map<String,String> param = new HashMap<String,String>(); |
||||
|
||||
param.put("userCode",userCode); |
||||
param.put("workItemId",workItemId); |
||||
param.put("commentText",commentText); |
||||
|
||||
String result = HttpUtils.HttpPostWWWForm(startUrl,null,param); |
||||
|
||||
return XMLUtils.xmlToList(result); |
||||
} |
||||
|
||||
//3、驳回工作任务到开始
|
||||
public static String returnToStart(Object[] object){ |
||||
PluginSimpleConfig psc = PluginSimpleConfig.getInstance(); |
||||
String startUrl = psc.getReturnToStart(); |
||||
|
||||
String workItemId = String.valueOf(object[0]); |
||||
String commentText = String.valueOf(object[1]); |
||||
|
||||
Map<String,String> param = new HashMap<String,String>(); |
||||
|
||||
param.put("workItemId",workItemId); |
||||
param.put("commentText",commentText); |
||||
|
||||
String result = HttpUtils.HttpPostWWWForm(startUrl,null,param); |
||||
|
||||
return XMLUtils.xmlToList(result); |
||||
} |
||||
|
||||
//4、提交工作任务
|
||||
public static String submit(Object[] object){ |
||||
PluginSimpleConfig psc = PluginSimpleConfig.getInstance(); |
||||
String startUrl = psc.getSubmit(); |
||||
|
||||
String userCode = String.valueOf(object[0]); |
||||
String workItemId = String.valueOf(object[1]); |
||||
String commentText = String.valueOf(object[2]); |
||||
String approval = String.valueOf(object[3]); |
||||
|
||||
Map<String,String> param = new HashMap<String,String>(); |
||||
|
||||
param.put("userCode",userCode); |
||||
param.put("workItemId",workItemId); |
||||
param.put("commentText",commentText); |
||||
param.put("approval",approval); |
||||
|
||||
String result = HttpUtils.HttpPostWWWForm(startUrl,null,param); |
||||
String result2 =XMLUtils.xmlToList(result); |
||||
insertToDB(param,"submitWorkItem",result2); |
||||
|
||||
return result2; |
||||
} |
||||
|
||||
//5、5、批量取消流程
|
||||
public static String cancel(Object[] object){ |
||||
PluginSimpleConfig psc = PluginSimpleConfig.getInstance(); |
||||
String startUrl = psc.getCancel(); |
||||
|
||||
String userCode = String.valueOf(object[0]); |
||||
String sequenceNos = String.valueOf(object[1]); |
||||
|
||||
Map<String,String> param = new HashMap<String,String>(); |
||||
|
||||
param.put("userCode",userCode); |
||||
param.put("instanceId",sequenceNos); |
||||
|
||||
String result = HttpUtils.HttpPostWWWForm(startUrl,null,param); |
||||
|
||||
return XMLUtils.xmlToList(result); |
||||
} |
||||
|
||||
//6、取消流程
|
||||
public static String cancelWithRemark(Object[] object){ |
||||
PluginSimpleConfig psc = PluginSimpleConfig.getInstance(); |
||||
String startUrl = psc.getCancelWithRemark(); |
||||
|
||||
String userCode = String.valueOf(object[0]); |
||||
String sequenceNos = String.valueOf(object[1]); |
||||
String remark = String.valueOf(object[2]); |
||||
|
||||
Map<String,String> param = new HashMap<String,String>(); |
||||
|
||||
param.put("userCode",userCode); |
||||
param.put("instanceId",sequenceNos); |
||||
param.put("remark",remark); |
||||
|
||||
String result = HttpUtils.HttpPostWWWForm(startUrl,null,param); |
||||
String result2 =XMLUtils.xmlToList(result); |
||||
|
||||
insertToDB(param,"cancelInstanceWithRemark",result2); |
||||
|
||||
|
||||
return result2; |
||||
} |
||||
|
||||
//7、重新激活流程
|
||||
public static String restart(Object[] object){ |
||||
PluginSimpleConfig psc = PluginSimpleConfig.getInstance(); |
||||
String startUrl = psc.getReStart(); |
||||
|
||||
String instanceId = String.valueOf(object[0]); |
||||
String activityCode = String.valueOf(object[1]); |
||||
|
||||
Map<String,String> param = new HashMap<String,String>(); |
||||
|
||||
param.put("instanceId",instanceId); |
||||
param.put("activityCode",activityCode); |
||||
|
||||
String result = HttpUtils.HttpPostWWWForm(startUrl,null,param); |
||||
String result2 =XMLUtils.xmlToList2(result); |
||||
insertToDB(param,"reStartWorkflow",result2); |
||||
|
||||
return result2; |
||||
} |
||||
|
||||
private static String getJSONDataStr(String jsonDataItems) { |
||||
JSONArray itemsJsons = new JSONArray(); |
||||
|
||||
if(Utils.isNotNullStr(jsonDataItems)){ |
||||
String[] items = jsonDataItems.split(";"); |
||||
|
||||
for(String item : items){ |
||||
String[] keyValue = item.split(","); |
||||
JSONObject jsonObject = new JSONObject(); |
||||
jsonObject.put(keyValue[0],keyValue[1]); |
||||
itemsJsons.add(jsonObject); |
||||
} |
||||
|
||||
return itemsJsons.toString(); |
||||
} |
||||
|
||||
return ""; |
||||
} |
||||
|
||||
private static List<String> getValues(String jsonDataItems) { |
||||
List<String> result = new ArrayList<String>(); |
||||
|
||||
if(Utils.isNotNullStr(jsonDataItems)){ |
||||
String[] items = jsonDataItems.split(";"); |
||||
|
||||
for(String item : items){ |
||||
String[] keyValue = item.split(","); |
||||
result.add(keyValue[1]); |
||||
} |
||||
} |
||||
|
||||
return result; |
||||
} |
||||
|
||||
private static void insertToDB(Map<String,String> param,String flowName,String result){ |
||||
String id = Utils.uuid(); |
||||
Date date = new Date(); |
||||
String yearMonth = DateUtilSelf.DateToString(date,"yyyyMM"); |
||||
//是否成功调用
|
||||
String isSuccess = "N"; |
||||
String sql = ""; |
||||
|
||||
if("startWorkflow".equals(flowName)){ |
||||
//请求参数
|
||||
String workflowCode = param.get("workflowCode"); |
||||
String userCode = param.get("userCode"); |
||||
String finishStart = param.get("finishStart"); |
||||
String jsonDataItems = param.get("jsonDataItems"); |
||||
String subJsonDataItems = param.get("subJsonDataItems"); |
||||
|
||||
List<String> values = getValues(jsonDataItems); |
||||
String field = getFileStr(values); |
||||
String value2 = getValueStr(values); |
||||
|
||||
if(Utils.isNullStr(result)){ |
||||
sql = "insert into FRSOURCEDATA10.RF_BPM_JYSGZ_TRIGGERLOG(ID,BPM_TYPE,YEARMONTH,STARTTIME,IS_SUCCESS,SUBMIT_DATA1,SUBMIT_DATA2,SUBMIT_DATA3"+field+")" + |
||||
" values('"+id+"','"+flowName+"','"+yearMonth+"',sysdate,'"+isSuccess+"','"+workflowCode+"','"+userCode+"','"+finishStart+"'"+value2+")"; |
||||
|
||||
JDBCUtil.update(sql); |
||||
return; |
||||
} |
||||
|
||||
JSONObject resultJson = new JSONObject(result); |
||||
isSuccess = resultJson.getBoolean("Success") ? "Y" : "N"; |
||||
//返回值
|
||||
String success = resultJson.getString("Success"); |
||||
String instanceID = resultJson.getString("InstanceID"); |
||||
String message = resultJson.getString("Message"); |
||||
String workItemID = resultJson.getString("WorkItemID"); |
||||
String workItemUrl = resultJson.getString("WorkItemUrl"); |
||||
String SequenceNO = resultJson.getString("SequenceNO"); |
||||
|
||||
sql = "insert into FRSOURCEDATA10.RF_BPM_JYSGZ_TRIGGERLOG(ID,BPM_TYPE,YEARMONTH,STARTTIME,IS_SUCCESS,SUBMIT_DATA1,SUBMIT_DATA2,SUBMIT_DATA3"+field+",BACK_DATA1,BACK_DATA2,BACK_DATA3,BACK_DATA4,BACK_DATA5,BACK_DATA6)" + |
||||
" values('"+id+"','"+flowName+"','"+yearMonth+"',sysdate,'"+isSuccess+"','"+workflowCode+"','"+userCode+"','"+finishStart+"'"+value2+",'"+success+"','"+instanceID+"','"+message+"','"+workItemID+"','"+workItemUrl+"','"+SequenceNO+"')"; |
||||
|
||||
FRUtils.FRLogInfo("sql:"+sql); |
||||
JDBCUtil.update(sql); |
||||
}else if("reStartWorkflow".equals(flowName)){ |
||||
//请求参数
|
||||
String instanceId = param.get("instanceId"); |
||||
String activityCode = param.get("activityCode"); |
||||
|
||||
if(Utils.isNullStr(result)){ |
||||
sql = "insert into FRSOURCEDATA10.RF_BPM_JYSGZ_TRIGGERLOG(ID,BPM_TYPE,YEARMONTH,STARTTIME,IS_SUCCESS,SUBMIT_DATA1,SUBMIT_DATA2)" + |
||||
" values('"+id+"','"+flowName+"','"+yearMonth+"',sysdate,'"+isSuccess+"','"+instanceId+"','"+activityCode+"')"; |
||||
|
||||
JDBCUtil.update(sql); |
||||
|
||||
return; |
||||
} |
||||
|
||||
JSONObject resultJson = new JSONObject(result); |
||||
isSuccess = resultJson.getBoolean("Success") ? "Y" : "N"; |
||||
//返回值
|
||||
String success = resultJson.getString("Success"); |
||||
String sequenceNo = resultJson.getString("SequenceNo"); |
||||
String instanceId2 = resultJson.getString("InstanceId"); |
||||
String message = resultJson.getString("Message"); |
||||
String jsonList = resultJson.getString("JsonList"); |
||||
|
||||
sql = "insert into FRSOURCEDATA10.RF_BPM_JYSGZ_TRIGGERLOG(ID,BPM_TYPE,YEARMONTH,STARTTIME,IS_SUCCESS,SUBMIT_DATA1,SUBMIT_DATA2,BACK_DATA1,BACK_DATA2,BACK_DATA3,BACK_DATA4,BACK_DATA5)" + |
||||
" values('"+id+"','"+flowName+"','"+yearMonth+"',sysdate,'"+isSuccess+"','"+instanceId+"','"+activityCode+"','"+success+"','"+sequenceNo+"','"+instanceId2+"','"+message+"','"+jsonList+"')"; |
||||
|
||||
FRUtils.FRLogInfo("sql:"+sql); |
||||
JDBCUtil.update(sql); |
||||
}else if("cancelInstanceWithRemark".equals(flowName)){ |
||||
//请求参数
|
||||
String userCode = param.get("userCode"); |
||||
String sequenceNos = param.get("sequenceNos"); |
||||
String remark = param.get("remark"); |
||||
|
||||
if(Utils.isNullStr(result)){ |
||||
sql = "insert into FRSOURCEDATA10.RF_BPM_JYSGZ_TRIGGERLOG(ID,BPM_TYPE,YEARMONTH,STARTTIME,IS_SUCCESS,SUBMIT_DATA1,SUBMIT_DATA2,SUBMIT_DATA3)" + |
||||
" values('"+id+"','"+flowName+"','"+yearMonth+"',sysdate,'"+isSuccess+"','"+userCode+"','"+sequenceNos+"','"+remark+"')"; |
||||
|
||||
JDBCUtil.update(sql); |
||||
return; |
||||
} |
||||
|
||||
|
||||
isSuccess = result.equals("true") ? "Y" : "N"; |
||||
|
||||
sql = "insert into FRSOURCEDATA10.RF_BPM_JYSGZ_TRIGGERLOG(ID,BPM_TYPE,YEARMONTH,STARTTIME,IS_SUCCESS,SUBMIT_DATA1,SUBMIT_DATA2,SUBMIT_DATA3,BACK_DATA1)" + |
||||
" values('"+id+"','"+flowName+"','"+yearMonth+"',sysdate,'"+isSuccess+"','"+userCode+"','"+sequenceNos+"','"+remark+"','"+isSuccess+"')"; |
||||
|
||||
FRUtils.FRLogInfo("sql:"+sql); |
||||
JDBCUtil.update(sql); |
||||
}else if("submitWorkItem".equals(flowName)){ |
||||
//请求参数
|
||||
String userCode = param.get("userCode"); |
||||
String workItemId = param.get("workItemId"); |
||||
String commentText = param.get("commentText"); |
||||
String approval = param.get("approval"); |
||||
|
||||
if(Utils.isNullStr(result)){ |
||||
sql = "insert into FRSOURCEDATA10.RF_BPM_JYSGZ_TRIGGERLOG(ID,BPM_TYPE,YEARMONTH,STARTTIME,IS_SUCCESS,SUBMIT_DATA1,SUBMIT_DATA2,SUBMIT_DATA3,SUBMIT_DATA4)" + |
||||
" values('"+id+"','"+flowName+"','"+yearMonth+"',sysdate,'"+isSuccess+"','"+userCode+"','"+workItemId+"','"+commentText+"','"+approval+"')"; |
||||
|
||||
JDBCUtil.update(sql); |
||||
return; |
||||
} |
||||
|
||||
isSuccess = result.equals("true") ? "Y" : "N"; |
||||
|
||||
sql = "insert into FRSOURCEDATA10.RF_BPM_JYSGZ_TRIGGERLOG(ID,BPM_TYPE,YEARMONTH,STARTTIME,IS_SUCCESS,SUBMIT_DATA1,SUBMIT_DATA2,SUBMIT_DATA3,SUBMIT_DATA4,BACK_DATA1)" + |
||||
" values('"+id+"','"+flowName+"','"+yearMonth+"',sysdate,'"+isSuccess+"','"+userCode+"','"+workItemId+"','"+commentText+"','"+approval+"','"+result+"')"; |
||||
|
||||
FRUtils.FRLogInfo("sql:"+sql); |
||||
JDBCUtil.update(sql); |
||||
} |
||||
} |
||||
|
||||
private static String getFileStr(List<String> values){ |
||||
String field = ""; |
||||
String fieldStr = "SUBMIT_DATA"; |
||||
int count = 4; |
||||
|
||||
for(String value : values){ |
||||
field+= ","+fieldStr + count; |
||||
|
||||
count ++; |
||||
} |
||||
|
||||
return field; |
||||
} |
||||
|
||||
private static String getValueStr(List<String> values){ |
||||
String result = ""; |
||||
|
||||
for(String value : values){ |
||||
result +=",'"+value+"'"; |
||||
} |
||||
|
||||
return result; |
||||
} |
||||
} |
@ -0,0 +1,22 @@
|
||||
package com.fr.plugin.it.config.simple; |
||||
|
||||
import com.fr.plugin.context.PluginContext; |
||||
import com.fr.plugin.it.config.simple.account.PluginSimpleConfig; |
||||
import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2018-12-04 |
||||
*/ |
||||
public class DemoInitializeMonitor extends AbstractPluginLifecycleMonitor { |
||||
@Override |
||||
public void afterRun(PluginContext pluginContext) { |
||||
PluginSimpleConfig.getInstance(); |
||||
} |
||||
|
||||
@Override |
||||
public void beforeStop(PluginContext pluginContext) { |
||||
|
||||
} |
||||
} |
@ -0,0 +1,23 @@
|
||||
package com.fr.plugin.it.config.simple; |
||||
|
||||
import com.fr.decision.fun.impl.AbstractEmbedRequestFilterProvider; |
||||
import com.fr.plugin.it.config.simple.account.PluginSimpleConfig; |
||||
|
||||
import javax.servlet.FilterConfig; |
||||
import javax.servlet.ServletException; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.IOException; |
||||
|
||||
public class PluginInitializeFilterBridge extends AbstractEmbedRequestFilterProvider { |
||||
|
||||
@Override |
||||
public void init(FilterConfig filterConfig) { |
||||
PluginSimpleConfig.getInstance(); |
||||
} |
||||
|
||||
@Override |
||||
public void filter(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException, ServletException { |
||||
|
||||
} |
||||
} |
@ -0,0 +1,10 @@
|
||||
package com.fr.plugin.it.config.simple; |
||||
|
||||
import com.fr.stable.fun.impl.AbstractLocaleFinder; |
||||
|
||||
public class PluginLocaleFinderBridge extends AbstractLocaleFinder { |
||||
@Override |
||||
public String find() { |
||||
return "conf"; |
||||
} |
||||
} |
@ -0,0 +1,112 @@
|
||||
package com.fr.plugin.it.config.simple.account; |
||||
|
||||
import com.fr.config.*; |
||||
import com.fr.config.holder.Conf; |
||||
import com.fr.config.holder.factory.Holders; |
||||
import com.fr.intelli.record.Focus; |
||||
import com.fr.intelli.record.Original; |
||||
import com.fr.record.analyzer.EnableMetrics; |
||||
|
||||
@Visualization(category = "流程接口配置") |
||||
@EnableMetrics |
||||
public class PluginSimpleConfig extends DefaultConfiguration { |
||||
|
||||
private static volatile PluginSimpleConfig config = null; |
||||
|
||||
@Focus(id="com.fr.plugin.it.config.simple", text = "流程接口配置", source = Original.PLUGIN) |
||||
public static PluginSimpleConfig getInstance() { |
||||
if (config == null) { |
||||
config = ConfigContext.getConfigInstance(PluginSimpleConfig.class); |
||||
} |
||||
return config; |
||||
} |
||||
|
||||
@Identifier(value = "start", name = "启动流程接口", description = "StartWorkflow", status = Status.SHOW) |
||||
private Conf<String> start = Holders.simple("http://192.168.18.71:8010/Portal/webServices/rfbpmservice.asmx/StartWorkflow"); |
||||
|
||||
@Identifier(value = "return1", name = "驳回工作任务接口", description = "ReturnWorkItem", status = Status.SHOW) |
||||
private Conf<String> return1 = Holders.simple("http://192.168.18.71:8010/Portal/webServices/rfbpmservice.asmx/ReturnWorkItem"); |
||||
|
||||
@Identifier(value = "returnToStart", name = "驳回工作任务到开始接口", description = "ReturnWorkflowToStart", status = Status.SHOW) |
||||
private Conf<String> returnToStart = Holders.simple("http://192.168.18.71:8010/Portal/webServices/rfbpmservice.asmx/ReturnWorkflowToStart"); |
||||
|
||||
@Identifier(value = "submit", name = "提交工作任务接口", description = "SubmitWorkItem", status = Status.SHOW) |
||||
private Conf<String> submit = Holders.simple("http://192.168.18.71:8010/Portal/webServices/rfbpmservice.asmx/SubmitWorkItem"); |
||||
|
||||
@Identifier(value = "cancel", name = "批量取消流程接口", description = "CancelInstances", status = Status.SHOW) |
||||
private Conf<String> cancel = Holders.simple("http://192.168.18.71:8010/Portal/webServices/rfbpmservice.asmx/CancelInstances"); |
||||
|
||||
@Identifier(value = "cancelWithRemark", name = "取消流程接口", description = "CancelInstanceWithRemark", status = Status.SHOW) |
||||
private Conf<String> cancelWithRemark = Holders.simple("http://192.168.18.71:8010/Portal/webServices/rfbpmservice.asmx/CancelInstanceWithRemark"); |
||||
|
||||
@Identifier(value = "restart", name = "重新激活流程接口", description = "ReStartWorkflow", status = Status.SHOW) |
||||
private Conf<String> restart = Holders.simple("http://192.168.18.71:8010/Portal/webServices/rfbpmservice.asmx/ReStartWorkflow"); |
||||
|
||||
public String getCancelWithRemark() { |
||||
return cancelWithRemark.get(); |
||||
} |
||||
|
||||
public void setCancelWithRemark(String url) { |
||||
this.cancelWithRemark.set(url); |
||||
} |
||||
|
||||
public String getReStart() { |
||||
return restart.get(); |
||||
} |
||||
|
||||
public void setReStart(String url) { |
||||
this.restart.set(url); |
||||
} |
||||
|
||||
public String getStart() { |
||||
return start.get(); |
||||
} |
||||
|
||||
public void setStart(String url) { |
||||
this.start.set(url); |
||||
} |
||||
|
||||
public String getReturn1() { |
||||
return return1.get(); |
||||
} |
||||
|
||||
public void setReturn1(String url) { |
||||
this.return1.set(url); |
||||
} |
||||
|
||||
public String getReturnToStart() { |
||||
return returnToStart.get(); |
||||
} |
||||
|
||||
public void setReturnToStart(String url) { |
||||
this.returnToStart.set(url); |
||||
} |
||||
|
||||
public String getSubmit() { |
||||
return submit.get(); |
||||
} |
||||
|
||||
public void setSubmit(String url) { |
||||
this.submit.set(url); |
||||
} |
||||
|
||||
public String getCancel() { |
||||
return cancel.get(); |
||||
} |
||||
|
||||
public void setCancel(String url) { |
||||
this.cancel.set(url); |
||||
} |
||||
|
||||
@Override |
||||
public Object clone() throws CloneNotSupportedException { |
||||
PluginSimpleConfig cloned = (PluginSimpleConfig) super.clone(); |
||||
// cloned.text = (Conf<String>) text.clone();
|
||||
// cloned.count = (Conf<Integer>) count.clone();
|
||||
// cloned.price = (Conf<Double>) price.clone();
|
||||
// cloned.time = (Conf<Long>) time.clone();
|
||||
// cloned.student = (Conf<Boolean>) student.clone();
|
||||
return cloned; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,14 @@
|
||||
package com.fr.plugin.it.function; |
||||
|
||||
import com.fr.plugin.it.api.FlowApi; |
||||
import com.fr.script.AbstractFunction; |
||||
import com.fr.stable.exception.FormulaException; |
||||
|
||||
public class Cancel extends AbstractFunction { |
||||
@Override |
||||
public Object run(Object[] objects) throws FormulaException { |
||||
String result = FlowApi.cancel(objects); |
||||
|
||||
return "{\"code\":\""+result+"\",\"message\":\"\"}"; |
||||
} |
||||
} |
@ -0,0 +1,14 @@
|
||||
package com.fr.plugin.it.function; |
||||
|
||||
import com.fr.plugin.it.api.FlowApi; |
||||
import com.fr.script.AbstractFunction; |
||||
import com.fr.stable.exception.FormulaException; |
||||
|
||||
public class CancelWithRemark extends AbstractFunction { |
||||
@Override |
||||
public Object run(Object[] objects) throws FormulaException { |
||||
String result = FlowApi.cancelWithRemark(objects); |
||||
|
||||
return "{\"code\":\""+result+"\",\"message\":\"\"}"; |
||||
} |
||||
} |
@ -0,0 +1,14 @@
|
||||
package com.fr.plugin.it.function; |
||||
|
||||
import com.fr.plugin.it.api.FlowApi; |
||||
import com.fr.script.AbstractFunction; |
||||
import com.fr.stable.exception.FormulaException; |
||||
|
||||
public class Restart extends AbstractFunction { |
||||
@Override |
||||
public Object run(Object[] objects) throws FormulaException { |
||||
String result = FlowApi.restart(objects); |
||||
|
||||
return "{\"code\":\""+result+"\",\"message\":\"\"}"; |
||||
} |
||||
} |
@ -0,0 +1,15 @@
|
||||
package com.fr.plugin.it.function; |
||||
|
||||
import com.fr.json.JSONObject; |
||||
import com.fr.plugin.it.api.FlowApi; |
||||
import com.fr.script.AbstractFunction; |
||||
import com.fr.stable.exception.FormulaException; |
||||
|
||||
public class Return extends AbstractFunction { |
||||
@Override |
||||
public Object run(Object[] objects) throws FormulaException { |
||||
String result = FlowApi.return1(objects); |
||||
|
||||
return "{\"code\":\""+result+"\",\"message\":\"\"}"; |
||||
} |
||||
} |
@ -0,0 +1,14 @@
|
||||
package com.fr.plugin.it.function; |
||||
|
||||
import com.fr.plugin.it.api.FlowApi; |
||||
import com.fr.script.AbstractFunction; |
||||
import com.fr.stable.exception.FormulaException; |
||||
|
||||
public class ReturnToStart extends AbstractFunction { |
||||
@Override |
||||
public Object run(Object[] objects) throws FormulaException { |
||||
String result = FlowApi.returnToStart(objects); |
||||
|
||||
return "{\"code\":\""+result+"\",\"message\":\"\"}"; |
||||
} |
||||
} |
@ -0,0 +1,25 @@
|
||||
package com.fr.plugin.it.function; |
||||
|
||||
import com.fr.json.JSONObject; |
||||
import com.fr.plugin.it.api.FlowApi; |
||||
import com.fr.plugin.it.utils.ResponseUtils; |
||||
import com.fr.plugin.it.utils.Utils; |
||||
import com.fr.script.AbstractFunction; |
||||
import com.fr.stable.exception.FormulaException; |
||||
|
||||
public class StartFlow extends AbstractFunction { |
||||
@Override |
||||
public Object run(Object[] objects) throws FormulaException { |
||||
String result = FlowApi.startFlow(objects); |
||||
|
||||
if(Utils.isNullStr(result)){ |
||||
return "{\"code\":\"false\",\"message\":\"开启流程失败\"}"; |
||||
} |
||||
|
||||
JSONObject resultJSON = new JSONObject(result); |
||||
boolean success = resultJSON.getBoolean("Success"); |
||||
String msg = resultJSON.getString("Message"); |
||||
|
||||
return "{\"code\":\""+success+"\",\"message\":\""+msg+"\"}"; |
||||
} |
||||
} |
@ -0,0 +1,14 @@
|
||||
package com.fr.plugin.it.function; |
||||
|
||||
import com.fr.plugin.it.api.FlowApi; |
||||
import com.fr.script.AbstractFunction; |
||||
import com.fr.stable.exception.FormulaException; |
||||
|
||||
public class Submit extends AbstractFunction { |
||||
@Override |
||||
public Object run(Object[] objects) throws FormulaException { |
||||
String result = FlowApi.submit(objects); |
||||
|
||||
return "{\"code\":\""+result+"\",\"message\":\"\"}"; |
||||
} |
||||
} |
@ -0,0 +1,13 @@
|
||||
package com.fr.plugin.it.handler; |
||||
|
||||
import com.fr.decision.fun.HttpHandler; |
||||
import com.fr.decision.fun.impl.AbstractHttpHandlerProvider; |
||||
|
||||
public class ExtendAttrHandlerProvider extends AbstractHttpHandlerProvider { |
||||
@Override |
||||
public HttpHandler[] registerHandlers() { |
||||
return new HttpHandler[]{ |
||||
new FlowOperate() |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,176 @@
|
||||
package com.fr.plugin.it.handler; |
||||
|
||||
import com.fr.decision.fun.impl.BaseHttpHandler; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.plugin.it.api.FlowApi; |
||||
import com.fr.plugin.it.utils.ResponseUtils; |
||||
import com.fr.plugin.it.utils.Utils; |
||||
import com.fr.plugin.transform.FunctionRecorder; |
||||
import com.fr.third.springframework.web.bind.annotation.RequestMethod; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
|
||||
@FunctionRecorder |
||||
public class FlowOperate extends BaseHttpHandler { |
||||
|
||||
|
||||
public FlowOperate() { |
||||
} |
||||
|
||||
@Override |
||||
public RequestMethod getMethod() { |
||||
return RequestMethod.GET; |
||||
} |
||||
|
||||
@Override |
||||
public String getPath() { |
||||
return "/flowOperate"; |
||||
} |
||||
|
||||
@Override |
||||
public boolean isPublic() { |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception { |
||||
String operateName = req.getParameter("operateName"); |
||||
|
||||
if("startWorkflow".equals(operateName)){ |
||||
Object[] param = new Object[5]; |
||||
String workflowCode = req.getParameter("workflowCode"); |
||||
String userCode = req.getParameter("userCode"); |
||||
String finishStart = req.getParameter("finishStart"); |
||||
String jsonDataItemsStr = req.getParameter("jsonDataItems"); |
||||
String subJsonDataItems = req.getParameter("subJsonDataItems"); |
||||
|
||||
|
||||
param[0] =workflowCode; |
||||
param[1] =userCode; |
||||
param[2] =finishStart; |
||||
param[3] =jsonDataItemsStr; |
||||
param[4] = subJsonDataItems; |
||||
|
||||
String result = FlowApi.startFlow(param); |
||||
|
||||
if(Utils.isNullStr(result)){ |
||||
ResponseUtils.failedResponse(res,"流程操作失败(500)!"); |
||||
return ; |
||||
} |
||||
|
||||
JSONObject json = new JSONObject(result); |
||||
boolean success = json.getBoolean("Success"); |
||||
String msg = json.getString("Message"); |
||||
|
||||
if(success){ |
||||
ResponseUtils.successResponse(res,msg); |
||||
}else{ |
||||
ResponseUtils.failedResponse(res,msg); |
||||
} |
||||
|
||||
} |
||||
else if("returnWorkItem".equals(operateName)){ |
||||
Object[] param = new Object[4]; |
||||
String userCode = req.getParameter("userCode"); |
||||
String workItemId = req.getParameter("workItemId"); |
||||
String commentText = req.getParameter("commentText"); |
||||
|
||||
param[0] =userCode; |
||||
param[1] =workItemId; |
||||
param[2] =commentText; |
||||
|
||||
String result = FlowApi.return1(param); |
||||
if(Utils.isNullStr(result)){ |
||||
ResponseUtils.failedResponse(res,"流程操作失败(500)!"); |
||||
return ; |
||||
} |
||||
ResponseUtils.successResponse(res,result); |
||||
} |
||||
else if("returnWorkflowToStart".equals(operateName)){ |
||||
Object[] param = new Object[4]; |
||||
String workItemId = req.getParameter("workItemId"); |
||||
String commentText = req.getParameter("commentText"); |
||||
|
||||
param[0] =workItemId; |
||||
param[1] =commentText; |
||||
|
||||
String result = FlowApi.returnToStart(param); |
||||
if(Utils.isNullStr(result)){ |
||||
ResponseUtils.failedResponse(res,"流程操作失败(500)!"); |
||||
return ; |
||||
} |
||||
ResponseUtils.successResponse(res,result); |
||||
} |
||||
else if("submitWorkItem".equals(operateName)){ |
||||
Object[] param = new Object[4]; |
||||
String userCode = req.getParameter("userCode"); |
||||
String workItemId = req.getParameter("workItemId"); |
||||
String commentText = req.getParameter("commentText"); |
||||
String approval = req.getParameter("approval"); |
||||
|
||||
param[0] =userCode; |
||||
param[1] =workItemId; |
||||
param[2] =commentText; |
||||
param[3] =approval; |
||||
|
||||
String result = FlowApi.submit(param); |
||||
if(Utils.isNullStr(result)){ |
||||
ResponseUtils.failedResponse(res,"流程操作失败(500)!"); |
||||
return ; |
||||
} |
||||
ResponseUtils.successResponse(res,result); |
||||
} |
||||
else if("cancelInstances".equals(operateName)){ |
||||
Object[] param = new Object[4]; |
||||
String userCode = req.getParameter("userCode"); |
||||
String sequenceNos = req.getParameter("instanceId"); |
||||
|
||||
param[0] =userCode; |
||||
param[1] =sequenceNos; |
||||
|
||||
String result = FlowApi.cancel(param); |
||||
if(Utils.isNullStr(result)){ |
||||
ResponseUtils.failedResponse(res,"流程操作失败(500)!"); |
||||
return ; |
||||
} |
||||
ResponseUtils.successResponse(res,result); |
||||
} |
||||
else if("cancelInstanceWithRemark".equals(operateName)){ |
||||
Object[] param = new Object[3]; |
||||
String userCode = req.getParameter("userCode"); |
||||
String sequenceNos = req.getParameter("instanceId"); |
||||
String remark = req.getParameter("remark"); |
||||
|
||||
param[0] =userCode; |
||||
param[1] =sequenceNos; |
||||
param[2] =remark; |
||||
|
||||
String result = FlowApi.cancelWithRemark(param); |
||||
if(Utils.isNullStr(result)){ |
||||
ResponseUtils.failedResponse(res,"流程操作失败(500)!"); |
||||
return ; |
||||
} |
||||
ResponseUtils.successResponse(res,result); |
||||
} |
||||
else if("reStartWorkflow".equals(operateName)){ |
||||
Object[] param = new Object[2]; |
||||
String userCode = req.getParameter("instanceId"); |
||||
String sequenceNos = req.getParameter("activityCode"); |
||||
|
||||
param[0] =userCode; |
||||
param[1] =sequenceNos; |
||||
|
||||
String result = FlowApi.restart(param); |
||||
if(Utils.isNullStr(result)){ |
||||
ResponseUtils.failedResponse(res,"流程操作失败(500)!"); |
||||
return ; |
||||
} |
||||
ResponseUtils.successResponse(res,result); |
||||
} |
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
} |
||||
|
@ -0,0 +1,14 @@
|
||||
package com.fr.plugin.it.handler; |
||||
|
||||
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 URLAliasProvide extends AbstractURLAliasProvider { |
||||
@Override |
||||
public URLAlias[] registerAlias() { |
||||
return new URLAlias[]{ |
||||
URLAliasFactory.createPluginAlias("/flowOperate","/flowOperate",true), |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,80 @@
|
||||
package com.fr.plugin.it.test; |
||||
|
||||
import com.fr.json.JSONObject; |
||||
import com.fr.plugin.it.utils.HttpUtils; |
||||
import com.fr.plugin.it.utils.JDBCUtil; |
||||
import com.fr.plugin.it.utils.XMLUtils; |
||||
import com.sun.media.jfxmediaimpl.HostUtils; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
public class Test { |
||||
public static void main(String[] args) { |
||||
// String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
|
||||
// "<CommomResult xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://tempuri.org/\">\n" +
|
||||
// " <Success>true</Success>\n" +
|
||||
// " <SequenceNo />\n" +
|
||||
// " <InstanceId>3b61681d-f164-45d9-84f0-7b0e40bb21b9</InstanceId>\n" +
|
||||
// " <Message>{\"InstanceId\":\"3b61681d-f164-45d9-84f0-7b0e40bb21b9\",\"WorkItemID\":\"\"}</Message>\n" +
|
||||
// " <JsonList />\n" +
|
||||
// "</CommomResult>";
|
||||
//
|
||||
String xml3 = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + |
||||
"<boolean xmlns=\"http://tempuri.org/\">true</boolean>"; |
||||
//
|
||||
// String a = XMLUtils.xmlToList2(xml3);
|
||||
// System.out.println(a);
|
||||
|
||||
// String xml2 = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
|
||||
// "<string xmlns=\"http://tempuri.org/\">{\"Success\":true,\"InstanceID\":\"da7a73f8-be3c-4f62-9a7d-8307db321420\",\"Message\":\"流程实例启动成功!\",\"WorkItemID\":\"\",\"WorkItemUrl\":\"\",\"SequenceNO\":\"20210000919399\"}</string>";
|
||||
|
||||
String result2 = XMLUtils.xmlToList(xml3); |
||||
|
||||
System.out.println(result2); |
||||
|
||||
//
|
||||
// System.out.println(result2);
|
||||
// JSONObject json = new JSONObject(result2);
|
||||
// boolean success = json.getBoolean("Success");
|
||||
// String msg = json.getString("Message");
|
||||
//
|
||||
// System.out.println(msg);
|
||||
// String[] a = new String[]{"1","2","3","4"};
|
||||
// String field = "subMITData3";
|
||||
// String value = "'a'";
|
||||
// String fieldStr = "SUBMITDATA";
|
||||
// int count = 4;
|
||||
// for(String b : a){
|
||||
// field+= ","+fieldStr + count;
|
||||
// value +=",'"+b+"'";
|
||||
// count ++;
|
||||
// }
|
||||
//
|
||||
// System.out.println(field);
|
||||
// System.out.println(value);
|
||||
// String sql = "insert into RF_BPM_JYSGZ_TRIGGERLOG(ID,BPM_TYPE,YEARMONTH,STARTTIME,IS_SUCCESS,SUBMIT_DATA1,SUBMIT_DATA2,SUBMIT_DATA3,SUBMIT_DATA4,SUBMIT_DATA5,BACK_DATA1,BACK_DATA2,BACK_DATA3,BACK_DATA4,BACK_DATA5) values('578c2b8b-5c20-49ef-bffe-2bd0577e8a49','startWorkflow','202105',sysdate,'N','010101','erpex1','true','','','false','','流程启动失败,流程模板不存在,模板编码:010101。','','')";
|
||||
// JDBCUtil.update(sql);
|
||||
// String url = "http://192.168.18.71:8010/Portal/webServices/commonwebservice.asmx/StartWorkflow";
|
||||
// Map<String,String> param = new HashMap<String,String>();
|
||||
// param.put("workflowCode","workflowCode");
|
||||
// param.put("userCode","workflowCode");
|
||||
// param.put("finishStart","true");
|
||||
// param.put("jsonDataItems","workflowCode");
|
||||
// param.put("subJsonDataItems","workflowCode");
|
||||
//
|
||||
// String result = HttpUtils.HttpPostWWWForm(url,null,param);
|
||||
//
|
||||
// String a = XMLUtils.xmlToList(result);
|
||||
// JSONObject json = new JSONObject(a);
|
||||
// System.out.println(result);
|
||||
//
|
||||
// String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
|
||||
// "<boolean xmlns=\"http://tempuri.org/\">false</boolean>";
|
||||
//
|
||||
// System.out.println(XMLUtils.xmlToList(xml));
|
||||
// String a = "http://192.168.243.237:8075/webroot/decision";
|
||||
// System.out.println(a.contains("url/mobile"));
|
||||
} |
||||
} |
@ -0,0 +1,227 @@
|
||||
package com.fr.plugin.it.utils; |
||||
|
||||
import java.sql.Timestamp; |
||||
import java.text.SimpleDateFormat; |
||||
import java.util.ArrayList; |
||||
import java.util.Calendar; |
||||
import java.util.Date; |
||||
import java.util.List; |
||||
|
||||
public class DateUtilSelf { |
||||
|
||||
/** |
||||
* 日期转换为日期字符串 |
||||
* @param date |
||||
* @param formatStr |
||||
* @return String |
||||
*/ |
||||
public static String DateToString(Date date,String formatStr) { |
||||
SimpleDateFormat sdf = new SimpleDateFormat(formatStr); |
||||
String dateStr = sdf.format(date).toString(); |
||||
|
||||
return dateStr; |
||||
} |
||||
|
||||
/** |
||||
* 日期字符串转换日期 |
||||
* @param dateStr |
||||
* @param formatStr |
||||
* @return Date |
||||
*/ |
||||
public static Date strToDate(String dateStr,String formatStr){ |
||||
SimpleDateFormat sdf = new SimpleDateFormat(formatStr); |
||||
Date date = null; |
||||
|
||||
try { |
||||
date = sdf.parse(dateStr); |
||||
} |
||||
catch(Exception e) { |
||||
} |
||||
|
||||
return date; |
||||
} |
||||
|
||||
/** |
||||
* Date转Timestamp |
||||
* @param date |
||||
* @return |
||||
*/ |
||||
public static Timestamp dateToTimestamp(Date date) { |
||||
Date transDate = DateUtilSelf.strToDate(DateUtilSelf.DateToString(date, "yyyy-MM-dd hh:mm:ss"),"yyyy-MM-dd hh:mm:ss"); |
||||
|
||||
Timestamp timestamp = new Timestamp(transDate.getTime()); |
||||
return timestamp; |
||||
} |
||||
|
||||
/** |
||||
* Date字符串转Timestamp |
||||
* @param dateStr |
||||
* @param format |
||||
* @return |
||||
*/ |
||||
public static Timestamp strToTimestamp(String dateStr,String format) { |
||||
Date date = strToDate(dateStr,format); |
||||
Timestamp timestamp = new Timestamp(date.getTime()); |
||||
return timestamp; |
||||
} |
||||
|
||||
/** |
||||
* 获取两个日期字符串之间的天数 |
||||
* @param startDateStr |
||||
* @param endDateStr |
||||
* @param formatStr |
||||
* @return |
||||
*/ |
||||
public static int getDays(String startDateStr,String endDateStr,String formatStr) { |
||||
|
||||
Date startDate = strToDate(startDateStr,formatStr); |
||||
Date endDate = strToDate(endDateStr,formatStr); |
||||
|
||||
long startTime = startDate.getTime(); |
||||
long endTime = endDate.getTime(); |
||||
|
||||
int days = (int) ((endTime - startTime)/(60*60*24*1000)); |
||||
|
||||
return days; |
||||
} |
||||
|
||||
/** |
||||
* 获取给定时间之前之后的时间 |
||||
* @param type |
||||
* @param dateStr |
||||
* @param count |
||||
* @param formatStr |
||||
* @return |
||||
*/ |
||||
public static String getAfterDateStr(int type,String dateStr,int count,String formatStr) { |
||||
Date startDate = strToDate(dateStr,formatStr); |
||||
|
||||
Calendar calendar = Calendar.getInstance(); |
||||
calendar.setTime(startDate); |
||||
|
||||
calendar.add(type, count); |
||||
|
||||
String endDateStr = DateToString(calendar.getTime(),formatStr); |
||||
|
||||
return endDateStr; |
||||
} |
||||
|
||||
/** |
||||
* 获取给定时间之前之后的时间 |
||||
* @param type |
||||
* @param date |
||||
* @param count |
||||
* @param formatStr |
||||
* @return |
||||
*/ |
||||
public static String getAfterDateStr(int type,Date date,int count,String formatStr) { |
||||
|
||||
Calendar calendar = Calendar.getInstance(); |
||||
calendar.setTime(date); |
||||
|
||||
calendar.add(type, count); |
||||
|
||||
String endDateStr = DateToString(calendar.getTime(),formatStr); |
||||
|
||||
return endDateStr; |
||||
} |
||||
|
||||
/** |
||||
* 获取给定时间之前之后的时间 |
||||
* @param type |
||||
* @param date |
||||
* @param count |
||||
* @return |
||||
*/ |
||||
public static Date getAfterDateStr(int type,Date date,int count) { |
||||
Calendar dateResult = Calendar.getInstance(); |
||||
dateResult.setTime(date); |
||||
dateResult.add(type, count); |
||||
return dateResult.getTime(); |
||||
} |
||||
|
||||
/** |
||||
* 时间戳转日期 |
||||
* @param timestamp |
||||
* @return |
||||
*/ |
||||
public static Date timestampToDate(Timestamp timestamp) { |
||||
Date date = new Date(timestamp.getTime()); |
||||
|
||||
return date; |
||||
} |
||||
|
||||
/** |
||||
* 时间戳转时间字符串 |
||||
* @param timestamp |
||||
* @param format 日期格式 |
||||
* @return |
||||
*/ |
||||
public static String timestampToStr(Timestamp timestamp,String format) { |
||||
Date date = timestampToDate(timestamp); |
||||
|
||||
String timeStr = DateToString(date, format); |
||||
|
||||
return timeStr; |
||||
} |
||||
|
||||
/** |
||||
* 获取所给日期length天内每一天的日期 |
||||
* @param date 所给日期(yyyy-MM-dd) |
||||
* @param length 长度 |
||||
* @return |
||||
*/ |
||||
public static List<String> getDateList(String date,int length){ |
||||
List<String> dateList = new ArrayList<String>(); |
||||
String format = "yyyy-MM-dd"; |
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
||||
//获取length天后的日期
|
||||
|
||||
String targetDate = getAfterDateStr(Calendar.DATE,date,length,format); |
||||
|
||||
Date start = null; |
||||
Date end = null; |
||||
|
||||
if(length >= 0) { |
||||
start = strToDate(date,format); |
||||
end = strToDate(targetDate,format); |
||||
}else { |
||||
start = strToDate(targetDate,format); |
||||
end = strToDate(date,format); |
||||
} |
||||
|
||||
Calendar calBegin = Calendar.getInstance(); |
||||
calBegin.setTime(start); |
||||
Calendar calEnd = Calendar.getInstance(); |
||||
calEnd.setTime(end); |
||||
|
||||
while (end.after(calBegin.getTime())) { |
||||
calBegin.add(Calendar.DATE, 1); |
||||
String dayStr = sdf.format(calBegin.getTime()); |
||||
dateList.add(dayStr); |
||||
} |
||||
|
||||
return dateList; |
||||
} |
||||
|
||||
/** |
||||
* 比较startDate是否在endDate之前 |
||||
* @param startDate |
||||
* @param endDate |
||||
* @param format |
||||
* @return 0 两个日期相等 <0 开始日期在结束日期之前 >0 开始日期在结束日期之后 |
||||
*/ |
||||
public static int comparisonDate(String startDate,String endDate,String format) { |
||||
Date start = strToDate(startDate,format); |
||||
Date end = strToDate(endDate,format); |
||||
|
||||
return start.compareTo(end); |
||||
} |
||||
|
||||
//获取当前日期年、月、日、时、分、秒
|
||||
public static int getCount(int type){ |
||||
Calendar calendar = Calendar.getInstance(); |
||||
|
||||
return calendar.get(type); |
||||
} |
||||
} |
@ -0,0 +1,158 @@
|
||||
package com.fr.plugin.it.utils; |
||||
|
||||
import com.fr.decision.authority.AuthorityContext; |
||||
import com.fr.decision.authority.data.User; |
||||
import com.fr.decision.webservice.login.LogInOutResultInfo; |
||||
import com.fr.decision.webservice.utils.DecisionServiceConstants; |
||||
import com.fr.decision.webservice.v10.login.LoginService; |
||||
import com.fr.decision.webservice.v10.login.event.LogInOutEvent; |
||||
import com.fr.decision.webservice.v10.user.UserService; |
||||
import com.fr.event.EventDispatcher; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.stable.query.QueryFactory; |
||||
import com.fr.stable.query.restriction.RestrictionFactory; |
||||
import com.fr.web.utils.WebUtils; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import javax.servlet.http.HttpSession; |
||||
import java.util.List; |
||||
|
||||
public class FRUtils { |
||||
/** |
||||
* 判断用户是否存在 |
||||
* @param userName |
||||
* @return |
||||
*/ |
||||
public static boolean isUserExist(String userName){ |
||||
if (StringUtils.isEmpty(userName)) { |
||||
return false; |
||||
} else { |
||||
try { |
||||
List var1 = AuthorityContext.getInstance().getUserController().find(QueryFactory.create().addRestriction(RestrictionFactory.eq("userName", userName))); |
||||
return var1 != null && !var1.isEmpty(); |
||||
} catch (Exception var2) { |
||||
FineLoggerFactory.getLogger().error(var2.getMessage()); |
||||
return false; |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 判断是否登录FR |
||||
* @param req |
||||
* @return |
||||
*/ |
||||
public static boolean isLogin(HttpServletRequest req){ |
||||
return LoginService.getInstance().isLogged(req); |
||||
} |
||||
|
||||
/** |
||||
* 帆软登录 |
||||
* @param httpServletRequest |
||||
* @param httpServletResponse |
||||
* @param userName |
||||
* @param url |
||||
*/ |
||||
public static void login(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse,String userName,String url){ |
||||
|
||||
FineLoggerFactory.getLogger().info("FRLOG:用户名:"+userName); |
||||
FineLoggerFactory.getLogger().info("FRLOG:跳转链接:"+url); |
||||
|
||||
|
||||
//判断用户名是否为空
|
||||
if(!Utils.isNullStr(userName)){ |
||||
if(isUserExist(userName)){ |
||||
String FRToken = ""; |
||||
|
||||
try { |
||||
HttpSession session = httpServletRequest.getSession(true); |
||||
|
||||
FRToken = LoginService.getInstance().login(httpServletRequest, httpServletResponse, userName); |
||||
|
||||
httpServletRequest.setAttribute(DecisionServiceConstants.FINE_AUTH_TOKEN_NAME,FRToken); |
||||
|
||||
session.setAttribute(DecisionServiceConstants.FINE_AUTH_TOKEN_NAME, FRToken); |
||||
EventDispatcher.fire(LogInOutEvent.LOGIN,new LogInOutResultInfo(httpServletRequest,httpServletResponse,userName,true)); |
||||
FineLoggerFactory.getLogger().info("FRLOG:登陆成功!"); |
||||
|
||||
if(!Utils.isNullStr(url)){ |
||||
httpServletResponse.sendRedirect(url); |
||||
} |
||||
} catch (Exception e) { |
||||
ResponseUtils.failedResponse(httpServletResponse,"登录异常,请联系管理员!"); |
||||
FineLoggerFactory.getLogger().info("FRLOG:登录异常,请联系管理员!"); |
||||
FineLoggerFactory.getLogger().info("FRLOGException:"+e.getMessage()); |
||||
} |
||||
}else{ |
||||
ResponseUtils.failedResponse(httpServletResponse,"用户在报表系统中不存在!"); |
||||
FineLoggerFactory.getLogger().info("FRLOG:用户在报表系统中不存在!"); |
||||
} |
||||
}else{ |
||||
ResponseUtils.failedResponse(httpServletResponse,"用户名不能为空!"); |
||||
FineLoggerFactory.getLogger().info("FRLOG:用户名不能为空!"); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param httpServletRequest |
||||
* @param httpServletResponse |
||||
*/ |
||||
public static void logout(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse) |
||||
{ |
||||
if(!isLogin(httpServletRequest)){ |
||||
return ; |
||||
} |
||||
|
||||
try { |
||||
LoginService.getInstance().logout(httpServletRequest,httpServletResponse); |
||||
} catch (Exception e) { |
||||
ResponseUtils.failedResponse(httpServletResponse,"登出异常,请联系管理员!"); |
||||
FineLoggerFactory.getLogger().info("FRLOG:登出异常,请联系管理员!"); |
||||
FineLoggerFactory.getLogger().info("FRLOGException:"+e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 打印FR日志 |
||||
* @param message |
||||
*/ |
||||
public static void FRLogInfo(String message){ |
||||
FineLoggerFactory.getLogger().info("FRLOG:"+message); |
||||
} |
||||
|
||||
/** |
||||
* 根据用户名获取用户信息 |
||||
* @param userName |
||||
* @return |
||||
*/ |
||||
public static User getFRUserByUserName(String userName){ |
||||
try { |
||||
return UserService.getInstance().getUserByUserName(userName); |
||||
} catch (Exception e) { |
||||
FRLogInfo("获取用户信息异常:"+e.getMessage()); |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
|
||||
/** |
||||
* 解密FR密码 |
||||
* @param password |
||||
* @return |
||||
*/ |
||||
// public static String decryptFRPsd(String password){
|
||||
// FRLogInfo("解密密码:"+password);
|
||||
// return TransmissionTool.decrypt(password);
|
||||
// }
|
||||
|
||||
/** |
||||
* 获取带参数的访问链接 |
||||
* @return |
||||
*/ |
||||
public static String getAllUrl(HttpServletRequest httpServletRequest){ |
||||
return WebUtils.getOriginalURL(httpServletRequest); |
||||
} |
||||
} |
@ -0,0 +1,232 @@
|
||||
package com.fr.plugin.it.utils; |
||||
|
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.third.org.apache.http.HttpEntity; |
||||
import com.fr.third.org.apache.http.HttpResponse; |
||||
import com.fr.third.org.apache.http.HttpStatus; |
||||
import com.fr.third.org.apache.http.NameValuePair; |
||||
import com.fr.third.org.apache.http.client.CookieStore; |
||||
import com.fr.third.org.apache.http.client.entity.UrlEncodedFormEntity; |
||||
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.entity.StringEntity; |
||||
import com.fr.third.org.apache.http.impl.client.BasicCookieStore; |
||||
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.impl.cookie.BasicClientCookie; |
||||
import com.fr.third.org.apache.http.message.BasicNameValuePair; |
||||
import com.fr.third.org.apache.http.ssl.SSLContexts; |
||||
import com.fr.third.org.apache.http.ssl.TrustStrategy; |
||||
import com.fr.third.org.apache.http.util.EntityUtils; |
||||
|
||||
import javax.net.ssl.SSLContext; |
||||
import javax.servlet.http.Cookie; |
||||
import java.io.UnsupportedEncodingException; |
||||
import java.security.KeyManagementException; |
||||
import java.security.KeyStoreException; |
||||
import java.security.NoSuchAlgorithmException; |
||||
import java.security.cert.CertificateException; |
||||
import java.security.cert.X509Certificate; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.Set; |
||||
|
||||
public class HttpUtils { |
||||
/** |
||||
* httpGet请求 |
||||
* @param url |
||||
* @return |
||||
*/ |
||||
public static String get(String url,Cookie[] cookies){ |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--url:"+url); |
||||
|
||||
//创建httpClient
|
||||
CloseableHttpClient httpclient = createHttpClient(cookies); |
||||
|
||||
HttpGet getMethod = new HttpGet(url); |
||||
|
||||
try { |
||||
HttpResponse response = httpclient.execute(getMethod); |
||||
|
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--status:"+response.getStatusLine().getStatusCode()); |
||||
|
||||
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { |
||||
HttpEntity entity = response.getEntity(); |
||||
String returnResult = EntityUtils.toString(entity, "utf-8"); |
||||
|
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--returnResult:"+returnResult); |
||||
|
||||
return returnResult; |
||||
} |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--exception:"+e.getMessage()); |
||||
} |
||||
|
||||
return ""; |
||||
} |
||||
|
||||
/** |
||||
* HttpPost请求 |
||||
* @param postMethod |
||||
* @return |
||||
*/ |
||||
private static String HttpPost(HttpPost postMethod){ |
||||
CloseableHttpClient httpclient = createHttpClient(null); |
||||
|
||||
try { |
||||
HttpResponse response = httpclient.execute(postMethod); |
||||
|
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPost:status:"+response.getStatusLine().getStatusCode()); |
||||
|
||||
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { |
||||
HttpEntity entity = response.getEntity(); |
||||
String returnResult = EntityUtils.toString(entity, "utf-8"); |
||||
|
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPost:returnResult:"+returnResult); |
||||
|
||||
return returnResult; |
||||
} |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPost:exception:"+e.getMessage()); |
||||
} |
||||
|
||||
return ""; |
||||
} |
||||
|
||||
public static String HttpPostXML(String url, String xmlParam){ |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPostXML:url:"+url); |
||||
|
||||
HttpPost postMethod = new HttpPost(url); |
||||
|
||||
postMethod.setHeader("Content-type", "text/html"); |
||||
HttpEntity entity2 = null; |
||||
try { |
||||
entity2 = new StringEntity(xmlParam); |
||||
} catch (UnsupportedEncodingException e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPostXML:参数异常:"+e.getMessage()); |
||||
return ""; |
||||
} |
||||
|
||||
postMethod.setEntity(entity2); |
||||
|
||||
return HttpPost(postMethod); |
||||
} |
||||
|
||||
public static String HttpPostJson(String url, String param,Map<String,String> header){ |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPostJSON:url:"+url); |
||||
|
||||
HttpPost postMethod = new HttpPost(url); |
||||
|
||||
postMethod.setHeader("Content-Type","application/json"); |
||||
|
||||
if(header != null && header.size() > 0){ |
||||
Set<String> keySet = header.keySet(); |
||||
|
||||
for(String key : keySet){ |
||||
postMethod.setHeader(key,header.get(key)); |
||||
} |
||||
} |
||||
|
||||
if(!Utils.isNullStr(param)){ |
||||
HttpEntity entity2 = null; |
||||
try { |
||||
entity2 = new StringEntity(param); |
||||
} catch (UnsupportedEncodingException e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPostJSON:参数异常:"+e.getMessage()); |
||||
return ""; |
||||
} |
||||
|
||||
postMethod.setEntity(entity2); |
||||
} |
||||
|
||||
return HttpPost(postMethod); |
||||
} |
||||
|
||||
public static String HttpPostWWWForm(String url, Map<String,String> header,Map<String,String> param){ |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpWWWForm:url:"+url); |
||||
|
||||
HttpPost postMethod = new HttpPost(url); |
||||
|
||||
if(header != null && header.size() > 0){ |
||||
FRUtils.FRLogInfo("header:"+header.toString()); |
||||
Set<String> keySet = header.keySet(); |
||||
|
||||
for(String key : keySet){ |
||||
postMethod.setHeader(key,header.get(key)); |
||||
} |
||||
} |
||||
|
||||
if(param != null && param.size() > 0){ |
||||
FRUtils.FRLogInfo("param:"+param.toString()); |
||||
|
||||
List<NameValuePair> params = new ArrayList<NameValuePair>(param.size()); |
||||
|
||||
for(Map.Entry<String,String> map : param.entrySet()){ |
||||
params.add(new BasicNameValuePair(map.getKey(), map.getValue())); |
||||
} |
||||
|
||||
try { |
||||
postMethod.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); |
||||
} catch (UnsupportedEncodingException e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpWWWForm:异常:"+e.getMessage()); |
||||
return ""; |
||||
} |
||||
} |
||||
|
||||
return HttpPost(postMethod); |
||||
} |
||||
|
||||
private static CloseableHttpClient createHttpClient(Cookie[] cookies){ |
||||
|
||||
SSLContext sslContext = null; |
||||
try { |
||||
sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustStrategy() { |
||||
@Override |
||||
public boolean isTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { |
||||
return true; |
||||
} |
||||
}).build(); |
||||
} catch (NoSuchAlgorithmException e) { |
||||
FRUtils.FRLogInfo("createHttpClientException:"+e.getMessage()); |
||||
} catch (KeyManagementException e) { |
||||
FRUtils.FRLogInfo("createHttpClientException:"+e.getMessage()); |
||||
} catch (KeyStoreException e) { |
||||
FRUtils.FRLogInfo("createHttpClientException:"+e.getMessage()); |
||||
} |
||||
|
||||
CloseableHttpClient httpclient = null; |
||||
|
||||
if(cookies != null && cookies.length > 0){ |
||||
CookieStore cookieStore = cookieToCookieStore(cookies); |
||||
|
||||
httpclient = HttpClients.custom().setSslcontext(sslContext). |
||||
setSSLHostnameVerifier(new NoopHostnameVerifier()).setDefaultCookieStore(cookieStore).build(); |
||||
} |
||||
else{ |
||||
httpclient = HttpClients.custom().setSslcontext(sslContext). |
||||
setSSLHostnameVerifier(new NoopHostnameVerifier()).build(); |
||||
} |
||||
|
||||
return httpclient; |
||||
} |
||||
|
||||
/** |
||||
* cookies转cookieStore |
||||
* @param cookies |
||||
* @return |
||||
*/ |
||||
public static CookieStore cookieToCookieStore(Cookie[] cookies){ |
||||
CookieStore cookieStore = new BasicCookieStore(); |
||||
|
||||
if(cookies != null && cookies.length>0){ |
||||
for(Cookie cookie : cookies){ |
||||
BasicClientCookie cookie1 = new BasicClientCookie(cookie.getName(), cookie.getValue()); |
||||
cookieStore.addCookie(cookie1); |
||||
} |
||||
} |
||||
|
||||
return cookieStore; |
||||
} |
||||
} |
@ -0,0 +1,65 @@
|
||||
package com.fr.plugin.it.utils; |
||||
|
||||
import java.io.*; |
||||
|
||||
public class IOUtils { |
||||
|
||||
/** |
||||
* 将inputStream写入本地文件 |
||||
* @param url |
||||
* @param inputStream |
||||
*/ |
||||
public static void writeFile(String url, InputStream inputStream){ |
||||
int index; |
||||
byte[] bytes = new byte[1024]; |
||||
FileOutputStream downloadFile = null ; |
||||
try { |
||||
downloadFile = new FileOutputStream(url); |
||||
while ((index = inputStream.read(bytes)) != -1) { |
||||
downloadFile.write(bytes, 0, index); |
||||
downloadFile.flush(); |
||||
} |
||||
}catch(Exception e){ |
||||
FRUtils.FRLogInfo("Exception:writeFile:"+e.getMessage()); |
||||
}finally { |
||||
try { |
||||
inputStream.close(); |
||||
downloadFile.close(); |
||||
} |
||||
catch (Exception e){ |
||||
FRUtils.FRLogInfo("Exception:writeFile:finally"+e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 字符串转输入流 |
||||
* @param str |
||||
* @return |
||||
*/ |
||||
public static InputStream strToInputStream(String str){ |
||||
try { |
||||
return new ByteArrayInputStream(str.getBytes("UTF-8")); |
||||
} catch (UnsupportedEncodingException e) { |
||||
FRUtils.FRLogInfo("IOUtils-strToInputStream:exception:"+e.getMessage()); |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
|
||||
public static String inputStreamToStr(InputStream inputStream) { |
||||
StringBuffer stringBuffer = new StringBuffer(); |
||||
byte[] byt = new byte[4096]; |
||||
|
||||
try { |
||||
for (int i; (i = inputStream.read(byt)) != -1; ) { |
||||
stringBuffer.append(new String(byt, 0, i)); |
||||
} |
||||
}catch(Exception e){ |
||||
FRUtils.FRLogInfo("Exception:inputStreamToStr:"+e.getMessage()); |
||||
} |
||||
|
||||
return stringBuffer.toString(); |
||||
} |
||||
} |
@ -0,0 +1,143 @@
|
||||
package com.fr.plugin.it.utils; |
||||
|
||||
import oracle.jdbc.driver.OracleDriver; |
||||
import java.sql.*; |
||||
import java.util.*; |
||||
|
||||
public class JDBCUtil { |
||||
private static void release(Connection conn,Statement st,ResultSet rs) { |
||||
closeRs(rs); |
||||
closeSt(st); |
||||
closeConn(conn); |
||||
} |
||||
|
||||
private static void closeRs(ResultSet rs) { |
||||
try { |
||||
if(rs!=null) { |
||||
rs.close(); |
||||
} |
||||
} catch (SQLException e) { |
||||
e.printStackTrace(); |
||||
} finally { |
||||
rs=null; |
||||
} |
||||
|
||||
} |
||||
|
||||
private static void closeSt(Statement st) { |
||||
try { |
||||
if(st!=null) { |
||||
st.close(); |
||||
} |
||||
} catch (SQLException e) { |
||||
e.printStackTrace(); |
||||
} finally { |
||||
st=null; |
||||
} |
||||
|
||||
} |
||||
|
||||
private static void closeConn(Connection conn) { |
||||
try { |
||||
if(conn!=null) { |
||||
conn.close(); |
||||
} |
||||
} catch (SQLException e) { |
||||
e.printStackTrace(); |
||||
} finally { |
||||
conn=null; |
||||
} |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 获取数据库连接 |
||||
* @param url |
||||
* @param user |
||||
* @param password |
||||
* @return |
||||
*/ |
||||
private static Connection getConnection(String url,String user,String password){ |
||||
Connection conn = null; |
||||
|
||||
try{ |
||||
//oracle
|
||||
DriverManager.registerDriver(new OracleDriver()); |
||||
//sqlService
|
||||
//DriverManager.registerDriver(new com.microsoft.sqlserver.jdbc.SQLServerDriver());
|
||||
conn =DriverManager.getConnection(url,user , password);} |
||||
catch(Exception e){ |
||||
FRUtils.FRLogInfo("获取数据库连接异常:"+e.getMessage()); |
||||
} |
||||
|
||||
return conn; |
||||
} |
||||
|
||||
public static List<Map<String,Object>> getResult(String sql, String[] columns){ |
||||
List<Map<String,Object>> result = new ArrayList<Map<String,Object>>(); |
||||
|
||||
Connection conn=null; |
||||
Statement st=null; |
||||
ResultSet rs=null; |
||||
|
||||
try { |
||||
String url = ""; |
||||
String user = ""; |
||||
String password = ""; |
||||
|
||||
conn = getConnection(url,user,password); |
||||
st = conn.createStatement(); |
||||
rs = st.executeQuery(sql); |
||||
//遍历查询每条记录
|
||||
while(rs.next()) { |
||||
Map<String,Object> map = new HashMap<String,Object>(); |
||||
|
||||
for(String column : columns){ |
||||
map.put(column,rs.getString(column)); |
||||
} |
||||
|
||||
result.add(map); |
||||
} |
||||
} catch (SQLException e) { |
||||
FRUtils.FRLogInfo("获取数据异常:"+e.getMessage()); |
||||
} finally { |
||||
release(conn, st, rs); |
||||
} |
||||
|
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* 更新 |
||||
* @param sql |
||||
* @return |
||||
*/ |
||||
public static int update(String sql){ |
||||
FRUtils.FRLogInfo("sql:"+sql); |
||||
Connection conn=null; |
||||
Statement st=null; |
||||
int count = 0; |
||||
|
||||
Properties p = PropertiesUtils.getProperties2("/resources/database.properties"); |
||||
|
||||
try { |
||||
DriverManager.registerDriver(new OracleDriver()); |
||||
String url = p.getProperty("url"); |
||||
String user = p.getProperty("username"); |
||||
String password = p.getProperty("psd"); |
||||
|
||||
FRUtils.FRLogInfo("url:"+url+"user:"+user+"password:"+password); |
||||
|
||||
conn = DriverManager.getConnection(url,user , password); |
||||
st = conn.createStatement(); |
||||
count = st.executeUpdate(sql); |
||||
|
||||
} catch (SQLException e) { |
||||
FRUtils.FRLogInfo("添加数据异常:"+e.getMessage()); |
||||
} finally { |
||||
JDBCUtil.release(conn, st, null); |
||||
} |
||||
|
||||
return count; |
||||
} |
||||
} |
@ -0,0 +1,40 @@
|
||||
package com.fr.plugin.it.utils; |
||||
|
||||
import com.fr.io.utils.ResourceIOUtils; |
||||
|
||||
import java.io.BufferedReader; |
||||
import java.io.InputStream; |
||||
import java.io.InputStreamReader; |
||||
import java.util.Properties; |
||||
|
||||
public class PropertiesUtils { |
||||
// private static final String RESOURCES_PATH = "config";
|
||||
// private static ResourceBundle bundle = null;
|
||||
//
|
||||
// static {
|
||||
// bundle = ResourceBundle.getBundle(RESOURCES_PATH);
|
||||
// }
|
||||
//
|
||||
// public static String getProperties(String key){
|
||||
// return bundle.getString(key);
|
||||
// }
|
||||
|
||||
/** |
||||
* 获取web-info下的配置文件 |
||||
* @param path |
||||
* @return |
||||
*/ |
||||
public static Properties getProperties2(String path){ |
||||
Properties p = new Properties(); |
||||
|
||||
try{ |
||||
InputStream is = ResourceIOUtils.read(path); |
||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is)); |
||||
p.load(bufferedReader); |
||||
}catch(Exception e){ |
||||
FRUtils.FRLogInfo("获取配置文件异常"); |
||||
} |
||||
|
||||
return p; |
||||
} |
||||
} |
@ -0,0 +1,80 @@
|
||||
package com.fr.plugin.it.utils; |
||||
|
||||
import com.fr.json.JSONObject; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.web.utils.WebUtils; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.PrintWriter; |
||||
|
||||
public class ResponseUtils { |
||||
private static final int SUCCESS = 200; |
||||
private static final int FAILED = -1; |
||||
|
||||
public static void successResponse(HttpServletResponse res, String body) { |
||||
response(res, body, SUCCESS); |
||||
} |
||||
|
||||
public static void failedResponse(HttpServletResponse res, String body) { |
||||
response(res, body, FAILED); |
||||
} |
||||
|
||||
private static void response(HttpServletResponse res, String body, int code) { |
||||
JSONObject object = new JSONObject(); |
||||
PrintWriter pw; |
||||
try { |
||||
object.put("code", code); |
||||
object.put("data", body); |
||||
pw = WebUtils.createPrintWriter(res); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info(e.getMessage()); |
||||
return; |
||||
} |
||||
res.setContentType("application/json;charset=utf-8"); |
||||
String result = object.toString(); |
||||
pw.println(result); |
||||
pw.flush(); |
||||
pw.close(); |
||||
} |
||||
|
||||
public static void response(HttpServletResponse res,JSONObject json){ |
||||
PrintWriter pw; |
||||
try { |
||||
pw = WebUtils.createPrintWriter(res); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info(e.getMessage()); |
||||
return; |
||||
} |
||||
res.setContentType("application/json;charset=utf-8"); |
||||
String result = json.toString(); |
||||
pw.println(result); |
||||
pw.flush(); |
||||
pw.close(); |
||||
} |
||||
|
||||
public static void setCSRFHeader(HttpServletResponse httpServletResponse){ |
||||
httpServletResponse.setHeader("Access-Control-Allow-Origin", "*"); |
||||
httpServletResponse.setHeader("Access-Control-Allow-Methods", "POST,GET,OPTIONS,DELETE,HEAD,PUT,PATCH"); |
||||
httpServletResponse.setHeader("Access-Control-Max-Age", "36000"); |
||||
httpServletResponse.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept,Authorization,authorization"); |
||||
} |
||||
|
||||
public static void responseJsonp(HttpServletRequest req, HttpServletResponse res, JSONObject json){ |
||||
PrintWriter pw; |
||||
try { |
||||
pw = WebUtils.createPrintWriter(res); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info(e.getMessage()); |
||||
return; |
||||
} |
||||
res.setContentType("text/javascript;charset=utf-8;charset=utf-8"); |
||||
String result = json.toString(); |
||||
|
||||
String jsonp=req.getParameter("callback"); |
||||
|
||||
pw.println(jsonp+"("+result+")"); |
||||
pw.flush(); |
||||
pw.close(); |
||||
} |
||||
} |
@ -0,0 +1,92 @@
|
||||
package com.fr.plugin.it.utils; |
||||
|
||||
import com.fr.json.JSONObject; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.stable.CodeUtils; |
||||
import com.fr.third.org.apache.commons.codec.digest.DigestUtils; |
||||
import sun.misc.BASE64Decoder; |
||||
import sun.misc.BASE64Encoder; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.io.BufferedReader; |
||||
import java.io.IOException; |
||||
import java.security.MessageDigest; |
||||
import java.util.UUID; |
||||
|
||||
public class Utils { |
||||
|
||||
/** |
||||
* 判断字符串是否为空 |
||||
* @param str |
||||
* @return true 空字符串 false 非空字符串 |
||||
*/ |
||||
public static boolean isNullStr(String str){ |
||||
return !(str != null && !str.isEmpty() && !"null".equals(str)); |
||||
} |
||||
|
||||
/** |
||||
* 判断字符串是否非空 |
||||
* @param str |
||||
* @return |
||||
*/ |
||||
public static boolean isNotNullStr(String str){ |
||||
return !isNullStr(str); |
||||
} |
||||
|
||||
/** |
||||
* MD5加密 |
||||
* @param str |
||||
* @return |
||||
*/ |
||||
public static String getMd5Str(String str) |
||||
{ |
||||
return DigestUtils.md5Hex(str); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 获取完整的访问路径 |
||||
*/ |
||||
public static String getAllUrl(HttpServletRequest req, String queryStr){ |
||||
String url = req.getRequestURL().toString(); |
||||
|
||||
if(isNullStr(queryStr)){ |
||||
return url; |
||||
} |
||||
|
||||
return url+"?"+queryStr; |
||||
} |
||||
|
||||
/** |
||||
* 帆软shaEncode加密 |
||||
*/ |
||||
|
||||
public static String shaEncode(String str){ |
||||
return CodeUtils.sha256Encode(str); |
||||
} |
||||
|
||||
/** |
||||
* 获取uuid |
||||
*/ |
||||
public static String uuid(){ |
||||
return UUID.randomUUID().toString(); |
||||
} |
||||
|
||||
public static JSONObject getRequestBody(HttpServletRequest req){ |
||||
StringBuffer sb = new StringBuffer(); |
||||
String line = null; |
||||
try { |
||||
BufferedReader reader = req.getReader(); |
||||
while ((line = reader.readLine()) != null) |
||||
sb.append(line); |
||||
} catch (Exception e) { |
||||
FRUtils.FRLogInfo("getRequestBody:exception:"+e.getMessage()); |
||||
} |
||||
//将空格和换行符替换掉避免使用反序列化工具解析对象时失败
|
||||
String jsonString = sb.toString().replaceAll("\\s","").replaceAll("\n",""); |
||||
|
||||
JSONObject json = new JSONObject(jsonString); |
||||
|
||||
return json; |
||||
} |
||||
} |
@ -0,0 +1,81 @@
|
||||
package com.fr.plugin.it.utils; |
||||
|
||||
import com.fr.json.JSONObject; |
||||
import org.dom4j.Document; |
||||
import org.dom4j.DocumentException; |
||||
import org.dom4j.Element; |
||||
import org.dom4j.io.SAXReader; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.LinkedHashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
public class XMLUtils { |
||||
public static String xmlToList(String xml){ |
||||
SAXReader reader = new SAXReader(); |
||||
Document document = null; |
||||
|
||||
FRUtils.FRLogInfo("xmlTolist:xml:"+xml); |
||||
|
||||
try { |
||||
document = reader.read(IOUtils.strToInputStream(xml)); |
||||
} catch (DocumentException e) { |
||||
FRUtils.FRLogInfo("documentException:"+e.getMessage()); |
||||
} |
||||
|
||||
Element feed = document.getRootElement(); |
||||
String value2 = feed.getStringValue(); |
||||
|
||||
return value2; |
||||
} |
||||
|
||||
// public boolean String getBoolean(String xml){
|
||||
// SAXReader reader = new SAXReader();
|
||||
// Document document = null;
|
||||
//
|
||||
// FRUtils.FRLogInfo("xmlTolist:xml:"+xml);
|
||||
//
|
||||
// try {
|
||||
// document = reader.read(IOUtils.strToInputStream(xml));
|
||||
// } catch (DocumentException e) {
|
||||
// FRUtils.FRLogInfo("documentException:"+e.getMessage());
|
||||
// }
|
||||
//
|
||||
// Element feed = document.getRootElement();
|
||||
//
|
||||
// return value2;
|
||||
// }
|
||||
|
||||
public static String xmlToList2(String xml){ |
||||
JSONObject resultJSON = new JSONObject(); |
||||
SAXReader reader = new SAXReader(); |
||||
Document document = null; |
||||
|
||||
FRUtils.FRLogInfo("xmlTolist2:xml:"+xml); |
||||
|
||||
try { |
||||
document = reader.read(IOUtils.strToInputStream(xml)); |
||||
} catch (DocumentException e) { |
||||
FRUtils.FRLogInfo("documentException:"+e.getMessage()); |
||||
} |
||||
|
||||
Element feed = document.getRootElement(); |
||||
|
||||
//数据集合
|
||||
List<Element> psnDataModels = feed.elements(); |
||||
|
||||
for(Element data : psnDataModels){ |
||||
String name = data.getName(); |
||||
String value = data.getStringValue(); |
||||
|
||||
if(name.equals("Success")){ |
||||
resultJSON.put(name,Boolean.parseBoolean(value)); |
||||
}else{ |
||||
resultJSON.put(name,value); |
||||
} |
||||
} |
||||
|
||||
return resultJSON.toString(); |
||||
} |
||||
} |
@ -0,0 +1,17 @@
|
||||
$.ajax({ |
||||
type:"GET", |
||||
async:false, |
||||
url:"localhost:8075/webroot/decision/url/cancelInstances", |
||||
data:{ |
||||
operateName:"returnToStart", |
||||
userCode:"用户编码", |
||||
sequenceNos:"流水号,逗号分隔" |
||||
}, |
||||
success:function(data){ |
||||
if(data.data){ |
||||
//成功
|
||||
}else{ |
||||
//失败
|
||||
} |
||||
} |
||||
}) |
Binary file not shown.
Loading…
Reference in new issue