Commit 18144407 authored by trumansdo's avatar trumansdo
Browse files

应用codestyle


千万千万要用vscode打开前端项目,或者关闭eslint,移除它
Signed-off-by: default avatartrumansdo <1012243881@qq.com>
parent 9b3d96a6
...@@ -3,46 +3,46 @@ package com.ibeetl.admin.core.file; ...@@ -3,46 +3,46 @@ package com.ibeetl.admin.core.file;
import java.io.OutputStream; import java.io.OutputStream;
public abstract class FileItem { public abstract class FileItem {
protected Long id; protected Long id;
protected String name; protected String name;
protected String path; protected String path;
boolean isTemp = false; boolean isTemp = false;
public abstract OutputStream openOutpuStream(); public abstract OutputStream openOutpuStream();
public abstract void copy(OutputStream os); public abstract void copy(OutputStream os);
public abstract boolean delete();
public abstract boolean delete();
public String getName() {
public String getName() { return name;
return name; }
}
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
public String getPath() {
return path; public String getPath() {
} return path;
public void setPath(String path) { }
this.path = path;
} public void setPath(String path) {
this.path = path;
public boolean isTemp() { }
return isTemp;
} public boolean isTemp() {
return isTemp;
public void setTemp(boolean isTemp) { }
this.isTemp = isTemp;
} public void setTemp(boolean isTemp) {
this.isTemp = isTemp;
public Long getId() { }
return id;
} public Long getId() {
return id;
public void setId(Long id) { }
this.id = id;
} public void setId(Long id) {
this.id = id;
}
} }
...@@ -4,54 +4,63 @@ import java.io.OutputStream; ...@@ -4,54 +4,63 @@ import java.io.OutputStream;
import java.util.List; import java.util.List;
/** /**
* 文件持久化,默认为文件系统,可以扩展到fastfds等 * 文件持久化,默认为文件系统,可以扩展到fastfds等
* @author xiandafu
* *
* @author xiandafu
*/ */
public interface FileService { public interface FileService {
/** /**
* 得到一个临时文件操作 * 得到一个临时文件操作
* @param name *
* @return * @param name
*/ * @return
public FileItem createFileTemp(String name); */
public FileItem createFileTemp(String name);
/**
* 创建一个持久的文档 /**
* @param name * 创建一个持久的文档
* @param bizType *
* @param bizId * @param name
* @param userId * @param bizType
* @param orgId * @param bizId
* @param tags * @param userId
* @return * @param orgId
*/ * @param tags
public FileItem createFileItem(String name,String bizType,String bizId,Long userId,Long orgId,String fileBatchId,List<FileTag> tags); * @return
*/
public FileItem createFileItem(
public FileItem loadFileItemByPath(String path); String name,
public FileItem getFileItemById(Long id); String bizType,
public FileItem getFileItemById(Long id,String batchFileId); String bizId,
Long userId,
public List<FileItem> queryByUserId(Long userId,List<FileTag> tags); Long orgId,
public List<FileItem> queryByBiz(String bizType,String bizId); String fileBatchId,
public List<FileItem> queryByBatchId(String fileBatchId); List<FileTag> tags);
/**
* 删除某个文件 public FileItem loadFileItemByPath(String path);
* @param id
* @param fileBatchId,用于验证 public FileItem getFileItemById(Long id);
*/
public void removeFile(Long id,String fileBatchId); public FileItem getFileItemById(Long id, String batchFileId);
/** public List<FileItem> queryByUserId(Long userId, List<FileTag> tags);
* 完善附件信息
* @param fileBatchId public List<FileItem> queryByBiz(String bizType, String bizId);
* @param bizType
* @param bizId public List<FileItem> queryByBatchId(String fileBatchId);
*/ /**
public void updateFile(String fileBatchId,String bizType,String bizId); * 删除某个文件
*
* @param id
* @param fileBatchId,用于验证
*/
public void removeFile(Long id, String fileBatchId);
/**
* 完善附件信息
*
* @param fileBatchId
* @param bizType
* @param bizId
*/
public void updateFile(String fileBatchId, String bizType, String bizId);
} }
package com.ibeetl.admin.core.file; package com.ibeetl.admin.core.file;
public class FileTag { public class FileTag {
String name; String name;
String value; String value;
Long fileId; Long fileId;
public String getName() {
return name; public String getName() {
} return name;
public void setName(String name) { }
this.name = name;
} public void setName(String name) {
public String getValue() { this.name = name;
return value; }
}
public void setValue(String value) { public String getValue() {
this.value = value; return value;
} }
public Long getFileId() {
return fileId; public void setValue(String value) {
} this.value = value;
public void setFileId(Long fileId) { }
this.fileId = fileId;
} public Long getFileId() {
return fileId;
}
public void setFileId(Long fileId) {
this.fileId = fileId;
}
} }
...@@ -9,67 +9,61 @@ import java.io.OutputStream; ...@@ -9,67 +9,61 @@ import java.io.OutputStream;
import com.ibeetl.admin.core.util.PlatformException; import com.ibeetl.admin.core.util.PlatformException;
/** /**
* 本地文件系统 * 本地文件系统
* @author xiandafu
* *
* @author xiandafu
*/ */
class LocalFileItem extends PersistFileItem{ class LocalFileItem extends PersistFileItem {
String root = null; String root = null;
public LocalFileItem(String root) {
this.root = root; public LocalFileItem(String root) {
} this.root = root;
public OutputStream openOutpuStream() { }
File file = new File(root + File.separator + path);
try { public OutputStream openOutpuStream() {
if(!file.exists()) { File file = new File(root + File.separator + path);
file.createNewFile(); try {
} if (!file.exists()) {
FileOutputStream fos = new FileOutputStream(file); file.createNewFile();
return fos; }
} catch (IOException e) { FileOutputStream fos = new FileOutputStream(file);
throw new PlatformException("Open stream error "+path); return fos;
} } catch (IOException e) {
throw new PlatformException("Open stream error " + path);
} }
}
@Override @Override
public void copy(OutputStream os) { public void copy(OutputStream os) {
File file = new File(root + File.separator + path); File file = new File(root + File.separator + path);
FileInputStream input = null; FileInputStream input = null;
try { try {
input = new FileInputStream(file); input = new FileInputStream(file);
byte[] buf = new byte[1024]; byte[] buf = new byte[1024];
int bytesRead; int bytesRead;
while ((bytesRead = input.read(buf)) > 0) { while ((bytesRead = input.read(buf)) > 0) {
os.write(buf, 0, bytesRead); os.write(buf, 0, bytesRead);
} }
}catch(Exception ex) {
throw new PlatformException("下载文件失败"+ex);
}
finally {
try {
input.close();
os.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(path.startsWith("temp")) { } catch (Exception ex) {
this.delete(); throw new PlatformException("下载文件失败" + ex);
} } finally {
try {
input.close();
os.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} }
@Override if (path.startsWith("temp")) {
public boolean delete() { this.delete();
File file = new File(root + File.separator + path);
return file.delete();
} }
}
}
@Override
public boolean delete() {
File file = new File(root + File.separator + path);
return file.delete();
}
}
...@@ -16,160 +16,154 @@ import com.ibeetl.admin.core.util.PlatformException; ...@@ -16,160 +16,154 @@ import com.ibeetl.admin.core.util.PlatformException;
import com.ibeetl.admin.core.util.UUIDUtil; import com.ibeetl.admin.core.util.UUIDUtil;
/** /**
* 一个本地文件系统,管理临时文件和用户文件 * 一个本地文件系统,管理临时文件和用户文件
* @author xiandafu
* *
* @author xiandafu
*/ */
public class LocalFileService implements FileService { public class LocalFileService implements FileService {
Log log = LogFactory.getLog(this.getClass()); Log log = LogFactory.getLog(this.getClass());
DBIndexHelper dbHelper = null; DBIndexHelper dbHelper = null;
String root = null; String root = null;
public LocalFileService(ApplicationContext ctx,String root) { public LocalFileService(ApplicationContext ctx, String root) {
this.root = root; this.root = root;
new File(root,"temp").mkdir(); new File(root, "temp").mkdir();
dbHelper = new DBIndexHelper(ctx.getBean(CoreFileDao.class)); dbHelper = new DBIndexHelper(ctx.getBean(CoreFileDao.class));
} }
@Override @Override
public FileItem loadFileItemByPath(String path) { public FileItem loadFileItemByPath(String path) {
CoreFile coreFile = dbHelper.getFileItemByPath(path); CoreFile coreFile = dbHelper.getFileItemByPath(path);
if(coreFile!=null) { if (coreFile != null) {
return getFileItem(coreFile); return getFileItem(coreFile);
}
LocalFileItem item = new LocalFileItem(root);
item.setPath(path);
item.setName(parseTempFileName(path));
item.setTemp(true);
return item;
}
@Override
public FileItem createFileTemp(String name) {
FileItem item = new LocalFileItem(root);
String fileName = "temp"+File.separator+name + "." + this.suffix();
item.setPath(fileName);
item.setName(name);
item.setTemp(true);
return item;
}
@Override
public FileItem createFileItem(String name, String bizType, String bizId, Long userId, Long orgId, String fileBatchId,List<FileTag> tags) {
CoreFile coreFile = new CoreFile();
coreFile.setBizId(bizId);
coreFile.setBizType(bizType);
coreFile.setUserId(userId);
coreFile.setOrgId(orgId);
coreFile.setName(name);
coreFile.setCreateTime(new Date());
coreFile.setFileBatchId(fileBatchId);
String dir = DateUtil.now("yyyyMMdd");
File dirFile = new File(root + File.separator + dir);
if(!dirFile.exists()) {
dirFile.mkdirs();
}
String fileName = name+"."+UUIDUtil.uuid();
String path = dir+File.separator+fileName;
coreFile.setPath(path);
//目前忽略tags
dbHelper.createFileItem(coreFile,tags);
return this.getFileItem(coreFile);
}
private String suffix() {
// TODO,改成唯一算法
return DateUtil.now("yyyyMMddhhmm")+ "-" + UUIDUtil.uuid();
}
private String parseTempFileName(String path) {
File file = new File(path);
String name = file.getName();
//去掉最后的临时标记
int index = name.lastIndexOf(".");
return name.substring(0, index);
}
protected FileItem getFileItem(CoreFile file) {
LocalFileItem item = new LocalFileItem(root);
item.setName(file.getName());
item.setPath(file.getPath());
item.setBizId(file.getBizId());
item.setBizType(file.getBizType());
item.setId(file.getId());
item.setOrgId(file.getOrgId());
item.setId(file.getId());
return item;
}
protected List<FileItem> getFileItem(List<CoreFile> files) {
List<FileItem> items = new ArrayList<>(files.size());
for(CoreFile file:files) {
items.add(this.getFileItem(file));
}
return items;
}
@Override
public FileItem getFileItemById(Long id) {
return this.getFileItem(dbHelper.getFileItemById(id));
}
@Override
public List<FileItem> queryByUserId(Long userId, List<FileTag> tags) {
return this.getFileItem(dbHelper.queryByUserId(userId, tags));
} }
LocalFileItem item = new LocalFileItem(root);
@Override item.setPath(path);
public List<FileItem> queryByBiz(String bizType, String bizId) { item.setName(parseTempFileName(path));
return this.getFileItem(dbHelper.queryByBiz(bizType, bizId)); item.setTemp(true);
return item;
}
@Override
public FileItem createFileTemp(String name) {
FileItem item = new LocalFileItem(root);
String fileName = "temp" + File.separator + name + "." + this.suffix();
item.setPath(fileName);
item.setName(name);
item.setTemp(true);
return item;
}
@Override
public FileItem createFileItem(
String name,
String bizType,
String bizId,
Long userId,
Long orgId,
String fileBatchId,
List<FileTag> tags) {
CoreFile coreFile = new CoreFile();
coreFile.setBizId(bizId);
coreFile.setBizType(bizType);
coreFile.setUserId(userId);
coreFile.setOrgId(orgId);
coreFile.setName(name);
coreFile.setCreateTime(new Date());
coreFile.setFileBatchId(fileBatchId);
String dir = DateUtil.now("yyyyMMdd");
File dirFile = new File(root + File.separator + dir);
if (!dirFile.exists()) {
dirFile.mkdirs();
} }
String fileName = name + "." + UUIDUtil.uuid();
@Override String path = dir + File.separator + fileName;
public List<FileItem> queryByBatchId(String fileBatchId) { coreFile.setPath(path);
return this.getFileItem(dbHelper.queryByBatchId(fileBatchId)); // 目前忽略tags
dbHelper.createFileItem(coreFile, tags);
return this.getFileItem(coreFile);
}
private String suffix() {
// TODO,改成唯一算法
return DateUtil.now("yyyyMMddhhmm") + "-" + UUIDUtil.uuid();
}
private String parseTempFileName(String path) {
File file = new File(path);
String name = file.getName();
// 去掉最后的临时标记
int index = name.lastIndexOf(".");
return name.substring(0, index);
}
protected FileItem getFileItem(CoreFile file) {
LocalFileItem item = new LocalFileItem(root);
item.setName(file.getName());
item.setPath(file.getPath());
item.setBizId(file.getBizId());
item.setBizType(file.getBizType());
item.setId(file.getId());
item.setOrgId(file.getOrgId());
item.setId(file.getId());
return item;
}
protected List<FileItem> getFileItem(List<CoreFile> files) {
List<FileItem> items = new ArrayList<>(files.size());
for (CoreFile file : files) {
items.add(this.getFileItem(file));
} }
return items;
@Override }
public void removeFile(Long id, String fileBatchId) {
CoreFile file = dbHelper.getFileItemById(id); @Override
if(!file.getFileBatchId().equals(fileBatchId)){ public FileItem getFileItemById(Long id) {
return ; return this.getFileItem(dbHelper.getFileItemById(id));
} }
FileItem item = this.getFileItem(file); @Override
boolean success = item.delete(); public List<FileItem> queryByUserId(Long userId, List<FileTag> tags) {
if(!success) { return this.getFileItem(dbHelper.queryByUserId(userId, tags));
log.warn("删除文件失败 "+file.getName()+ ",id="+file.getId()+" path="+file.getPath()); }
throw new PlatformException("删除文件失败 "+file.getName());
} @Override
dbHelper.fileDao.deleteById(id); public List<FileItem> queryByBiz(String bizType, String bizId) {
return ; return this.getFileItem(dbHelper.queryByBiz(bizType, bizId));
}
@Override
public List<FileItem> queryByBatchId(String fileBatchId) {
return this.getFileItem(dbHelper.queryByBatchId(fileBatchId));
}
@Override
public void removeFile(Long id, String fileBatchId) {
CoreFile file = dbHelper.getFileItemById(id);
if (!file.getFileBatchId().equals(fileBatchId)) {
return;
} }
@Override FileItem item = this.getFileItem(file);
public void updateFile(String fileBatchId, String bizType, String bizId) { boolean success = item.delete();
dbHelper.fileDao.updateBatchIdInfo(bizType, bizId, fileBatchId); if (!success) {
log.warn("删除文件失败 " + file.getName() + ",id=" + file.getId() + " path=" + file.getPath());
throw new PlatformException("删除文件失败 " + file.getName());
} }
dbHelper.fileDao.deleteById(id);
@Override return;
public FileItem getFileItemById(Long id, String fileBatchId) { }
CoreFile file = dbHelper.getFileItemById(id);
if(!file.getFileBatchId().equals(fileBatchId)){ @Override
return null; public void updateFile(String fileBatchId, String bizType, String bizId) {
} dbHelper.fileDao.updateBatchIdInfo(bizType, bizId, fileBatchId);
return this.getFileItem(file); }
@Override
public FileItem getFileItemById(Long id, String fileBatchId) {
CoreFile file = dbHelper.getFileItemById(id);
if (!file.getFileBatchId().equals(fileBatchId)) {
return null;
} }
return this.getFileItem(file);
}
} }
...@@ -3,52 +3,62 @@ package com.ibeetl.admin.core.file; ...@@ -3,52 +3,62 @@ package com.ibeetl.admin.core.file;
import java.io.OutputStream; import java.io.OutputStream;
public abstract class PersistFileItem extends FileItem { public abstract class PersistFileItem extends FileItem {
protected Long id; protected Long id;
protected Long userId; protected Long userId;
protected Long orgId; protected Long orgId;
protected String bizType; protected String bizType;
protected String bizId; protected String bizId;
FileTag[] tags; FileTag[] tags;
public PersistFileItem() {
this.isTemp = false;
}
public Long getUserId() {
return userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
public Long getOrgId() {
return orgId;
}
public void setOrgId(Long orgId) {
this.orgId = orgId;
}
public FileTag[] getTags() {
return tags;
}
public void setTags(FileTag[] tags) {
this.tags = tags;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getBizType() {
return bizType;
}
public void setBizType(String bizType) {
this.bizType = bizType;
}
public String getBizId() {
return bizId;
}
public void setBizId(String bizId) {
this.bizId = bizId;
}
public PersistFileItem() {
this.isTemp = false;
}
public Long getUserId() {
return userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
public Long getOrgId() {
return orgId;
}
public void setOrgId(Long orgId) {
this.orgId = orgId;
}
public FileTag[] getTags() {
return tags;
}
public void setTags(FileTag[] tags) {
this.tags = tags;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getBizType() {
return bizType;
}
public void setBizType(String bizType) {
this.bizType = bizType;
}
public String getBizId() {
return bizId;
}
public void setBizId(String bizId) {
this.bizId = bizId;
}
} }
...@@ -5,6 +5,7 @@ import java.io.Writer; ...@@ -5,6 +5,7 @@ import java.io.Writer;
import com.ibeetl.admin.core.gen.model.Entity; import com.ibeetl.admin.core.gen.model.Entity;
public interface AutoGen { public interface AutoGen {
public void make(Target target,Entity entity); public void make(Target target, Entity entity);
public String getName();
public String getName();
} }
...@@ -11,76 +11,72 @@ import org.beetl.core.resource.ClasspathResourceLoader; ...@@ -11,76 +11,72 @@ import org.beetl.core.resource.ClasspathResourceLoader;
import com.ibeetl.admin.core.util.beetl.VerifyForamtFunction; import com.ibeetl.admin.core.util.beetl.VerifyForamtFunction;
public abstract class BaseTarget implements Target { public abstract class BaseTarget implements Target {
protected GroupTemplate gt = null; protected GroupTemplate gt = null;
protected String urlBase = null; protected String urlBase = null;
@Override
@Override public void flush(AutoGen gen, String content) {
public void flush(AutoGen gen, String content) { // TODO Auto-generated method stub
// TODO Auto-generated method stub
}
}
@Override
@Override public GroupTemplate getGroupTemplate() {
public GroupTemplate getGroupTemplate() { if (gt != null) {
if(gt!=null) { return gt;
return gt; }
}
ClassLoader loader = Thread.currentThread().getContextClassLoader();
ClasspathResourceLoader rs = new ClasspathResourceLoader(loader, "codeTemplate");
ClassLoader loader = Thread.currentThread().getContextClassLoader(); try {
ClasspathResourceLoader rs = new ClasspathResourceLoader(loader,"codeTemplate");
try { Configuration cfg = Configuration.defaultConfiguration();
cfg.setStatementStart("@");
Configuration cfg = Configuration.defaultConfiguration(); cfg.setStatementEnd(null);
cfg.setStatementStart("@");
cfg.setStatementEnd(null); cfg.setHtmlTagSupport(false);
cfg.build();
cfg.setHtmlTagSupport(false); gt = new GroupTemplate(rs, cfg);
cfg.build(); gt.registerFunction("verifyFormat", new VerifyForamtFunction());
gt = new GroupTemplate(rs,cfg); gt.registerFunction(
gt.registerFunction("verifyFormat", new VerifyForamtFunction()); "upperFirst",
gt.registerFunction("upperFirst", new Function() { new Function() {
@Override @Override
public Object call(Object[] paras, Context ctx) { public Object call(Object[] paras, Context ctx) {
String s = (String)paras[0]; String s = (String) paras[0];
return upperFirst(s); return upperFirst(s);
}
} });
} catch (IOException e) {
}); throw new RuntimeException(e);
} catch (IOException e) { }
throw new RuntimeException(e); return gt;
} }
return gt;
} public static String upperFirst(String s) {
if (Character.isUpperCase(s.charAt(0))) return s;
public static String upperFirst(String s) { else
if (Character.isUpperCase(s.charAt(0))) return (new StringBuilder())
return s; .append(Character.toUpperCase(s.charAt(0)))
else .append(s.substring(1))
return (new StringBuilder()) .toString();
.append(Character.toUpperCase(s.charAt(0))) }
.append(s.substring(1)).toString();
} public GroupTemplate getGt() {
return gt;
public GroupTemplate getGt() { }
return gt;
} public void setGt(GroupTemplate gt) {
this.gt = gt;
public void setGt(GroupTemplate gt) { }
this.gt = gt;
} public String getUrlBase() {
return urlBase;
public String getUrlBase() { }
return urlBase;
} public void setUrlBase(String urlBase) {
this.urlBase = urlBase;
public void setUrlBase(String urlBase) { }
this.urlBase = urlBase;
}
} }
package com.ibeetl.admin.core.gen; package com.ibeetl.admin.core.gen;
/** /**
* 用于代码生成 * 用于代码生成
* @author xiandafu
* *
* @author xiandafu
*/ */
public class ConsoleTarget extends BaseTarget {
public ConsoleTarget() {}
public class ConsoleTarget extends BaseTarget { @Override
public ConsoleTarget() { public void flush(AutoGen gen, String content) {
System.out.println("==========" + gen.getClass().getSimpleName() + "=============");
} System.out.println(content);
@Override }
public void flush(AutoGen gen, String content) {
System.out.println("=========="+gen.getClass().getSimpleName()+"=============");
System.out.println(content);
}
} }
...@@ -5,84 +5,77 @@ import org.beetl.core.Template; ...@@ -5,84 +5,77 @@ import org.beetl.core.Template;
import com.ibeetl.admin.core.gen.model.Entity; import com.ibeetl.admin.core.gen.model.Entity;
public class HtmlGen implements AutoGen{ public class HtmlGen implements AutoGen {
@Override
public void make(Target target, Entity entity) {
HtmlIndexGen indexGen = new HtmlIndexGen();
indexGen.make(target, entity);
HtmlEditGen editGen = new HtmlEditGen();
editGen.make(target, entity);
HtmlAddGen addGen = new HtmlAddGen();
addGen.make(target, entity);
}
@Override
public String getName() {
return "";
}
}
@Override
public void make(Target target, Entity entity) {
class HtmlIndexGen implements AutoGen{ HtmlIndexGen indexGen = new HtmlIndexGen();
indexGen.make(target, entity);
@Override
public void make(Target target, Entity entity) { HtmlEditGen editGen = new HtmlEditGen();
GroupTemplate gt = target.getGroupTemplate(); editGen.make(target, entity);
Template template = gt.getTemplate("/html/index.html");
template.binding("entity", entity);
template.binding("target", target);
String content = template.render();
target.flush(this, content);
}
@Override
public String getName() {
return "index.html";
}
}
class HtmlEditGen implements AutoGen{ HtmlAddGen addGen = new HtmlAddGen();
addGen.make(target, entity);
@Override }
public void make(Target target, Entity entity) {
GroupTemplate gt = target.getGroupTemplate(); @Override
Template template = gt.getTemplate("/html/edit.html"); public String getName() {
template.binding("entity", entity); return "";
template.binding("target", target); }
String content = template.render();
target.flush(this, content);
}
@Override
public String getName() {
return "edit.html";
}
} }
class HtmlAddGen implements AutoGen{ class HtmlIndexGen implements AutoGen {
@Override @Override
public void make(Target target, Entity entity) { public void make(Target target, Entity entity) {
GroupTemplate gt = target.getGroupTemplate(); GroupTemplate gt = target.getGroupTemplate();
Template template = gt.getTemplate("/html/add.html"); Template template = gt.getTemplate("/html/index.html");
template.binding("entity", entity); template.binding("entity", entity);
template.binding("target", target); template.binding("target", target);
String content = template.render(); String content = template.render();
target.flush(this, content); target.flush(this, content);
} }
@Override
public String getName() { @Override
return "add.html"; public String getName() {
} return "index.html";
}
} }
class HtmlEditGen implements AutoGen {
@Override
public void make(Target target, Entity entity) {
GroupTemplate gt = target.getGroupTemplate();
Template template = gt.getTemplate("/html/edit.html");
template.binding("entity", entity);
template.binding("target", target);
String content = template.render();
target.flush(this, content);
}
@Override
public String getName() {
return "edit.html";
}
}
class HtmlAddGen implements AutoGen {
@Override
public void make(Target target, Entity entity) {
GroupTemplate gt = target.getGroupTemplate();
Template template = gt.getTemplate("/html/add.html");
template.binding("entity", entity);
template.binding("target", target);
String content = template.render();
target.flush(this, content);
}
@Override
public String getName() {
return "add.html";
}
}
...@@ -5,124 +5,117 @@ import org.beetl.core.Template; ...@@ -5,124 +5,117 @@ import org.beetl.core.Template;
import com.ibeetl.admin.core.gen.model.Entity; import com.ibeetl.admin.core.gen.model.Entity;
public class JSGen implements AutoGen{ public class JSGen implements AutoGen {
@Override
public void make(Target target, Entity entity) {
JSDelGen delGen = new JSDelGen();
delGen.make(target, entity);
JSAddGen addGen = new JSAddGen();
addGen.make(target, entity);
JSEditGen editGen = new JSEditGen();
editGen.make(target, entity);
JSApiGen apiGen = new JSApiGen();
apiGen.make(target, entity);
JSIndexGen indexGen = new JSIndexGen();
indexGen.make(target, entity);
}
@Override
public String getName() {
return "";
}
}
class JSDelGen implements AutoGen{ @Override
public void make(Target target, Entity entity) {
@Override JSDelGen delGen = new JSDelGen();
public void make(Target target, Entity entity) { delGen.make(target, entity);
GroupTemplate gt = target.getGroupTemplate(); JSAddGen addGen = new JSAddGen();
Template template = gt.getTemplate("/js/del.js"); addGen.make(target, entity);
template.binding("entity", entity); JSEditGen editGen = new JSEditGen();
template.binding("target", target); editGen.make(target, entity);
String content = template.render(); JSApiGen apiGen = new JSApiGen();
target.flush(this, content); apiGen.make(target, entity);
JSIndexGen indexGen = new JSIndexGen();
} indexGen.make(target, entity);
@Override }
public String getName() {
return "del.js"; @Override
} public String getName() {
return "";
} }
class JSAddGen implements AutoGen{
@Override
public void make(Target target, Entity entity) {
GroupTemplate gt = target.getGroupTemplate();
Template template = gt.getTemplate("/js/add.js");
template.binding("entity", entity);
template.binding("target", target);
String content = template.render();
target.flush(this, content);
}
@Override
public String getName() {
return "add.js";
}
} }
class JSApiGen implements AutoGen{ class JSDelGen implements AutoGen {
Entity entity; @Override
@Override public void make(Target target, Entity entity) {
public void make(Target target, Entity entity) { GroupTemplate gt = target.getGroupTemplate();
this.entity =entity; Template template = gt.getTemplate("/js/del.js");
GroupTemplate gt = target.getGroupTemplate(); template.binding("entity", entity);
Template template = gt.getTemplate("/js/entityApi.js"); template.binding("target", target);
template.binding("entity", entity); String content = template.render();
template.binding("target", target); target.flush(this, content);
String content = template.render(); }
target.flush(this, content);
@Override
} public String getName() {
@Override return "del.js";
public String getName() { }
return entity.getCode()+"Api.js";
}
} }
class JSAddGen implements AutoGen {
@Override
public void make(Target target, Entity entity) {
GroupTemplate gt = target.getGroupTemplate();
Template template = gt.getTemplate("/js/add.js");
template.binding("entity", entity);
template.binding("target", target);
String content = template.render();
target.flush(this, content);
}
class JSEditGen implements AutoGen{ @Override
public String getName() {
@Override return "add.js";
public void make(Target target, Entity entity) { }
GroupTemplate gt = target.getGroupTemplate();
Template template = gt.getTemplate("/js/edit.js");
template.binding("entity", entity);
template.binding("target", target);
String content = template.render();
target.flush(this, content);
}
@Override
public String getName() {
return "edit.js";
}
} }
class JSIndexGen implements AutoGen{ class JSApiGen implements AutoGen {
@Override Entity entity;
public void make(Target target, Entity entity) {
GroupTemplate gt = target.getGroupTemplate(); @Override
Template template = gt.getTemplate("/js/index.js"); public void make(Target target, Entity entity) {
template.binding("entity", entity); this.entity = entity;
template.binding("target", target); GroupTemplate gt = target.getGroupTemplate();
String content = template.render(); Template template = gt.getTemplate("/js/entityApi.js");
target.flush(this, content); template.binding("entity", entity);
} template.binding("target", target);
@Override String content = template.render();
public String getName() { target.flush(this, content);
return "index.js"; }
}
@Override
public String getName() {
return entity.getCode() + "Api.js";
}
} }
class JSEditGen implements AutoGen {
@Override
public void make(Target target, Entity entity) {
GroupTemplate gt = target.getGroupTemplate();
Template template = gt.getTemplate("/js/edit.js");
template.binding("entity", entity);
template.binding("target", target);
String content = template.render();
target.flush(this, content);
}
@Override
public String getName() {
return "edit.js";
}
}
class JSIndexGen implements AutoGen {
@Override
public void make(Target target, Entity entity) {
GroupTemplate gt = target.getGroupTemplate();
Template template = gt.getTemplate("/js/index.js");
template.binding("entity", entity);
template.binding("target", target);
String content = template.render();
target.flush(this, content);
}
@Override
public String getName() {
return "index.js";
}
}
...@@ -11,206 +11,196 @@ import org.beetl.core.Template; ...@@ -11,206 +11,196 @@ import org.beetl.core.Template;
import com.ibeetl.admin.core.gen.model.Attribute; import com.ibeetl.admin.core.gen.model.Attribute;
import com.ibeetl.admin.core.gen.model.Entity; import com.ibeetl.admin.core.gen.model.Entity;
public class JavaCodeGen implements AutoGen{ public class JavaCodeGen implements AutoGen {
String basePackage; String basePackage;
Entity entity; Entity entity;
String basicFunctionCode = null; String basicFunctionCode = null;
static String CR = System.getProperty("line.separator"); static String CR = System.getProperty("line.separator");
public JavaCodeGen(String basePackage,Entity entity,String basicFunctionCode) {
this.basePackage =basePackage;
this.entity = entity;
this.basicFunctionCode =basicFunctionCode;
}
@Override
public void make(Target target, Entity entity) {
JavaEntityGen entityGen = new JavaEntityGen(this);
entityGen.make(target, entity);
JavaDaoGen daoGen = new JavaDaoGen(this);
daoGen.make(target, entity);
JavaServiceGen serviceGen = new JavaServiceGen(this);
serviceGen.make(target, entity);
JavaControllerGen webGen = new JavaControllerGen(this);
webGen.make(target, entity);
JavaQueryGen queryGen = new JavaQueryGen(this);
queryGen.make(target, entity);
}
@Override
public String getName() {
return "";
}
}
public JavaCodeGen(String basePackage, Entity entity, String basicFunctionCode) {
this.basePackage = basePackage;
this.entity = entity;
this.basicFunctionCode = basicFunctionCode;
}
class JavaEntityGen implements AutoGen{ @Override
JavaCodeGen gen; public void make(Target target, Entity entity) {
public JavaEntityGen(JavaCodeGen gen){
this.gen = gen;
}
@Override
public void make(Target target, Entity entity) {
GroupTemplate gt = target.getGroupTemplate();
Template template = gt.getTemplate("/java/pojo.java");
template.binding("entity", entity);
template.binding("target", target);
template.binding("package", gen.basePackage+".entity");
template.binding("className", entity.getName());
List<Map<String,Object>> attrs = new ArrayList<Map<String,Object>>();
for(Attribute attr:entity.getList()) {
Map<String,Object> map = new HashMap<String,Object>();
map.put("comment", attr.getComment());
map.put("type", attr.getJavaType());
map.put("name", attr.getName());
map.put("methodName", BaseTarget.upperFirst(attr.getName()));
map.put("isId", attr.isId());
map.put("dictType", attr.getDictType());
attrs.add(map);
}
template.binding("attrs", attrs);
String srcHead ="";
srcHead+="import java.math.*;"+JavaCodeGen.CR;
srcHead+="import java.util.Date;"+JavaCodeGen.CR;
srcHead+="import java.sql.Timestamp;"+JavaCodeGen.CR;
template.binding("imports", srcHead);
template.binding("comment", entity.getComment());
String content = template.render();
target.flush(this, content);
}
@Override
public String getName() {
return gen.entity.getName()+".java";
}
}
JavaEntityGen entityGen = new JavaEntityGen(this);
entityGen.make(target, entity);
class JavaDaoGen implements AutoGen{ JavaDaoGen daoGen = new JavaDaoGen(this);
JavaCodeGen gen; daoGen.make(target, entity);
public JavaDaoGen(JavaCodeGen gen){
this.gen = gen;
}
@Override
public void make(Target target, Entity entity) {
GroupTemplate gt = target.getGroupTemplate();
Template template = gt.getTemplate("/java/dao.java");
template.binding("entity", entity);
template.binding("target", target);
template.binding("package", gen.basePackage+".dao");
template.binding("basePackage", gen.basePackage);
String content = template.render();
target.flush(this, content);
}
@Override
public String getName() {
return gen.entity.getName()+"Dao.java";
}
}
JavaServiceGen serviceGen = new JavaServiceGen(this);
serviceGen.make(target, entity);
class JavaServiceGen implements AutoGen{ JavaControllerGen webGen = new JavaControllerGen(this);
JavaCodeGen gen; webGen.make(target, entity);
public JavaServiceGen(JavaCodeGen gen){
this.gen = gen;
}
@Override
public void make(Target target, Entity entity) {
GroupTemplate gt = target.getGroupTemplate();
Template template = gt.getTemplate("/java/service.java");
template.binding("entity", entity);
template.binding("target", target);
template.binding("package", gen.basePackage+".service");
template.binding("basePackage", gen.basePackage);
String content = template.render();
target.flush(this, content);
}
@Override
public String getName() {
return gen.entity.getName()+"Service.java";
}
}
JavaQueryGen queryGen = new JavaQueryGen(this);
queryGen.make(target, entity);
}
class JavaControllerGen implements AutoGen{ @Override
JavaCodeGen gen; public String getName() {
public JavaControllerGen(JavaCodeGen gen){ return "";
this.gen = gen; }
}
@Override
public void make(Target target, Entity entity) {
GroupTemplate gt = target.getGroupTemplate();
Template template = gt.getTemplate("/java/controller.java");
template.binding("entity", entity);
template.binding("target", target);
template.binding("package", gen.basePackage+".web");
template.binding("basePackage", gen.basePackage);
template.binding("basicfunctionCode",gen.basicFunctionCode);
String content = template.render();
target.flush(this, content);
}
@Override
public String getName() {
return gen.entity.getName()+"Controller.java";
}
} }
class JavaEntityGen implements AutoGen {
class JavaQueryGen implements AutoGen{ JavaCodeGen gen;
JavaCodeGen gen;
public JavaQueryGen(JavaCodeGen gen){ public JavaEntityGen(JavaCodeGen gen) {
this.gen = gen; this.gen = gen;
} }
@Override
public void make(Target target, Entity entity) { @Override
GroupTemplate gt = target.getGroupTemplate(); public void make(Target target, Entity entity) {
Template template = gt.getTemplate("/java/query.java"); GroupTemplate gt = target.getGroupTemplate();
List<Attribute> list = new ArrayList<Attribute>(); Template template = gt.getTemplate("/java/pojo.java");
for(Attribute attr:entity.getList()) { template.binding("entity", entity);
if(attr.isShowInQuery()) { template.binding("target", target);
list.add(attr); template.binding("package", gen.basePackage + ".entity");
} template.binding("className", entity.getName());
} List<Map<String, Object>> attrs = new ArrayList<Map<String, Object>>();
for (Attribute attr : entity.getList()) {
if(list.isEmpty()) { Map<String, Object> map = new HashMap<String, Object>();
list.add(entity.getIdAttribute()); map.put("comment", attr.getComment());
} map.put("type", attr.getJavaType());
map.put("name", attr.getName());
template.binding("entity", entity); map.put("methodName", BaseTarget.upperFirst(attr.getName()));
template.binding("target", target); map.put("isId", attr.isId());
template.binding("package", gen.basePackage+".web.query"); map.put("dictType", attr.getDictType());
template.binding("basePackage", gen.basePackage); attrs.add(map);
template.binding("attrs", list); }
String content = template.render(); template.binding("attrs", attrs);
target.flush(this, content); String srcHead = "";
} srcHead += "import java.math.*;" + JavaCodeGen.CR;
srcHead += "import java.util.Date;" + JavaCodeGen.CR;
@Override
public String getName() { srcHead += "import java.sql.Timestamp;" + JavaCodeGen.CR;
return gen.entity.getName()+"Query.java"; template.binding("imports", srcHead);
} template.binding("comment", entity.getComment());
String content = template.render();
target.flush(this, content);
}
@Override
public String getName() {
return gen.entity.getName() + ".java";
}
} }
class JavaDaoGen implements AutoGen {
JavaCodeGen gen;
public JavaDaoGen(JavaCodeGen gen) {
this.gen = gen;
}
@Override
public void make(Target target, Entity entity) {
GroupTemplate gt = target.getGroupTemplate();
Template template = gt.getTemplate("/java/dao.java");
template.binding("entity", entity);
template.binding("target", target);
template.binding("package", gen.basePackage + ".dao");
template.binding("basePackage", gen.basePackage);
String content = template.render();
target.flush(this, content);
}
@Override
public String getName() {
return gen.entity.getName() + "Dao.java";
}
}
class JavaServiceGen implements AutoGen {
JavaCodeGen gen;
public JavaServiceGen(JavaCodeGen gen) {
this.gen = gen;
}
@Override
public void make(Target target, Entity entity) {
GroupTemplate gt = target.getGroupTemplate();
Template template = gt.getTemplate("/java/service.java");
template.binding("entity", entity);
template.binding("target", target);
template.binding("package", gen.basePackage + ".service");
template.binding("basePackage", gen.basePackage);
String content = template.render();
target.flush(this, content);
}
@Override
public String getName() {
return gen.entity.getName() + "Service.java";
}
}
class JavaControllerGen implements AutoGen {
JavaCodeGen gen;
public JavaControllerGen(JavaCodeGen gen) {
this.gen = gen;
}
@Override
public void make(Target target, Entity entity) {
GroupTemplate gt = target.getGroupTemplate();
Template template = gt.getTemplate("/java/controller.java");
template.binding("entity", entity);
template.binding("target", target);
template.binding("package", gen.basePackage + ".web");
template.binding("basePackage", gen.basePackage);
template.binding("basicfunctionCode", gen.basicFunctionCode);
String content = template.render();
target.flush(this, content);
}
@Override
public String getName() {
return gen.entity.getName() + "Controller.java";
}
}
class JavaQueryGen implements AutoGen {
JavaCodeGen gen;
public JavaQueryGen(JavaCodeGen gen) {
this.gen = gen;
}
@Override
public void make(Target target, Entity entity) {
GroupTemplate gt = target.getGroupTemplate();
Template template = gt.getTemplate("/java/query.java");
List<Attribute> list = new ArrayList<Attribute>();
for (Attribute attr : entity.getList()) {
if (attr.isShowInQuery()) {
list.add(attr);
}
}
if (list.isEmpty()) {
list.add(entity.getIdAttribute());
}
template.binding("entity", entity);
template.binding("target", target);
template.binding("package", gen.basePackage + ".web.query");
template.binding("basePackage", gen.basePackage);
template.binding("attrs", list);
String content = template.render();
target.flush(this, content);
}
@Override
public String getName() {
return gen.entity.getName() + "Query.java";
}
}
...@@ -7,114 +7,116 @@ import java.io.IOException; ...@@ -7,114 +7,116 @@ import java.io.IOException;
import com.ibeetl.admin.core.gen.model.Entity; import com.ibeetl.admin.core.gen.model.Entity;
public class MavenProjectTarget extends BaseTarget { public class MavenProjectTarget extends BaseTarget {
Entity entity; Entity entity;
String basePackage; String basePackage;
String basePackagePath = null; String basePackagePath = null;
String targetPath = null; String targetPath = null;
public MavenProjectTarget(Entity entity,String basePackage) { public MavenProjectTarget(Entity entity, String basePackage) {
this.entity = entity; this.entity = entity;
this.basePackage = basePackage; this.basePackage = basePackage;
this.basePackagePath = basePackage.replace('.', '/'); this.basePackagePath = basePackage.replace('.', '/');
} }
@Override @Override
public void flush(AutoGen gen, String content) { public void flush(AutoGen gen, String content) {
String name = gen.getName(); String name = gen.getName();
String target = null; String target = null;
if (gen instanceof JSDelGen) { if (gen instanceof JSDelGen) {
target = getResourcePath()+"/static/js/"+this.urlBase+"/"+entity.getCode()+"/"+name; target =
}else if (gen instanceof JSEditGen) { getResourcePath() + "/static/js/" + this.urlBase + "/" + entity.getCode() + "/" + name;
target = getResourcePath()+"/static/js/"+this.urlBase+"/"+entity.getCode()+"/"+name; } else if (gen instanceof JSEditGen) {
}else if (gen instanceof JSAddGen) { target =
target = getResourcePath()+"/static/js/"+this.urlBase+"/"+entity.getCode()+"/"+name; getResourcePath() + "/static/js/" + this.urlBase + "/" + entity.getCode() + "/" + name;
}else if (gen instanceof JSApiGen) { } else if (gen instanceof JSAddGen) {
target = getResourcePath()+"/static/js/"+this.urlBase+"/"+entity.getCode()+"/"+name; target =
}else if (gen instanceof JSIndexGen) { getResourcePath() + "/static/js/" + this.urlBase + "/" + entity.getCode() + "/" + name;
target = getResourcePath()+"/static/js/"+this.urlBase+"/"+entity.getCode()+"/"+name; } else if (gen instanceof JSApiGen) {
}else if (gen instanceof HtmlIndexGen) { target =
target = getResourcePath()+"/templates/"+this.urlBase+"/"+entity.getCode()+"/"+name; getResourcePath() + "/static/js/" + this.urlBase + "/" + entity.getCode() + "/" + name;
}else if (gen instanceof HtmlEditGen) { } else if (gen instanceof JSIndexGen) {
target = getResourcePath()+"/templates/"+this.urlBase+"/"+entity.getCode()+"/"+name; target =
}else if (gen instanceof HtmlAddGen) { getResourcePath() + "/static/js/" + this.urlBase + "/" + entity.getCode() + "/" + name;
target = getResourcePath()+"/templates/"+this.urlBase+"/"+entity.getCode()+"/"+name; } else if (gen instanceof HtmlIndexGen) {
}else if (gen instanceof MdGen) { target =
target = getResourcePath()+"/sql/"+entity.getSystem()+"/"+name; getResourcePath() + "/templates/" + this.urlBase + "/" + entity.getCode() + "/" + name;
}else if (gen instanceof JavaEntityGen) { } else if (gen instanceof HtmlEditGen) {
target = getSrcPath()+"/"+basePackagePath+"/entity/"+name; target =
}else if (gen instanceof JavaDaoGen) { getResourcePath() + "/templates/" + this.urlBase + "/" + entity.getCode() + "/" + name;
target = getSrcPath()+"/"+basePackagePath+"/dao/"+name; } else if (gen instanceof HtmlAddGen) {
}else if (gen instanceof JavaQueryGen) { target =
target = getSrcPath()+"/"+basePackagePath+"/web/query/"+name; getResourcePath() + "/templates/" + this.urlBase + "/" + entity.getCode() + "/" + name;
}else if (gen instanceof JavaServiceGen) { } else if (gen instanceof MdGen) {
target = getSrcPath()+"/"+basePackagePath+"/service/"+name; target = getResourcePath() + "/sql/" + entity.getSystem() + "/" + name;
}else if (gen instanceof JavaControllerGen) { } else if (gen instanceof JavaEntityGen) {
target = getSrcPath()+"/"+basePackagePath+"/web/"+name; target = getSrcPath() + "/" + basePackagePath + "/entity/" + name;
} } else if (gen instanceof JavaDaoGen) {
target = getSrcPath() + "/" + basePackagePath + "/dao/" + name;
if(target==null) { } else if (gen instanceof JavaQueryGen) {
return ; target = getSrcPath() + "/" + basePackagePath + "/web/query/" + name;
} } else if (gen instanceof JavaServiceGen) {
flush(target,content); target = getSrcPath() + "/" + basePackagePath + "/service/" + name;
} else if (gen instanceof JavaControllerGen) {
} target = getSrcPath() + "/" + basePackagePath + "/web/" + name;
}
protected void flush(String path, String content) {
if (target == null) {
FileWriter fw; return;
try { }
File file = new File(path); flush(target, content);
if(!file.getParentFile().exists()) { }
file.getParentFile().mkdirs();
} protected void flush(String path, String content) {
fw = new FileWriter(new File(path));
fw.write(content); FileWriter fw;
fw.close(); try {
System.out.println(path); File file = new File(path);
} catch (IOException e) { if (!file.getParentFile().exists()) {
// TODO Auto-generated catch block file.getParentFile().mkdirs();
e.printStackTrace(); }
} fw = new FileWriter(new File(path));
fw.write(content);
fw.close();
} System.out.println(path);
} catch (IOException e) {
// TODO Auto-generated catch block
public String getTargetPath() { e.printStackTrace();
return targetPath;
} }
}
public void setTargetPath(String targetPath) { public String getTargetPath() {
this.targetPath = targetPath; return targetPath;
}
public void setTargetPath(String targetPath) {
this.targetPath = targetPath;
}
private String getSrcPath() {
return getRootPath() + File.separator + "src/main/java";
}
private String getResourcePath() {
return getRootPath() + File.separator + "src/main/resources";
}
public String getRootPath() {
if (targetPath != null) {
return targetPath;
} else {
return detectRootPath();
} }
}
private String getSrcPath() { public static String detectRootPath() {
String srcPath;
return getRootPath() + File.separator + "src/main/java"; String userDir = System.getProperty("user.dir");
} if (userDir == null) {
throw new NullPointerException("用户目录未找到");
private String getResourcePath() { }
return getRootPath() + File.separator + "src/main/resources";
}
public String getRootPath() {
if(targetPath!=null) {
return targetPath;
}else {
return detectRootPath();
}
}
public static String detectRootPath() {
String srcPath;
String userDir = System.getProperty("user.dir");
if (userDir == null) {
throw new NullPointerException("用户目录未找到");
}
return userDir;
}
return userDir;
}
} }
...@@ -11,30 +11,26 @@ import org.beetl.core.Template; ...@@ -11,30 +11,26 @@ import org.beetl.core.Template;
import com.ibeetl.admin.core.gen.model.Attribute; import com.ibeetl.admin.core.gen.model.Attribute;
import com.ibeetl.admin.core.gen.model.Entity; import com.ibeetl.admin.core.gen.model.Entity;
public class MdGen implements AutoGen{ public class MdGen implements AutoGen {
static String CR = System.getProperty("line.separator"); static String CR = System.getProperty("line.separator");
Entity entity = null; Entity entity = null;
public MdGen() {
public MdGen() {}
}
@Override
public void make(Target target, Entity entity) {
this.entity = entity;
GroupTemplate gt = target.getGroupTemplate();
Template template = gt.getTemplate("/md/entity.md");
template.binding("entity", entity);
template.binding("target", target);
String content = template.render();
target.flush(this, content);
}
@Override
public String getName() {
return entity.getCode()+".md";
}
}
@Override
public void make(Target target, Entity entity) {
this.entity = entity;
GroupTemplate gt = target.getGroupTemplate();
Template template = gt.getTemplate("/md/entity.md");
template.binding("entity", entity);
template.binding("target", target);
String content = template.render();
target.flush(this, content);
}
@Override
public String getName() {
return entity.getCode() + ".md";
}
}
...@@ -4,10 +4,11 @@ import org.beetl.core.GroupTemplate; ...@@ -4,10 +4,11 @@ import org.beetl.core.GroupTemplate;
/** /**
* 描述如何输出代码,有打印后台,页面输出,或者直接生成到项目里 * 描述如何输出代码,有打印后台,页面输出,或者直接生成到项目里
* @author lijiazhi
* *
* @author lijiazhi
*/ */
public interface Target { public interface Target {
public void flush(AutoGen gen,String content); public void flush(AutoGen gen, String content);
public GroupTemplate getGroupTemplate();
public GroupTemplate getGroupTemplate();
} }
...@@ -5,20 +5,16 @@ import java.util.Map; ...@@ -5,20 +5,16 @@ import java.util.Map;
import com.ibeetl.admin.core.gen.model.Entity; import com.ibeetl.admin.core.gen.model.Entity;
public class WebTarget extends MavenProjectTarget { public class WebTarget extends MavenProjectTarget {
public Map<Object,String> map = new HashMap<Object,String>();
public WebTarget(Entity entity,String basePackage) {
super(entity,basePackage);
}
@Override
public void flush(AutoGen gen, String content) {
map.put(gen, content);
} public Map<Object, String> map = new HashMap<Object, String>();
public WebTarget(Entity entity, String basePackage) {
super(entity, basePackage);
}
@Override
public void flush(AutoGen gen, String content) {
map.put(gen, content);
}
} }
...@@ -4,106 +4,123 @@ import java.util.ArrayList; ...@@ -4,106 +4,123 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class Attribute { public class Attribute {
private String name; private String name;
private String colName; private String colName;
private String javaType; private String javaType;
private String displayName; private String displayName;
private boolean isId; private boolean isId;
private boolean showInQuery =false; private boolean showInQuery = false;
//数据字典 // 数据字典
private String dictType; private String dictType;
private String comment; private String comment;
// 是否范围 // 是否范围
private boolean isDateRange; private boolean isDateRange;
private boolean isDateTimeRange; private boolean isDateTimeRange;
//校验对象 // 校验对象
private List<Verify> verifyList = new ArrayList<>(); private List<Verify> verifyList = new ArrayList<>();
public Attribute() {
public Attribute() { super();
super(); }
}
public String getName() { public String getName() {
return name; return name;
} }
public void setName(String name) {
this.name = name; public void setName(String name) {
} this.name = name;
public String getColName() { }
return colName;
} public String getColName() {
public void setColName(String colName) { return colName;
this.colName = colName; }
}
public String getJavaType() { public void setColName(String colName) {
return javaType; this.colName = colName;
} }
public void setJavaType(String javaType) {
this.javaType = javaType; public String getJavaType() {
} return javaType;
public String getDisplayName() { }
if(displayName==null) {
return this.name; public void setJavaType(String javaType) {
} this.javaType = javaType;
return displayName; }
}
public void setDisplayName(String displayName) { public String getDisplayName() {
this.displayName = displayName; if (displayName == null) {
} return this.name;
public boolean isId() { }
return isId; return displayName;
} }
public void setId(boolean isId) {
this.isId = isId; public void setDisplayName(String displayName) {
} this.displayName = displayName;
public boolean isShowInQuery() { }
return showInQuery;
} public boolean isId() {
public void setShowInQuery(boolean showInQuery) { return isId;
this.showInQuery = showInQuery; }
}
public String getComment() { public void setId(boolean isId) {
return comment; this.isId = isId;
} }
public void setComment(String comment) {
this.comment = comment; public boolean isShowInQuery() {
} return showInQuery;
public String getDictType() { }
return dictType;
public void setShowInQuery(boolean showInQuery) {
this.showInQuery = showInQuery;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
public String getDictType() {
return dictType;
}
public void setDictType(String dictType) {
this.dictType = dictType;
}
public List<Verify> getVerifyList() {
return verifyList;
}
public void setVerifyList(List<Verify> verifyList) {
this.verifyList = verifyList;
}
public boolean isDateRange() {
for (Verify verify : verifyList) {
if (verify.getName().equals("dateRange")) {
return true;
}
} }
public void setDictType(String dictType) { return false;
this.dictType = dictType; }
public void setDateRange(boolean dateRange) {
isDateRange = dateRange;
}
public boolean isDateTimeRange() {
for (Verify verify : verifyList) {
if (verify.getName().equals("datetimeRange")) {
return true;
}
} }
public List<Verify> getVerifyList() { return false;
return verifyList; }
}
public void setVerifyList(List<Verify> verifyList) { public void setDateTimeRange(boolean dateTimeRange) {
this.verifyList = verifyList; isDateTimeRange = dateTimeRange;
} }
public boolean isDateRange() {
for(Verify verify: verifyList) {
if(verify.getName().equals("dateRange")) {
return true;
}
}
return false;
}
public void setDateRange(boolean dateRange) {
isDateRange = dateRange;
}
public boolean isDateTimeRange() {
for(Verify verify: verifyList) {
if(verify.getName().equals("datetimeRange")) {
return true;
}
}
return false;
}
public void setDateTimeRange(boolean dateTimeRange) {
isDateTimeRange = dateTimeRange;
}
} }
...@@ -4,115 +4,138 @@ import java.util.ArrayList; ...@@ -4,115 +4,138 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class Entity { public class Entity {
String name; String name;
String tableName; String tableName;
String code; String code;
String displayName; String displayName;
ArrayList<Attribute> list = new ArrayList<Attribute>(); ArrayList<Attribute> list = new ArrayList<Attribute>();
Attribute idAttribute; Attribute idAttribute;
Attribute nameAttribute; Attribute nameAttribute;
String comment; String comment;
String system; String system;
//是否生成excel导入导出按钮 // 是否生成excel导入导出按钮
boolean includeExcel =false; boolean includeExcel = false;
//是否包含附件信息 // 是否包含附件信息
boolean attachment=false; boolean attachment = false;
//是否生成代码,也同时生成功能点 // 是否生成代码,也同时生成功能点
boolean autoAddFunction = false; boolean autoAddFunction = false;
boolean autoAddMenu = false; boolean autoAddMenu = false;
public String getName() { public String getName() {
return name; return name;
} }
public void setName(String name) {
this.name = name; public void setName(String name) {
} this.name = name;
public String getTableName() { }
return tableName;
} public String getTableName() {
public void setTableName(String tableName) { return tableName;
this.tableName = tableName; }
}
public String getCode() { public void setTableName(String tableName) {
return code; this.tableName = tableName;
} }
public void setCode(String code) {
this.code = code; public String getCode() {
} return code;
public String getDisplayName() { }
if(displayName==null) {
return this.displayName; public void setCode(String code) {
} this.code = code;
return displayName; }
}
public void setDisplayName(String displayName) { public String getDisplayName() {
this.displayName = displayName; if (displayName == null) {
} return this.displayName;
public ArrayList<Attribute> getList() {
return list;
}
public void setList(ArrayList<Attribute> list) {
this.list = list;
}
public Attribute getIdAttribute() {
return idAttribute;
}
public void setIdAttribute(Attribute idAttribute) {
this.idAttribute = idAttribute;
}
public Attribute getNameAttribute() {
return nameAttribute;
}
public void setNameAttribute(Attribute nameAttribute) {
this.nameAttribute = nameAttribute;
}
public String getSystem() {
return system;
}
public void setSystem(String system) {
this.system = system;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
public List<Attribute> getGeneralList(){
List<Attribute> newList = new ArrayList<Attribute>();
for(Attribute attr:list) {
if(attr.getName().equals(this.idAttribute.getName())) {
continue;
}
newList.add(attr);
}
return newList;
}
public boolean isIncludeExcel() {
return includeExcel;
}
public void setIncludeExcel(boolean includeExcel) {
this.includeExcel = includeExcel;
}
public boolean isAttachment() {
return attachment;
} }
public void setAttachment(boolean attachment) { return displayName;
this.attachment = attachment; }
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public ArrayList<Attribute> getList() {
return list;
}
public void setList(ArrayList<Attribute> list) {
this.list = list;
}
public Attribute getIdAttribute() {
return idAttribute;
}
public void setIdAttribute(Attribute idAttribute) {
this.idAttribute = idAttribute;
}
public Attribute getNameAttribute() {
return nameAttribute;
}
public void setNameAttribute(Attribute nameAttribute) {
this.nameAttribute = nameAttribute;
}
public String getSystem() {
return system;
}
public void setSystem(String system) {
this.system = system;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
public List<Attribute> getGeneralList() {
List<Attribute> newList = new ArrayList<Attribute>();
for (Attribute attr : list) {
if (attr.getName().equals(this.idAttribute.getName())) {
continue;
}
newList.add(attr);
} }
public boolean isAutoAddFunction() { return newList;
return autoAddFunction; }
}
public void setAutoAddFunction(boolean autoAddFunction) { public boolean isIncludeExcel() {
this.autoAddFunction = autoAddFunction; return includeExcel;
} }
public boolean isAutoAddMenu() {
return autoAddMenu; public void setIncludeExcel(boolean includeExcel) {
} this.includeExcel = includeExcel;
public void setAutoAddMenu(boolean autoAddMenu) { }
this.autoAddMenu = autoAddMenu;
} public boolean isAttachment() {
return attachment;
}
public void setAttachment(boolean attachment) {
this.attachment = attachment;
}
public boolean isAutoAddFunction() {
return autoAddFunction;
}
public void setAutoAddFunction(boolean autoAddFunction) {
this.autoAddFunction = autoAddFunction;
}
public boolean isAutoAddMenu() {
return autoAddMenu;
}
public void setAutoAddMenu(boolean autoAddMenu) {
this.autoAddMenu = autoAddMenu;
}
} }
package com.ibeetl.admin.core.gen.model; package com.ibeetl.admin.core.gen.model;
/** /** 添加表单属性的校验 */
* 添加表单属性的校验
*/
public class Verify { public class Verify {
private String name;//校验规则名称 private String name; // 校验规则名称
public String getName() { public String getName() {
return name; return name;
} }
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
} }
...@@ -2,15 +2,18 @@ package com.ibeetl.admin.core.rbac; ...@@ -2,15 +2,18 @@ package com.ibeetl.admin.core.rbac;
/** /**
* 数据权限算法结果 * 数据权限算法结果
* @author xiandafu
* *
* @author xiandafu
*/ */
public enum AccessType { public enum AccessType {
OnlyUser(1), OnlyOrg(2), AllOrg(3), NoneOrg(4); OnlyUser(1),
OnlyOrg(2),
AllOrg(3),
NoneOrg(4);
private int value; private int value;
AccessType(int value) { AccessType(int value) {
this.value = value; this.value = value;
} }
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment