diff --git a/src/main/java/com/ffii/tsms/modules/data/service/TeamService.kt b/src/main/java/com/ffii/tsms/modules/data/service/TeamService.kt index b249bd0..2254457 100644 --- a/src/main/java/com/ffii/tsms/modules/data/service/TeamService.kt +++ b/src/main/java/com/ffii/tsms/modules/data/service/TeamService.kt @@ -26,7 +26,7 @@ open class TeamService( @Transactional(rollbackFor = [Exception::class]) open fun saveTeam(req: NewTeamRequest): Team { - val ids = req.addStaffIds + val ids = req.addStaffIds!! val teamLead = staffRepository.findById(ids[0]).orElseThrow() val teamName = "Team " + teamLead.name @@ -51,19 +51,28 @@ open class TeamService( @Transactional(rollbackFor = [Exception::class]) open fun updateTeam(req: NewTeamRequest, team: Team): Team { - val addIds = req.addStaffIds - val teamLead = staffRepository.findById(addIds[0]).orElseThrow() - val teamName = "Team " + teamLead.name + val addIds = req.addStaffIds ?: listOf() - val initials = teamLead.name.split(" ").map { it.first() } - val teamCode = initials.joinToString("") + val teamName: String + val teamCode: String + + if (addIds.isNotEmpty()) { + val teamLead = staffRepository.findById(addIds[0].toLong()).orElseThrow() + teamName = "Team " + teamLead.name + + val initials = teamLead.name.split(" ").map { it.first() } + teamCode = initials.joinToString("") + } else { + teamName = team.name + teamCode = team.code + } team.apply { name = teamName code = teamCode description = req.description } - println(!req.deleteStaffIds.isNullOrEmpty()) +// println(!req.deleteStaffIds.isNullOrEmpty()) if (!req.deleteStaffIds.isNullOrEmpty()) { for (id in req.deleteStaffIds) { val staff = staffRepository.findById(id).orElseThrow() diff --git a/src/main/java/com/ffii/tsms/modules/data/web/models/NewStaffRequest.kt b/src/main/java/com/ffii/tsms/modules/data/web/models/NewStaffRequest.kt index 338d5d1..8bec723 100644 --- a/src/main/java/com/ffii/tsms/modules/data/web/models/NewStaffRequest.kt +++ b/src/main/java/com/ffii/tsms/modules/data/web/models/NewStaffRequest.kt @@ -19,9 +19,9 @@ data class NewStaffRequest( val salaryId: Long, // @field:NotNull(message = "Staff skillSetId cannot be empty") val skillSetId: Long?, - val joinDate: LocalDate, val currentPositionId: Long, + val salaryEffId: Long, val joinPositionId: Long, val gradeId: Long?, val teamId: Long?, diff --git a/src/main/java/com/ffii/tsms/modules/data/web/models/NewTeamRequest.kt b/src/main/java/com/ffii/tsms/modules/data/web/models/NewTeamRequest.kt index 3935ad8..98b4df1 100644 --- a/src/main/java/com/ffii/tsms/modules/data/web/models/NewTeamRequest.kt +++ b/src/main/java/com/ffii/tsms/modules/data/web/models/NewTeamRequest.kt @@ -6,7 +6,7 @@ import java.time.LocalDate data class NewTeamRequest ( @field:NotNull(message = "ids cannot be empty") - val addStaffIds: List, + val addStaffIds: List?, val deleteStaffIds: List?, val description: String, val id: Long? diff --git a/src/main/java/com/ffii/tsms/modules/file/service/FileService.kt b/src/main/java/com/ffii/tsms/modules/file/service/FileService.kt index 9b7314f..31e439e 100644 --- a/src/main/java/com/ffii/tsms/modules/file/service/FileService.kt +++ b/src/main/java/com/ffii/tsms/modules/file/service/FileService.kt @@ -14,7 +14,7 @@ import org.springframework.transaction.annotation.Transactional import org.springframework.web.multipart.MultipartFile import java.io.ByteArrayInputStream import java.io.IOException -import java.util.Map +import kotlin.collections.Map import java.util.Optional import javax.imageio.ImageIO @@ -46,7 +46,7 @@ open class FileService( open fun findFileByIdAndKey(id: Long, skey: String): Optional { return jdbcDao.queryForEntity( "SELECT * from file f where f.id = :id and f.skey = :skey ", - Map.of("id", id, "skey", skey), File::class.java + setOf("id", id, "skey", skey), File::class.java ) } @@ -54,14 +54,14 @@ open class FileService( open fun findFileRefByTypeAndId(refType: String, refId: Long): List { return jdbcDao.queryForList( "SELECT * from file_ref where refType = :refType and refId = :refId order by id ", - java.util.Map.of("refType", refType, "refId", refId), FileRef::class.java + setOf("refType", refType, "refId", refId), FileRef::class.java ) } @Transactional(isolation = Isolation.READ_COMMITTED, rollbackFor = [Exception::class], readOnly = true) open fun findFileRefByFileId(fileId: Long): Optional { return jdbcDao.queryForEntity( - "SELECT * from file_ref where fileId = :fileId", java.util.Map.of("fileId", fileId), + "SELECT * from file_ref where fileId = :fileId", setOf("fileId", fileId), FileRef::class.java ) } @@ -70,7 +70,7 @@ open class FileService( open fun findFileBlobByFileId(fileId: Long): Optional { return jdbcDao.queryForEntity( "SELECT * from file_blob fb where fb.fileId = :fileId ", - java.util.Map.of("fileId", fileId), FileBlob::class.java + setOf("fileId", fileId), FileBlob::class.java ) } @@ -83,7 +83,7 @@ open class FileService( + " AND f.id = :id" + " AND f.skey = :skey") - val count = jdbcDao.queryForInt(sql, Map.of("id", id, "skey", skey)) + val count = jdbcDao.queryForInt(sql, setOf("id", id, "skey", skey)) return (count > 0) } @@ -129,7 +129,7 @@ open class FileService( @Transactional(isolation = Isolation.SERIALIZABLE, rollbackFor = [Exception::class], readOnly = false) open fun deleteFile(fileId: Long, refId: Long, refType: String, skey: String) { val args = - Map.of("fileId", fileId, "refId", refId, "refType", refType, "skey", skey) + setOf("fileId", fileId, "refId", refId, "refType", refType, "skey", skey) jdbcDao.executeUpdate( ("DELETE FROM file_ref" @@ -143,7 +143,7 @@ open class FileService( @Transactional(isolation = Isolation.SERIALIZABLE, rollbackFor = [Exception::class], readOnly = false) open fun deleteFile(fileId: Long?, skey: String?, filename: String?) { - val args = Map.of("fileId", fileId, "skey", skey, "filename", filename) + val args = setOf("fileId", fileId, "skey", skey, "filename", filename) jdbcDao.executeUpdate( ("DELETE FROM file_ref " diff --git a/src/main/java/com/ffii/tsms/modules/file/web/FileController.kt b/src/main/java/com/ffii/tsms/modules/file/web/FileController.kt index 5367ef3..e14c941 100644 --- a/src/main/java/com/ffii/tsms/modules/file/web/FileController.kt +++ b/src/main/java/com/ffii/tsms/modules/file/web/FileController.kt @@ -25,8 +25,8 @@ open class FileController (private val fileService: FileService) { @PostMapping("/list") @Throws(ServletRequestBindingException::class) fun listJson( - model: Model?, - request: HttpServletRequest?, +// model: Model?, +// request: HttpServletRequest?, @RequestBody req: @Valid FileReq ): RecordsRes> { val args: MutableMap = HashMap() @@ -40,8 +40,8 @@ open class FileController (private val fileService: FileService) { @PostMapping("/update") fun update( - model: Model?, - response: HttpServletResponse?, +// model: Model?, +// response: HttpServletResponse?, @RequestBody req: @Valid UpdateFileReq ): Map { val file: File = fileService.findFileByIdAndKey(req.fileId, req.skey).get() diff --git a/src/main/java/com/ffii/tsms/modules/file/web/UploadFileController.kt b/src/main/java/com/ffii/tsms/modules/file/web/UploadFileController.kt index cd8b0c2..63ae129 100644 --- a/src/main/java/com/ffii/tsms/modules/file/web/UploadFileController.kt +++ b/src/main/java/com/ffii/tsms/modules/file/web/UploadFileController.kt @@ -24,8 +24,8 @@ class UploadFileController(private val settingsService: SettingsService, private @PostMapping("/ul") @Throws(ServletRequestBindingException::class, IOException::class) fun uploadFile( - request: HttpServletRequest, - model: Model, +// request: HttpServletRequest, +// model: Model, @RequestParam refId: Long, @RequestParam refType: String, @RequestParam(defaultValue = StringUtils.EMPTY) refCode: String,