Compare commits

..

No commits in common. "main" and "khj" have entirely different histories.
main ... khj

7 changed files with 83 additions and 154 deletions

View File

@ -180,11 +180,4 @@ public class ProjectController {
return ApiResponse.ok(netprojctService.selectUserProjectPeriod(projctSeq)); return ApiResponse.ok(netprojctService.selectUserProjectPeriod(projctSeq));
} }
@ParameterCheck
@GetMapping("/people/{memberSeq}")
public ApiResponse<List<MapDto>> selectUserProjectPeriod2(@PathVariable int memberSeq) {
return ApiResponse.ok(netprojctService.selectUserProjectPeriod2(memberSeq));
}
} }

View File

@ -1,9 +1,5 @@
package io.company.localhost.controller.common; package io.company.localhost.controller.common;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -69,86 +65,62 @@ public class WeatherController {
JsonNode nodeData = objectMapper.readTree(jsonData); JsonNode nodeData = objectMapper.readTree(jsonData);
JsonNode forecastList = nodeData.get("list"); JsonNode forecastList = nodeData.get("list");
// 현재 날짜 시간 계산 // 날짜별로 데이터 그룹화
LocalDate today = LocalDate.now();
LocalDateTime nowTime = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
// 날짜별 데이터를 그룹화
Map<String, List<String>> dailyWeathers = new HashMap<>(); Map<String, List<String>> dailyWeathers = new HashMap<>();
Map<String, List<String>> dailyDescriptions = new HashMap<>(); Map<String, List<String>> dailyDescriptions = new HashMap<>();
Map<String, List<String>> dailyIcons = new HashMap<>(); Map<String, List<String>> dailyIcons = new HashMap<>();
// 오늘 예보 가장 가까운 예보 저장 변수
JsonNode closestForecastToday = null;
long minDiff = Long.MAX_VALUE;
// forecastList를 순회하며 데이터를 그룹화하고, 오늘의 경우 가장 가까운 forecast 선택
for (JsonNode forecast : forecastList) { for (JsonNode forecast : forecastList) {
String dtTxt = forecast.get("dt_txt").asText(); String date = forecast.get("dt_txt").asText().split(" ")[0]; //날짜 추출
String date = dtTxt.split(" ")[0]; // 날짜 추출 (: "2025-04-04")
JsonNode weather = forecast.get("weather").get(0); JsonNode weather = forecast.get("weather").get(0);
String mainWeather = weather.get("main").asText(); String mainWeather = weather.get("main").asText();
String description = weather.get("description").asText(); String description = weather.get("description").asText();
String icon = weather.get("icon").asText(); String icon = weather.get("icon").asText();
// 해당 날짜의 리스트에 추가 (map이 없으면 생성) if (!dailyWeathers.containsKey(date)) {
dailyWeathers.computeIfAbsent(date, k -> new ArrayList<>()).add(mainWeather); dailyWeathers.put(date, new ArrayList<>());
dailyDescriptions.computeIfAbsent(date, k -> new ArrayList<>()).add(description); dailyDescriptions.put(date, new ArrayList<>());
dailyIcons.computeIfAbsent(date, k -> new ArrayList<>()).add(icon); dailyIcons.put(date, new ArrayList<>());
// 오늘 날짜의 forecast라면 현재 시간과의 차이 계산
if (date.equals(today.toString())) {
LocalDateTime forecastTime = LocalDateTime.parse(dtTxt, formatter);
long diff = Math.abs(Duration.between(forecastTime, nowTime).toMillis());
if (diff < minDiff) {
minDiff = diff;
closestForecastToday = forecast;
}
} }
dailyWeathers.get(date).add(mainWeather);
dailyDescriptions.get(date).add(description);
dailyIcons.get(date).add(icon);
} }
// 최종적으로 날짜의 대표 날씨 결정 // 날짜별 대표 날씨 결정 (가장 빈번한 날씨 상태)
List<WeatherVo> dailyWeatherList = new ArrayList<>(); List<WeatherVo> dailyWeatherList = new ArrayList<>();
for (String date : dailyWeathers.keySet()) { for (String date : dailyWeathers.keySet()) {
String repMainWeather; List<String> weathers = dailyWeathers.get(date);
String repDescription; List<String> descriptions = dailyDescriptions.get(date);
String repIcon; List<String> icons = dailyIcons.get(date);
// 오늘인 경우, 가장 가까운 forecast의 아이콘과 설명 사용 // 가장 빈번한 날씨 찾기(카운팅)
if (date.equals(today.toString()) && closestForecastToday != null) { Map<String, Integer> weatherCounts = new HashMap<>();
JsonNode weather = closestForecastToday.get("weather").get(0); for (String w : weathers) {
repMainWeather = weather.get("main").asText(); weatherCounts.put(w, weatherCounts.getOrDefault(w, 0) + 1);
repDescription = weather.get("description").asText();
repIcon = weather.get("icon").asText();
} else {
// 기타 날짜는 기존 방식대로 가장 빈번한 날씨 상태 선택
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);
}
repMainWeather = "";
int maxCount = 0;
for (Map.Entry<String, Integer> entry : weatherCounts.entrySet()) {
if (entry.getValue() > maxCount) {
maxCount = entry.getValue();
repMainWeather = entry.getKey();
}
}
int repIndex = weathers.indexOf(repMainWeather);
repDescription = descriptions.get(repIndex);
repIcon = icons.get(repIndex);
} }
dailyWeatherList.add(new WeatherVo(date, repMainWeather, repDescription, repIcon)); 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; return dailyWeatherList;
} }

View File

@ -34,7 +34,4 @@ public interface NetprojctMapper {
int deleteProject(MapDto map); int deleteProject(MapDto map);
List<MapDto> selectUserProjectPeriod(int projectSeq); List<MapDto> selectUserProjectPeriod(int projectSeq);
List<MapDto> selectUserProjectPeriod2(int memberSeq);
} }

View File

@ -175,8 +175,4 @@ public class NetprojctService {
return netprojctMapper.selectUserProjectPeriod(projctSeq); return netprojctMapper.selectUserProjectPeriod(projctSeq);
} }
public List<MapDto> selectUserProjectPeriod2(int memberSeq) {
return netprojctMapper.selectUserProjectPeriod2(memberSeq);
}
} }

View File

@ -288,29 +288,32 @@ public class localvacaService {
return emp; return emp;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
} }
/**
/** * 연차 계산 로직
* 연차 계산 로직 */
*/
public int procCalculateTotalVacation(LocalDate hireDate) { public int procCalculateTotalVacation(LocalDate hireDate) {
LocalDate today = LocalDate.now(); LocalDate today = LocalDate.now();
int hireYear = hireDate.getYear();
int currentYear = today.getYear(); int currentYear = today.getYear();
int hireYear = hireDate.getYear();
int hireMonth = hireDate.getMonthValue();
// 입사년도와 현재년도가 같으면 : (12 - 입사월) // 올해 입사자 1년 미만: 입사월 이후로 계산
if (hireYear == currentYear) { if (hireYear == currentYear) {
return 12 - hireDate.getMonthValue(); return 12 - hireMonth;
} }
// 기본 연차 15
int totalVacation = 15; int totalVacation = 15;
// 입사년도 기준 3년차 1월부터, 2년마다 1개씩 // 2년 경과 이후부터, 입사월이 도래했을 1개씩
LocalDate accrualDate = LocalDate.of(hireYear + 3, 1, 1); LocalDate baseDate = hireDate.plusYears(2).withDayOfMonth(1);
while (!accrualDate.isAfter(today)) { while (!baseDate.isAfter(today)) {
totalVacation++; // 입사월이 현재 달과 같거나 지났을 때만 연차 추가
accrualDate = accrualDate.plusYears(2); if (baseDate.getYear() == today.getYear() && baseDate.getMonthValue() > today.getMonthValue()) {
break; // 아직 입사월이 도달하지 않았으면 종료
}
totalVacation += 1;
baseDate = baseDate.plusYears(2);
} }
return totalVacation; return totalVacation;

View File

@ -95,8 +95,6 @@ logging:
connection: off connection: off
io.company: DEBUG io.company: DEBUG
io.company.localhost.mapper: off io.company.localhost.mapper: off
file:
path: logs
filePath: filePath:

View File

@ -116,65 +116,35 @@
<!-- 프로젝트 모든 사용자 참여기간 조회 --> <!-- 프로젝트 모든 사용자 참여기간 조회 -->
<select id="selectUserProjectPeriod" resultType="io.company.localhost.common.dto.MapDto"> <select id="selectUserProjectPeriod" resultType="io.company.localhost.common.dto.MapDto">
SELECT SELECT
m.MEMBERSEQ, m.MEMBERSEQ,
m.MEMBERNAM, m.MEMBERNAM,
p.PROJCTSEQ, p.PROJCTSEQ,
p.PROJCTNAM, p.PROJCTNAM,
p.PROJCTSTR AS projectStartDate, p.PROJCTSTR as projectStartDate,
p.PROJCTEND AS projectEndDate, p.PROJCTEND as projectEndDate,
COALESCE(( (
SELECT MIN(c2.COMMUTDAY) SELECT MIN(c2.COMMUTDAY)
FROM commuters c2 FROM commuters c2
WHERE c2.PROJCTSEQ = p.PROJCTSEQ WHERE c2.PROJCTSEQ = p.PROJCTSEQ
AND c2.MEMBERSEQ = m.MEMBERSEQ AND c2.MEMBERSEQ = m.MEMBERSEQ
), p.PROJCTSTR) AS userStartDate, ) as userStartDate,
COALESCE(( (
SELECT MAX(c2.COMMUTDAY) SELECT MAX(c2.COMMUTDAY)
FROM commuters c2 FROM commuters c2
WHERE c2.PROJCTSEQ = p.PROJCTSEQ WHERE c2.PROJCTSEQ = p.PROJCTSEQ
AND c2.MEMBERSEQ = m.MEMBERSEQ AND c2.MEMBERSEQ = m.MEMBERSEQ
), p.PROJCTEND) AS userEndDate ) as userEndDate
FROM FROM
netprojct p netprojct p
LEFT JOIN INNER JOIN
commuters c ON p.PROJCTSEQ = c.PROJCTSEQ commuters c ON p.PROJCTSEQ = c.PROJCTSEQ
LEFT JOIN INNER JOIN
netmember m ON c.MEMBERSEQ = m.MEMBERSEQ netmember m ON c.MEMBERSEQ = m.MEMBERSEQ
WHERE WHERE
p.PROJCTSEQ = #{projectSeq} p.PROJCTSEQ = #{projectSeq}
GROUP BY GROUP BY
m.MEMBERSEQ, m.MEMBERNAM, p.PROJCTSEQ, p.PROJCTNAM, p.PROJCTSTR, p.PROJCTEND m.MEMBERSEQ, p.PROJCTSEQ
</select> </select>
<select id="selectUserProjectPeriod2" resultType="io.company.localhost.common.dto.MapDto">
SELECT
pm.MEMBERSEQ,
p.PROJCTSEQ,
p.PROJCTNAM,
p.PROJCTSTR AS projectStartDate,
p.PROJCTEND AS projectEndDate,
(
SELECT MIN(c2.COMMUTDAY)
FROM commuters c2
WHERE c2.PROJCTSEQ = p.PROJCTSEQ
AND c2.MEMBERSEQ = pm.MEMBERSEQ
) AS userStartDate,
CASE
WHEN p.PROJCTEND IS NOT NULL THEN (
SELECT MAX(c2.COMMUTDAY)
FROM commuters c2
WHERE c2.PROJCTSEQ = p.PROJCTSEQ
AND c2.MEMBERSEQ = pm.MEMBERSEQ
)
ELSE NULL
END AS userEndDate
FROM promember pm
INNER JOIN netprojct p ON pm.PROJCTSEQ = p.PROJCTSEQ
WHERE pm.MEMBERSEQ = #{memberSeq}
AND pm.PROJCTYON = 1
</select>
</mapper> </mapper>