xinyb
2022-05-18 c2dc593c9b8948718381f3a2996b6f94a59ad80a
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
363
364
365
366
367
368
package com.yc.service.build.type;
 
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;
 
import com.yc.api.bean.T9685Entity;
import com.yc.api.service.ApiServiceIfc;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.jdbc.support.rowset.SqlRowSet;
import org.springframework.stereotype.Service;
import com.yc.action.grid.TreeGridIfc;
import com.yc.entity.AttachmentConfig;
import com.yc.service.BaseService;
import com.yc.service.build.BuildFuncIfc;
import com.yc.service.commons.GformIfc;
import com.yc.service.impl.DBHelper;
import com.yc.utils.HtmlUtil;
import com.yc.utils.SessionKey;
import com.yc.utils.fileAndFolder.FileAndFolderOper;
 
/*
 * 窗体类型生成基类
 * danaus
 * 2011-02-18
 */
@Service
@Scope("prototype")
public class BaseImpl extends BaseService implements BaseIfc {
    @Autowired
    protected BuildFuncIfc BFI;
    @Autowired
    protected TreeGridIfc treeGrid;
    @Autowired
    protected GformIfc gformIfc;
    @Autowired
    private ApiServiceIfc apiServiceIfc;
 
    FileAndFolderOper FAFO = new FileAndFolderOper();
    protected String formID = "";
    protected String URI = "";
    protected String path = "";
    protected String[] formName;
 
    protected String versionId;// 版本号
    protected String dataBaseId;// 数据库id号
    protected String language;
    protected String gPath = "";
    protected String title = "";
    public String path2 = "";// 第二路径
    public String getPath2() {
        return path2;
    }
 
    public void setPath2(String path2) {
        this.path2 = path2;
    }
    protected int type = 0;
    protected String hostUrl = "";
    private String injector="";
    protected String mainformid=null;//主功能号,针对多表的子功能号生成,需要附带上主功能号,如:150348子功能号,需要生成:150101_15348
    public String getInjector() {
        return injector;
    }
 
    public String getHostUrl() {
        return hostUrl;
    }
 
    public void setHostUrl(String hostUrl) {
        this.hostUrl = hostUrl;
    }
 
    public String getgPath() {
    return gPath;
    }
 
    public void setgPath(String gPath) {
    this.gPath = gPath;
    }
 
    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;
    }
 
    public String[] getFormName() {
    return formName;
    }
 
    public void setFormName(String[] formName) {
    this.formName = formName;
    }
 
    // 查找哪些功能号把当前功能号作为主表使用
    // 格式:引用的功能号|外表的关联字段;当前表的关联字段,......
    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("");
    }
 
    public String getPath() {
    return path;
    }
 
    public void setPath(String path) {
    this.path = path;
    }
 
    public String getFormID() {
    return formID;
    }
 
    public String getURI() {
    return URI;
    }
 
    @Override
    public void setFormID(String formID) {
    this.formID = formID;
    }
 
    @Override
    public void setURI(String URI) {
    this.URI = URI;
    }
    @Override
    public void setHostURI(String URI) {
    this.hostUrl = URI;
    }
    @Override
    public void setPath(String formID, int type) throws Exception {
    this.type = type;
    this.path = BFI.getPath(formID, type, getVersionId(), getDataBaseId(), getLanguage());
    gPath = getDataBaseId() + File.separator + getVersionId() + File.separator + getLanguage();
    }
 
    @Override
    public synchronized int build() throws Exception {
    return 0;
    }
 
    public String getUpath(String formID, int type) {
    String p = "";
    try {
        p = BFI.getPath(formID, type, getVersionId(), getDataBaseId(), getLanguage());
    } catch (Exception e) {
        e.printStackTrace();
    }
    return p;
    }
 
    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() {
    String path1 = "";
    try {
        path1 = this.URI + File.separator + "app" + File.separator + BFI.getPath(formID, type, getVersionId(), getDataBaseId(), getLanguage()) + File.separator;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return path1;
    }
    protected String getIonicCreatePath(int ptype) {
    String path1 = "";
    try {
        //this.URI + File.separator + "app" + File.separator +"ionic"+ File.separator+getDataBaseId()+File.separator+formID+File.separator+type+ File.separator;
        path1 =AttachmentConfig.getInstanse().get("Ionic.webUrl")+ File.separator+getDomainUrl()+
            File.separator+"ionic_chcp"+File.separator+"www"+File.separator+"app"+File.separator+getDataBaseId()+File.separator+getFormidCreate()+
            File.separator+ptype+ File.separator; //D:/ionicPage/178/ionic_chcp/www/app/178/+File.separator+formID+File.separator+type+ File.separator
    } catch (Exception e) {
        e.printStackTrace();
    }
    return path1;
    }
 
    /**
     * 根据是否存在主功能号做相应的处理
     * @return
     */
    private String getFormidCreate(){
        if(mainformid!=null)
            return mainformid+"_"+formID;
        else
            return formID;
    }
    protected String getDomainUrl(){
     if(this.hostUrl=="") return "";
      String str=HtmlUtil.getDomain(this.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);
    }
    protected String getIonicBaseUrl() {
      String path1 = "";
      try {
          //this.URI + File.separator + "app" + File.separator +"ionic"+ File.separator+getDataBaseId()+File.separator+formID+File.separator+type+ File.separator;
        
          path1 =AttachmentConfig.getInstanse().get("Ionic.webUrl")+ 
              File.separator+getDomainUrl();//getDataBaseId();
      } catch (Exception e) {
          e.printStackTrace();
      }
      return path1;
    }
 
    @Override
    public void buildPageCode(String data, String targetFileName) throws Exception {
        File file = new File(this.URI + File.separator + "app" + File.separator + BFI.getPath(formID, type, getVersionId(), getDataBaseId(), getLanguage()) + 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=" + formID + " and (gridcontroltype in(9,19,40) or controltype in(9,19,40))");
        row.next();
        int num = row.getInt(1);
        String js_css = "<!--Bootstrap插件包(包含fileInput),bootstrap版本是5.1.3-->\n";
        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" +
                "<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" +
                "<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" +
                "<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";
        if (num != 0) {//表示存在有上传控件
            js_css +=
//            "<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";
                    "<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" +
                            "<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" +
                            "<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" +
                            "<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" +
                            "<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>";
//        data = data.replace("@_add_js_css_@", js_css);
        }
//    else {
        data = data.replace("@_add_js_css_@", js_css);
//    }
 
 
        //-------------文字颜色说明---------xin 2022-5-18 16:09:54-----------//
        StringBuilder colorText =new StringBuilder();//文字颜色说明
        if(StringUtils.isNotBlank(formID)) {
            List<T9685Entity> colorList = apiServiceIfc.get9685List(Integer.parseInt(formID));
            if (colorList != null && colorList.size() > 0) {
                colorText.append("文字颜色说明");
                for (T9685Entity t : colorList) {
                    colorText.append("<div><span title=\"" + t.getItemMemo() + "\" class=\"spanColor\" " +
                            "style=\"background-color: " + t.getHexColor() + "\"></span>" +
                            "<span style=\"color: " + t.getHexColor() + "\">" +
                            t.getColorName() + "</span></div>");
                }
            }
        }
        //文字颜色说明 xin 2022-5-18 15:53:13
        data = data.replace("[?ColorDescription]",colorText);
 
        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) throws IOException {
    return FileUtils.readFileToString(new File(this.URI + File.separator + "public" + File.separator + "template" + File.separator + getVersionId() + File.separator + type + File.separator + templateFileName), "utf-8");
    }
 
    @Override
    public String toString(Object str) {
    return str == null ? "" : str.toString();
    }
 
    @Override
    public String getBuildPath() {
    return getTemPath() + type + File.separator;
    }
    @Override
    public String getIonicPath() {
    return this.URI + File.separator + "public" + File.separator + "ionic" + File.separator + getVersionId() + File.separator + type + File.separator;
    }
    @Override
    public String getIonicBasePath() {
    
      return this.URI + File.separator + "public" + File.separator + "ionic" + File.separator + getVersionId() + File.separator;
    }
    public String getTemPath() {
    return this.URI + File.separator + "public" + File.separator + "template" + File.separator + getVersionId() + File.separator;
    }
 
    public String getVersionId() {
    return versionId;
    }
 
    public void setVersionId(String versionId) {
    this.versionId = versionId;
    }
 
    public String getDataBaseId() {
    return dataBaseId;
    }
 
    public void setDataBaseId(String dataBaseId) {
    this.dataBaseId = dataBaseId;
    }
 
    public String getLanguage() {
    return language;
    }
 
    public void setLanguage(String language) {
    this.language = language;
    }
 
    public String replaceGform(String tmpJsp) {
    Map<String, Object> formInfo = gformIfc.getGformInfo("dataformid,formdatafilters", Integer.parseInt(formID));
    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", "");
    }
 
    @Override
    public void setInjector(String s) {
    this.injector=s;
    }
}