From b55d150bc0eba37bce36faf4def39aad46de554a Mon Sep 17 00:00:00 2001 From: nevermoregb Date: Fri, 4 Apr 2025 13:21:23 +0900 Subject: [PATCH] =?UTF-8?q?=EC=82=AC=EC=9B=90=EB=93=B1=EB=A1=9D=ED=94=84?= =?UTF-8?q?=EB=A1=9C=EC=84=B8=EC=8A=A4=20=EC=B6=94=EA=B0=80,=20=EC=A3=BC?= =?UTF-8?q?=EA=B0=84=20=EB=82=A0=EC=94=A8=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20?= =?UTF-8?q?=EC=A0=84=ED=99=94=20=ED=94=84=EB=A1=9C=EC=84=B8=EC=8A=A4=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/api/MainController.java | 17 ++++ .../controller/common/WeatherController.java | 95 ++++++++++++++++++- .../localhost/mapper/NetmemberMapper.java | 4 + .../localhost/service/MainService.java | 30 ++++++ .../localhost/service/NetmemberService.java | 8 ++ .../io/company/localhost/vo/WeatherVo.java | 33 +++++++ src/main/resources/mapper/NetmemberMapper.xml | 21 ++++ 7 files changed, 206 insertions(+), 2 deletions(-) create mode 100644 src/main/java/io/company/localhost/vo/WeatherVo.java diff --git a/src/main/java/io/company/localhost/controller/api/MainController.java b/src/main/java/io/company/localhost/controller/api/MainController.java index 817d573..ee58698 100644 --- a/src/main/java/io/company/localhost/controller/api/MainController.java +++ b/src/main/java/io/company/localhost/controller/api/MainController.java @@ -4,6 +4,7 @@ import java.util.List; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -59,4 +60,20 @@ public class MainController { public ApiResponse> registerMemberList() { return mainService.registerMemberList(); } + + @Admin + @ParameterCheck + @PostMapping("/registerMember") + public ApiResponse registerMember(@ReqMap MapDto map) { + long memberSeq = map.getInt("memberSeq"); + return mainService.registerMember(memberSeq); + } + + @Admin + @ParameterCheck + @PostMapping("/rejectMember") + public ApiResponse rejectMember(@ReqMap MapDto map) { + long memberSeq = map.getInt("memberSeq"); + return mainService.rejectMember(memberSeq); + } } diff --git a/src/main/java/io/company/localhost/controller/common/WeatherController.java b/src/main/java/io/company/localhost/controller/common/WeatherController.java index 1f003ea..4fd9485 100644 --- a/src/main/java/io/company/localhost/controller/common/WeatherController.java +++ b/src/main/java/io/company/localhost/controller/common/WeatherController.java @@ -1,5 +1,10 @@ package io.company.localhost.controller.common; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -7,17 +12,27 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + import io.company.localhost.common.dto.ApiResponse; +import io.company.localhost.common.dto.MapDto; +import io.company.localhost.vo.WeatherVo; +import lombok.RequiredArgsConstructor; @RestController +@RequiredArgsConstructor @RequestMapping("/api/weather") public class WeatherController { @Value("${api.weather.key}") private String weatherApiKey; + + private final ObjectMapper objectMapper; + @GetMapping - public ApiResponse getWeather(@RequestParam("lat") double lat,@RequestParam("lon") double lon) { + public ApiResponse getWeather(@RequestParam("lat") double lat,@RequestParam("lon") double lon) throws Exception { String url = String.format( "https://api.openweathermap.org/data/2.5/forecast?lat=%f&lon=%f&appid=%s&units=metric&lang=kr", lat, lon, weatherApiKey @@ -25,8 +40,84 @@ public class WeatherController { RestTemplate restTemplate = new RestTemplate(); String response = restTemplate.getForObject(url, String.class); + List list = this.convertDailyForecast(response); + + MapDto map = new MapDto(); + map.put("weatherInfo", response); + map.put("dailyWeatherList", list); - return ApiResponse.ok(response); + return ApiResponse.ok(map); + } + + + /** + * 일별 데이터 전환 + * + * @param jsonData + * @return + * @throws Exception + */ + private List convertDailyForecast(String jsonData) throws Exception { + JsonNode nodeData = objectMapper.readTree(jsonData); + JsonNode forecastList = nodeData.get("list"); + + // 날짜별로 데이터 그룹화 + Map> dailyWeathers = new HashMap<>(); + Map> dailyDescriptions = new HashMap<>(); + Map> dailyIcons = new HashMap<>(); + + for (JsonNode forecast : forecastList) { + String date = forecast.get("dt_txt").asText().split(" ")[0]; //날짜 추출 + + JsonNode weather = forecast.get("weather").get(0); + String mainWeather = weather.get("main").asText(); + String description = weather.get("description").asText(); + String icon = weather.get("icon").asText(); + + if (!dailyWeathers.containsKey(date)) { + dailyWeathers.put(date, new ArrayList<>()); + dailyDescriptions.put(date, new ArrayList<>()); + dailyIcons.put(date, new ArrayList<>()); + } + + dailyWeathers.get(date).add(mainWeather); + dailyDescriptions.get(date).add(description); + dailyIcons.get(date).add(icon); + } + + // 각 날짜별 대표 날씨 결정 (가장 빈번한 날씨 상태) + List dailyWeatherList = new ArrayList<>(); + + for (String date : dailyWeathers.keySet()) { + List weathers = dailyWeathers.get(date); + List descriptions = dailyDescriptions.get(date); + List icons = dailyIcons.get(date); + + // 가장 빈번한 날씨 찾기(카운팅) + Map weatherCounts = new HashMap<>(); + for (String w : weathers) { + weatherCounts.put(w, weatherCounts.getOrDefault(w, 0) + 1); + } + + String mainWeather = ""; + int maxCount = 0; + + for (Map.Entry entry : weatherCounts.entrySet()) { + if (entry.getValue() > maxCount) { + maxCount = entry.getValue(); + mainWeather = entry.getKey(); + } + } + + // 평균값 계산 + int mainWeatherIndex = weathers.indexOf(mainWeather); + String description = descriptions.get(mainWeatherIndex); + String icon = icons.get(mainWeatherIndex); + + dailyWeatherList.add(new WeatherVo(date, mainWeather, description, icon)); + } + + return dailyWeatherList; } } diff --git a/src/main/java/io/company/localhost/mapper/NetmemberMapper.java b/src/main/java/io/company/localhost/mapper/NetmemberMapper.java index 0ac83dd..1d4f83a 100644 --- a/src/main/java/io/company/localhost/mapper/NetmemberMapper.java +++ b/src/main/java/io/company/localhost/mapper/NetmemberMapper.java @@ -51,4 +51,8 @@ public interface NetmemberMapper { List selectRegisterMemberList(); + int updateRegistMember(long memberSeq); + + int updateRejectMember(long memberSeq); + } diff --git a/src/main/java/io/company/localhost/service/MainService.java b/src/main/java/io/company/localhost/service/MainService.java index 08950e7..c562fc6 100644 --- a/src/main/java/io/company/localhost/service/MainService.java +++ b/src/main/java/io/company/localhost/service/MainService.java @@ -89,9 +89,39 @@ public class MainService { } } + /** + * 사원 등록 대상자 목록 조회 + * + * @return + */ public ApiResponse> registerMemberList() { return ApiResponse.ok(netmemberService.selectRegisterMemberList()); } + + + /** + * 사원 등록 승인 + * @param memberSeq + * + * @return + */ + public ApiResponse registerMember(long memberSeq) { + int result = netmemberService.registerMember(memberSeq); + + return result == 1 ? ApiResponse.ok("사원 등록 성공") : ApiResponse.ok("사원 등록 실패"); + } + + /** + * 사원 등록 거절 + * + * @param memberSeq + * @return + */ + public ApiResponse rejectMember(long memberSeq) { + int result = netmemberService.rejectMember(memberSeq); + + return result == 1 ? ApiResponse.ok("미승인 대상자 등록") : ApiResponse.ok("미승인 대상자 등록 실패"); + } diff --git a/src/main/java/io/company/localhost/service/NetmemberService.java b/src/main/java/io/company/localhost/service/NetmemberService.java index 9e689ea..bc12970 100644 --- a/src/main/java/io/company/localhost/service/NetmemberService.java +++ b/src/main/java/io/company/localhost/service/NetmemberService.java @@ -202,4 +202,12 @@ public class NetmemberService { return memberMapper.selectRegisterMemberList(); } + public int registerMember(long memberSeq) { + return memberMapper.updateRegistMember(memberSeq); + } + + public int rejectMember(long memberSeq) { + return memberMapper.updateRejectMember(memberSeq); + } + } diff --git a/src/main/java/io/company/localhost/vo/WeatherVo.java b/src/main/java/io/company/localhost/vo/WeatherVo.java new file mode 100644 index 0000000..483ca4a --- /dev/null +++ b/src/main/java/io/company/localhost/vo/WeatherVo.java @@ -0,0 +1,33 @@ +/************************************************************ + * + * @packageName : io.company.localhost.vo + * @fileName : MemberVo.java + * @author : 조인제 + * @date : 24.12.06 + * @description : + * + * =========================================================== + * DATE AUTHOR NOTE + * ----------------------------------------------------------- + * 24.12.06 조인제 최초 생성 + * + *************************************************************/ +package io.company.localhost.vo; + +import lombok.*; + +import java.util.Date; + +@Getter +@Setter +@Builder +@NoArgsConstructor +@AllArgsConstructor +@ToString +public class WeatherVo { + String date; + String mainWeather; + String description; + String icon; +} + diff --git a/src/main/resources/mapper/NetmemberMapper.xml b/src/main/resources/mapper/NetmemberMapper.xml index d2e3c7c..c95a89b 100644 --- a/src/main/resources/mapper/NetmemberMapper.xml +++ b/src/main/resources/mapper/NetmemberMapper.xml @@ -193,5 +193,26 @@ WHERE MEMBERPRM = 'N' + + + /* 멤버 승인 */ + UPDATE + NETMEMBER + SET + MEMBERPRM = 'Y' + WHERE + MEMBERSEQ = #{memberSeq} + + + + /* 멤버 등록 미승인 */ + UPDATE + NETMEMBER + SET + MEMBERPRM = 'R' + WHERE + MEMBERSEQ = #{memberSeq} + +