This commit is contained in:
20932067@zju.edu.cn 2021-01-27 16:53:18 +08:00
parent 3974bdb7f3
commit b16866d43e
7 changed files with 117 additions and 4 deletions

View File

@ -3,8 +3,8 @@ ENV = 'development'
# 宏驰云管理系统/开发环境
#VUE_APP_BASE_API = '/dev-api'
VUE_APP_BASE_API = 'http://localhost:8085/dev-api'
#VUE_APP_BASE_API = 'http://apibase.hchyun.com/dev-api'
#VUE_APP_BASE_API = 'http://localhost:8085/dev-api'
VUE_APP_BASE_API = 'http://apibase.hchyun.com/dev-api'
# 路由懒加载
VUE_CLI_BABEL_TRANSPILE_MODULES = true

View File

@ -12,6 +12,8 @@ import com.hchyun.common.utils.ServerResult;
import com.hchyun.generator.dto.InterTableDto;
import com.hchyun.generator.entity.Apiclass;
import com.hchyun.generator.service.ApiclassService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.prepost.PreAuthorize;
@ -38,6 +40,8 @@ import com.hchyun.common.utils.poi.ExcelUtil;
* @author hchyun
* @date 2021-01-25
*/
@Api("接口信息")
@RestController
@RequestMapping("/generator/intertable")
public class InterTableController extends HcyBaseController {
@ -67,6 +71,26 @@ public class InterTableController extends HcyBaseController {
}
}
/**
* 预览代码(工作流)
*/
@ApiOperation("预览代码测试")
@GetMapping("/classpreview/{id}")
public AjaxResult classPreview(@PathVariable("id") Long id){
try {
ServerResult<Map<String,String>> serverResult = interTableService.previewCodeCalss(id);
if (serverResult.isStart()){
return AjaxResult.success(serverResult.getData());
}else {
return AjaxResult.error(serverResult.getMsg());
}
}catch (RuntimeException e){
logger.error(e.getMessage());
return AjaxResult.error(ReturnConstants.SYS_ERROR);
}
}
// /**
// * 导出接口信息列表
// */

View File

@ -4,25 +4,38 @@ import com.hchyun.generator.dao.ApiclassDao;
import com.hchyun.generator.dao.InterTableDao;
import com.hchyun.generator.entity.Apiclass;
import com.hchyun.generator.entity.InterTable;
import com.hchyun.generator.service.InterTableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/test")
public class SysTest {
@Autowired
private InterTableDao interTableDao;
@Autowired
private InterTableService interTableService;
@GetMapping("/1")
public Apiclass test(){
public Apiclass test() {
return interTableDao.selectInterTableClass(3L);
}
@GetMapping("/2")
public List<InterTable> test2(){
public List<InterTable> test2() {
return interTableDao.selectInterTableModule(3L);
}
@GetMapping("/3")
public Map<String, String> test3(){
return interTableService.previewCodeCalss(3L).getData();
}
}

View File

@ -62,4 +62,6 @@ public interface InterTableService
* @return 结果
*/
ServerResult<Integer> deleteInterTableById(Long id);
ServerResult<Map<String,String>> previewCodeCalss(Long cid);
}

View File

@ -1,9 +1,12 @@
package com.hchyun.generator.service.impl;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import com.hchyun.common.constant.Constants;
import com.hchyun.common.constant.ReturnConstants;
import com.hchyun.common.utils.SecurityUtils;
import com.hchyun.common.utils.ServerResult;
@ -12,6 +15,12 @@ import com.hchyun.generator.dao.ModuleDao;
import com.hchyun.generator.dto.InterTableDto;
import com.hchyun.generator.entity.Apiclass;
import com.hchyun.generator.entity.Module;
import com.hchyun.generator.util.InterTableUtils;
import com.hchyun.generator.util.VelocityInitializer;
import com.sun.org.apache.regexp.internal.RE;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -184,4 +193,23 @@ public class InterTableServiceImpl implements InterTableService {
return new ServerResult<Integer>(false, ReturnConstants.DB_EX);
}
}
@Override
public ServerResult<Map<String, String>> previewCodeCalss(Long cid) {
try {
Map<String,String> dataMap = new LinkedHashMap<String, String>();
Apiclass apiclass = interTableDao.selectInterTableClass(cid);
VelocityInitializer.initVelocity();
VelocityContext context = InterTableUtils.prepareClassContext(apiclass);
String templates = InterTableUtils.getTemplateList(2);
StringWriter sw = new StringWriter();
Template template = Velocity.getTemplate(templates, Constants.UTF8);
template.merge(context,sw);
dataMap.put(templates,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);
}
}
}

View File

@ -1,4 +1,39 @@
package com.hchyun.generator.util;
import com.hchyun.common.utils.DateUtils;
import com.hchyun.generator.entity.Apiclass;
import org.apache.velocity.VelocityContext;
import java.util.ArrayList;
import java.util.List;
public class InterTableUtils {
public static VelocityContext prepareClassContext(Apiclass apiclass) {
VelocityContext velocityContext = new VelocityContext();
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("functionName", apiclass.getcDescribe());
velocityContext.put("author", apiclass.getAuthor());
velocityContext.put("emali", apiclass.getEmail());
velocityContext.put("time", DateUtils.getTime());
return velocityContext;
}
public static String getTemplateList(Integer type) {
String templates = "vm/java/class.java.vm";
if (type == 1) {
templates = "vm/java/module.java.vm";
}
return templates;
}
public static String getUpperCase(String str){
return str.substring(0,1).toUpperCase() + str.substring(1);
}
public static String getLowerCase(String str){
return str.substring(0,1).toUpperCase()+str.substring(1);
}
}

View File

@ -0,0 +1,11 @@
package ${packageName}controller;
/**
* ${ClassName} ${functionName}
*
* @Author ${author}
* @Email ${emali}
* @Date ${time}
*/