提交 741c3139 authored 作者: 钟是志's avatar 钟是志

12501 所有-自定义统计,查询结果优化

上级 512fe19b
......@@ -72,7 +72,7 @@
.title2{
position: absolute;
top: 43px;
right:-50px;
right:-70px;
transform:rotate(30deg)
}
......
import React from 'react';
import ReactDOM from 'react-dom';
import { Select, Button, Modal, Input, Table, Row, Col, Tag, Form, message ,notification } from 'antd';
import { connect } from 'dva';
import { getToken } from '../utils/token'
import {Select, Button, Modal, Input, Table, Row, Col, Tag, Form, message, notification} from 'antd';
import {connect} from 'dva';
import {getToken} from '../utils/token'
import config from '@/webPublic/one_stop_public/config';
import QueryItem from './QueryItem';
import OrderItem from './OrderItem';
import styles from './Ability.css';
import FormdataWrapper from '../utils/object-to-formdata-custom';
import ButtonDiy from './ButtonDiy/ButtonDiy';
const Option = Select.Option;
const nameSpan = {
small: 9,
......@@ -31,7 +32,7 @@ function swapArray(arr, index1, index2) {
}
const FormItem = Form.Item;
@connect(({ cms, loading }) => ({
@connect(({cms, loading}) => ({
cms,
loading: loading.models.cms,
}))
......@@ -40,7 +41,7 @@ export default class StatisticsInfo extends React.Component {
constructor(props) {
super(props);
this.state = {
exportLoading:false,
exportLoading: false,
visiable: false,
queryVisiable: false,
groupVisiable: false,
......@@ -74,17 +75,17 @@ export default class StatisticsInfo extends React.Component {
}
onSelectChange = (sourceSelectedKeys, targetSelectedKeys) => {
this.setState({ sourceSelectedKeys, targetSelectedKeys });
this.setState({sourceSelectedKeys, targetSelectedKeys});
};
deleteQuery = (i) => {
const querys = this.state.querys;
querys.splice(i);
this.setState({ querys });
this.setState({querys});
};
deleteOrder = (i) => {
const orders = this.state.orders;
orders.splice(i);
this.setState({ orders });
this.setState({orders});
};
deleteGroup = (i) => {
const groups = this.state.groups;
......@@ -92,12 +93,12 @@ export default class StatisticsInfo extends React.Component {
this.setState(
{
groups
},()=>{
}, () => {
this.finish();
});
};
open = () => {
const { dispatch } = this.props;
const {dispatch} = this.props;
dispatch({
......@@ -149,30 +150,30 @@ export default class StatisticsInfo extends React.Component {
}
this.setState({
mockData, mockXZData,infos, visiable: true, qs, gs, os,
mockData, mockXZData, infos, visiable: true, qs, gs, os,
});
},
});
};
onCancle = () => {
this.setState({ visiable: false });
this.setState({visiable: false});
};
handleChange = (targetKeys, direction, moveKeys) => {
this.setState({ targetKeys });
this.setState({targetKeys});
};
addOrder = () => {
this.setState({ orderVisiable: true });
this.setState({orderVisiable: true});
};
okOrder = () => {
const orders = this.state.orders;
orders.push(this.state.infos[this.state.currentOrderKey]);
this.setState({ orders, orderVisiable: false, currentOrderKey: null });
this.setState({orders, orderVisiable: false, currentOrderKey: null});
};
okGroup = () => {
......@@ -185,19 +186,20 @@ export default class StatisticsInfo extends React.Component {
this.setState({
groups,
groupVisiable: false,
currentGroupKey: null },()=>{
currentGroupKey: null
}, () => {
this.finish();
});
};
addGroup = () => {
this.setState({ groupVisiable: true });
this.setState({groupVisiable: true});
};
addQuery = () => {
this.setState({ queryVisiable: true });
this.setState({queryVisiable: true});
};
okQuery = () => {
......@@ -207,12 +209,12 @@ export default class StatisticsInfo extends React.Component {
}
const querys = this.state.querys;
querys.push(this.state.infos[this.state.currentQueryKey]);
this.setState({ querys, queryVisiable: false, currentQueryKey: null });
this.setState({querys, queryVisiable: false, currentQueryKey: null});
};
finish = () => {
const { dispatch, objId } = this.props;
const { x, y, z, infos, XxX, currentKey, groups } = this.state;
const {dispatch, objId} = this.props;
const {x, y, z, infos, XxX, currentKey, groups} = this.state;
if (x == null) {
message.error('请选择第一统计项');
......@@ -248,7 +250,7 @@ export default class StatisticsInfo extends React.Component {
}
for (var i = 0; i < groups.length; i++) {
ggs.push({ hql: groups[i].hql })
ggs.push({hql: groups[i].hql})
}
const tx = infos[x]
const ty = infos[y]
......@@ -256,34 +258,34 @@ export default class StatisticsInfo extends React.Component {
var ttx;
var tty;
var ttz;
if(tx.notes){
if(tx.notes.indexOf("com.")==-1){
ttx=infos[x].hql.replace(".id",".dictName")
}else{
ttx=infos[x].hql
if (tx.notes) {
if (tx.notes.indexOf("com.") == -1) {
ttx = infos[x].hql.replace(".id", ".dictName")
} else {
ttx = infos[x].hql
}
}else{
ttx=infos[x].hql
} else {
ttx = infos[x].hql
}
if(ty.notes){
if(ty.notes.indexOf("com.")==-1){
tty=infos[y].hql.replace(".id",".dictName")
}else{
tty=infos[y].hql
if (ty.notes) {
if (ty.notes.indexOf("com.") == -1) {
tty = infos[y].hql.replace(".id", ".dictName")
} else {
tty = infos[y].hql
}
}else{
tty=infos[y].hql
} else {
tty = infos[y].hql
}
if(z!=null){
if (z != null) {
const tz = infos[z]
if(tz&&tz.notes){
if(tz.notes.indexOf("com.")==-1){
ttz=infos[z].hql.replace(".id",".dictName")
}else{
ttz=infos[z].hql
if (tz && tz.notes) {
if (tz.notes.indexOf("com.") == -1) {
ttz = infos[z].hql.replace(".id", ".dictName")
} else {
ttz = infos[z].hql
}
}else{
ttz=infos[z].hql
} else {
ttz = infos[z].hql
}
}
dispatch({
......@@ -300,7 +302,7 @@ export default class StatisticsInfo extends React.Component {
groups: JSON.stringify(ggs),
},
callback: (data) => {
this.setState({ dataSource: data.dataSource, columns: data.columns });
this.setState({dataSource: data.dataSource, columns: data.columns});
},
});
......@@ -309,24 +311,25 @@ export default class StatisticsInfo extends React.Component {
};
downloadFile(url, params) {
this.setState({ exportLoading: true });
this.setState({exportLoading: true});
fetch(url, {
method: 'POST',
body: FormdataWrapper(params)
}).then(res=>{
}).then(res => {
if (res.status != '200') {
return res.json();
}else {
} else {
return res.blob();
}
}).then(data=>{
}).then(data => {
if (data instanceof Blob) {
let a = document.createElement('a');
let url = window.URL.createObjectURL(data);
let filename = (this.props.fileName ? this.props.fileName:'导出文件') + '.xlsx';
let filename = (this.props.fileName ? this.props.fileName : '导出文件') + '.xlsx';
a.href = url;
a.download = filename;
a.click();
......@@ -339,17 +342,18 @@ export default class StatisticsInfo extends React.Component {
});
}
}).catch(err=>{
}).catch(err => {
notification.error({
message: `网络请求超时`,
});
}).finally(()=>{
this.setState({ exportLoading: false });
}).finally(() => {
this.setState({exportLoading: false});
});
}
export = () => {
const { dispatch, objId} = this.props;
const { x, y, z, infos, XxX, currentKey, groups } = this.state;
const {dispatch, objId} = this.props;
const {x, y, z, infos, XxX, currentKey, groups} = this.state;
if (x == null) {
message.error('请选择第一统计项');
......@@ -385,7 +389,7 @@ export default class StatisticsInfo extends React.Component {
}
for (var i = 0; i < groups.length; i++) {
ggs.push({ hql: groups[i].hql })
ggs.push({hql: groups[i].hql})
}
const tx = infos[x]
const ty = infos[y]
......@@ -393,34 +397,34 @@ export default class StatisticsInfo extends React.Component {
var ttx;
var tty;
var ttz;
if(tx.notes){
if(tx.notes.indexOf("com.")==-1){
ttx=infos[x].hql.replace(".id",".dictName")
}else{
ttx=infos[x].hql
if (tx.notes) {
if (tx.notes.indexOf("com.") == -1) {
ttx = infos[x].hql.replace(".id", ".dictName")
} else {
ttx = infos[x].hql
}
}else{
ttx=infos[x].hql
} else {
ttx = infos[x].hql
}
if(ty.notes){
if(ty.notes.indexOf("com.")==-1){
tty=infos[y].hql.replace(".id",".dictName")
}else{
tty=infos[y].hql
if (ty.notes) {
if (ty.notes.indexOf("com.") == -1) {
tty = infos[y].hql.replace(".id", ".dictName")
} else {
tty = infos[y].hql
}
}else{
tty=infos[y].hql
} else {
tty = infos[y].hql
}
if(z!=null){
if (z != null) {
const tz = infos[z]
if(tz&&tz.notes){
if(tz.notes.indexOf("com.")==-1){
ttz=infos[z].hql.replace(".id",".dictName")
}else{
ttz=infos[z].hql
if (tz && tz.notes) {
if (tz.notes.indexOf("com.") == -1) {
ttz = infos[z].hql.replace(".id", ".dictName")
} else {
ttz = infos[z].hql
}
}else{
ttz=infos[z].hql
} else {
ttz = infos[z].hql
}
}
const param = {
......@@ -435,34 +439,33 @@ export default class StatisticsInfo extends React.Component {
}
let downloadUrl = config.httpServer + '/DataObjApi/exportStatistics?';
const token = getToken()!=null&&getToken()!="null"?getToken():"0000";
const token = getToken() != null && getToken() != "null" ? getToken() : "0000";
downloadUrl = `${downloadUrl}token=${token}`;
this.downloadFile(downloadUrl, param);
});
};
cancelGroup = () => {
this.setState({ currentGroupKey: null, groupVisiable: false });
this.setState({currentGroupKey: null, groupVisiable: false});
};
cancelQuery = () => {
this.setState({ currentQueryKey: null, queryVisiable: false });
this.setState({currentQueryKey: null, queryVisiable: false});
};
cancelOrder = () => {
this.setState({ currentOrderKey: null, orderVisiable: false });
this.setState({currentOrderKey: null, orderVisiable: false});
};
selectOrder = (e) => {
this.setState({ currentOrderKey: e });
this.setState({currentOrderKey: e});
};
selectQuery = (e) => {
this.setState({ currentQueryKey: e, flag: !this.state.flag });
this.setState({currentQueryKey: e, flag: !this.state.flag});
};
selectGroup = (e) => {
this.setState({ currentGroupKey: e, flag: !this.state.flag });
this.setState({currentGroupKey: e, flag: !this.state.flag});
};
changeX = (x) => {
......@@ -470,7 +473,7 @@ export default class StatisticsInfo extends React.Component {
x,
flag: !this.state.flag,
},()=>{
}, () => {
this.finish();
});
};
......@@ -478,25 +481,25 @@ export default class StatisticsInfo extends React.Component {
this.setState({
y,
flag: !this.state.flag
},()=>{
}, () => {
this.finish();
});
};
changeZ = (z) => {
this.setState({ z, flag: !this.state.flag });
this.setState({z, flag: !this.state.flag});
};
cancelZ = () => {
this.setState({ z: null, flag: !this.state.flag });
this.setState({z: null, flag: !this.state.flag});
};
selectXxX = (XxX) => {
this.setState({ XxX, flag: !this.state.flag });
this.setState({XxX, flag: !this.state.flag});
};
selectCurrentKey = (currentKey) => {
this.setState({ currentKey, XxX: null, flag: !this.state.flag });
this.setState({currentKey, XxX: null, flag: !this.state.flag});
};
cancelCurrentKey = () => {
this.setState({ currentKey: null, XxX: null, flag: !this.state.flag });
this.setState({currentKey: null, XxX: null, flag: !this.state.flag});
};
componentDidMount() {
......@@ -505,18 +508,36 @@ export default class StatisticsInfo extends React.Component {
pageConfig = (item = 0) => {
const {
visiable, queryVisiable, querys, groups, currentKey, XxX,
infos, mockData, mockXZData, columns, dataSource, qs, os, gs, x, y, z, currentQueryKey, currentGroupKey, groupVisiable,
visiable,
queryVisiable,
querys,
groups,
currentKey,
XxX,
infos,
mockData,
mockXZData,
columns,
dataSource,
qs,
os,
gs,
x,
y,
z,
currentQueryKey,
currentGroupKey,
groupVisiable,
} = this.state;
let xxxs = [];
if (currentKey != null) {
if (infos[currentKey].type == 'java.lang.Integer' || infos[currentKey].type == 'java.lang.Double' || infos[currentKey].type == 'java.lang.Long') {
xxxs = [{ label: '数量', value: 'count' }, { label: '最大值', value: 'max' }, {
xxxs = [{label: '数量', value: 'count'}, {label: '最大值', value: 'max'}, {
label: '最小值',
value: 'min',
}, { label: '平均值', value: 'avg' }, { label: '求和', value: 'sum' }];
}, {label: '平均值', value: 'avg'}, {label: '求和', value: 'sum'}];
} else {
xxxs = [{ label: '数量', value: 'count' }];
xxxs = [{label: '数量', value: 'count'}];
}
}
......@@ -696,7 +717,7 @@ export default class StatisticsInfo extends React.Component {
const nameSpanThis = dataIndex > 0 ? nameSpan2 : nameSpan;
return (
<Col span={4}
style={{ paddingLeft: '15px' }}
style={{paddingLeft: '15px'}}
key={dataIndex}>
<FormItem label={selectConfigItem.name}
required={config.required || false}
......@@ -710,7 +731,7 @@ export default class StatisticsInfo extends React.Component {
xxl: 24 - nameSpanThis.big,
}}
>
<Select style={{ width: '100%' }}
<Select style={{width: '100%'}}
onChange={selectConfigItem.onChange}
value={selectConfigItem.value}>
{selectConfigItem.options.map((r) => {
......@@ -728,7 +749,7 @@ export default class StatisticsInfo extends React.Component {
return (
<Col span={1}
key={buttonDs.key}
style={{ paddingLeft: '15px' }}>
style={{paddingLeft: '15px'}}>
<FormItem colon={false}
labelCol={{
xl: nameSpan.small,
......@@ -742,7 +763,7 @@ export default class StatisticsInfo extends React.Component {
<ButtonDiy name={buttonDs.name}
type='default'
className={buttonDs.className}
handleClick={buttonDs.handleClick} />
handleClick={buttonDs.handleClick}/>
</FormItem>
</Col>
);
......@@ -756,23 +777,23 @@ export default class StatisticsInfo extends React.Component {
render() {
const { form, loading } = this.props;
const {form, loading} = this.props;
const {
visiable, querys, groups, currentKey, XxX,exportLoading,
visiable, querys, groups, currentKey, XxX, exportLoading,
infos, mockData, columns, dataSource, qs, os, gs, x, y, z, currentQueryKey, currentGroupKey, groupVisiable,
} = this.state;
const loadingxxx=loading||exportLoading;
const loadingxxx = loading || exportLoading;
let columnsTemp = columns;
if (columnsTemp.length > 0) {
if (z == null) {
columnsTemp[0].title = <div className={styles.out2} style={{ fontSize: 14 }}>
columnsTemp[0].title = <div className={styles.out2} style={{fontSize: 14}}>
<span className={styles.title1}>{infos[x] ? infos[x].name : ''}</span> <span
className={styles.title3}>{infos[y] ? infos[y].name : ''}</span>
</div>;
columnsTemp[0].width = 200;
} else {
columnsTemp[0].title = <div className={styles.out} style={{ fontSize: 14 }}>
columnsTemp[0].title = <div className={styles.out} style={{fontSize: 14}}>
<span className={styles.title1}>{infos[x] ? infos[x].name : ''}</span> <span
className={styles.title2}>{infos[z] ? infos[z].name : ''}</span> <span
className={styles.title3}>{infos[y] ? infos[y].name : ''}</span>
......@@ -785,12 +806,12 @@ export default class StatisticsInfo extends React.Component {
if (infos[currentKey].type === 'java.lang.Integer' ||
infos[currentKey].type === 'java.lang.Double' ||
infos[currentKey].type === 'java.lang.Long') {
xxxs = [{ label: '数量', value: 'count' }, { label: '最大值', value: 'max' }, {
xxxs = [{label: '数量', value: 'count'}, {label: '最大值', value: 'max'}, {
label: '最小值',
value: 'min',
}, { label: '平均值', value: 'avg' }, { label: '求和', value: 'sum' }];
}, {label: '平均值', value: 'avg'}, {label: '求和', value: 'sum'}];
} else {
xxxs = [{ label: '数量', value: 'count' }];
xxxs = [{label: '数量', value: 'count'}];
}
}
return (
......@@ -799,9 +820,9 @@ export default class StatisticsInfo extends React.Component {
<ButtonDiy name='自定义统计'
type='default'
className='defaultBlue'
handleClick={this.open} />
handleClick={this.open}/>
<div id='downloadDiv'
style={{ display: 'none' }}>
style={{display: 'none'}}>
</div>
<Modal
......@@ -819,7 +840,10 @@ export default class StatisticsInfo extends React.Component {
{this.selectDom(2)}
{this.selectDom(3)}
{this.selectDom(4)}
<div style={{ textAlign: 'left', paddingLeft: '25px' }}>
<div style={{
textAlign: 'left',
paddingLeft: '25px',
}}>
{querys.map((r, i) =>
<FormItem key={i}
labelCol={{
......@@ -832,7 +856,7 @@ export default class StatisticsInfo extends React.Component {
}}
label={r.name}>
{form.getFieldDecorator(i + 'q__', {
initialValue: { stringX: '=' }, rules: [{
initialValue: {stringX: '='}, rules: [{
validator: (rule, value, callback) => {
var errors = [];
if (value == null) {
......@@ -846,7 +870,7 @@ export default class StatisticsInfo extends React.Component {
},
}],
})(<QueryItem obj={r}
deleteQuery={this.deleteQuery.bind(this, i)} />)}
deleteQuery={this.deleteQuery.bind(this, i)}/>)}
</FormItem>)}
</div>
{this.selectDom(5)}
......@@ -863,11 +887,11 @@ export default class StatisticsInfo extends React.Component {
</Tag>,
)}
</Row>
<Row style={{ paddingTop: '20px' }}>
<Col span={24} style={{ textAlign: 'left' }}>
<Row style={{paddingTop: '20px'}}>
<Col span={24} style={{textAlign: 'left'}}>
<ButtonDiy handleClick={this.finish}
name={'查询'}
loading={loadingxxx} />
loading={loadingxxx}/>
<ButtonDiy handleClick={this.export}
name={'导出'}
loading={loadingxxx}/>
......@@ -881,13 +905,18 @@ export default class StatisticsInfo extends React.Component {
</Button>
结果:*/}
</Col>
<Col span={24}>
<Col span={24}
style={{
overFlow: 'auto',
minHeight: '500px',
}}
>
<Table size="small"
bordered
dataSource={dataSource}
rowKey={'col0'}
columns={columnsTemp}
pagination={false} />
pagination={false}/>
{/*{columns.length > 0 ?*/}
{/*<Table size="small"*/}
{/*bordered*/}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论