package geoinfo.admins.constructionProjectManagement; import java.io.IOException; import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.security.SecureRandom; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; import javax.annotation.Resource; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Sheet; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import egovframework.rte.psl.dataaccess.util.EgovMap; import egovframework.rte.ptl.mvc.tags.ui.pagination.PaginationInfo; import geoinfo.admins.constructionProjectManagement.service.ConstructionProjectManagementService; import geoinfo.admins.user.service.DrillingInquiryService; import geoinfo.admins.user.service.GeneralUserMngService; import geoinfo.admins.user.service.HomeTrainingService; import geoinfo.com.EgovExcel; import geoinfo.comm.util.ScriptUtil; import geoinfo.comm.util.strUtil; import geoinfo.session.UserInfo; import geoinfo.util.ExcelMergeHeaderUtil; import geoinfo.util.MyUtil; @Controller public class ConstructionProjectManagementController { @Resource(name = "generalUserMngService") private GeneralUserMngService masterService; @Resource(name = "homeTrainingService") private HomeTrainingService homeTrainingService; // [변경] 새로 만든 서비스 주입 @Resource(name = "constructionProjectManagementService") private ConstructionProjectManagementService constructionProjectManagementService; // [추가] 기존 검색/조회 기능을 위해 필요 (변수 선언 추가) @Resource(name = "drillingInquiryService") private DrillingInquiryService drillingInquiryService; /** * 건설현장 통계 화면 * @param params * @param model * @param response * @param request * @return * @throws Exception */ @RequestMapping(value = "admins/constructionProjectManagement/construction-project-statistics-index.do") public String homeTrainingIndex(@RequestParam HashMap params, ModelMap model, HttpServletResponse response, HttpServletRequest request) throws Exception { if (!UserInfo.isValidSession(request, response, "admin")) { return ""; } model.addAttribute("params", params); return "admins/constructionProjectManagement/construction-project-statistics-index"; } /** * 건설현장 통계 데이터 조회 (AJAX) */ @RequestMapping(value = "admins/constructionProjectManagement/selectStatistics.do", method = RequestMethod.POST) @ResponseBody public JSONObject selectStatistics(HttpServletRequest request, @RequestBody String strJSON, HttpServletResponse response) { JSONObject jsonResponse = new JSONObject(); try { // 1. 파라미터 파싱 JSONParser jsonParser = new JSONParser(); JSONObject jsonObject = (JSONObject) jsonParser.parse(strJSON); HashMap params = new HashMap<>(); if (jsonObject != null) { for(Object key : jsonObject.keySet()){ params.put((String)key, jsonObject.get(key)); } } // 2. 서비스 호출 (새로 만든 서비스 사용) Map stats = constructionProjectManagementService.selectConstructionProjectStatistics(params); jsonResponse.put("result", "true"); jsonResponse.put("data", stats); } catch (Exception e) { jsonResponse.put("result", "false"); jsonResponse.put("message", e.getMessage()); e.printStackTrace(); } return jsonResponse; } /** * 집합교육 추가 * @param request * @param strJSON * @param response * @return */ @RequestMapping(value = "admins/constructionProjectManagement/home-training-index/add.do", method = RequestMethod.POST) @ResponseBody public JSONObject addHomeTraining( HttpServletRequest request, @RequestBody String strJSON, HttpServletResponse response) { JSONObject jsonResponse = new JSONObject(); System.out.println( "\n--------------------------------------------------------------\n" + request.getRequestURI() + " IN:" + "\n--------------------------------------------------------------\n" + "strJSON" + strJSON + "\n" + "\n--------------------------------------------------------------\n" ); JSONParser jsonParser = new JSONParser(); JSONArray jsonArr = null; boolean isFail = false; String failMsg = ""; try { jsonArr = (JSONArray)jsonParser.parse(strJSON); for (Object obj : jsonArr) { JSONObject jsonObject = (JSONObject) obj; // JSONObject를 HashMap으로 변환 HashMap params = new HashMap<>(); for (Object key : jsonObject.keySet()) { String keyStr = (String) key; Object value = jsonObject.get(keyStr); params.put(keyStr, value); } try { HashMap hashMap = homeTrainingService.addHomeTraining(request, response, params); int nRetCode = MyUtil.getIntegerFromObject(hashMap.get("p_result_code")); String lpszRetMsg = MyUtil.getStringFromObject(hashMap.get("p_err_msg")); long lWvtRegId = MyUtil.getLongFromObject(hashMap.get("p_wvt_reg_id")); if( nRetCode == 100 ) { jsonResponse.put("resultCode", nRetCode); jsonResponse.put("result", "true"); jsonResponse.put("message", "등록이 완료되었습니다."); } else { if( nRetCode == 11 ) { lpszRetMsg += "\n" + "사업명: " + params.get("constName"); } jsonResponse.put("resultCode", nRetCode); jsonResponse.put("result", "false"); jsonResponse.put("message", lpszRetMsg); isFail = true; failMsg = lpszRetMsg; break; } } catch (Exception e) { // TODO Auto-generated catch block String strTxt = "---------- BUG REPORTING START ----------" + "\n" + "에러 문구:[" + request.getRequestURI() + " " + "]" + "\n" + "strJSON:[\n" + strJSON + "\n]\n" + "e.getMessage():[\n" + e.getMessage() + "\n]\n" + "\n" + "new Date().toString():[" + new Date().toString() + "]\n" + "\n" + "---------- BUG REPORTING END ----------" + "\n" + ""; System.out.println(strTxt); jsonResponse.put("resultCode", -1); jsonResponse.put("result", "false"); jsonResponse.put("message", e.getMessage()); } } } catch (org.json.simple.parser.ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } if( isFail ) { jsonResponse.put("resultCode", -2); jsonResponse.put("result", "false"); jsonResponse.put("message", failMsg); } System.out.println("\n--------------------------------------------------------------\n" + request.getRequestURI() + " OUT:" + "\n--------------------------------------------------------------\n" + "jsonResponse.toJSONString():[" + jsonResponse.toJSONString() + "]\n" + "\n--------------------------------------------------------------\n"); return jsonResponse; } /** * 집합교육 수정 * @param request * @param strJSON * @param response * @return */ @RequestMapping(value = "admins/constructionProjectManagement/home-training-index/update.do", method = RequestMethod.POST) @ResponseBody public JSONObject updateHomeTraining( HttpServletRequest request, @RequestBody String strJSON, HttpServletResponse response) { JSONObject jsonResponse = new JSONObject(); System.out.println( "\n--------------------------------------------------------------\n" + request.getRequestURI() + " IN:" + "\n--------------------------------------------------------------\n" + "strJSON" + strJSON + "\n" + "\n--------------------------------------------------------------\n" ); JSONParser jsonParser = new JSONParser(); JSONArray jsonArr = null; boolean isFail = false; String failMsg = ""; try { jsonArr = (JSONArray)jsonParser.parse(strJSON); for (Object obj : jsonArr) { JSONObject jsonObject = (JSONObject) obj; // JSONObject를 HashMap으로 변환 HashMap params = new HashMap<>(); for (Object key : jsonObject.keySet()) { String keyStr = (String) key; Object value = jsonObject.get(keyStr); params.put(keyStr, value); } try { HashMap hashMap = homeTrainingService.updateHomeTraining(request, response, params); int nRetCode = MyUtil.getIntegerFromObject(hashMap.get("p_result_code")); String lpszRetMsg = MyUtil.getStringFromObject(hashMap.get("p_err_msg")); if( nRetCode == 100 ) { jsonResponse.put("resultCode", nRetCode); jsonResponse.put("result", "true"); jsonResponse.put("message", "수정이 완료되었습니다."); } else { if( nRetCode == 11 ) { lpszRetMsg += "\n" + "사업명: " + params.get("constName"); } jsonResponse.put("resultCode", nRetCode); jsonResponse.put("result", "false"); jsonResponse.put("message", lpszRetMsg); isFail = true; failMsg = lpszRetMsg; break; } } catch (Exception e) { // TODO Auto-generated catch block String strTxt = "---------- BUG REPORTING START ----------" + "\n" + "에러 문구:[" + request.getRequestURI() + " " + "]" + "\n" + "strJSON:[\n" + strJSON + "\n]\n" + "e.getMessage():[\n" + e.getMessage() + "\n]\n" + "\n" + "new Date().toString():[" + new Date().toString() + "]\n" + "\n" + "---------- BUG REPORTING END ----------" + "\n" + ""; System.out.println(strTxt); jsonResponse.put("resultCode", -1); jsonResponse.put("result", "false"); jsonResponse.put("message", e.getMessage()); } } } catch (org.json.simple.parser.ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } if( isFail ) { jsonResponse.put("resultCode", -2); jsonResponse.put("result", "false"); jsonResponse.put("message", failMsg); } System.out.println("\n--------------------------------------------------------------\n" + request.getRequestURI() + " OUT:" + "\n--------------------------------------------------------------\n" + "jsonResponse.toJSONString():[" + jsonResponse.toJSONString() + "]\n" + "\n--------------------------------------------------------------\n"); return jsonResponse; } @RequestMapping(value = "admins/constructionProjectManagement/home-training-index/list.do", method = RequestMethod.GET) @ResponseBody public JSONObject getHomeTraining( HttpServletRequest request, @RequestParam HashMap params, HttpServletResponse response) { JSONObject jsonResponse = new JSONObject(); System.out.println( "\n--------------------------------------------------------------\n" + request.getRequestURI() + " IN:" + "\n--------------------------------------------------------------\n" + "params.toString()" + params.toString() + "\n" + "\n--------------------------------------------------------------\n" ); try { homeTrainingService.getHomeTraining(request, response, jsonResponse, params); jsonResponse.put("resultCode", 100); jsonResponse.put("result", "true"); jsonResponse.put("message", "조회가 완료되었습니다."); } catch (Exception e) { // TODO Auto-generated catch block String strTxt = "---------- BUG REPORTING START ----------" + "\n" + "에러 문구:[" + request.getRequestURI() + " " + "]" + "\n" + "e.getMessage():[\n" + e.getMessage() + "\n]\n" + "\n" + "new Date().toString():[" + new Date().toString() + "]\n" + "\n" + "---------- BUG REPORTING END ----------" + "\n" + ""; System.out.println(strTxt); String eMsg = e.getMessage(); if( eMsg != null ) { if( eMsg.equals("로그인이 필요한 서비스입니다.") ) { jsonResponse.put("resultCode", 401); } } jsonResponse.put("resultCode", -1); jsonResponse.put("result", "false"); jsonResponse.put("message", e.getMessage()); } System.out.println( "\n--------------------------------------------------------------\n" + request.getRequestURI() + " OUT:" + "\n--------------------------------------------------------------\n" + "jsonResponse.toJSONString():[" + jsonResponse.toJSONString() + "]\n" + "\n--------------------------------------------------------------\n" ); return jsonResponse; } /** * 특정 집합교육에 참여한 사용자 목록을 조회한다. * @param request * @param params * @param response * @return */ @RequestMapping(value = "admins/constructionProjectManagement/home-training-index/item/list.do", method = RequestMethod.GET) @ResponseBody public JSONObject getHomeTrainingItemList( HttpServletRequest request, @RequestParam HashMap params, HttpServletResponse response) { JSONObject jsonResponse = new JSONObject(); System.out.println( "\n--------------------------------------------------------------\n" + request.getRequestURI() + " IN:" + "\n--------------------------------------------------------------\n" + "params.toString()" + params.toString() + "\n" + "\n--------------------------------------------------------------\n" ); try { homeTrainingService.getHomeTrainingItemList(request, response, jsonResponse, params); jsonResponse.put("resultCode", 100); jsonResponse.put("result", "true"); jsonResponse.put("message", "조회가 완료되었습니다."); } catch (Exception e) { // TODO Auto-generated catch block String strTxt = "---------- BUG REPORTING START ----------" + "\n" + "에러 문구:[" + request.getRequestURI() + " " + "]" + "\n" + "e.getMessage():[\n" + e.getMessage() + "\n]\n" + "\n" + "new Date().toString():[" + new Date().toString() + "]\n" + "\n" + "---------- BUG REPORTING END ----------" + "\n" + ""; System.out.println(strTxt); jsonResponse.put("resultCode", -1); jsonResponse.put("result", "false"); jsonResponse.put("message", e.getMessage()); } System.out.println( "\n--------------------------------------------------------------\n" + request.getRequestURI() + " OUT:" + "\n--------------------------------------------------------------\n" + "jsonResponse.toJSONString():[" + jsonResponse.toJSONString() + "]\n" + "\n--------------------------------------------------------------\n" ); return jsonResponse; } @RequestMapping(value = "admins/constructionProjectManagement/home-training-index/item/delete.do", method = RequestMethod.POST) @ResponseBody public JSONObject deleteHomeTrainingItem( HttpServletRequest request, @RequestBody String strJSON, HttpServletResponse response) { JSONObject jsonResponse = new JSONObject(); System.out.println( "\n--------------------------------------------------------------\n" + request.getRequestURI() + " IN:" + "\n--------------------------------------------------------------\n" + "strJSON" + strJSON + "\n" + "\n--------------------------------------------------------------\n" ); JSONParser jsonParser = new JSONParser(); JSONArray jsonArr = null; boolean isFail = false; String failMsg = ""; try { jsonArr = (JSONArray)jsonParser.parse(strJSON); for (Object obj : jsonArr) { JSONObject jsonObject = (JSONObject) obj; // JSONObject를 HashMap으로 변환 HashMap params = new HashMap<>(); for (Object key : jsonObject.keySet()) { String keyStr = (String) key; Object value = jsonObject.get(keyStr); params.put(keyStr, value); } try { HashMap hashMap = homeTrainingService.deleteHomeTrainingItem(request, response, params); int nRetCode = MyUtil.getIntegerFromObject(hashMap.get("p_result_code")); String lpszRetMsg = MyUtil.getStringFromObject(hashMap.get("p_err_msg")); if( nRetCode == 100 ) { jsonResponse.put("resultCode", nRetCode); jsonResponse.put("result", "true"); jsonResponse.put("message", "삭제가 완료되었습니다."); } else { if( nRetCode == 11 ) { lpszRetMsg += "\n" + "사업명: " + params.get("constName"); } jsonResponse.put("resultCode", nRetCode); jsonResponse.put("result", "false"); jsonResponse.put("message", lpszRetMsg); isFail = true; failMsg = lpszRetMsg; break; } } catch (Exception e) { // TODO Auto-generated catch block String strTxt = "---------- BUG REPORTING START ----------" + "\n" + "에러 문구:[" + request.getRequestURI() + " " + "]" + "\n" + "strJSON:[\n" + strJSON + "\n]\n" + "e.getMessage():[\n" + e.getMessage() + "\n]\n" + "\n" + "new Date().toString():[" + new Date().toString() + "]\n" + "\n" + "---------- BUG REPORTING END ----------" + "\n" + ""; System.out.println(strTxt); jsonResponse.put("resultCode", -1); jsonResponse.put("result", "false"); jsonResponse.put("message", e.getMessage()); } } } catch (org.json.simple.parser.ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } if( isFail ) { jsonResponse.put("resultCode", -2); jsonResponse.put("result", "false"); jsonResponse.put("message", failMsg); } System.out.println("\n--------------------------------------------------------------\n" + request.getRequestURI() + " OUT:" + "\n--------------------------------------------------------------\n" + "jsonResponse.toJSONString():[" + jsonResponse.toJSONString() + "]\n" + "\n--------------------------------------------------------------\n"); return jsonResponse; } /** * 집합교육 승인 화면 * @param params * @param model * @param response * @param request * @return * @throws Exception */ @RequestMapping(value = "admins/constructionProjectManagement/home-training-approval-system") public String homeTrainingApprovalSystem(@RequestParam HashMap params, ModelMap model, HttpServletResponse response, HttpServletRequest request) throws Exception { if (!UserInfo.isValidSession(request, response, "admin")) { return ""; } model.addAttribute("params", params); return "admins/constructionProjectManagement/home-training-approval-system"; } /** * 방문교육 달력 화면 * @param params * @param model * @param response * @param request * @return * @throws Exception */ @RequestMapping(value = "admins/constructionProjectManagement/visit-training-index.do") public String visitTrainingIndex(@RequestParam HashMap params, ModelMap model, HttpServletResponse response, HttpServletRequest request) throws Exception { if (!UserInfo.isValidSession(request, response, "admin")) { return ""; } model.addAttribute("params", params); return "admins/constructionProjectManagement/visit-training-index"; } /** * 방문교육 승인 화면 * @param params * @param model * @param response * @param request * @return * @throws Exception */ @RequestMapping(value = "admins/constructionProjectManagement/visit-training-approval-system") public String visitTrainingApprovalSystem(@RequestParam HashMap params, ModelMap model, HttpServletResponse response, HttpServletRequest request) throws Exception { if (!UserInfo.isValidSession(request, response, "admin")) { return ""; } model.addAttribute("params", params); return "admins/constructionProjectManagement/visit-training-approval-system"; } /** * 건설현장 조회 목록화면 * @param params * @param model * @param response * @param request * @return * @throws Exception */ @RequestMapping(value = "admins/constructionProjectManagement/construction-site-index.do") public String constructionSiteIndex(@RequestParam HashMap params, ModelMap model, HttpServletResponse response, HttpServletRequest request) throws Exception { JSONObject jsonObj = new JSONObject(); if (!UserInfo.isValidSession(request, response, "admin")) { return ""; } List gDis = drillingInquiryService.getGDisList(params); jsonObj.put("gDis", gDis); model.put("result", jsonObj); model.addAttribute("params", params); return "admins/constructionProjectManagement/construction-site-index"; } /** * 건설현장 관리 > 발주기관 계정 화면 * @param params * @param model * @param response * @param request * @return * @throws Exception */ @RequestMapping(value = "admins/constructionProjectManagement/construction-user-mgmt-index.do") public String goConstructionUserMgmt(@RequestParam HashMap params, ModelMap model, HttpServletResponse response, HttpServletRequest request) throws Exception { if (!UserInfo.isValidSession(request, response, "admin")) { return ""; } /** 2023.10.25 LHJ 검색조건 추가 : 가입기간 시작/종료날짜를 8자리 숫자로 입력하지 않았을 때 처리 **/ String searchBgndt = (String) params.get("searchBgndt"); if(searchBgndt == null || searchBgndt.length() != 8 || !searchBgndt.matches("[0-9]+")) { params.put("searchBgndt", ""); } String searchEnddt = (String) params.get("searchEnddt"); if(searchEnddt == null || searchEnddt.length() != 8 || !searchEnddt.matches("[0-9]+")) { params.put("searchEnddt", ""); } params.put("cls", "2"); /** pageing */ PaginationInfo paginationInfo = new PaginationInfo(); if (params.get("pageIndex") == null || "".equals(params.get("pageIndex"))) { paginationInfo.setCurrentPageNo(1); params.put("pageIndex", 1); } else { paginationInfo.setCurrentPageNo(Integer.valueOf((String) params.get("pageIndex"))); } paginationInfo.setRecordCountPerPage(10); paginationInfo.setPageSize(10); params.put("firstRecordIndex", paginationInfo.getFirstRecordIndex()); params.put("recordCountPerPage", paginationInfo.getRecordCountPerPage()); List resultList = masterService.selectInfoList(params); int totalCnt = resultList.size() == 0 ? 0 : Integer.valueOf(((EgovMap) resultList.get(0)).get("totalrows").toString()); paginationInfo.setTotalRecordCount(totalCnt); model.addAttribute("params", params); model.addAttribute("resultList", resultList); model.addAttribute("paginationInfo", paginationInfo); return "admins/constructionProjectManagement/construction-user-mgmt-index"; } /** * 발주기관 계정등록 팝업 * @param params * @param model * @param response * @param request * @return * @throws Exception */ @RequestMapping(value = "admins/client/05_addUser.do") public String showAddClientPopop(@RequestParam HashMap params, ModelMap model, HttpServletResponse response, HttpServletRequest request) throws Exception { if( !UserInfo.isValidSession(request, response, "admin")) { return ""; } // 지역 목록 JSONObject jsonObj = new JSONObject(); List gDis = masterService.getUserGDisList(params); jsonObj.put("gDis", gDis); model.put("result", jsonObj); return "admins/constructionProjectManagement/05_addUser"; } /** * 발주기관 계정등록 - 아이디 중복 체크 * @param request * @param params * @param response * @return * @throws Exception */ @RequestMapping(value = "admins/client/duplChk.do", method = RequestMethod.POST, produces = { "application/json; charset=utf-8" }) @ResponseBody public Map clientDuplChk(HttpServletRequest request, @RequestParam HashMap params, HttpServletResponse response) throws Exception { if (!UserInfo.isValidSession(request, response, "admin")) { return null; } Map result = new HashMap<>(); EgovMap resultMap = masterService.selectInfoDuplClient(params); result.put("duplCnt", resultMap.get("duplCnt")); return result; } /** * 발주기관 계정등록 * @param request * @param params * @param response * @return * @throws Exception */ @RequestMapping(value = "admins/client/insert.do", method = RequestMethod.POST) @ResponseBody public Map insertClient(HttpServletRequest request, @RequestParam HashMap params, HttpServletResponse response) throws Exception { if (!UserInfo.isValidSession(request, response, "admin")) { return null; } strUtil sUtil = new strUtil(); String pass2 = ""; String pass = sUtil.checkNull((String)params.get("passwd")); pass2 = ScriptUtil.getSha256(pass, "UTF-8").substring(0, 20); params.put("encPasswd", pass2); Map result = new HashMap<>(); int resultCnt = masterService.insertWebMemberInClient(params); result.put("resultCnt", resultCnt); return result; } /** * 건설현장 관리 > 발주기관 계정 상세조회 화면 * @param params * @param model * @param response * @param request * @return * @throws Exception */ @RequestMapping(value = "admins/constructionProjectManagement/construction-user-detail.do") public String goConstructionUserDetail(@RequestParam HashMap params, ModelMap model, HttpServletResponse response, HttpServletRequest request) throws Exception { if (!UserInfo.isValidSession(request, response, "admin")) { return ""; } model.addAttribute("params", params); return "admins/constructionProjectManagement/construction-user-detail"; } /** * 프로젝트 목록 조회 프로젝트명 자동검색 * @param request * @param response * @param params * @return * @throws Exception */ @ResponseBody @RequestMapping(value = "/drilling-project-list", method = RequestMethod.GET, produces = "application/json; charset=UTF-8") public String getDrillingProjectList(HttpServletRequest request, HttpServletResponse response, @RequestParam HashMap params) throws Exception { if (!UserInfo.isValidSession(request, response, "admin")) { return ""; } JSONObject jsonObject = new JSONObject(); strUtil sUtil = new strUtil(); String projectName = sUtil.checkNull((String)params.get("projectName")); JSONArray jsonListObject = new JSONArray(); JSONObject result = new JSONObject(); result.put("list", drillingInquiryService.drillingInquiryAutocompleteList(request, params)); jsonObject.put("resultMessage", "OK"); jsonObject.put("resultCode", 200); jsonObject.put("result", result); response.setContentType("application/json; charset=UTF-8"); // 응답 헤더 설정 response.setCharacterEncoding("UTF-8"); // 응답 데이터 인코딩 설정 (중요) try (OutputStream os = response.getOutputStream()) { // OutputStream 사용 os.write(jsonObject.toString().getBytes("UTF-8")); // UTF-8 인코딩하여 출력 } return null; // @ResponseBody이므로 반환 값은 필요 없습니다. } /** * 발주기관 프로젝트목록 가져오기 * @param request * @param params * @param response * @return * @throws IOException */ @RequestMapping(value = "/drilling/inquiry/list.do", method = RequestMethod.GET, produces = { "application/json; charset=utf-8" }) @ResponseBody public ResponseEntity drillingInquiryList ( HttpServletRequest request, @RequestParam HashMap params, HttpServletResponse response ) throws IOException { if (!UserInfo.isValidSession(request, response, "admin")) { return null; } System.out.println( "\n--------------------------------------------------------------\n" + request.getRequestURI() + " IN:" + "\n--------------------------------------------------------------\n" + "params" + params.toString() + "\n" + "\n--------------------------------------------------------------\n" ); JSONObject jSONOResponse = null; try { jSONOResponse = drillingInquiryService.drillingInquiryList( request, params ); } catch (Exception e) { // TODO Auto-generated catch block jSONOResponse = new JSONObject(); String strTxt = "---------- BUG REPORTING START ----------" + "\n" + "에러 문구:[" + request.getRequestURI() + " " + "]" + "\n" + "params:[\n" + params.toString() + "\n]\n" + "e.getMessage():[\n" + e.getMessage() + "\n]\n" + "\n" + "new Date().toString():[" + new Date().toString() + "]\n" + "\n" + "---------- BUG REPORTING END ----------" + "\n" + ""; System.out.println(strTxt); jSONOResponse.put("resultCode", -1); jSONOResponse.put("result", "false"); jSONOResponse.put("message", e.getMessage()); } System.out.println( "\n--------------------------------------------------------------\n" + request.getRequestURI() + " OUT:" + "\n--------------------------------------------------------------\n" + "jSONOResponse.toJSONString():[" + jSONOResponse.toJSONString() + "]\n" + "\n--------------------------------------------------------------\n" ); int contentLength = 0; try { contentLength = jSONOResponse.toJSONString().getBytes("UTF-8").length; } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } response.setStatus(HttpServletResponse.SC_OK); response.setCharacterEncoding("UTF-8"); response.setHeader("Content-Type", "application/json; charset=utf-8"); response.setContentLength(contentLength); // Content-Length 설정 try { response.getWriter().print(jSONOResponse); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } /** * 발주기관 건설현장 CSV 다운로드 처리 * @param workbook * @param request * @param response * @throws Exception */ @RequestMapping(value = "admins/drilling/inquiry/excel.do") public void downloadDrillingInquiryListExcel(HttpServletRequest request, HttpServletResponse response, HSSFWorkbook workbook, @RequestParam HashMap params) throws Exception { HashMap map = new HashMap(); String[] headers = {"cid","constName","projectStateCodeName","constStartDate","constStateCodeName","inquiryDist" ,"masterCompanyDept","masterCompanyAdmin","masterCompanyTel","coinstCompanyDept","constCompanyAdmin","constCompanyTel"}; String[][] headerNames = {{"연번", "사업명", "입력상태", "사업내용", "", "발주기관현황", "", "", "", "건설사현황", "", ""}, {"", "", "", "사업기간", "사업단계", "발주처", "담당부서", "담당자", "담당자연락처", "건설사명", "담당자", "담당자연락처"}}; final int[] headerWidths = {1325, 15900, 4240, 6360, 5830, 8830, 6890, 2915, 3710, 5035, 2915, 3710}; String[] columnType = {"String", "String", "String", "String", "String", "String", "String", "String", "String", "String", "String", "String"}; String sheetName = "Sheet1"; String excelFileName = "발주기관 건설현장 목록"; // int startIndex = 0; Long totalCount = 0L; // DB 조회 JSONObject resultObj = drillingInquiryService.drillingInquiryList(request, params); // 여기에서 list 꺼내기 List list = (List) resultObj.get("datas"); totalCount = (Long) resultObj.get("count"); int idx = 0; for (EgovMap rowData : list) { // 공사기간 형식 처리: startDate ~ endDate String constStartDate = (String) rowData.get("constStartDate"); String constEndDate = (String) rowData.get("constEndDate"); rowData.put("constStartDate", constStartDate + " ~ " + constEndDate); // 공사기간을 'startDate ~ endDate' 형식으로 변환 rowData.put("cid", (totalCount) - (idx++)); String glName = ""; String gmName = ""; String gsName = ""; String inquiryDist = ""; // 발주처 if ((String)rowData.get("glName") != null) { glName = (String)rowData.get("glName"); inquiryDist = inquiryDist + glName + " "; }if ((String)rowData.get("gmName") != null) { gmName = (String)rowData.get("gmName"); inquiryDist = inquiryDist + gmName + " "; }if ((String)rowData.get("gsName") != null) { gsName = (String)rowData.get("gsName"); inquiryDist = inquiryDist + gsName; } rowData.put("inquiryDist", inquiryDist); } ExcelMergeHeaderUtil.listToExcelMergeHeader(list, response, headers, headerNames, headerWidths, columnType, sheetName, excelFileName); } /** * 건설현장 관리 > 발주기관 로그인 내역 화면 * @param params * @param model * @param response * @param request * @return * @throws Exception */ @RequestMapping(value = "admins/constructionProjectManagement/construction-user-login-history.do") public String goConstructionUserloginHist(@RequestParam HashMap params, ModelMap model, HttpServletResponse response, HttpServletRequest request) throws Exception { if (!UserInfo.isValidSession(request, response, "admin")) { return ""; } /** 2023.10.25 LHJ 검색조건 추가 : 가입기간 시작/종료날짜를 8자리 숫자로 입력하지 않았을 때 처리 **/ String searchBgndt = (String) params.get("searchBgndt"); if(searchBgndt == null || searchBgndt.length() != 8 || !searchBgndt.matches("[0-9]+")) { params.put("searchBgndt", ""); } String searchEnddt = (String) params.get("searchEnddt"); if(searchEnddt == null || searchEnddt.length() != 8 || !searchEnddt.matches("[0-9]+")) { params.put("searchEnddt", ""); } /** pageing */ PaginationInfo paginationInfo = new PaginationInfo(); if (params.get("pageIndex") == null || "".equals(params.get("pageIndex"))) { paginationInfo.setCurrentPageNo(1); params.put("pageIndex", 1); } else { paginationInfo.setCurrentPageNo(Integer.valueOf((String) params.get("pageIndex"))); } paginationInfo.setRecordCountPerPage(10); paginationInfo.setPageSize(10); params.put("firstRecordIndex", paginationInfo.getFirstRecordIndex()); params.put("recordCountPerPage", paginationInfo.getRecordCountPerPage()); List resultList = masterService.selectUserLoginHistory(params); int totalCnt = resultList.size() == 0 ? 0 : Integer.valueOf(((EgovMap) resultList.get(0)).get("totalrows").toString()); paginationInfo.setTotalRecordCount(totalCnt); model.addAttribute("params", params); model.addAttribute("resultList", resultList); model.addAttribute("paginationInfo", paginationInfo); return "admins/constructionProjectManagement/construction-user-login-history"; } public void buildExcelDocument(Map model, HSSFWorkbook workbook, HttpServletRequest request, HttpServletResponse response) throws Exception { List selectInfoListExcel = (List) model.get("selectInfoListExcel"); String[] arrHeader = (String[]) model.get("arrHeader"); Sheet sheet = workbook.createSheet((String) model.get("sheetName")); EgovExcel.SetExcelList(workbook, sheet, arrHeader, selectInfoListExcel, 0, 0); response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode((String) model.get("fileName") + (new SimpleDateFormat("yyyy.MM.dd", Locale.KOREA)).format(new Date()), "UTF-8") + ".xls" + ";"); ServletOutputStream myOut = response.getOutputStream(); workbook.write(myOut); // 파일 저장 } /** * 발주기관 건설현장 CSV 다운로드 처리 * @param workbook * @param request * @param response * @throws Exception */ @RequestMapping(value = "admins/constructionProjectManagement/excel.do") public void constructionProjectManagementExcel(HttpServletRequest request, HttpServletResponse response, HSSFWorkbook workbook, @RequestParam HashMap params) throws Exception { HashMap map = new HashMap(); String[] headers = {"num","userid","userName","companyName","datetime","note"}; String[] headerNames = {"번호", "아이디", "이름", "소속", "로그인일시", "로그인여부"}; final int[] headerWidths = {1325, 15900, 4240, 6360, 5830, 8830, 6890, 2915, 3710, 5035, 2915, 3710}; String[] columnType = {"String", "String", "String", "String", "String", "String"}; String sheetName = "발주기관 로그인 내역"; String excelFileName = "국토지반_발주기관_로그인_내역"; // int startIndex = 0; Long totalCount = 0L; // DB 조회 /** pageing */ PaginationInfo paginationInfo = new PaginationInfo(); if (params.get("pageIndex") == null || "".equals(params.get("pageIndex"))) { paginationInfo.setCurrentPageNo(1); params.put("pageIndex", 1); } else { paginationInfo.setCurrentPageNo(Integer.valueOf((String) params.get("pageIndex"))); } paginationInfo.setRecordCountPerPage(10); paginationInfo.setPageSize(10); params.put("firstRecordIndex", paginationInfo.getFirstRecordIndex()); params.put("recordCountPerPage", paginationInfo.getRecordCountPerPage()); List resultList = masterService.selectUserLoginHistory(params); int totalCnt = resultList.size() == 0 ? 0 : Integer.valueOf(((EgovMap) resultList.get(0)).get("totalrows").toString()); paginationInfo.setTotalRecordCount(totalCnt); ExcelMergeHeaderUtil.listToExcelMergeHeaderForLoginHistory(resultList, response, headers, headerNames, headerWidths, columnType, sheetName, excelFileName); } }