@ -1,4 +1,4 @@
package org.jeecgframework.web. cgform.controller.autoform ;
package org.jeecgframework.web. autoform.controller ;
import java.io.IOException ;
import java.io.IOException ;
import java.io.StringWriter ;
import java.io.StringWriter ;
@ -9,10 +9,6 @@ import java.util.HashMap;
import java.util.Iterator ;
import java.util.Iterator ;
import java.util.List ;
import java.util.List ;
import java.util.Map ;
import java.util.Map ;
import java.util.Map.Entry ;
import java.util.Set ;
import java.util.regex.Matcher ;
import java.util.regex.Pattern ;
import javax.servlet.http.HttpServletRequest ;
import javax.servlet.http.HttpServletRequest ;
import javax.servlet.http.HttpServletResponse ;
import javax.servlet.http.HttpServletResponse ;
@ -22,7 +18,7 @@ import net.sf.json.JSONObject;
import org.apache.commons.lang3.StringUtils ;
import org.apache.commons.lang3.StringUtils ;
import org.apache.log4j.Logger ;
import org.apache.log4j.Logger ;
import org. jeecgframework.codegenerate.database.JeecgReadTable ;
import org. apache.velocity.VelocityContext ;
import org.jeecgframework.core.common.controller.BaseController ;
import org.jeecgframework.core.common.controller.BaseController ;
import org.jeecgframework.core.common.exception.BusinessException ;
import org.jeecgframework.core.common.exception.BusinessException ;
import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery ;
import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery ;
@ -32,19 +28,19 @@ import org.jeecgframework.core.constant.Globals;
import org.jeecgframework.core.util.DynamicDBUtil ;
import org.jeecgframework.core.util.DynamicDBUtil ;
import org.jeecgframework.core.util.MyBeanUtils ;
import org.jeecgframework.core.util.MyBeanUtils ;
import org.jeecgframework.core.util.ResourceUtil ;
import org.jeecgframework.core.util.ResourceUtil ;
import org.jeecgframework.core.util.SqlUtil ;
import org.jeecgframework.core.util.StringUtil ;
import org.jeecgframework.core.util.StringUtil ;
import org.jeecgframework.core.util.oConvertUtils ;
import org.jeecgframework.core.util.oConvertUtils ;
import org.jeecgframework.p3.core.util.plugin.ViewVelocity ;
import org.jeecgframework.tag.core.easyui.TagUtil ;
import org.jeecgframework.tag.core.easyui.TagUtil ;
import org.jeecgframework.web. cgform.entity.autoform .AutoFormDbEntity;
import org.jeecgframework.web. autoform.entity .AutoFormDbEntity;
import org.jeecgframework.web. cgform.entity.autoform .AutoFormDbFieldEntity;
import org.jeecgframework.web. autoform.entity .AutoFormDbFieldEntity;
import org.jeecgframework.web. cgform.entity.autoform .AutoFormEntity;
import org.jeecgframework.web. autoform.entity .AutoFormEntity;
import org.jeecgframework.web. cgform.entity.autoform .AutoFormParamEntity;
import org.jeecgframework.web. autoform.entity .AutoFormParamEntity;
import org.jeecgframework.web. cgform.entity.autoform .AutoFormStyleEntity;
import org.jeecgframework.web. autoform.entity .AutoFormStyleEntity;
import org.jeecgframework.web. cgform.service.autoform .AutoFormDbServiceI;
import org.jeecgframework.web. autoform.service .AutoFormDbServiceI;
import org.jeecgframework.web. cgform.service.autoform .AutoFormServiceI;
import org.jeecgframework.web. autoform.service .AutoFormServiceI;
import org.jeecgframework.web. cg form.util.AutoFormCommUtil;
import org.jeecgframework.web. auto form.util.AutoFormCommUtil;
import org.jeecgframework.web. cg form.util.AutoFormTemplateParseUtil;
import org.jeecgframework.web. auto form.util.AutoFormTemplateParseUtil;
import org.jeecgframework.web.cgform.util.TemplateUtil ;
import org.jeecgframework.web.cgform.util.TemplateUtil ;
import org.jeecgframework.web.system.pojo.base.DynamicDataSourceEntity ;
import org.jeecgframework.web.system.pojo.base.DynamicDataSourceEntity ;
import org.jeecgframework.web.system.pojo.base.TSType ;
import org.jeecgframework.web.system.pojo.base.TSType ;
@ -55,7 +51,6 @@ import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element ;
import org.jsoup.nodes.Element ;
import org.jsoup.select.Elements ;
import org.jsoup.select.Elements ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.context.annotation.Scope ;
import org.springframework.stereotype.Controller ;
import org.springframework.stereotype.Controller ;
import org.springframework.web.bind.annotation.RequestMapping ;
import org.springframework.web.bind.annotation.RequestMapping ;
import org.springframework.web.bind.annotation.ResponseBody ;
import org.springframework.web.bind.annotation.ResponseBody ;
@ -102,7 +97,7 @@ public class AutoFormController extends BaseController {
* /
* /
@RequestMapping ( params = "autoForm" )
@RequestMapping ( params = "autoForm" )
public ModelAndView autoForm ( HttpServletRequest request ) {
public ModelAndView autoForm ( HttpServletRequest request ) {
return new ModelAndView ( "jeecg/ cgform/ autoform/autoFormList") ;
return new ModelAndView ( "jeecg/ autoform/autoFormList") ;
}
}
/ * *
/ * *
@ -114,7 +109,6 @@ public class AutoFormController extends BaseController {
* @param
* @param
* /
* /
@SuppressWarnings ( "unchecked" )
@RequestMapping ( params = "datagrid" )
@RequestMapping ( params = "datagrid" )
public void datagrid ( AutoFormEntity autoForm , HttpServletRequest request , HttpServletResponse response , DataGrid dataGrid ) {
public void datagrid ( AutoFormEntity autoForm , HttpServletRequest request , HttpServletResponse response , DataGrid dataGrid ) {
CriteriaQuery cq = new CriteriaQuery ( AutoFormEntity . class , dataGrid ) ;
CriteriaQuery cq = new CriteriaQuery ( AutoFormEntity . class , dataGrid ) ;
@ -205,11 +199,9 @@ public class AutoFormController extends BaseController {
autoForm . setFormContent ( html ) ;
autoForm . setFormContent ( html ) ;
autoForm . setFormParse ( autoForm . getFormContent ( ) ) ;
autoForm . setFormParse ( autoForm . getFormContent ( ) ) ;
}
}
autoForm . setCreateDate ( new Date ( ) ) ;
autoForm . setCreateDate ( new Date ( ) ) ;
autoForm . setCreateName ( ResourceUtil . getSessionUserName ( ) . getRealName ( ) ) ;
autoForm . setCreateName ( ResourceUtil . getSessionUserName ( ) . getRealName ( ) ) ;
autoForm . setCreateBy ( ResourceUtil . getSessionUserName ( ) . getUserName ( ) ) ;
autoForm . setCreateBy ( ResourceUtil . getSessionUserName ( ) . getUserName ( ) ) ;
autoFormService . save ( autoForm ) ;
autoFormService . save ( autoForm ) ;
systemService . addLog ( message , Globals . Log_Type_INSERT , Globals . Log_Leavel_INFO ) ;
systemService . addLog ( message , Globals . Log_Type_INSERT , Globals . Log_Leavel_INFO ) ;
} catch ( Exception e ) {
} catch ( Exception e ) {
@ -249,17 +241,15 @@ public class AutoFormController extends BaseController {
t . setFormContent ( html ) ;
t . setFormContent ( html ) ;
t . setFormParse ( autoForm . getFormContent ( ) ) ;
t . setFormParse ( autoForm . getFormContent ( ) ) ;
}
}
autoForm . setUpdateDate ( new Date ( ) ) ;
autoForm . setUpdateDate ( new Date ( ) ) ;
autoForm . setUpdateName ( ResourceUtil . getSessionUserName ( ) . getRealName ( ) ) ;
autoForm . setUpdateName ( ResourceUtil . getSessionUserName ( ) . getRealName ( ) ) ;
autoForm . setUpdateBy ( ResourceUtil . getSessionUserName ( ) . getUserName ( ) ) ;
autoForm . setUpdateBy ( ResourceUtil . getSessionUserName ( ) . getUserName ( ) ) ;
autoFormService . saveOrUpdate ( t ) ;
autoFormService . saveOrUpdate ( t ) ;
attributes . put ( "id" , t . getId ( ) ) ;
attributes . put ( "id" , t . getId ( ) ) ;
j . setAttributes ( attributes ) ;
j . setAttributes ( attributes ) ;
message = "表单更新成功 ";
message = "表单更新成功 ! ";
if ( StringUtils . isBlank ( autoForm . getMainTableSource ( ) ) )
if ( StringUtils . isBlank ( autoForm . getMainTableSource ( ) ) )
message + = " ,主数据源为空,请选择主数据源! ";
message + = " (主数据源尚未设置) ";
} else {
} else {
if ( StringUtils . isNotBlank ( autoForm . getFormContent ( ) ) ) {
if ( StringUtils . isNotBlank ( autoForm . getFormContent ( ) ) ) {
// Map<String,Object> map = tool.processor(autoForm.getFormContent());
// Map<String,Object> map = tool.processor(autoForm.getFormContent());
@ -274,13 +264,12 @@ public class AutoFormController extends BaseController {
}
}
//TODO 待实现
//TODO 待实现
autoFormService . save ( autoForm ) ;
autoFormService . save ( autoForm ) ;
attributes . put ( "id" , autoForm . getId ( ) ) ;
attributes . put ( "id" , autoForm . getId ( ) ) ;
j . setAttributes ( attributes ) ;
j . setAttributes ( attributes ) ;
message = "表单添加成功 ";
message = "表单添加成功 ! ";
if ( StringUtils . isBlank ( autoForm . getMainTableSource ( ) ) )
if ( StringUtils . isBlank ( autoForm . getMainTableSource ( ) ) )
message + = " ,主数据源为空,请选择主数据源! ";
message + = " (主数据源尚未设置) ";
}
}
systemService . addLog ( message , Globals . Log_Type_UPDATE , Globals . Log_Leavel_INFO ) ;
systemService . addLog ( message , Globals . Log_Type_UPDATE , Globals . Log_Leavel_INFO ) ;
} catch ( Exception e ) {
} catch ( Exception e ) {
@ -307,7 +296,6 @@ public class AutoFormController extends BaseController {
map . put ( name , name ) ;
map . put ( name , name ) ;
}
}
}
}
// Elements ids = doc.select("input[name$=.id]");
// Elements ids = doc.select("input[name$=.id]");
// for (Element el: ids) {
// for (Element el: ids) {
// String name = el.attr("name");
// String name = el.attr("name");
@ -318,7 +306,6 @@ public class AutoFormController extends BaseController {
// map.put(name, name);
// map.put(name, name);
// }
// }
// }
// }
}
}
@ -336,7 +323,7 @@ public class AutoFormController extends BaseController {
JSONArray jsonArray = JSONArray . fromObject ( getStyleList ( "" ) ) ;
JSONArray jsonArray = JSONArray . fromObject ( getStyleList ( "" ) ) ;
req . setAttribute ( "styleSelect" , jsonArray . toString ( ) ) ;
req . setAttribute ( "styleSelect" , jsonArray . toString ( ) ) ;
return new ModelAndView ( "jeecg/ cgform/ autoform/autoForm-add") ;
return new ModelAndView ( "jeecg/ autoform/autoForm-add") ;
}
}
/ * *
/ * *
* 表 单 表 编 辑 页 面 跳 转
* 表 单 表 编 辑 页 面 跳 转
@ -355,7 +342,7 @@ public class AutoFormController extends BaseController {
JSONArray dbArray = JSONArray . fromObject ( getFormDbList ( autoForm . getId ( ) ) ) ;
JSONArray dbArray = JSONArray . fromObject ( getFormDbList ( autoForm . getId ( ) ) ) ;
req . setAttribute ( "dbDate" , dbArray . toString ( ) ) ;
req . setAttribute ( "dbDate" , dbArray . toString ( ) ) ;
return new ModelAndView ( "jeecg/ cgform/ autoform/autoForm-update") ;
return new ModelAndView ( "jeecg/ autoform/autoForm-update") ;
}
}
/ * *
/ * *
@ -409,9 +396,7 @@ public class AutoFormController extends BaseController {
for ( AutoFormDbEntity dbForm : list ) {
for ( AutoFormDbEntity dbForm : list ) {
map = new HashMap < String , Object > ( ) ;
map = new HashMap < String , Object > ( ) ;
map . put ( "id" , dbForm . getId ( ) ) ;
map . put ( "id" , dbForm . getId ( ) ) ;
map . put ( "name" , dbForm . getDbChName ( ) + "(" + dbForm . getDbName ( ) + ")" ) ;
map . put ( "name" , dbForm . getDbChName ( ) + "(" + dbForm . getDbName ( ) + ")" ) ;
map . put ( "dbCode" , dbForm . getDbName ( ) ) ;
map . put ( "dbCode" , dbForm . getDbName ( ) ) ;
map . put ( "pid" , "0" ) ;
map . put ( "pid" , "0" ) ;
//增加父节点
//增加父节点
@ -422,9 +407,7 @@ public class AutoFormController extends BaseController {
for ( AutoFormDbFieldEntity field : fieldlist ) {
for ( AutoFormDbFieldEntity field : fieldlist ) {
map = new HashMap < String , Object > ( ) ;
map = new HashMap < String , Object > ( ) ;
map . put ( "id" , field . getId ( ) ) ;
map . put ( "id" , field . getId ( ) ) ;
map . put ( "name" , ( StringUtils . isBlank ( field . getFieldText ( ) ) | | "null" . equals ( field . getFieldText ( ) ) ) ? field . getFieldName ( ) : field . getFieldText ( ) + "(" + field . getFieldName ( ) + ")" ) ;
map . put ( "name" , ( StringUtils . isBlank ( field . getFieldText ( ) ) | | "null" . equals ( field . getFieldText ( ) ) ) ? field . getFieldName ( ) : field . getFieldText ( ) + "(" + field . getFieldName ( ) + ")" ) ;
map . put ( "pId" , dbForm . getId ( ) ) ;
map . put ( "pId" , dbForm . getId ( ) ) ;
map . put ( "nocheck" , true ) ;
map . put ( "nocheck" , true ) ;
dateList . add ( map ) ;
dateList . add ( map ) ;
@ -436,9 +419,7 @@ public class AutoFormController extends BaseController {
for ( AutoFormDbFieldEntity field : fieldlist ) {
for ( AutoFormDbFieldEntity field : fieldlist ) {
map = new HashMap < String , Object > ( ) ;
map = new HashMap < String , Object > ( ) ;
map . put ( "id" , field . getId ( ) ) ;
map . put ( "id" , field . getId ( ) ) ;
map . put ( "name" , ( StringUtils . isBlank ( field . getFieldText ( ) ) | | "null" . equals ( field . getFieldText ( ) ) ) ? field . getFieldName ( ) : field . getFieldText ( ) + "(" + field . getFieldName ( ) + ")" ) ;
map . put ( "name" , ( StringUtils . isBlank ( field . getFieldText ( ) ) | | "null" . equals ( field . getFieldText ( ) ) ) ? field . getFieldName ( ) : field . getFieldText ( ) + "(" + field . getFieldName ( ) + ")" ) ;
map . put ( "pId" , dbForm . getId ( ) ) ;
map . put ( "pId" , dbForm . getId ( ) ) ;
map . put ( "nocheck" , true ) ;
map . put ( "nocheck" , true ) ;
dateList . add ( map ) ;
dateList . add ( map ) ;
@ -487,15 +468,11 @@ public class AutoFormController extends BaseController {
dsData . put ( "dsName" , db . getDbName ( ) ) ;
dsData . put ( "dsName" , db . getDbName ( ) ) ;
dsList . add ( dsData ) ;
dsList . add ( dsData ) ;
if ( "table" . equals ( db . getDbType ( ) ) ) {
if ( "table" . equals ( db . getDbType ( ) ) ) {
String hql = "select new Map(t.fieldName as fieldName,t.fieldText as fieldText) from AutoFormDbFieldEntity t where t.autoFormDbId=?" ;
String hql = "select new Map(t.fieldName as fieldName,t.fieldText as fieldText) from AutoFormDbFieldEntity t where t.autoFormDbId=?" ;
List < Map < String , Object > > columns = this . systemService . findHql ( hql , autoFormDbId ) ;
List < Map < String , Object > > columns = this . systemService . findHql ( hql , autoFormDbId ) ;
dsData . put ( "columns" , columns ) ;
dsData . put ( "columns" , columns ) ;
} else if ( "sql" . equals ( db . getDbType ( ) ) ) {
} else if ( "sql" . equals ( db . getDbType ( ) ) ) {
String hql = "select new Map(t.fieldName as fieldName,t.fieldText as fieldText) from AutoFormDbFieldEntity t where t.autoFormDbId=?" ;
String hql = "select new Map(t.fieldName as fieldName,t.fieldText as fieldText) from AutoFormDbFieldEntity t where t.autoFormDbId=?" ;
List < Map < String , Object > > columns = this . systemService . findHql ( hql , autoFormDbId ) ;
List < Map < String , Object > > columns = this . systemService . findHql ( hql , autoFormDbId ) ;
if ( columns . size ( ) > 0 ) {
if ( columns . size ( ) > 0 ) {
dsData . put ( "columns" , columns ) ;
dsData . put ( "columns" , columns ) ;
@ -563,12 +540,11 @@ public class AutoFormController extends BaseController {
//3.传递参数
//3.传递参数
//req.setAttribute("tbDbKey", autoFormDbEntity.getTbDbKey());
//req.setAttribute("tbDbKey", autoFormDbEntity.getTbDbKey());
req . setAttribute ( "dbKey" , autoFormDbEntity . getDbKey ( ) ) ;
req . setAttribute ( "dbKey" , autoFormDbEntity . getDbKey ( ) ) ;
}
}
req . setAttribute ( "paramList" , paramList ) ;
req . setAttribute ( "paramList" , paramList ) ;
req . setAttribute ( "autoFormPage" , autoForm ) ;
req . setAttribute ( "autoFormPage" , autoForm ) ;
}
}
return new ModelAndView ( "jeecg/ cgform/ autoform/autoForm-view") ;
return new ModelAndView ( "jeecg/ autoform/autoForm-view") ;
}
}
@ -633,7 +609,6 @@ public class AutoFormController extends BaseController {
paramMap . put ( key , tem . get ( key ) ) ;
paramMap . put ( key , tem . get ( key ) ) ;
}
}
String op = req . getParameter ( "op" ) ;
String op = req . getParameter ( "op" ) ;
if ( StringUtil . isEmpty ( op ) ) {
if ( StringUtil . isEmpty ( op ) ) {
op = AutoFormTemplateParseUtil . OP_VIEW ;
op = AutoFormTemplateParseUtil . OP_VIEW ;
@ -642,10 +617,10 @@ public class AutoFormController extends BaseController {
if ( StringUtils . isNotBlank ( autoForm . getFormName ( ) ) ) {
if ( StringUtils . isNotBlank ( autoForm . getFormName ( ) ) ) {
autoForm = this . systemService . findUniqueByProperty ( AutoFormEntity . class , "formName" , autoForm . getFormName ( ) ) ;
autoForm = this . systemService . findUniqueByProperty ( AutoFormEntity . class , "formName" , autoForm . getFormName ( ) ) ;
if ( autoForm = = null ) {
if ( autoForm = = null ) {
return new ModelAndView ( "jeecg/ cgform/ autoform/autoForm-error") . addObject ( "message" , "表单信息获取失败!" ) ;
return new ModelAndView ( "jeecg/ autoform/autoForm-error") . addObject ( "message" , "表单信息获取失败!" ) ;
}
}
} else {
} else {
return new ModelAndView ( "jeecg/ cgform/ autoform/autoForm-error") . addObject ( "message" , "formName不能为空! " ) ;
return new ModelAndView ( "jeecg/ autoform/autoForm-error") . addObject ( "message" , "formName不能为空! " ) ;
}
}
//根据formid查询表单的参数
//根据formid查询表单的参数
@ -654,7 +629,7 @@ public class AutoFormController extends BaseController {
for ( String param : paramList ) {
for ( String param : paramList ) {
String paramValue = req . getParameter ( param ) ;
String paramValue = req . getParameter ( param ) ;
if ( paramValue = = null ) {
if ( paramValue = = null ) {
return new ModelAndView ( "jeecg/ cgform/ autoform/autoForm-error") . addObject ( "message" , "缺少表单参数:" + param ) ;
return new ModelAndView ( "jeecg/ autoform/autoForm-error") . addObject ( "message" , "缺少表单参数:" + param ) ;
}
}
}
}
}
}
@ -673,7 +648,7 @@ public class AutoFormController extends BaseController {
ftlContent = AutoFormTemplateParseUtil . parseHtmlForAdd ( ftlContent , paras ) ;
ftlContent = AutoFormTemplateParseUtil . parseHtmlForAdd ( ftlContent , paras ) ;
req . setAttribute ( "formContent" , ftlContent ) ;
req . setAttribute ( "formContent" , ftlContent ) ;
req . setAttribute ( "op" , op ) ;
req . setAttribute ( "op" , op ) ;
return new ModelAndView ( "jeecg/ cgform/ autoform/autoForm-review-add") ;
return new ModelAndView ( "jeecg/ autoform/autoForm-review-add") ;
} else if ( AutoFormTemplateParseUtil . OP_UPDATE . equals ( op ) ) {
} else if ( AutoFormTemplateParseUtil . OP_UPDATE . equals ( op ) ) {
paras = getFormData ( autoForm , paramMap ) ;
paras = getFormData ( autoForm , paramMap ) ;
String id = req . getParameter ( "id" ) ;
String id = req . getParameter ( "id" ) ;
@ -684,23 +659,23 @@ public class AutoFormController extends BaseController {
ftlContent = AutoFormTemplateParseUtil . parseHtmlForUpdate ( ftlContent , paras ) ;
ftlContent = AutoFormTemplateParseUtil . parseHtmlForUpdate ( ftlContent , paras ) ;
req . setAttribute ( "formContent" , ftlContent ) ;
req . setAttribute ( "formContent" , ftlContent ) ;
req . setAttribute ( "op" , op ) ;
req . setAttribute ( "op" , op ) ;
return new ModelAndView ( "jeecg/ cgform/ autoform/autoForm-review-update") ;
return new ModelAndView ( "jeecg/ autoform/autoForm-review-update") ;
} else if ( AutoFormTemplateParseUtil . OP_ADD_OR_UPDATE . equals ( op ) ) {
} else if ( AutoFormTemplateParseUtil . OP_ADD_OR_UPDATE . equals ( op ) ) {
paras = getFormData ( autoForm , paramMap ) ;
paras = getFormData ( autoForm , paramMap ) ;
// 2.解析ueditor html 注入数据【智能提交模式】
// 2.解析ueditor html 注入数据【智能提交模式】
ftlContent = AutoFormTemplateParseUtil . parseHtmlForAddOrUpdate ( ftlContent , paras ) ;
ftlContent = AutoFormTemplateParseUtil . parseHtmlForAddOrUpdate ( ftlContent , paras ) ;
req . setAttribute ( "formContent" , ftlContent ) ;
req . setAttribute ( "formContent" , ftlContent ) ;
req . setAttribute ( "op" , op ) ;
req . setAttribute ( "op" , op ) ;
return new ModelAndView ( "jeecg/ cgform/ autoform/autoForm-review-addorupdate") ;
return new ModelAndView ( "jeecg/ autoform/autoForm-review-addorupdate") ;
}
}
req . setAttribute ( "formContent" , ftlContent ) ;
req . setAttribute ( "formContent" , ftlContent ) ;
req . setAttribute ( "op" , op ) ;
req . setAttribute ( "op" , op ) ;
return new ModelAndView ( "jeecg/ cgform/ autoform/autoForm-review") ;
return new ModelAndView ( "jeecg/ autoform/autoForm-review") ;
} catch ( Exception e ) {
} catch ( Exception e ) {
e . printStackTrace ( ) ;
e . printStackTrace ( ) ;
message = "表单添加失败:" + e . getMessage ( ) ;
message = "表单添加失败:" + e . getMessage ( ) ;
}
}
return new ModelAndView ( "jeecg/ cgform/ autoform/autoForm-error") . addObject ( "message" , message ) ;
return new ModelAndView ( "jeecg/ autoform/autoForm-error") . addObject ( "message" , message ) ;
}
}
@ -728,7 +703,7 @@ public class AutoFormController extends BaseController {
if ( autoFormDbFieldEntityList . size ( ) > 0 ) {
if ( autoFormDbFieldEntityList . size ( ) > 0 ) {
StringBuffer hqlTable = new StringBuffer ( ) . append ( "select " ) ;
StringBuffer hqlTable = new StringBuffer ( ) . append ( "select " ) ;
for ( AutoFormDbFieldEntity autoFormDbFieldEntity : autoFormDbFieldEntityList ) {
for ( AutoFormDbFieldEntity autoFormDbFieldEntity : autoFormDbFieldEntityList ) {
//author:jg_renjie----start-----date:20160228--------for: TASK #704 【表单填报预览】针对特殊类型数据, 需要进行转换, 比如blob
boolean flag = false ;
boolean flag = false ;
for ( Map < String , Object > typeMap : typeList ) {
for ( Map < String , Object > typeMap : typeList ) {
String dataType = typeMap . get ( "dataType" ) . toString ( ) . toUpperCase ( ) ;
String dataType = typeMap . get ( "dataType" ) . toString ( ) . toUpperCase ( ) ;
@ -759,7 +734,6 @@ public class AutoFormController extends BaseController {
//当前上下文中的DB环境, 获取数据库表中的所有数据
//当前上下文中的DB环境, 获取数据库表中的所有数据
data = systemService . findForJdbc ( hqlTable . toString ( ) ) ;
data = systemService . findForJdbc ( hqlTable . toString ( ) ) ;
}
}
else {
else {
DynamicDataSourceEntity dynamicDataSourceEntity = dynamicDataSourceServiceI . getDynamicDataSourceEntityForDbKey ( formDb . getDbKey ( ) ) ;
DynamicDataSourceEntity dynamicDataSourceEntity = dynamicDataSourceServiceI . getDynamicDataSourceEntityForDbKey ( formDb . getDbKey ( ) ) ;
if ( dynamicDataSourceEntity ! = null ) {
if ( dynamicDataSourceEntity ! = null ) {
@ -799,14 +773,18 @@ public class AutoFormController extends BaseController {
// data = systemService.findForJdbc(dbDynSql);
// data = systemService.findForJdbc(dbDynSql);
Object dbKeys = paramMap . get ( "dbKey" ) ;
Object dbKeys = paramMap . get ( "dbKey" ) ;
if ( dbKeys ! = null & & dbKeys ! = "" ) {
if ( oConvertUtils. isNotEmpty ( dbKeys ) ) {
if ( dbKeys instanceof String ) {
if ( dbKeys instanceof String ) {
String dbKey = dbKeys . toString ( ) ;
String dbKey = dbKeys . toString ( ) ;
data = DynamicDBUtil . findList ( dbKey , dbDynSql ) ;
data = DynamicDBUtil . findList ( dbKey , dbDynSql ) ;
} else {
} else {
String [ ] keys = ( String [ ] ) dbKeys ;
String [ ] keys = ( String [ ] ) dbKeys ;
String dbKey = keys [ 0 ] ;
String dbKey = keys [ 0 ] ;
data = DynamicDBUtil . findList ( dbKey , dbDynSql ) ;
if ( oConvertUtils . isNotEmpty ( dbKey ) ) {
data = DynamicDBUtil . findList ( dbKey , dbDynSql ) ;
} else {
data = systemService . findForJdbc ( dbDynSql ) ;
}
}
}
} else {
} else {
data = systemService . findForJdbc ( dbDynSql ) ;
data = systemService . findForJdbc ( dbDynSql ) ;
@ -831,7 +809,7 @@ public class AutoFormController extends BaseController {
* @param dbTableNm
* @param dbTableNm
* @return
* @return
* /
* /
//author:jg_renjie----start-----date:20160228--------for: TASK #704 【表单填报预览】针对特殊类型数据, 需要进行转换, 比如blob
private List < Map < String , Object > > getColumnTypes ( String dbTableNm , String dbkey ) {
private List < Map < String , Object > > getColumnTypes ( String dbTableNm , String dbkey ) {
List < Map < String , Object > > list = new ArrayList < Map < String , Object > > ( ) ;
List < Map < String , Object > > list = new ArrayList < Map < String , Object > > ( ) ;
String sql = "select DATA_TYPE as dataType,COLUMN_NAME as columnNm from information_schema.COLUMNS where TABLE_NAME='" + dbTableNm + "'" ;
String sql = "select DATA_TYPE as dataType,COLUMN_NAME as columnNm from information_schema.COLUMNS where TABLE_NAME='" + dbTableNm + "'" ;
@ -884,7 +862,7 @@ public class AutoFormController extends BaseController {
TemplateUtil tool = new TemplateUtil ( ) ;
TemplateUtil tool = new TemplateUtil ( ) ;
Map < String , Object > map = tool . processor ( autoForm . getFormContent ( ) ) ;
Map < String , Object > map = tool . processor ( autoForm . getFormContent ( ) ) ;
req . setAttribute ( "formContent" , map . get ( "parseHtml" ) ) ;
req . setAttribute ( "formContent" , map . get ( "parseHtml" ) ) ;
return new ModelAndView ( "jeecg/ cgform/ autoform/autoForm-review") ;
return new ModelAndView ( "jeecg/ autoform/autoForm-review") ;
}
}
/ * *
/ * *
*
*
@ -917,9 +895,7 @@ public class AutoFormController extends BaseController {
if ( StringUtils . isNotBlank ( dbForm . getAutoFormId ( ) ) ) {
if ( StringUtils . isNotBlank ( dbForm . getAutoFormId ( ) ) ) {
List < AutoFormDbEntity > dbFormList = this . systemService . findByProperty ( AutoFormDbEntity . class , "autoFormId" , dbForm . getAutoFormId ( ) ) ;
List < AutoFormDbEntity > dbFormList = this . systemService . findByProperty ( AutoFormDbEntity . class , "autoFormId" , dbForm . getAutoFormId ( ) ) ;
if ( dbFormList . size ( ) > 0 ) {
if ( dbFormList . size ( ) > 0 ) {
message = "<option value='' selected='selected'>请选择数据源</option>" ;
message = "<option value='' selected='selected'>请选择数据源</option>" ;
for ( AutoFormDbEntity entity : dbFormList ) {
for ( AutoFormDbEntity entity : dbFormList ) {
//根据数据源名称进行匹配数据
//根据数据源名称进行匹配数据
message + = "<option value='" + entity . getDbName ( ) + "'>" + ( StringUtils . isBlank ( entity . getDbChName ( ) ) ? entity . getDbName ( ) : entity . getDbChName ( ) ) + "</option>" ;
message + = "<option value='" + entity . getDbName ( ) + "'>" + ( StringUtils . isBlank ( entity . getDbChName ( ) ) ? entity . getDbName ( ) : entity . getDbChName ( ) ) + "</option>" ;
@ -928,17 +904,13 @@ public class AutoFormController extends BaseController {
j . setMsg ( message ) ;
j . setMsg ( message ) ;
} else {
} else {
j . setSuccess ( false ) ;
j . setSuccess ( false ) ;
message = "<option value='' selected='selected'>请先添加数据源</option>" ;
message = "<option value='' selected='selected'>请先添加数据源</option>" ;
j . setMsg ( message ) ;
j . setMsg ( message ) ;
}
}
} else {
} else {
//2.如果ID为空, 则option拼接提示信息
//2.如果ID为空, 则option拼接提示信息
j . setSuccess ( false ) ;
j . setSuccess ( false ) ;
message = "<option value='' selected='selected'>请先添加数据源</option>" ;
message = "<option value='' selected='selected'>请先添加数据源</option>" ;
j . setMsg ( message ) ;
j . setMsg ( message ) ;
}
}
return j ;
return j ;
@ -963,7 +935,6 @@ public class AutoFormController extends BaseController {
List < AutoFormDbEntity > list = this . systemService . findHql ( hqlList , dbForm . getDbName ( ) , dbForm . getAutoFormId ( ) ) ;
List < AutoFormDbEntity > list = this . systemService . findHql ( hqlList , dbForm . getDbName ( ) , dbForm . getAutoFormId ( ) ) ;
if ( list . size ( ) = = 1 ) {
if ( list . size ( ) = = 1 ) {
dbForm = list . get ( 0 ) ;
dbForm = list . get ( 0 ) ;
//dbForm = this.systemService.findUniqueByProperty(AutoFormDbEntity.class, "dbName", dbForm.getDbName());
//dbForm = this.systemService.findUniqueByProperty(AutoFormDbEntity.class, "dbName", dbForm.getDbName());
List < Map < String , Object > > columns = new ArrayList < Map < String , Object > > ( ) ;
List < Map < String , Object > > columns = new ArrayList < Map < String , Object > > ( ) ;
if ( "table" . equals ( dbForm . getDbType ( ) ) ) {
if ( "table" . equals ( dbForm . getDbType ( ) ) ) {
@ -982,9 +953,7 @@ public class AutoFormController extends BaseController {
}
}
}
}
if ( columns . size ( ) > 0 ) {
if ( columns . size ( ) > 0 ) {
message = "<option value='' selected='selected'>请选择字段</option>" ;
message = "<option value='' selected='selected'>请选择字段</option>" ;
for ( Map < String , Object > map : columns ) {
for ( Map < String , Object > map : columns ) {
message + = "<option value='" + map . get ( "fieldName" ) + "'>" + ( StringUtils . isBlank ( ( String ) map . get ( "fieldText" ) ) ? map . get ( "fieldName" ) : map . get ( "fieldText" ) ) + "</option>" ;
message + = "<option value='" + map . get ( "fieldName" ) + "'>" + ( StringUtils . isBlank ( ( String ) map . get ( "fieldText" ) ) ? map . get ( "fieldName" ) : map . get ( "fieldText" ) ) + "</option>" ;
}
}
@ -992,23 +961,19 @@ public class AutoFormController extends BaseController {
j . setMsg ( message ) ;
j . setMsg ( message ) ;
} else {
} else {
j . setSuccess ( false ) ;
j . setSuccess ( false ) ;
message = "<option value='' selected='selected'>请先添加字段</option>" ;
message = "<option value='' selected='selected'>请先添加字段</option>" ;
j . setMsg ( message ) ;
j . setMsg ( message ) ;
}
}
} else {
} else {
//2.如果ID为空, 则option拼接提示信息
//2.如果ID为空, 则option拼接提示信息
j . setSuccess ( false ) ;
j . setSuccess ( false ) ;
message = "<option value='' selected='selected'>请先选择数据源</option>" ;
message = "<option value='' selected='selected'>请先选择数据源</option>" ;
j . setMsg ( message ) ;
j . setMsg ( message ) ;
}
}
}
}
return j ;
return j ;
}
}
//add-begin--Author:jg_renjie Date:20150725 for: 数据源根据autoFormId与dbName取数据,并拼接成tr串
/ * *
/ * *
* 得 到 与 指 定 数 据 源 对 应 的 字 段 , 并 拼 接 成 table 字 符 串
* 得 到 与 指 定 数 据 源 对 应 的 字 段 , 并 拼 接 成 table 字 符 串
* @param dbForm
* @param dbForm
@ -1038,7 +1003,6 @@ public class AutoFormController extends BaseController {
} else {
} else {
attributes . put ( "dbName" , dbForm . getDbName ( ) ) ;
attributes . put ( "dbName" , dbForm . getDbName ( ) ) ;
}
}
//dbForm = this.systemService.findUniqueByProperty(AutoFormDbEntity.class, "dbName", dbForm.getDbName());
//dbForm = this.systemService.findUniqueByProperty(AutoFormDbEntity.class, "dbName", dbForm.getDbName());
List < Map < String , Object > > columns = new ArrayList < Map < String , Object > > ( ) ;
List < Map < String , Object > > columns = new ArrayList < Map < String , Object > > ( ) ;
if ( "table" . equals ( dbForm . getDbType ( ) ) ) {
if ( "table" . equals ( dbForm . getDbType ( ) ) ) {
@ -1199,7 +1163,6 @@ public class AutoFormController extends BaseController {
message = "<option value=\"\">无字段</option>" ;
message = "<option value=\"\">无字段</option>" ;
}
}
j . setSuccess ( true ) ;
j . setSuccess ( true ) ;
//j.setMsg(message);
//j.setMsg(message);
attributes . put ( "tableHtml" , message ) ;
attributes . put ( "tableHtml" , message ) ;
@ -1215,7 +1178,7 @@ public class AutoFormController extends BaseController {
}
}
return j ;
return j ;
}
}
//add-end--Author:jg_renjie Date:20150725 for: 数据源根据autoFormId与dbName取数据,并拼接成tr串
/ * *
/ * *
* 字 段 下 拉 框 选 择 值 时 , 自 动 填 充 表 头 信 息
* 字 段 下 拉 框 选 择 值 时 , 自 动 填 充 表 头 信 息
@ -1246,7 +1209,6 @@ public class AutoFormController extends BaseController {
return j ;
return j ;
}
}
/ * *
/ * *
* 添 加 表 单
* 添 加 表 单
*
*
@ -1352,7 +1314,6 @@ public class AutoFormController extends BaseController {
return j ;
return j ;
}
}
@RequestMapping ( params = "checkTbCode" )
@RequestMapping ( params = "checkTbCode" )
@ResponseBody
@ResponseBody
public com . alibaba . fastjson . JSONObject checkTbCode ( String param , String cVal ) {
public com . alibaba . fastjson . JSONObject checkTbCode ( String param , String cVal ) {
@ -1375,7 +1336,6 @@ public class AutoFormController extends BaseController {
jsonObject . put ( "status" , "y" ) ;
jsonObject . put ( "status" , "y" ) ;
return jsonObject ;
return jsonObject ;
}
}
private void delFormDb ( String autoFormId ) {
private void delFormDb ( String autoFormId ) {
List < AutoFormDbEntity > list = this . systemService . findByProperty ( AutoFormDbEntity . class , "autoFormId" , autoFormId ) ;
List < AutoFormDbEntity > list = this . systemService . findByProperty ( AutoFormDbEntity . class , "autoFormId" , autoFormId ) ;
if ( list ! = null & & list . size ( ) > 0 ) {
if ( list ! = null & & list . size ( ) > 0 ) {
@ -1386,4 +1346,169 @@ public class AutoFormController extends BaseController {
}
}
}
}
/ * *
* 表 单 表 列 表 页 面 跳 转
*
* @return
* /
@RequestMapping ( params = "autoForm_vm" )
public void autoFormVM ( HttpServletResponse response , HttpServletRequest request ) throws Exception {
VelocityContext velocityContext = new VelocityContext ( ) ;
String viewName = "autoform/autoFormList.vm" ;
ViewVelocity . view ( request , response , viewName , velocityContext ) ;
}
@RequestMapping ( params = "goAdd_vm" )
public void goAddVM ( HttpServletResponse response , HttpServletRequest request ) throws Exception {
JSONArray jsonArray = JSONArray . fromObject ( getStyleList ( "" ) ) ;
VelocityContext velocityContext = new VelocityContext ( ) ;
String viewName = "autoform/autoForm-add.vm" ;
velocityContext . put ( "styleSelect" , jsonArray . toString ( ) ) ;
ViewVelocity . view ( request , response , viewName , velocityContext ) ;
}
@RequestMapping ( params = "goUpdate_vm" )
public void goUpdateVM ( AutoFormEntity autoForm , HttpServletResponse response , HttpServletRequest request ) throws Exception {
VelocityContext velocityContext = new VelocityContext ( ) ;
if ( StringUtil . isNotEmpty ( autoForm . getId ( ) ) ) {
autoForm = autoFormService . getEntity ( AutoFormEntity . class , autoForm . getId ( ) ) ;
velocityContext . put ( "autoFormPage" , autoForm ) ;
}
JSONArray jsonArray = JSONArray . fromObject ( getStyleList ( autoForm . getFormStyleId ( ) ) ) ;
velocityContext . put ( "styleSelect" , jsonArray . toString ( ) ) ;
JSONArray dbArray = JSONArray . fromObject ( getFormDbList ( autoForm . getId ( ) ) ) ;
velocityContext . put ( "dbDate" , dbArray . toString ( ) ) ;
String viewName = "autoform/autoForm-update.vm" ;
ViewVelocity . view ( request , response , viewName , velocityContext ) ;
}
/ *
* 在 预 览 前 , 检 查 制 定 的 数 据 源 是 否 有 参 数 , 并 输 入 参 数 的 值
* /
@RequestMapping ( params = "parse_vm" )
public void parseVM ( AutoFormEntity autoForm , HttpServletResponse response , HttpServletRequest request ) throws Exception {
VelocityContext velocityContext = new VelocityContext ( ) ;
if ( StringUtils . isNotBlank ( autoForm . getId ( ) ) ) {
autoForm = this . systemService . findUniqueByProperty ( AutoFormEntity . class , "id" , autoForm . getId ( ) ) ;
List < String > paramList = getFormParams ( autoForm . getId ( ) ) ;
List < AutoFormDbEntity > autoList = systemService . findByProperty ( AutoFormDbEntity . class , "dbName" , autoForm . getMainTableSource ( ) ) ;
if ( autoList ! = null & & autoList . size ( ) > 0 ) {
AutoFormDbEntity autoFormDbEntity = autoList . get ( 0 ) ;
//3.传递参数
//req.setAttribute("tbDbKey", autoFormDbEntity.getTbDbKey());
velocityContext . put ( "dbKey" , autoFormDbEntity . getDbKey ( ) ) ;
}
velocityContext . put ( "paramList" , paramList ) ;
velocityContext . put ( "autoFormPage" , autoForm ) ;
}
String viewName = "autoform/autoForm-view.vm" ;
ViewVelocity . view ( request , response , viewName , velocityContext ) ;
}
@RequestMapping ( params = "viewContent_vm" )
public void viewContentVM ( AutoFormEntity autoForm , HttpServletResponse response , HttpServletRequest request ) throws Exception {
VelocityContext velocityContext = new VelocityContext ( ) ;
String message = "" ;
try {
//获取参数
Map < String , String [ ] > tem = request . getParameterMap ( ) ;
Map < String , Object > paramMap = new HashMap < String , Object > ( ) ;
for ( String key : tem . keySet ( ) ) {
paramMap . put ( key , tem . get ( key ) ) ;
}
String op = request . getParameter ( "op" ) ;
if ( StringUtil . isEmpty ( op ) ) {
op = AutoFormTemplateParseUtil . OP_VIEW ;
}
Map < String , List < Map < String , Object > > > paras = new HashMap < String , List < Map < String , Object > > > ( ) ;
if ( StringUtils . isNotBlank ( autoForm . getFormName ( ) ) ) {
autoForm = this . systemService . findUniqueByProperty ( AutoFormEntity . class , "formName" , autoForm . getFormName ( ) ) ;
if ( autoForm = = null ) {
String viewName = "autoform/autoForm-error.vm" ;
velocityContext . put ( "message" , "表单信息获取失败!" ) ;
ViewVelocity . view ( request , response , viewName , velocityContext ) ;
}
} else {
String viewName = "autoform/autoForm-error.vm" ;
velocityContext . put ( "message" , "formName不能为空! " ) ;
ViewVelocity . view ( request , response , viewName , velocityContext ) ;
}
//根据formid查询表单的参数
List < String > paramList = getFormParams ( autoForm . getId ( ) ) ;
if ( paramList ! = null & & paramList . size ( ) > 0 ) {
for ( String param : paramList ) {
String paramValue = request . getParameter ( param ) ;
if ( paramValue = = null ) {
String viewName = "autoform/autoForm-error.vm" ;
velocityContext . put ( "message" , "缺少表单参数:" + param ) ;
ViewVelocity . view ( request , response , viewName , velocityContext ) ;
}
}
}
velocityContext . put ( "formName" , autoForm . getFormName ( ) ) ;
velocityContext . put ( "param" , paramMap ) ;
//paras = getFormData(autoForm,paramMap);
String ftlContent = autoForm . getFormParse ( ) ;
// 1.获取表单数据
if ( AutoFormTemplateParseUtil . OP_VIEW . equals ( op ) ) {
// 2.解析ueditor html 注入数据【预览查看模式】
paras = getFormData ( autoForm , paramMap ) ;
ftlContent = AutoFormTemplateParseUtil . parseHtmlForView ( ftlContent , paras ) ;
} else if ( AutoFormTemplateParseUtil . OP_ADD . equals ( op ) ) {
// 2.解析ueditor html 注入数据【添加提交模式】
ftlContent = AutoFormTemplateParseUtil . parseHtmlForAdd ( ftlContent , paras ) ;
velocityContext . put ( "formContent" , ftlContent ) ;
velocityContext . put ( "op" , op ) ;
String viewName = "autoform/autoForm-review-add.vm" ;
ViewVelocity . view ( request , response , viewName , velocityContext ) ;
} else if ( AutoFormTemplateParseUtil . OP_UPDATE . equals ( op ) ) {
paras = getFormData ( autoForm , paramMap ) ;
String id = request . getParameter ( "id" ) ;
if ( StringUtil . isEmpty ( id ) ) {
throw new BusinessException ( "参数id不能为空! " ) ;
}
// 2.解析ueditor html 注入数据【更新提交模式】
ftlContent = AutoFormTemplateParseUtil . parseHtmlForUpdate ( ftlContent , paras ) ;
velocityContext . put ( "formContent" , ftlContent ) ;
velocityContext . put ( "op" , op ) ;
String viewName = "autoform/autoForm-review-update.vm" ;
ViewVelocity . view ( request , response , viewName , velocityContext ) ;
} else if ( AutoFormTemplateParseUtil . OP_ADD_OR_UPDATE . equals ( op ) ) {
paras = getFormData ( autoForm , paramMap ) ;
// 2.解析ueditor html 注入数据【智能提交模式】
ftlContent = AutoFormTemplateParseUtil . parseHtmlForAddOrUpdate ( ftlContent , paras ) ;
velocityContext . put ( "formContent" , ftlContent ) ;
velocityContext . put ( "op" , op ) ;
String viewName = "autoform/autoForm-review-addorupdate.vm" ;
ViewVelocity . view ( request , response , viewName , velocityContext ) ;
}
velocityContext . put ( "formContent" , ftlContent ) ;
velocityContext . put ( "op" , op ) ;
String viewName = "autoform/autoForm-review.vm" ;
ViewVelocity . view ( request , response , viewName , velocityContext ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
message = "表单添加失败:" + e . getMessage ( ) ;
}
String viewName = "autoform/autoForm-error.vm" ;
velocityContext . put ( "message" , message ) ;
ViewVelocity . view ( request , response , viewName , velocityContext ) ;
}
}
}