This commit is contained in:
parent
8f7ea27575
commit
e8fe91ed6e
|
|
@ -104,7 +104,7 @@ public class InterTableController extends HcyBaseController {
|
||||||
dataMap.put("Test02.java","Test02.java");
|
dataMap.put("Test02.java","Test02.java");
|
||||||
dataMap.put("Test03.java","Test03.java");
|
dataMap.put("Test03.java","Test03.java");
|
||||||
dataMap.put("Test04.java","Test04.java");
|
dataMap.put("Test04.java","Test04.java");
|
||||||
ServerResult<Map<String,String>> serverResult = interTableService.previewCodeMoudle(id);
|
ServerResult<Map<String,Object>> serverResult = interTableService.previewCodeMoudle(id);
|
||||||
return AjaxResult.success(dataMap);
|
return AjaxResult.success(dataMap);
|
||||||
}catch (RuntimeException e){
|
}catch (RuntimeException e){
|
||||||
logger.error(e.getMessage());
|
logger.error(e.getMessage());
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,9 @@ public class SysTest {
|
||||||
return interTableService.previewCodeCalss(3L).getData();
|
return interTableService.previewCodeCalss(3L).getData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/4")
|
||||||
|
public Map<String,Object> test4(){
|
||||||
|
return interTableService.previewCodeMoudle(3L).getData();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import io.swagger.annotations.ApiModel;
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -76,6 +77,9 @@ public class Apiclass extends BaseEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setInterTables(List<InterTable> interTables) {
|
public void setInterTables(List<InterTable> interTables) {
|
||||||
|
if (interTables == null){
|
||||||
|
interTables = new ArrayList<InterTable>();
|
||||||
|
}
|
||||||
this.interTables = interTables;
|
this.interTables = interTables;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
package com.hchyun.generator.service;
|
package com.hchyun.generator.service;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.hchyun.common.utils.ServerResult;
|
import com.hchyun.common.utils.ServerResult;
|
||||||
|
|
@ -71,7 +70,7 @@ public interface InterTableService
|
||||||
*/
|
*/
|
||||||
ServerResult<Map<String,String>> previewCodeCalss(Long cid);
|
ServerResult<Map<String,String>> previewCodeCalss(Long cid);
|
||||||
|
|
||||||
ServerResult<Map<String,String>> previewCodeMoudle(Long mid);
|
ServerResult<Map<String,Object>> previewCodeMoudle(Long mid);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -213,18 +213,25 @@ public class InterTableServiceImpl implements InterTableService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ServerResult<Map<String, String>> previewCodeMoudle(Long mid) {
|
public ServerResult<Map<String, Object>> previewCodeMoudle(Long mid) {
|
||||||
try {
|
try {
|
||||||
Map<String,String> dataMap = new LinkedHashMap<String,String>();
|
Map<String,Object> dataMap = new LinkedHashMap<String,Object>();
|
||||||
List<InterTable> interTableList = interTableDao.selectInterTableModule(mid);
|
List<InterTable> interTableList = interTableDao.selectInterTableModule(mid);
|
||||||
VelocityInitializer.initVelocity();
|
VelocityInitializer.initVelocity();
|
||||||
VelocityContext context = InterTableUtils.prepareMoudleContext(interTableList);
|
List<VelocityContext> contextList = InterTableUtils.prepareMoudleContext(interTableList);
|
||||||
|
String templates = InterTableUtils.getTemplateList(1);
|
||||||
|
for (VelocityContext context : contextList){
|
||||||
|
StringWriter sw = new StringWriter();
|
||||||
|
Template template = Velocity.getTemplate(templates, Constants.UTF8);
|
||||||
|
template.merge(context,sw);
|
||||||
|
dataMap.put(getJavaClassName(context.get("ClassName")),sw.toString());
|
||||||
|
}
|
||||||
|
dataMap.put("data",contextList);
|
||||||
|
return new ServerResult<Map<String,Object>>(true,dataMap);
|
||||||
}catch (RuntimeException e){
|
}catch (RuntimeException e){
|
||||||
logger.error(e.getMessage());
|
logger.error(e.getMessage());
|
||||||
return new ServerResult<Map<String,String>>(false,ReturnConstants.DB_EX);
|
return new ServerResult<Map<String,Object>>(false,ReturnConstants.DB_EX);
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getJavaClassName(String cName){
|
public String getJavaClassName(String cName){
|
||||||
|
|
|
||||||
|
|
@ -9,24 +9,83 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class InterTableUtils {
|
public class InterTableUtils {
|
||||||
public static VelocityContext prepareMoudleContext(List<InterTable> interTableList){
|
public static List<VelocityContext> prepareMoudleContext(List<InterTable> interTableList) {
|
||||||
|
List<Apiclass> apiclassList = new ArrayList<Apiclass>();
|
||||||
|
for (int i = 0; i < interTableList.size(); i++) {
|
||||||
|
InterTable interTable = interTableList.get(i);
|
||||||
|
if (apiclassList.size() == 0) {
|
||||||
|
Apiclass apiclass = interTable.getApiclass();
|
||||||
|
List<InterTable> interTables = new ArrayList<InterTable>();
|
||||||
|
interTable.setApiclass(null);
|
||||||
|
interTables.add(interTable);
|
||||||
|
apiclass.setInterTables(interTables);
|
||||||
|
apiclassList.add(apiclass);
|
||||||
|
} else {
|
||||||
|
boolean start = true;
|
||||||
|
for (int j = 0; j < apiclassList.size(); j++) {
|
||||||
|
Apiclass api = apiclassList.get(j);
|
||||||
|
if (interTable.getcId() == api.getId()) {
|
||||||
|
List<InterTable> interTableList1 = api.getInterTables();
|
||||||
|
interTable.setApiclass(null);
|
||||||
|
interTableList1.add(interTable);
|
||||||
|
api.setInterTables(interTableList1);
|
||||||
|
apiclassList.set(j, api);
|
||||||
|
start = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (start) {
|
||||||
|
Apiclass apiclass = interTable.getApiclass();
|
||||||
|
List<InterTable> interTables = new ArrayList<InterTable>();
|
||||||
|
interTable.setApiclass(null);
|
||||||
|
interTables.add(interTable);
|
||||||
|
apiclass.setInterTables(interTables);
|
||||||
|
apiclassList.add(apiclass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
List<VelocityContext> contextList = new ArrayList<VelocityContext>();
|
||||||
|
for (int i = 0; i < apiclassList.size(); i++){
|
||||||
|
Apiclass apiclass = apiclassList.get(i);
|
||||||
|
VelocityContext velocityContext = new VelocityContext();
|
||||||
|
String module = apiclass.getInterTables().get(0).getmName();
|
||||||
|
String className = apiclass.getcName();
|
||||||
|
boolean permission = false;
|
||||||
|
for (InterTable interTable : apiclass.getInterTables()) {
|
||||||
|
if (interTable.getIsPermission().equals("1")) {
|
||||||
|
permission = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
velocityContext.put("Permission", permission);
|
||||||
|
velocityContext.put("packageName", "com.huhyun."+module);
|
||||||
|
velocityContext.put("prefix",module+":"+getLowerCase(className));
|
||||||
|
velocityContext.put("ClassName",getUpperCase(className));
|
||||||
|
velocityContext.put("columns", apiclass.getInterTables());
|
||||||
|
velocityContext.put("reqMapping","/"+module+"/"+getLowerCase(className));
|
||||||
|
velocityContext.put("functionName",apiclass.getcDescribe());
|
||||||
|
velocityContext.put("author", apiclass.getAuthor());
|
||||||
|
velocityContext.put("emali", apiclass.getEmail());
|
||||||
|
velocityContext.put("time", DateUtils.getTime());
|
||||||
|
contextList.add(velocityContext);
|
||||||
|
|
||||||
return new VelocityContext();
|
}
|
||||||
|
return contextList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static VelocityContext prepareClassContext(Apiclass apiclass) {
|
public static VelocityContext prepareClassContext(Apiclass apiclass) {
|
||||||
VelocityContext velocityContext = new VelocityContext();
|
VelocityContext velocityContext = new VelocityContext();
|
||||||
boolean permission = false;
|
boolean permission = false;
|
||||||
for (InterTable interTable: apiclass.getInterTables() ) {
|
for (InterTable interTable : apiclass.getInterTables()) {
|
||||||
if (interTable.getIsPermission().equals("1")){
|
if (interTable.getIsPermission().equals("1")) {
|
||||||
permission = true;
|
permission = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
velocityContext.put("Permission",permission);
|
velocityContext.put("Permission", permission);
|
||||||
velocityContext.put("packageName", apiclass.getPackageName());
|
velocityContext.put("packageName", apiclass.getPackageName());
|
||||||
velocityContext.put("ClassName", getUpperCase(apiclass.getcName()));
|
velocityContext.put("ClassName", getUpperCase(apiclass.getcName()));
|
||||||
velocityContext.put("columns", apiclass.getInterTables());
|
velocityContext.put("columns", apiclass.getInterTables());
|
||||||
velocityContext.put("prefix", apiclass.getPrefix());
|
velocityContext.put("prefix", apiclass.getPrefix());
|
||||||
velocityContext.put("reqMapping", getClassUrl(apiclass.getcName(),apiclass.getModule().getmName()));
|
velocityContext.put("reqMapping", getClassUrl(apiclass.getcName(), apiclass.getModule().getmName()));
|
||||||
velocityContext.put("functionName", apiclass.getcDescribe());
|
velocityContext.put("functionName", apiclass.getcDescribe());
|
||||||
velocityContext.put("author", apiclass.getAuthor());
|
velocityContext.put("author", apiclass.getAuthor());
|
||||||
velocityContext.put("emali", apiclass.getEmail());
|
velocityContext.put("emali", apiclass.getEmail());
|
||||||
|
|
@ -34,9 +93,10 @@ public class InterTableUtils {
|
||||||
return velocityContext;
|
return velocityContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getClassUrl(String cname,String mname){
|
public static String getClassUrl(String cname, String mname) {
|
||||||
return "/"+getLowerCase(mname)+"/"+getLowerCase(cname);
|
return "/" + getLowerCase(mname) + "/" + getLowerCase(cname);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getTemplateList(Integer type) {
|
public static String getTemplateList(Integer type) {
|
||||||
String templates = "vm/java/class.java.vm";
|
String templates = "vm/java/class.java.vm";
|
||||||
if (type == 1) {
|
if (type == 1) {
|
||||||
|
|
@ -45,10 +105,11 @@ public class InterTableUtils {
|
||||||
return templates;
|
return templates;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getUpperCase(String str){
|
public static String getUpperCase(String str) {
|
||||||
return str.substring(0,1).toUpperCase() + str.substring(1);
|
return str.substring(0, 1).toUpperCase() + str.substring(1);
|
||||||
}
|
}
|
||||||
public static String getLowerCase(String str){
|
|
||||||
return str.substring(0,1).toLowerCase()+str.substring(1);
|
public static String getLowerCase(String str) {
|
||||||
|
return str.substring(0, 1).toLowerCase() + str.substring(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
<collection property="apiclass" javaType="com.hchyun.generator.entity.Apiclass" resultMap="ModuleApiclassResult" notNullColumn="c_id"/>
|
<collection property="apiclass" javaType="com.hchyun.generator.entity.Apiclass" resultMap="ModuleApiclassResult" notNullColumn="c_id"/>
|
||||||
</resultMap>
|
</resultMap>
|
||||||
<resultMap type="com.hchyun.generator.entity.Apiclass" id="ModuleApiclassResult">
|
<resultMap type="com.hchyun.generator.entity.Apiclass" id="ModuleApiclassResult">
|
||||||
<result property="id" column="id" />
|
<result property="id" column="class_id" />
|
||||||
<result property="mId" column="m_id" />
|
<result property="mId" column="m_id" />
|
||||||
<result property="cName" column="c_name" />
|
<result property="cName" column="c_name" />
|
||||||
<result property="cDescribe" column="c_describe" />
|
<result property="cDescribe" column="c_describe" />
|
||||||
|
|
@ -85,7 +85,8 @@
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectInterTableModule" resultMap="InterTableResult" parameterType="Long">
|
<select id="selectInterTableModule" resultMap="InterTableResult" parameterType="Long">
|
||||||
SELECT (select m_name from sys_module sm WHERE sm.id=sit.m_id) AS m_name, sit.*, sa.*
|
SELECT (select m_name from sys_module sm WHERE sm.id=sit.m_id) AS m_name, sit.*,
|
||||||
|
sa.id as class_id, sa.m_id, sa.c_name, sa.c_describe, sa.package_name, sa.author, sa.email, sa.prefix, sa.remark, sa.create_time, sa.create_by, sa.update_time, sa.update_by
|
||||||
from sys_inter_table sit
|
from sys_inter_table sit
|
||||||
LEFT JOIN sys_apiclass sa ON sa.id = sit.c_id
|
LEFT JOIN sys_apiclass sa ON sa.id = sit.c_id
|
||||||
WHERE sit.m_id=#{id} AND sit.type = 1;
|
WHERE sit.m_id=#{id} AND sit.type = 1;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue