Browse Source

提交开源任务材料

10.0
LAPTOP-SB56SG4Q\86185 3 years ago
parent
commit
78d6268c4a
  1. BIN
      JSD-9115-需求确认书V2.docx
  2. 5
      README.md
  3. 22
      plugin.xml
  4. 48
      src/main/java/com/eco/plugin/xxxx/oats/bean/AjaxResult.java
  5. 105
      src/main/java/com/eco/plugin/xxxx/oats/bean/ParamBean.java
  6. 21
      src/main/java/com/eco/plugin/xxxx/oats/config/InitializeMonitor.java
  7. 75
      src/main/java/com/eco/plugin/xxxx/oats/config/PluginSimpleConfig.java
  8. 14
      src/main/java/com/eco/plugin/xxxx/oats/controller/ControllerRegisterProvider.java
  9. 76
      src/main/java/com/eco/plugin/xxxx/oats/controller/ControllerSelf.java
  10. 52
      src/main/java/com/eco/plugin/xxxx/oats/handler/DeleteRequestInfoByJson.java
  11. 13
      src/main/java/com/eco/plugin/xxxx/oats/handler/ExtendAttrHandlerProvider.java
  12. 52
      src/main/java/com/eco/plugin/xxxx/oats/handler/ProcessDoneRequestByJson.java
  13. 52
      src/main/java/com/eco/plugin/xxxx/oats/handler/ProcessOverRequestByJson.java
  14. 56
      src/main/java/com/eco/plugin/xxxx/oats/handler/ReceiveTodoRequestByJson.java
  15. 18
      src/main/java/com/eco/plugin/xxxx/oats/handler/URLAliasProvide.java
  16. 147
      src/main/java/com/eco/plugin/xxxx/oats/shili.js
  17. 227
      src/main/java/com/eco/plugin/xxxx/oats/utils/DateUtilSelf.java
  18. 255
      src/main/java/com/eco/plugin/xxxx/oats/utils/FRUtils.java
  19. 243
      src/main/java/com/eco/plugin/xxxx/oats/utils/HttpUtils.java
  20. 94
      src/main/java/com/eco/plugin/xxxx/oats/utils/ResponseUtils.java
  21. 226
      src/main/java/com/eco/plugin/xxxx/oats/utils/Utils.java

BIN
JSD-9115-需求确认书V2.docx

Binary file not shown.

5
README.md

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

22
plugin.xml

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin>
<id>com.eco.plugin.xxxx.oats</id>
<name><![CDATA[OA待办推送]]></name>
<active>yes</active>
<version>1.0.4</version>
<env-version>10.0</env-version>
<jartime>2018-07-31</jartime>
<vendor>fr.open</vendor>
<description><![CDATA[OA待办推送]]></description>
<change-notes><![CDATA[
]]></change-notes>
<main-package>com.eco.plugin.xxxx.oats</main-package>
<lifecycle-monitor class="com.eco.plugin.xxxx.oats.config.InitializeMonitor"/>
<extra-decision>
<HttpHandlerProvider class="com.eco.plugin.xxxx.oats.handler.ExtendAttrHandlerProvider"/>
<URLAliasProvider class="com.eco.plugin.xxxx.oats.handler.URLAliasProvide"/>
</extra-decision>
<function-recorder class="com.eco.plugin.xxxx.oats.config.PluginSimpleConfig"/>
</plugin>

48
src/main/java/com/eco/plugin/xxxx/oats/bean/AjaxResult.java

@ -0,0 +1,48 @@
package com.eco.plugin.xxxx.oats.bean;
/**
* ajax 返回值
*/
public class AjaxResult {
//状态码
private int code;
//信息
private String msg;
//数据
private String data;
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
public AjaxResult(int code, String msg, String data){}
public static AjaxResult success(String data){
return new AjaxResult(200,"请求成功","");
}
public static AjaxResult error(String msg){
return new AjaxResult(-1,msg,"");
}
}

105
src/main/java/com/eco/plugin/xxxx/oats/bean/ParamBean.java

@ -0,0 +1,105 @@
package com.eco.plugin.xxxx.oats.bean;
/**
* 请求参数
*/
public class ParamBean {
//异构系统标识
private String syscode;
//流程实例id
private String flowid;
//标题
private String requestname;
//流程类型名称
private String workflowname;
//步骤名称(节点名称)
private String nodename;
//PC地址
private String pcurl;
//APP地址
private String appurl;
//创建人(原值)
private String creator;
//接收人(原值)
private String receiver;
public String getSyscode() {
return syscode;
}
public void setSyscode(String syscode) {
this.syscode = syscode;
}
public String getFlowid() {
return flowid;
}
public void setFlowid(String flowid) {
this.flowid = flowid;
}
public String getRequestname() {
return requestname;
}
public void setRequestname(String requestname) {
this.requestname = requestname;
}
public String getWorkflowname() {
return workflowname;
}
public void setWorkflowname(String workflowname) {
this.workflowname = workflowname;
}
public String getNodename() {
return nodename;
}
public void setNodename(String nodename) {
this.nodename = nodename;
}
public String getPcurl() {
return pcurl;
}
public void setPcurl(String pcurl) {
this.pcurl = pcurl;
}
public String getAppurl() {
return appurl;
}
public void setAppurl(String appurl) {
this.appurl = appurl;
}
public String getCreator() {
return creator;
}
public void setCreator(String creator) {
this.creator = creator;
}
public String getReceiver() {
return receiver;
}
public void setReceiver(String receiver) {
this.receiver = receiver;
}
}

21
src/main/java/com/eco/plugin/xxxx/oats/config/InitializeMonitor.java

@ -0,0 +1,21 @@
package com.eco.plugin.xxxx.oats.config;
import com.fr.plugin.context.PluginContext;
import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor;
/**
* @author fr.open
* @version 10.0
* Created by wink on 2021-12-03
*/
public class InitializeMonitor extends AbstractPluginLifecycleMonitor {
@Override
public void afterRun(PluginContext pluginContext) {
PluginSimpleConfig.getInstance();
}
@Override
public void beforeStop(PluginContext pluginContext) {
}
}

75
src/main/java/com/eco/plugin/xxxx/oats/config/PluginSimpleConfig.java

@ -0,0 +1,75 @@
package com.eco.plugin.xxxx.oats.config;
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.eco.plugin.xxxx.oats.config", text = "待办推送配置", source = Original.PLUGIN)
public static PluginSimpleConfig getInstance() {
if (config == null) {
config = ConfigContext.getConfigInstance(PluginSimpleConfig.class);
}
return config;
}
@Identifier(value = "receiveTodoRequestByJson", name = "接收异构系统流程", description = "接收异构系统流程", status = Status.SHOW)
private Conf<String> receiveTodoRequestByJson = Holders.simple("http://xxxx/ReceiveTodoRequestByJson");
@Identifier(value = "processDoneRequestByJson", name = "处理待办流程(变为已办)", description = "处理待办流程(变为已办)", status = Status.SHOW)
private Conf<String> processDoneRequestByJson = Holders.simple("http://xxxx/ProcessDoneRequestByJson");
@Identifier(value = "processOverRequestByJson", name = "处理办结流程(变为办结)", description = "处理办结流程(变为办结)", status = Status.SHOW)
private Conf<String> processOverRequestByJson = Holders.simple("http://xxxx/ProcessOverRequestByJson");
@Identifier(value = "deleteRequestInfoByJson", name = "删除异构系统所有待办流程(json格式)", description = "删除异构系统所有待办流程(json格式)", status = Status.SHOW)
private Conf<String> deleteRequestInfoByJson = Holders.simple("http://xxxx/deleteRequestInfoByJson");
public String getReceiveTodoRequestByJson() {
return receiveTodoRequestByJson.get();
}
public void setReceiveTodoRequestByJson(String url) {
this.receiveTodoRequestByJson.set(url);
}
public String getProcessDoneRequestByJson() {
return processDoneRequestByJson.get();
}
public void setProcessDoneRequestByJson(String url) {
this.processDoneRequestByJson.set(url);
}
public String getProcessOverRequestByJson() {
return processOverRequestByJson.get();
}
public void setProcessOverRequestByJson(String url) {
this.processOverRequestByJson.set(url);
}
public String getDeleteRequestInfoByJson() {
return deleteRequestInfoByJson.get();
}
public void setDeleteRequestInfoByJson(String url) {
this.deleteRequestInfoByJson.set(url);
}
@Override
public Object clone() throws CloneNotSupportedException {
PluginSimpleConfig cloned = (PluginSimpleConfig) super.clone();
return cloned;
}
}

14
src/main/java/com/eco/plugin/xxxx/oats/controller/ControllerRegisterProvider.java

@ -0,0 +1,14 @@
package com.eco.plugin.xxxx.oats.controller;
import com.fr.decision.fun.impl.AbstractControllerRegisterProvider;
import com.fr.plugin.transform.FunctionRecorder;
@FunctionRecorder
public class ControllerRegisterProvider extends AbstractControllerRegisterProvider {
@Override
public Class<?>[] getControllers() {
return new Class[]{
ControllerSelf.class
};
}
}

76
src/main/java/com/eco/plugin/xxxx/oats/controller/ControllerSelf.java

@ -0,0 +1,76 @@
package com.eco.plugin.xxxx.oats.controller;
import com.eco.plugin.xxxx.oats.config.PluginSimpleConfig;
import com.eco.plugin.xxxx.oats.utils.DateUtilSelf;
import com.eco.plugin.xxxx.oats.utils.HttpUtils;
import com.fr.decision.webservice.annotation.LoginStatusChecker;
import com.fr.json.JSONObject;
import com.fr.plugin.transform.FunctionRecorder;
import com.fr.third.springframework.stereotype.Controller;
import com.fr.third.springframework.web.bind.annotation.PostMapping;
import com.fr.third.springframework.web.bind.annotation.RequestBody;
import com.fr.third.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.Map;
@Controller
@LoginStatusChecker(required = false)
@FunctionRecorder
public class ControllerSelf {
@PostMapping(value = "/ofs/receiveTodoRequestByJson")
@ResponseBody
public JSONObject receiveTodoRequestByJson(@RequestBody Map<String,String> param, HttpServletRequest request, HttpServletResponse response){
String time = DateUtilSelf.DateToString(new Date(),"yyyy-MM-dd HH:mm:ss");
param.put("createdatetime",time);
param.put("receivedatetime",time);
JSONObject json = JSONObject.mapFrom(param);
String url = PluginSimpleConfig.getInstance().getReceiveTodoRequestByJson();
String result = HttpUtils.HttpPostJson(url,json.toString(),null);
return new JSONObject(result);
}
@PostMapping(value = "/ofs/processDoneRequestByJson")
@ResponseBody
public JSONObject processDoneRequestByJson(@RequestBody Map<String,String> param, HttpServletRequest request, HttpServletResponse response){
JSONObject json = JSONObject.mapFrom(param);
String url = PluginSimpleConfig.getInstance().getProcessDoneRequestByJson();
String result = HttpUtils.HttpPostJson(url,json.toString(),null);
return new JSONObject(result);
}
@PostMapping(value = "/ofs/processOverRequestByJson")
@ResponseBody
public JSONObject processOverRequestByJson(@RequestBody Map<String,String> param, HttpServletRequest request, HttpServletResponse response){
JSONObject json = JSONObject.mapFrom(param);
String url = PluginSimpleConfig.getInstance().getProcessOverRequestByJson();
String result = HttpUtils.HttpPostJson(url,json.toString(),null);
return new JSONObject(result);
}
@PostMapping(value = "/ofs/deleteRequestInfoByJson")
@ResponseBody
public JSONObject deleteRequestInfoByJson(@RequestBody Map<String,String> param, HttpServletRequest request, HttpServletResponse response){
JSONObject json = JSONObject.mapFrom(param);
String url = PluginSimpleConfig.getInstance().getDeleteRequestInfoByJson();
String result = HttpUtils.HttpPostJson(url,json.toString(),null);
return new JSONObject(result);
}
}

52
src/main/java/com/eco/plugin/xxxx/oats/handler/DeleteRequestInfoByJson.java

@ -0,0 +1,52 @@
package com.eco.plugin.xxxx.oats.handler;
import com.eco.plugin.xxxx.oats.config.PluginSimpleConfig;
import com.eco.plugin.xxxx.oats.utils.HttpUtils;
import com.eco.plugin.xxxx.oats.utils.ResponseUtils;
import com.eco.plugin.xxxx.oats.utils.Utils;
import com.fr.decision.fun.impl.BaseHttpHandler;
import com.fr.json.JSONObject;
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 DeleteRequestInfoByJson extends BaseHttpHandler {
public DeleteRequestInfoByJson() {
}
@Override
public RequestMethod getMethod() {
return RequestMethod.POST;
}
@Override
public String getPath() {
return "/ofs/deleteRequestInfoByJson";
}
@Override
public boolean isPublic() {
return true;
}
@Override
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception {
JSONObject json = Utils.getRequestBody(req);
String url = PluginSimpleConfig.getInstance().getDeleteRequestInfoByJson();
String result = HttpUtils.HttpPostJson(url,json.toString(),null);
ResponseUtils.response(res,new JSONObject(result));
}
}

13
src/main/java/com/eco/plugin/xxxx/oats/handler/ExtendAttrHandlerProvider.java

@ -0,0 +1,13 @@
package com.eco.plugin.xxxx.oats.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 ReceiveTodoRequestByJson(),new DeleteRequestInfoByJson(),new ProcessOverRequestByJson(),new ProcessDoneRequestByJson()
};
}
}

52
src/main/java/com/eco/plugin/xxxx/oats/handler/ProcessDoneRequestByJson.java

@ -0,0 +1,52 @@
package com.eco.plugin.xxxx.oats.handler;
import com.eco.plugin.xxxx.oats.config.PluginSimpleConfig;
import com.eco.plugin.xxxx.oats.utils.HttpUtils;
import com.eco.plugin.xxxx.oats.utils.ResponseUtils;
import com.eco.plugin.xxxx.oats.utils.Utils;
import com.fr.decision.fun.impl.BaseHttpHandler;
import com.fr.json.JSONObject;
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 ProcessDoneRequestByJson extends BaseHttpHandler {
public ProcessDoneRequestByJson() {
}
@Override
public RequestMethod getMethod() {
return RequestMethod.POST;
}
@Override
public String getPath() {
return "/ofs/processDoneRequestByJson";
}
@Override
public boolean isPublic() {
return true;
}
@Override
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception {
JSONObject json = Utils.getRequestBody(req);
String url = PluginSimpleConfig.getInstance().getProcessDoneRequestByJson();
String result = HttpUtils.HttpPostJson(url,json.toString(),null);
ResponseUtils.response(res,new JSONObject(result));
}
}

52
src/main/java/com/eco/plugin/xxxx/oats/handler/ProcessOverRequestByJson.java

@ -0,0 +1,52 @@
package com.eco.plugin.xxxx.oats.handler;
import com.eco.plugin.xxxx.oats.config.PluginSimpleConfig;
import com.eco.plugin.xxxx.oats.utils.HttpUtils;
import com.eco.plugin.xxxx.oats.utils.ResponseUtils;
import com.eco.plugin.xxxx.oats.utils.Utils;
import com.fr.decision.fun.impl.BaseHttpHandler;
import com.fr.json.JSONObject;
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 ProcessOverRequestByJson extends BaseHttpHandler {
public ProcessOverRequestByJson() {
}
@Override
public RequestMethod getMethod() {
return RequestMethod.POST;
}
@Override
public String getPath() {
return "/ofs/processOverRequestByJson";
}
@Override
public boolean isPublic() {
return true;
}
@Override
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception {
JSONObject json = Utils.getRequestBody(req);
String url = PluginSimpleConfig.getInstance().getProcessOverRequestByJson();
String result = HttpUtils.HttpPostJson(url,json.toString(),null);
ResponseUtils.response(res,new JSONObject(result));
}
}

56
src/main/java/com/eco/plugin/xxxx/oats/handler/ReceiveTodoRequestByJson.java

@ -0,0 +1,56 @@
package com.eco.plugin.xxxx.oats.handler;
import com.eco.plugin.xxxx.oats.config.PluginSimpleConfig;
import com.eco.plugin.xxxx.oats.utils.DateUtilSelf;
import com.eco.plugin.xxxx.oats.utils.HttpUtils;
import com.eco.plugin.xxxx.oats.utils.ResponseUtils;
import com.eco.plugin.xxxx.oats.utils.Utils;
import com.fr.decision.fun.impl.BaseHttpHandler;
import com.fr.json.JSONObject;
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;
import java.util.Date;
@FunctionRecorder
public class ReceiveTodoRequestByJson extends BaseHttpHandler {
public ReceiveTodoRequestByJson() {
}
@Override
public RequestMethod getMethod() {
return RequestMethod.POST;
}
@Override
public String getPath() {
return "/ofs/receiveTodoRequestByJson";
}
@Override
public boolean isPublic() {
return true;
}
@Override
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception {
JSONObject param = Utils.getRequestBody(req);
String time = DateUtilSelf.DateToString(new Date(),"yyyy-MM-dd HH:mm:ss");
param.put("createdatetime",time);
param.put("receivedatetime",time);
String url = PluginSimpleConfig.getInstance().getReceiveTodoRequestByJson();
String result = HttpUtils.HttpPostJson(url,param.toString(),null);
ResponseUtils.response(res,new JSONObject(result));
}
}

18
src/main/java/com/eco/plugin/xxxx/oats/handler/URLAliasProvide.java

@ -0,0 +1,18 @@
package com.eco.plugin.xxxx.oats.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("/ofs/receiveTodoRequestByJson","/ofs/receiveTodoRequestByJson",true),
URLAliasFactory.createPluginAlias("/ofs/processDoneRequestByJson","/ofs/processDoneRequestByJson",true),
URLAliasFactory.createPluginAlias("/ofs/processOverRequestByJson","/ofs/processOverRequestByJson",true),
URLAliasFactory.createPluginAlias("/ofs/deleteRequestInfoByJson","/ofs/deleteRequestInfoByJson",true),
};
}
}

147
src/main/java/com/eco/plugin/xxxx/oats/shili.js

@ -0,0 +1,147 @@
//接收待办流程(json格式)
var receviers = ['hejia','hejia2'];
for(var i=0;i<receviers.length;i++){
var obj = {
"syscode":"异构系统标识",
"flowid":"流程实例id",
"requestname":"标题",
"workflowname":"流程类型名称",
"nodename":"步骤名称(节点名称)",
"pcurl":"PC地址",
"appurl":"APP地址",
"creator":"创建人(原值)",
"receiver":receviers[i]
};
$.ajax({
type:"post",
async:false,
url:"/webroot/decision/url/ofs/receiveTodoRequestByJson",
contentType:"application/json;charset=UTF-8",
data:JSON.stringify(obj),
success:function(data){
//异构系统标识
var syscode = data.syscode;
//数据类型 IsUse:统一待办中心 OtherSys:异构系统 WfType:流程类型 WfData:流程数据 SetParam:参数设置
var dateType = data.dateType;
// 操作类型 AutoNew :自动创建 New:新建 AutoEdit:自动更新 Edit:编辑 Del:删除 Check:检测 Set:设置
var operType = data.operType;
// 操作结果 1:成功 0:失败
var operResult = data.operResult;
//错误信息
var message = data.message;
},
error:function(data){
//请求失败
}
})
}
// 处理待办流程(变为已办)(json格式)
var obj = {
"syscode":"异构系统标识",
"flowid":"流程实例id",
"requestname":"标题",
"workflowname":"流程类型名称",
"nodename":"步骤名称(节点名称)",
"receiver":"接收人(原值)",
"prevnodename":"上一节点审批名称",
"approveduser":"审批人",
"approvedaction":"审批动作",
"reserve1":"预留字段"
};
$.ajax({
type:"post",
async:false,
url:"/webroot/decision/url/ofs/processDoneRequestByJson",
contentType:"application/json;charset=UTF-8",
data:JSON.stringify(obj),
success:function(data){
//异构系统标识
var syscode = data.syscode;
//数据类型 IsUse:统一待办中心 OtherSys:异构系统 WfType:流程类型 WfData:流程数据 SetParam:参数设置
var dateType = data.dateType;
// 操作类型 AutoNew :自动创建 New:新建 AutoEdit:自动更新 Edit:编辑 Del:删除 Check:检测 Set:设置
var operType = data.operType;
// 操作结果 1:成功 0:失败
var operResult = data.operResult;
//错误信息
var message = data.message;
},
error:function(data){
//请求失败
}
})
// 处理办结流程(变为办结)(json格式)
var obj ={
"syscode":"异构系统标识",
"flowid":"流程实例id",
"requestname":"标题",
"workflowname":"流程类型名称",
"nodename":"步骤名称(节点名称)",
"receiver":"接收人(原值)",
"prevnodename":"上一节点审批名称",
"approveduser":"审批人",
"approvedaction":"审批动作",
"reserve1":"预留字段"
};
$.ajax({
type:"post",
async:false,
url:"/webroot/decision/url/ofs/processOverRequestByJson",
contentType:"application/json;charset=UTF-8",
data:JSON.stringify(obj),
success:function(data){
//异构系统标识
var syscode = data.syscode;
//数据类型 IsUse:统一待办中心 OtherSys:异构系统 WfType:流程类型 WfData:流程数据 SetParam:参数设置
var dateType = data.dateType;
// 操作类型 AutoNew :自动创建 New:新建 AutoEdit:自动更新 Edit:编辑 Del:删除 Check:检测 Set:设置
var operType = data.operType;
// 操作结果 1:成功 0:失败
var operResult = data.operResult;
//错误信息
var message = data.message;
},
error:function(data){
//请求失败
}
})
// 删除异构系统所有待办流程(json格式)
var obj = {
"syscode":"异构系统标识",
"flowid":"流程实例id"
};
$.ajax({
type:"post",
async:false,
url:"/webroot/decision/url/ofs/deleteRequestInfoByJson",
contentType:"application/json;charset=UTF-8",
data:JSON.stringify(obj),
success:function(data){
//异构系统标识
var syscode = data.syscode;
//数据类型 IsUse:统一待办中心 OtherSys:异构系统 WfType:流程类型 WfData:流程数据 SetParam:参数设置
var dateType = data.dateType;
// 操作类型 AutoNew :自动创建 New:新建 AutoEdit:自动更新 Edit:编辑 Del:删除 Check:检测 Set:设置
var operType = data.operType;
// 操作结果 1:成功 0:失败
var operResult = data.operResult;
//错误信息
var message = data.message;
},
error:function(data){
//请求失败
}
})

227
src/main/java/com/eco/plugin/xxxx/oats/utils/DateUtilSelf.java

@ -0,0 +1,227 @@
package com.eco.plugin.xxxx.oats.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天内每s一天的日期
* @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);
}
}

255
src/main/java/com/eco/plugin/xxxx/oats/utils/FRUtils.java

@ -0,0 +1,255 @@
package com.eco.plugin.xxxx.oats.utils;
import com.fr.base.ServerConfig;
import com.fr.base.TableData;
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.file.TableDataConfig;
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.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
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
* @param token
* @param url
*/
public static void loginByToken(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse,String token,String url){
FineLoggerFactory.getLogger().info("FRLOG:token:"+token);
FineLoggerFactory.getLogger().info("FRLOG:跳转链接:"+url);
//判断用户名是否为空
if(!Utils.isNullStr(token)){
writeToken2Cookie(httpServletResponse,token,-1);
HttpSession session = httpServletRequest.getSession(true);
httpServletRequest.setAttribute(DecisionServiceConstants.FINE_AUTH_TOKEN_NAME,token);
session.setAttribute(DecisionServiceConstants.FINE_AUTH_TOKEN_NAME, token);
if(!Utils.isNullStr(url)){
try {
httpServletResponse.sendRedirect(url);
} catch (IOException e) {
ResponseUtils.failedResponse(httpServletResponse,"跳转异常!");
FineLoggerFactory.getLogger().info("FRLOG:跳转异常!");
}
}
}else{
ResponseUtils.failedResponse(httpServletResponse,"token不能为空!");
FineLoggerFactory.getLogger().info("FRLOG:token不能为空!");
}
}
/**
* 获取token
* @param httpServletRequest
* @param httpServletResponse
* @param username
* @return
*/
public static String getToken(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse,String username){
String token = "";
try {
token = LoginService.getInstance().login(httpServletRequest, httpServletResponse, username);
} catch (Exception e) {
FineLoggerFactory.getLogger().info("FRLOG:获取token失败"+e.getMessage());
}
return token;
}
private static void writeToken2Cookie(HttpServletResponse var1, String var2, int var3) {
try {
if (StringUtils.isNotEmpty(var2)) {
Cookie var4 = new Cookie("fine_auth_token", var2);
long var5 = var3 == -2 ? 1209600000L : (long)var3;
var4.setMaxAge((int)var5);
var4.setPath(ServerConfig.getInstance().getCookiePath());
var1.addCookie(var4);
Cookie var7 = new Cookie("fine_remember_login", String.valueOf(var3 == -2 ? -2 : -1));
var7.setMaxAge((int)var5);
var7.setPath(ServerConfig.getInstance().getCookiePath());
var1.addCookie(var7);
} else {
FineLoggerFactory.getLogger().error("empty token cannot save.");
}
} catch (Exception var8) {
FineLoggerFactory.getLogger().error(var8.getMessage(), var8);
}
}
/**
*
* @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);
}
/**
* 打印FR日志-error
* @param message
*/
public static void FRLogError(String message){
FineLoggerFactory.getLogger().error("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);
}
public static TableData getTableData(String serverDataSetName){
TableData userInfo = TableDataConfig.getInstance().getTableData("serverDataSetName");
// DataModel userInfoDM = userInfo.createDataModel(Calculator.createCalculator());
return userInfo;
}
}

243
src/main/java/com/eco/plugin/xxxx/oats/utils/HttpUtils.java

@ -0,0 +1,243 @@
package com.eco.plugin.xxxx.oats.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.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 httpGet(String url,Cookie[] cookies,Map<String,String> header){
FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--url:"+url);
//创建httpClient
CloseableHttpClient httpclient = createHttpClient(cookies);
HttpGet getMethod = new HttpGet(url);
if(header != null && header.size() > 0){
Set<String> keySet = header.keySet();
for(String key : keySet){
getMethod.setHeader(key,header.get(key));
}
}
try {
HttpResponse response = httpclient.execute(getMethod);
int status =response.getStatusLine().getStatusCode();
HttpEntity entity = response.getEntity();
String returnResult = EntityUtils.toString(entity, "utf-8");
FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--status:"+status);
FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--returnResult:"+returnResult);
httpclient.close();
if (status == HttpStatus.SC_OK) {
return returnResult;
}
} catch (Exception e) {
FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--exception:"+e.getMessage());
}
try {
httpclient.close();
} catch (Exception e) {
FineLoggerFactory.getLogger().info("FRLOG:http关闭异常:"+e.getMessage());
}
return "";
}
/**
* HttpPost请求
* @param postMethod
* @return
*/
private static String HttpPost(HttpPost postMethod){
CloseableHttpClient httpclient = createHttpClient(null);
try {
HttpResponse response = httpclient.execute(postMethod);
int status = response.getStatusLine().getStatusCode();
HttpEntity entity = response.getEntity();
String returnResult = EntityUtils.toString(entity, "utf-8");
FineLoggerFactory.getLogger().info("FRLOG:HttpPost:status:"+status);
FineLoggerFactory.getLogger().info("FRLOG:HttpPost:returnResult:"+returnResult);
httpclient.close();
if (status == HttpStatus.SC_OK) {
return returnResult;
}
} catch (Exception e) {
FineLoggerFactory.getLogger().info("FRLOG:HttpPost:exception:"+e.getMessage());
}
try {
httpclient.close();
} catch (Exception e) {
FineLoggerFactory.getLogger().info("FRLOG:http关闭异常:"+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;charset=");
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,"utf-8");
} catch (Exception 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){
Set<String> keySet = header.keySet();
for(String key : keySet){
postMethod.setHeader(key,header.get(key));
}
}
if(param != null && param.size() > 0){
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 (Exception e) {
FRUtils.FRLogInfo("exception:"+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;
}
}

94
src/main/java/com/eco/plugin/xxxx/oats/utils/ResponseUtils.java

@ -0,0 +1,94 @@
package com.eco.plugin.xxxx.oats.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 responseXml(HttpServletResponse res,String xml){
PrintWriter pw;
try {
pw = WebUtils.createPrintWriter(res);
} catch (Exception e) {
FineLoggerFactory.getLogger().info(e.getMessage());
return;
}
res.setContentType("text/xml;charset=utf-8");
pw.println(xml);
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();
}
}

226
src/main/java/com/eco/plugin/xxxx/oats/utils/Utils.java

@ -0,0 +1,226 @@
package com.eco.plugin.xxxx.oats.utils;
import com.fr.base.TemplateUtils;
import com.fr.data.NetworkHelper;
import com.fr.io.utils.ResourceIOUtils;
import com.fr.json.JSONObject;
import com.fr.stable.CodeUtils;
import com.fr.stable.StringUtils;
import com.fr.third.org.apache.commons.codec.digest.DigestUtils;
import com.fr.web.utils.WebUtils;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.InputStream;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
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);
}
/**
* 帆软shaEncode加密
*/
public static String shaEncode(String str){
return CodeUtils.sha256Encode(str);
}
/**
* 获取uuid
*/
public static String uuid(){
return UUID.randomUUID().toString();
}
/**
* 替换空字符串
* @param str
* @param replace
* @return
*/
public static String replaceNullStr(String str,String replace){
if(isNullStr(str)){
return replace;
}
return str;
}
/**
* 获取请求体
* @param req
* @return
*/
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;
}
/**
* 获取ip
* @return
*/
public static String getIp(HttpServletRequest req){
String realIp = req.getHeader("X-Real-IP");
String fw = req.getHeader("X-Forwarded-For");
if (StringUtils.isNotEmpty(fw) && !"unKnown".equalsIgnoreCase(fw)) {
int var3 = fw.indexOf(",");
return var3 != -1 ? fw.substring(0, var3) : fw;
} else {
fw = realIp;
if (StringUtils.isNotEmpty(realIp) && !"unKnown".equalsIgnoreCase(realIp)) {
return realIp;
} else {
if (StringUtils.isBlank(realIp) || "unknown".equalsIgnoreCase(realIp)) {
fw = req.getHeader("Proxy-Client-IP");
}
if (StringUtils.isBlank(fw) || "unknown".equalsIgnoreCase(fw)) {
fw = req.getHeader("WL-Proxy-Client-IP");
}
if (StringUtils.isBlank(fw) || "unknown".equalsIgnoreCase(fw)) {
fw = req.getHeader("HTTP_CLIENT_IP");
}
if (StringUtils.isBlank(fw) || "unknown".equalsIgnoreCase(fw)) {
fw = req.getHeader("HTTP_X_FORWARDED_FOR");
}
if (StringUtils.isBlank(fw) || "unknown".equalsIgnoreCase(fw)) {
fw = req.getRemoteAddr();
}
return fw;
}
}
}
/**
* 根据key获取cookie
* @param req
* @return
*/
public static String getCookieByKey(HttpServletRequest req,String key){
Cookie[] cookies = req.getCookies();
String cookie = "";
if(cookies == null || cookies.length <=0){
return "";
}
for(int i = 0; i < cookies.length; i++) {
Cookie item = cookies[i];
if (item.getName().equalsIgnoreCase(key)) {
cookie = item.getValue();
}
}
FRUtils.FRLogInfo("cookie:"+cookie);
return cookie;
}
/**
* 判断是否是手机端的链接
* @param req
* @return
*/
public static boolean isMobile(HttpServletRequest req) {
String[] mobileArray = {"iPhone", "iPad", "android", "windows phone", "xiaomi"};
String userAgent = req.getHeader("user-agent");
if (userAgent != null && userAgent.toUpperCase().contains("MOBILE")) {
for(String mobile : mobileArray) {
if(userAgent.toUpperCase().contains(mobile.toUpperCase())) {
return true;
}
}
}
return NetworkHelper.getDevice(req).isMobile();
}
/**
* 只编码中文
* @param url
* @return
*/
public static String encodeCH(String url ){
Matcher matcher = Pattern.compile("[\\u4e00-\\u9fa5]").matcher(url);
while(matcher.find()){
String chn = matcher.group();
url = url.replaceAll(chn, URLEncoder.encode(chn));
}
return url;
}
/**
* 获取web-inf文件夹下的文件
* filename /resources/ip4enc.properties
*/
public static InputStream getResourcesFile(String filename){
return ResourceIOUtils.read(filename);
}
public static void toErrorPage(HttpServletResponse res,String path,Map<String, String> parameterMap){
if(parameterMap == null){
parameterMap = new HashMap<String, String>();
}
try {
String macPage = TemplateUtils.renderTemplate(path, parameterMap);
WebUtils.printAsString(res, macPage);
}catch (Exception e){
FRUtils.FRLogError("跳转页面异常");
}
}
}
Loading…
Cancel
Save