Optimize code

This commit is contained in:
2024-01-18 16:54:23 +08:00
parent d559fc53dd
commit cec9a9e07b
32 changed files with 295 additions and 290 deletions

View File

@@ -38,9 +38,7 @@ class GroupController(
@GetMapping("/{id}") @GetMapping("/{id}")
@PreAuthorize("hasAnyAuthority('system:group:query:one')") @PreAuthorize("hasAnyAuthority('system:group:query:one')")
fun getOne(@PathVariable id: Long): ResponseResult<GroupWithRoleVo> = fun getOne(@PathVariable id: Long): ResponseResult<GroupWithRoleVo> =
ResponseResult.databaseSuccess( ResponseResult.databaseSuccess(data = groupService.getOne(id))
data = groupService.getOne(id)
)
/** /**
* Get group paging information * Get group paging information
@@ -76,7 +74,7 @@ class GroupController(
@PreAuthorize("hasAnyAuthority('system:group:query:list', 'system:user:add:one', 'system:user:modify:one')") @PreAuthorize("hasAnyAuthority('system:group:query:list', 'system:user:add:one', 'system:user:modify:one')")
fun list(): ResponseResult<List<GroupVo>> = fun list(): ResponseResult<List<GroupVo>> =
ResponseResult.databaseSuccess( ResponseResult.databaseSuccess(
data = groupService.listAll() data = groupService.getList()
) )
/** /**
@@ -94,11 +92,9 @@ class GroupController(
@PostMapping @PostMapping
@PreAuthorize("hasAnyAuthority('system:group:add:one')") @PreAuthorize("hasAnyAuthority('system:group:add:one')")
fun add(@Valid @RequestBody groupAddParam: GroupAddParam): ResponseResult<GroupVo> = fun add(@Valid @RequestBody groupAddParam: GroupAddParam): ResponseResult<GroupVo> =
groupService.add(groupAddParam)?.let {
ResponseResult.databaseSuccess( ResponseResult.databaseSuccess(
ResponseCode.DATABASE_INSERT_SUCCESS, data = it ResponseCode.DATABASE_INSERT_SUCCESS, data = groupService.add(groupAddParam)
) )
} ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_INSERT_FAILED) }
/** /**
* Update group * Update group
@@ -115,11 +111,9 @@ class GroupController(
@PutMapping @PutMapping
@PreAuthorize("hasAnyAuthority('system:group:modify:one')") @PreAuthorize("hasAnyAuthority('system:group:modify:one')")
fun update(@Valid @RequestBody groupUpdateParam: GroupUpdateParam): ResponseResult<GroupVo> = fun update(@Valid @RequestBody groupUpdateParam: GroupUpdateParam): ResponseResult<GroupVo> =
groupService.update(groupUpdateParam)?.let {
ResponseResult.databaseSuccess( ResponseResult.databaseSuccess(
ResponseCode.DATABASE_UPDATE_SUCCESS, data = it ResponseCode.DATABASE_UPDATE_SUCCESS, data = groupService.update(groupUpdateParam)
) )
} ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_UPDATE_FILED) }
/** /**
* Update status of group * Update status of group
@@ -134,11 +128,9 @@ class GroupController(
@Operation(summary = "修改用户组状态") @Operation(summary = "修改用户组状态")
@PatchMapping @PatchMapping
@PreAuthorize("hasAnyAuthority('system:group:modify:status')") @PreAuthorize("hasAnyAuthority('system:group:modify:status')")
fun updateStatus(@Valid @RequestBody groupUpdateStatusParam: GroupUpdateStatusParam): ResponseResult<Nothing> = fun updateStatus(@Valid @RequestBody groupUpdateStatusParam: GroupUpdateStatusParam): ResponseResult<Nothing> {
if (groupService.status(groupUpdateStatusParam)) { groupService.status(groupUpdateStatusParam)
ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_SUCCESS) return ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_SUCCESS)
} else {
ResponseResult.databaseFail(ResponseCode.DATABASE_UPDATE_FILED)
} }
/** /**

View File

@@ -37,11 +37,8 @@ class RoleController(
@Operation(summary = "获取单个角色") @Operation(summary = "获取单个角色")
@GetMapping("/{id}") @GetMapping("/{id}")
@PreAuthorize("hasAnyAuthority('system:role:query:one')") @PreAuthorize("hasAnyAuthority('system:role:query:one')")
fun getOne(@PathVariable id: Long): ResponseResult<RoleWithPowerVo> { fun getOne(@PathVariable id: Long): ResponseResult<RoleWithPowerVo> =
return ResponseResult.databaseSuccess( ResponseResult.databaseSuccess(data = roleService.getOne(id))
data = roleService.getOne(id)
)
}
/** /**
* Get role paging information * Get role paging information
@@ -57,11 +54,10 @@ class RoleController(
@Operation(summary = "获取角色") @Operation(summary = "获取角色")
@GetMapping @GetMapping
@PreAuthorize("hasAnyAuthority('system:role:query:all')") @PreAuthorize("hasAnyAuthority('system:role:query:all')")
fun get(roleGetParam: RoleGetParam?): ResponseResult<PageVo<RoleWithPowerVo>> { fun get(roleGetParam: RoleGetParam?): ResponseResult<PageVo<RoleWithPowerVo>> =
return ResponseResult.databaseSuccess( ResponseResult.databaseSuccess(
data = roleService.getPage(roleGetParam) data = roleService.getPage(roleGetParam)
) )
}
/** /**
* Get role list * 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')") @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<List<RoleVo>> { fun list(): ResponseResult<List<RoleVo>> {
return ResponseResult.databaseSuccess( return ResponseResult.databaseSuccess(
data = roleService.listAll() data = roleService.getList()
) )
} }
@@ -95,13 +91,10 @@ class RoleController(
@Operation(summary = "添加角色") @Operation(summary = "添加角色")
@PostMapping @PostMapping
@PreAuthorize("hasAnyAuthority('system:role:add:one')") @PreAuthorize("hasAnyAuthority('system:role:add:one')")
fun add(@Valid @RequestBody roleAddParam: RoleAddParam): ResponseResult<RoleVo> { fun add(@Valid @RequestBody roleAddParam: RoleAddParam): ResponseResult<RoleVo> =
return roleService.add(roleAddParam)?.let {
ResponseResult.databaseSuccess( ResponseResult.databaseSuccess(
ResponseCode.DATABASE_INSERT_SUCCESS, data = it ResponseCode.DATABASE_INSERT_SUCCESS, data = roleService.add(roleAddParam)
) )
} ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_INSERT_FAILED) }
}
/** /**
* Update role * Update role
@@ -117,13 +110,10 @@ class RoleController(
@Operation(summary = "修改角色") @Operation(summary = "修改角色")
@PutMapping @PutMapping
@PreAuthorize("hasAnyAuthority('system:role:modify:one')") @PreAuthorize("hasAnyAuthority('system:role:modify:one')")
fun update(@Valid @RequestBody roleUpdateParam: RoleUpdateParam): ResponseResult<RoleVo> { fun update(@Valid @RequestBody roleUpdateParam: RoleUpdateParam): ResponseResult<RoleVo> =
return roleService.update(roleUpdateParam)?.let {
ResponseResult.databaseSuccess( ResponseResult.databaseSuccess(
ResponseCode.DATABASE_UPDATE_SUCCESS, data = it ResponseCode.DATABASE_UPDATE_SUCCESS, data = roleService.update(roleUpdateParam)
) )
} ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_UPDATE_FILED) }
}
/** /**
* Update status of role * Update status of role
@@ -139,11 +129,8 @@ class RoleController(
@PatchMapping @PatchMapping
@PreAuthorize("hasAnyAuthority('system:role:modify:status')") @PreAuthorize("hasAnyAuthority('system:role:modify:status')")
fun status(@Valid @RequestBody roleUpdateStatusParam: RoleUpdateStatusParam): ResponseResult<Nothing> { fun status(@Valid @RequestBody roleUpdateStatusParam: RoleUpdateStatusParam): ResponseResult<Nothing> {
return if (roleService.status(roleUpdateStatusParam)) { roleService.status(roleUpdateStatusParam)
ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_SUCCESS) return ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_SUCCESS)
} else {
ResponseResult.databaseFail(ResponseCode.DATABASE_UPDATE_FILED)
}
} }
/** /**

View File

@@ -7,7 +7,6 @@ import org.springframework.web.bind.annotation.*
import top.fatweb.oxygen.api.annotation.BaseController import top.fatweb.oxygen.api.annotation.BaseController
import top.fatweb.oxygen.api.entity.common.ResponseCode import top.fatweb.oxygen.api.entity.common.ResponseCode
import top.fatweb.oxygen.api.entity.common.ResponseResult 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.param.permission.user.*
import top.fatweb.oxygen.api.service.permission.IUserService import top.fatweb.oxygen.api.service.permission.IUserService
import top.fatweb.oxygen.api.vo.PageVo import top.fatweb.oxygen.api.vo.PageVo
@@ -38,9 +37,7 @@ class UserController(
@Operation(summary = "获取当前用户信息") @Operation(summary = "获取当前用户信息")
@GetMapping("info") @GetMapping("info")
fun getInfo(): ResponseResult<UserWithPowerInfoVo> = fun getInfo(): ResponseResult<UserWithPowerInfoVo> =
userService.getInfo()?.let { ResponseResult.databaseSuccess(data = userService.getInfo())
ResponseResult.databaseSuccess(data = it)
} ?: let { ResponseResult.databaseFail() }
/** /**
* Get user by ID * Get user by ID
@@ -56,11 +53,7 @@ class UserController(
@GetMapping("/{id}") @GetMapping("/{id}")
@PreAuthorize("hasAnyAuthority('system:user:query:one')") @PreAuthorize("hasAnyAuthority('system:user:query:one')")
fun getOne(@PathVariable id: Long): ResponseResult<UserWithRoleInfoVo> = fun getOne(@PathVariable id: Long): ResponseResult<UserWithRoleInfoVo> =
userService.getOne(id)?.let { ResponseResult.databaseSuccess(data = userService.getOne(id))
ResponseResult.databaseSuccess(data = it)
} ?: let {
throw NoRecordFoundException()
}
/** /**
* Get user paging information * Get user paging information
@@ -96,11 +89,9 @@ class UserController(
@PostMapping @PostMapping
@PreAuthorize("hasAnyAuthority('system:user:add:one')") @PreAuthorize("hasAnyAuthority('system:user:add:one')")
fun add(@Valid @RequestBody userAddParam: UserAddParam): ResponseResult<UserWithPasswordRoleInfoVo> = fun add(@Valid @RequestBody userAddParam: UserAddParam): ResponseResult<UserWithPasswordRoleInfoVo> =
userService.add(userAddParam)?.let {
ResponseResult.databaseSuccess( ResponseResult.databaseSuccess(
ResponseCode.DATABASE_INSERT_SUCCESS, data = it ResponseCode.DATABASE_INSERT_SUCCESS, data = userService.add(userAddParam)
) )
} ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_INSERT_FAILED) }
/** /**
* Update user * Update user
@@ -117,11 +108,9 @@ class UserController(
@PutMapping @PutMapping
@PreAuthorize("hasAnyAuthority('system:user:modify:one')") @PreAuthorize("hasAnyAuthority('system:user:modify:one')")
fun update(@Valid @RequestBody userUpdateParam: UserUpdateParam): ResponseResult<UserWithRoleInfoVo> = fun update(@Valid @RequestBody userUpdateParam: UserUpdateParam): ResponseResult<UserWithRoleInfoVo> =
userService.update(userUpdateParam)?.let {
ResponseResult.databaseSuccess( ResponseResult.databaseSuccess(
ResponseCode.DATABASE_UPDATE_SUCCESS, data = it ResponseCode.DATABASE_UPDATE_SUCCESS, data = userService.update(userUpdateParam)
) )
} ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_UPDATE_FILED) }
/** /**
* Update user password * Update user password

View File

@@ -18,8 +18,7 @@ class BaseController(
@Operation(summary = "获取单个基板") @Operation(summary = "获取单个基板")
@GetMapping("/{id}") @GetMapping("/{id}")
fun getOne(@PathVariable id: Long): ResponseResult<ToolBaseVo> = fun getOne(@PathVariable id: Long): ResponseResult<ToolBaseVo> =
toolBaseService.getOne(id)?.let { ResponseResult.databaseSuccess(data = it) } ResponseResult.databaseSuccess(data = toolBaseService.getOne(id))
?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_NO_RECORD_FOUND) }
@Operation(summary = "获取基板") @Operation(summary = "获取基板")
@GetMapping @GetMapping
@@ -46,5 +45,5 @@ class BaseController(
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
fun delete(@PathVariable id: Long): ResponseResult<Nothing> = fun delete(@PathVariable id: Long): ResponseResult<Nothing> =
if (toolBaseService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) if (toolBaseService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS)
else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FILED) else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FAILED)
} }

View File

@@ -25,8 +25,7 @@ class CategoryController(
@Operation(summary = "获取单个类别") @Operation(summary = "获取单个类别")
@GetMapping("/{id}") @GetMapping("/{id}")
fun getOne(@PathVariable id: Long): ResponseResult<ToolCategoryVo> = fun getOne(@PathVariable id: Long): ResponseResult<ToolCategoryVo> =
toolCategoryService.getOne(id)?.let { ResponseResult.databaseSuccess(data = it) } ResponseResult.databaseSuccess(data = toolCategoryService.getOne(id))
?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_NO_RECORD_FOUND) }
@Operation(summary = "获取类别") @Operation(summary = "获取类别")
@GetMapping @GetMapping
@@ -53,5 +52,5 @@ class CategoryController(
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
fun delete(@PathVariable id: Long): ResponseResult<Nothing> = fun delete(@PathVariable id: Long): ResponseResult<Nothing> =
if (toolCategoryService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) if (toolCategoryService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS)
else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FILED) else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FAILED)
} }

View File

@@ -24,8 +24,7 @@ class EditController(
@Operation(summary = "获取单个工具") @Operation(summary = "获取单个工具")
@GetMapping("/{id}") @GetMapping("/{id}")
fun getOne(@PathVariable id: Long): ResponseResult<ToolVo> = fun getOne(@PathVariable id: Long): ResponseResult<ToolVo> =
toolService.getOne(id)?.let { ResponseResult.databaseSuccess(data = it) } ResponseResult.databaseSuccess(data = toolService.getOne(id))
?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_NO_RECORD_FOUND) }
@Operation(summary = "获取工具") @Operation(summary = "获取工具")
@GetMapping @GetMapping
@@ -52,5 +51,5 @@ class EditController(
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
fun delete(@PathVariable id: Long): ResponseResult<Nothing> = fun delete(@PathVariable id: Long): ResponseResult<Nothing> =
if (toolService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) if (toolService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS)
else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FILED) else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FAILED)
} }

View File

@@ -18,8 +18,7 @@ class ManagementController(
@Operation(summary = "获取单个工具") @Operation(summary = "获取单个工具")
@GetMapping("/{id}") @GetMapping("/{id}")
fun getOne(@PathVariable id: Long): ResponseResult<ToolVo> = fun getOne(@PathVariable id: Long): ResponseResult<ToolVo> =
toolService.getOne(id)?.let { ResponseResult.databaseSuccess(data = it) } ResponseResult.databaseSuccess(data = toolService.getOne(id))
?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_NO_RECORD_FOUND) }
@Operation(summary = "获取工具") @Operation(summary = "获取工具")
@GetMapping @GetMapping
@@ -46,5 +45,5 @@ class ManagementController(
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
fun delete(@PathVariable id: Long): ResponseResult<Nothing> = fun delete(@PathVariable id: Long): ResponseResult<Nothing> =
if (toolService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) if (toolService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS)
else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FILED) else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FAILED)
} }

View File

@@ -18,8 +18,7 @@ class TemplateController(
@Operation(summary = "获取单个模板") @Operation(summary = "获取单个模板")
@GetMapping("/{id}") @GetMapping("/{id}")
fun getOne(@PathVariable id: Long): ResponseResult<ToolTemplateVo> = fun getOne(@PathVariable id: Long): ResponseResult<ToolTemplateVo> =
toolTemplateService.getOne(id)?.let { ResponseResult.databaseSuccess(data = it) } ResponseResult.databaseSuccess(data = toolTemplateService.getOne(id))
?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_NO_RECORD_FOUND) }
@Operation(summary = "获取模板") @Operation(summary = "获取模板")
@GetMapping @GetMapping
@@ -46,5 +45,5 @@ class TemplateController(
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
fun delete(@PathVariable id: Long): ResponseResult<Nothing> = fun delete(@PathVariable id: Long): ResponseResult<Nothing> =
if (toolTemplateService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) if (toolTemplateService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS)
else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FILED) else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FAILED)
} }

View File

@@ -1,7 +1,6 @@
package top.fatweb.oxygen.api.converter.tool package top.fatweb.oxygen.api.converter.tool
import top.fatweb.oxygen.api.entity.tool.ToolBase import top.fatweb.oxygen.api.entity.tool.ToolBase
import top.fatweb.oxygen.api.param.tool.ToolBaseAddParam
import top.fatweb.oxygen.api.vo.tool.ToolBaseVo import top.fatweb.oxygen.api.vo.tool.ToolBaseVo
object ToolBaseConverter { object ToolBaseConverter {

View File

@@ -51,9 +51,9 @@ enum class ResponseCode(val code: Int) {
DATABASE_INSERT_SUCCESS(BusinessCode.DATABASE, 10), DATABASE_INSERT_SUCCESS(BusinessCode.DATABASE, 10),
DATABASE_INSERT_FAILED(BusinessCode.DATABASE, 15), DATABASE_INSERT_FAILED(BusinessCode.DATABASE, 15),
DATABASE_UPDATE_SUCCESS(BusinessCode.DATABASE, 20), 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_SUCCESS(BusinessCode.DATABASE, 30),
DATABASE_DELETE_FILED(BusinessCode.DATABASE, 35), DATABASE_DELETE_FAILED(BusinessCode.DATABASE, 35),
DATABASE_EXECUTE_ERROR(BusinessCode.DATABASE, 50), DATABASE_EXECUTE_ERROR(BusinessCode.DATABASE, 50),
DATABASE_DUPLICATE_KEY(BusinessCode.DATABASE, 51), DATABASE_DUPLICATE_KEY(BusinessCode.DATABASE, 51),
DATABASE_NO_RECORD_FOUND(BusinessCode.DATABASE, 52), DATABASE_NO_RECORD_FOUND(BusinessCode.DATABASE, 52),

View File

@@ -0,0 +1,3 @@
package top.fatweb.oxygen.api.exception
class DatabaseDeleteException(message: String = "Database delete failed"): RuntimeException(message)

View File

@@ -0,0 +1,3 @@
package top.fatweb.oxygen.api.exception
class DatabaseInsertException(message: String = "Database insert failed"): RuntimeException(message)

View File

@@ -0,0 +1,3 @@
package top.fatweb.oxygen.api.exception
class DatabaseSelectException(message: String = "Database select failed"): RuntimeException(message)

View File

@@ -0,0 +1,3 @@
package top.fatweb.oxygen.api.exception
class DatabaseUpdateException(message: String = "Database update failed"): RuntimeException(message)

View File

@@ -166,6 +166,26 @@ class ExceptionHandler {
} }
/* SQL */ /* 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 -> { is BadSqlGrammarException -> {
logger.debug(e.localizedMessage, e) logger.debug(e.localizedMessage, e)
ResponseResult.fail(ResponseCode.DATABASE_EXECUTE_ERROR, "Incorrect SQL syntax", null) ResponseResult.fail(ResponseCode.DATABASE_EXECUTE_ERROR, "Incorrect SQL syntax", null)

View File

@@ -59,12 +59,12 @@ class AvatarServiceImpl : IAvatarService {
if (avatarBaseParam == null || avatarBaseParam.colors.isNullOrEmpty()) if (avatarBaseParam == null || avatarBaseParam.colors.isNullOrEmpty())
TriangleAvatar.newAvatarBuilder() TriangleAvatar.newAvatarBuilder()
else TriangleAvatar.newAvatarBuilder( else TriangleAvatar.newAvatarBuilder(
*avatarBaseParam.colors!!.map { decodeColor(it) }.toTypedArray() *avatarBaseParam.colors!!.map(this::decodeColor).toTypedArray()
) )
).apply { ).apply {
avatarBaseParam?.size?.let { size(it, it) } avatarBaseParam?.size?.let(this::size)
avatarBaseParam?.margin?.let { margin(it) } avatarBaseParam?.margin?.let(this::margin)
avatarBaseParam?.padding?.let { padding(it) } avatarBaseParam?.padding?.let(this::padding)
avatarBaseParam?.background?.let { layers(ColorPaintBackgroundLayer(decodeColor(it))) } avatarBaseParam?.background?.let { layers(ColorPaintBackgroundLayer(decodeColor(it))) }
}.build() }.build()
@@ -79,12 +79,12 @@ class AvatarServiceImpl : IAvatarService {
if (avatarBaseParam == null || avatarBaseParam.colors.isNullOrEmpty()) if (avatarBaseParam == null || avatarBaseParam.colors.isNullOrEmpty())
SquareAvatar.newAvatarBuilder() SquareAvatar.newAvatarBuilder()
else SquareAvatar.newAvatarBuilder( else SquareAvatar.newAvatarBuilder(
*avatarBaseParam.colors!!.map { decodeColor(it) }.toTypedArray() *avatarBaseParam.colors!!.map(this::decodeColor).toTypedArray()
) )
).apply { ).apply {
avatarBaseParam?.size?.let { size(it, it) } avatarBaseParam?.size?.let(this::size)
avatarBaseParam?.margin?.let { margin(it) } avatarBaseParam?.margin?.let(this::margin)
avatarBaseParam?.padding?.let { padding(it) } avatarBaseParam?.padding?.let(this::padding)
avatarBaseParam?.background?.let { layers(ColorPaintBackgroundLayer(decodeColor(it))) } avatarBaseParam?.background?.let { layers(ColorPaintBackgroundLayer(decodeColor(it))) }
}.build() }.build()
@@ -96,9 +96,9 @@ class AvatarServiceImpl : IAvatarService {
override fun identicon(avatarBaseParam: AvatarBaseParam?): ByteArray { override fun identicon(avatarBaseParam: AvatarBaseParam?): ByteArray {
val avatar = IdenticonAvatar.newAvatarBuilder().apply { val avatar = IdenticonAvatar.newAvatarBuilder().apply {
avatarBaseParam?.size?.let { size(it, it) } avatarBaseParam?.size?.let(this::size)
avatarBaseParam?.margin?.let { margin(it) } avatarBaseParam?.margin?.let(this::margin)
avatarBaseParam?.padding?.let { padding(it) } avatarBaseParam?.padding?.let(this::padding)
if (avatarBaseParam != null && !avatarBaseParam.colors.isNullOrEmpty()) { if (avatarBaseParam != null && !avatarBaseParam.colors.isNullOrEmpty()) {
color(decodeColor(avatarBaseParam.colors!!.random())) color(decodeColor(avatarBaseParam.colors!!.random()))
} }
@@ -114,9 +114,9 @@ class AvatarServiceImpl : IAvatarService {
override fun github(avatarGitHubParam: AvatarGitHubParam?): ByteArray { override fun github(avatarGitHubParam: AvatarGitHubParam?): ByteArray {
val avatar = (avatarGitHubParam?.let { GitHubAvatar.newAvatarBuilder(it.elementSize, it.precision) } val avatar = (avatarGitHubParam?.let { GitHubAvatar.newAvatarBuilder(it.elementSize, it.precision) }
?: let { GitHubAvatar.newAvatarBuilder(400, 5) }).apply { ?: let { GitHubAvatar.newAvatarBuilder(400, 5) }).apply {
avatarGitHubParam?.size?.let { size(it, it) } avatarGitHubParam?.size?.let(this::size)
avatarGitHubParam?.margin?.let { margin(it) } avatarGitHubParam?.margin?.let(this::margin)
avatarGitHubParam?.padding?.let { padding(it) } avatarGitHubParam?.padding?.let(this::padding)
if (avatarGitHubParam != null && !avatarGitHubParam.colors.isNullOrEmpty()) { if (avatarGitHubParam != null && !avatarGitHubParam.colors.isNullOrEmpty()) {
color(decodeColor(avatarGitHubParam.colors!!.random())) color(decodeColor(avatarGitHubParam.colors!!.random()))
} }

View File

@@ -16,6 +16,17 @@ import top.fatweb.oxygen.api.vo.permission.base.GroupVo
* @see Group * @see Group
*/ */
interface IGroupService : IService<Group> { interface IGroupService : IService<Group> {
/**
* 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 * Get group in page
* *
@@ -29,17 +40,6 @@ interface IGroupService : IService<Group> {
*/ */
fun getPage(groupGetParam: GroupGetParam?): PageVo<GroupWithRoleVo> fun getPage(groupGetParam: GroupGetParam?): PageVo<GroupWithRoleVo>
/**
* 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 * Get all group in list
* *
@@ -48,7 +48,7 @@ interface IGroupService : IService<Group> {
* @since 1.0.0 * @since 1.0.0
* @see GroupVo * @see GroupVo
*/ */
fun listAll(): List<GroupVo> fun getList(): List<GroupVo>
/** /**
* Add group * Add group
@@ -60,7 +60,7 @@ interface IGroupService : IService<Group> {
* @see GroupAddParam * @see GroupAddParam
* @see GroupVo * @see GroupVo
*/ */
fun add(groupAddParam: GroupAddParam): GroupVo? fun add(groupAddParam: GroupAddParam): GroupVo
/** /**
* Update group * Update group
@@ -72,7 +72,7 @@ interface IGroupService : IService<Group> {
* @see GroupUpdateParam * @see GroupUpdateParam
* @see GroupVo * @see GroupVo
*/ */
fun update(groupUpdateParam: GroupUpdateParam): GroupVo? fun update(groupUpdateParam: GroupUpdateParam): GroupVo
/** /**
* Update status of group * Update status of group
@@ -83,7 +83,7 @@ interface IGroupService : IService<Group> {
* @since 1.0.0 * @since 1.0.0
* @see GroupUpdateStatusParam * @see GroupUpdateStatusParam
*/ */
fun status(groupUpdateStatusParam: GroupUpdateStatusParam): Boolean fun status(groupUpdateStatusParam: GroupUpdateStatusParam)
/** /**
* Delete group by ID * Delete group by ID

View File

@@ -16,6 +16,17 @@ import top.fatweb.oxygen.api.vo.permission.base.RoleVo
* @see Role * @see Role
*/ */
interface IRoleService : IService<Role> { interface IRoleService : IService<Role> {
/**
* 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 * Get role in page
* *
@@ -29,17 +40,6 @@ interface IRoleService : IService<Role> {
*/ */
fun getPage(roleGetParam: RoleGetParam?): PageVo<RoleWithPowerVo> fun getPage(roleGetParam: RoleGetParam?): PageVo<RoleWithPowerVo>
/**
* 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 * Get all role in list
* *
@@ -48,7 +48,7 @@ interface IRoleService : IService<Role> {
* @since 1.0.0 * @since 1.0.0
* @see RoleVo * @see RoleVo
*/ */
fun listAll(): List<RoleVo> fun getList(): List<RoleVo>
/** /**
* Add role * Add role
@@ -60,7 +60,7 @@ interface IRoleService : IService<Role> {
* @see RoleAddParam * @see RoleAddParam
* @see RoleVo * @see RoleVo
*/ */
fun add(roleAddParam: RoleAddParam): RoleVo? fun add(roleAddParam: RoleAddParam): RoleVo
/** /**
* Update role * Update role
@@ -72,7 +72,7 @@ interface IRoleService : IService<Role> {
* @see RoleUpdateParam * @see RoleUpdateParam
* @see RoleVo * @see RoleVo
*/ */
fun update(roleUpdateParam: RoleUpdateParam): RoleVo? fun update(roleUpdateParam: RoleUpdateParam): RoleVo
/** /**
* Update status of role * Update status of role
@@ -83,7 +83,7 @@ interface IRoleService : IService<Role> {
* @since 1.0.0 * @since 1.0.0
* @see RoleUpdateStatusParam * @see RoleUpdateStatusParam
*/ */
fun status(roleUpdateStatusParam: RoleUpdateStatusParam): Boolean fun status(roleUpdateStatusParam: RoleUpdateStatusParam)
/** /**
* Delete role by ID * Delete role by ID

View File

@@ -37,7 +37,18 @@ interface IUserService : IService<User> {
* @since 1.0.0 * @since 1.0.0
* @see UserWithPowerInfoVo * @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 * Get user in page
@@ -52,17 +63,6 @@ interface IUserService : IService<User> {
*/ */
fun getPage(userGetParam: UserGetParam?): PageVo<UserWithRoleInfoVo> fun getPage(userGetParam: UserGetParam?): PageVo<UserWithRoleInfoVo>
/**
* 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 * Get all user as list
* *
@@ -71,7 +71,7 @@ interface IUserService : IService<User> {
* @since 1.0.0 * @since 1.0.0
* @see UserWithInfoVo * @see UserWithInfoVo
*/ */
fun listAll(): List<UserWithInfoVo> fun getList(): List<UserWithInfoVo>
/** /**
* Add user * Add user
@@ -83,7 +83,7 @@ interface IUserService : IService<User> {
* @see UserAddParam * @see UserAddParam
* @see UserWithPasswordRoleInfoVo * @see UserWithPasswordRoleInfoVo
*/ */
fun add(userAddParam: UserAddParam): UserWithPasswordRoleInfoVo? fun add(userAddParam: UserAddParam): UserWithPasswordRoleInfoVo
/** /**
* Update user * Update user
@@ -95,7 +95,7 @@ interface IUserService : IService<User> {
* @see UserUpdateParam * @see UserUpdateParam
* @see UserWithRoleInfoVo * @see UserWithRoleInfoVo
*/ */
fun update(userUpdateParam: UserUpdateParam): UserWithRoleInfoVo? fun update(userUpdateParam: UserUpdateParam): UserWithRoleInfoVo
/** /**
* Update user password * Update user password

View File

@@ -92,7 +92,7 @@ class AuthenticationServiceImpl(
sendVerifyMail(user.username!!, user.verify!!, registerParam.email!!) 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) return RegisterVo(token = loginVo.token, userId = loginVo.userId)
} }

View File

@@ -8,6 +8,9 @@ import org.springframework.transaction.annotation.Transactional
import top.fatweb.oxygen.api.converter.permission.GroupConverter import top.fatweb.oxygen.api.converter.permission.GroupConverter
import top.fatweb.oxygen.api.entity.permission.Group import top.fatweb.oxygen.api.entity.permission.Group
import top.fatweb.oxygen.api.entity.permission.RRoleGroup 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.mapper.permission.GroupMapper
import top.fatweb.oxygen.api.param.permission.group.* import top.fatweb.oxygen.api.param.permission.group.*
import top.fatweb.oxygen.api.service.permission.IGroupService import top.fatweb.oxygen.api.service.permission.IGroupService
@@ -54,55 +57,51 @@ class GroupServiceImpl(
return GroupConverter.groupPageToGroupWithRolePageVo(groupPage) return GroupConverter.groupPageToGroupWithRolePageVo(groupPage)
} }
override fun getOne(id: Long): GroupWithRoleVo? { override fun getOne(id: Long): GroupWithRoleVo =
return baseMapper.selectOneById(id)?.let { GroupConverter.groupToGroupWithRoleVo(it) } ?: let { null } baseMapper.selectOneById(id)?.let(GroupConverter::groupToGroupWithRoleVo) ?: throw NoRecordFoundException()
}
override fun listAll(): List<GroupVo> { override fun getList(): List<GroupVo> = this.list().map(GroupConverter::groupToGroupVo)
val groups = this.list()
return groups.map { GroupConverter.groupToGroupVo(it) }
}
@Transactional @Transactional
override fun add(groupAddParam: GroupAddParam): GroupVo? { override fun add(groupAddParam: GroupAddParam): GroupVo {
val group = GroupConverter.groupAddParamToGroup(groupAddParam) val group = GroupConverter.groupAddParamToGroup(groupAddParam)
if (baseMapper.insert(group) == 1) { if (baseMapper.insert(group) != 1) {
throw DatabaseInsertException()
}
if (group.roles.isNullOrEmpty()) { if (group.roles.isNullOrEmpty()) {
return GroupConverter.groupToGroupVo(group) return GroupConverter.groupToGroupVo(group)
} }
if (rRoleGroupService.saveBatch(group.roles!!.map { rRoleGroupService.saveBatch(group.roles!!.map {
RRoleGroup().apply { RRoleGroup().apply {
groupId = group.id groupId = group.id
roleId = it.id roleId = it.id
} }
})) { })
return GroupConverter.groupToGroupVo(group)
}
}
return null return GroupConverter.groupToGroupVo(group)
} }
@Transactional @Transactional
override fun update(groupUpdateParam: GroupUpdateParam): GroupVo? { override fun update(groupUpdateParam: GroupUpdateParam): GroupVo {
val group = GroupConverter.groupUpdateParamToGroup(groupUpdateParam) val group = GroupConverter.groupUpdateParamToGroup(groupUpdateParam)
if (baseMapper.updateById(group) != 1) {
throw DatabaseUpdateException()
}
val oldRoleList = rRoleGroupService.list( val oldRoleList = rRoleGroupService.list(
KtQueryWrapper(RRoleGroup()).select(RRoleGroup::roleId).eq(RRoleGroup::groupId, groupUpdateParam.id) KtQueryWrapper(RRoleGroup()).select(RRoleGroup::roleId).eq(RRoleGroup::groupId, groupUpdateParam.id)
).map { it.roleId } ).map { it.roleId }
val addRoleIds = HashSet<Long>() val addRoleIds = HashSet<Long>()
val removeRoleIds = HashSet<Long>() val removeRoleIds = HashSet<Long>()
groupUpdateParam.roleIds?.forEach { addRoleIds.add(it) } groupUpdateParam.roleIds?.forEach(addRoleIds::add)
oldRoleList.forEach { oldRoleList.forEach {
if (it != null) { it?.let(removeRoleIds::add)
removeRoleIds.add(it)
}
} }
removeRoleIds.removeAll(addRoleIds) removeRoleIds.removeAll(addRoleIds)
oldRoleList.toSet().let { addRoleIds.removeAll(it) } oldRoleList.toSet().let(addRoleIds::removeAll)
baseMapper.updateById(group)
removeRoleIds.forEach { removeRoleIds.forEach {
rRoleGroupService.remove( rRoleGroupService.remove(
@@ -124,13 +123,15 @@ class GroupServiceImpl(
return GroupConverter.groupToGroupVo(group) return GroupConverter.groupToGroupVo(group)
} }
override fun status(groupUpdateStatusParam: GroupUpdateStatusParam): Boolean { override fun status(groupUpdateStatusParam: GroupUpdateStatusParam) {
updateById(GroupConverter.groupUpdateStatusParamToGroup(groupUpdateStatusParam)).let { updateById(GroupConverter.groupUpdateStatusParamToGroup(groupUpdateStatusParam)).let {
if (it && !groupUpdateStatusParam.enable) { if (!it) {
groupUpdateStatusParam.id?.let { id -> offlineUser(id) } throw DatabaseUpdateException()
} }
return it if (!groupUpdateStatusParam.enable) {
groupUpdateStatusParam.id?.let { id -> offlineUser(id) }
}
} }
} }

View File

@@ -8,6 +8,9 @@ import org.springframework.transaction.annotation.Transactional
import top.fatweb.oxygen.api.converter.permission.RoleConverter import top.fatweb.oxygen.api.converter.permission.RoleConverter
import top.fatweb.oxygen.api.entity.permission.RPowerRole import top.fatweb.oxygen.api.entity.permission.RPowerRole
import top.fatweb.oxygen.api.entity.permission.Role 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.mapper.permission.RoleMapper
import top.fatweb.oxygen.api.param.permission.role.* import top.fatweb.oxygen.api.param.permission.role.*
import top.fatweb.oxygen.api.service.permission.* import top.fatweb.oxygen.api.service.permission.*
@@ -58,60 +61,54 @@ class RoleServiceImpl(
return RoleConverter.rolePageToRoleWithPowerPageVo(rolePage) return RoleConverter.rolePageToRoleWithPowerPageVo(rolePage)
} }
override fun getOne(id: Long): RoleWithPowerVo? { override fun getOne(id: Long): RoleWithPowerVo =
return baseMapper.selectOneById(id)?.let { RoleConverter.roleToRoleWithPowerVo(it) } ?: let { null } baseMapper.selectOneById(id)?.let(RoleConverter::roleToRoleWithPowerVo) ?: throw NoRecordFoundException()
}
override fun listAll(): List<RoleVo> {
val roles = this.list()
return roles.map { RoleConverter.roleToRoleVo(it) }
}
override fun getList(): List<RoleVo> = this.list().map(RoleConverter::roleToRoleVo)
@Transactional @Transactional
override fun add(roleAddParam: RoleAddParam): RoleVo? { override fun add(roleAddParam: RoleAddParam): RoleVo {
val fullPowerIds = roleAddParam.powerIds?.let { getFullPowerIds(it) } val fullPowerIds = roleAddParam.powerIds?.let(this::getFullPowerIds)
val role = RoleConverter.roleAddParamToRole(roleAddParam) val role = RoleConverter.roleAddParamToRole(roleAddParam)
if (baseMapper.insert(role) == 1) { if (baseMapper.insert(role) != 1) {
throw DatabaseInsertException()
}
if (fullPowerIds.isNullOrEmpty()) { if (fullPowerIds.isNullOrEmpty()) {
return RoleConverter.roleToRoleVo(role) return RoleConverter.roleToRoleVo(role)
} }
if (rPowerRoleService.saveBatch(fullPowerIds.map { rPowerRoleService.saveBatch(fullPowerIds.map {
RPowerRole().apply { RPowerRole().apply {
roleId = role.id roleId = role.id
powerId = it powerId = it
} }
})) { })
return RoleConverter.roleToRoleVo(role) return RoleConverter.roleToRoleVo(role)
} }
}
return null
}
@Transactional @Transactional
override fun update(roleUpdateParam: RoleUpdateParam): RoleVo? { override fun update(roleUpdateParam: RoleUpdateParam): RoleVo {
val fullPowerIds = roleUpdateParam.powerIds?.let { getFullPowerIds(it) } val fullPowerIds = roleUpdateParam.powerIds?.let(this::getFullPowerIds)
val role = RoleConverter.roleUpdateParamToRole(roleUpdateParam) val role = RoleConverter.roleUpdateParamToRole(roleUpdateParam)
if (baseMapper.updateById(role) != 1) {
throw DatabaseUpdateException()
}
val oldPowerList = rPowerRoleService.list( val oldPowerList = rPowerRoleService.list(
KtQueryWrapper(RPowerRole()).select(RPowerRole::powerId).eq(RPowerRole::roleId, roleUpdateParam.id) KtQueryWrapper(RPowerRole()).select(RPowerRole::powerId).eq(RPowerRole::roleId, roleUpdateParam.id)
).map { it.powerId } ).map { it.powerId }
val addPowerIds = HashSet<Long>() val addPowerIds = HashSet<Long>()
val removePowerIds = HashSet<Long>() val removePowerIds = HashSet<Long>()
fullPowerIds?.forEach { addPowerIds.add(it) } fullPowerIds?.forEach(addPowerIds::add)
oldPowerList.forEach { oldPowerList.forEach {
if (it != null) { it?.let(removePowerIds::add)
removePowerIds.add(it)
}
} }
removePowerIds.removeAll(addPowerIds) removePowerIds.removeAll(addPowerIds)
oldPowerList.toSet().let { addPowerIds.removeAll(it) } oldPowerList.toSet().let(addPowerIds::removeAll)
baseMapper.updateById(role)
removePowerIds.forEach { removePowerIds.forEach {
rPowerRoleService.remove( rPowerRoleService.remove(
@@ -133,13 +130,15 @@ class RoleServiceImpl(
return RoleConverter.roleToRoleVo(role) return RoleConverter.roleToRoleVo(role)
} }
override fun status(roleUpdateStatusParam: RoleUpdateStatusParam): Boolean { override fun status(roleUpdateStatusParam: RoleUpdateStatusParam) {
updateById(RoleConverter.roleUpdateStatusParamToRole(roleUpdateStatusParam)).let { updateById(RoleConverter.roleUpdateStatusParamToRole(roleUpdateStatusParam)).let {
if (it && !roleUpdateStatusParam.enable) { if (!it) {
roleUpdateStatusParam.id?.let { id -> offlineUser(id) } throw DatabaseUpdateException()
} }
return it if (!roleUpdateStatusParam.enable) {
roleUpdateStatusParam.id?.let { id -> offlineUser(id) }
}
} }
} }

View File

@@ -11,11 +11,14 @@ import org.springframework.security.crypto.password.PasswordEncoder
import org.springframework.stereotype.Service import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional import org.springframework.transaction.annotation.Transactional
import top.fatweb.oxygen.api.converter.permission.UserConverter 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.RUserGroup
import top.fatweb.oxygen.api.entity.permission.UserInfo
import top.fatweb.oxygen.api.entity.permission.RUserRole 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.NoRecordFoundException
import top.fatweb.oxygen.api.exception.UserNotFoundException
import top.fatweb.oxygen.api.mapper.permission.UserMapper import top.fatweb.oxygen.api.mapper.permission.UserMapper
import top.fatweb.oxygen.api.param.permission.user.* import top.fatweb.oxygen.api.param.permission.user.*
import top.fatweb.oxygen.api.service.permission.* 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.util.WebUtil
import top.fatweb.oxygen.api.vo.PageVo import top.fatweb.oxygen.api.vo.PageVo
import top.fatweb.oxygen.api.vo.permission.UserWithPasswordRoleInfoVo 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 top.fatweb.oxygen.api.vo.permission.UserWithRoleInfoVo
import java.time.LocalDateTime import java.time.LocalDateTime
import java.time.ZoneOffset import java.time.ZoneOffset
@@ -76,8 +80,13 @@ class UserServiceImpl(
return user return user
} }
override fun getInfo() = WebUtil.getLoginUsername() override fun getInfo(): UserWithPowerInfoVo =
?.let { username -> getUserWithPowerByAccount(username)?.let { UserConverter.userToUserWithPowerInfoVo(it) } } 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<UserWithRoleInfoVo> { override fun getPage(userGetParam: UserGetParam?): PageVo<UserWithRoleInfoVo> {
val userIdsPage = Page<Long>(userGetParam?.currentPage ?: 1, userGetParam?.pageSize ?: 20) val userIdsPage = Page<Long>(userGetParam?.currentPage ?: 1, userGetParam?.pageSize ?: 20)
@@ -99,13 +108,10 @@ class UserServiceImpl(
return UserConverter.userPageToUserWithRoleInfoPageVo(userPage) return UserConverter.userPageToUserWithRoleInfoPageVo(userPage)
} }
override fun getOne(id: Long) = override fun getList() = baseMapper.selectListWithInfo().map(UserConverter::userToUserWithInfoVo)
baseMapper.selectOneWithRoleInfoById(id)?.let { UserConverter.userToUserWithRoleInfoVo(it) }
override fun listAll() = baseMapper.selectListWithInfo().map { UserConverter.userToUserWithInfoVo(it) }
@Transactional @Transactional
override fun add(userAddParam: UserAddParam): UserWithPasswordRoleInfoVo? { override fun add(userAddParam: UserAddParam): UserWithPasswordRoleInfoVo {
val rawPassword = val rawPassword =
if (userAddParam.password.isNullOrBlank()) StrUtil.getRandomPassword(10) else userAddParam.password if (userAddParam.password.isNullOrBlank()) StrUtil.getRandomPassword(10) else userAddParam.password
val user = UserConverter.userAddParamToUser(userAddParam) val user = UserConverter.userAddParamToUser(userAddParam)
@@ -117,8 +123,12 @@ class UserServiceImpl(
}-${UUID.randomUUID()}-${UUID.randomUUID()}-${UUID.randomUUID()}" }-${UUID.randomUUID()}-${UUID.randomUUID()}-${UUID.randomUUID()}"
} }
if (this.save(user)) { if (!this.save(user)) {
user.userInfo?.let { userInfoService.save(it.apply { userId = user.id }) } throw DatabaseInsertException()
}
user.userInfo?.apply { userId = user.id }?.let(userInfoService::save)
if (!user.roles.isNullOrEmpty()) { if (!user.roles.isNullOrEmpty()) {
rUserRoleService.saveBatch(user.roles!!.map { rUserRoleService.saveBatch(user.roles!!.map {
@@ -143,11 +153,8 @@ class UserServiceImpl(
return UserConverter.userToUserWithPasswordRoleInfoVo(user) return UserConverter.userToUserWithPasswordRoleInfoVo(user)
} }
return null
}
@Transactional @Transactional
override fun update(userUpdateParam: UserUpdateParam): UserWithRoleInfoVo? { override fun update(userUpdateParam: UserUpdateParam): UserWithRoleInfoVo {
val user = UserConverter.userUpdateParamToUser(userUpdateParam) val user = UserConverter.userUpdateParamToUser(userUpdateParam)
user.updateTime = LocalDateTime.now(ZoneOffset.UTC) user.updateTime = LocalDateTime.now(ZoneOffset.UTC)
@@ -156,28 +163,24 @@ class UserServiceImpl(
).map { it.roleId } ).map { it.roleId }
val addRoleIds = HashSet<Long>() val addRoleIds = HashSet<Long>()
val removeRoleIds = HashSet<Long>() val removeRoleIds = HashSet<Long>()
userUpdateParam.roleIds?.forEach { addRoleIds.add(it) } userUpdateParam.roleIds?.forEach(addRoleIds::add)
oldRoleList.forEach { oldRoleList.forEach {
if (it != null) { it?.let(removeRoleIds::add)
removeRoleIds.add(it)
}
} }
removeRoleIds.removeAll(addRoleIds) removeRoleIds.removeAll(addRoleIds)
oldRoleList.toSet().let { addRoleIds.removeAll(it) } oldRoleList.toSet().let(addRoleIds::removeAll)
val oldGroupList = rUserGroupService.list( val oldGroupList = rUserGroupService.list(
KtQueryWrapper(RUserGroup()).select(RUserGroup::groupId).eq(RUserGroup::userId, userUpdateParam.id) KtQueryWrapper(RUserGroup()).select(RUserGroup::groupId).eq(RUserGroup::userId, userUpdateParam.id)
).map { it.groupId } ).map { it.groupId }
val addGroupIds = HashSet<Long>() val addGroupIds = HashSet<Long>()
val removeGroupIds = HashSet<Long>() val removeGroupIds = HashSet<Long>()
userUpdateParam.groupIds?.forEach { addGroupIds.add(it) } userUpdateParam.groupIds?.forEach(addGroupIds::add)
oldGroupList.forEach { oldGroupList.forEach {
if (it != null) { it?.let(removeGroupIds::add)
removeGroupIds.add(it)
}
} }
removeGroupIds.removeAll(addGroupIds) removeGroupIds.removeAll(addGroupIds)
oldGroupList.toSet().let { addGroupIds.removeAll(it) } oldGroupList.toSet().let(addGroupIds::removeAll)
this.updateById(user) this.updateById(user)
this.update( this.update(
@@ -252,7 +255,9 @@ class UserServiceImpl(
) )
.set(User::updateTime, LocalDateTime.now(ZoneOffset.UTC)) .set(User::updateTime, LocalDateTime.now(ZoneOffset.UTC))
this.update(wrapper) if (!this.update(wrapper)) {
throw DatabaseUpdateException()
}
userUpdatePasswordParam.id?.let { WebUtil.offlineUser(redisUtil, it) } userUpdatePasswordParam.id?.let { WebUtil.offlineUser(redisUtil, it) }
} ?: let { } ?: let {

View File

@@ -50,7 +50,7 @@ class SettingsServiceImpl : ISettingsService {
port = SettingsOperator.getMailValue(MailSettings::port), port = SettingsOperator.getMailValue(MailSettings::port),
securityType = SettingsOperator.getMailValue(MailSettings::securityType), securityType = SettingsOperator.getMailValue(MailSettings::securityType),
username = SettingsOperator.getMailValue(MailSettings::username), 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), from = SettingsOperator.getMailValue(MailSettings::from),
fromName = SettingsOperator.getMailValue(MailSettings::fromName) fromName = SettingsOperator.getMailValue(MailSettings::fromName)
) )

View File

@@ -2,11 +2,9 @@ package top.fatweb.oxygen.api.service.tool
import com.baomidou.mybatisplus.extension.service.IService import com.baomidou.mybatisplus.extension.service.IService
import top.fatweb.oxygen.api.entity.tool.ToolBase 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.ToolBaseAddParam
import top.fatweb.oxygen.api.param.tool.ToolBaseUpdateParam import top.fatweb.oxygen.api.param.tool.ToolBaseUpdateParam
import top.fatweb.oxygen.api.vo.tool.ToolBaseVo import top.fatweb.oxygen.api.vo.tool.ToolBaseVo
import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo
/** /**
* Tool base service interface * Tool base service interface
@@ -17,7 +15,7 @@ import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo
* @see ToolBase * @see ToolBase
*/ */
interface IToolBaseService : IService<ToolBase> { interface IToolBaseService : IService<ToolBase> {
fun getOne(id: Long): ToolBaseVo? fun getOne(id: Long): ToolBaseVo
fun get(): List<ToolBaseVo> fun get(): List<ToolBaseVo>

View File

@@ -15,7 +15,7 @@ import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo
* @see ToolCategory * @see ToolCategory
*/ */
interface IToolCategoryService : IService<ToolCategory> { interface IToolCategoryService : IService<ToolCategory> {
fun getOne(id: Long): ToolCategoryVo? fun getOne(id: Long): ToolCategoryVo
fun get(): List<ToolCategoryVo> fun get(): List<ToolCategoryVo>

View File

@@ -15,7 +15,7 @@ import top.fatweb.oxygen.api.vo.tool.ToolVo
* @see Tool * @see Tool
*/ */
interface IToolService : IService<Tool> { interface IToolService : IService<Tool> {
fun getOne(id: Long): ToolVo? fun getOne(id: Long): ToolVo
fun get(): List<ToolVo> fun get(): List<ToolVo>

View File

@@ -15,7 +15,7 @@ import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo
* @see ToolTemplate * @see ToolTemplate
*/ */
interface IToolTemplateService : IService<ToolTemplate> { interface IToolTemplateService : IService<ToolTemplate> {
fun getOne(id: Long): ToolTemplateVo? fun getOne(id: Long): ToolTemplateVo
fun get(): List<ToolTemplateVo> fun get(): List<ToolTemplateVo>

View File

@@ -28,7 +28,8 @@ import top.fatweb.oxygen.api.vo.tool.ToolBaseVo
class ToolBaseServiceImpl( class ToolBaseServiceImpl(
private val toolDataService: IToolDataService private val toolDataService: IToolDataService
) : ServiceImpl<ToolBaseMapper, ToolBase>(), IToolBaseService { ) : ServiceImpl<ToolBaseMapper, ToolBase>(), 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<ToolBaseVo> = baseMapper.selectList().map(ToolBaseConverter::toolBaseToToolBaseVo) override fun get(): List<ToolBaseVo> = baseMapper.selectList().map(ToolBaseConverter::toolBaseToToolBaseVo)
@@ -72,7 +73,7 @@ class ToolBaseServiceImpl(
name = toolBaseUpdateParam.name name = toolBaseUpdateParam.name
}) })
return this.getOne(toolBase.id!!)!! return this.getOne(toolBase.id!!)
} }
@Transactional @Transactional

View File

@@ -2,9 +2,11 @@ package top.fatweb.oxygen.api.service.tool.impl
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
import org.springframework.stereotype.Service import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import top.fatweb.oxygen.api.converter.tool.ToolCategoryConverter import top.fatweb.oxygen.api.converter.tool.ToolCategoryConverter
import top.fatweb.oxygen.api.entity.tool.ToolCategory 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.mapper.tool.ToolCategoryMapper
import top.fatweb.oxygen.api.param.tool.ToolCategoryAddParam import top.fatweb.oxygen.api.param.tool.ToolCategoryAddParam
import top.fatweb.oxygen.api.param.tool.ToolCategoryUpdateParam import top.fatweb.oxygen.api.param.tool.ToolCategoryUpdateParam
@@ -23,8 +25,8 @@ import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo
*/ */
@Service @Service
class ToolCategoryServiceImpl : ServiceImpl<ToolCategoryMapper, ToolCategory>(), IToolCategoryService { class ToolCategoryServiceImpl : ServiceImpl<ToolCategoryMapper, ToolCategory>(), IToolCategoryService {
override fun getOne(id: Long): ToolCategoryVo? = override fun getOne(id: Long): ToolCategoryVo =
this.getById(id)?.let(ToolCategoryConverter::toolCategoryToToolCategoryVo) this.getById(id)?.let(ToolCategoryConverter::toolCategoryToToolCategoryVo) ?: throw NoRecordFoundException()
override fun get(): List<ToolCategoryVo> = override fun get(): List<ToolCategoryVo> =
this.list().map(ToolCategoryConverter::toolCategoryToToolCategoryVo) this.list().map(ToolCategoryConverter::toolCategoryToToolCategoryVo)
@@ -32,7 +34,9 @@ class ToolCategoryServiceImpl : ServiceImpl<ToolCategoryMapper, ToolCategory>(),
override fun add(toolCategoryAddParam: ToolCategoryAddParam): ToolCategoryVo { override fun add(toolCategoryAddParam: ToolCategoryAddParam): ToolCategoryVo {
val toolCategory = ToolCategoryConverter.toolCategoryAddParamToToolCategory(toolCategoryAddParam) val toolCategory = ToolCategoryConverter.toolCategoryAddParamToToolCategory(toolCategoryAddParam)
this.save(toolCategory) if (!this.save(toolCategory)) {
throw DatabaseInsertException()
}
return ToolCategoryConverter.toolCategoryToToolCategoryVo(toolCategory) return ToolCategoryConverter.toolCategoryToToolCategoryVo(toolCategory)
} }
@@ -40,7 +44,9 @@ class ToolCategoryServiceImpl : ServiceImpl<ToolCategoryMapper, ToolCategory>(),
override fun update(toolCategoryUpdateParam: ToolCategoryUpdateParam): ToolCategoryVo { override fun update(toolCategoryUpdateParam: ToolCategoryUpdateParam): ToolCategoryVo {
val toolCategory = ToolCategoryConverter.toolCategoryUpdateParamToToolCategory(toolCategoryUpdateParam) val toolCategory = ToolCategoryConverter.toolCategoryUpdateParamToToolCategory(toolCategoryUpdateParam)
this.updateById(toolCategory) if (this.updateById(toolCategory)) {
throw DatabaseUpdateException()
}
return ToolCategoryConverter.toolCategoryToToolCategoryVo(toolCategory) return ToolCategoryConverter.toolCategoryToToolCategoryVo(toolCategory)
} }

View File

@@ -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.entity.tool.ToolData
import top.fatweb.oxygen.api.exception.NoRecordFoundException import top.fatweb.oxygen.api.exception.NoRecordFoundException
import top.fatweb.oxygen.api.exception.ToolHasPublish 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.mapper.tool.ToolMapper
import top.fatweb.oxygen.api.param.tool.ToolAddParam import top.fatweb.oxygen.api.param.tool.ToolAddParam
import top.fatweb.oxygen.api.param.tool.ToolUpdateParam import top.fatweb.oxygen.api.param.tool.ToolUpdateParam
@@ -36,14 +35,15 @@ class ToolServiceImpl(
private val rToolCategoryService: IRToolCategoryService, private val rToolCategoryService: IRToolCategoryService,
private val userService: IUserService private val userService: IUserService
) : ServiceImpl<ToolMapper, Tool>(), IToolService { ) : ServiceImpl<ToolMapper, Tool>(), 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<ToolVo> = baseMapper.selectList().map(ToolConverter::toolToToolVo) override fun get(): List<ToolVo> = baseMapper.selectList().map(ToolConverter::toolToToolVo)
@Transactional @Transactional
override fun add(toolAddParam: ToolAddParam): ToolVo { override fun add(toolAddParam: ToolAddParam): ToolVo {
toolBaseService.getOne(toolAddParam.baseId!!) ?: throw NoRecordFoundException() toolBaseService.getOne(toolAddParam.baseId!!)
userService.getOne(toolAddParam.authorId!!) ?: throw UserNotFoundException() userService.getOne(toolAddParam.authorId!!)
val newSource = ToolData().apply { data = toolAddParam.source } val newSource = ToolData().apply { data = toolAddParam.source }
val newDist = ToolData().apply { data = toolAddParam.dist } val newDist = ToolData().apply { data = toolAddParam.dist }
@@ -74,7 +74,7 @@ class ToolServiceImpl(
}) })
} }
return this.getOne(tool.id!!)!! return this.getOne(tool.id!!)
} }
@Transactional @Transactional
@@ -83,7 +83,7 @@ class ToolServiceImpl(
if (tool.publish == 1) { if (tool.publish == 1) {
throw ToolHasPublish() throw ToolHasPublish()
} }
userService.getOne(toolUpdateParam.authorId!!) ?: throw UserNotFoundException() userService.getOne(toolUpdateParam.authorId!!)
toolDataService.updateById(ToolData().apply { toolDataService.updateById(ToolData().apply {
id = tool.sourceId id = tool.sourceId
@@ -106,9 +106,9 @@ class ToolServiceImpl(
keywords = toolUpdateParam.keywords keywords = toolUpdateParam.keywords
}) })
// TODO // TODO Category process
return this.getOne(tool.id!!)!! return this.getOne(tool.id!!)
} }
@Transactional @Transactional

View File

@@ -30,15 +30,16 @@ class ToolTemplateServiceImpl(
private val toolDataService: IToolDataService, private val toolDataService: IToolDataService,
private val toolBaseService: IToolBaseService private val toolBaseService: IToolBaseService
) : ServiceImpl<ToolTemplateMapper, ToolTemplate>(), IToolTemplateService { ) : ServiceImpl<ToolTemplateMapper, ToolTemplate>(), IToolTemplateService {
override fun getOne(id: Long): ToolTemplateVo? = override fun getOne(id: Long): ToolTemplateVo =
baseMapper.selectOne(id)?.let(ToolTemplateConverter::toolTemplateToToolTemplateVo) baseMapper.selectOne(id)?.let(ToolTemplateConverter::toolTemplateToToolTemplateVo)
?: throw NoRecordFoundException()
override fun get(): List<ToolTemplateVo> = override fun get(): List<ToolTemplateVo> =
baseMapper.selectList().map(ToolTemplateConverter::toolTemplateToToolTemplateVo) baseMapper.selectList().map(ToolTemplateConverter::toolTemplateToToolTemplateVo)
@Transactional @Transactional
override fun add(toolTemplateAddParam: ToolTemplateAddParam): ToolTemplateVo { override fun add(toolTemplateAddParam: ToolTemplateAddParam): ToolTemplateVo {
toolBaseService.getOne(toolTemplateAddParam.baseId!!) ?: throw NoRecordFoundException() toolBaseService.getOne(toolTemplateAddParam.baseId!!)
val newSource = ToolData().apply { data = toolTemplateAddParam.source } val newSource = ToolData().apply { data = toolTemplateAddParam.source }
val newDist = ToolData().apply { data = toolTemplateAddParam.dist } val newDist = ToolData().apply { data = toolTemplateAddParam.dist }
@@ -64,7 +65,7 @@ class ToolTemplateServiceImpl(
@Transactional @Transactional
override fun update(toolTemplateUpdateParam: ToolTemplateUpdateParam): ToolTemplateVo { override fun update(toolTemplateUpdateParam: ToolTemplateUpdateParam): ToolTemplateVo {
val toolTemplate = baseMapper.selectOne(toolTemplateUpdateParam.id!!) ?: throw NoRecordFoundException() 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 { toolDataService.updateById(ToolData().apply {
id = toolTemplate.sourceId id = toolTemplate.sourceId
@@ -83,7 +84,7 @@ class ToolTemplateServiceImpl(
baseId = toolTemplateUpdateParam.baseId baseId = toolTemplateUpdateParam.baseId
}) })
return this.getOne(toolTemplate.id!!)!! return this.getOne(toolTemplate.id!!)
} }
@Transactional @Transactional