@@ -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<Int>() | |||
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() | |||
@@ -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?, | |||
@@ -6,7 +6,7 @@ import java.time.LocalDate | |||
data class NewTeamRequest ( | |||
@field:NotNull(message = "ids cannot be empty") | |||
val addStaffIds: List<Long>, | |||
val addStaffIds: List<Long>?, | |||
val deleteStaffIds: List<Long>?, | |||
val description: String, | |||
val id: Long? |
@@ -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<File> { | |||
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<FileRef> { | |||
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<FileRef> { | |||
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<FileBlob> { | |||
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 " | |||
@@ -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<Map<String, Any>> { | |||
val args: MutableMap<String, Any> = 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<String, Any> { | |||
val file: File = fileService.findFileByIdAndKey(req.fileId, req.skey).get() | |||
@@ -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, | |||