Merge remote-tracking branch 'origin/main' into main

This commit is contained in:
wangjiahao 2021-04-20 11:47:03 +08:00
commit 3c17fc57c0
11 changed files with 324 additions and 16 deletions

View File

@ -7,6 +7,7 @@ import io.dataease.controller.request.dataset.DataSetTableRequest;
import io.dataease.datasource.dto.TableFiled;
import io.dataease.service.dataset.DataSetTableService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.util.List;
@ -86,4 +87,9 @@ public class DataSetTableController {
public Map<String, Object> datasetDetail(@PathVariable String id) {
return dataSetTableService.getDatasetDetail(id);
}
@PostMapping("excel/upload")
public Map<String, Object> excelUpload(@RequestParam("file") MultipartFile file) throws Exception {
return dataSetTableService.excelSaveAndParse(file);
}
}

View File

@ -18,10 +18,26 @@ import io.dataease.dto.dataset.DataTableInfoDTO;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.*;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.sql.ResultSet;
import java.text.DecimalFormat;
import java.text.MessageFormat;
import java.util.*;
import java.util.stream.Collectors;
@ -42,6 +58,8 @@ public class DataSetTableService {
private DataSetTableTaskService dataSetTableTaskService;
@Resource
private DatasetTableIncrementalConfigMapper datasetTableIncrementalConfigMapper;
@Value("${upload.file.path}")
private String path;
public void batchInsert(List<DatasetTable> datasetTable) throws Exception {
for (DatasetTable table : datasetTable) {
@ -434,4 +452,120 @@ public class DataSetTableService {
}
return map;
}
public Map<String, Object> excelSaveAndParse(MultipartFile file) throws Exception {
String filename = file.getOriginalFilename();
String suffix = filename.substring(filename.lastIndexOf(".") + 1);
List<TableFiled> fields = new ArrayList<>();
List<String[]> data = new ArrayList<>();
List<Map<String, Object>> jsonArray = new ArrayList<>();
InputStream inputStream = file.getInputStream();
if (StringUtils.equalsIgnoreCase(suffix, "xls")) {
HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
HSSFSheet sheet0 = workbook.getSheetAt(0);
if (sheet0.getNumMergedRegions() > 0) {
throw new RuntimeException("Sheet have merged regions.");
}
int rows = Math.min(sheet0.getPhysicalNumberOfRows(), 100);
for (int i = 0; i < rows; i++) {
HSSFRow row = sheet0.getRow(i);
String[] r = new String[row.getPhysicalNumberOfCells()];
for (int j = 0; j < row.getPhysicalNumberOfCells(); j++) {
if (i == 0) {
TableFiled tableFiled = new TableFiled();
tableFiled.setFieldName(readCell(row.getCell(j)));
tableFiled.setRemarks(readCell(row.getCell(j)));
fields.add(tableFiled);
} else {
r[j] = readCell(row.getCell(j));
}
}
if (i > 0) {
data.add(r);
}
}
} else if (StringUtils.equalsIgnoreCase(suffix, "xlsx")) {
XSSFWorkbook xssfWorkbook = new XSSFWorkbook(inputStream);
XSSFSheet sheet0 = xssfWorkbook.getSheetAt(0);
if (sheet0.getNumMergedRegions() > 0) {
throw new RuntimeException("Sheet have merged regions.");
}
int rows = Math.min(sheet0.getPhysicalNumberOfRows(), 100);
for (int i = 0; i < rows; i++) {
XSSFRow row = sheet0.getRow(i);
String[] r = new String[row.getPhysicalNumberOfCells()];
for (int j = 0; j < row.getPhysicalNumberOfCells(); j++) {
if (i == 0) {
TableFiled tableFiled = new TableFiled();
tableFiled.setFieldName(readCell(row.getCell(j)));
tableFiled.setRemarks(readCell(row.getCell(j)));
fields.add(tableFiled);
} else {
r[j] = readCell(row.getCell(j));
}
}
if (i > 0) {
data.add(r);
}
}
} else if (StringUtils.equalsIgnoreCase(suffix, "csv")) {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
String s = reader.readLine();// first line
String[] split = s.split(",");
for (String s1 : split) {
TableFiled tableFiled = new TableFiled();
tableFiled.setFieldName(s1);
tableFiled.setRemarks(s1);
fields.add(tableFiled);
}
int num = 1;
String line = null;
while ((line = reader.readLine()) != null) {
if (num > 100) {
break;
}
data.add(line.split(","));
num++;
}
}
String[] fieldArray = fields.stream().map(TableFiled::getFieldName).toArray(String[]::new);
if (CollectionUtils.isNotEmpty(data)) {
jsonArray = data.stream().map(ele -> {
Map<String, Object> map = new HashMap<>();
for (int i = 0; i < ele.length; i++) {
map.put(fieldArray[i], ele[i]);
}
return map;
}).collect(Collectors.toList());
}
inputStream.close();
Map<String, Object> map = new HashMap<>();
map.put("fields", fields);
map.put("data", jsonArray);
return map;
}
private String readCell(Cell cell) {
CellType cellTypeEnum = cell.getCellTypeEnum();
if (cellTypeEnum.equals(CellType.STRING)) {
return cell.getStringCellValue();
} else if (cellTypeEnum.equals(CellType.NUMERIC)) {
double d = cell.getNumericCellValue();
try {
return new Double(d).longValue() + "";
} catch (Exception e) {
BigDecimal b = new BigDecimal(d);
return b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue() + "";
}
} else if (cellTypeEnum.equals(CellType.BOOLEAN)) {
return cell.getBooleanCellValue() ? "1" : "0";
} else {
return "";
}
}
}

View File

@ -48,3 +48,10 @@ export function loadGenerate(resourceId) {
method: 'post'
})
}
export function loadResource(resourceId) {
return request({
url: 'panel/group/findOne/' + resourceId,
method: 'get'
})
}

View File

@ -324,7 +324,15 @@ export default {
this.addCondition(condition)
},
addCondition(condition) {
this.conditions.push(condition)
let conditionExist = false
for (let index = 0; index < this.conditions.length; index++) {
const element = this.conditions[index]
if (condition.componentId === element.componentId) {
this.conditions[index] = condition
conditionExist = true
}
}
!conditionExist && this.conditions.push(condition)
this.executeSearch()
},
deleteCondition(condition) {

View File

@ -783,7 +783,8 @@ export default {
detail: '详情',
type: '类型',
create_by: '创建者',
create_time: '创建时间'
create_time: '创建时间',
preview_100_data: '预览前100行数据'
},
datasource: {
datasource: '数据源',

View File

@ -1,5 +1,5 @@
<template>
<div id="link"><router-view />
<div id="link" style="height:100%;"><router-view />
</div>
</template>
<script>

View File

@ -5,6 +5,9 @@ import store from '../store'
import '@/styles/index.scss' // global css
import i18n from '../lang' // internationalization
import ElementUI from 'element-ui'
import '@/components/canvas/custom-component' // 注册自定义组件
import * as echarts from 'echarts'
Vue.prototype.$echarts = echarts
Vue.config.productionTip = false
Vue.use(ElementUI, {

View File

@ -9,7 +9,7 @@
<el-button size="mini" @click="cancel">
{{ $t('dataset.cancel') }}
</el-button>
<el-button size="mini" type="primary" @click="save">
<el-button :disabled="!form.name || fileList.length === 0" size="mini" type="primary" @click="save">
{{ $t('dataset.confirm') }}
</el-button>
</el-row>
@ -24,11 +24,14 @@
</el-form-item>
<el-form-item>
<el-upload
action="/posts/"
:action="baseUrl+'dataset/table/excel/upload'"
:multiple="false"
:show-file-list="false"
:file-list="fileList"
accept=".xls,.xlsx,.csv"
:on-success="uploadSuccess"
name="file"
:headers="headers"
>
<el-button size="mini" type="primary">{{ $t('dataset.upload_file') }}</el-button>
</el-upload>
@ -42,6 +45,7 @@
<el-card class="box-card dataPreview" shadow="never">
<div slot="header" class="clearfix">
<span>{{ $t('dataset.data_preview') }}</span>
<span style="font-size: 12px;color: #3d4d66;">{{ $t('dataset.preview_100_data') }}</span>
</div>
<div class="text item">
<ux-grid
@ -70,6 +74,9 @@
<script>
import { post } from '@/api/dataset/dataset'
import { getToken } from '@/utils/auth'
const token = getToken()
export default {
name: 'AddExcel',
@ -85,8 +92,12 @@ export default {
name: ''
},
fields: [],
data: [],
mode: '1',
height: 600
height: 600,
fileList: [],
headers: { Authorization: token },
baseUrl: process.env.VUE_APP_BASE_API
}
},
watch: {
@ -120,6 +131,18 @@ export default {
// },
uploadSuccess(response, file, fileList) {
console.log(response)
console.log(file)
console.log(fileList)
this.fields = response.data.fields
this.data = response.data.data
const datas = this.data
this.$refs.plxTable.reloadData(datas)
if (file.name.lastIndexOf('.') > 0) {
this.form.name = file.name.substring(0, file.name.lastIndexOf('.'))
}
this.fileList = fileList
},
save() {

View File

@ -1,5 +1,5 @@
<template>
<div>
<div style="height: 100%;">
<link-error v-if="showIndex===0" :resource-id="resourceId" />
<link-pwd v-if="showIndex===1" :resource-id="resourceId" />
<link-view v-if="showIndex===2" :resource-id="resourceId" />

View File

@ -1,19 +1,54 @@
<template>
<div>
我是视图页面
<div style="width: 100%;height: 100%;background-color: #f7f8fa">
<Preview v-if="show" />
</div>
</template>
<script>
import { loadResource } from '@/api/link'
import { uuid } from 'vue-uuid'
import Preview from '@/components/canvas/components/Editor/Preview'
export default {
name: 'LinkView',
data() {
return {
components: { Preview },
props: {
resourceId: {
type: String,
default: null
}
},
data() {
return {
show: false
}
},
created() {
this.show = false
this.setPanelInfo()
},
methods: {
setPanelInfo() {
loadResource(this.resourceId).then(res => {
this.$store.commit('setComponentData', this.resetID(JSON.parse(res.data.panelData)))
// this.$store.commit('setComponentData', JSON.parse(res.data.panelData))
this.$store.commit('setCanvasStyle', JSON.parse(res.data.panelStyle))
this.show = true
})
},
resetID(data) {
data.forEach(item => {
item.id = uuid.v1()
})
return data
}
}
}
</script>
<style scoped>
*{
margin: 0;
padding: 0;
}
</style>

View File

@ -12,12 +12,12 @@
</el-breadcrumb-item>
</el-breadcrumb>
</div>
<div class="component-search filter-common">
<!-- <div class="component-search filter-common">
<el-input
placeholder="请输入内容"
prefix-icon="el-icon-search"
/>
</div>
</div> -->
<!-- <div class="component-result-content filter-common" @dragstart="handleDragStart" @dragend="handleDragEnd"> -->
<div class="component-result-content filter-common">
@ -68,7 +68,61 @@
</div>
</div>
</el-tab-pane>
<el-tab-pane :lazy="true" class="de-tab" label="按组件选择" name="assembly">按组件选择</el-tab-pane>
<el-tab-pane :lazy="true" class="de-tab" label="按组件选择" name="assembly">
<div class="component-header filter-common">
<el-breadcrumb separator-class="el-icon-arrow-right">
<el-breadcrumb-item v-for="bread in componentSetBreads" :key="bread.label">
<a v-if="bread.link" :class="{'link-text' : bread.link}" @click="comBackLink(bread)"> {{ bread.label }}</a>
<span v-else>{{ bread.label }}</span>
</el-breadcrumb-item>
</el-breadcrumb>
</div>
<!-- <div class="component-search filter-common">
<el-input
placeholder="请输入内容"
prefix-icon="el-icon-search"
/>
</div> -->
<div class="component-result-content filter-common">
<el-table
v-if="comShowDomType === 'view'"
class="de-filter-data-table"
:data="viewInfos"
:show-header="false"
size="mini"
:highlight-current-row="true"
style="width: 100%"
>
<el-table-column prop="name" label="名称">
<template v-if="comShowDomType === 'view'" :id="scope.row.id" slot-scope="scope">
<div class="filter-db-row" @click="comShowFieldDatas(scope.row)">
<i class="el-icon-s-data" />
<span> {{ scope.row.name }}</span>
</div>
</template>
</el-table-column>
</el-table>
<div v-else-if="comShowDomType === 'field'">
<draggable
v-model="comFieldDatas"
:options="{group:{name: 'dimension',pull:'clone'},sort: true}"
animation="300"
:move="onMove"
class="drag-list"
@end="end1"
@start="start1"
>
<transition-group>
<div v-for="item in comFieldDatas" :key="item.id" class="filter-db-row">
<i class="el-icon-s-data" />
<span> {{ item.name }}</span>
</div>
</transition-group>
</draggable>
</div>
</div>
</el-tab-pane>
</el-tabs>
</de-aside-container>
@ -200,12 +254,18 @@ export default {
return {
activeName: 'dataset',
showDomType: 'tree',
comShowDomType: 'view',
dataSetBreads: [
{ label: '数据列表', link: false, type: 'root' }
],
componentSetBreads: [
{ label: '组件列表', link: false, type: 'root' }
],
data: [],
sceneDatas: [],
// viewDatas: [],
fieldDatas: [],
comFieldDatas: [],
defaultProps: {
children: 'children',
label: 'label'
@ -319,15 +379,28 @@ export default {
tail.type = node.type
tail.link = true
},
comSetTailLink(node) {
const tail = this.componentSetBreads[this.componentSetBreads.length - 1]
tail.type = node.type
tail.link = true
},
addTail(node) {
const tail = { link: false, label: node.label || node.name, type: node.type }
this.dataSetBreads.push(tail)
},
comAddTail(node) {
const tail = { link: false, label: node.label || node.name, type: node.type }
this.componentSetBreads.push(tail)
},
removeTail() {
this.dataSetBreads = this.dataSetBreads.slice(0, this.dataSetBreads.length - 1)
this.dataSetBreads[this.dataSetBreads.length - 1]['link'] = false
},
comRemoveTail() {
this.componentSetBreads = this.componentSetBreads.slice(0, this.componentSetBreads.length - 1)
this.componentSetBreads[this.componentSetBreads.length - 1]['link'] = false
},
backToLink(bread) {
if (bread.type === 'db') {
this.showDomType = 'db'
@ -337,6 +410,10 @@ export default {
this.removeTail()
},
comBackLink(bread) {
this.comShowDomType = 'view'
this.comRemoveTail()
},
loadTable(sceneId) {
loadTable({ sceneId: sceneId, sort: 'type asc,create_time desc,name asc' }).then(res => {
this.sceneDatas = res.data
@ -352,13 +429,27 @@ export default {
this.fieldDatas = datas
})
},
comLoadField(tableId) {
fieldList(tableId).then(res => {
let datas = res.data
if (this.widget && this.widget.filterFieldMethod) {
datas = this.widget.filterFieldMethod(datas)
}
this.comFieldDatas = datas
})
},
showFieldDatas(row) {
this.showDomType = 'field'
this.setTailLink(row)
this.addTail(row)
this.loadField(row.id)
},
test(row) {},
comShowFieldDatas(row) {
this.comShowDomType = 'field'
this.comSetTailLink(row)
this.comAddTail(row)
this.comLoadField(row.tableId)
},
onMove(e, originalEvent) {
this.moveId = e.draggedContext.element.id
return true