xinyb_
2021-08-04 1ed34269969429fb03aee77fc0785155972f5e05
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
package com.yc.service.build.type.v2;
 
import com.yc.action.grid.GridUtils;
import com.yc.action.grid.TreeGridIfc;
import com.yc.service.BaseService;
import com.yc.service.build.BuildFuncIfc;
import com.yc.service.build.top.v2.BuildTopIfc;
import com.yc.service.commons.GformIfc;
import com.yc.service.impl.DBHelper;
import com.yc.service.panel.v2.PanelServiceIfc;
import com.yc.utils.HtmlUtil;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.support.rowset.SqlRowSet;
import org.springframework.stereotype.Service;
 
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
 
/*
 * 窗体类型生成基类V2
 * by danaus 2020/2/13 17:47
 */
@Service("VbaseImpl")
public class BaseImpl extends BaseService implements BaseIfc {
    @Autowired
    protected BuildFuncIfc BFI;
    @Autowired
    protected TreeGridIfc treeGrid;
    @Autowired
    protected GformIfc gformIfc;
    @Autowired
    private BuildTopIfc buildTopIfc;
 
    @Autowired
    protected PanelServiceIfc pIfc;
 
    public static String BEAN_INFO = "beaninfo";
    private static String GFORM_SQL = " isTitle,formname,showdetail,isopenFuncshowpwdedit,isshowpwdedit,optype,HDTable,version,dataformid,formdatafilters,panellabellayout,CancelBtnProcName,CancelBtnExpression,CancelBtnEditStatus,CancelBtnName,RevokeBtnProcName,RevokeBtnExpression,RevokeBtnEditStatus,isShowOnlineMsg,isShowProcessTracking,autoOpen,predocstatus,procgroupaftersavedoc,dealafterdocsave,transgroupcode,dttable,isShowNewDocButton,isStartupSerialNumber,SerialNumberBtnEditStatus ";
 
    protected Map<String, Object> getGformInfo(String formid) {
        return gformIfc.getGformInfo(GFORM_SQL, Integer.parseInt(formid));
    }
 
 
//    public String getTitle() {
//    return "【<%=session.getAttribute(\""+SessionKey.USERNAME+"\")%>】" + this.formName[0] + "-" + this.formID;
//    }
//
//    public String getTitle2() {// 针对5,8,16类型
//    return "【<%=session.getAttribute(\""+SessionKey.USERNAME+"\")%>】" + this.formName[1] + "-" + this.formID;
//    }
 
 
    // 查找哪些功能号把当前功能号作为主表使用
    // 格式:引用的功能号|外表的关联字段;当前表的关联字段,......
    protected String[] getPrIndex(String formid, List<Map<String, Object>> list, String type) {
        String ind = "";
        int index = 0;
        for (Map<String, Object> map : list) {
            if (type.equalsIgnoreCase((Integer) map.get("formtype") + "") && !formid.equalsIgnoreCase((Integer) map.get("formid") + "")) {
                index++;
                if (formid.equalsIgnoreCase((Integer) map.get("FT") + "")) {
                    ind += "T_" + map.get("formid") + "|" + ((((String) map.get("SeekGroupID")).split(";").length > 1) ? ((String) map.get("SeekGroupID")).split(";")[1] : "")
                            + ";" +
                            ((((String) map.get("FK")).split(";").length > 1) ? ((String) map.get("FK")).split(";")[1] : "")
                            + ",";
                }
            }
        }
        return new String[]{(ind != "" || !ind.isEmpty()) ? ind.substring(0, ind.length() - 1) : "", index + ""};
    }
 
    // 去除字符串中的换行符等
    public String replaceBlank(String str) {
        if (str == null) {
            return "";
        }
        Pattern p = Pattern.compile("\t|\r|\n");
        Matcher m = p.matcher(str);
        return m.replaceAll("");
    }
 
 
    @Override
    public int build(BaseBean baseBean) throws Exception {
        return 0;
    }
 
    protected Map<String, Object> init(BaseBean baseBean) {
        Map<String, Object> gformInfo = this.getGformInfo(baseBean.getFormID());
        gformInfo.put(BEAN_INFO, baseBean);//把传进去的参数值加到map,再传给各个方法调用,避免出现并发问题
        return gformInfo;
    }
 
    protected String getValue(Map<String, String> map, String col) {
        return (map.get(col) == null) ? "" : map.get(col).toString();
    }
 
    protected String getValueInt(Map<String, String> map, String col) {
        return (map.get(col) == null) ? "0" : map.get(col).toString();
    }
 
    protected String getToPath(BaseBean baseBean) {
        String path1 = "";
        try {
            path1 = baseBean.URI + File.separator + "app" + File.separator + BFI.getPath(baseBean.formID, baseBean.type, baseBean.versionId, baseBean.dataBaseId, baseBean.language) + File.separator;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return path1;
    }
 
 
    /**
     * 根据是否存在主功能号做相应的处理
     *
     * @return
     */
    private String getFormidCreate(BaseBean baseBean) {
        if (baseBean.mainformid != null)
            return baseBean.mainformid + "_" + baseBean.formID;
        else
            return baseBean.formID;
    }
 
    /**
     * 生成panel页面
     *
     * @throws Exception
     */
    public void buildPanel(Map<String,Object> gformInfo) throws Exception {
        BaseBean baseBean = (BaseBean) gformInfo.get(BEAN_INFO);
        String fileName = "panel.jsp";
        String[] data = new String[2];
        data[0] = FileUtils.readFileToString(new File(getBuildPath(baseBean) + fileName), "utf-8");
        data[1] = FileUtils.readFileToString(new File(getTemPath(baseBean) + "panelControl.jsp"), "utf-8");
        // ----------------
        Map<String, String> map = pIfc.getPanelHtml(Integer.parseInt(baseBean.formID), baseBean.type, data, gformInfo);
        buildPageCode(map.get("panHTML"), fileName, baseBean);
        buildPageCode(map.get("panelControl"), "panelControl" + baseBean.formID + ".jsp", baseBean);
        if(map!=null&&map.get("zhu")!=null){
            baseBean.zhu=map.get("zhu");
        }
    }
 
    protected String getDomainUrl(BaseBean baseBean) {
        if (baseBean.hostUrl == "") return "";
        String str = HtmlUtil.getDomain(baseBean.hostUrl);
        int inx = str.indexOf(".");
        if (inx == -1) {
            int y = str.indexOf(":");
            return y == -1 ? str : str.substring(0, y);
        }
        return str.substring(0, inx);
    }
 
    /**
     * 生成主页面
     *
     * @throws Exception
     */
    public void buildIndex(Map<String, Object> gformInfo) throws Exception {
        BaseBean baseBean = (BaseBean) gformInfo.get(BEAN_INFO);
        String fileName = "index.jsp";
        String data = getPageCode(fileName, baseBean);
        //--------从gform表获取是否显示大标题字段值(isTitle)判断是否显示大标题,并替换标识符-2012-02-20-syz--------[begin]----------------------
 
        if (GridUtils.prossRowSetDataType_Int(gformInfo, "isTitle") == 1) {//如果配置了显示大标题
            String TopAndTitle_str =
                    "<table id=\"top_table\" width=\"100%\" bgcolor=\"#DEEDF7\">\n" +
                            "<tr>\n" +
                            "<td>\n" +
                            "<div id=\"title_top\">[?title]</div>\n" +
                            "</td></tr>\n" +
//                            "<tr>\n" +
//                            "<td>\n" +
//                            "<hr style=\"position: absolute;left:0px;top:28px;height: 1px;color: #bdc7c6;width: 99%;\">\n" +
//                            "</td>\n" +
//                            "</tr>\n" +
                            "<tr><td>\n" +
                            "<div id=\"tplt-top\">\n" +
                            "\t\t\t<%@ include file=\"top.jsp\" %>\n" +
                            "\t\t</div>\n" +
                            "</td></tr>\n" +
                            "</table>\n";
            data = data.replace("[?TopAndTitle]", TopAndTitle_str);//替换功能号标识符
        } else {//如果没有配置显示大标题
            String TopAndTitle_str =
                    "<div id=\"tplt-top\">\n" +
                            "\t\t\t<%@ include file=\"top.jsp\" %>\n" +
                            "</div>\n";
            data = data.replace("[?TopAndTitle]", TopAndTitle_str);//替换功能号标识符
        }
 
        //--------从gform表获取是否显示大标题字段值(isTitle)判断是否显示大标题,并替换标识符-2012-02-20-syz-----[end]-------------------------//
 
        // ----------------
        data = data.replace("[?title]", gformInfo.get("formname") + "");
        data = data.replaceAll("@gridJsp@", baseBean.formID + "_grid.jsp");
        data = data.replace("[?treewidth]", gformInfo.get("treewidth")+"");
        buildPageCode(data, fileName, baseBean);
    }
 
    /**
     * 生成foolter页面(资源释放页)
     *
     * @throws Exception
     */
    public void buildFoolter(BaseBean baseBean) throws Exception {
        String fileName = "foolter.jsp";
        String data = getPageCode(fileName, baseBean);
        // ----------------
 
        buildPageCode(data, fileName, baseBean);
    }
 
    /**
     * 生成Grid页面
     *
     * @throws Exception
     */
    public void buildGrid(BaseBean baseBean) throws Exception {
        treeGrid.createGrid(baseBean.type, Integer.parseInt(baseBean.formID), baseBean.URI, "app/" + baseBean.gPath + "/", new String[]{baseBean.formID + "_grid.jsp"}, getTemPath(baseBean), "/" + baseBean.formID + "/" + baseBean.type + "/", null, baseBean.dataBaseId);
    }
 
    /**
     * 生成js css 导入的页面
     *
     * @throws Exception
     */
    protected void buildJsCssHead(BaseBean baseBean) throws Exception {
        String fileName = "jsCssHead.jsp";
        String data = getPageCode(fileName, baseBean);
        buildPageCode(data, fileName, baseBean);
    }
 
    /**
     * 生成帮助页面
     *
     * @throws Exception
     */
    public void buildHelpPage(Map<String, Object> gformInfo) throws Exception {
        BaseBean baseBean = (BaseBean) gformInfo.get(BEAN_INFO);
        buildTopIfc.build(Integer.parseInt(baseBean.formID), baseBean.type, getTemPath(baseBean) + "help.jsp", getToPath(baseBean) + "help.jsp", gformInfo, this);
    }
 
    /**
     * 生成top页面
     *
     * @throws Exception
     */
    public void buildTop(Map<String, Object> gformInfo) throws Exception {
        BaseBean baseBean = (BaseBean) gformInfo.get(BEAN_INFO);
        buildTopIfc.build(Integer.parseInt(baseBean.formID), baseBean.type, getBuildPath(baseBean) + "top.jsp", getToPath(baseBean) + "top.jsp", gformInfo, this);
    }
 
    @Override
    public void buildPageCode(String data, String targetFileName, BaseBean baseBean) throws Exception {
        File file = new File(baseBean.URI + File.separator + "app" + File.separator + BFI.getPath(baseBean.formID, baseBean.type, baseBean.versionId, baseBean.dataBaseId, baseBean.language) + File.separator);
        //处理上传控件需要增加js,css的导出,根据功能号是否设置有9,19,40控件决定加不加上这些页面,从而优化页面加载 by danaus 17-11-23
        //根据formid查找9802中是不是有包括上面所说的控件,有则加载。
        SqlRowSet row = this.getRowSet(" set nocount on ; select count(1) as a from gfield where  formid=" + baseBean.formID + " and (gridcontroltype in(9,19,40) or controltype in(9,19,40))");
        row.next();
        int num = row.getInt(1);
        if (num != 0) {//表示存在有上传控件
            String js_css = "<!--上传控件-->\n" +
                    "<link rel=\"stylesheet\" type=\"text/css\" href=\"/js/bootstrap-upload/css/fileinput.css?v=<%=com.yc.utils.FileUtil.getVerstion(request,\"/js/bootstrap-upload/css/fileinput.css\")%>\">\n" +
                    "<link rel=\"stylesheet\" type=\"text/css\" href=\"/js/bootstrap-upload/css/bootstrap.css?v=<%=com.yc.utils.FileUtil.getVerstion(request,\"/js/bootstrap-upload/css/bootstrap.css\")%>\">\n" +
                    "<link rel=\"stylesheet\" type=\"text/css\" href=\"/js/bootstrap-upload/css/rotationscaling.css?v=<%=com.yc.utils.FileUtil.getVerstion(request,\"/js/bootstrap-upload/css/rotationscaling.css\")%>\">\n" +
                    "<script type=\"text/javascript\" src=\"/js/bootstrap-upload/js/fileinput.js?v=<%=com.yc.utils.FileUtil.getVerstion(request,\"/js/bootstrap-upload/js/fileinput.js\")%>\"></script>\n" +
                    "<script type=\"text/javascript\" src=\"/js/bootstrap-upload/js/locales/zh.js?v=<%=com.yc.utils.FileUtil.getVerstion(request,\"/js/bootstrap-upload/js/locales/zh.js\")%>\"></script>\n" +
                    "<script type=\"text/javascript\" src=\"/shopping/view/javascript/bootstrap/js/bootstrap.min.js?v=<%=com.yc.utils.FileUtil.getVerstion(request,\"/shopping/view/javascript/bootstrap/js/bootstrap.min.js\")%>\"></script>\n";
            data = data.replace("@_add_js_css_@", js_css);
        } else {
            data = data.replace("@_add_js_css_@", "");
        }
        if (!file.exists() || !file.isDirectory()) file.mkdirs();
        file = new File(file.getPath() + File.separator + targetFileName);
        FileUtils.writeStringToFile(file, data, "utf-8");
    }
 
    @Override
    public String getPageCode(String templateFileName, BaseBean baseBean) throws IOException {
        return FileUtils.readFileToString(new File(baseBean.URI + File.separator + "public" + File.separator + "template" + File.separator + baseBean.versionId + File.separator + baseBean.type + File.separator + templateFileName), "utf-8");
    }
 
    @Override
    public String toString(Object str) {
        return str == null ? "" : str.toString();
    }
 
    @Override
    public String getBuildPath(BaseBean baseBean) {
        return getTemPath(baseBean) + baseBean.type + File.separator;
    }
 
 
    public String getTemPath(BaseBean baseBean) {
        return baseBean.URI + File.separator + "public" + File.separator + "template" + File.separator + baseBean.versionId + File.separator;
    }
 
 
    /**
     * 生成jsp数据处理头页面
     *
     * @throws Exception
     */
    public String buildDataHead(Map<String, Object> gformInfo) throws Exception {
        BaseBean baseBean = (BaseBean) gformInfo.get(BEAN_INFO);
        String fileName = "dataHead.jsp";
        String tmpJsp = getPageCode(fileName, baseBean);
        tmpJsp = tmpJsp.replace("[?formId]", baseBean.formID);
        tmpJsp = tmpJsp.replace("[?table]", toString(gformInfo.get("HDTable")));
        tmpJsp = tmpJsp.replace("[?formType]", baseBean.type + "");
        tmpJsp = tmpJsp.replace("[?canelProc]",toString(gformInfo.get("CancelBtnProcName")));//取消确认
        tmpJsp = tmpJsp.replace("[?revokeProc]",toString(gformInfo.get("RevokeBtnProcName")));//撤回
        tmpJsp= tmpJsp.replace("[?zhu]", baseBean.zhu);
        tmpJsp = tmpJsp.replace("[?sousuo]", baseBean.sous);
        tmpJsp = tmpJsp.replace("@doc", baseBean.doc);
        tmpJsp = tmpJsp.replace("@id_info", baseBean.id_info);
        tmpJsp = tmpJsp.replace("[?predocstatus]", gformInfo.get("predocstatus") + "");
        tmpJsp = tmpJsp.replace("[?isShowOnlineMsg]", gformInfo.get("isShowOnlineMsg") + "");
        tmpJsp = tmpJsp.replace("[?isShowProcessTracking]", gformInfo.get("isShowProcessTracking") + "");
        tmpJsp = tmpJsp.replace("[?isOpenFuncShowPwdEdit]", toString(gformInfo.get("isopenFuncshowpwdedit")));
        tmpJsp = tmpJsp.replace("[?version]", ("".equalsIgnoreCase(toString(gformInfo.get("version"))) ? "0" : toString(gformInfo.get("version"))));
        // 序列号扫码 xin 2021-8-2 17:45:43
        tmpJsp = tmpJsp.replace("[?isStartupSerialNumber]", DBHelper.getValueInt(gformInfo,"isStartupSerialNumber")+"");
        tmpJsp = tmpJsp.replace("[?SerialNumberBtnEditStatus]", DBHelper.getValue(gformInfo,"SerialNumberBtnEditStatus"));
        //--操作类型
        if (gformInfo.get("optype") != null && !StringUtils.isBlank(gformInfo.get("optype").toString())) {
            tmpJsp = tmpJsp.replace("[?formOptType]", gformInfo.get("optype").toString().equalsIgnoreCase("0") ? "-1" : gformInfo.get("optype").toString());
        } else {
            tmpJsp = tmpJsp.replace("[?formOptType]", "-1");
        }
        tmpJsp = replaceGform(tmpJsp, gformInfo);
        buildPageCode(tmpJsp, fileName, baseBean);
        return tmpJsp;
    }
 
    public String replaceGform(String tmpJsp, Map<String, Object> formInfo) {
        String dataformid = DBHelper.getValue(formInfo, "dataformid");
        tmpJsp = tmpJsp.replaceAll("#dataformid#", (dataformid.equals("")) ? "" : ("," + dataformid));//" or formid in(" + dataformid + ")"
        String formdatafilters = DBHelper.getValue(formInfo, "formdatafilters");
        tmpJsp = tmpJsp.replaceAll("#formdatafilters#", (formdatafilters.equals("")) ? "" : " and " + formdatafilters);
        return tmpJsp;
    }
 
    public String trim(Object str) {
        if (str == null) {
            return "";
        }
        return str.toString().trim().replaceAll("\\r\\n|\\n|\\r", "");
    }
 
 
}