Skip to content

Commit

Permalink
🔀 pull main branch
Browse files Browse the repository at this point in the history
  • Loading branch information
KimTaeO committed Mar 27, 2023
2 parents 53653d7 + f6f90b1 commit 23008b6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,30 @@ class ExcelParsingService(
else
HSSFWorkbook(file.inputStream)
val workSheet:Sheet = workBook.getSheetAt(0)
val allEmail = userRepository.findAllEmail()
val map = hashMapOf<String, UpdateDto>()
for(i in 1 until workSheet.physicalNumberOfRows){
val row = workSheet.getRow(i)
val email = row.getCell(4).stringCellValue
if(!allEmail.contains(email))
continue
val grade = row.getCell(0).numericCellValue.toInt()
val classNum = row.getCell(1).numericCellValue.toInt()
val num = row.getCell(2).numericCellValue.toInt()
val name = row.getCell(3).stringCellValue.toString()
val gender = Gender.valueOf(row.getCell(5).stringCellValue)
val user = userRepository.findByEmail(email) ?: continue
val update = user.update(name, grade, classNum, num, gender)
userRepository.save(update)
map[email] =
UpdateDto(
name = row.getCell(3).stringCellValue.toString(),
grade = row.getCell(0).numericCellValue.toInt(),
classNum = row.getCell(1).numericCellValue.toInt(),
num = row.getCell(2).numericCellValue.toInt(),
gender = Gender.valueOf(row.getCell(5).stringCellValue)
)
}
userRepository.findByEmailIn(map.keys.toList())
.forEach {
val updateDto = map[it.email] ?: throw Exception()
userRepository.save(it.update(updateDto.name, updateDto.grade, updateDto.classNum, updateDto.num, updateDto.gender))
}
}
data class UpdateDto(
val name: String,
val grade: Int,
val classNum: Int,
val num: Int,
val gender: Gender
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ import org.springframework.data.jpa.repository.Query

interface UserRepository: JpaRepository<User, Long>, JpaSpecificationExecutor<User> {
fun findByEmail(email: String): User?
fun findByEmailIn(emailList: List<String>): List<User>
fun existsByEmail(email: String): Boolean
@Query("select user.email from User user")
fun findAllEmail(): List<String>



fun findAllByState(state: UserState): List<User>
fun findAllByStateOrderByGrade(state: UserState, pageable: Pageable): List<User>
fun findAllByStateAndNameContainingOrderByGrade(state: UserState, name: String, pageable: Pageable): List<User>
fun findAllByStateAndClassNumOrderByGrade(state: UserState, classNum: Int, pageable: Pageable): List<User>
Expand Down

0 comments on commit 23008b6

Please sign in to comment.