*/
@RequestMapping(params = "doMigrateIn", method = RequestMethod.POST)
@ResponseBody
public AjaxJson doMigrateIn(HttpServletRequest request,
HttpServletResponse response) {
AjaxJson j = new AjaxJson();
String ls_file = "";
UploadFile uploadFile = new UploadFile(request, ls_file);
uploadFile.setCusPath("");
uploadFile.setSwfpath("");
String uploadbasepath = uploadFile.getBasePath();// 文件上传根目录
if (uploadbasepath == null) {
uploadbasepath = ResourceUtil.getConfigByName("uploadpath");
}
String path = uploadbasepath + "\\";// 文件保存在硬盘的相对路径
String realPath = uploadFile.getMultipartRequest().getSession()
.getServletContext().getRealPath("\\")
+ path;// 文件的硬盘真实路径
message = null;
try {
File file = new File(realPath);
if (!file.exists()) {
file.mkdir();// 若目录不存在,创建根目录
}
uploadFile.getMultipartRequest().setCharacterEncoding("UTF-8");
MultipartHttpServletRequest multipartRequest = uploadFile
.getMultipartRequest();
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
String fileName = "";
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
MultipartFile mf = entity.getValue();// 获取上传文件对象
fileName = mf.getOriginalFilename();// 获取文件名
String savePath = realPath + fileName;
File savefile = new File(savePath);
String ls_tmp = savefile.getName();
/*String sqlfilename = realPath
+ ls_tmp.substring(0, ls_tmp.lastIndexOf(".")) + "\\"
+ ls_tmp.substring(0, ls_tmp.lastIndexOf(".")) + ".sql";*/
FileCopyUtils.copy(mf.getBytes(), savefile);
MigrateForm.unzip(savePath, "");
String sqlFileDir = realPath + ls_tmp.substring(0, ls_tmp.lastIndexOf("."));
File sqlDirFile = new File(sqlFileDir);
String sqlfilename = sqlDirFile.getPath() + "/";
if(sqlDirFile.isDirectory()){
sqlfilename += sqlDirFile.list()[0];
}
/*OfficeHtmlUtil officeHtml = new OfficeHtmlUtil();
String sqlStr = officeHtml.getInfo(sqlfilename);
String[] sqlStrs = sqlStr.split(";");
for (String exesql : sqlStrs) {
if (!StringUtil.isEmpty(exesql) && !"\n".equals(exesql)) {
jdbcTemplate.execute(exesql);
}
}*/
XStream xStream = new XStream();
xStream.processAnnotations(DBTable.class);
@SuppressWarnings("unchecked")
List<DBTable> dbTables = (List<DBTable>) xStream.fromXML(new File(sqlfilename));
if(!dbTables.isEmpty() && dbTables.size()>0){
for (DBTable dbTable : dbTables) {
mergeMigrateInComponent(dbTable);
}
}
}
} catch (Exception e1) {
e1.printStackTrace();
LogUtil.error(e1.toString());
message = e1.toString();
}
if (StringUtil.isNotEmpty(message))
j.setMsg("SQL文件导入失败," + message);
else
j.setMsg("SQL文件导入成功");
return j;
}