/**
* エクスポート処理
* @param daityouKbn
* @param form
* @param request
* @param response
* @param model
* @return
*/
@RequestMapping(value = "/export", method = RequestMethod.POST)
public String exportDaityouFile(@RequestParam("daityouKbn") String daityouKbn,TinputTableForm form,HttpServletRequest request, HttpServletResponse response, Model model) {
String resultStatus = null;
XSSFWorkbook wb = null;
FileInputStream fs = null;
// 基準値
Map<Integer, Object> criteriaMap;
// 分析要否マップ
Map<String, String> itemsMap;
TInputItemDto conditionDto = new TInputItemDto();
// 依頼書番号
conditionDto.setRequestNo(form.getRequestNo());
// 検査年度
conditionDto.setYear(form.getYear());
// 検査状況コード
conditionDto.setInspectionResult(form.getInspectionResult());
// 立入担当者コード
conditionDto.setInspectionStaff(form.getInspectionStaff());
// 調査区分コード
conditionDto.setExamClass(form.getExamClass());
// 分析区分コード
conditionDto.setAnalysisClass(form.getAnalysisClass());
// 措置コード
conditionDto.setTreatment(form.getTreatment());
// 分析期間初日
if (!StringUtils.isEmpty(form.getAnalysisFromString())) {
conditionDto.setAnalysisFrom(FormatUtil.strToDate(form.getAnalysisFromString(),SAMConst.DATE_FORMAT_YYYYMMDDE));
}
// 分析期間最終日
if (!StringUtils.isEmpty(form.getAnalysisToString())) {
conditionDto.setAnalysisTo(FormatUtil.strToDate(form.getAnalysisToString(),SAMConst.DATE_FORMAT_YYYYMMDDE));
}
// ページ情報
conditionDto.setiDisplayStart(form.getiDisplayStart());
conditionDto.setiDisplayLength(form.getiDisplayLength());
if ("4".equals(daityouKbn)) {
// 検索総件数
int resultCnt = tInputItemService.getInputItemListCount(conditionDto);
if (resultCnt < 1) {
return existCheckError();
}
// 検索
List<TInputItemDto> resultDtoList = tInputItemService.getInputItemList(conditionDto);
// 分析項目を取得
List<TInputItemDto> analyzeItemList = tInputItemService.getAnalyzeItem();
try {
// テンプレートパス
String templatePath = SAMBeans.getLedgerTemplatePath();
fs = new FileInputStream(templatePath + "analysis_dependence_format" + SAMConst.EXCEL_EXTENSION);
wb = new XSSFWorkbook(fs);
XSSFSheet sheet;
XSSFRow row;
String outputFileName = "分析依頼書";
// データシート
int i=0;
for (TInputItemDto resultDto : resultDtoList) {
sheet = wb.cloneSheet(0);
wb.setSheetName(++i, "分析依頼書"+SAMUtil.objToStr(resultDto.getInputItemId()));
// 依頼書番号
row = sheet.getRow(1);
XSSFCell cell = row.getCell(1);
ExcelUtil.setCellValue(cell, SAMUtil.objToStr(resultDto.getReportNo()));
// 試料番号
row = sheet.getRow(5);
cell = row.getCell(2);
ExcelUtil.setCellValue(cell, SAMUtil.objToStr(resultDto.getSampleNo()));
// 採水日時
row = sheet.getRow(6);
cell = row.getCell(2);
ExcelUtil.setCellValue(cell, SAMUtil.objToStr(FormatUtil.ImperialCalendarSample4(resultDto.getSamplingTime())));
// 時間
cell = row.getCell(6);
ExcelUtil.setCellValue(cell, SAMUtil.objToStr(FormatUtil.formatDateToTime(resultDto.getSamplingTime())));
// 天候
cell = row.getCell(8);
ExcelUtil.setCellValue(cell, SAMUtil.objToStr(resultDto.getWeatherName()));
// 採水場所
row = sheet.getRow(7);
cell = row.getCell(2);
ExcelUtil.setCellValue(cell, SAMUtil.objToStr(resultDto.getSamplingPlace()));
// 外観
row = sheet.getRow(9);
cell = row.getCell(0);
ExcelUtil.setCellValue(cell, SAMUtil.objToStr(1));
cell = row.getCell(6);
ExcelUtil.setCellValue(cell, SAMUtil.objToStr(resultDto.getAppearanceName()));
// 色
row = sheet.getRow(10);
cell = row.getCell(0);
ExcelUtil.setCellValue(cell, SAMUtil.objToStr(2));
// 臭気
row = sheet.getRow(11);
cell = row.getCell(0);
ExcelUtil.setCellValue(cell, SAMUtil.objToStr(3));
cell = row.getCell(6);
ExcelUtil.setCellValue(cell, SAMUtil.objToStr(resultDto.getOdorName()));
// 温度
row = sheet.getRow(12);
cell = row.getCell(0);
ExcelUtil.setCellValue(cell, SAMUtil.objToStr(4));
cell = row.getCell(6);
ExcelUtil.setCellValue(cell, SAMUtil.objToStr(""));
// 次ページをコピー
int index = 13;
// 基準値
criteriaMap = tJigyoujouService.getCriteria(resultDto.getJigyoujouId());
// 分析要否マップ
itemsMap = resultDto.getItemsMap();
for (TInputItemDto analyzeItem : analyzeItemList) {
row = sheet.createRow(index++);
ExcelUtil.copyRow(sheet, sheet.getRow(12), row, 1, true);
cell = ExcelUtil.getCell(row, 0);
ExcelUtil.setCellValue(cell, SAMUtil.objToStr(index-9));
// 項目
cell = ExcelUtil.getCell(row, 1);
ExcelUtil.setCellValue(cell, SAMUtil.objToStr(analyzeItem.getItemName()));
// 単位
cell = ExcelUtil.getCell(row, 4);
ExcelUtil.setCellValue(cell, SAMUtil.objToStr(analyzeItem.getUnitName()));
// 基準値
cell = ExcelUtil.getCell(row, 5);
ExcelUtil.setCellValue(cell, SAMUtil.objToStr(criteriaMap.get(analyzeItem.getAnalyzeItemId())));
// 分析項目
cell = ExcelUtil.getCell(row, 6);
if (itemsMap == null) {
ExcelUtil.setCellValue(cell, SAMUtil.objToStr(""));
}else {
String item="";
if ("1".equals(SAMUtil.objToStr(itemsMap.get(SAMUtil.objToStr(analyzeItem.getAnalyzeItemId()))))) {
item=SAMConst.INPUT_ITEM_ITEMS_NAME;
}
ExcelUtil.setCellValue(cell, item);
}
}
row = sheet.createRow(index++);
cell = ExcelUtil.getCell(row, 1);
ExcelUtil.setCellValue(cell, SAMUtil.objToStr("備 考"));
criteriaMap = null;
itemsMap = null;
cell = null;
row = null;
wb.setPrintArea(i-1, 0, 9, 0, index+2);
}
wb.removeSheetAt(0);
// ファイル出力
ExcelUtil.excelOutPut(wb, response, outputFileName);
} catch (Exception e) {
e.printStackTrace();
resultStatus = SAMConst.RESULT_ERROR;
} finally {
if (wb != null) {
try {
wb.close();
} catch (IOException e) {
// ignore
}
wb = null;
}
if (fs != null) {
try {
fs.close();
} catch (IOException e) {
// ignore
}
fs = null;
}
}
}
// 排他ロック解除
if(!unLock(SAMConst.ACCOUNT_EXPORT, super.getLoginUserId())){
// ロック解除処理
return deleteSuccess();
}
return resultStatus;
}