fs-danaus
2021-03-16 b9e8fc5bba5c30050cae3419a414c3d999365295
提交 | 用户 | age
a6a76f 1 /*
F 2  * (#)TreeGrid.java 1.0 2011-3-3 2011-3-3
3  */
4 package com.yc.action.grid;
5
6 import com.yc.action.BaseAction;
7 import com.yc.exception.ApplicationException;
8 import com.yc.factory.FactoryBean;
9 import com.yc.multiData.SpObserver;
10 import com.yc.service.build.type.T_22_Ifc;
11 import com.yc.service.grid.GridServiceIfc;
12 import com.yc.service.impl.DBHelper;
13 import com.yc.utils.EncodeUtil;
14 import com.yc.utils.FileUtil;
15 import com.yc.utils.YCBase64;
16 import org.apache.commons.lang.StringUtils;
17 import org.springframework.beans.factory.annotation.Autowired;
18 import org.springframework.dao.DataAccessException;
19 import org.springframework.dao.EmptyResultDataAccessException;
20 import org.springframework.jdbc.support.rowset.SqlRowSet;
21 import org.springframework.jdbc.support.rowset.SqlRowSetMetaData;
22 import org.springframework.stereotype.Service;
23
24 import java.io.File;
25 import java.io.UnsupportedEncodingException;
26 import java.sql.SQLException;
27 import java.util.HashMap;
28 import java.util.List;
29 import java.util.Map;
30 import java.util.regex.Pattern;
31
32
33 /***
34  * TreeGrid表格生成,
35  *
36  *
37  * @author 邓文峰 2011-3-3
38  **/
39 @SuppressWarnings("all")
40 @Service("treeGrid")
41 public class TreeGrid extends BaseAction implements TreeGridIfc {
42     private static final int GRID_HEIGHT = 300;
43     /**
44      * 表格处理的业务类
45      */
46     @Autowired
47     private GridServiceIfc gridService;//表格处理的业务类
48
49     //static  String domain= AttachmentConfig.get("attachment.server");
50
51     /**
52      * 取得与树设置有关的字段名,
53      * 格式:树1字段1;树1字段2,树2字段1;树2字段2
54      * by danaus 2018-11-20 支持3类型显示多树功能而修改
55      **/
56     private synchronized String getTreeFields(int formid, String dbid) {
57         try {
58             SpObserver.setDBtoInstance("_" + dbid);
59             return gridService.getSimpleJdbcTemplate().queryForObject("SELECT stuff((SELECT',' + CONVERT(VARCHAR, nodeid) FROM _systreeset  where formid=? FOR XML PATH ('')),1,1,'') ", new Object[]{formid}, String.class);
60         } finally {
61             SpObserver.setDBtoInstance();
62         }
63     }
64
65     /**
66      * 根据功能号取得格线高度
67      **/
68     public synchronized int getGrigHieght(int formID, int type, String dbid) {
69         if (type != 8) {
70             try {
71                 SpObserver.setDBtoInstance("_" + dbid);
72                 Integer in = gridService.getSimpleJdbcTemplate().queryForObject("select GridHeight from  gform where formid=" + formID, Integer.class);
73                 return in == null ? 0 : in;
74             } finally {
75                 SpObserver.setDBtoInstance();
76             }
77         } else if (type == 8) {//3表结构
78             int temp = 0;
79             int tg = 0;
80             List<Map> list = null;
81             try {
82                 SpObserver.setDBtoInstance("_" + dbid);
83                 list = gridService.getThreeTableInfo(formID);
84             } finally {
85                 SpObserver.setDBtoInstance();
86             }
87             if (list.size() == 0) {
88                 throw new ApplicationException("三表关联未设置好--9825");
89             }
90             for (Map map : list) {
91                 temp = (Integer) map.get("DetailFormID");
92                 tg = (map.get("gridHeight") == null) ? 0 : (Integer) map.get("gridHeight");
93             }
94             list = null;
95             try {
96                 SpObserver.setDBtoInstance("_" + dbid);
97                 int h = gridService.getSimpleJdbcTemplate().queryForObject("select GridHeight from  gform where formid=" + formID, Integer.class);
98                 if (tg == 0)
99                     tg = gridService.getSimpleJdbcTemplate().queryForObject("select GridHeight from  gform where formid=" + temp, Integer.class);
100                 return (tg == 0 ? GRID_HEIGHT : tg) + (h == 0 ? GRID_HEIGHT : h);
101             } finally {
102                 SpObserver.setDBtoInstance();
103             }
104         } else {
105             return 0;
106         }
107     }
108
109     /**
110      * 根据类型选用不同的字段作为排序
111      *
112      * @return 1表示清单,2表示明细
113      **/
114     private int setOrderName(TreeGridDTO dto) {
115
116         switch (dto.winType) {
117             case 9:
118             case 15:
119             case 17:
120             case 499:
121             case 497:
122                 if (dto.conNum == 0) {
123                     //isList=t
124                     return 1;
125                 } else
126                     return 2;
127             case 1:
128                 if (dto.b497 || dto.b499)
129                     return 2;
130                 else
131                     return 1;
132             default:
133                 return 1;
134         }
135     }
136
137     private int setToolAdd(TreeGridDTO dto) {
138         switch (dto.winType) {
139             case 9:
140             case 15:
141             case 17:
142             case 499:
143             case 497:
144                 if (dto.conNum == 0)
145                     return 1;
146                 else
147                     return 2;
148             case 18:
149             case 38:
150             case 19:
151                 return 1;
152             default:
153                 return 2;
154         }
155     }
156
157     //只有明细表才需要执行,其他的都只是输出{}
158     private String setToolAddForNew(TreeGridDTO dto) {
159         if (dto.postStatusAddNew) return "<%=bdMap.toString()%>";
160         switch (dto.winType) {
161             case 9:
162             case 15:
163             case 17:
164             case 499:
165             case 497:
166                 if (dto.conNum == 0)
167                     return "{}";
168                 else
169                     return "<%=bdMap.toString()%>";
170             case 18:
171             case 38:
172             case 19:
173                 return "{}";
174             default:
175                 return "{}";
176         }
177     }
178
179     /**
180      * 根据窗体类型取得应当读取哪一个表的数据.
181      **/
182     private synchronized int setGetPrivaryTable(int winType) {
183         switch (winType) {
184             case 5:
185             case 9:
186             case 2:
187             case 30:
188             case 301:
189             case 10:
190             case 19:
191             case 304:
192                 return 1;//从表
193             case 8://三表
194                 return 2;
195             default:
196                 return 0;
197         }
198     }
199
200     /**
201      * 是否为单据类型,
202      **/
203     private synchronized boolean isDanJun(TreeGridDTO dto) {
204         if (dto.winType == 15 || dto.winType == 9 || dto.winType == 17 || dto.winType == 499 || dto.winType == 497)
205             return true;
206         else
207             return false;
208     }
209
210     /**
211      * 根据功能号取得主从表名称 -----9801信息---增加新窗体类型都需要增加相应判断
212      **/
213     public String getTableName(int formid, String winType, TreeGridDTO dto) {
214         SqlRowSet gform = null;
215         try {
216             SpObserver.setDBtoInstance("_" + dto.dbid);
217             gform = gridService.getGformByFormID(formid);
218         } finally {
219             SpObserver.setDBtoInstance();
220         }
221         String[] temp = winType.split("\\|");
222         dto.winType = Integer.parseInt(temp[0]);
223         dto.conNum = temp.length > 1 ? Integer.parseInt(temp[1]) : 0;
224         if (!gform.wasNull()) {
225             gform.first();
226             dto.HDTable = gform.getString("hdtable");
227             dto.dataformid = (gform.getString("dataformid") == null || gform.getString("dataformid").length() == 0 || gform.getString("dataformid").equalsIgnoreCase("0")) ? "" : (gform.getString("dataformid") + (!this.isDanJun(dto) ? "" : "@p@" + gform.getInt("predocstatus")));
228             dto.tranformid = (gform.getString("dataformid") == null || gform.getString("dataformid").length() == 0 || gform.getString("dataformid").equalsIgnoreCase("0")) ? "" : (gform.getString("dataformid"));
229             dto.DTtable = gform.getString("dttable");
230             dto.frozencols = gform.getInt("frozencols");
231             dto.formname = gform.getString("formname");
232             dto.gantt = gform.getBoolean("isGantt");//是否为甘特图类型的功能号
233             dto.predocstatus = gform.getInt("predocstatus");//确认前状态,为了给格线在确认后不能再修改(新增,修改,删除) by 2013-02-01
234             dto.rowcopyfields = gform.getString("rowcopyfields");//行复制时排除字段
235             dto.pageSize = gform.getInt("pageSize");//页记录数
236             dto.autopaging = gform.getInt("autopaging");//是否分页
237             dto.optype = gform.getInt("optype");//功能号权限
238             dto.lockGridSort = gform.getInt("LockGridSort");//冻结列排序
239             dto.colset = gform.getInt("isShowCell");//是否显示列过滤
240             dto.mainCol = gform.getString("byGroup");//树分组显示字段
241             dto.isFilter = gform.getInt("isFilter");//是否打开过滤功能
242             boolean blactions = gform.getBoolean("addNewRow");//直接增行
243 //         try {
244 //         dto.postStatusAddNew=gform.getInt("PostStatusGridAddNew");//根据状态值是否可以显示增行按钮,用在OA审核中
245 //         }catch(Exception e) {
246 //             dto.postStatusAddNew=0;
247 //         }
248             if (blactions) dto.actions = "<Actions OnClickButtonAdd=\"AddRowEnd\" />";
249             dto.defaultRowCount = gform.getInt("DefaultRowCount");//格线默认加载时显示行数
250             if (!"".equalsIgnoreCase(dto.tolkey) && (dto.b497 || dto.b499) && dto.PriFormID > 0) {//是多表的情况 且是第一个子功能号
251
252                 SqlRowSet f = null;
253                 try {
254                     SpObserver.setDBtoInstance("_" + dto.dbid);
255                     f = gridService.getGformByFormID(dto.PriFormID);
256                 } finally {
257                     SpObserver.setDBtoInstance();
258                 }
259                 if (!f.wasNull()) {
260                     f.first();
261                     dto.rowcopyformids = f.getString("rowcopyformids");//复单时排除功能号
262                 }
263
264             } else {
265                 dto.rowcopyformids = gform.getString("rowcopyformids");//复单时排除功能号
266             }
267             if (dto.gridHeight == 0) dto.gridHeight = gform.getInt("GridHeight");//表格高度
268             dto.glcodefield = gform.getString("glcodefield");//会计科目需要的字段
269             if (!this.isNullOrEmptry(dto.glcodefield)) {//格式:主表汇总,明细表汇总|平衡字段|平衡值公式字段
270                 List<Map<String, Object>> map = null;
271                 try {
272                     SpObserver.setDBtoInstance("_" + dto.dbid);
273                     map = gridService.getSimpleJdbcTemplate().queryForList("select MasterSumFields,DetailSumFields from _sysmasterdetail where FormID=?", dto.formID);
274                 } finally {
275                     SpObserver.setDBtoInstance();
276                 }
277                 if (map.size() > 0) {
278                     Map<String, Object> m = map.get(0);
279                     dto.gltotal = m.get("MasterSumFields") + "," + m.get("DetailSumFields") + "|" + gform.getString("checkblncfields") + "|" + gform.getString("chkFormula");
280                     m = null;
281                 }
282                 map = null;
283             }
284             dto.index1 = gform.getString("index1");//列表的排序字段-9类型
285             dto.index2 = gform.getString("index2");//明细表的排序字段-5类型
286             dto.formdatafilters = gform.getString("formdatafilters") == null ? "" : this.replaceBlank(gform.getString("formdatafilters"));
287             dto.ProcGroupafterSavedoc = gform.getString("ProcGroupafterSavedoc") == null ? "" : this.replaceBlank(gform.getString("ProcGroupafterSavedoc"));
288             dto.trangroup = gform.getString("transgroupcode") == null ? "" : gform.getString("transgroupcode");
289             dto.DealAfterDocSave = gform.getString("DealAfterDocSave") == null ? "" : this.replaceBlank(gform.getString("DealAfterDocSave"));
290
291             dto.cancelProc = gform.getString("CancelBtnProcName") == null ? "" : this.replaceBlank(gform.getString("CancelBtnProcName"));
292
293             dto.revokeProc = gform.getString("RevokeBtnProcName") == null ? "" : this.replaceBlank(gform.getString("RevokeBtnProcName"));
294
295             dto.cancelisSave = gform.getBoolean("CancelIsSave") ? 1 : 0;
296             dto.isExchangeDataWithHost = gform.getBoolean("isExchangeDataWithHost") ? 1 : 0;
297
298             if (dto.winType == 0 || dto.winType == 7 || dto.winType == 1 || dto.winType == 5 || (dto.winType == 9 && dto.conNum == 0) || dto.winType == 3 || dto.winType == 4 ||
299                     dto.winType == 17 || dto.winType == 302 || dto.winType == 19 ||
300                     (dto.winType == 499 && dto.conNum == 0) ||
301                     (dto.winType == 497 && dto.conNum == 0) ||
302                     (dto.winType == 15 && (dto.conNum == 0 || dto.conNum == 2))) {
303                 dto.table = dto.HDTable;
304                 dto.isList = true;
305             } else {
306                 dto.table = dto.DTtable;
307             }
308
309             gform = null;
310             return dto.table;
311         } else
312             return null;
313     }
314
315     private void getFirstField(TreeGridDTO dto) throws DataAccessException, SQLException {
316         //1先读表关键功能,如果没有相关的再读表结构
317
318         String keyfields = null;
319         try {
320             SpObserver.setDBtoInstance("_" + dto.dbid);
321             keyfields = gridService.getTableKeyFields(dto.table);
322         } finally {
323             SpObserver.setDBtoInstance();
324         }
325
326         if (keyfields == null || "".equals(keyfields)) {
327             //2只取主表,主从表情况 及18,19类型,三表暂时不考虑
328             List<String> keys = null;
329             try {
330                 SpObserver.setDBtoInstance("_" + dto.dbid);
331                 keys = gridService.getPrimaryKey(dto.table);
332             } finally {
333                 SpObserver.setDBtoInstance();
334             }
335             for (String str : keys) {
336                 if ("".equals(dto.field))
337                     dto.field += str;
338                 else
339                     dto.field += ";" + str;
340             }
341             keys = null;
342         } else {
343             String[] arry = keyfields.split(";");
344             for (int i = 0; i < arry.length; i++) {
345                 if ("".equals(dto.field))
346                     dto.field += arry[i].toLowerCase();
347                 else
348                     dto.field += ";" + arry[i].toLowerCase();
349
350             }
351             arry = null;
352         }
353         dto.primeKey = dto.field;
354     }
355
356     private void print(String root, TreeGridDTO dto) throws DataAccessException, SQLException {//输出表格
357         String sql = "select top 1 fieldid from gfield where formid=? and HeadFlag=? and ShowOnGrid=1 order by statisid desc";
358         if (dto.winType != 9 && dto.winType != 15) {//针对只生成一个表格的情况,17类型由于第二个没有表格所以也存在这里了
359             try {
360                 SpObserver.setDBtoInstance("_" + dto.dbid);
361                 dto.gfields = gridService.getGfiledByFormID9(dto.formID, this.setGetPrivaryTable(dto.winType));//取得所有字段信息 增加类型
362             } finally {
363                 SpObserver.setDBtoInstance();
364             }
365         } else {
366             if (dto.winType == 15 && dto.conNum == 1) {
367                 List<Map> list = null;
368                 try {
369                     SpObserver.setDBtoInstance("_" + dto.dbid);
370                     list = gridService.getThreeTableInfo(dto.formID);
371                 } finally {
372                     SpObserver.setDBtoInstance();
373                 }
374                 if (list.size() == 0) {
375                     throw new ApplicationException(";;" + dto.formID + "-三表关联未设置好--9825");
376                 }
377                 for (Map map : list) {
378                     int temp = (Integer) map.get("DetailFormID");
379                     dto.masterKey = (String) map.get("MasterKeys");
380                     dto.detailKey = (String) map.get("DetailKeys");
381                     dto.formID3 = temp;
382                     dto.tempGridHeight = (map.get("gridHeight") == null) ? 0 : (Integer) map.get("gridHeight");
383                 }
384                 list = null;
385             }
386             if (dto.conNum < 2) {
387                 try {
388                     SpObserver.setDBtoInstance("_" + dto.dbid);
389                     dto.gfields = gridService.getGfiledByFormID9(dto.formID, dto.conNum);//取得所有字段信息
390                     dto.lastField = gridService.getSimpleJdbcTemplate().queryForObject(sql, new Object[]{dto.formID, 1}, String.class);
391                 } catch (DataAccessException e) {
392                     dto.lastField = "";
393                     throw new ApplicationException(dto.formID + "-列表没设置需要显示的字段,请在9802重新设置");
394
395                 } finally {
396                     SpObserver.setDBtoInstance();
397                 }
398             } else {//三表中的第三张表
399                 dto.minID = dto.formID;//为了生成页面时取第一表的功能号
400                 dto.formID = dto.formID3;
401                 try {
402                     SpObserver.setDBtoInstance("_" + dto.dbid);
403                     dto.gfields = gridService.getGfiledByFormID9(dto.formID, 0);//取得所有 字段信息
404                     dto.lastField = gridService.getSimpleJdbcTemplate().queryForObject(sql, new Object[]{dto.formID, 0}, String.class);
405                 } finally {
406                     SpObserver.setDBtoInstance();
407                 }
408             }
409         }
410         //try {
411         this.getTableName(dto.formID, dto.winType + "|" + dto.conNum, dto);// 增加类型
412         if (dto.table == null) throw new ApplicationException(dto.formID + "--未设置明细表,请在9802设置后重新生成!");
413         if (dto.isTable) {
414             this.getFirstField(dto);
415         }
416         if (dto.conNum >= 2)
417             if (dto.tempGridHeight != 0) dto.gridHeight = dto.tempGridHeight;
418
419         gridConfig(root, dto);
420         createCoumtHeader(dto);
421         //} catch (Exception e) {
422         //    e.printStackTrace();
423         //}
424     }
425
426     private synchronized void fillColumnNumTree(int num, TreeGridDTO dto) {//根据最大行值填充列
427         StringBuilder mps = new StringBuilder();
428         int j = 0;
429         //dto.gfields.first();
430         try {
431             //do{
432             for (Map<String, Object> map : dto.gfields) {
433
434                 if ("1".equalsIgnoreCase(map.get("ShowOnGrid") + "")) {
435                     String dec = map.get("gridcaption") == null ? "" : map.get("gridcaption") + "";//表格描述
436                     String fieldname = map.get("fieldname") == null ? "" : map.get("fieldname") + "";//字段描述
437                     String id = map.get("fieldid") + "";//字段名
438                     if (id.equalsIgnoreCase("id")) id = "_ycid_";//避免id与格线中的id冲突而增加,页面返回时需要转换
439                     String cap = (dec == null || "".equalsIgnoreCase(dec)) ? fieldname : dec;//如果没定义表描述就取字段名称作为表格显示字段
440                     if (cap == null || cap == "" || cap.length() == 0) cap = id;
441                     String[] temp = cap.split("\\|");//分割字符串,外表|接收数据|外表字段
442                     int tempN = this.getColumnNumOf(temp[0], dto.tempStr, 0, dto);//取得当前列最大行数是多少.
443                     int colNum = this.getColumnNum(temp[0], dto.tempStr, 0, temp[0], 0, dto);//跨列值
444                     int ts = num - temp.length;
445                     StringBuilder mp = new StringBuilder();
446                     if (j != 0) mps.append("&#039;");
447                     if (tempN == num && temp.length < num) {//全行都有但长度不够需要在后面补足
448                         for (int i = 0; i < ts; i++) {
449                             mp.append("|¥");
450                         }
451                         mps.append(cap + mp.toString());
452
453                     } else {
454                         if (colNum > 1) {
455                             for (int i = 0; i < ts; i++) {
456                                 mp.append("|¥");
457                             }
458                             mps.append(cap + mp.toString());
459                         } else {
460                             for (int i = 0; i < ts; i++) {
461                                 mp.append("¥|");
462                             }
463                             mps.append(mp.toString() + cap);
464                         }
465                     }
466                     j++;
467                     mp = null;
468                 }
469             }
470             //while(dto.gfields.next());
471         } catch (Exception e) {
472             //System.out.println(e+"错误3");
473         }
474         dto.tempStr = mps.toString();
475         mps = null;
476     }
477
478     /**
479      * 获取当前表定义的列格式最大数,作为自定义表头列分割的依据
480      * 循环gfields集合中{表格|描述}字段值,分割”|”生成数组,返回最大数组长度,及取得表所有字段描述和长度分布情况
481      *
482      * @return int 最大值
483      */
484     private synchronized int getMaxColumnNum(TreeGridDTO dto) {
485         int num = 0;
486         int j = 0;
487         //dto.gfields.first();
488         try {
489             //do{
490             for (Map<String, Object> map : dto.gfields) {
491                 if (GridUtils.prossRowSetDataType_Int(map, "ShowOnGrid") > 0) {
492                     String dec = map.get("gridcaption") == null ? "" : map.get("gridcaption") + "";//表格描述
493                     String fieldname = map.get("fieldname") == null ? "" : map.get("fieldname") + "";//字段描述
494                     String id = map.get("fieldid") + "";//字段名
495                     if (id.equalsIgnoreCase("id")) id = "_ycid_";//避免id与格线中的id冲突而增加,页面返回时需要转换
496                     String cap = (dec == null || "".equals(dec)) ? fieldname : dec;//如果没定义表描述就取字段名称作为表格显示字段
497                     if (cap == null || cap == "" || cap.length() == 0) cap = id;
498                     String[] temp = cap.split("\\|");//分割字符串,外表|接收数据|外表字段
499                     if (j != 0) dto.tempStr += "&#039;";//特殊分隔符
500                     dto.tempStr += cap;
501                     if (!dto.decMap.containsKey(temp[0])) {//不存在这个key时放到map保存
502                         dto.decMap.put(temp[0], temp.length);//保存字段分割最大长度
503                     } else if (temp.length > dto.decMap.get(temp[0])) {//当前值比map里的值大时候,换为新值
504                         dto.decMap.remove(temp[0]);
505                         dto.decMap.put(temp[0], temp.length);
506                     }
507                     if (num < temp.length) {
508                         num = temp.length;
509                     }
510                     j++;
511                 }
512             }
513             //while(dto.gfields.next());
514         } catch (Exception e) {
515             //System.out.println(e+"错误4");
516         }
517         return num;
518     }
519
520     /**
521      * 查找类似“表格|显示,表格|描述,表格|类型,表格|长度”中表格出现的次数
522      *
523      * @param String colName---列名称
524      * @param String gridcaption---列名称的组合串,在getMaxColumnNum方法生成
525      */
526     private synchronized int getColumnNum(String colName, String gridcaption, int index, String per, int m, TreeGridDTO dto) {
527         if (colName.equalsIgnoreCase("¥")) return 0;
528         int num = 0;
529         String temp1 = colName;
530         String temp2 = dto.tempStr;
531         String[] temp3 = temp2.split("&#039;");
532         String temp4 = "";//保存前一个值
533         int j = 0;
534         for (int k = 0; k < temp3.length; k++) {
535             j++;
536             String s = temp3[k];
537             String[] ts = s.split("\\|");
538             if (ts.length < index + 1) continue;
539             if (ts[index].equalsIgnoreCase(temp1.toLowerCase()) && per.equals(ts[index == 0 ? 0 : index - 1]) && j >= m) {//判断需要计算的列的前一个值与当前列的前一个列是否相同
540                 num++;
541                 temp4 = ts[index];
542             } else if (temp4 != "" && !temp4.equals(ts[index])) {//不匹配时
543                 break;
544             } else {
545                 continue;
546             }
547         }
548         temp3 = null;
549         temp1 = null;
550         temp2 = null;
551         return num;
552     }
553
554     /**
555      * 查找类似“表格|显示,表格|描述,表格|类型,表格|长度”中在表格所属的最大行数
556      *
557      * @param String colName---列名称
558      * @param String gridcaption---列名称的组合串,在getMaxColumnNum方法生成
559      */
560     private synchronized int getColumnNumOf(String colName, String gridcaption, int index, TreeGridDTO dto) {
561         int num = 0;
562         int temp = 0;//临时值
563         String temp1 = colName;//列名
564         String temp2 = dto.tempStr;//列串
565         String[] temp3 = temp2.split("&#039;");//分割为数组
566         String temp4 = "";//保存前一个值
567         int j = 0;
568         for (int k = 0; k < temp3.length; k++) {
569             String s = temp3[k];
570             String[] ts = s.split("\\|");
571             if (ts.length < index + 1) continue;
572             if (ts[index].equalsIgnoreCase(temp1) && (temp4 == "" || temp4.equalsIgnoreCase(ts[index]))) {
573                 temp = ts.length;
574                 temp4 = ts[index];
575                 if (temp > num) num = temp;
576             } else if (temp4 != "" && !temp4.equalsIgnoreCase(ts[index])) {//不匹配时
577                 break;
578             } else {
579                 continue;
580             }
581         }
582         temp3 = null;
583         temp1 = null;
584         temp2 = null;
585         return num;
586     }
587
588     /**
589      * 动态根据表描述字段的如下规律
590      * 表格|显示|表格|描述|表格|类型|表格|长度
591      * 外表|表号|外表|类型|外表|清空关联
592      * 生成跨行跨列的表头格式生成
593      * 首先是查找最大跨行数,由最大跨行数得到需要输出多少行
594      * 再一行行的输出每列信息,在每列输出时需要根据表描述字段决定跨行跨列设置
595      * 全局控制都是根据分割表描述字段所得的数组来处理
596      *
597      * @return String 表头html代码
598      **/
599     private void createCoumtHeader(TreeGridDTO dto) throws DataAccessException { //生成自定义表头
600         StringBuilder gridHeader = new StringBuilder();//表头html
601         int num = getMaxColumnNum(dto);//返回需要分行,分列的值
602         this.fillColumnNumTree(num, dto);
603         String temID = "";//保存之前字段描述值,以便当下一次与这个值相等时可以跳过不输出
604         String temPa = "";//temID的上级值,区分{外表|接收数据|自身字段,外表|条件|自身字段 }情况
605         String top = "";
606         String[] str = dto.tempStr.split("&#039;");//填充后的列格式
607         for (int i = 0; i < num; i++) {//循环分行取值
608             int k = 0;
609             //dto.gfields.first();
610             if (dto.gantt && !dto.isList && i == 0)
611                 gridHeader.append("<Header id='id' ");
612             else
613                 gridHeader.append("<Header " + ((i == num - 1) ? "id='Header' " : " Spanned='1' "));
614             //do{
615             for (int y = 0; y < dto.gfields.size(); y++) {
616                 Map<String, Object> map = dto.gfields.get(y);
617                 if (GridUtils.prossRowSetDataType_Boolean(map, "ShowOnGrid")) {//设置为隐藏
618                     String dec = GridUtils.prossRowSetDataType_String(map, "gridcaption");//表格描述
619                     String fieldname = GridUtils.prossRowSetDataType_String(map, "fieldname");//字段描述
620                     String id = map.get("fieldid") + "".trim();//字段名,去掉空格
621                     if (id.equalsIgnoreCase("id") && (!dto.gantt)) id = "_ycid_";//避免id与格线中的id冲突而增加,页面返回时需要转换
622                     String temp = (dec == null || "".equalsIgnoreCase(dec)) ? fieldname : dec;//如果没定义表描述就取字段名称作为表格显示字段
623                     if (temp == null || temp == "" || temp.length() == 0) temp = id;
624                     String[] capf = temp.split("\\|");//分割字符串,外表|接收数据|外表字段    去掉 .replaceAll("'", "\\\\'"),因为用""括进来了,为的就是动态标题传参数有单引号的情况
625                     String[] cap = str[k].split("\\|");
626                     if (cap[i].trim().indexOf("!") == 0) {//动态标题,替换参数
627                         if (k > 0 && dto.setInfo_dy.length() > 1 && cap[i].indexOf("@") > -1) dto.setInfo_dy += ",";
628                         this.prossIntoSessionForFilter_dy(cap[i], dto);
629
630                     }
631                     k++;
632                     boolean flag = false;//标记是否需要隐藏
633                     String show = "";
634                     String hidden = "";
635                     int colNum = 0;
636                     if (i > 0 && cap.length > 1 && i < cap.length) {
637                         if (!cap[i].equalsIgnoreCase("¥") && temID.equalsIgnoreCase(cap[i]) && temPa.equalsIgnoreCase(cap[i - 1]) && top.equalsIgnoreCase(cap[0])) {
638                             continue;//只输出一个,表格|显示,表格|描述,表格|类型,表格|长度
639                         }
640                     }
641                     try {
642                         colNum = this.getColumnNum(cap[i], dto.tempStr, i, i == 0 ? cap[0] : cap[i - 1], k, dto);//取得跨列值
643                         if (colNum == 0) flag = true;//表示存在¥,则不需要显示
644
645                         show = id.toLowerCase() + "=\"" + this.getFormCap(cap[i]) + "\" " + id.toLowerCase() + "Align='Center' " + (colNum > 1 ? (" " + id.toLowerCase() + "Span='" + colNum + "' ") : "");
646                         hidden = id.toLowerCase() + "Visible='-1' ";
647                         if (flag)
648                             gridHeader.append(hidden);
649                         else
650                             gridHeader.append(show);
651                     } catch (Exception e) {
652                         throw new ApplicationException(dto.formID + "-字段设置有问题-" + id);
653                     }
654                     flag = false;
655                     top = capf[0];//取得第一个字段值
656                     if (i < capf.length) temID = capf[i];
657                     if (i > 0 && i < capf.length) temPa = capf[i - 1];//得到上级值
658                 }
659             }
660             //while(dto.gfields.next());
661             if (!dto.isList && dto.gantt) gridHeader.append("  G='Gantt'");
662             gridHeader.append(" />\n");
663         }
664         try {
665             if (gridHeader.length() > 0) dto.header = gridHeader.substring(0, gridHeader.length() - 1);
666
667         } catch (Exception e) {
668             throw new ApplicationException("生成格线表头出错,因为格线所有栏位都设为不显示");
669         } finally {
670             gridHeader = null;
671             dto.gfields = null;
672         }
673     }
674
675     ;
676
677     /**
678      * 根据当前值是否有特定标记@day,@moth,@year,等。以替换成真实值
679      */
680     private synchronized String getFormCap(String id) {
681         String s = id.toLowerCase().trim();
682         String[] day = null;
683         if (s.indexOf("@day") > -1) {//日
684
685             if (s.indexOf("+") > -1) {
686                 day = s.split("\\+");
687             } else if (s.indexOf("-") > -1) {//-号
688                 day = s.split("\\-");
689                 day[1] = "-" + day[1];
690             } else {
691                 day = s.split("\\+");
692             }
693             if (day.length > 1) {
694                 return "#GT.getDay(" + Integer.parseInt(day[1]) + ")";
695             } else {
696                 return "#GT.getDay(0)";
697             }
698
699         } else if (id.toLowerCase().indexOf("@month") > -1) {//月
700             if (s.indexOf("+") > -1) {
701                 day = s.split("\\+");
702             } else if (s.indexOf("-") > -1) {//-号
703                 day = s.split("\\-");
704                 day[1] = "-" + day[1];
705             } else {
706                 day = s.split("\\+");
707             }
708             if (day.length > 1) {
709                 return "#GT.getMonth(" + Integer.parseInt(day[1]) + ")";
710             } else {
711                 return "#GT.getMonth(0)";
712             }
713         } else if (id.toLowerCase().indexOf("@quarter") > -1) {//季
714             return id;
715         } else if (id.toLowerCase().indexOf("@year") > -1) {//年
716
717             if (s.indexOf("+") > -1) {
718                 day = s.split("\\+");
719             } else if (s.indexOf("-") > -1) {//-号
720                 day = s.split("\\-");
721                 day[1] = "-" + day[1];
722             } else {
723                 day = s.split("\\+");
724             }
725             if (day.length > 1) {
726                 return "#GT.getYear(" + Integer.parseInt(day[1]) + ")";
727             } else {
728                 return "#GT.getYear(0)";
729             }
730         } else {
731             return id.replaceAll("<", "&lt;").replaceAll(">", "&gt;");
732         }
733
734     }
735
736     /**
737      * 取得自动编号的类型
738      */
739     private synchronized List getAutoCodeType(int formid, String dbid) {
740         try {
741             SpObserver.setDBtoInstance("_" + dbid);
742             String sql = "select precodetype,codelength,preFixcode from gform where formid=?";
743             return gridService.getJdbcTemplate().queryForList(sql, new Object[]{formid});
744         } finally {
745             SpObserver.setDBtoInstance();
746         }
747     }
748
749     private List getCodeInfo(int formid, String dbid) {
750         try {
751             SpObserver.setDBtoInstance("_" + dbid);
752             String sql = "select g.formid,g.codelength,g.preFixcode,g.precodetype,c.Formtype,c.Curcode,c.Fieldid from gform g,_sysautocode c where g.formid=c.formid and g.formid=?";
753             return gridService.getJdbcTemplate().queryForList(sql, new Object[]{formid});
754         } finally {
755             SpObserver.setDBtoInstance();
756         }
757     }
758
759     /**
760      * 查找字符串中是否存在指定的内容
761      * 返回需要替换的字段名
762      */
763     private synchronized String getString(String str) {
764         Pattern p = Pattern.compile("@\\w+");
765         String s = "";
766         java.util.regex.Matcher propsMatcher = p.matcher(str != null ? str.toLowerCase() : "");
767         while (propsMatcher.find()) {
768             s += propsMatcher.group() + ";";
769         }
770         return s;
771     }
772
773     /**
774      * 填充参数值列表,下拉列表控件时,需要填充数据,用作2类型控件
775      *
776      * @param type 控件类型
777      * @param ft   --参数号
778      * @return
779      */
780     private StringBuilder fillFT(int type, int ft, String sql, TreeGridDTO dto) {
781         StringBuilder sb = new StringBuilder();
782         SqlRowSet rst = null;
783         try {
784             SpObserver.setDBtoInstance("_" + dto.dbid);
785             rst = gridService.getFTData(ft);
786         } finally {
787             SpObserver.setDBtoInstance();
788         }
789         sb.append("");
790         boolean flag = false;
791         if (type == 31 || type == 2 || type == 35 || type == 43 || type == 30 || type == 32) {//2,类型,31类型下拉列表控件时,为三种情况,一个是静态sql,一个是动态sql,需要用页面的值替换再用ajax提交返回,另一个就是表号生成
792             StringBuilder id = new StringBuilder();
793             StringBuilder value = new StringBuilder();
794             if (type != 30 && type != 32) {
795                 id.append("| ");
796                 value.append("| ");
797             }
798             try {
799                 if (sql != null && sql != "" && sql.length() > 0) {//有sql参数
800                     if (sql.indexOf("&") > -1 || sql.indexOf("@") > -1) {//表示需要在页面替换参数,取页面值,ajax提交填充
801                         this.prossIntoSession(getString(sql), dto);
802                         sb.append("dySql=\"" + sql + "\"");
803                     } else {
804                         if (type == 2) {
805                             SqlRowSet set = null;
806                             try {
807                                 SpObserver.setDBtoInstance("_" + dto.dbid);
808                                 set = gridService.getJdbcTemplate().queryForRowSet(sql);
809                             } finally {
810                                 SpObserver.setDBtoInstance();
811                             }
812                             if (!set.wasNull()) {
813                                 while (set.next()) {
814                                     id.append("|").append(this.replaceBlank(set.getString(1)));
815                                     value.append("|").append(this.replaceBlank(set.getString(2)));
816                                 }
817                                 set = null;
818                             }
819                         } else {//31,35
820                             sb.append("dySql=\"" + sql + "\"");
821                         }
822                     }
823
824
825                     flag = true;
826                 }
827                 if (!flag) {
828                     if (!rst.wasNull()) {
829                         while (rst.next()) {
830                             id.append("|").append(this.replaceBlank(rst.getString("interValue")));
831                             value.append("|").append(this.replaceBlank(rst.getString("dictvalue")));
832                         }
833                     }
834                 }
835
836             } catch (Exception e) {
837                 sb.append("");
838             } finally {
839                 rst = null;
840             }
841             if (type == 31)
842                 if (ft != 0)//有表号才会有新增选项
843                     sb.append("  EnumKeys='").append(id.toString() + "|-add-").append("' Enum='").append(value.toString() + "|&lt;&lt;新增&gt;&gt;").append("' ");
844                 else//当没表号表示不需要新增选项
845                     sb.append("  EnumKeys='").append(id.toString()).append("' Enum='").append(value.toString()).append("' ");
846             else {
847                 if (type != 35) {
848                     sb.append("  EnumKeys='").append(id.toString()).append("' Enum='").append(value.toString()).append("' ");
849                 }
850             }
851             if (type == 35) {//可编辑列表,值与键需要一样
852                 sb.append("  Button='Defaults' Defaults='").append(("|".equals(value.toString().trim())?"":value.toString())).append("' ");
853             }
854             if (type == 43 || type == 30) {
855                 sb.append("  Range='1' ");
856             }
857
858             id = null;
859             value = null;
860         }
861 //        else if(type==35){//可编辑列表,值与键相同
862 //            StringBuilder value=new StringBuilder();
863 //            try{
864 //            if(!rst.wasNull()){
865 //            while(rst.next()){
866 //                value.append("|").append(this.replaceBlank(rst.getString("dictvalue")));
867 //                }
868 //            }
869 //            }catch(Exception e){
870 //                sb.append("");
871 //            }finally{
872 //                rst=null;
873 //            }
874 //             sb.append("  Button='Defaults' Defaults='").append(value.toString()).append("' ");
875 //             value=null;
876 //        }
877         return sb;
878     }
879
880     private synchronized String setJsName(TreeGridDTO dto) {
881         return "grid_" + dto.formID + "_" + dto.winType + ".xml";
882     }
883
884     /**
885      * 生成页面时需要检查的关键字段名,避免生成格线有问题
886      */
887     private synchronized boolean checkKey(String id) {
888         String[] keys = {"_ycid_", "added", "Deleted", "Changed", "Moved", "Panel", "Prev", "Next", "id"};
889         for (String k : keys) {
890             if (k.equalsIgnoreCase(id)) {
891                 return true;
892             }
893         }
894         return false;
895     }
896
897     private String getFileter(TreeGridDTO dto) {
898         StringBuffer temp = new StringBuffer();
899         temp.append("");
900         try {
901             // dto.gfields.first();
902             // do{
903             for (int y = 0; y < dto.gfields.size(); y++) {
904                 Map<String, Object> map = dto.gfields.get(y);
905                 String top = this.replaceBlank(GridUtils.prossRowSetDataType_String(map, "SeekGroupID") + "".toLowerCase());
906                 String sf = this.replaceBlank(GridUtils.prossRowSetDataType_String(map, "HyperlinkSPremissField") + "".toLowerCase());
907                 String ft = this.replaceBlank(GridUtils.prossRowSetDataType_String(map, "HyperlinkFT") + "".toLowerCase());
908                 String initValue = this.replaceBlank(GridUtils.prossRowSetDataType_String(map, "initValue") + "");
909
910                 if (top.length() > 0)
911                     temp.append(top).append(";");
912                 if (sf.length() > 0)
913                     temp.append(sf).append(";");
914                 if (ft.length() > 0)
915                     temp.append(ft).append(";");
916                 if (initValue.length() > 0)
917                     temp.append(initValue).append(";");
918             }
919             //while(dto.gfields.next());
920         } catch (ArrayIndexOutOfBoundsException e) {
921             throw new ApplicationException("读取不到" + dto.formID + "在9802里面的字段信息,请检查9802是否已做了相关设置");
922         }
923         return temp.toString();
924     }
925
926     /**
927      * sugg--列表显示的字段
928      * backFilds-取外表字段,以便选择后返回哪些值。
929      * tp ---自表字段,返回给哪些字段
930      */
931     public String getSuggestFilds(String fromid, int type, String sugg, String backFilds, String to, String form, boolean one, int rod, String dbid, String sf, String df) {//取得需要的字段名称
932         int flg = this.setGetPrivaryTable(type);
933         StringBuffer sb = new StringBuffer();
934         StringBuffer exps = new StringBuffer();
935         String sql = " select FieldID,fieldname,GridCaption,ShowOnGrid,showFieldValueExpression from gfield where formid=? and HeadFlag=?  order by statisid asc";
936         List<Map<String, Object>> list = null;
937         try {
938             SpObserver.setDBtoInstance("_" + dbid);
939             list = gridService.getSimpleJdbcTemplate().queryForList(sql, new Object[]{fromid, flg});
940         } finally {
941             SpObserver.setDBtoInstance();
942         }
943         String[] tem = sugg.replaceAll(",", ";").split(";");
944         int i = 0;
945         String str = "";//保存哪些字段是隐藏的
946
947         for (String s : tem) {
948             for (Map<String, Object> map : list) {
b9e8fc 949                 if (s.trim().equalsIgnoreCase((String) map.get("FieldID"))) {
a6a76f 950                     if ((Integer) (map.get("ShowOnGrid") == null ? 0 : map.get("ShowOnGrid")) == 1)
F 951                         sb.append("<th width=\"\">").append(map.get("fieldname") == null ? (String) map.get("GridCaption") : (String) map.get("fieldname")).append("</th>");
952                     else {
953                         if (str == "")
954                             str += map.get("FieldID");
955                         else
956                             str += ";" + map.get("FieldID");
957                         sb.append("<th width=\"\" style=\"display:none;\">").append(map.get("fieldname") == null ? (String) map.get("GridCaption") : (String) map.get("fieldname")).append("</th>");
958                     }
959                     //取权限表达式输出到页面
960                     String strexp = GridUtils.prossRowSetDataType_String(map, "showFieldValueExpression");
961                     if (!"".equalsIgnoreCase(strexp)) {
962
963                         if (exps.length() == 0)
964                             exps.append(s + "|").append(strexp).append(";");
965                         else
966                             exps.append(";").append(s + "|").append(strexp);
967                     }
968
969                     break;
970                 }
971             }
972
973             i++;
974         }
975         String strexps = "";
976         try {
977             strexps = new String(YCBase64.encode(exps.toString().getBytes()));
978         } catch (Exception e) {
979             // TODO Auto-generated catch block
980             e.printStackTrace();
981         }
982         String json = "{\"data\":\";" + str + ";\",\"backfilds\":\"" + backFilds + "\",\"sf\":\"" + sf + "\",\"df\":\"" + df + "\",\"to\":\"" + to + "\",\"form\":\"" + form + "\",\"exp\":\"" + strexps + "\",\"one\":\"" + (one ? 1 : 0) + "\"}";
983         return "<div id=\"T_" + fromid + "_10" + rod + "div\" style=\"z-index:9999;display:none;position:absolute;height:300px;overflow:auto;\"><table  data='" + json + "' id=\"T_" + fromid + "_10" + rod + "CDiv\" class=\"hovertable\"><tr>" +
984                 sb.toString() + "</tr></table></div>\t\n";
985     }
986
987     /**
988      * 处理9802里面设置了取值的字段但又不需要显示的所有字段
989      * 针对超链接的参数进行处理
990      */
991     private Map<String, String> prossDisable(TreeGridDTO dto) {
992         Map<String, String> map = new HashMap<String, String>();
993         //dto.gfields.first();
994         //do{
995         for (int y = 0; y < dto.gfields.size(); y++) {
996             Map<String, Object> map1 = dto.gfields.get(y);
997             String ft = GridUtils.prossRowSetDataType_String(map1, "HyperlinkFT");
998             String type = GridUtils.prossRowSetDataType_String(map1, "HyperlinkFTFormType");
999             String field = GridUtils.prossRowSetDataType_String(map1, "HyperlinkSPremissField");
1000             String filter = GridUtils.prossRowSetDataType_String(map1, "HyperlinkEFilter");
1001             pullValue(map, ft);
1002             pullValue(map, type);
1003             pullValue(map, field);
1004             pullValue(map, filter);
1005
1006         }
1007         //while(dto.gfields.next());
1008         return map;
1009
1010     }
1011
1012     private void pullValue(Map<String, String> m, String ft) {
1013         if (ft != null && !"".equalsIgnoreCase(ft)) {
1014             ft = ft.replaceAll(",", ";");
1015             String[] str = ft.split(";");
1016             for (String s : str) {
1017                 m.put(s, "1");
1018             }
1019         }
1020     }
1021
1022     /**
1023      * grid定义数据集及列定义
1024      */
1025     private void gridConfig(String root, TreeGridDTO dto) throws DataAccessException {
1026
1027         StringBuilder left = new StringBuilder();//leftcols定义
1028         StringBuilder cols = new StringBuilder();//列定义json
1029         StringBuilder formn = new StringBuilder();//自定义公式
1030         StringBuilder values = new StringBuilder();//初始值
1031         StringBuilder sumfu = new StringBuilder();//统计公式
1032         StringBuilder valExp = new StringBuilder();//权限控制值
1033         StringBuilder cssExp = new StringBuilder();//css控制值
1034         StringBuilder tipsExp = new StringBuilder();//提示信息
1035         StringBuilder msgInfo = new StringBuilder();//错误提示信息
1036         StringBuilder exportInfo = new StringBuilder();//保存导出字段
1037         StringBuilder rowCopys = new StringBuilder();//保存复单时排除字段,读9802
1038         //StringBuilder exportTitle=new StringBuilder();//保存导出文件名称,在生成下载的excel文件时候用到
1039
1040         //List<Integer>  sugId=new ArrayList<Integer>();//保存生成div的功能号,以便排队生成相同的div
1041         dto.filter = new StringBuilder();//过滤设置,读9802
1042         dto.filter.append("<Filter  id=\"Filter1\" Height=\"22\" ");
1043         //
1044         exportInfo.append(dto.formname.replaceAll("-", "_")).append("-");//取得功能号名称
1045         StringBuilder SumFieldInfo = new StringBuilder();
1046         int rod = 0;//42类型生成的索引值,由于分布式部署的原因,需要确保生成的索引值都是一样才能在页面加载时,不管加载到那一个节点也是正确的
1047         try {
1048             int index = 0;//标记当前位置
1049             String firstID = "";//第一个字段名称
1050             SqlRowSetMetaData metaData = null;
1051             if (dto.winType != 18 && dto.winType != 38 && dto.winType != 19) {
1052                 try {
1053                     SpObserver.setDBtoInstance("_" + dto.dbid);
1054                     metaData = gridService.getMetaData(dto.table.split("\\|")[0]);//元数据
1055                 } finally {
1056                     SpObserver.setDBtoInstance();
1057                 }
1058             }
1059             List typeInfo = null;
1060             try {
1061                 SpObserver.setDBtoInstance("_" + dto.dbid);
1062                 typeInfo = gridService.getColumnsTypeInfo(dto.table.split("\\|")[0]);
1063             } finally {
1064                 SpObserver.setDBtoInstance();
1065             }
1066             Map<String, String> len = new HashMap<String, String>();
1067             if (!dto.isList) {//只有是有明细表才需要有长度限制
1068                 String lengthInfo = null;
1069                 try {
1070                     SpObserver.setDBtoInstance("_" + dto.dbid);
1071                     lengthInfo = gridService.getTypeLengthInfo(dto.table.split("\\|")[0]);
1072                 } finally {
1073                     SpObserver.setDBtoInstance();
1074                 }
1075                 if (lengthInfo != null) {
1076                     String[] tem = lengthInfo.split(",");
1077                     for (String s : tem) {
1078                         String[] ss = s.split("-");
1079                         if (ss.length < 3)
1080                             len.put(ss[0].toLowerCase(), ss[1]);
1081                         else
1082                             len.put(ss[0].toLowerCase(), ss[2]);
1083                     }
1084                 }
1085             }
1086             //String fileter=this.getFileter();//保存需要隐藏输出的字段,只取自身字段
1087             boolean iscopy = false;//标记当前9802是否有复制时排除字段,为了兼用不存在出错的情况
1088             boolean isref = false;//标记当前9802是否有自动刷新和加载到页面的字段,为了兼用不存在出错的情况
1089             int fumIndex = 0;//标记导出时候字段位置
1090             Map<String, String> vMap = this.prossDisable(dto);
1091             //dto.gfields.first();
1092             //    do{
1093             for (int i = 0; i < dto.gfields.size(); i++) {
1094                 boolean fileterID = false;//标记为需要隐藏输出
1095                 Map<String, Object> map = dto.gfields.get(i);
1096 //                  //----处理动态sql
1097 //            Map<String,String> map9801= SqlFormatUtils.createSQLFormat(map,9801);
1098 //            Map<String,String> map9802= SqlFormatUtils.createSQLFormat(map,9802);
1099 //                //-----
1100                 String id = GridUtils.prossRowSetDataType_String(map, "fieldid");//字段名
1101                 String dec = GridUtils.prossRowSetDataType_String(map, "gridcaption");//表格描述
1102                 String fieldname = GridUtils.prossRowSetDataType_String(map, "fieldname");//字段描述
1103                 String temp = (dec == null || "".equalsIgnoreCase(dec)) ? fieldname : dec;//如果没定义表描述就取字段名称作为表格显示字段
1104                 if (this.checkKey(id.toLowerCase())) {
1105                     msgInfo.append("警告:格线所用字段不能使用[" + id + "]关键字!");
1106                 }
1107                 if (id.equalsIgnoreCase("id") && (!dto.gantt)) id = "_ycid_";//避免id与格线中的id冲突而增加,页面返回时需要转换
1108                 if (temp == null || "".equalsIgnoreCase(temp) || temp.length() == 0) temp = id;
1109                 if (firstID == "") firstID = id;
1110                 int type = GridUtils.prossRowSetDataType_Int(map, "gridcontroltype");//表格单元格控件类型
1111                 int ft = GridUtils.prossRowSetDataType_Int(map, "ft");//外表|表号
1112                 int wiType = GridUtils.prossRowSetDataType_Int(map, "FTFormType");//外表|窗体类型
1113                 int width = GridUtils.prossRowSetDataType_Int(map, "GridLength");//单元格宽度
1114                 if (width == 0) {
1115                     width = 100;
1116                 } else {
1117                     width *= 10;
1118                 }
1119                 if (width < 100 && width > 50) width = 100;
1120                 if (width < 50) width = 50;
1121                 int calcuField = GridUtils.prossRowSetDataType_Int(map, "calcuField");//自定义公式|1,表示是否当前字段变化后需要重新计算包括有这个字段的所有公式内容
1122                 String fua = GridUtils.prossRowSetDataType_String(map, "formula");//自定义公式
1123                 if (fua != null && !"".equalsIgnoreCase(fua)) {
1124                     this.prossIntoSessionForFilter(fua, dto);
1125                 }
1126                 String value = GridUtils.prossRowSetDataType_String(map, "initValue");//初始值
1127                 String emptyrefdata = GridUtils.prossRowSetDataType_String(map, "emptyrefdata");//清空关联
1128                 int SumField = GridUtils.prossRowSetDataType_Int(map, "SumField");//统计方式
1129                 String funclinkname = GridUtils.prossRowSetDataType_String(map, "funclinkname");//自定义统计公式
1130                 boolean activefuns = GridUtils.prossRowSetDataType_Boolean(map, "activefuns");//公式是否生效
1131                 boolean ShowOnGrid = GridUtils.prossRowSetDataType_Boolean(map, "ShowOnGrid");//是否显示
1132                 boolean KeyInput = GridUtils.prossRowSetDataType_Boolean(map, "KeyInput");//是否必录
1133                 String passwordchar = GridUtils.prossRowSetDataType_String(map, "passwordchar");//是否为密码字符
1134                 String displayformat = GridUtils.prossRowSetDataType_String(map, "displayformat");//数字格式
1135                 String ef = GridUtils.prossRowSetDataType_String(map, "eFilter");
1136                 boolean readOnly = GridUtils.prossRowSetDataType_Boolean(map, "ReadOnly");//只读
1137                 boolean dataLink = GridUtils.prossRowSetDataType_Boolean(map, "DataLink");//感应字段
1138                 boolean uppercase = GridUtils.prossRowSetDataType_Boolean(map, "uppercase");//大写
1139                 String ValueExp = GridUtils.prossRowSetDataType_String(map, "showFieldValueExpression");//权限控制是否显示该值
1140                 String editStatus = GridUtils.prossRowSetDataType_String(map, "editStatus");//权限控制是否显示该值
1141                 boolean oneRec = GridUtils.prossRowSetDataType_Boolean(map, "return_one_record");//是否返回到单记录
1142                 boolean onlyOne = GridUtils.prossRowSetDataType_Boolean(map, "onlyOne");//只返回单条记录
1143                 String sqlScript = this.replaceBlank(GridUtils.prossRowSetDataType_String(map, "SqlScript"));// 控件sql
1144                 String sqlWhere = this.replaceBlank(GridUtils.prossRowSetDataType_String(map, "sqlWhere"));// 下拉控件(31),编辑状态时需要附加这个条件
1145                 this.prossIntoSessionForFilter_dy(sqlWhere, dto);
1146                 boolean rowspan = GridUtils.prossRowSetDataType_Boolean(map, "rowSpan");//是否合并行
1147                 boolean isExport = GridUtils.prossRowSetDataType_Boolean(map, "isExport");//是否导出
1148                 boolean statisFlag = GridUtils.prossRowSetDataType_Boolean(map, "StatisFlag");//是否可查询
1149                 boolean cpltrow = GridUtils.prossRowSetDataType_Boolean(map, "copyfromlastrow");//插入时从上行复制
1150                 String cs = GridUtils.prossRowSetDataType_String(map, "stylecss");//css样式
1151                 String tips = GridUtils.prossRowSetDataType_String(map, "TipsExpression");
1152                 valExp.append((ValueExp != null && !"".equalsIgnoreCase(ValueExp)) ? id + "|" + this.replaceBlank(ValueExp) + ";" : "");
1153                 cssExp.append((cs != null && !"".equalsIgnoreCase(cs)) ? id + "|" + this.replaceBlank(cs.replaceAll(";", "~")) + ";" : "");
1154                 tipsExp.append((tips != null && !"".equalsIgnoreCase(tips)) ? id + "|" + this.replaceBlank(tips.replaceAll(";", "~")) + ";" : "");
1155                 String cellAlign = GridUtils.prossRowSetDataType_String(map, "cellAlign");//单元格对齐属性
1156                 //int expTitle=GridUtils.prossRowSetDataType_Int(map,"exportTitle");//下载文件名称
1157                 String dataType = "";
1158                 int dIndex = 1;
1159                 if (metaData != null) {
1160                     dIndex = this.getType(metaData, id);//取得每个字段的数据类型,1数字 ,3字符,4日期
1161                     switch (dIndex) {
1162                         case 1:
1163                             dataType = "n";//数值
1164                             break;
1165                         case 3:
1166                             dataType = "s";//字符串
1167                             break;
1168                         case 4:
1169                             dataType = "d";//时间
1170                             break;
1171                     }
1172                 }
1173
1174                 int isAudit = 0;
1175                 //if(ShowOnGrid&&statisFlag)//可显示且可查询
1176                 setFilter(id.toLowerCase(), type, dto.filter, dIndex);
1177                 try {
1178                     if (!iscopy) {
1179                         boolean isCopyExclude = GridUtils.prossRowSetDataType_Boolean(map, "isCopyExclude");//复单时是否排除
1180                         if (isCopyExclude)
1181                             rowCopys.append(id.toLowerCase()).append(";");
1182                     }
1183                     //是否审计,1:
1184                     //表示当前字段分二种情况来处理,
1185                     //第一个情况是值没变化的 情况 下只作为后期审计查询的唯一条件,附加进有变化的审计字段的行,插入数据表
1186                     //第二个情况是值有变化的情况下,除了作为后期审计查询的唯一条件,附加进有变化的审计字段的行,也需要记录本身的新旧值变化的情况
1187                     //第三种情况是删行的情况下,也需要记录本身的新旧值变化的情况
1188                     //2:
1189                     //只作为有变化的情况的审计字段,记录新旧值插入数据表
1190                     isAudit = GridUtils.prossRowSetDataType_Int(map, "audit");
1191                 } catch (Exception e) {
1192                     iscopy = true;
1193                     isAudit = 0;
1194                 }
1195                 boolean isLoad = false;
1196                 try {
1197                     if (!isref) {
1198                         if (dto.order == 1//表示是列表的情况(很少存在需要取隐藏字段值的情况) by 2015-4-7 去掉这个限制
1199                                 && (type == 33 || type == 34 || type == 36 || type == 38 || type == 41))
1200                             isLoad = false;
1201                         else
1202                             isLoad = GridUtils.prossRowSetDataType_Boolean(map, "isLoad");//是否加载到页面
1203                     }
1204                     //在超接连中有参数,需要再判断是否需要加载到页面
1205                     if (vMap.containsKey(id.toLowerCase())) {
1206                         isLoad = true;
1207
1208                     }
1209                 } catch (Exception e) {
1210                     isref = true;
1211                 }
1212
1213                 if (cellAlign == null || cellAlign.length() == 0) cellAlign = "Center";
1214
1215                 if (!this.checkFormat(displayformat))
1216                     msgInfo.append(id + "-的格式设置不正确,存在连续二个分隔符,[" + displayformat + "]");
1217
1218                 if (displayformat != null && displayformat.contains("#"))
1219                     msgInfo.append(id + "-的格式设置不正确,不能以#号分隔,[" + displayformat + "]");
1220
1221                 //上面的都是读取9802的设置信息,接下来的才是逻辑处理
1222                 if (isExport) {
1223                     //if(expTitle==1)   exportTitle.append(id.toLowerCase()).append(";");//拼接所有需要组成的id
1224                     if (displayformat != null && !displayformat.isEmpty())
1225                         exportInfo.append(id.toLowerCase()).append("#").append(temp.replaceAll("-", "_")).append("#").append(displayformat.replaceAll("-", "~")).append(";");//-转成~是为了兼容之前的代码
1226                     else
1227                         exportInfo.append(id.toLowerCase()).append("#").append(temp.replaceAll("-", "_")).append(";");
1228                     if (SumField > 0)
1229                         SumFieldInfo.append(id.toLowerCase()).append("#").append(SumField).append("|").append(funclinkname).append("|").append(fumIndex).append("|").append((displayformat != null && !displayformat.isEmpty()) ? displayformat.replaceAll("-", "~") : "0").append(";");
1230                     fumIndex++;
1231                 }
1232
1233                 boolean listShow = ((dto.order == 1//表示是列表的情况(很少存在需要取隐藏字段值的情况) by 2015-4-7 去掉这个限制
1234                         // &&(type==33||type==34||type==36||type==38||type==41)
1235                         && (dto.winType == 9 || dto.winType == 15 || dto.winType == 17 ||
1236                         dto.winType == 499 || dto.winType == 497)
1237                 )) ? true : false;
1238                 //增加作为主键时,但没勾选上加载到页面时,也需要生成出来。
1239                 boolean isprimeKey = false;
1240                 if ((";" + dto.primeKey.toLowerCase()).contains(";" + id.toLowerCase() + ";"))
1241                     isprimeKey = true;//判断是主键,不管有没选上加载到页面都需要生成到页面
1242
1243                 if (!isprimeKey && (!isLoad || listShow)) {//不加载到页面或是列表的情况
1244                     if ((!isref && !isLoad
1245                             && !id.equalsIgnoreCase("doccode")//这二个字段特殊,需要区别对待,需要取出来
1246                             && !id.equalsIgnoreCase("docdate"))
1247                             //||
1248                             //(!ShowOnGrid&&listShow)//表示不选显示,但又是列情的情况则不需要理会是否加载到页面的选项,也就是在列表的情况下,不选显示的优先级高
1249                             ||
1250                             (dto.winType != 18 && !dataLink && !ShowOnGrid)
1251                     ) continue;//条件为在9802中设置不显示且是在明细表的情况下才输出显示
1252
1253
1254                 }
1255                 //检查当前是否有会计科目设置
1256                 if (!this.isNullOrEmptry(dto.glcodefield)) {
1257                     if (id.toLowerCase().matches("cv\\d{1}") || id.toLowerCase().matches("cv\\d{1}name")) {
1258                         type = -3;//会计核算之用
1259                     }
1260                 }
1261
1262                 if (dto.order == 1 && "".equalsIgnoreCase(dto.orderFiled)) {//排序字段
1263                     if (id.equalsIgnoreCase("doccode")) {
1264                         dto.orderFiled = id + " desc";
1265                     }
1266                     if (id.equalsIgnoreCase("docdate")) {
1267                         dto.orderFiled = dto.orderFiled.length() == 0 ? id + " desc" : "," + id + " desc";
1268                     }
1269                 } else if (dto.order == 2 && "".equalsIgnoreCase(dto.orderFiled)) {
1270                     if (id.equalsIgnoreCase("docitem"))
1271                         dto.orderFiled = id + " asc";
1272                 }
1273                 if (!dataLink) {//不感应但可能数据库存在有字段
1274                     if (gridService.getColumnInfo(dto.table, id.toLowerCase()) == 1) {//存在,表示要在页面显示出来,但在新增,修改时需要过滤
1275                         dataLink = true;
1276                         dto.columns = id.toLowerCase() + ",";
1277                     }
1278                 }
1279
1280                 if (fua != null && !fua.equalsIgnoreCase("") && activefuns&&calcuField!=0) {
1281                     formn.append(id.toLowerCase()).append("@p@").append(fua).append(":");
1282                 }
1283                 if (value != null && !value.equalsIgnoreCase("")) {//自动编号功能
1284                     if (value.equalsIgnoreCase("autocode")) {
1285                         List<Map> ct = this.getAutoCodeType(dto.formID, dto.dbid);
1286                         if (ct.size() == 0) msgInfo.append(id + "字段设置autocode,但没在9801进行相关设置!");
1287                         Map ma = ct.get(0);
1288                         if (ma.get("precodetype") == null || ma.get("codelength") == null || ma.get("preFixcode") == null)
1289                             msgInfo.append(id + "-字段设置autocode,但没在9801对【precodetype,preFixcode,codelength】进行相关设置!");
1290                         if ((Integer) ma.get("precodetype") == 1) {
1291                             List<Map<String, Object>> li = this.getCodeInfo(dto.formID, dto.dbid);
1292                             if (li.size() == 0) msgInfo.append(id + "字段设置autocode,但没在[_sysautocode]表进行相关设置!");
1293                             Map map1 = li.get(0);
1294                             value = "autocode|1|" + (Integer) map1.get("formid") + "," + (Integer) map1.get("Formtype") + "," + (String) map1.get("Fieldid") + "," + (Integer) map1.get("codelength") + "," + (String) map1.get("preFixcode");
1295                             map1 = null;
1296                         } else if ((Integer) ma.get("precodetype") == 2) {
1297                             try {
1298                                 SpObserver.setDBtoInstance("_" + dto.dbid);
1299                                 String table = gridService.getTreeTable(dto.formID);//TODO 暂时只取第一个,以后需要修正能处理多树的情况
1300                                 String[] strings = table.split(";");//TODO 以后去掉
1301                                 value = "autocode|2|~," + (Integer) ma.get("codelength") + ",#," + (String) ma.get("preFixcode") + "," + strings[0];
1302                             } finally {
1303                                 SpObserver.setDBtoInstance();
1304                             }
1305                         }
1306                         values.append(id.toLowerCase()).append("#").append(value).append("&p&");
1307                         ma = null;
1308                     } else if (!value.equalsIgnoreCase("@now") && (value.indexOf("@") > -1 || value.indexOf("!") > -1)) {//替换成当前session的值
1309                         //@now 表示需要取当前时间,所以通过js调用
1310                         String temp1 = DBHelper.getValRep(value, false);
1311                         values.append(id.toLowerCase()).append("#").append(temp1).append("&p&");
1312                     } else
1313                         values.append(id.toLowerCase()).append("#").append(value).append("&p&");
1314                 }
1315                 if (SumField != 0)
1316                     sumfu.append(id.toLowerCase()).append("#").append(SumField).append(":").append(funclinkname.replaceAll(",", "@p@")).append(",");//自定义公式有可能存在有,号需要处理
1317                 if ((passwordchar != null && !"".equalsIgnoreCase(passwordchar) && "1".equalsIgnoreCase(passwordchar)))
1318                     type = 101;
1319                 //控件类型
1320                 String typeName = Control.getTypeName(type == 0 ? 1 : type, typeInfo, id, displayformat, dto.winType);
1321                 StringBuilder sb = new StringBuilder();
1322                 if (type == 9 || type == 40) {
1323                     if (dto.picFild != null && dto.picFild != "") {
1324                         if (!dto.picFild.contains(id + ";"))
1325                             dto.picFild += id.toLowerCase() + ";";//保存是哪一个字段是图片字段
1326                     } else {
1327                         dto.picFild += id.toLowerCase() + ";";//保存是哪一个字段是图片字段
1328                     }
1329                     sb.append(" CanFocus='0' ");//图片不需要取得焦点,避免在进入编辑状态时上传图片,返回不显示的问题
1330                     sb.append(" showType='" + (type == 9 ? 0 : 2) + "' ");//以后增加格线支持多附件显示需要用到,区别出到时应该取哪一个附件表(_sys_Attachment9,_sys_Attachment)的数据
1331                 }
1332                 if (type == 2 || type == 35 || type == 31 || type == 43 || type == 30 || type == 32) {
1333                     sb = fillFT(type, ft, sqlScript, dto);//2类型
1334                     sb.append(" CanEmpty='0' ");
1335                     dto.foot2 += id.toLowerCase() + ";";//解决针对2,35类型有值时候统计列会显示出来的问题
1336                     dto.footb.append(id.toLowerCase()).append("Type='Text' ").append(id.toLowerCase()).append("Button='' ");//汇总页需要屏蔽单元格类型为Text
1337                 }
1338                 if (isAudit != 0) sb.append(" audit='").append(isAudit).append("'");//增加审计标记
1339                 if (rowspan) {//合并行
1340                     sb.append(" Spanned='1' ");//表示需要合并
1341                     dto.rowspanStr += id + ";";//保存需要合并的字段,加载时需要用到
1342                 }
1343
1344                 if (type == 3 || type == 31 || type == -3 || type == 42) { //3类型
1345                     String suggest = this.replaceBlank(GridUtils.prossRowSetDataType_String(map, "SuggestFileds").replaceAll("\\bid\\b", "_ycid_").toLowerCase());
1346                     String RelationField = this.replaceBlank(GridUtils.prossRowSetDataType_String(map, "RelationField").replaceAll("\\bid\\b", "_ycid_").toLowerCase());
1347                     if ("".equalsIgnoreCase(suggest) && type == 42)
1348                         msgInfo.append(temp + "字段为42类型控件,但列表字段[SuggestFileds]未设置");
1349                     //String path="/"+dto.verNo+ft+"/"+wiType+"/";
1350                     String path = "app#spellPath#" + ft + "/" + wiType + "/index.jsp";//#spellPath#在页面js替换, 解决定制页面生成时,数据源用了当前而造成移植到其他系统不对的问题
1351                     String top = this.replaceBlank(GridUtils.prossRowSetDataType_String(map, "SeekGroupID").replaceAll("\\bid\\b", "_ycid_").toLowerCase());
1352                     String form = this.replaceBlank(GridUtils.prossRowSetDataType_String(map, "FK").replaceAll("\\bid\\b", "_ycid_").toLowerCase());
1353                     String sf = this.replaceBlank(GridUtils.prossRowSetDataType_String(map, "sPremissField").replaceAll("\\bid\\b", "_ycid_").toLowerCase());
1354                     String df = this.replaceBlank(GridUtils.prossRowSetDataType_String(map, "dPremissField").replaceAll("\\bid\\b", "_ycid_").toLowerCase());
1355                     if(StringUtils.isNotBlank(top)&&StringUtils.isBlank(form)){
1356                         throw new ApplicationException("【9802】里【"+id+"】设置了【外表|接收自身字段名】,则【外表|接收外表字段名】不能为空");
1357                     }
1358 if(StringUtils.isNotBlank(sf)&&StringUtils.isBlank(df)){
1359     throw new ApplicationException("【9802】里【"+id+"】设置了【外表|自身条件字段名】,则【外表|外表条件字段名】不能为空");
1360                     }
1361                     sb.append(" formid='").append(ft)
1362                             .append("' toParm=\"").append(top)
1363                             .append("\" formParm=\"").append(form)
1364                             .append("\" sField=\"").append(sf)
1365                             .append("\" dField=\"").append(df)
1366                             .append("\" id='").append(id.toLowerCase())
1367                             .append("' wtype='").append(wiType)
1368                             .append("' oneRec='").append(oneRec ? 1 : 0)
1369                             .append("' onlyOne='").append(onlyOne ? 1 : 0)
1370                             .append("' sqlWhere=\"").append(sqlWhere)// by danaus 2019/12/20 15:28
1371                             .append("\" path='").append(path)
1372
1373                             .append(uppercase ? "'  uppercase='" + uppercase : "")
1374                             .append("' eFilter=\"").append(ef == null ? "" : (ef.replaceAll("'", "\\\\'").replaceAll("\n\t", ""))).append("\"");
1375                     String sug = "";
1376                     if (!"".equalsIgnoreCase(suggest)) {//加上自动补全功能
1377                         if (!"".equalsIgnoreCase(RelationField)) {//关联查询字段
1378                             sb.append(" refield='").append(RelationField + "'");
1379                         }
1380                         //去掉重复字段
1381                         String[] temp1 = suggest.toLowerCase().split(";");
1382
1383                         for (String s : temp1) {
1384                             if (sug.indexOf(s + ";") < 0) {
1385                                 sug += s + ";";
1386
1387                             }
1388                         }
1389                         sug = sug.substring(0, sug.length() - 1);
1390                         sb.append(" suggest='" + sug + "'");
1391                         //生成显示的数据名称
1392
1393                         //if(!sugId.contains(ft)){
1394                         //    sugId.add(ft);
1395                         rod++;//生成100之内的随机数
1396                         sb.append(" rand='10" + rod + "'");
1397                         dto.sugList.append(this.getSuggestFilds(ft + "", wiType, sug, sug, top, form, oneRec, rod, dto.dbid, sf, df));
1398                         //    }
1399                     }
1400                     if (type == -3)//表示为辅助核算
1401                         sb.append(" curType='gl' ");
1402                     if (type == 3 || type == -3)
1403                         sb.append(" Button='/images/ppp.gif'  WidthPad='20'");
1404                     this.prossIntoSession(top, dto);
1405                     this.prossIntoSession(form, dto);
1406                     this.prossIntoSession(sf, dto);
1407                     this.prossIntoSession(df, dto);
1408                     this.prossIntoSessionForFilter(ef, dto);
1409                     dto.footb.append(id.toLowerCase()).append("Type='Text' ").append(id.toLowerCase()).append("Button='' ");//汇总页需要屏蔽单元格类型为Text
1410
1411                 } else if (type == 6) {
1412                     sb.append(" CanEmpty='0' ");//解决在只读时候,没值会显示不正确的情况
1413                     dto.footb.append(id.toLowerCase()).append("Type='Text' ");//汇总页需要屏蔽单元格类型为Text
1414                 } else if (type == 1 || type == 0 || type == 7) {
1415                     sb.append(uppercase ? "  uppercase='" + uppercase + "'" : "");
1416
1417                 } else if (type == 9) {//图片控件
1418                     sb.append(" Button='/images/d.jpg'  WidthPad='20' ");
1419                     dto.footb.append(id.toLowerCase()).append("Type='Text' ").append(id.toLowerCase()).append("Button='' ");//汇总页需要屏蔽单元格类型为Text
1420                 }
1421                 if (type != 2 && type != 31) {//下拉类型的不需要显示
1422                     if (len.get(id.toLowerCase()) != null && Integer.parseInt(len.get(id.toLowerCase())) > 0) { //存在varchar(max),nvarchar(max)的情况
1423
1424                         String rep = "^\\\\\\s*[\\\\\\s\\\\\\S]{0," + len.get(id.toLowerCase()) + "}\\\\\\s*\\$";
1425                         sb.append(" EditMask='").append(rep).append("' ")
1426                                 .append(" Tsize='").append(len.get(id.toLowerCase())).append("' ")
1427                                 .append(" Tip='").append("最长").append(len.get(id.toLowerCase()))
1428                                 .append("个字符(每汉字占2个字符)'");
1429                     }
1430                 }
1431                 sb.append(calcuField != 0 ? "  calcuField='" + calcuField + "'" : "");
1432                 sb.append(KeyInput ? "  KeyIn='1'" : "").append(" dataType='").append(dataType).append("' ");
1433                 if (emptyrefdata != null && !emptyrefdata.equalsIgnoreCase("") && !emptyrefdata.equalsIgnoreCase("0") && type != 6)
1434                     sb.append(" emptyrefdata='").append(this.replaceBlank(emptyrefdata)).append("'");//增加清空关联
1435                 if (!this.isNullOrEmptry(GridUtils.prossRowSetDataType_String(map, "HyperlinkFT")) && !this.isNullOrEmptry(GridUtils.prossRowSetDataType_String(map, "HyperlinkFTFormType"))) {
1436                     //判断22类型的主表是不是自定义.do。
1437                     String execdo = "";
1438                     if ("22".equals(GridUtils.prossRowSetDataType_String(map, "HyperlinkFTFormType"))
1439                             && org.apache.commons.lang.StringUtils.isNumeric(GridUtils.prossRowSetDataType_String(map, "HyperlinkFT"))) {
1440                         T_22_Ifc t22ifc = (T_22_Ifc) FactoryBean.getBean("T_22_Impl");
1441                         execdo = t22ifc.getProcName(GridUtils.prossRowSetDataType_String(map, "HyperlinkFT"));
1442                         if (execdo != null && !"".equals(execdo)) {
1443                             execdo = (execdo.indexOf(".do") != -1 ? execdo : "");
1444                         }
1445                     }
1446                     String efl = this.replaceBlank(GridUtils.prossRowSetDataType_String(map, "HyperlinkEFilter").toLowerCase());
1447                     String op = this.replaceBlank(GridUtils.prossRowSetDataType_String(map, "Hyperlinkmode").toLowerCase());
1448                     int save = GridUtils.prossRowSetDataType_Int(map, "isAutoSaved");
1449 //                    String openType=this.prossRowSetDataType_String(map,"openType")==null?"0":this.replaceBlank(this.prossRowSetDataType_String(map,"openType").toLowerCase());
1450                     String sf = this.replaceBlank(GridUtils.prossRowSetDataType_String(map, "HyperlinkSPremissField").replaceAll("\\bid\\b", "_ycid_").toLowerCase());
1451                     String df = this.replaceBlank(GridUtils.prossRowSetDataType_String(map, "HyperlinkDPremissField").replaceAll("\\bid\\b", "_ycid_").toLowerCase());
1452                     boolean autoref = false;
1453                     try {
1454                         autoref = GridUtils.prossRowSetDataType_Boolean(map, "isAutoRefresh");
1455                     } catch (Exception e) {
1456
1457                     }
1458                     sb.append("  Fformid='").append(this.replaceBlank(GridUtils.prossRowSetDataType_String(map, "HyperlinkFT").toLowerCase()))
1459                             .append("' FsField=\"").append(sf)
1460                             .append("\" FdField=\"").append(df)
1461                             .append("\" Fref=\"").append(autoref ? 1 : 0)
1462 //                        .append("\" FopenType=\"").append(openType)//增加弹出层的功能 1表示正常的页卡,2表示弹出层显示
1463                             .append("\" Fwtype='").append(GridUtils.prossRowSetDataType_String(map, "HyperlinkFTFormType"))
1464                             .append("' Fop='").append(op == null ? "0" : (op.replaceAll("'", "\\\\'").replaceAll("\n\t", "")))
1465                             .append("' Fsave='").append(save)
1466                             .append("' Fexec='").append(execdo)
1467                             .append("' FeFilter=\"").append(efl == null ? "" : (efl.replaceAll("'", "\\\\'").replaceAll("\n\t", ""))).append("\"");
1468                     this.prossIntoSession(sf, dto);
1469                     this.prossIntoSession(df, dto);
1470                     this.prossIntoSessionForFilter(efl, dto);
1471                 }
1472                 if ((dto.order == 1 && id.equalsIgnoreCase("doccode") && this.isNullOrEmptry(GridUtils.prossRowSetDataType_String(map, "HyperlinkFT")) && this.isNullOrEmptry(GridUtils.prossRowSetDataType_String(map, "HyperlinkFTFormType")))//当是单据时候增加对doccode字段自动超链接
1473                 ) {
1474                     sb.append("  Fformid='").append(dto.formID)
1475                             .append("' FsField=\"").append("doccode")
1476                             .append("\" FdField=\"").append("doccode")
1477                             .append("\" Fwtype='").append(dto.othType)
1478                             .append("' FeFilter=\"").append("\"");
1479                 }
1480                 if (ShowOnGrid && id.equalsIgnoreCase(dto.lastField.toLowerCase())) sb.append(" ent='1' ");//增加标记为最后一个字段
1481                 if (index < dto.frozencols) {//
1482                     left.append("<C CaseSensitive='0' Name='").append(id.toLowerCase()).append("'").append(" cpltrow='").append(cpltrow ? 1 : 0).append("' CanEdit='").append(readOnly ? 0 : 1).append("' Type='").append(typeName).append("' ")
1483                             .append((editStatus == "" || editStatus == null) ? "" : " editStatus='" + editStatus + "'")
1484                             .append(ShowOnGrid ? "" : " Visible='0' ")
1485                             .append(fileterID ? " Visible='0' " : "");
1486                     if (!dto.isList && dto.gantt && "subtask".equalsIgnoreCase(id.toLowerCase()))
1487                         left.append(" CanGroup='2' GroupChar='/' GroupEmpty='0' ");
1488                     left.append((displayformat != null && !"".equalsIgnoreCase(displayformat) && !"0".equalsIgnoreCase(displayformat)) ? ("  Format='" + displayformat + "'" + ("Date".equalsIgnoreCase(typeName) ? " EditFormat='" + displayformat + "'" : "")) : ("Date".equalsIgnoreCase(typeName) ? " Format='yyyy-MM-dd' EditFormat='yyyy-MM-dd'" : ""))
1489                             .append("  CanEmpty='1' Align='").append(cellAlign).append("' Width='").append(width).append("' ").append(sb.toString() + "/>\n");
1490                     if (ValueExp != null && !"".equalsIgnoreCase(ValueExp)) {//增加一个有权限控制的关联字段
1491                         left.append("<C CaseSensitive='0' Name='").append(id.toLowerCase()).append("_expr'")
1492                                 .append(" Visible='0' ")
1493                                 .append(" />\n");
1494                     }
1495                     if (!fileterID&&ShowOnGrid) index++;
1496                 } else {
1497                     cols.append("<C CaseSensitive='0' Name='").append(id.toLowerCase()).append("'").append(" cpltrow='").append(cpltrow ? 1 : 0).append("' CanEdit='").append(readOnly ? 0 : 1).append("' Type='").append(typeName).append("' ")
1498                             .append((editStatus == "" || editStatus == null) ? "" : " editStatus='" + editStatus + "'")
1499                             .append(ShowOnGrid ? "" : " Visible='0' ")
1500
1501                             .append(fileterID ? " Visible='0' " : "");
1502                     if (!dto.isList && dto.gantt && "subtask".equalsIgnoreCase(id.toLowerCase()))
1503                         cols.append(" CanGroup='2' GroupChar='/' GroupEmpty='0' ");
1504                     cols.append((displayformat != null && !"".equalsIgnoreCase(displayformat) && !"0".equalsIgnoreCase(displayformat)) ? ("  Format='" + displayformat + "'" + ("Date".equalsIgnoreCase(typeName) ? " EditFormat='" + displayformat + "'" : "")) : ("Date".equalsIgnoreCase(typeName) ? " Format='yyyy-MM-dd' EditFormat='yyyy-MM-dd'" : ""))
1505                             .append("  CanEmpty='1' Align='").append(cellAlign).append("' Width='").append(width).append("' ").append(sb.toString() + "/>\n");
1506                     if (ValueExp != null && !"".equalsIgnoreCase(ValueExp)) {//增加一个有权限控制的关联字段
1507                         cols.append("<C CaseSensitive='0' Name='").append(id.toLowerCase()).append("_expr'")
1508                                 .append(" Visible='0' ")
1509                                 .append(" />\n");
1510
1511                     }
1512                 }
1513
1514             }
1515             //while(dto.gfields.next());
1516             if ("".equalsIgnoreCase(dto.orderFiled)) dto.orderFiled = firstID + " desc";
1517             dto.expr = valExp.length() > 0 ? valExp.substring(0, valExp.length() - 1) : "";
1518             dto.cspr = cssExp.length() > 0 ? cssExp.substring(0, cssExp.length() - 1) : "";
1519             dto.tipspr = tipsExp.length() > 0 ? tipsExp.substring(0, tipsExp.length() - 1) : "";
1520             if (cols.length() == 0 && !dto.gantt) {
1521                 msgInfo.append(dto.formID + "-格线未设置显示字段或9801定义的冻结列数大于需要显示的列数或加载项(isLoad)未勾选!");
1522             }
1523             if (cols.length() > 0)
1524                 dto.colsConfig = cols.substring(0, cols.length() - 1);
1525             dto.LeftCols = left.length() > 0 ? "<LeftCols>" + left.substring(0, left.length() - 1) + "</LeftCols>" : "";
1526             dto.formula = formn.length() > 1 ? formn.substring(0, formn.length() - 1) : "";
1527             dto.initValue = values.length() > 1 ? values.substring(0, values.length() - 3) : "";
1528             dto.totalCols = sumfu.length() > 1 ? sumfu.substring(0, sumfu.length() - 1) : "";
1529             if (!iscopy && rowCopys != null) {
1530                 dto.rowcopyfields = rowCopys.length() > 1 ? rowCopys.substring(0, rowCopys.length() - 1) : "";
1531             }
1532             if (dto.totalCols == "") {
1533                 dto.foot = "";
1534                 dto.foot2 = "";
1535             }//当没有统计列时候不需要显示
1536             else {
1537                 dto.foot = "<Foot><I id=\"Fix1\" CanEdit='0' " + dto.footb.toString() + "/></Foot>";
1538             }
1539
1540             if ((exportInfo.lastIndexOf("-") + 1) < exportInfo.length()) {
1541                 int tsm = dto.conNum == 0 ? dto.winType : dto.othType;
1542                 exportInfo.append("-").append(tsm).append("-").append(SumFieldInfo.toString());//后面跟窗体类型
1543                 // String titles="";
1544 //            if(exportTitle.length()>0) {
1545 //             titles=exportTitle.toString();
1546 //            if(titles.lastIndexOf(";")>0) titles=titles.substring(0, titles.length()-1);
1547 //            }
1548                 // titles=titles+"@p@"+exportInfo.toString();
1549                 FileUtil.writeFile(exportInfo.toString(), root.replaceAll("\\\\", "/") + File.separator + dto.verNo + "/" + dto.formID + "/" + tsm + "/data");//写到文件里面
1550             }
1551             if (msgInfo.length() > 0) throw new ApplicationException(msgInfo.toString());
1552         } catch (ArrayIndexOutOfBoundsException e1) {
1553             throw new ApplicationException("读取不到" + dto.formID + "在9802里面的字段信息,请检查9802是否已做了相关设置");
1554         } catch (Exception e) {
1555             e.printStackTrace();
1556             throw new ApplicationException(e.getCause() == null ? e.getMessage() + "\n" + msgInfo.toString() + "_" + dto.dbid : e.getCause().getMessage() + "\n" + msgInfo.toString() + "_" + dto.dbid);
1557         } finally {
1558             left = null;
1559             cols = null;
1560             formn = null;
1561             values = null;
1562             sumfu = null;
1563             valExp = null;
1564             msgInfo = null;
1565         }
1566     }
1567
1568     private void setFilter(String id, int type, StringBuilder filter, int dIndex) {
1569         switch (type) {
1570
1571             case 1:
1572             case 7:
1573                 if (dIndex == 4)//是日期类型,虽然定义为1类型也显示日期
1574                     filter.append(id).append("Range=\"1\" ")
1575                             .append(id).append("Filter=\"0\" ")
1576                             .append(id).append("ShowMenu=\"0\" ");
1577                 else
1578                     filter.append(id).append("Range=\"1\" ")
1579                             .append(id).append("Filter=\"0\" ")
1580                             .append(id).append("ShowMenu=\"1\" ");
1581                 break;
1582             case 5:
1583                 filter.append(id).append("Range=\"1\" ")
1584                         .append(id).append("Filter=\"0\" ")
1585                         .append(id).append("ShowMenu=\"0\" ");
1586                 break;
1587             case 2:
1588             case 31:
1589             case 35:
1590                 filter.append(id).append("Range=\"1\"  ")
1591
1592                         .append(id).append("Type='Text'")
1593                         .append(id).append("ShowMenu=\"1\"  ");
1594                 break;
1595             case 3:
1596                 filter.append(id).append("Range=\"1\" ")
1597                         .append(id).append("Button='' ")
1598                         .append(id).append("Type='Text'")
1599                         .append(id).append("ShowMenu=\"1\" ");
1600                 break;
1601             case 9:
1602             case 19:
1603             case 40:
1604                 filter.append(id).append("CanEdit='0' ")
1605                         .append(id).append("Button=''  ")
1606                         .append(id).append("Type='Text' ")
1607                         .append(id).append("ShowMenu='0' ");
1608                 break;
1609             case 6:
1610                 filter.append(id).append("Range=\"1\" ")
1611                         .append(id).append("Button=\"Defaults\" ")
1612                         .append(id).append("Defaults=\"|*FilterOff|*RowsAll\" ")
1613                         .append(id).append("ShowMenu=\"0\" ");
1614                 break;
1615         }
1616
1617     }
1618
1619     /**
1620      * 把需要从会话中替换的值写到页面里
1621      **/
1622     private void prossIntoSession(String str, TreeGridDTO dto) {
1623         if (str != null && str.length() > 0) {
1624             StringBuilder sb = new StringBuilder();
1625             String[] s = str.split(";");
1626             int index = 0;
1627             String kk = "";//中间变量
1628             for (String te : s) {
1629                 if (te.indexOf("@") == 0) {//需要从会话里读
1630                     //处理会话值为空的情况,导致页面js的json对象出现脚本错误
1631                     String temp = "<%=(session.getAttribute(\"" + te.toLowerCase() + "\")==null||((String)session.getAttribute(\"" + te.toLowerCase() + "\")).length()==0)?\"\":session.getAttribute(\"" + te.toLowerCase() + "\")%>";//DBHelper.getValRep(te.toLowerCase(),false);
1632
1633                     if (te.equalsIgnoreCase(kk)) continue;
1634                     kk = te;
1635                     if (index > 0) sb.append(",");
1636                     if (dto.setInfo != null && dto.setInfo.trim().length() > 0 && index == 0) dto.setInfo += ",";
1637                     sb.append(te.replaceAll("'", "").replaceAll("@", "").toLowerCase())
1638                             .append(":")
1639                             .append("'")
1640                             .append(temp)
1641                             .append("'");//还原引号是因为需要引号括起来,在页面才不会出现脚本错误
1642                     index++;
1643                 }
1644             }
1645
1646             dto.setInfo += sb.toString();
1647         }
1648     }
1649
1650     /**
1651      * 把需要从会话中替换的值写到页面里 ,适用是自定义条件的情况
1652      * 也就是一条sql语句中需要查出来替换,isnull(cccode,'')='@cccode'
1653      **/
1654     private void prossIntoSessionForFilter(String str, TreeGridDTO dto) {
1655         if (str != null && str.length() > 0) {
1656             StringBuilder sb = new StringBuilder();
1657             Pattern p = Pattern.compile("@.*?\\w+");// 匹配以@开头的单词
1658             java.util.regex.Matcher propsMatcher = p.matcher(str);
1659             int index = 0;
1660             String kk = "";
1661             String kt = "";
1662             while (propsMatcher.find()) {
1663                 String te = propsMatcher.group();
1664
1665                 String temp = "<%=(session.getAttribute(\"" + te.toLowerCase() + "\")==null||((String)session.getAttribute(\"" + te.toLowerCase() + "\")).length()==0)?\"\":session.getAttribute(\"" + te.toLowerCase() + "\")%>";//DBHelper.getValRep(te.toLowerCase(),false);
1666                 if (te.equalsIgnoreCase(kk)) continue;
1667                 if (dto.setInfo.indexOf(kt + ":") > 0) continue;
1668                 kk = te;
1669                 if (index > 0) sb.append(",");
1670                 if (dto.setInfo != null && dto.setInfo.trim().length() > 0 && index == 0) dto.setInfo += ",";
1671                 kt = te.replaceAll("@", "").toLowerCase();
1672                 sb.append(te.replaceAll("@", "").toLowerCase())
1673                         .append(":")
1674                         .append("'")
1675                         .append(temp)
1676                         .append("'");
1677                 index++;
1678             }
1679
1680             dto.setInfo += sb.toString();
1681         }
1682     }
1683
1684     private void prossIntoSessionForFilter_dy(String str, TreeGridDTO dto) {
1685         if (str != null && str.length() > 0) {
1686             StringBuilder sb = new StringBuilder();
1687             Pattern p = Pattern.compile("@.*?\\w+");// 匹配以@开头的单词
1688             java.util.regex.Matcher propsMatcher = p.matcher(str);
1689             int index = 0;
1690             String kk = "";
1691             while (propsMatcher.find()) {
1692                 String te = propsMatcher.group();
1693
1694                 String temp = "<%=(session.getAttribute(\"" + te.toLowerCase() + "\")==null||((String)session.getAttribute(\"" + te.toLowerCase() + "\")).length()==0)?\"\":session.getAttribute(\"" + te.toLowerCase() + "\")%>";//DBHelper.getValRep(te.toLowerCase(),false);
1695                 if (te.equalsIgnoreCase(kk)) continue;
1696                 kk = te;
1697                 if (index > 0) sb.append(",");
1698                 sb.append(te.replaceAll("@", "").toLowerCase())
1699                         .append(":")
1700                         .append("'")
1701                         .append(temp)
1702                         .append("'");
1703                 index++;
1704                 if(!"".equalsIgnoreCase(dto.setInfo_dy)){
1705                     dto.setInfo_dy +=",";
1706                 }
1707             }
1708             dto.setInfo_dy += sb.toString();
1709         }
1710     }
1711
1712     /**
1713      * 处理生成多表结构中的多表格
1714      **/
1715     public void setTabPage(int formType, int height, int count, TreeGridDTO dto) {
1716         dto.tabPage = formType;
1717         dto.gridHeight = height;
1718         dto.masterKey = count == 0 ? "" : count + "";
1719         dto.b499 = true;
1720     }
1721
1722     public void setTabPage497(int type, int height1, String indexs, String tolkey, int formid, int index, TreeGridDTO dto) {
1723         dto.tabPage = type;
1724         dto.gridHeight = height1;
1725         dto.masterKey = indexs;
1726         dto.b497 = true;
1727         dto.b499 = true;
1728         dto.tolkey = tolkey;
1729         dto.PriFormID = formid;//取得主功能号里面的排除功能号和字段列表用 by 11-5-28
1730         dto.PriIndex = index;
1731     }
1732
1733     /**
1734      * 根据不同类型决定不同的排序规则
1735      * //1,读取9801设置,
1736      * //2,根据不同类型再进行不同的设置(单据清单desc,明细 以docitem asc,)
1737      * //3,对于不是上面的二种情况不用排序
1738      */
1739     private String setOrderBy(TreeGridDTO dto) {
1740         String temp = "";
1741         if (dto.order == 1 && dto.index1 != null && !dto.index1.isEmpty()) { //9801 主表
1742             temp = setSqlOrderBy(dto.index1, " asc");
1743         } else if (dto.order == 2 && dto.index2 != null && !dto.index2.isEmpty()) {//明细表
1744             temp = setSqlOrderBy(dto.index2, " asc");
1745         } else {
1746             if (dto.field.isEmpty())
1747                 temp = dto.orderFiled;
1748             else {
1749                 //处理8类型第三表的排序不是默认的docitm的情况,也就是9801定义有排序
1750                 if(dto.winType==15&&dto.order==2&& org.apache.commons.lang3.StringUtils.isNotBlank(dto.index1)){
1751                     temp = setSqlOrderBy(dto.index1, " asc");
1752                 }else {
1753                     temp = setSqlOrderBy(dto.field, dto.order == 1 ? " desc" : " asc");
1754                 }
1755             }
1756         }
1757         dto.field = "";
1758         if ("".equalsIgnoreCase(temp)) return "";
1759         String[] s = temp.replaceAll(",", " ").split("\\s+");//
1760         String cols = "SortCols='";
1761         String types = "SortTypes='";
1762         for (int j = 0; j < s.length; j += 2) {
1763             if (j > 0) {
1764                 cols += ",";
1765                 types += ",";
1766             }
1767             cols += s[j].equalsIgnoreCase("_ycid_") ? "id" : s[j];
1768             types += "asc".equalsIgnoreCase(s[j + 1]) ? "0" : "1";
1769         }
1770         return cols + "' " + types + "'";
1771
1772     }
1773
1774     private String setSqlOrderBy(String index22, String x) {//x为desc,asc
1775         String temp = "";
1776         index22 = index22.replaceAll(";", ",");
1777         String[] sorts = index22.split(",");
1778         int index = 0;
1779         for (String s : sorts) {
1780             String[] str = s.split("\\s");
1781             if (str.length == 2) {
1782                 if (index > 0)
1783                     temp += "," + str[0] + " " + str[1];
1784                 else
1785                     temp += str[0] + " " + str[1];
1786             } else {
1787                 if (index > 0)
1788                     temp += "," + str[0] + " " + x;
1789                 else
1790                     temp += str[0] + " " + x;
1791             }
1792             index++;
1793         }
1794         return temp;
1795     }
1796
1797     /**
1798      * 设置表格高度
1799      */
1800     private String setGridHight(TreeGridDTO dto) {
1801         if (((dto.winType != 1 || dto.winType != 10) && dto.order == 2) && dto.gridHeight == 0)
1802             dto.gridHeight = GRID_HEIGHT;
1803         String temp = dto.gridHeight > 0 ? dto.gridHeight + "px" : GRID_HEIGHT + "px";
1804         dto.gridHeight = 0;
1805         return temp;
1806     }
1807
1808     /* (non-Javadoc)
1809      * @see com.yc.action.grid.TreeGridIfc#createGrid(int, int, java.lang.String, java.lang.String, java.lang.String[])
1810      */
1811     @Override
1812     public void createGrid(int type, int formID, String root, String path, String fileName[], String tempPath, String pst, TMuiDTO dt, String dbid) throws DataAccessException, SQLException {
1813         try {
1814             StringBuilder sb = new StringBuilder();//总的js
1815             StringBuilder jsp = new StringBuilder();//总的jsp
1816             StringBuilder main = new StringBuilder();//临时main标记
1817             StringBuilder hd = new StringBuilder();//临时header标记
1818             TreeGridDTO dto = new TreeGridDTO();
1819             String refgrid = "";//保存需要引用多少个grid
1820             dto.verNo = path.replaceAll("\\\\", "/");//系统号+版本号+语言
1821             dto.formID = formID;
1822             dto.winType = type;
1823             dto.othType = 0;
1824             dto.dbid = dbid;
1825             if (dt != null) {//把多表的值传过来填充
1826                 this.setTabPage497(dt.type, dt.height1, dt.indexs, dt.tolkey, dt.fromid, dt.index,dto);
1827                 this.setXxk(dt.xxk, dto);
1828                 dto.formTabName=dt.formTabName;
1829             }
1830             if (dt != null && dt.addnew)
1831                 dto.postStatusAddNew = dt.addnew;
1832             int ty = gridService.getwinType(dto.winType);
1833             if (ty == 4 || ty == 5) {
1834                 dto.isTable = false;
1835                 dto.action = ty == 4 ? "func" : "proc";
1836             }
1837             String hasGrid = "";
1838             int num = 1;//循环次数
1839             if (dto.winType == 9) {
1840                 num = 2;
1841                 dto.othType = 5;
1842             }
1843             if (dto.winType == 17) {
1844                 num = 1;
1845                 dto.othType = 16;
1846                 hasGrid = "0";
1847             }
1848             if (dto.winType == 15) {
1849                 num = 3;
1850                 dto.othType = 8;
1851                 dto.muilGrid = true;
1852             }//三表有关联
1853             if (dto.winType == 152) {
1854                 num = 3;
1855                 dto.othType = 151;
1856                 dto.muilGrid = true;
1857             }//三表无关联
1858             if (dto.winType == 499 || dto.winType == 498) {
1859                 dto.othType = 498;
1860                 hasGrid = "many";
1861             }//多表
1862             if (dto.winType == 497 || dto.winType == 496) {
1863                 dto.othType = 496;
1864                 hasGrid = "many";
1865             }//多表且有关联
1866
1867             for (int i = 0; i < num; i++) {
1868                 if (dto.winType == 3 || dto.winType == 4 || dto.winType == 30 || dto.winType == 301) {//树类型,需要生成与树相关的值
1869                     dto.treefield = this.getTreeFields(formID, dto.dbid);
1870                 }
1871                 String str = FileUtil.readFile(tempPath + "/grid.jsp");//页面模板
1872                 if (dto.muilGrid && i == 0) jsp.append(str).append("\n");    //先保存好模板,以便生成多表时候用
1873                 dto.conNum = i;
1874                 dto.order = setOrderName(dto);
1875                 this.print(root, dto);
1876                 String strJs = FileUtil.readFile(tempPath + (((dto.gantt && dto.order == 2) || (dto.gantt && dto.winType == 18)) ? "/grid_Gantt.js" : "/grid.js"));//页面js
1877                 String[] ver = dto.verNo.split("/");
1878                 String ddsave = "";
1879                 try {
1880                     if (dto.DealAfterDocSave != null && dto.DealAfterDocSave.trim().length() > 0)
1881                         ddsave = "&DealAfterDocSave=" + this.replaceBlank(EncodeUtil.base64Encode(dto.DealAfterDocSave));
1882                 } catch (UnsupportedEncodingException e) {
1883                     throw new ApplicationException("加密保存后执行组出错-" + dto.DealAfterDocSave);
1884                 }
1885                 try {
1886                     String js = FileUtil.readFile(tempPath + (((dto.gantt && dto.order == 2) || (dto.gantt && dto.winType == 18)) ? "/gridDef_Gantt.xml" : "/gridDef.xml"));//js结构
1887                     js = js
1888                             .replaceAll("@id", "T_" + dto.formID)//功能号
1889                             .replaceAll("@lang", ver[ver.length - 1])//语言
1890                             .replaceAll("@Cols", dto.colsConfig + "")//列定义
1891                             .replaceAll("@LeftCols", dto.LeftCols + "")//列定义
1892                             .replaceAll("@Header", dto.header.replaceAll("\\$", "\\\\\\$") + "")//列标题,转义$为\$
1893                             .replaceAll("@minHeight", GRID_HEIGHT + "")//最小高度
1894                             .replaceAll("@formidType", dto.winType + "|" + i)//当前grid的窗体类型
1895                             .replaceAll("@formid", dto.formID + "")//当前grid的功能号
1896                             .replaceAll("@formula", this.replaceBlank(dto.formula))//自定义公式 //增加判断是否存在死循环的可能
1897                             .replaceAll("@rowSpan", this.replaceBlank(dto.rowspanStr))//合并行的字段
1898                             .replaceAll("@totalCols", this.replaceBlank(dto.totalCols))//统计列
1899                             .replaceAll("@rowcopyfields", dto.rowcopyfields == null ? "" : this.replaceBlank(dto.rowcopyfields))
1900                             .replaceAll("@rowcopyformids", dto.rowcopyformids == null ? "" : this.replaceBlank(dto.rowcopyformids))
1901                             .replaceAll("@t302", dto.winType == 302 ? true + "" : false + "")//302类型
1902                             .replaceAll("@t15", (dto.winType == 15 && dto.conNum == 1) ? true + "" : false + "")//15类型中单击查询第二个grid
1903                             .replaceAll("@gType", (dto.tabPage > 0) ? ((dto.tabPage == 77 || dto.tabPage == 7) ? "77" : (dto.b497 ? 497 : 499) + "") : dto.winType + "")//当前grid的窗体类型
1904                             .replaceAll("@Disabled", (dto.winType == 18 && dto.gantt) ? "GanttDisabled=\"2\"" : "")
1905                             .replaceAll("@glcodefield", dto.glcodefield == null ? "" : dto.glcodefield + "")
1906                             .replaceAll("@treefield", this.replaceBlank(dto.treefield))//用在格线对应字段没设置初始值时,需要从树里取得值,所以需要在这里
1907                             .replaceAll("@expr", this.replaceBlank(dto.expr.replaceAll("<", "&lt;").replaceAll(">", "&gt;")))
1908                             .replaceAll("@css", this.replaceBlank(dto.cspr))
1909                             .replaceAll("@tips", this.replaceBlank(dto.tipspr))
1910                             .replaceAll("@tolkey", this.replaceBlank(dto.tolkey))
1911                             .replaceAll("@colns", this.replaceBlank(dto.columns))
1912                             .replaceAll("@MainCol", (dto.mainCol == null || "".equalsIgnoreCase(dto.mainCol)) ? "" : "MainCol='" + dto.mainCol.toLowerCase() + "'")
1913                             .replaceAll("@isNine", ((dto.othType > 0) && i == 0) ? ("/" + dto.verNo + dto.formID + "/" + dto.othType + "/index.jsp") : "null")//双击打开
1914                             .replaceAll("@nineType", dto.othType + "")////双击打开页面指定的类型
1915                             .replaceAll("@keyid", (dto.b499 || dto.b497) ? (dto.masterKey.trim().equalsIgnoreCase(",") ? "" : dto.masterKey.trim()) : (dto.masterKey + "," + dto.detailKey).trim().equalsIgnoreCase(",") ? "" : (dto.masterKey + "," + dto.detailKey))
1916                             .replaceAll("@Sorting", (dto.lockGridSort == 0 ? 1 : 0) + "")//取相反值,因为是冻结排序
1917                             .replaceAll("@Sort", this.replaceBlank(this.setOrderBy(dto)))//主键列,可以有多个,以"|"分隔
1918                             .replaceAll("@foot", this.replaceBlank(dto.foot))//汇总列
1919                             .replaceAll("@panelID", dto.PriIndex + "")//针对77类型取哪一个面板数据进行过滤
1920                             .replaceAll("@ycadd", this.setToolAdd(dto) == 2 ? "Add, " : "")//清单和查询页面不需要增行和删行
1921                             .replaceAll("@predocstatus", dto.predocstatus + "")//确认前状态值
1922                             //.replaceAll("@PostStatusGridAddNew",dto.postStatusAddNew+"")//确认前状态值
1923                             .replaceAll("@Columns", dto.colset == 1 ? "Columns," : "")//列过滤
1924                             .replaceAll("@Actions", dto.actions)//
1925                             .replace("@Tree", (dto.conNum == 0 || (dto.mainCol == null || "".equalsIgnoreCase(dto.mainCol))) ? "" : " AddChild,")//
1926                             .replace("@isTree", (dto.conNum == 0 || (dto.mainCol == null || "".equalsIgnoreCase(dto.mainCol))) ? "0" : "1")
1927                             .replace("@formTabName", dto.formTabName)
1928                             .replaceAll("@primeKey", (dto.primeKey == null || "".equalsIgnoreCase(dto.primeKey)) ? "" : dto.primeKey + ";")
1929                             .replaceAll("@Filter", (dto.isFilter == 1) ? dto.filter.append(" />").toString() : "")//DIV
1930                             .replaceAll("@defaultRowCount", dto.order == 2 ? dto.defaultRowCount + "" : "0")//格线默认行数
1931                             .replaceAll("@gltotal", this.replaceBlank(dto.gltotal));//辅助核算需要的汇兑,平衡字段
1932                     strJs = strJs
1933                             .replaceAll("@dataformid", (i == 0) ? (dto.dataformid != "" ? "&dataformid=" + this.replaceBlank(dto.dataformid) : "") : "")//dataformid功能,i==0表示只有单据清单才需要过滤
1934
1935                             .replaceAll("@tranformid", (dto.tranformid != "" ? "&tranformid=" + this.replaceBlank(dto.tranformid) : ""))//dataformid功能,确认时候调用来断定
1936                             .replaceAll("@action", dto.action)
1937                             .replaceAll("@lang", ver[ver.length - 1])//语言
1938                             .replaceAll("@foot2", this.replaceBlank(dto.foot2))
1939                             .replaceAll("@_ycaddnew_@", this.setToolAddForNew(dto))//当前用户是否存在OA审核按钮,其中有为1的则格线需要显示增行按钮
1940                             //.replaceAll("@_attachment_server_@", domain==null?"":domain)//附件服务器地址
1941                             .replaceAll("@picFild", this.replaceBlank("&picFild=" + dto.picFild))
1942                             .replaceAll("@TBCols", "&tbCols=" + EncodeUtil.base64Encode(this.replaceBlank(dto.totalCols)))//统计列
1943                             .replaceAll("@initValue", this.replaceBlank(dto.initValue))//初始值
1944                             .replaceAll("@verNo", this.replaceBlank(dto.verNo))//系统号+版本号+语言
1945                             .replaceAll("@setInfo", this.replaceBlank(dto.setInfo_dy.length() > 0 ? (dto.setInfo.length() > 0 ? dto.setInfo + "," + dto.setInfo_dy : dto.setInfo_dy) : dto.setInfo))//会话信息
1946                             .replaceAll("@optype", this.replaceBlank(dto.optype + ""))//权限信息
1947                             .replaceAll("@num", setGridNum(dto))
1948                             .replaceAll("@fileTime", this.setFilePath(path.replaceAll("\\\\", "/"), this.setJsName(dto), pst, dto))
1949                             .replaceAll("@divID", "T_" + dto.formID)//div所在的id
1950                             .replaceAll("@trangroup", dto.trangroup)//过帐类型
1951                             .replaceAll("@layout", this.setJsName(dto))//js文件名称
1952                             .replaceAll("@hasGrid", hasGrid)//js文件名称
1953                             .replaceAll("@isTree", (dto.mainCol == null || "".equalsIgnoreCase(dto.mainCol)) ? "" : "&isTree=1")
1954                             .replaceAll("@winType", dto.winType + "@p@" + i)//表的顺序 0表示读取主表 1表示读取从表
1955                             .replaceAll("@id", dto.formID + "")//功能号
1956                             .replaceAll("@DealAfterDocSave", ddsave)//保存时执行
1957                             .replaceAll("@CancelProc", "&cancelProc=" + this.replaceBlank(EncodeUtil.base64Encode(dto.cancelProc)) + "&cancelisSave=" + dto.cancelisSave + "&isExchangeDataWithHost=" + dto.isExchangeDataWithHost)//取消确认
1958                             .replaceAll("@revokeProc", "&revokeProc=" + this.replaceBlank(EncodeUtil.base64Encode(dto.revokeProc)))//审核撤回
1959                             .replaceAll("@pageSize", this.replaceBlank(dto.pageSize + ""))//
1960                             .replaceAll("@paging", "&autopaging=" + this.replaceBlank((dto.autopaging == 1 ? 3 : 2) + ""))//
1961                             .replaceAll("@formdatafilters", this.replaceBlank(i == 0 ? dto.formdatafilters.replaceAll("'", "\\\\'").replaceAll("%", "@~") : ""))//i==0表示只有单据清单才需要过滤
1962                             .replaceAll("@ProcGroupafterSavedoc", (dto.othType > 0 && i > 0 && dto.ProcGroupafterSavedoc != null && dto.ProcGroupafterSavedoc.trim().length() > 0) ? "&ProcGroupafterSavedoc=" + dto.ProcGroupafterSavedoc : "");
1963                     String tableType = null;
1964                     try {
1965                         SpObserver.setDBtoInstance("_" + dto.dbid);
1966                         tableType = this.gridService.getSimpleJdbcTemplate().queryForObject("select TABLE_TYPE from information_schema.TABLES where table_name=?", new Object[]{dto.table.split("\\|")[0]}, String.class);
1967                     } catch (DataAccessException e) {
1968                         if (e instanceof EmptyResultDataAccessException) {
1969                             tableType = "";
1970                         } else {
1971                             throw e;
1972                         }
1973
1974                     } finally {
1975                         SpObserver.setDBtoInstance();
1976                     }
1977                     if (dto.conNum != 0 && ("BASE TABLE".equals(tableType) || "VIEW".equals(tableType))) {//表示为基本表,需要有主键
1978                         if ((dto.primeKey == null || "".equalsIgnoreCase(dto.primeKey)))
1979                             throw new ApplicationException(dto.formID + "-" + dto.table + "表没有设置主键!");
1980                     }
1981
1982                     //--------------------
1983                     String hi = this.setGridHight(dto);
1984                     dto.headerDiv = "\n<div id=\"T_" + dto.formID + "\" style=\"margin-left:10px;margin-top:10px;width: 96%; height: " + hi + ";" + ((dto.b497 && dto.PriFormID == 0 || dto.b499 && dto.PriFormID == 0) && dto.xxk == 0 ? "display:none" : "") + "\"></div>" + ("90%".equalsIgnoreCase(hi) ? "" : "<div style=\"height:10px;\"></div>");//增加多表加载时不显示所有格线
1985                     if ((i <= 1 && !dto.muilGrid) || (dto.muilGrid && i < 1 && num < 4)) {//不是多表,只需要生成一个gt-grid   单表,清单表(二表,三表,多表)
1986                         if ((dto.winType != 7 && dto.winType != 77) && (dto.b497 && dto.PriFormID == -1 || dto.b499 && dto.PriFormID == -1)) {//表示496,498多表的第一个表
1987                             int value = Integer.parseInt(dto.tolkey);
1988                             String create = "";
1989                             for (int v = 1; v <= value; v++)
1990                                 create += "create" + v + "(where,flag,cp);";//为了引用其它grid,3表
1991                             strJs = strJs.replaceAll("@create", create);
1992                         } else {
1993                             if (dto.winType == 15) {//表示15类型的第二表需要增加一个定时执行功能,以便处理第三表的过滤问题
1994                                 //create1(where,flag,cp);
1995                                 if (i == 1) {
1996                                     strJs = strJs.replaceAll("@create", "var def=jQuery.Deferred();\n setTimeout(function() {def.resolve('ok');}, 3000);");
1997
1998                                 }
1999                             }
2000                             //前端处理,通过从表调用过滤 避免主表还没加载完的情况 by danaus 2021/1/28 16:05
2001 //                            else if (dto.b497) {//表示多表增加一个定时执行功能,以便处理关联表的过滤问题
2002 //                                strJs = strJs.replaceAll("@create", "setTimeout(function() {mygrid" + setGridNum(dto) + ".setFilter496();}, 3000);");
2003 //                            }
2004                             strJs = strJs.replaceAll("@create", "");
2005
2006                         }
2007                         str = str
2008                                 .replaceAll("@main", strJs)
2009                                 .replaceAll("@head", dto.headerDiv)//DIV
2010                                 .replaceAll("@suggstDiv", dto.sugList.toString())//自动补全
2011                                 .replaceAll("@gridconnum", String.valueOf(dto.conNum));//判断单表用来计算grid高度需要。。。替换grid.jsp里面的@gridconnum
2012                         FileUtil.writeFile(js, root.replaceAll("\\\\", "/") + File.separatorChar + this.setFilePath(path.replaceAll("\\\\", "/"), this.setJsName(dto), pst, dto));//生成新页面js
2013                         FileUtil.writeFile(str, root.replaceAll("\\\\", "/") + File.separatorChar + this.setFilePath(path.replaceAll("\\\\", "/"), fileName[0], pst, dto));//生成新页面
2014                     } else {//多表,整个页面生成多个表格
2015                         if (refgrid != "") refgrid += ",";
2016                         refgrid += ("T_" + dto.formID);//为了引用其它grid,3表
2017                         if (!"".equalsIgnoreCase(setGridNum(dto))) {
2018                             if (dto.winType == 15) {//表示15类型的第二表需要增加一个定时执行功能,以便处理第三表的过滤问题
2019                                 if (i == 2) {
2020                                     strJs = strJs.replaceAll("@create", " var def=jQuery.Deferred(); \n setTimeout(function() { def.resolve('ok');}, 3000);");
2021                                     strJs = strJs.replaceAll("@jspromise", " return def;");
2022                                 }
2023                             }
2024
2025                             strJs = strJs.replaceAll("@create", "");
2026
2027                             //create+="setTimeout(function() {create"+setGridNum()+"(where,flag,cp);}, 1000);";
2028                             if (Integer.parseInt(setGridNum(dto)) == 1 && dto.winType == 15) {
2029                                 // dto.create+=" setTimeout(function() {create"+setGridNum(dto)+"(where,flag,cp);}, 500);";
2030                                 dto.create += " var def=jQuery.Deferred(); setTimeout(function() {def.resolve('ok');}, 2000);";
2031
2032                             } else
2033                                 dto.create += "create" + setGridNum(dto) + "(where,flag,cp);";//为了引用其它grid,3表
2034
2035                         }
2036                         main.append(strJs).append("\n");
2037                         hd.append(dto.headerDiv).append("\n");
2038
2039                         FileUtil.writeFile(js, root.replaceAll("\\\\", "/") + File.separatorChar + this.setFilePath(path.replaceAll("\\\\", "/"), this.setJsName(dto), pst, dto));//生成各个表的js
2040                     }
2041                     dto.gfields = null;
2042                 } catch (Exception e) {
2043                     throw new ApplicationException(e.toString());
2044                 }
2045             }
2046             if (dto.muilGrid && dto.conNum > 1) {//多表,需要把几个gt-grid生成在同一个页面
2047                 String strd = jsp.toString()
2048
2049                         .replaceAll("@main", main.toString().replaceAll("@refgrid", refgrid)).replaceAll("@create", dto.create)
2050                         .replaceAll("@head", hd.toString())//自定义表头
2051                         .replaceAll("@suggstDiv", dto.sugList.toString())//自动补全
2052                         .replaceAll("@gridconnum", String.valueOf(dto.conNum));//判断多表用来计算grid高度需要。。。替换grid.jsp里面的@gridconnum
2053                 FileUtil.writeFile(strd, root.replaceAll("\\\\", "/") + this.setFilePath(path.replaceAll("\\\\", "/"), fileName[0], pst, dto));//生成新页面
2054             }
2055             sb = null;
2056             jsp = null;
2057             main = null;
2058             hd = null;
2059         } catch (DataAccessException e) {
2060             throw new ApplicationException(e.toString());
2061         }
2062     }
2063
2064     /**
2065      * 解决5,9 16,17 8,15的关联生成问题
2066      *
2067      * @param root TODO
2068      **/
2069     private String setFilePath(String p, String name, String root, TreeGridDTO dto) {
2070         StringBuilder sb = new StringBuilder();
2071         if (!dto.b497 || !dto.b499)
2072             root = sb.append("/").append(dto.minID == 0 ? dto.formID : dto.minID).append("/").append(dto.conNum == 0 ? dto.winType : dto.othType).append("/").toString();
2073         return new StringBuilder().append(p).append(root).append(name).toString();
2074     }
2075
2076     /**
2077      * 根据当前grid的次数而生成需要的标记,以区别同一页面不同grid的引用
2078      */
2079     private String setGridNum(TreeGridDTO dto) {
2080         if (dto.b497 || dto.b499)
2081             return dto.PriIndex == 0 ? "" : dto.PriIndex + "";
2082         else
2083             return dto.conNum <= 1 ? "" : (dto.conNum - 1) + "";
2084     }
2085
2086     @Override
2087     public void setTabPage(int type, int height1, String indexs, String tolkey, int formid, int index, TreeGridDTO dto) {
2088         dto.tabPage = type;
2089         dto.gridHeight = height1;
2090         dto.masterKey = indexs;
2091         dto.b497 = true;
2092         dto.tolkey = tolkey;
2093         dto.PriFormID = formid;//取得主功能号里面的排除功能号和字段列表用 by 11-5-28
2094         dto.PriIndex = index;
2095     }
2096
2097     @Override
2098     public Grid getGridInfo(int formid, String type, boolean excel, TreeGridDTO dto) {
2099         Grid grid = new Grid();
2100         this.getTableName(formid, type, dto);//type:"9|0"
2101         grid.setFormID(formid);
2102         grid.setWinType(type);
2103         String ddsave = "";
2104         grid.setExcel(excel);
2105         try {
2106             if (dto.DealAfterDocSave != null && dto.DealAfterDocSave.trim().length() > 0)
2107                 ddsave = EncodeUtil.base64Encode(dto.DealAfterDocSave);
2108         } catch (UnsupportedEncodingException e) {
2109             throw new ApplicationException("加密保存后执行组出错-" + dto.DealAfterDocSave);
2110         }
2111         grid.setDealAfterDocSave(ddsave);
2112         if (dto.ProcGroupafterSavedoc != null && !"".equals(dto.ProcGroupafterSavedoc)) {
2113             grid.setProcGroupafterSavedoc(Integer.parseInt(dto.ProcGroupafterSavedoc));
2114         }
2115         grid.setTrangroup(dto.trangroup);//过账逻辑号
2116         return grid;
2117     }
2118
2119     @Override
2120     public void setXxk(int xxk, TreeGridDTO dto) {
2121         // TODO Auto-generated method stub
2122         dto.xxk = xxk;
2123     }
2124 }