diff --git a/src/main/java/org/mobidgim/mobidigimproject/controller/Controller.java b/src/main/java/org/mobidgim/mobidigimproject/controller/Controller.java index 4afe714..62d0a81 100644 --- a/src/main/java/org/mobidgim/mobidigimproject/controller/Controller.java +++ b/src/main/java/org/mobidgim/mobidigimproject/controller/Controller.java @@ -9,6 +9,9 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import java.io.IOException; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; + @RestController @RequestMapping("/setting") @@ -44,4 +47,11 @@ public class Controller { var entity = settingService.readFileWithRegister(); return Api.OK(entity); } + + @PostMapping("/register-upload") + public Api toUpload(@RequestBody RegisterDTO request) throws IOException { + boolean success = settingService.registerUpload(request); + return success ? Api.OK("succes upload") : Api.ERROR("false upload"); + } + } diff --git a/src/main/java/org/mobidgim/mobidigimproject/service/SettingService.java b/src/main/java/org/mobidgim/mobidigimproject/service/SettingService.java index ec0329f..8e59887 100644 --- a/src/main/java/org/mobidgim/mobidigimproject/service/SettingService.java +++ b/src/main/java/org/mobidgim/mobidigimproject/service/SettingService.java @@ -17,6 +17,7 @@ import org.springframework.stereotype.Service; import javax.swing.text.html.parser.Parser; import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; import java.nio.file.Path; @@ -100,4 +101,17 @@ public class SettingService { return registerDTO; } + public boolean registerUpload(RegisterDTO request) throws IOException{ + try{ + String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(request); + Files.write(Paths.get("./temp/registerConfig.json"),json.getBytes(StandardCharsets.UTF_8)); + return true; + } + catch(Exception e){ + e.printStackTrace(); + return false; + } + + } + } diff --git a/src/main/resources/static/index.html b/src/main/resources/static/index.html index ed24fcf..e91bc4a 100644 --- a/src/main/resources/static/index.html +++ b/src/main/resources/static/index.html @@ -450,6 +450,7 @@
+
@@ -531,6 +532,7 @@
+
@@ -604,6 +606,7 @@
+
@@ -670,6 +673,7 @@
+
@@ -1704,6 +1708,85 @@ } }); }); + + document.getElementById('uploadProtocolBtn').addEventListener('click', () => { + fetch('http://localhost:8080/setting/register-upload', { + method: 'POST', + headers: {'Content-Type': 'application/json'}, + body: JSON.stringify(collectConfigData()) + }) + .then(res => res.json()) + .then(data => { + // result_code가 200이면 성공 + if (data.result && data.result.result_code === 200) { + alert('하드웨어 업로드 성공!'); + } else { + alert('하드웨어 업로드 실패: ' + (data.result?.result_message || data.body || '')); + } + }) + .catch(err => { + alert('통신 오류: ' + err.message); + }); + }); + document.getElementById('uploadModbusBtn').addEventListener('click', () => { + fetch('http://localhost:8080/setting/register-upload', { + method: 'POST', + headers: {'Content-Type': 'application/json'}, + body: JSON.stringify(collectConfigData()) + }) + .then(res => res.json()) + .then(data => { + // result_code가 200이면 성공 + if (data.result && data.result.result_code === 200) { + alert('하드웨어 업로드 성공!'); + } else { + alert('하드웨어 업로드 실패: ' + (data.result?.result_message || data.body || '')); + } + }) + .catch(err => { + alert('통신 오류: ' + err.message); + }); + }); + document.getElementById('uploadOpcuaFileBtn').addEventListener('click', () => { + fetch('http://localhost:8080/setting/register-upload', { + method: 'POST', + headers: {'Content-Type': 'application/json'}, + body: JSON.stringify(collectConfigData()) + }) + .then(res => res.json()) + .then(data => { + // result_code가 200이면 성공 + if (data.result && data.result.result_code === 200) { + alert('하드웨어 업로드 성공!'); + } else { + alert('하드웨어 업로드 실패: ' + (data.result?.result_message || data.body || '')); + } + }) + .catch(err => { + alert('통신 오류: ' + err.message); + }); + }); + document.getElementById('uploadCanBtn').addEventListener('click', () => { + fetch('http://localhost:8080/setting/register-upload', { + method: 'POST', + headers: {'Content-Type': 'application/json'}, + body: JSON.stringify(collectConfigData()) + }) + .then(res => res.json()) + .then(data => { + // result_code가 200이면 성공 + if (data.result && data.result.result_code === 200) { + alert('하드웨어 업로드 성공!'); + } else { + alert('하드웨어 업로드 실패: ' + (data.result?.result_message || data.body || '')); + } + }) + .catch(err => { + alert('통신 오류: ' + err.message); + }); + }); + + \ No newline at end of file