com.ajaxjs.developer.DeveloperToolsController Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ajaxjs-framework2 Show documentation
Show all versions of ajaxjs-framework2 Show documentation
AJAXJS aims to full-stack, not only the server-side framework,
but also integrates the front-end library. It's written in HTML5 + Java, a successor to the JVM platform, efficient, secure, stable, cross-platform and many other advantages, but it abandoned the traditional enterprise architecture brought about by the large and bloated,
emphasizing the lightweight, and fast, very suitable for the Internet fast application.
The newest version!
package com.ajaxjs.developer;
import com.ajaxjs.config.GetConfig;
import com.ajaxjs.developer.MysqlAutoBackup.MysqlExport;
import com.ajaxjs.framework.BaseController;
import com.ajaxjs.framework.filter.DataBaseFilter;
import com.ajaxjs.sql.JdbcConnection;
import com.ajaxjs.util.XmlHelper;
import com.ajaxjs.util.io.FileHelper;
import com.ajaxjs.util.io.ZipHelper;
import com.ajaxjs.web.mvc.MvcRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
/**
* 开发工具
*
* @author sp42 [email protected]
*
*/
@Controller
@RequestMapping("/admin/developer/developer-tool")
public class DeveloperToolsController extends BaseController {
@Autowired
private GetConfig cfg;
@GetMapping
public String deve(ModelMap mv, HttpServletRequest _req) {
MvcRequest req = (MvcRequest) _req;
// 代码生成器
mv.put("saveFolder", cfg.get("System.project_folder") + "\\src"); // 臨時保存
mv.put("conn", XmlHelper.nodeAsMap(req.mappath("/META-INF/context.xml"), "//Resource[@name='" + cfg.get("data.database_node") + "']"));
return "developer/developer-tool";
}
@GetMapping("docs")
public String docs() {
return "developer/developer-doc";
}
@ResponseBody
@GetMapping(value = "backup/images", produces = JSON)
public String images(HttpServletRequest _req) {
MvcRequest req = (MvcRequest) _req;
String folder = req.mappath("/images");
ZipHelper.zip(folder, req.mappath("/temp/images.zip"));
return jsonOk("备份图片成功!");
}
@ResponseBody
@GetMapping(value = "backup/site", produces = JSON)
public String site(HttpServletRequest _req, int i) {
MvcRequest req = (MvcRequest) _req;
String folder = req.mappath("/");
String save = req.mappath("/temp/site.zip"), _save = save.replaceAll("/", "\\\\");
String images = req.mappath("/images").replaceAll("/", "\\\\");
String lib = req.mappath("/WEB-INF/lib").replaceAll("/", "\\\\");
String classes = req.mappath("/WEB-INF/classes").replaceAll("/", "\\\\");
boolean isWithImage = (i & 1) == 1, isWithClasses = (i & 2) == 2, isWithLib = (i & 4) == 4;
ZipHelper.zip(folder, save, file -> {
String path = file.toString();
if (path.equals(images))
return isWithImage;
if (path.equals(lib))
return isWithLib;
if (path.equals(classes))
return isWithClasses;
if (path.equals(_save)) // 排除自己,不然 zip 文件会越来越大
return false;
return true;
});
return jsonOk("备份项目成功!");
}
@ResponseBody
@DataBaseFilter
@GetMapping(value = "backup/db", produces = JSON)
public String db(HttpServletRequest _req) {
MvcRequest req = (MvcRequest) _req;
String save = req.mappath("/temp/");
String zipFile = new MysqlExport(JdbcConnection.getConnection(), save).export();
return jsonOk_Extension("备份SQL成功!", "\"zipFile\" : \"" + zipFile + "\"");
}
@ResponseBody
@DeleteMapping(value = "backup", produces = JSON)
public String clear(HttpServletRequest _req) {
MvcRequest req = (MvcRequest) _req;
FileHelper.delete(req.mappath("/temp/"));
return jsonOk("清理成功!");
}
}