Commit 84ae12a0 authored by 赵啸非's avatar 赵啸非

编写系统代码生成模块

parent e15256e7
...@@ -139,8 +139,8 @@ export default { ...@@ -139,8 +139,8 @@ export default {
// 格式化单元格数据 // 格式化单元格数据
formatter(row, column, val) { formatter(row, column, val) {
const content = formatter(this.tableData, column, val); const content = formatter(this.tableData, column, val);
return content; //return content;
// return content ? <el-tag type={'info'} size='mini'>{content}</el-tag> : val return content ? <el-tag type={'info'} size='mini'>{content}</el-tag> : val
}, },
formatterLink(row, column, val) { formatterLink(row, column, val) {
const content = formatter(this.tableData, column-2, val); const content = formatter(this.tableData, column-2, val);
......
...@@ -172,6 +172,11 @@ export const normalCallGet = (url, formData, config= {}) => { ...@@ -172,6 +172,11 @@ export const normalCallGet = (url, formData, config= {}) => {
return call(get, url, formData, config); return call(get, url, formData, config);
}; };
const mimeMap = {
xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
zip: 'application/zip'
}
/** /**
* 普通的ajax download请求 * 普通的ajax download请求
* *
...@@ -186,15 +191,35 @@ export const download = (url, formData, config= {}) => { ...@@ -186,15 +191,35 @@ export const download = (url, formData, config= {}) => {
responseType:'blob' responseType:'blob'
}) })
try { try {
console.log("option",option)
const data = await post(url, formData, option) const data = await post(url, formData, option)
let downloadUrl = window.URL.createObjectURL(new Blob([data]))
let link = document.createElement('a') const link = document.createElement('a')
link.style.display ='none'; var blob = new Blob([data], { type: mimeMap.zip })
link.href = downloadUrl; // //从response的headers中获取filename, 后端response.setHeader("Content-disposition", "attachment; filename=xxxx.docx") 设置的文件名;
link.setAttribute('download', `${url.substr(1).replace(/\//g, '_')}_${new Date().getTime()}.xls`); // var patt = new RegExp('filename=([^;]+\\.[^\\.;]+);*')
document.body.appendChild(link); // var contentDisposition = decodeURI(DataTransferItem.headers['Content-Disposition'])
link.click(); // var result = patt.exec(contentDisposition)
document.body.removeChild(link); // var fileName = result[1]
// fileName = fileName.replace(/\"/g, '')
link.href = URL.createObjectURL(blob)
link.setAttribute('download', `${url.substr(1).replace(/\//g, '_')}_${new Date().getTime()}.zip`) // 设置下载文件名称
document.body.appendChild(link)
link.click()
document.body.appendChild(link)
// const data = await post(url, formData, option)
// let downloadUrl = window.URL.createObjectURL(new Blob([data]))
// let link = document.createElement('a')
// link.style.display ='none';
// link.href = downloadUrl;
// link.setAttribute('download', `${url.substr(1).replace(/\//g, '_')}_${new Date().getTime()}.xls`);
// document.body.appendChild(link);
// link.click();
// document.body.removeChild(link);
resolve(); resolve();
} catch (error) { } catch (error) {
reject(error); reject(error);
...@@ -202,6 +227,7 @@ export const download = (url, formData, config= {}) => { ...@@ -202,6 +227,7 @@ export const download = (url, formData, config= {}) => {
}) })
}; };
export const downloadWithCustName = (url, formData, config= {}) => { export const downloadWithCustName = (url, formData, config= {}) => {
return new Promise(async (resolve, reject)=>{ return new Promise(async (resolve, reject)=>{
const option = Object.assign({}, config, { const option = Object.assign({}, config, {
......
...@@ -14,6 +14,7 @@ Prototype.install = (Vue, options) => { ...@@ -14,6 +14,7 @@ Prototype.install = (Vue, options) => {
Vue.prototype.$isLogin = utils.getLoginStatus; // {function} 登录状态 Vue.prototype.$isLogin = utils.getLoginStatus; // {function} 登录状态
Vue.prototype.$cookie = cookie; // {object} cookie操作 Vue.prototype.$cookie = cookie; // {object} cookie操作
Vue.prototype.$handleTree = utils.handleTree; // {function} 获取js对象类型 Vue.prototype.$handleTree = utils.handleTree; // {function} 获取js对象类型
Vue.prototype.$download = utils.download; // {function} ajax download
} }
export default Prototype; export default Prototype;
...@@ -106,6 +106,12 @@ ...@@ -106,6 +106,12 @@
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.31</version>
</dependency>
</dependencies> </dependencies>
</project> </project>
...@@ -13,14 +13,16 @@ import org.springframework.stereotype.Component; ...@@ -13,14 +13,16 @@ import org.springframework.stereotype.Component;
@Component @Component
@ConfigurationProperties(prefix = "gen") @ConfigurationProperties(prefix = "gen")
@PropertySource(value = { "classpath:generator.yml" }) @PropertySource(value = { "classpath:generator.yml" })
public class GenConfig public class GenConfig {
{
/** 作者 */ /** 作者 */
public static String author; public static String author;
/** 生成包路径 */ /** 生成包路径 */
public static String packageName; public static String packageName;
/** 生成moduleName */
public static String moduleName;
/** 自动去除表前缀,默认是false */ /** 自动去除表前缀,默认是false */
public static boolean autoRemovePre; public static boolean autoRemovePre;
...@@ -49,6 +51,15 @@ public class GenConfig ...@@ -49,6 +51,15 @@ public class GenConfig
GenConfig.packageName = packageName; GenConfig.packageName = packageName;
} }
public static String getModuleName() {
return moduleName;
}
@Value("${moduleName}")
public void setModuleName(String moduleName) {
GenConfig.moduleName = moduleName;
}
public static boolean getAutoRemovePre() public static boolean getAutoRemovePre()
{ {
return autoRemovePre; return autoRemovePre;
......
...@@ -9,7 +9,7 @@ import com.mortals.xhx.common.utils.StringUtils; ...@@ -9,7 +9,7 @@ import com.mortals.xhx.common.utils.StringUtils;
* Description:GentableColumn * Description:GentableColumn
* date: 2021-9-29 18:10:02 * date: 2021-9-29 18:10:02
*/ */
public class GentableColumnEntity extends BaseEntityLong{ public class GentableColumnEntity extends GentableColumnEntityExt{
private static final long serialVersionUID = 1632910202558L; private static final long serialVersionUID = 1632910202558L;
......
...@@ -2,14 +2,19 @@ package com.mortals.xhx.base.system.gentable.model; ...@@ -2,14 +2,19 @@ package com.mortals.xhx.base.system.gentable.model;
import com.mortals.framework.model.BaseEntityLong; import com.mortals.framework.model.BaseEntityLong;
import com.mortals.xhx.common.utils.StringUtils; import com.mortals.xhx.common.utils.StringUtils;
import lombok.Data;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.Map;
/** /**
* Description:GentableColumn * Description:GentableColumn
* date: 2021-9-28 10:10:15 * date: 2021-9-28 10:10:15
*/ */
@Data
public class GentableColumnEntityExt extends BaseEntityLong { public class GentableColumnEntityExt extends BaseEntityLong {
private List<Map<String,String>> dict;
} }
\ No newline at end of file
...@@ -10,13 +10,14 @@ import java.util.List; ...@@ -10,13 +10,14 @@ import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
* <p>Title: 代码生成业务表</p> * <p>Title: 代码生成业务表</p>
* <p>Description: GentableService service接口 </p> * <p>Description: GentableService service接口 </p>
* <p>Copyright: Copyright &reg; </p> * <p>Copyright: Copyright &reg; </p>
* @version 1.0.0 *
*/ * @version 1.0.0
*/
public interface GentableService extends ICRUDService<GentableEntity,Long> { public interface GentableService extends ICRUDService<GentableEntity, Long> {
/** /**
* 查询据库列表 * 查询据库列表
...@@ -24,7 +25,7 @@ public interface GentableService extends ICRUDService<GentableEntity,Long> { ...@@ -24,7 +25,7 @@ public interface GentableService extends ICRUDService<GentableEntity,Long> {
* @param query 业务信息 * @param query 业务信息
* @return 数据库表集合 * @return 数据库表集合
*/ */
List<GentableEntity> selectDbTableList(GentableQuery query); List<GentableEntity> selectDbTableList(GentableQuery query);
/** /**
...@@ -33,28 +34,28 @@ public interface GentableService extends ICRUDService<GentableEntity,Long> { ...@@ -33,28 +34,28 @@ public interface GentableService extends ICRUDService<GentableEntity,Long> {
* @param tableNames 表名称组 * @param tableNames 表名称组
* @return 数据库表集合 * @return 数据库表集合
*/ */
List<GentableEntity> selectDbTableListByNames(String[] tableNames); List<GentableEntity> selectDbTableListByNames(String[] tableNames);
/** /**
* 查询所有表信息 * 查询所有表信息
* *
* @return 表信息集合 * @return 表信息集合
*/ */
List<GentableEntity> selectGenTableAll(); List<GentableEntity> selectGenTableAll();
/** /**
* 导入表结构 * 导入表结构
* *
* @param tableList 导入表列表 * @param tableList 导入表列表
*/ */
void importGenTable(List<GentableEntity> tableList, Context context); void importGenTable(List<GentableEntity> tableList, Context context);
/** /**
* 修改保存参数校验 * 修改保存参数校验
* *
* @param genTable 业务信息 * @param genTable 业务信息
*/ */
void validateEdit(GentableEntity genTable); void validateEdit(GentableEntity genTable);
/** /**
...@@ -63,7 +64,7 @@ public interface GentableService extends ICRUDService<GentableEntity,Long> { ...@@ -63,7 +64,7 @@ public interface GentableService extends ICRUDService<GentableEntity,Long> {
* @param id 表Id * @param id 表Id
* @return 预览数据列表 * @return 预览数据列表
*/ */
Map<String, String> previewCode(Long id); Map<String, String> previewCode(Long id);
/** /**
* 生成代码(单表生成下载方式) * 生成代码(单表生成下载方式)
...@@ -71,5 +72,20 @@ public interface GentableService extends ICRUDService<GentableEntity,Long> { ...@@ -71,5 +72,20 @@ public interface GentableService extends ICRUDService<GentableEntity,Long> {
* @param tableName 表名称 * @param tableName 表名称
* @return 数据 * @return 数据
*/ */
byte[] downloadCode(String tableName); byte[] downloadCode(String tableName);
/**
* 批量生成代码(下载方式)
*
* @param tableNames 表数组
* @return 数据
*/
byte[] downloadCode(String[] tableNames);
/**
* 同步数据库
*
* @param tableName 表名称
*/
void synchDb(String tableName);
} }
\ No newline at end of file
...@@ -24,6 +24,7 @@ import com.mortals.xhx.common.utils.GenUtils; ...@@ -24,6 +24,7 @@ import com.mortals.xhx.common.utils.GenUtils;
import com.mortals.xhx.common.utils.StringUtils; import com.mortals.xhx.common.utils.StringUtils;
import freemarker.template.Template; import freemarker.template.Template;
import freemarker.template.TemplateException; import freemarker.template.TemplateException;
import lombok.SneakyThrows;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -33,6 +34,7 @@ import java.io.ByteArrayOutputStream; ...@@ -33,6 +34,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.StringWriter; import java.io.StringWriter;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
...@@ -122,8 +124,14 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge ...@@ -122,8 +124,14 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge
// 查询表信息 // 查询表信息
GentableEntity gentableEntity = this.get(id); GentableEntity gentableEntity = this.get(id);
List<GentableColumnEntity> columnEntities = this.gentableColumnService.find(new GentableColumnQuery().tableId(gentableEntity.getId())).stream().map(column -> {
List<GentableColumnEntity> columnEntities = this.gentableColumnService.find(new GentableColumnQuery().tableId(gentableEntity.getId())); //拆解枚举类,格式必须为(1.啊啊啊,2.不不不)
String temp1 = StringUtils.substringBetween(column.getColumnComment(), "(", ")");
String temp2 = StringUtils.substringBetween(column.getColumnComment(), "(", ")");
GenUtils.checkDict(column, temp1);
GenUtils.checkDict(column, temp2);
return column;
}).collect(Collectors.toList());
gentableEntity.setColumns(columnEntities); gentableEntity.setColumns(columnEntities);
// 设置主子表信息 // 设置主子表信息
setSubTable(gentableEntity); setSubTable(gentableEntity);
...@@ -167,15 +175,78 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge ...@@ -167,15 +175,78 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge
} }
@SneakyThrows
@Override @Override
public byte[] downloadCode(String tableName) { public byte[] downloadCode(String tableName) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ZipOutputStream zip = new ZipOutputStream(outputStream); ZipOutputStream zip = new ZipOutputStream(outputStream);
FreeMarkerUtils.menuSql = new StringBuilder();
FreeMarkerUtils.dbSql = new StringBuilder();
generatorCode(tableName, zip); generatorCode(tableName, zip);
if (StringUtils.isNotEmpty(FreeMarkerUtils.menuSql)) {
zip.putNextEntry(new ZipEntry("db/menu.sql"));
IOUtils.write(FreeMarkerUtils.menuSql.toString(), zip, Constant.UTF8);
}
if (StringUtils.isNotEmpty(FreeMarkerUtils.dbSql)) {
zip.putNextEntry(new ZipEntry("db/db.sql"));
IOUtils.write(FreeMarkerUtils.dbSql.toString(), zip, Constant.UTF8);
}
IOUtils.closeQuietly(zip); IOUtils.closeQuietly(zip);
return outputStream.toByteArray(); return outputStream.toByteArray();
} }
@SneakyThrows
@Override
public byte[] downloadCode(String[] tableNames) {
FreeMarkerUtils.menuSql = new StringBuilder();
FreeMarkerUtils.dbSql = new StringBuilder();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ZipOutputStream zip = new ZipOutputStream(outputStream);
for (String tableName : tableNames) {
generatorCode(tableName, zip);
}
if (StringUtils.isNotEmpty(FreeMarkerUtils.menuSql)) {
zip.putNextEntry(new ZipEntry("db/menu.sql"));
IOUtils.write(FreeMarkerUtils.menuSql.toString(), zip, Constant.UTF8);
}
if (StringUtils.isNotEmpty(FreeMarkerUtils.dbSql)) {
zip.putNextEntry(new ZipEntry("db/db.sql"));
IOUtils.write(FreeMarkerUtils.dbSql.toString(), zip, Constant.UTF8);
}
IOUtils.closeQuietly(zip);
return outputStream.toByteArray();
}
@Override
public void synchDb(String tableName) {
GentableEntity table = this.selectOne(new GentableQuery().tableName(tableName));
List<GentableColumnEntity> tableColumns = gentableColumnService.find(new GentableColumnQuery().tableId(table.getId()));
table.setColumns(tableColumns);
List<String> tableColumnNames = tableColumns.stream().map(GentableColumnEntity::getColumnName).collect(Collectors.toList());
List<GentableColumnEntity> dbTableColumns = gentableColumnService.selectDbTableColumnsByName(tableName);
if (StringUtils.isEmpty(dbTableColumns)) {
throw new AppException("同步数据失败,原表结构不存在");
}
List<String> dbTableColumnNames = dbTableColumns.stream().map(GentableColumnEntity::getColumnName).collect(Collectors.toList());
dbTableColumns.forEach(column -> {
if (!tableColumnNames.contains(column.getColumnName())) {
GenUtils.initColumnField(column, table);
gentableColumnService.save(column);
}
});
List<GentableColumnEntity> delColumns = tableColumns.stream().filter(column -> !dbTableColumnNames.contains(column.getColumnName())).collect(Collectors.toList());
if (StringUtils.isNotEmpty(delColumns)) {
Long[] ids = delColumns.stream().map(GentableColumnEntity::getId).toArray(Long[]::new);
gentableColumnService.remove(ids, null);
}
}
/** /**
* 查询表信息并生成代码 * 查询表信息并生成代码
...@@ -183,7 +254,15 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge ...@@ -183,7 +254,15 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge
private void generatorCode(String tableName, ZipOutputStream zip) { private void generatorCode(String tableName, ZipOutputStream zip) {
GentableEntity gentableEntity = this.selectOne(new GentableQuery().tableName(tableName)); GentableEntity gentableEntity = this.selectOne(new GentableQuery().tableName(tableName));
if (!ObjectUtils.isEmpty(gentableEntity)) { if (!ObjectUtils.isEmpty(gentableEntity)) {
List<GentableColumnEntity> columnEntities = this.gentableColumnService.find(new GentableColumnQuery().tableId(gentableEntity.getId())); List<GentableColumnEntity> columnEntities = this.gentableColumnService.find(new GentableColumnQuery().tableId(gentableEntity.getId())).stream().map(column -> {
//拆解枚举类,格式必须为(1.啊啊啊,2.不不不)
String temp1 = StringUtils.substringBetween(column.getColumnComment(), "(", ")");
String temp2 = StringUtils.substringBetween(column.getColumnComment(), "(", ")");
GenUtils.checkDict(column, temp1);
GenUtils.checkDict(column, temp2);
return column;
}).collect(Collectors.toList());
gentableEntity.setColumns(columnEntities); gentableEntity.setColumns(columnEntities);
// 设置主子表信息 // 设置主子表信息
...@@ -196,23 +275,30 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge ...@@ -196,23 +275,30 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge
//生成模板基础数据 //生成模板基础数据
Map data = FreeMarkerUtils.prepareSetFreeMarkerData(gentableEntity); Map data = FreeMarkerUtils.prepareSetFreeMarkerData(gentableEntity);
//输出合成模板
//Template template = FreeMarkerUtils.getTemplate("entity.ftl");
Template template = FreeMarkerUtils.getTemplate("service.ftl");
StringWriter sw = new StringWriter();
//通过模板生成不同的业务类 List<String> templates = FreeMarkerUtils.getTemplateList(gentableEntity.getTplCategory());
try { for (String temp : templates) {
template.process(data, sw); //通过模板生成不同的业务类
System.out.println(sw.toString()); try {
// 添加到zip StringWriter sw = new StringWriter();
zip.putNextEntry(new ZipEntry(FreeMarkerUtils.getFileName(template.getName(), gentableEntity))); Template template = FreeMarkerUtils.getTemplate(temp);
IOUtils.write(sw.toString(), zip, Constant.UTF8); template.process(data, sw);
IOUtils.closeQuietly(sw); // 添加到zip
zip.flush(); if (template.getName().equals("menu.sql.ftl")) {
zip.closeEntry(); FreeMarkerUtils.menuSql.append(sw.toString());
} catch (Exception e) { } else if (template.getName().equals("db.sql.ftl")) {
log.error("渲染模板失败,表名:" + gentableEntity.getTableName(), e); FreeMarkerUtils.dbSql.append(sw.toString());
} else {
zip.putNextEntry(new ZipEntry(FreeMarkerUtils.getFileName(template.getName(), gentableEntity)));
IOUtils.write(sw.toString(), zip, Constant.UTF8);
}
IOUtils.closeQuietly(sw);
zip.flush();
zip.closeEntry();
} catch (Exception e) {
log.error("渲染模板失败,表名:" + gentableEntity.getTableName(), e);
}
} }
} }
......
...@@ -142,7 +142,6 @@ public class GentableController extends BaseCRUDJsonMappingController<GentableSe ...@@ -142,7 +142,6 @@ public class GentableController extends BaseCRUDJsonMappingController<GentableSe
@PostMapping("/genCode") @PostMapping("/genCode")
public void genCode(@RequestParam(value = "tableName") String tableName) { public void genCode(@RequestParam(value = "tableName") String tableName) {
Map<String, Object> model = new HashMap<>(); Map<String, Object> model = new HashMap<>();
JSONObject ret = new JSONObject();
String busiDesc = "生成单表代码"; String busiDesc = "生成单表代码";
try { try {
...@@ -155,6 +154,27 @@ public class GentableController extends BaseCRUDJsonMappingController<GentableSe ...@@ -155,6 +154,27 @@ public class GentableController extends BaseCRUDJsonMappingController<GentableSe
} }
/**
* 通过表名生成代码
*
* @param tables
* @return
*/
@PostMapping("/batchGenCode")
public void batchGenCode(@RequestParam(value = "tables") String tables) {
Map<String, Object> model = new HashMap<>();
String busiDesc = "批量生成单表代码";
try {
String[] tableNames = Convert.toStrArray(tables);
byte[] bytes = this.service.downloadCode(tableNames);
genCode(response, bytes);
recordSysLog(request, busiDesc + " 【成功】");
} catch (Exception e) {
this.doException(request, busiDesc, model, e);
}
}
/** /**
* 预览代码 * 预览代码
* *
...@@ -179,6 +199,27 @@ public class GentableController extends BaseCRUDJsonMappingController<GentableSe ...@@ -179,6 +199,27 @@ public class GentableController extends BaseCRUDJsonMappingController<GentableSe
return ret.toJSONString(); return ret.toJSONString();
} }
/**
* 同步数据库
*
* @param tableName
* @return
*/
@PostMapping("/synchDb")
public String synchDb(@RequestParam(value = "tableName") String tableName) {
JSONObject ret = new JSONObject();
String busiDesc = "同步数据库";
int code = VALUE_RESULT_SUCCESS;
try {
this.service.synchDb(tableName);
recordSysLog(request, busiDesc + " 【成功】");
} catch (Exception e) {
code = VALUE_RESULT_FAILURE;
}
ret.put(KEY_RESULT_CODE, code);
return ret.toJSONString();
}
/** /**
* 生成zip文件 * 生成zip文件
...@@ -187,7 +228,7 @@ public class GentableController extends BaseCRUDJsonMappingController<GentableSe ...@@ -187,7 +228,7 @@ public class GentableController extends BaseCRUDJsonMappingController<GentableSe
response.reset(); response.reset();
response.addHeader("Access-Control-Allow-Origin", "*"); response.addHeader("Access-Control-Allow-Origin", "*");
response.addHeader("Access-Control-Expose-Headers", "Content-Disposition"); response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
response.setHeader("Content-Disposition", "attachment; filename=\"ruoyi.zip\""); response.setHeader("Content-Disposition", "attachment; filename=\"genCode.zip\"");
response.addHeader("Content-Length", "" + data.length); response.addHeader("Content-Length", "" + data.length);
response.setContentType("application/octet-stream; charset=UTF-8"); response.setContentType("application/octet-stream; charset=UTF-8");
IOUtils.write(data, response.getOutputStream()); IOUtils.write(data, response.getOutputStream());
......
...@@ -71,19 +71,20 @@ public class GenConstants { ...@@ -71,19 +71,20 @@ public class GenConstants {
/** /**
* 页面不需要编辑字段 * 页面不需要编辑字段
*/ */
public static final String[] COLUMNNAME_NOT_EDIT = {"id", "create_by", "create_time", "del_flag"}; public static final String[] COLUMNNAME_NOT_EDIT = {"id", "createUser", "createTime", "delFlag","updateUser",
"updateTime"};
/** /**
* 页面不需要显示的列表字段 * 页面不需要显示的列表字段
*/ */
public static final String[] COLUMNNAME_NOT_LIST = {"id", "create_by", "create_time", "del_flag", "update_by", public static final String[] COLUMNNAME_NOT_LIST = {"id", "createUser", "createTime", "delFlag", "updateUser",
"update_time"}; "updateTime"};
/** /**
* 页面不需要查询字段 * 页面不需要查询字段
*/ */
public static final String[] COLUMNNAME_NOT_QUERY = {"id", "create_by", "create_time", "del_flag", "update_by", public static final String[] COLUMNNAME_NOT_QUERY = {"id", "createUser", "createTime", "delFlag", "updateUser",
"update_time", "remark"}; "updateTime", "remark"};
/** /**
* Entity基类字段 * Entity基类字段
...@@ -179,4 +180,9 @@ public class GenConstants { ...@@ -179,4 +180,9 @@ public class GenConstants {
* 需要 * 需要
*/ */
public static final Integer REQUIRE = 1; public static final Integer REQUIRE = 1;
/**
* 不需要
*/
public static final Integer NOREQUIRE = 0;
} }
...@@ -14,6 +14,7 @@ import freemarker.template.Template; ...@@ -14,6 +14,7 @@ import freemarker.template.Template;
import freemarker.template.TemplateException; import freemarker.template.TemplateException;
import freemarker.template.TemplateExceptionHandler; import freemarker.template.TemplateExceptionHandler;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import org.springframework.util.ObjectUtils;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
...@@ -44,6 +45,9 @@ public class FreeMarkerUtils { ...@@ -44,6 +45,9 @@ public class FreeMarkerUtils {
public static Configuration cfg = null; public static Configuration cfg = null;
public static StringBuilder dbSql = new StringBuilder();
public static StringBuilder menuSql = new StringBuilder();
/** /**
* 初始化freeMaker方法 * 初始化freeMaker方法
*/ */
...@@ -89,8 +93,12 @@ public class FreeMarkerUtils { ...@@ -89,8 +93,12 @@ public class FreeMarkerUtils {
templates.add("web.java.ftl"); templates.add("web.java.ftl");
templates.add("webForm.java.ftl"); templates.add("webForm.java.ftl");
templates.add("sqlMap.xml.ftl"); templates.add("sqlMap.xml.ftl");
templates.add("webVueList.vue.ftl");
templates.add("webVueShow.vue.ftl");
templates.add("db.sql.ftl");
templates.add("menu.sql.ftl");
if (GenConstants.TPL_CRUD.equals(tplCategory)) { if (GenConstants.TPL_CRUD.equals(tplCategory)) {
// templates.add("vm/vue/index.vue.vm"); // templates.add("vm/vue/index.vue.vm");
} else if (GenConstants.TPL_TREE.equals(tplCategory)) { } else if (GenConstants.TPL_TREE.equals(tplCategory)) {
//templates.add("vm/vue/index-tree.vue.vm"); //templates.add("vm/vue/index-tree.vue.vm");
} else if (GenConstants.TPL_SUB.equals(tplCategory)) { } else if (GenConstants.TPL_SUB.equals(tplCategory)) {
...@@ -119,8 +127,14 @@ public class FreeMarkerUtils { ...@@ -119,8 +127,14 @@ public class FreeMarkerUtils {
Map data = new HashMap(); Map data = new HashMap();
String moduleName = genTable.getModuleName(); String moduleName = genTable.getModuleName();
String businessName = genTable.getBusinessName(); String businessName = genTable.getBusinessName().replace("\\.", "");
String packageName = genTable.getPackageName();
//包路径=basepackage+businessName去除.号
//basepackage=com.mortals.xhx
//module=moduleName
//b
//String packageName = genTable.getPackageName();
String packageName = genTable.getPackageName() + "." + moduleName + "." + businessName;
String tplCategory = genTable.getTplCategory(); String tplCategory = genTable.getTplCategory();
String functionName = genTable.getFunctionName(); String functionName = genTable.getFunctionName();
...@@ -131,8 +145,8 @@ public class FreeMarkerUtils { ...@@ -131,8 +145,8 @@ public class FreeMarkerUtils {
data.put("ClassName", genTable.getClassName()); data.put("ClassName", genTable.getClassName());
data.put("className", StringUtils.uncapitalize(genTable.getClassName())); data.put("className", StringUtils.uncapitalize(genTable.getClassName()));
data.put("moduleName", genTable.getModuleName()); data.put("moduleName", genTable.getModuleName());
data.put("BusinessName", StringUtils.capitalize(genTable.getBusinessName())); data.put("BusinessName", StringUtils.capitalize(businessName));
data.put("businessName", genTable.getBusinessName()); data.put("businessName", businessName);
data.put("basePackage", getPackagePrefix(packageName)); data.put("basePackage", getPackagePrefix(packageName));
data.put("packageName", packageName); data.put("packageName", packageName);
data.put("author", genTable.getFunctionAuthor()); data.put("author", genTable.getFunctionAuthor());
...@@ -150,8 +164,6 @@ public class FreeMarkerUtils { ...@@ -150,8 +164,6 @@ public class FreeMarkerUtils {
if (GenConstants.TPL_SUB.equals(tplCategory)) { if (GenConstants.TPL_SUB.equals(tplCategory)) {
setSubFreeMarkerData(data, genTable); setSubFreeMarkerData(data, genTable);
} }
// System.out.println(JSON.toJSONString(data));
return data; return data;
} }
...@@ -243,15 +255,34 @@ public class FreeMarkerUtils { ...@@ -243,15 +255,34 @@ public class FreeMarkerUtils {
String subTableFkName = genTable.getSubTableFkName(); String subTableFkName = genTable.getSubTableFkName();
String subClassName = genTable.getSubTable().getClassName(); String subClassName = genTable.getSubTable().getClassName();
String subTableFkClassName = StringUtils.convertToCamelCase(subTableFkName); String subTableFkClassName = StringUtils.convertToCamelCase(subTableFkName);
String businessName = subTable.getBusinessName().replace("\\.", "");
String subPackageName = genTable.getPackageName() + "." + genTable.getModuleName() + "." + businessName;
data.put("subTable", subTable); data.put("subTable", subTable);
data.put("subPackageName", subPackageName);
data.put("subTableName", subTableName); data.put("subTableName", subTableName);
data.put("subTableFkName", subTableFkName); data.put("subTableFkName", subTableFkName);
//外键java类型
data.put("subTableFkType", getFkJavaType(subTable, subTableFkName));
data.put("subTableFkClassName", subTableFkClassName); data.put("subTableFkClassName", subTableFkClassName);
data.put("subTableFkclassName", StringUtils.uncapitalize(subTableFkClassName)); data.put("subTableFkclassName", StringUtils.uncapitalize(subTableFkClassName));
data.put("subClassName", subClassName); data.put("subClassName", subClassName);
data.put("subBusinessName", businessName);
data.put("subclassName", StringUtils.uncapitalize(subClassName)); data.put("subclassName", StringUtils.uncapitalize(subClassName));
data.put("subImportList", getImportList(genTable.getSubTable())); data.put("subImportList", getImportList(subTable));
data.put("subColumns", subTable.getColumns());
data.put("subPkColumn", subTable.getPkColumn());
}
private static String getFkJavaType(GentableEntity subTable, String subTableFkName) {
String subTableFkType = "";
GentableColumnEntity gentableColumnEntity = subTable.getColumns().stream().filter(f -> subTableFkName.equals(f.getColumnName())).findFirst().orElseGet(() -> null);
if (!ObjectUtils.isEmpty(gentableColumnEntity)) {
subTableFkType = gentableColumnEntity.getJavaType();
}
return subTableFkType;
} }
...@@ -306,42 +337,36 @@ public class FreeMarkerUtils { ...@@ -306,42 +337,36 @@ public class FreeMarkerUtils {
// 业务名称 // 业务名称
String businessName = StringUtils.replace(genTable.getBusinessName(), ".", "/"); String businessName = StringUtils.replace(genTable.getBusinessName(), ".", "/");
// main/java+ packageName(com.mortals.xhx.modules) // main/java+ packageName(com.mortals.xhx.modules)
String javaPath = PROJECT_PATH + "/" + StringUtils.replace(packageName, ".", "/"); String javaPath = PROJECT_PATH + "/" + StringUtils.replace(packageName, ".", "/") + "/" + moduleName;
String mybatisPath = MYBATIS_PATH + "/" + moduleName; String mybatisPath = MYBATIS_PATH + "/" + moduleName;
String vuePath = "vue"; String vuePath = "vue";
String dbPath = "db";
//实体类输出路径 //实体类输出路径
if (template.contains("entity.ftl")) { if (template.contains("entity.java.ftl")) {
fileName = StringUtils.format("{}/{}/model/{}Entity.java", javaPath, businessName, className); fileName = StringUtils.format("{}/{}/model/{}Entity.java", javaPath, businessName, className);
} else if (template.contains("entityQuery.ftl")) { } else if (template.contains("entityQuery.java.ftl")) {
fileName = StringUtils.format("{}/{}/model/{}Query.java", javaPath, businessName, className); fileName = StringUtils.format("{}/{}/model/{}Query.java", javaPath, businessName, className);
} else if (template.contains("dao.java.ftl")) {
fileName = StringUtils.format("{}/{}/dao/{}Dao.java", javaPath, businessName, className);
} else if (template.contains("daoImpl.java.ftl")) {
fileName = StringUtils.format("{}/{}/dao/ibatis/{}DaoImpl.java", javaPath, businessName, className);
} else if (template.contains("service.java.ftl")) {
fileName = StringUtils.format("{}/{}/service/{}Service.java", javaPath, businessName, className);
} else if (template.contains("serviceImpl.java.ftl")) {
fileName = StringUtils.format("{}/{}/service/impl/{}ServiceImpl.java", javaPath, businessName, className);
} else if (template.contains("web.java.ftl")) {
fileName = StringUtils.format("{}/{}/web/{}Controller.java", javaPath, businessName, className);
} else if (template.contains("webForm.java.ftl")) {
fileName = StringUtils.format("{}/{}/web/{}Form.java", javaPath, businessName, className);
} else if (template.contains("sqlMap.xml.ftl")) {
fileName = StringUtils.format("{}/{}/{}Mapper.xml", mybatisPath, businessName, className);
} else if (template.contains("webVueList.vue.ftl")) {
fileName = StringUtils.format("{}/views/{}/list.vue", vuePath, businessName);
} else if (template.contains("webVueShow.vue.ftl")) {
fileName = StringUtils.format("{}/views/{}/show.vue", vuePath, businessName);
} }
//todo
// if (template.contains("sub-domain.java.vm") && StringUtils.equals(GenConstants.TPL_SUB, genTable.getTplCategory())) {
// fileName = StringUtils.format("{}/domain/{}.java", javaPath, genTable.getSubTable().getClassName());
// } else if (template.contains("mapper.java.vm")) {
// fileName = StringUtils.format("{}/mapper/{}Mapper.java", javaPath, className);
// } else if (template.contains("service.java.vm")) {
// fileName = StringUtils.format("{}/service/I{}Service.java", javaPath, className);
// } else if (template.contains("serviceImpl.java.vm")) {
// fileName = StringUtils.format("{}/service/impl/{}ServiceImpl.java", javaPath, className);
// } else if (template.contains("controller.java.vm")) {
// fileName = StringUtils.format("{}/controller/{}Controller.java", javaPath, className);
// } else if (template.contains("mapper.xml.vm")) {
// fileName = StringUtils.format("{}/{}Mapper.xml", mybatisPath, className);
// } else if (template.contains("sql.vm")) {
// fileName = businessName + "Menu.sql";
// } else if (template.contains("api.js.vm")) {
// fileName = StringUtils.format("{}/api/{}/{}.js", vuePath, moduleName, businessName);
// } else if (template.contains("index.vue.vm")) {
// fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName);
// } else if (template.contains("index-tree.vue.vm")) {
// fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName);
// }
return fileName; return fileName;
} }
......
...@@ -9,9 +9,12 @@ import com.mortals.xhx.common.code.HtmlTypeEnum; ...@@ -9,9 +9,12 @@ import com.mortals.xhx.common.code.HtmlTypeEnum;
import com.mortals.xhx.common.code.YesNoEnum; import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.common.key.GenConstants; import com.mortals.xhx.common.key.GenConstants;
import org.apache.commons.lang3.RegExUtils; import org.apache.commons.lang3.RegExUtils;
import org.springframework.util.ObjectUtils;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
...@@ -26,8 +29,9 @@ public class GenUtils { ...@@ -26,8 +29,9 @@ public class GenUtils {
*/ */
public static void initTable(GentableEntity genTable, String operName) { public static void initTable(GentableEntity genTable, String operName) {
genTable.setClassName(convertClassName(genTable.getTableName())); genTable.setClassName(convertClassName(genTable.getTableName()));
//packageName
genTable.setPackageName(GenConfig.getPackageName()); genTable.setPackageName(GenConfig.getPackageName());
genTable.setModuleName(getModuleName(GenConfig.getPackageName())); genTable.setModuleName(GenConfig.getModuleName());
genTable.setBusinessName(getBusinessName(genTable.getTableName())); genTable.setBusinessName(getBusinessName(genTable.getTableName()));
genTable.setFunctionName(replaceText(genTable.getTableComment())); genTable.setFunctionName(replaceText(genTable.getTableComment()));
genTable.setFunctionAuthor(GenConfig.getAuthor()); genTable.setFunctionAuthor(GenConfig.getAuthor());
...@@ -81,17 +85,31 @@ public class GenUtils { ...@@ -81,17 +85,31 @@ public class GenUtils {
// 编辑字段 // 编辑字段
if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName) && column.getIsPrimaryKey()!= YesNoEnum.YES.getValue()) { if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName) && column.getIsPrimaryKey()!= YesNoEnum.YES.getValue()) {
column.setIsEdit(GenConstants.REQUIRE); column.setIsEdit(GenConstants.REQUIRE);
}else{
column.setIsEdit(GenConstants.NOREQUIRE);
} }
// 列表字段 // 列表字段
if (!arraysContains(GenConstants.COLUMNNAME_NOT_LIST, columnName) && column.getIsPrimaryKey()!= YesNoEnum.YES.getValue()) { if (!arraysContains(GenConstants.COLUMNNAME_NOT_LIST, columnName) && column.getIsPrimaryKey()!= YesNoEnum.YES.getValue()) {
column.setIsList(GenConstants.REQUIRE); column.setIsList(GenConstants.REQUIRE);
}else {
column.setIsList(GenConstants.NOREQUIRE);
} }
// 查询字段 // 查询字段
if (!arraysContains(GenConstants.COLUMNNAME_NOT_QUERY, columnName) && column.getIsPrimaryKey()!= YesNoEnum.YES.getValue()) { if (!arraysContains(GenConstants.COLUMNNAME_NOT_QUERY, columnName) && column.getIsPrimaryKey()!= YesNoEnum.YES.getValue()) {
column.setIsQuery(GenConstants.REQUIRE); column.setIsQuery(GenConstants.REQUIRE);
}else {
column.setIsQuery(GenConstants.NOREQUIRE);
} }
//拆解枚举类,格式必须为(1.啊啊啊,2.不不不)
String temp1 = StringUtils.substringBetween(column.getColumnComment(), "(", ")");
String temp2 = StringUtils.substringBetween(column.getColumnComment(), "(", ")");
checkDict(column, temp1);
checkDict(column, temp2);
// if(column.)
// 状态字段设置单选框 // 状态字段设置单选框
if (StringUtils.endsWithIgnoreCase(columnName, "status")) { if (StringUtils.endsWithIgnoreCase(columnName, "status")) {
column.setHtmlType(HtmlTypeEnum.HTML_RADIO.getValue()); column.setHtmlType(HtmlTypeEnum.HTML_RADIO.getValue());
...@@ -115,6 +133,39 @@ public class GenUtils { ...@@ -115,6 +133,39 @@ public class GenUtils {
} }
} }
public static void checkDict(GentableColumnEntity column, String temp) {
if(StringUtils.isNotEmpty(temp)){
String[] split = checkSplitStr(temp,",");
if(split.length<=1){
split = checkSplitStr(temp,",");
}
if(split.length<=1){
split = checkSplitStr(temp,"、");
}
if(split.length>0){
Arrays.asList(split).stream().peek(item->{
String[] vals =checkSplitStr(item,".");
if(vals.length>1){
HashMap<String, String> map = new HashMap<>();
map.put("num",vals[0]);
map.put("value",vals[1]);
if(ObjectUtils.isEmpty(column.getDict())){
column.setDict(new ArrayList<>());
}
column.getDict().add(map);
}
}).count();
}
}
}
public static String[] checkSplitStr(String temp,String separator) {
return StringUtils.split(temp, separator);
}
/** /**
* 校验数组是否包含指定值 * 校验数组是否包含指定值
* *
...@@ -242,7 +293,6 @@ public class GenUtils { ...@@ -242,7 +293,6 @@ public class GenUtils {
System.out.println(Arrays.stream(name.split("_")).collect(Collectors.joining("."))); System.out.println(Arrays.stream(name.split("_")).collect(Collectors.joining(".")));
System.out.println(Arrays.stream("data".split(".")).collect(Collectors.joining("/"))); System.out.println(Arrays.stream("data".split(".")).collect(Collectors.joining("/")));
} }
} }
package com.mortals.xhx.module.demo.dao;
import com.mortals.framework.dao.ICRUDDao;
import com.mortals.xhx.module.demo.model.DemoEntity;
/**
* 测试Dao
* 测试 DAO接口
*
* @author zxfei
* @date 2021-10-03
*/
public interface DemoDao extends ICRUDDao<DemoEntity,String>{
}
package com.mortals.xhx.module.demo.dao.ibatis;
import org.springframework.stereotype.Repository;
import com.mortals.xhx.module.demo.dao.DemoDao;
import com.mortals.xhx.module.demo.model.DemoEntity;
import java.util.Date;
import com.mortals.framework.dao.ibatis.BaseCRUDDaoMybatis;
/**
* 测试DaoImpl DAO接口
*
* @author zxfei
* @date 2021-10-03
*/
@Repository("demoDao")
public class DemoDaoImpl extends BaseCRUDDaoMybatis<DemoEntity,String> implements DemoDao {
}
package com.mortals.xhx.module.demo.detail.dao;
import com.mortals.framework.dao.ICRUDDao;
import com.mortals.xhx.module.demo.detail.model.DemoDetailEntity;
/**
* Dao
* DAO接口
*
* @author zxfei
* @date 2021-10-03
*/
public interface DemoDetailDao extends ICRUDDao<DemoDetailEntity,Long>{
}
package com.mortals.xhx.module.demo.detail.dao.ibatis;
import org.springframework.stereotype.Repository;
import com.mortals.xhx.module.demo.detail.dao.DemoDetailDao;
import com.mortals.xhx.module.demo.detail.model.DemoDetailEntity;
import java.util.Date;
import com.mortals.framework.dao.ibatis.BaseCRUDDaoMybatis;
/**
* DaoImpl DAO接口
*
* @author zxfei
* @date 2021-10-03
*/
@Repository("demoDetailDao")
public class DemoDetailDaoImpl extends BaseCRUDDaoMybatis<DemoDetailEntity,Long> implements DemoDetailDao {
}
package com.mortals.xhx.module.demo.detail.model;
import com.mortals.framework.model.BaseEntityLong;
/**
* 实体对象
*
* @author zxfei
* @date 2021-10-03
*/
public class DemoDetailEntity extends BaseEntityLong {
private static final long serialVersionUID = 1L;
/**
*
*/
private String demoId;
/**
*
*/
private Long number;
/**
*
*/
private String detail;
public DemoDetailEntity(){}
/**
* 获取
* @return String
*/
public String getDemoId(){
return demoId;
}
/**
* 设置
* @param demoId
*/
public void setDemoId(String demoId){
this.demoId = demoId;
}
/**
* 获取
* @return Long
*/
public Long getNumber(){
return number;
}
/**
* 设置
* @param number
*/
public void setNumber(Long number){
this.number = number;
}
/**
* 获取
* @return String
*/
public String getDetail(){
return detail;
}
/**
* 设置
* @param detail
*/
public void setDetail(String detail){
this.detail = detail;
}
@Override
public int hashCode() {
return this.getId().hashCode();
}
@Override
public boolean equals(Object obj) {
if (obj == null) return false;
if (obj instanceof DemoDetailEntity) {
DemoDetailEntity tmp = (DemoDetailEntity) obj;
if (this.getId() == tmp.getId()) {
return true;
}
}
return false;
}
public String toString(){
StringBuilder sb = new StringBuilder("");
sb.append(",demoId:").append(getDemoId());
sb.append(",number:").append(getNumber());
sb.append(",detail:").append(getDetail());
return sb.toString();
}
public void initAttrValue(){
this.demoId = null;
this.number = null;
this.detail = null;
}
}
\ No newline at end of file
package com.mortals.xhx.module.demo.detail.model;
import java.util.List;
/**
* 查询对象
*
* @author zxfei
* @date 2021-10-03
*/
public class DemoDetailQuery extends DemoDetailEntity {
/** 开始 */
private Long idStart;
/** 结束 */
private Long idEnd;
/** 增加 */
private Long idIncrement;
/** 列表 */
private List<Long> idList;
/** */
private List<String> demoIdList;
/** 开始 */
private Long numberStart;
/** 结束 */
private Long numberEnd;
/** 增加 */
private Long numberIncrement;
/** 列表 */
private List <Long> numberList;
/** */
private List<String> detailList;
/** OR条件集合,列表项之间是OR,项内容之间是AND,如:(list[0].1 and list[0].2) or (list[1].3 and list[1].4) */
private List<DemoDetailQuery> orConditionList;
/** AND条件集合,列表项之间是AND,项内容之间是OR,如:(list[0].1 or list[0].2) and (list[1].3 or list[1].4) */
private List<DemoDetailQuery> andConditionList;
public DemoDetailQuery(){}
/**
* 获取 开始
* @return idStart
*/
public Long getIdStart(){
return this.idStart;
}
/**
* 设置 开始
* @param idStart
*/
public void setIdStart(Long idStart){
this.idStart = idStart;
}
/**
* 获取 结束
* @return $idEnd
*/
public Long getIdEnd(){
return this.idEnd;
}
/**
* 设置 结束
* @param idEnd
*/
public void setIdEnd(Long idEnd){
this.idEnd = idEnd;
}
/**
* 获取 增加
* @return idIncrement
*/
public Long getIdIncrement(){
return this.idIncrement;
}
/**
* 设置 增加
* @param idIncrement
*/
public void setIdIncrement(Long idIncrement){
this.idIncrement = idIncrement;
}
/**
* 获取
* @return idList
*/
public List<Long> getIdList(){
return this.idList;
}
/**
* 设置
* @param idList
*/
public void setIdList(List<Long> idList){
this.idList = idList;
}
/**
* 获取
* @return demoIdList
*/
public List<String> getDemoIdList(){
return this.demoIdList;
}
/**
* 设置
* @param demoIdList
*/
public void setDemoIdList(List<String> demoIdList){
this.demoIdList = demoIdList;
}
/**
* 获取 开始
* @return numberStart
*/
public Long getNumberStart(){
return this.numberStart;
}
/**
* 设置 开始
* @param numberStart
*/
public void setNumberStart(Long numberStart){
this.numberStart = numberStart;
}
/**
* 获取 结束
* @return $numberEnd
*/
public Long getNumberEnd(){
return this.numberEnd;
}
/**
* 设置 结束
* @param numberEnd
*/
public void setNumberEnd(Long numberEnd){
this.numberEnd = numberEnd;
}
/**
* 获取 增加
* @return numberIncrement
*/
public Long getNumberIncrement(){
return this.numberIncrement;
}
/**
* 设置 增加
* @param numberIncrement
*/
public void setNumberIncrement(Long numberIncrement){
this.numberIncrement = numberIncrement;
}
/**
* 获取
* @return numberList
*/
public List<Long> getNumberList(){
return this.numberList;
}
/**
* 设置
* @param numberList
*/
public void setNumberList(List<Long> numberList){
this.numberList = numberList;
}
/**
* 获取
* @return detailList
*/
public List<String> getDetailList(){
return this.detailList;
}
/**
* 设置
* @param detailList
*/
public void setDetailList(List<String> detailList){
this.detailList = detailList;
}
/**
* 设置
* @param id
*/
public DemoDetailQuery id(Long id){
setId(id);
return this;
}
/**
* 设置 开始
* @param idStart
*/
public DemoDetailQuery idStart(Long idStart){
this.idStart = idStart;
return this;
}
/**
* 设置 结束
* @param idEnd
*/
public DemoDetailQuery idEnd(Long idEnd){
this.idEnd = idEnd;
return this;
}
/**
* 设置 增加
* @param idIncrement
*/
public DemoDetailQuery idIncrement(Long idIncrement){
this.idIncrement = idIncrement;
return this;
}
/**
* 设置
* @param idList
*/
public DemoDetailQuery idList(List<Long> idList){
this.idList = idList;
return this;
}
/**
* 设置
* @param demoId
*/
public DemoDetailQuery demoId(String demoId){
setDemoId(demoId);
return this;
}
/**
* 设置
* @param demoIdList
*/
public DemoDetailQuery demoIdList(List<String> demoIdList){
this.demoIdList = demoIdList;
return this;
}
/**
* 设置
* @param number
*/
public DemoDetailQuery number(Long number){
setNumber(number);
return this;
}
/**
* 设置 开始
* @param numberStart
*/
public DemoDetailQuery numberStart(Long numberStart){
this.numberStart = numberStart;
return this;
}
/**
* 设置 结束
* @param numberEnd
*/
public DemoDetailQuery numberEnd(Long numberEnd){
this.numberEnd = numberEnd;
return this;
}
/**
* 设置 增加
* @param numberIncrement
*/
public DemoDetailQuery numberIncrement(Long numberIncrement){
this.numberIncrement = numberIncrement;
return this;
}
/**
* 设置
* @param numberList
*/
public DemoDetailQuery numberList(List<Long> numberList){
this.numberList = numberList;
return this;
}
/**
* 设置
* @param detail
*/
public DemoDetailQuery detail(String detail){
setDetail(detail);
return this;
}
/**
* 设置
* @param detailList
*/
public DemoDetailQuery detailList(List<String> detailList){
this.detailList = detailList;
return this;
}
/**
* 获取 OR条件集合,列表项之间是OR,项内容之间是AND,如:(list[0].1 and list[0].2) or (list[1].3 and list[1].4)
* @return orConditionList
*/
public List<DemoDetailQuery> getOrConditionList(){
return this.orConditionList;
}
/**
* 设置 OR条件集合,列表项之间是OR,项内容之间是AND,如:(list[0].1 and list[0].2) or (list[1].3 and list[1].4)
* @param orConditionList
*/
public void setOrConditionList(List<DemoDetailQuery> orConditionList){
this.orConditionList = orConditionList;
}
/**
* 获取 AND条件集合,列表项之间是AND,项内容之间是OR,如:(list[0].1 or list[0].2) and (list[1].3 or list[1].4)
* @return andConditionList
*/
public List<DemoDetailQuery> getAndConditionList(){
return this.andConditionList;
}
/**
* 设置 AND条件集合,列表项之间是AND,项内容之间是OR,如:(list[0].1 or list[0].2) and (list[1].3 or list[1].4)
* @param andConditionList
*/
public void setAndConditionList(List<DemoDetailQuery> andConditionList){
this.andConditionList = andConditionList;
}
}
\ No newline at end of file
package com.mortals.xhx.module.demo.detail.service;
import com.mortals.framework.service.ICRUDService;
import com.mortals.xhx.module.demo.detail.model.DemoDetailEntity;
/**
* DemoDetailService
*
* service接口
*
* @author zxfei
* @date 2021-10-03
*/
public interface DemoDetailService extends ICRUDService<DemoDetailEntity,Long>{
}
\ No newline at end of file
package com.mortals.xhx.module.demo.detail.service.impl;
import org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.xhx.module.demo.detail.dao.DemoDetailDao;
import com.mortals.xhx.module.demo.detail.model.DemoDetailEntity;
import com.mortals.xhx.module.demo.detail.service.DemoDetailService;
/**
* DemoDetailService
* service实现
*
* @author zxfei
* @date 2021-10-03
*/
@Service("demoDetailService")
public class DemoDetailServiceImpl extends AbstractCRUDServiceImpl<DemoDetailDao, DemoDetailEntity, Long> implements DemoDetailService {
}
\ No newline at end of file
package com.mortals.xhx.module.demo.detail.web;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mortals.framework.model.Context;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.mortals.framework.web.BaseCRUDJsonMappingController;
import com.mortals.framework.common.IBaseEnum;
import com.mortals.framework.common.code.YesNo;
import com.mortals.xhx.module.demo.detail.model.DemoDetailEntity;
import com.mortals.xhx.module.demo.detail.service.DemoDetailService;
import java.util.Map;
/**
* DemoDetailController
*
* 控制器
*
* @author zxfei
* @date 2021-10-03
*/
@RestController
@RequestMapping("demo/detail")
public class DemoDetailController extends BaseCRUDJsonMappingController<DemoDetailService,DemoDetailForm,DemoDetailEntity,Long> {
public DemoDetailController(){
super.setFormClass(DemoDetailForm.class);
super.setModuleDesc( "");
}
@Override
protected void init(HttpServletRequest request, HttpServletResponse response, DemoDetailForm form, Map<String, Object> model, Context context) {
this.addDict(model, "status", IBaseEnum.getEnumMap(YesNo.class));
super.init(request, response, form, model, context);
}
}
\ No newline at end of file
package com.mortals.xhx.module.demo.detail.web;
import com.mortals.framework.web.BaseCRUDFormLong;
import com.mortals.xhx.module.demo.detail.model.DemoDetailEntity;
import com.mortals.xhx.module.demo.detail.model.DemoDetailQuery;
/**
* DemoDetail
*
* Form
*
* @author zxfei
* @date 2021-10-03
*/
public class DemoDetailForm extends BaseCRUDFormLong<DemoDetailEntity> {
private DemoDetailEntity entity = new DemoDetailEntity();
private DemoDetailQuery query = new DemoDetailQuery();
public DemoDetailForm(){
}
@Override
public DemoDetailEntity getEntity() {
return entity;
}
public void setDemoDetail(DemoDetailEntity entity) {
this.entity = entity;
}
@Override
public DemoDetailQuery getQuery() {
return query;
}
public void setQuery(DemoDetailQuery query) {
this.query = query;
}
}
\ No newline at end of file
package com.mortals.xhx.daemon.demo; package com.mortals.xhx.module.demo.model;
import java.util.List;
import com.mortals.framework.model.BaseEntityStr; import com.mortals.framework.model.BaseEntityStr;
import com.mortals.xhx.module.demo.detail.model.DemoDetailEntity;
/** /**
* 实体对象 * 测试实体对象
* *
* @author zxfei * @author zxfei
* @date 2021-09-30 * @date 2021-10-03
*/ */
public class DemoEntity extends BaseEntityStr { public class DemoEntity extends BaseEntityStr {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** /**
* *
*/ */
private String fieldOne; private String fieldOne;
/** /**
* *
*/ */
private Long fieldTwo; private Long fieldTwo;
/**
* 信息
*/
private List<DemoDetailEntity> demoDetailList;
public DemoEntity(){} public DemoEntity(){}
/** /**
* 获取 * 获取
* @return String * @return String
*/ */
public String getFieldOne(){ public String getFieldOne(){
return fieldOne; return fieldOne;
} }
/** /**
* 设置 * 设置
* @param fieldOne * @param fieldOne
*/ */
public void setFieldOne(String fieldOne){ public void setFieldOne(String fieldOne){
this.fieldOne = fieldOne; this.fieldOne = fieldOne;
} }
/** /**
* 获取 * 获取
* @return Long * @return Long
*/ */
public Long getFieldTwo(){ public Long getFieldTwo(){
return fieldTwo; return fieldTwo;
} }
/** /**
* 设置 * 设置
* @param fieldTwo * @param fieldTwo
*/ */
public void setFieldTwo(Long fieldTwo){ public void setFieldTwo(Long fieldTwo){
this.fieldTwo = fieldTwo; this.fieldTwo = fieldTwo;
} }
public List<DemoDetailEntity> getDemoDetailList(){
return demoDetailList;
}
public void setDemoDetailList(List<DemoDetailEntity> demoDetailList){
this.demoDetailList = demoDetailList;
}
@Override @Override
public int hashCode() { public int hashCode() {
return this.getId().hashCode(); return this.getId().hashCode();
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
...@@ -63,7 +76,7 @@ public class DemoEntity extends BaseEntityStr { ...@@ -63,7 +76,7 @@ public class DemoEntity extends BaseEntityStr {
if (obj instanceof DemoEntity) { if (obj instanceof DemoEntity) {
DemoEntity tmp = (DemoEntity) obj; DemoEntity tmp = (DemoEntity) obj;
if (this.getId() == tmp.getId()) { if (this.getId() == tmp.getId()) {
return true; return true;
} }
} }
return false; return false;
...@@ -77,7 +90,7 @@ public class DemoEntity extends BaseEntityStr { ...@@ -77,7 +90,7 @@ public class DemoEntity extends BaseEntityStr {
} }
public void initAttrValue(){ public void initAttrValue(){
this.fieldOne = null; this.fieldOne = null;
this.fieldTwo = null; this.fieldTwo = null;
} }
} }
\ No newline at end of file
package com.mortals.xhx.daemon.demo; package com.mortals.xhx.module.demo.model;
import java.util.List; import java.util.List;
/** /**
* 查询对象 * 测试查询对象
* *
* @author zxfei * @author zxfei
* @date 2021-09-30 * @date 2021-10-03
*/ */
public class DemoQuery extends DemoEntity { public class DemoQuery extends DemoEntity {
/** */ /** */
private List<String> idList; private List<String> idList;
...@@ -53,344 +53,344 @@ public class DemoQuery extends DemoEntity { ...@@ -53,344 +53,344 @@ public class DemoQuery extends DemoEntity {
public DemoQuery(){} public DemoQuery(){}
/** /**
* 获取 * 获取
* @return idList * @return idList
*/ */
public List<String> getIdList(){ public List<String> getIdList(){
return this.idList; return this.idList;
} }
/** /**
* 设置 * 设置
* @param idList * @param idList
*/ */
public void setIdList(List<String> idList){ public void setIdList(List<String> idList){
this.idList = idList; this.idList = idList;
} }
/** /**
* 获取 * 获取
* @return fieldOneList * @return fieldOneList
*/ */
public List<String> getFieldOneList(){ public List<String> getFieldOneList(){
return this.fieldOneList; return this.fieldOneList;
} }
/** /**
* 设置 * 设置
* @param fieldOneList * @param fieldOneList
*/ */
public void setFieldOneList(List<String> fieldOneList){ public void setFieldOneList(List<String> fieldOneList){
this.fieldOneList = fieldOneList; this.fieldOneList = fieldOneList;
} }
/** /**
* 获取 开始 * 获取 开始
* @return fieldTwoStart * @return fieldTwoStart
*/ */
public Long getFieldTwoStart(){ public Long getFieldTwoStart(){
return this.fieldTwoStart; return this.fieldTwoStart;
} }
/** /**
* 设置 开始 * 设置 开始
* @param fieldTwoStart * @param fieldTwoStart
*/ */
public void setFieldTwoStart(Long fieldTwoStart){ public void setFieldTwoStart(Long fieldTwoStart){
this.fieldTwoStart = fieldTwoStart; this.fieldTwoStart = fieldTwoStart;
} }
/** /**
* 获取 结束 * 获取 结束
* @return $fieldTwoEnd * @return $fieldTwoEnd
*/ */
public Long getFieldTwoEnd(){ public Long getFieldTwoEnd(){
return this.fieldTwoEnd; return this.fieldTwoEnd;
} }
/** /**
* 设置 结束 * 设置 结束
* @param fieldTwoEnd * @param fieldTwoEnd
*/ */
public void setFieldTwoEnd(Long fieldTwoEnd){ public void setFieldTwoEnd(Long fieldTwoEnd){
this.fieldTwoEnd = fieldTwoEnd; this.fieldTwoEnd = fieldTwoEnd;
} }
/** /**
* 获取 增加 * 获取 增加
* @return fieldTwoIncrement * @return fieldTwoIncrement
*/ */
public Long getFieldTwoIncrement(){ public Long getFieldTwoIncrement(){
return this.fieldTwoIncrement; return this.fieldTwoIncrement;
} }
/** /**
* 设置 增加 * 设置 增加
* @param fieldTwoIncrement * @param fieldTwoIncrement
*/ */
public void setFieldTwoIncrement(Long fieldTwoIncrement){ public void setFieldTwoIncrement(Long fieldTwoIncrement){
this.fieldTwoIncrement = fieldTwoIncrement; this.fieldTwoIncrement = fieldTwoIncrement;
} }
/** /**
* 获取 * 获取
* @return fieldTwoList * @return fieldTwoList
*/ */
public List<Long> getFieldTwoList(){ public List<Long> getFieldTwoList(){
return this.fieldTwoList; return this.fieldTwoList;
} }
/** /**
* 设置 * 设置
* @param fieldTwoList * @param fieldTwoList
*/ */
public void setFieldTwoList(List<Long> fieldTwoList){ public void setFieldTwoList(List<Long> fieldTwoList){
this.fieldTwoList = fieldTwoList; this.fieldTwoList = fieldTwoList;
} }
/** /**
* 获取 开始 * 获取 开始
* @return updateTimeStart * @return updateTimeStart
*/ */
public String getUpdateTimeStart(){ public String getUpdateTimeStart(){
return this.updateTimeStart; return this.updateTimeStart;
} }
/** /**
* 设置 开始 * 设置 开始
* @param updateTimeStart * @param updateTimeStart
*/ */
public void setUpdateTimeStart(String updateTimeStart){ public void setUpdateTimeStart(String updateTimeStart){
this.updateTimeStart = updateTimeStart; this.updateTimeStart = updateTimeStart;
} }
/** /**
* 获取 结束 * 获取 结束
* @return updateTimeEnd * @return updateTimeEnd
*/ */
public String getUpdateTimeEnd(){ public String getUpdateTimeEnd(){
return this.updateTimeEnd; return this.updateTimeEnd;
} }
/** /**
* 设置 结束 * 设置 结束
* @param updateTimeEnd * @param updateTimeEnd
*/ */
public void setUpdateTimeEnd(String updateTimeEnd){ public void setUpdateTimeEnd(String updateTimeEnd){
this.updateTimeEnd = updateTimeEnd; this.updateTimeEnd = updateTimeEnd;
} }
/** /**
* 获取 * 获取
* @return updateUserList * @return updateUserList
*/ */
public List<String> getUpdateUserList(){ public List<String> getUpdateUserList(){
return this.updateUserList; return this.updateUserList;
} }
/** /**
* 设置 * 设置
* @param updateUserList * @param updateUserList
*/ */
public void setUpdateUserList(List<String> updateUserList){ public void setUpdateUserList(List<String> updateUserList){
this.updateUserList = updateUserList; this.updateUserList = updateUserList;
} }
/** /**
* 获取 开始 * 获取 开始
* @return createTimeStart * @return createTimeStart
*/ */
public String getCreateTimeStart(){ public String getCreateTimeStart(){
return this.createTimeStart; return this.createTimeStart;
} }
/** /**
* 设置 开始 * 设置 开始
* @param createTimeStart * @param createTimeStart
*/ */
public void setCreateTimeStart(String createTimeStart){ public void setCreateTimeStart(String createTimeStart){
this.createTimeStart = createTimeStart; this.createTimeStart = createTimeStart;
} }
/** /**
* 获取 结束 * 获取 结束
* @return createTimeEnd * @return createTimeEnd
*/ */
public String getCreateTimeEnd(){ public String getCreateTimeEnd(){
return this.createTimeEnd; return this.createTimeEnd;
} }
/** /**
* 设置 结束 * 设置 结束
* @param createTimeEnd * @param createTimeEnd
*/ */
public void setCreateTimeEnd(String createTimeEnd){ public void setCreateTimeEnd(String createTimeEnd){
this.createTimeEnd = createTimeEnd; this.createTimeEnd = createTimeEnd;
} }
/** /**
* 获取 * 获取
* @return createUserList * @return createUserList
*/ */
public List<String> getCreateUserList(){ public List<String> getCreateUserList(){
return this.createUserList; return this.createUserList;
} }
/** /**
* 设置 * 设置
* @param createUserList * @param createUserList
*/ */
public void setCreateUserList(List<String> createUserList){ public void setCreateUserList(List<String> createUserList){
this.createUserList = createUserList; this.createUserList = createUserList;
} }
/** /**
* 设置 * 设置
* @param id * @param id
*/ */
public DemoQuery id(String id){ public DemoQuery id(String id){
setId(id); setId(id);
return this; return this;
} }
/** /**
* 设置 * 设置
* @param idList * @param idList
*/ */
public DemoQuery idList(List<String> idList){ public DemoQuery idList(List<String> idList){
this.idList = idList; this.idList = idList;
return this; return this;
} }
/** /**
* 设置 * 设置
* @param fieldOne * @param fieldOne
*/ */
public DemoQuery fieldOne(String fieldOne){ public DemoQuery fieldOne(String fieldOne){
setFieldOne(fieldOne); setFieldOne(fieldOne);
return this; return this;
} }
/** /**
* 设置 * 设置
* @param fieldOneList * @param fieldOneList
*/ */
public DemoQuery fieldOneList(List<String> fieldOneList){ public DemoQuery fieldOneList(List<String> fieldOneList){
this.fieldOneList = fieldOneList; this.fieldOneList = fieldOneList;
return this; return this;
} }
/** /**
* 设置 * 设置
* @param fieldTwo * @param fieldTwo
*/ */
public DemoQuery fieldTwo(Long fieldTwo){ public DemoQuery fieldTwo(Long fieldTwo){
setFieldTwo(fieldTwo); setFieldTwo(fieldTwo);
return this; return this;
} }
/** /**
* 设置 开始 * 设置 开始
* @param fieldTwoStart * @param fieldTwoStart
*/ */
public DemoQuery fieldTwoStart(Long fieldTwoStart){ public DemoQuery fieldTwoStart(Long fieldTwoStart){
this.fieldTwoStart = fieldTwoStart; this.fieldTwoStart = fieldTwoStart;
return this; return this;
} }
/** /**
* 设置 结束 * 设置 结束
* @param fieldTwoEnd * @param fieldTwoEnd
*/ */
public DemoQuery fieldTwoEnd(Long fieldTwoEnd){ public DemoQuery fieldTwoEnd(Long fieldTwoEnd){
this.fieldTwoEnd = fieldTwoEnd; this.fieldTwoEnd = fieldTwoEnd;
return this; return this;
} }
/** /**
* 设置 增加 * 设置 增加
* @param fieldTwoIncrement * @param fieldTwoIncrement
*/ */
public DemoQuery fieldTwoIncrement(Long fieldTwoIncrement){ public DemoQuery fieldTwoIncrement(Long fieldTwoIncrement){
this.fieldTwoIncrement = fieldTwoIncrement; this.fieldTwoIncrement = fieldTwoIncrement;
return this; return this;
} }
/** /**
* 设置 * 设置
* @param fieldTwoList * @param fieldTwoList
*/ */
public DemoQuery fieldTwoList(List<Long> fieldTwoList){ public DemoQuery fieldTwoList(List<Long> fieldTwoList){
this.fieldTwoList = fieldTwoList; this.fieldTwoList = fieldTwoList;
return this; return this;
} }
/** /**
* 设置 * 设置
* @param updateUser * @param updateUser
*/ */
public DemoQuery updateUser(String updateUser){ public DemoQuery updateUser(String updateUser){
setUpdateUser(updateUser); setUpdateUser(updateUser);
return this; return this;
} }
/** /**
* 设置 * 设置
* @param updateUserList * @param updateUserList
*/ */
public DemoQuery updateUserList(List<String> updateUserList){ public DemoQuery updateUserList(List<String> updateUserList){
this.updateUserList = updateUserList; this.updateUserList = updateUserList;
return this; return this;
} }
/** /**
* 设置 * 设置
* @param createUser * @param createUser
*/ */
public DemoQuery createUser(String createUser){ public DemoQuery createUser(String createUser){
setCreateUser(createUser); setCreateUser(createUser);
return this; return this;
} }
/** /**
* 设置 * 设置
* @param createUserList * @param createUserList
*/ */
public DemoQuery createUserList(List<String> createUserList){ public DemoQuery createUserList(List<String> createUserList){
this.createUserList = createUserList; this.createUserList = createUserList;
return this; return this;
} }
/** /**
* 获取 OR条件集合,列表项之间是OR,项内容之间是AND,如:(list[0].1 and list[0].2) or (list[1].3 and list[1].4) * 获取 OR条件集合,列表项之间是OR,项内容之间是AND,如:(list[0].1 and list[0].2) or (list[1].3 and list[1].4)
* @return orConditionList * @return orConditionList
*/ */
public List<DemoQuery> getOrConditionList(){ public List<DemoQuery> getOrConditionList(){
return this.orConditionList; return this.orConditionList;
} }
/** /**
* 设置 OR条件集合,列表项之间是OR,项内容之间是AND,如:(list[0].1 and list[0].2) or (list[1].3 and list[1].4) * 设置 OR条件集合,列表项之间是OR,项内容之间是AND,如:(list[0].1 and list[0].2) or (list[1].3 and list[1].4)
* @param orConditionList * @param orConditionList
*/ */
public void setOrConditionList(List<DemoQuery> orConditionList){ public void setOrConditionList(List<DemoQuery> orConditionList){
this.orConditionList = orConditionList; this.orConditionList = orConditionList;
} }
/** /**
* 获取 AND条件集合,列表项之间是AND,项内容之间是OR,如:(list[0].1 or list[0].2) and (list[1].3 or list[1].4) * 获取 AND条件集合,列表项之间是AND,项内容之间是OR,如:(list[0].1 or list[0].2) and (list[1].3 or list[1].4)
* @return andConditionList * @return andConditionList
*/ */
public List<DemoQuery> getAndConditionList(){ public List<DemoQuery> getAndConditionList(){
return this.andConditionList; return this.andConditionList;
} }
/** /**
* 设置 AND条件集合,列表项之间是AND,项内容之间是OR,如:(list[0].1 or list[0].2) and (list[1].3 or list[1].4) * 设置 AND条件集合,列表项之间是AND,项内容之间是OR,如:(list[0].1 or list[0].2) and (list[1].3 or list[1].4)
* @param andConditionList * @param andConditionList
*/ */
public void setAndConditionList(List<DemoQuery> andConditionList){ public void setAndConditionList(List<DemoQuery> andConditionList){
this.andConditionList = andConditionList; this.andConditionList = andConditionList;
} }
......
package com.mortals.xhx.module.demo.service;
import com.mortals.framework.service.ICRUDService;
import com.mortals.xhx.module.demo.model.DemoEntity;
/**
* DemoService
*
* 测试 service接口
*
* @author zxfei
* @date 2021-10-03
*/
public interface DemoService extends ICRUDService<DemoEntity,String>{
}
\ No newline at end of file
package com.mortals.xhx.module.demo.service.impl;
import org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.xhx.module.demo.dao.DemoDao;
import com.mortals.xhx.module.demo.model.DemoEntity;
import com.mortals.xhx.module.demo.service.DemoService;
/**
* DemoService
* 测试 service实现
*
* @author zxfei
* @date 2021-10-03
*/
@Service("demoService")
public class DemoServiceImpl extends AbstractCRUDServiceImpl<DemoDao, DemoEntity, String> implements DemoService {
}
\ No newline at end of file
package com.mortals.xhx.module.demo.web;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mortals.framework.model.Context;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.mortals.framework.web.BaseCRUDJsonMappingController;
import com.mortals.framework.common.IBaseEnum;
import com.mortals.framework.common.code.YesNo;
import com.mortals.xhx.module.demo.model.DemoEntity;
import com.mortals.xhx.module.demo.service.DemoService;
import java.util.Map;
/**
* DemoController
*
* 测试 控制器
*
* @author zxfei
* @date 2021-10-03
*/
@RestController
@RequestMapping("demo")
public class DemoController extends BaseCRUDJsonMappingController<DemoService,DemoForm,DemoEntity,String> {
public DemoController(){
super.setFormClass(DemoForm.class);
super.setModuleDesc( "测试");
}
@Override
protected void init(HttpServletRequest request, HttpServletResponse response, DemoForm form, Map<String, Object> model, Context context) {
this.addDict(model, "status", IBaseEnum.getEnumMap(YesNo.class));
super.init(request, response, form, model, context);
}
}
\ No newline at end of file
package com.mortals.xhx.module.demo.web;
import com.mortals.framework.web.BaseCRUDFormStr;
import com.mortals.xhx.module.demo.model.DemoEntity;
import com.mortals.xhx.module.demo.model.DemoQuery;
/**
* Demo
*
* 测试 Form
*
* @author zxfei
* @date 2021-10-03
*/
public class DemoForm extends BaseCRUDFormStr<DemoEntity> {
private DemoEntity entity = new DemoEntity();
private DemoQuery query = new DemoQuery();
public DemoForm(){
}
@Override
public DemoEntity getEntity() {
return entity;
}
public void setDemo(DemoEntity entity) {
this.entity = entity;
}
@Override
public DemoQuery getQuery() {
return query;
}
public void setQuery(DemoQuery query) {
this.query = query;
}
}
\ No newline at end of file
package com.mortals.xhx.module.matter.dao.ibatis; package com.mortals.xhx.module.matter.dao.ibatis;
import com.mortals.framework.model.TableParam; import com.mortals.framework.dao.ibatis.BaseCRUDDaoMybatis;
import com.mortals.framework.model.TableStrategy;
import com.mortals.framework.util.DateUtils;
import com.mortals.framework.util.StringUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.stereotype.Repository;
import com.mortals.xhx.module.matter.dao.MatterDatumDao; import com.mortals.xhx.module.matter.dao.MatterDatumDao;
import com.mortals.xhx.module.matter.model.MatterDatumEntity; import com.mortals.xhx.module.matter.model.MatterDatumEntity;
import java.util.Date; import org.springframework.stereotype.Repository;
import com.mortals.framework.dao.ibatis.SubmeterDaoImpl;
import com.mortals.xhx.module.matter.model.MatterDatumQuery;
/** /**
* 事项申请材料DaoImpl DAO接口 * 事项申请材料DaoImpl DAO接口
* *
...@@ -18,30 +11,8 @@ import com.mortals.xhx.module.matter.model.MatterDatumQuery; ...@@ -18,30 +11,8 @@ import com.mortals.xhx.module.matter.model.MatterDatumQuery;
* @date 2021-09-30 * @date 2021-09-30
*/ */
@Repository("matterDatumDao") @Repository("matterDatumDao")
public class MatterDatumDaoImpl extends SubmeterDaoImpl<MatterDatumEntity,Long> implements MatterDatumDao { public class MatterDatumDaoImpl extends BaseCRUDDaoMybatis<MatterDatumEntity,Long> implements MatterDatumDao {
@Override
protected TableStrategy getTableStrategy() {
return new TableStrategy("mortals_xhx_matter_datum_${unionTime}", TableStrategy.STRATEGY_BY_MONTH, 3);
}
@Override
public TableParam getTableParam(MatterDatumEntity makeTableNameOfentity) {
TableParam tableParam = new TableParam();
if (!ObjectUtils.isEmpty(makeTableNameOfentity.getCreateTime())) {
tableParam.unionTime = makeTableNameOfentity.getCreateTime();
} else if (makeTableNameOfentity instanceof MatterDatumQuery) {
MatterDatumQuery MatterDatumQuery = (MatterDatumQuery) makeTableNameOfentity;
if (StringUtils.isNotEmpty(MatterDatumQuery.getCreateTimeStart())) {
tableParam.unionTime = DateUtils.StrToDate(MatterDatumQuery.getCreateTimeStart());
} else if (StringUtils.isNotEmpty(MatterDatumQuery.getCreateTimeEnd())) {
tableParam.unionTime = DateUtils.StrToDate(MatterDatumQuery.getCreateTimeEnd());
}
}
if (ObjectUtils.isEmpty(tableParam.unionTime)) {
tableParam.unionTime = new Date();
}
return tableParam;
}
} }
\ No newline at end of file
...@@ -2,8 +2,10 @@ ...@@ -2,8 +2,10 @@
gen: gen:
# 作者 # 作者
author: zxfei author: zxfei
# 默认生成包路径 module 需改成自己的模块名称 如 system monitor tool # 默认生成包路径
packageName: com.mortals.xhx.module packageName: com.mortals.xhx
# module名称
moduleName: module
# 自动去除表前缀,默认是false # 自动去除表前缀,默认是false
autoRemovePre: true autoRemovePre: true
# 表前缀(生成类名不会包含表前缀,多个用逗号分隔) # 表前缀(生成类名不会包含表前缀,多个用逗号分隔)
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
SELECT SELECT
column_name as columnName, column_name as columnName,
column_default as defaultValue, column_default as defaultValue,
( CASE WHEN ( is_nullable = 'no' <![CDATA[ && ]]> column_key != 'PRI' ) THEN '1' ELSE NULL END ) AS isRequired, ( CASE WHEN ( is_nullable = 'no' <![CDATA[ && ]]> column_key != 'PRI' ) THEN '1' ELSE '0' END ) AS isRequired,
( CASE WHEN column_key = 'PRI' THEN '1' ELSE '0' END ) AS isPrimaryKey, ( CASE WHEN column_key = 'PRI' THEN '1' ELSE '0' END ) AS isPrimaryKey,
ordinal_position AS sort, ordinal_position AS sort,
column_comment AS columnComment, column_comment AS columnComment,
......
package ${packageName}.${businessName}.dao; package ${packageName}.dao;
import com.mortals.framework.dao.ICRUDDao; import com.mortals.framework.dao.ICRUDDao;
import ${packageName}.${businessName}.model.${ClassName}Entity; import ${packageName}.model.${ClassName}Entity;
/** /**
* ${functionName}Dao * ${functionName}Dao
...@@ -15,6 +15,6 @@ import ${packageName}.${businessName}.model.${ClassName}Entity; ...@@ -15,6 +15,6 @@ import ${packageName}.${businessName}.model.${ClassName}Entity;
<#else> <#else>
<#assign Dao = "ICRUDDao"> <#assign Dao = "ICRUDDao">
</#if> </#if>
public interface ${ClassName}Dao extends ${Dao}<${ClassName}Entity,Long>{ public interface ${ClassName}Dao extends ${Dao}<${ClassName}Entity,${pkColumn.javaType}>{
} }
package ${packageName}.${businessName}.dao.ibatis; package ${packageName}.dao.ibatis;
import com.mortals.framework.model.TableParam;
import com.mortals.framework.model.TableStrategy;
import com.mortals.framework.util.DateUtils;
import com.mortals.framework.util.StringUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import ${packageName}.${businessName}.dao.${ClassName}Dao; import ${packageName}.dao.${ClassName}Dao;
import ${packageName}.${businessName}.model.${ClassName}Entity; import ${packageName}.model.${ClassName}Entity;
import java.util.Date; import java.util.Date;
<#if table.dividedTableType==0 > <#if table.dividedTableType==0 >
import com.mortals.framework.dao.ibatis.BaseCRUDDaoMybatis; import com.mortals.framework.dao.ibatis.BaseCRUDDaoMybatis;
<#else> <#else>
import com.mortals.framework.model.TableParam;
import com.mortals.framework.model.TableStrategy;
import com.mortals.framework.util.DateUtils;
import com.mortals.framework.util.StringUtils;
import org.springframework.util.ObjectUtils;
import com.mortals.framework.dao.ibatis.SubmeterDaoImpl; import com.mortals.framework.dao.ibatis.SubmeterDaoImpl;
import ${packageName}.${businessName}.model.${ClassName}Query; import ${packageName}.model.${ClassName}Query;
</#if> </#if>
<#if table.dividedTableType==1 > <#if table.dividedTableType==1 >
<#assign TableStrategy = "TableStrategy.STRATEGY_BY_DAY"> <#assign TableStrategy = "TableStrategy.STRATEGY_BY_DAY">
...@@ -33,7 +34,7 @@ import ${packageName}.${businessName}.model.${ClassName}Query; ...@@ -33,7 +34,7 @@ import ${packageName}.${businessName}.model.${ClassName}Query;
*/ */
@Repository("${ClassName?uncap_first}Dao") @Repository("${ClassName?uncap_first}Dao")
<#if table.dividedTableType!=0 > <#if table.dividedTableType!=0 >
public class ${ClassName}DaoImpl extends SubmeterDaoImpl<${ClassName}Entity,Long> implements ${ClassName}Dao { public class ${ClassName}DaoImpl extends SubmeterDaoImpl<${ClassName}Entity,${pkColumn.javaType}> implements ${ClassName}Dao {
@Override @Override
protected TableStrategy getTableStrategy() { protected TableStrategy getTableStrategy() {
...@@ -59,7 +60,7 @@ public class ${ClassName}DaoImpl extends SubmeterDaoImpl<${ClassName}Entity,Long ...@@ -59,7 +60,7 @@ public class ${ClassName}DaoImpl extends SubmeterDaoImpl<${ClassName}Entity,Long
return tableParam; return tableParam;
} }
<#else> <#else>
public class ${ClassName}DaoImpl extends BaseCRUDDaoMybatis<${ClassName}Entity,Long> implements ${ClassName}Dao { public class ${ClassName}DaoImpl extends BaseCRUDDaoMybatis<${ClassName}Entity,${pkColumn.javaType}> implements ${ClassName}Dao {
</#if> </#if>
......
-- ----------------------------
-- ${functionName}表
-- ----------------------------
DROP TABLE IF EXISTS `${tableName}`;
CREATE TABLE ${tableName}(
<#list columns as column>
<#if column.isIncrement==1 >
<#assign autoInc>auto_increment</#assign>
<#else>
<#assign autoInc></#assign>
</#if>
<#if column.isRequired==1 >
<#assign Required>NOT NULL</#assign>
<#else>
<#assign Required></#assign>
</#if>
<#if column.isRequired==1 >
<#assign Required>NOT NULL</#assign>
<#else>
<#assign Required></#assign>
</#if>
<#if column.javaType=="String" >
<#assign Type>CHARACTER SET utf8 COLLATE utf8_general_ci</#assign>
<#else>
<#assign Type></#assign>
</#if>
<#if column.defaultValue??>
<#assign Default>DEFAULT '${column.defaultValue}'</#assign>
<#else>
<#assign Default>DEFAULT NULL</#assign>
</#if>
`${column.columnName}` ${column.columnType} ${Required} ${Default} ${Type} ${autoInc} COMMENT '${column.columnComment}',
</#list>
PRIMARY KEY (`${pkColumn.columnName}`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='${functionName}';
package ${packageName}.${businessName}.model; package ${packageName}.model;
<#if table.tplCategory=="crud" > <#if table.tplCategory=="crud" >
<#--判断主键类型,设置继承实体类 --> <#--判断主键类型,设置继承实体类 -->
<#if pkColumn??&&pkColumn.javaType=="String" > <#if pkColumn??&&pkColumn.javaType=="String" >
...@@ -13,15 +13,27 @@ package ${packageName}.${businessName}.model; ...@@ -13,15 +13,27 @@ package ${packageName}.${businessName}.model;
<#elseif table.tplCategory=="tree"> <#elseif table.tplCategory=="tree">
<#assign Entity = "TreeEntity"> <#assign Entity = "TreeEntity">
<#elseif table.tplCategory=="sub"> <#elseif table.tplCategory=="sub">
<#assign Entity = "BaseEntityLong"> <#--判断主键类型,设置继承实体类 -->
<#if pkColumn??&&pkColumn.javaType=="String" >
<#assign Entity = "BaseEntityStr">
<#elseif pkColumn??&&pkColumn.javaType=="Integer">
<#assign Entity = "BaseEntityInt">
<#elseif pkColumn??&&pkColumn.javaType=="Long">
<#assign Entity = "BaseEntityLong">
<#else>
<#assign Entity = "BaseEntityLong">
</#if>
<#else> <#else>
<#assign Entity = "BaseEntityLong"> <#assign Entity = "BaseEntityLong">
</#if> </#if>
<#list importList as import> <#list importList as import>
import ${import}; import ${import};
</#list> </#list>
import java.util.List;
import com.mortals.framework.model.${Entity}; import com.mortals.framework.model.${Entity};
<#if table.tplCategory=="sub" >
import ${subPackageName}.model.${subClassName}Entity;
</#if>
/** /**
* ${functionName}实体对象 * ${functionName}实体对象
* *
...@@ -45,7 +57,7 @@ public class ${ClassName}Entity extends ${Entity} { ...@@ -45,7 +57,7 @@ public class ${ClassName}Entity extends ${Entity} {
/** /**
* ${table.subTable.functionName}信息 * ${table.subTable.functionName}信息
*/ */
private List<${subClassName}> ${subclassName}List; private List<${subClassName}Entity> ${subclassName}List;
</#if> </#if>
...@@ -77,15 +89,13 @@ public class ${ClassName}Entity extends ${Entity} { ...@@ -77,15 +89,13 @@ public class ${ClassName}Entity extends ${Entity} {
<#if subTable??> <#if subTable??>
public List<${subClassName}Entity> get${subClassName}List(){
public List<${subClassName}> get${subClassName}List(){
return ${subclassName}List; return ${subclassName}List;
} }
public void set${subClassName}List(List<${subClassName}> ${subclassName}List){ public void set${subClassName}List(List<${subClassName}Entity> ${subclassName}List){
this.${subclassName}List = ${subclassName}List; this.${subclassName}List = ${subclassName}List;
} }
</#if> </#if>
@Override @Override
......
package ${packageName}.${businessName}.model; package ${packageName}.model;
<#list importList as import> <#list importList as import>
import ${import}; import ${import};
</#list> </#list>
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
* ${functionName}查询对象 * ${functionName}查询对象
......
-- ----------------------------
-- 菜单 SQL
-- ----------------------------
INSERT INTO `mortals_xhx_menu` VALUES (null, '${tableComment}', '/${RequestMapping}/list', -1, 1, 1, 0, 0, NULL, NULL, NULL, 0, 0, 3, NULL, NULL, NULL);
-- ----------------------------
-- 资源路径 SQL
-- ----------------------------
INSERT INTO `mortals_xhx_resource` VALUES (null, '${functionName}-菜单管理-查看', '/${RequestMapping}/list,/${RequestMapping}/view', 3, 0, NULL, NULL, NULL, 0);
INSERT INTO `mortals_xhx_resource` VALUES (null, '${functionName}-菜单管理-维护', '/${RequestMapping}/add,/${RequestMapping}/edit,/${RequestMapping}/delete,/${RequestMapping}/save', 3, 0, NULL, NULL, NULL, 0);
-- ----------------------------
-- 参数 SQL
-- ----------------------------
<#list columns as column>
<#if column.dict??&&(column.columnType?contains("tinyint") ||column.htmlType==3||column.htmlType==5)>
<#list column.dict as dict>
INSERT INTO `mortals_xhx_param` VALUES (null, '${column.columnComment?remove_beginning("(")}', '${column.javaField}', NULL, '${dict.num}', '${dict.value}', 1, 4, 0, NULL, NULL, NULL, NULL);
</#list>
</#if>
</#list>
\ No newline at end of file
package ${packageName}.${businessName}.service; package ${packageName}.service;
<#if table.cacheServiceType==0 > <#if table.cacheServiceType==0 >
<#assign Service = "ICRUDService"> <#assign Service = "ICRUDService">
<#elseif table.cacheServiceType==1 > <#elseif table.cacheServiceType==1 >
...@@ -9,7 +9,7 @@ package ${packageName}.${businessName}.service; ...@@ -9,7 +9,7 @@ package ${packageName}.${businessName}.service;
<#assign Service = "ICRUDService"> <#assign Service = "ICRUDService">
</#if> </#if>
import com.mortals.framework.service.${Service}; import com.mortals.framework.service.${Service};
import ${packageName}.${businessName}.model.${ClassName}Entity; import ${packageName}.model.${ClassName}Entity;
/** /**
* ${ClassName}Service * ${ClassName}Service
...@@ -19,6 +19,6 @@ import ${packageName}.${businessName}.model.${ClassName}Entity; ...@@ -19,6 +19,6 @@ import ${packageName}.${businessName}.model.${ClassName}Entity;
* @author ${author} * @author ${author}
* @date ${datetime} * @date ${datetime}
*/ */
public interface ${ClassName}Service extends ${Service}<${ClassName}Entity,Long>{ public interface ${ClassName}Service extends ${Service}<${ClassName}Entity,${pkColumn.javaType}>{
} }
\ No newline at end of file
package ${packageName}.${businessName}.service.impl; package ${packageName}.service.impl;
<#if table.cacheServiceType==0 > <#if table.cacheServiceType==0 >
<#assign Service = "AbstractCRUDServiceImpl"> <#assign Service = "AbstractCRUDServiceImpl">
<#elseif table.cacheServiceType==1 > <#elseif table.cacheServiceType==1 >
...@@ -10,9 +10,9 @@ package ${packageName}.${businessName}.service.impl; ...@@ -10,9 +10,9 @@ package ${packageName}.${businessName}.service.impl;
</#if> </#if>
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.${Service}; import com.mortals.framework.service.impl.${Service};
import ${packageName}.${businessName}.dao.${ClassName}Dao; import ${packageName}.dao.${ClassName}Dao;
import ${packageName}.${businessName}.model.${ClassName}Entity; import ${packageName}.model.${ClassName}Entity;
import ${packageName}.${businessName}.service.${ClassName}Service; import ${packageName}.service.${ClassName}Service;
/** /**
* ${ClassName}Service * ${ClassName}Service
...@@ -22,6 +22,6 @@ import ${packageName}.${businessName}.service.${ClassName}Service; ...@@ -22,6 +22,6 @@ import ${packageName}.${businessName}.service.${ClassName}Service;
* @date ${datetime} * @date ${datetime}
*/ */
@Service("${ClassName?uncap_first}Service") @Service("${ClassName?uncap_first}Service")
public class ${ClassName}ServiceImpl extends ${Service}<${ClassName}Dao, ${ClassName}Entity, Long> implements ${ClassName}Service { public class ${ClassName}ServiceImpl extends ${Service}<${ClassName}Dao, ${ClassName}Entity, ${pkColumn.javaType}> implements ${ClassName}Service {
} }
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"mybatis-3-mapper.dtd"> "mybatis-3-mapper.dtd">
<mapper namespace="${packageName}.${businessName}.dao.ibatis.${ClassName}DaoImpl"> <mapper namespace="${packageName}.dao.ibatis.${ClassName}DaoImpl">
<#if table.tplCategory=="sub" > <#if table.tplCategory=="sub" >
<#assign SubArray><collection property="columns" javaType="java.util.List" resultMap="${subClassName?uncap_first}Entity-Map" /></#assign> <#assign SubArray><collection property="${subclassName}List" column="${subTableFkName}" ofType="${subClassName}Entity-Map" javaType="ArrayList" select="get${subClassName}By${subTableFkClassName}">< /collection></#assign>
<#else> <#else>
<#assign SubArray></#assign> <#assign SubArray></#assign>
</#if> </#if>
<!-- 字段和属性映射 --> <!-- 字段和属性映射 -->
<resultMap type="${ClassName}Entity" id="${ClassName}Entity-Map"> <resultMap type="${ClassName}Entity" id="${ClassName}Entity-Map">
<#list columns as column> <#list columns as column>
<result property="${column.javaField}" column="${column.columnName}" /> <#if column.isPrimaryKey==1>
<id property="${column.javaField}" column="${column.columnName}" />
<#else >
<result property="${column.javaField}" column="${column.columnName}" />
</#if>
</#list> </#list>
${SubArray} ${SubArray}
</resultMap> </resultMap>
<#if table.tplCategory=="sub" > <#if table.tplCategory=="sub" >
<resultMap type="${subClassName?uncap_first}Entity" id="${subClassName?uncap_first}Entity-Map"> <resultMap type="${subClassName}Entity" id="${subClassName}Entity-Map">
<#list subTable.columns as column> <#list subTable.columns as column>
<result property="${column.javaField}" column="${column.columnName}" /> <result property="${column.javaField}" column="${column.columnName}" />
</#list> </#list>
...@@ -28,8 +29,18 @@ ...@@ -28,8 +29,18 @@
<#-- 判断是否分表,如果分表 则不指定表名 --> <#-- 判断是否分表,如果分表 则不指定表名 -->
<#if table.dividedTableType==0 > <#if table.dividedTableType==0 >
<#assign TempTable>${tableName}</#assign> <#assign TempTable>${tableName}</#assign>
<#if table.tplCategory=="sub" >
<#assign TempSubTable>${subTableName}</#assign>
<#else >
<#assign TempSubTable></#assign>
</#if>
<#else> <#else>
<#assign TempTable>`<#noparse>$</#noparse>{tableName}`</#assign> <#assign TempTable>`<#noparse>$</#noparse>{tableName}`</#assign>
<#if table.tplCategory=="sub" >
<#assign TempSubTable>`<#noparse>$</#noparse>{subTableName}`</#assign>
<#else >
<#assign TempSubTable></#assign>
</#if>
</#if> </#if>
<#if table.dividedTableType!=0> <#if table.dividedTableType!=0>
<update id="createTable" parameterType="paramDto"> <update id="createTable" parameterType="paramDto">
...@@ -72,6 +83,18 @@ ...@@ -72,6 +83,18 @@
</#list> </#list>
</trim> </trim>
</sql> </sql>
<#if table.tplCategory=="sub" >
<!-- 子表所有列 -->
<sql id="_columns_sub">
<trim suffixOverrides="," suffix="">
<#list subColumns as column>
<if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('${column.javaField}') or colPickMode == 1 and data.containsKey('${column.javaField}')))">
a.${column.columnName} as ${column.javaField},
</if>
</#list>
</trim>
</sql>
</#if>
<!-- 新增 区分主键自增加还是业务插入 --> <!-- 新增 区分主键自增加还是业务插入 -->
<insert id="insert" parameterType="${ClassName}Entity" <#if pkColumn.isIncrement?? && pkColumn.isIncrement==1> useGeneratedKeys="true" keyProperty="${pkColumn.javaField}"</#if>> <insert id="insert" parameterType="${ClassName}Entity" <#if pkColumn.isIncrement?? && pkColumn.isIncrement==1> useGeneratedKeys="true" keyProperty="${pkColumn.javaField}"</#if>>
insert into ${TempTable} insert into ${TempTable}
...@@ -194,6 +217,24 @@ ...@@ -194,6 +217,24 @@
</trim> </trim>
<include refid="_orderCols_"/> <include refid="_orderCols_"/>
</select> </select>
<#if table.tplCategory=="sub" >
<!-- 获取子列表 -->
<#if subTableFkType=="Integer" >
<#assign ParameterType>java.lang.Integer</#assign>
<#elseif subTableFkType=="Long">
<#assign ParameterType>java.lang.Long</#assign>
<#elseif subTableFkType=="String">
<#assign ParameterType>java.lang.String</#assign>
</#if>
<select id="get${subClassName}By${subTableFkClassName}" parameterType="${ParameterType}" resultMap="${subClassName}Entity-Map">
select <include refid="_columns_sub"/>
from ${TempSubTable} as a
<trim suffixOverrides="where" suffix="">
where a.${subTableFkName} = <#noparse>#</#noparse>{${subTableFkName}}
</trim>
</select>
</#if>
<!-- 获取 --> <!-- 获取 -->
<select id="getListCount" parameterType="paramDto" resultType="int"> <select id="getListCount" parameterType="paramDto" resultType="int">
select count(1) select count(1)
......
package ${packageName}.${businessName}.web; package ${packageName}.web;
<#if table.tplCategory=="crud" > <#if table.tplCategory=="crud" >
<#assign Controller = "BaseCRUDJsonMappingController"> <#assign Controller = "BaseCRUDJsonMappingController">
<#elseif table.tplCategory=="tree"> <#elseif table.tplCategory=="tree">
...@@ -6,16 +6,18 @@ package ${packageName}.${businessName}.web; ...@@ -6,16 +6,18 @@ package ${packageName}.${businessName}.web;
<#else> <#else>
<#assign Controller = "BaseCRUDJsonMappingController"> <#assign Controller = "BaseCRUDJsonMappingController">
</#if> </#if>
import com.mortals.xhx.base.system.param.service.ParamService;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.mortals.framework.model.Context;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import com.mortals.framework.web.${Controller}; import com.mortals.framework.web.${Controller};
import com.mortals.framework.common.IBaseEnum; import com.mortals.framework.common.IBaseEnum;
import com.mortals.framework.common.code.YesNo; import com.mortals.framework.common.code.YesNo;
import ${packageName}.${businessName}.model.${ClassName}Entity; import ${packageName}.model.${ClassName}Entity;
import ${packageName}.${businessName}.service.${ClassName}Service; import ${packageName}.service.${ClassName}Service;
import java.util.Map;
/** /**
* ${ClassName}Controller * ${ClassName}Controller
...@@ -27,16 +29,23 @@ import ${packageName}.${businessName}.service.${ClassName}Service; ...@@ -27,16 +29,23 @@ import ${packageName}.${businessName}.service.${ClassName}Service;
*/ */
@RestController @RestController
@RequestMapping("${RequestMapping}") @RequestMapping("${RequestMapping}")
public class ${ClassName}Controller extends ${Controller}<${ClassName}Service,${ClassName}Form,${ClassName}Entity,Long> { public class ${ClassName}Controller extends ${Controller}<${ClassName}Service,${ClassName}Form,${ClassName}Entity,${pkColumn.javaType}> {
@Autowired
private ParamService paramService;
public ${ClassName}Controller(){ public ${ClassName}Controller(){
super.setFormClass(${ClassName}Form.class);RequestMapping super.setFormClass(${ClassName}Form.class);
super.setModuleDesc( "${functionName}"); super.setModuleDesc( "${functionName}");
} }
@Override @Override
protected void init(HttpServletRequest request, HttpServletResponse response, ${ClassName}Form form, Map<String, Object> model, Context context) { protected void init(HttpServletRequest request, HttpServletResponse response, ${ClassName}Form form, Map<String, Object> model, Context context) {
this.addDict(model, "status", IBaseEnum.getEnumMap(YesNo.class)); <#list columns as column>
<#if column.columnType?contains("tinyint") ||column.htmlType==3||column.htmlType==5>
this.addDict(model, "${column.javaField}", paramService.getParamByFirstOrganize("${column.javaField}");
</#if>
</#list>
super.init(request, response, form, model, context); super.init(request, response, form, model, context);
} }
......
...@@ -11,8 +11,8 @@ package ${packageName}.${businessName}.web; ...@@ -11,8 +11,8 @@ package ${packageName}.${businessName}.web;
</#if> </#if>
import com.mortals.framework.web.${Form}; import com.mortals.framework.web.${Form};
import ${packageName}.${businessName}.model.${ClassName}Entity; import ${packageName}.model.${ClassName}Entity;
import ${packageName}.${businessName}.model.${ClassName}Query; import ${packageName}.model.${ClassName}Query;
/** /**
* ${ClassName} * ${ClassName}
......
<template>
<div class="page">
<LayoutTable :data='tableData' :config='tableConfig' />
</div>
</template>
<script>
import table from "@/assets/mixins/table";
export default {
components: {
},
mixins: [table],
created() {
},
methods: {
},
data() {
return {
config: {
search: [
<#list columns as column>
<#if column.isQuery == 1 &&column.htmlType==1>
{
name: "${column.javaField}",
type: "text",
label: "${column.columnComment}",
fuzzy: true
},
<#elseif column.isQuery == 1 &&column.htmlType==3>
{
name: "${column.javaField}",
type: "select",
label: "${column.columnComment}",
fuzzy: true
},
<#elseif column.isQuery == 1 &&column.htmlType==4>
{
name: "${column.javaField}",
type: "checkbox",
label: "${column.columnComment}",
fuzzy: true
},
<#elseif column.isQuery == 1 &&column.htmlType==6>
{
name: "${column.javaField}",
type: "date",
label: "${column.columnComment}",
fuzzy: true
},
</#if>
</#list>
],
columns: [
{type: "selection", width: 60},
<#list columns as column>
<#if column.javaType == "Long">
{label: "${column.columnComment}", prop: "${column.javaField}", formatter: this.formatterString},
</#if>
<#if column.javaType == "String"||column.javaType == "Integer">
{label: "${column.columnComment}", prop: "${column.javaField}"},
</#if>
<#if column.javaType == "Date">
{label: "${column.columnComment}", prop: "${column.javaField}", formatter: this.formatterDate},
</#if>
<#if column.javaType == "BigDecimal">
{label: "${column.columnComment}", prop: "${column.javaField}", formatter: this.formatterMoney},
</#if>
</#list>
<#if table.tplCategory=="sub">
{label: "${column.columnComment}", prop: "subColumns"},
</#if>
{
label: "操作",
width: 180,
formatter: row => {
return (
<div><el-button type="primary" icon="el-icon-edit" round size='mini' onClick={()=>{this.toEdit(row)}}>编辑</el-button></div>
);
}
}
]
}
};
}
};
</script>
\ No newline at end of file
?<template>
<layout-form>
<el-form :model="form" :loading="loading" :rules="rules" size='small' style="width:100%" label-width='120px' ref="form">
<el-row>
<#list columns as column>
<#if column.isPrimaryKey != 1>
<#if column.htmlType == 1 && !column.columnType?contains("tinyint")>
<Field label="${column.columnComment}" prop="${column.javaField}" v-model="form.${column.javaField}" placeholder="请输入${column.columnComment}"/>
<#elseif column.htmlType == 2>
<Field label="${column.columnComment}" prop="${column.javaField}" v-model="form.${column.javaField}" type="textarea" placeholder="请输入${column.columnComment}"/>
<#elseif column.htmlType == 3 ||column.columnType?contains("tinyint")>
<Field label="${column.columnComment}" prop="${column.javaField}" v-model="form.${column.javaField}" type="select" :enumData="dict.${column.javaField}" placeholder="请选择${column.columnComment}"/>
<#elseif column.htmlType == 4>
<Field label="${column.columnComment}" prop="${column.javaField}" v-model="form.${column.javaField}" type="checkbox" :enumData="dict.${column.javaField}" />
<#elseif column.htmlType == 5>
<Field label="${column.columnComment}" prop="${column.javaField}" v-model="form.${column.javaField}" type="radio" :enumData="dict.${column.javaField}" />
<#elseif column.htmlType == 6>
<Field label="${column.columnComment}" prop="${column.javaField}" v-model="form.${column.javaField}" type="date" :enumData="dict.${column.javaField}" />
<#elseif column.htmlType == 6>
<Field label="${column.columnComment}" prop="${column.javaField}" v-model="form.${column.javaField}" type="date" :enumData="dict.${column.javaField}" />
<#else >
<Field label="${column.columnComment}" prop="${column.javaField}" v-model="form.${column.javaField}" placeholder="请输入${column.columnComment}"/>
</#if>
</#if>
</#list>
</el-row>
<form-buttons @submit='submitForm'/>
</el-form>
</layout-form>
</template>
<script>
import form from "@/assets/mixins/form";
export default {
mixins: [form],
toString:[
<#list columns as column>
<#if column.columnType?contains("tinyint")>
"${column.javaField}",
</#if>
</#list>
],
data() {
return {
rules: {
<#list columns as column>
<#if column.javaType == "String" && column.isEdit==1>
${column.javaField}: [
{<#if column.isRequired==1>required: true,</#if> trigger: "blur" },
],
</#if>
<#if column.javaType == "Integer" && column.isEdit==1>
${column.javaField}: [
{<#if column.isRequired==1>required: true,</#if> type: 'integer',trigger: "blur" },
],
</#if>
<#if column.javaType == "BigDecimal" && column.isEdit==1>
${column.javaField}: [
{<#if column.isRequired==1>required: true,</#if> type: 'number',trigger: "blur" },
],
</#if>
<#if column.javaType == "Date" &&column.htmlType ==6 && column.isEdit==1>
${column.javaField}: [
{<#if column.isRequired==1>required: true,</#if> },
],
</#if>
</#list>
}
};
}
};
</script>
\ No newline at end of file
Markdown is supported
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