사원등록프로세스 추가, 주간 날씨 데이터 전화 프로세스 추가
This commit is contained in:
parent
e4956f12b0
commit
b55d150bc0
@ -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<List<MapDto>> registerMemberList() {
|
||||
return mainService.registerMemberList();
|
||||
}
|
||||
|
||||
@Admin
|
||||
@ParameterCheck
|
||||
@PostMapping("/registerMember")
|
||||
public ApiResponse<String> registerMember(@ReqMap MapDto map) {
|
||||
long memberSeq = map.getInt("memberSeq");
|
||||
return mainService.registerMember(memberSeq);
|
||||
}
|
||||
|
||||
@Admin
|
||||
@ParameterCheck
|
||||
@PostMapping("/rejectMember")
|
||||
public ApiResponse<String> rejectMember(@ReqMap MapDto map) {
|
||||
long memberSeq = map.getInt("memberSeq");
|
||||
return mainService.rejectMember(memberSeq);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<String> getWeather(@RequestParam("lat") double lat,@RequestParam("lon") double lon) {
|
||||
public ApiResponse<MapDto> 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<WeatherVo> 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<WeatherVo> convertDailyForecast(String jsonData) throws Exception {
|
||||
JsonNode nodeData = objectMapper.readTree(jsonData);
|
||||
JsonNode forecastList = nodeData.get("list");
|
||||
|
||||
// 날짜별로 데이터 그룹화
|
||||
Map<String, List<String>> dailyWeathers = new HashMap<>();
|
||||
Map<String, List<String>> dailyDescriptions = new HashMap<>();
|
||||
Map<String, List<String>> 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<WeatherVo> dailyWeatherList = new ArrayList<>();
|
||||
|
||||
for (String date : dailyWeathers.keySet()) {
|
||||
List<String> weathers = dailyWeathers.get(date);
|
||||
List<String> descriptions = dailyDescriptions.get(date);
|
||||
List<String> icons = dailyIcons.get(date);
|
||||
|
||||
// 가장 빈번한 날씨 찾기(카운팅)
|
||||
Map<String, Integer> weatherCounts = new HashMap<>();
|
||||
for (String w : weathers) {
|
||||
weatherCounts.put(w, weatherCounts.getOrDefault(w, 0) + 1);
|
||||
}
|
||||
|
||||
String mainWeather = "";
|
||||
int maxCount = 0;
|
||||
|
||||
for (Map.Entry<String, Integer> 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -51,4 +51,8 @@ public interface NetmemberMapper {
|
||||
|
||||
List<MapDto> selectRegisterMemberList();
|
||||
|
||||
int updateRegistMember(long memberSeq);
|
||||
|
||||
int updateRejectMember(long memberSeq);
|
||||
|
||||
}
|
||||
|
||||
@ -89,9 +89,39 @@ public class MainService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 사원 등록 대상자 목록 조회
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public ApiResponse<List<MapDto>> registerMemberList() {
|
||||
return ApiResponse.ok(netmemberService.selectRegisterMemberList());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 사원 등록 승인
|
||||
* @param memberSeq
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public ApiResponse<String> registerMember(long memberSeq) {
|
||||
int result = netmemberService.registerMember(memberSeq);
|
||||
|
||||
return result == 1 ? ApiResponse.ok("사원 등록 성공") : ApiResponse.ok("사원 등록 실패");
|
||||
}
|
||||
|
||||
/**
|
||||
* 사원 등록 거절
|
||||
*
|
||||
* @param memberSeq
|
||||
* @return
|
||||
*/
|
||||
public ApiResponse<String> rejectMember(long memberSeq) {
|
||||
int result = netmemberService.rejectMember(memberSeq);
|
||||
|
||||
return result == 1 ? ApiResponse.ok("미승인 대상자 등록") : ApiResponse.ok("미승인 대상자 등록 실패");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
33
src/main/java/io/company/localhost/vo/WeatherVo.java
Normal file
33
src/main/java/io/company/localhost/vo/WeatherVo.java
Normal file
@ -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;
|
||||
}
|
||||
|
||||
@ -193,5 +193,26 @@
|
||||
WHERE
|
||||
MEMBERPRM = 'N'
|
||||
</select>
|
||||
|
||||
<update id="updateRegistMember">
|
||||
/* 멤버 승인 */
|
||||
UPDATE
|
||||
NETMEMBER
|
||||
SET
|
||||
MEMBERPRM = 'Y'
|
||||
WHERE
|
||||
MEMBERSEQ = #{memberSeq}
|
||||
</update>
|
||||
|
||||
<update id="updateRejectMember">
|
||||
/* 멤버 등록 미승인 */
|
||||
UPDATE
|
||||
NETMEMBER
|
||||
SET
|
||||
MEMBERPRM = 'R'
|
||||
WHERE
|
||||
MEMBERSEQ = #{memberSeq}
|
||||
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user