This commit is contained in:
parent
b16866d43e
commit
473afbb834
|
|
@ -17,6 +17,14 @@ export function getIntertable(id) {
|
|||
})
|
||||
}
|
||||
|
||||
// 查询接口信息详细
|
||||
export function getClassPreview(id) {
|
||||
return request({
|
||||
url: 'generator/intertable/classpreview/' + id,
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
// 新增接口信息
|
||||
export function addIntertable(data) {
|
||||
return request({
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@
|
|||
type="text"
|
||||
size="small"
|
||||
icon="el-icon-view"
|
||||
@click="handlePreview(scope.row)"
|
||||
@click="handlePreview(scope.row.id)"
|
||||
v-hasPermi="['tool:apiclass:preview']"
|
||||
>预览</el-button>
|
||||
<el-button
|
||||
|
|
@ -201,13 +201,28 @@
|
|||
<el-button @click="cancel">取 消</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
<!-- 预览界面 -->
|
||||
<el-dialog :title="preview.title" :visible.sync="preview.open" width="80%" top="5vh" append-to-body>
|
||||
<el-tabs v-model="preview.activeName">
|
||||
<el-tab-pane
|
||||
v-for="(value, key) in preview.data"
|
||||
:label="key.substring(key.lastIndexOf('/')+1,key.indexOf('.vm'))"
|
||||
:name="key.substring(key.lastIndexOf('/')+1,key.indexOf('.vm'))"
|
||||
:key="key"
|
||||
>
|
||||
<pre><code class="hljs" v-html="highlightedCode(value, key)"></code></pre>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { listApiclass, getApiclass, delApiclass, addApiclass, updateApiclass, exportApiclass } from "@/api/tool/apiclass";
|
||||
import {queryListModule} from "@/api/tool/module"
|
||||
|
||||
import {getClassPreview} from "@/api/tool/interTable"
|
||||
import hljs from "highlight.js/lib/highlight";
|
||||
hljs.registerLanguage("java", require("highlight.js/lib/languages/java"));
|
||||
export default {
|
||||
name: "Apiclass",
|
||||
components: {},
|
||||
|
|
@ -243,6 +258,13 @@
|
|||
cName: null,
|
||||
cDescribe: null,
|
||||
},
|
||||
// 预览参数
|
||||
preview: {
|
||||
open: false,
|
||||
title: "代码预览",
|
||||
data: {},
|
||||
activeName: "domain.java"
|
||||
},
|
||||
// 表单参数
|
||||
form: {},
|
||||
// 表单校验
|
||||
|
|
@ -283,6 +305,21 @@
|
|||
})
|
||||
},
|
||||
methods: {
|
||||
/** 预览代码 */
|
||||
handlePreview(id){
|
||||
getClassPreview(3).then(res =>{
|
||||
this.preview.data = res.data;
|
||||
this.preview.open = true;
|
||||
console.log(res)
|
||||
})
|
||||
},
|
||||
/** 高亮显示 */
|
||||
highlightedCode(code, key) {
|
||||
const vmName = key.substring(key.lastIndexOf("/") + 1, key.indexOf(".vm"));
|
||||
var language = vmName.substring(vmName.indexOf(".") + 1, vmName.length);
|
||||
const result = hljs.highlight(language, code || "", true);
|
||||
return result.value || ' ';
|
||||
},
|
||||
/** 查询接口类名列表 */
|
||||
getList() {
|
||||
this.loading = true;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.hchyun.web.core.config;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
|
@ -23,22 +24,27 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
|||
|
||||
/**
|
||||
* Swagger2的接口配置
|
||||
*
|
||||
*
|
||||
* @author hchyun
|
||||
*/
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
public class SwaggerConfig
|
||||
{
|
||||
/** 系统基础配置 */
|
||||
public class SwaggerConfig {
|
||||
/**
|
||||
* 系统基础配置
|
||||
*/
|
||||
@Autowired
|
||||
private HchYunConfig hchYunConfig;
|
||||
|
||||
/** 是否开启swagger */
|
||||
/**
|
||||
* 是否开启swagger
|
||||
*/
|
||||
@Value("${swagger.enabled}")
|
||||
private boolean enabled;
|
||||
|
||||
/** 设置请求的统一前缀 */
|
||||
/**
|
||||
* 设置请求的统一前缀
|
||||
*/
|
||||
@Value("${swagger.pathMapping}")
|
||||
private String pathMapping;
|
||||
|
||||
|
|
@ -46,8 +52,7 @@ public class SwaggerConfig
|
|||
* 创建API
|
||||
*/
|
||||
@Bean
|
||||
public Docket createRestApi()
|
||||
{
|
||||
public Docket createRestApi() {
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
// 是否启用Swagger
|
||||
.enable(enabled)
|
||||
|
|
@ -72,8 +77,7 @@ public class SwaggerConfig
|
|||
/**
|
||||
* 安全模式,这里指定token通过Authorization头请求头传递
|
||||
*/
|
||||
private List<ApiKey> securitySchemes()
|
||||
{
|
||||
private List<ApiKey> securitySchemes() {
|
||||
List<ApiKey> apiKeyList = new ArrayList<ApiKey>();
|
||||
apiKeyList.add(new ApiKey("Authorization", "Authorization", "header"));
|
||||
return apiKeyList;
|
||||
|
|
@ -82,8 +86,7 @@ public class SwaggerConfig
|
|||
/**
|
||||
* 安全上下文
|
||||
*/
|
||||
private List<SecurityContext> securityContexts()
|
||||
{
|
||||
private List<SecurityContext> securityContexts() {
|
||||
List<SecurityContext> securityContexts = new ArrayList<>();
|
||||
securityContexts.add(
|
||||
SecurityContext.builder()
|
||||
|
|
@ -96,8 +99,7 @@ public class SwaggerConfig
|
|||
/**
|
||||
* 默认的安全上引用
|
||||
*/
|
||||
private List<SecurityReference> defaultAuth()
|
||||
{
|
||||
private List<SecurityReference> defaultAuth() {
|
||||
AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
|
||||
AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
|
||||
authorizationScopes[0] = authorizationScope;
|
||||
|
|
@ -109,8 +111,7 @@ public class SwaggerConfig
|
|||
/**
|
||||
* 添加摘要信息
|
||||
*/
|
||||
private ApiInfo apiInfo()
|
||||
{
|
||||
private ApiInfo apiInfo() {
|
||||
// 用ApiInfoBuilder进行定制
|
||||
return new ApiInfoBuilder()
|
||||
// 设置标题
|
||||
|
|
|
|||
|
|
@ -205,11 +205,14 @@ public class InterTableServiceImpl implements InterTableService {
|
|||
StringWriter sw = new StringWriter();
|
||||
Template template = Velocity.getTemplate(templates, Constants.UTF8);
|
||||
template.merge(context,sw);
|
||||
dataMap.put(templates,sw.toString());
|
||||
dataMap.put(getJavaClassName(apiclass.getcName()),sw.toString());
|
||||
return new ServerResult<Map<String, String>>(true,dataMap);
|
||||
}catch (RuntimeException e){
|
||||
logger.error(e.getMessage());
|
||||
return new ServerResult<Map<String,String>>(false,ReturnConstants.DB_EX);
|
||||
}
|
||||
}
|
||||
public String getJavaClassName(String cName){
|
||||
return InterTableUtils.getUpperCase(cName) + "Controller.java";
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ package com.hchyun.generator.util;
|
|||
|
||||
import com.hchyun.common.utils.DateUtils;
|
||||
import com.hchyun.generator.entity.Apiclass;
|
||||
import com.hchyun.generator.entity.InterTable;
|
||||
import org.apache.velocity.VelocityContext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -10,11 +11,18 @@ import java.util.List;
|
|||
public class InterTableUtils {
|
||||
public static VelocityContext prepareClassContext(Apiclass apiclass) {
|
||||
VelocityContext velocityContext = new VelocityContext();
|
||||
boolean permission = false;
|
||||
for (InterTable interTable: apiclass.getInterTables() ) {
|
||||
if (interTable.getIsPermission().equals("1")){
|
||||
permission = true;
|
||||
}
|
||||
}
|
||||
velocityContext.put("Permission",permission);
|
||||
velocityContext.put("packageName", apiclass.getPackageName());
|
||||
velocityContext.put("ClassName", getUpperCase(apiclass.getcName()));
|
||||
velocityContext.put("columns", apiclass.getInterTables());
|
||||
velocityContext.put("prefix", apiclass.getPrefix());
|
||||
velocityContext.put("reqMapping", getLowerCase(apiclass.getcName()));
|
||||
velocityContext.put("reqMapping", getClassUrl(apiclass.getcName(),apiclass.getModule().getmName()));
|
||||
velocityContext.put("functionName", apiclass.getcDescribe());
|
||||
velocityContext.put("author", apiclass.getAuthor());
|
||||
velocityContext.put("emali", apiclass.getEmail());
|
||||
|
|
@ -22,6 +30,9 @@ public class InterTableUtils {
|
|||
return velocityContext;
|
||||
}
|
||||
|
||||
public static String getClassUrl(String cname,String mname){
|
||||
return "/"+getLowerCase(mname)+"/"+getLowerCase(cname);
|
||||
}
|
||||
public static String getTemplateList(Integer type) {
|
||||
String templates = "vm/java/class.java.vm";
|
||||
if (type == 1) {
|
||||
|
|
@ -34,6 +45,6 @@ public class InterTableUtils {
|
|||
return str.substring(0,1).toUpperCase() + str.substring(1);
|
||||
}
|
||||
public static String getLowerCase(String str){
|
||||
return str.substring(0,1).toUpperCase()+str.substring(1);
|
||||
return str.substring(0,1).toLowerCase()+str.substring(1);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,9 +54,24 @@
|
|||
<result property="createBy" column="create_by" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
<collection property="interTables" javaType="java.util.List" notNullColumn="id" resultMap="InterTableResult"/>
|
||||
<collection property="interTables" javaType="java.util.List" notNullColumn="id" resultMap="InterTableClassResult"/>
|
||||
<collection property="module" javaType="com.hchyun.generator.entity.Module" notNullColumn="m_id" resultMap="ModuleResult"/>
|
||||
</resultMap>
|
||||
<resultMap type="com.hchyun.generator.entity.InterTable" id="InterTableClassResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="mId" column="m_id" />
|
||||
<result property="cId" column="c_id" />
|
||||
<result property="itName" column="it_name" />
|
||||
<result property="itDescribe" column="it_describe" />
|
||||
<result property="isPermission" column="is_permission" />
|
||||
<result property="requrl" column="requrl" />
|
||||
<result property="method" column="method" />
|
||||
<result property="type" column="type" />
|
||||
<result property="mName" column="m_name" />
|
||||
<result property="isGenerate" column="is_generate" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="createBy" column="create_by" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectInterTableVo">
|
||||
select id, m_id, c_id, it_name, it_describe, is_permission, requrl, method, is_generate, type, create_time, create_by from sys_inter_table
|
||||
|
|
|
|||
|
|
@ -7,5 +7,52 @@ package ${packageName}controller;
|
|||
* @Email ${emali}
|
||||
* @Date ${time}
|
||||
*/
|
||||
import com.hchyun.common.constant.ReturnConstants;
|
||||
import com.hchyun.common.core.controller.BaseController;
|
||||
import com.hchyun.common.core.entity.AjaxResult;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Map;
|
||||
#if($Permission)
|
||||
@Api("${functionName}")
|
||||
#end
|
||||
@RestController
|
||||
@RequestMapping("${reqMapping}")
|
||||
public class ${ClassName}Controller extends BaseController{
|
||||
private final Logger logger = LoggerFactory.getLogger(${ClassName}Controller.class);
|
||||
|
||||
#foreach($column in $columns)
|
||||
#if($column.isGenerate.equals("1"))
|
||||
#set($InterName = $column.itName.substring(0,1).toUpperCase() + ${column.itName.substring(1)})
|
||||
/**
|
||||
* ${column.itDescribe}
|
||||
*/
|
||||
@ApiOperation("${column.itDescribe}")
|
||||
#if($column.isPermission.equals("1"))
|
||||
@PreAuthorize("@ss.hasPermi('${prefix}:${column.requrl}')")
|
||||
@Log(title = "${column.itDescribe}", businessType = BusinessType.INSERT)
|
||||
#end
|
||||
@${column.method}Mapping("/${column.requrl}")
|
||||
public AjaxResult ${InterName} (@RequestBody Map<String,String> parms){
|
||||
try {
|
||||
return AjaxResult.success("${column.itDescribe}测试!");
|
||||
}catch (RuntimeException e){
|
||||
logger.error(e.getMessage());
|
||||
return AjaxResult.error(ReturnConstants.DB_EX);
|
||||
}
|
||||
}
|
||||
#end
|
||||
#end
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue