PatientStatistics.java 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  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. Cell cell8 = row.createCell(7);
  241. Cell cell9 = row.createCell(8);
  242. cell1.setCellStyle(styleOfBoardFillFontBlackBold16);
  243. cell2.setCellStyle(styleOfBoardFillFontBlackBold16);
  244. cell3.setCellStyle(styleOfBoardFillFontBlackBold16);
  245. cell4.setCellStyle(styleOfBoardFillFontBlackBold16);
  246. cell5.setCellStyle(styleOfBoardFillFontBlackBold16);
  247. cell6.setCellStyle(styleOfBoardFillFontBlackBold16);
  248. cell7.setCellStyle(styleOfBoardFillFontBlackBold16);
  249. cell8.setCellStyle(styleOfBoardFillFontBlackBold16);
  250. cell9.setCellStyle(styleOfBoardFillFontBlackBold16);
  251. sheet1.setColumnWidth( 0, 10000); //생활치료센터명
  252. sheet1.setColumnWidth( 1, 6000); //소관
  253. sheet1.setColumnWidth( 2, 6000); //환자인원
  254. sheet1.setColumnWidth( 3, 6000); //입소
  255. sheet1.setColumnWidth( 4, 15000); //퇴실소계
  256. sheet1.setColumnWidth( 5, 6000); //퇴소
  257. sheet1.setColumnWidth( 6, 6000); //지정병원이송
  258. sheet1.setColumnWidth( 7, 6000); //생치센터이송
  259. sheet1.setColumnWidth( 8, 6000); //자가격리
  260. cell1.setCellValue("생활치료센터명");
  261. sheet1.addMergedRegion(new CellRangeAddress(0,1,0,0));
  262. cell2.setCellValue("소관");
  263. sheet1.addMergedRegion(new CellRangeAddress(0,1,1,1));
  264. cell3.setCellValue("환자인원");
  265. sheet1.addMergedRegion(new CellRangeAddress(0,1,2,2));
  266. cell4.setCellValue("입소");
  267. sheet1.addMergedRegion(new CellRangeAddress(0,1,3,3));
  268. cell5.setCellValue("퇴실소계 (퇴소 + 지정병원이송 + 생치센터이송 + 자가격리)");
  269. sheet1.addMergedRegion(new CellRangeAddress(0,1,4,4));
  270. cell6.setCellValue("퇴실");
  271. sheet1.addMergedRegion(new CellRangeAddress(0,0,5,8));
  272. row = sheet1.createRow(i);
  273. cell1 = row.createCell(0);
  274. cell2 = row.createCell(1);
  275. cell3 = row.createCell(2);
  276. cell4 = row.createCell(3);
  277. cell5 = row.createCell(4);
  278. cell6 = row.createCell(5);
  279. cell7 = row.createCell(6);
  280. cell8 = row.createCell(7);
  281. cell9 = row.createCell(8);
  282. cell1.setCellStyle(styleOfBoardFillFontBlackBold16);
  283. cell2.setCellStyle(styleOfBoardFillFontBlackBold16);
  284. cell3.setCellStyle(styleOfBoardFillFontBlackBold16);
  285. cell4.setCellStyle(styleOfBoardFillFontBlackBold16);
  286. cell5.setCellStyle(styleOfBoardFillFontBlackBold16);
  287. cell6.setCellStyle(styleOfBoardFillFontBlackBold16);
  288. cell7.setCellStyle(styleOfBoardFillFontBlackBold16);
  289. cell8.setCellStyle(styleOfBoardFillFontBlackBold16);
  290. cell9.setCellStyle(styleOfBoardFillFontBlackBold16);
  291. cell6.setCellValue( "퇴소" );
  292. cell7.setCellValue( "지정병원이송" );
  293. cell8.setCellValue( "생치센터이송" );
  294. cell9.setCellValue( "자가격리" );
  295. i++;
  296. // th영역 끝
  297. CellStyle styleOfBoardFillFontBlackBold17 = workbook.createCellStyle();
  298. CellStyle styleOfBoardFillFontBlackBold18 = workbook.createCellStyle();
  299. CellStyle styleOfBoardFillFontBlackBold19 = workbook.createCellStyle();
  300. Font fontOfGothicBlackBold17 = workbook.createFont();
  301. Font fontOfGothicBlackBold18 = workbook.createFont();
  302. Font fontOfGothicBlackBold19 = workbook.createFont();
  303. fontOfGothicBlackBold17.setFontName("맑은 고딕"); //글씨체
  304. fontOfGothicBlackBold18.setFontName("맑은 고딕"); //글씨체
  305. fontOfGothicBlackBold19.setFontName("맑은 고딕"); //글씨체
  306. fontOfGothicBlackBold17.setBoldweight(Font.BOLDWEIGHT_BOLD); //볼드 (굵게)
  307. styleOfBoardFillFontBlackBold17.setFont(fontOfGothicBlackBold17);
  308. styleOfBoardFillFontBlackBold17.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0"));
  309. styleOfBoardFillFontBlackBold18.setFont(fontOfGothicBlackBold18);
  310. styleOfBoardFillFontBlackBold19.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0"));
  311. for (PatientDTO dto : data) {
  312. // 센터별 통계 row
  313. row = sheet1.createRow(i);
  314. cell1 = row.createCell(0);
  315. cell2 = row.createCell(1);
  316. cell3 = row.createCell(2);
  317. cell4 = row.createCell(3);
  318. cell5 = row.createCell(4);
  319. cell6 = row.createCell(5);
  320. cell7 = row.createCell(6);
  321. cell8 = row.createCell(7);
  322. cell9 = row.createCell(8);
  323. styleOfBoardFillFontBlackBold17.setAlignment(CellStyle.ALIGN_RIGHT);
  324. cell1.setCellStyle(styleOfBoardFillFontBlackBold18);
  325. cell2.setCellStyle(styleOfBoardFillFontBlackBold19);
  326. cell3.setCellStyle(styleOfBoardFillFontBlackBold17);
  327. cell4.setCellStyle(styleOfBoardFillFontBlackBold17);
  328. cell5.setCellStyle(styleOfBoardFillFontBlackBold19);
  329. cell6.setCellStyle(styleOfBoardFillFontBlackBold19);
  330. cell7.setCellStyle(styleOfBoardFillFontBlackBold19);
  331. cell8.setCellStyle(styleOfBoardFillFontBlackBold19);
  332. cell9.setCellStyle(styleOfBoardFillFontBlackBold19);
  333. cell1.setCellValue( dto.getCenterName() );
  334. cell2.setCellValue( dto.getJurisdictionName() );
  335. cell3.setCellValue( dto.gethTotal() + dto.getdTotal() + dto.gettTotal() + dto.getlTotal() + dto.getsTotal() );
  336. cell4.setCellValue( dto.gethTotal() );
  337. cell5.setCellValue( dto.getdTotal() + dto.gettTotal() + dto.getlTotal() + dto.getsTotal() );
  338. cell6.setCellValue( dto.getdTotal() ); // 퇴소
  339. cell7.setCellValue( dto.gettTotal() ); // 지정병원이송
  340. cell8.setCellValue( dto.getlTotal() ); // 생치센터이송
  341. cell9.setCellValue( dto.getsTotal() ); // 자가격리
  342. i++;
  343. }
  344. row = sheet1.createRow(i);
  345. cell1 = row.createCell(2);
  346. cell2 = row.createCell(3);
  347. cell3 = row.createCell(4);
  348. cell4 = row.createCell(5);
  349. cell5 = row.createCell(6);
  350. cell6 = row.createCell(7);
  351. cell7 = row.createCell(8);
  352. cell8 = row.createCell(9);
  353. cell9 = row.createCell(10);
  354. try {
  355. // JBOSS에서 구동시 /home1/jboss/jboss-eap-7.3/domain/test/excel-temp 경로에 저장이됨
  356. String tempPath = "../excel-temp/testExcel.xlsx";
  357. String downName = LifeCenterFunction.getNow() + "_["+registDay+"] 환자입퇴소통계.xlsx";
  358. File xlsFile = new File(tempPath);
  359. ByteArrayOutputStream fileOut = new ByteArrayOutputStream();
  360. FileOutputStream fos = new FileOutputStream(tempPath);
  361. workbook.write(fileOut);
  362. InputStream filein = new ByteArrayInputStream(fileOut.toByteArray());
  363. OPCPackage opc = OPCPackage.open(filein);
  364. POIFSFileSystem fileSystem = new POIFSFileSystem();
  365. EncryptionInfo encryptionInfo = new EncryptionInfo(EncryptionMode.agile);
  366. Encryptor encryptor = encryptionInfo.getEncryptor();
  367. encryptor.confirmPassword(password);
  368. opc.save(encryptor.getDataStream(fileSystem));
  369. opc.flush();
  370. fileSystem.writeFilesystem(fos);
  371. fileOut.close();
  372. opc.close();
  373. filein.close();
  374. fileSystem.close();
  375. LifeCenterFileDownload.download(request, response, tempPath, downName);
  376. xlsFile.delete();
  377. } catch (FileNotFoundException e) {
  378. e.printStackTrace();
  379. } catch (IOException e) {
  380. e.printStackTrace();
  381. } catch (InvalidFormatException e) {
  382. // TODO Auto-generated catch block
  383. e.printStackTrace();
  384. } catch (GeneralSecurityException e) {
  385. // TODO Auto-generated catch block
  386. e.printStackTrace();
  387. }
  388. }
  389. private void getStatisticsPatientExcel(HttpServletRequest request, HttpServletResponse response, List<PatientDTO> data, PatientDTO sum ) {
  390. String password = LifeCenterSessionController.getSession(request, "sesPhoneNumber");
  391. password = password.toLowerCase();
  392. if (!password.equals("null") && !password.equals( "" )) {
  393. password = password.replace("-", "");
  394. password = password.substring(3).trim();
  395. } else {
  396. password = "";
  397. }
  398. Workbook workbook = new XSSFWorkbook();
  399. Sheet sheet1 = workbook.createSheet("firstSheet");
  400. DecimalFormat df = new DecimalFormat("#,###");
  401. //1.셀 스타일 및 폰트 설정
  402. CellStyle styleOfBoardFillFontBlackBold16 = workbook.createCellStyle();
  403. //정렬
  404. styleOfBoardFillFontBlackBold16.setAlignment(CellStyle.ALIGN_CENTER); //가운데 정렬
  405. styleOfBoardFillFontBlackBold16.setVerticalAlignment(CellStyle.VERTICAL_CENTER); //높이 가운데 정렬
  406. //배경색
  407. styleOfBoardFillFontBlackBold16.setFillForegroundColor(IndexedColors.LIGHT_YELLOW.getIndex());
  408. styleOfBoardFillFontBlackBold16.setFillPattern(CellStyle.SOLID_FOREGROUND);
  409. //테두리 선 (우,좌,위,아래)
  410. styleOfBoardFillFontBlackBold16.setBorderRight(HSSFCellStyle.BORDER_THIN);
  411. styleOfBoardFillFontBlackBold16.setBorderLeft(HSSFCellStyle.BORDER_THIN);
  412. styleOfBoardFillFontBlackBold16.setBorderTop(HSSFCellStyle.BORDER_THIN);
  413. styleOfBoardFillFontBlackBold16.setBorderBottom(HSSFCellStyle.BORDER_THIN);
  414. //폰트 설정
  415. Font fontOfGothicBlackBold16 = workbook.createFont();
  416. // fontOfGothicBlackBold16.setFontName("나눔고딕"); //글씨체
  417. fontOfGothicBlackBold16.setFontHeight((short)(10*20)); //사이즈
  418. fontOfGothicBlackBold16.setBoldweight(Font.BOLDWEIGHT_BOLD); //볼드 (굵게)
  419. styleOfBoardFillFontBlackBold16.setFont(fontOfGothicBlackBold16);
  420. styleOfBoardFillFontBlackBold16.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0"));
  421. int i = 1;
  422. // th영역
  423. Row row = sheet1.createRow(0);
  424. Cell cell1 = row.createCell(0);
  425. Cell cell2 = row.createCell(1);
  426. Cell cell3 = row.createCell(2);
  427. Cell cell4 = row.createCell(3);
  428. Cell cell5 = row.createCell(4);
  429. Cell cell6 = row.createCell(5);
  430. Cell cell7 = row.createCell(6);
  431. Cell cell8 = row.createCell(7);
  432. cell1.setCellStyle(styleOfBoardFillFontBlackBold16);
  433. cell2.setCellStyle(styleOfBoardFillFontBlackBold16);
  434. cell3.setCellStyle(styleOfBoardFillFontBlackBold16);
  435. cell4.setCellStyle(styleOfBoardFillFontBlackBold16);
  436. cell5.setCellStyle(styleOfBoardFillFontBlackBold16);
  437. cell6.setCellStyle(styleOfBoardFillFontBlackBold16);
  438. cell7.setCellStyle(styleOfBoardFillFontBlackBold16);
  439. cell8.setCellStyle(styleOfBoardFillFontBlackBold16);
  440. sheet1.setColumnWidth( 0, 5000); //날짜
  441. sheet1.setColumnWidth( 1, 6000); //환자인원
  442. sheet1.setColumnWidth( 2, 6000); //입소
  443. sheet1.setColumnWidth( 3, 15000); //퇴실소계
  444. sheet1.setColumnWidth( 4, 6000); //퇴소
  445. sheet1.setColumnWidth( 5, 6000); //지정병원 이송
  446. sheet1.setColumnWidth( 6, 6000); //생치센터이송
  447. sheet1.setColumnWidth( 6, 6000); //자가격리
  448. cell1.setCellValue("날짜");
  449. sheet1.addMergedRegion(new CellRangeAddress(0,1,0,0));
  450. cell2.setCellValue("환자인원");
  451. sheet1.addMergedRegion(new CellRangeAddress(0,1,1,1));
  452. cell3.setCellValue("입소");
  453. sheet1.addMergedRegion(new CellRangeAddress(0,1,2,2));
  454. cell4.setCellValue("퇴실소계 (퇴소 + 지정병원이송 + 생치센터이송 + 자가격리)");
  455. sheet1.addMergedRegion(new CellRangeAddress(0,1,3,3));
  456. cell5.setCellValue("퇴실");
  457. sheet1.addMergedRegion(new CellRangeAddress(0,0,4,7));
  458. row = sheet1.createRow(i);
  459. cell1 = row.createCell(0);
  460. cell2 = row.createCell(1);
  461. cell3 = row.createCell(2);
  462. cell4 = row.createCell(3);
  463. cell5 = row.createCell(4);
  464. cell6 = row.createCell(5);
  465. cell7 = row.createCell(6);
  466. cell8 = row.createCell(7);
  467. cell1.setCellStyle(styleOfBoardFillFontBlackBold16);
  468. cell2.setCellStyle(styleOfBoardFillFontBlackBold16);
  469. cell3.setCellStyle(styleOfBoardFillFontBlackBold16);
  470. cell4.setCellStyle(styleOfBoardFillFontBlackBold16);
  471. cell5.setCellStyle(styleOfBoardFillFontBlackBold16);
  472. cell6.setCellStyle(styleOfBoardFillFontBlackBold16);
  473. cell7.setCellStyle(styleOfBoardFillFontBlackBold16);
  474. cell8.setCellStyle(styleOfBoardFillFontBlackBold16);
  475. cell5.setCellValue( "퇴소" );
  476. cell6.setCellValue( "지정병원이송" );
  477. cell7.setCellValue( "생치센터이송" );
  478. cell8.setCellValue( "자가격리" );
  479. i++;
  480. // th영역 끝
  481. // 누적 row
  482. CellStyle styleOfBoardFillFontBlackBold17 = workbook.createCellStyle();
  483. CellStyle styleOfBoardFillFontBlackBold18 = workbook.createCellStyle();
  484. CellStyle styleOfBoardFillFontBlackBold19 = workbook.createCellStyle();
  485. Font fontOfGothicBlackBold17 = workbook.createFont();
  486. Font fontOfGothicBlackBold18 = workbook.createFont();
  487. Font fontOfGothicBlackBold19 = workbook.createFont();
  488. fontOfGothicBlackBold17.setFontName("맑은 고딕"); //글씨체
  489. fontOfGothicBlackBold18.setFontName("맑은 고딕"); //글씨체
  490. fontOfGothicBlackBold19.setFontName("맑은 고딕"); //글씨체
  491. fontOfGothicBlackBold17.setBoldweight(Font.BOLDWEIGHT_BOLD); //볼드 (굵게)
  492. styleOfBoardFillFontBlackBold17.setFont(fontOfGothicBlackBold17);
  493. styleOfBoardFillFontBlackBold17.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0"));
  494. styleOfBoardFillFontBlackBold18.setFont(fontOfGothicBlackBold18);
  495. styleOfBoardFillFontBlackBold19.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0"));
  496. row = sheet1.createRow(i);
  497. cell1 = row.createCell(0);
  498. cell2 = row.createCell(1);
  499. cell3 = row.createCell(2);
  500. cell4 = row.createCell(3);
  501. cell5 = row.createCell(4);
  502. cell6 = row.createCell(5);
  503. cell7 = row.createCell(6);
  504. cell8 = row.createCell(7);
  505. styleOfBoardFillFontBlackBold17.setAlignment(CellStyle.ALIGN_RIGHT);
  506. styleOfBoardFillFontBlackBold17.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
  507. styleOfBoardFillFontBlackBold18.setAlignment(CellStyle.ALIGN_CENTER);
  508. cell1.setCellStyle(styleOfBoardFillFontBlackBold18);
  509. cell2.setCellStyle(styleOfBoardFillFontBlackBold19);
  510. cell3.setCellStyle(styleOfBoardFillFontBlackBold17);
  511. cell4.setCellStyle(styleOfBoardFillFontBlackBold17);
  512. cell5.setCellStyle(styleOfBoardFillFontBlackBold19);
  513. cell6.setCellStyle(styleOfBoardFillFontBlackBold19);
  514. cell7.setCellStyle(styleOfBoardFillFontBlackBold19);
  515. cell8.setCellStyle(styleOfBoardFillFontBlackBold19);
  516. cell1.setCellValue( "누적" );
  517. cell2.setCellValue( sum.gethTotal() + sum.getdTotal() + sum.gettTotal() + sum.getlTotal() + sum.getsTotal() );
  518. cell3.setCellValue( sum.gethTotal() );
  519. cell4.setCellValue( sum.getdTotal() + sum.gettTotal() + sum.getlTotal() + sum.getsTotal() );
  520. cell5.setCellValue( sum.getdTotal() );
  521. cell6.setCellValue( sum.gettTotal() );
  522. cell7.setCellValue( sum.getlTotal() );
  523. cell8.setCellValue( sum.getsTotal() );
  524. i++;
  525. // 누적 row 끝
  526. // 일별 통계 row
  527. for (PatientDTO dto : data) {
  528. row = sheet1.createRow(i);
  529. cell1 = row.createCell(0);
  530. cell2 = row.createCell(1);
  531. cell3 = row.createCell(2);
  532. cell4 = row.createCell(3);
  533. cell5 = row.createCell(4);
  534. cell6 = row.createCell(5);
  535. cell7 = row.createCell(6);
  536. cell8 = row.createCell(7);
  537. styleOfBoardFillFontBlackBold17.setAlignment(CellStyle.ALIGN_RIGHT);
  538. cell1.setCellStyle(styleOfBoardFillFontBlackBold18);
  539. cell2.setCellStyle(styleOfBoardFillFontBlackBold19);
  540. cell3.setCellStyle(styleOfBoardFillFontBlackBold17);
  541. cell4.setCellStyle(styleOfBoardFillFontBlackBold17);
  542. cell5.setCellStyle(styleOfBoardFillFontBlackBold19);
  543. cell6.setCellStyle(styleOfBoardFillFontBlackBold19);
  544. cell7.setCellStyle(styleOfBoardFillFontBlackBold19);
  545. cell8.setCellStyle(styleOfBoardFillFontBlackBold19);
  546. cell1.setCellValue( dto.getInDate() );
  547. cell2.setCellValue( dto.gethTotal() + dto.getdTotal() + dto.gettTotal() + dto.getlTotal() + dto.getsTotal() );
  548. cell3.setCellValue( dto.gethTotal() );
  549. cell4.setCellValue( dto.getdTotal() + dto.gettTotal() + dto.getlTotal() + dto.getsTotal() );
  550. cell5.setCellValue( dto.getdTotal() );
  551. cell6.setCellValue( dto.gettTotal() );
  552. cell7.setCellValue( dto.getlTotal() );
  553. cell8.setCellValue( dto.getsTotal() );
  554. i++;
  555. }
  556. row = sheet1.createRow(i);
  557. cell1 = row.createCell(2);
  558. cell2 = row.createCell(3);
  559. cell3 = row.createCell(4);
  560. cell4 = row.createCell(5);
  561. cell5 = row.createCell(6);
  562. cell6 = row.createCell(7);
  563. cell7 = row.createCell(8);
  564. cell8 = row.createCell(9);
  565. try {
  566. // JBOSS에서 구동시 /home1/jboss/jboss-eap-7.3/domain/test/excel-temp 경로에 저장이됨
  567. String tempPath = "../excel-temp/testExcel.xlsx";
  568. String downName = LifeCenterFunction.getNow() + " 환자입퇴소통계.xlsx";
  569. File xlsFile = new File(tempPath);
  570. // FileOutputStream fileOut = new FileOutputStream(tempPath);
  571. // workbook.write(fileOut);
  572. // fileOut.close();
  573. ByteArrayOutputStream fileOut = new ByteArrayOutputStream();
  574. FileOutputStream fos = new FileOutputStream(tempPath);
  575. workbook.write(fileOut);
  576. InputStream filein = new ByteArrayInputStream(fileOut.toByteArray());
  577. OPCPackage opc = OPCPackage.open(filein);
  578. POIFSFileSystem fileSystem = new POIFSFileSystem();
  579. EncryptionInfo encryptionInfo = new EncryptionInfo(EncryptionMode.agile);
  580. Encryptor encryptor = encryptionInfo.getEncryptor();
  581. encryptor.confirmPassword(password);
  582. opc.save(encryptor.getDataStream(fileSystem));
  583. opc.flush();
  584. fileSystem.writeFilesystem(fos);
  585. fileOut.close();
  586. opc.close();
  587. filein.close();
  588. fileSystem.close();
  589. LifeCenterFileDownload.download(request, response, tempPath, downName);
  590. xlsFile.delete();
  591. } catch (FileNotFoundException e) {
  592. e.printStackTrace();
  593. } catch (IOException e) {
  594. e.printStackTrace();
  595. }
  596. catch (InvalidFormatException e) {
  597. // TODO Auto-generated catch block
  598. e.printStackTrace();
  599. } catch (GeneralSecurityException e) {
  600. // TODO Auto-generated catch block
  601. e.printStackTrace();
  602. }
  603. }
  604. }