提交 | 用户 | age
|
a6a76f
|
1 |
package com.yc.service.build.type; |
F |
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.IOException; |
|
5 |
import java.util.List; |
|
6 |
import java.util.Map; |
|
7 |
import java.util.regex.Matcher; |
|
8 |
import java.util.regex.Pattern; |
c2dc59
|
9 |
|
X |
10 |
import com.yc.api.bean.T9685Entity; |
|
11 |
import com.yc.api.service.ApiServiceIfc; |
a6a76f
|
12 |
import org.apache.commons.io.FileUtils; |
c2dc59
|
13 |
import org.apache.commons.lang.StringUtils; |
a6a76f
|
14 |
import org.springframework.beans.factory.annotation.Autowired; |
F |
15 |
import org.springframework.context.annotation.Scope; |
|
16 |
import org.springframework.jdbc.support.rowset.SqlRowSet; |
|
17 |
import org.springframework.stereotype.Service; |
|
18 |
import com.yc.action.grid.TreeGridIfc; |
|
19 |
import com.yc.entity.AttachmentConfig; |
|
20 |
import com.yc.service.BaseService; |
|
21 |
import com.yc.service.build.BuildFuncIfc; |
|
22 |
import com.yc.service.commons.GformIfc; |
|
23 |
import com.yc.service.impl.DBHelper; |
|
24 |
import com.yc.utils.HtmlUtil; |
|
25 |
import com.yc.utils.SessionKey; |
|
26 |
import com.yc.utils.fileAndFolder.FileAndFolderOper; |
|
27 |
|
|
28 |
/* |
|
29 |
* 窗体类型生成基类 |
|
30 |
* danaus |
|
31 |
* 2011-02-18 |
|
32 |
*/ |
|
33 |
@Service |
|
34 |
@Scope("prototype") |
|
35 |
public class BaseImpl extends BaseService implements BaseIfc { |
|
36 |
@Autowired |
|
37 |
protected BuildFuncIfc BFI; |
|
38 |
@Autowired |
|
39 |
protected TreeGridIfc treeGrid; |
|
40 |
@Autowired |
|
41 |
protected GformIfc gformIfc; |
c2dc59
|
42 |
@Autowired |
X |
43 |
private ApiServiceIfc apiServiceIfc; |
a6a76f
|
44 |
|
F |
45 |
FileAndFolderOper FAFO = new FileAndFolderOper(); |
|
46 |
protected String formID = ""; |
|
47 |
protected String URI = ""; |
|
48 |
protected String path = ""; |
|
49 |
protected String[] formName; |
|
50 |
|
|
51 |
protected String versionId;// 版本号 |
|
52 |
protected String dataBaseId;// 数据库id号 |
|
53 |
protected String language; |
|
54 |
protected String gPath = ""; |
|
55 |
protected String title = ""; |
|
56 |
public String path2 = "";// 第二路径 |
|
57 |
public String getPath2() { |
|
58 |
return path2; |
|
59 |
} |
|
60 |
|
|
61 |
public void setPath2(String path2) { |
|
62 |
this.path2 = path2; |
|
63 |
} |
|
64 |
protected int type = 0; |
|
65 |
protected String hostUrl = ""; |
|
66 |
private String injector=""; |
|
67 |
protected String mainformid=null;//主功能号,针对多表的子功能号生成,需要附带上主功能号,如:150348子功能号,需要生成:150101_15348 |
|
68 |
public String getInjector() { |
|
69 |
return injector; |
|
70 |
} |
|
71 |
|
|
72 |
public String getHostUrl() { |
|
73 |
return hostUrl; |
|
74 |
} |
|
75 |
|
|
76 |
public void setHostUrl(String hostUrl) { |
|
77 |
this.hostUrl = hostUrl; |
|
78 |
} |
|
79 |
|
|
80 |
public String getgPath() { |
|
81 |
return gPath; |
|
82 |
} |
|
83 |
|
|
84 |
public void setgPath(String gPath) { |
|
85 |
this.gPath = gPath; |
|
86 |
} |
|
87 |
|
|
88 |
public String getTitle() { |
|
89 |
return "【<%=session.getAttribute(\""+SessionKey.USERNAME+"\")%>】" + this.formName[0] + "-" + this.formID; |
|
90 |
} |
|
91 |
|
|
92 |
public String getTitle2() {// 针对5,8,16类型 |
|
93 |
return "【<%=session.getAttribute(\""+SessionKey.USERNAME+"\")%>】" + this.formName[1] + "-" + this.formID; |
|
94 |
} |
|
95 |
|
|
96 |
public String[] getFormName() { |
|
97 |
return formName; |
|
98 |
} |
|
99 |
|
|
100 |
public void setFormName(String[] formName) { |
|
101 |
this.formName = formName; |
|
102 |
} |
|
103 |
|
|
104 |
// 查找哪些功能号把当前功能号作为主表使用 |
|
105 |
// 格式:引用的功能号|外表的关联字段;当前表的关联字段,...... |
|
106 |
protected String[] getPrIndex(String formid, List<Map<String, Object>> list, String type) { |
|
107 |
String ind = ""; |
|
108 |
int index = 0; |
|
109 |
for (Map<String, Object> map : list) { |
|
110 |
if (type.equalsIgnoreCase((Integer) map.get("formtype") + "") && !formid.equalsIgnoreCase((Integer) map.get("formid") + "")) { |
|
111 |
index++; |
|
112 |
if (formid.equalsIgnoreCase((Integer) map.get("FT") + "")) { |
|
113 |
ind += "T_" + map.get("formid") + "|" +((((String) map.get("SeekGroupID")).split(";").length>1)?((String) map.get("SeekGroupID")).split(";")[1]:"") |
|
114 |
+ ";" + |
|
115 |
((((String) map.get("FK")).split(";").length>1)?((String) map.get("FK")).split(";")[1]:"") |
|
116 |
+ ","; |
|
117 |
} |
|
118 |
} |
|
119 |
} |
|
120 |
return new String[] { (ind != "" || !ind.isEmpty()) ? ind.substring(0, ind.length() - 1) : "", index + "" }; |
|
121 |
} |
|
122 |
|
|
123 |
// 去除字符串中的换行符等 |
|
124 |
public String replaceBlank(String str) { |
|
125 |
if (str == null) { return ""; } |
|
126 |
Pattern p = Pattern.compile("\t|\r|\n"); |
|
127 |
Matcher m = p.matcher(str); |
|
128 |
return m.replaceAll(""); |
|
129 |
} |
|
130 |
|
|
131 |
public String getPath() { |
|
132 |
return path; |
|
133 |
} |
|
134 |
|
|
135 |
public void setPath(String path) { |
|
136 |
this.path = path; |
|
137 |
} |
|
138 |
|
|
139 |
public String getFormID() { |
|
140 |
return formID; |
|
141 |
} |
|
142 |
|
|
143 |
public String getURI() { |
|
144 |
return URI; |
|
145 |
} |
|
146 |
|
|
147 |
@Override |
|
148 |
public void setFormID(String formID) { |
|
149 |
this.formID = formID; |
|
150 |
} |
|
151 |
|
|
152 |
@Override |
|
153 |
public void setURI(String URI) { |
|
154 |
this.URI = URI; |
|
155 |
} |
|
156 |
@Override |
|
157 |
public void setHostURI(String URI) { |
|
158 |
this.hostUrl = URI; |
|
159 |
} |
|
160 |
@Override |
|
161 |
public void setPath(String formID, int type) throws Exception { |
|
162 |
this.type = type; |
|
163 |
this.path = BFI.getPath(formID, type, getVersionId(), getDataBaseId(), getLanguage()); |
|
164 |
gPath = getDataBaseId() + File.separator + getVersionId() + File.separator + getLanguage(); |
|
165 |
} |
|
166 |
|
|
167 |
@Override |
|
168 |
public synchronized int build() throws Exception { |
|
169 |
return 0; |
|
170 |
} |
|
171 |
|
|
172 |
public String getUpath(String formID, int type) { |
|
173 |
String p = ""; |
|
174 |
try { |
|
175 |
p = BFI.getPath(formID, type, getVersionId(), getDataBaseId(), getLanguage()); |
|
176 |
} catch (Exception e) { |
|
177 |
e.printStackTrace(); |
|
178 |
} |
|
179 |
return p; |
|
180 |
} |
|
181 |
|
|
182 |
protected String getValue(Map<String, String> map, String col) { |
|
183 |
return (map.get(col) == null) ? "" : map.get(col).toString(); |
|
184 |
} |
|
185 |
|
|
186 |
protected String getValueInt(Map<String, String> map, String col) { |
|
187 |
return (map.get(col) == null) ? "0" : map.get(col).toString(); |
|
188 |
} |
|
189 |
|
|
190 |
protected String getToPath() { |
|
191 |
String path1 = ""; |
|
192 |
try { |
|
193 |
path1 = this.URI + File.separator + "app" + File.separator + BFI.getPath(formID, type, getVersionId(), getDataBaseId(), getLanguage()) + File.separator; |
|
194 |
} catch (Exception e) { |
|
195 |
e.printStackTrace(); |
|
196 |
} |
|
197 |
return path1; |
|
198 |
} |
|
199 |
protected String getIonicCreatePath(int ptype) { |
|
200 |
String path1 = ""; |
|
201 |
try { |
|
202 |
//this.URI + File.separator + "app" + File.separator +"ionic"+ File.separator+getDataBaseId()+File.separator+formID+File.separator+type+ File.separator; |
|
203 |
path1 =AttachmentConfig.getInstanse().get("Ionic.webUrl")+ File.separator+getDomainUrl()+ |
|
204 |
File.separator+"ionic_chcp"+File.separator+"www"+File.separator+"app"+File.separator+getDataBaseId()+File.separator+getFormidCreate()+ |
|
205 |
File.separator+ptype+ File.separator; //D:/ionicPage/178/ionic_chcp/www/app/178/+File.separator+formID+File.separator+type+ File.separator |
|
206 |
} catch (Exception e) { |
|
207 |
e.printStackTrace(); |
|
208 |
} |
|
209 |
return path1; |
|
210 |
} |
|
211 |
|
|
212 |
/** |
|
213 |
* 根据是否存在主功能号做相应的处理 |
|
214 |
* @return |
|
215 |
*/ |
|
216 |
private String getFormidCreate(){ |
|
217 |
if(mainformid!=null) |
|
218 |
return mainformid+"_"+formID; |
|
219 |
else |
|
220 |
return formID; |
|
221 |
} |
|
222 |
protected String getDomainUrl(){ |
|
223 |
if(this.hostUrl=="") return ""; |
|
224 |
String str=HtmlUtil.getDomain(this.hostUrl); |
|
225 |
int inx=str.indexOf("."); |
|
226 |
if(inx==-1){ |
|
227 |
int y=str.indexOf(":"); |
|
228 |
return y==-1?str:str.substring(0, y); |
|
229 |
} |
|
230 |
return str.substring(0, inx); |
|
231 |
} |
|
232 |
protected String getIonicBaseUrl() { |
|
233 |
String path1 = ""; |
|
234 |
try { |
|
235 |
//this.URI + File.separator + "app" + File.separator +"ionic"+ File.separator+getDataBaseId()+File.separator+formID+File.separator+type+ File.separator; |
|
236 |
|
|
237 |
path1 =AttachmentConfig.getInstanse().get("Ionic.webUrl")+ |
|
238 |
File.separator+getDomainUrl();//getDataBaseId(); |
|
239 |
} catch (Exception e) { |
|
240 |
e.printStackTrace(); |
|
241 |
} |
|
242 |
return path1; |
|
243 |
} |
|
244 |
|
|
245 |
@Override |
|
246 |
public void buildPageCode(String data, String targetFileName) throws Exception { |
7f7112
|
247 |
File file = new File(this.URI + File.separator + "app" + File.separator + BFI.getPath(formID, type, getVersionId(), getDataBaseId(), getLanguage()) + File.separator); |
X |
248 |
//处理上传控件需要增加js,css的导出,根据功能号是否设置有9,19,40控件决定加不加上这些页面,从而优化页面加载 by danaus 17-11-23 |
|
249 |
//根据formid查找9802中是不是有包括上面所说的控件,有则加载。 |
|
250 |
SqlRowSet row = this.getRowSet(" set nocount on ; select count(1) as a from gfield where formid=" + formID + " and (gridcontroltype in(9,19,40) or controltype in(9,19,40))"); |
|
251 |
row.next(); |
|
252 |
int num = row.getInt(1); |
|
253 |
String js_css = "<!--Bootstrap插件包(包含fileInput),bootstrap版本是5.1.3-->\n"; |
|
254 |
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" + |
|
255 |
"<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" + |
|
256 |
"<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" + |
|
257 |
"<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"; |
|
258 |
if (num != 0) {//表示存在有上传控件 |
|
259 |
js_css += |
|
260 |
// "<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"+ |
|
261 |
// "<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"+ |
|
262 |
// "<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"+ |
|
263 |
// "<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"+ |
|
264 |
// "<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"+ |
|
265 |
// "<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"; |
|
266 |
"<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" + |
|
267 |
"<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" + |
|
268 |
"<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" + |
|
269 |
"<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" + |
|
270 |
"<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>"; |
|
271 |
// data = data.replace("@_add_js_css_@", js_css); |
|
272 |
} |
|
273 |
// else { |
|
274 |
data = data.replace("@_add_js_css_@", js_css); |
|
275 |
// } |
c2dc59
|
276 |
|
X |
277 |
|
|
278 |
//-------------文字颜色说明---------xin 2022-5-18 16:09:54-----------// |
|
279 |
StringBuilder colorText =new StringBuilder();//文字颜色说明 |
|
280 |
if(StringUtils.isNotBlank(formID)) { |
|
281 |
List<T9685Entity> colorList = apiServiceIfc.get9685List(Integer.parseInt(formID)); |
|
282 |
if (colorList != null && colorList.size() > 0) { |
f210ac
|
283 |
colorText.append("<div class=\"colorDescriptionContainer\">"); |
X |
284 |
colorText.append("<div class=\"colorDescriptionTitle\">文字颜色说明</div>"); |
|
285 |
colorText.append("<div class=\"colorDescription\">"); |
c2dc59
|
286 |
for (T9685Entity t : colorList) { |
X |
287 |
colorText.append("<div><span title=\"" + t.getItemMemo() + "\" class=\"spanColor\" " + |
|
288 |
"style=\"background-color: " + t.getHexColor() + "\"></span>" + |
f210ac
|
289 |
"<span class=\"spanText\" style=\"color: " + t.getHexColor() + "\">" + |
c2dc59
|
290 |
t.getColorName() + "</span></div>"); |
X |
291 |
} |
f210ac
|
292 |
colorText.append("</div></div>"); |
c2dc59
|
293 |
} |
X |
294 |
} |
|
295 |
//文字颜色说明 xin 2022-5-18 15:53:13 |
|
296 |
data = data.replace("[?ColorDescription]",colorText); |
|
297 |
|
7f7112
|
298 |
if (!file.exists() || !file.isDirectory()) file.mkdirs(); |
X |
299 |
file = new File(file.getPath() + File.separator + targetFileName); |
|
300 |
FileUtils.writeStringToFile(file, data, "utf-8"); |
a6a76f
|
301 |
} |
F |
302 |
|
|
303 |
@Override |
|
304 |
public String getPageCode(String templateFileName) throws IOException { |
|
305 |
return FileUtils.readFileToString(new File(this.URI + File.separator + "public" + File.separator + "template" + File.separator + getVersionId() + File.separator + type + File.separator + templateFileName), "utf-8"); |
|
306 |
} |
|
307 |
|
|
308 |
@Override |
|
309 |
public String toString(Object str) { |
|
310 |
return str == null ? "" : str.toString(); |
|
311 |
} |
|
312 |
|
|
313 |
@Override |
|
314 |
public String getBuildPath() { |
|
315 |
return getTemPath() + type + File.separator; |
|
316 |
} |
|
317 |
@Override |
|
318 |
public String getIonicPath() { |
|
319 |
return this.URI + File.separator + "public" + File.separator + "ionic" + File.separator + getVersionId() + File.separator + type + File.separator; |
|
320 |
} |
|
321 |
@Override |
|
322 |
public String getIonicBasePath() { |
|
323 |
|
|
324 |
return this.URI + File.separator + "public" + File.separator + "ionic" + File.separator + getVersionId() + File.separator; |
|
325 |
} |
|
326 |
public String getTemPath() { |
|
327 |
return this.URI + File.separator + "public" + File.separator + "template" + File.separator + getVersionId() + File.separator; |
|
328 |
} |
|
329 |
|
|
330 |
public String getVersionId() { |
|
331 |
return versionId; |
|
332 |
} |
|
333 |
|
|
334 |
public void setVersionId(String versionId) { |
|
335 |
this.versionId = versionId; |
|
336 |
} |
|
337 |
|
|
338 |
public String getDataBaseId() { |
|
339 |
return dataBaseId; |
|
340 |
} |
|
341 |
|
|
342 |
public void setDataBaseId(String dataBaseId) { |
|
343 |
this.dataBaseId = dataBaseId; |
|
344 |
} |
|
345 |
|
|
346 |
public String getLanguage() { |
|
347 |
return language; |
|
348 |
} |
|
349 |
|
|
350 |
public void setLanguage(String language) { |
|
351 |
this.language = language; |
|
352 |
} |
|
353 |
|
|
354 |
public String replaceGform(String tmpJsp) { |
|
355 |
Map<String, Object> formInfo = gformIfc.getGformInfo("dataformid,formdatafilters", Integer.parseInt(formID)); |
|
356 |
String dataformid = DBHelper.getValue(formInfo, "dataformid"); |
|
357 |
tmpJsp = tmpJsp.replaceAll("#dataformid#", (dataformid.equals("")) ? "" :(","+ dataformid));//" or formid in(" + dataformid + ")" |
|
358 |
String formdatafilters = DBHelper.getValue(formInfo, "formdatafilters"); |
|
359 |
tmpJsp = tmpJsp.replaceAll("#formdatafilters#", (formdatafilters.equals("")) ? "" : " and " + formdatafilters); |
|
360 |
return tmpJsp; |
|
361 |
} |
|
362 |
public String trim(Object str){ |
|
363 |
if(str==null)return ""; |
|
364 |
return str.toString().trim().replaceAll("\\r\\n|\\n|\\r", ""); |
|
365 |
} |
|
366 |
|
|
367 |
@Override |
|
368 |
public void setInjector(String s) { |
|
369 |
this.injector=s; |
|
370 |
} |
|
371 |
} |