MigrationSystemCheckOperation.jsp
8.85 KB
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
<%@ page language="java" contentType="text/html; charset=UTF-8" %><%@ page import="weaver.general.Util,weaver.general.GCONST" %><%@ page import="java.util.*" %><%@ page import="java.io.*" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="weaver.upgradetool.dbupgrade.upgrade.DBUpgrade" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.upgradetool.dbupgrade.upgrade.PropUtil" %>
<%@ page import="weaver.hrm.User" %>
<%@ page import="org.apache.xmlbeans.impl.regex.Match" %>
<%@ page import="weaver.hrm.UserManager" %>
<%@ page import="weaver.upgradetool.dbupgrade.logger.DBUpgradeLogger" %>
<%@ page import="weaver.templetecheck.*" %>
<%@ page import="org.dom4j.Document" %>
<%@ include file="/system/upgradetoe9/MigrationOperation.jsp"%>
<%
String operation=Util.null2String(request.getParameter("operation"));//获取执行的动作
RecordSet rs=new RecordSet();
if("initfile".equalsIgnoreCase(operation)){//初始化文件
String path=Util.null2String(request.getParameter("path"));//获得路径名或则是表名\
try{
String type="";
rs.executeQuery("select type from DBUpgradeInitConfig where path=?",path);
if(rs.next()){
type=rs.getString("type");
}
if("properties".equalsIgnoreCase(type)){//初始化properties文件
File file=new File(GCONST.getRootPath()+path);
if(!file.exists()){
JSONObject json=new JSONObject();
json.put("status","0");
response.getWriter().print(json);
}else{
PropUtil propUtil=PropUtil.getInstance(GCONST.getRootPath()+path.replace("\\","/"));
rs.executeQuery("select property,value from DBUpgradeInitConfig where path='"+path+"'");
while(rs.next()){
String propertyname=Util.null2String(rs.getString("property"));
String propertyvalue=Util.null2String(rs.getString("value"));
propUtil.put(propertyname,propertyvalue);
}
propUtil.store();
}
JSONObject json=new JSONObject();
json.put("status","1");
response.getWriter().print(json);
return;
}else if("db".equalsIgnoreCase(type)){//初始化数据库的操作
RecordSet rs1=new RecordSet();
rs.executeQuery("select * from DBUpgradeInitConfig where path=?",path);
while(rs.next()){
String propertyname=Util.null2String(rs.getString("property"));
String propertyvalue=Util.null2String(rs.getString("value"));
rs1.executeQuery("update "+path+" set "+propertyname+"= "+propertyvalue);
}
JSONObject json=new JSONObject();
json.put("status","1");
response.getWriter().print(json);
return;
}
}catch(Exception e){
DBUpgradeLogger.write2File("初始化文件错误"+e);
}
return;
}else if("checkfile".equalsIgnoreCase(operation)){//检查模板
User user=new UserManager().getUserByUserIdAndLoginType(1,"1");
user.setLanguage(7);
Map<String,String> params=new HashMap<String,String>();
params.put("description","");
params.put("name","检测流程模板");
params.put("content","");
params.put("ishtml","0");
params.put("tabtype","checkhtml");
params.put("type","1");
MatchUtil checkUtil=new MatchUtil();
List<Map<String,String>> list=checkUtil.getMatchResult(user,params,request,response);
JSONObject json=new JSONObject();
json.put("status","1");//成功的状态
json.put("counts",list.size());
response.getWriter().print(json.toString());
return;
}else if("checkconfig".equalsIgnoreCase(operation)){
//检查文件规范
StringBuffer checkfileresult=new StringBuffer();
StringBuffer exitfileresutl=new StringBuffer();
String migrationtablespath=GCONST.getRootPath() + "system" + File.separatorChar + "upgradetoe9" + File.separatorChar +"resource" + File.separatorChar + "migration.properties";
PropUtil tableprop=PropUtil.getInstance(migrationtablespath);
String tablestr=Util.null2String(tableprop.getValues("checkxmlfilepath"));//获得需要检测的xml文件的路径
if(tablestr.length()>0){
String[] xmlpaths=tablestr.split(",");
for (int i=0;i<xmlpaths.length;i++){
String filepath=xmlpaths[i];
String filename=filepath.substring(filepath.lastIndexOf("/")+1);
// DBUpgradeLogger.write2File("检测xml文件名:"+filename);
FileUtil fileUtil = new FileUtil();
String isxml = "0";//0 是xml 1;文件不存在 2:xml格式有问题
try {
// DBUpgradeLogger.write2File("检测xml路径:"+GCONST.getRootPath()+filepath);
File file = new File(fileUtil.getPath(GCONST.getRootPath()+filepath));
if(file.exists()) {
ReadXml readxml = new ReadXml();
Document doc = readxml.read(file.getPath());
if(doc == null) {
// DBUpgradeLogger.write2File("检测xml文件名:"+filename+"文件文件格式出现问题");
// checkfileresult.append(","+filename+"文件格式不规范");
checkfileresult.append(","+filename);
// if(checkfileresult.length()>0){
//
// }else{
// checkfileresult.append(filename);
// }
}
} else {
DBUpgradeLogger.write2File("检测xml文件名:"+filename+"文件不存在");
exitfileresutl.append(","+filename);//文件不存在的时候
// checkfileresult.append(","+filename+"文件不存在");
}
} catch(Exception e) {
// checkfileresult.append(","+filename+"文件格式不规范");
checkfileresult.append(","+filename);
// if(checkfileresult.length()>0){
// checkfileresult.append(","+filename);
// }else{
// checkfileresult.append(filename);
// }
DBUpgradeLogger.write2File("xml文件规范检测出现错误"+e);
}
}
}
//检测文件,获得数量
CheckConfigFile checkConfigFile = new CheckConfigFile();
ConfigOperation configOperation=new ConfigOperation();
String ids=Util.null2String(request.getParameter("ids"));
User user=new UserManager().getUserByUserIdAndLoginType(1,"1");
user.setLanguage(7);
Map<String,String> params=new HashMap<String,String>();
params.put("ids",ids);
params.put("filetype","0");
params.put("status","2");
params.put("filename","");
params.put("attrname","");
params.put("attrvalue","");
int checkcount=0;
List<Map<String, String>> configlist=configOperation.getConfigFileList(user,params,request,response);
// DBUpgradeLogger.write2File(configlist.toString());
for(int i=0 ;i<configlist.size();i++){
Map<String, String> map = configlist.get(i);
String isconfiged=Util.null2String(map.get("isconfiged"));
// DBUpgradeLogger.write2File(isconfiged);
if(isconfiged.equalsIgnoreCase("否")){
checkcount++;
}
}
// List<Map<String, String>> list=checkConfigFile.getMatchResult(user,params,request,response);
JSONObject json=new JSONObject();
json.put("status","1");//成功的状态
// json.put("counts",list.size());
json.put("counts",checkcount);
String backresulttext="";
if(checkfileresult.length()>0){
// backresulttext=checkfileresult.toString();
backresulttext+=checkfileresult.toString()+"文件格式不规范";
}
if(exitfileresutl.length()>0){
backresulttext=backresulttext+exitfileresutl+"文件不存在";
}
DBUpgradeLogger.write2File("检测xml文件名:"+backresulttext);
json.put("result",backresulttext);
response.getWriter().print(json.toString());
return;
}else if("removesession".equalsIgnoreCase(operation)){
//session.removeAttribute("weaver_user@bean");
JSONObject json=new JSONObject();
json.put("status","1");//成功的状态
response.getWriter().print(json.toString());
return;
}
%>