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