1、API可配置

Former-commit-id: 0e0ad49bf1937138c531c6d2452d31b83f75e29f
master
wangbing 5 years ago
parent 1fd3db5498
commit 5fa36c66ad

@ -218,26 +218,26 @@ public class JavaFxApplication extends Application {
md_right_menu.setOnAction(xEventHandler); md_right_menu.setOnAction(xEventHandler);
table_right_menu.setOnAction(xEventHandler); table_right_menu.setOnAction(xEventHandler);
URL projectdetail = JavaFxApplication.class.getClassLoader().getResource("fxml/projectdetail.fxml"); URL projectdetail = JavaFxApplication.class.getClassLoader().getResource("fxml/DetailProject.fxml");
if (projectdetail == null) { if (projectdetail == null) {
projectdetail = getClass().getResource("../../../fxml/projectdetail.fxml"); projectdetail = getClass().getResource("../../../fxml/DetailProject.fxml");
} }
mProjectLoader = new FXMLLoader(projectdetail); mProjectLoader = new FXMLLoader(projectdetail);
mProjectLoader.load(); mProjectLoader.load();
detailProjectController = mProjectLoader.getController(); detailProjectController = mProjectLoader.getController();
URL mddetail = JavaFxApplication.class.getClassLoader().getResource("fxml/moduledetail.fxml"); URL mddetail = JavaFxApplication.class.getClassLoader().getResource("fxml/DetailModule.fxml");
if (mddetail == null) { if (mddetail == null) {
mddetail = getClass().getResource("../../../fxml/moduledetail.fxml"); mddetail = getClass().getResource("../../../fxml/DetailModule.fxml");
} }
mModuleLoader = new FXMLLoader(mddetail); mModuleLoader = new FXMLLoader(mddetail);
mModuleLoader.load(); mModuleLoader.load();
mdDetailController = mModuleLoader.getController(); mdDetailController = mModuleLoader.getController();
URL tabledetail = JavaFxApplication.class.getClassLoader().getResource("fxml/tabledetail.fxml"); URL tabledetail = JavaFxApplication.class.getClassLoader().getResource("fxml/DetailTable.fxml");
if (tabledetail == null) { if (tabledetail == null) {
tabledetail = getClass().getResource("../../../fxml/tabledetail.fxml"); tabledetail = getClass().getResource("../../../fxml/DetailTable.fxml");
} }
mTableLoader = new FXMLLoader(tabledetail); mTableLoader = new FXMLLoader(tabledetail);
mTableLoader.load(); mTableLoader.load();
@ -503,6 +503,12 @@ public class JavaFxApplication extends Application {
currentProject.setNeedAsync(newValue); currentProject.setNeedAsync(newValue);
} }
}); });
detailProjectController.getApi().selectedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
currentProject.setNeedApi(newValue);
}
});
detailProjectController.getDatabase().selectedToggleProperty().addListener(new ChangeListener<Toggle>() { detailProjectController.getDatabase().selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
@Override @Override
public void changed(ObservableValue<? extends Toggle> observable, Toggle oldValue, Toggle newValue) { public void changed(ObservableValue<? extends Toggle> observable, Toggle oldValue, Toggle newValue) {
@ -677,6 +683,7 @@ public class JavaFxApplication extends Application {
} }
detailProjectController.getCloud().setSelected(currentProject.isNeedCloud()); detailProjectController.getCloud().setSelected(currentProject.isNeedCloud());
detailProjectController.getAsync().setSelected(currentProject.isNeedAsync()); detailProjectController.getAsync().setSelected(currentProject.isNeedAsync());
detailProjectController.getApi().setSelected(currentProject.isNeedApi());
if (gridPane != null) { if (gridPane != null) {
mDetail.getChildren().clear(); mDetail.getChildren().clear();

@ -23,6 +23,8 @@ public class DetailProjectController {
private CheckBox cloud; private CheckBox cloud;
@FXML @FXML
private CheckBox async; private CheckBox async;
@FXML
private CheckBox api;
public CheckBox getSysMD() { public CheckBox getSysMD() {
return sysMD; return sysMD;
@ -87,4 +89,12 @@ public class DetailProjectController {
public void setAsync(CheckBox async) { public void setAsync(CheckBox async) {
this.async = async; this.async = async;
} }
public CheckBox getApi() {
return api;
}
public void setApi(CheckBox api) {
this.api = api;
}
} }

@ -212,7 +212,7 @@ public class SpringBootCallable implements Callable {
} }
} }
{ if (project.isNeedApi()){
File api = Tool.createPath(root.getAbsolutePath(), "api"); File api = Tool.createPath(root.getAbsolutePath(), "api");
for (Module module : project.getModules()) { for (Module module : project.getModules()) {
@ -426,10 +426,6 @@ public class SpringBootCallable implements Callable {
ctx.put("author", md.getProjectAuthor()); ctx.put("author", md.getProjectAuthor());
ctx.put("date", new Date()); ctx.put("date", new Date());
if (md.getModuleName().equals("api")) {
freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "ApiExampleResponse" + ".java"), "SpringBoot/java/module/rsp/ApiExampleResponse.java", ctx);
}
for (Table table : md.getTables()) { for (Table table : md.getTables()) {
ctx.put("table", table); ctx.put("table", table);

@ -40,6 +40,8 @@ public class Project extends TreeItem {
private boolean needCloud; private boolean needCloud;
@Property("needAsync") @Property("needAsync")
private boolean needAsync; private boolean needAsync;
@Property("api")
private boolean api;
@Property(value = "database") @Property(value = "database")
private DataBase database; private DataBase database;
@ -134,4 +136,12 @@ public class Project extends TreeItem {
public void setNeedAsync(boolean needAsync) { public void setNeedAsync(boolean needAsync) {
this.needAsync = needAsync; this.needAsync = needAsync;
} }
public boolean isNeedApi() {
return api;
}
public void setNeedApi(boolean api) {
this.api = api;
}
} }

@ -89,8 +89,9 @@ public class EntityReader {
continue; continue;
} }
if (className != null) { if (className != null) {
if (line.contains("@ColumnName") || if (line.contains("@ColumnName")
line.contains("@ColumnDescription") || line.contains("@ColumnDescription")
|| line.contains("@ColumnList")
) { ) {
continue; continue;
} }

@ -78,6 +78,7 @@
<CheckBox fx:id="multiDB" text="多数据库"/> <CheckBox fx:id="multiDB" text="多数据库"/>
<CheckBox fx:id="cloud" selected="false" text="添加Cloud"/> <CheckBox fx:id="cloud" selected="false" text="添加Cloud"/>
<CheckBox fx:id="async" selected="false" text="异步编程"/> <CheckBox fx:id="async" selected="false" text="异步编程"/>
<CheckBox fx:id="api" selected="false" text="Api接口"/>
</children> </children>
</HBox> </HBox>
</children> </children>

@ -24,16 +24,20 @@ import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver; import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;
import ${basePackage}.config.ActionConfig; import ${basePackage}.config.ActionConfig;
import ${basePackage}.frame.auth.LocalData; import ${basePackage}.frame.auth.LocalData;
import ${basePackage}.frame.auth.Token;
import ${basePackage}.frame.base.BaseRequest; import ${basePackage}.frame.base.BaseRequest;
import ${basePackage}.frame.base.BaseResponse; import ${basePackage}.frame.base.BaseResponse;
import ${basePackage}.frame.base.ErrorType; import ${basePackage}.frame.base.ErrorType;
import ${basePackage}.frame.base.Screen; import ${basePackage}.frame.base.Screen;
import ${basePackage}.frame.auth.Token;
import ${basePackage}.frame.utils.AESUtil; import ${basePackage}.frame.utils.AESUtil;
import ${basePackage}.frame.utils.LogUtil; import ${basePackage}.frame.utils.LogUtil;
import ${basePackage}.frame.utils.MD5Util; import ${basePackage}.frame.utils.MD5Util;
import ${basePackage}.frame.utils.MapperUtil; import ${basePackage}.frame.utils.MapperUtil;
import ${basePackage}.frame.utils.RequestUtil; import ${basePackage}.frame.utils.RequestUtil;
import ${basePackage}.frame.utils.StringUtil;
import ${basePackage}.module.system.mgr.TokensManager;
import ${basePackage}.module.system.req.TokensBuildRequest;
import ${basePackage}.module.system.rsp.TokensBuildResponse;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@ -305,7 +309,6 @@ public class GlobalController implements ErrorController {
} }
} }
@RequestMapping(path = "/api/{module}/{target}/{method}", method = RequestMethod.POST) @RequestMapping(path = "/api/{module}/{target}/{method}", method = RequestMethod.POST)
@ResponseBody @ResponseBody
public String api( public String api(
@ -356,10 +359,23 @@ public class GlobalController implements ErrorController {
} }
// 权限验证 // 权限验证
if (StringUtil.isNotEmpty(token)) {
TokensManager tokensManager = LocalData.getBean(TokensManager.class);
TokensBuildRequest tokensBuildRequest = new TokensBuildRequest();
tokensBuildRequest.setToken(token);
TokensBuildResponse tokensBuildResponse = tokensManager.build(tokensBuildRequest, LocalData.getSysToken());
LocalData.setToken(tokensBuildResponse.getToken());
if (!LocalData.getToken().hasRes(httpServletRequest.getServletPath())) { if (!LocalData.getToken().hasRes(httpServletRequest.getServletPath())) {
response.addError(ErrorType.BUSINESS_ERROR, "[" + httpServletRequest.getServletPath() + "]未授权的资源!"); response.addError(ErrorType.BUSINESS_ERROR, "[" + httpServletRequest.getServletPath() + "]未授权的资源!");
return AESUtil.encrypt2Base64(MapperUtil.toJson(response).getBytes(), appSecret); return AESUtil.encrypt2Base64(MapperUtil.toJson(response).getBytes(), appSecret);
} }
} else {
String excluded = LocalData.getEnvironment().getProperty("web.url.auth.excluded", "") + ",/api/system/User/login";
if (!excluded.contains(excluded)) {
response.addError(ErrorType.BUSINESS_ERROR, "请通过登录接口获取Token!");
return AESUtil.encrypt2Base64(MapperUtil.toJson(response).getBytes(), appSecret);
}
}
// 开始处理业务 // 开始处理业务
try { try {

@ -68,6 +68,9 @@
<include refid="table"/> <include refid="table"/>
WHERE WHERE
"IS_DELETED" = 0 "IS_DELETED" = 0
<if test="request.userId == null and request.roleId == null">
AND "FREE" = '1'
</if>
<if test="request.userId != null"> <if test="request.userId != null">
AND "ID" IN ( AND "ID" IN (
SELECT t2.RES_ID SELECT t2.RES_ID

@ -30,31 +30,42 @@
<select id="find" resultMap="user"> <select id="find" resultMap="user">
SELECT SELECT
<include refid="entityColumnList"/> t1.*,t2.ROLE_NAMES, t2.ROLE_CODES
FROM FROM
<include refid="table"/> "sys_user" t1,
(
SELECT
t2.user_id, GROUP_CONCAT(t3.NAME) ROLE_NAMES, GROUP_CONCAT(t3.CODE) ROLE_CODES
FROM
"sys_user_role" t2,
"sys_role" t3
WHERE WHERE
"IS_DELETED" = 0 t2.ROLE_ID = t3.ID
AND t2."IS_DELETED" = 0
AND t3."IS_DELETED" = 0
GROUP BY t2.USER_ID
) t2
WHERE t1."IS_DELETED" = 0 and t1.ID = t2.user_id
<if test="request.userName != null and request.userName != ''"> <if test="request.userName != null and request.userName != ''">
AND USER_NAME = ${r"#"}{request.userName} AND t1."USER_NAME" = ${r'#'}{request.userName}
</if> </if>
<if test="request.userCode != null and request.userCode != ''"> <if test="request.userCode != null and request.userCode != ''">
AND USER_CODE = ${r"#"}{request.userCode} AND t1."USER_CODE" = ${r'#'}{request.userCode}
</if> </if>
<if test="request.userAlias != null and request.userAlias != ''"> <if test="request.userAlias != null and request.userAlias != ''">
AND USER_ALIAS = ${r"#"}{request.userAlias} AND t1."USER_ALIAS" = ${r'#'}{request.userAlias}
</if> </if>
<if test="request.userStatus != null and request.userStatus != ''"> <if test="request.userStatus != null and request.userStatus != ''">
AND USER_STATUS = ${r"#"}{request.userStatus} AND t1."USER_STATUS" = ${r'#'}{request.userStatus}
</if> </if>
<if test="request.deptId != null and request.deptId != 0"> <if test="request.deptId != null and request.deptId != 0">
AND DEPT_ID = ${r"#"}{request.deptId} AND t1."DEPT_ID" = ${r'#'}{request.deptId}
</if> </if>
<if test="request.deptCode != null and request.deptCode != ''"> <if test="request.deptCode != null and request.deptCode != ''">
AND DEPT_CODE = ${r"#"}{request.deptCode} AND t1."DEPT_CODE" = ${r'#'}{request.deptCode}
</if> </if>
<if test="request.deptName != null and request.deptName != ''"> <if test="request.deptName != null and request.deptName != ''">
AND DEPT_NAME = ${r"#"}{request.deptName} AND t1."DEPT_NAME" = ${r'#'}{request.deptName}
</if> </if>
</select> </select>

@ -51,6 +51,11 @@ public class UserUpdateRequest extends BaseUpdateRequest {
*/ */
private String deptCode; private String deptCode;
/**
*
*/
private String deptName;
public Long getId() { public Long getId() {
return this.id; return this.id;
} }
@ -98,4 +103,12 @@ public class UserUpdateRequest extends BaseUpdateRequest {
public void setDeptCode(String deptCode) { public void setDeptCode(String deptCode) {
this.deptCode = deptCode; this.deptCode = deptCode;
} }
public String getDeptName() {
return deptName;
}
public void setDeptName(String deptName) {
this.deptName = deptName;
}
} }

@ -126,7 +126,7 @@ web.url.index=/index.htm
# 登录页 # 登录页
web.url.login=/login.htm web.url.login=/login.htm
# 拦截验证 # 拦截验证
web.url.auth.included=/,/**/*.htm,/ajax/**,/api/** web.url.auth.included=/,/**/*.htm,/ajax/**
# 直接放行 # 直接放行
web.url.auth.excluded=/login.htm,/ajax/system/User/login,/ajax/system/User/logout web.url.auth.excluded=/login.htm,/ajax/system/User/login,/ajax/system/User/logout
# 超级管理员 # 超级管理员

@ -126,7 +126,7 @@ web.url.index=/index.htm
# 登录页 # 登录页
web.url.login=/login.htm web.url.login=/login.htm
# 拦截验证 # 拦截验证
web.url.auth.included=/,/**/*.htm,/ajax/**,/api/** web.url.auth.included=/,/**/*.htm,/ajax/**
# 直接放行 # 直接放行
web.url.auth.excluded=/login.htm,/ajax/system/User/login,/ajax/system/User/logout web.url.auth.excluded=/login.htm,/ajax/system/User/login,/ajax/system/User/logout
# 超级管理员 # 超级管理员

@ -293,6 +293,30 @@ public class DataInit {
</#list> </#list>
</#list> </#list>
<#if project.isNeedAsync()>
<#list project.modules as module>
<#list module.tables as table>
<#if table.create>
forMgr.add(createRes("API_${module.moduleName?upper_case}_${table.tableName?upper_case}_CREATE", "${table.tableComment}新增", "请求", "/api/${module.moduleName}/${table.getFName()}/create"));
</#if>
<#if table.delete>
forMgr.add(createRes("API_${module.moduleName?upper_case}_${table.tableName?upper_case}_DELETE", "${table.tableComment}删除", "请求", "/api/${module.moduleName}/${table.getFName()}/delete"));
</#if>
<#if table.update>
forMgr.add(createRes("API_${module.moduleName?upper_case}_${table.tableName?upper_case}_UPDATE", "${table.tableComment}更新", "请求", "/api/${module.moduleName}/${table.getFName()}/update"));
</#if>
<#if table.find>
forMgr.add(createRes("API_${module.moduleName?upper_case}_${table.tableName?upper_case}_FIND", "${table.tableComment}查询", "请求", "/api/${module.moduleName}/${table.getFName()}/find"));
</#if>
<#if table.get>
forMgr.add(createRes("API_${module.moduleName?upper_case}_${table.tableName?upper_case}_GET", "${table.tableComment}获取", "请求", "/api/${module.moduleName}/${table.getFName()}/get"));
</#if>
<#if table.search>
forMgr.add(createRes("API_${module.moduleName?upper_case}_${table.tableName?upper_case}_SEARCH", "${table.tableComment}搜索", "请求", "/api/${module.moduleName}/${table.getFName()}/search"));
</#if>
</#list>
</#list>
</#if>
} }
{//初始化开发角色 {//初始化开发角色

Loading…
Cancel
Save

Powered by TurnKey Linux.