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}")
@PreAuthorize("hasAnyAuthority('system:group:query:one')")
fun getOne(@PathVariable id: Long): ResponseResult<GroupWithRoleVo> =
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<List<GroupVo>> =
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<GroupVo> =
groupService.add(groupAddParam)?.let {
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
@@ -115,11 +111,9 @@ class GroupController(
@PutMapping
@PreAuthorize("hasAnyAuthority('system:group:modify:one')")
fun update(@Valid @RequestBody groupUpdateParam: GroupUpdateParam): ResponseResult<GroupVo> =
groupService.update(groupUpdateParam)?.let {
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
@@ -134,11 +128,9 @@ class GroupController(
@Operation(summary = "修改用户组状态")
@PatchMapping
@PreAuthorize("hasAnyAuthority('system:group:modify:status')")
fun updateStatus(@Valid @RequestBody groupUpdateStatusParam: GroupUpdateStatusParam): ResponseResult<Nothing> =
if (groupService.status(groupUpdateStatusParam)) {
ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_SUCCESS)
} else {
ResponseResult.databaseFail(ResponseCode.DATABASE_UPDATE_FILED)
fun updateStatus(@Valid @RequestBody groupUpdateStatusParam: GroupUpdateStatusParam): ResponseResult<Nothing> {
groupService.status(groupUpdateStatusParam)
return ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_SUCCESS)
}
/**

View File

@@ -37,11 +37,8 @@ class RoleController(
@Operation(summary = "获取单个角色")
@GetMapping("/{id}")
@PreAuthorize("hasAnyAuthority('system:role:query:one')")
fun getOne(@PathVariable id: Long): ResponseResult<RoleWithPowerVo> {
return ResponseResult.databaseSuccess(
data = roleService.getOne(id)
)
}
fun getOne(@PathVariable id: Long): ResponseResult<RoleWithPowerVo> =
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<PageVo<RoleWithPowerVo>> {
return ResponseResult.databaseSuccess(
fun get(roleGetParam: RoleGetParam?): ResponseResult<PageVo<RoleWithPowerVo>> =
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<List<RoleVo>> {
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<RoleVo> {
return roleService.add(roleAddParam)?.let {
fun add(@Valid @RequestBody roleAddParam: RoleAddParam): ResponseResult<RoleVo> =
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
@@ -117,13 +110,10 @@ class RoleController(
@Operation(summary = "修改角色")
@PutMapping
@PreAuthorize("hasAnyAuthority('system:role:modify:one')")
fun update(@Valid @RequestBody roleUpdateParam: RoleUpdateParam): ResponseResult<RoleVo> {
return roleService.update(roleUpdateParam)?.let {
fun update(@Valid @RequestBody roleUpdateParam: RoleUpdateParam): ResponseResult<RoleVo> =
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
@@ -139,11 +129,8 @@ class RoleController(
@PatchMapping
@PreAuthorize("hasAnyAuthority('system:role:modify:status')")
fun status(@Valid @RequestBody roleUpdateStatusParam: RoleUpdateStatusParam): ResponseResult<Nothing> {
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)
}
/**

View File

@@ -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<UserWithPowerInfoVo> =
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<UserWithRoleInfoVo> =
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<UserWithPasswordRoleInfoVo> =
userService.add(userAddParam)?.let {
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
@@ -117,11 +108,9 @@ class UserController(
@PutMapping
@PreAuthorize("hasAnyAuthority('system:user:modify:one')")
fun update(@Valid @RequestBody userUpdateParam: UserUpdateParam): ResponseResult<UserWithRoleInfoVo> =
userService.update(userUpdateParam)?.let {
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

View File

@@ -18,8 +18,7 @@ class BaseController(
@Operation(summary = "获取单个基板")
@GetMapping("/{id}")
fun getOne(@PathVariable id: Long): ResponseResult<ToolBaseVo> =
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<Nothing> =
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 = "获取单个类别")
@GetMapping("/{id}")
fun getOne(@PathVariable id: Long): ResponseResult<ToolCategoryVo> =
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<Nothing> =
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 = "获取单个工具")
@GetMapping("/{id}")
fun getOne(@PathVariable id: Long): ResponseResult<ToolVo> =
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<Nothing> =
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 = "获取单个工具")
@GetMapping("/{id}")
fun getOne(@PathVariable id: Long): ResponseResult<ToolVo> =
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<Nothing> =
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 = "获取单个模板")
@GetMapping("/{id}")
fun getOne(@PathVariable id: Long): ResponseResult<ToolTemplateVo> =
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<Nothing> =
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
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 {

View File

@@ -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),

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 */
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)

View File

@@ -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()))
}

View File

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

View File

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

View File

@@ -37,7 +37,18 @@ interface IUserService : IService<User> {
* @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<User> {
*/
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
*
@@ -71,7 +71,7 @@ interface IUserService : IService<User> {
* @since 1.0.0
* @see UserWithInfoVo
*/
fun listAll(): List<UserWithInfoVo>
fun getList(): List<UserWithInfoVo>
/**
* Add user
@@ -83,7 +83,7 @@ interface IUserService : IService<User> {
* @see UserAddParam
* @see UserWithPasswordRoleInfoVo
*/
fun add(userAddParam: UserAddParam): UserWithPasswordRoleInfoVo?
fun add(userAddParam: UserAddParam): UserWithPasswordRoleInfoVo
/**
* Update user
@@ -95,7 +95,7 @@ interface IUserService : IService<User> {
* @see UserUpdateParam
* @see UserWithRoleInfoVo
*/
fun update(userUpdateParam: UserUpdateParam): UserWithRoleInfoVo?
fun update(userUpdateParam: UserUpdateParam): UserWithRoleInfoVo
/**
* Update user password

View File

@@ -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)
}

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.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<GroupVo> {
val groups = this.list()
return groups.map { GroupConverter.groupToGroupVo(it) }
}
override fun getList(): List<GroupVo> = 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 (baseMapper.insert(group) != 1) {
throw DatabaseInsertException()
}
if (group.roles.isNullOrEmpty()) {
return GroupConverter.groupToGroupVo(group)
}
if (rRoleGroupService.saveBatch(group.roles!!.map {
rRoleGroupService.saveBatch(group.roles!!.map {
RRoleGroup().apply {
groupId = group.id
roleId = it.id
}
})) {
return GroupConverter.groupToGroupVo(group)
}
}
})
return null
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<Long>()
val removeRoleIds = HashSet<Long>()
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) }
}
}
}

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.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<RoleVo> {
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<RoleVo> = 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 (baseMapper.insert(role) != 1) {
throw DatabaseInsertException()
}
if (fullPowerIds.isNullOrEmpty()) {
return RoleConverter.roleToRoleVo(role)
}
if (rPowerRoleService.saveBatch(fullPowerIds.map {
rPowerRoleService.saveBatch(fullPowerIds.map {
RPowerRole().apply {
roleId = role.id
powerId = it
}
})) {
})
return RoleConverter.roleToRoleVo(role)
}
}
return null
}
@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<Long>()
val removePowerIds = HashSet<Long>()
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) }
}
}
}

View File

@@ -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<UserWithRoleInfoVo> {
val userIdsPage = Page<Long>(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,8 +123,12 @@ class UserServiceImpl(
}-${UUID.randomUUID()}-${UUID.randomUUID()}-${UUID.randomUUID()}"
}
if (this.save(user)) {
user.userInfo?.let { userInfoService.save(it.apply { userId = user.id }) }
if (!this.save(user)) {
throw DatabaseInsertException()
}
user.userInfo?.apply { userId = user.id }?.let(userInfoService::save)
if (!user.roles.isNullOrEmpty()) {
rUserRoleService.saveBatch(user.roles!!.map {
@@ -143,11 +153,8 @@ class UserServiceImpl(
return UserConverter.userToUserWithPasswordRoleInfoVo(user)
}
return null
}
@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<Long>()
val removeRoleIds = HashSet<Long>()
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<Long>()
val removeGroupIds = HashSet<Long>()
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 {

View File

@@ -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)
)

View File

@@ -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<ToolBase> {
fun getOne(id: Long): ToolBaseVo?
fun getOne(id: Long): ToolBaseVo
fun get(): List<ToolBaseVo>

View File

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

View File

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

View File

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

View File

@@ -28,7 +28,8 @@ import top.fatweb.oxygen.api.vo.tool.ToolBaseVo
class ToolBaseServiceImpl(
private val toolDataService: IToolDataService
) : 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)
@@ -72,7 +73,7 @@ class ToolBaseServiceImpl(
name = toolBaseUpdateParam.name
})
return this.getOne(toolBase.id!!)!!
return this.getOne(toolBase.id!!)
}
@Transactional

View File

@@ -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<ToolCategoryMapper, ToolCategory>(), 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<ToolCategoryVo> =
this.list().map(ToolCategoryConverter::toolCategoryToToolCategoryVo)
@@ -32,7 +34,9 @@ class ToolCategoryServiceImpl : ServiceImpl<ToolCategoryMapper, ToolCategory>(),
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<ToolCategoryMapper, ToolCategory>(),
override fun update(toolCategoryUpdateParam: ToolCategoryUpdateParam): ToolCategoryVo {
val toolCategory = ToolCategoryConverter.toolCategoryUpdateParamToToolCategory(toolCategoryUpdateParam)
this.updateById(toolCategory)
if (this.updateById(toolCategory)) {
throw DatabaseUpdateException()
}
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.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<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)
@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

View File

@@ -30,15 +30,16 @@ class ToolTemplateServiceImpl(
private val toolDataService: IToolDataService,
private val toolBaseService: IToolBaseService
) : ServiceImpl<ToolTemplateMapper, ToolTemplate>(), 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<ToolTemplateVo> =
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