package geoinfo.admins.chLog;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.FilenameUtils;
import org.apache.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Sheet;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.util.FileCopyUtils;
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 com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import egovframework.com.cmm.service.EgovProperties;
import egovframework.rte.psl.dataaccess.util.EgovMap;
import egovframework.rte.ptl.mvc.tags.ui.pagination.PaginationInfo;
import geoinfo.admins.board.RefrncRoomController;
import geoinfo.admins.chLog.service.ChInfoService;
import geoinfo.com.EgovExcel;
import geoinfo.com.GeoinfoCommon;
import geoinfo.session.UserInfo;
/**
* 관리자시스템 > 유통/공급 통계분석 > 유통정보를 처리하는 Controller 클래스
*
* @author 공간정보기술(주)
* @since 2017.06.07
* @version 1.0
* @see
*
*
* << 개정이력(Modification Information) >>
*
* 수정일 수정자 수정내용
* ------------ ---------------- ---------------------------
* 2017.06.07 공간정보기술(주) 최초 생성
* 2023.11.01 ICTWAY 임효주 공종/공정/광역시도/시군구별 통계 추가
*
*
*/
@Controller
public class ChInfoController {
@Resource(name = "chInfoService")
private ChInfoService masterService;
private static final Logger LOGGER = Logger.getLogger(RefrncRoomController.class.getName());
// 운영서버 경로
// private final String savePath = "D:\\Tomcat6\\geoinfoEgov\\webapps\\geoinfo\\files";
// 개발서버 경로
private final String savePath = EgovProperties.getProperty("Geoinfo.FilePath");
/**
* 관리자시스템 > 유통/공급 통계분석 > 유통정보 > 날짜별 리스트
*
* @param params
* @param model
* @param response
* @param request
* @return
* @throws Exception
*/
@RequestMapping(value = "admins/chLog/00.do")
public String selectInfoListDate(@RequestParam HashMap params, ModelMap model, HttpServletResponse response, HttpServletRequest request) throws Exception {
if (!UserInfo.isValidSession(request, response, "admin")) {
return "";
}
List> getYear_date = masterService.getYear_date();
if ("".equals(params.get("year")) || params.get("year") == null) {
params.put("year", ((EgovMap) getYear_date.get(0)).get("value"));
}
List> getMonth_date = masterService.getMonth_date(params);
if ("".equals(params.get("month")) || params.get("month") == null || (getMonth_date.size() != 0 && getMonth_date.size() < Integer.valueOf((String) params.get("month")))) {
params.put("month", ((EgovMap) getMonth_date.get(0)).get("value"));
}
/** 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(20);
paginationInfo.setPageSize(10);
params.put("firstRecordIndex", paginationInfo.getFirstRecordIndex());
params.put("recordCountPerPage", paginationInfo.getRecordCountPerPage());
if (params.get("agreeyn") == null || "".equals(params.get("agreeyn"))) {
params.put("agreeyn", "0");
}
if (params.get("downyn") == null || "".equals(params.get("downyn"))) {
params.put("downyn", "0");
}
List> resultList = masterService.selectInfoListDate(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("getYear_date", getYear_date);
model.addAttribute("getMonth_date", getMonth_date);
model.addAttribute("resultList", resultList);
model.addAttribute("paginationInfo", paginationInfo);
return "admins/chLog/00";
}
/**
* 관리자시스템 > 유통/공급 통계분석 > 유통정보 > 날짜별 리스트 > 그래프
*
* @param params
* @param model
* @param response
* @param request
* @return
* @throws Exception
*/
@RequestMapping(value = "admins/chLog/00_graph.do")
public String selectInfoGraph(@RequestParam HashMap params, ModelMap model, HttpServletResponse response, HttpServletRequest request) throws Exception {
if (!UserInfo.isValidSession(request, response, "admin")) {
return "";
}
List> getYear_date = masterService.getYear_date();
if ("".equals(params.get("year")) || params.get("year") == null) {
params.put("year", ((EgovMap) getYear_date.get(0)).get("value"));
}
List> getMonth_date = masterService.getMonth_date(params);
if ("".equals(params.get("month")) || params.get("month") == null || (getMonth_date.size() != 0 && getMonth_date.size() < Integer.valueOf((String) params.get("month")))) {
params.put("month", ((EgovMap) getMonth_date.get(0)).get("value"));
}
EgovMap result = masterService.selectInfoGraph(params);
model.addAttribute("params", params);
model.addAttribute("getYear_date", getYear_date);
model.addAttribute("getMonth_date", getMonth_date);
model.addAttribute("result", result);
return "admins/chLog/00_graph";
}
/**
* 관리자시스템 > 유통/공급 통계분석 > 유통정보 > 날짜별 리스트 엑셀 다운로드
*
* @param params
* @param workbook
* @param request
* @param response
* @throws Exception
*/
@RequestMapping(value = "admins/chLog/00_excel.do")
public void selectInfoListDateExcel(@RequestParam HashMap params, HSSFWorkbook workbook, HttpServletRequest request, HttpServletResponse response)
throws Exception {
HashMap map = new HashMap();
List> selectInfoListExcel = masterService.selectInfoListDateExcel(params);
String[] arrHeader = { "번호", "사업명", "다운로드 수" };
map.put("selectInfoListExcel", selectInfoListExcel);
map.put("arrHeader", arrHeader);
map.put("sheetName", "날짜별 유통정보");
map.put("fileName", "날짜별유통정보_");
buildExcelDocument(map, workbook, request, response);
}
/**
* 관리자시스템 > 유통/공급 통계분석 > 유통정보 > 사업별 리스트
*
* @param params
* @param model
* @param response
* @param request
* @return
* @throws Exception
*/
@RequestMapping(value = "admins/chLog/01.do")
public String selectInfoListBusiness(@RequestParam HashMap params, ModelMap model, HttpServletResponse response, HttpServletRequest request) throws Exception {
if (!UserInfo.isValidSession(request, response, "admin")) {
return "";
}
/** 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(20);
paginationInfo.setPageSize(10);
params.put("firstRecordIndex", paginationInfo.getFirstRecordIndex());
params.put("recordCountPerPage", paginationInfo.getRecordCountPerPage());
List> resultList = masterService.selectInfoListBusiness(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/chLog/01";
}
/**
* 관리자시스템 > 유통/공급 통계분석 > 유통정보 > 사업별 리스트 엑셀 다운로드
*
* @param params
* @param workbook
* @param request
* @param response
* @throws Exception
*/
@RequestMapping(value = "admins/chLog/01_excel.do")
public void selectInfoListBusinessExcel(@RequestParam HashMap params, HSSFWorkbook workbook, HttpServletRequest request, HttpServletResponse response)
throws Exception {
HashMap map = new HashMap();
List> selectInfoListExcel = masterService.selectInfoListBusinessExcel(params);
String[] arrHeader = { "번호", "사업명", "다운로드 수" };
map.put("selectInfoListExcel", selectInfoListExcel);
map.put("arrHeader", arrHeader);
map.put("sheetName", "사업별 유통정보");
map.put("fileName", "사업별유통정보_");
buildExcelDocument(map, workbook, request, response);
}
/**
* 관리자시스템 > 유통/공급 통계분석 > 유통정보 > 다운로드 로그정보 팝업
*
* @param params
* @param model
* @param response
* @param request
* @return
* @throws Exception
*/
@RequestMapping(value = "admins/chLog/download_view.do")
public String selectInfoListDateLogPop(@RequestParam HashMap params, ModelMap model, HttpServletResponse response, HttpServletRequest request)
throws Exception {
if (!UserInfo.isValidSession(request, response, "admin")) {
return "";
}
/** 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(6);
paginationInfo.setPageSize(10);
params.put("firstRecordIndex", paginationInfo.getFirstRecordIndex());
params.put("recordCountPerPage", paginationInfo.getRecordCountPerPage());
List> resultList = masterService.selectInfoListDateLogPop(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/chLog/download_view";
}
@RequestMapping(value = "admins/chLog/03.do")
public String selectInfoListPurpose(ModelMap model, HttpServletResponse response, HttpServletRequest request) throws Exception {
if (!UserInfo.isValidSession(request, response, "admin")) {
return "";
}
List> resultList = masterService.selectInfoListPurpose();
model.addAttribute("resultList", resultList);
return "admins/chLog/03";
}
@RequestMapping(value = "admins/chLog/03_excel.do")
public void selectInfoListPurposeExcel(HSSFWorkbook workbook, HttpServletRequest request, HttpServletResponse response) throws Exception {
HashMap map = new HashMap();
List> selectInfoListExcel = masterService.selectInfoListPurpose();
String[] arrHeader = { "년도", "정책입안", "학술연구", "공사계획 및 예비조사", "기본설계", "실시설계", "시공 및 유지관리", "사업비산정", "지하시설물 유지관리",
"스마트시티","도시재생","지진 예방","산사태 예방","급경사지 관리","홍수 예방","지하안전영향평가","소규모지하안전영향평가","사후지하안전영향조사","지반침하위험도평가","지하안전점검",
"기타", "검수", "총계" };
map.put("selectInfoListExcel", selectInfoListExcel);
map.put("arrHeader", arrHeader);
map.put("sheetName", "목적별 유통정보");
map.put("fileName", "목적별유통정보_");
buildExcelDocument(map, workbook, request, response);
}
/**
* 2023.11.01 LHJ 공종별 시추공등록 통계 추가
* 2023.11.01 LHJ 유통/공급 통계분석 > 유통정보 > 공종별 리스트
*
* @param model
* @param response
* @param request
* @return
* @throws Exception
*/
@RequestMapping(value = "admins/chLog/11.do")
public String selectInfoListGongjong(ModelMap model, HttpServletResponse response, HttpServletRequest request) throws Exception {
if (!UserInfo.isValidSession(request, response, "admin")) {
return "";
}
List