Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
yangxiujun
/
paidan_demo
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 31675bc4
authored
Jul 10, 2023
by
chamberone
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 重构user代码
1 parent
c7956cd2
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
1 additions
and
761 deletions
project-interface/src/main/java/com/dituhui/pea/pojo/UserAuthInfo.java
project-interface/src/main/java/com/dituhui/pea/pojo/UserInfo.java
project-user/src/main/java/com/dituhui/pea/user/controller/TeamController.java
project-user/src/main/java/com/dituhui/pea/user/dao/TeamDao.java
project-user/src/main/java/com/dituhui/pea/user/dao/UserTeamDao.java
project-user/src/main/java/com/dituhui/pea/user/entity/TeamEntity.java
project-user/src/main/java/com/dituhui/pea/user/entity/UserTeamEntity.java
project-user/src/main/java/com/dituhui/pea/user/factory/QqThirdStrategy.java
project-user/src/main/java/com/dituhui/pea/user/factory/WeiboThirdStrategy.java
project-user/src/main/java/com/dituhui/pea/user/service/TeamService.java
project-interface/src/main/java/com/dituhui/pea/pojo/UserAuthInfo.java
View file @
31675bc
...
...
@@ -18,11 +18,6 @@ public class UserAuthInfo implements Serializable {
private
String
userId
;
/**
* 团队id
*/
private
String
teamId
;
/**
* 用户名称
*/
private
String
userName
;
...
...
@@ -37,9 +32,8 @@ public class UserAuthInfo implements Serializable {
*/
private
String
role
;
public
UserAuthInfo
(
String
userId
,
String
teamId
,
String
userName
,
String
password
,
String
role
)
{
public
UserAuthInfo
(
String
userId
,
String
userName
,
String
password
,
String
role
)
{
this
.
userId
=
userId
;
this
.
teamId
=
teamId
;
this
.
userName
=
userName
;
this
.
password
=
password
;
this
.
role
=
role
;
...
...
project-interface/src/main/java/com/dituhui/pea/pojo/UserInfo.java
View file @
31675bc
...
...
@@ -97,14 +97,5 @@ public class UserInfo {
* 更新时间
*/
private
Date
updatedTime
;
/**
* 团队ID
*/
private
String
teamId
;
/**
* 团队信息
*/
private
TeamInfo
teamInfo
;
}
project-user/src/main/java/com/dituhui/pea/user/controller/TeamController.java
deleted
100644 → 0
View file @
c7956cd
package
com
.
dituhui
.
pea
.
user
.
controller
;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
com.dituhui.pea.enums.StatusCodeEnum
;
import
com.dituhui.pea.pojo.RoleInfo
;
import
com.dituhui.pea.pojo.UserInfo
;
import
com.dituhui.pea.user.ITeam
;
import
com.dituhui.pea.user.entity.TeamEntity
;
import
com.dituhui.pea.user.service.TeamService
;
import
com.dituhui.pea.pojo.WebResult
;
import
com.dituhui.pea.pojo.TeamInfo
;
import
org.apache.commons.lang.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cloud.context.config.annotation.RefreshScope
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.List
;
/**
*
* 团队控制层
* @author zl
* @since 2020-12-09 15:42:00
*
*/
@RestController
@RefreshScope
public
class
TeamController
implements
ITeam
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
TestController
.
class
);
@Autowired
TeamService
teamService
;
@Override
public
WebResult
<
TeamInfo
>
queryById
(
String
teamId
)
{
if
(
StringUtils
.
isBlank
(
teamId
))
{
return
WebResult
.
failed
(
StatusCodeEnum
.
COMMON_PARAM_EMPTY
);
}
TeamInfo
teamInfo
=
teamService
.
queryTeamById
(
teamId
);
return
WebResult
.
ok
(
teamInfo
);
}
@Override
public
WebResult
<
TeamInfo
>
queryByAppKey
(
String
ak
)
{
if
(
StringUtils
.
isBlank
(
ak
))
{
return
WebResult
.
failed
(
StatusCodeEnum
.
COMMON_PARAM_EMPTY
);
}
TeamInfo
teamInfo
=
teamService
.
queryTeamByAppKey
(
ak
);
return
WebResult
.
ok
(
teamInfo
);
}
@Override
public
WebResult
<
TeamInfo
>
addTeam
(
@Validated
TeamInfo
teamInfo
)
{
TeamEntity
teamEntity
=
BeanUtil
.
copyProperties
(
teamInfo
,
TeamEntity
.
class
);
teamInfo
=
teamService
.
saveTeam
(
teamEntity
);
return
WebResult
.
ok
(
teamInfo
);
}
@Override
public
WebResult
<
TeamInfo
>
updateTeam
(
TeamInfo
teamInfo
)
{
if
(
ObjectUtil
.
isNull
(
teamInfo
))
{
return
WebResult
.
failed
(
StatusCodeEnum
.
COMMON_PARAM_EMPTY
);
}
if
(
StringUtils
.
isBlank
(
teamInfo
.
getId
())){
return
WebResult
.
failed
(
StatusCodeEnum
.
COMMON_PARAM_EMPTY
);
}
teamInfo
=
teamService
.
updateTeam
(
teamInfo
);
return
WebResult
.
ok
(
teamInfo
);
}
@Override
public
WebResult
<
Boolean
>
deleteTeam
(
String
teamId
)
{
if
(
StringUtils
.
isBlank
(
teamId
))
{
return
WebResult
.
failed
(
StatusCodeEnum
.
COMMON_PARAM_EMPTY
);
}
teamService
.
deleteTeam
(
teamId
);
return
WebResult
.
ok
();
}
@Override
public
WebResult
<
Boolean
>
addTeamUser
(
String
teamId
,
String
userId
)
{
if
(
StringUtils
.
isBlank
(
teamId
)
&&
StringUtils
.
isBlank
(
userId
))
{
return
WebResult
.
failed
(
StatusCodeEnum
.
COMMON_PARAM_EMPTY
);
}
teamService
.
saveTeamUser
(
teamId
,
userId
);
return
WebResult
.
ok
();
}
@Override
public
WebResult
<
Boolean
>
deleteTeamUser
(
String
teamId
,
String
userId
)
{
if
(
StringUtils
.
isBlank
(
teamId
)
&&
StringUtils
.
isBlank
(
userId
))
{
return
WebResult
.
failed
(
StatusCodeEnum
.
COMMON_PARAM_EMPTY
);
}
teamService
.
deleteTeamUser
(
teamId
,
userId
);
return
WebResult
.
ok
();
}
@Override
public
WebResult
<
List
<
UserInfo
>>
getTeamUser
(
String
teamId
)
{
if
(
StringUtils
.
isBlank
(
teamId
))
{
return
WebResult
.
failed
(
StatusCodeEnum
.
COMMON_PARAM_EMPTY
);
}
List
<
UserInfo
>
teamUserList
=
teamService
.
getTeamUserList
(
teamId
);
return
WebResult
.
ok
(
teamUserList
);
}
@Override
public
WebResult
<
List
<
RoleInfo
>>
getTeamRole
(
String
teamId
)
{
if
(
StringUtils
.
isBlank
(
teamId
))
{
return
WebResult
.
failed
(
StatusCodeEnum
.
COMMON_PARAM_EMPTY
);
}
List
<
RoleInfo
>
teamRoleList
=
teamService
.
getTeamRoleList
(
teamId
);
return
WebResult
.
ok
(
teamRoleList
);
}
}
project-user/src/main/java/com/dituhui/pea/user/dao/TeamDao.java
deleted
100644 → 0
View file @
c7956cd
package
com
.
dituhui
.
pea
.
user
.
dao
;
import
com.dituhui.pea.user.entity.TeamEntity
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
import
org.springframework.data.repository.CrudRepository
;
/**
* 团队表(Team)表数据库访问层
*
* @author zl
* @since 2020-12-09 15:34:36
*/
public
interface
TeamDao
extends
JpaRepository
<
TeamEntity
,
String
>,
JpaSpecificationExecutor
<
TeamEntity
>,
CrudRepository
<
TeamEntity
,
String
>
{
/**
* 查询团队信息
*
* @param ak 团队ak
* @return
*/
TeamEntity
findByAppKey
(
String
ak
);
}
project-user/src/main/java/com/dituhui/pea/user/dao/UserTeamDao.java
deleted
100644 → 0
View file @
c7956cd
package
com
.
dituhui
.
pea
.
user
.
dao
;
import
com.dituhui.pea.user.entity.UserTeamEntity
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
import
org.springframework.data.repository.CrudRepository
;
import
java.util.List
;
/**
* 用户所属团队表(UserTeam)表数据库访问层
*
* @author zl
* @since 2020-12-09 15:34:53
*/
public
interface
UserTeamDao
extends
JpaRepository
<
UserTeamEntity
,
String
>,
JpaSpecificationExecutor
<
UserTeamEntity
>,
CrudRepository
<
UserTeamEntity
,
String
>
{
/**
* 根据用户ID查询
* @param userId 用户ID
* @return
*/
UserTeamEntity
findByUserId
(
String
userId
);
/**
* 根据用户ID查询
*
* @param userId 用户ID
* @param status 状态
* @return
*/
List
<
UserTeamEntity
>
findAllByUserIdAndStatusOrderByCreatedByDesc
(
String
userId
,
int
status
);
/**
* 根据团队Id和用户ID查询
* @param userId 用户ID
* @param teamId 团队ID
* @return
*/
UserTeamEntity
findByUserIdAndTeamId
(
String
userId
,
String
teamId
);
/**
* 根据用户ID删除
* @param userId 用户ID
*/
void
deleteByUserId
(
String
userId
);
/**
* 根据团队ID查询
* @param teamId 团队ID
* @return
*/
List
<
UserTeamEntity
>
findByTeamId
(
String
teamId
);
/**
* 根据teamId删除
* @param teamId 团队Id
*/
void
deleteByTeamId
(
String
teamId
);
/**
* 根据团队和用户删除
* @param teamId 团队ID
* @param userId 用户ID
*/
void
deleteByTeamIdAndUserId
(
String
teamId
,
String
userId
);
}
project-user/src/main/java/com/dituhui/pea/user/entity/TeamEntity.java
deleted
100644 → 0
View file @
c7956cd
package
com
.
dituhui
.
pea
.
user
.
entity
;
import
lombok.Data
;
import
org.hibernate.annotations.DynamicUpdate
;
import
org.hibernate.annotations.GenericGenerator
;
import
org.springframework.data.annotation.CreatedDate
;
import
org.springframework.data.annotation.LastModifiedDate
;
import
org.springframework.data.jpa.domain.support.AuditingEntityListener
;
import
javax.persistence.*
;
import
javax.validation.constraints.NotNull
;
import
java.io.Serializable
;
import
java.util.Date
;
/**
* 团队表(TeamEntity)实体类
*
* @author zl
* @since 2020-12-09 15:16:29
*/
@Data
@Entity
@Table
(
name
=
"team"
)
@EntityListeners
(
AuditingEntityListener
.
class
)
public
class
TeamEntity
implements
Serializable
{
private
static
final
long
serialVersionUID
=
959077359004482022L
;
/**
* 主键
*/
@Id
@GeneratedValue
(
generator
=
"uuid"
)
@GenericGenerator
(
name
=
"uuid"
,
strategy
=
"uuid"
)
@Column
(
name
=
"ID"
,
unique
=
true
,
nullable
=
false
,
length
=
32
)
private
String
id
;
/**
* 名称
*/
@Column
(
name
=
"name"
)
@NotNull
(
message
=
"团队名称不能为空!"
)
private
String
name
;
/**
* 到期时间
*/
@Column
(
name
=
"expire_date"
)
@NotNull
(
message
=
"团队到期时间不能为空!"
)
private
Date
expireDate
;
/**
* 是否签约
*/
@Column
(
name
=
"contract"
)
@NotNull
(
message
=
"团队签约状态不能为空!"
)
private
Integer
contract
;
/**
* ak
*/
@Column
(
name
=
"app_key"
)
@NotNull
(
message
=
"团队ak不能为空!"
)
private
String
appKey
;
/**
* 密钥
*/
@NotNull
(
message
=
"团队secret不能为空!"
)
@Column
(
name
=
"secret"
)
private
String
secret
;
/**
* 公司图标
*/
@Column
(
name
=
"logo"
)
private
String
logo
;
/**
* 所属行业
*/
@Column
(
name
=
"business"
)
private
String
business
;
/**
* 所属省
*/
@Column
(
name
=
"province"
)
private
String
province
;
/**
* 所属市
*/
@Column
(
name
=
"city"
)
private
String
city
;
/**
* 所属区县
*/
@Column
(
name
=
"county"
)
private
String
county
;
/**
* 人数
*/
@Column
(
name
=
"size"
)
private
String
size
;
/**
* 公司地址
*/
@Column
(
name
=
"address"
)
private
String
address
;
/**
* 营业执照
*/
@Column
(
name
=
"charter"
)
private
String
charter
;
/**
* 团队自定义条件
*/
@Column
(
name
=
"extra"
)
private
String
extra
;
/**
* 创始人用户id
*/
@Column
(
name
=
"admin_id"
)
private
String
adminId
;
/**
* 创建人
*/
@Column
(
name
=
"CREATED_BY"
)
private
String
createdBy
;
/**
* 创建时间
*/
@Column
(
name
=
"CREATED_TIME"
)
@CreatedDate
private
Date
createdTime
;
/**
* 更新人
*/
@Column
(
name
=
"UPDATED_BY"
)
private
String
updatedBy
;
/**
* 更新时间
*/
@Column
(
name
=
"UPDATED_TIME"
)
@LastModifiedDate
private
Date
updatedTime
;
}
project-user/src/main/java/com/dituhui/pea/user/entity/UserTeamEntity.java
deleted
100644 → 0
View file @
c7956cd
package
com
.
dituhui
.
pea
.
user
.
entity
;
import
lombok.Data
;
import
org.hibernate.annotations.GenericGenerator
;
import
org.springframework.data.annotation.CreatedDate
;
import
org.springframework.data.annotation.LastModifiedDate
;
import
org.springframework.data.jpa.domain.support.AuditingEntityListener
;
import
javax.persistence.*
;
import
javax.validation.constraints.NotNull
;
import
java.io.Serializable
;
import
java.util.Date
;
/**
* 用户所属团队表(UserTeamEntity)实体类
*
* @author zl
* @since 2020-12-09 15:12:19
*/
@Data
@Entity
@Table
(
name
=
"user_team"
)
@EntityListeners
(
AuditingEntityListener
.
class
)
public
class
UserTeamEntity
implements
Serializable
{
private
static
final
long
serialVersionUID
=
544874589204245131L
;
/**
* 主键
*/
@Id
@GeneratedValue
(
generator
=
"uuid"
)
@GenericGenerator
(
name
=
"uuid"
,
strategy
=
"uuid"
)
@Column
(
name
=
"ID"
,
unique
=
true
,
nullable
=
false
,
length
=
32
)
private
String
id
;
/**
* 用户id
*/
@Column
(
name
=
"user_id"
)
@NotNull
(
message
=
"用户ID为空"
)
private
String
userId
;
/**
* 团队id
*/
@Column
(
name
=
"team_id"
)
@NotNull
(
message
=
"团队ID为空"
)
private
String
teamId
;
/**
* 状态
*/
@Column
(
name
=
"status"
)
@NotNull
(
message
=
"用户状态为空"
)
private
Integer
status
;
/**
* 创建人
*/
@Column
(
name
=
"CREATED_BY"
)
private
String
createdBy
;
/**
* 创建时间
*/
@Column
(
name
=
"CREATED_TIME"
)
@CreatedDate
private
Date
createdTime
;
/**
* 更新人
*/
@Column
(
name
=
"UPDATED_BY"
)
private
String
updatedBy
;
/**
* 更新时间
*/
@Column
(
name
=
"UPDATED_TIME"
)
@LastModifiedDate
private
Date
updatedTime
;
}
project-user/src/main/java/com/dituhui/pea/user/factory/QqThirdStrategy.java
deleted
100644 → 0
View file @
c7956cd
package
com
.
dituhui
.
pea
.
user
.
factory
;
import
com.dituhui.pea.user.entity.UserEntity
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.CollectionUtils
;
import
java.util.List
;
/**
* QqThirdStrategy
*
* @author zhouyun
* 2021/5/21 15:08
* <p>Company: 成都地图慧科技有限公司</p>
*/
@Component
(
"QQ"
)
public
class
QqThirdStrategy
extends
AbstractThirdStrategy
{
@Override
public
UserEntity
getUser
(
String
id
)
{
List
<
UserEntity
>
allUserEntityList
=
userDao
.
findByQq
(
id
);
if
(
CollectionUtils
.
isEmpty
(
allUserEntityList
))
{
return
null
;
}
// 如果存在多个qq用户 默认取第一个
return
allUserEntityList
.
get
(
0
);
}
}
project-user/src/main/java/com/dituhui/pea/user/factory/WeiboThirdStrategy.java
deleted
100644 → 0
View file @
c7956cd
package
com
.
dituhui
.
pea
.
user
.
factory
;
import
com.dituhui.pea.user.entity.UserEntity
;
import
org.springframework.stereotype.Component
;
/**
* WeiboThirdStrategy
*
* @author zhouyun
* 2021/5/21 15:09
* <p>Company: 成都地图慧科技有限公司</p>
*/
@Component
(
"WEIBO"
)
public
class
WeiboThirdStrategy
extends
AbstractThirdStrategy
{
@Override
public
UserEntity
getUser
(
String
id
)
{
return
userDao
.
findByWeibo
(
id
).
orElse
(
null
);
}
}
project-user/src/main/java/com/dituhui/pea/user/service/TeamService.java
deleted
100644 → 0
View file @
c7956cd
package
com
.
dituhui
.
pea
.
user
.
service
;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.util.IdUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
com.dituhui.pea.enums.RedisKeyGroup
;
import
com.dituhui.pea.enums.StatusCodeEnum
;
import
com.dituhui.pea.enums.TeamContractEnum
;
import
com.dituhui.pea.enums.UserStatusEnum
;
import
com.dituhui.pea.exception.BusinessException
;
import
com.dituhui.pea.pojo.RoleInfo
;
import
com.dituhui.pea.pojo.TeamInfo
;
import
com.dituhui.pea.pojo.UserInfo
;
import
com.dituhui.pea.user.commom.RedisService
;
import
com.dituhui.pea.user.controller.TestController
;
import
com.dituhui.pea.user.dao.RoleDao
;
import
com.dituhui.pea.user.dao.TeamDao
;
import
com.dituhui.pea.user.dao.UserDao
;
import
com.dituhui.pea.user.dao.UserTeamDao
;
import
com.dituhui.pea.user.entity.RoleEntity
;
import
com.dituhui.pea.user.entity.TeamEntity
;
import
com.dituhui.pea.user.entity.UserEntity
;
import
com.dituhui.pea.user.entity.UserTeamEntity
;
import
com.google.common.collect.Lists
;
import
org.apache.commons.lang.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
* 团队业务层
* @author zl
*/
@Service
public
class
TeamService
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
TestController
.
class
);
@Autowired
TeamDao
teamDao
;
@Autowired
UserDao
userDao
;
@Autowired
UserTeamDao
userTeamDao
;
@Autowired
RoleDao
roleDao
;
@Autowired
private
RedisService
redisService
;
public
TeamInfo
queryTeamById
(
String
teamId
)
{
TeamEntity
teamEntity
=
teamDao
.
findById
(
teamId
).
orElse
(
null
);
if
(
ObjectUtil
.
isNull
(
teamEntity
))
{
throw
new
BusinessException
(
StatusCodeEnum
.
TEAM_DOES_NOT_EXIST
);
}
return
BeanUtil
.
copyProperties
(
teamEntity
,
TeamInfo
.
class
);
}
public
TeamInfo
queryTeamByAppKey
(
String
ak
)
{
TeamEntity
teamEntity
=
teamDao
.
findByAppKey
(
ak
);
if
(
ObjectUtil
.
isNull
(
teamEntity
))
{
throw
new
BusinessException
(
StatusCodeEnum
.
TEAM_DOES_NOT_EXIST
);
}
return
BeanUtil
.
copyProperties
(
teamEntity
,
TeamInfo
.
class
);
}
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
TeamInfo
saveTeam
(
TeamEntity
teamEntity
)
{
teamEntity
.
setContract
(
TeamContractEnum
.
NO_CONTRACT
.
getStatus
());
teamEntity
.
setAppKey
(
IdUtil
.
simpleUUID
());
teamEntity
.
setSecret
(
IdUtil
.
simpleUUID
());
teamEntity
=
teamDao
.
save
(
teamEntity
);
return
BeanUtil
.
copyProperties
(
teamEntity
,
TeamInfo
.
class
);
}
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
deleteTeam
(
String
teamId
)
{
TeamEntity
teamEntity
=
teamDao
.
findById
(
teamId
).
orElse
(
null
);
if
(
ObjectUtil
.
isNull
(
teamEntity
))
{
throw
new
BusinessException
(
StatusCodeEnum
.
TEAM_DOES_NOT_EXIST
);
}
// 删除团队
teamDao
.
deleteById
(
teamId
);
// 删除团队关系表
userTeamDao
.
deleteByTeamId
(
teamId
);
if
(
StringUtils
.
isNotEmpty
(
teamEntity
.
getAppKey
()))
{
// 删除团队信息缓存
redisService
.
remove
(
RedisKeyGroup
.
appKey
.
toString
()
+
":"
+
teamEntity
.
getAppKey
());
}
}
public
TeamInfo
updateTeam
(
TeamInfo
teamInfo
)
{
TeamEntity
oldTeamEntity
=
teamDao
.
findById
(
teamInfo
.
getId
()).
orElse
(
null
);
if
(
oldTeamEntity
==
null
)
{
throw
new
BusinessException
(
StatusCodeEnum
.
TEAM_DOES_NOT_EXIST
);
}
if
(
StringUtils
.
isNotEmpty
(
oldTeamEntity
.
getAppKey
()))
{
// 删除团队信息缓存
redisService
.
remove
(
RedisKeyGroup
.
appKey
.
toString
()
+
":"
+
oldTeamEntity
.
getAppKey
());
}
assembleUpdateTeamInfo
(
teamInfo
,
oldTeamEntity
);
oldTeamEntity
=
teamDao
.
save
(
oldTeamEntity
);
teamInfo
=
BeanUtil
.
copyProperties
(
oldTeamEntity
,
TeamInfo
.
class
);
return
teamInfo
;
}
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
TeamInfo
saveTeamUser
(
String
teamId
,
String
userId
)
{
// 查询团队是否存在
TeamEntity
teamEntity
=
teamDao
.
findById
(
teamId
).
orElse
(
null
);
if
(
ObjectUtil
.
isNull
(
teamEntity
))
{
throw
new
BusinessException
(
StatusCodeEnum
.
TEAM_DOES_NOT_EXIST
);
}
// 查询用户是否存在
UserEntity
userEntity
=
userDao
.
findById
(
userId
).
orElse
(
null
);
if
(
ObjectUtil
.
isNull
(
userEntity
))
{
throw
new
BusinessException
(
StatusCodeEnum
.
USER_DOES_NOT_EXIST
);
}
// 查询用户是否存在该团队
UserTeamEntity
userTeamEntity
=
userTeamDao
.
findByUserIdAndTeamId
(
userId
,
teamId
);
if
(
ObjectUtil
.
isNotNull
(
userTeamEntity
))
{
throw
new
BusinessException
(
StatusCodeEnum
.
USER_ALREADY_EXISTS_TEAM
);
}
userTeamEntity
=
assembleUserTeamEntity
(
userEntity
,
teamEntity
);
userTeamDao
.
save
(
userTeamEntity
);
return
BeanUtil
.
copyProperties
(
teamEntity
,
TeamInfo
.
class
);
}
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
deleteTeamUser
(
String
teamId
,
String
userId
)
{
//查询团队是否存在
TeamEntity
teamEntity
=
teamDao
.
findById
(
teamId
).
orElse
(
null
);
if
(
ObjectUtil
.
isNull
(
teamEntity
))
{
throw
new
BusinessException
(
StatusCodeEnum
.
TEAM_DOES_NOT_EXIST
);
}
// 查询用户是否存在
UserEntity
userEntity
=
userDao
.
findById
(
userId
).
orElse
(
null
);
if
(
ObjectUtil
.
isNull
(
userEntity
))
{
throw
new
BusinessException
(
StatusCodeEnum
.
USER_DOES_NOT_EXIST
);
}
// 删除团队用户关系
userTeamDao
.
deleteByTeamIdAndUserId
(
teamId
,
userId
);
// 删除用户
userDao
.
deleteById
(
userId
);
}
public
List
<
UserInfo
>
getTeamUserList
(
String
teamId
)
{
//查询团队是否存在
TeamEntity
teamEntity
=
teamDao
.
findById
(
teamId
).
orElse
(
null
);
if
(
ObjectUtil
.
isNull
(
teamEntity
))
{
throw
new
BusinessException
(
StatusCodeEnum
.
TEAM_DOES_NOT_EXIST
);
}
// 查询用户关系表
List
<
UserTeamEntity
>
userTeamEntities
=
userTeamDao
.
findByTeamId
(
teamId
);
if
(
CollUtil
.
isEmpty
(
userTeamEntities
))
{
return
Lists
.
newArrayList
();
}
List
<
String
>
userIdList
=
userTeamEntities
.
stream
().
map
(
UserTeamEntity:
:
getUserId
).
collect
(
Collectors
.
toList
());
// 查询用户
List
<
UserEntity
>
userEntityList
=
userDao
.
findByIdIn
(
userIdList
);
// 对象转换
List
<
UserInfo
>
userInfoList
=
Lists
.
newArrayList
();
userEntityList
.
forEach
(
userEntity
->
{
UserInfo
userInfo
=
BeanUtil
.
copyProperties
(
userEntity
,
UserInfo
.
class
);
userInfoList
.
add
(
userInfo
);
});
return
userInfoList
;
}
public
List
<
RoleInfo
>
getTeamRoleList
(
String
teamId
)
{
// 查询团队是否存在
TeamEntity
teamEntity
=
teamDao
.
findById
(
teamId
).
orElse
(
null
);
if
(
ObjectUtil
.
isNull
(
teamEntity
))
{
throw
new
BusinessException
(
StatusCodeEnum
.
TEAM_DOES_NOT_EXIST
);
}
// 查询团队下的角色
List
<
RoleEntity
>
roleEntities
=
roleDao
.
findByTeamId
(
teamId
);
if
(
CollUtil
.
isEmpty
(
roleEntities
))
{
return
Lists
.
newArrayList
();
}
// 对象转换
List
<
RoleInfo
>
roleInfoList
=
Lists
.
newArrayList
();
roleEntities
.
forEach
(
roleEntity
->
{
RoleInfo
roleInfo
=
BeanUtil
.
copyProperties
(
roleEntity
,
RoleInfo
.
class
);
roleInfoList
.
add
(
roleInfo
);
});
return
roleInfoList
;
}
/**
* 组装用户团队关系表
* @param userEntity 用户信息
* @param teamEntity 团队信息
* @return
*/
private
UserTeamEntity
assembleUserTeamEntity
(
UserEntity
userEntity
,
TeamEntity
teamEntity
)
{
UserTeamEntity
userTeamEntity
=
new
UserTeamEntity
();
userTeamEntity
.
setUserId
(
userEntity
.
getId
());
userTeamEntity
.
setTeamId
(
teamEntity
.
getId
());
userTeamEntity
.
setStatus
(
UserStatusEnum
.
NORMAL
.
getStatus
());
return
userTeamEntity
;
}
/**
* 组装更新用户信息
* @param formTeamInfo
* @param toTeamEntity
*/
private
void
assembleUpdateTeamInfo
(
TeamInfo
formTeamInfo
,
TeamEntity
toTeamEntity
)
{
if
(
StringUtils
.
isNotBlank
(
formTeamInfo
.
getName
()))
{
toTeamEntity
.
setName
(
formTeamInfo
.
getName
());
}
if
(
formTeamInfo
.
getExpireDate
()
!=
null
)
{
toTeamEntity
.
setExpireDate
(
formTeamInfo
.
getExpireDate
());
}
if
(
formTeamInfo
.
getContract
()
!=
null
)
{
toTeamEntity
.
setContract
(
formTeamInfo
.
getContract
());
}
if
(
StringUtils
.
isNotBlank
(
formTeamInfo
.
getAppKey
()))
{
toTeamEntity
.
setAppKey
(
formTeamInfo
.
getAppKey
());
}
if
(
StringUtils
.
isNotBlank
(
formTeamInfo
.
getSecret
()))
{
toTeamEntity
.
setSecret
(
formTeamInfo
.
getSecret
());
}
if
(
StringUtils
.
isNotBlank
(
formTeamInfo
.
getLogo
()))
{
toTeamEntity
.
setLogo
(
formTeamInfo
.
getLogo
());
}
if
(
StringUtils
.
isNotBlank
(
formTeamInfo
.
getBusiness
()))
{
toTeamEntity
.
setBusiness
(
formTeamInfo
.
getBusiness
());
}
if
(
StringUtils
.
isNotBlank
(
formTeamInfo
.
getProvince
()))
{
toTeamEntity
.
setProvince
(
formTeamInfo
.
getProvince
());
}
if
(
StringUtils
.
isNotBlank
(
formTeamInfo
.
getCity
()))
{
toTeamEntity
.
setCity
(
formTeamInfo
.
getCity
());
}
if
(
StringUtils
.
isNotBlank
(
formTeamInfo
.
getCounty
()))
{
toTeamEntity
.
setCounty
(
formTeamInfo
.
getCounty
());
}
if
(
StringUtils
.
isNotBlank
(
formTeamInfo
.
getAddress
()))
{
toTeamEntity
.
setAddress
(
formTeamInfo
.
getAddress
());
}
if
(
StringUtils
.
isNotBlank
(
formTeamInfo
.
getCharter
()))
{
toTeamEntity
.
setCharter
(
formTeamInfo
.
getCharter
());
}
if
(
StringUtils
.
isNotBlank
(
formTeamInfo
.
getExtra
()))
{
toTeamEntity
.
setExtra
(
formTeamInfo
.
getExtra
());
}
}
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment