郑根木 пре 2 година
родитељ
комит
028eaa2c1d
17 измењених фајлова са 615 додато и 113 уклоњено
  1. +54
    -0
      smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/cache/AbstractEntityCache.java
  2. +18
    -15
      smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/common/SwEnum.java
  3. +5
    -1
      smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/db/vo/ModelIndex.java
  4. +0
    -6
      smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/spring/BpmConfigBean.java
  5. +91
    -75
      smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/util/CodeGenUtil.java
  6. +37
    -5
      smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/util/CodeGenerator.java
  7. +73
    -0
      smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/util/IdeaUtil.java
  8. +12
    -0
      smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/util/XmlUtil.java
  9. +163
    -0
      smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/CodeBuildHandler.java
  10. +2
    -1
      smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormCache.java
  11. +13
    -1
      smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormService.java
  12. +0
    -3
      smtweb-system/sw-system-bpm/src/main/resources/config/application-dev.yaml
  13. +1
    -6
      smtweb-system/sw-system-bpm/src/main/resources/config/application.yaml
  14. +42
    -0
      smtweb-system/sw-system-bpm/src/main/resources/static/template/java_bean.ftl
  15. +51
    -0
      smtweb-system/sw-system-bpm/src/main/resources/static/template/java_cache.ftl
  16. +30
    -0
      smtweb-system/sw-system-bpm/src/main/resources/static/template/java_service.ftl
  17. +23
    -0
      smtweb-system/sw-system-bpm/src/test/java/cc/smtweb/system/bpm/test/ModelFormTest.java

+ 54
- 0
smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/cache/AbstractEntityCache.java Прегледај датотеку

@@ -0,0 +1,54 @@
package cc.smtweb.framework.core.cache;

import cc.smtweb.framework.core.common.SwConsts;
import cc.smtweb.framework.core.db.DbEngine;
import cc.smtweb.framework.core.db.EntityDao;
import cc.smtweb.framework.core.db.impl.DefaultEntity;

import java.util.List;

/**
* Created by Akmm at 2022/6/16 15:53
*/
public class AbstractEntityCache<T extends DefaultEntity> extends AbstractCache<T> {
@Override
protected String getId(T bean) {
return String.valueOf(bean.getEntityId());
}

private String getCacheKey(T bean, String fields) {
String[] fs = fields.split(",");
String ret = "";
for (String f: fs) {
ret += SwConsts.SPLIT_CHAR + bean.getStr(f);
}
return ret.substring(SwConsts.SPLIT_CHAR.length());
}

/**
* 注册其他key的List缓存,如tree的children
*
* @param key
* @param fields
*/
protected void regList(String key, String fields) {
regList(key, bean -> getCacheKey(bean, fields));
}

/**
* 注册其他key的Map缓存,如按code缓存
*
* @param key
* @param fields
*/

protected void regMap(String key, String fields) {
regMap(key, bean -> getCacheKey(bean, fields));
}

@Override
protected List<T> loadAll() {
EntityDao<T> dao = DbEngine.getInstance().findDao(pTypeClass);
return dao.query();
}
}

+ 18
- 15
smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/common/SwEnum.java Прегледај датотеку

@@ -86,16 +86,18 @@ public interface SwEnum {
public String sqlType;
public int dataLength;
public String javaType;
public String shortJavaType;
//java.sql.Types里的值
public int type;
public String defaultValue;
public String editor;

public DataTypeBean(String value, String name, String sqlType, int dataLength, String javaType, int type, String defaultValue, String editor) {
public DataTypeBean(String value, String name, String sqlType, int dataLength, String javaType, String shortJavaType, int type, String defaultValue, String editor) {
super(value, name);
this.sqlType = sqlType;
this.dataLength = dataLength;
this.javaType = javaType;
this.shortJavaType = shortJavaType;
this.defaultValue = defaultValue;
this.editor = editor;
this.type = type;
@@ -105,6 +107,7 @@ public interface SwEnum {
if (dataLength > 0) return sqlType + "(" + dataLength + ")";
return sqlType;
}

}

/**
@@ -116,26 +119,26 @@ public interface SwEnum {
public final static String TYPE_DATETIME = "datetime";

public static DataType instance = new DataType();
public static DataTypeBean ID = instance.addEnum("id", "ID", "bigint", 0, "long", Types.BIGINT, "", EditorType.INPUT.value);
public static DataTypeBean CODE = instance.addEnum("code", "编码", "varchar", 32, "string", Types.VARCHAR, "", EditorType.INPUT.value);
public static DataTypeBean NAME = instance.addEnum("name", "名称", "varchar", 100, "string", Types.VARCHAR, "", EditorType.INPUT.value);
public static DataTypeBean REMARK = instance.addEnum("remark", "备注", "varchar", 255, "string", Types.VARCHAR, "", EditorType.INPUT.value);
public static DataTypeBean TEXT = instance.addEnum("text", "大文本", "text", 0, "string", Types.CLOB, "", EditorType.TEXT.value);
public static DataTypeBean INT = instance.addEnum("int", "整型", "int", 0, "int", Types.INTEGER, "0", EditorType.NUMBER.value);
public static DataTypeBean SHORT = instance.addEnum("short", "短整型", "smallint", 0, "short", Types.SMALLINT, "0", EditorType.NUMBER.value);
public static DataTypeBean BOOL = instance.addEnum("bool", "布尔型", "tinyint", 0, "boolean", Types.TINYINT, "0", EditorType.SWITCH.value);
public static DataTypeBean CURRENCY = instance.addEnum("currency", "金额型", "bigint", 0, "long", Types.BIGINT, "0", EditorType.NUMBER.value);
public static DataTypeBean DATE = instance.addEnum("date", "日期型", "bigint", 0, "long", Types.BIGINT, "0", EditorType.DATE.value);
public static DataTypeBean TIME = instance.addEnum("time", "时间型", "bigint", 0, "long", Types.BIGINT, "0", EditorType.TIME.value);
public static DataTypeBean DATETIME = instance.addEnum("datetime", "日期时间型", "bigint", 0, "long", Types.BIGINT, "0", EditorType.DATETIME.value);
public static DataTypeBean ID = instance.addEnum("id", "ID", "bigint", 0, "long", "Long", Types.BIGINT, "", EditorType.INPUT.value);
public static DataTypeBean CODE = instance.addEnum("code", "编码", "varchar", 32, "String", "Str", Types.VARCHAR, "", EditorType.INPUT.value);
public static DataTypeBean NAME = instance.addEnum("name", "名称", "varchar", 100, "String", "Str", Types.VARCHAR, "", EditorType.INPUT.value);
public static DataTypeBean REMARK = instance.addEnum("remark", "备注", "varchar", 255, "String", "Str", Types.VARCHAR, "", EditorType.INPUT.value);
public static DataTypeBean TEXT = instance.addEnum("text", "大文本", "text", 0, "String", "Str", Types.CLOB, "", EditorType.TEXT.value);
public static DataTypeBean INT = instance.addEnum("int", "整型", "int", 0, "int", "Int", Types.INTEGER, "0", EditorType.NUMBER.value);
public static DataTypeBean SHORT = instance.addEnum("short", "短整型", "smallint", 0, "int", "Int", Types.SMALLINT, "0", EditorType.NUMBER.value);
public static DataTypeBean BOOL = instance.addEnum("bool", "布尔型", "tinyint", 0, "boolean", "Bool", Types.TINYINT, "0", EditorType.SWITCH.value);
public static DataTypeBean CURRENCY = instance.addEnum("currency", "金额型", "bigint", 0, "long", "Long", Types.BIGINT, "0", EditorType.NUMBER.value);
public static DataTypeBean DATE = instance.addEnum("date", "日期型", "bigint", 0, "long","Long", Types.BIGINT, "0", EditorType.DATE.value);
public static DataTypeBean TIME = instance.addEnum("time", "时间型", "bigint", 0, "long", "Long", Types.BIGINT, "0", EditorType.TIME.value);
public static DataTypeBean DATETIME = instance.addEnum("datetime", "日期时间型", "bigint", 0, "long", "Long", Types.BIGINT, "0", EditorType.DATETIME.value);

@Override
protected DataTypeBean buildBean(String value, String name) {
return null;
}

public DataTypeBean addEnum(String value, String name, String sqlType, int dataLength, String javaType, int type, String defaultValue, String editor) {
final DataTypeBean bean = new DataTypeBean(value, name, sqlType, dataLength, javaType, type, defaultValue, editor);
public DataTypeBean addEnum(String value, String name, String sqlType, int dataLength, String javaType, String shortJavaType, int type, String defaultValue, String editor) {
final DataTypeBean bean = new DataTypeBean(value, name, sqlType, dataLength, javaType, shortJavaType, type, defaultValue, editor);
mapAll.put(value, bean);
return bean;
}


+ 5
- 1
smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/db/vo/ModelIndex.java Прегледај датотеку

@@ -1,6 +1,7 @@
package cc.smtweb.framework.core.db.vo;

import lombok.Data;
import org.apache.commons.codec.digest.DigestUtils;

/**
* 索引定义 {name:"索引名称,如idx_t1", fields:"字段,如f1,f2", type="索引类别:P-主键 I-一般索引 U-唯一索引"}
@@ -12,10 +13,13 @@ public class ModelIndex {
public static final String TYPE_UNIQUE = "U";

private String type;
private String name;
private String fields;

public boolean isUnique() {
return TYPE_UNIQUE.equals(type);
}

public String getName() {
return DigestUtils.md5Hex(fields).substring(0, 16);
}
}

+ 0
- 6
smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/spring/BpmConfigBean.java Прегледај датотеку

@@ -10,11 +10,5 @@ import org.springframework.stereotype.Component;
public class BpmConfigBean {
// 是否debug模式
private boolean debug;
private boolean codeBuild;
private String codeVuePath;
private String codeVueDir;
private String codeJavaPath;
private String codeJavaPackage;
/** UI控件扩展定义路径 */
private String configUiPath;
}

+ 91
- 75
smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/util/CodeGenUtil.java Прегледај датотеку

@@ -3,93 +3,109 @@ package cc.smtweb.system.bpm.util;
import org.apache.commons.lang3.StringUtils;

public class CodeGenUtil {
private CodeGenUtil() {}
private CodeGenUtil() {
}

/***
* 下划线命名转为驼峰命名
*
* @param para
* 下划线命名的字符串
*/
public static String underlineToHump(String para){
StringBuilder result=new StringBuilder();
String[] a = para.split("_");
for(String s:a){
if(result.length() == 0){
result.append(s.toLowerCase());
}else{
result.append(s.substring(0, 1).toUpperCase());
result.append(s.substring(1).toLowerCase());
}
/***
* 下划线命名转为驼峰命名
*
* @param para
* 下划线命名的字符串
*/
public static String underlineToHump(String para) {
StringBuilder result = new StringBuilder();
String[] a = para.split("_");
for (String s : a) {
if (result.length() == 0) {
result.append(s.toLowerCase());
} else {
result.append(s.substring(0, 1).toUpperCase());
result.append(s.substring(1).toLowerCase());
}
}
return result.toString();
}
return result.toString();
}

/***
* 下划线命名转为大写驼峰命名
* 大驼峰式命名法(upper camel case)
*
* @param para
* 下划线命名的字符串
*/
public static String underlineToUpperHump(String para){
StringBuilder result=new StringBuilder();
String[] a = para.split("_");
for(String s : a){
result.append(s.substring(0, 1).toUpperCase());
result.append(s.substring(1).toLowerCase());
/***
* 下划线命名转为大写驼峰命名
* 大驼峰式命名法(upper camel case)
*
* @param para
* 下划线命名的字符串
*/
public static String underlineToUpperHump(String para) {
StringBuilder result = new StringBuilder();
String[] a = para.split("_");
for (String s : a) {
result.append(s.substring(0, 1).toUpperCase());
result.append(s.substring(1).toLowerCase());
}
return result.toString();
}
return result.toString();
}

/***
* 驼峰命名转为下划线命名
*
* @param para
* 驼峰命名的字符串
*/
public static String humpToUnderline(String para){
return humpTo(para, "_");
}
/***
* 驼峰命名转为下划线命名
*
* @param para
* 驼峰命名的字符串
*/
public static String humpToUnderline(String para) {
return humpTo(para, "_");
}

private static String humpTo(String para, String splitChar){
StringBuilder sb = new StringBuilder(para);
//偏移量,第i个下划线的位置是 当前的位置+ 偏移量(i-1),第一个下划线偏移量是0
int temp=0;
for(int i=0;i<para.length();i++){
if(Character.isUpperCase(para.charAt(i))){
sb.insert(i+temp, splitChar);
temp+=1;
}
private static String humpTo(String para, String splitChar) {
StringBuilder sb = new StringBuilder(para);
//偏移量,第i个下划线的位置是 当前的位置+ 偏移量(i-1),第一个下划线偏移量是0
int temp = 0;
for (int i = 0; i < para.length(); i++) {
if (Character.isUpperCase(para.charAt(i))) {
sb.insert(i + temp, splitChar);
temp += 1;
}
}
return sb.toString().toLowerCase();
}
return sb.toString().toLowerCase();
}

/***
* 驼峰命名转为横线线命名
*
* @param para
* 驼峰命名的字符串
*/
public static String humpToDash(String para){
return humpTo(para, "-");
}
/***
* 驼峰命名转为横线线命名
*
* @param para
* 驼峰命名的字符串
*/
public static String humpToDash(String para) {
return humpTo(para, "-");
}

/** 大驼峰转小驼峰 */
public static String toLowerHump(String name) {
if (StringUtils.isNotBlank(name)) {
return Character.toLowerCase(name.charAt(0)) + name.substring(1);
/**
* 大驼峰转小驼峰
*/
public static String toLowerHump(String name) {
if (StringUtils.isNotBlank(name)) {
return Character.toLowerCase(name.charAt(0)) + name.substring(1);
}

return "";
}

return "";
}
/**
* 小驼峰转大驼峰
*/
public static String toUpperHump(String name) {
if (StringUtils.isNotBlank(name)) {
return Character.toUpperCase(name.charAt(0)) + name.substring(1);
}

/** 小驼峰转大驼峰 */
public static String toUpperHump(String name) {
if (StringUtils.isNotBlank(name)) {
return Character.toUpperCase(name.charAt(0)) + name.substring(1);
return "";
}

return "";
}
public static String getBeanName(String tableName) {
StringBuilder result = new StringBuilder();
String[] a = tableName.split("_");
for (int i = 1, len = a.length; i < len; i++) {
String s = a[i];
result.append(s.substring(0, 1).toUpperCase());
result.append(s.substring(1).toLowerCase());
}
return result.toString();
}
}

+ 37
- 5
smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/util/CodeGenerator.java Прегледај датотеку

@@ -1,12 +1,20 @@
package cc.smtweb.system.bpm.util;

import cc.smtweb.framework.core.common.SwEnum;
import cc.smtweb.framework.core.common.SwException;
import cc.smtweb.framework.core.common.SwMap;
import cc.smtweb.framework.core.db.DbEngine;
import cc.smtweb.framework.core.db.cache.ModelTableCache;
import cc.smtweb.framework.core.db.vo.ModelField;
import cc.smtweb.framework.core.db.vo.ModelTable;
import cc.smtweb.framework.core.util.DateUtil;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateMethodModelEx;
import freemarker.template.TemplateModelException;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import sun.nio.ch.IOUtil;

import java.io.*;
import java.nio.charset.StandardCharsets;
@@ -21,6 +29,9 @@ import java.util.Map;
*/
public class CodeGenerator {
private final static String KEY_MODEL = "model";
private final static String TEMPLATE_JAVA_BEAN = "java_bean";
private final static String TEMPLATE_JAVA_CACHE = "java_cache";
private final static String TEMPLATE_JAVA_SERVICE = "java_service";
private static CodeGenerator instance = null;

private Configuration configuration = null;
@@ -69,16 +80,24 @@ public class CodeGenerator {
}
}

public void generate(Map<String, Object> model, String templateName, OutputStream out) {

public void generate(Map<String, Object> model, String templateName, String fileName) {
File file = new File(fileName);
if (file.exists()) file.delete();
FileOutputStream out = null;
try {
file.createNewFile();
out = new FileOutputStream(fileName);

initModel(model);
Template template = configuration.getTemplate(templateName, StandardCharsets.UTF_8.toString());
Template template = configuration.getTemplate(templateName + ".ftl", StandardCharsets.UTF_8.toString());
template.setOutputEncoding(encode);
template.process(model, new OutputStreamWriter(out, encode));
out.close();
out.flush();
} catch (Exception e) {
e.printStackTrace();
throw new SwException(e);
throw new SwException("生成代码失败!", e);
} finally {
IOUtils.closeQuietly(out);
}
}

@@ -88,6 +107,18 @@ public class CodeGenerator {
return out.getBuffer().toString();
}

public void generateBean(Map<String, Object> model, String fileName) {
generate(model, TEMPLATE_JAVA_BEAN, fileName);
}

public void generateCache(Map<String, Object> model, String fileName) {
generate(model, TEMPLATE_JAVA_CACHE, fileName);
}

public void generateService(Map<String, Object> model, String fileName) {
generate(model, TEMPLATE_JAVA_SERVICE, fileName);
}

/**
* 获取单实例
*
@@ -110,6 +141,7 @@ public class CodeGenerator {
}
}


/*
{param:{pa:"aaa"},
layout:{


+ 73
- 0
smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/util/IdeaUtil.java Прегледај датотеку

@@ -0,0 +1,73 @@
package cc.smtweb.system.bpm.util;


import cc.smtweb.framework.core.common.SwMap;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import lombok.Data;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* Created by Akmm at 14-2-14 上午10:13
* 读取Idea信息的工具类
*/
public class IdeaUtil {
//获取工程中的Module文件
public static Map<String, String> getModules(String ideaPath) {
Map<String, String> map = new HashMap<>();
IdeaProject project = XmlUtil.readValue(new File(ideaPath + "/.idea/modules.xml"), IdeaProject.class);
if (project == null || project.component == null || project.component.modules == null) return map;
for (Module module: project.component.modules) {
String s = module.filepath.replace("$PROJECT_DIR$", ideaPath);
File f = new File(s);
s = f.getName();
int i = s.lastIndexOf(".");
if (i >= 0) s = s.substring(0, i);
map.put(s, f.getParent());
}
return map;
}


public static void main(String args[]) throws Exception {
Map<String, String> list = getModules("e:/jujia/git/6.0/smtweb2/smtweb-framework");
for (Map.Entry<String, String> s : list.entrySet()) {
System.out.println(s.getKey() + "=" + s.getValue());
}
}

@Data
@JsonIgnoreProperties(ignoreUnknown = true)
@JacksonXmlRootElement(localName = "project")
public static class IdeaProject {
private Component component;

}

@Data
@JsonIgnoreProperties(ignoreUnknown = true)
static class Component {
@JacksonXmlElementWrapper(localName = "modules")
@JacksonXmlProperty(localName = "module")
public List<Module> modules;
}

@Data
@JsonIgnoreProperties(ignoreUnknown = true)
static class Module {
@JacksonXmlProperty
private String fileurl;
@JacksonXmlProperty
private String filepath;
}
}

+ 12
- 0
smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/util/XmlUtil.java Прегледај датотеку

@@ -34,6 +34,18 @@ public class XmlUtil {
}
}

public static <T> T readValue(File file, Class<T> clazz) {
try {
if (file == null || !file.exists()) {
return null;
} else {
return OBJECT_MAPPER.readValue(file, clazz);
}
} catch (Exception e) {
throw new JsonParseException("can't convert this json to " + clazz + " type", e);
}
}

public static <T> T readValue(InputStream is, Class<T> clazz) {
try {
if (is == null) {


+ 163
- 0
smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/CodeBuildHandler.java Прегледај датотеку

@@ -0,0 +1,163 @@
package cc.smtweb.system.bpm.web.design.form;

import cc.smtweb.framework.core.common.R;
import cc.smtweb.framework.core.common.SwEnum;
import cc.smtweb.framework.core.common.SwException;
import cc.smtweb.framework.core.common.SwMap;
import cc.smtweb.framework.core.db.cache.ModelTableCache;
import cc.smtweb.framework.core.db.vo.ModelCache;
import cc.smtweb.framework.core.db.vo.ModelField;
import cc.smtweb.framework.core.db.vo.ModelProject;
import cc.smtweb.framework.core.db.vo.ModelTable;
import cc.smtweb.framework.core.mvc.service.AbstractHandler;
import cc.smtweb.framework.core.util.CommUtil;
import cc.smtweb.framework.core.util.DateUtil;
import cc.smtweb.framework.core.util.MapUtil;
import cc.smtweb.framework.core.util.SpringUtil;
import cc.smtweb.system.bpm.spring.BpmConfigBean;
import cc.smtweb.system.bpm.util.CodeGenUtil;
import cc.smtweb.system.bpm.util.CodeGenerator;
import cc.smtweb.system.bpm.util.IdeaUtil;
import cc.smtweb.system.bpm.web.design.db.ModelCatalogCache;
import cc.smtweb.system.bpm.web.design.db.ModelProjectCache;
import org.apache.commons.lang3.StringUtils;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
* Created by Akmm at 2022/6/14 20:11
* 生成代码
*/
public class CodeBuildHandler extends AbstractHandler {
private static final String SRC_MAIN_JAVA = "/src/main/java/";
private static final String SRC_MAIN_RES = "/src/main/resources";

private String userName;
//java文件所在路径
private String codeJavaPath;
private String packageName;
private BpmConfigBean bpmConfigBean;

public R buildJavaCode() {
userName = String.valueOf(us.getUserId());

//页面id
long pageId = params.readLong("pageId");

//是否需要创建服务
boolean needBuildService = params.readBool("service");
//实体相关
List<Map<String, Object>> tables = params.readListMap("table");

buildCodeJavaPath(pageId);
for (Map<String, Object> map : tables) {
long tableId = MapUtil.readLong(map, "tableId");
buildJavaTable(tableId, MapUtil.readBool(map, "bean"), MapUtil.readBool(map, "cache"));
}
if (needBuildService) buildJavaService(pageId);
return R.success();
}

/**
* 构建java代码路径
*
* @param pageId 页面id
*/
private void buildCodeJavaPath(long pageId) {
ModelForm form = ModelFormCache.getInstance().get(pageId);
if (form == null) throw new SwException("未找到指定的页面定义!");
String moduleName = ModelProjectCache.getInstance().getModule(form.getPrjId());

if (StringUtils.isEmpty(moduleName) || moduleName.equals("sys") || moduleName.equals("bpm")) {
moduleName = "sw-system-bpm";
packageName = "cc.smtweb.system.bpm.web";
} else {
packageName = "cc.smtweb.biz." + moduleName + ".web";
}
BpmConfigBean bpmConfigBean = SpringUtil.getBean(BpmConfigBean.class);
Map<String, String> mapIdeaModules = IdeaUtil.getModules(bpmConfigBean.getCodeJavaPath());
if (mapIdeaModules == null || mapIdeaModules.isEmpty()) throw new SwException("没有定义idea项目的路径!");
codeJavaPath = mapIdeaModules.get(moduleName);
if (StringUtils.isEmpty(codeJavaPath)) {
throw new SwException("没有找到对应项目在idea中Module的路径!");
}
codeJavaPath += "/src/main/java/";
//加上目录
String cn = ModelCatalogCache.getInstance().getFullName(form.getMcId());
if (StringUtils.isNotEmpty(cn)) {
packageName += "." + cn;
}
codeJavaPath += packageName.replaceAll("\\.", "/");
new File(codeJavaPath).mkdirs();
}

/**
* 生成bean
*
* @param tableId
*/
private void buildJavaTable(long tableId, boolean needBean, boolean needCache) {
ModelTable table = ModelTableCache.getInstance().get(tableId);
if (table == null) throw new SwException("没有找到对应的表定义!");
SwMap model = new SwMap();
model.put("user", userName);
model.put("sysTime", DateUtil.nowDateTime());
model.put("packageName", packageName);
model.put("tableName", table.getName());
model.put("tableTitle", table.getTitle());

final String beanName = CodeGenUtil.getBeanName(table.getName());
model.put("beanName", beanName);
if (needBean) {
List<SwMap> fields = new ArrayList<>();
model.put("fields", fields);
for (ModelField field : table.getFields()) {
SwMap fn = new SwMap();
fields.add(fn);
fn.put("name", field.getName());
fn.put("title", field.getTitle());
fn.put("javaName", CodeGenUtil.getBeanName(field.getName()));
SwEnum.DataTypeBean dtb = SwEnum.DataType.instance.getByValue(field.getDataType());
fn.put("javaType", dtb.javaType);
fn.put("shortJavaType", dtb.shortJavaType);
}

CodeGenerator.getInstance().generateBean(model, codeJavaPath + "/" + beanName + ".java");
}

if (needCache) {
if (!table.isNeedCache()) throw new SwException("表设置为不需要缓存!" + table.getTitle());
List<SwMap> caches = new ArrayList<>();
model.put("caches", caches);
for (ModelCache cache : table.getCaches()) {
SwMap fn = new SwMap();
caches.add(fn);
final String name = cache.getName();
fn.put("name", name);
fn.put("nameUF", CodeGenUtil.toUpperHump(name));
fn.put("title", cache.getTitle());
fn.put("fields", cache.getFields());
}

CodeGenerator.getInstance().generateCache(model, codeJavaPath + "/" + beanName + "Cache.java");
}
}

private void buildJavaService(long pageId) {
ModelForm form = ModelFormCache.getInstance().get(pageId);
String sName = form.getService();
if (StringUtils.isEmpty(sName)) throw new SwException("页面设置未定义服务名!" + form.getTitle());
sName = CodeGenUtil.toUpperHump(sName);

SwMap model = new SwMap();
model.put("user", userName);
model.put("sysTime", DateUtil.nowDateTime());
model.put("packageName", packageName);
model.put("formTitle", form.getTitle());

CodeGenerator.getInstance().generateService(model, codeJavaPath + "/" + sName + "Service.java");
}
}

+ 2
- 1
smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormCache.java Прегледај датотеку

@@ -2,6 +2,7 @@ package cc.smtweb.system.bpm.web.design.form;

import cc.smtweb.framework.core.annotation.SwCache;
import cc.smtweb.framework.core.cache.AbstractCache;
import cc.smtweb.framework.core.cache.AbstractEntityCache;
import cc.smtweb.framework.core.cache.CacheManager;
import cc.smtweb.framework.core.common.SwConsts;
import cc.smtweb.framework.core.db.DbEngine;
@@ -16,7 +17,7 @@ import java.util.Set;
* Created by Akmm at 2022/1/12 18:34
*/
@SwCache(ident = "ASP_MODEL_FORM", title = "页面定义")
public class ModelFormCache extends AbstractCache<ModelForm> {
public class ModelFormCache extends AbstractEntityCache<ModelForm> {
private final static String mk = "k";
private final static String mp = "prj";
private final static String mc = "c";


+ 13
- 1
smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormService.java Прегледај датотеку

@@ -24,6 +24,7 @@ import java.util.List;
*/
@SwService
public class ModelFormService extends AbstractCompService {
private final static String TYPE_CODE = "type_code";
@Override
protected AbstractHandler createHandler(String type) {
switch (type) {
@@ -35,7 +36,8 @@ public class ModelFormService extends AbstractCompService {
return new DefaultDelHandler<ModelForm>(ModelForm.ENTITY_NAME);
case TYPE_LIST:
return new DefaultListHandler<ModelForm>(ModelForm.ENTITY_NAME);

case TYPE_CODE:
return new CodeBuildHandler();
}
return null;
}
@@ -142,4 +144,14 @@ public class ModelFormService extends AbstractCompService {
public R loadTmpls(@SwBody SwMap params, UserSession us) {
return R.success(CodeGenerator.getInstance().getModelTemplates());
}

//加载模板定义
public R buildJaveCode(@SwBody SwMap params, UserSession us) {
try {
CodeBuildHandler handler = (CodeBuildHandler) getHandler(params, us, TYPE_CODE);
return handler.buildJavaCode();
} catch (Exception e) {
return R.error("操作失败!", e);
}
}
}

+ 0
- 3
smtweb-system/sw-system-bpm/src/main/resources/config/application-dev.yaml Прегледај датотеку

@@ -5,9 +5,6 @@ smtweb:
url: http://127.0.0.1:8888/sw/files/
bpm:
debug: true
code-build: true
code-vue-path: '/code/2021/nodejs/sw-sys-uc-vue/src/'
code-vue-dir: 'pages'
code-java-path: '/code/2021/java/sw-sys-uc/sw-sys-uc-web/src/main/java/'
code-java-package: 'cc.smtweb.system.uc.web'
config-ui-path: '/code/2021/java/sw-sys-uc/sw-sys-uc-web/src/main/resources/plugin/config/'


+ 1
- 6
smtweb-system/sw-system-bpm/src/main/resources/config/application.yaml Прегледај датотеку

@@ -5,12 +5,7 @@ smtweb:
url: http://127.0.0.1:8888/sw/files/
bpm:
debug: true
code-build: true
code-vue-path: '/code/2021/nodejs/sw-sys-uc-vue/src/'
code-vue-dir: 'pages'
code-java-path: '/code/2021/java/sw-sys-uc/sw-sys-uc-web/src/main/java/'
code-java-package: 'cc.smtweb.system.uc.web'
config-ui-path: '/code/2021/java/sw-sys-uc/sw-sys-uc-web/src/main/resources/plugin/config/'
code-java-path: 'e:/jujia/git/6.0/smtweb2/smtweb-framework'
db:
type: mysql
default:


+ 42
- 0
smtweb-system/sw-system-bpm/src/main/resources/static/template/java_bean.ftl Прегледај датотеку

@@ -0,0 +1,42 @@
package ${packageName};

import cc.smtweb.framework.core.annotation.SwTable;
import cc.smtweb.framework.core.common.SwMap;
import cc.smtweb.framework.core.db.impl.DefaultEntity;

/**
* Created by ${user} at ${sysTime}
* 实体【[${tableTitle}](${tableName})】的Entity类
*/
@SwTable("${tableName}")
public class ${beanName} extends DefaultEntity {
public static final String ENTITY_NAME = "${tableName}";

public ${beanName}() {
super(ENTITY_NAME);
}

<#list fields as field>
<#if field.javaType == "boolean">
/** ${field.title} */
public boolean is${field.javaName}() {
return getBool("${field.name}");
}

/** ${field.title} */
public void set${javaName}(boolean ${field.name}) {
setBool("${field.name}", ${field.name});
}
<#else >
/** ${field.title} */
public ${field.javaType} get${field.javaName}() {
return get${field.shortJavaType}("${field.name}");
}

/** ${field.title} */
public void set${field.javaName}(${field.javaType} ${field.name}) {
put("${field.name}", ${field.name});
}
</#if>
</#list>
}

+ 51
- 0
smtweb-system/sw-system-bpm/src/main/resources/static/template/java_cache.ftl Прегледај датотеку

@@ -0,0 +1,51 @@
package ${packageName};

import cc.smtweb.framework.core.annotation.SwCache;
import cc.smtweb.framework.core.cache.AbstractEntityCache;
import cc.smtweb.framework.core.cache.CacheManager;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Set;

/**
* Created by ${user} at ${sysTime}
* 实体【[${tableTitle}](${tableName})】的缓存类
*/
@SwCache(ident = "${tableName}", title = "页面定义")
public class ${beanName}Cache extends AbstractEntityCache<${beanName}> {
<#list caches as cache>
//缓存key:${cache.title}
public final static String mk_${cache.name} = "${cache.name}";
</#list>

public static ${beanName}Cache getInstance() {
return CacheManager.getIntance().getCache(${beanName}Cache.class);
}

public ${beanName}Cache() {
<#list caches as cache>
//缓存key:${cache.title}
<#if cache.type=="M">
regMap(mk_${cache.name}, "${cache.fields}");
<#else>
regList(mk_${cache.name}, "${cache.fields}");
</#if>
</#list>
}

<#list caches as cache>
<#if cache.type=="M">
//缓存key:${cache.title}
public final ${beanName} getBy${cache.nameUF}(String key) {
return getByKey(mk_${cache.name}, key);
}
<#else>
//缓存key:${cache.title}
public final Set<${beanName}> getBy${cache.nameUF}(String key) {
return getListByKey(mk_${cache.name}, key);
}
</#if>
</#list>
}

+ 30
- 0
smtweb-system/sw-system-bpm/src/main/resources/static/template/java_service.ftl Прегледај датотеку

@@ -0,0 +1,30 @@
package ${packageName};

import cc.smtweb.framework.core.annotation.SwBody;
import cc.smtweb.framework.core.annotation.SwService;
import cc.smtweb.framework.core.common.R;
import cc.smtweb.framework.core.common.SwMap;
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageService;
import cc.smtweb.framework.core.mvc.service.AbstractHandler;
import cc.smtweb.framework.core.session.UserSession;

/**
* Created by ${user} at ${sysTime}
* 页面【[${formTitle}]的服务类
*/
@SwService
public class ${service}Service extends DynPageService {
//public final static String TYPE_DEMO = "demo";
@Override
protected AbstractHandler createHandler(String type) {
return super.createHandler(type);
}

/* demo
//自定义
public R demo(@SwBody SwMap params, UserSession us) {
return pageHandler(params, us, TYPE_DEMO, handler -> ((DemoHandler)handler).demo());
}
*/

}

+ 23
- 0
smtweb-system/sw-system-bpm/src/test/java/cc/smtweb/system/bpm/test/ModelFormTest.java Прегледај датотеку

@@ -5,12 +5,16 @@ import cc.smtweb.framework.core.common.SwMap;
import cc.smtweb.system.bpm.spring.BpmApplication;
import cc.smtweb.system.bpm.web.design.form.ModelForm;
import cc.smtweb.system.bpm.web.design.form.ModelFormHelper;
import cc.smtweb.system.bpm.web.design.form.ModelFormService;
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.ArrayList;
import java.util.List;

/**
* Created by Akmm at 2022/4/26 9:46
*/
@@ -72,4 +76,23 @@ public class ModelFormTest {
ModelFormHelper.buildSaveModelByTmpl(form, "model_simple");
System.out.println(form.getContent());
}

@Test
public void testBuildJavaBean() {
//{pageId,dataset:"", data:{form:{},list: {total:0,rows:[]}}, filter:{}}
SwMap params = new SwMap();
params.put("pageId", 718479207767740416L);
params.put("service", true);
List<SwMap> table = new ArrayList<>();
params.put("table", table);
SwMap map = new SwMap();
map.put("tableId", 718391823709507584L);
map.put("bean", true);
map.put("cache", true);
table.add(map);

ModelFormService service = new ModelFormService();
R r = service.buildJaveCode(params, null);
System.out.println(r.readSuccess());
}
}

Loading…
Откажи
Сачувај