diff --git a/src/main/java/cokr/xit/fims/rent/RentQuery.java b/src/main/java/cokr/xit/fims/rent/RentQuery.java index 929f5537..592636b7 100644 --- a/src/main/java/cokr/xit/fims/rent/RentQuery.java +++ b/src/main/java/cokr/xit/fims/rent/RentQuery.java @@ -56,6 +56,8 @@ public class RentQuery extends CmmnQuery { private String callPurpose; // infoDialog 호출 용도(view 조회(편집불가), create 등록, update 수정, refresh 재조회). private String delRsn; // 삭제 사유 + private String cellDataDef; + public String getCrdnId() { return ifEmpty(crdnId, () -> null); } @@ -322,4 +324,10 @@ public class RentQuery extends CmmnQuery { } // ETC ///////////////////////////////////////////////////////////////////// + public String getCellDataDef() { + return ifEmpty(cellDataDef, () -> null); + } + public void setCellDataDef(String cellDataDef) { + this.cellDataDef = cellDataDef; + } } diff --git a/src/main/java/cokr/xit/fims/rent/web/Rent04Controller.java b/src/main/java/cokr/xit/fims/rent/web/Rent04Controller.java new file mode 100644 index 00000000..beff33ad --- /dev/null +++ b/src/main/java/cokr/xit/fims/rent/web/Rent04Controller.java @@ -0,0 +1,265 @@ +package cokr.xit.fims.rent.web; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.List; + +import javax.annotation.Resource; + +import org.apache.poi.xssf.usermodel.XSSFCell; +import org.apache.poi.xssf.usermodel.XSSFRow; +import org.apache.poi.xssf.usermodel.XSSFSheet; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.servlet.ModelAndView; + +import com.fasterxml.jackson.core.type.TypeReference; + +import cokr.xit.base.docs.xls.CellDef; +import cokr.xit.base.docs.xls.XLSWriter; +import cokr.xit.base.web.ApplicationController; +import cokr.xit.fims.base.FimsUser; +import cokr.xit.fims.cmmn.CmmnUtil; +import cokr.xit.fims.cmmn.xls.StyleMaker; +import cokr.xit.fims.crdn.CrdnQuery; +import cokr.xit.fims.crdn.dao.CrdnListMapper; +import cokr.xit.fims.rent.RentQuery; +import cokr.xit.fims.rent.dao.LsctMapper; +import cokr.xit.fims.rent.dao.UserRentEntMpngMapper; +import cokr.xit.foundation.data.DataObject; + +/**위택스 납부자 변경 서비스의 웹 컨트롤러 +* +*

상세 설명: +* +*

+* ============ 변경 이력 ============
+* 2024-09-30   leebj 최초 작성
+* ================================
+* 
+*/ +@Controller +@RequestMapping(name = "위택스 납부자 변경", value=Rent04Controller.CLASS_URL) +public class Rent04Controller extends ApplicationController { + + public static final String CLASS_URL = "/rent/rent04"; + + public class METHOD_URL { + public static final String + changeWetaxPayerMain = "/010/main.do", // 위택스 납부자 변경 메인 화면 + upload = "/010/upload.do", + download = "/010/download.do" + ; + } + + @Resource(name = "crdnListMapper") + private CrdnListMapper crdnListMapper; + + @Resource(name = "lsctMapper") + private LsctMapper lsctMapper; + + @Resource(name = "userRentEntMpngMapper") + private UserRentEntMpngMapper userRentEntMpngMapper; + + /**위택스 납부자 변경 메인화면을 연다. + * @return /rent/rent04010-main + */ + @RequestMapping(name = "위택스 납부자 변경 메인", value=METHOD_URL.changeWetaxPayerMain) + public ModelAndView changeWetaxPayerMain() { + ModelAndView mav = new ModelAndView("fims/rent/rent04010-main"); + + // 사용자 정보 + FimsUser fimsUser = (FimsUser)currentUser().getUser(); + + RentQuery req = new RentQuery(); + req.setUserId(fimsUser.getId()); + + + return mav + .addObject("pageName", "rent04010") // View(jsp)에서 사용할 id 뒤에 붙일 suffix + .addObject("prefixUrl", CLASS_URL) // prefixUrl + .addObject("userId", fimsUser.getId()) // 사용자 ID(USER_ID) + ; + } + + @PostMapping(name = "위택스 납부자 변경 엑셀파일 업로드", value=METHOD_URL.upload) + public ModelAndView upload(MultipartFile file) throws InterruptedException, IOException { + ModelAndView mav = new ModelAndView("jsonView"); + + byte[] bytesOfFile = file.getBytes(); + InputStream in = new ByteArrayInputStream(bytesOfFile); + XSSFWorkbook workbook = new XSSFWorkbook(in); + in.close(); + + int rowNo = 0; + int cellIndex = 0; + + XSSFSheet sheet = workbook.getSheetAt(0); // 0 번째 시트를 가져온다 + List result = new ArrayList(); + + int rows = sheet.getPhysicalNumberOfRows(); // 사용자가 입력한 엑셀 Row수를 가져온다 + for(rowNo = 0; rowNo < rows; rowNo++){ + DataObject resultRow = new DataObject(); + + resultRow + .set("A", "").set("B", "").set("C", "").set("D", "").set("E", "").set("F", "").set("G", "").set("H", "") + .set("I", "").set("J", "").set("K", "").set("L", "").set("M", "").set("N", "").set("O", "").set("P", ""); + + XSSFRow row = sheet.getRow(rowNo); + + if(row != null){ + int cells = 9; + for(cellIndex = 0; cellIndex <= cells; cellIndex++){ + + XSSFCell cell = row.getCell(cellIndex); // 셀의 값을 가져온다 + String value = ""; + if(cell == null){ // 빈 셀 체크 + value = ""; + }else{ + // 타입 별로 내용을 읽는다 + switch (cell.getCellType()){ + case FORMULA: + value = cell.getCellFormula(); + break; + case NUMERIC: + if(cellIndex == 6) { + value = new SimpleDateFormat("yyyy-MM-dd").format(cell.getDateCellValue()); + } else { + value = ""+(int)cell.getNumericCellValue() + ""; + } + + break; + case STRING: + value = cell.getStringCellValue() + ""; + break; + case BLANK: + value = ""; + break; + case ERROR: + value = cell.getErrorCellValue() + ""; + break; + } + } + + if(rowNo != 0) { + resultRow.put(CmmnUtil.indexToAlphabet(cellIndex, true, true), value); + } + } + + if(rowNo != 0) { + List searchResult = null; + + RentQuery entQuery = new RentQuery(); + entQuery.setUserId(currentUser().getId()); + List entList = userRentEntMpngMapper.selectUserRentEntMpngList(entQuery); + //사용자 기업ID 목록 + String[] entIds = entList.stream().map(i -> i.string("ENT_ID")).toList().toArray(new String[entList.size()]); + //사용자 기업등록번호 목록 + List entRegNos = entList.stream().map(i -> i.string("ENT_REG_NO")).toList(); + //사용자 기업명 목록 + List entNms = entList.stream().map(i -> i.string("ENT_NM")).toList(); + + RentQuery lsctQuery = new RentQuery(); + lsctQuery.setEntIds(entIds); + lsctQuery.setSchVhrno(resultRow.string("D")); + lsctQuery.setSchCtrtYmd(resultRow.string("G")); + //rentQuery.set시간(resultRow.string("G")); + searchResult = lsctMapper.selectLsctList(lsctQuery); + + if(searchResult != null && !searchResult.isEmpty()) { + DataObject searchResult1 = searchResult.get(0); + + resultRow.set("K", searchResult1.string("HIRER_NM")); + if(searchResult1.string("HIRER_SE_CD").equals("99")) { + resultRow.set("L", searchResult1.string("HIRER_REG_NO")); + } else { + resultRow.set("M", searchResult1.string("HIRER_REG_NO")); + } + resultRow.set("N", searchResult1.string("HIRER_ADDR")); + resultRow.set("O", searchResult1.string("HIRER_DTL_ADDR")); + resultRow.set("P", searchResult1.string("HIRER_ZIP")); + + } else { + CrdnQuery crdnQuery = new CrdnQuery(); + crdnQuery.setVhrno(resultRow.string("D")); + crdnQuery.setSchCrdnYmdFrom(resultRow.string("G")); + crdnQuery.setSchCrdnYmdTo(resultRow.string("G")); + //crdnQuery.set시간(resultRow.string("G")); + searchResult = crdnListMapper.selectCrackdownList(crdnQuery); + + if(searchResult != null && !searchResult.isEmpty()) { + DataObject searchResult1 = searchResult.get(0); + + //납부자정보가 사용자기업정보가 아니면 + if(!entNms.contains(searchResult1.string("RTPYR_NM")) + && !entRegNos.contains(searchResult1.string("RTPYR_NO")) + ) { + resultRow.set("K", searchResult1.string("RTPYR_NM")); + if(searchResult1.string("RTPYR_SE_CD").equals("99")) { + resultRow.set("L", searchResult1.string("RTPYR_NO")); + } else { + resultRow.set("M", searchResult1.string("RTPYR_NO")); + } + resultRow.set("N", searchResult1.string("RTPYR_ADDR")); + resultRow.set("O", searchResult1.string("RTPYR_DTL_ADDR")); + resultRow.set("P", searchResult1.string("RTPYR_ZIP")); + } + + } + } + + + result.add(resultRow); + } + } + } + workbook.close(); + + mav.addObject("data", result); + mav.addObject("saved", true); + return mav; + } + + @GetMapping(name = "위택스 납부자 변경 엑셀파일 다운로드", value=METHOD_URL.download) + public ModelAndView download(RentQuery query) { + + ModelAndView mav = new ModelAndView("downloadView"); + XLSWriter xlsx = new XLSWriter().worksheet(0); + + List cellDefs = new ArrayList(); + cellDefs.add(new CellDef().setField("A").setLabel("관리번호")); + cellDefs.add(new CellDef().setField("B").setLabel("전자납부번호")); + cellDefs.add(new CellDef().setField("C").setLabel("관할자치단체")); + cellDefs.add(new CellDef().setField("D").setLabel("부과대상")); + cellDefs.add(new CellDef().setField("E").setLabel("위반장소")); + cellDefs.add(new CellDef().setField("F").setLabel("위반내용")); + cellDefs.add(new CellDef().setField("G").setLabel("등록(위반)일시")); + cellDefs.add(new CellDef().setField("H").setLabel("과태료부과금액")); + cellDefs.add(new CellDef().setField("I").setLabel("의견제출시작일")); + cellDefs.add(new CellDef().setField("J").setLabel("의견제출종료일")); + cellDefs.add(new CellDef().setField("K").setLabel("변경자 성명/법인명")); + cellDefs.add(new CellDef().setField("L").setLabel("변경자 운전면허번호")); + cellDefs.add(new CellDef().setField("M").setLabel("변경자 주민/법인번호")); + cellDefs.add(new CellDef().setField("N").setLabel("변경자 주소")); + cellDefs.add(new CellDef().setField("O").setLabel("변경자 상세주소")); + cellDefs.add(new CellDef().setField("P").setLabel("변경자 우편번호")); + + List list = fromJson(query.getCellDataDef(), new TypeReference>(){}); + + xlsx.cell(0, 0).rowValues(CellDef.header(cellDefs, () -> StyleMaker.headerStyle(xlsx))); + xlsx.cell(1, 0).values(list, CellDef.values(cellDefs)); + + + mav.addObject("download", xlsx.getDownloadable().setFilename("위택스 법인과태료대상목록(결과).xlsx")); + + return mav; + } + +}