PatientStatistics.java 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. package com.lemon.lifecenter.controller;
  2. import java.io.ByteArrayInputStream;
  3. import java.io.ByteArrayOutputStream;
  4. import java.io.File;
  5. import java.io.FileNotFoundException;
  6. import java.io.FileOutputStream;
  7. import java.io.IOException;
  8. import java.io.InputStream;
  9. import java.security.GeneralSecurityException;
  10. import java.text.DecimalFormat;
  11. import java.util.ArrayList;
  12. import java.util.List;
  13. import javax.servlet.http.HttpServletRequest;
  14. import javax.servlet.http.HttpServletResponse;
  15. import org.apache.poi.hssf.usermodel.HSSFCellStyle;
  16. import org.apache.poi.hssf.usermodel.HSSFDataFormat;
  17. import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
  18. import org.apache.poi.openxml4j.opc.OPCPackage;
  19. import org.apache.poi.poifs.crypt.EncryptionInfo;
  20. import org.apache.poi.poifs.crypt.EncryptionMode;
  21. import org.apache.poi.poifs.crypt.Encryptor;
  22. import org.apache.poi.poifs.filesystem.POIFSFileSystem;
  23. import org.apache.poi.ss.usermodel.Cell;
  24. import org.apache.poi.ss.usermodel.CellStyle;
  25. import org.apache.poi.ss.usermodel.Font;
  26. import org.apache.poi.ss.usermodel.IndexedColors;
  27. import org.apache.poi.ss.usermodel.Row;
  28. import org.apache.poi.ss.usermodel.Sheet;
  29. import org.apache.poi.ss.usermodel.Workbook;
  30. import org.apache.poi.ss.util.CellRangeAddress;
  31. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  32. import org.springframework.beans.factory.annotation.Autowired;
  33. import org.springframework.stereotype.Controller;
  34. import org.springframework.web.bind.annotation.RequestMapping;
  35. import org.springframework.web.bind.annotation.RequestParam;
  36. import org.springframework.web.servlet.ModelAndView;
  37. import com.lemon.lifecenter.common.LifeCenterConfigVO;
  38. import com.lemon.lifecenter.common.LifeCenterController;
  39. import com.lemon.lifecenter.common.LifeCenterFileDownload;
  40. import com.lemon.lifecenter.common.LifeCenterFunction;
  41. import com.lemon.lifecenter.common.LifeCenterPaging;
  42. import com.lemon.lifecenter.common.LifeCenterSessionController;
  43. import com.lemon.lifecenter.dto.LocationDTO;
  44. import com.lemon.lifecenter.dto.PatientDTO;
  45. import com.lemon.lifecenter.service.CenterService;
  46. import com.lemon.lifecenter.service.PatientService;
  47. @Controller
  48. @RequestMapping( "/statistics/patient" )
  49. public class PatientStatistics extends LifeCenterController {
  50. @Autowired
  51. private CenterService centerService;
  52. @Autowired
  53. private LifeCenterConfigVO config;
  54. @Autowired
  55. private PatientService patientService;
  56. private LifeCenterPaging paging;
  57. @RequestMapping( "/list" )
  58. public ModelAndView list(
  59. @RequestParam(value="page", required=false, defaultValue="1") int page,
  60. @RequestParam(value="q", required=false, defaultValue="") String q,
  61. @RequestParam(value="locationCode", required=false, defaultValue="") String locationCode,
  62. @RequestParam(value="startDate", required=false, defaultValue="") String startDate,
  63. @RequestParam(value="endDate", required=false, defaultValue="") String endDate,
  64. @RequestParam(value="registDay", required=false, defaultValue="") String inputRegistDay,
  65. @RequestParam(value="v", required=false, defaultValue="") String v ) {
  66. //일자별 통계
  67. if( v.equals( "day" ) ) {
  68. PatientDTO dto = new PatientDTO();
  69. if( endDate.equals( "" ) ) {
  70. endDate = LifeCenterFunction.getNow( "yyyy-MM-dd" );
  71. }
  72. if( startDate.equals( "" ) ) {
  73. //기록상 최초 환자 입소일 이후부터 계산
  74. startDate = "2020-11-23";
  75. }
  76. dto.setLimit( ( Integer.valueOf( page ) - 1 ) * config.pageDataSize );
  77. dto.setLimitMax( config.pageDataSize );
  78. dto.setQ(q);
  79. dto.setLocationCode(locationCode);
  80. dto.setStartDate(startDate);
  81. dto.setEndDate(endDate);
  82. List<LocationDTO> locationList = centerService.selectLocation();
  83. int total = patientService.selectStatisticsPatientCount(dto);
  84. List<PatientDTO> statisticsList = patientService.selectStatisticsPatientList(dto);
  85. PatientDTO statisticsSum = patientService.selectStatisticsPatientSum(dto);
  86. String param = "q=" + q + "&locationCode=" + locationCode + "&startDate=" + startDate + "&endDate=" + endDate + "&v=day";
  87. paging = LifeCenterPaging.getInstance();
  88. paging.paging(config, total, page, param);
  89. ModelAndView mv = setMV("statistics/list2");
  90. mv.addObject( "q" , q );
  91. mv.addObject( "statisticsList" , statisticsList );
  92. mv.addObject( "statisticsSum" , statisticsSum );
  93. mv.addObject( "locationList", locationList );
  94. mv.addObject( "locationCode", locationCode );
  95. mv.addObject( "startDate", startDate);
  96. mv.addObject( "endDate", endDate);
  97. mv.addObject( "total", total);
  98. mv.addObject( "paging", paging );
  99. mv.addObject( "page", page );
  100. mv.addObject( "pageSize", dto.getLimitMax() );
  101. return mv;
  102. } else {
  103. String registDayTime = "";
  104. //센터별 통계
  105. PatientDTO dto = new PatientDTO();
  106. dto.setLimit( ( Integer.valueOf( page ) - 1 ) * config.pageDataSize );
  107. dto.setLimitMax( config.pageDataSize );
  108. dto.setQ(q);
  109. dto.setLocationCode(locationCode);
  110. if (inputRegistDay.isEmpty()) {
  111. inputRegistDay = LifeCenterFunction.getNow("yyyy-MM-dd");
  112. }
  113. if( inputRegistDay.equals( LifeCenterFunction.getNow("yyyy-MM-dd") ) ) {
  114. dto.setRegistDayTime( inputRegistDay + " " + LifeCenterFunction.getNow("hh:mm") );
  115. } else {
  116. dto.setRegistDayTime( inputRegistDay + " 00:00" );
  117. }
  118. dto.setRegistDay(inputRegistDay);
  119. registDayTime = dto.getRegistDayTime();
  120. List<LocationDTO> locationList = centerService.selectLocation();
  121. int total = patientService.selectStatisticsPatientByCenterCount(dto);
  122. List<PatientDTO> statisticsList = new ArrayList<PatientDTO>();
  123. if( total > 0 ) {
  124. statisticsList = patientService.selectStatisticsPatientByCenterList(dto);
  125. }
  126. String param = "locationCode="+locationCode+"&q="+q+"&registDay="+inputRegistDay;
  127. paging = LifeCenterPaging.getInstance();
  128. paging.paging(config, total, page, param);
  129. ModelAndView mv = setMV("statistics/list");
  130. mv.addObject( "q" , q );
  131. mv.addObject( "statisticsList" , statisticsList );
  132. mv.addObject( "locationList", locationList );
  133. mv.addObject( "locationCode", locationCode );
  134. mv.addObject( "registDay", inputRegistDay );
  135. mv.addObject( "registDayTime", registDayTime );
  136. mv.addObject( "total", total);
  137. mv.addObject( "paging", paging );
  138. mv.addObject( "page", page );
  139. mv.addObject( "pageSize", dto.getLimitMax() );
  140. return mv;
  141. }
  142. }
  143. @RequestMapping( "/excel" )
  144. public void excel(
  145. HttpServletRequest request, HttpServletResponse response,
  146. @RequestParam(value="page", required=false, defaultValue="1") int page,
  147. @RequestParam(value="q", required=false, defaultValue="") String q,
  148. @RequestParam(value="locationCode", required=false, defaultValue="") String locationCode,
  149. @RequestParam(value="startDate", required=false, defaultValue="") String startDate,
  150. @RequestParam(value="endDate", required=false, defaultValue="") String endDate,
  151. @RequestParam(value="registDay", required=false, defaultValue="") String inputRegistDay,
  152. @RequestParam(value="v", required=false, defaultValue="") String v ) {
  153. // 일자별 통계
  154. if( v.equals( "day" ) ) {
  155. PatientDTO dto = new PatientDTO();
  156. if( endDate.equals( "" ) ) {
  157. endDate = LifeCenterFunction.getNow( "yyyy-MM-dd" );
  158. }
  159. if( startDate.equals( "" ) ) {
  160. //기록상 최초 환자 입소일 이후부터 계산
  161. startDate = "2020-11-23";
  162. }
  163. dto.setQ(q);
  164. dto.setLocationCode(locationCode);
  165. dto.setStartDate(startDate);
  166. dto.setEndDate(endDate);
  167. int total = patientService.selectStatisticsPatientCount(dto);
  168. dto.setLimit( 0 );
  169. dto.setLimitMax( total );
  170. List<PatientDTO> statisticsList = patientService.selectStatisticsPatientList(dto);
  171. PatientDTO statisticsSum = patientService.selectStatisticsPatientSum(dto);
  172. getStatisticsPatientExcel(request, response, statisticsList, statisticsSum);
  173. } else {
  174. //센터별 통계
  175. PatientDTO dto = new PatientDTO();
  176. dto.setQ(q);
  177. dto.setLocationCode(locationCode);
  178. if (inputRegistDay.isEmpty()) {
  179. inputRegistDay = LifeCenterFunction.getNow("yyyy-MM-dd");
  180. }
  181. if( inputRegistDay.equals( LifeCenterFunction.getNow("yyyy-MM-dd") ) ) {
  182. dto.setRegistDayTime( inputRegistDay + " " + LifeCenterFunction.getNow("hh:mm") );
  183. } else {
  184. dto.setRegistDayTime( inputRegistDay + " 00:00" );
  185. }
  186. dto.setRegistDay(inputRegistDay);
  187. List<LocationDTO> locationList = centerService.selectLocation();
  188. int total = patientService.selectStatisticsPatientByCenterCount(dto);
  189. List<PatientDTO> statisticsList = new ArrayList<PatientDTO>();
  190. dto.setLimit( 0 );
  191. dto.setLimitMax( total );
  192. if( total > 0 ) {
  193. statisticsList = patientService.selectStatisticsPatientByCenterList(dto);
  194. }
  195. getStatisticsPatientByCenterExcel(request, response, statisticsList, inputRegistDay );
  196. }
  197. }
  198. private void getStatisticsPatientByCenterExcel(HttpServletRequest request, HttpServletResponse response, List<PatientDTO> data, String registDay ) {
  199. String password = LifeCenterSessionController.getSession(request, "sesPhoneNumber");
  200. password = password.toLowerCase();
  201. if (!password.equals("null") && !password.equals( "" )) {
  202. password = password.replace("-", "");
  203. password = password.substring(3).trim();
  204. } else {
  205. password = "";
  206. }
  207. Workbook workbook = new XSSFWorkbook();
  208. Sheet sheet1 = workbook.createSheet("firstSheet");
  209. DecimalFormat df = new DecimalFormat("#,###");
  210. //1.셀 스타일 및 폰트 설정
  211. CellStyle styleOfBoardFillFontBlackBold16 = workbook.createCellStyle();
  212. //정렬
  213. styleOfBoardFillFontBlackBold16.setAlignment(CellStyle.ALIGN_CENTER); //가운데 정렬
  214. styleOfBoardFillFontBlackBold16.setVerticalAlignment(CellStyle.VERTICAL_CENTER); //높이 가운데 정렬
  215. //배경색
  216. styleOfBoardFillFontBlackBold16.setFillForegroundColor(IndexedColors.LIGHT_YELLOW.getIndex());
  217. styleOfBoardFillFontBlackBold16.setFillPattern(CellStyle.SOLID_FOREGROUND);
  218. //테두리 선 (우,좌,위,아래)
  219. styleOfBoardFillFontBlackBold16.setBorderRight(HSSFCellStyle.BORDER_THIN);
  220. styleOfBoardFillFontBlackBold16.setBorderLeft(HSSFCellStyle.BORDER_THIN);
  221. styleOfBoardFillFontBlackBold16.setBorderTop(HSSFCellStyle.BORDER_THIN);
  222. styleOfBoardFillFontBlackBold16.setBorderBottom(HSSFCellStyle.BORDER_THIN);
  223. //폰트 설정
  224. Font fontOfGothicBlackBold16 = workbook.createFont();
  225. // fontOfGothicBlackBold16.setFontName("나눔고딕"); //글씨체
  226. fontOfGothicBlackBold16.setFontHeight((short)(10*20)); //사이즈
  227. fontOfGothicBlackBold16.setBoldweight(Font.BOLDWEIGHT_BOLD); //볼드 (굵게)
  228. styleOfBoardFillFontBlackBold16.setFont(fontOfGothicBlackBold16);
  229. styleOfBoardFillFontBlackBold16.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0"));
  230. int i = 1;
  231. // th영역
  232. Row row = sheet1.createRow(0);
  233. Cell cell1 = row.createCell(0);
  234. Cell cell2 = row.createCell(1);
  235. Cell cell3 = row.createCell(2);
  236. Cell cell4 = row.createCell(3);
  237. Cell cell5 = row.createCell(4);
  238. Cell cell6 = row.createCell(5);
  239. Cell cell7 = row.createCell(6);
  240. cell1.setCellStyle(styleOfBoardFillFontBlackBold16);
  241. cell2.setCellStyle(styleOfBoardFillFontBlackBold16);
  242. cell3.setCellStyle(styleOfBoardFillFontBlackBold16);
  243. cell4.setCellStyle(styleOfBoardFillFontBlackBold16);
  244. cell5.setCellStyle(styleOfBoardFillFontBlackBold16);
  245. cell6.setCellStyle(styleOfBoardFillFontBlackBold16);
  246. cell7.setCellStyle(styleOfBoardFillFontBlackBold16);
  247. sheet1.setColumnWidth( 0, 10000); //생활치료센터명
  248. sheet1.setColumnWidth( 1, 6000); //소관
  249. sheet1.setColumnWidth( 2, 6000); //환자인원
  250. sheet1.setColumnWidth( 3, 6000); //입소
  251. sheet1.setColumnWidth( 4, 9000); //퇴실소계
  252. sheet1.setColumnWidth( 5, 6000); //퇴소
  253. sheet1.setColumnWidth( 6, 6000); //지정병원이송
  254. cell1.setCellValue("생활치료센터명");
  255. sheet1.addMergedRegion(new CellRangeAddress(0,1,0,0));
  256. cell2.setCellValue("소관");
  257. sheet1.addMergedRegion(new CellRangeAddress(0,1,1,1));
  258. cell3.setCellValue("환자인원");
  259. sheet1.addMergedRegion(new CellRangeAddress(0,1,2,2));
  260. cell4.setCellValue("입소");
  261. sheet1.addMergedRegion(new CellRangeAddress(0,1,3,3));
  262. cell5.setCellValue("퇴실소계 (퇴소 + 지정병원이송)");
  263. sheet1.addMergedRegion(new CellRangeAddress(0,1,4,4));
  264. cell6.setCellValue("퇴실");
  265. sheet1.addMergedRegion(new CellRangeAddress(0,0,5,6));
  266. row = sheet1.createRow(i);
  267. cell1 = row.createCell(0);
  268. cell2 = row.createCell(1);
  269. cell3 = row.createCell(2);
  270. cell4 = row.createCell(3);
  271. cell5 = row.createCell(4);
  272. cell6 = row.createCell(5);
  273. cell7 = row.createCell(6);
  274. cell1.setCellStyle(styleOfBoardFillFontBlackBold16);
  275. cell2.setCellStyle(styleOfBoardFillFontBlackBold16);
  276. cell3.setCellStyle(styleOfBoardFillFontBlackBold16);
  277. cell4.setCellStyle(styleOfBoardFillFontBlackBold16);
  278. cell5.setCellStyle(styleOfBoardFillFontBlackBold16);
  279. cell6.setCellStyle(styleOfBoardFillFontBlackBold16);
  280. cell7.setCellStyle(styleOfBoardFillFontBlackBold16);
  281. cell6.setCellValue( "퇴소" );
  282. cell7.setCellValue( "지정병원이송" );
  283. i++;
  284. // th영역 끝
  285. CellStyle styleOfBoardFillFontBlackBold17 = workbook.createCellStyle();
  286. CellStyle styleOfBoardFillFontBlackBold18 = workbook.createCellStyle();
  287. CellStyle styleOfBoardFillFontBlackBold19 = workbook.createCellStyle();
  288. Font fontOfGothicBlackBold17 = workbook.createFont();
  289. Font fontOfGothicBlackBold18 = workbook.createFont();
  290. Font fontOfGothicBlackBold19 = workbook.createFont();
  291. fontOfGothicBlackBold17.setFontName("맑은 고딕"); //글씨체
  292. fontOfGothicBlackBold18.setFontName("맑은 고딕"); //글씨체
  293. fontOfGothicBlackBold19.setFontName("맑은 고딕"); //글씨체
  294. fontOfGothicBlackBold17.setBoldweight(Font.BOLDWEIGHT_BOLD); //볼드 (굵게)
  295. styleOfBoardFillFontBlackBold17.setFont(fontOfGothicBlackBold17);
  296. styleOfBoardFillFontBlackBold17.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0"));
  297. styleOfBoardFillFontBlackBold18.setFont(fontOfGothicBlackBold18);
  298. styleOfBoardFillFontBlackBold19.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0"));
  299. for (PatientDTO dto : data) {
  300. // 센터별 통계 row
  301. row = sheet1.createRow(i);
  302. cell1 = row.createCell(0);
  303. cell2 = row.createCell(1);
  304. cell3 = row.createCell(2);
  305. cell4 = row.createCell(3);
  306. cell5 = row.createCell(4);
  307. cell6 = row.createCell(5);
  308. cell7 = row.createCell(6);
  309. styleOfBoardFillFontBlackBold17.setAlignment(CellStyle.ALIGN_RIGHT);
  310. cell1.setCellStyle(styleOfBoardFillFontBlackBold18);
  311. cell2.setCellStyle(styleOfBoardFillFontBlackBold19);
  312. cell3.setCellStyle(styleOfBoardFillFontBlackBold17);
  313. cell4.setCellStyle(styleOfBoardFillFontBlackBold17);
  314. cell5.setCellStyle(styleOfBoardFillFontBlackBold19);
  315. cell6.setCellStyle(styleOfBoardFillFontBlackBold19);
  316. cell7.setCellStyle(styleOfBoardFillFontBlackBold19);
  317. cell1.setCellValue( dto.getCenterName() );
  318. cell2.setCellValue( dto.getJurisdictionName() );
  319. cell3.setCellValue( dto.gethTotal() + dto.getdTotal() + dto.gettTotal() );
  320. cell4.setCellValue( dto.gethTotal() );
  321. cell5.setCellValue( dto.getdTotal() + dto.gettTotal() );
  322. cell6.setCellValue( dto.getdTotal() );
  323. cell7.setCellValue( dto.gettTotal() );
  324. i++;
  325. }
  326. row = sheet1.createRow(i);
  327. cell1 = row.createCell(2);
  328. cell2 = row.createCell(3);
  329. cell3 = row.createCell(4);
  330. cell4 = row.createCell(5);
  331. cell5 = row.createCell(6);
  332. cell6 = row.createCell(7);
  333. cell7 = row.createCell(7);
  334. try {
  335. // JBOSS에서 구동시 /home1/jboss/jboss-eap-7.3/domain/test/excel-temp 경로에 저장이됨
  336. String tempPath = "../excel-temp/testExcel.xlsx";
  337. String downName = LifeCenterFunction.getNow() + "_["+registDay+"] 환자입퇴소통계.xlsx";
  338. File xlsFile = new File(tempPath);
  339. ByteArrayOutputStream fileOut = new ByteArrayOutputStream();
  340. FileOutputStream fos = new FileOutputStream(tempPath);
  341. workbook.write(fileOut);
  342. InputStream filein = new ByteArrayInputStream(fileOut.toByteArray());
  343. OPCPackage opc = OPCPackage.open(filein);
  344. POIFSFileSystem fileSystem = new POIFSFileSystem();
  345. EncryptionInfo encryptionInfo = new EncryptionInfo(EncryptionMode.agile);
  346. Encryptor encryptor = encryptionInfo.getEncryptor();
  347. encryptor.confirmPassword(password);
  348. opc.save(encryptor.getDataStream(fileSystem));
  349. opc.flush();
  350. fileSystem.writeFilesystem(fos);
  351. fileOut.close();
  352. opc.close();
  353. filein.close();
  354. fileSystem.close();
  355. LifeCenterFileDownload.download(request, response, tempPath, downName);
  356. xlsFile.delete();
  357. } catch (FileNotFoundException e) {
  358. e.printStackTrace();
  359. } catch (IOException e) {
  360. e.printStackTrace();
  361. } catch (InvalidFormatException e) {
  362. // TODO Auto-generated catch block
  363. e.printStackTrace();
  364. } catch (GeneralSecurityException e) {
  365. // TODO Auto-generated catch block
  366. e.printStackTrace();
  367. }
  368. }
  369. private void getStatisticsPatientExcel(HttpServletRequest request, HttpServletResponse response, List<PatientDTO> data, PatientDTO sum ) {
  370. String password = LifeCenterSessionController.getSession(request, "sesPhoneNumber");
  371. password = password.toLowerCase();
  372. if (!password.equals("null") && !password.equals( "" )) {
  373. password = password.replace("-", "");
  374. password = password.substring(3).trim();
  375. } else {
  376. password = "";
  377. }
  378. Workbook workbook = new XSSFWorkbook();
  379. Sheet sheet1 = workbook.createSheet("firstSheet");
  380. DecimalFormat df = new DecimalFormat("#,###");
  381. //1.셀 스타일 및 폰트 설정
  382. CellStyle styleOfBoardFillFontBlackBold16 = workbook.createCellStyle();
  383. //정렬
  384. styleOfBoardFillFontBlackBold16.setAlignment(CellStyle.ALIGN_CENTER); //가운데 정렬
  385. styleOfBoardFillFontBlackBold16.setVerticalAlignment(CellStyle.VERTICAL_CENTER); //높이 가운데 정렬
  386. //배경색
  387. styleOfBoardFillFontBlackBold16.setFillForegroundColor(IndexedColors.LIGHT_YELLOW.getIndex());
  388. styleOfBoardFillFontBlackBold16.setFillPattern(CellStyle.SOLID_FOREGROUND);
  389. //테두리 선 (우,좌,위,아래)
  390. styleOfBoardFillFontBlackBold16.setBorderRight(HSSFCellStyle.BORDER_THIN);
  391. styleOfBoardFillFontBlackBold16.setBorderLeft(HSSFCellStyle.BORDER_THIN);
  392. styleOfBoardFillFontBlackBold16.setBorderTop(HSSFCellStyle.BORDER_THIN);
  393. styleOfBoardFillFontBlackBold16.setBorderBottom(HSSFCellStyle.BORDER_THIN);
  394. //폰트 설정
  395. Font fontOfGothicBlackBold16 = workbook.createFont();
  396. // fontOfGothicBlackBold16.setFontName("나눔고딕"); //글씨체
  397. fontOfGothicBlackBold16.setFontHeight((short)(10*20)); //사이즈
  398. fontOfGothicBlackBold16.setBoldweight(Font.BOLDWEIGHT_BOLD); //볼드 (굵게)
  399. styleOfBoardFillFontBlackBold16.setFont(fontOfGothicBlackBold16);
  400. styleOfBoardFillFontBlackBold16.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0"));
  401. int i = 1;
  402. // th영역
  403. Row row = sheet1.createRow(0);
  404. Cell cell1 = row.createCell(0);
  405. Cell cell2 = row.createCell(1);
  406. Cell cell3 = row.createCell(2);
  407. Cell cell4 = row.createCell(3);
  408. Cell cell5 = row.createCell(4);
  409. Cell cell6 = row.createCell(5);
  410. cell1.setCellStyle(styleOfBoardFillFontBlackBold16);
  411. cell2.setCellStyle(styleOfBoardFillFontBlackBold16);
  412. cell3.setCellStyle(styleOfBoardFillFontBlackBold16);
  413. cell4.setCellStyle(styleOfBoardFillFontBlackBold16);
  414. cell5.setCellStyle(styleOfBoardFillFontBlackBold16);
  415. cell6.setCellStyle(styleOfBoardFillFontBlackBold16);
  416. sheet1.setColumnWidth( 0, 5000); //날짜
  417. sheet1.setColumnWidth( 1, 6000); //환자인원
  418. sheet1.setColumnWidth( 2, 6000); //입소
  419. sheet1.setColumnWidth( 3, 8000); //퇴실소계
  420. sheet1.setColumnWidth( 4, 6000); //퇴소
  421. sheet1.setColumnWidth( 5, 6000); //지정병원 이송
  422. cell1.setCellValue("날짜");
  423. sheet1.addMergedRegion(new CellRangeAddress(0,1,0,0));
  424. cell2.setCellValue("환자인원");
  425. sheet1.addMergedRegion(new CellRangeAddress(0,1,1,1));
  426. cell3.setCellValue("입소");
  427. sheet1.addMergedRegion(new CellRangeAddress(0,1,2,2));
  428. cell4.setCellValue("퇴실소계 (퇴소 + 지정병원이송)");
  429. sheet1.addMergedRegion(new CellRangeAddress(0,1,3,3));
  430. cell5.setCellValue("퇴실");
  431. sheet1.addMergedRegion(new CellRangeAddress(0,0,4,5));
  432. row = sheet1.createRow(i);
  433. cell1 = row.createCell(0);
  434. cell2 = row.createCell(1);
  435. cell3 = row.createCell(2);
  436. cell4 = row.createCell(3);
  437. cell5 = row.createCell(4);
  438. cell6 = row.createCell(5);
  439. cell1.setCellStyle(styleOfBoardFillFontBlackBold16);
  440. cell2.setCellStyle(styleOfBoardFillFontBlackBold16);
  441. cell3.setCellStyle(styleOfBoardFillFontBlackBold16);
  442. cell4.setCellStyle(styleOfBoardFillFontBlackBold16);
  443. cell5.setCellStyle(styleOfBoardFillFontBlackBold16);
  444. cell6.setCellStyle(styleOfBoardFillFontBlackBold16);
  445. cell5.setCellValue( "퇴소" );
  446. cell6.setCellValue( "지정병원이송" );
  447. i++;
  448. // th영역 끝
  449. // 누적 row
  450. CellStyle styleOfBoardFillFontBlackBold17 = workbook.createCellStyle();
  451. CellStyle styleOfBoardFillFontBlackBold18 = workbook.createCellStyle();
  452. CellStyle styleOfBoardFillFontBlackBold19 = workbook.createCellStyle();
  453. Font fontOfGothicBlackBold17 = workbook.createFont();
  454. Font fontOfGothicBlackBold18 = workbook.createFont();
  455. Font fontOfGothicBlackBold19 = workbook.createFont();
  456. fontOfGothicBlackBold17.setFontName("맑은 고딕"); //글씨체
  457. fontOfGothicBlackBold18.setFontName("맑은 고딕"); //글씨체
  458. fontOfGothicBlackBold19.setFontName("맑은 고딕"); //글씨체
  459. fontOfGothicBlackBold17.setBoldweight(Font.BOLDWEIGHT_BOLD); //볼드 (굵게)
  460. styleOfBoardFillFontBlackBold17.setFont(fontOfGothicBlackBold17);
  461. styleOfBoardFillFontBlackBold17.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0"));
  462. styleOfBoardFillFontBlackBold18.setFont(fontOfGothicBlackBold18);
  463. styleOfBoardFillFontBlackBold19.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0"));
  464. row = sheet1.createRow(i);
  465. cell1 = row.createCell(0);
  466. cell2 = row.createCell(1);
  467. cell3 = row.createCell(2);
  468. cell4 = row.createCell(3);
  469. cell5 = row.createCell(4);
  470. cell6 = row.createCell(5);
  471. styleOfBoardFillFontBlackBold17.setAlignment(CellStyle.ALIGN_RIGHT);
  472. styleOfBoardFillFontBlackBold17.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
  473. styleOfBoardFillFontBlackBold18.setAlignment(CellStyle.ALIGN_CENTER);
  474. cell1.setCellStyle(styleOfBoardFillFontBlackBold18);
  475. cell2.setCellStyle(styleOfBoardFillFontBlackBold19);
  476. cell3.setCellStyle(styleOfBoardFillFontBlackBold17);
  477. cell4.setCellStyle(styleOfBoardFillFontBlackBold17);
  478. cell5.setCellStyle(styleOfBoardFillFontBlackBold19);
  479. cell6.setCellStyle(styleOfBoardFillFontBlackBold19);
  480. cell1.setCellValue( "누적" );
  481. cell2.setCellValue( sum.gethTotal() + sum.getdTotal() + sum.gettTotal() );
  482. cell3.setCellValue( sum.gethTotal() );
  483. cell4.setCellValue( sum.getdTotal() + sum.gettTotal() );
  484. cell5.setCellValue( sum.getdTotal() );
  485. cell6.setCellValue( sum.gettTotal() );
  486. i++;
  487. // 누적 row 끝
  488. // 일별 통계 row
  489. for (PatientDTO dto : data) {
  490. row = sheet1.createRow(i);
  491. cell1 = row.createCell(0);
  492. cell2 = row.createCell(1);
  493. cell3 = row.createCell(2);
  494. cell4 = row.createCell(3);
  495. cell5 = row.createCell(4);
  496. cell6 = row.createCell(5);
  497. styleOfBoardFillFontBlackBold17.setAlignment(CellStyle.ALIGN_RIGHT);
  498. cell1.setCellStyle(styleOfBoardFillFontBlackBold18);
  499. cell2.setCellStyle(styleOfBoardFillFontBlackBold19);
  500. cell3.setCellStyle(styleOfBoardFillFontBlackBold17);
  501. cell4.setCellStyle(styleOfBoardFillFontBlackBold17);
  502. cell5.setCellStyle(styleOfBoardFillFontBlackBold19);
  503. cell6.setCellStyle(styleOfBoardFillFontBlackBold19);
  504. cell1.setCellValue( dto.getInDate() );
  505. cell2.setCellValue( dto.gethTotal() + dto.getdTotal() + dto.gettTotal() );
  506. cell3.setCellValue( dto.gethTotal() );
  507. cell4.setCellValue( dto.getdTotal() + dto.gettTotal() );
  508. cell5.setCellValue( dto.getdTotal() );
  509. cell6.setCellValue( dto.gettTotal() );
  510. i++;
  511. }
  512. row = sheet1.createRow(i);
  513. cell1 = row.createCell(2);
  514. cell2 = row.createCell(3);
  515. cell3 = row.createCell(4);
  516. cell4 = row.createCell(5);
  517. cell5 = row.createCell(6);
  518. cell6 = row.createCell(7);
  519. try {
  520. // JBOSS에서 구동시 /home1/jboss/jboss-eap-7.3/domain/test/excel-temp 경로에 저장이됨
  521. String tempPath = "../excel-temp/testExcel.xlsx";
  522. String downName = LifeCenterFunction.getNow() + " 환자입퇴소통계.xlsx";
  523. File xlsFile = new File(tempPath);
  524. // FileOutputStream fileOut = new FileOutputStream(tempPath);
  525. // workbook.write(fileOut);
  526. // fileOut.close();
  527. ByteArrayOutputStream fileOut = new ByteArrayOutputStream();
  528. FileOutputStream fos = new FileOutputStream(tempPath);
  529. workbook.write(fileOut);
  530. InputStream filein = new ByteArrayInputStream(fileOut.toByteArray());
  531. OPCPackage opc = OPCPackage.open(filein);
  532. POIFSFileSystem fileSystem = new POIFSFileSystem();
  533. EncryptionInfo encryptionInfo = new EncryptionInfo(EncryptionMode.agile);
  534. Encryptor encryptor = encryptionInfo.getEncryptor();
  535. encryptor.confirmPassword(password);
  536. opc.save(encryptor.getDataStream(fileSystem));
  537. opc.flush();
  538. fileSystem.writeFilesystem(fos);
  539. fileOut.close();
  540. opc.close();
  541. filein.close();
  542. fileSystem.close();
  543. LifeCenterFileDownload.download(request, response, tempPath, downName);
  544. xlsFile.delete();
  545. } catch (FileNotFoundException e) {
  546. e.printStackTrace();
  547. } catch (IOException e) {
  548. e.printStackTrace();
  549. }
  550. catch (InvalidFormatException e) {
  551. // TODO Auto-generated catch block
  552. e.printStackTrace();
  553. } catch (GeneralSecurityException e) {
  554. // TODO Auto-generated catch block
  555. e.printStackTrace();
  556. }
  557. }
  558. }