xinyb
2024-04-22 bc82b6b46b695c41a42ff569c33d30800a6aec98
提交 | 用户 | age
a6a76f 1 /*
F 2  * v2功能号生成 by danaus 2019/12/24 10:29
3  */
4 package com.yc.action.build.v2;
5
6 import com.yc.action.build.BuildMessage;
7 import com.yc.action.build.DTO;
8 import com.yc.action.build.FormidVersionIfc;
777a1e 9 import com.yc.action.grid.ExprotType;
a6a76f 10 import com.yc.action.personalized.BuildTemplateAction;
F 11 import com.yc.entity.AttachmentConfig;
12 import com.yc.entity.DataSourceEntity;
13 import com.yc.factory.FactoryBean;
14 import com.yc.factory.InitSystem;
15 import com.yc.multiData.MultiDataSource;
16 import com.yc.multiData.SpObserver;
17 import com.yc.sdk.shopping.util.SettingKey;
18 import com.yc.sdk.weixincp.util.AsynchronousExecution;
19 import com.yc.service.build.type.v2.*;
20 import com.yc.service.build.v2.BuildFuncIfc;
ca30ee 21 import com.yc.service.customControl.ControlLayoutIfc;
c8be5e 22 import com.yc.service.impl.BaseDoIfc;
a6a76f 23 import com.yc.service.personalized.PanelDataIfc;
F 24 import com.yc.service.report._sys_form_reportDao;
25 import com.yc.utils.HtmlUtil;
26 import com.yc.utils.SessionKey;
27 import org.apache.commons.io.FileUtils;
28 import org.apache.commons.lang3.StringUtils;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
31 import org.springframework.stereotype.Controller;
32 import org.springframework.web.bind.annotation.RequestMapping;
33
34 import javax.servlet.http.HttpServletRequest;
35 import javax.servlet.http.HttpServletResponse;
36 import java.io.*;
37 import java.sql.SQLException;
38 import java.util.*;
39 import java.util.concurrent.*;
40
41 /*得到窗体类型,通过不同窗体类型,分发到各个窗体生成类进行处理*/
42 @Controller
43 @RequestMapping("/buildv2.do")
44 public class FormsBuilded extends com.yc.action.BaseAction {
45     ThreadPoolTaskExecutor threadPoolExecutor= (ThreadPoolTaskExecutor) FactoryBean.getBean("threadPoolExecutor");//线程池
46     @Autowired
47     private BuildFuncIfc mBuildFuncIfc;
48     @Autowired
49     private T_2_Ifc V2;
50     @Autowired
51     private T_1_Ifc V1;
52     @Autowired
53     private T_3_Ifc V3;
54     @Autowired
55     private T_4_Ifc V4;
56     @Autowired
57     private T_5_Ifc V5;
58     @Autowired
59     private T_7_Ifc V7;
60     @Autowired
61     private T_9_Ifc V9;
62     @Autowired
63     private T_10_Ifc V10;
64     @Autowired
65     private T_38_Ifc V38;
66     @Autowired
67     private T_18_Ifc V18;
68     @Autowired
69     private T_16_Ifc V16;
70     @Autowired
71     private T_17_Ifc V17;
72     @Autowired
73     private T_19_Ifc V19;
74     @Autowired
75     private T_20_Ifc V20;
76     @Autowired
77     private T_22_Ifc V22;
78     @Autowired
79     private T_30_Ifc V30;
80     @Autowired
81     private T_301_Ifc V301;
82     @Autowired
83     private T_15_Ifc V15;
84     @Autowired
85     private T_8_Ifc V8;
86     @Autowired
87     private T_181_Ifc V181;
88
89     @Autowired
90     private T_182_Ifc V182;
91
92     @Autowired
93     private T_238_Ifc V238;
94
95     @Autowired
96     private T_302_Ifc V302;
97
98     @Autowired
99     private T_303_Ifc V303;
100
101     @Autowired
102     private T_304_Ifc V304;
103 //
104     @Autowired
105     private T_497_Ifc V497;
106     @Autowired
107     private T_496_Ifc V496;
108     @Autowired
109     private T_499_Ifc V499;
110     @Autowired
111     private T_498_Ifc V498;
112     @Autowired
113     private T_77_Ifc V77;
114
115     @Autowired
116     private _sys_form_reportDao reportdDao;
117
118     @Autowired
119     FormidVersionIfc formidVersion;
120     
121     @Autowired
122     PanelDataIfc panelDataIfc;
c8be5e 123     @Autowired
D 124     BaseDoIfc baseDoIfc;
ca30ee 125     @Autowired
X 126     ControlLayoutIfc controlLayoutIfc;
a6a76f 127     public static String staticform = readProperties(FormsBuilded.class.getClassLoader().getResource("staticForm.properties").getFile());
F 128     protected static String isGenerateFormIdByCluster=AttachmentConfig.get("GenerateFormIdByCluster");
129
130     /**
131      * 执行所有数据库的页面生成
132      * @param req
133      * @param resp
134      * @throws SQLException
135      * @throws IOException
136      */
137     @RequestMapping(params = "m=t")
138     public synchronized void doDataBaseAll(HttpServletRequest req, HttpServletResponse resp) throws SQLException, IOException {
139         Map<String, DataSourceEntity> list = MultiDataSource.getDataSourceMaps(); 
140     
141         for (Map.Entry<String, DataSourceEntity> entry : list.entrySet()) {
142             DataSourceEntity dataSourceEntity = entry.getValue();
143             if(!dataSourceEntity.getActived()) continue;
144             String dbid = String.valueOf(dataSourceEntity.getDbId());
145             req.setAttribute(SessionKey.DATA_BASE_ID, dbid);
146             doAll(req, resp);
147         }
148     }
149
150     @RequestMapping(params = "m=a") // 一键生成
151     public synchronized void doAll(HttpServletRequest req, HttpServletResponse resp) throws IOException {// 重新生成系统所有的页面
152     String list = req.getParameter("list");
153     if (list != null && list != "") {
154         if (list.indexOf(";") == -1) {
155         resp.setContentType("text/html;charset=utf-8");
156         resp.getWriter().println("功能号格式错误,请以;分隔");
157         } else {
158         String[] ls = list.split(";");
159         for (String s : ls) {
160             req.setAttribute("isManual", true);// 标记是这里传入的
161             req.setAttribute("formID", s);
162             this.formTypeDistribute(req, resp);
163         }
164         }
165     } else {
166         try {
167
168         List<String> idlist =null;
169         List<String> paneidlist =null;
170         try{
171             SpObserver.setDBtoInstance("_"+req.getSession().getAttribute(SessionKey.DATA_BASE_ID));
172         idlist=this.mBuildFuncIfc.getAll();
173         // 数据源列表页面生成 by danaus 2013-5-4
174         paneidlist=this.mBuildFuncIfc.getPanelData();
175         }finally{
176             SpObserver.setDBtoInstance();
177         }
178         if (paneidlist.size() != 0) {
179             for (String id : paneidlist) {
180             BuildTemplateAction build = (BuildTemplateAction) FactoryBean.getBean("buildTemplateAction");
181             req.setAttribute("formId", id);
182             build.buildPersonlizedTemplate(req, resp);
183             }
184         }
185         /// -------------
186         for (String id : idlist) {
187             req.setAttribute("isManual", true);// 标记是这里传入的
188             req.setAttribute("formID", id);
189             this.formTypeDistribute(req, resp);
190         }
191
192         } catch (Exception e) {
193         e.printStackTrace();
194         }
195     }
196     }
197
198     // 读取properties的信息
199     public static String readProperties(String filePath) {
200     Properties props = new Properties();
201     InputStream in = null;
202     String s = "";
203     try {
204         in = new BufferedInputStream(new FileInputStream(filePath));
205         props.load(in);
206         Enumeration<?> en = props.propertyNames();
207         while (en.hasMoreElements()) {
208         String key = (String) en.nextElement();
209         s = props.getProperty(key);
210         }
211     } catch (Exception e) {
212         e.printStackTrace();
213     } finally {
214         in = null;
215     }
216     return s;
217     }
218     //用线程处理每一个生成功能号请求
219 class  PostFormRunable implements Callable<String> {
220         final FormVO mFormVO;
221         final HttpServletResponse response;
222         final HttpServletRequest request;
17a262 223
F 224         public PostFormRunable(FormVO formVO, HttpServletResponse response, HttpServletRequest request) {
225             this.mFormVO = formVO;
226             this.response = response;
227             this.request = request;
228         }
229
230         private void print(String msg) {
231             try {
232                 response.setContentType("text/html;charset=utf-8");
233                 PrintWriter out = response.getWriter();
234                 out.print(msg);
235                 out.flush();
236                 out.close();
237             } catch (IOException e) {
238                 e.printStackTrace();
239             }
240         }
241
a6a76f 242         @Override
F 243         public String call() throws Exception {
17a262 244             BuildMessage buildMessage = new BuildMessage();
a6a76f 245             try {
17a262 246                 SpObserver.setDBtoInstance("_" + mFormVO.dbid);// 切换数据源
F 247                 // 不是集群生成功能号
248                 if (!mFormVO.isCluster) {
c8be5e 249                 /*TODO 去掉了reportdDao.updateVersion调用,已经没意义,所以去掉这段代码 by danaus 2022/11/4 11:30
a6a76f 250                 if (mFormVO.isManual ) { // 直接手动生成页面调用
F 251                     //reportdDao.updateVersion(Integer.parseInt(mFormVO.formID)); // TODO 更新SQL数据库版本号 ,每生成一次都更新版本号???
c8be5e 252                 }*/
a6a76f 253
F 254
17a262 255                     String queryString = "formID=" + mFormVO.formID + "&" + SessionKey.DATA_BASE_ID + "=" + mFormVO.dbid + "&" + SessionKey.VERSION_ID + "=" + mFormVO.verid + "&" + SessionKey.SYSTEM_LANGUAGE + "=" + mFormVO.lang + "&isCluster=true";
F 256                     try {
257                         AsynchronousExecution.doRefreshUri(mFormVO.hostUrlLocal, "/buildv2.do", queryString); // 多线程 远程调用 生成功能号
258                     } catch (Exception e) {
259                         e.printStackTrace();
260                         //this.print("修改出错!错误原因:" + e.getMessage());
261                         return "修改出错!错误原因:" + e.getMessage();
262                     }
a6a76f 263 //                //生成 /personalized 目录下的浮动窗口功能号   ,Added by Johns Wang,2019-11-12
17a262 264                     Map<String, Object> panalDataMap = panelDataIfc.getPanelData(Integer.parseInt(mFormVO.formID));
a6a76f 265                     if (panalDataMap != null && panalDataMap.size() > 0) {
17a262 266                         request.setAttribute("formId", mFormVO.formID);
a6a76f 267                         request.setAttribute("isAutoRefresh", "true");
17a262 268                         BuildTemplateAction bta = (BuildTemplateAction) FactoryBean.getBean("buildTemplateAction");
a6a76f 269                         bta.buildPersonlizedTemplate(request, response);
c2f760 270                     }
05efb4 271                         //生成 /app 目录下功能号
F 272                         buildAction(buildMessage);
17a262 273                 } else {
F 274                     //如果是集群,且集群主机使用同一个 ROOT 目录时,则该目录不需要重复生成
275                     if (isGenerateFormIdByCluster == null || "".equalsIgnoreCase(isGenerateFormIdByCluster)
276                             || "false".equalsIgnoreCase(isGenerateFormIdByCluster)) {
277                         int serverVersion = reportdDao.getVersion(Integer.parseInt(mFormVO.formID)); // 从SQL数据库读取版本号
278                         // 同步更新本地java服务器版本号
279                         formidVersion.setFormidVersion(mFormVO.dbid, mFormVO.formID, serverVersion);
280                     } else {
05efb4 281
17a262 282                         //生成 /personalized 目录下的浮动窗口功能号   ,Added by Johns Wang,2019-11-12
F 283                         Map<String, Object> panalDataMap = panelDataIfc.getPanelData(Integer.parseInt(mFormVO.formID));
284                         if (panalDataMap != null && panalDataMap.size() > 0) {
285                             request.setAttribute("formId", mFormVO.formID);
286                             request.setAttribute("isAutoRefresh", "true");
287                             BuildTemplateAction bta = (BuildTemplateAction) FactoryBean.getBean("buildTemplateAction");
288                             bta.buildPersonlizedTemplate(request, response);
c2f760 289                         }
05efb4 290                             //生成 /app 目录下功能号
F 291                             buildAction(buildMessage);
17a262 292                     }
a6a76f 293
17a262 294                 }
F 295             } catch (Exception e) {
296                 e.printStackTrace();
297             } finally {
298                 SpObserver.setDBtoInstance();
a6a76f 299             }
c8be5e 300             //更新9801的isErrorsWhenAutoBuildPage标记位,使自动生成页面时不能再重复执行生成功能号 by danaus 2022/11/4 11:44
D 301             //生成失败 isErrorsWhenAutoBuildPage=1, 成功 isErrorsWhenAutoBuildPage=0
17a262 302             try {
F 303                 SpObserver.setDBtoInstance("_" + mFormVO.dbid);
304                 baseDoIfc.doExecute("set nocount on\n update a set a.isErrorsWhenAutoBuildPage=" + (buildMessage.isError() ? 1 : 0) + " from gform a where a.formid=" + mFormVO.formID);
305             } catch (Exception ex) {
306                 buildMessage.addErrorMsg(ex.getMessage());
307                 buildMessage.setError(true);
308             } finally {
309                 SpObserver.setDBtoInstance();
310             }
a6a76f 311             return buildMessage.getErrorMsg().toString();
F 312
17a262 313         }
F 314
a6a76f 315         //生成功能号主程序
17a262 316         private void buildAction(BuildMessage buildMessage) throws Exception {
a6a76f 317             final String messageNoResult = "无匹配的窗体类型,请检查是否未进行系统菜单设置。";
F 318             buildMessage.setManual(mFormVO.isManual);
319             if (staticform.contains("," + mFormVO.formID + ",")) {// 静态模板,当前功能号是属于这种情况,则copy过去,然后返回,不再通过后面生成页面
320                 File from = new File(mFormVO.baseURL + "public" + File.separator + "staticform" + File.separator + mFormVO.formID);//
321                 File to = new File(mFormVO.baseURL + "app" + File.separator + mFormVO.dbid + File.separator + mFormVO.verid + File.separator + mFormVO.lang
322                         + File.separator + mFormVO.formID);
323                 try {
324                     FileUtils.copyDirectory(from, to);
325                     buildMessage.addErrorMsg("生成成功");
326                     buildMessage.setError(false);
327                 } catch (IOException e) {
328                     e.printStackTrace();
329                 }
17a262 330                 return;
a6a76f 331             }
F 332             //总线程数,指执行生成页面的线程,因为单据类型一个功能号需要二个线程生成,所以需要确认真正需要的线程数
17a262 333             int threadCount = 0;
a6a76f 334             //读取主功能号9801,9802信息生成页面
17a262 335             List<DTO> formIDList = new ArrayList<>();//保存当前需要生成功能号所关联的所有功能号id
F 336             //,------------------取9802所有子功能号及主功能号
a6a76f 337
17a262 338             List<FormInfo> forms = null;
a6a76f 339             try {
F 340                 SpObserver.setDBtoInstance("_" + mFormVO.dbid);
17a262 341                 forms = mBuildFuncIfc.getFormInfo(mFormVO.formID);
05efb4 342                if(forms==null) return;//针对桌面定义的功能号会返回空
17a262 343             } catch (Exception e) {
185287 344                 buildMessage.addErrorMsg(e.getCause()!=null?e.getCause().getMessage():e.getMessage());
17a262 345             } finally {
a6a76f 346                 SpObserver.setDBtoInstance();
F 347             }
17a262 348             threadCount += fillFormInfo(formIDList, forms);
F 349
a6a76f 350             //----生成主功能号前删除缓存表
17a262 351             baseDoIfc.doExecute("declare @formid int=" + mFormVO.formID + ",@FormType int  \tdelete a  from _sys_TableColumnsDefinition a where a.formid = @formid \n" +
5fc8e3 352                     "    select @FormType = FormType from _sysMenu where formid = @formid \n" +
F 353                     "     if @FormType in (496,497,498,499) \n" +
354                     "    begin\n" +
355                     "    delete a from _sys_TableColumnsDefinition  a \n" +
356                     "        where exists (select 1 from _sys_TabPageFormid b where b.mainformid = @formid and a.FormId = b.formid ) \n" +
357                     " end ");
17a262 358             CountDownLatch countDownLatch = new CountDownLatch(formIDList.size() + threadCount);//formIDList.size()+threadCount
F 359             for (DTO dto : formIDList) {// 循环生成所有子功能号,生成对应的页面
a6a76f 360                 // 根据窗体类型分发
F 361                 BaseIfc base = null;
362                 try {
363                     switch (dto.getType()) {
364                         // 未获得窗体类型的错误消息输出
365                         case 0:
366                             buildMessage.addErrorMsg("<script language=\"javascript\">parent.message('" + messageNoResult
367                                     + "','" + mFormVO.hostUrl + "')</script>");
368                             buildMessage.setError(true);
369                             break;
370                         // 1 类型窗体
371                         case 1:
372
373                             base = (BaseIfc) V1;
374
375                             break;
376                         case 2:
377
378                             base = (BaseIfc) V2;
379
380                             break;
381                         case 3:
382
383                             base = (BaseIfc) V3;
384
385                             break;
386                         case 4:
387                             base = (BaseIfc) V4;
388                             break;
389                         case 7:
390                             base = (BaseIfc) V7;
391                             break;
392                         case 9:
393                             base = (BaseIfc) V5;
394
17a262 395                             threadPoolExecutor.execute(new BuildByFormType(countDownLatch, mFormVO, dto, 5, buildMessage,
F 396                                     false, base));
a6a76f 397                             base = (BaseIfc) V9;
F 398
399                             break;
400                         case 10:
401                             base = (BaseIfc) V10;
402                             break;
403                         case 15:
404                             base = (BaseIfc) V8;
17a262 405                             threadPoolExecutor.execute(new BuildByFormType(countDownLatch, mFormVO, dto, 8, buildMessage,
F 406                                     false, base));
a6a76f 407                             base = (BaseIfc) V15;
F 408
409                             break;
410                         case 38:
411                             base = (BaseIfc) V38;
412                             break;
413                         case 18:
414
415                             base = (BaseIfc) V18;
416                             break;
417                         case 17:
418                             base = (BaseIfc) V16;
17a262 419                             threadPoolExecutor.execute(new BuildByFormType(countDownLatch, mFormVO, dto, 16, buildMessage,
F 420                                     false, base));
a6a76f 421                             base = (BaseIfc) V17;
F 422
423                             break;
424                         case 19:
425                             base = (BaseIfc) V19;
426                             break;
427                         case 20:
428                             base = (BaseIfc) V20;
429                             break;
430                         case 22:
431                             base = (BaseIfc) V22;
432                             break;
433                         case 30:
434                             base = (BaseIfc) V30;
435                             break;
436                         case 181:
437                             base = (BaseIfc) V181;
438                             break;
439                         case 182:
440                             base = (BaseIfc) V182;
441                             break;
442                         case 238:
443                             base = (BaseIfc) V238;
444                             break;
445                         case 301:
446                             base = (BaseIfc) V301;
447                             break;
448                         case 302:
449                             base = (BaseIfc) V302;
450                             break;
451                         case 303:
452                             base = (BaseIfc) V303;
453                             break;
454                         case 304:
455                             base = (BaseIfc) V304;
456                             break;
457                         case 499:
458                             base = (BaseIfc) V498;
17a262 459                             threadPoolExecutor.execute(new BuildByFormType(countDownLatch, mFormVO, dto, 498, buildMessage,
F 460                                     false, base));
a6a76f 461                             base = (BaseIfc) V499;
F 462                             break;
463                         case 497:
464                             base = (BaseIfc) V496;
17a262 465                             threadPoolExecutor.execute(new BuildByFormType(countDownLatch, mFormVO, dto, 496, buildMessage,
F 466                                     false, base));
a6a76f 467                             base = (BaseIfc) V497;
F 468                             break;
469                         case 77:
470                             base = (BaseIfc) V77;
471                             break;
472                         case 1000://权限号
17a262 473                             File from = new File(mFormVO.baseURL + "public" + File.separator + "staticform" + File.separator + "1000" + File.separator + "index.jsp");//
F 474                             String path = mFormVO.baseURL + "app" + File.separator + mFormVO.dbid + File.separator + mFormVO.verid + File.separator + mFormVO.lang
475                                     + File.separator + mFormVO.formID + File.separator + 1000;
476                             File dir = new File(path);
477                             if (!dir.exists()) {
478                                 dir.mkdir();
479                             }
a6a76f 480                             File to = new File(path + File.separator + "index.jsp");
F 481                             try {
482                                 FileUtils.copyFile(from, to);
483                                 buildMessage.addErrorMsg("1000类型生成成功");
484                                 buildMessage.setError(false);
485                                 continue;
486                             } catch (IOException e) {
487                                 e.printStackTrace();
17a262 488                             } finally {
a6a76f 489                                 countDownLatch.countDown();
F 490                             }
491                             break;
492                         default:
493                             buildMessage.addErrorMsg("\r\n功能号:" + dto.getFormid() + "设置中无窗体类型:" + dto.getType());
494                             buildMessage.setThrowError(true);
495                             buildMessage.setError(true);
496                             break;
497                     }
498                     if (base != null) {
499                         try {
17a262 500                             threadPoolExecutor.execute(new BuildByFormType(countDownLatch, mFormVO, dto, dto.getType(),
F 501                                     buildMessage, false, base));
a6a76f 502                         } catch (Exception e) {
F 503                         }
504                     }
505                 } catch (Exception e) {
506                     throw e;
507                 }
508             }
509             //System.out.println("等待数据返回....");
17a262 510             countDownLatch.await(2, TimeUnit.MINUTES);//超时2分钟退出
a6a76f 511             //System.out.println("全部处理成功返回数据 ....");
F 512
513         }
514
17a262 515         private int fillFormInfo(List<DTO> formIDList, List<FormInfo> ftForms) {
F 516             int count = 0;
517             for (FormInfo formFt : ftForms) {
518                 try {
519                     String[] name = new String[2];
520                     name[0] = (formFt.formmemo == null || formFt.formmemo.trim().length() == 0) ? formFt.formname : formFt.formmemo;
521                     name[1] = formFt.formname;
522                     count += countFormType(formFt.formType);
523                     formIDList.add(new DTO(formFt.formid, setFormType(Integer.parseInt(formFt.formType)), name));
524                 } catch (Exception e) {
525                     continue;
a6a76f 526                 }
F 527             }
528             return count;
529
17a262 530         }
a6a76f 531     }
F 532     private int countFormType(String type){
533         return (type.equals("5")||type.equals("9")
534                 ||type.equals("8")||type.equals("15")
535                 ||type.equals("16")||type.equals("17")
536                 ||type.equals("496")||type.equals("497")
537                 ||type.equals("498")||type.equals("499"))?1:0;
538     }
539
540     @RequestMapping
541     public  void formTypeDistribute(HttpServletRequest request, HttpServletResponse response)  {
542         String baseURL = request.getServletContext().getRealPath("/");
543         boolean isVer = (request.getAttribute("isver") == null ? false : true);
544         String dbid = SessionKey.getDatabaseId(request);
545         String verid = SessionKey.getAppVersionId(request); // modified by Johns Wang, 2016-09-18
546         String lang = SessionKey.getLanguage(request); // modified by Johns Wang, 2016-09-18
547         String hostUrl = SettingKey.getHostUrl(request);
548         String hostUrlLocal = SettingKey.getHostUrlByLocal(request);
549         String formID =SessionKey.getFormID(request);
550         if(!StringUtils.isNumeric(formID)){
551             this.print(response,"功能号【"+formID+"】只能为数字");
552             return;
553         }
554
555         boolean isCluster = (request.getParameter("isCluster") == null || "".equals(request.getParameter("isCluster")) ? false : true); // 是否集群时生成
556         boolean isStaticForm = (request.getAttribute("isStaticForm") == null ? false : // 缺省值 必须为 true ,表示是从手动生成的
557                 Boolean.parseBoolean(request.getAttribute("isStaticForm")+"")); // 是否手动生成的
558         boolean isManual = (request.getAttribute("isManual") == null ? true : // 缺省值 必须为 true ,表示是从手动生成的
559             (Boolean) request.getAttribute("isManual")); // 是否手动生成的
560
561         FormVO formVO=new FormVO();
562         formVO.setBaseURL(baseURL);
563         formVO.setVer(isVer);
564         formVO.setDbid(dbid);
565         formVO.setLang(lang);
566         formVO.setHostUrl(hostUrl);
567         formVO.setHostUrlLocal(hostUrlLocal);
568         formVO.setFormID(formID);
569         formVO.verid=verid;
570         formVO.isManual=isManual;
571         formVO.isCluster=isCluster;
572         formVO.isVer=isVer;
ca30ee 573         formVO.userCode= (String) request.getSession().getAttribute(SessionKey.USERCODE); //xin 2024-1-12 17:38:19
a6a76f 574         //CountDownLatch countDownLatch=new CountDownLatch(1);
F 575         final Future<String> future = threadPoolExecutor.submit(new PostFormRunable(formVO, response, request));//调用线程处理请求一个主功能号的生成
576             try {
577                 String msg=future.get();
578                 //System.out.println("msg:"+msg);
579                 if(isManual)
580                     this.print(response,msg);
581                 else {
582                     if(!isStaticForm) {//不是静态模板才需要调用刷新,不然会出现不断刷新页面的错误
583                         this.print(response, "<script>location.reload();</script>");
584                     }
585                 }
586             } catch (InterruptedException e) {
587                 e.printStackTrace();
588             } catch (ExecutionException e) {
589                 e.printStackTrace();
590             }
591
592     }
593
594     
595     private String getDomainName(String hostUrl){
596      if(hostUrl=="") return "";
597       String str=HtmlUtil.getDomain(hostUrl);
598         int inx=str.indexOf(".");
599         if(inx==-1){
600         int y=str.indexOf(":");
601         return y==-1?str:str.substring(0, y);
602         }
603        return str.substring(0, inx);
604     }
605     
606
607
608
609     private int setFormType(int lFTFormType) {
610     if (lFTFormType == 5) lFTFormType = 9;
611     if (lFTFormType == 16) lFTFormType = 17;
612     if (lFTFormType == 8) lFTFormType = 15;
613     if (lFTFormType == 498) lFTFormType = 499;
614     if (lFTFormType == 496) lFTFormType = 497;
615     return lFTFormType;
616     }
617
618     private  class BuildByFormType implements Runnable{
619         //final CyclicBarrier cyclicBarrier;
620         final  CountDownLatch countDownLatch;
621         final FormVO formVO;
622         final DTO dto;
623         final int type;
624         final  BuildMessage buildMessage;
625         final boolean isApp;
626         final BaseIfc base;
627         public BuildByFormType(CountDownLatch countDownLatch, FormVO formVO, DTO dto, int type, BuildMessage buildMessage, boolean isApp, BaseIfc base) {
628             this.countDownLatch=countDownLatch;
629             this.formVO = formVO;
630             this.dto = dto;
631             this.type = type;
632             this.buildMessage = buildMessage;
633             this.isApp = isApp;
634             this.base=base;
635         }
636         @Override
637         public void run() {
638             int returnError = 0;
639             try {
640                 //System.out.println(base+">>"+Thread.currentThread().getName()+"|"+DateUtil.toDay()+"....>"+dto.getFormid());
641                 BaseBean baseBean=new BaseBean();
642                 baseBean.setFormID(dto.getFormid());
643                 baseBean.setURI(formVO.baseURL);
644                 baseBean.setFormName(dto.getFormName());
645                 /** 版本号和dbId和language **/
646                 baseBean.setDataBaseId(formVO.dbid);
647                 baseBean.setHostUrl(formVO.hostUrl);
648                 baseBean.setVersionId(formVO.verid);
649                 baseBean.setLanguage(formVO.lang);
650                 /** 版本号和dbId **/
651                 baseBean.setPath(dto.getFormid(), type);
652
ca30ee 653                 baseBean.setUsrCode(formVO.userCode);
X 654
a6a76f 655                 InitSystem.getInstance();
F 656                 if (!formVO.isVer && InitSystem.getPages().contains(dto.getFormid())) {// 存在这个值表示是页面打开时,版本旧了需要更新页面,但是不需要生成新的版本
657 //                    BaseService bs = (BaseService) FactoryBean.getBean("BaseService");
658 //                    try{
659 //                        SpObserver.setDBtoInstance("_"+formVO.dbid);
660 //                        //bs.getJdbcTemplate().execute("update gform set version=isnull(version,0)+1  where formid=" + dto.getFormid());// 更新版本
661 //                    }finally{
662 //                        SpObserver.setDBtoInstance();
663 //                    }
664                     InitSystem.getPages().remove(dto.getFormid());
665                 }
666                 //删除excel导出的设置文件,保持设置是最新
667                 if(!isApp) {//生成APP页面时不需要执行
668                     File file=new File(formVO.baseURL+"/app"+"/"+formVO.dbid+"/"+formVO.verid+"/"+formVO.lang+"/"+dto.getFormid());
669                     //+"/"+dto.getType()
670                     if(file.isDirectory()) {
671                         File[] fils=file.listFiles();
672                         for(File f :fils) {
673                             if(f.isDirectory()) {
674                                 if(f.getName().equalsIgnoreCase(type+"")) {//只有是当前的才需要执行删除,不然会把之前新生成的也删除了
675                                     File[] fst=f.listFiles();
676                                     for(File fs:fst) {
677                                         if(fs.getName().equalsIgnoreCase("data")||fs.getName().equalsIgnoreCase("panel_data")) {
5fc8e3 678                                             //log.info("del>>>"+fs.getAbsolutePath());
a6a76f 679                                             fs.delete();
F 680                                         }
681                                     }
682                                 }
683                              }
684                         }
685                     }
686                 }
687                 //处理静态页面
688                 if (staticform.contains("," + dto.getFormid() + ",")) {// 静态模板,当前功能号是属于这种情况,则copy过去,然后返回,不再通过后面生成页面
689                     File from = new File(formVO.baseURL + "public" + File.separator + "staticform" + File.separator + dto.getFormid());//
690                     File to = new File(formVO.baseURL + "app" + File.separator + formVO.dbid + File.separator + formVO.verid + File.separator + formVO.lang
691                             + File.separator + dto.getFormid());
692                     try {
693                         FileUtils.copyDirectory(from, to);
694                         buildMessage.addErrorMsg(dto.getFormid()+"-生成成功<br>");
695                         buildMessage.setError(false);
696                     } catch (IOException e) {
697                         e.printStackTrace();
698                     }finally {
699                         countDownLatch.countDown();
700                     }
701                     return ;
702                 }
703                 try {
704                     SpObserver.setDBtoInstance("_" + formVO.dbid);
c3d941 705                     //检查DocVersion字段是否存在 xin 2022-3-23 09:02:31
44365f 706                     //这里排除广宁广陶的系统(1639)
X 707                     if (";1;2;3;7;10;20;30;5;9;8;15;16;17;496;497;498;499;".indexOf(";" + dto.getType() + ";") != -1 && !"1639".equals(formVO.dbid)) {
c3d941 708                         panelDataIfc.setDocVersionProcess(dto.getFormid());
X 709                     }
ca30ee 710                     if(formVO.formID.equals(dto.getFormid())){//当前页面功能号和遍历出来的功能号一样就检查是否有自定义控件布局 xin 2024-1-15 09:10:46
bc82b6 711                         baseBean.setCustomLayout(controlLayoutIfc.hasControlLayout(dto.getFormid(),formVO.getUserCode(), this.type, ExprotType.Panel,false));//true表示有 false表示没有
ca30ee 712                     }
97a11f 713                     //System.out.println(dto.getFormid()+"--开始生成功能号页面.....");
a6a76f 714                     returnError = base.build(baseBean);
F 715                     //copy一份到备份目录 by danaus 2020/9/28 14:45
716                     String appdir=AttachmentConfig.get("backup.AppDir");
717                     if(StringUtils.isNotBlank(appdir)){
718                         String form=formVO.baseURL + "app" + File.separator + formVO.dbid + File.separator + formVO.verid + File.separator + formVO.lang+ File.separator + dto.getFormid();
719                     String[] dirs=appdir.split(";");
720                     for(String dir:dirs){
721                         String to=dir+ File.separator+ "app" + File.separator + formVO.dbid + File.separator + formVO.verid + File.separator + formVO.lang+ File.separator + dto.getFormid();
722                         FileUtils.copyDirectory(new File(form),new File(to));
723                     }
724                     }
725                     //System.out.println(dto.getFormid()+"--结束生成功能号页面.....");
726                 }finally {
727                     SpObserver.setDBtoInstance();
728                 }
729                 // 手动生成功能号结束
730                 if (!buildMessage.isError()) {
731                     // if ( isManual ) {
732                     int serverVersion = 0; // 从SQL数据库读取版本号
733                     try {
734                         SpObserver.setDBtoInstance("_" + formVO.dbid);
735                         serverVersion = reportdDao.getVersion(Integer.parseInt(dto.getFormid()));
5fc8e3 736                         //System.out.println("dbid:"+formVO.dbid+";页面生成成功:"+dto.getFormid());
F 737                         //System.out.println("dbid:"+formVO.dbid+";serverVersion:"+serverVersion);
738                         // 同步更新本地java服务器版本号,及同一个集群其他tomcat的内存版本号,避免重复生成
a6a76f 739                         formidVersion.setFormidVersion(formVO.dbid, dto.getFormid(), serverVersion);
5fc8e3 740                         //System.out.println("----------dbid:"+formVO.dbid+";localVersion:"+formidVersion.getFormVersion(formVO.dbid,dto.getFormid())+"-----------------");
a6a76f 741                     } catch (Exception e) {
F 742                         e.printStackTrace();
743                     }finally {
744                         SpObserver.setDBtoInstance();
745                     }
746                     //System.out.println(dto.getFormid()+".....>>");
747                     //由于单据类型的功能号调用二次,所以这里判断下,只输出一个就好
748                     if(buildMessage.getErrorMsg().toString().indexOf(dto.getFormid())<0)
749                             buildMessage.addErrorMsg(dto.getFormid() + "-生成成功。"+baseBean.getOverlapText()+"<BR>");
750                 }
751             } catch (Exception e) {
752
8aafd9 753                 buildMessage.addErrorMsg("</br>" + "功能号:" + dto.getFormid() + "窗体类型:" + dto.getType() + " 信息:" + (e.getCause() != null ? e.getCause().getMessage() : e.getMessage()));
a6a76f 754                 buildMessage.setThrowError(true);
F 755                 buildMessage.setError(true);
756             }finally {
757                 countDownLatch.countDown();
758             }
759             if (returnError != 0 && !buildMessage.isThrowError()) {
760                 buildMessage.setError(true);
761                 buildMessage.addErrorMsg("\r\n" + returnError + "==>" + dto.getFormid() + "---Type--" + dto.getType() + "<br>");
762
763             }
764
765
766         }
767     }
768 }