<!DOCTYPE html>
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
<head>
|
<title>上传接口测试</title>
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
<script src="js/jquery.1.12.4.js"></script>
|
<script src="js/rsa.min.js"></script>
|
<script src="js/rollups.js"></script>
|
<script src="js/insertFiles.js"></script>
|
<script>
|
var app = {};
|
var path = "20230127";
|
var url = "http://127.0.0.1:12316/server/";
|
var token = "dca04924-122a-4b1a-88b7-aca0c4a7ba47";
|
|
$(function () {
|
$("#pathSpan").html(path);
|
$("#tokenSpan").html(token);
|
getPublicKey();
|
});
|
|
// Ajax
|
function ajax(url, type, data, dataType, contentType, fn) {
|
$.ajax({
|
url: url,
|
type: type,
|
data: data,
|
dataType: dataType || "json", // html、json、jsonp、script、text
|
contentType: contentType || "application/json", // "application/x-www-form-urlencoded"
|
success: function (data) {
|
fn(data);
|
},
|
error: function (e) {
|
console.error(e);
|
fn();
|
}
|
});
|
}
|
|
// 获取URL
|
function getUrl(method) {
|
return url + method + "?token=" + token;
|
}
|
|
function getPublicKey() {
|
$.get(url + "sign/getPublicKey", function (rs) {
|
if (rs && rs.code == 200) {
|
window.encrypt = new JSEncrypt();
|
encrypt.setPublicKey(rs.result);
|
}
|
});
|
}
|
</script>
|
<script>
|
// 查询目录
|
function selectPath() {
|
ajax(getUrl("dataUpload/selectPath"), "GET", null, null, null, function (rs) {
|
console.log(rs);
|
alert("code = " + rs.code + ", msg = " + rs.msg + ", result = " + rs.result);
|
path = rs.result;
|
});
|
}
|
|
// 上传文件
|
function uploadFiles() {
|
var formData = new FormData();
|
var fs = document.getElementById("file1");
|
for (var i = 0, c = fs.files.length; i < c; i++) {
|
formData.append(fs.files[i].name, fs.files[i]); // fs.files[i].name,file
|
}
|
|
$.ajax(getUrl("dataUpload/uploadFiles") + "&path=" + path, {
|
type: "post",
|
data: formData,
|
async: true,
|
cache: false,
|
processData: false,
|
contentType: false,
|
success: function (rs) {
|
document.getElementById("file1").value = "";
|
console.log(rs);
|
alert("code = " + rs.code + ", msg = " + rs.msg + ", result = " + rs.result);
|
},
|
error: function (e) {
|
document.getElementById("file1").value = "";
|
console.error(e);
|
alert("上传文件失败!");
|
}
|
});
|
}
|
|
// 查询文件
|
function selectFiles() {
|
ajax(getUrl("dataUpload/selectFiles") + "&path=" + path, "GET", null, null, null, function (rs) {
|
console.log(rs);
|
alert("code = " + rs.code + ", msg = " + rs.msg + ", result = " + rs.result);
|
app.data = rs.result;
|
});
|
}
|
|
// 删除文件
|
function deleteFiles() {
|
if (app.data == null) return;
|
|
ajax(getUrl("dataUpload/deleteFiles"), "POST", JSON.stringify([data[0]]), null, null, function (rs) {
|
console.log(rs);
|
alert("code = " + rs.code + ", msg = " + rs.msg + ", result = " + rs.result);
|
selectFiles();
|
});
|
}
|
|
// 读取映射
|
function readMappers() {
|
ajax(getUrl("dataUpload/selectMappers") + "&path=" + path + "&dirid=163&verid=0&epsgCode=EPSG:4490", "GET", null, null, null, function (rs) {
|
console.log(rs);
|
alert("code = " + rs.code + ", msg = " + rs.msg + ", result = " + rs.result);
|
if (rs.code == 200) {
|
app.mappers = rs.result;
|
}
|
});
|
}
|
|
// Xls入库 *
|
function insertXls() {
|
if (app.data == null) return;
|
|
var obj = {
|
metaEntity: {
|
depid: 1,
|
dirid: 10,
|
verid: 0,
|
//type: "file",
|
//cs: "CGCS 2000",
|
//scale: "1:1000",
|
//resolution: "0.5m",
|
gather: "2022-10-05 15:00:00",
|
descr: "测试Xls",
|
},
|
fileEntities: app.data,
|
tabEntities: [
|
{ filename: "2-2 管线成果表.xlsx", subPath: "20221128010101\2-2 管线成果表.xlsx", tab: null, entity: "mdGdcg", type: "xls" },
|
{ filename: "海原县中线成果表.xlsx", subPath: "20221128010101\海原县中线成果表.xlsx", tab: null, entity: "mdZxcg", type: "xls" }
|
]
|
};
|
|
ajax(getUrl("dataLoader/insertFiles"), "POST", JSON.stringify(obj), null, null, function (rs) {
|
console.log(rs);
|
app.data = null;
|
alert("code = " + rs.code + ", msg = " + rs.msg + ", result = " + rs.result);
|
});
|
}
|
</script>
|
<script>
|
// 上传附件
|
function uploadAttach() {
|
var formData = new FormData();
|
var fs = document.getElementById("file3");
|
if (fs.files.length == 0) {
|
alert("请选择要上传的文件!");
|
return;
|
}
|
for (var i = 0, c = fs.files.length; i < c; i++) {
|
formData.append("file", fs.files[i]); // fs.files[i].name,file
|
}
|
|
$.ajax(getUrl("dataQuery/uploadFiles") + "&tabName=lf.sys_style&eventid=fa25979a5ef8b43ba82a0be35b3fb0d4", {
|
type: "post",
|
data: formData,
|
async: true,
|
cache: false,
|
processData: false,
|
contentType: false,
|
success: function (rs) {
|
console.log(rs);
|
document.getElementById("file3").value = "";
|
alert("code = " + rs.code + ", msg = " + rs.msg + ", result = " + rs.result);
|
},
|
error: function (e) {
|
console.error(e);
|
document.getElementById("file3").value = "";
|
alert("上传文件失败!");
|
}
|
});
|
}
|
</script>
|
<script>
|
function downloadReq() {
|
var obj = {
|
pwd: encrypt.encrypt("Test!321&456"),
|
ids: [113, 120, 121, 122]
|
};
|
|
ajax(getUrl("meta/downloadReq"), "POST", JSON.stringify(obj), null, null, function (rs) {
|
console.log(rs);
|
alert("code = " + rs.code + ", msg = " + rs.msg + ", result = " + rs.result);
|
});
|
}
|
|
function selectDownloadFile() {
|
var guid = "af68c8d6d847070e3a3055ba58e05929"; // "5ce046cc05b186332775c03ac6792caf";
|
var pwd = encodeURIComponent(encrypt.encrypt("Test!321&456")); // Admin@123
|
|
ajax(getUrl("meta/selectDownloadFile") + "&guid=" + guid + "&pwd=" + pwd, "GET", null, null, null, function (rs) {
|
console.log(rs);
|
//alert("code = " + rs.code + ", msg = " + rs.msg + ", result = " + rs.result);
|
if (rs.code != 200 || !rs.result) {
|
alert(rs.msg);
|
return;
|
}
|
|
downloadFile(guid, pwd);
|
});
|
}
|
|
function downloadFile(guid, pwd) {
|
//var a = document.createElement('a');
|
//a.style.display = 'none';
|
//a.href = getUrl("meta/downloadFile") + "&guid=" + guid + "&pwd=" + encodeURIComponent(encrypt.encrypt("Admin@123"));
|
|
//document.body.appendChild(a);
|
//a.click();
|
//document.body.removeChild(a);
|
|
var url = getUrl("meta/downloadFile") + "&guid=" + guid + "&pwd=" + pwd;
|
$("#downFrame").attr("src", url).click();
|
}
|
</script>
|
<script>
|
function downloadDbReq() {
|
var obj = {
|
pwd: encrypt.encrypt("Test!321&456"),
|
entities: ["dlgagnp", "dlg25wboul", "dlg25wresa"],
|
// entities: ["dlgagnp"],
|
wkt: aesEncrypt("POLYGON ((115.94927385452 32.3754479115071 0,121.989371092554 32.2766788010181 0,121.850621222894 29.6874200067864 0,115.9727267226 29.7835368627922 0,115.94927385452 32.3754479115071 0))")
|
};
|
|
ajax(getUrl("dataLib/downloadDbReq"), "POST", JSON.stringify(obj), null, null, function (rs) {
|
console.log(rs);
|
alert("code = " + rs.code + ", msg = " + rs.msg + ", result = " + rs.result);
|
});
|
}
|
|
function aesEncrypt(word) {
|
return CryptoJS.AES.encrypt(CryptoJS.enc.Utf8.parse(word), CryptoJS.enc.Utf8.parse(base64Decode("QSNzX2xGX3NFcnZlX2sueQ==")), { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 }).toString();
|
}
|
|
function aesDecrypt(word) {
|
return CryptoJS.enc.Utf8.stringify(CryptoJS.AES.decrypt(word, CryptoJS.enc.Utf8.parse(base64Decode("QSNzX2xGX3NFcnZlX2sueQ==")), { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 })).toString();
|
}
|
</script>
|
<script>
|
function selectDbOverflowDep() {
|
var obj = {
|
// entities: ["dlgagnp"],
|
entities: ["dlgagnp", "dlg25wboul", "dlg25wresa"],
|
wkt: aesEncrypt("POLYGON ((115.94927385452 32.3754479115071 0,121.989371092554 32.2766788010181 0,121.850621222894 29.6874200067864 0,115.9727267226 29.7835368627922 0,115.94927385452 32.3754479115071 0))")
|
};
|
|
ajax(getUrl("dataLib/selectDbOverflowDep"), "POST", JSON.stringify(obj), null, null, function (rs) {
|
console.log(rs);
|
alert("code = " + rs.code + ", msg = " + rs.msg + ", result = " + rs.result);
|
});
|
}
|
|
function insertApply() {
|
var obj = {
|
ids: [20, 21, 22],
|
pwd: aesEncrypt("Test!321&456"),
|
tabs: ["城市点", "行政区划线", "居民地面"],
|
entities: ["dlgagnp", "dlg25wboul", "dlg25wresa"],
|
wkt: aesEncrypt("POLYGON ((115.94927385452 32.3754479115071 0,121.989371092554 32.2766788010181 0,121.850621222894 29.6874200067864 0,115.9727267226 29.7835368627922 0,115.94927385452 32.3754479115071 0))"),
|
descr: "用于生产项目,请批准"
|
};
|
|
ajax(getUrl("apply/insertApply"), "POST", JSON.stringify(obj), null, null, function (rs) {
|
console.log(rs);
|
alert("code = " + rs.code + ", msg = " + rs.msg + ", result = " + rs.result);
|
});
|
}
|
|
// 综合数据入库
|
function insertAllFiles() {
|
ajax(getUrl("dataUpload/insertFiles"), "POST", JSON.stringify(metaFiles), null, null, function (rs) {
|
console.log(rs);
|
alert("code = " + rs.code + ", msg = " + rs.msg + ", result = " + rs.result);
|
});
|
}
|
|
// 多文件入库
|
function insertMultiFiles() {
|
if (!app.mappers) return;
|
ajax(getUrl("dataUpload/insertFiles"), "POST", JSON.stringify(app.mappers), null, null, function (rs) {
|
console.log(rs);
|
app.mappers = null;
|
alert("code = " + rs.code + ", msg = " + rs.msg + ", result = " + rs.result);
|
});
|
}
|
|
// 挂载附件
|
function uploadAnnex() {
|
var formData = new FormData();
|
var fs = document.getElementById("file1");
|
if (fs.files.length == 0) {
|
alert("请选择要上传的文件!");
|
return;
|
}
|
for (var i = 0, c = fs.files.length; i < c; i++) {
|
formData.append("file", fs.files[i]); // fs.files[i].name,file
|
}
|
formData.append("ids", 1209);
|
formData.append("ids", 1180);
|
formData.append("ids", 1387);
|
|
//$.ajax(getUrl("dataUpload/uploadXlsAnnex") + "&path=" + path + "&ids=1209&ids=1180&ids=1387", {
|
$.ajax(getUrl("dataUpload/uploadXlsAnnex") + "&path=" + path, {
|
type: "post",
|
data: formData,
|
async: true,
|
cache: false,
|
processData: false,
|
contentType: false,
|
success: function (rs) {
|
console.log(rs);
|
document.getElementById("file1").value = "";
|
alert("code = " + rs.code + ", msg = " + rs.msg + ", result = " + rs.result);
|
},
|
error: function (e) {
|
console.error(e);
|
document.getElementById("file3").value = "";
|
alert("上传文件失败!");
|
}
|
});
|
}
|
|
// 空间数据入库
|
function insertDbFiles() {
|
ajax(getUrl("dataUpload/insertFiles"), "POST", JSON.stringify(dbFiles), null, null, function (rs) {
|
console.log(rs);
|
alert("code = " + rs.code + ", msg = " + rs.msg + ", result = " + rs.result);
|
});
|
}
|
|
// 请求管线分析
|
function selectPipeAnalysis() {
|
var data = {
|
gid: 24,
|
tabs: ["bd.dlg_25w_hydl", "bd.dlg_25w_lrdl", "bd.dlg_25w_lrrl", "bd.dlg_25w_hyda"]
|
};
|
ajax(getUrl("pipeline/selectPipeAnalysis"), "POST", JSON.stringify(data), null, null, function (rs) {
|
console.log(rs);
|
alert("code = " + rs.code + ", msg = " + rs.msg + ", result = " + rs.result);
|
});
|
}
|
|
// 管线分析结果下载
|
function downloadPipeAnalysis() {
|
var data = {
|
pwd: encrypt.encrypt("Test!321&456"),
|
gid: 24,
|
tabs: ["bd.dlg_25w_hydl", "bd.dlg_25w_lrdl", "bd.dlg_25w_lrrl", "bd.dlg_25w_hyda"]
|
};
|
ajax(getUrl("pipeline/downloadReq"), "POST", JSON.stringify(data), null, null, function (rs) {
|
console.log(rs);
|
alert("code = " + rs.code + ", msg = " + rs.msg + ", result = " + rs.result);
|
});
|
}
|
</script>
|
</head>
|
<body>
|
<form id="upForm" name="upForm" method="post" enctype="multipart/form-data" action="http://127.0.0.1:12316/file/upload">
|
上传路径:<span id="pathSpan"></span>,当前令牌:<span id="tokenSpan"></span>
|
<hr />
|
<br />
|
|
数据入库:
|
<input id="file1" type="file" multiple="multiple" accept=".xls,.xlsx,.mdb,.zip" />
|
<input value="查询目录 *" type="button" onclick="selectPath();" />
|
<input value="上传文件" type="button" onclick="uploadFiles();" />
|
<input value="查询文件 *" type="button" onclick="selectFiles();" />
|
<input value="删除文件" type="button" onclick="deleteFiles();" />
|
<!--<input value="Xls入库" type="button" onclick="insertXls();" />-->
|
<input value="读取映射 *" type="button" onclick="readMappers();" />
|
<input value="综合数据入库 *" type="button" onclick="insertAllFiles();" />
|
<input value="空间数据入库 *" type="button" onclick="insertDbFiles();" />
|
<input value="多文件入库 *" type="button" onclick="insertMultiFiles();" />
|
<input value="挂载附件 *" type="button" onclick="uploadAnnex();" />
|
<hr />
|
<br />
|
|
数据检索:
|
<input id="file3" type="file" multiple="multiple" />
|
<input value="上传附件" type="button" onclick="uploadAttach();" />
|
<hr />
|
<br />
|
|
元数据:
|
<input value="请求下载" type="button" onclick="downloadReq();" />
|
<input value="下载文件" type="button" onclick="selectDownloadFile();" />
|
<iframe id="downFrame" src="" style="display: none; border: 0; padding: 0; height: 0; width: 0"></iframe>
|
<hr />
|
<br />
|
|
空间数据:
|
<input value="请求下载" type="button" onclick="downloadDbReq();" />
|
<input value="下载文件" type="button" onclick="selectDownloadFile();" />
|
<hr />
|
<br />
|
|
数据申请:
|
<input value="查询DB中溢出的单位ID" type="button" onclick="selectDbOverflowDep();" />
|
<input value="插入数据申请" type="button" onclick="insertApply();" />
|
<input value="请求管线分析" type="button" onclick="selectPipeAnalysis();" />
|
<input value="管线分析结果下载" type="button" onclick="downloadPipeAnalysis();" />
|
<hr />
|
<br />
|
</form>
|
<br />
|
<br />
|
</body>
|
</html>
|