[Backend] [區域資料管理][區域設定] 上傳3D模型,紀錄urn到資料庫

This commit is contained in:
wanli 2022-11-30 16:28:12 +08:00
parent 194ef691d4
commit 65e3655c6f
7 changed files with 403 additions and 130 deletions

View File

@ -104,22 +104,43 @@ namespace Backend.Controllers
//新增
//抓取當前的Priority
var current_priority = await backendRepository.GetCurrentPriority("building");
var map_3d_guid = new Guid();
var map_3d_guid = Guid.NewGuid();
Dictionary<string, object> building = new Dictionary<string, object>();
building = new Dictionary<string, object>()
if (post.urn_3D != null)
{
{ "@building_tag", post.building_tag},
{ "@full_name", post.Full_name},
{ "@ip_address", post.Ip_address},
{ "@ip_port", post.Ip_port},
{ "@priority", current_priority + 1},
{ "@orgName_3D", post.orgName_3D},
{ "@saveName_3D", map_3d_guid},
{ "@extName_3D", post.extName_3D},
{ "@created_by", myUserInfo.Userinfo_guid}
};
await backendRepository.AddOneByCustomTable(building, "building");
Dictionary<string, object> building = new Dictionary<string, object>();
building = new Dictionary<string, object>()
{
{ "@building_tag", post.building_tag},
{ "@full_name", post.Full_name},
{ "@ip_address", post.Ip_address},
{ "@ip_port", post.Ip_port},
{ "@priority", current_priority + 1},
{ "@orgName_3D", post.orgName_3D},
{ "@saveName_3D", map_3d_guid},
{ "@extName_3D", post.extName_3D},
{ "@urn_3D", post.urn_3D},
{ "@created_by", myUserInfo.Userinfo_guid}
};
await backendRepository.AddOneByCustomTable(building, "building");
}
else
{
Dictionary<string, object> building = new Dictionary<string, object>();
building = new Dictionary<string, object>()
{
{ "@building_tag", post.building_tag},
{ "@full_name", post.Full_name},
{ "@ip_address", post.Ip_address},
{ "@ip_port", post.Ip_port},
{ "@priority", current_priority + 1},
{ "@orgName_3D", post.orgName_3D},
{ "@saveName_3D", map_3d_guid},
{ "@extName_3D", post.extName_3D},
{ "@created_by", myUserInfo.Userinfo_guid}
};
await backendRepository.AddOneByCustomTable(building, "building");
}
if (post.orgName_3D != null && post.extName_3D != null)
{
@ -186,18 +207,38 @@ namespace Backend.Controllers
if (!judgeIPAddressRepeat)
{
Dictionary<string, object> building = new Dictionary<string, object>();
building = new Dictionary<string, object>()
if (post.urn_3D != null)
{
{ "@full_name", post.Full_name},
{ "@ip_address", post.Ip_address},
{ "@ip_port", post.Ip_port},
{ "@orgName_3D", post.orgName_3D},
{ "@extName_3D", post.extName_3D},
{ "@updated_by", myUserInfo.Userinfo_guid},
{ "@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}
};
await backendRepository.UpdateOneByCustomTable(building, "building", "building_tag='" + post.building_tag + "'");
Dictionary<string, object> building = new Dictionary<string, object>();
building = new Dictionary<string, object>()
{
{ "@full_name", post.Full_name},
{ "@ip_address", post.Ip_address},
{ "@ip_port", post.Ip_port},
{ "@orgName_3D", post.orgName_3D},
{ "@extName_3D", post.extName_3D},
{ "@urn_3D", post.urn_3D},
{ "@updated_by", myUserInfo.Userinfo_guid},
{ "@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}
};
await backendRepository.UpdateOneByCustomTable(building, "building", "building_tag='" + post.building_tag + "'");
}
else
{
Dictionary<string, object> building = new Dictionary<string, object>();
building = new Dictionary<string, object>()
{
{ "@full_name", post.Full_name},
{ "@ip_address", post.Ip_address},
{ "@ip_port", post.Ip_port},
{ "@orgName_3D", post.orgName_3D},
{ "@extName_3D", post.extName_3D},
{ "@updated_by", myUserInfo.Userinfo_guid},
{ "@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}
};
await backendRepository.UpdateOneByCustomTable(building, "building", "building_tag='" + post.building_tag + "'");
}
if (post.orgName_3D != null && post.extName_3D != null)
{

View File

@ -102,7 +102,7 @@ namespace forgeSample.Controllers
/// <returns></returns>
[HttpPost]
[Route("api/forge/oss/objects")]
public async Task<dynamic> UploadObject([FromForm] UploadFile input)
public async Task<string> UploadObject([FromForm] UploadFile input)
{
// save the file on the server
var fileSavePath = Path.Combine(_env.WebRootPath, Path.GetFileName(input.fileToUpload.FileName));
@ -126,10 +126,10 @@ namespace forgeSample.Controllers
// cleanup
System.IO.File.Delete(fileSavePath);
var a = Base64Encode((string)uploadedObj.objectId);
//var test = new TreeNode(Base64Encode((string)uploadedObj.objectId), objInfo.Value.objectKey, "object", false)
string urn = Base64Encode((string)uploadedObj.objectId);
string result = urn + "," + uploadedObj.objectKey;
return uploadedObj;
return result;//uploadedObj;
}
public class UploadFile

View File

@ -20,6 +20,7 @@ namespace Backend.Models
public string orgName_3D { get; set; }
public string saveName_3D { get; set; }
public string extName_3D { get; set; }
public string urn_3D { get; set; }
//public string Created_at { get; set; } //建立時間
}

View File

@ -45,6 +45,7 @@
var selected_build_guid_top = "";
var selected_build_guid_top_name;
var selected_floor_guid = "";
let input3Dfile = null;
//#region 區域基本資料 document ready
$(function () {
@ -261,121 +262,367 @@
maxlength: 50,
filterspace: true
},
file_3d_modal: {
accept: "image/svg+xml"
build_file_3d_modal: {
required: true, extension: "nwc|nwd"
}
}
},
messages: { build_file_3d_modal: "File must be nwc, nwd" }
});
//#endregion
//#region 儲存區域基本資料
function SaveBuild() {
if ($("#build-form").valid()) {
$("#save-building-btn").html('<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>').attr("disabled", true);
var url = "/BuildInfo/SaveBuildInfo";
var formData = new FormData();
formData.append("building_tag", $('#build_name_tag').val());
formData.append("Full_name", $('#build_name_modal').val());
formData.append("Ip_address", $('#ip_address_modal').val());
formData.append("Ip_port", $('#ip_port_modal').val());
if(input3Dfile != undefined && input3Dfile != null) {//上傳3d檔案至forge平台
var file = input3Dfile;
var formData = new FormData();
formData.append('fileToUpload', file);
formData.append('bucketKey', "ta3hqsffzqbnouxkpldkuksew4sj21w5-bims_models");//forge上傳平台-資料夾
maps = $('#build_file_3d_modal')[0].files;
if (maps.length > 0) {
var file_names = maps[0].name.split(".");
$.ajax({
url: '/api/forge/oss/objects',
data: formData,
processData: false,
contentType: false,
type: 'POST',
success: function (data) {
var datas = data.split(",");
var urn = datas[0];
let m3d_names = datas[1].split(".");
formData.append("Map3dFile", maps[0]);
formData.append("orgName_3D", file_names[0]);
formData.append("extName_3D", file_names[1]);
var url = "/BuildInfo/SaveBuildInfo";
var formData2 = new FormData();
formData2.append("building_tag", $('#build_name_tag').val());
formData2.append("Full_name", $('#build_name_modal').val());
formData2.append("Ip_address", $('#ip_address_modal').val());
formData2.append("Ip_port", $('#ip_port_modal').val());
maps = $('#build_file_3d_modal')[0].files;
if (maps.length > 0) {
var file_names = maps[0].name.split(".");
formData2.append("Map3dFile", maps[0]);
}
formData2.append("urn_3D", urn);
formData2.append("orgName_3D", m3d_names[0]);
formData2.append("extName_3D", m3d_names[1]);
$.ajax({
type: "POST",
url: url,
data: formData2,
cache: false,
contentType: false,
processData: false,
success: function (rel) {
$("#save-building-btn").html('確定').attr("disabled", false);
if (rel.code != "0000") {
if (rel.code == "9999") {
toast_error(rel.msg);
}
else {
toast_warning(rel.msg);
}
return;
}
else {
toast_ok(rel.msg);
buildInfoTable.ajax.reload(null, false);
$('#build-modal').modal('hide');
return;
}
},
fail: function (xhr, status, error) {
$("#save-building-btn").html('確定').attr("disabled", false);
}
});
},
fail: function (xhr, status, error) {
toast_error("上傳3d模型檔失敗!");
$("#save-building-btn").html('確定').attr("disabled", false);
}
});
}
else {
toast_warning("無3d模型檔案!");
var url = "/BuildInfo/SaveBuildInfo";
$.ajax({
type: "POST",
url: url,
data: formData,
cache: false,
contentType: false,
processData: false,
success: function (rel) {
$("#save-building-btn").html('確定').attr("disabled", false);
if (rel.code != "0000") {
if (rel.code == "9999") {
toast_error(rel.msg);
var formData = new FormData();
formData.append("building_tag", $('#build_name_tag').val());
formData.append("Full_name", $('#build_name_modal').val());
formData.append("Ip_address", $('#ip_address_modal').val());
formData.append("Ip_port", $('#ip_port_modal').val());
maps = $('#build_file_3d_modal')[0].files;
if (maps.length > 0) {
var file_names = maps[0].name.split(".");
formData.append("Map3dFile", maps[0]);
formData.append("orgName_3D", file_names[0]);
formData.append("extName_3D", file_names[1]);
}
$.ajax({
type: "POST",
url: url,
data: formData,
cache: false,
contentType: false,
processData: false,
success: function (rel) {
$("#save-building-btn").html('確定').attr("disabled", false);
if (rel.code != "0000") {
if (rel.code == "9999") {
toast_error(rel.msg);
}
else {
toast_warning(rel.msg);
}
return;
}
else {
toast_warning(rel.msg);
toast_ok(rel.msg);
buildInfoTable.ajax.reload(null, false);
$('#build-modal').modal('hide');
return;
}
return;
},
fail: function (xhr, status, error) {
$("#save-building-btn").html('確定').attr("disabled", false);
}
else {
toast_ok(rel.msg);
buildInfoTable.ajax.reload(null, false);
$('#build-modal').modal('hide');
return;
}
},
fail: function (xhr, status, error) {
$("#save-building-btn").html('確定').attr("disabled", false);
}
});
});
}
//var url = "/BuildInfo/SaveBuildInfo";
//var formData = new FormData();
//formData.append("building_tag", $('#build_name_tag').val());
//formData.append("Full_name", $('#build_name_modal').val());
//formData.append("Ip_address", $('#ip_address_modal').val());
//formData.append("Ip_port", $('#ip_port_modal').val());
//maps = $('#build_file_3d_modal')[0].files;
//if (maps.length > 0) {
// var file_names = maps[0].name.split(".");
// formData.append("Map3dFile", maps[0]);
// formData.append("orgName_3D", file_names[0]);
// formData.append("extName_3D", file_names[1]);
//}
//$.ajax({
// type: "POST",
// url: url,
// data: formData,
// cache: false,
// contentType: false,
// processData: false,
// success: function (rel) {
// $("#save-building-btn").html('確定').attr("disabled", false);
// if (rel.code != "0000") {
// if (rel.code == "9999") {
// toast_error(rel.msg);
// }
// else {
// toast_warning(rel.msg);
// }
// return;
// }
// else {
// toast_ok(rel.msg);
// buildInfoTable.ajax.reload(null, false);
// $('#build-modal').modal('hide');
// return;
// }
// },
// fail: function (xhr, status, error) {
// $("#save-building-btn").html('確定').attr("disabled", false);
// }
//});
}
}
function EditBuild() {
if ($("#build-form").valid()) {
$("#save-building-btn").html('<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>').attr("disabled", true);
var url = "/BuildInfo/EditBuildInfo";
var formData = new FormData();
if (input3Dfile != undefined && input3Dfile != null) {//上傳3d檔案至forge平台
var file = input3Dfile;
var formData = new FormData();
formData.append('fileToUpload', file);
formData.append('bucketKey', "ta3hqsffzqbnouxkpldkuksew4sj21w5-bims_models");//forge上傳平台-資料夾
formData.append("building_tag", selected_build_guid);
formData.append("Full_name", $('#build_name_modal').val());
formData.append("Ip_address", $('#ip_address_modal').val());
formData.append("Ip_port", $('#ip_port_modal').val());
$.ajax({
url: '/api/forge/oss/objects',
data: formData,
processData: false,
contentType: false,
type: 'POST',
success: function (data) {
var datas = data.split(",");
var urn = datas[0];
let m3d_names = datas[1].split(".");
maps = $('#build_file_3d_modal')[0].files;
if (maps.length > 0) {
var file_names = maps[0].name.split(".");
var url = "/BuildInfo/EditBuildInfo";
var formData2 = new FormData();
formData.append("Map3dFile", maps[0]);
formData.append("orgName_3D", file_names[0]);
formData.append("extName_3D", file_names[1]);
formData2.append("building_tag", selected_build_guid);
formData2.append("Full_name", $('#build_name_modal').val());
formData2.append("Ip_address", $('#ip_address_modal').val());
formData2.append("Ip_port", $('#ip_port_modal').val());
maps = $('#build_file_3d_modal')[0].files;
if (maps.length > 0) {
var file_names = maps[0].name.split(".");
formData2.append("Map3dFile", maps[0]);
//formData2.append("orgName_3D", file_names[0]);
//formData2.append("extName_3D", file_names[1]);
}
formData2.append("urn_3D", urn);
formData2.append("orgName_3D", m3d_names[0]);
formData2.append("extName_3D", m3d_names[1]);
$.ajax({
type: "POST",
url: url,
data: formData2,
cache: false,
contentType: false,
processData: false,
success: function (rel) {
$("#save-building-btn").html('確定').attr("disabled", false);
if (rel.code != "0000") {
if (rel.code == "9999") {
toast_error(rel.msg);
}
else {
toast_warning(rel.msg);
}
return;
}
else {
toast_ok(rel.msg);
buildInfoTable.ajax.reload(null, false);
$('#build-modal').modal('hide');
return;
}
},
fail: function (xhr, status, error) {
$("#save-building-btn").html('確定').attr("disabled", false);
}
});
},
fail: function (xhr, status, error) {
toast_error("上傳3d模型檔失敗!");
$("#save-building-btn").html('確定').attr("disabled", false);
}
});
}
else {
var url = "/BuildInfo/EditBuildInfo";
var formData = new FormData();
$.ajax({
type: "POST",
url: url,
data: formData,
cache: false,
contentType: false,
processData: false,
success: function (rel) {
$("#save-building-btn").html('確定').attr("disabled", false);
if (rel.code != "0000") {
if (rel.code == "9999") {
toast_error(rel.msg);
formData.append("building_tag", selected_build_guid);
formData.append("Full_name", $('#build_name_modal').val());
formData.append("Ip_address", $('#ip_address_modal').val());
formData.append("Ip_port", $('#ip_port_modal').val());
maps = $('#build_file_3d_modal')[0].files;
if (maps.length > 0) {
var file_names = maps[0].name.split(".");
formData.append("Map3dFile", maps[0]);
formData.append("orgName_3D", file_names[0]);
formData.append("extName_3D", file_names[1]);
}
$.ajax({
type: "POST",
url: url,
data: formData,
cache: false,
contentType: false,
processData: false,
success: function (rel) {
$("#save-building-btn").html('確定').attr("disabled", false);
if (rel.code != "0000") {
if (rel.code == "9999") {
toast_error(rel.msg);
}
else {
toast_warning(rel.msg);
}
return;
}
else {
toast_warning(rel.msg);
toast_ok(rel.msg);
buildInfoTable.ajax.reload(null, false);
$('#build-modal').modal('hide');
return;
}
return;
},
fail: function (xhr, status, error) {
$("#save-building-btn").html('確定').attr("disabled", false);
}
else {
toast_ok(rel.msg);
buildInfoTable.ajax.reload(null, false);
$('#build-modal').modal('hide');
return;
}
},
fail: function (xhr, status, error) {
$("#save-building-btn").html('確定').attr("disabled", false);
}
});
});
}
//var url = "/BuildInfo/EditBuildInfo";
//var formData = new FormData();
//formData.append("building_tag", selected_build_guid);
//formData.append("Full_name", $('#build_name_modal').val());
//formData.append("Ip_address", $('#ip_address_modal').val());
//formData.append("Ip_port", $('#ip_port_modal').val());
//maps = $('#build_file_3d_modal')[0].files;
//if (maps.length > 0) {
// var file_names = maps[0].name.split(".");
// formData.append("Map3dFile", maps[0]);
// formData.append("orgName_3D", file_names[0]);
// formData.append("extName_3D", file_names[1]);
//}
//$.ajax({
// type: "POST",
// url: url,
// data: formData,
// cache: false,
// contentType: false,
// processData: false,
// success: function (rel) {
// $("#save-building-btn").html('確定').attr("disabled", false);
// if (rel.code != "0000") {
// if (rel.code == "9999") {
// toast_error(rel.msg);
// }
// else {
// toast_warning(rel.msg);
// }
// return;
// }
// else {
// toast_ok(rel.msg);
// buildInfoTable.ajax.reload(null, false);
// $('#build-modal').modal('hide');
// return;
// }
// },
// fail: function (xhr, status, error) {
// $("#save-building-btn").html('確定').attr("disabled", false);
// }
//});
}
}
//#endregion
</script>
<script>
//#region 樓層設定 document ready
$(function () {
@ -701,29 +948,13 @@
}
//#endregion
//#region 變更樓層平面圖
//#region 變更樓層平面圖 3d模型
function changeImage(input) {
$(`#map_file_preview_modal`).attr("data-src", window.URL.createObjectURL(input.files[0]));
console.log("---- abc test ---");
var file = input.files[0];
var formData = new FormData();
formData.append('fileToUpload', file);
formData.append('bucketKey', "ta3hqsffzqbnouxkpldkuksew4sj21w5-bims_models");
$.ajax({
url: '/api/forge/oss/objects',
data: formData,
processData: false,
contentType: false,
type: 'POST',
success: function (data) {
$('#appBuckets').jstree(true).refresh_node(node);
_this.value = '';
}
});
input3Dfile = input.files[0];
}
//#endregion
</script>
}

View File

@ -57,7 +57,7 @@
<input type="text" id="ip_port_modal" class="form-control" name="ip_port_modal">
</div>
<div class="form-group col-12">
<label class="form-label" for="build_file_3d_modal">3D檔(限制SVG格式)</label>
<label class="form-label" for="build_file_3d_modal">3D檔(限制NWD、NWC格式)</label>
<input type="file" id="build_file_3d_modal" class="form-control" name="build_file_3d_modal" onchange="changeImage(this)">
</div>
</div>