parent
5ccb79dc71
commit
6493413941
|
|
@ -1,10 +1,14 @@
|
|||
package geoinfo.drilling.inquiry;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
|
|
@ -21,6 +25,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import egovframework.rte.psl.dataaccess.util.EgovMap;
|
||||
import geoinfo.drilling.inquiry.service.DrillingInquiryService;
|
||||
import geoinfo.util.MyUtil;
|
||||
|
||||
|
|
@ -286,4 +291,89 @@ public class DrillingInquiryController {
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 발주기관 프로젝트 CSV 다운로드 처리
|
||||
* @param request
|
||||
* @param params
|
||||
* @param response
|
||||
* @throws Exception
|
||||
*/
|
||||
@RequestMapping(value = "/drilling/inquiry/csvDownload.do", method = RequestMethod.GET, produces = { "text/csv; charset=UTF-8" })
|
||||
@ResponseBody
|
||||
public void drillingInquiryCsvDownload (
|
||||
HttpServletRequest request,
|
||||
@RequestParam HashMap<String, Object> params,
|
||||
HttpServletResponse response
|
||||
) throws Exception {
|
||||
int startIndex = 0;
|
||||
Long totalCount = 0L;
|
||||
// DB 조회
|
||||
JSONObject resultObj = drillingInquiryService.drillingInquiryList(request, params);
|
||||
|
||||
// 여기에서 list 꺼내기
|
||||
List<EgovMap> list = (List<EgovMap>) resultObj.get("datas");
|
||||
totalCount = (Long) resultObj.get("count");
|
||||
// CSV 생성
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
// 헤더
|
||||
sb.append("연번,사업명,입력상태,사업기간,사업단계,담당부서,담당자,담당연락처,건설사명,건설사담당자,건설사연락처\n");
|
||||
|
||||
Long idx = 0L; // 연번계산
|
||||
// 바디
|
||||
for (EgovMap row : list) {
|
||||
long index = totalCount - (startIndex + idx);
|
||||
|
||||
sb.append(index).append(","); // ★ 연번 화면 동일하게 출력
|
||||
idx++;
|
||||
// sb.append(row.get("cid")).append(",");
|
||||
|
||||
sb.append(s(row.get("constName"))).append(",");
|
||||
sb.append(s(row.get("projectStateCodeName"))).append(",");
|
||||
|
||||
// 사업기간 constStartDate ~ constEndDate
|
||||
sb.append(s(row.get("constStartDate"))).append(" ~ ").append(s(row.get("constEndDate"))).append(",");
|
||||
|
||||
sb.append(s(row.get("constStateCodeName"))).append(",");
|
||||
sb.append(s(row.get("masterCompanyDept"))).append(",");
|
||||
sb.append(s(row.get("masterCompanyAdmin"))).append(",");
|
||||
sb.append(s(row.get("masterCompanyTel"))).append(",");
|
||||
sb.append(s(row.get("coinstCompanyDept"))).append(",");
|
||||
sb.append(s(row.get("constCompanyAdmin"))).append(",");
|
||||
sb.append(s(row.get("constCompanyTel"))).append("\n");
|
||||
}
|
||||
|
||||
byte[] csvBytes = sb.toString().getBytes("UTF-8");
|
||||
byte[] bom = new byte[] {(byte)0xEF, (byte)0xBB, (byte)0xBF};
|
||||
|
||||
// ---------- ★ 한글 파일명 브라우저별 처리 ----------
|
||||
String filename = "건설현장조회.csv";
|
||||
String userAgent = request.getHeader("User-Agent");
|
||||
String encodedFilename;
|
||||
|
||||
if (userAgent.contains("MSIE") || userAgent.contains("Trident")) {
|
||||
// IE 11 이하
|
||||
encodedFilename = URLEncoder.encode(filename, "UTF-8").replaceAll("\\+", "%20");
|
||||
} else if (userAgent.contains("Edge")) {
|
||||
// Edge (Chromium 의 이전 EdgeHTML 버전)
|
||||
encodedFilename = URLEncoder.encode(filename, "UTF-8");
|
||||
} else {
|
||||
// Chrome, Firefox, Safari, New Edge
|
||||
encodedFilename = "UTF-8''" + URLEncoder.encode(filename, "UTF-8");
|
||||
}
|
||||
// -------------------------------------------------
|
||||
response.setContentType("text/csv; charset=UTF-8");
|
||||
response.setHeader("Content-Disposition", "attachment; filename*=" + encodedFilename);
|
||||
response.setContentLength(bom.length + csvBytes.length);
|
||||
|
||||
OutputStream os = response.getOutputStream();
|
||||
os.write(bom); // 먼저 BOM 쓰기
|
||||
os.write(csvBytes); // 그 다음 CSV 내용
|
||||
os.flush();
|
||||
}
|
||||
|
||||
private String s(Object o) {
|
||||
return o == null ? "" : o.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ public class DrillingInquiryServiceImpl implements DrillingInquiryService {
|
|||
JSONObject jsonResponse = new JSONObject();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
String userId = MyUtil.getStringFromObject( request.getSession().getAttribute("USERID") );
|
||||
String excelDownload = MyUtil.getStringFromObject( params.get("excelDownload") );
|
||||
|
||||
if( userId == null){
|
||||
throw new Exception( "로그인이 필요한 서비스입니다." );
|
||||
|
|
@ -103,6 +104,9 @@ public class DrillingInquiryServiceImpl implements DrillingInquiryService {
|
|||
|
||||
|
||||
Long count = drillingInquiryMapper.sPCntTblCsiByKeyword(params);
|
||||
if ("Y".equals(excelDownload)) {
|
||||
params.put("nCount", count);
|
||||
}
|
||||
List<EgovMap> datas = drillingInquiryMapper.spGetTblCsiByKeyword(params);
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -403,6 +403,33 @@ if (request.getSession().getAttribute("CLS") == null || "2".equals(request.getSe
|
|||
|
||||
});
|
||||
|
||||
/**
|
||||
* 발주기관 목록화면 tr 드래그 시 상세화면 이동 방지처리
|
||||
* 드래그 이벤트와 클릭이벤트를 구분하여 감지한다.
|
||||
*/
|
||||
function clickExcelListDown() {
|
||||
const params = new URLSearchParams();
|
||||
|
||||
params.append("constTag", trim($('#const-tag').val()));
|
||||
params.append("constName", trim($('#const-name').val()));
|
||||
params.append("constStartDate", trim($('#const-start-date').val()));
|
||||
params.append("constEndDate", trim($('#const-end-date').val()));
|
||||
params.append("constStateCode", trim($('#const-state-code').val()));
|
||||
params.append("constCompanyName", trim($('#company-dept').val()));
|
||||
params.append("constCompanyAdmin", trim($('#company-admin').val()));
|
||||
params.append("constCompanyTel", trim($('#company-tel').val()));
|
||||
params.append("excelDownload", "Y");
|
||||
|
||||
// 페이지 정보
|
||||
const pagingEle = document.getElementById('paging');
|
||||
params.append("nPage", pagingEle.getAttribute("data-npage"));
|
||||
params.append("nCount", pagingEle.getAttribute("data-ncount"));
|
||||
|
||||
// AJAX가 아닌 직접 다운로드 요청
|
||||
window.location.href = "/drilling/inquiry/csvDownload.do?" + params.toString();
|
||||
$('#excelDownload').val("");
|
||||
}
|
||||
|
||||
/**
|
||||
* 발주기관 목록화면 tr 드래그 시 상세화면 이동 방지처리
|
||||
* 드래그 이벤트와 클릭이벤트를 구분하여 감지한다.
|
||||
|
|
@ -450,6 +477,7 @@ if (request.getSession().getAttribute("CLS") == null || "2".equals(request.getSe
|
|||
<div class="page-top-search">
|
||||
<form class="form-inline">
|
||||
<label class="input-label-display">검색</label>
|
||||
<input type="hidden" id="excelDownload" name="excelDownload" value="" >
|
||||
<input type="hidden" id="const-tag" name="const-tag" value="C" >
|
||||
<input type="search" id="const-name" name="const-name" class="input" placeholder="프로젝트명" title="" value="">
|
||||
<div id="suggestionList"></div>
|
||||
|
|
@ -479,7 +507,12 @@ if (request.getSession().getAttribute("CLS") == null || "2".equals(request.getSe
|
|||
</button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="table-info-group">Total: <span id="count">-</span>건</div>
|
||||
<div class="table-info-group display-flex" style="justify-content: space-between;">
|
||||
<div>
|
||||
<button class="btn-green btn-list-excel-download" type="button" id="excel-download-btn" onclick="javascript:clickExcelListDown();">CSV 다운로드</button>
|
||||
</div>
|
||||
<div>Total: <span id="count">-</span>건</div>
|
||||
</div>
|
||||
<div class="table-wrap">
|
||||
<table>
|
||||
<colgroup>
|
||||
|
|
|
|||
|
|
@ -6793,6 +6793,29 @@ ul.faq-q > li textarea {
|
|||
width: 26px;
|
||||
height: 26px;
|
||||
}
|
||||
.drilling .btn-list-excel-download {
|
||||
padding: 4px 14px 4px 46px;
|
||||
position: relative;
|
||||
font-size: 14px;
|
||||
height: 34px;
|
||||
font-weight: bold;
|
||||
box-sizing: border-box;
|
||||
background-color: #19b3e5;
|
||||
border: 1px solid #19b3e5;
|
||||
color: #fff;
|
||||
margin-right: 10px;
|
||||
}
|
||||
.drilling .btn-list-excel-download::before {
|
||||
display: inline-block;
|
||||
position: absolute;
|
||||
top: 3px;
|
||||
left: 12px;
|
||||
content: "";
|
||||
background: url(/com/img/common/icon/ico_btn_download_excel.png) no-repeat 50% 50%;
|
||||
background-size: contain;
|
||||
width: 26px;
|
||||
height: 26px;
|
||||
}
|
||||
.drilling .table-scrollable {
|
||||
border-top: 2px solid #114672;
|
||||
border-bottom: 1px solid #114672;
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -5143,6 +5143,29 @@ ul.faq-q > li textarea {
|
|||
height: 26px;
|
||||
}
|
||||
}
|
||||
.btn-list-excel-download {
|
||||
padding: 4px 14px 4px 46px;
|
||||
position: relative;
|
||||
font-size: 14px;
|
||||
height: 34px;
|
||||
font-weight: bold;
|
||||
box-sizing: border-box;
|
||||
background-color: #19b3e5;
|
||||
border:1px solid #19b3e5;
|
||||
color: #fff;
|
||||
margin-right: 10px;
|
||||
&::before {
|
||||
display: inline-block;
|
||||
position: absolute;
|
||||
top: 3px;
|
||||
left: 12px;
|
||||
content: "";
|
||||
background: url(/com/img/common/icon/ico_btn_download_excel.png) no-repeat 50% 50%;
|
||||
background-size: contain;
|
||||
width: 26px;
|
||||
height: 26px;
|
||||
}
|
||||
}
|
||||
.table-scrollable {
|
||||
border-top: 2px solid #114672;
|
||||
border-bottom: 1px solid #114672;
|
||||
|
|
|
|||
Loading…
Reference in New Issue