fs-danaus
2021-03-05 a6a76f98715a5539c8fd77676d0ea1af5c9c5a4c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
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 ;
    }
}