支持直接删除表的行数据
This commit is contained in:
@@ -5,6 +5,7 @@ import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.alibaba.fastjson.util.TypeUtils;
|
||||
import com.zyplayer.doc.core.annotation.AuthMan;
|
||||
@@ -87,6 +88,20 @@ public class DbDataViewController {
|
||||
return responseJson;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除表数据
|
||||
*
|
||||
* @param lineJson
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/deleteTableLineData")
|
||||
public ResponseJson deleteTableLineData(Long sourceId, String dbName, String tableName, String lineJson) {
|
||||
JSONArray lineJsonArr = JSON.parseArray(lineJson);
|
||||
DbBaseService dbBaseService = databaseServiceFactory.getDbBaseService(sourceId);
|
||||
dbBaseService.deleteTableLineData(sourceId, dbName, tableName, lineJsonArr);
|
||||
return DocDbResponseJson.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 单表数据下载
|
||||
*
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.zyplayer.doc.db.framework.db.mapper.base;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.zyplayer.doc.db.controller.param.ProcedureListParam;
|
||||
import com.zyplayer.doc.db.controller.vo.TableStatusVo;
|
||||
import com.zyplayer.doc.db.framework.db.dto.*;
|
||||
@@ -150,4 +151,11 @@ public interface BaseMapper {
|
||||
* @since 2020年4月24日
|
||||
*/
|
||||
void deleteProcedure(@Param("dbName") String dbName, @Param("typeName") String typeName, @Param("procName") String procName);
|
||||
|
||||
/**
|
||||
* 删除行数
|
||||
* @author 暮光:城中城
|
||||
* @since 2021-08-14
|
||||
*/
|
||||
void deleteTableLineData(@Param("dbName") String dbName, @Param("tableName") String tableName, @Param("lineParam") JSONObject lineParam);
|
||||
}
|
||||
|
||||
@@ -86,4 +86,11 @@
|
||||
select 1 from ${dbName}.${tableName} where 0 = 1
|
||||
</insert>
|
||||
|
||||
<delete id="deleteTableLineData">
|
||||
delete from ${dbName}.${tableName} where
|
||||
<foreach collection="lineParam.entrySet()" index="key" item="value">
|
||||
${key} = #{value}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -87,6 +87,13 @@
|
||||
DROP ${typeName} IF EXISTS `${dbName}`.`${procName}`
|
||||
</delete>
|
||||
|
||||
<delete id="deleteTableLineData">
|
||||
delete from `${dbName}`.`${tableName}` where
|
||||
<foreach collection="lineParam.entrySet()" index="key" item="value">
|
||||
${key} = #{value}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<sql id="ProcedureListCondition">
|
||||
where db=#{param.dbName}
|
||||
<if test="param.name != null and param.name != ''">and `name` like #{param.name}</if>
|
||||
|
||||
@@ -72,4 +72,11 @@
|
||||
comment on column ${dbName}.${tableName}.${columnName} is #{new Desc}
|
||||
</insert>
|
||||
|
||||
<delete id="deleteTableLineData">
|
||||
delete from ${dbName}.${tableName} where
|
||||
<foreach collection="lineParam.entrySet()" index="key" item="value">
|
||||
${key} = #{value}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -87,5 +87,13 @@
|
||||
</if>
|
||||
</select>
|
||||
|
||||
|
||||
<delete id="deleteTableLineData">
|
||||
delete from ${dbName}.${tableName} where
|
||||
<foreach collection="lineParam.entrySet()" index="key" item="value">
|
||||
${key} = #{value}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
|
||||
|
||||
@@ -96,5 +96,12 @@
|
||||
, @level2type = 'COLUMN', @level2name = #{columnName}
|
||||
</insert>
|
||||
|
||||
<delete id="deleteTableLineData">
|
||||
delete from ${dbName}.${tableName} where
|
||||
<foreach collection="lineParam.entrySet()" index="key" item="value">
|
||||
${key} = #{value}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.zyplayer.doc.db.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.zyplayer.doc.core.exception.ConfirmException;
|
||||
import com.zyplayer.doc.data.config.security.DocUserUtil;
|
||||
import com.zyplayer.doc.data.repository.support.consts.DocAuthConst;
|
||||
@@ -19,13 +21,16 @@ import com.zyplayer.doc.db.framework.db.mapper.base.ExecuteResult;
|
||||
import com.zyplayer.doc.db.framework.db.mapper.base.SqlExecutor;
|
||||
import com.zyplayer.doc.db.service.download.BaseDownloadService;
|
||||
import com.zyplayer.doc.db.service.download.DownloadService;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 数据库的mapper持有对象接口
|
||||
@@ -34,6 +39,7 @@ import java.util.stream.Collectors;
|
||||
* @since 2018年8月8日
|
||||
*/
|
||||
public abstract class DbBaseService {
|
||||
private static Logger logger = LoggerFactory.getLogger(DbBaseService.class);
|
||||
|
||||
@Resource
|
||||
SqlExecutor sqlExecutor;
|
||||
@@ -387,4 +393,16 @@ public abstract class DbBaseService {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void deleteTableLineData(Long sourceId, String dbName, String tableName, JSONArray lineJsonArr) {
|
||||
for (int i = 0; i < lineJsonArr.size(); i++) {
|
||||
JSONObject lineParam = lineJsonArr.getJSONObject(i);
|
||||
if (lineParam.isEmpty()) {
|
||||
logger.error("待删除行的条件参数为空,不允许删除");
|
||||
continue;
|
||||
}
|
||||
BaseMapper baseMapper = this.getViewAuthBaseMapper(sourceId);
|
||||
baseMapper.deleteTableLineData(dbName, tableName, lineParam);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=favicon-db.png><title>数据库文档管理</title><link href=css/chunk-vendors.8924efc6.css rel=preload as=style><link href=css/index.2a7107f3.css rel=preload as=style><link href=js/chunk-vendors.333ced1f.js rel=preload as=script><link href=js/index.5607dd4d.js rel=preload as=script><link href=css/chunk-vendors.8924efc6.css rel=stylesheet><link href=css/index.2a7107f3.css rel=stylesheet></head><body><noscript><strong>We're sorry but zyplayer-db-ui doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=js/chunk-vendors.333ced1f.js></script><script src=js/index.5607dd4d.js></script></body></html>
|
||||
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=favicon-db.png><title>数据库文档管理</title><link href=css/chunk-vendors.8924efc6.css rel=preload as=style><link href=css/index.2a7107f3.css rel=preload as=style><link href=js/chunk-vendors.333ced1f.js rel=preload as=script><link href=js/index.dab72f94.js rel=preload as=script><link href=css/chunk-vendors.8924efc6.css rel=stylesheet><link href=css/index.2a7107f3.css rel=stylesheet></head><body><noscript><strong>We're sorry but zyplayer-db-ui doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=js/chunk-vendors.333ced1f.js></script><script src=js/index.dab72f94.js></script></body></html>
|
||||
File diff suppressed because one or more lines are too long
1
zyplayer-doc-db/src/main/resources/dist/js/index.dab72f94.js
vendored
Normal file
1
zyplayer-doc-db/src/main/resources/dist/js/index.dab72f94.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -2,8 +2,8 @@
|
||||
ENV = 'development'
|
||||
|
||||
# base api
|
||||
# VUE_APP_BASE_API = 'http://local.zyplayer.com:8083/zyplayer-doc-manage'
|
||||
VUE_APP_BASE_API = 'http://doc.zyplayer.com/zyplayer-doc-manage'
|
||||
VUE_APP_BASE_API = 'http://local.zyplayer.com:8083/zyplayer-doc-manage'
|
||||
# VUE_APP_BASE_API = 'http://doc.zyplayer.com/zyplayer-doc-manage'
|
||||
|
||||
VUE_CLI_BABEL_TRANSPILE_MODULES = true
|
||||
|
||||
|
||||
@@ -110,4 +110,7 @@ export default {
|
||||
getTableColumnRelation: data => {
|
||||
return request({url: '/zyplayer-doc-db/table-relation/getRelation', method: 'post', data: Qs.stringify(data)});
|
||||
},
|
||||
deleteTableLineData: data => {
|
||||
return request({url: '/zyplayer-doc-db/data-view/deleteTableLineData', method: 'post', data: Qs.stringify(data)});
|
||||
},
|
||||
};
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
<div v-else-if="executeResultList.length <= 0" v-loading="sqlExecuting" style="padding: 20px 0;">暂无数据</div>
|
||||
<div v-else style="position: relative;">
|
||||
<div style="position: absolute;right: 0;z-index: 1;" v-show="this.choiceResultObj[this.executeShowTable] && this.choiceResultObj[this.executeShowTable].length > 0">
|
||||
<!-- <el-button icon="el-icon-delete" size="small" @click="deleteCheckLine" type="danger" plain style="margin-right: 10px;">删除</el-button>-->
|
||||
<el-button icon="el-icon-delete" size="small" @click="deleteCheckLine" type="danger" plain style="margin-right: 10px;">删除</el-button>
|
||||
<!-- 复制选中行 -->
|
||||
<el-dropdown @command="handleCopyCheckLineCommand">
|
||||
<el-button type="primary" size="small" icon="el-icon-document-copy">
|
||||
@@ -93,6 +93,8 @@
|
||||
<el-option label="SQL Inserts" value="insert"></el-option>
|
||||
<el-option label="SQL Updates" value="update"></el-option>
|
||||
<el-option label="JSON" value="json"></el-option>
|
||||
<!-- <el-option label="Excel" value="excel"></el-option>-->
|
||||
<!-- <el-option label="CVS" value="cvs"></el-option>-->
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="数据表:" v-if="downloadDataParam.downloadType === 'insert'">
|
||||
@@ -377,7 +379,37 @@
|
||||
}
|
||||
},
|
||||
deleteCheckLine() {
|
||||
// todo
|
||||
let choiceData = this.choiceResultObj[this.executeShowTable] || [];
|
||||
if (choiceData.length > 0) {
|
||||
let primaryKey = this.primaryKeyColumn.name;
|
||||
if (!primaryKey) {
|
||||
this.$message.error("删除失败,未找到数据表的主键列");
|
||||
return;
|
||||
}
|
||||
// 通过主键ID和值删除行的数据
|
||||
let deleteParam = [];
|
||||
choiceData.forEach(item => {
|
||||
let line = {};
|
||||
line[primaryKey] = item[primaryKey];
|
||||
deleteParam.push(line);
|
||||
});
|
||||
this.$confirm(`确定要删除选中的${choiceData.length}行数据吗?`, '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
let param = {
|
||||
sourceId: this.pageParam.sourceId,
|
||||
dbName: this.pageParam.dbName,
|
||||
tableName: this.pageParam.tableName,
|
||||
lineJson: JSON.stringify(deleteParam)
|
||||
};
|
||||
datasourceApi.deleteTableLineData(param).then(() => {
|
||||
this.$message.success("删除成功!");
|
||||
this.refreshData();
|
||||
});
|
||||
}).catch(()=>{});
|
||||
}
|
||||
},
|
||||
handleCopyCheckLineCommand(type) {
|
||||
let choiceData = this.choiceResultObj[this.executeShowTable] || [];
|
||||
|
||||
Reference in New Issue
Block a user