diff --git a/ruoyi-admin/src/main/resources/static/ruoyi/js/common.js b/ruoyi-admin/src/main/resources/static/ruoyi/js/common.js index 273a64d1e..845d77e71 100644 --- a/ruoyi-admin/src/main/resources/static/ruoyi/js/common.js +++ b/ruoyi-admin/src/main/resources/static/ruoyi/js/common.js @@ -308,7 +308,7 @@ function createMenuItem(dataUrl, menuName) { return false; } -//日志打印封装处理 +// 日志打印封装处理 var log = { log: function(msg) { console.log(msg); @@ -324,7 +324,7 @@ var log = { } }; -//本地缓存处理 +// 本地缓存处理 var storage = { set: function(key, value) { window.localStorage.setItem(key, value); @@ -340,6 +340,52 @@ var storage = { } }; +// 主子表操作封装处理 +var sub = { + editColumn: function() { + var count = $("#" + table.options.id).bootstrapTable('getData').length; + var params = new Array(); + for (var dataIndex = 0; dataIndex <= count; dataIndex++) { + var columns = $('#' + table.options.id + ' tr[data-index="' + dataIndex + '"] td'); + var obj = new Object(); + for (var i = 0; i < columns.length; i++) { + var inputValue = $(columns[i]).find('input'); + var selectValue = $(columns[i]).find('select'); + var key = table.options.columns[i].field; + if ($.common.isNotEmpty(inputValue.val())) { + obj[key] = inputValue.val(); + } else if ($.common.isNotEmpty(selectValue.val())) { + obj[key] = selectValue.val(); + } else { + obj[key] = ""; + } + } + params.push({ index: dataIndex, row: obj }); + } + $("#" + table.options.id).bootstrapTable("updateRow", params); + }, + delColumn: function(column) { + var subColumn = $.common.isEmpty(column) ? "index" : column; + var ids = $.table.selectColumns(subColumn); + if (ids.length == 0) { + $.modal.alertWarning("请至少选择一条记录"); + return; + } + $("#" + table.options.id).bootstrapTable('remove', { field: subColumn, values: ids }); + if($.common.equals("index", subColumn)) + { + sub.resetIndex(); + } + }, + resetIndex: function(msg) { + var count = $("#" + table.options.id).bootstrapTable('getData').length; + for (var index = 0; index <= count; index++) { + // 重置序号 + $("#" + table.options.id).bootstrapTable('updateRow', { index: index, row: { index: parseInt(index + 1) } }) + } + } +}; + /** 设置全局ajax处理 */ $.ajaxSetup({ complete: function(XMLHttpRequest, textStatus) { diff --git a/ruoyi-admin/src/main/resources/static/ruoyi/js/ry-ui.js b/ruoyi-admin/src/main/resources/static/ruoyi/js/ry-ui.js index 49087ee58..1195d074f 100644 --- a/ruoyi-admin/src/main/resources/static/ruoyi/js/ry-ui.js +++ b/ruoyi-admin/src/main/resources/static/ruoyi/js/ry-ui.js @@ -1523,6 +1523,20 @@ var table = { }); return json; }, + // 数据字典转下拉框 + dictToSelect: function(datas, value, name) { + var actions = []; + actions.push($.common.sprintf("'); + return actions.join(''); + }, // 获取obj对象长度 getLength: function(obj) { var count = 0;   diff --git a/ruoyi-admin/src/main/resources/templates/demo/table/subdata.html b/ruoyi-admin/src/main/resources/templates/demo/table/subdata.html index ba30bfc9c..519adf6fe 100644 --- a/ruoyi-admin/src/main/resources/templates/demo/table/subdata.html +++ b/ruoyi-admin/src/main/resources/templates/demo/table/subdata.html @@ -63,8 +63,8 @@

商品数据

- - + +
@@ -150,28 +150,9 @@ autoclose: true }); - function addColumn(){ + function addColumn() { var count = $("#" + table.options.id).bootstrapTable('getData').length; - - var params = new Array(); - for (var dataIndex = 0; dataIndex <= count; dataIndex++) { - var columns = $('#' + table.options.id + ' tr[data-index="' + dataIndex + '"] td'); - var obj = new Object(); - for (var i = 0; i < columns.length; i++) { - var inputValue = $(columns[i]).find('input'); - var selectValue = $(columns[i]).find('select'); - var key = table.options.columns[i].field; - if ($.common.isNotEmpty(inputValue.val())) { - obj[key] = inputValue.val(); - } else if ($.common.isNotEmpty(selectValue.val())) { - obj[key] = selectValue.val(); - } else { - obj[key] = ""; - } - } - params.push({ index: dataIndex, row: obj }); - } - $("#" + table.options.id).bootstrapTable("updateRow", params); + sub.editColumn(); $("#" + table.options.id).bootstrapTable('insertRow', { index: count, @@ -182,35 +163,14 @@ price: "", type: "", } - }) - resetIndex(); - } - - function delColumn(){ - var ids = $.table.selectColumns("index"); - if (ids.length == 0) { - $.modal.alertWarning("请至少选择一条记录"); - return; - } - $("#" + table.options.id).bootstrapTable('remove', { - field: 'index', - values: ids - }) - resetIndex(); - } - - function resetIndex() { - var count = $("#" + table.options.id).bootstrapTable('getData').length; - for (var index = 0; index <= count; index++) { - // 重置序号 - $("#" + table.options.id).bootstrapTable('updateRow', { index: index, row: { index: parseInt(index + 1) } }) - } + }); + sub.resetIndex(); } - + - diff --git a/ruoyi-generator/src/main/resources/vm/html/edit.html.vm b/ruoyi-generator/src/main/resources/vm/html/edit.html.vm index f7b371736..60a24e99b 100644 --- a/ruoyi-generator/src/main/resources/vm/html/edit.html.vm +++ b/ruoyi-generator/src/main/resources/vm/html/edit.html.vm @@ -12,6 +12,9 @@
+#if($table.sub) +

${functionName}信息

+#end #foreach($column in $columns) #if($column.edit && !$column.pk) @@ -103,6 +106,18 @@ #end #end #end +#end +#if($table.sub) +

${subTable.functionName}信息

+
+
+ + +
+
+
+
+
#end
@@ -113,8 +128,15 @@ #break #end #end - diff --git a/ruoyi-generator/src/main/resources/vm/html/list-tree.html.vm b/ruoyi-generator/src/main/resources/vm/html/list-tree.html.vm index b0e736d9f..6def5ffae 100644 --- a/ruoyi-generator/src/main/resources/vm/html/list-tree.html.vm +++ b/ruoyi-generator/src/main/resources/vm/html/list-tree.html.vm @@ -101,7 +101,7 @@ exportUrl: prefix + "/export", modalName: "${functionName}", columns: [{ - field: 'selectItem', + field: 'selectItem', radio: true }, #foreach($column in $columns) @@ -116,7 +116,7 @@ #if($column.pk) #elseif($column.list && "" != $dictType) { - field: '${javaField}', + field: '${javaField}', title: '${comment}', align: 'left', formatter: function(value, row, index) { @@ -125,7 +125,7 @@ }, #elseif($column.list && "" != $javaField) { - field: '${javaField}', + field: '${javaField}', title: '${comment}', align: 'left' }, diff --git a/ruoyi-generator/src/main/resources/vm/html/list.html.vm b/ruoyi-generator/src/main/resources/vm/html/list.html.vm index 692cb38bf..252b983bc 100644 --- a/ruoyi-generator/src/main/resources/vm/html/list.html.vm +++ b/ruoyi-generator/src/main/resources/vm/html/list.html.vm @@ -112,13 +112,13 @@ #end #if($column.pk) { - field: '${javaField}', + field: '${javaField}', title: '${comment}', visible: false }, #elseif($column.list && "" != $dictType) { - field: '${javaField}', + field: '${javaField}', title: '${comment}', formatter: function(value, row, index) { return $.table.selectDictLabel(${javaField}Datas, value); @@ -126,7 +126,7 @@ }, #elseif($column.list && "" != $javaField) { - field: '${javaField}', + field: '${javaField}', title: '${comment}' }, #end diff --git a/ruoyi-generator/src/main/resources/vm/java/controller.java.vm b/ruoyi-generator/src/main/resources/vm/java/controller.java.vm index 7b4bf470b..c5caa7724 100644 --- a/ruoyi-generator/src/main/resources/vm/java/controller.java.vm +++ b/ruoyi-generator/src/main/resources/vm/java/controller.java.vm @@ -17,7 +17,7 @@ import ${packageName}.service.I${ClassName}Service; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.utils.poi.ExcelUtil; -#if($table.crud) +#if($table.crud || $table.sub) import com.ruoyi.common.core.page.TableDataInfo; #elseif($table.tree) import com.ruoyi.common.utils.StringUtils; @@ -46,7 +46,7 @@ public class ${ClassName}Controller extends BaseController return prefix + "/${businessName}"; } -#if($table.crud) +#if($table.crud || $table.sub) /** * 查询${functionName}列表 */ @@ -87,7 +87,7 @@ public class ${ClassName}Controller extends BaseController return util.exportExcel(list, "${businessName}"); } -#if($table.crud) +#if($table.crud || $table.sub) /** * 新增${functionName} */ @@ -146,7 +146,7 @@ public class ${ClassName}Controller extends BaseController return toAjax(${className}Service.update${ClassName}(${className})); } -#if($table.crud) +#if($table.crud || $table.sub) /** * 删除${functionName} */ diff --git a/ruoyi-generator/src/main/resources/vm/java/domain.java.vm b/ruoyi-generator/src/main/resources/vm/java/domain.java.vm index 76e51b030..a9d18f097 100644 --- a/ruoyi-generator/src/main/resources/vm/java/domain.java.vm +++ b/ruoyi-generator/src/main/resources/vm/java/domain.java.vm @@ -6,7 +6,7 @@ import ${import}; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; import com.ruoyi.common.annotation.Excel; -#if($table.crud) +#if($table.crud || $table.sub) import com.ruoyi.common.core.domain.BaseEntity; #elseif($table.tree) import com.ruoyi.common.core.domain.TreeEntity; @@ -18,7 +18,7 @@ import com.ruoyi.common.core.domain.TreeEntity; * @author ${author} * @date ${datetime} */ -#if($table.crud) +#if($table.crud || $table.sub) #set($Entity="BaseEntity") #elseif($table.tree) #set($Entity="TreeEntity") @@ -48,6 +48,11 @@ public class ${ClassName} extends ${Entity} private $column.javaType $column.javaField; #end +#end +#if($table.sub) + /** $table.subTable.functionName信息 */ + private List<${subClassName}> ${subclassName}List; + #end #foreach ($column in $columns) #if(!$table.isSuperColumn($column.javaField)) @@ -68,6 +73,18 @@ public class ${ClassName} extends ${Entity} #end #end +#if($table.sub) + public List<${subClassName}> get${subClassName}List() + { + return ${subclassName}List; + } + + public void set${subClassName}List(List<${subClassName}> ${subclassName}List) + { + this.${subclassName}List = ${subclassName}List; + } + +#end @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) @@ -78,6 +95,9 @@ public class ${ClassName} extends ${Entity} #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) #end .append("${column.javaField}", get${AttrName}()) +#end +#if($table.sub) + .append("${subclassName}List", get${subClassName}List()) #end .toString(); } diff --git a/ruoyi-generator/src/main/resources/vm/java/mapper.java.vm b/ruoyi-generator/src/main/resources/vm/java/mapper.java.vm index 6e20c516a..d25ec18cb 100644 --- a/ruoyi-generator/src/main/resources/vm/java/mapper.java.vm +++ b/ruoyi-generator/src/main/resources/vm/java/mapper.java.vm @@ -2,6 +2,9 @@ package ${packageName}.mapper; import java.util.List; import ${packageName}.domain.${ClassName}; +#if($table.sub) +import ${packageName}.domain.${subClassName}; +#end /** * ${functionName}Mapper接口 @@ -58,4 +61,31 @@ public interface ${ClassName}Mapper * @return 结果 */ public int delete${ClassName}ByIds(String[] ${pkColumn.javaField}s); +#if($table.sub) + + /** + * 批量删除${subTable.functionName} + * + * @param customerIds 需要删除的数据ID + * @return 结果 + */ + public int delete${subClassName}By${subTableFkClassName}s(String[] ${pkColumn.javaField}s); + + /** + * 批量新增${subTable.functionName} + * + * @param ${subclassName}List ${subTable.functionName}列表 + * @return 结果 + */ + public int batch${subClassName}(List<${subClassName}> ${subclassName}List); + + + /** + * 通过${functionName}ID删除${subTable.functionName}信息 + * + * @param roleId 角色ID + * @return 结果 + */ + public int delete${subClassName}By${subTableFkClassName}(${pkColumn.javaType} ${pkColumn.javaField}); +#end } diff --git a/ruoyi-generator/src/main/resources/vm/java/serviceImpl.java.vm b/ruoyi-generator/src/main/resources/vm/java/serviceImpl.java.vm index bbeb4de89..4592abce8 100644 --- a/ruoyi-generator/src/main/resources/vm/java/serviceImpl.java.vm +++ b/ruoyi-generator/src/main/resources/vm/java/serviceImpl.java.vm @@ -13,6 +13,12 @@ import com.ruoyi.common.utils.DateUtils; #end import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +#if($table.sub) +import java.util.ArrayList; +import com.ruoyi.common.utils.StringUtils; +import org.springframework.transaction.annotation.Transactional; +import ${packageName}.domain.${subClassName}; +#end import ${packageName}.mapper.${ClassName}Mapper; import ${packageName}.domain.${ClassName}; import ${packageName}.service.I${ClassName}Service; @@ -60,6 +66,9 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service * @param ${className} ${functionName} * @return 结果 */ +#if($table.sub) + @Transactional +#end @Override public int insert${ClassName}(${ClassName} ${className}) { @@ -68,7 +77,13 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service ${className}.setCreateTime(DateUtils.getNowDate()); #end #end +#if($table.sub) + int rows = ${className}Mapper.insert${ClassName}(${className}); + insert${subClassName}(${className}); + return rows; +#else return ${className}Mapper.insert${ClassName}(${className}); +#end } /** @@ -77,6 +92,9 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service * @param ${className} ${functionName} * @return 结果 */ +#if($table.sub) + @Transactional +#end @Override public int update${ClassName}(${ClassName} ${className}) { @@ -84,6 +102,10 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service #if($column.javaField == 'updateTime') ${className}.setUpdateTime(DateUtils.getNowDate()); #end +#end +#if($table.sub) + ${className}Mapper.delete${subClassName}By${subTableFkClassName}(${className}.get${pkColumn.capJavaField}()); + insert${subClassName}(${className}); #end return ${className}Mapper.update${ClassName}(${className}); } @@ -94,9 +116,15 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service * @param ids 需要删除的数据ID * @return 结果 */ +#if($table.sub) + @Transactional +#end @Override public int delete${ClassName}ByIds(String ids) { +#if($table.sub) + ${className}Mapper.delete${subClassName}By${subTableFkClassName}s(Convert.toStrArray(ids)); +#end return ${className}Mapper.delete${ClassName}ByIds(Convert.toStrArray(ids)); } @@ -109,6 +137,9 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service @Override public int delete${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField}) { +#if($table.sub) + ${className}Mapper.delete${subClassName}By${subTableFkClassName}(${pkColumn.javaField}); +#end return ${className}Mapper.delete${ClassName}ById(${pkColumn.javaField}); } #if($table.tree) @@ -138,4 +169,30 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service return ztrees; } #end +#if($table.sub) + + /** + * 新增${subTable.functionName}信息 + * + * @param ${className} ${functionName}对象 + */ + public void insert${subClassName}(${ClassName} ${className}) + { + List<${subClassName}> ${subclassName}List = ${className}.get${subClassName}List(); + Long ${pkColumn.javaField} = ${className}.get${pkColumn.capJavaField}(); + if (StringUtils.isNotNull(${subclassName}List)) + { + List<${subClassName}> list = new ArrayList<${subClassName}>(); + for (${subClassName} ${subclassName} : ${subclassName}List) + { + ${subclassName}.set${pkColumn.capJavaField}(${pkColumn.javaField}); + list.add(${subclassName}); + } + if (list.size() > 0) + { + ${className}Mapper.batch${subClassName}(list); + } + } + } +#end } diff --git a/ruoyi-generator/src/main/resources/vm/java/sub-domain.java.vm b/ruoyi-generator/src/main/resources/vm/java/sub-domain.java.vm new file mode 100644 index 000000000..3539474cc --- /dev/null +++ b/ruoyi-generator/src/main/resources/vm/java/sub-domain.java.vm @@ -0,0 +1,75 @@ +package ${packageName}.domain; + +#foreach ($import in $subImportList) +import ${import}; +#end +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.core.domain.BaseEntity; + +/** + * ${subTable.functionName}对象 ${subTableName} + * + * @author ${author} + * @date ${datetime} + */ +public class ${subClassName} extends BaseEntity +{ + private static final long serialVersionUID = 1L; + +#foreach ($column in $subTable.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 $subTable.columns) +#if(!$table.isSuperColumn($column.javaField)) +#if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]")) +#set($AttrName=$column.javaField) +#else +#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) +#end + public void set${AttrName}($column.javaType $column.javaField) + { + this.$column.javaField = $column.javaField; + } + + public $column.javaType get${AttrName}() + { + return $column.javaField; + } +#end +#end + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) +#foreach ($column in $subTable.columns) +#if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]")) +#set($AttrName=$column.javaField) +#else +#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) +#end + .append("${column.javaField}", get${AttrName}()) +#end + .toString(); + } +} diff --git a/ruoyi-generator/src/main/resources/vm/xml/mapper.xml.vm b/ruoyi-generator/src/main/resources/vm/xml/mapper.xml.vm index 9729df1ef..9e96159a3 100644 --- a/ruoyi-generator/src/main/resources/vm/xml/mapper.xml.vm +++ b/ruoyi-generator/src/main/resources/vm/xml/mapper.xml.vm @@ -12,6 +12,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #end +#if($table.sub) + + + + + + +#foreach ($column in $subTable.columns) + +#end + +#end select#foreach($column in $columns) $column.columnName#if($velocityCount != $columns.size()),#end#end from ${tableName} @@ -52,7 +64,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #end - #if($table.crud) where ${pkColumn.columnName} = #{${pkColumn.javaField}} @@ -61,6 +73,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" from ${tableName} t left join ${tableName} p on p.${pkColumn.columnName} = t.${tree_parent_code} where t.${pkColumn.columnName} = #{${pkColumn.javaField}} +#elseif($table.sub) + select#foreach($column in $columns) a.$column.columnName#if($velocityCount != $columns.size()),#end#end, + #foreach($column in $subTable.columns) b.$column.columnName#if($velocityCount != $subTable.columns.size()),#end#end + + from ${tableName} a + left join ${subTableName} b on b.${subTableFkName} = a.${pkColumn.columnName} + where a.${pkColumn.columnName} = #{${pkColumn.javaField}} #end @@ -104,5 +123,25 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{${pkColumn.javaField}} +#if($table.sub) + + delete from ${subTableName} where ${subTableFkName} in + + #{${subTableFkclassName}} + + + + + delete from ${subTableName} where ${subTableFkName} = #{${subTableFkclassName}} + + + + insert into ${subTableName}(#foreach($column in $subTable.columns) $column.columnName#if($velocityCount != $columns.size()),#end#end) values + + (#foreach($column in $subTable.columns) #{item.$column.javaField}#if($velocityCount != $columns.size()),#end#end) + + +#end + \ No newline at end of file diff --git a/sql/ry_20200604.sql b/sql/ry_20200617.sql similarity index 97% rename from sql/ry_20200604.sql rename to sql/ry_20200617.sql index 75e0175d5..1548410c9 100644 --- a/sql/ry_20200604.sql +++ b/sql/ry_20200617.sql @@ -648,22 +648,24 @@ insert into sys_notice values('2', '维护通知:2018-07-01 若依系统凌晨 -- ---------------------------- drop table if exists gen_table; create table gen_table ( - table_id bigint(20) not null auto_increment comment '编号', - table_name varchar(200) default '' comment '表名称', - table_comment varchar(500) default '' comment '表描述', - class_name varchar(100) default '' comment '实体类名称', - tpl_category varchar(200) default 'crud' comment '使用的模板(crud单表操作 tree树表操作)', - package_name varchar(100) comment '生成包路径', - module_name varchar(30) comment '生成模块名', - business_name varchar(30) comment '生成业务名', - function_name varchar(50) comment '生成功能名', - function_author varchar(50) comment '生成功能作者', - options varchar(1000) comment '其它生成选项', - create_by varchar(64) default '' comment '创建者', - create_time datetime comment '创建时间', - update_by varchar(64) default '' comment '更新者', - update_time datetime comment '更新时间', - remark varchar(500) default null comment '备注', + table_id bigint(20) not null auto_increment comment '编号', + table_name varchar(200) default '' comment '表名称', + table_comment varchar(500) default '' comment '表描述', + sub_table_name varchar(64) default null comment '关联父表的表名', + sub_table_fk_name varchar(64) default null comment '本表关联父表的外键名', + class_name varchar(100) default '' comment '实体类名称', + tpl_category varchar(200) default 'crud' comment '使用的模板(crud单表操作 tree树表操作 sub主子表操作)', + package_name varchar(100) comment '生成包路径', + module_name varchar(30) comment '生成模块名', + business_name varchar(30) comment '生成业务名', + function_name varchar(50) comment '生成功能名', + function_author varchar(50) comment '生成功能作者', + options varchar(1000) comment '其它生成选项', + create_by varchar(64) default '' comment '创建者', + create_time datetime comment '创建时间', + update_by varchar(64) default '' comment '更新者', + update_time datetime comment '更新时间', + remark varchar(500) default null comment '备注', primary key (table_id) ) engine=innodb auto_increment=1 comment = '代码生成业务表';