문자 agent 테스트 mms 파일 전송 진행중

파일경로 수정
This commit is contained in:
hylee 2024-08-19 15:55:31 +09:00
parent 2d42bb1348
commit 967e4e87a5
3 changed files with 66 additions and 5 deletions

View File

@ -4,16 +4,29 @@ import com.itn.admin.agent.client.one.mapper.domain.AgentCOneVO;
import com.itn.admin.agent.client.one.service.AgentCOneService;
import com.itn.admin.cmn.msg.RestResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.HashMap;
import java.util.Map;
@RestController
public class AgentCOneRestController {
private AgentCOneService agentCOneService;
private final String UPLOAD_DIR = "/home/mjon_client_agent_1/mmsfile";
@Autowired
@ -56,4 +69,53 @@ public class AgentCOneRestController {
public ResponseEntity<RestResponse> findByLogMoveCnt(@RequestBody AgentCOneVO agentCOneVO) throws Exception {
return ResponseEntity.ok().body(agentCOneService.findAllLogMoveCnt(agentCOneVO));
}
@PostMapping("/agent/one/uploadFiles")
public ResponseEntity<RestResponse> uploadFiles(@RequestParam("filename01") MultipartFile file1,
@RequestParam("filename02") MultipartFile file2,
@RequestParam("filename03") MultipartFile file3) {
try {
Map<String, String> fileNames = new HashMap<>();
// 파일을 업로드하고 파일명을 수집
String fileName = "";
if (!file1.isEmpty()) {
fileName = uploadSingleFile(file1);
fileNames.put("fileName01", fileName);
}
if (!file2.isEmpty()) {
fileName = uploadSingleFile(file2);
fileNames.put("fileName02", fileName);
}
if (!file3.isEmpty()) {
fileName = uploadSingleFile(file3);
fileNames.put("fileName03", fileName);
}
// 경로와 파일명 반환
Map<String, Object> response = new HashMap<>();
response.put("fileNames", fileNames);
response.put("status", "OK");
return ResponseEntity.ok(new RestResponse(HttpStatus.OK, "",response) );
} catch (IOException ex) {
return ResponseEntity.ok(new RestResponse(HttpStatus.INTERNAL_SERVER_ERROR, "저장실패","") );
}
}
private String uploadSingleFile(MultipartFile file) throws IOException {
String fileName = StringUtils.cleanPath(file.getOriginalFilename());
Path uploadPath = Paths.get(UPLOAD_DIR);
if (!Files.exists(uploadPath)) {
Files.createDirectories(uploadPath);
}
Path filePath = uploadPath.resolve(fileName);
Files.copy(file.getInputStream(), filePath, StandardCopyOption.REPLACE_EXISTING);
return fileName;
}
}

View File

@ -26,7 +26,7 @@ public class AgentCTwoRestController {
private AgentCTwoService agentCTwoService;
private final String UPLOAD_DIR = "/home/mjon_client_agent_1/mmsfile";
private final String UPLOAD_DIR = "/home/mjon_client_agent_2/mmsfile";
@Autowired
@ -106,8 +106,7 @@ public class AgentCTwoRestController {
private String uploadSingleFile(MultipartFile file) throws IOException {
String fileName = StringUtils.cleanPath(file.getOriginalFilename());
String uploadDir = "user-files/";
Path uploadPath = Paths.get(uploadDir);
Path uploadPath = Paths.get(UPLOAD_DIR);
if (!Files.exists(uploadPath)) {
Files.createDirectories(uploadPath);

View File

@ -887,7 +887,7 @@
return false;
}
console.log('jsonObject : ', jsonObject);
/*
$.ajax({
type: "POST",
url: "/agent/two/send",
@ -917,7 +917,7 @@
complete : function(xhr, textStatus) {
oneStopInsertTimer();
}
});*/
});
} else {
alert("파일 업로드 실패: " + response.msg);
}