开发基础主数据查询根据配置动态分页查询功能
parent
513c0eac2e
commit
3afe3b4b9d
|
@ -5,7 +5,7 @@ import org.springframework.boot.SpringApplication;
|
|||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
@MapperScan("com.songpeng.sparchetype.*.mapper*")
|
||||
@MapperScan("com.songpeng.sparchetype.**.mapper*")
|
||||
public class SparchetypeApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
package com.songpeng.sparchetype.basedata.common.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.songpeng.sparchetype.basedata.common.request.QueryTableNameDataReq;
|
||||
import com.songpeng.sparchetype.basedata.common.service.QueryTableNameDataService;
|
||||
import com.songpeng.sparchetype.common.Result;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author wangziyang
|
||||
*
|
||||
* <p>对基础数据表CURD控制器</p>
|
||||
* @since 2020/03/11
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/common/query")
|
||||
public class QueryTableNameDataController {
|
||||
/**
|
||||
* 通用基础数据service
|
||||
*/
|
||||
@Autowired
|
||||
private QueryTableNameDataService queryTableNameDataService;
|
||||
|
||||
/**
|
||||
* 根据参数查询的表名称,拼接SQL语句分页查询
|
||||
*
|
||||
* @param req 请求参数
|
||||
* @return Result 执行结果
|
||||
*/
|
||||
@ApiOperation("主数据表头分页查询")
|
||||
@ApiImplicitParams({@ApiImplicitParam(name = "req", value = "请求参数", defaultValue = "请求参数")})
|
||||
@PostMapping("/page")
|
||||
@ResponseBody
|
||||
public Result page(QueryTableNameDataReq req) throws Exception {
|
||||
if (StringUtils.isEmpty(req.getTableName()) || StringUtils.isEmpty(req.getTableNameId())) {
|
||||
throw new Exception("未选中表信息");
|
||||
}
|
||||
IPage<Map<String, String>> page = queryTableNameDataService.queryTableNameDataList(req);
|
||||
return Result.success(page);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.songpeng.sparchetype.basedata.common.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.songpeng.sparchetype.basedata.common.request.QueryTableNameDataReq;
|
||||
import com.songpeng.sparchetype.basedata.entity.SpTableManagerItem;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 基础数据查询maper
|
||||
*
|
||||
* @author WANGZIYANG
|
||||
* @since 2020/03/11
|
||||
*/
|
||||
public interface QueryTableNameDataMapper extends BaseMapper<SpTableManagerItem> {
|
||||
/**
|
||||
* 基础数据通用查询服务
|
||||
*
|
||||
* @param col 列组合
|
||||
* @param tableName 表名称
|
||||
* @return 数据集合
|
||||
*/
|
||||
List<Map<String, String>> queryTableNameDataList(QueryTableNameDataReq req);
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package com.songpeng.sparchetype.basedata.common.request;
|
||||
|
||||
import com.songpeng.sparchetype.common.BasePageReq;
|
||||
|
||||
/**
|
||||
* @author wangziyang
|
||||
* @since 2020/03/11
|
||||
* 基础数据通用分页查询 对象
|
||||
*/
|
||||
public class QueryTableNameDataReq extends BasePageReq {
|
||||
/**
|
||||
* 表配置明细字段关联ID
|
||||
*/
|
||||
private String tableNameId;
|
||||
|
||||
/**
|
||||
* 表名称
|
||||
*/
|
||||
private String tableName;
|
||||
|
||||
private String col;
|
||||
|
||||
/**
|
||||
* 获取 表配置明细字段关联ID
|
||||
*
|
||||
* @return tableNameId 表配置明细字段关联ID
|
||||
*/
|
||||
public String getTableNameId() {
|
||||
return this.tableNameId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 表配置明细字段关联ID
|
||||
*
|
||||
* @param tableNameId 表配置明细字段关联ID
|
||||
*/
|
||||
public void setTableNameId(String tableNameId) {
|
||||
this.tableNameId = tableNameId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 表名称
|
||||
*
|
||||
* @return tableName 表名称
|
||||
*/
|
||||
public String getTableName() {
|
||||
return this.tableName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 表名称
|
||||
*
|
||||
* @param tableName 表名称
|
||||
*/
|
||||
public void setTableName(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public String getCol() {
|
||||
return col;
|
||||
}
|
||||
|
||||
public void setCol(String col) {
|
||||
this.col = col;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.songpeng.sparchetype.basedata.common.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.songpeng.sparchetype.basedata.common.request.QueryTableNameDataReq;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author wangziyang
|
||||
* @since 2020/03/11
|
||||
* 基础数据通用CURD服务接口
|
||||
*/
|
||||
public interface QueryTableNameDataService {
|
||||
/**
|
||||
* 基础数据通用查询服务
|
||||
*
|
||||
* @param req 列组合
|
||||
* @return 数据集合
|
||||
*/
|
||||
IPage<Map<String, String>> queryTableNameDataList(QueryTableNameDataReq req);
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package com.songpeng.sparchetype.basedata.common.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.google.inject.internal.util.$Nullable;
|
||||
import com.songpeng.sparchetype.basedata.common.mapper.QueryTableNameDataMapper;
|
||||
import com.songpeng.sparchetype.basedata.common.request.QueryTableNameDataReq;
|
||||
import com.songpeng.sparchetype.basedata.common.service.QueryTableNameDataService;
|
||||
import com.songpeng.sparchetype.basedata.entity.SpTableManagerItem;
|
||||
import com.songpeng.sparchetype.basedata.service.ISpTableManagerItemService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 基础数据通用查询service
|
||||
*
|
||||
* @author wangziyang
|
||||
* @since 2020/03/11
|
||||
*/
|
||||
@Service
|
||||
public class QueryTableNameDataServiceImpl implements QueryTableNameDataService {
|
||||
/**
|
||||
* 基础数据通用查询mpapper
|
||||
*/
|
||||
@Autowired
|
||||
public QueryTableNameDataMapper queryTableNameDataMapper;
|
||||
/**
|
||||
* 查询配置表明细服务
|
||||
*/
|
||||
@Autowired
|
||||
public ISpTableManagerItemService iSpTableManagerItemService;
|
||||
|
||||
/**
|
||||
* 基础数据通用查询服务
|
||||
*
|
||||
* @param page 分页对象
|
||||
* @return 数据集合
|
||||
*/
|
||||
@Override
|
||||
public IPage<Map<String, String>> queryTableNameDataList(QueryTableNameDataReq page) {
|
||||
List<SpTableManagerItem> spTableManagerItems = iSpTableManagerItemService.queryItemBytableNameId(page.getTableNameId());
|
||||
StringBuilder col = new StringBuilder();
|
||||
for (SpTableManagerItem spTableManagerItem : spTableManagerItems) {
|
||||
col.append(spTableManagerItem.getField() + ",");
|
||||
}
|
||||
//剔除拼接最后的一个逗号
|
||||
String lastCol = col.substring(0, col.length() - 1);
|
||||
page.setCol(lastCol);
|
||||
page.setRecords(queryTableNameDataMapper.queryTableNameDataList(page));
|
||||
return page;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
<?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.songpeng.sparchetype.basedata.common.mapper.QueryTableNameDataMapper">
|
||||
|
||||
<!--基础数据通用查询-->
|
||||
<select id="queryTableNameDataList" resultType="java.util.Map">
|
||||
SELECT ${col} FROM ${tableName}
|
||||
</select>
|
||||
</mapper>
|
|
@ -324,13 +324,11 @@
|
|||
}
|
||||
});
|
||||
//打码规则项渲染赋值
|
||||
console.log(ruleDetailRows);
|
||||
$.each(ruleDetailRows, function (index, item) {
|
||||
var inputId = addRuleDetail();
|
||||
//必填项
|
||||
$('#js-must-fill-' + inputId).val(item.mustFill);
|
||||
//字段名称
|
||||
console.log(item.field);
|
||||
$('#js-rule-item-type-' + inputId).val(item.field);
|
||||
//字段详细名称
|
||||
$('#js-field-desc-' + inputId).val(item.fieldDesc);
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
<body>
|
||||
<div class="splayui-container">
|
||||
<div class="layui-row">
|
||||
<div class="layui-col-md3 layui-bg-gray" >
|
||||
<div class="layui-col-md3 layui-bg-gray">
|
||||
<table id="js-table-name" lay-filter="js-table-name-filter"></table>
|
||||
</div>
|
||||
<div class="layui-col-md9">
|
||||
|
@ -22,7 +22,8 @@
|
|||
<div class="layui-inline">
|
||||
<label class="layui-form-label">表名称</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" name="tableName" autocomplete="off" class="layui-input">
|
||||
<input id="js-search-test" type="text" name="tableName" autocomplete="off"
|
||||
readonly="true" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-inline">
|
||||
|
@ -65,44 +66,11 @@
|
|||
table = layui.table,
|
||||
splayer = layui.splayer,
|
||||
sptable = layui.sptable;
|
||||
colsArr = [];
|
||||
ruleDetailRows = {};
|
||||
|
||||
// 表格及数据初始化
|
||||
var tableIns = sptable.render({
|
||||
url: '${request.contextPath}/basedata/manager/page',
|
||||
cols: [
|
||||
[{
|
||||
type: 'checkbox'
|
||||
}, {
|
||||
field: 'tableName', title: '表名称', width: 120
|
||||
}, {
|
||||
field: 'tableDesc', title: '业务描述', width: 130
|
||||
}, {
|
||||
field: 'createUsername', title: '创建用户', width: 130
|
||||
}, {
|
||||
field: 'createTime', title: '创建时间', width: 160
|
||||
}, {
|
||||
field: 'updateUsername', title: '更改用户', width: 130
|
||||
}, {
|
||||
field: 'updateTime', title: '更改时间', width: 160
|
||||
}, {
|
||||
field: 'isDeleted', title: '状态', width: 90, templet: function (records) {
|
||||
return spConfig.isDeletedDict[records.isDeleted];
|
||||
}
|
||||
}, {
|
||||
fixed: 'right',
|
||||
field: 'operate',
|
||||
title: '操作',
|
||||
toolbar: '#js-record-table-toolbar-right',
|
||||
unresize: true,
|
||||
width: 150
|
||||
}]
|
||||
],
|
||||
done: function (res, curr, count) {
|
||||
}
|
||||
});
|
||||
|
||||
// 表格及数据初始化
|
||||
var tableIns = sptable.render({
|
||||
// 左侧表格及数据初始化
|
||||
var tableName = sptable.render({
|
||||
toolbar: '',
|
||||
elem: '#js-table-name',//指定原始表格元素选择器(推荐id选择器)
|
||||
height: 'full-24',
|
||||
|
@ -118,6 +86,58 @@
|
|||
}
|
||||
});
|
||||
|
||||
//监听行单击事件 初始化表明细
|
||||
table.on('row(js-table-name-filter)', function (obj) {
|
||||
$('#js-search-test').val(obj.data.tableDesc);
|
||||
//初始化数据
|
||||
colsArr = [];
|
||||
//动态拼接需要表格明细需要显示的列头
|
||||
buildcol(obj.data.id);
|
||||
// 表格数据明细初始化
|
||||
var tableIns = sptable.render({
|
||||
url: '${request.contextPath}/common/query/page',
|
||||
cols: [colsArr],
|
||||
where: { tableNameId: obj.data.id,tableName :obj.data.tableName},
|
||||
done: function (res, curr, count) {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
//动态拼接需要表格需要显示的列头
|
||||
function buildcol(id) {
|
||||
// 1. ajax 获取表头数据
|
||||
spUtil.ajax({
|
||||
url: '${request.contextPath}/basedata/manager/item/by/tableNameId',
|
||||
async: false,
|
||||
type: 'POST',
|
||||
// 是否显示 loading
|
||||
showLoading: true,
|
||||
// 是否序列化参数
|
||||
serializable: false,
|
||||
// 参数
|
||||
data: {
|
||||
tableNameId: id
|
||||
},
|
||||
success: function (data) {
|
||||
ruleDetailRows = data.data;
|
||||
}
|
||||
});
|
||||
// 2. 构造layui表头结构
|
||||
$.each(ruleDetailRows, function (index, item) {
|
||||
colsArr.push({
|
||||
field: item.field, title: item.fieldDesc
|
||||
})
|
||||
});
|
||||
colsArr.push({
|
||||
fixed: 'right',
|
||||
field: 'operate',
|
||||
title: '操作',
|
||||
toolbar: '#js-record-table-toolbar-right',
|
||||
unresize: true,
|
||||
width: 150
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* 数据表格中form表单元素是动态插入,所以需要更新渲染下
|
||||
* http://www.layui.com/doc/modules/form.html#render
|
||||
|
@ -125,7 +145,6 @@
|
|||
$(function () {
|
||||
form.render();
|
||||
});
|
||||
|
||||
/**
|
||||
* 搜索按钮事件
|
||||
*/
|
||||
|
@ -212,7 +231,8 @@
|
|||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
})
|
||||
;
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue