package com.yc.service.build.type;
|
import java.io.File;
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpSession;
|
|
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.lang.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.context.annotation.Scope;
|
import org.springframework.dao.DataAccessException;
|
import org.springframework.jdbc.support.rowset.SqlRowSet;
|
import org.springframework.stereotype.Service;
|
|
import com.yc.service.build.top.BuildTopIfc;
|
import com.yc.service.commons.GformIfc;
|
import com.yc.service.panel.PanelServiceIfc;
|
import com.yc.utils.SessionKey;
|
|
@Service("T_22_Impl")
|
@Scope("prototype")
|
public class T_22_Impl extends BaseImpl implements T_22_Ifc {
|
|
private final String GET_PROC_NAME="declare @hdtable varchar(200) ;\n"
|
+ " SELECT @hdtable = hdtable FROM gform WHERE formid=? \n"
|
+ " select @hdtable as hdtable ; \n";
|
|
private final String GET_ZHONG_NAME="SELECT JNITempTable FROM gform WHERE formid=?";
|
|
private final String GET_PROC_PARAM="select name,colid,isoutparam,xtype from syscolumns where id=? order by colid";
|
|
private final String GET_PROC_ID="select id from sysobjects where name=?";
|
|
private final String GET_COLUMNS = " declare @formid int ; \n"
|
+ " select @formid = ? ; \n"
|
+ " if exists(select 1 from gform where formid = @formid and hdtable like '%.do%') \n"
|
+ " begin \n"
|
+ " select fieldid as name from gfield where formid = @formid and isLoad = 1 and isnull(HeadFlag,0) = 0 and isnull(DataLink,0)=1 order by StatisID asc ;\n"
|
+ " end else \n"
|
+ " begin \n "
|
+ " select name from syscolumns \n"
|
+ " where id=(select id from sysobjects where name=(select hdtable from gform where formid=@formid)) \n"
|
+ " and isoutparam=0 \n"
|
+ " order by colid ; \n"
|
+ " end ; ";
|
@Override
|
public String getScriptColumns(String formId){
|
SqlRowSet rs = this.jdbcTemplate.queryForRowSet(GET_COLUMNS, formId);
|
StringBuilder procParam= new StringBuilder();
|
procParam.append("[");
|
String temp=null;
|
while(rs != null && rs.next()){
|
temp=rs.getString("name");
|
temp=temp.replace("@","");
|
procParam.append("'").append(temp).append("',");
|
}
|
if(procParam.length()>1){
|
procParam.deleteCharAt(procParam.length()-1);
|
}
|
procParam.append("]");
|
//为空则是淘宝接口
|
|
return procParam.toString();
|
}
|
|
@Override
|
public List<Map<String,Object>> getProcInfo(String procId){
|
return this.jdbcTemplate.queryForList(GET_PROC_PARAM,procId);
|
}
|
@Override
|
public Map<String,Object> executProc(String proc) {
|
return this.jdbcTemplate.queryForMap(proc);
|
}
|
@Override
|
public String getProcName(String formid) {
|
try {
|
return this.jdbcTemplate.queryForObject(GET_PROC_NAME,new Object[] {formid},String.class);
|
|
} catch (Exception e) {
|
throw e ;
|
}
|
}
|
@Override
|
public String getzhongName(String formid) {
|
return this.jdbcTemplate.queryForObject(GET_ZHONG_NAME, new Object[] {formid},String.class);
|
}
|
@Override
|
public void doExecutProc_2(String proc) {
|
this.jdbcTemplate.execute(" Set ARITHABORT ON ");
|
this.jdbcTemplate.execute(proc);
|
}
|
@Override
|
public String getProcId(String procName) {
|
SqlRowSet rs= this.jdbcTemplate.queryForRowSet(GET_PROC_ID, procName);
|
if(rs.next()){
|
return rs.getString(1);
|
}
|
return null;
|
}
|
@Override
|
public SqlRowSet doGetRowSet(String sql, Object... objs) throws DataAccessException{
|
this.jdbcTemplate.execute(" Set ARITHABORT ON \n SET NOCOUNT ON \n");
|
return this.jdbcTemplate.queryForRowSet(sql, objs);
|
|
}
|
|
|
@Override
|
public synchronized int build() throws Exception {
|
Map<String, Object> gformInfo = gformIfc.getGformInfo("formname,showdetail,isopenFuncshowpwdedit,isshowpwdedit,optype,version", Integer.parseInt(formID));
|
buildDataHead(gformInfo);
|
buildIndex(gformInfo);
|
buildTop(gformInfo);
|
buildHelpPage(gformInfo);
|
buildJsCssHead();
|
buildPanel();
|
return 0;
|
}
|
/**
|
* 生成jsp数据处理头页面
|
* @throws Exception
|
*/
|
public void buildDataHead(Map<String,Object> gformInfo) throws Exception{
|
String fileName = "dataHead.jsp";
|
String tmpJsp = getPageCode(fileName);
|
tmpJsp = tmpJsp.replace("[?formId]", formID);
|
//--操作类型
|
if(gformInfo.get("optype")!=null&&!StringUtils.isBlank(gformInfo.get("optype").toString())){
|
tmpJsp = tmpJsp.replace("[?formOptType]", gformInfo.get("optype").toString().equalsIgnoreCase("0")?"-1":gformInfo.get("optype").toString());
|
}else{
|
tmpJsp = tmpJsp.replace("[?formOptType]","-1");
|
}
|
//操作类型--//
|
|
tmpJsp = tmpJsp.replace("[?formType]",type+"");
|
// tmpJsp = tmpJsp.replace("[?isShowPwdEdit]",toString(map.get("isshowpwdedit")));//1类型没有确认
|
tmpJsp = tmpJsp.replace("[?isOpenFuncShowPwdEdit]",toString(gformInfo.get("isopenFuncshowpwdedit")));
|
tmpJsp = tmpJsp.replace("[?version]",("".equalsIgnoreCase(toString(gformInfo.get("version")))?"0":toString(gformInfo.get("version"))));
|
buildPageCode(tmpJsp, fileName);
|
buildPageCode(tmpJsp, "grid2.jsp");
|
}
|
/**
|
* 生成主页面
|
* @throws Exception
|
*/
|
public void buildIndex(Map<String,Object> gformInfo) throws Exception{
|
String fileName = "index.jsp";
|
String data = getPageCode(fileName);
|
//--------从gform表获取是否显示大标题字段值(isTitle)判断是否显示大标题,并替换标识符-2012-02-20-syz--------[begin]----------------------
|
|
// String menuname_str="";
|
String sSQL = "select * from gform where formid='" + formID + "' and isTitle='1' ";// isTitle=1表示配置了显示大标题
|
List<Map<String, Object>> arrayList = new ArrayList<Map<String, Object>>();
|
arrayList = getArrayList(sSQL);
|
String procName = getProcName(formID) ;
|
if (procName == null || "".equals(procName)) {
|
throw new Exception("请在9801中定义主表名称(被调用的 过程名称 )") ;
|
}
|
if (arrayList.size() > 0) {// 如果配置了显示大标题
|
String TopAndTitle_str = "<table id=\"top_table\" width=\"100%\" bgcolor=\"#DEEDF7\">\n" + "<tr>\n" + "<td>\n"
|
+ "<div id=\"title_top\">[?title]</div>\n" + "</td></tr>\n" + "<tr>\n" + "<td>\n"
|
+ "<hr style=\"position: absolute;left:0px;top:28px;height: 1px;color: #bdc7c6;width: 99%;\">\n"
|
+ "</td>\n" + "</tr>\n" + "<tr><td>\n" + "<div id=\"tplt-top\">\n"
|
+ "\t\t\t<%@ include file=\"top.jsp\" %>\n" + "\t\t</div>\n" + "</td></tr>\n" + "</table>"
|
+ " <input type=\"hidden\" name=execdo id=\"execdo\" value=\"" + getExecDo(procName)
|
+ "\" >";
|
data = data.replace("[?TopAndTitle]", TopAndTitle_str);// 替换功能号标识符
|
} else {
|
// 如果没有配置显示大标题
|
String TopAndTitle_str = "<div id=\"tplt-top\">\n" + "\t\t\t<%@ include file=\"top.jsp\" %>\n" + "</div>"
|
+ "<input type=\"hidden\" name=execdo id=\"execdo\" value=\"" + getExecDo(procName)
|
+ "\" >";
|
data = data.replace("[?TopAndTitle]", TopAndTitle_str);// 替换功能号标识符
|
}
|
|
// --------从gform表获取是否显示大标题字段值(isTitle)判断是否显示大标题,并替换标识符-2012-02-20-syz-----[end]-------------------------//
|
|
//----------------
|
|
data = data.replace("[?title]", gformInfo.get("formname")+"");
|
buildPageCode(data, fileName);
|
}
|
/**
|
* 处理过程存在.do的函数 xin 2017-7-20 18:04:18
|
* @param execdo
|
* @return
|
*/
|
private String getExecDo(String execdo){
|
return (execdo.indexOf(".do")!=-1?execdo:"");
|
}
|
/**
|
* 生成top页面
|
* @throws Exception
|
*/
|
public void buildTop(Map<String,Object> gformInfo) throws Exception{
|
buildTopIfc.build(Integer.parseInt(formID), type,getBuildPath()+"top.jsp",getToPath()+"top.jsp",gformInfo,this);
|
}
|
/**
|
* 生成帮助页面
|
* @throws Exception
|
*/
|
public void buildHelpPage(Map<String,Object> gformInfo) throws Exception{
|
buildTopIfc.build(Integer.parseInt(formID), type,getTemPath()+"help.jsp",getToPath()+"help.jsp",gformInfo,this);
|
}
|
/**
|
* 生成js css 导入的页面
|
* @throws Exception
|
*/
|
public void buildJsCssHead() throws Exception{
|
String fileName = "jsCssHead.jsp";
|
String data = getPageCode(fileName);
|
//----------------
|
String scriptColumns = getScriptColumns(formID);
|
data = data.replace("[?columns]", scriptColumns.toLowerCase());
|
buildPageCode(data, fileName);
|
}
|
|
|
@Autowired
|
private GformIfc gformIfc;
|
|
/**
|
* 生成panel页面
|
* @throws Exception
|
*/
|
public void buildPanel() throws Exception{
|
String fileName = "panel.jsp";
|
String[] data=new String[2];
|
data[0]=FileUtils.readFileToString(new File(getBuildPath()+fileName),"utf-8");
|
data[1]=FileUtils.readFileToString(new File(getTemPath()+"panelControl.jsp"), "utf-8");
|
//----------------
|
Map<String, String> map=pIfc.getPanelHtml(Integer.parseInt(formID), type,data,this);
|
buildPageCode(map.get("panHTML"), fileName);
|
buildPageCode(map.get("panelControl"), "panelControl"+formID+".jsp");
|
}
|
|
@Autowired
|
private PanelServiceIfc pIfc;
|
|
@Autowired
|
private BuildTopIfc buildTopIfc;
|
|
|
/**
|
* 获取页面传过来的参数值集合 map ,适用获取于 22 类型窗体
|
* @param request
|
* @return
|
*/
|
@Override
|
public Map<String,String> getParamMap(HttpServletRequest request) {
|
HttpSession session = request.getSession();
|
Map<String,String> map = new HashMap<String,String> () ;
|
//String dbId = Maintaince.getDatabaseId(request);
|
try {
|
//DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap( request) ;
|
//SpObserver.setDBtoInstance("_"+dataSourceEntity.getDbId());//切换数据源
|
String parameter = request.getParameter("param");
|
String[] paramVas = null;
|
if (parameter != null) {
|
paramVas = SessionKey.replaceSessionValue(parameter.replaceAll("@p@",";"), session).split(";");
|
}
|
String formid = request.getParameter("formid");
|
String columns = this.getScriptColumns(formid);
|
if (columns != null && !"".equals(columns)) {
|
columns = columns.replace("[", "").replace("]","").replace("'","");
|
String fieldIds[] = columns.split(",") ;
|
for (int i = 0 ;i< fieldIds.length;i++) {
|
String value = "" ;
|
if (fieldIds[i] != null) { // && fieldIds[i].indexOf("'usercode'") > 0 ) {
|
if (paramVas !=null && paramVas.length >= i +1 ) {
|
value = paramVas[i] ;
|
}else {
|
value = "" ;
|
}
|
}
|
map.put(fieldIds[i], value) ;
|
}
|
}
|
}catch (Exception e) {
|
//e.printStackTrace();
|
throw e ;
|
}finally {
|
// SpObserver.setDBtoInstance();
|
}
|
return map ;
|
}
|
}
|