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