This repository has been archived by the owner on Dec 7, 2024. It is now read-only.
generated from GSM-MSG/MSG-Repository-Generator
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #292 from GSM-MSG/287-feat/attendance-status-excel…
…-print 🔀 :: 287 출석부 엑셀 출력 API
- Loading branch information
Showing
8 changed files
with
148 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/com/msg/gcms/domain/attendance/service/ClubAttendanceStatusExcelService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.msg.gcms.domain.attendance.service | ||
|
||
import java.time.LocalDate | ||
|
||
interface ClubAttendanceStatusExcelService { | ||
fun execute(currentDate: LocalDate): ByteArray | ||
} |
93 changes: 93 additions & 0 deletions
93
...otlin/com/msg/gcms/domain/attendance/service/impl/ClubAttendanceStatusExcelServiceImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package com.msg.gcms.domain.attendance.service.impl | ||
|
||
import com.msg.gcms.domain.attendance.domain.entity.Schedule | ||
import com.msg.gcms.domain.attendance.repository.AttendanceRepository | ||
import com.msg.gcms.domain.attendance.repository.ScheduleRepository | ||
import com.msg.gcms.domain.attendance.service.ClubAttendanceStatusExcelService | ||
import com.msg.gcms.domain.club.domain.entity.Club | ||
import com.msg.gcms.global.annotation.ServiceWithReadOnlyTransaction | ||
import com.msg.gcms.global.util.ExcelUtil | ||
import org.apache.poi.ss.usermodel.* | ||
import org.apache.poi.xssf.usermodel.XSSFCellStyle | ||
import org.apache.poi.xssf.usermodel.XSSFSheet | ||
import org.apache.poi.xssf.usermodel.XSSFWorkbook | ||
import java.io.ByteArrayOutputStream | ||
import java.time.LocalDate | ||
|
||
@ServiceWithReadOnlyTransaction | ||
class ClubAttendanceStatusExcelServiceImpl( | ||
private val scheduleRepository: ScheduleRepository, | ||
private val attendanceRepository: AttendanceRepository | ||
): ClubAttendanceStatusExcelService { | ||
override fun execute(currentDate: LocalDate): ByteArray { | ||
val schedule = scheduleRepository.findAllByDate(currentDate) | ||
|
||
val workBook = XSSFWorkbook() | ||
|
||
val font = workBook.createFont() | ||
font.fontName = "Arial" | ||
font.fontHeightInPoints = 11 | ||
|
||
schedule.forEach { | ||
var rowNum = 1 | ||
|
||
val sheet = workBook.createHeaderRow(font, it.club.name) | ||
|
||
val attendances = attendanceRepository.findAllBySchedule(it) | ||
|
||
attendances.groupBy { attendance -> attendance.user }.forEach { (user, attendances) -> | ||
val row = sheet.createRow(rowNum) | ||
|
||
val sortedAttendances = attendances.sortedBy { it.period } | ||
listOf( | ||
"${user.grade}${user.classNum}${user.number.toString().padStart(2, '0')}", | ||
user.nickname, | ||
*sortedAttendances.map { sortedAttendance -> sortedAttendance.attendanceStatus.sign }.toTypedArray() | ||
).forEachIndexed { idx, data -> | ||
val cell = row.createCell(idx) | ||
cell.setCellValue(data) | ||
cell.cellStyle = workBook.createCellStyle() | ||
.apply { | ||
alignment = HorizontalAlignment.CENTER | ||
verticalAlignment = VerticalAlignment.CENTER | ||
setFont(font) | ||
} | ||
} | ||
} | ||
rowNum++ | ||
} | ||
|
||
ByteArrayOutputStream().use { stream -> | ||
workBook.write(stream) | ||
return stream.toByteArray() | ||
} | ||
} | ||
|
||
// 출석부의 헤더 열을 만들고 엑셀 시트를 만들어 반환하는 함수 | ||
private fun XSSFWorkbook.createHeaderRow(font: Font, name: String): XSSFSheet { | ||
val sheet = createSheet(name) | ||
val headerRow = sheet.createRow(0) | ||
|
||
listOf( | ||
"학번", | ||
"이름", | ||
"8교시", | ||
"9교시", | ||
"10교시", | ||
"11교시" | ||
).forEachIndexed { idx, column -> | ||
val cell = headerRow.createCell(idx) | ||
cell.setCellValue(column) | ||
cell.cellStyle = createCellStyle() | ||
.apply { | ||
fillForegroundColor = IndexedColors.GREY_25_PERCENT.index | ||
fillPattern = FillPatternType.SOLID_FOREGROUND | ||
alignment = HorizontalAlignment.CENTER | ||
verticalAlignment = VerticalAlignment.CENTER | ||
setFont(font) | ||
} | ||
} | ||
|
||
return sheet | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
2024-03-22 13:55:02.243 INFO 9820 --- [http-nio-8080-exec-1] RequestLogFilter : client ip = 0:0:0:0:0:0:0:1 | ||
2024-03-22 13:55:02.243 INFO 9820 --- [http-nio-8080-exec-1] RequestLogFilter : request method = GET | ||
2024-03-22 13:55:02.244 INFO 9820 --- [http-nio-8080-exec-1] RequestLogFilter : request url = /attend/excel | ||
2024-03-22 13:55:02.244 INFO 9820 --- [http-nio-8080-exec-1] RequestLogFilter : client info = Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 | ||
2024-03-22 13:55:02.698 INFO 9820 --- [http-nio-8080-exec-1] RequestLogFilter : response status = 200 | ||
2024-03-22 13:55:42.052 INFO 9895 --- [http-nio-8080-exec-2] RequestLogFilter : client ip = 0:0:0:0:0:0:0:1 | ||
2024-03-22 13:55:42.053 INFO 9895 --- [http-nio-8080-exec-2] RequestLogFilter : request method = GET | ||
2024-03-22 13:55:42.053 INFO 9895 --- [http-nio-8080-exec-2] RequestLogFilter : request url = /attend/excel | ||
2024-03-22 13:55:42.053 INFO 9895 --- [http-nio-8080-exec-2] RequestLogFilter : client info = Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 | ||
2024-03-22 13:55:42.442 INFO 9895 --- [http-nio-8080-exec-2] RequestLogFilter : response status = 200 | ||
2024-03-22 14:03:50.076 INFO 9895 --- [http-nio-8080-exec-4] RequestLogFilter : client ip = 0:0:0:0:0:0:0:1 | ||
2024-03-22 14:03:50.078 INFO 9895 --- [http-nio-8080-exec-4] RequestLogFilter : request method = GET | ||
2024-03-22 14:03:50.078 INFO 9895 --- [http-nio-8080-exec-4] RequestLogFilter : request url = /attend/excel | ||
2024-03-22 14:03:50.078 INFO 9895 --- [http-nio-8080-exec-4] RequestLogFilter : client info = Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 | ||
2024-03-22 14:03:50.211 INFO 9895 --- [http-nio-8080-exec-4] RequestLogFilter : response status = 200 | ||
2024-03-22 14:06:23.777 INFO 9970 --- [http-nio-8080-exec-1] RequestLogFilter : client ip = 0:0:0:0:0:0:0:1 | ||
2024-03-22 14:06:23.777 INFO 9970 --- [http-nio-8080-exec-1] RequestLogFilter : request method = GET | ||
2024-03-22 14:06:23.777 INFO 9970 --- [http-nio-8080-exec-1] RequestLogFilter : request url = /attend/excel | ||
2024-03-22 14:06:23.778 INFO 9970 --- [http-nio-8080-exec-1] RequestLogFilter : client info = Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 | ||
2024-03-22 14:06:24.164 INFO 9970 --- [http-nio-8080-exec-1] RequestLogFilter : response status = 200 | ||
2024-03-22 14:17:19.875 INFO 10189 --- [http-nio-8080-exec-1] RequestLogFilter : client ip = 0:0:0:0:0:0:0:1 | ||
2024-03-22 14:17:19.875 INFO 10189 --- [http-nio-8080-exec-1] RequestLogFilter : request method = GET | ||
2024-03-22 14:17:19.875 INFO 10189 --- [http-nio-8080-exec-1] RequestLogFilter : request url = /attend/excel | ||
2024-03-22 14:17:19.876 INFO 10189 --- [http-nio-8080-exec-1] RequestLogFilter : client info = Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 | ||
2024-03-22 14:17:20.264 INFO 10189 --- [http-nio-8080-exec-1] RequestLogFilter : response status = 200 | ||
2024-03-22 14:17:25.296 INFO 10189 --- [http-nio-8080-exec-2] RequestLogFilter : client ip = 0:0:0:0:0:0:0:1 | ||
2024-03-22 14:17:25.298 INFO 10189 --- [http-nio-8080-exec-2] RequestLogFilter : request method = GET | ||
2024-03-22 14:17:25.298 INFO 10189 --- [http-nio-8080-exec-2] RequestLogFilter : request url = /attend/excel | ||
2024-03-22 14:17:25.299 INFO 10189 --- [http-nio-8080-exec-2] RequestLogFilter : client info = Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 | ||
2024-03-22 14:17:25.326 INFO 10189 --- [http-nio-8080-exec-2] RequestLogFilter : response status = 200 |
Empty file.