@@ -77,24 +77,86 @@ public List<HistoryDto> getAllHistory(int client_code) {
7777 list .sort ((a , b ) -> b .getAnalysisDate ().compareTo (a .getAnalysisDate ())); return list ;
7878 }
7979
80+ //타입별 조회
81+ private List <HistoryDto > getHistoryByType (int clientCode , String serviceType ) {
82+
83+ List <HistoryDto > list = new ArrayList <>();
84+ String t = serviceType .toUpperCase ();
85+
86+ switch (t ) {
87+ case "LAW" -> lawRepository .findHistory (clientCode ).forEach (l ->
88+ list .add (HistoryDto .builder ()
89+ .serviceType ("LAW" )
90+ .serviceCode ((long ) l .getLaw_code ())
91+ .analysisDate (java .sql .Timestamp .valueOf (l .getLaw_date ()))
92+ .input (l .getLaw_input ())
93+ .output (l .getLaw_output ())
94+ .mark (l .getLaw_mark ())
95+ .build ())
96+ );
97+
98+ case "YUSA" -> yusaRepository .findHistory (clientCode ).forEach (y ->
99+ list .add (HistoryDto .builder ()
100+ .serviceType ("YUSA" )
101+ .serviceCode ((long ) y .getYusa_code ())
102+ .analysisDate (java .sql .Timestamp .valueOf (y .getYusa_date ()))
103+ .input (y .getYusa_input ())
104+ .output (y .getYusa_output ())
105+ .mark (y .getYusa_mark ())
106+ .build ())
107+ );
108+
109+ case "JOGI" -> jogiRepository .findHistory (clientCode ).forEach (j ->
110+ list .add (HistoryDto .builder ()
111+ .serviceType ("JOGI" )
112+ .serviceCode ((long ) j .getJogi_code ())
113+ .analysisDate (java .sql .Timestamp .valueOf (j .getJogi_date ()))
114+ .input (j .getJogi_input ())
115+ .output (j .getJogi_output ())
116+ .mark (j .getJogi_mark ())
117+ .build ())
118+ );
119+
120+ case "BOONJANG" -> boonjangRepository .findHistory (clientCode ).forEach (b ->
121+ list .add (HistoryDto .builder ()
122+ .serviceType ("BOONJANG" )
123+ .serviceCode ((long ) b .getBoonjang_code ())
124+ .analysisDate (java .sql .Timestamp .valueOf (b .getBoonjang_date ()))
125+ .input (b .getBoonjang_input ())
126+ .output (b .getBoonjang_output ())
127+ .mark (b .getBoonjang_mark ())
128+ .build ())
129+ );
130+ }
131+
132+ list .sort ((a , b ) -> b .getAnalysisDate ().compareTo (a .getAnalysisDate ()));
133+ return list ;
134+ }
135+
136+
80137 //페이징
81- public HistoryPageDto getHistoryPage (int client_code , int page , int size ) {
82- // 1) 전체 목록 만들기(지금 작성하신 getAllHistory 재사용)
83- List <HistoryDto > all = getAllHistory (client_code );
138+ public HistoryPageDto getHistoryPage (int clientCode , int page , int size , String serviceType ) {
139+ List <HistoryDto > source ;
140+
141+ if (serviceType == null || serviceType .isBlank ()) {
142+ source = getAllHistory (clientCode );
143+ } else {
144+ source = getHistoryByType (clientCode , serviceType );
145+ }
84146
85- int totalCount = all .size ();
147+ int totalCount = source .size ();
86148 int totalPages = (int ) Math .ceil ((double ) totalCount / size );
87149
88- // page 보정(1~totalPages)
89150 if (page < 1 ) page = 1 ;
90151 if (totalPages > 0 && page > totalPages ) page = totalPages ;
91152
92153 int fromIndex = (page - 1 ) * size ;
93154 int toIndex = Math .min (fromIndex + size , totalCount );
94155
95156 List <HistoryDto > content =
96- (totalCount == 0 ) ? java .util .Collections .emptyList ()
97- : all .subList (fromIndex , toIndex );
157+ totalCount == 0
158+ ? Collections .emptyList ()
159+ : source .subList (fromIndex , toIndex );
98160
99161 return new HistoryPageDto (content , totalCount , page , size , totalPages );
100162 }
0 commit comments