2025-03-07 16:50 결제관리 excel download 수정
@4fe717d4ef4ff181a05f7f24200f5f3910445b4e
--- src/main/java/itn/let/mjo/pay/web/MjonPayController.java
+++ src/main/java/itn/let/mjo/pay/web/MjonPayController.java
... | ... | @@ -13,11 +13,9 @@ |
| 13 | 13 |
import java.text.NumberFormat; |
| 14 | 14 |
import java.text.SimpleDateFormat; |
| 15 | 15 |
import java.time.LocalDate; |
| 16 |
-import java.time.LocalDateTime; |
|
| 17 | 16 |
import java.util.ArrayList; |
| 18 | 17 |
import java.util.Calendar; |
| 19 | 18 |
import java.util.Date; |
| 20 |
-import java.util.HashMap; |
|
| 21 | 19 |
import java.util.List; |
| 22 | 20 |
import java.util.Locale; |
| 23 | 21 |
import java.util.Map; |
... | ... | @@ -41,18 +39,12 @@ |
| 41 | 39 |
import org.json.simple.parser.JSONParser; |
| 42 | 40 |
import org.slf4j.Logger; |
| 43 | 41 |
import org.slf4j.LoggerFactory; |
| 44 |
-import org.springframework.http.HttpStatus; |
|
| 45 |
-import org.springframework.http.MediaType; |
|
| 46 |
-import org.springframework.http.ResponseEntity; |
|
| 47 | 42 |
import org.springframework.stereotype.Controller; |
| 48 | 43 |
import org.springframework.ui.Model; |
| 49 | 44 |
import org.springframework.ui.ModelMap; |
| 50 | 45 |
import org.springframework.web.bind.annotation.ModelAttribute; |
| 51 |
-import org.springframework.web.bind.annotation.RequestBody; |
|
| 52 | 46 |
import org.springframework.web.bind.annotation.RequestMapping; |
| 53 |
-import org.springframework.web.bind.annotation.RequestMethod; |
|
| 54 | 47 |
import org.springframework.web.bind.annotation.RequestParam; |
| 55 |
-import org.springframework.web.bind.annotation.ResponseBody; |
|
| 56 | 48 |
import org.springframework.web.multipart.MultipartFile; |
| 57 | 49 |
import org.springframework.web.multipart.MultipartHttpServletRequest; |
| 58 | 50 |
import org.springframework.web.servlet.HandlerMapping; |
... | ... | @@ -67,7 +59,6 @@ |
| 67 | 59 |
import itn.com.cmm.ComDefaultCodeVO; |
| 68 | 60 |
import itn.com.cmm.EgovMessageSource; |
| 69 | 61 |
import itn.com.cmm.LoginVO; |
| 70 |
-import itn.com.cmm.RestResponse; |
|
| 71 | 62 |
import itn.com.cmm.service.EgovCmmUseService; |
| 72 | 63 |
import itn.com.cmm.service.FileVO; |
| 73 | 64 |
import itn.com.cmm.util.DateUtils; |
... | ... | @@ -76,8 +67,6 @@ |
| 76 | 67 |
import itn.com.cmm.util.RedirectUrlMaker; |
| 77 | 68 |
import itn.com.cmm.util.StringUtil; |
| 78 | 69 |
import itn.com.utl.fcc.service.EgovStringUtil; |
| 79 |
-import itn.let.fax.admin.service.FaxStatVO; |
|
| 80 |
-import itn.let.mail.service.StatusResponse; |
|
| 81 | 70 |
import itn.let.mjo.mjocommon.MjonCommon; |
| 82 | 71 |
import itn.let.mjo.msg.service.MjonMsgService; |
| 83 | 72 |
import itn.let.mjo.msg.service.MjonMsgVO; |
... | ... | @@ -107,6 +96,7 @@ |
| 107 | 96 |
import itn.let.uss.umt.service.MberManageVO; |
| 108 | 97 |
import itn.let.uss.umt.service.UserManageVO; |
| 109 | 98 |
import itn.let.utl.fcc.service.EgovCryptoUtil; |
| 99 |
+import itn.let.utl.user.service.ExcelUtil; |
|
| 110 | 100 |
import itn.let.utl.user.service.MjonNoticeSendUtil; |
| 111 | 101 |
|
| 112 | 102 |
@Controller |
... | ... | @@ -1952,7 +1942,6 @@ |
| 1952 | 1942 |
|
| 1953 | 1943 |
model.addAttribute("prePaymentYn", userManageVO.getPrePaymentYn());
|
| 1954 | 1944 |
|
| 1955 |
- |
|
| 1956 | 1945 |
System.out.println("pattern :: "+ pattern);
|
| 1957 | 1946 |
if(pattern.equals("/web/member/pay/PayListAllAjax.do")
|
| 1958 | 1947 |
|| pattern.equals("/web/member/pay/PayListMobileAjax.do")
|
... | ... | @@ -2051,7 +2040,7 @@ |
| 2051 | 2040 |
|
| 2052 | 2041 |
return "/web/pay/PayListRefundAjax"; |
| 2053 | 2042 |
} |
| 2054 |
- |
|
| 2043 |
+ |
|
| 2055 | 2044 |
//일반 결제 페이지 처리 |
| 2056 | 2045 |
if("".equals(mjonPayVO.getSearchSortCnd())){ //최초조회시 최신것 조회List
|
| 2057 | 2046 |
mjonPayVO.setSearchSortCnd("moid");
|
... | ... | @@ -2073,7 +2062,7 @@ |
| 2073 | 2062 |
} |
| 2074 | 2063 |
|
| 2075 | 2064 |
} |
| 2076 |
- |
|
| 2065 |
+ |
|
| 2077 | 2066 |
if(pattern.equals("/web/member/pay/PayListAllAjax.do")) { //전체
|
| 2078 | 2067 |
mjonPayVO.setPageType("all");
|
| 2079 | 2068 |
} |
... | ... | @@ -2121,7 +2110,7 @@ |
| 2121 | 2110 |
|
| 2122 | 2111 |
// mjonPayVO.setStartDate(mjonPayVO.getStartDate() == null ? DateUtil.getDateDaysAgo(365) : mjonPayVO.getStartDate()); |
| 2123 | 2112 |
// mjonPayVO.setEndDate(mjonPayVO.getEndDate() == null ? DateUtil.getCurrentDate() : mjonPayVO.getEndDate()); |
| 2124 |
- |
|
| 2113 |
+ |
|
| 2125 | 2114 |
if(!DateUtils.dateChkAndValueChk(mjonPayVO.getStartDate(),mjonPayVO.getEndDate(), 12 )) {
|
| 2126 | 2115 |
mjonPayVO.setStartDate(DateUtils.getDateMonthsAgo(12)); |
| 2127 | 2116 |
mjonPayVO.setEndDate(DateUtils.getCurrentDate()); |
... | ... | @@ -4085,7 +4074,7 @@ |
| 4085 | 4074 |
} |
| 4086 | 4075 |
|
| 4087 | 4076 |
//결제 엑셀 다운로드 |
| 4088 |
- @RequestMapping(value= {"/web/member/pay/PayExcelDownload.do"})
|
|
| 4077 |
+ @RequestMapping(value= {"/web/member/pay/PayExcelDownload_OLD.do"})
|
|
| 4089 | 4078 |
public void PayExcelDownload( MjonPayVO mjonPayVO, |
| 4090 | 4079 |
HttpServletRequest request, |
| 4091 | 4080 |
HttpServletResponse response , |
... | ... | @@ -4180,6 +4169,118 @@ |
| 4180 | 4169 |
} |
| 4181 | 4170 |
} |
| 4182 | 4171 |
|
| 4172 |
+ //결제 엑셀 다운로드 |
|
| 4173 |
+ @RequestMapping(value= {"/web/member/pay/PayExcelDownload.do"})
|
|
| 4174 |
+ public void PayNewExcelDownload( MjonPayVO mjonPayVO, |
|
| 4175 |
+ HttpServletRequest request, |
|
| 4176 |
+ HttpServletResponse response , |
|
| 4177 |
+ ModelMap model) throws Exception {
|
|
| 4178 |
+ |
|
| 4179 |
+ //로그인 여부 체크 및 ID 획득 |
|
| 4180 |
+ LoginVO loginVO = EgovUserDetailsHelper.isAuthenticated()? (LoginVO)EgovUserDetailsHelper.getAuthenticatedUser():null; |
|
| 4181 |
+ String userId = loginVO == null ? "" : EgovStringUtil.isNullToString(loginVO.getId()); |
|
| 4182 |
+ if(loginVO != null) {
|
|
| 4183 |
+ |
|
| 4184 |
+ String fileName ="결제내역 엑셀 리스트"; //file name |
|
| 4185 |
+ |
|
| 4186 |
+ try{
|
|
| 4187 |
+ /** pageing */ |
|
| 4188 |
+ PaginationInfo paginationInfo = new PaginationInfo(); |
|
| 4189 |
+ paginationInfo.setCurrentPageNo(1); |
|
| 4190 |
+ paginationInfo.setRecordCountPerPage(10000); |
|
| 4191 |
+ paginationInfo.setPageSize(10); |
|
| 4192 |
+ |
|
| 4193 |
+ mjonPayVO.setFirstIndex(paginationInfo.getFirstRecordIndex()); |
|
| 4194 |
+ mjonPayVO.setLastIndex(paginationInfo.getLastRecordIndex()); |
|
| 4195 |
+ mjonPayVO.setRecordCountPerPage(paginationInfo.getRecordCountPerPage()); |
|
| 4196 |
+ |
|
| 4197 |
+ mjonPayVO.setUserId(userId); |
|
| 4198 |
+ |
|
| 4199 |
+ |
|
| 4200 |
+ //url에 따른 타입 처리 |
|
| 4201 |
+ String pattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE); |
|
| 4202 |
+ System.out.println("pattern========");
|
|
| 4203 |
+ System.out.println(pattern); |
|
| 4204 |
+ |
|
| 4205 |
+ //url에 따른 검색 조건 처리 |
|
| 4206 |
+ mjonPayVO = this.p_checkSearchCnd(pattern, mjonPayVO); |
|
| 4207 |
+ |
|
| 4208 |
+ |
|
| 4209 |
+ //검색 기간 처리 |
|
| 4210 |
+ mjonPayVO = this.p_checkSearchDate(mjonPayVO); |
|
| 4211 |
+ |
|
| 4212 |
+ |
|
| 4213 |
+ //정렬 처리 |
|
| 4214 |
+ mjonPayVO = this.p_checkSortCnd(mjonPayVO); |
|
| 4215 |
+ |
|
| 4216 |
+ |
|
| 4217 |
+ //결과 리스트 정보 불러오기 |
|
| 4218 |
+ List<MjonPayVO> resultList = mjonPayService.selectPayList(mjonPayVO); |
|
| 4219 |
+ |
|
| 4220 |
+ //필요 컬럼 추가 |
|
| 4221 |
+ for (int i=0;i<resultList.size();i++) {
|
|
| 4222 |
+ MjonPayVO tMjonPayVO = resultList.get(i); |
|
| 4223 |
+ tMjonPayVO.setSeqNo(resultList.size()-i); |
|
| 4224 |
+ } |
|
| 4225 |
+ |
|
| 4226 |
+ //excel 만들기 |
|
| 4227 |
+ List<Object> excelData = new ArrayList<>(); |
|
| 4228 |
+ excelData.addAll(resultList); |
|
| 4229 |
+ // 세팅값 |
|
| 4230 |
+ String title = "요금결제내역"; //sheet name & title |
|
| 4231 |
+ |
|
| 4232 |
+ // 너비 |
|
| 4233 |
+ int[] width = {
|
|
| 4234 |
+ 4000 |
|
| 4235 |
+ , 4000 |
|
| 4236 |
+ , 4000 |
|
| 4237 |
+ , 4000 |
|
| 4238 |
+ , 4000 |
|
| 4239 |
+ |
|
| 4240 |
+ , 4000 |
|
| 4241 |
+ //, 4000 |
|
| 4242 |
+ , 4000 |
|
| 4243 |
+ }; |
|
| 4244 |
+ |
|
| 4245 |
+ // 헤더 |
|
| 4246 |
+ String[] header = {
|
|
| 4247 |
+ "번호" |
|
| 4248 |
+ , "결제일시" |
|
| 4249 |
+ , "결제방식" |
|
| 4250 |
+ , "결제금액" |
|
| 4251 |
+ , "충전금액" |
|
| 4252 |
+ |
|
| 4253 |
+ , "결제상태" |
|
| 4254 |
+ //, "증빙서류 발행 요청" |
|
| 4255 |
+ , "비고1" |
|
| 4256 |
+ }; |
|
| 4257 |
+ |
|
| 4258 |
+ // 컬럼명 |
|
| 4259 |
+ String[] order = {
|
|
| 4260 |
+ "SeqNo" |
|
| 4261 |
+ , "RegDate" |
|
| 4262 |
+ , "PayMethodTxt" |
|
| 4263 |
+ , "Amt" |
|
| 4264 |
+ , "Cash" |
|
| 4265 |
+ |
|
| 4266 |
+ , "PgStatusTxt" |
|
| 4267 |
+ //, "RcptTypeTxt" |
|
| 4268 |
+ , "VbankNum" |
|
| 4269 |
+ |
|
| 4270 |
+ }; |
|
| 4271 |
+ |
|
| 4272 |
+ // 호출 - download file 처리 |
|
| 4273 |
+ SXSSFWorkbook workbook = ExcelUtil.makeSimpleFruitExcelWorkbook(excelData , header, order, width, title); |
|
| 4274 |
+ response = this.p_makeResponse(response, fileName); |
|
| 4275 |
+ workbook.write(response.getOutputStream()); |
|
| 4276 |
+ |
|
| 4277 |
+ }catch(Exception e) {
|
|
| 4278 |
+ e.printStackTrace(); |
|
| 4279 |
+ } |
|
| 4280 |
+ |
|
| 4281 |
+ } |
|
| 4282 |
+ |
|
| 4283 |
+ } |
|
| 4183 | 4284 |
|
| 4184 | 4285 |
//포인트 교환내역 엑셀 다운로드 |
| 4185 | 4286 |
@RequestMapping(value= {"/web/member/pay/PointExcelDownload.do"})
|
... | ... | @@ -6088,6 +6189,119 @@ |
| 6088 | 6189 |
model.addAttribute("paginationInfo", paginationInfo);
|
| 6089 | 6190 |
|
| 6090 | 6191 |
return "/uss/ion/pay/cashPointSendList"; |
| 6091 |
- } |
|
| 6192 |
+ } |
|
| 6193 |
+ |
|
| 6194 |
+ /** |
|
| 6195 |
+ * @param p_pattern |
|
| 6196 |
+ * @param p_mjonPayVO |
|
| 6197 |
+ * @return |
|
| 6198 |
+ * @throws Exception |
|
| 6199 |
+ */ |
|
| 6200 |
+ private MjonPayVO p_checkSearchCnd( |
|
| 6201 |
+ String p_pattern |
|
| 6202 |
+ , MjonPayVO p_mjonPayVO |
|
| 6203 |
+ ) throws Exception{
|
|
| 6204 |
+ if(p_pattern.equals("/web/member/pay/PayListAllAjax.do")) { //전체
|
|
| 6205 |
+ p_mjonPayVO.setPageType("all");
|
|
| 6206 |
+ } |
|
| 6207 |
+ if(p_pattern.equals("/web/member/pay/PayListMobileAjax.do")) { //모바일일때
|
|
| 6208 |
+ p_mjonPayVO.setSearchCondition2("CELLPHONE");
|
|
| 6209 |
+ p_mjonPayVO.setPayMethod("CELLPHONE");
|
|
| 6210 |
+ p_mjonPayVO.setPageType("cellphone");
|
|
| 6211 |
+ } |
|
| 6212 |
+ if(p_pattern.equals("/web/member/pay/PayListCardAjax.do")) { //신용카드
|
|
| 6213 |
+ p_mjonPayVO.setSearchCondition2("CARD");
|
|
| 6214 |
+ p_mjonPayVO.setPayMethod("CARD");
|
|
| 6215 |
+ p_mjonPayVO.setPageType("card");
|
|
| 6216 |
+ } |
|
| 6217 |
+ if(p_pattern.equals("/web/member/pay/PayListVBankAjax.do")) { //전용계좌
|
|
| 6218 |
+ p_mjonPayVO.setSearchCondition2("VBANK");
|
|
| 6219 |
+ p_mjonPayVO.setPayMethod("VBANK");
|
|
| 6220 |
+ p_mjonPayVO.setPageType("vbank");
|
|
| 6221 |
+ } |
|
| 6222 |
+ if(p_pattern.equals("/web/member/pay/PayListBankAjax.do")) { //즉시이체
|
|
| 6223 |
+ p_mjonPayVO.setSearchCondition2("BANK");
|
|
| 6224 |
+ p_mjonPayVO.setPayMethod("BANK");
|
|
| 6225 |
+ p_mjonPayVO.setPageType("bank");
|
|
| 6226 |
+ } |
|
| 6227 |
+ if(p_pattern.equals("/web/member/pay/PayListSPayAjax.do")) { //즉시이체
|
|
| 6228 |
+ p_mjonPayVO.setSearchCondition2("SPAY");
|
|
| 6229 |
+ p_mjonPayVO.setPayMethod("SPAY");
|
|
| 6230 |
+ p_mjonPayVO.setPageType("SPAY");
|
|
| 6231 |
+ } |
|
| 6232 |
+ if(p_pattern.equals("/web/member/pay/PayListOfflineAjax.do")) { //무통장
|
|
| 6233 |
+ p_mjonPayVO.setSearchCondition2("OFFLINE");
|
|
| 6234 |
+ p_mjonPayVO.setPayMethod("OFFLINE");
|
|
| 6235 |
+ p_mjonPayVO.setPageType("offline");
|
|
| 6236 |
+ } |
|
| 6237 |
+ |
|
| 6238 |
+ return p_mjonPayVO; |
|
| 6239 |
+ } |
|
| 6240 |
+ |
|
| 6241 |
+ /** |
|
| 6242 |
+ * @param p_mjonPayVO |
|
| 6243 |
+ * @return |
|
| 6244 |
+ * @throws Exception |
|
| 6245 |
+ */ |
|
| 6246 |
+ private MjonPayVO p_checkSortCnd( |
|
| 6247 |
+ MjonPayVO p_mjonPayVO |
|
| 6248 |
+ ) throws Exception{
|
|
| 6249 |
+ //정렬 처리 |
|
| 6250 |
+ if("".equals(p_mjonPayVO.getSearchSortCnd())){ //최초조회시 최신것 조회List
|
|
| 6251 |
+ p_mjonPayVO.setSearchSortCnd("moid");
|
|
| 6252 |
+ p_mjonPayVO.setSearchSortOrd("desc");
|
|
| 6253 |
+ }else {//포인트 교환내역에서 정렬 종류가 달라서 변환처리 해줌
|
|
| 6254 |
+ |
|
| 6255 |
+ String sortCnt = p_mjonPayVO.getSearchSortCnd(); |
|
| 6256 |
+ |
|
| 6257 |
+ if(sortCnt.equals("pointUseId") || sortCnt.equals("refundId")) {
|
|
| 6258 |
+ p_mjonPayVO.setSearchSortCnd("moid");
|
|
| 6259 |
+ }else if(sortCnt.equals("frstRegistPnttm") || sortCnt.equals("frstRegisterPnttm") || sortCnt.equals("refundHandlePnttm")) {
|
|
| 6260 |
+ p_mjonPayVO.setSearchSortCnd("regDate");
|
|
| 6261 |
+ }else if(sortCnt.equals("type")) {
|
|
| 6262 |
+ p_mjonPayVO.setSearchSortCnd("payMethodTxt");
|
|
| 6263 |
+ }else if(sortCnt.equals("point") || sortCnt.equals("refundMoney") || sortCnt.equals("refundCash")) {
|
|
| 6264 |
+ p_mjonPayVO.setSearchSortCnd("amt");
|
|
| 6265 |
+ }else if(sortCnt.equals("cmpltYn") || sortCnt.equals("refundStatus")) {
|
|
| 6266 |
+ p_mjonPayVO.setSearchSortCnd("pgStatusTxt");
|
|
| 6267 |
+ } |
|
| 6268 |
+ |
|
| 6269 |
+ } |
|
| 6270 |
+ |
|
| 6271 |
+ return p_mjonPayVO; |
|
| 6272 |
+ } |
|
| 6273 |
+ |
|
| 6274 |
+ /** |
|
| 6275 |
+ * @param p_mjonPayVO |
|
| 6276 |
+ * @return |
|
| 6277 |
+ * @throws Exception |
|
| 6278 |
+ */ |
|
| 6279 |
+ private MjonPayVO p_checkSearchDate( |
|
| 6280 |
+ MjonPayVO p_mjonPayVO |
|
| 6281 |
+ ) throws Exception{
|
|
| 6282 |
+ //검색 기간 처리 |
|
| 6283 |
+ if(!DateUtils.dateChkAndValueChk(p_mjonPayVO.getStartDate(),p_mjonPayVO.getEndDate(), 12 )) |
|
| 6284 |
+ {
|
|
| 6285 |
+ p_mjonPayVO.setStartDate(DateUtils.getDateMonthsAgo(12)); |
|
| 6286 |
+ p_mjonPayVO.setEndDate(DateUtils.getCurrentDate()); |
|
| 6287 |
+ } |
|
| 6288 |
+ |
|
| 6289 |
+ return p_mjonPayVO; |
|
| 6290 |
+ } |
|
| 6291 |
+ |
|
| 6292 |
+ private HttpServletResponse p_makeResponse( |
|
| 6293 |
+ HttpServletResponse p_response |
|
| 6294 |
+ , String p_fileName |
|
| 6295 |
+ ) throws Exception{
|
|
| 6296 |
+ p_response.setHeader("Set-Cookie", "fileDownload=true; path=/");
|
|
| 6297 |
+ SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat ( "yyyy_MM_dd_HH_mm_ss", Locale.KOREA ); |
|
| 6298 |
+ Date currentTime = new Date (); |
|
| 6299 |
+ String mTime = mSimpleDateFormat.format ( currentTime ); |
|
| 6300 |
+ p_fileName = p_fileName+"("+mTime+")";
|
|
| 6301 |
+ |
|
| 6302 |
+ p_response.setHeader("Content-Disposition", String.format("attachment; filename=\""+new String((p_fileName).getBytes("KSC5601"),"8859_1")+".xlsx"));
|
|
| 6303 |
+ |
|
| 6304 |
+ return p_response; |
|
| 6305 |
+ } |
|
| 6092 | 6306 |
} |
| 6093 | 6307 |
|
+++ src/main/java/itn/let/utl/user/service/ExcelUtil.java
... | ... | @@ -0,0 +1,143 @@ |
| 1 | +package itn.let.utl.user.service; | |
| 2 | + | |
| 3 | +import java.beans.PropertyDescriptor; | |
| 4 | +import java.lang.reflect.Method; | |
| 5 | +import java.util.List; | |
| 6 | + | |
| 7 | +import org.apache.poi.hssf.usermodel.HSSFCellStyle; | |
| 8 | +import org.apache.poi.hssf.usermodel.HSSFDataFormat; | |
| 9 | +import org.apache.poi.ss.usermodel.Cell; | |
| 10 | +import org.apache.poi.ss.usermodel.CellStyle; | |
| 11 | +import org.apache.poi.ss.usermodel.HorizontalAlignment; | |
| 12 | +import org.apache.poi.ss.usermodel.Row; | |
| 13 | +import org.apache.poi.ss.usermodel.VerticalAlignment; | |
| 14 | +import org.apache.poi.xssf.streaming.SXSSFSheet; | |
| 15 | +import org.apache.poi.xssf.streaming.SXSSFWorkbook; | |
| 16 | +import org.slf4j.Logger; | |
| 17 | +import org.slf4j.LoggerFactory; | |
| 18 | +import org.springframework.stereotype.Component; | |
| 19 | + | |
| 20 | +@Component | |
| 21 | +public class ExcelUtil { | |
| 22 | + private static final Logger log = LoggerFactory.getLogger(ExcelUtil.class); | |
| 23 | + | |
| 24 | + /** | |
| 25 | + * 엑셀 파일을 방출합니다. | |
| 26 | + * | |
| 27 | + * @param voList 엑셀에 넣고 싶은 vo 리스트 형태로 넣습니다. | |
| 28 | + * @param header 엑셀 해더 | |
| 29 | + * @param order 헤더에 해당하는 내용의 vo 필드 이름을 작성합니다. 예를 들어 String userName; 필드의 1번째 해더이름을 "사용자 이름" 으로 정했으면 | |
| 30 | + * 순서를 맞추어 1번째 order 배열에 "UserName" 이라는 글짜를 입력해줍니다(*주의:첫 문자는 대문자, 낙타체). 첫번째 컬럼에는 "줄번호"가 | |
| 31 | + * 들어가는데, 이것에 대한 내용은 order에 값을 입력하지 않습니다. | |
| 32 | + * @param width 컬럼 너비를 설정합니다. length가 해더의 length와 일치할 필요는 없습니다. | |
| 33 | + * @param title | |
| 34 | + * @throws Exception | |
| 35 | + * @return SXSSFSheet | |
| 36 | + * | |
| 37 | + * 특징 : 해더보다 내용의 컬럼수가 많을 때 해당 줄의 컬럼은 cut, 해더 이름이 vo와 다르게 되면 해당 컬럼 출력 안됨 require : 날짜 포멧은 | |
| 38 | + * 지원하지 않습니다. | |
| 39 | + * | |
| 40 | + * | |
| 41 | + * *********************************************************************************************** | |
| 42 | + * EX String title = "게시판 리스트"; | |
| 43 | + * int[] width = {1500, 1500, 1500, 3000, 30000, 3000 }; | |
| 44 | + * String[] header = {"번호", "게시판번호", "작성자", "제목", "내용", "작성일" }; | |
| 45 | + * String[] order = { "Seq", "UserId", "Title", "Content", "RegDt" }; | |
| 46 | + * => 첫번째 "번호"에 대한 order 이름이 비어있습니다. | |
| 47 | + * | |
| 48 | + * *********************************************************************************************** | |
| 49 | + */ | |
| 50 | + public static SXSSFWorkbook makeSimpleFruitExcelWorkbook(List<Object> voList, String[] header, String[] order, int[] width, String title) throws Exception { | |
| 51 | + // 시트 생성 | |
| 52 | + SXSSFWorkbook workbook = new SXSSFWorkbook(); | |
| 53 | + SXSSFSheet sheet = workbook.createSheet(title); | |
| 54 | + for (int i = 0; i < width.length; i++) { | |
| 55 | + // JSP 2022.02.24 => width 변경 | |
| 56 | + //sheet.setColumnWidth(0, width[width.length - (i + 1)]); | |
| 57 | + sheet.setColumnWidth(i, width[i]); | |
| 58 | + } | |
| 59 | + | |
| 60 | + int r = 2;// 줄부터 찍기 | |
| 61 | + | |
| 62 | + CellStyle headerstyle = workbook.createCellStyle(); | |
| 63 | + headerstyle.setAlignment(HorizontalAlignment.CENTER); | |
| 64 | + headerstyle.setVerticalAlignment(VerticalAlignment.CENTER); | |
| 65 | + headerstyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); | |
| 66 | + // 헤더 행 생 | |
| 67 | + Row headerRow = sheet.createRow(r); | |
| 68 | + // 해더 값 채움 (우측 방향으로) | |
| 69 | + Cell headerCell = null; | |
| 70 | + for (int i = 0; i < header.length; i++) { | |
| 71 | + headerRow.setHeight((short)512); | |
| 72 | + | |
| 73 | + headerCell = headerRow.createCell(i); | |
| 74 | + headerCell.setCellStyle(headerstyle); | |
| 75 | + headerCell.setCellValue(header[i]); | |
| 76 | + } | |
| 77 | + | |
| 78 | + // 내용 행 및 셀 생성 | |
| 79 | + Row bodyRow = null; | |
| 80 | + Cell bodyCell = null; | |
| 81 | + | |
| 82 | + bodyRow = sheet.createRow(0); | |
| 83 | + bodyCell = bodyRow.createCell(0); | |
| 84 | + bodyCell.setCellValue(title);// 읽어온 데이터 표시 | |
| 85 | + | |
| 86 | + //System.out.println("voList.size()"); | |
| 87 | + //System.out.println(voList.size()); | |
| 88 | + //System.out.println(voList.size()); | |
| 89 | + | |
| 90 | + int c = 0;// 컬럼 | |
| 91 | + for (Object vo : voList) { | |
| 92 | + bodyRow = sheet.createRow(r + 1); | |
| 93 | + bodyCell = bodyRow.createCell(0); | |
| 94 | + //bodyCell.setCellValue(r + 1); // 첫 컬럼은 줄 번호 | |
| 95 | + | |
| 96 | + PropertyDescriptor pd; // 클래스의 필드 메소드를 찾아줌. 이름을 기존에 vo.setUserId() 란 메소드를 통해서만 호출이 가능 했다면, PropertyDescriptor는 이름만으로 메소드 | |
| 97 | + // 호출이 가능함. 클래스가 변경 되어도 동일한 작동으로 getter&setter 호출이 가능하도록 도와줌 | |
| 98 | + Method[] methods = vo.getClass().getDeclaredMethods(); // 메소드들 호출함 | |
| 99 | + // 배열로 준 이름 과 같으면 해당 열 데이터 쓰기 | |
| 100 | + for (int i = 0; i < order.length; i++) { | |
| 101 | + for (Method method : methods) { // vo 내부 메소드 반복 | |
| 102 | + | |
| 103 | +// System.out.println("i :: "+ i + "methods : "+ methods); | |
| 104 | + /*System.out.println("voList.method()"); | |
| 105 | + System.out.println(method.getName());*/ | |
| 106 | + | |
| 107 | + if (method.getName().equals("get" + (order[i] == null ? "" : order[i]))) { // vo메소드 이름과 order의 이름 비교 | |
| 108 | + // getter 호출 준비 | |
| 109 | + String getMethodName = method.getName().substring(3); // getter의 이름 가져옴 | |
| 110 | + pd = new PropertyDescriptor(getMethodName, vo.getClass()); | |
| 111 | + // vo의 데이터 세팅 | |
| 112 | + String cellData = (pd.getReadMethod().invoke(vo) != null ? pd.getReadMethod().invoke(vo) : "").toString(); | |
| 113 | + bodyCell = bodyRow.createCell(c++); // 데이터 순서 | |
| 114 | + if(getMethodName.equals("InstrFee") || getMethodName.equals("SpecialWorkAllow") || getMethodName.equals("DistanceAllow") | |
| 115 | + || getMethodName.equals("TrafficFee") || getMethodName.equals("AcmdtFee") | |
| 116 | + || getMethodName.equals("Amt") || getMethodName.equals("Cash") | |
| 117 | + ){ | |
| 118 | + | |
| 119 | + // JSP 2022.02.22 => null 에러 try~catch 문 추가 | |
| 120 | + try { | |
| 121 | + double num = Double.parseDouble(cellData); | |
| 122 | + CellStyle bodyStyle = workbook.createCellStyle(); | |
| 123 | + bodyCell.setCellValue(num);// 읽어온 데이터 표시 | |
| 124 | + bodyStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0")); | |
| 125 | + bodyCell.setCellStyle(bodyStyle); | |
| 126 | + } | |
| 127 | + catch (Exception ex) { | |
| 128 | + bodyCell.setCellValue(cellData); | |
| 129 | + } | |
| 130 | + }else { | |
| 131 | + bodyCell.setCellValue(cellData);// 읽어온 데이터 표시 | |
| 132 | + } | |
| 133 | + //System.out.println("@@ : "+getMethodName +" --- " + cellData); | |
| 134 | + } | |
| 135 | + } | |
| 136 | + } | |
| 137 | + c = 0; | |
| 138 | + r++; | |
| 139 | + } | |
| 140 | + return workbook; | |
| 141 | + } | |
| 142 | + | |
| 143 | +} |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?