동적으로 table 명 수정

This commit is contained in:
hylee 2024-02-16 11:17:47 +09:00
parent 4afe85bd87
commit fbcec14177
3 changed files with 14 additions and 6 deletions

View File

@ -60,5 +60,5 @@ public class CommuteVO implements Serializable {
private String searchMonth;
private String searchDay;
private String tableNm;
}

View File

@ -13,9 +13,7 @@ import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
@Slf4j
@ -61,8 +59,18 @@ public class CommuteServiceImpl implements CommuteService {
commuteVO.setStartDate(commuteVO.getSearchYear()+"-"+commuteVO.getSearchMonth()+"-"+commuteVO.getSearchDay()+" 06:00:00");
commuteVO.setEndDate(commuteVO.getSearchYear()+"-"+commuteVO.getSearchMonth()+"-"+commuteVO.getSearchDay()+" 23:59:59");
// 테이블명 생성
String tableNmM = commuteVO.getSearchMonth().length() <2 ? "0"+commuteVO.getSearchMonth() : commuteVO.getSearchMonth();
commuteVO.setTableNm("t_lg"+commuteVO.getSearchYear()+tableNmM);
List<CommuteVO> commuteList = commuteMapper.findAll(commuteVO);
List<CommuteVO> commuteList = new ArrayList<>();
try {
commuteList = commuteMapper.findAll(commuteVO);
}catch (Exception e){
// 월별로 테이블이 생성되는데
// 없는 테이블을 select하면 Exception이 발생함
// 해당 exception 방지용 try-catch
}
commuteList.stream().forEach(t->{
if(StringUtils.isNotEmpty(t.getUsrid())){

View File

@ -11,7 +11,7 @@
MIN(SRVDT) AS firstActivityTime,
MAX(SRVDT) AS lastActivityTime
FROM
t_lg202402
${tableNm}
WHERE SRVDT BETWEEN #{startDate} AND #{endDate}
-- AND usrid IS NOT NULL
AND LENGTH(USRID)>0