多变关联查询
This commit is contained in:
parent
aaf933d5ca
commit
14453f2c10
|
|
@ -210,7 +210,7 @@ export default {
|
||||||
const relTables = this.$refs.genInfo.relTables;
|
const relTables = this.$refs.genInfo.relTables;
|
||||||
console.log(relTables)
|
console.log(relTables)
|
||||||
for (let i=0;i<relTables.length;i++){
|
for (let i=0;i<relTables.length;i++){
|
||||||
if (relTables[i].unionId===null){
|
if (relTables[i].tableName===null){
|
||||||
Message({
|
Message({
|
||||||
message: "关联父表不能为空!",
|
message: "关联父表不能为空!",
|
||||||
type: 'error'
|
type: 'error'
|
||||||
|
|
@ -240,7 +240,7 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let assColumns = null;
|
let assColumns = null;
|
||||||
if (assCloumnTable!=undefined){
|
if (assCloumnTable!==undefined){
|
||||||
assColumns = assCloumnTable.data
|
assColumns = assCloumnTable.data
|
||||||
}
|
}
|
||||||
Promise.all([basicForm, genForm].map(this.getFormPromise)).then(res => {
|
Promise.all([basicForm, genForm].map(this.getFormPromise)).then(res => {
|
||||||
|
|
|
||||||
|
|
@ -396,13 +396,13 @@
|
||||||
<i class="el-icon-question"></i>
|
<i class="el-icon-question"></i>
|
||||||
</el-tooltip>
|
</el-tooltip>
|
||||||
</span>
|
</span>
|
||||||
<el-select v-model="table.tableIndex" @change="tableChange(table.tableIndex,index)"
|
<el-select v-model="table.tableName" @change="tableChange(table.tableName,index)"
|
||||||
placeholder="请选择关联主表">
|
placeholder="请选择关联主表">
|
||||||
<el-option
|
<el-option
|
||||||
v-for="(item , num) in tableList"
|
v-for="(item , index) in tableList"
|
||||||
:key="num"
|
:key="index"
|
||||||
:label="item.tableName"
|
:label="item.tableName"
|
||||||
:value="num"
|
:value="item.tableName"
|
||||||
/>
|
/>
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
@ -636,37 +636,18 @@ export default {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
|
this.relTables = []
|
||||||
this.tableId = this.$route.params && this.$route.params.tableId;
|
this.tableId = this.$route.params && this.$route.params.tableId;
|
||||||
getTableInfos().then(res => {
|
getTableInfos().then(res => {
|
||||||
this.tableInfo = res.data
|
this.tableInfo = res.data
|
||||||
})
|
})
|
||||||
},
|
getRelColumnInfos(this.tableId).then(res => {
|
||||||
watch: {
|
|
||||||
'info.subTableName': function (val) {
|
|
||||||
this.setSubTableColumns(val);
|
|
||||||
},
|
|
||||||
'info': function (val) {
|
|
||||||
if (val.tplCategory === 'ass') {
|
|
||||||
getAssColumnsByTableId(this.tableId).then(res => {
|
|
||||||
this.assCloumns = res.data
|
|
||||||
})
|
|
||||||
} else if (val.tplCategory === 'rel') {
|
|
||||||
this.tableList = []
|
|
||||||
let table = {
|
|
||||||
tableName: val.tableName,
|
|
||||||
unionId: this.tableId,
|
|
||||||
isMain: 1,
|
|
||||||
}
|
|
||||||
this.tableList.push(table)
|
|
||||||
getRelColumnInfos(val.tableId).then(res => {
|
|
||||||
this.relTables = []
|
|
||||||
if (res.data.length === 0) {
|
if (res.data.length === 0) {
|
||||||
getRelId().then(res => {
|
getRelId().then(res => {
|
||||||
let relTable = {
|
let relTable = {
|
||||||
id: res.data,
|
id: res.data,
|
||||||
unionId: null,
|
|
||||||
tableId: this.tableId,
|
tableId: this.tableId,
|
||||||
isMain: 2,
|
tableName:null,
|
||||||
relName: null,
|
relName: null,
|
||||||
relComment: null,
|
relComment: null,
|
||||||
relColumn: null,
|
relColumn: null,
|
||||||
|
|
@ -683,28 +664,40 @@ export default {
|
||||||
for (let i=0;i<data.length;i++){
|
for (let i=0;i<data.length;i++){
|
||||||
let table = {
|
let table = {
|
||||||
tableName: data[i].relName,
|
tableName: data[i].relName,
|
||||||
unionId: data[i].id,
|
|
||||||
isMain: 1,
|
|
||||||
}
|
}
|
||||||
|
getTableColumns(data[i].tableName).then(res => {
|
||||||
|
data[i].tableColumns = res.data
|
||||||
|
})
|
||||||
this.tableList.push(table)
|
this.tableList.push(table)
|
||||||
}
|
}
|
||||||
this.relTables=res.data
|
this.relTables=data
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
'info.subTableName': function (val) {
|
||||||
|
this.setSubTableColumns(val);
|
||||||
|
},
|
||||||
|
'info': function (val) {
|
||||||
|
if (val.tplCategory === 'ass') {
|
||||||
|
getAssColumnsByTableId(this.tableId).then(res => {
|
||||||
|
this.assCloumns = res.data
|
||||||
|
})
|
||||||
|
} else if (val.tplCategory === 'rel') {
|
||||||
|
let table = {
|
||||||
|
tableName: val.tableName
|
||||||
|
}
|
||||||
|
this.tableList.unshift(table)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
/** 关联父表改变 */
|
/** 关联父表改变 */
|
||||||
tableChange(num, index) {
|
tableChange(tableName, index) {
|
||||||
this.relTables[index].unionId = this.tableList[num].unionId
|
|
||||||
this.relTables[index].isMain = this.tableList[num].isMain
|
|
||||||
let tableName = this.tableList[num].tableName
|
|
||||||
getTableColumns(tableName).then(res => {
|
getTableColumns(tableName).then(res => {
|
||||||
this.relTables[index].tableColumns = res.data
|
this.relTables[index].tableColumns = res.data
|
||||||
})
|
})
|
||||||
console.log(this.relTables)
|
|
||||||
},
|
},
|
||||||
/** 删除关子联表 */
|
/** 删除关子联表 */
|
||||||
removeRelTable(index) {
|
removeRelTable(index) {
|
||||||
|
|
@ -716,8 +709,6 @@ export default {
|
||||||
getRelColumns(relName, this.relTables[index].id).then(res => {
|
getRelColumns(relName, this.relTables[index].id).then(res => {
|
||||||
let table = {
|
let table = {
|
||||||
tableName: relName,
|
tableName: relName,
|
||||||
unionId: this.relTables[index].id,
|
|
||||||
isMain: 2,
|
|
||||||
}
|
}
|
||||||
this.tableList.push(table)
|
this.tableList.push(table)
|
||||||
for (let i = 0; i < this.tableInfo.length; i++) {
|
for (let i = 0; i < this.tableInfo.length; i++) {
|
||||||
|
|
@ -734,10 +725,8 @@ export default {
|
||||||
getRelId().then(res => {
|
getRelId().then(res => {
|
||||||
let relTable = {
|
let relTable = {
|
||||||
id: res.data,
|
id: res.data,
|
||||||
unionId: this.tableId,
|
|
||||||
tableId: this.tableId,
|
tableId: this.tableId,
|
||||||
isMain: 1,
|
tableName:null,
|
||||||
tableIndex: null,
|
|
||||||
relName: null,
|
relName: null,
|
||||||
relComment: null,
|
relComment: null,
|
||||||
relColumn: null,
|
relColumn: null,
|
||||||
|
|
@ -773,9 +762,34 @@ export default {
|
||||||
},
|
},
|
||||||
/** 选择生成模板触发 */
|
/** 选择生成模板触发 */
|
||||||
tplSelectChange(value) {
|
tplSelectChange(value) {
|
||||||
if (value !== 'sub') {
|
if (value === 'rel'){
|
||||||
|
this.tableList = []
|
||||||
|
let table = {
|
||||||
|
tableName: this.info.tableName,
|
||||||
|
}
|
||||||
|
this.tableList.push(table)
|
||||||
|
getRelId().then(res => {
|
||||||
|
let relTable = {
|
||||||
|
id: res.data,
|
||||||
|
tableId: this.tableId,
|
||||||
|
tableName:null,
|
||||||
|
relName: null,
|
||||||
|
relComment: null,
|
||||||
|
relColumn: null,
|
||||||
|
tableColumn: null,
|
||||||
|
queryType: 'left',
|
||||||
|
sort: 1,
|
||||||
|
tableColumns: [],
|
||||||
|
relColumns: [],
|
||||||
|
}
|
||||||
|
this.relTables.push(relTable);
|
||||||
|
})
|
||||||
|
}else if (value !== 'sub') {
|
||||||
this.info.subTableName = '';
|
this.info.subTableName = '';
|
||||||
this.info.subTableFkName = '';
|
this.info.subTableFkName = '';
|
||||||
|
this.relTables=[]
|
||||||
|
}else {
|
||||||
|
this.relTables=[]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/** 设置关联外键 */
|
/** 设置关联外键 */
|
||||||
|
|
|
||||||
|
|
@ -165,8 +165,8 @@
|
||||||
<el-tabs v-model="preview.activeName">
|
<el-tabs v-model="preview.activeName">
|
||||||
<el-tab-pane
|
<el-tab-pane
|
||||||
v-for="(value, key) in preview.data"
|
v-for="(value, key) in preview.data"
|
||||||
:label="key.substring(key.lastIndexOf('/')+1,key.indexOf('.vm'))"
|
:label="key"
|
||||||
:name="key.substring(key.lastIndexOf('/')+1,key.indexOf('.vm'))"
|
:name="key"
|
||||||
:key="key"
|
:key="key"
|
||||||
>
|
>
|
||||||
<pre><code class="hljs" v-html="highlightedCode(value, key)"></code></pre>
|
<pre><code class="hljs" v-html="highlightedCode(value, key)"></code></pre>
|
||||||
|
|
@ -304,7 +304,7 @@ export default {
|
||||||
},
|
},
|
||||||
/** 高亮显示 */
|
/** 高亮显示 */
|
||||||
highlightedCode(code, key) {
|
highlightedCode(code, key) {
|
||||||
const vmName = key.substring(key.lastIndexOf("/") + 1, key.indexOf(".vm"));
|
const vmName = key;
|
||||||
var language = vmName.substring(vmName.indexOf(".") + 1, vmName.length);
|
var language = vmName.substring(vmName.indexOf(".") + 1, vmName.length);
|
||||||
const result = hljs.highlight(language, code || "", true);
|
const result = hljs.highlight(language, code || "", true);
|
||||||
return result.value || ' ';
|
return result.value || ' ';
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
package com.hchyun.generator.entity;
|
package com.hchyun.generator.entity;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
|
||||||
import javax.validation.constraints.NotBlank;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class RelTable {
|
public class RelTable {
|
||||||
|
|
@ -9,14 +7,16 @@ public class RelTable {
|
||||||
|
|
||||||
//表id
|
//表id
|
||||||
private long id;
|
private long id;
|
||||||
//unionid
|
|
||||||
private long unionId;
|
|
||||||
//主表id
|
//主表id
|
||||||
private long tableId;
|
private long tableId;
|
||||||
//是否是一级关联查询
|
|
||||||
private Integer isMain;
|
|
||||||
//关联子表表名
|
//关联子表表名
|
||||||
private String relName;
|
private String relName;
|
||||||
|
//子表表名称简写
|
||||||
|
private String relAs;
|
||||||
|
//父表名称
|
||||||
|
private String tableName;
|
||||||
|
//父表名称简写
|
||||||
|
private String tableAs;
|
||||||
//关联子表描述
|
//关联子表描述
|
||||||
private String relComment;
|
private String relComment;
|
||||||
//关联子表的字段
|
//关联子表的字段
|
||||||
|
|
@ -25,6 +25,8 @@ public class RelTable {
|
||||||
private String tableColumn;
|
private String tableColumn;
|
||||||
//实体类名称(子表)
|
//实体类名称(子表)
|
||||||
private String relClass;
|
private String relClass;
|
||||||
|
//实体小写类名称(子表)
|
||||||
|
private String relclass;
|
||||||
//查询方式
|
//查询方式
|
||||||
private String queryType;
|
private String queryType;
|
||||||
//排序
|
//排序
|
||||||
|
|
@ -34,14 +36,6 @@ public class RelTable {
|
||||||
|
|
||||||
private List<RelColumn> relColumns;
|
private List<RelColumn> relColumns;
|
||||||
|
|
||||||
public List<RelColumn> getRelColumns() {
|
|
||||||
return relColumns;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRelColumns(List<RelColumn> relColumns) {
|
|
||||||
this.relColumns = relColumns;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getId() {
|
public long getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
@ -50,14 +44,6 @@ public class RelTable {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getUnionId() {
|
|
||||||
return unionId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUnionId(long unionId) {
|
|
||||||
this.unionId = unionId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getTableId() {
|
public long getTableId() {
|
||||||
return tableId;
|
return tableId;
|
||||||
}
|
}
|
||||||
|
|
@ -66,14 +52,6 @@ public class RelTable {
|
||||||
this.tableId = tableId;
|
this.tableId = tableId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getIsMain() {
|
|
||||||
return isMain;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIsMain(Integer isMain) {
|
|
||||||
this.isMain = isMain;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRelName() {
|
public String getRelName() {
|
||||||
return relName;
|
return relName;
|
||||||
}
|
}
|
||||||
|
|
@ -82,6 +60,30 @@ public class RelTable {
|
||||||
this.relName = relName;
|
this.relName = relName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getRelAs() {
|
||||||
|
return relAs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRelAs(String relAs) {
|
||||||
|
this.relAs = relAs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTableName() {
|
||||||
|
return tableName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTableName(String tableName) {
|
||||||
|
this.tableName = tableName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTableAs() {
|
||||||
|
return tableAs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTableAs(String tableAs) {
|
||||||
|
this.tableAs = tableAs;
|
||||||
|
}
|
||||||
|
|
||||||
public String getRelComment() {
|
public String getRelComment() {
|
||||||
return relComment;
|
return relComment;
|
||||||
}
|
}
|
||||||
|
|
@ -114,6 +116,14 @@ public class RelTable {
|
||||||
this.relClass = relClass;
|
this.relClass = relClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getRelclass() {
|
||||||
|
return relclass;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRelclass(String relclass) {
|
||||||
|
this.relclass = relclass;
|
||||||
|
}
|
||||||
|
|
||||||
public String getQueryType() {
|
public String getQueryType() {
|
||||||
return queryType;
|
return queryType;
|
||||||
}
|
}
|
||||||
|
|
@ -137,4 +147,12 @@ public class RelTable {
|
||||||
public void setCreateBy(long createBy) {
|
public void setCreateBy(long createBy) {
|
||||||
this.createBy = createBy;
|
this.createBy = createBy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<RelColumn> getRelColumns() {
|
||||||
|
return relColumns;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRelColumns(List<RelColumn> relColumns) {
|
||||||
|
this.relColumns = relColumns;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -13,8 +14,7 @@ import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
import com.hchyun.generator.dao.AssociatedDao;
|
import com.hchyun.generator.dao.AssociatedDao;
|
||||||
import com.hchyun.generator.dao.RelDao;
|
import com.hchyun.generator.dao.RelDao;
|
||||||
import com.hchyun.generator.entity.AssColumn;
|
import com.hchyun.generator.entity.*;
|
||||||
import com.hchyun.generator.entity.RelTable;
|
|
||||||
import com.hchyun.generator.service.GenTableService;
|
import com.hchyun.generator.service.GenTableService;
|
||||||
import com.hchyun.generator.utils.*;
|
import com.hchyun.generator.utils.*;
|
||||||
import com.hchyun.generator.utils.constant.Constants;
|
import com.hchyun.generator.utils.constant.Constants;
|
||||||
|
|
@ -33,8 +33,6 @@ import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.hchyun.generator.entity.GenTable;
|
|
||||||
import com.hchyun.generator.entity.GenTableColumn;
|
|
||||||
import com.hchyun.generator.dao.GenTableColumnDao;
|
import com.hchyun.generator.dao.GenTableColumnDao;
|
||||||
import com.hchyun.generator.dao.GenTableDao;
|
import com.hchyun.generator.dao.GenTableDao;
|
||||||
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
||||||
|
|
@ -170,7 +168,11 @@ public class GenTableServiceImpl implements GenTableService {
|
||||||
relTables = genTable.getRelTables();
|
relTables = genTable.getRelTables();
|
||||||
for (int i = 0; i < relTables.size(); i++) {
|
for (int i = 0; i < relTables.size(); i++) {
|
||||||
RelTable relTable = relTables.get(i);
|
RelTable relTable = relTables.get(i);
|
||||||
|
relTable.setTableAs(GenStringUtils.sqlFormat(relTable.getTableName()));
|
||||||
|
relTable.setRelAs(GenStringUtils.sqlFormat(relTable.getRelName()));
|
||||||
relTable.setRelClass(GenUtils.convertClassName(relTable.getRelName()));
|
relTable.setRelClass(GenUtils.convertClassName(relTable.getRelName()));
|
||||||
|
relTable.setCreateBy(GenSecurityUtils.getUserId());
|
||||||
|
relTable.setRelclass(GenStringUtils.uncapitalize(relTable.getRelClass()));
|
||||||
relTables.set(i,relTable);
|
relTables.set(i,relTable);
|
||||||
}
|
}
|
||||||
if (relTables != null) {
|
if (relTables != null) {
|
||||||
|
|
@ -200,6 +202,15 @@ public class GenTableServiceImpl implements GenTableService {
|
||||||
try {
|
try {
|
||||||
genTableDao.deleteGenTableByIds(tableIds);
|
genTableDao.deleteGenTableByIds(tableIds);
|
||||||
genTableColumnDao.deleteGenTableColumnByIds(tableIds);
|
genTableColumnDao.deleteGenTableColumnByIds(tableIds);
|
||||||
|
for (Long tableId : tableIds) {
|
||||||
|
List<RelTable> relTables = relDao.relTableByTableId(tableId);
|
||||||
|
if (relTables.size()>0){
|
||||||
|
relDao.deleteRelTableByTableId(tableId);
|
||||||
|
for (RelTable relTable : relTables) {
|
||||||
|
relDao.deleteRelColumnByRelId(relTable.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return new GenServerResult<>(true);
|
return new GenServerResult<>(true);
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||||
|
|
@ -252,8 +263,10 @@ public class GenTableServiceImpl implements GenTableService {
|
||||||
// 设置主子表信息
|
// 设置主子表信息
|
||||||
setSubTable(table);
|
setSubTable(table);
|
||||||
}
|
}
|
||||||
if (table.getTplCategory().equals(GenConstants.TPL_ASS)) {
|
if (table.getTplCategory().equals(GenConstants.TPL_REL)) {
|
||||||
table.setAssColumns(associatedDao.selectTableColumnByTableId(tableId));
|
List<RelTable> relTables = relDao.relTableByTableId(tableId);
|
||||||
|
relTables = relTables.stream().sorted(Comparator.comparing(RelTable::getSort)).collect(Collectors.toList());
|
||||||
|
table.setRelTables(relTables);
|
||||||
}
|
}
|
||||||
// 设置主键列信息
|
// 设置主键列信息
|
||||||
setPkColumn(table);
|
setPkColumn(table);
|
||||||
|
|
@ -265,10 +278,24 @@ public class GenTableServiceImpl implements GenTableService {
|
||||||
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
|
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
|
||||||
for (String template : templates) {
|
for (String template : templates) {
|
||||||
// 渲染模板
|
// 渲染模板
|
||||||
|
if (template.equals("vm/java/rel-entity.java.vm")){
|
||||||
|
List<RelTable> relTables = table.getRelTables();
|
||||||
|
for (RelTable relTable : relTables) {
|
||||||
|
List<RelColumn> relColumns = relTable.getRelColumns();
|
||||||
|
relColumns = relColumns.stream().sorted(Comparator.comparing(RelColumn::getSort)).collect(Collectors.toList());
|
||||||
|
relTable.setRelColumns(relColumns);
|
||||||
|
context.put("relTable",relTable);
|
||||||
|
StringWriter stringWriter = new StringWriter();
|
||||||
|
Template temp = Velocity.getTemplate(template,Constants.UTF8);
|
||||||
|
temp.merge(context,stringWriter);
|
||||||
|
dataMap.put(VelocityUtils.getPreviewName(template,relTable.getRelClass()),stringWriter.toString());
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
Template tpl = Velocity.getTemplate(template, Constants.UTF8);
|
Template tpl = Velocity.getTemplate(template, Constants.UTF8);
|
||||||
tpl.merge(context, sw);
|
tpl.merge(context, sw);
|
||||||
dataMap.put(template, sw.toString());
|
dataMap.put(VelocityUtils.getPreviewName(template,table.getClassName()), sw.toString());
|
||||||
}
|
}
|
||||||
return dataMap;
|
return dataMap;
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
|
|
@ -322,6 +349,26 @@ public class GenTableServiceImpl implements GenTableService {
|
||||||
for (String template : templates) {
|
for (String template : templates) {
|
||||||
if (!GenStringUtils.containsAny(template, "table.sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm")) {
|
if (!GenStringUtils.containsAny(template, "table.sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm")) {
|
||||||
// 渲染模板
|
// 渲染模板
|
||||||
|
if (template.equals("vm/java/rel-entity.java.vm")){
|
||||||
|
List<RelTable> relTables = table.getRelTables();
|
||||||
|
for (RelTable relTable : relTables) {
|
||||||
|
List<RelColumn> relColumns = relTable.getRelColumns();
|
||||||
|
relColumns = relColumns.stream().sorted(Comparator.comparing(RelColumn::getSort)).collect(Collectors.toList());
|
||||||
|
relTable.setRelColumns(relColumns);
|
||||||
|
context.put("relTable",relTable);
|
||||||
|
StringWriter stringWriter = new StringWriter();
|
||||||
|
Template temp = Velocity.getTemplate(template,Constants.UTF8);
|
||||||
|
temp.merge(context,stringWriter);
|
||||||
|
try {
|
||||||
|
String path = getGenPath(table, template);
|
||||||
|
FileUtils.writeStringToFile(new File(path), stringWriter.toString(), CharsetKit.UTF_8);
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error("渲染模板失败,表名:" + table.getTableName());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
Template tpl = Velocity.getTemplate(template, Constants.UTF8);
|
Template tpl = Velocity.getTemplate(template, Constants.UTF8);
|
||||||
tpl.merge(context, sw);
|
tpl.merge(context, sw);
|
||||||
|
|
@ -431,22 +478,17 @@ public class GenTableServiceImpl implements GenTableService {
|
||||||
* todo 查询表信息并生成代码
|
* todo 查询表信息并生成代码
|
||||||
*/
|
*/
|
||||||
private ZipOutputStream generatorCode(String tableName, ZipOutputStream zip) {
|
private ZipOutputStream generatorCode(String tableName, ZipOutputStream zip) {
|
||||||
try {
|
|
||||||
|
|
||||||
} catch (RuntimeException e) {
|
|
||||||
logger.error(e.getMessage());
|
|
||||||
throw new GenCustomException(GenReturnConstants.OP_ERROR);
|
|
||||||
}
|
|
||||||
// 查询表信息
|
// 查询表信息
|
||||||
GenTable table = genTableDao.selectGenTableByName(tableName);
|
GenTable table = genTableDao.selectGenTableByName(tableName);
|
||||||
// 设置主子表信息
|
// 设置主子表信息
|
||||||
setSubTable(table);
|
setSubTable(table);
|
||||||
// 设置主键列信息
|
// 设置主键列信息
|
||||||
setPkColumn(table);
|
setPkColumn(table);
|
||||||
if (table.getTplCategory().equals(GenConstants.TPL_ASS)) {
|
if (table.getTplCategory().equals(GenConstants.TPL_REL)) {
|
||||||
table.setAssColumns(associatedDao.selectTableColumnByTableId(table.getTableId()));
|
List<RelTable> relTables = relDao.relTableByTableId(table.getTableId());
|
||||||
|
relTables = relTables.stream().sorted(Comparator.comparing(RelTable::getSort)).collect(Collectors.toList());
|
||||||
|
table.setRelTables(relTables);
|
||||||
}
|
}
|
||||||
|
|
||||||
VelocityInitializer.initVelocity();
|
VelocityInitializer.initVelocity();
|
||||||
|
|
||||||
VelocityContext context = VelocityUtils.prepareContext(table);
|
VelocityContext context = VelocityUtils.prepareContext(table);
|
||||||
|
|
@ -454,7 +496,31 @@ public class GenTableServiceImpl implements GenTableService {
|
||||||
// 获取模板列表
|
// 获取模板列表
|
||||||
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
|
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
|
||||||
for (String template : templates) {
|
for (String template : templates) {
|
||||||
|
|
||||||
// 渲染模板
|
// 渲染模板
|
||||||
|
if (template.equals("vm/java/rel-entity.java.vm")){
|
||||||
|
List<RelTable> relTables = table.getRelTables();
|
||||||
|
for (RelTable relTable : relTables) {
|
||||||
|
List<RelColumn> relColumns = relTable.getRelColumns();
|
||||||
|
relColumns = relColumns.stream().sorted(Comparator.comparing(RelColumn::getSort)).collect(Collectors.toList());
|
||||||
|
relTable.setRelColumns(relColumns);
|
||||||
|
context.put("relTable",relTable);
|
||||||
|
StringWriter stringWriter = new StringWriter();
|
||||||
|
Template temp = Velocity.getTemplate(template,Constants.UTF8);
|
||||||
|
temp.merge(context,stringWriter);
|
||||||
|
try {
|
||||||
|
// 添加到zip
|
||||||
|
zip.putNextEntry(new ZipEntry(VelocityUtils.getRelFileName(template, table,relTable)));
|
||||||
|
IOUtils.write(stringWriter.toString(), zip, Constants.UTF8);
|
||||||
|
IOUtils.closeQuietly(stringWriter);
|
||||||
|
zip.flush();
|
||||||
|
zip.closeEntry();
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error("渲染模板失败,表名:" + table.getTableName(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
Template tpl = Velocity.getTemplate(template, Constants.UTF8);
|
Template tpl = Velocity.getTemplate(template, Constants.UTF8);
|
||||||
tpl.merge(context, sw);
|
tpl.merge(context, sw);
|
||||||
|
|
|
||||||
|
|
@ -403,6 +403,10 @@ public class GenStringUtils extends org.apache.commons.lang3.StringUtils {
|
||||||
return sqlStr;
|
return sqlStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String toLoad(String str){
|
||||||
|
return str.substring(0,1).toLowerCase()+str.substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <T> T cast(Object obj) {
|
public static <T> T cast(Object obj) {
|
||||||
return (T) obj;
|
return (T) obj;
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.hchyun.generator.entity.RelTable;
|
||||||
import com.hchyun.generator.utils.constant.GenConstants;
|
import com.hchyun.generator.utils.constant.GenConstants;
|
||||||
import org.apache.velocity.VelocityContext;
|
import org.apache.velocity.VelocityContext;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
|
@ -69,18 +70,15 @@ public class VelocityUtils {
|
||||||
if (GenConstants.TPL_SUB.equals(tplCategory)) {
|
if (GenConstants.TPL_SUB.equals(tplCategory)) {
|
||||||
setSubVelocityContext(velocityContext, genTable);
|
setSubVelocityContext(velocityContext, genTable);
|
||||||
}
|
}
|
||||||
if (GenConstants.TPL_ASS.equals(tplCategory)) {
|
if (GenConstants.TPL_REL.equals(tplCategory)) {
|
||||||
setAssVelocityContext(velocityContext, genTable);
|
setRelVelocityContext(velocityContext, genTable);
|
||||||
}
|
}
|
||||||
return velocityContext;
|
return velocityContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setAssVelocityContext(VelocityContext context, GenTable genTable) {
|
public static void setRelVelocityContext(VelocityContext context, GenTable genTable) {
|
||||||
String assClassName = GenUtils.convertClassName(genTable.getAssTableName());
|
context.put("relTables", genTable.getRelTables());
|
||||||
context.put("assClassName", assClassName);
|
|
||||||
context.put("assclassName", GenStringUtils.uncapitalize(assClassName));
|
|
||||||
context.put("tableMapping", GenStringUtils.sqlFormat(genTable.getTableName()));
|
context.put("tableMapping", GenStringUtils.sqlFormat(genTable.getTableName()));
|
||||||
context.put("assMapping", GenStringUtils.sqlFormat(genTable.getAssTableName()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setMenuVelocityContext(VelocityContext context, GenTable genTable) {
|
public static void setMenuVelocityContext(VelocityContext context, GenTable genTable) {
|
||||||
|
|
@ -150,12 +148,56 @@ public class VelocityUtils {
|
||||||
} else if (GenConstants.TPL_SUB.equals(tplCategory)) {
|
} else if (GenConstants.TPL_SUB.equals(tplCategory)) {
|
||||||
templates.add("vm/vue/index.vue.vm");
|
templates.add("vm/vue/index.vue.vm");
|
||||||
templates.add("vm/java/sub-entity.java.vm");
|
templates.add("vm/java/sub-entity.java.vm");
|
||||||
} else if (GenConstants.TPL_ASS.equals(tplCategory)) {
|
} else if (GenConstants.TPL_REL.equals(tplCategory)) {
|
||||||
templates.add("vm/vue/index.vue.vm");
|
templates.add("vm/vue/index.vue.vm");
|
||||||
templates.add("vm/java/ass-entity.java.vm");
|
templates.add("vm/java/rel-entity.java.vm");
|
||||||
}
|
}
|
||||||
return templates;
|
return templates;
|
||||||
}
|
}
|
||||||
|
public static String getRelFileName(String template, GenTable genTable, RelTable relTable){
|
||||||
|
|
||||||
|
// 文件名称
|
||||||
|
String fileName = "";
|
||||||
|
// 包路径
|
||||||
|
String packageName = genTable.getPackageName();
|
||||||
|
// 模块名
|
||||||
|
String moduleName = genTable.getModuleName();
|
||||||
|
|
||||||
|
String javaPath = PROJECT_PATH + "/" + GenStringUtils.replace(packageName, ".", "/");
|
||||||
|
fileName = GenStringUtils.format("{}/entity/{}.java", javaPath, relTable.getRelClass());
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getPreviewName(String template, String ClassName) {
|
||||||
|
String fileName = "";
|
||||||
|
if (template.contains("entity.java.vm")) {
|
||||||
|
fileName = GenStringUtils.format("{}.java", ClassName);
|
||||||
|
}
|
||||||
|
if (template.contains("sub-entity.java.vm") && GenStringUtils.equals(GenConstants.TPL_SUB, ClassName)) {
|
||||||
|
fileName = GenStringUtils.format("{}.java", ClassName);
|
||||||
|
} else if (template.contains("rel-entity.java.vm")) {
|
||||||
|
fileName = GenStringUtils.format("{}.java", ClassName);
|
||||||
|
} else if (template.contains("dao.java.vm")) {
|
||||||
|
fileName = GenStringUtils.format("{}Dao.java", ClassName);
|
||||||
|
} else if (template.contains("service.java.vm")) {
|
||||||
|
fileName = GenStringUtils.format("{}Service.java", ClassName);
|
||||||
|
} else if (template.contains("serviceImpl.java.vm")) {
|
||||||
|
fileName = GenStringUtils.format("{}ServiceImpl.java", ClassName);
|
||||||
|
} else if (template.contains("controller.java.vm")) {
|
||||||
|
fileName = GenStringUtils.format("{}Controller.java",ClassName);
|
||||||
|
} else if (template.contains("mapper.xml.vm")) {
|
||||||
|
fileName = GenStringUtils.format("{}Mapper.xml",ClassName);
|
||||||
|
} else if (template.contains("table.sql.vm")) {
|
||||||
|
fileName = ClassName + "menu.sql";
|
||||||
|
} else if (template.contains("api.js.vm")) {
|
||||||
|
fileName = GenStringUtils.format("{}.js", GenStringUtils.toLoad(ClassName));
|
||||||
|
} else if (template.contains("index.vue.vm")) {
|
||||||
|
fileName = "index.vue";
|
||||||
|
} else if (template.contains("index-tree.vue.vm")) {
|
||||||
|
fileName = "index.vue";
|
||||||
|
}
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取文件名
|
* 获取文件名
|
||||||
|
|
@ -194,7 +236,7 @@ public class VelocityUtils {
|
||||||
} else if (template.contains("mapper.xml.vm")) {
|
} else if (template.contains("mapper.xml.vm")) {
|
||||||
fileName = GenStringUtils.format("{}/{}Mapper.xml", mybatisPath, className);
|
fileName = GenStringUtils.format("{}/{}Mapper.xml", mybatisPath, className);
|
||||||
} else if (template.contains("table.sql.vm")) {
|
} else if (template.contains("table.sql.vm")) {
|
||||||
fileName = businessName + "GenMenu.sql";
|
fileName = businessName + "menu.sql";
|
||||||
} else if (template.contains("api.js.vm")) {
|
} else if (template.contains("api.js.vm")) {
|
||||||
fileName = GenStringUtils.format("{}/api/{}/{}.js", vuePath, moduleName, businessName);
|
fileName = GenStringUtils.format("{}/api/{}/{}.js", vuePath, moduleName, businessName);
|
||||||
} else if (template.contains("index.vue.vm")) {
|
} else if (template.contains("index.vue.vm")) {
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,10 @@ public class GenConstants {
|
||||||
* 关联查询(增删改查)
|
* 关联查询(增删改查)
|
||||||
*/
|
*/
|
||||||
public static final String TPL_ASS = "ass";
|
public static final String TPL_ASS = "ass";
|
||||||
|
/**
|
||||||
|
* 多表关联查询(增删改查)
|
||||||
|
*/
|
||||||
|
public static final String TPL_REL = "rel";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 树编码字段
|
* 树编码字段
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,16 @@
|
||||||
|
|
||||||
<resultMap id="RelTableResult" type="com.hchyun.generator.entity.RelTable">
|
<resultMap id="RelTableResult" type="com.hchyun.generator.entity.RelTable">
|
||||||
<result property="id" column="id"/>
|
<result property="id" column="id"/>
|
||||||
<result property="unionId" column="union_id"/>
|
|
||||||
<result property="tableId" column="table_id"/>
|
<result property="tableId" column="table_id"/>
|
||||||
<result property="isMain" column=""/>
|
|
||||||
<result property="relName" column="rel_name"/>
|
<result property="relName" column="rel_name"/>
|
||||||
|
<result property="relAs" column="rel_as"/>
|
||||||
|
<result property="tableName" column="table_name"/>
|
||||||
|
<result property="tableAs" column="table_as"/>
|
||||||
<result property="relComment" column="rel_comment"/>
|
<result property="relComment" column="rel_comment"/>
|
||||||
<result property="relColumn" column="rel_column"/>
|
<result property="relColumn" column="rel_column"/>
|
||||||
<result property="tableColumn" column="table_column"/>
|
<result property="tableColumn" column="table_column"/>
|
||||||
<result property="relClass" column="rel_class"/>
|
<result property="relClass" column="rel_class"/>
|
||||||
|
<result property="relclass" column="relclass"/>
|
||||||
<result property="queryType" column="query_type"/>
|
<result property="queryType" column="query_type"/>
|
||||||
<result property="sort" column="sort"/>
|
<result property="sort" column="sort"/>
|
||||||
<result property="createBy" column="create_by"/>
|
<result property="createBy" column="create_by"/>
|
||||||
|
|
@ -30,10 +32,10 @@
|
||||||
<result property="javaField" column="java_field"/>
|
<result property="javaField" column="java_field"/>
|
||||||
<result property="isList" column="is_list"/>
|
<result property="isList" column="is_list"/>
|
||||||
<result property="isQuery" column="is_query"/>
|
<result property="isQuery" column="is_query"/>
|
||||||
<result property="queryType" column="query_type"/>
|
<result property="queryType" column="col_query_type"/>
|
||||||
<result property="htmlType" column="html_type"/>
|
<result property="htmlType" column="html_type"/>
|
||||||
<result property="dictType" column="dict_type"/>
|
<result property="dictType" column="dict_type"/>
|
||||||
<result property="sort" column="sort"/>
|
<result property="sort" column="sorts"/>
|
||||||
<result property="createBy" column="create_by"/>
|
<result property="createBy" column="create_by"/>
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
|
|
@ -55,17 +57,17 @@
|
||||||
from information_schema.columns
|
from information_schema.columns
|
||||||
where table_schema = (select database())
|
where table_schema = (select database())
|
||||||
and table_name = (#{tableName})
|
and table_name = (#{tableName})
|
||||||
order by sort
|
order by sort desc
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<insert id="insertRelTables" parameterType="java.util.List">
|
<insert id="insertRelTables" parameterType="java.util.List">
|
||||||
insert into gen_rel_table(id, union_id, table_id, is_main, rel_name, rel_comment,
|
insert into gen_rel_table(id, table_id, rel_name,rel_as,table_name,table_as, rel_comment,
|
||||||
rel_column, table_column, rel_class, query_type, sort, create_by)
|
rel_column, table_column, rel_class, relclass, query_type, sort, create_by)
|
||||||
values
|
values
|
||||||
<foreach collection="list" item="item" index="index" separator=",">
|
<foreach collection="list" item="item" index="index" separator=",">
|
||||||
(#{item.id},#{item.unionId},#{item.tableId},#{item.isMain},
|
(#{item.id},#{item.tableId},#{item.relName},#{item.relAs},#{item.tableName},
|
||||||
#{item.relName},#{item.relComment},#{item.relColumn},#{item.tableColumn},#{item.relClass},
|
#{item.tableAs},#{item.relComment},#{item.relColumn},#{item.tableColumn},#{item.relClass},
|
||||||
#{item.queryType},#{item.sort},#{item.createBy})
|
#{item.relclass},#{item.queryType},#{item.sort},#{item.createBy})
|
||||||
</foreach>
|
</foreach>
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
|
|
@ -89,11 +91,12 @@
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="relTableByTableId" resultMap="RelTableColumnResult" parameterType="Long">
|
<select id="relTableByTableId" resultMap="RelTableColumnResult" parameterType="Long">
|
||||||
select grt.id, grt.union_id, grt.table_id, grt.is_main, grt.rel_name, grt.rel_comment, grt.rel_column, grt.table_column, grt.rel_class, grt.query_type, grt.sort, grt.create_by,
|
select grt.id, grt.table_id, grt.rel_name, grt.rel_as, grt.table_name, grt.table_as, grt.rel_comment, grt.rel_column, grt.table_column, grt.rel_class, grt.relclass, grt.query_type, grt.sort, grt.create_by,
|
||||||
grc.rel_id, grc.column_name, grc.column_comment, grc.column_type, grc.java_type, grc.java_field, grc.is_list, grc.is_query, grc.query_type, grc.html_type, grc.dict_type, grc.sort, grc.create_by
|
grc.rel_id, grc.column_name, grc.column_comment, grc.column_type, grc.java_type, grc.java_field, grc.is_list, grc.is_query, grc.query_type as col_query_type, grc.html_type, grc.dict_type, grc.sort as sorts, grc.create_by
|
||||||
from gen_rel_table grt
|
from gen_rel_table grt
|
||||||
left join gen_rel_column grc on grt.id = grc.rel_id
|
left join gen_rel_column grc on grt.id = grc.rel_id
|
||||||
where grt.table_id = #{tableId}
|
where grt.table_id = #{tableId}
|
||||||
|
order by grt.sort desc
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<delete id="deleteRelColumnByRelId">
|
<delete id="deleteRelColumnByRelId">
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ import com.hchyun.common.utils.poi.ExcelUtil;
|
||||||
#if($table.crud || $table.sub)
|
#if($table.crud || $table.sub)
|
||||||
import com.hchyun.common.core.page.TableDataInfo;
|
import com.hchyun.common.core.page.TableDataInfo;
|
||||||
#elseif($table.tree)
|
#elseif($table.tree)
|
||||||
#elseif($table.tplCategory.equals("ass"))
|
#elseif($table.tplCategory.equals("rel"))
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
#end
|
#end
|
||||||
|
|
||||||
|
|
@ -63,7 +63,7 @@ public class ${ClassName}Controller extends HcyBaseController {
|
||||||
startPage(${className}.getParams());
|
startPage(${className}.getParams());
|
||||||
ServerResult<List<${ClassName}>> genServerResult = ${className}Service.select${ClassName}List(${className});
|
ServerResult<List<${ClassName}>> genServerResult = ${className}Service.select${ClassName}List(${className});
|
||||||
if (genServerResult.isStart()) {
|
if (genServerResult.isStart()) {
|
||||||
#if($table.crud || $table.sub || $table.tplCategory.equals("ass"))
|
#if($table.crud || $table.sub || $tplCategory.equals("rel"))
|
||||||
return getDataTable(genServerResult.getData());
|
return getDataTable(genServerResult.getData());
|
||||||
#elseif($table.tree)
|
#elseif($table.tree)
|
||||||
return AjaxResult.success(genServerResult.getData());
|
return AjaxResult.success(genServerResult.getData());
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,7 @@ package ${packageName}.entity;
|
||||||
#foreach ($import in $importList)
|
#foreach ($import in $importList)
|
||||||
import ${import};
|
import ${import};
|
||||||
#end
|
#end
|
||||||
import com.hchyun.common.annotation.Excel;
|
#if($table.crud || $table.sub || $tplCategory.equals("rel"))
|
||||||
#if($table.crud || $table.sub)
|
|
||||||
#set($Entity="BaseEntity")
|
#set($Entity="BaseEntity")
|
||||||
#elseif($table.tree)
|
#elseif($table.tree)
|
||||||
#set($Entity="TreeEntity")
|
#set($Entity="TreeEntity")
|
||||||
|
|
@ -17,10 +16,10 @@ import ${packageName}.entity.${assClassName};
|
||||||
import ${packageName}.entity.${subClassName};
|
import ${packageName}.entity.${subClassName};
|
||||||
#end
|
#end
|
||||||
import com.hchyun.common.core.entity.${Entity};
|
import com.hchyun.common.core.entity.${Entity};
|
||||||
|
import com.hchyun.common.annotation.Excel;
|
||||||
|
import com.hchyun.common.annotation.Excels;
|
||||||
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModel;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
|
||||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ${functionName}对象 ${tableName}
|
* ${functionName}对象 ${tableName}
|
||||||
|
|
@ -34,12 +33,10 @@ import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
#set($Entity="TreeEntity")
|
#set($Entity="TreeEntity")
|
||||||
#end
|
#end
|
||||||
@ApiModel("${functionName}")
|
@ApiModel("${functionName}")
|
||||||
public class ${ClassName} extends ${Entity}
|
public class ${ClassName} extends ${Entity}{
|
||||||
{
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
#foreach ($column in $columns)
|
#foreach ($column in $columns)
|
||||||
#if(!$table.isSuperColumn($column.javaField))
|
#if(!$table.isSuperColumn($column.javaField))
|
||||||
|
|
||||||
/** $column.columnComment */
|
/** $column.columnComment */
|
||||||
#if($column.list)
|
#if($column.list)
|
||||||
#set($parentheseIndex=$column.columnComment.indexOf("("))
|
#set($parentheseIndex=$column.columnComment.indexOf("("))
|
||||||
|
|
@ -67,17 +64,17 @@ public class ${ClassName} extends ${Entity}
|
||||||
@ApiModelProperty("${table.subTable.functionName}信息")
|
@ApiModelProperty("${table.subTable.functionName}信息")
|
||||||
private List<${subClassName}> ${subclassName}List;
|
private List<${subClassName}> ${subclassName}List;
|
||||||
|
|
||||||
#elseif($table.tplCategory.equals("ass"))
|
#elseif($tplCategory.equals("rel"))
|
||||||
#set($count = 0)
|
#foreach($table in $relTables)
|
||||||
#foreach($column in $table.assColumns)
|
#foreach($column in $table.relColumns)
|
||||||
#if($column.isList == "1")
|
#if($column.isList.equals("1"))
|
||||||
#set($count = $count + 1)
|
#set($count = $count + 1)
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
#set($targetName = "")
|
#set($targetName = "")
|
||||||
#set($indexs = 0)
|
#set($indexs = 0)
|
||||||
#foreach($column in $table.assColumns)
|
#foreach($column in $table.relColumns)
|
||||||
#if($column.isList == "1")
|
#if($column.isList.equals("1"))
|
||||||
#set($parentheseIndex=$column.columnComment.indexOf("("))
|
#set($parentheseIndex=$column.columnComment.indexOf("("))
|
||||||
#if($parentheseIndex != -1)
|
#if($parentheseIndex != -1)
|
||||||
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
|
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
|
||||||
|
|
@ -87,12 +84,16 @@ public class ${ClassName} extends ${Entity}
|
||||||
#set($indexs = $indexs + 1)
|
#set($indexs = $indexs + 1)
|
||||||
#set($targetName = $targetName + '@Excel(name = "'+$comment+'",targetAttr = "'+$column.javaField+'")')
|
#set($targetName = $targetName + '@Excel(name = "'+$comment+'",targetAttr = "'+$column.javaField+'")')
|
||||||
#if($indexs != $count)
|
#if($indexs != $count)
|
||||||
#set($targetName = $targetName + ",")
|
#set($targetName = $targetName + ",")
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
@Excels({${targetName}}))
|
|
||||||
private ${assClassName} ${assclassName};
|
/** ${table.relComment}信息 */
|
||||||
|
@Excels({${targetName}})
|
||||||
|
private ${table.relClass} ${table.relclass};
|
||||||
|
#end
|
||||||
|
|
||||||
#end
|
#end
|
||||||
|
|
||||||
#foreach ($column in $columns)
|
#foreach ($column in $columns)
|
||||||
|
|
@ -120,16 +121,16 @@ public class ${ClassName} extends ${Entity}
|
||||||
public void set${subClassName}List(List<${subClassName}> ${subclassName}List){
|
public void set${subClassName}List(List<${subClassName}> ${subclassName}List){
|
||||||
this.${subclassName}List = ${subclassName}List;
|
this.${subclassName}List = ${subclassName}List;
|
||||||
}
|
}
|
||||||
|
#elseif($table.tplCategory.equals("rel"))
|
||||||
|
#foreach($table in $relTables)
|
||||||
|
public ${table.relClass} get${table.relClass}(){
|
||||||
|
return ${table.relclass};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set${table.relClass}(${table.relClass} ${table.relclass}){
|
||||||
|
this.${table.relclass} = ${table.relclass};
|
||||||
|
}
|
||||||
#end
|
#end
|
||||||
#if($table.tplCategory.equals("ass"))
|
|
||||||
public ${assClassName} get${assClassName}(){
|
|
||||||
return ${assclassName};
|
|
||||||
}
|
|
||||||
|
|
||||||
public void set${assClassName}(${assClassName} ${assclassName}){
|
|
||||||
this.${assclassName} = ${assclassName};
|
|
||||||
}
|
|
||||||
|
|
||||||
#end
|
#end
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|
@ -144,6 +145,10 @@ public class ${ClassName} extends ${Entity}
|
||||||
#end
|
#end
|
||||||
#if($table.sub)
|
#if($table.sub)
|
||||||
.append("${subclassName}List", get${subClassName}List())
|
.append("${subclassName}List", get${subClassName}List())
|
||||||
|
#elseif($tplCategory.equals("rel"))
|
||||||
|
#foreach($table in $relTables)
|
||||||
|
.append("${table.relclass}",get${table.relClass}())
|
||||||
|
#end
|
||||||
#end
|
#end
|
||||||
.toString();
|
.toString();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,9 @@
|
||||||
package ${packageName}.entity;
|
package ${packageName}.entity;
|
||||||
|
|
||||||
#foreach ($import in $subImportList)
|
|
||||||
import ${import};
|
|
||||||
#end
|
|
||||||
import com.hchyun.common.annotation.Excel;
|
import com.hchyun.common.annotation.Excel;
|
||||||
import com.hchyun.common.core.entity.BaseEntity;
|
import com.hchyun.common.core.entity.BaseEntity;
|
||||||
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
@ -12,9 +11,9 @@ import com.hchyun.common.core.entity.BaseEntity;
|
||||||
* @date ${datetime}
|
* @date ${datetime}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class ${assClassName} extends BaseEntity{
|
public class ${relTable.relClass} extends BaseEntity{
|
||||||
|
|
||||||
#foreach($column in $table.assColumns)
|
#foreach($column in $relTable.relColumns)
|
||||||
#if(!$table.isSuperColumn($column.javaField))
|
#if(!$table.isSuperColumn($column.javaField))
|
||||||
/** $column.columnComment */
|
/** $column.columnComment */
|
||||||
#set($parentheseIndex=$column.columnComment.indexOf("("))
|
#set($parentheseIndex=$column.columnComment.indexOf("("))
|
||||||
|
|
@ -36,7 +35,7 @@ public class ${assClassName} extends BaseEntity{
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
|
|
||||||
#foreach ($column in $table.assColumns)
|
#foreach ($column in $relTable.relColumns)
|
||||||
#if(!$table.isSuperColumn($column.javaField))
|
#if(!$table.isSuperColumn($column.javaField))
|
||||||
#if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]"))
|
#if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]"))
|
||||||
#set($AttrName=$column.javaField)
|
#set($AttrName=$column.javaField)
|
||||||
|
|
@ -63,7 +63,9 @@
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
#foreach($column in $table.assColumns)
|
#if($tplCategory.equals("rel"))
|
||||||
|
#foreach($table in $relTables)
|
||||||
|
#foreach($column in $table.relColumns)
|
||||||
#if($column.isQuery == '1')
|
#if($column.isQuery == '1')
|
||||||
#set($dictType=$column.dictType)
|
#set($dictType=$column.dictType)
|
||||||
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
|
|
@ -76,7 +78,7 @@
|
||||||
#if($column.htmlType == "input")
|
#if($column.htmlType == "input")
|
||||||
<el-form-item label="${comment}" prop="${column.javaField}">
|
<el-form-item label="${comment}" prop="${column.javaField}">
|
||||||
<el-input
|
<el-input
|
||||||
v-model="queryParams.${assclassName}.${column.javaField}"
|
v-model="queryParams.${table.relclass}.${column.javaField}"
|
||||||
placeholder="请输入${comment}"
|
placeholder="请输入${comment}"
|
||||||
clearable
|
clearable
|
||||||
size="small"
|
size="small"
|
||||||
|
|
@ -85,9 +87,9 @@
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
#elseif(($column.htmlType == "select" || $column.htmlType == "radio") && "" != $dictType)
|
#elseif(($column.htmlType == "select" || $column.htmlType == "radio") && "" != $dictType)
|
||||||
<el-form-item label="${comment}" prop="${column.javaField}">
|
<el-form-item label="${comment}" prop="${column.javaField}">
|
||||||
<el-select v-model="queryParams.${assclassName}.${column.javaField}" placeholder="请选择${comment}" clearable size="small">
|
<el-select v-model="queryParams.${table.relclass}.${column.javaField}" placeholder="请选择${comment}" clearable size="small">
|
||||||
<el-option
|
<el-option
|
||||||
v-for="dict in ${column.javaField}Options"
|
v-for="dict in ${table.relclass}${column.javaField}Options"
|
||||||
:key="dict.dictValue"
|
:key="dict.dictValue"
|
||||||
:label="dict.dictLabel"
|
:label="dict.dictLabel"
|
||||||
:value="dict.dictValue"
|
:value="dict.dictValue"
|
||||||
|
|
@ -96,14 +98,14 @@
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
#elseif(($column.htmlType == "select" || $column.htmlType == "radio") && $dictType)
|
#elseif(($column.htmlType == "select" || $column.htmlType == "radio") && $dictType)
|
||||||
<el-form-item label="${comment}" prop="${column.javaField}">
|
<el-form-item label="${comment}" prop="${column.javaField}">
|
||||||
<el-select v-model="queryParams.${assclassName}.${column.javaField}" placeholder="请选择${comment}" clearable size="small">
|
<el-select v-model="queryParams.${table.relclass}.${column.javaField}" placeholder="请选择${comment}" clearable size="small">
|
||||||
<el-option label="请选择字典生成" value="" />
|
<el-option label="请选择字典生成" value="" />
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
#elseif($column.htmlType == "datetime" && $column.queryType != "BETWEEN")
|
#elseif($column.htmlType == "datetime" && $column.queryType != "BETWEEN")
|
||||||
<el-form-item label="${comment}" prop="${column.javaField}">
|
<el-form-item label="${comment}" prop="${column.javaField}">
|
||||||
<el-date-picker clearable size="small"
|
<el-date-picker clearable size="small"
|
||||||
v-model="queryParams.${assclassName}.${column.javaField}"
|
v-model="queryParams.${table.relclass}.${column.javaField}"
|
||||||
type="date"
|
type="date"
|
||||||
value-format="yyyy-MM-dd"
|
value-format="yyyy-MM-dd"
|
||||||
placeholder="选择${comment}">
|
placeholder="选择${comment}">
|
||||||
|
|
@ -112,7 +114,7 @@
|
||||||
#elseif($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
|
#elseif($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
|
||||||
<el-form-item label="${comment}">
|
<el-form-item label="${comment}">
|
||||||
<el-date-picker
|
<el-date-picker
|
||||||
v-model="ass${AttrName}"
|
v-model="${table.relclass}${AttrName}"
|
||||||
size="small"
|
size="small"
|
||||||
style="width: 240px"
|
style="width: 240px"
|
||||||
value-format="yyyy-MM-dd"
|
value-format="yyyy-MM-dd"
|
||||||
|
|
@ -124,6 +126,8 @@
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
#end
|
#end
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
||||||
|
|
@ -201,9 +205,9 @@
|
||||||
<el-table-column label="${comment}" align="center" prop="${javaField}" />
|
<el-table-column label="${comment}" align="center" prop="${javaField}" />
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
|
#if($tplCategory.equals("rel"))
|
||||||
#if($table.tplCategory.equals("ass"))
|
#foreach($table in $relTables)
|
||||||
#foreach($column in $table.assColumns)
|
#foreach($column in $table.relColumns)
|
||||||
#set($javaField=$column.javaField)
|
#set($javaField=$column.javaField)
|
||||||
#set($parentheseIndex=$column.columnComment.indexOf("("))
|
#set($parentheseIndex=$column.columnComment.indexOf("("))
|
||||||
#if($parentheseIndex != -1)
|
#if($parentheseIndex != -1)
|
||||||
|
|
@ -212,19 +216,19 @@
|
||||||
#set($comment=$column.columnComment)
|
#set($comment=$column.columnComment)
|
||||||
#end
|
#end
|
||||||
#if($column.isList == "1" && $column.htmlType == "datetime")
|
#if($column.isList == "1" && $column.htmlType == "datetime")
|
||||||
<el-table-column label="${comment}" align="center" prop="${assclassName}.${javaField}" width="180">
|
<el-table-column label="${comment}" align="center" prop="${table.relclass}.${javaField}" width="180">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<span>{{ parseTime(scope.row.${assClassName}.${javaField}, '{y}-{m}-{d} {h}:{m}:{s}') }}</span>
|
<span>{{ parseTime(scope.row.${table.relclass}.${javaField}, '{y}-{m}-{d} {h}:{m}:{s}') }}</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
#elseif($column.isList == "1" && "" != $column.dictType)
|
#elseif($column.isList == "1" && "" != $column.dictType)
|
||||||
<el-table-column label="${comment}" align="center" prop="${assclassName}.${javaField}" :formatter="${javaField}Format" />
|
<el-table-column label="${comment}" align="center" prop="${table.relclass}.${javaField}" :formatter="${javaField}Format" />
|
||||||
#elseif($column.isList == "1" && "" != $javaField)
|
#elseif($column.isList == "1" && "" != $javaField)
|
||||||
<el-table-column label="${comment}" align="center" prop="${assclassName}.${javaField}" />
|
<el-table-column label="${comment}" align="center" prop="${table.relclass}.${javaField}" />
|
||||||
|
#end
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
|
|
||||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<el-button
|
<el-button
|
||||||
|
|
@ -480,20 +484,23 @@ export default {
|
||||||
daterange${AttrName}: [],
|
daterange${AttrName}: [],
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
#foreach ($column in $table.assColumns)
|
|
||||||
|
#foreach($table in $relTables)
|
||||||
|
#foreach($column in $table.relColumns)
|
||||||
#set($parentheseIndex=$column.columnComment.indexOf("("))
|
#set($parentheseIndex=$column.columnComment.indexOf("("))
|
||||||
#if($parentheseIndex != -1)
|
#if($parentheseIndex != -1)
|
||||||
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
|
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
|
||||||
#else
|
#else
|
||||||
#set($comment=$column.columnComment)
|
#set($comment=$column.columnComment)
|
||||||
#end
|
#end
|
||||||
#if(${column.dictType} != '')
|
#if(!$column.dictType.equals(""))
|
||||||
// $comment字典
|
// $comment字典
|
||||||
${column.javaField}Options: [],
|
${table.relclass}${column.javaField}Options: [],
|
||||||
#elseif($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
|
#elseif($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
|
||||||
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
// $comment时间范围
|
// $comment时间范围
|
||||||
ass${AttrName}: [],
|
${table.relclass}${AttrName}: [],
|
||||||
|
#end
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
// 查询参数
|
// 查询参数
|
||||||
|
|
@ -508,15 +515,16 @@ export default {
|
||||||
|
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
#if($table.tplCategory.equals("ass"))
|
#if($table.tplCategory.equals("rel"))
|
||||||
${assclassName}: {
|
#foreach($table in $relTables)
|
||||||
#foreach ($column in $table.assColumns)
|
${table.relclass}: {
|
||||||
|
#foreach($column in $table.relColumns)
|
||||||
#if($column.isQuery == '1' && $column.htmlType != "datetime" && $column.queryType != "BETWEEN")
|
#if($column.isQuery == '1' && $column.htmlType != "datetime" && $column.queryType != "BETWEEN")
|
||||||
${column.javaField}: null#if($velocityCount != $columns.size()),#end
|
${column.javaField}: null#if($velocityCount != $columns.size()),#end
|
||||||
|
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
}
|
}
|
||||||
|
#end
|
||||||
#end
|
#end
|
||||||
},
|
},
|
||||||
// 表单参数
|
// 表单参数
|
||||||
|
|
@ -551,6 +559,17 @@ export default {
|
||||||
this.${column.javaField}Options = response.data;
|
this.${column.javaField}Options = response.data;
|
||||||
});
|
});
|
||||||
#end
|
#end
|
||||||
|
#end
|
||||||
|
#if($table.tplCategory.equals("rel"))
|
||||||
|
#foreach ($table in $relTables)
|
||||||
|
#foreach ($column in $table.relColumns)
|
||||||
|
#if(${column.dictType} != '')
|
||||||
|
this.getDicts("${column.dictType}").then(response => {
|
||||||
|
this.${table.relclass}${column.javaField}Options = response.data;
|
||||||
|
});
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
#end
|
#end
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|
@ -565,15 +584,18 @@ export default {
|
||||||
this.queryParams.params["end${AttrName}"] = this.daterange${AttrName}[1];
|
this.queryParams.params["end${AttrName}"] = this.daterange${AttrName}[1];
|
||||||
}
|
}
|
||||||
#end
|
#end
|
||||||
#end
|
#end#if($tplCategory.equals("rel"))
|
||||||
#foreach ($column in $table.assColumns)
|
#foreach($table in $relTables)
|
||||||
|
#foreach($column in $table.relColumns)
|
||||||
#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
|
#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
|
||||||
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
if (null != this.ass${AttrName} && '' != this.ass${AttrName}) {
|
if (null != this.ass${AttrName} && '' != this.ass${AttrName}) {
|
||||||
this.queryParams.params["assbegin${AttrName}"] = this.ass${AttrName}[0];
|
this.queryParams.${table.relclass}.params["begin${AttrName}"] = this.ass${AttrName}[0];
|
||||||
this.queryParams.params["assend${AttrName}"] = this.ass${AttrName}[1];
|
this.queryParams.${table.relclass}.params["end${AttrName}"] = this.ass${AttrName}[1];
|
||||||
}
|
}
|
||||||
#end
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
#end
|
#end
|
||||||
list${BusinessName}(this.queryParams).then(response => {
|
list${BusinessName}(this.queryParams).then(response => {
|
||||||
this.${businessName}List = response.rows;
|
this.${businessName}List = response.rows;
|
||||||
|
|
@ -635,10 +657,15 @@ export default {
|
||||||
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
this.daterange${AttrName} = [];
|
this.daterange${AttrName} = [];
|
||||||
#end
|
#end
|
||||||
#end#foreach ($column in $table.assColumns)
|
#end
|
||||||
|
#if($tplCategory.equals("rel"))
|
||||||
|
#foreach($table in $relTables)
|
||||||
|
#foreach($column in $table.relColumns)
|
||||||
#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
|
#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
|
||||||
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
this.assdaterange${AttrName} = [];
|
this.${table.relass}${AttrName} = [];
|
||||||
|
#end
|
||||||
|
#end
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
this.resetForm("queryForm");
|
this.resetForm("queryForm");
|
||||||
|
|
|
||||||
|
|
@ -21,36 +21,45 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
#end
|
#end
|
||||||
</resultMap>
|
</resultMap>
|
||||||
#end
|
#end
|
||||||
#if($table.tplCategory.equals("ass"))
|
#if($table.tplCategory.equals("rel"))
|
||||||
<resultMap id="${ClassName}${assClassName}Result" type="${packageName}.entity.${ClassName}" extends="${ClassName}Result">
|
<resultMap id="${ClassName}AllResult" type="${packageName}.entity.${ClassName}" extends="${ClassName}Result">
|
||||||
<collection property="${assclassName}" notNullColumn="${table.assTableColumn}" javaType="${packageName}.entity.${assClassName}" resultMap="${assClassName}Result" />
|
#foreach($table in $relTables)
|
||||||
|
<collection property="${table.relClass}" notNullColumn="${table.relColumn}" javaType="${packageName}.entity.${table.relClass}" resultMap="${table.relClass}Result" />
|
||||||
|
#end
|
||||||
</resultMap>
|
</resultMap>
|
||||||
<resultMap type="${packageName}.entity.${assClassName}" id="${assClassName}Result">
|
#foreach($table in $relTables)
|
||||||
#foreach ($column in $table.assColumns)
|
<resultMap id="${table.relClass}Result" type="${packageName}.entity.${table.relClass}">
|
||||||
|
#foreach($column in $table.relColumns)
|
||||||
<result property="${column.javaField}" column="${column.columnName}" />
|
<result property="${column.javaField}" column="${column.columnName}" />
|
||||||
#end
|
#end
|
||||||
</resultMap>
|
</resultMap>
|
||||||
#end
|
#end
|
||||||
|
|
||||||
|
#end
|
||||||
<sql id="select${ClassName}Vo">
|
<sql id="select${ClassName}Vo">
|
||||||
select#foreach($column in $columns) $column.columnName#if($velocityCount != $columns.size()),#end#end from ${tableName}
|
select#foreach($column in $columns) $column.columnName#if($velocityCount != $columns.size()),#end#end from ${tableName}
|
||||||
</sql>
|
</sql>
|
||||||
#if($table.tplCategory.equals("ass"))
|
|
||||||
<select id="select${ClassName}List" parameterType="${ClassName}" resultMap="${ClassName}${assClassName}Result">
|
|
||||||
select#foreach($column in $columns) ${tableMapping}.$column.columnName#if($velocityCount != $columns.size()),#end#end,
|
#if($tplCategory.equals("rel"))
|
||||||
|
<select id="select${ClassName}List" parameterType="${ClassName}" resultMap="${ClassName}AllResult">
|
||||||
|
select #foreach($column in $columns) ${tableMapping}.$column.columnName#if($velocityCount != $columns.size()),#end#end,
|
||||||
|
#foreach($table in $relTables)
|
||||||
#set($count = 0)
|
#set($count = 0)
|
||||||
#foreach($column in $table.assColumns)
|
#foreach($column in $table.relColumns)
|
||||||
#if($column.isList == "1")
|
#if($column.isList == "1")
|
||||||
#set($count = $count + 1)
|
#set($count = $count + 1)
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
#set($targetName = "")
|
|
||||||
#set($indexs = 0)
|
#set($indexs = 0)
|
||||||
#foreach($column in $table.assColumns)#if($column.isList == "1")#set($indexs = $indexs + 1)${assMapping}.$column.columnName#if($indexs != $count), #end#end
|
#foreach($column in $table.relColumns) #if($column.isList == "1")#set($indexs = $indexs + 1)${table.relAs}.$column.columnName#if($indexs != $count),#end#end#end#if($velocityCount != $columns.size()),
|
||||||
|
#end
|
||||||
#end
|
#end
|
||||||
|
|
||||||
from ${tableName} ${tableMapping}
|
from ${tableName} ${tableMapping}
|
||||||
${table.assQueryType} join ${table.assTableName} ${assMapping} on ${assMapping}.${table.assTableFkColumn} = ${tableMapping}.${table.assTableColumn}
|
#foreach($table in $relTables)
|
||||||
|
${table.queryType} join ${table.relName} on ${table.tableAs}.${table.tableColumn} = ${table.relAs}.${table.relColumn}
|
||||||
|
#end
|
||||||
<where>
|
<where>
|
||||||
#foreach($column in $columns)
|
#foreach($column in $columns)
|
||||||
#set($queryType=$column.queryType)
|
#set($queryType=$column.queryType)
|
||||||
|
|
@ -78,11 +87,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
#foreach($column in $table.assColumns)
|
#foreach($table in $relTables)
|
||||||
|
#foreach($column in $table.relColumns)
|
||||||
#set($queryType=$column.queryType)
|
#set($queryType=$column.queryType)
|
||||||
#set($javaField=$assclassName+'.'+$column.javaField)
|
#set($javaField=$table.relclass + "." + $column.javaField)
|
||||||
#set($javaType=$column.javaType)
|
#set($javaType=$column.javaType)
|
||||||
#set($columnName=$assMapping+'.'+$column.columnName)
|
#set($columnName=$table.relclass+'.'+$column.columnName)
|
||||||
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
#if($column.isQuery.equals("1"))
|
#if($column.isQuery.equals("1"))
|
||||||
#if($column.queryType == "EQ")
|
#if($column.queryType == "EQ")
|
||||||
|
|
@ -100,7 +110,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
#elseif($queryType == "LIKE")
|
#elseif($queryType == "LIKE")
|
||||||
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName like concat('%', #{$javaField}, '%')</if>
|
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName like concat('%', #{$javaField}, '%')</if>
|
||||||
#elseif($queryType == "BETWEEN")
|
#elseif($queryType == "BETWEEN")
|
||||||
<if test="params.assbegin$AttrName != null and params.assbegin$AttrName != '' and params.assend$AttrName != null and params.assend$AttrName != ''"> and $columnName between #{params.assbegin$AttrName} and #{params.assend$AttrName}</if>
|
<if test="${table.relclass}.params.begin$AttrName != null and ${table.relclass}.params.begin$AttrName != '' and ${table.relclass}.params.end$AttrName != null and ${table.relclass}.params.end$AttrName != ''"> and $columnName between #{${table.relclass}.params.begin$AttrName} and #{${table.relclass}.params.end$AttrName}</if>
|
||||||
|
#end
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
|
|
@ -138,8 +149,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
</where>
|
</where>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="select${ClassName}ById" parameterType="${pkColumn.javaType}" resultMap="#if($table.sub)${ClassName}${subClassName}Result#else${ClassName}Result#end">
|
<select id="select${ClassName}ById" parameterType="${pkColumn.javaType}" resultMap="#if($table.sub)${ClassName}${subClassName}Result#elseif($tplCategory.equals("ass"))${ClassName}AllResult#else${ClassName}Result#end">
|
||||||
#if($table.crud || $table.tree)
|
#if($table.crud || $table.tree || $tplCategory.equals("rel"))
|
||||||
<include refid="select${ClassName}Vo"/>
|
<include refid="select${ClassName}Vo"/>
|
||||||
where ${pkColumn.columnName} = #{${pkColumn.javaField}}
|
where ${pkColumn.columnName} = #{${pkColumn.javaField}}
|
||||||
#elseif($table.sub)
|
#elseif($table.sub)
|
||||||
|
|
@ -149,24 +160,30 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
from ${tableName} ${tableMapping}
|
from ${tableName} ${tableMapping}
|
||||||
left join ${subTableName} ${subMapping} on ${subMapping}.${subTableFkName} = ${tableMapping}.${pkColumn.columnName}
|
left join ${subTableName} ${subMapping} on ${subMapping}.${subTableFkName} = ${tableMapping}.${pkColumn.columnName}
|
||||||
where ${tableMapping}.${pkColumn.columnName} = #{${pkColumn.javaField}}
|
where ${tableMapping}.${pkColumn.columnName} = #{${pkColumn.javaField}}
|
||||||
#elseif($table.tplCategory.equals("ass"))
|
#end
|
||||||
select#foreach($column in $columns) ${tableMapping}.$column.columnName#if($velocityCount != $columns.size()),#end#end,
|
</select>
|
||||||
|
#if($tplCategory.equals("rel"))
|
||||||
|
<select id="select${ClassName}AllById" parameterType="${pkColumn.javaType}" resultMap="${ClassName}AllResult">
|
||||||
|
select #foreach($column in $columns) ${tableMapping}.$column.columnName#if($velocityCount != $columns.size()),#end#end,
|
||||||
|
#foreach($table in $relTables)
|
||||||
#set($count = 0)
|
#set($count = 0)
|
||||||
#foreach($column in $table.assColumns)
|
#foreach($column in $table.relColumns)
|
||||||
#if($column.isList == "1")
|
#if($column.isList == "1")
|
||||||
#set($count = $count + 1)
|
#set($count = $count + 1)
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
#set($targetName = "")
|
|
||||||
#set($indexs = 0)
|
#set($indexs = 0)
|
||||||
#foreach($column in $table.assColumns)#if($column.isList == "1")#set($indexs = $indexs + 1)${assMapping}.$column.columnName#if($indexs != $count), #end#end
|
#foreach($column in $table.relColumns) #if($column.isList == "1")#set($indexs = $indexs + 1)${table.relAs}.$column.columnName#if($indexs != $count),#end#end#end#if($velocityCount != $columns.size()),
|
||||||
|
#end
|
||||||
#end
|
#end
|
||||||
|
|
||||||
from ${tableName} ${tableMapping}
|
from ${tableName} ${tableMapping}
|
||||||
${table.assQueryType} join ${table.assTableName} ${assMapping} on ${assMapping}.${table.assTableFkColumn} = ${tableMapping}.${table.assTableColumn}
|
#foreach($table in $relTables)
|
||||||
where ${tableMapping}.${pkColumn.columnName} = #{${pkColumn.javaField}}
|
${table.queryType} join ${table.relName} on ${table.tableAs}.${table.tableColumn} = ${table.relAs}.${table.relColumn}
|
||||||
#end
|
#end
|
||||||
|
where ${tableMapping}.${pkColumn.columnName} = #{${pkColumn.javaField}}
|
||||||
</select>
|
</select>
|
||||||
|
#end
|
||||||
|
|
||||||
<insert id="insert${ClassName}" parameterType="${ClassName}"#if($pkColumn.increment) useGeneratedKeys="true" keyProperty="$pkColumn.javaField"#end>
|
<insert id="insert${ClassName}" parameterType="${ClassName}"#if($pkColumn.increment) useGeneratedKeys="true" keyProperty="$pkColumn.javaField"#end>
|
||||||
insert into ${tableName}
|
insert into ${tableName}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,174 @@
|
||||||
|
package com.hchyun.test.controller;
|
||||||
|
|
||||||
|
import com.hchyun.common.annotation.Log;
|
||||||
|
import com.hchyun.common.constant.ReturnConstants;
|
||||||
|
import com.hchyun.common.core.controller.HcyBaseController;
|
||||||
|
import com.hchyun.common.core.entity.AjaxResult;
|
||||||
|
import com.hchyun.common.enums.BusinessType;
|
||||||
|
import com.hchyun.common.utils.ServerResult;
|
||||||
|
import com.hchyun.common.utils.poi.ExcelUtil;
|
||||||
|
import com.hchyun.test.entity.RelA;
|
||||||
|
import com.hchyun.test.service.RelAService;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试aController
|
||||||
|
*
|
||||||
|
* @author hchyun
|
||||||
|
* @date 2021-02-26
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Api(value = "测试a管理",tags = "测试a管理")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/test/a")
|
||||||
|
public class RelAController extends HcyBaseController {
|
||||||
|
protected final Logger logger = LoggerFactory.getLogger(RelAController.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RelAService relAService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询测试a列表
|
||||||
|
*/
|
||||||
|
@ApiOperation("查询测试a列表")
|
||||||
|
@PreAuthorize("@hchyun.hasPermi('test:a:list')")
|
||||||
|
@PutMapping("/list")
|
||||||
|
public Serializable list(@Validated @RequestBody RelA relA) {
|
||||||
|
try {
|
||||||
|
startPage(relA.getParams());
|
||||||
|
ServerResult<List<RelA>> genServerResult = relAService.selectRelAList(relA);
|
||||||
|
if (genServerResult.isStart()) {
|
||||||
|
return AjaxResult.success(genServerResult.getData());
|
||||||
|
} else {
|
||||||
|
return AjaxResult.info(genServerResult.getMsg());
|
||||||
|
}
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
logger.error(e.getMessage());
|
||||||
|
return AjaxResult.error(ReturnConstants.SYS_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出测试a列表
|
||||||
|
*/
|
||||||
|
@ApiOperation("导出测试a列表")
|
||||||
|
@PreAuthorize("@hchyun.hasPermi('test:a:export')")
|
||||||
|
@Log(title = "测试a", businessType = BusinessType.EXPORT)
|
||||||
|
@PutMapping("/export")
|
||||||
|
public AjaxResult export(@Validated @RequestBody RelA relA) {
|
||||||
|
try {
|
||||||
|
ServerResult<List<RelA>> genServerResult = relAService.selectRelAList(relA);
|
||||||
|
ExcelUtil<RelA> util = new ExcelUtil<RelA>(RelA. class);
|
||||||
|
if (genServerResult.isStart()) {
|
||||||
|
return util.exportExcel(genServerResult.getData(), "a");
|
||||||
|
} else {
|
||||||
|
return AjaxResult.error(genServerResult.getMsg());
|
||||||
|
}
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
logger.error(e.getMessage());
|
||||||
|
return AjaxResult.error(ReturnConstants.SYS_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取测试a详细信息
|
||||||
|
*/
|
||||||
|
@ApiOperation("获取测试a详细信息")
|
||||||
|
@ApiImplicitParam(name = "aid" , value = "测试aaid" , required = true, dataType = "Long" , paramType = "path")
|
||||||
|
@PreAuthorize("@hchyun.hasPermi('test:a:query')")
|
||||||
|
@GetMapping(value = "/{aid}")
|
||||||
|
public AjaxResult getInfo(@PathVariable("aid") Long aid) {
|
||||||
|
try {
|
||||||
|
ServerResult<RelA> genServerResult = relAService.selectRelAById(aid);
|
||||||
|
if (genServerResult.isStart()) {
|
||||||
|
return AjaxResult.success(genServerResult.getData());
|
||||||
|
} else {
|
||||||
|
return AjaxResult.info(genServerResult.getMsg());
|
||||||
|
}
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
logger.error(e.getMessage());
|
||||||
|
return AjaxResult.error(ReturnConstants.SYS_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增测试a
|
||||||
|
*/
|
||||||
|
@ApiOperation("新增测试a")
|
||||||
|
@ApiImplicitParam(name = "relA" , value = "新增测试a信息" , dataType = "RelA")
|
||||||
|
@PreAuthorize("@hchyun.hasPermi('test:a:add')")
|
||||||
|
@Log(title = "测试a", businessType = BusinessType.INSERT)
|
||||||
|
@PostMapping
|
||||||
|
public AjaxResult add(@RequestBody RelA relA) {
|
||||||
|
try {
|
||||||
|
ServerResult<Integer> genServerResult = relAService.insertRelA(relA);
|
||||||
|
if (genServerResult.isStart()) {
|
||||||
|
return AjaxResult.success();
|
||||||
|
} else {
|
||||||
|
return AjaxResult.error(genServerResult.getMsg());
|
||||||
|
}
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
logger.error(e.getMessage());
|
||||||
|
return AjaxResult.error(ReturnConstants.SYS_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改测试a
|
||||||
|
*/
|
||||||
|
@ApiOperation("修改测试a")
|
||||||
|
@ApiImplicitParam(name = "relA" , value = "修改测试a信息" , dataType = "RelA")
|
||||||
|
@PreAuthorize("@hchyun.hasPermi('test:a:edit')")
|
||||||
|
@Log(title = "测试a", businessType = BusinessType.UPDATE)
|
||||||
|
@PutMapping
|
||||||
|
public AjaxResult edit(@RequestBody RelA relA) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
ServerResult<Integer> genServerResult = relAService.updateRelA(relA);
|
||||||
|
if (genServerResult.isStart()) {
|
||||||
|
return AjaxResult.success();
|
||||||
|
} else {
|
||||||
|
return AjaxResult.error(genServerResult.getMsg());
|
||||||
|
}
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
logger.error(e.getMessage());
|
||||||
|
return AjaxResult.error(ReturnConstants.SYS_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除测试a
|
||||||
|
*/
|
||||||
|
@ApiOperation("删除测试a")
|
||||||
|
@ApiImplicitParam(name = "aids" , value = "测试aaids" , required = true, dataType = "Long" , paramType = "path")
|
||||||
|
@PreAuthorize("@hchyun.hasPermi('test:a:remove')")
|
||||||
|
@Log(title = "测试a", businessType = BusinessType.DELETE)
|
||||||
|
@DeleteMapping("/{aids}")
|
||||||
|
public AjaxResult remove(@PathVariable Long[] aids) {
|
||||||
|
try {
|
||||||
|
if (aids.length<0){
|
||||||
|
return AjaxResult.error("id不能为空!");
|
||||||
|
}
|
||||||
|
ServerResult<Integer> genServerResult = relAService.deleteRelAByIds(aids);
|
||||||
|
if (genServerResult.isStart()) {
|
||||||
|
return AjaxResult.success();
|
||||||
|
} else {
|
||||||
|
return AjaxResult.error(genServerResult.getMsg());
|
||||||
|
}
|
||||||
|
}catch (RuntimeException e){
|
||||||
|
logger.error(e.getMessage());
|
||||||
|
return AjaxResult.error(ReturnConstants.SYS_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,61 @@
|
||||||
|
package com.hchyun.test.dao;
|
||||||
|
|
||||||
|
import com.hchyun.test.entity.RelA;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试aMapper接口
|
||||||
|
*
|
||||||
|
* @author hchyun
|
||||||
|
* @date 2021-02-26
|
||||||
|
*/
|
||||||
|
public interface RelADao {
|
||||||
|
/**
|
||||||
|
* 查询测试a
|
||||||
|
*
|
||||||
|
* @param aid 测试aID
|
||||||
|
* @return 测试a
|
||||||
|
*/
|
||||||
|
RelA selectRelAById(Long aid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询测试a列表
|
||||||
|
*
|
||||||
|
* @param relA 测试a
|
||||||
|
* @return 测试a集合
|
||||||
|
*/
|
||||||
|
List<RelA> selectRelAList(RelA relA);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增测试a
|
||||||
|
*
|
||||||
|
* @param relA 测试a
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
int insertRelA(RelA relA);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改测试a
|
||||||
|
*
|
||||||
|
* @param relA 测试a
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
int updateRelA(RelA relA);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除测试a
|
||||||
|
*
|
||||||
|
* @param aid 测试aID
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
int deleteRelAById(Long aid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除测试a
|
||||||
|
*
|
||||||
|
* @param aids 需要删除的数据ID
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
int deleteRelAByIds(Long[] aids);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,77 @@
|
||||||
|
package com.hchyun.test.entity;
|
||||||
|
|
||||||
|
import com.hchyun.common.annotation.Excel;
|
||||||
|
import com.hchyun.common.annotation.Excels;
|
||||||
|
import com.hchyun.common.core.entity.BaseEntity;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试a对象 test_rel_a
|
||||||
|
*
|
||||||
|
* @author hchyun
|
||||||
|
* @date 2021-02-26
|
||||||
|
*/
|
||||||
|
@ApiModel("测试a")
|
||||||
|
public class RelA extends BaseEntity{
|
||||||
|
|
||||||
|
/** id表a */
|
||||||
|
@ApiModelProperty("id表a")
|
||||||
|
private Long aid;
|
||||||
|
|
||||||
|
/** a表信息 */
|
||||||
|
@Excel(name = "a表信息")
|
||||||
|
@ApiModelProperty("a表信息")
|
||||||
|
private String infoa;
|
||||||
|
|
||||||
|
|
||||||
|
/** 测试c表信息 */
|
||||||
|
@Excels({@Excel(name = "关联ID",targetAttr = "uniconId"),@Excel(name = "c表id",targetAttr = "cid"),@Excel(name = "c表信息",targetAttr = "infoc"),})
|
||||||
|
private RelC relC;
|
||||||
|
|
||||||
|
/** 测试b表信息 */
|
||||||
|
@Excels({@Excel(name = "信息b",targetAttr = "infob"),@Excel(name = "关联id",targetAttr = "uniconId"),@Excel(name = "b表id",targetAttr = "bid"),})
|
||||||
|
private RelB relB;
|
||||||
|
|
||||||
|
|
||||||
|
public void setAid(Long aid){
|
||||||
|
this.aid = aid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getAid(){
|
||||||
|
return aid;
|
||||||
|
}
|
||||||
|
public void setInfoa(String infoa){
|
||||||
|
this.infoa = infoa;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getInfoa(){
|
||||||
|
return infoa;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RelC getRelC(){
|
||||||
|
return relC;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRelC(RelC relC){
|
||||||
|
this.relC = relC;
|
||||||
|
}
|
||||||
|
public RelB getRelB(){
|
||||||
|
return relB;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRelB(RelB relB){
|
||||||
|
this.relB = relB;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
|
||||||
|
.append("aid", getAid())
|
||||||
|
.append("infoa", getInfoa())
|
||||||
|
.append("relC",getRelC())
|
||||||
|
.append("relB",getRelB())
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
package com.hchyun.test.entity;
|
||||||
|
|
||||||
|
import com.hchyun.common.annotation.Excel;
|
||||||
|
import com.hchyun.common.core.entity.BaseEntity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author hchyun
|
||||||
|
* @date 2021-02-26
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class RelB extends BaseEntity{
|
||||||
|
|
||||||
|
/** b表id */
|
||||||
|
@Excel(name = "b表id")
|
||||||
|
private Long bid;
|
||||||
|
|
||||||
|
/** 关联id */
|
||||||
|
@Excel(name = "关联id")
|
||||||
|
private Long uniconId;
|
||||||
|
|
||||||
|
/** 信息b */
|
||||||
|
@Excel(name = "信息b")
|
||||||
|
private String infob;
|
||||||
|
|
||||||
|
|
||||||
|
public void setBid(Long bid){
|
||||||
|
this.bid = bid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getBid(){
|
||||||
|
return bid;
|
||||||
|
}
|
||||||
|
public void setUniconId(Long uniconId){
|
||||||
|
this.uniconId = uniconId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getUniconId(){
|
||||||
|
return uniconId;
|
||||||
|
}
|
||||||
|
public void setInfob(String infob){
|
||||||
|
this.infob = infob;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getInfob(){
|
||||||
|
return infob;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
package com.hchyun.test.entity;
|
||||||
|
|
||||||
|
import com.hchyun.common.annotation.Excel;
|
||||||
|
import com.hchyun.common.core.entity.BaseEntity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author hchyun
|
||||||
|
* @date 2021-02-26
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class RelC extends BaseEntity{
|
||||||
|
|
||||||
|
/** c表id */
|
||||||
|
@Excel(name = "c表id")
|
||||||
|
private Long cid;
|
||||||
|
|
||||||
|
/** 关联ID */
|
||||||
|
@Excel(name = "关联ID")
|
||||||
|
private Long uniconId;
|
||||||
|
|
||||||
|
/** c表信息 */
|
||||||
|
@Excel(name = "c表信息")
|
||||||
|
private String infoc;
|
||||||
|
|
||||||
|
|
||||||
|
public void setCid(Long cid){
|
||||||
|
this.cid = cid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getCid(){
|
||||||
|
return cid;
|
||||||
|
}
|
||||||
|
public void setUniconId(Long uniconId){
|
||||||
|
this.uniconId = uniconId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getUniconId(){
|
||||||
|
return uniconId;
|
||||||
|
}
|
||||||
|
public void setInfoc(String infoc){
|
||||||
|
this.infoc = infoc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getInfoc(){
|
||||||
|
return infoc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,63 @@
|
||||||
|
package com.hchyun.test.service;
|
||||||
|
|
||||||
|
import com.hchyun.common.utils.ServerResult;
|
||||||
|
import com.hchyun.test.entity.RelA;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试aService接口
|
||||||
|
*
|
||||||
|
* @author hchyun
|
||||||
|
* @date 2021-02-26
|
||||||
|
*/
|
||||||
|
public interface RelAService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 查询测试a
|
||||||
|
*
|
||||||
|
* @param aid 测试aID
|
||||||
|
* @return 测试a
|
||||||
|
*/
|
||||||
|
ServerResult<RelA> selectRelAById(Long aid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询测试a列表
|
||||||
|
*
|
||||||
|
* @param relA 测试a
|
||||||
|
* @return 测试a集合
|
||||||
|
*/
|
||||||
|
ServerResult<List<RelA>> selectRelAList(RelA relA);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增测试a
|
||||||
|
*
|
||||||
|
* @param relA 测试a
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
ServerResult<Integer> insertRelA(RelA relA);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改测试a
|
||||||
|
*
|
||||||
|
* @param relA 测试a
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
ServerResult<Integer> updateRelA(RelA relA);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除测试a
|
||||||
|
*
|
||||||
|
* @param aids 需要删除的测试aID
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
ServerResult<Integer> deleteRelAByIds(Long[] aids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除测试a信息
|
||||||
|
*
|
||||||
|
* @param aid 测试aID
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
ServerResult<Integer> deleteRelAById(Long aid);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,153 @@
|
||||||
|
package com.hchyun.test.service.impl;
|
||||||
|
|
||||||
|
import com.hchyun.common.constant.ReturnConstants;
|
||||||
|
import com.hchyun.common.utils.ServerResult;
|
||||||
|
import com.hchyun.test.dao.RelADao;
|
||||||
|
import com.hchyun.test.entity.RelA;
|
||||||
|
import com.hchyun.test.service.RelAService;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试aService业务层处理
|
||||||
|
*
|
||||||
|
* @author hchyun
|
||||||
|
* @date 2021-02-26
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class RelAServiceImpl implements RelAService {
|
||||||
|
private Logger logger = LoggerFactory.getLogger(RelAServiceImpl.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RelADao relADao;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询测试a
|
||||||
|
*
|
||||||
|
* @param aid 测试aID
|
||||||
|
* @return 测试a
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ServerResult<RelA> selectRelAById(Long aid) {
|
||||||
|
try {
|
||||||
|
RelA relA = relADao.selectRelAById(aid);
|
||||||
|
if (relA != null){
|
||||||
|
return new ServerResult<RelA>(true,relA);
|
||||||
|
}else {
|
||||||
|
return new ServerResult<RelA>(false, ReturnConstants.RESULT_EMPTY);
|
||||||
|
}
|
||||||
|
}catch (RuntimeException e){
|
||||||
|
logger.error(e.getMessage());
|
||||||
|
return new ServerResult<RelA>(false,ReturnConstants.DB_EX);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询测试a列表
|
||||||
|
*
|
||||||
|
* @param relA 测试a
|
||||||
|
* @return 测试a
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ServerResult<List<RelA>> selectRelAList(RelA relA) {
|
||||||
|
try {
|
||||||
|
List<RelA> relAList = relADao.selectRelAList(relA);
|
||||||
|
if (relAList.size()>0){
|
||||||
|
return new ServerResult<List<RelA>>(true,relAList);
|
||||||
|
}else {
|
||||||
|
return new ServerResult<List<RelA>>(false,ReturnConstants.RESULT_EMPTY);
|
||||||
|
}
|
||||||
|
}catch (RuntimeException e){
|
||||||
|
logger.error(e.getMessage());
|
||||||
|
return new ServerResult<List<RelA>>(false,ReturnConstants.DB_EX);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增测试a
|
||||||
|
*
|
||||||
|
* @param relA 测试a
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ServerResult<Integer> insertRelA(RelA relA) {
|
||||||
|
try {
|
||||||
|
Integer renewal = relADao.insertRelA(relA);
|
||||||
|
if (renewal >0){
|
||||||
|
return new ServerResult<>(true,renewal);
|
||||||
|
}else {
|
||||||
|
return new ServerResult<>(false,ReturnConstants.SYS_FAILL);
|
||||||
|
}
|
||||||
|
}catch (RuntimeException e){
|
||||||
|
logger.error(e.getMessage());
|
||||||
|
return new ServerResult<>(false,ReturnConstants.DB_EX);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改测试a
|
||||||
|
*
|
||||||
|
* @param relA 测试a
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ServerResult<Integer> updateRelA(RelA relA) {
|
||||||
|
try {
|
||||||
|
Integer renewal = relADao.updateRelA(relA);
|
||||||
|
if (renewal >0){
|
||||||
|
return new ServerResult<>(true,renewal);
|
||||||
|
}else {
|
||||||
|
return new ServerResult<>(false,ReturnConstants.SYS_FAILL);
|
||||||
|
}
|
||||||
|
}catch (RuntimeException e){
|
||||||
|
logger.error(e.getMessage());
|
||||||
|
return new ServerResult<>(false,ReturnConstants.DB_EX);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除测试a
|
||||||
|
*
|
||||||
|
* @param aids 需要删除的测试aID
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ServerResult<Integer> deleteRelAByIds(Long[] aids) {
|
||||||
|
try {
|
||||||
|
Integer renewal = relADao.deleteRelAByIds(aids);
|
||||||
|
if (renewal >0){
|
||||||
|
return new ServerResult<>(true,renewal);
|
||||||
|
}else {
|
||||||
|
return new ServerResult<>(false,ReturnConstants.SYS_FAILL);
|
||||||
|
}
|
||||||
|
}catch (RuntimeException e){
|
||||||
|
logger.error(e.getMessage());
|
||||||
|
return new ServerResult<>(false,ReturnConstants.DB_EX);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除测试a信息
|
||||||
|
*
|
||||||
|
* @param aid 测试aID
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ServerResult<Integer> deleteRelAById(Long aid) {
|
||||||
|
try {
|
||||||
|
Integer renewal = relADao.deleteRelAById(aid);
|
||||||
|
if (renewal >0){
|
||||||
|
return new ServerResult<>(true,renewal);
|
||||||
|
}else {
|
||||||
|
return new ServerResult<>(false,ReturnConstants.SYS_FAILL);
|
||||||
|
}
|
||||||
|
}catch (RuntimeException e){
|
||||||
|
logger.error(e.getMessage());
|
||||||
|
return new ServerResult<>(false,ReturnConstants.DB_EX);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,71 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.hchyun.test.dao.RelADao">
|
||||||
|
|
||||||
|
<resultMap type="com.hchyun.test.entity.RelA" id="RelAResult">
|
||||||
|
<result property="aid" column="aid" />
|
||||||
|
<result property="infoa" column="infoa" />
|
||||||
|
</resultMap>
|
||||||
|
<resultMap id="RelAAllResult" type="com.hchyun.test.entity.RelA" extends="RelAResult">
|
||||||
|
<collection property="RelC" notNullColumn="unicon_id" javaType="com.hchyun.test.entity.RelC" resultMap="RelCResult" />
|
||||||
|
<collection property="RelB" notNullColumn="unicon_id" javaType="com.hchyun.test.entity.RelB" resultMap="RelBResult" />
|
||||||
|
</resultMap>
|
||||||
|
<resultMap id="RelCResult" type="com.hchyun.test.entity.RelC">
|
||||||
|
<result property="uniconId" column="unicon_id" />
|
||||||
|
<result property="cid" column="cId" />
|
||||||
|
<result property="infoc" column="infoc" />
|
||||||
|
</resultMap>
|
||||||
|
<resultMap id="RelBResult" type="com.hchyun.test.entity.RelB">
|
||||||
|
<result property="infob" column="infob" />
|
||||||
|
<result property="uniconId" column="unicon_id" />
|
||||||
|
<result property="bid" column="bid" />
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<sql id="selectRelAVo">
|
||||||
|
select aid, infoa from test_rel_a
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
|
||||||
|
<select id="selectRelAList" parameterType="RelA" resultMap="RelAAllResult">
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectRelAById" parameterType="Long" resultMap="RelAResult">
|
||||||
|
<include refid="selectRelAVo"/>
|
||||||
|
where aid = #{aid}
|
||||||
|
</select>
|
||||||
|
<select id="selectRelAAllById" parameterType="Long" resultMap="RelAAllResult">
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<insert id="insertRelA" parameterType="RelA">
|
||||||
|
insert into test_rel_a
|
||||||
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||||
|
<if test="aid != null">aid,</if>
|
||||||
|
<if test="infoa != null">infoa,</if>
|
||||||
|
</trim>
|
||||||
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
|
<if test="aid != null">#{aid},</if>
|
||||||
|
<if test="infoa != null">#{infoa},</if>
|
||||||
|
</trim>
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<update id="updateRelA" parameterType="RelA">
|
||||||
|
update test_rel_a
|
||||||
|
<trim prefix="SET" suffixOverrides=",">
|
||||||
|
<if test="infoa != null">infoa = #{infoa},</if>
|
||||||
|
</trim>
|
||||||
|
where aid = #{aid}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<delete id="deleteRelAById" parameterType="Long">
|
||||||
|
delete from test_rel_a where aid = #{aid}
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<delete id="deleteRelAByIds" parameterType="String">
|
||||||
|
delete from test_rel_a where aid in
|
||||||
|
<foreach item="aid" collection="array" open="(" separator="," close=")">
|
||||||
|
#{aid}
|
||||||
|
</foreach>
|
||||||
|
</delete>
|
||||||
|
</mapper>
|
||||||
Loading…
Reference in New Issue