xiamaofa
2 years ago
commit
38e0637a6f
38 changed files with 8356 additions and 0 deletions
@ -0,0 +1,122 @@
|
||||
|
||||
apply plugin: 'java' |
||||
|
||||
|
||||
ext { |
||||
/** |
||||
* 项目中依赖的jar的路径 |
||||
* 1.如果依赖的jar需要打包到zip中,放置在lib根目录下 |
||||
* 2.如果依赖的jar仅仅是编译时需要,防止在lib下子目录下即可 |
||||
*/ |
||||
libPath = "$projectDir/../webroot/WEB-INF/lib" |
||||
|
||||
/** |
||||
* 是否对插件的class进行加密保护,防止反编译 |
||||
*/ |
||||
guard = false |
||||
|
||||
def pluginInfo = getPluginInfo() |
||||
pluginPre = "fine-plugin" |
||||
pluginName = pluginInfo.id |
||||
pluginVersion = pluginInfo.version |
||||
|
||||
outputPath = "$projectDir/../webroot/WEB-INF/plugins/plugin-" + pluginName + "-1.0/classes" |
||||
} |
||||
|
||||
group = 'com.fr.plugin' |
||||
version = '10.0' |
||||
sourceCompatibility = '8' |
||||
|
||||
sourceSets { |
||||
main { |
||||
java.outputDir = file(outputPath) |
||||
output.resourcesDir = file(outputPath) |
||||
} |
||||
} |
||||
|
||||
ant.importBuild("encrypt.xml") |
||||
//定义ant变量 |
||||
ant.projectDir = projectDir |
||||
ant.references["compile.classpath"] = ant.path { |
||||
fileset(dir: libPath, includes: '**/*.jar') |
||||
fileset(dir: ".",includes:"**/*.jar" ) |
||||
} |
||||
|
||||
classes.dependsOn('clean') |
||||
|
||||
task copyFiles(type: Copy,dependsOn: 'classes'){ |
||||
from outputPath |
||||
into "$projectDir/classes" |
||||
} |
||||
|
||||
task preJar(type:Copy,dependsOn: guard ? 'compile_encrypt_javas' : 'compile_plain_javas'){ |
||||
from "$projectDir/classes" |
||||
into "$projectDir/transform-classes" |
||||
include "**/*.*" |
||||
} |
||||
jar.dependsOn("preJar") |
||||
|
||||
task makeJar(type: Jar,dependsOn: preJar){ |
||||
from fileTree(dir: "$projectDir/transform-classes") |
||||
baseName pluginPre |
||||
appendix pluginName |
||||
version pluginVersion |
||||
destinationDir = file("$buildDir/libs") |
||||
|
||||
doLast(){ |
||||
delete file("$projectDir/classes") |
||||
delete file("$projectDir/transform-classes") |
||||
} |
||||
} |
||||
|
||||
task copyFile(type: Copy,dependsOn: ["makeJar"]){ |
||||
from "$buildDir/libs" |
||||
from("$projectDir/lib") { |
||||
include "*.jar" |
||||
} |
||||
from "$projectDir/plugin.xml" |
||||
into file("$buildDir/temp/plugin") |
||||
} |
||||
|
||||
task zip(type:Zip,dependsOn:["copyFile"]){ |
||||
from "$buildDir/temp/plugin" |
||||
destinationDir file("$buildDir/install") |
||||
baseName pluginPre |
||||
appendix pluginName |
||||
version pluginVersion |
||||
} |
||||
|
||||
//控制build时包含哪些文件,排除哪些文件 |
||||
processResources { |
||||
// exclude everything |
||||
// 用*.css没效果 |
||||
// exclude '**/*.css' |
||||
// except this file |
||||
// include 'xx.xml' |
||||
} |
||||
|
||||
/*读取plugin.xml中的version*/ |
||||
def getPluginInfo(){ |
||||
def xmlFile = file("plugin.xml") |
||||
if (!xmlFile.exists()) { |
||||
return ["id":"none", "version":"1.0.0"] |
||||
} |
||||
def plugin = new XmlParser().parse(xmlFile) |
||||
def version = plugin.version[0].text() |
||||
def id = plugin.id[0].text() |
||||
return ["id":id,"version":version] |
||||
} |
||||
|
||||
repositories { |
||||
mavenLocal() |
||||
maven { |
||||
url = uri('http://mvn.finedevelop.com/repository/maven-public/') |
||||
} |
||||
} |
||||
|
||||
dependencies { |
||||
//使用本地jar |
||||
implementation fileTree(dir: 'lib', include: ['**/*.jar']) |
||||
implementation fileTree(dir: libPath, include: ['**/*.jar']) |
||||
} |
||||
|
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
||||
<project> |
||||
<target name="compile_encrypt_javas" depends="copyFiles"> |
||||
<echo message="加密文件"/> |
||||
<echo message="${projectDir}"/> |
||||
<taskdef name="pretreatment" classname="com.fr.plugin.pack.PluginPretreatmentTask"> |
||||
<classpath refid="compile.classpath"/> |
||||
</taskdef> |
||||
<pretreatment baseDir="${projectDir}"/> |
||||
</target> |
||||
<target name="compile_plain_javas" depends="copyFiles"> |
||||
</target> |
||||
</project> |
Binary file not shown.
Binary file not shown.
@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin> |
||||
<id>com.eco.plugin.wink.workflow</id> |
||||
<name><![CDATA[流程管理插件]]></name> |
||||
<active>yes</active> |
||||
<version>1.0.1</version> |
||||
<env-version>10.0</env-version> |
||||
<jartime>2018-07-31</jartime> |
||||
<vendor>wink</vendor> |
||||
<description><![CDATA[流程管理插件]]></description> |
||||
<change-notes><![CDATA[ |
||||
2022-09-13 代码初始化 |
||||
]]></change-notes> |
||||
<main-package>com.eco.plugin.wink.workflow</main-package> |
||||
|
||||
<extra-decision> |
||||
<WebResourceProvider class="com.eco.plugin.wink.workflow.webresource.WebResourceProvider"/> |
||||
<ControllerRegisterProvider class="com.eco.plugin.wink.workflow.controller.ControllerRegisterProvider"/> |
||||
</extra-decision> |
||||
|
||||
<extra-core> |
||||
<DBAccessProvider class="com.eco.plugin.wink.workflow.db.controller.WorkFlowController"/> |
||||
<DBAccessProvider class="com.eco.plugin.wink.workflow.db.controller.FormDbController"/> |
||||
<DBAccessProvider class="com.eco.plugin.wink.workflow.db.controller.WorkflowConfigDbController"/> |
||||
<DBAccessProvider class="com.eco.plugin.wink.workflow.db.controller.WorkFlowProcessController"/> |
||||
</extra-core> |
||||
|
||||
<function-recorder class="com.eco.plugin.wink.workflow.webresource.WebResourceProvider"/> |
||||
|
||||
|
||||
</plugin> |
@ -0,0 +1,21 @@
|
||||
package com.eco.plugin.wink.workflow.controller; |
||||
|
||||
import com.fr.decision.fun.impl.AbstractControllerRegisterProvider; |
||||
import com.fr.plugin.context.PluginContexts; |
||||
import com.fr.stable.fun.Authorize; |
||||
|
||||
@Authorize(callSignKey = "com.eco.plugin.wink.zjgintegrate") |
||||
public class ControllerRegisterProvider extends AbstractControllerRegisterProvider { |
||||
@Override |
||||
public Class<?>[] getControllers() { |
||||
|
||||
if(!PluginContexts.currentContext().isAvailable()) { |
||||
return new Class[]{}; |
||||
} |
||||
|
||||
return new Class[]{ |
||||
ControllerSelf.class,FormController.class,WorkflowConfigController.class, |
||||
DataProcessingController.class,WorkflowProcessController.class |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,150 @@
|
||||
package com.eco.plugin.wink.workflow.controller; |
||||
|
||||
import com.eco.plugin.wink.workflow.db.bean.DBLinkEntity; |
||||
import com.eco.plugin.wink.workflow.db.bean.FormDefEntity; |
||||
import com.eco.plugin.wink.workflow.db.bean.FormDetailEntity; |
||||
import com.eco.plugin.wink.workflow.db.controller.WorkFlowController; |
||||
import com.eco.plugin.wink.workflow.utils.DateUtilSelf; |
||||
import com.eco.plugin.wink.workflow.utils.ResponseUtils; |
||||
import com.eco.plugin.wink.workflow.utils.Utils; |
||||
import com.fr.decision.webservice.annotation.LoginStatusChecker; |
||||
import com.fr.json.JSONArray; |
||||
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.ArrayList; |
||||
import java.util.List; |
||||
import java.util.UUID; |
||||
|
||||
@Controller |
||||
@LoginStatusChecker(required = false) |
||||
@FunctionRecorder |
||||
public class ControllerSelf { |
||||
|
||||
/** |
||||
* 获取全部数据库链接 |
||||
* @param req |
||||
* @param res |
||||
*/ |
||||
@PostMapping(value = "/workflow/getAllDbLink") |
||||
@ResponseBody |
||||
public void getAllDbLink(HttpServletRequest req,HttpServletResponse res){ |
||||
List<DBLinkEntity> dbLinkList = WorkFlowController.getAllDBLink(); |
||||
ResponseUtils.response(res,new JSONObject().put("data",dbLinkList)); |
||||
} |
||||
|
||||
/** |
||||
* 根据id获取单个数据库链接 |
||||
* @param req |
||||
* @param res |
||||
*/ |
||||
@PostMapping(value = "/workflow/getDbLinkById") |
||||
@ResponseBody |
||||
public DBLinkEntity getDbLinkById(HttpServletRequest req,HttpServletResponse res){ |
||||
String id = Utils.getRequestBody(req).getString("id"); |
||||
DBLinkEntity dbLink = WorkFlowController.getDBLinkById(id); |
||||
return dbLink; |
||||
} |
||||
|
||||
@PostMapping(value = "/workflow/addDbLink") |
||||
@ResponseBody |
||||
public void addDbLink(HttpServletRequest req, HttpServletResponse res, @RequestBody DBLinkEntity dbLink){ |
||||
String now = DateUtilSelf.getNow(); |
||||
if(Utils.isNullStr(dbLink.getId())){ |
||||
dbLink.setId(UUID.randomUUID().toString()); |
||||
dbLink.setCreatetime(now); |
||||
} |
||||
|
||||
if(Utils.isNotNullStr(dbLink.getId())){ |
||||
dbLink.setCreatetime(WorkFlowController.getDBLinkById(dbLink.getId()).getCreatetime()); |
||||
} |
||||
|
||||
dbLink.setUpdatetime(now); |
||||
WorkFlowController.singleDBLink(dbLink,null); |
||||
ResponseUtils.successResponse(res,"success"); |
||||
} |
||||
|
||||
@PostMapping(value = "/workflow/deleteDBLink") |
||||
@ResponseBody |
||||
public void deleteDBLink(HttpServletRequest req, HttpServletResponse res, @RequestBody DBLinkEntity dbLink){ |
||||
WorkFlowController.singleDBLink(null,dbLink); |
||||
ResponseUtils.successResponse(res,"success"); |
||||
} |
||||
|
||||
@PostMapping(value = "/workflow/importForm") |
||||
@ResponseBody |
||||
public void importForm(HttpServletRequest req, HttpServletResponse res){ |
||||
JSONObject json = Utils.getRequestBody(req); |
||||
String paramstr = json.getString("data"); |
||||
JSONArray params = new JSONArray(paramstr); |
||||
for(int i=0;i<params.length();i++){ |
||||
JSONObject param = params.getJSONObject(i); |
||||
String formid = addForm(param); |
||||
|
||||
addFormField(formid,param.getJsonArray("fields")); |
||||
} |
||||
|
||||
|
||||
ResponseUtils.successResponse(res,"success"); |
||||
} |
||||
|
||||
@PostMapping(value = "/workflow/getFormList") |
||||
@ResponseBody |
||||
public void getFormList(HttpServletRequest req, HttpServletResponse res){ |
||||
JSONObject json = Utils.getRequestBody(req); |
||||
|
||||
String formid = addForm(json); |
||||
|
||||
addFormField(formid,json.getJsonArray("fields")); |
||||
ResponseUtils.successResponse(res,"success"); |
||||
} |
||||
|
||||
private void addFormField(String formid, JSONArray fields) { |
||||
List<FormDetailEntity> formDetailEntitys = new ArrayList<>(); |
||||
|
||||
for(int i=0;i< fields.length();i++){ |
||||
FormDetailEntity fde = new FormDetailEntity(); |
||||
String id = UUID.randomUUID().toString(); |
||||
JSONObject field = fields.getJSONObject(i); |
||||
String fieldname = field.getString("fieldname"); |
||||
String fielddesc = field.getString("fielddesc"); |
||||
fde.setId(id); |
||||
fde.setFormid(formid); |
||||
fde.setFieldname(fieldname); |
||||
fde.setFielddec(fielddesc); |
||||
fde.setSort(String.valueOf(i)); |
||||
formDetailEntitys.add(fde); |
||||
} |
||||
|
||||
WorkFlowController.batch(formDetailEntitys,null); |
||||
} |
||||
|
||||
/** |
||||
* 添加表单 |
||||
* @param json |
||||
* @return |
||||
*/ |
||||
private String addForm(JSONObject json) { |
||||
String tablename = json.getString("tablename"); |
||||
String formname = json.getString("formname"); |
||||
FormDefEntity fde = new FormDefEntity(); |
||||
String id = UUID.randomUUID().toString(); |
||||
fde.setId(id); |
||||
fde.setTablename(tablename); |
||||
fde.setFormname(formname); |
||||
String now = DateUtilSelf.getNow(); |
||||
fde.setCreatetime(now); |
||||
fde.setUpdatetime(now); |
||||
//可用
|
||||
fde.setStatus("0"); |
||||
WorkFlowController.singleForm(fde,null); |
||||
|
||||
return id; |
||||
} |
||||
} |
@ -0,0 +1,178 @@
|
||||
package com.eco.plugin.wink.workflow.controller; |
||||
|
||||
import com.eco.plugin.wink.workflow.db.bean.FormDefEntity; |
||||
import com.eco.plugin.wink.workflow.db.bean.FormDetailEntity; |
||||
import com.eco.plugin.wink.workflow.db.bean.WorkflowDefEntity; |
||||
import com.eco.plugin.wink.workflow.db.bean.WorkflowNodeEntity; |
||||
import com.eco.plugin.wink.workflow.db.controller.FormDbController; |
||||
import com.eco.plugin.wink.workflow.db.controller.WorkflowConfigDbController; |
||||
import com.eco.plugin.wink.workflow.utils.*; |
||||
import com.fr.decision.webservice.annotation.LoginStatusChecker; |
||||
import com.fr.json.JSONArray; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.third.springframework.stereotype.Controller; |
||||
import com.fr.third.springframework.web.bind.annotation.PostMapping; |
||||
import com.fr.third.springframework.web.bind.annotation.ResponseBody; |
||||
import org.nfunk.jep.function.Str; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.util.*; |
||||
|
||||
@Controller |
||||
@LoginStatusChecker(required = false) |
||||
public class DataProcessingController { |
||||
|
||||
@PostMapping(value = "/workflow/dataprocess/add") |
||||
@ResponseBody |
||||
public void add(HttpServletRequest req, HttpServletResponse res) throws Exception { |
||||
JSONObject json = Utils.getRequestBody(req); |
||||
String formid = json.getString("formid"); |
||||
FormDefEntity form = FormDbController.getById(formid); |
||||
|
||||
JSONArray fields = json.getJSONArray("field"); |
||||
|
||||
String sql = generateInsertSql(req,form,fields); |
||||
FRUtils.FRLogInfo("sql:"+sql); |
||||
JDBCUtils.update(sql); |
||||
} |
||||
|
||||
@PostMapping(value = "/workflow/dataprocess/getPageData") |
||||
@ResponseBody |
||||
public void getPageData(HttpServletRequest req, HttpServletResponse res) throws Exception { |
||||
JSONObject json = Utils.getRequestBody(req); |
||||
String formid = json.getString("formid"); |
||||
int page = json.getInt("page"); |
||||
int count = json.getInt("count"); |
||||
String createTime = json.getString("createtime"); |
||||
|
||||
//1、数据录入 2、数据审核
|
||||
String from = json.getString("from"); |
||||
|
||||
FormDefEntity form = FormDbController.getById(formid); |
||||
|
||||
String sql = generateQuerySql(form); |
||||
|
||||
if(Utils.isNotNullStr(createTime)){ |
||||
sql += " where createtime >= "+createTime; |
||||
} |
||||
|
||||
String username =FRUserUtils.getCurrentUser(req).getUserName(); |
||||
|
||||
if("1".equals(from)){ |
||||
sql+= sql.contains("where") ? " and createuser = '"+username+"'": " where createuser='"+username+"'"; |
||||
}else{ |
||||
sql+= sql.contains("where") ? " and currentuser like '%["+username+"]%'" : " where currentuser like '%["+username+"]%'"; |
||||
} |
||||
|
||||
sql += " order by createtime limit "+(page - 1)*count+","+count; |
||||
|
||||
FRUtils.FRLogInfo("sql:"+sql); |
||||
|
||||
String[] column = getColumn(form); |
||||
|
||||
List<Map<String,Object>> items = JDBCUtils.getResult(sql,column,formid); |
||||
|
||||
String countSql = "select count(id) from " + form.getTablename(); |
||||
|
||||
Map<String,Object> result = new HashMap<>(); |
||||
result.put("page",page); |
||||
result.put("count",count); |
||||
result.put("items",items); |
||||
ResponseUtils.successResponse(res,new JSONObject().put("page",page).put("count",count).put("items",items).put("total",JDBCUtils.getCount(countSql)).toString()); |
||||
} |
||||
|
||||
@PostMapping(value = "/workflow/dataprocess/getData") |
||||
@ResponseBody |
||||
public Map<String,Object> getData(HttpServletRequest req, HttpServletResponse res) throws Exception { |
||||
JSONObject json = Utils.getRequestBody(req); |
||||
String formid = json.getString("formid"); |
||||
String dataid = json.getString("dataid"); |
||||
|
||||
FormDefEntity form = FormDbController.getById(formid); |
||||
String sql = generateQuerySql(form); |
||||
|
||||
sql += " where id='"+dataid+"'"; |
||||
String[] column = getColumn(form); |
||||
|
||||
List<Map<String,Object>> items = JDBCUtils.getResult(sql,column,formid); |
||||
return items.get(0); |
||||
} |
||||
|
||||
@PostMapping(value = "/workflow/dataprocess/delete") |
||||
@ResponseBody |
||||
public void delete(HttpServletRequest req, HttpServletResponse res) throws Exception { |
||||
JSONObject json = Utils.getRequestBody(req); |
||||
String formid = json.getString("formid"); |
||||
String dataid = json.getString("dataid"); |
||||
|
||||
FormDefEntity form = FormDbController.getById(formid); |
||||
String sql = generateDeleteSql(form); |
||||
|
||||
sql += " where id='"+dataid+"'"; |
||||
|
||||
JDBCUtils.update(sql); |
||||
} |
||||
|
||||
private String generateDeleteSql(FormDefEntity form) { |
||||
String sql = "delete from "+form.getTablename(); |
||||
return sql ; |
||||
} |
||||
|
||||
/** |
||||
* 获取列名 |
||||
* @param form |
||||
* @return |
||||
*/ |
||||
private String[] getColumn(FormDefEntity form){ |
||||
List<FormDetailEntity> fields = FormDbController.getFieldByFormId(form.getId()); |
||||
String[] column = new String[fields.size()]; |
||||
|
||||
for(int i=0;i<fields.size();i++){ |
||||
column[i] = fields.get(i).getFieldname(); |
||||
} |
||||
|
||||
return column; |
||||
} |
||||
|
||||
/** |
||||
* 生成查询sql |
||||
* @param form |
||||
* @return |
||||
*/ |
||||
private String generateQuerySql(FormDefEntity form) { |
||||
String sql = "select "; |
||||
List<FormDetailEntity> fields = FormDbController.getFieldByFormId(form.getId()); |
||||
|
||||
for(FormDetailEntity field : fields){ |
||||
sql += field.getFieldname()+","; |
||||
} |
||||
|
||||
return sql.substring(0,sql.length()-1) + " from " + form.getTablename(); |
||||
} |
||||
|
||||
/** |
||||
* 生成插入sql |
||||
* @param form |
||||
* @param fields |
||||
* @return |
||||
*/ |
||||
private static String generateInsertSql(HttpServletRequest req,FormDefEntity form, JSONArray fields) throws Exception { |
||||
String insertsql = "insert into " + form.getTablename() +"(id"; |
||||
String valuesql =" values('"+UUID.randomUUID().toString()+"'"; |
||||
|
||||
|
||||
for(int i=0;i<fields.length();i++){ |
||||
JSONObject field = fields.getJSONObject(i); |
||||
insertsql+= ","+field.getString("field"); |
||||
valuesql+=",'"+field.getString("value")+"'"; |
||||
} |
||||
|
||||
insertsql+=",status,createtime,createuser)"; |
||||
|
||||
valuesql+= ",'','"+DateUtilSelf.getNow()+"','"+FRUserUtils.getCurrentUser(req).getUserName()+"')"; |
||||
|
||||
return insertsql+valuesql; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,47 @@
|
||||
package com.eco.plugin.wink.workflow.controller; |
||||
|
||||
import com.eco.plugin.wink.workflow.db.bean.FormDefEntity; |
||||
import com.eco.plugin.wink.workflow.db.bean.FormDetailEntity; |
||||
import com.eco.plugin.wink.workflow.db.controller.FormDbController; |
||||
import com.eco.plugin.wink.workflow.utils.ResponseUtils; |
||||
import com.eco.plugin.wink.workflow.utils.Utils; |
||||
import com.fr.decision.webservice.annotation.LoginStatusChecker; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.third.springframework.stereotype.Controller; |
||||
import com.fr.third.springframework.web.bind.annotation.PostMapping; |
||||
import com.fr.third.springframework.web.bind.annotation.ResponseBody; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.util.List; |
||||
|
||||
@Controller |
||||
@LoginStatusChecker(required = false) |
||||
public class FormController { |
||||
|
||||
/** |
||||
* 获取全部表单 |
||||
* @param req |
||||
* @param res |
||||
*/ |
||||
@PostMapping(value = "/workflow/form/getFormList") |
||||
@ResponseBody |
||||
public void getFormList(HttpServletRequest req,HttpServletResponse res){ |
||||
List<FormDefEntity> formDefEntityList = FormDbController.getFormList(); |
||||
ResponseUtils.response(res,new JSONObject().put("data",formDefEntityList)); |
||||
} |
||||
|
||||
/** |
||||
* 根据表单id获取字段列表 |
||||
* @param req |
||||
* @param res |
||||
*/ |
||||
@PostMapping(value = "/workflow/form/getFieldByFormId") |
||||
@ResponseBody |
||||
public void getFieldByFormId(HttpServletRequest req,HttpServletResponse res){ |
||||
JSONObject param = Utils.getRequestBody(req); |
||||
String formid = param.getString("id"); |
||||
List<FormDetailEntity> formDetailEntityList = FormDbController.getFieldByFormId(formid); |
||||
ResponseUtils.response(res,new JSONObject().put("data",formDetailEntityList)); |
||||
} |
||||
} |
@ -0,0 +1,133 @@
|
||||
package com.eco.plugin.wink.workflow.controller; |
||||
|
||||
import com.eco.plugin.wink.workflow.db.bean.FormDefEntity; |
||||
import com.eco.plugin.wink.workflow.db.bean.WorkflowDefEntity; |
||||
import com.eco.plugin.wink.workflow.db.bean.WorkflowNodeEntity; |
||||
import com.eco.plugin.wink.workflow.db.controller.FormDbController; |
||||
import com.eco.plugin.wink.workflow.db.controller.WorkflowConfigDbController; |
||||
import com.eco.plugin.wink.workflow.utils.DateUtilSelf; |
||||
import com.eco.plugin.wink.workflow.utils.ResponseUtils; |
||||
import com.eco.plugin.wink.workflow.utils.Utils; |
||||
import com.fr.decision.webservice.annotation.LoginStatusChecker; |
||||
import com.fr.json.JSONArray; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.third.springframework.stereotype.Controller; |
||||
import com.fr.third.springframework.web.bind.annotation.PostMapping; |
||||
import com.fr.third.springframework.web.bind.annotation.ResponseBody; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.UUID; |
||||
|
||||
@Controller |
||||
@LoginStatusChecker(required = false) |
||||
public class WorkflowConfigController { |
||||
|
||||
@PostMapping(value = "/workflow/config/importWorkFlow") |
||||
@ResponseBody |
||||
public void importWorkFlow(HttpServletRequest req, HttpServletResponse res){ |
||||
JSONObject json = Utils.getRequestBody(req); |
||||
String paramstr = json.getString("data"); |
||||
JSONArray params = new JSONArray(paramstr); |
||||
for(int i=0;i<params.length();i++){ |
||||
String result = importFlow(params.getJSONObject(i)); |
||||
} |
||||
|
||||
|
||||
ResponseUtils.successResponse(res,"success"); |
||||
} |
||||
|
||||
/** |
||||
* 导入流程 |
||||
* @param param |
||||
* @return |
||||
*/ |
||||
private String importFlow(JSONObject param) { |
||||
String id = addWorkflowDef(param); |
||||
String result = addWorkflowNode(id,param.getJsonArray("workflowNodes")); |
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* 添加流程节点 |
||||
* @param id |
||||
* @param workflowNodes |
||||
* @return |
||||
*/ |
||||
private String addWorkflowNode(String id, JSONArray workflowNodes) { |
||||
String[] ids = id.split(","); |
||||
String formid = ids[1]; |
||||
String workflowDefId = ids[0]; |
||||
List<WorkflowNodeEntity> nodelist = new ArrayList<>(); |
||||
for(int i=0;i<workflowNodes.size();i++){ |
||||
JSONObject node = workflowNodes.getJSONObject(i); |
||||
WorkflowNodeEntity workflowNodeEntity = new WorkflowNodeEntity(); |
||||
workflowNodeEntity.setId(UUID.randomUUID().toString()); |
||||
workflowNodeEntity.setWorkflowid(workflowDefId); |
||||
workflowNodeEntity.setFormid(formid); |
||||
workflowNodeEntity.setNode(node.getString("node")); |
||||
workflowNodeEntity.setNodename(node.getString("nodename")); |
||||
workflowNodeEntity.setSort(String.valueOf(i)); |
||||
workflowNodeEntity.setRolename(node.getString("rolename")); |
||||
nodelist.add(workflowNodeEntity); |
||||
} |
||||
|
||||
WorkflowConfigDbController.batchWorkflowNode(nodelist,null); |
||||
|
||||
return ""; |
||||
} |
||||
|
||||
/** |
||||
* 添加流程定义 |
||||
* @param param |
||||
* @return |
||||
*/ |
||||
private String addWorkflowDef(JSONObject param){ |
||||
String tablename = param.getString("tablename"); |
||||
FormDefEntity formDefEntity = FormDbController.getByTablename(tablename); |
||||
String formid = formDefEntity.getId(); |
||||
String workflowcode = param.getString("workflowcode"); |
||||
String workflowname = param.getString("workflowname"); |
||||
String createtime = DateUtilSelf.getNow(); |
||||
|
||||
WorkflowDefEntity workflowDefEntity = new WorkflowDefEntity(); |
||||
String id = UUID.randomUUID().toString(); |
||||
workflowDefEntity.setId(id); |
||||
workflowDefEntity.setWorkflowcode(workflowcode); |
||||
workflowDefEntity.setWorkflowname(workflowname); |
||||
workflowDefEntity.setCreatetime(createtime); |
||||
workflowDefEntity.setFormid(formid); |
||||
|
||||
WorkflowConfigDbController.singleWorkflowDef(workflowDefEntity,null); |
||||
|
||||
return id+","+formid; |
||||
} |
||||
|
||||
/** |
||||
* 获取全部流程定义 |
||||
* @param req |
||||
* @param res |
||||
*/ |
||||
@PostMapping(value = "/workflow/config/getWorkflowDefList") |
||||
@ResponseBody |
||||
public void getFormList(HttpServletRequest req,HttpServletResponse res){ |
||||
List<WorkflowDefEntity> workflowDefEntityList = WorkflowConfigDbController.getWrokflowDefList(); |
||||
ResponseUtils.response(res,new JSONObject().put("data",workflowDefEntityList)); |
||||
} |
||||
|
||||
/** |
||||
* 根据流程id获取流程节点 |
||||
* @param req |
||||
* @param res |
||||
*/ |
||||
@PostMapping(value = "/workflow/config/getNodeByWorkflowId") |
||||
@ResponseBody |
||||
public void getFieldByFormId(HttpServletRequest req,HttpServletResponse res){ |
||||
JSONObject param = Utils.getRequestBody(req); |
||||
String workflowid = param.getString("id"); |
||||
List<WorkflowNodeEntity> workflowNodeEntityList = WorkflowConfigDbController.getNodesByWorkflowId(workflowid); |
||||
ResponseUtils.response(res,new JSONObject().put("data",workflowNodeEntityList)); |
||||
} |
||||
} |
@ -0,0 +1,315 @@
|
||||
package com.eco.plugin.wink.workflow.controller; |
||||
|
||||
import com.eco.plugin.wink.workflow.db.bean.FormDefEntity; |
||||
import com.eco.plugin.wink.workflow.db.bean.WorkflowDefEntity; |
||||
import com.eco.plugin.wink.workflow.db.bean.WorkflowNodeEntity; |
||||
import com.eco.plugin.wink.workflow.db.bean.WorkflowProcessEntity; |
||||
import com.eco.plugin.wink.workflow.db.controller.FormDbController; |
||||
import com.eco.plugin.wink.workflow.db.controller.WorkFlowProcessController; |
||||
import com.eco.plugin.wink.workflow.db.controller.WorkflowConfigDbController; |
||||
import com.eco.plugin.wink.workflow.kit.UserServiceKit; |
||||
import com.eco.plugin.wink.workflow.utils.*; |
||||
import com.fr.decision.authority.data.User; |
||||
import com.fr.decision.webservice.annotation.LoginStatusChecker; |
||||
import com.fr.json.JSONArray; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.stable.query.data.DataList; |
||||
import com.fr.third.springframework.stereotype.Controller; |
||||
import com.fr.third.springframework.web.bind.annotation.PostMapping; |
||||
import com.fr.third.springframework.web.bind.annotation.ResponseBody; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.util.*; |
||||
|
||||
@Controller |
||||
@LoginStatusChecker(required = false) |
||||
public class WorkflowProcessController { |
||||
|
||||
/** |
||||
* 发起流程 |
||||
* @param req |
||||
* @param res |
||||
*/ |
||||
@PostMapping(value = "/workflow/process/start") |
||||
@ResponseBody |
||||
public void importWorkFlow(HttpServletRequest req, HttpServletResponse res){ |
||||
JSONObject json = Utils.getRequestBody(req); |
||||
|
||||
//处理当前流程节点
|
||||
try { |
||||
operateWorkflow(json,req,"start"); |
||||
} catch (Exception e) { |
||||
ResponseUtils.failedResponse(res,"发起失败:"+e.getMessage()); |
||||
return ; |
||||
} |
||||
|
||||
ResponseUtils.successResponse(res,"发起成功"); |
||||
} |
||||
|
||||
/** |
||||
* 审核流程 |
||||
* @param req |
||||
* @param res |
||||
*/ |
||||
@PostMapping(value = "/workflow/process/approve") |
||||
@ResponseBody |
||||
public void approve(HttpServletRequest req, HttpServletResponse res){ |
||||
JSONObject json = Utils.getRequestBody(req); |
||||
|
||||
//处理当前流程节点
|
||||
try { |
||||
operateWorkflow(json,req,"approve"); |
||||
} catch (Exception e) { |
||||
ResponseUtils.failedResponse(res,"审核失败:"+e.getMessage()); |
||||
return ; |
||||
} |
||||
|
||||
ResponseUtils.successResponse(res,"审核成功"); |
||||
} |
||||
|
||||
/** |
||||
* 处理流程 |
||||
* @param param |
||||
* @param req |
||||
* @param type start 发起 approve审核 |
||||
*/ |
||||
private void operateWorkflow(JSONObject param,HttpServletRequest req,String type) throws Exception { |
||||
//参数
|
||||
String formid = param.getString("formid"); |
||||
String dataid = param.getString("dataid"); |
||||
String comment = param.getString("comment"); |
||||
//表单定义
|
||||
FormDefEntity form = FormDbController.getById(formid); |
||||
//流程定义
|
||||
WorkflowDefEntity workflowDefEntity = WorkflowConfigDbController.getByFormid(formid); |
||||
//流程节点
|
||||
List<WorkflowNodeEntity> nodes = WorkflowConfigDbController.getNodesByWorkflowId(workflowDefEntity.getId()); |
||||
//当前用户
|
||||
User user = FRUserUtils.getCurrentUser(req); |
||||
|
||||
//流程执行列表
|
||||
List<WorkflowProcessEntity> processList = new ArrayList<>(); |
||||
|
||||
if(!"start".equals(type)){ |
||||
processList = WorkFlowProcessController.getByFormidAndDataid(formid,dataid); |
||||
} |
||||
|
||||
List<WorkflowProcessEntity> process = new ArrayList<>(); |
||||
WorkflowProcessEntity currentNodeProcess = getCurrenNode(user,formid,dataid,nodes,processList); |
||||
WorkflowProcessEntity nextNodeProcess = getNextNodeProcess(currentNodeProcess,nodes,formid,dataid); |
||||
|
||||
if(Utils.isNotNullStr(comment)){ |
||||
currentNodeProcess.setComment(comment); |
||||
} |
||||
|
||||
process.add(currentNodeProcess); |
||||
process.add(nextNodeProcess); |
||||
//操作流程处理表
|
||||
WorkFlowProcessController.batch(process,null); |
||||
updateDataStatus(dataid,formid,nextNodeProcess,nodes); |
||||
} |
||||
|
||||
/** |
||||
* 获取下个节点 |
||||
* @param currentNodeProcess |
||||
* @param nodes |
||||
* @param formid |
||||
* @param dataid |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
private WorkflowProcessEntity getNextNodeProcess(WorkflowProcessEntity currentNodeProcess, List<WorkflowNodeEntity> nodes, String formid, String dataid) throws Exception { |
||||
WorkflowProcessEntity current = new WorkflowProcessEntity(); |
||||
current.setId(UUID.randomUUID().toString()); |
||||
current.setFormid(formid); |
||||
current.setDataid(dataid); |
||||
current.setCreatetime(DateUtilSelf.getNow()); |
||||
current.setLastnode(currentNodeProcess.getCurrentnode()); |
||||
//结束
|
||||
if(Utils.isNullStr(currentNodeProcess.getNextnode())){ |
||||
current.setCurrentnode("结束"); |
||||
WorkflowNodeEntity finnalNode = nodes.get(nodes.size() -1 ); |
||||
String sort = String.valueOf(Integer.valueOf(finnalNode.getSort()) + 1); |
||||
current.setSort(sort); |
||||
}else{ |
||||
Map<String,WorkflowNodeEntity> map = getNextAndThirdNodeByNode(currentNodeProcess.getNextnode(),nodes); |
||||
WorkflowNodeEntity currentNode = map.get("current"); |
||||
WorkflowNodeEntity nextNode = map.get("next"); |
||||
|
||||
current.setCurrentnode(currentNode.getNode()); |
||||
String checker = getChecker(currentNode.getRolename()); |
||||
current.setOperateruser(checker); |
||||
|
||||
if(nextNode != null){ |
||||
current.setNextnode(nextNode.getNode()); |
||||
} |
||||
current.setSort(currentNode.getSort()); |
||||
} |
||||
|
||||
return current; |
||||
} |
||||
|
||||
/** |
||||
* 获取当前节点 |
||||
* @param user |
||||
* @param formid |
||||
* @param dataid |
||||
* @param nodes |
||||
* @param processList |
||||
* @return |
||||
*/ |
||||
private WorkflowProcessEntity getCurrenNode(User user, String formid, String dataid, List<WorkflowNodeEntity> nodes,List<WorkflowProcessEntity> processList){ |
||||
boolean isStart = processList == null || processList.size() <= 0; |
||||
String currentNodeCode = isStart ? "" : processList.get(processList.size() -1).getCurrentnode(); |
||||
Map<String,WorkflowNodeEntity> map = getCurrentAndNextByNode(currentNodeCode,nodes); |
||||
WorkflowNodeEntity currentNode = map.get("current"); |
||||
WorkflowNodeEntity nextNode = map.get("next"); |
||||
|
||||
WorkflowProcessEntity current = new WorkflowProcessEntity(); |
||||
|
||||
//发起
|
||||
if(isStart){ |
||||
current.setId(UUID.randomUUID().toString()); |
||||
current.setFormid(formid); |
||||
current.setDataid(dataid); |
||||
current.setCurrentnode(currentNode.getNode()); |
||||
current.setNextnode(nextNode.getNode()); |
||||
current.setOperateruser(user.getUserName()); |
||||
current.setSort(currentNode.getSort()); |
||||
current.setCreatetime(DateUtilSelf.getNow()); |
||||
}else{ |
||||
current = processList.get(processList.size() -1); |
||||
current.setOperateruser(current.getOperateruser()+"("+user.getUserName()+")"); |
||||
} |
||||
|
||||
return current; |
||||
} |
||||
|
||||
|
||||
|
||||
/** |
||||
* 修改数据审核状态 |
||||
* @param |
||||
*/ |
||||
private void updateDataStatus(String dataid,String formid,WorkflowProcessEntity current,List<WorkflowNodeEntity> nodes) throws Exception { |
||||
FormDefEntity formDef = FormDbController.getById(formid); |
||||
String tablename = formDef.getTablename(); |
||||
String nodename = ""; |
||||
|
||||
String currentuser = ""; |
||||
if(current.getCurrentnode().equals("结束")){ |
||||
nodename = "结束"; |
||||
}else{ |
||||
for (WorkflowNodeEntity node : nodes){ |
||||
if(node.getNode().equals(current.getCurrentnode())){ |
||||
nodename = node.getNodename(); |
||||
currentuser = getCheckerForData(node.getRolename()); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
String sql = "update " + tablename + " set status='"+nodename+"',currentuser='"+currentuser+"' where id = '"+dataid+"'"; |
||||
|
||||
JDBCUtils.update(sql); |
||||
} |
||||
|
||||
/** |
||||
* 根据节点编码获取当前节点和下个节点 |
||||
* @param node |
||||
* @param nodes |
||||
* @return |
||||
*/ |
||||
private Map<String,WorkflowNodeEntity> getCurrentAndNextByNode(String node,List<WorkflowNodeEntity> nodes){ |
||||
Map<String,WorkflowNodeEntity> map = new HashMap<>(); |
||||
|
||||
//发起流程 直接返回前两个节点
|
||||
if(Utils.isNullStr(node)){ |
||||
map.put("current",nodes.get(0)); |
||||
map.put("next",nodes.get(1)); |
||||
return map; |
||||
} |
||||
|
||||
//审核流程
|
||||
for(int i=0;i<nodes.size();i++){ |
||||
WorkflowNodeEntity currentNode = nodes.get(i); |
||||
if(!currentNode.getNode().equals(node)){ |
||||
continue; |
||||
} |
||||
|
||||
map.put("current",currentNode); |
||||
map.put("next",null); |
||||
|
||||
if(i != nodes.size() -1){ |
||||
map.put("next",nodes.get(nodes.size() -1)); |
||||
} |
||||
|
||||
break; |
||||
} |
||||
|
||||
return map; |
||||
} |
||||
|
||||
/** |
||||
* 根据当前节点获取下个和下下个节点 |
||||
* @param node |
||||
* @param nodes |
||||
* @return |
||||
*/ |
||||
private Map<String,WorkflowNodeEntity> getNextAndThirdNodeByNode(String node,List<WorkflowNodeEntity> nodes){ |
||||
Map<String,WorkflowNodeEntity> map = new HashMap<>(); |
||||
|
||||
for(int i=0;i<nodes.size();i++){ |
||||
WorkflowNodeEntity currentNode = nodes.get(i); |
||||
if(!currentNode.getNode().equals(node)){ |
||||
continue; |
||||
} |
||||
|
||||
map.put("current",currentNode); |
||||
map.put("next",null); |
||||
|
||||
if(i != nodes.size() -1){ |
||||
map.put("next",nodes.get(nodes.size() -1)); |
||||
} |
||||
|
||||
break; |
||||
} |
||||
|
||||
return map; |
||||
} |
||||
|
||||
/** |
||||
* 根据角色名称获取审核人 |
||||
* @param rolename |
||||
* @return |
||||
*/ |
||||
private String getChecker(String rolename) throws Exception { |
||||
// return "xiamaofa";
|
||||
List<User> users = UserServiceKit.getInstance().getAllUsersByRolename(rolename); |
||||
String checker = ""; |
||||
for(User user : users){ |
||||
checker+=","+user.getUserName(); |
||||
} |
||||
|
||||
checker = checker.replaceFirst(",",""); |
||||
return checker; |
||||
} |
||||
|
||||
/** |
||||
* 根据角色名称获取审核人-修改data审核人用 |
||||
* @param rolename |
||||
* @return |
||||
*/ |
||||
private String getCheckerForData(String rolename) throws Exception { |
||||
// return "[xiamaofa]";
|
||||
List<User> users = UserServiceKit.getInstance().getAllUsersByRolename(rolename); |
||||
String checker = ""; |
||||
for(User user : users){ |
||||
checker+=",["+user.getUserName()+"]"; |
||||
} |
||||
|
||||
checker = checker.replaceFirst(",",""); |
||||
return checker; |
||||
} |
||||
} |
@ -0,0 +1,162 @@
|
||||
package com.eco.plugin.wink.workflow.db.bean; |
||||
|
||||
import com.fr.stable.db.entity.BaseEntity; |
||||
import com.fr.stable.db.entity.TableAssociation; |
||||
import com.fr.third.javax.persistence.Column; |
||||
import com.fr.third.javax.persistence.Entity; |
||||
import com.fr.third.javax.persistence.Table; |
||||
|
||||
/** |
||||
* @author wink |
||||
* @version 10.0 |
||||
* Created by wink on 2021-07-29 |
||||
* 数据库链接信息表 |
||||
**/ |
||||
@Entity |
||||
@Table(name = "plugin_wink_shop_workflow_entity_dblink") |
||||
@TableAssociation(associated = true) |
||||
public class DBLinkEntity extends BaseEntity { |
||||
|
||||
//数据库类型
|
||||
@Column(name = "dbtype") |
||||
private String dbtype = null; |
||||
|
||||
//驱动
|
||||
@Column(name = "driver") |
||||
private String driver = null; |
||||
|
||||
//数据库名称
|
||||
@Column(name = "dbname") |
||||
private String dbname = null; |
||||
|
||||
//主机
|
||||
@Column(name = "host") |
||||
private String host = null; |
||||
//端口
|
||||
@Column(name = "port") |
||||
private String port = null; |
||||
|
||||
//用户名
|
||||
@Column(name = "username") |
||||
private String username = null; |
||||
|
||||
//密码
|
||||
@Column(name = "password") |
||||
private String password = null; |
||||
|
||||
//编码
|
||||
@Column(name = "encode") |
||||
private String encode = null; |
||||
|
||||
//模式
|
||||
@Column(name = "mode") |
||||
private String mode = null; |
||||
|
||||
//数据库链接
|
||||
@Column(name = "url") |
||||
private String url = null; |
||||
|
||||
//创建时间
|
||||
@Column(name = "createtime") |
||||
private String createtime = null; |
||||
|
||||
//修改时间
|
||||
@Column(name = "updatetime") |
||||
private String updatetime = null; |
||||
|
||||
public String getCreatetime() { |
||||
return createtime; |
||||
} |
||||
|
||||
public void setCreatetime(String createtime) { |
||||
this.createtime = createtime; |
||||
} |
||||
|
||||
public String getUpdatetime() { |
||||
return updatetime; |
||||
} |
||||
|
||||
public void setUpdatetime(String updatetime) { |
||||
this.updatetime = updatetime; |
||||
} |
||||
|
||||
public String getDbtype() { |
||||
return dbtype; |
||||
} |
||||
|
||||
public void setDbtype(String dbtype) { |
||||
this.dbtype = dbtype; |
||||
} |
||||
|
||||
public String getDriver() { |
||||
return driver; |
||||
} |
||||
|
||||
public void setDriver(String driver) { |
||||
this.driver = driver; |
||||
} |
||||
|
||||
public String getDbname() { |
||||
return dbname; |
||||
} |
||||
|
||||
public void setDbname(String dbname) { |
||||
this.dbname = dbname; |
||||
} |
||||
|
||||
public String getHost() { |
||||
return host; |
||||
} |
||||
|
||||
public void setHost(String host) { |
||||
this.host = host; |
||||
} |
||||
|
||||
public String getPort() { |
||||
return port; |
||||
} |
||||
|
||||
public void setPort(String port) { |
||||
this.port = port; |
||||
} |
||||
|
||||
public String getUsername() { |
||||
return username; |
||||
} |
||||
|
||||
public void setUsername(String username) { |
||||
this.username = username; |
||||
} |
||||
|
||||
public String getPassword() { |
||||
return password; |
||||
} |
||||
|
||||
public void setPassword(String password) { |
||||
this.password = password; |
||||
} |
||||
|
||||
public String getEncode() { |
||||
return encode; |
||||
} |
||||
|
||||
public void setEncode(String encode) { |
||||
this.encode = encode; |
||||
} |
||||
|
||||
public String getMode() { |
||||
return mode; |
||||
} |
||||
|
||||
public void setMode(String mode) { |
||||
this.mode = mode; |
||||
} |
||||
|
||||
public String getUrl() { |
||||
return url; |
||||
} |
||||
|
||||
public void setUrl(String url) { |
||||
this.url = url; |
||||
} |
||||
} |
@ -0,0 +1,79 @@
|
||||
package com.eco.plugin.wink.workflow.db.bean; |
||||
|
||||
import com.fr.stable.db.entity.BaseEntity; |
||||
import com.fr.stable.db.entity.TableAssociation; |
||||
import com.fr.third.javax.persistence.Column; |
||||
import com.fr.third.javax.persistence.Entity; |
||||
import com.fr.third.javax.persistence.Table; |
||||
|
||||
/** |
||||
* @author wink |
||||
* @version 10.0 |
||||
* Created by wink on 2021-07-29 |
||||
* 表单定义表 |
||||
**/ |
||||
@Entity |
||||
@Table(name = "plugin_wink_shop_workflow_form_def") |
||||
@TableAssociation(associated = true) |
||||
public class FormDefEntity extends BaseEntity { |
||||
|
||||
//表名
|
||||
@Column(name = "tablename") |
||||
private String tablename = null; |
||||
|
||||
//表单名称
|
||||
@Column(name = "formname") |
||||
private String formname = null; |
||||
|
||||
//创建时间
|
||||
@Column(name = "createtime") |
||||
private String createtime = null; |
||||
|
||||
//修改时间
|
||||
@Column(name = "updatetime") |
||||
private String updatetime = null; |
||||
|
||||
//状态 --预留字段
|
||||
@Column(name = "status") |
||||
private String status = null; |
||||
|
||||
public String getTablename() { |
||||
return tablename; |
||||
} |
||||
|
||||
public void setTablename(String tablename) { |
||||
this.tablename = tablename; |
||||
} |
||||
|
||||
public String getFormname() { |
||||
return formname; |
||||
} |
||||
|
||||
public void setFormname(String formname) { |
||||
this.formname = formname; |
||||
} |
||||
|
||||
public String getCreatetime() { |
||||
return createtime; |
||||
} |
||||
|
||||
public void setCreatetime(String createtime) { |
||||
this.createtime = createtime; |
||||
} |
||||
|
||||
public String getUpdatetime() { |
||||
return updatetime; |
||||
} |
||||
|
||||
public void setUpdatetime(String updatetime) { |
||||
this.updatetime = updatetime; |
||||
} |
||||
|
||||
public String getStatus() { |
||||
return status; |
||||
} |
||||
|
||||
public void setStatus(String status) { |
||||
this.status = status; |
||||
} |
||||
} |
@ -0,0 +1,67 @@
|
||||
package com.eco.plugin.wink.workflow.db.bean; |
||||
|
||||
import com.fr.stable.db.entity.BaseEntity; |
||||
import com.fr.stable.db.entity.TableAssociation; |
||||
import com.fr.third.javax.persistence.Column; |
||||
import com.fr.third.javax.persistence.Entity; |
||||
import com.fr.third.javax.persistence.Table; |
||||
|
||||
/** |
||||
* @author wink |
||||
* @version 10.0 |
||||
* Created by wink on 2021-07-29 |
||||
* 表单明细表 |
||||
**/ |
||||
@Entity |
||||
@Table(name = "plugin_wink_shop_workflow_form_detail") |
||||
@TableAssociation(associated = true) |
||||
public class FormDetailEntity extends BaseEntity { |
||||
|
||||
//表单id
|
||||
@Column(name = "formid") |
||||
private String formid = null; |
||||
|
||||
//字段名
|
||||
@Column(name = "fieldname") |
||||
private String fieldname = null; |
||||
|
||||
//字段描述
|
||||
@Column(name = "fielddec") |
||||
private String fielddec = null; |
||||
|
||||
//排序
|
||||
@Column(name = "sort") |
||||
private String sort = null; |
||||
|
||||
public String getFormid() { |
||||
return formid; |
||||
} |
||||
|
||||
public void setFormid(String formid) { |
||||
this.formid = formid; |
||||
} |
||||
|
||||
public String getFieldname() { |
||||
return fieldname; |
||||
} |
||||
|
||||
public void setFieldname(String fieldname) { |
||||
this.fieldname = fieldname; |
||||
} |
||||
|
||||
public String getFielddec() { |
||||
return fielddec; |
||||
} |
||||
|
||||
public void setFielddec(String fielddec) { |
||||
this.fielddec = fielddec; |
||||
} |
||||
|
||||
public String getSort() { |
||||
return sort; |
||||
} |
||||
|
||||
public void setSort(String sort) { |
||||
this.sort = sort; |
||||
} |
||||
} |
@ -0,0 +1,67 @@
|
||||
package com.eco.plugin.wink.workflow.db.bean; |
||||
|
||||
import com.fr.stable.db.entity.BaseEntity; |
||||
import com.fr.stable.db.entity.TableAssociation; |
||||
import com.fr.third.javax.persistence.Column; |
||||
import com.fr.third.javax.persistence.Entity; |
||||
import com.fr.third.javax.persistence.Table; |
||||
|
||||
/** |
||||
* @author wink |
||||
* @version 10.0 |
||||
* Created by wink on 2021-07-29 |
||||
* 流程节点 |
||||
**/ |
||||
@Entity |
||||
@Table(name = "plugin_wink_shop_workflow_def") |
||||
@TableAssociation(associated = true) |
||||
public class WorkflowDefEntity extends BaseEntity { |
||||
|
||||
//表单id
|
||||
@Column(name = "formid") |
||||
private String formid = null; |
||||
|
||||
//流程编码
|
||||
@Column(name = "workflowcode") |
||||
private String workflowcode = null; |
||||
|
||||
//流程名称
|
||||
@Column(name = "workflowname") |
||||
private String workflowname = null; |
||||
|
||||
//创建时间
|
||||
@Column(name = "createtime") |
||||
private String createtime = null; |
||||
|
||||
public String getFormid() { |
||||
return formid; |
||||
} |
||||
|
||||
public void setFormid(String formid) { |
||||
this.formid = formid; |
||||
} |
||||
|
||||
public String getWorkflowcode() { |
||||
return workflowcode; |
||||
} |
||||
|
||||
public void setWorkflowcode(String workflowcode) { |
||||
this.workflowcode = workflowcode; |
||||
} |
||||
|
||||
public String getWorkflowname() { |
||||
return workflowname; |
||||
} |
||||
|
||||
public void setWorkflowname(String workflowname) { |
||||
this.workflowname = workflowname; |
||||
} |
||||
|
||||
public String getCreatetime() { |
||||
return createtime; |
||||
} |
||||
|
||||
public void setCreatetime(String createtime) { |
||||
this.createtime = createtime; |
||||
} |
||||
} |
@ -0,0 +1,91 @@
|
||||
package com.eco.plugin.wink.workflow.db.bean; |
||||
|
||||
import com.fr.stable.db.entity.BaseEntity; |
||||
import com.fr.stable.db.entity.TableAssociation; |
||||
import com.fr.third.javax.persistence.Column; |
||||
import com.fr.third.javax.persistence.Entity; |
||||
import com.fr.third.javax.persistence.Table; |
||||
|
||||
/** |
||||
* @author wink |
||||
* @version 10.0 |
||||
* Created by wink on 2021-07-29 |
||||
* 流程定义表 |
||||
**/ |
||||
@Entity |
||||
@Table(name = "plugin_wink_shop_workflow_node") |
||||
@TableAssociation(associated = true) |
||||
public class WorkflowNodeEntity extends BaseEntity { |
||||
|
||||
//表单id
|
||||
@Column(name = "formid") |
||||
private String formid = null; |
||||
|
||||
//流程id
|
||||
@Column(name = "workflowid") |
||||
private String workflowid = null; |
||||
|
||||
//节点编码 ---预留字段
|
||||
@Column(name = "node") |
||||
private String node = null; |
||||
|
||||
//节点名称
|
||||
@Column(name = "nodename") |
||||
private String nodename = null; |
||||
|
||||
//排序
|
||||
@Column(name = "sort") |
||||
private String sort = null; |
||||
|
||||
//角色名称
|
||||
@Column(name = "rolename") |
||||
private String rolename = null; |
||||
|
||||
public String getRolename() { |
||||
return rolename; |
||||
} |
||||
|
||||
public void setRolename(String rolename) { |
||||
this.rolename = rolename; |
||||
} |
||||
|
||||
public String getFormid() { |
||||
return formid; |
||||
} |
||||
|
||||
public void setFormid(String formid) { |
||||
this.formid = formid; |
||||
} |
||||
|
||||
public String getNode() { |
||||
return node; |
||||
} |
||||
|
||||
public void setNode(String node) { |
||||
this.node = node; |
||||
} |
||||
|
||||
public String getNodename() { |
||||
return nodename; |
||||
} |
||||
|
||||
public void setNodename(String nodename) { |
||||
this.nodename = nodename; |
||||
} |
||||
|
||||
public String getSort() { |
||||
return sort; |
||||
} |
||||
|
||||
public void setSort(String sort) { |
||||
this.sort = sort; |
||||
} |
||||
|
||||
public String getWorkflowid() { |
||||
return workflowid; |
||||
} |
||||
|
||||
public void setWorkflowid(String workflowid) { |
||||
this.workflowid = workflowid; |
||||
} |
||||
} |
@ -0,0 +1,125 @@
|
||||
package com.eco.plugin.wink.workflow.db.bean; |
||||
|
||||
import com.fr.stable.db.entity.BaseEntity; |
||||
import com.fr.stable.db.entity.TableAssociation; |
||||
import com.fr.third.javax.persistence.*; |
||||
|
||||
/** |
||||
* @author wink |
||||
* @version 10.0 |
||||
* Created by wink on 2021-07-29 |
||||
* 流程执行表 |
||||
**/ |
||||
@Entity |
||||
@Table(name = "plugin_wink_shop_workflow_process") |
||||
@TableAssociation(associated = true) |
||||
public class WorkflowProcessEntity extends BaseEntity { |
||||
|
||||
//表单id
|
||||
@Column(name = "formid") |
||||
private String formid = null; |
||||
|
||||
//实体数据id
|
||||
@Column(name = "dataid") |
||||
private String dataid = null; |
||||
|
||||
//上个流程节点
|
||||
@Column(name = "lastnode") |
||||
private String lastnode = null; |
||||
|
||||
//当前流程节点
|
||||
@Column(name = "currentnode") |
||||
private String currentnode = null; |
||||
|
||||
//下个流程节点
|
||||
@Column(name = "nextnode") |
||||
private String nextnode = null; |
||||
|
||||
//经办人
|
||||
@Column(name = "operateruser") |
||||
private String operateruser = null; |
||||
|
||||
//排序
|
||||
@Column(name = "sort") |
||||
private String sort = null; |
||||
|
||||
//创建时间
|
||||
@Column(name = "createtime") |
||||
private String createtime = null; |
||||
|
||||
//审核意见
|
||||
@Column(name = "comment") |
||||
private String comment = null; |
||||
|
||||
public String getComment() { |
||||
return comment; |
||||
} |
||||
|
||||
public void setComment(String comment) { |
||||
this.comment = comment; |
||||
} |
||||
|
||||
public String getFormid() { |
||||
return formid; |
||||
} |
||||
|
||||
public void setFormid(String formid) { |
||||
this.formid = formid; |
||||
} |
||||
|
||||
public String getDataid() { |
||||
return dataid; |
||||
} |
||||
|
||||
public void setDataid(String dataid) { |
||||
this.dataid = dataid; |
||||
} |
||||
|
||||
public String getLastnode() { |
||||
return lastnode; |
||||
} |
||||
|
||||
public void setLastnode(String lastnode) { |
||||
this.lastnode = lastnode; |
||||
} |
||||
|
||||
public String getCurrentnode() { |
||||
return currentnode; |
||||
} |
||||
|
||||
public void setCurrentnode(String currentnode) { |
||||
this.currentnode = currentnode; |
||||
} |
||||
|
||||
public String getNextnode() { |
||||
return nextnode; |
||||
} |
||||
|
||||
public void setNextnode(String nextnode) { |
||||
this.nextnode = nextnode; |
||||
} |
||||
|
||||
public String getOperateruser() { |
||||
return operateruser; |
||||
} |
||||
|
||||
public void setOperateruser(String operateruser) { |
||||
this.operateruser = operateruser; |
||||
} |
||||
|
||||
public String getSort() { |
||||
return sort; |
||||
} |
||||
|
||||
public void setSort(String sort) { |
||||
this.sort = sort; |
||||
} |
||||
|
||||
public String getCreatetime() { |
||||
return createtime; |
||||
} |
||||
|
||||
public void setCreatetime(String createtime) { |
||||
this.createtime = createtime; |
||||
} |
||||
} |
@ -0,0 +1,225 @@
|
||||
package com.eco.plugin.wink.workflow.db.controller; |
||||
|
||||
import com.eco.plugin.wink.workflow.db.bean.FormDefEntity; |
||||
import com.eco.plugin.wink.workflow.db.bean.FormDetailEntity; |
||||
import com.eco.plugin.wink.workflow.db.dao.FormDefDao; |
||||
import com.eco.plugin.wink.workflow.db.dao.FormFieldDao; |
||||
import com.eco.plugin.wink.workflow.utils.FRUtils; |
||||
import com.fr.db.fun.impl.AbstractDBAccessProvider; |
||||
import com.fr.record.analyzer.EnableMetrics; |
||||
import com.fr.stable.db.accessor.DBAccessor; |
||||
import com.fr.stable.db.action.DBAction; |
||||
import com.fr.stable.db.dao.DAOContext; |
||||
import com.fr.stable.db.dao.DAOProvider; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author wink |
||||
* @version 10.0 |
||||
* Created by wink on 2021-07-29 |
||||
**/ |
||||
@EnableMetrics |
||||
public class FormDbController extends AbstractDBAccessProvider { |
||||
|
||||
private static DBAccessor accessor; |
||||
|
||||
public static DBAccessor getAccessor() { |
||||
return accessor; |
||||
} |
||||
|
||||
@Override |
||||
public DAOProvider[] registerDAO() { |
||||
return new DAOProvider[]{ |
||||
FormDefDao.DAO, FormFieldDao.DAO |
||||
}; |
||||
} |
||||
|
||||
@Override |
||||
public void onDBAvailable(DBAccessor accessor) { |
||||
FormDbController.accessor = accessor; |
||||
} |
||||
|
||||
/** |
||||
* 单个操作表单 |
||||
* @param addOrUpdate |
||||
* @param delete |
||||
* @return |
||||
*/ |
||||
public static boolean singleForm(FormDefEntity addOrUpdate, FormDefEntity delete){ |
||||
//新增或者删除
|
||||
if(addOrUpdate != null ){ |
||||
try{ |
||||
accessor.runDMLAction(new DBAction<Boolean>() { |
||||
@Override |
||||
public Boolean run(DAOContext context) throws Exception { |
||||
FormDefEntity ae =context.getDAO(FormDefDao.class).getById(addOrUpdate.getId()); |
||||
if(ae != null ){ |
||||
context.getDAO(FormDefDao.class).update(addOrUpdate); |
||||
}else{ |
||||
context.getDAO(FormDefDao.class).add(addOrUpdate); |
||||
} |
||||
return true; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
FRUtils.FRLogError("singleForm exception ->"+e.getMessage() + addOrUpdate.toString()); |
||||
} |
||||
} |
||||
|
||||
if(delete != null ){ |
||||
try{ |
||||
accessor.runDMLAction(new DBAction<Boolean>() { |
||||
@Override |
||||
public Boolean run(DAOContext context) throws Exception { |
||||
context.getDAO(FormDefDao.class).remove(delete.getId()); |
||||
return true; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
FRUtils.FRLogError("singleForm delete exception ->"+e.getMessage() + delete.toString()); |
||||
} |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
/** |
||||
* 批量操作表单字段 |
||||
* @param addOrUpdate |
||||
* @param delete |
||||
* @return |
||||
*/ |
||||
public static boolean batch(List<FormDetailEntity> addOrUpdate, List<FormDetailEntity> delete){ |
||||
//新增或者删除
|
||||
if(addOrUpdate != null && addOrUpdate.size() > 0){ |
||||
for(final FormDetailEntity dbe : addOrUpdate){ |
||||
|
||||
try{ |
||||
accessor.runDMLAction(new DBAction<Boolean>() { |
||||
@Override |
||||
public Boolean run(DAOContext context) throws Exception { |
||||
FormDetailEntity ae =context.getDAO(FormFieldDao.class).getById(dbe.getId()); |
||||
if(ae != null ){ |
||||
context.getDAO(FormFieldDao.class).update(dbe); |
||||
}else{ |
||||
context.getDAO(FormFieldDao.class).add(dbe); |
||||
} |
||||
return true; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
FRUtils.FRLogError("batch addOrUpdate formfield exception ->"+e.getMessage() + dbe.toString()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
if(delete != null && delete.size() > 0){ |
||||
for(final FormDetailEntity dbe : delete){ |
||||
|
||||
try{ |
||||
accessor.runDMLAction(new DBAction<Boolean>() { |
||||
@Override |
||||
public Boolean run(DAOContext context) throws Exception { |
||||
context.getDAO(FormFieldDao.class).remove(dbe.getId()); |
||||
return true; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
FRUtils.FRLogError("batch formfiled delete exception ->"+e.getMessage() + dbe.toString()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
/** |
||||
* 获取所有表单信息 |
||||
* @param |
||||
* @return |
||||
*/ |
||||
public static List<FormDefEntity> getFormList(){ |
||||
try{ |
||||
return accessor.runQueryAction(new DBAction<List<FormDefEntity>>() { |
||||
@Override |
||||
public List<FormDefEntity> run(DAOContext context) throws Exception { |
||||
List<FormDefEntity> result = context.getDAO(FormDefDao.class).getAll(); |
||||
|
||||
return result == null ? new ArrayList<FormDefEntity>() : result; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
FRUtils.FRLogError("exception getAllDBLink:"+e.getMessage()); |
||||
} |
||||
|
||||
return new ArrayList<FormDefEntity>(); |
||||
} |
||||
|
||||
/** |
||||
* 根据tablename获取表单 |
||||
* @param |
||||
* @return |
||||
*/ |
||||
public static FormDefEntity getByTablename(final String tablename){ |
||||
try{ |
||||
return accessor.runQueryAction(new DBAction<FormDefEntity>() { |
||||
@Override |
||||
public FormDefEntity run(DAOContext context) throws Exception { |
||||
FormDefEntity result = context.getDAO(FormDefDao.class).getByTablename(tablename); |
||||
|
||||
return result == null ? new FormDefEntity() : result; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
FRUtils.FRLogError("exception getAllDBLink:"+e.getMessage()); |
||||
} |
||||
|
||||
return new FormDefEntity(); |
||||
} |
||||
|
||||
/** |
||||
* 根据id获取表单 |
||||
* @param |
||||
* @return |
||||
*/ |
||||
public static FormDefEntity getById(final String id){ |
||||
try{ |
||||
return accessor.runQueryAction(new DBAction<FormDefEntity>() { |
||||
@Override |
||||
public FormDefEntity run(DAOContext context) throws Exception { |
||||
FormDefEntity result = context.getDAO(FormDefDao.class).getById(id); |
||||
|
||||
return result == null ? new FormDefEntity() : result; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
FRUtils.FRLogError("exception getById:"+e.getMessage()); |
||||
} |
||||
|
||||
return new FormDefEntity(); |
||||
} |
||||
|
||||
/** |
||||
* 根据表单id获取字段列表 |
||||
* @param |
||||
* @return |
||||
*/ |
||||
public static List<FormDetailEntity> getFieldByFormId(String formid){ |
||||
try{ |
||||
return accessor.runQueryAction(new DBAction<List<FormDetailEntity>>() { |
||||
@Override |
||||
public List<FormDetailEntity> run(DAOContext context) throws Exception { |
||||
List<FormDetailEntity> result = context.getDAO(FormFieldDao.class).getFieldById(formid); |
||||
|
||||
return result == null ? new ArrayList<FormDetailEntity>() : result; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
FRUtils.FRLogError("exception getAllDBLink:"+e.getMessage()); |
||||
} |
||||
|
||||
return new ArrayList<FormDetailEntity>(); |
||||
} |
||||
} |
@ -0,0 +1,228 @@
|
||||
package com.eco.plugin.wink.workflow.db.controller; |
||||
|
||||
import com.eco.plugin.wink.workflow.db.bean.DBLinkEntity; |
||||
import com.eco.plugin.wink.workflow.db.bean.FormDefEntity; |
||||
import com.eco.plugin.wink.workflow.db.bean.FormDetailEntity; |
||||
import com.eco.plugin.wink.workflow.db.dao.DBLinkDao; |
||||
import com.eco.plugin.wink.workflow.db.dao.FormDefDao; |
||||
import com.eco.plugin.wink.workflow.db.dao.FormFieldDao; |
||||
import com.eco.plugin.wink.workflow.utils.FRUtils; |
||||
import com.fr.db.fun.impl.AbstractDBAccessProvider; |
||||
import com.fr.plugin.transform.FunctionRecorder; |
||||
import com.fr.record.analyzer.EnableMetrics; |
||||
import com.fr.stable.db.accessor.DBAccessor; |
||||
import com.fr.stable.db.action.DBAction; |
||||
import com.fr.stable.db.dao.DAOContext; |
||||
import com.fr.stable.db.dao.DAOProvider; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author wink |
||||
* @version 10.0 |
||||
* Created by wink on 2021-07-29 |
||||
**/ |
||||
@EnableMetrics |
||||
public class WorkFlowController extends AbstractDBAccessProvider { |
||||
|
||||
private static DBAccessor accessor; |
||||
|
||||
public static DBAccessor getAccessor() { |
||||
return accessor; |
||||
} |
||||
|
||||
@Override |
||||
public DAOProvider[] registerDAO() { |
||||
return new DAOProvider[]{ |
||||
DBLinkDao.DAO, FormDefDao.DAO, FormFieldDao.DAO |
||||
}; |
||||
} |
||||
|
||||
@Override |
||||
public void onDBAvailable(DBAccessor accessor) { |
||||
WorkFlowController.accessor = accessor; |
||||
} |
||||
|
||||
/** |
||||
* 单个操作数据库链接 |
||||
* @param addOrUpdate |
||||
* @param delete |
||||
* @return |
||||
*/ |
||||
public static boolean singleDBLink(DBLinkEntity addOrUpdate,DBLinkEntity delete){ |
||||
//新增或者删除
|
||||
if(addOrUpdate != null ){ |
||||
try{ |
||||
accessor.runDMLAction(new DBAction<Boolean>() { |
||||
@Override |
||||
public Boolean run(DAOContext context) throws Exception { |
||||
DBLinkEntity ae =context.getDAO(DBLinkDao.class).getById(addOrUpdate.getId()); |
||||
if(ae != null ){ |
||||
context.getDAO(DBLinkDao.class).update(addOrUpdate); |
||||
}else{ |
||||
context.getDAO(DBLinkDao.class).add(addOrUpdate); |
||||
} |
||||
return true; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
FRUtils.FRLogError("singleDBLink exception ->"+e.getMessage() + addOrUpdate.toString()); |
||||
} |
||||
} |
||||
|
||||
if(delete != null ){ |
||||
try{ |
||||
accessor.runDMLAction(new DBAction<Boolean>() { |
||||
@Override |
||||
public Boolean run(DAOContext context) throws Exception { |
||||
context.getDAO(DBLinkDao.class).remove(delete.getId()); |
||||
return true; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
FRUtils.FRLogError("singleDBLink delete exception ->"+e.getMessage() + delete.toString()); |
||||
} |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
/** |
||||
* 获取所有数据库链接信息 |
||||
* @param |
||||
* @return |
||||
*/ |
||||
public static List<DBLinkEntity> getAllDBLink(){ |
||||
try{ |
||||
return accessor.runQueryAction(new DBAction<List<DBLinkEntity>>() { |
||||
@Override |
||||
public List<DBLinkEntity> run(DAOContext context) throws Exception { |
||||
List<DBLinkEntity> result = context.getDAO(DBLinkDao.class).getAll(); |
||||
|
||||
return result == null ? new ArrayList<DBLinkEntity>() : result; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
FRUtils.FRLogError("exception getAllDBLink:"+e.getMessage()); |
||||
} |
||||
|
||||
return new ArrayList<DBLinkEntity>(); |
||||
} |
||||
|
||||
/** |
||||
* 根据id获取信息 |
||||
* @param id |
||||
* @return |
||||
*/ |
||||
public static DBLinkEntity getDBLinkById(final String id){ |
||||
try{ |
||||
return accessor.runQueryAction(new DBAction<DBLinkEntity>() { |
||||
@Override |
||||
public DBLinkEntity run(DAOContext context) throws Exception { |
||||
DBLinkEntity result = context.getDAO(DBLinkDao.class).getById(id); |
||||
|
||||
return result == null ? new DBLinkEntity() : result; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
FRUtils.FRLogError("exception getDBLinkById:"+e.getMessage()); |
||||
} |
||||
|
||||
return new DBLinkEntity(); |
||||
} |
||||
|
||||
/** |
||||
* 单个操作表单 |
||||
* @param addOrUpdate |
||||
* @param delete |
||||
* @return |
||||
*/ |
||||
public static boolean singleForm(FormDefEntity addOrUpdate, FormDefEntity delete){ |
||||
//新增或者删除
|
||||
if(addOrUpdate != null ){ |
||||
try{ |
||||
accessor.runDMLAction(new DBAction<Boolean>() { |
||||
@Override |
||||
public Boolean run(DAOContext context) throws Exception { |
||||
FormDefEntity ae =context.getDAO(FormDefDao.class).getById(addOrUpdate.getId()); |
||||
if(ae != null ){ |
||||
context.getDAO(FormDefDao.class).update(addOrUpdate); |
||||
}else{ |
||||
context.getDAO(FormDefDao.class).add(addOrUpdate); |
||||
} |
||||
return true; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
FRUtils.FRLogError("singleForm exception ->"+e.getMessage() + addOrUpdate.toString()); |
||||
} |
||||
} |
||||
|
||||
if(delete != null ){ |
||||
try{ |
||||
accessor.runDMLAction(new DBAction<Boolean>() { |
||||
@Override |
||||
public Boolean run(DAOContext context) throws Exception { |
||||
context.getDAO(FormDefDao.class).remove(delete.getId()); |
||||
return true; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
FRUtils.FRLogError("singleForm delete exception ->"+e.getMessage() + delete.toString()); |
||||
} |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
/** |
||||
* 批量操作表单字段 |
||||
* @param addOrUpdate |
||||
* @param delete |
||||
* @return |
||||
*/ |
||||
public static boolean batch(List<FormDetailEntity> addOrUpdate, List<FormDetailEntity> delete){ |
||||
//新增或者删除
|
||||
if(addOrUpdate != null && addOrUpdate.size() > 0){ |
||||
for(final FormDetailEntity dbe : addOrUpdate){ |
||||
|
||||
try{ |
||||
accessor.runDMLAction(new DBAction<Boolean>() { |
||||
@Override |
||||
public Boolean run(DAOContext context) throws Exception { |
||||
FormDetailEntity ae =context.getDAO(FormFieldDao.class).getById(dbe.getId()); |
||||
if(ae != null ){ |
||||
context.getDAO(FormFieldDao.class).update(dbe); |
||||
}else{ |
||||
context.getDAO(FormFieldDao.class).add(dbe); |
||||
} |
||||
return true; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
FRUtils.FRLogError("batch addOrUpdate formfield exception ->"+e.getMessage() + dbe.toString()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
if(delete != null && delete.size() > 0){ |
||||
for(final FormDetailEntity dbe : delete){ |
||||
|
||||
try{ |
||||
accessor.runDMLAction(new DBAction<Boolean>() { |
||||
@Override |
||||
public Boolean run(DAOContext context) throws Exception { |
||||
context.getDAO(FormFieldDao.class).remove(dbe.getId()); |
||||
return true; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
FRUtils.FRLogError("batch formfiled delete exception ->"+e.getMessage() + dbe.toString()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
} |
@ -0,0 +1,115 @@
|
||||
package com.eco.plugin.wink.workflow.db.controller; |
||||
|
||||
import com.eco.plugin.wink.workflow.db.bean.DBLinkEntity; |
||||
import com.eco.plugin.wink.workflow.db.bean.WorkflowProcessEntity; |
||||
import com.eco.plugin.wink.workflow.db.dao.DBLinkDao; |
||||
import com.eco.plugin.wink.workflow.db.dao.WorkflowProcessDao; |
||||
import com.eco.plugin.wink.workflow.utils.FRUtils; |
||||
import com.fr.db.fun.impl.AbstractDBAccessProvider; |
||||
import com.fr.record.analyzer.EnableMetrics; |
||||
import com.fr.stable.db.accessor.DBAccessor; |
||||
import com.fr.stable.db.action.DBAction; |
||||
import com.fr.stable.db.dao.DAOContext; |
||||
import com.fr.stable.db.dao.DAOProvider; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author wink |
||||
* @version 10.0 |
||||
* Created by wink on 2021-07-29 |
||||
**/ |
||||
@EnableMetrics |
||||
public class WorkFlowProcessController extends AbstractDBAccessProvider { |
||||
|
||||
private static DBAccessor accessor; |
||||
|
||||
public static DBAccessor getAccessor() { |
||||
return accessor; |
||||
} |
||||
|
||||
@Override |
||||
public DAOProvider[] registerDAO() { |
||||
return new DAOProvider[]{ |
||||
WorkflowProcessDao.DAO |
||||
}; |
||||
} |
||||
|
||||
@Override |
||||
public void onDBAvailable(DBAccessor accessor) { |
||||
WorkFlowProcessController.accessor = accessor; |
||||
} |
||||
|
||||
/** |
||||
* 批量发起审核 |
||||
* @param addOrUpdate |
||||
* @param delete |
||||
* @return |
||||
*/ |
||||
public static boolean batch(List<WorkflowProcessEntity> addOrUpdate, List<WorkflowProcessEntity> delete){ |
||||
//新增或者删除
|
||||
if(addOrUpdate != null && addOrUpdate.size() > 0){ |
||||
for(final WorkflowProcessEntity dbe : addOrUpdate){ |
||||
|
||||
try{ |
||||
accessor.runDMLAction(new DBAction<Boolean>() { |
||||
@Override |
||||
public Boolean run(DAOContext context) throws Exception { |
||||
WorkflowProcessEntity ae =context.getDAO(WorkflowProcessDao.class).getById(dbe.getId()); |
||||
if(ae != null ){ |
||||
context.getDAO(WorkflowProcessDao.class).update(dbe); |
||||
}else{ |
||||
context.getDAO(WorkflowProcessDao.class).add(dbe); |
||||
} |
||||
return true; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
FRUtils.FRLogError("batch addOrUpdate formfield exception ->"+e.getMessage() + dbe.toString()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
if(delete != null && delete.size() > 0){ |
||||
for(final WorkflowProcessEntity dbe : delete){ |
||||
|
||||
try{ |
||||
accessor.runDMLAction(new DBAction<Boolean>() { |
||||
@Override |
||||
public Boolean run(DAOContext context) throws Exception { |
||||
context.getDAO(WorkflowProcessDao.class).remove(dbe.getId()); |
||||
return true; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
FRUtils.FRLogError("batch formfiled delete exception ->"+e.getMessage() + dbe.toString()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
/** |
||||
* 根据formid和dataid获取流程 |
||||
* @param |
||||
* @return |
||||
*/ |
||||
public static List<WorkflowProcessEntity> getByFormidAndDataid(String formid,String dataid){ |
||||
try{ |
||||
return accessor.runQueryAction(new DBAction<List<WorkflowProcessEntity>>() { |
||||
@Override |
||||
public List<WorkflowProcessEntity> run(DAOContext context) throws Exception { |
||||
List<WorkflowProcessEntity> result = context.getDAO(WorkflowProcessDao.class).getByFormidAndDataid(formid,dataid); |
||||
|
||||
return result == null ? new ArrayList<WorkflowProcessEntity>() : result; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
FRUtils.FRLogError("exception getAllDBLink:"+e.getMessage()); |
||||
} |
||||
|
||||
return new ArrayList<WorkflowProcessEntity>(); |
||||
} |
||||
} |
@ -0,0 +1,205 @@
|
||||
package com.eco.plugin.wink.workflow.db.controller; |
||||
|
||||
import com.eco.plugin.wink.workflow.db.bean.WorkflowDefEntity; |
||||
import com.eco.plugin.wink.workflow.db.bean.WorkflowNodeEntity; |
||||
import com.eco.plugin.wink.workflow.db.dao.WorkflowDefDao; |
||||
import com.eco.plugin.wink.workflow.db.dao.WorkflowNodeDao; |
||||
import com.eco.plugin.wink.workflow.db.dao.WorkflowDefDao; |
||||
import com.eco.plugin.wink.workflow.db.dao.WorkflowNodeDao; |
||||
import com.eco.plugin.wink.workflow.utils.FRUtils; |
||||
import com.fr.db.fun.impl.AbstractDBAccessProvider; |
||||
import com.fr.record.analyzer.EnableMetrics; |
||||
import com.fr.stable.db.accessor.DBAccessor; |
||||
import com.fr.stable.db.action.DBAction; |
||||
import com.fr.stable.db.dao.DAOContext; |
||||
import com.fr.stable.db.dao.DAOProvider; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author wink |
||||
* @version 10.0 |
||||
* Created by wink on 2021-07-29 |
||||
**/ |
||||
@EnableMetrics |
||||
public class WorkflowConfigDbController extends AbstractDBAccessProvider { |
||||
|
||||
private static DBAccessor accessor; |
||||
|
||||
public static DBAccessor getAccessor() { |
||||
return accessor; |
||||
} |
||||
|
||||
@Override |
||||
public DAOProvider[] registerDAO() { |
||||
return new DAOProvider[]{ |
||||
WorkflowDefDao.DAO, WorkflowNodeDao.DAO |
||||
}; |
||||
} |
||||
|
||||
@Override |
||||
public void onDBAvailable(DBAccessor accessor) { |
||||
WorkflowConfigDbController.accessor = accessor; |
||||
} |
||||
|
||||
/** |
||||
* 单个操作流程定义 |
||||
* @param addOrUpdate |
||||
* @param delete |
||||
* @return |
||||
*/ |
||||
public static boolean singleWorkflowDef(WorkflowDefEntity addOrUpdate, WorkflowDefEntity delete){ |
||||
//新增或者删除
|
||||
if(addOrUpdate != null ){ |
||||
try{ |
||||
accessor.runDMLAction(new DBAction<Boolean>() { |
||||
@Override |
||||
public Boolean run(DAOContext context) throws Exception { |
||||
WorkflowDefEntity ae =context.getDAO(WorkflowDefDao.class).getById(addOrUpdate.getId()); |
||||
if(ae != null ){ |
||||
context.getDAO(WorkflowDefDao.class).update(addOrUpdate); |
||||
}else{ |
||||
context.getDAO(WorkflowDefDao.class).add(addOrUpdate); |
||||
} |
||||
return true; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
FRUtils.FRLogError("singleWorkflowDef exception ->"+e.getMessage() + addOrUpdate.toString()); |
||||
} |
||||
} |
||||
|
||||
if(delete != null ){ |
||||
try{ |
||||
accessor.runDMLAction(new DBAction<Boolean>() { |
||||
@Override |
||||
public Boolean run(DAOContext context) throws Exception { |
||||
context.getDAO(WorkflowDefDao.class).remove(delete.getId()); |
||||
return true; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
FRUtils.FRLogError("singleWorkflowDef delete exception ->"+e.getMessage() + delete.toString()); |
||||
} |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
/** |
||||
* 批量操作流程节点 |
||||
* @param addOrUpdate |
||||
* @param delete |
||||
* @return |
||||
*/ |
||||
public static boolean batchWorkflowNode(List<WorkflowNodeEntity> addOrUpdate, List<WorkflowNodeEntity> delete){ |
||||
//新增或者删除
|
||||
if(addOrUpdate != null && addOrUpdate.size() > 0){ |
||||
for(final WorkflowNodeEntity dbe : addOrUpdate){ |
||||
|
||||
try{ |
||||
accessor.runDMLAction(new DBAction<Boolean>() { |
||||
@Override |
||||
public Boolean run(DAOContext context) throws Exception { |
||||
WorkflowNodeEntity ae =context.getDAO(WorkflowNodeDao.class).getById(dbe.getId()); |
||||
if(ae != null ){ |
||||
context.getDAO(WorkflowNodeDao.class).update(dbe); |
||||
}else{ |
||||
context.getDAO(WorkflowNodeDao.class).add(dbe); |
||||
} |
||||
return true; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
FRUtils.FRLogError("batch addOrUpdate batchWorkflowNode exception ->"+e.getMessage() + dbe.toString()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
if(delete != null && delete.size() > 0){ |
||||
for(final WorkflowNodeEntity dbe : delete){ |
||||
|
||||
try{ |
||||
accessor.runDMLAction(new DBAction<Boolean>() { |
||||
@Override |
||||
public Boolean run(DAOContext context) throws Exception { |
||||
context.getDAO(WorkflowNodeDao.class).remove(dbe.getId()); |
||||
return true; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
FRUtils.FRLogError("batch batchWorkflowNode delete exception ->"+e.getMessage() + dbe.toString()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
/** |
||||
* 获取所有流程定义信息 |
||||
* @param |
||||
* @return |
||||
*/ |
||||
public static List<WorkflowDefEntity> getWrokflowDefList(){ |
||||
try{ |
||||
return accessor.runQueryAction(new DBAction<List<WorkflowDefEntity>>() { |
||||
@Override |
||||
public List<WorkflowDefEntity> run(DAOContext context) throws Exception { |
||||
List<WorkflowDefEntity> result = context.getDAO(WorkflowDefDao.class).getAll(); |
||||
|
||||
return result == null ? new ArrayList<WorkflowDefEntity>() : result; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
FRUtils.FRLogError("exception getWrokflowDefList:"+e.getMessage()); |
||||
} |
||||
|
||||
return new ArrayList<WorkflowDefEntity>(); |
||||
} |
||||
|
||||
/** |
||||
* 根据表单获取流程定义 |
||||
* @param formid |
||||
* @return |
||||
*/ |
||||
public static WorkflowDefEntity getByFormid(String formid){ |
||||
try{ |
||||
return accessor.runQueryAction(new DBAction<WorkflowDefEntity>() { |
||||
@Override |
||||
public WorkflowDefEntity run(DAOContext context) throws Exception { |
||||
WorkflowDefEntity result = context.getDAO(WorkflowDefDao.class).getByFormid(formid); |
||||
|
||||
return result == null ? new WorkflowDefEntity() : result; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
FRUtils.FRLogError("exception getWrokflowDefList:"+e.getMessage()); |
||||
} |
||||
|
||||
return new WorkflowDefEntity(); |
||||
} |
||||
|
||||
/** |
||||
* 根据workflowid获取流程节点 |
||||
* @param |
||||
* @return |
||||
*/ |
||||
public static List<WorkflowNodeEntity> getNodesByWorkflowId(String formid){ |
||||
try{ |
||||
return accessor.runQueryAction(new DBAction<List<WorkflowNodeEntity>>() { |
||||
@Override |
||||
public List<WorkflowNodeEntity> run(DAOContext context) throws Exception { |
||||
List<WorkflowNodeEntity> result = context.getDAO(WorkflowNodeDao.class).getFieldById(formid); |
||||
|
||||
return result == null ? new ArrayList<WorkflowNodeEntity>() : result; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
FRUtils.FRLogError("exception getNodesByWorkflowId:"+e.getMessage()); |
||||
} |
||||
|
||||
return new ArrayList<WorkflowNodeEntity>(); |
||||
} |
||||
} |
@ -0,0 +1,57 @@
|
||||
package com.eco.plugin.wink.workflow.db.dao; |
||||
|
||||
import com.eco.plugin.wink.workflow.db.bean.DBLinkEntity; |
||||
import com.fr.stable.db.dao.BaseDAO; |
||||
import com.fr.stable.db.dao.DAOProvider; |
||||
import com.fr.stable.db.session.DAOSession; |
||||
import com.fr.stable.query.QueryFactory; |
||||
import com.fr.stable.query.restriction.RestrictionFactory; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author wink |
||||
* @version 10.0 |
||||
* Created by wink on 2021-12-03 |
||||
**/ |
||||
public class DBLinkDao extends BaseDAO<DBLinkEntity> { |
||||
|
||||
public DBLinkDao(DAOSession session) { |
||||
super(session); |
||||
} |
||||
|
||||
@Override |
||||
protected Class<DBLinkEntity> getEntityClass() { |
||||
return DBLinkEntity.class; |
||||
} |
||||
|
||||
public final static DAOProvider DAO = new DAOProvider() { |
||||
@Override |
||||
public Class getEntityClass() { |
||||
return DBLinkEntity.class; |
||||
} |
||||
|
||||
@Override |
||||
public Class<? extends BaseDAO> getDAOClass() { |
||||
return DBLinkDao.class; |
||||
} |
||||
}; |
||||
|
||||
public void add(DBLinkEntity entity) throws Exception { |
||||
getSession().persist(entity); |
||||
} |
||||
|
||||
public void remove(String id) throws Exception { |
||||
getSession().remove(QueryFactory.create() |
||||
.addRestriction(RestrictionFactory.eq("id", id)), |
||||
this.getEntityClass()); |
||||
} |
||||
|
||||
public void update(DBLinkEntity entity) throws Exception { |
||||
getSession().merge(entity); |
||||
} |
||||
|
||||
public List<DBLinkEntity> getAll () throws Exception { |
||||
return getSession().find(QueryFactory.create().addSort("createtime",false),DBLinkEntity.class); |
||||
} |
||||
} |
@ -0,0 +1,67 @@
|
||||
package com.eco.plugin.wink.workflow.db.dao; |
||||
|
||||
import com.eco.plugin.wink.workflow.db.bean.FormDefEntity; |
||||
import com.fr.stable.db.dao.BaseDAO; |
||||
import com.fr.stable.db.dao.DAOProvider; |
||||
import com.fr.stable.db.session.DAOSession; |
||||
import com.fr.stable.query.QueryFactory; |
||||
import com.fr.stable.query.restriction.RestrictionFactory; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author wink |
||||
* @version 10.0 |
||||
* Created by wink on 2021-12-03 |
||||
**/ |
||||
public class FormDefDao extends BaseDAO<FormDefEntity> { |
||||
|
||||
public FormDefDao(DAOSession session) { |
||||
super(session); |
||||
} |
||||
|
||||
@Override |
||||
protected Class<FormDefEntity> getEntityClass() { |
||||
return FormDefEntity.class; |
||||
} |
||||
|
||||
public final static DAOProvider DAO = new DAOProvider() { |
||||
@Override |
||||
public Class getEntityClass() { |
||||
return FormDefEntity.class; |
||||
} |
||||
|
||||
@Override |
||||
public Class<? extends BaseDAO> getDAOClass() { |
||||
return FormDefDao.class; |
||||
} |
||||
}; |
||||
|
||||
public void add(FormDefEntity entity) throws Exception { |
||||
getSession().persist(entity); |
||||
} |
||||
|
||||
public void remove(String id) throws Exception { |
||||
getSession().remove(QueryFactory.create() |
||||
.addRestriction(RestrictionFactory.eq("id", id)), |
||||
this.getEntityClass()); |
||||
} |
||||
|
||||
public void update(FormDefEntity entity) throws Exception { |
||||
getSession().merge(entity); |
||||
} |
||||
|
||||
public List<FormDefEntity> getAll () throws Exception { |
||||
return getSession().find(QueryFactory.create().addSort("createtime",false),FormDefEntity.class); |
||||
} |
||||
|
||||
/** |
||||
* 根据表名获取表单定义对象 |
||||
* @param tablename |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public FormDefEntity getByTablename(String tablename) throws Exception { |
||||
return getSession().findOne(QueryFactory.create().addRestriction(RestrictionFactory.eq("tablename",tablename)),FormDefEntity.class); |
||||
} |
||||
} |
@ -0,0 +1,61 @@
|
||||
package com.eco.plugin.wink.workflow.db.dao; |
||||
|
||||
import com.eco.plugin.wink.workflow.db.bean.FormDetailEntity; |
||||
import com.fr.stable.db.dao.BaseDAO; |
||||
import com.fr.stable.db.dao.DAOProvider; |
||||
import com.fr.stable.db.session.DAOSession; |
||||
import com.fr.stable.query.QueryFactory; |
||||
import com.fr.stable.query.restriction.RestrictionFactory; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author wink |
||||
* @version 10.0 |
||||
* Created by wink on 2021-12-03 |
||||
**/ |
||||
public class FormFieldDao extends BaseDAO<FormDetailEntity> { |
||||
|
||||
public FormFieldDao(DAOSession session) { |
||||
super(session); |
||||
} |
||||
|
||||
@Override |
||||
protected Class<FormDetailEntity> getEntityClass() { |
||||
return FormDetailEntity.class; |
||||
} |
||||
|
||||
public final static DAOProvider DAO = new DAOProvider() { |
||||
@Override |
||||
public Class getEntityClass() { |
||||
return FormDetailEntity.class; |
||||
} |
||||
|
||||
@Override |
||||
public Class<? extends BaseDAO> getDAOClass() { |
||||
return FormFieldDao.class; |
||||
} |
||||
}; |
||||
|
||||
public void add(FormDetailEntity entity) throws Exception { |
||||
getSession().persist(entity); |
||||
} |
||||
|
||||
public void remove(String id) throws Exception { |
||||
getSession().remove(QueryFactory.create() |
||||
.addRestriction(RestrictionFactory.eq("id", id)), |
||||
this.getEntityClass()); |
||||
} |
||||
|
||||
public void update(FormDetailEntity entity) throws Exception { |
||||
getSession().merge(entity); |
||||
} |
||||
|
||||
// public List<FormDetailEntity> getAll () throws Exception {
|
||||
//// return getSession().find(QueryFactory.create().addSort("createtime",false),FormDetailEntity.class);
|
||||
// }
|
||||
|
||||
public List<FormDetailEntity> getFieldById(String formid) throws Exception{ |
||||
return getSession().find(QueryFactory.create().addRestriction(RestrictionFactory.eq("formid",formid)).addSort("sort",false),FormDetailEntity.class); |
||||
} |
||||
} |
@ -0,0 +1,62 @@
|
||||
package com.eco.plugin.wink.workflow.db.dao; |
||||
|
||||
import com.eco.plugin.wink.workflow.db.bean.WorkflowDefEntity; |
||||
import com.fr.stable.db.dao.BaseDAO; |
||||
import com.fr.stable.db.dao.DAOProvider; |
||||
import com.fr.stable.db.session.DAOSession; |
||||
import com.fr.stable.query.QueryFactory; |
||||
import com.fr.stable.query.restriction.RestrictionFactory; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author wink |
||||
* @version 10.0 |
||||
* Created by wink on 2021-12-03 |
||||
**/ |
||||
public class WorkflowDefDao extends BaseDAO<WorkflowDefEntity> { |
||||
|
||||
public WorkflowDefDao(DAOSession session) { |
||||
super(session); |
||||
} |
||||
|
||||
@Override |
||||
protected Class<WorkflowDefEntity> getEntityClass() { |
||||
return WorkflowDefEntity.class; |
||||
} |
||||
|
||||
public final static DAOProvider DAO = new DAOProvider() { |
||||
@Override |
||||
public Class getEntityClass() { |
||||
return WorkflowDefEntity.class; |
||||
} |
||||
|
||||
@Override |
||||
public Class<? extends BaseDAO> getDAOClass() { |
||||
return WorkflowDefDao.class; |
||||
} |
||||
}; |
||||
|
||||
public void add(WorkflowDefEntity entity) throws Exception { |
||||
getSession().persist(entity); |
||||
} |
||||
|
||||
public void remove(String id) throws Exception { |
||||
getSession().remove(QueryFactory.create() |
||||
.addRestriction(RestrictionFactory.eq("id", id)), |
||||
this.getEntityClass()); |
||||
} |
||||
|
||||
public void update(WorkflowDefEntity entity) throws Exception { |
||||
getSession().merge(entity); |
||||
} |
||||
|
||||
public List<WorkflowDefEntity> getAll () throws Exception { |
||||
return getSession().find(QueryFactory.create().addSort("createtime",false),WorkflowDefEntity.class); |
||||
} |
||||
|
||||
//根据formid获取流程定义
|
||||
public WorkflowDefEntity getByFormid (String formid) throws Exception { |
||||
return getSession().findOne(QueryFactory.create().addRestriction(RestrictionFactory.eq("formid",formid)).addSort("createtime",false),WorkflowDefEntity.class); |
||||
} |
||||
} |
@ -0,0 +1,57 @@
|
||||
package com.eco.plugin.wink.workflow.db.dao; |
||||
|
||||
import com.eco.plugin.wink.workflow.db.bean.WorkflowNodeEntity; |
||||
import com.fr.stable.db.dao.BaseDAO; |
||||
import com.fr.stable.db.dao.DAOProvider; |
||||
import com.fr.stable.db.session.DAOSession; |
||||
import com.fr.stable.query.QueryFactory; |
||||
import com.fr.stable.query.restriction.RestrictionFactory; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author wink |
||||
* @version 10.0 |
||||
* Created by wink on 2021-12-03 |
||||
**/ |
||||
public class WorkflowNodeDao extends BaseDAO<WorkflowNodeEntity> { |
||||
|
||||
public WorkflowNodeDao(DAOSession session) { |
||||
super(session); |
||||
} |
||||
|
||||
@Override |
||||
protected Class<WorkflowNodeEntity> getEntityClass() { |
||||
return WorkflowNodeEntity.class; |
||||
} |
||||
|
||||
public final static DAOProvider DAO = new DAOProvider() { |
||||
@Override |
||||
public Class getEntityClass() { |
||||
return WorkflowNodeEntity.class; |
||||
} |
||||
|
||||
@Override |
||||
public Class<? extends BaseDAO> getDAOClass() { |
||||
return WorkflowNodeDao.class; |
||||
} |
||||
}; |
||||
|
||||
public void add(WorkflowNodeEntity entity) throws Exception { |
||||
getSession().persist(entity); |
||||
} |
||||
|
||||
public void remove(String id) throws Exception { |
||||
getSession().remove(QueryFactory.create() |
||||
.addRestriction(RestrictionFactory.eq("id", id)), |
||||
this.getEntityClass()); |
||||
} |
||||
|
||||
public void update(WorkflowNodeEntity entity) throws Exception { |
||||
getSession().merge(entity); |
||||
} |
||||
|
||||
public List<WorkflowNodeEntity> getFieldById(String workflowId) throws Exception{ |
||||
return getSession().find(QueryFactory.create().addRestriction(RestrictionFactory.eq("workflowid",workflowId)).addSort("sort",false),WorkflowNodeEntity.class); |
||||
} |
||||
} |
@ -0,0 +1,61 @@
|
||||
package com.eco.plugin.wink.workflow.db.dao; |
||||
|
||||
import com.eco.plugin.wink.workflow.db.bean.WorkflowProcessEntity; |
||||
import com.fr.stable.db.dao.BaseDAO; |
||||
import com.fr.stable.db.dao.DAOProvider; |
||||
import com.fr.stable.db.session.DAOSession; |
||||
import com.fr.stable.query.QueryFactory; |
||||
import com.fr.stable.query.restriction.RestrictionFactory; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author wink |
||||
* @version 10.0 |
||||
* Created by wink on 2021-12-03 |
||||
**/ |
||||
public class WorkflowProcessDao extends BaseDAO<WorkflowProcessEntity> { |
||||
|
||||
public WorkflowProcessDao(DAOSession session) { |
||||
super(session); |
||||
} |
||||
|
||||
@Override |
||||
protected Class<WorkflowProcessEntity> getEntityClass() { |
||||
return WorkflowProcessEntity.class; |
||||
} |
||||
|
||||
public final static DAOProvider DAO = new DAOProvider() { |
||||
@Override |
||||
public Class getEntityClass() { |
||||
return WorkflowProcessEntity.class; |
||||
} |
||||
|
||||
@Override |
||||
public Class<? extends BaseDAO> getDAOClass() { |
||||
return WorkflowProcessDao.class; |
||||
} |
||||
}; |
||||
|
||||
public void add(WorkflowProcessEntity entity) throws Exception { |
||||
getSession().persist(entity); |
||||
} |
||||
|
||||
public void remove(String id) throws Exception { |
||||
getSession().remove(QueryFactory.create() |
||||
.addRestriction(RestrictionFactory.eq("id", id)), |
||||
this.getEntityClass()); |
||||
} |
||||
|
||||
public void update(WorkflowProcessEntity entity) throws Exception { |
||||
getSession().merge(entity); |
||||
} |
||||
|
||||
public List<WorkflowProcessEntity> getAll () throws Exception { |
||||
return getSession().find(QueryFactory.create().addSort("createtime",false),WorkflowProcessEntity.class); |
||||
} |
||||
|
||||
public List<WorkflowProcessEntity> getByFormidAndDataid (String formid,String dataid) throws Exception { |
||||
return getSession().find(QueryFactory.create().addRestriction(RestrictionFactory.eq("formid",formid)).addRestriction(RestrictionFactory.eq("dataid",dataid)).addSort("createtime",false).addSort("sort",false),WorkflowProcessEntity.class); |
||||
} |
||||
} |
@ -0,0 +1,55 @@
|
||||
package com.eco.plugin.wink.workflow.kit; |
||||
|
||||
import com.eco.plugin.wink.workflow.utils.FRUserUtils; |
||||
import com.eco.plugin.wink.workflow.utils.FRUtils; |
||||
import com.fr.decision.authority.AuthorityContext; |
||||
import com.fr.decision.authority.base.constant.SoftRoleType; |
||||
import com.fr.decision.authority.base.constant.type.operation.ManualOperationType; |
||||
import com.fr.decision.authority.data.CustomRole; |
||||
import com.fr.decision.authority.data.User; |
||||
import com.fr.decision.base.util.UUIDUtil; |
||||
import com.fr.decision.privilege.encrpt.PasswordValidator; |
||||
import com.fr.decision.webservice.bean.user.RoleBean; |
||||
import com.fr.decision.webservice.bean.user.UserBean; |
||||
import com.fr.decision.webservice.exception.general.DuplicatedNameException; |
||||
import com.fr.decision.webservice.exception.general.SpecialCharProhibitException; |
||||
import com.fr.decision.webservice.exception.login.UserPasswordCanNotEmptyException; |
||||
import com.fr.decision.webservice.utils.CharLimitType; |
||||
import com.fr.decision.webservice.utils.ControllerFactory; |
||||
import com.fr.decision.webservice.utils.UserSourceFactory; |
||||
import com.fr.decision.webservice.utils.WebServiceUtils; |
||||
import com.fr.decision.webservice.v10.user.CustomRoleService; |
||||
import com.fr.decision.webservice.v10.user.UserService; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.stable.query.QueryFactory; |
||||
import com.fr.stable.query.condition.QueryCondition; |
||||
import com.fr.stable.query.restriction.Restriction; |
||||
import com.fr.stable.query.restriction.RestrictionFactory; |
||||
|
||||
/** |
||||
* 普通角色Service |
||||
*/ |
||||
public class CustomRoleServiceKit extends CustomRoleService { |
||||
private static volatile CustomRoleServiceKit roleServiceKit = null; |
||||
|
||||
public CustomRoleServiceKit() { |
||||
} |
||||
|
||||
public static CustomRoleServiceKit getInstance() { |
||||
if (roleServiceKit == null) { |
||||
roleServiceKit = new CustomRoleServiceKit(); |
||||
} |
||||
return roleServiceKit; |
||||
} |
||||
|
||||
/** |
||||
* 根据角色名获取角色信息 |
||||
* @param rolename |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public CustomRole getByRolename(String rolename) throws Exception { |
||||
CustomRole customRole = AuthorityContext.getInstance().getCustomRoleController().findOne(QueryFactory.create().addRestriction(RestrictionFactory.eq("name",rolename))); |
||||
return customRole; |
||||
} |
||||
} |
@ -0,0 +1,115 @@
|
||||
package com.eco.plugin.wink.workflow.kit; |
||||
|
||||
import com.eco.plugin.wink.workflow.utils.FRUserUtils; |
||||
import com.eco.plugin.wink.workflow.utils.FRUtils; |
||||
import com.fr.decision.authority.AuthorityContext; |
||||
import com.fr.decision.authority.base.constant.SoftRoleType; |
||||
import com.fr.decision.authority.base.constant.type.operation.ManualOperationType; |
||||
import com.fr.decision.authority.data.CustomRole; |
||||
import com.fr.decision.authority.data.User; |
||||
import com.fr.decision.base.util.UUIDUtil; |
||||
import com.fr.decision.privilege.encrpt.PasswordValidator; |
||||
import com.fr.decision.webservice.bean.user.UserBean; |
||||
import com.fr.decision.webservice.exception.general.DuplicatedNameException; |
||||
import com.fr.decision.webservice.exception.general.SpecialCharProhibitException; |
||||
import com.fr.decision.webservice.exception.login.UserPasswordCanNotEmptyException; |
||||
import com.fr.decision.webservice.utils.CharLimitType; |
||||
import com.fr.decision.webservice.utils.ControllerFactory; |
||||
import com.fr.decision.webservice.utils.UserSourceFactory; |
||||
import com.fr.decision.webservice.utils.WebServiceUtils; |
||||
import com.fr.decision.webservice.v10.user.UserService; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.stable.query.QueryFactory; |
||||
import com.fr.stable.query.condition.QueryCondition; |
||||
import com.fr.stable.query.data.DataList; |
||||
import com.fr.stable.query.restriction.Restriction; |
||||
import com.fr.stable.query.restriction.RestrictionFactory; |
||||
|
||||
import java.util.List; |
||||
|
||||
public class UserServiceKit extends UserService { |
||||
private static volatile UserServiceKit userServiceKit = null; |
||||
|
||||
public UserServiceKit() { |
||||
} |
||||
|
||||
public static UserServiceKit getInstance() { |
||||
if (userServiceKit == null) { |
||||
userServiceKit = new UserServiceKit(); |
||||
} |
||||
return userServiceKit; |
||||
} |
||||
|
||||
public void editUser(UserBean userBean, String var2) throws Exception { |
||||
this.editUserInfo(userBean); |
||||
if (userBean.isResetPassword()) { |
||||
this.resetPassword(userBean); |
||||
} |
||||
|
||||
this.updateUserRoles(var2, userBean); |
||||
this.updateUserDepartmentPost(var2, userBean); |
||||
} |
||||
|
||||
/** |
||||
* 添加用户 |
||||
* @param userBean |
||||
* @throws Exception |
||||
*/ |
||||
public void addUser(UserBean userBean) throws Exception { |
||||
if (StringUtils.isEmpty(userBean.getPassword())) { |
||||
throw new UserPasswordCanNotEmptyException(); |
||||
} else { |
||||
String username = userBean.getUsername(); |
||||
String mobile = userBean.getMobile(); |
||||
String email = userBean.getEmail(); |
||||
String id = userBean.getId(); |
||||
String psd = userBean.getPassword(); |
||||
this.checkUsernameLegal(username, CharLimitType.USER_LIMIT); |
||||
this.checkNonRequiredField(mobile, CharLimitType.MOBILE_LIMIT); |
||||
this.checkNonRequiredField(email, CharLimitType.EMAIL_LIMIT); |
||||
this.checkDuplicatedUser(username); |
||||
String salt = UUIDUtil.generate(); |
||||
PasswordValidator var8 = UserSourceFactory.getInstance().getUserSource(ManualOperationType.KEY).getPasswordValidator(); |
||||
User user = (new User()).userName(username).realName(userBean.getRealName()).password(var8.encode(username, psd, salt)).salt(salt).email(userBean.getEmail()).mobile(userBean.getMobile()).creationType(ManualOperationType.KEY).lastOperationType(ManualOperationType.KEY).enable(true).id(id); |
||||
FRUtils.FRLogInfo(user.toString()); |
||||
AuthorityContext.getInstance().getUserController().add(user); |
||||
this.deleteSoftData(user.getUserName()); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 获取角色下所有用户 |
||||
* @param rolename |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public List<User> getAllUsersByRolename(String rolename) throws Exception{ |
||||
UserBean userBean = FRUserUtils.getAdminUser(); |
||||
CustomRole customRole = CustomRoleServiceKit.getInstance().getByRolename(rolename); |
||||
return ControllerFactory.getInstance().getUserController(userBean.getUsername()).findAllUsersByCustomRole(userBean.getId(), customRole.getId(), "", false).getList(); |
||||
} |
||||
|
||||
private void checkUsernameLegal(String var1, CharLimitType var2) throws SpecialCharProhibitException { |
||||
if (WebServiceUtils.containSQLChars(var1) || WebServiceUtils.containIllegalChars(var2, var1)) { |
||||
throw new SpecialCharProhibitException(); |
||||
} |
||||
} |
||||
|
||||
private void checkNonRequiredField(String var1, CharLimitType var2) { |
||||
if (StringUtils.isNotEmpty(var1) && WebServiceUtils.containIllegalChars(var2, var1)) { |
||||
throw new SpecialCharProhibitException(); |
||||
} |
||||
} |
||||
|
||||
private void checkDuplicatedUser(String var1) throws Exception { |
||||
User var2 = this.getUserByUserName(var1); |
||||
if (var2 != null) { |
||||
throw new DuplicatedNameException("Duplicated names! ", var1); |
||||
} |
||||
} |
||||
|
||||
private void deleteSoftData(String var1) throws Exception { |
||||
QueryCondition var2 = QueryFactory.create().addRestriction(RestrictionFactory.and(new Restriction[]{RestrictionFactory.eq("deletedName", var1), RestrictionFactory.eq("type", SoftRoleType.USER)})); |
||||
AuthorityContext.getInstance().getSoftDataController().remove(var2); |
||||
} |
||||
} |
@ -0,0 +1,235 @@
|
||||
package com.eco.plugin.wink.workflow.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 { |
||||
|
||||
/** |
||||
* 获取当前时间 格式 yyyy-MM-dd HH:mm:ss |
||||
* @return |
||||
*/ |
||||
public static String getNow() { |
||||
return DateToString(new Date(),"yyyy-MM-dd HH:mm:ss"); |
||||
} |
||||
|
||||
/** |
||||
* 日期转换为日期字符串 |
||||
* @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); |
||||
} |
||||
} |
@ -0,0 +1,32 @@
|
||||
package com.eco.plugin.wink.workflow.utils; |
||||
|
||||
import com.fr.decision.authority.data.CustomRole; |
||||
import com.fr.decision.webservice.bean.user.RoleBean; |
||||
import com.fr.decision.webservice.v10.user.CustomRoleService; |
||||
import com.fr.decision.webservice.v10.user.controller.SuperCustomRoleController; |
||||
|
||||
public class FRRoleUtils { |
||||
|
||||
/** |
||||
* 获取角色service |
||||
* @return |
||||
*/ |
||||
private static CustomRoleService getRoleService(){ |
||||
return CustomRoleService.getInstance(); |
||||
} |
||||
|
||||
/** |
||||
* 获取全部角色 |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static CustomRole[] getAllRole() throws Exception { |
||||
// List<RoleBean> roleBean = UserMiddleRoleService.getInstance().getAllCustomRoles();
|
||||
CustomRole[] roles = SuperCustomRoleController.KEY.getAllCustomRoles((String)null, ""); |
||||
return roles; |
||||
} |
||||
|
||||
public static RoleBean getRoleByName(String rolename) throws Exception { |
||||
return getRoleService().getCustomRole(rolename); |
||||
} |
||||
} |
@ -0,0 +1,235 @@
|
||||
package com.eco.plugin.wink.workflow.utils; |
||||
|
||||
import com.fr.decision.authority.AuthorityContext; |
||||
import com.fr.decision.authority.controller.UserController; |
||||
import com.fr.decision.authority.data.User; |
||||
import com.fr.decision.privilege.TransmissionTool; |
||||
import com.fr.decision.webservice.bean.user.*; |
||||
import com.fr.decision.webservice.v10.login.ExtendTokenProcessor; |
||||
import com.fr.decision.webservice.v10.login.LoginService; |
||||
import com.fr.decision.webservice.v10.user.UserService; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
public class FRUserUtils { |
||||
|
||||
/** |
||||
* 获取用户Service |
||||
* @return |
||||
*/ |
||||
public static UserService getUserService(){ |
||||
return UserService.getInstance(); |
||||
} |
||||
|
||||
/** |
||||
* 获取全量用户 |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static List<UserAdditionBean> getAllUsers() throws Exception { |
||||
// List<UserBean> userbean = UserMiddleRoleService.getInstance().getAllUsers(false);
|
||||
List<UserAdditionBean> users = new ArrayList<UserAdditionBean>(); |
||||
getAllUser(getAdminUser().getUsername(),0,1000,users); |
||||
return users; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param adminUsername 管理员用户名 |
||||
* @param page 页数 |
||||
* @param num 每页的数据 |
||||
* @param users 保存用户的列表 |
||||
*/ |
||||
private static void getAllUser(String adminUsername,int page,int num,List<UserAdditionBean> users) throws Exception { |
||||
Map<String,Object> result = getUserService().getAllUsers(adminUsername,page,num,"","",true); |
||||
Long total = (Long)result.get("total"); |
||||
List<UserAdditionBean> item = (List<UserAdditionBean>)result.get("items"); |
||||
users.addAll(item); |
||||
|
||||
page = page+1; |
||||
|
||||
if(page * num >= total){ |
||||
return ; |
||||
} |
||||
|
||||
getAllUser(adminUsername,page,num,users); |
||||
} |
||||
/** |
||||
* 添加用户 |
||||
* @param userBean |
||||
*/ |
||||
public static void addUser(UserBean userBean) throws Exception { |
||||
userBean.setPassword(TransmissionTool.defaultEncrypt(userBean.getPassword())); |
||||
getUserService().addUser(userBean); |
||||
} |
||||
|
||||
/** |
||||
* 删除用户 |
||||
* @param userBean |
||||
*/ |
||||
public static void updateUser(User userBean) throws Exception { |
||||
UserController userController = AuthorityContext.getInstance().getUserController(); |
||||
userController.update(userBean); |
||||
// UserServiceKit.getInstance().editUser(userBean,getAdminUser().getId());
|
||||
} |
||||
|
||||
/** |
||||
* 删除用户 |
||||
* @param user |
||||
* @return |
||||
*/ |
||||
public static int deleteUser(User user) throws Exception { |
||||
String userId = user.getId(); |
||||
|
||||
UserUpdateBean userUpdateBean = new UserUpdateBean(); |
||||
userUpdateBean.setRemoveUserIds(new String[]{userId}); |
||||
|
||||
return getUserService().deleteUsers(userUpdateBean); |
||||
} |
||||
|
||||
/** |
||||
* 根据用户名获取用户实体 |
||||
* @param userName |
||||
* @return |
||||
*/ |
||||
public static User getUserByUserName(String userName) throws Exception { |
||||
return getUserService().getUserByUserName(userName); |
||||
} |
||||
|
||||
/** |
||||
* 根据用户名获取用户实体 |
||||
* @param userName |
||||
* @return |
||||
*/ |
||||
public static UserBean getUserBeanByUserName(String userName ) throws Exception { |
||||
String id = getUserService().getUserByUserName(userName).getId(); |
||||
return getUser(id); |
||||
} |
||||
|
||||
/** |
||||
* 根据id获取用户 |
||||
* @param id |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static UserBean getUser(String id) throws Exception { |
||||
return getUserService().getUser(id); |
||||
} |
||||
|
||||
/** |
||||
* 判断是否是管理员 |
||||
* @param username |
||||
* @return |
||||
*/ |
||||
public static boolean isAdmin(String username) throws Exception{ |
||||
return getUserService().isAdmin(getUserByUserName(username).getId()); |
||||
} |
||||
|
||||
/** |
||||
* 禁用启用用户 |
||||
* @param userId |
||||
* @param state false 禁用 true 启用 |
||||
* @throws Exception 异常说明失败 |
||||
*/ |
||||
public static void forbidUser(String userId,boolean state) throws Exception { |
||||
getUserService().forbidUser(userId,state); |
||||
} |
||||
|
||||
/** |
||||
* 修改用户部门 |
||||
* @param departmentId |
||||
* @param postId |
||||
// * @param ud
|
||||
* @throws Exception |
||||
*/ |
||||
public static void updateDepartmentPostUsers(String departmentId, String postId, String userid) throws Exception { |
||||
AuthorityContext.getInstance().getUserController().addUserToDepartmentAndPost(userid, departmentId, postId); |
||||
// getUserService().updateDepartmentPostUsers(departmentId,postId,ud);
|
||||
} |
||||
|
||||
|
||||
// /**
|
||||
// * 验证密码是否正确
|
||||
// * @param psd 明文密码
|
||||
// * @param user 根据用户名获取得用户对象
|
||||
// * @return
|
||||
// */
|
||||
// public static boolean checkPsd(String psd,User user){
|
||||
// String shaPsd = CipherUtils.jdksha256(psd);
|
||||
//
|
||||
// return shaPsd.equals(user.getPassword());
|
||||
// }
|
||||
public static User getCurrentUser(HttpServletRequest req) throws Exception { |
||||
String username = LoginService.getInstance().getCurrentUserNameFromRequestCookie(req); |
||||
|
||||
if(Utils.isNullStr(username)){ |
||||
return null; |
||||
} |
||||
|
||||
return getUserByUserName(username); |
||||
} |
||||
|
||||
public static UserBean getCurrentUserBean(HttpServletRequest req) throws Exception { |
||||
String username = LoginService.getInstance().getCurrentUserNameFromRequestCookie(req); |
||||
|
||||
if(Utils.isNullStr(username)){ |
||||
return null; |
||||
} |
||||
|
||||
return getUserBeanByUserName(username); |
||||
} |
||||
|
||||
/** |
||||
* 获取用户部门角色 |
||||
* @param username |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
private static UserRolesBean getUserRolesBean(String username) throws Exception { |
||||
return FRUserUtils.getUserService().getUserDepAndCustomRoles(username); |
||||
} |
||||
|
||||
/** |
||||
* 获取部门职务 |
||||
* @param username |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static List<DepRoleBean> getDepRoleBean(String username) throws Exception{ |
||||
return getUserRolesBean(username).getDepRoles(); |
||||
} |
||||
|
||||
/** |
||||
* 获取角色 |
||||
* @param username |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static List<String> getCustomRoles(String username) throws Exception{ |
||||
return getUserRolesBean(username).getCustomRoles(); |
||||
} |
||||
|
||||
public static UserBean getAdminUser() throws Exception { |
||||
String adminid = getUserService().getAdminUserIdList().get(0); |
||||
return getUser(adminid); |
||||
} |
||||
|
||||
public static String getUsernameFromToken(String token){ |
||||
String username = ExtendTokenProcessor.KEY.getUsername(token); |
||||
return username; |
||||
} |
||||
|
||||
/** |
||||
* 通过参数获取用户 |
||||
* @param mobile |
||||
* @return |
||||
*/ |
||||
public static List<User> getUsersFromMobile(String mobile) throws Exception { |
||||
List<User> users = getUserService().getUsersFromMobile(mobile); |
||||
return users; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,332 @@
|
||||
package com.eco.plugin.wink.workflow.utils; |
||||
|
||||
import com.fr.base.ServerConfig; |
||||
import com.fr.base.TableData; |
||||
import com.fr.base.TemplateUtils; |
||||
import com.fr.decision.authority.AuthorityContext; |
||||
import com.fr.decision.authority.base.constant.type.operation.ManualOperationType; |
||||
import com.fr.decision.authority.data.User; |
||||
import com.fr.decision.base.util.UUIDUtil; |
||||
import com.fr.decision.privilege.encrpt.PasswordValidator; |
||||
import com.fr.decision.webservice.bean.authentication.OriginUrlResponseBean; |
||||
import com.fr.decision.webservice.interceptor.handler.ReportTemplateRequestChecker; |
||||
import com.fr.decision.webservice.login.LogInOutResultInfo; |
||||
import com.fr.decision.webservice.utils.DecisionServiceConstants; |
||||
import com.fr.decision.webservice.utils.DecisionStatusService; |
||||
import com.fr.decision.webservice.utils.UserSourceFactory; |
||||
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.general.data.DataModel; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.script.Calculator; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.stable.query.QueryFactory; |
||||
import com.fr.stable.query.restriction.RestrictionFactory; |
||||
import com.fr.third.springframework.web.method.HandlerMethod; |
||||
import com.fr.web.controller.ReportRequestService; |
||||
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 userList = AuthorityContext.getInstance().getUserController().find(QueryFactory.create().addRestriction(RestrictionFactory.eq("userName", userName))); |
||||
return userList != null && !userList.isEmpty(); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error(e.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 req, String token, int num) { |
||||
try { |
||||
if (StringUtils.isNotEmpty(token)) { |
||||
Cookie cookie = new Cookie("fine_auth_token", token); |
||||
long maxAge = num == -2 ? 1209600000L : (long)num; |
||||
cookie.setMaxAge((int)maxAge); |
||||
cookie.setPath(ServerConfig.getInstance().getCookiePath()); |
||||
req.addCookie(cookie); |
||||
Cookie rememberCookie = new Cookie("fine_remember_login", String.valueOf(num == -2 ? -2 : -1)); |
||||
rememberCookie.setMaxAge((int)maxAge); |
||||
rememberCookie.setPath(ServerConfig.getInstance().getCookiePath()); |
||||
req.addCookie(rememberCookie); |
||||
} else { |
||||
FineLoggerFactory.getLogger().error("empty token cannot save."); |
||||
} |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
} |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 后台登出 |
||||
* @param httpServletRequest |
||||
* @param httpServletResponse |
||||
*/ |
||||
public static void logoutByToken(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse,String token) |
||||
{ |
||||
httpServletRequest.setAttribute("fine_auth_token",token); |
||||
logout(httpServletRequest,httpServletResponse); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @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 getDBPsd(String username,String password){ |
||||
PasswordValidator pv = UserSourceFactory.getInstance().getUserSource(ManualOperationType.KEY).getPasswordValidator(); |
||||
String uuid = UUIDUtil.generate(); |
||||
|
||||
return pv.encode(username, password, uuid); |
||||
} |
||||
|
||||
/** |
||||
* 获取带参数的访问链接 |
||||
* @return |
||||
*/ |
||||
public static String getAllUrl(HttpServletRequest httpServletRequest){ |
||||
return WebUtils.getOriginalURL(httpServletRequest); |
||||
} |
||||
|
||||
/** |
||||
* 根据originKey获取源链接 |
||||
* @param req |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static String getOriginUrl(HttpServletRequest req) throws Exception { |
||||
String origin = req.getParameter("origin"); |
||||
if (StringUtils.isNotEmpty(origin)) { |
||||
OriginUrlResponseBean originUrlResponseBean = (OriginUrlResponseBean) DecisionStatusService.originUrlStatusService().get(origin); |
||||
DecisionStatusService.originUrlStatusService().delete(origin); |
||||
if (originUrlResponseBean != null) { |
||||
return originUrlResponseBean.getOriginUrl(); |
||||
} |
||||
} |
||||
|
||||
return new OriginUrlResponseBean(TemplateUtils.render("${fineServletURL}")).getOriginUrl(); |
||||
} |
||||
|
||||
/** |
||||
* 判断是否开启模板认证 |
||||
* @param |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static boolean isTempAuth(HttpServletRequest req,HttpServletResponse res) throws Exception { |
||||
ReportTemplateRequestChecker checker = new ReportTemplateRequestChecker(); |
||||
HandlerMethod hm = new HandlerMethod(new ReportRequestService(),ReportRequestService.class.getMethod("preview", HttpServletRequest.class, HttpServletResponse.class, String.class)); |
||||
return checker.checkRequest(req,res,hm); |
||||
} |
||||
|
||||
/** |
||||
* 获取数据集数据 |
||||
* @param serverDataSetName |
||||
* @return |
||||
*/ |
||||
public static DataModel getTableData(String serverDataSetName){ |
||||
TableData userInfo = TableDataConfig.getInstance().getTableData(serverDataSetName); |
||||
DataModel userInfoDM = userInfo.createDataModel(Calculator.createCalculator()); |
||||
// userInfoDM.getRowCount();
|
||||
// userInfoDM.getColumnIndex();
|
||||
// userInfoDM.getValueAt()
|
||||
return userInfoDM; |
||||
} |
||||
|
||||
public static String getIndex(HttpServletRequest req){ |
||||
String url = req.getScheme()+"://"+req.getServerName()+":"+String.valueOf(req.getServerPort())+req.getRequestURI(); |
||||
return url; |
||||
} |
||||
} |
@ -0,0 +1,186 @@
|
||||
package com.eco.plugin.wink.workflow.utils; |
||||
|
||||
import com.eco.plugin.wink.workflow.db.bean.DBLinkEntity; |
||||
import com.eco.plugin.wink.workflow.db.controller.WorkFlowController; |
||||
import org.apache.commons.dbcp2.BasicDataSourceFactory; |
||||
|
||||
import javax.sql.DataSource; |
||||
import java.sql.Connection; |
||||
import java.sql.ResultSet; |
||||
import java.sql.SQLException; |
||||
import java.sql.Statement; |
||||
import java.util.*; |
||||
|
||||
public class JDBCUtils { |
||||
private static Properties properties = new Properties(); |
||||
private static DataSource dataSource; |
||||
|
||||
static{ |
||||
DBLinkEntity dbLink = WorkFlowController.getAllDBLink().get(0); |
||||
properties.setProperty("driverClassName","com.mysql.jdbc.Driver"); |
||||
properties.setProperty("url",dbLink.getUrl()+"?useSSL=false&useUnicode=true&characterEncoding=UTF-8"); |
||||
properties.setProperty("username",dbLink.getUsername()); |
||||
properties.setProperty("password",dbLink.getPassword()); |
||||
properties.setProperty("initialSize","30"); |
||||
properties.setProperty("maxTotal","30"); |
||||
properties.setProperty("maxIdle","10"); |
||||
properties.setProperty("minIdle","5"); |
||||
properties.setProperty("maxWailMillis","1000"); |
||||
properties.setProperty("removeAbandonedOnMaintenance","true"); |
||||
properties.setProperty("removeAbandonedOnBorrow","true"); |
||||
properties.setProperty("removeAbandonedTimeout","300"); |
||||
try { |
||||
dataSource = BasicDataSourceFactory.createDataSource(properties); |
||||
} catch (Exception e) { |
||||
FRUtils.FRLogError("创建链接池异常:"+e.getMessage()); |
||||
} |
||||
|
||||
|
||||
} |
||||
|
||||
public static Connection getConnect(){ |
||||
Connection connection = null; |
||||
|
||||
try{ |
||||
connection = dataSource.getConnection(); |
||||
}catch(Exception e){ |
||||
FRUtils.FRLogError("获取数据库连接异常:"+e.getMessage()); |
||||
} |
||||
|
||||
return connection; |
||||
} |
||||
|
||||
/** |
||||
* 更新 |
||||
* @param sql |
||||
* @return |
||||
*/ |
||||
public static int update(String sql){ |
||||
Connection conn=null; |
||||
Statement st=null; |
||||
int count = 0; |
||||
|
||||
try { |
||||
conn = getConnect(); |
||||
st = conn.createStatement(); |
||||
count = st.executeUpdate(sql); |
||||
|
||||
} catch (SQLException e) { |
||||
FRUtils.FRLogError("执行updata语句异常"); |
||||
} finally { |
||||
release(conn, st, null); |
||||
} |
||||
|
||||
return count; |
||||
} |
||||
|
||||
/** |
||||
* 获取数据 |
||||
* @param sql |
||||
* @param columns |
||||
* @return |
||||
*/ |
||||
public static List<Map<String,Object>> getResult(String sql, String[] columns,String formid){ |
||||
List<Map<String,Object>> result = new ArrayList<Map<String,Object>>(); |
||||
|
||||
Connection conn=null; |
||||
Statement st=null; |
||||
ResultSet rs=null; |
||||
|
||||
try { |
||||
conn = getConnect(); |
||||
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)); |
||||
} |
||||
map.put("formid",formid); |
||||
result.add(map); |
||||
} |
||||
} catch (SQLException e) { |
||||
FRUtils.FRLogInfo("获取数据异常:"+e.getMessage()); |
||||
} finally { |
||||
release(conn, st, rs); |
||||
} |
||||
|
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* 获取数量 |
||||
* @param sql |
||||
* @return |
||||
*/ |
||||
public static int getCount(String sql){ |
||||
int count = 0; |
||||
|
||||
Connection conn=null; |
||||
Statement st=null; |
||||
ResultSet rs=null; |
||||
|
||||
try { |
||||
conn = getConnect(); |
||||
st = conn.createStatement(); |
||||
rs = st.executeQuery(sql); |
||||
//遍历查询每条记录
|
||||
while(rs.next()) { |
||||
count = rs.getInt(1); |
||||
} |
||||
} catch (SQLException e) { |
||||
FRUtils.FRLogInfo("获取数量异常:"+e.getMessage()); |
||||
} finally { |
||||
release(conn, st, rs); |
||||
} |
||||
|
||||
return count; |
||||
} |
||||
|
||||
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) { |
||||
FRUtils.FRLogError("关闭rs异常"); |
||||
} finally { |
||||
rs=null; |
||||
} |
||||
|
||||
} |
||||
|
||||
private static void closeSt(Statement st) { |
||||
try { |
||||
if(st!=null) { |
||||
st.close(); |
||||
} |
||||
} catch (SQLException e) { |
||||
FRUtils.FRLogError("关闭st异常"); |
||||
} finally { |
||||
st=null; |
||||
} |
||||
|
||||
} |
||||
|
||||
private static void closeConn(Connection conn) { |
||||
try { |
||||
if(conn!=null) { |
||||
conn.close(); |
||||
} |
||||
} catch (SQLException e) { |
||||
FRUtils.FRLogError("关闭connect异常"); |
||||
} finally { |
||||
conn=null; |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,108 @@
|
||||
package com.eco.plugin.wink.workflow.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 responseText(HttpServletResponse res,String text){ |
||||
PrintWriter pw; |
||||
try { |
||||
pw = WebUtils.createPrintWriter(res); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info(e.getMessage()); |
||||
return; |
||||
} |
||||
res.setContentType("text/html;charset=utf-8"); |
||||
pw.println(text); |
||||
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(); |
||||
} |
||||
} |
@ -0,0 +1,329 @@
|
||||
package com.eco.plugin.wink.workflow.utils; |
||||
|
||||
import com.fr.base.TemplateUtils; |
||||
import com.fr.data.NetworkHelper; |
||||
import com.fr.decision.webservice.v10.user.UserService; |
||||
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.List; |
||||
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",""); |
||||
FRUtils.FRLogInfo("reqBody:"+jsonString); |
||||
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 para3 = fw.indexOf(","); |
||||
return para3 != -1 ? fw.substring(0, para3) : 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); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param res |
||||
* @param path /com/fr/plugin/loginAuth/html/getMac.html |
||||
* @param parameterMap |
||||
*/ |
||||
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("跳转页面异常"); |
||||
} |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 判断是否是管理员 |
||||
* @param username |
||||
* @return |
||||
*/ |
||||
public static boolean isAdmin(String username) throws Exception{ |
||||
return UserService.getInstance().isAdmin(UserService.getInstance().getUserByUserName(username).getId()); |
||||
} |
||||
|
||||
/** |
||||
* 去掉浏览器中的参数 |
||||
* @param url |
||||
* @param param |
||||
* @return |
||||
*/ |
||||
public static String removeParam(String url,String param){ |
||||
if(!url.contains("?"+param) && !url.contains("&"+param)){ |
||||
return url; |
||||
} |
||||
|
||||
return url.substring(0,url.indexOf(url.contains("?"+param) ? "?"+param : "&"+param)); |
||||
} |
||||
|
||||
/** |
||||
* 获取跳转链接 |
||||
* @param req |
||||
* @param param |
||||
* @return |
||||
*/ |
||||
public static String getRedirectUrl(HttpServletRequest req,String param){ |
||||
String url = FRUtils.getAllUrl(req); |
||||
|
||||
if(isNotNullStr(param)){ |
||||
url = removeParam(url,param); |
||||
} |
||||
|
||||
url = encodeCH(url); |
||||
|
||||
return url; |
||||
} |
||||
|
||||
/** |
||||
* 去除空格换行 |
||||
* @param str |
||||
* @return |
||||
*/ |
||||
public static String trim(String str){ |
||||
return str.trim().replaceAll("\n","").replaceAll("\r",""); |
||||
} |
||||
|
||||
/** |
||||
* list 转化为指定字符分割的字符串 |
||||
* @param list |
||||
* @param list |
||||
* @return |
||||
*/ |
||||
public static String listToStr(List<String> list, String split){ |
||||
String result = ""; |
||||
|
||||
if(list == null || list.size() <= 0){ |
||||
return result; |
||||
} |
||||
|
||||
for(String str : list){ |
||||
result+=","+str; |
||||
} |
||||
|
||||
result = result.substring(1); |
||||
|
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* array 转化为指定字符分割的字符串 |
||||
* @param list |
||||
* @param list |
||||
* @return |
||||
*/ |
||||
public static String arrayToStr(String[] list, String split){ |
||||
String result = ""; |
||||
|
||||
if(list == null ||list.length <= 0){ |
||||
return result; |
||||
} |
||||
|
||||
for(int i=0;i<list.length;i++){ |
||||
String str = list[i]; |
||||
result+=","+str; |
||||
} |
||||
|
||||
result = result.substring(1); |
||||
|
||||
return result; |
||||
} |
||||
} |
@ -0,0 +1,37 @@
|
||||
package com.eco.plugin.wink.workflow.webresource; |
||||
|
||||
import com.fr.decision.fun.impl.AbstractWebResourceProvider; |
||||
import com.fr.decision.web.MainComponent; |
||||
import com.fr.plugin.transform.FunctionRecorder; |
||||
import com.fr.web.struct.Atom; |
||||
import com.fr.web.struct.Component; |
||||
import com.fr.web.struct.browser.RequestClient; |
||||
import com.fr.web.struct.category.ScriptPath; |
||||
import com.fr.web.struct.category.StylePath; |
||||
|
||||
/** |
||||
* Created by wink on 2021-12-03 |
||||
*/ |
||||
@FunctionRecorder |
||||
public class WebResourceProvider extends AbstractWebResourceProvider { |
||||
@Override |
||||
public Atom attach() { |
||||
return MainComponent.KEY; |
||||
} |
||||
|
||||
@Override |
||||
public Atom client() { |
||||
return new Component() { |
||||
@Override |
||||
public ScriptPath script(RequestClient requestClient) { |
||||
return ScriptPath.build("/com/eco/plugin/wink/workflow/js/ui.js"); |
||||
} |
||||
|
||||
@Override |
||||
public StylePath style(RequestClient requestClient) { |
||||
return StylePath.EMPTY; |
||||
// return StylePath.build("/com/fr/plugin/jdfSSO/css/icon.css");
|
||||
} |
||||
}; |
||||
} |
||||
} |
Loading…
Reference in new issue