xinyb_
2021-03-13 1a57bc63d1387f6c2da0f6a7fd0731c2756df23a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
package com.yc.service.panel;
 
import com.yc.entity.FormLoadParameterEntity;
import com.yc.factory.FactoryBean;
import com.yc.sdk.shopping.util.SettingKey;
import com.yc.service.BaseService;
import com.yc.service.impl.DBHelper;
import com.yc.utils.SessionKey;
 
import oracle.net.aso.b;
 
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.BadSqlGrammarException;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.sql.SQLException;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
 
/**
 * 
 * @author pengbei
 * 
 */
@Service("PanelManage")
public class PanelManageImpl implements PanelManageDao {
    @Autowired
    SqlDBHelperIfc sqlDBHelperIfc;
    @Autowired
    SystemSettingsDao systemSettingsBo;
    @Autowired
    GfieldApprovedButtonIfc gButtonIfc;
 
    // 针对多表
    private List<Map<String, Object>> multiList = new ArrayList<>();
 
    /**
     * 获得页面上真正显示的Id (不是数据库的列字段了)
     * 
     * @param filed    匹配数控字段的map集合的Key
     * @param mapValue 数据库字段
     * @return 网页的控件Id
     */
    public String getMapsKay(Map<String, Map<String, String>> maplist, String filed, String mapValue) {
        String yeId = "";
        for (String key : maplist.keySet()) {
            if (maplist.get(key).get(filed).trim().equals(mapValue)) {
                yeId = key;
                break;
            }
        }
        return yeId;
    }
 
    /**
     * 加载单据信息
     */
//    @Override
    public List<Map<String, Object>> getFromEnd(String sql, String tableis, String where, int formType,
            HttpServletRequest request) throws Exception {
        HttpSession session = request.getSession();
        sql = getRepSql(sql);
        List<Map<String, Object>> listInfo = null;
        Map<String, Object> mapDoc = null;
        String lookUpSql = "";
        try {
            where = isSpecialChar(where) ? URLEncoder.encode(where, "UTF-8") : where; // xin 2020-5-19 10:14:20
            where = URLDecoder.decode(where, "utf-8");// by danaus 2020/5/1 23:02
        } catch (Exception e) {// 出错表示不需要解码
        }
        if (";22;18;19;7;".indexOf(";" + String.valueOf(formType) + ";") != -1) {// 类型窗体处理
            try {
                listInfo = new ArrayList<Map<String, Object>>();
                where = where.replaceAll("like", ";pb#").replaceAll("=", ";pb#").replace("@~", "").replaceAll("'", "");
                String[] valueS = where.split("and");
                String[] cols = null;
                HashMap<String, Object> map = new HashMap<String, Object>();
                for (int i = 0; i < valueS.length; i++) {
                    cols = valueS[i].split(";pb#");
                    if (cols.length > 1) {
                        map.put(cols[0].trim().toLowerCase(), cols[1].trim());
                    } else {
 
                    }
                }
                map.put("doc_size", 0);// 让其赋默认值
                listInfo.add(map);
            } catch (ArrayIndexOutOfBoundsException e) {// 数组越界异常捕获
                throw e;
            } catch (Exception e) {
                throw e;
            }
        } else {
            try {
                lookUpSql = sql + tableis + ((where != null && !where.equals("")) ? " where " + where : "");
                lookUpSql = lookUpSql.replace("!", "");
                listInfo = sqlDBHelperIfc.getHashMapObj(lookUpSql);// 获取对应单号数据
                mapDoc = (listInfo != null && listInfo.size() > 0) ? listInfo.get(0) : new HashMap<String, Object>();
                Pattern pattern = Pattern.compile("\\w+doccode\\s*=");
                if (";5;8;16;496;498;".indexOf(";" + String.valueOf(formType) + ";") != -1) {// 加入同一筛选条件下的上下单号
                    if (listInfo.size() > 0) {
                        String nextSql = "";
                        Matcher matcher = pattern.matcher(lookUpSql.toLowerCase());
                        if (matcher.find()) {
                            lookUpSql = lookUpSql.toLowerCase().replace(matcher.group(), "doccode=");
                        }
                        StringBuffer docAndDoc = new StringBuffer();
                        // 去掉空格,by danaus 2020/12/3 16:02
                        nextSql = lookUpSql.toLowerCase().replaceAll("doccode\\s*=\\s*'.*?'", "1=1")
                                .replaceFirst("top\\s*\\d*\\s*\\*", "top 1 doccode ") + " order by doccode asc ";
                        docAndDoc.append(getSqlDoc(nextSql, session));// 第一单
 
                        nextSql = lookUpSql.toLowerCase().replaceAll("doccode\\s*=\\s*", "doccode < ")
                                .replaceFirst("top\\s*\\d*\\s*\\*", "top 1 doccode ") + " order by doccode desc ";
                        docAndDoc.append(";").append(getSqlDoc(nextSql, session));// 上一单
 
                        nextSql = docAndDoc.toString();
                        mapDoc.put("updoc", nextSql);
                        docAndDoc.delete(0, docAndDoc.length());
 
                        nextSql = lookUpSql.toLowerCase().replaceAll("doccode\\s*=\\s*\\S*", "1=1")
                                .replaceFirst("top\\s*\\d*\\s*\\*", "top 1 doccode ") + " order by doccode desc ";
                        docAndDoc.append(getSqlDoc(nextSql, session));// 最后一单
 
                        nextSql = lookUpSql.toLowerCase().replaceAll("doccode\\s*=\\s*", "doccode > ")
                                .replaceFirst("top\\s*\\d*\\s*\\*", "top 1 doccode ") + " order by doccode asc ";
                        docAndDoc.append(";").append(getSqlDoc(nextSql, session));// 下一单
                        nextSql = docAndDoc.toString();
                        mapDoc.put("nextdoc", nextSql);
                        docAndDoc = null;
                    } else {
                        if (where.indexOf("1=2") == -1) {// 是否是新单据状态
                            // 上面的方法没有查到该单据并且不是新单据后,这里执行是否有权限查看或单据已经不存在的返回提示---xin
                            // 2015-9-22 14:43:37
                            try {
                                List<Map<String, Object>> isDoc = null;
                                String w = "1=2";
                                Pattern pattern1 = Pattern.compile("and\\s*\\(\\s*");// 去掉and后面在()里的权限条件
                                Matcher matcher = pattern1.matcher(where.toLowerCase());
                                if (matcher.find()) {
                                    w = where.toLowerCase().split("and\\s*\\(\\s*")[0];
                                } else {
                                    pattern1 = Pattern.compile("doccode\\s*=\\s*\\S*");
                                    matcher = pattern1.matcher(where.toLowerCase());
                                    if (matcher.find()) {
                                        w = where;
                                    }
                                }
                                String isDoccode = sql + tableis + " where " + w;// 组装没有权限限制的sql
                                isDoccode = isDoccode.replace("!", "");
                                isDoc = sqlDBHelperIfc.getHashMapObj(isDoccode);// 查询是否存在数据
                                if (isDoc != null && isDoc.size() > 0) {// 返回提示
                                    throw new Exception("提示:你没有权限查看【" + w.split("'")[1] + "】的内容,请联系制单人【"
                                            + DBHelper.getValue(isDoc.get(0), "entername") + "】");
                                }
                            } catch (Exception e) {
                                throw e;
                            }
                        }
                        // if (tableis.equals("_sys_formid_Help")) {
                        // }
                        mapDoc.put("updoc", ";");// mapDoc 中都为小写key
                        mapDoc.put("nextdoc", ";");
                    }
                }
                mapDoc.put("doc_size", listInfo.size());// 判断单据需要
                mapDoc.put("yic", "t");// 这一个字段已经没有用处,新的模板里已经删除。这个字段以后需要删除掉 xin
                                        // 2019-3-1 10:10:44
                listInfo.clear();
                listInfo.add(mapDoc);
            } catch (SQLException | BadSqlGrammarException ee) {
                throw ee;
            } catch (Exception e) {
                throw e;
            } finally {
            }
        }
        return listInfo;
    }
 
    /**
     * 获得单号
     * 
     * @param sqlString 获得单号sql
     * @return 单号
     * @throws SQLException
     */
    private String getSqlDoc(String sqlString, HttpSession session) throws SQLException {
        List<Map<String, Object>> listInfoDoc = null;
        try {
            // SpObserver.setDBtoInstance("_" +
            // session.getAttribute(SessionKey.DATA_BASE_ID));
            listInfoDoc = sqlDBHelperIfc.getHashMapObj(sqlString);
        } catch (Exception e) {
            throw e;
        } finally {
            // SpObserver.setDBtoInstance();
        }
        return listInfoDoc.size() > 0
                ? (listInfoDoc.get(0).get("doccode") == null ? "" : listInfoDoc.get(0).get("doccode").toString())
                : "";
    }
 
    /**
     * 替换掉sql语句中如:&formid&=9801之类的&formid&写法 此时直接可以为 formid 解决设置冲突而这样写时的错误
     * 
     * @param sql
     * @return
     */
    private String getRepSql(String sql) {
        Map<String, String> parm = new HashMap<String, String>();
        List<String> list = DBHelper.getStrRepInfo(sql, "&");
        boolean bol = ((sql.indexOf("'&") != -1 && sql.indexOf("&'") != -1) ? true : false);
        for (String id : list) {
            parm.put((bol ? "'" : "") + "&" + id + "&" + (bol ? "'" : ""), id);
        }
        sql = DBHelper.getRep(parm, sql);
        return sql;
    }
 
    /**
     * 复单的时候进入
     */
    @Override
    public List<Map<String, Object>> getFromEnd(String sql, String tableis, String where, int formType, String copy,
            HttpServletRequest request) throws Exception {
        List<Map<String, Object>> lics = new ArrayList<Map<String, Object>>();
        List<Map<String, Object>> lic = new ArrayList<Map<String, Object>>();
        try {
            lic = getFromEnd(sql, tableis, where, formType, request);
            if (copy.equals("1") && DBHelper.getValueInt(lic.get(0), "formid") != 0) {// 复单时候进入
                lics = systemSettingsBo.selectAll(Integer.parseInt(lic.get(0).get("formid").toString()), 0);
                @SuppressWarnings("rawtypes")
                Iterator iter = lic.get(0).entrySet().iterator();
                while (iter.hasNext()) {
                    @SuppressWarnings("rawtypes")
                    Map.Entry entry = (Map.Entry) iter.next();
                    Object key = entry.getKey();
                    for (int c = 0; c < lics.size(); c++) {
                        if ((key.toString().toLowerCase())
                                .equals(lics.get(c).get("fieldid").toString().toLowerCase())) {
                            if (lics.get(c).get("iscopyexclude") == null) {//复单时是否排除
                                lics.get(c).put("iscopyexclude", "0");
                            }
                            if (Integer.parseInt(lics.get(c).get("iscopyexclude").toString()) == 1) {
                                lic.get(0).put(key.toString(), "");
                            }
                            break;
                        }
                    }
                }
            }
            lic.get(0).put("doccode", "");
            lic.get(0).put("docstatus", 0);
        } catch (Exception e) {
            throw new Exception("复单出错:" + e.getMessage());
        }
        return lic;
    }
 
    /**
     * 返回单据状态
     * 
     */
    @Override
    public String getDocstatus(String where, int formid, String tabs, HttpServletRequest request) throws Exception {
        String docStatus = "0";
        String docSql = "select top 1 docstatus from " + tabs + " where " + where;
        try {
            List<Map<String, Object>> docList = sqlDBHelperIfc.getHashMapObj(docSql);
            docStatus = DBHelper.getValueInt(docList.get(0), "docstatus") + "";
        } catch (Exception e) {
            return docStatus;
        } finally {
        }
        return docStatus;
    }
 
    @Override
    public int getCancelButton(String sql) {
        BaseService b = (BaseService) FactoryBean.getBean("BaseService");
        int ex = 0;
        // try{
        ex = b.getSimpleJdbcTemplate().queryForObject(sql, Integer.class);
        // }catch(Exception e){
        // }
        return ex;
    }
 
    /**
     * 针对496全是面板加载问题 wherePan 加载时得到的条件 where 9770功能号设置的关联关系 map 各个面板的集合 以功能号为key
     * map为值
     */
    @Override
    public String getMultiTableWhere(String wherePan, int FT, String FK, String SeekGroupID, Boolean bol)
            throws Exception {
        try {
            if (bol) {
                for (Map<String, Object> docMap : multiList) {
                    if (DBHelper.getValueInt(docMap, "formid") == FT) {
                        wherePan = SeekGroupID + "='" + DBHelper.getValue(docMap, FK) + "'";
                        break;
                    }
                }
            } else {
                multiList.clear();
            }
        } catch (Exception e) {
            return wherePan;
        } finally {
 
        }
        return wherePan;// 返回关联关系后的where条件。
    }
 
    @Override
    public void getMultiTableList(Map<String, Object> multi) {
        this.multiList.add(multi);
    }
 
    /**
     * 判断是否含有特殊字符
     *
     * @param str
     * @return true为包含,false为不包含
     */
    public static boolean isSpecialChar(String str) {
        String regEx = "[ _`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]|\n|\r|\t";
        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(str);
        return m.find();
    }
 
    /**
     * 加载功能号数据信息  xin 2021-1-26 09:32:34
     */
    @Override
    public List<Map<String, Object>> getFormLoad(FormLoadParameterEntity formLoad) throws Exception {
        try {
            List<Map<String, Object>> formList = new ArrayList<>();
            Map<String, Object> map = new HashMap<String, Object>();
            // 特定类型窗体处理
            if (";22;18;19;7;".indexOf(";" + formLoad.getFormType() + ";") != -1 && !formLoad.isHasCopy()) {
                try {
                    String where = formLoad.getSqlWhere();
                    where = where.replaceAll("like", ";pb#").replaceAll("=", ";pb#");
                    where = where.replaceAll("@~", "").replaceAll("'", "");
                    String[] s = where.split("and");
                    String[] p = null;
                    for (int i = 0; i < s.length; i++) {
                        p = s[i].split(";pb#");
                        if (p.length > 1) {
                            map.put(p[0].trim().toLowerCase(), p[1].trim());
                        } else {
 
                        }
                    }
                    map.put("doc_size", 0);// 让其赋默认值
                    formList.add(map);
                    return formList;
                } catch (ArrayIndexOutOfBoundsException e) {
                    throw new Exception("加载功能号数据信息【" + formLoad.getFormType() + "】类型时,条件值出现数组越界。");
                } catch (Exception e) {
                    throw new Exception("加载功能号数据信息【" + formLoad.getFormType() + "】类型时出错。");
                }
            }
            boolean hasData = ((";5;8;16;496;498;".indexOf(";" + formLoad.getFormType() + ";") != -1) ? true : false);// 是否为单据类型数据
            // 表示已读 xin 2021-1-26 16:29:16
            String readSql = "set nocount on \n "
                    + "update a set a.isread=1 from t219001 a where a.usercode='"
                    + formLoad.getSession().getAttribute(SessionKey.USERCODE) + "' " + "and a.formid="
                    + formLoad.getFormId() + " and a.formtype=" + formLoad.getFormType() + " and a.doccode='"
                    + formLoad.getDoccode() + "' \n ";
 
            String sql = formLoad.getSql() + formLoad.getTableName()
                    + (!"".equals(formLoad.getSqlWhere()) ? " where " + formLoad.getSqlWhere() : "");
            sql = sql.replace("!", "");
            List<Map<String, Object>> list = sqlDBHelperIfc.getHashMapObj((hasData ? readSql : "") + sql);// 获取对应单号数据信息
            if (list != null && list.size() > 0) {// 查询到单据信息的时候
                map.putAll(list.get(0));// 把数据信息赋给map
                // 如果是复单进入
                if (formLoad.isHasCopy() && formLoad.getFormId() != 0) {
                    List<Map<String, Object>> fieldList = systemSettingsBo.selectAll(formLoad.getFormId(), 0);
                        for(Map<String, Object> fMap : fieldList) {
                                //iscopyexclude表示复单时是否排除这个字段,1表示需要排除掉
                                if(DBHelper.getValueInt(fMap, "iscopyexclude")==1) {
                                    String value=DBHelper.getValue(map, DBHelper.getValue(fMap, "fieldid"));
                                    if(!"".equals(value)){
                                        map.put(DBHelper.getValue(fMap, "fieldid").toLowerCase(), "");//直接赋空值
                                    }
                                }
                            }
                    map.put("doccode", "");
                    map.put("docstatus", 0);
                    formList.add(map);
                    return formList;
                }
                // 是单据类型数据
                if (hasData) {
                    String nextSql = "";
                    Pattern pattern = Pattern.compile("\\w+doccode\\s*=");
                    Matcher matcher = pattern.matcher(sql.toLowerCase());
                    if (matcher.find()) {
                        sql = sql.toLowerCase().replace(matcher.group(), "doccode=");
                    }
                    StringBuffer docAndDoc = new StringBuffer();
                    // 去掉空格,by danaus 2020/12/3 16:02
                    nextSql = sql.toLowerCase().replaceAll("doccode\\s*=\\s*'.*?'", "1=1")
                            .replaceFirst("top\\s*\\d*\\s*\\*", "top 1 doccode ") + " order by doccode asc ";
                    docAndDoc.append(getSqlDoc(nextSql, formLoad.getSession()));// 第一单
 
                    nextSql = sql.toLowerCase().replaceAll("doccode\\s*=\\s*", "doccode < ")
                            .replaceFirst("top\\s*\\d*\\s*\\*", "top 1 doccode ") + " order by doccode desc ";
                    docAndDoc.append(";").append(getSqlDoc(nextSql, formLoad.getSession()));// 上一单
 
                    nextSql = docAndDoc.toString();
                    map.put("updoc", nextSql);
                    docAndDoc.delete(0, docAndDoc.length());
 
                    nextSql = sql.toLowerCase().replaceAll("doccode\\s*=\\s*\\S*", "1=1")
                            .replaceFirst("top\\s*\\d*\\s*\\*", "top 1 doccode ") + " order by doccode desc ";
                    docAndDoc.append(getSqlDoc(nextSql, formLoad.getSession()));// 最后一单
 
                    nextSql = sql.toLowerCase().replaceAll("doccode\\s*=\\s*", "doccode > ")
                            .replaceFirst("top\\s*\\d*\\s*\\*", "top 1 doccode ") + " order by doccode asc ";
                    docAndDoc.append(";").append(getSqlDoc(nextSql, formLoad.getSession()));// 下一单
                    nextSql = docAndDoc.toString();
                    map.put("nextdoc", nextSql);
                }
            }else {// 查询不到单据信息
                if (!"".equals(formLoad.getDoccode())) {// 有单号。但是查询不到数据
                    sql = formLoad.getSql() + formLoad.getTableName() + " where doccode='" + formLoad.getDoccode()
                            + "'";
                    List<Map<String, Object>> docList = sqlDBHelperIfc.getHashMapObj(sql);// 获取对应单号数据信息
                    if (docList != null && docList.size() > 0) {// 单号能查询到数据,说明之前的查询设置了权限。当前的账号没权限查看
                        throw new Exception("提示:你没有权限查看【" + formLoad.getDoccode() + "】的内容,请联系制单人【"
                                + DBHelper.getValue(docList.get(0), "entername") + "】");
                    }
                }
            }
            map.put("doc_size", list.size());// 判断单据需要
            formList.add(map);
            return formList;
        } catch (Exception e) {
            throw e;
        }
    }
    
    /**
     * OA审核加载新界面数据 xin 2021-2-1 09:33:18
     * @param formId
     * @param docState
     * @param doccode
     * @param request
     * @return
     * @throws Exception
     */
    public List<Object> getOAVerifyMethod(int formId, int docState, String doccode,
            HttpServletRequest request) throws Exception {
        try {
            List<Object> lMap = new ArrayList<>();
            List<Map<String, Object>> bList = gButtonIfc.getTopOaButton(formId);// 获取审核按钮集合
            if (bList != null && bList.size() > 0) {
                List<List<Map<String, Object>>> oList = new ArrayList<>();// 存放排序好的审核按钮
                List<Map<String, Object>> listInfo = new ArrayList<>();// 存放当前单据的详细信息数据
                String but = "declare ";// 声明属性
                String sql = "";// 查询当前单据能显示出来的审核按钮
                String gets = "";// 返回声明的属性值
                String HDTable = "";// 当前单据查询的表
                String upId = "";
                for (Map<String, Object> butMap : bList) { // 这里对审核按钮进行排序组装处理
                    String id = DBHelper.getValue(butMap, "fieldid");
                    if (!upId.equals(id)) {
                        List<Map<String, Object>> fList = new ArrayList<>();
                        fList = bList.stream().filter(b -> id.equals(b.get("fieldid"))).collect(Collectors.toList());
                        if (fList.size() > 0) {
                            oList.add(fList);
                            upId = id;
                        }
                    }
                }
                Map<String, Object> sysMap = systemSettingsBo.getFormIdInTable(formId);// 获取审核的单据表名
                if (sysMap != null) {
                    HDTable = DBHelper.getValue(sysMap, "HDTable").trim();// 获取表名
                    // 获取当前单据的详细信息数据
                    listInfo = sqlDBHelperIfc
                            .getHashMapObj("select * from " + HDTable + " where doccode='" + doccode + "'");
                }
                // 遍历组装需要查询的审核按钮
                for (int i = 0; i < bList.size(); i++) {
                    Map<String, Object> map = bList.get(i);
                    but += "@but" + DBHelper.getValue(map, "buttonID") + " int";
                    sql += "@but" + DBHelper.getValue(map, "buttonID") + "= (case when "
                            + (DBHelper.getValueInt(map, "editStatus") == 0 ? ""
                                    : "DocStatus in (" + DBHelper.getValueInt(map, "editStatus") + ") and ")
                            + (!"".equals(DBHelper.getValue(map, "showItemExpression"))
                                    ? DBHelper.getValRepShi(formId, DBHelper.getValue(map, "showItemExpression"),
                                            request.getSession(), listInfo.get(0), false)// 这里需要对设置有会话值或替换值进行处理
                                    : "curchecker like '%," + request.getSession().getAttribute(SessionKey.USERCODE)
                                            + ",%'")
                            + " then 1 else 0 end ) \n";
                    gets += "@but" + DBHelper.getValue(map, "buttonID") + " as '" + DBHelper.getValue(map, "buttonID")
                            + "'";
                    if ((i + 1) < bList.size()) {
                        but += ",";
                        sql += ",";
                        gets += ",";
                    }
                }
                // 组装sql语句
                sql = but + "\n set nocount on \n select " + sql + " from " + HDTable + " where DocCode='" + doccode
                        + "' \n" + "select " + gets;
                // 获取到当前单据显示出来的审核按钮 。0表示不需要显示,1表示要显示。
                List<Map<String, Object>> listbut = sqlDBHelperIfc.getHashMapObj(sql);
                if (listbut != null && listbut.size() > 0) {
                    // 组装
                    lMap = getButList(oList, listbut.get(0), listInfo.get(0), request);
                }
                return lMap;
            } else {
                throw new Exception("获取不到当前单据的审核按钮信息。");
            }
        } catch (Exception e) {
            throw e;
        }
    }
    
    /**
     * 组装审核按钮
     * @param oList
     * @param mapbut
     * @param mapInfo
     * @param request
     * @return
     */
    private List<Object> getButList(List<List<Map<String, Object>>> oList,Map<String, Object> mapbut, Map<String, Object> mapInfo,
            HttpServletRequest request) throws SQLException {
        try {
            String userCode = (String) request.getSession().getAttribute(SessionKey.USERCODE);
            List<Object> buttons = new ArrayList<>();
            List<Object> nameList = new ArrayList<>();
            List<Object> oaButList = new ArrayList<>();
            List<Object> dataList = new ArrayList<>();
            Boolean bol = false;
            for (List<Map<String, Object>> butList : oList) {
                List<String> name = new ArrayList<>();
                List<Object> clickList = new ArrayList<>();
                List<Object> date = new ArrayList<>();
                List<Map<String, Object>> but = new ArrayList<>();
                String ccusercodes = "";
                String id="";
                for (Map<String, Object> buttonMap : butList) {
                    int state = DBHelper.getValueInt(mapbut, DBHelper.getValue(buttonMap, "buttonID"));// 按状态,0表示不显示,1表示显示。
                    if (state == 1) {// 显示状态进入
                        // 是当前审核人的话 bol=true
                        bol = (DBHelper.getValueInt(buttonMap, "editStatus") == DBHelper.getValueInt(mapInfo,
                                "DocStatus") ? true : bol);
                        // 当前审核人审核结束后,但是撤销按钮有显示的话 bol=true
                        if(DBHelper.getValue(mapInfo, "CurChecked").contains(userCode) && !DBHelper.getValue(mapInfo, "CurChecker").contains(userCode)) {
                            bol=true;
                        }
                        if (name.size() == 0) {
                            String namev=DBHelper.getValue(buttonMap, "fieldName");
                            if(namev.indexOf("!")!=-1){//有查询
                                String sql=DBHelper.getValRepShi(namev, request.getSession(), mapInfo, false);
                                List<Map<String, Object>> listbut = sqlDBHelperIfc.getHashMapObj(sql.replace("!", ""));
                                name.add(DBHelper.getValue(listbut.get(0), ""));// 显示的审核名
                            }else{
                                name.add(namev);// 显示的审核名
                            }
                        }
                        if (clickList.size() == 0) {// 显示当前审核页卡的按钮
                            clickList.add((bol ? "layui-show" : ""));
                            id=DBHelper.getValue(buttonMap, "fieldid").toLowerCase();
                            clickList.add(id);// 字段
                            ccusercodes = DBHelper.getValue(buttonMap, "fieldid").toLowerCase().replace("memo",
                                    "ccusercodes");
                            clickList.add(ccusercodes);// 抄送字段
                        }
                        // 查询按钮集合中是否有当前字段,有则在此上加按钮
                        String onclick = "";
                        String pawString = (DBHelper.getValueInt(buttonMap, "isShowPwdEdit") == 1) ? "true" : "false";// 弹出密码框
                        String ReturnCurChecker = DBHelper.getValue(buttonMap, "ReturnCurChecker");
                        String ReturnCurCheckerName = DBHelper.getValue(buttonMap, "ReturnCurCheckerName");
                        boolean isInspection = (DBHelper.getValueInt(buttonMap, "isInspection") == 1 ? true : false);// 是否禁止必录检查
                        String getBtnStr = pawString + ",'" + DBHelper.getValueInt(buttonMap, "formid") + "'," + "'"
                                + SettingKey.getHostUrl(request) + "/',this," + isInspection + ",'"
                                + DBHelper.getValue(buttonMap, "ExternalURL") + "',"
                                + DBHelper.getValueInt(buttonMap, "UrlShowLocation") + ","
                                + DBHelper.getValue(buttonMap, "buttonID");
                        String url1 = DBHelper.getValueInt(buttonMap, "FT") + "/"
                                + DBHelper.getValueInt(buttonMap, "FTFormType") + "/index.jsp";
                        switch (DBHelper.getValueInt(buttonMap, "SelectChecker")) {
                        case 0:
                            onclick = "window.parent.getBtn(" + getBtnStr + ");";
                            break;
                        case 1:
                            onclick = "window.parent.createPopSelect('" + ReturnCurChecker + "','"
                                    + ReturnCurCheckerName + "'," + getBtnStr + ");";
                            break;
                        case 2:
                            onclick = "window.parent.mulChoice2('" + DBHelper.getValue(buttonMap, "FK") + "','"
                                    + DBHelper.getValue(buttonMap, "SeekGroupID") + "','"
                                    + DBHelper.getValue(buttonMap, "sPremissField") + "','"
                                    + DBHelper.getValue(buttonMap, "dPremissField") + "','"
                                    + DBHelper.getValue(buttonMap, "FKeFilter") + "','" + SettingKey.getHostUrl(request)
                                    + "/app'+spellPath+'" + url1 + "'," + getBtnStr + ");";
                            break;
                        default:
                            break;
                        }
                        String par = DBHelper.getValue(buttonMap, "fieldid").toLowerCase() + ";"
                                + DBHelper.getValue(buttonMap, "docitem");
                        Map<String, Object> parMap = new HashMap<>();
                        parMap.put("click",
                                "getccusercodes('"+id+"','" + ccusercodes + "');window.parent.setOa('" + par + "');" + onclick);
                        parMap.put("butname", DBHelper.getValue(buttonMap, "ButtonName"));
                        parMap.put("iocn", getIocnText(DBHelper.getValue(buttonMap, "ButtonName")));
                        parMap.put("id", DBHelper.getValueInt(buttonMap, "buttonID"));
                        but.add(parMap);
                    }
                    if (date.size() == 0) {// 显示流程跟踪
                        String namev=DBHelper.getValue(buttonMap, "fieldName");
                        if(namev.indexOf("!")!=-1){//有查询
                            String sql=DBHelper.getValRepShi(namev, request.getSession(), mapInfo, false);
                            List<Map<String, Object>> listbut = sqlDBHelperIfc.getHashMapObj(sql.replace("!", ""));
                            date.add(DBHelper.getValue(listbut.get(0), ""));
                        }else{
                            date.add(namev);
                        }
                        String userName = DBHelper.getValue(mapInfo,
                                DBHelper.getValue(buttonMap, "fieldid").toLowerCase().replace("memo", "username"));
                        String dates = DBHelper.getValue(mapInfo,
                                DBHelper.getValue(buttonMap, "fieldid").toLowerCase().replace("memo", "date"));
                        date.add(bol ? "" : userName);
                        date.add(bol ? "" : dates);
                        date.add(bol ? "" : "process-active");
                        date.add(bol ? "" : DBHelper.getValue(mapInfo, DBHelper.getValue(buttonMap, "fieldid")));
                    }
                }
                if (name != null && name.size() == 1) {
                    name.add((bol ? "layui-this" : ""));// 显示当前审核页卡
                    nameList.add(name);
                }
                if (clickList != null && clickList.size() > 0) {
                    clickList.add(but);
                    oaButList.add(clickList);
                }
                if (date != null && date.size() > 0) {
                    dataList.add(date);
                }
            }
            // 下面的顺序不能乱,会影响界面显示
            buttons.add(nameList);
            buttons.add(oaButList);
            buttons.add(dataList);
            return buttons;
        } catch (Exception e) {
            throw e;
        }
    }
    
    /**
     * 获取审核按钮图标
     * @param docitem
     * @return
     */
    private String getIocnText(String docitem) {
        String iocn = "";
        if(docitem.contains("通过")){
            iocn="icon-tongguo";//通过
        }else if(docitem.contains("驳回")){
            iocn="icon-bohui";//驳回
        }else if(docitem.contains("驳回上")){
            iocn="icon-bohuidao";//驳回上一级
        }else if(docitem.contains("撤销")){
            iocn="icon-chexiao";//撤销
        }else if(docitem.contains("保存")){
            iocn="icon-baocun";//保存
        }
//        switch (docitem) {
//        case 10:
//            iocn="icon-tongguo";//通过
//            break;
//        case 20:
//            iocn="icon-bohui";//驳回
//            break;
//        case 30:
//            iocn="icon-bohuidao";//驳回上一级
//            break;
//        case 40:
//            iocn="icon-chexiao";//撤销
//            break;
//        case 50:
//            iocn="icon-baocun";//保存
//            break;
//        default:
//            break;
//        }
        return iocn;
    }
}