diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/GroupController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/GroupController.kt index 5238386..563345d 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/GroupController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/GroupController.kt @@ -38,9 +38,7 @@ class GroupController( @GetMapping("/{id}") @PreAuthorize("hasAnyAuthority('system:group:query:one')") fun getOne(@PathVariable id: Long): ResponseResult = - ResponseResult.databaseSuccess( - data = groupService.getOne(id) - ) + ResponseResult.databaseSuccess(data = groupService.getOne(id)) /** * Get group paging information @@ -76,7 +74,7 @@ class GroupController( @PreAuthorize("hasAnyAuthority('system:group:query:list', 'system:user:add:one', 'system:user:modify:one')") fun list(): ResponseResult> = ResponseResult.databaseSuccess( - data = groupService.listAll() + data = groupService.getList() ) /** @@ -94,11 +92,9 @@ class GroupController( @PostMapping @PreAuthorize("hasAnyAuthority('system:group:add:one')") fun add(@Valid @RequestBody groupAddParam: GroupAddParam): ResponseResult = - groupService.add(groupAddParam)?.let { - ResponseResult.databaseSuccess( - ResponseCode.DATABASE_INSERT_SUCCESS, data = it - ) - } ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_INSERT_FAILED) } + ResponseResult.databaseSuccess( + ResponseCode.DATABASE_INSERT_SUCCESS, data = groupService.add(groupAddParam) + ) /** * Update group @@ -115,11 +111,9 @@ class GroupController( @PutMapping @PreAuthorize("hasAnyAuthority('system:group:modify:one')") fun update(@Valid @RequestBody groupUpdateParam: GroupUpdateParam): ResponseResult = - groupService.update(groupUpdateParam)?.let { - ResponseResult.databaseSuccess( - ResponseCode.DATABASE_UPDATE_SUCCESS, data = it - ) - } ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_UPDATE_FILED) } + ResponseResult.databaseSuccess( + ResponseCode.DATABASE_UPDATE_SUCCESS, data = groupService.update(groupUpdateParam) + ) /** * Update status of group @@ -134,12 +128,10 @@ class GroupController( @Operation(summary = "修改用户组状态") @PatchMapping @PreAuthorize("hasAnyAuthority('system:group:modify:status')") - fun updateStatus(@Valid @RequestBody groupUpdateStatusParam: GroupUpdateStatusParam): ResponseResult = - if (groupService.status(groupUpdateStatusParam)) { - ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_SUCCESS) - } else { - ResponseResult.databaseFail(ResponseCode.DATABASE_UPDATE_FILED) - } + fun updateStatus(@Valid @RequestBody groupUpdateStatusParam: GroupUpdateStatusParam): ResponseResult { + groupService.status(groupUpdateStatusParam) + return ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_SUCCESS) + } /** * Delete group by ID diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/RoleController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/RoleController.kt index c92dee9..0a45bb8 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/RoleController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/RoleController.kt @@ -37,11 +37,8 @@ class RoleController( @Operation(summary = "获取单个角色") @GetMapping("/{id}") @PreAuthorize("hasAnyAuthority('system:role:query:one')") - fun getOne(@PathVariable id: Long): ResponseResult { - return ResponseResult.databaseSuccess( - data = roleService.getOne(id) - ) - } + fun getOne(@PathVariable id: Long): ResponseResult = + ResponseResult.databaseSuccess(data = roleService.getOne(id)) /** * Get role paging information @@ -57,11 +54,10 @@ class RoleController( @Operation(summary = "获取角色") @GetMapping @PreAuthorize("hasAnyAuthority('system:role:query:all')") - fun get(roleGetParam: RoleGetParam?): ResponseResult> { - return ResponseResult.databaseSuccess( + fun get(roleGetParam: RoleGetParam?): ResponseResult> = + ResponseResult.databaseSuccess( data = roleService.getPage(roleGetParam) ) - } /** * Get role list @@ -77,7 +73,7 @@ class RoleController( @PreAuthorize("hasAnyAuthority('system:role:query:list', 'system:group:add:one', 'system:group:modify:one', 'system:user:add:one', 'system:user:modify:one')") fun list(): ResponseResult> { return ResponseResult.databaseSuccess( - data = roleService.listAll() + data = roleService.getList() ) } @@ -95,13 +91,10 @@ class RoleController( @Operation(summary = "添加角色") @PostMapping @PreAuthorize("hasAnyAuthority('system:role:add:one')") - fun add(@Valid @RequestBody roleAddParam: RoleAddParam): ResponseResult { - return roleService.add(roleAddParam)?.let { - ResponseResult.databaseSuccess( - ResponseCode.DATABASE_INSERT_SUCCESS, data = it - ) - } ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_INSERT_FAILED) } - } + fun add(@Valid @RequestBody roleAddParam: RoleAddParam): ResponseResult = + ResponseResult.databaseSuccess( + ResponseCode.DATABASE_INSERT_SUCCESS, data = roleService.add(roleAddParam) + ) /** * Update role @@ -117,13 +110,10 @@ class RoleController( @Operation(summary = "修改角色") @PutMapping @PreAuthorize("hasAnyAuthority('system:role:modify:one')") - fun update(@Valid @RequestBody roleUpdateParam: RoleUpdateParam): ResponseResult { - return roleService.update(roleUpdateParam)?.let { - ResponseResult.databaseSuccess( - ResponseCode.DATABASE_UPDATE_SUCCESS, data = it - ) - } ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_UPDATE_FILED) } - } + fun update(@Valid @RequestBody roleUpdateParam: RoleUpdateParam): ResponseResult = + ResponseResult.databaseSuccess( + ResponseCode.DATABASE_UPDATE_SUCCESS, data = roleService.update(roleUpdateParam) + ) /** * Update status of role @@ -139,11 +129,8 @@ class RoleController( @PatchMapping @PreAuthorize("hasAnyAuthority('system:role:modify:status')") fun status(@Valid @RequestBody roleUpdateStatusParam: RoleUpdateStatusParam): ResponseResult { - return if (roleService.status(roleUpdateStatusParam)) { - ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_SUCCESS) - } else { - ResponseResult.databaseFail(ResponseCode.DATABASE_UPDATE_FILED) - } + roleService.status(roleUpdateStatusParam) + return ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_SUCCESS) } /** diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/UserController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/UserController.kt index 9cb4261..6c23fa7 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/UserController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/UserController.kt @@ -7,7 +7,6 @@ import org.springframework.web.bind.annotation.* import top.fatweb.oxygen.api.annotation.BaseController import top.fatweb.oxygen.api.entity.common.ResponseCode import top.fatweb.oxygen.api.entity.common.ResponseResult -import top.fatweb.oxygen.api.exception.NoRecordFoundException import top.fatweb.oxygen.api.param.permission.user.* import top.fatweb.oxygen.api.service.permission.IUserService import top.fatweb.oxygen.api.vo.PageVo @@ -38,9 +37,7 @@ class UserController( @Operation(summary = "获取当前用户信息") @GetMapping("info") fun getInfo(): ResponseResult = - userService.getInfo()?.let { - ResponseResult.databaseSuccess(data = it) - } ?: let { ResponseResult.databaseFail() } + ResponseResult.databaseSuccess(data = userService.getInfo()) /** * Get user by ID @@ -56,11 +53,7 @@ class UserController( @GetMapping("/{id}") @PreAuthorize("hasAnyAuthority('system:user:query:one')") fun getOne(@PathVariable id: Long): ResponseResult = - userService.getOne(id)?.let { - ResponseResult.databaseSuccess(data = it) - } ?: let { - throw NoRecordFoundException() - } + ResponseResult.databaseSuccess(data = userService.getOne(id)) /** * Get user paging information @@ -96,11 +89,9 @@ class UserController( @PostMapping @PreAuthorize("hasAnyAuthority('system:user:add:one')") fun add(@Valid @RequestBody userAddParam: UserAddParam): ResponseResult = - userService.add(userAddParam)?.let { - ResponseResult.databaseSuccess( - ResponseCode.DATABASE_INSERT_SUCCESS, data = it - ) - } ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_INSERT_FAILED) } + ResponseResult.databaseSuccess( + ResponseCode.DATABASE_INSERT_SUCCESS, data = userService.add(userAddParam) + ) /** * Update user @@ -117,11 +108,9 @@ class UserController( @PutMapping @PreAuthorize("hasAnyAuthority('system:user:modify:one')") fun update(@Valid @RequestBody userUpdateParam: UserUpdateParam): ResponseResult = - userService.update(userUpdateParam)?.let { - ResponseResult.databaseSuccess( - ResponseCode.DATABASE_UPDATE_SUCCESS, data = it - ) - } ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_UPDATE_FILED) } + ResponseResult.databaseSuccess( + ResponseCode.DATABASE_UPDATE_SUCCESS, data = userService.update(userUpdateParam) + ) /** * Update user password diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/BaseController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/BaseController.kt index d7d95b7..5d14167 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/BaseController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/BaseController.kt @@ -18,8 +18,7 @@ class BaseController( @Operation(summary = "获取单个基板") @GetMapping("/{id}") fun getOne(@PathVariable id: Long): ResponseResult = - toolBaseService.getOne(id)?.let { ResponseResult.databaseSuccess(data = it) } - ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_NO_RECORD_FOUND) } + ResponseResult.databaseSuccess(data = toolBaseService.getOne(id)) @Operation(summary = "获取基板") @GetMapping @@ -46,5 +45,5 @@ class BaseController( @DeleteMapping("/{id}") fun delete(@PathVariable id: Long): ResponseResult = if (toolBaseService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) - else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FILED) + else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FAILED) } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/CategoryController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/CategoryController.kt index 09ef95f..504e3d1 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/CategoryController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/CategoryController.kt @@ -25,8 +25,7 @@ class CategoryController( @Operation(summary = "获取单个类别") @GetMapping("/{id}") fun getOne(@PathVariable id: Long): ResponseResult = - toolCategoryService.getOne(id)?.let { ResponseResult.databaseSuccess(data = it) } - ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_NO_RECORD_FOUND) } + ResponseResult.databaseSuccess(data = toolCategoryService.getOne(id)) @Operation(summary = "获取类别") @GetMapping @@ -53,5 +52,5 @@ class CategoryController( @DeleteMapping("/{id}") fun delete(@PathVariable id: Long): ResponseResult = if (toolCategoryService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) - else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FILED) + else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FAILED) } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt index 8027b4b..e69c0c0 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt @@ -24,8 +24,7 @@ class EditController( @Operation(summary = "获取单个工具") @GetMapping("/{id}") fun getOne(@PathVariable id: Long): ResponseResult = - toolService.getOne(id)?.let { ResponseResult.databaseSuccess(data = it) } - ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_NO_RECORD_FOUND) } + ResponseResult.databaseSuccess(data = toolService.getOne(id)) @Operation(summary = "获取工具") @GetMapping @@ -52,5 +51,5 @@ class EditController( @DeleteMapping("/{id}") fun delete(@PathVariable id: Long): ResponseResult = if (toolService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) - else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FILED) + else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FAILED) } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/ManagementController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/ManagementController.kt index 1db647c..9e09628 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/ManagementController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/ManagementController.kt @@ -18,8 +18,7 @@ class ManagementController( @Operation(summary = "获取单个工具") @GetMapping("/{id}") fun getOne(@PathVariable id: Long): ResponseResult = - toolService.getOne(id)?.let { ResponseResult.databaseSuccess(data = it) } - ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_NO_RECORD_FOUND) } + ResponseResult.databaseSuccess(data = toolService.getOne(id)) @Operation(summary = "获取工具") @GetMapping @@ -46,5 +45,5 @@ class ManagementController( @DeleteMapping("/{id}") fun delete(@PathVariable id: Long): ResponseResult = if (toolService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) - else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FILED) + else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FAILED) } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/TemplateController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/TemplateController.kt index e9eb154..2067c58 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/TemplateController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/TemplateController.kt @@ -18,8 +18,7 @@ class TemplateController( @Operation(summary = "获取单个模板") @GetMapping("/{id}") fun getOne(@PathVariable id: Long): ResponseResult = - toolTemplateService.getOne(id)?.let { ResponseResult.databaseSuccess(data = it) } - ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_NO_RECORD_FOUND) } + ResponseResult.databaseSuccess(data = toolTemplateService.getOne(id)) @Operation(summary = "获取模板") @GetMapping @@ -46,5 +45,5 @@ class TemplateController( @DeleteMapping("/{id}") fun delete(@PathVariable id: Long): ResponseResult = if (toolTemplateService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) - else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FILED) + else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FAILED) } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolBaseConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolBaseConverter.kt index d9b3333..ba16e30 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolBaseConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolBaseConverter.kt @@ -1,7 +1,6 @@ package top.fatweb.oxygen.api.converter.tool import top.fatweb.oxygen.api.entity.tool.ToolBase -import top.fatweb.oxygen.api.param.tool.ToolBaseAddParam import top.fatweb.oxygen.api.vo.tool.ToolBaseVo object ToolBaseConverter { diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt index 4e3032c..047c15f 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt @@ -51,9 +51,9 @@ enum class ResponseCode(val code: Int) { DATABASE_INSERT_SUCCESS(BusinessCode.DATABASE, 10), DATABASE_INSERT_FAILED(BusinessCode.DATABASE, 15), DATABASE_UPDATE_SUCCESS(BusinessCode.DATABASE, 20), - DATABASE_UPDATE_FILED(BusinessCode.DATABASE, 25), + DATABASE_UPDATE_FAILED(BusinessCode.DATABASE, 25), DATABASE_DELETE_SUCCESS(BusinessCode.DATABASE, 30), - DATABASE_DELETE_FILED(BusinessCode.DATABASE, 35), + DATABASE_DELETE_FAILED(BusinessCode.DATABASE, 35), DATABASE_EXECUTE_ERROR(BusinessCode.DATABASE, 50), DATABASE_DUPLICATE_KEY(BusinessCode.DATABASE, 51), DATABASE_NO_RECORD_FOUND(BusinessCode.DATABASE, 52), diff --git a/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseDeleteException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseDeleteException.kt new file mode 100644 index 0000000..f6926b2 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseDeleteException.kt @@ -0,0 +1,3 @@ +package top.fatweb.oxygen.api.exception + +class DatabaseDeleteException(message: String = "Database delete failed"): RuntimeException(message) \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseInsertException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseInsertException.kt new file mode 100644 index 0000000..1744ea7 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseInsertException.kt @@ -0,0 +1,3 @@ +package top.fatweb.oxygen.api.exception + +class DatabaseInsertException(message: String = "Database insert failed"): RuntimeException(message) \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseSelectException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseSelectException.kt new file mode 100644 index 0000000..e8e1d2b --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseSelectException.kt @@ -0,0 +1,3 @@ +package top.fatweb.oxygen.api.exception + +class DatabaseSelectException(message: String = "Database select failed"): RuntimeException(message) \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseUpdateException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseUpdateException.kt new file mode 100644 index 0000000..c2fa87c --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseUpdateException.kt @@ -0,0 +1,3 @@ +package top.fatweb.oxygen.api.exception + +class DatabaseUpdateException(message: String = "Database update failed"): RuntimeException(message) \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt b/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt index a47a3c3..879627a 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt @@ -166,6 +166,26 @@ class ExceptionHandler { } /* SQL */ + is DatabaseSelectException -> { + logger.debug(e.localizedMessage, e) + ResponseResult.databaseFail(ResponseCode.DATABASE_SELECT_FAILED, e.localizedMessage, null) + } + + is DatabaseInsertException -> { + logger.debug(e.localizedMessage, e) + ResponseResult.databaseFail(ResponseCode.DATABASE_INSERT_FAILED, e.localizedMessage, null) + } + + is DatabaseUpdateException -> { + logger.debug(e.localizedMessage, e) + ResponseResult.databaseFail(ResponseCode.DATABASE_UPDATE_FAILED, e.localizedMessage, null) + } + + is DatabaseDeleteException -> { + logger.debug(e.localizedMessage, e) + ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FAILED, e.localizedMessage, null) + } + is BadSqlGrammarException -> { logger.debug(e.localizedMessage, e) ResponseResult.fail(ResponseCode.DATABASE_EXECUTE_ERROR, "Incorrect SQL syntax", null) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/api/v1/impl/AvatarServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/api/v1/impl/AvatarServiceImpl.kt index b117db4..9fc383d 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/api/v1/impl/AvatarServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/api/v1/impl/AvatarServiceImpl.kt @@ -59,12 +59,12 @@ class AvatarServiceImpl : IAvatarService { if (avatarBaseParam == null || avatarBaseParam.colors.isNullOrEmpty()) TriangleAvatar.newAvatarBuilder() else TriangleAvatar.newAvatarBuilder( - *avatarBaseParam.colors!!.map { decodeColor(it) }.toTypedArray() + *avatarBaseParam.colors!!.map(this::decodeColor).toTypedArray() ) ).apply { - avatarBaseParam?.size?.let { size(it, it) } - avatarBaseParam?.margin?.let { margin(it) } - avatarBaseParam?.padding?.let { padding(it) } + avatarBaseParam?.size?.let(this::size) + avatarBaseParam?.margin?.let(this::margin) + avatarBaseParam?.padding?.let(this::padding) avatarBaseParam?.background?.let { layers(ColorPaintBackgroundLayer(decodeColor(it))) } }.build() @@ -79,12 +79,12 @@ class AvatarServiceImpl : IAvatarService { if (avatarBaseParam == null || avatarBaseParam.colors.isNullOrEmpty()) SquareAvatar.newAvatarBuilder() else SquareAvatar.newAvatarBuilder( - *avatarBaseParam.colors!!.map { decodeColor(it) }.toTypedArray() + *avatarBaseParam.colors!!.map(this::decodeColor).toTypedArray() ) ).apply { - avatarBaseParam?.size?.let { size(it, it) } - avatarBaseParam?.margin?.let { margin(it) } - avatarBaseParam?.padding?.let { padding(it) } + avatarBaseParam?.size?.let(this::size) + avatarBaseParam?.margin?.let(this::margin) + avatarBaseParam?.padding?.let(this::padding) avatarBaseParam?.background?.let { layers(ColorPaintBackgroundLayer(decodeColor(it))) } }.build() @@ -96,9 +96,9 @@ class AvatarServiceImpl : IAvatarService { override fun identicon(avatarBaseParam: AvatarBaseParam?): ByteArray { val avatar = IdenticonAvatar.newAvatarBuilder().apply { - avatarBaseParam?.size?.let { size(it, it) } - avatarBaseParam?.margin?.let { margin(it) } - avatarBaseParam?.padding?.let { padding(it) } + avatarBaseParam?.size?.let(this::size) + avatarBaseParam?.margin?.let(this::margin) + avatarBaseParam?.padding?.let(this::padding) if (avatarBaseParam != null && !avatarBaseParam.colors.isNullOrEmpty()) { color(decodeColor(avatarBaseParam.colors!!.random())) } @@ -114,9 +114,9 @@ class AvatarServiceImpl : IAvatarService { override fun github(avatarGitHubParam: AvatarGitHubParam?): ByteArray { val avatar = (avatarGitHubParam?.let { GitHubAvatar.newAvatarBuilder(it.elementSize, it.precision) } ?: let { GitHubAvatar.newAvatarBuilder(400, 5) }).apply { - avatarGitHubParam?.size?.let { size(it, it) } - avatarGitHubParam?.margin?.let { margin(it) } - avatarGitHubParam?.padding?.let { padding(it) } + avatarGitHubParam?.size?.let(this::size) + avatarGitHubParam?.margin?.let(this::margin) + avatarGitHubParam?.padding?.let(this::padding) if (avatarGitHubParam != null && !avatarGitHubParam.colors.isNullOrEmpty()) { color(decodeColor(avatarGitHubParam.colors!!.random())) } diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IGroupService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IGroupService.kt index 761ef8d..9db4c4f 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IGroupService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IGroupService.kt @@ -16,6 +16,17 @@ import top.fatweb.oxygen.api.vo.permission.base.GroupVo * @see Group */ interface IGroupService : IService { + /** + * Get one group by ID + * + * @param id ID + * @return GroupWithRoleVo object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see GroupWithRoleVo + */ + fun getOne(id: Long): GroupWithRoleVo + /** * Get group in page * @@ -29,17 +40,6 @@ interface IGroupService : IService { */ fun getPage(groupGetParam: GroupGetParam?): PageVo - /** - * Get one group by ID - * - * @param id ID - * @return GroupWithRoleVo object - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - * @see GroupWithRoleVo - */ - fun getOne(id: Long): GroupWithRoleVo? - /** * Get all group in list * @@ -48,7 +48,7 @@ interface IGroupService : IService { * @since 1.0.0 * @see GroupVo */ - fun listAll(): List + fun getList(): List /** * Add group @@ -60,7 +60,7 @@ interface IGroupService : IService { * @see GroupAddParam * @see GroupVo */ - fun add(groupAddParam: GroupAddParam): GroupVo? + fun add(groupAddParam: GroupAddParam): GroupVo /** * Update group @@ -72,7 +72,7 @@ interface IGroupService : IService { * @see GroupUpdateParam * @see GroupVo */ - fun update(groupUpdateParam: GroupUpdateParam): GroupVo? + fun update(groupUpdateParam: GroupUpdateParam): GroupVo /** * Update status of group @@ -83,7 +83,7 @@ interface IGroupService : IService { * @since 1.0.0 * @see GroupUpdateStatusParam */ - fun status(groupUpdateStatusParam: GroupUpdateStatusParam): Boolean + fun status(groupUpdateStatusParam: GroupUpdateStatusParam) /** * Delete group by ID diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IRoleService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IRoleService.kt index c12c6d8..37d6da7 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IRoleService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IRoleService.kt @@ -16,6 +16,17 @@ import top.fatweb.oxygen.api.vo.permission.base.RoleVo * @see Role */ interface IRoleService : IService { + /** + * Get user by ID + * + * @param id ID + * @return RoleWithPowerVo object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see RoleWithPowerVo + */ + fun getOne(id: Long): RoleWithPowerVo + /** * Get role in page * @@ -29,17 +40,6 @@ interface IRoleService : IService { */ fun getPage(roleGetParam: RoleGetParam?): PageVo - /** - * Get user by ID - * - * @param id ID - * @return RoleWithPowerVo object - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - * @see RoleWithPowerVo - */ - fun getOne(id: Long): RoleWithPowerVo? - /** * Get all role in list * @@ -48,7 +48,7 @@ interface IRoleService : IService { * @since 1.0.0 * @see RoleVo */ - fun listAll(): List + fun getList(): List /** * Add role @@ -60,7 +60,7 @@ interface IRoleService : IService { * @see RoleAddParam * @see RoleVo */ - fun add(roleAddParam: RoleAddParam): RoleVo? + fun add(roleAddParam: RoleAddParam): RoleVo /** * Update role @@ -72,7 +72,7 @@ interface IRoleService : IService { * @see RoleUpdateParam * @see RoleVo */ - fun update(roleUpdateParam: RoleUpdateParam): RoleVo? + fun update(roleUpdateParam: RoleUpdateParam): RoleVo /** * Update status of role @@ -83,7 +83,7 @@ interface IRoleService : IService { * @since 1.0.0 * @see RoleUpdateStatusParam */ - fun status(roleUpdateStatusParam: RoleUpdateStatusParam): Boolean + fun status(roleUpdateStatusParam: RoleUpdateStatusParam) /** * Delete role by ID diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IUserService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IUserService.kt index fe38623..3406bf8 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IUserService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IUserService.kt @@ -37,7 +37,18 @@ interface IUserService : IService { * @since 1.0.0 * @see UserWithPowerInfoVo */ - fun getInfo(): UserWithPowerInfoVo? + fun getInfo(): UserWithPowerInfoVo + + /** + * Get one user by ID + * + * @param id ID + * @return UserWithRoleInfoVo object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see UserWithRoleInfoVo + */ + fun getOne(id: Long): UserWithRoleInfoVo /** * Get user in page @@ -52,17 +63,6 @@ interface IUserService : IService { */ fun getPage(userGetParam: UserGetParam?): PageVo - /** - * Get one user by ID - * - * @param id ID - * @return UserWithRoleInfoVo object - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - * @see UserWithRoleInfoVo - */ - fun getOne(id: Long): UserWithRoleInfoVo? - /** * Get all user as list * @@ -71,7 +71,7 @@ interface IUserService : IService { * @since 1.0.0 * @see UserWithInfoVo */ - fun listAll(): List + fun getList(): List /** * Add user @@ -83,7 +83,7 @@ interface IUserService : IService { * @see UserAddParam * @see UserWithPasswordRoleInfoVo */ - fun add(userAddParam: UserAddParam): UserWithPasswordRoleInfoVo? + fun add(userAddParam: UserAddParam): UserWithPasswordRoleInfoVo /** * Update user @@ -95,7 +95,7 @@ interface IUserService : IService { * @see UserUpdateParam * @see UserWithRoleInfoVo */ - fun update(userUpdateParam: UserUpdateParam): UserWithRoleInfoVo? + fun update(userUpdateParam: UserUpdateParam): UserWithRoleInfoVo /** * Update user password diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/AuthenticationServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/AuthenticationServiceImpl.kt index dc6fd10..45c7a58 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/AuthenticationServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/AuthenticationServiceImpl.kt @@ -92,7 +92,7 @@ class AuthenticationServiceImpl( sendVerifyMail(user.username!!, user.verify!!, registerParam.email!!) - val loginVo = this.login(request, registerParam.username!!, registerParam.password!!) + val loginVo = this.login(request, registerParam.username, registerParam.password!!) return RegisterVo(token = loginVo.token, userId = loginVo.userId) } diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/GroupServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/GroupServiceImpl.kt index 246137c..d81da51 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/GroupServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/GroupServiceImpl.kt @@ -8,6 +8,9 @@ import org.springframework.transaction.annotation.Transactional import top.fatweb.oxygen.api.converter.permission.GroupConverter import top.fatweb.oxygen.api.entity.permission.Group import top.fatweb.oxygen.api.entity.permission.RRoleGroup +import top.fatweb.oxygen.api.exception.DatabaseInsertException +import top.fatweb.oxygen.api.exception.DatabaseUpdateException +import top.fatweb.oxygen.api.exception.NoRecordFoundException import top.fatweb.oxygen.api.mapper.permission.GroupMapper import top.fatweb.oxygen.api.param.permission.group.* import top.fatweb.oxygen.api.service.permission.IGroupService @@ -54,55 +57,51 @@ class GroupServiceImpl( return GroupConverter.groupPageToGroupWithRolePageVo(groupPage) } - override fun getOne(id: Long): GroupWithRoleVo? { - return baseMapper.selectOneById(id)?.let { GroupConverter.groupToGroupWithRoleVo(it) } ?: let { null } - } + override fun getOne(id: Long): GroupWithRoleVo = + baseMapper.selectOneById(id)?.let(GroupConverter::groupToGroupWithRoleVo) ?: throw NoRecordFoundException() - override fun listAll(): List { - val groups = this.list() - - return groups.map { GroupConverter.groupToGroupVo(it) } - } + override fun getList(): List = this.list().map(GroupConverter::groupToGroupVo) @Transactional - override fun add(groupAddParam: GroupAddParam): GroupVo? { + override fun add(groupAddParam: GroupAddParam): GroupVo { val group = GroupConverter.groupAddParamToGroup(groupAddParam) - if (baseMapper.insert(group) == 1) { - if (group.roles.isNullOrEmpty()) { - return GroupConverter.groupToGroupVo(group) - } - - if (rRoleGroupService.saveBatch(group.roles!!.map { - RRoleGroup().apply { - groupId = group.id - roleId = it.id - } - })) { - return GroupConverter.groupToGroupVo(group) - } + if (baseMapper.insert(group) != 1) { + throw DatabaseInsertException() } - return null + if (group.roles.isNullOrEmpty()) { + return GroupConverter.groupToGroupVo(group) + } + + rRoleGroupService.saveBatch(group.roles!!.map { + RRoleGroup().apply { + groupId = group.id + roleId = it.id + } + }) + + return GroupConverter.groupToGroupVo(group) } @Transactional - override fun update(groupUpdateParam: GroupUpdateParam): GroupVo? { + override fun update(groupUpdateParam: GroupUpdateParam): GroupVo { val group = GroupConverter.groupUpdateParamToGroup(groupUpdateParam) + + if (baseMapper.updateById(group) != 1) { + throw DatabaseUpdateException() + } + val oldRoleList = rRoleGroupService.list( KtQueryWrapper(RRoleGroup()).select(RRoleGroup::roleId).eq(RRoleGroup::groupId, groupUpdateParam.id) ).map { it.roleId } val addRoleIds = HashSet() val removeRoleIds = HashSet() - groupUpdateParam.roleIds?.forEach { addRoleIds.add(it) } + groupUpdateParam.roleIds?.forEach(addRoleIds::add) oldRoleList.forEach { - if (it != null) { - removeRoleIds.add(it) - } + it?.let(removeRoleIds::add) } removeRoleIds.removeAll(addRoleIds) - oldRoleList.toSet().let { addRoleIds.removeAll(it) } - - baseMapper.updateById(group) + oldRoleList.toSet().let(addRoleIds::removeAll) removeRoleIds.forEach { rRoleGroupService.remove( @@ -124,13 +123,15 @@ class GroupServiceImpl( return GroupConverter.groupToGroupVo(group) } - override fun status(groupUpdateStatusParam: GroupUpdateStatusParam): Boolean { + override fun status(groupUpdateStatusParam: GroupUpdateStatusParam) { updateById(GroupConverter.groupUpdateStatusParamToGroup(groupUpdateStatusParam)).let { - if (it && !groupUpdateStatusParam.enable) { - groupUpdateStatusParam.id?.let { id -> offlineUser(id) } + if (!it) { + throw DatabaseUpdateException() } - return it + if (!groupUpdateStatusParam.enable) { + groupUpdateStatusParam.id?.let { id -> offlineUser(id) } + } } } diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RoleServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RoleServiceImpl.kt index fdb70e6..8ea381c 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RoleServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RoleServiceImpl.kt @@ -8,6 +8,9 @@ import org.springframework.transaction.annotation.Transactional import top.fatweb.oxygen.api.converter.permission.RoleConverter import top.fatweb.oxygen.api.entity.permission.RPowerRole import top.fatweb.oxygen.api.entity.permission.Role +import top.fatweb.oxygen.api.exception.DatabaseInsertException +import top.fatweb.oxygen.api.exception.DatabaseUpdateException +import top.fatweb.oxygen.api.exception.NoRecordFoundException import top.fatweb.oxygen.api.mapper.permission.RoleMapper import top.fatweb.oxygen.api.param.permission.role.* import top.fatweb.oxygen.api.service.permission.* @@ -58,60 +61,54 @@ class RoleServiceImpl( return RoleConverter.rolePageToRoleWithPowerPageVo(rolePage) } - override fun getOne(id: Long): RoleWithPowerVo? { - return baseMapper.selectOneById(id)?.let { RoleConverter.roleToRoleWithPowerVo(it) } ?: let { null } - } - - override fun listAll(): List { - val roles = this.list() - - return roles.map { RoleConverter.roleToRoleVo(it) } - } + override fun getOne(id: Long): RoleWithPowerVo = + baseMapper.selectOneById(id)?.let(RoleConverter::roleToRoleWithPowerVo) ?: throw NoRecordFoundException() + override fun getList(): List = this.list().map(RoleConverter::roleToRoleVo) @Transactional - override fun add(roleAddParam: RoleAddParam): RoleVo? { - val fullPowerIds = roleAddParam.powerIds?.let { getFullPowerIds(it) } + override fun add(roleAddParam: RoleAddParam): RoleVo { + val fullPowerIds = roleAddParam.powerIds?.let(this::getFullPowerIds) val role = RoleConverter.roleAddParamToRole(roleAddParam) - if (baseMapper.insert(role) == 1) { - if (fullPowerIds.isNullOrEmpty()) { - return RoleConverter.roleToRoleVo(role) - } - - if (rPowerRoleService.saveBatch(fullPowerIds.map { - RPowerRole().apply { - roleId = role.id - powerId = it - } - })) { - return RoleConverter.roleToRoleVo(role) - } + if (baseMapper.insert(role) != 1) { + throw DatabaseInsertException() } - return null + if (fullPowerIds.isNullOrEmpty()) { + return RoleConverter.roleToRoleVo(role) + } + + rPowerRoleService.saveBatch(fullPowerIds.map { + RPowerRole().apply { + roleId = role.id + powerId = it + } + }) + return RoleConverter.roleToRoleVo(role) } @Transactional - override fun update(roleUpdateParam: RoleUpdateParam): RoleVo? { - val fullPowerIds = roleUpdateParam.powerIds?.let { getFullPowerIds(it) } + override fun update(roleUpdateParam: RoleUpdateParam): RoleVo { + val fullPowerIds = roleUpdateParam.powerIds?.let(this::getFullPowerIds) val role = RoleConverter.roleUpdateParamToRole(roleUpdateParam) + + if (baseMapper.updateById(role) != 1) { + throw DatabaseUpdateException() + } + val oldPowerList = rPowerRoleService.list( KtQueryWrapper(RPowerRole()).select(RPowerRole::powerId).eq(RPowerRole::roleId, roleUpdateParam.id) ).map { it.powerId } val addPowerIds = HashSet() val removePowerIds = HashSet() - fullPowerIds?.forEach { addPowerIds.add(it) } + fullPowerIds?.forEach(addPowerIds::add) oldPowerList.forEach { - if (it != null) { - removePowerIds.add(it) - } + it?.let(removePowerIds::add) } removePowerIds.removeAll(addPowerIds) - oldPowerList.toSet().let { addPowerIds.removeAll(it) } - - baseMapper.updateById(role) + oldPowerList.toSet().let(addPowerIds::removeAll) removePowerIds.forEach { rPowerRoleService.remove( @@ -133,13 +130,15 @@ class RoleServiceImpl( return RoleConverter.roleToRoleVo(role) } - override fun status(roleUpdateStatusParam: RoleUpdateStatusParam): Boolean { + override fun status(roleUpdateStatusParam: RoleUpdateStatusParam) { updateById(RoleConverter.roleUpdateStatusParamToRole(roleUpdateStatusParam)).let { - if (it && !roleUpdateStatusParam.enable) { - roleUpdateStatusParam.id?.let { id -> offlineUser(id) } + if (!it) { + throw DatabaseUpdateException() } - return it + if (!roleUpdateStatusParam.enable) { + roleUpdateStatusParam.id?.let { id -> offlineUser(id) } + } } } diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserServiceImpl.kt index 1758246..b698886 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserServiceImpl.kt @@ -11,11 +11,14 @@ import org.springframework.security.crypto.password.PasswordEncoder import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional import top.fatweb.oxygen.api.converter.permission.UserConverter -import top.fatweb.oxygen.api.entity.permission.User import top.fatweb.oxygen.api.entity.permission.RUserGroup -import top.fatweb.oxygen.api.entity.permission.UserInfo import top.fatweb.oxygen.api.entity.permission.RUserRole +import top.fatweb.oxygen.api.entity.permission.User +import top.fatweb.oxygen.api.entity.permission.UserInfo +import top.fatweb.oxygen.api.exception.DatabaseInsertException +import top.fatweb.oxygen.api.exception.DatabaseUpdateException import top.fatweb.oxygen.api.exception.NoRecordFoundException +import top.fatweb.oxygen.api.exception.UserNotFoundException import top.fatweb.oxygen.api.mapper.permission.UserMapper import top.fatweb.oxygen.api.param.permission.user.* import top.fatweb.oxygen.api.service.permission.* @@ -25,6 +28,7 @@ import top.fatweb.oxygen.api.util.StrUtil import top.fatweb.oxygen.api.util.WebUtil import top.fatweb.oxygen.api.vo.PageVo import top.fatweb.oxygen.api.vo.permission.UserWithPasswordRoleInfoVo +import top.fatweb.oxygen.api.vo.permission.UserWithPowerInfoVo import top.fatweb.oxygen.api.vo.permission.UserWithRoleInfoVo import java.time.LocalDateTime import java.time.ZoneOffset @@ -76,8 +80,13 @@ class UserServiceImpl( return user } - override fun getInfo() = WebUtil.getLoginUsername() - ?.let { username -> getUserWithPowerByAccount(username)?.let { UserConverter.userToUserWithPowerInfoVo(it) } } + override fun getInfo(): UserWithPowerInfoVo = + WebUtil.getLoginUsername()?.let(this::getUserWithPowerByAccount)?.let(UserConverter::userToUserWithPowerInfoVo) + ?: throw UserNotFoundException() + + override fun getOne(id: Long): UserWithRoleInfoVo = + baseMapper.selectOneWithRoleInfoById(id)?.let(UserConverter::userToUserWithRoleInfoVo) + ?: throw UserNotFoundException() override fun getPage(userGetParam: UserGetParam?): PageVo { val userIdsPage = Page(userGetParam?.currentPage ?: 1, userGetParam?.pageSize ?: 20) @@ -99,13 +108,10 @@ class UserServiceImpl( return UserConverter.userPageToUserWithRoleInfoPageVo(userPage) } - override fun getOne(id: Long) = - baseMapper.selectOneWithRoleInfoById(id)?.let { UserConverter.userToUserWithRoleInfoVo(it) } - - override fun listAll() = baseMapper.selectListWithInfo().map { UserConverter.userToUserWithInfoVo(it) } + override fun getList() = baseMapper.selectListWithInfo().map(UserConverter::userToUserWithInfoVo) @Transactional - override fun add(userAddParam: UserAddParam): UserWithPasswordRoleInfoVo? { + override fun add(userAddParam: UserAddParam): UserWithPasswordRoleInfoVo { val rawPassword = if (userAddParam.password.isNullOrBlank()) StrUtil.getRandomPassword(10) else userAddParam.password val user = UserConverter.userAddParamToUser(userAddParam) @@ -117,37 +123,38 @@ class UserServiceImpl( }-${UUID.randomUUID()}-${UUID.randomUUID()}-${UUID.randomUUID()}" } - if (this.save(user)) { - user.userInfo?.let { userInfoService.save(it.apply { userId = user.id }) } - - if (!user.roles.isNullOrEmpty()) { - rUserRoleService.saveBatch(user.roles!!.map { - RUserRole().apply { - userId = user.id - roleId = it.id - } - }) - } - - if (!user.groups.isNullOrEmpty()) { - rUserGroupService.saveBatch(user.groups!!.map { - RUserGroup().apply { - userId = user.id - groupId = it.id - } - }) - } - - user.password = rawPassword - - return UserConverter.userToUserWithPasswordRoleInfoVo(user) + if (!this.save(user)) { + throw DatabaseInsertException() } - return null + + user.userInfo?.apply { userId = user.id }?.let(userInfoService::save) + + if (!user.roles.isNullOrEmpty()) { + rUserRoleService.saveBatch(user.roles!!.map { + RUserRole().apply { + userId = user.id + roleId = it.id + } + }) + } + + if (!user.groups.isNullOrEmpty()) { + rUserGroupService.saveBatch(user.groups!!.map { + RUserGroup().apply { + userId = user.id + groupId = it.id + } + }) + } + + user.password = rawPassword + + return UserConverter.userToUserWithPasswordRoleInfoVo(user) } @Transactional - override fun update(userUpdateParam: UserUpdateParam): UserWithRoleInfoVo? { + override fun update(userUpdateParam: UserUpdateParam): UserWithRoleInfoVo { val user = UserConverter.userUpdateParamToUser(userUpdateParam) user.updateTime = LocalDateTime.now(ZoneOffset.UTC) @@ -156,28 +163,24 @@ class UserServiceImpl( ).map { it.roleId } val addRoleIds = HashSet() val removeRoleIds = HashSet() - userUpdateParam.roleIds?.forEach { addRoleIds.add(it) } + userUpdateParam.roleIds?.forEach(addRoleIds::add) oldRoleList.forEach { - if (it != null) { - removeRoleIds.add(it) - } + it?.let(removeRoleIds::add) } removeRoleIds.removeAll(addRoleIds) - oldRoleList.toSet().let { addRoleIds.removeAll(it) } + oldRoleList.toSet().let(addRoleIds::removeAll) val oldGroupList = rUserGroupService.list( KtQueryWrapper(RUserGroup()).select(RUserGroup::groupId).eq(RUserGroup::userId, userUpdateParam.id) ).map { it.groupId } val addGroupIds = HashSet() val removeGroupIds = HashSet() - userUpdateParam.groupIds?.forEach { addGroupIds.add(it) } + userUpdateParam.groupIds?.forEach(addGroupIds::add) oldGroupList.forEach { - if (it != null) { - removeGroupIds.add(it) - } + it?.let(removeGroupIds::add) } removeGroupIds.removeAll(addGroupIds) - oldGroupList.toSet().let { addGroupIds.removeAll(it) } + oldGroupList.toSet().let(addGroupIds::removeAll) this.updateById(user) this.update( @@ -252,7 +255,9 @@ class UserServiceImpl( ) .set(User::updateTime, LocalDateTime.now(ZoneOffset.UTC)) - this.update(wrapper) + if (!this.update(wrapper)) { + throw DatabaseUpdateException() + } userUpdatePasswordParam.id?.let { WebUtil.offlineUser(redisUtil, it) } } ?: let { diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SettingsServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SettingsServiceImpl.kt index c107aa4..aa3a7e5 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SettingsServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SettingsServiceImpl.kt @@ -50,7 +50,7 @@ class SettingsServiceImpl : ISettingsService { port = SettingsOperator.getMailValue(MailSettings::port), securityType = SettingsOperator.getMailValue(MailSettings::securityType), username = SettingsOperator.getMailValue(MailSettings::username), - password = SettingsOperator.getMailValue(MailSettings::password)?.let { StrUtil.md5(it) }, + password = SettingsOperator.getMailValue(MailSettings::password)?.let(StrUtil::md5), from = SettingsOperator.getMailValue(MailSettings::from), fromName = SettingsOperator.getMailValue(MailSettings::fromName) ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolBaseService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolBaseService.kt index 0ccfff9..f4e9fbb 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolBaseService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolBaseService.kt @@ -2,11 +2,9 @@ package top.fatweb.oxygen.api.service.tool import com.baomidou.mybatisplus.extension.service.IService import top.fatweb.oxygen.api.entity.tool.ToolBase -import top.fatweb.oxygen.api.entity.tool.ToolCategory import top.fatweb.oxygen.api.param.tool.ToolBaseAddParam import top.fatweb.oxygen.api.param.tool.ToolBaseUpdateParam import top.fatweb.oxygen.api.vo.tool.ToolBaseVo -import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo /** * Tool base service interface @@ -17,7 +15,7 @@ import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo * @see ToolBase */ interface IToolBaseService : IService { - fun getOne(id: Long): ToolBaseVo? + fun getOne(id: Long): ToolBaseVo fun get(): List diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolCategoryService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolCategoryService.kt index c661773..4f70553 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolCategoryService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolCategoryService.kt @@ -15,7 +15,7 @@ import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo * @see ToolCategory */ interface IToolCategoryService : IService { - fun getOne(id: Long): ToolCategoryVo? + fun getOne(id: Long): ToolCategoryVo fun get(): List diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolService.kt index d32a1a5..69ef68c 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolService.kt @@ -15,7 +15,7 @@ import top.fatweb.oxygen.api.vo.tool.ToolVo * @see Tool */ interface IToolService : IService { - fun getOne(id: Long): ToolVo? + fun getOne(id: Long): ToolVo fun get(): List diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolTemplateService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolTemplateService.kt index 3fcdf81..7d29168 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolTemplateService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolTemplateService.kt @@ -15,7 +15,7 @@ import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo * @see ToolTemplate */ interface IToolTemplateService : IService { - fun getOne(id: Long): ToolTemplateVo? + fun getOne(id: Long): ToolTemplateVo fun get(): List diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt index 4b338da..445c830 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt @@ -28,7 +28,8 @@ import top.fatweb.oxygen.api.vo.tool.ToolBaseVo class ToolBaseServiceImpl( private val toolDataService: IToolDataService ) : ServiceImpl(), IToolBaseService { - override fun getOne(id: Long): ToolBaseVo? = baseMapper.selectOne(id)?.let(ToolBaseConverter::toolBaseToToolBaseVo) + override fun getOne(id: Long): ToolBaseVo = + baseMapper.selectOne(id)?.let(ToolBaseConverter::toolBaseToToolBaseVo) ?: throw NoRecordFoundException() override fun get(): List = baseMapper.selectList().map(ToolBaseConverter::toolBaseToToolBaseVo) @@ -72,7 +73,7 @@ class ToolBaseServiceImpl( name = toolBaseUpdateParam.name }) - return this.getOne(toolBase.id!!)!! + return this.getOne(toolBase.id!!) } @Transactional diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolCategoryServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolCategoryServiceImpl.kt index a9c408b..d200bb4 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolCategoryServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolCategoryServiceImpl.kt @@ -2,9 +2,11 @@ package top.fatweb.oxygen.api.service.tool.impl import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl import org.springframework.stereotype.Service -import org.springframework.transaction.annotation.Transactional import top.fatweb.oxygen.api.converter.tool.ToolCategoryConverter import top.fatweb.oxygen.api.entity.tool.ToolCategory +import top.fatweb.oxygen.api.exception.DatabaseInsertException +import top.fatweb.oxygen.api.exception.DatabaseUpdateException +import top.fatweb.oxygen.api.exception.NoRecordFoundException import top.fatweb.oxygen.api.mapper.tool.ToolCategoryMapper import top.fatweb.oxygen.api.param.tool.ToolCategoryAddParam import top.fatweb.oxygen.api.param.tool.ToolCategoryUpdateParam @@ -23,8 +25,8 @@ import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo */ @Service class ToolCategoryServiceImpl : ServiceImpl(), IToolCategoryService { - override fun getOne(id: Long): ToolCategoryVo? = - this.getById(id)?.let(ToolCategoryConverter::toolCategoryToToolCategoryVo) + override fun getOne(id: Long): ToolCategoryVo = + this.getById(id)?.let(ToolCategoryConverter::toolCategoryToToolCategoryVo) ?: throw NoRecordFoundException() override fun get(): List = this.list().map(ToolCategoryConverter::toolCategoryToToolCategoryVo) @@ -32,7 +34,9 @@ class ToolCategoryServiceImpl : ServiceImpl(), override fun add(toolCategoryAddParam: ToolCategoryAddParam): ToolCategoryVo { val toolCategory = ToolCategoryConverter.toolCategoryAddParamToToolCategory(toolCategoryAddParam) - this.save(toolCategory) + if (!this.save(toolCategory)) { + throw DatabaseInsertException() + } return ToolCategoryConverter.toolCategoryToToolCategoryVo(toolCategory) } @@ -40,7 +44,9 @@ class ToolCategoryServiceImpl : ServiceImpl(), override fun update(toolCategoryUpdateParam: ToolCategoryUpdateParam): ToolCategoryVo { val toolCategory = ToolCategoryConverter.toolCategoryUpdateParamToToolCategory(toolCategoryUpdateParam) - this.updateById(toolCategory) + if (this.updateById(toolCategory)) { + throw DatabaseUpdateException() + } return ToolCategoryConverter.toolCategoryToToolCategoryVo(toolCategory) } diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolServiceImpl.kt index f48ca96..ca982af 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolServiceImpl.kt @@ -10,7 +10,6 @@ import top.fatweb.oxygen.api.entity.tool.Tool import top.fatweb.oxygen.api.entity.tool.ToolData import top.fatweb.oxygen.api.exception.NoRecordFoundException import top.fatweb.oxygen.api.exception.ToolHasPublish -import top.fatweb.oxygen.api.exception.UserNotFoundException import top.fatweb.oxygen.api.mapper.tool.ToolMapper import top.fatweb.oxygen.api.param.tool.ToolAddParam import top.fatweb.oxygen.api.param.tool.ToolUpdateParam @@ -36,14 +35,15 @@ class ToolServiceImpl( private val rToolCategoryService: IRToolCategoryService, private val userService: IUserService ) : ServiceImpl(), IToolService { - override fun getOne(id: Long): ToolVo? = baseMapper.selectOne(id)?.let(ToolConverter::toolToToolVo) + override fun getOne(id: Long): ToolVo = + baseMapper.selectOne(id)?.let(ToolConverter::toolToToolVo) ?: throw NoRecordFoundException() override fun get(): List = baseMapper.selectList().map(ToolConverter::toolToToolVo) @Transactional override fun add(toolAddParam: ToolAddParam): ToolVo { - toolBaseService.getOne(toolAddParam.baseId!!) ?: throw NoRecordFoundException() - userService.getOne(toolAddParam.authorId!!) ?: throw UserNotFoundException() + toolBaseService.getOne(toolAddParam.baseId!!) + userService.getOne(toolAddParam.authorId!!) val newSource = ToolData().apply { data = toolAddParam.source } val newDist = ToolData().apply { data = toolAddParam.dist } @@ -74,7 +74,7 @@ class ToolServiceImpl( }) } - return this.getOne(tool.id!!)!! + return this.getOne(tool.id!!) } @Transactional @@ -83,7 +83,7 @@ class ToolServiceImpl( if (tool.publish == 1) { throw ToolHasPublish() } - userService.getOne(toolUpdateParam.authorId!!) ?: throw UserNotFoundException() + userService.getOne(toolUpdateParam.authorId!!) toolDataService.updateById(ToolData().apply { id = tool.sourceId @@ -106,9 +106,9 @@ class ToolServiceImpl( keywords = toolUpdateParam.keywords }) - // TODO + // TODO Category process - return this.getOne(tool.id!!)!! + return this.getOne(tool.id!!) } @Transactional diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolTemplateServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolTemplateServiceImpl.kt index f78b226..872b24a 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolTemplateServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolTemplateServiceImpl.kt @@ -30,15 +30,16 @@ class ToolTemplateServiceImpl( private val toolDataService: IToolDataService, private val toolBaseService: IToolBaseService ) : ServiceImpl(), IToolTemplateService { - override fun getOne(id: Long): ToolTemplateVo? = + override fun getOne(id: Long): ToolTemplateVo = baseMapper.selectOne(id)?.let(ToolTemplateConverter::toolTemplateToToolTemplateVo) + ?: throw NoRecordFoundException() override fun get(): List = baseMapper.selectList().map(ToolTemplateConverter::toolTemplateToToolTemplateVo) @Transactional override fun add(toolTemplateAddParam: ToolTemplateAddParam): ToolTemplateVo { - toolBaseService.getOne(toolTemplateAddParam.baseId!!) ?: throw NoRecordFoundException() + toolBaseService.getOne(toolTemplateAddParam.baseId!!) val newSource = ToolData().apply { data = toolTemplateAddParam.source } val newDist = ToolData().apply { data = toolTemplateAddParam.dist } @@ -64,7 +65,7 @@ class ToolTemplateServiceImpl( @Transactional override fun update(toolTemplateUpdateParam: ToolTemplateUpdateParam): ToolTemplateVo { val toolTemplate = baseMapper.selectOne(toolTemplateUpdateParam.id!!) ?: throw NoRecordFoundException() - toolTemplateUpdateParam.baseId?.let { toolBaseService.getOne(it) ?: throw NoRecordFoundException() } + toolTemplateUpdateParam.baseId?.let(toolBaseService::getOne) toolDataService.updateById(ToolData().apply { id = toolTemplate.sourceId @@ -83,7 +84,7 @@ class ToolTemplateServiceImpl( baseId = toolTemplateUpdateParam.baseId }) - return this.getOne(toolTemplate.id!!)!! + return this.getOne(toolTemplate.id!!) } @Transactional