xinyb
2022-05-18 c2dc593c9b8948718381f3a2996b6f94a59ad80a
提交 | 用户 | age
a6a76f 1 package com.yc.service.build.type.v2;
F 2
3 import com.yc.action.grid.GridUtils;
4 import com.yc.action.grid.TreeGridIfc;
c2dc59 5 import com.yc.api.bean.T9685Entity;
X 6 import com.yc.api.service.ApiServiceIfc;
a6a76f 7 import com.yc.service.BaseService;
F 8 import com.yc.service.build.BuildFuncIfc;
9 import com.yc.service.build.top.v2.BuildTopIfc;
10 import com.yc.service.commons.GformIfc;
11 import com.yc.service.impl.DBHelper;
12 import com.yc.service.panel.v2.PanelServiceIfc;
13 import com.yc.utils.HtmlUtil;
14 import org.apache.commons.io.FileUtils;
15 import org.apache.commons.lang.StringUtils;
16 import org.springframework.beans.factory.annotation.Autowired;
17 import org.springframework.jdbc.support.rowset.SqlRowSet;
18 import org.springframework.stereotype.Service;
19
20 import java.io.File;
21 import java.io.IOException;
22 import java.util.List;
23 import java.util.Map;
24 import java.util.regex.Matcher;
25 import java.util.regex.Pattern;
26
27 /*
28  * 窗体类型生成基类V2
29  * by danaus 2020/2/13 17:47
30  */
31 @Service("VbaseImpl")
32 public class BaseImpl extends BaseService implements BaseIfc {
33     @Autowired
34     protected BuildFuncIfc BFI;
35     @Autowired
36     protected TreeGridIfc treeGrid;
37     @Autowired
38     protected GformIfc gformIfc;
39     @Autowired
40     private BuildTopIfc buildTopIfc;
c2dc59 41     @Autowired
X 42     private ApiServiceIfc apiServiceIfc;
a6a76f 43
F 44     @Autowired
45     protected PanelServiceIfc pIfc;
46
47     public static String BEAN_INFO = "beaninfo";
9479f0 48     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,isshowinserialbtn,inserialbtneditstatus,isshowoutserialbtn ,outserialbtneditstatus,isshowonlinepaymentbutton,isshowgridstyleforapp,popupWindowsHeightRate ";
b1ae83 49     protected Map<String, Object> getGformInfo(String formid) {
a6a76f 50         return gformIfc.getGformInfo(GFORM_SQL, Integer.parseInt(formid));
F 51     }
52
53
54 //    public String getTitle() {
55 //    return "【<%=session.getAttribute(\""+SessionKey.USERNAME+"\")%>】" + this.formName[0] + "-" + this.formID;
56 //    }
57 //
58 //    public String getTitle2() {// 针对5,8,16类型
59 //    return "【<%=session.getAttribute(\""+SessionKey.USERNAME+"\")%>】" + this.formName[1] + "-" + this.formID;
60 //    }
61
62
63     // 查找哪些功能号把当前功能号作为主表使用
64     // 格式:引用的功能号|外表的关联字段;当前表的关联字段,......
65     protected String[] getPrIndex(String formid, List<Map<String, Object>> list, String type) {
66         String ind = "";
67         int index = 0;
68         for (Map<String, Object> map : list) {
69             if (type.equalsIgnoreCase((Integer) map.get("formtype") + "") && !formid.equalsIgnoreCase((Integer) map.get("formid") + "")) {
70                 index++;
71                 if (formid.equalsIgnoreCase((Integer) map.get("FT") + "")) {
72                     ind += "T_" + map.get("formid") + "|" + ((((String) map.get("SeekGroupID")).split(";").length > 1) ? ((String) map.get("SeekGroupID")).split(";")[1] : "")
73                             + ";" +
74                             ((((String) map.get("FK")).split(";").length > 1) ? ((String) map.get("FK")).split(";")[1] : "")
75                             + ",";
76                 }
77             }
78         }
79         return new String[]{(ind != "" || !ind.isEmpty()) ? ind.substring(0, ind.length() - 1) : "", index + ""};
80     }
81
82     // 去除字符串中的换行符等
83     public String replaceBlank(String str) {
84         if (str == null) {
85             return "";
86         }
87         Pattern p = Pattern.compile("\t|\r|\n");
88         Matcher m = p.matcher(str);
89         return m.replaceAll("");
90     }
91
92
93     @Override
94     public int build(BaseBean baseBean) throws Exception {
95         return 0;
96     }
97
b1ae83 98     protected Map<String, Object> init(BaseBean baseBean) {
a6a76f 99         Map<String, Object> gformInfo = this.getGformInfo(baseBean.getFormID());
F 100         gformInfo.put(BEAN_INFO, baseBean);//把传进去的参数值加到map,再传给各个方法调用,避免出现并发问题
101         return gformInfo;
102     }
103
104     protected String getValue(Map<String, String> map, String col) {
105         return (map.get(col) == null) ? "" : map.get(col).toString();
106     }
107
108     protected String getValueInt(Map<String, String> map, String col) {
109         return (map.get(col) == null) ? "0" : map.get(col).toString();
110     }
111
112     protected String getToPath(BaseBean baseBean) {
113         String path1 = "";
114         try {
115             path1 = baseBean.URI + File.separator + "app" + File.separator + BFI.getPath(baseBean.formID, baseBean.type, baseBean.versionId, baseBean.dataBaseId, baseBean.language) + File.separator;
116         } catch (Exception e) {
117             e.printStackTrace();
118         }
119         return path1;
120     }
121
122
123     /**
124      * 根据是否存在主功能号做相应的处理
125      *
126      * @return
127      */
128     private String getFormidCreate(BaseBean baseBean) {
129         if (baseBean.mainformid != null)
130             return baseBean.mainformid + "_" + baseBean.formID;
131         else
132             return baseBean.formID;
133     }
134
135     /**
136      * 生成panel页面
137      *
138      * @throws Exception
139      */
b1ae83 140     public void buildPanel(Map<String,Object> gformInfo) throws Exception {
a6a76f 141         BaseBean baseBean = (BaseBean) gformInfo.get(BEAN_INFO);
F 142         String fileName = "panel.jsp";
143         String[] data = new String[2];
144         data[0] = FileUtils.readFileToString(new File(getBuildPath(baseBean) + fileName), "utf-8");
145         data[1] = FileUtils.readFileToString(new File(getTemPath(baseBean) + "panelControl.jsp"), "utf-8");
146         // ----------------
147         Map<String, String> map = pIfc.getPanelHtml(Integer.parseInt(baseBean.formID), baseBean.type, data, gformInfo);
148         buildPageCode(map.get("panHTML"), fileName, baseBean);
149         buildPageCode(map.get("panelControl"), "panelControl" + baseBean.formID + ".jsp", baseBean);
150         if(map!=null&&map.get("zhu")!=null){
151             baseBean.zhu=map.get("zhu");
152         }
153     }
154
155     protected String getDomainUrl(BaseBean baseBean) {
156         if (baseBean.hostUrl == "") return "";
157         String str = HtmlUtil.getDomain(baseBean.hostUrl);
158         int inx = str.indexOf(".");
159         if (inx == -1) {
160             int y = str.indexOf(":");
161             return y == -1 ? str : str.substring(0, y);
162         }
163         return str.substring(0, inx);
164     }
165
166     /**
167      * 生成主页面
168      *
169      * @throws Exception
170      */
171     public void buildIndex(Map<String, Object> gformInfo) throws Exception {
172         BaseBean baseBean = (BaseBean) gformInfo.get(BEAN_INFO);
173         String fileName = "index.jsp";
174         String data = getPageCode(fileName, baseBean);
175         //--------从gform表获取是否显示大标题字段值(isTitle)判断是否显示大标题,并替换标识符-2012-02-20-syz--------[begin]----------------------
176
177         if (GridUtils.prossRowSetDataType_Int(gformInfo, "isTitle") == 1) {//如果配置了显示大标题
178             String TopAndTitle_str =
179                     "<table id=\"top_table\" width=\"100%\" bgcolor=\"#DEEDF7\">\n" +
180                             "<tr>\n" +
181                             "<td>\n" +
182                             "<div id=\"title_top\">[?title]</div>\n" +
183                             "</td></tr>\n" +
5f1f90 184 //                            "<tr>\n" +
X 185 //                            "<td>\n" +
186 //                            "<hr style=\"position: absolute;left:0px;top:28px;height: 1px;color: #bdc7c6;width: 99%;\">\n" +
187 //                            "</td>\n" +
188 //                            "</tr>\n" +
a6a76f 189                             "<tr><td>\n" +
F 190                             "<div id=\"tplt-top\">\n" +
191                             "\t\t\t<%@ include file=\"top.jsp\" %>\n" +
192                             "\t\t</div>\n" +
193                             "</td></tr>\n" +
194                             "</table>\n";
195             data = data.replace("[?TopAndTitle]", TopAndTitle_str);//替换功能号标识符
196         } else {//如果没有配置显示大标题
197             String TopAndTitle_str =
198                     "<div id=\"tplt-top\">\n" +
199                             "\t\t\t<%@ include file=\"top.jsp\" %>\n" +
200                             "</div>\n";
201             data = data.replace("[?TopAndTitle]", TopAndTitle_str);//替换功能号标识符
202         }
203
204         //--------从gform表获取是否显示大标题字段值(isTitle)判断是否显示大标题,并替换标识符-2012-02-20-syz-----[end]-------------------------//
205
c2dc59 206         //-------------文字颜色说明---------xin 2022-5-18 16:09:54-----------//
X 207         StringBuilder colorText =new StringBuilder();//文字颜色说明
208         if(StringUtils.isNotBlank(baseBean.formID)) {
209             List<T9685Entity> colorList = apiServiceIfc.get9685List(Integer.parseInt(baseBean.formID));
210             if (colorList != null && colorList.size() > 0) {
211                 colorText.append("文字颜色说明");
212                 for (T9685Entity t : colorList) {
213                     colorText.append("<div><span title=\"" + t.getItemMemo() + "\" class=\"spanColor\" " +
214                             "style=\"background-color: " + t.getHexColor() + "\"></span>" +
215                             "<span style=\"color: " + t.getHexColor() + "\">" +
216                             t.getColorName() + "</span></div>");
217                 }
218             }
219         }
220         //文字颜色说明 xin 2022-5-18 15:53:13
221         data = data.replace("[?ColorDescription]",colorText);
a6a76f 222         // ----------------
F 223         data = data.replace("[?title]", gformInfo.get("formname") + "");
224         data = data.replaceAll("@gridJsp@", baseBean.formID + "_grid.jsp");
225         data = data.replace("[?treewidth]", gformInfo.get("treewidth")+"");
226         buildPageCode(data, fileName, baseBean);
227     }
228
229     /**
230      * 生成foolter页面(资源释放页)
231      *
232      * @throws Exception
233      */
234     public void buildFoolter(BaseBean baseBean) throws Exception {
235         String fileName = "foolter.jsp";
236         String data = getPageCode(fileName, baseBean);
237         // ----------------
238
239         buildPageCode(data, fileName, baseBean);
240     }
241
242     /**
243      * 生成Grid页面
244      *
245      * @throws Exception
246      */
247     public void buildGrid(BaseBean baseBean) throws Exception {
248         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);
249     }
250
251     /**
252      * 生成js css 导入的页面
253      *
254      * @throws Exception
255      */
256     protected void buildJsCssHead(BaseBean baseBean) throws Exception {
257         String fileName = "jsCssHead.jsp";
258         String data = getPageCode(fileName, baseBean);
259         buildPageCode(data, fileName, baseBean);
260     }
261
262     /**
263      * 生成帮助页面
264      *
265      * @throws Exception
266      */
267     public void buildHelpPage(Map<String, Object> gformInfo) throws Exception {
268         BaseBean baseBean = (BaseBean) gformInfo.get(BEAN_INFO);
269         buildTopIfc.build(Integer.parseInt(baseBean.formID), baseBean.type, getTemPath(baseBean) + "help.jsp", getToPath(baseBean) + "help.jsp", gformInfo, this);
270     }
271
272     /**
273      * 生成top页面
274      *
275      * @throws Exception
276      */
277     public void buildTop(Map<String, Object> gformInfo) throws Exception {
278         BaseBean baseBean = (BaseBean) gformInfo.get(BEAN_INFO);
279         buildTopIfc.build(Integer.parseInt(baseBean.formID), baseBean.type, getBuildPath(baseBean) + "top.jsp", getToPath(baseBean) + "top.jsp", gformInfo, this);
280     }
281
282     @Override
283     public void buildPageCode(String data, String targetFileName, BaseBean baseBean) throws Exception {
284         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);
285         //处理上传控件需要增加js,css的导出,根据功能号是否设置有9,19,40控件决定加不加上这些页面,从而优化页面加载 by danaus 17-11-23
286         //根据formid查找9802中是不是有包括上面所说的控件,有则加载。
b1ae83 287         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))");
a6a76f 288         row.next();
F 289         int num = row.getInt(1);
7f7112 290         String js_css = "<!--Bootstrap插件包(包含fileInput),bootstrap版本是5.1.3-->\n";
X 291         js_css += "<link rel=\"stylesheet\" type=\"text/css\" href=\"/js/bootstrap/v5.1.3/css/bootstrap.css?v=<%=com.yc.utils.FileUtil.getVerstion(request,\"/js/bootstrap/v5.1.3/css/bootstrap.css\")%>\">\n" +
292                 "<link rel=\"stylesheet\" type=\"text/css\" href=\"/js/bootstrap/v5.1.3/icons/font/bootstrap-icons.css?v=<%=com.yc.utils.FileUtil.getVerstion(request,\"/js/bootstrap/v5.1.3/icons/font/bootstrap-icons.css\")%>\">\n" +
293                 "<script type=\"text/javascript\" src=\"/js/bootstrap/v5.1.3/js/bootstrap.js?v=<%=com.yc.utils.FileUtil.getVerstion(request,\"/js/bootstrap/v5.1.3/js/bootstrap.js\")%>\"></script>\n" +
294                 "<script type=\"text/javascript\" src=\"/js/bootstrap/v5.1.3/js/bootstrap.bundle.js?v=<%=com.yc.utils.FileUtil.getVerstion(request,\"/js/bootstrap/v5.1.3/js/bootstrap.bundle.js\")%>\"></script>\n";
a6a76f 295         if (num != 0) {//表示存在有上传控件
7f7112 296             js_css +=
X 297 //                    "<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" +
298 //                    "<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" +
299 //                    "<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" +
300 //                    "<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" +
301 //                    "<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" +
302 //                    "<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";
303                     "<link rel=\"stylesheet\" type=\"text/css\" href=\"/js/bootstrap/fileinput/css/fileinput.css?v=<%=com.yc.utils.FileUtil.getVerstion(request,\"/js/bootstrap/fileinput/css/fileinput.css\")%>\">\n" +
304                             "<link rel=\"stylesheet\" type=\"text/css\" href=\"/general/Viewer/css/viewer.min.css?v=<%=com.yc.utils.FileUtil.getVerstion(request,\"/general/Viewer/css/viewer.min.css\")%>\">\n" +
305                             "<script type=\"text/javascript\" src=\"/js/bootstrap/fileinput/js/fileinput.js?v=<%=com.yc.utils.FileUtil.getVerstion(request,\"/js/bootstrap/fileinput/js/fileinput.js\")%>\"></script>\n" +
306                             "<script type=\"text/javascript\" src=\"/js/bootstrap/fileinput/js/locales/zh.js?v=<%=com.yc.utils.FileUtil.getVerstion(request,\"/js/bootstrap/fileinput/js/locales/zh.js\")%>\"></script>\n" +
307                             "<script type=\"text/javascript\" src=\"/general/Viewer/js/viewer.min.js?v=<%=com.yc.utils.FileUtil.getVerstion(request,\"/general/Viewer/js/viewer.min.js\")%>\"></script>";
a6a76f 308         }
7f7112 309         data = data.replace("@_add_js_css_@", js_css);
a6a76f 310         if (!file.exists() || !file.isDirectory()) file.mkdirs();
F 311         file = new File(file.getPath() + File.separator + targetFileName);
312         FileUtils.writeStringToFile(file, data, "utf-8");
313     }
314
315     @Override
316     public String getPageCode(String templateFileName, BaseBean baseBean) throws IOException {
317         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");
318     }
319
320     @Override
321     public String toString(Object str) {
322         return str == null ? "" : str.toString();
323     }
324
325     @Override
326     public String getBuildPath(BaseBean baseBean) {
327         return getTemPath(baseBean) + baseBean.type + File.separator;
328     }
329
330
331     public String getTemPath(BaseBean baseBean) {
332         return baseBean.URI + File.separator + "public" + File.separator + "template" + File.separator + baseBean.versionId + File.separator;
333     }
334
335
336     /**
337      * 生成jsp数据处理头页面
338      *
339      * @throws Exception
340      */
341     public String buildDataHead(Map<String, Object> gformInfo) throws Exception {
342         BaseBean baseBean = (BaseBean) gformInfo.get(BEAN_INFO);
343         String fileName = "dataHead.jsp";
344         String tmpJsp = getPageCode(fileName, baseBean);
345         tmpJsp = tmpJsp.replace("[?formId]", baseBean.formID);
346         tmpJsp = tmpJsp.replace("[?table]", toString(gformInfo.get("HDTable")));
347         tmpJsp = tmpJsp.replace("[?formType]", baseBean.type + "");
d09c0b 348         tmpJsp = tmpJsp.replace("[?formName]", gformInfo.get("formName")+"");
a6a76f 349         tmpJsp = tmpJsp.replace("[?canelProc]",toString(gformInfo.get("CancelBtnProcName")));//取消确认
F 350         tmpJsp = tmpJsp.replace("[?revokeProc]",toString(gformInfo.get("RevokeBtnProcName")));//撤回
351         tmpJsp= tmpJsp.replace("[?zhu]", baseBean.zhu);
352         tmpJsp = tmpJsp.replace("[?sousuo]", baseBean.sous);
353         tmpJsp = tmpJsp.replace("@doc", baseBean.doc);
354         tmpJsp = tmpJsp.replace("@id_info", baseBean.id_info);
355         tmpJsp = tmpJsp.replace("[?predocstatus]", gformInfo.get("predocstatus") + "");
356         tmpJsp = tmpJsp.replace("[?isShowOnlineMsg]", gformInfo.get("isShowOnlineMsg") + "");
357         tmpJsp = tmpJsp.replace("[?isShowProcessTracking]", gformInfo.get("isShowProcessTracking") + "");
358         tmpJsp = tmpJsp.replace("[?isOpenFuncShowPwdEdit]", toString(gformInfo.get("isopenFuncshowpwdedit")));
359         tmpJsp = tmpJsp.replace("[?version]", ("".equalsIgnoreCase(toString(gformInfo.get("version"))) ? "0" : toString(gformInfo.get("version"))));
1ed342 360         // 序列号扫码 xin 2021-8-2 17:45:43
92b189 361         //入库
X 362         tmpJsp = tmpJsp.replace("[?isshowinserialbtn]", DBHelper.getValueInt(gformInfo,"isshowinserialbtn")+"");
363         tmpJsp = tmpJsp.replace("[?inserialbtneditstatus]", DBHelper.getValue(gformInfo,"inserialbtneditstatus"));
364         //出库
365         tmpJsp = tmpJsp.replace("[?isshowoutserialbtn]", DBHelper.getValueInt(gformInfo,"isshowoutserialbtn")+"");
366         tmpJsp = tmpJsp.replace("[?outserialbtneditstatus]", DBHelper.getValue(gformInfo,"outserialbtneditstatus"));
c6abc2 367         //农行支付收付款控制 xin 2021-8-23 14:30:39
229bc8 368         //在线收
c6abc2 369         tmpJsp = tmpJsp.replace("[?isshowonlinepaymentbutton]", DBHelper.getValueInt(gformInfo,"isshowonlinepaymentbutton")+"");
X 370
a6a76f 371         //--操作类型
F 372         if (gformInfo.get("optype") != null && !StringUtils.isBlank(gformInfo.get("optype").toString())) {
373             tmpJsp = tmpJsp.replace("[?formOptType]", gformInfo.get("optype").toString().equalsIgnoreCase("0") ? "-1" : gformInfo.get("optype").toString());
374         } else {
375             tmpJsp = tmpJsp.replace("[?formOptType]", "-1");
376         }
377         tmpJsp = replaceGform(tmpJsp, gformInfo);
378         buildPageCode(tmpJsp, fileName, baseBean);
379         return tmpJsp;
380     }
381
382     public String replaceGform(String tmpJsp, Map<String, Object> formInfo) {
383         String dataformid = DBHelper.getValue(formInfo, "dataformid");
384         tmpJsp = tmpJsp.replaceAll("#dataformid#", (dataformid.equals("")) ? "" : ("," + dataformid));//" or formid in(" + dataformid + ")"
385         String formdatafilters = DBHelper.getValue(formInfo, "formdatafilters");
386         tmpJsp = tmpJsp.replaceAll("#formdatafilters#", (formdatafilters.equals("")) ? "" : " and " + formdatafilters);
387         return tmpJsp;
388     }
389
390     public String trim(Object str) {
391         if (str == null) {
392             return "";
393         }
394         return str.toString().trim().replaceAll("\\r\\n|\\n|\\r", "");
395     }
396
397
398 }