diff --git a/ruoyi-modules/ruoyi-gen/build.gradle b/ruoyi-modules/ruoyi-gen/build.gradle index a48a9d1f..647fc73d 100644 --- a/ruoyi-modules/ruoyi-gen/build.gradle +++ b/ruoyi-modules/ruoyi-gen/build.gradle @@ -38,8 +38,8 @@ dependencies { implementation "org.apache.commons:commons-lang3:3.11" implementation "io.springfox:springfox-swagger-ui:2.9.2" implementation "org.mariadb.jdbc:mariadb-java-client:2.7.1" - implementation "org.mybatis.spring.boot:mybatis-spring-boot-starter:2.1.4" - +// implementation "org.mybatis.spring.boot:mybatis-spring-boot-starter:2.1.4" + implementation 'com.baomidou:mybatis-plus-boot-starter:3.4.1' implementation "com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-config:${alibabaCloud}" implementation "com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-discovery:${alibabaCloud}" implementation "com.alibaba.cloud:spring-cloud-starter-alibaba-sentinel:${alibabaCloud}" diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/VelocityUtils.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/VelocityUtils.java index 7ebd81a1..b080be36 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/VelocityUtils.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/VelocityUtils.java @@ -105,11 +105,18 @@ public class VelocityUtils { */ public static List getTemplateList(String tplCategory) { List templates = new ArrayList(); - templates.add("vm/java/domain.java.vm"); - templates.add("vm/java/mapper.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/domain.java.vm"); +// templates.add("vm/java/mapper.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-plus/domain.java.vm"); + templates.add("vm/java-plus/mapper.java.vm"); + templates.add("vm/java-plus/service.java.vm"); + templates.add("vm/java-plus/serviceImpl.java.vm"); + templates.add("vm/java-plus/controller.java.vm"); + templates.add("vm/xml/mapper.xml.vm"); templates.add("vm/sql/sql.vm"); templates.add("vm/js/api.js.vm"); @@ -143,7 +150,7 @@ public class VelocityUtils { if (template.contains("domain.java.vm")) { fileName = StringUtils.format("{}/domain/{}.java", javaPath, className); } else if (template.contains("mapper.java.vm")) { - fileName = StringUtils.format("{}/mapper/{}Mapper.java", javaPath, className); + fileName = StringUtils.format("{}/dao.mysql/{}Mapper.java", javaPath, className); } else if (template.contains("service.java.vm")) { fileName = StringUtils.format("{}/service/{}Service.java", javaPath, className); } else if (template.contains("serviceImpl.java.vm")) { diff --git a/ruoyi-modules/ruoyi-gen/src/main/resources/mapper/generator/GenTableColumnMapper.xml b/ruoyi-modules/ruoyi-gen/src/main/resources/mapper/generator/GenTableColumnMapper.xml index 83565467..bc52e56b 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/resources/mapper/generator/GenTableColumnMapper.xml +++ b/ruoyi-modules/ruoyi-gen/src/main/resources/mapper/generator/GenTableColumnMapper.xml @@ -1,95 +1,95 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - - + + select column_id, table_id, column_name, column_comment, column_type, java_type, java_field, is_pk, is_increment, is_required, is_insert, is_edit, is_list, is_query, query_type, html_type, dict_type, sort, create_by, create_time, update_by, update_time from gen_table_column - - where table_id = #{tableId} order by sort - + - - + + insert into gen_table_column ( - table_id, - column_name, - column_comment, - column_type, - java_type, - java_field, - is_pk, - is_increment, - is_required, - is_insert, - is_edit, - is_list, - is_query, - query_type, - html_type, - dict_type, - sort, - create_by, - create_time - )values( - #{tableId}, - #{columnName}, - #{columnComment}, - #{columnType}, - #{javaType}, - #{javaField}, - #{isPk}, - #{isIncrement}, - #{isRequired}, - #{isInsert}, - #{isEdit}, - #{isList}, - #{isQuery}, - #{queryType}, - #{htmlType}, - #{dictType}, - #{sort}, - #{createBy}, - sysdate() - ) + table_id, + column_name, + column_comment, + column_type, + java_type, + java_field, + is_pk, + is_increment, + is_required, + is_insert, + is_edit, + is_list, + is_query, + query_type, + html_type, + dict_type, + sort, + create_by, + create_time + )values( + #{tableId}, + #{columnName}, + #{columnComment}, + #{columnType}, + #{javaType}, + #{javaField}, + #{isPk}, + #{isIncrement}, + #{isRequired}, + #{isInsert}, + #{isEdit}, + #{isList}, + #{isQuery}, + #{queryType}, + #{htmlType}, + #{dictType}, + #{sort}, + #{createBy}, + sysdate() + ) - - + + update gen_table_column column_comment = #{columnComment}, @@ -111,14 +111,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - delete from gen_table_column where table_id in + delete from gen_table_column where table_id in #{tableId} - + - delete from gen_table_column where column_id in + delete from gen_table_column where column_id in #{item.columnId} diff --git a/ruoyi-modules/ruoyi-gen/src/main/resources/mapper/generator/GenTableMapper.xml b/ruoyi-modules/ruoyi-gen/src/main/resources/mapper/generator/GenTableMapper.xml index eea10019..a1da62c8 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/resources/mapper/generator/GenTableMapper.xml +++ b/ruoyi-modules/ruoyi-gen/src/main/resources/mapper/generator/GenTableMapper.xml @@ -1,157 +1,156 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + select table_id, table_name, table_comment, class_name, tpl_category, package_name, module_name, business_name, function_name, function_author, gen_type, gen_path, options, create_by, create_time, update_by, update_time, remark from gen_table - - - - - - - + + + + AND lower(table_name) like lower(concat('%', #{tableName}, '%')) + + + AND lower(table_comment) like lower(concat('%', #{tableComment}, '%')) + + + AND date_format(create_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d') + + + AND date_format(create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d') + + + + + + + + + - - SELECT t.table_id, t.table_name, t.table_comment, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark, c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort FROM gen_table t LEFT JOIN gen_table_column c ON t.table_id = c.table_id where t.table_id = #{tableId} order by c.sort - - SELECT t.table_id, t.table_name, t.table_comment, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark, c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort FROM gen_table t LEFT JOIN gen_table_column c ON t.table_id = c.table_id where t.table_name = #{tableName} order by c.sort - - + + insert into gen_table ( - table_name, - table_comment, - class_name, - tpl_category, - package_name, - module_name, - business_name, - function_name, - function_author, - gen_type, - gen_path, - remark, - create_by, - create_time - )values( - #{tableName}, - #{tableComment}, - #{className}, - #{tplCategory}, - #{packageName}, - #{moduleName}, - #{businessName}, - #{functionName}, - #{functionAuthor}, - #{genType}, - #{genPath}, - #{remark}, - #{createBy}, - sysdate() - ) + table_name, + table_comment, + class_name, + tpl_category, + package_name, + module_name, + business_name, + function_name, + function_author, + gen_type, + gen_path, + remark, + create_by, + create_time + )values( + #{tableName}, + #{tableComment}, + #{className}, + #{tplCategory}, + #{packageName}, + #{moduleName}, + #{businessName}, + #{functionName}, + #{functionAuthor}, + #{genType}, + #{genPath}, + #{remark}, + #{createBy}, + sysdate() + ) - - + + update gen_table table_name = #{tableName}, @@ -172,9 +171,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where table_id = #{tableId} - + - delete from gen_table where table_id in + delete from gen_table where table_id in #{tableId} diff --git a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java-plus/controller.java.vm b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java-plus/controller.java.vm new file mode 100644 index 00000000..255a9d0d --- /dev/null +++ b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java-plus/controller.java.vm @@ -0,0 +1,119 @@ +package ${packageName}.controller; + +import java.util.List; +import java.util.Set; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.DeleteMapping; +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.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; +import com.ruoyi.common.log.annotation.Log; +import com.ruoyi.common.log.enums.BusinessType; +import com.ruoyi.common.security.annotation.PreAuthorize; +import ${packageName}.domain.${ClassName}; +import ${packageName}.service.${ClassName}Service; +import com.ruoyi.common.core.web.controller.BaseController; +import com.ruoyi.common.core.web.domain.AjaxResult; +import com.ruoyi.common.core.utils.poi.ExcelUtil; +#if($table.crud) +import com.ruoyi.common.core.web.page.TableDataInfo; +#elseif($table.tree) +#end + +/** + * ${functionName}Controller + * + * @author ${author} + * @date ${datetime} + */ +@RestController +@RequestMapping("/${businessName}") +public class ${ClassName}Controller extends BaseController +{ + @Autowired + private ${ClassName}Service ${className}Service; + + /** + * 查询${functionName}列表 + */ + @PreAuthorize(hasPermi = "${permissionPrefix}:list") + @GetMapping("/list") +#if($table.crud) + public TableDataInfo list(${ClassName} ${className}) + { + startPage(); + List<${ClassName}> list = ${className}Service.list(new QueryWrapper<>(${className})); + return getDataTable(list); + } +#elseif($table.tree) + public AjaxResult list(${ClassName} ${className}) + { + List<${ClassName}> list = ${className}Service.list(new QueryWrapper<>(${className})); + return AjaxResult.success(list); + } +#end + + /** + * 导出${functionName}列表 + */ + @PreAuthorize(hasPermi = "${permissionPrefix}:export") + @Log(title = "${functionName}", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, ${ClassName} ${className}) throws IOException + { + List<${ClassName}> list = ${className}Service.list(new QueryWrapper<>(${className})); + ExcelUtil<${ClassName}> util = new ExcelUtil<${ClassName}>(${ClassName}.class); + util.exportExcel(response, list, "${businessName}"); + } + + /** + * 获取${functionName}详细信息 + */ + @PreAuthorize(hasPermi = "${permissionPrefix}:query") + @GetMapping(value = "/{${pkColumn.javaField}}") + public AjaxResult getInfo(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField}) + { + return AjaxResult.success(${className}Service.getById(${pkColumn.javaField})); + } + + /** + * 新增${functionName} + */ + @PreAuthorize(hasPermi = "${permissionPrefix}:add") + @Log(title = "${functionName}", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody ${ClassName} ${className}) + { + return toAjax(${className}Service.save(${className}) ? 1 : 0); + } + + /** + * 修改${functionName} + */ + @PreAuthorize(hasPermi = "${permissionPrefix}:edit") + @Log(title = "${functionName}", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody ${ClassName} ${className}) + { + return toAjax(${className}Service.update(new UpdateWrapper(${className})) ? 1 : 0); + } + + /** + * 删除${functionName} + */ + @PreAuthorize(hasPermi = "${permissionPrefix}:remove") + @Log(title = "${functionName}", businessType = BusinessType.DELETE) + @DeleteMapping("/{${pkColumn.javaField}s}") + public AjaxResult remove(@PathVariable ${pkColumn.javaType}[] ${pkColumn.javaField}s) + { + return toAjax(${className}Service.removeByIds(Set.of(${pkColumn.javaField}s)) ? ${pkColumn.javaField}s.length : 0); + } +} diff --git a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java-plus/domain.java.vm b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java-plus/domain.java.vm new file mode 100644 index 00000000..d386b64d --- /dev/null +++ b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java-plus/domain.java.vm @@ -0,0 +1,58 @@ +package ${packageName}.domain; + +#foreach ($import in $importList) +import ${import}; +#end +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.ruoyi.common.core.annotation.Excel; +#if($table.crud) +import com.ruoyi.common.core.web.domain.BaseEntity; +#elseif($table.tree) +import com.ruoyi.common.core.web.domain.TreeEntity; +#end +import lombok.Data; +import lombok.Builder; +import com.baomidou.mybatisplus.annotation.TableName; +/** + * ${functionName}对象 ${tableName} + * + * @author ${author} + * @date ${datetime} + */ +#if($table.crud) +#set($Entity="BaseEntity") +#elseif($table.tree) +#set($Entity="TreeEntity") +#end +@Data +@Builder +@TableName("${tableName}") +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') + @JsonFormat(pattern = "yyyy-MM-dd") + @Excel(name = "${comment}", width = 30, dateFormat = "yyyy-MM-dd") +#else + @Excel(name = "${comment}") +#end +#end + private $column.javaType $column.javaField; + +#end +#end +} \ No newline at end of file diff --git a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java-plus/mapper.java.vm b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java-plus/mapper.java.vm new file mode 100644 index 00000000..907a3286 --- /dev/null +++ b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java-plus/mapper.java.vm @@ -0,0 +1,14 @@ +package ${packageName}.dao.mysql; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import ${packageName}.domain.${ClassName}; + +/** + * ${functionName}Mapper接口 + * + * @author ${author} + * @date ${datetime} + */ +public interface ${ClassName}Mapper extends BaseMapper<${ClassName}> { + +} diff --git a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java-plus/service.java.vm b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java-plus/service.java.vm new file mode 100644 index 00000000..310f472e --- /dev/null +++ b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java-plus/service.java.vm @@ -0,0 +1,13 @@ +package ${packageName}.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import ${packageName}.domain.${ClassName}; +/** + * ${functionName}Service接口 + * + * @author ${author} + * @date ${datetime} + */ +public interface ${ClassName}Service extends IService<${ClassName}> { + +} diff --git a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java-plus/serviceImpl.java.vm b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java-plus/serviceImpl.java.vm new file mode 100644 index 00000000..e7a57298 --- /dev/null +++ b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java-plus/serviceImpl.java.vm @@ -0,0 +1,27 @@ +package ${packageName}.service.impl; + +import java.util.List; +#foreach ($column in $columns) +#if($column.javaField == 'createTime' || $column.javaField == 'updateTime') +import com.ruoyi.common.core.utils.DateUtils; +#break +#end +#end +import org.springframework.beans.factory.annotation.Autowired; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; +import ${packageName}.dao.mysql.${ClassName}Mapper; +import ${packageName}.domain.${ClassName}; +import ${packageName}.service.${ClassName}Service; + +/** + * ${functionName}Service业务层处理 + * + * @author ${author} + * @date ${datetime} + */ +@Service("${moduleName}${ClassName}Service") +public class ${ClassName}ServiceImpl extends ServiceImpl<${ClassName}Mapper, ${ClassName}> implements ${ClassName}Service { + + +}