@@ -1,12 +1,11 @@ | |||
package com.taauav.tool.controller; | |||
import com.taauav.admin.controller.BaseController; | |||
import com.taauav.common.bean.Response; | |||
import com.taauav.tool.service.IGenTableService; | |||
import org.apache.ibatis.annotations.Param; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.GetMapping; | |||
import org.springframework.web.bind.annotation.PathVariable; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RestController; | |||
import org.springframework.web.bind.annotation.*; | |||
@RestController | |||
@RequestMapping("gen") | |||
@@ -14,10 +13,21 @@ public class GenController extends BaseController { | |||
@Autowired | |||
private IGenTableService genTableService; | |||
@Autowired | |||
private Response response; | |||
/** | |||
* 导入表结构(保存) | |||
*/ | |||
@GetMapping("/importTable") | |||
public Response importTableSave(String tables) | |||
{ | |||
genTableService.importGenTable(tables); | |||
return response.success("操作成功"); | |||
} | |||
@GetMapping("genCode") | |||
public void genCode(@PathVariable("tableName") String tableName) | |||
public Response genCode(@Param("tableName") String tableName) | |||
{ | |||
genTableService.generatorCode(tableName); | |||
genTableService.generatorCode(tableName); | |||
return response.success("操作成功"); | |||
} | |||
} |
@@ -92,6 +92,20 @@ public class GenTable extends Entity | |||
@TableField(exist = false) | |||
private Integer columnId; | |||
/** | |||
* 忽略该字段 | |||
*/ | |||
@TableField(exist = false) | |||
private boolean ignore; | |||
public boolean isIgnore() { | |||
return ignore; | |||
} | |||
public void setIgnore(boolean ignore) { | |||
this.ignore = ignore; | |||
} | |||
public Integer getTableId() | |||
{ | |||
return id; |
@@ -23,13 +23,6 @@ public interface GenTableColumnMapper extends BaseMapper<GenTableColumn> | |||
/** | |||
* 新增业务字段 | |||
* | |||
* @param genTableColumn 业务字段信息 | |||
* @return 结果 | |||
*/ | |||
public int insertGenTableColumn(GenTableColumn genTableColumn); | |||
/** | |||
* 修改业务字段 | |||
@@ -47,5 +40,4 @@ public interface GenTableColumnMapper extends BaseMapper<GenTableColumn> | |||
*/ | |||
public int deleteGenTableColumnByIds(Integer[] ids); | |||
GenTable selectGenTableById(Integer id); | |||
} |
@@ -34,49 +34,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||
order by ordinal_position | |||
</select> | |||
<insert id="insertGenTableColumn" parameterType="com.taauav.tool.entity.GenTableColumn" useGeneratedKeys="true" keyProperty="id"> | |||
insert into gen_table_column ( | |||
<if test="tableId != null and tableId != ''">table_id,</if> | |||
<if test="columnName != null and columnName != ''">column_name,</if> | |||
<if test="columnComment != null and columnComment != ''">column_comment,</if> | |||
<if test="columnType != null and columnType != ''">column_type,</if> | |||
<if test="javaType != null and javaType != ''">java_type,</if> | |||
<if test="javaField != null and javaField != ''">java_field,</if> | |||
<if test="isPk != null and isPk != ''">is_pk,</if> | |||
<if test="isIncrement != null and isIncrement != ''">is_increment,</if> | |||
<if test="isRequired != null and isRequired != ''">is_required,</if> | |||
<if test="isInsert != null and isInsert != ''">is_insert,</if> | |||
<if test="isEdit != null and isEdit != ''">is_edit,</if> | |||
<if test="isList != null and isList != ''">is_list,</if> | |||
<if test="isQuery != null and isQuery != ''">is_query,</if> | |||
<if test="queryType != null and queryType != ''">query_type,</if> | |||
<if test="htmlType != null and htmlType != ''">html_type,</if> | |||
<if test="dictType != null and dictType != ''">dict_type,</if> | |||
<if test="sort != null">sort,</if> | |||
<if test="createBy != null and createBy != ''">create_by,</if> | |||
create_time | |||
)values( | |||
<if test="tableId != null and tableId != ''">#{tableId},</if> | |||
<if test="columnName != null and columnName != ''">#{columnName},</if> | |||
<if test="columnComment != null and columnComment != ''">#{columnComment},</if> | |||
<if test="columnType != null and columnType != ''">#{columnType},</if> | |||
<if test="javaType != null and javaType != ''">#{javaType},</if> | |||
<if test="javaField != null and javaField != ''">#{javaField},</if> | |||
<if test="isPk != null and isPk != ''">#{isPk},</if> | |||
<if test="isIncrement != null and isIncrement != ''">#{isIncrement},</if> | |||
<if test="isRequired != null and isRequired != ''">#{isRequired},</if> | |||
<if test="isInsert != null and isInsert != ''">#{isInsert},</if> | |||
<if test="isEdit != null and isEdit != ''">#{isEdit},</if> | |||
<if test="isList != null and isList != ''">#{isList},</if> | |||
<if test="isQuery != null and isQuery != ''">#{isQuery},</if> | |||
<if test="queryType != null and queryType != ''">#{queryType},</if> | |||
<if test="htmlType != null and htmlType != ''">#{htmlType},</if> | |||
<if test="dictType != null and dictType != ''">#{dictType},</if> | |||
<if test="sort != null">#{sort},</if> | |||
<if test="createBy != null and createBy != ''">#{createBy},</if> | |||
sysdate() | |||
) | |||
</insert> | |||
<update id="updateGenTableColumn" parameterType="com.taauav.tool.entity.GenTableColumn"> | |||
update gen_table_column |
@@ -0,0 +1,22 @@ | |||
package com.taauav.tool.service; | |||
import com.taauav.common.service.impl.BaseServiceImpl; | |||
import com.taauav.tool.entity.GenTableColumn; | |||
import com.taauav.tool.mapper.GenTableColumnMapper; | |||
import org.springframework.stereotype.Service; | |||
import java.util.List; | |||
@Service | |||
public class GenTableColumnServiceImpl extends BaseServiceImpl<GenTableColumnMapper, GenTableColumn> implements IGenTableColumnService { | |||
@Override | |||
public List<GenTableColumn> selectDbTableColumnsByName(String tableName) { | |||
return getBaseMapper().selectDbTableColumnsByName(tableName); | |||
} | |||
@Override | |||
public void insertGenTableColumn(GenTableColumn column) { | |||
save(column); | |||
} | |||
} |
@@ -1,16 +1,20 @@ | |||
package com.taauav.tool.service; | |||
import com.taauav.common.config.GenConfig; | |||
import com.taauav.common.core.text.Convert; | |||
import com.taauav.common.service.impl.BaseServiceImpl; | |||
import com.taauav.common.util.ShiroUtils; | |||
import com.taauav.common.util.StringUtils; | |||
import com.taauav.tool.entity.GenTable; | |||
import com.taauav.tool.entity.GenTableColumn; | |||
import com.taauav.tool.mapper.GenTableMapper; | |||
import com.taauav.tool.util.GenUtils; | |||
import com.taauav.tool.util.VelocityInitializer; | |||
import com.taauav.tool.util.VelocityUtils; | |||
import org.apache.velocity.Template; | |||
import org.apache.velocity.VelocityContext; | |||
import org.apache.velocity.app.Velocity; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import java.io.File; | |||
@@ -26,6 +30,8 @@ import java.util.List; | |||
@Service | |||
public class GenTableServiceImpl extends BaseServiceImpl<GenTableMapper, GenTable> implements IGenTableService { | |||
@Autowired | |||
private IGenTableColumnService genTableColumnService; | |||
@Override | |||
public void generatorCode(String tableName) { | |||
@@ -63,6 +69,42 @@ public class GenTableServiceImpl extends BaseServiceImpl<GenTableMapper, GenTabl | |||
} | |||
} | |||
@Override | |||
public void importGenTable(String tables) { | |||
String[] tableNames = Convert.toStrArray(tables); | |||
// 查询表信息 | |||
List<GenTable> tableList = selectDbTableListByNames(tableNames); | |||
Integer operName = ShiroUtils.getAdminId(); | |||
for (GenTable table : tableList) | |||
{ | |||
try | |||
{ | |||
String tableName = table.getTableName(); | |||
GenUtils.initTable(table, operName); | |||
boolean row = save(table); | |||
if (row) | |||
{ | |||
// 保存列信息 | |||
List<GenTableColumn> genTableColumns = genTableColumnService.selectDbTableColumnsByName(tableName); | |||
for (GenTableColumn column : genTableColumns) | |||
{ | |||
GenUtils.initColumnField(column, table); | |||
genTableColumnService.insertGenTableColumn(column); | |||
} | |||
} | |||
} | |||
catch (Exception e) | |||
{ | |||
log.error("表名 " + table.getTableName() + " 导入失败:", e); | |||
} | |||
} | |||
} | |||
public List<GenTable> selectDbTableListByNames(String[] tableNames) { | |||
List<GenTable> tableList = getBaseMapper().selectDbTableListByNames(tableNames); | |||
return tableList; | |||
} | |||
/** | |||
* 设置主键列信息 | |||
* @param genTable | |||
@@ -79,4 +121,16 @@ public class GenTableServiceImpl extends BaseServiceImpl<GenTableMapper, GenTabl | |||
genTable.setPkColumn(columns.get(0)); | |||
} | |||
} | |||
public void setIgnoreColumn(GenTable genTable, List<GenTableColumn> columns) { | |||
for (GenTableColumn column : columns) { | |||
if (column.getColumnName().equals("status") || column.getColumnName().equals("create_user") || | |||
column.getColumnName().equals("create_time") || column.getColumnName().equals("update_user") || | |||
column.getColumnName().equals("update_time") || column.getColumnName().equals("mark")) { | |||
genTable.setIgnore(true); | |||
} else { | |||
genTable.setIgnore(false); | |||
} | |||
} | |||
} | |||
} |
@@ -1,4 +1,12 @@ | |||
package com.taauav.tool.service; | |||
public interface IGenTableColumnService { | |||
import com.taauav.common.service.IBaseService; | |||
import com.taauav.tool.entity.GenTableColumn; | |||
import java.util.List; | |||
public interface IGenTableColumnService extends IBaseService<GenTableColumn> { | |||
List<GenTableColumn> selectDbTableColumnsByName(String tableName); | |||
void insertGenTableColumn(GenTableColumn column); | |||
} |
@@ -9,4 +9,6 @@ import com.taauav.tool.entity.GenTable; | |||
*/ | |||
public interface IGenTableService extends IBaseService<GenTable> { | |||
void generatorCode(String tableName); | |||
void importGenTable(String tables); | |||
} |
@@ -25,20 +25,23 @@ public class VelocityUtils | |||
String tplCategory = genTable.getTplCategory(); | |||
String funcationName = genTable.getFunctionName(); | |||
List<GenTableColumn> columnList = genTable.getColumns(); | |||
VelocityContext velocityContext = new VelocityContext(); | |||
velocityContext.put("tplCategory", tplCategory); | |||
velocityContext.put("tableName", genTable.getTableName()); | |||
velocityContext.put("functionName", funcationName); | |||
velocityContext.put("className", StringUtils.uncapitalize(genTable.getClassName())); | |||
velocityContext.put("ClassName", genTable.getClassName()); | |||
velocityContext.put("moduleName", moduleName); | |||
velocityContext.put("businessName", StringUtils.uncapitalize(businessName)); | |||
velocityContext.put("packageName", packageName); | |||
velocityContext.put("author", genTable.getFunctionAuthor()); | |||
velocityContext.put("datetime", DateUtil.today()); | |||
velocityContext.put("pkColumn", genTable.getPkColumn()); | |||
velocityContext.put("importList", null); | |||
velocityContext.put("permissionPrefix", null); | |||
velocityContext.put("columns", genTable.getColumns()); | |||
velocityContext.put("importList", getImportList(genTable.getColumns())); | |||
velocityContext.put("permissionPrefix", getPermissionPrefix(moduleName,businessName)); | |||
velocityContext.put("columns", columnList); | |||
velocityContext.put("table", genTable); | |||
return velocityContext; | |||
} | |||
@@ -81,26 +84,26 @@ public class VelocityUtils | |||
String bussinessName = genTable.getBusinessName(); | |||
String javaPath = PROJECT_PATH + "/" + StringUtils.replace(packageName, ".", "/"); | |||
String javaPath = PROJECT_PATH; | |||
if (template.contains("entity.java.vm")) | |||
{ | |||
fileName = StringUtils.format("{}/{}/{}/entity/{}.java", javaPath,packageName,moduleName, className); | |||
fileName = StringUtils.format("{}/{}//entity/{}.java", javaPath,packageName, className); | |||
} else if (template.contains("mapper.java.vm")) | |||
{ | |||
fileName = StringUtils.format("{}/{}/{}/mapper/{}.java", javaPath,packageName,moduleName, className); | |||
fileName = StringUtils.format("{}/{}//mapper/{}Mapper.java", javaPath,packageName, className); | |||
} else if (template.contains("service.java.vm")) | |||
{ | |||
fileName = StringUtils.format("{}/{}/{}/service/{}.java", javaPath,packageName,moduleName, className); | |||
fileName = StringUtils.format("{}/{}//service/I{}Service.java", javaPath,packageName, className); | |||
} else if (template.contains("serviceImpl.java.vm")) | |||
{ | |||
fileName = StringUtils.format("{}/{}/{}/service/impl/{}.java", javaPath,packageName,moduleName, className); | |||
fileName = StringUtils.format("{}/{}//service/impl/{}ServiceImpl.java", javaPath,packageName, className); | |||
} else if (template.contains("controller.java.vm")) | |||
{ | |||
fileName = StringUtils.format("{}/{}/{}/controller/{}.java", javaPath,packageName,moduleName, className); | |||
fileName = StringUtils.format("{}/{}//controller/{}Controller.java", javaPath,packageName, className); | |||
} else if (template.contains("mapper.xml.vm")) | |||
{ | |||
fileName = StringUtils.format("{}/{}/{}/mapper/{}.java", javaPath,packageName,moduleName, className); | |||
fileName = StringUtils.format("{}//{}/mapper/{}Mapper.xml", javaPath,packageName, className); | |||
} else if (template.contains("sql.vm")) | |||
{ | |||
fileName = PROJECT_PATH + "/" + bussinessName + "/Menu.sql"; | |||
@@ -136,6 +139,9 @@ public class VelocityUtils | |||
} else if(!column.isSuperColumn() && GenConstants.TYPE_BIGDECIMAL.equals(column.getJavaType())) | |||
{ | |||
importList.add("java.math.BigDecimal"); | |||
}else if(!column.isSuperColumn() && GenConstants.HTML_DATETIME.equals(column.getJavaType())) | |||
{ | |||
importList.add("java.util.Date"); | |||
} | |||
} | |||
return importList; |
@@ -1,12 +1,9 @@ | |||
package ${packageName}.controller; | |||
import java.util.List; | |||
import com.baomidou.mybatisplus.core.metadata.IPage; | |||
import com.meijia.common.core.mp.Condition; | |||
import com.meijia.common.core.mp.Query; | |||
import com.taauav.admin.controller.BaseController; | |||
import com.taauav.common.bean.Response; | |||
import com.taauav.common.constant.PermissionConstants; | |||
import org.apache.shiro.authz.annotation.RequiresPermissions; | |||
import com.taauav.common.core.mps.BaseQuery; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.GetMapping; | |||
import org.springframework.web.bind.annotation.PostMapping; | |||
@@ -16,8 +13,7 @@ import org.springframework.web.bind.annotation.PathVariable; | |||
import org.springframework.web.bind.annotation.RequestBody; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RestController; | |||
import com.taauav.common.bean.Response; | |||
import ${packageName}.domain.${ClassName}; | |||
import ${packageName}.entity.${ClassName}; | |||
import ${packageName}.service.I${ClassName}Service; | |||
@@ -36,12 +32,12 @@ public class ${ClassName}Controller extends BaseController | |||
@Autowired | |||
private Response response; | |||
/** | |||
* 查询${functionName}列表 | |||
*/ | |||
@RequiresPermissions("${permissionPrefix}:list") | |||
@GetMapping("/list") | |||
public Response list(${ClassName} ${className}, Query query) | |||
/** | |||
* 查询${functionName}列表 | |||
*/ | |||
@RequiresPermissions("${permissionPrefix}:list") | |||
@GetMapping("/list") | |||
public Response list(${ClassName} ${className}, BaseQuery query) | |||
{ | |||
return ${className}Service.pageData(query,${className}); | |||
} | |||
@@ -51,17 +47,17 @@ public class ${ClassName}Controller extends BaseController | |||
/** | |||
* 获取${functionName}详细信息 | |||
*/ | |||
@PreAuthorize("${permissionPrefix}:query") | |||
@RequiresPermissions("${permissionPrefix}:query") | |||
@GetMapping(value = "/{${pkColumn.javaField}}") | |||
public Response getInfo(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField}) | |||
{ | |||
response.success(${className}Service.getInfo(${pkColumn.javaField})); | |||
return response.success(${className}Service.getInfo(${pkColumn.javaField})); | |||
} | |||
/** | |||
* 新增${functionName} | |||
*/ | |||
@PreAuthorize("${permissionPrefix}:add") | |||
@RequiresPermissions("${permissionPrefix}:add") | |||
@PostMapping | |||
public Response add(@RequestBody ${ClassName} ${className}) | |||
{ | |||
@@ -71,7 +67,7 @@ public class ${ClassName}Controller extends BaseController | |||
/** | |||
* 修改${functionName} | |||
*/ | |||
@PreAuthorize("${permissionPrefix}:edit") | |||
@RequiresPermissions("${permissionPrefix}:edit") | |||
@PutMapping | |||
public Response edit(@RequestBody ${ClassName} ${className}) | |||
{ | |||
@@ -81,7 +77,7 @@ public class ${ClassName}Controller extends BaseController | |||
/** | |||
* 删除${functionName} | |||
*/ | |||
@PreAuthorize("${permissionPrefix}:remove") | |||
@RequiresPermissions("${permissionPrefix}:remove") | |||
@DeleteMapping("/{${pkColumn.javaField}s}") | |||
public Response remove(@PathVariable ${pkColumn.javaType}[] ${pkColumn.javaField}s) | |||
{ |
@@ -1,12 +1,9 @@ | |||
package ${packageName}.entity; | |||
import com.baomidou.mybatisplus.annotation.TableName; | |||
import com.taauav.common.domain.Entity; | |||
import lombok.Data; | |||
import lombok.EqualsAndHashCode; | |||
import lombok.experimental.Accessors; | |||
import java.io.Serializable; | |||
#foreach ($import in $importList) | |||
import ${import}; | |||
@@ -20,30 +17,14 @@ import ${import}; | |||
@Data | |||
@EqualsAndHashCode(callSuper = false) | |||
@Accessors(chain = true) | |||
public class ${ClassName} extends Entity implements ${Entity} { | |||
public class ${ClassName} extends Entity { | |||
private static final long serialVersionUID = 1L; | |||
#foreach ($column in $columns) | |||
#if(!$table.isSuperColumn($column.javaField)) | |||
/** $column.columnComment */ | |||
#if($column.list) | |||
#set($parentheseIndex=$column.columnComment.indexOf("(")) | |||
#if($parentheseIndex != -1) | |||
#set($comment=$column.columnComment.substring(0, $parentheseIndex)) | |||
#else | |||
#set($comment=$column.columnComment) | |||
#end | |||
#if($parentheseIndex != -1) | |||
@Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()") | |||
#elseif($column.javaType == 'Date') | |||
@Excel(name = "${comment}", width = 30, dateFormat = "yyyy-MM-dd") | |||
#else | |||
@Excel(name = "${comment}") | |||
#end | |||
#end | |||
private $column.javaType $column.javaField; | |||
#end | |||
#end | |||
} | |||
#foreach ($column in $columns) | |||
#if(!$table.isSuperColumn($column.javaField) || $column.getIgnore) | |||
/** $column.columnComment */ | |||
private $column.javaType $column.javaField; | |||
#end | |||
#end | |||
} |
@@ -1,6 +1,6 @@ | |||
package ${packageName}.service; | |||
import ${packageName}.domain.${ClassName}; | |||
import ${packageName}.entity.${ClassName}; | |||
import com.taauav.common.service.IBaseService; | |||
/** |
@@ -4,7 +4,7 @@ package ${packageName}.service.impl; | |||
import com.taauav.common.service.impl.BaseServiceImpl; | |||
import org.springframework.stereotype.Service; | |||
import ${packageName}.mapper.${ClassName}Mapper; | |||
import ${packageName}.domain.${ClassName}; | |||
import ${packageName}.entity.${ClassName}; | |||
import ${packageName}.service.I${ClassName}Service; | |||
/** |
@@ -1,7 +1,7 @@ | |||
package ${packageName}.wrapper; | |||
import com.taauav.common.web.BaseWrapper; | |||
import ${packageName}.domain.${ClassName}; | |||
import ${packageName}.entity.${ClassName}; | |||
import ${packageName}.vo.${ClassName}VO; | |||
import org.springframework.beans.BeanUtils; | |||