代码生成;
This commit is contained in:
parent
883a68b7b2
commit
692cb45255
|
|
@ -74,7 +74,7 @@ public class GenController extends BaseController {
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public TableDataInfo columnList(GenTable genTable) {
|
public TableDataInfo columnList(GenTable genTable) {
|
||||||
TableDataInfo dataInfo = new TableDataInfo();
|
TableDataInfo dataInfo = new TableDataInfo();
|
||||||
List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(genTable);
|
List<GenTableColumn> list = genTableService.selectGenTableById(genTable.getTableId()).getColumns();
|
||||||
dataInfo.setRows(list);
|
dataInfo.setRows(list);
|
||||||
dataInfo.setTotal(list.size());
|
dataInfo.setTotal(list.size());
|
||||||
return dataInfo;
|
return dataInfo;
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,6 @@ public class GenTable extends BaseEntity {
|
||||||
/**
|
/**
|
||||||
* 表描述
|
* 表描述
|
||||||
*/
|
*/
|
||||||
@NotBlank(message = "表描述不能为空")
|
|
||||||
private String tableComment;
|
private String tableComment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -70,7 +69,6 @@ public class GenTable extends BaseEntity {
|
||||||
/**
|
/**
|
||||||
* 生成功能名
|
* 生成功能名
|
||||||
*/
|
*/
|
||||||
@NotBlank(message = "生成功能名不能为空")
|
|
||||||
private String functionName;
|
private String functionName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -89,7 +87,10 @@ public class GenTable extends BaseEntity {
|
||||||
* 表列信息
|
* 表列信息
|
||||||
*/
|
*/
|
||||||
@Valid
|
@Valid
|
||||||
@OneToMany(mappedBy = "table")
|
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
|
||||||
|
@JoinTable(name = "gen_table_columns",
|
||||||
|
joinColumns = @JoinColumn(name = "genTableTableId", referencedColumnName = "tableId"),
|
||||||
|
inverseJoinColumns = @JoinColumn(name = "columnsColumnId", referencedColumnName = "columnId"))
|
||||||
private List<GenTableColumn> columns;
|
private List<GenTableColumn> columns;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -104,13 +104,6 @@ public class GenTableColumn extends BaseEntity {
|
||||||
*/
|
*/
|
||||||
private Integer sort;
|
private Integer sort;
|
||||||
|
|
||||||
@ManyToOne
|
|
||||||
@JoinTable(name = "gen_table_columns",
|
|
||||||
inverseJoinColumns = @JoinColumn(name = "genTableTableId", referencedColumnName = "tableId"),
|
|
||||||
joinColumns = @JoinColumn(name = "columnsColumnId", referencedColumnName = "columnId"))
|
|
||||||
@org.hibernate.annotations.ForeignKey(name = "none")
|
|
||||||
private GenTable table;
|
|
||||||
|
|
||||||
public void setColumnId(Long columnId) {
|
public void setColumnId(Long columnId) {
|
||||||
this.columnId = columnId;
|
this.columnId = columnId;
|
||||||
}
|
}
|
||||||
|
|
@ -341,11 +334,7 @@ public class GenTableColumn extends BaseEntity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public GenTable getTable() {
|
public String capital(){
|
||||||
return table;
|
return StringUtils.capitalize(this.javaField);
|
||||||
}
|
|
||||||
|
|
||||||
public void setTable(GenTable table) {
|
|
||||||
this.table = table;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,20 +1,10 @@
|
||||||
package com.ruoyi.generator.repository;
|
package com.ruoyi.generator.repository;
|
||||||
|
|
||||||
import com.ruoyi.common.base.BaseRepository;
|
import com.ruoyi.common.base.BaseRepository;
|
||||||
import com.ruoyi.generator.domain.GenTable;
|
|
||||||
import com.ruoyi.generator.domain.GenTableColumn;
|
import com.ruoyi.generator.domain.GenTableColumn;
|
||||||
import org.springframework.data.jpa.repository.Modifying;
|
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface GenTableColumnRepository extends BaseRepository<GenTableColumn, Long> {
|
public interface GenTableColumnRepository extends BaseRepository<GenTableColumn, Long> {
|
||||||
|
|
||||||
List<GenTableColumn> findByTable(GenTable genTable);
|
|
||||||
|
|
||||||
@Modifying
|
|
||||||
void deleteByTableIn(Collection<GenTable> tables);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package com.ruoyi.generator.repository;
|
||||||
|
|
||||||
import com.ruoyi.common.base.BaseRepository;
|
import com.ruoyi.common.base.BaseRepository;
|
||||||
import com.ruoyi.generator.domain.GenTable;
|
import com.ruoyi.generator.domain.GenTable;
|
||||||
import org.springframework.data.jpa.repository.EntityGraph;
|
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
@ -12,7 +11,6 @@ public interface GenTableRepository extends BaseRepository<GenTable, Long> {
|
||||||
|
|
||||||
GenTable findFirstByTableName(String tableName);
|
GenTable findFirstByTableName(String tableName);
|
||||||
|
|
||||||
@EntityGraph(attributePaths = {"columns"})
|
|
||||||
@Override
|
@Override
|
||||||
Optional<GenTable> findById(Long id);
|
Optional<GenTable> findById(Long id);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,5 @@
|
||||||
package com.ruoyi.generator.service;
|
package com.ruoyi.generator.service;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.ruoyi.generator.domain.GenTable;
|
|
||||||
import com.ruoyi.generator.domain.GenTableColumn;
|
import com.ruoyi.generator.domain.GenTableColumn;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -11,13 +8,6 @@ import com.ruoyi.generator.domain.GenTableColumn;
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
public interface IGenTableColumnService {
|
public interface IGenTableColumnService {
|
||||||
/**
|
|
||||||
* 查询业务字段列表
|
|
||||||
*
|
|
||||||
* @param genTable 业务字段信息
|
|
||||||
* @return 业务字段集合
|
|
||||||
*/
|
|
||||||
public List<GenTableColumn> selectGenTableColumnListByTableId(GenTable genTable);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增业务字段
|
* 新增业务字段
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package com.ruoyi.generator.service.impl;
|
package com.ruoyi.generator.service.impl;
|
||||||
|
|
||||||
import com.ruoyi.common.core.text.Convert;
|
import com.ruoyi.common.core.text.Convert;
|
||||||
import com.ruoyi.generator.domain.GenTable;
|
|
||||||
import com.ruoyi.generator.domain.GenTableColumn;
|
import com.ruoyi.generator.domain.GenTableColumn;
|
||||||
import com.ruoyi.generator.repository.GenTableColumnRepository;
|
import com.ruoyi.generator.repository.GenTableColumnRepository;
|
||||||
import com.ruoyi.generator.service.IGenTableColumnService;
|
import com.ruoyi.generator.service.IGenTableColumnService;
|
||||||
|
|
@ -9,8 +8,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 业务字段 服务层实现
|
* 业务字段 服务层实现
|
||||||
*
|
*
|
||||||
|
|
@ -21,16 +18,6 @@ public class GenTableColumnServiceImpl implements IGenTableColumnService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private GenTableColumnRepository genTableColumnRepository;
|
private GenTableColumnRepository genTableColumnRepository;
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询业务字段列表
|
|
||||||
*
|
|
||||||
* @param genTable 业务字段信息
|
|
||||||
* @return 业务字段集合
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public List<GenTableColumn> selectGenTableColumnListByTableId(GenTable genTable) {
|
|
||||||
return genTableColumnRepository.findByTable(genTable);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增业务字段
|
* 新增业务字段
|
||||||
|
|
|
||||||
|
|
@ -179,12 +179,9 @@ public class GenTableServiceImpl extends BaseService implements IGenTableService
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public void deleteGenTableByIds(String ids) {
|
public void deleteGenTableByIds(String ids) {
|
||||||
List<GenTable> tables = new ArrayList<>();
|
|
||||||
for(Long id : Convert.toLongArray(ids)){
|
for(Long id : Convert.toLongArray(ids)){
|
||||||
genTableRepository.deleteById(id);
|
genTableRepository.deleteById(id);
|
||||||
tables.add(new GenTable(id));
|
|
||||||
}
|
}
|
||||||
genTableColumnRepository.deleteByTableIn(tables);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -199,15 +196,17 @@ public class GenTableServiceImpl extends BaseService implements IGenTableService
|
||||||
for (GenTable table : tableList) {
|
for (GenTable table : tableList) {
|
||||||
try {
|
try {
|
||||||
GenUtils.initTable(table, operName);
|
GenUtils.initTable(table, operName);
|
||||||
genTableRepository.save(table);
|
List<GenTableColumn> columns = new ArrayList<>();
|
||||||
String sql = "select column_name, (case when (is_nullable = 'no' && column_key != 'PRI') then '1' else null end) as is_required, (case when column_key = 'PRI' then '1' else '0' end) as is_pk, ordinal_position as sort, column_comment, (case when extra = 'auto_increment' then '1' else '0' end) as is_increment, column_type " +
|
String sql = "select column_name, (case when (is_nullable = 'no' && column_key != 'PRI') then '1' else null end) as is_required, (case when column_key = 'PRI' then '1' else '0' end) as is_pk, ordinal_position as sort, column_comment, (case when extra = 'auto_increment' then '1' else '0' end) as is_increment, column_type " +
|
||||||
" from information_schema.columns where table_schema = (select database()) and table_name = '" + table.getTableName() + "'" +
|
" from information_schema.columns where table_schema = (select database()) and table_name = '" + table.getTableName() + "'" +
|
||||||
" order by ordinal_position";
|
" order by ordinal_position";
|
||||||
List<GenTableColumn> genTableColumns = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(GenTableColumn.class));
|
List<GenTableColumn> genTableColumns = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(GenTableColumn.class));
|
||||||
for (GenTableColumn column : genTableColumns) {
|
for (GenTableColumn column : genTableColumns) {
|
||||||
GenUtils.initColumnField(column, table);
|
GenUtils.initColumnField(column, table);
|
||||||
genTableColumnRepository.save(column);
|
columns.add(column);
|
||||||
}
|
}
|
||||||
|
table.setColumns(columns);
|
||||||
|
genTableRepository.save(table);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("表名 " + table.getTableName() + " 导入失败:", e);
|
log.error("表名 " + table.getTableName() + " 导入失败:", e);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
package com.ruoyi.generator.util;
|
package com.ruoyi.generator.util;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.RegExUtils;
|
|
||||||
import com.ruoyi.common.constant.GenConstants;
|
import com.ruoyi.common.constant.GenConstants;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
import com.ruoyi.generator.config.GenConfig;
|
import com.ruoyi.generator.config.GenConfig;
|
||||||
import com.ruoyi.generator.domain.GenTable;
|
import com.ruoyi.generator.domain.GenTable;
|
||||||
import com.ruoyi.generator.domain.GenTableColumn;
|
import com.ruoyi.generator.domain.GenTableColumn;
|
||||||
|
import org.apache.commons.lang3.RegExUtils;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 代码生成器 工具类
|
* 代码生成器 工具类
|
||||||
|
|
@ -34,7 +34,6 @@ public class GenUtils {
|
||||||
public static void initColumnField(GenTableColumn column, GenTable table) {
|
public static void initColumnField(GenTableColumn column, GenTable table) {
|
||||||
String dataType = getDbType(column.getColumnType());
|
String dataType = getDbType(column.getColumnType());
|
||||||
String columnName = column.getColumnName();
|
String columnName = column.getColumnName();
|
||||||
column.setTable(table);
|
|
||||||
column.setCreateBy(table.getCreateBy());
|
column.setCreateBy(table.getCreateBy());
|
||||||
// 设置java字段名
|
// 设置java字段名
|
||||||
column.setJavaField(StringUtils.toCamelCase(columnName));
|
column.setJavaField(StringUtils.toCamelCase(columnName));
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
package com.ruoyi.generator.util;
|
package com.ruoyi.generator.util;
|
||||||
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import org.apache.velocity.app.Velocity;
|
|
||||||
import com.ruoyi.common.constant.Constants;
|
import com.ruoyi.common.constant.Constants;
|
||||||
|
import org.apache.velocity.app.Velocity;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* VelocityEngine工厂
|
* VelocityEngine工厂
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,5 @@
|
||||||
package com.ruoyi.generator.util;
|
package com.ruoyi.generator.util;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.apache.velocity.VelocityContext;
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.ruoyi.common.constant.GenConstants;
|
import com.ruoyi.common.constant.GenConstants;
|
||||||
import com.ruoyi.common.utils.DateUtils;
|
import com.ruoyi.common.utils.DateUtils;
|
||||||
|
|
@ -12,6 +7,11 @@ import com.ruoyi.common.utils.StringUtils;
|
||||||
import com.ruoyi.generator.config.GenConfig;
|
import com.ruoyi.generator.config.GenConfig;
|
||||||
import com.ruoyi.generator.domain.GenTable;
|
import com.ruoyi.generator.domain.GenTable;
|
||||||
import com.ruoyi.generator.domain.GenTableColumn;
|
import com.ruoyi.generator.domain.GenTableColumn;
|
||||||
|
import org.apache.velocity.VelocityContext;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class VelocityUtils {
|
public class VelocityUtils {
|
||||||
/**
|
/**
|
||||||
|
|
@ -47,6 +47,7 @@ public class VelocityUtils {
|
||||||
velocityContext.put("functionName", StringUtils.isNotEmpty(functionName) ? functionName : "【请填写功能名称】");
|
velocityContext.put("functionName", StringUtils.isNotEmpty(functionName) ? functionName : "【请填写功能名称】");
|
||||||
velocityContext.put("ClassName", genTable.getClassName());
|
velocityContext.put("ClassName", genTable.getClassName());
|
||||||
velocityContext.put("className", StringUtils.uncapitalize(genTable.getClassName()));
|
velocityContext.put("className", StringUtils.uncapitalize(genTable.getClassName()));
|
||||||
|
velocityContext.put("classname", StringUtils.uncapitalize(genTable.getClassName()));
|
||||||
velocityContext.put("moduleName", genTable.getModuleName());
|
velocityContext.put("moduleName", genTable.getModuleName());
|
||||||
velocityContext.put("businessName", genTable.getBusinessName());
|
velocityContext.put("businessName", genTable.getBusinessName());
|
||||||
velocityContext.put("basePackage", getPackagePrefix(packageName));
|
velocityContext.put("basePackage", getPackagePrefix(packageName));
|
||||||
|
|
@ -54,6 +55,7 @@ public class VelocityUtils {
|
||||||
velocityContext.put("author", genTable.getFunctionAuthor());
|
velocityContext.put("author", genTable.getFunctionAuthor());
|
||||||
velocityContext.put("datetime", DateUtils.getDate());
|
velocityContext.put("datetime", DateUtils.getDate());
|
||||||
velocityContext.put("pkColumn", genTable.getPkColumn());
|
velocityContext.put("pkColumn", genTable.getPkColumn());
|
||||||
|
velocityContext.put("primaryKeyType", genTable.getPkColumn().getJavaType());
|
||||||
velocityContext.put("importList", getImportList(genTable.getColumns()));
|
velocityContext.put("importList", getImportList(genTable.getColumns()));
|
||||||
velocityContext.put("permissionPrefix", getPermissionPrefix(moduleName, businessName));
|
velocityContext.put("permissionPrefix", getPermissionPrefix(moduleName, businessName));
|
||||||
velocityContext.put("columns", genTable.getColumns());
|
velocityContext.put("columns", genTable.getColumns());
|
||||||
|
|
@ -91,9 +93,8 @@ public class VelocityUtils {
|
||||||
public static List<String> getTemplateList(String tplCategory) {
|
public static List<String> getTemplateList(String tplCategory) {
|
||||||
List<String> templates = new ArrayList<String>();
|
List<String> templates = new ArrayList<String>();
|
||||||
templates.add("vm/java/domain.java.vm");
|
templates.add("vm/java/domain.java.vm");
|
||||||
templates.add("vm/java/mapper.java.vm");
|
templates.add("vm/java/repository.java.vm");
|
||||||
templates.add("vm/java/service.java.vm");
|
templates.add("vm/java/service.java.vm");
|
||||||
templates.add("vm/java/serviceImpl.java.vm");
|
|
||||||
templates.add("vm/java/controller.java.vm");
|
templates.add("vm/java/controller.java.vm");
|
||||||
templates.add("vm/xml/mapper.xml.vm");
|
templates.add("vm/xml/mapper.xml.vm");
|
||||||
if (GenConstants.TPL_CRUD.equals(tplCategory)) {
|
if (GenConstants.TPL_CRUD.equals(tplCategory)) {
|
||||||
|
|
@ -128,11 +129,13 @@ public class VelocityUtils {
|
||||||
String htmlPath = TEMPLATES_PATH + "/" + moduleName + "/" + businessName;
|
String htmlPath = TEMPLATES_PATH + "/" + moduleName + "/" + businessName;
|
||||||
|
|
||||||
if (template.contains("domain.java.vm")) {
|
if (template.contains("domain.java.vm")) {
|
||||||
fileName = StringUtils.format("{}/domain/{}.java", javaPath, className);
|
fileName = StringUtils.format("{}/entity/{}.java", javaPath, className);
|
||||||
} else if (template.contains("mapper.java.vm")) {
|
} else if (template.contains("mapper.java.vm")) {
|
||||||
fileName = StringUtils.format("{}/mapper/{}Mapper.java", javaPath, className);
|
fileName = StringUtils.format("{}/mapper/{}Mapper.java", javaPath, className);
|
||||||
|
} else if (template.contains("repository.java.vm")) {
|
||||||
|
fileName = StringUtils.format("{}/repository/{}Repository.java", javaPath, className);
|
||||||
} else if (template.contains("service.java.vm")) {
|
} else if (template.contains("service.java.vm")) {
|
||||||
fileName = StringUtils.format("{}/service/I{}Service.java", javaPath, className);
|
fileName = StringUtils.format("{}/service/{}Service.java", javaPath, className);
|
||||||
} else if (template.contains("serviceImpl.java.vm")) {
|
} else if (template.contains("serviceImpl.java.vm")) {
|
||||||
fileName = StringUtils.format("{}/service/impl/{}ServiceImpl.java", javaPath, className);
|
fileName = StringUtils.format("{}/service/impl/{}ServiceImpl.java", javaPath, className);
|
||||||
} else if (template.contains("controller.java.vm")) {
|
} else if (template.contains("controller.java.vm")) {
|
||||||
|
|
|
||||||
|
|
@ -12,15 +12,15 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
import com.ruoyi.common.annotation.Log;
|
import com.ruoyi.common.annotation.Log;
|
||||||
import com.ruoyi.common.enums.BusinessType;
|
import com.ruoyi.common.enums.BusinessType;
|
||||||
import ${packageName}.domain.${ClassName};
|
import ${packageName}.entity.${ClassName};
|
||||||
import ${packageName}.service.I${ClassName}Service;
|
import ${packageName}.service.${ClassName}Service;
|
||||||
import com.ruoyi.common.core.controller.BaseController;
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
import com.ruoyi.common.core.domain.AjaxResult;
|
import com.ruoyi.common.core.domain.AjaxResult;
|
||||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||||
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
#if($table.crud)
|
#if($table.crud)
|
||||||
import com.ruoyi.common.core.page.TableDataInfo;
|
import com.ruoyi.common.core.page.TableDataInfo;
|
||||||
#elseif($table.tree)
|
#elseif($table.tree)
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
|
||||||
import com.ruoyi.common.core.domain.Ztree;
|
import com.ruoyi.common.core.domain.Ztree;
|
||||||
#end
|
#end
|
||||||
|
|
||||||
|
|
@ -37,7 +37,7 @@ public class ${ClassName}Controller extends BaseController
|
||||||
private String prefix = "${moduleName}/${businessName}";
|
private String prefix = "${moduleName}/${businessName}";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private I${ClassName}Service ${className}Service;
|
private ${ClassName}Service ${className}Service;
|
||||||
|
|
||||||
@RequiresPermissions("${permissionPrefix}:view")
|
@RequiresPermissions("${permissionPrefix}:view")
|
||||||
@GetMapping()
|
@GetMapping()
|
||||||
|
|
@ -54,9 +54,7 @@ public class ${ClassName}Controller extends BaseController
|
||||||
@PostMapping("/list")
|
@PostMapping("/list")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public TableDataInfo list(${ClassName} ${className}) {
|
public TableDataInfo list(${ClassName} ${className}) {
|
||||||
startPage();
|
return getDataTable(${className}Service.findByPage(${className}, getPageRequest()));
|
||||||
List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
|
|
||||||
return getDataTable(list);
|
|
||||||
}
|
}
|
||||||
#elseif($table.tree)
|
#elseif($table.tree)
|
||||||
/**
|
/**
|
||||||
|
|
@ -67,7 +65,7 @@ public class ${ClassName}Controller extends BaseController
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public List<${ClassName}> list(${ClassName} ${className})
|
public List<${ClassName}> list(${ClassName} ${className})
|
||||||
{
|
{
|
||||||
List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
|
List<${ClassName}> list = ${className}Service.findAll(${className});
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
#end
|
#end
|
||||||
|
|
@ -81,7 +79,7 @@ public class ${ClassName}Controller extends BaseController
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public AjaxResult export(${ClassName} ${className})
|
public AjaxResult export(${ClassName} ${className})
|
||||||
{
|
{
|
||||||
List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
|
List<${ClassName}> list = ${className}Service.findAll(${className});
|
||||||
ExcelUtil<${ClassName}> util = new ExcelUtil<${ClassName}>(${ClassName}.class);
|
ExcelUtil<${ClassName}> util = new ExcelUtil<${ClassName}>(${ClassName}.class);
|
||||||
return util.exportExcel(list, "${businessName}");
|
return util.exportExcel(list, "${businessName}");
|
||||||
}
|
}
|
||||||
|
|
@ -104,7 +102,7 @@ public class ${ClassName}Controller extends BaseController
|
||||||
{
|
{
|
||||||
if (StringUtils.isNotNull(${pkColumn.javaField}))
|
if (StringUtils.isNotNull(${pkColumn.javaField}))
|
||||||
{
|
{
|
||||||
mmap.put("${className}", ${className}Service.select${ClassName}ById(${pkColumn.javaField}));
|
mmap.put("${className}", ${className}Service.findById(${pkColumn.javaField}));
|
||||||
}
|
}
|
||||||
return prefix + "/add";
|
return prefix + "/add";
|
||||||
}
|
}
|
||||||
|
|
@ -119,7 +117,12 @@ public class ${ClassName}Controller extends BaseController
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public AjaxResult addSave(${ClassName} ${className})
|
public AjaxResult addSave(${ClassName} ${className})
|
||||||
{
|
{
|
||||||
return toAjax(${className}Service.insert${ClassName}(${className}));
|
try{
|
||||||
|
${className}Service.insert(${className});
|
||||||
|
return toAjax(true);
|
||||||
|
}catch (Exception e){
|
||||||
|
return error(e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -128,7 +131,7 @@ public class ${ClassName}Controller extends BaseController
|
||||||
@GetMapping("/edit/{${pkColumn.javaField}}")
|
@GetMapping("/edit/{${pkColumn.javaField}}")
|
||||||
public String edit(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField}, ModelMap mmap)
|
public String edit(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField}, ModelMap mmap)
|
||||||
{
|
{
|
||||||
${ClassName} ${className} = ${className}Service.select${ClassName}ById(${pkColumn.javaField});
|
${ClassName} ${className} = ${className}Service.findById(${pkColumn.javaField});
|
||||||
mmap.put("${className}", ${className});
|
mmap.put("${className}", ${className});
|
||||||
return prefix + "/edit";
|
return prefix + "/edit";
|
||||||
}
|
}
|
||||||
|
|
@ -142,7 +145,12 @@ public class ${ClassName}Controller extends BaseController
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public AjaxResult editSave(${ClassName} ${className})
|
public AjaxResult editSave(${ClassName} ${className})
|
||||||
{
|
{
|
||||||
return toAjax(${className}Service.update${ClassName}(${className}));
|
try{
|
||||||
|
${className}Service.update(${className});
|
||||||
|
return toAjax(true);
|
||||||
|
}catch (Exception e){
|
||||||
|
return error(e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if($table.crud)
|
#if($table.crud)
|
||||||
|
|
@ -155,7 +163,7 @@ public class ${ClassName}Controller extends BaseController
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public AjaxResult remove(String ids)
|
public AjaxResult remove(String ids)
|
||||||
{
|
{
|
||||||
return toAjax(${className}Service.delete${ClassName}ByIds(ids));
|
return toAjax(${className}Service.deleteByIds(ids));
|
||||||
}
|
}
|
||||||
#elseif($table.tree)
|
#elseif($table.tree)
|
||||||
/**
|
/**
|
||||||
|
|
@ -167,7 +175,7 @@ public class ${ClassName}Controller extends BaseController
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public AjaxResult remove(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField})
|
public AjaxResult remove(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField})
|
||||||
{
|
{
|
||||||
return toAjax(${className}Service.delete${ClassName}ById(${pkColumn.javaField}));
|
return toAjax(${className}Service.deleteById(${pkColumn.javaField}));
|
||||||
}
|
}
|
||||||
#end
|
#end
|
||||||
#if($table.tree)
|
#if($table.tree)
|
||||||
|
|
@ -181,7 +189,7 @@ public class ${ClassName}Controller extends BaseController
|
||||||
{
|
{
|
||||||
if (StringUtils.isNotNull(${pkColumn.javaField}))
|
if (StringUtils.isNotNull(${pkColumn.javaField}))
|
||||||
{
|
{
|
||||||
mmap.put("${className}", ${className}Service.select${ClassName}ById(${pkColumn.javaField}));
|
mmap.put("${className}", ${className}Service.findById(${pkColumn.javaField}));
|
||||||
}
|
}
|
||||||
return prefix + "/tree";
|
return prefix + "/tree";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,84 +1,86 @@
|
||||||
package ${packageName}.domain;
|
package ${packageName}.entity;
|
||||||
|
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
import com.ruoyi.common.annotation.Excel;
|
import com.ruoyi.common.annotation.Excel;
|
||||||
#if($table.crud)
|
import javax.persistence.Entity;
|
||||||
import com.ruoyi.common.core.domain.BaseEntity;
|
#if($table.crud)
|
||||||
#elseif($table.tree)
|
import com.ruoyi.common.core.domain.BaseDatabaseEntity;
|
||||||
import com.ruoyi.common.core.domain.TreeEntity;
|
#elseif($table.tree)
|
||||||
#end
|
import com.ruoyi.common.core.domain.TreeEntity;
|
||||||
#foreach ($import in $importList)
|
#end
|
||||||
import ${import};
|
#foreach ($import in $importList)
|
||||||
#end
|
import ${import};
|
||||||
|
#end
|
||||||
/**
|
|
||||||
* ${functionName}对象 ${tableName}
|
/**
|
||||||
*
|
* ${functionName}对象 ${tableName}
|
||||||
* @author ${author}
|
*
|
||||||
* @date ${datetime}
|
* @author ${author}
|
||||||
*/
|
* @date ${datetime}
|
||||||
#if($table.crud)
|
*/
|
||||||
#set($Entity="BaseEntity")
|
#if($table.crud)
|
||||||
#elseif($table.tree)
|
#set($Entity="BaseDatabaseEntity")
|
||||||
#set($Entity="TreeEntity")
|
#elseif($table.tree)
|
||||||
#end
|
#set($Entity="TreeEntity")
|
||||||
public class ${ClassName} extends ${Entity}
|
#end
|
||||||
{
|
@Entity
|
||||||
private static final long serialVersionUID = 1L;
|
public class ${ClassName} extends ${Entity}
|
||||||
|
{
|
||||||
#foreach ($column in $columns)
|
private static final long serialVersionUID = 1L;
|
||||||
#if(!$table.isSuperColumn($column.javaField))
|
|
||||||
/** $column.columnComment */
|
#foreach ($column in $columns)
|
||||||
#if($column.list)
|
#if(!$table.isSuperColumn($column.javaField))
|
||||||
#set($parentheseIndex=$column.columnComment.indexOf("("))
|
/** $column.columnComment */
|
||||||
#if($parentheseIndex != -1)
|
#if($column.list)
|
||||||
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
|
#set($parentheseIndex=$column.columnComment.indexOf("("))
|
||||||
#else
|
#if($parentheseIndex != -1)
|
||||||
#set($comment=$column.columnComment)
|
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
|
||||||
#end
|
#else
|
||||||
#if($parentheseIndex != -1)
|
#set($comment=$column.columnComment)
|
||||||
@Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
|
#end
|
||||||
#elseif($column.javaType == 'Date')
|
#if($parentheseIndex != -1)
|
||||||
@Excel(name = "${comment}", width = 30, dateFormat = "yyyy-MM-dd")
|
@Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
|
||||||
#else
|
#elseif($column.javaType == 'Date')
|
||||||
@Excel(name = "${comment}")
|
@Excel(name = "${comment}", width = 30, dateFormat = "yyyy-MM-dd")
|
||||||
#end
|
#else
|
||||||
#end
|
@Excel(name = "${comment}")
|
||||||
private $column.javaType $column.javaField;
|
#end
|
||||||
|
#end
|
||||||
#end
|
private $column.javaType $column.javaField;
|
||||||
#end
|
|
||||||
#foreach ($column in $columns)
|
#end
|
||||||
#if(!$table.isSuperColumn($column.javaField))
|
#end
|
||||||
#if($column.javaField.substring(1,2).matches("[A-Z]"))
|
#foreach ($column in $columns)
|
||||||
#set($AttrName=$column.javaField)
|
#if(!$table.isSuperColumn($column.javaField))
|
||||||
#else
|
#if($column.javaField.substring(1,2).matches("[A-Z]"))
|
||||||
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
#set($AttrName=$column.javaField)
|
||||||
#end
|
#else
|
||||||
public void set${AttrName}($column.javaType $column.javaField)
|
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
{
|
#end
|
||||||
this.$column.javaField = $column.javaField;
|
public void set${AttrName}($column.javaType $column.javaField)
|
||||||
}
|
{
|
||||||
|
this.$column.javaField = $column.javaField;
|
||||||
public $column.javaType get${AttrName}()
|
}
|
||||||
{
|
|
||||||
return $column.javaField;
|
public $column.javaType get${AttrName}()
|
||||||
}
|
{
|
||||||
#end
|
return $column.javaField;
|
||||||
#end
|
}
|
||||||
|
#end
|
||||||
@Override
|
#end
|
||||||
public String toString() {
|
|
||||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
@Override
|
||||||
#foreach ($column in $columns)
|
public String toString() {
|
||||||
#if($column.javaField.substring(1,2).matches("[A-Z]"))
|
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||||
#set($AttrName=$column.javaField)
|
#foreach ($column in $columns)
|
||||||
#else
|
#if($column.javaField.substring(1,2).matches("[A-Z]"))
|
||||||
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
#set($AttrName=$column.javaField)
|
||||||
#end
|
#else
|
||||||
.append("${column.javaField}", get${AttrName}())
|
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
#end
|
#end
|
||||||
.toString();
|
.append("${column.javaField}", get${AttrName}())
|
||||||
}
|
#end
|
||||||
}
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
package ${packageName}.repository;
|
||||||
|
|
||||||
|
import ${packageName}.entity.${ClassName};
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
/**
|
||||||
|
* ${functionName} dao层实现
|
||||||
|
*
|
||||||
|
* @author ${author}
|
||||||
|
* @date ${datetime}
|
||||||
|
*/
|
||||||
|
@Repository
|
||||||
|
public interface ${ClassName}Repository extends BaseRepository<${ClassName}, ${primaryKeyType}>{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,73 +1,139 @@
|
||||||
package ${packageName}.service;
|
package ${packageName}.service;
|
||||||
|
|
||||||
import ${packageName}.domain.${ClassName};
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
#if($table.tree)
|
import java.util.Date;
|
||||||
import com.ruoyi.common.core.domain.Ztree;
|
|
||||||
#end
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
/**
|
import org.springframework.stereotype.Service;
|
||||||
* ${functionName}Service接口
|
import org.springframework.data.domain.Page;
|
||||||
*
|
import org.springframework.data.domain.Pageable;
|
||||||
* @author ${author}
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
* @date ${datetime}
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
*/
|
import ${packageName}.repository.${ClassName}Repository;
|
||||||
public interface I${ClassName}Service
|
import ${packageName}.entity.${ClassName};
|
||||||
{
|
import com.ruoyi.common.core.text.Convert;
|
||||||
/**
|
|
||||||
* 查询${functionName}
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
*
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
* @param ${pkColumn.javaField} ${functionName}ID
|
import javax.persistence.criteria.Predicate;
|
||||||
* @return ${functionName}
|
import javax.persistence.criteria.Root;
|
||||||
*/
|
|
||||||
public ${ClassName} select${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField});
|
/**
|
||||||
|
* ${functionName} 服务层实现
|
||||||
/**
|
*
|
||||||
* 查询${functionName}列表
|
* @author ${author}
|
||||||
*
|
* @date ${datetime}
|
||||||
* @param ${className} ${functionName}
|
*/
|
||||||
* @return ${functionName}集合
|
@Service
|
||||||
*/
|
public class ${ClassName}Service {
|
||||||
public List<${ClassName}> select${ClassName}List(${ClassName} ${className});
|
|
||||||
|
@Autowired
|
||||||
/**
|
private ${ClassName}Repository ${classname}Repository;
|
||||||
* 新增${functionName}
|
|
||||||
*
|
/**
|
||||||
* @param ${className} ${functionName}
|
* 查询 ${functionName} 分页信息
|
||||||
* @return 结果
|
*
|
||||||
*/
|
* @param ${classname} 查询对象
|
||||||
public int insert${ClassName}(${ClassName} ${className});
|
* @param pageRequest 分页信息
|
||||||
|
* @return ${functionName} 分页后结果
|
||||||
/**
|
*/
|
||||||
* 修改${functionName}
|
public Page<${ClassName}> findByPage(${ClassName} ${classname}, Pageable pageRequest){
|
||||||
*
|
return ${classname}Repository.findAll(getSpecification(${classname}), pageRequest);
|
||||||
* @param ${className} ${functionName}
|
}
|
||||||
* @return 结果
|
|
||||||
*/
|
/**
|
||||||
public int update${ClassName}(${ClassName} ${className});
|
* 查询 ${functionName} 所有信息
|
||||||
|
*
|
||||||
/**
|
* @param ${classname} 查询对象
|
||||||
* 批量删除${functionName}
|
* @return ${functionName} 结果
|
||||||
*
|
*/
|
||||||
* @param ids 需要删除的数据ID
|
public List<${ClassName}> findAll(${ClassName} ${classname}){
|
||||||
* @return 结果
|
return ${classname}Repository.findAll(getSpecification(${classname}));
|
||||||
*/
|
}
|
||||||
public int delete${ClassName}ByIds(String ids);
|
|
||||||
|
/**
|
||||||
/**
|
* 新增${functionName}
|
||||||
* 删除${functionName}信息
|
*
|
||||||
*
|
* @param ${classname} ${functionName}信息
|
||||||
* @param ${pkColumn.javaField} ${functionName}ID
|
* @return 保存后的对象
|
||||||
* @return 结果
|
*/
|
||||||
*/
|
@Transactional
|
||||||
public int delete${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField});
|
public ${ClassName} insert(${ClassName} ${classname}){
|
||||||
#if($table.tree)
|
return ${classname}Repository.save(${classname});
|
||||||
|
}
|
||||||
/**
|
|
||||||
* 查询${functionName}树列表
|
/**
|
||||||
*
|
* 修改${functionName}
|
||||||
* @return 所有${functionName}信息
|
*
|
||||||
*/
|
* @param ${classname} ${functionName}信息
|
||||||
public List<Ztree> select${ClassName}Tree();
|
* @return 保存后的对象
|
||||||
#end
|
*/
|
||||||
}
|
@Transactional
|
||||||
|
public ${ClassName} update(${ClassName} ${classname}){
|
||||||
|
return ${classname}Repository.save(${classname});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询${functionName}对象
|
||||||
|
*
|
||||||
|
* @param ${pkColumn.javaField} 需要查询的id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public ${ClassName} findById(${pkColumn.javaType} ${pkColumn.javaField}){
|
||||||
|
return ${classname}Repository.findById(${pkColumn.javaField}).orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除${functionName}对象
|
||||||
|
*
|
||||||
|
* @param ${pkColumn.javaField} 需要删除的数据ID
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
public void deleteById(${pkColumn.javaType} ${pkColumn.javaField}){
|
||||||
|
${classname}Repository.deleteById(${pkColumn.javaField});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除${functionName}对象
|
||||||
|
*
|
||||||
|
* @param ids 需要删除的数据ID
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
public int deleteByIds(String ids) {
|
||||||
|
for(String id : Convert.toStrArray(ids)){
|
||||||
|
${classname}Repository.deleteById(${pkColumn.javaType}.valueOf(id));
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Specification<${ClassName}> getSpecification(${ClassName} ${classname}){
|
||||||
|
return new Specification<${ClassName}>() {
|
||||||
|
@Override
|
||||||
|
public Predicate toPredicate(Root<${ClassName}> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
|
||||||
|
List<Predicate> predicates = new ArrayList<>();
|
||||||
|
#foreach($column in $columns)
|
||||||
|
#if($column.javaType == "String")
|
||||||
|
if(StringUtils.isNotEmpty(${classname}.get${column.capital()}())){
|
||||||
|
predicates.add(criteriaBuilder.like(root.get("$column.javaField").as(${column.javaType}.class), "%" + ${classname}.get${column.capital()}() + "%"));
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if(${classname}.get${column.capital()}() != null){
|
||||||
|
predicates.add(criteriaBuilder.equal(root.get("$column.javaField").as(${column.javaType}.class), ${classname}.get${column.capital()}()));
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
if(${classname}.getStartTime() != null){
|
||||||
|
predicates.add(criteriaBuilder.lessThanOrEqualTo(root.get("createDate").as(Date.class), ${classname}.getStartTime()));
|
||||||
|
}
|
||||||
|
if(${classname}.getEndTime() != null){
|
||||||
|
predicates.add(criteriaBuilder.greaterThanOrEqualTo(root.get("createDate").as(Date.class), ${classname}.getEndTime()));
|
||||||
|
}
|
||||||
|
return criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()]));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,141 +1,149 @@
|
||||||
package ${packageName}.service.impl;
|
package ${packageName}.service.impl;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
#if($table.tree)
|
import org.springframework.data.domain.Page;
|
||||||
import java.util.ArrayList;
|
import org.springframework.data.domain.Pageable;
|
||||||
import com.ruoyi.common.core.domain.Ztree;
|
#if($table.tree)
|
||||||
#end
|
import java.util.ArrayList;
|
||||||
#foreach ($column in $columns)
|
import com.ruoyi.common.core.domain.Ztree;
|
||||||
#if($column.javaField == 'createTime' || $column.javaField == 'updateTime')
|
#end
|
||||||
import com.ruoyi.common.utils.DateUtils;
|
#foreach ($column in $columns)
|
||||||
#break
|
#if($column.javaField == 'createTime' || $column.javaField == 'updateTime')
|
||||||
#end
|
import com.ruoyi.common.utils.DateUtils;
|
||||||
#end
|
#break
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
#end
|
||||||
import org.springframework.stereotype.Service;
|
#end
|
||||||
import ${packageName}.mapper.${ClassName}Mapper;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import ${packageName}.domain.${ClassName};
|
import org.springframework.stereotype.Service;
|
||||||
import ${packageName}.service.I${ClassName}Service;
|
import ${packageName}.mapper.${ClassName}Mapper;
|
||||||
import com.ruoyi.common.core.text.Convert;
|
import ${packageName}.domain.${ClassName};
|
||||||
|
import ${packageName}.service.I${ClassName}Service;
|
||||||
/**
|
import com.ruoyi.common.core.text.Convert;
|
||||||
* ${functionName}Service业务层处理
|
|
||||||
*
|
/**
|
||||||
* @author ${author}
|
* ${functionName}Service业务层处理
|
||||||
* @date ${datetime}
|
*
|
||||||
*/
|
* @author ${author}
|
||||||
@Service
|
* @date ${datetime}
|
||||||
public class ${ClassName}ServiceImpl implements I${ClassName}Service
|
*/
|
||||||
{
|
@Service
|
||||||
@Autowired
|
public class ${ClassName}ServiceImpl implements I${ClassName}Service
|
||||||
private ${ClassName}Mapper ${className}Mapper;
|
{
|
||||||
|
@Autowired
|
||||||
/**
|
private ${ClassName}Mapper ${className}Mapper;
|
||||||
* 查询${functionName}
|
@Autowired
|
||||||
*
|
private ${ClassName}Repository ${className}Repository;
|
||||||
* @param ${pkColumn.javaField} ${functionName}ID
|
|
||||||
* @return ${functionName}
|
public Page<${ClassName}> findByPage(${className}, Pageable pageable){
|
||||||
*/
|
|
||||||
@Override
|
}
|
||||||
public ${ClassName} select${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField})
|
|
||||||
{
|
/**
|
||||||
return ${className}Mapper.select${ClassName}ById(${pkColumn.javaField});
|
* 查询${functionName}
|
||||||
}
|
*
|
||||||
|
* @param ${pkColumn.javaField} ${functionName}ID
|
||||||
/**
|
* @return ${functionName}
|
||||||
* 查询${functionName}列表
|
*/
|
||||||
*
|
@Override
|
||||||
* @param ${className} ${functionName}
|
public ${ClassName} select${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField})
|
||||||
* @return ${functionName}
|
{
|
||||||
*/
|
return ${className}Mapper.select${ClassName}ById(${pkColumn.javaField});
|
||||||
@Override
|
}
|
||||||
public List<${ClassName}> select${ClassName}List(${ClassName} ${className})
|
|
||||||
{
|
/**
|
||||||
return ${className}Mapper.select${ClassName}List(${className});
|
* 查询${functionName}列表
|
||||||
}
|
*
|
||||||
|
* @param ${className} ${functionName}
|
||||||
/**
|
* @return ${functionName}
|
||||||
* 新增${functionName}
|
*/
|
||||||
*
|
@Override
|
||||||
* @param ${className} ${functionName}
|
public List<${ClassName}> select${ClassName}List(${ClassName} ${className})
|
||||||
* @return 结果
|
{
|
||||||
*/
|
return ${className}Mapper.select${ClassName}List(${className});
|
||||||
@Override
|
}
|
||||||
public int insert${ClassName}(${ClassName} ${className})
|
|
||||||
{
|
/**
|
||||||
#foreach ($column in $columns)
|
* 新增${functionName}
|
||||||
#if($column.javaField == 'createTime')
|
*
|
||||||
${className}.setCreateTime(DateUtils.getNowDate());
|
* @param ${className} ${functionName}
|
||||||
#end
|
* @return 结果
|
||||||
#end
|
*/
|
||||||
return ${className}Mapper.insert${ClassName}(${className});
|
@Override
|
||||||
}
|
public int insert${ClassName}(${ClassName} ${className})
|
||||||
|
{
|
||||||
/**
|
#foreach ($column in $columns)
|
||||||
* 修改${functionName}
|
#if($column.javaField == 'createTime')
|
||||||
*
|
${className}.setCreateTime(DateUtils.getNowDate());
|
||||||
* @param ${className} ${functionName}
|
#end
|
||||||
* @return 结果
|
#end
|
||||||
*/
|
return ${className}Mapper.insert${ClassName}(${className});
|
||||||
@Override
|
}
|
||||||
public int update${ClassName}(${ClassName} ${className})
|
|
||||||
{
|
/**
|
||||||
#foreach ($column in $columns)
|
* 修改${functionName}
|
||||||
#if($column.javaField == 'updateTime')
|
*
|
||||||
${className}.setUpdateTime(DateUtils.getNowDate());
|
* @param ${className} ${functionName}
|
||||||
#end
|
* @return 结果
|
||||||
#end
|
*/
|
||||||
return ${className}Mapper.update${ClassName}(${className});
|
@Override
|
||||||
}
|
public int update${ClassName}(${ClassName} ${className})
|
||||||
|
{
|
||||||
/**
|
#foreach ($column in $columns)
|
||||||
* 删除${functionName}对象
|
#if($column.javaField == 'updateTime')
|
||||||
*
|
${className}.setUpdateTime(DateUtils.getNowDate());
|
||||||
* @param ids 需要删除的数据ID
|
#end
|
||||||
* @return 结果
|
#end
|
||||||
*/
|
return ${className}Mapper.update${ClassName}(${className});
|
||||||
@Override
|
}
|
||||||
public int delete${ClassName}ByIds(String ids)
|
|
||||||
{
|
/**
|
||||||
return ${className}Mapper.delete${ClassName}ByIds(Convert.toStrArray(ids));
|
* 删除${functionName}对象
|
||||||
}
|
*
|
||||||
|
* @param ids 需要删除的数据ID
|
||||||
/**
|
* @return 结果
|
||||||
* 删除${functionName}信息
|
*/
|
||||||
*
|
@Override
|
||||||
* @param ${pkColumn.javaField} ${functionName}ID
|
public int delete${ClassName}ByIds(String ids)
|
||||||
* @return 结果
|
{
|
||||||
*/
|
return ${className}Mapper.delete${ClassName}ByIds(Convert.toStrArray(ids));
|
||||||
@Override
|
}
|
||||||
public int delete${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField})
|
|
||||||
{
|
/**
|
||||||
return ${className}Mapper.delete${ClassName}ById(${pkColumn.javaField});
|
* 删除${functionName}信息
|
||||||
}
|
*
|
||||||
#if($table.tree)
|
* @param ${pkColumn.javaField} ${functionName}ID
|
||||||
|
* @return 结果
|
||||||
/**
|
*/
|
||||||
* 查询${functionName}树列表
|
@Override
|
||||||
*
|
public int delete${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField})
|
||||||
* @return 所有${functionName}信息
|
{
|
||||||
*/
|
return ${className}Mapper.delete${ClassName}ById(${pkColumn.javaField});
|
||||||
@Override
|
}
|
||||||
public List<Ztree> select${ClassName}Tree()
|
#if($table.tree)
|
||||||
{
|
|
||||||
List<${ClassName}> ${className}List = ${className}Mapper.select${ClassName}List(new ${ClassName}());
|
/**
|
||||||
List<Ztree> ztrees = new ArrayList<Ztree>();
|
* 查询${functionName}树列表
|
||||||
for (${ClassName} ${className} : ${className}List)
|
*
|
||||||
{
|
* @return 所有${functionName}信息
|
||||||
Ztree ztree = new Ztree();
|
*/
|
||||||
#set($TreeCode=$treeCode.substring(0,1).toUpperCase() + ${treeCode.substring(1)})
|
@Override
|
||||||
#set($TreeParentCode=$treeParentCode.substring(0,1).toUpperCase() + ${treeParentCode.substring(1)})
|
public List<Ztree> select${ClassName}Tree()
|
||||||
#set($TreeName=$treeName.substring(0,1).toUpperCase() + ${treeName.substring(1)})
|
{
|
||||||
ztree.setId(${className}.get${TreeCode}());
|
List<${ClassName}> ${className}List = ${className}Mapper.select${ClassName}List(new ${ClassName}());
|
||||||
ztree.setpId(${className}.get${TreeParentCode}());
|
List<Ztree> ztrees = new ArrayList<Ztree>();
|
||||||
ztree.setName(${className}.get${TreeName}());
|
for (${ClassName} ${className} : ${className}List)
|
||||||
ztree.setTitle(${className}.get${TreeName}());
|
{
|
||||||
ztrees.add(ztree);
|
Ztree ztree = new Ztree();
|
||||||
}
|
#set($TreeCode=$treeCode.substring(0,1).toUpperCase() + ${treeCode.substring(1)})
|
||||||
return ztrees;
|
#set($TreeParentCode=$treeParentCode.substring(0,1).toUpperCase() + ${treeParentCode.substring(1)})
|
||||||
}
|
#set($TreeName=$treeName.substring(0,1).toUpperCase() + ${treeName.substring(1)})
|
||||||
#end
|
ztree.setId(${className}.get${TreeCode}());
|
||||||
}
|
ztree.setpId(${className}.get${TreeParentCode}());
|
||||||
|
ztree.setName(${className}.get${TreeName}());
|
||||||
|
ztree.setTitle(${className}.get${TreeName}());
|
||||||
|
ztrees.add(ztree);
|
||||||
|
}
|
||||||
|
return ztrees;
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue