xinyb
2024-07-25 180c20a90d12c9dcfeff1e3b26603f54b9d4c2d9
src/com/yc/service/panel/PanelManageImpl.java
@@ -1,19 +1,24 @@
package com.yc.service.panel;
import com.yc.api.bean.FormInfo;
import com.yc.api.controller.ApiController;
import com.yc.entity.FormLoadParameterEntity;
import com.yc.factory.FactoryBean;
import com.yc.sdk.password.action.ChangePassword;
import com.yc.sdk.shopping.util.SettingKey;
import com.yc.service.BaseService;
import com.yc.service.impl.DBHelper;
import com.yc.service.tree.TreeIfc;
import com.yc.utils.EncodeUtil;
import com.yc.utils.SessionKey;
import oracle.net.aso.b;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
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.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.net.URLDecoder;
import java.net.URLEncoder;
@@ -24,646 +29,757 @@
import java.util.stream.Collectors;
/**
 *
 * @author pengbei
 *
 */
@Service("PanelManage")
public class PanelManageImpl implements PanelManageDao {
   @Autowired
   SqlDBHelperIfc sqlDBHelperIfc;
   @Autowired
   SystemSettingsDao systemSettingsBo;
   @Autowired
   GfieldApprovedButtonIfc gButtonIfc;
    @Autowired
    SqlDBHelperIfc sqlDBHelperIfc;
    @Autowired
    SystemSettingsDao systemSettingsBo;
    @Autowired
    GfieldApprovedButtonIfc gButtonIfc;
   // 针对多表
   private List<Map<String, Object>> multiList = new ArrayList<>();
    @Autowired
    ApiController apiController;
    @Autowired
    TreeIfc treeIfc;
    // 针对多表
    private Map<String, List<Map<String, Object>>> multiList = new HashMap<>();
   /**
    * 获得页面上真正显示的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;
   }
    /**
     * 获得页面上真正显示的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;
    }
   /**
    * 加载单据信息
    */
    /**
     * 针对20,30窗体加载面板数据时候做排序
     * @param sql
     * @param tableis
     * @param where
     * @param formId
     * @param formType
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public List<Map<String, Object>> getFromEndOrder(String sql, String tableis, String where, Integer formId , Integer formType,
                                                     HttpServletRequest request, HttpServletResponse response) throws Exception {
        Integer treeFormId = formId;
        //通过功能号查询树功能号
        List<Map<String, Object>> list = treeIfc.getTreeSetByFormid("top 1 treeformid ", formId + "");
        if (list != null && list.size() > 0) {
            treeFormId = MapUtils.getInteger(list.get(0), "treeformid");
        }
        FormInfo info = new FormInfo();
        info.setFormid(treeFormId);
        info.setWintype("20@p@0");
        Map<String, String> map = apiController.getPrimKey(info, request, response);
        if (map != null && !map.isEmpty()) {
            String sortCols = MapUtils.getString(map, "sortCols");
            Integer sortTypes = MapUtils.getInteger(map, "sortTypes");
            where = (StringUtils.isBlank(where) ? " 1=1 " : where);
            where += " order by " + sortCols + " " + (sortTypes == 1 ? "desc" : "");
        }
        return getFromEnd(sql, tableis, where, formType, request);
    }
    /**
     * 加载单据信息
     */
//   @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 {
    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
            where = EncodeUtil.replaceUrlChar(where);//解码 xin 2022-6-27 10:26:00
        } catch (Exception e) {// 出错表示不需要解码
        }
        //10窗体是where条件查询,不需要放到这里,直接在下面进行查询返回结果,如果返回空,那么检查sql的查询表是否正确, xin 2022-12-26 14:29:45
        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));// 第一单
                    }
                }
                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*=");
                boolean isMasterFormId = false;
                if (";16;".indexOf(";" + String.valueOf(formType) + ";") != -1) {//针对496多表类型的处理(子功能号不需要上下单导航) xin 2022-5-16 10:08:25
                    String isMaster = (String) request.getAttribute("isMasterFormId");
                    if (StringUtils.isNotBlank(isMaster) && "true".equalsIgnoreCase(isMaster)) {
                        isMasterFormId = true;
                    }
                }
                if (";5;8;16;496;498;".indexOf(";" + String.valueOf(formType) + ";") != -1 && !isMasterFormId) {// 加入同一筛选条件下的上下单号
                    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 = 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 = 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*\\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;
   }
                        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;
                            }
                        }
                        mapDoc.put("updoc", ";");// mapDoc 中都为小写key
                        mapDoc.put("nextdoc", ";");
                    }
                }
                //处理设置了权限字段并且值为0 需要值加密
                for (String key : mapDoc.keySet()) {
                    if (key.indexOf("_expr") != -1) {
                        String expr = (String) mapDoc.get(key);
                        if (StringUtils.isNotBlank(expr) && expr.equals("0")) {//权限值是0进行处理
                            String id = key.split("_expr")[0];
                            String value = (String) mapDoc.get(id);
                            if (StringUtils.isNotBlank(value)) {
                                mapDoc.put(id, ChangePassword.getEncryptPassword(value));//加密后添加到集合内
                            }
                        }
                    }
                }
                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())
            : "";
   }
    /**
     * 获得单号
     *
     * @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;
   }
    /**
     * 替换掉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 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 String getDocstatus(String where, int formid, String tabs, HttpServletRequest request) throws Exception {
        String docStatus = "0";
        String docSql = "set nocount on ; 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;
   }
    @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 {
    /**
     * 针对496全是面板加载问题 wherePan 加载时得到的条件 where 9770功能号设置的关联关系 map 各个面板的集合 以功能号为key
     * map为值
     */
    @Override
    public String getMultiTableWhere(HttpServletRequest request, String wherePan, int FT, String FK, String SeekGroupID, Boolean bol)
            throws Exception {
        try {
            if (bol) {
                if (multiList.get(request.getRequestedSessionId()) != null) {
                    for (Map<String, Object> map : multiList.get(request.getRequestedSessionId())) {
                        if (DBHelper.getValueInt(map, "formid") == FT) {
                            wherePan = SeekGroupID + "='" + DBHelper.getValue(map, FK) + "'";
                            break;
                        }
                    }
                }
                if (wherePan.toLowerCase().indexOf("and") != -1) {
                    wherePan = wherePan.split("and")[0];
                }
            }
        } catch (Exception e) {
            return "1==2";
        } finally {
      }
      return wherePan;// 返回关联关系后的where条件。
   }
        }
        return wherePan;// 返回关联关系后的where条件。
    }
   @Override
   public void getMultiTableList(Map<String, Object> multi) {
      this.multiList.add(multi);
   }
    @Override
    public void getMultiTableList(HttpServletRequest request, Map<String, Object> docMap, boolean bol) {
        if (bol) {
            if (multiList.get(request.getRequestedSessionId()) == null) {
                List<Map<String, Object>> list = new ArrayList<>();
                list.add(docMap);
                multiList.put(request.getRequestedSessionId(), list);
            } else {
                multiList.get(request.getRequestedSessionId()).add(docMap);
            }
        } else {
            multiList.remove(request.getRequestedSessionId());
        }
    }
   /**
    * 判断是否含有特殊字符
    *
    * @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();
   }
    /**
     * 旧版本 后期删
     */
    @Override
    public String getMultiTableWhere(String wherePan, int FT, String FK, String SeekGroupID, Boolean bol)
            throws Exception {
        try {
            if (bol) {
                if (wherePan.toLowerCase().indexOf("and") != -1) {
                    wherePan = wherePan.split("and")[0];
                }
            }
        } catch (Exception e) {
            return "1==2";
        } finally {
   /**
    * 加载功能号数据信息  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 {
        }
        return wherePan;// 返回关联关系后的where条件。
    }
                  }
               }
               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 ";
    /**
     * 旧版本 后期删
     */
    @Override
    public void getMultiTableList(Map<String, Object> docMap) {
         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()));// 上一单
    /**
     * 判断是否含有特殊字符
     *
     * @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();
    }
               nextSql = docAndDoc.toString();
               map.put("updoc", nextSql);
               docAndDoc.delete(0, docAndDoc.length());
    /**
     * 加载功能号数据信息(目前5类型窗体在调用)  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 {
               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()));// 最后一单
                        }
                    }
                    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,ReadDateTime=getdate() 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 ";
               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);// 抄送字段
                     clickList.add(DBHelper.getValueInt(buttonMap, "isshowccusercodes"));//是否显示抄送
                  }
                  // 查询按钮集合中是否有当前字段,有则在此上加按钮
                  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", DBHelper.getValue(buttonMap, "iconpath"));
                  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;
      }
   }
            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()
                            + "'";
                    sql = sql.replace("!", "");
                    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") + "】");
                    }
                }
            }
            //处理设置了权限字段并且值为0 需要值加密 xin 2024-5-23 09:48:51
            for (String key : map.keySet()) {
                if (key.indexOf("_expr") != -1) {
                    String expr = (String) map.get(key);
                    if (StringUtils.isNotBlank(expr) && expr.equals("0")) {//权限值是0进行处理
                        String id = key.split("_expr")[0];
                        String value = (String) map.get(id);
                        if (StringUtils.isNotBlank(value)) {
                            map.put(id, ChangePassword.getEncryptPassword(value));//加密后添加到集合内
                        }
                    }
                }
            }
            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, doccode);// 获取审核按钮集合
            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("set nocount on ; 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, DBHelper.getValueInt(sysMap, "isshowmemowhenapprovals"));
                }
                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, Integer isshowmemowhenapprovals) 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);// 抄送字段
                            clickList.add(DBHelper.getValueInt(buttonMap, "isshowccusercodes"));//是否显示抄送
                        }
                        // 查询按钮集合中是否有当前字段,有则在此上加按钮
                        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", DBHelper.getValue(buttonMap, "iconpath"));
                        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);
                    clickList.add(isshowmemowhenapprovals);//审核时显示意见录入框
                    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;
        }
    }
}